2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
// carica report html
2018-09-06 09:45:49 +02:00
$report = file_get_contents ( __DIR__ . '/magazzino_inventario.html' );
$body = file_get_contents ( __DIR__ . '/magazzino_inventario_body.html' );
2017-08-04 16:28:16 +02:00
2017-09-21 15:51:39 +02:00
$search_codice = $_GET [ 'search_codice' ];
$search_descrizione = $_GET [ 'search_descrizione' ];
2018-04-17 17:32:39 +02:00
2018-06-26 14:30:26 +02:00
if ( $_GET [ 'search_subcategoria' ] == 'undefined' ) {
$_GET [ 'search_subcategoria' ] = '' ;
}
2018-04-17 17:32:39 +02:00
2018-06-26 14:30:26 +02:00
if ( ! empty ( $_GET [ 'search_categoria' ]) or ! empty ( $_GET [ 'search_subcategoria' ])) {
$search_categoria = $_GET [ 'search_categoria' ] . ' ' . $_GET [ 'search_subcategoria' ];
}
2018-04-17 17:32:39 +02:00
2017-09-21 15:51:39 +02:00
$search_tipo = $_GET [ 'search_tipo' ];
2017-08-04 16:28:16 +02:00
if ( $search_tipo == '' ) {
$search_tipo = 'solo prodotti attivi' ;
}
if ( $search_tipo == 'solo prodotti attivi' ) {
$add_where = ' AND attivo=1' ;
} elseif ( $search_tipo == 'solo prodotti non attivi' ) {
$add_where = ' AND attivo=0' ;
} else {
$add_where = '' ;
}
2018-06-26 14:30:26 +02:00
if ( $search_codice != '' ) {
$add_where .= " AND ( replace(codice,'.','') LIKE \" % $search_codice % \" OR codice LIKE \" % $search_codice % \" ) " ;
}
2018-04-17 17:32:39 +02:00
2018-06-26 14:30:26 +02:00
if ( $search_descrizione != '' ) {
$add_where .= " AND replace(descrizione,'.','') LIKE \" % $search_descrizione % \" " ;
}
2018-04-17 17:32:39 +02:00
$add_having = '' ;
2018-06-26 14:30:26 +02:00
if ( ! empty ( $search_categoria )) {
$add_having .= " AND CONCAT_WS( ' ', categoria, subcategoria ) LIKE '% " . $search_categoria . " %' " ;
}
2018-04-17 17:32:39 +02:00
2017-08-04 16:28:16 +02:00
include_once $docroot . '/templates/pdfgen_variables.php' ;
// Ciclo tra gli articoli selezionati
// LEFT OUTER JOIN mg_unitamisura ON mg_unitamisura.id=mg_articoli.idum
// mg_unitamisura.valore AS um
// LEFT OUTER JOIN mg_categorie ON (mg_categorie.id=mg_articoli.id_categoria AND mg_categorie.parent = 0) OR (mg_categorie.id=mg_articoli.id_sottocategoria AND mg_categorie.parent = 1)
2018-09-04 10:56:03 +02:00
$period_end = $_SESSION [ 'period_end' ];
2019-06-13 16:24:50 +02:00
$query = 'SELECT *, mg_articoli.id AS id_articolo, (SELECT nome FROM mg_categorie WHERE mg_categorie.parent = 0 AND mg_categorie.id = mg_articoli.id_categoria) AS categoria, (SELECT nome FROM mg_categorie WHERE mg_categorie.parent = 1 AND mg_categorie.id = mg_articoli.id_sottocategoria) AS subcategoria, (SELECT SUM(qta) FROM mg_movimenti WHERE mg_movimenti.idarticolo=mg_articoli.id AND (mg_movimenti.idintervento IS NULL) AND data <= ' . prepare ( $period_end ) . ' ) AS qta FROM mg_articoli WHERE 1=1 ' . $add_where . ' HAVING 2=2 AND servizio = 0 AND attivo = 1' . $add_having . ' ORDER BY codice ASC' ;
2018-04-17 17:32:39 +02:00
$rs = $dbo -> fetchArray ( $query );
2017-08-04 16:28:16 +02:00
$totrows = sizeof ( $rs );
2018-09-04 10:56:03 +02:00
$body .= '<h3>INVENTARIO AL ' . Translator :: dateToLocale ( $period_end ) . " </h3> \n " ;
2017-08-04 16:28:16 +02:00
$body .= " <table cellspacing='0' style='table-layout:fixed;'> \n " ;
$body .= " <col width='100'><col width='230'><col width='70'><col width='70'><col width='70'><col width='90'> \n " ;
$body .= " <tr> \n " ;
$body .= " <th bgcolor='#dddddd' class='full_cell1 cell-padded'>Codice</th> \n " ;
$body .= " <th bgcolor='#dddddd' class='full_cell cell-padded'>Descrizione</th> \n " ;
$body .= " <th bgcolor='#dddddd' class='full_cell cell-padded'>Prezzo di vendita</th> \n " ;
$body .= " <th bgcolor='#dddddd' class='full_cell cell-padded'>Q.tà</th> \n " ;
$body .= " <th bgcolor='#dddddd' class='full_cell cell-padded'>Prezzo di acquisto</th> \n " ;
$body .= " <th bgcolor='#dddddd' class='full_cell cell-padded'>Valore totale</th> \n " ;
$body .= " </tr> \n " ;
for ( $r = 0 ; $r < sizeof ( $rs ); ++ $r ) {
$body .= " <tr> \n " ;
$body .= " <td class='first_cell cell-padded'> " . $rs [ $r ][ 'codice' ] . " </td> \n " ;
$body .= " <td class='table_cell cell-padded'> " . $rs [ $r ][ 'descrizione' ] . " </td> \n " ;
2019-04-13 02:56:39 +02:00
$body .= " <td class='table_cell text-right cell-padded'> " . moneyFormat ( $rs [ $r ][ 'prezzo_vendita' ]) . " </td> \n " ;
2019-06-29 11:01:26 +02:00
$body .= " <td class='table_cell text-right cell-padded'> " . Translator :: numberToLocale ( $rs [ $r ][ 'qta' ]) . ' ' . $rs [ $r ][ 'um' ] . " </td> \n " ;
2019-04-13 02:56:39 +02:00
$body .= " <td class='table_cell text-right cell-padded'> " . moneyFormat ( $rs [ $r ][ 'prezzo_acquisto' ]) . " </td> \n " ;
$body .= " <td class='table_cell text-right cell-padded'> " . moneyFormat (( $rs [ $r ][ 'prezzo_acquisto' ] * $rs [ $r ][ 'qta' ])) . " </td> \n " ;
2017-08-04 16:28:16 +02:00
$body .= " </tr> \n " ;
$totale_qta += $rs [ $r ][ 'qta' ];
$totale_acquisto += ( $rs [ $r ][ 'prezzo_acquisto' ] * $rs [ $r ][ 'qta' ]);
}
// Totali
$body .= " <tr> \n " ;
$body .= " <td colspan='2' bgcolor='#dddddd' class='first_cell text-right cell-padded'><b>TOTALE:</b></td> \n " ;
$body .= " <td bgcolor='#dddddd' class='first_cell text-right cell-padded'></td> \n " ;
2017-09-21 10:01:07 +02:00
$body .= " <td bgcolor='#dddddd' class='table_cell text-right cell-padded'><b> " . Translator :: numberToLocale ( $totale_qta ) . " </b></td> \n " ;
2017-08-04 16:28:16 +02:00
$body .= " <td bgcolor='#dddddd' class='first_cell text-right cell-padded'></td> \n " ;
2019-04-13 02:56:39 +02:00
$body .= " <td bgcolor='#dddddd' class='table_cell text-right cell-padded'><b> " . moneyFormat ( $totale_acquisto ) . " </b></td> \n " ;
2017-08-04 16:28:16 +02:00
$body .= " </tr> \n " ;
$body .= " </table> \n " ;
$report_name = 'inventario.pdf' ;