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
2017-09-21 10:28:35 +02:00
$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' ) {
$queryc = 'SELECT * FROM an_anagrafiche WHERE idanagrafica=' . prepare ( $id_cliente );
} else {
2020-10-04 10:02:41 +02: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
*/
$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 nome='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 ) {
2018-06-26 10:25:50 +02:00
$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 = '' ;
2017-09-10 14:35:41 +02:00
if ( ! empty ( $values [ 'cap' ])) {
2017-09-08 18:19:39 +02:00
$citta .= $values [ 'cap' ];
}
2017-09-10 14:35:41 +02:00
if ( ! empty ( $values [ 'citta' ])) {
2017-09-08 18:19:39 +02:00
$citta .= ' ' . $values [ 'citta' ];
}
2017-09-10 14:35:41 +02:00
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' ])) {
2020-10-16 08:31:10 +02:00
$nazione = $database -> fetchOne ( 'SELECT * FROM an_nazioni WHERE id = ' . prepare ( $values [ 'id_nazione' ]));
if ( $nazione [ 'iso2' ] != 'IT' ) {
2020-10-04 10:02:41 +02:00
$citta .= ' - ' . $nazione [ 'name' ];
}
}
2017-09-08 18:19:39 +02:00
$values [ 'citta_full' ] = $citta ;
2018-02-04 17:26:25 +01:00
$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
}
2018-02-04 17:26:25 +01: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 ) {
2018-02-04 17:26:25 +01:00
$ { $prefix . $key } = $value ;
2017-09-08 18:19:39 +02:00
$replaces [ $prefix . $key ] = $value ;
}
}
2017-09-21 10:18:08 +02:00
2018-02-22 11:25:18 +01:00
// Header di default
2018-07-02 15:41:38 +02:00
$header_file = App :: filepath ( 'templates/base|custom|/header.php' );
2018-02-22 11:25:18 +01:00
$default_header = include $header_file ;
2019-07-29 16:54:20 +02:00
$default_header = ! empty ( $options [ 'hide-header' ]) ? '' : $default_header ;
2018-02-22 11:25:18 +01:00
// Footer di default
2018-07-02 15:41:38 +02:00
$footer_file = App :: filepath ( 'templates/base|custom|/footer.php' );
2018-02-22 11:25:18 +01:00
$default_footer = include $footer_file ;
2019-07-29 16:54:20 +02:00
$default_footer = ! empty ( $options [ 'hide-footer' ]) ? '' : $default_footer ;
2018-02-22 11:25:18 +01:00
// Logo di default
2018-07-02 15:41:38 +02:00
$default_logo = App :: filepath ( 'templates/base|custom|/logo_azienda.jpg' );
2018-02-22 11:25:18 +01:00
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' ));
}
2018-02-22 11:25:18 +01:00
2018-02-25 11:06:14 +01:00
// Logo specifico della stampa
2018-07-02 15:41:38 +02:00
$logo = Prints :: filepath ( $id_print , 'logo_azienda.jpg' );
2018-02-25 11:06:14 +01:00
2018-07-02 15:41:38 +02:00
if ( empty ( $logo )) {
$logo = empty ( $custom_logo ) ? $default_logo : $custom_logo ;
2018-02-25 11:06:14 +01:00
}
2018-02-22 11:25:18 +01:00
2017-09-21 10:18:08 +02:00
// Valori aggiuntivi per la sostituzione
2017-09-21 10:28:35 +02:00
$replaces = array_merge ( $replaces , [
2018-02-22 11:25:18 +01:00
'default_header' => $default_header ,
'default_footer' => $default_footer ,
'default_logo' => $default_logo ,
2018-02-25 11:06:14 +01:00
'logo' => $logo ,
2020-09-23 13:36:37 +02:00
'base_dir()' => base_dir (),
2020-09-23 17:53:19 +02:00
'base_link()' => base_path (),
2017-09-22 15:16:56 +02:00
'directory' => Prints :: get ( $id_print )[ 'full_directory' ],
2017-09-21 10:18:08 +02:00
'footer' => ! empty ( $footer ) ? $footer : '' ,
2021-07-07 07:57:10 +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 (art 21 dpr 633/72).' ) : '' ),
2017-09-21 10:28:35 +02:00
]);
2018-02-04 17:26:25 +01:00
unset ( $replace );