2020-11-12 09:23:07 +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-12-12 19:08:23 +01:00
include_once __DIR__ . '/../../core.php' ;
// Imposto come azienda l'azienda predefinita per selezionare le sedi a cui ho accesso
2020-08-17 16:25:01 +02:00
// select-options
2019-12-12 19:08:23 +01:00
?>
2019-12-13 10:04:27 +01:00
< form action = " " method = " post " id = " add-form " >
2020-08-04 11:51:26 +02:00
< input type = " hidden " name = " op " value = " add " >
< input type = " hidden " name = " backto " value = " record-edit " >
2020-11-11 15:01:48 +01:00
< div class = " row " >
< div class = " col-md-offset-4 col-md-4 " >
2020-11-12 17:11:09 +01:00
{[ " type " : " text " , " label " : " <?php echo tr('Ricerca con lettore'); ?> " , " name " : " barcode " , " icon-before " : " <i class= \" fa fa-barcode \" ></i> " ]}
2020-08-04 11:51:26 +02:00
</ div >
</ div >
2020-12-18 14:19:32 +01:00
2019-12-12 19:08:23 +01:00
< div class = " row " >
< div class = " col-md-4 " >
2020-08-17 16:25:01 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Articolo'); ?> " , " name " : " idarticolo " , " ajax-source " : " articoli " , " value " : " " , " required " : 1 , " select-options " : { " permetti_movimento_a_zero " : 1 , " idanagrafica " : < ? php echo setting ( 'Azienda predefinita' ); ?> , "idsede_partenza": 0, "idsede_destinazione": 0} ]}
2019-12-12 19:08:23 +01:00
</ div >
< div class = " col-md-2 " >
2020-03-03 10:33:32 +01:00
{[ " type " : " number " , " label " : " <?php echo tr('Quantità'); ?> " , " name " : " qta " , " decimals " : " 2 " , " value " : " 1 " , " required " : 1 ]}
2019-12-12 19:08:23 +01:00
</ div >
< div class = " col-md-2 " >
2020-03-03 10:33:32 +01:00
{[ " type " : " date " , " label " : " <?php echo tr('Data'); ?> " , " name " : " data " , " value " : " -now- " , " required " : 1 ]}
2019-12-12 19:08:23 +01:00
</ div >
< div class = " col-md-4 " >
2020-08-04 11:51:26 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Causale'); ?> " , " name " : " causale " , " values " : " query=SELECT id, nome as text, descrizione, tipo_movimento FROM mg_causali_movimenti " , " value " : 1 , " required " : 1 ]}
< input type = " hidden " name = " tipo_movimento " id = " tipo_movimento " value = " carico " >
2019-12-12 19:08:23 +01:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-12 " >
2020-08-04 11:51:26 +02:00
{[ " type " : " textarea " , " label " : " <?php echo tr('Descrizione movimento'); ?> " , " name " : " movimento " , " required " : 1 , " value " : " Carico manuale " ]}
2019-12-12 19:08:23 +01:00
</ div >
</ div >
< div class = " row " >
2019-12-13 10:04:27 +01:00
< div class = " col-md-6 " >
2020-08-04 11:51:26 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Partenza merce'); ?> " , " name " : " idsede_partenza " , " ajax-source " : " sedi_azienda " , " value " : " 0 " , " required " : 1 , " disabled " : " 1 " ]}
2019-12-12 19:08:23 +01:00
</ div >
< div class = " col-md-6 " >
2020-08-04 11:51:26 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Destinazione merce'); ?> " , " name " : " idsede_destinazione " , " ajax-source " : " sedi_azienda " , " value " : " 0 " , " required " : 1 ]}
2019-12-12 19:08:23 +01:00
</ div >
</ div >
2020-08-04 11:51:26 +02:00
<!-- PULSANTI -->
< div class = " row " id = " buttons " >
< div class = " col-md-12 text-right " >
< button type = " submit " class = " btn btn-default " >
2020-11-12 09:23:07 +01:00
< i class = " fa fa-exchange " ></ i > < ? php echo tr ( 'Movimenta e chiudi' ); ?>
2020-08-04 11:51:26 +02:00
</ button >
< button type = " button " class = " btn btn-primary " onclick = " salva(this); " id = " aggiungi " >
2020-11-12 09:23:07 +01:00
< i class = " fa fa-exchange " ></ i > < ? php echo tr ( 'Movimenta' ); ?>
2020-08-04 11:51:26 +02:00
</ button >
</ div >
</ div >
2019-12-12 19:08:23 +01:00
</ form >
2020-08-04 11:51:26 +02:00
< ? php
echo '
< hr >
2019-12-12 19:08:23 +01:00
2020-02-05 10:32:41 +01:00
< div id = " messages " ></ div >
2020-08-04 11:51:26 +02:00
< div class = " alert alert-info hidden " id = " articolo-missing " >
< i class = " fa fa-exclamation-circle " ></ i > '.tr(' Nessuna corrispondenza trovata ! ').'
</ div >
2019-12-12 19:08:23 +01:00
< script >
2020-08-04 11:51:26 +02:00
// Lettura codici da lettore barcode
$ ( document ) . unbind ( " keyup " );
2020-12-09 18:07:18 +01:00
$ ( " #modals > div " ) . on ( " shown.bs.modal " , function (){
2020-11-11 15:01:48 +01:00
$ ( " #barcode " ) . focus ();
});
2020-08-04 11:51:26 +02:00
$ ( document ) . on ( " keyup " , function ( event ) {
if ( $ ( " :focus " ) . is ( " input, textarea " )) {
return ;
}
let key = window . event ? event . keyCode : event . which ; // IE vs Netscape/Firefox/Opera
$ ( " #articolo-missing " ) . addClass ( " hidden " );
let barcode = $ ( " #barcode " );
if ( key === 13 ) {
2020-11-11 15:01:48 +01:00
let search = barcode . val () . replace ( / [ ^ a - z0 - 9 \s\ - \ . \ / \\ | ] +/ gmi , " " );
2020-08-04 11:51:26 +02:00
ricercaBarcode ( search );
} else if ( key === 8 ) {
barcode . val ( barcode . val () . substr ( 0 , barcode . val () . length - 1 ));
} else if ( key <= 90 && key >= 48 ) {
barcode . val ( barcode . val () + String . fromCharCode ( key ));
}
});
function abilitaSede ( id ){
$ ( id ) . removeClass ( " disabled " )
. attr ( " disabled " , false )
. attr ( " required " , true );
}
function disabilitaSede ( id ){
$ ( id ) . addClass ( " disabled " )
. attr ( " disabled " , true )
. attr ( " required " , false );
}
$ ( document ) . ready ( function () {
$ ( " #causale " ) . on ( " change " , function () {
let data = $ ( this ) . selectData ();
2020-03-03 10:33:32 +01:00
if ( data ) {
2020-08-04 11:51:26 +02:00
$ ( " #movimento " ) . val ( data . descrizione );
$ ( " #tipo_movimento " ) . val ( data . tipo_movimento );
if ( data . tipo_movimento === " carico " ) {
disabilitaSede ( " #idsede_partenza " );
abilitaSede ( " #idsede_destinazione " );
} else if ( data . tipo_movimento === " scarico " ) {
abilitaSede ( " #idsede_partenza " );
disabilitaSede ( " #idsede_destinazione " );
} else {
abilitaSede ( " #idsede_partenza " );
abilitaSede ( " #idsede_destinazione " );
}
} else {
disabilitaSede ( " #idsede_partenza " );
disabilitaSede ( " #idsede_destinazione " );
2020-03-03 10:33:32 +01:00
}
2019-12-12 19:08:23 +01:00
});
2020-08-04 11:51:26 +02:00
// Reload pagina appena chiudo il modal
$ ( " #modals > div " ) . on ( " hidden.bs.modal " , function () {
location . reload ();
});
});
2019-12-13 10:04:27 +01:00
2020-08-04 11:51:26 +02:00
function ricercaBarcode ( barcode ) {
// Ricerca via ajax del barcode negli articoli
2020-12-18 14:19:32 +01:00
$ . get ( globals . rootdir + " /ajax_select.php?op=articoli&search= " + barcode ,
2020-08-04 11:51:26 +02:00
function ( data ){
data = JSON . parse ( data );
2019-12-13 10:04:27 +01:00
2020-08-04 11:51:26 +02:00
// Articolo trovato
if ( data . results . length === 1 ) {
2020-12-18 14:19:32 +01:00
let record = data . results [ 0 ];
2020-08-04 11:51:26 +02:00
$ ( " #idarticolo " ) . selectSetNew ( record . id , record . text , record );
2019-12-12 19:08:23 +01:00
2020-08-04 11:51:26 +02:00
salva ( $ ( " #aggiungi " ));
}
2019-12-13 10:19:00 +01:00
2020-08-04 11:51:26 +02:00
// Articolo non trovato
else {
2020-11-11 17:16:26 +01:00
$ ( " #messages " ) . remove ();
2020-08-04 11:51:26 +02:00
$ ( " #articolo-missing " ) . removeClass ( " hidden " );
}
}
);
}
async function salva ( button ) {
$ ( " #messages " ) . html ( " " );
2020-12-18 14:19:32 +01:00
let qta_input = input ( " qta " );
let tipo_movimento = $ ( " #tipo_movimento " ) . val ();
2020-08-04 11:51:26 +02:00
2021-03-29 18:31:23 +02:00
await salvaForm ( " #add-form " , {}, button );
let articolo = $ ( " #idarticolo " ) . selectData ();
let prezzo_acquisto = parseFloat ( articolo . prezzo_acquisto );
let prezzo_vendita = parseFloat ( articolo . prezzo_vendita );
2021-04-22 12:36:00 +02:00
let iva_vendita = articolo . iva_vendita ;
2021-03-29 18:31:23 +02:00
let qta_movimento = qta_input . get ();
let alert_type , icon , text , qta_rimanente ;
if ( tipo_movimento === " carico " ) {
alert_type = " alert-success " ;
icon = " fa-arrow-up " ;
text = " Carico " ;
qta_rimanente = parseFloat ( articolo . qta ) + parseFloat ( qta_movimento );
} else if ( tipo_movimento === " scarico " ) {
alert_type = " alert-danger " ;
icon = " fa-arrow-down " ;
text = " Scarico " ;
qta_rimanente = parseFloat ( articolo . qta ) - parseFloat ( qta_movimento );
} else if ( tipo_movimento === " spostamento " ) {
alert_type = " alert-info " ;
icon = " fa-arrow-down " ;
text = " Spostamento " ;
qta_rimanente = parseFloat ( articolo . qta );
}
2020-12-18 14:19:32 +01:00
2021-03-29 18:31:23 +02:00
if ( articolo . descrizione ) {
let testo = $ ( " #info-articolo " ) . html ();
testo = testo . replace ( " |alert-type| " , alert_type )
. replace ( " |icon| " , icon )
. replace ( " |descrizione| " , articolo . descrizione )
. replace ( " |codice| " , articolo . codice )
. replace ( " |misura| " , articolo . um )
. replace ( " |misura| " , articolo . um )
. replace ( " |descrizione-movimento| " , text )
. replace ( " |movimento| " , qta_movimento . toLocale ())
. replace ( " |rimanente| " , qta_rimanente . toLocale ())
. replace ( " |prezzo_acquisto| " , prezzo_acquisto . toLocale ())
2021-04-22 12:36:00 +02:00
. replace ( " |prezzo_vendita| " , prezzo_vendita . toLocale ())
. replace ( " |iva_vendita| " , iva_vendita );
2021-03-29 18:31:23 +02:00
$ ( " #messages " ) . html ( testo );
}
2020-03-03 10:33:32 +01:00
2021-03-29 18:31:23 +02:00
qta_input . set ( 1 );
$ ( " #causale " ) . trigger ( " change " );
2020-12-09 18:07:18 +01:00
2021-03-29 18:31:23 +02:00
if ( input ( " barcode " ) . get () !== " " ){
$ ( " #idarticolo " ) . selectReset ();
input ( " barcode " ) . set ( " " );
$ ( " #barcode " ) . focus ();
2019-12-12 19:08:23 +01:00
}
2020-08-04 11:51:26 +02:00
}
</ script > ' ;
2020-02-28 00:22:12 +01:00
if ( setting ( 'Attiva scorciatoie da tastiera' )) {
2020-02-28 12:04:12 +01:00
echo '
2020-03-03 10:33:32 +01:00
< script >
2020-08-04 11:51:26 +02:00
hotkeys ( " f8 " , " carico " , function () {
2020-03-03 10:33:32 +01:00
$ ( " #modals > div #direzione " ) . val ( 1 ) . change ();
});
2020-08-04 11:51:26 +02:00
hotkeys . setScope ( " carico " );
2020-03-03 10:33:32 +01:00
2020-08-04 11:51:26 +02:00
hotkeys ( " f9 " , " scarico " , function () {
2020-03-03 10:33:32 +01:00
$ ( " #modals > div #direzione " ) . val ( 2 ) . change ();
});
2020-08-04 11:51:26 +02:00
hotkeys . setScope ( " scarico " );
2020-03-03 10:33:32 +01:00
</ script > ' ;
2020-02-28 12:04:12 +01:00
}
2020-08-04 11:51:26 +02:00
echo '
< div class = " hidden " id = " info-articolo " >
< div class = " row " >
< div class = " col-md-6 " >
< div class = " alert alert-info text-center " >
< h3 >
| codice |
</ h3 >
< p >< b > '.tr(' Descrizione ').' :</ b > | descrizione |</ p >
< p >< b > '.tr(' Prezzo acquisto ').' :</ b > | prezzo_acquisto | '.currency().' </ p >
< p >< b > '.tr(' Prezzo vendita ').' :</ b > | prezzo_vendita | '.currency().' </ p >
2021-04-22 12:36:00 +02:00
< p >< b > '.tr(' IVA ').' :</ b > | iva_vendita |</ p >
2020-08-04 11:51:26 +02:00
</ div >
</ div >
< div class = " col-md-6 " >
< div class = " alert |alert-type| text-center " >
< h3 >
< i class = " fa |icon| " ></ i > | descrizione - movimento | | movimento | | misura |
< i class = " fa fa-arrow-circle-right " ></ i > | rimanente | | misura | rimanenti
</ h3 >
</ div >
</ div >
</ div >
</ div > ' ;