X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fui%2Fitems_cart.inc;h=a5e15fdbf4a524d1c7ded60d06f48ed4b6a75372;hb=76ca9fef9bb510236a6a7740fa0f60eb7db384c9;hp=fb4b71ab86faad4f4a1114590d91a7ecaef9f332;hpb=c2d8171259968d683568f3a5915b541f075fd194;p=fa-stable.git diff --git a/includes/ui/items_cart.inc b/includes/ui/items_cart.inc index fb4b71ab..a5e15fdb 100644 --- a/includes/ui/items_cart.inc +++ b/includes/ui/items_cart.inc @@ -1,20 +1,25 @@ . +***********************************************************************/ +include_once($path_to_root . "/includes/prefs/sysprefs.inc"); include_once($path_to_root . "/inventory/includes/inventory_db.inc"); -class items_cart +class items_cart { - + var $trans_type; var $line_items; var $gl_items; - var $gl_item_count; - var $order_id; - var $editing_item, $deleting_item; - var $from_loc; var $to_loc; var $tran_date; @@ -23,28 +28,30 @@ class items_cart var $memo_; var $person_id; var $branch_id; - - function items_cart() + var $reference; + var $original_amount; + + function items_cart($type) { + $this->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); + display_error("unexpected - adding an invalid item or null quantity", "", true); } return false; @@ -52,92 +59,84 @@ 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(); - } + array_splice($this->line_items, $line_no, 1); } - 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; } + return -1; } // ----------- GL item functions 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, - $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description); - $this->gl_item_count++; - $this->clear_editing_flags(); + $this->gl_items[] = new gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description); return true; - } - else + } + else { // shouldn't come here under normal circumstances - display_db_error("unexpected - adding an invalid item or null quantity", "", true); + display_error("unexpected - invalid parameters in add_gl_item($code_id, $dimension_id, $dimension2_id, $amount,...)", "", true); } return false; } - function update_gl_item($index, $dimension_id, $dimension2_id, $amount, $reference, $description=null) + function update_gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null) { - $this->gl_items[$index]->index = $index; + $this->gl_items[$index]->code_id = $code_id; $this->gl_items[$index]->dimension_id = $dimension_id; $this->gl_items[$index]->dimension2_id = $dimension2_id; $this->gl_items[$index]->amount = $amount; $this->gl_items[$index]->reference = $reference; - if ($description != null) + if ($description == null) + $this->gl_items[$index]->description = get_gl_account_name($code_id); + else $this->gl_items[$index]->description = $description; - $this->clear_editing_flags(); } function remove_gl_item($index) { - if (isset($index)) - { - unset($this->gl_items[$index]); - $this->clear_editing_flags(); - } + array_splice($this->gl_items, $index, 1); } - 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 +144,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 +155,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,48 +168,20 @@ class items_cart // ------------ common functions - function clear_items() + function clear_items() { unset($this->line_items); $this->line_items = array(); unset($this->gl_items); $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; @@ -226,7 +197,7 @@ class line_item $item_row = get_item($stock_id); if ($item_row == null) - display_db_error("invalid item added to order : $stock_id", ""); + display_error("invalid item added to order : $stock_id", ""); $this->mb_flag = $item_row["mb_flag"]; $this->units = $item_row["units"]; @@ -249,7 +220,9 @@ class line_item function check_qoh($location, $date_, $reverse) { - if (!sys_prefs::allow_negative_stock()) + global $SysPrefs; + + if (!$SysPrefs->allow_negative_stock()) { if (has_stock_holding($this->mb_flag)) { @@ -261,7 +234,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,10 +247,9 @@ class line_item //--------------------------------------------------------------------------------------- -class gl_item +class gl_item { - var $index; var $code_id; var $dimension_id; var $dimension2_id; @@ -285,7 +257,7 @@ class gl_item var $reference; var $description; - function gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference, + function gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null) { //echo "adding $index, $code_id, $dimension_id, $amount, $reference
"; @@ -295,7 +267,6 @@ class gl_item else $this->description = $description; - $this->index = $index; $this->code_id = $code_id; $this->dimension_id = $dimension_id; $this->dimension2_id = $dimension2_id;