✨ feat(devis): Gère l'affichage et les calculs des promotions, cautions et formules
This commit is contained in:
@@ -432,6 +432,10 @@ class ContratPdfService extends Fpdf
|
||||
$this->Ln(6);
|
||||
|
||||
// --- 3. TABLEAU FINANCIER ---
|
||||
$devis = $this->contrats->getDevis();
|
||||
$formule = $devis?->getFormule();
|
||||
$promotion = $devis?->getOrderSession()?->getPromotion();
|
||||
|
||||
$interval = $this->contrats->getDateAt()->diff($this->contrats->getEndAt());
|
||||
$nbJoursTotal = $interval->days + 1;
|
||||
$nbJoursSup = max(0, $nbJoursTotal - 1);
|
||||
@@ -448,30 +452,100 @@ class ContratPdfService extends Fpdf
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$totalHt = 0; $totalCaution = 0;
|
||||
$isFormuleLineAdded = false;
|
||||
|
||||
foreach ($this->contrats->getContratsLines() as $line) {
|
||||
$sousTotal = $line->getPrice1DayHt() + ($line->getPriceSupDayHt() * $nbJoursSup);
|
||||
$price1Day = $line->getPrice1DayHt();
|
||||
$priceSup = $line->getPriceSupDayHt();
|
||||
|
||||
// Si formule, on force les prix à 0
|
||||
if ($formule) {
|
||||
$price1Day = 0;
|
||||
$priceSup = 0;
|
||||
}
|
||||
|
||||
$sousTotal = $price1Day + ($priceSup * $nbJoursSup);
|
||||
|
||||
// Gestion Formule Line
|
||||
if ($formule && !$isFormuleLineAdded && $price1Day == 0 && $priceSup == 0) {
|
||||
$fPrice = $formule->getPrice1j() ?? 0;
|
||||
if ($nbJoursTotal >= 2 && $formule->getPrice2j()) $fPrice = $formule->getPrice2j();
|
||||
if ($nbJoursTotal >= 5 && $formule->getPrice5j()) $fPrice = $formule->getPrice5j();
|
||||
|
||||
$totalHt += $fPrice;
|
||||
$totalCaution += $formule->getCaution() ?? 0;
|
||||
|
||||
$this->Cell(85, 7, $this->clean("Formule : " . $formule->getName()), 1, 0, 'L');
|
||||
$this->Cell(25, 7, number_format($fPrice, 2, ',', ' ') . $this->euro(), 1, 0, 'R');
|
||||
$this->Cell(15, 7, $nbJoursTotal . " j.", 1, 0, 'C');
|
||||
$this->Cell(25, 7, $tvaLabel, 1, 0, 'C');
|
||||
$this->Cell(40, 7, number_format($fPrice, 2, ',', ' ') . $this->euro(), 1, 1, 'R');
|
||||
|
||||
$isFormuleLineAdded = true;
|
||||
}
|
||||
|
||||
// Caution
|
||||
if (!$formule) {
|
||||
$totalCaution += $line->getCaution();
|
||||
}
|
||||
|
||||
$totalHt += $sousTotal;
|
||||
$totalCaution += $line->getCaution();
|
||||
|
||||
$this->Cell(85, 7, $this->clean($line->getName()), 1, 0, 'L');
|
||||
$this->Cell(25, 7, number_format($line->getPrice1DayHt(), 2, ',', ' ') . $this->euro(), 1, 0, 'R');
|
||||
$this->Cell(25, 7, ($price1Day == 0 ? "Inclus" : number_format($price1Day, 2, ',', ' ') . $this->euro()), 1, 0, 'R');
|
||||
$this->Cell(15, 7, $nbJoursTotal . " j.", 1, 0, 'C');
|
||||
$this->Cell(25, 7, $tvaLabel, 1, 0, 'C');
|
||||
$this->Cell(40, 7, number_format($sousTotal, 2, ',', ' ') . $this->euro(), 1, 1, 'R');
|
||||
$this->Cell(40, 7, ($sousTotal == 0 && $price1Day == 0 ? "Inclus" : number_format($sousTotal, 2, ',', ' ') . $this->euro()), 1, 1, 'R');
|
||||
}
|
||||
|
||||
foreach ($this->contrats->getContratsOptions() as $opt) {
|
||||
$totalHt += $opt->getPrice();
|
||||
$priceOpt = $opt->getPrice();
|
||||
$optionName = $opt->getName();
|
||||
|
||||
// Si formule, options gratuites sauf livraison
|
||||
if ($formule) {
|
||||
$isDelivery = stripos($optionName, 'livraison') !== false || stripos($optionName, 'déplacement') !== false;
|
||||
if (!$isDelivery) {
|
||||
$priceOpt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$totalHt += $priceOpt;
|
||||
$this->SetFillColor(245, 245, 245);
|
||||
$this->Cell(85, 7, $this->clean("[Option] " . $opt->getName()), 1, 0, 'L', true);
|
||||
$this->Cell(25, 7, number_format($opt->getPrice(), 2, ',', ' ') . $this->euro(), 1, 0, 'R', true);
|
||||
$this->Cell(85, 7, $this->clean("[Option] " . $optionName), 1, 0, 'L', true);
|
||||
$this->Cell(25, 7, ($priceOpt == 0 ? "Inclus" : number_format($priceOpt, 2, ',', ' ') . $this->euro()), 1, 0, 'R', true);
|
||||
$this->Cell(15, 7, "Forfait", 1, 0, 'C', true);
|
||||
$this->Cell(25, 7, $tvaLabel, 1, 0, 'C', true);
|
||||
$this->Cell(40, 7, number_format($opt->getPrice(), 2, ',', ' ') . $this->euro(), 1, 1, 'R', true);
|
||||
$this->Cell(40, 7, ($priceOpt == 0 ? "Inclus" : number_format($priceOpt, 2, ',', ' ') . $this->euro()), 1, 1, 'R', true);
|
||||
}
|
||||
|
||||
// --- 4. RÉCAPITULATIF FINANCIER ---
|
||||
|
||||
// Gestion Promotion
|
||||
if ($promotion) {
|
||||
$percentage = $promotion['percentage'] ?? 0;
|
||||
$name = $promotion['name'] ?? 'Remise';
|
||||
$discountAmount = $totalHt * ($percentage / 100);
|
||||
|
||||
// Ligne Total HT Avant Remise
|
||||
$this->Ln(5);
|
||||
$this->SetX(110);
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$this->SetTextColor(100, 100, 100);
|
||||
$this->Cell(50, 7, $this->clean("Total HT Avant Remise"), 'B', 0, 'L');
|
||||
$this->Cell(40, 7, number_format($totalHt, 2, ',', ' ') . $this->euro(), 'B', 1, 'R');
|
||||
|
||||
// Ligne Promotion
|
||||
$this->Ln();
|
||||
$this->SetX(110);
|
||||
$this->SetTextColor(37, 99, 235);
|
||||
$this->Cell(50, 7, $this->clean("Promotion : $name (-$percentage%)"), 'B', 0, 'L');
|
||||
$this->Cell(40, 7, "- " . number_format($discountAmount, 2, ',', ' ') . $this->euro(), 'B', 1, 'R');
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
|
||||
$totalHt -= $discountAmount;
|
||||
}
|
||||
|
||||
$amountTva = $totalHt * $tvaRate;
|
||||
$totalTtc = $totalHt + $amountTva;
|
||||
$arrhes = $totalTtc * 0.25; // Arrhes calculées sur le TTC
|
||||
@@ -479,7 +553,10 @@ class ContratPdfService extends Fpdf
|
||||
$this->Ln(5);
|
||||
$this->SetX(110);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
$this->Cell(50, 7, $this->clean("TOTAL HT"), 'B', 0, 'L');
|
||||
|
||||
$lblTotal = $promotion ? "TOTAL HT REMISÉ" : "TOTAL HT";
|
||||
|
||||
$this->Cell(50, 7, $this->clean($lblTotal), 'B', 0, 'L');
|
||||
$this->Cell(40, 7, number_format($totalHt, 2, ',', ' ') . $this->euro(), 'B', 1, 'R');
|
||||
|
||||
if($tvaEnabled) {
|
||||
|
||||
@@ -5,7 +5,6 @@ GREEN='\033[0;32m'
|
||||
CYAN='\033[0;36m'
|
||||
RESET='\033[0m' # Reset color to default
|
||||
|
||||
php bin/console app:git-log-update
|
||||
echo "${CYAN}####################################${RESET}"
|
||||
echo "${CYAN}# LUDIKEVENT INTRANET UPDATE START #${RESET}"
|
||||
echo "${CYAN}####################################${RESET}"
|
||||
|
||||
Reference in New Issue
Block a user