public function indexAction()
 {
     $this->_helper->getHelper('layout')->disableLayout();
     $purchaseorderid = $this->_getParam('purchaseorderid', 0);
     $locale = Zend_Registry::get('Zend_Locale');
     //Get purchaseorder
     $purchaseorderDb = new Purchases_Model_DbTable_Purchaseorder();
     $purchaseorder = $purchaseorderDb->getPurchaseorder($purchaseorderid);
     //Get positions
     $positions = $this->getPositions($purchaseorderid);
     //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 Purchases_Form_Purchaseorderpos();
         $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);
     }
     $purchaseorder['subtotal'] = $this->_currency->toCurrency($purchaseorder['subtotal']);
     $purchaseorder['taxes'] = $this->_currency->toCurrency($purchaseorder['taxes']);
     $purchaseorder['total'] = $this->_currency->toCurrency($purchaseorder['total']);
     $this->view->forms = $forms;
     $this->view->purchaseorder = $purchaseorder;
     $this->view->toolbar = new Purchases_Form_ToolbarPositions();
 }
 public function lockAction()
 {
     header('Content-type: application/json');
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->getHelper('layout')->disableLayout();
     $id = $this->_getParam('id', 0);
     $purchaseorderDb = new Purchases_Model_DbTable_Purchaseorder();
     $purchaseorder = $purchaseorderDb->getPurchaseorder($id);
     if ($this->isLocked($purchaseorder['locked'], $purchaseorder['lockedtime'])) {
         $userDb = new Users_Model_DbTable_User();
         $user = $userDb->getUser($purchaseorder['locked']);
         echo Zend_Json::encode(array('message' => $this->view->translate('MESSAGES_ACCESS_DENIED_%1$s', $user['name'])));
     } else {
         $purchaseorderDb->lock($id, $this->_user['id'], $this->_date);
     }
 }