Merge branch 'features/feature-devis-group' into releases/release-hytha-prod
This commit is contained in:
commit
0276655040
File diff suppressed because one or more lines are too long
9
gestion/lib/Constants/DevisExportTypeConstant.php
Normal file
9
gestion/lib/Constants/DevisExportTypeConstant.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace OCA\Gestion\Constants;
|
||||||
|
abstract class DevisExportTypeConstant
|
||||||
|
{
|
||||||
|
const TYPE_SINGLE = "client";
|
||||||
|
const TYPE_GROUP = "group";
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ namespace OCA\Gestion\Controller;
|
|||||||
use \FPDF;
|
use \FPDF;
|
||||||
use \Datetime;
|
use \Datetime;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use OCA\Gestion\Constants\DevisExportTypeConstant;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
defined("TAB1") or define("TAB1", "\t");
|
defined("TAB1") or define("TAB1", "\t");
|
||||||
@ -2855,9 +2856,9 @@ class PageController extends Controller {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function exportDevisByClientAndMonthYearToPdf($clientId,$month,$year){
|
public function exportDevisByClientAndMonthYearToPdf($clientId,$month,$year,$type=DevisExportTypeConstant::TYPE_SINGLE){
|
||||||
try{
|
try{
|
||||||
$devisFilename = $this->devisPdfService->generateMultipleDevisPdfByClientAndMonthYear($clientId,$month,$year,$this->idNextcloud);
|
$devisFilename = $this->devisPdfService->generateMultipleDevisPdfByClientAndMonthYear($clientId,$month,$year,$type,$this->idNextcloud);
|
||||||
return $devisFilename;
|
return $devisFilename;
|
||||||
}
|
}
|
||||||
catch(\OCP\Files\NotFoundException $e) { }
|
catch(\OCP\Files\NotFoundException $e) { }
|
||||||
|
|||||||
@ -3038,13 +3038,18 @@ class Bdd {
|
|||||||
return $factureData;
|
return $factureData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDevisByClientAndMonthYear($clientId,$month,$year){
|
private function getDevisByClientIdsListAndMonthYear($clientIds,$month,$year){
|
||||||
|
if(empty($clientIds)){
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$clientSqlPlaceholders = implode(',', array_fill(0, count($clientIds), '?'));
|
||||||
$sql = "SELECT
|
$sql = "SELECT
|
||||||
devis.id as devis_id,
|
devis.id as devis_id,
|
||||||
devis.date as devis_date,
|
devis.date as devis_date,
|
||||||
devis.num as calendar_uuid,
|
devis.num as calendar_uuid,
|
||||||
devis.comment as devis_comment,
|
devis.comment as devis_comment,
|
||||||
devis.id_client as devis_id_client,
|
devis.id_client as devis_id_client,
|
||||||
|
devis.devis_full_number,
|
||||||
client.nom as client_nom,
|
client.nom as client_nom,
|
||||||
client.entreprise as client_entreprise,
|
client.entreprise as client_entreprise,
|
||||||
client.adresse as client_adresse,
|
client.adresse as client_adresse,
|
||||||
@ -3053,9 +3058,68 @@ class Bdd {
|
|||||||
lieu.nom as lieu_nom,
|
lieu.nom as lieu_nom,
|
||||||
lieu.adresse as lieu_adresse,
|
lieu.adresse as lieu_adresse,
|
||||||
thanato.nom as thanato_nom,
|
thanato.nom as thanato_nom,
|
||||||
thanato.prenom as thanato_prenom
|
thanato.prenom as thanato_prenom,
|
||||||
|
client_group_facturation.group_facturation_name as group_name,
|
||||||
|
client_group_facturation.phone_number as group_phone_number,
|
||||||
|
client_group_facturation.address as group_address,
|
||||||
|
client_group_facturation.postal_code as group_postal_code,
|
||||||
|
client_group_facturation.city as group_city,
|
||||||
|
client_group_facturation.email as group_email,
|
||||||
|
client_group_facturation.siret_number as group_siret_number,
|
||||||
|
client_group_facturation.tva_intracommu as group_tva_intracommu
|
||||||
FROM ".$this->tableprefix."devis as devis
|
FROM ".$this->tableprefix."devis as devis
|
||||||
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
||||||
|
LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation on client.fk_client_group_facturation_id = client_group_facturation.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 IN ($clientSqlPlaceholders) AND
|
||||||
|
YEAR(devis.date) = ?";
|
||||||
|
|
||||||
|
$conditions = array_merge(
|
||||||
|
$clientIds,
|
||||||
|
[$year]
|
||||||
|
);
|
||||||
|
if($month != 0){
|
||||||
|
$conditions[] = $month;
|
||||||
|
$sql .= " AND MONTH(devis.date) = ?";
|
||||||
|
}
|
||||||
|
$sql .= ";";
|
||||||
|
$devisList = $this->execSQLNoJsonReturn(
|
||||||
|
$sql,
|
||||||
|
$conditions);
|
||||||
|
|
||||||
|
return $devisList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDevisByClientAndMonthYear($clientId,$month,$year){
|
||||||
|
$sql = "SELECT
|
||||||
|
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,
|
||||||
|
devis.devis_full_number,
|
||||||
|
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,
|
||||||
|
client_group_facturation.group_facturation_name as group_name,
|
||||||
|
client_group_facturation.phone_number as group_phone_number,
|
||||||
|
client_group_facturation.address as group_address,
|
||||||
|
client_group_facturation.postal_code as group_postal_code,
|
||||||
|
client_group_facturation.city as group_city,
|
||||||
|
client_group_facturation.email as group_email,
|
||||||
|
client_group_facturation.siret_number as group_siret_number,
|
||||||
|
client_group_facturation.tva_intracommu as group_tva_intracommu
|
||||||
|
FROM ".$this->tableprefix."devis as devis
|
||||||
|
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
||||||
|
LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation on client.fk_client_group_facturation_id = client_group_facturation.id
|
||||||
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.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."lieu as lieu on devis.id_lieu = lieu.id
|
||||||
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
||||||
@ -3075,6 +3139,12 @@ class Bdd {
|
|||||||
return $devisList;
|
return $devisList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDevisPdfDataByClientGroupFacturationAndMonthYear($clientGroupFacturationId,$month,$year,$configuration){
|
||||||
|
$clientIds = $this->getClientIdsByClientGroupFacturationId($clientGroupFacturationId);
|
||||||
|
$devisList = $this->getDevisByClientIdsListAndMonthYear($clientIds,$month,$year);
|
||||||
|
return $devisList;
|
||||||
|
}
|
||||||
|
|
||||||
public function getDevisPdfDataByClientAndMonthYear($clientId,$month,$year,$configuration){
|
public function getDevisPdfDataByClientAndMonthYear($clientId,$month,$year,$configuration){
|
||||||
$devisList = $this->getDevisByClientAndMonthYear($clientId,$month,$year);
|
$devisList = $this->getDevisByClientAndMonthYear($clientId,$month,$year);
|
||||||
return $devisList;
|
return $devisList;
|
||||||
|
|||||||
@ -27,6 +27,7 @@ declare(strict_types=1);
|
|||||||
namespace OCA\Gestion\Service\Devis\Pdf;
|
namespace OCA\Gestion\Service\Devis\Pdf;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use OCA\Gestion\Constants\DevisExportTypeConstant;
|
||||||
use OCA\Gestion\Db\Bdd;
|
use OCA\Gestion\Db\Bdd;
|
||||||
use OCA\Gestion\Helpers\DateHelpers;
|
use OCA\Gestion\Helpers\DateHelpers;
|
||||||
use OCA\Gestion\Helpers\FileExportHelpers;
|
use OCA\Gestion\Helpers\FileExportHelpers;
|
||||||
@ -150,10 +151,15 @@ class DevisPdfService {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetMultipleDevisFilename($multipleDevisData,$month,$year){
|
private function GetMultipleDevisFilename($multipleDevisData,$month,$year,$type = DevisExportTypeConstant::TYPE_SINGLE){
|
||||||
$filename = "";
|
$filename = "";
|
||||||
foreach($multipleDevisData as $devis){
|
foreach($multipleDevisData as $devis){
|
||||||
$filename = strtoupper($devis["client_entreprise"]);
|
if($type == DevisExportTypeConstant::TYPE_SINGLE){
|
||||||
|
$filename = mb_strtoupper($devis["client_nom"],'UTF-8');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$filename = mb_strtoupper($devis["group_name"],'UTF-8');
|
||||||
|
}
|
||||||
$filename .= $month != 0 ? '_'.DateHelpers::GetMonthPlainString($month) :'';
|
$filename .= $month != 0 ? '_'.DateHelpers::GetMonthPlainString($month) :'';
|
||||||
$filename .= "_".$year;
|
$filename .= "_".$year;
|
||||||
break;
|
break;
|
||||||
@ -161,24 +167,40 @@ class DevisPdfService {
|
|||||||
return $filename;
|
return $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateMultipleDevisPdfByClientAndMonthYear($clientId,$month,$year,$idNextCloud){
|
public function generateMultipleDevisPdfByClientAndMonthYear($clientId,$month,$year,$type,$idNextCloud){
|
||||||
$storage = $this->rootFolder->getUserFolder($idNextCloud);
|
$storage = $this->rootFolder->getUserFolder($idNextCloud);
|
||||||
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
|
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
|
||||||
$currentConfig = $configs[0];
|
$currentConfig = $configs[0];
|
||||||
$logo = $this->getLogo();
|
$logo = $this->getLogo();
|
||||||
$mulitpleDevisData = $this->gestionBdd->getDevisPdfDataByClientAndMonthYear($clientId,$month,$year,$currentConfig);
|
if($type == DevisExportTypeConstant::TYPE_SINGLE){
|
||||||
if(empty($mulitpleDevisData)){
|
$multipleDevisData = $this->gestionBdd->getDevisPdfDataByClientAndMonthYear($clientId,$month,$year,$currentConfig);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$multipleDevisData = $this->gestionBdd->getDevisPdfDataByClientGroupFacturationAndMonthYear(
|
||||||
|
$clientId,
|
||||||
|
$month,
|
||||||
|
$year,
|
||||||
|
$currentConfig
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if(empty($multipleDevisData)){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$multipleDevisDataFormatted = $this->formatMultipleDevisToPdfFormat($mulitpleDevisData,$currentConfig);
|
$multipleDevisDataFormatted = $this->formatMultipleDevisToPdfFormat($multipleDevisData,$currentConfig);
|
||||||
|
if($type == DevisExportTypeConstant::TYPE_SINGLE){
|
||||||
|
$clientFolderName = mb_strtoupper($multipleDevisDataFormatted[0]["client_nom"] ?? "-","UTF-8");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$clientFolderName = mb_strtoupper($multipleDevisDataFormatted[0]["group_name"] ?? "-","UTF-8");
|
||||||
|
}
|
||||||
$pdf = new DevisPdfHandler();
|
$pdf = new DevisPdfHandler();
|
||||||
$pdf->AddFont('ComicSans','','Comic Sans MS.php');
|
$pdf->AddFont('ComicSans','','Comic Sans MS.php');
|
||||||
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
|
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
|
||||||
$pdf->SetMultipleDevisPdfData($multipleDevisDataFormatted,$logo);
|
$pdf->SetMultipleDevisPdfData($multipleDevisDataFormatted,$logo);
|
||||||
$pdf->SetMultipleDevisContent();
|
$pdf->SetMultipleDevisContent();
|
||||||
$racinePath = html_entity_decode(string: $currentConfig->path).'/';
|
$racinePath = html_entity_decode(string: $currentConfig->path).'/';
|
||||||
$clientRacineFolder = $racinePath.'CLIENTS/'.strtoupper($multipleDevisDataFormatted[0]["client_entreprise"]).'/';
|
$clientRacineFolder = $racinePath.'CLIENTS/'.$clientFolderName.'/';
|
||||||
$filename = 'DEVIS'.'_'.$this->GetMultipleDevisFilename($multipleDevisDataFormatted,$month,$year);
|
$filename = 'DEVIS'.'_'.$this->GetMultipleDevisFilename($multipleDevisDataFormatted,$month,$year,$type);
|
||||||
$filenamePath = $clientRacineFolder.$filename.'.pdf';
|
$filenamePath = $clientRacineFolder.$filename.'.pdf';
|
||||||
$pdfContent = $pdf->Output('','S');
|
$pdfContent = $pdf->Output('','S');
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -18,8 +18,20 @@ window.addEventListener("DOMContentLoaded", function () {
|
|||||||
const clientId = urlParams.get('cli');
|
const clientId = urlParams.get('cli');
|
||||||
const year = urlParams.get('annee');
|
const year = urlParams.get('annee');
|
||||||
const month = urlParams.get('mois');
|
const month = urlParams.get('mois');
|
||||||
|
const filterType = urlParams.get('filterType');
|
||||||
var exportMultipleDevisToPdfButton = this.document.getElementById("exportMultipleDevisToPdf");
|
var exportMultipleDevisToPdfButton = this.document.getElementById("exportMultipleDevisToPdf");
|
||||||
exportMultipleDevisToPdfButton.addEventListener("click",function(){
|
exportMultipleDevisToPdfButton.addEventListener("click",function(){
|
||||||
exportClientDevisByMonthAndYearToPdf(clientId,year,month);
|
exportClientDevisByMonthAndYearToPdf(clientId,year,month,filterType);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.onchange = function(event) {
|
||||||
|
if (event.target && event.target.id === 'clientselector') {
|
||||||
|
let selectedOption = event.target.options[event.target.selectedIndex];
|
||||||
|
let filterType = selectedOption.getAttribute('data-type');
|
||||||
|
let filterTypeInput = document.getElementById('filterType');
|
||||||
|
if (filterTypeInput) {
|
||||||
|
filterTypeInput.value = filterType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -834,11 +834,12 @@ export function exportDevisToPdf(devisId) {
|
|||||||
* Export multiple devis to pdf
|
* Export multiple devis to pdf
|
||||||
* @param {*} devisId
|
* @param {*} devisId
|
||||||
*/
|
*/
|
||||||
export function exportClientDevisByMonthAndYearToPdf(clientId,year,month) {
|
export function exportClientDevisByMonthAndYearToPdf(clientId,year,month,filterType) {
|
||||||
let payload = {
|
let payload = {
|
||||||
clientId: clientId,
|
clientId: clientId,
|
||||||
month : month,
|
month : month,
|
||||||
year : year
|
year : year,
|
||||||
|
type: filterType
|
||||||
};
|
};
|
||||||
|
|
||||||
showLoader();
|
showLoader();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user