57ac176f5c744f3807a090648eb6a50328904112
[memberdb.git] / include / finances.php
1 <?php
2
3
4 function finance_get_total_paid_fees() {
5     $row = db_select_single(sprintf('SELECT SUM(value) as paid_fees FROM %1$s WHERE type IN(\'old_fee\', \'fee\') AND status=\'paid\'',
6         DB_TABLE_EARNINGS
7     ));
8
9     $paid_fees = $row['paid_fees'];
10
11     return $paid_fees;
12 }
13
14
15 function finance_get_paid_fees_for_member($member_id, $old_fees = false) {
16     // $old_fees: Beiträge die nicht durch Lastschrift eingezogen werden.
17     //            Falls zu viel bezahlt, müssen diese auf die per Lastschrift
18     //            eingezogenen Beiträge angerechnet werden.
19     $row = db_select_single(sprintf('SELECT SUM(value) as paid_fees FROM %1$s WHERE member_id=\'%2$d\' AND type=\'%3$s\' AND status=\'paid\'',
20         DB_TABLE_EARNINGS,
21         db_escape($member_id),
22         $old_fees ? 'old_fee' : 'fee'
23     ));
24
25     $paid_fees = $row['paid_fees'];
26
27     if ($old_fees) return $paid_fees;
28
29     $invoiced_fees      = fees_sum_for_member($member_id, DIRECTDEBIT_DATE - 86400);
30     $paid_invoiced_fees = finance_get_paid_fees_for_member($member_id, true);
31     if (bccomp($paid_invoiced_fees, $invoiced_fees) == 1) $paid_fees = bcadd($paid_fees, bcsub($paid_invoiced_fees, $invoiced_fees));
32
33     return $paid_fees;
34 }
35
36 function finance_list_paid_fees_for_member($member_id) {
37     return db_select_multi(sprintf('SELECT * FROM %1$s WHERE member_id=\'%2$d\' ORDER BY `date` ASC',
38         DB_TABLE_EARNINGS,
39         db_escape($member_id)
40     ));
41 }
42
43 function action_finances() {/*{{{*/
44 ?>
45     <h2>Finanzen</h2>
46 <?php
47     action_create_expense();
48     action_create_earning();
49     echo '<br style="clear: left;"/>';
50     render_open_payments();
51     render_finished_payments();
52 }/*}}}*/
53