X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fui%2Fitems_cart.inc;h=9d7781deec929f42ff7b730b24e2335b5373c165;hb=6bcd87642330092910f5d6977845a76ac59350ac;hp=e149865f651fd9ded3b6bd6f01a308a354e27032;hpb=3b431d909abc53e4a4d712cbafa39ca556409d0e;p=fa-stable.git diff --git a/includes/ui/items_cart.inc b/includes/ui/items_cart.inc index e149865f..9d7781de 100644 --- a/includes/ui/items_cart.inc +++ b/includes/ui/items_cart.inc @@ -38,7 +38,9 @@ class items_cart var $tax_info; // tax info for the GL transaction - function items_cart($type, $trans_no=0) + var $fixed_asset; + + function __construct($type, $trans_no=0) { $this->trans_type = $type; $this->order_id = $trans_no; @@ -95,23 +97,37 @@ class items_cart function check_qoh($location, $date_, $reverse=false) { - foreach ($this->line_items as $line_no => $line_item) - { - $item_ret = $line_item->check_qoh($location, $date_, $reverse); - if ($item_ret != null) - return $line_no; + global $SysPrefs; + + $low_stock = array(); + + if (!$SysPrefs->allow_negative_stock() || is_fixed_asset($line_item->mb_flag)) + { + foreach ($this->line_items as $line_no => $line_item) + if (has_stock_holding($line_item->mb_flag) || is_fixed_asset($line_item->mb_flag)) + { + $quantity = $line_item->quantity; + if ($reverse) + $quantity = -$line_item->quantity; + + if ($quantity >= 0) + continue; + + if (check_negative_stock($line_item->stock_id, $quantity, $location, $date_)) + $low_stock[] = $line_item->stock_id; + } } - return -1; + return $low_stock; } // ----------- GL item functions - function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $memo='', $act_descr=null, $person_id=null) + function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $memo='', $act_descr=null, $person_id=null, $date=null) { if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id) && isset($dimension2_id)) { - $this->gl_items[] = new gl_item($code_id, $dimension_id, $dimension2_id, $amount, $memo, $act_descr, $person_id); + $this->gl_items[] = new gl_item($code_id, $dimension_id, $dimension2_id, $amount, $memo, $act_descr, $person_id, $date); return true; } else @@ -208,7 +224,7 @@ class items_cart { foreach ($this->gl_items as $gl_item) { - if ($gl_item->person_id) + if (is_subledger_account($gl_item->code_id)) return true; } return false; @@ -293,7 +309,7 @@ class items_cart if (!isset($tax_info['tax_reg']) && isset($tax_info['person_type'])) $tax_info['tax_reg'] = $tax_info['person_type']==PT_CUSTOMER ? TR_OUTPUT : TR_INPUT; - if (count(@$tax_info['net_amount'])) // guess exempt sales/purchase if any tax has been found + if (count_array(@$tax_info['net_amount'])) // guess exempt sales/purchase if any tax has been found { $ex_net = abs($net_sum) - @array_sum($tax_info['net_amount']); if ($ex_net != 0) @@ -347,7 +363,10 @@ class items_cart $total_gl = 0; foreach($this->gl_items as $gl) { - $total_gl += add_gl_trans($this->trans_type, $this->order_id, $this->tran_date, $gl->code_id, $gl->dimension_id, $gl->dimension2_id, + if (!isset($gl->date)) + $gl->date = $this->tran_date; + + $total_gl += add_gl_trans($this->trans_type, $this->order_id, $gl->date, $gl->code_id, $gl->dimension_id, $gl->dimension2_id, $gl->reference, $gl->amount, $this->currency, $gl->person_type_id, $gl->person_id, "", $this->rate); // post to first found bank account using given gl acount code. @@ -365,8 +384,7 @@ class items_cart // do not post exchange variations to AR/AP (journal in not customer/supplier currency) if ($gl->person_type_id==PT_SUPPLIER && (get_supplier_currency($gl->person_id) == $this->currency || $this->currency != $home_currency)) $supp_trans[$gl->person_id] = @$supp_trans[$gl->person_id] + $gl->amount; - else - if ($gl->person_type_id==PT_CUSTOMER && (get_customer_currency(null, $gl->branch_id) == $this->currency || $this->currency != $home_currency)) + elseif ($gl->person_type_id==PT_CUSTOMER && (get_customer_currency(null, $gl->branch_id) == $this->currency || $this->currency != $home_currency)) $cust_trans[$gl->branch_id] = @$cust_trans[$gl->branch_id] + $gl->amount; } @@ -389,7 +407,7 @@ class items_cart foreach($cust_trans as $branch_id => $amount) if (floatcmp($amount, 0)) write_cust_journal($this->trans_type, $this->order_id, $branch_id, $this->tran_date, - $this->reference, -$amount, $this->rate); + $this->reference, $amount, $this->rate); // update AP foreach($supp_trans as $supp_id => $amount) if (floatcmp($amount, 0)) @@ -428,10 +446,7 @@ class items_cart add_trans_tax_details($this->trans_type, $this->order_id, $tax_id, $this->tax_info['rate'][$tax_id], 0, $tax_nominal, $net, $this->rate, $this->tran_date, - $this->source_ref, - $this->tax_info['tax_group'], - $this->tax_info['tax_date'], - $tax, $this->tax_info['tax_category'], 0, $reg); + $this->source_ref, $reg); } } } @@ -450,7 +465,7 @@ class line_item var $price; var $standard_cost; - function line_item ($stock_id, $qty, $standard_cost=null, $description=null) + function __construct($stock_id, $qty, $standard_cost=null, $description=null) { $item_row = get_item($stock_id); @@ -466,7 +481,7 @@ class line_item $this->item_description = $description; if ($standard_cost == null) - $this->standard_cost = $item_row["actual_cost"]; + $this->standard_cost = $item_row["purchase_cost"]; else $this->standard_cost = $standard_cost; @@ -475,32 +490,6 @@ class line_item //$this->price = $price; $this->price = 0; } - - function check_qoh($location, $date_, $reverse) - { - global $SysPrefs; - - if (!$SysPrefs->allow_negative_stock()) - { - if (has_stock_holding($this->mb_flag)) - { - $quantity = $this->quantity; - if ($reverse) - $quantity = -$this->quantity; - - if ($quantity >= 0) - return null; - - $qoh = get_qoh_on_date($this->stock_id, $location, $date_); - if ($quantity + $qoh < 0) - { - return $this; - } - } - } - - return null; - } } //--------------------------------------------------------------------------------------- @@ -518,9 +507,10 @@ class gl_item var $person_type_id; var $person_name; var $branch_id; + var $date; - function gl_item($code_id=null, $dimension_id=0, $dimension2_id=0, $amount=0, $memo='', - $act_descr=null, $person_id=null) + function __construct($code_id=null, $dimension_id=0, $dimension2_id=0, $amount=0, $memo='', + $act_descr=null, $person_id=null, $date=null) { //echo "adding $index, $code_id, $dimension_id, $amount, $reference
"; @@ -543,5 +533,6 @@ class gl_item $this->dimension2_id = $dimension2_id; $this->amount = round($amount, 2); $this->reference = $memo; + $this->date = $date; } }