diff --git a/modules/articoli/widgets/stampa_inventario.php b/modules/articoli/widgets/stampa_inventario.php new file mode 100755 index 000000000..665f3fdcd --- /dev/null +++ b/modules/articoli/widgets/stampa_inventario.php @@ -0,0 +1,31 @@ +fetchOne('SELECT zz_prints.id FROM zz_prints INNER JOIN zz_modules ON zz_prints.id_module=zz_modules.id WHERE zz_modules.name="Articoli" AND zz_prints.name="Inventario magazzino"')['id']; + +echo ' +
+ +'; diff --git a/templates/magazzino_inventario/body.php b/templates/magazzino_inventario/body.php index 074de9eeb..1ec8be6d2 100755 --- a/templates/magazzino_inventario/body.php +++ b/templates/magazzino_inventario/body.php @@ -1,70 +1,43 @@ $_GET['search_codice'], - 'descrizione' => $_GET['search_descrizione'], - 'categoria' => $_GET['search_categoria'], - 'subcategoria' => $_GET['search_subcategoria'], - 'tipo' => $_GET['search_tipo'], - 'fornitore' => $_GET['search_fornitore'], - 'barcode' => $_GET['search_barcode'], -]; +$where['servizio'] = '0'; -foreach ($search as $name => $value) { - if ($value == 'undefined') { - $search[$name] = null; +foreach( $_SESSION['module_'.$id_module] as $name => $value ){ + if( preg_match('/^search_(.+?)$/', $name, $m) ){ + $where[ $m[1] ] = $value; } } -$search['tipo'] = $search['tipo'] ?: 'solo prodotti attivi'; - -// Filtri effettivi -$where = [ - 'deleted_at IS NULL', - 'servizio = 0', -]; -if ($search['tipo'] == 'solo prodotti attivi') { - $where[] = 'attivo = 1'; -} elseif ($search['tipo'] == 'solo prodotti non attivi') { - $where[] = 'attivo = 0'; -} - -if (!empty($search['codice'])) { - $where[] = "(REPLACE(codice, '.', '') LIKE ".prepare('%'.$search['codice'].'%').' OR codice LIKE '.prepare('%'.$search['codice'].'%').')'; -} - -if (!empty($search['descrizione'])) { - $where[] .= "REPLACE(descrizione, '.', '') LIKE ".prepare('%'.$search['descrizione'].'%'); -} - -if (!empty($search['categoria'])) { - $where[] = 'id_categoria IN (SELECT id FROM mg_categorie WHERE nome LIKE '.prepare('%'.$search['categoria'].'%').' AND parent IS NULL)'; -} - -if (!empty($search['subcategoria'])) { - $where[] = 'id_sottocategoria IN (SELECT id FROM mg_categorie WHERE nome LIKE '.prepare('%'.$search['subcategoria'].'%').' AND parent NOT NULL)'; -} - -if (!empty($search['fornitore'])) { - $where[] = 'id_fornitore IN (SELECT idanagrafica FROM an_anagrafiche WHERE ragione_sociale LIKE '.prepare('%'.$search['fornitore'].'%').')'; -} - -if (!empty($search['barcode'])) { - $where[] = "(REPLACE(barcode, '.', '') LIKE ".prepare('%'.$search['barcode'].'%').' OR barcode LIKE '.prepare('%'.$search['barcode'].'%').')'; -} - $period_end = $_SESSION['period_end']; -$query = 'SELECT *, - (SELECT SUM(qta) FROM mg_movimenti WHERE mg_movimenti.idarticolo=mg_articoli.id AND data <= '.prepare($period_end).') AS qta -FROM mg_articoli LEFT OUTER JOIN (SELECT id, nome FROM mg_categorie) AS categoria ON mg_articoli.id_categoria = categoria.id WHERE 1=1 -ORDER BY codice ASC'; +$structure = Modules::get($id_module); -$query = str_replace('1=1', '1=1'.(!empty($where) ? ' AND '.implode(' AND ', $where) : ''), $query); -$rs = $dbo->fetchArray($query); +// RISULTATI VISIBILI +Util\Query::setSegments(false); +$query = Query::getQuery($structure, $where, 0, []); + +$query = Modules::replaceAdditionals($id_module, $query); + +// Modifiche alla query principale +$query = preg_replace('/ FROM `mg_articoli` /', ' FROM mg_articoli LEFT JOIN (SELECT idarticolo, SUM(qta) AS qta_totale FROM mg_movimenti GROUP BY idarticolo) movimenti ON movimenti.idarticolo=mg_articoli.id ', $query); + +$query = preg_replace('/^SELECT /', 'SELECT mg_articoli.prezzo_acquisto,', $query); +$query = preg_replace('/^SELECT /', 'SELECT mg_articoli.prezzo_vendita,', $query); +$query = preg_replace('/^SELECT /', 'SELECT mg_articoli.um,', $query); +$query = preg_replace('/^SELECT /', 'SELECT movimenti.qta_totale,', $query); + +if (post('tipo') == 'nozero') { + $query = str_replace('2=2', '2=2 AND movimenti.qta_totale > 0', $query); +} + +$data = Query::executeAndCount($query); echo '