function cronjob($runHours = 'month') { $updatedRE = false; //Get Time $now = date('Y-m-d'); //data de azi //Convert Time $model = new Default_Model_RecurrentExpenses(); $select = $model->getMapper()->getDbTable()->select()->where('NOT `deleted`'); $result = $model->fetchAll($select); if ($result) { foreach ($result as $values) { $date = $values->getDatePaid() ? $values->getDatePaid() : $values->getDate(); //1 mai 2014 $day = date('d', strtotime($date)); $feb = date('L', strtotime($date)) ? 29 : 28; //an bisect $days = array(0, 31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31); //nr zile pe luna //$month=array(1,2,3,4,5,6,7,8,9,10,11,12); $newdate = strtotime('+' . $days[date('n', strtotime($date))] . ' days', strtotime($date)); if ($day < 29 && $day > 1) { $newdate = date('Y-m', $newdate) . "-{$day}"; } else { if (date('n', strtotime($date)) == 1) { //january if ($feb == 29) { $newdate = date('Y-02') . "-" . ($day == 1 ? '01' : '29'); } else { $newdate = date('Y-02') . "-" . ($day == 1 ? '01' : '28'); } } else { if ($days[date('n', strtotime($date))] > $days[date('n', strtotime($date)) + 1] && $day > 1) { $newdate = date('Y-m-d', strtotime('+' . $days[date('n', strtotime($date)) + 1] . ' days', strtotime($date))); } else { $newdate = date('Y-m-d', $newdate); } } //$newdate=date ( 'Y-m-d' , $newdate ); } if ($newdate <= date('Y-m-d')) { $model->find($values->getId()); $model->setDatePaid($newdate); if ($model->save()) { $modelExpenses = new Default_Model_Expenses(); $modelExpenses->setIdMember($model->getIdMember()); $modelExpenses->setName($model->getName()); $modelExpenses->setPrice($model->getPrice()); $modelExpenses->setType($model->getType()); $modelExpenses->setDate($model->getDatePaid()); if ($expenseId = $modelExpenses->save()) { $productGroups = new Default_Model_ProductGroups(); $select = $productGroups->getMapper()->getDbTable()->select()->where('idProduct=?', $model->getId())->where('repeated=?', 1); $result = $productGroups->fetchRow($select); if (NULL != $result) { $idGroup = $result->getIdGroup(); $productGroups->setIdProduct($expenseId); $productGroups->setIdGroup($idGroup); $productGroups->setId(''); $productGroups->setRepeated(0); $productGroups->save(); } } $updatedRE = true; } } } } return $updatedRE; }
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 EXPENSES $conditions['pagination'] = true; $expenses = new Default_Model_RecurrentExpenses(); $select = $expenses->getMapper()->getDbTable()->select()->from(array('p' => 'recurrent_expenses'), array('p.id', 'p.name', 'p.price', 'p.date', 'p.created', 'p.deleted'))->where('p.type=?', 0)->where('NOT p.deleted')->where('idMember=?', Zend_Registry::get('user')->getId()); if (!empty($params['nameSearch'])) { $select->where('p.name LIKE ?', '%' . $params['nameSearch'] . '%'); } if (!empty($params['idGroupSearch'])) { $select->where('p.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')); $resultExpense = Needs_Tools::showRecurrentExpensesDashboardbyDate(!empty($params['fromDate']) ? $params['fromDate'] : date('Y-m-01'), !empty($params['toDate']) ? $params['toDate'] : date('Y-m-d')); $this->view->resultExpense = $resultExpense; //END:SELECT PROJECTS $form = new Default_Form_RecurrentExpenses(); $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/recurrent-expenses/add-expense.phtml')))); $this->view->form = $form; if ($this->getRequest()->isPost() && $this->getRequest()->getParam('control') == 'addExpense') { if ($form->isValid($this->getRequest()->getPost())) { $post = $this->getRequest()->getPost(); $model = new Default_Model_RecurrentExpenses(); $model->setOptions($form->getValues()); $model->setDate(date("Y-m-d", strtotime($post["date"]))); $model->setType('0'); $idGroup = $this->getRequest()->getParam('idGroup'); $model->setIdGroup($idGroup); 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->setIdMessage($expenseId); $gallery->setIdUser(1); $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(1); $modelGroup->save(); //mesaj de succes $this->_flashMessenger->addMessage("<div class='success canhide'><p>Recurrent expense was added successfully<a href='javascript:;'></a><p></div>"); } else { //mesaj de eroare $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Recurrent expense was not added<a href='javascript:;'></a><p></div>"); } //redirect $this->_redirect(WEBROOT . 'recurrent-expenses'); } } $formsearch = new Default_Form_RecurrentExpenseSearch(); $formsearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/recurrent-expenses/expense-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(); }
public function saveRecurrentexpenseincomePriceAction() { $return = ''; $id = (int) $this->getRequest()->getParam('id'); if ($id) { $post = $this->getRequest()->getPost(); $model = new Default_Model_RecurrentExpenses(); $model->find($id); $model->setPrice($post['update_value']); if ($model->save()) { $return = $post['update_value']; } else { $return = "Error modifying value"; } } echo number_format($return, 2); }