Merge branch 'features/feature-save-multiple-invoice-at-once' into staging
This commit is contained in:
commit
508d13f630
@ -67,6 +67,7 @@ return [
|
|||||||
['name' => 'page#insertFacture', 'url' => '/facture/insert', 'verb' => 'POST'],
|
['name' => 'page#insertFacture', 'url' => '/facture/insert', 'verb' => 'POST'],
|
||||||
['name' => 'page#exportDevisToFacture', 'url' => '/exportDevisToFacture', 'verb' => 'POST'],
|
['name' => 'page#exportDevisToFacture', 'url' => '/exportDevisToFacture', 'verb' => 'POST'],
|
||||||
['name' => 'page#exportFactureToPdf', 'url' => '/facture/exportFactureToPdf', 'verb' => 'POST'],
|
['name' => 'page#exportFactureToPdf', 'url' => '/facture/exportFactureToPdf', 'verb' => 'POST'],
|
||||||
|
['name' => 'page#exportFactureByClientAndMonthYearToPdf', 'url' => '/facture/exportFactureByClientAndMonthYearToPdf', 'verb' => 'POST'],
|
||||||
|
|
||||||
['name' => 'page#getProduits', 'url' => '/getProduits', 'verb' => 'PROPFIND'],
|
['name' => 'page#getProduits', 'url' => '/getProduits', 'verb' => 'PROPFIND'],
|
||||||
['name' => 'page#getProduitsById', 'url' => '/getProduitsById', 'verb' => 'POST'],
|
['name' => 'page#getProduitsById', 'url' => '/getProduitsById', 'verb' => 'POST'],
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -2777,6 +2777,24 @@ class PageController extends Controller {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @NoCSRFRequired
|
||||||
|
* @param string $clientId
|
||||||
|
* @param string $month
|
||||||
|
* @param string $year
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function exportFactureByClientAndMonthYearToPdf($clientId,$month,$year){
|
||||||
|
try{
|
||||||
|
$factureFilename = $this->invoicePdfService->generateMultipleInvoicePdfByClientAndMonthYear($clientId,$month,$year,$this->idNextcloud);
|
||||||
|
return $factureFilename;
|
||||||
|
}
|
||||||
|
catch(\OCP\Files\NotFoundException $e) { }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
|
|||||||
@ -2302,6 +2302,68 @@ class Bdd {
|
|||||||
return $factureData;
|
return $factureData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getInvoicePdfDataByClientAndMonthYear($clientId,$month,$year,$configuration){
|
||||||
|
$invoices = $this->getInvoiceByClientAndMonthYear($clientId,$month,$year);
|
||||||
|
$firstClient = $this->getFirstClient();
|
||||||
|
foreach($invoices as &$invoice){
|
||||||
|
$invoice["siret"] = $firstClient != null ? $firstClient['legal_one'] : '';
|
||||||
|
$products = $this->getDevisProduits($invoice["devis_id"]);
|
||||||
|
$invoice["products"] = $products;
|
||||||
|
$invoice["configuration"] = $configuration;
|
||||||
|
|
||||||
|
$clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($invoice["client_adresse"]);
|
||||||
|
$invoice["client_real_adress"] = $clientAdresses["address"];
|
||||||
|
$invoice["client_adress_city"] = $clientAdresses["city"];
|
||||||
|
|
||||||
|
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse);
|
||||||
|
$invoice["configuration_adresse"] = $configurationAdresses["address"];
|
||||||
|
$invoice["configuration_adresse_city"] = $configurationAdresses["city"];
|
||||||
|
}
|
||||||
|
return $invoices;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getInvoiceByClientAndMonthYear($clientId,$month,$year){
|
||||||
|
$sql = "SELECT
|
||||||
|
facture.id,
|
||||||
|
facture.date,
|
||||||
|
facture.date_paiement,
|
||||||
|
facture.num,
|
||||||
|
devis.id as devis_id,
|
||||||
|
devis.date as devis_date,
|
||||||
|
devis.num as calendar_uuid,
|
||||||
|
devis.comment as devis_comment,
|
||||||
|
devis.id_client as devis_id_client,
|
||||||
|
client.nom as client_nom,
|
||||||
|
client.entreprise as client_entreprise,
|
||||||
|
client.adresse as client_adresse,
|
||||||
|
defunt.nom as defunt_nom,
|
||||||
|
defunt.sexe as defunt_sexe,
|
||||||
|
lieu.nom as lieu_nom,
|
||||||
|
lieu.adresse as lieu_adresse,
|
||||||
|
thanato.nom as thanato_nom,
|
||||||
|
thanato.prenom as thanato_prenom
|
||||||
|
FROM ".$this->tableprefix."facture as facture
|
||||||
|
LEFT JOIN ".$this->tableprefix."devis as devis on facture.id_devis = devis.id
|
||||||
|
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
||||||
|
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
||||||
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
||||||
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
||||||
|
WHERE devis.id_client = ? AND
|
||||||
|
YEAR(facture.date_paiement) = ?";
|
||||||
|
|
||||||
|
$conditions = [$clientId,$year];
|
||||||
|
if($month != 0){
|
||||||
|
$conditions[] = $month;
|
||||||
|
$sql .= " AND MONTH(facture.date_paiement) = ?";
|
||||||
|
}
|
||||||
|
$sql .= ";";
|
||||||
|
$factures = $this->execSQLNoJsonReturn(
|
||||||
|
$sql,
|
||||||
|
$conditions);
|
||||||
|
|
||||||
|
return $factures;
|
||||||
|
}
|
||||||
|
|
||||||
private function getFactureByIdWithDevis($factureId){
|
private function getFactureByIdWithDevis($factureId){
|
||||||
$sql = "SELECT
|
$sql = "SELECT
|
||||||
facture.id,
|
facture.id,
|
||||||
|
|||||||
@ -5,6 +5,7 @@ namespace OCA\Gestion\Helpers;
|
|||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use IntlDateFormatter;
|
||||||
|
|
||||||
class DateHelpers
|
class DateHelpers
|
||||||
{
|
{
|
||||||
@ -20,6 +21,23 @@ class DateHelpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function GetMonthPlainString($month){
|
||||||
|
$formatter = new IntlDateFormatter(
|
||||||
|
'fr_FR',
|
||||||
|
IntlDateFormatter::FULL,
|
||||||
|
IntlDateFormatter::NONE,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
'MMMM'
|
||||||
|
);
|
||||||
|
|
||||||
|
$date = DateTime::createFromFormat('!m', $month);
|
||||||
|
$monthString = strtoupper($formatter->format($date));
|
||||||
|
$normalizedMonth = mb_convert_case($monthString, MB_CASE_UPPER, "UTF-8");
|
||||||
|
|
||||||
|
return $normalizedMonth;
|
||||||
|
}
|
||||||
|
|
||||||
public static function GetDateWithFormatDayAndMonthPlainString(string $date){
|
public static function GetDateWithFormatDayAndMonthPlainString(string $date){
|
||||||
$dateTime = new DateTime($date);
|
$dateTime = new DateTime($date);
|
||||||
$formattedDate = $dateTime->format('d F');
|
$formattedDate = $dateTime->format('d F');
|
||||||
|
|||||||
@ -28,11 +28,13 @@ namespace OCA\Gestion\Service;
|
|||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use \FPDF;
|
use \FPDF;
|
||||||
|
use OCA\Gestion\Helpers\DateHelpers;
|
||||||
use OCA\Gestion\Helpers\FileExportHelpers;
|
use OCA\Gestion\Helpers\FileExportHelpers;
|
||||||
use OCA\Gestion\Helpers\PriceHelpers;
|
use OCA\Gestion\Helpers\PriceHelpers;
|
||||||
|
|
||||||
class InvoicePdfHandler extends FPDF {
|
class InvoicePdfHandler extends FPDF {
|
||||||
|
|
||||||
|
private $multipleFactureData = [];
|
||||||
private $factureData = [];
|
private $factureData = [];
|
||||||
private $logo = null;
|
private $logo = null;
|
||||||
private $logoPath = "/var/www/html/data/admin/files/.gestion/";
|
private $logoPath = "/var/www/html/data/admin/files/.gestion/";
|
||||||
@ -44,7 +46,6 @@ class InvoicePdfHandler extends FPDF {
|
|||||||
else{
|
else{
|
||||||
$this->Cell(55,30,'');
|
$this->Cell(55,30,'');
|
||||||
}
|
}
|
||||||
$this->Ln(30);
|
|
||||||
}
|
}
|
||||||
function Footer()
|
function Footer()
|
||||||
{
|
{
|
||||||
@ -65,7 +66,23 @@ class InvoicePdfHandler extends FPDF {
|
|||||||
$this->logo = $logo;
|
$this->logo = $logo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetFilename(){
|
public function MutlipleInvoicePdfFactory(array $multipleInvoiceData,$logo = null){
|
||||||
|
$this->multipleFactureData = $multipleInvoiceData;
|
||||||
|
$this->logo = $logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetMultipleInvoiceFilename($month,$year){
|
||||||
|
$filename = "";
|
||||||
|
foreach($this->multipleFactureData as $factureData){
|
||||||
|
$filename = strtoupper($factureData["client_entreprise"]);
|
||||||
|
$filename .= $month != 0 ? '_'.DateHelpers::GetMonthPlainString($month) :'';
|
||||||
|
$filename .= "_".$year;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetInvoiceFilename(){
|
||||||
$factureNum = $this->factureData['num'];
|
$factureNum = $this->factureData['num'];
|
||||||
$factureNum = str_replace('/','-',$factureNum);
|
$factureNum = str_replace('/','-',$factureNum);
|
||||||
$defuntNom = str_replace(' ',' ',$this->factureData['defunt_nom']);
|
$defuntNom = str_replace(' ',' ',$this->factureData['defunt_nom']);
|
||||||
@ -73,6 +90,7 @@ class InvoicePdfHandler extends FPDF {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function DrawInvoiceCompanyAndClientInfo(){
|
private function DrawInvoiceCompanyAndClientInfo(){
|
||||||
|
$this->SetY(40);
|
||||||
$this->SetFont('Arial', '', 12);
|
$this->SetFont('Arial', '', 12);
|
||||||
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['configuration']->entreprise), 0, 0);
|
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['configuration']->entreprise), 0, 0);
|
||||||
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['client_nom']), 0, 1,'R');
|
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['client_nom']), 0, 1,'R');
|
||||||
@ -92,8 +110,8 @@ class InvoicePdfHandler extends FPDF {
|
|||||||
$factureDatePaiement = DateTime::createFromFormat('Y-m-d',$factureDatePaiement);
|
$factureDatePaiement = DateTime::createFromFormat('Y-m-d',$factureDatePaiement);
|
||||||
$factureDateEcheance = $factureDatePaiement;
|
$factureDateEcheance = $factureDatePaiement;
|
||||||
$factureDatePaiement = $factureDatePaiement->format('d-m-Y');
|
$factureDatePaiement = $factureDatePaiement->format('d-m-Y');
|
||||||
$factureDateEcheance->modify('+1 month');
|
$factureDateEcheance->modify('last day of next month');
|
||||||
$factureDateEcheance = $factureDateEcheance->format('t-m-Y');
|
$factureDateEcheance = $factureDateEcheance->format('d-m-Y');
|
||||||
$this->SetFont('Arial', 'B', 11);
|
$this->SetFont('Arial', 'B', 11);
|
||||||
$this->Cell(30, 7, 'DATE', 1, 0, 'C');
|
$this->Cell(30, 7, 'DATE', 1, 0, 'C');
|
||||||
$this->Cell(80, 7, 'CLIENT', 1, 0, 'C');
|
$this->Cell(80, 7, 'CLIENT', 1, 0, 'C');
|
||||||
@ -218,7 +236,14 @@ class InvoicePdfHandler extends FPDF {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetFactureContent(){
|
public function SetMultipleFactureContent(){
|
||||||
|
foreach($this->multipleFactureData as $factureData){
|
||||||
|
$this->factureData = $factureData;
|
||||||
|
$this->SetFactureContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function SetFactureContent(){
|
||||||
$this->AddPage();
|
$this->AddPage();
|
||||||
$this->SetMargins(10,0,10);
|
$this->SetMargins(10,0,10);
|
||||||
$this->DrawInvoiceCompanyAndClientInfo();
|
$this->DrawInvoiceCompanyAndClientInfo();
|
||||||
@ -227,8 +252,6 @@ class InvoicePdfHandler extends FPDF {
|
|||||||
$this->DrawArticlesTableHeader();
|
$this->DrawArticlesTableHeader();
|
||||||
$totalPriceValue = $this->DrawArticlesTableValueAndReturnTotalPrice();
|
$totalPriceValue = $this->DrawArticlesTableValueAndReturnTotalPrice();
|
||||||
$this->DrawBankAndTotalPriceInfo($totalPriceValue);
|
$this->DrawBankAndTotalPriceInfo($totalPriceValue);
|
||||||
$pdfContent = $this->Output('','S');
|
|
||||||
return $pdfContent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function MultiAlignCell($w,$h,$text,$border=0,$ln=0,$align='L',$fill=false)
|
function MultiAlignCell($w,$h,$text,$border=0,$ln=0,$align='L',$fill=false)
|
||||||
|
|||||||
@ -75,12 +75,13 @@ class InvoicePdfService {
|
|||||||
if($invoicePdfData == null){
|
if($invoicePdfData == null){
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
$clean_folder = html_entity_decode($currentConfig->path).'/';
|
$clean_folder = html_entity_decode(string: $currentConfig->path).'/';
|
||||||
$factureFolders = $this->getFacturesFolder($invoicePdfData,$clean_folder);
|
$factureFolders = $this->getFacturesFolder($invoicePdfData,$clean_folder);
|
||||||
$pdf = new InvoicePdfHandler();
|
$pdf = new InvoicePdfHandler();
|
||||||
$pdf->InvoicePdfFactory($invoicePdfData,$logo);
|
$pdf->InvoicePdfFactory($invoicePdfData,$logo);
|
||||||
$pdfContent = $pdf->GetFactureContent();
|
$pdf->SetFactureContent();
|
||||||
$pdfFilename = $pdf->GetFilename();
|
$pdfContent = $pdf->Output('','S');
|
||||||
|
$pdfFilename = $pdf->GetInvoiceFilename();
|
||||||
$filenames = [];
|
$filenames = [];
|
||||||
foreach($factureFolders as $folder){
|
foreach($factureFolders as $folder){
|
||||||
try {
|
try {
|
||||||
@ -116,4 +117,32 @@ class InvoicePdfService {
|
|||||||
$this->generateFacturePdfByFactureId($factureId,$idNextCloud);
|
$this->generateFacturePdfByFactureId($factureId,$idNextCloud);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function generateMultipleInvoicePdfByClientAndMonthYear($clientId,$month,$year,$idNextCloud){
|
||||||
|
$storage = $this->rootFolder->getUserFolder($idNextCloud);
|
||||||
|
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
|
||||||
|
$currentConfig = $configs[0];
|
||||||
|
$logo = $this->getLogo();
|
||||||
|
$invoiceData = $this->gestionBdd->getInvoicePdfDataByClientAndMonthYear($clientId,$month,$year,$currentConfig);
|
||||||
|
if(empty($invoiceData)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$pdf = new InvoicePdfHandler();
|
||||||
|
$pdf->MutlipleInvoicePdfFactory($invoiceData,$logo);
|
||||||
|
$pdf->SetMultipleFactureContent();
|
||||||
|
$racinePath = html_entity_decode(string: $currentConfig->path).'/';
|
||||||
|
$clientRacineFolder = $racinePath.'CLIENTS/'.strtoupper($invoiceData[0]["client_entreprise"]).'/';
|
||||||
|
$filename = $currentConfig->facture_prefixe.'_'.$pdf->GetMultipleInvoiceFilename($month,$year);
|
||||||
|
$filenamePath = $clientRacineFolder.$filename.'.pdf';
|
||||||
|
$pdfContent = $pdf->Output('','S');
|
||||||
|
try {
|
||||||
|
$storage->newFolder($clientRacineFolder);
|
||||||
|
}
|
||||||
|
catch(\OCP\Files\NotPermittedException $e) {
|
||||||
|
}
|
||||||
|
$storage->newFile($filenamePath);
|
||||||
|
$file_pdf = $storage->get($filenamePath);
|
||||||
|
$file_pdf->putContent($pdfContent);
|
||||||
|
return $filenamePath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,22 +4,23 @@ import "../css/mycss.css";
|
|||||||
|
|
||||||
import { globalConfiguration } from "./modules/mainFunction.mjs";
|
import { globalConfiguration } from "./modules/mainFunction.mjs";
|
||||||
import "./listener/main_listener";
|
import "./listener/main_listener";
|
||||||
|
import "./listener/invoiceListener";
|
||||||
import { getPDF } from "./pdf";
|
import { getPDF } from "./pdf";
|
||||||
import { saveDocumentRecap } from "./modules/ajaxRequest.mjs";
|
import { saveDocumentRecap } from "./modules/ajaxRequest.mjs";
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", function () {
|
window.addEventListener("DOMContentLoaded", function () {
|
||||||
globalConfiguration();
|
globalConfiguration();
|
||||||
|
|
||||||
var pdf = document.getElementById("pdfFactures");
|
// var pdf = document.getElementById("pdfFactures");
|
||||||
pdf.addEventListener("click",async ()=>{
|
// pdf.addEventListener("click",async ()=>{
|
||||||
getPDF('facture');
|
// getPDF('facture');
|
||||||
});
|
// });
|
||||||
|
|
||||||
var documentRecap = document.getElementById("documentrecap");
|
var documentRecap = document.getElementById("documentrecap");
|
||||||
documentRecap.addEventListener("click", async ()=> {
|
documentRecap.addEventListener("click", async ()=> {
|
||||||
// Get the URL parameters
|
// Get the URL parameters
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
// Access specific parameter values
|
// Access specific parameter values
|
||||||
const idclient = urlParams.get('cli');
|
const idclient = urlParams.get('cli');
|
||||||
const annee = urlParams.get('annee');
|
const annee = urlParams.get('annee');
|
||||||
|
|||||||
32
gestion/src/js/listener/invoiceListener.js
Normal file
32
gestion/src/js/listener/invoiceListener.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import {showError, showSuccess } from "@nextcloud/dialogs";
|
||||||
|
import {baseUrl} from "../modules/mainFunction.mjs";
|
||||||
|
|
||||||
|
$('body').on('click', '#exportMultipleFactureToPdf', function () {
|
||||||
|
// Access specific parameter values
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const clientId = urlParams.get('cli');
|
||||||
|
const year = urlParams.get('annee');
|
||||||
|
const month = urlParams.get('mois');
|
||||||
|
var exportMultipleFacturePayload = {
|
||||||
|
clientId : clientId,
|
||||||
|
month : month,
|
||||||
|
year : year
|
||||||
|
};
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: baseUrl + '/facture/exportFactureByClientAndMonthYearToPdf',
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify(exportMultipleFacturePayload)
|
||||||
|
}).done(function (response) {
|
||||||
|
var fileName = response;
|
||||||
|
if(fileName != null){
|
||||||
|
showSuccess('Sauvegardé dans' + fileName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
showError(t('gestion', "Les données pour sauvegarde sont vides"));
|
||||||
|
}).fail(function (response, code) {
|
||||||
|
showError(t('gestion', "Erreur dans la génération de facture multiple"));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
@ -58,7 +58,7 @@
|
|||||||
if(sizeof($factures)>0) {
|
if(sizeof($factures)>0) {
|
||||||
?>
|
?>
|
||||||
<?php if($showRecapButton) {?><button class="btn btn-secondary" type="button" id="documentrecap">Generer le document recapitulatif</button><?php }?>
|
<?php if($showRecapButton) {?><button class="btn btn-secondary" type="button" id="documentrecap">Generer le document recapitulatif</button><?php }?>
|
||||||
<button class="btn btn-secondary ml-2" type="button" id="pdfFactures"><?php p($l->t('Save in Nextcloud'));?></button>
|
<button class="btn btn-secondary ml-2" type="button" id="exportMultipleFactureToPdf"><?php p($l->t('Save in Nextcloud'));?></button>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user