facture simple number, devis quantite of product fixe, fix design facture simple

This commit is contained in:
Tiavina 2025-04-10 10:44:18 +03:00
parent 879c2ad766
commit 51d2353a9a
3 changed files with 101 additions and 50 deletions

View File

@ -605,7 +605,7 @@ class Bdd {
} }
public function getOneFacture($numfacture, $idNextcloud){ public function getOneFacture($numfacture, $idNextcloud){
$sql = "SELECT ".$this->tableprefix."facture.id," . $this->tableprefix . "facture.version," . $this->tableprefix . "facture.num, " $sql = "SELECT ".$this->tableprefix."facture.id," . $this->tableprefix . "facture.version," . $this->tableprefix . "facture.num, " . $this->tableprefix . "facture.facture_number, "
.$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum, comment, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom, prenom, entreprise," .$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum, comment, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom, prenom, entreprise,"
.$this->tableprefix."devis.comment as dcomment,".$this->tableprefix."lieu.nom as lieu, ".$this->tableprefix."lieu.adresse as adresse_soin," .$this->tableprefix."devis.comment as dcomment,".$this->tableprefix."lieu.nom as lieu, ".$this->tableprefix."lieu.adresse as adresse_soin,"
.$this->tableprefix."defunt.nom as nom_defunt, " .$this->tableprefix."defunt.nom as nom_defunt, "
@ -1414,7 +1414,14 @@ class Bdd {
} }
$factureDate = $devisDatetime->format('Y-m-d'); $factureDate = $devisDatetime->format('Y-m-d');
$factureNumber = $this->getFactureNumberByDate($devisDatetime); $factureNumber = $this->getFactureNumberByDate($devisDatetime);
$fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($devisDatetime,$factureNumber,"FAC"); $facturePrefix = "FAC";
$devis = json_decode($this->getOneDevis($devisId, $idNextcloud))[0];
$isDevisNegative = $this->isDevisNegative($devisId,clientId: $devis->clientid);
if($isDevisNegative){
$facturePrefix = "AVO";
}
$fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($devisDatetime,$factureNumber,$facturePrefix);
$last = 0; $last = 0;
$last = $this->lastNumFacture($idNextcloud); $last = $this->lastNumFacture($idNextcloud);
$sql = "INSERT INTO `".$this->tableprefix."facture` (`date`,`id_nextcloud`,`num`,`date_paiement`,`type_paiement`,`id_devis`,`user_id`, `version`,`facture_number`) VALUES (?,?,?,?,?,?,?,?,?);"; $sql = "INSERT INTO `".$this->tableprefix."facture` (`date`,`id_nextcloud`,`num`,`date_paiement`,`type_paiement`,`id_devis`,`user_id`, `version`,`facture_number`) VALUES (?,?,?,?,?,?,?,?,?);";
@ -1514,6 +1521,24 @@ class Bdd {
$this->execSQLNoData($sql, array($idNextcloud,'inserer un texte ici')); $this->execSQLNoData($sql, array($idNextcloud,'inserer un texte ici'));
return true; return true;
} }
private function isDevisNegative($devisId,$clientId){
$sql = "SELECT produit_devis.quantite,produit.prix_unitaire,produit.id
FROM ".$this->tableprefix."produit_devis as produit_devis
LEFT JOIN ".$this->tableprefix."produit as produit ON produit_devis.produit_id = produit.id
WHERE produit_devis.devis_id = ?;";
$devisProduits = $this->execSQLNoJsonReturn($sql,array($devisId));
$total = 0;
if(!empty($devisProduits)){
foreach($devisProduits as $currentProduit){
if($currentProduit['id'] != null){
$produitPrice = $this->getProductPriceByClient($currentProduit['id'],$clientId,$currentProduit['prix_unitaire']);
$total += $produitPrice * $currentProduit['quantite'];
}
}
}
return $total < 0;
}
/** /**
* UPDATE * UPDATE
@ -1526,7 +1551,15 @@ class Bdd {
if($facture['date_paiement'] != $data){ if($facture['date_paiement'] != $data){
$facturationDatetime = Datetime::createFromFormat('Y-m-d',$data); $facturationDatetime = Datetime::createFromFormat('Y-m-d',$data);
$factureNumber = $this->getFactureNumberByDate($facturationDatetime); $factureNumber = $this->getFactureNumberByDate($facturationDatetime);
$fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($facturationDatetime,$factureNumber,"FAC"); $facturePrefix = "FAC";
if($facture['id_devis']){
$devis = json_decode($this->getOneDevis($facture['id_devis'], $idNextcloud))[0];
$isDevisNegative = $this->isDevisNegative($facture['id_devis'],$devis->clientid);
if($isDevisNegative){
$facturePrefix = "AVO";
}
}
$fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($facturationDatetime,$factureNumber,$facturePrefix);
$sql = "UPDATE ".$this->tableprefix.$table." SET `facture_number`= ? WHERE `id` = ?"; $sql = "UPDATE ".$this->tableprefix.$table." SET `facture_number`= ? WHERE `id` = ?";
$this->execSQLNoData($sql, array($factureNumber, $id)); $this->execSQLNoData($sql, array($factureNumber, $id));
$sql = "UPDATE ".$this->tableprefix.$table." SET $column = ?, `num`= ? WHERE `id` = ?"; $sql = "UPDATE ".$this->tableprefix.$table." SET $column = ?, `num`= ? WHERE `id` = ?";
@ -1539,6 +1572,16 @@ class Bdd {
$devis = json_decode($this->getOneDevis(htmlentities(rtrim($data)), $idNextcloud))[0]; $devis = json_decode($this->getOneDevis(htmlentities(rtrim($data)), $idNextcloud))[0];
$sql = "UPDATE ".$this->tableprefix.$table." SET $column = ?, `date`= ?, `version`= ? WHERE `id` = ?"; $sql = "UPDATE ".$this->tableprefix.$table." SET $column = ?, `date`= ?, `version`= ? WHERE `id` = ?";
$this->execSQLNoData($sql, array(htmlentities(rtrim($data)), $devis->date, html_entity_decode($devis->version),$id)); $this->execSQLNoData($sql, array(htmlentities(rtrim($data)), $devis->date, html_entity_decode($devis->version),$id));
$facturePrefix = "FAC";
$factureNumber = $facture->facture_number;
$isDevisNegative = $this->isDevisNegative($devis->devisid,$devis->clientid);
if($isDevisNegative){
$facturePrefix = "AVO";
}
$facturationDatetime = new Datetime($facture->date);
$fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($facturationDatetime,$factureNumber,$facturePrefix);
$sql = "UPDATE ".$this->tableprefix.$table." SET `num`= ? WHERE `id` = ?";
$this->execSQLNoData($sql, array($fullFactureNumber, $id));
} else if(strcmp($table, "lieu")==0 && (strcmp($column, "latitude")==0 || strcmp($column, "longitude")==0)) { } else if(strcmp($table, "lieu")==0 && (strcmp($column, "latitude")==0 || strcmp($column, "longitude")==0)) {

View File

@ -140,7 +140,7 @@ class DevisPdfHandler extends FPDF {
$products = $this->devisData["products"]; $products = $this->devisData["products"];
$yValue = 116; $yValue = 116;
foreach($products as $product){ foreach($products as $product){
$valueHt = $product['produit_price']; $valueHt = $product['produit_price'] * $product['quantite'];
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt,$tvaValue); $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt,$tvaValue);
$totalHt+=$valueHt; $totalHt+=$valueHt;
$totalTtc+=$valueTtc; $totalTtc+=$valueTtc;

View File

@ -42,7 +42,13 @@ class InvoicePdfHandler extends FPDF
private $logoPath = "/var/www/html/data/admin/files/.gestion/"; private $logoPath = "/var/www/html/data/admin/files/.gestion/";
protected $extgstates = []; protected $extgstates = [];
private $thereIsOrderOrCaseNumber = false; private $thereIsOrderOrCaseNumber = false;
private $startingYOfArticlesTable = 95; private $startingYOfArticlesTable = 100;
private $endingYOfArticlesTable = 230;
private $articleTablesHeight = 130;
public $interLigneHeader = 5;
function Header() function Header()
{ {
if ($this->logo != "nothing") { if ($this->logo != "nothing") {
@ -90,11 +96,14 @@ class InvoicePdfHandler extends FPDF
function Footer() function Footer()
{ {
$this->SetY(-34); $this->SetY(-34);
$this->SetFont('ComicSans', '', 7); $this->SetFont('ComicSans', '', 7);
$this->MultiCell(0, 4, utf8_decode(html_entity_decode('Tout retard de paiement entraînera de plein droit une pénalité de retard de 3 fois le taux légal ( Loi 2008-776 du 4 août 2008) et une indemnité forfaitaire de 40 EUR pour frais de recouvrement sera appliquée.')));
$this->MultiCell(0,4,utf8_decode(html_entity_decode('Tout retard de paiement entraînera de plein droit une pénalité de retard de 3 fois le taux légal ')));
$this->MultiCell(0,4,utf8_decode(html_entity_decode('( Loi 2008-776 du 4 août 2008) et une indemnité forfaitaire de 40 EUR pour frais de recouvrement sera appliquée.')));
$this->MultiCell(0,4,utf8_decode(html_entity_decode('sera appliquée.')));
$this->Ln(1); $this->Ln(1);
$this->MultiCell(0, 4, utf8_decode(html_entity_decode('Si les frais de recouvrement sont supérieurs à ce montant forfaitaire, une indemnisation complémentaire sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du code de commerce ). $this->MultiCell(0,4,utf8_decode(html_entity_decode('Si les frais de recouvrement sont supérieurs à ce montant forfaitaire, une indemnisation complémentaire')));
'))); $this->MultiCell(0,4,utf8_decode(html_entity_decode('sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du code de commerce ).')));
$this->SetY(-10); $this->SetY(-10);
$this->SetFont('ComicSans', '', 7); $this->SetFont('ComicSans', '', 7);
@ -142,11 +151,11 @@ class InvoicePdfHandler extends FPDF
{ {
$this->SetY(40); $this->SetY(40);
$this->SetFont('ComicSans', '', 10); $this->SetFont('ComicSans', '', 10);
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport($this->factureData['configuration']->entreprise), 0, 1); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration']->entreprise), 0, 1);
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse']), 0, 1); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse']), 0, 1);
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse_city']), 0, 1); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse_city']), 0, 1);
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->factureData['configuration']->telephone), 0, 1); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->factureData['configuration']->telephone), 0, 1);
$this->Cell(0, 5, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1); $this->Cell(0, $this->interLigneHeader, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1);
} }
private function DrawInvoiceClientInfo() private function DrawInvoiceClientInfo()
{ {
@ -165,22 +174,22 @@ class InvoicePdfHandler extends FPDF
$clientInfoYAxis = $clientAdressIsMultiline ? 35 : 40; $clientInfoYAxis = $clientAdressIsMultiline ? 35 : 40;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, 4, FileExportHelpers::FormatTextForExport($clientName)); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($clientName));
$clientInfoYAxis += 4; $clientInfoYAxis += $this->interLigneHeader;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->MultiCell(0, 4, trim(FileExportHelpers::FormatTextForExport($clientAddress))); $this->MultiCell(0, $this->interLigneHeader, trim(FileExportHelpers::FormatTextForExport($clientAddress)));
if ($clientAdressIsMultiline) { if ($clientAdressIsMultiline) {
$clientInfoYAxis += 4; $clientInfoYAxis += $this->interLigneHeader;
} }
$clientInfoYAxis += 4; $clientInfoYAxis += $this->interLigneHeader;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, 4, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city']))); $this->Cell(0, $this->interLigneHeader, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city'])));
$clientInfoYAxis += 4; $clientInfoYAxis += $this->interLigneHeader;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, 4, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . $this->factureData['siret']); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . $this->factureData['siret']);
$clientInfoYAxis += 4; $clientInfoYAxis += $this->interLigneHeader;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, 4, FileExportHelpers::FormatTextForExport('Mail : ') . $this->factureData['client_mail']); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport('Mail : ') . $this->factureData['client_mail']);
} }
private function DrawInvoiceCompanyAndClientInfo() private function DrawInvoiceCompanyAndClientInfo()
@ -191,23 +200,22 @@ class InvoicePdfHandler extends FPDF
private function DrawInvoiceInfoTable() private function DrawInvoiceInfoTable()
{ {
$this->setY(80); $this->setY(70);
$factureDatePaiement = $this->factureData['date_paiement']; $factureDatePaiement = $this->factureData['date_paiement'];
$factureDatePaiement = DateTime::createFromFormat('Y-m-d', $factureDatePaiement); $factureDatePaiement = DateTime::createFromFormat('Y-m-d', $factureDatePaiement);
$factureDateEcheance = $factureDatePaiement; $factureDateEcheance = $factureDatePaiement;
$factureDatePaiement = $factureDatePaiement->format('d-m-Y'); $factureDatePaiement = $factureDatePaiement->format('d-m-Y');
$factureDateEcheance->modify('last day of next month'); $factureDateEcheance->modify('last day of next month');
$factureDateEcheance = $factureDateEcheance->format('d-m-Y'); $factureDateEcheance = $factureDateEcheance->format('d-m-Y');
$this->SetFont('ComicSans', 'B', 11); $this->SetFont('ComicSans', '', 9);
$this->Cell(25, 7, 'DATE', 1, 0, 'C'); $this->Cell(25, 7, 'DATE', 1, 0, 'C');
$this->Cell(104, 7, 'CLIENT', 1, 0, 'C'); $this->Cell(104, 7, 'CLIENT', 1, 0, 'C');
$this->Cell(39, 7, 'FACTURE', 1, 0, 'C'); $this->Cell(39, 7, 'FACTURE', 1, 0, 'C');
$this->Cell(36, 7, 'ECHEANCE', 1, 1, 'C'); $this->Cell(36, 7, 'ECHEANCE', 1, 1, 'C');
$this->setY(90); $this->setY(77);
$this->SetFont('ComicSans', '', 10); $this->SetFont('ComicSans', '', 9);
$this->setY(30);
$this->Cell(25, 11, $factureDatePaiement, 1, 0, 'C'); $this->Cell(25, 11, $factureDatePaiement, 1, 0, 'C');
$this->Cell(104, 11, utf8_decode(html_entity_decode($this->factureData['client_nom'])), 1, 0, 'C'); $this->Cell(104, 11, utf8_decode(html_entity_decode($this->factureData['client_nom'])), 1, 0, 'C');
$this->Cell(39, 11, $this->factureData['num'], 1, 0, 'C'); $this->Cell(39, 11, $this->factureData['num'], 1, 0, 'C');
@ -231,22 +239,22 @@ class InvoicePdfHandler extends FPDF
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport("Numéro de dossier: " . $this->factureData['case_number']), 0, 1, 'C'); $this->Cell(0, 5, FileExportHelpers::FormatTextForExport("Numéro de dossier: " . $this->factureData['case_number']), 0, 1, 'C');
} }
$this->startingYOfArticlesTable = $this->thereIsOrderOrCaseNumber ? 98 : 88; $this->startingYOfArticlesTable = $this->thereIsOrderOrCaseNumber ? $$this->startingYOfArticlesTable + 3 : $this->startingYOfArticlesTable - 7;
} }
private function DrawArticlesTable() private function DrawArticlesTable()
{ {
$this->SetLineWidth(0.2); $this->SetLineWidth(0.2);
$gapBetweenStartingOfArticlesTableAndColumnName = 10; $gapBetweenStartingOfArticlesTableAndColumnName = 10;
$tableHeight = $this->thereIsOrderOrCaseNumber ? 137 : 137 + 10; $tableHeight = $this->thereIsOrderOrCaseNumber ? $this->articleTablesHeight : $this->articleTablesHeight + 10;
$this->Rect(3, $this->startingYOfArticlesTable, 204, $tableHeight, "D"); $this->Rect(3, $this->startingYOfArticlesTable, 204, $tableHeight, "D");
// cadre titre des colonnes // cadre titre des colonnes
$this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName); $this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName);
// les traits verticaux colonnes // les traits verticaux colonnes
$this->Line(28, $this->startingYOfArticlesTable, 28, 232); $this->Line(28, $this->startingYOfArticlesTable, 28, $this->endingYOfArticlesTable + 3);
$this->Line(132, $this->startingYOfArticlesTable, 132, 232); $this->Line(132, $this->startingYOfArticlesTable, 132, $this->endingYOfArticlesTable + 3);
$this->Line(157, $this->startingYOfArticlesTable, 157, 232); $this->Line(157, $this->startingYOfArticlesTable, 157, $this->endingYOfArticlesTable + 3);
$this->Line(182, $this->startingYOfArticlesTable, 182, 232); $this->Line(182, $this->startingYOfArticlesTable, 182, $this->endingYOfArticlesTable + 3);
} }
private function DrawArticlesTableHeader() private function DrawArticlesTableHeader()
@ -284,9 +292,7 @@ class InvoicePdfHandler extends FPDF
$yValue = $this->startingYOfArticlesTable + 11; $yValue = $this->startingYOfArticlesTable + 11;
foreach ($products as $product) { foreach ($products as $product) {
$this->SetFont('ComicSans', '', 8); $valueHt = $product['produit_price'] * $product['quantite'];
$valueHt = $product['produit_price'];
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue); $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue);
$totalHt += $valueHt; $totalHt += $valueHt;
$totalTtc += $valueTtc; $totalTtc += $valueTtc;
@ -327,34 +333,36 @@ class InvoicePdfHandler extends FPDF
private function DrawBankAndTotalPriceInfo($totalPriceArray) private function DrawBankAndTotalPriceInfo($totalPriceArray)
{ {
$this->SetY(235); $this->SetY(235);
$this->SetFont('ComicSans', '', 7); $this->SetFont('ComicSans', '', 8);
$this->MultiCell(0, 5, utf8_decode(html_entity_decode("Paiement à votre convenance par chèque à l'ordre de " . $this->factureData['configuration']->entreprise))); $this->MultiCell(0,4,utf8_decode(html_entity_decode("Paiement à votre convenance par chèque à l'ordre de ". $this->factureData['configuration']->entreprise)));
$this->MultiCell(0, 5, utf8_decode(html_entity_decode("en indiquant le numéro de facture, ou par virement :"))); $this->MultiCell(0,4,utf8_decode(html_entity_decode("en indiquant le numéro de facture, ou par virement :")));
$this->Ln(1); $this->Ln(1);
// Table IBAN // Table IBAN
$this->SetFont('ComicSans', '', 7); $this->SetFont('ComicSans', '', 8);
$ibanWidth = 56; $ibanWidth = 62;
$ibanCursorY = $this->GetY(); $ibanCursorY = $this->GetY();
$this->Cell($ibanWidth, 5, 'IBAN : FR76 1360 6000 1436 5418 1800 038', 1, 1, 'C'); $this->Cell($ibanWidth, 5, 'IBAN : FR76 1360 6000 1436 5418 1800 038', 1, 1, 'C');
$ibanCursorX = $this->GetX(); $ibanCursorX = $this->GetX();
$this->Cell($ibanWidth, 5, 'Code SWIFT : AGRI FR PP 836', 1, 1, 'C'); $this->Cell($ibanWidth, 5, 'Code SWIFT : AGRI FR PP 836', 1, 1, 'C');
//TABLE HT //TABLE HT
$tableWidth = 40; // Largeur totale de la 2e table (20+20) $tableWidth = 48; // Largeur totale de la 2e table (20+20)
$marginRight = 3; // Marge par rapport au bord droit $marginRight = 3; // Marge par rapport au bord droit
$pageWidth = 210; // Largeur d'une page A4 en mm (portrait) $pageWidth = 210; // Largeur d'une page A4 en mm (portrait)
// Position correcte de la 2e table // Position correcte de la 2e table
$startOfArrayX = $pageWidth - $tableWidth - $marginRight; $startOfArrayX = $pageWidth - $tableWidth - $marginRight;
$startOfArrayY = $ibanCursorY - 10; $startOfArrayY = $ibanCursorY - 5;
foreach ($totalPriceArray as $label => $price) { $this->SetFont('ComicSans', '', 10);
$this->SetXY($startOfArrayX, $startOfArrayY);
$this->Cell(20, 5, $label, 1, 1, 'C'); foreach($totalPriceArray as $label => $price){
$this->SetXY($startOfArrayX + 20, $startOfArrayY); $this->SetXY($startOfArrayX,$startOfArrayY);
$this->Cell(20, 5, number_format($price, 2, '.', '') . chr(128), 1, 1, 'C'); $this->Cell(24, 5, $label, 1, 1, 'C');
$this->SetXY($startOfArrayX + 24,$startOfArrayY);
$this->Cell(24, 5, number_format($price,2,'.','').chr(128), 1, 1, 'C');
$startOfArrayY += 5; $startOfArrayY += 5;
} }
} }