From 00a5924cbae1a8745c12a24929654cafaf4e50cc Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Fri, 9 Feb 2018 14:00:41 +0100 Subject: [PATCH 1/2] Replica fix da branch 2.4 Replica fix da branch 2.4 per le stampe: risolve i problemi indirizzati da #141 e ottimizza la gestione futura. --- templates/info.php | 43 ++++++++++++++++------------------ templates/pdfgen_variables.php | 5 +++- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/templates/info.php b/templates/info.php index 7b26d36a9..d9ec66706 100644 --- a/templates/info.php +++ b/templates/info.php @@ -33,19 +33,7 @@ $keys = []; // Predisposizione delle informazioni delle anagrafiche per la sostituzione automatica foreach ($replace as $prefix => $values) { - // Individuazione dei campi minimi $values = (array) $values; - if ($prefix == 'c_') { - $keys = array_keys($values); - } - - // Se l'azienda predefinita non è impostata - if (empty($values) && $prefix == 'f_') { - $values = []; - foreach ($keys as $key) { - $values[$key] = ''; - } - } // Rinominazione dei campi foreach ($rename as $key => $value) { @@ -53,11 +41,6 @@ foreach ($replace as $prefix => $values) { unset($values[$key]); } - // Salvataggio dei campi come variabili PHP - foreach ($values as $key => $value) { - ${$prefix.$key} = $value; - } - // Eventuali estensioni dei contenuti $citta = ''; if (!empty($values['cap'])) { @@ -72,23 +55,37 @@ foreach ($replace as $prefix => $values) { $values['citta_full'] = $citta; - // Completamento dei campi minimi - if ($key == 'c_') { - $keys = array_unique(array_merge($keys, array_keys($values))); + $replace[$prefix] = $values; + + // Individuazione dei campi minimi + $keys = array_merge($keys, array_keys($values)); +} + +$keys = array_unique($keys); + +foreach ($replace as $prefix => $values) { + // Impostazione di default per le informazioni mancanti + foreach ($keys as $key) { + if (!isset($values[$key])) { + $values[$key] = ''; + } } - // Aggiunta delle informazioni per la sostituzione automatica + // Salvataggio dei campi come variabili PHP e aggiunta delle informazioni per la sostituzione automatica foreach ($values as $key => $value) { + ${$prefix.$key} = $value; $replaces[$prefix.$key] = $value; } } // Valori aggiuntivi per la sostituzione $replaces = array_merge($replaces, [ + 'default_header' => include DOCROOT.'/templates/base/header.php', + 'default_footer' => include DOCROOT.'/templates/base/footer.php', 'docroot' => DOCROOT, 'rootdir' => ROOTDIR, 'footer' => !empty($footer) ? $footer : '', 'dicitura_fissa_fattura' => get_var('Dicitura fissa fattura'), - 'default_header' => include DOCROOT.'/templates/base/header.php', - 'default_footer' => include DOCROOT.'/templates/base/footer.php', ]); + +unset($replace); diff --git a/templates/pdfgen_variables.php b/templates/pdfgen_variables.php index e0780c61a..8f16613dd 100644 --- a/templates/pdfgen_variables.php +++ b/templates/pdfgen_variables.php @@ -3,7 +3,10 @@ include_once __DIR__.'/info.php'; // Retrocompatibilità con le stampe gestite da HTML2PDF -$replaces['pagination'] = str_replace(['{PAGENO}', '{nb}'], ['[[page_cu]]', '[[page_nb]]'], $replaces['pagination']); +$replaces['default_header'] = str_replace(['{PAGENO}', '{nb}'], ['[[page_cu]]', '[[page_nb]]'], $replaces['default_header']); + +$replaces['footer'] = str_replace(['{PAGENO}', '{nb}'], ['[[page_cu]]', '[[page_nb]]'], $replaces['footer']); +$replaces['default_footer'] = str_replace(['{PAGENO}', '{nb}'], ['[[page_cu]]', '[[page_nb]]'], $replaces['default_footer']); $prefixes = [ 'c_', From 2129106a4b3b307a087d8d4b20025bc1aa33c3a6 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Fri, 9 Feb 2018 14:25:40 +0100 Subject: [PATCH 2/2] Miglioria #139 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correzione delle query per la selezione degli articoli, con rimozione del limite di quantità per gli articoli nelle Fatture di Acquisto. Ottimizzazione delle query per l'individuazione della presenza di Articoli, DDT, ... Grazie a @dariosera e @xxfuma85xx --- ajax_select.php | 6 ++--- modules/articoli/modutil.php | 6 ++--- modules/fatture/edit.php | 52 ++++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/ajax_select.php b/ajax_select.php index 366e76edf..4ca1eaa1d 100644 --- a/ajax_select.php +++ b/ajax_select.php @@ -231,9 +231,9 @@ switch ($op) { $filter[] = 'mg_articoli.id='.prepare($element); } - $where[] = 'attivo=1'; + $where[] = 'attivo = 1'; if (!empty($superselect['dir']) && $superselect['dir'] == 'entrata') { - //$where[] = 'qta>0'; + //$where[] = '(qta > 0 OR servizio = 1)'; } if (!empty($search)) { @@ -241,7 +241,6 @@ switch ($op) { $search_fields[] = 'mg_articoli.codice LIKE '.prepare('%'.$search.'%'); } - $wh = ''; if (!empty($search_fields)) { $where[] = '('.implode(' OR ', $search_fields).')'; } @@ -250,6 +249,7 @@ switch ($op) { $where[] = '('.implode(' OR ', $filter).')'; } + $wh = ''; if (count($where) != 0) { $wh = 'WHERE '.implode(' AND ', $where); } diff --git a/modules/articoli/modutil.php b/modules/articoli/modutil.php index 73f71e13f..dabab38f7 100644 --- a/modules/articoli/modutil.php +++ b/modules/articoli/modutil.php @@ -12,7 +12,7 @@ function add_movimento_magazzino($idarticolo, $qta, $array = [], $descrizone = ' if (empty($qta)) { return false; } - + //Info Articolo $rs_art = $dbo->fetchArray("SELECT * FROM mg_articoli WHERE id='".$idarticolo."'"); @@ -79,9 +79,9 @@ function add_movimento_magazzino($idarticolo, $qta, $array = [], $descrizone = ' $movimento = str_replace(['_NAME_', '_TYPE_', '_NUM_'], [$nome, $tipo, $numero], $movimento); $new = ($qta > 0 ? '+' : '').$qta; - + //Movimento il magazzino solo se l'articolo non è un servizio - if($rs_art[0]['servizio']==0){ + if ($rs_art[0]['servizio'] == 0) { // Movimentazione effettiva if (empty($array['idintervento']) || empty($array['idautomezzo'])) { $dbo->query('UPDATE mg_articoli SET qta = qta + '.$new.' WHERE id = '.prepare($idarticolo)); diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php index 2b24704c2..7aad27565 100644 --- a/modules/fatture/edit.php +++ b/modules/fatture/edit.php @@ -7,6 +7,7 @@ $dir = $rs[0]['dir']; $tipodoc = $rs[0]['descrizione']; $_SESSION['superselect']['idanagrafica'] = $records[0]['idanagrafica']; +$_SESSION['superselect']['ddt'] = $dir; ?>
@@ -17,12 +18,12 @@ $_SESSION['superselect']['idanagrafica'] = $records[0]['idanagrafica']; - +
-

