INSERTINTO`zz_settings`(`id`,`nome`,`valore`,`tipo`,`editable`,`sezione`,`order`,`help`)VALUES(NULL,'Condizioni generali di fornitura contratti','','ckeditor','1','Contratti',NULL,NULL);
UPDATE`zz_widgets`SET`query`='SELECT COUNT(id) AS dato FROM mg_articoli WHERE qta < threshold_qta AND attivo=1 AND deleted_at IS NULL'WHERE`zz_widgets`.`name`='Articoli in esaurimento';
UPDATE`zz_widgets`SET`query`='SELECT COUNT(id) AS dato FROM co_preventivi WHERE idstato=(SELECT id FROM co_statipreventivi WHERE descrizione=\"In lavorazione\") AND default_revision=1'WHERE`zz_widgets`.`name`='Preventivi in lavorazione';
-- Rimosso controllo is_pianificabile widget contratti in scadenza
UPDATE`zz_widgets`SET`query`='SELECT COUNT(dati.id) AS dato FROM(SELECT id, ((SELECT SUM(co_righe_contratti.qta) FROM co_righe_contratti WHERE co_righe_contratti.um=\'ore\' AND co_righe_contratti.idcontratto=co_contratti.id) - IFNULL( (SELECT SUM(in_interventi_tecnici.ore) FROM in_interventi_tecnici INNER JOIN in_interventi ON in_interventi_tecnici.idintervento=in_interventi.id WHERE in_interventi.id_contratto=co_contratti.id AND in_interventi.idstatointervento IN (SELECT in_statiintervento.idstatointervento FROM in_statiintervento WHERE in_statiintervento.is_completato = 1)), 0) ) AS ore_rimanenti, DATEDIFF(data_conclusione, NOW()) AS giorni_rimanenti, data_conclusione, ore_preavviso_rinnovo, giorni_preavviso_rinnovo, (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=co_contratti.idanagrafica) AS ragione_sociale FROM co_contratti WHERE rinnovabile = 1 AND YEAR(data_conclusione) > 1970 AND co_contratti.id NOT IN (SELECT idcontratto_prev FROM co_contratti contratti) HAVING (ore_rimanenti < ore_preavviso_rinnovo OR DATEDIFF(data_conclusione, NOW()) < ABS(giorni_preavviso_rinnovo)) ORDER BY giorni_rimanenti ASC, ore_rimanenti ASC) dati'WHERE`zz_widgets`.`name`='Contratti in scadenza';
-- Aggiornamento ritenuta contributi in contributi previdenziali
UPDATE`zz_modules`SET`options`='SELECT |select|\r\nFROM `or_ordini`\r\n LEFT JOIN `an_anagrafiche` ON `or_ordini`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`\r\n LEFT JOIN `or_tipiordine` ON `or_ordini`.`idtipoordine` = `or_tipiordine`.`id`\r\n LEFT JOIN (\r\n SELECT `idordine`,\r\n SUM(`qta` - `qta_evasa`) AS `qta_da_evadere`,\r\n SUM(`subtotale` - `sconto`) AS `totale_imponibile`,\r\n SUM(`subtotale` - `sconto` + `iva`) AS `totale`\r\n FROM `or_righe_ordini`\r\n GROUP BY `idordine`\r\n ) AS righe ON `or_ordini`.`id` = `righe`.`idordine`\r\n LEFT JOIN (\r\n SELECT `idordine`,\r\n MIN(`data_evasione`) AS `data_evasione`\r\n FROM `or_righe_ordini`\r\n WHERE (`qta` - `qta_evasa`)>0\r\n GROUP BY `idordine`\r\n ) AS `righe_da_evadere` ON `righe`.`idordine`=`righe_da_evadere`.`idordine`\r\n LEFT JOIN (\r\n SELECT GROUP_CONCAT(DISTINCT co_documenti.numero_esterno SEPARATOR \", \") AS info, co_righe_documenti.idordine FROM co_documenti INNER JOIN co_righe_documenti ON co_documenti.id = co_righe_documenti.iddocumento GROUP BY idordine\r\n) AS fattura ON fattura.idordine = or_ordini.id\r\nLEFT JOIN (\r\n SELECT `zz_operations`.`id_email`, `zz_operations`.`id_record`\r\n FROM `zz_operations`\r\n INNER JOIN `em_emails` ON `zz_operations`.`id_email` = `em_emails`.`id`\r\n INNER JOIN `em_templates` ON `em_emails`.`id_template` = `em_templates`.`id`\r\n INNER JOIN `zz_modules` ON `zz_operations`.`id_module` = `zz_modules`.`id`\r\n WHERE `zz_modules`.`name` = \'Ordinifornitore\' AND `zz_operations`.`op` = \'send-email\'\r\n GROUP BY `zz_operations`.`id_record`\r\n ) AS `email` ON `email`.`id_record` = `or_ordini`.`id`\r\nWHERE 1=1 AND `dir` = \'uscita\' |date_period(`data`)|\r\nHAVING 2=2\r\nORDER BY `data` DESC, CAST(`numero_esterno` AS UNSIGNED) DESC'WHERE`zz_modules`.`name`='Ordini fornitore';
UPDATE`zz_modules`SET`options`='SELECT |select|\r\nFROM `or_ordini`\r\n LEFT JOIN `an_anagrafiche` ON `or_ordini`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`\r\n LEFT JOIN `or_tipiordine` ON `or_ordini`.`idtipoordine` = `or_tipiordine`.`id`\r\n LEFT JOIN (\r\n SELECT `idordine`,\r\n SUM(`qta` - `qta_evasa`) AS `qta_da_evadere`,\r\n SUM(`subtotale` - `sconto`) AS `totale_imponibile`,\r\n SUM(`subtotale` - `sconto` + `iva`) AS `totale`\r\n FROM `or_righe_ordini`\r\n GROUP BY `idordine`\r\n ) AS righe ON `or_ordini`.`id` = `righe`.`idordine`\r\n LEFT JOIN (\r\n SELECT `idordine`,\r\n MIN(`data_evasione`) AS `data_evasione`\r\n FROM `or_righe_ordini`\r\n WHERE (`qta` - `qta_evasa`)>0\r\n GROUP BY `idordine`\r\n ) AS `righe_da_evadere` ON `righe`.`idordine`=`righe_da_evadere`.`idordine`\r\n LEFT JOIN (\r\n SELECT GROUP_CONCAT(DISTINCT co_documenti.numero_esterno SEPARATOR \", \") AS info, co_righe_documenti.idordine FROM co_documenti INNER JOIN co_righe_documenti ON co_documenti.id = co_righe_documenti.iddocumento GROUP BY idordine\r\n) AS fattura ON fattura.idordine = or_ordini.id\r\nLEFT JOIN (\r\n SELECT `zz_operations`.`id_email`, `zz_operations`.`id_record`\r\n FROM `zz_operations`\r\n INNER JOIN `em_emails` ON `zz_operations`.`id_email` = `em_emails`.`id`\r\n INNER JOIN `em_templates` ON `em_emails`.`id_template` = `em_templates`.`id`\r\n INNER JOIN `zz_modules` ON `zz_operations`.`id_module` = `zz_modules`.`id`\r\n WHERE `zz_modules`.`name` = \'Ordinicliente\' AND `zz_operations`.`op` = \'send-email\'\r\n GROUP BY `zz_operations`.`id_record`\r\n ) AS `email` ON `email`.`id_record` = `or_ordini`.`id`\r\nWHERE 1=1 AND `dir` = \'entrata\' |date_period(`data`)|\r\nHAVING 2=2\r\nORDER BY `data` DESC, CAST(`numero_esterno` AS UNSIGNED) DESC'WHERE`zz_modules`.`name`='Ordini cliente';
((SELECT`id`FROM`zz_modules`WHERE`name`='Ordini cliente'),'icon_Inviata','IF(`email`.`id_email` IS NOT NULL, \'fafa-envelopetext-success\', \'\')',12,1,0,0,'','',1,0,0),
((SELECT`id`FROM`zz_modules`WHERE`name`='Ordini fornitore'),'icon_Inviata','IF(`email`.`id_email` IS NOT NULL, \'fafa-envelopetext-success\', \'\')',12,1,0,0,'','',0,0,0);