コード例 #1
0
 public function testIsBalanced()
 {
     $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->assertTrue($v->isBalanced());
     // A unbalanced 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->assertFalse($v->isBalanced());
 }
コード例 #2
0
ファイル: SIE.php プロジェクト: apikck/accounting
 /**
  * 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;
 }