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
|
<?php $formid = "Operation"; require_once "inc/configure.php";
$parent_refid = filter_var($_REQUEST['parent_refid'], FILTER_SANITIZE_NUMBER_INT);
//(int)$_REQUEST['productID']; //vdump($_REQUEST); if( $_REQUEST['action']=="master_operation_addform" && !empty($parent_refid) ){
$code = strtoupper(filter_var($_REQUEST['code'], FILTER_SANITIZE_STRING)); $unit_price = filter_var($_REQUEST['unit_price'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); $codedesc_en = filter_var($_REQUEST['codedesc_en'], FILTER_SANITIZE_STRING); $codedesc_sc = filter_var($_REQUEST['codedesc_sc'], FILTER_SANITIZE_STRING); $uom_cy = filter_var($_REQUEST['uom_cy'], FILTER_SANITIZE_STRING); $uom_svc = filter_var($_REQUEST['uom_svc'], FILTER_SANITIZE_STRING); $workplace = filter_var($_REQUEST['workplace'], FILTER_SANITIZE_STRING); $settingcategy = filter_var($_REQUEST['settingcategy'], FILTER_SANITIZE_STRING);
$createby = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING); $lastupby = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING); if(havePermission("GNu")){ // check existance of operation before insert $sql = "SELECT count(*) as count from master_operation where code=:code"; $sth = $dbh->prepare($sql); $sth->execute( array(':code'=> $code) ); $row = $sth->fetch(); if( $row['count']>0 ){ $msg="Master Operation is already existed"; header("Location: master_operation_addform.php?refid=$parent_refid&error=$msg"); exit; } unset($sth); //get parent operation info if($parent_refid==-1){ //root operation $level = 0; } else{ $sql = "SELECT * from master_operation where refid=:refid"; $sth = $dbh->prepare($sql); $sth->execute( array(':refid'=> $parent_refid) ); $row = $sth->fetch(); $level = $row['level']+1; unset($sth); } //update operation master table $sql = "INSERT INTO master_operation ( code, codedesc_en, codedesc_sc, workplace, level, parent_refid, settingcategy, createby, createdate, lastupby, lastupdate ) VALUES ( :code, :codedesc_en, :codedesc_sc, :workplace, :level, :parent_refid, :settingcategy, :createby, getdate(), :lastupby, getdate() )"; $sth = $dbh->prepare($sql); $q= $sth->execute( array(':code' => $code, ':codedesc_en' => $codedesc_en, ':codedesc_sc' => $codedesc_sc, ':workplace' => $workplace, ':level' => $level, ':parent_refid' => $parent_refid, ':settingcategy' => $settingcategy, ':createby' => $createby, ':lastupby' => $lastupby) ); pdo_showerror($sth, $q); $refid = $dbh->lastInsertId(); //remove old operation cost $sql = "DELETE from master_svc_cost WHERE opr_refid = :opr_refid"; $sth = $dbh->prepare($sql); $q= $sth->execute( array(':opr_refid' => $refid) ); pdo_showerror($sth, $q); //add operation cost $sql = "INSERT INTO master_svc_cost ( opr_refid, unit_price, uom_cy, uom_svc, createby, createdate, lastupby, lastupdate ) VALUES ( :opr_refid, :unit_price, :uom_cy, :uom_svc, :createby, getdate(), :lastupby, getdate() )"; $sth = $dbh->prepare($sql); $q= $sth->execute( array(':opr_refid' => $refid, ':unit_price' => $unit_price, ':uom_cy' => $uom_cy, ':uom_svc' => $uom_svc, ':createby' => $createby, ':lastupby' => $lastupby) ); pdo_showerror($sth, $q); /*echo $sth->getSQL( ) . HTML_EOL;*/ } //exit; header("Location: master_operation_modifyform.php?refid=$refid&msg=Saved."); print "Saved."; exit; } print "Invalid Request";
|