Merge branch 'features/feature-group-facturation' into staging

This commit is contained in:
Tiavina 2025-01-23 14:36:06 +03:00
commit 4afb42ee13
16 changed files with 1078 additions and 314 deletions

View File

@ -9909,7 +9909,10 @@ __webpack_require__.r(__webpack_exports__);
let values = [];
results.forEach(result => {
let inputValue = (0,html_entities__WEBPACK_IMPORTED_MODULE_5__.decode)(result.id);
let inputLabel = (0,html_entities__WEBPACK_IMPORTED_MODULE_5__.decode)(result.nom);
let prenomValue = result.prenom;
prenomValue = prenomValue === "" || prenomValue === "-" ? "" : prenomValue;
let fullNameValue = result.nom + " " + prenomValue;
let inputLabel = (0,html_entities__WEBPACK_IMPORTED_MODULE_5__.decode)(fullNameValue);
values.push({
value: inputValue.toString(),
label: inputLabel
@ -310270,4 +310273,4 @@ appointmentsConfigsStore.addInitialConfigs((0,_nextcloud_initial_state__WEBPACK_
/******/ })()
;
//# sourceMappingURL=calendar-main.js.map?v=2146a4228da0323e0f03
//# sourceMappingURL=calendar-main.js.map?v=0dc4fd2a55b47dd8acd1

File diff suppressed because one or more lines are too long

View File

@ -8865,7 +8865,7 @@ window._registerCustomPickerElement = _;
/******/ // This function allow to reference async chunks
/******/ __webpack_require__.u = (chunkId) => {
/******/ // return url for filenames based on template
/******/ return "calendar-" + chunkId + ".js?v=" + {"vendors-node_modules_vue_dist_vue_runtime_esm_js":"7e3171593bdc0f62040b","vendors-node_modules_nextcloud_capabilities_dist_index_js-node_modules_nextcloud_vue-select_d-877981":"31a7d4ece3cdde2d67f1","vendors-node_modules_nextcloud_cdav-library_dist_dist_js-node_modules_nextcloud_logger_dist_i-36c16b":"c3b3db23da041c717fc1","vendors-node_modules_vue-material-design-icons_CalendarBlank_vue-node_modules_vue-material-de-e2c1f8":"1ec24b5ef07652c6dd39","vendors-node_modules_vue-material-design-icons_CalendarBlankOutline_vue-node_modules_nextclou-4adead":"702892edfb255629754c","vendors-node_modules_autosize_dist_autosize_esm_js-node_modules_html-entities_lib_index_js-no-4072c5":"7212b31e059bc10c256e","src_models_rfcProps_js-src_services_caldavService_js-src_services_talkService_js-src_services-8a2790":"7cf71b4f92d5bbc180b4","src_fullcalendar_eventSources_eventSourceFunction_js-src_utils_moment_js-data_image_svg_xml_3-b73258":"740a2859d1f364b508c1","src_views_Calendar_vue-data_image_svg_xml_3csvg_20xmlns_27http_www_w3_org_2000_svg_27_20heigh-4a4254":"b772f2fa794015e69dde","vendors-node_modules_webdav_dist_web_index_js":"454da8f908d41b47c607","src_store_index_js":"e380346f21f6daf64ba8","vendors-node_modules_path-browserify_index_js-node_modules_nextcloud_dialogs_dist_chunks_Dial-e0595f":"7ec0cf6b65f5c745fa03","node_modules_nextcloud_dialogs_dist_legacy_mjs":"8be838e4c6e9aae56c87","vendors-node_modules_nextcloud_dialogs_dist_chunks_FilePicker-8ibBgPg__mjs":"ea54a36450de178d1141","public-calendar-subscription-picker":"2315e24e67ebf6e4b6db","vendors-node_modules_moment_locale_af_js-node_modules_moment_locale_ar-dz_js-node_modules_mom-582c96":"ce1bed825f57dd1d117a","node_modules_moment_locale_sync_recursive_":"4bc2c39c5e0ff182c2e3"}[chunkId] + "";
/******/ return "calendar-" + chunkId + ".js?v=" + {"vendors-node_modules_vue_dist_vue_runtime_esm_js":"7e3171593bdc0f62040b","vendors-node_modules_nextcloud_capabilities_dist_index_js-node_modules_nextcloud_vue-select_d-877981":"31a7d4ece3cdde2d67f1","vendors-node_modules_nextcloud_cdav-library_dist_dist_js-node_modules_nextcloud_logger_dist_i-36c16b":"c3b3db23da041c717fc1","vendors-node_modules_vue-material-design-icons_CalendarBlank_vue-node_modules_vue-material-de-e2c1f8":"1ec24b5ef07652c6dd39","vendors-node_modules_vue-material-design-icons_CalendarBlankOutline_vue-node_modules_nextclou-4adead":"702892edfb255629754c","vendors-node_modules_autosize_dist_autosize_esm_js-node_modules_html-entities_lib_index_js-no-4072c5":"7212b31e059bc10c256e","src_models_rfcProps_js-src_services_caldavService_js-src_services_talkService_js-src_services-8a2790":"7cf71b4f92d5bbc180b4","src_fullcalendar_eventSources_eventSourceFunction_js-src_utils_moment_js-data_image_svg_xml_3-b73258":"740a2859d1f364b508c1","src_views_Calendar_vue-data_image_svg_xml_3csvg_20xmlns_27http_www_w3_org_2000_svg_27_20heigh-4a4254":"f59d0f97f0675fd9c321","vendors-node_modules_webdav_dist_web_index_js":"454da8f908d41b47c607","src_store_index_js":"e380346f21f6daf64ba8","vendors-node_modules_path-browserify_index_js-node_modules_nextcloud_dialogs_dist_chunks_Dial-e0595f":"7ec0cf6b65f5c745fa03","node_modules_nextcloud_dialogs_dist_legacy_mjs":"8be838e4c6e9aae56c87","vendors-node_modules_nextcloud_dialogs_dist_chunks_FilePicker-8ibBgPg__mjs":"ea54a36450de178d1141","public-calendar-subscription-picker":"2315e24e67ebf6e4b6db","vendors-node_modules_moment_locale_af_js-node_modules_moment_locale_ar-dz_js-node_modules_mom-582c96":"ce1bed825f57dd1d117a","node_modules_moment_locale_sync_recursive_":"4bc2c39c5e0ff182c2e3"}[chunkId] + "";
/******/ };
/******/ })();
/******/
@ -9115,4 +9115,4 @@ __webpack_require__.p = (0,_nextcloud_router__WEBPACK_IMPORTED_MODULE_1__.linkTo
/******/ })()
;
//# sourceMappingURL=calendar-reference.js.map?v=0c7983efb99a4e95e241
//# sourceMappingURL=calendar-reference.js.map?v=6458b3ad533e25b1d187

File diff suppressed because one or more lines are too long

View File

@ -6449,7 +6449,10 @@ __webpack_require__.r(__webpack_exports__);
let values = [];
results.forEach(result => {
let inputValue = (0,html_entities__WEBPACK_IMPORTED_MODULE_5__.decode)(result.id);
let inputLabel = (0,html_entities__WEBPACK_IMPORTED_MODULE_5__.decode)(result.nom);
let prenomValue = result.prenom;
prenomValue = prenomValue === "" || prenomValue === "-" ? "" : prenomValue;
let fullNameValue = result.nom + " " + prenomValue;
let inputLabel = (0,html_entities__WEBPACK_IMPORTED_MODULE_5__.decode)(fullNameValue);
values.push({
value: inputValue.toString(),
label: inputLabel
@ -27411,4 +27414,4 @@ module.exports = "data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/sv
/***/ })
}]);
//# sourceMappingURL=calendar-src_views_Calendar_vue-data_image_svg_xml_3csvg_20xmlns_27http_www_w3_org_2000_svg_27_20heigh-4a4254.js.map?v=b772f2fa794015e69dde
//# sourceMappingURL=calendar-src_views_Calendar_vue-data_image_svg_xml_3csvg_20xmlns_27http_www_w3_org_2000_svg_27_20heigh-4a4254.js.map?v=f59d0f97f0675fd9c321

View File

