/** * Cancels a transaction * * @param \DateTime $transactionAt * @return null|int */ protected function cancelTransaction($transactionAt) { $monthNo = $transactionAt->format('m'); $year = $transactionAt->format('Y'); $this->transData = $this->transaction->getLatestTransactionByTermId($this->termId, $monthNo, $year); if ($this->transData) { if ($this->transData->getInvoiceID() > 0) { $this->transactionAmount += $this->transData->getAmount(); } $this->transData->setStatusId($this->transStatusCancelled); $this->transaction->updateTransaction($this->transData); $previousId = $this->transData->getId(); $this->tsData = $this->transactionSupport->getTransactionSupport($previousId); $this->tsData->setTransDate($transactionAt->format('Y-m-d'))->setBand($this->band); $this->transactionSupport->updateTransactionSupport($this->tsData); return $previousId; } return null; }
/** * Gets the latest transaction record for the given term Id * * @param int $termId * @param int|null $month * @param int|null $year * @return Model_Core_Transaction|null */ public function getLatestTransactionByTermId($termId, $month = null, $year = null) { $select = $this->select(); $select->where('termId = ?', $termId)->where('statusId = ?', Model_Core_Transaction::STATUS_LIVE); if ($month && $year) { $select->where('YEAR(TransactionDate) = ?', $year)->where('MONTH(TransactionDate) = ?', $month); } else { if ($month) { $select->where('MONTH(TransactionDate) = ?', $month); } else { $select->order('ID DESC'); } } $select->limit(1); $row = $this->fetchRow($select); // There should only be a single transaction with the given id if (count($row) == 1) { $transaction = new Model_Core_Transaction(); $transaction->setId($row->ID)->setPreviousId($row->PreviousID)->setEnquiryId($row->EnquiryID)->setAmount($row->Amount)->setStatusId($row->StatusID)->setInvoiceId($row->InvoiceID)->setCreditNoteId($row->CreditNoteID)->setInsuranceNetAmount($row->InsuranceNetAmount)->setTransactionDate($row->TransactionDate); return $transaction; } return null; }