3 /* Definition of the cart class
4 this class can hold all the information for:
12 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
13 include_once($path_to_root . "/taxes/tax_calc.inc");
18 var $line_items; /*array of objects of class line_details using the product id as the pointer */
21 var $default_sales_type; // set to the customer's sales type
22 var $sales_type_name; // set to customer's sales type name
23 var $customer_currency; // set to the customer's currency
24 var $default_discount; // set to the customer's discount %
25 var $direct_invoice; // direct invoicing
26 var $memo_; // memo_ on direct invoicing
29 var $delivery_address;
38 var $order_no; // the order number
54 /*Constructor function initialises a new shopping cart */
55 $this->line_items = array();
56 $this->default_sales_type = "";
57 $this->direct_invoice=false;
60 function add_to_cart($stock_id, $qty, $price, $disc, $qty_invoiced=0, $standard_cost=0, $description=null)
63 if (isset($stock_id) && $stock_id != "" && isset($qty) && $qty > 0)
66 $this->line_items[$stock_id] = new line_details($stock_id, $qty, $price, $disc,
67 $qty_invoiced, $standard_cost, $description);
72 // shouldn't come here under normal circumstances
73 display_db_error("unexpected - adding an invalid item or null quantity", "", true);
78 function find_cart_item($stock_id)
80 if (isset($this->line_items[$stock_id]) && $this->line_items[$stock_id] != null)
81 return $this->line_items[$stock_id];
85 function update_cart_item($update_item, $qty, $price, $disc)
90 $this->line_items[$update_item]->quantity = $qty;
92 $this->line_items[$update_item]->price = $price;
93 $this->line_items[$update_item]->discount_percent = $disc;
96 function update_add_cart_item_qty($update_item, $qty)
98 $this->line_items[$update_item]->quantity += $qty;
101 function remove_from_cart(&$stock_id)
103 if (isset($stock_id))
105 unset($this->line_items[$stock_id]);
109 function clear_items()
111 unset($this->line_items);
112 $this->line_items = array();
113 $this->default_sales_type = "";
114 $this->customer_id = $this->order_no = 0;
117 function count_items()
119 return count($this->line_items);
122 function get_items_total_dispatch($tax_group_id=null)
126 // preload the taxgroup !
127 if ($tax_group_id != null)
128 $tax_group_array = get_tax_group_items_as_array($tax_group_id);
130 $tax_group_array = null;
132 foreach ($this->line_items as $ln_itm)
134 $total += ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
139 function has_items_dispatch()
141 foreach ($this->line_items as $ln_itm)
143 if ($ln_itm->qty_dispatched > 0)
149 function get_items_total($tax_group_id=null)
153 // preload the taxgroup !
154 if ($tax_group_id != null)
155 $tax_group_array = get_tax_group_items_as_array($tax_group_id);
157 $tax_group_array = null;
159 foreach ($this->line_items as $ln_itm) {
160 $total += ($ln_itm->quantity * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
165 function any_already_delivered()
167 /* Checks if there have been deliveries of line items */
169 foreach ($this->line_items as $stock_item)
171 if ($stock_item->qty_inv !=0)
181 function some_already_delivered($stock_id)
183 /* Checks if there have been deliveries of a specific line item */
184 if (isset($stock_id) && isset($this->line_items[$stock_id]) &&
185 $this->line_items[$stock_id]->qty_inv != 0)
192 function get_taxes($tax_group_id=null, $shipping_cost=0)
197 if ($tax_group_id == null)
198 $tax_group_id = $this->tax_group_id;
200 // preload the taxgroup !
201 $tax_group_array = get_tax_group_items_as_array($tax_group_id);
203 foreach ($this->line_items as $ln_itm)
205 $items[] = $ln_itm->stock_id;
206 $prices[] = ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
210 $taxes = get_tax_for_items($items, $prices, $shipping_cost, $tax_group_id, $tax_group_array);
215 } /* end of class defintion */
220 var $item_description;
228 var $discount_percent;
233 function line_details ($stock_id, $qty, $prc, $disc_percent,
234 $qty_invoiced, $standard_cost, $description)
236 /* Constructor function to add a new LineDetail object with passed params */
237 $item_row = get_item($stock_id);
239 if ($item_row == null)
240 display_db_error("invalid item added to order : $stock_id", "");
242 $this->mb_flag = $item_row["mb_flag"];
243 $this->units = $item_row["units"];
244 if ($description == null)
245 $this->item_description = $item_row["description"];
247 $this->item_description = $description;
248 //$this->standard_cost = $item_row["material_cost"] + $item_row["labour_cost"] + $item_row["overhead_cost"];
249 $this->tax_type = $item_row["tax_type_id"];
250 $this->tax_type_name = $item_row["tax_type_name"];
252 $this->stock_id = $stock_id;
253 $this->quantity = $qty;
255 $this->discount_percent = $disc_percent;
256 $this->qty_inv = $qty_invoiced;
257 $this->qty_dispatched = $qty - $qty_invoiced;
258 $this->standard_cost = $standard_cost;
261 function full_price()
266 function taxfree_price($tax_group_id, $tax_group_array=null)
268 if ($tax_group_id==null)
270 return get_tax_free_price_for_item($this->stock_id, $this->price, $tax_group_id, $tax_group_array);