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
|
<?php $formid = "Inventory"; require_once "inc/configure.php";
function copy_NST_item($companyid){ global $dbh, $createby, $lastupby, $system_var; $lastID = inv_getLastStocktakeID($companyid); $currID = inv_getCurrentStocktakeID($companyid); //vdump($lastID, $currID); $sql = "SELECT dbo.inv_stocktake_raw.* FROM dbo.inv_stocktake_raw WHERE dbo.inv_stocktake_raw.invstocktake_refid = :invstocktake_refid "; $sth = $dbh->prepare($sql); $q = $sth->execute( array(':invstocktake_refid'=>$lastID) ); /* echo $sth->getSQL( array(':invstocktake_refid'=>$lastID) ). HTML_EOL;*/ pdo_showerror($sth, $q); $sql2 = "INSERT into inv_stocktake_raw( invno, location, bomcategy, itemid, input_qty, uom_qty, input_wt, uom_wt, invstocktake_refid, price, uom_price, uom_cy, createby, createdate, lastupby, lastupdate ) VALUES ( :invno, :location, :bomcategy, :itemid, :input_qty, :uom_qty, :input_wt, :uom_wt, :invstocktake_refid, :price, :uom_price, :uom_cy, :createby, GETDATE(), :lastupby, GETDATE() )"; $sth2 = $dbh->prepare($sql2); while($row = $sth->fetch() ){ $table = inv_getBomcategyTablename($row['bomcategy']); //vdump($table, $row['itemid']); $inv_item = getDB($table, $row['itemid']); //vdump($inv_item['nostocktake']); if($inv_item['nostocktake']){ //echo "NST"; if($row['bomcategy']=='accessory'){ $price = accessoryUnitPrice($refid); }else{ if($location==$system_var['COMPANY_OVERSEA']){ $price = $inv_item['supplier_price']; }else{ $price = $inv_item['price']; } } $q = $sth2->execute( array(':invno'=> $invno, ':location'=> $row['location'], ':bomcategy'=> $row['bomcategy'], ':itemid'=> $row['itemid'], ':input_qty'=> $row['input_qty'], ':uom_qty'=> $row['uom_qty'], ':input_wt'=> $row['input_wt'], ':uom_wt'=> $row['uom_wt'], ':createby'=> $createby, ':lastupby'=> $lastupby, ':price'=> $inv_item['price'], ':uom_price'=> $inv_item['uom_price'], ':uom_cy'=> $inv_item['uom_cy'], ':invstocktake_refid'=> $currID) ); /* echo $sth2->getSQL( array(':invno'=> $invno, ':location'=> $row['location'], ':bomcategy'=> $row['bomcategy'], ':itemid'=> $row['itemid'], ':input_qty'=> $row['input_qty'], ':uom_qty'=> $row['uom_qty'], ':input_wt'=> $row['input_wt'], ':uom_wt'=> $row['uom_wt'], ':createby'=> $createby, ':lastupby'=> $lastupby, ':price'=> $inv_item['price'], ':uom_price'=> $inv_item['uom_price'], ':uom_cy'=> $inv_item['uom_cy'], ':invstocktake_refid'=> $currID) ); */ pdo_showerror($sth, $q); } else{ //echo "skipped"; } } }
//$refid = filter_var($_REQUEST['refid'], FILTER_SANITIZE_NUMBER_INT); $invno = filter_var($_REQUEST['invno'], FILTER_SANITIZE_STRING); $companyid = filter_var($_REQUEST['companyid'], FILTER_SANITIZE_STRING); $createby = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING); $lastupby = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
//vdump($_REQUEST); if( $_REQUEST['action']=="stocktake_finish" ){ if(inv_underStocktake($companyid)===false){ myerror(INVALID.WS.REQUEST); exit; } if(havePermission("SIu")===false){ myerror(INVALID.WS.PERMISSION); exit; } $dbh->beginTransaction();
//copy nostocktake items copy_NST_item($companyid); $sql = "UPDATE inv_stocktake SET finishdate = GETDATE(), lastupby = :lastupby, lastupdate = GETDATE() WHERE finishdate IS NULL AND companyid = :companyid"; $sth = $dbh->prepare($sql); $q = $sth->execute( array(':lastupby'=>$lastupby, ':companyid'=>$companyid) ); /* echo $sth->getSQL( array(':invno'=>$invno, ':createby'=>$createby, ':lastupby'=>$lastupby) ). HTML_EOL;*/ pdo_showerror($sth, $q); //exit; $dbh->commit(); //header("Location: inv_stone_index.php?act=resume&msg=Saved."); header("Location: inv_stocktake_index.php?companyid=$companyid&msg=Finished."); print "Saved."; exit; } print "Invalid Request";
|