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' ;
2019-12-21 19:07:02 +01:00
// Verifico se è già stata eseguita l'apertura bilancio
$bilancio_gia_aperto = $dbo -> fetchNum ( 'SELECT id FROM co_movimenti WHERE is_apertura=1 AND data BETWEEN ' . prepare ( $_SESSION [ 'period_start' ]) . ' AND ' . prepare ( $_SESSION [ 'period_end' ]));
$msg = tr ( 'Sei sicuro di voler aprire il bilancio?' );
$btn_class = 'btn-info' ;
2019-12-24 12:36:35 +01:00
if ( $bilancio_gia_aperto ) {
2019-12-21 19:07:02 +01:00
$msg .= ' ' . tr ( 'I movimenti di apertura già esistenti verranno annullati e ricreati' ) . '.' ;
$btn_class = 'btn-default' ;
}
2020-08-06 10:41:21 +02:00
echo '
2021-11-29 15:40:19 +01:00
< div class = " row " >
2024-05-17 12:11:00 +02:00
< div class = " offset-md-4 col-md-3 " >
2024-07-30 16:23:04 +02:00
< input type = " text " class = " form-control form-control-lg text-center " id = " input-cerca " placeholder = " '.tr('Cerca').'... " >
2021-11-29 15:40:19 +01:00
</ div >
2022-03-11 09:11:14 +01:00
< div class = " col-md-1 " >
< button type = " button " class = " btn btn-lg btn-primary " id = " button-search " >
< i class = " fa fa-search " ></ i > '.tr(' Cerca ').'
</ button >
</ div >
2021-11-29 15:40:19 +01:00
< div class = " col-md-4 text-right " >
< button type = " button " class = " btn btn-lg '. $btn_class .' " data - op = " apri-bilancio " data - title = " '.tr('Apertura bilancio').' " data - backto = " record-list " data - msg = " '. $msg .' " data - button = " '.tr('Riprendi saldi').' " data - class = " btn btn-lg btn-warning " onclick = " message( this ); " >
< i class = " fa fa-folder-open " ></ i > '.tr(' Apertura bilancio ').'
</ button >
</ div >
2020-08-06 10:41:21 +02:00
</ div > ' ;
2019-12-21 19:07:02 +01:00
2019-07-08 15:48:48 +02:00
// Livello 1
2020-08-11 17:09:00 +02:00
$query1 = 'SELECT * FROM `co_pianodeiconti1` ORDER BY id DESC' ;
2019-07-08 15:48:48 +02:00
$primo_livello = $dbo -> fetchArray ( $query1 );
2019-07-08 17:11:48 +02:00
foreach ( $primo_livello as $conto_primo ) {
2018-02-10 19:42:52 +01:00
$totale_attivita = [];
$totale_passivita = [];
2017-08-04 16:28:16 +02:00
2018-02-10 19:42:52 +01:00
$costi = [];
$ricavi = [];
2019-07-08 17:11:48 +02:00
$titolo = $conto_primo [ 'descrizione' ] == 'Economico' ? tr ( 'Conto economico' ) : tr ( 'Stato patrimoniale' );
2019-07-08 15:48:48 +02:00
echo '
< hr >
2024-05-16 18:02:50 +02:00
< div class = " card conto1 " >
< div class = " card-header " >
< h3 class = " card-title " >
2021-07-02 10:20:07 +02:00
'.$titolo.'
2024-05-16 18:02:50 +02:00
< button type = " button " class = " btn btn-xs btn-primary " data - card - widget = " tooltip " title = " '.tr('Aggiungi un nuovo conto...').' " onclick = " aggiungiConto('. $conto_primo['id'] .', 2) " >
2021-07-02 10:20:07 +02:00
< i class = " fa fa-plus-circle " ></ i >
</ button >
</ h3 >
2019-07-08 15:48:48 +02:00
</ div >
2019-12-27 10:28:53 +01:00
2024-05-16 18:02:50 +02:00
< div class = " card-body " > ' ;
2017-08-04 16:28:16 +02:00
2017-09-14 18:48:45 +02:00
// Livello 2
2020-08-06 14:42:59 +02:00
$query2 = 'SELECT * FROM `co_pianodeiconti2` WHERE idpianodeiconti1 = ' . prepare ( $conto_primo [ 'id' ]) . ' ORDER BY numero ASC' ;
2019-07-08 15:48:48 +02:00
$secondo_livello = $dbo -> fetchArray ( $query2 );
2017-08-04 16:28:16 +02:00
2019-07-08 17:11:48 +02:00
foreach ( $secondo_livello as $conto_secondo ) {
2017-09-14 18:48:45 +02:00
// Livello 2
2022-04-07 14:50:27 +02:00
if ( $conto_primo [ 'descrizione' ] == 'Economico' ) {
$totale_conto2 = $dbo -> fetchOne ( 'SELECT SUM(-totale) AS totale FROM `co_movimenti` INNER JOIN co_pianodeiconti3 ON co_movimenti.idconto=co_pianodeiconti3.id WHERE idconto IN(SELECT id FROM co_pianodeiconti3 WHERE idpianodeiconti2=' . prepare ( $conto_secondo [ 'id' ]) . ') AND co_movimenti.data>=' . prepare ( $_SESSION [ 'period_start' ]) . ' AND co_movimenti.data<=' . prepare ( $_SESSION [ 'period_end' ]))[ 'totale' ];
} else {
$totale_conto2 = $dbo -> fetchOne ( 'SELECT SUM(totale) AS totale FROM `co_movimenti` INNER JOIN co_pianodeiconti3 ON co_movimenti.idconto=co_pianodeiconti3.id WHERE idconto IN(SELECT id FROM co_pianodeiconti3 WHERE idpianodeiconti2=' . prepare ( $conto_secondo [ 'id' ]) . ') AND co_movimenti.data>=' . prepare ( $_SESSION [ 'period_start' ]) . ' AND co_movimenti.data<=' . prepare ( $_SESSION [ 'period_end' ]))[ 'totale' ];
}
2023-08-04 14:54:28 +02:00
2019-07-08 15:48:48 +02:00
echo '
2022-03-11 09:11:14 +01:00
< div class = " conto2 " id = " conto2-'. $conto_secondo['id'] .' " >
2024-05-16 18:02:50 +02:00
< div class = " float-right d-none d-sm-inline " >
2022-03-11 09:11:14 +01:00
< b > '.moneyFormat($totale_conto2, 2).' </ b >& ensp ; & ensp ;
2021-11-29 15:40:19 +01:00
'.Prints::getLink(' Mastrino ', $conto_secondo[' id '], ' btn - info btn - xs ', ' ', null, ' lev = 2 ').'
< button type = " button " class = " btn btn-warning btn-xs " onclick = " modificaConto('. $conto_secondo['id'] .', 2) " >
< i class = " fa fa-edit " ></ i >
</ button >
2024-05-16 18:02:50 +02:00
< button type = " button " class = " btn btn-xs btn-primary " data - card - widget = " tooltip " title = " '.tr('Aggiungi un nuovo conto...').' " onclick = " aggiungiConto('. $conto_secondo['id'] .') " >
2021-11-29 15:40:19 +01:00
< i class = " fa fa-plus-circle " ></ i >
</ button >
</ div >
2022-03-11 09:11:14 +01:00
< h5 >
2024-02-23 15:14:00 +01:00
< button type = " button " id = " conto2-'. $conto_secondo['id'] .' " class = " btn btn-default btn-xs plus-btn search " >< i class = " fa fa-plus " ></ i ></ button >
< span class = " clickable " id = " conto2-'. $conto_secondo['id'] .' " >
2022-03-11 09:11:14 +01:00
< b > '.$conto_secondo[' numero '].' '.$conto_secondo[' descrizione '].' </ b >
</ span >
< div id = " conto2_'. $conto_secondo['id'] .' " style = " display:none; " ></ div >
</ h5 >
2019-07-08 15:48:48 +02:00
</ div > ' ;
2021-01-29 11:13:01 +01:00
// Somma dei totali
2024-04-12 13:22:14 +02:00
if ( $totale_conto2 ) {
if ( $conto_primo [ 'descrizione' ] == 'Patrimoniale' ) {
if ( $totale_conto2 > 0 ) {
$totale_attivita [] = abs ( $totale_conto2 );
} else {
$totale_passivita [] = abs ( $totale_conto2 );
}
2021-01-29 11:13:01 +01:00
} else {
2024-04-12 13:22:14 +02:00
if ( $totale_conto2 > 0 ) {
$totale_ricavi [] = abs ( $totale_conto2 );
} else {
$totale_costi [] = abs ( $totale_conto2 );
}
2021-01-29 11:13:01 +01:00
}
}
2021-02-18 18:48:44 +01:00
$totale_conto2 = 0 ;
$totale_reddito2 = 0 ;
2019-07-08 15:48:48 +02:00
}
2017-08-04 16:28:16 +02:00
2019-07-08 15:48:48 +02:00
echo '
</ div >
2019-12-27 10:28:53 +01:00
2024-10-16 15:48:50 +02:00
< table class = " table table-sm table-hover totali " > ' ;
2020-08-06 14:42:59 +02:00
2019-07-08 15:48:48 +02:00
// Riepiloghi
if ( $conto_primo [ 'descrizione' ] == 'Patrimoniale' ) {
2018-02-10 19:42:52 +01:00
$attivita = abs ( sum ( $totale_attivita ));
$passivita = abs ( sum ( $totale_passivita ));
$utile_perdita = abs ( sum ( $totale_ricavi )) - abs ( sum ( $totale_costi ));
2017-08-04 16:28:16 +02:00
if ( $utile_perdita < 0 ) {
$pareggio1 = $attivita + abs ( $utile_perdita );
$pareggio2 = abs ( $passivita );
} else {
$pareggio1 = $attivita ;
$pareggio2 = abs ( $passivita ) + abs ( $utile_perdita );
}
2017-09-14 18:48:45 +02:00
// Attività
2019-07-08 15:48:48 +02:00
echo '
2020-08-06 14:42:59 +02:00
< tr >
< th class = " text-right " >
< big > '.tr(' Totale attività ').' :</ big >
</ th >
< td class = " text-right " width = " 150 " >
< big > '.moneyFormat($attivita, 2).' </ big >
</ td >
< td width = " 50 " ></ td > ' ;
2017-08-04 16:28:16 +02:00
2017-09-14 18:48:45 +02:00
// Passività
2019-07-08 15:48:48 +02:00
echo '
2020-08-06 14:42:59 +02:00
< th class = " text-right " >
< big > '.tr(' Passività ').' :</ big >
</ th >
< td class = " text-right " width = " 150 " >
< big > '.moneyFormat($passivita, 2).' </ big >
</ td >
2022-03-11 09:11:14 +01:00
< td width = " 100 " ></ td >
2020-08-06 14:42:59 +02:00
</ tr > ' ;
2017-08-04 16:28:16 +02:00
2017-09-14 18:48:45 +02:00
// Perdita d'esercizio
2017-08-04 16:28:16 +02:00
if ( $utile_perdita < 0 ) {
2019-07-08 15:48:48 +02:00
echo '
2020-08-06 14:42:59 +02:00
< tr >
< th class = " text-right " >
< big > '.tr("Perdita d' esercizio " ).':</big>
</ th >
< td class = " text-right " >
< big > '.moneyFormat(sum($utile_perdita), 2).' </ big >
</ td >
< td ></ td >
< td ></ td >
< td ></ td >
2022-03-11 09:11:14 +01:00
< td ></ td >
2020-08-06 14:42:59 +02:00
</ tr > ' ;
2017-08-04 16:28:16 +02:00
} else {
2019-07-08 15:48:48 +02:00
echo '
2020-08-06 14:42:59 +02:00
< tr >
< td ></ td >
< td ></ td >
< td ></ td >
< th class = " text-right " >
< big > '.tr(' Utile ').' :</ big >
</ th >
< td class = " text-right " >
< big > '.moneyFormat(sum($utile_perdita), 2).' </ big >
</ td >
2022-03-11 09:11:14 +01:00
< td ></ td >
2020-08-06 14:42:59 +02:00
</ tr > ' ;
2017-08-04 16:28:16 +02:00
}
2017-09-14 18:48:45 +02:00
// Totale a pareggio
2019-07-08 15:48:48 +02:00
echo '
2020-08-06 14:42:59 +02:00
< tr >
< th class = " text-right " >
< big > '.tr(' Totale a pareggio ').' :</ big >
</ th >
< td class = " text-right " width = " 150 " >
< big > '.moneyFormat(sum($pareggio1), 2).' </ big >
</ td >
< td width = " 50 " ></ td >
< th class = " text-right " >
< big > '.tr(' Totale a pareggio ').' :</ big >
</ th >
< td class = " text-right " width = " 150 " >
< big > '.moneyFormat(sum($pareggio2), 2).' </ big >
</ td >
2022-03-11 09:11:14 +01:00
< td ></ td >
2020-08-06 14:42:59 +02:00
</ tr > ' ;
2017-08-04 16:28:16 +02:00
} else {
2019-07-08 15:48:48 +02:00
echo '
2020-08-06 14:42:59 +02:00
< tr >
< th class = " text-right " >
< big > '.tr(' Ricavi ').' :</ big >
</ th >
< td class = " text-right " width = " 150 " >
< big > '.moneyFormat(sum($totale_ricavi), 2).' </ big >
</ td >
2022-03-11 09:11:14 +01:00
< td width = " 100 " ></ td >
2020-08-06 14:42:59 +02:00
</ tr >
< tr >
< th class = " text-right " >
< big > '.tr(' Costi ').' :</ big >
</ th >
< td class = " text-right " width = " 150 " >
< big > '.moneyFormat(sum($totale_costi), 2).' </ big >
</ td >
2022-03-11 09:11:14 +01:00
< td ></ td >
2020-08-06 14:42:59 +02:00
</ tr >
2021-11-29 15:40:19 +01:00
< tr class = " totali " >
2020-08-06 14:42:59 +02:00
< th class = " text-right " >
< big > '.tr(' Utile / perdita ').' :</ big >
</ th >
< td class = " text-right " width = " 150 " >
< big > '.moneyFormat(sum($totale_ricavi) - abs(sum($totale_costi)), 2).' </ big >
</ td >
2022-03-11 09:11:14 +01:00
< td ></ td >
2020-08-06 14:42:59 +02:00
</ tr > ' ;
2017-08-04 16:28:16 +02:00
}
2019-07-08 15:48:48 +02:00
2019-07-08 17:11:48 +02:00
echo '
2020-08-06 14:42:59 +02:00
</ table >
</ div >
</ div > ' ;
2019-07-08 15:48:48 +02:00
}
2019-12-21 19:07:02 +01:00
// Verifico se è già stata eseguita l'apertura bilancio
$bilancio_gia_chiuso = $dbo -> fetchNum ( 'SELECT id FROM co_movimenti WHERE is_chiusura=1 AND data BETWEEN ' . prepare ( $_SESSION [ 'period_start' ]) . ' AND ' . prepare ( $_SESSION [ 'period_end' ]));
$msg = tr ( 'Sei sicuro di voler aprire il bilancio?' );
$btn_class = 'btn-info' ;
2019-12-24 12:36:35 +01:00
if ( $bilancio_gia_chiuso ) {
2019-12-21 19:07:02 +01:00
$msg .= ' ' . tr ( 'I movimenti di apertura già esistenti verranno annullati e ricreati' ) . '.' ;
$btn_class = 'btn-default' ;
}
2020-08-06 10:41:21 +02:00
echo '
2019-12-21 19:07:02 +01:00
< div class = " text-right " >
2020-08-06 10:41:21 +02:00
< button type = " button " class = " btn btn-lg '. $btn_class .' " data - op = " chiudi-bilancio " data - title = " '.tr('Chiusura bilancio').' " data - backto = " record-list " data - msg = " '. $msg .' " data - button = " '.tr('Chiudi bilancio').' " data - class = " btn btn-lg btn-primary " onclick = " message( this ); " >
< i class = " fa fa-folder " ></ i > '.tr(' Chiusura bilancio ').'
</ button >
2019-12-21 19:07:02 +01:00
</ div >
2020-08-06 14:42:59 +02:00
< div class = " clearfix " ></ div >
< hr >
2019-07-08 15:48:48 +02:00
< script >
2020-08-06 10:41:21 +02:00
$ ( document ) . ready ( function () {
2023-04-06 17:23:22 +02:00
$ ( " #input-cerca " ) . keyup ( function ( key ) {
if ( key . which == 13 ) {
$ ( " #button-search " ) . click ();
}
});
2024-02-23 15:14:00 +01:00
$ ( " button[id^=conto2-] " ) . each ( function () {
2021-07-02 10:20:07 +02:00
$ ( this ) . on ( " click " , function () {
2022-03-11 09:11:14 +01:00
let conto3 = $ ( this ) . parent () . find ( " div[id^=conto2_] " );
2021-07-02 10:20:07 +02:00
2022-03-11 09:11:14 +01:00
if ( ! conto3 . html ()) {
2021-07-02 10:20:07 +02:00
let id_conto = $ ( this ) . attr ( " id " ) . split ( " - " ) . pop ();
2022-03-11 09:11:14 +01:00
caricaConti3 ( conto3 . attr ( " id " ), id_conto );
2021-07-02 10:20:07 +02:00
} else {
2022-03-11 09:11:14 +01:00
conto3 . slideToggle ();
2021-07-02 10:20:07 +02:00
}
$ ( this ) . parent () . find ( " .plus-btn i " ) . toggleClass ( " fa-plus " ) . toggleClass ( " fa-minus " );
2020-08-06 10:41:21 +02:00
});
2022-03-11 09:11:14 +01:00
});
2020-08-06 10:41:21 +02:00
});
2019-12-27 10:28:53 +01:00
2021-07-02 10:20:07 +02:00
function aggiungiConto ( id_conto , level = 3 ) {
openModal ( " '.tr('Nuovo conto').' " , " '. $structure->fileurl ('add_conto.php').'?id= " + id_conto + " &lvl= " + level );
2020-08-06 10:41:21 +02:00
}
2019-07-08 15:48:48 +02:00
2020-08-06 14:42:59 +02:00
function modificaConto ( id_conto , level = 3 ) {
launch_modal ( " '.tr('Modifica conto').' " , " '. $structure->fileurl ('edit_conto.php').'?id= " + id_conto + " &lvl= " + level );
}
2022-03-11 09:11:14 +01:00
function caricaConti3 ( selector , id_conto ) {
2020-08-06 10:41:21 +02:00
$ ( " #main_loading " ) . show ();
$ . ajax ({
2022-03-11 09:11:14 +01:00
url : " '. $structure->fileurl ('dettagli_conto2.php').' " ,
2020-08-06 10:41:21 +02:00
type : " get " ,
data : {
id_module : globals . id_module ,
id_conto : id_conto ,
},
success : function ( data ){
$ ( " # " + selector ) . html ( data )
. slideToggle ();
$ ( " #main_loading " ) . fadeOut ();
}
});
}
2019-07-08 15:48:48 +02:00
2020-08-06 10:41:21 +02:00
function aggiornaReddito ( id_conto ){
2020-08-11 17:23:25 +02:00
openModal ( " '.tr('Ricalcola importo deducibile').' " , " '. $structure->fileurl ('aggiorna_reddito.php').'?id= " + id_conto )
2020-08-06 10:41:21 +02:00
}
2021-11-29 15:40:19 +01:00
2022-03-11 09:11:14 +01:00
$ ( " #button-search " ) . on ( " click " , function (){
var text = $ ( " #input-cerca " ) . val ();
2024-02-23 15:14:00 +01:00
2022-03-11 09:11:14 +01:00
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " POST " ,
dataType : " json " ,
data : {
id_module : globals . id_module ,
text : text ,
op : " search " ,
},
success : function ( results ) {
if ( results . conti2 === 0 && results . conti3 === 0 ){
$ ( " .conto2 " ) . each ( function () {
if ( $ ( this ) . find ( " .search > i " ) . hasClass ( " fa-minus " )) {
$ ( this ) . find ( " .search " ) . click ();
}
});
$ ( " .conto3 " ) . show ();
$ ( " .conto1 " ) . show ();
$ ( " .conto2 " ) . show ();
$ ( " .totali " ) . show ();
} else {
$ ( " .conto1 " ) . hide ();
$ ( " .conto2 " ) . hide ();
$ ( " .conto3 " ) . hide ();
$ ( " .totali " ) . hide ();
results . conti2 . forEach ( function ( item ) {
$ ( " #conto2- " + item ) . parent () . parent () . show ();
$ ( " #conto2- " + item ) . show ();
});
results . conti2_3 . forEach ( function ( item ) {
$ ( " #conto2- " + item ) . parent () . parent () . show ();
$ ( " #conto2- " + item ) . show ();
if ( $ ( " #conto2- " + item ) . find ( " .search > i " ) . hasClass ( " fa-plus " )) {
$ ( " #conto2- " + item ) . find ( " .search " ) . click ();
}
});
results . conti3 . forEach ( function ( item ) {
$ ( " #conto3- " + item ) . show ();
});
}
}
});
2021-11-29 15:40:19 +01:00
});
$ . expr [ " : " ] . contains = $ . expr . createPseudo ( function ( arg ) {
return function ( elem ) {
return $ ( elem ) . text () . toUpperCase () . indexOf ( arg . toUpperCase ()) >= 0 ;
};
});
2020-08-06 10:41:21 +02:00
</ script > ' ;