Aggiornamento stampa inventario (#537)

This commit is contained in:
Thomas Zilio 2019-11-22 18:25:33 +01:00
parent 37b0c73026
commit 3821d6a944
7 changed files with 118 additions and 165 deletions

View File

@ -60,7 +60,7 @@ $(function() {
format: "MMMM YYYY",
locale: globals.locale,
useCurrent: false,
defaultDate: moment("'.$date->format("Y-m-d H:i:s").'")
defaultDate: moment("'.$date->format('Y-m-d H:i:s').'")
});
$("#date").on("dp.change", function(e) {

View File

@ -0,0 +1,107 @@
<?php
include_once __DIR__.'/../../core.php';
// Valori di ricerca
$search = [
'codice' => $_GET['search_codice'],
'descrizione' => $_GET['search_descrizione'],
'categoria' => $_GET['search_categoria'],
'subcategoria' => $_GET['search_subcategoria'],
'tipo' => $_GET['search_tipo'],
];
foreach ($search as $name => $value) {
if ($value == 'undefined') {
$search[$name] = null;
}
}
$search['tipo'] = $search['tipo'] ?: 'solo prodotti attivi';
// Filtri effettivi
$where = [
'servizio = 0',
];
if ($search['tipo'] == 'solo prodotti attivi') {
$where[] = 'attivo = 1';
} elseif ($search['tipo'] == 'solo prodotti non attivi') {
$where[] = 'attivo = 0';
}
if (!empty($search['codice'])) {
$where[] = "(REPLACE(codice, '.', '') LIKE ".prepare('%'.$search['codice'].'%').' OR codice LIKE '.prepare('%'.$search['codice'].'%').')';
}
if (!empty($search['descrizione'])) {
$where[] .= "REPLACE(descrizione, '.', '') LIKE ".prepare('%'.$search['descrizione'].'%');
}
if (!empty($search['categoria'])) {
$where[] = 'id_categoria IN (SELECT id FROM mg_categorie WHERE descrizione LIKE '.prepare('%'.$search['categoria'].'%').')';
}
if (!empty($search['subcategoria'])) {
$where[] = 'id_sottocategoria IN (SELECT id FROM mg_categorie WHERE descrizione LIKE '.prepare('%'.$search['subcategoria'].'%').')';
}
$period_end = $_SESSION['period_end'];
$query = 'SELECT *,
(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
ORDER BY codice ASC';
$query = str_replace('1=1', '1=1'.(!empty($where) ? ' AND '.implode(' AND ', $where) : ''), $query);
$rs = $dbo->fetchArray($query);
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>
<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.', [], ['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>
<tbody>';
$totali = [];
foreach ($rs as $r) {
$valore_magazzino = $r['prezzo_acquisto'] * $r['qta'];
echo '
<tr>
<td>'.$r['codice'].'</td>
<td>'.$r['descrizione'].'</td>
<td class="text-right">'.moneyFormat($r['prezzo_vendita']).'</td>
<td class="text-right">'.Translator::numberToLocale($r['qta']).' '.$r['um'].'</td>
<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);
$totale_qta = sum(array_column($rs, 'qta'));
echo '
</tbody>
<tr>
<td colspan="2" class="text-right border-top"><b>'.tr('Totale', [], ['upper' => true]).':</b></td>
<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>';

View File

@ -1,59 +0,0 @@
<style>
<!--
.table_values td{
border: 1px solid #888;
padding: 4px;
white-space: normal;
}
.table_values th{
background: #abbfcb;
padding: 4px;
}
.first_cell{
border-left: 1px solid #aaa;
border-right: 1px solid #aaa;
border-bottom: 1px solid #aaa;
}
.table_cell{
border-bottom: 1px solid #aaa;
border-right: 1px solid #aaa;
}
.full_cell1{
border: 1px solid #aaa;
}
.full_cell{
border-top: 1px solid #aaa;
border-right: 1px solid #aaa;
border-bottom: 1px solid #aaa;
}
.text-center{
text-align: center;
}
.text-right{
text-align: right;
}
.b-right{
border-right: 1px solid #aaa;
}
.b-bottom{
border-bottom: 1px solid #aaa;
}
.cell-padded{
padding: 4px;
}
-->
</style>
<page backcolor="#ffffff" backtop="35mm" backbottom="10mm" backleft="0mm" backright="0mm" footer="" style="font-size: $font_size$">
$body$
</page>

View File

@ -1,9 +0,0 @@
<page_header>
<table $body_table_params$>
<!-- Intestazione fornitore -->
<tr><td style="width:105mm; font-size:8pt; color:#555;">
<img src="$logo$" alt="Logo" border="0" />
</td></tr>
</table>
<br/>
</page_header>

View File

@ -1,95 +0,0 @@
<?php
include_once __DIR__.'/../../core.php';
// carica report html
$report = file_get_contents(__DIR__.'/magazzino_inventario.html');
$body = file_get_contents(__DIR__.'/magazzino_inventario_body.html');
$search_codice = $_GET['search_codice'];
$search_descrizione = $_GET['search_descrizione'];
if ($_GET['search_subcategoria'] == 'undefined') {
$_GET['search_subcategoria'] = '';
}
if (!empty($_GET['search_categoria']) or !empty($_GET['search_subcategoria'])) {
$search_categoria = $_GET['search_categoria'].' '.$_GET['search_subcategoria'];
}
$search_tipo = $_GET['search_tipo'];
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 = '';
}
if ($search_codice != '') {
$add_where .= " AND ( replace(codice,'.','') LIKE \"%$search_codice%\" OR codice LIKE \"%$search_codice%\" )";
}
if ($search_descrizione != '') {
$add_where .= " AND replace(descrizione,'.','') LIKE \"%$search_descrizione%\"";
}
$add_having = '';
if (!empty($search_categoria)) {
$add_having .= " AND CONCAT_WS( ' ', categoria, subcategoria ) LIKE '%".$search_categoria."%' ";
}
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)
$period_end = $_SESSION['period_end'];
$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';
$rs = $dbo->fetchArray($query);
$totrows = sizeof($rs);
$body .= '<h3>INVENTARIO AL '.Translator::dateToLocale($period_end)."</h3>\n";
$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";
$body .= " <td class='table_cell text-right cell-padded'>".moneyFormat($rs[$r]['prezzo_vendita'])."</td>\n";
$body .= " <td class='table_cell text-right cell-padded'>".Translator::numberToLocale($rs[$r]['qta']).' '.$rs[$r]['um']."</td>\n";
$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";
$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";
$body .= "<td bgcolor='#dddddd' class='table_cell text-right cell-padded'><b>".Translator::numberToLocale($totale_qta)."</b></td>\n";
$body .= "<td bgcolor='#dddddd' class='first_cell text-right cell-padded'></td>\n";
$body .= "<td bgcolor='#dddddd' class='table_cell text-right cell-padded'><b>".moneyFormat($totale_acquisto)."</b></td>\n";
$body .= "</tr>\n";
$body .= "</table>\n";

View File

@ -0,0 +1,6 @@
<?php
return [
//'orientation' => 'L',
'font-size' => '11pt',
];

View File

@ -905,4 +905,7 @@ UPDATE `zz_views` SET `query` = 'codice' WHERE `zz_views`.`name` = 'Codice' AND
UPDATE `zz_modules` SET `icon` = 'fa fa-angle-right' WHERE `zz_modules`.`name` = 'Categorie documenti';
UPDATE `zz_widgets` SET `query` = 'SELECT CONCAT_WS(" ", REPLACE(REPLACE(REPLACE(FORMAT(SUM(prezzo_acquisto*qta),2), ",", "#"), ".", ","), "#", "."), "&euro;") AS dato FROM mg_articoli WHERE qta>0 AND deleted_at IS NULL' WHERE `zz_widgets`.`name` = 'Valore magazzino';
UPDATE `zz_widgets` SET `query` = 'SELECT CONCAT_WS(" ", REPLACE(REPLACE(REPLACE(FORMAT(SUM(qta),2), ",", "#"), ".", ","), "#", "."), "unit&agrave;") AS dato FROM mg_articoli WHERE qta>0 AND deleted_at IS NULL' WHERE `zz_widgets`.`name` = 'Articoli in magazzino';
UPDATE `zz_widgets` SET `query` = 'SELECT CONCAT_WS(" ", REPLACE(REPLACE(REPLACE(FORMAT(SUM(qta),2), ",", "#"), ".", ","), "#", "."), "unit&agrave;") AS dato FROM mg_articoli WHERE qta>0 AND deleted_at IS NULL' WHERE `zz_widgets`.`name` = 'Articoli in magazzino';
-- Fix accesso alla stampa dell'inverntario magazzino
UPDATE `zz_prints` SET `is_record` = '0' WHERE `zz_prints`.`name` = 'Inventario magazzino';