Пример #1
0
 public function indexAction()
 {
     $auth = Zend_Auth::getInstance();
     $authAccount = $auth->getStorage()->read();
     $params = array();
     $conditions = array();
     if ($this->getRequest()->getParam('nameSearch')) {
         $params['nameSearch'] = $this->getRequest()->getParam('nameSearch');
     }
     if ($this->getRequest()->getParam('idGroupSearch')) {
         $params['idGroupSearch'] = $this->getRequest()->getParam('idGroupSearch');
     }
     if ($this->getRequest()->getParam('fromDate')) {
         $params['fromDate'] = date("Y-m-d", strtotime($this->getRequest()->getParam('fromDate')));
     }
     if ($this->getRequest()->getParam('toDate')) {
         $params['toDate'] = date("Y-m-d", strtotime($this->getRequest()->getParam('toDate')));
     }
     //BEGIN:SELECT INCOME
     $conditions['pagination'] = true;
     $expenses = new Default_Model_Expenses();
     $select = $expenses->getMapper()->getDbTable()->select()->from(array('p' => 'expenses'), array('p.id', 'p.name', 'p.price', 'p.date', 'p.created', 'p.deleted'))->where('NOT p.deleted')->where('p.type=?', 1)->where('idMember=?', Zend_Registry::get('user')->getId());
     if (!empty($params['nameSearch'])) {
         $select->where('p.name LIKE ?', '%' . $params['nameSearch'] . '%');
     }
     if (!empty($params['idGroupSearch'])) {
         $select->joinLeft(array('pg' => 'product_groups'), 'p.`id` = pg.`idProduct`', array('gid' => 'pg.idGroup'))->where('pg.idGroup = ?', $params['idGroupSearch']);
     }
     if (!empty($params['fromDate'])) {
         $select->where('p.date >= ?', $params['fromDate']);
     }
     if (!empty($params['toDate'])) {
         $select->where('p.date <= ?', $params['toDate']);
     }
     $select->joinLeft(array('uf' => 'uploaded_files'), 'p.`id` = uf.`idMessage`', array('ufiles' => 'uf.id', 'recurrent' => 'uf.idUser'))->setIntegrityCheck(false);
     $select->order(array('date DESC'));
     $resultIncome = Needs_Tools::showIncomeDashboardbyDate(!empty($params['fromDate']) ? $params['fromDate'] : date('Y-m-01'), !empty($params['toDate']) ? $params['toDate'] : date('Y-m-d'), !empty($params['idGroupSearch']) ? $params['idGroupSearch'] : '');
     $this->view->resultIncome = $resultIncome;
     //END:SELECT INCOME
     $form = new Default_Form_Income();
     $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/income/add-income.phtml'))));
     $this->view->form = $form;
     if ($this->getRequest()->isPost() && $this->getRequest()->getParam('control') == 'addIncome') {
         if ($form->isValid($this->getRequest()->getPost())) {
             $post = $this->getRequest()->getPost();
             $model = new Default_Model_Expenses();
             $model->setOptions($form->getValues());
             $model->setDate(date("Y-m-d", strtotime($post["date"])));
             $model->setType('1');
             if ($expenseId = $model->save()) {
                 if (!empty($post['galleryFiles']) && is_array($post['galleryFiles'])) {
                     foreach ($post['galleryFiles'] as $valuesGallery) {
                         $tmpFiles = new Default_Model_TempFiles();
                         if ($tmpFiles->find($valuesGallery)) {
                             $post = $this->getRequest()->getPost();
                             $gallery = new Default_Model_FileManager();
                             $gallery->setOptions($form->getValues());
                             $gallery->setType($tmpFiles->getFileType());
                             $gallery->setSize($tmpFiles->getFileSize());
                             $gallery->setModule('sharedfiles');
                             $gallery->setIdUser(0);
                             //0 - means the image is for non recurrent income
                             $gallery->setIdMessage($expenseId);
                             $gallery->setName($tmpFiles->getFileName());
                             $savedId = $gallery->save();
                             if ($savedId) {
                                 $shared = new Default_Model_SharedList();
                                 $shared->setIdUser(Zend_Registry::get('user')->getId());
                                 $shared->setIdFile($savedId);
                                 $shared->save();
                             }
                             //copy picture and crop
                             $tempFile = APPLICATION_PUBLIC_PATH . '/media/temps/' . $tmpFiles->getFileName();
                             $targetFile = APPLICATION_PUBLIC_PATH . '/media/files/' . $tmpFiles->getFileName();
                             @copy($tempFile, $targetFile);
                             @unlink($tempFile);
                             $tmpFiles->delete();
                         }
                     }
                     //END:SAVE ATTACHMENTS
                 }
                 $idGroup = $this->getRequest()->getParam('idGroup');
                 $modelGroup = new Default_Model_ProductGroups();
                 $modelGroup->setIdProduct($expenseId);
                 $modelGroup->setIdGroup($idGroup);
                 $modelGroup->setRepeated(0);
                 $modelGroup->save();
                 //mesaj de succes
                 $this->_flashMessenger->addMessage("<div class='success  canhide'><p>Income was added successfully<a href='javascript:;'></a><p></div>");
             } else {
                 //mesaj de eroare
                 $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Income was not added<a href='javascript:;'></a><p></div>");
             }
             //redirect
             $this->_redirect(WEBROOT . 'income');
         }
     }
     $formsearch = new Default_Form_IncomeSearch();
     $formsearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/income/income-search.phtml'))));
     $this->view->formsearch = $formsearch;
     $this->view->search = $params;
     // pagination
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
     $paginator->setItemCountPerPage(15);
     $paginator->setCurrentPageNumber($this->_getParam('page'));
     $paginator->setPageRange(5);
     Zend_Paginator::setDefaultScrollingStyle('Sliding');
     Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $params));
     $this->view->result = $paginator;
     $this->view->itemCountPerPage = $paginator->getItemCountPerPage();
     $this->view->totalItemCount = $paginator->getTotalItemCount();
 }