// Add bank payment or deposit to database.
//
// $from_account - bank account id
-// $item - transaction cart (line item's amounts in bank account's currency)
+// $items - transaction cart (line amounts in bank account's currency); negative for deposit
// $person_type_id - defines type of $person_id identifiers
// $person_id - supplier/customer/other id
-// $person_detail_id - customer branch id or not used
+// $person_detail_id - customer branch id or not used
+// $settled_amount - settled amount in AR/AP (if applicable) in customer/supplier currency (always non-negative number)
//
// returns an array of (inserted trans type, trans no)
//
if ($person_type_id == PT_CUSTOMER)
{
// we need to add a customer transaction record
-
// convert to customer currency
if (!isset($settled_amount)) // leaved for backward/ext compatibility
- $cust_amount = exchange_from_to($total_amount, $currency, get_customer_currency($person_id), $date_);
+ $cust_amount = exchange_from_to(abs($total_amount), $currency, get_customer_currency($person_id), $date_);
else
$cust_amount = $settled_amount;
- // we need to negate it too
- $cust_amount = -$cust_amount;
+
+ if ($trans_type == ST_BANKPAYMENT)
+ $cust_amount = -$cust_amount;
$trans_no = write_customer_trans($trans_type, 0, $person_id, $person_detail_id, $date_,
$ref, $cust_amount);
// we need to add a supplier transaction record
// convert to supp currency
if (!isset($settled_amount)) // leaved for for backward/ext compatibility
- $supp_amount = exchange_from_to($total_amount, $currency, get_supplier_currency($person_id), $date_);
+ $supp_amount = exchange_from_to(abs($total_amount), $currency, get_supplier_currency($person_id), $date_);
else
$supp_amount = $settled_amount;
- // we need to negate it too
- $supp_amount = -$supp_amount;
+ if ($trans_type == ST_BANKPAYMENT)
+ $supp_amount = -$supp_amount;
$trans_no = write_supp_trans($trans_type, 0, $person_id, $date_, '',
$ref, "", $supp_amount, 0, 0);