Formatting
[memberdb.git] / include / fees.php
index 7b89f7c..976526a 100644 (file)
@@ -1,11 +1,10 @@
 <?php
 
+use MemberDB\Config\Config;
 
-/* HELPER functions FOR FEES {{{ */
+// HELPER functions FOR FEES
 
 // build an empty structure for holding monthly information
-use MemberDB\Config\Config;
-
 function _fees_build_month_array($start_date, $end_date, $preset = array())
 {
     $start_info = getdate($start_date);
@@ -114,7 +113,6 @@ function _fees_apply_event_information(&$info, $events)
 
 function fees_get_list_for_member($member_id, $end_date)
 {
-
     static $cache = array();
     $config = Config::getInstance();
 
@@ -137,7 +135,7 @@ function fees_get_list_for_member($member_id, $end_date)
 
     $ret = _fees_build_month_array($config->get('founding_date'), $end_date);
     if (empty($ret)) {
-        return;
+        return null;
     }
 
     _fees_apply_event_information($ret, db_get_events_for_member($member_id));
@@ -224,7 +222,6 @@ function fees_get_list_for_month($year, $month)
 
 function fee_next_directdebit_for_member($member_id, $max_date = null)
 {
-
     $config = Config::getInstance();
     $member = db_get_member_with_id($member_id);
     if (!$member['directdebit']) {
@@ -304,15 +301,11 @@ function fee_next_directdebit_for_member($member_id, $max_date = null)
         }
     }
 
-
+    return null;
 }
 
-/* }}} */
-
-
 function action_fees()
-{/*{{{*/
-
+{
     if (isset($_REQUEST['member_id'])) {
         render_fees_for_member($_REQUEST['member_id']);
         return;
@@ -326,11 +319,10 @@ function action_fees()
     render_accrued_fees_by_month();
     render_next_direct_debit();
     render_future_fees();
-
-}/*}}}*/
+}
 
 function render_fees_by_member()
-{/*{{{*/
+{
     $members = db_get_members();
     $config = Config::getInstance();
     ?>
@@ -360,20 +352,21 @@ function render_fees_by_member()
             $open_fees = bcadd(bcsub($sum_old_fees, $sum_old_paid), max(bcsub($sum_new_fees, $sum_new_paid), 0));
             ?>
             <tr>
-                <td><a href="<?= html_escape(link_to('fees',
-                        array('member_id' => $member['id']))) ?>"><?= html_escape($member['number']) ?></a></td>
-                <td><?= html_escape($member['nickname']) ?></td>
-                <td style="text-align: right;"><?= format_money($sum_fees) ?></td>
-                <td style="text-align: right;"><?= isset($current_fee) ? format_money($current_fee) : '-' ?></td>
-                <td style="text-align: right;"><?= $open_fees > 0 ? format_money($open_fees) : '-' ?></td>
+                <td><a href="<?php echo html_escape(link_to('fees',
+                        array('member_id' => $member['id']))); ?>"><?php echo html_escape($member['number']); ?></a>
+                </td>
+                <td><?php echo html_escape($member['nickname']); ?></td>
+                <td style="text-align: right;"><?php echo format_money($sum_fees); ?></td>
+                <td style="text-align: right;"><?php echo isset($current_fee) ? format_money($current_fee) : '-'; ?></td>
+                <td style="text-align: right;"><?php echo $open_fees > 0 ? format_money($open_fees) : '-'; ?></td>
             </tr>
         <?php endforeach ?>
     </table>
     <?php
-}/*}}}*/
+}
 
 function render_future_fees()
