Formatting
[memberdb.git] / include / finances.php
index 12fec88..77496ef 100644 (file)
@@ -1,27 +1,24 @@
 <?php
 
-
 use MemberDB\Config\Config;
 
 function finance_get_total_paid_fees()
 {
-    $paid = db_select_single('SELECT SUM(value) AS paid_fees FROM `earnings` WHERE type IN(\'old_fee\', \'fee\') AND `status`=\'paid\'');
-    $refunded = db_select_single('SELECT SUM(value) AS refunded_fees FROM `expenses` WHERE type IN(\'member_fee\') AND `status`=\'paid\'');
+    $paid = db_select_single("SELECT SUM(value) AS paid_fees FROM `earnings` WHERE type IN('old_fee', 'fee') AND `status`='paid'");
+    $refunded = db_select_single("SELECT SUM(value) AS refunded_fees FROM `expenses` WHERE type IN('member_fee') AND `status`='paid'");
 
     return bcsub($paid['paid_fees'], $refunded['refunded_fees']);
 }
 
-
 function finance_get_paid_fees_for_member($member_id, $old_fees = false)
 {
     // $old_fees: Beiträge die nicht durch Lastschrift eingezogen werden.
     //            Falls zu viel bezahlt, müssen diese auf die per Lastschrift
     //            eingezogenen Beiträge angerechnet werden.
-    $row = db_select_single(sprintf(
-        'SELECT SUM(value) AS paid_fees FROM `earnings` WHERE member_id=\'%d\' AND type=\'%s\' AND `status`=\'paid\'',
-        db_escape($member_id),
-        $old_fees ? 'old_fee' : 'fee'
-    ));
+    $row = db_select_single(
+        'SELECT SUM(value) AS paid_fees FROM `earnings` WHERE member_id=? AND type=? AND `status`=\'paid\'',
+        [$member_id, $old_fees ? 'old_fee' : 'fee']
+    );
 
     $paid_fees = $row['paid_fees'];
 
@@ -30,7 +27,7 @@ function finance_get_paid_fees_for_member($member_id, $old_fees = false)
     }
 
     /** @var DateTime $direct_debit */
-    $direct_debit = Config::getInstance()->get('direct_debit')['date']
+    $direct_debit = Config::getInstance()->get('direct_debit')['date'];
     $invoiced_fees = fees_sum_for_member($member_id, $direct_debit->getTimestamp() - 86400);
     $paid_invoiced_fees = finance_get_paid_fees_for_member($member_id, true);
     if (bccomp($paid_invoiced_fees, $invoiced_fees) == 1) {
@@ -38,26 +35,26 @@ function finance_get_paid_fees_for_member($member_id, $old_fees = false)
     }
 
 
-    $refunded = db_select_single(sprintf(
-        'SELECT SUM(value) AS refunded_fees FROM `expenses` WHERE member_id=\'%d\' AND type IN(\'member_fee\') AND `status`=\'paid\'',
-        db_escape($member_id)
-    ));
+    $refunded = db_select_single(
+        "SELECT SUM(value) AS refunded_fees FROM `expenses` WHERE member_id=? AND type IN('member_fee') AND `status`='paid'",
+        [$member_id]
+    );
     return bcsub($paid_fees, $refunded['refunded_fees']);
 }
 
 function finance_list_paid_fees_for_member($member_id)
 {
-    return db_select_multi(sprintf('
-               (SELECT id, date, type, status, account, value, member_id, description, created_at, modified_at FROM `earnings` WHERE member_id=\'%1$d\' AND type IN(\'old_fee\', \'fee\'))
+    return db_select_multi("
+               (SELECT id, date, type, status, account, value, member_id, description, created_at, modified_at FROM `earnings` WHERE member_id=? AND type IN('old_fee', 'fee'))
                UNION
-               (SELECT id, date, type, status, account, value*-1, member_id, description, created_at, modified_at FROM `expenses` WHERE member_id=\'%1$d\' AND type IN(\'member_fee\'))
-               ORDER BY `date` DESC',
-        db_escape($member_id)
-    ));
+               (SELECT id, date, type, status, account, value*-1, member_id, description, created_at, modified_at FROM `expenses` WHERE member_id=? AND type IN('member_fee'))
+               ORDER BY `date` DESC",
+        [$member_id, $member_id]
+    );
 }
 
 function action_finances()
-{/*{{{*/
+{
     ?>
     <h2>Finanzen</h2>
     <?php
@@ -67,4 +64,4 @@ function action_finances()
     render_open_payments();
     render_finished_payments();
     echo '<a href="' . link_to('export') . '">.xls runterladen</a>';
-}/*}}}*/
+}