mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-02 17:07:01 +01:00
Miglioramento giacenze e qta progressiva
This commit is contained in:
parent
e1d5bd4d08
commit
2a947a0c1d
@ -1,46 +1,243 @@
|
||||
<?php
|
||||
|
||||
$sedi = $dbo->fetchArray('(SELECT "0" AS id, "Sede legale" AS nomesede) UNION (SELECT id, CONCAT(nomesede, " - ", citta ) AS nomesede FROM an_sedi WHERE idanagrafica='.prepare(setting('Azienda predefinita')).')');
|
||||
?>
|
||||
include_once __DIR__.'/../../../core.php';
|
||||
|
||||
$impegnato = 0;
|
||||
$ordinato = 0;
|
||||
|
||||
$query = 'SELECT
|
||||
or_ordini.id AS id,
|
||||
or_ordini.numero,
|
||||
or_ordini.numero_esterno,
|
||||
data,
|
||||
SUM(or_righe_ordini.qta) AS qta_ordinata,
|
||||
or_righe_ordini.um
|
||||
FROM or_ordini
|
||||
INNER JOIN or_righe_ordini ON or_ordini.id = or_righe_ordini.idordine
|
||||
WHERE idarticolo = '.prepare($articolo->id)."
|
||||
AND (SELECT dir FROM or_tipiordine WHERE or_tipiordine.id=or_ordini.idtipoordine) = '|direzione|'
|
||||
AND (or_righe_ordini.qta - or_righe_ordini.qta_evasa) > 0
|
||||
GROUP BY or_ordini.id
|
||||
HAVING qta_ordinata > 0";
|
||||
|
||||
/*
|
||||
** Impegnato
|
||||
*/
|
||||
echo '
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title"><?php echo tr('Giacenze'); ?></h3>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<table class="table table-striped table-condensed table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="400"><?php echo tr('Sede'); ?></th>
|
||||
<th width="200"><?php echo tr('Q.tà'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<div class="col-md-3">
|
||||
<div class="alert alert-info" style="height: 75px;">
|
||||
<i class="fa fa-info-circle"></i> Quantità impegnate in ordini cliente che non siano già completamente evasi o articoli in cesta commessa
|
||||
</div>
|
||||
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($sedi as $sede) {
|
||||
// Lettura movimenti delle mie sedi
|
||||
$qta_azienda = $dbo->fetchOne("SELECT SUM(mg_movimenti.qta) AS qta, IF(mg_movimenti.idsede_azienda= 0,'Sede legale',(CONCAT_WS(' - ',an_sedi.nomesede,an_sedi.citta))) as sede FROM mg_movimenti LEFT JOIN an_sedi ON an_sedi.id = mg_movimenti.idsede_azienda WHERE mg_movimenti.idarticolo=".prepare($id_record).' AND idsede_azienda='.prepare($sede['id']).' GROUP BY idsede_azienda');
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Impegnato</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
|
||||
// Lettura eventuali movimenti ad una propria sede (nel caso di movimenti fra sedi della mia azienda)
|
||||
if ($sede['id'] != 0) {
|
||||
$qta_controparte = $dbo->fetchOne("SELECT SUM(mg_movimenti.qta) AS qta, IF(mg_movimenti.idsede_controparte= 0,'Sede legale',(CONCAT_WS(' - ',an_sedi.nomesede,an_sedi.citta))) as sede FROM mg_movimenti LEFT JOIN an_sedi ON an_sedi.id = mg_movimenti.idsede_controparte WHERE mg_movimenti.idarticolo=".prepare($id_record).' AND idsede_controparte='.prepare($sede['id']).' GROUP BY idsede_controparte');
|
||||
} else {
|
||||
$qta_controparte = $dbo->fetchOne("SELECT SUM(mg_movimenti.qta) AS qta, IF(mg_movimenti.idsede_controparte= 0,'Sede legale',(CONCAT_WS(' - ',an_sedi.nomesede,an_sedi.citta))) as sede FROM ((( mg_movimenti LEFT JOIN an_sedi ON an_sedi.id = mg_movimenti.idsede_controparte ) LEFT JOIN dt_ddt ON mg_movimenti.idddt = dt_ddt.id ) LEFT JOIN co_documenti ON mg_movimenti.iddocumento = co_documenti.id ) WHERE mg_movimenti.idarticolo=".prepare($id_record).' AND idsede_controparte='.prepare($sede['id']).' AND IFNULL( dt_ddt.idanagrafica, co_documenti.idanagrafica ) = '.prepare(setting('Azienda predefinita')).' GROUP BY idsede_controparte');
|
||||
}
|
||||
<table class="table table-bordered table-condensed table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Descrizione</th>
|
||||
<th>Qta</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>';
|
||||
|
||||
echo '
|
||||
$ordini = $dbo->fetchArray(str_replace('|dir|', 'entrata', $query));
|
||||
$impegnato = sum(array_column($ordini, 'qta_ordinata'));
|
||||
|
||||
$modulo = Modules::get('Ordini cliente');
|
||||
foreach ($ordini as $documento) {
|
||||
$numero = !empty($documento['numero_esterno']) ? $documento['numero_esterno'] : $documento['numero'];
|
||||
$qta = $documento['qta_ordinata'];
|
||||
|
||||
echo '
|
||||
<tr>
|
||||
<td>
|
||||
'.Modules::link($modulo['id'], $documento['id'], tr('Ordine num. _NUM_ del _DATE_', [
|
||||
'_NUM_' => $numero,
|
||||
'_DATE_' => dateFormat($documento['data']),
|
||||
])).'
|
||||
</td>
|
||||
<td class="text-right">
|
||||
'.numberFormat($qta).' '.$documento['um'].'
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<tr>
|
||||
<td class="text-right">
|
||||
<b>Totale</b>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
'.numberFormat($impegnato).'
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
/*
|
||||
** In ordine
|
||||
*/
|
||||
echo '
|
||||
<div class="col-md-3">
|
||||
<div class="alert alert-info" style="height: 75px;"><i class="fa fa-info-circle"></i> Quantità ordinate al fornitore in ordini che non siano già completamente evasi</div>
|
||||
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">In ordine</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
|
||||
<table class="table table-bordered table-condensed table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Descrizione</th>
|
||||
<th>Qta</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>';
|
||||
|
||||
$ordini = $dbo->fetchArray(str_replace('|dir|', 'uscita', $query));
|
||||
$ordinato = sum(array_column($ordini, 'qta_ordinata'));
|
||||
|
||||
$modulo = Modules::get('Ordini cliente');
|
||||
foreach ($ordini as $documento) {
|
||||
$numero = !empty($documento['numero_esterno']) ? $documento['numero_esterno'] : $documento['numero'];
|
||||
$qta = $documento['qta_ordinata'];
|
||||
|
||||
echo '
|
||||
<tr>
|
||||
<td>
|
||||
'.Modules::link($modulo['id'], $documento['id'], tr('Ordine num. _NUM_ del _DATE_', [
|
||||
'_NUM_' => $numero,
|
||||
'_DATE_' => dateFormat($documento['data']),
|
||||
])).'
|
||||
</td>
|
||||
<td class="text-right">
|
||||
'.numberFormat($qta).' '.$documento['um'].'
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<tr>
|
||||
<td class="text-right">
|
||||
<b>Totale</b>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
'.numberFormat($ordinato).'
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
/**
|
||||
** Da ordinare.
|
||||
*/
|
||||
$qta_presente = $articolo->qta > 0 ? $articolo->qta : 0;
|
||||
$diff = ($qta_presente - $impegnato + $ordinato) * -1;
|
||||
$da_ordinare = $diff < 0 ? 0 : $diff;
|
||||
|
||||
echo '
|
||||
<div class="col-md-3">
|
||||
<div class="alert alert-info" style="height: 75px;"><i class="fa fa-info-circle"></i> Quantità richieste dal cliente meno le quantità già ordinate</div>
|
||||
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Da ordinare</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-center" style="font-size:35pt;">
|
||||
<b>
|
||||
'.numberFormat($da_ordinare).' '.$articolo->um.'</b>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
/**
|
||||
** Disponibile.
|
||||
*/
|
||||
$qta_disponibile = $qta_presente - $impegnato;
|
||||
$disponibile = $qta_presente < 0 ? 0 : $qta_presente;
|
||||
echo '
|
||||
<div class="col-md-3">
|
||||
<div class="alert alert-info" style="height: 75px;"><i class="fa fa-info-circle"></i> Quantità disponibili nel magazzino</div>
|
||||
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Disponibile</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-center" style="font-size:35pt;">
|
||||
'.numberFormat($disponibile).' '.$articolo->um.'</b>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
$sedi = $dbo->fetchArray('(SELECT "0" AS id, "Sede legale" AS nomesede) UNION (SELECT id, CONCAT(nomesede, " - ", citta ) AS nomesede FROM an_sedi WHERE idanagrafica='.prepare(setting('Azienda predefinita')).')');
|
||||
|
||||
echo '
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.tr('Giacenze').'</h3>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<table class="table table-striped table-condensed table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="400">'.tr('Sede').'</th>
|
||||
<th width="200">'.tr('Q.tà').'</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>';
|
||||
|
||||
foreach ($sedi as $sede) {
|
||||
// Lettura movimenti delle mie sedi
|
||||
$qta_azienda = $dbo->fetchOne("SELECT SUM(mg_movimenti.qta) AS qta, IF(mg_movimenti.idsede_azienda= 0,'Sede legale',(CONCAT_WS(' - ',an_sedi.nomesede,an_sedi.citta))) as sede FROM mg_movimenti LEFT JOIN an_sedi ON an_sedi.id = mg_movimenti.idsede_azienda WHERE mg_movimenti.idarticolo=".prepare($id_record).' AND idsede_azienda='.prepare($sede['id']).' GROUP BY idsede_azienda');
|
||||
|
||||
// Lettura eventuali movimenti ad una propria sede (nel caso di movimenti fra sedi della mia azienda)
|
||||
if ($sede['id'] != 0) {
|
||||
$qta_controparte = $dbo->fetchOne("SELECT SUM(mg_movimenti.qta) AS qta, IF(mg_movimenti.idsede_controparte= 0,'Sede legale',(CONCAT_WS(' - ',an_sedi.nomesede,an_sedi.citta))) as sede FROM mg_movimenti LEFT JOIN an_sedi ON an_sedi.id = mg_movimenti.idsede_controparte WHERE mg_movimenti.idarticolo=".prepare($id_record).' AND idsede_controparte='.prepare($sede['id']).' GROUP BY idsede_controparte');
|
||||
} else {
|
||||
$qta_controparte = $dbo->fetchOne("SELECT SUM(mg_movimenti.qta) AS qta, IF(mg_movimenti.idsede_controparte= 0,'Sede legale',(CONCAT_WS(' - ',an_sedi.nomesede,an_sedi.citta))) as sede FROM ((( mg_movimenti LEFT JOIN an_sedi ON an_sedi.id = mg_movimenti.idsede_controparte ) LEFT JOIN dt_ddt ON mg_movimenti.idddt = dt_ddt.id ) LEFT JOIN co_documenti ON mg_movimenti.iddocumento = co_documenti.id ) WHERE mg_movimenti.idarticolo=".prepare($id_record).' AND idsede_controparte='.prepare($sede['id']).' AND IFNULL( dt_ddt.idanagrafica, co_documenti.idanagrafica ) = '.prepare(setting('Azienda predefinita')).' GROUP BY idsede_controparte');
|
||||
}
|
||||
|
||||
echo '
|
||||
<tr>
|
||||
<td>'.$sede['nomesede'].'</td>
|
||||
<td class="text-right">'.Translator::numberToLocale($qta_azienda['qta'] - $qta_controparte['qta']).'</td>
|
||||
</tr>';
|
||||
} ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
echo '
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
@ -3,7 +3,6 @@
|
||||
include_once __DIR__.'/../../../core.php';
|
||||
|
||||
// Movimentazione degli articoli
|
||||
|
||||
echo '
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
@ -30,9 +29,8 @@ if (empty($_GET['show_all1'])) {
|
||||
$query .= ' LIMIT 0, 20';
|
||||
}
|
||||
|
||||
$rs2 = $dbo->fetchArray($query);
|
||||
|
||||
if (!empty($rs2)) {
|
||||
$movimenti = $dbo->fetchArray($query);
|
||||
if (!empty($movimenti)) {
|
||||
if (empty($_GET['show_all1'])) {
|
||||
echo '
|
||||
<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>';
|
||||
@ -44,42 +42,63 @@ if (!empty($rs2)) {
|
||||
echo '
|
||||
<table class="table table-striped table-condensed table-bordered">
|
||||
<tr>
|
||||
<th >'.tr('Q.tà').'</th>
|
||||
<th >'.tr('Causale').'</th>
|
||||
<th >'.tr('Data').'</th>
|
||||
<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>
|
||||
<th class="text-center" width="7%">#</th>
|
||||
</tr>';
|
||||
foreach ($rs2 as $r) {
|
||||
|
||||
foreach ($movimenti as $i => $movimento) {
|
||||
// Quantità progressiva
|
||||
if ($i == 0) {
|
||||
$movimento['progressivo_finale'] = $articolo->qta;
|
||||
} else {
|
||||
$movimento['progressivo_finale'] = $movimenti[$i - 1]['progressivo_iniziale'];
|
||||
}
|
||||
$movimento['progressivo_iniziale'] = $movimento['progressivo_finale'] - intval($movimento['qta']);
|
||||
|
||||
$movimenti[$i]['progressivo_iniziale'] = $movimento['progressivo_iniziale'];
|
||||
$movimenti[$i]['progressivo_finale'] = $movimento['progressivo_finale'];
|
||||
|
||||
// Quantità
|
||||
echo '
|
||||
<tr>
|
||||
<td class="text-right">'.Translator::numberToLocale($r['qta'], 'qta').' '.$record['um'].'</td>';
|
||||
<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>';
|
||||
|
||||
// Causale
|
||||
$dir = ($r['qta'] < 0) ? 'vendita' : 'acquisto';
|
||||
$dir = ($movimento['qta'] < 0) ? 'vendita' : 'acquisto';
|
||||
|
||||
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';
|
||||
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';
|
||||
}
|
||||
|
||||
echo '
|
||||
<td>'.$r['movimento'].'
|
||||
'.((!empty($r['idintervento'])) ? Modules::link('Interventi', $r['idintervento']) : '').'
|
||||
'.((!empty($r['idddt'])) ? (Modules::link('DDt di '.$dir, $r['idddt'], null, null, (intval($database->fetchOne('SELECT * FROM `dt_ddt` WHERE `id` ='.prepare($r['idddt'])))) ? '' : 'class="disabled"')) : '').'
|
||||
'.((!empty($r['iddocumento'])) ? (Modules::link('Fatture di '.$dir, $r['iddocumento'], null, null, (intval($database->fetchOne('SELECT * FROM `co_documenti` WHERE `id` ='.prepare($r['iddocumento'])))) ? '' : 'class="disabled"')) : '').'
|
||||
<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"')) : '').'
|
||||
</td>';
|
||||
|
||||
// Data
|
||||
echo '
|
||||
<td class="text-center" >'.Translator::dateToLocale($r['data']).' <span class=\'tip\' title=\''.tr('Data del movimento: ').Translator::timestampToLocale($r['created_at']).'\' ><i class="fa fa-question-circle-o"></i></span> </td>';
|
||||
<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>';
|
||||
|
||||
// Operazioni
|
||||
echo '
|
||||
<td class="text-center">';
|
||||
|
||||
if (Auth::admin() && $r['manuale'] == '1') {
|
||||
if (Auth::admin() && $movimento['manuale'] == '1') {
|
||||
echo '
|
||||
<a class="btn btn-danger btn-sm ask" data-backto="record-edit" data-op="delmovimento" data-idmovimento="'.$r['id'].'">
|
||||
<a class="btn btn-danger btn-sm ask" data-backto="record-edit" data-op="delmovimento" data-idmovimento="'.$movimento['id'].'">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>';
|
||||
}
|
||||
@ -88,13 +107,14 @@ if (!empty($rs2)) {
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</table>';
|
||||
} else {
|
||||
echo '
|
||||
<div class="alert alert-info">
|
||||
<i class="fa fa-info-circle"></i>
|
||||
'.tr('Questo articolo non è ancora stato movimentato', []).'.
|
||||
'.tr('Questo articolo non è ancora stato movimentato').'.
|
||||
</div>';
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user