|
1
|
<?
|
|
2
|
|
|
3
|
require_once ('DBTable.php');
|
|
4
|
require_once ('BasicEnum.php');
|
|
5
|
require_once ('DBFactory.php');
|
|
6
|
require_once ('StockCardRecord.php');
|
|
7
|
require_once ('Stock.php');
|
|
8
|
require_once ('Util.php');
|
|
9
|
|
|
10
|
final class Inbound extends DBTable
|
|
11
|
{
|
|
12
|
|
|
13
|
public $__TABLE = 'Inbound';
|
|
14
|
public static $__COLUMNS = array(
|
|
15
|
'id' => 0,
|
|
16
|
'item_id' => 0,
|
|
17
|
'item_dvsn_id' => 0,
|
|
18
|
'customer_id' => 0,
|
|
19
|
'customer_dvsn_id' => 0,
|
|
20
|
'supplier_id' => '',
|
|
21
|
'supplier_dvsn_id' => 0,
|
|
22
|
'package_type' => 0,
|
|
23
|
'package_qty' => 0,
|
|
24
|
'product_date' => '',
|
|
25
|
'qty' => 0,
|
|
26
|
'location_id' => 0,
|
|
27
|
'location_dvsn_id' => 0,
|
|
28
|
'status' => 0,
|
|
29
|
'slip_divide' => '',
|
|
30
|
'create_dt' => '',
|
|
31
|
'create_user_id' => 0,
|
|
32
|
'update_dt' => '',
|
|
33
|
'update_user_id' => 0,
|
|
34
|
'act_type' => '',
|
|
35
|
);
|
|
36
|
|
|
37
|
/**
|
|
38
|
* Insert record with generated ID
|
|
39
|
*
|
|
40
|
* @return generated ID
|
|
41
|
*/
|
|
42
|
public function add($ib_cols) {
|
|
43
|
try {
|
|
44
|
$id = parent::add($ib_cols);
|
|
45
|
|
|
46
|
// Update or Add to Stock table
|
|
47
|
$ib_cols['update_user_id'] = $ib_cols['create_user_id'];
|
|
48
|
$result_stockcard = (new StockCardRecord())->addStockCard_ib($ib_cols);
|
|
49
|
|
|
50
|
$result = (new Stock())->updateQty($ib_cols);
|
|
51
|
|
|
52
|
} catch (Exception $e) {
|
|
53
|
$this::$logger->error("Caught exception: " . print_r(sqlsrv_errors(), true));
|
|
54
|
return false;
|
|
55
|
}
|
|
56
|
|
|
57
|
return $id;
|
|
58
|
}
|
|
59
|
|
|
60
|
public function set_($ib_cols, $where, $diff, $old=null) {
|
|
61
|
try {
|
|
62
|
$rows_affected = parent::set($ib_cols, $where);
|
|
63
|
|
|
64
|
// check Item and Location with original value
|
|
65
|
if ($old == null) {
|
|
66
|
// Update or Add to Stock table with old key(Item and Location)
|
|
67
|
$ib_cols['qty'] = $diff;
|
|
68
|
$result = (new Stock())->updateQty($ib_cols);
|
|
69
|
} else {
|
|
70
|
$this::$logger->debug("Item or Location changed!");
|
|
71
|
// Add the qty number with new key
|
|
72
|
$result = (new Stock())->updateQty($ib_cols);
|
|
73
|
|
|
74
|
// Deduct an old stock record with its old number
|
|
75
|
$ib_cols['qty'] = $old['oqty'] * -1;
|
|
76
|
$ib_cols['item_id'] = $old['oitem_id'];
|
|
77
|
$ib_cols['item_dvsn_id'] = $old['oitem_dvsn_id'];
|
|
78
|
$ib_cols['location_id'] = $old['olocation_id'];
|
|
79
|
$ib_cols['location_dvsn_id'] = $old['olocation_dvsn_id'];
|
|
80
|
$ob_cols['product_date'] = $old['oproduct_date'];
|
|
81
|
$result = (new Stock())->updateQty($ib_cols);
|
|
82
|
}
|
|
83
|
|
|
84
|
} catch (Exception $e) {
|
|
85
|
$this::$logger->error("Caught exception: " . print_r(sqlsrv_errors(), true));
|
|
86
|
return false;
|
|
87
|
}
|
|
88
|
return $rows_affected;
|
|
89
|
}
|
|
90
|
|
|
91
|
public function remove($ib_cols) {
|
|
92
|
try {
|
|
93
|
$rows_affected = parent::remove("id = " . $ib_cols['id']);
|
|
94
|
|
|
95
|
// Update or Add to Stock table
|
|
96
|
$ib_cols['qty'] = $ib_cols['qty'] * -1;
|
|
97
|
$result = (new Stock())->updateQty($ib_cols);
|
|
98
|
|
|
99
|
} catch (Exception $e) {
|
|
100
|
$this::$logger->error("Caught exception: " . print_r(sqlsrv_errors(), true));
|
|
101
|
return false;
|
|
102
|
}
|
|
103
|
return $rows_affected;
|
|
104
|
}
|
|
105
|
|
|
106
|
/**
|
|
107
|
* cancel
|
|
108
|
*
|
|
109
|
* @return true if update successfully, otherwise return false
|
|
110
|
*/
|
|
111
|
public function cancel($ib_cols, $where){
|
|
112
|
try {
|
|
113
|
|
|
114
|
$upd_inb = "UPDATE " . $this->__TABLE .
|
|
115
|
" SET status = 3 ".
|
|
116
|
" , update_user_id = '" . $ib_cols['update_user_id'] . "'" .
|
|
117
|
" WHERE id='" . $ib_cols['id'] ."'";
|
|
118
|
|
|
119
|
$rows_affected = (new DBFactory())->query($upd_inb);
|
|
120
|
|
|
121
|
//$ib_cols['package_qty'] *= -1;
|
|
122
|
//$ib_cols['qty'] *= -1;
|
|
123
|
|
|
124
|
$upd_stock = "UPDATE Stock " .
|
|
125
|
" SET qty = qty - " . $ib_cols['qty'] .
|
|
126
|
" , update_user_id = '" . $ib_cols['update_user_id'] . "'" .
|
|
127
|
" WHERE item_id='" . $ib_cols['item_id'] . "'" .
|
|
128
|
" AND item_dvsn_id=" . $ib_cols['item_dvsn_id'] .
|
|
129
|
" AND customer_id='" . $ib_cols['customer_id'] . "'".
|
|
130
|
" AND customer_dvsn_id='" . $ib_cols['customer_dvsn_id']. "'";
|
|
131
|
|
|
132
|
$rows_affected = (new DBFactory())->query($upd_stock);
|
|
133
|
|
|
134
|
$ib_cols['package_qty'] *= -1;
|
|
135
|
$ib_cols['qty'] *= -1;
|
|
136
|
|
|
137
|
$create_dt = $ib_cols['create_dt']->format('Y-m-d H:i:s');
|
|
138
|
unset($ib_cols['create_dt']);
|
|
139
|
|
|
140
|
$ib_cols['create_dt'] = $create_dt;
|
|
141
|
$result_stockcard = (new StockCardRecord())->addStockCard_ib($ib_cols)?1:0;
|
|
142
|
|
|
143
|
return $result_stockcard;
|
|
144
|
}catch (Exception $e) {
|
|
145
|
$this::$logger->error("Caught exception: " . print_r(sqlsrv_errors(), true));
|
|
146
|
return false;
|
|
147
|
}
|
|
148
|
|
|
149
|
}
|
|
150
|
}
|