2020-02-17 18:43:49 +01:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-02-18 18:53:28 +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-02-17 18:43:49 +01:00
use Modules\Contratti\Contratto ;
include_once __DIR__ . '/../../core.php' ;
2021-02-18 09:57:35 +01:00
include_once __DIR__ . '/../modutil.php' ;
2020-02-17 18:43:49 +01:00
$contratto = Contratto :: find ( $id_record );
2021-02-18 09:57:35 +01:00
$giorni_fatturazione = [];
for ( $i = 1 ; $i <= 31 ; ++ $i ) {
$giorni_fatturazione [] = [
'id' => $i ,
'text' => $i ,
];
}
2020-02-17 18:43:49 +01:00
echo '
< form action = " " method = " post " >
< input type = " hidden " name = " op " value = " add " >
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " id_module " value = " '. $id_module .' " >
< input type = " hidden " name = " id_plugin " value = " '. $id_plugin .' " >
< input type = " hidden " name = " id_record " value = " '. $id_record .' " >
< div class = " nav-tabs-custom " >
< ul class = " nav nav-tabs nav-justified " >
2020-11-13 15:27:07 +01:00
< li class = " active " >< a href = " #periodi " data - tab = " periodi " onclick = " apriTab(this) " data - toggle = " tab " > '.tr(' Periodi ').' </ a ></ li >
2020-02-17 18:43:49 +01:00
2021-02-18 09:57:35 +01:00
< li >< a href = " #div_righe " data - tab = " righe " data - toggle = " tab " > '.tr(' Righe ').' </ a ></ li >
2020-02-17 18:43:49 +01:00
</ ul >
< div class = " tab-content " >
< div class = " tab-pane active " id = " periodi " >
2021-02-18 09:57:35 +01:00
< br >
< div class = " row " >
2020-02-17 18:43:49 +01:00
< div class = " col-md-3 " >
2021-02-18 09:57:35 +01:00
{[ " type " : " select " , " label " : " '.tr('Ricorrenza fatturazione').' " , " name " : " scadenza " , " values " : " list= \" \" : \" Seleziona un \ 'opzione \" , \" Mensile \" : \" Mensile \" , \" Bimestrale \" : \" Bimestrale \" , \" Trimestrale \" : \" Trimestrale \" , \" Quadrimestrale \" : \" Quadrimestrale \" , \" Semestrale \" : \" Semestrale \" , \" Annuale \" : \" Annuale \" " , " value " : " Mensile " , " help " : " '.tr('Specificare la cadenza con cui creare la pianificazione fatturazione').' " ]}
</ div >
< div class = " col-md-3 " >
2021-10-26 16:52:56 +02:00
{[ " type " : " select " , " label " : " '.tr('Giorno di fatturazione').' " , " name " : " cadenza_fatturazione " , " values " : " list= \" \" : \" Seleziona un \ 'opzione \" , \" Inizio \" : \" Inizio mese \" , \" Fine \" : \" Fine mese \" , \" Giorno \" : \" Giorno fisso \" " , " value " : " Inizio " , " help " : " '.tr('Specificare per la pianificazione fatturazione se si desidera creare le fatture ad inizio o alla fine del mese. Se non specificata alcuna opzione saranno create di default a fine mese.').' " ]}
2021-02-18 09:57:35 +01:00
</ div >
2021-10-26 16:52:56 +02:00
< div class = " col-md-3 " >
{[ " type " : " select " , " label " : " '.tr('Giorno fisso fatturazione').' " , " disabled " : 1 , " name " : " giorno_fisso " , " id " : " giorno_fisso " , " values " : '.json_encode($giorni_fatturazione).' , " value " : " " , " help " : " '.tr('Selezionare il giorno fisso di fatturazione.').' " ]}
2021-02-18 09:57:35 +01:00
</ div >
2021-04-02 09:58:11 +02:00
< input type = " hidden " name = " data_inizio " value = " '. $contratto->data_accettazione .' " >
2021-02-18 09:57:35 +01:00
</ div >
< div class = " row " >
< div class = " col-md-12 " >
< h4 id = " total_check " > Rate : 0 </ h4 >
</ div >
</ div >
< br >
< div id = " cadenza " >
2021-04-02 09:58:11 +02:00
< script > $ ( " #cadenza " ) . load (); </ script >
2020-02-17 18:43:49 +01:00
</ div >
2020-08-24 15:05:29 +02:00
< br >
< div class = " row " >
< div class = " col-md-12 " >
< div class = " btn-group " >
2020-11-06 19:24:11 +01:00
< button type = " button " class = " btn btn-sm btn-primary " onclick = " selezionaTutto() " >
'.tr(' Tutti ').'
2020-08-24 15:05:29 +02:00
</ button >
2020-11-06 19:24:11 +01:00
< button type = " button " class = " btn btn-sm btn-danger " onclick = " deselezionaTutto() " >
2020-11-13 15:27:07 +01:00
< i class = " fa fa-times " ></ i >
2020-08-24 15:05:29 +02:00
</ button >
</ div >
</ div >
</ div >
2020-02-17 18:43:49 +01:00
</ div >
2020-11-25 15:10:35 +01:00
< div class = " tab-pane " id = " div_righe " > ' ;
2020-02-17 18:43:49 +01:00
$iva_righe = $contratto -> getRighe () -> groupBy ( 'idiva' );
2021-02-18 09:57:35 +01:00
/*
2020-02-17 18:43:49 +01:00
foreach ( $iva_righe as $id_iva => $righe ) {
$iva = $righe -> first () -> aliquota ;
2021-02-18 09:57:35 +01:00
$descrizione = $righe -> first () -> descrizione ;
2020-02-17 18:43:49 +01:00
$righe = $righe -> toArray ();
2021-02-18 09:57:35 +01:00
*/
$righe = $contratto -> getRighe ();
echo '
< div class = " alert alert-info " >
2021-02-18 18:48:44 +01:00
< p > '.tr(' Puoi utilizzare le seguenti variabili nella descrizione delle righe ').' :</ p > '.variables()[' list '].'
2021-02-18 09:57:35 +01:00
</ div > ' ;
foreach ( $righe as $riga ) {
$id_iva = $riga -> id_iva ;
$descrizione = $riga -> descrizione . " \n { periodo} " ;
$options = [
'id' => $riga -> id ,
'totale_imponibile' => $riga -> totale_imponibile ,
'iva' => $riga -> iva ,
'totale' => $riga -> totale ,
'qta' => $riga -> qta ,
];
$options = json_encode ( $options );
2020-02-17 18:43:49 +01:00
echo '
2021-02-18 09:57:35 +01:00
<!-- h5 > '.tr(' Informazioni generali sulle righe con IVA : _IVA_ ' , [
'_IVA_' => $riga -> iva -> descrizione ,
]) . ' </ h5 -->
2020-02-17 18:43:49 +01:00
< div class = " row " >
< div class = " col-md-9 " >
2021-10-26 16:52:56 +02:00
{[ " type " : " textarea " , " label " : " '.tr('Descrizione').' " , " name " : " descrizione['. $riga->id .'] " , " value " : " '. $descrizione .' " , " extra " : " rows=6 " ]}
2020-02-17 18:43:49 +01:00
2021-10-26 16:52:56 +02:00
{[ " type " : " number " , " label " : " '.tr('Q.tà per fattura').' " , " class " : " qta_fattura " , " name " : " qta['. $riga->id .'] " , " required " : 1 , " value " : " 1 " , " decimals " : " qta " , " min-value " : " 1 " , " icon-after " : " '.tr('su _TOT_ totali', [
2021-02-18 18:48:44 +01:00
'_TOT_' => Translator :: numberToLocale (( $riga -> qta - $riga -> qta_evasa )),
]) . '", "options":"' . str_replace ( '"' , '\"' , $options ) . ' " ]}
2020-02-17 18:43:49 +01:00
</ div >
2021-02-18 09:57:35 +01:00
< div class = " col-md-3 " id = " totali_'. $riga->id .' " >
2020-02-17 18:43:49 +01:00
</ div >
2021-10-26 16:52:56 +02:00
</ div > ' ;
echo ' < div class = " label label-warning alert_rate hide " >
< i class = " fa fa-warning " ></ i > < span > '.tr(' Attenzione , sono previste _RATE_ rate su _TOT_ quantità totali ' , [
'_RATE_' => '<span class="num_rate"></span>' ,
'_TOT_' => '<span class="qta_disponibili">' . Translator :: numberToLocale (( $riga -> qta - $riga -> qta_evasa )) . '</span>' ,
]) . ' </ span >.
</ div >< hr > ' ;
2020-02-17 18:43:49 +01:00
}
2021-02-18 09:57:35 +01:00
echo '
< div class = " row " >
< div class = " col-md-offset-9 col-md-3 " id = " div_totale " >
</ div >
</ div > ' ;
2020-02-17 18:43:49 +01:00
echo '
2021-04-02 09:58:11 +02:00
< div class = " row " >
< div class = " col-md-12 text-right " >
2021-10-26 16:52:56 +02:00
< button type = " submit " class = " btn btn-primary " id = " btn_procedi " >< i class = " fa fa-chevron-right " ></ i > '.tr(' Procedi ').' </ button >
2021-04-02 09:58:11 +02:00
</ div >
</ div >
2020-02-17 18:43:49 +01:00
</ div >
</ div >
</ div >
2021-04-02 09:58:11 +02:00
2020-02-17 18:43:49 +01:00
</ form > ' ;
echo '
2020-08-24 15:05:29 +02:00
< script > $ ( document ) . ready ( init ) </ script >
< script >
2021-02-18 09:57:35 +01:00
$ ( document ) . ready ( function (){
caricaCadenza ();
get_prezzi ();
2021-02-18 18:53:28 +01:00
});
2021-02-18 09:57:35 +01:00
2021-10-26 16:52:56 +02:00
2021-02-18 09:57:35 +01:00
$ ( " #scadenza " ) . change ( function (){
caricaCadenza ();
2020-08-24 15:05:29 +02:00
});
2021-02-18 09:57:35 +01:00
function caricaCadenza () {
let container = $ ( " #cadenza " );
2021-02-18 18:53:28 +01:00
2021-02-18 09:57:35 +01:00
localLoading ( container , true );
2021-04-02 09:58:11 +02:00
return $ . get ( " '. $structure->fileurl ('ajax_cadenza.php').'?id_module='. $id_module .'&id_record='. $id_record .'&scadenza= " + $ ( " #scadenza " ) . val () + " &data_inizio= " + input ( " data_inizio " ) . get (), function ( data ) {
2021-02-18 09:57:35 +01:00
container . html ( data );
localLoading ( container , false );
});
}
2021-02-18 18:53:28 +01:00
2021-10-26 16:52:56 +02:00
function controlloProcedi (){
var len = 0 ;
$ ( this ) . change ( function () {
len = $ ( " input[type=checkbox]:checked.check_periodo " ) . length ;
if ( len > 0 ){
$ ( " #btn_procedi " ) . removeClass ( " disabled " );
} else {
$ ( " #btn_procedi " ) . addClass ( " disabled " );
}
});
}
2021-02-18 09:57:35 +01:00
function selezionaTutto (){
var check = 0 ;
$ ( " #periodi input " ) . each ( function (){
2021-04-02 09:58:11 +02:00
$ ( this ) . prop ( " checked " , true );
if ( $ ( this ) . is ( " :checked " ) ){
2021-02-18 09:57:35 +01:00
check = check + 1 ;
}
});
$ ( " #total_check " ) . html ( " Rate: " + check ) . trigger ( " change " );
2021-10-26 16:52:56 +02:00
$ ( " .num_rate " ) . html ( check ) . trigger ( " change " );
var qta_disponibili = 0 ;
$ ( " .alert_rate " ) . each ( function (){
qta_disponibili = parseFloat ( $ ( this ) . find ( " .qta_disponibili " ) . text ());
if ( check > qta_disponibili ){
$ ( this ) . removeClass ( " hide " );
} else {
$ ( this ) . addClass ( " hide " );
}
});
2021-02-18 09:57:35 +01:00
}
function deselezionaTutto (){
var check = 0 ;
$ ( " #periodi input " ) . each ( function (){
$ ( " input:checkbox " ) . prop ( " checked " , false );
if ( $ ( " input:checkbox " ) . is ( " :checked " ) ){
check = check + 1 ;
}
});
$ ( " #total_check " ) . html ( " Rate: " + check ) . trigger ( " change " );
2021-10-26 16:52:56 +02:00
$ ( " .num_rate " ) . html ( check ) . trigger ( " change " );
var qta_disponibili = 0 ;
$ ( " .alert_rate " ) . each ( function (){
qta_disponibili = parseFloat ( $ ( this ) . find ( " .qta_disponibili " ) . text ());
if ( check > qta_disponibili ){
$ ( this ) . removeClass ( " hide " );
} else {
$ ( this ) . addClass ( " hide " );
}
});
2021-02-18 09:57:35 +01:00
}
$ ( " .qta_fattura " ) . change ( function (){
get_prezzi ();
});
function get_prezzi (){
$ ( " .qta_fattura " ) . each ( function (){
var qta = parseFloat ( $ ( this ) . val () . replace ( " , " , " . " )) . toFixed ( 2 );
var riga = JSON . parse ( $ ( this ) . attr ( " options " ));
var imponibile_riga = ( riga . totale_imponibile / riga . qta ) * qta ;
2021-04-02 09:58:11 +02:00
imponibile_riga = imponibile_riga . toLocale () + " € " ;
2021-02-18 18:53:28 +01:00
2021-02-18 09:57:35 +01:00
var iva_riga = ( riga . iva / riga . qta ) * qta ;
2021-04-02 09:58:11 +02:00
iva_riga = iva_riga . toLocale () + " € " ;
2021-02-18 09:57:35 +01:00
var totale_riga = ( riga . totale / riga . qta ) * qta ;
2021-04-02 09:58:11 +02:00
totale_riga = totale_riga . toLocale () + " € " ;
2021-02-18 09:57:35 +01:00
$ ( " #totali_ " + riga . id ) . html ( " <p><b>Imponibile</b>: " + imponibile_riga + " </p> \
< p >< b > IVA </ b >: " +iva_riga+ " </ p > \
< p >< b > Totale </ b >: " +totale_riga+ " </ p > " );
});
}
2021-10-26 16:52:56 +02:00
$ ( " #cadenza_fatturazione " ) . change ( function ( event ){
event . preventDefault ();
2021-02-18 09:57:35 +01:00
if ( $ ( this ) . val () == " Giorno " ){
2021-10-26 16:52:56 +02:00
$ ( " #giorno_fisso " ) . prop ( " required " , true );
input ( " giorno_fisso " ) . enable ();
2021-02-18 09:57:35 +01:00
} else {
2021-10-26 16:52:56 +02:00
$ ( " #giorno_fisso " ) . prop ( " required " , false );
input ( " giorno_fisso " ) . disable ();
2021-02-18 09:57:35 +01:00
}
})
2021-02-18 18:53:28 +01:00
2020-08-24 15:05:29 +02:00
</ script > ' ;