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