2019-02-14 17:49:58 +01:00
< ? php
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 ;
}
2019-07-23 15:39:00 +02:00
// Informazioi utili
$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
2019-07-23 15:39:00 +02:00
// IVA predefinta
$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 '
2019-12-13 15:56:52 +01:00
2019-07-23 15:39:00 +02:00
< 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 .' " >
< input type = " hidden " name = " type " value = " '. $options['type'] .' " > ' ;
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 > ' ;
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 )) {
2019-07-23 15:39:00 +02:00
$segmento = $dbo -> fetchOne ( " SELECT * FROM zz_segments WHERE predefined_accredito='1' " );
$id_segment = $segmento [ 'id' ];
} else {
$id_segment = $_SESSION [ 'module_' . $final_module [ 'id' ]][ 'id_segment' ];
2019-02-14 17:49:58 +01:00
}
echo '
2019-07-23 15:39:00 +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 >
2019-12-13 15:56:52 +01:00
2019-07-23 15:39:00 +02:00
< div class = " col-md-12 " >
{[ " 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-02-14 12:23:50 +01:00
} elseif ( $options [ 'op' ] == 'add_ordine_cliente' ) {
$tipo_anagrafica = tr ( 'Fornitore' );
$ajax = 'fornitori' ;
echo '
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '. $tipo_anagrafica .' " , " name " : " idanagrafica " , " required " : 1 , " ajax-source " : " '. $ajax .' " , " icon-after " : " add|<'.Modules::get('Anagrafiche')['id'].'|tipoanagrafica='. $tipo_anagrafica .' " ]}
</ 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
}
// Conto, rivalsa INPS, ritenuta d'acconto e ritenuta contributi
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 )) {
$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 " >
{[ " 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).' " ]}
</ 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
2019-07-23 15:39:00 +02:00
echo '
< 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
2019-07-23 15:39:00 +02:00
foreach ( $righe as $i => $r ) {
// Descrizione
echo '
< tr >
< td >
2020-04-20 10:09:40 +02:00
< input type = " hidden " id = " prezzo_unitario_'. $i .' " name = " subtot['. $r['id'] .'] " value = " '. $r['prezzo_unitario'] .' " />
< input type = " hidden " id = " sconto_unitario_'. $i .' " name = " sconto['. $r['id'] .'] " value = " '. $r['sconto_unitario'] .' " />
< input type = " hidden " id = " iva_unitaria_'. $i .' " name = " iva['. $r['id'] .'] " value = " '. $r['iva_unitaria'] .' " />
< input type = " hidden " id = " qta_max_'. $i .' " value = " '.( $r['qta_rimanente'] ).' " /> ' ;
2019-07-23 15:39:00 +02:00
// Checkbox - da evadere?
echo '
< input type = " checkbox " checked = " checked " id = " checked_'. $i .' " name = " evadere['. $r['id'] .'] " value = " on " onclick = " ricalcola_subtotale_riga('. $i .'); " /> ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
$descrizione = ( $r -> isArticolo () ? $r -> articolo -> codice . ' - ' : '' ) . $r [ '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 " >
'.Translator::numberToLocale($r[' qta_rimanente ']).'
</ td > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Q.tà da evadere
echo '
< td >
{[ " type " : " number " , " name " : " qta_da_evadere['. $r['id'] .'] " , " id " : " qta_'. $i .' " , " required " : 1 , " value " : " '. $r['qta_rimanente'] .' " , " decimals " : " qta " , " min-value " : " 0 " , " extra " : " '.(( $r['is_descrizione'] ) ? 'readonly' : '').' onkeyup= \" ricalcola_subtotale_riga('. $i .'); \" " ]}
</ td > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
echo '
< td >
< big id = " subtotale_'. $i .' " > '.moneyFormat($r->totale).' </ big >< br />
2019-12-13 15:56:52 +01:00
2019-07-23 15:39:00 +02:00
< small style = " color:#777; " id = " subtotaledettagli_'. $i .' " > '.Translator::numberToLocale($r->totale_imponibile).' + '.Translator::numberToLocale($r->iva).' </ small >
</ 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
2019-07-23 15:39:00 +02:00
if ( ! empty ( $r [ 'abilita_serial' ])) {
$serials = $r -> 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 '
{[ " type " : " select " , " name " : " serial['. $r['id'] .'][] " , " id " : " serial_'. $i .' " , " multiple " : 1 , " values " : '.json_encode($list).' , " value " : " '.implode(',', $serials ).' " , " extra " : " data-maximum= \" '.intval( $r['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
2019-07-23 15:39:00 +02:00
if ( empty ( $r [ 'abilita_serial' ]) || empty ( $serials )) {
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 >
< td colspan = " '.(!empty( $options['serials'] ) ? 4 : 3).' " align = " right " class = " text-right " >
< 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 >