3 include_once($path_to_root . "/includes/prefs/sysprefs.inc");
4 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
16 var $editing_item, $deleting_item;
27 function items_cart($type)
29 $this->trans_type = $type;
33 // --------------- line item functions
35 function add_to_cart($line_no, $stock_id, $qty, $standard_cost, $description=null)
38 if (isset($stock_id) && $stock_id != "" && isset($qty))
40 $this->line_items[$line_no] = new line_item($stock_id, $qty,
41 $standard_cost, $description);
46 // shouldn't come here under normal circumstances
47 display_db_error("unexpected - adding an invalid item or null quantity", "", true);
53 function find_cart_item($stock_id)
55 foreach($this->line_items as $line_no=>$line) {
56 if ($line->stock_id == $stock_id)
57 return $this->line_items[$line_no];
62 function update_cart_item($line_no, $qty, $standard_cost)
64 $this->line_items[$line_no]->quantity = $qty;
65 $this->line_items[$line_no]->standard_cost = $standard_cost;
68 function remove_from_cart($line_no)
70 unset($this->line_items[$line_no]);
73 function count_items()
75 return count($this->line_items);
78 function check_qoh($location, $date_, $reverse=false)
80 foreach ($this->line_items as $line_no => $line_item)
82 $item_ret = $line_item->check_qoh($location, $date_, $reverse);
83 if ($item_ret != null)
89 // ----------- GL item functions
91 function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
93 if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id) &&
94 isset($dimension2_id))
96 $this->gl_items[$this->gl_item_count] = new gl_item($this->gl_item_count,
97 $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description);
98 $this->gl_item_count++;
103 // shouldn't come here under normal circumstances
104 display_db_error("unexpected - adding an invalid item or null quantity", "", true);
110 function update_gl_item($index, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
112 $this->gl_items[$index]->index = $index;
113 $this->gl_items[$index]->dimension_id = $dimension_id;
114 $this->gl_items[$index]->dimension2_id = $dimension2_id;
115 $this->gl_items[$index]->amount = $amount;
116 $this->gl_items[$index]->reference = $reference;
117 if ($description != null)
118 $this->gl_items[$index]->description = $description;
122 function remove_gl_item($index)
126 unset($this->gl_items[$index]);
130 function count_gl_items()
132 return count($this->gl_items);
135 function gl_items_total()
138 foreach ($this->gl_items as $gl_item)
139 $total += $gl_item->amount;
143 function gl_items_total_debit()
146 foreach ($this->gl_items as $gl_item)
148 if ($gl_item->amount > 0)
149 $total += $gl_item->amount;
154 function gl_items_total_credit()
157 foreach ($this->gl_items as $gl_item)
159 if ($gl_item->amount < 0)
160 $total += $gl_item->amount;
165 // ------------ common functions
167 function clear_items()
169 unset($this->line_items);
170 $this->line_items = array();
172 unset($this->gl_items);
173 $this->gl_items = array();
174 $this->gl_item_count = 1;
179 //--------------------------------------------------------------------------------------------
184 var $item_description;
192 function line_item ($stock_id, $qty, $standard_cost=null, $description=null)
194 $item_row = get_item($stock_id);
196 if ($item_row == null)
197 display_db_error("invalid item added to order : $stock_id", "");
199 $this->mb_flag = $item_row["mb_flag"];
200 $this->units = $item_row["units"];
202 if ($description == null)
203 $this->item_description = $item_row["description"];
205 $this->item_description = $description;
207 if ($standard_cost == null)
208 $this->standard_cost = $item_row["actual_cost"];
210 $this->standard_cost = $standard_cost;
212 $this->stock_id = $stock_id;
213 $this->quantity = $qty;
214 //$this->price = $price;
218 function check_qoh($location, $date_, $reverse)
220 if (!sys_prefs::allow_negative_stock())
222 if (has_stock_holding($this->mb_flag))
224 $quantity = $this->quantity;
226 $quantity = -$this->quantity;
231 $qoh = get_qoh_on_date($this->stock_id, $location, $date_);
232 if ($quantity + $qoh < 0)
243 //---------------------------------------------------------------------------------------
256 function gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference,
259 //echo "adding $index, $code_id, $dimension_id, $amount, $reference<br>";
261 if ($description == null)
262 $this->description = get_gl_account_name($code_id);
264 $this->description = $description;
266 $this->index = $index;
267 $this->code_id = $code_id;
268 $this->dimension_id = $dimension_id;
269 $this->dimension2_id = $dimension2_id;
270 $this->amount = $amount;
271 $this->reference = $reference;
275 //---------------------------------------------------------------------------------------