Formatting
[memberdb.git] / include / payments.php
index 7fb2425..ee7b683 100644 (file)
@@ -1,13 +1,12 @@
 <?php
 
 // NOTE: combination of earnings and expenses
-
 $ACCOUNT_TYPES = array(
     'bank' => 'Konto',
     'cash' => 'Kasse'
 );
 
-/* DB functions {{{ */
+// DB functions
 function db_get_payments($offset, $count, $where)
 {
     $limit = '';
@@ -16,22 +15,22 @@ function db_get_payments($offset, $count, $where)
     } elseif (isset($offset)) {
         $limit = sprintf(' LIMIT %d', (int)$count);
     }
-    $sql = '
+    $sql = "
         SELECT t.*, members.nickname AS nickname
         FROM (
-            (SELECT \'earning\' AS ptype, `earnings`.* FROM `earnings` `earnings`)
+            (SELECT 'earning' AS ptype, `earnings`.* FROM `earnings` `earnings`)
             UNION
-            (SELECT \'expense\', expenses.* FROM `expenses` `earnings`)
+            (SELECT 'expense', expenses.* FROM `expenses` `earnings`)
         ) AS t
         LEFT JOIN `members` ON t.member_id=members.id
         ORDER BY `date` DESC, t.id DESC
-    ' . $limit;
+    " . $limit;
     return db_select_multi(sprintf($sql, $where));
 }
 
 function db_get_finished_payments($offset, $count)
 {
-    $where = ' WHERE status=\'paid\'';
+    $where = " WHERE status='paid'";
     $payments = db_get_payments($offset, $count, $where);
 
     $bank = 0;
@@ -40,13 +39,13 @@ function db_get_finished_payments($offset, $count)
     if ($count != 0) { // XXX TODO hä? - An dieser Stelle gäbe es sinnigere Bedinungen
         $limit = sprintf(' LIMIT %d,18446744073709551615',
             (int)($count + $offset)); // SELECT mit Offset aber ohne Limit
-        $sql = 'SELECT SUM(IF(`account`=\'bank\', `value`, 0)) AS `bank`, SUM(IF(`account`=\'cash\', `value`, 0)) AS `cash`, SUM(`value`) AS `total` 
+        $sql = "SELECT SUM(IF(`account`='bank', `value`, 0)) AS `bank`, SUM(IF(`account`='cash', `value`, 0)) AS `cash`, SUM(`value`) AS `total` 
                 FROM (
                     SELECT `value`, `account` 
-                    FROM (( SELECT `value`,                 `id`, `date`, `account` FROM `earnings` %1$s) 
-                    UNION ( SELECT `value` * -1 AS `value`, `id`, `date`, `account` FROM `expenses` %1$s)
+                    FROM (( SELECT `value`,                 `id`, `date`, `account` FROM `earnings` %1\$s) 
+                    UNION ( SELECT `value` * -1 AS `value`, `id`, `date`, `account` FROM `expenses` %1\$s)
                     ) AS t
-                    ORDER BY `date` DESC, t.id DESC' . $limit . '
+                    ORDER BY `date` DESC, t.id DESC" . $limit . '
                 ) AS u';
         $row = db_select_single(sprintf($sql, $where));
         $bank = $row['bank'];
@@ -78,7 +77,7 @@ function db_get_finished_payments($offset, $count)
 
 function db_count_finished_payments()
 {
-    $where = ' WHERE status=\'paid\'';
+    $where = " WHERE status='paid'";
     $sql = 'SELECT count(*) AS `count` FROM ((SELECT * FROM `earnings` %1$s) UNION (SELECT * FROM `expenses` %1$s)) AS t';
     $row = db_select_single(sprintf($sql, $where));
     return $row['count'];
@@ -86,14 +85,12 @@ function db_count_finished_payments()
 
 function db_get_open_payments($offset, $count)
 {
-    return db_get_payments($offset, $count, ' WHERE status=\'open\'');
+    return db_get_payments($offset, $count, " WHERE status='open'");
 }
 
-/* }}} */
-
 function render_finished_payments($count = 100)
-{/*{{{*/
-    global $EXPENSE_TYPES, $EARNING_TYPES, $ACCOUNT_TYPES;
+{
+    global $EXPENSE_TYPES, $EARNING_TYPES;
     $page = 1;
     if (!empty($_REQUEST['page'])) {
         $page = max(1, (int)$_REQUEST['page']);
@@ -116,19 +113,19 @@ function render_finished_payments($count = 100)
             <th>Gesamt</th>
         </tr>
         <?php foreach ($payments as $payment) : ?>
-            <tr class="<?= $payment['ptype'] ?>">
-                <td style="text-align: right;"><a href="<?= html_escape(link_to('change_' . $payment['ptype'],
-                        array('id' => $payment['id']))) ?>"><?= html_escape($payment['id']) ?></a></td>
-                <td><?= html_escape(format_date(db_date2unixtime($payment['date']))) ?></td>
-                <td><?= html_escape($payment['ptype'] == 'earning' ? $EARNING_TYPES[$payment['type']] : $EXPENSE_TYPES[$payment['type']]) ?></td>
-                <td><?php if ($payment['member_id'] != 0) : ?><a href="<?= html_escape(link_to('view_member',
-                        array('id' => $payment['member_id']))) ?>"><?= html_escape($payment['nickname']) ?><?php endif ?></a>
+            <tr class="<?php echo $payment['ptype'] ?>">
+                <td style="text-align: right;"><a href="<?php echo html_escape(link_to('change_' . $payment['ptype'],
+                        array('id' => $payment['id']))) ?>"><?php echo html_escape($payment['id']) ?></a></td>
+                <td><?php echo html_escape(format_date(db_date2unixtime($payment['date']))) ?></td>
+                <td><?php echo html_escape($payment['ptype'] == 'earning' ? $EARNING_TYPES[$payment['type']] : $EXPENSE_TYPES[$payment['type']]) ?></td>
+                <td><?php if ($payment['member_id'] != 0) : ?><a href="<?php echo html_escape(link_to('view_member',
+                        array('id' => $payment['member_id']))) ?>"><?php echo html_escape($payment['nickname']) ?><?php endif ?></a>
                 </td>
