2020-07-01 18:10:00 +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 />.
*/
2020-07-01 18:10:00 +02:00
include_once __DIR__ . '/../../core.php' ;
2022-03-02 16:38:58 +01:00
use Models\Module ;
2022-10-26 17:24:40 +02:00
use Carbon\Carbon ;
2022-03-02 16:38:58 +01:00
2020-07-01 18:10:00 +02:00
$id_record = filter ( 'id_record' );
$dir = filter ( 'dir' );
2020-07-02 17:30:09 +02:00
$nome_stampa = filter ( 'nome_stampa' );
2022-03-02 16:38:58 +01:00
$id_print = $dbo -> fetchOne ( 'SELECT id FROM zz_prints WHERE name=' . prepare ( $nome_stampa ))[ 'id' ];
$id_module = Module :: pool ( 'Stampe contabili' ) -> id ;
2020-07-01 18:10:00 +02:00
2022-10-26 17:24:40 +02:00
$year = ( new Carbon ( $_SESSION [ 'period_end' ])) -> format ( 'Y' );
$periodi [] = [
'id' => 'manuale' ,
'text' => tr ( 'Manuale' ),
];
$month_start = 1 ;
$month_end = 3 ;
for ( $i = 1 ; $i <= 4 ; $i ++ ) {
$periodi [] = [
'id' => '' . $i . '_trimestre' ,
'text' => tr ( '_NUM_° Trimestre _YEAR_' , [ '_NUM_' => $i , '_YEAR_' => $year ]),
'date_start' => $year . ',' . $month_start . ',01' ,
'date_end' => $year . ',' . $month_end . ',' . ( new Carbon ( $year . '-' . $month_end . '-01' )) -> endOfMonth () -> format ( 'd' ),
];
$month_start += 3 ;
$month_end += 3 ;
}
for ( $i = 1 ; $i <= 12 ; $i ++ ) {
$month = ( new Carbon ( $year . '-' . $i . '-01' )) -> locale ( 'it' ) -> getTranslatedMonthName ( 'IT MMMM' );
$periodi [] = [
'id' => '' . $i . '_mese' ,
'text' => tr ( '_MONTH_ _YEAR_' , [ '_MONTH_' => $month , '_YEAR_' => $year ]),
'date_start' => $year . ',' . $i . ',01' ,
'date_end' => $year . ',' . $i . ',' . ( new Carbon ( $year . '-' . $i . '-01' )) -> endOfMonth () -> format ( 'd' ),
];
}
2020-07-01 18:10:00 +02:00
// Trovo id_print della stampa
2020-07-02 17:30:09 +02:00
$link = Prints :: getHref ( $nome_stampa , $id_record );
2020-07-01 18:10:00 +02:00
echo '
2022-03-02 16:38:58 +01:00
< div class = " alert alert-info hidden " id = " period " >
2022-03-11 09:51:46 +01:00
< i class = " fa fa-exclamation-circle " ></ i > '.tr(' Non è possibile creare la stampa definitiva nel periodo selezionato , è necessario prima impostare un trimestre o un singolo mese ! ').'
2022-03-02 16:38:58 +01:00
</ div >
2020-07-01 18:10:00 +02:00
2022-03-02 16:38:58 +01:00
< div class = " alert alert-warning hidden " id = " is_definitiva " >
< i class = " fa fa-warning " ></ i > '.tr(' È già presente la stampa definitiva per il periodo selezionato ! ').'
</ div >
2020-10-13 17:50:37 +02:00
2022-03-02 16:38:58 +01:00
< form action = " " method = " post " id = " form " >
< div class = " row " > ' ;
echo '
2020-07-02 17:30:09 +02:00
< div class = " col-md-4 " >
2022-03-02 16:38:58 +01:00
{[ " type " : " date " , " label " : " '.tr('Data inizio').' " , " required " : " 1 " , " name " : " date_start " , " value " : " '. $_SESSION['period_start'] .' " ]}
2020-07-02 17:30:09 +02:00
</ div >
< div class = " col-md-4 " >
2022-03-02 16:38:58 +01:00
{[ " type " : " date " , " label " : " '.tr('Data fine').' " , " required " : " 1 " , " name " : " date_end " , " value " : " '. $_SESSION['period_end'] .' " ]}
2020-07-02 17:30:09 +02:00
</ div >
2022-10-26 17:24:40 +02:00
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr('Periodo').' " , " name " : " periodo " , " required " : " 1 " , " values " : '.json_encode($periodi).' , " value " : " manuale " ]}
</ div >
2020-07-02 17:30:09 +02:00
</ div > ' ;
2022-03-02 16:38:58 +01:00
echo '
2022-10-26 17:24:40 +02:00
< div class = " row " > ' ;
if ( $nome_stampa != 'Liquidazione IVA' ) {
echo '
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr('Sezionale').' " , " name " : " id_sezionale " , " required " : " 1 " , " values " : " query=SELECT id AS id, name AS descrizione FROM zz_segments WHERE id_module = (SELECT id FROM zz_modules WHERE name = \ ''.(( $dir == 'entrata') ? 'Fatture di vendita' : 'Fatture di acquisto').' \ ') AND is_fiscale = 1 UNION SELECT 0 AS id, \ 'Tutti i sezionali \ ' AS descrizione " ]}
</ div > ' ;
}
echo '
2020-07-02 17:30:09 +02:00
< div class = " col-md-4 " >
2020-07-01 18:10:00 +02:00
{[ " type " : " select " , " label " : " '.tr('Formato').' " , " name " : " format " , " required " : " 1 " , " values " : " list= \" A4 \" : \" '.tr('A4').' \" , \" A3 \" : \" '.tr('A3').' \" " , " value " : " '. $_SESSION['stampe_contabili'] ['format'].' " ]}
</ div >
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr('Orientamento').' " , " name " : " orientation " , " required " : " 1 " , " values " : " list= \" L \" : \" '.tr('Orizzontale').' \" , \" P \" : \" '.tr('Verticale').' \" " , " value " : " '. $_SESSION['stampe_contabili'] ['orientation'].' " ]}
2022-03-02 16:38:58 +01:00
</ div > ' ;
2020-07-01 18:10:00 +02:00
2022-03-02 16:38:58 +01:00
if ( $nome_stampa != 'Liquidazione IVA' ) {
echo '
2020-07-02 17:30:09 +02:00
< div class = " col-md-4 " >
2022-03-11 09:51:46 +01:00
{[ " type " : " checkbox " , " label " : " '.tr('Definitiva').' " , " disabled " : " 1 " , " name " : " definitiva " , " help " : " '.tr('Per abilitare il pulsante è necessario impostare nei campi Data inizio e Data fine uno dei 4 trimestri o un singolo mese e non deve essere già stata creata la stampa definitiva del periodo selezionato').' " ]}
2022-03-02 16:38:58 +01:00
</ div > ' ;
}
echo '
< div class = " col-md-4 pull-right " >
2020-07-01 18:10:00 +02:00
< p style = " line-height:14px; " >& nbsp ; </ p >
2022-03-02 16:38:58 +01:00
< button type = " button " class = " btn btn-primary btn-block " onclick = " if( $ ( \ '#form \ ').parsley().validate()) { return avvia_stampa(); } " >
2020-07-01 18:10:00 +02:00
< i class = " fa fa-print " ></ i > '.tr(' Stampa ').'
</ button >
</ div >
</ div >
</ form >
2022-03-02 16:38:58 +01:00
< br > ' ;
if ( $nome_stampa != 'Liquidazione IVA' ) {
$elementi = $dbo -> fetchArray ( 'SELECT * FROM co_stampecontabili WHERE date_end BETWEEN ' . prepare ( $_SESSION [ 'period_start' ]) . ' AND ' . prepare ( $_SESSION [ 'period_end' ]) . ' AND id_print=' . prepare ( $id_print ) . ' AND dir=' . prepare ( $dir ));
echo '
< div class = " box box-primary collapsable collapsed-box " >
< div class = " box-header with-border " >
< h3 class = " box-title " >< i class = " fa fa-print " ></ i > '.tr(' Stampe definitive registro iva _DIR_ dal _START_ al _END_ ' , [
'_DIR_' => $dir == 'entrata' ? 'vendite' : 'acquisti' ,
'_START_' => dateFormat ( $_SESSION [ 'period_start' ]),
'_END_' => dateFormat ( $_SESSION [ 'period_end' ]),
]) . ' </ h3 >
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >< i class = " fa fa-plus " ></ i ></ button >
</ div >
</ div >
< div class = " box-body " >
< ul > ' ;
foreach ( $elementi as $elemento ) {
$descrizione = tr ( 'Stampa definitiva dal _START_ al _END_ (_FIRST_-_LAST_)' , [
'_START_' => dateFormat ( $elemento [ 'date_start' ]),
'_END_' => dateFormat ( $elemento [ 'date_end' ]),
'_FIRST_' => $elemento [ 'first_page' ],
'_LAST_' => $elemento [ 'last_page' ],
]);
$file = $dbo -> selectOne ( 'zz_files' , '*' , [ 'id_module' => $id_module , 'id_record' => $elemento [ 'id' ]]);
echo '
< li >
< a class = " btn btn-xs btn-primary " href = " '.base_path().'/actions.php?id_module='. $id_module .'&op=download-allegato&id='. $file['id'] .'&filename='. $file['filename'] .' " target = " _blank " >< i class = " fa fa-download " ></ i >
</ a >
'.$descrizione.'
</ li > ' ;
}
if ( empty ( $elementi )) {
echo '<p class="text-center">' . tr ( 'Nessuna stampa presente' ) . '</p>' ;
}
echo '
</ ul >
</ div >
</ div > ' ;
2020-07-01 18:10:00 +02:00
2022-03-02 16:38:58 +01:00
echo '
< script >
$ ( document ) . ready ( function () {
2022-10-26 17:24:40 +02:00
setTimeout ( function () {
eseguiControlli ();
}, 1000 );
2022-03-02 16:38:58 +01:00
});
2022-10-26 17:24:40 +02:00
$ ( " #date_start " ) . on ( " blur " , function (){
2022-03-02 16:38:58 +01:00
eseguiControlli ();
});
2022-10-26 17:24:40 +02:00
$ ( " #date_end " ) . on ( " blur " , function (){
2022-03-02 16:38:58 +01:00
eseguiControlli ();
});
function eseguiControlli () {
let date_start = $ ( " #date_start " ) . data ( " DateTimePicker " ) . date () . format ( " YYYY-MM-DD " );
let date_end = $ ( " #date_end " ) . data ( " DateTimePicker " ) . date () . format ( " YYYY-MM-DD " );
controllaDate ( date_start , date_end );
}
2022-03-11 09:51:46 +01:00
// Controllo se le date inserite corrispondono ad uno dei 4 trimestri o ad un mese
2022-03-02 16:38:58 +01:00
function controllaDate ( date_start , date_end ) {
let intervallo_corretto = 0 ;
let date = new Date ( date_start );
let year = date . getFullYear ();
let m_start = 0 ;
let m_end = 3 ;
for ( i = 0 ; i <= 3 ; i ++ ) {
let start = new Date ( year , m_start , 1 );
let end = new Date ( year , m_end , 0 );
int_start = start . getFullYear () + " - " + ( " 0 " + ( start . getMonth () + 1 )) . slice ( - 2 ) + " - " + ( " 0 " + start . getDate ()) . slice ( - 2 );
int_end = end . getFullYear () + " - " + ( " 0 " + ( end . getMonth () + 1 )) . slice ( - 2 ) + " - " + ( " 0 " + end . getDate ()) . slice ( - 2 );
if ( date_start == int_start && date_end == int_end ) {
intervallo_corretto = 1 ;
}
m_start += 3 ;
m_end += 3 ;
}
2022-03-11 09:51:46 +01:00
m_start = 0 ;
m_end = 1 ;
for ( i = 0 ; i <= 11 ; i ++ ) {
let start = new Date ( year , m_start , 1 );
let end = new Date ( year , m_end , 0 );
int_start = start . getFullYear () + " - " + ( " 0 " + ( start . getMonth () + 1 )) . slice ( - 2 ) + " - " + ( " 0 " + start . getDate ()) . slice ( - 2 );
int_end = end . getFullYear () + " - " + ( " 0 " + ( end . getMonth () + 1 )) . slice ( - 2 ) + " - " + ( " 0 " + end . getDate ()) . slice ( - 2 );
if ( date_start == int_start && date_end == int_end ) {
intervallo_corretto = 1 ;
}
m_start += 1 ;
m_end += 1 ;
}
2022-03-02 16:38:58 +01:00
$ ( " #is_definitiva " ) . addClass ( " hidden " );
if ( intervallo_corretto ) {
$ ( " #period " ) . addClass ( " hidden " );
controllaStampa ( date_start , date_end );
} else {
$ ( " #period " ) . removeClass ( " hidden " );
input ( " definitiva " ) . disable ();
$ ( " #definitiva " ) . prop ( " checked " , false );
}
}
// Controllo se è già stata creata una stampa definitiva nel periodo selezionato
function controllaStampa ( date_start , date_end ) {
$ ( document ) . load ( globals . rootdir + " /ajax_complete.php?module=stampe_contabili&op=controlla_stampa&dir='. $dir .'&id_print='. $id_print .'&date_start= " + date_start + " &date_end= " + date_end , function ( response ) {
let stampa_definitiva = response ;
if ( stampa_definitiva == 0 ) {
$ ( " #is_definitiva " ) . addClass ( " hidden " );
input ( " definitiva " ) . enable ();
} else {
$ ( " #is_definitiva " ) . removeClass ( " hidden " );
input ( " definitiva " ) . disable ();
$ ( " #definitiva " ) . prop ( " checked " , false );
}
});
}
</ script > ' ;
}
2020-07-01 18:10:00 +02:00
echo '
< script >
2022-10-26 17:24:40 +02:00
$ ( document ) . ready ( init );
2020-10-13 17:50:37 +02:00
function avvia_stampa (){
2022-03-02 16:38:58 +01:00
if ( $ ( " #definitiva " ) . is ( " :checked " )) {
let date_start = $ ( " #date_start " ) . data ( " DateTimePicker " ) . date () . format ( " YYYY-MM-DD " );
let date_end = $ ( " #date_end " ) . data ( " DateTimePicker " ) . date () . format ( " YYYY-MM-DD " );
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " POST " ,
data : {
id_module : globals . id_module ,
op : " crea_definitiva " ,
date_start : date_start ,
date_end : date_end ,
id_print : '.$id_print.' ,
id_sezionale : $ ( " #id_sezionale " ) . val (),
dir : " '. $dir .' " ,
},
success : function ( result ) {
window . open ( " '. $link .'&dir='. $dir .'&id_sezionale= " + $ ( " #id_sezionale " ) . val () + " &date_start= " + $ ( " #date_start " ) . val () + " &date_end= " + $ ( " #date_end " ) . val () + " " );
$ ( " #modals > div " ) . modal ( " hide " );
}
});
} else {
window . open ( " '. $link .'&dir='. $dir .'¬definitiva=1&id_sezionale= " + $ ( " #id_sezionale " ) . val () + " &date_start= " + $ ( " #date_start " ) . val () + " &date_end= " + $ ( " #date_end " ) . val () + " " );
$ ( " #modals > div " ) . modal ( " hide " );
}
2020-10-13 17:50:37 +02:00
}
2020-07-01 18:10:00 +02:00
2022-03-02 16:38:58 +01:00
$ ( " #format " ) . change ( function () {
session_set ( " stampe_contabili,format " , $ ( this ) . val (), 0 , 0 );
});
2020-09-07 15:04:06 +02:00
2022-03-02 16:38:58 +01:00
$ ( " #orientation " ) . change ( function () {
session_set ( " stampe_contabili,orientation " , $ ( this ) . val (), 0 , 0 );
});
2022-10-26 17:24:40 +02:00
$ ( " #periodo " ) . change ( function () {
if ( $ ( this ) . val () == " manuale " ) {
input ( " date_start " ) . enable ();
input ( " date_end " ) . enable ();
} else {
$ ( " #date_start " ) . data ( " DateTimePicker " ) . date ( new Date ( input ( " periodo " ) . getData () . date_start ));
$ ( " #date_end " ) . data ( " DateTimePicker " ) . date ( new Date ( input ( " periodo " ) . getData () . date_end ));
input ( " date_start " ) . disable ();
input ( " date_end " ) . disable ();
2022-10-27 15:27:09 +02:00
} ' ;
if ( $nome_stampa != 'Liquidazione IVA' ) {
echo 'eseguiControlli();' ;
2022-10-26 17:24:40 +02:00
}
2022-10-27 15:27:09 +02:00
echo '
2022-10-26 17:24:40 +02:00
});
2020-07-01 18:10:00 +02:00
</ script > ' ;