Exemplo n.º 1
0
 /**
  * Edit the amount paid as rent for a particular month
  * @param int $amount The new payment amount
  * @return boolean
  */
 public function editPayment($amount)
 {
     $start = $this->_start_date;
     $end = $this->_end_date;
     $tenant_id = $this->_tid;
     $rent_pm = Room::findByTenantId($tenant_id)->getRent();
     $rent_pm = (int) str_replace(',', '', $rent_pm);
     $amount = (int) str_replace(',', '', $amount);
     $curr_amount = (int) $this->_amount;
     $db = Database::getInstance();
     $mysqli = $db->getConnection();
     if (PaymentStatus::paymentStatusOK($tenant_id, $start, $end) && $amount < $rent_pm) {
         // Change payment status for tenant during period
         $statusObj = PaymentStatus::findByPeriod($tenant_id, $start, $end);
         $statusObj->setStatus(0);
         // Create a new arrears object
         $arrears = new Arrears();
         $bal_owed = $rent_pm - $amount;
         $arrears->setTenantId($tenant_id);
         $arrears->setStartPeriod($start);
         $arrears->setEndPeriod($end);
         $arrears->setAmountOwed($bal_owed);
         // Change Amount
         $this->setPaymentAmount($amount);
         $mysqli->autocommit(false);
         $arrears->save();
         $statusObj->save();
         $this->save();
         if (!$mysqli->commit()) {
             $mysqli->rollback();
             $mysqli->autocommit(true);
             return false;
         } else {
             $mysqli->autocommit(true);
             return true;
         }
     } elseif (!PaymentStatus::paymentStatusOK($tenant_id, $start, $end) && $amount == $rent_pm) {
         // Change payment status for tenant during period
         $statusObj = PaymentStatus::findByPeriod($tenant_id, $start, $end);
         $statusObj->setStatus(1);
         // Find corresponding arrears
         $arrears = Arrears::findByPeriodForTenant($tenant_id, $start, $end);
         // Change Amount
         $this->setPaymentAmount($amount);
         $mysqli->autocommit(false);
         $arrears->delete();
         $statusObj->save();
         $this->save();
         if (!$mysqli->commit()) {
             $mysqli->rollback();
             $mysqli->autocommit(true);
             return false;
         } else {
             $mysqli->autocommit(true);
             return true;
         }
     } elseif (!PaymentStatus::paymentStatusOK($tenant_id, $start, $end) && $amount < $rent_pm) {
         // reduce amount paid and increase amount owed
         $arrears = Arrears::findByPeriodForTenant($tenant_id, $start, $end);
         $new_arrears = $rent_pm - $amount;
         $arrears->setAmountOwed($new_arrears);
         $this->setPaymentAmount($amount);
         $mysqli->autocommit(false);
         $arrears->save();
         $this->save();
         if (!$mysqli->commit()) {
             $mysqli->rollback();
             $mysqli->autocommit(true);
             return false;
         } else {
             $mysqli->autocommit(true);
             return true;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Check to establish whether tenant has paid the rent 
  * full rent for the specified period
  * @param int $tenant_id ID used to identify the tenant
  * @param string $start Date string specifying start of the period
  * @param string $end Date string specifying end of the period
  * @return boolean
  */
 public function hasPaidFullRent($tenant_id, $start, $end)
 {
     $status = PaymentStatus::paymentStatusOK($tenant_id, $start, $end);
     return $status;
 }
Exemplo n.º 3
0
 /**
  * Delete arrears of a particular tenant for a specified period
  * @todo Delete an outstanding arrears and set the tenants payment
  *  status as paid
  * @return boolean
  */
 public function deleteArrears()
 {
     $db = Database::getInstance();
     $mysqli = $db->getConnection();
     $tenant_id = $this->_tid;
     $start = $this->_start_date;
     $end = $this->_end_date;
     if (!PaymentStatus::paymentStatusOK($tenant_id, $start, $end)) {
         $status = PaymentStatus::findByPeriod($tenant_id, $start, $end);
         $status->setStatus(1);
         //$arrears = static::findByPeriod($tenant_id, $start, $end);
         $mysqli->autocommit(false);
         $status->save();
         $this->delete();
         if (!$mysqli->commit()) {
             $mysqli->rollback();
             $mysqli->autocommit(true);
             return false;
         } else {
             $mysqli->autocommit(true);
             return true;
         }
     }
 }
Exemplo n.º 4
0
///////////////////////// PROCESS SUBMIT ////////////////////////
/////////////////////////////////////////////////////////////////
if (isset($_POST['submit'])) {
    $start_date = $_POST['start_date'];
    $end_date = $_POST['end_date'];
    $amount_owed = $_POST['amount'];
    if (empty($start_date) || empty($end_date) || empty($amount_owed)) {
        $err = "Form fields marked with an asterix are required";
    } else {
        $arrears = Arrears::findById($arrears_id);
        $amount = (int) $arrears->removeCommasFromCurrency($_POST['amount']);
        $rent_pm = Room::findByTenantId($tenant_id)->getRent();
        $rent_pm = (int) $arrears->removeCommasFromCurrency($rent_pm);
        if ($amount > $rent_pm) {
            $err = "Arrears cannot exceed the tenants monthly rent";
        } elseif (PaymentStatus::paymentStatusOK($tenant_id, $start, $end)) {
            $mesg = "Tenant already paid the full rent for the specified period and therefore cannot have arrears";
            $session->message($mesg);
            redirect_to("tenant_arrears.php?tid={$tenant_id}");
        } else {
            $arrears->setTenantId($tenant->id);
            $arrears->setStartPeriod($start_date);
            $arrears->setEndPeriod($end_date);
            $arrears->setAmountOwed($amount_owed);
            if ($arrears->save()) {
                $mesg = "Changes Saved";
                $session->message($mesg);
                redirect_to("tenant_arrears.php?tid={$tenant_id}");
            } else {
                $err = "An error occured preventing the arrears from being recorded. Please try again later";
            }