public function saveAction() { $this->_helper->getHelper('layout')->disableLayout(); $this->_helper->viewRenderer->setRender('pdf'); $id = $this->_getParam('id', 0); $locale = Zend_Registry::get('Zend_Locale'); $creditnoteDb = new Sales_Model_DbTable_Creditnote(); $creditnote = $creditnoteDb->getCreditnote($id); if ($creditnote['templateid']) { $templateDb = new Application_Model_DbTable_Template(); $template = $templateDb->getTemplate($creditnote['templateid']); if ($template['filename']) { $this->_helper->viewRenderer->setRender($template['filename']); } $this->view->template = $template; } $positions = $this->getPositions($id); if (!$creditnote['creditnoteid']) { //Get latest creditnote Id $latestCreditnote = $creditnoteDb->fetchRow($creditnoteDb->select()->where('clientid = ?', $this->_user['clientid'])->order('creditnoteid DESC')->limit(1)); //Set new creditnote Id $newCreditnoteId = $latestCreditnote['creditnoteid'] + 1; $creditnoteDb->saveCreditnote($id, $newCreditnoteId, $this->_date, 105, $this->_date, $this->_user['id']); $creditnote = $creditnoteDb->getCreditnote($id); //Update item data if (count($positions)) { $itemsDb = new Items_Model_DbTable_Item(); foreach ($positions as $position) { $item = $itemsDb->fetchRow($itemsDb->select()->where('sku = ?', $position['sku'])); if ($item) { $quantity = $item->quantity + $position->quantity; $itemsDb->quantityItem($item->id, $quantity, $this->_date, $this->_user['id']); } } } } if (count($positions)) { foreach ($positions as $position) { $precision = floor($position->quantity) == $position->quantity ? 0 : 2; $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' => $precision, 'locale' => Zend_Registry::get('Zend_Locale'))); } $creditnote['taxes'] = $this->_currency->toCurrency($creditnote['taxes']); $creditnote['subtotal'] = $this->_currency->toCurrency($creditnote['subtotal']); $creditnote['total'] = $this->_currency->toCurrency($creditnote['total']); if ($creditnote['taxfree']) { $creditnote['taxrate'] = Zend_Locale_Format::toNumber(0, array('precision' => 2, 'locale' => $locale)); } else { $creditnote['taxrate'] = Zend_Locale_Format::toNumber($positions[0]->taxrate, array('precision' => 2, 'locale' => $locale)); } } $this->view->creditnote = $creditnote; $this->view->positions = $positions; $this->view->footers = $this->_helper->Footer->getFooters($creditnote['templateid'], $this->_user['clientid']); }
public function applyAction() { $this->_helper->getHelper('layout')->setLayout('plain'); $request = $this->getRequest(); $locale = Zend_Registry::get('Zend_Locale'); $itemid = $this->_getParam('itemid', 0); $quoteid = $this->_getParam('quoteid', 0); $form = new Items_Form_Item(); if ($request->isPost()) { $this->_helper->viewRenderer->setNoRender(); $this->_helper->getHelper('layout')->disableLayout(); $data = array(); if ($itemid && $quoteid) { $item = new Items_Model_DbTable_Item(); $item = $item->getItem($itemid); $data['quoteid'] = $quoteid; $data['itemid'] = $itemid; $data['sku'] = $item['sku']; $data['title'] = $item['title']; $data['image'] = $item['image']; $data['description'] = $item['description']; $data['price'] = $item['price']; $data['taxrate'] = $item['taxid'] ? $this->_helper->TaxRate->getTaxRate($item['taxid']) : 0; $data['quantity'] = 1; $data['total'] = $data['price'] * $data['quantity']; $data['uom'] = $item['uomid'] ? $this->_helper->Uom->getUom($item['uomid']) : ''; $data['ordering'] = $this->getLatestOrdering($quoteid) + 1; $data['created'] = $this->_date; $data['createdby'] = $this->_user['id']; $data['clientid'] = $this->_user['clientid']; $position = new Sales_Model_DbTable_Quotepos(); $position->addPosition($data); //Calculate $this->_helper->Calculate($quoteid, $this->_currency, $this->_date, $this->_user['id']); } else { $form->populate($request->getPost()); } } else { if ($itemid > 0) { $item = new Items_Model_DbTable_Item(); $form->populate($item->getItem($itemid)); } } $this->view->form = $form; }
protected function search($params, $categories) { $itemsDb = new Items_Model_DbTable_Item(); $columns = array('title', 'sku', 'description'); $query = ''; if ($params['keyword']) { $query = $this->_helper->Query->getQueryKeyword($query, $params['keyword'], $columns); } if ($params['catid']) { $query = $this->_helper->Query->getQueryCategory($query, $params['catid'], $categories); } $items = $itemsDb->fetchAll($itemsDb->select()->where($query ? $query : 1)->order($params['order'] . ' ' . $params['sort'])->limit($params['limit'])); foreach ($items as $item) { if (strlen($item->description) > 43) { $item->description = substr($item->description, 0, 40) . '...'; } $item->cost = $this->_currency->toCurrency($item->cost); $item->price = $this->_currency->toCurrency($item->price); } return $items; }