finish facture group (add tables,default type,facturation devis group on front,pdf group), WIP : facture details impact,recap impact,facturation groupe impact,FEC
This commit is contained in:
parent
7af04a62a9
commit
a1b94284b0
1
gestion/.gitignore
vendored
Normal file
1
gestion/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
||||
File diff suppressed because one or more lines are too long
9
gestion/lib/Constants/FactureTypeConstant.php
Normal file
9
gestion/lib/Constants/FactureTypeConstant.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\Gestion\Constants;
|
||||
abstract class FactureTypeConstant
|
||||
{
|
||||
const TYPE_SINGLE = "SINGLE";
|
||||
const TYPE_GROUP = "GROUP";
|
||||
}
|
||||
@ -3,6 +3,7 @@ namespace OCA\Gestion\Controller;
|
||||
|
||||
use Exception;
|
||||
use OCA\Gestion\Constants\BddConstant;
|
||||
use OCA\Gestion\Constants\FactureTypeConstant;
|
||||
use OCA\Gestion\Service\InvoicePdfHandler;
|
||||
defined("TAB1") or define("TAB1", "\t");
|
||||
|
||||
@ -1500,11 +1501,22 @@ class PageController extends Controller {
|
||||
* @param array $devisToFacture
|
||||
* @param string $paymentDate
|
||||
*/
|
||||
public function exportDevisToFacture($devisToFacture,$paymentDate) {
|
||||
$factureIdsGenerated = $this->myDb->insertFactureForeEachDevisId($this->idNextcloud,$devisToFacture,$paymentDate);
|
||||
public function exportDevisToFacture($devisToFacture,$paymentDate,$type = FactureTypeConstant::TYPE_SINGLE) {
|
||||
$response = true;
|
||||
$factureIdsGenerated = [];
|
||||
if($type == FactureTypeConstant::TYPE_GROUP){
|
||||
$doDevisIdsListIdsBelongsToTheSameClientFacturationGroup = $this->myDb->doDevisIdsListIdsBelongsToTheSameClientFacturationGroup($devisToFacture);
|
||||
if($doDevisIdsListIdsBelongsToTheSameClientFacturationGroup == false){
|
||||
return "Les devis fournis ne sont pas dans la même groupe de facturation";
|
||||
}
|
||||
$factureIdsGenerated = $this->myDb->generateGroupFactureForMultipleDevis($devisToFacture,$paymentDate);
|
||||
}
|
||||
else{
|
||||
$factureIdsGenerated = $this->myDb->insertFactureForeEachDevisId($this->idNextcloud,$devisToFacture,$paymentDate);
|
||||
}
|
||||
$this->invoicePdfService->generateFacturePdfByFactureIds($factureIdsGenerated,$this->idNextcloud);
|
||||
$this->refreshFEC();
|
||||
return true;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2475,8 +2487,6 @@ class PageController extends Controller {
|
||||
|
||||
public function exportFactureToPdf($factureId){
|
||||
try{
|
||||
//for HYTHA 35 , the default admin idnextcloud is Johann, for H2F it is Emmanuelle
|
||||
// $this->idNextcloud = self::HYTHA_35_DEFAULT_ADMIN;
|
||||
$factureFilenames = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->idNextcloud);
|
||||
return json_encode($factureFilenames);
|
||||
}
|
||||
|
||||
@ -2,7 +2,9 @@
|
||||
namespace OCA\Gestion\Db;
|
||||
|
||||
use OCA\Gestion\Constants\FactureStatusConstant;
|
||||
use OCA\Gestion\Constants\FactureTypeConstant;
|
||||
use OCA\Gestion\Helpers\DateHelpers;
|
||||
use OCA\Gestion\Helpers\PriceHelpers;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use \Datetime;
|
||||
@ -1291,7 +1293,6 @@ class Bdd {
|
||||
}
|
||||
$placeholders = implode(',', array_fill(0, count($devisListId), '?'));
|
||||
$mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionsFilter), '?'));
|
||||
$this->logger->debug('Placeholders : ' . $placeholders);
|
||||
$sql = "SELECT devis.id as id,devis.date as devis_date
|
||||
FROM ".$this->tableprefix."devis as devis
|
||||
WHERE devis.id IN ($placeholders) AND
|
||||
@ -2732,6 +2733,109 @@ class Bdd {
|
||||
return $clientList;
|
||||
}
|
||||
|
||||
private function getInvoiceGroupDevisDatasByFactureId($factureId){
|
||||
$sql = "SELECT
|
||||
devis_facture.id as devis_facture_id,
|
||||
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_facture as devis_facture
|
||||
LEFT JOIN ".$this->tableprefix."devis as devis on devis_facture.fk_devis_id = 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
|
||||
LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation on client.fk_client_group_facturation_id = client_group_facturation.id
|
||||
WHERE devis_facture.fk_facture_id = ?
|
||||
;";
|
||||
$devis = $this->execSQLNoJsonReturn(
|
||||
$sql,
|
||||
[$factureId]);
|
||||
|
||||
return $devis;
|
||||
}
|
||||
|
||||
public function getFactureByFactureId($factureId){
|
||||
$sql = "SELECT * FROM ".$this->tableprefix."facture as facture
|
||||
WHERE facture.id = ? LIMIT 1;
|
||||
";
|
||||
|
||||
$result = $this->execSQLNoJsonReturn($sql,[$factureId]);
|
||||
if(!empty($result)){
|
||||
return $result[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getInvoiceGroupPdfData($factureId,$configuration){
|
||||
$tvaValue = $configuration->tva_default;
|
||||
$factureData = $this->getFactureByFactureId($factureId);
|
||||
$factureDevisList = $this->getInvoiceGroupDevisDatasByFactureId($factureId);
|
||||
$factureData["group_name"] = "";
|
||||
$factureIncrement = 0;
|
||||
$productsCount = 0;
|
||||
$totalHt = 0;
|
||||
$totalTtc = 0;
|
||||
$totalTva = 0;
|
||||
foreach($factureDevisList as &$devis){
|
||||
if($factureIncrement == 0){
|
||||
$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"] ?? "";
|
||||
}
|
||||
$products = $this->getDevisProduits($devis["devis_id"]);
|
||||
foreach($products as $product){
|
||||
$valueHt = $product['produit_price'] * $product['quantite'];
|
||||
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt,$tvaValue);
|
||||
$totalHt+=$valueHt;
|
||||
$totalTtc+=$valueTtc;
|
||||
$tvaAmount = $valueTtc - $valueHt;
|
||||
$totalTva += $tvaAmount;
|
||||
}
|
||||
$productsCount += count($products);
|
||||
$devis['products'] = $products;
|
||||
$factureIncrement++;
|
||||
}
|
||||
$totaPricesArray = [
|
||||
"TOTAL HT" => $totalHt,
|
||||
"TVA ".$tvaValue. "%" => $totalTva,
|
||||
"TOTAL TTC" => $totalTtc
|
||||
];
|
||||
$factureData["devis"] = $factureDevisList;
|
||||
$factureData["configuration"] = $configuration;
|
||||
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse);
|
||||
$factureData["configuration_adresse"] = $configurationAdresses["address"];
|
||||
$factureData["configuration_adresse_city"] = $configurationAdresses["city"];
|
||||
$factureData["productsCount"] = $productsCount;
|
||||
$factureData["totalPrices"] = $totaPricesArray;
|
||||
return $factureData;
|
||||
}
|
||||
|
||||
public function getInvoicePdfData($factureId,$configuration){
|
||||
$factureData = $this->getFactureByIdWithDevis($factureId);
|
||||
if($factureData == null){
|
||||
@ -3894,4 +3998,128 @@ class Bdd {
|
||||
|
||||
return $this->execSQL($sql,[BddConstant::DEFAULT_THANATOS_GROUP_NAME]);
|
||||
}
|
||||
|
||||
public function doDevisIdsListIdsBelongsToTheSameClientFacturationGroup(array $devisIds){
|
||||
if(empty($devisIds)){
|
||||
return [];
|
||||
}
|
||||
$sqlPlacholders = implode(',', array_fill(0, count($devisIds), '?'));
|
||||
$sql = "SELECT
|
||||
devis.id,
|
||||
client.fk_client_group_facturation_id
|
||||
FROM ".$this->tableprefix."devis as devis
|
||||
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
||||
WHERE
|
||||
devis.id_client IS NOT NULL AND
|
||||
devis.id IN($sqlPlacholders);";
|
||||
|
||||
$results = $this->execSQLNoJsonReturn($sql,$devisIds);
|
||||
$clientGroupFacturationsIds = [];
|
||||
foreach($results as $currentResult){
|
||||
if($currentResult['fk_client_group_facturation_id'] == null){
|
||||
return false;
|
||||
}
|
||||
$clientGroupFacturationsIds[] = $currentResult['fk_client_group_facturation_id'];
|
||||
}
|
||||
$uniqueClientGroupFacturation = array_unique($clientGroupFacturationsIds);
|
||||
return $uniqueClientGroupFacturation > 1;
|
||||
|
||||
}
|
||||
|
||||
private function doesDevisFactureGroupAlreadyExist($factureId,$devisId){
|
||||
$sql = "SELECT count(*) as DEVIS_FACTURE_COUNT
|
||||
FROM ".$this->tableprefix."devis_facture as devis_facture
|
||||
WHERE devis_facture.fk_devis_id = ? AND devis_facture.fk_facture_id = ?";
|
||||
|
||||
$result = $this->execSQLNoJsonReturn($sql,[$devisId,$factureId]);
|
||||
if(!empty($result)){
|
||||
return $result[0]["DEVIS_FACTURE_COUNT"] > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function createFactureGroupDevis($factureId,$devisId){
|
||||
$doesDevisFactureGroupAlreadyExist = $this->doesDevisFactureGroupAlreadyExist($factureId,$devisId);
|
||||
if(!$doesDevisFactureGroupAlreadyExist){
|
||||
$sql = "INSERT INTO `".$this->tableprefix."devis_facture` (`fk_devis_id`,`fk_facture_id`) VALUES (?,?);";
|
||||
$this->execSQLNoData($sql, [$devisId,$factureId]);
|
||||
$this->gestion_update('devis','mentions',DevisMentionConstant::FACTURED_FORMATTED,$devisId,BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
|
||||
}
|
||||
}
|
||||
|
||||
public function createFactureGroupForDevisList($factureId,$devisIds){
|
||||
foreach($devisIds as $devis){
|
||||
$this->createFactureGroupDevis($factureId,$devis['id']);
|
||||
}
|
||||
}
|
||||
|
||||
private function getFactureIdByFactureNumber($factureNumber){
|
||||
$sql = "SELECT max(facture.id) AS FACTURE_ID
|
||||
FROM ".$this->tableprefix."facture as facture
|
||||
WHERE facture.num = ? ;";
|
||||
|
||||
$result = $this->execSQLNoJsonReturn($sql,[$factureNumber]);
|
||||
if(!empty($result)){
|
||||
return $result[0]['FACTURE_ID'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function createFactureAndReturnFactureId($facturationDate,$type){
|
||||
$datetimeNow = new Datetime();
|
||||
if($facturationDate == null || $facturationDate == ""){
|
||||
$facturationDate = DateHelpers::GetLastDayOfTheMonthOfADate($datetimeNow);
|
||||
$facturationDate = $facturationDate->format('Y-m-d');
|
||||
}
|
||||
else{
|
||||
$facturationDate = Datetime::createFromFormat('Y-m-d',$facturationDate);
|
||||
$facturationDate = $facturationDate->format('Y-m-d');
|
||||
}
|
||||
|
||||
$factureDate = $datetimeNow->format('Y-m-d');
|
||||
$factureNumber = $this->getFactureNumberByDate($datetimeNow);
|
||||
$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 (?,?,?,?,?,?,?,?,?,?);";
|
||||
$this->execSQLNoData($sql, array(
|
||||
$factureDate ,
|
||||
BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD,
|
||||
$fullFactureNumber,
|
||||
$facturationDate,
|
||||
"",
|
||||
0,
|
||||
$last+1,
|
||||
"",
|
||||
$factureNumber,
|
||||
$type)
|
||||
);
|
||||
|
||||
return $this->getFactureIdByFactureNumber($fullFactureNumber);
|
||||
|
||||
}
|
||||
|
||||
public function generateGroupFactureForMultipleDevis($devisToFacture,$paymentDate){
|
||||
$mentionsFilter = [
|
||||
DevisMentionConstant::NEW,
|
||||
DevisMentionConstant::MENTION
|
||||
];
|
||||
$devisIdListFiltered = $this->getDevisIdListFilteredByMentionAndDevisListId($mentionsFilter,$devisToFacture);
|
||||
$factureId = $this->createFactureAndReturnFactureId($paymentDate,FactureTypeConstant::TYPE_GROUP);
|
||||
$this->createFactureGroupForDevisList($factureId,$devisIdListFiltered);
|
||||
return [$factureId];
|
||||
}
|
||||
|
||||
public function getFactureTypeByFactureId($factureId): mixed{
|
||||
$sql = "SELECT
|
||||
facture.facture_type
|
||||
FROM ".$this->tableprefix."facture as facture
|
||||
WHERE facture.id = ? LIMIT 1;";
|
||||
|
||||
$result = $this->execSQLNoJsonReturn($sql,[$factureId]);
|
||||
if(!empty($result)){
|
||||
return $result[0]['facture_type'];
|
||||
}
|
||||
return FactureTypeConstant::TYPE_SINGLE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,385 @@
|
||||
<?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\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;
|
||||
|
||||
class InvoiceGroupPdfHandler extends FPDF {
|
||||
private $factureData = [];
|
||||
private $logo = null;
|
||||
|
||||
private $productsCount = 0;
|
||||
|
||||
private $totalPrices = [];
|
||||
private $devisCount = 0;
|
||||
private $logoPath = "/var/www/html/data/admin/files/.gestion/";
|
||||
|
||||
private $currentIndexPosition = 0;
|
||||
private $initialIndexPosition = 0;
|
||||
|
||||
private $devisCountToGet = 0;
|
||||
private $devisList = [];
|
||||
|
||||
private $thereIsOrderOrCaseNumber = false;
|
||||
private $startingYOfArticlesTable = 95;
|
||||
private const MAX_ARTICLES_PER_PAGE = 19;
|
||||
private $additionalArticlesLineBasedOnMultiline = 0;
|
||||
function Header()
|
||||
{
|
||||
if($this->logo != "nothing"){
|
||||
$this->Image($this->logoPath."logo.png", 2, 2, 50,35);
|
||||
}
|
||||
else{
|
||||
$this->Cell(55,30,'');
|
||||
}
|
||||
$this->SetMargins(3,0,3);
|
||||
$this->DrawInvoiceCompanyAndClientInfo();
|
||||
$this->DrawInvoiceInfoTable();
|
||||
}
|
||||
function Footer()
|
||||
{
|
||||
$this->SetY(-35);
|
||||
$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->factureData['configuration']->legal_one)), 0, 0, 'C');
|
||||
}
|
||||
|
||||
public function InvoicePdfFactory(array $factureData,$logo = null){
|
||||
$this->factureData = $factureData;
|
||||
$this->productsCount = $this->factureData["productsCount"];
|
||||
$this->devisCount = count($this->factureData['devis']);
|
||||
$this->totalPrices = $this->factureData["totalPrices"];
|
||||
$this->devisCountToGet = ($this->devisCount <= self::MAX_ARTICLES_PER_PAGE ) ? $this->devisCount : self::MAX_ARTICLES_PER_PAGE;
|
||||
$this->devisList = $this->factureData['devis'];
|
||||
$this->logo = $logo;
|
||||
}
|
||||
|
||||
public function GetInvoiceFilename(){
|
||||
$factureNum = $this->factureData['num'];
|
||||
$factureNum = str_replace('/','-',$factureNum);
|
||||
$clientName = str_replace(' ',' ',$this->factureData['group_name'] ?? '');
|
||||
return $this->factureData['configuration']->facture_prefixe.'_'.$factureNum.'_'.mb_strtoupper($clientName,'UTF-8');
|
||||
}
|
||||
|
||||
private function DrawPageNumbersText($pageNumber,$pageCount){
|
||||
$this->SetXY( 120, 5 );
|
||||
$this->Cell( 160, 8, $pageNumber . '/' . $pageCount, 0, 0, 'C');
|
||||
}
|
||||
|
||||
private function DrawArticlesTable(){
|
||||
$pageCount = ceil($this->devisCount / self::MAX_ARTICLES_PER_PAGE);
|
||||
$pageNumber = 1;
|
||||
while($pageNumber <= $pageCount){
|
||||
if($pageNumber > 1){
|
||||
$this->AddPage();
|
||||
$this->DrawPageNumbersText($pageNumber,$pageCount);
|
||||
}
|
||||
$this->DrawArticlesTableRect();
|
||||
$this->DrawArticlesTableHeader();
|
||||
$this->DrawArticlesTableValue();
|
||||
$pageNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
private function DrawInvoiceCompanyInfo(){
|
||||
$this->SetY(40);
|
||||
$this->SetFont('ComicSans', '', 10);
|
||||
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport($this->factureData['configuration']->entreprise), 0, 1);
|
||||
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse']), 0, 1);
|
||||
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse_city']), 0, 1);
|
||||
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->factureData['configuration']->telephone),0,1);
|
||||
$this->Cell(0, 5, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1);
|
||||
}
|
||||
private function DrawInvoiceClientInfo(){
|
||||
$this->SetFont('ComicSans', '', 10);
|
||||
$clientName = $this->factureData['group_name'];
|
||||
$clientInfoXAxis = 125;
|
||||
|
||||
$clientAddress = $this->factureData['client_real_adress'];
|
||||
$clientAdressWidth = $this->GetStringWidth($clientAddress);
|
||||
$maxWidth = $this->GetPageWidth();
|
||||
$availableWidhtForClientInfo = $maxWidth - 10 - $clientInfoXAxis;
|
||||
$clientAdressIsMultiline = $clientAdressWidth > $availableWidhtForClientInfo;
|
||||
|
||||
$clientInfoYAxis = $clientAdressIsMultiline ? 35 : 40;
|
||||
$this->SetXY($clientInfoXAxis,$clientInfoYAxis);
|
||||
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport($clientName));
|
||||
$clientInfoYAxis += 5;
|
||||
$this->SetXY($clientInfoXAxis,$clientInfoYAxis);
|
||||
$this->MultiCell( 0, 5, trim(FileExportHelpers::FormatTextForExport($clientAddress)));
|
||||
if($clientAdressIsMultiline){
|
||||
$clientInfoYAxis += 5;
|
||||
}
|
||||
$clientInfoYAxis += 5;
|
||||
$this->SetXY($clientInfoXAxis,$clientInfoYAxis);
|
||||
$this->Cell(0, 5, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city'])));
|
||||
$clientInfoYAxis += 5;
|
||||
$this->SetXY($clientInfoXAxis,$clientInfoYAxis);
|
||||
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . $this->factureData['siret']);
|
||||
$clientInfoYAxis += 5;
|
||||
$this->SetXY($clientInfoXAxis,$clientInfoYAxis);
|
||||
$this->Cell(0, 5, FileExportHelpers::FormatTextForExport('Mail : ') . $this->factureData['client_mail']);
|
||||
}
|
||||
|
||||
private function DrawInvoiceCompanyAndClientInfo(){
|
||||
$this->DrawInvoiceCompanyInfo();
|
||||
$this->DrawInvoiceClientInfo();
|
||||
}
|
||||
|
||||
private function DrawInvoiceInfoTable(){
|
||||
$this->setY(67);
|
||||
$factureDatePaiement = $this->factureData['date_paiement'];
|
||||
$factureDatePaiement = DateTime::createFromFormat('Y-m-d',$factureDatePaiement);
|
||||
$factureDateEcheance = $factureDatePaiement;
|
||||
$factureDatePaiement = $factureDatePaiement->format('d-m-Y');
|
||||
$factureDateEcheance->modify('last day of next month');
|
||||
$factureDateEcheance = $factureDateEcheance->format('d-m-Y');
|
||||
$this->SetFont('ComicSans', 'B', 11);
|
||||
$this->Cell(30, 7, 'DATE', 1, 0, 'C');
|
||||
$this->Cell(94, 7, 'CLIENT', 1, 0, 'C');
|
||||
$this->Cell(40, 7, 'FACTURE', 1, 0, 'C');
|
||||
$this->Cell(40, 7, 'ECHEANCE', 1, 1, 'C');
|
||||
|
||||
$this->SetFont('ComicSans', '', 10);
|
||||
$this->Cell(30, 7, $factureDatePaiement, 1, 0, 'C');
|
||||
$this->Cell(94, 7, utf8_decode(html_entity_decode($this->factureData['group_name'])), 1, 0, 'C');
|
||||
$this->Cell(40, 7, $this->factureData['num'], 1, 0, 'C');
|
||||
$this->Cell(40, 7, $factureDateEcheance, 1, 1, 'C');
|
||||
|
||||
$this->startingYOfArticlesTable = 85;
|
||||
}
|
||||
|
||||
private function DrawArticlesTableRect(){
|
||||
$this->SetLineWidth(0.2);
|
||||
$gapBetweenStartingOfArticlesTableAndColumnName = 10;
|
||||
$tableHeight = $this->thereIsOrderOrCaseNumber ? 137 : 137 + 10;
|
||||
$this->Rect(3, $this->startingYOfArticlesTable, 204, $tableHeight, "D");
|
||||
// cadre titre des colonnes
|
||||
$this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207,$this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName);
|
||||
// les traits verticaux colonnes
|
||||
$this->Line(35, $this->startingYOfArticlesTable, 35, 232);
|
||||
$this->Line(135, $this->startingYOfArticlesTable, 135, 232);
|
||||
$this->Line(160, $this->startingYOfArticlesTable, 160, 232);
|
||||
$this->Line(180, $this->startingYOfArticlesTable, 180, 232);
|
||||
}
|
||||
|
||||
private function DrawArticlesTableHeader(){
|
||||
$tvaValue = $this->factureData["configuration"]->tva_default;
|
||||
$columnNameY = $this->startingYOfArticlesTable + 1;
|
||||
$this->SetFont('ComicSans','',10);
|
||||
$this->SetXY( 9,$columnNameY );
|
||||
$this->Cell( 20, 8, "Date", 0, 0, 'C');
|
||||
|
||||
$this->SetXY( 35,$columnNameY );
|
||||
$this->Cell( 100, 8, "Description", 0, 0, 'C');
|
||||
|
||||
$this->SetXY( 138,$columnNameY );
|
||||
$this->Cell( 20, 8, "Prix Uni. HT", 0, 0, 'C');
|
||||
|
||||
$this->SetXY( 160,$columnNameY );
|
||||
$this->Cell( 20, 8, 'TVA ' . $tvaValue . '%', 0, 0, 'C');
|
||||
|
||||
$this->SetXY( 181,$columnNameY );
|
||||
$this->Cell( 25, 8, "Prix Uni. TTC", 0, 0, 'C');
|
||||
|
||||
}
|
||||
|
||||
public function DrawArticlesTableValue(){
|
||||
$this->SetFont('ComicSans','',10);
|
||||
$devisData = $this->factureData['devis'];
|
||||
$tvaValue = $this->factureData["configuration"]->tva_default;
|
||||
$totalHt = 0;
|
||||
$totalTtc = 0;
|
||||
$totalTva = 0;
|
||||
$yValue = $this->startingYOfArticlesTable + 11;
|
||||
$maxDescriptionWidth = 98;
|
||||
$currentIndexPosition = $this->currentIndexPosition;
|
||||
for($currentIndexPosition;$currentIndexPosition<($this->initialIndexPosition + $this->devisCountToGet);$currentIndexPosition++){
|
||||
$currentDevis = $devisData[$currentIndexPosition];
|
||||
$devisDate = $currentDevis['devis_date'];
|
||||
$devisDate = DateTime::createFromFormat('Y-m-d',$devisDate);
|
||||
$devisDate = $devisDate->format('d-m-Y');
|
||||
$products = $currentDevis["products"];
|
||||
foreach($products as $product){
|
||||
$valueHt = $product['produit_price'];
|
||||
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt,$tvaValue);
|
||||
$totalHt+=$valueHt;
|
||||
$totalTtc+=$valueTtc;
|
||||
$productDescription = $product["produit_description"] ?? "";
|
||||
$dateValue = "";
|
||||
if($product === end($products)){
|
||||
$dateValue = $devisDate;
|
||||
$productDescription .= " de " . $currentDevis["defunt_nom"] ?? "";
|
||||
}
|
||||
$productDescriptionWidth = $this->GetStringWidth($productDescription);
|
||||
$productDescriptionIsMultiline = $productDescriptionWidth > $maxDescriptionWidth;
|
||||
$tvaAmount = $valueTtc - $valueHt;
|
||||
$this->SetXY( 8,$yValue );
|
||||
$this->Cell(20, 6, $dateValue, 0,0);
|
||||
|
||||
$this->SetXY( 35,$yValue );
|
||||
$this->MultiAlignCell(100, 6, FileExportHelpers::FormatTextForExport($productDescription),0,'0',);
|
||||
|
||||
$this->SetXY( 138,$yValue );
|
||||
$this->Cell(20, 6, number_format($valueHt,2,'.','').chr(128), 0, 0, 'C');
|
||||
|
||||
$this->SetXY( 160,$yValue );
|
||||
$this->Cell(20, 6, number_format($tvaAmount,2,'.','').chr(128), 0, 0, 'C');
|
||||
|
||||
$this->SetXY( 181,$yValue );
|
||||
$this->Cell(25, 6, number_format($valueTtc,2,'.','').chr(128), 0, 1, 'C');
|
||||
$yValue += 6;
|
||||
$totalTva += $tvaAmount;
|
||||
if($productDescriptionIsMultiline){
|
||||
$yValue += 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->currentIndexPosition = $currentIndexPosition;
|
||||
$this->initialIndexPosition += $this->currentIndexPosition;
|
||||
$chargedDevisCount = $this->currentIndexPosition + 1;
|
||||
$devisLeftToGet = $this->devisCount - $chargedDevisCount;
|
||||
$this->devisCountToGet = ($devisLeftToGet <= self::MAX_ARTICLES_PER_PAGE) ? $devisLeftToGet + 1 : self::MAX_ARTICLES_PER_PAGE;
|
||||
}
|
||||
|
||||
private function DrawBankAndTotalPriceInfo(){
|
||||
$this->SetY(235);
|
||||
$this->SetFont('ComicSans', '', 7);
|
||||
$this->MultiCell(0,5,utf8_decode(html_entity_decode("Paiement à votre convenance par chèque à l'ordre de ". $this->factureData['configuration']->entreprise)));
|
||||
$this->MultiCell(0,5,utf8_decode(html_entity_decode("en indiquant le numéro de facture, ou par virement :")));
|
||||
|
||||
$this->Ln(1);
|
||||
|
||||
//Table IBAN
|
||||
$this->SetFont('ComicSans', '', 9);
|
||||
$ibanWidth = 90;
|
||||
$ibanCursorY = $this->GetY();
|
||||
$this->Cell($ibanWidth, 5, 'IBAN : FR76 1360 6000 1436 5418 1800 038', 1, 1, 'C');
|
||||
$ibanCursorX = $this->GetX();
|
||||
$this->Cell($ibanWidth, 5, 'Code SWIFT : AGRI FR PP 836', 1, 1, 'C');
|
||||
|
||||
//TABLE HT
|
||||
$ibanLastPositionX = $ibanCursorX+$ibanWidth + 54;
|
||||
$startOfArrayX = $ibanLastPositionX;
|
||||
$startOfArrayY = $ibanCursorY - 10;
|
||||
$totalPriceArray = $this->totalPrices;
|
||||
foreach($totalPriceArray as $label => $price){
|
||||
$this->SetXY($startOfArrayX,$startOfArrayY);
|
||||
$this->Cell(30, 5, $label, 1, 1, 'C');
|
||||
$this->SetXY($startOfArrayX + 30,$startOfArrayY);
|
||||
$this->Cell(30, 5, number_format($price,2,'.','').chr(128), 1, 1, 'C');
|
||||
$startOfArrayY += 5;
|
||||
}
|
||||
}
|
||||
|
||||
public function SetFactureContent(){
|
||||
$this->AddPage();
|
||||
$this->SetMargins(3,0,3);
|
||||
$this->DrawArticlesTable();
|
||||
$this->DrawBankAndTotalPriceInfo();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -27,9 +27,11 @@ declare(strict_types=1);
|
||||
namespace OCA\Gestion\Service;
|
||||
|
||||
use DateTime;
|
||||
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\Files\IRootFolder;
|
||||
|
||||
@ -73,7 +75,7 @@ class InvoicePdfService {
|
||||
return base64_encode($file->getContent());
|
||||
}
|
||||
|
||||
public function generateFacturePdfByFactureId($factureId,$idNextCloud){
|
||||
private function generateFactureSinglePdfByFactureId($factureId,$idNextCloud){
|
||||
$storage = $this->rootFolder->getUserFolder($idNextCloud);
|
||||
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
|
||||
$currentConfig = $configs[0];
|
||||
@ -106,6 +108,28 @@ class InvoicePdfService {
|
||||
}
|
||||
return $filenames;
|
||||
}
|
||||
|
||||
public function generateFacturePdfByFactureId($factureId,$idNextCloud){
|
||||
$factureType = $this->gestionBdd->getFactureTypeByFactureId($factureId);
|
||||
if($factureType == FactureTypeConstant::TYPE_SINGLE){
|
||||
return $this->generateFactureSinglePdfByFactureId($factureId,$idNextCloud);
|
||||
}
|
||||
else{
|
||||
return $this->generateFactureGroupPdfByFactureId($factureId,$idNextCloud);
|
||||
}
|
||||
}
|
||||
|
||||
private function getGroupFactureFolder(array $factureData,$racinePath){
|
||||
$clientRacineFolder = $racinePath.'CLIENTS/'.mb_strtoupper($factureData["group_name"],'UTF-8').'/';
|
||||
$factureDate = $factureData['date_paiement'];
|
||||
$factureDatetime = new DateTime($factureDate);
|
||||
$factureDateYear = $factureDatetime->format('Y');
|
||||
$factureMonth = DateHelpers::GetDateWithFormatDayAndMonthPlainString($factureData['date_paiement']);
|
||||
$factureByYearFolder = $clientRacineFolder."$factureDateYear".'/'.$factureMonth.'/'.'FACTURES'.'/';
|
||||
return [
|
||||
$factureByYearFolder
|
||||
];
|
||||
}
|
||||
|
||||
private function getFacturesFolder(array $factureData,$racinePath){
|
||||
$clientRacineFolder = $racinePath.'CLIENTS/'.mb_strtoupper($factureData["client_nom"],'UTF-8').'/';
|
||||
@ -121,6 +145,40 @@ class InvoicePdfService {
|
||||
];
|
||||
}
|
||||
|
||||
private function generateFactureGroupPdfByFactureId($factureId,$idNextCloud){
|
||||
$storage = $this->rootFolder->getUserFolder($idNextCloud);
|
||||
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
|
||||
$currentConfig = $configs[0];
|
||||
$logo = $this->getLogo();
|
||||
$invoicePdfData = $this->gestionBdd->getInvoiceGroupPdfData($factureId,$currentConfig);
|
||||
if($invoicePdfData == null){
|
||||
return "";
|
||||
}
|
||||
$clean_folder = html_entity_decode(string: $currentConfig->path).'/';
|
||||
$factureFolders = $this->getGroupFactureFolder($invoicePdfData,$clean_folder);
|
||||
$pdf = new InvoiceGroupPdfHandler();
|
||||
$pdf->AddFont('ComicSans','','Comic Sans MS.php');
|
||||
$pdf->AddFont('ComicSans','B','comic-sans-bold.php');
|
||||
$pdf->InvoicePdfFactory($invoicePdfData,$logo);
|
||||
$pdf->SetFactureContent();
|
||||
$pdfContent = $pdf->Output('','S');
|
||||
$pdfFilename = $pdf->GetInvoiceFilename();
|
||||
$filenames = [];
|
||||
foreach($factureFolders as $folder){
|
||||
try {
|
||||
$storage->newFolder($folder);
|
||||
}
|
||||
catch(\OCP\Files\NotPermittedException $e) {
|
||||
}
|
||||
$ff_pdf = $folder.$pdfFilename.'.pdf';
|
||||
$storage->newFile($ff_pdf);
|
||||
$file_pdf = $storage->get($ff_pdf);
|
||||
$file_pdf->putContent($pdfContent);
|
||||
$filenames[] = $ff_pdf;
|
||||
}
|
||||
return $filenames;
|
||||
}
|
||||
|
||||
public function generateFacturePdfByFactureIds(array $factureIds,$idNextCloud){
|
||||
foreach( $factureIds as $factureId ){
|
||||
$this->generateFacturePdfByFactureId($factureId,$idNextCloud);
|
||||
|
||||
8
gestion/lib/Sql/20250228-ADD_GROUP_DEVIS_FACTURE.sql
Normal file
8
gestion/lib/Sql/20250228-ADD_GROUP_DEVIS_FACTURE.sql
Normal file
@ -0,0 +1,8 @@
|
||||
create table if not exists oc_gestion_devis_facture (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
fk_devis_id INT NOT NULL,
|
||||
fk_facture_id INT NOT NULL
|
||||
);
|
||||
|
||||
alter table oc_gestion_facture
|
||||
add column facture_type VARCHAR(50) NOT NULL DEFAULT 'SINGLE';
|
||||
@ -48,9 +48,12 @@ $('body').on('click', '#invoiceQuote', function () {
|
||||
return;
|
||||
}
|
||||
|
||||
var factureTypeSelect = document.getElementById("factureTypeSelect");
|
||||
var selectedValue = factureTypeSelect.value;
|
||||
let devisToFacturePayload = {
|
||||
devisToFacture: devisToFacture,
|
||||
paymentDate: dateValue
|
||||
paymentDate: dateValue,
|
||||
type: selectedValue
|
||||
}
|
||||
|
||||
showLoader();
|
||||
|
||||
@ -61,6 +61,10 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="date" id="facturationDate">
|
||||
<select id="factureTypeSelect" name="type">
|
||||
<option value="SINGLE" selected>Simple</option>
|
||||
<option value="GROUP">Groupé</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="closeDevisModal" type="button" class="btn btn-secondary">Annuler</button>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user