public function create($entries = array(), $tags = array(), $comment = null, $parentId = null) { // check integrity if (!$this->checkIntegritySum($entries)) { // todo: throw error } $transaction = new Transaction(); $transaction->setComment(null); foreach ($entries as $elem) { $account = $this->em->getRepository('ElcwebAccountingBundle:Account')->findOneBySlug($elem['slug']); if (!$account) { // todo: throw error } $entry = new Entry(); $entry->setAccount($account); $entry->setAmount($elem['amount']); if (array_key_exists('comment', $elem)) { $entry->setComment($elem['comment']); } $transaction->addEntry($entry); } // Tags foreach ($tags as $tag) { $tag = $this->tagManager->loadOrCreateTag($tag); $this->tagManager->addTag($tag, $transaction); } // Parent transaction if ($parentId) { $transaction->setParent($this->get($parentId)); } $this->em->persist($transaction); $this->em->flush(); $this->tagManager->saveTagging($transaction); }
/** * Add entry * * @param Entry $entry * @return Entry */ public function addEntry(Entry $entry) { $entry->setTransaction($this); $this->entries[] = $entry; return $this; }