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
|
<?php
use Illuminate\Database\Capsule\Manager as DB; use Carbon\Carbon as Carbon;
class StocktransferItem extends BaseModel{ protected $table = "stocktransfer_item";
public function stocktransfer(){ return $this->belongsTo('Stocktransfer'); }
public function proProductSku(){ return $this->belongsTo('ProProductSku', 'sku_id'); }
/*
Status: NEW-->SENT-->RECEIVED |-->DELETED
*/
public function can_be_updated(){ switch ($this->status) { case 'NEW': return true; } return false; }
public function can_be_deleted(){ switch ($this->status) { case 'NEW': return true; } return false; }
public function can_be_sent(){ switch ($this->status) { case 'NEW': return true; } return false; }
public function can_be_received(){ switch ($this->status) { case 'SENT': return true; } return false; }
public function send(){ if($this->can_be_sent()){ $this->status = 'SENT'; $this->senddate = timestamp();
// modify inventory_txn Inventory::stocktransfer($this->sku_id, $this->qty, $this->stocktransfer->from_warehouse_id, $this->stocktransfer->transport_warehouse_id, array( 'to_stocktransfer_id' => $this->stocktransfer_id, 'stockout_doc' => array( 'doc_type' => 'StocktransferItem', 'doc_id' => $this->id, ), 'stockin_doc' => array( 'doc_type' => 'StocktransferItem', 'doc_id' => $this->id, ), ));
return $this; } throw new Exception("Unable to send the product", 1); }
public function receive(){ if($this->can_be_received()){ $this->status = 'RECEIVED'; $this->receivedate = timestamp();
// modify inventory_txn Inventory::stocktransfer($this->sku_id, $this->qty, $this->stocktransfer->transport_warehouse_id, $this->stocktransfer->to_warehouse_id, array( 'from_stocktransfer_id' => $this->stocktransfer_id, 'stockout_doc' => array( 'doc_type' => 'StocktransferItem', 'doc_id' => $this->id, ), 'stockin_doc' => array( 'doc_type' => 'StocktransferItem', 'doc_id' => $this->id, ), )); return $this; } throw new Exception("Unable to receive the product", 1); } }
|