X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=js%2Fkivi.DeliveryOrder.js;h=00a929450168c0c6d8fa96d058789e385ecd2e18;hb=1268bf670c06f5a66ad78a75e41ad6c15061d9bc;hp=ea6e14ba505336cac8e49b8c4a8159ef753ebf5d;hpb=d6cc1832b06d875ea85b14dd523da9ff7e32df8d;p=kivitendo-erp.git diff --git a/js/kivi.DeliveryOrder.js b/js/kivi.DeliveryOrder.js index ea6e14ba5..00a929450 100644 --- a/js/kivi.DeliveryOrder.js +++ b/js/kivi.DeliveryOrder.js @@ -1,6 +1,6 @@ -namespace('kivi.Order', function(ns) { +namespace('kivi.DeliveryOrder', function(ns) { ns.check_cv = function() { - if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation') { + if ($('#type').val() == 'sales_delivery_order') { if ($('#order_customer_id').val() === '') { alert(kivi.t8('Please select a customer.')); return false; @@ -51,14 +51,14 @@ namespace('kivi.Order', function(ns) { if (warn_on_reqdate && !ns.check_valid_reqdate()) return; var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/' + action }); + data.push({ name: 'action', value: 'DeliveryOrder/' + action }); $.post("controller.pl", data, kivi.eval_json_result); }; ns.delete_order = function() { var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/delete' }); + data.push({ name: 'action', value: 'DeliveryOrder/delete' }); $.post("controller.pl", data, kivi.eval_json_result); }; @@ -78,12 +78,72 @@ namespace('kivi.Order', function(ns) { }); }; + ns.open_stock_in_out_dialog = function(clicked, in_out) { + var $row = $(clicked).parents("tbody").first(); + var id = $row.find('[name="orderitem_ids[+]"]').val(); + $row.uniqueId(); + + kivi.popup_dialog({ + id: "stock_in_out_dialog", + url: "controller.pl?action=DeliveryOrder/stock_in_out_dialog", + data: { + id: $("#id").val(), + type: $("#type").val(), + parts_id: $row.find("[name$=parts_id]").val(), + unit: $row.find("[name$=unit]").val(), + qty_as_number: $row.find("[name$=qty_as_number]").val(), + stock: $row.find("[name$=stock_info]").val(), + item_id: id, + row: $row.attr("id"), + }, + dialog: { title: kivi.t8('Transfer stock') } + }); + }; + + ns.save_updated_stock = function() { + // stock information is saved in DOM as a yaml dump. + // we don't want to do this in javascript so we do a tiny roundtrip to the backend + + let data = []; + $("#stock-in-out-table tr.listrow").each((i,row) => { + let qty = kivi.parse_amount($(row).find(".data-qty").val()); + + if (qty === 0) return; + + data.push({ + qty: qty, + warehouse_id: $(row).find(".data-warehouse-id").val(), + bin_id: $(row).find(".data-bin-id").val(), + chargenumber: $(row).find(".data-chargenumber").val(), + bestbefore: $(row).find(".data-bestbefore").val(), + unit: $(row).find(".data-unit").val(), + delivery_order_items_stock_id: $(row).find(".data-stock-id").val(), + }); + }); + + let row = $(".data-row").val(); + + $.post("controller.pl", + kivi.serialize({ + action: "DeliveryOrder/update_stock_information", + unit: $("#" + row).find("[name$=unit]").val(), + stock_info: data, + row: row + }), + (data) => { + $("#" + row + " .data-stock-info").val(data.stock_info); + $("#" + row + " .data-stock-qty").text(data.stock_qty) + $("#stock_in_out_dialog").dialog("close"); + } + ); + }; + ns.print = function() { $('#print_options').dialog('close'); var data = $('#order_form').serializeArray(); data = data.concat($('#print_options_form').serializeArray()); - data.push({ name: 'action', value: 'Order/print' }); + data.push({ name: 'action', value: 'DeliveryOrder/print' }); $.post("controller.pl", data, kivi.eval_json_result); }; @@ -115,7 +175,7 @@ namespace('kivi.Order', function(ns) { height: 600, title: kivi.t8('Send email'), modal: true, - beforeClose: kivi.Order.finish_send_email_dialog, + beforeClose: kivi.DeliveryOrder.finish_send_email_dialog, close: function(event, ui) { email_dialog.remove(); } @@ -127,7 +187,7 @@ namespace('kivi.Order', function(ns) { email_dialog.html(html); email_dialog.dialog(dialog_params); - kivi.Order.setup_send_email_dialog(); + kivi.DeliveryOrder.setup_send_email_dialog(); $('.cancel').click(ns.close_email_dialog); @@ -141,7 +201,7 @@ namespace('kivi.Order', function(ns) { var data = $('#order_form').serializeArray(); data = data.concat($('[name^="email_form."]').serializeArray()); data = data.concat($('[name^="print_options."]').serializeArray()); - data.push({ name: 'action', value: 'Order/send_email' }); + data.push({ name: 'action', value: 'DeliveryOrder/send_email' }); $.post("controller.pl", data, kivi.eval_json_result); }; @@ -162,7 +222,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' }); + data.push({ name: 'action', value: 'DeliveryOrder/customer_vendor_changed' }); $.post("controller.pl", data, kivi.eval_json_result); }; @@ -196,7 +256,7 @@ namespace('kivi.Order', function(ns) { } var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/update_exchangerate' }); + data.push({ name: 'action', value: 'DeliveryOrder/update_exchangerate' }); $.ajax({ url: 'controller.pl', @@ -243,7 +303,7 @@ namespace('kivi.Order', function(ns) { $(select_elt).data('oldval', $(select_elt).val()); var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/unit_changed' }, + data.push({ name: 'action', value: 'DeliveryOrder/unit_changed' }, { name: 'item_id', value: item_id_dom.val() }, { name: 'old_unit', value: oldval }, { name: 'sellprice_dom_id', value: sellprice_dom.attr('id') }); @@ -267,7 +327,7 @@ namespace('kivi.Order', function(ns) { return; } var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/load_second_rows' }, + data.push({ name: 'action', value: 'DeliveryOrder/load_second_rows' }, { name: 'item_ids[]', value: item_id_dom.val() }); $.post("controller.pl", data, kivi.eval_json_result); @@ -288,7 +348,7 @@ namespace('kivi.Order', function(ns) { } var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/load_second_rows' }); + data.push({ name: 'action', value: 'DeliveryOrder/load_second_rows' }); data = data.concat(item_ids); $.post("controller.pl", data, kivi.eval_json_result); @@ -409,7 +469,7 @@ namespace('kivi.Order', function(ns) { $('#' + order_by + '_header_id a').append('' + kivi.t8('sort items') + ''); var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/reorder_items' }, + data.push({ name: 'action', value: 'DeliveryOrder/reorder_items' }, { name: 'order_by', value: order_by }, { name: 'sort_dir', value: dir }); @@ -451,7 +511,7 @@ namespace('kivi.Order', function(ns) { var insert_before_item_id = ns.get_insert_before_item_id($('#add_item_position').val()); var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/add_item' }, + data.push({ name: 'action', value: 'DeliveryOrder/add_item' }, { name: 'insert_before_item_id', value: insert_before_item_id }); $.post("controller.pl", data, kivi.eval_json_result); @@ -468,7 +528,7 @@ namespace('kivi.Order', function(ns) { ns.add_multi_items = function(data) { var insert_before_item_id = ns.get_insert_before_item_id($('#multi_items_position').val()); data = data.concat($('#order_form').serializeArray()); - data.push({ name: 'action', value: 'Order/add_multi_items' }, + data.push({ name: 'action', value: 'DeliveryOrder/add_multi_items' }, { name: 'insert_before_item_id', value: insert_before_item_id }); $.post("controller.pl", data, kivi.eval_json_result); }; @@ -510,86 +570,18 @@ namespace('kivi.Order', function(ns) { var item_id_dom = $(row).find('[name="orderitem_ids[+]"]'); var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/price_popup' }, + data.push({ name: 'action', value: 'DeliveryOrder/price_popup' }, { name: 'item_id', value: item_id_dom.val() }); $.post("controller.pl", data, kivi.eval_json_result); }; - ns.update_price_source = function(item_id, source, descr, price_str, price_editable) { - var row = $('#item_' + item_id).parents("tbody").first(); - var source_elt = $(row).find('[name="order.orderitems[].active_price_source"]'); - var button_elt = $(row).find('[name="price_chooser_button"]'); - - button_elt.val(button_elt.val().replace(/.*\|/, descr + " |")); - source_elt.val(source); - - var editable_div_elt = $(row).find('[name="editable_price"]'); - var not_editable_div_elt = $(row).find('[name="not_editable_price"]'); - if (price_editable == 1 && source === '') { - // editable - $(editable_div_elt).show(); - $(not_editable_div_elt).hide(); - $(editable_div_elt).find(':input').prop("disabled", false); - $(not_editable_div_elt).find(':input').prop("disabled", true); - } else { - // not editable - $(editable_div_elt).hide(); - $(not_editable_div_elt).show(); - $(editable_div_elt).find(':input').prop("disabled", true); - $(not_editable_div_elt).find(':input').prop("disabled", false); - } - - if (price_str) { - 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); - } - - kivi.io.close_dialog(); - }; - - ns.update_discount_source = function(item_id, source, descr, discount_str, price_editable) { - var row = $('#item_' + item_id).parents("tbody").first(); - var source_elt = $(row).find('[name="order.orderitems[].active_discount_source"]'); - var button_elt = $(row).find('[name="price_chooser_button"]'); - - button_elt.val(button_elt.val().replace(/\|.*/, "| " + descr)); - source_elt.val(source); - - var editable_div_elt = $(row).find('[name="editable_discount"]'); - var not_editable_div_elt = $(row).find('[name="not_editable_discount"]'); - if (price_editable == 1 && source === '') { - // editable - $(editable_div_elt).show(); - $(not_editable_div_elt).hide(); - $(editable_div_elt).find(':input').prop("disabled", false); - $(not_editable_div_elt).find(':input').prop("disabled", true); - } else { - // not editable - $(editable_div_elt).hide(); - $(not_editable_div_elt).show(); - $(editable_div_elt).find(':input').prop("disabled", true); - $(not_editable_div_elt).find(':input').prop("disabled", false); - } - - if (discount_str) { - var discount_elt = $(row).find('[name="order.orderitems[].discount_as_percent"]'); - var html_elt = $(row).find('[name="discount_text"]'); - discount_elt.val(discount_str); - html_elt.html(discount_str); - } - - kivi.io.close_dialog(); - }; - ns.show_vc_details_dialog = function() { if (!ns.check_cv()) return; var vc; var vc_id; var title; - if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) { + if ($('#order_customer_id').val()) { vc = 'customer'; vc_id = $('#order_customer_id').val(); title = kivi.t8('Customer details'); @@ -601,7 +593,7 @@ namespace('kivi.Order', function(ns) { kivi.popup_dialog({ url: 'controller.pl', - data: { action: 'Order/show_customer_vendor_details_dialog', + data: { action: 'DeliveryOrder/show_customer_vendor_details_dialog', type : $('#type').val(), vc : vc, vc_id : vc_id @@ -621,7 +613,7 @@ namespace('kivi.Order', function(ns) { var item_id_dom = $(row).find('[name="orderitem_ids[+]"]'); var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/update_row_from_master_data' }); + data.push({ name: 'action', value: 'DeliveryOrder/update_row_from_master_data' }); data.push({ name: 'item_ids[]', value: item_id_dom.val() }); $.post("controller.pl", data, kivi.eval_json_result); @@ -638,7 +630,7 @@ namespace('kivi.Order', function(ns) { } var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/update_row_from_master_data' }); + data.push({ name: 'action', value: 'DeliveryOrder/update_row_from_master_data' }); data = data.concat(item_ids); $.post("controller.pl", data, kivi.eval_json_result); @@ -661,7 +653,7 @@ namespace('kivi.Order', function(ns) { ns.purchase_order_check_for_direct_delivery = function() { if ($('#type').val() != 'sales_order') { - kivi.submit_form_with_action($('#order_form'), 'Order/purchase_order'); + kivi.submit_form_with_action($('#order_form'), 'DeliveryOrder/purchase_order'); } var empty = true; @@ -691,7 +683,7 @@ namespace('kivi.Order', function(ns) { if (!empty) { ns.direct_delivery_dialog(shipto); } else { - kivi.submit_form_with_action($('#order_form'), 'Order/purchase_order'); + kivi.submit_form_with_action($('#order_form'), 'DeliveryOrder/purchase_order'); } }; @@ -702,7 +694,7 @@ namespace('kivi.Order', function(ns) { $('').appendTo('#order_form').val('1'); } - kivi.submit_form_with_action($('#order_form'), 'Order/purchase_order'); + kivi.submit_form_with_action($('#order_form'), 'DeliveryOrder/purchase_order'); }; ns.direct_delivery_dialog = function(shipto) { @@ -712,9 +704,9 @@ namespace('kivi.Order', function(ns) { 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 = '

' + text1 + '

' + shipto + '

' + text2 + '

'; html = html + '

'; - html = html + ''; + html = html + ''; html = html + ' '; - html = html + ''; + html = html + ''; html = html + '

'; $(html).hide().appendTo('#order_form'); @@ -764,7 +756,7 @@ namespace('kivi.Order', function(ns) { ns.create_part = function() { var data = $('#order_form').serializeArray(); - data.push({ name: 'action', value: 'Order/create_part' }); + data.push({ name: 'action', value: 'DeliveryOrder/create_part' }); $.post("controller.pl", data, kivi.eval_json_result); }; @@ -772,37 +764,29 @@ namespace('kivi.Order', function(ns) { }); $(function() { - if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) { - $('#order_customer_id').change(kivi.Order.reload_cv_dependent_selections); - } else { - $('#order_vendor_id').change(kivi.Order.reload_cv_dependent_selections); - } - - $('#order_currency_id').change(kivi.Order.update_exchangerate); - $('#order_transdate_as_date').change(kivi.Order.update_exchangerate); - $('#order_exchangerate_as_null_number').change(kivi.Order.exchangerate_changed); - - if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) { - $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) }); - } else { - $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.lastcost, -2)) }); - } + $('#order_customer_id').change(kivi.DeliveryOrder.reload_cv_dependent_selections); + $('#order_vendor_id').change(kivi.DeliveryOrder.reload_cv_dependent_selections); + + $('#order_currency_id').change(kivi.DeliveryOrder.update_exchangerate); + $('#order_transdate_as_date').change(kivi.DeliveryOrder.update_exchangerate); + $('#order_exchangerate_as_null_number').change(kivi.DeliveryOrder.exchangerate_changed); + $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_description').val(o.description) }); $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) }); $('.add_item_input').keydown(function(event) { if (event.keyCode == 13) { event.preventDefault(); - kivi.Order.add_item(); + kivi.DeliveryOrder.add_item(); return false; } }); - kivi.Order.init_row_handlers(); + kivi.DeliveryOrder.init_row_handlers(); $('#row_table_id').on('sortstop', function(event, ui) { $('#row_table_id thead a img').remove(); - kivi.Order.renumber_positions(); + kivi.DeliveryOrder.renumber_positions(); }); $('#expand_all').on('click', function(event) { @@ -813,21 +797,21 @@ $(function() { $('#expand_all').attr('alt', kivi.t8('Show all details')); $('#expand_all').attr('title', kivi.t8('Show all details')); $('.row_entry').each(function(idx, elt) { - kivi.Order.hide_second_row(elt); + kivi.DeliveryOrder.hide_second_row(elt); }); } else { $('#expand_all').data('expanded', 1); $('#expand_all').attr('src', "image/collapse.svg"); $('#expand_all').attr('alt', kivi.t8('Hide all details')); $('#expand_all').attr('title', kivi.t8('Hide all details')); - kivi.Order.load_all_second_rows(); + kivi.DeliveryOrder.load_all_second_rows(); $('.row_entry').each(function(idx, elt) { - kivi.Order.show_second_row(elt); + kivi.DeliveryOrder.show_second_row(elt); }); } return false; }); - $('.reformat_number_as_null_number').change(kivi.Order.reformat_number_as_null_number); + $('.reformat_number_as_null_number').change(kivi.DeliveryOrder.reformat_number_as_null_number); });