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-07-20 09:28:37 +02:00
$righe_totali = $documento -> getRighe ();
2021-07-07 07:57:10 +02:00
if ( $final_module [ 'name' ] == 'Interventi' ) {
2021-07-20 09:28:37 +02:00
$righe = $righe_totali -> where ( 'is_descrizione' , '=' , 0 )
-> where ( 'qta_rimanente' , '>' , 0 );
$righe_evase = $righe_totali -> where ( 'is_descrizione' , '=' , 0 )
-> where ( 'qta_rimanente' , '=' , 0 );
2021-07-07 07:57:10 +02:00
} elseif ( $final_module [ 'name' ] == 'Ordini fornitore' ) {
2021-07-20 09:28:37 +02:00
$righe = $righe_totali ;
$righe_evase = collect ();
2021-07-07 07:57:10 +02:00
} else {
2021-07-20 09:28:37 +02:00
$righe = $righe_totali -> where ( 'qta_rimanente' , '>' , 0 );
$righe_evase = $righe_totali -> where ( 'qta_rimanente' , '=' , 0 );
2021-05-14 16:16:09 +02:00
}
2021-07-20 09:28:37 +02:00
if ( $righe -> isEmpty ()) {
2019-07-23 15:39:00 +02:00
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
2021-09-17 12:18:21 +02:00
if ( ! empty ( $options [ 'reversed' ])) {
2021-09-16 11:57:07 +02:00
$idtipodocumento = $dbo -> selectOne ( 'co_tipidocumento' , [ 'id' ], [
'dir' => $dir ,
'descrizione' => 'Nota di credito' ,
])[ 'id' ];
2021-09-17 12:18:21 +02:00
} elseif ( in_array ( $original_module [ 'name' ], [ 'Ddt di vendita' , 'Ddt di acquisto' ])) {
2021-09-16 11:57:07 +02:00
$idtipodocumento = $dbo -> selectOne ( 'co_tipidocumento' , [ 'id' ], [
'dir' => $dir ,
2021-09-17 12:18:21 +02:00
'descrizione' => ( $dir == 'uscita' ? 'Fattura differita di acquisto' : 'Fattura differita di vendita' ),
2021-09-16 11:57:07 +02:00
])[ 'id' ];
2021-09-17 12:18:21 +02:00
} else {
2021-09-16 11:57:07 +02:00
$idtipodocumento = $dbo -> selectOne ( 'co_tipidocumento' , [ 'id' ], [
'predefined' => 1 ,
'dir' => $dir ,
])[ 'id' ];
}
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
2021-09-16 11:57:07 +02:00
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr('Tipo documento').' " , " name " : " idtipodocumento " , " required " : 1 , " values " : " query=SELECT id, CONCAT(codice_tipo_documento_fe, \ ' - \ ', descrizione) AS descrizione FROM co_tipidocumento WHERE enabled = 1 AND dir = '.prepare( $dir ).' ORDER BY codice_tipo_documento_fe " , " value " : " '. $idtipodocumento .' " ]}
</ div >
< div class = " col-md-4 " >
2021-09-16 12:45:12 +02:00
{[ " 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 .' " ]}
2020-09-09 11:44:14 +02:00
</ div >
2021-09-16 12:45:12 +02:00
2021-09-16 11:57:07 +02:00
< div class = " col-md-4 " >
2021-09-16 12:45:12 +02:00
{[ " type " : " select " , " label " : " '.tr('Ritenuta contributi').' " , " name " : " id_ritenuta_contributi " , " value " : " $id_ritenuta_contributi $ " , " values " : " query=SELECT * FROM co_ritenuta_contributi " ]}
2020-09-09 11:44:14 +02:00
</ 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_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
2021-07-15 10:58:36 +02:00
echo '
2019-07-23 15:39:00 +02:00
< div class = " row " > ' ;
2021-07-15 10:58:36 +02:00
// Rivalsa INPS
echo '
2019-07-23 15:39:00 +02:00
< 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 > ' ;
2021-07-07 15:00:59 +02:00
2021-07-15 10:58:36 +02:00
// Ritenuta d'acconto
echo '
2019-07-23 15:39:00 +02:00
< 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 > ' ;
2021-07-15 10:58:36 +02:00
// Calcola ritenuta d'acconto su
echo '
2019-07-23 15:39:00 +02:00
< 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
2021-07-15 10:58:36 +02: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-07-07 07:57:10 +02:00
if ( $final_module [ 'name' ] == 'Ordini fornitore' ) {
2021-06-11 17:11:34 +02:00
$qta_rimanente = $riga [ 'qta' ];
2021-07-07 07:57:10 +02:00
} else {
2021-06-11 17:11:34 +02:00
$qta_rimanente = $riga [ 'qta_rimanente' ];
}
2021-07-02 10:17:09 +02:00
$attr = 'checked="checked"' ;
2021-07-07 07:57:10 +02:00
if ( $original_module [ 'name' ] == 'Preventivi' ) {
if ( empty ( $riga [ 'confermato' ]) && $riga [ 'is_descrizione' ] == 0 ) {
2021-07-02 10:17:09 +02:00
$attr = '' ;
}
}
2021-07-07 07:57:10 +02:00
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-07-07 13:01:54 +02:00
< input type = " hidden " id = " max_qta_'. $i .' " value = " '.( $options['superamento_soglia_qta'] ? '' : $riga['qta_rimanente'] ).' " /> ' ;
2019-07-23 15:39:00 +02:00
// Checkbox - da evadere?
echo '
2021-07-02 10:17:09 +02:00
< input type = " checkbox " '.$attr.' 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-07-07 07:57:10 +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 > ' ;
2021-07-20 09:28:37 +02:00
// Elenco righe evase completametne
if ( ! $righe_evase -> isEmpty ()) {
echo '
< div class = " box box-info collapsable collapsed-box " >
< div class = " box-header with-border " >
2021-07-20 10:01:59 +02:00
< h3 class = " box-title " > '.tr(' Righe evase completamente ').' </ h3 >
2021-07-20 09:28:37 +02:00
< 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 >
< table class = " box-body table table-striped table-hover table-condensed " >
< thead >
< tr >
< th > '.tr(' Descrizione ').' </ th >
< th width = " 10% " class = " text-center " > '.tr(' Q . tà ').' </ th >
</ tr >
</ thead >
< tbody > ' ;
foreach ( $righe_evase as $riga ) {
echo '
< tr >
< td > '.$riga->descrizione.' </ td >
< td class = " text-center " > '.numberFormat($riga->qta, ' qta ').' '.$riga->um.' </ td >
</ tr > ' ;
}
echo '
</ tbody >
</ table >
</ div > ' ;
}
// Gestione articolo sottoscorta
2020-09-22 09:44:35 +02:00
echo '
2021-07-20 09:28:37 +02:00
< 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 >
< th class = " text-center " width = " 150 " > '.tr(' Scarto ').' </ th >
</ tr >
</ thead >
2020-09-22 09:44:35 +02:00
2021-07-20 09:28:37 +02:00
< tbody ></ tbody >
</ table >
</ div > ' ;
2020-09-22 09:44:35 +02:00
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
2021-07-20 09:28:37 +02:00
// Individuazione scorte
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 '
2021-07-20 09:28:37 +02:00
< script type = " text/javascript " >
var scorte = '.json_encode($scorte).' ;
var permetti_documento_vuoto = '.intval(!empty($options[' allow - empty '])).' ;
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
2021-07-20 09:28:37 +02:00
function controllaMagazzino () {
if ( ! abilita_scorte ) return ;
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
let righe = $ ( " #righe_documento_importato tr " );
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +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 " );
let id_articolo = riga . find ( " [id^=id_articolo_] " ) . text ();
2020-09-22 09:44:35 +02:00
2021-07-20 09:28:37 +02:00
if ( ! $ ( " #checked_ " + id ) . is ( " :checked " ) || ! id_articolo ) {
continue ;
}
let qta = parseFloat ( riga . find ( " input[id^=qta_] " ) . val ());
richieste [ id_articolo ] = richieste [ id_articolo ] ? richieste [ id_articolo ] + qta : qta ;
2019-02-14 17:49:58 +01:00
}
2021-07-20 09:28:37 +02:00
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 ]);
if (( qta_richiesta > qta_scorta ) && ( scorte [ id_articolo ][ " servizio " ] !== 1 )) {
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 >
< td class = " text-right " > ` + (qta_richiesta - qta_scorta).toLocale() + ` </ td >
</ tr > ` );
}
}
2020-09-22 09:44:35 +02:00
2021-07-20 09:28:37 +02:00
if ( body . html ()) {
sottoscorta . removeClass ( " hidden " );
} else {
sottoscorta . addClass ( " hidden " );
2019-02-14 17:49:58 +01:00
}
2020-09-22 09:44:35 +02:00
}
2021-07-20 09:28:37 +02:00
$ ( " input[name=righe] " ) . each ( function () {
ricalcolaTotaleRiga ( $ ( this ) . val ());
});
2020-09-22 09:44:35 +02:00
2021-07-20 09:28:37 +02:00
function ricalcolaTotaleRiga ( r ) {
let prezzo_unitario = $ ( " #prezzo_unitario_ " + r ) . val ();
let sconto = $ ( " #sconto_unitario_ " + r ) . val ();
2021-06-11 17:11:34 +02:00
2021-07-20 09:28:37 +02:00
let max_qta_input = $ ( " #max_qta_ " + r );
let qta_max = max_qta_input . val ();
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
prezzo_unitario = parseFloat ( prezzo_unitario );
sconto = parseFloat ( sconto );
qta_max = parseFloat ( qta_max );
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
let prezzo_scontato = prezzo_unitario - sconto ;
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
let qta = ( $ ( " #qta_ " + r ) . val ()) . toEnglish ();
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
// Se inserisco una quantità da evadere maggiore di quella rimanente, la imposto al massimo possibile
if ( qta > qta_max ) {
qta = qta_max ;
2020-09-22 09:44:35 +02:00
2021-07-20 09:28:37 +02:00
$ ( " #qta_ " + r ) . val ( qta );
}
2020-09-22 09:44:35 +02:00
2021-07-20 09:28:37 +02:00
// Se tolgo la spunta della casella dell\'evasione devo azzerare i conteggi
if ( isNaN ( qta ) || ! $ ( " #checked_ " + r ) . is ( " :checked " )) {
qta = 0 ;
}
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
let serial_select = $ ( " #serial_ " + r );
serial_select . selectClear ();
serial_select . select2 ( " destroy " );
serial_select . data ( " maximum " , qta );
start_superselect ();
2019-07-23 15:39:00 +02:00
2021-07-20 09:28:37 +02:00
let subtotale = ( prezzo_scontato * qta ) . toLocale ();
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
$ ( " #subtotale_ " + r ) . html ( subtotale + " " + globals . currency );
2019-02-14 17:49:58 +01:00
2021-04-21 14:53:53 +02:00
2021-07-20 09:28:37 +02:00
ricalcolaTotale ();
}
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
function ricalcolaTotale () {
let totale = 0.00 ;
let totale_qta = 0 ;
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
$ ( " input[id*=qta_] " ) . each ( function () {
let qta = ( $ ( this ) . val ()) . toEnglish ();
let r = $ ( this ) . attr ( " id " ) . replace ( " qta_ " , " " );
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
if ( ! $ ( " #checked_ " + r ) . is ( " :checked " ) || isNaN ( qta )) {
qta = 0 ;
}
2020-09-22 09:44:35 +02:00
2021-07-20 09:28:37 +02:00
let prezzo_unitario = $ ( " #prezzo_unitario_ " + r ) . val ();
let sconto = $ ( " #sconto_unitario_ " + r ) . val ();
2019-07-25 15:48:28 +02:00
2021-07-20 09:28:37 +02:00
prezzo_unitario = parseFloat ( prezzo_unitario );
sconto = parseFloat ( sconto );
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
let prezzo_scontato = prezzo_unitario - sconto ;
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
if ( prezzo_scontato ) {
totale += prezzo_scontato * qta ;
}
2019-02-14 17:49:58 +01:00
2021-07-20 09:28:37 +02:00
totale_qta += qta ;
});
2020-09-22 09:44:35 +02:00
2021-07-20 09:28:37 +02:00
$ ( " #totale " ) . html (( totale . toLocale ()) + " " + globals . currency );
2020-09-22 09:44:35 +02:00
2021-07-20 09:28:37 +02:00
if ( ! permetti_documento_vuoto ) {
if ( totale_qta > 0 ) {
$ ( " #submit_btn " ) . show ();
} else {
$ ( " #submit_btn " ) . hide ();
}
}
2020-09-22 09:44:35 +02:00
2021-07-20 09:28:37 +02:00
controllaMagazzino ();
}
2019-04-12 01:11:32 +02:00
2021-07-20 09:28:37 +02:00
ricalcolaTotale ();
2021-07-07 15:00:59 +02:00
$ ( document ) . ready ( function (){
2021-07-20 09:28:37 +02:00
if ( input ( " id_ritenuta_acconto " ) . get ()) {
2021-07-07 15:00:59 +02:00
$ ( " #calcolo_ritenuta_acconto " ) . prop ( " required " , true );
} else {
$ ( " #calcolo_ritenuta_acconto " ) . prop ( " required " , false );
input ( " calcolo_ritenuta_acconto " ) . set ( " " );
}
$ ( " #id_ritenuta_acconto " ) . on ( " change " , function (){
2021-07-20 09:28:37 +02:00
if ( input ( " id_ritenuta_acconto " ) . get ()) {
2021-07-07 15:00:59 +02:00
$ ( " #calcolo_ritenuta_acconto " ) . prop ( " required " , true );
} else {
$ ( " #calcolo_ritenuta_acconto " ) . prop ( " required " , false );
input ( " calcolo_ritenuta_acconto " ) . set ( " " );
}
});
});
2020-09-22 09:44:35 +02:00
</ script > ' ;