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)
88 // ----------- GL item functions
90 function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
92 if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id) &&
93 isset($dimension2_id))
95 $this->gl_items[$this->gl_item_count] = new gl_item($this->gl_item_count,
96 $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description);
97 $this->gl_item_count++;
102 // shouldn't come here under normal circumstances
103 display_db_error("unexpected - adding an invalid item or null quantity", "", true);
109 function update_gl_item($index, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
111 $this->gl_items[$index]->index = $index;
112 $this->gl_items[$index]->dimension_id = $dimension_id;
113 $this->gl_items[$index]->dimension2_id = $dimension2_id;
114 $this->gl_items[$index]->amount = $amount;
115 $this->gl_items[$index]->reference = $reference;
116 if ($description != null)
117 $this->gl_items[$index]->description = $description;
121 function remove_gl_item($index)
125 unset($this->gl_items[$index]);
129 function count_gl_items()
131 return count($this->gl_items);
134 function gl_items_total()
137 foreach ($this->gl_items as $gl_item)
138 $total += $gl_item->amount;
142 function gl_items_total_debit()
145 foreach ($this->gl_items as $gl_item)
147 if ($gl_item->amount > 0)
148 $total += $gl_item->amount;
153 function gl_items_total_credit()
156 foreach ($this->gl_items as $gl_item)
158 if ($gl_item->amount < 0)
159 $total += $gl_item->amount;
164 // ------------ common functions
166 function clear_items()
168 unset($this->line_items);
169 $this->line_items = array();
171 unset($this->gl_items);
172 $this->gl_items = array();
173 $this->gl_item_count = 1;
178 //--------------------------------------------------------------------------------------------
183 var $item_description;
191 function line_item ($stock_id, $qty, $standard_cost=null, $description=null)
193 $item_row = get_item($stock_id);
195 if ($item_row == null)
196 display_db_error("invalid item added to order : $stock_id", "");
198 $this->mb_flag = $item_row["mb_flag"];
199 $this->units = $item_row["units"];
201 if ($description == null)
202 $this->item_description = $item_row["description"];
204 $this->item_description = $description;
206 if ($standard_cost == null)
207 $this->standard_cost = $item_row["actual_cost"];
209 $this->standard_cost = $standard_cost;
211 $this->stock_id = $stock_id;
212 $this->quantity = $qty;
213 //$this->price = $price;
217 function check_qoh($location, $date_, $reverse)
219 if (!sys_prefs::allow_negative_stock())
221 if (has_stock_holding($this->mb_flag))
223 $quantity = $this->quantity;
225 $quantity = -$this->quantity;
230 $qoh = get_qoh_on_date($this->stock_id, $location, $date_);
231 if ($quantity + $qoh < 0)
242 //---------------------------------------------------------------------------------------
255 function gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference,
258 //echo "adding $index, $code_id, $dimension_id, $amount, $reference<br>";
260 if ($description == null)
261 $this->description = get_gl_account_name($code_id);
263 $this->description = $description;
265 $this->index = $index;
266 $this->code_id = $code_id;
267 $this->dimension_id = $dimension_id;
268 $this->dimension2_id = $dimension2_id;
269 $this->amount = $amount;
270 $this->reference = $reference;
274 //---------------------------------------------------------------------------------------