CVars: Lieferadressen-CVars in Stammdaten bearbeiten
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 5 Apr 2016 10:43:53 +0000 (12:43 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 6 Apr 2016 14:05:32 +0000 (16:05 +0200)
SL/Controller/CustomerVendor.pm
SL/DB/Shipto.pm
js/kivi.CustomerVendor.js
templates/webpages/customer_vendor/tabs/shipto.html

index 7685e8b..46857cb 100644 (file)
@@ -198,7 +198,7 @@ sub _save {
 
     $self->{shipto}->trans_id($self->{cv}->id);
     if( $self->{shipto}->shiptoname ne '' ) {
-      $self->{shipto}->save();
+      $self->{shipto}->save(cascade => 1);
     }
 
     my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber;
@@ -529,7 +529,8 @@ sub action_get_delivery {
 sub action_ajaj_get_shipto {
   my ($self) = @_;
 
-  my $data = {
+  my $data = {};
+  $data->{shipto} = {
     map(
       {
         my $name = 'shipto'. $_;
@@ -539,6 +540,8 @@ sub action_ajaj_get_shipto {
     )
   };
 
+  $data->{shipto_cvars} = $self->_prepare_cvar_configs_for_ajaj($self->{shipto}->cvars_by_config);
+
   $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
 }
 
@@ -755,6 +758,7 @@ sub _instantiate_args {
 
   $self->_copy_form_to_cvars(target => $self->{cv},      source => $::form->{cv_cvars});
   $self->_copy_form_to_cvars(target => $self->{contact}, source => $::form->{contact_cvars});
+  $self->_copy_form_to_cvars(target => $self->{shipto},  source => $::form->{shipto_cvars});
 }
 
 sub _load_customer_vendor {
index 3da07fb..5e2813d 100644 (file)
@@ -4,6 +4,10 @@ use strict;
 
 use SL::DB::MetaSetup::Shipto;
 use SL::DB::Manager::Shipto;
+use SL::DB::Helper::CustomVariables (
+  module      => 'ShipTo',
+  cvars_alias => 1,
+);
 
 our @SHIPTO_VARIABLES = qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptogln shiptocontact
                            shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2);
index 1b5bba2..d682067 100644 (file)
@@ -2,28 +2,23 @@ namespace('kivi.CustomerVendor', function(ns) {
 
   this.selectShipto = function(params) {
     var shiptoId = $('#shipto_shipto_id').val();
+    var url      = 'controller.pl?action=CustomerVendor/ajaj_get_shipto&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&shipto_id='+ shiptoId;
 
-    if( shiptoId ) {
-      var url = 'controller.pl?action=CustomerVendor/ajaj_get_shipto&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&shipto_id='+ shiptoId;
+    $.getJSON(url, function(data) {
+      var shipto = data.shipto;
+      for(var key in shipto)
+        $('#shipto_'+ key).val(shipto[key])
 
-      $.getJSON(url, function(data) {
-        for(var key in data)
-          $('#shipto_'+ key).val(data[key]);
+      kivi.CustomerVendor.setCustomVariablesFromAJAJ(data.shipto_cvars, 'shipto_cvars_');
 
+      if ( shiptoId )
         $('#action_delete_shipto').show();
+      else
+        $('#action_delete_shipto').hide();
 
-        if( params.onFormSet )
-          params.onFormSet();
-      });
-    }
-    else {
-      $('#shipto :input').not(':button, :submit, :reset, :hidden').val('');
-
-      $('#action_delete_shipto').hide();
-
-      if( params.onFormSet )
+      if ( params.onFormSet )
         params.onFormSet();
-    }
+    });
   };
 
   this.selectDelivery = function(fromDate, toDate) {
@@ -41,10 +36,10 @@ namespace('kivi.CustomerVendor', function(ns) {
     }
   };
 
-  this.setCustomVariablesFromAJAJ = function(cvars) {
+  this.setCustomVariablesFromAJAJ = function(cvars, prefix) {
     for (var key in cvars) {
       var cvar  = cvars[key];
-      var $ctrl = $('#contact_cvars_'+ key);
+      var $ctrl = $('#' + prefix + key);
 
       if (cvar.type == 'bool')
         $ctrl.prop('checked', cvar.value == 1 ? 'checked' : '');
@@ -70,7 +65,7 @@ namespace('kivi.CustomerVendor', function(ns) {
       for(var key in contact)
         $('#contact_'+ key).val(contact[key])
 
-      kivi.CustomerVendor.setCustomVariablesFromAJAJ(data.contact_cvars);
+      kivi.CustomerVendor.setCustomVariablesFromAJAJ(data.contact_cvars, 'contact_cvars_');
 
       if ( contactId )
         $('#action_delete_contact').show();
index fa5d5d3..b881fb0 100644 (file)
         [% L.input_tag('shipto.shiptoemail', SELF.shipto.shiptoemail,  size = 45) %]
       </td>
     </tr>
+
+    [% shipto_cvars = SELF.shipto.cvars_by_config %]
+
+    [% IF ( shipto_cvars.size ) %]
+      <tr>
+        <td colspan="2">
+          <hr>
+        </td>
+      </tr>
+
+      [% FOREACH var = shipto_cvars %]
+        <tr>
+          <th align="right" valign="top" nowrap>[% var.config.description | html %]</th>
+
+          <td valign="top">
+            [% INCLUDE 'common/render_cvar_input.html'
+                       cvar_name_prefix = 'shipto_cvars.'
+            %]
+          </td>
+        </tr>
+      [% END %]
+    [% END %]
   </table>
 
   [% L.button_tag('submitInputButton(this);', LxERP.t8('Delete Shipto'), name = 'action_delete_shipto', class = 'submit') %]