var $order_id;
- var $editing_item, $deleting_item;
-
var $from_loc;
var $to_loc;
var $tran_date;
var $transfer_type;
var $increase;
var $memo_;
- var $person_id;
var $branch_id;
var $reference;
+ var $original_amount;
function items_cart($type)
{
return count($this->line_items);
}
+ /*
+ Checks cart quantities on document_date.
+ Returns array of stock_ids which stock quantities would go negative on some day.
+ */
function check_qoh($location, $date_, $reverse=false)
{
+ $low_stock = array();
+
+ // collect quantities by stock_id
+ $qtys = array();
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;
+ $qty = $reverse ? -$line_item->quantity : $line_item->quantity;
+
+ $qtys[$line_item->stock_id]['qty'] = $qty + @$qtys[$line_item->stock_id]['qty'];
+ $qtys[$line_item->stock_id]['line'] = $line_no;
}
- return -1;
+
+ foreach($qtys as $stock_id => $sum)
+ {
+ $fail = check_negative_stock($stock_id, $sum['qty'], $location, $date_);
+ if ($fail)
+ $low_stock[] = $stock_id;
+ }
+
+ return $low_stock;
}
// ----------- GL item functions
- function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
+ function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null, $person_id=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, $reference, $description);
+ $this->gl_items[] = new gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description, $person_id);
return true;
}
else
return false;
}
- function update_gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
+ function update_gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null, $person_id=null)
{
$this->gl_items[$index]->code_id = $code_id;
+ $this->gl_items[$index]->person_id = $person_id;
+
+ $gl_type = is_subledger_account($code_id, $person_id);
+ if ($gl_type)
+ {
+ $this->gl_items[$index]->person_type_id = $gl_type > 0 ? PT_CUSTOMER : PT_SUPPLIER;
+ $this->gl_items[$index]->person_name = get_subaccount_name($code_id, $person_id);
+ } else
+ {
+ $this->gl_items[$index]->person_type_id = $this->gl_items[$index]->person_name = '';
+ }
$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 = array();
}
+ //
+ // Check if cart contains virtual subaccount (AP/AR) postings
+ //
+ function has_sub_accounts()
+ {
+ foreach ($this->gl_items as $gl_item)
+ {
+ if ($gl_item->person_id)
+ return true;
+ }
+ return false;
+ }
}
//--------------------------------------------------------------------------------------------
$this->price = 0;
}
+ /*
+ This method is generally obsolete and subject to removal in FA 2.4 (preserved for now to support 2.3 extensions).
+ Use items_cart::check_qoh instead.
+ */
function check_qoh($location, $date_, $reverse)
{
global $SysPrefs;
-
+
if (!$SysPrefs->allow_negative_stock())
{
if (has_stock_holding($this->mb_flag))
if ($quantity >= 0)
return null;
- $qoh = get_qoh_on_date($this->stock_id, $location, $date_);
- if ($quantity + $qoh < 0)
- {
- return $this;
- }
+ $fail = check_negative_stock($this->stock_id, $quantity, $location, $date_);
+ if ($fail)
+ return $this;
}
}
var $amount;
var $reference;
var $description;
+ var $person_id;
+ var $person_type_id;
+ var $person_name;
function gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference,
- $description=null)
+ $description=null, $person_id=null)
{
//echo "adding $index, $code_id, $dimension_id, $amount, $reference<br>";
$this->description = $description;
$this->code_id = $code_id;
+ $this->person_id = $person_id;
+ $gl_type = is_subledger_account($code_id, $person_id);
+ if ($gl_type)
+ {
+ $this->person_type_id = $gl_type > 0 ? PT_CUSTOMER : PT_SUPPLIER;
+ $this->person_name = get_subaccount_name($code_id, $person_id);
+ }
$this->dimension_id = $dimension_id;
$this->dimension2_id = $dimension2_id;
$this->amount = $amount;
//---------------------------------------------------------------------------------------
-?>