Something is totally wrong with my query. .. Slow. .. Why?
That query seems to fetch 4 columns from one particular row of one table:
select ((four columns))
    from        item_ledger_entry as z
        where  ( z.orgLine = l.id OR z.cargoLine = l.id )
          AND e.docNr = l.docNr ORDER  BY z.id DESC LIMIT  1

Correct?  If so, I suggest:
SELECT ....
    FROM ( SELECT a,b,c,d
               FROM item_ledger_entry z
               WHERE (   z.orgLine = l.id
                      OR z.cargoLine = l.id )
                 AND e.docNr = l.docNr
               ORDER  BY z.id DESC LIMIT  1
         ) AS z2
    JOIN FROM cargo_line_receive AS l 
                     ON ( z2.orgLine = l.id
                      OR  z2.cargoLine = l.id )

    LEFT JOIN ...

That will help performance some.
The OR hurt performance; you use it often.  Is there some way to avoid it?  I hesitate to mention using UNION because I am not sure the transformation will work easily.
WHERE  h.clientCode = '999999999999' 
AND h.agreements = 'LIG00067' 

begs for h to have INDEX(clientCode, agreements).  (The order of those columns does not matter.)
GROUP  BY l.id 

worries me.  It sounds like the &quot;explode-implode&quot; scenario.  Note that (at least logically), first all the JOINs are done.  This produces (potentially) a much larger table that any of the original ones.  Then the GROUP BY implodes down to the original size.  The typical remedy is to get the l.id values you ultimately need, then do the JOINs.
The high &quot;Rows&quot; for e confirms that OR is a big part of the performance issue.  It is doing a full table scan -- probably repeatedly -- because of
ON e.cargoline = l.id 
OR e.orgline = l.id 

But, before I address that, Please justify or get rid of LEFT.  Keep in mind that JOIN matches up rows from the two tables, whereas LEFT JOIN also takes any missing rows from the 'right' table, supplying NULLs to indicate that the row is missing.
If JOIN is warranted, then this might 'save the day':
JOIN  ( ( SELECT  FROM item_ledger_entry 
            WHERE  e.cargoline = l.id )
        UNION DISTINCT
        ( SELECT  FROM item_ledger_entry 
            WHERE  e.orgline = l.id )
      ) AS e

instead of
LEFT JOIN item_ledger_entry AS e 
ON e.cargoline = l.id 
OR e.orgline = l.id 

Note, e will need two separate indexes:  INDEX(cargoline), INDEX(orgline)
(I'm sorry, but your query is so convoluted that each of my suggestions may fail for some reason.  You can add the indexes safely; at worst, they might not 'help'.)