2017-08-04 16:28:16 +02:00
< ? php
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 />.
*/
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../../core.php' ;
2024-03-05 16:01:45 +01:00
use Models\Module ;
2024-03-22 15:52:24 +01:00
use Modules\Anagrafiche\Anagrafica ;
2024-02-26 08:52:46 +01:00
2022-10-18 11:28:06 +02:00
echo '
< div class = " panel panel-primary " >
< div class = " panel-heading " >
< h3 class = " panel-title " > '.tr(' Articolo ').' </ h3 >
</ div >
< div class = " panel-body " >
< div class = " row " >
< div class = " col-md-6 " >
2023-08-04 14:54:28 +02:00
< span >< b > '.tr(' Codice : ').' </ b > '.$articolo->codice.' </ span >
2022-10-18 11:28:06 +02:00
</ div >
< div class = " col-md-6 " >
2024-03-19 18:18:11 +01:00
< span >< b > '.tr(' Descrizione : ').' </ b > '.$articolo->getTranslation(' name ').' </ span >
2022-10-18 11:28:06 +02:00
</ div >
</ div >
</ div >
</ div > ' ;
2017-08-04 16:28:16 +02:00
// Movimentazione degli articoli
echo '
< div class = " box " >
< div class = " box-header with-border " >
2017-09-04 12:02:29 +02:00
< h3 class = " box-title " > '.tr(' Movimenti ').' </ h3 >
2020-03-03 10:33:32 +01:00
< div class = " pull-right " > ' ;
2022-10-18 11:28:06 +02:00
echo '
2024-03-27 16:59:46 +01:00
< a class = " btn btn-warning btn-xs " onclick = " openModal( \ ''.tr('Movimenta articolo').' \ ', \ ''.base_path().'/modules/articoli/modals/add_movimento.php?id_module='.(new Module())->getByField('name', 'Movimenti', Models \ Locale::getPredefined()->id).'&id_articolo='. $id_record .' \ '); " >
2022-10-18 11:28:06 +02:00
< i class = " fa fa-truck " ></ i >
'.tr(' Movimenta articolo ').'
</ a > ' ;
2020-03-03 10:33:32 +01:00
if ( empty ( $_GET [ 'movimentazione_completa' ])) {
echo '
2020-09-23 17:53:19 +02:00
< a class = " btn btn-info btn-xs " href = " '.base_path().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&movimentazione_completa=1#tab_'. $id_plugin .' " >
2020-03-03 10:33:32 +01:00
< i class = " fa fa-eye " ></ i >
'.tr(' Mostra tutti i movimenti ').'
</ a > ' ;
} else {
echo '
2020-09-23 17:53:19 +02:00
< a class = " btn btn-info btn-xs " href = " '.base_path().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&movimentazione_completa=0#tab_'. $id_plugin .' " >
2020-03-03 10:33:32 +01:00
< i class = " fa fa-eye-slash " ></ i >
'.tr(' Mostra gli ultimi 20 movimenti ').'
</ a > ' ;
}
echo '
2024-03-27 16:59:46 +01:00
< a class = " btn btn-warning btn-xs " href = " '.base_path().'/controller.php?id_module='.(new Module())->getByField('name', 'Movimenti', Models \ Locale::getPredefined()->id).'&search_Articolo='.( $articolo->codice .' - '. $articolo->getTranslation ('name')).' " >
2020-03-03 10:33:32 +01:00
< i class = " fa fa-external-link " ></ i >
'.tr(' Visualizza dettagli ').'
</ a > ' ;
echo '
</ div >
2017-08-04 16:28:16 +02:00
</ div >
< div class = " box-body " > ' ;
// Calcolo la quantità dai movimenti in magazzino
2019-11-15 18:03:59 +01:00
$qta_totale = $dbo -> fetchOne ( 'SELECT SUM(qta) AS qta FROM mg_movimenti WHERE idarticolo=' . prepare ( $id_record ))[ 'qta' ];
$qta_totale_attuale = $dbo -> fetchOne ( 'SELECT SUM(qta) AS qta FROM mg_movimenti WHERE idarticolo=' . prepare ( $id_record ) . ' AND data <= CURDATE()' )[ 'qta' ];
2017-08-04 16:28:16 +02:00
2019-11-15 18:03:59 +01:00
echo '
2020-03-03 10:33:32 +01:00
< p > '.tr(' Quantità calcolata dai movimenti ').' : < b > '.Translator::numberToLocale($qta_totale, ' qta ').' '.$record[' um '].' </ b > < span class = " tip " title = " '.tr('Quantità calcolata da tutti i movimenti registrati').'. " >< i class = " fa fa-question-circle-o " ></ i ></ span ></ p > ' ;
2017-08-04 16:28:16 +02:00
2019-11-15 18:03:59 +01:00
echo '
2020-03-03 10:33:32 +01:00
< p > '.tr(' Quantità calcolata attuale ').' : < b > '.Translator::numberToLocale($qta_totale_attuale, ' qta ').' '.$record[' um '].' </ b > < span class = " tip " title = " '.tr('Quantità calcolata secondo i movimenti registrati con data oggi o date trascorse').'. " >< i class = " fa fa-question-circle-o " ></ i ></ span ></ p > ' ;
2018-05-17 11:37:23 +02:00
2020-03-03 10:33:32 +01:00
// Individuazione movimenti
$movimenti = $articolo -> movimentiComposti ()
2021-06-18 11:38:00 +02:00
-> orderBy ( 'mg_movimenti.data' , 'DESC' )
-> orderBy ( 'mg_movimenti.id' , 'DESC' );
2020-03-03 10:33:32 +01:00
if ( empty ( $_GET [ 'movimentazione_completa' ])) {
$movimenti -> limit ( 20 );
2017-08-04 16:28:16 +02:00
}
2020-03-03 10:33:32 +01:00
// Raggruppamento per documento
2021-06-18 11:38:00 +02:00
$movimenti = $movimenti -> leftJoin ( 'an_sedi' , 'mg_movimenti.idsede' , 'an_sedi.id' ) -> get ();
2019-09-11 16:50:42 +02:00
if ( ! empty ( $movimenti )) {
2017-08-04 16:28:16 +02:00
echo '
< table class = " table table-striped table-condensed table-bordered " >
< tr >
2021-06-18 11:38:00 +02:00
< th class = " text-center " width = " 120 " > '.tr(' Q . tà ').' </ th >
2019-09-11 16:50:42 +02:00
< th class = " text-center " > '.tr(' Q . tà progressiva ').' </ th >
2020-03-03 10:33:32 +01:00
< th > '.tr(' Operazione ').' </ th >
2024-02-26 08:52:46 +01:00
< th > '.tr(' Controparte ').' </ th >
2021-06-18 11:38:00 +02:00
< th class = " text-center " > '.tr(' Sede ').' </ th >
< th class = " text-center " width = " 120 " > '.tr(' Data ').' </ th >
< th class = " text-center " width = " 80 " > #</th>
2017-08-04 16:28:16 +02:00
</ tr > ' ;
2019-09-11 16:50:42 +02:00
foreach ( $movimenti as $i => $movimento ) {
// Quantità progressiva
if ( $i == 0 ) {
$movimento [ 'progressivo_finale' ] = $articolo -> qta ;
} else {
$movimento [ 'progressivo_finale' ] = $movimenti [ $i - 1 ][ 'progressivo_iniziale' ];
}
2020-03-03 10:33:32 +01:00
$movimento [ 'progressivo_iniziale' ] = $movimento [ 'progressivo_finale' ] - $movimento -> qta ;
$movimento [ 'progressivo_iniziale' ] = $movimento [ 'progressivo_finale' ] - $movimento -> qta ;
2019-09-11 16:50:42 +02:00
$movimenti [ $i ][ 'progressivo_iniziale' ] = $movimento [ 'progressivo_iniziale' ];
$movimenti [ $i ][ 'progressivo_finale' ] = $movimento [ 'progressivo_finale' ];
2017-08-04 16:28:16 +02:00
// Quantità
echo '
< tr >
2019-09-11 16:50:42 +02:00
< td class = " text-center " >
2020-03-03 10:33:32 +01:00
'.numberFormat($movimento->qta, ' qta ').' '.$record[' um '].'
2019-09-11 16:50:42 +02:00
</ td >
2020-03-03 10:33:32 +01:00
2019-09-11 16:50:42 +02:00
< 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 '].'
2020-03-03 10:33:32 +01:00
</ td >
< td >
'.$movimento->descrizione.' '.($movimento->hasDocument() ? ' - '.reference($movimento->getDocument()) : ' ').'
2021-06-18 11:38:00 +02:00
</ td >
2024-02-26 08:52:46 +01:00
< td >
'.Anagrafica::find($movimento->getDocument()->idanagrafica)->ragione_sociale.'
</ td >
2021-06-18 11:38:00 +02:00
< td class = " text-center " >
2021-07-07 07:57:10 +02:00
'.($movimento->nomesede ?: tr(' Sede legale ')).'
2020-03-03 10:33:32 +01:00
</ td > ' ;
2017-08-04 16:28:16 +02:00
// Data
2023-08-04 14:54:28 +02:00
$utente = $dbo -> table ( 'zz_users' ) -> where ( 'id' , $movimento -> idutente ) -> first ();
2023-01-11 11:03:56 +01:00
$data = ( $movimento -> data ? $movimento -> data : $movimento -> data_movimento );
2017-08-04 16:28:16 +02:00
echo '
2023-01-11 11:03:56 +01:00
< td class = " text-center " > '.dateFormat($data).' < span class = " tip " title = " '.tr('Creazione movimento: _DATE_ <br>Creatore movimento: _USER_', [
2024-03-22 15:52:24 +01:00
'_DATE_' => timestampFormat ( $movimento -> data_movimento ),
'_USER_' => $utente -> username ,
]) . '"><i class="fa fa-question-circle-o"></i></span> </td>' ;
2017-09-05 17:31:58 +02:00
// Operazioni
echo '
< td class = " text-center " > ' ;
2020-03-03 10:33:32 +01:00
if ( Auth :: admin () && $movimento -> isManuale ()) {
2017-09-05 17:31:58 +02:00
echo '
2021-10-28 11:31:04 +02:00
< a class = " btn btn-danger btn-xs ask " data - backto = " record-edit " data - op = " delmovimento " data - idmovimento = " '. $movimento->tipo_gruppo .' " >
2017-09-05 17:31:58 +02:00
< i class = " fa fa-trash " ></ i >
</ a > ' ;
}
echo '
</ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
}
2019-09-11 16:50:42 +02:00
2017-08-04 16:28:16 +02:00
echo '
</ table > ' ;
} else {
2018-06-26 14:30:26 +02:00
echo '
2018-05-17 12:58:53 +02:00
< div class = " alert alert-info " >
< i class = " fa fa-info-circle " ></ i >
2019-09-11 16:50:42 +02:00
'.tr(' Questo articolo non è ancora stato movimentato ').' .
2018-05-17 12:58:53 +02:00
</ div > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
</ div >
</ div > ' ;