/var/www/enzatesting.onesolution.hk/ajax_ord_pick_printlabel.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
$formid 
"Order";
require_once 
"inc/configure.php";
require_once 
"inc/ord_dtl_func.php";

// //write actual value to order BOM
// function updateOrderBOM_actualval($opr_param){

//     global $dbh;
//     $sql = "UPDATE ord_item_bom SET
//                 actual_qty = :actual_qty,
//                 lastupby = :lastupby,
//                 lastupdate = GETDATE()
//             WHERE refid = :refid";
//     $sth = $dbh->prepare($sql);
//     $q = $sth->execute(  array(':actual_qty' => $opr_param['txwt'],
//                             ':lastupby' => $opr_param['lastupby'],
//                             ':refid' => $opr_param['ordbom_refid']) );
// /*    echo $sth->getSQL(  array(':actual_qty' => $opr_param['txwt'],
//                             ':lastupby' => $opr_param['lastupby'],
//                             ':refid' => $opr_param['ordbom_refid']) );        */
//     pdo_showerror($sth, $q);
// }

function pick_checkinout($opr_param){
    
//write tx details to txpick
    
global $dbh;
    
$sql "INSERT into ord_txpick (
                txmain_refid, ordbom_refid, txqty, txwt, uom_qty, uom_wt,
                checkinby, checkin_time, checkoutby, checkout_time, status,
                bomcategy, itemnoid,
                createby, createdate, lastupby, lastupdate
            ) VALUES (
                :txmain_refid, :ordbom_refid, :txqty, :txwt, :uom_qty, :uom_wt,
                :checkinby, GETDATE(), :checkoutby, GETDATE(), :status,
                :bomcategy, :itemnoid,
                :createby, GETDATE(), :lastupby, GETDATE()
            )"
;
    
$sth $dbh->prepare($sql);
    
$q $sth->execute(  array(':txmain_refid' => $opr_param['txmain_refid'],
                            
':ordbom_refid' => $opr_param['ordbom_refid'],
                            
':txqty' => $opr_param['txqty'],
                            
':txwt' => $opr_param['txwt'],
                            
':uom_qty' => $opr_param['uom_qty'],
                            
':uom_wt' => $opr_param['uom_wt'],
                            
':checkinby' => $opr_param['checkinby'],
                            
':checkoutby' => $opr_param['checkoutby'],
                            
':status' => $opr_param['status'],
                            
':bomcategy' => $opr_param['bomcategy'],
                            
':itemnoid' => $opr_param['itemnoid'],
                            
':createby' => $opr_param['createby'],
                            
':lastupby' => $opr_param['lastupby']) );
/*    echo $sth->getSQL(  array(':txmain_refid' => $opr_param['txmain_refid'],
                            ':ordbom_refid' => $opr_param['ordbom_refid'],
                            ':txqty' => $opr_param['txqty'],
                            ':txwt' => $opr_param['txwt'],
                            ':uom_qty' => $opr_param['uom_qty'],
                            ':uom_wt' => $opr_param['uom_wt'],
                            ':checkinby' => $opr_param['checkinby'],
                            ':checkoutby' => $opr_param['checkoutby'],
                            ':status' => $opr_param['status'],
                            ':createby' => $opr_param['createby'],
                            ':lastupby' => $opr_param['lastupby']) );*/
    
pdo_showerror($sth$q);
    
$inc_refid $dbh->lastInsertId();

    
// updateOrderBOM_actualval($opr_param); //moved to update actual value at receive time
    
$opr_param['indqty'] = $opr_param['txqty'];
    
$opr_param['indwt'] = $opr_param['txwt'];
    
txpending_checkin($inc_refid$opr_param);

    return 
$inc_refid;
}

