Performance MySQL query with for loop
SELECT MAX(id) AS id
                      FROM sw_sowing
                      WHERE status != 0
                      AND id_tenant = :id_tenant
                      AND date &lt;= :dates
                      AND multiply != 1
                      AND id_product = 1


needs INDEX(id_tennant, id_product, dates, multiply, id)

GROUP BY id_production_unit_detail does not make sense since you are not doing SELECT id_production_unit_detail, MAX(ID) and then using id_production_unit_detail in some way.

Eh?  Doing this for each Sunday??  AND date &lt;= :dates -- That means you are scanning more and more of the table.  And, if there are no entries in a week, returning the same data sometimes.  There are much better ways to get the data for a given week withouut scanning the rest of the data.  And it lends itself better to doing everything at once (instead of looping through Sundays).

I assume these are all the same type?

SELECT ..., sw_sowing.type, ...
    GROUP BY ..., sw_sowing.type
    HAVING type NOT IN('ER','PR')


If so, then it would be more efficient to move the test against type into WHERE instead of HAVING.

(There may be more to improve on.  Do these things, then come back for more abuse/advice.)