Gewicht in Druckvorlagen verfügbar machen
[kivitendo-erp.git] / SL / IS.pm
index 052dcfd..8a94ec6 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -144,7 +144,7 @@ sub invoice_details {
 
   $form->{discount} = [];
 
-  IC->prepare_parts_for_printing();
+  IC->prepare_parts_for_printing(myconfig => $myconfig, form => $form);
 
   my $ic_cvar_configs = CVar->get_configs(module => 'IC');
 
@@ -154,7 +154,7 @@ sub invoice_details {
        partnotes serialnumber reqdate sellprice listprice netprice
        discount p_discount discount_sub nodiscount_sub
        linetotal  nodiscount_linetotal tax_rate projectnumber projectdescription
-       price_factor price_factor_name partsgroup);
+       price_factor price_factor_name partsgroup weight lineweight);
 
   push @arrays, map { "ic_cvar_$_->{name}" } @{ $ic_cvar_configs };
 
@@ -164,6 +164,7 @@ sub invoice_details {
 
   map { $form->{TEMPLATE_ARRAYS}->{$_} = [] } (@arrays, @tax_arrays, @payment_arrays);
 
+  my $totalweight = 0;
   foreach $item (sort { $a->[1] cmp $b->[1] } @partsgroup) {
     $i = $item->[0];
 
@@ -280,6 +281,13 @@ sub invoice_details {
       push(@{ $form->{TEMPLATE_ARRAYS}->{projectnumber} },              $projectnumbers{$form->{"project_id_$i"}});
       push(@{ $form->{TEMPLATE_ARRAYS}->{projectdescription} },         $projectdescriptions{$form->{"project_id_$i"}});
 
+      my $lineweight = $form->{"qty_$i"} * $form->{"weight_$i"};
+      $totalweight += $lineweight;
+      push @{ $form->{TEMPLATE_ARRAYS}->{weight} },            $form->format_amount($myconfig, $form->{"weight_$i"}, 3);
+      push @{ $form->{TEMPLATE_ARRAYS}->{weight_nofmt} },      $form->{"weight_$i"};
+      push @{ $form->{TEMPLATE_ARRAYS}->{lineweight} },        $form->format_amount($myconfig, $lineweight, 3);
+      push @{ $form->{TEMPLATE_ARRAYS}->{lineweight_nofmt} },  $lineweight;
+
       @taxaccounts = split(/ /, $form->{"taxaccounts_$i"});
       $taxrate     = 0;
       $taxdiff     = 0;
@@ -366,6 +374,9 @@ sub invoice_details {
     }
   }
 
+  $form->{totalweight}       = $form->format_amount($myconfig, $totalweight, 3);
+  $form->{totalweight_nofmt} = $totalweight;
+
   foreach my $item (sort keys %taxaccounts) {
     $tax += $taxamount = $form->round_amount($taxaccounts{$item}, 2);
 
@@ -821,7 +832,7 @@ sub post_invoice {
   }
 
   $project_id = conv_i($form->{"globalproject_id"});
-
+  # entsprechend auch beim Bestimmen des Steuerschlüssels in Taxkey.pm berücksichtigen
   my $taxdate = $form->{deliverydate} ? $form->{deliverydate} : $form->{invdate};
 
   foreach my $trans_id (keys %{ $form->{amount_cogs} }) {
@@ -863,19 +874,19 @@ sub post_invoice {
         $query =
           qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id, chart_link)
              VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
-                     (SELECT tax_id 
-                      FROM taxkeys 
-                      WHERE chart_id= (SELECT id  
-                                       FROM chart 
-                                       WHERE accno = ?) 
-                      AND startdate <= ? 
+                     (SELECT tax_id
+                      FROM taxkeys
+                      WHERE chart_id= (SELECT id
+                                       FROM chart
+                                       WHERE accno = ?)
+                      AND startdate <= ?
                       ORDER BY startdate DESC LIMIT 1),
                      (SELECT taxkey_id
-                      FROM taxkeys 
-                      WHERE chart_id= (SELECT id  
-                                       FROM chart 
-                                       WHERE accno = ?) 
-                      AND startdate <= ? 
+                      FROM taxkeys
+                      WHERE chart_id= (SELECT id
+                                       FROM chart
+                                       WHERE accno = ?)
+                      AND startdate <= ?
                       ORDER BY startdate DESC LIMIT 1),
                      ?,
                      (SELECT link FROM chart WHERE accno = ?))|;
@@ -892,19 +903,19 @@ sub post_invoice {
         $query =
           qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id, chart_link)
              VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
-                     (SELECT tax_id 
-                      FROM taxkeys 
-                      WHERE chart_id= (SELECT id 
-                                       FROM chart 
-                                       WHERE accno = ?) 
-                      AND startdate <= ? 
+                     (SELECT tax_id
+                      FROM taxkeys
+                      WHERE chart_id= (SELECT id
+                                       FROM chart
+                                       WHERE accno = ?)
+                      AND startdate <= ?
                       ORDER BY startdate DESC LIMIT 1),
-                     (SELECT taxkey_id 
-                      FROM taxkeys 
-                      WHERE chart_id= (SELECT id 
-                                       FROM chart 
-                                       WHERE accno = ?) 
-                      AND startdate <= ? 
+                     (SELECT taxkey_id
+                      FROM taxkeys
+                      WHERE chart_id= (SELECT id
+                                       FROM chart
+                                       WHERE accno = ?)
+                      AND startdate <= ?
                       ORDER BY startdate DESC LIMIT 1),
                      ?,
                      (SELECT link FROM chart WHERE accno = ?))|;
@@ -956,19 +967,19 @@ sub post_invoice {
         $query =
         qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id, chart_link)
            VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
-                   (SELECT tax_id 
-                    FROM taxkeys 
-                    WHERE chart_id= (SELECT id  
-                                     FROM chart 
-                                     WHERE accno = ?) 
-                    AND startdate <= ? 
+                   (SELECT tax_id
+                    FROM taxkeys
+                    WHERE chart_id= (SELECT id
+                                     FROM chart
+                                     WHERE accno = ?)
+                    AND startdate <= ?
                     ORDER BY startdate DESC LIMIT 1),
-                   (SELECT taxkey_id 
-                    FROM taxkeys 
-                    WHERE chart_id= (SELECT id  
-                                     FROM chart 
-                                     WHERE accno = ?) 
-                    AND startdate <= ? 
+                   (SELECT taxkey_id
+                    FROM taxkeys
+                    WHERE chart_id= (SELECT id
+                                     FROM chart
+                                     WHERE accno = ?)
+                    AND startdate <= ?
                     ORDER BY startdate DESC LIMIT 1),
                    ?,
                    (SELECT link FROM chart WHERE accno = ?))|;
@@ -983,19 +994,19 @@ sub post_invoice {
       $query =
       qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, tax_id, taxkey, project_id, chart_link)
          VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?,
-                 (SELECT tax_id 
-                  FROM taxkeys 
-                  WHERE chart_id= (SELECT id  
-                                   FROM chart 
-                                   WHERE accno = ?) 
-                  AND startdate <= ? 
+                 (SELECT tax_id
+                  FROM taxkeys
+                  WHERE chart_id= (SELECT id
+                                   FROM chart
+                                   WHERE accno = ?)
+                  AND startdate <= ?
                   ORDER BY startdate DESC LIMIT 1),
-                 (SELECT taxkey_id 
-                  FROM taxkeys 
-                  WHERE chart_id= (SELECT id  
-                                   FROM chart 
-                                   WHERE accno = ?) 
-                  AND startdate <= ? 
+                 (SELECT taxkey_id
+                  FROM taxkeys
+                  WHERE chart_id= (SELECT id
+                                   FROM chart
+                                   WHERE accno = ?)
+                  AND startdate <= ?
                   ORDER BY startdate DESC LIMIT 1),
                  ?,
                  (SELECT link FROM chart WHERE accno = ?))|;
@@ -1042,19 +1053,19 @@ sub post_invoice {
         $query =
           qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, tax_id, taxkey, project_id, chart_link)
              VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1',
-                 (SELECT tax_id 
-                  FROM taxkeys 
-                  WHERE chart_id= (SELECT id  
-                                   FROM chart 
-                                   WHERE accno = ?) 
-                  AND startdate <= ? 
+                 (SELECT tax_id
+                  FROM taxkeys
+                  WHERE chart_id= (SELECT id
+                                   FROM chart
+                                   WHERE accno = ?)
+                  AND startdate <= ?
                   ORDER BY startdate DESC LIMIT 1),
-                 (SELECT taxkey_id 
-                  FROM taxkeys 
-                  WHERE chart_id= (SELECT id  
-                                   FROM chart 
-                                   WHERE accno = ?) 
-                  AND startdate <= ? 
+                 (SELECT taxkey_id
+                  FROM taxkeys
+                  WHERE chart_id= (SELECT id
+                                   FROM chart
+                                   WHERE accno = ?)
+                  AND startdate <= ?
                   ORDER BY startdate DESC LIMIT 1),
                  ?,
                  (SELECT link FROM chart WHERE accno = ?))|;
@@ -1174,6 +1185,7 @@ sub post_invoice {
       dbh        => $dbh,
       from       => $transdate,
       to         => $transdate,
+      trans_id   => $form->{id},
     );
 
     $datev->export;
@@ -1948,7 +1960,7 @@ sub retrieve_item {
          p.unit, p.assembly, p.bin, p.onhand,
          p.notes AS partnotes, p.notes AS longdescription,
          p.not_discountable, p.formel, p.payment_id AS part_payment_id,
-         p.price_factor_id,
+         p.price_factor_id, p.weight,
 
          pfac.factor AS price_factor,
 
@@ -2034,7 +2046,6 @@ sub retrieve_item {
     my $i = 0;
     while (my $ptr = $stw->fetchrow_hashref('NAME_lc')) {
 
-      #    if ($customertax{$ref->{accno}})
       if (($ptr->{accno} eq "") && ($ptr->{rate} == 0)) {
         $i++;
         $ptr->{accno} = $i;