Merge branch 'fixes/fix-table-facture' into staging

This commit is contained in:
Tiavina 2025-01-03 15:59:39 +03:00
commit c55fa754bf
4 changed files with 141 additions and 88 deletions

View File

@ -58,6 +58,8 @@ class PageController extends Controller {
/** @var InvoicePdfService */
private $invoicePdfService;
private $adminStorage;
/**
* Constructor
*/
@ -105,6 +107,14 @@ class PageController extends Controller {
}catch(\OC\User\NoUserException $e){
}
try{
$this->adminStorage = $rootFolder->getUserFolder(self::DEFAULT_NEXTCLOUD_ADMIN);
}catch(\OC\User\NoUserException $e){
}
}
/**
@ -811,7 +821,7 @@ class PageController extends Controller {
// logo : 80 de largeur et 55 de hauteur
if($isLogoExist){
$pdf->Image($this->currentUserImagePath."logo.png", 10, 10, 55, 30);
$pdf->Image($this->currentUserImagePath."logo.png", 10, 10, 75, 25);
}
// adresse du facture
$pdf->SetFont('Arial','B',size: 11);
@ -823,7 +833,7 @@ class PageController extends Controller {
}
// date facture
$pdf->SetFont('Arial','',11);
$pdf->Cell( 0, 8, "Saint Senoux le, ".utf8_decode($date_formated), 0, 1, 'R');
$pdf->Cell( 0, 8, "Saint Senoux, le ".utf8_decode($date_formated), 0, 1, 'R');
// observations
$pdf->SetFont( "Arial", "BU", 10 ); $pdf->SetXY( 10, 85 ) ; $pdf->Cell($pdf->GetStringWidth("Objet:"), 0, "Objet:", 0, "L");
@ -851,7 +861,7 @@ class PageController extends Controller {
$y0 = 260;
$pageWidth = $pdf->GetPageWidth();
//Positionnement en bas et tout centrer
$pdf->SetFont('Arial','',8);
$pdf->SetFont('Arial','',7);
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->mentions_default)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 8 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 12 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C');
@ -875,7 +885,7 @@ class PageController extends Controller {
$pdf->SetAutoPagebreak(False);
$pdf->SetMargins(0,0,10);
if($isLogoExist){
$pdf->Image($this->currentUserImagePath."logo.png", 10, 10, 55, 30);
$pdf->Image($this->currentUserImagePath."logo.png", 10, 10, 75, 25);
}
// n° page en haute à droite
@ -886,7 +896,7 @@ class PageController extends Controller {
// date facture
$pdf->SetFont('Arial','',11);
$pdf->SetY(10);
$pdf->Cell( 0, 8,"Saint Senoux le, ".utf8_decode($date_formated), 0, 0, 'R');
$pdf->Cell( 0, 8,"Saint Senoux, le ".utf8_decode($date_formated), 0, 0, 'R');
// n° facture, date echeance et reglement et obs
$pdf->SetLineWidth(0.1); $pdf->SetFillColor(255); $pdf->Rect(114, 20, 85, 8, "DF");
@ -900,7 +910,7 @@ class PageController extends Controller {
if($clientCity != ''){
$pdf->Cell( 0, 6, utf8_decode(html_entity_decode($clientCity)), 0, 1, 'R');
}
$pdf->Cell( 0, 6, FileExportHelpers::FormatTextForExport('Numéro') . ' TVA: ' . FileExportHelpers::FormatTextForExport($tvaIntraCommuValue), 0, 1, 'R');
$pdf->Cell( 0, 6, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . FileExportHelpers::FormatTextForExport($tvaIntraCommuValue), 0, 1, 'R');
$pdf->Cell( 0, 6, 'Email: ' . utf8_decode(html_entity_decode($facture['mail_client'])), 0, 1, 'R');
// ***********************
@ -936,8 +946,8 @@ class PageController extends Controller {
$pdf->SetXY( 6, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, $client[$index_facture_position]['num'], 0, 0, '');
$pdf->SetXY( 32, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 18, 8, utf8_decode($formatter_ds->format($date_soin_temp)), 0, 0, '');
$pdf->SetXY( 50, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['produit_references'])), 0, 0, '');
$pdf->SetXY( 100, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 38, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['defunt'])), 0, 0, '');
$pdf->SetXY( 50, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 38, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['defunt'])), 0, 0, '');
$pdf->SetXY( 90, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['produit_references'])), 0, 0, '');
$pdf->SetXY( 147, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 13, 8, number_format($client[$index_facture_position]['montant_htc'],2,'.','').chr(128), 0, 0, 'C');
$pdf->SetXY( 168, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 10, 8, number_format($client[$index_facture_position]['montant_tva'],2,'.','').chr(128), 0, 0, 'C');
$pdf->SetXY( 183, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 22, 8, number_format($client[$index_facture_position]['montant_ttc'],2,'.','').chr(128), 0, 0, 'C');
@ -982,7 +992,7 @@ class PageController extends Controller {
// pied de page
// **************************
$pdf->SetFont('Arial','',8);
$pdf->SetFont('Arial','',7);
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->mentions_default)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 8 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 12 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C');
@ -1167,7 +1177,8 @@ class PageController extends Controller {
// cadre titre des colonnes
$pdf->Line(5, 90, 205, 90);
// les traits verticaux colonnes
$pdf->Line(145, 80, 145, 233); $pdf->Line(163, 80, 163, 233);
$pdf->Line(145, 80, 145, 233);
$pdf->Line(163, 80, 163, 233);
if($num_page == $nb_page) $pdf->Line(183, 80, 183, 240);
else $pdf->Line(183, 80, 183, 233);
// titre colonne
@ -2019,8 +2030,8 @@ class PageController extends Controller {
private function signatureImageExists(string $signatureImageName){
$signatureExist = true;
try{
if(isset($this->storage)){
$file = $this->storage->get("/.gestion/".$signatureImageName);
if(isset($this->adminStorage)){
$file = $this->adminStorage->get("/.gestion/".$signatureImageName);
}else{
$signatureExist = false;
}
@ -2034,8 +2045,8 @@ class PageController extends Controller {
private function getLogo(){
try{
if(isset($this->storage)){
$file = $this->storage->get('/.gestion/logo.png');
if(isset($this->adminStorage)){
$file = $this->adminStorage->get('/.gestion/logo.png');
}else{
return "nothing";
}

View File

@ -5,6 +5,7 @@ use OCA\Gestion\Helpers\DateHelpers;
use OCP\IDBConnection;
use OCP\IL10N;
use \Datetime;
use OCA\Gestion\Helpers\FileExportHelpers;
use Psr\Log\LoggerInterface;
use OCA\Gestion\Helpers\VCalendarHelpers;
@ -2285,26 +2286,19 @@ class Bdd {
}
$products = $this->getDevisProduits($factureData["devis_id"]);
$factureData = $this->setDevisStartAndEndTime($factureData);
$firstClient = $this->getFirstClient();
$factureData["siret"] = $firstClient != null ? $firstClient['legal_one'] : '';
$factureData["products"] = $products;
$factureData["configuration"] = $configuration;
$factureData["client_real_adress"] = "";
$factureData["client_adress_city"] = "";
$clientAdresses = explode("-",$factureData["client_adresse"]);
if(isset($clientAdresses[0])){
$factureData["client_real_adress"] = trim($clientAdresses[0]);
}
if(isset($clientAdresses[1])){
$factureData["client_adress_city"] = trim($clientAdresses[1]);
}
$factureData["configuration_adresse"] = "";
$factureData["configuration_adresse_city"] = "";
$configurationAdresses = explode("-",$configuration->adresse);
if(isset($configurationAdresses[0])){
$factureData["configuration_adresse"] = trim($configurationAdresses[0]);
}
if(isset($configurationAdresses[1])){
$factureData["configuration_adresse_city"] = trim($configurationAdresses[1]);
}
$clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($factureData["client_adresse"]);
$factureData["client_real_adress"] = $clientAdresses["address"];
$factureData["client_adress_city"] = $clientAdresses["city"];
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse);
$factureData["configuration_adresse"] = $configurationAdresses["address"];
$factureData["configuration_adresse_city"] = $configurationAdresses["city"];
return $factureData;
}

View File

@ -16,10 +16,10 @@ class FileExportHelpers
$cityResult = "";
$adresses = explode("-",$adresse);
if(isset($adresses[0])){
$adresseResult = trim($adresses[0]);
$adresseResult = self::RemoveSpaceFromString($adresses[0]);
}
if(isset($adresses[1])){
$cityResult = trim($adresses[1]);
$cityResult = self::RemoveSpaceFromString($adresses[1]);
}
return [
"address" => $adresseResult,
@ -31,4 +31,10 @@ class FileExportHelpers
return $sexeKey === 'f' ? 'Mme' : 'Mr';
}
public static function RemoveSpaceFromString(string $string){
$string = trim($string);
$string = str_replace(" ",'',$string);
return $string;
}
}

View File

@ -36,7 +36,6 @@ class InvoicePdfHandler extends FPDF {
private $factureData = [];
private $logo = null;
private $logoPath = "/var/www/html/data/admin/files/.gestion/";
function Header()
{
if($this->logo != "nothing"){
@ -47,18 +46,13 @@ class InvoicePdfHandler extends FPDF {
}
$this->Ln(30);
}
// Page footer
function Footer()
{
$this->SetY(-45);
$this->SetY(-40);
$this->SetFont('Arial', '', 8);
$this->MultiCell(0,5,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,5,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->Ln(1);
$this->MultiCell(0,5,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,5,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->SetY(-15);
@ -78,37 +72,28 @@ sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du cod
return $this->factureData['configuration']->facture_prefixe.'_'.$factureNum.'_'.strtoupper($defuntNom);
}
public function GetFactureContent(){
$this->AddPage();
$this->SetMargins(10,0,10);
$factureDate = $this->factureData['date'];
$factureDate = DateTime::createFromFormat('Y-m-d',$factureDate);
$factureDate = $factureDate->format('d-m-Y');
private function DrawInvoiceCompanyAndClientInfo(){
$this->SetFont('Arial', '', 12);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['configuration']->entreprise), 0, 0);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['client_nom'] . ' ' . $this->factureData['client_entreprise']), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse']), 0, 0);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['client_real_adress']), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse_city']), 0, 0);border:
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city']), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->factureData['configuration']->telephone),0,1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . $this->factureData['siret'], 0, 1,'R');
$this->Cell(0, 7, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1);
$this->Ln(3);
}
private function DrawInvoiceInfoTable(){
$factureDatePaiement = $this->factureData['date_paiement'];
$factureDatePaiement = DateTime::createFromFormat('Y-m-d',$factureDatePaiement);
$factureDateEcheance = $factureDatePaiement;
$factureDatePaiement = $factureDatePaiement->format('d-m-Y');
$factureDateEcheance->modify('+30 days');
$factureDateEcheance = $factureDateEcheance->format('d-m-Y');
$devisDate = $this->factureData['devis_date'];
$devisDate = DateTime::createFromFormat('Y-m-d',$devisDate);
$devisDate = $devisDate->format('d-m-Y');
$this->SetFont('Arial', '', 12);
$this->Cell(0, 7, utf8_decode(html_entity_decode($this->factureData['configuration']->entreprise)), 0, 0);
$this->Cell(0, 7, utf8_decode(html_entity_decode($this->factureData['client_nom'] . ' ' . $this->factureData['client_entreprise'])), 0, 1,'R');
$this->Cell(0, 7, utf8_decode(html_entity_decode($this->factureData['configuration_adresse'])), 0, 0);
$this->Cell(0, 7, utf8_decode(html_entity_decode($this->factureData['client_real_adress'])), 0, 1,'R');
$this->Cell(0, 7, utf8_decode(html_entity_decode($this->factureData['configuration_adresse_city'])), 0, 0);border:
$this->Cell(0, 7, utf8_decode(html_entity_decode($this->factureData['client_adress_city'])), 0, 1,'R');
$this->Cell(0, 7, utf8_decode(html_entity_decode('Tél : ')) . utf8_decode(html_entity_decode($this->factureData['configuration']->telephone)) , 0, 1);
$this->Cell(0, 7, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1);
$this->Ln(3);
//facture infos
$this->SetFont('Arial', 'B', 11);
$this->Cell(30, 7, 'DATE', 1, 0, 'C');
$this->Cell(80, 7, 'CLIENT', 1, 0, 'C');
@ -122,42 +107,90 @@ sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du cod
$this->Cell(40, 7, $factureDateEcheance, 1, 1, 'C');
$this->Ln(8);
}
//Articles info
private function DrawArticlesTable(){
$this->SetLineWidth(0.1);
$this->Rect(10, 105, 190, 100, "D");
// cadre titre des colonnes
$this->Line(10, 115, 200,115);
// les traits verticaux colonnes
$this->Line(35, 105, 35, 205);
$this->Line(135, 105, 135, 205);
$this->Line(155, 105, 155, 205);
$this->Line(175, 105, 175, 205);
}
private function DrawArticlesTableHeader(){
$tvaValue = $this->factureData["configuration"]->tva_default;
$this->SetFont('Arial', 'B', 11);
$this->Cell(20, 8, 'Date', 1, 0);
$this->Cell(90, 8, 'Description', 1, 0,'C');
$this->Cell(30, 8, 'Prix Uni. HT', 1, 0, 'C');
$this->Cell(20, 8, 'TVA ' . $tvaValue . '%', 1, 0, 'C');
$this->Cell(30, 8, 'Prix Uni. TTC', 1, 1, 'C');
$this->SetFont('Arial','',10);
$this->SetXY( 10,106 );
$this->Cell( 20, 8, "Date", 0, 0, 'C');
$this->SetXY( 35,106 );
$this->Cell( 100, 8, "Description", 0, 0, 'C');
$this->SetXY( 135,106 );
$this->Cell( 20, 8, "Prix Uni. HT", 0, 0, 'C');
$this->SetXY( 155,106 );
$this->Cell( 20, 8, 'TVA ' . $tvaValue . '%', 0, 0, 'C');
$this->SetXY( 175,106 );
$this->Cell( 25, 8, "Prix Uni. TTC", 0, 0, 'C');
}
public function DrawArticlesTableValueAndReturnTotalPrice(){
$this->SetFont('Arial','',10);
$devisDate = $this->factureData['devis_date'];
$devisDate = DateTime::createFromFormat('Y-m-d',$devisDate);
$devisDate = $devisDate->format('d-m-Y');
$tvaValue = $this->factureData["configuration"]->tva_default;
$totalHt = 0;
$totalTtc = 0;
$totalTva = 0;
$products = $this->factureData["products"];
$yValue = 116;
foreach($products as $product){
$valueHt = $product['produit_price'];
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt,$tvaValue);
$totalHt+=$valueHt;
$totalTtc+=$valueTtc;
$descriptionLineNumber = $this->NbLines(90,$product["produit_description"]);
$productDescription = $product["produit_description"];
$dateValue = "";
if($product === end($products)){
$dateValue = $devisDate;
$productDescription .= " de " . FileExportHelpers::GetSexeLabel($this->factureData['defunt_sexe']) . ' '. $this->factureData["defunt_nom"];
}
$articleListMaxHeight = $descriptionLineNumber * 6;
$tvaAmount = $valueTtc - $valueHt;
$this->SetFont('Arial', '', 10);
$this->Cell(20, $articleListMaxHeight, $dateValue, 'LR',0);
$this->MultiAlignCell(90, $articleListMaxHeight, utf8_decode(html_entity_decode($productDescription)),'LR','0',);
$this->Cell(30, $articleListMaxHeight, number_format($valueHt,2,'.','').chr(128), 'LR', 0, 'C');
$this->Cell(20, $articleListMaxHeight, number_format($tvaAmount,2,'.','').chr(128), 'LR', 0, 'C');
$this->Cell(30, $articleListMaxHeight, number_format($valueTtc,2,'.','').chr(128), 'LR', 1, 'C');
$this->SetXY( 10,$yValue );
$this->Cell(20, 6, $dateValue, 0,0);
$this->SetXY( 35,$yValue );
$this->MultiAlignCell(100, 6, utf8_decode(html_entity_decode($productDescription)),0,'0',);
$this->SetXY( 135,$yValue );
$this->Cell(20, 6, number_format($valueHt,2,'.','').chr(128), 0, 0, 'C');
$this->SetXY( 155,$yValue );
$this->Cell(20, 6, number_format($tvaAmount,2,'.','').chr(128), 0, 0, 'C');
$this->SetXY( 175,$yValue );
$this->Cell(25, 6, number_format($valueTtc,2,'.','').chr(128), 0, 1, 'C');
$yValue += 12;
$totalTva += $tvaAmount;
}
$this->Cell(190,0,'','T');
$this->Ln(8);
return [
"totalHt" => $totalHt,
"totalTtc" => $totalTtc,
"totalTvaValue" => $totalTva
];
}
private function DrawBankAndTotalPriceInfo($totalPriceArray){
$this->SetY(210);
$this->SetFont('Arial', '', 9);
$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,5,utf8_decode(html_entity_decode("en indiquant le numéro de facture, ou par virement :")));
@ -180,7 +213,7 @@ sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du cod
$this->Cell($totalHtArrayWidth, 7, 'TOTAL HT', 1, 1, 'C');
$this->SetXY($ibanLastPositionX,$ibanCursorY);
$this->SetFont('Arial', '', 11);
$this->Cell($totalHtArrayWidth, 20, number_format($totalHt,2,'.','').chr(128), 1, 1, 'C');
$this->Cell($totalHtArrayWidth, 20, number_format($totalPriceArray['totalHt'],2,'.','').chr(128), 1, 1, 'C');
$tableHTLastPostionX = $ibanLastPositionX + $totalHtArrayWidth + 10;
//TABLE TTC
@ -189,10 +222,19 @@ sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du cod
$this->Cell(30, 7, 'TOTAL TTC', 1, 1, 'C');
$this->SetXY($tableHTLastPostionX,$ibanCursorY+14);
$this->SetFont('Arial', '', 11);
$this->Cell(30, 7, number_format($totalTtc,2,'.','').chr(128), 1, 1, 'C');
$this->Cell(30, 7, number_format($totalPriceArray['totalTtc'],2,'.','').chr(128), 1, 1, 'C');
}
public function GetFactureContent(){
$this->AddPage();
$this->SetMargins(10,0,10);
$this->DrawInvoiceCompanyAndClientInfo();
$this->DrawInvoiceInfoTable();
$this->DrawArticlesTable();
$this->DrawArticlesTableHeader();
$totalPriceValue = $this->DrawArticlesTableValueAndReturnTotalPrice();
$this->DrawBankAndTotalPriceInfo($totalPriceValue);
$pdfContent = $this->Output('','S');
return $pdfContent;
}