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 $trans_type; // invoice, order, delivery note ...
26 var $memo_; // memo_ on direct invoicing
29 var $delivery_address;
37 var $order_no; // the original order number
38 var $trans_no;// transaction number
52 function Cart($type = 'order')
54 /*Constructor function initialises a new shopping cart */
55 $this->line_items = array();
56 $this->default_sales_type = "";
57 $this->trans_type = $type;
60 function add_to_cart($stock_id, $qty, $price, $disc, $qty_done=0, $standard_cost=0, $description=null, $id=0)
62 if (isset($stock_id) && $stock_id != "" && isset($qty)/* && $qty > 0*/)
64 $this->line_items[] = new line_details($stock_id, $qty, $price, $disc,
65 $qty_done, $standard_cost, $description, $id);
70 // shouldn't come here under normal circumstances
71 display_db_error("unexpected - adding an invalid item or null quantity", "", true);
76 function update_cart_item($line_no, $qty, $price, $disc)
81 $this->line_items[$line_no]->quantity = $qty;
83 $this->line_items[$line_no]->price = $price;
84 $this->line_items[$line_no]->discount_percent = $disc;
86 function update_add_cart_item_qty($line_no, $qty)
88 $this->line_items[$line_no]->quantity += $qty;
91 function remove_from_cart($line_no)
93 unset($this->line_items[$line_no]);
96 function clear_items()
98 unset($this->line_items);
99 $this->line_items = array();
100 $this->default_sales_type = "";
102 $this->customer_id = $this->order_no = 0;
105 function count_items()
108 foreach($this->line_items as $line) {
109 if($line->quantity>$line->qty_done) $counter++;
114 function get_items_total_dispatch($tax_group_id=null)
118 // preload the taxgroup !
119 if ($tax_group_id != null)
120 $tax_group_array = get_tax_group_items_as_array($tax_group_id);
122 $tax_group_array = null;
124 foreach ($this->line_items as $ln_itm)
126 $total += ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
131 function has_items_dispatch()
133 foreach ($this->line_items as $ln_itm)
135 if ($ln_itm->qty_dispatched > 0)
141 function get_items_total($tax_group_id=null)
145 // preload the taxgroup !
146 if ($tax_group_id != null)
147 $tax_group_array = get_tax_group_items_as_array($tax_group_id);
149 $tax_group_array = null;
151 foreach ($this->line_items as $ln_itm) {
152 $total += ($ln_itm->quantity * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
157 function any_already_delivered()
159 /* Checks if there have been deliveries of line items */
161 foreach ($this->line_items as $stock_item)
163 if ($stock_item->qty_done !=0)
173 function some_already_delivered($line_no)
175 /* Checks if there have been deliveries of a specific line item */
176 if (isset($this->line_items[$line_no]) &&
177 $this->line_items[$line_no]->qty_done != 0)
184 function get_taxes($tax_group_id=null, $shipping_cost=0)
189 if ($tax_group_id == null)
190 $tax_group_id = $this->tax_group_id;
192 // preload the taxgroup !
193 $tax_group_array = get_tax_group_items_as_array($tax_group_id);
195 foreach ($this->line_items as $ln_itm)
197 $items[] = $ln_itm->stock_id;
198 $prices[] = ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
202 $taxes = get_tax_for_items($items, $prices, $shipping_cost, $tax_group_id, $tax_group_array);
207 } /* end of class defintion */
214 var $item_description;
222 var $discount_percent;
223 var $qty_done; // quantity processed so far
224 var $qty_dispatched; // quantity selected to process
227 function line_details ($stock_id, $qty, $prc, $disc_percent,
228 $qty_done, $standard_cost, $description, $id=0)
230 /* Constructor function to add a new LineDetail object with passed params */
233 $item_row = get_item($stock_id);
235 if ($item_row == null)
236 display_db_error("invalid item added to order : $stock_id", "");
238 $this->mb_flag = $item_row["mb_flag"];
239 $this->units = $item_row["units"];
240 if ($description == null)
241 $this->item_description = $item_row["description"];
243 $this->item_description = $description;
244 //$this->standard_cost = $item_row["material_cost"] + $item_row["labour_cost"] + $item_row["overhead_cost"];
245 $this->tax_type = $item_row["tax_type_id"];
246 $this->tax_type_name = $item_row["tax_type_name"];
248 $this->stock_id = $stock_id;
249 $this->quantity = $qty;
251 $this->discount_percent = $disc_percent;
252 $this->qty_done = $qty_done;
253 $this->standard_cost = $standard_cost;
256 function full_price()
261 function taxfree_price($tax_group_id, $tax_group_array=null)
263 if ($tax_group_id==null)
265 return get_tax_free_price_for_item($this->stock_id, $this->price, $tax_group_id, $tax_group_array);