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 '
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(' Articolo ').' </ h3 >
2022-10-18 11:28:06 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2022-10-18 11:28:06 +02:00
< 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-04-18 17:44:05 +02:00
< span >< b > '.tr(' Descrizione : ').' </ b > '.$articolo->getTranslation(' title ').' </ 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 '
2024-05-16 18:02:50 +02:00
< div class = " card " >
< div class = " card-header with-border " >
< h3 class = " card-title " > '.tr(' Movimenti ').' </ h3 >
< div class = " float-right d-none d-sm-inline " > ' ;
2022-10-18 11:28:06 +02:00
echo '
2024-06-11 16:58:27 +02:00
< a class = " btn btn-warning btn-xs " onclick = " openModal( \ ''.tr('Movimenta articolo').' \ ', \ ''.base_path().'/modules/articoli/modals/add_movimento.php?id_module='.Module::where('name', 'Movimenti')->first()->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-06-11 16:58:27 +02:00
< a class = " btn btn-warning btn-xs " href = " '.base_path().'/controller.php?id_module='.Module::where('name', 'Movimenti')->first()->id.'&search_Articolo='.( $articolo->codice .' - '. $articolo->getTranslation ('title')).' " >
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 >
2024-05-16 18:02:50 +02:00
< div class = " card-body " > ' ;
2017-08-04 16:28:16 +02:00
// 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
}
2024-09-03 12:44:38 +02:00
$giacenze = $articolo -> getGiacenze ();
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 '
2024-10-16 15:48:50 +02:00
< table class = " table table-striped table-sm table-bordered " >
2017-08-04 16:28:16 +02:00
< tr >
2024-07-30 17:03:49 +02:00
< th class = " text-center " width = " 40 " > #</th>
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
2024-09-03 12:44:38 +02:00
if ( $mov [ $movimento [ 'idsede' ]][ 'progressivo_finale' ] === null ) {
$movimento [ 'progressivo_finale' ] = $giacenze [ $movimento [ 'idsede' ]][ 0 ];
2019-09-11 16:50:42 +02:00
} else {
2024-09-03 12:44:38 +02:00
$movimento [ 'progressivo_finale' ] = $mov [ $movimento [ 'idsede' ]][ 'progressivo_iniziale' ];
2019-09-11 16:50:42 +02:00
}
2024-08-27 09:20:20 +02:00
2020-03-03 10:33:32 +01:00
$movimento [ 'progressivo_iniziale' ] = $movimento [ 'progressivo_finale' ] - $movimento -> qta ;
2024-08-27 09:20:20 +02:00
2024-09-03 12:44:38 +02:00
$mov [ $movimento [ 'idsede' ]][ 'progressivo_iniziale' ] = $movimento [ 'progressivo_iniziale' ];
$mov [ $movimento [ 'idsede' ]][ 'progressivo_finale' ] = $movimento [ 'progressivo_finale' ];
2019-09-11 16:50:42 +02:00
2017-08-04 16:28:16 +02:00
// Quantità
echo '
< tr >
2024-07-30 17:03:49 +02:00
< td class = " text-center " >
2024-08-27 09:20:20 +02:00
'.count($movimenti) - $i.'
2024-07-30 17:03:49 +02:00
</ td >
2024-08-27 09:20:20 +02:00
< td class = " text-center " style = " color: '.( $movimento->qta < 0 ? 'red' : 'green').'; " >
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 ();
2024-04-08 15:44:33 +02:00
$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 > ' ;