2019-02-14 17:49:58 +01:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
* Copyright ( C ) DevCode s . n . c .
*
* 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 />.
*/
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Inizializzazione
$documento = $options [ 'documento' ];
$documento_finale = $options [ 'documento_finale' ];
if ( empty ( $documento ) || ( ! empty ( $documento_finale ) && $documento_finale -> direzione != $documento -> direzione )) {
2019-02-14 17:49:58 +01:00
return ;
}
2020-09-09 11:44:14 +02:00
// Informazioni utili
2019-07-23 15:39:00 +02:00
$dir = $documento -> direzione ;
$original_module = Modules :: get ( $documento -> module );
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
$name = ! empty ( $documento_finale ) ? $documento_finale -> module : $options [ 'module' ];
$final_module = Modules :: get ( $name );
2019-02-14 17:49:58 +01:00
2020-09-09 11:44:14 +02:00
// IVA predefinita
2019-07-23 15:39:00 +02:00
$id_iva = $id_iva ? : setting ( 'Iva predefinita' );
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
$righe = $documento -> getRighe () -> where ( 'qta_rimanente' , '>' , 0 );
if ( empty ( $righe )) {
echo '
< p > '.tr(' Non ci sono elementi da evadere ').' ...</ p > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
return ;
}
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
$link = ! empty ( $documento_finale ) ? ROOTDIR . '/editor.php?id_module=' . $final_module [ 'id' ] . '&id_record=' . $documento_finale -> id : ROOTDIR . '/controller.php?id_module=' . $final_module [ 'id' ];
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
echo '
< form action = " '. $link .' " method = " post " >
< input type = " hidden " name = " op " value = " '. $options['op'] .' " >
< input type = " hidden " name = " backto " value = " record-edit " >
2019-12-13 15:56:52 +01:00
2019-07-23 15:39:00 +02:00
< input type = " hidden " name = " id_documento " value = " '. $documento->id .' " >
2020-07-02 15:27:18 +02:00
< input type = " hidden " name = " type " value = " '. $options['type'] .' " >
2020-07-06 13:19:20 +02:00
< input type = " hidden " name = " class " value = " '.get_class( $documento ).' " >
< input type = " hidden " name = " is_evasione " value = " 1 " > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Creazione fattura dal documento
if ( ! empty ( $options [ 'create_document' ])) {
echo '
< div class = " box box-warning " >
< div class = " box-header with-border " >
< h3 class = " box-title " > '.tr(' Nuovo documento ').' </ h3 >
</ div >
< div class = " box-body " >
2019-12-13 15:56:52 +01:00
2019-07-23 15:39:00 +02:00
< div class = " row " >
< input type = " hidden " name = " create_document " value = " on " />
2019-12-13 15:56:52 +01:00
2019-07-23 15:39:00 +02:00
< div class = " col-md-6 " >
{[ " type " : " date " , " label " : " '.tr('Data del documento').' " , " name " : " data " , " required " : 1 , " value " : " -now- " ]}
</ div > ' ;
2020-09-09 11:44:14 +02:00
// Opzioni aggiuntive per le Fatture
2019-07-23 15:39:00 +02:00
if ( in_array ( $final_module [ 'name' ], [ 'Fatture di vendita' , 'Fatture di acquisto' ])) {
2020-02-14 12:23:50 +01:00
if ( $options [ 'op' ] == 'nota_accredito' && ! empty ( $segmenti )) {
2020-09-09 11:44:14 +02:00
$segmento = $database -> fetchOne ( " SELECT * FROM zz_segments WHERE predefined_accredito='1' " );
2019-07-23 15:39:00 +02:00
$id_segment = $segmento [ 'id' ];
} else {
$id_segment = $_SESSION [ 'module_' . $final_module [ 'id' ]][ 'id_segment' ];
2019-02-14 17:49:58 +01:00
}
2020-09-09 11:44:14 +02:00
$stato_predefinito = $database -> fetchOne ( " SELECT * FROM co_statidocumento WHERE descrizione = 'Bozza' " );
2019-02-14 17:49:58 +01:00
echo '
2020-09-09 11:44:14 +02:00
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " id_stato " , " required " : 1 , " values " : " query=SELECT * FROM co_statidocumento WHERE descrizione IN ( \ 'Emessa \ ', \ 'Bozza \ ') " , " value " : " '. $stato_predefinito['id'] .' " ]}
</ div >
2019-12-13 15:56:52 +01:00
2020-09-09 11:44:14 +02:00
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Ritenuta contributi').' " , " name " : " id_ritenuta_contributi " , " value " : " $id_ritenuta_contributi $ " , " values " : " query=SELECT * FROM co_ritenuta_contributi " ]}
</ div >
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Sezionale').' " , " name " : " id_segment " , " required " : 1 , " values " : " query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='.prepare( $final_module['id'] ).' ORDER BY name " , " value " : " '. $id_segment .' " ]}
</ div > ' ;
2020-07-31 10:30:38 +02:00
}
2020-09-09 11:44:14 +02:00
2020-07-31 10:30:38 +02:00
// Opzioni aggiuntive per gli Interventi
elseif ( $final_module [ 'name' ] == 'Interventi' ) {
echo '
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " id_stato_intervento " , " required " : 1 , " values " : " query=SELECT idstatointervento AS id, descrizione, colore AS _bgcolor_ FROM in_statiintervento WHERE deleted_at IS NULL " ]}
</ div >
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Tipo').' " , " name " : " id_tipo_intervento " , " required " : 1 , " values " : " query=SELECT idtipointervento AS id, descrizione FROM in_tipiintervento " ]}
</ div > ' ;
}
2020-09-09 11:44:14 +02:00
// Opzioni aggiuntive per i Contratti
elseif ( $final_module [ 'name' ] == 'Contratti' ) {
$stato_predefinito = $database -> fetchOne ( " SELECT * FROM co_staticontratti WHERE descrizione = 'Bozza' " );
echo '
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " id_stato " , " required " : 1 , " values " : " query=SELECT id, descrizione FROM co_staticontratti " , " value " : " '. $stato_predefinito['id'] .' " ]}
</ div > ' ;
}
// Opzioni aggiuntive per i DDT
elseif ( in_array ( $final_module [ 'name' ], [ 'Ddt di vendita' , 'Ddt di acquisto' ])) {
$stato_predefinito = $database -> fetchOne ( " SELECT * FROM dt_statiddt WHERE descrizione = 'Bozza' " );
echo '
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " id_stato " , " required " : 1 , " values " : " query=SELECT * FROM dt_statiddt " , " value " : " '. $stato_predefinito['id'] .' " ]}
</ div >
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Causale trasporto').' " , " name " : " id_causale_trasporto " , " required " : 1 , " ajax-source " : " causali " , " icon-after " : " add|'.Modules::get('Causali')['id'].' " , " help " : " '.tr('Definisce la causale del trasporto').' " ]}
</ div > ' ;
}
// Opzioni aggiuntive per gli Ordini
elseif ( in_array ( $final_module [ 'name' ], [ 'Ordini cliente' , 'Ordini fornitore' ])) {
$stato_predefinito = $database -> fetchOne ( " SELECT * FROM or_statiordine WHERE descrizione = 'Bozza' " );
echo '
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " id_stato " , " required " : 1 , " values " : " query=SELECT * FROM or_statiordine WHERE descrizione IN( \ 'Bozza \ ', \ 'Accettato \ ', \ 'In attesa di conferma \ ', \ 'Annullato \ ') " , " value " : " '. $stato_predefinito['id'] .' " ]}
</ div > ' ;
}
2020-07-31 10:30:38 +02:00
// Selezione fornitore per Ordine fornitore
2020-09-09 11:44:14 +02:00
if ( $options [ 'op' ] == 'add_ordine_cliente' ) {
2020-02-14 12:23:50 +01:00
$tipo_anagrafica = tr ( 'Fornitore' );
$ajax = 'fornitori' ;
echo '
< div class = " col-md-6 " >
2020-09-09 11:44:14 +02:00
{[ " type " : " select " , " label " : " '. $tipo_anagrafica .' " , " name " : " idanagrafica " , " required " : 1 , " ajax-source " : " '. $ajax .' " , " icon-after " : " add|'.Modules::get('Anagrafiche')['id'].'|tipoanagrafica='. $tipo_anagrafica .' " ]}
2020-02-14 12:23:50 +01:00
</ div > ' ;
2019-02-14 17:49:58 +01:00
}
2019-07-23 15:39:00 +02:00
echo '
</ div >
2019-02-26 21:20:05 +01:00
</ div >
2019-02-14 17:49:58 +01:00
</ div > ' ;
2019-07-23 15:39:00 +02:00
}
2020-07-31 10:30:38 +02:00
// Conto, rivalsa INPS, ritenuta d'acconto e ritenuta contributi
2019-07-23 15:39:00 +02:00
if ( in_array ( $final_module [ 'name' ], [ 'Fatture di vendita' , 'Fatture di acquisto' ]) && ! in_array ( $original_module [ 'name' ], [ 'Fatture di vendita' , 'Fatture di acquisto' ])) {
$id_rivalsa_inps = setting ( 'Percentuale rivalsa' );
if ( $dir == 'uscita' ) {
$id_ritenuta_acconto = $documento -> anagrafica -> id_ritenuta_acconto_acquisti ;
} else {
$id_ritenuta_acconto = $documento -> anagrafica -> id_ritenuta_acconto_vendite ? : setting ( " Percentuale ritenuta d'acconto " );
}
$calcolo_ritenuta_acconto = setting ( " Metodologia calcolo ritenuta d'acconto predefinito " );
$show_rivalsa = ! empty ( $id_rivalsa_inps );
$show_ritenuta_acconto = setting ( " Percentuale ritenuta d'acconto " ) != '' || ! empty ( $id_ritenuta_acconto );
$show_ritenuta_contributi = ! empty ( $documento_finale [ 'id_ritenuta_contributi' ]);
$id_conto = $documento_finale [ 'idconto' ];
if ( empty ( $id_conto )) {
2020-09-09 11:44:14 +02:00
$id_conto = $dir == 'entrata' ? setting ( 'Conto predefinito fatture di vendita' ) : setting ( 'Conto predefinito fatture di acquisto' );
2019-02-26 21:20:05 +01:00
}
2019-02-14 17:49:58 +01:00
echo '
2019-07-23 15:39:00 +02:00
< div class = " box box-info " >
< div class = " box-header with-border " >
< h3 class = " box-title " > '.tr(' Opzioni generali delle righe ').' </ h3 >
</ div >
< div class = " box-body " > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
if ( $show_rivalsa || $show_ritenuta_acconto ) {
echo '
< div class = " row " > ' ;
// Rivalsa INPS
if ( $show_rivalsa ) {
echo '
< div class = " col-md-4 " >
2020-09-09 11:44:14 +02:00
{[ " type " : " select " , " label " : " '.tr('Rivalsa').' " , " name " : " id_rivalsa_inps " , " value " : " '. $id_rivalsa_inps .' " , " values " : " query=SELECT * FROM co_rivalse " , " help " : " '.( $options['dir'] == 'entrata' ? setting('Tipo Cassa Previdenziale') : null).' " ]}
2019-07-23 15:39:00 +02:00
</ div > ' ;
}
// Ritenuta d'acconto
if ( $show_ritenuta_acconto ) {
echo '
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr( " Ritenuta d 'acconto").' " , " name " : " id_ritenuta_acconto " , " value " : " '.$id_ritenuta_acconto.' " , " values " : " query = SELECT * FROM co_ritenutaacconto " ]}
</ div > ' ;
// Calcola ritenuta d'acconto su
echo '
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr( " Calcola ritenuta d 'acconto su").' " , " name " : " calcolo_ritenuta_acconto " , " value " : " '.$calcolo_ritenuta_acconto.' " , " values " : " list = \ " IMP \" : \" Imponibile \" , \" IMP+RIV \" : \" Imponibile + rivalsa \" " , " required " : " 1 " ]}
</ div > ' ;
}
2019-02-14 17:49:58 +01:00
echo '
2019-07-23 15:39:00 +02:00
</ div > ' ;
2019-02-14 17:49:58 +01:00
}
2019-07-23 15:39:00 +02:00
$width = $show_ritenuta_contributi ? 6 : 12 ;
2019-02-14 17:49:58 +01:00
echo '
2019-07-23 15:39:00 +02:00
< div class = " row " > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Ritenuta contributi
if ( $show_ritenuta_contributi ) {
2019-02-14 17:49:58 +01:00
echo '
2019-07-23 15:39:00 +02:00
< div class = " col-md-'. $width .' " >
{[ " type " : " checkbox " , " label " : " '.tr('Ritenuta contributi').' " , " name " : " ritenuta_contributi " , " value " : " 1 " ]}
</ div > ' ;
}
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Conto
echo '
< div class = " col-md-'. $width .' " >
{[ " type " : " select " , " label " : " '.tr('Conto').' " , " name " : " id_conto " , " required " : 1 , " value " : " '. $id_conto .' " , " ajax-source " : " '.( $dir == 'entrata' ? 'conti-vendite' : 'conti-acquisti').' " ]}
</ div >
</ div >
</ div >
</ div > ' ;
}
2019-02-14 17:49:58 +01:00
2020-09-09 11:44:14 +02:00
// Righe del documento
echo '
2019-07-23 15:39:00 +02:00
< div class = " box box-success " >
< div class = " box-header with-border " >
< h3 class = " box-title " > '.tr(' Righe da importare ').' </ h3 >
</ div >
2019-12-13 15:56:52 +01:00
2019-07-23 15:39:00 +02:00
< table class = " box-body table table-striped table-hover table-condensed " >
< tr >
< th > '.tr(' Descrizione ').' </ th >
< th width = " 10% " > '.tr(' Q . tà ').' </ th >
< th width = " 15% " > '.tr(' Q . tà da evadere ').' </ th >
< th width = " 20% " > '.tr(' Subtot . ').' </ th > ' ;
if ( ! empty ( $options [ 'serials' ])) {
echo '
< th width = " 20% " > '.tr(' Seriali ').' </ th > ' ;
}
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
echo '
</ tr > ' ;
2019-02-14 17:49:58 +01:00
2020-09-09 11:44:14 +02:00
foreach ( $righe as $i => $riga ) {
2019-07-23 15:39:00 +02:00
// Descrizione
echo '
< tr >
< td >
2020-09-09 11:44:14 +02:00
< input type = " hidden " id = " prezzo_unitario_'. $i .' " name = " subtot['. $riga['id'] .'] " value = " '. $riga['prezzo_unitario'] .' " />
< input type = " hidden " id = " sconto_unitario_'. $i .' " name = " sconto['. $riga['id'] .'] " value = " '. $riga['sconto_unitario'] .' " />
< input type = " hidden " id = " iva_unitaria_'. $i .' " name = " iva['. $riga['id'] .'] " value = " '. $riga['iva_unitaria'] .' " />
< input type = " hidden " id = " qta_max_'. $i .' " value = " '.( $riga['qta_rimanente'] ).' " /> ' ;
2019-07-23 15:39:00 +02:00
// Checkbox - da evadere?
echo '
2020-09-09 11:44:14 +02:00
< input type = " checkbox " checked = " checked " id = " checked_'. $i .' " name = " evadere['. $riga['id'] .'] " value = " on " onclick = " ricalcola_subtotale_riga('. $i .'); " /> ' ;
2019-02-14 17:49:58 +01:00
2020-09-09 11:44:14 +02:00
$descrizione = ( $riga -> isArticolo () ? $riga -> articolo -> codice . ' - ' : '' ) . $riga [ 'descrizione' ];
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
echo ' ' . nl2br ( $descrizione );
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
echo '
</ td > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Q.tà rimanente
echo '
< td class = " text-center " >
2020-09-09 11:44:14 +02:00
'.numberFormat($riga[' qta_rimanente ']).'
2019-07-23 15:39:00 +02:00
</ td > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Q.tà da evadere
echo '
< td >
2020-09-09 11:44:14 +02:00
{[ " type " : " number " , " name " : " qta_da_evadere['. $riga['id'] .'] " , " id " : " qta_'. $i .' " , " required " : 1 , " value " : " '. $riga['qta_rimanente'] .' " , " decimals " : " qta " , " min-value " : " 0 " , " extra " : " '.(( $riga['is_descrizione'] ) ? 'readonly' : '').' onkeyup= \" ricalcola_subtotale_riga('. $i .'); \" " ]}
2019-07-23 15:39:00 +02:00
</ td > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
echo '
< td >
2020-09-09 11:44:14 +02:00
< big id = " subtotale_'. $i .' " > '.moneyFormat($riga->totale).' </ big >< br />
2019-12-13 15:56:52 +01:00
2020-09-09 11:44:14 +02:00
< small style = " color:#777; " id = " subtotaledettagli_'. $i .' " > '.numberFormat($riga->totale_imponibile).' + '.numberFormat($riga->iva).' </ small >
2019-07-23 15:39:00 +02:00
</ td > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Seriali
if ( ! empty ( $options [ 'serials' ])) {
echo '
< td > ' ;
2019-02-14 17:49:58 +01:00
2020-09-09 11:44:14 +02:00
if ( ! empty ( $riga [ 'abilita_serial' ])) {
$serials = $riga -> serials ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
$list = [];
foreach ( $serials as $serial ) {
$list [] = [
'id' => $serial ,
'text' => $serial ,
];
2019-02-14 17:49:58 +01:00
}
2019-07-23 15:39:00 +02:00
if ( ! empty ( $serials )) {
echo '
2020-09-09 11:44:14 +02:00
{[ " type " : " select " , " name " : " serial['. $riga['id'] .'][] " , " id " : " serial_'. $i .' " , " multiple " : 1 , " values " : '.json_encode($list).' , " value " : " '.implode(',', $serials ).' " , " extra " : " data-maximum= \" '.intval( $riga['qta_rimanente'] ).' \" " ]} ' ;
2019-02-14 17:49:58 +01:00
}
2019-07-23 15:39:00 +02:00
}
2019-02-14 17:49:58 +01:00
2020-09-09 11:44:14 +02:00
if ( empty ( $riga [ 'abilita_serial' ]) || empty ( $serials )) {
2019-07-23 15:39:00 +02:00
echo '-' ;
2019-02-14 17:49:58 +01:00
}
echo '
2019-07-23 15:39:00 +02:00
</ td > ' ;
2019-02-14 17:49:58 +01:00
}
echo '
2019-07-23 15:39:00 +02:00
</ tr > ' ;
}
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Totale
echo '
< tr >
2020-07-06 13:19:20 +02:00
< td colspan = " '.(!empty( $options['serials'] ) ? 4 : 3).' " class = " text-right " >
2019-07-23 15:39:00 +02:00
< b > '.tr(' Totale ').' :</ b >
</ td >
< td class = " text-right " colspan = " 2 " >
< big id = " totale " ></ big >
</ td >
</ tr >
</ table >
</ div > ' ;
echo '
2019-02-14 17:49:58 +01:00
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
< button type = " submit " id = " submit_btn " class = " btn btn-primary pull-right " >
< i class = " fa fa-plus " ></ i > '.$options[' button '].'
</ button >
</ div >
</ div >
</ form > ' ;
echo '
2019-07-26 17:40:52 +02:00
< script > $ ( document ) . ready ( init ) </ script > ' ;
2019-02-14 17:49:58 +01:00
?>
< script type = " text/javascript " >
function ricalcola_subtotale_riga ( r ) {
2020-04-20 10:09:40 +02:00
var prezzo_unitario = $ ( " #prezzo_unitario_ " + r ) . val ();
var sconto = $ ( " #sconto_unitario_ " + r ) . val ();
var iva = $ ( " #iva_unitaria_ " + r ) . val ();
2019-02-14 17:49:58 +01:00
2020-04-20 10:09:40 +02:00
var qta_max_input = $ ( " #qta_max_ " + r );
var qta_max = qta_max_input . val () ? qta_max_input . val () : 0 ;
2019-02-14 17:49:58 +01:00
2020-04-20 10:09:40 +02:00
prezzo_unitario = parseFloat ( prezzo_unitario );
2019-02-14 17:49:58 +01:00
sconto = parseFloat ( sconto );
iva = parseFloat ( iva );
2020-04-20 10:09:40 +02:00
qta_max = parseFloat ( qta_max );
2019-02-14 17:49:58 +01:00
2020-04-20 10:09:40 +02:00
var prezzo_scontato = prezzo_unitario - sconto ;
2019-02-14 17:49:58 +01:00
2020-04-20 10:09:40 +02:00
var qta = $ ( " #qta_ " + r ) . val () . toEnglish ();
2019-02-14 17:49:58 +01:00
// Se inserisco una quantità da evadere maggiore di quella rimanente, la imposto al massimo possibile
2020-04-20 10:09:40 +02:00
if ( qta > qta_max ) {
qta = qta_max ;
2019-02-14 17:49:58 +01:00
$ ( '#qta_' + r ) . val ( qta );
}
// Se tolgo la spunta della casella dell'evasione devo azzerare i conteggi
if ( isNaN ( qta ) || ! $ ( '#checked_' + r ) . is ( ':checked' )) {
qta = 0 ;
}
2020-04-20 10:09:40 +02:00
var serial_select = $ ( " #serial_ " + r );
serial_select . selectClear ();
serial_select . select2 ( " destroy " );
serial_select . data ( 'maximum' , qta );
2019-02-14 17:49:58 +01:00
start_superselect ();
2020-04-20 10:09:40 +02:00
var subtotale = ( prezzo_scontato * qta + iva * qta ) . toLocale ();
2019-02-14 17:49:58 +01:00
2019-04-13 00:09:48 +02:00
$ ( " #subtotale_ " + r ) . html ( subtotale + " " + globals . currency );
2020-04-20 10:09:40 +02:00
$ ( " #subtotaledettagli_ " + r ) . html (( prezzo_scontato * qta ) . toLocale () + " + " + ( iva * qta ) . toLocale ());
2019-02-14 17:49:58 +01:00
ricalcola_totale ();
}
function ricalcola_totale () {
2020-04-20 10:09:40 +02:00
var totale = 0.00 ;
var totale_qta = 0 ;
2019-07-23 15:39:00 +02:00
2019-02-14 17:49:58 +01:00
$ ( 'input[id*=qta_]' ) . each ( function () {
2020-04-20 10:09:40 +02:00
var qta = $ ( this ) . val () . toEnglish ();
var r = $ ( this ) . attr ( " id " ) . replace ( " qta_ " , " " );
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
if ( ! $ ( " #checked_ " + r ) . is ( " :checked " ) || isNaN ( qta )) {
2019-02-14 17:49:58 +01:00
qta = 0 ;
}
2020-04-20 10:09:40 +02:00
var prezzo_unitario = $ ( " #prezzo_unitario_ " + r ) . val ();
var sconto = $ ( " #sconto_unitario_ " + r ) . val ();
var iva = $ ( " #iva_unitaria_ " + r ) . val ();
2019-02-14 17:49:58 +01:00
2020-04-20 10:09:40 +02:00
prezzo_unitario = parseFloat ( prezzo_unitario );
2019-02-14 17:49:58 +01:00
sconto = parseFloat ( sconto );
iva = parseFloat ( iva );
2020-04-20 10:09:40 +02:00
var prezzo_scontato = prezzo_unitario - sconto ;
2019-02-14 17:49:58 +01:00
2020-04-20 10:09:40 +02:00
if ( prezzo_scontato ) {
totale += prezzo_scontato * qta + iva * qta ;
2019-04-12 01:11:32 +02:00
}
2019-07-25 15:48:28 +02:00
totale_qta += qta ;
2019-02-14 17:49:58 +01:00
});
2019-04-13 00:09:48 +02:00
$ ( '#totale' ) . html (( totale . toLocale ()) + " " + globals . currency );
2019-02-14 17:49:58 +01:00
< ? php
2019-07-23 15:39:00 +02:00
if ( empty ( $options [ 'allow-empty' ])) {
2019-02-14 17:49:58 +01:00
echo '
2019-07-25 15:48:28 +02:00
if ( totale_qta > 0 )
2019-02-14 17:49:58 +01:00
$ ( " #submit_btn " ) . show ();
else
$ ( " #submit_btn " ) . hide (); ' ;
}
?>
}
2019-04-12 01:11:32 +02:00
ricalcola_totale ();
2019-02-14 17:49:58 +01:00
</ script >