Auftrags-Controller: Sortieren der Positionen
[kivitendo-erp.git] / templates / webpages / order / tabs / basic_data.html
1 [%- USE T8 %]
2 [%- USE HTML %]
3 [%- USE LxERP %]
4 [%- USE L %]
5
6 <div id="ui-tabs-basic-data">
7   <table width="100%">
8     <tr valign="top">
9       <td>
10         <table width="100%">
11           <tr>
12             <th align="right">[% SELF.cv | $T8 %]</th>
13             [% SET cv_id = SELF.cv _ '_id' %]
14             <td>[% L.customer_vendor_picker("order.${SELF.cv}" _ '_id', SELF.order.$cv_id, type=SELF.cv, style='width: 300px') %]</td>
15           </tr>
16
17           <tr id='cp_row' [%- IF !SELF.order.${SELF.cv}.contacts.size %]style='display:none'[%- END %]>
18             <th align="right">[% 'Contact Person' | $T8 %]</th>
19             <td>[% L.select_tag('order.cp_id',
20                                 SELF.order.${SELF.cv}.contacts,
21                                 default=SELF.order.cp_id,
22                                 title_key='full_name_dep',
23                                 value_key='cp_id',
24                                 with_empty=1,
25                                 style='width: 300px') %]</td>
26           </tr>
27
28           <tr id='shipto_row' [%- IF !SELF.order.${SELF.cv}.shipto.size %]style='display:none'[%- END %]>
29             <th align="right">[% 'Shipping Address' | $T8 %]</th>
30             <td>[% L.select_tag('order.shipto_id',
31                                 SELF.order.${SELF.cv}.shipto,
32                                 default=SELF.order.shipto_id,
33                                 title_key='displayable_id',
34                                 value_key='shipto_id',
35                                 with_empty=1,
36                                 style='width: 300px') %]</td>
37           </tr>
38
39           <tr>
40             <th align="right">[% 'Steuersatz' | $T8 %]</th>
41             <td>[% L.select_tag('order.taxzone_id', SELF.all_taxzones, default=SELF.order.taxzone_id, title_key='description', style='width: 300px', class='recalc') %]</td>
42           </tr>
43
44 [%- IF SELF.all_departments.size %]
45           <tr>
46             <th align="right">[% 'Department' | $T8 %]</th>
47             <td>
48               [% L.select_tag('order.department_id', SELF.all_departments, default=SELF.order.department_id, title_key='description', with_empty=1, style='width:300px') %]
49             </td>
50           </tr>
51 [%- END %]
52
53           <tr>
54             <th align="right">[% 'Shipping Point' | $T8 %]</th>
55             <td>[% L.input_tag('order.shippingpoint', SELF.order.shippingpoint, style='width: 300px') %]</td>
56           </tr>
57
58           <tr>
59             <th align="right">[% 'Ship via' | $T8 %]</th>
60             <td>[% L.input_tag('order.shipvia', SELF.order.shipvia, style='width: 300px') %]</td>
61           </tr>
62
63           <tr>
64             <th align="right">[% 'Transaction description' | $T8 %]</th>
65             <td>[% L.input_tag('order.transaction_description', SELF.order.transaction_description, style='width: 300px') %]</td>
66           </tr>
67
68           <tr>
69             <th align="right">[% 'Project Number' | $T8 %]</th>
70             <td>[% L.project_picker('order.globalproject_id', SELF.order.globalproject_id, style='width: 300px') %]</td>
71           </tr>
72
73         </table>
74       </td>
75
76       <td align="right">
77         <table>
78
79           <tr>
80             <td colspan="2" align="center">
81               [%- IF SELF.order.id %]
82                 <label for="order.delivered">[% 'Delivery Order(s) for full qty created' | $T8 %]</label>
83                 [% L.yes_no_tag('order.delivered', SELF.order.delivered) %]
84                 <label for="order.closed">[% 'Closed' | $T8 %]</label>
85                 [% L.yes_no_tag('order.closed', SELF.order.closed) %]
86               [%- END %]
87             </td>
88           </tr>
89
90           <tr>
91             <th align="right">[% 'Employee' | $T8 %]</th>
92             <td>[% L.select_tag('order.employee_id',
93               SELF.all_employees,
94               default=(SELF.order.employee_id ? SELF.order.employee_id : SELF.current_employee_id),
95               title_key='safe_name') %]</td>
96           </tr>
97
98           [% IF SELF.cv == 'customer' %]
99           <tr>
100             <th align="right">[% 'Salesman' | $T8 %]</th>
101             <td>[% L.select_tag('order.salesman_id',
102               SELF.all_salesmen,
103               default=(SELF.order.salesman_id ? SELF.order.salesman_id : SELF.current_employee_id),
104               title_key='safe_name') %]</td>
105           </tr>
106           [% END %]
107
108           <tr>
109             <th width="70%" align="right" nowrap>[% 'Order Number' | $T8 %]</th>
110             <td>[% L.input_tag('order.ordnumber', SELF.order.ordnumber, size = 11) %]</td>
111           </tr>
112
113           <tr>
114             <th width="70%" align="right" nowrap>[% 'Quotation Number' | $T8 %]</th>
115             <td>[% L.input_tag('order.quonumber', SELF.order.quonumber, size = 11) %]</td>
116           </tr>
117
118           <tr>
119             <th width="70%" align="right" nowrap>[% 'Customer Order Number' | $T8 %]</th>
120             <td>[% L.input_tag('order.cusordnumber', SELF.order.cusordnumber, size = 11) %]</td>
121           </tr>
122
123           <tr>
124             <th width="70%" align="right" nowrap>[% 'Order Date' | $T8 %]</th>
125             <td>[% L.date_tag('order.transdate', SELF.order.transdate) %]</td>
126           </tr>
127
128           <tr>
129             <th width="70%" align="right" nowrap>[% 'Reqdate' | $T8 %]</th>
130             <td>[% L.date_tag('order.reqdate', SELF.order.reqdate) %]</td>
131           </tr>
132
133           <tr>
134             <th width="70%" align="right" nowrap>[% 'Insert Date' | $T8 %]</th>
135             <td>[% SELF.order.itime_as_date %]</td>
136           </tr>
137
138         </table>
139
140       </td>
141     </tr>
142   </table>
143
144   [%- PROCESS order/tabs/_item_input.html %]
145
146   [% L.button_tag('show_multi_items_dialog()', LxERP.t8('Add multiple parts')) %]</td>
147
148   <table width="100%">
149     <tr>
150       <td>
151
152         <div id="row_table_scroll_id" style="overflow-y: auto; height: 25vh">
153           <table id="row_table_id" width="100%">
154             <thead>
155               <tr class="listheading">
156                 <th class="listheading" style='display:none'></th>
157                 <th class="listheading" nowrap width="3" >[%- 'position'     | $T8 %] </th>
158                 <th class="listheading" style='text-align:center' nowrap width="1"><img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]"></th>
159                 <th class="listheading" style='text-align:center' nowrap width="1"><img src="image/close.png" alt="[%- LxERP.t8('delete item') %]"></th>
160                 <th id="partnumber_header_id"  class="listheading" nowrap width="15"><a href='#' onClick='javascript:reorder_items("partnumber")'> [%- 'Partnumber'  | $T8 %]</a></th>
161                 <th id="description_header_id" class="listheading" nowrap           ><a href='#' onClick='javascript:reorder_items("description")'>[%- 'Description' | $T8 %]</a></th>
162                 <th id="qty_header_id"         class="listheading" nowrap width="5" ><a href='#' onClick='javascript:reorder_items("qty")'>        [%- 'Qty'         | $T8 %]</a></th>
163                 <th class="listheading" nowrap width="5" >[%- 'Price Factor' | $T8 %] </th>
164                 <th class="listheading" nowrap width="5" >[%- 'Unit'         | $T8 %] </th>
165                 <th class="listheading" nowrap width="5" >[%- 'Price Source' | $T8 %] </th>
166                 <th id="sellprice_header_id"   class="listheading" nowrap width="15" ><a href='#' onClick='javascript:reorder_items("sellprice")'> [%- 'Price'       | $T8 %]</a></th>
167                 <th id="discount_header_id"    class="listheading" nowrap width="15" ><a href='#' onClick='javascript:reorder_items("discount")'>  [%- 'Discount'    | $T8 %]</a></th>
168                 <th class="listheading" nowrap width="10">[%- 'Extended'     | $T8 %] </th>
169               </tr>
170             </thead>
171
172             [%- FOREACH item = SELF.order.items_sorted %]
173               [%- PROCESS order/tabs/_row.html ITEM=item ID=item.id %]
174             [%- END %]
175
176           </table>
177         </div>
178
179       </td>
180     </tr>
181
182     <tr>
183     </tr>
184
185     <tr>
186       <td colspan="100%" width="100%">
187         <table width="100%">
188           <tr>
189             <td>
190               <table>
191                 <tr>
192                   <th align="left">[% 'Notes' | $T8 %]</th>
193                   <th align="left">[% 'Internal Notes' | $T8 %]</th>
194                 </tr>
195                 <tr valign="top">
196                   <td>
197                     [% L.textarea_tag('order.notes', SELF.order.notes, wrap="soft", style="width: 350px; height: 150px", class="texteditor") %]
198                   </td>
199                   <td>
200                     [% L.textarea_tag('order.intnotes', SELF.order.intnotes, wrap="soft", style="width: 350px; height: 150px") %]
201                   </td>
202                 </tr>
203               </table>
204             </td>
205
206             <td>
207               <table>
208                 <tr>
209                   <th align="right">[% 'Payment Terms' | $T8 %]</th>
210                   <td>[% L.select_tag('order.payment_id',
211                                       SELF.all_payment_terms,
212                                       default = SELF.order.payment_id,
213                                       with_empty = 1,
214                                       title_key = 'description',
215                                       style = 'width: 250px') %]</td>
216                 </tr>
217                 <tr>
218                   <th align="right">[% 'Delivery Terms' | $T8 %]</th>
219                   <td>[% L.select_tag('order.delivery_term_id',
220                                       SELF.all_delivery_terms,
221                                       default = SELF.order.delivery_term_id,
222                                       with_empty = 1,
223                                       title_key = 'description',
224                                       style = 'width: 250px') %]</td>
225                 </tr>
226               </table>
227             </td>
228
229             <td align="right">
230               <table>
231                 <tr id="taxincluded_row_id" [%- IF !SELF.taxes.size %]style="display:none"[%- END %]>
232                   <td align=right colspan="2">
233                     <label for="order.taxincluded"><b>[% 'Tax Included' | $T8 %]</b></label>
234                     [% L.yes_no_tag('order.taxincluded', SELF.order.taxincluded, class='recalc') %]
235                   </td>
236                 </tr>
237
238                 <tr id="subtotal_row_id" [%- IF SELF.order.taxincluded %]style="display:none"[%- END %]>
239                   <th align="right">[%- 'Subtotal' | $T8 %]</th>
240                   <td align="right">
241                     [%- L.div_tag(SELF.order.netamount_as_number, id='netamount_id') %]
242                   </td>
243                 </tr>
244                 [%- FOREACH tax = SELF.taxes %]
245                   [%- PROCESS order/tabs/_tax_row.html TAX=tax TAXINCLUDED=SELF.order.taxincluded %]
246                 [%- END %]
247                 <tr id="amount_row_id">
248                   <th align="right">[%- 'Total' | $T8 %]</th>
249                   <td align="right">
250                     [%- L.div_tag(SELF.order.amount_as_number, id='amount_id') %]
251                   </td>
252                 </tr>
253               </table>
254             </td>
255
256           </tr>
257         </table>
258       </td>
259     </tr>
260
261   </table>
262
263 </div>
264
265
266 [% L.sortable_element('#row_table_id') %]
267
268 <script type='text/javascript'>
269 function reload_cv_dependend_selections() {
270   var data = $('#order_form').serialize();
271   data += '&action=Order/customer_vendor_changed';
272
273   $.post("controller.pl", data, kivi.eval_json_result);
274 }
275
276 function unit_change(event) {
277   var row = $(event.target).parents("tbody").first();
278   var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
279   var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
280   var select_elt = $(row).find('[name="order.orderitems[].unit"]');
281
282   var oldval = $(select_elt).data('oldval');
283   $(select_elt).data('oldval', $(select_elt).val());
284
285   var data = $('#order_form').serialize();
286   data += '&action=Order/unit_changed';
287   data += '&item_id=' + item_id_dom.val();
288   data += '&old_unit=' + oldval;
289   data += '&sellprice_dom_id=' + sellprice_dom.attr('id');
290
291   $.post("controller.pl", data, kivi.eval_json_result);
292 }
293
294 function update_sellprice(item_id, price_str) {
295   var row = $('#item_' + item_id).parents("tbody").first();
296   var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
297   var html_elt  = $(row).find('[name="sellprice_text"]');
298   price_elt.val(price_str);
299   html_elt.html(price_str);
300 }
301
302 function add_item() {
303   if ($('#add_item_parts_id').val() == '') return;
304   if (!check_cv()) return;
305
306   $('#row_table_id thead a img').remove();
307
308   var data = $('#order_form').serialize();
309   data += '&action=Order/add_item';
310
311   $.post("controller.pl", data, kivi.eval_json_result);
312 }
313
314 function show_multi_items_dialog() {
315   if (!check_cv()) return;
316
317   $('#row_table_id thead a img').remove();
318
319   kivi.popup_dialog({
320     url: 'controller.pl?action=Order/show_multi_items_dialog',
321     data: { type: $('#type').val(),
322             callback: 'Order/add_multi_items',
323             callback_data_id: 'order_form' },
324     id: 'jq_multi_items_dialog',
325     dialog: {
326       title: kivi.t8('Add multiple items'),
327       width:  800,
328       height: 500
329     }
330   });
331   return true;
332 }
333
334 function close_multi_items_dialog() {
335   $('#jq_multi_items_dialog').dialog('close');
336 };
337
338 function delete_order_item_row(clicked) {
339   var row = $(clicked).parents("tbody").first();
340   $(row).remove();
341
342   renumber_positions();
343   recalc_amounts_and_taxes();
344 }
345
346 function price_chooser_item_row(clicked) {
347   var row = $(clicked).parents("tbody").first();
348   var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
349
350   var data = $('#order_form').serialize();
351   data += '&action=Order/price_popup';
352   data += '&item_id=' + item_id_dom.val();
353
354   $.post("controller.pl", data, kivi.eval_json_result);
355 }
356
357 function update_price_source(item_id, source, descr, price_str) {
358   var row = $('#item_' + item_id).parents("tbody").first();
359   var source_elt = $(row).find('[name="order.orderitems[].active_price_source"]');
360   var button_elt = $(row).find('[name="price_chooser_button"]');
361
362   button_elt.val(button_elt.val().replace(/.*\|/, descr + " |"));
363   source_elt.val(source);
364
365   var editable_div_elt = $(row).find('[name="editable_price"]');
366   var not_editable_div_elt = $(row).find('[name="not_editable_price"]');
367   if ([%- AUTH.assert('edit_prices', 1) %] == 1 && source == '') {
368     // editable
369     $(editable_div_elt).show();
370     $(not_editable_div_elt).hide();
371     $(editable_div_elt).find(':input').prop("disabled", false);
372     $(not_editable_div_elt).find(':input').prop("disabled", true);
373   } else {
374     // not editable
375     $(editable_div_elt).hide();
376     $(not_editable_div_elt).show();
377     $(editable_div_elt).find(':input').prop("disabled", true);
378     $(not_editable_div_elt).find(':input').prop("disabled", false);
379   }
380
381   if (price_str) {
382     var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
383     var html_elt  = $(row).find('[name="sellprice_text"]');
384     price_elt.val(price_str);
385     html_elt.html(price_str);
386     recalc_amounts_and_taxes();
387   }
388
389   kivi.io.close_dialog();
390 }
391
392 function update_discount_source(item_id, source, descr, discount_str) {
393   var row = $('#item_' + item_id).parents("tbody").first();
394   var source_elt = $(row).find('[name="order.orderitems[].active_discount_source"]');
395   var button_elt = $(row).find('[name="price_chooser_button"]');
396
397   button_elt.val(button_elt.val().replace(/\|.*/, "| " + descr));
398   source_elt.val(source);
399
400   var editable_div_elt = $(row).find('[name="editable_discount"]');
401   var not_editable_div_elt = $(row).find('[name="not_editable_discount"]');
402   if ([%- AUTH.assert('edit_prices', 1) %] == 1 && source == '') {
403     // editable
404     $(editable_div_elt).show();
405     $(not_editable_div_elt).hide();
406     $(editable_div_elt).find(':input').prop("disabled", false);
407     $(not_editable_div_elt).find(':input').prop("disabled", true);
408   } else {
409     // not editable
410     $(editable_div_elt).hide();
411     $(not_editable_div_elt).show();
412     $(editable_div_elt).find(':input').prop("disabled", true);
413     $(not_editable_div_elt).find(':input').prop("disabled", false);
414   }
415
416   if (discount_str) {
417     var discount_elt = $(row).find('[name="order.orderitems[].discount_as_percent"]');
418     var html_elt     = $(row).find('[name="discount_text"]');
419     discount_elt.val(discount_str);
420     html_elt.html(discount_str);
421     recalc_amounts_and_taxes();
422   }
423
424   kivi.io.close_dialog();
425 }
426
427 function reformat_number(event) {
428   $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
429 }
430
431 function recalc_amounts_and_taxes() {
432   var data = $('#order_form').serialize();
433   data += '&action=Order/recalc_amounts_and_taxes';
434
435   $.post("controller.pl", data, kivi.eval_json_result);
436 }
437
438 function redisplay_linetotals(data) {
439   $('.row_entry [name="linetotal"]').each(function(idx, elt) {
440     $(elt).html(data[idx]);
441   });
442 }
443
444 function row_table_scroll_down() {
445   $('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight);
446 }
447
448 function row_set_keyboard_events_by_id(item_id) {
449   var row = $('#item_' + item_id).parents("tbody").first();
450
451   row_set_keyboard_events(row);
452 }
453
454 function row_set_keyboard_events(rows) {
455   $(rows).keydown(function(event) {
456     if(event.keyCode == 40 && event.shiftKey == true) {
457       // shift arrow down
458       event.preventDefault();
459       var row = $(event.target).parents(".row_entry").first();
460       $(row).children().not(':first').show();
461       return false;
462     }
463     if(event.keyCode == 38 && event.shiftKey == true) {
464       // shift arrow up
465       event.preventDefault();
466       var row = $(event.target).parents(".row_entry").first();
467       $(row).children().not(':first').hide();
468       return false;
469     }
470   });
471
472   $(rows).dblclick(function(event) {
473       event.preventDefault();
474       var row = $(event.target).parents(".row_entry").first();
475       $(row).children().not(':first').toggle();
476       return false;
477   });
478 }
479
480 function set_unit_change_with_oldval_by_id(item_id) {
481   var row = $('#item_' + item_id).parents("tbody").first();
482   var select_elt = $(row).find('[name="order.orderitems[].unit"]');
483
484   set_unit_change_with_oldval(select_elt);
485 }
486
487 function set_unit_change_with_oldval(selects) {
488   selects.each(function(idx,elt) {
489     $(elt).data('oldval', $(elt).val());
490   });
491
492   selects.change(unit_change);
493 }
494
495 var email_dialog;
496
497 function show_email_dialog(html) {
498   var id            = 'jqueryui_popup_dialog';
499   var dialog_params = {
500     id:     id,
501     width:  800,
502     height: 500,
503     modal:  true,
504     close: function(event, ui) {
505       email_dialog.remove();
506     },
507   };
508
509   $('#' + id).remove();
510
511   email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
512   email_dialog.html(html);
513   email_dialog.dialog(dialog_params);
514
515   $('.cancel').click(close_email_dialog);
516
517   return true;
518 }
519
520 close_email_dialog = function() {
521   email_dialog.dialog("close");
522 }
523
524 function renumber_positions() {
525   $('.row_entry [name="position"]').each(function(idx, elt) {
526     $(elt).html(idx+1);
527   });
528 }
529
530 function reorder_items(order_by) {
531   var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir");
532   $('#row_table_id thead a img').remove();
533
534   var src;
535   if (dir == "1") {
536     dir = "0";
537     src = "image/up.png";
538   } else {
539     dir = "1";
540     src = "image/down.png";
541   };
542
543   $('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="[%- LxERP.t8('sort items') %]">');
544
545   var data = $('#order_form').serialize();
546   data += '&action=Order/reorder_items';
547   data += '&order_by=' + order_by;
548   data += '&sort_dir=' + dir;
549
550   $.post("controller.pl", data, kivi.eval_json_result);
551 }
552
553 function redisplay_items(data) {
554   var old_rows = $('.row_entry').detach();
555   var new_rows = [];
556   $(data).each(function(idx, elt) {
557     new_rows.push(old_rows[elt.old_pos - 1]);
558   });
559   $(new_rows).appendTo($('#row_table_id'));
560   renumber_positions();
561 }
562
563 $(function(){
564   $('#order_[%- cv_id %]').change(reload_cv_dependend_selections);
565   [%- IF SELF.cv == 'customer' %]
566     $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) });
567   [%- ELSE %]
568     $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.lastcost, -2)) });
569   [%- END %]
570   $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_description').val(o.description) });
571   $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) });
572   $('.add_item_input').keydown(function(event) {
573     if(event.keyCode == 13) {
574       event.preventDefault();
575       add_item();
576       return false;
577     }
578   });
579   row_set_keyboard_events($('.row_entry'));
580   $('.recalc').change(recalc_amounts_and_taxes);
581   $('.reformat_number').change(reformat_number);
582
583   set_unit_change_with_oldval($('.unitselect'));
584 });
585
586 $('#row_table_id').on('sortstop', function(event, ui) {
587   $('#row_table_id thead a img').remove();
588   renumber_positions();
589 });
590 </script>