Kreditorenbeleg prinzipiell um reverse_charge für beliebige Steuerschlüssel erw.
[kivitendo-erp.git] / bin / mozilla / ap.pl
index 58f8cc5..0e3048a 100644 (file)
@@ -496,9 +496,11 @@ sub form_header {
     $form->{"taxcharts_$i"}          = \@taxcharts;
 
     # reverse charge hack for template, display two taxes
-    if ($taxchart_to_use->taxkey == 94) {
+    if ($taxchart_to_use->reverse_charge_chart_id) {
       my $tmpnetamount;
-      ($tmpnetamount, $form->{"tax_reverse_$i"}) = $form->calculate_tax($form->parse_amount(\%myconfig, $form->{"amount_$i"}), 0.19, $form->{taxincluded},2);
+      ($tmpnetamount, $form->{"tax_reverse_$i"}) = $form->calculate_tax($form->parse_amount(\%myconfig, $form->{"amount_$i"}),
+                                                                        $taxchart_to_use->rate, $form->{taxincluded}, 2        );
+
       $form->{"tax_charge_$i"}  = $form->{"tax_reverse_$i"} * -1;
       $form->{"tax_reverse_$i"} = $form->format_amount(\%myconfig, $form->{"tax_reverse_$i"}, 2);
       $form->{"tax_charge_$i"}  = $form->format_amount(\%myconfig, $form->{"tax_charge_$i"}, 2);
@@ -807,14 +809,15 @@ sub post {
   $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
 
   my $zero_amount_posting = 1;
-  # no taxincluded for 94
-  my $tax = SL::DB::Manager::Tax->get_first( where => [taxkey => 94 ]);
-  my $tax_id = ref $tax eq 'SL::DB::Tax' ? $tax->id : undef;
   for my $i (1 .. $form->{rowcount}) {
-    # no taxincluded for 94
-    if ($tax_id && $form->{"taxchart_$i"} =~ m/^$tax_id--/ && $form->{taxincluded}) {
+
+    # no taxincluded for reverse charge
+    my ($used_tax_id) = split(/--/, $form->{"taxchart_$i"});
+    my $tax = SL::DB::Manager::Tax->find_by(id => $used_tax_id);
+    if ($tax->reverse_charge_chart_id && $form->{taxincluded}) {
       $form->error($locale->text('Cannot Post AP transaction with tax included!'));
     }
+
     if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
       $zero_amount_posting = 0;
     }
@@ -987,6 +990,8 @@ sub search {
   $form->{title} = $locale->text('Vendor Invoices & AP Transactions');
 
   $::form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all_sorted;
+  $::form->{ALL_TAXZONES}    = SL::DB::Manager::TaxZone   ->get_all_sorted;
+
   # constants and subs for template
   $form->{vc_keys}   = sub { "$_[0]->{name}--$_[0]->{id}" };
 
@@ -1044,7 +1049,7 @@ sub ap_transactions {
 
   my @hidden_variables = map { "l_${_}" } @columns;
   push @hidden_variables, "l_subtotal", qw(open closed vendor invnumber ordnumber transaction_description notes project_id transdatefrom transdateto
-                                           parts_partnumber parts_description department_id);
+                                           parts_partnumber parts_description department_id taxzone_id);
 
   my $href = build_std_url('action=ap_transactions', grep { $form->{$_} } @hidden_variables);
 
@@ -1078,7 +1083,7 @@ sub ap_transactions {
     'insertdate'              => { 'text' => $locale->text('Insert Date'), },
   );
 
-  foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description direct_debit department)) {
+  foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description direct_debit department taxzone)) {
     my $sortdir                 = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
     $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
   }