/**
  * Build records that will be used in rendering the reports
  * @param int $prop_id ID used to identify the property
  * @param string $start Date string specifying start of the period
  * @param sring $end Date string specifyinng end of the period
  * @return array $record_objects An array of record objects
  */
 public static function buildRecords($prop_id, $start, $end)
 {
     $room_count = Room::getNumRoomsForProperty($prop_id);
     $rooms = Room::findByPropertyId($prop_id);
     $record_objects = array();
     $aobj = new Arrears();
     for ($i = 0; $i < $room_count; $i++) {
         $record = new self();
         $rm = $rooms[$i];
         $record->room_label = $rm->getRoomLabel();
         if (!is_null($rm->getTenantId())) {
             $tenant = Tenant::findByRoomId($rm->id);
             $rent_obj = Rent::findByPeriodForTenant($tenant->id, $start, $end);
             $rent_paid = !is_null($rent_obj) ? $rent_obj->getPaymentAmount() : NULL;
             $receipt = !is_null($rent_obj) ? $rent_obj->getReceiptNo() : NULL;
             $remarks = !is_null($rent_obj) ? $rent_obj->getRemarks() : NULL;
             $arrears_paid = ArrearsPaid::calcAmountPaidByTenantDuringPeriod($tenant->id, $start, $end);
             $arrears = $aobj->calcTotalArrearsFromTenant($tenant->id);
             $deposit_obj = Deposit::findByPeriodForTenant($tenant->id, $start, $end);
             $deposit_paid = !is_null($deposit_obj) ? $deposit_obj->getPaymentAmount() : NULL;
             $kplc_obj = DepositKPLC::findByPeriodForTenant($tenant->id, $start, $end);
             $kplc_paid = !is_null($kplc_obj) ? $kplc_obj->getPaymentAmount() : NULL;
             $eldowas_obj = DepositEldowas::findByPeriodForTenant($tenant->id, $start, $end);
             $eldowas_paid = !is_null($eldowas_obj) ? $eldowas_obj->getPaymentAmount() : NULL;
             $totals = $tenant->calcPaymentsMadeDuringPeriod($start, $end);
             $record->tenant = $tenant->getFullName();
             $record->receipt_no = $receipt;
             $record->rent_pm = $rm->getRent();
             $record->rent_paid = $rent_paid;
             $record->arrears_paid = $arrears_paid;
             $record->arrears = $arrears;
             $record->house_deposit = $deposit_paid;
             $record->kplc_deposit = $kplc_paid;
             $record->eldowas_deposit = $eldowas_paid;
             $record->totals = $totals;
             $record->remarks = $remarks;
         } else {
             $record->tenant = "VACANT";
             $record->rent_pm = $rm->getRent();
         }
         $record_objects[] = $record;
     }
     return $record_objects;
 }
