Excel-Export
[memberdb.git] / include / fees.php
index 7551a91..c168a66 100644 (file)
@@ -77,7 +77,7 @@ function fees_get_list_for_member($member_id, $end_date) {
 
     static $cache = array();
 
-    $end_date = db_date2unixtime(db_unixtime2date($end_date)); // remove hours, minutes, seconds
+    $end_date = mktime(0, 0, 0, date('m', $end_date) + 1, 0, date('Y', $end_date)); // last day of given month
 
     if (isset($cache[$member_id][$end_date])) return $cache[$member_id][$end_date];
     if (isset($cache[$member_id])) {
@@ -122,6 +122,13 @@ function fees_for_member_at_date($member_id, $end_date) {
     return NULL;
 }
 
+function fees_info_for_member($member_id, $end_date) {
+    $membership_info = fees_get_list_for_member($member_id, $end_date);
+    
+    $this_year = array_pop($membership_info);
+    return array_pop($this_year);
+}
+
 function fees_sum_by_month($end_date) {
     $members = db_get_members();
     $fees = array();
@@ -231,6 +238,7 @@ function action_fees() {/*{{{*/
     render_fees_by_member();
     render_accrued_fees_by_month();
     render_next_direct_debit();
+    render_future_fees();
 
 }/*}}}*/
 
@@ -270,6 +278,53 @@ function render_fees_by_member() {/*{{{*/
 <?php
 }/*}}}*/
 
+function render_future_fees() {/*{{{*/
+    $total_paid = finance_get_total_paid_fees();
+    $this_year = date('Y');
+    $this_month = date('m');
+    $fees = fees_sum_by_month(mktime(0, 0, 0, date('m') + 6,   date('d'),   date('Y')+1));
+    $total = 0;
+    foreach ($fees as $year => $months) {
+        foreach ($months as $month => $fee) {
+            $total = bcadd($total, $fee);
+            $fees[$year][$month] = array('total' => $total, 'fee' => $fee);
+        }
+    }
+    $fees = array_reverse($fees, true);
+?>
+<h2>Beitragsprognose nach Monat</h2>
+<table>
+    <tr>
+        <th>Monat</th>
+        <th style="text-align: right;">Mitgliedsbeitr&auml;ge</th>
+        <th style="text-align: right;">kummuliert</th>
+        <th style="text-align: right;">eingenommen</th>
+        <th style="text-align: right;"><strong>offen</strong></th>
+    </tr>
+<?php foreach ($fees as $year => $months) : ?>
+    <?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 style="text-align: right;">
+        <?php if ($year == $this_year && $month == $this_month) : ?>
+            <?=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 endif ?>
+        </td>
+    </tr>
+    <?php endforeach ?>
+<?php endforeach ?>
+</table>
+<?php
+}/*}}}*/
+
 function render_accrued_fees_by_month() {/*{{{*/
     $fees = fees_sum_by_month(time());
     $fees = array_reverse($fees, true);
@@ -346,7 +401,7 @@ function render_next_direct_debit() {/*{{{*/
 }
 
 function render_fees_for_member($member_id) {/*{{{*/
-    global $MEMBER_TYPES, $EARNING_TYPES;
+    global $MEMBER_TYPES, $EARNING_TYPES, $EXPENSE_TYPES;
 
     $member      = db_get_member_with_id($member_id);
     if (!isset($member)) redirect(link_to('fees'));
@@ -354,7 +409,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 = array_reverse(finance_list_paid_fees_for_member($member_id, time(), true));
+    $paid_fees = finance_list_paid_fees_for_member($member_id, time(), true);
 
     $sum_new_paid = finance_get_paid_fees_for_member($member_id);
     $sum_old_paid = finance_get_paid_fees_for_member($member_id, true);
@@ -452,7 +507,7 @@ function render_fees_for_member($member_id) {/*{{{*/
 <?php foreach ($paid_fees as $payment) : ?>
     <tr>
         <td><?=html_escape(format_date(db_date2unixtime($payment['date'])))?></td>
-        <td><?=$EARNING_TYPES[$payment['type']]?></td>
+        <td><?=($payment['value'] < 0) ? $EXPENSE_TYPES[$payment['type']]: $EARNING_TYPES[$payment['type']]?></td>
         <td style="text-align: right;"><?=format_money($payment['value'])?></td>
     </tr>
 <?php endforeach ?>