예제 #1
0
 /**
  * @param AccountType $type
  * @return FTry
  */
 protected function checkType(AccountType $type)
 {
     return Match::on($type->getValue())->test(AccountType::CR, function () {
         return FTry::with(AccountType::CR());
     })->test(AccountType::DR, function () {
         return FTry::with(AccountType::DR());
     })->any(function () {
         return FTry::with(new AccountsException(self::ERR_NOTYPE));
     })->value();
 }
예제 #2
0
 /**
  * Create a new Chart
  *
  * @param StringType $chartName
  * @param Organisation $org
  * @param ChartDefinition $def
  *
  * @return Chart
  */
 public function createChart(StringType $chartName, Organisation $org, ChartDefinition $def)
 {
     return FFor::create()->dom(function () use($def) {
         return $def->getDefinition();
     })->xpath(function ($dom) {
         return new \DOMXPath($dom);
     })->root(function ($xpath) {
         return $xpath->query('/chart/account')->item(0);
     })->tree(function () {
         return new Node();
     })->chart(function ($tree) use($chartName, $org) {
         return new Chart($chartName, $org, $tree);
     })->build(function ($root, $tree, $chart) {
         $this->buildTree($tree, $root, $chart, AccountType::toArray());
     })->fyield('chart');
 }
예제 #3
0
 public function testYouCanGetTheAccountName()
 {
     $this->sut = new Account($this->chart, new Nominal('9999'), AccountType::DUMMY(), new StringType('foo'));
     $this->assertEquals(new StringType('foo'), $this->sut->getName());
 }
예제 #4
0
 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());
 }
예제 #5
0
 /**
  * @expectedException SAccounts\AccountsException
  */
 public function testGetABalanceWithInvalidAccountTypeWillThrowException()
 {
     $ac = new AccountType(AccountType::DUMMY);
     $ac->balance(Factory::create('gbp'), Factory::create('gbp'));
 }
 public function testASplitTransactionIsSimpleIfItHasOneDrAndOneCrEntry()
 {
     $this->assertTrue($this->sut->isSimple());
     $amount = Factory::create('gbp', 0.1);
     $this->sut->addEntry(new Entry(new Nominal('2000'), $amount, AccountType::CR()));
     $this->assertFalse($this->sut->isSimple());
 }
예제 #7
0
 /**
  * Create transaction from dom element
  *
  * @param \DOMElement $txn
  * @param $crcyCode
  * @param \DOMXPath
  *
  * @return SplitTransaction
  */
 protected function createTransactionFromElement(\DOMElement $txn, $crcyCode, \DOMXPath $xpath)
 {
     $drNodes = $xpath->query("./split[@type='DR']", $txn);
     $transaction = (new SplitTransaction(new \DateTime($txn->attributes->getNamedItem('date')->nodeValue), new StringType($txn->attributes->getNamedItem('note')->nodeValue)))->setId(new IntType($txn->attributes->getNamedItem('id')->nodeValue));
     foreach ($drNodes as $drNode) {
         $transaction->addEntry(new Entry(new Nominal($drNode->attributes->getNamedItem('nominal')->nodeValue), CurrencyFactory::create($crcyCode)->set(intval($drNode->attributes->getNamedItem('amount')->nodeValue)), AccountType::DR()));
     }
     $crNodes = $xpath->query("./split[@type='CR']", $txn);
     foreach ($crNodes as $crNode) {
         $transaction->addEntry(new Entry(new Nominal($crNode->attributes->getNamedItem('nominal')->nodeValue), CurrencyFactory::create($crcyCode)->set(intval($crNode->attributes->getNamedItem('amount')->nodeValue)), AccountType::CR()));
     }
     return $transaction;
 }
예제 #8
0
 /**
  * Get the account balance
  *
  * Returns the current account balance.
  *
  * @return Currency
  */
 public function getBalance()
 {
     return $this->type->balance($this->acDr, $this->acCr);
 }
예제 #9
0
 public function testYouCanGetTheTypeOfAnEntry()
 {
     $this->assertEquals(AccountType::CR(), (new Entry(new Nominal('9999'), Factory::create('gbp', 1), AccountType::CR()))->getType());
 }
예제 #10
0
 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());
 }
 /**
  * Constructor
  *
  * @param Nominal $drAc Account to debit
  * @param Nominal $crAc Account to credit
  * @param Currency $amount Transaction amount
  * @param StringType $note Defaults to '' if not set
  * @param \DateTime $date Defaults to today if not set
  */
 public function __construct(Nominal $drAc, Nominal $crAc, Currency $amount, StringType $note = null, \DateTime $date = null)
 {
     parent::__construct($date, $note);
     $this->addEntry(new Entry($drAc, $amount, AccountType::DR()));
     $this->addEntry(new Entry($crAc, $amount, AccountType::CR()));
 }
예제 #12
0
 protected function getEntry($id, $amount, $type)
 {
     return new Entry(new Nominal($id), Factory::create('gbp', $amount), $type == 'dr' ? AccountType::DR() : AccountType::CR());
 }