$interventi=$dbo->fetcharray('SELECT '.prepare(Module::where('name','Interventi')->first()->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(Module::where('name','Preventivi')->first()->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(Module::where('name','Contratti')->first()->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(Module::where('name','Ddt in uscita')->first()->id,$permessi)){
$ddt_vendita=$dbo->fetcharray('SELECT '.prepare(Module::where('name','Ddt in uscita')->first()->id)." AS id_module, id AS id_record, CONCAT('Ddt in uscita 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(Module::where('name','Ddt in entrata')->first()->id,$permessi)){
$ddt_acquisto=$dbo->fetcharray('SELECT '.prepare(Module::where('name','Ddt in entrata')->first()->id)." AS id_module, id AS id_record, CONCAT('Ddt in entrata 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(Module::where('name','Fatture di vendita')->first()->id,$permessi)){
$fatture_vendita=$dbo->fetcharray('SELECT '.prepare(Module::where('name','Fatture di vendita')->first()->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(Module::where('name','Fatture di acquisto')->first()->id,$permessi)){
$fatture_acquisto=$dbo->fetcharray('SELECT '.prepare(Module::where('name','Fatture di acquisto')->first()->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(Module::where('name','Ordini cliente')->first()->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(Module::where('name','Ordini fornitore')->first()->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']));