Merge branch 'features/feature-save-in-nextcloud-from-backend' into staging

This commit is contained in:
Tiavina 2024-12-30 21:22:11 +03:00
commit 14c5ec7232
25 changed files with 55 additions and 58 deletions

View File

@ -31,7 +31,6 @@ return [
['name' => 'page#getThanatopracteurs', 'url' => '/getThanatopracteurs', 'verb' => 'PROPFIND'], ['name' => 'page#getThanatopracteurs', 'url' => '/getThanatopracteurs', 'verb' => 'PROPFIND'],
['name' => 'page#insertThanatopracteur', 'url' => '/thanatopracteur/insert', 'verb' => 'POST'], ['name' => 'page#insertThanatopracteur', 'url' => '/thanatopracteur/insert', 'verb' => 'POST'],
['name' => 'page#exportThanatoStatistic', 'url' => '/thanatopracteur/exportThanatoStatistic', 'verb' => 'POST'], ['name' => 'page#exportThanatoStatistic', 'url' => '/thanatopracteur/exportThanatoStatistic', 'verb' => 'POST'],
['name' => 'page#generateSamplePdf', 'url' => '/generateSamplePdf', 'verb' => 'POST'],
['name' => 'page#getDevis', 'url' => '/getDevis', 'verb' => 'PROPFIND'], ['name' => 'page#getDevis', 'url' => '/getDevis', 'verb' => 'PROPFIND'],
['name' => 'page#getDevisDelphine', 'url' => '/getDevisDelphine/{idtrajetdetails}', 'verb' => 'PROPFIND'], ['name' => 'page#getDevisDelphine', 'url' => '/getDevisDelphine/{idtrajetdetails}', 'verb' => 'PROPFIND'],
@ -65,6 +64,7 @@ return [
['name' => 'page#apercustousdevis', 'url' => '/devis/apercus', 'verb' => 'GET'], ['name' => 'page#apercustousdevis', 'url' => '/devis/apercus', 'verb' => 'GET'],
['name' => 'page#insertFacture', 'url' => '/facture/insert', 'verb' => 'POST'], ['name' => 'page#insertFacture', 'url' => '/facture/insert', 'verb' => 'POST'],
['name' => 'page#exportDevisToFacture', 'url' => '/exportDevisToFacture', 'verb' => 'POST'], ['name' => 'page#exportDevisToFacture', 'url' => '/exportDevisToFacture', 'verb' => 'POST'],
['name' => 'page#exportFactureToPdf', 'url' => '/facture/exportFactureToPdf', 'verb' => 'POST'],
['name' => 'page#getProduits', 'url' => '/getProduits', 'verb' => 'PROPFIND'], ['name' => 'page#getProduits', 'url' => '/getProduits', 'verb' => 'PROPFIND'],
['name' => 'page#getProduitsById', 'url' => '/getProduitsById', 'verb' => 'POST'], ['name' => 'page#getProduitsById', 'url' => '/getProduitsById', 'verb' => 'POST'],

View File

@ -2638,37 +2638,10 @@ class PageController extends Controller {
* *
*/ */
public function generateSamplePdf($factureId){ public function exportFactureToPdf($factureId){
$factureId = 1;
$configs = json_decode($this->myDb->getConfiguration($this->idNextcloud));
$currentConfig = $configs[0];
$logo = $this->getLogo();
$invoicePdfData = $this->myDb->getInvoicePdfData($factureId,$currentConfig);
if($invoicePdfData == null){
return "";
}
try{ try{
$clean_folder = html_entity_decode($currentConfig->path).'/'; $factureFilenames = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->idNextcloud);
$_clean_folder = $clean_folder.'SAMPLES/'; return json_encode($factureFilenames);
try {
$this->storage->newFolder($_clean_folder);
}
catch(\OCP\Files\NotPermittedException $e) {
}
$pdf = new InvoicePdfHandler();
$pdf->InvoicePdfFactory($invoicePdfData,$logo);
$pdfContent = $pdf->GetFactureContent();
$pdf->Output();
$ff_pdf = $_clean_folder.Uuid::uuid4()->toString().'.pdf';
$this->storage->newFile($ff_pdf);
$file_pdf = $this->storage->get($ff_pdf);
$file_pdf->putContent($pdfContent);
$res = array();
$res['path'] = $_clean_folder;
return json_encode($res);
} }
catch(\OCP\Files\NotFoundException $e) { } catch(\OCP\Files\NotFoundException $e) { }

View File

@ -62,7 +62,8 @@ class InvoicePdfHandler extends FPDF {
public function GetFilename(){ public function GetFilename(){
$factureNum = $this->factureData['num']; $factureNum = $this->factureData['num'];
$factureNum = str_replace('/','-',$factureNum); $factureNum = str_replace('/','-',$factureNum);
return $this->factureData['configuration']->facture_prefixe.'_'.$factureNum.'_'.strtoupper($this->factureData['defunt_nom']); $defuntNom = str_replace(' ',' ',$this->factureData['defunt_nom']);
return $this->factureData['configuration']->facture_prefixe.'_'.$factureNum.'_'.strtoupper($defuntNom);
} }
public function GetFactureContent(){ public function GetFactureContent(){

View File

@ -86,15 +86,14 @@ class InvoicePdfService {
foreach($factureFolders as $folder){ foreach($factureFolders as $folder){
try { try {
$this->storage->newFolder($folder); $this->storage->newFolder($folder);
$ff_pdf = $folder.$pdfFilename.'.pdf';
$this->storage->newFile($ff_pdf);
$file_pdf = $this->storage->get($ff_pdf);
$file_pdf->putContent($pdfContent);
$filenames[] = $ff_pdf;
} }
catch(\OCP\Files\NotPermittedException $e) { catch(\OCP\Files\NotPermittedException $e) {
} }
$ff_pdf = $folder.$pdfFilename.'.pdf';
$this->storage->newFile($ff_pdf);
$file_pdf = $this->storage->get($ff_pdf);
$file_pdf->putContent($pdfContent);
$filenames[] = $ff_pdf;
} }
return $filenames; return $filenames;
} }

View File

@ -487,3 +487,26 @@ $('body').on('click', '#exportClientStat', function () {
}); });
$('body').on('click', '#exportFactureToPdf', function () {
var factureIdentifier = $('#factureIdentifier').data('id');
var exportFacturePayload = {
factureId: factureIdentifier
};
$.ajax({
url: baseUrl + '/facture/exportFactureToPdf',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(exportFacturePayload)
}).done(function (response) {
var fileNames = JSON.parse(response);
fileNames.forEach(fileName => {
showSuccess('Sauvegardé dans' + fileName);
});
}).fail(function (response, code) {
showError(t('gestion', "Please create a new hypodermique"));
});
});

View File

@ -2,6 +2,7 @@
<div class="d-flex flex-column w-100"> <div class="d-flex flex-column w-100">
<h2 class="mt-3 mb-3 text-center"><?php p($l->t('Invoice #'));?> <h2 class="mt-3 mb-3 text-center"><?php p($l->t('Invoice #'));?>
<div id="factureid" style="display:inline"><?php echo $_['facture'][0]->num;?></div> <div id="factureid" style="display:inline"><?php echo $_['facture'][0]->num;?></div>
<div id="factureIdentifier" data-id="<?php echo $_['facture'][0]->id;?>" class="d-none"></div>
</h2> </h2>
<hr/> <hr/>
<div class="row"> <div class="row">
@ -104,7 +105,7 @@
</div> </div>
<hr> <hr>
<div> <div>
<button id="pdf" type="button" class="mb-2 btn btn-outline-success" data-html2canvas-ignore data-name=""><?php p($l->t('Save in Nextcloud'));?></button> <button id="exportFactureToPdf" type="button" class="mb-2 btn btn-outline-success" data-html2canvas-ignore data-name=""><?php p($l->t('Save in Nextcloud'));?></button>
<button id="mailGestion" type="button" class="mb-2 btn btn-outline-success sendmail" data-html2canvas-ignore data-name=""><?php p($l->t('Send by email'));?></button> <button id="mailGestion" type="button" class="mb-2 btn btn-outline-success sendmail" data-html2canvas-ignore data-name=""><?php p($l->t('Send by email'));?></button>
</div> </div>
<div class="mt-0 table-responsive"> <div class="mt-0 table-responsive">