namespace('kivi.Order', function(ns) {
ns.check_cv = function() {
- if ($('#type').val() == 'sales_order') {
+ if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
if ($('#order_customer_id').val() === '') {
alert(kivi.t8('Please select a customer.'));
return false;
return true;
};
- ns.save = function(warn_on_duplicates) {
+ ns.save = function(action, warn_on_duplicates) {
if (!ns.check_cv()) return;
if (warn_on_duplicates && !ns.check_save_duplicate_parts()) return;
var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/save' });
-
- $.post("controller.pl", data, kivi.eval_json_result);
- };
-
- ns.save_and_delivery_order = function(warn_on_duplicates) {
- if (!ns.check_cv()) return;
- if (warn_on_duplicates && !ns.check_save_duplicate_parts()) return;
-
- var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/save_and_delivery_order' });
+ data.push({ name: 'action', value: 'Order/' + action });
$.post("controller.pl", data, kivi.eval_json_result);
};
var email_dialog;
+ ns.setup_send_email_dialog = function() {
+ kivi.SalesPurchase.show_all_print_options_elements();
+ kivi.SalesPurchase.show_print_options_elements([ 'sendmode', 'media', 'copies', 'remove_draft' ], false);
+
+ $('#print_options_form table').first().remove().appendTo('#email_form_print_options');
+
+ var to_focus = $('#email_form_to').val() === '' ? 'to' : 'subject';
+ $('#email_form_' + to_focus).focus();
+ };
+
+ ns.finish_send_email_dialog = function() {
+ kivi.SalesPurchase.show_all_print_options_elements();
+
+ $('#email_form_print_options table').first().remove().prependTo('#print_options_form');
+ return true;
+ };
+
ns.show_email_dialog = function(html) {
- var id = 'jqueryui_popup_dialog';
+ var id = 'send_email_dialog';
var dialog_params = {
id: id,
width: 800,
- height: 500,
+ height: 600,
+ title: kivi.t8('Send email'),
modal: true,
+ beforeClose: kivi.Order.finish_send_email_dialog,
close: function(event, ui) {
email_dialog.remove();
- },
+ }
};
$('#' + id).remove();
email_dialog.html(html);
email_dialog.dialog(dialog_params);
+ kivi.Order.setup_send_email_dialog();
+
$('.cancel').click(ns.close_email_dialog);
return true;
ns.send_email = function() {
var data = $('#order_form').serializeArray();
- data = data.concat($('#email_form').serializeArray());
+ data = data.concat($('[name^="email_form."]').serializeArray());
+ data = data.concat($('[name^="print_options."]').serializeArray());
data.push({ name: 'action', value: 'Order/send_email' });
$.post("controller.pl", data, kivi.eval_json_result);
};
email_dialog.dialog("close");
};
+ ns.set_number_in_title = function(elt) {
+ $('#nr_in_title').html($(elt).val());
+ };
+
ns.reload_cv_dependant_selections = function() {
var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/customer_vendor_changed' });
ns.hide_second_row = function(row) {
$(row).children().not(':first').hide();
- $(row).data('expanded', false);
+ $(row).data('expanded', 0);
var elt = $(row).find('.expand');
- elt.attr('src', "image/expand3.gif");
+ elt.attr('src', "image/expand.svg");
elt.attr('alt', kivi.t8('Show details'));
elt.attr('title', kivi.t8('Show details'));
};
ns.show_second_row = function(row) {
$(row).children().not(':first').show();
- $(row).data('expanded', true);
+ $(row).data('expanded', 1);
var elt = $(row).find('.expand');
- elt.attr('src', "image/collapse3.gif");
+ elt.attr('src', "image/collapse.svg");
elt.attr('alt', kivi.t8('Hide details'));
elt.attr('title', kivi.t8('Hide details'));
};
ns.toggle_second_row = function(row) {
- if ($(row).data('expanded') === true) {
+ if ($(row).data('expanded') == 1) {
ns.hide_second_row(row);
} else {
ns.show_second_row(row);
kivi.io.close_dialog();
};
+ ns.show_periodic_invoices_config_dialog = function() {
+ if ($('#type').val() !== 'sales_order') return;
+
+ kivi.popup_dialog({
+ url: 'controller.pl?action=Order/show_periodic_invoices_config_dialog',
+ data: { type : $('#type').val(),
+ id : $('#id').val(),
+ config : $('#order_periodic_invoices_config').val(),
+ customer_id: $('#order_customer_id').val(),
+ transdate : $('#order_transdate').val(),
+ language_id: $('#language_id').val()
+ },
+ id: 'jq_periodic_invoices_config_dialog',
+ load: kivi.reinit_widgets,
+ dialog: {
+ title: kivi.t8('Edit the configuration for periodic invoices'),
+ width: 800,
+ height: 650
+ }
+ });
+ return true;
+ };
+
+ ns.close_periodic_invoices_config_dialog = function() {
+ $('#jq_periodic_invoices_config_dialog').dialog('close');
+ };
+
+ ns.assign_periodic_invoices_config = function() {
+ var data = $('[name="Form"]').serializeArray();
+ data.push({ name: 'type', value: $('#type').val() });
+ data.push({ name: 'action', value: 'Order/assign_periodic_invoices_config' });
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.check_save_active_periodic_invoices = function() {
+ var type = $('#type').val();
+ if (type !== 'sales_order') return true;
+
+ var active = false;
+ $.ajax({
+ url: 'controller.pl',
+ data: { action: 'Order/get_has_active_periodic_invoices',
+ type : type,
+ id : $('#id').val(),
+ config: $('#order_periodic_invoices_config').val(),
+ },
+ method: "GET",
+ async: false,
+ dataType: 'text',
+ success: function(val){
+ active = val;
+ }
+ });
+
+ if (active == 1) {
+ return confirm(kivi.t8('This sales order has an active configuration for periodic invoices. If you save then all subsequently created invoices will contain those changes as well, but not those that have already been created. Do you want to continue?'));
+ }
+
+ return true;
+ };
+
});
$(function(){
- if ($('#type').val() == 'sales_order') {
+ if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
$('#order_customer_id').change(kivi.Order.reload_cv_dependant_selections);
} else {
$('#order_vendor_id').change(kivi.Order.reload_cv_dependant_selections);
}
- if ($('#type').val() == 'sales_order') {
+ 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)) });
$('#expand_all').on('click', function(event) {
event.preventDefault();
- if ($('#expand_all').data('expanded') === true) {
- $('#expand_all').data('expanded', false);
- $('#expand_all').attr('src', 'image/expand3.gif');
+ if ($('#expand_all').data('expanded') == 1) {
+ $('#expand_all').data('expanded', 0);
+ $('#expand_all').attr('src', 'image/expand.svg');
$('#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);
});
} else {
- $('#expand_all').data('expanded', true);
- $('#expand_all').attr('src', "image/collapse3.gif");
+ $('#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();
}
return false;
});
+
});