Revision 68da3b40
Von Bernd Bleßmann vor mehr als 6 Jahren hinzugefügt
js/kivi.Order.js | ||
---|---|---|
1 | 1 |
namespace('kivi.Order', function(ns) { |
2 | 2 |
ns.check_cv = function() { |
3 |
if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
|
|
3 |
if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation') { |
|
4 | 4 |
if ($('#order_customer_id').val() === '') { |
5 | 5 |
alert(kivi.t8('Please select a customer.')); |
6 | 6 |
return false; |
... | ... | |
15 | 15 |
}; |
16 | 16 |
|
17 | 17 |
ns.check_save_duplicate_parts = function() { |
18 |
var id_arr = $('[name="order.orderitems[].parts_id"]').map(function() {return this.value;}).get();
|
|
18 |
var id_arr = $('[name="order.orderitems[].parts_id"]').map(function() { return this.value; }).get();
|
|
19 | 19 |
|
20 | 20 |
var i, obj = {}, pos = []; |
21 | 21 |
|
... | ... | |
47 | 47 |
ns.save = function(action, warn_on_duplicates, warn_on_reqdate) { |
48 | 48 |
if (!ns.check_cv()) return; |
49 | 49 |
if (warn_on_duplicates && !ns.check_save_duplicate_parts()) return; |
50 |
if (warn_on_reqdate && !ns.check_valid_reqdate()) return; |
|
50 |
if (warn_on_reqdate && !ns.check_valid_reqdate()) return;
|
|
51 | 51 |
|
52 | 52 |
var data = $('#order_form').serializeArray(); |
53 | 53 |
data.push({ name: 'action', value: 'Order/' + action }); |
... | ... | |
86 | 86 |
}; |
87 | 87 |
|
88 | 88 |
ns.download_pdf = function(pdf_filename, key) { |
89 |
var data = []; |
|
90 |
data.push({ name: 'action', value: 'Order/download_pdf' }); |
|
91 |
data.push({ name: 'type', value: $('#type').val() }); |
|
92 |
data.push({ name: 'pdf_filename', value: pdf_filename }); |
|
93 |
data.push({ name: 'key', value: key }); |
|
89 |
var data = [{ name: 'action', value: 'Order/download_pdf' }, |
|
90 |
{ name: 'type', value: $('#type').val() }, |
|
91 |
{ name: 'pdf_filename', value: pdf_filename }, |
|
92 |
{ name: 'key', value: key }]; |
|
94 | 93 |
$.download("controller.pl", data); |
95 | 94 |
}; |
96 | 95 |
|
... | ... | |
183 | 182 |
}; |
184 | 183 |
|
185 | 184 |
ns.unit_change = function(event) { |
186 |
var row = $(event.target).parents("tbody").first(); |
|
187 |
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]'); |
|
185 |
var row = $(event.target).parents("tbody").first();
|
|
186 |
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
|
|
188 | 187 |
var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]'); |
189 |
var select_elt = $(row).find('[name="order.orderitems[].unit"]'); |
|
188 |
var select_elt = $(row).find('[name="order.orderitems[].unit"]');
|
|
190 | 189 |
|
191 | 190 |
var oldval = $(select_elt).data('oldval'); |
192 | 191 |
$(select_elt).data('oldval', $(select_elt).val()); |
193 | 192 |
|
194 | 193 |
var data = $('#order_form').serializeArray(); |
195 |
data.push({ name: 'action', value: 'Order/unit_changed' });
|
|
196 |
data.push({ name: 'item_id', value: item_id_dom.val() });
|
|
197 |
data.push({ name: 'old_unit', value: oldval });
|
|
198 |
data.push({ name: 'sellprice_dom_id', value: sellprice_dom.attr('id') });
|
|
194 |
data.push({ name: 'action', value: 'Order/unit_changed' },
|
|
195 |
{ name: 'item_id', value: item_id_dom.val() },
|
|
196 |
{ name: 'old_unit', value: oldval },
|
|
197 |
{ name: 'sellprice_dom_id', value: sellprice_dom.attr('id') });
|
|
199 | 198 |
|
200 | 199 |
$.post("controller.pl", data, kivi.eval_json_result); |
201 | 200 |
}; |
202 | 201 |
|
203 | 202 |
ns.update_sellprice = function(item_id, price_str) { |
204 |
var row = $('#item_' + item_id).parents("tbody").first(); |
|
203 |
var row = $('#item_' + item_id).parents("tbody").first();
|
|
205 | 204 |
var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]'); |
206 | 205 |
var html_elt = $(row).find('[name="sellprice_text"]'); |
207 | 206 |
price_elt.val(price_str); |
... | ... | |
210 | 209 |
|
211 | 210 |
ns.load_second_row = function(row) { |
212 | 211 |
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]'); |
213 |
var div_elt = $(row).find('[name="second_row"]'); |
|
212 |
var div_elt = $(row).find('[name="second_row"]');
|
|
214 | 213 |
|
215 | 214 |
if ($(div_elt).data('loaded') == 1) { |
216 | 215 |
return; |
217 | 216 |
} |
218 | 217 |
var data = $('#order_form').serializeArray(); |
219 |
data.push({ name: 'action', value: 'Order/load_second_rows' });
|
|
220 |
data.push({ name: 'item_ids[]', value: item_id_dom.val() });
|
|
218 |
data.push({ name: 'action', value: 'Order/load_second_rows' },
|
|
219 |
{ name: 'item_ids[]', value: item_id_dom.val() });
|
|
221 | 220 |
|
222 | 221 |
$.post("controller.pl", data, kivi.eval_json_result); |
223 | 222 |
}; |
... | ... | |
285 | 284 |
|
286 | 285 |
kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) { |
287 | 286 |
$(elt).keydown(function(event) { |
288 |
if(event.keyCode == 40 && event.shiftKey === true) { |
|
287 |
if (event.keyCode == 40 && event.shiftKey === true) {
|
|
289 | 288 |
// shift arrow down |
290 | 289 |
event.preventDefault(); |
291 | 290 |
var row = $(event.target).parents(".row_entry").first(); |
... | ... | |
293 | 292 |
ns.show_second_row(row); |
294 | 293 |
return false; |
295 | 294 |
} |
296 |
if(event.keyCode == 38 && event.shiftKey === true) { |
|
295 |
if (event.keyCode == 38 && event.shiftKey === true) {
|
|
297 | 296 |
// shift arrow up |
298 | 297 |
event.preventDefault(); |
299 | 298 |
var row = $(event.target).parents(".row_entry").first(); |
... | ... | |
352 | 351 |
$('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="' + kivi.t8('sort items') + '">'); |
353 | 352 |
|
354 | 353 |
var data = $('#order_form').serializeArray(); |
355 |
data.push({ name: 'action', value: 'Order/reorder_items' });
|
|
356 |
data.push({ name: 'order_by', value: order_by });
|
|
357 |
data.push({ name: 'sort_dir', value: dir });
|
|
354 |
data.push({ name: 'action', value: 'Order/reorder_items' },
|
|
355 |
{ name: 'order_by', value: order_by },
|
|
356 |
{ name: 'sort_dir', value: dir });
|
|
358 | 357 |
|
359 | 358 |
$.post("controller.pl", data, kivi.eval_json_result); |
360 | 359 |
}; |
... | ... | |
388 | 387 |
|
389 | 388 |
kivi.popup_dialog({ |
390 | 389 |
url: 'controller.pl?action=Order/show_multi_items_dialog', |
391 |
data: { type: $('#type').val(), |
|
392 |
callback: 'Order/add_multi_items', |
|
390 |
data: { type: $('#type').val(),
|
|
391 |
callback: 'Order/add_multi_items',
|
|
393 | 392 |
callback_data_id: 'order_form' }, |
394 | 393 |
id: 'jq_multi_items_dialog', |
395 | 394 |
dialog: { |
396 |
title: kivi.t8('Add multiple items'), |
|
395 |
title: kivi.t8('Add multiple items'),
|
|
397 | 396 |
width: 800, |
398 | 397 |
height: 500 |
399 | 398 |
} |
... | ... | |
418 | 417 |
}; |
419 | 418 |
|
420 | 419 |
ns.show_longdescription_dialog = function(clicked) { |
421 |
var row = $(clicked).parents("tbody").first(); |
|
422 |
var position = $(row).find('[name="position"]').html(); |
|
423 |
var partnumber = $(row).find('[name="partnumber"]').html(); |
|
424 |
var description_elt = $(row).find('[name="order.orderitems[].description"]'); |
|
425 |
var description = description_elt.val(); |
|
420 |
var row = $(clicked).parents("tbody").first();
|
|
421 |
var position = $(row).find('[name="position"]').html();
|
|
422 |
var partnumber = $(row).find('[name="partnumber"]').html();
|
|
423 |
var description_elt = $(row).find('[name="order.orderitems[].description"]');
|
|
424 |
var description = description_elt.val();
|
|
426 | 425 |
var longdescription_elt = $(row).find('[name="order.orderitems[].longdescription"]'); |
427 | 426 |
var longdescription; |
428 | 427 |
|
429 | 428 |
if (!longdescription_elt.length) { |
430 |
var data = []; |
|
431 |
data.push({ name: 'action', value: 'Order/get_item_longdescription' }); |
|
432 |
data.push({ name: 'type', value: $('#type').val() }); |
|
433 |
data.push({ name: 'item_id', value: $(row).find('[name="order.orderitems[+].id"]').val() }); |
|
434 |
data.push({ name: 'parts_id', value: $(row).find('[name="order.orderitems[].parts_id"]').val() }); |
|
429 |
var data = [ |
|
430 |
{ name: 'action', value: 'Order/get_item_longdescription' }, |
|
431 |
{ name: 'type', value: $('#type').val() }, |
|
432 |
{ name: 'item_id', value: $(row).find('[name="order.orderitems[+].id"]').val() }, |
|
433 |
{ name: 'parts_id', value: $(row).find('[name="order.orderitems[].parts_id"]').val() } |
|
434 |
]; |
|
435 |
|
|
435 | 436 |
$.ajax({ |
436 |
url: 'controller.pl', |
|
437 |
data: data, |
|
438 |
method: "GET", |
|
439 |
async: false, |
|
437 |
url: 'controller.pl',
|
|
438 |
data: data,
|
|
439 |
method: "GET",
|
|
440 |
async: false,
|
|
440 | 441 |
dataType: 'text', |
441 |
success: function(val){
|
|
442 |
success: function(val) {
|
|
442 | 443 |
longdescription = val; |
443 | 444 |
} |
444 | 445 |
}); |
... | ... | |
446 | 447 |
longdescription = longdescription_elt.val(); |
447 | 448 |
} |
448 | 449 |
|
449 |
var params = { runningnumber: position, |
|
450 |
partnumber: partnumber, |
|
451 |
description: description, |
|
452 |
default_longdescription: longdescription, |
|
453 |
set_function: function(val){ |
|
454 |
longdescription_elt.remove(); |
|
455 |
$('<input type="hidden" name="order.orderitems[].longdescription">').insertAfter(description_elt).val(val); |
|
456 |
} |
|
457 |
}; |
|
450 |
var params = { |
|
451 |
runningnumber: position, |
|
452 |
partnumber: partnumber, |
|
453 |
description: description, |
|
454 |
default_longdescription: longdescription, |
|
455 |
set_function: function(val) { |
|
456 |
longdescription_elt.remove(); |
|
457 |
$('<input type="hidden" name="order.orderitems[].longdescription">').insertAfter(description_elt).val(val); |
|
458 |
} |
|
459 |
}; |
|
458 | 460 |
|
459 | 461 |
kivi.SalesPurchase.edit_longdescription_with_params(params); |
460 | 462 |
}; |
461 | 463 |
|
462 | 464 |
ns.price_chooser_item_row = function(clicked) { |
463 | 465 |
if (!ns.check_cv()) return; |
464 |
var row = $(clicked).parents("tbody").first(); |
|
466 |
var row = $(clicked).parents("tbody").first();
|
|
465 | 467 |
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]'); |
466 | 468 |
|
467 | 469 |
var data = $('#order_form').serializeArray(); |
468 |
data.push({ name: 'action', value: 'Order/price_popup' });
|
|
469 |
data.push({ name: 'item_id', value: item_id_dom.val() });
|
|
470 |
data.push({ name: 'action', value: 'Order/price_popup' },
|
|
471 |
{ name: 'item_id', value: item_id_dom.val() });
|
|
470 | 472 |
|
471 | 473 |
$.post("controller.pl", data, kivi.eval_json_result); |
472 | 474 |
}; |
473 | 475 |
|
474 | 476 |
ns.update_price_source = function(item_id, source, descr, price_str, price_editable) { |
475 |
var row = $('#item_' + item_id).parents("tbody").first(); |
|
477 |
var row = $('#item_' + item_id).parents("tbody").first();
|
|
476 | 478 |
var source_elt = $(row).find('[name="order.orderitems[].active_price_source"]'); |
477 | 479 |
var button_elt = $(row).find('[name="price_chooser_button"]'); |
478 | 480 |
|
479 | 481 |
button_elt.val(button_elt.val().replace(/.*\|/, descr + " |")); |
480 | 482 |
source_elt.val(source); |
481 | 483 |
|
482 |
var editable_div_elt = $(row).find('[name="editable_price"]'); |
|
484 |
var editable_div_elt = $(row).find('[name="editable_price"]');
|
|
483 | 485 |
var not_editable_div_elt = $(row).find('[name="not_editable_price"]'); |
484 | 486 |
if (price_editable == 1 && source === '') { |
485 | 487 |
// editable |
... | ... | |
507 | 509 |
}; |
508 | 510 |
|
509 | 511 |
ns.update_discount_source = function(item_id, source, descr, discount_str, price_editable) { |
510 |
var row = $('#item_' + item_id).parents("tbody").first(); |
|
512 |
var row = $('#item_' + item_id).parents("tbody").first();
|
|
511 | 513 |
var source_elt = $(row).find('[name="order.orderitems[].active_discount_source"]'); |
512 | 514 |
var button_elt = $(row).find('[name="price_chooser_button"]'); |
513 | 515 |
|
514 | 516 |
button_elt.val(button_elt.val().replace(/\|.*/, "| " + descr)); |
515 | 517 |
source_elt.val(source); |
516 | 518 |
|
517 |
var editable_div_elt = $(row).find('[name="editable_discount"]'); |
|
519 |
var editable_div_elt = $(row).find('[name="editable_discount"]');
|
|
518 | 520 |
var not_editable_div_elt = $(row).find('[name="not_editable_discount"]'); |
519 | 521 |
if (price_editable == 1 && source === '') { |
520 | 522 |
// editable |
... | ... | |
545 | 547 |
if ($('#type').val() !== 'sales_order') return; |
546 | 548 |
|
547 | 549 |
kivi.popup_dialog({ |
548 |
url: 'controller.pl?action=Order/show_periodic_invoices_config_dialog', |
|
549 |
data: { type : $('#type').val(),
|
|
550 |
id : $('#id').val(),
|
|
551 |
config : $('#order_periodic_invoices_config').val(),
|
|
552 |
customer_id: $('#order_customer_id').val(), |
|
553 |
transdate : $('#order_transdate').val(),
|
|
554 |
language_id: $('#language_id').val() |
|
555 |
}, |
|
556 |
id: 'jq_periodic_invoices_config_dialog', |
|
557 |
load: kivi.reinit_widgets, |
|
550 |
url: 'controller.pl?action=Order/show_periodic_invoices_config_dialog',
|
|
551 |
data: { type: $('#type').val(),
|
|
552 |
id: $('#id').val(),
|
|
553 |
config: $('#order_periodic_invoices_config').val(),
|
|
554 |
customer_id: $('#order_customer_id').val(),
|
|
555 |
transdate: $('#order_transdate').val(),
|
|
556 |
language_id: $('#language_id').val()
|
|
557 |
},
|
|
558 |
id: 'jq_periodic_invoices_config_dialog',
|
|
559 |
load: kivi.reinit_widgets,
|
|
558 | 560 |
dialog: { |
559 |
title: kivi.t8('Edit the configuration for periodic invoices'), |
|
561 |
title: kivi.t8('Edit the configuration for periodic invoices'),
|
|
560 | 562 |
width: 800, |
561 | 563 |
height: 650 |
562 | 564 |
} |
... | ... | |
570 | 572 |
|
571 | 573 |
ns.assign_periodic_invoices_config = function() { |
572 | 574 |
var data = $('[name="Form"]').serializeArray(); |
573 |
data.push({ name: 'type', value: $('#type').val() });
|
|
574 |
data.push({ name: 'action', value: 'Order/assign_periodic_invoices_config' });
|
|
575 |
data.push({ name: 'type', value: $('#type').val() },
|
|
576 |
{ name: 'action', value: 'Order/assign_periodic_invoices_config' });
|
|
575 | 577 |
$.post("controller.pl", data, kivi.eval_json_result); |
576 | 578 |
}; |
577 | 579 |
|
... | ... | |
581 | 583 |
|
582 | 584 |
var active = false; |
583 | 585 |
$.ajax({ |
584 |
url: 'controller.pl', |
|
585 |
data: { action: 'Order/get_has_active_periodic_invoices', |
|
586 |
type : type, |
|
587 |
id : $('#id').val(), |
|
588 |
config: $('#order_periodic_invoices_config').val(), |
|
589 |
}, |
|
590 |
method: "GET", |
|
591 |
async: false, |
|
586 |
url: 'controller.pl',
|
|
587 |
data: { action: 'Order/get_has_active_periodic_invoices',
|
|
588 |
type : type,
|
|
589 |
id : $('#id').val(),
|
|
590 |
config: $('#order_periodic_invoices_config').val(),
|
|
591 |
},
|
|
592 |
method: "GET",
|
|
593 |
async: false,
|
|
592 | 594 |
dataType: 'text', |
593 |
success: function(val){
|
|
595 |
success: function(val) {
|
|
594 | 596 |
active = val; |
595 | 597 |
} |
596 | 598 |
}); |
... | ... | |
618 | 620 |
} |
619 | 621 |
|
620 | 622 |
kivi.popup_dialog({ |
621 |
url: 'controller.pl', |
|
622 |
data: { action: 'Order/show_customer_vendor_details_dialog', |
|
623 |
type : $('#type').val(), |
|
624 |
vc : vc, |
|
625 |
vc_id : vc_id |
|
626 |
}, |
|
627 |
id: 'jq_customer_vendor_details_dialog', |
|
623 |
url: 'controller.pl',
|
|
624 |
data: { action: 'Order/show_customer_vendor_details_dialog',
|
|
625 |
type : $('#type').val(),
|
|
626 |
vc : vc,
|
|
627 |
vc_id : vc_id
|
|
628 |
},
|
|
629 |
id: 'jq_customer_vendor_details_dialog',
|
|
628 | 630 |
dialog: { |
629 |
title: title, |
|
631 |
title: title,
|
|
630 | 632 |
width: 800, |
631 | 633 |
height: 650 |
632 | 634 |
} |
... | ... | |
635 | 637 |
}; |
636 | 638 |
|
637 | 639 |
ns.show_calculate_qty_dialog = function(clicked) { |
638 |
var row = $(clicked).parents("tbody").first(); |
|
639 |
var input_id = $(row).find('[name="order.orderitems[].qty_as_number"]').attr('id'); |
|
640 |
var row = $(clicked).parents("tbody").first();
|
|
641 |
var input_id = $(row).find('[name="order.orderitems[].qty_as_number"]').attr('id');
|
|
640 | 642 |
var formula_id = $(row).find('[name="formula[+]"]').attr('id'); |
641 | 643 |
|
642 | 644 |
calculate_qty_selection_dialog("", input_id, "", formula_id); |
643 | 645 |
return true; |
644 |
} |
|
646 |
};
|
|
645 | 647 |
|
646 | 648 |
}); |
647 | 649 |
|
648 |
$(function(){ |
|
650 |
$(function() {
|
|
649 | 651 |
if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) { |
650 | 652 |
$('#order_customer_id').change(kivi.Order.reload_cv_dependant_selections); |
651 | 653 |
} else { |
... | ... | |
661 | 663 |
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) }); |
662 | 664 |
|
663 | 665 |
$('.add_item_input').keydown(function(event) { |
664 |
if(event.keyCode == 13) { |
|
666 |
if (event.keyCode == 13) {
|
|
665 | 667 |
event.preventDefault(); |
666 | 668 |
kivi.Order.add_item(); |
667 | 669 |
return false; |
Auch abrufbar als: Unified diff
Auftrags-Controller: kivi.Order.js: Kosmetik
- alignement
- whitespaces
- weniger data.push