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
2018-05-17 12:58:53 +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 OR idautomezzo = 0) AND data <= CURDATE() ) AS qta_totale_attuale FROM mg_movimenti WHERE idarticolo=' . prepare ( $id_record ) . ' AND (idintervento IS NULL OR idautomezzo = 0)' );
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' ;
}
$rs2 = $dbo -> fetchArray ( $query );
if ( ! empty ( $rs2 )) {
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 >
2018-05-17 12:58:53 +02:00
< th > '.tr(' Q . tà ').' </ th >
< th > '.tr(' Causale ').' </ th >
< th > '.tr(' Data ').' </ th >
< th class = " text-center " width = " 7% " > #</th>
2017-08-04 16:28:16 +02:00
</ tr > ' ;
2017-09-05 17:31:58 +02:00
foreach ( $rs2 as $r ) {
2017-08-04 16:28:16 +02:00
// Quantità
echo '
< tr >
2018-07-18 15:20:10 +02:00
< td class = " text-right " > '.Translator::numberToLocale($r[' qta '], ' qta ').' '.$record[' um '].' </ td > ' ;
2017-08-04 16:28:16 +02:00
// Causale
2018-06-26 14:30:26 +02:00
$dir = ( $r [ 'qta' ] < 0 ) ? 'vendita' : 'acquisto' ;
2018-07-03 17:28:02 +02:00
if ( ! empty ( $r [ 'iddocumento' ])) {
$dir = $dbo -> fetchArray ( 'SELECT dir FROM co_tipidocumento WHERE id = (SELECT idtipodocumento FROM co_documenti WHERE id = ' . prepare ( $r [ 'iddocumento' ]) . ')' )[ 0 ][ 'dir' ] == 'entrata' ? 'vendita' : 'acquisto' ;
}
2017-08-04 16:28:16 +02:00
echo '
2018-06-29 13:35:39 +02:00
< td > '.$r[' movimento '].'
2018-06-26 14:30:26 +02:00
'.((!empty($r[' idintervento '])) ? Modules::link(' Interventi ', $r[' idintervento ']) : ' ').'
'.((!empty($r[' idautomezzo '])) ? Modules::link(' Automezzi ', $r[' idautomezzo ']) : ' ').'
'.((!empty($r[' iddt '])) ? Modules::link(' DDt di '.$dir.' ', $r[' iddt ']) : ' ').'
'.((!empty($r[' iddocumento '])) ? Modules::link(' Fatture di '.$dir.' ', $r[' iddocumento ']) : ' ').'
2018-05-17 12:58:53 +02:00
</ td > ' ;
2017-08-04 16:28:16 +02:00
// Data
echo '
2018-05-17 12:58:53 +02:00
< td class = " text-center " > '.Translator::dateToLocale($r[' data ']).' < span class = \ 'tip\' title=\'' . tr ( 'Data del movimento: ' ) . Translator :: dateToLocale ( $r [ '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 " > ' ;
2018-06-26 14:30:26 +02:00
if ( Auth :: admin () && $r [ 'manuale' ] == '1' ) {
2017-09-05 17:31:58 +02:00
echo '
< a class = " btn btn-danger btn-sm ask " data - backto = " record-edit " data - op = " delmovimento " data - idmovimento = " '. $r['id'] .' " >
< i class = " fa fa-trash " ></ i >
</ a > ' ;
}
echo '
</ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
}
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 >
'.tr(' Questo articolo non è ancora stato movimentato ', []).' .
</ div > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
</ div >
</ div > ' ;