THANASOFT-HFC/gestion/templates/content/apercustousdevis.php
2025-10-23 00:14:07 +03:00

360 lines
19 KiB
PHP

<div class="d-flex flex-column w-100 p-4">
<div class="d-flex justify-content-between">
<form method="get" class="d-flex flex-row align-items-center">
<select name="cli" id="clientselector">
<?php
$showRecapButton = false;
foreach ($_['clients'] as $key => $client) {
?>
<option <?php
if ($_GET['cli'] == $client->id && $_GET['filterType'] == $client->client_type) {
echo 'selected';
}
?> value='<?php echo $client->id; ?>' data-type='<?php echo $client->client_type ?>'>
<?php echo strtoupper(html_entity_decode($client->nom)); ?>
</option>
<?php
}
?>
</select>&nbsp;&nbsp;
<select name="annee" id="yearselector">
<option value="-1" <?php if ((int) $_GET['annee'] == -1) {
echo 'selected';
} ?>>Toutes les années</option>
<?php
$currentYear = date('Y');
for ($year = $currentYear; $year >= $currentYear - 10; $year--) {
echo '<option value="' . $year . '" ' . ((int) $_GET['annee'] == $year ? 'selected' : '') . '>' . $year . '</option>';
}
?>
</select>&nbsp;&nbsp;
<select name="mois" id="monthselector">
<option value="0" <?php if ((int) $_GET['mois'] == 0) {
echo 'selected';
} ?>>Tous les mois</option>
<option value="1" <?php if ((int) $_GET['mois'] == 1) {
echo 'selected';
} ?>>Janvier</option>
<option value="2" <?php if ((int) $_GET['mois'] == 2) {
echo 'selected';
} ?>>Fevrier</option>
<option value="3" <?php if ((int) $_GET['mois'] == 3) {
echo 'selected';
} ?>>Mars</option>
<option value="4" <?php if ((int) $_GET['mois'] == 4) {
echo 'selected';
} ?>>Avril</option>
<option value="5" <?php if ((int) $_GET['mois'] == 5) {
echo 'selected';
} ?>>Mai</option>
<option value="6" <?php if ((int) $_GET['mois'] == 6) {
echo 'selected';
} ?>>Juin</option>
<option value="7" <?php if ((int) $_GET['mois'] == 7) {
echo 'selected';
} ?>>Juillet</option>
<option value="8" <?php if ((int) $_GET['mois'] == 8) {
echo 'selected';
} ?>>Août</option>
<option value="9" <?php if ((int) $_GET['mois'] == 9) {
echo 'selected';
} ?>>Septembre</option>
<option value="10" <?php if ((int) $_GET['mois'] == 10) {
echo 'selected';
} ?>>Octobre</option>
<option value="11" <?php if ((int) $_GET['mois'] == 11) {
echo 'selected';
} ?>>Novembre</option>
<option value="12" <?php if ((int) $_GET['mois'] == 12) {
echo 'selected';
} ?>>Decembre</option>
</select>&nbsp;&nbsp;
<input type="hidden" name="filterType" id="filterType"
value="<?php echo($_GET['filterType'] ?? 'group'); ?>">
<input type="submit" value="Filtrer" />
</form>
<div class="d-flex flex-row">
<?php
$clients = $_['clients'];
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if(intval($_GET['mois']) != 0 && intval($_GET['annee']) != 0) {
$showRecapButton = true;
}
$devis = array_filter($_['devis'], function ($currentDevis) {
if ($currentDevis->cid) {
$datesplit = explode("-", $currentDevis->date);
$year = (int) $datesplit[0];
$month = (int) $datesplit[1];
$checkClient = false;
$filterType = "group";
if (array_key_exists('filterType', $_GET) && $_GET['filterType'] == 'client') {
$filterType = "client";
}
$clientIsNotSelected = strcmp($_GET['cli'], '') == 0;
if ($clientIsNotSelected) {
if ($filterType == "group") {
$checkClient = $_['clients'][0]->fk_client_group_facturation_id == $currentDevis->cid;
} else {
$checkClient = $_['clients'][0]->id == $currentDevis->cid;
}
} else {
if ($filterType == "group") {
$checkClient = $currentDevis->fk_client_group_facturation_id == $_GET['cli'];
} else {
$checkClient = $currentDevis->cid == $_GET['cli'];
}
}
$checkYear = ((int) ($_GET['annee']) == -1) ? (true) : ($year == ((int) $_GET['annee']));
$checkMounth = (((int) $_GET['mois']) == 0) ? (true) : ($month == ((int) $_GET['mois']));
return $checkClient && $checkYear && $checkMounth;
}
return false;
});
if (strcmp($_GET['cli'], '') != 0 && sizeof($devis) > 0) {
?>
<button class="btn btn-secondary" type="button"
id="exportMultipleDevisToPdf"><?php p($l->t('Save in Nextcloud')); ?></button>
<button class="btn btn-secondary" type="button" id="showGroupDevisFacturationModal" data-toggle="modal"
data-target="#groupDevisFacturationModal">
Facturer
</button>
<?php
}
if (strcmp($_GET['cli'], '') != 0 && sizeof($devis) > 0) {
?>
<?php if($showRecapButton) {?><button class="btn btn-secondary" type="button" id="showDevisRecapModal" data-toggle="modal"
data-target="#devisRecapMontant">Generer le document recapitulatif</button><?php }
}
}
?>
</div>
</div>
<hr>
<div id="gestion-canvas" class="canvas_div_pdf">
<?php
if ($_SERVER['REQUEST_METHOD'] == 'GET' && strcmp($_GET['cli'], '') != 0) {
if (sizeof($devis) == 0) {
echo "Aucun devis trouvé.";
}
}
;
foreach ($devis as $key => $currentDevis) {
?>
<div class="bootstrap-iso d-flex flex-column justify-content-between">
<div class="d-flex flex-column w-100">
<h2 class="mt-3 mb-3 text-center"> <?php p($l->t('Quote')); ?>
<div id="devisid" style="display:inline" data-table="devis" data-column="num"
data-id="<?php echo $currentDevis->id; ?>">sur le defunt <?php echo $currentDevis->nom_defunt; ?></div>
</h2>
<div class="row">
<div class="col col-md">
<label class="fw-bold"><?php p($l->t('Number')); ?> : </label>
<div class="col col-xl mb-3 text-center" style="display:inline">
<?php echo $currentDevis->num; ?>
</div>
</div>
<div class="col col-md">
<label class="fw-bold"><?php p($l->t('Date')); ?> : </label>
<div class="col col-xl mb-3 text-center" style="display:inline">
<?php echo $currentDevis->date; ?>
</div>
</div>
</div>
<div class="row">
<div class="col col-md">
<div class="d-flex flex-column">
<span>Defunt : <b><?php echo $currentDevis->nom_defunt; ?></b></span>
<span>Lieu : <b><?php echo $currentDevis->lieu; ?> (<?php echo $currentDevis->adresse_soin; ?>)</b>
</div>
</div>
</div>
<div class="row">
<div class="col col-md">
<label class="fw-bold">Commande :</label>
<div class="col col-xl mb-3 text-center editable"
style="display:inline"
data-table="devis" data-column="order_number"
data-id="<?php echo $currentDevis->id;?>">
<?php echo ($currentDevis->order_number == "") ? "-" : $currentDevis->order_number ; ?>
</div>
</div>
<hr />
</div>
<div class="row">
<div class="col col-md">
<label class="fw-bold">Numéro de dossier :</label>
<div class="col col-xl mb-3 text-center editable"
style="display:inline"
data-table="devis" data-column="case_number"
data-id="<?php echo $currentDevis->id;?>">
<?php echo ($currentDevis->case_number == "") ? "-" : $currentDevis->case_number ; ?>
</div>
</div>
<hr />
</div>
<div class="table-responsive">
<table id="produits" data-type="facture" class="table table-striped">
<thead>
<tr>
<th><?php p($l->t('Reference')); ?></th>
<th><?php p($l->t('Designation')); ?></th>
<th><?php p($l->t('Comment')); ?></th>
<th><?php p($l->t('TVA'));?></th>
<th><?php p($l->t('Quantity')); ?></th>
<th><?php p($l->t('Unit price without VAT'));?></th>
<th><?php p($l->t('Total without VAT'));?></th>
<th><?php p($l->t('Total with VAT'));?></th>
</tr>
</thead>
<tbody>
<?php
// ⭐ NOUVEAU: Grouper par taux de TVA pour les calculs
$totalsByTva = [];
foreach ($currentDevis->dproduits as $key => $produit) {
// Récupérer le taux de TVA du produit (défaut 20%)
$tvaValue = isset($produit->tva) && $produit->tva !== null ? floatval($produit->tva) : 20.00;
$totalHT = $produit->prix_unitaire * $produit->quantite;
$totalTTC = $totalHT * (1 + $tvaValue / 100);
// Grouper par taux
if (!isset($totalsByTva[$tvaValue])) {
$totalsByTva[$tvaValue] = [
'totalHT' => 0,
'totalTVA' => 0,
'totalTTC' => 0
];
}
$totalsByTva[$tvaValue]['totalHT'] += $totalHT;
$totalsByTva[$tvaValue]['totalTVA'] += ($totalTTC - $totalHT);
$totalsByTva[$tvaValue]['totalTTC'] += $totalTTC;
?>
<tr>
<td><?php echo $produit->reference ?></td>
<td><?php echo $produit->description ?></td>
<td><?php echo $produit->comment ?></td>
<td><?php echo number_format($tvaValue, 0) ?>%</td>
<td><?php echo $produit->quantite ?></td>
<td>&euro;<?php echo number_format($produit->prix_unitaire, 2) ?></td>
<td>&euro;<?php echo number_format($totalHT, 2) ?></td>
<td>&euro;<?php echo number_format($totalTTC, 2) ?></td>
</tr>
<?php }
// ⭐ NOUVEAU: Trier par taux
ksort($totalsByTva);
// ⭐ NOUVEAU: Afficher les totaux par TVA dans le tableau
if (count($totalsByTva) > 0) {
?>
<tr class="table-secondary">
<td colspan="8"><hr style="border-top: 2px solid #000; margin: 5px 0;"></td>
</tr>
<?php
foreach ($totalsByTva as $tva => $totals) {
?>
<tr class="fw-bold">
<td colspan="3">Total TVA <?php echo number_format($tva, 0) ?>%</td>
<td></td>
<td></td>
<td></td>
<td>&euro;<?php echo number_format($totals['totalHT'], 2) ?></td>
<td>&euro;<?php echo number_format($totals['totalTTC'], 2) ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
<div class="mt-0 table-responsive">
<table id="totaldevis" 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('Total VAT')); ?></th>
<th class="text-center"><?php p($l->t('Total Price')); ?></th>
</tr>
</thead>
<tbody>
<?php
// ⭐ NOUVEAU: Calculer les totaux généraux
$totalGeneralHT = 0;
$totalGeneralTVA = 0;
$totalGeneralTTC = 0;
foreach ($totalsByTva as $totals) {
$totalGeneralHT += $totals['totalHT'];
$totalGeneralTVA += $totals['totalTVA'];
$totalGeneralTTC += $totals['totalTTC'];
}
?>
<tr class="fw-bold">
<td class="text-center">&euro;<?php echo number_format($totalGeneralHT, 2) ?></td>
<td class="text-center">&euro;<?php echo number_format($totalGeneralTVA, 2) ?></td>
<td class="text-center">&euro;<?php echo number_format($totalGeneralTTC, 2) ?></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="d-flex flex-column w-100">
<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>
<hr />
<div class="col m-0 pb-0 alert alert-info text-center">
<p><?php echo $res->entreprise; ?><br /><?php echo $res->adresse; ?><br /><?php echo $res->legal_one; ?><br /><?php echo $res->legal_two; ?>
</p>
</div>
</div>
</div>
<hr data-html2canvas-ignore>
<hr data-html2canvas-ignore>
<hr data-html2canvas-ignore>
<?php
}
?>
</div>
<div class="modal" id="devisRecapMontant" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Récapitulatif des devis avec montant</h5>
</div>
<div class="modal-body">
<div class="form-check d-flex align-items-center">
<input class="form-check-input me-2" type="checkbox" id="sansMontant" value="">
<label class="form-check-label" for="sansMontant">
Sans Montant
</label>
</div>
</div>
<div class="modal-footer">
<button id="closeDevisRecapModal" type="button" class="btn btn-secondary">Annuler</button>
<button id="devisRecapAction" type="button" class="btn btn-primary">Générer</button>
</div>
</div>
</div>
</div>
<div class="modal" id="groupDevisFacturationModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Choisir la date de facturation souhaitée</h5>
</div>
<div class="modal-body">
<input type="date" id="facturationDate">
</div>
<div class="modal-footer">
<button id="closeGroupDevisModal" type="button" class="btn btn-secondary">Annuler</button>
<button id="invoiceGroupQuote" type="button" class="btn btn-primary">Facturer</button>
</div>
</div>
</div>
</div>
</div>