finish export group devis into facture features on backend , wip frontend
This commit is contained in:
parent
28cad12ff0
commit
ab961fffd1
@ -169,5 +169,8 @@ return [
|
||||
['name' => 'page#payInvoices','url' => '/facture/payInvoices', 'verb' => 'POST'],
|
||||
//relation of user and thanato
|
||||
['name' => 'page#getUsersNotLinkedToThanato','url' => '/user/getUsersNotLinkedToThanato', 'verb' => 'PROPFIND'],
|
||||
|
||||
//group of devis and facture
|
||||
['name' => 'page#exportGroupOfDevisIntoFacture','url' => '/devis/exportGroupOfDevisIntoFacture', 'verb' => 'POST'],
|
||||
]
|
||||
];
|
||||
|
||||
@ -2926,4 +2926,26 @@ class PageController extends Controller {
|
||||
return json_encode([]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
*/
|
||||
public function exportGroupOfDevisIntoFacture($clientId,$clientType,$month,$year,$facturationDate){
|
||||
try{
|
||||
$result = $this->invoicePdfService->exportGroupOfDevisIntoFacture(
|
||||
$clientId,
|
||||
$clientType,
|
||||
$month,
|
||||
$year,
|
||||
$facturationDate,
|
||||
$this->idNextcloud
|
||||
);
|
||||
return json_encode($result);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
return json_encode([]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2798,8 +2798,19 @@ class Bdd {
|
||||
public function getInvoiceGroupPdfData($factureId,$configuration){
|
||||
$tvaValue = $configuration->tva_default;
|
||||
$factureData = $this->getFactureByFactureId($factureId);
|
||||
$factureDevisList = $this->getInvoiceGroupDevisDatasByFactureId($factureId);
|
||||
$factureData["group_name"] = "";
|
||||
$isFactureForSingleClient = $factureData['fk_client_id'] != null && $factureData['fk_client_id'] != 0;
|
||||
if($isFactureForSingleClient){
|
||||
$factureDevisList = $this->getDevisDataByClientIdAndMonthYear(
|
||||
$factureData['fk_client_id'],
|
||||
$factureData['month'],
|
||||
$factureData['year']);
|
||||
}
|
||||
else{
|
||||
$factureDevisList = $this->getDevisDataByClientGroupFacturationIdAndMonthYear(
|
||||
$factureData['fk_client_group_facturation_id'],
|
||||
$factureData['month'],
|
||||
$factureData['year']);
|
||||
}
|
||||
$factureIncrement = 0;
|
||||
$productsCount = 0;
|
||||
$totalHt = 0;
|
||||
@ -2809,12 +2820,22 @@ class Bdd {
|
||||
$orderNumber = "";
|
||||
foreach($factureDevisList as &$devis){
|
||||
if($factureIncrement == 0){
|
||||
if($isFactureForSingleClient){
|
||||
$clientAddresses = FileExportHelpers::GetAddressAndCityFromAddress($devis['client_adresse']);
|
||||
$factureData["client_real_adress"] = $clientAddresses['address'];
|
||||
$factureData["client_adress_city"] = $clientAddresses['city'];
|
||||
$factureData["client_mail"] = $devis["client_mail"];
|
||||
$factureData["siret"] = $devis["client_legal_one"];
|
||||
$factureData["group_name"] = $devis["client_nom"] ?? "";
|
||||
}
|
||||
else{
|
||||
$factureData["client_real_adress"] = $devis["group_address"] ?? "";
|
||||
$factureData["client_adress_city"] = $devis["group_postal_code"]." ".$devis["group_city"];
|
||||
$factureData["client_mail"] = $devis["group_email"];
|
||||
$factureData["siret"] = $devis["group_siret_number"];
|
||||
$factureData["group_name"] = $devis["group_name"] ?? "";
|
||||
}
|
||||
}
|
||||
$caseNumber = empty($devis["case_number"]) ? $caseNumber : $devis["case_number"];
|
||||
$orderNumber = empty($devis["order_number"]) ? $orderNumber : $devis["order_number"];
|
||||
$products = $this->getDevisProduits($devis["devis_id"]);
|
||||
@ -4076,8 +4097,10 @@ class Bdd {
|
||||
return null;
|
||||
}
|
||||
|
||||
private function createFactureAndReturnFactureId($facturationDate,$type){
|
||||
public function createFactureAndReturnFactureId($facturationDate,$type,$month = null,$year = null,$fkClientId = null,$fkClientGroupFacturationId = null){
|
||||
$datetimeNow = new Datetime();
|
||||
$month = $month ?? $datetimeNow->format('m');
|
||||
$year = $year ?? $datetimeNow->format('Y');
|
||||
if($facturationDate == null || $facturationDate == ""){
|
||||
$facturationDate = DateHelpers::GetLastDayOfTheMonthOfADate($datetimeNow);
|
||||
$facturationDate = $facturationDate->format('Y-m-d');
|
||||
@ -4092,7 +4115,7 @@ class Bdd {
|
||||
$fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($datetimeNow,$factureNumber,"FAC");
|
||||
$last = 0;
|
||||
$last = $this->lastNumFacture(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
|
||||
$sql = "INSERT INTO `".$this->tableprefix."facture` (`date`,`id_nextcloud`,`num`,`date_paiement`,`type_paiement`,`id_devis`,`user_id`, `version`,`facture_number`,`facture_type`) VALUES (?,?,?,?,?,?,?,?,?,?);";
|
||||
$sql = "INSERT INTO `".$this->tableprefix."facture` (`date`,`id_nextcloud`,`num`,`date_paiement`,`type_paiement`,`id_devis`,`user_id`, `version`,`facture_number`,`facture_type`,`month`,`year`,`fk_client_id`,`fk_client_group_facturation_id`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
$this->execSQLNoData($sql, array(
|
||||
$factureDate ,
|
||||
BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD,
|
||||
@ -4103,7 +4126,11 @@ class Bdd {
|
||||
$last+1,
|
||||
"",
|
||||
$factureNumber,
|
||||
$type)
|
||||
$type,
|
||||
$month,
|
||||
$year,
|
||||
$fkClientId,
|
||||
$fkClientGroupFacturationId)
|
||||
);
|
||||
|
||||
return $this->getFactureIdByFactureNumber($fullFactureNumber);
|
||||
@ -4133,4 +4160,202 @@ class Bdd {
|
||||
}
|
||||
return FactureTypeConstant::TYPE_SINGLE;
|
||||
}
|
||||
|
||||
public function getDevisIdsByClientGroupFacturationIdAndMonthYear($clientGroupFacturationId,$month,$year){
|
||||
$sql = "SELECT devis.id
|
||||
FROM ".$this->tableprefix."devis as devis
|
||||
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
||||
WHERE
|
||||
client.fk_client_group_facturation_id = ? AND
|
||||
YEAR(devis.date) = ? AND
|
||||
MONTH(devis.date) = ?
|
||||
";
|
||||
|
||||
$result = $this->execSQLNoJsonReturn($sql,[$clientGroupFacturationId,$year,$month]);
|
||||
|
||||
$devisIds = [];
|
||||
foreach($result as $currentResult){
|
||||
$devisIds[] = $currentResult['id'];
|
||||
}
|
||||
return $devisIds;
|
||||
|
||||
}
|
||||
|
||||
public function getDevisIdsByClientIdAndMonthYear($clientId,$month,$year){
|
||||
$sql = "SELECT devis.id
|
||||
FROM ".$this->tableprefix."devis as devis
|
||||
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
||||
WHERE
|
||||
client.id = ? AND
|
||||
YEAR(devis.date) = ? AND
|
||||
MONTH(devis.date) = ?
|
||||
";
|
||||
|
||||
$result = $this->execSQLNoJsonReturn($sql,[$clientId,$year,$month]);
|
||||
|
||||
$devisIds = [];
|
||||
foreach($result as $currentResult){
|
||||
$devisIds[] = $currentResult['id'];
|
||||
}
|
||||
return $devisIds;
|
||||
|
||||
}
|
||||
|
||||
public function getFactureIdByClientIdAndMonthYear($clientId,$month,$year){
|
||||
$sql = "SELECT
|
||||
facture.id as facture_id
|
||||
FROM ".$this->tableprefix."facture as facture
|
||||
WHERE
|
||||
facture.fk_client_id = ? AND
|
||||
facture.year = ? AND
|
||||
facture.month = ? AND
|
||||
facture.facture_type = ?";
|
||||
|
||||
$result = $this->execSQLNoJsonReturn($sql,[
|
||||
$clientId,
|
||||
$year,
|
||||
$month,
|
||||
FactureTypeConstant::TYPE_GROUP
|
||||
]);
|
||||
|
||||
if(!empty($result)){
|
||||
return $result[0]['facture_id'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getFactureIdByClientGroupFacturationIdAndMonthYear($clientId,$month,$year){
|
||||
$sql = "SELECT
|
||||
facture.id as facture_id
|
||||
FROM ".$this->tableprefix."facture as facture
|
||||
WHERE
|
||||
facture.fk_client_group_facturation_id = ? AND
|
||||
facture.year = ? AND
|
||||
facture.month = ? AND
|
||||
facture.facture_type = ?";
|
||||
|
||||
$result = $this->execSQLNoJsonReturn($sql,[
|
||||
$clientId,
|
||||
$year,
|
||||
$month,
|
||||
FactureTypeConstant::TYPE_GROUP
|
||||
]);
|
||||
|
||||
if(!empty($result)){
|
||||
return $result[0]['facture_id'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function invoiceListOfDevisIds($devisIds){
|
||||
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($devisIds), '?'));
|
||||
$sql = "UPDATE ".$this->tableprefix."devis as devis
|
||||
SET devis.mentions = ?
|
||||
WHERE devis.id IN ($sqlConditionsPlaceholder);";
|
||||
|
||||
$conditions = array_merge(
|
||||
[DevisMentionConstant::FACTURED_FORMATTED],
|
||||
$devisIds
|
||||
);
|
||||
|
||||
$this->execSQLNoData($sql,$conditions);
|
||||
}
|
||||
|
||||
private function getDevisDataByClientGroupFacturationIdAndMonthYear($clientGroupFacturationId,$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.order_number as order_number,
|
||||
devis.case_number as case_number,
|
||||
client.nom as client_nom,
|
||||
client.entreprise as client_entreprise,
|
||||
client.adresse as client_adresse,
|
||||
client.mail as client_mail,
|
||||
client.legal_one as client_legal_one,
|
||||
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.id as group_id,
|
||||
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."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
|
||||
LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation on client.fk_client_group_facturation_id = client_group_facturation.id
|
||||
WHERE
|
||||
client.fk_client_group_facturation_id = ? AND
|
||||
YEAR(devis.date) = ? AND
|
||||
MONTH(devis.date) = ?
|
||||
ORDER BY devis.date ASC;";
|
||||
|
||||
$devisList = $this->execSQLNoJsonReturn($sql,[
|
||||
$clientGroupFacturationId,
|
||||
$year,
|
||||
$month
|
||||
]);
|
||||
|
||||
return $devisList;
|
||||
}
|
||||
|
||||
private function getDevisDataByClientIdAndMonthYear($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.order_number as order_number,
|
||||
devis.case_number as case_number,
|
||||
client.nom as client_nom,
|
||||
client.entreprise as client_entreprise,
|
||||
client.adresse as client_adresse,
|
||||
client.mail as client_mail,
|
||||
client.legal_one as client_legal_one,
|
||||
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.id as group_id,
|
||||
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."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
|
||||
LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation on client.fk_client_group_facturation_id = client_group_facturation.id
|
||||
WHERE
|
||||
client.id = ? AND
|
||||
YEAR(devis.date) = ? AND
|
||||
MONTH(devis.date) = ?
|
||||
ORDER BY devis.date ASC;";
|
||||
|
||||
$devisList = $this->execSQLNoJsonReturn($sql,[
|
||||
$clientId,
|
||||
$year,
|
||||
$month
|
||||
]);
|
||||
|
||||
return $devisList;
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,8 +28,6 @@ namespace OCA\Gestion\Service\InvoiceGroupPdfHandler;
|
||||
|
||||
use DateTime;
|
||||
use \FPDF;
|
||||
use OCA\Gestion\Constants\MultipleFactureTypeConstant;
|
||||
use OCA\Gestion\Helpers\DateHelpers;
|
||||
use OCA\Gestion\Helpers\FileExportHelpers;
|
||||
use OCA\Gestion\Helpers\PriceHelpers;
|
||||
|
||||
|
||||
@ -27,12 +27,14 @@ declare(strict_types=1);
|
||||
namespace OCA\Gestion\Service;
|
||||
|
||||
use DateTime;
|
||||
use OCA\Gestion\Constants\BddConstant;
|
||||
use OCA\Gestion\Constants\FactureTypeConstant;
|
||||
use OCA\Gestion\Constants\MultipleFactureTypeConstant;
|
||||
use OCA\Gestion\Db\Bdd;
|
||||
use OCA\Gestion\Helpers\DateHelpers;
|
||||
use OCA\Gestion\Service\InvoiceGroupPdfHandler\InvoiceGroupPdfHandler;
|
||||
use OCA\Gestion\Service\InvoiceRecap\InvoiceRecapService;
|
||||
use OCP\DB\Exception;
|
||||
use OCP\Files\IRootFolder;
|
||||
|
||||
class InvoicePdfService {
|
||||
@ -224,4 +226,44 @@ class InvoicePdfService {
|
||||
public function generateInvoiceRecap($filter,$filterType,$date,$idNextCloud){
|
||||
$this->invoiceRecapService->generateInvoiceRecap($filter,$filterType,$date,$idNextCloud);
|
||||
}
|
||||
|
||||
public function exportGroupOfDevisIntoFacture($clientId,$clientType,$month,$year,$facturationDate,$idNextcloud = BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD){
|
||||
try{
|
||||
$datetime = new Datetime();
|
||||
$month = $month ?? $datetime->format('m');
|
||||
$year = $year ?? $datetime->format('Y');
|
||||
|
||||
$factureId = null;
|
||||
$fkClientId = null;
|
||||
$fkClientGroupFacturationId = null;
|
||||
if($clientType == MultipleFactureTypeConstant::CLIENT_FILTER_TYPE){
|
||||
$factureId = $this->gestionBdd->getFactureIdByClientIdAndMonthYear($clientId,$month,$year);
|
||||
$devisIds = $this->gestionBdd->getDevisIdsByClientIdAndMonthYear($clientId,$month,$year);
|
||||
$fkClientId = $clientId;
|
||||
}
|
||||
else{
|
||||
$factureId = $this->gestionBdd->getFactureIdByClientGroupFacturationIdAndMonthYear($clientId,$month,$year);
|
||||
$devisIds = $this->gestionBdd->getDevisIdsByClientGroupFacturationIdAndMonthYear($clientId,$month,$year);
|
||||
$fkClientGroupFacturationId = $clientId;
|
||||
}
|
||||
$clientIsAlreadyFacturedForThisMonthAndYear = $factureId != null && $factureId != 0;
|
||||
if($clientIsAlreadyFacturedForThisMonthAndYear == false){
|
||||
$factureId = $this->gestionBdd->createFactureAndReturnFactureId(
|
||||
$facturationDate,
|
||||
FactureTypeConstant::TYPE_GROUP,
|
||||
$month,
|
||||
$year,
|
||||
$fkClientId,
|
||||
$fkClientGroupFacturationId);
|
||||
}
|
||||
|
||||
$this->gestionBdd->invoiceListOfDevisIds($devisIds);
|
||||
$filenames = $this->generateFactureGroupPdfByFactureId($factureId,$idNextcloud);
|
||||
return $filenames;
|
||||
}
|
||||
catch(Exception){
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user