]> wagnertech.de Git - mfinanz.git/blobdiff - templates/webpages/order/tabs/basic_data.html
Auftrags-Controller: serializeArray und push statt serialize und += auf Strings
[mfinanz.git] / templates / webpages / order / tabs / basic_data.html
index 27032e0e503d416a466ae12eac4cb843b57d16c0..b3c9fa050333cfd0cf70f3b45698a55ee90abbc1 100644 (file)
@@ -3,6 +3,8 @@
 [%- USE LxERP %]
 [%- USE L %]
 
+[%- INCLUDE 'generic/set_longdescription.html' %]
+
 <div id="ui-tabs-basic-data">
   <table width="100%">
     <tr valign="top">
             <thead>
               <tr class="listheading">
                 <th class="listheading" style='display:none'></th>
+                <th class="listheading" nowrap width="3" >[%- 'position'     | $T8 %] </th>
                 <th class="listheading" style='text-align:center' nowrap width="1"><img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]"></th>
                 <th class="listheading" style='text-align:center' nowrap width="1"><img src="image/close.png" alt="[%- LxERP.t8('delete item') %]"></th>
-                <th class="listheading" nowrap width="15">[%- 'Partnumber'   | $T8 %] </th>
-                <th class="listheading" nowrap           >[%- 'Description'  | $T8 %] </th>
-                <th class="listheading" nowrap width="5" >[%- 'Qty'          | $T8 %] </th>
+                <th id="partnumber_header_id"  class="listheading" nowrap width="15"><a href='#' onClick='javascript:reorder_items("partnumber")'> [%- 'Partnumber'  | $T8 %]</a></th>
+                <th id="description_header_id" class="listheading" nowrap           ><a href='#' onClick='javascript:reorder_items("description")'>[%- 'Description' | $T8 %]</a></th>
+                <th id="qty_header_id"         class="listheading" nowrap width="5" ><a href='#' onClick='javascript:reorder_items("qty")'>        [%- 'Qty'         | $T8 %]</a></th>
                 <th class="listheading" nowrap width="5" >[%- 'Price Factor' | $T8 %] </th>
                 <th class="listheading" nowrap width="5" >[%- 'Unit'         | $T8 %] </th>
                 <th class="listheading" nowrap width="5" >[%- 'Price Source' | $T8 %] </th>
-                <th class="listheading" nowrap width="15">[%- 'Price'        | $T8 %] </th>
-                <th class="listheading" nowrap width="5" >[%- 'Discount'     | $T8 %] </th>
+                <th id="sellprice_header_id"   class="listheading" nowrap width="15" ><a href='#' onClick='javascript:reorder_items("sellprice")'> [%- 'Price'       | $T8 %]</a></th>
+                <th id="discount_header_id"    class="listheading" nowrap width="15" ><a href='#' onClick='javascript:reorder_items("discount")'>  [%- 'Discount'    | $T8 %]</a></th>
                 <th class="listheading" nowrap width="10">[%- 'Extended'     | $T8 %] </th>
               </tr>
             </thead>
 
 <script type='text/javascript'>
 function reload_cv_dependend_selections() {
-  var data = $('#order_form').serialize();
-  data += '&action=Order/customer_vendor_changed';
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/customer_vendor_changed' });
 
   $.post("controller.pl", data, kivi.eval_json_result);
 }
 
+function unit_change(event) {
+  var row = $(event.target).parents("tbody").first();
+  var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
+  var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
+  var select_elt = $(row).find('[name="order.orderitems[].unit"]');
+
+  var oldval = $(select_elt).data('oldval');
+  $(select_elt).data('oldval', $(select_elt).val());
+
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/unit_changed' });
+  data.push({ name: 'item_id', value: item_id_dom.val() });
+  data.push({ name: 'old_unit', value: oldval });
+  data.push({ name: 'sellprice_dom_id', value: sellprice_dom.attr('id') });
+
+  $.post("controller.pl", data, kivi.eval_json_result);
+}
+
+function update_sellprice(item_id, price_str) {
+  var row = $('#item_' + item_id).parents("tbody").first();
+  var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
+  var html_elt  = $(row).find('[name="sellprice_text"]');
+  price_elt.val(price_str);
+  html_elt.html(price_str);
+}
+
 function add_item() {
   if ($('#add_item_parts_id').val() == '') return;
   if (!check_cv()) return;
 
-  var data = $('#order_form').serialize();
-  data += '&action=Order/add_item';
+  $('#row_table_id thead a img').remove();
+
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/add_item' });
 
   $.post("controller.pl", data, kivi.eval_json_result);
 }
