/** * 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; } } }
/** * 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; } }
/** * Show the rent payment status of tenants from a particular property * during a specified period of time * @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 * @retun array $tenants An array of tenant objects */ public static function showPaymentStatusOfTenantsByProperty($prop_id, $start, $end) { $tenants = static::findByPropertyId($prop_id); foreach ($tenants as $tnt) { $status = PaymentStatus::findByPeriod($tnt->id, $start, $end); if (!is_null($status) && $status->getTenantId() == $tnt->id) { $payment_status = $status->getStatus(); $tnt->setPaymentStatus($payment_status); } } return $tenants; }