* * @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 DrawArticlesTableValue(){ $this->SetFont('Arial','',10); $devisData = $this->factureData['devis']; $tvaValue = $this->factureData["configuration"]->tva_default; $totalHt = 0; $totalTtc = 0; $totalTva = 0; $yValue = $this->startingYOfArticlesTable + 13; $maxDescriptionWidth = 102; $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( 30,$yValue ); $this->MultiAlignCell(100, 6, FileExportHelpers::FormatTextForExport($subcontractorOrderNumberText),0,'0',); $yValue += 6; $this->SetXY( 30,$yValue ); $this->MultiAlignCell(100, 6, FileExportHelpers::FormatTextForExport($subcontractorCaseNumberText),0,'0',); $yValue += 6; foreach($products as $product){ $valueHt = $product['produit_price'] * $product["quantite"]; $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"] ?? ""; } $tvaAmount = $valueTtc - $valueHt; $this->SetXY( 4.5,$yValue ); $this->Cell(5, 6, $dateValue, 0,0); $this->SetXY( 30,$yValue ); $productDescription = FileExportHelpers::FormatTextForExport($productDescription); $productDescriptionWidth = $this->GetStringWidth($productDescription); $productDescriptionWidthIsGreaterThanMaxWidth = $productDescriptionWidth > $maxDescriptionWidth; $productDescriptionIsMultiline = false; if ($productDescriptionWidthIsGreaterThanMaxWidth) { $yBefore = $this->GetY(); $this->MultiCell($maxDescriptionWidth, 6, $productDescription,0,'L'); $yAfter = $this->GetY(); $productDescriptionIsMultiline = ($yAfter - $yBefore) > 6; if($productDescriptionIsMultiline){ $this->SetXY($this->GetX(),$yBefore); } } else { $this->Cell($maxDescriptionWidth, 6, $productDescription); } $this->SetXY( 144,$yValue ); $this->Cell(20, 6, number_format($valueHt,2,'.','').chr(128), 0, 0, 'C'); $this->SetXY( 165,$yValue ); $this->Cell(20, 6, number_format($tvaAmount,2,'.','').chr(128), 0, 0, 'C'); $this->SetXY( 182,$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; $devisLeftToGet = $this->devisCount - $chargedDevisCount; $this->devisCountToGet = ($devisLeftToGet < $this->maxArticlePerPage) ? $devisLeftToGet + 1: $this->maxArticlePerPage; } }