Esempio n. 1
0
 public function testAnEntryMustHaveCrOrDrType()
 {
     $sut = new Entry(new Nominal('9999'), Factory::create('gbp'), AccountType::CR());
     $this->assertInstanceOf('SAccounts\\Transaction\\Entry', $sut);
     $sut = new Entry(new Nominal('9999'), Factory::create('gbp'), AccountType::DR());
     $this->assertInstanceOf('SAccounts\\Transaction\\Entry', $sut);
 }
 public function testYouCanSetAnOptionalDateOnConstruction()
 {
     $note = new StringType('foo bar');
     $dt = new \DateTime();
     $amount = Factory::create('gbp', 12.26);
     $sut = (new SplitTransaction($dt, $note))->addEntry(new Entry(new Nominal('0000'), $amount, AccountType::DR()))->addEntry(new Entry(new Nominal('1000'), $amount, AccountType::CR()));
     $this->assertEquals($dt, $sut->getDate());
 }
Esempio n. 3
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());
 }
Esempio n. 5
0
 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());
 }
 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());
 }
Esempio n. 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;
 }
 /**
  * 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()));
 }
Esempio n. 9
0
 protected function getEntry($id, $amount, $type)
 {
     return new Entry(new Nominal($id), Factory::create('gbp', $amount), $type == 'dr' ? AccountType::DR() : AccountType::CR());
 }