* * @author Anna Larch * @author Richard Steinmetz * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see . * */ namespace OCA\Gestion\Service\InvoiceGroupPdfHandler; use DateTime; use OCA\Gestion\Helpers\FileExportHelpers; use OCA\Gestion\Helpers\PriceHelpers; class InvoiceFunecapPdfHandler extends InvoiceGroupPdfHandler { public int $maxArticlePerPage = 6; public function DrawInvoiceClientInfo(){ $this->SetFont('ComicSans', '', 10); $clientName = $this->factureData['group_name']; $clientInfoXAxis = 125; $clientAddress = $this->factureData['client_real_adress']; $clientAdressWidth = $this->GetStringWidth($clientAddress); $maxWidth = $this->GetPageWidth(); $availableWidhtForClientInfo = $maxWidth - 10 - $clientInfoXAxis; $clientAdressIsMultiline = $clientAdressWidth > $availableWidhtForClientInfo; $clientInfoYAxis = $clientAdressIsMultiline ? 35 : 40; $this->SetXY($clientInfoXAxis,$clientInfoYAxis); $this->Cell(0, 5, FileExportHelpers::FormatTextForExport($clientName)); $clientInfoYAxis += 5; $this->SetXY($clientInfoXAxis,$clientInfoYAxis); $this->MultiCell( 0, 5, trim(FileExportHelpers::FormatTextForExport($clientAddress))); if($clientAdressIsMultiline){ $clientInfoYAxis += 5; } $clientInfoYAxis += 5; $this->SetXY($clientInfoXAxis,$clientInfoYAxis); $this->Cell(0, 5, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city']))); } public function DrawInvoiceInfoTable(){ $this->setY(67); $factureDatePaiement = $this->factureData['date_paiement']; $factureDatePaiement = DateTime::createFromFormat('Y-m-d',$factureDatePaiement); $factureDateEcheance = $factureDatePaiement; $factureDatePaiement = $factureDatePaiement->format('d-m-Y'); $factureDateEcheance->modify('last day of next month'); $factureDateEcheance = $factureDateEcheance->format('d-m-Y'); $this->SetFont('ComicSans', 'B', 11); $this->Cell(30, 7, 'DATE', 1, 0, 'C'); $this->Cell(94, 7, 'CLIENT', 1, 0, 'C'); $this->Cell(40, 7, 'FACTURE', 1, 0, 'C'); $this->Cell(40, 7, 'ECHEANCE', 1, 1, 'C'); $this->SetFont('ComicSans', '', 10); $this->Cell(30, 7, $factureDatePaiement, 1, 0, 'C'); $this->Cell(94, 7, utf8_decode(html_entity_decode($this->factureData['group_name'])), 1, 0, 'C'); $this->Cell(40, 7, $this->factureData['num'], 1, 0, 'C'); $this->Cell(40, 7, $factureDateEcheance, 1, 1, 'C'); $this->startingYOfArticlesTable = 85; } public function DrawArticlesTableValue(){ $this->SetFont('ComicSans','',10); $devisData = $this->factureData['devis']; $tvaValue = $this->factureData["configuration"]->tva_default; $totalHt = 0; $totalTtc = 0; $totalTva = 0; $yValue = $this->startingYOfArticlesTable + 11; $maxDescriptionWidth = 98; $currentIndexPosition = $this->currentIndexPosition; for($currentIndexPosition;$currentIndexPosition<($this->initialIndexPosition + $this->devisCountToGet);$currentIndexPosition++){ $currentDevis = $devisData[$currentIndexPosition]; $devisDate = $currentDevis['devis_date']; $devisDate = DateTime::createFromFormat('Y-m-d',$devisDate); $devisDate = $devisDate->format('d-m-Y'); $products = $currentDevis["products"]; $subcontractorOrderNumberText = "Numéro de sous traitance ".$currentDevis["order_number"]; $subcontractorCaseNumberText = "Numéro de dossier ".$currentDevis["case_number"]; $this->SetXY( 35,$yValue ); $this->MultiAlignCell(100, 6, FileExportHelpers::FormatTextForExport($subcontractorOrderNumberText),0,'0',); $yValue += 6; $this->SetXY( 35,$yValue ); $this->MultiAlignCell(100, 6, FileExportHelpers::FormatTextForExport($subcontractorCaseNumberText),0,'0',); $yValue += 6; foreach($products as $product){ $valueHt = $product['produit_price']; $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt,$tvaValue); $totalHt+=$valueHt; $totalTtc+=$valueTtc; $productDescription = $product["produit_description"] ?? ""; $dateValue = ""; if($product === end($products)){ $dateValue = $devisDate; $productDescription .= " de " . $currentDevis["defunt_nom"] ?? ""; } $productDescriptionWidth = $this->GetStringWidth($productDescription); $productDescriptionIsMultiline = $productDescriptionWidth > $maxDescriptionWidth; $tvaAmount = $valueTtc - $valueHt; $this->SetXY( 8,$yValue ); $this->Cell(20, 6, $dateValue, 0,0); $this->SetXY( 35,$yValue ); $this->MultiAlignCell(100, 6, FileExportHelpers::FormatTextForExport($productDescription),0,'0',); $this->SetXY( 138,$yValue ); $this->Cell(20, 6, number_format($valueHt,2,'.','').chr(128), 0, 0, 'C'); $this->SetXY( 160,$yValue ); $this->Cell(20, 6, number_format($tvaAmount,2,'.','').chr(128), 0, 0, 'C'); $this->SetXY( 181,$yValue ); $this->Cell(25, 6, number_format($valueTtc,2,'.','').chr(128), 0, 1, 'C'); $yValue += 6; $totalTva += $tvaAmount; if($productDescriptionIsMultiline){ $yValue += 6; } } $yValue += 2; } $this->currentIndexPosition = $currentIndexPosition; $this->initialIndexPosition = $this->currentIndexPosition; $chargedDevisCount = $this->currentIndexPosition + 1; var_dump("CURRENT POSITION : ".$this->currentIndexPosition); var_dump("CHARGED DEVIS COUNT : ".$chargedDevisCount); $devisLeftToGet = $this->devisCount - $chargedDevisCount; var_dump("LEFT TO GET : ".$devisLeftToGet); $this->devisCountToGet = ($devisLeftToGet <= $this->maxArticlePerPage) ? $devisLeftToGet + 1 : $this->maxArticlePerPage; var_dump("DEVIS COUNT TO GET : ".$this->devisCountToGet); } }