2019-03-29 12:46:17 +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-03-29 12:46:17 +01:00
// Descrizione
echo App :: internalLoad ( 'descrizione.php' , $result , $options );
// Conti, rivalsa INPS e ritenuta d'acconto
echo App :: internalLoad ( 'conti.php' , $result , $options );
2020-09-29 15:27:00 +02:00
$incorpora_iva = $options [ 'dir' ] == 'entrata' && setting ( 'Utilizza prezzi di vendita comprensivi di IVA' );
2019-03-29 12:46:17 +01:00
// Sconto percentuale
echo '
2020-09-29 15:27:00 +02:00
< div class = " row " > ' ;
2019-07-11 17:28:53 +02:00
if ( $options [ 'action' ] == 'add' ) {
echo '
2020-09-29 15:27:00 +02:00
< div class = " col-md-4 " >
{[ " type " : " number " , " label " : " '.tr('Sconto/maggiorazione percentuale').' " , " name " : " sconto_percentuale " , " icon-after " : " % " , " help " : " '.tr('Il valore positivo indica uno sconto: per applicare una maggiorazione inserire un valore negativo').' " ]}
</ div > ' ;
2019-07-11 17:28:53 +02:00
}
2019-03-29 12:46:17 +01:00
// Sconto unitario
echo '
2020-09-29 15:27:00 +02:00
< div class = " col-md-'.( $options['action'] == 'add' ? 4 : 6).' " >
{[ " type " : " number " , " label " : " '.tr('Sconto/maggiorazione unitario').' " , " name " : " sconto_unitario " , " value " : " '. $result['sconto_unitario_corrente'] .' " , " icon-after " : " '.currency().' " , " help " : " '.tr('Il valore positivo indica uno sconto: per applicare una maggiorazione inserire un valore negativo').' " ]}
</ div > ' ;
2019-03-29 12:46:17 +01:00
// Iva
echo '
2020-09-29 15:27:00 +02:00
< div class = " col-md-'.( $options['action'] == 'add' ? 4 : 6).' " >
{[ " type " : " select " , " label " : " '.tr('Iva').' " , " name " : " idiva " , " required " : 1 , " value " : " '. $result['idiva'] .' " , " ajax-source " : " iva " ]}
</ div >
</ div > ' ;
2019-03-29 12:46:17 +01:00
2020-09-29 15:27:00 +02:00
// Funzione per l'aggiornamento in tempo reale dello sconto
$totale_documento = $incorpora_iva ? $options [ 'totale_documento' ] : $options [ 'totale_imponibile_documento' ];
2019-03-29 12:46:17 +01:00
echo '
2020-09-29 15:27:00 +02:00
< script >
var descrizione = $ ( " #descrizione_riga " );
2020-07-02 10:11:33 +02:00
2020-09-29 15:27:00 +02:00
var form = descrizione . closest ( " form " );
var sconto_percentuale = form . find ( " #sconto_percentuale " );
var sconto_unitario = form . find ( " #sconto_unitario " );
2019-03-29 12:46:17 +01:00
2020-09-29 15:27:00 +02:00
var totale = '.($totale_documento ?: 0).' ;
2020-07-02 10:11:33 +02:00
2020-09-29 15:27:00 +02:00
function aggiorna_sconto_percentuale () {
var sconto = sconto_percentuale . val () . toEnglish ();
var unitario = sconto / 100 * totale ;
var msg = sconto >= 0 ? " '.tr('Sconto percentuale').' " : " '.tr('Maggiorazione percentuale').' " ;
2022-04-08 16:54:31 +02:00
var div = sconto_percentuale . closest ( " div " ) . next ( " div[id*=errors] " );
2020-07-02 10:11:33 +02:00
2020-09-29 15:27:00 +02:00
sconto_unitario . val ( unitario . toLocale ());
2020-07-02 10:11:33 +02:00
2021-01-12 15:40:49 +01:00
if ( sconto !== 0 ) {
2020-09-29 15:27:00 +02:00
descrizione . val ( msg + " " + Math . abs ( sconto ) . toLocale () + " % " );
2019-03-29 12:46:17 +01:00
}
2022-04-08 16:54:31 +02:00
if ( sconto > 0 ) {
div . html ( `<small class="label label-default" >'.tr('Sconto').'</small>` );
} else if ( sconto < 0 ) {
div . html ( `<small class="label label-default" >'.tr('Maggiorazione').'</small>` );
} else {
div . html ( " " );
}
2020-09-29 15:27:00 +02:00
}
2020-07-02 10:11:33 +02:00
2020-09-29 15:27:00 +02:00
function aggiorna_sconto_unitario (){
var sconto = sconto_unitario . val () . toEnglish ();
var msg = sconto >= 0 ? " '.tr('Sconto unitario').' " : " '.tr('Maggiorazione unitaria').' " ;
2022-04-08 16:54:31 +02:00
var div = sconto_unitario . closest ( " div " ) . next ( " div[id*=errors] " );
2019-03-29 12:46:17 +01:00
2020-09-29 15:27:00 +02:00
sconto_percentuale . val ( 0 );
2020-07-02 10:11:33 +02:00
2021-01-12 15:40:49 +01:00
if ( sconto !== 0 ) {
2020-09-29 15:27:00 +02:00
descrizione . val ( msg );
2019-03-29 12:46:17 +01:00
}
2022-04-08 16:54:31 +02:00
if ( sconto > 0 ) {
div . html ( `<small class="label label-default" >'.tr('Sconto').'</small>` );
} else if ( sconto < 0 ) {
div . html ( `<small class="label label-default" >'.tr('Maggiorazione').'</small>` );
} else {
div . html ( " " );
}
2020-09-29 15:27:00 +02:00
}
2019-03-29 12:46:17 +01:00
2020-09-29 15:27:00 +02:00
sconto_percentuale . keyup ( aggiorna_sconto_percentuale );
sconto_unitario . keyup ( aggiorna_sconto_unitario );
</ script > ' ;