Revision 0935b012
Von Bernd Bleßmann vor fast 9 Jahren hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
189 | 189 |
$::auth->set_session_value("Order::create_pdf-${key}" => $sfile->file_name); |
190 | 190 |
|
191 | 191 |
$self->js |
192 |
->run('download_pdf', $pdf_filename, $key) |
|
192 |
->run('kivi.Order.download_pdf', $pdf_filename, $key)
|
|
193 | 193 |
->flash('info', t8('The PDF has been created')); |
194 | 194 |
|
195 | 195 |
} elsif ($media eq 'printer') { |
... | ... | |
275 | 275 |
|
276 | 276 |
my $dialog_html = $self->render('order/tabs/_email_dialog', { output => 0 }); |
277 | 277 |
$self->js |
278 |
->run('show_email_dialog', $dialog_html) |
|
278 |
->run('kivi.Order.show_email_dialog', $dialog_html)
|
|
279 | 279 |
->reinit_widgets |
280 | 280 |
->render($self); |
281 | 281 |
} |
... | ... | |
315 | 315 |
|
316 | 316 |
$self->js |
317 | 317 |
->val('#order_intnotes', $intnotes) |
318 |
->run('close_email_dialog') |
|
318 |
->run('kivi.Order.close_email_dialog')
|
|
319 | 319 |
->render($self); |
320 | 320 |
} |
321 | 321 |
|
... | ... | |
395 | 395 |
$self->_recalc(); |
396 | 396 |
|
397 | 397 |
$self->js |
398 |
->run('update_sellprice', $::form->{item_id}, $item->sellprice_as_number); |
|
398 |
->run('kivi.Order.update_sellprice', $::form->{item_id}, $item->sellprice_as_number);
|
|
399 | 399 |
$self->_js_redisplay_linetotals; |
400 | 400 |
$self->_js_redisplay_amounts_and_taxes; |
401 | 401 |
$self->js->render(); |
... | ... | |
423 | 423 |
$self->js |
424 | 424 |
->append('#row_table_id', $row_as_html) |
425 | 425 |
->val('.add_item_input', '') |
426 |
->run('init_row_handlers') |
|
427 |
->run('row_table_scroll_down') |
|
428 |
->run('renumber_positions') |
|
426 |
->run('kivi.Order.init_row_handlers')
|
|
427 |
->run('kivi.Order.row_table_scroll_down')
|
|
428 |
->run('kivi.Order.renumber_positions')
|
|
429 | 429 |
->focus('#add_item_parts_id_name'); |
430 | 430 |
|
431 | 431 |
$self->_js_redisplay_amounts_and_taxes; |
... | ... | |
484 | 484 |
} |
485 | 485 |
|
486 | 486 |
$self->js |
487 |
->run('close_multi_items_dialog') |
|
488 |
->run('init_row_handlers') |
|
489 |
->run('row_table_scroll_down') |
|
490 |
->run('renumber_positions') |
|
487 |
->run('kivi.Order.close_multi_items_dialog')
|
|
488 |
->run('kivi.Order.init_row_handlers')
|
|
489 |
->run('kivi.Order.row_table_scroll_down')
|
|
490 |
->run('kivi.Order.renumber_positions')
|
|
491 | 491 |
->focus('#add_item_parts_id_name'); |
492 | 492 |
|
493 | 493 |
$self->_js_redisplay_amounts_and_taxes; |
... | ... | |
523 | 523 |
@to_sort = sort { $b->{order_by} cmp $a->{order_by} } @to_sort; |
524 | 524 |
} |
525 | 525 |
$self->js |
526 |
->run('redisplay_items', \@to_sort) |
|
526 |
->run('kivi.Order.redisplay_items', \@to_sort)
|
|
527 | 527 |
->render; |
528 | 528 |
} |
529 | 529 |
|
... | ... | |
553 | 553 |
|
554 | 554 |
my @data = map {$::form->format_amount(\%::myconfig, $_->{linetotal}, 2, 0)} @{ $self->order->items_sorted }; |
555 | 555 |
$self->js |
556 |
->run('redisplay_linetotals', \@data); |
|
556 |
->run('kivi.Order.redisplay_linetotals', \@data);
|
|
557 | 557 |
} |
558 | 558 |
|
559 | 559 |
sub _js_redisplay_amounts_and_taxes { |
... | ... | |
946 | 946 |
} } @all_objects; |
947 | 947 |
} |
948 | 948 |
|
949 |
$::request->{layout}->use_javascript("${_}.js") for qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery); |
|
949 |
$::request->{layout}->use_javascript("${_}.js") for qw(kivi.SalesPurchase kivi.Order ckeditor/ckeditor ckeditor/adapters/jquery);
|
|
950 | 950 |
} |
951 | 951 |
|
952 | 952 |
sub _create_pdf { |
js/kivi.Order.js | ||
---|---|---|
1 |
namespace('kivi.Order', function(ns) { |
|
2 |
ns.check_cv = function() { |
|
3 |
if ($('#type').val() == 'sales_order') { |
|
4 |
if ($('#order_customer_id').val() == '') { |
|
5 |
alert(kivi.t8('Please select a customer.')); |
|
6 |
return false; |
|
7 |
} |
|
8 |
} else { |
|
9 |
if ($('#order_vendor_id').val() == '') { |
|
10 |
alert(kivi.t8('Please select a vendor.')); |
|
11 |
return false; |
|
12 |
} |
|
13 |
} |
|
14 |
return true; |
|
15 |
}; |
|
16 |
|
|
17 |
ns.save = function() { |
|
18 |
if (!ns.check_cv()) return; |
|
19 |
|
|
20 |
var data = $('#order_form').serializeArray(); |
|
21 |
data.push({ name: 'action', value: 'Order/save' }); |
|
22 |
|
|
23 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
24 |
}; |
|
25 |
|
|
26 |
ns.save_and_delivery_order = function() { |
|
27 |
if (!ns.check_cv()) return; |
|
28 |
|
|
29 |
var data = $('#order_form').serializeArray(); |
|
30 |
data.push({ name: 'action', value: 'Order/save_and_delivery_order' }); |
|
31 |
|
|
32 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
33 |
}; |
|
34 |
|
|
35 |
ns.delete_order = function() { |
|
36 |
var data = $('#order_form').serializeArray(); |
|
37 |
data.push({ name: 'action', value: 'Order/delete' }); |
|
38 |
|
|
39 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
40 |
}; |
|
41 |
|
|
42 |
ns.show_print_options = function() { |
|
43 |
if (!ns.check_cv()) return; |
|
44 |
|
|
45 |
kivi.popup_dialog({ |
|
46 |
id: 'print_options', |
|
47 |
dialog: { |
|
48 |
title: kivi.t8('Print options'), |
|
49 |
width: 800, |
|
50 |
height: 300 |
|
51 |
} |
|
52 |
}); |
|
53 |
}; |
|
54 |
|
|
55 |
ns.print = function() { |
|
56 |
$('#print_options').dialog('close'); |
|
57 |
|
|
58 |
var data = $('#order_form').serializeArray(); |
|
59 |
data = data.concat($('#print_options_form').serializeArray()); |
|
60 |
data.push({ name: 'action', value: 'Order/print' }); |
|
61 |
|
|
62 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
63 |
}; |
|
64 |
|
|
65 |
ns.download_pdf = function(pdf_filename, key) { |
|
66 |
var data = []; |
|
67 |
data.push({ name: 'action', value: 'Order/download_pdf' }); |
|
68 |
data.push({ name: 'type', value: $('#type').val() }); |
|
69 |
data.push({ name: 'pdf_filename', value: pdf_filename }); |
|
70 |
data.push({ name: 'key', value: key }); |
|
71 |
$.download("controller.pl", data); |
|
72 |
}; |
|
73 |
|
|
74 |
ns.email = function() { |
|
75 |
if (!ns.check_cv()) return; |
|
76 |
var data = $('#order_form').serializeArray(); |
|
77 |
data.push({ name: 'action', value: 'Order/show_email_dialog' }); |
|
78 |
|
|
79 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
80 |
}; |
|
81 |
|
|
82 |
var email_dialog; |
|
83 |
|
|
84 |
ns.show_email_dialog = function(html) { |
|
85 |
var id = 'jqueryui_popup_dialog'; |
|
86 |
var dialog_params = { |
|
87 |
id: id, |
|
88 |
width: 800, |
|
89 |
height: 500, |
|
90 |
modal: true, |
|
91 |
close: function(event, ui) { |
|
92 |
email_dialog.remove(); |
|
93 |
}, |
|
94 |
}; |
|
95 |
|
|
96 |
$('#' + id).remove(); |
|
97 |
|
|
98 |
email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body'); |
|
99 |
email_dialog.html(html); |
|
100 |
email_dialog.dialog(dialog_params); |
|
101 |
|
|
102 |
$('.cancel').click(ns.close_email_dialog); |
|
103 |
|
|
104 |
return true; |
|
105 |
}; |
|
106 |
|
|
107 |
ns.send_email = function() { |
|
108 |
var data = $('#order_form').serializeArray(); |
|
109 |
data = data.concat($('#email_form').serializeArray()); |
|
110 |
data.push({ name: 'action', value: 'Order/send_email' }); |
|
111 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
112 |
}; |
|
113 |
|
|
114 |
ns.close_email_dialog = function() { |
|
115 |
email_dialog.dialog("close"); |
|
116 |
}; |
|
117 |
|
|
118 |
ns.reload_cv_dependend_selections = function() { |
|
119 |
var data = $('#order_form').serializeArray(); |
|
120 |
data.push({ name: 'action', value: 'Order/customer_vendor_changed' }); |
|
121 |
|
|
122 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
123 |
}; |
|
124 |
|
|
125 |
ns.reformat_number = function(event) { |
|
126 |
$(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2)); |
|
127 |
}; |
|
128 |
|
|
129 |
ns.recalc_amounts_and_taxes = function() { |
|
130 |
var data = $('#order_form').serializeArray(); |
|
131 |
data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' }); |
|
132 |
|
|
133 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
134 |
}; |
|
135 |
|
|
136 |
ns.unit_change = function(event) { |
|
137 |
var row = $(event.target).parents("tbody").first(); |
|
138 |
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]'); |
|
139 |
var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]'); |
|
140 |
var select_elt = $(row).find('[name="order.orderitems[].unit"]'); |
|
141 |
|
|
142 |
var oldval = $(select_elt).data('oldval'); |
|
143 |
$(select_elt).data('oldval', $(select_elt).val()); |
|
144 |
|
|
145 |
var data = $('#order_form').serializeArray(); |
|
146 |
data.push({ name: 'action', value: 'Order/unit_changed' }); |
|
147 |
data.push({ name: 'item_id', value: item_id_dom.val() }); |
|
148 |
data.push({ name: 'old_unit', value: oldval }); |
|
149 |
data.push({ name: 'sellprice_dom_id', value: sellprice_dom.attr('id') }); |
|
150 |
|
|
151 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
152 |
}; |
|
153 |
|
|
154 |
ns.update_sellprice = function(item_id, price_str) { |
|
155 |
var row = $('#item_' + item_id).parents("tbody").first(); |
|
156 |
var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]'); |
|
157 |
var html_elt = $(row).find('[name="sellprice_text"]'); |
|
158 |
price_elt.val(price_str); |
|
159 |
html_elt.html(price_str); |
|
160 |
}; |
|
161 |
|
|
162 |
ns.init_row_handlers = function() { |
|
163 |
kivi.run_once_for('.recalc', 'on_change_recalc', function(elt) { |
|
164 |
$(elt).change(ns.recalc_amounts_and_taxes); |
|
165 |
}); |
|
166 |
|
|
167 |
kivi.run_once_for('.reformat_number', 'on_change_reformat', function(elt) { |
|
168 |
$(elt).change(ns.reformat_number); |
|
169 |
}); |
|
170 |
|
|
171 |
kivi.run_once_for('.unitselect', 'on_change_unit_with_oldval', function(elt) { |
|
172 |
$(elt).data('oldval', $(elt).val()); |
|
173 |
$(elt).change(ns.unit_change); |
|
174 |
}); |
|
175 |
|
|
176 |
kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) { |
|
177 |
$(elt).keydown(function(event) { |
|
178 |
if(event.keyCode == 40 && event.shiftKey == true) { |
|
179 |
// shift arrow down |
|
180 |
event.preventDefault(); |
|
181 |
var row = $(event.target).parents(".row_entry").first(); |
|
182 |
$(row).children().not(':first').show(); |
|
183 |
return false; |
|
184 |
} |
|
185 |
if(event.keyCode == 38 && event.shiftKey == true) { |
|
186 |
// shift arrow up |
|
187 |
event.preventDefault(); |
|
188 |
var row = $(event.target).parents(".row_entry").first(); |
|
189 |
$(row).children().not(':first').hide(); |
|
190 |
return false; |
|
191 |
} |
|
192 |
}); |
|
193 |
$(elt).dblclick(function(event) { |
|
194 |
event.preventDefault(); |
|
195 |
var row = $(event.target).parents(".row_entry").first(); |
|
196 |
$(row).children().not(':first').toggle(); |
|
197 |
return false; |
|
198 |
}); |
|
199 |
}); |
|
200 |
}; |
|
201 |
|
|
202 |
ns.redisplay_linetotals = function(data) { |
|
203 |
$('.row_entry [name="linetotal"]').each(function(idx, elt) { |
|
204 |
$(elt).html(data[idx]); |
|
205 |
}); |
|
206 |
}; |
|
207 |
|
|
208 |
ns.renumber_positions = function() { |
|
209 |
$('.row_entry [name="position"]').each(function(idx, elt) { |
|
210 |
$(elt).html(idx+1); |
|
211 |
}); |
|
212 |
}; |
|
213 |
|
|
214 |
ns.reorder_items = function(order_by) { |
|
215 |
var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir"); |
|
216 |
$('#row_table_id thead a img').remove(); |
|
217 |
|
|
218 |
var src; |
|
219 |
if (dir == "1") { |
|
220 |
dir = "0"; |
|
221 |
src = "image/up.png"; |
|
222 |
} else { |
|
223 |
dir = "1"; |
|
224 |
src = "image/down.png"; |
|
225 |
}; |
|
226 |
|
|
227 |
$('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="' + kivi.t8('sort items') + '">'); |
|
228 |
|
|
229 |
var data = $('#order_form').serializeArray(); |
|
230 |
data.push({ name: 'action', value: 'Order/reorder_items' }); |
|
231 |
data.push({ name: 'order_by', value: order_by }); |
|
232 |
data.push({ name: 'sort_dir', value: dir }); |
|
233 |
|
|
234 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
235 |
}; |
|
236 |
|
|
237 |
ns.redisplay_items = function(data) { |
|
238 |
var old_rows = $('.row_entry').detach(); |
|
239 |
var new_rows = []; |
|
240 |
$(data).each(function(idx, elt) { |
|
241 |
new_rows.push(old_rows[elt.old_pos - 1]); |
|
242 |
}); |
|
243 |
$(new_rows).appendTo($('#row_table_id')); |
|
244 |
ns.renumber_positions(); |
|
245 |
}; |
|
246 |
|
|
247 |
ns.add_item = function() { |
|
248 |
if ($('#add_item_parts_id').val() == '') return; |
|
249 |
if (!ns.check_cv()) return; |
|
250 |
|
|
251 |
$('#row_table_id thead a img').remove(); |
|
252 |
|
|
253 |
var data = $('#order_form').serializeArray(); |
|
254 |
data.push({ name: 'action', value: 'Order/add_item' }); |
|
255 |
|
|
256 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
257 |
}; |
|
258 |
|
|
259 |
ns.show_multi_items_dialog = function() { |
|
260 |
if (!ns.check_cv()) return; |
|
261 |
|
|
262 |
$('#row_table_id thead a img').remove(); |
|
263 |
|
|
264 |
kivi.popup_dialog({ |
|
265 |
url: 'controller.pl?action=Order/show_multi_items_dialog', |
|
266 |
data: { type: $('#type').val(), |
|
267 |
callback: 'Order/add_multi_items', |
|
268 |
callback_data_id: 'order_form' }, |
|
269 |
id: 'jq_multi_items_dialog', |
|
270 |
dialog: { |
|
271 |
title: kivi.t8('Add multiple items'), |
|
272 |
width: 800, |
|
273 |
height: 500 |
|
274 |
} |
|
275 |
}); |
|
276 |
return true; |
|
277 |
}; |
|
278 |
|
|
279 |
ns.close_multi_items_dialog = function() { |
|
280 |
$('#jq_multi_items_dialog').dialog('close'); |
|
281 |
}; |
|
282 |
|
|
283 |
ns.delete_order_item_row = function(clicked) { |
|
284 |
var row = $(clicked).parents("tbody").first(); |
|
285 |
$(row).remove(); |
|
286 |
|
|
287 |
ns.renumber_positions(); |
|
288 |
ns.recalc_amounts_and_taxes(); |
|
289 |
}; |
|
290 |
|
|
291 |
ns.row_table_scroll_down = function() { |
|
292 |
$('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight); |
|
293 |
}; |
|
294 |
|
|
295 |
ns.show_longdescription_dialog = function(clicked) { |
|
296 |
var row = $(clicked).parents("tbody").first(); |
|
297 |
var position = $(row).find('[name="position"]').html(); |
|
298 |
var partnumber = $(row).find('[name="partnumber"]').html(); |
|
299 |
var description_elt = $(row).find('[name="order.orderitems[].description"]'); |
|
300 |
var description = description_elt.val(); |
|
301 |
var longdescription_elt = $(row).find('[name="order.orderitems[].longdescription"]'); |
|
302 |
var longdescription; |
|
303 |
|
|
304 |
if (!longdescription_elt.length) { |
|
305 |
var data = []; |
|
306 |
data.push({ name: 'action', value: 'Order/get_item_longdescription' }); |
|
307 |
data.push({ name: 'type', value: $('#type').val() }); |
|
308 |
data.push({ name: 'item_id', value: $(row).find('[name="order.orderitems[+].id"]').val() }); |
|
309 |
data.push({ name: 'parts_id', value: $(row).find('[name="order.orderitems[].parts_id"]').val() }); |
|
310 |
$.ajax({ |
|
311 |
url: 'controller.pl', |
|
312 |
data: data, |
|
313 |
method: "GET", |
|
314 |
async: false, |
|
315 |
dataType: 'text', |
|
316 |
success: function(val){ |
|
317 |
longdescription = val; |
|
318 |
} |
|
319 |
}); |
|
320 |
} else { |
|
321 |
longdescription = longdescription_elt.val(); |
|
322 |
} |
|
323 |
|
|
324 |
var params = { runningnumber: position, |
|
325 |
partnumber: partnumber, |
|
326 |
description: description, |
|
327 |
default_longdescription: longdescription, |
|
328 |
set_function: function(val){ |
|
329 |
longdescription_elt.remove(); |
|
330 |
$('<input type="hidden" name="order.orderitems[].longdescription">').insertAfter(description_elt).val(val); |
|
331 |
} |
|
332 |
}; |
|
333 |
|
|
334 |
kivi.SalesPurchase.edit_longdescription_with_params(params); |
|
335 |
}; |
|
336 |
|
|
337 |
ns.price_chooser_item_row = function(clicked) { |
|
338 |
var row = $(clicked).parents("tbody").first(); |
|
339 |
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]'); |
|
340 |
|
|
341 |
var data = $('#order_form').serializeArray(); |
|
342 |
data.push({ name: 'action', value: 'Order/price_popup' }); |
|
343 |
data.push({ name: 'item_id', value: item_id_dom.val() }); |
|
344 |
|
|
345 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
346 |
}; |
|
347 |
|
|
348 |
ns.update_price_source = function(item_id, source, descr, price_str, price_editable) { |
|
349 |
var row = $('#item_' + item_id).parents("tbody").first(); |
|
350 |
var source_elt = $(row).find('[name="order.orderitems[].active_price_source"]'); |
|
351 |
var button_elt = $(row).find('[name="price_chooser_button"]'); |
|
352 |
|
|
353 |
button_elt.val(button_elt.val().replace(/.*\|/, descr + " |")); |
|
354 |
source_elt.val(source); |
|
355 |
|
|
356 |
var editable_div_elt = $(row).find('[name="editable_price"]'); |
|
357 |
var not_editable_div_elt = $(row).find('[name="not_editable_price"]'); |
|
358 |
if (price_editable == 1 && source == '') { |
|
359 |
// editable |
|
360 |
$(editable_div_elt).show(); |
|
361 |
$(not_editable_div_elt).hide(); |
|
362 |
$(editable_div_elt).find(':input').prop("disabled", false); |
|
363 |
$(not_editable_div_elt).find(':input').prop("disabled", true); |
|
364 |
} else { |
|
365 |
// not editable |
|
366 |
$(editable_div_elt).hide(); |
|
367 |
$(not_editable_div_elt).show(); |
|
368 |
$(editable_div_elt).find(':input').prop("disabled", true); |
|
369 |
$(not_editable_div_elt).find(':input').prop("disabled", false); |
|
370 |
} |
|
371 |
|
|
372 |
if (price_str) { |
|
373 |
var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]'); |
|
374 |
var html_elt = $(row).find('[name="sellprice_text"]'); |
|
375 |
price_elt.val(price_str); |
|
376 |
html_elt.html(price_str); |
|
377 |
ns.recalc_amounts_and_taxes(); |
|
378 |
} |
|
379 |
|
|
380 |
kivi.io.close_dialog(); |
|
381 |
}; |
|
382 |
|
|
383 |
ns.update_discount_source = function(item_id, source, descr, discount_str, price_editable) { |
|
384 |
var row = $('#item_' + item_id).parents("tbody").first(); |
|
385 |
var source_elt = $(row).find('[name="order.orderitems[].active_discount_source"]'); |
|
386 |
var button_elt = $(row).find('[name="price_chooser_button"]'); |
|
387 |
|
|
388 |
button_elt.val(button_elt.val().replace(/\|.*/, "| " + descr)); |
|
389 |
source_elt.val(source); |
|
390 |
|
|
391 |
var editable_div_elt = $(row).find('[name="editable_discount"]'); |
|
392 |
var not_editable_div_elt = $(row).find('[name="not_editable_discount"]'); |
|
393 |
if (price_editable == 1 && source == '') { |
|
394 |
// editable |
|
395 |
$(editable_div_elt).show(); |
|
396 |
$(not_editable_div_elt).hide(); |
|
397 |
$(editable_div_elt).find(':input').prop("disabled", false); |
|
398 |
$(not_editable_div_elt).find(':input').prop("disabled", true); |
|
399 |
} else { |
|
400 |
// not editable |
|
401 |
$(editable_div_elt).hide(); |
|
402 |
$(not_editable_div_elt).show(); |
|
403 |
$(editable_div_elt).find(':input').prop("disabled", true); |
|
404 |
$(not_editable_div_elt).find(':input').prop("disabled", false); |
|
405 |
} |
|
406 |
|
|
407 |
if (discount_str) { |
|
408 |
var discount_elt = $(row).find('[name="order.orderitems[].discount_as_percent"]'); |
|
409 |
var html_elt = $(row).find('[name="discount_text"]'); |
|
410 |
discount_elt.val(discount_str); |
|
411 |
html_elt.html(discount_str); |
|
412 |
ns.recalc_amounts_and_taxes(); |
|
413 |
} |
|
414 |
|
|
415 |
kivi.io.close_dialog(); |
|
416 |
}; |
|
417 |
|
|
418 |
}); |
|
419 |
|
|
420 |
$(function(){ |
|
421 |
if ($('#type').val() == 'sales_order') { |
|
422 |
$('#order_customer_id').change(kivi.Order.reload_cv_dependend_selections); |
|
423 |
} else { |
|
424 |
$('#order_vendor_id').change(kivi.Order.reload_cv_dependend_selections); |
|
425 |
} |
|
426 |
|
|
427 |
if ($('#type').val() == 'sales_order') { |
|
428 |
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) }); |
|
429 |
} else { |
|
430 |
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.lastcost, -2)) }); |
|
431 |
} |
|
432 |
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_description').val(o.description) }); |
|
433 |
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) }); |
|
434 |
|
|
435 |
$('.add_item_input').keydown(function(event) { |
|
436 |
if(event.keyCode == 13) { |
|
437 |
event.preventDefault(); |
|
438 |
kivi.Order.add_item(); |
|
439 |
return false; |
|
440 |
} |
|
441 |
}); |
|
442 |
|
|
443 |
kivi.Order.init_row_handlers(); |
|
444 |
|
|
445 |
$('#row_table_id').on('sortstop', function(event, ui) { |
|
446 |
$('#row_table_id thead a img').remove(); |
|
447 |
kivi.Order.renumber_positions(); |
|
448 |
}); |
|
449 |
}); |
templates/webpages/order/form.html | ||
---|---|---|
7 | 7 |
<form method="post" action="controller.pl" id="print_options_form"> |
8 | 8 |
[% SELF.print_options %] |
9 | 9 |
<br> |
10 |
[% L.button_tag('print()', LxERP.t8('Print')) %] |
|
10 |
[% L.button_tag('kivi.Order.print()', LxERP.t8('Print')) %]
|
|
11 | 11 |
<a href="#" onclick="$('#print_options').dialog('close');">[% LxERP.t8("Cancel") %]</a> |
12 | 12 |
</form> |
13 | 13 |
</div> |
... | ... | |
43 | 43 |
|
44 | 44 |
[% L.hidden_tag('action', 'Order/dispatch') %] |
45 | 45 |
|
46 |
[% L.button_tag('save()', LxERP.t8('Save')) %] |
|
47 |
[% L.button_tag('show_print_options()', LxERP.t8('Print')) %] |
|
48 |
[% L.button_tag('email()', LxERP.t8('E-mail')) %] |
|
49 |
[% L.button_tag('save_and_delivery_order()', LxERP.t8('Save and Delivery Order')) %] |
|
46 |
[% L.button_tag('kivi.Order.save()', LxERP.t8('Save')) %]
|
|
47 |
[% L.button_tag('kivi.Order.show_print_options()', LxERP.t8('Print')) %]
|
|
48 |
[% L.button_tag('kivi.Order.email()', LxERP.t8('E-mail')) %]
|
|
49 |
[% L.button_tag('kivi.Order.save_and_delivery_order()', LxERP.t8('Save and Delivery Order')) %]
|
|
50 | 50 |
[%- IF SELF.order.id && ( (SELF.cv == 'customer' && INSTANCE_CONF.get_sales_order_show_delete) || (SELF.cv == 'vendor' && INSTANCE_CONF.get_purchase_order_show_delete) ) %] |
51 |
[% L.button_tag('delete_order()', LxERP.t8('Delete'), confirm=LxERP.t8("Are you sure?")) %] |
|
51 |
[% L.button_tag('kivi.Order.delete_order()', LxERP.t8('Delete'), confirm=LxERP.t8("Are you sure?")) %]
|
|
52 | 52 |
[%- END %] |
53 | 53 |
|
54 | 54 |
</form> |
55 |
|
|
56 |
|
|
57 |
<script type='text/javascript'> |
|
58 |
|
|
59 |
function delete_order() { |
|
60 |
var data = $('#order_form').serializeArray(); |
|
61 |
data.push({ name: 'action', value: 'Order/delete' }); |
|
62 |
|
|
63 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
64 |
} |
|
65 |
|
|
66 |
function save() { |
|
67 |
if (!check_cv()) return; |
|
68 |
var data = $('#order_form').serializeArray(); |
|
69 |
data.push({ name: 'action', value: 'Order/save' }); |
|
70 |
|
|
71 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
72 |
} |
|
73 |
|
|
74 |
function show_print_options() { |
|
75 |
if (!check_cv()) return; |
|
76 |
|
|
77 |
kivi.popup_dialog({ |
|
78 |
id: 'print_options', |
|
79 |
dialog: { |
|
80 |
title: kivi.t8('Print options'), |
|
81 |
width: 800, |
|
82 |
height: 300 |
|
83 |
} |
|
84 |
}); |
|
85 |
} |
|
86 |
|
|
87 |
function print() { |
|
88 |
$('#print_options').dialog('close'); |
|
89 |
|
|
90 |
var data = $('#order_form').serializeArray(); |
|
91 |
data = data.concat($('#print_options_form').serializeArray()); |
|
92 |
data.push({ name: 'action', value: 'Order/print' }); |
|
93 |
|
|
94 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
95 |
} |
|
96 |
|
|
97 |
function download_pdf(pdf_filename, key) { |
|
98 |
var data = []; |
|
99 |
data.push({ name: 'action', value: 'Order/download_pdf' }); |
|
100 |
data.push({ name: 'type', value: $('#type').val() }); |
|
101 |
data.push({ name: 'pdf_filename', value: pdf_filename }); |
|
102 |
data.push({ name: 'key', value: key }); |
|
103 |
$.download("controller.pl", data); |
|
104 |
} |
|
105 |
|
|
106 |
function email() { |
|
107 |
if (!check_cv()) return; |
|
108 |
var data = $('#order_form').serializeArray(); |
|
109 |
data.push({ name: 'action', value: 'Order/show_email_dialog' }); |
|
110 |
|
|
111 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
112 |
} |
|
113 |
|
|
114 |
function save_and_delivery_order() { |
|
115 |
if (!check_cv()) return; |
|
116 |
var data = $('#order_form').serializeArray(); |
|
117 |
data.push({ name: 'action', value: 'Order/save_and_delivery_order' }); |
|
118 |
|
|
119 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
120 |
} |
|
121 |
|
|
122 |
function check_cv() { |
|
123 |
if ($('#order_[%- cv_id %]').val() == '') { |
|
124 |
[%- IF SELF.cv == 'customer' %] |
|
125 |
alert(kivi.t8('Please select a customer.')); |
|
126 |
[%- ELSE %] |
|
127 |
alert(kivi.t8('Please select a vendor.')); |
|
128 |
[%- END %] |
|
129 |
return false; |
|
130 |
} |
|
131 |
return true; |
|
132 |
} |
|
133 |
</script> |
templates/webpages/order/tabs/_email_dialog.html | ||
---|---|---|
49 | 49 |
|
50 | 50 |
<br> |
51 | 51 |
[% L.hidden_tag('action', 'Order/dispatch') %] |
52 |
[% L.button_tag('send_email()', LxERP.t8('Continue')) %] |
|
53 |
<a href="#" onclick="close_email_dialog();">[%- LxERP.t8("Cancel") %]</a> |
|
54 |
|
|
55 |
<script type='text/javascript'> |
|
56 |
function send_email() { |
|
57 |
var data = $('#order_form').serializeArray(); |
|
58 |
data = data.concat($('#email_form').serializeArray()); |
|
59 |
data.push({ name: 'action', value: 'Order/send_email' }); |
|
60 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
61 |
} |
|
62 |
</script> |
|
52 |
[% L.button_tag('kivi.Order.send_email()', LxERP.t8('Continue')) %] |
|
53 |
<a href="#" onclick="kivi.Order.close_email_dialog();">[%- LxERP.t8("Cancel") %]</a> |
|
63 | 54 |
|
64 | 55 |
</form> |
templates/webpages/order/tabs/_item_input.html | ||
---|---|---|
22 | 22 |
</td> |
23 | 23 |
<td>[% L.input_tag('add_item.sellprice_as_number', '', size = 10, class="add_item_input numeric") %]</td> |
24 | 24 |
<td>[% L.input_tag('add_item.discount_as_percent', '', size = 5, class="add_item_input numeric") %]</td> |
25 |
<td>[% L.button_tag('add_item()', LxERP.t8('Add part')) %]</td> |
|
25 |
<td>[% L.button_tag('kivi.Order.add_item()', LxERP.t8('Add part')) %]</td>
|
|
26 | 26 |
</tr> |
27 | 27 |
</tbody> |
28 | 28 |
</table> |
templates/webpages/order/tabs/_multi_items_dialog.html | ||
---|---|---|
19 | 19 |
<hr> |
20 | 20 |
|
21 | 21 |
[% L.button_tag('add_multi_items()', LxERP.t8('Continue'), id='continue_button') %] |
22 |
<a href="#" onclick="close_multi_items_dialog();">[%- LxERP.t8("Cancel") %]</a> |
|
22 |
<a href="#" onclick="kivi.Order.close_multi_items_dialog();">[%- LxERP.t8("Cancel") %]</a>
|
|
23 | 23 |
|
24 | 24 |
<script type='text/javascript'> |
25 | 25 |
function update_result() { |
templates/webpages/order/tabs/_price_sources_dialog.html | ||
---|---|---|
4 | 4 |
[%- USE LxERP %] |
5 | 5 |
[% SET best_price = price_source.best_price %] |
6 | 6 |
[% SET best_discount = price_source.best_discount %] |
7 |
[% SET price_editable = AUTH.assert('edit_prices', 1) %] |
|
7 | 8 |
<h2>[% 'Prices' | $T8 %]</h2> |
8 | 9 |
|
9 | 10 |
<table> |
... | ... | |
16 | 17 |
</tr> |
17 | 18 |
<tr class='listrow'> |
18 | 19 |
[%- IF price_source.record_item.active_price_source %] |
19 |
<td>[% L.button_tag('update_price_source(\'' _ FORM.item_id _ '\', \'\', \'' _ LxERP.t8('None (PriceSource)') _ '\')', LxERP.t8('Select')) %]</td>
|
|
20 |
<td>[% L.button_tag('kivi.Order.update_price_source(\'' _ FORM.item_id _ '\', \'\', \'' _ LxERP.t8('None (PriceSource)') _ '\', \'\', ' _ price_editable _ ')', LxERP.t8('Select')) %]</td>
|
|
20 | 21 |
[%- ELSE %] |
21 | 22 |
<td><b>[% 'Selected' | $T8 %]</b></td> |
22 | 23 |
[%- END %] |
... | ... | |
28 | 29 |
[%- FOREACH price IN price_source.available_prices %] |
29 | 30 |
<tr class='listrow'> |
30 | 31 |
[%- IF price_source.record_item.active_price_source != price.source %] |
31 |
<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>
|
|
32 |
<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>
|
|
32 | 33 |
[%- ELSIF price_source.record_item.sellprice * 1 != price.price * 1 %] |
33 |
<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>
|
|
34 |
<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>
|
|
34 | 35 |
[%- ELSE %] |
35 | 36 |
<td><b>[% 'Selected' | $T8 %]</b></td> |
36 | 37 |
[% END %] |
... | ... | |
58 | 59 |
</tr> |
59 | 60 |
<tr class='listrow'> |
60 | 61 |
[%- IF price_source.record_item.active_discount_source %] |
61 |
<td>[% L.button_tag('update_discount_source(\'' _ FORM.item_id _ '\', \'\', \'' _ LxERP.t8('None (PriceSource Discount)') _ '\')', LxERP.t8('Select')) %]</td>
|
|
62 |
<td>[% L.button_tag('kivi.Order.update_discount_source(\'' _ FORM.item_id _ '\', \'\', \'' _ LxERP.t8('None (PriceSource Discount)') _ '\', \'\', ' _ price_editable _ ')', LxERP.t8('Select')) %]</td>
|
|
62 | 63 |
[%- ELSE %] |
63 | 64 |
<td><b>[% 'Selected' | $T8 %]</b></td> |
64 | 65 |
[%- END %] |
... | ... | |
70 | 71 |
[%- FOREACH price IN price_source.available_discounts %] |
71 | 72 |
<tr class='listrow'> |
72 | 73 |
[%- IF price_source.record_item.active_discount_source != price.source %] |
73 |
<td>[% L.button_tag('update_discount_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ price.discount_as_percent _ '\')', LxERP.t8('Select')) %]</td>
|
|
74 |
<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>
|
|
74 | 75 |
[%- ELSIF price_source.record_item.discount * 1 != price.discount * 1 %] |
75 |
<td>[% L.button_tag('update_discount_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ price.discount_as_percent _ '\')', LxERP.t8('Update Discount')) %]</td>
|
|
76 |
<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>
|
|
76 | 77 |
[%- ELSE %] |
77 | 78 |
<td><b>[% 'Selected' | $T8 %]</b></td> |
78 | 79 |
[% END %] |
templates/webpages/order/tabs/_row.html | ||
---|---|---|
20 | 20 |
<img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]" class="dragdrop"> |
21 | 21 |
</td> |
22 | 22 |
<td align="center"> |
23 |
[%- L.button_tag("delete_order_item_row(this)", |
|
23 |
[%- L.button_tag("kivi.Order.delete_order_item_row(this)",
|
|
24 | 24 |
LxERP.t8("X"), |
25 | 25 |
confirm=LxERP.t8("Are you sure?")) %] |
26 | 26 |
</td> |
... | ... | |
31 | 31 |
[% L.input_tag("order.orderitems[].description", |
32 | 32 |
ITEM.description, |
33 | 33 |
style='width: 300px') %] |
34 |
[%- L.button_tag("show_longdescription_dialog(this)", LxERP.t8("L")) %] |
|
34 |
[%- L.button_tag("kivi.Order.show_longdescription_dialog(this)", LxERP.t8("L")) %]
|
|
35 | 35 |
</td> |
36 | 36 |
<td> |
37 | 37 |
[%- L.input_tag("order.orderitems[].qty_as_number", |
... | ... | |
56 | 56 |
class = 'unitselect') %] |
57 | 57 |
</td> |
58 | 58 |
<td> |
59 |
[%- L.button_tag("price_chooser_item_row(this)", |
|
59 |
[%- L.button_tag("kivi.Order.price_chooser_item_row(this)",
|
|
60 | 60 |
ITEM.active_price_source.source_description _ ' | ' _ ITEM.active_discount_source.source_description, |
61 | 61 |
name = "price_chooser_button") %] |
62 | 62 |
</td> |
templates/webpages/order/tabs/basic_data.html | ||
---|---|---|
145 | 145 |
|
146 | 146 |
[%- PROCESS order/tabs/_item_input.html %] |
147 | 147 |
|
148 |
[% L.button_tag('show_multi_items_dialog()', LxERP.t8('Add multiple parts')) %]</td>
|
|
148 |
[% L.button_tag('kivi.Order.show_multi_items_dialog()', LxERP.t8('Add multiple items')) %]</td>
|
|
149 | 149 |
|
150 | 150 |
<table width="100%"> |
151 | 151 |
<tr> |
... | ... | |
159 | 159 |
<th class="listheading" nowrap width="3" >[%- 'position' | $T8 %] </th> |
160 | 160 |
<th class="listheading" style='text-align:center' nowrap width="1"><img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]"></th> |
161 | 161 |
<th class="listheading" style='text-align:center' nowrap width="1"><img src="image/close.png" alt="[%- LxERP.t8('delete item') %]"></th> |
162 |
<th id="partnumber_header_id" class="listheading" nowrap width="15"><a href='#' onClick='javascript:reorder_items("partnumber")'> [%- 'Partnumber' | $T8 %]</a></th> |
|
163 |
<th id="description_header_id" class="listheading" nowrap ><a href='#' onClick='javascript:reorder_items("description")'>[%- 'Description' | $T8 %]</a></th> |
|
164 |
<th id="qty_header_id" class="listheading" nowrap width="5" ><a href='#' onClick='javascript:reorder_items("qty")'> [%- 'Qty' | $T8 %]</a></th> |
|
162 |
<th id="partnumber_header_id" class="listheading" nowrap width="15"><a href='#' onClick='javascript:kivi.Order.reorder_items("partnumber")'> [%- 'Partnumber' | $T8 %]</a></th>
|
|
163 |
<th id="description_header_id" class="listheading" nowrap ><a href='#' onClick='javascript:kivi.Order.reorder_items("description")'>[%- 'Description' | $T8 %]</a></th>
|
|
164 |
<th id="qty_header_id" class="listheading" nowrap width="5" ><a href='#' onClick='javascript:kivi.Order.reorder_items("qty")'> [%- 'Qty' | $T8 %]</a></th>
|
|
165 | 165 |
<th class="listheading" nowrap width="5" >[%- 'Price Factor' | $T8 %] </th> |
166 | 166 |
<th class="listheading" nowrap width="5" >[%- 'Unit' | $T8 %] </th> |
167 | 167 |
<th class="listheading" nowrap width="5" >[%- 'Price Source' | $T8 %] </th> |
168 |
<th id="sellprice_header_id" class="listheading" nowrap width="15" ><a href='#' onClick='javascript:reorder_items("sellprice")'> [%- 'Price' | $T8 %]</a></th> |
|
169 |
<th id="discount_header_id" class="listheading" nowrap width="15" ><a href='#' onClick='javascript:reorder_items("discount")'> [%- 'Discount' | $T8 %]</a></th> |
|
168 |
<th id="sellprice_header_id" class="listheading" nowrap width="15" ><a href='#' onClick='javascript:kivi.Order.reorder_items("sellprice")'> [%- 'Price' | $T8 %]</a></th>
|
|
169 |
<th id="discount_header_id" class="listheading" nowrap width="15" ><a href='#' onClick='javascript:kivi.Order.reorder_items("discount")'> [%- 'Discount' | $T8 %]</a></th>
|
|
170 | 170 |
<th class="listheading" nowrap width="10">[%- 'Extended' | $T8 %] </th> |
171 | 171 |
</tr> |
172 | 172 |
</thead> |
... | ... | |
264 | 264 |
|
265 | 265 |
</div> |
266 | 266 |
|
267 |
|
|
268 | 267 |
[% L.sortable_element('#row_table_id') %] |
269 |
|
|
270 |
<script type='text/javascript'> |
|
271 |
function reload_cv_dependend_selections() { |
|
272 |
var data = $('#order_form').serializeArray(); |
|
273 |
data.push({ name: 'action', value: 'Order/customer_vendor_changed' }); |
|
274 |
|
|
275 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
276 |
} |
|
277 |
|
|
278 |
function unit_change(event) { |
|
279 |
var row = $(event.target).parents("tbody").first(); |
|
280 |
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]'); |
|
281 |
var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]'); |
|
282 |
var select_elt = $(row).find('[name="order.orderitems[].unit"]'); |
|
283 |
|
|
284 |
var oldval = $(select_elt).data('oldval'); |
|
285 |
$(select_elt).data('oldval', $(select_elt).val()); |
|
286 |
|
|
287 |
var data = $('#order_form').serializeArray(); |
|
288 |
data.push({ name: 'action', value: 'Order/unit_changed' }); |
|
289 |
data.push({ name: 'item_id', value: item_id_dom.val() }); |
|
290 |
data.push({ name: 'old_unit', value: oldval }); |
|
291 |
data.push({ name: 'sellprice_dom_id', value: sellprice_dom.attr('id') }); |
|
292 |
|
|
293 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
294 |
} |
|
295 |
|
|
296 |
function update_sellprice(item_id, price_str) { |
|
297 |
var row = $('#item_' + item_id).parents("tbody").first(); |
|
298 |
var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]'); |
|
299 |
var html_elt = $(row).find('[name="sellprice_text"]'); |
|
300 |
price_elt.val(price_str); |
|
301 |
html_elt.html(price_str); |
|
302 |
} |
|
303 |
|
|
304 |
function add_item() { |
|
305 |
if ($('#add_item_parts_id').val() == '') return; |
|
306 |
if (!check_cv()) return; |
|
307 |
|
|
308 |
$('#row_table_id thead a img').remove(); |
|
309 |
|
|
310 |
var data = $('#order_form').serializeArray(); |
|
311 |
data.push({ name: 'action', value: 'Order/add_item' }); |
|
312 |
|
|
313 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
314 |
} |
|
315 |
|
|
316 |
function show_multi_items_dialog() { |
|
317 |
if (!check_cv()) return; |
|
318 |
|
|
319 |
$('#row_table_id thead a img').remove(); |
|
320 |
|
|
321 |
kivi.popup_dialog({ |
|
322 |
url: 'controller.pl?action=Order/show_multi_items_dialog', |
|
323 |
data: { type: $('#type').val(), |
|
324 |
callback: 'Order/add_multi_items', |
|
325 |
callback_data_id: 'order_form' }, |
|
326 |
id: 'jq_multi_items_dialog', |
|
327 |
dialog: { |
|
328 |
title: kivi.t8('Add multiple items'), |
|
329 |
width: 800, |
|
330 |
height: 500 |
|
331 |
} |
|
332 |
}); |
|
333 |
return true; |
|
334 |
} |
|
335 |
|
|
336 |
function close_multi_items_dialog() { |
|
337 |
$('#jq_multi_items_dialog').dialog('close'); |
|
338 |
}; |
|
339 |
|
|
340 |
function delete_order_item_row(clicked) { |
|
341 |
var row = $(clicked).parents("tbody").first(); |
|
342 |
$(row).remove(); |
|
343 |
|
|
344 |
renumber_positions(); |
|
345 |
recalc_amounts_and_taxes(); |
|
346 |
} |
|
347 |
|
|
348 |
function price_chooser_item_row(clicked) { |
|
349 |
var row = $(clicked).parents("tbody").first(); |
|
350 |
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]'); |
|
351 |
|
|
352 |
var data = $('#order_form').serializeArray(); |
|
353 |
data.push({ name: 'action', value: 'Order/price_popup' }); |
|
354 |
data.push({ name: 'item_id', value: item_id_dom.val() }); |
|
355 |
|
|
356 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
357 |
} |
|
358 |
|
|
359 |
function update_price_source(item_id, source, descr, price_str) { |
|
360 |
var row = $('#item_' + item_id).parents("tbody").first(); |
|
361 |
var source_elt = $(row).find('[name="order.orderitems[].active_price_source"]'); |
|
362 |
var button_elt = $(row).find('[name="price_chooser_button"]'); |
|
363 |
|
|
364 |
button_elt.val(button_elt.val().replace(/.*\|/, descr + " |")); |
|
365 |
source_elt.val(source); |
|
366 |
|
|
367 |
var editable_div_elt = $(row).find('[name="editable_price"]'); |
|
368 |
var not_editable_div_elt = $(row).find('[name="not_editable_price"]'); |
|
369 |
if ([%- AUTH.assert('edit_prices', 1) %] == 1 && source == '') { |
|
370 |
// editable |
|
371 |
$(editable_div_elt).show(); |
|
372 |
$(not_editable_div_elt).hide(); |
|
373 |
$(editable_div_elt).find(':input').prop("disabled", false); |
|
374 |
$(not_editable_div_elt).find(':input').prop("disabled", true); |
|
375 |
} else { |
|
376 |
// not editable |
|
377 |
$(editable_div_elt).hide(); |
|
378 |
$(not_editable_div_elt).show(); |
|
379 |
$(editable_div_elt).find(':input').prop("disabled", true); |
|
380 |
$(not_editable_div_elt).find(':input').prop("disabled", false); |
|
381 |
} |
|
382 |
|
|
383 |
if (price_str) { |
|
384 |
var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]'); |
|
385 |
var html_elt = $(row).find('[name="sellprice_text"]'); |
|
386 |
price_elt.val(price_str); |
|
387 |
html_elt.html(price_str); |
|
388 |
recalc_amounts_and_taxes(); |
|
389 |
} |
|
390 |
|
|
391 |
kivi.io.close_dialog(); |
|
392 |
} |
|
393 |
|
|
394 |
function update_discount_source(item_id, source, descr, discount_str) { |
|
395 |
var row = $('#item_' + item_id).parents("tbody").first(); |
|
396 |
var source_elt = $(row).find('[name="order.orderitems[].active_discount_source"]'); |
|
397 |
var button_elt = $(row).find('[name="price_chooser_button"]'); |
|
398 |
|
|
399 |
button_elt.val(button_elt.val().replace(/\|.*/, "| " + descr)); |
|
400 |
source_elt.val(source); |
|
401 |
|
|
402 |
var editable_div_elt = $(row).find('[name="editable_discount"]'); |
|
403 |
var not_editable_div_elt = $(row).find('[name="not_editable_discount"]'); |
|
404 |
if ([%- AUTH.assert('edit_prices', 1) %] == 1 && source == '') { |
|
405 |
// editable |
|
406 |
$(editable_div_elt).show(); |
|
407 |
$(not_editable_div_elt).hide(); |
|
408 |
$(editable_div_elt).find(':input').prop("disabled", false); |
|
409 |
$(not_editable_div_elt).find(':input').prop("disabled", true); |
|
410 |
} else { |
|
411 |
// not editable |
|
412 |
$(editable_div_elt).hide(); |
|
413 |
$(not_editable_div_elt).show(); |
|
414 |
$(editable_div_elt).find(':input').prop("disabled", true); |
|
415 |
$(not_editable_div_elt).find(':input').prop("disabled", false); |
|
416 |
} |
|
417 |
|
|
418 |
if (discount_str) { |
|
419 |
var discount_elt = $(row).find('[name="order.orderitems[].discount_as_percent"]'); |
|
420 |
var html_elt = $(row).find('[name="discount_text"]'); |
|
421 |
discount_elt.val(discount_str); |
|
422 |
html_elt.html(discount_str); |
|
423 |
recalc_amounts_and_taxes(); |
|
424 |
} |
|
425 |
|
|
426 |
kivi.io.close_dialog(); |
|
427 |
} |
|
428 |
|
|
429 |
function reformat_number(event) { |
|
430 |
$(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2)); |
|
431 |
} |
|
432 |
|
|
433 |
function recalc_amounts_and_taxes() { |
|
434 |
var data = $('#order_form').serializeArray(); |
|
435 |
data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' }); |
|
436 |
|
|
437 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
438 |
} |
|
439 |
|
|
440 |
function redisplay_linetotals(data) { |
|
441 |
$('.row_entry [name="linetotal"]').each(function(idx, elt) { |
|
442 |
$(elt).html(data[idx]); |
|
443 |
}); |
|
444 |
} |
|
445 |
|
|
446 |
function row_table_scroll_down() { |
|
447 |
$('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight); |
|
448 |
} |
|
449 |
|
|
450 |
var email_dialog; |
|
451 |
|
|
452 |
function show_email_dialog(html) { |
|
453 |
var id = 'jqueryui_popup_dialog'; |
|
454 |
var dialog_params = { |
|
455 |
id: id, |
|
456 |
width: 800, |
|
457 |
height: 500, |
|
458 |
modal: true, |
|
459 |
close: function(event, ui) { |
|
460 |
email_dialog.remove(); |
|
461 |
}, |
|
462 |
}; |
|
463 |
|
|
464 |
$('#' + id).remove(); |
|
465 |
|
|
466 |
email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body'); |
|
467 |
email_dialog.html(html); |
|
468 |
email_dialog.dialog(dialog_params); |
|
469 |
|
|
470 |
$('.cancel').click(close_email_dialog); |
|
471 |
|
|
472 |
return true; |
|
473 |
} |
|
474 |
|
|
475 |
close_email_dialog = function() { |
|
476 |
email_dialog.dialog("close"); |
|
477 |
} |
|
478 |
|
|
479 |
function renumber_positions() { |
|
480 |
$('.row_entry [name="position"]').each(function(idx, elt) { |
|
481 |
$(elt).html(idx+1); |
|
482 |
}); |
|
483 |
} |
|
484 |
|
|
485 |
function reorder_items(order_by) { |
|
486 |
var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir"); |
|
487 |
$('#row_table_id thead a img').remove(); |
|
488 |
|
|
489 |
var src; |
|
490 |
if (dir == "1") { |
|
491 |
dir = "0"; |
|
492 |
src = "image/up.png"; |
|
493 |
} else { |
|
494 |
dir = "1"; |
|
495 |
src = "image/down.png"; |
|
496 |
}; |
|
497 |
|
|
498 |
$('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="[%- LxERP.t8('sort items') %]">'); |
|
499 |
|
|
500 |
var data = $('#order_form').serializeArray(); |
|
501 |
data.push({ name: 'action', value: 'Order/reorder_items' }); |
|
502 |
data.push({ name: 'order_by', value: order_by }); |
|
503 |
data.push({ name: 'sort_dir', value: dir }); |
|
504 |
|
|
505 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
506 |
} |
|
507 |
|
|
508 |
function redisplay_items(data) { |
|
509 |
var old_rows = $('.row_entry').detach(); |
|
510 |
var new_rows = []; |
|
511 |
$(data).each(function(idx, elt) { |
|
512 |
new_rows.push(old_rows[elt.old_pos - 1]); |
|
513 |
}); |
|
514 |
$(new_rows).appendTo($('#row_table_id')); |
|
515 |
renumber_positions(); |
|
516 |
} |
|
517 |
|
|
518 |
function show_longdescription_dialog(clicked) { |
|
519 |
var row = $(clicked).parents("tbody").first(); |
|
520 |
var position = $(row).find('[name="position"]').html(); |
|
521 |
var partnumber = $(row).find('[name="partnumber"]').html(); |
|
522 |
var description_elt = $(row).find('[name="order.orderitems[].description"]'); |
|
523 |
var description = description_elt.val(); |
|
524 |
var longdescription_elt = $(row).find('[name="order.orderitems[].longdescription"]'); |
|
525 |
var longdescription; |
|
526 |
|
|
527 |
if (!longdescription_elt.length) { |
|
528 |
var data = []; |
|
529 |
data.push({ name: 'action', value: 'Order/get_item_longdescription' }); |
|
530 |
data.push({ name: 'type', value: $('#type').val() }); |
|
531 |
data.push({ name: 'item_id', value: $(row).find('[name="order.orderitems[+].id"]').val() }); |
|
532 |
data.push({ name: 'parts_id', value: $(row).find('[name="order.orderitems[].parts_id"]').val() }); |
|
533 |
$.ajax({ |
|
534 |
url: 'controller.pl', |
|
535 |
data: data, |
|
536 |
method: "GET", |
|
537 |
async: false, |
|
538 |
dataType: 'text', |
|
539 |
success: function(val){ |
|
540 |
longdescription = val; |
|
541 |
} |
|
542 |
}); |
|
543 |
} else { |
|
544 |
longdescription = longdescription_elt.val(); |
|
545 |
} |
|
546 |
|
|
547 |
var params = { runningnumber: position, |
|
548 |
partnumber: partnumber, |
|
549 |
description: description, |
|
550 |
default_longdescription: longdescription, |
|
551 |
set_function: function(val){ |
|
552 |
longdescription_elt.remove(); |
|
553 |
$('<input type="hidden" name="order.orderitems[].longdescription">').insertAfter(description_elt).val(val); |
|
554 |
} |
|
555 |
}; |
|
556 |
|
|
557 |
kivi.SalesPurchase.edit_longdescription_with_params(params); |
|
558 |
} |
|
559 |
|
|
560 |
function init_row_handlers() { |
|
561 |
kivi.run_once_for('.recalc', 'on_change_recalc', function(elt) { |
|
562 |
$(elt).change(recalc_amounts_and_taxes); |
|
563 |
}); |
|
564 |
|
|
565 |
kivi.run_once_for('.reformat_number', 'on_change_reformat', function(elt) { |
|
566 |
$(elt).change(reformat_number); |
|
567 |
}); |
|
568 |
|
|
569 |
kivi.run_once_for('.unitselect', 'on_change_unit_with_oldval', function(elt) { |
|
570 |
$(elt).data('oldval', $(elt).val()); |
|
571 |
$(elt).change(unit_change); |
|
572 |
}); |
|
573 |
|
|
574 |
kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) { |
|
575 |
$(elt).keydown(function(event) { |
|
576 |
if(event.keyCode == 40 && event.shiftKey == true) { |
|
577 |
// shift arrow down |
|
578 |
event.preventDefault(); |
|
579 |
var row = $(event.target).parents(".row_entry").first(); |
|
580 |
$(row).children().not(':first').show(); |
|
581 |
return false; |
|
582 |
} |
|
583 |
if(event.keyCode == 38 && event.shiftKey == true) { |
|
584 |
// shift arrow up |
|
585 |
event.preventDefault(); |
|
586 |
var row = $(event.target).parents(".row_entry").first(); |
|
587 |
$(row).children().not(':first').hide(); |
|
588 |
return false; |
|
589 |
} |
|
590 |
}); |
|
591 |
$(elt).dblclick(function(event) { |
|
592 |
event.preventDefault(); |
|
593 |
var row = $(event.target).parents(".row_entry").first(); |
|
594 |
$(row).children().not(':first').toggle(); |
|
595 |
return false; |
|
596 |
}); |
|
597 |
}); |
|
598 |
} |
|
599 |
|
|
600 |
|
|
601 |
$(function(){ |
|
602 |
$('#order_[%- cv_id %]').change(reload_cv_dependend_selections); |
|
603 |
[%- IF SELF.cv == 'customer' %] |
|
604 |
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) }); |
|
605 |
[%- ELSE %] |
|
606 |
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.lastcost, -2)) }); |
|
607 |
[%- END %] |
|
608 |
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_description').val(o.description) }); |
|
609 |
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) }); |
|
610 |
$('.add_item_input').keydown(function(event) { |
|
611 |
if(event.keyCode == 13) { |
|
612 |
event.preventDefault(); |
|
613 |
add_item(); |
|
614 |
return false; |
|
615 |
} |
|
616 |
}); |
|
617 |
init_row_handlers(); |
|
618 |
}); |
|
619 |
|
|
620 |
$('#row_table_id').on('sortstop', function(event, ui) { |
|
621 |
$('#row_table_id thead a img').remove(); |
|
622 |
renumber_positions(); |
|
623 |
}); |
|
624 |
</script> |
Auch abrufbar als: Unified diff
Auftrags-Controller: javascript-Code in eigene Datei auslagern