finish group facturation adress , wip column articles in facture recap

This commit is contained in:
Tiavina 2025-02-05 13:52:48 +03:00
parent 4be7dc2a23
commit 5e14418ab0
2 changed files with 69 additions and 29 deletions

View File

@ -379,6 +379,7 @@ class Bdd {
.$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, "
.$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."devis.comment as numero_commande, "
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
.$this->tableprefix."client.legal_one as client_siret, "
.$this->tableprefix."client.mail as mail_client, ".$this->tableprefix."client.entreprise as client_entreprise, ".$this->tableprefix."client.fk_client_group_id as fk_client_group_id, "
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
@ -413,16 +414,25 @@ class Bdd {
.$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."devis.comment as numero_commande, "
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
.$this->tableprefix."client.mail as mail_client, ".$this->tableprefix."client.entreprise as client_entreprise, ".$this->tableprefix."client.fk_client_group_id as fk_client_group_id, "
.$this->tableprefix."client.legal_one as client_siret, "
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
.$this->tableprefix."facture.version, status_paiement
.$this->tableprefix."facture.version, status_paiement, "
.$this->tableprefix."client_group_facturation.id as group_id, "
.$this->tableprefix."client_group_facturation.group_facturation_name as group_name, "
.$this->tableprefix."client_group_facturation.address as group_address, "
.$this->tableprefix."client_group_facturation.postal_code as group_postal_code, "
.$this->tableprefix."client_group_facturation.city as group_city, "
.$this->tableprefix."client_group_facturation.email as group_email, "
.$this->tableprefix."client_group_facturation.siret_number as group_siret_number
FROM (".$this->tableprefix."facture
LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id)
LEFT JOIN ".$this->tableprefix."lieu on ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id
LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
LEFT JOIN ".$this->tableprefix."defunt on ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id
WHERE YEAR(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[2]." AND MONTH(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[1]."
LEFT JOIN ".$this->tableprefix."client_group_facturation on ".$this->tableprefix."client.fk_client_group_facturation_id = ".$this->tableprefix."client_group_facturation.id
WHERE YEAR(".$this->tableprefix."facture.date_paiement) = ".explode('-', string: $date)[2]." AND MONTH(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[1]."
AND ".$this->tableprefix."client.id = ? ORDER BY date_soin ASC";
$result = $this->execSQL($sql, array($clientId));
return $result;
@ -3687,7 +3697,7 @@ class Bdd {
return true;
}
private function getClientGroupFacturationById($clientGroupFacturationId){
public function getClientGroupFacturationById($clientGroupFacturationId){
$sql = "SELECT *
FROM ".$this->tableprefix."client_group_facturation as client_group_facturation
WHERE client_group_facturation.id = ? ;";

View File

@ -88,18 +88,16 @@ class InvoiceRecapService {
$storage = $this->rootFolder->getUserFolder($idNextcloud);
$doesLogoExist = $this->doesLogoExist();
$doesSignatureExist = $this->doesSignatureImageExists();
$tvaIntraCommuValue = "";
$firstClient = $this->gestionBdd->getFirstClient();
if($firstClient != null){
$tvaIntraCommuValue = $firstClient["legal_one"];
}
$defaultConfig = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$configurationAddresses = FileExportHelpers::GetAddressAndCityFromAddress($defaultConfig[0]->adresse);
$configurationAddress = $configurationAddresses["address"];
$configurationAddressCity = $configurationAddresses["city"];
$factures = json_decode($this->gestionBdd->getClientFacturesByClientGroupFacturationIdAndDate($clientGroupId,$date));
$factures = array_filter($factures, callback: function($facture) {return $facture->id_client != NULL; });
$groupName = "";
$clientGroupFacturation = $this->gestionBdd->getClientGroupFacturationById($clientGroupId);
if($clientGroupFacturation == null){
return null;
}
foreach ($factures as $key => $facture) {
$facture_temp = array(
'num' => $facture->num,
@ -118,8 +116,7 @@ class InvoiceRecapService {
'montant_htc' => 0,
'tva' => $defaultConfig[0]->tva_default,
'montant_tva' => 0,
'montant_ttc' => 0,
'group_facturation_name' => $facture->group_facturation_name
'montant_ttc' => 0
);
$produits = json_decode($this->gestionBdd->getListProduit($facture->id_devis,$idNextcloud));
$produitsReferenceArray = [];
@ -156,7 +153,6 @@ class InvoiceRecapService {
$pdf = new FPDF();
$pdf->AddFont('ComicSans','','Comic Sans MS.php');
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
$groupName = $mois[0]['group_facturation_name'];
$date_facture = $mois[0]['date_facture'];
$date_temp = date("t-m-Y", strtotime($date_facture));
@ -203,10 +199,16 @@ class InvoiceRecapService {
$clientInfoYAxis = 40;
$pdf->SetFont('ComicSans','',size: 11);
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, utf8_decode('Groupe '.$groupName));
$pdf->Cell( 0, 7, utf8_decode($clientGroupFacturation["group_facturation_name"]));
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, trim(utf8_decode(html_entity_decode($clientGroupFacturation["address"]))));
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, trim(utf8_decode(html_entity_decode($clientGroupFacturation["postal_code"]. ' ' .$clientGroupFacturation["city"]))));
// date facture
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, "Saint Senoux, le ".utf8_decode($date_formated));
// observations
@ -291,7 +293,19 @@ class InvoiceRecapService {
$clientInfoYAxis = 40;
$pdf->SetFont('ComicSans','',size: 11);
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, utf8_decode('Groupe '.$groupName));
$pdf->Cell( 0, 7, utf8_decode('Groupe '.$clientGroupFacturation["group_facturation_name"]));
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, trim(utf8_decode(html_entity_decode($clientGroupFacturation["address"]))));
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, trim(utf8_decode(html_entity_decode($clientGroupFacturation["postal_code"]. ' '.$clientGroupFacturation["city"]))));
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . FileExportHelpers::FormatTextForExport($clientGroupFacturation["siret_number"]));
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, 'Email: ' . utf8_decode(html_entity_decode($clientGroupFacturation["email"])),0,1);
// ***********************
// le cadre des articles
@ -406,7 +420,7 @@ class InvoiceRecapService {
strtoupper(
FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])
).
'/GROUPE_'.$groupName.'_RECAP_FACTURE_'.strtoupper(
'/GROUPE_'.$clientGroupFacturation["group_facturation_name"].'_RECAP_FACTURE_'.strtoupper(
FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])
).'_'.$key_annee.'.pdf';
$storage->newFile($ff_pdf);
@ -422,11 +436,6 @@ class InvoiceRecapService {
$data_factures = [];
$storage = $this->rootFolder->getUserFolder($idNextcloud);
$doesLogoExist = $this->doesLogoExist();
$tvaIntraCommuValue = "";
$firstClient = $this->gestionBdd->getFirstClient();
if($firstClient != null){
$tvaIntraCommuValue = $firstClient["legal_one"];
}
$defaultConfig = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$configurationAddresses = FileExportHelpers::GetAddressAndCityFromAddress($defaultConfig[0]->adresse);
$configurationAddress = $configurationAddresses["address"];
@ -455,6 +464,14 @@ class InvoiceRecapService {
'tva' => $defaultConfig[0]->tva_default,
'montant_tva' => 0,
'montant_ttc' => 0,
"group_id" => $facture->group_id,
"group_name" => $facture->group_name,
"group_address" => $facture->group_address,
"group_email" => $facture->group_email,
"group_city" => $facture->group_city,
"group_postal_code" => $facture->group_postal_code,
"group_siret_number" => $facture->group_siret_number,
"client_siret" => $facture->client_siret
);
$produits = json_decode($this->gestionBdd->getListProduit($facture->id_devis,$idNextcloud));
$produitsReferenceArray = [];
@ -493,19 +510,32 @@ class InvoiceRecapService {
$pdf->AddFont('ComicSans','','Comic Sans MS.php');
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
$current_client = '';
$clientHeaderLabel = '';
$clientAddress = '';
$clientCity = '';
$tvaIntraCommuValue = '';
$clientMail = '';
$date_facture;
$j=1;
foreach ($client as $key => $facture) {
if($j==1) {
$current_client = $facture['nom_client'];
$date_facture = $facture['date_facture'];
$current_client = $facture['nom_client'];
$clientHeaderLabel = $current_client;
$date_facture = $facture['date_facture'];
$isClientInsideGroup = $facture["group_id"] != null;
if($isClientInsideGroup){
$clientHeaderLabel = $facture["group_name"];
$clientAddress = $facture["group_address"];
$clientCity = $facture["group_postal_code"]. " ".$facture["group_city"];
$tvaIntraCommuValue = $facture["group_siret_number"];
$clientMail = $facture["group_email"];
}
else{
$clientAddresses = FileExportHelpers::GetAddressAndCityFromAddress($facture['adresse_client']);
$clientAddress = $clientAddresses['address'];
$clientCity = $clientAddresses['city'];
$tvaIntraCommuValue = $facture["client_siret"];
$clientMail = $facture['mail_client'];
}
$j++;
break;
}
$date_temp = date("t-m-Y", strtotime($date_facture));
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
@ -551,7 +581,7 @@ class InvoiceRecapService {
$clientInfoYAxis = 40;
$pdf->SetFont('ComicSans','',size: 11);
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, utf8_decode($current_client));
$pdf->Cell( 0, 7, utf8_decode($clientHeaderLabel));
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, trim(utf8_decode(html_entity_decode($clientAddress))));
@ -581,7 +611,7 @@ class InvoiceRecapService {
// signature
$pdf->SetFont('ComicSans','',11); $pdf->SetXY( 145, 145 );
$pdf->Cell( $pdf->GetStringWidth($defaultConfig[0]->nom.' '.$defaultConfig[0]->prenom), 0, utf8_decode(html_entity_decode($defaultConfig[0]->nom.' '.$defaultConfig[0]->prenom)), 0, 0, 'L');
$signatureExists = $this->doesSignatureImageExists('sign.png');
$signatureExists = $this->doesSignatureImageExists();
if($signatureExists){
$pdf->Image($this->defaultImagePath."sign.png", 135, 150, 60,40);
}
@ -645,7 +675,7 @@ class InvoiceRecapService {
$clientInfoYAxis = 40;
$pdf->SetFont('ComicSans','',size: 11);
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, utf8_decode($current_client));
$pdf->Cell( 0, 7, utf8_decode($clientHeaderLabel));
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, trim(utf8_decode(html_entity_decode($clientAddress))));
@ -657,7 +687,7 @@ class InvoiceRecapService {
$pdf->Cell( 0, 7, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . FileExportHelpers::FormatTextForExport($tvaIntraCommuValue));
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis,$clientInfoYAxis);
$pdf->Cell( 0, 7, 'Email: ' . utf8_decode(html_entity_decode($facture['mail_client'])),0,1);
$pdf->Cell( 0, 7, 'Email: ' . utf8_decode(html_entity_decode($clientMail)),0,1);
// ***********************
// le cadre des articles