]> wagnertech.de Git - mfinanz.git/blobdiff - js/kivi.Order.js
Auftrags-Controller: Workflow VK->EK: Lieferadresse für direkte Lieferung
[mfinanz.git] / js / kivi.Order.js
index 4d7971d18c64fd05280f63fd3e5b1f766a5c31a0..a62be8838cd0df8940cdd62c4650c09131c2740c 100644 (file)
@@ -164,6 +164,7 @@ namespace('kivi.Order', function(ns) {
   };
 
   ns.reload_cv_dependent_selections = function() {
+    $('#order_shipto_id').val('');
     var data = $('#order_form').serializeArray();
     data.push({ name: 'action', value: 'Order/customer_vendor_changed' });
 
@@ -174,9 +175,29 @@ namespace('kivi.Order', function(ns) {
     $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
   };
 
+  ns.reformat_number_as_null_number = function(event) {
+    if ($(event.target).val() === '') {
+      return;
+    }
+    ns.reformat_number(event);
+  };
+
   ns.update_exchangerate = function(event) {
+    if (!ns.check_cv()) {
+      $('#order_currency_id').val($('#old_currency_id').val());
+      return;
+    }
+
     var rate_input = $('#order_exchangerate_as_null_number');
-    rate_input.prop('disabled', true);
+    // unset exchangerate if currency changed
+    if ($('#order_currency_id').val() !== $('#old_currency_id').val()) {
+      rate_input.val('');
+    }
+
+    // only set exchangerate if unset
+    if (rate_input.val() !== '') {
+      return;
+    }
 
     var data = $('#order_form').serializeArray();
     data.push({ name: 'action', value: 'Order/update_exchangerate' });
@@ -189,17 +210,14 @@ namespace('kivi.Order', function(ns) {
       success: function(data){
         if (!data.is_standard) {
           $('#currency_name').text(data.currency_name);
-          var rate_text = $('#exchangerate_text');
           if (data.exchangerate) {
-            rate_text.text(data.exchangerate);
-            rate_input.hide();
+            rate_input.val(data.exchangerate);
           } else {
-            rate_text.text('');
-            rate_input.prop('disabled', false);
-            rate_input.show().val(0);
+            rate_input.val('');
           }
           $('#exchangerate_settings').show();
         } else {
+          rate_input.val('');
           $('#exchangerate_settings').hide();
         }
         if ($('#order_currency_id').val() != $('#old_currency_id').val() ||
@@ -828,6 +846,77 @@ namespace('kivi.Order', function(ns) {
     return true;
   };
 
+  ns.edit_custom_shipto = function() {
+    if (!ns.check_cv()) return;
+
+    kivi.SalesPurchase.edit_custom_shipto();
+  };
+
+  ns.purchase_order_check_for_direct_delivery = function() {
+    if ($('#type').val() != 'sales_order') {
+      kivi.submit_form_with_action($('#order_form'), 'Order/purchase_order');
+    }
+
+    var empty = true;
+    var shipto;
+    if ($('#order_shipto_id').val() !== '') {
+      empty = false;
+      shipto = $('#order_shipto_id option:selected').text();
+    } else {
+      $('#shipto_inputs [id^="shipto"]').each(function(idx, elt) {
+        if (!empty)                                     return true;
+        if (/^shipto_to_copy/.test($(elt).prop('id')))  return true;
+        if (/^shiptocp_gender/.test($(elt).prop('id'))) return true;
+        if (/^shiptocvar_/.test($(elt).prop('id')))     return true;
+        if ($(elt).val() !== '') {
+          empty = false;
+          return false;
+        }
+      });
+      var shipto_elements = [];
+      $([$('#shiptoname').val(), $('#shiptostreet').val(), $('#shiptozipcode').val(), $('#shiptocity').val()]).each(function(idx, elt) {
+        if (elt !== '') shipto_elements.push(elt);
+      });
+      shipto = shipto_elements.join('; ');
+    }
+
+    var use_it = false;
+    if (!empty) {
+      ns.direct_delivery_dialog(shipto);
+    } else {
+      kivi.submit_form_with_action($('#order_form'), 'Order/purchase_order');
+    }
+  };
+
+  ns.direct_delivery_callback = function(accepted) {
+    $('#direct-delivery-dialog').dialog('close');
+
+    if (accepted) {
+      $('<input type="hidden" name="use_shipto">').appendTo('#order_form').val('1');
+    }
+
+    kivi.submit_form_with_action($('#order_form'), 'Order/purchase_order');
+  };
+
+  ns.direct_delivery_dialog = function(shipto) {
+    $('#direct-delivery-dialog').remove();
+
+    var text1 = kivi.t8('You have entered or selected the following shipping address for this customer:');
+    var text2 = kivi.t8('Do you want to carry this shipping address over to the new purchase order so that the vendor can deliver the goods directly to your customer?');
+    var html  = '<div id="direct-delivery-dialog"><p>' + text1 + '</p><p>' + shipto + '</p><p>' + text2 + '</p>';
+    html      = html + '<hr><p>';
+    html      = html + '<input type="button" value="' + kivi.t8('Yes') + '" size="30" onclick="kivi.Order.direct_delivery_callback(true)">';
+    html      = html + '&nbsp;';
+    html      = html + '<input type="button" value="' + kivi.t8('No')  + '" size="30" onclick="kivi.Order.direct_delivery_callback(false)">';
+    html      = html + '</p></div>';
+    $(html).hide().appendTo('#order_form');
+
+    kivi.popup_dialog({id: 'direct-delivery-dialog',
+                       dialog: {title:  kivi.t8('Carry over shipping address'),
+                                height: 300,
+                                width:  500 }});
+  };
+
 });
 
 $(function() {
@@ -887,4 +976,6 @@ $(function() {
     return false;
   });
 
+  $('.reformat_number_as_null_number').change(kivi.Order.reformat_number_as_null_number);
+
 });