public static function showIncomeDashboardbyDateCat($from = '', $to = '', $categoryIncome = array(), $timeframe) { $resultInfo = array(); $idUser = Zend_Registry::get('user')->getId(); $expenses = new Default_Model_Expenses(); $diff = abs(strtotime($to) - strtotime($from)); $nr_days = $diff / 86400; if ($nr_days < 7) { $timeframe = 'd'; } //if ($nr_days>40) $timeframe='w'; //if () switch ($timeframe) { case "m": $y1 = date('Y', strtotime($from)); $y2 = date('Y', strtotime($to)); $m1 = date('m', strtotime($from)); //4 $m2 = date('m', strtotime($to)); $nrLuni = ($y2 - $y1) * 12 + ($m2 - $m1) + 1; //13 $feb = date('L', strtotime($from)) ? 29 : 28; //an bisect $daysOfMonth = array(0, 31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31); //nr zile pe luna $months = array(); $firstMonth = 1; for ($i = 1; $i <= $nrLuni; $i++) { if ($firstMonth == 1) { $startDay = date('d', strtotime($from)); } else { $startDay = '01'; } if ($firstMonth == $nrLuni) { $endDay = date('d', strtotime($to)); } else { $endDay = $daysOfMonth[$m1 + $i == 13 ? 12 : ($m1 + $i - 1) % 12]; } $firstMonth++; $yearDate = $y1 + floor(($m1 + $i - 2) / 12); $monthDate = $m1 + $i == 13 ? 12 : (strlen(($m1 + $i - 1) % 12) == 1 ? '0' . ($m1 + $i - 1) % 12 : ($m1 + $i - 1) % 12); $select = $expenses->getMapper()->getDbTable()->select()->from(array('e' => 'expenses'), array('price' => 'SUM(e.price)'))->where('NOT e.deleted')->where('e.idMember = ? ', $idUser)->where('e.type=?', 1)->where('e.date>=?', $yearDate . "-" . $monthDate . "-" . $startDay)->where('e.date<=?', $yearDate . "-" . $monthDate . "-" . $endDay); if ($categoryIncome[0] != 2) { //if we want to see specific categories, not all the expenses $select->joinLeft(array('pg' => 'product_groups'), 'e.`id` = pg.`idProduct`', array(''))->joinLeft(array('g' => 'groups'), 'g.`id` = pg.`idGroup`', array('g.id', 'g.name', 'ufiles' => 'g.color'))->where('g.id IN (?)', $categoryIncome)->group('g.id')->order('g.name')->setIntegrityCheck(false); } $result = $expenses->fetchAll($select); //get results for all categories of expenses that exist for this week foreach ($result as $values) { $valueName = $values->getName(); $valuePrice = $values->getPrice(); $valueUfiles = $values->getUfiles(); $returnValues[date('MY', strtotime($yearDate . "-" . $monthDate . "-" . $startDay))][$values->getId()][0] = !empty($valueName) ? $values->getName() : Zend_Registry::get('translate')->_('admin_income'); $returnValues[date('MY', strtotime($yearDate . "-" . $monthDate . "-" . $startDay))][$values->getId()][1] = date('M', strtotime($yearDate . "-" . $monthDate . "-" . $startDay)) . " " . $yearDate; $returnValues[date('MY', strtotime($yearDate . "-" . $monthDate . "-" . $startDay))][$values->getId()][2] = !empty($valuePrice) ? $values->getPrice() : 0; $returnValues[date('MY', strtotime($yearDate . "-" . $monthDate . "-" . $startDay))][$values->getId()][3] = !empty($valueUfiles) ? $values->getUfiles() : '#58a87d'; //color of the category //print_r($returnValues); } } //print_r($returnValues); return $returnValues; break; case "w": $weeks = array(); $weeks = Self::weeks($from, $to); $temp_week = ''; $contor_saptamani = 0; $year = date('Y', strtotime($from)); foreach ($weeks as $week) { if ($temp_week) { if ($week < $temp_week) { $year++; } //it means that this week is from the next year: why 1 is less than last week (52) } $temp_week = $week; $timestamp = mktime(0, 0, 0, 1, 1, $year) + ($week - 1) * 7 * 24 * 60 * 60; $timestamp_for_monday = $timestamp - 86400 * (date('N', $timestamp) - 1); $first_dow = $contor_saptamani == 0 ? $from : date('Y-m-d', $timestamp_for_monday); $monday = date('Y-m-d', $timestamp_for_monday); $last_dow = $contor_saptamani == count($weeks) - 1 ? $to : date('Y-m-d', strtotime($monday) + 24 * 3600 * 6); $contor_saptamani++; $select = $expenses->getMapper()->getDbTable()->select()->from(array('e' => 'expenses'), array('price' => 'SUM(e.price)'))->where('NOT e.deleted')->where('e.idMember = ? ', $idUser)->where('e.type=?', 1)->where('e.date>=?', $first_dow)->where('e.date<=?', $last_dow); if ($categoryIncome[0] != 2) { //if we want to see specific categories, not all the expenses $select->joinLeft(array('pg' => 'product_groups'), 'e.`id` = pg.`idProduct`', array(''))->joinLeft(array('g' => 'groups'), 'g.`id` = pg.`idGroup`', array('g.id', 'g.name', 'ufiles' => 'g.color'))->where('g.id IN (?)', $categoryIncome)->group('g.id')->order('g.name')->setIntegrityCheck(false); } $result = $expenses->fetchAll($select); //get results for all categories of expenses that exist for this week foreach ($result as $values) { $valueName = $values->getName(); $valuePrice = $values->getPrice(); $valueUfiles = $values->getUfiles(); $returnValues[$week][$values->getId()][0] = !empty($valueName) ? $values->getName() : Zend_Registry::get('translate')->_('admin_income'); $returnValues[$week][$values->getId()][1] = $first_dow . "/" . $last_dow; $returnValues[$week][$values->getId()][2] = !empty($valuePrice) ? $values->getPrice() : 0; $returnValues[$week][$values->getId()][3] = !empty($valueUfiles) ? $values->getUfiles() : '#58a87d'; //color of the category } } return $returnValues; break; case "d": for ($i = 0; $i < $nr_days; $i++) { $date = date('Y-m-d', strtotime($from . ' +' . $i . ' days')); $select = $expenses->getMapper()->getDbTable()->select()->from(array('e' => 'expenses'), array('price' => 'SUM(e.price)'))->where('NOT e.deleted')->where('e.idMember = ? ', $idUser)->where('e.type=?', 1)->where('e.date=?', $date); if ($categoryIncome[0] != 2) { //if we want to see specific categories, not all the expenses $select->joinLeft(array('pg' => 'product_groups'), 'e.`id` = pg.`idProduct`', array(''))->joinLeft(array('g' => 'groups'), 'g.`id` = pg.`idGroup`', array('g.id', 'g.name', 'ufiles' => 'g.color'))->where('g.id IN (?)', $categoryIncome)->group('g.id')->order('g.name')->setIntegrityCheck(false); } $result = $expenses->fetchAll($select); //get results for all categories of expenses that exist for this week foreach ($result as $values) { $valueName = $values->getName(); $valuePrice = $values->getPrice(); $valueUfiles = $values->getUfiles(); $returnValues[$date][$values->getId()][0] = !empty($valueName) ? $values->getName() : Zend_Registry::get('translate')->_('admin_income'); $returnValues[$date][$values->getId()][1] = $date; $returnValues[$date][$values->getId()][2] = !empty($valuePrice) ? $values->getPrice() : 0; $returnValues[$date][$values->getId()][3] = !empty($valueUfiles) ? $values->getUfiles() : '#58a87d'; //color of the category } } return $returnValues; break; } }
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_Expenses(); 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 . '/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'); // } } }