-{/*{{{*/
+{
     $total_paid = finance_get_total_paid_fees();
     $this_year = date('Y');
     $this_month = date('m');
@@ -400,19 +393,19 @@ function render_future_fees()
             <?php $months = array_reverse($months, true); ?>
             <?php foreach ($months as $month => $data) : ?>
                 <tr<?php if ($year == $this_year && $month == $this_month) : ?> class="current"<?php endif ?>>
-                    <td><a href="<?= html_escape(link_to('fees',
-                            array('year' => $year, 'month' => $month))) ?>"><?= html_escape(format_month($year,
-                                $month)) ?></a></td>
-                    <td style="text-align: right;"><?= html_escape(format_money($data['fee'])) ?></td>
-                    <td style="text-align: right;"><?= html_escape(format_money($data['total'])) ?></td>
+                    <td><a href="<?php echo html_escape(link_to('fees',
+                            array('year' => $year, 'month' => $month))); ?>"><?php echo html_escape(format_month($year,
+                                $month)); ?></a></td>
+                    <td style="text-align: right;"><?php echo html_escape(format_money($data['fee'])); ?></td>
+                    <td style="text-align: right;"><?php echo html_escape(format_money($data['total'])); ?></td>
                     <td style="text-align: right;">
                         <?php if ($year == $this_year && $month == $this_month) : ?>
-                            <?= html_escape(format_money($total_paid)) ?>
+                            <?php echo html_escape(format_money($total_paid)); ?>
                         <?php endif ?>
                     </td>
                     <td style="text-align: right;">
                         <?php if ($year > $this_year || ($year >= $this_year && $month >= $this_month)) : ?>
-                            <?= html_escape(format_money(bcsub($data['total'], $total_paid))) ?>
+                            <?php echo html_escape(format_money(bcsub($data['total'], $total_paid))); ?>
                         <?php endif ?>
                     </td>
                 </tr>
@@ -420,10 +413,10 @@ function render_future_fees()
         <?php endforeach ?>
     </table>
     <?php
-}/*}}}*/
+}
 
 function render_accrued_fees_by_month()
-{/*{{{*/
+{
     $fees = fees_sum_by_month(time());
     $fees = array_reverse($fees, true);
     ?>
@@ -437,22 +430,22 @@ function render_accrued_fees_by_month()
             <?php $months = array_reverse($months, true); ?>
             <?php foreach ($months as $month => $fee) : ?>
                 <tr>
-                    <td><a href="<?= html_escape(link_to('fees',
-                            array('year' => $year, 'month' => $month))) ?>"><?= html_escape(format_month($year,
+                    <td><a href="<?php echo html_escape(link_to('fees',
+                            array('year' => $year, 'month' => $month))); ?>"><?php echo html_escape(format_month($year,
                                 $month)) ?></a></td>
-                    <td style="text-align: right;"><?= html_escape(format_money($fee)) ?></td>
+                    <td style="text-align: right;"><?php echo html_escape(format_money($fee)) ?></td>
                 </tr>
             <?php endforeach ?>
         <?php endforeach ?>
     </table>
     <?php
-}/*}}}*/
+}
 
 function render_accrued_fees_for_month($year, $month)
-{/*{{{*/
+{
     $fees = fees_get_list_for_month($year, $month);
     ?>
-    <h2>Angefallene Mitgliedsbeitr&auml;ge f&uuml;r <?= format_month($year, $month) ?></h2>
+    <h2>Angefallene Mitgliedsbeitr&auml;ge f&uuml;r <?php echo format_month($year, $month) ?></h2>
     <table>
         <tr>
             <th>Mitgliedsnummer</th>
@@ -461,19 +454,19 @@ function render_accrued_fees_for_month($year, $month)
         </tr>
         <?php foreach ($fees as $info) : ?>
             <tr>
-                <td><a href="<?= html_escape(link_to('fees',
-                        array('member_id' => $info['id']))) ?>"><?= html_escape($info['number']) ?></a></td>
-                <td><?= html_escape($info['nickname']) ?></td>
-                <td style="text-align: right;"><?= html_escape($info['is_member'] ? format_money($info['fee']) : '-') ?></td>
+                <td><a href="<?php echo html_escape(link_to('fees',
+                        array('member_id' => $info['id']))) ?>"><?php echo html_escape($info['number']) ?></a></td>
+                <td><?php echo html_escape($info['nickname']) ?></td>
+                <td style="text-align: right;"><?php echo html_escape($info['is_member'] ? format_money($info['fee']) : '-') ?></td>
             </tr>
         <?php endforeach ?>
     </table>
