2019-05-29 19:17:57 +02:00
< ? php
2024-12-02 11:17:31 +01:00
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*/
2019-05-29 19:17:57 +02:00
2019-09-11 16:50:42 +02:00
include_once __DIR__ . '/../../../core.php' ;
$impegnato = 0 ;
$ordinato = 0 ;
2024-03-22 15:52:24 +01:00
$query = ' SELECT
2024-03-01 11:32:13 +01:00
`or_ordini` . `id` AS id ,
`or_ordini` . `numero` ,
`or_ordini` . `numero_esterno` ,
`data` ,
SUM ( `or_righe_ordini` . `qta` ) AS qta_ordinata ,
SUM ( `or_righe_ordini` . `qta` - `or_righe_ordini` . `qta_evasa` ) AS qta_impegnata ,
`or_righe_ordini` . `um`
FROM
`or_ordini`
INNER JOIN `or_righe_ordini` ON `or_ordini` . `id` = `or_righe_ordini` . `idordine`
INNER JOIN `or_statiordine` ON `or_ordini` . `idstatoordine` = `or_statiordine` . `id`
2024-03-01 15:07:42 +01:00
INNER JOIN `or_tipiordine` ON `or_ordini` . `idtipoordine` = `or_tipiordine` . `id`
2024-03-01 11:32:13 +01:00
WHERE
2024-03-22 15:52:24 +01:00
`idarticolo` = ' . prepare ( $articolo -> id ) . "
2024-03-01 11:32:13 +01:00
AND `or_tipiordine` . `dir` = '|dir|'
AND ( `or_righe_ordini` . `qta` - `or_righe_ordini` . `qta_evasa` ) > 0
AND `or_righe_ordini` . `confermato` = 1
AND `or_statiordine` . `impegnato` = 1
2024-09-03 18:02:02 +02:00
GROUP BY
`or_ordini` . `id`
2024-03-01 11:32:13 +01:00
HAVING
`qta_ordinata` > 0 " ;
2019-09-11 16:50:42 +02:00
/*
** Impegnato
*/
echo '
< div class = " row " >
< div class = " col-md-3 " >
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Impegnato ').' < span class = " tip pull-right " title = " '.tr('Quantità impegnate in ordini cliente che non siano già completamente evasi.').' " >
2019-11-23 06:48:58 +01:00
< i class = " fa fa-question-circle-o " ></ i ></ span ></ h3 >
2019-09-11 16:50:42 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " style = " min-height:98px; " > ' ;
2019-09-11 16:50:42 +02:00
2019-09-12 09:12:11 +02:00
$ordini = $dbo -> fetchArray ( str_replace ( '|dir|' , 'entrata' , $query ));
2021-03-09 17:26:12 +01:00
$impegnato = sum ( array_column ( $ordini , 'qta_impegnata' ));
2019-09-12 09:12:11 +02:00
if ( ! empty ( $ordini )) {
echo '
2024-10-16 15:48:50 +02:00
< table class = " table table-bordered table-sm table-striped " >
2019-09-11 16:50:42 +02:00
< thead >
< tr >
2019-09-12 09:12:11 +02:00
< th > '.tr(' Descrizione ').' </ th >
2021-03-09 19:36:51 +01:00
< th class = " text-right " > '.$record[' um '].' </ th >
2019-09-11 16:50:42 +02:00
</ tr >
</ thead >
2020-09-07 15:04:06 +02:00
2019-09-11 16:50:42 +02:00
< tbody > ' ;
2019-09-12 09:12:11 +02:00
foreach ( $ordini as $documento ) {
$numero = ! empty ( $documento [ 'numero_esterno' ]) ? $documento [ 'numero_esterno' ] : $documento [ 'numero' ];
2021-03-09 17:26:12 +01:00
$qta = $documento [ 'qta_impegnata' ];
2019-09-11 16:50:42 +02:00
2019-09-12 09:12:11 +02:00
echo '
2019-09-11 16:50:42 +02:00
< tr >
< td >
2021-03-09 19:36:51 +01:00
< small >
2024-03-08 11:54:00 +01:00
'.Modules::link(' Ordini cliente ', $documento[' id '], tr(' Ordine num . _NUM_ del _DATE_ ' , [
2024-03-22 15:52:24 +01:00
'_NUM_' => $numero ,
'_DATE_' => dateFormat ( $documento [ 'data' ]),
])) . '
2021-03-09 19:36:51 +01:00
</ small >
2019-09-11 16:50:42 +02:00
</ td >
< td class = " text-right " >
2023-04-18 11:21:48 +02:00
< small > '.numberFormat($qta, ' qta ').' </ small >
2019-09-11 16:50:42 +02:00
</ td >
</ tr > ' ;
2019-09-12 09:12:11 +02:00
}
2019-09-11 16:50:42 +02:00
2019-09-12 09:12:11 +02:00
echo '
2019-09-11 16:50:42 +02:00
< tr >
< td class = " text-right " >
2021-03-09 19:36:51 +01:00
< small >< b > '.tr(' Totale ').' </ b ></ small >
2019-09-11 16:50:42 +02:00
</ td >
< td class = " text-right " >
2023-04-18 11:21:48 +02:00
< small > '.numberFormat($impegnato, ' qta ').' </ small >
2019-09-11 16:50:42 +02:00
</ td >
</ tr >
2019-09-12 09:12:11 +02:00
</ table > ' ;
} else {
echo '
< p > '.tr(' Nessun ordine cliente con quantità da evadere individuato ').' .</ p > ' ;
}
echo '
2019-09-11 16:50:42 +02:00
</ div >
</ div >
</ div > ' ;
/*
** In ordine
*/
echo '
< div class = " col-md-3 " >
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' In ordine ').' < span class = " tip pull-right " title = " '.tr('Quantità ordinate al fornitore in ordini che non siano già completamente evasi.').' " >
2019-11-23 06:48:58 +01:00
< i class = " fa fa-question-circle-o " ></ i ></ span ></ h3 >
2019-09-11 16:50:42 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " style = " min-height:98px; " > ' ;
2019-09-11 16:50:42 +02:00
2019-09-12 09:12:11 +02:00
$ordini = $dbo -> fetchArray ( str_replace ( '|dir|' , 'uscita' , $query ));
2024-03-01 15:07:42 +01:00
2019-09-12 09:12:11 +02:00
if ( ! empty ( $ordini )) {
2024-03-01 15:07:42 +01:00
$ordinato = sum ( array_column ( $ordini , 'qta_ordinata' ));
2019-09-12 09:12:11 +02:00
echo '
2024-10-16 15:48:50 +02:00
< table class = " table table-bordered table-sm table-striped " >
2019-09-11 16:50:42 +02:00
< thead >
< tr >
2019-09-12 09:12:11 +02:00
< th > '.tr(' Descrizione ').' </ th >
2021-03-09 19:36:51 +01:00
< th class = " text-right " > '.$record[' um '].' </ th >
2019-09-11 16:50:42 +02:00
</ tr >
</ thead >
2020-09-07 15:04:06 +02:00
2019-09-11 16:50:42 +02:00
< tbody > ' ;
2019-09-12 09:12:11 +02:00
foreach ( $ordini as $documento ) {
$numero = ! empty ( $documento [ 'numero_esterno' ]) ? $documento [ 'numero_esterno' ] : $documento [ 'numero' ];
$qta = $documento [ 'qta_ordinata' ];
2019-09-11 16:50:42 +02:00
2019-09-12 09:12:11 +02:00
echo '
2019-09-11 16:50:42 +02:00
< tr >
< td >
2021-03-09 19:36:51 +01:00
< small >
2024-03-08 11:54:00 +01:00
'.Modules::link(' Ordini fornitore ', $documento[' id '], tr(' Ordine num . _NUM_ del _DATE_ ' , [
2024-03-22 15:52:24 +01:00
'_NUM_' => $numero ,
'_DATE_' => dateFormat ( $documento [ 'data' ]),
])) . '
2021-03-09 19:36:51 +01:00
</ small >
2019-09-11 16:50:42 +02:00
</ td >
< td class = " text-right " >
2023-04-18 11:21:48 +02:00
< small > '.numberFormat($qta, ' qta ').' </ small >
2019-09-11 16:50:42 +02:00
</ td >
</ tr > ' ;
2019-09-12 09:12:11 +02:00
}
2019-09-11 16:50:42 +02:00
2019-09-12 09:12:11 +02:00
echo '
2019-09-11 16:50:42 +02:00
< tr >
< td class = " text-right " >
2021-03-09 19:36:51 +01:00
< small >< b > '.tr(' Totale ').' </ b ></ small >
2019-09-11 16:50:42 +02:00
</ td >
< td class = " text-right " >
2023-04-18 11:21:48 +02:00
< small > '.numberFormat($ordinato, ' qta ').' </ small >
2019-09-11 16:50:42 +02:00
</ td >
</ tr >
2019-09-12 09:12:11 +02:00
</ table > ' ;
} else {
echo '
< p > '.tr(' Nessun ordine fornitore con quantità da evadere individuato ').' .</ p > ' ;
}
echo '
2019-09-11 16:50:42 +02:00
</ div >
</ div >
</ div > ' ;
/**
** Da ordinare .
*/
$qta_presente = $articolo -> qta > 0 ? $articolo -> qta : 0 ;
$diff = ( $qta_presente - $impegnato + $ordinato ) * - 1 ;
2021-03-09 17:26:12 +01:00
$da_ordinare = (( $diff <= 0 ) ? 0 : $diff );
2019-09-11 16:50:42 +02:00
echo '
< div class = " col-md-3 " >
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Da ordinare ').' < span class = " tip pull-right " title = " '.tr('Quantità richieste dal cliente meno le quantità già ordinate.').' " >
2019-11-23 06:48:58 +01:00
< i class = " fa fa-question-circle-o " ></ i ></ span ></ h3 >
2019-09-11 16:50:42 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2019-09-11 16:50:42 +02:00
< div class = " row " >
< div class = " col-md-12 text-center " style = " font-size:35pt; " >
2023-04-18 11:21:48 +02:00
'.numberFormat($da_ordinare, ' qta ').' '.$articolo->um.'
2019-09-11 16:50:42 +02:00
</ div >
</ div >
</ div >
</ div >
</ div > ' ;
/**
** Disponibile .
*/
2020-02-13 11:42:29 +01:00
$disponibile = $qta_presente - $impegnato ;
2019-09-11 16:50:42 +02:00
echo '
< div class = " col-md-3 " >
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Disponibile ').' < span class = " tip pull-right " title = " '.tr('Quantità disponibili nel magazzino.').' " >
2019-11-23 06:48:58 +01:00
< i class = " fa fa-question-circle-o " ></ i ></ span ></ h3 >
2019-09-11 16:50:42 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2019-09-11 16:50:42 +02:00
< div class = " row " >
< div class = " col-md-12 text-center " style = " font-size:35pt; " >
2023-04-18 11:21:48 +02:00
'.numberFormat($disponibile, ' qta ').' '.$articolo->um.'
2019-09-11 16:50:42 +02:00
</ div >
</ div >
</ div >
</ div >
</ div >
</ div > ' ;
2021-06-10 17:44:21 +02:00
$sedi = $dbo -> fetchArray ( '(SELECT "0" AS id, IF(indirizzo!=\'\', CONCAT_WS(" - ", "' . tr ( 'Sede legale' ) . '", CONCAT(citta, \' (\', indirizzo, \')\')), CONCAT_WS(" - ", "' . tr ( 'Sede legale' ) . '", citta)) AS nomesede FROM an_anagrafiche WHERE idanagrafica = ' . prepare ( setting ( 'Azienda predefinita' )) . ') UNION (SELECT id, IF(indirizzo!=\'\',CONCAT_WS(" - ", nomesede, CONCAT(citta, \' (\', indirizzo, \')\')), CONCAT_WS(" - ", nomesede, citta )) AS nomesede FROM an_sedi WHERE idanagrafica=' . prepare ( setting ( 'Azienda predefinita' )) . ')' );
2020-11-13 17:54:58 +01:00
$giacenze = $articolo -> getGiacenze ();
2019-05-29 19:17:57 +02:00
2019-09-11 16:50:42 +02:00
echo '
2019-05-29 19:17:57 +02:00
< div class = " row " >
2019-09-11 16:50:42 +02:00
< div class = " col-md-12 " >
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Giacenze ').' </ h3 >
2019-09-11 16:50:42 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2024-10-16 15:48:50 +02:00
< table class = " table table-striped table-sm table-bordered " >
2019-09-11 16:50:42 +02:00
< thead >
< tr >
2022-10-11 10:58:32 +02:00
< th > '.tr(' Sede ').' </ th >
2024-11-20 08:59:35 +01:00
< th class = " text-center " width = " 20% " > '.tr(' Soglia minima quantità ').' </ th >
< th width = " 20% " class = " text-center " > '.tr(' Giacenza ').' </ th >
2022-10-11 10:58:32 +02:00
< th width = " 5% " class = " text-center " > #</th>
2019-09-11 16:50:42 +02:00
</ tr >
</ thead >
2020-09-07 15:04:06 +02:00
2019-09-11 16:50:42 +02:00
< tbody > ' ;
foreach ( $sedi as $sede ) {
2024-11-20 08:59:35 +01:00
$scorta = $dbo -> selectOne ( 'mg_scorte_sedi' , '*' , [ 'id_sede' => $sede [ 'id' ], 'id_articolo' => $id_record ]);
2019-09-11 16:50:42 +02:00
echo '
2024-11-20 08:59:35 +01:00
< tr data - id = " '. $sede['id'] .' " >
2019-06-17 11:10:32 +02:00
< td > '.$sede[' nomesede '].' </ td >
2024-11-20 08:59:35 +01:00
< td >
{[ " type " : " number " , " decimals " : " qta " , " name " : " scorta_'. $sede['id'] .' " , " value " : " '. $scorta['threshold_qta'] .' " , " onchange " : " aggiornaSogliaMinima( $ (this).closest( \ 'tr \ ').data( \ 'id \ ')) " ]}
</ td >
< td class = " text-right " >
{[ " type " : " number " , " decimals " : " qta " , " name " : " giacenza_'. $sede['id'] .' " , " value " : " '. $giacenze[$sede['id'] ][0].' " , " onchange " : " aggiornaGiacenza( $ (this).closest( \ 'tr \ ').data( \ 'id \ '), \ ''. $giacenze[$sede['id'] ][0].' \ ') " ]}
</ td >
2022-10-11 10:58:32 +02:00
< td class = " text-center " >
< a class = " btn btn-xs btn-info " title = " Dettagli " onclick = " getDettagli('. $sede['id'] .'); " >
< i class = " fa fa-eye " ></ i >
</ a >
</ td >
2019-05-29 19:17:57 +02:00
</ tr > ' ;
2019-09-11 16:50:42 +02:00
}
2024-01-15 15:30:45 +01:00
echo '
2019-09-11 16:50:42 +02:00
</ tbody >
</ table >
</ div >
</ div >
2019-05-29 19:17:57 +02:00
</ div >
2019-09-11 16:50:42 +02:00
</ div > ' ;
2022-10-11 10:58:32 +02:00
echo '
< script >
function getDettagli ( idsede ) {
// Apertura modal
openModal ( " '.tr('Dettagli').' " , " '. $rootdir .'/modules/articoli/plugins/dettagli_giacenze.php?id_module= " + globals . id_module + " &id_record= " + globals . id_record + " &idsede= " + idsede );
}
2024-11-20 08:59:35 +01:00
function aggiornaSogliaMinima ( id_sede ) {
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " POST " ,
data : {
id_module : globals . id_module ,
id_record : globals . id_record ,
op : " update_soglia_minima " ,
id_sede : id_sede ,
threshold_qta : $ ( " #scorta_ " + id_sede ) . val ()
},
success : function ( response ) {
renderMessages ();
},
error : function ( xhr , status , error ) {
renderMessages ();
}
});
}
function aggiornaGiacenza ( id_sede , giacenza ) {
content_was_modified = false ;
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " POST " ,
data : {
id_module : globals . id_module ,
id_record : globals . id_record ,
op : " update_giacenza " ,
id_sede : id_sede ,
qta : giacenza ,
new_qta : $ ( " #giacenza_ " + id_sede ) . val ()
},
success : function ( response ) {
location . reload ();
},
error : function ( xhr , status , error ) {
location . reload ();
}
});
}
2023-08-04 14:54:28 +02:00
</ script > ' ;