function 
pick_checkout($refid$opr_param){
    
//update tx details to txpick
    
global $dbh;
    
$sql "UPDATE ord_txpick SET
                ordbom_refid = :ordbom_refid,
                txqty = :txqty,
                txwt = :txwt,
                uom_qty = :uom_qty,
                uom_wt = :uom_wt,
                checkoutby = :checkoutby,
                bomcategy = :bomcategy,
                itemnoid = :itemnoid,
                checkout_time = GETDATE(),
                lastupby = :lastupby,
                lastupdate = GETDATE()
            WHERE refid = :refid"
;
    
$sth $dbh->prepare($sql);
    
$q $sth->execute(  array(':ordbom_refid' => $opr_param['ordbom_refid'],
                            
':txqty' => $opr_param['txqty'],
                            
':txwt' => $opr_param['txwt'],
                            
':uom_qty' => $opr_param['uom_qty'],
                            
':uom_wt' => $opr_param['uom_wt'],
                            
':checkoutby' => $opr_param['checkoutby'],
                            
':bomcategy' => $opr_param['bomcategy'],
                            
':itemnoid' => $opr_param['itemnoid'],
                            
':lastupby' => $opr_param['lastupby'],
                            
':refid' => $refid) );
/*    echo $sth->getSQL(  array(':ordbom_refid' => $opr_param['ordbom_refid'],
                            ':txqty' => $opr_param['txqty'],
                            ':txwt' => $opr_param['txwt'],
                            ':uom_qty' => $opr_param['uom_qty'],
                            ':uom_wt' => $opr_param['uom_wt'],
                            ':checkoutby' => $opr_param['checkoutby'],
                            ':lastupby' => $opr_param['lastupby'],
                            ':refid' => $refid) );        */
    
pdo_showerror($sth$q);


    
// updateOrderBOM_actualval($opr_param); //moved to update actual value at receive time
    
$opr_param['indqty'] = $opr_param['txqty'];
    
$opr_param['indwt'] = $opr_param['txwt'];
    
txpending_checkin($refid$opr_param);
    return 
$refid;
}

$refid                 = (int) filter_var($_REQUEST['refid'], FILTER_SANITIZE_STRING);
$orddtl_refid         = (int)filter_var($_REQUEST['orddtl_refid'], FILTER_SANITIZE_STRING);

if( 
$_POST['action']=="ord_pick_printlabel" && !empty($refid) ){
    
//vdump($_REQUEST);

    
$opr_param['opr_code']     = "PICK";
    
$opr_param['oprcode_fm']= "WHOO";
    
$opr_param['subtable']    = "ord_txpick";
    
$opr_param['checkinby'] = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
$opr_param['createby']    = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
$opr_param['lastupby']    = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
$opr_param['checkoutby']    = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
$opr_param['status']        = "PICK";    //mark picked in txpick

    
$dbh->beginTransaction();

    
//check if there is a txmain of PICK of the job card
    //if yes-> get the txmain_refid
    //if no-> create txmain for PICK and return txmain_refid
    
$txmain_all ord_getTxmain($orddtl_refid$opr_param['opr_code']);
    if( empty(
$txmain_all[0]) ){
        
$txmain_refid ord_checkin_tx($orddtl_refid$opr_param);
    } else {
        
$txmain_refid $txmain_all[0]['refid'];
    }
    
//vdump($txmain_all, $txmain_refid);

    
$opr_param['txmain_refid']    = $txmain_refid;
    
$refid             = (int)filter_var($_REQUEST['refid'], FILTER_SANITIZE_STRING);
    
$txqty            = (float)filter_var($_REQUEST['txqty'], FILTER_SANITIZE_NUMBER_FLOATFILTER_FLAG_ALLOW_FRACTION);
    
$actual_qty     = (float)filter_var($_REQUEST['qty'], FILTER_SANITIZE_NUMBER_FLOATFILTER_FLAG_ALLOW_FRACTION);
    
//$actual_qty_old    = (float)filter_var($_REQUEST['qty_old'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
    
$uom_qty        filter_var($_REQUEST['uom_qty'], FILTER_SANITIZE_STRING);
    
//store acutal picking values
    
if( $actual_qty>){ //update
        
$orderbom getDB_Orditembom($refid);
        
$opr_param['bomcategy']        = $orderbom['bomcategy'];
        
$opr_param['itemnoid']        = $orderbom['itemnoid'];
        
$opr_param['uom_qty']        = $orderbom['uom_qty'];

        
$opr_param['ordbom_refid']    = $refid;
        
$opr_param['txqty']            = $txqty;
        
$opr_param['txwt']            = $actual_qty;
        
$opr_param['uom_wt']        = $uom_qty;
        
$opr_param['orddtl_refid']    = $orddtl_refid;

        
//vdump($opr_param);

        //create/update txpick ref txmain_refid
        
$txpick ord_getTxpick$refid );
        if( empty(
$txpick) ){                            //new tx
            //echo "new";
            
$additional_qty $actual_qty;
            
pick_checkinout($opr_param);
            
inv_disableNoStocktake($opr_param['bomcategy'], $opr_param['itemnoid']);
        } elseif(
$txpick['txwt'] != $actual_qty) {        //update tx with new qty
            //echo "update";
            
$additional_qty $actual_qty $txpick_rm['txwt'];
            
pick_checkout($txpick['refid'], $opr_param);
            
inv_disableNoStocktake($opr_param['bomcategy'], $opr_param['itemnoid']);
        } else {
            
//echo "same val";
        
}

        
//check stock inventory have enough stock
        
$inv_valuable inv_getSafeWt($system_var['COMPANY_FACTORY'], $orderbom['bomcategy'], $orderbom['itemnoid']);
        
//vdump($inv_valuable, $actual_qty);
        
if( $additional_qty$inv_valuable){
            echo 
INSUFFICIENT_STOCK.PHP_EOL;
            
//exit; control disabled warning only (at this moment)
        
}

    }

    
