2021-11-29 17:35:29 +01:00
< ? php
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
* Copyright ( C ) DevCode s . r . l .
*
* 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 />.
*/
include_once __DIR__ . '/../../core.php' ;
include_once __DIR__ . '/../init.php' ;
2024-03-05 16:01:45 +01:00
use Models\Module ;
2024-03-22 15:52:24 +01:00
use Modules\Fatture\Fattura ;
2021-11-29 17:35:29 +01:00
2024-01-02 15:52:43 +01:00
if ( empty ( $_GET [ 'visualizza_movimenti' ])) {
2021-11-29 17:35:29 +01:00
echo '
2024-01-02 15:52:43 +01:00
< div class = " row " >
< div class = " col-md-12 text-center " >
< a class = " btn btn-info btn-lg " href = " '.base_path().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&visualizza_movimenti=1#tab_'. $id_plugin .' " >
< i class = " fa fa-eye " ></ i >
'.tr(' Visualizza tutti i movimenti ').'
</ a >
</ div >
</ div > ' ;
} else {
2024-04-18 17:44:05 +02:00
$modulo = Module :: find ( $id_module ) -> getTranslation ( 'title' );
2024-01-02 15:52:43 +01:00
if ( $modulo == 'Anagrafiche' ) {
$movimenti = $dbo -> fetchArray ( 'SELECT co_movimenti.*, SUM(totale) AS totale, co_pianodeiconti3.descrizione, co_pianodeiconti3.numero AS conto3, co_pianodeiconti2.numero AS conto2 FROM co_movimenti LEFT JOIN co_pianodeiconti3 ON co_movimenti.idconto=co_pianodeiconti3.id LEFT JOIN co_pianodeiconti2 ON co_pianodeiconti3.idpianodeiconti2=co_pianodeiconti2.id WHERE id_anagrafica=' . prepare ( $id_record ) . ' GROUP BY idmastrino, idconto ORDER BY data, idmastrino' );
} else {
$movimenti = $dbo -> fetchArray ( 'SELECT co_movimenti.*, SUM(totale) AS totale, co_pianodeiconti3.descrizione, co_pianodeiconti3.numero AS conto3, co_pianodeiconti2.numero AS conto2 FROM co_movimenti LEFT JOIN co_pianodeiconti3 ON co_movimenti.idconto=co_pianodeiconti3.id LEFT JOIN co_pianodeiconti2 ON co_pianodeiconti3.idpianodeiconti2=co_pianodeiconti2.id WHERE iddocumento=' . prepare ( $id_record ) . ' GROUP BY idmastrino, idconto ORDER BY data, idmastrino' );
}
2022-01-20 14:36:20 +01:00
2024-01-02 15:52:43 +01:00
$idmastrini_processati = [ - 1 ];
2022-01-20 14:36:20 +01:00
2024-01-02 15:52:43 +01:00
if ( ! empty ( $movimenti )) {
2023-08-04 14:54:28 +02:00
echo '
2024-01-02 15:52:43 +01:00
< table class = " table table-hover table-condensed table-bordered table-striped " style = " font-size:11pt; " >
< thead >
2022-01-20 14:36:20 +01:00
< tr >
2024-01-02 15:52:43 +01:00
< th width = " 160 " > '.tr(' Data ').' </ th >
< th > '.tr(' Conto ').' </ th >
< th width = " 170 " > '.tr(' Dare ').' </ th >
< th width = " 170 " > '.tr(' Avere ').' </ th >
< th width = " 170 " > '.tr(' Scalare ').' </ th >
</ tr >
</ thead >
2022-02-25 18:13:11 +01:00
2024-01-02 15:52:43 +01:00
< tbody > ' ;
2022-02-25 18:13:11 +01:00
2024-01-02 15:52:43 +01:00
foreach ( $movimenti as $movimento ) {
$documento = $modulo == 'Anagrafiche' ? Fattura :: find ( $movimento [ 'iddocumento' ]) : null ;
$scalare += $movimento [ 'totale' ];
$descrizione = $movimento [ 'conto2' ] . '.' . $movimento [ 'conto3' ] . ' - ' . $movimento [ 'descrizione' ];
2022-02-25 18:13:11 +01:00
2024-01-02 15:52:43 +01:00
if ( $movimento [ 'primanota' ] == 1 ) {
$descrizione = Modules :: link ( 'Prima nota' , $movimento [ 'idmastrino' ], $descrizione );
2023-08-04 14:54:28 +02:00
}
2022-02-25 18:13:11 +01:00
2023-08-04 14:54:28 +02:00
echo '
2022-02-25 18:13:11 +01:00
< tr >
2024-01-02 15:52:43 +01:00
< td class = " text-center " > '.Translator::dateToLocale($movimento[' data ']).' </ td >
2022-02-25 18:13:11 +01:00
< td > '.$descrizione.' < small class = " pull-right text-right text-muted " style = " font-size:8pt; " > '.($documento ? $documento->getReference() : ' ').' </ small ></ td >
2024-01-02 15:52:43 +01:00
< td class = " text-right " > '.($movimento[' totale '] > 0 ? moneyFormat(abs($movimento[' totale '])) : ' ').' </ td >
< td class = " text-right " > '.($movimento[' totale '] < 0 ? moneyFormat(abs($movimento[' totale '])) : ' ').' </ td >
2022-02-25 18:13:11 +01:00
< td class = " text-right " > '.moneyFormat($scalare).' </ td >
</ tr > ' ;
2024-01-02 15:52:43 +01:00
$idmastrini_processati [] = $movimento [ 'idmastrino' ];
2021-11-29 17:35:29 +01:00
}
2024-01-02 15:52:43 +01:00
// Altri movimenti del mastrino collegati ma non direttamente collegati alla fattura (es. spese bancarie)
if ( $modulo != 'Anagrafiche' ) {
$altri_movimenti = $dbo -> fetchArray ( 'SELECT co_movimenti.*, SUM(totale) AS totale, co_pianodeiconti3.descrizione, co_pianodeiconti3.numero AS conto3, co_pianodeiconti2.numero AS conto2 FROM co_movimenti LEFT JOIN co_pianodeiconti3 ON co_movimenti.idconto=co_pianodeiconti3.id LEFT JOIN co_pianodeiconti2 ON co_pianodeiconti3.idpianodeiconti2=co_pianodeiconti2.id WHERE iddocumento=0 AND idmastrino IN(' . implode ( ',' , $idmastrini_processati ) . ') GROUP BY idmastrino, idconto ORDER BY data, idmastrino' );
foreach ( $altri_movimenti as $altro_movimento ) {
$documento = $modulo == 'Anagrafiche' ? Fattura :: find ( $altro_movimento [ 'iddocumento' ]) : null ;
$scalare += $altro_movimento [ 'totale' ];
$descrizione = $altro_movimento [ 'conto2' ] . '.' . $altro_movimento [ 'conto3' ] . ' - ' . $altro_movimento [ 'descrizione' ];
if ( $altro_movimento [ 'primanota' ] == 1 ) {
$descrizione = Modules :: link ( 'Prima nota' , $altro_movimento [ 'idmastrino' ], $descrizione );
}
echo '
< tr >
< td class = " text-center " > '.Translator::dateToLocale($altro_movimento[' data ']).' </ td >
< td > '.$descrizione.' < small class = " pull-right text-right text-muted " style = " font-size:8pt; " > '.($documento ? $documento->getReference() : ' ').' </ small ></ td >
< td class = " text-right " > '.($altro_movimento[' totale '] > 0 ? moneyFormat(abs($altro_movimento[' totale '])) : ' ').' </ td >
< td class = " text-right " > '.($altro_movimento[' totale '] < 0 ? moneyFormat(abs($altro_movimento[' totale '])) : ' ').' </ td >
< td class = " text-right " > '.moneyFormat($scalare).' </ td >
</ tr > ' ;
}
}
echo '
</ tbody >
</ table > ' ;
} else {
echo '
< h3 class = " text-center " >
< small class = " help-block " > '.tr(' Non sono presenti movimenti contabili ').' </ small >
</ h3 > ' ;
2023-08-04 14:54:28 +02:00
}
2024-01-04 14:47:06 +01:00
}