$interventi=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('name','Interventi'))." 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('name','Preventivi'))." 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('name','Contratti'))." 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('name','Ddt di vendita'),$permessi)){
$ddt_vendita=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('name','Ddt di vendita'))." 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('name','Ddt di acquisto'),$permessi)){
$ddt_acquisto=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('name','Ddt di acquisto'))." 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('name','Fatture di vendita'),$permessi)){
$fatture_vendita=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('name','Fatture di vendita'))." 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('name','Fatture di acquisto'),$permessi)){
$fatture_acquisto=$dbo->fetcharray('SELECT '.prepare((newModule())->getByField('name','Fatture di acquisto'))." 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('name','Ordini cliente'))." 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('name','Ordini fornitore'))." 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']));