- # forex
- $form->{forex} = $form->{exchangerate};
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
- foreach $key (keys %{ $form->{AR_links} }) {
- # if there is a value we have an old entry
- my $j = 0;
- my $k = 0;
-
- for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
- if ($key eq "AR_paid") {
- $j++;
- $form->{"AR_paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{accno};
-
- # reverse paid
- $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
- $form->{"datepaid_$j"} =
- $form->{acc_trans}{$key}->[$i - 1]->{transdate};
- $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
- $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
-
- $form->{"forex_$j"} = $form->{"exchangerate_$i"} =
- $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
- $form->{"paid_project_id_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{project_id};
- $form->{paidaccounts}++;
-
- } else {
-
- $akey = $key;
- $akey =~ s/AR_//;
-
- if ($key eq "AR_tax" || $key eq "AP_tax") {
- $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
- "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
- $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
- $form->round_amount(
- $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
- 2);
-
- if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
- $totaltax +=
- $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
- $taxrate +=
- $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
- } else {
- $totalwithholding +=
- $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
- $withholdingrate +=
- $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
- }
- $index = $form->{acc_trans}{$key}->[$i - 1]->{index};
- $form->{"tax_$index"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
- $totaltax += $form->{"tax_$index"};
-
- } else {
- $k++;
- $form->{"${akey}_$k"} =
- $form->round_amount(
- $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
- 2);
- if ($akey eq 'amount') {
- $form->{rowcount}++;
- $totalamount += $form->{"${akey}_$i"};
-
- $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} =
- "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
- $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate};
- $form->{"project_id_$k"} =
- "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
- }
- $form->{"${key}_$i"} =
- "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
-
- if ($akey eq "AR") {
- $form->{ARselected} = $form->{acc_trans}{$key}->[$i-1]->{accno};
-
- } elsif ($akey eq "amount") {
- $form->{"${key}_$k"} = $form->{acc_trans}{$key}->[$i-1]->{accno} .
- "--" . $form->{acc_trans}{$key}->[$i-1]->{id};
- $form->{"taxchart_$k"} = $form->{acc_trans}{$key}->[$i-1]->{id} .
- "--" . $form->{acc_trans}{$key}->[$i-1]->{rate};
- }
- }
- }
- }
- }
-
- $form->{taxincluded} = $taxincluded if ($form->{id});
- $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
-
- if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
-
- # add tax to amounts and invtotal
- for $i (1 .. $form->{rowcount}) {
- $taxamount =
- ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
- $tax = $form->round_amount($taxamount, 2);
- $diff += ($taxamount - $tax);
- $form->{"amount_$i"} += $form->{"tax_$i"};
- }
- $form->{amount_1} += $form->round_amount($diff, 2);
- }
-
- $taxamount = $form->round_amount($taxamount, 2);
- $form->{tax} = $taxamount;
-
- $form->{invtotal} = $totalamount + $totaltax;