public function detailsAction()
 {
     $userId = null;
     $auth = Zend_Auth::getInstance();
     $authAccount = $auth->getStorage()->read();
     if (null != $authAccount) {
         if (null != $authAccount->getId()) {
             $this->view->userlogat = $authAccount;
         }
     }
     $id = (int) $this->getRequest()->getParam('id');
     if ($id) {
         // BEGIN: Find model
         $model = new Default_Model_RecurrentExpenses();
         if ($model->find($id)) {
             $this->view->result = $model;
         }
         $select = $model->getMapper()->getDbTable()->select()->where('NOT deleted')->order(array('created DESC'));
         $result = $model->fetchAll($select);
         // END: Find model
         //START: Adaugare comment
         $form_comments = new Default_Form_Comments();
         $form_comments->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/comments.phtml'))));
         $this->view->plugin_form_comments = $form_comments;
         if ($this->getRequest()->isPost()) {
             $model = new Default_Model_Comments();
             $action = $this->getRequest()->getPost('action');
             if ($form_comments->isValid($this->getRequest()->getPost())) {
                 $model->setOptions($form_comments->getValues());
                 $model->setIdProject($id);
                 $saved_comment = $model->save();
                 if ($saved_comment) {
                     $admins = Needs_Tools::findAdmins();
                     $adminIds = Needs_Tools::findAdmins('id');
                     foreach ($adminIds as $adminId) {
                         $emailTemplate = new Default_Model_EmailTemplates();
                     }
                     $auth = Zend_Auth::getInstance();
                     $authAccount = $auth->getStorage()->read();
                     if (null != $authAccount) {
                         if (null != $authAccount->getId()) {
                             $user = new Default_Model_Users();
                             $user->find($authAccount->getId());
                         }
                     }
                     $select = $emailTemplate->getMapper()->getDbTable()->select()->where('const = ?', 'adaugare_comentariu_admin')->limit(1);
                     $emailTemplate->fetchRow($select);
                     if (NULL != $emailTemplate->getContent()) {
                         $emailArray = array();
                         $name = $user->name . ' ' . $user->surname;
                         $message = $emailTemplate->getContent();
                         $message = str_replace("{" . "\$" . "name}", $name, $message);
                         $notification = new Default_Model_NotificationMessages();
                         $notification->setIdUser($authAccount->getId());
                         $notification->setIdProject($id);
                         $notification->setSubject($emailTemplate->getSubject());
                         $notification->setMessage($message);
                         if ($idNotification = $notification->save()) {
                             $notify = new Default_Model_NotificationTo();
                             $notify->setIdNotification($idNotification);
                             $notify->setStatus('1');
                             foreach ($adminIds as $adminId) {
                                 $notify->setIdUserTo($adminId);
                                 $notify->save();
                             }
                         } else {
                             $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Notificarile nu au fost salvate cu succes<a href='javascript:;'></a></p></div>");
                         }
                         $emailArray['subject'] = $emailTemplate->getSubject();
                         $emailArray['content'] = $message;
                         $emailArray['toEmail'] = $admins;
                         $emailArray['toName'] = $name;
                         $emailArray['fromEmail'] = EMAIL;
                         $emailArray['fromName'] = FROM_NAME;
                         $emailArray['SMTP_USERNAME'] = SMTP_USERNAME;
                         $emailArray['SMTP_PASSWORD'] = SMTP_PASSWORD;
                         $emailArray['SMTP_PORT'] = SMTP_PORT;
                         $emailArray['SMTP_URL'] = SMTP_URL;
                         Needs_Tools::sendEmail($emailArray);
                     }
                     $this->_flashMessenger->addMessage("<div class='success  canhide'><p>The comment was added successfully!<a href='javascript:;'></a></p></div>");
                 } else {
                     $this->_flashMessenger->addMessage("<div class='failure canhide'><p>The comment was not added successfully!<a href='javascript:;'></a></p></div>");
                 }
                 $this->_redirect(WEBROOT . '/recurrent-expenses/details/id/' . $id);
             }
         }
         //end adaugare comment
         //$modelc = new Default_Model_Comments();
         //			$select = $modelc->getMapper()->getDbTable()->select()
         //			->from(array('c' => 'comment'), array('c.*'))
         //			->where("NOT c.deleted")
         //			->where("c.idParent IS NULL")
         //			->where("c.idProduct=?",$model->getId())
         //			->order(array('c.created DESC'));
         //			$resultc = $modelc->fetchAll($select);
         //
         //			if(NULL != $resultc)
         //			{
         //				$paginator = Zend_Paginator::factory($resultc);
         //				$paginator->setItemCountPerPage(25);
         //				$paginator->setCurrentPageNumber($this->_getParam('page'));
         //				$paginator->setPageRange(5);
         //				$this->view->resultc = $paginator;
         //				$this->view->itemCountPerPage = $paginator->getItemCountPerPage();
         //				$this->view->totalItemCount = $paginator->getTotalItemCount();
         //
         //				Zend_Paginator::setDefaultScrollingStyle('Sliding');
         //				Zend_View_Helper_PaginationControl::setDefaultViewPartial('_pagination.phtml');
         //			}
     }
 }
Beispiel #2
0
 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;
 }