Auftrags-Controller: Einheiten per Select ändern können und sellprice anpassen.
[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.closed %] [% 'Closed' | $T8 %] [%- ELSE %] [% 'Open' | $T8 %] [%- END %]
82             </td>
83           </tr>
84
85           <tr>
86             <th align="right">[% 'Employee' | $T8 %]</th>
87             <td>[% L.select_tag('order.employee_id',
88               SELF.all_employees,
89               default=(SELF.order.employee_id ? SELF.order.employee_id : SELF.current_employee_id),
90               title_key='safe_name') %]</td>
91           </tr>
92
93           [% IF SELF.cv == 'customer' %]
94           <tr>
95             <th align="right">[% 'Salesman' | $T8 %]</th>
96             <td>[% L.select_tag('order.salesman_id',
97               SELF.all_salesmen,
98               default=(SELF.order.salesman_id ? SELF.order.salesman_id : SELF.current_employee_id),
99               title_key='safe_name') %]</td>
100           </tr>
101           [% END %]
102
103           <tr>
104             <th width="70%" align="right" nowrap>[% 'Order Number' | $T8 %]</th>
105             <td>[% L.input_tag('order.ordnumber', SELF.order.ordnumber, size = 11) %]</td>
106           </tr>
107
108           <tr>
109             <th width="70%" align="right" nowrap>[% 'Quotation Number' | $T8 %]</th>
110             <td>[% L.input_tag('order.quonumber', SELF.order.quonumber, size = 11) %]</td>
111           </tr>
112
113           <tr>
114             <th width="70%" align="right" nowrap>[% 'Customer Order Number' | $T8 %]</th>
115             <td>[% L.input_tag('order.cusordnumber', SELF.order.cusordnumber, size = 11) %]</td>
116           </tr>
117
118           <tr>
119             <th width="70%" align="right" nowrap>[% 'Order Date' | $T8 %]</th>
120             <td>[% L.date_tag('order.transdate', SELF.order.transdate) %]</td>
121           </tr>
122
123           <tr>
124             <th width="70%" align="right" nowrap>[% 'Reqdate' | $T8 %]</th>
125             <td>[% L.date_tag('order.reqdate', SELF.order.reqdate) %]</td>
126           </tr>
127
128           <tr>
129             <th width="70%" align="right" nowrap>[% 'Insert Date' | $T8 %]</th>
130             <td>[% SELF.order.itime_as_date %]</td>
131           </tr>
132
133         </table>
134
135       </td>
136     </tr>
137   </table>
138
139   [%- PROCESS order/tabs/_item_input.html %]
140
141   [% L.button_tag('show_multi_items_dialog()', LxERP.t8('Add multiple items')) %]</td>
142
143   <table width="100%">
144     <tr>
145       <td>
146
147         <div id="row_table_scroll_id" style="overflow-y: auto; height: 25vh">
148           <table id="row_table_id" width="100%">
149             <thead>
150               <tr class="listheading">
151                 <th class="listheading" style='display:none'></th>
152                 <th class="listheading" style='text-align:center' nowrap width="1"><img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]"></th>
153                 <th class="listheading" style='text-align:center' nowrap width="1"><img src="image/close.png" alt="[%- LxERP.t8('delete item') %]"></th>
154                 <th class="listheading" nowrap width="15">[%- 'Partnumber'  | $T8 %] </th>
155                 <th class="listheading" nowrap           >[%- 'Description'  | $T8 %] </th>
156                 <th class="listheading" nowrap width="5" >[%- 'Qty'          | $T8 %] </th>
157                 <th class="listheading" nowrap width="5" >[%- 'Price Factor' | $T8 %] </th>
158                 <th class="listheading" nowrap width="5" >[%- 'Unit'         | $T8 %] </th>
159                 <th class="listheading" nowrap width="5" >[%- 'Price Source' | $T8 %] </th>
160                 <th class="listheading" nowrap width="15">[%- 'Price'        | $T8 %] </th>
161                 <th class="listheading" nowrap width="5" >[%- 'Discount'     | $T8 %] </th>
162                 <th class="listheading" nowrap width="10">[%- 'Extended'     | $T8 %] </th>
163               </tr>
164             </thead>
165
166             [%- FOREACH item = SELF.order.items_sorted %]
167               [%- PROCESS order/tabs/_row.html ITEM=item ID=item.id %]
168             [%- END %]
169
170           </table>
171         </div>
172
173       </td>
174     </tr>
175
176     <tr>
177     </tr>
178
179     <tr>
180       <td colspan="100%" width="100%">
181         <table width="100%">
182           <tr>
183             <td>
184               <table>
185                 <tr>
186                   <th align="left">[% 'Notes' | $T8 %]</th>
187                   <th align="left">[% 'Internal Notes' | $T8 %]</th>
188                 </tr>
189                 <tr valign="top">
190                   <td>
191                     [% L.textarea_tag('order.notes', SELF.order.notes, wrap="soft", style="width: 350px; height: 150px", class="texteditor") %]
192                   </td>
193                   <td>
194                     [% L.textarea_tag('order.intnotes', SELF.order.intnotes, wrap="soft", style="width: 350px; height: 150px") %]
195                   </td>
196                 </tr>
197               </table>
198             </td>
199
200             <td>
201               <table>
202                 <tr>
203                   <th align="right">[% 'Payment Terms' | $T8 %]</th>
204                   <td>[% L.select_tag('order.payment_id',
205                                       SELF.all_payment_terms,
206                                       default = SELF.order.payment_id,
207                                       with_empty = 1,
208                                       title_key = 'description',
209                                       style = 'width: 250px') %]</td>
210                 </tr>
211                 <tr>
212                   <th align="right">[% 'Delivery Terms' | $T8 %]</th>
213                   <td>[% L.select_tag('order.delivery_term_id',
214                                       SELF.all_delivery_terms,
215                                       default = SELF.order.delivery_term_id,
216                                       with_empty = 1,
217                                       title_key = 'description',
218                                       style = 'width: 250px') %]</td>
219                 </tr>
220               </table>
221             </td>
222
223             <td align="right">
224               <table>
225                 <tr id="taxincluded_row_id" [%- IF !SELF.taxes.size %]style="display:none"[%- END %]>
226                   <td align=right colspan="2">
227                     <label for="order.taxincluded"><b>[% 'Tax Included' | $T8 %]</b></label>
228                     [% L.yes_no_tag('order.taxincluded', SELF.order.taxincluded, class='recalc') %]
229                   </td>
230                 </tr>
231
232                 <tr id="subtotal_row_id" [%- IF SELF.order.taxincluded %]style="display:none"[%- END %]>
233                   <th align="right">[%- 'Subtotal' | $T8 %]</th>
234                   <td align="right">
235                     [%- L.div_tag(SELF.order.netamount_as_number, id='netamount_id') %]
236                   </td>
237                 </tr>
238                 [%- FOREACH tax = SELF.taxes %]
239                   [%- PROCESS order/tabs/_tax_row.html TAX=tax TAXINCLUDED=SELF.order.taxincluded %]
240                 [%- END %]
241                 <tr id="amount_row_id">
242                   <th align="right">[%- 'Total' | $T8 %]</th>
243                   <td align="right">
244                     [%- L.div_tag(SELF.order.amount_as_number, id='amount_id') %]
245                   </td>
246                 </tr>
247               </table>
248             </td>
249
250           </tr>
251         </table>
252       </td>
253     </tr>
254
255   </table>
256
257 </div>
258
259
260 [% L.sortable_element('#row_table_id') %]
261
262 <script type='text/javascript'>
263 function reload_cv_dependend_selections() {
264   var data = $('#order_form').serialize();
265   data += '&action=Order/customer_vendor_changed';
266
267   $.post("controller.pl", data, kivi.eval_json_result);
268 }
269
270 function unit_change(event) {
271   var row = $(event.target).parents("tbody").first();
272   var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
273   var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
274   var select_elt = $(row).find('[name="order.orderitems[].unit"]');
275
276   var oldval = $(select_elt).data('oldval');
277   $(select_elt).data('oldval', $(select_elt).val());
278
279   var data = $('#order_form').serialize();
280   data += '&action=Order/unit_changed';
281   data += '&item_id=' + item_id_dom.val();
282   data += '&old_unit=' + oldval;
283   data += '&sellprice_dom_id=' + sellprice_dom.attr('id');
284
285   $.post("controller.pl", data, kivi.eval_json_result);
286 }
287
288 function update_sellprice(item_id, price_str) {
289   var row = $('#item_' + item_id).parents("tbody").first();
290   var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
291   var html_elt  = $(row).find('[name="sellprice_text"]');
292   price_elt.val(price_str);
293   html_elt.html(price_str);
294 }
295
296 function add_item() {
297   if ($('#add_item_parts_id').val() == '') return;
298   if (!check_cv()) return;
299
300   var data = $('#order_form').serialize();
301   data += '&action=Order/add_item';
302   data += '&type=' + $('#type').val();
303
304   $.post("controller.pl", data, kivi.eval_json_result);
305 }
306
307 function show_multi_items_dialog() {
308   if (!check_cv()) return;
309
310   var data = 'type=' + $('#type').val();
311   data += 'type=' + $('#type').val();
312   kivi.popup_dialog({
313     url: 'controller.pl?action=Order/show_multi_items_dialog',
314     data: $.extend({},
315                    { 'type': $('#type').val(),
316                      'callback': 'Order/add_multi_items',
317                      'callback_data_id': 'order_form' }),
318     id: 'jq_multi_items_dialog',
319     dialog: {
320       title: kivi.t8('Add multiple items'),
321       width:  800,
322       height: 500
323     }
324   });
325   return true;
326 }
327
328 function close_multi_items_dialog() {
329   $('#jq_multi_items_dialog').dialog('close');
330 };
331
332 function delete_order_item_row(clicked) {
333   var row = $(clicked).parents("tbody").first();
334   $(row).remove();
335
336   recalc_amounts_and_taxes();
337 }
338
339 function price_chooser_item_row(clicked) {
340   var row = $(clicked).parents("tbody").first();
341   var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
342
343   var data = $('#order_form').serialize();
344   data += '&action=Order/price_popup';
345   data += '&item_id=' + item_id_dom.val();
346
347   $.post("controller.pl", data, kivi.eval_json_result);
348 }
349
350 function update_price_source(item_id, source, descr, price_str) {
351   var row = $('#item_' + item_id).parents("tbody").first();
352   var source_elt = $(row).find('[name="order.orderitems[].active_price_source"]');
353   var button_elt = $(row).find('[name="price_chooser_button"]');
354
355   button_elt.val(button_elt.val().replace(/.*\|/, descr + " |"));
356   source_elt.val(source);
357
358   var editable_div_elt = $(row).find('[name="editable_price"]');
359   var not_editable_div_elt = $(row).find('[name="not_editable_price"]');
360   if ([%- AUTH.assert('edit_prices', 1) %] == 1 && source == '') {
361     // editable
362     $(editable_div_elt).show();
363     $(not_editable_div_elt).hide();
364     $(editable_div_elt).find(':input').prop("disabled", false);
365     $(not_editable_div_elt).find(':input').prop("disabled", true);
366   } else {
367     // not editable
368     $(editable_div_elt).hide();
369     $(not_editable_div_elt).show();
370     $(editable_div_elt).find(':input').prop("disabled", true);
371     $(not_editable_div_elt).find(':input').prop("disabled", false);
372   }
373
374   if (price_str) {
375     var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
376     var html_elt  = $(row).find('[name="sellprice_text"]');
377     price_elt.val(price_str);
378     html_elt.html(price_str);
379     recalc_amounts_and_taxes();
380   }
381
382   kivi.io.close_dialog();
383 }
384
385 function update_discount_source(item_id, source, descr, discount_str) {
386   var row = $('#item_' + item_id).parents("tbody").first();
387   var source_elt = $(row).find('[name="order.orderitems[].active_discount_source"]');
388   var button_elt = $(row).find('[name="price_chooser_button"]');
389
390   button_elt.val(button_elt.val().replace(/\|.*/, "| " + descr));
391   source_elt.val(source);
392
393   var editable_div_elt = $(row).find('[name="editable_discount"]');
394   var not_editable_div_elt = $(row).find('[name="not_editable_discount"]');
395   if ([%- AUTH.assert('edit_prices', 1) %] == 1 && source == '') {
396     // editable
397     $(editable_div_elt).show();
398     $(not_editable_div_elt).hide();
399     $(editable_div_elt).find(':input').prop("disabled", false);
400     $(not_editable_div_elt).find(':input').prop("disabled", true);
401   } else {
402     // not editable
403     $(editable_div_elt).hide();
404     $(not_editable_div_elt).show();
405     $(editable_div_elt).find(':input').prop("disabled", true);
406     $(not_editable_div_elt).find(':input').prop("disabled", false);
407   }
408
409   if (discount_str) {
410     var discount_elt = $(row).find('[name="order.orderitems[].discount_as_percent"]');
411     var html_elt     = $(row).find('[name="discount_text"]');
412     discount_elt.val(discount_str);
413     html_elt.html(discount_str);
414     recalc_amounts_and_taxes();
415   }
416
417   kivi.io.close_dialog();
418 }
419
420 function reformat_number(event) {
421   $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
422 }
423
424 function recalc_amounts_and_taxes() {
425   var data = $('#order_form').serialize();
426   data += '&action=Order/recalc_amounts_and_taxes';
427   data += '&type=' + $('#type').val();
428
429   $.post("controller.pl", data, kivi.eval_json_result);
430 }
431
432 function redisplay_linetotals(data) {
433   $('.row_entry [name="linetotal"]').each(function(idx, elt) {
434     $(elt).html(data[idx]);
435   });
436 }
437
438 function row_table_scroll_down() {
439   $('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight);
440 }
441
442 function row_set_keyboard_events_by_id(item_id) {
443   var row = $('#item_' + item_id).parents("tbody").first();
444
445   row_set_keyboard_events(row);
446 }
447
448 function row_set_keyboard_events(rows) {
449   $(rows).keydown(function(event) {
450     if(event.keyCode == 40 && event.shiftKey == true) {
451       // shift arrow down
452       event.preventDefault();
453       var row = $(event.target).parents(".row_entry").first();
454       $(row).children().not(':first').show();
455       return false;
456     }
457     if(event.keyCode == 38 && event.shiftKey == true) {
458       // shift arrow up
459       event.preventDefault();
460       var row = $(event.target).parents(".row_entry").first();
461       $(row).children().not(':first').hide();
462       return false;
463     }
464   });
465
466   $(rows).dblclick(function(event) {
467       event.preventDefault();
468       var row = $(event.target).parents(".row_entry").first();
469       $(row).children().not(':first').toggle();
470       return false;
471   });
472 }
473
474 function set_unit_change_with_oldval_by_id(item_id) {
475   var row = $('#item_' + item_id).parents("tbody").first();
476   var select_elt = $(row).find('[name="order.orderitems[].unit"]');
477
478   set_unit_change_with_oldval(select_elt)
479 }
480
481 function set_unit_change_with_oldval(selects) {
482   selects.data('oldval', selects.val());
483
484   selects.change(unit_change);
485 }
486
487 var email_dialog;
488
489 function show_email_dialog(html) {
490   var id            = 'jqueryui_popup_dialog';
491   var dialog_params = {
492     id:     id,
493     width:  800,
494     height: 500,
495     modal:  true,
496     close: function(event, ui) {
497       email_dialog.remove();
498     },
499   };
500
501   $('#' + id).remove();
502
503   email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
504   email_dialog.html(html);
505   email_dialog.dialog(dialog_params);
506
507   $('.cancel').click(close_email_dialog);
508
509   return true;
510 }
511
512 close_email_dialog = function() {
513   email_dialog.dialog("close");
514 }
515
516
517 $(function(){
518   $('#order_[%- cv_id %]').change(reload_cv_dependend_selections);
519   [%- IF SELF.cv == 'customer' %]
520     $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) });
521   [%- ELSE %]
522     $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.lastcost, -2)) });
523   [%- END %]
524   $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_description').val(o.description) });
525   $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) });
526   $('.add_item_input').keydown(function(event) {
527     if(event.keyCode == 13) {
528       event.preventDefault();
529       add_item();
530       return false;
531     }
532   });
533   row_set_keyboard_events($('.row_entry'));
534   $('.recalc').change(recalc_amounts_and_taxes);
535   $('.reformat_number').change(reformat_number);
536
537   set_unit_change_with_oldval($('.unitselect'));
538 });
539
540 </script>