2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../../core.php' ;
// Movimentazione degli articoli
echo '
< div class = " box " >
< div class = " box-header with-border " >
2017-09-04 12:02:29 +02:00
< h3 class = " box-title " > '.tr(' Movimenti ').' </ h3 >
2017-08-04 16:28:16 +02:00
</ div >
< div class = " box-body " > ' ;
// Calcolo la quantità dai movimenti in magazzino
2019-05-29 19:17:57 +02:00
$rst = $dbo -> fetchArray ( 'SELECT COUNT(mg_movimenti.id) AS `row`, SUM(qta) AS qta_totale, (SELECT SUM(qta) FROM mg_movimenti WHERE idarticolo=' . prepare ( $id_record ) . ' AND (idintervento IS NULL) AND data <= CURDATE()) AS qta_totale_attuale FROM mg_movimenti WHERE idarticolo=' . prepare ( $id_record ) . ' AND (idintervento IS NULL)' );
2017-08-04 16:28:16 +02:00
$qta_totale = $rst [ 0 ][ 'qta_totale' ];
2018-05-17 11:37:23 +02:00
$qta_totale_attuale = $rst [ 0 ][ 'qta_totale_attuale' ];
2017-08-04 16:28:16 +02:00
2018-06-26 14:30:26 +02:00
if ( $rst [ 0 ][ 'row' ] > 0 ) {
echo '
2018-07-18 15:20:10 +02:00
< p > '.tr(' Quantità calcolata dai movimenti ').' : < b > '.Translator::numberToLocale($qta_totale, ' qta ').' '.$record[' um '].' </ b > < span class = \ 'tip\' title=\'' . tr ( 'Quantità calcolata da tutti i movimenti registrati' ) . '.\' ><i class="fa fa-question-circle-o"></i></span></p>' ;
2017-08-04 16:28:16 +02:00
2018-06-26 14:30:26 +02:00
echo '
2018-07-18 15:20:10 +02:00
< p > '.tr(' Quantità calcolata attuale ').' : < b > '.Translator::numberToLocale($qta_totale_attuale, ' qta ').' '.$record[' um '].' </ b > < span class = \ 'tip\' title=\'' . tr ( 'Quantità calcolata secondo i movimenti registrati con data oggi o date trascorse' ) . '.\' ><i class="fa fa-question-circle-o"></i></span></p>' ;
2018-05-17 12:58:53 +02:00
}
2018-05-17 11:37:23 +02:00
2017-08-04 16:28:16 +02:00
// Elenco movimenti magazzino
2018-09-28 12:47:43 +02:00
$query = 'SELECT * FROM mg_movimenti WHERE idarticolo=' . prepare ( $id_record ) . ' ORDER BY created_at DESC, id DESC' ;
2017-08-04 16:28:16 +02:00
if ( empty ( $_GET [ 'show_all1' ])) {
$query .= ' LIMIT 0, 20' ;
}
2019-09-11 16:50:42 +02:00
$movimenti = $dbo -> fetchArray ( $query );
if ( ! empty ( $movimenti )) {
2017-08-04 16:28:16 +02:00
if ( empty ( $_GET [ 'show_all1' ])) {
echo '
2017-09-04 12:02:29 +02:00
< p >< a href = " '. $rootdir .'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&show_all1=1#tab_'. $id_plugin .' " > [ '.tr(' Mostra tutti i movimenti ').' ] </ a ></ p > ' ;
2017-08-04 16:28:16 +02:00
} else {
echo '
2017-09-04 12:02:29 +02:00
< p >< a href = " '. $rootdir .'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&show_all1=0#tab_'. $id_plugin .' " > [ '.tr(' Mostra solo gli ultimi 20 movimenti ').' ] </ a ></ p > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
< table class = " table table-striped table-condensed table-bordered " >
< tr >
2019-09-11 16:50:42 +02:00
< th class = " text-center " > '.tr(' Q . tà ').' </ th >
< th class = " text-center " > '.tr(' Q . tà progressiva ').' </ th >
< th > '.tr(' Causale ').' </ th >
< th class = " text-center " > '.tr(' Data ').' </ th >
2018-05-17 12:58:53 +02:00
< th class = " text-center " width = " 7% " > #</th>
2017-08-04 16:28:16 +02:00
</ tr > ' ;
2019-09-11 16:50:42 +02:00
foreach ( $movimenti as $i => $movimento ) {
// Quantità progressiva
if ( $i == 0 ) {
$movimento [ 'progressivo_finale' ] = $articolo -> qta ;
} else {
$movimento [ 'progressivo_finale' ] = $movimenti [ $i - 1 ][ 'progressivo_iniziale' ];
}
2019-09-11 17:26:05 +02:00
$movimento [ 'progressivo_iniziale' ] = $movimento [ 'progressivo_finale' ] - floatval ( $movimento [ 'qta' ]);
2019-09-11 16:50:42 +02:00
$movimenti [ $i ][ 'progressivo_iniziale' ] = $movimento [ 'progressivo_iniziale' ];
$movimenti [ $i ][ 'progressivo_finale' ] = $movimento [ 'progressivo_finale' ];
2017-08-04 16:28:16 +02:00
// Quantità
echo '
< tr >
2019-09-11 16:50:42 +02:00
< td class = " text-center " >
'.numberFormat($movimento[' qta '], ' qta ').' '.$record[' um '].'
</ td >
< td class = " text-center " >
'.numberFormat($movimento[' progressivo_iniziale '], ' qta ').' '.$record[' um '].'
< i class = " fa fa-arrow-circle-right " ></ i >
'.numberFormat($movimento[' progressivo_finale '], ' qta ').' '.$record[' um '].'
</ td > ' ;
2017-08-04 16:28:16 +02:00
// Causale
2019-09-11 16:50:42 +02:00
$dir = ( $movimento [ 'qta' ] < 0 ) ? 'vendita' : 'acquisto' ;
2018-06-26 14:30:26 +02:00
2019-09-11 16:50:42 +02:00
if ( ! empty ( $movimento [ 'iddocumento' ])) {
$dir = $dbo -> fetchArray ( 'SELECT dir FROM co_tipidocumento WHERE id = (SELECT idtipodocumento FROM co_documenti WHERE id = ' . prepare ( $movimento [ 'iddocumento' ]) . ')' )[ 0 ][ 'dir' ] == 'entrata' ? 'vendita' : 'acquisto' ;
2018-07-03 17:28:02 +02:00
}
2017-08-04 16:28:16 +02:00
echo '
2019-09-11 16:50:42 +02:00
< td > '.$movimento[' movimento '].'
'.((!empty($movimento[' idintervento '])) ? Modules::link(' Interventi ', $movimento[' idintervento ']) : ' ').'
'.((!empty($movimento[' idddt '])) ? (Modules::link(' DDt di '.$dir, $movimento[' idddt '], null, null, (intval($database->fetchOne(' SELECT * FROM `dt_ddt` WHERE `id` = '.prepare($movimento[' idddt '])))) ? ' ' : ' class = " disabled " ')) : ' ').'
'.((!empty($movimento[' iddocumento '])) ? (Modules::link(' Fatture di '.$dir, $movimento[' iddocumento '], null, null, (intval($database->fetchOne(' SELECT * FROM `co_documenti` WHERE `id` = '.prepare($movimento[' iddocumento '])))) ? ' ' : ' class = " disabled " ')) : ' ').'
2018-05-17 12:58:53 +02:00
</ td > ' ;
2017-08-04 16:28:16 +02:00
// Data
echo '
2019-09-11 16:50:42 +02:00
< td class = " text-center " > '.Translator::dateToLocale($movimento[' data ']).' < span class = \ 'tip\' title=\'' . tr ( 'Data del movimento: ' ) . Translator :: timestampToLocale ( $movimento [ 'created_at' ]) . '\' ><i class="fa fa-question-circle-o"></i></span> </td>' ;
2017-09-05 17:31:58 +02:00
// Operazioni
echo '
< td class = " text-center " > ' ;
2019-09-11 16:50:42 +02:00
if ( Auth :: admin () && $movimento [ 'manuale' ] == '1' ) {
2017-09-05 17:31:58 +02:00
echo '
2019-09-11 16:50:42 +02:00
< a class = " btn btn-danger btn-sm ask " data - backto = " record-edit " data - op = " delmovimento " data - idmovimento = " '. $movimento['id'] .' " >
2017-09-05 17:31:58 +02:00
< i class = " fa fa-trash " ></ i >
</ a > ' ;
}
echo '
</ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
}
2019-09-11 16:50:42 +02:00
2017-08-04 16:28:16 +02:00
echo '
</ table > ' ;
} else {
2018-06-26 14:30:26 +02:00
echo '
2018-05-17 12:58:53 +02:00
< div class = " alert alert-info " >
< i class = " fa fa-info-circle " ></ i >
2019-09-11 16:50:42 +02:00
'.tr(' Questo articolo non è ancora stato movimentato ').' .
2018-05-17 12:58:53 +02:00
</ div > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
</ div >
</ div > ' ;