public function testCreditingAnAccountWillCreditItsParentIfOneExistsInAChart() { $ac1 = new Account($this->chart, new Nominal('9998'), AccountType::DR(), new StringType('foo1')); $ac2 = new Account($this->chart, new Nominal('9999'), AccountType::DR(), new StringType('foo2')); $this->chart->addAccount($ac1); $this->chart->addAccount($ac2, $ac1->getId()); $ac2->credit(Factory::create('gbp', 1)); $this->assertEquals(100, $ac1->getCredit()->get()); }
/** * Get parent id as an Option * * @return Option */ protected function optGetParentId() { return Match::on(FTry::with(function () { return $this->chart->getParentId($this->id); }))->Monad_FTry_Success(function ($id) { return Option::create($id->flatten()); })->Monad_FTry_Failure(function () { return Option::create(null); })->value(); }
public function testGettingTheParentIdOfAnAccountThatHasAParentWillReturnTheParentId() { $ac1 = new Account($this->sut, new Nominal('9998'), AccountType::ASSET(), new StringType('Asset')); $this->sut->addAccount($ac1); $ac2 = new Account($this->sut, new Nominal('9999'), AccountType::ASSET(), new StringType('Asset-2')); $this->sut->addAccount($ac2, $ac1->getId()); $f = $this->sut->getParentId($ac2->getId()); $b = $f->get(); $this->assertEquals('9998', $this->sut->getParentId($ac2->getId())->get()); }
public function testYouCanWriteATransactionToAJournalAndUpdateAChart() { $chart = new Chart(new StringType('foo bar'), new Organisation(new IntType(1), new StringType('Foo Org'), CurrencyFactory::create('gbp'))); $chart->addAccount(new Account($chart, new Nominal('0000'), AccountType::DR(), new StringType('Foo'))); $chart->addAccount(new Account($chart, new Nominal('0001'), AccountType::CR(), new StringType('Bar'))); $journal = new Journal(new StringType('Foo Journal'), CurrencyFactory::create('gbp'), $this->journalist); $txn = new Transaction(new Nominal('0000'), new Nominal('0001'), CurrencyFactory::create('gbp', 12.26)); $this->journalist->expects($this->once())->method('writeTransaction')->will($this->returnValue(new IntType(1))); $returnedTransaction = $this->sut->writeTransaction($txn, $chart, $journal); $this->assertEquals(1, $returnedTransaction->getId()->get()); $this->assertEquals(1226, $chart->getAccount(new Nominal('0000'))->getDebit()->get()); $this->assertEquals(1226, $chart->getAccount(new Nominal('0001'))->getCredit()->get()); }
/** * Write a Transaction to the Journal and update the Chart * * @param SplitTransaction $txn * @param Chart $chart * @param Journal $journal * * @return SplitTransaction Transaction with txn Id set * @throws AccountsException */ public function writeTransaction(SplitTransaction $txn, Chart $chart, Journal $journal) { return FFor::create()->txn(function () use($journal, $txn) { return $journal->write($txn); })->chart(function ($txn) use($chart) { $chart->getAccount($txn->getDrAc()[0])->debit($txn->getAmount()); $chart->getAccount($txn->getCrAc()[0])->credit($txn->getAmount()); })->fyield('txn'); }
/** * Send a chart to storage * * @param Chart $chart * @return bool */ public function send(Chart $chart) { return file_put_contents($this->normalizeName($chart->getName()), serialize($chart)) > 0; }