public function testGetDifference() { $bank = new Account('1920', 'T', 'Bank'); $income = new Account('3000', 'I', 'Income'); //A balanced verification $trans = array(new Transaction($bank, new Amount('100')), new Transaction($bank, new Amount('200')), new Transaction($income, new Amount('-300'))); $v = new Verification('test'); foreach ($trans as $t) { $v->addTransaction($t); } $this->assertEquals((string) new Amount('0'), (string) $v->getDifference()); // A negaitve verification $trans = array(new Transaction($bank, new Amount('100')), new Transaction($income, new Amount('-300'))); $v = new Verification('test'); foreach ($trans as $t) { $v->addTransaction($t); } $this->assertEquals((string) new Amount('-200'), (string) $v->getDifference()); // A positive verification $trans = array(new Transaction($bank, new Amount('200')), new Transaction($income, new Amount('-100'))); $v = new Verification('test'); foreach ($trans as $t) { $v->addTransaction($t); } $this->assertEquals((string) new Amount('100'), (string) $v->getDifference()); }
public function testClear() { $sie = new SIE(); $v = new Verification('testver'); $v->addTransaction(new Transaction(new Account('1920', 'T', 'Bank'), new Amount('100', 2))); $v->addTransaction(new Transaction(new Account('3000', 'I', 'Income'), new Amount('-100', 2))); $sie->addVerification($v); $sie->clear(); $this->assertEquals(0, preg_match('/#VER/', $sie->generate())); }
/** * Create verification from template * * @param ChartOfAccounts $chart * @return Verification * @throws UnexpectedValueException If any key is NOT substituted */ public function buildVerification(ChartOfAccounts $chart) { if (!$this->ready($key)) { throw new UnexpectedValueException("Unable to substitute template key <{$key}>"); } // Build verification $ver = new Verification($this->getText()); foreach ($this->getTransactions() as $arTransData) { list($number, $amount) = $arTransData; // Ignore 0 amount transactions if (0 != floatval($amount)) { $ver->addTransaction(new Transaction($chart->getAccount($number), new Amount($amount))); } } return $ver; }