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