statistic after implementing facture group

This commit is contained in:
Tiavina 2025-03-10 10:36:21 +03:00
parent 45d09b7730
commit 221b4b7d23
2 changed files with 63 additions and 10 deletions

View File

@ -1884,7 +1884,7 @@ class PageController extends Controller {
* @NoCSRFRequired
*/
public function getAnnualTurnoverPerMonthNoVat(){
return $this->myDb->getAnnualTurnoverPerMonthNoVat($this->idNextcloud);
return $this->myDb->retrieveTotalInvoicesForTheYear();
}
/**

View File

@ -2060,6 +2060,43 @@ class Bdd {
return $this->execSQL($sql, array());
}
public function retrieveTotalInvoicesForTheYear(){
$sql = "SELECT
EXTRACT(YEAR FROM facture.date_paiement) AS y,
EXTRACT(MONTH FROM facture.date_paiement) AS m,
SUM(
COALESCE(client_group_discount.ht_amount,produit.prix_unitaire)
* produit_devis.quantite
) AS total
FROM ".$this->tableprefix."facture AS facture
JOIN ".$this->tableprefix."devis AS devis
ON MONTH(facture.date_paiement) = MONTH(devis.date) AND
YEAR(facture.date_paiement) = YEAR(devis.date)
JOIN ".$this->tableprefix."produit_devis AS produit_devis
ON devis.id = produit_devis.devis_id
JOIN ".$this->tableprefix."produit AS produit
ON produit_devis.produit_id = produit.id
JOIN ".$this->tableprefix."client AS client
ON devis.id_client = client.id
LEFT JOIN ".$this->tableprefix."client_group AS client_group
ON client.fk_client_group_id = client_group.id
LEFT JOIN ".$this->tableprefix."client_group_discount AS client_group_discount
ON client_group.id = client_group_discount.fk_client_group_id
AND produit.id = client_group_discount.fk_produit_id
WHERE
(devis.mentions = ? OR devis.mentions = ?)
GROUP BY
EXTRACT(YEAR FROM facture.date_paiement),
EXTRACT(MONTH FROM facture.date_paiement)
ORDER BY
EXTRACT(YEAR FROM facture.date_paiement) DESC,
EXTRACT(MONTH FROM facture.date_paiement);";
return $this->execSQL($sql, [
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
]);
}
/**
* Annual turnover per month without VAT
*/
@ -2091,7 +2128,7 @@ class Bdd {
ORDER BY
EXTRACT(YEAR FROM facture.date_paiement) DESC,
EXTRACT(MONTH FROM facture.date_paiement);";
return $this->execSQL($sql, array());
return $this->execSQLNoJsonReturn($sql, array());
}
public function getStatArticleAnnuel($idNextcloud, $annee) {
@ -2111,10 +2148,16 @@ class Bdd {
FROM ".$this->tableprefix."produit p
LEFT JOIN ".$this->tableprefix."produit_devis pd ON p.id = pd.produit_id
LEFT JOIN ".$this->tableprefix."devis d ON pd.devis_id = d.id
LEFT JOIN ".$this->tableprefix."facture f ON f.id_devis = d.id
WHERE YEAR(f.date_paiement) = ".$annee." AND pd.devis_id IS NOT NULL
LEFT JOIN ".$this->tableprefix."facture f
ON MONTH(f.date_paiement) = MONTH(d.date) AND
YEAR(f.date_paiement) = YEAR(f.date)
WHERE YEAR(f.date_paiement) = ".$annee." AND pd.devis_id IS NOT NULL AND
(d.mentions = ? or d.mentions = ?)
GROUP BY p.id, p.reference;";
return $this->execSQL($sql, array());
return $this->execSQL($sql, [
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
]);
}
public function getStatSoinsThanatoAnnuel($idNextcloud, $annee) {
@ -2134,13 +2177,19 @@ class Bdd {
COALESCE(SUM(CASE WHEN MONTH(d.date) = 11 THEN 1 ELSE 0 END), 0) AS novembre,
COALESCE(SUM(CASE WHEN MONTH(d.date) = 12 THEN 1 ELSE 0 END), 0) AS decembre
FROM ".$this->tableprefix."devis d
LEFT JOIN ".$this->tableprefix."facture f ON f.id_devis = d.id
LEFT JOIN ".$this->tableprefix."facture f
ON MONTH(f.date_paiement) = MONTH(d.date) AND
YEAR(f.date_paiement) = YEAR(f.date)
LEFT JOIN ".$this->tableprefix."thanato thanato ON d.id_thanato = thanato.id
WHERE YEAR(d.date) = ".$annee." AND d.id_thanato IS NOT NULL
WHERE YEAR(d.date) = ".$annee." AND d.id_thanato IS NOT NULL AND
(d.mentions = ? or d.mentions = ?)
AND thanato.id IS NOT NULL
GROUP BY nom_thanato, prenom_thanato
ORDER BY nom_thanato;";
return $this->execSQL($sql, array());
return $this->execSQL($sql, [
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
]);
}
public function getStatSoinsThanatoWeekend($idNextcloud, $annee, $mois) {
@ -2174,10 +2223,14 @@ class Bdd {
WHERE
MONTH(devis.date) = ".$mois."
AND YEAR(devis.date) = ".$annee."
AND DAYOFWEEK(devis.date) IN (1, 7)
AND DAYOFWEEK(devis.date) IN (1, 7) AND
(devis.mentions = ? or devis.mentions = ?)
GROUP BY
thanato.id, nom_thanato, prenom_thanato;";
return $this->execSQL($sql, array());
return $this->execSQL($sql, [
DevisMentionConstant::FACTURED,
DevisMentionConstant::FACTURED_FORMATTED
]);
}
/**