@ -91,7 +91,10 @@ export default {
let values = []
results.forEach(result => {
let inputValue = decode(result.id)
let inputLabel = decode(result.nom)
let prenomValue = result.prenom
prenomValue = prenomValue === "" || prenomValue === "-" ? "" : prenomValue
let fullNameValue = result.nom + " " + prenomValue
let inputLabel = decode(fullNameValue)
values.push({
value : inputValue.toString(),
label :inputLabel

View File

@ -749,303 +749,8 @@ class PageController extends Controller {
}
private function generer_document_comptable_client($date, $filter,$filterType) {
$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));
if($filterType == MultipleFactureTypeConstant::CLIENT_FILTER_TYPE){
$factures = json_decode($this->myDb->getClientFacturesByClientIdAndDate(
clientId: $filter,
date: $date
));
}
else{
$factures = json_decode($this->myDb->getClientFacturesByClientGroupFacturationIdAndDate(
clientGroupFacturationId: $filter,
date: $date
));
}
$factures = array_filter($factures, callback: function($facture) {return $facture->id_client != NULL; });
foreach ($factures as $key => $facture) {
$facture_temp = array(
'num' => $facture->num,
'id_client' => $facture->id_client,
'client' => $facture->entreprise,
'adresse_client' => $facture->adresse_client,
'mail_client' => $facture->mail_client,
'adresse_devis' => $facture->lieu,
'nom_client' => html_entity_decode($facture->nom),
'prenoms_client' => html_entity_decode($facture->prenom),
'numero_commande' => $facture->numero_commande,
'date_soin' => $facture->date_soin,
'date' => $facture->date,
'date_facture' => $facture->date_paiement,
'defunt' => $facture->nom_defunt,
'montant_htc' => 0,
'tva' => $current_config[0]->tva_default,
'montant_tva' => 0,
'montant_ttc' => 0,
);
$produits = json_decode($this->getProduitsById($facture->id_devis));
$produitsReferenceArray = [];
foreach ($produits as $key => $produit) {
$facture_temp['montant_htc'] += $produit->prix_unitaire * $produit->quantite;
$produitsReferenceArray[] = $produit->reference;
};
$produitsReferenceArray = array_unique($produitsReferenceArray);
$produitsReferenceAsString = implode("-", $produitsReferenceArray);
$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);
};
$data_temp = array();
foreach ($data_factures as $key => $facture) {
$datesplit = explode('-', $facture['date_facture']);
if($data_temp[strval($datesplit[0])][strval($datesplit[1])][$facture['id_client']]==NULL) {
$data_temp[strval($datesplit[0])][strval($datesplit[1])][$facture['id_client']] = array(0=>$facture);
} else {
array_push($data_temp[strval($datesplit[0])][strval($datesplit[1])][$facture['id_client']], $facture);
}
}
foreach ($data_temp as $key_annee => $annee) {
foreach ($annee as $key_mois => $mois) {
foreach ($mois as $key_client => $client) {
$pdf = new FPDF();
$pdf->AddFont('ComicSans','','Comic Sans MS.php');
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
$current_client = '';
$clientAddress = '';
$clientCity = '';
$date_facture;
$j=1;
foreach ($client as $key => $facture) {
if($j==1) {
$current_client = $facture['prenoms_client'].' '.$facture['nom_client'];
$date_facture = $facture['date_facture'];
$clientAddresses = FileExportHelpers::GetAddressAndCityFromAddress($facture['adresse_client']);
$clientAddress = $clientAddresses['address'];
$clientCity = $clientAddresses['city'];
}
$j++;
}
$date_temp = date("t-m-Y", strtotime($date_facture));
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
$date_formated = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_temp));
try {
$this->storage->newFolder(html_entity_decode($current_config[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'/');
} catch(\OCP\Files\NotPermittedException $e) { }
$pdf->AddPage();
// on sup les 2 cm en bas
$pdf->SetAutoPagebreak(False);
$pdf->SetMargins(0,0,10);
// logo : 80 de largeur et 55 de hauteur
if($isLogoExist){
$pdf->Image($this->defaultImagePath."logo.png", 10, 10, 75, 25);
}
// adresse du facture
$pdf->SetFont('ComicSans','B',size: 11);
$pdf->SetY(40);
$pdf->Cell( 0, 8, utf8_decode($current_client), 0, 1, 'R');
$pdf->Cell( 0, 8, trim(utf8_decode(html_entity_decode($clientAddress))), 0,1,'R');
if($clientCity != ''){
$pdf->Cell( 0, 8, trim(utf8_decode(html_entity_decode($clientCity))), 0, 1, 'R');
}
// date facture
$pdf->SetFont('ComicSans','',11);
$pdf->Cell( 0, 8, "Saint Senoux, le ".utf8_decode($date_formated), 0, 1, 'R');
// observations
$pdf->SetFont( "ComicSans", "BU", 10 ); $pdf->SetXY( 10, 85 ) ; $pdf->Cell($pdf->GetStringWidth("Objet:"), 0, "Objet:", 0, "L");
$objet = utf8_decode("Récapitulatif Facturation du mois de ").strtoupper($this->convert_special_char(explode(' ', $date_formated)[1]));
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 85 ) ; $pdf->Cell($pdf->GetStringWidth($objet), 0, $objet, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 95 ); $pdf->Cell($pdf->GetStringWidth("Madame, Monsieur"), 0, "Madame, Monsieur", 0, "L");
$text1 = utf8_decode("Veuillez trouver ci-dessous le récapitulatif de la facturation du mois de ").strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).".";
$text2 = utf8_decode("Vous en souhaitant bonne réception.");
$text3 = utf8_decode("Veuillez agréer, Madame, Monsieur, mes salutations les meilleures.");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 105 ) ; $pdf->Cell($pdf->GetStringWidth($text1), 0, $text1, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 110 ) ; $pdf->Cell($pdf->GetStringWidth($text2), 0, $text2, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 120 ) ; $pdf->Cell($pdf->GetStringWidth($text3), 0, $text3, 0, "L");
// signature
$pdf->SetFont('ComicSans','',11); $pdf->SetXY( 145, 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');
$signatureExists = $this->signatureImageExists('sign.png');
if($signatureExists){
$pdf->Image($this->defaultImagePath."sign.png", 135, 150, 55, 30);
}
$y0 = 260;
$pageWidth = $pdf->GetPageWidth();
//Positionnement en bas et tout centrer
$pdf->SetFont('ComicSans','',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');
$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');*/
$num_page = 1;
$nb_page = ceil(sizeof($client) / 26);
$index_facture_position = 0;
$max_nb_toget = (sizeof($client)<=26)?sizeof($client):26;
$montant_ht_total = 0;
$montant_tva_total = 0;
$montant_ttc_total = 0;
while ($num_page <= $nb_page) {
$pdf->AddPage();
// on sup les 2 cm en bas
$pdf->SetAutoPagebreak(False);
$pdf->SetMargins(0,0,10);
if($isLogoExist){
$pdf->Image($this->defaultImagePath."logo.png", 10, 10, 75, 25);
}
// n° page en haute à droite
if($nb_page>1){
$pdf->SetXY( 120, 5 ); $pdf->SetFont( "ComicSans", "B", 9 ); $pdf->Cell( 160, 8, $num_page . '/' . $nb_page, 0, 0, 'C');
}
// date facture
$pdf->SetFont('ComicSans','',11);
$pdf->SetY(10);
$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");
$pdf->SetXY( 114, 20 ); $pdf->SetFont( "ComicSans", "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('ComicSans','B',11);
$pdf->SetY(y: 32);
$pdf->Cell( 0, 6, utf8_decode($current_client), 0, 1, 'R');
$pdf->Cell( 0, 6, trim(utf8_decode(html_entity_decode($clientAddress))), 0, 1, 'R');
if($clientCity != ''){
$pdf->Cell( 0, 6, trim(utf8_decode(html_entity_decode($clientCity))), 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');
// ***********************
// le cadre des articles
// ***********************
// cadre avec 18 lignes max ! et 118 de hauteur --> 80 + 118 = 198 pour les traits verticaux
$pdf->SetLineWidth(0.1); $pdf->Rect(5, 80, 200, 153, "D");
// 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);
if($num_page == $nb_page) $pdf->Line(183, 80, 183, 240);
else $pdf->Line(183, 80, 183, 233);
// titre colonne
$pdf->SetXY( 1, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 140, 8, "OBJET", 0, 0, 'C');
$pdf->SetXY( 147, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 13, 8, "H.T.", 0, 0, 'C');
$pdf->SetXY( 168, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 10, 8, "TVA 20%", 0, 0, 'C');
$pdf->SetXY( 183, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 22, 8, "T.T.C", 0, 0, 'C');
// (new DateTime($facture['date_soin']))->format('d-M')
$formatter_ds = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
// Set the pattern for the formatter to "d-MMMM" to display the day and month name in French
$formatter_ds->setPattern('dd-MMM');
//recuperation des factures
$y_facture = 90;
$init_index = $index_facture_position;
for ($index_facture_position; $index_facture_position < ($init_index + $max_nb_toget) ; $index_facture_position++) {
$date_soin_temp = new DateTime($client[$index_facture_position]['date_soin']);
$pdf->SetXY( 6, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 28, 8, $client[$index_facture_position]['num'], 0, 0, '');
$pdf->SetXY( 32, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 18, 8, utf8_decode($formatter_ds->format($date_soin_temp)), 0, 0, '');
$pdf->SetXY( 50, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 38, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['defunt'])), 0, 0, '');
$pdf->SetXY( 90, $y_facture ); $pdf->SetFont('ComicSans','',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('ComicSans','',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('ComicSans','',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('ComicSans','',8); $pdf->Cell( 22, 8, number_format($client[$index_facture_position]['montant_ttc'],2,'.','').chr(128), 0, 0, 'C');
$montant_ht_total = $montant_ht_total+$client[$index_facture_position]['montant_htc'];
$montant_tva_total = $montant_tva_total+$client[$index_facture_position]['montant_tva'];
$montant_ttc_total = $montant_ttc_total+$client[$index_facture_position]['montant_ttc'];
$y_facture=$y_facture+5;
}
$nb_facture_chargee = $index_facture_position+1;
$reste_a_chargee = sizeof($client) - $nb_facture_chargee;
$max_nb_toget = ($reste_a_chargee <= 26) ? $reste_a_chargee+1 : 26;
// si derniere page alors afficher cadre des TVA
if ($num_page == $nb_page)
{
$pdf->Line(5, 225, 205, 225);
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 5, 225 ); $pdf->Cell( 140, 8, 'TOTAL', 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 147, 225 ); $pdf->Cell( 13, 8, number_format($montant_ht_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 168, 225 ); $pdf->Cell( 10, 8, number_format($montant_tva_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 183, 225 ); $pdf->Cell( 22, 8, number_format($montant_ttc_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->Rect(145, 233, 60, 7, "D");
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 147, 233 ); $pdf->Cell( 30, 6.5, 'TOTAL TTC', 0, 0, 'C');
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 183, 233 ); $pdf->Cell( 22, 6.5, number_format($montant_ttc_total,2,'.','').chr(128), 0, 0, 'C', true);
}
$y1 = 245;
$pdf->SetFillColor(255);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont('ComicSans','',9);
$pdf->SetXY( 10, $y1 );$pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Loi N° 92-442 du 31 décembre 1992: La présente facture est payable en comptant a réception."), 0, 0, 'L');
$pdf->SetXY( 10, $y1 + 4 );$pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Indemnité forfaitaire pour frais de recouvrement due en cas de retard de paiement: 40").chr(128), 0, 0, 'L');
$pdf->SetXY( 10, $y1 + 8 );$pdf->Multicell( $pdf->GetPageWidth()-20, 4, utf8_decode("Toute somme non payée dans les trente jours est susceptible de porter intérets à un taux égal à une fois et demi le taux de l'intéret légal."), 0, 0, 'L');
// **************************
// pied de page
// **************************
$pdf->SetFont('ComicSans','',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');
$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');*/
$num_page++;
}
$ff_pdf = html_entity_decode($current_config[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'/'.strtoupper($this->convert_special_char($current_client)).'_RECAP_FACTURE_'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'_'.$key_annee.'.pdf';
$this->storage->newFile($ff_pdf);
$pdfContent = $pdf->Output('','S');
$file_pdf = $this->storage->get($ff_pdf);
$file_pdf->putContent($pdfContent);
}
}
}
} catch(\OCP\Files\NotFoundException $e) { }
$this->invoicePdfService->generateInvoiceRecap($filter,$filterType,$date,$this->idNextcloud);
} catch(\OCP\Files\NotPermittedException $e) { }
}

View File

@ -391,12 +391,14 @@ class Bdd {
.$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."client_group_facturation.id as client_group_facturation_id, ".$this->tableprefix."client_group_facturation.group_facturation_name as group_facturation_name,"
.$this->tableprefix."facture.version, status_paiement
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
LEFT JOIN ".$this->tableprefix."defunt on ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id
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('-', $date)[2]." AND MONTH(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[1]."
AND ".$this->tableprefix."client.id IN($clientIdsSqlPlaceholder) ORDER BY year DESC, month DESC;";
$result = $this->execSQL(

View File

@ -37,4 +37,15 @@ class FileExportHelpers
return $stringWithoutSpace;
}
public static function ConvertSpecialChar($str) {
$unwanted_array = array(
'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y'
);
return strtr( $str, $unwanted_array );
}
}

View File

@ -137,7 +137,7 @@ class DevisPdfService {
}
private function getDevisPdfFolder(array $devisPdfData,$racinePath){
$clientRacineFolder = $racinePath.'CLIENTS/'.strtoupper($devisPdfData["client_entreprise"]).'/';
$clientRacineFolder = $racinePath.'CLIENTS/'.strtoupper($devisPdfData["client_nom"]).'/';
$defuntsFolder = $clientRacineFolder.'DEFUNTS/'.strtoupper($devisPdfData['defunt_nom']).'/'.'DEVIS'.'/';
$devisDate = $devisPdfData['devis_date'];
$devisDatetime = new DateTime($devisDate);

View File

@ -77,10 +77,10 @@ class InvoicePdfHandler extends FPDF {
foreach($this->multipleFactureData as $factureData){
$factureType = $factureData["facture_type"];
if($factureType == MultipleFactureTypeConstant::CLIENT_FILTER_TYPE){
$filename = mb_strtoupper($factureData["client_entreprise"],'UTF-8');
$filename = mb_strtoupper($factureData["client_prenom"],'UTF-8');
}
else{
$filename = 'GROUP_'.mb_strtoupper($factureData["client_entreprise"],'UTF-8');
$filename = 'GROUP_'.mb_strtoupper($factureData["client_nom"],'UTF-8');
}
$filename .= $month != 0 ? '_'.DateHelpers::GetMonthPlainString($month) :'';
$filename .= "_".$year;

View File

@ -29,6 +29,7 @@ namespace OCA\Gestion\Service;
use DateTime;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Helpers\DateHelpers;
use OCA\Gestion\Service\InvoiceRecap\InvoiceRecapService;
use OCP\Files\IRootFolder;
class InvoicePdfService {
@ -38,12 +39,17 @@ class InvoicePdfService {
/** @var IRootFolder */
private $rootFolder;
/** @var InvoiceRecapService */
private $invoiceRecapService;
private const DEFAULT_NEXTCLOUD_ADMIN = "admin";
public function __construct(
Bdd $gestionBdd,
IRootFolder $rootFolder) {
IRootFolder $rootFolder,
InvoiceRecapService $invoiceRecapService) {
$this->gestionBdd = $gestionBdd;
$this->rootFolder = $rootFolder;
$this->invoiceRecapService = $invoiceRecapService;
}
private function getLogo(){
@ -101,7 +107,7 @@ class InvoicePdfService {
}
private function getFacturesFolder(array $factureData,$racinePath){
$clientRacineFolder = $racinePath.'CLIENTS/'.mb_strtoupper($factureData["client_entreprise"],'UTF-8').'/';
$clientRacineFolder = $racinePath.'CLIENTS/'.mb_strtoupper($factureData["client_nom"],'UTF-8').'/';
$defuntsFolder = $clientRacineFolder.'DEFUNTS/'.mb_strtoupper($factureData['defunt_nom'],'UTF-8').'/'.'FACTURES'.'/';
$devisDate = $factureData['devis_date'];
$devisDatetime = new DateTime($devisDate);
@ -149,4 +155,8 @@ class InvoicePdfService {
$file_pdf->putContent($pdfContent);
return $filenamePath;
}
public function generateInvoiceRecap($filter,$filterType,$date,$idNextCloud){
$this->invoiceRecapService->generateInvoiceRecap($filter,$filterType,$date,$idNextCloud);
}
}

View File

@ -0,0 +1,656 @@
<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Gestion\Service\InvoiceRecap;
use DateTime;
use OCA\Gestion\Constants\MultipleFactureTypeConstant;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Helpers\DateHelpers;
use OCP\Files\IRootFolder;
use \FPDF;
use IntlDateFormatter;
use OCA\Gestion\Helpers\FileExportHelpers;
class InvoiceRecapService {
/** @var Bdd */
private $gestionBdd;
/** @var IRootFolder */
private $rootFolder;
private $defaultImagePath = "/var/www/html/data/admin/files/.gestion/";
private const DEFAULT_NEXTCLOUD_ADMIN = "admin";
public function __construct(
Bdd $gestionBdd,
IRootFolder $rootFolder) {
$this->gestionBdd = $gestionBdd;
$this->rootFolder = $rootFolder;
}
private function doesSignatureImageExists(){
$storage = $this->rootFolder->getUserFolder(self::DEFAULT_NEXTCLOUD_ADMIN);
try{
if(isset($storage)){
$storage->get("/.gestion/sign.png");
$signatureExist = true;
}else{
$signatureExist = false;
}
}
catch(\OCP\Files\NotFoundException $e) {
$signatureExist = false;
}
return $signatureExist;
}
private function doesLogoExist(){
$storage = $this->rootFolder->getUserFolder(self::DEFAULT_NEXTCLOUD_ADMIN);
try{
if(isset($storage)){
$file = $storage->get('/.gestion/logo.png');
return true;
}else{
return false;
}
}
catch(\OCP\Files\NotFoundException $e) {
return false;
}
}
private function generateInvoiceRecapPerClientGroupFacturation($clientGroupId,$date,$idNextcloud){
$data_factures = [];
$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));
$factures = json_decode($this->gestionBdd->getClientFacturesByClientGroupFacturationIdAndDate($clientGroupId,$date));
$factures = array_filter($factures, callback: function($facture) {return $facture->id_client != NULL; });
$groupName = "";
foreach ($factures as $key => $facture) {
$facture_temp = array(
'num' => $facture->num,
'id_client' => $facture->id_client,
'client' => $facture->entreprise,
'adresse_client' => $facture->adresse_client,
'mail_client' => $facture->mail_client,
'adresse_devis' => $facture->lieu,
'nom_client' => html_entity_decode($facture->nom),
'prenoms_client' => html_entity_decode($facture->prenom),
'numero_commande' => $facture->numero_commande,
'date_soin' => $facture->date_soin,
'date' => $facture->date,
'date_facture' => $facture->date_paiement,
'defunt' => $facture->nom_defunt,
'montant_htc' => 0,
'tva' => $defaultConfig[0]->tva_default,
'montant_tva' => 0,
'montant_ttc' => 0,
'group_facturation_name' => $facture->group_facturation_name
);
$produits = json_decode($this->gestionBdd->getListProduit($facture->id_devis,$idNextcloud));
$produitsReferenceArray = [];
foreach ($produits as $key => $produit) {
$facture_temp['montant_htc'] += $produit->prix_unitaire * $produit->quantite;
$produitsReferenceArray[] = $produit->reference;
};
$produitsReferenceArray = array_unique($produitsReferenceArray);
$produitsReferenceAsString = implode("-", $produitsReferenceArray);
$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);
};
$data_temp = array();
foreach ($data_factures as $key => $facture) {
$datesplit = explode('-', $facture['date_facture']);
if($data_temp[strval($datesplit[0])][strval($datesplit[1])]==NULL) {
$data_temp[strval($datesplit[0])][strval($datesplit[1])] = array(0=>$facture);
} else {
array_push($data_temp[strval($datesplit[0])][strval($datesplit[1])], $facture);
}
}
foreach ($data_temp as $key_annee => $annee) {
foreach ($annee as $key_mois => $mois) {
$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));
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
$date_formated = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_temp));
try {
$storage->newFolder(html_entity_decode($defaultConfig[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper(FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])).'/');
} catch(\OCP\Files\NotPermittedException $e) { }
$pdf->AddPage();
// on sup les 2 cm en bas
$pdf->SetAutoPagebreak(False);
$pdf->SetMargins(0,0,0);
// logo : 80 de largeur et 55 de hauteur
if($doesLogoExist){
$pdf->Image($this->defaultImagePath."logo.png", 10, 10, 75, 25);
}
// adresse du facture
$pdf->SetFont('ComicSans','B',11); $_x = 122 ; $_y = 40;
$pdf->SetXY( $_x, $_y ); $pdf->Cell( 100, 8, utf8_decode('Groupe '.$groupName), 0, 0, ''); $_y += 8;
// date facture
$pdf->SetFont('ComicSans','',11); $pdf->SetXY( 122, 60 );
$pdf->Cell( 60, 8, "Saint Senoux, le ".utf8_decode($date_formated), 0, 0, '');
// observations
$pdf->SetFont( "ComicSans", "BU", 10 ); $pdf->SetXY( 10, 85 ) ; $pdf->Cell($pdf->GetStringWidth("Objet:"), 0, "Objet:", 0, "L");
$objet = utf8_decode("Récapitulatif Facturation du mois de ").strtoupper(FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1]));
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 85 ) ; $pdf->Cell($pdf->GetStringWidth($objet), 0, $objet, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 95 ); $pdf->Cell($pdf->GetStringWidth("Madame, Monsieur"), 0, "Madame, Monsieur", 0, "L");
$text1 = utf8_decode("Veuillez trouver ci-dessous le récapitulatif de la facturation du mois de ").strtoupper(FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])).".";
$text2 = utf8_decode("Vous en souhaitant bonne réception.");
$text3 = utf8_decode("Veuillez agréer, Madame, Monsieur, mes salutations les meilleures.");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 105 ) ; $pdf->Cell($pdf->GetStringWidth($text1), 0, $text1, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 110 ) ; $pdf->Cell($pdf->GetStringWidth($text2), 0, $text2, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 120 ) ; $pdf->Cell($pdf->GetStringWidth($text3), 0, $text3, 0, "L");
// 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');
if($doesSignatureExist){
$pdf->Image($this->defaultImagePath."sign.png", 135, 150, 60,40);
}
$y0 = 260;
$pageWidth = $pdf->GetPageWidth();
//Positionnement en bas et tout centrer
$pdf->SetFont('ComicSans','',6);
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->legal_one)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 8 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->legal_two)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 12 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->telephone)), 0, 0, 'C');
/*$pdf->SetXY( 1, $y0 + 16 );
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
$num_page = 1;
$nb_page = ceil(sizeof($mois) / 26);
$index_facture_position = 0;
$max_nb_toget = (sizeof($mois)<=26)?sizeof($mois):26;
$montant_ht_total = 0;
$montant_tva_total = 0;
$montant_ttc_total = 0;
while ($num_page <= $nb_page) {
$pdf->AddPage();
// on sup les 2 cm en bas
$pdf->SetAutoPagebreak(False);
$pdf->SetMargins(0,0,10);
if($doesLogoExist){
$pdf->Image($this->defaultImagePath."logo.png", 10, 10, 75, 25);
}
// n° page en haute à droite
if($nb_page>1){
$pdf->SetXY( 120, 5 ); $pdf->SetFont( "ComicSans", "B", 9 ); $pdf->Cell( 160, 8, $num_page . '/' . $nb_page, 0, 0, 'C');
}
// date facture
$pdf->SetFont('ComicSans','',11); $pdf->SetXY( 122, 15 );
$pdf->SetY(10);
$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");
$pdf->SetXY( 114, 20 ); $pdf->SetFont( "ComicSans", "B", 12 ); $pdf->Cell( 85, 8, 'FACTURE N'.utf8_decode('°').' FAC/'.$key_annee.'/'.strtoupper(FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])), 0, 0, 'C');
// adresse du facture
$pdf->SetFont('ComicSans','B',11);
$pdf->SetY(32);
// $pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, 'doit', 0, 0, ''); $y += 8;
$pdf->Cell( 0, 6, 'Groupe '.$groupName, 0, 1, 'R');
$pdf->Cell( 0, 6, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . FileExportHelpers::FormatTextForExport($tvaIntraCommuValue), 0, 1, 'R');
// ***********************
// le cadre des articles
// ***********************
// cadre avec 18 lignes max ! et 118 de hauteur --> 80 + 118 = 198 pour les traits verticaux
$pdf->SetLineWidth(0.1); $pdf->Rect(5, 80, 200, 153, "D");
// 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);
if($num_page == $nb_page) $pdf->Line(183, 80, 183, 240);
else $pdf->Line(183, 80, 183, 233);
// titre colonne
$pdf->SetXY( 1, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 140, 8, "OBJET", 0, 0, 'C');
$pdf->SetXY( 147, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 13, 8, "H.T.", 0, 0, 'C');
$pdf->SetXY( 168, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 10, 8, "TVA 20%", 0, 0, 'C');
$pdf->SetXY( 183, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 22, 8, "T.T.C", 0, 0, 'C');
// (new DateTime($facture['date_soin']))->format('d-M')
$formatter_ds = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
// Set the pattern for the formatter to "d-MMMM" to display the day and month name in French
$formatter_ds->setPattern('dd-MMM');
//recuperation des factures
$y_facture = 90;
$init_index = $index_facture_position;
for ($index_facture_position; $index_facture_position < ($init_index + $max_nb_toget) ; $index_facture_position++) {
$date_soin_temp = new DateTime($mois[$index_facture_position]['date_soin']);
$pdf->SetXY( 6, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 28, 8, $mois[$index_facture_position]['num'], 0, 0, '');
$pdf->SetXY( 26, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 28, 8, utf8_decode($formatter_ds->format($date_soin_temp)), 0, 0, '');
$pdf->SetXY( 40, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 18, 8, utf8_decode(html_entity_decode($mois[$index_facture_position]['defunt'])), 0, 0, '');
$pdf->SetXY( 86, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 38, 8, $mois[$index_facture_position]['prenoms_client'].' '.$mois[$index_facture_position]['nom_client'], 0, 0, '');
$pdf->SetXY( 147, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 13, 8, number_format($mois[$index_facture_position]['montant_htc'],2,'.','').chr(128), 0, 0, 'C');
$pdf->SetXY( 168, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 10, 8, number_format($mois[$index_facture_position]['montant_tva'],2,'.','').chr(128), 0, 0, 'C');
$pdf->SetXY( 183, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 22, 8, number_format($mois[$index_facture_position]['montant_ttc'],2,'.','').chr(128), 0, 0, 'C');
$montant_ht_total = $montant_ht_total+$mois[$index_facture_position]['montant_htc'];
$montant_tva_total = $montant_tva_total+$mois[$index_facture_position]['montant_tva'];
$montant_ttc_total = $montant_ttc_total+$mois[$index_facture_position]['montant_ttc'];
$y_facture=$y_facture+5;
}
$nb_facture_chargee = $index_facture_position+1;
$reste_a_chargee = sizeof($mois) - $nb_facture_chargee;
$max_nb_toget = ($reste_a_chargee <= 26) ? $reste_a_chargee+1 : 26;
// si derniere page alors afficher cadre des TVA
if ($num_page == $nb_page)
{
$pdf->Line(5, 225, 205, 225);
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 5, 225 ); $pdf->Cell( 140, 8, 'TOTAL', 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 147, 225 ); $pdf->Cell( 13, 8, number_format($montant_ht_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 168, 225 ); $pdf->Cell( 10, 8, number_format($montant_tva_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 183, 225 ); $pdf->Cell( 22, 8, number_format($montant_ttc_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->Rect(145, 233, 60, 7, "D");
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 147, 233 ); $pdf->Cell( 30, 6.5, 'TOTAL TTC', 0, 0, 'C');
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 183, 233 ); $pdf->Cell( 22, 6.5, number_format($montant_ttc_total,2,'.','').chr(128), 0, 0, 'C', true);
}
$y1 = 245;
$pdf->SetFillColor(255);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont('ComicSans','',9);
$pdf->SetXY( 10, $y1 ); $pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Loi N° 92-442 du 31 décembre 1992: La présente facture est payable en comptant a réception."), 0, 0, 'L');
$pdf->SetXY( 10, $y1 + 4 ); $pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Indemnité forfaitaire pour frais de recouvrement due en cas de retard de paiement: 40").chr(128), 0, 0, 'L');
$pdf->SetXY( 10, $y1 + 8 ); $pdf->Multicell( $pdf->GetPageWidth()-20, 4, utf8_decode("Toute somme non payée dans les trente jours est susceptible de porter intérets à un taux égal à une fois et demi le taux de l'intéret légal."), 0, 0, 'L');
// **************************
// pied de page
// **************************
$pdf->SetFont('ComicSans','',6);
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->legal_one)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 8 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->legal_two)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 12 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->telephone)), 0, 0, 'C');
/*$pdf->SetXY( 1, $y0 + 16 );
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
$num_page++;
}
// var_dump("tonga aty ve");die;
$ff_pdf = html_entity_decode(
$defaultConfig[0]->path).
'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.
strtoupper(
FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])
).
'/GROUPE_'.$groupName.'_RECAP_FACTURE_'.strtoupper(
FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])
).'_'.$key_annee.'.pdf';
$storage->newFile($ff_pdf);
$pdfContent = $pdf->Output('','S');
$file_pdf = $storage->get($ff_pdf);
$file_pdf->putContent($pdfContent);
}
}
}
private function generateInvoiceRecapPerClient($clientId,$date,$idNextcloud){
$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));
$factures = json_decode($this->gestionBdd->getClientFacturesByClientIdAndDate(
clientId: $clientId,
date: $date
));
$factures = array_filter($factures, callback: function($facture) {return $facture->id_client != NULL; });
foreach ($factures as $key => $facture) {
$facture_temp = array(
'num' => $facture->num,
'id_client' => $facture->id_client,
'client' => $facture->entreprise,
'adresse_client' => $facture->adresse_client,
'mail_client' => $facture->mail_client,
'adresse_devis' => $facture->lieu,
'nom_client' => html_entity_decode($facture->nom),
'prenoms_client' => html_entity_decode($facture->prenom),
'numero_commande' => $facture->numero_commande,
'date_soin' => $facture->date_soin,
'date' => $facture->date,
'date_facture' => $facture->date_paiement,
'defunt' => $facture->nom_defunt,
'montant_htc' => 0,
'tva' => $defaultConfig[0]->tva_default,
'montant_tva' => 0,
'montant_ttc' => 0,
);
$produits = json_decode($this->gestionBdd->getListProduit($facture->id_devis,$idNextcloud));
$produitsReferenceArray = [];
foreach ($produits as $key => $produit) {
$facture_temp['montant_htc'] += $produit->prix_unitaire * $produit->quantite;
$produitsReferenceArray[] = $produit->reference;
};
$produitsReferenceArray = array_unique($produitsReferenceArray);
$produitsReferenceAsString = implode("-", $produitsReferenceArray);
$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);
};
$data_temp = array();
foreach ($data_factures as $key => $facture) {
$datesplit = explode('-', $facture['date_facture']);
if($data_temp[strval($datesplit[0])][strval($datesplit[1])][$facture['id_client']]==NULL) {
$data_temp[strval($datesplit[0])][strval($datesplit[1])][$facture['id_client']] = array(0=>$facture);
} else {
array_push($data_temp[strval($datesplit[0])][strval($datesplit[1])][$facture['id_client']], $facture);
}
}
foreach ($data_temp as $key_annee => $annee) {
foreach ($annee as $key_mois => $mois) {
foreach ($mois as $key_client => $client) {
$pdf = new FPDF();
$pdf->AddFont('ComicSans','','Comic Sans MS.php');
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
$current_client = '';
$clientAddress = '';
$clientCity = '';
$date_facture;
$j=1;
foreach ($client as $key => $facture) {
if($j==1) {
$current_client = $facture['prenoms_client'].' '.$facture['nom_client'];
$date_facture = $facture['date_facture'];
$clientAddresses = FileExportHelpers::GetAddressAndCityFromAddress($facture['adresse_client']);
$clientAddress = $clientAddresses['address'];
$clientCity = $clientAddresses['city'];
}
$j++;
}
$date_temp = date("t-m-Y", strtotime($date_facture));
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
$date_formated = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_temp));
try {
$storage->newFolder(html_entity_decode($defaultConfig[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper(FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])).'/');
} catch(\OCP\Files\NotPermittedException $e) { }
$pdf->AddPage();
// on sup les 2 cm en bas
$pdf->SetAutoPagebreak(False);
$pdf->SetMargins(0,0,10);
// logo : 80 de largeur et 55 de hauteur
if($doesLogoExist){
$pdf->Image($this->defaultImagePath."logo.png", 10, 10, 75, 25);
}
// adresse du facture
$pdf->SetFont('ComicSans','B',size: 11);
$pdf->SetY(40);
$pdf->Cell( 0, 8, utf8_decode($current_client), 0, 1, 'R');
$pdf->Cell( 0, 8, trim(utf8_decode(html_entity_decode($clientAddress))), 0,1,'R');
if($clientCity != ''){
$pdf->Cell( 0, 8, trim(utf8_decode(html_entity_decode($clientCity))), 0, 1, 'R');
}
// date facture
$pdf->SetFont('ComicSans','',11);
$pdf->Cell( 0, 8, "Saint Senoux, le ".utf8_decode($date_formated), 0, 1, 'R');
// observations
$pdf->SetFont( "ComicSans", "BU", 10 ); $pdf->SetXY( 10, 85 ) ; $pdf->Cell($pdf->GetStringWidth("Objet:"), 0, "Objet:", 0, "L");
$objet = utf8_decode("Récapitulatif Facturation du mois de ").strtoupper(FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1]));
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 85 ) ; $pdf->Cell($pdf->GetStringWidth($objet), 0, $objet, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 95 ); $pdf->Cell($pdf->GetStringWidth("Madame, Monsieur"), 0, "Madame, Monsieur", 0, "L");
$text1 = utf8_decode("Veuillez trouver ci-dessous le récapitulatif de la facturation du mois de ").strtoupper(FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])).".";
$text2 = utf8_decode("Vous en souhaitant bonne réception.");
$text3 = utf8_decode("Veuillez agréer, Madame, Monsieur, mes salutations les meilleures.");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 105 ) ; $pdf->Cell($pdf->GetStringWidth($text1), 0, $text1, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 110 ) ; $pdf->Cell($pdf->GetStringWidth($text2), 0, $text2, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 120 ) ; $pdf->Cell($pdf->GetStringWidth($text3), 0, $text3, 0, "L");
// 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');
if($signatureExists){
$pdf->Image($this->defaultImagePath."sign.png", 135, 150, 60,40);
}
$y0 = 260;
$pageWidth = $pdf->GetPageWidth();
//Positionnement en bas et tout centrer
$pdf->SetFont('ComicSans','',7);
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->mentions_default)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 8 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->legal_one)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 12 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->legal_two)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 16 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->telephone)), 0, 0, 'C');
/*$pdf->SetXY( 1, $y0 + 16 );
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
$num_page = 1;
$nb_page = ceil(sizeof($client) / 26);
$index_facture_position = 0;
$max_nb_toget = (sizeof($client)<=26)?sizeof($client):26;
$montant_ht_total = 0;
$montant_tva_total = 0;
$montant_ttc_total = 0;
while ($num_page <= $nb_page) {
$pdf->AddPage();
// on sup les 2 cm en bas
$pdf->SetAutoPagebreak(False);
$pdf->SetMargins(0,0,10);
if($doesLogoExist){
$pdf->Image($this->defaultImagePath."logo.png", 10, 10, 75, 25);
}
// n° page en haute à droite
if($nb_page>1){
$pdf->SetXY( 120, 5 ); $pdf->SetFont( "ComicSans", "B", 9 ); $pdf->Cell( 160, 8, $num_page . '/' . $nb_page, 0, 0, 'C');
}
// date facture
$pdf->SetFont('ComicSans','',11);
$pdf->SetY(10);
$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");
$pdf->SetXY( 114, 20 ); $pdf->SetFont( "ComicSans", "B", 12 ); $pdf->Cell( 85, 8, 'FACTURE N'.utf8_decode('°').' FAC/'.$key_annee.'/'.strtoupper(FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])), 0, 0, 'C');
// adresse du facture
$pdf->SetFont('ComicSans','B',11);
$pdf->SetY(y: 32);
$pdf->Cell( 0, 6, utf8_decode($current_client), 0, 1, 'R');
$pdf->Cell( 0, 6, trim(utf8_decode(html_entity_decode($clientAddress))), 0, 1, 'R');
if($clientCity != ''){
$pdf->Cell( 0, 6, trim(utf8_decode(html_entity_decode($clientCity))), 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');
// ***********************
// le cadre des articles
// ***********************
// cadre avec 18 lignes max ! et 118 de hauteur --> 80 + 118 = 198 pour les traits verticaux
$pdf->SetLineWidth(0.1); $pdf->Rect(5, 80, 200, 153, "D");
// 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);
if($num_page == $nb_page) $pdf->Line(183, 80, 183, 240);
else $pdf->Line(183, 80, 183, 233);
// titre colonne
$pdf->SetXY( 1, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 140, 8, "OBJET", 0, 0, 'C');
$pdf->SetXY( 147, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 13, 8, "H.T.", 0, 0, 'C');
$pdf->SetXY( 168, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 10, 8, "TVA 20%", 0, 0, 'C');
$pdf->SetXY( 183, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 22, 8, "T.T.C", 0, 0, 'C');
// (new DateTime($facture['date_soin']))->format('d-M')
$formatter_ds = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
// Set the pattern for the formatter to "d-MMMM" to display the day and month name in French
$formatter_ds->setPattern('dd-MMM');
//recuperation des factures
$y_facture = 90;
$init_index = $index_facture_position;
for ($index_facture_position; $index_facture_position < ($init_index + $max_nb_toget) ; $index_facture_position++) {
$date_soin_temp = new DateTime($client[$index_facture_position]['date_soin']);
$pdf->SetXY( 6, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 28, 8, $client[$index_facture_position]['num'], 0, 0, '');
$pdf->SetXY( 32, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 18, 8, utf8_decode($formatter_ds->format($date_soin_temp)), 0, 0, '');
$pdf->SetXY( 50, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 38, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['defunt'])), 0, 0, '');
$pdf->SetXY( 90, $y_facture ); $pdf->SetFont('ComicSans','',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('ComicSans','',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('ComicSans','',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('ComicSans','',8); $pdf->Cell( 22, 8, number_format($client[$index_facture_position]['montant_ttc'],2,'.','').chr(128), 0, 0, 'C');
$montant_ht_total = $montant_ht_total+$client[$index_facture_position]['montant_htc'];
$montant_tva_total = $montant_tva_total+$client[$index_facture_position]['montant_tva'];
$montant_ttc_total = $montant_ttc_total+$client[$index_facture_position]['montant_ttc'];
$y_facture=$y_facture+5;
}
$nb_facture_chargee = $index_facture_position+1;
$reste_a_chargee = sizeof($client) - $nb_facture_chargee;
$max_nb_toget = ($reste_a_chargee <= 26) ? $reste_a_chargee+1 : 26;
// si derniere page alors afficher cadre des TVA
if ($num_page == $nb_page)
{
$pdf->Line(5, 225, 205, 225);
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 5, 225 ); $pdf->Cell( 140, 8, 'TOTAL', 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 147, 225 ); $pdf->Cell( 13, 8, number_format($montant_ht_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 168, 225 ); $pdf->Cell( 10, 8, number_format($montant_tva_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 183, 225 ); $pdf->Cell( 22, 8, number_format($montant_ttc_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->Rect(145, 233, 60, 7, "D");
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 147, 233 ); $pdf->Cell( 30, 6.5, 'TOTAL TTC', 0, 0, 'C');
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 183, 233 ); $pdf->Cell( 22, 6.5, number_format($montant_ttc_total,2,'.','').chr(128), 0, 0, 'C', true);
}
$y1 = 245;
$pdf->SetFillColor(255);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont('ComicSans','',9);
$pdf->SetXY( 10, $y1 );$pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Loi N° 92-442 du 31 décembre 1992: La présente facture est payable en comptant a réception."), 0, 0, 'L');
$pdf->SetXY( 10, $y1 + 4 );$pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Indemnité forfaitaire pour frais de recouvrement due en cas de retard de paiement: 40").chr(128), 0, 0, 'L');
$pdf->SetXY( 10, $y1 + 8 );$pdf->Multicell( $pdf->GetPageWidth()-20, 4, utf8_decode("Toute somme non payée dans les trente jours est susceptible de porter intérets à un taux égal à une fois et demi le taux de l'intéret légal."), 0, 0, 'L');
// **************************
// pied de page
// **************************
$pdf->SetFont('ComicSans','',7);
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->mentions_default)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 8 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->legal_one)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 12 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->legal_two)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 16 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($defaultConfig[0]->telephone)), 0, 0, 'C');
/*$pdf->SetXY( 1, $y0 + 16 );
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
$num_page++;
}
$fullPdfPath = html_entity_decode($defaultConfig[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper(FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])).'/'.strtoupper(FileExportHelpers::ConvertSpecialChar($current_client)).'_RECAP_FACTURE_'.strtoupper(FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])).'_'.$key_annee.'.pdf';
$storage->newFile($fullPdfPath);
$pdfContent = $pdf->Output('','S');
$file_pdf = $storage->get($fullPdfPath);
$file_pdf->putContent($pdfContent);
}
}
}
}
public function generateInvoiceRecap($filter,$filterType,$date,$idNextcloud){
try {
if($filterType == MultipleFactureTypeConstant::GROUP_FILTER_TYPE){
$this->generateInvoiceRecapPerClientGroupFacturation($filter,$date,$idNextcloud);
}
else{
$this->generateInvoiceRecapPerClient($filter,$date,$idNextcloud);
}
} catch(\OCP\Files\NotFoundException $e) { }
}
}

View File

@ -0,0 +1,371 @@
<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Gestion\Service\InvoiceRecap\PdfHandler;
use DateTime;
use \FPDF;
use IntlDateFormatter;
use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Helpers\PriceHelpers;
class InvoiceRecapPdfHandler extends FPDF {
private $invoices = [];
private $logo = null;
private $logoPath = "/var/www/html/data/admin/files/.gestion/";
private $configs = [];
private $signatureImageExist = false;
// function Header()
// {
// if($this->logo != "nothing"){
// $this->Image($this->logoPath."logo.png", 10, 10, 75, 25);
// }
// else{
// $this->Cell(55,30,'');
// }
// }
// function Footer()
// {
// $this->SetY(-40);
// $this->SetFont('ComicSans', '', 7);
// $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->SetY(-15);
// $this->SetFont('ComicSans', 'B', 8);
// $this->Cell(0, 10, utf8_decode(html_entity_decode($this->devisData['configuration']->legal_one)), 0, 0, 'C');
// }
public function SetInvoiceRecapFacture(array $invoices,array $configs,$logo = null,$signatureImageExist = false){
$this->invoices = $invoices;
$this->logo = $logo;
$this->signatureImageExist = $signatureImageExist;
$this->configs = $configs;
}
public function SetInvoiceRecap(){
$data_temp = $this->invoices;
$isLogoExist = $this->logo != null;
foreach ($data_temp as $key_annee => $annee) {
foreach ($annee as $key_mois => $mois) {
foreach ($mois as $key_client => $client) {
$pdf = new FPDF();
$pdf->AddFont('ComicSans','','Comic Sans MS.php');
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
$current_client = '';
$clientAddress = '';
$clientCity = '';
$date_facture;
$j=1;
foreach ($client as $key => $facture) {
if($j==1) {
$current_client = $facture['prenoms_client'].' '.$facture['nom_client'];
$date_facture = $facture['date_facture'];
$clientAddresses = FileExportHelpers::GetAddressAndCityFromAddress($facture['adresse_client']);
$clientAddress = $clientAddresses['address'];
$clientCity = $clientAddresses['city'];
}
$j++;
}
$date_temp = date("t-m-Y", strtotime($date_facture));
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
$date_formated = $formatter->format(DateTime::createFromFormat('d-m-Y', $date_temp));
$pdf->AddPage();
// on sup les 2 cm en bas
$pdf->SetAutoPagebreak(False);
$pdf->SetMargins(0,0,10);
// logo : 80 de largeur et 55 de hauteur
if($isLogoExist){
$pdf->Image($this->logoPath."logo.png", 10, 10, 75, 25);
}
// adresse du facture
$pdf->SetFont('ComicSans','B',size: 11);
$pdf->SetY(40);
$pdf->Cell( 0, 8, utf8_decode($current_client), 0, 1, 'R');
$pdf->Cell( 0, 8, trim(utf8_decode(html_entity_decode($clientAddress))), 0,1,'R');
if($clientCity != ''){
$pdf->Cell( 0, 8, trim(utf8_decode(html_entity_decode($clientCity))), 0, 1, 'R');
}
// date facture
$pdf->SetFont('ComicSans','',11);
$pdf->Cell( 0, 8, "Saint Senoux, le ".utf8_decode($date_formated), 0, 1, 'R');
// observations
$pdf->SetFont( "ComicSans", "BU", 10 ); $pdf->SetXY( 10, 85 ) ; $pdf->Cell($pdf->GetStringWidth("Objet:"), 0, "Objet:", 0, "L");
$objet = utf8_decode("Récapitulatif Facturation du mois de ").strtoupper($this->convert_special_char(explode(' ', $date_formated)[1]));
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 85 ) ; $pdf->Cell($pdf->GetStringWidth($objet), 0, $objet, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 95 ); $pdf->Cell($pdf->GetStringWidth("Madame, Monsieur"), 0, "Madame, Monsieur", 0, "L");
$text1 = utf8_decode("Veuillez trouver ci-dessous le récapitulatif de la facturation du mois de ").strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).".";
$text2 = utf8_decode("Vous en souhaitant bonne réception.");
$text3 = utf8_decode("Veuillez agréer, Madame, Monsieur, mes salutations les meilleures.");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 105 ) ; $pdf->Cell($pdf->GetStringWidth($text1), 0, $text1, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 110 ) ; $pdf->Cell($pdf->GetStringWidth($text2), 0, $text2, 0, "L");
$pdf->SetFont( "ComicSans", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 120 ) ; $pdf->Cell($pdf->GetStringWidth($text3), 0, $text3, 0, "L");
// signature
$pdf->SetFont('ComicSans','',11); $pdf->SetXY( 145, 145 );
$pdf->Cell( $pdf->GetStringWidth($this->configs[0]->nom.' '.$this->configs[0]->prenom), 0, utf8_decode(html_entity_decode($this->configs[0]->nom.' '.$this->configs[0]->prenom)), 0, 0, 'L');
if($this->signatureImageExist){
$pdf->Image($this->logoPath."sign.png", 135, 150, 55, 30);
}
$y0 = 260;
$pageWidth = $pdf->GetPageWidth();
//Positionnement en bas et tout centrer
$pdf->SetFont('ComicSans','',7);
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($this->configs[0]->mentions_default)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 8 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($this->configs[0]->legal_one)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 12 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($this->configs[0]->legal_two)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 16 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($this->configs[0]->telephone)), 0, 0, 'C');
/*$pdf->SetXY( 1, $y0 + 16 );
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
$num_page = 1;
$nb_page = ceil(sizeof($client) / 26);
$index_facture_position = 0;
$max_nb_toget = (sizeof($client)<=26)?sizeof($client):26;
$montant_ht_total = 0;
$montant_tva_total = 0;
$montant_ttc_total = 0;
while ($num_page <= $nb_page) {
$pdf->AddPage();
// on sup les 2 cm en bas
$pdf->SetAutoPagebreak(False);
$pdf->SetMargins(0,0,10);
if($isLogoExist){
$pdf->Image($this->logoPath."logo.png", 10, 10, 75, 25);
}
// n° page en haute à droite
if($nb_page>1){
$pdf->SetXY( 120, 5 ); $pdf->SetFont( "ComicSans", "B", 9 ); $pdf->Cell( 160, 8, $num_page . '/' . $nb_page, 0, 0, 'C');
}
// date facture
$pdf->SetFont('ComicSans','',11);
$pdf->SetY(10);
$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");
$pdf->SetXY( 114, 20 ); $pdf->SetFont( "ComicSans", "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('ComicSans','B',11);
$pdf->SetY(y: 32);
$pdf->Cell( 0, 6, utf8_decode($current_client), 0, 1, 'R');
$pdf->Cell( 0, 6, trim(utf8_decode(html_entity_decode($clientAddress))), 0, 1, 'R');
if($clientCity != ''){
$pdf->Cell( 0, 6, trim(utf8_decode(html_entity_decode($clientCity))), 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');
// ***********************
// le cadre des articles
// ***********************
// cadre avec 18 lignes max ! et 118 de hauteur --> 80 + 118 = 198 pour les traits verticaux
$pdf->SetLineWidth(0.1); $pdf->Rect(5, 80, 200, 153, "D");
// 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);
if($num_page == $nb_page) $pdf->Line(183, 80, 183, 240);
else $pdf->Line(183, 80, 183, 233);
// titre colonne
$pdf->SetXY( 1, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 140, 8, "OBJET", 0, 0, 'C');
$pdf->SetXY( 147, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 13, 8, "H.T.", 0, 0, 'C');
$pdf->SetXY( 168, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 10, 8, "TVA 20%", 0, 0, 'C');
$pdf->SetXY( 183, 81 ); $pdf->SetFont('ComicSans','B',8); $pdf->Cell( 22, 8, "T.T.C", 0, 0, 'C');
// (new DateTime($facture['date_soin']))->format('d-M')
$formatter_ds = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
// Set the pattern for the formatter to "d-MMMM" to display the day and month name in French
$formatter_ds->setPattern('dd-MMM');
//recuperation des factures
$y_facture = 90;
$init_index = $index_facture_position;
for ($index_facture_position; $index_facture_position < ($init_index + $max_nb_toget) ; $index_facture_position++) {
$date_soin_temp = new DateTime($client[$index_facture_position]['date_soin']);
$pdf->SetXY( 6, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 28, 8, $client[$index_facture_position]['num'], 0, 0, '');
$pdf->SetXY( 32, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 18, 8, utf8_decode($formatter_ds->format($date_soin_temp)), 0, 0, '');
$pdf->SetXY( 50, $y_facture ); $pdf->SetFont('ComicSans','',8); $pdf->Cell( 38, 8, utf8_decode(html_entity_decode($client[$index_facture_position]['defunt'])), 0, 0, '');
$pdf->SetXY( 90, $y_facture ); $pdf->SetFont('ComicSans','',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('ComicSans','',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('ComicSans','',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('ComicSans','',8); $pdf->Cell( 22, 8, number_format($client[$index_facture_position]['montant_ttc'],2,'.','').chr(128), 0, 0, 'C');
$montant_ht_total = $montant_ht_total+$client[$index_facture_position]['montant_htc'];
$montant_tva_total = $montant_tva_total+$client[$index_facture_position]['montant_tva'];
$montant_ttc_total = $montant_ttc_total+$client[$index_facture_position]['montant_ttc'];
$y_facture=$y_facture+5;
}
$nb_facture_chargee = $index_facture_position+1;
$reste_a_chargee = sizeof($client) - $nb_facture_chargee;
$max_nb_toget = ($reste_a_chargee <= 26) ? $reste_a_chargee+1 : 26;
// si derniere page alors afficher cadre des TVA
if ($num_page == $nb_page)
{
$pdf->Line(5, 225, 205, 225);
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 5, 225 ); $pdf->Cell( 140, 8, 'TOTAL', 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 147, 225 ); $pdf->Cell( 13, 8, number_format($montant_ht_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 168, 225 ); $pdf->Cell( 10, 8, number_format($montant_tva_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->SetFont('ComicSans','',8); $pdf->SetXY( 183, 225 ); $pdf->Cell( 22, 8, number_format($montant_ttc_total,2,'.','').chr(128), 0, 0, 'C');
$pdf->Rect(145, 233, 60, 7, "D");
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 147, 233 ); $pdf->Cell( 30, 6.5, 'TOTAL TTC', 0, 0, 'C');
$pdf->SetFont('ComicSans','B',8); $pdf->SetXY( 183, 233 ); $pdf->Cell( 22, 6.5, number_format($montant_ttc_total,2,'.','').chr(128), 0, 0, 'C', true);
}
$y1 = 245;
$pdf->SetFillColor(255);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont('ComicSans','',9);
$pdf->SetXY( 10, $y1 );$pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Loi N° 92-442 du 31 décembre 1992: La présente facture est payable en comptant a réception."), 0, 0, 'L');
$pdf->SetXY( 10, $y1 + 4 );$pdf->Cell( $pdf->GetPageWidth(), 4, utf8_decode("Indemnité forfaitaire pour frais de recouvrement due en cas de retard de paiement: 40").chr(128), 0, 0, 'L');
$pdf->SetXY( 10, $y1 + 8 );$pdf->Multicell( $pdf->GetPageWidth()-20, 4, utf8_decode("Toute somme non payée dans les trente jours est susceptible de porter intérets à un taux égal à une fois et demi le taux de l'intéret légal."), 0, 0, 'L');
// **************************
// pied de page
// **************************
$pdf->SetFont('ComicSans','',7);
$pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($this->configs[0]->mentions_default)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 8 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($this->configs[0]->legal_one)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 12 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($this->configs[0]->legal_two)), 0, 0, 'C');
$pdf->SetXY( 1, $y0 + 16 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($this->configs[0]->telephone)), 0, 0, 'C');
/*$pdf->SetXY( 1, $y0 + 16 );
$pdf->Cell( $pageWidth, 5, utf8_decode("SIREN 751621293"), 0, 0, 'C');*/
$num_page++;
}
$ff_pdf = html_entity_decode($this->configs[0]->path).'/DOCUMENTS RECAPITULATIFS/'.$key_annee.'/'.$key_mois.' '.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'/'.strtoupper($this->convert_special_char($current_client)).'_RECAP_FACTURE_'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])).'_'.$key_annee.'.pdf';
$this->storage->newFile($ff_pdf);
$pdfContent = $pdf->Output('','S');
$file_pdf = $this->storage->get($ff_pdf);
$file_pdf->putContent($pdfContent);
}
}
}
}
function MultiAlignCell($w,$h,$text,$border=0,$ln=0,$align='L',$fill=false)
{
// Store reset values for (x,y) positions
$x = $this->GetX() + $w;
$y = $this->GetY();
// Make a call to FPDF's MultiCell
$this->MultiCell($w,$h,$text,$border,$align,$fill);
// Reset the line position to the right, like in Cell
if( $ln==0 )
{
$this->SetXY($x,$y);
}
}
function NbLines($w, $txt)
{
// Compute the number of lines a MultiCell of width w will take
if(!isset($this->CurrentFont))
$this->Error('No font has been set');
$cw = $this->CurrentFont['cw'];
if($w==0)
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
$s = str_replace("\r",'',(string)$txt);
$nb = strlen($s);
if($nb>0 && $s[$nb-1]=="\n")
$nb--;
$sep = -1;
$i = 0;
$j = 0;
$l = 0;
$nl = 1;
while($i<$nb)
{
$c = $s[$i];
if($c=="\n")
{
$i++;
$sep = -1;
$j = $i;
$l = 0;
$nl++;
continue;
}
if($c==' ')
$sep = $i;
$l += $cw[$c];
if($l>$wmax)
{
if($sep==-1)
{
if($i==$j)
$i++;
}
else
$i = $sep+1;
$sep = -1;
$j = $i;
$l = 0;
$nl++;
}
else
$i++;
}
return $nl;
}
}

View File

@ -25,9 +25,9 @@
<tr>
<th><?php p($l->t('A exporter'));?></th>
<th><?php p($l->t('ID'));?></th>
<th><?php p($l->t('Code comptable'));?></th>
<th><?php p($l->t('Agence'));?></th>
<th><?php p($l->t('Company'));?></th>
<th><?php p($l->t('First name'));?></th>
<th><?php p($l->t('Last name'));?></th>
<th><?php p($l->t('Legal information'));?></th>
<th><?php p($l->t('Phone number'));?></th>
<th><?php p($l->t('Email'));?></th>