Aggiunta tabella zz_prints_lang

This commit is contained in:
Pek5892 2024-03-12 12:31:49 +01:00
parent 0d005c1a97
commit 5624f9ea07
19 changed files with 168 additions and 25 deletions

View File

@ -151,7 +151,7 @@ echo '
<div class="row">
<div class="col-md-6">
{[ "type": "select", "multiple": "1", "label": "'.tr('Stampe').'", "name": "prints[]", "value": "'.implode(',', $selected).'", "values": "query=SELECT id, title AS text FROM zz_prints WHERE id_module = '.prepare($id_module).' AND enabled=1 AND is_record=1", "link": "stampa" ]}
{[ "type": "select", "multiple": "1", "label": "'.tr('Stampe').'", "name": "prints[]", "value": "'.implode(',', $selected).'", "values": "query=SELECT `zz_prints`.`id`, `title` AS text FROM `zz_prints` LEFT JOIN `zz_prints_lang` ON (`zz_prints`.`id` = `zz_prints_lang`.`id_record` AND `zz_prints_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_module` = '.prepare($id_module).' AND `enabled`=1 AND `is_record`=1", "link": "stampa" ]}
</div>';
$uploads = [];

View File

@ -21,11 +21,12 @@ include_once __DIR__.'/../../core.php';
use Carbon\Carbon;
use Models\Module;
use Models\PrintTemplate;
$id_record = filter('id_record');
$dir = filter('dir');
$nome_stampa = filter('nome_stampa');
$id_print = $dbo->fetchOne('SELECT id FROM zz_prints WHERE name='.prepare($nome_stampa))['id'];
$id_print = (new PrintTemplate())->getByName($nome_stampa)->id_record;
$id_module = (new Module())->getByName('Stampe contabili')->id_record;
$year = (new Carbon($_SESSION['period_end']))->format('Y');

View File

