public function indexAction()
 {
     $this->_helper->getHelper('layout')->disableLayout();
     $creditnoteid = $this->_getParam('creditnoteid', 0);
     $locale = Zend_Registry::get('Zend_Locale');
     //Get creditnote
     $creditnoteDb = new Sales_Model_DbTable_Creditnote();
     $creditnote = $creditnoteDb->getCreditnote($creditnoteid);
     //Get positions
     $positions = $this->getPositions($creditnoteid);
     //Get units of measurements
     $uoms = $this->_helper->Uom->getUoms();
     $uoms = array_combine($uoms, $uoms);
     //Get tax rates
     $taxRates = $this->_helper->TaxRate->getTaxRates($locale);
     $forms = array();
     $orderings = array();
     foreach ($positions as $position) {
         $orderings[$position->ordering] = $position->ordering;
     }
     foreach ($positions as $position) {
         $position->total = $this->_currency->toCurrency($position->price * $position->quantity);
         $position->price = $this->_currency->toCurrency($position->price);
         $position->quantity = Zend_Locale_Format::toNumber($position->quantity, array('precision' => 2, 'locale' => $locale));
         $form = new Sales_Form_Creditnotepos();
         $forms[$position->id] = $form->populate($position->toArray());
         $forms[$position->id]->uom->addMultiOptions($uoms);
         $forms[$position->id]->taxrate->addMultiOptions($taxRates);
         $forms[$position->id]->ordering->addMultiOptions($orderings);
     }
     $creditnote['subtotal'] = $this->_currency->toCurrency($creditnote['subtotal']);
     $creditnote['taxes'] = $this->_currency->toCurrency($creditnote['taxes']);
     $creditnote['total'] = $this->_currency->toCurrency($creditnote['total']);
     $this->view->forms = $forms;
     $this->view->creditnote = $creditnote;
     $this->view->toolbar = new Sales_Form_ToolbarPositions();
 }
 public function lockAction()
 {
     header('Content-type: application/json');
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->getHelper('layout')->disableLayout();
     $id = $this->_getParam('id', 0);
     $creditnoteDb = new Sales_Model_DbTable_Creditnote();
     $creditnote = $creditnoteDb->getCreditnote($id);
     if ($this->isLocked($creditnote['locked'], $creditnote['lockedtime'])) {
         $userDb = new Users_Model_DbTable_User();
         $user = $userDb->getUser($creditnote['locked']);
         echo Zend_Json::encode(array('message' => $this->view->translate('MESSAGES_ACCESS_DENIED_%1$s', $user['name'])));
     } else {
         $creditnoteDb->lock($id, $this->_user['id'], $this->_date);
     }
 }