Example #2
0
        <th>Phone No</th>
        <th>Business Name</th>
        <th>Status</th>
        <th>Rent/M</th>
        <th>Arrears(<?php 
    echo $month;
    ?>
)</th>
    </tr>
    </thead>
    <tbody>
    <?php 
    foreach ($tenants as $tnt) {
        ?>
    <?php 
        $bal = Arrears::findByPeriodForTenant($tnt->id, $start, $end);
        //echo var_dump($bal);
        $arrears = 0.0;
        if (is_null($bal) && $tnt->getPaymentStatus() == 0) {
            $arrears = Room::findByTenantId($tnt->id)->getRent();
        } elseif (!is_null($bal)) {
            $arrears = $bal->getAmountOwed();
        }
        ?>
    <tr <?php 
        if ($tnt->getPaymentStatus() == 0) {
            echo ' style="background:red;color:white;"';
        }
        ?>
>
    	<td align="right"><a href="tenant.php?tid=<?php 
<?php

require_once '../lib/init.php';
if (!$session->isLoggedIn()) {
    redirect_to('../index.php');
}
if (isset($_GET['tid']) && !empty($_GET['tid'])) {
    $tenant_id = (int) $_GET['tid'];
    if (!is_int($tenant_id)) {
        $mesg = "Rent arrears of this tenant could not be shown. An invalid value was sent through the URL";
        $session->message($mesg);
        redirect_to("tenant.php?tid={$tenant_id}");
    } else {
        $tenant = Tenant::findById($tenant_id);
        $arrears = Arrears::findByTenantId($tenant_id);
    }
}
include_layout_template('admin_header.php');
?>

	<div id="container">
    <h3>Actions</h3>
    <div id="side-bar">
	<?php 
$actions = array("tenants" => "Tenants", "tenant_search" => "Search Tenant", "tenants_old" => "Previous Tenants");
echo create_action_links($actions);
?>
    </div>
    <div id="main-content">
    
    <a class="new-item" href="record_arrears.php?tid=<?php 
 /**
  * Generate a report that outlines the rent collection for a particular 
  * property over a specified period of time
  * @param mixed $title The report title
  * @param object $result_obj A result object obtained from a SELECT query
  * @param object $arrears_paid_obj A result object obtained from a SELECT query
  * @param object $arrears_obj A result object obtained from a SELECT query
  * @param object $expenses_obj A result object obtained from a SELECT query
  * @param array $headings Array of table heading names
  * @param array $widths Array of column widths
  * @param array $aligns Array of column alignments
  * @param string $orientation The page orientation of the report
  * @param mixed $page_size Dimensions of page that displays report
  * @param int $prop_id The ID used to identify the property
  * @param string $start Date string specifying start of the period
  * @param string $end Date string specifying end of the period
  */
 public function pdf($title, $result_obj, $arrears_paid_obj, $arrears_obj, $expenses_obj, $headings = NULL, $widths = NULL, $aligns = NULL, $orientation = 'P', $page_size = 'A4', $prop_id, $start, $end)
 {
     define('HORZ_PADDING', 2);
     define('VERT_PADDING', 3);
     $filename = date('Y-m-d') . '-report-' . uniqid() . '.pdf';
     $pdf = new PDF_Report($orientation, 'pt', $page_size);
     $pdf->set_title($title);
     $pdf->setStartPeriod($start);
     $pdf->setEndPeriod($end);
     $pdf->SetX(-1);
     $page_width = $pdf->GetX() + 1;
     $pdf->AliasNbPages();
     $pdf->SetFont('Helvetica', '', 7);
     $pdf->SetLineWidth(0.1);
     $pdf->SetMargins(self::PDF_MARGIN, self::PDF_MARGIN);
     $pdf->SetAutoPageBreak(true, self::PDF_MARGIN);
     $pdf->SetHorizontalPadding(HORZ_PADDING);
     $pdf->SetVerticalPadding(VERT_PADDING);
     $ncols = $this->columnCount($result_obj);
     // Instantiate Helper Variables
     $rent = new Rent();
     $total_collection = Rent::calcTotalCollection($prop_id, $start, $end);
     $paid_arrears = ArrearsPaid::calcCollectionForPropertyDuringPeriod($prop_id, $start, $end);
     $owed_arrears = Arrears::calcArrearsForPropertyDuringPeriod($prop_id, $start, $end);
     $collection_summary = Rent::calcCollectionSummary($prop_id, $start, $end);
     $mgt_fee = $rent->calcManagementFee($prop_id, $start, $end);
     $net_amount = $rent->calcBalanceAfterMgtFee($prop_id, $start, $end);
     $total_expenses = Expense::calcTotalExpenses($prop_id, $start, $end);
     $net_banking = $rent->calcNetBanking($prop_id, $start, $end);
     $rent_collection_array = array(0 => 'Rent Collection', 1 => $total_collection);
     $paid_arrears_array = array(0 => 'Paid Arrears', 1 => $paid_arrears);
     $summary_collection_array = array(0 => 'Total Collection', 1 => $collection_summary);
     $percentage_mgt_fee = Property::findById($prop_id)->getManagementFee();
     $percentage_mgt_fee = '(' . $percentage_mgt_fee . '%)';
     $mgt_fee_array = array(0 => 'Management Fee' . $percentage_mgt_fee, 1 => $mgt_fee);
     $net_amount_array = array(0 => 'Net Collection (Balance after Management Fee)', 1 => $net_amount);
     $total_expenses_array = array(0 => 'Total Expenses', 1 => $total_expenses);
     $net_banking_array = array(0 => 'Banking(Money Deposited to Landlord\'s Account)', 1 => $net_banking);
     if (is_null($headings)) {
         $headings = $this->columnHeadings($result_obj);
     }
     //$pdf->set_headings($headings);
     //$pdf->SetFont('Helvetica', 'B', 8);
     //$pdf->RowX($headings, false);/
     if (is_null($widths)) {
         $w = ($page_width - 2 * self::PDF_MARGIN) / $ncols;
         for ($i = 0; $i < $ncols; $i++) {
             $widths[$i] = $w;
         }
     }
     if (count($widths) == $ncols - 1) {
         $n = 0;
         foreach ($widths as $w) {
             $n += $w;
         }
         $widths[$ncols - 1] = $page_width - 2 * self::PDF_MARGIN - $n;
     }
     $pdf->SetWidths($widths);
     if (!is_null($aligns)) {
         $a = 'R';
         for ($i = 0; $i < $ncols; $i++) {
             $aligns[$i] = $a;
         }
     }
     $pdf->SetAligns($aligns);
     $pdf->AddPage();
     $pdf->SetFont('Helvetica', 'B', 8);
     $pdf->RowX($headings, false);
     $pdf->SetFont('Helvetica', '', 7);
     while ($row = $result_obj->fetch_row()) {
         $pdf->RowX($row);
     }
     if (!is_null($total_collection)) {
         $xPos = $page_width - (self::PDF_MARGIN + $w);
         $pdf->SetX($xPos);
         $pdf->SetFont('Times', 'B', 8);
         $text = "Total: " . $total_collection;
         $pdf->MultiCell($w, 12, $text, 1, 'R');
     }
     $pdf->Ln();
     $pdf->Ln();
     $pdf->SetX(0 + self::PDF_MARGIN);
     $pdf->SetFont('Arial', 'B', 10);
     $pdf->SetTextColor(24);
     $timestamp_start = strtotime($start);
     $timestamp_end = strtotime($end);
     $text_arrears_paid = "Arrears Collected for Period ";
     $text_arrears_paid .= strftime("%B %d, %Y", $timestamp_start);
     $text_arrears_paid .= " to " . strftime("%B %d, %Y", $timestamp_end);
     $pdf->MultiCell($pdf->get_page_width() - self::PDF_MARGIN * 2, 8, $text_arrears_paid, 'B', 'C');
     $pdf->Ln();
     // Arrears Paid
     if ($arrears_paid_obj->num_rows >= 1) {
         $col_count_arrears_paid = $this->columnCount($arrears_paid_obj);
         $arrears_paid_headings = $this->columnHeadings($arrears_paid_obj);
         $arrears_paid_widths = array();
         $w = ($page_width - 2 * self::PDF_MARGIN) / $col_count_arrears_paid;
         for ($i = 0; $i < $col_count_arrears_paid; $i++) {
             $arrears_paid_widths[$i] = $w;
         }
         //$pdf->SetWidths(array(70, 70, 70, 70, 70, 70));
         $pdf->SetWidths($arrears_paid_widths);
         $arrears_paid_aligns = array();
         $a = 'R';
         for ($i = 0; $i < $col_count_arrears_paid; $i++) {
             $arrears_paid_aligns[$i] = $a;
         }
         $pdf->SetAligns($arrears_paid_aligns);
         $pdf->SetFont('Helvetica', 'B', 8);
         $pdf->RowX($arrears_paid_headings, false);
         $pdf->SetFont('Helvetica', '', 7);
         while ($row = $arrears_paid_obj->fetch_row()) {
             $pdf->RowX($row);
         }
         if (!is_null($paid_arrears)) {
             $xPos = $page_width - (self::PDF_MARGIN + $w);
             $pdf->SetX($xPos);
             $pdf->SetFont('Times', 'B', 8);
             $text = "Total: " . $paid_arrears;
             $pdf->MultiCell($w, 12, $text, 1, 'R');
         }
     } else {
         $no_arrears = "Ksh. 0.00";
         $xPos = $page_width - (self::PDF_MARGIN + $w);
         $pdf->SetX($xPos);
         $pdf->MultiCell($w, 8, $no_arrears, 0, 'R');
         $pdf->Ln();
     }
     // Outstanding Arrears
     $pdf->Ln();
     $pdf->Ln();
     $pdf->SetX(0 + self::PDF_MARGIN);
     $pdf->SetFont('Arial', 'B', 10);
     $pdf->SetTextColor(24);
     $arrears_owed = "Outstanding Rent Arrears for the Period ";
     $arrears_owed .= strftime("%B %d, %Y", $timestamp_start);
     $arrears_owed .= " to " . strftime("%B %d, %Y", $timestamp_end);
     $pdf->MultiCell($pdf->get_page_width() - self::PDF_MARGIN * 2, 8, $arrears_owed, 'B', 'C');
     $pdf->Ln();
     if ($arrears_obj->num_rows >= 1) {
         $col_count_arrears = $this->columnCount($arrears_obj);
         $arrears_headings = $this->columnHeadings($arrears_obj);
         $arrears_widths = array();
         $w = ($page_width - 2 * self::PDF_MARGIN) / $col_count_arrears;
         for ($i = 0; $i < $col_count_arrears; $i++) {
             $arrears_widths[$i] = $w;
         }
         //$pdf->SetWidths(array(70, 70, 70, 70, 70, 70));
         $pdf->SetWidths($arrears_widths);
         $arrears_aligns = array();
         $a = 'R';
         for ($i = 0; $i < $col_count_arrears; $i++) {
             $arrears_aligns[$i] = $a;
         }
         $pdf->SetAligns($arrears_aligns);
         $pdf->SetFont('Helvetica', 'B', 8);
         $pdf->RowX($arrears_headings, false);
         $pdf->SetFont('Helvetica', '', 7);
         while ($row = $arrears_obj->fetch_row()) {
             $pdf->RowX($row);
         }
         if (!is_null($owed_arrears)) {
             $xPos = $page_width - (self::PDF_MARGIN + $w);
             $pdf->SetX($xPos);
             $pdf->SetFont('Times', 'B', 8);
             $text = "Total: " . $owed_arrears;
             $pdf->MultiCell($w, 12, $text, 1, 'R');
         }
     } else {
         $no_arrears = "Ksh. 0.00";
         $xPos = $page_width - (self::PDF_MARGIN + $w);
         $pdf->SetX($xPos);
         $pdf->MultiCell($w, 8, $no_arrears, 0, 'R');
         $pdf->Ln();
     }
     // Collection Summary
     $pdf->Ln();
     $pdf->Ln();
     $pdf->SetX(0 + self::PDF_MARGIN);
     $pdf->SetFont('Arial', 'B', 10);
     $pdf->SetTextColor(24);
     $pdf->MultiCell($pdf->get_page_width() - self::PDF_MARGIN * 2, 8, 'Collection Summary', 'B', 'C');
     $pdf->Ln();
     $summary_aligns = array('R', 'R');
     $pdf->SetAligns($summary_aligns);
     $cell_width = $pdf->get_page_width() / 4;
     $summary_widths = array($cell_width, $cell_width);
     $pdf->SetWidths($summary_widths);
     $pdf->Ln();
     $xPos = $page_width - (self::PDF_MARGIN + $cell_width * 2);
     //$pdf->SetX($xPos);
     $pdf->RowX($rent_collection_array);
     //$pdf->SetX($xPos);
     $pdf->RowX($paid_arrears_array);
     //$pdf->SetX($xPos);
     $pdf->RowX($summary_collection_array);
     $pdf->Ln();
     $pdf->Ln();
     //$pdf->SetX($xPos);
     $pdf->RowX($mgt_fee_array);
     //$pdf->SetX($xPos);
     //$pdf->RowX($net_amount_array);
     $pdf->Ln();
     $pdf->Ln();
     // Outline Expenses
     $pdf->SetX(0 + self::PDF_MARGIN);
     $pdf->SetFont('Arial', 'B', 10);
     $pdf->SetTextColor(24);
     $exp_incurred = "Expenses for the Period ";
     $exp_incurred .= strftime("%B %d, %Y", $timestamp_start);
     $exp_incurred .= " to " . strftime("%B %d, %Y", $timestamp_end);
     $pdf->MultiCell($pdf->get_page_width() - self::PDF_MARGIN * 2, 8, $exp_incurred, 'B', 'C');
     $pdf->Ln();
     if ($expenses_obj->num_rows >= 1) {
         $col_count_expenses = $this->columnCount($expenses_obj);
         $expense_headings = $this->columnHeadings($expenses_obj);
         $expense_widths = array();
         $w = ($page_width - 2 * self::PDF_MARGIN) / $col_count_expenses;
         for ($i = 0; $i < $col_count_expenses; $i++) {
             $expense_widths[$i] = $w;
         }
         //$pdf->SetWidths(array(70, 70, 70, 70, 70, 70));
         $pdf->SetWidths($expense_widths);
         $expense_aligns = array();
         $a = 'R';
         for ($i = 0; $i < $col_count_expenses; $i++) {
             $expense_aligns[$i] = $a;
         }
         $pdf->SetAligns($expense_aligns);
         $pdf->SetFont('Helvetica', 'B', 8);
         $pdf->RowX($expense_headings, false);
         $pdf->SetFont('Helvetica', '', 7);
         while ($row = $expenses_obj->fetch_row()) {
             $pdf->RowX($row);
         }
         if (!is_null($total_expenses)) {
             $xPos = $page_width - (self::PDF_MARGIN + $w);
             $pdf->SetX($xPos);
             $pdf->SetFont('Times', 'B', 8);
             $text = "Total: " . $total_expenses;
             $pdf->MultiCell($w, 12, $text, 1, 'R');
         }
     } else {
         $no_expenses = "Ksh. 0.00";
         $xPos = $page_width - (self::PDF_MARGIN + $w);
         $pdf->SetX($xPos);
         $pdf->MultiCell($w, 8, $no_expenses, 0, 'R');
         $pdf->Ln();
     }
     $pdf->Ln();
     $pdf->Ln();
     $pdf->SetX(0 + self::PDF_MARGIN);
     $pdf->SetFont('Arial', 'B', 10);
     $pdf->SetTextColor(24);
     $pdf->MultiCell($pdf->get_page_width() - self::PDF_MARGIN * 2, 8, 'Banking', 'B', 'C');
     $banking_aligns = array('R', 'R');
     $pdf->SetAligns($banking_aligns);
     $cell_width = $pdf->get_page_width() / 4;
     $banking_widths = array($cell_width, $cell_width);
     $pdf->SetWidths($banking_widths);
     $pdf->Ln();
     $xPos = $page_width - (self::PDF_MARGIN + $cell_width * 2);
     //$pdf->SetX($xPos);
     $pdf->RowX($net_amount_array);
     //$pdf->SetX($xPos);
     $pdf->RowX($total_expenses_array);
     //$pdf->SetX($xPos);
     $pdf->RowX($net_banking_array);
     $pdf->Ln();
     $pdf->MultiCell($pdf->get_page_width() - self::PDF_MARGIN * 2, 8, 'Analysis', 'B', 'C');
     $pdf->Ln();
     $currProp = Property::findById($prop_id);
     $num_of_rooms = $currProp->getNumRooms();
     $num_occupied_rooms = $currProp->getNumRoomsOccupied();
     $occupancy_level = $currProp->calcOccupancyLevel();
     $monthly_collection = $currProp->calcExpectedMonthlyCollection();
     $expected_collection = $currProp->calcExpectedCollectionForPeriod($start, $end);
     $percentage_collection = $currProp->calcCollectionPercentageForPeriod($start, $end);
     $period = $currProp->getNumMonthsInPeriod($start, $end);
     $period = '( ' . $period . ' Month[s] )';
     $num_rooms_array = array(0 => 'Number of Rooms in Property', 1 => $num_of_rooms);
     $occupied_rooms_array = array(0 => 'No. of Occupied Rooms', 1 => $num_occupied_rooms);
     $occupancy_level_array = array(0 => 'Occupancy Level (%)', 1 => $occupancy_level . '%');
     $expected_monthly_collection = array(0 => 'Expected Monthly Collection', 1 => $monthly_collection);
     $amount_collected_array = array(0 => "Total Amount Collected in Period{$period}", 1 => $collection_summary);
     $expected_collection_array = array(0 => 'Expected Collection for Period', 1 => $expected_collection);
     $percentage_collection_array = array(0 => 'Collection Level (%)', 1 => $percentage_collection . '%');
     //$pdf->SetX($xPos);
     $pdf->RowX($num_rooms_array);
     //$pdf->SetX($xPos);
     $pdf->RowX($occupied_rooms_array);
     //$pdf->SetX($xPos);
     $pdf->RowX($occupancy_level_array);
     //$pdf->SetX($xPos);
     $pdf->RowX($expected_monthly_collection);
     //$pdf->SetX($xPos);
     $pdf->RowX($amount_collected_array);
     //$pdf->SetX($xPos);
     $pdf->RowX($expected_collection_array);
     //$pdf->SetX($xPos);
     $pdf->RowX($percentage_collection_array);
     $pdf->Output($filename, 'D');
 }
<?php

require_once '../lib/init.php';
if (!$session->isLoggedIn()) {
    redirect_to('../index.php');
}
if (!$ac->hasPermission('delete_rent')) {
    $mesg = "You don't have permission to access this page";
    $session->message($mesg);
    redirect_to($_SERVER['HTTP_REFERER']);
}
if (isset($_GET['tid']) && !empty($_GET['tid']) && (isset($_GET['aid']) && !empty($_GET['aid']))) {
    $tenant_id = (int) $_GET['tid'];
    $arrears_id = (int) $_GET['aid'];
    if (!is_int($tenant_id) || !is_int($arrears_id)) {
        $mesg = "Arrears could not be edited. An invalid value was sent through the URL";
        $session->message($mesg);
        redirect_to("tenants.php");
    } else {
        $arrears = Arrears::findById($arrears_id);
        echo var_dump($arrears);
        if ($arrears->deleteArrears()) {
            $mesg = "Arrears deleted";
            $session->message($mesg);
            redirect_to("tenant_arrears.php?tid={$tenant_id}");
        }
    }
}
 /**
  * Generate the HTML of the receipt print
  */
 public function buildArrearsReceipt()
 {
     global $session;
     $html = '<div id="outerHTML">';
     $html .= '<div id="printArea">';
     $html .= '<h2 align="center">Salesforce</h2>';
     $html .= '<h3 align="center">Official Receipt: Arrears Payment</h3>';
     $html .= '<div id="receipt-header">';
     $html .= '<p align="center">';
     $html .= 'Kenyatta Street, New Muya House<br />';
     $html .= '2<sup>nd</sup> Flr, Room 105.<br />';
     $html .= 'Tel: + 254 721 156 315 &nbsp; / &nbsp; + 254 720 711 115<br />';
     $html .= 'www.salesforce.co.ke &nbsp; Email: info@salesforce.co.ke';
     $html .= '</p></div>';
     $html .= '<hr align="center" />';
     $html .= '<div id="receipt-body">';
     $html .= '<p><strong>Receipt No:</strong> &nbsp;<span style="color:#F00;">';
     $html .= $this->_receipt_no;
     $html .= '</span></p>';
     $html .= '<p><strong>Tenant:</strong> &nbsp;';
     $tenant = Tenant::findById($this->_tid);
     $html .= $tenant->getFullName() . '</p>';
     $html .= '<p><strong>Room No:</strong> &nbsp;';
     $html .= Room::findById(Tenant::findById($this->_tid)->getRoomId())->getRoomLabel();
     $html .= '</p><p><strong>Payment Amount:</strong> &nbsp;';
     //$html .= number_format($session->sessionVar('amount'));
     $html .= number_format($this->_amount);
     if ($tenant->hasArrears()) {
         $arrears = new Arrears();
         $html .= '</p><p><strong>Arrears</strong>&nbsp;';
         $html .= $arrears->calcTotalArrearsFromTenant($this->_tid);
     }
     $html .= '</p><p><strong>Month:</strong>&nbsp;';
     $html .= $this->_getMonthFromDate($this->_start_date);
     $html .= '</p><p><strong>Company Agent:</strong> &nbsp;';
     $html .= $this->_agent . '</p>';
     $html .= '<p><strong>Date:</strong> &nbsp;';
     $html .= $this->_date_paid . " &nbsp;&nbsp;";
     $html .= '</p></div>';
     $html .= '</div></div>';
     print $html;
 }
    $tenant_id = (int) $_GET['tid'];
    if (!is_int($tenant_id)) {
        $mesg = "Rent arrears for the tenant could not be recorded. An invalid value was sent through the URL";
        $session->message($mesg);
        redirect_to("tenants.php");
    } else {
        $tenant = Tenant::findById($tenant_id);
    }
}
/////////////////////////////////////////////////////////////////
///////////////////////// PROCESS SUBMIT ////////////////////////
/////////////////////////////////////////////////////////////////
if (isset($_POST['submit'])) {
    $start = $_POST['start_date'];
    $end = $_POST['end_date'];
    $arrears = new Arrears();
    if (empty($start) || empty($end)) {
        $err = "Form fields marked with an asterix are required";
    } elseif (!valid_date_range($start, $end)) {
        $err = "You must specify arrears monthly. Specify a month by ";
        $err .= "choosing the start and end dates of the month";
    } elseif ($tenant->hasPaidFullRent($tenant_id, $start, $end)) {
        $err = "Tenant has already paid the full rent of the period you specified";
    } elseif ($arrears->arrearsExist($tenant_id, $start, $end)) {
        $err = "You cannot record arrears for a particular month more than once. ";
        $err .= "Go to the arrears menu and edit the amount entered as arrears";
    } else {
        //$arrears = new Arrears();
        if ($arrears->recordArrears($tenant_id, $start, $end)) {
            $mesg = "Rent arrears for tenant recorded";
            $session->message($mesg);
 /**
  * Delete a rent payment
  * @todo Delete records from both the rent and payment_status tables
  * @return boolean
  */
 public function deletePayment()
 {
     $start = $this->getStartPeriod();
     $end = $this->getEndPeriod();
     $tenant_id = $this->_tid;
     $payment_status = PaymentStatus::findByPeriod($tenant_id, $start, $end);
     $arrears = Arrears::findByPeriodForTenant($tenant_id, $start, $end);
     $db = Database::getInstance();
     $mysqli = $db->getConnection();
     $mysqli->autocommit(false);
     if (!is_null($arrears)) {
         if ($arrears->arrearsExist($tenant_id, $start, $end)) {
             $arrears->deleteTenantArrearsForPeriod($start, $end);
         }
     }
     $payment_status->delete();
     $this->delete();
     if (!$mysqli->commit()) {
         $mysqli->rollback();
         $mysqli->autocommit(true);
         return false;
     } else {
         $mysqli->autocommit(true);
         return true;
     }
 }
$prop_id = $session->sessionVar("prop_id");
//echo var_dump($prop_id);
if (isset($_POST['submit'])) {
    $start_date = $_POST['start_date'];
    $end_date = $_POST['end_date'];
    if (empty($start_date) || empty($end_date)) {
        $err = "Choose a month from which to display rent payments from";
    } elseif (!valid_date_range($start_date, $end_date)) {
        $err = "Reports can only be specified monthly";
    } else {
        // continue with processing
        //echo var_dump($prop_id);
        $payments = Rent::getPaymentsFromProperty($prop_id, $start_date, $end_date);
        //echo var_dump($payments);
        $arrears_paid = ArrearsPaid::getPaidArrearsForProperty($prop_id, $start_date, $end_date);
        $arrears = Arrears::getOutstandingArrearsForProperty($prop_id, $start_date, $end_date);
        $expenses = Expense::findByPeriodForProperty($prop_id, $start_date, $end_date);
        $deposits = Deposit::findPaymentsForPeriodByProperty($prop_id, $start_date, $end_date);
        $refunds = Deposit::findRefundsForPeriodByProperty($prop_id, $start_date, $end_date);
        $refunds_kplc = DepositKPLC::findRefundsForPeriodByProperty($prop_id, $start_date, $end_date);
        $refunds_eldowas = DepositEldowas::findRefundsForPeriodByProperty($prop_id, $start_date, $end_date);
        $records = CollectionReport::buildRecords($prop_id, $start_date, $end_date);
        $deductions = CollectionReport::calcTotalDeductionsForPeriod($prop_id, $start_date, $end_date);
        //echo var_dump($records);
        //echo var_dump($arrears_paid);
    }
} elseif (isset($_POST['report'])) {
    // Generate PDF report
    $start_date = $_POST['start_date'];
    $end_date = $_POST['end_date'];
    if (empty($start_date) || empty($end_date)) {
 /**
  * Record a payment of an outstanding rent balance
  * @param int $arrears_id The ID used to identify the arrears
  * @param int $amount The amount payed to settle the arrears
  * @param string $start Date specifying start of a month
  * @param string $end Date specifying end of a month
  * @param string $mode The mode of payment for the transaction
  * @param object $session A session object declared in global scope
  * @return boolean
  */
 public function payArrears($arrears_id, $amount, $start, $end, $mode, $session)
 {
     $arrears = Arrears::findById($arrears_id);
     $bal = $arrears->getAmountOwed();
     $bal = (int) $this->_sanitizeMoneyString($bal);
     $db = Database::getInstance();
     $mysqli = $db->getConnection();
     // Initialize object to keep track of transaction details
     $ap = new ArrearsPaid();
     $ap->setTenantId($this->id);
     $ap->setPaymentAmount($amount);
     $ap->setStartPeriod($start);
     $ap->setEndPeriod($end);
     $ap->setDatePaid();
     $ap->generateReceiptNo();
     $ap->setPaymentMode($mode);
     $ap->setReceivingAgent($session);
     if ($amount == $bal) {
         // All arrears cleared
         $status = PaymentStatus::findByPeriod($this->id, $start, $end);
         $status->setStatus(1);
         $mysqli->autocommit(false);
         $ap->save();
         $arrears->delete();
         $_SESSION['arrears_obj'] = $this->arrears_obj = serialize($arrears);
         $status->save();
         if (!$mysqli->commit()) {
             $mysqli->rollback();
             $mysqli->autocommit(true);
             return false;
         } else {
             $mysqli->autocommit(true);
             return true;
         }
     } elseif ($amount < $bal) {
         // Arrears partially cleared
         $new_arrears = (int) $bal - (int) $amount;
         $arrears->setAmountOwed($new_arrears);
         $mysqli->autocommit(false);
         $ap->save();
         $arrears->save();
         if (!$mysqli->commit()) {
             $mysqli->rollback();
             $mysqli->autocommit(true);
             return false;
         } else {
             $mysqli->autocommit(true);
             return true;
         }
     }
 }
        <td align="right"><?php 
        echo $ar->getMonth();
        ?>
</td>
        <td align="right"><?php 
        echo $ar->getAmountOwed();
        ?>
</td>
    </tr>
    <?php 
    }
    ?>
    <tr>
    	<td colspan="2" class="analysis" align="right">Total</td>
        <td align="right" class="analysis"><?php 
    echo Arrears::calcArrearsForPropertyDuringPeriod($prop_id, $start, $end);
    ?>
</td>
    </tr>
    </tbody>
    </table>
    <?php 
} elseif (empty($arrears) && !empty($prop_id) && !empty($start) && !empty($end)) {
    echo "<p>Property doesn't have any arrears for the specified period</p>";
}
?>
    
    </div>
    </div>

<?php