+

@@ -42,7 +43,7 @@ $_SESSION['superselect']['idanagrafica'] = $records[0]['idanagrafica'];
'; $label = tr('Numero secondario'); } else { - $label = tr('Numero fattura'); + $label = tr('Numero fattura'); } ?>
@@ -109,7 +110,7 @@ $_SESSION['superselect']['idanagrafica'] = $records[0]['idanagrafica'];
- {[ "type": "select", "label": "", "name": "idtipodocumento", "required": 1, "values": "query=SELECT id, descrizione FROM co_tipidocumento WHERE dir=''", "value": "$idtipodocumento$" ]} + {[ "type": "select", "label": "", "name": "idtipodocumento", "required": 1, "values": "query=SELECT id, descrizione FROM co_tipidocumento WHERE dir=''", "value": "$idtipodocumento$" ]}
@@ -120,7 +121,7 @@ $_SESSION['superselect']['idanagrafica'] = $records[0]['idanagrafica']; $ajaxsource = 'conti-acquisti'; } ?> - {[ "type": "select", "label": "", "name": "idconto", "required": 1, "value": "$idconto$", "ajax-source": "" ]} + {[ "type": "select", "label": "", "name": "idconto", "required": 1, "value": "$idconto$", "ajax-source": "" ]}
@@ -191,13 +192,13 @@ $da_pagare = $rs3[0]['da_pagare']; if (($n2 <= 0 && $records[0]['stato'] == 'Emessa') || $differenza != 0) { ?> - Aggiungi prima nota...

+ ...

- Riapri fattura... + ... @@ -206,7 +207,7 @@ if ($records[0]['stato'] == 'Pagato') {
- {[ "type": "number", "label": "", "name": "sconto_generico", "value": "$sconto_globale$", "help": "", "icon-after": "choice|untprc|$tipo_sconto_globale$"", "name": "sconto_generico", "value": "$sconto_globale$", "help": "", "icon-after": "choice|untprc|$tipo_sconto_globale$"fetchNum($qi); + $int_query = 'SELECT COUNT(*) AS tot FROM in_interventi WHERE idanagrafica='.prepare($records[0]['idanagrafica'])." AND NOT idstatointervento='DENY' AND id NOT IN (SELECT idintervento FROM co_righe_documenti WHERE idintervento IS NOT NULL) AND id NOT IN (SELECT idintervento FROM co_preventivi_interventi WHERE idintervento IS NOT NULL) AND id NOT IN (SELECT idintervento FROM co_righe_contratti WHERE idintervento IS NOT NULL)"; + $interventi = $dbo->fetchArray($int_query)[0]['tot']; // Se non trovo niente provo a vedere se ce ne sono per clienti terzi if (empty($interventi)) { // Lettura interventi non rifiutati, non fatturati e non collegati a preventivi o contratti (clienti terzi) - $qi = 'SELECT id FROM in_interventi WHERE idclientefinale='.prepare($records[0]['idanagrafica'])." AND NOT idstatointervento='DENY' AND id NOT IN (SELECT idintervento FROM co_righe_documenti WHERE idintervento IS NOT NULL) AND id NOT IN (SELECT idintervento FROM co_preventivi_interventi WHERE idintervento IS NOT NULL) AND id NOT IN (SELECT idintervento FROM co_righe_contratti WHERE idintervento IS NOT NULL)"; - $interventi = $dbo->fetchNum($qi); + $int_query = 'SELECT COUNT(*) AS tot FROM in_interventi WHERE idclientefinale='.prepare($records[0]['idanagrafica'])." AND NOT idstatointervento='DENY' AND id NOT IN (SELECT idintervento FROM co_righe_documenti WHERE idintervento IS NOT NULL) AND id NOT IN (SELECT idintervento FROM co_preventivi_interventi WHERE idintervento IS NOT NULL) AND id NOT IN (SELECT idintervento FROM co_righe_contratti WHERE idintervento IS NOT NULL)"; + $interventi = $dbo->fetchArray($int_query)[0]['tot']; } echo ' @@ -266,16 +267,16 @@ if ($records[0]['stato'] != 'Pagato' && $records[0]['stato'] != 'Emessa') { '; // Lettura preventivi accettati, in attesa di conferma o in lavorazione - $qp = 'SELECT id FROM co_preventivi WHERE idanagrafica='.prepare($records[0]['idanagrafica'])." AND id NOT IN (SELECT idpreventivo FROM co_righe_documenti WHERE NOT idpreventivo=NULL) AND idstato IN( SELECT id FROM co_statipreventivi WHERE descrizione='Accettato' OR descrizione='In lavorazione' OR descrizione='In attesa di conferma')"; - $preventivi = $dbo->fetchNum($qp); + $prev_query = 'SELECT COUNT(*) AS tot FROM co_preventivi WHERE idanagrafica='.prepare($records[0]['idanagrafica'])." AND id NOT IN (SELECT idpreventivo FROM co_righe_documenti WHERE NOT idpreventivo=NULL) AND idstato IN( SELECT id FROM co_statipreventivi WHERE descrizione='Accettato' OR descrizione='In lavorazione' OR descrizione='In attesa di conferma')"; + $preventivi = $dbo->fetchArray($prev_query)[0]['tot']; echo ' Preventivo '; // Lettura contratti accettati, in attesa di conferma o in lavorazione - $qc = 'SELECT id FROM co_contratti WHERE idanagrafica='.prepare($records[0]['idanagrafica']).' AND id NOT IN (SELECT idcontratto FROM co_righe_documenti WHERE NOT idcontratto=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)'; - $contratti = $dbo->fetchNum($qc); + $contr_query = 'SELECT COUNT(*) AS tot FROM co_contratti WHERE idanagrafica='.prepare($records[0]['idanagrafica']).' AND id NOT IN (SELECT idcontratto FROM co_righe_documenti WHERE NOT idcontratto=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)'; + $contratti = $dbo->fetchArray($contr_query)[0]['tot']; echo ' @@ -283,8 +284,8 @@ if ($records[0]['stato'] != 'Pagato' && $records[0]['stato'] != 'Emessa') { '; // Lettura ddt - $qd = 'SELECT id FROM dt_ddt WHERE idanagrafica='.prepare($records[0]['idanagrafica']).' AND idstatoddt IN (SELECT id FROM dt_statiddt WHERE descrizione IN(\'Bozza\', \'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)'; - $ddt = $dbo->fetchNum($qd); + $ddt_query = 'SELECT COUNT(*) AS tot FROM dt_ddt WHERE idanagrafica='.prepare($records[0]['idanagrafica']).' AND idstatoddt IN (SELECT id FROM dt_statiddt WHERE descrizione IN(\'Bozza\', \'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)'; + $ddt = $dbo->fetchArray($ddt_query)[0]['tot']; echo ' Ddt @@ -292,7 +293,12 @@ if ($records[0]['stato'] != 'Pagato' && $records[0]['stato'] != 'Emessa') { } // Lettura articoli - $articoli = $dbo->fetchNum('SELECT * FROM mg_articoli WHERE qta > 0'); + $art_query = 'SELECT COUNT(*) AS tot FROM mg_articoli WHERE attivo = 1'; + if ($dir == 'entrata') { + $art_query .= ' AND (qta > 0 OR servizio = 1)'; + } + + $articoli = $dbo->fetchArray($art_query)[0]['tot']; echo ' Articolo @@ -302,7 +308,7 @@ if ($records[0]['stato'] != 'Pagato' && $records[0]['stato'] != 'Emessa') { Riga generica '; - + echo ' Descrizione @@ -341,11 +347,11 @@ if ($dir == 'entrata') { } else { if ($records[0]['descrizione_tipodoc'] == 'Fattura accompagnatoria di vendita') { ?> - Stampa fattura + Stampa fattura - Stampa fattura + Stampa fattura
-{( "name": "filelist_and_upload", "id_module": "", "id_record": "" )} +{( "name": "filelist_and_upload", "id_module": "", "id_record": "" )}