@ -18,11 +18,21 @@
*/
include_once __DIR__.'/../../../core.php';
use Models\PrintTemplate;
// Trovo id_print della stampa
if(!empty(setting('Magazzino cespiti'))){
$id_print = $dbo->fetchOne('SELECT `zz_prints`.`id` FROM `zz_prints` INNER JOIN `zz_modules` ON `zz_prints`.`id_module`=`zz_modules`.`id` LEFT JOIN `zz_modules_lang` ON (`zz_modules`.`id` = `zz_modules_lang`.`id_record` AND `zz_modules_lang`.`id_lang` = '.setting('Lingua').') WHERE `zz_modules_lang`.`name`="Articoli" AND `zz_prints`.`name`="Inventario cespiti"')['id'];
$id_print = $dbo->fetchOne('SELECT
`zz_prints`.`id`
FROM
`zz_prints`
LEFT JOIN `zz_prints_lang` ON (`zz_prints`.`id` = `zz_prints_lang`.`id_record` AND `zz_prints_lang`.`id_lang` = '.setting('Lingua').')
INNER JOIN `zz_modules` ON `zz_prints`.`id_module`=`zz_modules`.`id`
LEFT JOIN `zz_modules_lang` ON (`zz_modules`.`id` = `zz_modules_lang`.`id_record` AND `zz_modules_lang`.`id_lang` = '.setting('Lingua').')
WHERE
`zz_modules_lang`.`name`="Articoli" AND `zz_prints_lang`.`name`="Inventario cespiti"')['id'];
echo '
<form action="'.base_path().'/pdfgen.php?id_print='.$id_print.'" method="post" target="_blank">

View File

@ -18,9 +18,18 @@
*/
include_once __DIR__.'/../../../core.php';
use Models\PrintTemplate;
// Trovo id_print della stampa
$id_print = $dbo->fetchOne('SELECT `zz_prints`.`id` FROM `zz_prints` INNER JOIN `zz_modules` ON `zz_prints`.`id_module`=`zz_modules`.`id` LEFT JOIN `zz_modules_lang` ON (`zz_modules`.`id` = `zz_modules_lang`.`id_record` AND `zz_modules_lang`.`id_lang` = '.setting('Lingua').') WHERE `zz_modules_lang`.`name`="Articoli" AND `zz_prints`.`name`="Inventario magazzino"')['id'];
$id_print = $dbo->fetchOne('SELECT
`zz_prints`.`id`
FROM
`zz_prints`
LEFT JOIN `zz_prints_lang` ON (`zz_prints`.`id` = `zz_prints_lang`.`id_record` AND `zz_prints_lang`.`id_lang` = '.setting('Lingua').')
INNER JOIN `zz_modules` ON `zz_prints`.`id_module`=`zz_modules`.`id`
LEFT JOIN `zz_modules_lang` ON (`zz_modules`.`id` = `zz_modules_lang`.`id_record` AND `zz_modules_lang`.`id_lang` = '.setting('Lingua').')
WHERE
`zz_modules_lang`.`name`="Articoli" AND `zz_prints_lang`.`name`="Inventario magazzino"')['id'];
echo '
<form action="'.base_path().'/pdfgen.php?id_print='.$id_print.'" method="post" target="_blank">

View File

@ -103,7 +103,7 @@ echo '
<div class="row">
<div class="col-md-12">
{[ "type": "select", "multiple": "1", "label": "'.tr('Stampe').'", "name": "prints[]", "value": "'.implode(',', $selected_prints).'", "values": "query=SELECT id, title AS text FROM zz_prints WHERE id_module = '.prepare($record['id_module']).' AND enabled=1 AND is_record=1" ]}
{[ "type": "select", "multiple": "1", "label": "'.tr('Stampe').'", "name": "prints[]", "value": "'.implode(',', $selected_prints).'", "values": "query=SELECT `zz_prints`.`id`, `zz_prints_lang`.`title` AS text FROM `zz_prints` LEFT JOIN `zz_prints_lang` ON (`zz_prints`.`id` = `zz_prints_lang`.`id_record` AND `zz_prints_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_module` = '.prepare($record['id_module']).' AND `enabled`=1 AND `is_record`=1" ]}
</div>
</div>

View File

@ -39,7 +39,7 @@ class Rapportino extends Resource implements RetrieveInterface, CreateInterface
$subject = $module->replacePlaceholders($id_record, $template['subject']);
$email = $module->replacePlaceholders($id_record, '{email}');
$prints = $database->fetchArray('SELECT id, title, EXISTS(SELECT id_print FROM em_print_template WHERE id_template = '.prepare($template['id']).' AND em_print_template.id_print = zz_prints.id) AS selected FROM zz_prints WHERE id_module = '.prepare($module->id).' AND enabled = 1');
$prints = $database->fetchArray('SELECT `zz_prints`.`id`, `title`, EXISTS(SELECT `id_print` FROM `em_print_template` WHERE `id_template` = '.prepare($template['id']).' AND `em_print_template`.`id_print` = `zz_prints`.`id`) AS selected FROM `zz_prints` LEFT JOIN `zz_prints_lang` ON (`zz_prints`.`id` = `zz_prints_lang`.`id_record` AND `zz_prints_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_module` = '.prepare($module->id).' AND `enabled` = 1');
return [
'email' => $email,

View File

@ -22,6 +22,7 @@ include_once __DIR__.'/../../core.php';
use Modules\Scadenzario\Scadenza;
use Modules\Fatture\Tipo;
use Models\Module;
use Models\PrintTemplate;
switch (post('op')) {
case 'add':
@ -140,9 +141,9 @@ switch (post('op')) {
case 'allega_fattura':
$scadenza = Scadenza::find($id_record);
$id_documento = post('iddocumento');
$print_predefined = $dbo->selectOne('zz_prints', '*', ['predefined' => 1, 'id_module' => (new Module())->GetByName('Fatture di vendita')->id_record]);
$print_predefined = PrintTemplate::where('predefined', 1)->where('id_module', (new Module())->GetByName('Fatture di vendita')->id_record)->first();
$print = Prints::render($print_predefined['id'], $id_documento, null, true);
$print = Prints::render($print_predefined->id, $id_documento, null, true);
$upload = Uploads::upload($print['pdf'], [
'name' => $scadenza->descrizione,
'original_name' => $scadenza->descrizione.'.pdf',

View File

@ -94,9 +94,9 @@ switch (post('op')) {
// Allego stampa della fattura se non presente
if (empty($fattura_allegata)) {
$print_predefined = $dbo->selectOne('zz_prints', '*', ['predefined' => 1, 'id_module' => (new Module())->GetByName('Fatture di vendita')->id_record]);
$print_predefined = PrintTemplate::where('predefined', 1)->where('id_module', (new Module())->GetByName('Fatture di vendita')->id_record)->first();
$print = Prints::render($print_predefined['id'], $id_documento, null, true);
$print = Prints::render($print_predefined->id, $id_documento, null, true);
$upload = Uploads::upload($print['pdf'], [
'name' => $scadenza->descrizione,
'original_name' => $scadenza->descrizione.'.pdf',

View File

@ -78,8 +78,7 @@ class SollecitoTask extends Manager
// Allego stampa della fattura se non presente
if (empty($fattura_allegata)) {
$print_predefined = database()->selectOne('zz_prints', '*', ['predefined' => 1, 'id_module' => (new Module())->getByName('Fatture di vendita')->id_record]);
$print_predefined = PrintTemplate::where('predefined', 1)->where('id_module', (new Module())->getByName('Fatture di vendita')->id_record)->first();
$print = \Prints::render($print_predefined['id'], $id_documento, null, true);
$name = 'Fattura di vendita';
$upload = \Uploads::upload($print['pdf'], [

View File

@ -22,17 +22,14 @@ include_once __DIR__.'/../../core.php';
switch (post('op')) {
case 'update':
if (!empty(intval(post('predefined'))) && !empty(post('module'))) {
$dbo->query('UPDATE zz_prints SET predefined = 0 WHERE zz_prints.id != '.prepare($id_record).' AND id_module = '.post('module'));
$dbo->query('UPDATE `zz_prints` SET `predefined` = 0 WHERE `id_module` = '.post('module'));
}
$print->title = post('title');
$print->filename = post('filename');
$print->options = post('options');
// $print->id_module = post('module');
// $print->enabled = post('enabled');
$print->order = post('order');
$print->predefined = intval(post('predefined'));
$print->save();
// Gestione file allegati

View File

@ -23,5 +23,8 @@ use Models\PrintTemplate;
if (isset($id_record)) {
$print = PrintTemplate::find($id_record);
$record = $print->toArray();
$record['title'] = $print->title;
$record['filename'] = $print->filename;
}

View File

@ -21,11 +21,12 @@ include_once __DIR__.'/../../core.php';
use Carbon\Carbon;
use Models\Module;
use Models\PrintTemplate;
$id_record = filter('id_record');
$dir = filter('dir');
$nome_stampa = filter('nome_stampa');
$id_print = $dbo->fetchOne('SELECT id FROM zz_prints WHERE name='.prepare($nome_stampa))['id'];
$id_print = (new PrintTemplate ())->getByName(prepare($nome_stampa))->id_record;
$id_module = (new Module())->getByName('Stampe contabili')->id_record;
$year = (new Carbon($_SESSION['period_end']))->format('Y');

View File

@ -18,6 +18,7 @@
*/
include_once __DIR__.'/core.php';
use Models\PrintTemplate;
$directory = !empty($directory) ? $directory : null;
$id_print = get('id_print');
@ -25,10 +26,10 @@ $id_print = get('id_print');
// Retrocompatibilitaà
$ptype = get('ptype');
if (!empty($ptype)) {
$print = $dbo->fetchArray('SELECT id, previous FROM zz_prints WHERE directory = '.prepare($ptype).' ORDER BY predefined DESC LIMIT 1');
$id_print = $print[0]['id'];
$print = PrintTemplate::where('directory', $ptype)->orderBy('predefined', 'DESC')->first();
$id_print = $print[0]->id;
$id_record = !empty($id_record) ? $id_record : get($print[0]['previous']);
$id_record = !empty($id_record) ? $id_record : get($print[0]->previous);
}
$result = Prints::render($id_print, $id_record, $directory);

View File

@ -41,7 +41,7 @@ class RapportinoIntervento extends Resource implements RetrieveInterface, Create
$subject = $module->replacePlaceholders($id_record, $template['subject']);
$email = $module->replacePlaceholders($id_record, '{email}');
$prints = $database->fetchArray('SELECT id, title, EXISTS(SELECT id_print FROM em_print_template WHERE id_template = '.prepare($template['id']).' AND em_print_template.id_print = zz_prints.id) AS selected FROM zz_prints WHERE id_module = '.prepare($module->id).' AND enabled = 1');
$prints = $database->fetchArray('SELECT `zz_prints`.`id`, `title`, EXISTS(SELECT `id_print` FROM `em_print_template` WHERE `id_template` = '.prepare($template['id']).' AND `em_print_template`.`id_print` = `zz_prints`.`id`) AS selected FROM `zz_prints` LEFT JOIN `zz_prints_lang` ON (`zz_prints`.`id` = `zz_prints_lang`.`id_record` AND `zz_prints_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_module` = '.prepare($module->id).' AND `enabled` = 1');
return [
'sender' => $account['from_name'].'<'.$account['from_address'].'>',

View File

@ -21,6 +21,7 @@ namespace HTMLBuilder\Manager;
use Modules\Emails\Template as TemplateEmail;
use Modules\SMS\Template as TemplateSMS;
use Models\PrintTemplate;
/**
* @since 2.4
@ -48,12 +49,12 @@ class ButtonManager implements ManagerInterface
protected function getInfo($options)
{
if ($options['type'] == 'print') {
$print = \Prints::get($options['id']);
$print = PrintTemplate::find($options['id']);
$result = [
'link' => \Prints::getHref($options['id'], $options['id_record'], $options['parameters']),
'title' => tr('Stampa').' '.((strtoupper($print['title']) == $print['title']) ? $print['title'] : lcfirst($print['title'])),
'icon' => $print['icon'],
'title' => tr('Stampa').' '.((strtoupper($print->title) == $print->title) ? $print->title : lcfirst($print->title)),
'icon' => $print->icon,
];
} elseif ($options['type'] == 'email') {
$template_email = TemplateEmail::find($options['id']);

View File

@ -64,6 +64,82 @@ class PrintTemplate extends Model
->first()->name;
}
/**
* Ritorna l'attributo title del template.
*
* @return string
*/
public function getTitleAttribute()
{
return database()->table($this->table.'_lang')
->select('title')
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'))
->first()->title;
}
/**
* Imposta l'attributo title della categoria.
*/
public function setTitleAttribute($value)
{
$table = database()->table($this->table.'_lang');
$translated = $table
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'));
if ($translated->count() > 0) {
$translated->update([
'title' => $value
]);
} else {
$table->insert([
'id_record' => $this->id,
'id_lang' => setting('Lingua'),
'title' => $value
]);
}
}
/**
* Ritorna l'attributo filename del template.
*
* @return string
*/
public function getFilenameAttribute()
{
return database()->table($this->table.'_lang')
->select('filename')
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'))
->first()->filename;
}
/**
* Imposta l'attributo filename della categoria.
*/
public function setFilenameAttribute($value)
{
$table = database()->table($this->table.'_lang');
$translated = $table
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'));
if ($translated->count() > 0) {
$translated->update([
'filename' => $value
]);
} else {
$table->insert([
'id_record' => $this->id,
'id_lang' => setting('Lingua'),
'filename' => $value
]);
}
}
/**
* Ritorna l'id del template a partire dal nome.
*

View File

@ -21,6 +21,7 @@ use Jurosh\PDFMerge\PDFMerger;
use Mpdf\Mpdf;
use Util\Query;
use Models\Module;
use Models\PrintTemplate;
/**
* Classe per la gestione delle informazioni relative alle stampe installate.
@ -44,7 +45,7 @@ class Prints
if (empty(self::$prints)) {
$database = database();
$results = $database->fetchArray('SELECT * FROM zz_prints WHERE enabled = 1 ORDER BY `order`');
$results = PrintTemplate::where('enabled', 1)->orderBy('order')->get();
$prints = [];

View File

@ -2164,3 +2164,45 @@ HAVING
2=2" WHERE `zz_modules`.`id` = (SELECT `id_record` FROM `zz_modules_lang` WHERE `name` = 'Gestione task');
UPDATE `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views_lang`.`id_record` = `zz_views`.`id` AND `zz_views_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = "Lingua")) INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` LEFT JOIN `zz_modules_lang` ON (`zz_modules_lang`.`id_record` = `zz_modules`.`id` AND `zz_modules_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = "Lingua")) SET `zz_views`.`query` = '`zz_tasks_lang`.`name`' WHERE `zz_modules_lang`.`name` = 'Gestione task' AND `zz_views_lang`.`name` = 'Nome';
UPDATE `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views_lang`.`id_record` = `zz_views`.`id` AND `zz_views_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = "Lingua")) INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` LEFT JOIN `zz_modules_lang` ON (`zz_modules_lang`.`id_record` = `zz_modules`.`id` AND `zz_modules_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = "Lingua")) SET `zz_views`.`query` = '`zz_tasks`.`id`' WHERE `zz_modules_lang`.`name` = 'Gestione task' AND `zz_views_lang`.`name` = 'id';
-- Aggiunta tabella zz_prints_lang
CREATE TABLE IF NOT EXISTS `zz_prints_lang` (
`id` int NOT NULL,
`id_lang` int NOT NULL,
`id_record` int NOT NULL,
`name` VARCHAR(255) NOT NULL,
`title` VARCHAR(255) NOT NULL,
`filename` VARCHAR(255) NOT NULL
);
ALTER TABLE `zz_prints_lang`
ADD PRIMARY KEY (`id`);
ALTER TABLE `zz_prints_lang`
MODIFY `id` int NOT NULL AUTO_INCREMENT;
INSERT INTO `zz_prints_lang` (`id`, `id_lang`, `id_record`, `name`, `title`, `filename`) SELECT NULL, (SELECT `id` FROM `zz_langs` WHERE `iso_code` = 'it'), `id`, `name`, `title`, `filename` FROM `zz_prints`;
ALTER TABLE `zz_prints`
DROP `name`,
DROP `title`,
DROP `filename`;
ALTER TABLE `zz_prints_lang` ADD CONSTRAINT `zz_prints_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `zz_prints`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;
-- Allineamento vista Stampe
UPDATE `zz_modules` SET `options` = "
SELECT
|select|
FROM
`zz_prints`
LEFT JOIN `zz_prints_lang` ON (`zz_prints_lang`.`id_record` = `zz_prints`.`id` AND `zz_prints_lang`.|lang|)
LEFT JOIN `zz_modules` ON `zz_modules`.`id` = `zz_prints`.`id_module`
LEFT JOIN `zz_modules_lang` ON (`zz_modules_lang`.`id_record` = `zz_modules`.`id` AND `zz_modules_lang`.|lang|)
WHERE
1=1
AND `zz_prints`.`enabled`=1
HAVING
2=2" WHERE `zz_modules`.`id` = (SELECT `id_record` FROM `zz_modules_lang` WHERE `name` = 'Stampe');
UPDATE `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views_lang`.`id_record` = `zz_views`.`id` AND `zz_views_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = "Lingua")) INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` LEFT JOIN `zz_modules_lang` ON (`zz_modules_lang`.`id_record` = `zz_modules`.`id` AND `zz_modules_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = "Lingua")) SET `zz_views`.`query` = '`zz_prints_lang`.`title`' WHERE `zz_modules_lang`.`name` = 'Stampe' AND `zz_views_lang`.`name` = 'Titolo';
UPDATE `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views_lang`.`id_record` = `zz_views`.`id` AND `zz_views_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = "Lingua")) INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` LEFT JOIN `zz_modules_lang` ON (`zz_modules_lang`.`id_record` = `zz_modules`.`id` AND `zz_modules_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = "Lingua")) SET `zz_views`.`query` = '`zz_prints_lang`.`filename`' WHERE `zz_modules_lang`.`name` = 'Stampe' AND `zz_views_lang`.`name` = 'Nome del file';

View File

@ -180,6 +180,7 @@ return [
'zz_plugins',
'zz_plugins_lang',
'zz_prints',
'zz_prints_lang',
'zz_segments',
'zz_segments_lang',
'zz_semaphores',