2018-03-02 19:20:42 +01: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 />.
*/
2018-03-02 19:20:42 +01:00
2018-12-20 17:49:41 +01:00
$r = $dbo -> fetchOne ( ' SELECT co_documenti .* ,
2021-02-11 15:05:29 +01:00
IF ( ( an_referenti . email IS NOT NULL AND an_referenti . email != " " ), an_referenti . email , an_anagrafiche . email ) AS email ,
2019-04-11 16:04:08 +02:00
an_anagrafiche . idconto_cliente ,
an_anagrafiche . idconto_fornitore ,
2018-12-20 17:49:41 +01:00
an_anagrafiche . pec ,
an_anagrafiche . ragione_sociale ,
2019-07-22 11:44:04 +02:00
co_tipidocumento . descrizione AS tipo_documento ,
2019-08-29 10:25:14 +02:00
( SELECT pec FROM em_accounts WHERE em_accounts . id = '.prepare($template[' id_account ']).' ) AS is_pec
2019-07-22 11:44:04 +02:00
FROM co_documenti
INNER JOIN an_anagrafiche ON co_documenti . idanagrafica = an_anagrafiche . idanagrafica
INNER JOIN co_tipidocumento ON co_tipidocumento . id = co_documenti . idtipodocumento
2021-02-11 15:05:29 +01:00
LEFT OUTER JOIN an_referenti ON an_referenti . id = co_documenti . idreferente
2019-07-22 11:44:04 +02:00
WHERE co_documenti . id = ' . prepare ( $id_record ));
2018-03-02 19:20:42 +01:00
2019-07-25 17:39:55 +02:00
if ( ! empty ( setting ( 'Logo stampe' ))) {
2020-09-23 13:36:37 +02:00
$logo_azienda = base_url () . '/' . Models\Upload :: where ( 'filename' , setting ( 'Logo stampe' )) -> first () -> fileurl ;
2019-07-25 18:05:47 +02:00
} else {
2020-09-23 13:36:37 +02:00
$logo_azienda = str_replace ( base_dir (), base_url (), App :: filepath ( 'templates/base|custom|/logo_azienda.jpg' ));
2019-07-25 17:39:55 +02:00
$logo_azienda = str_replace ( '\\' , '/' , $logo_azienda );
}
2019-01-29 18:54:32 +01:00
2019-04-11 16:04:08 +02:00
//cliente
2019-04-12 01:11:32 +02:00
if ( $r [ 'idconto_cliente' ] != '' ) {
2019-04-11 16:04:08 +02:00
$conto = $r [ 'idconto_cliente' ];
$conto_descrizione = $dbo -> fetchOne ( 'SELECT CONCAT ((SELECT numero FROM co_pianodeiconti2 WHERE id=co_pianodeiconti3.idpianodeiconti2), ".", numero, " ", descrizione) AS descrizione FROM co_pianodeiconti3 WHERE id=' . prepare ( $conto ))[ 'descrizione' ];
}
//Fornitore
2019-04-12 01:11:32 +02:00
elseif ( $r [ 'idconto_fornitore' ] != '' ) {
2019-04-11 16:04:08 +02:00
$conto = $r [ 'idconto_fornitore' ];
$conto_descrizione = $dbo -> fetchOne ( 'SELECT CONCAT ((SELECT numero FROM co_pianodeiconti2 WHERE id=co_pianodeiconti3.idpianodeiconti2), ".", numero, " ", descrizione) AS descrizione FROM co_pianodeiconti3 WHERE id=' . prepare ( $conto ))[ 'descrizione' ];
}
2019-08-28 16:58:47 +02:00
$r_user = $dbo -> fetchOne ( 'SELECT * FROM an_anagrafiche WHERE idanagrafica=' . prepare ( Auth :: user ()[ 'idanagrafica' ]));
2019-06-25 16:02:45 +02:00
$r_company = $dbo -> fetchOne ( 'SELECT * FROM an_anagrafiche WHERE idanagrafica=' . prepare ( setting ( 'Azienda predefinita' )));
2018-03-02 19:20:42 +01:00
// Variabili da sostituire
return [
2018-11-12 18:49:51 +01:00
'email' => $r [ 'is_pec' ] ? $r [ 'pec' ] : $r [ 'email' ],
2018-07-10 12:07:48 +02:00
'id_anagrafica' => $r [ 'idanagrafica' ],
2018-12-23 14:01:59 +01:00
'ragione_sociale' => $r [ 'ragione_sociale' ],
2018-03-02 19:20:42 +01:00
'numero' => empty ( $r [ 'numero_esterno' ]) ? $r [ 'numero' ] : $r [ 'numero_esterno' ],
2019-07-22 11:44:04 +02:00
'tipo_documento' => $r [ 'tipo_documento' ],
2018-06-26 10:25:50 +02:00
'note' => $r [ 'note' ],
2018-03-02 19:20:42 +01:00
'data' => Translator :: dateToLocale ( $r [ 'data' ]),
2019-07-04 20:54:09 +02:00
'logo_azienda' => ! empty ( $logo_azienda ) ? '<img src="' . $logo_azienda . '" />' : '' ,
2019-04-11 16:04:08 +02:00
'conto' => $conto ,
'conto_descrizione' => $conto_descrizione ,
2019-06-25 16:02:45 +02:00
'nome_utente' => $r_user [ 'ragione_sociale' ],
'telefono_utente' => $r_user [ 'cellulare' ],
'sito_web' => $r_company [ 'sitoweb' ],
2018-03-02 19:20:42 +01:00
];