From: Janusz Dobrowolski Date: Sun, 21 Sep 2008 14:52:11 +0000 (+0000) Subject: Automatic exchange rate update after document date change X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=545a2aa0153c9d1dbf87d2aa9b5833ffd8bda90a;p=textcart.git exchange rate update after document date change --- diff --git a/gl/bank_transfer.php b/gl/bank_transfer.php index d40436d..78089f5 100644 --- a/gl/bank_transfer.php +++ b/gl/bank_transfer.php @@ -37,6 +37,10 @@ if (isset($_GET['AddedID'])) safeExit(); } +if (isset($_POST['_DatePaid_changed'])) { + $Ajax->activate('_ex_rate'); +} + //---------------------------------------------------------------------------------------- function gl_payment_controls() @@ -54,7 +58,7 @@ function gl_payment_controls() bank_accounts_list_row(_("To Account:"), 'ToBankAccount', null, true); - date_row(_("Transfer Date:"), 'DatePaid'); + date_row(_("Transfer Date:"), 'DatePaid', '', null, 0, 0, 0, null, true); $from_currency = get_bank_account_currency($_POST['FromBankAccount']); $to_currency = get_bank_account_currency($_POST['ToBankAccount']); diff --git a/gl/gl_bank.php b/gl/gl_bank.php index 3bb0e9e..ce8c40f 100644 --- a/gl/gl_bank.php +++ b/gl/gl_bank.php @@ -98,6 +98,9 @@ if (isset($_GET['AddedDep'])) display_footer_exit(); } +if (isset($_POST['_date__changed'])) { + $Ajax->activate('_ex_rate'); +} //-------------------------------------------------------------------------------------------------- function handle_new_order($type) diff --git a/gl/includes/db/gl_db_rates.inc b/gl/includes/db/gl_db_rates.inc index 0a2c227..cba2e5a 100644 --- a/gl/includes/db/gl_db_rates.inc +++ b/gl/includes/db/gl_db_rates.inc @@ -18,14 +18,18 @@ function get_exchange_rate($rate_id) return db_fetch($result); } +// Retrieves buy exchange rate for given currency/date, zero if no result function get_date_exchange_rate($curr_code, $date_) { $date = date2sql($date_); - $sql = "SELECT date_ FROM ".TB_PREF."exchange_rates WHERE curr_code='$curr_code' + $sql = "SELECT rate_buy FROM ".TB_PREF."exchange_rates WHERE curr_code='$curr_code' AND date_='$date'"; $result = db_query($sql, "could not get exchange rate for $curr_code - $date_"); - return (db_num_rows($result) == 1); + if(db_num_rows($result) == 0) + return 0; + $row = db_fetch($result); + return $row[0]; } //--------------------------------------------------------------------------------------------- @@ -100,11 +104,11 @@ function get_ecb_rate($curr_b) $contents = str_replace (" |i"; preg_match ( $from_mask, $contents, $out ); - $val_a = $out[1]; + $val_a = isset($out[1]) ? $out[1] : 0; $val_a = str_replace ( ',', '', $val_a ); $to_mask = "||i"; preg_match ( $to_mask, $contents, $out ); - $val_b = $out[1]; + $val_b = isset($out[1]) ? $out[1] : 0; $val_b = str_replace ( ',', '', $val_b ); if ($val_b) { diff --git a/gl/includes/ui/gl_bank_ui.inc b/gl/includes/ui/gl_bank_ui.inc index 3ea9b9d..61c5250 100644 --- a/gl/includes/ui/gl_bank_ui.inc +++ b/gl/includes/ui/gl_bank_ui.inc @@ -13,7 +13,7 @@ function display_bank_header(&$order) bank_accounts_list_row( $payment ? _("From:") : _("To:"), 'bank_account', null, true); - date_row(_("Date:"), 'date_'); + date_row(_("Date:"), 'date_', '', null, 0, 0, 0, null, true); echo ""; // inner table diff --git a/includes/banking.inc b/includes/banking.inc index e3232a7..2c0fa94 100644 --- a/includes/banking.inc +++ b/includes/banking.inc @@ -85,7 +85,7 @@ function get_exchange_rate_from_home_currency($currency_code, $date_) if (db_num_rows($result) == 0) { // no stored exchange rate, just return 1 - display_error(_("Cannot get exchange rate for this currency. Please add exchange rate manually on Exchange Rates page.") ); + display_error(_("Cannot retrieve currency exchange rate for this date. Please add exchange rate manually on Exchange Rates page.") ); return 1.000; } diff --git a/purchasing/supplier_payment.php b/purchasing/supplier_payment.php index c731c49..28e16c6 100644 --- a/purchasing/supplier_payment.php +++ b/purchasing/supplier_payment.php @@ -41,6 +41,9 @@ if (isset($_POST['_supplier_id_editor'])) { array( 'supplier_id', 'bank_account', 'DatePaid', 'PaymentType', 'ref', 'amount', 'discount', 'memo_') ); } +if (isset($_POST['_DatePaid_changed'])) { + $Ajax->activate('_ex_rate'); +} //---------------------------------------------------------------------------------------- if (isset($_GET['AddedID'])) @@ -83,7 +86,7 @@ function display_controls() amount_row(_("Amount of Payment:"), 'amount'); amount_row(_("Amount of Discount:"), 'discount'); - date_row(_("Date Paid") . ":", 'DatePaid'); + date_row(_("Date Paid") . ":", 'DatePaid', '', null, 0, 0, 0, null, true); echo ""; echo ""; // outer table diff --git a/sales/customer_payments.php b/sales/customer_payments.php index 42cb552..1ab43ce 100644 --- a/sales/customer_payments.php +++ b/sales/customer_payments.php @@ -114,6 +114,9 @@ if (isset($_POST['_customer_id_button'])) { // unset($_POST['branch_id']); $Ajax->activate('BranchID'); } +if (isset($_POST['_DateBanked_changed'])) { + $Ajax->activate('_ex_rate'); +} //---------------------------------------------------------------------------------------------- if (isset($_POST['AddPaymentItem'])) { @@ -171,7 +174,6 @@ function display_item_form() read_customer_data(); set_global_customer($_POST['customer_id']); - if (isset($_POST['HoldAccount']) && $_POST['HoldAccount'] != 0) { echo ""; display_note(_("This customer account is on hold."), 0, 0, "class='redfb'"); @@ -184,7 +186,7 @@ function display_item_form() label_row(_("Customer prompt payment discount :"), $display_discount_percent); - date_row(_("Date of Deposit:"), 'DateBanked'); + date_row(_("Date of Deposit:"), 'DateBanked','',null, 0, 0, 0, null, true); echo ""; echo ""; // outer table diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index 46427af..83c9e28 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -138,7 +138,7 @@ class cart get_invoice_duedate($this->customer_id, $this->document_date); else $this->due_date = - add_days($this->document_date, 10); // FIX this should be in company prefs + add_days($this->document_date, sys_prefs::default_delivery_required_by()); } }