3 include_once($path_to_root . "/inventory/includes/prefs/sysprefs.inc");
4 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
16 var $editing_item, $deleting_item;
32 // --------------- line item functions
34 function add_to_cart($stock_id, $qty, $standard_cost, $description=null)
37 if (isset($stock_id) && $stock_id != "" && isset($qty))
39 $this->line_items[$stock_id] = new line_item($stock_id, $qty,
40 $standard_cost, $description);
41 $this->clear_editing_flags();
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 if (isset($this->line_items[$stock_id]) && $this->line_items[$stock_id] != null)
56 return $this->line_items[$stock_id];
60 function update_cart_item($update_item, $qty, $standard_cost)
62 $this->line_items[$update_item]->quantity = $qty;
63 $this->line_items[$update_item]->standard_cost = $standard_cost;
64 $this->clear_editing_flags();
67 function remove_from_cart(&$stock_id)
71 unset($this->line_items[$stock_id]);
72 $this->clear_editing_flags();
76 function count_items()
78 return count($this->line_items);
81 function check_qoh($location, $date_, $reverse=false)
83 foreach ($this->line_items as $line_item)
85 $item_ret = $line_item->check_qoh($location, $date_, $reverse);
86 if ($item_ret != null)
91 // ----------- GL item functions
93 function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
95 if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id) &&
96 isset($dimension2_id))
98 $this->gl_items[$this->gl_item_count] = new gl_item($this->gl_item_count,
99 $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description);
100 $this->gl_item_count++;
101 $this->clear_editing_flags();
106 // shouldn't come here under normal circumstances
107 display_db_error("unexpected - adding an invalid item or null quantity", "", true);
113 function update_gl_item($index, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
115 $this->gl_items[$index]->index = $index;
116 $this->gl_items[$index]->dimension_id = $dimension_id;
117 $this->gl_items[$index]->dimension2_id = $dimension2_id;
118 $this->gl_items[$index]->amount = $amount;
119 $this->gl_items[$index]->reference = $reference;
120 if ($description != null)
121 $this->gl_items[$index]->description = $description;
123 $this->clear_editing_flags();
126 function remove_gl_item($index)
130 unset($this->gl_items[$index]);
131 $this->clear_editing_flags();
135 function count_gl_items()
137 return count($this->gl_items);
140 function gl_items_total()
143 foreach ($this->gl_items as $gl_item)
144 $total += $gl_item->amount;
148 function gl_items_total_debit()
151 foreach ($this->gl_items as $gl_item)
153 if ($gl_item->amount > 0)
154 $total += $gl_item->amount;
159 function gl_items_total_credit()
162 foreach ($this->gl_items as $gl_item)
164 if ($gl_item->amount < 0)
165 $total += $gl_item->amount;
170 // ------------ common functions
172 function clear_items()
174 unset($this->line_items);
175 $this->line_items = array();
177 unset($this->gl_items);
178 $this->gl_items = array();
179 $this->gl_item_count = 1;
181 $this->clear_editing_flags();
184 function clear_editing_flags()
186 $this->editing_item = $this->deleting_item = 0;
189 function get_editing_item()
191 return $this->editing_item;
194 function get_deleting_item()
196 return $this->deleting_item;
199 function is_editing_item($index)
201 return ($this->editing_item > 0) && ($this->editing_item == $index);
204 function is_deleting_item($index)
206 return ($this->deleting_item > 0) && ($this->deleting_item == $index);
211 //--------------------------------------------------------------------------------------------
216 var $item_description;
224 function line_item ($stock_id, $qty, $standard_cost=null, $description=null)
226 $item_row = get_item($stock_id);
228 if ($item_row == null)
229 display_db_error("invalid item added to order : $stock_id", "");
231 $this->mb_flag = $item_row["mb_flag"];
232 $this->units = $item_row["units"];
234 if ($description == null)
235 $this->item_description = $item_row["description"];
237 $this->item_description = $description;
239 if ($standard_cost == null)
240 $this->standard_cost = $item_row["actual_cost"];
242 $this->standard_cost = $standard_cost;
244 $this->stock_id = $stock_id;
245 $this->quantity = $qty;
246 //$this->price = $price;
250 function check_qoh($location, $date_, $reverse)
252 if (!sys_prefs::allow_negative_stock())
254 if (has_stock_holding($this->mb_flag))
256 $quantity = $this->quantity;
258 $quantity = -$this->quantity;
263 $qoh = get_qoh_on_date($this->stock_id, $location, $date_);
264 if ($quantity + $qoh < 0)
275 //---------------------------------------------------------------------------------------
288 function gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference,
291 //echo "adding $index, $code_id, $dimension_id, $amount, $reference<br>";
293 if ($description == null)
294 $this->description = get_gl_account_name($code_id);
296 $this->description = $description;
298 $this->index = $index;
299 $this->code_id = $code_id;
300 $this->dimension_id = $dimension_id;
301 $this->dimension2_id = $dimension2_id;
302 $this->amount = $amount;
303 $this->reference = $reference;
307 //---------------------------------------------------------------------------------------