X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=js%2Fkivi.Order.js;h=288af2d42e38bc35bfb5c243d11b403d7e3678cb;hb=d6b56cbd6138dd03b755a8d9f4828568cfafaf53;hp=e4cebb2f550aeaefa05c6619ae5ddb900cf0cd9c;hpb=efbdf52ccd4543b1e0f9eddecf8977e390c713c0;p=kivitendo-erp.git diff --git a/js/kivi.Order.js b/js/kivi.Order.js index e4cebb2f5..288af2d42 100644 --- a/js/kivi.Order.js +++ b/js/kivi.Order.js @@ -28,7 +28,7 @@ namespace('kivi.Order', function(ns) { } if (pos.length > 0) { - question = question || kivi.t8("Do you really want to save?"); + question = question || kivi.t8("Do you really want to continue?"); return confirm(kivi.t8("There are duplicate parts at positions") + "\n" + pos.join(', ') + "\n" + question); @@ -89,17 +89,6 @@ namespace('kivi.Order', function(ns) { $.post("controller.pl", data, kivi.eval_json_result); }; - ns.email = function(warn_on_duplicates) { - if (warn_on_duplicates && !ns.check_duplicate_parts(kivi.t8("Do you really want to send by mail?"))) return; - if (!ns.check_cv()) return; - - var data = $('#order_form').serializeArray(); - data.push({ name: 'order.language_id', value: $('#language_id').val() }); // language from print options - data.push({ name: 'action', value: 'Order/show_email_dialog' }); - - $.post("controller.pl", data, kivi.eval_json_result); - }; - var email_dialog; ns.setup_send_email_dialog = function() { @@ -164,6 +153,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,6 +164,68 @@ 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'); + // 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' }); + + $.ajax({ + url: 'controller.pl', + data: data, + method: 'POST', + dataType: 'json', + success: function(data){ + if (!data.is_standard) { + $('#currency_name').text(data.currency_name); + if (data.exchangerate) { + rate_input.val(data.exchangerate); + } else { + rate_input.val(''); + } + $('#exchangerate_settings').show(); + } else { + rate_input.val(''); + $('#exchangerate_settings').hide(); + } + if ($('#order_currency_id').val() != $('#old_currency_id').val() || + !data.is_standard && data.exchangerate != $('#old_exchangerate').val()) { + kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please check prices.')); + } + $('#old_currency_id').val($('#order_currency_id').val()); + $('#old_exchangerate').val(data.exchangerate); + } + }); + }; + + ns.exchangerate_changed = function(event) { + if (kivi.parse_amount($('#order_exchangerate_as_null_number').val()) != kivi.parse_amount($('#old_exchangerate').val())) { + kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please check prices.')); + $('#old_exchangerate').val($('#order_exchangerate_as_null_number').val()); + } + }; + ns.recalc_amounts_and_taxes = function() { var data = $('#order_form').serializeArray(); data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' }); @@ -783,6 +835,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) { + $('').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 = '

' + text1 + '

' + shipto + '

' + text2 + '

'; + html = html + '

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

'; + $(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() { @@ -792,6 +915,10 @@ $(function() { $('#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 { @@ -838,4 +965,6 @@ $(function() { return false; }); + $('.reformat_number_as_null_number').change(kivi.Order.reformat_number_as_null_number); + });