2018-02-19 10:52:42 +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 />.
*/
2018-02-19 10:52:42 +01:00
2024-03-05 16:01:45 +01:00
use Models\Module ;
2024-03-22 15:52:24 +01:00
use Modules\Articoli\Articolo ;
2024-02-29 15:10:55 +01:00
$articolo = Articolo :: find ( $result [ 'idarticolo' ]);
$width = $options [ 'dir' ] == 'uscita' && $articolo -> fattore_um_secondaria ? 3 : 4 ;
2023-05-02 14:55:21 +02:00
2018-02-19 10:52:42 +01:00
// Descrizione
echo App :: internalLoad ( 'descrizione.php' , $result , $options );
2018-09-03 16:31:15 +02:00
// Conti, rivalsa INPS e ritenuta d'acconto
echo App :: internalLoad ( 'conti.php' , $result , $options );
2018-02-19 10:52:42 +01:00
// Iva
echo '
< div class = " row " >
2023-05-02 14:55:21 +02:00
< div class = " col-md-'. $width .' '.(!empty( $options['nascondi_prezzi'] ) ? 'hidden' : '').' " >
2020-08-17 16:25:01 +02:00
{[ " type " : " select " , " label " : " '.tr('Iva').' " , " name " : " idiva " , " required " : 1 , " value " : " '. $result['idiva'] .' " , " ajax-source " : " iva " , " select-options " : '.json_encode($options[' select - options '][' iva ']).' ]}
2018-02-19 10:52:42 +01:00
</ div > ' ;
// Quantità
echo '
2023-05-02 14:55:21 +02:00
< div class = " col-md-'. $width .' " >
2023-08-04 14:54:28 +02:00
{[ " type " : " number " , " label " : " '.tr('Q.tà').' " , " name " : " qta " , " required " : 1 , " value " : " '.abs((float) $result['qta'] ).' " , " decimals " : " qta " '.(isset($result[' max_qta ']) ? ' , " icon-after " : " <span class= \" tip \" title= \" '.tr( " L 'elemento è collegato a un documento: la quantità massima ammessa è relativa allo stato di evasione dell' elemento nel documento di origine ( quantità dell 'elemento / quantità massima ammessa)").' \ " >/ '.numberFormat(abs((float) $result['max_qta'] ), 'qta').' <i class= \" fa fa-question-circle-o \" ></i></span> " ' : ' ').' , " min-value " : " '.abs((float) $result['qta_evasa'] ).' " ]}
2018-02-19 10:52:42 +01:00
</ div > ' ;
// Unità di misura
echo '
2023-05-02 14:55:21 +02:00
< div class = " col-md-'. $width .' " >
2024-04-18 17:44:05 +02:00
{[ " type " : " select " , " label " : " '.tr('Unità di misura').' " , " icon-after " : " add|'.(new Module())->getByField('title', 'Unità di misura', Models \ Locale::getPredefined()->id).' " , " name " : " um " , " value " : " '. $result['um'] .' " , " ajax-source " : " misure " ]}
2023-05-02 14:55:21 +02:00
</ div > ' ;
// Unità di misura
2024-02-29 15:10:55 +01:00
if ( $options [ 'dir' ] == 'uscita' && $articolo -> fattore_um_secondaria ) {
2023-08-04 14:54:28 +02:00
echo '
2023-05-02 14:55:21 +02:00
< div class = " col-md-3 " >
2024-03-22 15:52:24 +01:00
{[ " type " : " number " , " label " : " '.tr('Q.tà secondaria').' " , " name " : " fattore_um_secondaria " , " value " : " '.abs((float) $articolo->fattore_um_secondaria * $result['qta'] ).' " , " icon-after " : " '. $articolo->um_secondaria .' " ]}
2018-02-19 11:25:56 +01:00
</ div >
2023-05-02 14:55:21 +02:00
< script >
input ( " fattore_um_secondaria " ) . on ( " change " , function () {
let articolo = input ( " idarticolo " ) . getData ();
let qta = input ( this ) . get () / articolo . fattore_um_secondaria ;
if ( input ( " qta " ) . get () != qta ) {
input ( " qta " ) . set ( qta );
}
});
input ( " qta " ) . on ( " change " , function () {
let articolo = input ( " idarticolo " ) . getData ();
let fattore_um_secondaria = input ( this ) . get () * articolo . fattore_um_secondaria ;
if ( input ( " fattore_um_secondaria " ) . get () != fattore_um_secondaria ) {
input ( " fattore_um_secondaria " ) . set ( fattore_um_secondaria );
}
});
</ script > ' ;
}
echo '
2018-02-19 11:25:56 +01:00
</ div > ' ;
2018-02-19 10:52:42 +01:00
2022-04-08 16:54:31 +02:00
$is_nota = $options [ 'is_nota' ] ? : 0 ;
2018-02-19 10:52:42 +01:00
echo '
2022-03-22 17:21:39 +01:00
< div class = " row '.(!empty( $options['nascondi_prezzi'] ) ? 'hidden' : '').' " >
2022-04-08 16:54:31 +02:00
< input type = " hidden " name = " prezzi_ivati " value = " '.setting('Utilizza prezzi di vendita comprensivi di IVA').' " >
< input type = " hidden " name = " is_nota " value = " '. $is_nota .' " >
< input type = " hidden " name = " dir " value = " '. $options['dir'] .' " > ' ;
2019-04-19 18:32:29 +02:00
2018-12-24 10:46:59 +01:00
$width = $options [ 'dir' ] == 'entrata' ? 4 : 6 ;
$label = $options [ 'dir' ] == 'entrata' ? tr ( 'Prezzo unitario di vendita' ) : tr ( 'Prezzo unitario' );
2019-04-19 18:32:29 +02:00
2018-12-23 16:16:59 +01:00
if ( $options [ 'dir' ] == 'entrata' ) {
// Prezzo di acquisto unitario
echo '
< div class = " col-md-'. $width .' " >
2020-02-14 18:31:07 +01:00
{[ " type " : " number " , " label " : " '.tr('Prezzo unitario di acquisto').' " , " name " : " costo_unitario " , " value " : " '. $result['costo_unitario'] .' " , " icon-after " : " '.currency().' " ]}
2018-12-23 14:25:20 +01:00
</ div > ' ;
2018-12-23 16:16:59 +01:00
// Funzione per l'aggiornamento in tempo reale del guadagno
echo '
< script >
function aggiorna_guadagno () {
2022-03-22 17:21:39 +01:00
var prezzi_ivati = input ( " prezzi_ivati " ) . get ();
2020-02-14 18:31:07 +01:00
var costo_unitario = $ ( " #costo_unitario " ) . val () . toEnglish ();
2022-03-22 17:21:39 +01:00
var prezzo = 0 ;
2018-12-23 16:16:59 +01:00
var sconto = $ ( " #sconto " ) . val () . toEnglish ();
2022-12-16 15:53:01 +01:00
2021-11-08 12:10:48 +01:00
if ( $ ( " #modals select[id^= \ 'tipo_sconto \ '] " ) . val () === " PRC " ) {
2023-02-07 16:17:15 +01:00
sconto = sconto / 100 * $ ( " #prezzo_unitario " ) . val () . toEnglish ();
2018-12-23 16:16:59 +01:00
}
2022-12-16 15:53:01 +01:00
if ( prezzi_ivati != 0 ) {
percentuale_iva = input ( " idiva " ) . getElement () . selectData () . percentuale ;
prezzo = ( $ ( " #prezzo_unitario " ) . val () . toEnglish () / ( 1 + percentuale_iva / 100 )) - ( sconto / ( 1 + percentuale_iva / 100 ));
} else {
prezzo = $ ( " #prezzo_unitario " ) . val () . toEnglish () - sconto ;
}
2022-05-19 17:42:41 +02:00
var provvigione = $ ( " #provvigione " ) . val () . toEnglish ();
if ( $ ( " #modals select[id^= \ 'tipo_provvigione \ '] " ) . val () === " PRC " ) {
2022-12-16 15:53:01 +01:00
provvigione = provvigione / 100 * prezzo ;
2022-05-19 17:42:41 +02:00
}
2018-12-23 16:16:59 +01:00
2022-12-16 15:53:01 +01:00
var guadagno = prezzo - provvigione - costo_unitario ;
var ricarico = (( prezzo / costo_unitario ) - 1 ) * 100 ;
2023-02-07 16:17:15 +01:00
var margine = ( 1 - ( costo_unitario / prezzo )) * 100 ;
var parent = $ ( " #costo_unitario " ) . closest ( " div " ) . parent ();
2022-05-19 17:42:41 +02:00
var div = $ ( " .margine " );
2021-10-26 10:29:10 +02:00
var mediaponderata = 0 ;
2018-12-23 16:16:59 +01:00
2020-07-06 13:57:45 +02:00
margine = isNaN ( margine ) || ! isFinite ( margine ) ? 0 : margine ; // Fix per magine NaN
2022-07-28 15:22:08 +02:00
ricarico = isNaN ( ricarico ) || ! isFinite ( ricarico ) ? 0 : ricarico ; // Fix per ricarico NaN
2020-07-06 13:57:45 +02:00
2021-10-26 10:29:10 +02:00
if ( $ ( " #idarticolo " ) . val ()) {
mediaponderata = parseFloat ( $ ( " #idarticolo " ) . selectData () . media_ponderata );
}
2021-10-25 14:26:35 +02:00
2022-05-19 17:42:41 +02:00
div . html ( " <table class= \" table table-extra-condensed table-margine \" style= \" margin-top:-13px; \" > \
2021-10-25 14:26:35 +02:00
< tr > \
< td > \
< small >& nbsp ; '.tr(' Guadagno ').' :</ small > \
</ td > \
< td align = \ " right \" > \
< small > " + guadagno.toLocale() + " </ small > \
</ td > \
2021-10-26 10:18:32 +02:00
< td align = \ " center \" > \
2021-10-25 14:26:35 +02:00
< small > " + globals.currency + " </ small > \
</ td > \
</ tr > \
< tr > \
< td > \
< small >& nbsp ; '.tr(' Margine ').' :</ small > \
</ td > \
< td align = \ " right \" > \
< small > " + margine.toLocale() + " < small > \
</ td > \
2021-10-26 10:18:32 +02:00
< td align = \ " center \" > \
2021-10-25 14:26:35 +02:00
< small >& nbsp ; %< small > \
</ td > \
</ tr > \
2022-07-28 15:22:08 +02:00
< tr > \
< td > \
< small >& nbsp ; '.tr(' Ricarico ').' :</ small > \
</ td > \
< td align = \ " right \" > \
< small > " + ricarico.toLocale() + " < small > \
</ td > \
< td align = \ " center \" > \
< small >& nbsp ; %< small > \
</ td > \
</ tr > \
2021-10-25 14:26:35 +02:00
< tr > \
< td > \
< small >& nbsp ; '.tr(' Costo medio ').' :</ small > \
</ td > \
< td align = \ " right \" > \
2021-10-26 11:10:28 +02:00
< small > " + (mediaponderata!=0 ? mediaponderata.toLocale() : " - " ) + " </ small > \
2021-10-25 14:26:35 +02:00
</ td > \
2021-10-26 10:18:32 +02:00
< td align = \ " center \" > \
2021-10-25 14:26:35 +02:00
< small > " + globals.currency + " </ small > \
</ td > \
</ tr > \
</ table > " );
2018-12-23 16:16:59 +01:00
if ( guadagno < 0 ) {
parent . addClass ( " has-error " );
2022-05-19 17:42:41 +02:00
$ ( " .table-margine " ) . addClass ( " label-danger " ) . removeClass ( " label-success " );
2018-12-23 16:16:59 +01:00
} else {
parent . removeClass ( " has-error " );
2022-05-19 17:42:41 +02:00
$ ( " .table-margine " ) . removeClass ( " label-danger " ) . addClass ( " label-success " );
2018-12-23 16:16:59 +01:00
}
}
2020-11-10 17:36:34 +01:00
$ ( " #modals > div " ) . on ( " shown.bs.modal " , function () {
aggiorna_guadagno ();
});
2018-12-24 10:46:59 +01:00
2020-02-14 18:31:07 +01:00
$ ( " #prezzo_unitario " ) . keyup ( aggiorna_guadagno );
$ ( " #costo_unitario " ) . keyup ( aggiorna_guadagno );
2018-12-25 11:32:19 +01:00
$ ( " #sconto " ) . keyup ( aggiorna_guadagno );
2021-11-08 12:10:48 +01:00
$ ( " #modals select[id^= \ 'tipo_sconto \ '] " ) . change ( aggiorna_guadagno );
2022-05-19 17:42:41 +02:00
$ ( " #provvigione " ) . keyup ( aggiorna_guadagno );
$ ( " #modals select[id^= \ 'tipo_provvigione \ '] " ) . change ( aggiorna_guadagno );
2018-12-23 16:16:59 +01:00
</ script > ' ;
}
2018-12-23 14:25:20 +01:00
// Prezzo di vendita unitario
echo '
2018-12-23 16:16:59 +01:00
< div class = " col-md-'. $width .' " >
2020-02-28 00:22:12 +01:00
{[ " type " : " number " , " label " : " '. $label .' " , " name " : " prezzo_unitario " , " value " : " '. $result['prezzo_unitario_corrente'] .' " , " required " : 1 , " icon-after " : " '.currency().' " , " help " : " '.( $options['dir'] == 'entrata' && setting('Utilizza prezzi di vendita comprensivi di IVA') ? tr('Importo IVA inclusa') : '').' " ]}
2018-02-19 10:52:42 +01:00
</ div > ' ;
// Sconto unitario
echo '
2018-12-23 16:16:59 +01:00
< div class = " col-md-'. $width .' " >
2020-02-15 14:11:44 +01:00
{[ " type " : " number " , " label " : " '.tr('Sconto unitario').' " , " name " : " sconto " , " value " : " '.( $result['sconto_percentuale'] ?: $result['sconto_unitario_corrente'] ).' " , " icon-after " : " choice|untprc|'. $result['tipo_sconto'] .' " , " help " : " '.tr('Il valore positivo indica uno sconto. Per applicare una maggiorazione inserire un valore negativo.').' " ]}
2018-02-19 10:52:42 +01:00
</ div >
</ div > ' ;
2020-08-06 11:36:43 +02:00
2022-05-19 17:42:41 +02:00
if ( $options [ 'dir' ] == 'entrata' ) {
echo '
< div class = " row " >
2022-11-15 17:38:42 +01:00
< div class = " col-md-4 margine " ></ div >
< div class = " col-md-4 prezzi " ></ div > ' ;
2023-08-04 14:54:28 +02:00
// Provvigione
echo '
2022-11-15 17:38:42 +01:00
< div class = " col-md-4 " >
< div class = " sconto " ></ div >
2022-05-19 17:42:41 +02:00
{[ " type " : " number " , " label " : " '.tr('Provvigione unitaria').' " , " name " : " provvigione " , " value " : " '.( $result['provvigione_percentuale'] ?: ( $result['provvigione_unitaria'] ?: $result['provvigione_default'] )).' " , " icon-after " : " choice|untprc|'.( $result['tipo_provvigione'] ?: $result['tipo_provvigione_default'] ).' " , " help " : " '.tr('Provvigione destinata all \ 'agente.').' " , " min-value " : " 0 " ]}
</ div >
2022-11-15 17:38:42 +01:00
</ div >
< div class = " row " >
< div class = " col-md-offset-4 col-md-4 minimo_vendita text-center " ></ div >
2022-05-19 17:42:41 +02:00
</ div > ' ;
2022-11-15 17:38:42 +01:00
} else {
echo '
< div class = " row " >
< div class = " col-md-6 prezzi " ></ div >
< div class = " col-md-6 sconto " ></ div >
</ div >
< br > ' ;
2022-05-19 17:42:41 +02:00
}
2020-08-06 11:36:43 +02:00
// Data prevista evasione (per ordini)
2024-04-18 17:44:05 +02:00
if ( in_array ( $module -> getTranslation ( 'title' ), [ 'Ordini cliente' , 'Ordini fornitore' , 'Preventivi' ])) {
2020-10-16 08:31:10 +02:00
if ( $options [ 'action' ] == 'add' ) {
2024-04-18 17:44:05 +02:00
if ( $module -> getTranslation ( 'title' ) == 'Ordini cliente' ) {
2020-10-16 08:31:10 +02:00
$confermato = setting ( 'Conferma automaticamente le quantità negli ordini cliente' );
2024-04-18 17:44:05 +02:00
} elseif ( $module -> getTranslation ( 'title' ) == 'Ordini fornitore' ) {
2020-10-16 08:31:10 +02:00
$confermato = setting ( 'Conferma automaticamente le quantità negli ordini fornitore' );
2021-07-02 10:17:09 +02:00
} else {
$confermato = setting ( 'Conferma automaticamente le quantità nei preventivi' );
2020-10-07 14:54:18 +02:00
}
2020-10-16 08:31:10 +02:00
} else {
2020-10-07 14:54:18 +02:00
$confermato = $result [ 'confermato' ];
}
2020-08-06 11:36:43 +02:00
echo '
2021-10-26 10:18:32 +02:00
< div class = " box box-info collapsable collapsed-box " >
2021-04-08 12:18:38 +02:00
< div class = " box-header with-border " >
< h3 class = " box-title " > '.tr(' Informazioni aggiuntive ').' </ h3 >
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >< i class = " fa fa-plus " ></ i ></ button >
2020-10-14 15:40:47 +02:00
</ div >
</ div >
2021-04-08 12:18:38 +02:00
< div class = " box-body " >
< div class = " row " >
< div class = " col-md-4 " >
{[ " type " : " date " , " label " : " '.tr('Data prevista evasione').' " , " name " : " data_evasione " , " value " : " '. $result['data_evasione'] .' " ]}
</ div >
< div class = " col-md-4 " >
{[ " type " : " time " , " label " : " '.tr('Ora prevista evasione').' " , " name " : " ora_evasione " , " value " : " '. $result['ora_evasione'] .' " , " disabled " : 1 ]}
</ div >
< div class = " col-md-4 " >
{[ " type " : " checkbox " , " label " : " '.tr('Cambia data a tutte le righe').' " , " name " : " data_evasione_all " , " value " : " " ]}
</ div >
2020-10-06 12:25:22 +02:00
</ div >
2021-04-08 12:18:38 +02:00
< div class = " row " >
< div class = " col-md-4 " >
</ div >
< div class = " col-md-4 " >
2024-04-18 17:44:05 +02:00
{[ " type " : " checkbox " , " label " : " '.tr('Articolo confermato').' " , " name " : " confermato " , " value " : " '. $confermato .' " , " help " : " '.tr('Articolo confermato dal _ANA_ e che è possibile evadere', ['_ANA_' => $module->getTranslation ('title') == 'Ordini fornitore' ? tr('fornitore') : tr('cliente')]).' " ]}
2021-04-08 12:18:38 +02:00
</ div >
< div class = " col-md-4 " >
{[ " type " : " checkbox " , " label " : " '.tr('Cambia stato a tutte le righe').' " , " name " : " confermato_all " , " value " : " " ]}
</ div >
2020-10-14 15:40:47 +02:00
</ div >
2020-08-06 11:44:41 +02:00
</ div >
</ div >
2021-04-08 12:18:38 +02:00
< script >
$ ( document ) . ready ( function () {
if ( input ( " data_evasione " ) . get ()){
input ( " ora_evasione " ) . enable ();
}
});
2021-05-18 11:18:06 +02:00
$ ( " #data_evasione " ) . blur ( function () {
2021-04-08 12:18:38 +02:00
if ( input ( " data_evasione " ) . get ()){
input ( " ora_evasione " ) . enable ();
} else {
input ( " ora_evasione " ) . disable ();
input ( " ora_evasione " ) . set ();
}
});
2022-04-08 16:54:31 +02:00
</ script > ' ;
2021-04-12 15:51:27 +02:00
}
2022-04-08 16:54:31 +02:00
2024-04-18 17:44:05 +02:00
if ( in_array ( $module -> getTranslation ( 'title' ), [ 'Fatture di vendita' , 'Fatture di acquisto' ])) {
2022-04-08 16:54:31 +02:00
echo '
< script >
$ ( document ) . ready ( function () {
if ( input ( " data_evasione " ) . get ()){
input ( " ora_evasione " ) . enable ();
}
controlla_prezzo ();
controlla_sconto ();
});
$ ( " #data_evasione " ) . blur ( function () {
if ( input ( " data_evasione " ) . get ()){
input ( " ora_evasione " ) . enable ();
} else {
input ( " ora_evasione " ) . disable ();
input ( " ora_evasione " ) . set ();
}
});
$ ( " #prezzo_unitario " ) . on ( " keyup " , function () {
controlla_prezzo ();
});
$ ( " #sconto " ) . on ( " keyup " , function () {
controlla_sconto ();
});
function controlla_prezzo () {
let prezzo_unitario = $ ( " #prezzo_unitario " ) . val () . toEnglish ();
let div = $ ( " #prezzo_unitario " ) . closest ( " div " ) . next ( " div[id*=errors] " );
if ( prezzo_unitario < 0 ) {
if ( input ( " is_nota " ) . get () == true ) {
if ( input ( " dir " ) . get () == " entrata " ) {
div . html ( `<small class="label label-warning"><i class="fa fa-exclamation-triangle"></i> '.tr('Importo a credito').'</small>` );
} else {
div . html ( `<small class="label label-warning"><i class="fa fa-exclamation-triangle"></i> '.tr('Importo a debito').'</small>` );
}
} else {
if ( input ( " dir " ) . get () == " entrata " ) {
div . html ( `<small class="label label-warning"><i class="fa fa-exclamation-triangle"></i> '.tr('Importo a debito').'</small>` );
} else {
div . html ( `<small class="label label-warning"><i class="fa fa-exclamation-triangle"></i> '.tr('Importo a credito').'</small>` );
}
}
} else {
div . html ( " " );
}
}
function controlla_sconto () {
let sconto = $ ( " #sconto " ) . val () . toEnglish ();
let div = $ ( " #sconto " ) . closest ( " div " ) . next ( " div[id*=errors] " );
2022-11-15 17:38:42 +01:00
let div_margine = $ ( " .margine " );
let div_prezzi = $ ( " .prezzi " );
div . css ( " margin-top " , " -13px " );
2022-04-08 16:54:31 +02:00
if ( sconto > 0 ) {
2022-11-15 17:38:42 +01:00
div_margine . css ( " margin-top " , " -20px " );
div_prezzi . css ( " margin-top " , " -20px " );
2023-02-17 17:03:22 +01:00
div_prezzi . css ( " margin-bottom " , " 20px " );
2022-04-08 16:54:31 +02:00
div . html ( `<small class="label label-default" >'.tr('Sconto').'</small>` );
} else if ( sconto < 0 ) {
2022-11-15 17:38:42 +01:00
div_margine . css ( " margin-top " , " -20px " );
div_prezzi . css ( " margin-top " , " -20px " );
2023-02-17 17:03:22 +01:00
div_prezzi . css ( " margin-bottom " , " 20px " );
2022-04-08 16:54:31 +02:00
div . html ( `<small class="label label-default" >'.tr('Maggiorazione').'</small>` );
} else {
2022-11-15 17:38:42 +01:00
div_margine . css ( " margin-top " , " 0px " );
div_prezzi . css ( " margin-top " , " 0px " );
2022-04-08 16:54:31 +02:00
div . html ( " " );
}
}
</ script > ' ;
2023-08-04 14:54:28 +02:00
}