Exemplo n.º 1
0
 /**
  * @param TransactionJournal $entry
  */
 public function addOrCreateExpense(TransactionJournal $entry)
 {
     // add each account individually:
     $destinations = TransactionJournal::destinationTransactionList($entry);
     foreach ($destinations as $transaction) {
         $amount = strval($transaction->amount);
         $account = $transaction->account;
         if (bccomp('0', $amount) === -1) {
             $amount = bcmul($amount, '-1');
         }
         $object = new stdClass();
         $object->amount = $amount;
         $object->name = $account->name;
         $object->count = 1;
         $object->id = $account->id;
         // overrule some properties:
         if ($this->expenses->has($account->id)) {
             $object = $this->expenses->get($account->id);
             $object->amount = bcadd($object->amount, $amount);
             $object->count++;
         }
         $this->expenses->put($account->id, $object);
     }
 }