diff --git a/modules/fatture/add_intervento.php b/modules/fatture/add_intervento.php index 2ec2c47be..c6d14fc8c 100755 --- a/modules/fatture/add_intervento.php +++ b/modules/fatture/add_intervento.php @@ -63,6 +63,7 @@ $rs = $dbo->fetchArray('SELECT AND in_interventi.id NOT IN (SELECT idintervento FROM co_righe_documenti WHERE idintervento IS NOT NULL) AND in_interventi.id_preventivo IS NULL AND in_interventi.id_contratto IS NULL + AND in_interventi.id_ordine IS NULL AND NOT in_interventi.id IN (SELECT idintervento FROM co_promemoria WHERE idintervento IS NOT NULL)'); foreach ($rs as $key => $value) { $intervento = \Modules\Interventi\Intervento::find($value['id']); diff --git a/modules/interventi/add.php b/modules/interventi/add.php index db593374a..5f96f4f2b 100755 --- a/modules/interventi/add.php +++ b/modules/interventi/add.php @@ -60,6 +60,7 @@ if (!empty($id_anagrafica)) { $id_intervento = filter('id_intervento'); $id_contratto = filter('idcontratto'); $id_promemoria_contratto = filter('idcontratto_riga'); +$id_ordine = null; // Trasformazione di un Promemoria dei Contratti in Intervento if (!empty($id_contratto) && !empty($id_promemoria_contratto)) { @@ -164,21 +165,23 @@ echo '
{[ "type": "select", "label": "'.tr('Cliente').'", "name": "idanagrafica", "required": 1, "value": "'.(!$id_cliente ? $id_anagrafica : $id_cliente).'", "ajax-source": "clienti", "icon-after": "add|'.$module_anagrafiche['id'].'|tipoanagrafica=Cliente&readonly_tipo=1", "readonly": "'.((empty($id_anagrafica) && empty($id_cliente)) ? 0 : 1).'" ]}
- -
- {[ "type": "select", "label": "'.tr('Preventivo').'", "name": "idpreventivo", "value": "'.$id_preventivo.'", "ajax-source": "preventivi", "readonly": "'.(empty($id_preventivo) ? 0 : 1).'" ]} -
- -
- {[ "type": "select", "label": "'.tr('Contratto').'", "name": "idcontratto", "value": "'.$id_contratto.'", "ajax-source": "contratti", "readonly": "'.(empty($id_contratto) ? 0 : 1).'" ]} -
- {[ "type": "select", "label": "'.tr('Ordine').'", "name": "idordine", "ajax-source": "ordini" ]} + {[ "type": "select", "label": "'.tr('Preventivo').'", "name": "idpreventivo", "value": "'.$id_preventivo.'", "ajax-source": "preventivi", "readonly": "'.(empty($id_preventivo) ? 0 : 1).'", "select-options": '.json_encode(['idanagrafica' => $id_anagrafica]).' ]}
+
+ {[ "type": "select", "label": "'.tr('Contratto').'", "name": "idcontratto", "value": "'.$id_contratto.'", "ajax-source": "contratti", "readonly": "'.(empty($id_contratto) ? 0 : 1).'", "select-options": '.json_encode(['idanagrafica' => $id_anagrafica]).' ]} +
+ +
+ {[ "type": "select", "label": "'.tr('Ordine').'", "name": "idordine", "ajax-source": "ordini-cliente", "value": "'.$id_ordine.'", "select-options": '.json_encode(['idanagrafica' => $id_anagrafica]).' ]} +
+
+ +
{[ "type": "timestamp", "label": "'.tr('Data/ora richiesta').'", "name": "data_richiesta", "required": 1, "value": "'.($data_richiesta ?: '-now-').'" ]}
@@ -186,14 +189,14 @@ echo '
{[ "type": "select", "label": "'.tr('Tipo').'", "name": "idtipointervento", "required": 1, "values": "query=SELECT idtipointervento AS id, descrizione FROM in_tipiintervento ORDER BY descrizione ASC", "value": "'.$id_tipo.'", "ajax-source": "tipiintervento" ]}
+ +
+ {[ "type": "select", "label": "'.tr('Stato').'", "name": "idstatointervento", "required": 1, "values": "query=SELECT idstatointervento AS id, descrizione, colore AS _bgcolor_ FROM in_statiintervento WHERE deleted_at IS NULL", "value": "'.$id_stato.'" ]} +
-
- {[ "type": "select", "label": "'.tr('Stato').'", "name": "idstatointervento", "required": 1, "values": "query=SELECT idstatointervento AS id, descrizione, colore AS _bgcolor_ FROM in_statiintervento WHERE deleted_at IS NULL", "value": "'.$id_stato.'" ]} -
- -
+
{[ "type": "ckeditor", "label": "'.tr('Richiesta').'", "name": "richiesta_add", "required": 1, "value": "'.$richiesta.'", "extra": "style=\'max-height:80px;\'" ]}
'; @@ -361,12 +364,14 @@ echo ' var sede = input("idsede_destinazione"); var contratto = input("idcontratto"); var preventivo = input("idpreventivo"); + var ordine = input("idordine"); $(document).ready(function() { if(!anagrafica.get()){ sede.disable(); - input("idpreventivo").disable(); - input("idcontratto").disable(); + preventivo.disable(); + contratto.disable(); + ordine.disable(); input("idimpianti").disable(); input("componenti").disable(); } @@ -404,10 +409,13 @@ echo ' sede.setDisabled(value) .getElement().selectReset(placeholder); - input("idpreventivo").setDisabled(value) + preventivo.setDisabled(value) .getElement().selectReset(placeholder); - input("idcontratto").setDisabled(value) + contratto.setDisabled(value) + .getElement().selectReset(placeholder); + + ordine.setDisabled(value) .getElement().selectReset(placeholder); input("idimpianti").setDisabled(value); @@ -436,13 +444,20 @@ echo ' } }); + // Gestione della modifica dell\'ordine selezionato + ordine.change(function() { + if (ordine.get()) { + contratto.getElement().selectReset(); + preventivo.getElement().selectReset(); + } + }); + // Gestione della modifica del preventivo selezionato preventivo.change(function() { - if (contratto.get() && preventivo.get()){ + if (preventivo.get()){ contratto.getElement().selectReset(); - } + ordine.getElement().selectReset(); - if (preventivo.get()) { input("idtipointervento").getElement() .selectSetNew($(this).selectData().idtipointervento, $(this).selectData().idtipointervento_descrizione); } @@ -450,8 +465,10 @@ echo ' // Gestione della modifica del contratto selezionato contratto.change(function() { - if (contratto.get() && preventivo.get()){ + if (contratto.get()){ preventivo.getElement().selectReset(); + ordine.getElement().selectReset(); + $("input[name=idcontratto_riga]").val(""); } }); diff --git a/modules/interventi/edit.php b/modules/interventi/edit.php index f57cb4626..fbf9edb1d 100755 --- a/modules/interventi/edit.php +++ b/modules/interventi/edit.php @@ -114,10 +114,8 @@ echo ' '.Modules::link('Ordini cliente', $record['idordine'], null, null, 'class="pull-right"'); } echo ' - - {[ "type": "select", "label": "'.tr('Ordine').'", "name": "idordine", "value": "'.$record['id_ordine'].'", "ajax-source": "ordini", "select-options": '.json_encode(['idanagrafica' => $record['idanagrafica']]).', "readonly": "'.$record['flag_completato'].'" ]} - + {[ "type": "select", "label": "'.tr('Ordine').'", "name": "idordine", "value": "'.$record['id_ordine'].'", "ajax-source": "ordini-cliente", "select-options": '.json_encode(['idanagrafica' => $record['idanagrafica']]).', "readonly": "'.$record['flag_completato'].'" ]}
@@ -589,59 +587,103 @@ $(document).ready(function() { caricaCosti(); }); -$("#idanagrafica").change(function () { - updateSelectOption("idanagrafica", $(this).val()); - session_set("superselect,idanagrafica", $(this).val(), 0); + var anagrafica = input("idanagrafica"); + var sede = input("idsede_destinazione"); + var contratto = input("idcontratto"); + var preventivo = input("idpreventivo"); + var ordine = input("idordine"); - $("#idsede_destinazione").selectReset(); - $("#idpreventivo").selectReset(); - $("#idcontratto").selectReset(); + // Gestione della modifica dell\'anagrafica + anagrafica.change(function() { + updateSelectOption("idanagrafica", $(this).val()); + session_set("superselect,idanagrafica", $(this).val(), 0); - if (($(this).val())) { - if (($(this).selectData().idzona)) { - $("#idzona").val($(this).selectData().idzona).change(); + let value = !$(this).val(); + let placeholder = value ? "'.tr('Seleziona prima un cliente').'" : "'.tr("Seleziona un'opzione").'"; - } else { - $("#idzona").val("").change(); + sede.setDisabled(value) + .getElement().selectReset(placeholder); + + preventivo.setDisabled(value) + .getElement().selectReset(placeholder); + + contratto.setDisabled(value) + .getElement().selectReset(placeholder); + + ordine.setDisabled(value) + .getElement().selectReset(placeholder); + + input("idimpianti").setDisabled(value); + + let data = anagrafica.getData(); + if (data) { + input("idzona").set(data.idzona ? data.idzona : ""); + // session_set("superselect,idzona", $(this).selectData().idzona, 0); + + // Impostazione del tipo intervento da anagrafica + input("idtipointervento").getElement() + .selectSetNew(data.idtipointervento, data.idtipointervento_descrizione); + } + }); + + // Gestione della modifica della sede selezionato + sede.change(function() { + updateSelectOption("idsede_destinazione", $(this).val()); + session_set("superselect,idsede_destinazione", $(this).val(), 0); + input("idimpianti").getElement().selectReset(); + + let data = sede.getData(); + if (data) { + input("idzona").set(data.idzona ? data.idzona : ""); + // session_set("superselect,idzona", $(this).selectData().idzona, 0); + } + }); + + // Gestione della modifica dell\'ordine selezionato + ordine.change(function() { + if (ordine.get()) { + contratto.getElement().selectReset(); + preventivo.getElement().selectReset(); } - } -}); + }); -$("#idpreventivo").change(function () { - if ($("#idcontratto").val() && $(this).val()) { - $("#idcontratto").val("").trigger("change"); - } -}); + // Gestione della modifica del preventivo selezionato + preventivo.change(function() { + if (preventivo.get()){ + contratto.getElement().selectReset(); + ordine.getElement().selectReset(); -$("#idcontratto").change(function () { - if ($("#idpreventivo").val() && $(this).val()) { - $("#idpreventivo").val("").trigger("change"); - $("input[name=idcontratto_riga]").val(""); - } -}); - -$("#matricola").change(function () { - session_set("superselect,matricola", $(this).val(), 0); -}); - -$("#idsede").change(function () { - if (($(this).val())) { - if (($(this).selectData().idzona)) { - $("#idzona").val($(this).selectData().idzona).change(); - } else { - $("#idzona").val("").change(); + input("idtipointervento").getElement() + .selectSetNew($(this).selectData().idtipointervento, $(this).selectData().idtipointervento_descrizione); } - //session_set("superselect,idzona", $(this).selectData().idzona, 0); - } -}); + }); -$("#codice_cig, #codice_cup").bind("keyup change", function (e) { - if ($("#codice_cig").val() == "" && $("#codice_cup").val() == "") { - $("#id_documento_fe").prop("required", false); - } else { - $("#id_documento_fe").prop("required", true); - } -}); + // Gestione della modifica del contratto selezionato + contratto.change(function() { + if (contratto.get()){ + preventivo.getElement().selectReset(); + ordine.getElement().selectReset(); + + $("input[name=idcontratto_riga]").val(""); + } + }); + + // Gestione delle modifiche agli impianti selezionati + input("idimpianti").change(function() { + updateSelectOption("matricola", $(this).val()); + session_set("superselect,matricola", $(this).val(), 0); + + input("componenti").setDisabled(!$(this).val()) + .getElement().selectReset(); + }); + + $("#codice_cig, #codice_cup").bind("keyup change", function (e) { + if ($("#codice_cig").val() == "" && $("#codice_cup").val() == "") { + $("#id_documento_fe").prop("required", false); + } else { + $("#id_documento_fe").prop("required", true); + } + }); '; // Collegamenti diretti diff --git a/modules/ordini/ajax/select.php b/modules/ordini/ajax/select.php index b15d50949..37fc1f64b 100644 --- a/modules/ordini/ajax/select.php +++ b/modules/ordini/ajax/select.php @@ -24,9 +24,14 @@ switch ($resource) { * Opzioni utilizzate: * - idanagrafica */ - case 'ordini': + case 'ordini-cliente': if (isset($superselect['idanagrafica'])) { - $query = 'SELECT or_ordini.id AS id, or_ordini.idanagrafica, CONCAT("Ordine ", numero, " del ", DATE_FORMAT(data, "%d/%m/%Y"), " [", (SELECT `descrizione` FROM `or_statiordine` WHERE `or_statiordine`.`id` = `idstatoordine`) , "]") AS descrizione, (SELECT SUM(subtotale) FROM or_righe_ordini WHERE idordine=or_ordini.id GROUP BY idordine) AS totale, (SELECT SUM(sconto) FROM or_righe_ordini WHERE idordine=or_ordini.id GROUP BY idordine) AS sconto FROM or_ordini INNER JOIN an_anagrafiche ON or_ordini.idanagrafica=an_anagrafiche.idanagrafica |where| ORDER BY id'; + $query = 'SELECT or_ordini.id AS id, + CONCAT("Ordine ", numero, " del ", DATE_FORMAT(data, "%d/%m/%Y"), " [", (SELECT `descrizione` FROM `or_statiordine` WHERE `or_statiordine`.`id` = `idstatoordine`) , "]") AS descrizione + FROM or_ordini + INNER JOIN an_anagrafiche ON or_ordini.idanagrafica = an_anagrafiche.idanagrafica + |where| + ORDER BY id'; foreach ($elements as $element) { $filter[] = 'id='.prepare($element); diff --git a/update/2_4_22.sql b/update/2_4_22.sql index c47f6c519..6fc84d85c 100644 --- a/update/2_4_22.sql +++ b/update/2_4_22.sql @@ -306,7 +306,8 @@ UPDATE `zz_views` SET `order` = 8, `name`='Conto dare' WHERE `name`='Conto avere UPDATE `zz_views` SET `name`='Conto avere' WHERE `name`='Conto avere_new'; -- Aggiunta campo per scelta ordine in intervento -ALTER TABLE `in_interventi` ADD `id_ordine` INT NOT NULL AFTER `id_contratto`; +ALTER TABLE `in_interventi` ADD `id_ordine` INT(11) AFTER `id_contratto`; +ALTER TABLE `in_interventi` ADD CONSTRAINT `in_interventi_ibfk_7` FOREIGN KEY (`id_ordine`) REFERENCES `or_ordini`(`id`) ON DELETE CASCADE; -- Aggiunta plugin consuntivo per ordini INSERT INTO `zz_plugins` (`id`, `name`, `title`, `idmodule_from`, `idmodule_to`, `position`, `script`, `enabled`, `default`, `order`, `compatibility`, `version`, `options2`, `options`, `directory`, `help`) VALUES @@ -314,4 +315,4 @@ INSERT INTO `zz_plugins` (`id`, `name`, `title`, `idmodule_from`, `idmodule_to`, -- Stampa consuntivo ordini INSERT INTO `zz_prints` (`id`, `id_module`, `is_record`, `name`, `title`, `filename`, `directory`, `previous`, `options`, `icon`, `version`, `compatibility`, `order`, `predefined`, `default`, `enabled`) VALUES -(NULL, (SELECT `id` FROM `zz_modules` WHERE name='Ordini cliente'), 1, 'Consuntivo ordine', 'Consuntivo ordine', 'Consuntivo ordine num. {numero} del {data}', 'ordini_cons', 'idordine', '{\"pricing\":true}', 'fa fa-print', '', '', 0, 0, 1, 1); \ No newline at end of file +(NULL, (SELECT `id` FROM `zz_modules` WHERE name='Ordini cliente'), 1, 'Consuntivo ordine', 'Consuntivo ordine', 'Consuntivo ordine num. {numero} del {data}', 'ordini_cons', 'idordine', '{\"pricing\":true}', 'fa fa-print', '', '', 0, 0, 1, 1);