-    <p><a href="<?= html_escape(link_to('fees')) ?>">Alle angefallenen Mitgliedsbeitr&auml;ge</a></p>
+    <p><a href="<?php echo html_escape(link_to('fees')) ?>">Alle angefallenen Mitgliedsbeitr&auml;ge</a></p>
     <?php
-}/*}}}*/
+}
 
 function render_next_direct_debit()
-{/*{{{*/
+{
     $members = db_get_members();
     ?>
     <h2>Nächste Abbuchungen nach Mitglied</h2>
@@ -490,15 +483,15 @@ function render_next_direct_debit()
         <?php foreach ($members as $member) : ?>
             <?php $next_debit = fee_next_directdebit_for_member($member['id']); ?>
             <tr>
-                <td><a href="<?= html_escape(link_to('fees',
-                        array('member_id' => $member['id']))) ?>"><?= html_escape($member['number']) ?></a></td>
-                <td><?= html_escape($member['nickname']) ?></td>
+                <td><a href="<?php echo html_escape(link_to('fees',
+                        array('member_id' => $member['id']))) ?>"><?php echo html_escape($member['number']) ?></a></td>
+                <td><?php echo html_escape($member['nickname']) ?></td>
                 <?php if (empty($next_debit)) : ?>
                     <td>-</td>
                     <td style="text-align: right;">-</td>
                 <?php else : ?>
-                    <td><?= html_escape($next_debit['info']) ?></td>
-                    <td style="text-align: right;"><?= format_money($next_debit['value']) ?></td>
+                    <td><?php echo html_escape($next_debit['info']) ?></td>
+                    <td style="text-align: right;"><?php echo format_money($next_debit['value']) ?></td>
                 <?php endif ?>
             </tr>
         <?php endforeach ?>
@@ -507,7 +500,7 @@ function render_next_direct_debit()
 }
 
 function render_fees_for_member($member_id)
-{/*{{{*/
+{
     global $MEMBER_TYPES, $EARNING_TYPES, $EXPENSE_TYPES;
     $config = Config::getInstance();
     /** @var DateTime $direct_debit */
@@ -521,7 +514,7 @@ function render_fees_for_member($member_id)
     $membership_info = fees_get_list_for_member($member_id, time());
     $membership_info = array_reverse($membership_info, true);
 
-    $paid_fees = finance_list_paid_fees_for_member($member_id, time(), true);
+    $paid_fees = finance_list_paid_fees_for_member($member_id);
 
     $sum_new_paid = finance_get_paid_fees_for_member($member_id);
     $sum_old_paid = finance_get_paid_fees_for_member($member_id, true);
@@ -550,15 +543,17 @@ function render_fees_for_member($member_id)
         $state = sprintf('Es sind noch %1$s Mitgliedsbeitrag offen.',
             format_money(bcsub($sum_new_fees, $sum_new_paid)));
     } elseif ($old_open) {
-        $state = sprintf('Für die Zeit vor dem %1$s sind noch %2$s Mitgliedsbeitrag offen.',
-            format_date($direct_debit->getTimestamp()), format_money(bcsub($sum_old_fees, $sum_old_paid)));
+        $state = sprintf(
+            'Für die Zeit vor dem %1$s sind noch %2$s Mitgliedsbeitrag offen.',
+            format_date($direct_debit->getTimestamp()), format_money(bcsub($sum_old_fees, $sum_old_paid))
+        );
     }
 
     $next_debit = fee_next_directdebit_for_member($member_id);
 
     ?>
     <h2>Mitgliedsbeitr&auml;ge
-        von <?= html_escape(!empty($member['nickname']) ? $member['nickname'] : sprintf('Mitglied Nr. %d',
+        von <?php echo html_escape(!empty($member['nickname']) ? $member['nickname'] : sprintf('Mitglied Nr. %d',
             $member['number'])) ?></h2>
     <h3>Mitgliedsdetails</h3>
     <table>
@@ -568,14 +563,14 @@ function render_fees_for_member($member_id)
             <th>Status</th>
         </tr>
         <tr>
-            <td><a href="<?= html_escape(link_to('view_member',
-                    array('id' => $member['id']))) ?>"><?= html_escape($member['number']) ?></a></td>
-            <td><?= html_escape($member['nickname']) ?></strong></p></td>
+            <td><a href="<?php echo html_escape(link_to('view_member',
+                    array('id' => $member['id']))) ?>"><?php echo html_escape($member['number']) ?></a></td>
+            <td><?php echo html_escape($member['nickname']) ?></strong></p></td>
             <td>
                 <?php if (empty($state)) : ?>
                     Kein Beitragsrückstand
                 <?php else : ?>
