2018-02-19 10:52:42 +01:00
< ? php
2018-06-23 18:35:08 +02:00
$result [ 'idarticolo' ] = isset ( $result [ 'idarticolo' ]) ? $result [ 'idarticolo' ] : null ;
2020-07-06 13:32:43 +02:00
$qta_minima = 0 ;
2018-02-19 10:52:42 +01:00
// Articolo
2020-02-14 17:02:16 +01:00
if ( empty ( $result [ 'idarticolo' ])) {
2018-02-19 11:50:42 +01:00
echo '
2018-02-19 10:52:42 +01:00
< div class = " row " >
< div class = " col-md-12 " >
2020-08-17 16:25:01 +02:00
{[ " type " : " select " , " label " : " '.tr('Articolo').' " , " name " : " idarticolo " , " required " : 1 , " value " : " '. $result['idarticolo'] .' " , " ajax-source " : " articoli " , " select-options " : '.json_encode($options[' select - options '][' articoli ']).' , " icon-after " : " add|'.Modules::get('Articoli')['id'].' " ]}
2018-02-19 10:52:42 +01:00
</ div >
2020-07-06 13:32:43 +02:00
</ div >
< input type = " hidden " name = " id_dettaglio_fornitore " id = " id_dettaglio_fornitore " value = " " > ' ;
2018-02-19 11:50:42 +01:00
} else {
2018-09-20 12:05:22 +02:00
$database = database ();
2020-07-06 13:32:43 +02:00
$articolo = $database -> fetchOne ( ' SELECT mg_articoli . id ,
mg_fornitore_articolo . id AS id_dettaglio_fornitore ,
IFNULL ( mg_fornitore_articolo . codice_fornitore , mg_articoli . codice ) AS codice ,
IFNULL ( mg_fornitore_articolo . descrizione , mg_articoli . descrizione ) AS descrizione ,
IFNULL ( mg_fornitore_articolo . qta_minima , 0 ) AS qta_minima
FROM mg_articoli
LEFT JOIN mg_fornitore_articolo ON mg_fornitore_articolo . id_articolo = mg_articoli . id AND mg_fornitore_articolo . id = '.prepare($result[' id_dettaglio_fornitore ']).'
WHERE mg_articoli . id = '.prepare($result[' idarticolo ' ]));
$qta_minima = $articolo [ 'qta_minima' ];
2018-02-19 11:50:42 +01:00
echo '
2020-04-15 16:25:44 +02:00
< p >< strong > '.tr(' Articolo ').' :</ strong > '.$articolo[' codice '].' - '.$articolo[' descrizione '].' .</ p >
< input type = " hidden " name = " idarticolo " id = " idarticolo " value = " '. $articolo['id'] .' " > ' ;
2020-02-14 17:02:16 +01:00
}
2020-07-06 13:32:43 +02:00
echo '
< input type = " hidden " name = " qta_minima " id = " qta_minima " value = " '. $qta_minima .' " > ' ;
2020-02-14 17:02:16 +01:00
// Selezione impianto per gli Interventi
if ( $module [ 'name' ] == 'Interventi' ) {
echo '
< div class = " row " >
< div class = " col-md-12 " >
2020-08-17 16:25:01 +02:00
{[ " type " : " select " , " label " : " '.tr('Impianto su cui installare').' " , " name " : " idimpianto " , " value " : " '. $idimpianto .' " , " ajax-source " : " impianti-intervento " , " select-options " : '.json_encode($options[' select - options '][' impianti ']).' ]}
2020-02-14 17:02:16 +01:00
</ div >
</ div > ' ;
2018-02-19 11:50:42 +01:00
}
2018-02-19 10:52:42 +01:00
echo App :: internalLoad ( 'riga.php' , $result , $options );
2020-02-14 17:02:16 +01:00
// Informazioni aggiuntive
if ( $module [ 'name' ] != 'Contratti' && $module [ 'name' ] != 'Preventivi' ) {
$disabled = empty ( $result [ 'idarticolo' ]);
2018-02-19 10:52:42 +01:00
2020-02-14 17:02:16 +01:00
echo '
2020-04-21 15:44:49 +02:00
< div class = " row '.(!empty( $options['nascondi_prezzi'] ) ? 'hidden' : '').' " id = " prezzi_articolo " >
2020-02-14 17:02:16 +01:00
< div class = " col-md-4 text-center " >
2020-04-15 16:25:44 +02:00
< button type = " button " class = " btn btn-sm btn-info btn-block '.( $disabled ? 'disabled' : '').' " '.($disabled ? ' disabled ' : ' ').' onclick = " $ ( \ '#prezziacquisto \ ').toggleClass( \ 'hide \ '); $ ( \ '#prezziacquisto \ ').load( \ ''.ROOTDIR. " / ajax_complete . php ? module = Articoli & op = getprezziacquisto & idarticolo = ' + ( $(' #idarticolo option:selected').val() || $('#idarticolo').val()) + '&idanagrafica=".$options['idanagrafica'].'\');">
< i class = " fa fa-search " ></ i > '.tr(' Ultimi prezzi di acquisto ').'
2020-02-14 17:02:16 +01:00
</ button >
2020-04-15 16:25:44 +02:00
< div id = " prezziacquisto " class = " hide " ></ div >
2020-02-14 17:02:16 +01:00
</ div >
2018-02-19 10:52:42 +01:00
2020-02-14 17:02:16 +01:00
< div class = " col-md-4 text-center " >
2020-04-15 16:25:44 +02:00
< button type = " button " class = " btn btn-sm btn-info btn-block '.( $disabled ? 'disabled' : '').' " '.($disabled ? ' disabled ' : ' ').' onclick = " $ ( \ '#prezzi \ ').toggleClass( \ 'hide \ '); $ ( \ '#prezzi \ ').load( \ ''.ROOTDIR. " / ajax_complete . php ? module = Articoli & op = getprezzi & idarticolo = ' + ( $(' #idarticolo option:selected').val() || $('#idarticolo').val()) + '&idanagrafica=".$options['idanagrafica'].'\');">
< i class = " fa fa-search " ></ i > '.tr(' Ultimi prezzi al cliente ').'
2020-02-14 17:02:16 +01:00
</ button >
2020-04-15 16:25:44 +02:00
< div id = " prezzi " class = " hide " ></ div >
2018-02-19 10:52:42 +01:00
</ div >
2020-02-14 17:02:16 +01:00
< div class = " col-md-4 text-center " >
2020-04-15 16:25:44 +02:00
< button type = " button " class = " btn btn-sm btn-info btn-block '.( $disabled ? 'disabled' : '').' " '.($disabled ? ' disabled ' : ' ').' onclick = " $ ( \ '#prezzivendita \ ').toggleClass( \ 'hide \ '); $ ( \ '#prezzivendita \ ').load( \ ''.ROOTDIR. " / ajax_complete . php ? module = Articoli & op = getprezzivendita & idarticolo = ' + ( $(' #idarticolo option:selected').val() || $('#idarticolo').val()) + '&idanagrafica=".$options['idanagrafica'].'\');">
< i class = " fa fa-search " ></ i > '.tr(' Ultimi prezzi di vendita ').'
2020-02-14 17:02:16 +01:00
</ button >
< div id = " prezzivendita " class = " hide " ></ div >
</ div >
</ div >
< br > ' ;
}
echo '
< script >
$ ( document ) . ready ( function () {
2020-07-06 13:32:43 +02:00
$ ( " #idarticolo " ) . on ( " change " , function () {
2020-02-14 17:02:16 +01:00
// Autoimpostazione dei valori relativi
if ( $ ( this ) . val ()) {
$data = $ ( this ) . selectData ();
2020-02-14 18:31:07 +01:00
$ ( " #prezzo_unitario " ) . val ( $data . prezzo_ '.($options[' dir '] == ' entrata ' ? ' vendita ' : ' acquisto ').' );
$ ( " #costo_unitario " ) . val ( $data . prezzo_acquisto );
2020-02-26 17:23:43 +01:00
$ ( " #descrizione_riga " ) . val ( $data . descrizione ); ' ;
2020-02-14 17:02:16 +01:00
2020-02-27 16:19:07 +01:00
if ( $options [ 'dir' ] == 'entrata' ) {
2020-02-26 17:23:43 +01:00
echo '
2020-07-06 13:32:43 +02:00
if ( $data . idiva_vendita ) {
2020-02-14 17:02:16 +01:00
$ ( " #idiva " ) . selectSetNew ( $data . idiva_vendita , $data . iva_vendita );
2020-02-26 17:23:43 +01:00
} ' ;
2020-07-06 13:32:43 +02:00
} else {
echo '
$ ( " #id_dettaglio_fornitore " ) . val ( $data . id_dettaglio_fornitore );
$ ( " #qta_minima " ) . val ( $data . qta_minima );
aggiorna_qta_minima (); ' ;
2020-02-26 17:23:43 +01:00
}
2020-02-27 16:19:07 +01:00
2020-02-26 17:23:43 +01:00
echo '
2020-07-06 13:32:43 +02:00
var id_conto = $data . idconto_ '.($options[' dir '] == ' entrata ' ? ' vendita ' : ' acquisto ').' ;
2020-02-14 17:02:16 +01:00
if ( id_conto ) {
$ ( " #idconto " ) . selectSetNew ( id_conto , $data . idconto_ '.($options[' dir '] == ' entrata ' ? ' vendita ' : ' acquisto ').' _title );
}
2020-07-06 13:32:43 +02:00
2020-02-14 17:02:16 +01:00
$ ( " #um " ) . selectSetNew ( $data . um , $data . um );
2020-07-30 14:22:22 +02:00
// Aggiornamento automatico di guadagno e margine
aggiorna_guadagno ();
2020-02-14 17:02:16 +01:00
} ' ;
2018-02-19 10:52:42 +01:00
2020-02-14 17:02:16 +01:00
if ( $module [ 'name' ] != 'Contratti' && $module [ 'name' ] != 'Preventivi' ) {
2018-02-19 11:50:42 +01:00
echo '
2020-02-14 17:02:16 +01:00
// Operazioni sui prezzi in fondo alla pagina
$ ( " #prezzi_articolo button " ) . attr ( " disabled " , ! $ ( this ) . val ());
if ( $ ( this ) . val ()) {
$ ( " #prezzi_articolo button " ) . removeClass ( " disabled " );
} else {
$ ( " #prezzi_articolo button " ) . addClass ( " disabled " );
}
$ ( " #prezzi " ) . html ( " " );
$ ( " #prezzivendita " ) . html ( " " );
$ ( " #prezziacquisto " ) . html ( " " ); ' ;
2018-02-19 11:50:42 +01:00
}
2020-02-14 17:02:16 +01:00
echo '
2020-07-06 13:32:43 +02:00
}); ' ;
if ( $options [ 'dir' ] == 'uscita' ) {
echo '
aggiorna_qta_minima ();
$ ( " #qta " ) . keyup ( aggiorna_qta_minima ); ' ;
}
echo '
}); ' ;
if ( $options [ 'dir' ] == 'uscita' ) {
echo '
// Funzione per l\'aggiornamento in tempo reale del guadagno
function aggiorna_qta_minima () {
var qta_minima = parseFloat ( $ ( " #qta_minima " ) . val ());
var qta = $ ( " #qta " ) . val () . toEnglish ();
if ( qta_minima == 0 ) {
return ;
}
var parent = $ ( " #qta " ) . closest ( " div " ) . parent ();
var div = parent . find ( " div[id*= \" errors \" ] " );
div . html ( " <small>'.tr('Quantità minima').': " + qta_minima . toLocale () + " </small> " );
if ( qta < qta_minima ) {
parent . addClass ( " has-error " );
div . addClass ( " text-danger " ) . removeClass ( " text-success " );
} else {
parent . removeClass ( " has-error " );
div . removeClass ( " text-danger " ) . addClass ( " text-success " );
}
} ' ;
}
echo '
2020-02-14 17:02:16 +01:00
</ script > ' ;