line_items = array(); $this->default_sales_type = ""; $this->direct_invoice=false; $this->lines_on_order = 0; } function add_to_cart($line_no, $id, $stock_id, $qty, $price, $disc, $qty_invoiced=0, $standard_cost=0, $description=null) { if (isset($stock_id) && $stock_id != "" && isset($qty) && $qty > 0) { $this->line_items[$line_no] = new line_details($line_no, $id, $stock_id, $qty, $price, $disc, $qty_invoiced, $standard_cost, $description); $this->lines_on_order++; return 1; } else { // shouldn't come here under normal circumstances display_db_error("unexpected - adding an invalid item or null quantity", "", true); } return 0; } function update_cart_item($line_no, $qty, $price, $disc) { if ($qty > 0) { $this->line_items[$line_no]->quantity = $qty; } $this->line_items[$line_no]->price = $price; $this->line_items[$line_no]->discount_percent = $disc; } function update_add_cart_item_qty($line_no, $qty) { $this->line_items[$line_no]->quantity += $qty; } function remove_from_cart($line_no) { $this->line_items[$line_no]->Deleted = true; } function clear_items() { unset($this->line_items); $this->line_items = array(); $this->default_sales_type = ""; $this->customer_id = $this->order_no = 0; $this->lines_on_order = 0; } function count_items() { return count($this->line_items); } function get_items_total_dispatch($tax_group_id=null) { $total = 0; // preload the taxgroup ! if ($tax_group_id != null) $tax_group_array = get_tax_group_items_as_array($tax_group_id); else $tax_group_array = null; foreach ($this->line_items as $ln_itm) { $total += ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent)); } return $total; } function has_items_dispatch() { foreach ($this->line_items as $ln_itm) { if ($ln_itm->qty_dispatched > 0) return true; } return false; } function get_items_total($tax_group_id=null) { $total = 0; // preload the taxgroup ! if ($tax_group_id != null) $tax_group_array = get_tax_group_items_as_array($tax_group_id); else $tax_group_array = null; foreach ($this->line_items as $ln_itm) { $total += ($ln_itm->quantity * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent)); } return $total; } function any_already_delivered() { /* Checks if there have been deliveries of line items */ foreach ($this->line_items as $stock_item) { if ($stock_item->qty_inv !=0) { return 1; } } return 0; } function some_already_delivered($line_no) { /* Checks if there have been deliveries of a specific line item */ if (isset($this->line_items[$line_no]) && $this->line_items[$line_no]->qty_inv != 0) { return 1; } return 0; } function get_taxes($tax_group_id=null, $shipping_cost=0) { $items = array(); $prices = array(); if ($tax_group_id == null) $tax_group_id = $this->tax_group_id; // preload the taxgroup ! $tax_group_array = get_tax_group_items_as_array($tax_group_id); foreach ($this->line_items as $ln_itm) { if (!$ln_itm->Deleted) { $items[] = $ln_itm->stock_id; $prices[] = ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent)); } } $taxes = get_tax_for_items($items, $prices, $shipping_cost, $tax_group_id, $tax_group_array); return $taxes; } } /* end of class defintion */ class line_details { var $line_no; var $id; var $stock_id; var $item_description; var $units; var $mb_flag; var $tax_type; var $tax_type_name; var $quantity; var $price; var $discount_percent; var $qty_inv; var $qty_dispatched; var $standard_cost; var $Deleted; function line_details ($line_no, $id, $stock_id, $qty, $prc, $disc_percent, $qty_invoiced, $standard_cost, $description) { /* Constructor function to add a new LineDetail object with passed params */ $this->line_no = $line_no; $this->id = $id; $item_row = get_item($stock_id); if ($item_row == null) display_db_error("invalid item added to order : $stock_id", ""); $this->mb_flag = $item_row["mb_flag"]; $this->units = $item_row["units"]; if ($description == null) $this->item_description = $item_row["description"]; else $this->item_description = $description; //$this->standard_cost = $item_row["material_cost"] + $item_row["labour_cost"] + $item_row["overhead_cost"]; $this->tax_type = $item_row["tax_type_id"]; $this->tax_type_name = $item_row["tax_type_name"]; $this->stock_id = $stock_id; $this->quantity = $qty; $this->price = $prc; $this->discount_percent = $disc_percent; $this->qty_inv = $qty_invoiced; $this->qty_dispatched = $qty - $qty_invoiced; $this->standard_cost = $standard_cost; $this->Deleted = false; } function full_price() { return $this->price; } function taxfree_price($tax_group_id, $tax_group_array=null) { if ($tax_group_id==null) return $this->price; return get_tax_free_price_for_item($this->stock_id, $this->price, $tax_group_id, $tax_group_array); } } ?>