-                <td style="text-align: right;"><?= html_escape(format_money(($payment['ptype'] == 'earning' ? 1 : -1) * $payment['value'])) ?></td>
-                <td><?= html_escape($payment['description']) ?></td>
-                <td style="text-align: right;<?php if ($payment['account'] == 'bank') : ?> text-decoration:underline;<?php endif ?>"><?= html_escape(format_money($payment['bank'])) ?></td>
-                <td style="text-align: right;<?php if ($payment['account'] == 'cash') : ?> text-decoration:underline;<?php endif ?>"><?= html_escape(format_money($payment['cash'])) ?></td>
-                <td style="text-align: right;"><?= html_escape(format_money($payment['total'])) ?></td>
+                <td style="text-align: right;"><?php echo html_escape(format_money(($payment['ptype'] == 'earning' ? 1 : -1) * $payment['value'])) ?></td>
+                <td><?php echo html_escape($payment['description']) ?></td>
+                <td style="text-align: right;<?php if ($payment['account'] == 'bank') : ?> text-decoration:underline;<?php endif ?>"><?php echo html_escape(format_money($payment['bank'])) ?></td>
+                <td style="text-align: right;<?php if ($payment['account'] == 'cash') : ?> text-decoration:underline;<?php endif ?>"><?php echo html_escape(format_money($payment['cash'])) ?></td>
+                <td style="text-align: right;"><?php echo html_escape(format_money($payment['total'])) ?></td>
             </tr>
         <?php endforeach ?>
     </table>
@@ -137,13 +134,11 @@ function render_finished_payments($count = 100)
     <p>Bisher gibt's noch keine abgeschlossenen Zahlungen.</p>
 <?php endif ?>
     <?php
-
-}/*}}}*/
+}
 
 function render_open_payments($offset = 0, $count = 25)
-{/*{{{*/
+{
     global $EXPENSE_TYPES, $EARNING_TYPES, $ACCOUNT_TYPES;
-    global $EXPENSE_TYPES, $EARNING_TYPES;
     $payments = db_get_open_payments($offset, $count);
     ?>
     <h3>Offene Zahlungen</h3>
@@ -159,17 +154,17 @@ function render_open_payments($offset = 0, $count = 25)
             <th>Beschreibung</th>
         </tr>
         <?php foreach ($payments as $payment) : ?>
-            <tr class="<?= $payment['ptype'] ?>">
-                <td style="text-align: right;"><a href="<?= html_escape(link_to('change_' . $payment['ptype'],
-                        array('id' => $payment['id']))) ?>"><?= html_escape($payment['id']) ?></a></td>
-                <td><?= html_escape(format_date(db_date2unixtime($payment['date']))) ?></td>
-                <td><?= html_escape($payment['ptype'] == 'earning' ? $EARNING_TYPES[$payment['type']] : $EXPENSE_TYPES[$payment['type']]) ?></td>
-                <td><?php if ($payment['member_id'] != 0) : ?><a href="<?= html_escape(link_to('view_member',
-                        array('id' => $payment['member_id']))) ?>"><?= html_escape($payment['nickname']) ?><?php endif ?></a>
+            <tr class="<?php echo $payment['ptype'] ?>">
+                <td style="text-align: right;"><a href="<?php echo html_escape(link_to('change_' . $payment['ptype'],
+                        array('id' => $payment['id']))) ?>"><?php echo html_escape($payment['id']) ?></a></td>
+                <td><?php echo html_escape(format_date(db_date2unixtime($payment['date']))) ?></td>
+                <td><?php echo html_escape($payment['ptype'] == 'earning' ? $EARNING_TYPES[$payment['type']] : $EXPENSE_TYPES[$payment['type']]) ?></td>
+                <td><?php if ($payment['member_id'] != 0) : ?><a href="<?php echo html_escape(link_to('view_member',
+                        array('id' => $payment['member_id']))) ?>"><?php echo html_escape($payment['nickname']) ?><?php endif ?></a>
                 </td>
-                <td><?= html_escape($ACCOUNT_TYPES[$payment['account']]) ?></td>
-                <td style="text-align: right;"><?= html_escape(format_money(($payment['ptype'] == 'earning' ? 1 : -1) * $payment['value'])) ?></td>
-                <td><?= html_escape($payment['description']) ?></td>
+                <td><?php echo html_escape($ACCOUNT_TYPES[$payment['account']]) ?></td>
+                <td style="text-align: right;"><?php echo html_escape(format_money(($payment['ptype'] == 'earning' ? 1 : -1) * $payment['value'])) ?></td>
+                <td><?php echo html_escape($payment['description']) ?></td>
             </tr>
         <?php endforeach ?>
     </table>
@@ -177,5 +172,4 @@ function render_open_payments($offset = 0, $count = 25)
     <p>Bisher gibt's noch keine abgeschlossenen Zahlungen.</p>
 <?php endif ?>
     <?php
-
-}/*}}}*/
+}