Merge branch 'features/feature-devis-group' into releases/release-hytha-prod

This commit is contained in:
Tiavina 2025-03-26 13:06:50 +03:00
commit 0276655040
7 changed files with 132 additions and 17 deletions

File diff suppressed because one or more lines are too long

View 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";
}

View File

@ -4,6 +4,7 @@ namespace OCA\Gestion\Controller;
use \FPDF;
use \Datetime;
use Exception;
use OCA\Gestion\Constants\DevisExportTypeConstant;
use OCP\IConfig;
use OCP\IRequest;
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{
$devisFilename = $this->devisPdfService->generateMultipleDevisPdfByClientAndMonthYear($clientId,$month,$year,$this->idNextcloud);
$devisFilename = $this->devisPdfService->generateMultipleDevisPdfByClientAndMonthYear($clientId,$month,$year,$type,$this->idNextcloud);
return $devisFilename;
}
catch(\OCP\Files\NotFoundException $e) { }

View File

@ -3038,13 +3038,18 @@ class Bdd {
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
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,
@ -3053,9 +3058,68 @@ class Bdd {
lieu.nom as lieu_nom,
lieu.adresse as lieu_adresse,
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
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."lieu as lieu on devis.id_lieu = lieu.id
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
@ -3075,6 +3139,12 @@ class Bdd {
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){
$devisList = $this->getDevisByClientAndMonthYear($clientId,$month,$year);
return $devisList;

View File

@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OCA\Gestion\Service\Devis\Pdf;
use DateTime;
use OCA\Gestion\Constants\DevisExportTypeConstant;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Helpers\DateHelpers;
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 = "";
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 .= "_".$year;
break;
@ -161,24 +167,40 @@ class DevisPdfService {
return $filename;
}
public function generateMultipleDevisPdfByClientAndMonthYear($clientId,$month,$year,$idNextCloud){
public function generateMultipleDevisPdfByClientAndMonthYear($clientId,$month,$year,$type,$idNextCloud){
$storage = $this->rootFolder->getUserFolder($idNextCloud);
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$currentConfig = $configs[0];
$logo = $this->getLogo();
$mulitpleDevisData = $this->gestionBdd->getDevisPdfDataByClientAndMonthYear($clientId,$month,$year,$currentConfig);
if(empty($mulitpleDevisData)){
if($type == DevisExportTypeConstant::TYPE_SINGLE){
$multipleDevisData = $this->gestionBdd->getDevisPdfDataByClientAndMonthYear($clientId,$month,$year,$currentConfig);
}
else{
$multipleDevisData = $this->gestionBdd->getDevisPdfDataByClientGroupFacturationAndMonthYear(
$clientId,
$month,
$year,
$currentConfig
);
}
if(empty($multipleDevisData)){
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->AddFont('ComicSans','','Comic Sans MS.php');
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
$pdf->SetMultipleDevisPdfData($multipleDevisDataFormatted,$logo);
$pdf->SetMultipleDevisContent();
$racinePath = html_entity_decode(string: $currentConfig->path).'/';
$clientRacineFolder = $racinePath.'CLIENTS/'.strtoupper($multipleDevisDataFormatted[0]["client_entreprise"]).'/';
$filename = 'DEVIS'.'_'.$this->GetMultipleDevisFilename($multipleDevisDataFormatted,$month,$year);
$clientRacineFolder = $racinePath.'CLIENTS/'.$clientFolderName.'/';
$filename = 'DEVIS'.'_'.$this->GetMultipleDevisFilename($multipleDevisDataFormatted,$month,$year,$type);
$filenamePath = $clientRacineFolder.$filename.'.pdf';
$pdfContent = $pdf->Output('','S');
try {

View File

@ -18,8 +18,20 @@ window.addEventListener("DOMContentLoaded", function () {
const clientId = urlParams.get('cli');
const year = urlParams.get('annee');
const month = urlParams.get('mois');
const filterType = urlParams.get('filterType');
var exportMultipleDevisToPdfButton = this.document.getElementById("exportMultipleDevisToPdf");
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;
}
}
};

View File

@ -834,11 +834,12 @@ export function exportDevisToPdf(devisId) {
* Export multiple devis to pdf
* @param {*} devisId
*/
export function exportClientDevisByMonthAndYearToPdf(clientId,year,month) {
export function exportClientDevisByMonthAndYearToPdf(clientId,year,month,filterType) {
let payload = {
clientId: clientId,
month : month,
year : year
year : year,
type: filterType
};
showLoader();