Merge branch 'dvthanato/dv-thanato-list-ttc-in-facture' into dvthanato/dv-thanato-tolotsoa-version

This commit is contained in:
narindraezway 2025-09-04 17:34:41 +03:00
commit 22c4c1d8eb
29 changed files with 132 additions and 25 deletions

1
gestion/js/943.app.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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)
];
}
}

View File

@ -17,4 +17,9 @@ class PriceHelpers
return number_format($price,2,'.','');
}
public static function formatDecimalPriceWithCurrency($price,$currency = '€')
{
return self::formatDecimalPrice($price) . $currency;
}
}

View File

@ -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 {
'<div>' + this.payment_date + '</div>',
'<div><span class="badge '+this.isDocumentAlreadyGeneratedClass+'">' + this.isDocumentAlreadyGeneratedLabel + '</span></div>',
'<div><span class="badge '+this.isDocumentAlreadySentClass+'">' + this.isDocumentAlreadySentLabel + '</span></div>',
'<div><span>'+this.totalTtc + '</span></div>',
'<div style="display:inline-block;margin-right:0px;width:80%;"><a href="' + this.baseUrl +'"><button>' + t('gestion', 'Open') + '</button></a></div><div data-modifier="facture" data-id=' + this.id + ' data-table="facture" style="display:inline-block;margin-right:0px;" class="deleteItem icon-delete"></div>',
];
return myrow;

View File

@ -39,6 +39,7 @@
<th><?php p($l->t('Date de paiement'));?></th>
<th><?php p($l->t('Générée'));?></th>
<th><?php p($l->t('Envoyée au client'));?></th>
<th><?php p($l->t('Total TTC'));?></th>
<th><?php p($l->t('Actions'));?></th>
</tr>
</thead>