openstamanager/templates/automezzi_inventario/init.php

62 lines
2.5 KiB
PHP
Raw Normal View History

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
2024-07-16 17:15:29 +02:00
$where[] = 'mg_movimenti.qta > 0';
2023-12-01 17:21:47 +01:00
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
2024-02-29 15:10:55 +01:00
$query = 'SELECT
`an_sedi`.`targa`,
`an_sedi`.`nome`,
`mg_articoli`.`codice`,
2024-04-18 17:44:05 +02:00
`mg_articoli_lang`.`title` as descrizione,
`mg_categorie_lang`.`title` AS subcategoria,
2024-02-29 15:10:55 +01:00
SUM(`mg_movimenti`.`qta`) AS qta,
`mg_articoli`.`um`
FROM
`an_sedi`
INNER JOIN `mg_movimenti` ON `mg_movimenti`.`idsede` = `an_sedi`.`id`
INNER JOIN `mg_articoli` ON `mg_movimenti`.`idarticolo` = `mg_articoli`.`id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `mg_articoli_lang` ON (`mg_articoli`.`id`=`mg_articoli_lang`.`id_record` AND `mg_articoli_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
2024-02-29 15:10:55 +01:00
LEFT JOIN `mg_categorie` ON `mg_categorie`.`id` = `mg_articoli`.`id_sottocategoria`
2024-03-22 15:52:24 +01:00
LEFT JOIN `mg_categorie_lang` ON (`mg_categorie`.`id`=`mg_categorie_lang`.`id_record` AND `mg_categorie_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
2024-02-29 15:10:55 +01:00
WHERE
2023-12-01 17:21:47 +01:00
'.implode(' AND ', $where).'
2024-02-29 15:10:55 +01:00
GROUP BY
2024-04-18 17:44:05 +02:00
`an_sedi`.`targa`, `an_sedi`.`nome`, `an_sedi`.`descrizione`, `mg_articoli`.`codice`, `mg_articoli_lang`.`title`, `mg_categorie_lang`.`title`, `mg_articoli`.`um`
2023-11-30 12:57:03 +01:00
ORDER BY
2024-02-29 15:10:55 +01:00
`an_sedi`.`targa`, `an_sedi`.`descrizione`';
2023-11-30 12:57:03 +01:00
$rs = $dbo->fetchArray($query);
$totrows = sizeof($rs);