openstamanager/templates/info.php

161 lines
6.0 KiB
PHP
Raw Normal View History

2017-09-08 18:19:39 +02:00
<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* 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/>.
*/
2017-09-08 18:19:39 +02:00
2024-02-05 17:07:33 +01:00
use Modules\Anagrafiche\Nazione;
$replaces = [];
2017-09-08 18:19:39 +02:00
// Retrocompatibilità
$id_cliente = $id_cliente ?: $idcliente;
// Leggo i dati della destinazione (se 0=sede legale, se!=altra sede da leggere da tabella an_sedi)
if (empty($id_sede) || $id_sede == '-1') {
2024-03-11 15:22:37 +01:00
$queryc = 'SELECT * FROM `an_anagrafiche` WHERE `idanagrafica`='.prepare($id_cliente);
2017-09-08 18:19:39 +02:00
} else {
2024-03-11 15:22:37 +01:00
$queryc = 'SELECT `an_anagrafiche`.*, `an_sedi`.*, if(`an_sedi`.`codice_fiscale` != "", `an_sedi`.`codice_fiscale`, `an_anagrafiche`.`codice_fiscale`) AS codice_fiscale, if(`an_sedi`.`piva` != "", `an_sedi`.`piva`, `an_anagrafiche`.`piva`) AS piva, if(`an_sedi`.`id_nazione` != "", `an_sedi`.`id_nazione`, `an_anagrafiche`.`id_nazione`) AS id_nazione FROM `an_sedi` JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica`=`an_sedi`.`idanagrafica` WHERE `an_sedi`.`idanagrafica`='.prepare($id_cliente).' AND `an_sedi`.`id`='.prepare($id_sede);
2017-09-08 18:19:39 +02:00
}
2020-09-24 16:51:41 +02:00
/**
* @deprecated
*/
2019-07-11 15:05:36 +02:00
$cliente = $dbo->fetchOne($queryc);
2017-09-08 18:19:39 +02:00
// Lettura dati aziendali
2020-09-24 16:51:41 +02:00
/**
* @deprecated
*/
2024-03-11 15:22:37 +01:00
$id_azienda = setting('Azienda predefinita');
2024-03-11 17:23:42 +01:00
$azienda = $dbo->fetchOne('SELECT *, (SELECT `iban` FROM `co_banche` WHERE `id` IN (SELECT `id_banca_azienda` FROM `co_documenti` WHERE `id` = '.prepare($id_record).')) AS codiceiban, (SELECT `nome` FROM `co_banche` WHERE `id` IN (SELECT `id_banca_azienda` FROM `co_documenti` WHERE `id` = '.prepare($id_record).')) AS appoggiobancario, (SELECT `bic` FROM `co_banche` WHERE `id` IN (SELECT `id_banca_azienda` FROM `co_documenti` WHERE `id` = '.prepare($id_record).")) AS bic FROM `an_anagrafiche` WHERE `idanagrafica` = (SELECT `valore` FROM `zz_settings` WHERE `name`='Azienda predefinita')");
2017-09-08 18:19:39 +02:00
2017-09-12 11:49:39 +02:00
// Prefissi e contenuti del replace
2020-09-24 16:51:41 +02:00
/**
* @deprecated
*/
2017-09-08 18:19:39 +02:00
$replace = [
2019-07-11 15:05:36 +02:00
'c_' => isset($cliente) ? $cliente : [],
'f_' => isset($azienda) ? $azienda : [],
2017-09-08 18:19:39 +02:00
];
2017-09-12 11:49:39 +02:00
// Rinominazione di particolari campi all'interno delle informazioni su anagrafica e azienda
2017-09-08 18:19:39 +02:00
$rename = [
'capitale_sociale' => 'capsoc',
'ragione_sociale' => 'ragionesociale',
'codice_fiscale' => 'codicefiscale',
];
$keys = [];
2017-09-12 11:49:39 +02:00
// Predisposizione delle informazioni delle anagrafiche per la sostituzione automatica
2017-09-08 18:19:39 +02:00
foreach ($replace as $prefix => $values) {
$values = (array) $values;
2017-09-12 11:49:39 +02:00
// Rinominazione dei campi
2017-09-08 18:19:39 +02:00
foreach ($rename as $key => $value) {
$val = null;
if (isset($values[$key])) {
$val = $values[$key];
}
$values[$value] = $val;
2017-09-08 18:19:39 +02:00
unset($values[$key]);
}
2017-09-12 11:49:39 +02:00
// Eventuali estensioni dei contenuti
2017-09-08 18:19:39 +02:00
$citta = '';
if (!empty($values['cap'])) {
2017-09-08 18:19:39 +02:00
$citta .= $values['cap'];
}
if (!empty($values['citta'])) {
2017-09-08 18:19:39 +02:00
$citta .= ' '.$values['citta'];
}
if (!empty($values['provincia'])) {
2017-09-08 18:19:39 +02:00
$citta .= ' ('.$values['provincia'].')';
}
2020-10-04 10:02:41 +02:00
if (!empty($values['id_nazione'])) {
2024-02-05 17:07:33 +01:00
$nazione = Nazione::find($values['id_nazione']);
2020-10-16 08:31:10 +02:00
if ($nazione['iso2'] != 'IT') {
2024-02-05 17:07:33 +01:00
$citta .= ' - '.$nazione->name;
2020-10-04 10:02:41 +02:00
}
}
2017-09-08 18:19:39 +02:00
$values['citta_full'] = $citta;
$replace[$prefix] = $values;
// Individuazione dei campi minimi
$keys = array_merge($keys, array_keys($values));
}
$keys = array_unique($keys);
foreach ($replace as $prefix => $values) {
// Impostazione di default per le informazioni mancanti
foreach ($keys as $key) {
if (!isset($values[$key])) {
$values[$key] = '';
}
2017-09-08 18:19:39 +02:00
}
// Salvataggio dei campi come variabili PHP e aggiunta delle informazioni per la sostituzione automatica
2017-09-08 18:19:39 +02:00
foreach ($values as $key => $value) {
${$prefix.$key} = $value;
2017-09-08 18:19:39 +02:00
$replaces[$prefix.$key] = $value;
}
}
// Header di default
$header_file = App::filepath('templates/base|custom|/header.php');
$default_header = include $header_file;
$default_header = !empty($options['hide-header']) ? '' : $default_header;
// Footer di default
$footer_file = App::filepath('templates/base|custom|/footer.php');
$default_footer = include $footer_file;
$default_footer = !empty($options['hide-footer']) ? '' : $default_footer;
// Logo di default
$default_logo = App::filepath('templates/base|custom|/logo_azienda.jpg');
2021-12-07 13:03:45 +01:00
// Logo generico
2018-07-13 16:19:44 +02:00
if (!empty(setting('Logo stampe'))) {
$custom_logo = App::filepath('files/anagrafiche/'.setting('Logo stampe'));
}
// Logo specifico della stampa
$logo = Prints::filepath($id_print, 'logo_azienda.jpg');
if (empty($logo)) {
$logo = empty($custom_logo) ? $default_logo : $custom_logo;
}
// Valori aggiuntivi per la sostituzione
$replaces = array_merge($replaces, [
'default_header' => $default_header,
'default_footer' => $default_footer,
'default_logo' => $default_logo,
'logo' => $logo,
'base_dir()' => base_dir(),
'base_link()' => base_path(),
'directory' => Prints::get($id_print)['full_directory'],
'footer' => !empty($footer) ? $footer : '',
2023-05-29 16:24:00 +02:00
'dicitura_fissa_fattura' => setting('Dicitura fissa fattura').((setting('Regime Fiscale') != 'RF02' && setting('Regime Fiscale') != 'RF19' && setting('Regime Fiscale') != 'RF18') ? ($tipo_cliente != 'Privato' ? tr('Documento privo di valenza fiscale ai sensi dellart. 21 Dpr 633/72. Loriginale è disponibile allindirizzo telematico da Lei fornito oppure nella Sua area riservata dellAgenzia delle Entrate') : tr('Copia della fattura elettronica disponibile nella Sua area riservata dellAgenzia delle Entrate')) : ''),
]);
unset($replace);