Fixed amounts displayed in header for customer/supplier bank payments.
}
//-----------------------------------------------------------------------------------------------
-if (isset($_POST['Process']))
+function check_trans()
{
+ global $Refs;
$input_error = 0;
if (!db_has_currency_rates(get_bank_account_currency($_POST['bank_account']), $_POST['date_'], true))
$input_error = 1;
- if ($input_error == 1)
- unset($_POST['Process']);
+ if (in_array(get_post('PayType'), array(PT_SUPPLIER, PT_CUSTOMER)) && (input_num('settled_amount') <= 0)) {
+ display_error(_("Settled amount have to be positive number."));
+ set_focus('person_id');
+ $input_error = 1;
+ }
+ return $input_error;
}
-if (isset($_POST['Process']))
+if (isset($_POST['Process']) && !check_trans())
{
begin_transaction();
// 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);
if ($person_curr != $bank_curr)
{
$_POST['settled_amount'] =
- price_format($order->gl_items_total() / get_exchange_rate_from_to($bank_curr, $person_curr, get_post('date_')));
+ price_format(abs($order->gl_items_total() / get_exchange_rate_from_to($bank_curr, $person_curr, get_post('date_'))));
amount_row($type == PT_CUSTOMER ? _("Settled AR Amount:") : _("Settled AP Amount:"),
'settled_amount', null, null, $person_curr, user_price_dec());
}
$sql = "SELECT ".TB_PREF."supp_trans.*, (".TB_PREF."supp_trans.ov_amount+".TB_PREF."supp_trans.ov_gst+".TB_PREF."supp_trans.ov_discount) AS Total,
".TB_PREF."suppliers.supp_name AS supplier_name, ".TB_PREF."suppliers.curr_code AS curr_code ";
- if ($trans_type == ST_SUPPAYMENT)
+ if ($trans_type == ST_SUPPAYMENT || $trans_type == ST_BANKPAYMENT)
{
// it's a payment so also get the bank account
$sql .= ", ".TB_PREF."bank_accounts.bank_name, ".TB_PREF."bank_accounts.bank_account_name, ".TB_PREF."bank_accounts.bank_curr_code,
$sql .= " FROM ".TB_PREF."supp_trans, ".TB_PREF."suppliers ";
- if ($trans_type == ST_SUPPAYMENT)
+ if ($trans_type == ST_SUPPAYMENT || $trans_type == ST_BANKPAYMENT)
{
// it's a payment so also get the bank account
$sql .= ", ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts";
if ($trans_type > 0)
$sql .= " AND ".TB_PREF."supp_trans.type=".db_escape($trans_type);
- if ($trans_type == ST_SUPPAYMENT)
+ if ($trans_type == ST_SUPPAYMENT || $trans_type == ST_BANKPAYMENT)
{
// it's a payment so also get the bank account
$sql .= " AND ".TB_PREF."bank_trans.trans_no =".db_escape($trans_no)."
."cust.tax_id, "
."com.memo_";
- if ($trans_type == ST_CUSTPAYMENT) {
+ if ($trans_type == ST_CUSTPAYMENT || $trans_type == ST_BANKDEPOSIT) {
// it's a payment so also get the bank account
// Chaitanya : Added bank_act to support Customer Payment Edit
$sql .= ",bank_act,".TB_PREF."bank_accounts.bank_name, ".TB_PREF."bank_accounts.bank_account_name,
LEFT JOIN ".TB_PREF."shippers ON ".TB_PREF."shippers.shipper_id=trans.ship_via,
".TB_PREF."debtors_master cust";
- if ($trans_type == ST_CUSTPAYMENT) {
+ if ($trans_type == ST_CUSTPAYMENT || $trans_type == ST_BANKDEPOSIT) {
// it's a payment so also get the bank account
$sql .= ", ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts";
}
AND trans.type=".db_escape($trans_type)."
AND trans.debtor_no=cust.debtor_no";
- if ($trans_type == ST_CUSTPAYMENT) {
+ if ($trans_type == ST_CUSTPAYMENT || $trans_type == ST_BANKDEPOSIT) {
// it's a payment so also get the bank account
$sql .= " AND ".TB_PREF."bank_trans.trans_no =".db_escape($trans_id)."
AND ".TB_PREF."bank_trans.type=$trans_type