my ($null, $taxrate, $amount);
my $exchangerate = 0;
+ $form->{defaultcurrency} = $form->get_default_currency($myconfig);
+
($null, $form->{department_id}) = split(/--/, $form->{department});
$form->{department_id} *= 1;
my @values;
my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
+ $form->{defaultcurrency} = $form->get_default_currency($myconfig);
# set exchangerate
$form->{exchangerate} = ($form->{currency} eq $form->{defaultcurrency}) ? 1 :
# update exchangerate
$form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, $form->{exchangerate}, 0)
- if ($form->{currency} ne $form->{defaultcurrency}) && $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'buy');
+ if ($form->{currency} ne $form->{defaultcurrency}) && !$form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'buy');
if (!$payments_only) {
$query =
if ($curr eq '') {
$main::lxdebug->leave_sub();
return;
+ }
+ my $query = qq|SELECT curr FROM defaults|;
+
+ my ($currency) = selectrow_query($self, $dbh, $query);
+ my ($defaultcurrency) = split m/:/, $currency;
+
+
+ if ($curr eq $defaultcurrency) {
+ $main::lxdebug->leave_sub();
+ return;
}
my $query = qq|SELECT e.curr FROM exchangerate e
FOR UPDATE|;
my $sth = prepare_execute_query($self, $dbh, $query, $curr, $transdate);
+ if ($buy == 0) {
+ $buy = "";
+ }
+ if ($sell == 0) {
+ $sell = "";
+ }
+
+ $buy = conv_i($buy, "NULL");
+ $sell = conv_i($sell, "NULL");
+
my $set;
if ($buy != 0 && $sell != 0) {
$set = "buy = $buy, sell = $sell";
SET $set
WHERE curr = ?
AND transdate = ?|;
+
} else {
$query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
VALUES (?, $buy, $sell, ?)|;
my $dbh = $self->dbconnect($myconfig);
- my ($buy, $sell) = (0, 0);
+ my ($buy, $sell);
+
$buy = $rate if $fld eq 'buy';
$sell = $rate if $fld eq 'sell';
+
$self->update_exchangerate($dbh, $currency, $transdate, $buy, $sell);
+
$dbh->disconnect;
$main::lxdebug->leave_sub();
return 1;
}
+ my $query = qq|SELECT curr FROM defaults|;
+
+ my ($currency) = selectrow_query($self, $dbh, $query);
+ my ($defaultcurrency) = split m/:/, $currency;
+
+ if ($currency eq $defaultcurrency) {
+ $main::lxdebug->leave_sub();
+ return 1;
+ }
+
my $query = qq|SELECT e.$fld FROM exchangerate e
WHERE e.curr = ? AND e.transdate = ?|;
my ($exchangerate) = selectrow_query($self, $dbh, $query, $curr, $transdate);
- if (!$exchangerate) {
- $exchangerate = 1;
- }
+
$main::lxdebug->leave_sub();
return "";
}
- my $dbh = $self->dbconnect($myconfig);
+ my ($defaultcurrency) = $self->get_default_currency($myconfig);
+
+ if ($currency eq $defaultcurrency) {
+ $main::lxdebug->leave_sub();
+ return 1;
+ }
+ my $dbh = $self->get_standard_dbh($myconfig);
my $query = qq|SELECT e.$fld FROM exchangerate e
WHERE e.curr = ? AND e.transdate = ?|;
+
my ($exchangerate) = selectrow_query($self, $dbh, $query, $currency, $transdate);
- $dbh->disconnect();
- $exchangerate = 1 if ($exchangerate == 0);
$exchangerate = 1 if ($exchangerate eq "");
$main::lxdebug->leave_sub();
return $exchangerate;
}
+sub get_default_currency {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig) = @_;
+ my $dbh = $self->get_standard_dbh($myconfig);
+
+ my $query = qq|SELECT curr FROM defaults|;
+
+ my ($curr) = selectrow_query($self, $dbh, $query);
+ my ($defaultcurrency) = split m/:/, $curr;
+
+ $main::lxdebug->leave_sub();
+
+ return $defaultcurrency;
+}
+
+
sub set_payment_options {
$main::lxdebug->enter_sub();
# connect to database, turn off autocommit
my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
+ $form->{defaultcurrency} = $form->get_default_currency($myconfig);
my ($query, $sth, @values, $project_id);
my ($allocated, $taxrate, $taxamount, $taxdiff, $item);
if (!$form->{employee_id}) {
$form->get_employee($dbh);
}
+
+ $form->{defaultcurrency} = $form->get_default_currency($myconfig);
($null, $form->{department_id}) = split(/--/, $form->{department});
$project
AND ac.amount > 0
AND c.accno = ?) AS credit |;
+
$drcr = prepare_query($form, $dbh, $q_drcr);
if ($form->{project_id}) {
($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
$readonly = ($form->{radier}) ? "" : $readonly;
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate =
+ $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
+ )));
+
+
# format amounts
$form->{exchangerate} =
$form->format_amount(\%myconfig, $form->{exchangerate});
-
+ if ($form->{exchangerate} == 0) {
+ $form->{exchangerate} = "";
+ }
$form->{creditlimit} =
$form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
$form->{creditremaining} =
}
$form->{"exchangerate_$i"} =
$form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
+ if ($form->{"exchangerate_$i"} == 0) {
+ $form->{"exchangerate_$i"} = "";
+ }
$exchangerate = qq| |;
if ($form->{currency} ne $form->{defaultcurrency}) {
s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
}
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate =
+ $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
+ )));
+
# format amounts
$form->{exchangerate} =
$form->format_amount(\%myconfig, $form->{exchangerate});
+ if ($form->{exchangerate} == 0) {
+ $form->{exchangerate} = "";
+ }
+
$form->{creditlimit} =
$form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
$form->{creditremaining} =
$form->{"exchangerate_$i"} =
$form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
+ if ($form->{"exchangerate_$i"} == 0) {
+ $form->{"exchangerate_$i"} = "";
+ }
+
$exchangerate = qq| |;
if ($form->{currency} ne $form->{defaultcurrency}) {
if ($form->{"forex_$i"}) {
}
}
}
-
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
$form->{radier} =
($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
$form->{"exchangerate_$i"} =
$form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
+ if ($form->{"exchangerate_$i"} == 0) {
+ $form->{"exchangerate_$i"} = "";
+ }
$exchangerate = qq| |;
if ($form->{currency} ne $form->{defaultcurrency}) {
if ($form->{"forex_$i"}) {
sub post_payment {
$lxdebug->enter_sub();
+
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
for $i (1 .. $form->{paidaccounts}) {
if ($form->{"paid_$i"}) {
$datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
sub post {
$lxdebug->enter_sub();
+
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
$form->isblank("invdate", $locale->text('Invoice Date missing!'));
$form->isblank("customer", $locale->text('Customer missing!'));
$form->{salesman_id} = $form->{old_salesman_id};
}
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+
map { $form->{$_} =~ s/\"/"/g }
qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
$form->{exchangerate} =
$form->format_amount(\%myconfig, $form->{exchangerate});
+ if (!$form->{exchangerate}) {
+ $form->{exchangerate} = "";
+ }
+
if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
$creditwarning = 1;
} else {
sub save_and_close {
$lxdebug->enter_sub();
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+
+
if ($form->{type} =~ /_order$/) {
$form->isblank("transdate", $locale->text('Order Date missing!'));
} else {
sub save {
$lxdebug->enter_sub();
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+
+
if ($form->{type} =~ /_order$/) {
$form->isblank("transdate", $locale->text('Order Date missing!'));
} else {
$form->{rowcount}--;
$form->{shipto} = 1;
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+
if ($form->{type} =~ /_order$/) {
$form->{exchangerate} = $exchangerate;
&create_backorder;