1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| SELECT f.fournisseur, f.nom, YEAR(c.date) AS annee,
SUM(b.quantite) / SUM(d.quantite) AS tauxRuptureQuantite,
SUM((b.prixNetUnitaire / b.quantite) * (b.quantite - d.quantite)) AS caPerdu,
SUM(b.prixNetUnitaire) AS caCommande,
SUM((b.prixNetUnitaire / b.quantite) * d.quantite) AS caLivre
FROM commandes a
INNER JOIN lignes_commandes b ON a.commande = b.commande AND b.annulee = 0
INNER JOIN bons_livraisons c ON a.commande = c.commande
INNER JOIN lignes_livraisons d ON c.bonLivraison = d.bonLivraison AND b.article = d.article AND b.collection = d.collection
INNER JOIN produits e ON b.article = e.codeProduit
INNER JOIN fournisseur f ON e.fournisseur = e.fournisseur AND f.inactif = 0
WHERE a.validee = 1
AND a.annule = 0
AND ((c.date <= STR_TO_DATE(CONCAT(YEAR(NOW()) - 1, "-", MONTH(NOW()), "-", DAY(NOW())), "%Y-%m-%d") AND c.date >= STR_TO_DATE(CONCAT(YEAR(NOW()) - 1, "-01-01"), "%Y-%m-%d"))
OR (c.date <= NOW() AND c.date >= STR_TO_DATE(CONCAT(YEAR(NOW()), "-01-01"), "%Y-%m-%d")))
GROUP BY f.fournisseur, YEAR(c.date) |
Partager