protected function setUp()
 {
     $this->transaction = new SimpleTransaction(new Nominal('0000'), new Nominal('0001'), Factory::create('gbp', 12.26), new StringType('a note'), new \DateTime());
     $this->chart = $this->getMock('SAccounts\\Chart', array(), array(), '', false);
     $this->journalist = $this->getMock('SAccounts\\JournalStorageInterface');
     $this->sut = new Journal(new StringType('Foo Bar'), Factory::create('gbp'), $this->journalist);
 }
 public function testYouCanSetAnOptionalDateOnConstruction()
 {
     $note = new StringType('foo bar');
     $dt = new \DateTime();
     $sut = new SimpleTransaction(new Nominal('0000'), new Nominal('1000'), Factory::create('gbp', 12.26), $note, $dt);
     $this->assertEquals($dt, $sut->getDate());
 }
Beispiel #3
0
 public function __construct(Chart $chart, Nominal $id, AccountType $type, StringType $name)
 {
     $this->chart = $chart;
     $this->id = $id;
     $this->type = $type;
     $this->name = $name;
     $currencyClass = $this->chart->getOrg()->getCurrencyCode()->get();
     $this->acDr = Factory::create($currencyClass);
     $this->acCr = Factory::create($currencyClass);
 }
Beispiel #4
0
 /**
  * Set up the build items that this builder will manage
  * We don't need to do any complicated build routine so can set values here
  */
 protected function setBuildItems()
 {
     $crcy = Factory::create($this->code);
     $refl = new \ReflectionClass($crcy);
     $fmt = $refl->getProperty('displayFormat');
     $fmt->setAccessible(true);
     $locale = $refl->getProperty('locale');
     $locale->setAccessible(true);
     $precision = $refl->getProperty('precision');
     $precision->setAccessible(true);
     $this->buildItems = ['code' => $this->code, 'name' => $crcy->getName()->get(), 'symbol' => $crcy->getSymbol()->get(), 'displayFormat' => $fmt->getValue($crcy)->get(), 'locale' => $locale->getValue($crcy)->get(), 'precision' => $precision->getValue($crcy)->get(), 'value' => $crcy()];
 }
 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());
 }
 /**
  * @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());
 }
 public function testYouCanDeleteAnAccountIfItsBalanceIsZero()
 {
     $ac1 = new Account($this->sut, new Nominal('9998'), AccountType::ASSET(), new StringType('Asset'));
     $this->sut->addAccount($ac1);
     $ac1->debit(Factory::create($this->sut->getOrg()->getCurrencyCode()));
     $this->sut->delAccount($ac1->getId());
     $this->assertFalse($this->sut->hasAccount($ac1->getId()));
     $ac2 = new Account($this->sut, new Nominal('9999'), AccountType::LIABILITY(), new StringType('Asset'));
     $this->sut->addAccount($ac2);
     $ac1->credit(Factory::create($this->sut->getOrg()->getCurrencyCode()));
     $this->sut->delAccount($ac2->getId());
     $this->assertFalse($this->sut->hasAccount($ac2->getId()));
 }
Beispiel #10
0
 /**
  * Create and return a test transaction
  *
  * @param $dr
  * @param $cr
  * @param $amount
  * @param null $note
  *
  * @return Transaction
  */
 protected function createTransaction($dr, $cr, $amount, $note = null)
 {
     $crcy = CurrencyFactory::create('gbp', $amount);
     if (is_null($note)) {
         $txn = new Transaction(new Nominal($dr), new Nominal($cr), $crcy);
     } else {
         $txn = new Transaction(new Nominal($dr), new Nominal($cr), $crcy, new StringType($note));
     }
     return $txn;
 }
Beispiel #11
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;
 }
Beispiel #12
0
 /**
  * @runInSeparateProcess
  * @see http://en.wikipedia.org/wiki/Rombo_language
  */
 public function testCreateWillUseFullLocaleIfLocaleSpecificNameCanBeFound()
 {
     Factory::setLocale('rof');
     $crcy = Factory::create('EUR', 2000);
     $this->assertEquals('€2,000.00', $crcy->display());
     $this->assertEquals('yuro', $crcy->getName()->get());
 }
Beispiel #13
0
 public function testYouCanGetTheTypeOfAnEntry()
 {
     $this->assertEquals(AccountType::CR(), (new Entry(new Nominal('9999'), Factory::create('gbp', 1), AccountType::CR()))->getType());
 }
 public function testYouCanGetOrganisationCurrency()
 {
     $this->assertEquals(Factory::create('gbp'), $this->sut->getCurrency());
 }
 /**
  * Get amount if the account is balanced
  *
  * @return Currency
  * @throw AccountsException
  */
 public function getAmount()
 {
     return Match::create(Option::create($this->entries->checkBalance(), false))->Monad_Option_Some(function () {
         $tot = 0;
         foreach ($this->entries as $entry) {
             $tot += $entry->getAmount()->get();
         }
         //use last entry to grab currency code from
         /** @noinspection PhpUndefinedVariableInspection */
         return CFactory::create($entry->getAmount()->getCode()->get())->set($tot / 2);
     })->Monad_Option_None(function () {
         throw new AccountsException('No amount for unbalanced transaction');
     })->value();
 }
 public function testYouCanFetchAChart()
 {
     $chart = new Chart(new StringType('foo bar'), new Organisation(new IntType(1), new StringType('Foo Org'), Factory::create('gbp')));
     file_put_contents($this->root->url() . '/foo_bar.saccount', serialize($chart));
     $this->assertEquals($chart, $this->sut->fetch(new StringType('foo bar')));
 }
 protected function getEntry($id, $amount, $type)
 {
     return new Entry(new Nominal($id), Factory::create('gbp', $amount), $type == 'dr' ? AccountType::DR() : AccountType::CR());
 }