/** * 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; } }
/** * 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; } } }
/** * * Fetches Payment information based on Status * * @params paymentStatus * - Status of type which payment information has to be fetched * * @returns List containing Cart objects. Payment history can be retrieved * from individual Cart object. */ function getPaymentsByStatus($paymentStatus) { Util::throwExceptionIfNullOrBlank($paymentStatus, "Payment Status"); $encodedPaymentStatus = Util::encodeParams($paymentStatus); $objUtil = new Util($this->apiKey, $this->secretKey); try { $params = null; $paymentObj = new PaymentStatus(); if ($paymentObj->isAvailable($paymentStatus) == "null") { throw new App42Exception("Payment Status '{$paymentStatus}' does not Exist "); } $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $signParams['status'] = $paymentStatus; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/payments/status/" . $encodedPaymentStatus; $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams); $cartResponseObj = new CartResponseBuilder(); $cartObj = $cartResponseObj->buildArrayResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $cartObj; }
/** * 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; }
///////////////////////// 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"; }