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