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;
32 // --------------- line item functions
34 function add_to_cart($line_no, $stock_id, $qty, $standard_cost, $description=null)
37 if (isset($stock_id) && $stock_id != "" && isset($qty))
39 $this->line_items[$line_no] = new line_item($stock_id, $qty,
40 $standard_cost, $description);
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 foreach($this->line_items as $line_no=>$line) {
55 if ($line->stock_id == $stock_id)
56 return $this->line_items[$line_no];
61 function update_cart_item($line_no, $qty, $standard_cost)
63 $this->line_items[$line_no]->quantity = $qty;
64 $this->line_items[$line_no]->standard_cost = $standard_cost;
67 function remove_from_cart($line_no)
69 unset($this->line_items[$line_no]);
72 function count_items()
74 return count($this->line_items);
77 function check_qoh($location, $date_, $reverse=false)
79 foreach ($this->line_items as $line_no => $line_item)
81 $item_ret = $line_item->check_qoh($location, $date_, $reverse);
82 if ($item_ret != null)
87 // ----------- GL item functions
89 function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
91 if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id) &&
92 isset($dimension2_id))
94 $this->gl_items[$this->gl_item_count] = new gl_item($this->gl_item_count,
95 $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description);
96 $this->gl_item_count++;
101 // shouldn't come here under normal circumstances
102 display_db_error("unexpected - adding an invalid item or null quantity", "", true);
108 function update_gl_item($index, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
110 $this->gl_items[$index]->index = $index;
111 $this->gl_items[$index]->dimension_id = $dimension_id;
112 $this->gl_items[$index]->dimension2_id = $dimension2_id;
113 $this->gl_items[$index]->amount = $amount;
114 $this->gl_items[$index]->reference = $reference;
115 if ($description != null)
116 $this->gl_items[$index]->description = $description;
120 function remove_gl_item($index)
124 unset($this->gl_items[$index]);
128 function count_gl_items()
130 return count($this->gl_items);
133 function gl_items_total()
136 foreach ($this->gl_items as $gl_item)
137 $total += $gl_item->amount;
141 function gl_items_total_debit()
144 foreach ($this->gl_items as $gl_item)
146 if ($gl_item->amount > 0)
147 $total += $gl_item->amount;
152 function gl_items_total_credit()
155 foreach ($this->gl_items as $gl_item)
157 if ($gl_item->amount < 0)
158 $total += $gl_item->amount;
163 // ------------ common functions
165 function clear_items()
167 unset($this->line_items);
168 $this->line_items = array();
170 unset($this->gl_items);
171 $this->gl_items = array();
172 $this->gl_item_count = 1;
177 //--------------------------------------------------------------------------------------------
182 var $item_description;
190 function line_item ($stock_id, $qty, $standard_cost=null, $description=null)
192 $item_row = get_item($stock_id);
194 if ($item_row == null)
195 display_db_error("invalid item added to order : $stock_id", "");
197 $this->mb_flag = $item_row["mb_flag"];
198 $this->units = $item_row["units"];
200 if ($description == null)
201 $this->item_description = $item_row["description"];
203 $this->item_description = $description;
205 if ($standard_cost == null)
206 $this->standard_cost = $item_row["actual_cost"];
208 $this->standard_cost = $standard_cost;
210 $this->stock_id = $stock_id;
211 $this->quantity = $qty;
212 //$this->price = $price;
216 function check_qoh($location, $date_, $reverse)
218 if (!sys_prefs::allow_negative_stock())
220 if (has_stock_holding($this->mb_flag))
222 $quantity = $this->quantity;
224 $quantity = -$this->quantity;
229 $qoh = get_qoh_on_date($this->stock_id, $location, $date_);
230 if ($quantity + $qoh < 0)
241 //---------------------------------------------------------------------------------------
254 function gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference,
257 //echo "adding $index, $code_id, $dimension_id, $amount, $reference<br>";
259 if ($description == null)
260 $this->description = get_gl_account_name($code_id);
262 $this->description = $description;
264 $this->index = $index;
265 $this->code_id = $code_id;
266 $this->dimension_id = $dimension_id;
267 $this->dimension2_id = $dimension2_id;
268 $this->amount = $amount;
269 $this->reference = $reference;
273 //---------------------------------------------------------------------------------------