2019-11-22 18:25:33 +01:00
< ? php
2020-04-07 16:10:00 +02:00
use Util\Query ;
2019-11-22 18:25:33 +01:00
include_once __DIR__ . '/../../core.php' ;
2020-04-07 16:10:00 +02:00
$id_module = Modules :: get ( 'Articoli' )[ 'id' ];
2019-11-22 18:25:33 +01:00
// Valori di ricerca
2020-04-07 16:10:00 +02:00
$where [ 'servizio' ] = '0' ;
2020-04-14 08:49:48 +02:00
foreach ( $_SESSION [ 'module_' . $id_module ] as $name => $value ) {
if ( preg_match ( '/^search_(.+?)$/' , $name , $m )) {
$where [ $m [ 1 ]] = $value ;
2019-11-22 18:25:33 +01:00
}
}
2020-04-07 16:10:00 +02:00
$period_end = $_SESSION [ 'period_end' ];
2019-11-22 18:25:33 +01:00
2020-04-07 16:10:00 +02:00
$structure = Modules :: get ( $id_module );
2019-11-22 18:25:33 +01:00
2020-04-07 16:10:00 +02:00
// RISULTATI VISIBILI
Util\Query :: setSegments ( false );
$query = Query :: getQuery ( $structure , $where , 0 , []);
2019-11-22 18:25:33 +01:00
2020-04-07 16:10:00 +02:00
$query = Modules :: replaceAdditionals ( $id_module , $query );
2019-11-22 18:25:33 +01:00
2020-04-07 16:10:00 +02:00
// Modifiche alla query principale
2020-07-23 12:08:31 +02:00
$query = preg_replace ( '/ FROM `mg_articoli` /' , ' FROM mg_articoli LEFT JOIN (SELECT idarticolo, SUM(qta) AS qta_totale FROM mg_movimenti WHERE data <=' . prepare ( $period_end ) . ' GROUP BY idarticolo) movimenti ON movimenti.idarticolo=mg_articoli.id ' , $query );
2019-11-22 18:25:33 +01:00
2020-04-07 16:10:00 +02:00
$query = preg_replace ( '/^SELECT /' , 'SELECT mg_articoli.prezzo_acquisto,' , $query );
$query = preg_replace ( '/^SELECT /' , 'SELECT mg_articoli.prezzo_vendita,' , $query );
$query = preg_replace ( '/^SELECT /' , 'SELECT mg_articoli.um,' , $query );
$query = preg_replace ( '/^SELECT /' , 'SELECT movimenti.qta_totale,' , $query );
2020-02-04 16:30:11 +01:00
2020-04-07 16:10:00 +02:00
if ( post ( 'tipo' ) == 'nozero' ) {
$query = str_replace ( '2=2' , '2=2 AND movimenti.qta_totale > 0' , $query );
2020-02-04 16:30:11 +01:00
}
2020-04-07 16:10:00 +02:00
$data = Query :: executeAndCount ( $query );
2019-11-22 18:25:33 +01:00
echo '
< h3 > '.tr(' Inventario al _DATE_ ' , [
'_DATE_' => Translator :: dateToLocale ( $period_end ),
], [ 'upper' => true ]) . ' </ h3 >
< table class = " table table-bordered " >
< thead >
< tr >
< th class = " text-center " width = " 150 " > '.tr(' Codice ', [], [' upper ' => true]).' </ th >
2020-02-01 11:40:23 +01:00
< th class = " text-center " > '.tr(' Categoria ', [], [' upper ' => true]).' </ th >
2019-11-22 18:25:33 +01:00
< th class = " text-center " > '.tr(' Descrizione ', [], [' upper ' => true]).' </ th >
< th class = " text-center " width = " 70 " > '.tr(' Prezzo di vendita ', [], [' upper ' => true]).' </ th >
< th class = " text-center " width = " 70 " > '.tr(' Q . tà ', [], [' upper ' => true]).' </ th >
< th class = " text-center " width = " 70 " > '.tr(' Prezzo di acquisto ', [], [' upper ' => true]).' </ th >
< th class = " text-center " width = " 90 " > '.tr(' Valore totale ', [], [' upper ' => true]).' </ th >
</ tr >
</ thead >
2020-03-03 10:33:32 +01:00
2019-11-22 18:25:33 +01:00
< tbody > ' ;
$totali = [];
2020-04-07 16:10:00 +02:00
foreach ( $data [ 'results' ] as $r ) {
$valore_magazzino = $r [ 'prezzo_acquisto' ] * $r [ 'qta_totale' ];
2019-11-22 18:25:33 +01:00
echo '
< tr >
2020-04-07 16:10:00 +02:00
< td > '.$r[' Codice '].' </ td >
< td > '.$r[' Categoria '].' </ td >
< td > '.$r[' Descrizione '].' </ td >
2019-11-22 18:25:33 +01:00
< td class = " text-right " > '.moneyFormat($r[' prezzo_vendita ']).' </ td >
2020-04-07 16:10:00 +02:00
< td class = " text-right " > '.Translator::numberToLocale($r[' qta_totale ']).' '.$r[' um '].' </ td >
2019-11-22 18:25:33 +01:00
< td class = " text-right " > '.moneyFormat($r[' prezzo_acquisto ']).' </ td >
< td class = " text-right " > '.moneyFormat($valore_magazzino).' </ td >
</ tr > ' ;
$totali [] = $valore_magazzino ;
}
// Totali
$totale_acquisto = sum ( $totali );
2020-04-07 16:10:00 +02:00
$totale_qta = sum ( array_column ( $rs , 'qta_totale' ));
2019-11-22 18:25:33 +01:00
echo '
</ tbody >
< tr >
2020-02-14 11:03:16 +01:00
< td colspan = " 3 " class = " text-right border-top " >< b > '.tr(' Totale ', [], [' upper ' => true]).' :</ b ></ td >
2019-11-22 18:25:33 +01:00
< td class = " border-top " ></ td >
< td class = " text-right border-top " >< b > '.Translator::numberToLocale($totale_qta).' </ b ></ td >
< td class = " border-top " ></ td >
< td class = " text-right border-top " >< b > '.moneyFormat($totale_acquisto).' </ b ></ td >
</ tr >
</ table > ' ;