From df1102d4b5dda6d75ce6edb1b88c8c7c2c1b60e7 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Thu, 14 Feb 2019 17:49:58 +0100 Subject: [PATCH] Aggiornamento passaggi tra documenti --- include/common/form.php | 4 +- include/common/importa.php | 322 +++++++ include/src/Components/Article.php | 2 +- include/src/Components/Description.php | 1 + include/src/Components/Row.php | 5 + lib/functions.js | 6 +- modules/contratti/ajax/select.php | 10 +- modules/contratti/buttons.php | 7 +- modules/contratti/crea_documento.php | 27 + modules/contratti/edit.php | 10 - modules/contratti/init.php | 8 +- modules/contratti/row-list.php | 6 +- .../src/Components/RelationTrait.php | 14 + modules/contratti/src/Contratto.php | 6 + modules/ddt/actions.php | 99 +-- modules/ddt/add_ordine.php | 101 ++- modules/ddt/buttons.php | 10 +- modules/ddt/crea_documento.php | 34 + modules/ddt/init.php | 4 +- modules/ddt/src/Components/Articolo.php | 1 + modules/ddt/src/Components/RelationTrait.php | 14 + modules/fatture/actions.php | 824 +++++------------- modules/fatture/add_contratto.php | 157 ++-- modules/fatture/add_ddt.php | 100 ++- modules/fatture/add_ordine.php | 100 ++- modules/fatture/add_preventivo.php | 155 ++-- modules/fatture/buttons.php | 4 +- modules/fatture/crea_documento.php | 351 +------- modules/fatture/edit.php | 4 +- modules/fatture/src/Components/Articolo.php | 1 + modules/interventi/add.php | 1 - modules/interventi/src/Intervento.php | 8 +- modules/ordini/actions.php | 106 +-- modules/ordini/buttons.php | 38 +- modules/ordini/crea_documento.php | 286 +----- modules/ordini/src/Components/Articolo.php | 1 + .../ordini/src/Components/RelationTrait.php | 14 + modules/preventivi/actions.php | 32 - modules/preventivi/ajax/select.php | 22 +- modules/preventivi/buttons.php | 49 +- modules/preventivi/crea_documento.php | 27 + modules/preventivi/init.php | 8 +- modules/preventivi/row-list.php | 5 +- .../src/Components/RelationTrait.php | 14 + modules/preventivi/src/Preventivo.php | 6 + src/App.php | 11 +- update/2_4_7.sql | 18 + 47 files changed, 1297 insertions(+), 1736 deletions(-) create mode 100644 include/common/importa.php create mode 100644 modules/contratti/crea_documento.php create mode 100644 modules/ddt/crea_documento.php create mode 100644 modules/preventivi/crea_documento.php diff --git a/include/common/form.php b/include/common/form.php index e59fb6c65..51c9f27b3 100644 --- a/include/common/form.php +++ b/include/common/form.php @@ -2,9 +2,7 @@ $result['id'] = isset($result['id']) ? $result['id'] : null; -/* - Form di inserimento riga documento -*/ +// Form di inserimento riga documento echo '
diff --git a/include/common/importa.php b/include/common/importa.php new file mode 100644 index 000000000..d278cbb2d --- /dev/null +++ b/include/common/importa.php @@ -0,0 +1,322 @@ +fetchOne('SELECT * FROM '.$table.' WHERE id = '.prepare($id_record)); +$numero = !empty($documento['numero_esterno']) ? $documento['numero_esterno'] : $documento['numero']; +$id_anagrafica = $documento['idanagrafica']; +$id_pagamento = $documento['idpagamento']; +$id_conto = $documento['idconto']; + +if (empty($documento)) { + return; +} + +$id_iva = $id_iva ?: setting('Iva predefinita'); +if (empty($id_conto)) { + $id_conto = ($dir == 'entrata') ? setting('Conto predefinito fatture di vendita') : setting('Conto predefinito fatture di acquisto'); +} + +// Selezione articoli dell'ordine da portare nel ddt +$righe = $dbo->fetchArray('SELECT *, IFNULL((SELECT codice FROM mg_articoli WHERE id=idarticolo),"") AS codice, (qta - qta_evasa) AS qta_rimanente FROM '.$table.' INNER JOIN '.$rows.' ON '.$table.'.id='.$rows.'.'.$id_rows.' WHERE '.$table.'.id='.prepare($id_record).' HAVING qta_rimanente > 0 OR is_descrizione = 1 ORDER BY `order`'); + +if (!empty($righe)) { + echo ' + + + + + + + + + + + + '; + + // Creazione fattura dal documento + if (!empty($options['create_document'])) { + echo ' +
+ + +
+ {[ "type": "date", "label": "'.tr('Data del documento').'", "name": "data", "required": 1, "value": "-now-" ]} +
'; + + if ($final_module['name'] == 'Fatture di vendita' || $final_module['name'] == 'Fatture di acquisto') { + if ($op == 'nota_accredito' && !empty($segmenti)) { + $segmento = $dbo->fetchOne("SELECT * FROM zz_segments WHERE predefined_accredito='1'"); + + $id_segment = $segmento['id']; + } else { + $id_segment = $_SESSION['module_'.$final_module['id']]['id_segment']; + } + + echo ' +
+ {[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='.prepare($final_module['id']).' ORDER BY name", "value": "'.$id_segment.'" ]} +
'; + } + + echo ' +
'; + } + + echo ' + +
'; + + // Iva + if ($original_module['name'] == 'Preventivi' || $original_module['name'] == 'Contratti') { + echo ' +
+ {[ "type": "select", "label": "'.tr('Iva').'", "name": "id_iva", "required": 1, "value": "'.$id_iva.'", "ajax-source": "iva" ]} +
'; + } + + // Conto + if (($final_module['name'] == 'Fatture di vendita' || $final_module['name'] == 'Fatture di acquisto') && $op != 'nota_credito') { + echo ' +
+ {[ "type": "select", "label": "'.tr('Conto').'", "name": "id_conto", "required": 1, "value": "'.$id_conto.'", "ajax-source": "'.($dir == 'entrata' ? 'conti-vendite' : 'conti-acquisti').'" ]} +
'; + } + + echo ' +
'; + + echo ' +
+
+ +

'.tr('Seleziona le righe e le relative quantità da inserire nel documento').'.

+ + + + + + + '; + + if (!empty($options['serials'])) { + echo ' + '; + } + + echo ' + '; + + $totale = 0.00; + + foreach ($righe as $i => $r) { + // Descrizione + echo ' + + '; + + // Q.tà rimanente + echo ' + '; + + // Q.tà da evadere + echo ' + '; + + // Subtotale + $subtotale = $r['subtotale'] / $r['qta'] * ($r['qta'] - $r['qta_evasa']); + $sconto = $r['sconto'] / $r['qta'] * ($r['qta'] - $r['qta_evasa']); + $iva = $r['iva'] / $r['qta'] * ($r['qta'] - $r['qta_evasa']); + + echo ' + '; + + // Seriali + if (!empty($options['serials'])) { + echo ' + '; + } + + echo ' + '; + + $totale += $subtotale - $sconto + $iva; + } + + // Totale + echo ' + + + + +
'.tr('Descrizione').''.tr('Q.tà').''.tr('Q.tà da evadere').''.tr('Subtot.').''.tr('Seriali').'
+ + + + '; + + // Checkbox - da evadere? + echo ' + '; + + $descrizione = (!empty($r['codice']) ? $r['codice'].' - ' : '').$r['descrizione']; + + echo ' '.nl2br($descrizione); + + echo ' + + + +

'.Translator::numberToLocale($r['qta_rimanente']).'

+
+ {[ "type": "number", "name": "qta_da_evadere['.$r['id'].']", "id": "qta_'.$i.'", "required": 1, "value": "'.$r['qta_rimanente'].'", "extra" : "onkeyup=\"ricalcola_subtotale_riga('.$i.');\"", "decimals": "qta", "min-value": "0", "extra": "'.(($r['is_descrizione']) ? 'readonly' : '').'" ]} + + + + + + + '.Translator::numberToLocale($subtotale - $sconto + $iva).' €
+ + '.Translator::numberToLocale($subtotale - $sconto).' + '.Translator::numberToLocale($iva).' +
'; + + if (!empty($r['abilita_serial'])) { + $query = 'SELECT DISTINCT serial AS id, serial AS descrizione FROM mg_prodotti WHERE dir='.prepare($dir).' AND '.$options['serials']['id_riga'].' = '.prepare($r['id']).' AND serial IS NOT NULL AND serial NOT IN (SELECT serial FROM mg_prodotti AS t WHERE serial IS NOT NULL AND dir='.prepare($dir).' AND '.$options['serials']['condition'].')'; + + $values = $dbo->fetchArray($query); + if (!empty($values)) { + echo ' + {[ "type": "select", "name": "serial['.$r['id'].'][]", "id": "serial_'.$i.'", "multiple": 1, "values": "query='.$query.'", "value": "'.implode(',', array_column($values, 'id')).'", "extra": "data-maximum=\"'.intval($r['qta_rimanente']).'\"" ]}'; + } + } + + if (empty($r['abilita_serial']) || empty($values)) { + echo '-'; + } + + echo ' +
+ '.tr('Totale').': + + '.Translator::numberToLocale($totale).' € +
'; + + echo ' + + +
+
+ +
+
+
'; +} else { + echo ' +

'.tr('Non ci sono elementi da evadere').'...

'; +} + +echo ' +'; + +?> + + diff --git a/include/src/Components/Article.php b/include/src/Components/Article.php index 6670e6261..45e9b9779 100644 --- a/include/src/Components/Article.php +++ b/include/src/Components/Article.php @@ -9,7 +9,7 @@ use UnexpectedValueException; abstract class Article extends Row { - protected $serialRowID = 'documento'; + protected $serialRowID = null; protected $abilita_movimentazione = true; protected $qta_movimentazione = 0; diff --git a/include/src/Components/Description.php b/include/src/Components/Description.php index ea0ea411c..af224110d 100644 --- a/include/src/Components/Description.php +++ b/include/src/Components/Description.php @@ -127,6 +127,7 @@ abstract class Description extends Model */ protected function customInitCopiaIn($original) { + $this->is_descrizione = $original->is_descrizione; } /** diff --git a/include/src/Components/Row.php b/include/src/Components/Row.php index 0e3eb202f..a016a5572 100644 --- a/include/src/Components/Row.php +++ b/include/src/Components/Row.php @@ -12,6 +12,11 @@ abstract class Row extends Description { protected $prezzo_unitario_vendita_riga = null; + protected $casts = [ + 'qta' => 'float', + //'qta_evasa' => 'float', + ]; + public static function build(Document $document, $bypass = false) { return parent::build($document, true); diff --git a/lib/functions.js b/lib/functions.js index bbcc2c911..d73f22377 100644 --- a/lib/functions.js +++ b/lib/functions.js @@ -1064,11 +1064,7 @@ jQuery.fn.selectData = function () { if ($select_obj[0] == undefined) { return undefined; } else { - if ($select_obj[0].selected == false) { - return $select_obj[0]; - } else { - return $select_obj[0].element.dataset; - } + return $select_obj[0]; } }; diff --git a/modules/contratti/ajax/select.php b/modules/contratti/ajax/select.php index f2710e169..48b4c303d 100644 --- a/modules/contratti/ajax/select.php +++ b/modules/contratti/ajax/select.php @@ -10,13 +10,11 @@ switch ($resource) { $filter[] = 'id='.prepare($element); } - $where[] = 'an_anagrafiche.idanagrafica='.prepare($superselect['idanagrafica']); + if (empty($elements)) { + $where[] = 'an_anagrafiche.idanagrafica='.prepare($superselect['idanagrafica']); - $stato = !empty($superselect['stato']) ? $superselect['stato'] : 'pianificabile'; - $where[] = 'idstato IN (SELECT `id` FROM co_staticontratti WHERE '.$stato.' = 1)'; - - if (!empty($superselect['non_fatturato'])) { - $where[] = 'id NOT IN (SELECT idcontratto FROM co_righe_documenti WHERE idcontratto IS NOT NULL)'; + $stato = !empty($superselect['stato']) ? $superselect['stato'] : 'pianificabile'; + $where[] = 'idstato IN (SELECT `id` FROM co_staticontratti WHERE '.$stato.' = 1)'; } if (!empty($search)) { diff --git a/modules/contratti/buttons.php b/modules/contratti/buttons.php index 4f6b5cba5..5ef34e6d2 100644 --- a/modules/contratti/buttons.php +++ b/modules/contratti/buttons.php @@ -3,15 +3,18 @@ include_once __DIR__.'/../../core.php'; $rs_documento = $dbo->fetchArray('SELECT * FROM co_righe_contratti WHERE idcontratto='.prepare($id_record)); + /* permetto di fatturare il contratto solo se contiene righe e si trova in uno stato fatturabile */ echo ' -'; if ($record['rinnovabile']) { $rinnova = !empty($record['data_accettazione']) && !empty($record['data_conclusione']) && $record['data_accettazione'] != '0000-00-00' && $record['data_conclusione'] != '0000-00-00' && $record['pianificabile']; + $stati_pianificabili = $dbo->fetchOne('SELECT GROUP_CONCAT(`descrizione` SEPARATOR ", ") AS stati_pianificabili FROM `co_staticontratti` WHERE `pianificabile` = 1')['stati_pianificabili']; + echo '
-
+
+
+ {[ "type": "select", "label": "'.tr('Contratto').'", "name": "id_documento", "ajax-source": "contratti" ]}
-'; +
+
+
+

'.tr('Informazioni di importazione').'

+
+
+
+
+ +
+ '.tr('Caricamento in corso').'... +
'; + +$file = basename(__FILE__); echo ' - '; + + +'; diff --git a/modules/fatture/add_ddt.php b/modules/fatture/add_ddt.php index a760a1ab2..ba257f97b 100644 --- a/modules/fatture/add_ddt.php +++ b/modules/fatture/add_ddt.php @@ -4,40 +4,88 @@ include_once __DIR__.'/../../core.php'; $module = Modules::get($id_module); -if ($module['name'] == 'Fatture di vendita') { - $dir = 'entrata'; - $module_origin = 'Ddt di vendita'; -} else { - $dir = 'uscita'; - $module_origin = 'Ddt di acquisto'; +$dir = ($module['name'] == 'Fatture di vendita') ? 'entrata' : 'uscita'; + +if (get('op')) { + $options = [ + 'op' => 'add_ddt', + 'id_importazione' => 'id_ddt', + 'final_module' => $module['name'], + 'original_module' => $module['name'] == 'Fatture di vendita' ? 'Ddt di vendita' : 'Ddt di acquisto', + 'sql' => [ + 'table' => 'dt_ddt', + 'rows' => 'dt_righe_ddt', + 'id_rows' => 'idddt', + ], + 'serials' => [ + 'id_riga' => 'id_riga_ddt', + 'condition' => '(id_riga_documento IS NOT NULL)', + ], + 'button' => tr('Aggiungi'), + 'dir' => $dir, + ]; + + $result = [ + 'id_record' => $id_record, + 'id_documento' => get('iddocumento'), + ]; + + echo App::load('importa.php', $result, $options, true); + + return; } $info = $dbo->fetchOne('SELECT * FROM co_documenti WHERE id='.prepare($id_record)); -$numero = ($info['numero_esterno'] != '') ? $info['numero_esterno'] : $info['numero']; $idanagrafica = $info['idanagrafica']; -// Ddt echo ' -
-
- {[ "type": "select", "label": "'.tr('Ddt').'", "name": "id_ddt", "required": 1, "values": "query=SELECT dt_ddt.id, CONCAT(\'nr. \', IF(numero_esterno != \'\', numero_esterno, numero), \' del \', DATE_FORMAT(data, \'%d-%m-%Y\')) AS descrizione FROM dt_ddt WHERE idanagrafica='.prepare($idanagrafica).' AND idstatoddt IN (SELECT id FROM dt_statiddt WHERE descrizione IN(\'Bozza\', \'Evaso\', \'Parzialmente evaso\', \'Parzialmente fatturato\')) AND idtipoddt=(SELECT id FROM dt_tipiddt WHERE dir='.prepare($dir).') AND dt_ddt.id IN (SELECT idddt FROM dt_righe_ddt WHERE dt_righe_ddt.idddt = dt_ddt.id AND (qta - qta_evasa) > 0) ORDER BY data DESC, numero DESC" ]} -
-
'; +
+
+ {[ "type": "select", "label": "'.tr('Ddt').'", "name": "id_documento", "values": "query=SELECT dt_ddt.id, CONCAT(\'DDT num. \', IF(numero_esterno != \'\', numero_esterno, numero), \' del \', DATE_FORMAT(data, \'%d-%m-%Y\')) AS descrizione FROM dt_ddt WHERE idanagrafica='.prepare($idanagrafica).' AND idstatoddt IN (SELECT id FROM dt_statiddt WHERE descrizione IN(\'Bozza\', \'Evaso\', \'Parzialmente evaso\', \'Parzialmente fatturato\')) AND idtipoddt=(SELECT id FROM dt_tipiddt WHERE dir='.prepare($dir).') AND dt_ddt.id IN (SELECT idddt FROM dt_righe_ddt WHERE dt_righe_ddt.idddt = dt_ddt.id AND (qta - qta_evasa) > 0) ORDER BY data DESC, numero DESC" ]} +
+
+
+
+

'.tr('Informazioni di importazione').'

+
+
+
+
+ +
+ '.tr('Caricamento in corso').'... +
'; + +$file = basename(__FILE__); echo ' -
-
-
'; - -echo ' - '; - -?> - + + +'; diff --git a/modules/fatture/add_ordine.php b/modules/fatture/add_ordine.php index 20e959962..aed3f4db2 100644 --- a/modules/fatture/add_ordine.php +++ b/modules/fatture/add_ordine.php @@ -4,40 +4,88 @@ include_once __DIR__.'/../../core.php'; $module = Modules::get($id_module); -if ($module['name'] == 'Fatture di vendita') { - $dir = 'entrata'; - $module_origin = 'Ordini cliente'; -} else { - $dir = 'uscita'; - $module_origin = 'Ordini fornitore'; +$dir = ($module['name'] == 'Fatture di vendita') ? 'entrata' : 'uscita'; + +if (get('op')) { + $options = [ + 'op' => 'add_ordine', + 'id_importazione' => 'id_ordine', + 'final_module' => $module['name'], + 'original_module' => $module['name'] == 'Fatture di vendita' ? 'Ordini cliente' : 'Ordini fornitore', + 'sql' => [ + 'table' => 'or_ordini', + 'rows' => 'or_righe_ordini', + 'id_rows' => 'idordine', + ], + 'serials' => [ + 'id_riga' => 'id_riga_ddt', + 'condition' => '(id_riga_documento IS NOT NULL)', + ], + 'button' => tr('Aggiungi'), + 'dir' => $dir, + ]; + + $result = [ + 'id_record' => $id_record, + 'id_documento' => get('iddocumento'), + ]; + + echo App::load('importa.php', $result, $options, true); + + return; } $info = $dbo->fetchOne('SELECT * FROM co_documenti WHERE id='.prepare($id_record)); -$numero = ($info['numero_esterno'] != '') ? $info['numero_esterno'] : $info['numero']; $idanagrafica = $info['idanagrafica']; -// Ordine echo ' -
-
- {[ "type": "select", "label": "'.tr('Ordine').'", "name": "id_ordine", "required": 1, "values": "query=SELECT or_ordini.id, CONCAT(IF(numero_esterno != \'\', numero_esterno, numero), \' del \', DATE_FORMAT(data, \'%d-%m-%Y\')) AS descrizione FROM or_ordini WHERE idanagrafica='.prepare($idanagrafica).' AND idstatoordine IN (SELECT id FROM or_statiordine WHERE descrizione IN(\'Bozza\', \'Evaso\', \'Parzialmente evaso\', \'Parzialmente fatturato\')) AND idtipoordine=(SELECT id FROM or_tipiordine WHERE dir='.prepare($dir).' LIMIT 0,1) AND or_ordini.id IN (SELECT idordine FROM or_righe_ordini WHERE or_righe_ordini.idordine = or_ordini.id AND (qta - qta_evasa) > 0) ORDER BY data DESC, numero DESC" ]} -
-
'; +
+
+ {[ "type": "select", "label": "'.tr('Ordine').'", "name": "id_documento", "values": "query=SELECT or_ordini.id, CONCAT(IF(numero_esterno != \'\', numero_esterno, numero), \' del \', DATE_FORMAT(data, \'%d-%m-%Y\')) AS descrizione FROM or_ordini WHERE idanagrafica='.prepare($idanagrafica).' AND idstatoordine IN (SELECT id FROM or_statiordine WHERE descrizione IN(\'Bozza\', \'Evaso\', \'Parzialmente evaso\', \'Parzialmente fatturato\')) AND idtipoordine=(SELECT id FROM or_tipiordine WHERE dir='.prepare($dir).' LIMIT 0,1) AND or_ordini.id IN (SELECT idordine FROM or_righe_ordini WHERE or_righe_ordini.idordine = or_ordini.id AND (qta - qta_evasa) > 0) ORDER BY data DESC, numero DESC" ]} +
+
+
+
+

'.tr('Informazioni di importazione').'

+
+
+
+
+ +
+ '.tr('Caricamento in corso').'... +
'; + +$file = basename(__FILE__); echo ' -
-
-
'; - -echo ' - '; - -?> - + + +'; diff --git a/modules/fatture/add_preventivo.php b/modules/fatture/add_preventivo.php index 4d95c0a8d..e93882797 100644 --- a/modules/fatture/add_preventivo.php +++ b/modules/fatture/add_preventivo.php @@ -4,93 +4,80 @@ include_once __DIR__.'/../../core.php'; $module = Modules::get($id_module); -if ($module['name'] == 'Fatture di vendita') { - $dir = 'entrata'; - $conti = 'conti-vendite'; -} else { - $dir = 'uscita'; - $conti = 'conti-acquisti'; +if (get('op')) { + $options = [ + 'op' => 'add_preventivo', + 'id_importazione' => 'id_preventivo', + 'final_module' => $module['name'], + 'original_module' => 'Preventivi', + 'sql' => [ + 'table' => 'co_preventivi', + 'rows' => 'co_righe_preventivi', + 'id_rows' => 'idpreventivo', + ], + 'serials' => false, + 'button' => tr('Aggiungi'), + 'dir' => $dir, + ]; + + $result = [ + 'id_record' => $id_record, + 'id_documento' => get('iddocumento'), + ]; + + echo App::load('importa.php', $result, $options, true); + + return; } -$info = $dbo->fetchOne('SELECT * FROM co_documenti WHERE id='.prepare($id_record)); -$numero = ($info['numero_esterno'] != '') ? $info['numero_esterno'] : $info['numero']; -$idanagrafica = $info['idanagrafica']; - -$idconto = ($dir == 'entrata') ? setting('Conto predefinito fatture di vendita') : setting('Conto predefinito fatture di acquisto'); - -/* - Form di inserimento riga documento -*/ echo ' -

'.tr('Documento numero _NUM_', [ - '_NUM_' => $numero, -]).'

- -
- - - '; - -// Preventivo -$_SESSION['superselect']['stati'] = [ - 'Accettato', - 'In lavorazione', - 'In attesa di conferma', -]; -$_SESSION['superselect']['non_fatturato'] = 1; - -echo ' -
-
- {[ "type": "select", "label": "'.tr('Preventivo').'", "name": "idpreventivo", "required": 1, "ajax-source": "preventivi", "extra": "onchange=\"$data = $(this).selectData(); $(\'#descrizione\').val($data.text); $(\'#prezzo\').val($data.totale - $data.sconto);console.log($data.totale)\"" ]} -
- -
- {[ "type": "checkbox", "label": "'.tr('Importa righe').'", "name": "import", "value": "1", "placeholder": "'.tr('Replica righe del preventivo in fattura').'" ]} -
-
'; - -// Descrizione -echo ' -
-
- {[ "type": "textarea", "label": "'.tr('Descrizione').'", "name": "descrizione", "required": 1 ]} -
-
'; - -// Leggo l'iva predefinita dall'articolo e se non c'è leggo quella predefinita generica -$idiva = $idiva ?: setting('Iva predefinita'); - -// Iva -echo ' -
-
- {[ "type": "select", "label": "'.tr('Iva').'", "name": "idiva", "required": 1, "value": "'.$idiva.'", "ajax-source": "iva" ]} -
'; - -echo ' -
- {[ "type": "select", "label": "'.tr('Conto').'", "name": "idconto", "required": 1, "value": "'.$idconto.'", "ajax-source": "'.$conti.'" ]} -
-
'; - -// Costo unitario -echo ' -
-
- {[ "type": "number", "label": "'.tr('Costo unitario').'", "name": "prezzo", "required": 1, "icon-after": "€", "disabled": 1 ]} -
-
'; - -echo ' - - -
-
- -
+
+
+ {[ "type": "select", "label": "'.tr('Preventivo').'", "name": "id_documento", "ajax-source": "preventivi" ]}
-'; +
+
+
+

'.tr('Informazioni di importazione').'

+
+
+
+
+ +
+ '.tr('Caricamento in corso').'... +
'; + +$file = basename(__FILE__); echo ' - '; + + +'; diff --git a/modules/fatture/buttons.php b/modules/fatture/buttons.php index 4308304c0..97e70b307 100644 --- a/modules/fatture/buttons.php +++ b/modules/fatture/buttons.php @@ -13,10 +13,10 @@ echo ' '.tr('Duplica fattura').' '; -if ($dir == 'entrata' && empty($record['ref_documento']) && $record['stato'] == 'Emessa') { +if ($dir == 'entrata') { echo '
- diff --git a/modules/fatture/crea_documento.php b/modules/fatture/crea_documento.php index 528dca6e6..10b1ee359 100644 --- a/modules/fatture/crea_documento.php +++ b/modules/fatture/crea_documento.php @@ -4,340 +4,29 @@ include_once __DIR__.'/../../core.php'; $module = Modules::get($id_module); -$data = [ - 'ddt' => [ - 'table' => 'dt_ddt', // Tabella del documento - 'rows' => 'dt_righe_ddt', // Tabella delle righe - 'id' => 'idddt', // ID nella tabella delle righe - 'condition' => '(id_riga_documento IS NOT NULL)', // Condizione per i seriali - ], - 'ord' => [ - 'table' => 'or_ordini', - 'rows' => 'or_righe_ordini', - 'id' => 'idordine', - 'condition' => '(id_riga_ddt IS NOT NULL OR id_riga_documento IS NOT NULL)', - ], - 'fat' => [ +$options = [ + 'op' => 'nota_credito', + 'id_importazione' => 'id_documento', + 'final_module' => $module['name'], + 'original_module' => $module['name'], + 'sql' => [ 'table' => 'co_documenti', 'rows' => 'co_righe_documenti', - 'id' => 'iddocumento', - 'condition' => '(1 = 2)', - 'allow-empty' => true, + 'id_rows' => 'iddocumento', ], + 'serials' => [ + 'id_riga' => 'id_riga_documento', + 'condition' => '(1 = 2)', + ], + 'button' => tr('Aggiungi'), + 'dir' => $dir, + 'create_document' => true, + 'allow-empty' => true, ]; -$documento = get('documento'); +$result = [ + 'id_record' => $id_record, + 'id_documento' => get('iddocumento'), +]; -if ($module['name'] == 'Ordini cliente' || $module['name'] == 'Ordini fornitore') { - $pos = 'ord'; - $op = ($documento == 'ddt') ? 'ddt_da_ordine' : 'fattura_da_ordine'; - - $head = tr('Ordine numero _NUM_'); - - $dir = ($module['name'] == 'Ordini cliente') ? 'entrata' : 'uscita'; -} elseif ($module['name'] == 'Ddt di vendita' || $module['name'] == 'Ddt di acquisto') { - $pos = 'ddt'; - $op = 'fattura_da_ddt'; - - $head = tr('Ddt numero _NUM_'); - - $dir = ($module['name'] == 'Ddt di vendita') ? 'entrata' : 'uscita'; -} else { - $pos = 'fat'; - $op = 'nota_credito'; - - $head = tr('Fattura numero _NUM_'); - - $dir = 'entrata'; -} - -$table = $data[$pos]['table']; -$rows = $data[$pos]['rows']; -$id = $data[$pos]['id']; -$row = str_replace('id', 'id_riga_', $id); - -if ($module['name'] == 'Ordini cliente') { - $module_name = ($documento == 'ddt') ? 'Ddt di vendita' : 'Fatture di vendita'; -} elseif ($module['name'] == 'Ordini fornitore') { - $module_name = ($documento == 'ddt') ? 'Ddt di acquisto' : 'Fatture di acquisto'; -} elseif ($module['name'] == 'Ddt di acquisto') { - $module_name = 'Fatture di acquisto'; -} else { - $module_name = 'Fatture di vendita'; -} - -$op = !empty(get('op')) ? get('op') : $op; - -$button = ($documento == 'ddt') ? tr('Crea ddt') : tr('Crea fattura'); -$button = !empty(get('op')) ? tr('Aggiungi') : $button; - -// Info documento -$rs = $dbo->fetchArray('SELECT * FROM '.$table.' WHERE id='.prepare($id_record)); -$numero = !empty($rs[0]['numero_esterno']) ? $rs[0]['numero_esterno'] : $rs[0]['numero']; -$idanagrafica = $rs[0]['idanagrafica']; -$idpagamento = $rs[0]['idpagamento']; -$idconto = $rs[0]['idconto']; - -if (empty($idconto)) { - $idconto = ($dir == 'entrata') ? setting('Conto predefinito fatture di vendita') : setting('Conto predefinito fatture di acquisto'); -} - -/* - Form di inserimento riga documento -*/ -echo ' -

'.str_replace('_NUM_', $numero, $head).'.

'; - -// Selezione articoli dell'ordine da portare nel ddt -$rs = $dbo->fetchArray('SELECT *, IFNULL((SELECT codice FROM mg_articoli WHERE id=idarticolo),"") AS codice, (qta - qta_evasa) AS qta_rimanente FROM '.$table.' INNER JOIN '.$rows.' ON '.$table.'.id='.$rows.'.'.$id.' WHERE '.$table.'.id='.prepare($id_record).' HAVING qta_rimanente > 0 OR is_descrizione = 1 ORDER BY `order`'); - -if (!empty($rs)) { - echo ' -

'.tr('Seleziona le righe e le relative quantità da inserire nel documento').'.

- -
- - - - - - - - - '; - - if (empty(get('op'))) { - echo ' -
- -
- {[ "type": "date", "label": "'.tr('Data del documento').'", "name": "data", "required": 1, "value": "-now-" ]} -
'; - - if ($module_name == 'Fatture di vendita' || $module_name == 'Fatture di acquisto') { - $rs_segment = $dbo->fetchArray("SELECT * FROM zz_segments WHERE predefined_accredito='1'"); - if ($op == 'nota_accredito' && sizeof($rs_segment) > 0) { - echo ' -
- {[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='.prepare(Modules::get($module_name)['id']).' ORDER BY name", "value": "'.$rs_segment[0]['id'].'" ]} -
'; - } else { - echo ' -
- {[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='.prepare(Modules::get($module_name)['id']).' ORDER BY name", "value": "'.$_SESSION['module_'.Modules::get($module_name)['id']]['id_segment'].'" ]} -
'; - } - } - - echo - '
'; - } - - echo ' -
-
- - - - - - - - - '; - - $totale = 0.00; - - foreach ($rs as $i => $r) { - // Descrizione - echo ' - - '; - - // Q.tà rimanente - echo ' - '; - - // Q.tà da evadere - echo ' - '; - - // Subtotale - $subtotale = $r['subtotale'] / $r['qta'] * ($r['qta'] - $r['qta_evasa']); - $sconto = $r['sconto'] / $r['qta'] * ($r['qta'] - $r['qta_evasa']); - $iva = $r['iva'] / $r['qta'] * ($r['qta'] - $r['qta_evasa']); - - echo ' - '; - - // Seriali - echo ' - - '; - - $totale += $subtotale - $sconto + $iva; - } - - // Totale - echo ' - - - - -
'.tr('Descrizione').''.tr('Q.tà').''.tr('Q.tà da evadere').''.tr('Subtot.').''.tr('Seriali').'
- - - - '; - - // Checkbox - da evadere? - echo ' - '; - - $descrizione = (!empty($r['codice']) ? $r['codice'].' - ' : '').$r['descrizione']; - - echo ' '.nl2br($descrizione); - - echo ' - - - -

'.Translator::numberToLocale($r['qta_rimanente']).'

-
- {[ "type": "number", "name": "qta_da_evadere['.$r['id'].']", "id": "qta_'.$i.'", "required": 1, "value": "'.$r['qta_rimanente'].'", "extra" : "onkeyup=\"ricalcola_subtotale_riga('.$i.');\"", "decimals": "qta", "min-value": "0", "extra": "'.(($r['is_descrizione']) ? 'readonly' : '').'" ]} - - - - - - - '.Translator::numberToLocale($subtotale - $sconto + $iva).' €
- - '.Translator::numberToLocale($subtotale - $sconto).' + '.Translator::numberToLocale($iva).' -
'; - if (!empty($r['abilita_serial'])) { - $query = 'SELECT DISTINCT serial AS id, serial AS descrizione FROM mg_prodotti WHERE dir='.prepare($dir).' AND '.$row.' = '.prepare($r['id']).' AND serial IS NOT NULL AND serial NOT IN (SELECT serial FROM mg_prodotti AS t WHERE serial IS NOT NULL AND dir='.prepare($dir).' AND '.$data[$pos]['condition'].')'; - - $values = $dbo->fetchArray($query); - if (!empty($values)) { - echo ' - {[ "type": "select", "name": "serial['.$r['id'].'][]", "id": "serial_'.$i.'", "multiple": 1, "values": "query='.$query.'", "value": "'.implode(',', array_column($values, 'id')).'", "extra": "data-maximum=\"'.intval($r['qta_rimanente']).'\"" ]}'; - } else { - echo '-'; - } - } else { - echo '-'; - } - echo ' -
- '.tr('Totale').': - - '.Translator::numberToLocale($totale).' € -
'; - - echo ' - - -
-
- -
-
-
'; -} else { - echo ' -

'.tr('Non ci sono articoli da evadere').'...

'; -} - -echo ' - '; - -?> - - +echo App::load('importa.php', $result, $options, true); diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php index fcd500bd2..8d2ec5809 100644 --- a/modules/fatture/edit.php +++ b/modules/fatture/edit.php @@ -432,7 +432,7 @@ if ($record['stato'] != 'Pagato' && $record['stato'] != 'Emessa') {
'; // Lettura preventivi accettati, in attesa di conferma o in lavorazione - $prev_query = 'SELECT COUNT(*) AS tot FROM co_preventivi WHERE idanagrafica='.prepare($record['idanagrafica'])." AND id NOT IN (SELECT idpreventivo FROM co_righe_documenti WHERE idpreventivo IS NOT NULL) AND id NOT IN (SELECT idpreventivo FROM or_righe_ordini WHERE NOT idpreventivo IS NOT NULL) AND idstato IN(SELECT id FROM co_statipreventivi WHERE descrizione='Accettato' OR descrizione='In lavorazione' OR descrizione='In attesa di conferma') AND default_revision=1"; + $prev_query = 'SELECT COUNT(*) AS tot FROM co_preventivi WHERE idanagrafica='.prepare($record['idanagrafica'])." AND idstato IN(SELECT id FROM co_statipreventivi WHERE descrizione='Accettato' OR descrizione='In lavorazione' OR descrizione='In attesa di conferma') AND default_revision=1 AND co_preventivi.id IN (SELECT idpreventivo FROM co_righe_preventivi WHERE co_righe_preventivi.idpreventivo = co_preventivi.id AND (qta - qta_evasa) > 0)"; $preventivi = $dbo->fetchArray($prev_query)[0]['tot']; echo '
@@ -442,7 +442,7 @@ if ($record['stato'] != 'Pagato' && $record['stato'] != 'Emessa') {
'; // Lettura contratti accettati, in attesa di conferma o in lavorazione - $contr_query = 'SELECT COUNT(*) AS tot FROM co_contratti WHERE idanagrafica='.prepare($record['idanagrafica']).' AND id NOT IN (SELECT idcontratto FROM co_righe_documenti WHERE idcontratto IS NOT NULL) AND idstato IN( SELECT id FROM co_staticontratti WHERE fatturabile = 1) AND NOT EXISTS (SELECT id FROM co_righe_documenti WHERE co_righe_documenti.idcontratto = co_contratti.id)'; + $contr_query = 'SELECT COUNT(*) AS tot FROM co_contratti WHERE idanagrafica='.prepare($record['idanagrafica']).' AND idstato IN( SELECT id FROM co_staticontratti WHERE fatturabile = 1) AND co_contratti.id IN (SELECT idcontratto FROM co_righe_contratti WHERE co_righe_contratti.idcontratto = co_contratti.id AND (qta - qta_evasa) > 0)'; $contratti = $dbo->fetchArray($contr_query)[0]['tot']; echo '
diff --git a/modules/fatture/src/Components/Articolo.php b/modules/fatture/src/Components/Articolo.php index d03256ee8..861294704 100644 --- a/modules/fatture/src/Components/Articolo.php +++ b/modules/fatture/src/Components/Articolo.php @@ -11,6 +11,7 @@ class Articolo extends Article use RelationTrait; protected $table = 'co_righe_documenti'; + protected $serialRowID = 'documento'; /** * Crea un nuovo articolo collegato ad una fattura. diff --git a/modules/interventi/add.php b/modules/interventi/add.php index ac3fe410d..44265b803 100644 --- a/modules/interventi/add.php +++ b/modules/interventi/add.php @@ -5,7 +5,6 @@ include_once __DIR__.'/../../core.php'; // Rimuovo session usate sui select combinati (sedi, preventivi, contratti, impianti) unset($_SESSION['superselect']['idanagrafica']); unset($_SESSION['superselect']['idsede']); -unset($_SESSION['superselect']['non_fatturato']); // Calcolo del nuovo codice $new_codice = \Modules\Interventi\Intervento::getNextCodice(); diff --git a/modules/interventi/src/Intervento.php b/modules/interventi/src/Intervento.php index 5f90f09ce..09bafee2a 100644 --- a/modules/interventi/src/Intervento.php +++ b/modules/interventi/src/Intervento.php @@ -4,6 +4,7 @@ namespace Modules\Interventi; use Common\Document; use Modules\Anagrafiche\Anagrafica; +use Modules\Contratti\Contratto; use Modules\Interventi\Components\Articolo; use Modules\Interventi\Components\Riga; use Modules\Preventivi\Preventivo; @@ -46,7 +47,12 @@ class Intervento extends Document public function preventivo() { - return $this->hasOne(Preventivo::class, 'id_preventivo'); + return $this->belongsTo(Preventivo::class, 'id_preventivo'); + } + + public function contratto() + { + return $this->belongsTo(Contratto::class, 'id_contratto'); } public function stato() diff --git a/modules/ordini/actions.php b/modules/ordini/actions.php index 73c7bc340..87fcbb9b1 100644 --- a/modules/ordini/actions.php +++ b/modules/ordini/actions.php @@ -22,11 +22,8 @@ switch (post('op')) { $idanagrafica = post('idanagrafica'); $data = post('data'); - // Leggo se l'ordine è cliente o fornitore - $tipo = $dbo->fetchOne('SELECT id FROM or_tipiordine WHERE dir='.prepare($dir)); - $anagrafica = Anagrafica::find($idanagrafica); - $tipo = Tipo::find($tipo['id']); + $tipo = Tipo::where('dir', $dir)->first(); $ordine = Ordine::build($anagrafica, $tipo, $data); $id_record = $ordine->id; @@ -347,88 +344,51 @@ switch (post('op')) { break; - case 'ordine_da_preventivo': + // Aggiunta di un preventivo in ordine + case 'add_preventivo': + $preventivo = \Modules\Preventivi\Preventivo::find(post('id_preventivo')); - $idanagrafica = post('idanagrafica'); - $idpreventivo = post('idpreventivo'); + // Creazione della fattura al volo + if (post('create_document') == 'on') { + $tipo = Tipo::where('dir', $dir)->first(); - $data = post('data'); + $ordine = Ordine::build($preventivo->anagrafica, $tipo, date('Y-m-d'), post('id_segment')); + $ordine->idpagamento = $preventivo->idpagamento; + $ordine->save(); - // Leggo se l'ordine è cliente o fornitore - $rs = $dbo->fetchArray('SELECT id FROM or_tipiordine WHERE dir='.prepare($dir)); - $idtipoordine = $rs[0]['id']; + $id_record = $ordine->id; + } - if (post('idanagrafica') !== null) { - $numero = get_new_numeroordine($data); - if ($dir == 'entrata') { - $numero_esterno = get_new_numerosecondarioordine($data); - } else { - $numero_esterno = ''; - } + $parziale = false; - $campo = ($dir == 'entrata') ? 'idpagamento_vendite' : 'idpagamento_acquisti'; + $id_iva = get('id_iva'); + $id_conto = get('id_conto'); + $righe = $preventivo->getRighe(); + foreach ($righe as $riga) { + if (post('evadere')[$riga->id] == 'on') { + $qta = post('qta_da_evadere')[$riga->id]; - // Tipo di pagamento predefinito dall'anagrafica - $query = 'SELECT id FROM co_pagamenti WHERE id=(SELECT '.$campo.' AS pagamento FROM an_anagrafiche WHERE idanagrafica='.prepare($idanagrafica).')'; - $rs = $dbo->fetchArray($query); - $idpagamento = isset($rs[0]) ? $rs[0]['id'] : null; + $copia = $riga->copiaIn($ordine, $qta); + $copia->id_iva = $id_iva; + $copia->id_conto = $id_conto; - // Se l'ordine è un ordine cliente e non è stato associato un pagamento predefinito al cliente leggo il pagamento dalle impostazioni - if ($dir == 'entrata' && empty($idpagamento)) { - $idpagamento = setting('Tipo di pagamento predefinito'); - } - - $query = 'INSERT INTO or_ordini( numero, numero_esterno, idanagrafica, idtipoordine, idpagamento, data, idstatoordine ) VALUES ( '.prepare($numero).', '.prepare($numero_esterno).', '.prepare($idanagrafica).', '.prepare($idtipoordine).', '.prepare($idpagamento).', '.prepare($data).", (SELECT `id` FROM `or_statiordine` WHERE `descrizione`='Bozza') )"; - $dbo->query($query); - - $id_record = $dbo->lastInsertedID(); - - flash()->info(tr('Aggiunto ordine numero _NUM_!', [ - '_NUM_' => $numero, - ])); - - // Lettura di tutte le righe della tabella in arrivo - // Inserisco anche le righe descrittive - foreach (post('evadere') as $i => $value) { - // Processo solo le righe da evadere - if (post('evadere')[$i] == 'on') { - $descrizione = post('descrizione')[$i]; - $prezzo = post('subtot')[$i]; - $qta = post('qta_da_evadere')[$i]; - $idiva = post('idiva')[$i]; - $um = post('um')[$i]; - $subtot = $prezzo * $qta; - $idarticolo = post('idarticolo')[$i]; - $sconto = post('sconto')[$i]; - - // Ottengo le informazioni sullo sconto - $qprc = 'SELECT tipo_sconto, sconto_unitario FROM co_righe_preventivi WHERE id='.prepare($i); - $rsprc = $dbo->fetchArray($qprc); - - $sconto_unitario = $rsprc[0]['sconto_unitario']; - $tipo_sconto = $rsprc[0]['tipo_sconto']; - - $sconto = $sconto * $qta; - - // Calcolo iva - $query = 'SELECT descrizione, percentuale, indetraibile FROM co_iva WHERE id='.prepare($idiva); - $rs = $dbo->fetchArray($query); - $iva = ($subtot - $sconto) / 100 * $rs[0]['percentuale']; - $iva_indetraibile = $iva / 100 * $rs[0]['indetraibile']; - - $query = 'INSERT INTO or_righe_ordini(idordine, idarticolo, idpreventivo, idiva, desc_iva, iva, iva_indetraibile, descrizione, subtotale, sconto, sconto_unitario, tipo_sconto, um, qta, is_descrizione, `order`) VALUES('.prepare($id_record).', '.prepare($idarticolo).', '.prepare($idpreventivo).', '.prepare($idiva).', '.prepare($rs[0]['descrizione']).', '.prepare($iva).', '.prepare($iva_indetraibile).', '.prepare($descrizione).', '.prepare($subtot).', '.prepare($sconto).', '.prepare($sconto_unitario).', '.prepare($tipo_sconto).', '.prepare($um).', '.prepare($qta).', '.prepare(empty($qta)).', (SELECT IFNULL(MAX(`order`) + 1, 0) FROM or_righe_ordini AS t WHERE idordine='.prepare($id_record).'))'; - $dbo->query($query); + // Aggiornamento seriali dalla riga dell'ordine + if ($copia->isArticolo()) { + $copia->movimenta($copia->qta); } } - // Ricalcolo inps, ritenuta e bollo - if ($dir == 'entrata') { - ricalcola_costiagg_ordine($id_record); - } else { - ricalcola_costiagg_ordine($id_record); + if ($riga->qta != $riga->qta_evasa) { + $parziale = true; } } + ricalcola_costiagg_ordine($id_record); + + flash()->info(tr('Preventivo _NUM_ aggiunto!', [ + '_NUM_' => $preventivo->numero, + ])); + break; } diff --git a/modules/ordini/buttons.php b/modules/ordini/buttons.php index 9681ab6fd..955a6c975 100644 --- a/modules/ordini/buttons.php +++ b/modules/ordini/buttons.php @@ -2,32 +2,26 @@ include_once __DIR__.'/../../core.php'; -if (!in_array($record['stato'], ['Fatturato'])) { - echo ' - '; -} +
  • +  '.tr('fattura').' + +
  • '; + + echo ' + +
    '; diff --git a/modules/ordini/crea_documento.php b/modules/ordini/crea_documento.php index dfce55d91..098096f88 100644 --- a/modules/ordini/crea_documento.php +++ b/modules/ordini/crea_documento.php @@ -4,268 +4,36 @@ include_once __DIR__.'/../../core.php'; $module = Modules::get($id_module); -$data = [ - 'preventivo' => [ - 'table' => 'co_preventivi', - 'rows' => 'co_righe_preventivi', - 'id' => 'idpreventivo', - 'condition' => '', - ], -]; - -$documento = get('documento'); - -$pos = 'preventivo'; -$op = 'ordine_da_preventivo'; - -$head = tr('Preventivo numero _NUM_'); - -$table = $data[$pos]['table']; -$rows = $data[$pos]['rows']; -$id = $data[$pos]['id']; -$row = str_replace('id', 'id_riga_', $id); - -$module_name = 'Ordini cliente'; - -$op = !empty(get('op')) ? get('op') : $op; - -$button = tr('Crea ordine'); -$button = !empty(get('op')) ? tr('Aggiungi') : $button; - -// Info documento -$rs = $dbo->fetchArray('SELECT * FROM '.$table.' WHERE id='.prepare($id_record)); -$numero = !empty($rs[0]['numero_esterno']) ? $rs[0]['numero_esterno'] : $rs[0]['numero']; -$idanagrafica = $rs[0]['idanagrafica']; -$idsede = $rs[0]['idsede']; -$idpagamento = $rs[0]['idpagamento']; -$idconto = $rs[0]['idconto']; - -/* - Form di inserimento riga documento -*/ -echo ' -

    '.str_replace('_NUM_', $numero, $head).'.

    '; - -// Selezione articoli del preventivo da copiare nell'ordine, usando l'ordinamento scelto dall'utente -$rs = $dbo->fetchArray('SELECT * FROM '.$table.' INNER JOIN '.$rows.' ON '.$table.'.id='.$rows.'.'.$id.' WHERE '.$table.'.id='.prepare($id_record).' ORDER BY `order`'); - -if (!empty($rs)) { - echo ' -

    '.tr('Seleziona le righe e le relative quantità da inserire nell\'ordine.').'.

    - -
    - - - - - - - - - - -
    - -
    - {[ "type": "date", "label": "'.tr('Data del documento').'", "name": "data", "required": 1, "value": "-now-" ]} -
    -
    - -
    -
    - - - - - - - - - '; - - $totale = 0.00; - - foreach ($rs as $i => $r) { - // Descrizione - echo ' - - '; - - if ($r['is_descrizione']) { - continue; - } - - // Q.tà rimanente - echo ' - '; - - // Q.tà da evadere - echo ' - '; - - // Subtotale - $subtotale = $r['subtotale'] / $r['qta'] * ($r['qta']); - $sconto = $r['sconto'] / $r['qta'] * ($r['qta']); - $iva = $r['iva'] / $r['qta'] * ($r['qta']); - - echo ' - '; - - // Seriali - echo ' - - '; - - $totale += $subtotale - $sconto + $iva; - } - - // Totale - echo ' - - - - -
    '.tr('Descrizione').''.tr('Q.tà').''.tr('Q.tà da evadere').''.tr('Subtot.').''.tr('Seriali').'
    - - - - '; - - // Checkbox - da evadere? - echo ' - '; - - echo nl2br($r['descrizione']); - - echo ' - - - -

    '.Translator::numberToLocale($r['qta'], 'qta').'

    -
    - {[ "type": "number", "name": "qta_da_evadere['.$r['id'].']", "id": "qta_'.$i.'", "required": 1, "value": "'.$r['qta'].'", "extra" : "onkeyup=\"ricalcola_subtotale_riga('.$i.');\"", "decimals": "qta", "min-value": "0" ]} - - - - - - - '.Translator::numberToLocale($subtotale - $sconto + $iva).' €
    - - '.Translator::numberToLocale($subtotale - $sconto).' + '.Translator::numberToLocale($iva).' -
    '; - if (!empty($r['abilita_serial'])) { - $values = $dbo->fetchArray('SELECT DISTINCT serial FROM mg_prodotti WHERE dir=\''.$dir.'\' AND '.$row.' = \''.$r['id'].'\' AND serial IS NOT NULL AND serial NOT IN (SELECT serial FROM mg_prodotti WHERE serial IS NOT NULL AND dir=\''.$dir.'\' AND '.$data[$pos]['condition'].')'); - - echo ' - {[ "type": "select", "name": "serial['.$i.']['.$r['id'].']", "id": "serial_'.$i.'", "multiple": 1, "values": "query=SELECT DISTINCT serial AS id, serial AS descrizione FROM mg_prodotti WHERE dir=\''.$dir.'\' AND '.$row.' = \''.$r['id'].'\' AND serial IS NOT NULL AND serial NOT IN (SELECT serial FROM mg_prodotti WHERE serial IS NOT NULL AND dir=\''.$dir.'\' AND '.$data[$pos]['condition'].')", "value": "'.implode(',', array_column($values, 'serial')).'", "extra": "data-maximum=\"'.intval($r['qta_rimanente']).'\"" ]} - '; - } else { - echo '-'; - } - echo ' -
    - '.tr('Totale').': - - '.Translator::numberToLocale($totale).' € -
    '; - - echo ' - - -
    -
    - -
    -
    -
    '; +if (get('documento') == 'fattura') { + $final_module = $module['name'] == 'Ordini cliente' ? 'Fatture di vendita' : 'Fatture di acquisto'; } else { - echo ' -

    '.tr('Non ci sono articoli da evadere').'...

    '; + $final_module = $module['name'] == 'Ordini cliente' ? 'Ddt di vendita' : 'Ddt di acquisto'; } -echo ' - '; +$dir = $module['name'] == 'Ordini cliente' ? 'entrata' : 'uscita'; -?> +$options = [ + 'op' => 'add_ordine', + 'id_importazione' => 'id_ordine', + 'final_module' => $final_module, + 'original_module' => $module['name'], + 'sql' => [ + 'table' => 'or_ordini', + 'rows' => 'or_righe_ordini', + 'id_rows' => 'idordine', + ], + 'serials' => [ + 'id_riga' => 'id_riga_ordine', + 'condition' => '(id_riga_ddt IS NOT NULL OR id_riga_documento IS NOT NULL)', + ], + 'button' => tr('Aggiungi'), + 'dir' => $dir, + 'create_document' => true, +]; - +echo App::load('importa.php', $result, $options, true); diff --git a/modules/ordini/src/Components/Articolo.php b/modules/ordini/src/Components/Articolo.php index 8f02973d8..d8c6be006 100644 --- a/modules/ordini/src/Components/Articolo.php +++ b/modules/ordini/src/Components/Articolo.php @@ -11,6 +11,7 @@ class Articolo extends Article use RelationTrait; protected $table = 'or_righe_ordini'; + protected $serialRowID = 'ordine'; /** * Crea un nuovo articolo collegato ad una ordine. diff --git a/modules/ordini/src/Components/RelationTrait.php b/modules/ordini/src/Components/RelationTrait.php index ff60c06bc..a315306f2 100644 --- a/modules/ordini/src/Components/RelationTrait.php +++ b/modules/ordini/src/Components/RelationTrait.php @@ -20,4 +20,18 @@ trait RelationTrait { return $this->parent(); } + + /** + * Effettua i conti per la Rivalsa INPS. + */ + protected function fixRivalsaINPS() + { + } + + /** + * Effettua i conti per la Ritenuta d'Acconto, basandosi sul valore del campo calcolo_ritenuta_acconto. + */ + protected function fixRitenutaAcconto() + { + } } diff --git a/modules/preventivi/actions.php b/modules/preventivi/actions.php index eeb9aceb8..936453547 100644 --- a/modules/preventivi/actions.php +++ b/modules/preventivi/actions.php @@ -3,8 +3,6 @@ include_once __DIR__.'/../../core.php'; use Modules\Anagrafiche\Anagrafica; -use Modules\Fatture\Fattura; -use Modules\Fatture\Tipo as TipoFattura; use Modules\Interventi\TipoSessione; use Modules\Preventivi\Components\Articolo; use Modules\Preventivi\Components\Riga; @@ -368,36 +366,6 @@ switch (post('op')) { flash()->info(tr('Aggiunta nuova revisione!')); break; - - // Creazione fattura da preventivo - case 'fattura_da_preventivo': - $preventivo = Preventivo::find($id_record); - - $tipo = TipoFattura::where('descrizione', 'Fattura immediata di vendita')->first(); - $id_segment = $dbo->fetchOne('SELECT * FROM zz_segments WHERE id_module='.prepare($id_module)." AND predefined='1'")['id']; - $data = date('Y-m-d'); - - $fattura = Fattura::build($preventivo->anagrafica, $tipo, $data, $id_segment); - $fattura->idpagamento = $preventivo->idpagamento; - - $id_conto = setting('Conto predefinito fatture di vendita'); - - $righe = $preventivo->getRighe(); - foreach ($righe as $riga) { - $copia = $riga->copiaIn($fattura); - $copia->idconto = $id_conto; - - if ($riga->isArticolo()) { - $copia->movimenta($copia->qta); - } - } - - flash()->info(tr('Creata una nuova fattura!')); - - $id_record = $fattura->id; - $id_module = Modules::get('Fatture di vendita')['id']; - - break; } if (post('op') !== null && post('op') != 'update') { diff --git a/modules/preventivi/ajax/select.php b/modules/preventivi/ajax/select.php index 75edcd740..4538125c2 100644 --- a/modules/preventivi/ajax/select.php +++ b/modules/preventivi/ajax/select.php @@ -11,24 +11,12 @@ switch ($resource) { $filter[] = 'id='.prepare($element); } - $where[] = 'an_anagrafiche.idanagrafica='.prepare($superselect['idanagrafica']); - $where[] = 'co_preventivi.default_revision=1'; + if (empty($elements)) { + $where[] = 'an_anagrafiche.idanagrafica='.prepare($superselect['idanagrafica']); + $where[] = 'co_preventivi.default_revision=1'; - $stati = !empty($superselect['stati']) ? $superselect['stati'] : [ - 'In attesa di conferma', - 'Accettato', - 'In lavorazione', - 'Concluso', - 'In attesa di pagamento', - ]; - $desc = []; - foreach ($stati as $value) { - $desc[] = prepare($value); - } - $where[] = 'idstato IN (SELECT `id` FROM co_statipreventivi WHERE descrizione IN ('.implode(',', $desc).'))'; - - if (!empty($superselect['non_fatturato'])) { - $where[] = 'id NOT IN (SELECT idpreventivo FROM co_righe_documenti WHERE idpreventivo IS NOT NULL)'; + $stato = !empty($superselect['stato']) ? $superselect['stato'] : 'fatturabile'; + $where[] = 'idstato IN (SELECT `id` FROM co_staticontratti WHERE '.$stato.' = 1)'; } if (!empty($search)) { diff --git a/modules/preventivi/buttons.php b/modules/preventivi/buttons.php index 0a568a642..37931a601 100644 --- a/modules/preventivi/buttons.php +++ b/modules/preventivi/buttons.php @@ -5,33 +5,31 @@ include_once __DIR__.'/../../core.php'; echo' '; -if (!in_array($record['stato'], ['Bozza', 'Rifiutato', 'In attesa di conferma'])) { - $disabled = ''; -} else { +$disabled = $record['fatturabile'] || $record['annullato']; +if (!$disabled) { echo ' '; - $disabled = 'disabled'; } // Creazione altri documenti echo ' -