-
-
-
- |
- . $locale->text('Account') . qq| |
- |
- . $locale->text('Amount') . qq| |
- |
- . $locale->text('Tax') . qq| |
- |
- . $locale->text('Korrektur') . qq| |
- |
- . $locale->text('Taxkey') . qq| |
- |
- . $locale->text('Project') . qq| |
-
-|;
-
- $amount = $locale->text('Amount');
- $project = $locale->text('Project');
-
- for $i (1 .. $form->{rowcount}) {
+ $form->header();
+ # get the correct date for tax
+ my $transdate = $::form->{transdate} ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local;
+ my $deliverydate = $::form->{deliverydate} ? DateTime->from_kivitendo($::form->{deliverydate}) : undef;
+ my $taxdate = $deliverydate ? $deliverydate : $transdate;
+ # helper for loop
+ my $first_taxchart;
+
+ for my $i (1 .. $form->{rowcount}) {
# format amounts
- $form->{"amount_$i"} =
- $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
+ $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
$form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
- $selectAP_amount = $selectAP_amount_unquoted;
- $re_amount = quotemeta($form->{"AP_amount_$i"});
- $selectAP_amount =~
- s/option value=\"${re_amount}\"/option value=\"$form->{"AP_amount_$i"}\" selected/;
- $tax = $taxchart;
- $tax_selected = $form->{"taxchart_$i"};
- $tax =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/;
- $tax =
- qq| | |;
-
- my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
-
- print qq|
-
- |
- {"amount_$i"}> |
- {"tax_$i"}> |
- |
- $tax
-
- {"project_id_$i"}>
- |
-
-|;
- $amount = "";
- $project = "";
+
+ my ($default_taxchart, $taxchart_to_use);
+ my $used_tax_id;
+ if ( $form->{"taxchart_$i"} ) {
+ ($used_tax_id) = split(/--/, $form->{"taxchart_$i"});
+ }
+ my $amount_chart_id = $form->{"AP_amount_chart_id_$i"} || $default_ap_amount_chart_id;
+
+ my @taxcharts = GL->get_active_taxes_for_chart($amount_chart_id, $taxdate, $used_tax_id);
+ foreach my $item (@taxcharts) {
+ my $key = $item->id . "--" . $item->rate;
+ $first_taxchart //= $item;
+ $default_taxchart = $item if $item->{is_default};
+ $taxchart_to_use = $item if $key eq $form->{"taxchart_$i"};
+ }
+
+ $taxchart_to_use //= $default_taxchart // $first_taxchart;
+ my $selected_taxchart = $taxchart_to_use->id . '--' . $taxchart_to_use->rate;
+ $form->{"selected_taxchart_$i"} = $selected_taxchart;
+ $form->{"AP_amount_chart_id_$i"} = $amount_chart_id;
+ $form->{"taxcharts_$i"} = \@taxcharts;
}
- $taxlabel =
- ($form->{taxincluded})
- ? $locale->text('Tax Included')
- : $locale->text('Tax');
+ $form->{taxchart_value_title_sub} = sub {
+ my $item = shift;
+ return [
+ $item->{id} .'--'. $item->{rate},
+ $item->{taxkey} . ' - ' . $item->{taxdescription} .' '. ($item->{rate} * 100) .' %',
+ ];
+ };
+ $form->{AP_paid_value_title_sub} = sub {
+ my $item = shift;
+ return [
+ $item->{accno},
+ $item->{accno} .'--'. $item->{description}
+ ];
+ };
+
+ $form->{invtotal_unformatted} = $form->{invtotal};
$form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
- print qq|
-
-
-
- |
-
-
- |
-
- $form->{invtotal} |
-
- {oldinvtotal}>
- {oldtotalpaid}>
-
-
-
- |
-
-
-
-
- |
-
-
-
-
- |
-
-