SELECT m.id, m.depot_code, m.commercial_code, m.produit_code, m.prix_ttc, m.type, m.etat,
		(select mu.id from mouvements as mu where mu.type="chargement" and mu.commercial_code=m.commercial_code and mu.produit_code=m.produit_code and etat='accepted' and date like '2025-03-03%' Limit 0,1) as id_chargement,
		(select mu.produit_code from mouvements as mu where mu.type="chargement" and mu.commercial_code=m.commercial_code and mu.produit_code=m.produit_code and etat='accepted' and date like '2025-03-03%' Limit 0,1) as produit_code_chargement,
		(select mu.prix_ttc from mouvements as mu where mu.type="chargement" and mu.commercial_code=m.commercial_code and mu.produit_code=m.produit_code and etat='accepted' and date like '2025-03-03%' Limit 0,1) as prix_ttc_chargement,
		(select mu.type from mouvements as mu where mu.type="chargement" and mu.commercial_code=m.commercial_code and mu.produit_code=m.produit_code and etat='accepted' and date like '2025-03-03%' Limit 0,1) as type_chargement,
		(select mu.etat from mouvements as mu where mu.type="chargement" and mu.commercial_code=m.commercial_code and mu.produit_code=m.produit_code and etat='accepted' and date like '2025-03-03%' Limit 0,1) as etat_chargement,
		(select mu.commercial_code from mouvements as mu where mu.type="chargement" and mu.commercial_code=m.commercial_code and mu.produit_code=m.produit_code and etat='accepted' and date like '2025-03-03%' Limit 0,1) as commercial_chargement,
        (select mu.date from mouvements as mu where mu.type="chargement" and mu.commercial_code=m.commercial_code and mu.produit_code=m.produit_code and etat='accepted' and date like '2025-03-03%' Limit 0,1) as date_chargement
FROM mouvements as m 
where  m.date like '2025-03-03%' and m.type not in ( 'chargement') and m.prix_ttc <> (select mu.prix_ttc from mouvements as mu where mu.type="chargement" 
                and mu.commercial_code=m.commercial_code and mu.produit_code=m.produit_code and etat='accepted' 
                and date like '2025-03-03%' Limit 0,1) and m.produit_code in ( SELECT mc.produit_code 
                from mouvements as mc where mc.type="chargement" and etat='accepted' and  mc.date like '2025-03-03%' and mc.commercial_code=m.commercial_code)

----
retour stock : 

update stock_depots as sd 
set sd.quantite = sd.quantite + (SELECT m.quantite  FROM mouvements as m where m.numero='CH-75995' and m.produit_code=sd.produit_code and m.type="retour"  and etat="accepted" Limit 0,1) 
where  sd.produit_code in (select produit_code from mouvements where numero ="CH-75995" and type="retour" and etat="accepted") and sd.soussociete_code="distrinat"



stock_depot  achat 
update  stock_depots as sd set sd.quantite = sd.quantite - (select m.quantite from mouvements as m where numero="FAC-2503N01-00856" and m.produit_code=sd.produit_code LIMIT 0,1) where sd.produit_code in (select produit_code from mouvements where numero="FAC-2503N01-00856")



select * from mouvements where id in (
		
'2312332',
'2344692',
'2344693',
'2344694',
'2344695',
'2344696',
'2344697',
'2344707',
'2344711',
'2344714',
'2344722'

)