public function setUp() { $this->curDate = new \DateTime('2014-11-29'); $accountValues = array(array('client_portfolio_id' => 2, 'system_client_account_id' => 2, 'total_value' => 101000, 'date' => '2014-11-27'), array('client_portfolio_id' => 2, 'system_client_account_id' => 2, 'total_value' => 202000, 'date' => '2014-11-28'), array('client_portfolio_id' => 2, 'system_client_account_id' => 2, 'total_value' => 303000, 'date' => '2014-11-29'), array('client_portfolio_id' => 2, 'system_client_account_id' => 2, 'total_value' => 404000, 'date' => '2014-11-30')); $repository = new ClientAccountValueRepo(); foreach ($accountValues as $value) { $model = new ClientAccountValueModel(); $model->loadFromArray($value); $repository->save($model); } $transactionValues = array(array('account_id' => 2, 'transaction_type_id' => 24, 'closing_method_id' => 6, 'security_id' => 11, 'tx_date' => '2014-11-28', 'qty' => 30, 'net_amount' => 3000, 'gross_amount' => 0), array('account_id' => 2, 'transaction_type_id' => 41, 'closing_method_id' => 6, 'security_id' => 482, 'tx_date' => '2014-11-28', 'qty' => 40, 'net_amount' => 4000, 'gross_amount' => 0), array('account_id' => 2, 'transaction_type_id' => 42, 'closing_method_id' => 6, 'security_id' => 13, 'tx_date' => '2014-11-28', 'qty' => 20, 'net_amount' => 2000, 'gross_amount' => 0), array('account_id' => 2, 'transaction_type_id' => 42, 'closing_method_id' => 6, 'security_id' => 13, 'tx_date' => '2014-11-29', 'qty' => 30, 'net_amount' => 2000, 'gross_amount' => 0), array('account_id' => 2, 'transaction_type_id' => 42, 'closing_method_id' => 6, 'security_id' => 13, 'tx_date' => '2014-11-30', 'qty' => 31, 'net_amount' => 2000, 'gross_amount' => 0)); $repository = new TransactionRepo(); foreach ($transactionValues as $value) { $model = new TransactionModel(); $model->loadFromArray($value); $repository->save($model); } $accounts[6][] = $this->getModelMock('SystemClientAccount', array('id' => 2, 'client_id' => 6, 'account_number' => '409888117', 'closed' => '2014-11-29', 'status' => SystemAccount::STATUS_CLOSED)); $calculator = $this->getMockBuilder('Pas\\TwrCalculator')->disableOriginalConstructor()->setMethods(array('getAllAccounts'))->getMock(); $calculator->expects($this->any())->method('getAllAccounts')->will($this->returnValue($accounts)); $calculator->run('2014-11-29'); $calculator->run('2014-11-30'); }
/** * Create transaction * * @param \Model\Pas\SystemClientAccount $account * @param array $data * @return int|null */ public function create(SystemClientAccountModel $account, array $data) { if (null == ($security = $this->getSecurity($data['symbol']))) { return null; } if (null == ($closingMethod = $this->getClosingMethod($data['closing_method']))) { return null; } if (null == ($transactionType = $this->getTransactionType($data['transaction_code']))) { return null; } $model = new TransactionModel(); $model->loadFromArray($data); $model->setStatus('verified'); $model->setAccountId($account->getId()); $model->setSecurityId($security->getId()); $model->setClosingMethodId($closingMethod->getId()); $model->setTransactionTypeId($transactionType->getId()); $id = $this->getRepository('Transaction')->save($model); if ($id && $model->isCreateLot()) { $data['transaction_id'] = $id; $this->collection[$data['tx_date']][] = $data; } if ($id) { // Update bill item fee collected $this->updateFeeCollected($account, $model); } return $id; }
/** * Save * * @param Transaction $model * @return int|bool */ public function save(Transaction $model) { $result = $this->getAllQuery(array('date' => $model->getTxDate(), 'account_id' => $model->getAccountId(), 'security_id' => $model->getSecurityId()))->limit(1)->fetch('id'); return $result ? $this->update($result, $model) : $this->insert($model); }