Support optional title passed into subject
[infodrom.org/service.infodrom.org] / src / InfoCon / buch / reimbursement.wml
1 #include <infocon.style>
2
3 <future>
4 <page func=InfoCon title="Buchhaltung">
5
6 <style type="text/css">
7 span.in { color: green; }
8 span.out { color: red; }
9 span.in:hover, span.out:hover { background: yellow; border: 1px solid #ccc; }
10 </style>
11
12 <h3>Erstattungen / Offene Buchungen</h3>
13
14 <form id="open_items">
15 Titel <input type="text" id="title" name="title" value="" size="20" title="Optionaler Titel der Liste"><br>
16 <?php
17     $sales = new Sales();
18     foreach ($sales->getOpenItems() as $row) {
19         $date = substr ($row->date,6,2) . "." . substr ($row->date,4,2) . "." . substr ($row->date,0,4);
20         printf('<input name="nr[]" type="checkbox" value="%d" price="%d">&nbsp;', $row->nr, $row->price);
21         printf('<span class="%s">%d&nbsp;&nbsp;%s %s (%.2f&nbsp;&euro;)</span><br>',
22                $row->price < 0 ? 'out' : 'in',
23                $row->nr, $date, $row->description, $row->price / 100);
24     }
25 ?>
26 Zwischensumme <input type="text" id="subtotal" value="" size="5" style="background: #ececec;text-align:right;" readonly> &euro;
27 <p><input type="submit" class="button" value="Bezahlen" onclick="return send_request()"> <input type="reset" class="button" value="Reset"><p>
28 </form>
29
30 </page>
31 <protect>
32 <script type="text/javascript">
33 function cb_change()
34 {
35     var subtotal = $('input#subtotal').val();
36     if (typeof subtotal == 'string' && !subtotal.length) subtotal = 0;
37     else subtotal = parseFloat(subtotal) * 100;
38
39     if ($(this).prop('checked'))
40         subtotal += parseFloat($(this).attr('price'));
41     else
42         subtotal -= parseFloat($(this).attr('price'));
43
44     if (subtotal == 0)
45         $('input#subtotal').val('');
46     else
47         $('input#subtotal').val(subtotal / 100);
48 }
49
50 function send_request()
51 {
52     $.invoke('Sales/Subtotal', $('form#open_items').serialize(), function(data){
53         show_message('Mail sent');
54         $('form#open_items')[0].reset();
55     });
56
57     return false;
58 }
59
60 $(function(){
61         $('form#open_items input[type="checkbox"]').click(cb_change);
62         setTimeout(function(){$('form#open_items')[0].reset();}, 500);
63 });
64 </script>
65 </protect>