2017-08-04 16:28:16 +02: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 />.
*/
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2023-06-26 15:12:43 +02:00
use Modules\DDT\DDT ;
2017-09-22 15:19:59 +02:00
$module = Modules :: get ( $id_module );
2023-07-05 11:43:07 +02:00
$module_articoli = Modules :: get ( 'Articoli' );
$plugin_serial = Plugins :: get ( 'Serial' );
2017-08-04 16:28:16 +02:00
2017-09-05 17:31:58 +02:00
// Controllo sulla direzione monetaria
2017-09-05 18:20:02 +02:00
$uscite = [
'Fatture di acquisto' ,
'Ddt di acquisto' ,
'Ordini fornitore' ,
2017-09-05 17:31:58 +02:00
];
2017-09-05 18:20:02 +02:00
if ( in_array ( $module [ 'name' ], $uscite )) {
2017-08-04 16:28:16 +02:00
$dir = 'uscita' ;
2017-09-05 18:20:02 +02:00
} else {
$dir = 'entrata' ;
2017-08-04 16:28:16 +02:00
}
2017-09-05 17:31:58 +02:00
$data = [
'fat' => [
'table' => 'co_righe_documenti' ,
'id' => 'iddocumento' ,
],
'ddt' => [
'table' => 'dt_righe_ddt' ,
'id' => 'idddt' ,
],
'ord' => [
'table' => 'or_righe_ordini' ,
'id' => 'idordine' ,
],
'int' => [
2020-02-14 17:02:16 +01:00
'table' => 'in_righe_interventi' ,
2017-09-05 17:31:58 +02:00
'id' => 'idintervento' ,
],
2023-11-13 15:38:27 +01:00
'veb' => [
'table' => 'vb_righe_venditabanco' ,
'id' => 'idvendita' ,
],
'con' => [
'table' => 'co_righe_contratti' ,
'id' => 'idcontratto' ,
],
2017-09-05 17:31:58 +02:00
];
// Individuazione delle tabelle interessate
if ( in_array ( $module [ 'name' ], [ 'Fatture di vendita' , 'Fatture di acquisto' ])) {
$modulo = 'fat' ;
} elseif ( in_array ( $module [ 'name' ], [ 'Ddt di vendita' , 'Ddt di acquisto' ])) {
$modulo = 'ddt' ;
2023-06-26 15:12:43 +02:00
$ddt = DDT :: find ( $id_record );
$is_rientrabile = $database -> fetchOne ( 'SELECT * FROM `dt_causalet` WHERE `id` = ' . prepare ( $ddt -> idcausalet ))[ 'is_rientrabile' ];
2017-09-05 17:31:58 +02:00
} elseif ( in_array ( $module [ 'name' ], [ 'Ordini cliente' , 'Ordini fornitore' ])) {
$modulo = 'ord' ;
2023-11-13 15:38:27 +01:00
} elseif ( $module [ 'name' ] == 'Interventi' ) {
2017-09-05 17:31:58 +02:00
$modulo = 'int' ;
2023-11-13 15:38:27 +01:00
} elseif ( $module [ 'name' ] == 'Contratti' ) {
$modulo = 'con' ;
} else {
$modulo = 'veb' ;
2017-09-05 17:31:58 +02:00
}
$table = $data [ $modulo ][ 'table' ];
$id = $data [ $modulo ][ 'id' ];
$riga = str_replace ( 'id' , 'id_riga_' , $id );
2020-07-06 13:19:20 +02:00
$idriga = get ( 'idriga' ) ? : get ( 'riga_id' );
2017-08-04 16:28:16 +02:00
2017-09-05 18:20:02 +02:00
$rs = $dbo -> fetchArray ( 'SELECT mg_articoli.id AS idarticolo, mg_articoli.codice, mg_articoli.descrizione, ' . $table . '.qta FROM ' . $table . ' INNER JOIN mg_articoli ON ' . $table . '.idarticolo=mg_articoli.id WHERE ' . $table . '.' . $id . '=' . prepare ( $id_record ) . ' AND ' . $table . '.id=' . prepare ( $idriga ));
2017-08-04 16:28:16 +02:00
echo '
2023-07-05 11:43:07 +02:00
< h4 class = " text-center " > '.tr(' Articolo ').' : '.$rs[0][' codice '].' - '.$rs[0][' descrizione '].' </ h4 >
2017-08-04 16:28:16 +02:00
2023-11-17 17:27:31 +01:00
< form action = " '.base_path().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .' " method = " post " id = " serial-form " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " op " value = " add_serial " >
< input type = " hidden " name = " backto " value = " record-edit " >
2017-09-05 17:31:58 +02:00
< input type = " hidden " name = " idriga " value = " '. $idriga .' " >
2017-09-05 18:20:02 +02:00
< input type = " hidden " name = " idarticolo " value = " '. $rs[0] ['idarticolo'].' " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " dir " value = " '. $dir .' " > ' ;
2017-09-05 17:31:58 +02:00
$info = $dbo -> fetchArray ( 'SELECT * FROM mg_prodotti WHERE serial IS NOT NULL AND ' . $riga . '=' . prepare ( $idriga ));
$serials = array_column ( $info , 'serial' );
2017-08-04 16:28:16 +02:00
if ( $dir == 'entrata' ) {
echo '
< div class = " row " >
< div class = " col-md-12 " >
2023-07-05 11:43:07 +02:00
{[ " type " : " select " , " label " : " '.tr('Serial').' " , " name " : " serial[] " , " multiple " : 1 , " value " : " '.implode(',', $serials ).' " , " ajax-source " : " serial-articolo " , " select-options " : '.json_encode([' idarticolo ' => $rs[0][' idarticolo ']]).' , " extra " : " data-maximum= \" '.intval( $rs[0] ['qta']).' \" " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
} else {
echo '
2023-07-05 11:43:07 +02:00
< div class = " row " >
< div class = " col-md-5 " >
{[ " type " : " text " , " label " : " '.tr('Inizio').' " , " name " : " serial_start " ]}
</ div >
< div class = " col-md-2 text-center " style = " padding-top: 20px; " >
< i class = " fa fa-arrow-circle-right fa-2x " ></ i >
</ div >
< div class = " col-md-5 " >
{[ " type " : " text " , " label " : " '.tr('Fine').' " , " name " : " serial_end " ]}
</ div >
</ div >
< div class = " row " >
< div class = " col-md-12 text-center " >
< button type = " button " class = " btn btn-info " onclick = " generaSerial(); " >< i class = " fa fa-magic " ></ i > '.tr(' Genera ').' </ button >
</ div >
</ div >
< hr >
< h5 > '.tr(' Inserisci i numeri seriali degli articoli aggiunti : ').' </ h5 > ' ;
2017-09-05 17:31:58 +02:00
for ( $i = 0 ; $i < $rs [ 0 ][ 'qta' ]; ++ $i ) {
if ( $i % 3 == 0 ) {
2017-08-04 16:28:16 +02:00
echo '
< div class = " row " > ' ;
}
2017-09-06 10:48:59 +02:00
$res = [];
2018-02-18 19:53:23 +01:00
if ( ! empty ( $serials [ $i ])) {
2017-09-06 10:48:59 +02:00
$res = $dbo -> fetchArray ( " SELECT * FROM mg_prodotti WHERE dir='entrata' AND serial = " . prepare ( $serials [ $i ]));
}
2017-08-04 16:28:16 +02:00
echo '
2023-06-26 15:12:43 +02:00
< div class = " col-md-6 " >
{[ " type " : " text " , " name " : " serial[] " , " class " : " serial " , " id " : " serial_'. $i .' " , " value " : " '. $serials[$i] .' " '.(!empty($res) ? ' , " readonly " : 1 ' : ' ').' ]} ' ;
2017-09-05 17:31:58 +02:00
if ( ! empty ( $res )) {
if ( ! empty ( $res [ 0 ][ 'id_riga_intervento' ])) {
$modulo = 'Interventi' ;
$pos = 'int' ;
} elseif ( ! empty ( $res [ 0 ][ 'id_riga_ddt' ])) {
$modulo = 'Ddt di vendita' ;
$pos = 'ddt' ;
} elseif ( ! empty ( $res [ 0 ][ 'id_riga_documento' ])) {
$modulo = 'Fatture di vendita' ;
$pos = 'fat' ;
} elseif ( ! empty ( $res [ 0 ][ 'id_riga_ordine' ])) {
$modulo = 'Ordini cliente' ;
$pos = 'ord' ;
2023-11-13 15:38:27 +01:00
} elseif ( ! empty ( $res [ 0 ][ 'id_riga_contratto' ])) {
$modulo = 'Contratti' ;
$pos = 'con' ;
} elseif ( ! empty ( $res [ 0 ][ 'id_riga_venditabanco' ])) {
$modulo = 'Vendita al banco' ;
$pos = 'veb' ;
2017-08-04 16:28:16 +02:00
}
2023-09-15 18:06:15 +02:00
$r = $dbo -> select ( $data [ $pos ][ 'table' ], $data [ $pos ][ 'id' ], [], [ 'id' => $res [ 0 ][ str_replace ( 'id' , 'id_riga_' , $data [ $pos ][ 'id' ])]]);
2017-09-05 17:31:58 +02:00
2017-08-04 16:28:16 +02:00
echo '
2017-09-14 10:27:49 +02:00
'.Modules::link($modulo, $r[0][$data[$pos][' id ']], tr(' Visualizza vendita ' ), null );
2017-08-04 16:28:16 +02:00
}
echo '
</ div > ' ;
2023-06-26 15:12:43 +02:00
if ( $is_rientrabile ) {
echo '
< div class = " col-md-6 " >
{[ " type " : " select " , " name " : " select_serial_'. $i .' " , " value " : " '.implode(',', $serials ).' " , " values " : " query=SELECT serial AS id, serial AS descrizione FROM mg_prodotti WHERE id_articolo = '.prepare( $rs[0] ['idarticolo']).' AND mg_prodotti.dir= \ 'entrata \ ' AND id=(SELECT MAX(id) FROM mg_prodotti AS prodotti WHERE prodotti.id_articolo=mg_prodotti.id_articolo AND prodotti.serial=mg_prodotti.serial) " , " onchange " : " aggiornaSerial('. $i .'); " '.(!empty($res) ? ' , " readonly " : 1 ' : ' ').' ]}
</ div > ' ;
}
2017-09-05 17:31:58 +02:00
if (( $i + 1 ) % 3 == 0 ) {
2017-08-04 16:28:16 +02:00
echo '
</ div >
< br > ' ;
}
}
2017-09-05 17:31:58 +02:00
if ( $i % 3 != 0 ) {
2017-08-04 16:28:16 +02:00
echo '
</ div > ' ;
}
2022-06-16 11:06:51 +02:00
2023-03-08 14:24:05 +01:00
$module_fatture = Modules :: get ( 'Fatture di acquisto' )[ 'id' ];
2022-06-16 11:06:51 +02:00
echo '
< br >
< div class = " alert alert-warning text-center has_serial hidden " >
< i class = " fa fa-warning " ></ i >
< b > '.tr(' Attenzione ! ').' </ b > '.tr(' Il Serial su questo articolo è già stato utilizzato in un altro documento di acquisto ').' .
</ div >
< script >
2023-07-05 11:43:07 +02:00
$ ( " .serial " ) . on ( " keyup change " , function () {
2023-06-26 15:12:43 +02:00
controllaSerial ( $ ( this ) . val ());
});
function controllaSerial ( value ) {
2022-06-16 11:06:51 +02:00
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " post " ,
data : {
id_module : " '. $module_fatture .' " ,
id_record : globals . id_record ,
2023-06-26 15:12:43 +02:00
serial : value ,
2023-07-05 11:43:07 +02:00
is_rientrabile : " '. $is_rientrabile .' " ,
2022-06-16 11:06:51 +02:00
id_articolo : input ( " idarticolo " ) . get (),
2023-07-05 11:43:07 +02:00
op : " controlla_serial "
2022-06-16 11:06:51 +02:00
},
success : function ( data ){
data = JSON . parse ( data );
if ( data ) {
$ ( " .has_serial " ) . removeClass ( " hidden " );
$ ( " #aggiorna " ) . addClass ( " disabled " );
} else {
$ ( " .has_serial " ) . addClass ( " hidden " );
$ ( " #aggiorna " ) . removeClass ( " disabled " );
}
}
});
2023-06-26 15:12:43 +02:00
}
function aggiornaSerial ( i ) {
let select_serial = $ ( " #select_serial_ " + i );
if ( select_serial . val ()) {
$ ( " #serial_ " + i ) . val ( select_serial . val ());
controllaSerial ( select_serial . val ());
select_serial . selectClear ();
}
}
2023-07-05 11:43:07 +02:00
function generaSerial () {
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " POST " ,
dataType : " json " ,
data : {
id_module : " '. $module_articoli->id .' " ,
id_record : " '. $rs[0] ['idarticolo'].' " ,
serial_start : input ( " serial_start " ) . get (),
serial_end : input ( " serial_end " ) . get (),
check : 1 ,
op : " generate_serials "
},
success : function ( response ) {
let i = 0 ;
$ ( " .serial " ) . each ( function () {
$ ( this ) . val ( response [ i ]);
controllaSerial ( response [ i ]);
i ++ ;
});
}
});
}
2022-06-16 11:06:51 +02:00
</ script > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
<!-- PULSANTI -->
< div class = " row " >
2023-07-05 11:43:07 +02:00
< div class = " col-md-2 " >
< button type = " button " class = " btn btn-info '.( $dir == 'uscita' ? 'hidden' : '').' " data - toggle = " modal " data - title = " '.tr('Aggiungi serial').' " data - href = " '.base_path().'/modules/articoli/plugins/articoli.lotti.php?id_module='. $module_articoli->id .'&id_record='. $rs[0] ['idarticolo'].'&modal=1 " >< i class = " fa fa-magic " ></ i > '.tr(' Crea ').' </ button >
</ div >
< div class = " col-md-10 text-right " >
2023-11-17 17:27:31 +01:00
< button type = " button " id = " aggiorna " class = " btn btn-primary pull-right " >< i class = " fa fa-barcode " ></ i > '.tr(' Aggiorna ').' </ button >
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ form > ' ;
echo '
2019-07-26 17:40:52 +02:00
< script > $ ( document ) . ready ( init ) </ script > ' ;
2023-11-17 17:27:31 +01:00
echo '
< script >
$ ( " #aggiorna " ) . on ( " click " , function () {
var form = input ( " #serial-form " );
salvaForm ( " #serial-form " , {
id_module : " '. $id_module .' " ,
id_record : " '. $id_record .' " ,
}) . then ( function ( response ) {
form . getElement () . closest ( " div[id^=bs-popup " ) . modal ( " hide " );
caricaRighe ( null );
});
return false ;
});
</ script > ' ;