@@ -285,6 +316,8 @@ function add_item() {
 function show_multi_items_dialog() {
   if (!check_cv()) return;
 
+  $('#row_table_id thead a img').remove();
+
   kivi.popup_dialog({
     url: 'controller.pl?action=Order/show_multi_items_dialog',
     data: { type: $('#type').val(),
@@ -308,6 +341,7 @@ function delete_order_item_row(clicked) {
   var row = $(clicked).parents("tbody").first();
   $(row).remove();
 
+  renumber_positions();
   recalc_amounts_and_taxes();
 }
 
@@ -315,9 +349,9 @@ function price_chooser_item_row(clicked) {
   var row = $(clicked).parents("tbody").first();
   var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
 
-  var data = $('#order_form').serialize();
-  data += '&action=Order/price_popup';
-  data += '&item_id=' + item_id_dom.val();
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/price_popup' });
+  data.push({ name: 'item_id', value: item_id_dom.val() });
 
   $.post("controller.pl", data, kivi.eval_json_result);
 }
@@ -397,8 +431,8 @@ function reformat_number(event) {
 }
 
 function recalc_amounts_and_taxes() {
-  var data = $('#order_form').serialize();
-  data += '&action=Order/recalc_amounts_and_taxes';
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' });
 
   $.post("controller.pl", data, kivi.eval_json_result);
 }
@@ -445,6 +479,21 @@ function row_set_keyboard_events(rows) {
   });
 }
 
+function set_unit_change_with_oldval_by_id(item_id) {
+  var row = $('#item_' + item_id).parents("tbody").first();
+  var select_elt = $(row).find('[name="order.orderitems[].unit"]');
+
+  set_unit_change_with_oldval(select_elt);
+}
+
+function set_unit_change_with_oldval(selects) {
+  selects.each(function(idx,elt) {
+    $(elt).data('oldval', $(elt).val());
+  });
+
+  selects.change(unit_change);
+}
+
 var email_dialog;
 
 function show_email_dialog(html) {
@@ -474,6 +523,86 @@ close_email_dialog = function() {
   email_dialog.dialog("close");
 }
 
+function renumber_positions() {
+  $('.row_entry [name="position"]').each(function(idx, elt) {
+    $(elt).html(idx+1);
+  });
+}
+
+function reorder_items(order_by) {
+  var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir");
+  $('#row_table_id thead a img').remove();
+
+  var src;
+  if (dir == "1") {
+    dir = "0";
+    src = "image/up.png";
+  } else {
+    dir = "1";
+    src = "image/down.png";
+  };
+
+  $('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="[%- LxERP.t8('sort items') %]">');
+
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/reorder_items' });
+  data.push({ name: 'order_by', value: order_by });
+  data.push({ name: 'sort_dir', value: dir });
+
+  $.post("controller.pl", data, kivi.eval_json_result);
+}
+
+function redisplay_items(data) {
+  var old_rows = $('.row_entry').detach();
+  var new_rows = [];
+  $(data).each(function(idx, elt) {
+    new_rows.push(old_rows[elt.old_pos - 1]);
+  });
+  $(new_rows).appendTo($('#row_table_id'));
+  renumber_positions();
+}
+
+function show_longdescription_dialog(clicked) {
+  var row = $(clicked).parents("tbody").first();
+  var position = $(row).find('[name="position"]').html();
+  var partnumber = $(row).find('[name="partnumber"]').html();
+  var description_elt = $(row).find('[name="order.orderitems[].description"]');
+  var description = description_elt.val();
+  var longdescription_elt = $(row).find('[name="order.orderitems[].longdescription"]');
+  var longdescription;
+
+  if (!longdescription_elt.length) {
+    var data = [];
+    data.push({ name: 'action', value: 'Order/get_item_longdescription' });
+    data.push({ name: 'type', value: $('#type').val() });
+    data.push({ name: 'item_id', value: $(row).find('[name="order.orderitems[+].id"]').val() });
+    data.push({ name: 'parts_id', value: $(row).find('[name="order.orderitems[].parts_id"]').val() });
+    $.ajax({
+      url: 'controller.pl',
+      data: data,
+      method: "GET",
+      async: false,
+      dataType: 'text',
+      success: function(val){
+        longdescription = val;
+      }
+    });
+  } else {
+    longdescription = longdescription_elt.val();
+  }
+
+  var params = { runningnumber: position,
+                 partnumber: partnumber,
+                 description: description,
+                 default_longdescription: longdescription,
+                 set_function: function(val){
+                   longdescription_elt.remove();
+                   $('<input type="hidden" name="order.orderitems[].longdescription">').insertAfter(description_elt).val(val);
+                 }
+               };
+
+  kivi.SalesPurchase.edit_longdescription_with_params(params);
+}
 
 $(function(){
   $('#order_[%- cv_id %]').change(reload_cv_dependend_selections);
@@ -494,6 +623,12 @@ $(function(){
   row_set_keyboard_events($('.row_entry'));
   $('.recalc').change(recalc_amounts_and_taxes);
   $('.reformat_number').change(reformat_number);
+
+  set_unit_change_with_oldval($('.unitselect'));
 });
 
+$('#row_table_id').on('sortstop', function(event, ui) {
+  $('#row_table_id thead a img').remove();
+  renumber_positions();
+});
 </script>