// print label
    
$sql2 "INSERT INTO prn_txlabel (
                label_type, orddtl_refid, barcode, label_refid,
                barcode_readable, status, computername, ipaddr,
                actual_wt, actual_uom_wt,
                createby, createdate, lastupby, lastupdate
            ) VALUES (
                :labeltype, :orddtl_refid, :barcode, :label_refid,
                :barcode_readable, :status, :computername, :ipaddr,
                :actual_wt, :actual_uom_wt,
                :createby, GETDATE(), :lastupby, GETDATE()
            )"
;
    
$sth2 $dbh->prepare($sql2);
    
$q   $sth2->execute(array(
        
':labeltype' => 2//picking label
        
':orddtl_refid' => $orddtl_refid,
        
':label_refid' => $refid,
        
':barcode_readable' => 1,
        
':barcode' => generateJCBarcode($orddtl_refid),
        
':status' => 0,
        
':computername' => getRealIpAddr(), //gethostbyaddr(getRealIpAddr())
        
':ipaddr' => getRealIpAddr(),
        
':actual_wt' => $actual_qty,
        
':actual_uom_wt' => $orderbom['uom_wt'],
        
':createby' => filter_var($_SESSION['user'], FILTER_SANITIZE_STRING),
        
':lastupby' => filter_var($_SESSION['user'], FILTER_SANITIZE_STRING)
    ));

    
//check if the picking is finished of the job card
    //if yes-> write checkout_time to txmain
    
if( ord_finishedPicking($orddtl_refid) ){
        
$sql "UPDATE ord_txmain SET
                checkout_time=GETDATE(),
                checkoutby=:checkoutby,
                lastupby=:lastupby,
                lastupdate=GETDATE()
                WHERE refid=:refid"
;
        
$sth $dbh->prepare($sql);
        
$q$sth->execute( array(':checkoutby'=> $opr_param['lastupby'],
                                    
':lastupby' => $opr_param['lastupby'],
                                    
':refid'=> $txmain_refid) );
    
/*echo $sth->getSQL( array(':checkoutby'=> $opr_param['lastupby'],
                                        ':lastupby' => $opr_param['lastupby'],
                                        ':refid'=> $txmain_refid) );
*/        
pdo_showerror($sth$q);
        
ordmain_markIfFinishedPickingord_getOrdmain_refid($orddtl_refid) );
    }


    
//exit;
    
$dbh->commit();
    print 
SAVED;
}else {
    
header('HTTP/1.1 400 Bad Request');
    die(
'ERROR');
}


?>