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
|
<?php $formid = $_REQUEST['formid']; require_once "inc/configure.php";
function copy_dgn_extra_bom($refid){ global $dbh; //copy info from last version $sql = "insert into dgn_extra_bom( pdt_moldno, drawing_no, bomname, est_price, qtn_price, createby, createdate, lastupby, lastupdate) select pdt_moldno, drawing_no, bomname, est_price, qtn_price, createby, createdate, lastupby, lastupdate from dgn_extra_bom where refid = :refid"; $sth = $dbh->prepare($sql); $sth->execute( array(':refid' => $refid) ); //echo $sth->getSQL( array(':refid' => $refid) );
$new_refid = $dbh->lastInsertId();
return $new_refid; }
if(havePermission("BMu")==false){ myerror("Invalid Permission"); }
$act = filter_var($_REQUEST['act'], FILTER_SANITIZE_STRING); $drawing_no = filter_var($_REQUEST['drawing_no'], FILTER_SANITIZE_STRING); $refid = filter_var($_REQUEST['refid'], FILTER_SANITIZE_NUMBER_INT);
//vdump($_REQUEST); exit;
if( $_REQUEST['action']=="dgn_extrabom_modify" && !empty($drawing_no) && !empty($refid) ){ //generals $bomname = filter_var($_REQUEST['bomname'], FILTER_SANITIZE_STRING); $pdt_moldno = filter_var($_REQUEST['pdt_moldno'], FILTER_SANITIZE_STRING); $est_price = (float)filter_var($_REQUEST['est_price'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); $qtn_price = (float)filter_var($_REQUEST['qtn_price'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); $createby = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING); $lastupby = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
$last_refid = $refid; $refid = copy_dgn_extra_bom($last_refid); $sql_param = array( ':bomname' => $bomname, ':lastupby' => $lastupby, ':refid' => $refid); if(havePermission("PPu")){ $sql_PPu_field="est_price = :est_price, qtn_price = :qtn_price,"; $sql_param[':est_price'] = $est_price; $sql_param[':qtn_price'] = $qtn_price; } //insert bom header $sql = "UPDATE dgn_extra_bom SET bomname=:bomname, $sql_PPu_field lastupby=:lastupby, lastupdate=GETDATE() where refid=:refid"; $sth = $dbh->prepare($sql);
$q= $sth->execute( $sql_param ); /*echo $q= $sth->getSQL( $sql_param );*/ pdo_showerror($sth, $q);
//delete old bom detail $sql = "DELETE from dgn_extra_bom_dtl WHERE extrabom_refid=:extrabom_refid"; $sth = $dbh->prepare($sql); $q= $sth->execute( array(':extrabom_refid'=> $last_refid) ); pdo_showerror($sth, $q); $sql = "DELETE from dgn_extra_bom WHERE refid=:refid"; $sth = $dbh->prepare($sql); $q= $sth->execute( array(':refid'=> $last_refid) ); pdo_showerror($sth, $q); // insert bom detail if(!empty($_REQUEST['bom_detail'])){ $sql = "INSERT INTO dgn_extra_bom_dtl (extrabom_refid, bomcategy, itemnoid, qty, uom_qty, price, uom_price, unitprice, createby, createdate, lastupby, lastupdate) Values(:extrabom_refid, :bcategy, :itemnoid, :qty, :uom_qty, :price, :uom_price, :unitprice, :createby, GETDATE(), :lastupby, GETDATE())"; $sth = $dbh->prepare($sql); foreach($_REQUEST['bom_detail'] as $bom_item){ //vdump($bom_item); $q= $sth->execute( array(':extrabom_refid' => $refid, ':bcategy' => $bom_item['bomcategy'], ':itemnoid' => $bom_item['itemnoid'], ':qty' => (float)$bom_item['qty'], ':uom_qty' => $bom_item['uom_qty'], ':price' => 0, ':uom_price' => $bom_item['uom_price'], ':unitprice' => 0, ':createby' => $createby, ':lastupby' => $lastupby) ); pdo_showerror($sth, $q); /* echo $sth->getSQL( array(':mold_refid' => $refid, ':bcategy' => $bom_item['bomcategy'], ':itemnoid' => $bom_item['itemnoid'], ':qty' => $bom_item['qty'], ':uom_qty' => $bom_item['uom_qty'], ':price' => $bom_item['price'], ':uom_price' => $bom_item['uom_price'], ':unitprice' => $bom_item['unitprice'], ':createby' => $createby, ':lastupby' => $lastupby) ) . HTML_EOL;*/ } }
/*// update product to mastermold reference---------------------------
$sql = "SELECT mold_refid from inv_product where refid = :refid"; $sth = $dbh->prepare($sql); $q= $sth->execute( array(':refid'=> $productrefid) ); pdo_showerror($sth, $q); //echo $sth->getSQL( array(':refid'=> $productrefid) ); pdo_showerror($sth, $q); $oldmold = $sth->fetch(); //var_dump($oldmold);
//update mastermold link of all related product $sql = "UPDATE inv_product SET mold_refid = :newrefid where mold_refid = :oldrefid"; $sth = $dbh->prepare($sql);
$q= $sth->execute( array(':newrefid'=> $refid, ':oldrefid'=> $oldmold['mold_refid']) ); //echo $sth->getSQL( array(':newrefid'=> $refid, ':oldrefid'=> $oldmold['mold_refid']) ); pdo_showerror($sth, $q); */
//header("Location: dgn_master_index.php?act=resume&refid=$refid&msg=Saved."); header("Location: iframe_dgn_extrabom_modifyform.php?action=$act&edit=1&refid=$refid&drawing_no=$drawing_no&formid=$formid&msg=Saved."); print "Saved."; exit; } myerror("Invaild request");
?>
|