feat add is_tva group facture

This commit is contained in:
Tolotsoa 2025-08-22 14:00:49 +03:00
parent 477196fa39
commit 96d117ead5
2 changed files with 87 additions and 30 deletions

View File

@ -5318,7 +5318,7 @@ COMMENTAIRES: ".$comment;
$configuration = $this->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD); $configuration = $this->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
$configuration = json_decode($configuration); $configuration = json_decode($configuration);
$currentConfig = $configuration[0]; $currentConfig = $configuration[0];
$tvaValue = $currentConfig->tva_default;
$isFactureSingleClient = $facture['fk_client_id'] != null $isFactureSingleClient = $facture['fk_client_id'] != null
&& $facture['fk_client_id'] != 0; && $facture['fk_client_id'] != 0;
@ -5329,6 +5329,21 @@ COMMENTAIRES: ".$comment;
$devis = $this->getDevisByFkFactureId($factureId); $devis = $this->getDevisByFkFactureId($factureId);
$factureGroupIsRelatedToAnyDevis = $devis != null; $factureGroupIsRelatedToAnyDevis = $devis != null;
// LOGIQUE TVA SIMPLIFIÉE
$tvaValue = 0;
$isTvaApplicable = false;
// Récupérer le statut TVA du client de cette facture
$clientId = $facture['fk_client_id'];
if ($clientId != null && $clientId != 0) {
$client = $this->getClientById($clientId);
// is_tva = 0 → Pas de TVA, is_tva = 1 → TVA par défaut
if (isset($client['is_tva']) && $client['is_tva'] == 1) {
$isTvaApplicable = true;
$tvaValue = (float)$currentConfig->tva_default;
}
}
if($isFactureSingleClient) { if($isFactureSingleClient) {
$client = $this->getClientById($facture['fk_client_id']); $client = $this->getClientById($facture['fk_client_id']);
@ -5337,6 +5352,7 @@ COMMENTAIRES: ".$comment;
$facture['client_address'] = $client["client_address"]; $facture['client_address'] = $client["client_address"];
$facture['siret'] = $client["client_legal_one"]; $facture['siret'] = $client["client_legal_one"];
$facture['mail'] = $client["client_mail"]; $facture['mail'] = $client["client_mail"];
if (!$factureGroupIsRelatedToAnyDevis) { if (!$factureGroupIsRelatedToAnyDevis) {
$devisList = $this->getDevisDataByClientIdAndMonthYear( $devisList = $this->getDevisDataByClientIdAndMonthYear(
$facture['fk_client_id'], $facture['fk_client_id'],
@ -5344,7 +5360,6 @@ COMMENTAIRES: ".$comment;
$facture['year'], $facture['year'],
$devisMentionFilters $devisMentionFilters
); );
} else { } else {
$devisList = $this->getDevisDataGroupByFactureId($factureId, $devisMentionFilters); $devisList = $this->getDevisDataGroupByFactureId($factureId, $devisMentionFilters);
} }
@ -5355,6 +5370,7 @@ COMMENTAIRES: ".$comment;
$facture['client_address'] = $clientGroupFacturation["address"] . ' - ' .$clientGroupFacturation["postal_code"] . ' ' . $clientGroupFacturation['city']; $facture['client_address'] = $clientGroupFacturation["address"] . ' - ' .$clientGroupFacturation["postal_code"] . ' ' . $clientGroupFacturation['city'];
$facture['siret'] = $clientGroupFacturation["siret_number"]; $facture['siret'] = $clientGroupFacturation["siret_number"];
$facture['mail'] = $clientGroupFacturation["email"]; $facture['mail'] = $clientGroupFacturation["email"];
if (!$factureGroupIsRelatedToAnyDevis) { if (!$factureGroupIsRelatedToAnyDevis) {
$devisList = $this->getDevisDataByClientGroupFacturationIdAndMonthYear( $devisList = $this->getDevisDataByClientGroupFacturationIdAndMonthYear(
$facture['fk_client_group_facturation_id'], $facture['fk_client_group_facturation_id'],
@ -5366,22 +5382,36 @@ COMMENTAIRES: ".$comment;
$devisList = $this->getDevisDataGroupByFactureId($factureId, $devisMentionFilters); $devisList = $this->getDevisDataGroupByFactureId($factureId, $devisMentionFilters);
} }
} }
$factureTotalHt = 0; $factureTotalHt = 0;
$factureTotalTva = 0; $factureTotalTva = 0;
$factureTotalTtc = 0; $factureTotalTtc = 0;
foreach($devisList as &$currentDevis) { foreach($devisList as &$currentDevis) {
$totalHt = 0; $totalHt = 0;
$totalTva = 0; $totalTva = 0;
$totalTtc = 0; $totalTtc = 0;
$devisProducts = $this->getDevisProduits($currentDevis['devis_id']); $devisProducts = $this->getDevisProduits($currentDevis['devis_id']);
foreach($devisProducts as $currentProduct) { foreach($devisProducts as $currentProduct) {
$valueHt = $currentProduct['produit_price'] * $currentProduct['quantite']; $valueHt = $currentProduct['produit_price'] * $currentProduct['quantite'];
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue);
// CALCUL SIMPLE : TVA OU PAS TVA
if ($isTvaApplicable) {
// Client soumis à TVA : utiliser le taux par défaut
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue);
$tvaAmount = $valueTtc - $valueHt;
} else {
// Client exonéré : TTC = HT
$valueTtc = $valueHt;
$tvaAmount = 0;
}
$totalHt += $valueHt; $totalHt += $valueHt;
$totalTtc += $valueTtc; $totalTtc += $valueTtc;
$tvaAmount = $valueTtc - $valueHt;
$totalTva += $tvaAmount; $totalTva += $tvaAmount;
} }
$currentDevis["totalHt"] = $totalHt; $currentDevis["totalHt"] = $totalHt;
$currentDevis["totalTtc"] = $totalTtc; $currentDevis["totalTtc"] = $totalTtc;
$currentDevis["totalTva"] = $totalTva; $currentDevis["totalTva"] = $totalTva;
@ -5390,10 +5420,19 @@ COMMENTAIRES: ".$comment;
$factureTotalTva += $totalTva; $factureTotalTva += $totalTva;
$facture["devisList"][] = $currentDevis; $facture["devisList"][] = $currentDevis;
} }
$facture["totalHt"] = $factureTotalHt; $facture["totalHt"] = $factureTotalHt;
$facture["totalTtc"] = $factureTotalTtc; $facture["totalTtc"] = $factureTotalTtc;
$facture["totalTva"] = $factureTotalTva; $facture["totalTva"] = $factureTotalTva;
$facture["isFactureClientGroup"] = !$isFactureSingleClient; $facture["isFactureClientGroup"] = !$isFactureSingleClient;
// INFOS TVA POUR LE TEMPLATE
$facture["tvaInfo"] = [
'is_applicable' => $isTvaApplicable,
'rate' => $tvaValue,
'is_exempt' => !$isTvaApplicable
];
return $facture; return $facture;
} }

