INSERTINTO`zz_modules`(`id`,`name`,`title`,`directory`,`options`,`options2`,`icon`,`version`,`compatibility`,`order`,`parent`,`default`,`enabled`,`use_notes`,`use_checklists`)VALUES(NULL,'Fasce orarie','Fasce orarie','fasce_orarie','SELECT |select| FROM `in_fasceorarie` WHERE 1=1 HAVING 2=2','','fa fa-angle-right','2.4.32','2.4.32','1',(SELECTidFROMzz_modulestWHEREt.name='Interventi'),'1','1','0','0');
INSERTINTO`zz_modules`(`id`,`name`,`title`,`directory`,`options`,`options2`,`icon`,`version`,`compatibility`,`order`,`parent`,`default`,`enabled`,`use_notes`,`use_checklists`)VALUES(NULL,'Eventi','Eventi','eventi','SELECT |select| FROM `zz_events` INNER JOIN `an_nazioni` ON `an_nazioni`.id = `zz_events`.id_nazione WHERE 1=1 HAVING 2=2','','fa fa-angle-right','2.4.32','2.4.32','1',(SELECTidFROMzz_modulestWHEREt.name='Tabelle'),'1','1','0','0');
UPDATE`zz_modules`SET`options`='SELECT |select| FROM `co_documenti`\n LEFT JOIN `an_anagrafiche` ON `co_documenti`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`\n LEFT JOIN `co_tipidocumento` ON `co_documenti`.`idtipodocumento` = `co_tipidocumento`.`id`\n LEFT JOIN `co_statidocumento` ON `co_documenti`.`idstatodocumento` = `co_statidocumento`.`id`\n LEFT JOIN `fe_stati_documento` ON `co_documenti`.`codice_stato_fe` = `fe_stati_documento`.`codice`\n LEFT JOIN (\n SELECT `iddocumento`,\n SUM(`subtotale` - `sconto`) AS `totale_imponibile`,\n SUM(`iva`) AS `iva`,\n `split_payment`\n FROM `co_righe_documenti` LEFT JOIN `co_documenti` ON `co_righe_documenti`.`iddocumento`=`co_documenti`.`id`\n GROUP BY `iddocumento`\n ) AS righe ON `co_documenti`.`id` = `righe`.`iddocumento`\n LEFT JOIN (\n SELECT `numero_esterno`, `id_segment`\n FROM `co_documenti`\n WHERE `co_documenti`.`idtipodocumento` IN(SELECT `id` FROM `co_tipidocumento` WHERE `dir` = \'entrata\') |date_period(`co_documenti`.`data`)| AND `numero_esterno` != \'\'\n GROUP BY `id_segment`, `numero_esterno`\n HAVING COUNT(`numero_esterno`) > 1\n ) dup ON `co_documenti`.`numero_esterno` = `dup`.`numero_esterno` AND `dup`.`id_segment` = `co_documenti`.`id_segment`\n LEFT JOIN (\n SELECT `zz_operations`.`id_email`, `zz_operations`.`id_record`\n FROM `zz_operations`\n INNER JOIN `em_emails` ON `zz_operations`.`id_email` = `em_emails`.`id`\n INNER JOIN `em_templates` ON `em_emails`.`id_template` = `em_templates`.`id`\n INNER JOIN `zz_modules` ON `zz_operations`.`id_module` = `zz_modules`.`id`\n WHERE `zz_modules`.`name` = \'Fatturedivendita\' AND `zz_operations`.`op` = \'send-email\'\n GROUP BY `zz_operations`.`id_record`\n ) AS `email` ON `email`.`id_record` = `co_documenti`.`id`\nWHERE 1=1 AND `dir` = \'entrata\' |segment(`co_documenti`.`id_segment`)| |date_period(`co_documenti`.`data`)|\nHAVING 2=2\nORDER BY `co_documenti`.`data` DESC, CAST(`co_documenti`.`numero_esterno` AS UNSIGNED) DESC'WHERE`zz_modules`.`name`='Fatture di vendita';
UPDATE`zz_modules`SET`options`='SELECT |select| FROM `co_documenti`\nLEFT JOIN `an_anagrafiche` ON `co_documenti`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`\nLEFT JOIN `co_tipidocumento` ON `co_documenti`.`idtipodocumento` = `co_tipidocumento`.`id`\nLEFT JOIN `co_statidocumento` ON `co_documenti`.`idstatodocumento` = `co_statidocumento`.`id`\nLEFT JOIN (\n SELECT `iddocumento`,\n SUM(`subtotale` - `sconto`) AS `totale_imponibile`,\n SUM(`iva`) AS `iva`,\n `split_payment`\n FROM `co_righe_documenti` LEFT JOIN `co_documenti` ON `co_righe_documenti`.`iddocumento`=`co_documenti`.`id`\n GROUP BY `iddocumento`\n) AS righe ON `co_documenti`.`id` = `righe`.`iddocumento`\nLEFT JOIN (\n SELECT COUNT(`d`.`id`) AS `conteggio`,\n IF(`d`.`numero_esterno`=\'\', `d`.`numero`, `d`.`numero_esterno`) AS `numero_documento`,\n `d`.`idanagrafica` AS `anagrafica`\n FROM `co_documenti` AS `d`\n LEFT JOIN `co_tipidocumento` AS `d_tipo` ON `d`.`idtipodocumento` = `d_tipo`.`id`\n WHERE 1=1\n AND `d_tipo`.`dir` = \'uscita\'\n AND (\'|period_start|\' <= `d`.`data` AND \'|period_end|\' >= `d`.`data` OR \'|period_start|\' <= `d`.`data_competenza` AND \'|period_end|\' >= `d`.`data_competenza`)\n GROUP BY `numero_documento`, `d`.`idanagrafica`\n) AS `d` ON (`d`.`numero_documento` = IF(`co_documenti`.`numero_esterno`=\'\', `co_documenti`.`numero`, `co_documenti`.`numero_esterno`) AND `d`.`anagrafica`=`co_documenti`.`idanagrafica`)\nWHERE 1=1 AND `dir` = \'uscita\' |segment(`co_documenti`.`id_segment`)||date_period(custom, \'|period_start|\' <= `co_documenti`.`data` AND \'|period_end|\' >= `co_documenti`.`data`, \'|period_start|\' <= `co_documenti`.`data_competenza` AND \'|period_end|\' >= `co_documenti`.`data_competenza` )|\nHAVING 2=2\nORDER BY `co_documenti`.`data` DESC, CAST(IF(`co_documenti`.`numero` = \'\', `co_documenti`.`numero_esterno`, `co_documenti`.`numero`) AS UNSIGNED) DESC'WHERE`zz_modules`.`name`='Fatture di acquisto';
-- Modificata query rif. fattura effettuando la ricerca su original_document e original_id e aggiunta colonne Preventivo, Ordine, Contratto in Attività
UPDATE`zz_modules`SET`options`='SELECT |select|\nFROM `or_ordini`\n LEFT JOIN `an_anagrafiche` ON `or_ordini`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`\n LEFT JOIN `or_tipiordine` ON `or_ordini`.`idtipoordine` = `or_tipiordine`.`id`\n LEFT JOIN (\n SELECT `idordine`,\n SUM(`qta` - `qta_evasa`) AS `qta_da_evadere`,\n SUM(`subtotale` - `sconto`) AS `totale_imponibile`,\n SUM(`subtotale` - `sconto` + `iva`) AS `totale`\n FROM `or_righe_ordini`\n GROUP BY `idordine`\n ) AS righe ON `or_ordini`.`id` = `righe`.`idordine`\n LEFT JOIN (\n SELECT `idordine`,\n MIN(`data_evasione`) AS `data_evasione`\n FROM `or_righe_ordini`\n WHERE (`qta` - `qta_evasa`)>0\n GROUP BY `idordine`\n ) AS `righe_da_evadere` ON `righe`.`idordine`=`righe_da_evadere`.`idordine`\n LEFT JOIN (\n SELECT GROUP_CONCAT(DISTINCT co_documenti.numero_esterno SEPARATOR \", \") AS info, co_righe_documenti.original_document_id AS idordine FROM co_documenti INNER JOIN co_righe_documenti ON co_documenti.id = co_righe_documenti.iddocumento WHERE original_document_type=\'Modules\\\\Ordini\\\\Ordine\' GROUP BY idordine\n) AS fattura ON fattura.idordine = or_ordini.id\nLEFT JOIN (\n SELECT `zz_operations`.`id_email`, `zz_operations`.`id_record`\n FROM `zz_operations`\n INNER JOIN `em_emails` ON `zz_operations`.`id_email` = `em_emails`.`id`\n INNER JOIN `em_templates` ON `em_emails`.`id_template` = `em_templates`.`id`\n INNER JOIN `zz_modules` ON `zz_operations`.`id_module` = `zz_modules`.`id`\n WHERE `zz_modules`.`name` = \'Ordinifornitore\' AND `zz_operations`.`op` = \'send-email\'\n GROUP BY `zz_operations`.`id_record`\n ) AS `email` ON `email`.`id_record` = `or_ordini`.`id`\nWHERE 1=1 AND `dir` = \'uscita\' |date_period(`data`)|\nHAVING 2=2\nORDER BY `data` DESC, CAST(`numero_esterno` AS UNSIGNED) DESC'WHERE`zz_modules`.`name`='Ordini fornitore';
UPDATE`zz_modules`SET`options`='SELECT |select|\nFROM `or_ordini`\n LEFT JOIN `an_anagrafiche` ON `or_ordini`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`\n LEFT JOIN `or_tipiordine` ON `or_ordini`.`idtipoordine` = `or_tipiordine`.`id`\n LEFT JOIN (\n SELECT `idordine`,\n SUM(`qta` - `qta_evasa`) AS `qta_da_evadere`,\n SUM(`subtotale` - `sconto`) AS `totale_imponibile`,\n SUM(`subtotale` - `sconto` + `iva`) AS `totale`\n FROM `or_righe_ordini`\n GROUP BY `idordine`\n ) AS righe ON `or_ordini`.`id` = `righe`.`idordine`\n LEFT JOIN (\n SELECT `idordine`,\n MIN(`data_evasione`) AS `data_evasione`\n FROM `or_righe_ordini`\n WHERE (`qta` - `qta_evasa`)>0\n GROUP BY `idordine`\n ) AS `righe_da_evadere` ON `righe`.`idordine`=`righe_da_evadere`.`idordine`\n LEFT JOIN (\n SELECT GROUP_CONCAT(DISTINCT co_documenti.numero_esterno SEPARATOR \", \") AS info, co_righe_documenti.original_document_id AS idordine FROM co_documenti INNER JOIN co_righe_documenti ON co_documenti.id = co_righe_documenti.iddocumento WHERE original_document_type=\'Modules\\\\Ordini\\\\Ordine\' GROUP BY idordine\n) AS fattura ON fattura.idordine = or_ordini.id\nLEFT JOIN (\n SELECT `zz_operations`.`id_email`, `zz_operations`.`id_record`\n FROM `zz_operations`\n INNER JOIN `em_emails` ON `zz_operations`.`id_email` = `em_emails`.`id`\n INNER JOIN `em_templates` ON `em_emails`.`id_template` = `em_templates`.`id`\n INNER JOIN `zz_modules` ON `zz_operations`.`id_module` = `zz_modules`.`id`\n WHERE `zz_modules`.`name` = \'Ordinicliente\' AND `zz_operations`.`op` = \'send-email\'\n GROUP BY `zz_operations`.`id_record`\n ) AS `email` ON `email`.`id_record` = `or_ordini`.`id`\nWHERE 1=1 AND `dir` = \'entrata\' |date_period(`data`)|\nHAVING 2=2\nORDER BY `data` DESC, CAST(`numero_esterno` AS UNSIGNED) DESC'WHERE`zz_modules`.`name`='Ordini cliente';
UPDATE`zz_modules`SET`options`='SELECT |select| FROM `in_interventi`\nINNER JOIN `an_anagrafiche` ON `in_interventi`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`\nLEFT JOIN `in_interventi_tecnici` ON `in_interventi_tecnici`.`idintervento` = `in_interventi`.`id`\nLEFT JOIN `in_interventi_tecnici_assegnati` ON `in_interventi_tecnici_assegnati`.`id_intervento` = `in_interventi`.`id`\nLEFT JOIN `in_statiintervento` ON `in_interventi`.`idstatointervento`=`in_statiintervento`.`idstatointervento`\nLEFT JOIN (\n SELECT an_sedi.id, CONCAT(an_sedi.nomesede, \'<br/>\',IF(an_sedi.telefono!=\'\',CONCAT(an_sedi.telefono,\'<br/>\'),\'\'),IF(an_sedi.cellulare!=\'\',CONCAT(an_sedi.cellulare,\'<br/>\'),\'\'),an_sedi.citta,IF(an_sedi.indirizzo!=\'\',CONCAT(\'-\',an_sedi.indirizzo),\'\')) AS info FROM an_sedi\n) AS sede_destinazione ON sede_destinazione.id = in_interventi.idsede_destinazione\nLEFT JOIN (\n SELECT GROUP_CONCAT(DISTINCT co_documenti.numero_esterno SEPARATOR \", \") AS info, co_righe_documenti.original_document_id AS idintervento FROM co_documenti INNER JOIN co_righe_documenti ON co_documenti.id = co_righe_documenti.iddocumento WHERE original_document_type=\'Modules\\\\Interventi\\\\Intervento\' GROUP BY idintervento\n) AS fattura ON fattura.idintervento = in_interventi.id\nLEFT JOIN (SELECT `zz_operations`.`id_email`, `zz_operations`.`id_record`\n FROM `zz_operations`\n INNER JOIN `em_emails` ON `zz_operations`.`id_email` = `em_emails`.`id`\n INNER JOIN `em_templates` ON `em_emails`.`id_template` = `em_templates`.`id`\n INNER JOIN `zz_modules` ON `zz_operations`.`id_module` = `zz_modules`.`id` \n WHERE `zz_modules`.`name` = \'Interventi\' AND `zz_operations`.`op` = \'send-email\' \n GROUP BY `zz_operations`.`id_record`) AS email ON email.id_record=in_interventi.id\nLEFT JOIN (\n SELECT GROUP_CONCAT(CONCAT(matricola, IF(nome != \'\', CONCAT(\'-\', nome), \'\')) SEPARATOR \'<br/>\') AS descrizione, my_impianti_interventi.idintervento\n FROM my_impianti\n INNER JOIN my_impianti_interventi ON my_impianti.id = my_impianti_interventi.idimpianto\n GROUP BY my_impianti_interventi.idintervento\n) AS impianti ON impianti.idintervento = in_interventi.id\nLEFT JOIN (\n SELECT co_contratti.id, CONCAT(co_contratti.numero, \'del\', DATE_FORMAT(data_bozza, \'%d/%m/%Y\')) AS info FROM co_contratti\n) AS contratto ON contratto.id = in_interventi.id_contratto\nLEFT JOIN (\n SELECT co_preventivi.id, CONCAT(co_preventivi.numero, \'del\', DATE_FORMAT(data_bozza, \'%d/%m/%Y\')) AS info FROM co_preventivi\n) AS preventivo ON preventivo.id = in_interventi.id_preventivo\nLEFT JOIN (\n SELECT or_ordini.id, CONCAT(or_ordini.numero, \'del\', DATE_FORMAT(data, \'%d/%m/%Y\')) AS info FROM or_ordini\n) AS ordine ON ordine.id = in_interventi.id_ordine\nWHERE 1=1 |date_period(`orario_inizio`,`data_richiesta`)|\nGROUP BY `in_interventi`.`id`\nHAVING 2=2\nORDER BY IFNULL(`orario_fine`, `data_richiesta`) DESC'WHERE`zz_modules`.`name`='Interventi';
UPDATE`zz_modules`SET`options`='SELECT |select|\nFROM `co_preventivi`\n LEFT JOIN `an_anagrafiche` ON `co_preventivi`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`\n LEFT JOIN `co_statipreventivi` ON `co_preventivi`.`idstato` = `co_statipreventivi`.`id`\n LEFT JOIN (\n SELECT `idpreventivo`,\n SUM(`subtotale` - `sconto`) AS `totale_imponibile`,\n SUM(`subtotale` - `sconto` + `iva`) AS `totale`\n FROM `co_righe_preventivi`\n GROUP BY `idpreventivo`\n ) AS righe ON `co_preventivi`.`id` = `righe`.`idpreventivo`\n\nLEFT JOIN (SELECT GROUP_CONCAT(DISTINCT co_documenti.numero_esterno SEPARATOR \", \") AS info, co_righe_documenti.original_document_id AS idpreventivo FROM co_documenti INNER JOIN co_righe_documenti ON co_documenti.id = co_righe_documenti.iddocumento WHERE original_document_type=\'Modules\\\\Preventivi\\\\Preventivo\' GROUP BY idpreventivo) AS fattura ON fattura.idpreventivo = co_preventivi.id\nWHERE 1=1 |date_period(custom,\'|period_start|\' >= `data_bozza` AND \'|period_start|\' <= `data_conclusione`,\'|period_end|\' >= `data_bozza` AND \'|period_end|\' <= `data_conclusione`,`data_bozza` >= \'|period_start|\' AND `data_bozza` <= \'|period_end|\',`data_conclusione` >= \'|period_start|\' AND `data_conclusione` <= \'|period_end|\',`data_bozza` >= \'|period_start|\' AND `data_conclusione` = \'0000-00-00\')| AND default_revision = 1\nGROUP BY `co_preventivi`.`id`\nHAVING 2=2\nORDER BY `co_preventivi`.`id` DESC 'WHERE`zz_modules`.`name`='Preventivi';
-- Aggiunta sezionale per fatture non elettroniche
INSERTINTO`zz_segments`(`id`,`id_module`,`name`,`clause`,`position`,`pattern`,`note`,`dicitura_fissa`,`predefined`,`predefined_accredito`,`predefined_addebito`,`created_at`,`updated_at`,`is_fiscale`)VALUES(NULL,(SELECT`id`FROM`zz_modules`WHERE`name`='Fatture di acquisto'),'Fatture non elettroniche','1=1','WHR','#','','','0','0','0',NULL,NULL,'1');