feat add is_tva group facture
This commit is contained in:
parent
477196fa39
commit
96d117ead5
@ -5318,7 +5318,7 @@ COMMENTAIRES: ".$comment;
|
||||
$configuration = $this->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
|
||||
$configuration = json_decode($configuration);
|
||||
$currentConfig = $configuration[0];
|
||||
$tvaValue = $currentConfig->tva_default;
|
||||
|
||||
$isFactureSingleClient = $facture['fk_client_id'] != null
|
||||
&& $facture['fk_client_id'] != 0;
|
||||
|
||||
@ -5329,6 +5329,21 @@ COMMENTAIRES: ".$comment;
|
||||
$devis = $this->getDevisByFkFactureId($factureId);
|
||||
$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) {
|
||||
$client = $this->getClientById($facture['fk_client_id']);
|
||||
@ -5337,6 +5352,7 @@ COMMENTAIRES: ".$comment;
|
||||
$facture['client_address'] = $client["client_address"];
|
||||
$facture['siret'] = $client["client_legal_one"];
|
||||
$facture['mail'] = $client["client_mail"];
|
||||
|
||||
if (!$factureGroupIsRelatedToAnyDevis) {
|
||||
$devisList = $this->getDevisDataByClientIdAndMonthYear(
|
||||
$facture['fk_client_id'],
|
||||
@ -5344,7 +5360,6 @@ COMMENTAIRES: ".$comment;
|
||||
$facture['year'],
|
||||
$devisMentionFilters
|
||||
);
|
||||
|
||||
} else {
|
||||
$devisList = $this->getDevisDataGroupByFactureId($factureId, $devisMentionFilters);
|
||||
}
|
||||
@ -5355,6 +5370,7 @@ COMMENTAIRES: ".$comment;
|
||||
$facture['client_address'] = $clientGroupFacturation["address"] . ' - ' .$clientGroupFacturation["postal_code"] . ' ' . $clientGroupFacturation['city'];
|
||||
$facture['siret'] = $clientGroupFacturation["siret_number"];
|
||||
$facture['mail'] = $clientGroupFacturation["email"];
|
||||
|
||||
if (!$factureGroupIsRelatedToAnyDevis) {
|
||||
$devisList = $this->getDevisDataByClientGroupFacturationIdAndMonthYear(
|
||||
$facture['fk_client_group_facturation_id'],
|
||||
@ -5366,22 +5382,36 @@ COMMENTAIRES: ".$comment;
|
||||
$devisList = $this->getDevisDataGroupByFactureId($factureId, $devisMentionFilters);
|
||||
}
|
||||
}
|
||||
|
||||
$factureTotalHt = 0;
|
||||
$factureTotalTva = 0;
|
||||
$factureTotalTtc = 0;
|
||||
|
||||
foreach($devisList as &$currentDevis) {
|
||||
$totalHt = 0;
|
||||
$totalTva = 0;
|
||||
$totalTtc = 0;
|
||||
$devisProducts = $this->getDevisProduits($currentDevis['devis_id']);
|
||||
|
||||
foreach($devisProducts as $currentProduct) {
|
||||
$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;
|
||||
$totalTtc += $valueTtc;
|
||||
$tvaAmount = $valueTtc - $valueHt;
|
||||
$totalTva += $tvaAmount;
|
||||
}
|
||||
|
||||
$currentDevis["totalHt"] = $totalHt;
|
||||
$currentDevis["totalTtc"] = $totalTtc;
|
||||
$currentDevis["totalTva"] = $totalTva;
|
||||
@ -5390,10 +5420,19 @@ COMMENTAIRES: ".$comment;
|
||||
$factureTotalTva += $totalTva;
|
||||
$facture["devisList"][] = $currentDevis;
|
||||
}
|
||||
|
||||
$facture["totalHt"] = $factureTotalHt;
|
||||
$facture["totalTtc"] = $factureTotalTtc;
|
||||
$facture["totalTva"] = $factureTotalTva;
|
||||
$facture["isFactureClientGroup"] = !$isFactureSingleClient;
|
||||
|
||||
// INFOS TVA POUR LE TEMPLATE
|
||||
$facture["tvaInfo"] = [
|
||||
'is_applicable' => $isTvaApplicable,
|
||||
'rate' => $tvaValue,
|
||||
'is_exempt' => !$isTvaApplicable
|
||||
];
|
||||
|
||||
return $facture;
|
||||
}
|
||||
|
||||
|
||||
@ -2,16 +2,17 @@
|
||||
|
||||
use OC\URLGenerator;
|
||||
use OCA\Gestion\Helpers\PriceHelpers;
|
||||
|
||||
$facture = $_['facture'];
|
||||
$factureOrderNumber = $facture->facture_order_number == '' ? '-' : $facture->facture_order_number;
|
||||
$factureCaseNumber = $facture->facture_case_number == '' ? '-' : $facture->facture_case_number;
|
||||
$isFactureClientGroup = $facture->isFactureClientGroup;
|
||||
$isFactureClientGroup = $facture->isFactureClientGroup;
|
||||
$currentConfig = json_decode($_['configuration'])[0];
|
||||
?>
|
||||
<div class="bootstrap-iso">
|
||||
<div id="factureId" 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>
|
||||
<hr />
|
||||
<div class="row">
|
||||
@ -34,7 +35,7 @@ $currentConfig = json_decode($_['configuration'])[0];
|
||||
} 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>";
|
||||
}
|
||||
?>
|
||||
?>
|
||||
</div>
|
||||
<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')); ?>
|
||||
@ -42,7 +43,7 @@ $currentConfig = json_decode($_['configuration'])[0];
|
||||
<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">
|
||||
<span><?php echo $facture->group_name; ?></span><br />
|
||||
<?php if($isFactureClientGroup == false){
|
||||
<?php if($isFactureClientGroup == false) {
|
||||
?>
|
||||
<span><?php echo $facture->client_name; ?></span><br />
|
||||
<?php }?>
|
||||
@ -88,8 +89,8 @@ $currentConfig = json_decode($_['configuration'])[0];
|
||||
<tbody>
|
||||
<?php
|
||||
$devisList = $facture->devisList;
|
||||
foreach ($devisList as $currentDevis) {
|
||||
?>
|
||||
foreach ($devisList as $currentDevis) {
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $currentDevis->devis_full_number; ?></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"
|
||||
><?php p($l->t('Send by email'));?></button>
|
||||
</div>
|
||||
<div class="mt-0 table-responsive">
|
||||
<table id="totalFactureGroupPrice" class="table table-striped table-xl">
|
||||
<thead class="bg-dark text-white">
|
||||
<tr>
|
||||
<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('Total VAT')); ?></th>
|
||||
<th class="text-center"><?php p($l->t('Total Price')); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<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"><?php echo (PriceHelpers::formatDecimalPrice($facture->totalTva).'€'); ?></td>
|
||||
<td class="text-center"><?php echo (PriceHelpers::formatDecimalPrice($facture->totalTtc).'€'); ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="mt-0 table-responsive">
|
||||
<table id="totalFactureGroupPrice" class="table table-striped table-xl">
|
||||
<thead class="bg-dark text-white">
|
||||
<tr>
|
||||
<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('Total VAT')); ?></th>
|
||||
<th class="text-center"><?php p($l->t('Total Price')); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="text-center"><?php echo PriceHelpers::formatDecimalPrice($facture->totalHt).'€'; ?></td>
|
||||
<td class="text-center">
|
||||
<?php
|
||||
// Affichage simple : Exonéré ou taux par défaut
|
||||
if (isset($facture->tvaInfo) && $facture->tvaInfo->is_exempt) {
|
||||
echo 'Exonéré';
|
||||
} else {
|
||||
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">
|
||||
<p><span id="mentions_default"><?php p($l->t('Please set in global configuration')); ?></span></p>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user