Beispiel #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();
 }
 public function testCanGetValuesAsClassesUsingStaticMethods()
 {
     $this->assertInstanceOf('SAccounts\\AccountType', AccountType::REAL());
     $this->assertInstanceOf('SAccounts\\AccountType', AccountType::CR());
     $this->assertInstanceOf('SAccounts\\AccountType', AccountType::DR());
     $this->assertInstanceOf('SAccounts\\AccountType', AccountType::ASSET());
     $this->assertInstanceOf('SAccounts\\AccountType', AccountType::BANK());
     $this->assertInstanceOf('SAccounts\\AccountType', AccountType::CUSTOMER());
     $this->assertInstanceOf('SAccounts\\AccountType', AccountType::EXPENSE());
     $this->assertInstanceOf('SAccounts\\AccountType', AccountType::INCOME());
     $this->assertInstanceOf('SAccounts\\AccountType', AccountType::LIABILITY());
     $this->assertInstanceOf('SAccounts\\AccountType', AccountType::EQUITY());
     $this->assertInstanceOf('SAccounts\\AccountType', AccountType::SUPPLIER());
 }
 public function accountTypesThatHaveBalance()
 {
     return [[AccountType::DR()], [AccountType::CR()], [AccountType::ASSET()], [AccountType::LIABILITY()], [AccountType::BANK()], [AccountType::CUSTOMER()], [AccountType::EQUITY()], [AccountType::EXPENSE()], [AccountType::INCOME()], [AccountType::SUPPLIER()]];
 }
 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());
 }
 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());
 }
Beispiel #6
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;
 }
 public function testYouCanGetTheTypeOfAnEntry()
 {
     $this->assertEquals(AccountType::CR(), (new Entry(new Nominal('9999'), Factory::create('gbp', 1), AccountType::CR()))->getType());
 }
 /**
  * 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()));
 }
 protected function getEntry($id, $amount, $type)
 {
     return new Entry(new Nominal($id), Factory::create('gbp', $amount), $type == 'dr' ? AccountType::DR() : AccountType::CR());
 }