Kontoauszug verbuchen - Punktesystem sichtbar machen
[kivitendo-erp.git] / SL / IS.pm
index caa2c34..c579aad 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -519,16 +519,26 @@ sub invoice_details {
   $form->{nodiscount}          = $form->format_amount($myconfig, $nodiscount, 2);
   $form->{yesdiscount}         = $form->format_amount($myconfig, $form->{nodiscount_total} - $nodiscount, 2);
 
-  $form->{invtotal} = ($form->{taxincluded}) ? $form->{total} : $form->{total} + $tax;
-  $form->{total}    = $form->format_amount($myconfig, $form->{invtotal} - $form->{paid}, 2);
+  my $grossamount = ($form->{taxincluded}) ? $form->{total} : $form->{total} + $tax;
+  $form->{invtotal} = $form->round_amount($grossamount, 2, 1);
+  $form->{rounding} = $form->round_amount(
+    $form->{invtotal} - $form->round_amount($grossamount, 2),
+    2
+  );
 
+  $form->{rounding} = $form->format_amount($myconfig, $form->{rounding}, 2);
+  $form->{total}    = $form->format_amount($myconfig, $form->{invtotal} - $form->{paid}, 2);
   $form->{invtotal} = $form->format_amount($myconfig, $form->{invtotal}, 2);
   $form->{paid}     = $form->format_amount($myconfig, $form->{paid}, 2);
 
-  $form->set_payment_options($myconfig, $form->{invdate});
+  $form->set_payment_options($myconfig, $form->{invdate}, 'sales_invoice');
 
   $form->{delivery_term} = SL::DB::Manager::DeliveryTerm->find_by(id => $form->{delivery_term_id} || undef);
-  $form->{delivery_term}->description_long($form->{delivery_term}->translated_attribute('description_long', $form->{language_id})) if $form->{delivery_term} && $form->{language_id};
+  if ($form->{delivery_term} && $form->{language_id}) {
+    $form->{delivery_term}->description_long(        $form->{delivery_term}->translated_attribute('description_long',         $form->{language_id}));
+    $form->{delivery_term}->description_long_invoice($form->{delivery_term}->translated_attribute('description_long_invoice', $form->{language_id}));
+  }
+
   $form->{department}    = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id};
 
   $form->{username} = $myconfig->{name};
@@ -600,8 +610,8 @@ sub customer_details {
       $ref->{cp_gender} = $contact->cp_gender;
     }
   }
-  # remove id and taxincluded before copy back
-  delete @$ref{qw(id taxincluded)};
+  # remove id,notes (double of customernotes) and taxincluded before copy back
+  delete @$ref{qw(id taxincluded notes)};
 
   @wanted_vars = grep({ $_ } @wanted_vars);
   if (scalar(@wanted_vars) > 0) {
@@ -969,15 +979,20 @@ SQL
   }
 
   # Invoice Summary includes Rounding
+  my $grossamount = $netamount + $tax;
   my $rounding = $form->round_amount(
-    $form->round_amount($netamount + $tax, 2, 1) - $form->round_amount($netamount + $tax, 2), 2
+    $form->round_amount($grossamount, 2, 1) - $form->round_amount($grossamount, 2),
+    2
   );
   my $rnd_accno = $rounding == 0 ? 0
                 : $rounding > 0  ? $form->{rndgain_accno}
-                :                  $form->{rndloss_accno};
-  $form->{amount}{ $form->{id} }{ $form->{AR} } = $form->round_amount($netamount + $tax, 2, 1);
-  $form->{paid} =
-    $form->round_amount($form->{paid} * $form->{exchangerate} + $diff, 2);
+                :                  $form->{rndloss_accno}
+  ;
+  $form->{amount}{ $form->{id} }{ $form->{AR} } = $form->round_amount($grossamount, 2, 1);
+  $form->{paid} = $form->round_amount(
+    $form->{paid} * $form->{exchangerate} + $diff,
+    2
+  );
 
   # reverse AR
   $form->{amount}{ $form->{id} }{ $form->{AR} } *= -1;
@@ -1293,7 +1308,7 @@ SQL
   if ($form->{storno}) {
     $query =
       qq!UPDATE ar SET
-           paid = paid + amount,
+           paid = amount,
            storno = 't',
            intnotes = ? || intnotes
          WHERE id = ?!;
@@ -1478,7 +1493,7 @@ sub _determine_wh_and_bin {
                                                       parts_id => $part->id,
                                                       bin_id   => $bin_id);
     if ($error == 1) {
-      push @errors, $::locale->text('Part "#1" has chargenumber or best before date set. So it cannot be transfered automaticaly.',
+      push @errors, $::locale->text('Part "#1" has chargenumber or best before date set. So it cannot be transfered automatically.',
                                     $part->description);
     }
     my $form_unit_obj = SL::DB::Unit->new(name => $unit)->load;