From 7422890c87c1c5d398ab8a8e8cdcdb3ac199c8e0 Mon Sep 17 00:00:00 2001 From: Tiavina Date: Thu, 4 Sep 2025 16:53:00 +0300 Subject: [PATCH] dv thanato list ttc value in facture list --- gestion/lib/Db/Bdd.php | 99 ++++++++++++++++++++++++++- gestion/lib/Helpers/PriceHelpers.php | 5 ++ gestion/src/js/objects/facture.mjs | 3 + gestion/templates/content/facture.php | 1 + 4 files changed, 107 insertions(+), 1 deletion(-) diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index 4f8ba57..e9daaf0 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -513,6 +513,7 @@ class Bdd foreach($facturesList as $currentFacture) { $produits = $this->getProduitsDevisByDevisId($currentFacture->id_devis); $currentFacture->produits = $produits; + $currentFacture->totalPrices = $this->getFactureTotalPrices($currentFacture->id); } return json_encode($facturesList); } @@ -4944,7 +4945,7 @@ COMMENTAIRES: ".$comment; $conditions = [$clientGroupFacturationId,$year,$month]; if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); - $sql .= " AND ". $this->tableprefix."devis.mentions IN ($mentionsFilterPlaceholders)"; + $sql .= " AND "."devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); } $sql .= ";"; @@ -5172,6 +5173,26 @@ COMMENTAIRES: ".$comment; return $devisList; } + public function getDevisIdsGroupByFactureId($factureId,$mentionFilters = []){ + $sql = "SELECT devis.id + FROM ".$this->tableprefix."devis as devis + WHERE devis.fk_facture_id = ? "; + + $conditions = [$factureId]; + if(!empty($mentionFilters)){ + $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); + $sql .= " AND devis.mentions IN ($mentionsFilterPlaceholders)"; + $conditions = array_merge($conditions, $mentionFilters); + } + $sql.= ";"; + $devisList = $this->execSQLNoJsonReturn($sql,$conditions); + $devisIds = []; + foreach($devisList as $devis){ + $devisIds[] = $devis['id']; + } + return $devisIds; + } + public function getDevisDataGroupByFactureId($factureId, $mentionFilters = []) { $sql = "SELECT @@ -5723,4 +5744,80 @@ COMMENTAIRES: ".$comment; return null; } + + private function getProductsTotalPrices($products) + { + $configs = json_decode($this->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD)); + $currentConfig = $configs[0]; + $totalHt = 0; + $totalTtc = 0; + foreach ($products as $product) { + $valueHt = $product['produit_price'] * $product['quantite']; + $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $currentConfig->tva_default); + $totalHt += $valueHt; + $totalTtc += $valueTtc; + } + return [ + "total_ht" => $totalHt, + "total_ttc" => $totalTtc, + "tva" => $currentConfig->tva_default + ]; + } + + private function getDevisIdsListByFactureId($factureId){ + $factureData = $this->getFactureByFactureId(factureId: $factureId); + $isFactureGroupOfDevis = $factureData["facture_type"] == FactureTypeConstant::TYPE_GROUP; + $factureDevisIdsList = []; + if($isFactureGroupOfDevis){ + $isFactureForSingleClient = $factureData['fk_client_id'] != null && $factureData['fk_client_id'] != 0; + $devisMentionFilters = [ + DevisMentionConstant::FACTURED_FORMATTED, + DevisMentionConstant::FACTURED + ]; + $devis = $this->getDevisByFkFactureId($factureId); + $factureGroupIsRelatedToAnyDevis = $devis != null; + if (!$factureGroupIsRelatedToAnyDevis) { + if($isFactureForSingleClient){ + $factureDevisIdsList = $this->getDevisIdsByClientIdAndMonthYear( + $factureData['fk_client_id'], + $factureData['month'], + $factureData['year'],$devisMentionFilters + ); + }else{ + $factureDevisIdsList = $this->getDevisIdsByClientGroupFacturationIdAndMonthYear( + $factureData['fk_client_group_facturation_id'], + $factureData['month'], + $factureData['year'],$devisMentionFilters + ); + } + }else{ + $factureDevisIdsList = $this->getDevisIdsGroupByFactureId($factureId, $devisMentionFilters ); + } + } + else{ + $factureDevisIdsList = $factureData['id_devis'] ? [$factureData['id_devis']] : []; + } + return $factureDevisIdsList; + } + + private function getFactureTotalPrices($factureId) + { + $factureDevisIds = $this->getDevisIdsListByFactureId($factureId); + $totalHt = 0; + $totalTtc = 0; + $tva = 0; + foreach($factureDevisIds as $devisId){ + $clientTvaStatus = $this->getClientTvaStatus($devisId,BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD); + $products = $this->getDevisProduits($devisId); + $totalPrices = $this->getProductsTotalPrices($products); + $totalHt += $totalPrices["total_ht"]; + $totalTtc += $clientTvaStatus == 1 ? $totalPrices["total_ttc"] : $totalPrices["total_ht"]; + $tva = $totalPrices["tva"]; + } + return [ + "total_ht" => PriceHelpers::formatDecimalPriceWithCurrency($totalHt), + "total_ttc" => PriceHelpers::formatDecimalPriceWithCurrency($totalTtc), + "tva" => PriceHelpers::formatDecimalPriceWithCurrency($tva) + ]; + } } diff --git a/gestion/lib/Helpers/PriceHelpers.php b/gestion/lib/Helpers/PriceHelpers.php index 55e3b3d..55b395a 100644 --- a/gestion/lib/Helpers/PriceHelpers.php +++ b/gestion/lib/Helpers/PriceHelpers.php @@ -17,4 +17,9 @@ class PriceHelpers return number_format($price,2,'.',''); } + public static function formatDecimalPriceWithCurrency($price,$currency = '€') + { + return self::formatDecimalPrice($price) . $currency; + } + } diff --git a/gestion/src/js/objects/facture.mjs b/gestion/src/js/objects/facture.mjs index 141703a..3abfc84 100644 --- a/gestion/src/js/objects/facture.mjs +++ b/gestion/src/js/objects/facture.mjs @@ -58,6 +58,8 @@ export class Facture { this.clientName = ((myresp.facture_group_name == null || myresp.facture_group_name.length == 0) ? '-' : myresp.facture_group_name); } } + + this.totalTtc = myresp?.totalPrices?.total_ttc ?? 0; } getDocumentStateLabel(documentState){ @@ -86,6 +88,7 @@ export class Facture { '
' + this.payment_date + '
', '
' + this.isDocumentAlreadyGeneratedLabel + '
', '
' + this.isDocumentAlreadySentLabel + '
', + '
'+this.totalTtc + '
', '
', ]; return myrow; diff --git a/gestion/templates/content/facture.php b/gestion/templates/content/facture.php index f8ba922..fa023e6 100644 --- a/gestion/templates/content/facture.php +++ b/gestion/templates/content/facture.php @@ -39,6 +39,7 @@ t('Date de paiement'));?> t('Générée'));?> t('Envoyée au client'));?> + t('Total TTC'));?> t('Actions'));?>