protected function processForm(sfWebRequest $request, sfForm $form) { $requestparam = $request->getParameter('accountentry'); $account = AccountTable::fetchById($requestparam['account_id']); $qty = $requestparam['qty']; $date = $requestparam['date']['year'] . "-" . $requestparam['date']['month'] . "-" . $requestparam['date']['day']; //$ref_class=$requestparam['ref_class']; //$ref_id=$requestparam['ref_id']; $type = $requestparam['type'] != "" ? $requestparam['type'] : 'Adjustment'; //$priority=0; $description = $requestparam['description']; if ($qty == 0) { $this->redirect('home/error?msg="Invalid Qty"'); } $accountentry = $account->addEntry($date, $qty, null, null, $type, $description); $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.'; $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $accountentry))); $this->getUser()->setFlash('notice', $notice); $this->redirect('account/view?id=' . $accountentry->getaccountId()); } else { if ($form['qty']->getError()) { $this->redirect('home/error?msg="Invalid Qty: ' . $qty . '"'); } if ($form['date']->getError()) { $this->redirect('home/error?msg="Invalid Date: ' . $date . '"'); } //$this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false); } }
public function getAccountEntry($settingname, $create = false, $qty = 0, $description = null) { $this->getAccountentriesArray(); $account_id = SettingsTable::fetch($settingname); $entry = $this->accountentriesarray[$account_id]; //if it does not exist, and "create or update" if (!$entry and $create) { $account = AccountTable::fetchById($account_id); $entry = $account->addEntry($this->getDate(), $qty, "Event", $this->getId(), null, $description); } else { if ($create) { $entry->setQty($qty); $entry->setBalance(null); $entry->save(); $entry->getAccount()->calcFromAccountentry($entry); } } return $entry; }