diff --git a/assets/src/css/style.css b/assets/src/css/style.css index 654f08589..93fd49cb2 100644 --- a/assets/src/css/style.css +++ b/assets/src/css/style.css @@ -793,3 +793,7 @@ input.small-width { .img-circle.square{ box-shadow: 0px 0px 1px 1px lightgray; } + +.select2-dropdown{ + z-index: 2000; +} diff --git a/lib/functions.js b/lib/functions.js index 9698b5aab..6dbae0fc8 100644 --- a/lib/functions.js +++ b/lib/functions.js @@ -1257,7 +1257,7 @@ function message(element) { if (data["title"] != undefined) title = data["title"]; var msg = globals.translations.deleteMessage; - if (data["msg"] != undefined) msg = '
' + data["msg"] + '
'; + if (data["msg"] != undefined) msg = data["msg"]; var button = globals.translations.delete; if (data["button"] != undefined) button = data["button"]; @@ -1267,22 +1267,33 @@ function message(element) { swal({ title: title, - html: msg, + html: '
' + msg + '
', type: "warning", showCancelButton: true, confirmButtonText: button, confirmButtonClass: btn_class, + onOpen: function () { + start_superselect(); + start_inputmask(); + }, preConfirm: function () { - $('#swal-form').find(':input').each(function () { + $form = $('#swal-form'); + $form.find(':input').each(function () { data[$(this).attr('name')] = $(this).val(); }); - return new Promise(function (resolve) { - resolve([]); - }); + if ($form.parsley().validate()) { + return new Promise(function (resolve) { + resolve(); + }); + } else { + $('.swal2-buttonswrapper button').each(function () { + $(this).prop('disabled', false); + }); + } } }).then( - function (result) { + function () { if (data["op"] == undefined) data["op"] = "delete"; var href = window.location.href.split("#")[0] diff --git a/modules/ddt/bulk.php b/modules/ddt/bulk.php index 418ab190e..147b24a16 100644 --- a/modules/ddt/bulk.php +++ b/modules/ddt/bulk.php @@ -4,6 +4,26 @@ include_once __DIR__.'/../../core.php'; include_once Modules::filepath('Fatture di vendita', 'modutil.php'); +use Modules\Fatture\Fattura; +use Modules\Fatture\Tipo; +use Modules\Anagrafiche\Anagrafica; + +if ($module['name'] == 'Ddt di vendita') { + $dir = 'entrata'; + $module_name = 'Fatture di vendita'; +} else { + $dir = 'uscita'; + $module_name = 'Fatture di acquisto'; +} + +// Segmenti +$id_fatture = Modules::get($module_name)['id']; +if (!isset($_SESSION['module_'.$id_fatture]['id_segment'])) { + $segments = Modules::getSegments($id_fatture); + $_SESSION['module_'.$id_fatture]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null; +} +$id_segment = $_SESSION['module_'.$id_fatture]['id_segment']; + switch (post('op')) { case 'crea_fattura': $id_documento_cliente = []; @@ -11,28 +31,16 @@ switch (post('op')) { // Informazioni della fattura if ($dir == 'entrata') { - $tipo_documento = $dbo->selectOne('co_tipidocumento', 'id', ['descrizione' => 'Fattura immediata di vendita'])['id']; - $module_name = 'Fatture di vendita'; - $idconto = setting('Conto predefinito fatture di vendita'); + $tipo_documento = 'Fattura immediata di vendita'; } else { - $tipo_documento = $dbo->selectOne('co_tipidocumento', 'id', ['descrizione' => 'Fattura immediata di acquisto'])['id']; - $module_name = 'Fatture di acquisto'; - $idconto = setting('Conto predefinito fatture di acquisto'); + $tipo_documento = 'Fattura immediata di acquisto'; } + $tipo_documento = Tipo::where('descrizione', $tipo_documento)->first(); + $idiva = setting('Iva predefinita'); $data = date('Y-m-d'); - - // Segmenti - $id_fatture = Modules::get($module_name)['id']; - if (!isset($_SESSION['module_'.$id_fatture]['id_segment'])) { - $segments = Modules::getSegments($id_fatture); - $_SESSION['module_'.$id_fatture]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null; - } - $id_segment = $_SESSION['module_'.$id_fatture]['id_segment']; - - $stato = $dbo->fetchOne("SELECT `id` FROM `co_statidocumento` WHERE `descrizione` = 'Bozza'")['id']; - $sede = $dbo->fetchOne('SELECT IFNULL(idsede_fatturazione, 0) AS id_sede FROM an_anagrafiche WHERE idanagrafica='.prepare($id_anagrafica))['id_sede']; + $id_segment = post('id_segment'); // Lettura righe selezionate foreach ($id_records as $id) { @@ -43,43 +51,15 @@ switch (post('op')) { // Proseguo solo se i ddt scelti sono fatturabili if (!empty($righe)) { $id_documento = $id_documento_cliente[$id_anagrafica]; + ++$totale_n_ddt; // Se non c'è già una fattura appena creata per questo cliente, creo una fattura nuova if (empty($id_documento)) { - $numero = get_new_numerofattura($data); - $numero_esterno = get_new_numerosecondariofattura($data); + $anagrafica = Anagrafica::find($id_anagrafica); + $fattura = Fattura::new($anagrafica, $tipo_documento, $data, $id_segment); - $idconto = setting('Conto predefinito fatture di vendita'); - - $campo = ($dir == 'entrata') ? 'idpagamento_vendite' : 'idpagamento_acquisti'; - - // Tipo di pagamento predefinito dall'anagrafica - $query = 'SELECT id FROM co_pagamenti WHERE id=(SELECT '.$campo.' AS pagamento FROM an_anagrafiche WHERE idanagrafica='.prepare($id_anagrafica).')'; - $rs = $dbo->fetchArray($query); - $idpagamento = $rs[0]['id']; - - // Se alla non è stato associato un pagamento predefinito al cliente, leggo il pagamento dalle impostazioni - if (empty($idpagamento)) { - $idpagamento = setting('Tipo di pagamento predefinito'); - } - - // Creazione nuova fattura - $dbo->insert('co_documenti', [ - 'numero' => $numero, - 'numero_esterno' => $numero_esterno, - 'idanagrafica' => $id_anagrafica, - 'idconto' => $idconto, - 'idtipodocumento' => $tipo_documento, - 'idpagamento' => $idpagamento, - 'data' => $data, - 'id_segment' => $id_segment, - 'idstatodocumento' => $stato, - 'idsede' => $sede, - ]); - - $id_documento = $dbo->lastInsertedID(); + $id_documento = $fattura->id; $id_documento_cliente[$id_anagrafica] = $id_documento; - ++$totale_n_ddt; } // Inserimento righe @@ -158,7 +138,8 @@ $operations = [ 'crea_fattura' => [ 'text' => tr('Crea fattura'), 'data' => [ - 'msg' => tr('Vuoi davvero creare una fattura per questi interventi?'), + 'title' => tr('Vuoi davvero creare una fattura per questi interventi?'), + 'msg' => '
{[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module=\''.$id_fatture.'\' AND is_fiscale = 1 ORDER BY name", "value": "'.$id_segment.'" ]}', 'button' => tr('Procedi'), 'class' => 'btn btn-lg btn-warning', 'blank' => false, diff --git a/modules/fatture/actions.php b/modules/fatture/actions.php index 433c9aa69..caeef17df 100644 --- a/modules/fatture/actions.php +++ b/modules/fatture/actions.php @@ -3,11 +3,11 @@ include_once __DIR__.'/../../core.php'; use Modules\Fatture\Fattura; +use Modules\Fatture\Tipo; use Modules\Fatture\Articolo; use Modules\Fatture\Riga; use Modules\Fatture\Descrizione; use Modules\Articoli\Articolo as ArticoloOriginale; -use Modules\Fatture\Tipo; use Modules\Anagrafiche\Anagrafica; // Necessaria per la funzione add_movimento_magazzino diff --git a/modules/interventi/bulk.php b/modules/interventi/bulk.php index 78ac6bb07..a221a2d07 100644 --- a/modules/interventi/bulk.php +++ b/modules/interventi/bulk.php @@ -7,9 +7,20 @@ if (file_exists(__DIR__.'/../../../core.php')) { } use Util\Zip; +use Modules\Fatture\Fattura; +use Modules\Fatture\Tipo; +use Modules\Anagrafiche\Anagrafica; include_once Modules::filepath('Fatture di vendita', 'modutil.php'); +// Segmenti +$id_fatture = Modules::get('Fatture di vendita')['id']; +if (!isset($_SESSION['module_'.$id_fatture]['id_segment'])) { + $segments = Modules::getSegments($id_fatture); + $_SESSION['module_'.$id_fatture]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null; +} +$id_segment = $_SESSION['module_'.$id_fatture]['id_segment']; + switch (post('op')) { case 'export-bulk': @@ -62,27 +73,15 @@ switch (post('op')) { $data = date('Y-m-d'); $dir = 'entrata'; - $tipo_documento = $dbo->selectOne('co_tipidocumento', 'id', ['descrizione' => 'Fattura immediata di vendita'])['id']; + $tipo_documento = Tipo::where('descrizione', 'Fattura immediata di vendita')->first(); $id_iva = setting('Iva predefinita'); $id_conto = setting('Conto predefinito fatture di vendita'); $accodare = post('accodare'); + $id_segment = post('id_segment'); - $module_name = 'Fatture di vendita'; - - // Segmenti - $id_fatture = Modules::get($module_name)['id']; - if (!isset($_SESSION['module_'.$id_fatture]['id_segment'])) { - $segments = Modules::getSegments($id_fatture); - $_SESSION['module_'.$id_fatture]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null; - } - $id_segment = $_SESSION['module_'.$id_fatture]['id_segment']; - - $interventi = $dbo->fetchArray('SELECT *, IFNULL((SELECT MIN(orario_inizio) FROM in_interventi_tecnici WHERE in_interventi_tecnici.idintervento = in_interventi.id), in_interventi.data_richiesta) AS data, in_statiintervento.descrizione AS stato FROM in_interventi INNER JOIN in_statiintervento ON in_interventi.idstatointervento=in_statiintervento.idstatointervento WHERE in_statiintervento.completato=1 AND in_interventi.id NOT IN (SELECT idintervento FROM co_righe_documenti WHERE idintervento IS NOT NULL) AND in_interventi.id NOT IN (SELECT idintervento FROM co_preventivi_interventi WHERE idintervento IS NOT NULL) AND in_interventi.id NOT IN (SELECT idintervento FROM co_promemoria WHERE idintervento IS NOT NULL) AND in_interventi.id IN ('.implode(',', $id_records).')'); - - $stato = $dbo->fetchOne("SELECT `id` FROM `co_statidocumento` WHERE `descrizione` = 'Bozza'")['id']; - $sede = $dbo->fetchOne('SELECT IFNULL(idsede_fatturazione, 0) AS id_sede FROM an_anagrafiche WHERE idanagrafica='.prepare($id_anagrafica))['id_sede']; + $interventi = $dbo->fetchArray('SELECT *, IFNULL((SELECT MIN(orario_inizio) FROM in_interventi_tecnici WHERE in_interventi_tecnici.idintervento = in_interventi.id), in_interventi.data_richiesta) AS data, in_statiintervento.descrizione AS stato FROM in_interventi INNER JOIN in_statiintervento ON in_interventi.idstatointervento=in_statiintervento.idstatointervento WHERE in_statiintervento.completato=1 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 NOT IN (SELECT idintervento FROM co_promemoria WHERE idintervento IS NOT NULL) AND in_interventi.id IN ('.implode(',', $id_records).')'); // Lettura righe selezionate foreach ($interventi as $intervento) { @@ -100,38 +99,11 @@ switch (post('op')) { } if (empty($id_documento)) { - $numero = get_new_numerofattura($data); - $numero_esterno = get_new_numerosecondariofattura($data); + $anagrafica = Anagrafica::find($id_anagrafica); + $fattura = Fattura::new($anagrafica, $tipo_documento, $data, $id_segment); - $campo = ($dir == 'entrata') ? 'idpagamento_vendite' : 'idpagamento_acquisti'; - - // Tipo di pagamento predefinito dall'anagrafica - $query = 'SELECT id FROM co_pagamenti WHERE id=(SELECT '.$campo.' AS pagamento FROM an_anagrafiche WHERE idanagrafica='.prepare($id_anagrafica).')'; - $rs = $dbo->fetchArray($query); - $idpagamento = $rs[0]['id']; - - // Se alla non è stato associato un pagamento predefinito al cliente, leggo il pagamento dalle impostazioni - if (empty($idpagamento)) { - $idpagamento = setting('Tipo di pagamento predefinito'); - } - - // Creazione nuova fattura - $dbo->insert('co_documenti', [ - 'numero' => $numero, - 'numero_esterno' => $numero_esterno, - 'idanagrafica' => $id_anagrafica, - 'idconto' => $id_conto, - 'idtipodocumento' => $tipo_documento, - 'idpagamento' => $idpagamento, - 'data' => $data, - 'id_segment' => $id_segment, - 'idstatodocumento' => $stato, - 'idsede' => $sede, - ]); - - $id_documento = $dbo->lastInsertedID(); + $id_documento = $fattura->id; $id_documento_cliente[$id_anagrafica] = $id_documento; - ++$totale_n_ddt; } } @@ -172,7 +144,8 @@ return [ 'text' => tr('Crea fattura'), 'data' => [ 'title' => tr('Vuoi davvero generare le fatture per questi interventi?'), - 'msg' => '
{[ "type": "checkbox", "placeholder": "'.tr('Aggiungere alle fatture esistenti non ancora emesse?').'", "name": "accodare" ]}', + 'msg' => '
{[ "type": "checkbox", "placeholder": "'.tr('Aggiungere alle fatture esistenti non ancora emesse?').'", "name": "accodare" ]} +
{[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module=\''.$id_fatture.'\' AND is_fiscale = 1 ORDER BY name", "value": "'.$id_segment.'" ]}', 'button' => tr('Crea fatture'), 'class' => 'btn btn-lg btn-warning', 'blank' => false,