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
2021-06-10 18:56:38 +02:00
if ( setting ( 'Attiva scorciatoie da tastiera' )) {
2021-07-07 07:57:10 +02:00
echo ' < div class = " alert alert-info " >
2021-11-15 12:02:21 +01:00
< i class = " fa fa-info-circle " ></ i > '.tr(' Scorciatoie da tastiera : < b > F7 </ b > - Barcode , < b > F8 </ b > - Carico , < b > F9 </ b > - Scarico , < b > F10 </ b > - Spostamento ').'
2021-06-10 18:56:38 +02:00
</ div > ' ;
}
2019-12-12 19:08:23 +01:00
?>
2021-06-10 18:56:38 +02: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 " >
2021-06-18 11:04:03 +02:00
{[ " type " : " number " , " label " : " <?php echo tr('Quantità'); ?> " , " name " : " qta " , " decimals " : " qta " , " 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 >
2021-06-10 18:56:38 +02:00
< div class = " alert alert-warning hidden " id = " articolo-missing " >
< h3 >< i class = " fa fa-warning " ></ i > '.tr(' Nessuna corrispondenza trovata ! ').' </ h3 >
2020-08-04 11:51:26 +02:00
</ 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 " );
2021-05-27 15:44:29 +02:00
$ ( " #modals > div " ) . on ( " shown.bs.modal " , function (){ ' ;
if ( setting ( 'Attiva scorciatoie da tastiera' )) {
echo 'EnableHotkeys()' ;
}
echo '
2020-11-11 15:01:48 +01:00
$ ( " #barcode " ) . focus ();
});
2021-05-27 15:44:29 +02:00
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 " );
2021-06-10 18:56:38 +02:00
if ( barcode . val () == " " && $ ( " #idarticolo " ) . val () == null && key === 13 ){
swal ( " '.tr('Inserisci barcode o seleziona un articolo').' " , " " , " warning " );
}
else 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 " );
2021-06-10 18:56:38 +02:00
input ( " barcode " ) . set ( " " );
$ ( " #barcode " ) . focus ();
2020-08-04 11:51:26 +02:00
}
}
);
}
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
}
2020-03-03 10:33:32 +01:00
2021-05-27 15:44:29 +02:00
function EnableHotkeys (){
2021-06-10 18:56:38 +02:00
//Anable hotkeys in blocked input elements
hotkeys . filter = function ( event ){
var tagName = ( event . target || event . srcElement ) . tagName ;
hotkeys . setScope ( /^ ( INPUT | TEXTAREA | SELECT ) $ /. test ( tagName ) ? " input " : " other " );
return true ;
}
2021-05-27 15:44:29 +02:00
hotkeys ( " f7,f8,f9,f10 " , function ( event , handler ) {
switch ( handler . key ) {
case " f7 " :
event . preventDefault ();
$ ( " #barcode " ) . focus ();
break ;
case " f8 " :
event . preventDefault ();
input ( " causale " ) . set ( " 1 " );
break ;
case " f9 " :
event . preventDefault ();
input ( " causale " ) . set ( " 2 " );
break ;
case " f10 " :
event . preventDefault ();
input ( " causale " ) . set ( " 3 " );
break ;
default : alert ( event );
}
});
}
2021-05-26 16:42:53 +02:00
2020-03-03 10:33:32 +01:00
</ script > ' ;
2020-08-04 11:51:26 +02:00
echo '
< div class = " hidden " id = " info-articolo " >
< div class = " row " >
< div class = " col-md-6 " >
2021-06-10 18:56:38 +02:00
< div class = " alert alert-info text-left " >
2020-08-04 11:51:26 +02:00
< h3 >
2021-06-10 18:56:38 +02:00
< b > '.tr(' Codice ').' :</ b > | codice |
2020-08-04 11:51:26 +02:00
</ 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 " >
2021-06-10 18:56:38 +02:00
< div class = " alert |alert-type| text-center " style = " margin-bottom:6px; " >
2020-08-04 11:51:26 +02:00
< h3 >
< i class = " fa |icon| " ></ i > | descrizione - movimento | | movimento | | misura |
</ h3 >
</ div >
2021-06-10 18:56:38 +02:00
< div class = " alert alert-info text-center " >
< h3 >
< i class = " fa fa-cubes " ></ i > | rimanente | | misura | rimanenti
</ h3 >
</ div >
2020-08-04 11:51:26 +02:00
</ div >
</ div >
</ div > ' ;
2021-10-06 12:03:31 +02:00
echo '
< script >
$ ( " #idsede_partenza " ) . change ( function (){
updateSelectOption ( " idsede_partenza " , $ ( this ) . val ());
session_set ( " superselect,idsede_partenza " , $ ( this ) . val (), 0 );
$ ( " #idarticolo " ) . selectReset ();
});
$ ( " #idsede_destinazione " ) . change ( function (){
updateSelectOption ( " idsede_destinazione " , $ ( this ) . val ());
session_set ( " superselect,idsede_destinazione " , $ ( this ) . val (), 0 );
$ ( " #idarticolo " ) . selectReset ();
});
2021-10-18 10:23:39 +02:00
</ script > ' ;