openstamanager/modules/ordini/quantita_impegnate.php

86 lines
3.3 KiB
PHP
Raw Normal View History

<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* 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/>.
*/
use Modules\Ordini\Ordine;
include_once __DIR__.'/../../core.php';
$ordine = Ordine::find($id_record);
$articoli = $ordine->articoli->groupBy('idarticolo');
if ($articoli->isEmpty()) {
echo '
<p>'.tr('Il documento non contiene articoli').'.</p>';
2020-07-16 16:49:36 +02:00
return;
}
echo '
<table class="table table-striped table-hover table-condensed table-bordered">
<thead>
<tr>
<th>'.tr('Articolo').'</th>
<th class="text-center tip" width="150" title="'.tr('Quantità presente nel documento').'">'.tr('Q.').'</th>
<th class="text-center tip" width="150" title="'.tr('Quantità presente nel magazzino del gestionale').'">'.tr('Q. magazzino').'</th>
<th class="text-center tip" width="150" title="'.tr('Quantità impegnata in altri Ordini del gestionale').'">'.tr('Q. impegnata').'</th>
</tr>
</thead>
<tbody>';
foreach ($articoli as $elenco) {
$qta = $elenco->sum('qta');
$articolo = $elenco->first()->articolo;
$codice = $articolo ? $articolo->codice : tr('Articolo eliminato');
2024-04-18 17:44:05 +02:00
$descrizione = $articolo ? $articolo->getTranslation('title') : $elenco->first()->getTranslation('title');
2024-03-22 15:52:24 +01:00
$qta_impegnata = $database->fetchOne('SELECT
2024-03-01 11:32:13 +01:00
SUM(`qta`) as qta
FROM
`or_righe_ordini`
INNER JOIN `or_ordini` ON `or_ordini`.`id` = `or_righe_ordini`.`idordine`
INNER JOIN `or_statiordine` ON `or_statiordine`.`id` = `or_ordini`.`idstatoordine`
2024-03-22 15:52:24 +01:00
LEFT JOIN `or_statiordine_lang` ON (`or_statiordine`.`id` = `or_statiordine_lang`.`id_record` AND `or_statiordine_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).")
2024-03-01 11:32:13 +01:00
INNER JOIN `or_tipiordine` ON `or_tipiordine`.`id` = `or_ordini`.`idtipoordine`
WHERE
2024-07-17 17:02:48 +02:00
`or_statiordine_lang`.`title` = 'Bozza'
2024-03-01 11:32:13 +01:00
AND `dir` = 'entrata'
AND `confermato` = 1
AND `idarticolo`=".prepare($articolo->id).'
GROUP BY
`idarticolo`')['qta'];
$qta_impegnata = floatval($qta_impegnata);
$class = $qta_impegnata + $qta > $articolo->qta ? 'danger' : 'success';
$descrizione_riga = $codice.' - '.$descrizione;
$text = $articolo ? Modules::link('Articoli', $articolo->id, $descrizione_riga) : $descrizione_riga;
echo '
<tr class="'.$class.'">
<td>'.$text.'</td>
<td class="text-center">'.numberFormat($qta, 'qta').'</td>
<td class="text-center">'.numberFormat($articolo->qta, 'qta').'</td>
<td class="text-center">'.numberFormat($qta_impegnata, 'qta').'</td>
</tr>';
}
echo '
</tbody>
</table>';