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