/** * Calculate total gross sales between 2 dates * * @param (date) $dateFrom - format: 'YYYY-mm-dd'; * @param (date) $dateTo - format: 'YYYY-mm-dd'; * @param int $shopId * @return int - total gross sales between 2 dates */ public static function calculateTotalWeekGrossSales($dateFrom, $dateTo, $shopId) { $model = new Default_Model_DailySales(); $selectAll = $model->getMapper()->getDbTable()->select()->from(array('ds' => 'daily_sales'), array('id' => 'SUM(ds.grossSales)'))->where('ds.date >= ?', $dateFrom)->where('ds.date <= ?', $dateTo)->where('ds.idShop = ?', $shopId); $model->fetchRow($selectAll); return $model->getId(); }
public function indexAction() { $date = $this->getRequest()->getParam('date') ? $this->getRequest()->getParam('date') : date('Y-m-d'); $form = new Default_Form_DailySales(); $form->showHistory($date); $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/daily-sales/add.phtml')))); $this->view->form = $form; $errorForm = new Default_Form_DailySalesErrors(); $errorForm->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/daily-sales-errors/add.phtml')))); $this->view->formError = $errorForm; if ($this->getRequest()->isPost()) { $post = $this->getRequest()->getPost(); if (!empty($post['action']) && $post['action'] == 'add') { if ($form->isValid($this->getRequest()->getPost())) { $post = $this->getRequest()->getPost(); $modelSave = new Default_Model_DailySales(); $modelSave->setOptions($form->getValues()); $modelSave->setIdShop(Zend_Registry::get('user')->getShop()->getId()); $modelSave->setOverShortNotification($post['overshort']); if ($this->getRequest()->getParam('date')) { $modelSave->setDate($this->getRequest()->getParam('date')); } else { $modelSave->setDate(date('Y-m-d')); } $arrayGiftNr = array(); $arrayGiftVal = array(); foreach ($post['giftNr'] as $key => $value) { $arrayGiftNr[] = $post['giftNr'][$key]; $arrayGiftVal[] = $post['giftVal'][$key]; } if ($id = $modelSave->save()) { foreach ($arrayGiftNr as $key => $value) { $model = new Default_Model_DailySalesGift(); $model->setIdSale($id); $model->setNumber($arrayGiftNr[$key]); $model->setValue($arrayGiftVal[$key]); $model->save(); } $products = Needs_Tools::getProductsByShop(); $registryNumber = Needs_Tools::getRegistryNrByShop(); foreach ($products as $value) { $model = new Default_Model_DailySalesProducts(); $model->setIdSale($id); $model->setIdShop(Zend_Registry::get('user')->getShop()->getId()); $model->setIdProduct($value->getId()); $model->setRegister1($post['register1_' . $value->getId()]); if ($registryNumber == 2) { $model->setRegister2($post['register2_' . $value->getId()]); } $model->save(); } //mesaj de succes $this->_flashMessenger->addMessage("<div class='success canhide'><p>Report was added successfully<a href='javascript:;'></a><p></div>"); } else { //mesaj de eroare $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Report was not added<a href='javascript:;'></a><p></div>"); } $this->_redirect(WEBROOT . 'daily-sales/index/date/' . $modelSave->getDate()); } } elseif ($post['action'] && $post['action'] == 'errorReport') { if ($errorForm->isValid($this->getRequest()->getPost())) { $post = $this->getRequest()->getPost(); $model = new Default_Model_DailySalesError(); $model->setOptions($errorForm->getValues()); $date = $post['year'] . '-' . $post['month'] . '-' . $post['day']; $shopId = Zend_Registry::get('user')->getShop()->getId(); $userId = Zend_Registry::get('user')->getId(); $saleId = Needs_Tools::getSaleIdByDateAndShopId($date, $shopId); if ($saleId) { $model->setIdSale($saleId->getId()); $model->setIdUser($userId); $model->setDate($date); if ($id = $model->save()) { //mesaj de succes $this->_flashMessenger->addMessage("<div class='success canhide'><p>The error report was successfully sent !<a href='javascript:;'></a><p></div>"); } else { //mesaj de eroare $this->_flashMessenger->addMessage("<div class='failure canhide'><p>There was an error while sending the report. Please try again !<a href='javascript:;'></a><p></div>"); } } else { $strdate = strtotime($date); $newDate = date('m-d-Y', $strdate); $this->_flashMessenger->addMessage("<div class='failure canhide'><p>No report registered for ' {$newDate} ' ! Please select a different date !<a href='javascript:;'></a><p></div>"); } $this->_redirect(WEBROOT . 'daily-sales/index/date/' . $date); } } } }
/** * * @return number of reports that have not been audited */ public function getTotalNoAudit() { $model = new Default_Model_DailySales(); $select = $model->getMapper()->getDbTable()->select()->from(array('d' => 'daily_sales'), array('id' => 'COUNT(d.id)'))->where('audited = ?', 0)->setIntegrityCheck(false); $model->fetchRow($select); return $model->getId(); }
public function statusAuditAction() { $dailySales = new Default_Model_DailySales(); $select = $dailySales->getMapper()->getDbTable()->select(); $select->from(array('d' => 'daily_sales'), array('d.idShop', 'd.date', 'd.id'))->where('audited = ?', 0)->order('date DESC'); $result = $dailySales->fetchAll($select); $this->view->totalNr = Needs_Tools::getTotalNoAudit(); if (NULL != $result) { $paginator = Zend_Paginator::factory($result); $paginator->setItemCountPerPage(10); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setPageRange(5); $this->view->result = $paginator; $this->view->itemCountPerPage = $paginator->getItemCountPerPage(); $this->view->totalItemCount = $paginator->getTotalItemCount(); Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial('_pagination.phtml'); } }