document recap

This commit is contained in:
Tiavina 2025-01-02 11:35:20 +03:00
parent a5915f52ba
commit 5746475d0d
2 changed files with 73 additions and 39 deletions

View File

@ -19,6 +19,7 @@ use \Datetime;
use \DatetimeImmutable;
use \IntlDateFormatter;
use \FPDF;
use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Service\ExportClientStatisticService;
use OCA\Gestion\Service\ExportThanatoStatisticService;
use OCA\Gestion\Service\InvoicePdfService;
@ -32,10 +33,12 @@ class PageController extends Controller {
// private $src_path = "/var/www/html/apps/gestion/img/";
private $src_path = "/var/www/html/custom_apps/gestion/img/";
private $sharedImagePath = "/var/www/html/data/.gestion/";
private $sharedImagePath = "/var/www/html/data/";
private $currentUserImagePath;
private const HYTHA_35_DEFAULT_ADMIN = "Johann";
private const H2F_DEFAULT_ADMIN = "Emmanuelle";
private const DEFAULT_NEXTCLOUD_ADMIN = "admin";
private $urlGenerator;
private $mailer;
private $config;
@ -82,6 +85,7 @@ class PageController extends Controller {
$this->exportThanatoStatisticService = $exportThanatoStatisticService;
$this->exportClientStatisticService = $exportClientStatisticService;
$this->invoicePdfService = $invoicePdfService;
$this->currentUserImagePath = $this->sharedImagePath.$this->idNextcloud.'/files/.gestion/';
//$this->fpdf = $fpdf;
if ($userSession->isLoggedIn()) {
@ -716,12 +720,19 @@ class PageController extends Controller {
}
private function generer_document_comptable_client($date, $idclient) {
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
$current_config = json_decode($this->myDb->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
try {
try {
$logo = $this->getLogo();
$isLogoExist = $logo != "nothing";
$tvaIntraCommuValue = "";
$firstClient = $this->myDb->getFirstClient();
if($firstClient != null){
$tvaIntraCommuValue = $firstClient["legal_one"];
}
$data_factures = array();
$factures = json_decode($this->myDb->getCurrentMonthFactures_byClient($this->idNextcloud, $date, $idclient));
$factures = array_filter($factures, function($facture) {return $facture->id_client != NULL; });
$factures = array_filter($factures, callback: function($facture) {return $facture->id_client != NULL; });
foreach ($factures as $key => $facture) {
$facture_temp = array(
'num' => $facture->num,
@ -743,11 +754,15 @@ class PageController extends Controller {
'montant_ttc' => 0,
);
$produits = json_decode($this->getProduitsById($facture->id_devis));
$produitsReferenceAsString = "";
foreach ($produits as $key => $produit) {
$facture_temp['montant_htc'] += $produit->prix_unitaire * $produit->quantite;
$produitsReferenceAsString .= $produit->reference."-";
};
$produitsReferenceAsString = rtrim($produitsReferenceAsString, "-");
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva'])/100;
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
$facture_temp['produit_references'] = $produitsReferenceAsString;
array_push($data_factures, $facture_temp);
};
@ -791,14 +806,16 @@ class PageController extends Controller {
$pdf->SetMargins(0,0,0);
// logo : 80 de largeur et 55 de hauteur
$pdf->Image($this->src_path."logo.png", 10, 10, 55, 30);
if($isLogoExist){
$pdf->Image($this->currentUserImagePath."logo.png", 10, 10, 55, 30);
}
// adresse du facture
$pdf->SetFont('Arial','B',11); $_x = 122 ; $_y = 40;
$pdf->SetFont('Arial','B',size: 11); $_x = 122 ; $_y = 40;
$pdf->SetXY( $_x, $_y ); $pdf->Cell( 100, 8, utf8_decode($current_client), 0, 0, ''); $_y += 8;
$pdf->SetXY( $_x, $_y ); $pdf->MultiCell( 80, 4, utf8_decode(html_entity_decode($adresse)), 0, 0, '');
// date facture
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 60 );
$pdf->Cell( 60, 8, "Croth le, ".utf8_decode($date_formated), 0, 0, '');
$pdf->Cell( 60, 8, $current_config[0]->adresse . " le, ".utf8_decode($date_formated), 0, 0, '');
// observations
$pdf->SetFont( "Arial", "BU", 10 ); $pdf->SetXY( 10, 85 ) ; $pdf->Cell($pdf->GetStringWidth("Objet:"), 0, "Objet:", 0, "L");
@ -818,15 +835,19 @@ class PageController extends Controller {
// signature
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 145 );
$pdf->Cell( $pdf->GetStringWidth($current_config[0]->nom.' '.$current_config[0]->prenom), 0, utf8_decode(html_entity_decode($current_config[0]->nom.' '.$current_config[0]->prenom)), 0, 0, 'L');
$pdf->Image($this->src_path."sign.png", 122, 150, 55, 30);
$signatureExists = $this->signatureImageExists('sign.png');
if($signatureExists){
$pdf->Image($this->currentUserImagePath."sign.png", 122, 150, 55, 30);
}
$y0 = 260;
$y0 = 265;
$pageWidth = $pdf->GetPageWidth();
//Positionnement en bas et tout centrer
$pdf->SetFont('Arial','',6);
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 8 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 12 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->telephone)), 0, 0, 'C');
$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');
$pdf->SetXY( 1, $y0 + 16 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->telephone)), 0, 0, 'C');
/*$pdf->SetXY( 1, $y0 + 16 );
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
@ -845,8 +866,9 @@ class PageController extends Controller {
// on sup les 2 cm en bas
$pdf->SetAutoPagebreak(False);
$pdf->SetMargins(0,0,0);
$pdf->Image($this->src_path."logo.png", 10, 10, 55, 30);
if($isLogoExist){
$pdf->Image($this->currentUserImagePath."logo.png", 10, 10, 55, 30);
}
// n° page en haute à droite
if($nb_page>1){
@ -855,16 +877,18 @@ class PageController extends Controller {
// date facture
$pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 15 );
$pdf->Cell( 60, 8, "Croth le, ".utf8_decode($date_formated), 0, 0, '');
$pdf->Cell( 60, 8, $current_config[0]->adresse . " le, ".utf8_decode($date_formated), 0, 0, '');
// n° facture, date echeance et reglement et obs
$pdf->SetLineWidth(0.1); $pdf->SetFillColor(255); $pdf->Rect(100, 30, 85, 8, "DF");
$pdf->SetXY( 100, 30 ); $pdf->SetFont( "Arial", "B", 12 ); $pdf->Cell( 85, 8, 'FACTURE N'.utf8_decode('°').' ETS/'.$key_annee.'/'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])), 0, 0, 'C');
$pdf->SetXY( 100, 30 ); $pdf->SetFont( "Arial", "B", 12 ); $pdf->Cell( 85, 8, 'FACTURE N'.utf8_decode('°').' FAC/'.$key_annee.'/'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])), 0, 0, 'C');
// adresse du facture
$pdf->SetFont('Arial','B',11); $x = 122 ; $y = 45;
$pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, utf8_decode($current_client), 0, 0, ''); $y += 8;
$pdf->SetXY( $x, $y ); $pdf->MultiCell( 80, 4, utf8_decode(html_entity_decode($adresse)), 0, 0, ''); $y += 9;
$pdf->SetXY( $x, $y ); $pdf->MultiCell( 80, 4, utf8_decode(html_entity_decode($adresse)), 0, 0, ''); $y += 7;
$pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, FileExportHelpers::FormatTextForExport('Numéro') . ' TVA:', 0, 0, ''); $x+=25;
$pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, FileExportHelpers::FormatTextForExport($tvaIntraCommuValue), 0, 0, '');$y += 7;$x-=25;
$pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, 'Email:', 0, 0, ''); $x+=13;
$pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, utf8_decode(html_entity_decode($facture['mail_client'])), 0, 0, '');
@ -900,10 +924,9 @@ class PageController extends Controller {
$date_soin_temp = new DateTime($client[$index_facture_position]['date_soin']);
$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( 28, 8, $client[$index_facture_position]['numero_commande'], 0, 0, '');
$pdf->SetXY( 53, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 18, 8, utf8_decode($formatter_ds->format($date_soin_temp)), 0, 0, '');
$pdf->SetXY( 65, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 38, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['adresse_devis'])), 0, 0, '');
$pdf->SetXY( 100, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 28, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['defunt'])), 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( 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, $client[$index_facture_position]['montant_htc'].chr(128), 0, 0, 'C');
$pdf->SetXY( 168, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 10, 8, $client[$index_facture_position]['montant_tva'].chr(128), 0, 0, 'C');
$pdf->SetXY( 183, $y_facture ); $pdf->SetFont('Arial','',8); $pdf->Cell( 22, 8, $client[$index_facture_position]['montant_ttc'].chr(128), 0, 0, 'C');
@ -949,9 +972,10 @@ class PageController extends Controller {
// **************************
$pdf->SetFont('Arial','',6);
$pdf->SetXY( 1, $y0 + 4 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 8 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 12 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->telephone)), 0, 0, 'C');
$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');
$pdf->SetXY( 1, $y0 + 16 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->telephone)), 0, 0, 'C');
/*$pdf->SetXY( 1, $y0 + 16 );
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
@ -1241,7 +1265,7 @@ class PageController extends Controller {
* @NoCSRFRequired
*/
public function getConfiguration() {
$idNextcloud = "admin";
$idNextcloud = self::DEFAULT_NEXTCLOUD_ADMIN;
return $this->myDb->getConfiguration($idNextcloud);
}
@ -1985,7 +2009,7 @@ class PageController extends Controller {
$signatureExist = true;
try{
if(isset($this->storage)){
$file = $this->storage->get('/.gestion/' .$signatureImageName);
$file = $this->storage->get("/.gestion/".$signatureImageName);
}else{
$signatureExist = false;
}
@ -1999,14 +2023,10 @@ class PageController extends Controller {
private function getLogo(){
try{
try {
if(isset($this->storage)){
$file = $this->storage->get('/.gestion/logo.png');
}else{
return "nothing";
}
} catch(\OCP\Files\NotFoundException $e) {
$file = $this->storage->get('/.gestion/logo.jpeg');
if(isset($this->storage)){
$file = $this->storage->get('/.gestion/logo.png');
}else{
return "nothing";
}
}
catch(\OCP\Files\NotFoundException $e) {
@ -2204,7 +2224,7 @@ class PageController extends Controller {
// logo : 80 de largeur et 55 de hauteur
$logo = $this->getLogo();
if($logo != 'nothing'){
$pdf->Image($this->sharedImagePath."logo.png", 10, 10, 55, 30);
$pdf->Image($this->currentUserImagePath."logo.png", 10, 10, 55, 30);
}
$pdf->SetY(55); $pdf->SetFont('Arial', 'B', 15); $pdf->Cell(0, 10, "ATTESTATION", 0, 0, 'C');
@ -2240,7 +2260,7 @@ class PageController extends Controller {
$signatureExist = $this->signatureImageExists('sign.png');
if($signatureExist){
$pdf->Image($this->sharedImagePath."sign.png", 15, $pdf->GetY(), 55, 30);
$pdf->Image($this->currentUserImagePath."sign.png", 15, $pdf->GetY(), 55, 30);
}
$pdf->setY($pdf->GetY()-5);
@ -2321,7 +2341,7 @@ class PageController extends Controller {
// logo : 80 de largeur et 55 de hauteur
$logo = $this->getLogo();
if($logo != 'nothing'){
$pdf->Image($this->sharedImagePath."logo.png", 15, 15, 55, 30);
$pdf->Image($this->currentUserImagePath."logo.png", 15, 15, 55, 30);
}
$pdf->setXY(15, 15); $pdf->SetFont('Arial', '', 10); $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("N : ".$numFacture)), '', 'R');
@ -2482,7 +2502,7 @@ class PageController extends Controller {
$signatureExist = $this->signatureImageExists('sign.png');
if($signatureExist){
$pdf->Image($this->sharedImagePath."sign.png", 15, $pdf->GetY(), 55, 30);
$pdf->Image($this->currentUserImagePath."sign.png", 15, $pdf->GetY(), 55, 30);
}
$pdf->setY($pdf->GetY()-5);
@ -2577,7 +2597,7 @@ class PageController extends Controller {
// logo : 80 de largeur et 55 de hauteur
$logo = $this->getLogo();
if($logo != 'nothing'){
$pdf->Image($this->sharedImagePath."logo.png", 10, 10, 55, 30);
$pdf->Image($this->currentUserImagePath."logo.png", 10, 10, 55, 30);
}
$pdf->SetY(55); $pdf->SetFont('Arial', 'B', 15); $pdf->Cell(0, 10, utf8_decode(html_entity_decode("ATTESTATION BIJOU(X)")), 0, 0, 'C');
@ -2621,7 +2641,7 @@ class PageController extends Controller {
$signatureExist = $this->signatureImageExists('sign.png');
if ($signatureExist) {
$pdf->Image($this->sharedImagePath."sign.png", 15, $pdf->GetY(), 55, 30);
$pdf->Image($this->currentUserImagePath."sign.png", 15, $pdf->GetY(), 55, 30);
}
$pdf->setY($pdf->GetY()-5);

View File

@ -2428,4 +2428,18 @@ class Bdd {
return $devisFullNumber;
}
public function getFirstClient(){
$sql = "SELECT * FROM ".$this->tableprefix."client as client LIMIT 1;";
$client = $this->execSQLNoJsonReturn(
$sql,
[]);
if(!empty($client)){
return $client[0];
}
return null;
}
}