Merge branch 'features/feature-order-pdf' into releases/release-h2f

This commit is contained in:
Tiavina 2025-02-11 16:08:45 +03:00
commit 5989a64c01
13 changed files with 522 additions and 369 deletions

View File

@ -164,6 +164,7 @@ return [
['name' => 'order#orderDetails', 'url' => '/order/{orderId}/details', 'verb' => 'GET'],
['name' => 'order#getOrderProductsById', 'url' => '/order/{orderId}/products', 'verb' => 'PROPFIND'],
['name' => 'order#getOrderTotalAmount', 'url' => '/order/{orderId}/totalAmount', 'verb' => 'PROPFIND'],
['name' => 'order#exportOrderToPdf', 'url' => '/order/{orderId}/exportToPdf', 'verb' => 'POST'],
//clients discount
['name' => 'page#getClientGroupDiscounts', 'url' => '/getClientGroupDiscounts', 'verb' => 'PROPFIND'],

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -25,12 +25,6 @@
* MIT Licensed
*/
/*!
* html2canvas 1.4.1 <https://html2canvas.hertzen.com>
* Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>
* Released under MIT License
*/
/*!
* jQuery JavaScript Library v3.6.3
* https://jquery.com/
@ -45,335 +39,8 @@
* Date: 2022-12-20T21:28Z
*/
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/*! @license DOMPurify 2.4.4 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.4.4/LICENSE */
/*! DataTables 1.13.2
* ©2008-2023 SpryMedia Ltd - datatables.net/license
*/
/**
* @license
Copyright (c) 2008, Adobe Systems Incorporated
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Adobe Systems Incorporated nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @license
*
* Copyright (c) 2014 James Robb, https://github.com/jamesbrobb
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* ====================================================================
*/
/**
* @license
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* @license
* (c) Dean McNamee <dean@gmail.com>, 2013.
*
* https://github.com/deanm/omggif
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* omggif is a JavaScript implementation of a GIF 89a encoder and decoder,
* including animation and compression. It does not rely on any specific
* underlying system, so should run in the browser, Node, or Plask.
*/
/**
* @license
* Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* @license
* Copyright (c) 2017 Aras Abbasi
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* @license
* Copyright (c) 2018 Aras Abbasi
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* @license
* Copyright (c) 2019 Aras Abbasi
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* @license
* FPDF is released under a permissive license: there is no usage restriction.
* You may embed it freely in your application (commercial or not), with or
* without modifications.
*
* Reference: http://www.fpdf.org/en/script/script37.php
*/
/**
* @license
* Joseph Myers does not specify a particular license for his work.
*
* Author: Joseph Myers
* Accessed from: http://www.myersdaily.org/joseph/javascript/md5.js
*
* Modified by: Owen Leong
*/
/**
* @license
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
* Author: Owen Leong (@owenl131)
* Date: 15 Oct 2020
* References:
* https://www.cs.cmu.edu/~dst/Adobe/Gallery/anon21jul01-pdf-encryption.txt
* https://github.com/foliojs/pdfkit/blob/master/lib/security.js
* http://www.fpdf.org/en/script/script37.php
*/
/**
* @license
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* @license
* Unicode Bidi Engine based on the work of Alex Shensis (@asthensis)
* MIT License
*/
/**
* @license
* jsPDF fileloading PlugIn
* Copyright (c) 2018 Aras Abbasi (aras.abbasi@gmail.com)
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* @license
* jsPDF filters PlugIn
* Copyright (c) 2014 Aras Abbasi
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* @license
* jsPDF virtual FileSystem functionality
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* A class to parse color values
* @author Stoyan Stefanov <sstoo@gmail.com>
* {@link http://www.phpied.com/rgb-color-parser-in-javascript/}
* @license Use it if you like it
*/
/** ====================================================================
* @license
* jsPDF XMP metadata plugin
* Copyright (c) 2016 Jussi Utunen, u-jussi@suomi24.fi
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* ====================================================================
*/
/** @license
* Copyright (c) 2017 Dominik Homberger
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
https://webpjs.appspot.com
WebPRiffParser dominikhlbg@gmail.com
*/
/** @license
*
* jsPDF - PDF Document creation from JavaScript
* Version 2.5.1 Built on 2022-01-28T15:37:57.791Z
* CommitID 00000000
*
* Copyright (c) 2010-2021 James Hall <james@parall.ax>, https://github.com/MrRio/jsPDF
* 2015-2021 yWorks GmbH, http://www.yworks.com
* 2015-2021 Lukas Holländer <lukas.hollaender@yworks.com>, https://github.com/HackbrettXXX
* 2016-2018 Aras Abbasi <aras.abbasi@gmail.com>
* 2010 Aaron Spike, https://github.com/acspike
* 2012 Willow Systems Corporation, https://github.com/willowsystems
* 2012 Pablo Hess, https://github.com/pablohess
* 2012 Florian Jenett, https://github.com/fjenett
* 2013 Warren Weckesser, https://github.com/warrenweckesser
* 2013 Youssef Beddad, https://github.com/lifof
* 2013 Lee Driscoll, https://github.com/lsdriscoll
* 2013 Stefan Slonevskiy, https://github.com/stefslon
* 2013 Jeremy Morel, https://github.com/jmorel
* 2013 Christoph Hartmann, https://github.com/chris-rock
* 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
* 2014 James Makes, https://github.com/dollaruw
* 2014 Diego Casorran, https://github.com/diegocr
* 2014 Steven Spungin, https://github.com/Flamenco
* 2014 Kenneth Glassey, https://github.com/Gavvers
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Contributor(s):
* siefkenj, ahwolf, rickygu, Midnith, saintclair, eaparango,
* kim3er, mfo, alnorth, Flamenco
*/
/** @license
* Copyright (c) 2012 Willow Systems Corporation, https://github.com/willowsystems
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* ====================================================================
*/

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,7 @@ namespace OCA\Gestion\Controller;
use Exception;
use OCA\Gestion\Service\ConfigurationService;
use OCA\Gestion\Service\NavigationService;
use OCA\Gestion\Service\Order\OrderPdfService;
use OCA\Gestion\Service\Order\OrderService;
use Psr\Log\LoggerInterface;
defined("TAB1") or define("TAB1", "\t");
@ -45,6 +46,7 @@ class OrderController extends Controller {
/** @var \OCA\Gestion\Service\NavigationService */
private $navigationService;
private $configurationService;
private $orderPdfService;
private $logger;
@ -64,7 +66,8 @@ class OrderController extends Controller {
OrderService $orderService,
NavigationService $navigationService,
ConfigurationService $configurationService,
LoggerInterface $logger
LoggerInterface $logger,
OrderPdfService $orderPdfService
){
parent::__construct($AppName, $request);
@ -78,6 +81,7 @@ class OrderController extends Controller {
$this->navigationService = $navigationService;
$this->configurationService = $configurationService;
$this->logger = $logger;
$this->orderPdfService = $orderPdfService;
if ($userSession->isLoggedIn()) {
$this->user = $userSession->getUser();
@ -231,4 +235,17 @@ class OrderController extends Controller {
$orderTotalAmount = $this->orderService->getOrderTotalAmount($orderId,$configuration["tva_default"] ?? 0);
return json_encode($orderTotalAmount);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param string $orderId
*/
public function exportOrderToPdf($orderId) {
try{
$factureFilenames = $this->orderPdfService->generateOrderPdfByOrderId($orderId,$this->idNextcloud);
return json_encode($factureFilenames);
}
catch(\OCP\Files\NotFoundException $e) { }
}
}

View File

@ -338,6 +338,7 @@ class OrderBdd {
client.legal_one as client_legal_one,
defunt.id as defunt_id,
defunt.nom as defunt_nom,
defunt.sexe as defunt_sexe,
lieu.id as lieu_id,
lieu.adresse as lieu_adresse,
lieu.nom as lieu_nom,

View File

@ -36,7 +36,7 @@ use OCA\Gestion\Helpers\PriceHelpers;
class InvoicePdfHandler extends FPDF {
private $multipleFactureData = [];
private $factureData = [];
private $orderData = [];
private $logo = null;
private $logoPath = "/var/www/html/data/admin/files/.gestion/";
function Header()
@ -59,11 +59,11 @@ class InvoicePdfHandler extends FPDF {
$this->SetY(-15);
$this->SetFont('Arial', 'B', 8);
$this->Cell(0, 10, utf8_decode(html_entity_decode($this->factureData['configuration']->legal_one)), 0, 0, 'C');
$this->Cell(0, 10, utf8_decode(html_entity_decode($this->orderData['configuration']->legal_one)), 0, 0, 'C');
}
public function InvoicePdfFactory(array $factureData,$logo = null){
$this->factureData = $factureData;
$this->orderData = $factureData;
$this->logo = $logo;
}
@ -84,32 +84,32 @@ class InvoicePdfHandler extends FPDF {
}
public function GetInvoiceFilename(){
$factureNum = $this->factureData['num'];
$factureNum = $this->orderData['num'];
$factureNum = str_replace('/','-',$factureNum);
$defuntNom = str_replace('&nbsp;',' ',$this->factureData['defunt_nom']);
return $this->factureData['configuration']->facture_prefixe.'_'.$factureNum.'_'.mb_strtoupper($defuntNom,'UTF-8');
$defuntNom = str_replace('&nbsp;',' ',$this->orderData['defunt_nom']);
return $this->orderData['configuration']->facture_prefixe.'_'.$factureNum.'_'.mb_strtoupper($defuntNom,'UTF-8');
}
private function DrawInvoiceCompanyAndClientInfo(){
$this->SetY(40);
$this->SetFont('Arial', '', 12);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['configuration']->entreprise), 0, 0);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->orderData['configuration']->entreprise), 0, 0);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport(
$this->factureData['client_prenom']. ' '.$this->factureData['client_nom']),
$this->orderData['client_prenom']. ' '.$this->orderData['client_nom']),
0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse']), 0, 0);
$this->Cell(0, 7, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_real_adress'])), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse_city']), 0, 0);border:
$this->Cell(0, 7, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city'])), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->factureData['configuration']->telephone),0,0);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . $this->factureData['siret'], 0, 1,'R');
$this->Cell(0, 7, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->orderData['configuration_adresse']), 0, 0);
$this->Cell(0, 7, trim(FileExportHelpers::FormatTextForExport($this->orderData['client_real_adress'])), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->orderData['configuration_adresse_city']), 0, 0);border:
$this->Cell(0, 7, trim(FileExportHelpers::FormatTextForExport($this->orderData['client_adress_city'])), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->orderData['configuration']->telephone),0,0);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . $this->orderData['siret'], 0, 1,'R');
$this->Cell(0, 7, 'Mail : ' . $this->orderData['configuration']->mail, 0, 1);
$this->Ln(3);
}
private function DrawInvoiceInfoTable(){
$factureDatePaiement = $this->factureData['date_paiement'];
$factureDatePaiement = $this->orderData['date_paiement'];
$factureDatePaiement = DateTime::createFromFormat('Y-m-d',$factureDatePaiement);
$factureDatePaiement = $factureDatePaiement->format('d-m-Y');
$factureDateEcheance = $factureDatePaiement;
@ -121,13 +121,13 @@ class InvoicePdfHandler extends FPDF {
$this->SetFont('Arial', '', 10);
$this->Cell(30, 7, $factureDatePaiement, 1, 0, 'C');
$this->Cell(80, 7, utf8_decode(html_entity_decode($this->factureData['lieu_nom'])), 1, 0, 'C');
$this->Cell(40, 7, $this->factureData['num'], 1, 0, 'C');
$this->Cell(80, 7, utf8_decode(html_entity_decode($this->orderData['lieu_nom'])), 1, 0, 'C');
$this->Cell(40, 7, $this->orderData['num'], 1, 0, 'C');
$this->Cell(40, 7, $factureDateEcheance, 1, 1, 'C');
$this->Ln(4);
$devisComment = ($this->factureData['devis_comment'] == "Commentaire" || $this->factureData['devis_comment'] == "" ? "" : $this->factureData['devis_comment']);
$devisComment = ($this->orderData['devis_comment'] == "Commentaire" || $this->orderData['devis_comment'] == "" ? "" : $this->orderData['devis_comment']);
if($devisComment != ""){
$this->SetFont('Arial', 'B', 9);
$this->Cell(0,5,"Bon de commande: ". $devisComment,0,1,'C');
@ -147,7 +147,7 @@ class InvoicePdfHandler extends FPDF {
}
private function DrawArticlesTableHeader(){
$tvaValue = $this->factureData["configuration"]->tva_default;
$tvaValue = $this->orderData["configuration"]->tva_default;
$this->SetFont('Arial','',10);
$this->SetXY( 10,106 );
$this->Cell( 20, 8, "Date", 0, 0, 'C');
@ -168,14 +168,14 @@ class InvoicePdfHandler extends FPDF {
public function DrawArticlesTableValueAndReturnTotalPrice(){
$this->SetFont('Arial','',10);
$devisDate = $this->factureData['devis_date'];
$devisDate = $this->orderData['devis_date'];
$devisDate = DateTime::createFromFormat('Y-m-d',$devisDate);
$devisDate = $devisDate->format('d-m-Y');
$tvaValue = $this->factureData["configuration"]->tva_default;
$tvaValue = $this->orderData["configuration"]->tva_default;
$totalHt = 0;
$totalTtc = 0;
$totalTva = 0;
$products = $this->factureData["products"];
$products = $this->orderData["products"];
$yValue = 116;
foreach($products as $product){
$valueHt = $product['produit_price'];
@ -186,7 +186,7 @@ class InvoicePdfHandler extends FPDF {
$dateValue = "";
if($product === end($products)){
$dateValue = $devisDate;
$productDescription .= " de " . FileExportHelpers::GetSexeLabel($this->factureData['defunt_sexe']) . ' '. $this->factureData["defunt_nom"];
$productDescription .= " de " . FileExportHelpers::GetSexeLabel($this->orderData['defunt_sexe']) . ' '. $this->orderData["defunt_nom"];
}
$tvaAmount = $valueTtc - $valueHt;
$this->SetXY( 10,$yValue );
@ -218,7 +218,7 @@ class InvoicePdfHandler extends FPDF {
$this->SetY(210);
$this->SetFont('Arial', '', 9);
$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("Paiement à votre convenance par chèque à l'ordre de ". $this->orderData['configuration']->entreprise)));
$this->MultiCell(0,5,utf8_decode(html_entity_decode("en indiquant le numéro de facture, ou par virement :")));
$this->Ln(1);
@ -246,7 +246,7 @@ class InvoicePdfHandler extends FPDF {
public function SetMultipleFactureContent(){
foreach($this->multipleFactureData as $factureData){
$this->factureData = $factureData;
$this->orderData = $factureData;
$this->SetFactureContent();
}
}

View File

@ -0,0 +1,139 @@
<?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\Order;
use DateTime;
use OCA\Gestion\Constants\BddConstant;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Db\OrderBdd;
use OCA\Gestion\Helpers\DateHelpers;
use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Service\Order\PdfHandler\OrderPdfHandler;
use OCP\Files\IRootFolder;
class OrderPdfService {
/** @var Bdd */
private $gestionBdd;
/** @var IRootFolder */
private $rootFolder;
private $orderBdd;
private $orderService;
public function __construct(
Bdd $gestionBdd,
IRootFolder $rootFolder,
OrderBdd $orderBdd,
OrderService $orderService) {
$this->orderBdd = $orderBdd;
$this->gestionBdd = $gestionBdd;
$this->rootFolder = $rootFolder;
$this->orderService = $orderService;
}
private function doesLogoExist(){
$storage = $this->rootFolder->getUserFolder(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
try {
if(isset($storage)){
$storage->get('/.gestion/logo.png');
return true;
}else{
return false;
}
}
catch(\OCP\Files\NotFoundException $e) {
return false;
}
}
private function formatOrderDataForPdfExport($orderPdfData,$config){
$orderPdfData["configuration"] = $config;
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($config->adresse);
$orderPdfData["configuration_adresse"] = $configurationAdresses["address"];
$orderPdfData["configuration_adresse_city"] = $configurationAdresses["city"];
$orderDate = $orderPdfData['order_date'];
$orderDate = DateTime::createFromFormat('Y-m-d',$orderDate);
$orderDate = $orderDate->format('d-m-Y');
$orderPdfData['order_date'] = $orderDate;
return $orderPdfData;
}
private function getCommandeFolders($orderPdfData,$racinePath){
$clientRacineFolder = $racinePath.'CLIENTS/'.mb_strtoupper($orderPdfData["client_entreprise"],'UTF-8').'/';
$defuntsFolder = $clientRacineFolder.'DEFUNTS/'.mb_strtoupper($orderPdfData['defunt_nom'],'UTF-8').'/'.'FOURNISSEUR'.'/';
$orderDate = $orderPdfData['order_date'];
$orderDatetime = new DateTime($orderDate);
$orderYear = $orderDatetime->format('Y');
$orderMonth = DateHelpers::GetDateWithFormatDayAndMonthPlainString($orderPdfData['order_date']);
$orderByYearFolder = $clientRacineFolder."$orderYear".'/'.$orderMonth.'/'.'FOURNISSEUR'.'/';
return [
$defuntsFolder,
$orderByYearFolder
];
}
private function GetOrderFilename($orderPdfData){
$orderFullNumber = $orderPdfData['order_full_number'];
$orderFullNumber = str_replace('/','-',$orderFullNumber);
$defuntNom = str_replace('&nbsp;',' ',$orderPdfData['defunt_nom']);
return "BDC".'_'.$orderFullNumber.'_'.mb_strtoupper($defuntNom,'UTF-8');
}
public function generateOrderPdfByOrderId($orderId,$idNextCloud){
$storage = $this->rootFolder->getUserFolder($idNextCloud);
$configs = json_decode($this->gestionBdd->getConfiguration(BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD));
$currentConfig = $configs[0];
$logoExist = $this->doesLogoExist();
$orderPdfData = $this->orderService->getOrderPdfData($orderId);
if($orderPdfData == null){
return "";
}
$orderPdfData = $this->formatOrderDataForPdfExport($orderPdfData,$currentConfig);
$racineFolder = html_entity_decode(string: $currentConfig->path).'/';
$orderFolders = $this->getCommandeFolders($orderPdfData,$racineFolder);
$pdf = new OrderPdfHandler();
$pdf->OrderPdfFactory($orderPdfData,$logoExist);
$pdf->SetOrderContent();
$pdfContent = $pdf->Output('','S');
$pdfFilename = $this->GetOrderFilename($orderPdfData);
$filenames = [];
foreach($orderFolders 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;
}
}

View File

@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OCA\Gestion\Service\Order;
use OCA\Gestion\Db\OrderBdd;
use OCA\Gestion\Helpers\FileExportHelpers;
use Psr\Log\LoggerInterface;
class OrderService {
@ -95,4 +96,17 @@ class OrderService {
public function getOrderTotalAmount($orderId,$tva){
return $this->orderBdd->getOrderTotalAmount($orderId,$tva);
}
public function getOrderPdfData($orderId){
$orderDetails = $this->orderBdd->getOrderByIdWithDetails($orderId);
if($orderDetails == null){
return null;
}
$orderProducts = $this->orderBdd->getOrderProductsByOrderId($orderId);
$orderDetails["products"] = $orderProducts;
$clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($orderDetails["client_adresse"]);
$orderDetails["client_real_adress"] = $clientAdresses["address"];
$orderDetails["client_adress_city"] = $clientAdresses["city"];
return $orderDetails;
}
}

View File

@ -0,0 +1,289 @@
<?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\Order\PdfHandler;
use DateTime;
use \FPDF;
use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Helpers\PriceHelpers;
class OrderPdfHandler extends FPDF {
private $orderData = [];
private $logoExist = false;
private $logoPath = "/var/www/html/data/admin/files/.gestion/";
private const DEFAULT_SUBCONTRACTOR_NAME = "SOUS TRAITANT";
function Header()
{
if($this->logoExist){
$this->Image($this->logoPath."logo.png", 10, 10, 50, 25);
}
else{
$this->Cell(55,30,'');
}
}
function Footer()
{
$this->SetY(-40);
$this->SetFont('Arial', '', 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('Arial', 'B', 8);
$this->Cell(0, 10, utf8_decode(html_entity_decode($this->orderData['configuration']->legal_one)), 0, 0, 'C');
}
public function OrderPdfFactory(array $factureData,$logoExist = false){
$this->orderData = $factureData;
$this->logoExist = $logoExist;
}
private function DrawOrderCompanyAndClientInfo(){
$this->SetY(40);
$this->SetFont('Arial', '', 12);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->orderData['configuration']->entreprise), 0, 0);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport(
self::DEFAULT_SUBCONTRACTOR_NAME),
0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->orderData['configuration_adresse']), 0, 0);
$this->Cell(0, 7, trim(FileExportHelpers::FormatTextForExport($this->orderData['client_real_adress'])), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->orderData['configuration_adresse_city']), 0, 0);border:
$this->Cell(0, 7, trim(FileExportHelpers::FormatTextForExport($this->orderData['client_adress_city'])), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->orderData['configuration']->telephone),0,0);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . $this->orderData['client_legal_one'], 0, 1,'R');
$this->Cell(0, 7, 'Mail : ' . $this->orderData['configuration']->mail, 0, 0);
$this->Cell(0, 7, 'Mail : ' . FileExportHelpers::FormatTextForExport($this->orderData['client_mail']), 0, 1,'R');
$this->Ln(3);
}
private function DrawOrderInfoTable(){
$this->SetFont('Arial', 'B', 11);
$this->Cell(45, 7, 'DATE DU COMMANDE', 1, 0, 'C');
$this->Cell(65, 7, 'LIEU', 1, 0, 'C');
$this->Cell(40, 7, 'COMMANDE', 1, 0, 'C');
$this->Cell(40, 7, 'DATE DE SOINS', 1, 1, 'C');
$this->SetFont('Arial', '', 10);
$this->Cell(45, 7, $this->orderData["order_date"], 1, 0, 'C');
$this->Cell(65, 7, utf8_decode(html_entity_decode($this->orderData['lieu_nom'])), 1, 0, 'C');
$this->Cell(40, 7, $this->orderData['order_full_number'], 1, 0, 'C');
$this->Cell(40, 7, $this->orderData["order_date"], 1, 1, 'C');
$this->Ln(4);
}
private function DrawArticlesTable(){
$this->SetLineWidth(0.1);
$this->Rect(10, 105, 190, 100, "D");
// cadre titre des colonnes
$this->Line(10, 115, 200,115);
// les traits verticaux colonnes
$this->Line(35, 105, 35, 205);
$this->Line(135, 105, 135, 205);
$this->Line(155, 105, 155, 205);
$this->Line(175, 105, 175, 205);
}
private function DrawArticlesTableHeader(){
$tvaValue = $this->orderData["configuration"]->tva_default;
$this->SetFont('Arial','',10);
$this->SetXY( 10,106 );
$this->Cell( 20, 8, "Date", 0, 0, 'C');
$this->SetXY( 35,106 );
$this->Cell( 100, 8, "Description", 0, 0, 'C');
$this->SetXY( 135,106 );
$this->Cell( 20, 8, "Prix Uni. HT", 0, 0, 'C');
$this->SetXY( 155,106 );
$this->Cell( 20, 8, 'TVA ' . $tvaValue . '%', 0, 0, 'C');
$this->SetXY( 175,106 );
$this->Cell( 25, 8, "Prix Uni. TTC", 0, 0, 'C');
}
public function DrawArticlesTableValueAndReturnTotalPrice(){
$this->SetFont('Arial','',10);
$tvaValue = $this->orderData["configuration"]->tva_default;
$totalHt = 0;
$totalTtc = 0;
$totalTva = 0;
$products = $this->orderData["products"];
$yValue = 116;
foreach($products as $product){
$valueHt = $product['produit_ht_price'];
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt,$tvaValue);
$totalHt+=$valueHt;
$totalTtc+=$valueTtc;
$productDescription = $product["produit_description"];
$dateValue = "";
if($product === end($products)){
$dateValue = $this->orderData["order_date"];
$productDescription .= " de " . FileExportHelpers::GetSexeLabel($this->orderData['defunt_sexe']) . ' '. $this->orderData["defunt_nom"];
}
$tvaAmount = $valueTtc - $valueHt;
$this->SetXY( 10,$yValue );
$this->Cell(20, 6, $dateValue, 0,0);
$this->SetXY( 35,$yValue );
$this->MultiAlignCell(100, 6, utf8_decode(html_entity_decode($productDescription)),0,'0',);
$this->SetXY( 135,$yValue );
$this->Cell(20, 6, number_format($valueHt,2,'.','').chr(128), 0, 0, 'C');
$this->SetXY( 155,$yValue );
$this->Cell(20, 6, number_format($tvaAmount,2,'.','').chr(128), 0, 0, 'C');
$this->SetXY( 175,$yValue );
$this->Cell(25, 6, number_format($valueTtc,2,'.','').chr(128), 0, 1, 'C');
$yValue += 12;
$totalTva += $tvaAmount;
}
return [
"TOTAL HT" => $totalHt,
"TVA ".$tvaValue. "%" => $totalTva,
"TOTAL TTC" => $totalTtc
];
}
private function DrawBankAndTotalPriceInfo($totalPriceArray){
$this->SetY(210);
$this->SetFont('Arial', '', 9);
$this->MultiCell(0,5,utf8_decode(html_entity_decode("Paiement à votre convenance par chèque à l'ordre de ". $this->orderData['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('Arial', '', 11);
$ibanWidth = 90;
$ibanCursorY = $this->GetY();
$this->Cell($ibanWidth, 7, 'IBAN : FR76 3000 3030 7700 0200 2057 074', 1, 1, 'C');
$ibanCursorX = $this->GetX();
$this->Cell($ibanWidth, 7, 'Code SWIFT : SOGEFRPP', 1, 1, 'C');
//TABLE HT
$ibanLastPositionX = $ibanCursorX+$ibanWidth + 20;
$startOfArrayX = $ibanLastPositionX;
$startOfArrayY = $ibanCursorY;
foreach($totalPriceArray as $label => $price){
$this->SetXY($startOfArrayX,$startOfArrayY);
$this->Cell(40, 7, $label, 1, 1, 'C');
$this->SetXY($startOfArrayX + 40,$startOfArrayY);
$this->Cell(40, 7, number_format($price,2,'.','').chr(128), 1, 1, 'C');
$startOfArrayY += 7;
}
}
public function SetOrderContent(){
$this->AddPage();
$this->SetMargins(10,0,10);
$this->DrawOrderCompanyAndClientInfo();
$this->DrawOrderInfoTable();
$this->DrawArticlesTable();
$this->DrawArticlesTableHeader();
$totalPriceValue = $this->DrawArticlesTableValueAndReturnTotalPrice();
$this->DrawBankAndTotalPriceInfo($totalPriceValue);
}
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;
}
}

View File

@ -3,6 +3,8 @@ import { Order } from "../objects/order.mjs";
import { updateOrderDate } from "../modules/order/orderAjaxRequest.mjs";
import { Thanatopracteur } from "../objects/thanatopracteur.mjs";
import { ThanatoSubcontractorTypeKey } from "../constants/thanatoTypeConstant";
import { hideLoader, showLoader,baseUrl } from "../modules/mainFunction.mjs";
import { showError, showSuccess } from "@nextcloud/dialogs";
$('body').on('change', '.orderInputDate', function () {
var dt = new DataTable('.tabledt');
@ -21,4 +23,31 @@ document.body.addEventListener('click', e => {
Order.createDefaultOrder(new DataTable('.tabledt'));
return;
}
});
});
$('body').on('click', '#exportOrderToPdf', function () {
var orderIdentifier = $('#orderId').data('id');
showLoader();
$.ajax({
url: baseUrl + '/order/'+orderIdentifier+'/exportToPdf',
type: 'POST',
contentType: 'application/json'
}).done(function (response) {
if(response != null){
var fileNames = JSON.parse(response);
fileNames.forEach(fileName => {
showSuccess('Sauvegardé dans' + fileName);
});
}
else{
showError(t('gestion', "Erreur dans la génération de pdf pour cette commande"));
}
}).fail(function (response, code) {
showError(t('gestion', "Erreur dans la génération de pdf pour cette commande"));
}).always(function () {
hideLoader();
});
});

View File

@ -1,13 +1,9 @@
import "@nextcloud/dialogs/dist/index.css";
import "datatables.net-dt/css/jquery.dataTables.css";
import "../css/mycss.css";
import { getArticlesById, getMailServerFrom, getProduitsById, savePdfToNextcloud,exportDevisToPdf} from "./modules/ajaxRequest.mjs";
import { globalConfiguration } from "./modules/mainFunction.mjs";
import "./listener/main_listener";
import { Client } from "./objects/client.mjs";
import { capture, sendMail, captureDevisFacture } from "./pdf";
import { showError } from "@nextcloud/dialogs";
import "./listener/orderListener";
import { getOrderProductsByOrderId } from "./modules/order/orderAjaxRequest.mjs";
window.addEventListener("DOMContentLoaded", function () {