Rechnungen: Nicht editierbare CVars nicht rendern, aber richtig speichern bzw. drucken.
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Tue, 27 Jan 2015 14:05:59 +0000 (15:05 +0100)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Tue, 27 Jan 2015 16:19:16 +0000 (17:19 +0100)
Die Änderung für Rechnungen (u. Gutschriften) fehlte noch im commit
6b4a71ff376e8337b708127f9f6c63c1d70d0af3
(Nicht editierbare CVars nicht rendern, aber richtig speichern und drucken.)

SL/IR.pm
SL/IS.pm

index 7a7f57c..dd04248 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -369,6 +369,7 @@ sub post_invoice {
 
     next if $payments_only;
 
+    my $cvars;
     if (!$form->{"invoice_id_$i"}) {
       # there is no persistent id, therefore create one with all necessary constraints
       my $q_invoice_id = qq|SELECT nextval('invoiceid')|;
@@ -379,7 +380,22 @@ sub post_invoice {
       do_query($form, $dbh, $q_create_invoice_id, conv_i($form->{"invoice_id_$i"}),
                conv_i($form->{id}), conv_i($position), conv_i($form->{"id_$i"}));
       $h_invoice_id->finish();
+
+      # get values for CVars from master data for new items
+      $cvars = CVar->get_custom_variables(dbh      => $dbh,
+                                          module   => 'IC',
+                                          trans_id => $form->{"id_$i"},
+                                         );
+    } else {
+      # get values for CVars from custom_variables for existing items
+      $cvars = CVar->get_custom_variables(dbh        => $dbh,
+                                          module     => 'IC',
+                                          sub_module => 'invoice',
+                                          trans_id   => $form->{"invoice_id_$i"},
+                                         );
     }
+    # map only non-editable CVars to form (editable ones are already there)
+    map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars };
 
       # save detail record in invoice table
       $query = <<SQL;
index 7b1871e..a647653 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -373,6 +373,24 @@ sub invoice_details {
         $sth->finish;
       }
 
+      my $cvars;
+      if (! $form->{"invoice_id_$i"}) {
+        # get values for CVars from master data for new items
+        $cvars = CVar->get_custom_variables(dbh      => $dbh,
+                                            module   => 'IC',
+                                            trans_id => $form->{"id_$i"},
+                                           );
+      } else {
+        # get values for CVars from custom_variables for existing items
+        $cvars = CVar->get_custom_variables(dbh        => $dbh,
+                                            module     => 'IC',
+                                            sub_module => 'invoice',
+                                            trans_id   => $form->{"invoice_id_$i"},
+                                           );
+      }
+      # map only non-editable CVars to form (editable ones are already there)
+      map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars };
+
       push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} },
         CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_)
           for @{ $ic_cvar_configs };
@@ -749,6 +767,7 @@ sub post_invoice {
       $pricegroup_id *= 1;
       $pricegroup_id  = undef if !$pricegroup_id;
 
+      my $cvars;
       if (!$form->{"invoice_id_$i"}) {
         # there is no persistent id, therefore create one with all necessary constraints
         my $q_invoice_id = qq|SELECT nextval('invoiceid')|;
@@ -759,7 +778,22 @@ sub post_invoice {
         do_query($form, $dbh, $q_create_invoice_id, conv_i($form->{"invoice_id_$i"}),
                  conv_i($form->{id}), conv_i($position), conv_i($form->{"id_$i"}));
         $h_invoice_id->finish();
+
+        # get values for CVars from master data for new items
+        $cvars = CVar->get_custom_variables(dbh      => $dbh,
+                                            module   => 'IC',
+                                            trans_id => $form->{"id_$i"},
+                                           );
+      } else {
+        # get values for CVars from custom_variables for existing items
+        $cvars = CVar->get_custom_variables(dbh        => $dbh,
+                                            module     => 'IC',
+                                            sub_module => 'invoice',
+                                            trans_id   => $form->{"invoice_id_$i"},
+                                           );
       }
+      # map only non-editable CVars to form (editable ones are already there)
+      map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars };
 
       # save detail record in invoice table
       $query = <<SQL;