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
2024-03-22 15:52:24 +01:00
use Models\Module ;
2024-02-15 17:03:44 +01:00
use Modules\Contratti\Stato as StatoContratto ;
2024-03-22 15:52:24 +01:00
use Modules\DDT\Stato ;
2024-02-16 11:20:17 +01:00
use Modules\Fatture\Stato as StatoFattura ;
2024-03-28 16:55:49 +01:00
use Modules\Fatture\Tipo as Tipofattura ;
2024-03-01 11:32:13 +01:00
use Modules\Ordini\Stato as StatoOrdine ;
2024-02-13 15:50:26 +01:00
use Plugins\ListinoFornitori\DettaglioFornitore ;
2022-07-29 09:21:55 +02: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 ;
2024-03-28 16:38:03 +01:00
$original_module = Module :: find (( new Module ()) -> getByField ( 'name' , $documento -> module , Models\Locale :: getPredefined () -> id ));
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' ];
2024-03-28 16:38:03 +01:00
$final_module = Module :: find (( new Module ()) -> getByField ( 'name' , $name , Models\Locale :: getPredefined () -> id ));
2024-03-05 16:01:45 +01:00
$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
// 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 ();
2024-03-28 11:39:26 +01:00
2024-03-28 16:55:49 +01:00
$id_module_interventi = ( new Module ()) -> getByField ( 'name' , 'Interventi' , Models\Locale :: getPredefined () -> id );
$id_module_ordini_f = ( new Module ()) -> getByField ( 'name' , 'Ordini fornitore' , Models\Locale :: getPredefined () -> id );
2024-03-28 11:39:26 +01:00
if ( $final_module -> id == $id_module_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 );
2024-03-28 11:39:26 +01:00
} elseif ( $final_module -> id == $id_module_ordini_f ) {
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
2024-03-05 16:01:45 +01: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
2024-03-28 11:39:26 +01:00
$id_module_fatt_vendita = ( new Module ()) -> getByField ( 'name' , 'Fatture di vendita' , Models\Locale :: getPredefined () -> id );
$id_module_fatt_acquisto = ( new Module ()) -> getByField ( 'name' , 'Fatture di acquisto' , Models\Locale :: getPredefined () -> id );
$id_module_ddt_vendita = ( new Module ()) -> getByField ( 'name' , 'Ddt di vendita' , Models\Locale :: getPredefined () -> id );
$id_module_ddt_acquisto = ( new Module ()) -> getByField ( 'name' , 'Ddt di acquisto' , Models\Locale :: getPredefined () -> id );
if ( in_array ( $final_module -> id , [ $id_module_fatt_vendita , $id_module_fatt_acquisto ])) {
2024-03-27 16:59:46 +01:00
$stato_predefinito = ( new StatoFattura ()) -> getByField ( 'name' , 'Bozza' , Models\Locale :: getPredefined () -> id );
2024-03-28 16:55:49 +01:00
$fatt_differita_acquisto = ( new Tipofattura ()) -> getByField ( 'name' , 'Fattura differita di acquisto' , Models\Locale :: getPredefined () -> id );
$fatt_differita_vendita = ( new Tipofattura ()) -> getByField ( 'name' , 'Fattura differita di vendita' , Models\Locale :: getPredefined () -> id );
2021-02-18 18:48:44 +01:00
2021-09-17 12:18:21 +02:00
if ( ! empty ( $options [ 'reversed' ])) {
2024-03-22 15:52:24 +01:00
$idtipodocumento = database () -> fetchOne ( 'SELECT `co_tipidocumento`.`id` FROM `co_tipidocumento` LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento_lang`.`id_record` = `co_tipidocumento`.`id` AND `co_tipidocumento_lang`.`id_lang` = ' . prepare ( Models\Locale :: getDefault () -> id ) . ') WHERE `name` = "Nota di credito" AND `dir` = \'' . $dir . '\'' )[ 'id' ];
2024-03-28 11:39:26 +01:00
} elseif ( in_array ( $original_module -> id , [ $id_module_ddt_vendita , $id_module_ddt_acquisto ])) {
$idtipodocumento = database () -> fetchOne ( 'SELECT `co_tipidocumento`.`id` FROM `co_tipidocumento` LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento_lang`.`id_record` = `co_tipidocumento`.`id` AND `co_tipidocumento_lang`.`id_lang` = ' . prepare ( Models\Locale :: getDefault () -> id ) . ') WHERE `co_tipidocumento`.`id` = ' . ( $dir == 'uscita' ? $fatt_differita_acquisto : $fatt_differita_vendita ) . ' AND `dir` = \'' . $dir . '\'' )[ 'id' ];
2021-09-17 12:18:21 +02:00
} else {
2024-03-22 15:52:24 +01:00
$idtipodocumento = database () -> fetchOne ( 'SELECT `co_tipidocumento`.`id` FROM `co_tipidocumento` LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento_lang`.`id_record` = `co_tipidocumento`.`id` AND `co_tipidocumento_lang`.`id_lang` = ' . prepare ( Models\Locale :: getDefault () -> id ) . ') WHERE `dir` = \'' . $dir . '\' AND `predefined` = 1' )[ 'id' ];
2021-09-16 11:57:07 +02:00
}
2024-03-28 11:39:26 +01:00
$id_bozza = ( new StatoFattura ()) -> getByField ( 'name' , 'Bozza' , Models\Locale :: getPredefined () -> id );
$id_emessa = ( new StatoFattura ()) -> getByField ( 'name' , 'Emessa' , Models\Locale :: getPredefined () -> id );
2019-02-14 17:49:58 +01:00
echo '
2020-09-09 11:44:14 +02:00
< div class = " col-md-6 " >
2024-03-28 11:39:26 +01:00
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " id_stato " , " required " : 1 , " values " : " query=SELECT `co_statidocumento`.`id` as id, `co_statidocumento_lang`.`name` as descrizione FROM `co_statidocumento` LEFT JOIN `co_statidocumento_lang` ON (`co_statidocumento`.`id` = `co_statidocumento_lang`.`id_record` AND `co_statidocumento_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') WHERE `co_statidocumento`.`id` IN ('. $id_bozza .', '. $id_emessa .') " , " value " : " '. $stato_predefinito .' " ]}
2020-09-09 11:44:14 +02:00
</ div >
2019-12-13 15:56:52 +01:00
2022-11-28 09:27:25 +01:00
< div class = " col-md-6 " >
2024-03-22 15:52:24 +01:00
{[ " type " : " select " , " label " : " '.tr('Tipo documento').' " , " name " : " idtipodocumento " , " required " : 1 , " values " : " query=SELECT `co_tipidocumento`.`id`, CONCAT(`codice_tipo_documento_fe`, \ ' - \ ', `name`) AS descrizione FROM `co_tipidocumento` LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento`.`id` = `co_tipidocumento_lang`.`id_record` AND `co_tipidocumento_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') WHERE `enabled` = 1 AND `dir` = '.prepare( $dir ).' ORDER BY `codice_tipo_documento_fe` " , " value " : " '. $idtipodocumento .' " ]}
2021-09-16 11:57:07 +02:00
</ div >
2021-09-16 12:45:12 +02:00
2022-11-28 09:27:25 +01:00
< div class = " col-md-6 " >
2022-01-15 18:21:48 +01:00
{[ " type " : " select " , " label " : " '.tr('Ritenuta previdenziale').' " , " 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
2024-03-20 11:13:28 +01:00
elseif ( $final_module -> getTranslation ( 'name' ) == 'Interventi' ) {
2020-07-31 10:30:38 +02:00
echo '
< div class = " col-md-6 " >
2024-03-22 15:52:24 +01:00
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " id_stato_intervento " , " required " : 1 , " values " : " query=SELECT `in_statiintervento`.`id`, `in_statiintervento_lang`.`name` as `descrizione`, `colore` AS _bgcolor_ FROM `in_statiintervento` LEFT JOIN `in_statiintervento_lang` ON (`in_statiintervento`.`id` = `in_statiintervento_lang`.`id_record` AND `in_statiintervento_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') WHERE `deleted_at` IS NULL AND `is_completato` = 0 ORDER BY `name` " ]}
2020-07-31 10:30:38 +02:00
</ div >
< div class = " col-md-6 " >
2023-04-18 16:55:37 +02:00
{[ " type " : " select " , " label " : " '.tr('Tipo').' " , " name " : " id_tipo_intervento " , " required " : 1 , " ajax-source " : " tipiintervento " ]}
2020-07-31 10:30:38 +02:00
</ div > ' ;
2024-03-22 15:52:24 +01:00
}
2020-09-09 11:44:14 +02:00
// Opzioni aggiuntive per i Contratti
2024-03-20 11:13:28 +01:00
elseif ( $final_module -> getTranslation ( 'name' ) == 'Contratti' ) {
2024-03-27 16:59:46 +01:00
$stato_predefinito = ( new StatoContratto ()) -> getByField ( 'name' , 'Bozza' , Models\Locale :: getPredefined () -> id );
2020-09-09 11:44:14 +02:00
echo '
< div class = " col-md-6 " >
2024-03-22 15:52:24 +01:00
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " id_stato " , " required " : 1 , " values " : " query=SELECT `co_staticontratti`.`id`, `co_staticontratti_lang`.`name` AS descrizione FROM `co_staticontratti` LEFT JOIN `co_staticontratti_lang` ON (`co_staticontratti`.`id` = `co_staticontratti_lang`.`id_record` AND `co_staticontratti_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') " , " value " : " '. $stato_predefinito .' " ]}
2020-09-09 11:44:14 +02:00
</ div > ' ;
}
// Opzioni aggiuntive per i DDT
2024-03-20 11:13:28 +01:00
elseif ( in_array ( $final_module -> getTranslation ( 'name' ), [ 'Ddt di vendita' , 'Ddt di acquisto' ])) {
2024-03-27 16:59:46 +01:00
$stato_predefinito = ( new Stato ()) -> getByField ( 'name' , 'Bozza' , Models\Locale :: getPredefined () -> id );
2020-09-09 11:44:14 +02:00
echo '
< div class = " col-md-6 " >
2024-03-28 12:10:13 +01:00
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " id_stato " , " required " : 1 , " values " : " query=SELECT `dt_statiddt`.*, `dt_statiddt_lang`.`name` AS descrizione FROM `dt_statiddt` LEFT JOIN `dt_statiddt_lang` ON (`dt_statiddt`.`id` = `dt_statiddt_lang`.`id_record` AND `dt_statiddt_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') " , " value " : " '. $stato_predefinito .' " ]}
2020-09-09 11:44:14 +02:00
</ div >
< div class = " col-md-6 " >
2024-03-27 16:59:46 +01:00
{[ " type " : " select " , " label " : " '.tr('Causale trasporto').' " , " name " : " id_causale_trasporto " , " required " : 1 , " ajax-source " : " causali " , " icon-after " : " add|'.(new Module())->getByField('name', 'Causali', Models \ Locale::getPredefined()->id).' " , " help " : " '.tr('Definisce la causale del trasporto').' " ]}
2020-09-09 11:44:14 +02:00
</ div > ' ;
}
// Opzioni aggiuntive per gli Ordini
2024-03-20 11:13:28 +01:00
elseif ( in_array ( $final_module -> getTranslation ( 'name' ), [ 'Ordini cliente' , 'Ordini fornitore' ])) {
2024-03-27 16:59:46 +01:00
$stato_predefinito = ( new StatoOrdine ()) -> getByField ( 'name' , 'Bozza' , Models\Locale :: getPredefined () -> id );
2020-09-09 11:44:14 +02:00
echo '
< div class = " col-md-6 " >
2024-03-22 15:52:24 +01:00
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " id_stato " , " required " : 1 , " values " : " query=SELECT * ,`or_statiordine`.`id`, `or_statiordine_lang`.`name` AS descrizione FROM `or_statiordine` LEFT JOIN `or_statiordine_lang` ON (`or_statiordine`.`id` = `or_statiordine_lang`.`id_record` AND `or_statiordine_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') WHERE `name` IN( \ 'Bozza \ ', \ 'Accettato \ ', \ 'In attesa di conferma \ ', \ 'Annullato \ ') " , " value " : " '. $stato_predefinito .' " ]}
2020-09-09 11:44:14 +02:00
</ 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 " >
2024-03-27 16:59:46 +01:00
{[ " type " : " select " , " label " : " '. $tipo_anagrafica .' " , " name " : " idanagrafica " , " required " : 1 , " ajax-source " : " '. $ajax .' " , " icon-after " : " add|'.(new Module())->getByField('name', 'Anagrafiche', Models \ Locale::getPredefined()->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 '
2022-11-28 09:27:25 +01:00
< div class = " col-md-6 " >
2024-03-05 16:01:45 +01:00
{[ " type " : " select " , " label " : " '.tr('Sezionale').' " , " name " : " id_segment " , " required " : 1 , " ajax-source " : " segmenti " , " select-options " : '.json_encode([' id_module ' => $final_module->id, ' is_sezionale ' => 1]).' , " value " : " '. $database->selectOne ('co_tipidocumento', 'id_segment', ['id' => $idtipodocumento ])['id_segment'].' " ]}
2022-11-28 09:27:25 +01:00
</ div >
2019-07-23 15:39:00 +02:00
</ 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
}
2022-01-15 18:21:48 +01:00
// Conto, rivalsa INPS, ritenuta d'acconto e ritenuta previdenziale
2024-03-20 11:13:28 +01:00
if ( in_array ( $final_module -> getTranslation ( 'name' ), [ 'Fatture di vendita' , 'Fatture di acquisto' ]) && ! in_array ( $original_module -> getTranslation ( 'name' ), [ 'Fatture di vendita' , 'Fatture di acquisto' ])) {
2022-01-15 18:21:48 +01:00
$id_rivalsa_inps = setting ( 'Cassa previdenziale predefinita' );
2019-07-23 15:39:00 +02:00
if ( $dir == 'uscita' ) {
$id_ritenuta_acconto = $documento -> anagrafica -> id_ritenuta_acconto_acquisti ;
} else {
2022-01-15 18:21:48 +01:00
$id_ritenuta_acconto = $documento -> anagrafica -> id_ritenuta_acconto_vendite ? : setting ( " Ritenuta d'acconto predefinita " );
2019-07-23 15:39:00 +02:00
}
$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
2022-01-15 18:21:48 +01:00
// Ritenuta previdenziale
2019-07-23 15:39:00 +02:00
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 .' " >
2022-01-15 18:21:48 +01:00
{[ " type " : " checkbox " , " label " : " '.tr('Ritenuta previdenziale').' " , " name " : " ritenuta_contributi " , " value " : " 1 " ]}
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
// 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
2022-03-02 17:18:05 +01:00
$has_serial = 0 ;
if ( ! empty ( $options [ 'serials' ])) {
foreach ( $righe as $riga ) {
if ( ! empty ( $riga [ 'abilita_serial' ])) {
$serials = $riga -> serials ? : 0 ;
if ( ! empty ( $serials )) {
$has_serial = 1 ;
}
}
}
}
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 >
2022-03-31 16:25:27 +02:00
< th width = " 2% " >< input id = " import_all " type = " checkbox " checked /></ th >
2020-09-22 09:44:35 +02:00
< 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
2022-03-02 17:18:05 +01:00
if ( ! empty ( $has_serial )) {
2019-07-23 15:39:00 +02:00
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 ) {
2024-03-20 11:13:28 +01:00
if ( $final_module -> getTranslation ( '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"' ;
2024-03-20 11:13:28 +01:00
if ( $original_module -> getTranslation ( 'name' ) == 'Preventivi' ) {
2021-07-07 07:57:10 +02:00
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 .' " >
2022-03-31 16:25:27 +02:00
< td style = " vertical-align:middle " >
< input class = " check " type = " checkbox " '.$attr.' id = " checked_'. $i .' " name = " evadere['. $riga['id'] .'] " value = " on " onclick = " ricalcolaTotaleRiga('. $i .'); " />
</ td >
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
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
2023-08-04 14:54:28 +02:00
if ( $riga -> isArticolo ()) {
2022-07-29 09:21:55 +02:00
$dettaglio_fornitore = DettaglioFornitore :: where ( 'id_articolo' , $riga -> idarticolo )
-> where ( 'id_fornitore' , $documento -> idanagrafica )
-> first ();
2023-08-04 14:54:28 +02:00
if ( ! empty ( $dettaglio_fornitore -> codice_fornitore )) {
2022-07-29 09:21:55 +02:00
echo '
< br >< small class = " text-muted " > '.tr(' Codice fornitore ').' : '.$dettaglio_fornitore->codice_fornitore.' </ small > ' ;
}
}
2022-03-02 17:18:05 +01:00
if ( $riga -> isArticolo () && ! empty ( $riga -> abilita_serial )) {
$serials = $riga -> serials ;
$mancanti = abs ( $riga -> qta ) - count ( $serials );
if ( ! empty ( $mancanti )) {
echo '
< br >< b >< small class = " text-danger " > '.tr(' _NUM_ serial mancanti ' , [
2024-03-22 15:52:24 +01:00
'_NUM_' => $mancanti ,
]) . '</small></b>' ;
2022-03-02 17:18:05 +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
2022-03-02 17:18:05 +01:00
if ( ! empty ( $has_serial )) {
2019-07-23 15:39:00 +02:00
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 " >
2022-03-31 16:25:27 +02:00
< div class = " col-md-12 text-right " >
2019-02-14 17:49:58 +01:00
< 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
2024-03-19 18:18:11 +01:00
$descrizione_riga = $articolo -> codice . ' - ' . $articolo -> getTranslation ( 'name' );
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 () {
2022-03-01 12:51:48 +01:00
ricalcolaTotaleRiga ( $ ( this ) . val (), first = true );
2021-07-20 09:28:37 +02:00
});
2020-09-22 09:44:35 +02:00
2022-03-01 12:51:48 +01:00
function ricalcolaTotaleRiga ( r , first ) {
2021-07-20 09:28:37 +02:00
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
2022-03-01 12:51:48 +01:00
if ( ! first ) {
let serial_select = $ ( " #serial_ " + r );
serial_select . selectClear ();
serial_select . data ( " maximum " , qta );
initSelectInput ( " #serial_ " + r );
}
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 () {
2022-04-29 10:43:00 +02:00
let qta = $ ( this ) . val () . toEnglish ();
2021-07-20 09:28:37 +02:00
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-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 ( " " );
}
});
2022-04-29 10:43:00 +02:00
ricalcolaTotale ();
2021-07-07 15:00:59 +02:00
});
2022-02-22 18:17:35 +01:00
$ ( " #import_all " ) . click ( function (){
if ( $ ( this ) . is ( " :checked " ) ){
$ ( " .check " ) . each ( function (){
if ( ! $ ( this ) . is ( " :checked " ) ){
$ ( this ) . trigger ( " click " );
}
});
} else {
$ ( " .check " ) . each ( function (){
if ( $ ( this ) . is ( " :checked " ) ){
$ ( this ) . trigger ( " click " );
}
});
}
});
2020-09-22 09:44:35 +02:00
</ script > ' ;