finish funecap facture, wip ogf facture

This commit is contained in:
Tiavina 2025-03-02 15:18:13 +03:00
parent 907653bed0
commit 69099e7187
5 changed files with 214 additions and 30 deletions

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace OCA\Gestion\Constants;
abstract class ClientTemplateTypeConstant
{
const PRIVEES = "PRIVEES";
const FUNECAP = "FUNECAP";
const OGF = "OGF";
}

View File

@ -1,6 +1,7 @@
<?php
namespace OCA\Gestion\Db;
use OCA\Gestion\Constants\ClientTemplateTypeConstant;
use OCA\Gestion\Constants\FactureStatusConstant;
use OCA\Gestion\Constants\FactureTypeConstant;
use OCA\Gestion\Helpers\DateHelpers;
@ -2818,6 +2819,7 @@ class Bdd {
$totalTva = 0;
$caseNumber = "";
$orderNumber = "";
$templateType = ClientTemplateTypeConstant::PRIVEES;
foreach($factureDevisList as &$devis){
if($factureIncrement == 0){
if($isFactureForSingleClient){
@ -2834,6 +2836,7 @@ class Bdd {
$factureData["client_mail"] = $devis["group_email"];
$factureData["siret"] = $devis["group_siret_number"];
$factureData["group_name"] = $devis["group_name"] ?? "";
$templateType = $devis['fk_template_type_key'] ?? ClientTemplateTypeConstant::PRIVEES;
}
}
$caseNumber = empty($devis["case_number"]) ? $caseNumber : $devis["case_number"];
@ -2865,6 +2868,7 @@ class Bdd {
$factureData["totalPrices"] = $totaPricesArray;
$factureData["case_number"] = $caseNumber;
$factureData["order_number"] = $orderNumber;
$factureData["template_type_key"] = $templateType;
return $factureData;
}
@ -4288,7 +4292,8 @@ class Bdd {
client_group_facturation.city as group_city,
client_group_facturation.email as group_email,
client_group_facturation.siret_number as group_siret_number,
client_group_facturation.tva_intracommu as group_tva_intracommu
client_group_facturation.tva_intracommu as group_tva_intracommu,
client_group_facturation.fk_template_type_key as fk_template_type_key
FROM ".$this->tableprefix."devis as devis
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
@ -4337,7 +4342,8 @@ class Bdd {
client_group_facturation.city as group_city,
client_group_facturation.email as group_email,
client_group_facturation.siret_number as group_siret_number,
client_group_facturation.tva_intracommu as group_tva_intracommu
client_group_facturation.tva_intracommu as group_tva_intracommu,
client_group_facturation.fk_template_type_key as fk_template_type_key
FROM ".$this->tableprefix."devis as devis
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id

View File

@ -0,0 +1,156 @@
<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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);
}
}

View File

@ -32,25 +32,25 @@ use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Helpers\PriceHelpers;
class InvoiceGroupPdfHandler extends FPDF {
private $factureData = [];
private $logo = null;
public $factureData = [];
public $logo = null;
private $productsCount = 0;
public $productsCount = 0;
private $totalPrices = [];
private $devisCount = 0;
private $logoPath = "/var/www/html/data/admin/files/.gestion/";
public $totalPrices = [];
public $devisCount = 0;
public $logoPath = "/var/www/html/data/admin/files/.gestion/";
private $currentIndexPosition = 0;
private $initialIndexPosition = 0;
public $currentIndexPosition = 0;
public $initialIndexPosition = 0;
private $devisCountToGet = 0;
private $devisList = [];
public $devisCountToGet = 0;
public $devisList = [];
private $thereIsOrderOrCaseNumber = false;
private $startingYOfArticlesTable = 95;
private const MAX_ARTICLES_PER_PAGE = 19;
private $additionalArticlesLineBasedOnMultiline = 0;
public $thereIsOrderOrCaseNumber = false;
public $startingYOfArticlesTable = 95;
public int $maxArticlePerPage = 19;
public $additionalArticlesLineBasedOnMultiline = 0;
function Header()
{
if($this->logo != "nothing"){
@ -82,7 +82,7 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->productsCount = $this->factureData["productsCount"];
$this->devisCount = count($this->factureData['devis']);
$this->totalPrices = $this->factureData["totalPrices"];
$this->devisCountToGet = ($this->devisCount <= self::MAX_ARTICLES_PER_PAGE ) ? $this->devisCount : self::MAX_ARTICLES_PER_PAGE;
$this->devisCountToGet = ($this->devisCount <= $this->maxArticlePerPage ) ? $this->devisCount : $this->maxArticlePerPage;
$this->devisList = $this->factureData['devis'];
$this->logo = $logo;
}
@ -94,13 +94,13 @@ class InvoiceGroupPdfHandler extends FPDF {
return $this->factureData['configuration']->facture_prefixe.'_'.$factureNum.'_'.mb_strtoupper($clientName,'UTF-8');
}
private function DrawPageNumbersText($pageNumber,$pageCount){
public function DrawPageNumbersText($pageNumber,$pageCount){
$this->SetXY( 120, 5 );
$this->Cell( 160, 8, $pageNumber . '/' . $pageCount, 0, 0, 'C');
}
private function DrawArticlesTable(){
$pageCount = ceil($this->devisCount / self::MAX_ARTICLES_PER_PAGE);
public function DrawArticlesTable(){
$pageCount = ceil($this->devisCount / $this->maxArticlePerPage);
$pageNumber = 1;
while($pageNumber <= $pageCount){
if($pageNumber > 1){
@ -114,7 +114,7 @@ class InvoiceGroupPdfHandler extends FPDF {
}
}
private function DrawInvoiceCompanyInfo(){
public function DrawInvoiceCompanyInfo(){
$this->SetY(40);
$this->SetFont('ComicSans', '', 10);
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport($this->factureData['configuration']->entreprise), 0, 1);
@ -123,7 +123,7 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->factureData['configuration']->telephone),0,1);
$this->Cell(0, 5, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1);
}
private function DrawInvoiceClientInfo(){
public function DrawInvoiceClientInfo(){
$this->SetFont('ComicSans', '', 10);
$clientName = $this->factureData['group_name'];
$clientInfoXAxis = 125;
@ -154,12 +154,12 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport('Mail : ') . $this->factureData['client_mail']);
}
private function DrawInvoiceCompanyAndClientInfo(){
public function DrawInvoiceCompanyAndClientInfo(){
$this->DrawInvoiceCompanyInfo();
$this->DrawInvoiceClientInfo();
}
private function DrawInvoiceInfoTable(){
public function DrawInvoiceInfoTable(){
$this->setY(67);
$factureDatePaiement = $this->factureData['date_paiement'];
$factureDatePaiement = DateTime::createFromFormat('Y-m-d',$factureDatePaiement);
@ -184,7 +184,7 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->startingYOfArticlesTable = 85;
}
private function DrawArticlesTableRect(){
public function DrawArticlesTableRect(){
$this->SetLineWidth(0.2);
$gapBetweenStartingOfArticlesTableAndColumnName = 10;
$tableHeight = $this->thereIsOrderOrCaseNumber ? 137 : 137 + 10;
@ -198,7 +198,7 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->Line(180, $this->startingYOfArticlesTable, 180, 232);
}
private function DrawArticlesTableHeader(){
public function DrawArticlesTableHeader(){
$tvaValue = $this->factureData["configuration"]->tva_default;
$columnNameY = $this->startingYOfArticlesTable + 1;
$this->SetFont('ComicSans','',10);
@ -271,13 +271,17 @@ class InvoiceGroupPdfHandler extends FPDF {
}
}
$this->currentIndexPosition = $currentIndexPosition;
$this->initialIndexPosition += $this->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;
$this->devisCountToGet = ($devisLeftToGet <= self::MAX_ARTICLES_PER_PAGE) ? $devisLeftToGet + 1 : self::MAX_ARTICLES_PER_PAGE;
var_dump("LEFT TO GET : ".$devisLeftToGet);
$this->devisCountToGet = ($devisLeftToGet <= $this->maxArticlePerPage) ? $devisLeftToGet + 1 : $this->maxArticlePerPage;
var_dump("DEVIS COUNT TO GET : ".$this->devisCountToGet);
}
private function DrawBankAndTotalPriceInfo(){
public function DrawBankAndTotalPriceInfo(){
$this->SetY(235);
$this->SetFont('ComicSans', '', 7);
$this->MultiCell(0,5,utf8_decode(html_entity_decode("Paiement à votre convenance par chèque à l'ordre de ". $this->factureData['configuration']->entreprise)));

View File

@ -28,10 +28,12 @@ namespace OCA\Gestion\Service;
use DateTime;
use OCA\Gestion\Constants\BddConstant;
use OCA\Gestion\Constants\ClientTemplateTypeConstant;
use OCA\Gestion\Constants\FactureTypeConstant;
use OCA\Gestion\Constants\MultipleFactureTypeConstant;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Helpers\DateHelpers;
use OCA\Gestion\Service\InvoiceGroupPdfHandler\InvoiceFunecapPdfHandler;
use OCA\Gestion\Service\InvoiceGroupPdfHandler\InvoiceGroupPdfHandler;
use OCA\Gestion\Service\InvoiceRecap\InvoiceRecapService;
use OCP\DB\Exception;
@ -156,9 +158,15 @@ class InvoicePdfService {
if($invoicePdfData == null){
return "";
}
$templateType = $invoicePdfData['template_type_key'];
$clean_folder = html_entity_decode(string: $currentConfig->path).'/';
$factureFolders = $this->getGroupFactureFolder($invoicePdfData,$clean_folder);
$pdf = new InvoiceGroupPdfHandler();
if($templateType == ClientTemplateTypeConstant::FUNECAP){
$pdf = new InvoiceFunecapPdfHandler();
}
else{
$pdf = new InvoiceGroupPdfHandler();
}
$pdf->AddFont('ComicSans','','Comic Sans MS.php');
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
$pdf->InvoicePdfFactory($invoicePdfData,$logo);