}
};
- ns.save = function(action, warn_on_duplicates, warn_on_reqdate) {
+ ns.save = function(action, warn_on_duplicates, warn_on_reqdate, back_to_caller) {
if (!ns.check_cv()) return;
if (warn_on_duplicates && !ns.check_duplicate_parts()) return;
if (warn_on_reqdate && !ns.check_valid_reqdate()) return;
var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/' + action });
+ if (back_to_caller) data.push({ name: 'back_to_caller', value: '1' });
+
$.post("controller.pl", data, kivi.eval_json_result);
};
ns.show_print_options = function(warn_on_duplicates, warn_on_reqdate) {
if (!ns.check_cv()) return;
if (warn_on_duplicates && !ns.check_duplicate_parts(kivi.t8("Do you really want to print?"))) return;
+ if (warn_on_reqdate && !ns.check_valid_reqdate()) return;
kivi.popup_dialog({
id: 'print_options',
$('#print_options_form table').first().remove().appendTo('#email_form_print_options');
+ $('select#format').change(kivi.Order.adjust_email_attachment_name_for_template_format);
+ kivi.Order.adjust_email_attachment_name_for_template_format();
+
var to_focus = $('#email_form_to').val() === '' ? 'to' : 'subject';
$('#email_form_' + to_focus).focus();
};
email_dialog.dialog("close");
};
+ ns.adjust_email_attachment_name_for_template_format = function() {
+ var $filename_elt = $('#email_form_attachment_filename');
+ var $format_elt = $('select#format');
+
+ if (!$filename_elt || !$format_elt)
+ return;
+
+ var format = $format_elt.val().toLowerCase();
+ var new_ext = format == 'html' ? 'html' : format == 'opendocument' ? 'odt' : 'pdf';
+ var filename = $filename_elt.val();
+
+ $filename_elt.val(filename.replace(/[^.]+$/, new_ext));
+ };
+
ns.set_number_in_title = function(elt) {
$('#nr_in_title').html($(elt).val());
};
};
ns.recalc_amounts_and_taxes = function() {
+ if (!kivi.validate_form('#order_form')) return;
+
var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' });
return insert_before_item_id;
};
+ ns.update_item_input_row = function() {
+ if (!ns.check_cv()) return;
+
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/update_item_input_row' });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
ns.add_item = function() {
if ($('#add_item_parts_id').val() === '') return;
if (!ns.check_cv()) return;
$.post("controller.pl", data, kivi.eval_json_result);
};
- ns.update_price_source = function(item_id, source, descr, price_str, price_editable) {
+ ns.set_price_and_source_text = 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"]');
var html_elt = $(row).find('[name="sellprice_text"]');
price_elt.val(price_str);
html_elt.html(price_str);
- ns.recalc_amounts_and_taxes();
}
+ };
+ ns.update_price_source = function(item_id, source, descr, price_str, price_editable) {
+ ns.set_price_and_source_text(item_id, source, descr, price_str, price_editable);
+
+ if (price_str) ns.recalc_amounts_and_taxes();
kivi.io.close_dialog();
};
- ns.update_discount_source = function(item_id, source, descr, discount_str, price_editable) {
+ ns.set_discount_and_source_text = 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"]');
var html_elt = $(row).find('[name="discount_text"]');
discount_elt.val(discount_str);
html_elt.html(discount_str);
- ns.recalc_amounts_and_taxes();
}
+ };
+ ns.update_discount_source = function(item_id, source, descr, discount_str, price_editable) {
+ ns.set_discount_and_source_text(item_id, source, descr, discount_str, price_editable);
+
+ if (discount_str) ns.recalc_amounts_and_taxes();
kivi.io.close_dialog();
};
if (number_info !== '') { info += ' (' + number_info + ')' }
if (name_info !== '') { info += ' (' + name_info + ')' }
- if (!$('#follow_up_rowcount').lenght) {
+ if (!$('#follow_up_rowcount').length) {
$('<input type="hidden" name="follow_up_rowcount" id="follow_up_rowcount">').appendTo('#order_form');
$('<input type="hidden" name="follow_up_trans_id_1" id="follow_up_trans_id_1">').appendTo('#order_form');
$('<input type="hidden" name="follow_up_trans_type_1" id="follow_up_trans_type_1">').appendTo('#order_form');
follow_up_window();
};
+ ns.create_part = function() {
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/create_part' });
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.check_transport_cost_article_presence = function() {
+ var $form = $('#order_form');
+ var wanted_part_id = $form.data('transport-cost-reminder-article-id');
+
+ if (!wanted_part_id) return true
+
+ var id_arr = $('[name="order.orderitems[].parts_id"]').map(function() { return this.value; }).get();
+ id_arr = $.grep(id_arr, function(elt) {
+ return ((elt*1) === wanted_part_id);
+ });
+
+ if (id_arr.length) return true;
+
+ var description = $form.data('transport-cost-reminder-article-description');
+ return confirm(kivi.t8("The transport cost article '#1' is missing. Do you want to continue anyway?", [ description ]));
+ };
+
+ ns.check_cusordnumber_presence = function() {
+ if ($('#order_cusordnumber').val() === '') {
+ return confirm(kivi.t8('The customer order number is missing. Do you want to continue anyway?'));
+ }
+ return true;
+ };
+
+ ns.load_phone_note = function(id, subject, body) {
+ $('#phone_note_edit_text').html(kivi.t8('Edit note'));
+ $('#phone_note_id').val(id);
+ $('#phone_note_subject').val(subject);
+ $('#phone_note_body').val(body);
+ $('#phone_note_delete_button').show();
+ };
+
+ ns.cancel_phone_note = function() {
+ $('#phone_note_edit_text').html(kivi.t8('Add note'));
+ $('#phone_note_id').val('');
+ $('#phone_note_subject').val('');
+ $('#phone_note_body').val('');
+ $('#phone_note_delete_button').hide();
+ };
+
+ ns.save_phone_note = function() {
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/save_phone_note' });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.delete_phone_note = function() {
+ if ($('#phone_note_id').val() === '') return;
+
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/delete_phone_note' });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
});
$(function() {
$('#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)) });
- }
- $('#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_parts_id').on('set_item:PartPicker', function() {
+ kivi.Order.update_item_input_row();
+ });
$('.add_item_input').keydown(function(event) {
if (event.keyCode == 13) {