View File

@ -2,16 +2,17 @@
use OC\URLGenerator; use OC\URLGenerator;
use OCA\Gestion\Helpers\PriceHelpers; use OCA\Gestion\Helpers\PriceHelpers;
$facture = $_['facture']; $facture = $_['facture'];
$factureOrderNumber = $facture->facture_order_number == '' ? '-' : $facture->facture_order_number; $factureOrderNumber = $facture->facture_order_number == '' ? '-' : $facture->facture_order_number;
$factureCaseNumber = $facture->facture_case_number == '' ? '-' : $facture->facture_case_number; $factureCaseNumber = $facture->facture_case_number == '' ? '-' : $facture->facture_case_number;
$isFactureClientGroup = $facture->isFactureClientGroup; $isFactureClientGroup = $facture->isFactureClientGroup;
$currentConfig = json_decode($_['configuration'])[0]; $currentConfig = json_decode($_['configuration'])[0];
?> ?>
<div class="bootstrap-iso"> <div class="bootstrap-iso">
<div id="factureId" data-id="<?php echo $facture->id; ?>"></div> <div id="factureId" data-id="<?php echo $facture->id; ?>"></div>
<div id="factureIdentifier" data-id="<?php echo $facture->id; ?>"></div> <div id="factureIdentifier" data-id="<?php echo $facture->id; ?>"></div>
<h2 class="mt-3 mb-3 text-center"> <?php echo ('Facture n° '.$facture->num); ?> <h2 class="mt-3 mb-3 text-center"> <?php echo('Facture n° '.$facture->num); ?>
</h2> </h2>
<hr /> <hr />
<div class="row"> <div class="row">
@ -34,7 +35,7 @@ $currentConfig = json_decode($_['configuration'])[0];
} else { } else {
echo "<span style='font-size:12px' id='Company-logo' data-html2canvas-ignore><b><center>" . $l->t('You can add your company logo here.') . "</center></b><br/><i>" . $l->t('To add a logo, drop the logo.png file in ".gestion" folder at the root of your Nextcloud Files app. Remember to set "Show hidden files".') . "</i><br/><br/><center>" . $l->t('This message will not appear on generated PDF.') . "</center></span>"; echo "<span style='font-size:12px' id='Company-logo' data-html2canvas-ignore><b><center>" . $l->t('You can add your company logo here.') . "</center></b><br/><i>" . $l->t('To add a logo, drop the logo.png file in ".gestion" folder at the root of your Nextcloud Files app. Remember to set "Show hidden files".') . "</i><br/><br/><center>" . $l->t('This message will not appear on generated PDF.') . "</center></span>";
} }
?> ?>
</div> </div>
<div class="col-5 h-100 m-0" style="min-height:250px;"> <div class="col-5 h-100 m-0" style="min-height:250px;">
<h5 class="p-3 m-0 text-dark text-center border border-2 border-dark"><?php p($l->t('TO')); ?> <h5 class="p-3 m-0 text-dark text-center border border-2 border-dark"><?php p($l->t('TO')); ?>
@ -42,7 +43,7 @@ $currentConfig = json_decode($_['configuration'])[0];
<p style="min-height:180px;" <p style="min-height:180px;"
class="p-3 m-0 h-100 text-center text-dark text-center border border-top-0 border-2 border-dark"> class="p-3 m-0 h-100 text-center text-dark text-center border border-top-0 border-2 border-dark">
<span><?php echo $facture->group_name; ?></span><br /> <span><?php echo $facture->group_name; ?></span><br />
<?php if($isFactureClientGroup == false){ <?php if($isFactureClientGroup == false) {
?> ?>
<span><?php echo $facture->client_name; ?></span><br /> <span><?php echo $facture->client_name; ?></span><br />
<?php }?> <?php }?>
@ -88,8 +89,8 @@ $currentConfig = json_decode($_['configuration'])[0];
<tbody> <tbody>
<?php <?php
$devisList = $facture->devisList; $devisList = $facture->devisList;
foreach ($devisList as $currentDevis) { foreach ($devisList as $currentDevis) {
?> ?>
<tr> <tr>
<td><?php echo $currentDevis->devis_full_number; ?></td> <td><?php echo $currentDevis->devis_full_number; ?></td>
<td><?php echo $currentDevis->defunt_nom; ?></td> <td><?php echo $currentDevis->defunt_nom; ?></td>
@ -113,26 +114,43 @@ $currentConfig = json_decode($_['configuration'])[0];
class="mb-2 btn btn-outline-success sendmail" class="mb-2 btn btn-outline-success sendmail"
><?php p($l->t('Send by email'));?></button> ><?php p($l->t('Send by email'));?></button>
</div> </div>
<div class="mt-0 table-responsive"> <div class="mt-0 table-responsive">
<table id="totalFactureGroupPrice" class="table table-striped table-xl"> <table id="totalFactureGroupPrice" class="table table-striped table-xl">
<thead class="bg-dark text-white"> <thead class="bg-dark text-white">
<tr> <tr>
<th class="text-center"><?php p($l->t('Total without VAT')); ?></th> <th class="text-center"><?php p($l->t('Total without VAT')); ?></th>
<th class="text-center"><?php p($l->t('VAT Rate')); ?></th> <th class="text-center"><?php p($l->t('VAT Rate')); ?></th>
<th class="text-center"><?php p($l->t('Total VAT')); ?></th> <th class="text-center"><?php p($l->t('Total VAT')); ?></th>
<th class="text-center"><?php p($l->t('Total Price')); ?></th> <th class="text-center"><?php p($l->t('Total Price')); ?></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td class="text-center"><?php echo (PriceHelpers::formatDecimalPrice($facture->totalHt).'€'); ?></td> <td class="text-center"><?php echo PriceHelpers::formatDecimalPrice($facture->totalHt).'€'; ?></td>
<td class="text-center"><?php echo (PriceHelpers::formatDecimalPrice($currentConfig->tva_default).'€'); ?></td> <td class="text-center">
<td class="text-center"><?php echo (PriceHelpers::formatDecimalPrice($facture->totalTva).'€'); ?></td> <?php
<td class="text-center"><?php echo (PriceHelpers::formatDecimalPrice($facture->totalTtc).'€'); ?></td> // Affichage simple : Exonéré ou taux par défaut
</tr> if (isset($facture->tvaInfo) && $facture->tvaInfo->is_exempt) {
</tbody> echo 'Exonéré';
</table> } else {
</div> echo PriceHelpers::formatDecimalPrice($facture->tvaInfo->rate).'%';
}
?>
</td>
<td class="text-center">
<?php
if (isset($facture->tvaInfo) && $facture->tvaInfo->is_exempt) {
echo '0,00€';
} else {
echo PriceHelpers::formatDecimalPrice($facture->totalTva).'€';
}
?>
</td>
<td class="text-center"><?php echo PriceHelpers::formatDecimalPrice($facture->totalTtc).'€'; ?></td>
</tr>
</tbody>
</table>
</div>
<div class="col m-0 pb-0 alert alert-info text-center"> <div class="col m-0 pb-0 alert alert-info text-center">
<p><span id="mentions_default"><?php p($l->t('Please set in global configuration')); ?></span></p> <p><span id="mentions_default"><?php p($l->t('Please set in global configuration')); ?></span></p>
</div> </div>