$::auth->set_session_value("Order::create_pdf-${key}" => $sfile->file_name);
$self->js
- ->run('download_pdf', $pdf_filename, $key)
+ ->run('kivi.Order.download_pdf', $pdf_filename, $key)
->flash('info', t8('The PDF has been created'));
} elsif ($media eq 'printer') {
my $dialog_html = $self->render('order/tabs/_email_dialog', { output => 0 });
$self->js
- ->run('show_email_dialog', $dialog_html)
+ ->run('kivi.Order.show_email_dialog', $dialog_html)
->reinit_widgets
->render($self);
}
$self->js
->val('#order_intnotes', $intnotes)
- ->run('close_email_dialog')
+ ->run('kivi.Order.close_email_dialog')
->render($self);
}
$self->_recalc();
$self->js
- ->run('update_sellprice', $::form->{item_id}, $item->sellprice_as_number);
+ ->run('kivi.Order.update_sellprice', $::form->{item_id}, $item->sellprice_as_number);
$self->_js_redisplay_linetotals;
$self->_js_redisplay_amounts_and_taxes;
$self->js->render();
$self->js
->append('#row_table_id', $row_as_html)
->val('.add_item_input', '')
- ->run('init_row_handlers')
- ->run('row_table_scroll_down')
- ->run('renumber_positions')
+ ->run('kivi.Order.init_row_handlers')
+ ->run('kivi.Order.row_table_scroll_down')
+ ->run('kivi.Order.renumber_positions')
->focus('#add_item_parts_id_name');
$self->_js_redisplay_amounts_and_taxes;
}
$self->js
- ->run('close_multi_items_dialog')
- ->run('init_row_handlers')
- ->run('row_table_scroll_down')
- ->run('renumber_positions')
+ ->run('kivi.Order.close_multi_items_dialog')
+ ->run('kivi.Order.init_row_handlers')
+ ->run('kivi.Order.row_table_scroll_down')
+ ->run('kivi.Order.renumber_positions')
->focus('#add_item_parts_id_name');
$self->_js_redisplay_amounts_and_taxes;
@to_sort = sort { $b->{order_by} cmp $a->{order_by} } @to_sort;
}
$self->js
- ->run('redisplay_items', \@to_sort)
+ ->run('kivi.Order.redisplay_items', \@to_sort)
->render;
}
my @data = map {$::form->format_amount(\%::myconfig, $_->{linetotal}, 2, 0)} @{ $self->order->items_sorted };
$self->js
- ->run('redisplay_linetotals', \@data);
+ ->run('kivi.Order.redisplay_linetotals', \@data);
}
sub _js_redisplay_amounts_and_taxes {
} } @all_objects;
}
- $::request->{layout}->use_javascript("${_}.js") for qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery);
+ $::request->{layout}->use_javascript("${_}.js") for qw(kivi.SalesPurchase kivi.Order ckeditor/ckeditor ckeditor/adapters/jquery);
}
sub _create_pdf {
--- /dev/null
+namespace('kivi.Order', function(ns) {
+ ns.check_cv = function() {
+ if ($('#type').val() == 'sales_order') {
+ if ($('#order_customer_id').val() == '') {
+ alert(kivi.t8('Please select a customer.'));
+ return false;
+ }
+ } else {
+ if ($('#order_vendor_id').val() == '') {
+ alert(kivi.t8('Please select a vendor.'));
+ return false;
+ }
+ }
+ return true;
+ };
+
+ ns.save = function() {
+ if (!ns.check_cv()) 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() {
+ if (!ns.check_cv()) return;
+
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/save_and_delivery_order' });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.delete_order = function() {
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/delete' });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.show_print_options = function() {
+ if (!ns.check_cv()) return;
+
+ kivi.popup_dialog({
+ id: 'print_options',
+ dialog: {
+ title: kivi.t8('Print options'),
+ width: 800,
+ height: 300
+ }
+ });
+ };
+
+ 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' });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.download_pdf = function(pdf_filename, key) {
+ var data = [];
+ data.push({ name: 'action', value: 'Order/download_pdf' });
+ data.push({ name: 'type', value: $('#type').val() });
+ data.push({ name: 'pdf_filename', value: pdf_filename });
+ data.push({ name: 'key', value: key });
+ $.download("controller.pl", data);
+ };
+
+ ns.email = function() {
+ if (!ns.check_cv()) return;
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/show_email_dialog' });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ var email_dialog;
+
+ ns.show_email_dialog = function(html) {
+ var id = 'jqueryui_popup_dialog';
+ var dialog_params = {
+ id: id,
+ width: 800,
+ height: 500,
+ modal: true,
+ close: function(event, ui) {
+ email_dialog.remove();
+ },
+ };
+
+ $('#' + id).remove();
+
+ email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
+ email_dialog.html(html);
+ email_dialog.dialog(dialog_params);
+
+ $('.cancel').click(ns.close_email_dialog);
+
+ return true;
+ };
+
+ ns.send_email = function() {
+ var data = $('#order_form').serializeArray();
+ data = data.concat($('#email_form').serializeArray());
+ data.push({ name: 'action', value: 'Order/send_email' });
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.close_email_dialog = function() {
+ email_dialog.dialog("close");
+ };
+
+ ns.reload_cv_dependend_selections = function() {
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/customer_vendor_changed' });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.reformat_number = function(event) {
+ $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
+ };
+
+ ns.recalc_amounts_and_taxes = function() {
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.unit_change = function(event) {
+ var row = $(event.target).parents("tbody").first();
+ var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
+ var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
+ var select_elt = $(row).find('[name="order.orderitems[].unit"]');
+
+ var oldval = $(select_elt).data('oldval');
+ $(select_elt).data('oldval', $(select_elt).val());
+
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/unit_changed' });
+ data.push({ name: 'item_id', value: item_id_dom.val() });
+ data.push({ name: 'old_unit', value: oldval });
+ data.push({ name: 'sellprice_dom_id', value: sellprice_dom.attr('id') });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.update_sellprice = function(item_id, price_str) {
+ var row = $('#item_' + item_id).parents("tbody").first();
+ 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);
+ };
+
+ ns.init_row_handlers = function() {
+ kivi.run_once_for('.recalc', 'on_change_recalc', function(elt) {
+ $(elt).change(ns.recalc_amounts_and_taxes);
+ });
+
+ kivi.run_once_for('.reformat_number', 'on_change_reformat', function(elt) {
+ $(elt).change(ns.reformat_number);
+ });
+
+ kivi.run_once_for('.unitselect', 'on_change_unit_with_oldval', function(elt) {
+ $(elt).data('oldval', $(elt).val());
+ $(elt).change(ns.unit_change);
+ });
+
+ kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) {
+ $(elt).keydown(function(event) {
+ if(event.keyCode == 40 && event.shiftKey == true) {
+ // shift arrow down
+ event.preventDefault();
+ var row = $(event.target).parents(".row_entry").first();
+ $(row).children().not(':first').show();
+ return false;
+ }
+ if(event.keyCode == 38 && event.shiftKey == true) {
+ // shift arrow up
+ event.preventDefault();
+ var row = $(event.target).parents(".row_entry").first();
+ $(row).children().not(':first').hide();
+ return false;
+ }
+ });
+ $(elt).dblclick(function(event) {
+ event.preventDefault();
+ var row = $(event.target).parents(".row_entry").first();
+ $(row).children().not(':first').toggle();
+ return false;
+ });
+ });
+ };
+
+ ns.redisplay_linetotals = function(data) {
+ $('.row_entry [name="linetotal"]').each(function(idx, elt) {
+ $(elt).html(data[idx]);
+ });
+ };
+
+ ns.renumber_positions = function() {
+ $('.row_entry [name="position"]').each(function(idx, elt) {
+ $(elt).html(idx+1);
+ });
+ };
+
+ ns.reorder_items = function(order_by) {
+ var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir");
+ $('#row_table_id thead a img').remove();
+
+ var src;
+ if (dir == "1") {
+ dir = "0";
+ src = "image/up.png";
+ } else {
+ dir = "1";
+ src = "image/down.png";
+ };
+
+ $('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="' + kivi.t8('sort items') + '">');
+
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/reorder_items' });
+ data.push({ name: 'order_by', value: order_by });
+ data.push({ name: 'sort_dir', value: dir });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.redisplay_items = function(data) {
+ var old_rows = $('.row_entry').detach();
+ var new_rows = [];
+ $(data).each(function(idx, elt) {
+ new_rows.push(old_rows[elt.old_pos - 1]);
+ });
+ $(new_rows).appendTo($('#row_table_id'));
+ ns.renumber_positions();
+ };
+
+ ns.add_item = function() {
+ if ($('#add_item_parts_id').val() == '') return;
+ if (!ns.check_cv()) return;
+
+ $('#row_table_id thead a img').remove();
+
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/add_item' });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.show_multi_items_dialog = function() {
+ if (!ns.check_cv()) return;
+
+ $('#row_table_id thead a img').remove();
+
+ kivi.popup_dialog({
+ url: 'controller.pl?action=Order/show_multi_items_dialog',
+ data: { type: $('#type').val(),
+ callback: 'Order/add_multi_items',
+ callback_data_id: 'order_form' },
+ id: 'jq_multi_items_dialog',
+ dialog: {
+ title: kivi.t8('Add multiple items'),
+ width: 800,
+ height: 500
+ }
+ });
+ return true;
+ };
+
+ ns.close_multi_items_dialog = function() {
+ $('#jq_multi_items_dialog').dialog('close');
+ };
+
+ ns.delete_order_item_row = function(clicked) {
+ var row = $(clicked).parents("tbody").first();
+ $(row).remove();
+
+ ns.renumber_positions();
+ ns.recalc_amounts_and_taxes();
+ };
+
+ ns.row_table_scroll_down = function() {
+ $('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight);
+ };
+
+ ns.show_longdescription_dialog = function(clicked) {
+ var row = $(clicked).parents("tbody").first();
+ var position = $(row).find('[name="position"]').html();
+ var partnumber = $(row).find('[name="partnumber"]').html();
+ var description_elt = $(row).find('[name="order.orderitems[].description"]');
+ var description = description_elt.val();
+ var longdescription_elt = $(row).find('[name="order.orderitems[].longdescription"]');
+ var longdescription;
+
+ if (!longdescription_elt.length) {
+ var data = [];
+ data.push({ name: 'action', value: 'Order/get_item_longdescription' });
+ data.push({ name: 'type', value: $('#type').val() });
+ data.push({ name: 'item_id', value: $(row).find('[name="order.orderitems[+].id"]').val() });
+ data.push({ name: 'parts_id', value: $(row).find('[name="order.orderitems[].parts_id"]').val() });
+ $.ajax({
+ url: 'controller.pl',
+ data: data,
+ method: "GET",
+ async: false,
+ dataType: 'text',
+ success: function(val){
+ longdescription = val;
+ }
+ });
+ } else {
+ longdescription = longdescription_elt.val();
+ }
+
+ var params = { runningnumber: position,
+ partnumber: partnumber,
+ description: description,
+ default_longdescription: longdescription,
+ set_function: function(val){
+ longdescription_elt.remove();
+ $('<input type="hidden" name="order.orderitems[].longdescription">').insertAfter(description_elt).val(val);
+ }
+ };
+
+ kivi.SalesPurchase.edit_longdescription_with_params(params);
+ };
+
+ ns.price_chooser_item_row = function(clicked) {
+ var row = $(clicked).parents("tbody").first();
+ 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: '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);
+ ns.recalc_amounts_and_taxes();
+ }
+
+ 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);
+ ns.recalc_amounts_and_taxes();
+ }
+
+ kivi.io.close_dialog();
+ };
+
+});
+
+$(function(){
+ if ($('#type').val() == 'sales_order') {
+ $('#order_customer_id').change(kivi.Order.reload_cv_dependend_selections);
+ } else {
+ $('#order_vendor_id').change(kivi.Order.reload_cv_dependend_selections);
+ }
+
+ if ($('#type').val() == 'sales_order') {
+ $('#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_input').keydown(function(event) {
+ if(event.keyCode == 13) {
+ event.preventDefault();
+ kivi.Order.add_item();
+ return false;
+ }
+ });
+
+ kivi.Order.init_row_handlers();
+
+ $('#row_table_id').on('sortstop', function(event, ui) {
+ $('#row_table_id thead a img').remove();
+ kivi.Order.renumber_positions();
+ });
+});
<form method="post" action="controller.pl" id="print_options_form">
[% SELF.print_options %]
<br>
- [% L.button_tag('print()', LxERP.t8('Print')) %]
+ [% L.button_tag('kivi.Order.print()', LxERP.t8('Print')) %]
<a href="#" onclick="$('#print_options').dialog('close');">[% LxERP.t8("Cancel") %]</a>
</form>
</div>
[% L.hidden_tag('action', 'Order/dispatch') %]
- [% L.button_tag('save()', LxERP.t8('Save')) %]
- [% L.button_tag('show_print_options()', LxERP.t8('Print')) %]
- [% L.button_tag('email()', LxERP.t8('E-mail')) %]
- [% L.button_tag('save_and_delivery_order()', LxERP.t8('Save and Delivery Order')) %]
+ [% L.button_tag('kivi.Order.save()', LxERP.t8('Save')) %]
+ [% L.button_tag('kivi.Order.show_print_options()', LxERP.t8('Print')) %]
+ [% L.button_tag('kivi.Order.email()', LxERP.t8('E-mail')) %]
+ [% L.button_tag('kivi.Order.save_and_delivery_order()', LxERP.t8('Save and Delivery Order')) %]
[%- IF SELF.order.id && ( (SELF.cv == 'customer' && INSTANCE_CONF.get_sales_order_show_delete) || (SELF.cv == 'vendor' && INSTANCE_CONF.get_purchase_order_show_delete) ) %]
- [% L.button_tag('delete_order()', LxERP.t8('Delete'), confirm=LxERP.t8("Are you sure?")) %]
+ [% L.button_tag('kivi.Order.delete_order()', LxERP.t8('Delete'), confirm=LxERP.t8("Are you sure?")) %]
[%- END %]
</form>
-
-
-<script type='text/javascript'>
-
-function delete_order() {
- var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/delete' });
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function save() {
- if (!check_cv()) return;
- var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/save' });
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function show_print_options() {
- if (!check_cv()) return;
-
- kivi.popup_dialog({
- id: 'print_options',
- dialog: {
- title: kivi.t8('Print options'),
- width: 800,
- height: 300
- }
- });
-}
-
-function print() {
- $('#print_options').dialog('close');
-
- var data = $('#order_form').serializeArray();
- data = data.concat($('#print_options_form').serializeArray());
- data.push({ name: 'action', value: 'Order/print' });
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function download_pdf(pdf_filename, key) {
- var data = [];
- data.push({ name: 'action', value: 'Order/download_pdf' });
- data.push({ name: 'type', value: $('#type').val() });
- data.push({ name: 'pdf_filename', value: pdf_filename });
- data.push({ name: 'key', value: key });
- $.download("controller.pl", data);
-}
-
-function email() {
- if (!check_cv()) return;
- var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/show_email_dialog' });
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function save_and_delivery_order() {
- if (!check_cv()) return;
- var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/save_and_delivery_order' });
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function check_cv() {
- if ($('#order_[%- cv_id %]').val() == '') {
- [%- IF SELF.cv == 'customer' %]
- alert(kivi.t8('Please select a customer.'));
- [%- ELSE %]
- alert(kivi.t8('Please select a vendor.'));
- [%- END %]
- return false;
- }
- return true;
-}
-</script>
<br>
[% L.hidden_tag('action', 'Order/dispatch') %]
-[% L.button_tag('send_email()', LxERP.t8('Continue')) %]
-<a href="#" onclick="close_email_dialog();">[%- LxERP.t8("Cancel") %]</a>
-
-<script type='text/javascript'>
-function send_email() {
- var data = $('#order_form').serializeArray();
- data = data.concat($('#email_form').serializeArray());
- data.push({ name: 'action', value: 'Order/send_email' });
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-</script>
+[% L.button_tag('kivi.Order.send_email()', LxERP.t8('Continue')) %]
+<a href="#" onclick="kivi.Order.close_email_dialog();">[%- LxERP.t8("Cancel") %]</a>
</form>
</td>
<td>[% L.input_tag('add_item.sellprice_as_number', '', size = 10, class="add_item_input numeric") %]</td>
<td>[% L.input_tag('add_item.discount_as_percent', '', size = 5, class="add_item_input numeric") %]</td>
- <td>[% L.button_tag('add_item()', LxERP.t8('Add part')) %]</td>
+ <td>[% L.button_tag('kivi.Order.add_item()', LxERP.t8('Add part')) %]</td>
</tr>
</tbody>
</table>
<hr>
[% L.button_tag('add_multi_items()', LxERP.t8('Continue'), id='continue_button') %]
-<a href="#" onclick="close_multi_items_dialog();">[%- LxERP.t8("Cancel") %]</a>
+<a href="#" onclick="kivi.Order.close_multi_items_dialog();">[%- LxERP.t8("Cancel") %]</a>
<script type='text/javascript'>
function update_result() {
[%- USE LxERP %]
[% SET best_price = price_source.best_price %]
[% SET best_discount = price_source.best_discount %]
+[% SET price_editable = AUTH.assert('edit_prices', 1) %]
<h2>[% 'Prices' | $T8 %]</h2>
<table>
</tr>
<tr class='listrow'>
[%- IF price_source.record_item.active_price_source %]
- <td>[% L.button_tag('update_price_source(\'' _ FORM.item_id _ '\', \'\', \'' _ LxERP.t8('None (PriceSource)') _ '\')', LxERP.t8('Select')) %]</td>
+ <td>[% L.button_tag('kivi.Order.update_price_source(\'' _ FORM.item_id _ '\', \'\', \'' _ LxERP.t8('None (PriceSource)') _ '\', \'\', ' _ price_editable _ ')', LxERP.t8('Select')) %]</td>
[%- ELSE %]
<td><b>[% 'Selected' | $T8 %]</b></td>
[%- END %]
[%- FOREACH price IN price_source.available_prices %]
<tr class='listrow'>
[%- IF price_source.record_item.active_price_source != price.source %]
- <td>[% L.button_tag('update_price_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ LxERP.format_amount(price.price, -2) _ '\')', LxERP.t8('Select')) %]</td>
+ <td>[% L.button_tag('kivi.Order.update_price_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ LxERP.format_amount(price.price, -2) _ '\', ' _ price_editable _ ')', LxERP.t8('Select')) %]</td>
[%- ELSIF price_source.record_item.sellprice * 1 != price.price * 1 %]
- <td>[% L.button_tag('update_price_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ LxERP.format_amount(price.price, -2) _ '\')', LxERP.t8('Update Price')) %]</td>
+ <td>[% L.button_tag('kivi.Order.update_price_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ LxERP.format_amount(price.price, -2) _ '\', ' _ price_editable _ ')', LxERP.t8('Update Price')) %]</td>
[%- ELSE %]
<td><b>[% 'Selected' | $T8 %]</b></td>
[% END %]
</tr>
<tr class='listrow'>
[%- IF price_source.record_item.active_discount_source %]
- <td>[% L.button_tag('update_discount_source(\'' _ FORM.item_id _ '\', \'\', \'' _ LxERP.t8('None (PriceSource Discount)') _ '\')', LxERP.t8('Select')) %]</td>
+ <td>[% L.button_tag('kivi.Order.update_discount_source(\'' _ FORM.item_id _ '\', \'\', \'' _ LxERP.t8('None (PriceSource Discount)') _ '\', \'\', ' _ price_editable _ ')', LxERP.t8('Select')) %]</td>
[%- ELSE %]
<td><b>[% 'Selected' | $T8 %]</b></td>
[%- END %]
[%- FOREACH price IN price_source.available_discounts %]
<tr class='listrow'>
[%- IF price_source.record_item.active_discount_source != price.source %]
- <td>[% L.button_tag('update_discount_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ price.discount_as_percent _ '\')', LxERP.t8('Select')) %]</td>
+ <td>[% L.button_tag('kivi.Order.update_discount_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ price.discount_as_percent _ '\', ' _ price_editable _ ')', LxERP.t8('Select')) %]</td>
[%- ELSIF price_source.record_item.discount * 1 != price.discount * 1 %]
- <td>[% L.button_tag('update_discount_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ price.discount_as_percent _ '\')', LxERP.t8('Update Discount')) %]</td>
+ <td>[% L.button_tag('kivi.Order.update_discount_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ price.discount_as_percent _ '\', ' _ price_editable _ ')', LxERP.t8('Update Discount')) %]</td>
[%- ELSE %]
<td><b>[% 'Selected' | $T8 %]</b></td>
[% END %]
<img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]" class="dragdrop">
</td>
<td align="center">
- [%- L.button_tag("delete_order_item_row(this)",
+ [%- L.button_tag("kivi.Order.delete_order_item_row(this)",
LxERP.t8("X"),
confirm=LxERP.t8("Are you sure?")) %]
</td>
[% L.input_tag("order.orderitems[].description",
ITEM.description,
style='width: 300px') %]
- [%- L.button_tag("show_longdescription_dialog(this)", LxERP.t8("L")) %]
+ [%- L.button_tag("kivi.Order.show_longdescription_dialog(this)", LxERP.t8("L")) %]
</td>
<td>
[%- L.input_tag("order.orderitems[].qty_as_number",
class = 'unitselect') %]
</td>
<td>
- [%- L.button_tag("price_chooser_item_row(this)",
+ [%- L.button_tag("kivi.Order.price_chooser_item_row(this)",
ITEM.active_price_source.source_description _ ' | ' _ ITEM.active_discount_source.source_description,
name = "price_chooser_button") %]
</td>
[%- PROCESS order/tabs/_item_input.html %]
- [% L.button_tag('show_multi_items_dialog()', LxERP.t8('Add multiple parts')) %]</td>
+ [% L.button_tag('kivi.Order.show_multi_items_dialog()', LxERP.t8('Add multiple items')) %]</td>
<table width="100%">
<tr>
<th class="listheading" nowrap width="3" >[%- 'position' | $T8 %] </th>
<th class="listheading" style='text-align:center' nowrap width="1"><img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]"></th>
<th class="listheading" style='text-align:center' nowrap width="1"><img src="image/close.png" alt="[%- LxERP.t8('delete item') %]"></th>
- <th id="partnumber_header_id" class="listheading" nowrap width="15"><a href='#' onClick='javascript:reorder_items("partnumber")'> [%- 'Partnumber' | $T8 %]</a></th>
- <th id="description_header_id" class="listheading" nowrap ><a href='#' onClick='javascript:reorder_items("description")'>[%- 'Description' | $T8 %]</a></th>
- <th id="qty_header_id" class="listheading" nowrap width="5" ><a href='#' onClick='javascript:reorder_items("qty")'> [%- 'Qty' | $T8 %]</a></th>
+ <th id="partnumber_header_id" class="listheading" nowrap width="15"><a href='#' onClick='javascript:kivi.Order.reorder_items("partnumber")'> [%- 'Partnumber' | $T8 %]</a></th>
+ <th id="description_header_id" class="listheading" nowrap ><a href='#' onClick='javascript:kivi.Order.reorder_items("description")'>[%- 'Description' | $T8 %]</a></th>
+ <th id="qty_header_id" class="listheading" nowrap width="5" ><a href='#' onClick='javascript:kivi.Order.reorder_items("qty")'> [%- 'Qty' | $T8 %]</a></th>
<th class="listheading" nowrap width="5" >[%- 'Price Factor' | $T8 %] </th>
<th class="listheading" nowrap width="5" >[%- 'Unit' | $T8 %] </th>
<th class="listheading" nowrap width="5" >[%- 'Price Source' | $T8 %] </th>
- <th id="sellprice_header_id" class="listheading" nowrap width="15" ><a href='#' onClick='javascript:reorder_items("sellprice")'> [%- 'Price' | $T8 %]</a></th>
- <th id="discount_header_id" class="listheading" nowrap width="15" ><a href='#' onClick='javascript:reorder_items("discount")'> [%- 'Discount' | $T8 %]</a></th>
+ <th id="sellprice_header_id" class="listheading" nowrap width="15" ><a href='#' onClick='javascript:kivi.Order.reorder_items("sellprice")'> [%- 'Price' | $T8 %]</a></th>
+ <th id="discount_header_id" class="listheading" nowrap width="15" ><a href='#' onClick='javascript:kivi.Order.reorder_items("discount")'> [%- 'Discount' | $T8 %]</a></th>
<th class="listheading" nowrap width="10">[%- 'Extended' | $T8 %] </th>
</tr>
</thead>
</div>
-
[% L.sortable_element('#row_table_id') %]
-
-<script type='text/javascript'>
-function reload_cv_dependend_selections() {
- var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/customer_vendor_changed' });
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function unit_change(event) {
- var row = $(event.target).parents("tbody").first();
- var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
- var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
- var select_elt = $(row).find('[name="order.orderitems[].unit"]');
-
- var oldval = $(select_elt).data('oldval');
- $(select_elt).data('oldval', $(select_elt).val());
-
- var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/unit_changed' });
- data.push({ name: 'item_id', value: item_id_dom.val() });
- data.push({ name: 'old_unit', value: oldval });
- data.push({ name: 'sellprice_dom_id', value: sellprice_dom.attr('id') });
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function update_sellprice(item_id, price_str) {
- var row = $('#item_' + item_id).parents("tbody").first();
- 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);
-}
-
-function add_item() {
- if ($('#add_item_parts_id').val() == '') return;
- if (!check_cv()) return;
-
- $('#row_table_id thead a img').remove();
-
- var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/add_item' });
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function show_multi_items_dialog() {
- if (!check_cv()) return;
-
- $('#row_table_id thead a img').remove();
-
- kivi.popup_dialog({
- url: 'controller.pl?action=Order/show_multi_items_dialog',
- data: { type: $('#type').val(),
- callback: 'Order/add_multi_items',
- callback_data_id: 'order_form' },
- id: 'jq_multi_items_dialog',
- dialog: {
- title: kivi.t8('Add multiple items'),
- width: 800,
- height: 500
- }
- });
- return true;
-}
-
-function close_multi_items_dialog() {
- $('#jq_multi_items_dialog').dialog('close');
-};
-
-function delete_order_item_row(clicked) {
- var row = $(clicked).parents("tbody").first();
- $(row).remove();
-
- renumber_positions();
- recalc_amounts_and_taxes();
-}
-
-function price_chooser_item_row(clicked) {
- var row = $(clicked).parents("tbody").first();
- 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: 'item_id', value: item_id_dom.val() });
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function update_price_source(item_id, source, descr, price_str) {
- 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 ([%- AUTH.assert('edit_prices', 1) %] == 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);
- recalc_amounts_and_taxes();
- }
-
- kivi.io.close_dialog();
-}
-
-function update_discount_source(item_id, source, descr, discount_str) {
- 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 ([%- AUTH.assert('edit_prices', 1) %] == 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);
- recalc_amounts_and_taxes();
- }
-
- kivi.io.close_dialog();
-}
-
-function reformat_number(event) {
- $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
-}
-
-function recalc_amounts_and_taxes() {
- var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' });
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function redisplay_linetotals(data) {
- $('.row_entry [name="linetotal"]').each(function(idx, elt) {
- $(elt).html(data[idx]);
- });
-}
-
-function row_table_scroll_down() {
- $('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight);
-}
-
-var email_dialog;
-
-function show_email_dialog(html) {
- var id = 'jqueryui_popup_dialog';
- var dialog_params = {
- id: id,
- width: 800,
- height: 500,
- modal: true,
- close: function(event, ui) {
- email_dialog.remove();
- },
- };
-
- $('#' + id).remove();
-
- email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
- email_dialog.html(html);
- email_dialog.dialog(dialog_params);
-
- $('.cancel').click(close_email_dialog);
-
- return true;
-}
-
-close_email_dialog = function() {
- email_dialog.dialog("close");
-}
-
-function renumber_positions() {
- $('.row_entry [name="position"]').each(function(idx, elt) {
- $(elt).html(idx+1);
- });
-}
-
-function reorder_items(order_by) {
- var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir");
- $('#row_table_id thead a img').remove();
-
- var src;
- if (dir == "1") {
- dir = "0";
- src = "image/up.png";
- } else {
- dir = "1";
- src = "image/down.png";
- };
-
- $('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="[%- LxERP.t8('sort items') %]">');
-
- var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/reorder_items' });
- data.push({ name: 'order_by', value: order_by });
- data.push({ name: 'sort_dir', value: dir });
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function redisplay_items(data) {
- var old_rows = $('.row_entry').detach();
- var new_rows = [];
- $(data).each(function(idx, elt) {
- new_rows.push(old_rows[elt.old_pos - 1]);
- });
- $(new_rows).appendTo($('#row_table_id'));
- renumber_positions();
-}
-
-function show_longdescription_dialog(clicked) {
- var row = $(clicked).parents("tbody").first();
- var position = $(row).find('[name="position"]').html();
- var partnumber = $(row).find('[name="partnumber"]').html();
- var description_elt = $(row).find('[name="order.orderitems[].description"]');
- var description = description_elt.val();
- var longdescription_elt = $(row).find('[name="order.orderitems[].longdescription"]');
- var longdescription;
-
- if (!longdescription_elt.length) {
- var data = [];
- data.push({ name: 'action', value: 'Order/get_item_longdescription' });
- data.push({ name: 'type', value: $('#type').val() });
- data.push({ name: 'item_id', value: $(row).find('[name="order.orderitems[+].id"]').val() });
- data.push({ name: 'parts_id', value: $(row).find('[name="order.orderitems[].parts_id"]').val() });
- $.ajax({
- url: 'controller.pl',
- data: data,
- method: "GET",
- async: false,
- dataType: 'text',
- success: function(val){
- longdescription = val;
- }
- });
- } else {
- longdescription = longdescription_elt.val();
- }
-
- var params = { runningnumber: position,
- partnumber: partnumber,
- description: description,
- default_longdescription: longdescription,
- set_function: function(val){
- longdescription_elt.remove();
- $('<input type="hidden" name="order.orderitems[].longdescription">').insertAfter(description_elt).val(val);
- }
- };
-
- kivi.SalesPurchase.edit_longdescription_with_params(params);
-}
-
-function init_row_handlers() {
- kivi.run_once_for('.recalc', 'on_change_recalc', function(elt) {
- $(elt).change(recalc_amounts_and_taxes);
- });
-
- kivi.run_once_for('.reformat_number', 'on_change_reformat', function(elt) {
- $(elt).change(reformat_number);
- });
-
- kivi.run_once_for('.unitselect', 'on_change_unit_with_oldval', function(elt) {
- $(elt).data('oldval', $(elt).val());
- $(elt).change(unit_change);
- });
-
- kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) {
- $(elt).keydown(function(event) {
- if(event.keyCode == 40 && event.shiftKey == true) {
- // shift arrow down
- event.preventDefault();
- var row = $(event.target).parents(".row_entry").first();
- $(row).children().not(':first').show();
- return false;
- }
- if(event.keyCode == 38 && event.shiftKey == true) {
- // shift arrow up
- event.preventDefault();
- var row = $(event.target).parents(".row_entry").first();
- $(row).children().not(':first').hide();
- return false;
- }
- });
- $(elt).dblclick(function(event) {
- event.preventDefault();
- var row = $(event.target).parents(".row_entry").first();
- $(row).children().not(':first').toggle();
- return false;
- });
- });
-}
-
-
-$(function(){
- $('#order_[%- cv_id %]').change(reload_cv_dependend_selections);
- [%- IF SELF.cv == 'customer' %]
- $('#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)) });
- [%- END %]
- $('#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();
- add_item();
- return false;
- }
- });
- init_row_handlers();
-});
-
-$('#row_table_id').on('sortstop', function(event, ui) {
- $('#row_table_id thead a img').remove();
- renumber_positions();
-});
-</script>