2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
$module = Modules :: getModule ( $id_module );
2017-09-05 17:31:58 +02:00
// Controllo sulla direzione monetaria
$entrate = [
'Fatture di vendita' ,
'Ddt di vendita' ,
'Ordini cliente' ,
];
if ( in_array ( $module [ 'name' ], $entrate )) {
2017-08-04 16:28:16 +02:00
$dir = 'entrata' ;
} else {
$dir = 'uscita' ;
}
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' => [
'table' => 'mg_articoli_interventi' ,
'id' => 'idintervento' ,
],
];
// 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' ;
} elseif ( in_array ( $module [ 'name' ], [ 'Ordini cliente' , 'Ordini fornitore' ])) {
$modulo = 'ord' ;
} else {
$modulo = 'int' ;
}
$table = $data [ $modulo ][ 'table' ];
$id = $data [ $modulo ][ 'id' ];
$riga = str_replace ( 'id' , 'id_riga_' , $id );
2017-08-04 16:28:16 +02:00
$idarticolo = get ( 'idarticolo' );
2017-09-05 17:31:58 +02:00
$idriga = get ( 'idriga' );
2017-08-04 16:28:16 +02:00
2017-09-05 17:31:58 +02:00
$rs = $dbo -> fetchArray ( 'SELECT 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 '
2017-09-05 17:31:58 +02:00
< p > '.tr(' Articolo ').' : '.$rs[0][' codice '].' - '.$rs[0][' descrizione '].' </ p >
2017-08-04 16:28:16 +02:00
< form action = " '. $rootdir .'/editor.php?id_module='. $id_module .'&id_record='. $id_record .' " method = " post " >
< 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 .' " >
< input type = " hidden " name = " idarticolo " value = " '. $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 " >
2017-09-05 17:31:58 +02:00
{[ " type " : " select " , " label " : " '.tr('Serial').' " , " name " : " serial[] " , " multiple " : 1 , " value " : " '.implode(',', $serials ).' " , " values " : " query=SELECT DISTINCT serial AS id, serial AS descrizione FROM mg_prodotti WHERE dir= \ 'uscita \ ' AND serial NOT IN (SELECT serial FROM mg_prodotti WHERE dir= \ 'entrata \ ' AND '. $riga .' != \ ''. $idriga .' \ ') " , " extra " : " data-maximum= \" '.intval( $rs[0] ['qta']).' \" " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
} else {
echo '
2017-09-04 12:02:29 +02:00
< p > '.tr(' Inserisci i numeri seriali degli articoli aggiunti : ').' </ p > ' ;
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-05 17:31:58 +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 '
< div class = " col-md-4 " >
2017-09-05 17:31:58 +02:00
{[ " type " : " text " , " name " : " serial[] " , " value " : " '. $serials[$i] .' " '.(!empty($res) ? ' , " readonly " : 1 ' : ' ').' ]} ' ;
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' ;
2017-08-04 16:28:16 +02:00
}
2017-09-05 17:31:58 +02:00
$r = $dbo -> select ( $data [ $pos ][ 'table' ], $data [ $pos ][ 'id' ], [ 'id' => $res [ 0 ][ str_replace ( 'id' , 'id_riga_' , $data [ $pos ][ 'id' ])]]);
2017-08-04 16:28:16 +02:00
echo '
2017-09-05 17:31:58 +02:00
'.Modules::link($modulo, $r[0][$data[$pos][' id ']], tr(' Visualizza vendita ').' < i class = " fa fa-external-link " ></ i > ' , null );
2017-08-04 16:28:16 +02:00
}
echo '
</ 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 > ' ;
}
}
echo '
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
2017-09-04 12:02:29 +02:00
< button type = " submit " 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 '
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;