diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index af61645..107b3c5 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -2718,14 +2718,22 @@ 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; - - $clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($factureData["client_adresse"]); - $factureData["client_real_adress"] = $clientAdresses["address"]; - $factureData["client_adress_city"] = $clientAdresses["city"]; + + $isClientInsideGroup = $factureData["group_id"] != null; + if($isClientInsideGroup){ + $factureData["client_real_adress"] = $factureData["group_address"]; + $factureData["client_adress_city"] = $factureData["group_postal_code"]." ".$factureData["group_city"]; + $factureData["client_mail"] = $factureData["group_email"]; + $factureData["siret"] = $factureData["group_siret_number"]; + } + else{ + $factureData["siret"] = $factureData["client_legal_one"]; + $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"]; @@ -2791,16 +2799,24 @@ class Bdd { year: $year ); } - $firstClient = $this->getFirstClient(); foreach($invoices as &$invoice){ - $invoice["siret"] = $firstClient != null ? $firstClient['legal_one'] : ''; $products = $this->getDevisProduits($invoice["devis_id"]); $invoice["products"] = $products; $invoice["configuration"] = $configuration; - $clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($invoice["client_adresse"]); - $invoice["client_real_adress"] = $clientAdresses["address"]; - $invoice["client_adress_city"] = $clientAdresses["city"]; + $isClientInsideGroup = $invoice["group_id"] != null; + if($isClientInsideGroup){ + $invoice["client_real_adress"] = $invoice["group_address"]; + $invoice["client_adress_city"] = $invoice["group_postal_code"]." ".$invoice["group_city"]; + $invoice["client_mail"] = $invoice["group_email"]; + $invoice["siret"] = $invoice["group_siret_number"]; + } + else{ + $invoice["siret"] = $invoice["client_legal_one"]; + $clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($invoice["client_adresse"]); + $invoice["client_real_adress"] = $clientAdresses["address"]; + $invoice["client_adress_city"] = $clientAdresses["city"]; + } $configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse); $invoice["configuration_adresse"] = $configurationAdresses["address"]; @@ -2850,7 +2866,15 @@ class Bdd { lieu.adresse as lieu_adresse, thanato.nom as thanato_nom, thanato.prenom as thanato_prenom, - client_group_facturation.group_facturation_name as group_facturation_name, + client_group_facturation.group_facturation_name as group_name, + client_group_facturation.id as group_id, + client_group_facturation.phone_number as group_phone_number, + client_group_facturation.address as group_address, + client_group_facturation.postal_code as group_postal_code, + 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, 'group' as facture_type FROM ".$this->tableprefix."facture as facture LEFT JOIN ".$this->tableprefix."devis as devis on facture.id_devis = devis.id @@ -2904,6 +2928,15 @@ class Bdd { lieu.adresse as lieu_adresse, thanato.nom as thanato_nom, thanato.prenom as thanato_prenom, + client_group_facturation.id as group_id, + client_group_facturation.group_facturation_name as group_name, + client_group_facturation.phone_number as group_phone_number, + client_group_facturation.address as group_address, + client_group_facturation.postal_code as group_postal_code, + 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' as facture_type FROM ".$this->tableprefix."facture as facture LEFT JOIN ".$this->tableprefix."devis as devis on facture.id_devis = devis.id @@ -2911,6 +2944,7 @@ class Bdd { LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id + LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation on client.fk_client_group_facturation_id = client_group_facturation.id WHERE client.id = ? AND YEAR(facture.date_paiement) = ?"; @@ -2973,18 +3007,29 @@ class Bdd { client.entreprise as client_entreprise, client.adresse as client_adresse, client.mail as client_mail, + client.legal_one as client_legal_one, defunt.nom as defunt_nom, defunt.sexe as defunt_sexe, lieu.nom as lieu_nom, lieu.adresse as lieu_adresse, thanato.nom as thanato_nom, - thanato.prenom as thanato_prenom + thanato.prenom as thanato_prenom, + client_group_facturation.id as group_id, + client_group_facturation.group_facturation_name as group_name, + client_group_facturation.phone_number as group_phone_number, + client_group_facturation.address as group_address, + client_group_facturation.postal_code as group_postal_code, + 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 FROM ".$this->tableprefix."facture as facture LEFT JOIN ".$this->tableprefix."devis as devis on facture.id_devis = devis.id 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 LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id + LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation on client.fk_client_group_facturation_id = client_group_facturation.id WHERE facture.id = ? ;"; $facture = $this->execSQLNoJsonReturn( diff --git a/gestion/lib/Service/InvoicePdfHandler.php b/gestion/lib/Service/InvoicePdfHandler.php index 596fe62..0eee5d5 100644 --- a/gestion/lib/Service/InvoicePdfHandler.php +++ b/gestion/lib/Service/InvoicePdfHandler.php @@ -80,7 +80,7 @@ class InvoicePdfHandler extends FPDF { $filename = mb_strtoupper($factureData["client_nom"],'UTF-8'); } else{ - $filename = 'GROUPE_'.mb_strtoupper($factureData["group_facturation_name"],'UTF-8'); + $filename = 'GROUPE_'.mb_strtoupper($factureData["group_name"],'UTF-8'); } $filename .= $month != 0 ? '_'.DateHelpers::GetMonthPlainString($month) :''; $filename .= "_".$year; @@ -109,8 +109,8 @@ class InvoicePdfHandler extends FPDF { private function DrawInvoiceClientInfo(){ $this->SetFont('ComicSans', '', 10); $clientName = $this->factureData['client_nom']; - if($this->factureData['facture_type'] == MultipleFactureTypeConstant::GROUP_FILTER_TYPE){ - $clientName = $this->factureData['group_facturation_name']; + if($this->factureData["group_name"] != null && $this->factureData["group_name"] != ""){ + $clientName = $this->factureData['group_name']; } $clientInfoXAxis = 125; $clientInfoYAxis = 40; diff --git a/gestion/lib/Service/InvoicePdfService.php b/gestion/lib/Service/InvoicePdfService.php index 0ea8dd9..05d34f8 100644 --- a/gestion/lib/Service/InvoicePdfService.php +++ b/gestion/lib/Service/InvoicePdfService.php @@ -27,6 +27,7 @@ declare(strict_types=1); namespace OCA\Gestion\Service; use DateTime; +use OCA\Gestion\Constants\MultipleFactureTypeConstant; use OCA\Gestion\Db\Bdd; use OCA\Gestion\Helpers\DateHelpers; use OCA\Gestion\Service\InvoiceRecap\InvoiceRecapService; @@ -141,8 +142,14 @@ class InvoicePdfService { $pdf->MutlipleInvoicePdfFactory($invoiceData,$logo); $pdf->SetMultipleFactureContent(); $racinePath = html_entity_decode(string: $currentConfig->path).'/'; - $clientRacineFolder = $racinePath.'CLIENTS/'.mb_strtoupper($invoiceData[0]["client_nom"],'UTF-8').'/'; - $filename = $currentConfig->facture_prefixe.'_'.$pdf->GetMultipleInvoiceFilename($month,$year); + $clientNameInFolder = $invoiceData[0]["client_nom"]; + if($invoiceData[0]['facture_type'] == MultipleFactureTypeConstant::GROUP_FILTER_TYPE){ + if($invoiceData[0]["group_name"] != null && $invoiceData[0]["group_name"] != ""){ + $clientNameInFolder = $invoiceData[0]["group_name"]; + } + } + $clientRacineFolder = $racinePath.'CLIENTS/'.mb_strtoupper($clientNameInFolder,'UTF-8').'/'; + $filename = "FACTURE".'_'.$pdf->GetMultipleInvoiceFilename($month,$year); $filenamePath = $clientRacineFolder.$filename.'.pdf'; $pdfContent = $pdf->Output('','S'); try {