X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fui%2Fui_view.inc;h=cc003088d2595ec51e8815823189b0f6a0534f8e;hb=22486f7826944e00937e7ccceab1a927c94d8f6a;hp=00684612e5834ea968d097228d176c4e988235f0;hpb=28e5f95d81850e496e1b0387126e7bb836da61c5;p=fa-stable.git diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 00684612..cc003088 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -250,45 +250,81 @@ function get_trans_view_str($type, $trans_no, $label="", $icon=false, return null; } +/* + Helper for ui drawing functions. + Checks whether any of input function parameters has changed or page is called with GET method (first page display). + $name - context +*/ +function check_ui_refresh($name=null) +{ + $bt = debug_backtrace(); + if (!$name) + $name = $bt[1]['function']; + $old = @$_SESSION['ui_context'][$name]; + $new = $_SESSION['ui_context'][$name] = $bt[1]['args']; + return ($new != $old) || ($_SERVER['REQUEST_METHOD'] == 'GET'); +} + //-------------------------------------------------------------------------------------- // Displays currency exchange rate for given date. // 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_, $edit_rate=false) +function exchange_rate_display($from_currency, $to_currency, $date_, $force_edit=false) { - global $Ajax; + global $Ajax, $xr_provider_authoritative; + + $readonly = false; if ($from_currency != $to_currency) { - $comp_currency = get_company_currency(); - if ($from_currency == $comp_currency) - $currency = $to_currency; - else - $currency = $from_currency; - $rate = 0; - if ($date_ == Today()) { - $rate = get_date_exchange_rate($currency, $date_); - if (!$rate) { + $rate = get_post('_ex_rate'); + if (check_ui_refresh() || !$rate) { // readonly or ui context changed + $comp_currency = get_company_currency(); + if ($from_currency == $comp_currency) + $currency = $to_currency; + else + $currency = $from_currency; + + $rate = get_date_exchange_rate($currency, $date_); // try local + + if ($rate) + $readonly = true; // if we have already local exrate keep it unchanged + + if (!$rate) { // retry from remote service $row = get_currency($currency); - if ($row['auto_update']) { - $rate = retrieve_exrate($currency, $date_); - if ($rate) - add_exchange_rate($currency, $date_, $rate, $rate); + + if ($row['auto_update']) // autoupdate means use remote service & store exrate on first transaction. + { + $rate = retrieve_exrate($currency, $date_); + if (!$rate) + display_warning(sprintf(_("Cannot retrieve exchange rate for currency %s. Please adjust approximate rate if needed."), $currency)); + elseif ($xr_provider_authoritative) { + // if the remote exrate is considered authoritative we can store the rate here, + // otherwise exrate will be stored during transaction write + $readonly = true; + add_new_exchange_rate($currency, $date_, $rate); + } } } + if (!$rate) { // get and edit latest available + $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_)); + $Ajax->activate('_ex_rate_span'); } - if (!$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()); - if ($edit_rate) - text_row(_("Exchange Rate:"), '_ex_rate', $rate, 8, 8, null, "", " $from_currency = 1 $to_currency"); - else - label_row(_("Exchange Rate:"),"$rate $from_currency = 1 $to_currency" ); - $Ajax->addUpdate('_ex_rate','_ex_rate', $rate); + + if ($force_edit || !$readonly) + $ctrl = ""; + else + $ctrl = "$rate"; + + label_row(_("Exchange Rate:"), $span = "$ctrl $from_currency = 1 $to_currency" ); + + $Ajax->addUpdate('_ex_rate_span', '_ex_rate_span', $span); } } @@ -301,7 +337,7 @@ function is_voided_display($type, $id, $label) if ($void_entry == null) return false; - start_table(TABLESTYLE, "width=50%"); + start_table(TABLESTYLE, "width='50%'"); echo "$label
"; echo "" . _("Date Voided:") . " " . sql2date($void_entry["date_"]) . "
"; if (strlen($void_entry["memo_"]) > 0) @@ -322,7 +358,7 @@ function comments_display_row($type, $id) echo ""; while ($comment = db_fetch($comments)) { - echo $comment["memo_"] . "
"; + echo nl2br($comment["memo_"]) . "
"; } echo ""; } @@ -506,7 +542,7 @@ function display_allocations($alloc_result, $total, $payments=false) display_heading2(($payments ? _("Payments") : _("Allocations"))); - start_table(TABLESTYLE, "width=80%"); + start_table(TABLESTYLE, "width='80%'"); $th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"), _("Left to Allocate"), _("This Allocation"));