3 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
15 var $editing_item, $deleting_item;
31 // --------------- line item functions
33 function add_to_cart($stock_id, $qty, $standard_cost, $description=null)
36 if (isset($stock_id) && $stock_id != "" && isset($qty))
38 $this->line_items[$stock_id] = new line_item($stock_id, $qty,
39 $standard_cost, $description);
40 $this->clear_editing_flags();
45 // shouldn't come here under normal circumstances
46 display_db_error("unexpected - adding an invalid item or null quantity", "", true);
52 function find_cart_item($stock_id)
54 if (isset($this->line_items[$stock_id]) && $this->line_items[$stock_id] != null)
55 return $this->line_items[$stock_id];
59 function update_cart_item($update_item, $qty, $standard_cost)
61 $this->line_items[$update_item]->quantity = $qty;
62 $this->line_items[$update_item]->standard_cost = $standard_cost;
63 $this->clear_editing_flags();
66 function remove_from_cart(&$stock_id)
70 unset($this->line_items[$stock_id]);
71 $this->clear_editing_flags();
75 function count_items()
77 return count($this->line_items);
80 function check_qoh($location, $date_, $reverse=false)
82 foreach ($this->line_items as $line_item)
84 $item_ret = $line_item->check_qoh($location, $date_, $reverse);
85 if ($item_ret != null)
90 // ----------- GL item functions
92 function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
94 if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id) &&
95 isset($dimension2_id))
97 $this->gl_items[$this->gl_item_count] = new gl_item($this->gl_item_count,
98 $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description);
99 $this->gl_item_count++;
100 $this->clear_editing_flags();
105 // shouldn't come here under normal circumstances
106 display_db_error("unexpected - adding an invalid item or null quantity", "", true);
112 function update_gl_item($index, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
114 $this->gl_items[$index]->index = $index;
115 $this->gl_items[$index]->dimension_id = $dimension_id;
116 $this->gl_items[$index]->dimension2_id = $dimension2_id;
117 $this->gl_items[$index]->amount = $amount;
118 $this->gl_items[$index]->reference = $reference;
119 if ($description != null)
120 $this->gl_items[$index]->description = $description;
122 $this->clear_editing_flags();
125 function remove_gl_item($index)
129 unset($this->gl_items[$index]);
130 $this->clear_editing_flags();
134 function count_gl_items()
136 return count($this->gl_items);
139 function gl_items_total()
142 foreach ($this->gl_items as $gl_item)
143 $total += $gl_item->amount;
147 function gl_items_total_debit()
150 foreach ($this->gl_items as $gl_item)
152 if ($gl_item->amount > 0)
153 $total += $gl_item->amount;
158 function gl_items_total_credit()
161 foreach ($this->gl_items as $gl_item)
163 if ($gl_item->amount < 0)
164 $total += $gl_item->amount;
169 // ------------ common functions
171 function clear_items()
173 unset($this->line_items);
174 $this->line_items = array();
176 unset($this->gl_items);
177 $this->gl_items = array();
178 $this->gl_item_count = 1;
180 $this->clear_editing_flags();
183 function clear_editing_flags()
185 $this->editing_item = $this->deleting_item = 0;
188 function get_editing_item()
190 return $this->editing_item;
193 function get_deleting_item()
195 return $this->deleting_item;
198 function is_editing_item($index)
200 return ($this->editing_item > 0) && ($this->editing_item == $index);
203 function is_deleting_item($index)
205 return ($this->deleting_item > 0) && ($this->deleting_item == $index);
210 //--------------------------------------------------------------------------------------------
215 var $item_description;
223 function line_item ($stock_id, $qty, $standard_cost=null, $description=null)
225 $item_row = get_item($stock_id);
227 if ($item_row == null)
228 display_db_error("invalid item added to order : $stock_id", "");
230 $this->mb_flag = $item_row["mb_flag"];
231 $this->units = $item_row["units"];
233 if ($description == null)
234 $this->item_description = $item_row["description"];
236 $this->item_description = $description;
238 if ($standard_cost == null)
239 $this->standard_cost = $item_row["actual_cost"];
241 $this->standard_cost = $standard_cost;
243 $this->stock_id = $stock_id;
244 $this->quantity = $qty;
245 //$this->price = $price;
249 function check_qoh($location, $date_, $reverse)
251 if (!sys_prefs::allow_negative_stock())
253 if (has_stock_holding($this->mb_flag))
255 $quantity = $this->quantity;
257 $quantity = -$this->quantity;
262 $qoh = get_qoh_on_date($this->stock_id, $location, $date_);
263 if ($quantity + $qoh < 0)
274 //---------------------------------------------------------------------------------------
287 function gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference,
290 //echo "adding $index, $code_id, $dimension_id, $amount, $reference<br>";
292 if ($description == null)
293 $this->description = get_gl_account_name($code_id);
295 $this->description = $description;
297 $this->index = $index;
298 $this->code_id = $code_id;
299 $this->dimension_id = $dimension_id;
300 $this->dimension2_id = $dimension2_id;
301 $this->amount = $amount;
302 $this->reference = $reference;
306 //---------------------------------------------------------------------------------------