Example #1
0
 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);
             }
         }
     }
 }
Example #2
0
File: Tools.php Project: valizr/MMA
 /**
  * Fetch a Daily Sales Product by SalesId and ProductId
  * 
  * @param int $idSales
  * @param int $productId
  * 
  * @return object $model -  Default_Model_DailySalesProducts
  */
 public static function fetchDailySalesProductbySalesId($idSales, $productId)
 {
     $model = new Default_Model_DailySalesProducts();
     $select = $model->getMapper()->getDbTable()->select()->where('idProduct = ?', $productId)->where('idSale = ?', $idSales);
     $model->fetchRow($select);
     return $model;
 }