Gestione allegati stampe

This commit is contained in:
MatteoPistorello 2023-06-29 11:11:41 +02:00
parent d9a8d2d9ca
commit 7f137f38a0
6 changed files with 129 additions and 12 deletions

View File

@ -28,8 +28,8 @@
"ext-simplexml": "*",
"ext-xsl": "*",
"ext-zip": "*",
"devcode-it/ical-easy-reader": "dev-main",
"davidepastore/codice-fiscale": "^0.6.0",
"devcode-it/ical-easy-reader": "dev-main",
"digitick/sepa-xml": "^2.1",
"dragonmantank/cron-expression": "^1.0",
"ezyang/htmlpurifier": "^4.8",
@ -39,6 +39,7 @@
"ifsnop/mysqldump-php": "^2.3",
"illuminate/database": "^8.0",
"intervention/image": "^2.3",
"jurosh/pdf-merge": "^2.1",
"league/csv": "9.7.0",
"league/oauth2-client": "^2.6",
"league/oauth2-google": "^3.0",

View File

@ -35,6 +35,16 @@ switch (post('op')) {
$print->save();
// Gestione file allegati
$dbo->delete('zz_files_print', ['id_print' => $id_record]);
$id_files = (array)post('id_files');
foreach ($id_files as $id_file) {
$dbo->insert('zz_files_print', [
'id_print' => $id_record,
'id_file' => $id_file
]);
}
flash()->info(tr('Modifiche salvate correttamente'));
break;

View File

@ -0,0 +1,61 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../../core.php';
switch ($resource) {
case 'allegati':
$id_module = $superselect['id_module'];
$id_plugin = $superselect['id_plugin'];
$id_record = $superselect['id_record'];
if (isset($id_module) || isset($id_plugin)) {
$query = 'SELECT `id`, `name` AS descrizione FROM zz_files |where|';
if (isset($id_module)) {
$where[] = 'zz_files.id_module = '.prepare($id_module);
}
if (isset($id_plugin)) {
$where[] = 'zz_files.id_plugin = '.prepare($id_plugin);
}
$where[] = 'zz_files.id_record = '.prepare($id_record);
if ($is_fiscale != null) {
$where[] = 'zz_segments.is_fiscale = '.prepare($is_fiscale);
}
if ($is_sezionale != null) {
$where[] = 'zz_segments.is_sezionale = '.prepare($is_sezionale);
}
if ($escludi_id != null) {
$where[] = 'zz_segments.id != '.prepare($escludi_id);
}
foreach ($elements as $element) {
$filter[] = 'id='.prepare($element);
}
if (!empty($search)) {
$search_fields[] = 'zz_segments.name LIKE '.prepare('%'.$search.'%');
}
}
break;
}

View File

@ -21,6 +21,8 @@ include_once __DIR__.'/../../core.php';
use Models\PrintTemplate;
$id_files = $dbo->select('zz_files_print', 'id_file', ['id_print' => $id_record]);
?><form action="" method="post" id="edit-form">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="update">
@ -43,21 +45,27 @@ use Models\PrintTemplate;
{[ "type": "text", "label": "<?php echo tr('Nome del file'); ?>", "name": "filename", "required": 1, "value": "$filename$" ]}
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="col-md-6">
{[ "type": "select", "label": "<?php echo tr('Modulo'); ?>", "name": "module", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_modules WHERE ( enabled = 1 AND options != 'custom' ) OR id = <?php echo $record['id_module']; ?> ORDER BY name ASC", "value": "<?php echo $record['id_module']; ?>", "disabled": "1" ]}
</div>
<div class="col-md-3">
<div class="col-md-6">
{[ "type": "select", "multiple": "1", "label": "<?php echo tr('File da accodare'); ?>", "name": "id_files[]", "value": "<?php echo implode(',', array_column($id_files, 'id_file')); ?>", "ajax-source": "allegati", "select-options": <?php echo json_encode(['id_module' => $id_module, 'id_record' => $id_record]); ?> ]}
</div>
</div>
<div class="row">
<div class="col-md-4">
{[ "type": "checkbox", "label": "<?php echo tr('Attiva'); ?>", "name": "enabled", "value": "$enabled$", "disabled": "1" ]}
</div>
<div class="col-md-3">
<div class="col-md-4">
{[ "type": "number", "label": "<?php echo tr('Ordine'); ?>", "name": "order", "required": 0, "value": "$order$", "decimals":0 ]}
</div>
@ -73,7 +81,7 @@ use Models\PrintTemplate;
}
?>
<div class="col-md-3">
<div class="col-md-4">
{[ "type": "checkbox", "label": "<?php echo tr('Predefinita'); ?>", "help" : "<?php echo tr('Attiva per impostare questa stampa come predefinita. Attualmente la stampa predefinita per questo modulo è: '.$nome_stampa_predefinita); ?>", "name": "predefined", "value": "$predefined$", "disabled": "<?php echo intval($record['predefined']); ?>" ]}
</div>
@ -133,7 +141,6 @@ echo '
</div>
</div>';
// Variabili utilizzabili
$module = Modules::get($record['id_module']);
$variables = $module->getPlaceholders($id_record);
@ -168,6 +175,7 @@ echo '
</div>
</div>
<hr>';
<hr>
{( "name": "filelist_and_upload", "id_module": "$id_module$", "id_record": "$id_record$" )}';
?>

View File

@ -17,6 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use Jurosh\PDFMerge\PDFMerger;
use Mpdf\Mpdf;
use Util\Query;
@ -694,8 +695,37 @@ class Prints
$mpdf->WriteHTML('<div style="position:absolute; bottom: 13mm; margin-right: '.($settings['margins']['right']).'mm">'.$foot.'</div>');
}
$id_files = $dbo->select('zz_files_print', 'id_file', ['id_print' => $id_print]);
$has_pdf = false;
foreach ($id_files as $id_file) {
$fil = Models\Upload::find($id_file)->first();
if ($fil->isImage()) {
$link = base_path().'/'.$fil->filepath;
$mpdf->WriteHTML('<pagebreak />');
$mpdf->WriteHTML('<img src="'.$link.'"></img>');
} elseif ($fil->isPdf()) {
$has_pdf = true;
}
}
// Creazione effettiva del PDF
$pdf = $mpdf->Output($path, $mode);
if ($has_pdf) {
$pdf_merger = new PDFMerger;
$mpdf->Output(base_dir().'/files/'.$infos['directory'].'/'.basename($path), 'F');
$pdf_merger->addPDF(base_dir().'/files/'.$infos['directory'].'/'.basename($path));
foreach ($id_files as $id_file) {
$fil = Models\Upload::find($id_file)->first();
$pdf_merger->addPDF( base_dir().'/'.$fil->file_path, 'all');
}
$mode_merger = ($mode == 'F' ? 'file' : ($mode == 'D' ? 'download' : ($mode == 'S' ? 'string' : 'I')));
$path_merger = $mode == 'F' ? base_dir().'/files/'.$infos['directory'].'/'.basename($path) : $path;
$pdf = $pdf_merger->merge($mode_merger, $path_merger);
} else {
$pdf = $mpdf->Output($path, $mode);
}
$file['pdf'] = $pdf;
}else{
$file = self::getFile($infos, $id_record, $directory, $replaces);

View File

@ -92,12 +92,13 @@ class Uploads
if (!empty($filename)) {
$database = database();
$name = $database->selectOne('zz_files', ['name'], [
$file = $database->selectOne('zz_files', '*', [
'filename' => $filename,
'id_module' => !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null,
'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null,
'id_record' => $data['id_record'],
])['name'];
]);
$name = $file['name'];
$fileinfo = self::fileInfo($filename);
$directory = base_dir().'/'.self::getDirectory($data['id_module'], $data['id_plugin']);
@ -117,6 +118,12 @@ class Uploads
'id_record' => $data['id_record'],
]);
if (Modules::get('Stampe')['id'] == $data['id_module']) {
$database->delete('zz_files_print', [
'id_file' => $file['id'],
]);
}
return $name;
}
}