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())); }
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()); }
/** * Add verification to SIE, verification MUST be balanced * * @param Verification $ver * @throws UnexpectedValueException If $ver is unbalanced * @throws OutOfBoundsException If $ver date is out of bounds * @return SIE Instance for chaining */ public function addVerification(Verification $ver) { // Verify that verification is balanced if (!$ver->isBalanced()) { throw new UnexpectedValueException("Verification <{$ver->getText()}> is not balanced"); } // Verify that verification date matches accounting year if (isset($this->yearStart)) { $verdate = $ver->getDate(); if ($verdate < $this->yearStart || $verdate > $this->yearStop) { $date = $verdate->format('Y-m-d'); throw new OutOfBoundsException("Verification date <{$date}> is out of bounds"); } } // Set names of used accounts foreach ($ver->getAccounts() as $account) { $nr = $account->getNumber(); $this->usedAccounts[$nr] = $account; } // Save verification $this->verifications[] = $ver; return $this; }
/** * 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; }