// if $currency is not set, then defaults to no conversion
function add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension2, $memo_,
- $amount, $currency=null, $person_type_id=null, $person_id=null, $err_msg="")
+ $amount, $currency=null, $person_type_id=null, $person_id=null, $err_msg="", $rate=0)
{
global $use_audit_trail;
$date = date2sql($date_);
if ($currency != null)
- $amount_in_home_currency = to_home_currency($amount, $currency, $date_);
+ {
+ if ($rate == 0)
+ $amount_in_home_currency = to_home_currency($amount, $currency, $date_);
+ else
+ $amount_in_home_currency = round($amount * $rate, user_price_dec());
+ }
else
$amount_in_home_currency = $amount;
if ($dimension == null || $dimension < 0)
if ($person_type == payment_person_types::customer())
{
$trans = get_customer_trans($trans_no, $type);
+ $pyt_trans = get_customer_trans($pyt_no, $pyt_type);
$ar_ap_act = $trans['receivables_account'];
$person_id = $trans['debtor_no'];
$curr = $trans['curr_code'];
else
{
$trans = get_supp_trans($trans_no, $type);
+ $pyt_trans = get_supp_trans($pyt_no, $pyt_type);
$supp_accs = get_supplier_accounts($trans['supplier_id']);
$ar_ap_act = $supp_accs['payable_account'];
$person_id = $trans['supplier_id'];
}
if (is_company_currency($curr))
return;
- $exc_var_act = get_company_pref('exchange_diff_act');
- $inv_amt = to_home_currency($amount, $curr, sql2date($trans['tran_date']));
- $pay_amt = to_home_currency($amount, $curr, $pyt_date);
+ $inv_amt = round($amount * $trans['rate'], user_price_dec());
+ $pay_amt = round($amount * $pyt_trans['rate'], user_price_dec());
if ($inv_amt != $pay_amt)
{
$diff = $inv_amt - $pay_amt;
$diff = -$diff;
if ($neg)
$diff = -$diff;
+ $exc_var_act = get_company_pref('exchange_diff_act');
$memo = systypes::name($type)." ".$trans_no;
add_gl_trans($pyt_type, $pyt_no, $pyt_date, $ar_ap_act, 0, 0, $memo, -$diff, null, $person_type, $person_id);
add_gl_trans($pyt_type, $pyt_no, $pyt_date, $exc_var_act, 0, 0, $memo, $diff, null, $person_type, $person_id);
// When there is no exrate for today,
// gets it form ECB and stores in local database.
//
-function exchange_rate_display($from_currency, $to_currency, $date_)
+function exchange_rate_display($from_currency, $to_currency, $date_, $edit_rate=false)
{
global $Ajax;
}
}
if (!$rate)
- $rate = get_exchange_rate_from_to($to_currency, $from_currency, $date_);
-
- if ($from_currency == $comp_currency)
- $rate = 1 / $rate;
+ $rate = get_exchange_rate_from_home_currency($currency, $date_);
+ if ($from_currency != $comp_currency)
+ $rate = 1 / ($rate / get_exchange_rate_from_home_currency($to_currency, $date_));
$rate = number_format2($rate, user_exrate_dec());
- label_row(_("Exchange Rate:"),"1 " . $from_currency
- . " = <span id='_ex_rate'>" . $rate . "</span> " . $to_currency );
- $Ajax->addUpdate('_ex_rate','_ex_rate', $rate);
+ if ($edit_rate)
+ text_row(_("Exchange Rate:"), '_ex_rate', $rate, 8, 8, null, "", " $from_currency = 1 $to_currency");
+ else
+ label_row(_("Exchange Rate:"),"<span id='_ex_rate'>$rate</span> $from_currency = 1 $to_currency" );
+ $Ajax->addUpdate('_ex_rate','_ex_rate', $rate);
}
}
<?php
function add_supp_payment($supplier_id, $date_, $payment_type, $bank_account,
- $amount, $discount, $ref, $memo_)
+ $amount, $discount, $ref, $memo_, $rate=0)
{
begin_transaction();
$supplier_currency = get_supplier_currency($supplier_id);
$bank_account_currency = get_bank_account_currency($bank_account);
- $supp_amount = exchange_from_to($amount, $bank_account_currency, $supplier_currency, $date_);
- $supp_discount = exchange_from_to($discount, $bank_account_currency, $supplier_currency, $date_);
+ if ($rate == 0)
+ {
+ $supp_amount = exchange_from_to($amount, $bank_account_currency, $supplier_currency, $date_);
+ $supp_discount = exchange_from_to($discount, $bank_account_currency, $supplier_currency, $date_);
+ }
+ else
+ {
+ $supp_amount = $amount / $rate;
+ $supp_discount = $discount / $rate;
+ }
+
// it's a supplier payment
$trans_type = 22;
/* Create a supp_trans entry for the supplier payment */
$payment_id = add_supp_trans($trans_type, $supplier_id, $date_, $date_,
- $ref, "", -$supp_amount, 0, -$supp_discount);
+ $ref, "", -$supp_amount, 0, -$supp_discount, "", $rate);
// Now debit creditors account with payment + discount
$supplier_accounts = get_supplier_accounts($supplier_id);
add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0,
- $supp_amount + $supp_discount, $supplier_id);
+ $supp_amount + $supp_discount, $supplier_id, "", $rate);
// Now credit discount received account with discounts
if ($supp_discount != 0)
{
add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payment_discount_account"], 0, 0,
- -$supp_discount, $supplier_id);
+ -$supp_discount, $supplier_id, "", $rate);
}
if ($supp_amount != 0)
{
add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_account, 0, 0,
- -$supp_amount, $supplier_id);
+ -$supp_amount, $supplier_id, "", $rate);
}
/*now enter the bank_trans entry */
//-------------------------------------------------------------------------------------------------------------
function add_supp_trans($type, $supplier_id, $date_, $due_date, $reference, $supp_reference,
- $amount, $amount_tax, $discount, $err_msg="")
+ $amount, $amount_tax, $discount, $err_msg="", $rate=0)
{
$date = date2sql($date_);
if ($due_date == "")
$trans_no = get_next_trans_no($type);
$curr = get_supplier_currency($supplier_id);
- $rate = get_exchange_rate_from_home_currency($curr, $date_);
+
+ if ($rate == 0)
+ $rate = get_exchange_rate_from_home_currency($curr, $date_);
$sql = "INSERT INTO ".TB_PREF."supp_trans (trans_no, type, supplier_id, tran_date, due_date,
// $amount is in SUPPLIERS'S currency
function add_gl_trans_supplier($type, $type_no, $date_, $account, $dimension, $dimension2,
- $amount, $supplier_id, $err_msg="")
+ $amount, $supplier_id, $err_msg="", $rate=0)
{
if ($err_msg == "")
$err_msg = "The supplier GL transaction could not be inserted";
return add_gl_trans($type, $type_no, $date_, $account, $dimension, $dimension2, "",
$amount, get_supplier_currency($supplier_id),
- payment_person_types::supplier(), $supplier_id, $err_msg);
+ payment_person_types::supplier(), $supplier_id, $err_msg, $rate);
}
//----------------------------------------------------------------------------------------
$bank_currency = get_bank_account_currency($_POST['bank_account']);
if ($bank_currency != $supplier_currency)
{
- exchange_rate_display($bank_currency, $supplier_currency, $_POST['DatePaid']);
+ exchange_rate_display($bank_currency, $supplier_currency, $_POST['DatePaid'], true);
}
bank_trans_types_list_row(_("Payment Type:"), 'PaymentType', null);
return false;
}
+ if (isset($_POST['_ex_rate']) && !check_num('_ex_rate', 0.000001))
+ {
+ display_error(_("The exchange rate must be numeric and greater than zero."));
+ set_focus('_ex_rate');
+ return false;
+ }
+
if ($_POST['discount'] == "")
{
$_POST['discount'] = 0;
if (input_num('amount') - input_num('discount') <= 0)
{
- display_error(_("The total of the amount and the discount negative. Please enter positive values."));
+ display_error(_("The total of the amount and the discount is zero or negative. Please enter positive values."));
set_focus('amount');
return false;
}
function handle_add_payment()
{
+ $supp_currency = get_supplier_currency($_POST['supplier_id']);
+ $bank_currency = get_bank_account_currency($_POST['bank_account']);
+ $comp_currency = get_company_currency();
+ if ($comp_currency != $bank_currency && $bank_currency != $supp_currency)
+ $rate = 0;
+ else
+ $rate = input_num('_ex_rate');
+
$payment_id = add_supp_payment($_POST['supplier_id'], $_POST['DatePaid'],
$_POST['PaymentType'], $_POST['bank_account'],
- input_num('amount'), input_num('discount'), $_POST['ref'], $_POST['memo_']);
+ input_num('amount'), input_num('discount'), $_POST['ref'], $_POST['memo_'], $rate);
//unset($_POST['supplier_id']);
unset($_POST['bank_account']);
$rep->TextCol(3, 4, sql2date($trans['due_date']));
$item[0] = $item[1] = 0.0;
if ($convert)
- $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $date);
+ $rate = $trans['rate'];
else
$rate = 1.0;
if ($trans['type'] == 11 || $trans['type'] == 12 || $trans['type'] == 2)
$subprov = 0;
}
$date = sql2date($myrow['tran_date']);
- $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $date);
+ $rate = $myrow['rate'];
$amt = $myrow['InvoiceTotal'] * $rate;
if ($subprov > $myrow['break_pt'] && $myrow['provision2'] != 0)
$prov = $myrow['provision2'] * $amt / 100;
$rep->TextCol(3, 4, sql2date($trans['due_date']));
$item[0] = $item[1] = 0.0;
if ($convert)
- $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $date);
+ //$rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $date);
+ $rate = $trans['rate'];
else
$rate = 1.0;
if ($trans['TotalAmount'] > 0.0)
$sql = "SELECT ".TB_PREF."sys_types.type_name,
".TB_PREF."supp_trans.supp_reference,
+ ".TB_PREF."supp_trans.tran_date,
".TB_PREF."supp_trans.due_date,
".TB_PREF."supp_trans.trans_no,
".TB_PREF."supp_trans.type,
- (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst - ".TB_PREF."supp_trans.alloc) AS Balance,
- (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst ) AS TranTotal
+ ".TB_PREF."supp_trans.rate,
+ (ABS(".TB_PREF."supp_trans.ov_amount) + ABS(".TB_PREF."supp_trans.ov_gst) - ".TB_PREF."supp_trans.alloc) AS Balance,
+ (ABS(".TB_PREF."supp_trans.ov_amount) + ABS(".TB_PREF."supp_trans.ov_gst) ) AS TranTotal
FROM ".TB_PREF."supp_trans,
".TB_PREF."sys_types
WHERE ".TB_PREF."sys_types.type_id = ".TB_PREF."supp_trans.type
AND ".TB_PREF."supp_trans.supplier_id = '" . $supplier . "'
- AND ".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst - ".TB_PREF."supp_trans.alloc != 0
- AND ".TB_PREF."supp_trans.due_date <='" . $date . "'
+ AND ABS(".TB_PREF."supp_trans.ov_amount) + ABS(".TB_PREF."supp_trans.ov_gst) - ".TB_PREF."supp_trans.alloc != 0
+ AND ".TB_PREF."supp_trans.tran_date <='" . $date . "'
ORDER BY ".TB_PREF."supp_trans.type,
".TB_PREF."supp_trans.trans_no";
$rep->fontSize += 2;
$rep->TextCol(0, 6, $myrow['name'] . " - " . $myrow['terms']);
if ($convert)
- {
- $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $to);
$rep->TextCol(6, 7, $myrow['curr_code']);
- }
- else
- $rate = 1.0;
$rep->fontSize -= 2;
$rep->NewLine(1, 2);
$res = getTransactions($myrow['supplier_id'], $to);
$total[0] = $total[1] = 0.0;
while ($trans=db_fetch($res))
{
+ if ($convert)
+ $rate = $trans['rate'];
+ else
+ $rate = 1.0;
$rep->NewLine(1, 2);
$rep->TextCol(0, 1, $trans['type_name']);
$rep->TextCol(1, 2, $trans['supp_reference']);
- $rep->TextCol(2, 3, sql2date($trans['due_date']));
- $item[0] = Abs($trans['TranTotal']) * $rate;
+ if ($trans['type'] == 20)
+ $rep->TextCol(2, 3, sql2date($trans['due_date']));
+ else
+ $rep->TextCol(2, 3, sql2date($trans['tran_date']));
+ if ($trans['type'] != 20)
+ {
+ $trans['TranTotal'] = -$trans['TranTotal'];
+ $trans['Balance'] = -$trans['Balance'];
+ }
+ $item[0] = $trans['TranTotal'] * $rate;
$rep->TextCol(6, 7, number_format2($item[0], $dec));
$item[1] = $trans['Balance'] * $rate;
$rep->TextCol(7, 8, number_format2($item[1], $dec));
$DisplayNet = number_format2($Net,$dec);
//$rep->TextCol(0, 1, $myrow2['item_code'], -2);
$rep->TextCol(0, 2, $myrow2['description'], -2);
- $rep->TextCol(2, 3, $myrow2['delivery_date'], -2);
+ $rep->TextCol(2, 3, sql2date($myrow2['delivery_date']), -2);
$rep->TextCol(3, 4, $DisplayQty, -2);
$rep->TextCol(4, 5, $myrow2['units'], -2);
$rep->TextCol(5, 6, $DisplayPrice, -2);
return false;
}
+ if (isset($_POST['_ex_rate']) && !check_num('_ex_rate', 0.000001))
+ {
+ display_error(_("The exchange rate must be numeric and greater than zero."));
+ set_focus('_ex_rate');
+ return false;
+ }
+
+ if ($_POST['discount'] == "")
+ {
+ $_POST['discount'] = 0;
+ }
+
if (!check_num('discount')) {
display_error(_("The entered discount is not a valid number."));
set_focus('discount');
//----------------------------------------------------------------------------------------------
if (isset($_POST['AddPaymentItem'])) {
+
+ $cust_currency = get_customer_currency($_POST['customer_id']);
+ $bank_currency = get_bank_account_currency($_POST['bank_account']);
+ $comp_currency = get_company_currency();
+ if ($comp_currency != $bank_currency && $bank_currency != $cust_currency)
+ $rate = 0;
+ else
+ $rate = input_num('_ex_rate');
+
$payment_no = write_customer_payment(0, $_POST['customer_id'], $_POST['BranchID'],
$_POST['bank_account'], $_POST['DateBanked'], $_POST['ReceiptType'], $_POST['ref'],
- input_num('amount'), input_num('discount'), $_POST['memo_']);
+ input_num('amount'), input_num('discount'), $_POST['memo_'], $rate);
meta_forward($_SERVER['PHP_SELF'], "AddedID=$payment_no");
}
$bank_currency = get_bank_account_currency($_POST['bank_account']);
if ($cust_currency != $bank_currency) {
- exchange_rate_display($cust_currency, $bank_currency, $_POST['DateBanked']);
+ exchange_rate_display($bank_currency, $cust_currency, $_POST['DateBanked'], true);
}
bank_trans_types_list_row(_("Type:"), 'ReceiptType', null);
function write_customer_trans($trans_type, $trans_no, $debtor_no, $BranchNo,
$date_, $reference, $Total, $discount=0, $Tax=0, $Freight=0, $FreightTax=0,
$sales_type=0, $order_no=0, $trans_link=0, $ship_via=0, $due_date="",
- $AllocAmt=0)
+ $AllocAmt=0, $rate=0)
{
$curr = get_customer_currency($debtor_no);
- $rate = get_exchange_rate_from_home_currency($curr, $date_);
+ if ($rate == 0)
+ $rate = get_exchange_rate_from_home_currency($curr, $date_);
$SQLDate = date2sql($date_);
if ($due_date == "")
Write/update customer payment.
*/
function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_account,
- $date_, $receipt_type, $ref, $amount, $discount, $memo_)
+ $date_, $receipt_type, $ref, $amount, $discount, $memo_, $rate=0)
{
begin_transaction();
$company_record = get_company_prefs();
- $payment_no = write_customer_trans(12, $trans_no,
- $customer_id, $branch_id, $date_, $ref, $amount, $discount);
+ $payment_no = write_customer_trans(12, $trans_no, $customer_id, $branch_id,
+ $date_, $ref, $amount, $discount, 0, 0, 0, 0, 0, 0, 0, "", 0, $rate);
if ($trans_no != 0) {
delete_comments(12, $trans_no);
/* Bank account entry first */
add_gl_trans_customer(12, $payment_no, $date_,
$bank_account, 0, 0, $amount, $customer_id,
- "Cannot insert a GL transaction for the bank account debit");
+ "Cannot insert a GL transaction for the bank account debit", $rate);
if ($branch_id != reserved_words::get_any_numeric()) {
/* Now Credit Debtors account with receipts + discounts */
add_gl_trans_customer(12, $payment_no, $date_,
$debtors_account, 0, 0, -($discount + $amount), $customer_id,
- "Cannot insert a GL transaction for the debtors account credit");
+ "Cannot insert a GL transaction for the debtors account credit", $rate);
}
if ($discount != 0) {
/* Now Debit discount account with discounts allowed*/
add_gl_trans_customer(12, $payment_no, $date_,
$discount_account, 0, 0, $discount, $customer_id,
- "Cannot insert a GL transaction for the payment discount debit");
+ "Cannot insert a GL transaction for the payment discount debit", $rate);
}
/*now enter the bank_trans entry */
// $amount is in CUSTOMER'S currency
function add_gl_trans_customer($type, $type_no, $date_, $account, $dimension, $dimension2,
- $amount, $customer_id, $err_msg="")
+ $amount, $customer_id, $err_msg="", $rate)
{
if ($err_msg == "")
$err_msg = "The customer GL transaction could not be inserted";
return add_gl_trans($type, $type_no, $date_, $account, $dimension, $dimension2, "", $amount,
get_customer_currency($customer_id),
- payment_person_types::customer(), $customer_id, $err_msg);
+ payment_person_types::customer(), $customer_id, $err_msg, $rate);
}
//----------------------------------------------------------------------------------------