X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fui%2Fitems_cart.inc;h=fb2ac021694058ed01d676935ebb70fe15951122;hb=e69cba03db9c0f74d3febcdc9014e81aafa5914e;hp=fb4b71ab86faad4f4a1114590d91a7ecaef9f332;hpb=c2d8171259968d683568f3a5915b541f075fd194;p=fa-stable.git diff --git a/includes/ui/items_cart.inc b/includes/ui/items_cart.inc index fb4b71ab..fb2ac021 100644 --- a/includes/ui/items_cart.inc +++ b/includes/ui/items_cart.inc @@ -1,11 +1,11 @@ trans_type = $type; $this->clear_items(); } // --------------- line item functions - function add_to_cart($stock_id, $qty, $standard_cost, $description=null) + function add_to_cart($line_no, $stock_id, $qty, $standard_cost, $description=null) { if (isset($stock_id) && $stock_id != "" && isset($qty)) { - $this->line_items[$stock_id] = new line_item($stock_id, $qty, + $this->line_items[$line_no] = new line_item($stock_id, $qty, $standard_cost, $description); - $this->clear_editing_flags(); return true; - } - else + } + else { // shouldn't come here under normal circumstances display_db_error("unexpected - adding an invalid item or null quantity", "", true); @@ -52,39 +52,36 @@ class items_cart function find_cart_item($stock_id) { - if (isset($this->line_items[$stock_id]) && $this->line_items[$stock_id] != null) - return $this->line_items[$stock_id]; + foreach($this->line_items as $line_no=>$line) { + if ($line->stock_id == $stock_id) + return $this->line_items[$line_no]; + } return null; } - function update_cart_item($update_item, $qty, $standard_cost) + function update_cart_item($line_no, $qty, $standard_cost) { - $this->line_items[$update_item]->quantity = $qty; - $this->line_items[$update_item]->standard_cost = $standard_cost; - $this->clear_editing_flags(); + $this->line_items[$line_no]->quantity = $qty; + $this->line_items[$line_no]->standard_cost = $standard_cost; } - function remove_from_cart(&$stock_id) + function remove_from_cart($line_no) { - if (isset($stock_id)) - { - unset($this->line_items[$stock_id]); - $this->clear_editing_flags(); - } + unset($this->line_items[$line_no]); } - function count_items() + function count_items() { return count($this->line_items); } function check_qoh($location, $date_, $reverse=false) { - foreach ($this->line_items as $line_item) + foreach ($this->line_items as $line_no => $line_item) { $item_ret = $line_item->check_qoh($location, $date_, $reverse); if ($item_ret != null) - return $line_item; + return $line_no; } } @@ -92,16 +89,15 @@ class items_cart function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null) { - if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id) && + if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id) && isset($dimension2_id)) { - $this->gl_items[$this->gl_item_count] = new gl_item($this->gl_item_count, + $this->gl_items[$this->gl_item_count] = new gl_item($this->gl_item_count, $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description); $this->gl_item_count++; - $this->clear_editing_flags(); return true; - } - else + } + else { // shouldn't come here under normal circumstances display_db_error("unexpected - adding an invalid item or null quantity", "", true); @@ -120,7 +116,6 @@ class items_cart if ($description != null) $this->gl_items[$index]->description = $description; - $this->clear_editing_flags(); } function remove_gl_item($index) @@ -128,16 +123,15 @@ class items_cart if (isset($index)) { unset($this->gl_items[$index]); - $this->clear_editing_flags(); } } - function count_gl_items() + function count_gl_items() { return count($this->gl_items); } - function gl_items_total() + function gl_items_total() { $total = 0; foreach ($this->gl_items as $gl_item) @@ -145,10 +139,10 @@ class items_cart return $total; } - function gl_items_total_debit() + function gl_items_total_debit() { $total = 0; - foreach ($this->gl_items as $gl_item) + foreach ($this->gl_items as $gl_item) { if ($gl_item->amount > 0) $total += $gl_item->amount; @@ -156,10 +150,10 @@ class items_cart return $total; } - function gl_items_total_credit() + function gl_items_total_credit() { $total = 0; - foreach ($this->gl_items as $gl_item) + foreach ($this->gl_items as $gl_item) { if ($gl_item->amount < 0) $total += $gl_item->amount; @@ -169,7 +163,7 @@ class items_cart // ------------ common functions - function clear_items() + function clear_items() { unset($this->line_items); $this->line_items = array(); @@ -178,39 +172,12 @@ class items_cart $this->gl_items = array(); $this->gl_item_count = 1; - $this->clear_editing_flags(); - } - - function clear_editing_flags() - { - $this->editing_item = $this->deleting_item = 0; } - - function get_editing_item() - { - return $this->editing_item; - } - - function get_deleting_item() - { - return $this->deleting_item; - } - - function is_editing_item($index) - { - return ($this->editing_item > 0) && ($this->editing_item == $index); - } - - function is_deleting_item($index) - { - return ($this->deleting_item > 0) && ($this->deleting_item == $index); - } - } //-------------------------------------------------------------------------------------------- -class line_item +class line_item { var $stock_id; var $item_description; @@ -261,7 +228,7 @@ class line_item return null; $qoh = get_qoh_on_date($this->stock_id, $location, $date_); - if ($quantity + $qoh < 0) + if ($quantity + $qoh < 0) { return $this; } @@ -274,7 +241,7 @@ class line_item //--------------------------------------------------------------------------------------- -class gl_item +class gl_item { var $index; @@ -285,7 +252,7 @@ class gl_item var $reference; var $description; - function gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference, + function gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null) { //echo "adding $index, $code_id, $dimension_id, $amount, $reference
";