/**
  * 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;
 }
if (isset($_POST['submit'])) {
    $referer_filename = $_POST['referer'];
    $selected_prop = $_POST['prop_name'];
    //echo var_dump($referer_filename);
    if (empty($selected_prop)) {
        if ($referer_filename == "rooms") {
            $err = "Please choose a property to add rooms to";
        } elseif ($referer_filename == "tenants") {
            $err = "Please choose a property from which to select a vacant room for the tenant";
        }
    } else {
        $session->sessionVar("prop_id", $selected_prop);
        $session->message("Property selection saved");
        $p = Property::findById($selected_prop);
        if ($referer_filename == "rooms") {
            if ($p->getNumRooms() == Room::getNumRoomsForProperty($selected_prop)) {
                $mesg = "You cannot create additional rooms on the selected property. The property already has the maximum number of rooms it can hold. You will first need to adjust the number of rooms the property holds before proceeding";
                $session->message($mesg);
                redirect_to("rooms.php");
            }
            redirect_to("add_room.php");
        } elseif ($referer_filename == "tenants") {
            if ($p->isFullyOccupied()) {
                $mesg = "The property you selected is fully occupied. Choose another property to add the tenant to";
                $session->message($mesg);
                redirect_to("tenants.php");
            }
            redirect_to("choose_room.php");
        }
    }
} else {