my $exchangerate = 0;
$form->{defaultcurrency} = $form->get_default_currency($myconfig);
+ delete $form->{currency} unless $form->{defaultcurrency};
($null, $form->{department_id}) = split(/--/, $form->{department});
$form->{department_id} *= 1;
$self->setup_form($form);
- ($form->{defaultcurrency}) = selectrow_query($form, $dbh, qq|SELECT curr FROM defaults|);
- $form->{defaultcurrency} = (split m/:/, $form->{defaultcurrency})[0];
- $form->{currency} = $form->{defaultcurrency} if ($form->{defaultcurrency} && ($form->{currency} =~ m/^\s*$/));
-
- $form->{exchangerate} = $form->format_amount($myconfig, $form->{exchangerate});
+ $form->{exchangerate} = $form->format_amount($myconfig, $form->{exchangerate});
+ $form->{defaultcurrency} = $form->get_default_currency($myconfig);
+ delete $form->{currency} unless $form->{defaultcurrency};
# Get the AP accno.
$query =
my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
$form->{defaultcurrency} = $form->get_default_currency($myconfig);
+ delete $form->{currency} unless $form->{default_currency};
# set exchangerate
$form->{exchangerate} = ($form->{currency} eq $form->{defaultcurrency}) ? 1 :
$self->setup_form($form);
- ($form->{defaultcurrency}) = selectrow_query($form, $dbh, qq|SELECT curr FROM defaults|);
- $form->{defaultcurrency} = (split m/:/, $form->{defaultcurrency})[0];
- $form->{currency} = $form->{defaultcurrency} if ($form->{defaultcurrency} && ($form->{currency} =~ m/^\s*$/));
-
- $form->{exchangerate} = $form->format_amount($myconfig, $form->{exchangerate});
+ $form->{exchangerate} = $form->format_amount($myconfig, $form->{exchangerate});
+ $form->{defaultcurrency} = $form->get_default_currency($myconfig);
+ delete $form->{currency} unless $form->{default_currency};
# Get the AR accno (which is normally done by Form::create_links()).
$query =
return $exchangerate;
}
-sub get_default_currency {
+sub get_all_currencies {
$main::lxdebug->enter_sub();
my ($self, $myconfig) = @_;
my $query = qq|SELECT curr FROM defaults|;
- my ($curr) = selectrow_query($self, $dbh, $query);
- my ($defaultcurrency) = split m/:/, $curr;
+ my ($curr) = selectrow_query($self, $dbh, $query);
+ my @currencies = grep { $_ } map { s/\s//g; $_ } split m/:/, $curr;
$main::lxdebug->leave_sub();
- return $defaultcurrency;
+ return @currencies;
}
+sub get_default_currency {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig) = @_;
+ my @currencies = $self->get_all_currencies($myconfig);
+
+ $main::lxdebug->leave_sub();
+
+ return $currencies[0];
+}
sub set_payment_options {
$main::lxdebug->enter_sub();
$form->{notes} = $form->{intnotes} unless $form->{notes};
# currencies
- my @curr = split(/:/, $form->{currencies});
- chomp $curr[0];
- $form->{defaultcurrency} = $curr[0];
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
- map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
+ map { $form->{selectcurrency} .= "<option>$_\n" } $form->get_all_currencies(\%myconfig);
# vendors
if (@{ $form->{all_vendor} || [] }) {
my $exchangerate = qq|
<input type=hidden name=forex value=$form->{forex}>
|;
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
if ($form->{forex}) {
$exchangerate .= qq|
<tr>
|;
my @column_index;
- if ($form->{currency} eq $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} eq $form->{defaultcurrency})) {
@column_index = qw(datepaid source memo paid AP_paid paid_project_id);
} else {
@column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
}
$exchangerate = qq| |;
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
if ($form->{"forex_$i"}) {
$exchangerate =
qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
$form->error($locale->text('Cannot post payment for a closed period!'))
if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
$form->{"exchangerate_$i"} = $form->{exchangerate}
if ($invdate == $datepaid);
$form->isblank("exchangerate_$i",
$form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
$form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
- if ($form->{currency} ne $form->{defaultcurrency});
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency}));
delete($form->{AP});
for my $i (1 .. $form->{paidaccounts}) {
$form->error($locale->text('Cannot post payment for a closed period!'))
if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
$form->{"exchangerate_$i"} = $form->{exchangerate}
if ($transdate == $datepaid);
$form->isblank("exchangerate_$i",
my $form = $main::form;
my %myconfig = %main::myconfig;
- my ($duedate, $taxincluded, @curr);
+ my ($duedate, $taxincluded);
$form->create_links("AR", \%myconfig, "customer");
$duedate = $form->{duedate};
$form->{notes} = $form->{intnotes} unless $form->{notes};
# currencies
- @curr = split(/:/, $form->{currencies});
- chomp $curr[0];
- $form->{defaultcurrency} = $curr[0];
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
- map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
+ map { $form->{selectcurrency} .= "<option>$_\n" } $form->get_all_currencies(\%myconfig);
# customers
if (@{ $form->{all_customer} || [] }) {
$exchangerate = qq|
<input type=hidden name=forex value=$form->{forex}>
|;
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
if ($form->{forex}) {
$exchangerate .= qq|
<th align=right>| . $locale->text('Exchangerate') . qq|</th>
</tr>
|;
- if ($form->{currency} eq $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} eq $form->{defaultcurrency})) {
@column_index = qw(datepaid source memo paid AR_paid paid_project_id);
} else {
@column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
}
$exchangerate = qq| |;
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
if ($form->{"forex_$i"}) {
$exchangerate =
qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
$form->error($locale->text('Cannot post payment for a closed period!')) if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
# $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
$form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
}
unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
$form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
- if ($form->{currency} ne $form->{defaultcurrency});
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency}));
delete($form->{AR});
$form->error($locale->text('Cannot post payment for a closed period!'))
if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
$form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
$form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
}