-                    <?= wordwrap(html_escape($state), 70, '<br/>') ?>
+                    <?php echo wordwrap(html_escape($state), 70, '<br/>') ?>
                 <?php endif ?>
             </td>
         </tr>
@@ -592,14 +587,14 @@ function render_fees_for_member($member_id)
                 <?php $months = array_reverse($months, true); ?>
                 <?php foreach ($months as $month => $info) : ?>
                     <tr>
-                        <td><?= html_escape(format_month($year, $month)) ?></td>
-                        <td><?= html_escape($info['is_member'] ? $MEMBER_TYPES[$info['member_type']] : 'Kein Mitglied') ?></td>
-                        <td style="text-align: right;"><?= html_escape($info['is_member'] ? format_money($info['fee']) : '-') ?></td>
+                        <td><?php echo html_escape(format_month($year, $month)) ?></td>
+                        <td><?php echo html_escape($info['is_member'] ? $MEMBER_TYPES[$info['member_type']] : 'Kein Mitglied') ?></td>
+                        <td style="text-align: right;"><?php echo html_escape($info['is_member'] ? format_money($info['fee']) : '-') ?></td>
                     </tr>
                 <?php endforeach ?>
             <?php endforeach ?>
         </table>
-        <p><a href="<?= html_escape(link_to('fees')) ?>">Alle angefallenen Mitgliedsbeitr&auml;ge</a></p>
+        <p><a href="<?php echo html_escape(link_to('fees')) ?>">Alle angefallenen Mitgliedsbeitr&auml;ge</a></p>
     </div>
     <div style="float: left; margin-left: 1em;">
         <h3>Nächste Abbuchung</h3>
@@ -612,8 +607,8 @@ function render_fees_for_member($member_id)
                 <td>-</td>
                 <td style="text-align: right;">-</td>
             <?php else : ?>
-                <td><?= html_escape($next_debit['info']) ?></td>
-                <td style="text-align: right;"><?= format_money($next_debit['value']) ?></td>
+                <td><?php echo html_escape($next_debit['info']) ?></td>
+                <td style="text-align: right;"><?php echo format_money($next_debit['value']) ?></td>
             <?php endif ?>
         </table>
         <h3>Bezahlte Mitgliedsbeitr&auml;ge</h3>
@@ -625,13 +620,13 @@ function render_fees_for_member($member_id)
             </tr>
             <?php foreach ($paid_fees as $payment) : ?>
                 <tr>
-                    <td><?= html_escape(format_date(db_date2unixtime($payment['date']))) ?></td>
-                    <td><?= ($payment['value'] < 0) ? $EXPENSE_TYPES[$payment['type']] : $EARNING_TYPES[$payment['type']] ?></td>
-                    <td style="text-align: right;"><?= format_money($payment['value']) ?></td>
+                    <td><?php echo html_escape(format_date(db_date2unixtime($payment['date']))) ?></td>
+                    <td><?php echo ($payment['value'] < 0) ? $EXPENSE_TYPES[$payment['type']] : $EARNING_TYPES[$payment['type']] ?></td>
+                    <td style="text-align: right;"><?php echo format_money($payment['value']) ?></td>
                 </tr>
             <?php endforeach ?>
         </table>
     </div>
     <br style="clear: left;"/>
     <?php
-}/*}}}*/
+}