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