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
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 />.
*/
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' ];
2021-01-25 12:37:53 +01:00
if ( empty ( $documento )) {
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
2021-05-14 16:16:09 +02:00
if ( $final_module [ 'name' ] == 'Interventi' ){
$righe = $documento -> getRighe () -> where ( 'qta_rimanente' , '>' , 0 ) -> where ( 'is_descrizione' , '=' , 0 );
2021-06-11 17:11:34 +02:00
} elseif ( $final_module [ 'name' ] == 'Ordini fornitore' ){
$righe = $documento -> getRighe ();
2021-05-14 16:16:09 +02:00
} else {
$righe = $documento -> getRighe () -> where ( 'qta_rimanente' , '>' , 0 );
}
2019-07-23 15:39:00 +02:00
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
2020-09-23 17:53:19 +02:00
$link = ! empty ( $documento_finale ) ? base_path () . '/editor.php?id_module=' . $final_module [ 'id' ] . '&id_record=' . $documento_finale -> id : base_path () . '/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' ])) {
2021-01-14 16:03:13 +01:00
$id_segment = $_SESSION [ 'module_' . $final_module [ 'id' ]][ 'id_segment' ];
2020-09-09 11:44:14 +02:00
2021-01-14 16:03:13 +01:00
$stato_predefinito = $database -> fetchOne ( " SELECT id FROM co_statidocumento WHERE descrizione = 'Bozza' " );
2021-02-18 18:48:44 +01:00
2019-02-14 17:49:58 +01:00
echo '
2021-01-14 16:03:13 +01:00
< input type = " hidden " name = " reversed " value = " '. $options['reversed'] .' " >
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
2021-05-11 11:50:44 +02:00
if ( $options [ 'op' ] == 'add_ordine_cliente' || $options [ 'op' ] == 'add_intervento' || $options [ 'op' ] == 'add_ordine_fornitore' ) {
$tipo_anagrafica = $options [ 'op' ] == 'add_intervento' ? tr ( 'Cliente' ) : tr ( 'Fornitore' );
$ajax = $options [ 'op' ] == 'add_intervento' ? 'clienti' : 'fornitori' ;
2020-02-14 12:23:50 +01:00
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 " >
2020-09-22 09:44:35 +02:00
< thead >
< tr >
< th > '.tr(' Descrizione ').' </ th >
2021-04-21 14:53:53 +02:00
< th width = " 10% " class = " text-center " > '.tr(' Q . tà ').' </ th >
2020-09-22 09:44:35 +02:00
< th width = " 15% " > '.tr(' Q . tà da evadere ').' </ th >
2021-04-21 14:53:53 +02:00
< th width = " 20% " class = " text-center " > '.tr(' Subtot . ').' </ th > ' ;
2019-07-23 15:39:00 +02:00
if ( ! empty ( $options [ 'serials' ])) {
echo '
2020-09-22 09:44:35 +02:00
< th width = " 20% " > '.tr(' Seriali ').' </ th > ' ;
2019-07-23 15:39:00 +02:00
}
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
echo '
2020-09-22 09:44:35 +02:00
</ tr >
</ thead >
< tbody id = " righe_documento_importato " > ' ;
2019-02-14 17:49:58 +01:00
2020-09-09 11:44:14 +02:00
foreach ( $righe as $i => $riga ) {
2021-06-11 17:11:34 +02:00
if ( $final_module [ 'name' ] == 'Ordini fornitore' ){
$qta_rimanente = $riga [ 'qta' ];
} else {
$qta_rimanente = $riga [ 'qta_rimanente' ];
}
2019-07-23 15:39:00 +02:00
// Descrizione
echo '
2020-09-22 09:44:35 +02:00
< tr data - local_id = " '. $i .' " >
2021-04-21 14:53:53 +02:00
< td style = " vertical-align:middle " >
2020-09-22 09:44:35 +02:00
< span class = " hidden " id = " id_articolo_'. $i .' " > '.$riga[' idarticolo '].' </ span >
2021-06-11 17:11:34 +02:00
< input type = " hidden " class = " righe " name = " righe " value = " '. $i .' " />
2020-09-22 09:44:35 +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'] .' " />
2021-06-11 17:11:34 +02:00
< input type = " hidden " id = " max_qta_'. $i .' " value = " '. $qta_rimanente .' " /> ' ;
2019-07-23 15:39:00 +02:00
// Checkbox - da evadere?
echo '
2020-09-22 09:44:35 +02:00
< input type = " checkbox " checked = " checked " id = " checked_'. $i .' " name = " evadere['. $riga['id'] .'] " value = " on " onclick = " ricalcolaTotaleRiga('. $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 '
2020-09-22 09:44:35 +02:00
</ td > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Q.tà rimanente
echo '
2021-04-21 14:53:53 +02:00
< td class = " text-center " style = " vertical-align:middle " >
2021-06-11 17:11:34 +02:00
'.numberFormat($qta_rimanente).'
2020-09-22 09:44:35 +02:00
</ td > ' ;
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Q.tà da evadere
echo '
2021-04-21 14:53:53 +02:00
< td style = " vertical-align:middle " >
2021-06-11 17:11:34 +02:00
{[ " type " : " number " , " name " : " qta_da_evadere['. $riga['id'] .'] " , " id " : " qta_'. $i .' " , " required " : 1 , " value " : " '. $qta_rimanente .' " , " decimals " : " qta " , " min-value " : " 0 " , " extra " : " '.(( $riga['is_descrizione'] ) ? 'readonly' : '').' onkeyup= \" ricalcolaTotaleRiga('. $i .'); \" " ]}
2020-09-22 09:44:35 +02:00
</ td > ' ;
2021-06-11 17:11:34 +02:00
2019-07-23 15:39:00 +02:00
echo '
2021-04-21 14:53:53 +02:00
< td style = " vertical-align:middle " class = " text-right " >
2021-06-11 17:11:34 +02:00
< span id = " subtotale_'. $i .' " ></ span >
2020-09-22 09:44:35 +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 '
2021-04-21 14:53:53 +02:00
< td style = " vertical-align:middle " > ' ;
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-22 09:44:35 +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
echo '
2020-09-22 09:44:35 +02:00
</ td > ' ;
2019-02-14 17:49:58 +01:00
}
echo '
2020-09-22 09:44:35 +02:00
</ tr > ' ;
2019-07-23 15:39:00 +02:00
}
2019-02-14 17:49:58 +01:00
2019-07-23 15:39:00 +02:00
// Totale
echo '
2020-09-22 09:44:35 +02:00
</ tbody >
2019-07-23 15:39:00 +02:00
< tr >
2021-06-11 17:11:34 +02:00
< td colspan = " 3 " class = " text-right " >
2019-07-23 15:39:00 +02:00
< b > '.tr(' Totale ').' :</ b >
</ td >
2021-04-21 14:53:53 +02:00
< td class = " text-right " >
< span id = " totale " ></ span >
2019-07-23 15:39:00 +02:00
</ td >
</ tr >
</ table >
</ div > ' ;
2020-09-22 09:44:35 +02:00
echo '
< div class = " alert alert-warning hidden " id = " articoli_sottoscorta " >
< table class = " table table-condensed " >
< thead >
< tr >
< th > '.tr(' Articolo ').' </ th >
< th class = " text-center tip " width = " 150 " title = " '.tr('Quantità richiesta').' " > '.tr(' Q . tà ').' </ th >
< th class = " text-center tip " width = " 150 " title = " '.tr('Quantità disponibile nel magazzino del gestionale').' " > '.tr(' Q . tà magazzino ').' </ th >
2020-09-24 10:47:21 +02:00
< th class = " text-center " width = " 150 " > '.tr(' Scarto ').' </ th >
2020-09-22 09:44:35 +02:00
</ tr >
</ thead >
< tbody ></ tbody >
</ table >
</ div > ' ;
2019-07-23 15:39:00 +02:00
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
2020-09-22 09:44:35 +02:00
echo '
2019-02-14 17:49:58 +01:00
< script type = " text/javascript " >
2020-09-22 09:44:35 +02:00
' ;
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
$articoli = $documento -> articoli -> groupBy ( 'idarticolo' );
$scorte = [];
foreach ( $articoli as $elenco ) {
$qta = $elenco -> sum ( 'qta' );
$articolo = $elenco -> first () -> articolo ;
2019-02-14 17:49:58 +01:00
2020-09-24 10:47:21 +02:00
$descrizione_riga = $articolo -> codice . ' - ' . $articolo -> descrizione ;
2020-09-22 09:44:35 +02:00
$text = $articolo ? Modules :: link ( 'Articoli' , $articolo -> id , $descrizione_riga ) : $descrizione_riga ;
$scorte [ $articolo -> id ] = [
'qta' => $articolo -> qta ,
'descrizione' => $text ,
2021-01-04 16:21:18 +01:00
'servizio' => $articolo -> servizio ,
2020-09-22 09:44:35 +02:00
];
}
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
echo '
var scorte = '.json_encode($scorte).' ;
2020-09-24 10:47:21 +02:00
var abilita_scorte = '.intval(!$documento::$movimenta_magazzino && !empty($options[' tipo_documento_finale ']) && $options[' tipo_documento_finale ']::$movimenta_magazzino).' ;
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
function controllaMagazzino () {
if ( ! abilita_scorte ) return ;
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
let righe = $ ( " #righe_documento_importato tr " );
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
// Lettura delle righe selezionate per l\'improtazione
let richieste = {};
for ( const r of righe ) {
let riga = $ ( r );
let id = $ ( riga ) . data ( " local_id " );
2020-09-24 11:36:47 +02:00
let id_articolo = riga . find ( " [id^=id_articolo_] " ) . text ();
2020-09-22 09:44:35 +02:00
2020-09-24 11:36:47 +02:00
if ( ! $ ( " #checked_ " + id ) . is ( " :checked " ) || ! id_articolo ) {
2020-09-22 09:44:35 +02:00
continue ;
2019-02-14 17:49:58 +01:00
}
2020-09-22 09:44:35 +02:00
let qta = parseFloat ( riga . find ( " input[id^=qta_] " ) . val ());
richieste [ id_articolo ] = richieste [ id_articolo ] ? richieste [ id_articolo ] + qta : qta ;
}
let sottoscorta = $ ( " #articoli_sottoscorta " );
let body = sottoscorta . find ( " tbody " );
body . html ( " " );
for ( const id_articolo in richieste ) {
let qta_scorta = parseFloat ( scorte [ id_articolo ][ " qta " ]);
let qta_richiesta = parseFloat ( richieste [ id_articolo ]);
2021-01-04 16:21:18 +01:00
if (( qta_richiesta > qta_scorta ) && ( scorte [ id_articolo ][ " servizio " ] !== 1 ) ) {
2020-09-22 09:44:35 +02:00
body . append ( ` < tr >
< td > ` + scorte[id_articolo]["descrizione"] + ` </ td >
< td class = " text-right " > ` + qta_richiesta.toLocale() + ` </ td >
< td class = " text-right " > ` + qta_scorta.toLocale() + ` </ td >
2020-09-24 10:47:21 +02:00
< td class = " text-right " > ` + (qta_richiesta - qta_scorta).toLocale() + ` </ td >
2020-09-22 09:44:35 +02:00
</ tr > ` );
2019-02-14 17:49:58 +01:00
}
2020-09-22 09:44:35 +02:00
}
if ( body . html ()) {
sottoscorta . removeClass ( " hidden " );
} else {
sottoscorta . addClass ( " hidden " );
}
}
2021-06-11 17:11:34 +02:00
$ ( " input[name=righe] " ) . each ( function () {
ricalcolaTotaleRiga ( $ ( this ) . val ());
});
2020-09-22 09:44:35 +02:00
function ricalcolaTotaleRiga ( r ) {
let prezzo_unitario = $ ( " #prezzo_unitario_ " + r ) . val ();
let sconto = $ ( " #sconto_unitario_ " + r ) . val ();
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
let max_qta_input = $ ( " #max_qta_ " + r );
let qta_max = max_qta_input . val () ? max_qta_input . val () : 0 ;
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
prezzo_unitario = parseFloat ( prezzo_unitario );
sconto = parseFloat ( sconto );
qta_max = parseFloat ( qta_max );
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
let prezzo_scontato = prezzo_unitario - sconto ;
2019-02-14 17:49:58 +01:00
2021-06-11 17:11:34 +02:00
let qta = ( $ ( " #qta_ " + r ) . val ()) . toEnglish ();
2020-09-22 09:44:35 +02:00
// Se inserisco una quantità da evadere maggiore di quella rimanente, la imposto al massimo possibile
if ( qta > qta_max ) {
qta = qta_max ;
$ ( " #qta_ " + r ) . val ( qta );
2019-02-14 17:49:58 +01:00
}
2020-09-22 09:44:35 +02:00
// Se tolgo la spunta della casella dell\'evasione devo azzerare i conteggi
if ( isNaN ( qta ) || ! $ ( " #checked_ " + r ) . is ( " :checked " )) {
qta = 0 ;
}
2019-07-23 15:39:00 +02:00
2020-09-22 09:44:35 +02:00
let serial_select = $ ( " #serial_ " + r );
serial_select . selectClear ();
serial_select . select2 ( " destroy " );
serial_select . data ( " maximum " , qta );
start_superselect ();
2019-02-14 17:49:58 +01:00
2021-04-21 14:53:53 +02:00
let subtotale = ( prezzo_scontato * qta ) . toLocale ();
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
$ ( " #subtotale_ " + r ) . html ( subtotale + " " + globals . currency );
2021-04-21 14:53:53 +02:00
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
ricalcolaTotale ();
}
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
function ricalcolaTotale () {
let totale = 0.00 ;
let totale_qta = 0 ;
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
$ ( " input[id*=qta_] " ) . each ( function () {
2021-06-11 17:11:34 +02:00
let qta = ( $ ( this ) . val ()) . toEnglish ();
2020-09-22 09:44:35 +02:00
let r = $ ( this ) . attr ( " id " ) . replace ( " qta_ " , " " );
if ( ! $ ( " #checked_ " + r ) . is ( " :checked " ) || isNaN ( qta )) {
qta = 0 ;
}
2019-07-25 15:48:28 +02:00
2020-09-22 09:44:35 +02:00
let prezzo_unitario = $ ( " #prezzo_unitario_ " + r ) . val ();
let sconto = $ ( " #sconto_unitario_ " + r ) . val ();
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
prezzo_unitario = parseFloat ( prezzo_unitario );
sconto = parseFloat ( sconto );
2021-04-21 14:53:53 +02:00
2020-09-22 09:44:35 +02:00
let prezzo_scontato = prezzo_unitario - sconto ;
2019-02-14 17:49:58 +01:00
2020-09-22 09:44:35 +02:00
if ( prezzo_scontato ) {
2021-04-21 14:53:53 +02:00
totale += prezzo_scontato * qta ;
2019-02-14 17:49:58 +01:00
}
2020-09-22 09:44:35 +02:00
totale_qta += qta ;
});
$ ( " #totale " ) . html (( totale . toLocale ()) + " " + globals . currency ); ' ;
if ( empty ( $options [ 'allow-empty' ])) {
echo '
if ( totale_qta > 0 ) {
$ ( " #submit_btn " ) . show ();
} else {
$ ( " #submit_btn " ) . hide ();
} ' ;
}
echo '
controllaMagazzino ();
}
2019-04-12 01:11:32 +02:00
2021-06-11 17:11:34 +02:00
ricalcolaTotale ();
2020-09-22 09:44:35 +02:00
</ script > ' ;