2023-11-30 12:57:03 +01:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
|
|
|
* Copyright (C) DevCode s.r.l.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
2023-12-01 17:21:47 +01:00
|
|
|
$azienda = $dbo->fetchOne('SELECT * FROM an_anagrafiche WHERE idanagrafica='.prepare(setting('Azienda predefinita')));
|
2023-11-30 12:57:03 +01:00
|
|
|
|
|
|
|
$where = [];
|
|
|
|
$search_targa = get('search_targa');
|
2023-12-01 17:21:47 +01:00
|
|
|
$search_nome = get('search_nome');
|
2023-11-30 12:57:03 +01:00
|
|
|
|
2023-12-01 17:21:47 +01:00
|
|
|
$where[] = 'movimenti.qta > 0';
|
|
|
|
$where[] = 'movimenti.qta > 0';
|
|
|
|
if ($search_targa) {
|
|
|
|
$where[] = 'an_sedi.targa like '.prepare('%'.$search_targa.'%');
|
2023-11-30 12:57:03 +01:00
|
|
|
}
|
2023-12-01 17:21:47 +01:00
|
|
|
if ($search_nome) {
|
|
|
|
$where[] = 'an_sedi.nome like '.prepare('%'.$search_nome.'%');
|
2023-11-30 12:57:03 +01:00
|
|
|
}
|
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
// Ciclo tra gli articoli selezionati
|
2023-12-01 17:21:47 +01:00
|
|
|
$query = '
|
2023-11-30 12:57:03 +01:00
|
|
|
SELECT
|
|
|
|
an_sedi.targa, an_sedi.nome,
|
|
|
|
mg_articoli.codice, mg_articoli.descrizione,
|
|
|
|
(SELECT mg_categorie.nome FROM mg_categorie WHERE mg_categorie.id=mg_articoli.id_sottocategoria) AS subcategoria,
|
|
|
|
movimenti.qta,
|
|
|
|
mg_articoli.um
|
|
|
|
FROM an_sedi
|
|
|
|
INNER JOIN (SELECT SUM(mg_movimenti.qta) AS qta, idarticolo, idsede FROM mg_movimenti GROUP BY idsede,idarticolo) AS movimenti ON movimenti.idsede = an_sedi.id
|
|
|
|
INNER JOIN mg_articoli ON movimenti.idarticolo = mg_articoli.id
|
|
|
|
WHERE
|
2023-12-01 17:21:47 +01:00
|
|
|
'.implode(' AND ', $where).'
|
2023-11-30 12:57:03 +01:00
|
|
|
ORDER BY
|
2023-12-01 17:21:47 +01:00
|
|
|
an_sedi.targa, an_sedi.descrizione';
|
2023-11-30 12:57:03 +01:00
|
|
|
|
|
|
|
$rs = $dbo->fetchArray($query);
|
|
|
|
$totrows = sizeof($rs);
|