/**
  * 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;
 }
 /**
  * Calculate the sum of all payments made by a tenant during a specifed
  * period of time. This includes monthly rent, rent arrears paid, house 
  * deposit, KPLC deposit and ELDOWAS deposit
  * @param string $start Date string specifying start of the period
  * @param string $end Date string specifying end of the period
  * @return int $total_payments
  */
 public function calcPaymentsMadeDuringPeriod($start, $end)
 {
     $total_amount = 0;
     $rent = Rent::findByPeriodForTenant($this->id, $start, $end);
     $arrers_paid = ArrearsPaid::calcAmountPaidByTenantDuringPeriod($this->id, $start, $end);
     $arrers_paid = $this->_formatCurrencyString($arrers_paid);
     $deposit = Deposit::findByPeriodForTenant($this->id, $start, $end);
     $kplc = DepositKPLC::findByPeriodForTenant($this->id, $start, $end);
     $eldowas = DepositEldowas::findByPeriodForTenant($this->id, $start, $end);
     $rent_amount = !is_null($rent) ? $this->_formatCurrencyString($rent->getPaymentAmount()) : 0;
     $deposit_amount = !is_null($deposit) ? $this->_formatCurrencyString($deposit->getPaymentAmount()) : 0;
     $kplc_amount = !is_null($kplc) ? $this->_formatCurrencyString($kplc->getPaymentAmount()) : 0;
     $eldowas_amount = !is_null($eldowas_amount) ? $this->_formatCurrencyString($eldowas->getPaymentAmount()) : 0;
     $total_amount = $rent_amount + $deposit_amount + $arrers_paid + $kplc_amount + $eldowas_amount;
     return number_format($total_amount);
 }