$interventi=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('title','Attività',Models\Locale::getPredefined()->id))." AS id_module, `id` AS id_record, CONCAT('Intervento num. ',codice,' del ',DATE_FORMAT(`data_richiesta`,'%d/%m/%Y')) AS descrizione FROM `in_interventi` WHERE `idanagrafica`=".prepare($id_record));
$preventivi=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('title','Preventivi',Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Preventivo num. ',numero,' del ',DATE_FORMAT(data_bozza,'%d/%m/%Y')) AS descrizione FROM co_preventivi WHERE idanagrafica=".prepare($id_record));
$contratti=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('title','Contratti',Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Preventivo num. ',numero,' del ',DATE_FORMAT(data_bozza,'%d/%m/%Y')) AS descrizione FROM co_contratti WHERE idanagrafica=".prepare($id_record));
if($user->is_admin||in_array((newModule())->getByField('title','Ddt in uscita',Models\Locale::getPredefined()->id),$permessi)){
$ddt_vendita=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('title','Ddt in uscita',Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Ddt di vendita num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM dt_ddt WHERE idanagrafica=".prepare($id_record));
if($user->is_admin||in_array((newModule())->getByField('title','Ddt in entrata',Models\Locale::getPredefined()->id),$permessi)){
$ddt_acquisto=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('title','Ddt in entrata',Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Ddt di acquisto num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM dt_ddt WHERE idanagrafica=".prepare($id_record));
if($user->is_admin||in_array((newModule())->getByField('title','Fatture di vendita',Models\Locale::getPredefined()->id),$permessi)){
$fatture_vendita=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('title','Fatture di vendita',Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Fattura di vendita num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data_registrazione,'%d/%m/%Y')) AS descrizione FROM co_documenti WHERE idanagrafica=".prepare($id_record));
if($user->is_admin||in_array((newModule())->getByField('title','Fatture di acquisto',Models\Locale::getPredefined()->id),$permessi)){
$fatture_acquisto=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('title','Fatture di acquisto',Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Fattura di acquisto num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data_registrazione,'%d/%m/%Y')) AS descrizione FROM co_documenti WHERE idanagrafica=".prepare($id_record));
$ordini_vendita=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('title','Ordini cliente',Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Ordine cliente num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM or_ordini WHERE idanagrafica=".prepare($id_record));
$ordini_acquisto=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('title','Ordini fornitore',Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Ordine fornitore num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM or_ordini WHERE idanagrafica=".prepare($id_record));
$allegati=$dbo->fetchArray('SELECT * FROM zz_files WHERE id_module='.prepare($documento['id_module']).' AND id_record='.prepare($documento['id_record']));