Esempio n. 1
0
 public function indexAction()
 {
     // BEGIN:FILTERS
     $filters = array();
     //array with variables to send to pagination (filters)
     // END:FILTERS
     //BEGIN:LISTING	MESSAGES
     $model = new Default_Model_Messages();
     $select = $model->getMapper()->getDbTable()->select();
     $select->from(array('u' => 'messages'), array('u.id', 'u.idUserFrom', 'u.idUserTo', 'u.subject', 'u.created'))->where('u.idUserTo = ?', Zend_Registry::get('user')->getId())->where('NOT u.deletedTo')->where('NOT u.trashedTo');
     $select->order('u.created  DESC')->setIntegrityCheck(false);
     // pagination
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
     $paginator->setItemCountPerPage(10);
     $paginator->setCurrentPageNumber($this->_getParam('page'));
     $paginator->setPageRange(5);
     Zend_Paginator::setDefaultScrollingStyle('Sliding');
     Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $filters));
     $this->view->inboxNr = Needs_Messages::getInboxMessagesNumber();
     $this->view->result = $paginator;
     $this->view->itemCountPerPage = $paginator->getItemCountPerPage();
     $this->view->totalItemCount = $paginator->getTotalItemCount();
     //END:LISTING MESSAGES
     //BEGIN:LISTING LATEST EXPENSES / INCOME
     $model = new Default_Model_Expenses();
     $select = $model->getMapper()->getDbTable()->select();
     $select->from(array('u' => 'expenses'), array('u.id', 'u.name', 'u.price', 'u.date', 'u.type'))->where('u.idMember = ?', Zend_Registry::get('user')->getId())->where('NOT u.deleted');
     $select->order('u.date  DESC');
     // pagination
     $paginatorLatest = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
     $paginatorLatest->setItemCountPerPage(10);
     $paginatorLatest->setCurrentPageNumber($this->_getParam('page'));
     $paginatorLatest->setPageRange(5);
     Zend_Paginator::setDefaultScrollingStyle('Sliding');
     Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $filters));
     $this->view->resultLatest = $paginatorLatest;
     $this->view->itemCountPerPageLatest = $paginatorLatest->getItemCountPerPage();
     $this->view->totalItemCountLatest = $paginatorLatest->getTotalItemCount();
     //END:LISTING LATEST EXPENSES / INCOME
     //START: Expenses PIE
     $groups = new Default_Model_Groups();
     $select = $groups->getMapper()->getDbTable()->select()->from(array('g' => 'groups'), array('g.id', 'g.name', 'g.color', 'g.created', 'g.deleted'))->joinLeft(array('pg' => 'product_groups'), 'g.id = pg.idGroup', array())->joinLeft(array('p' => 'expenses'), 'p.id = pg.idProduct', array('price' => 'SUM(p.price)'))->where('NOT g.deleted')->where('p.type=?', 0)->where('p.date>=?', date('Y-m-01'))->group('g.id')->setIntegrityCheck(false);
     $resultPieExpenses = $groups->fetchAll($select);
     $this->view->resultPieExpenses = $resultPieExpenses;
     //END: Expenses PIE
     //START: Income PIE
     $groups2 = new Default_Model_Groups();
     $select2 = $groups2->getMapper()->getDbTable()->select()->from(array('g' => 'groups'), array('g.id', 'g.name', 'g.color', 'g.created', 'g.deleted'))->joinLeft(array('pg' => 'product_groups'), 'g.id = pg.idGroup', array())->joinLeft(array('p' => 'expenses'), 'p.id = pg.idProduct', array('price' => 'SUM(p.price)'))->where('NOT g.deleted')->where('p.type=?', 1)->where('p.date>=?', date('Y-m-01'))->group('g.id')->setIntegrityCheck(false);
     $resultPieIncome = $groups2->fetchAll($select2);
     $this->view->resultPieIncome = $resultPieIncome;
     //END: Income PIE
     $date = date('Y-m-d');
     $thisWeekStartDate = Needs_Tools::getWeekDaysByDate($date, $type = 'start');
     $thisWeekEndDay = Needs_Tools::getWeekDaysByDate($date, $type = 'end');
     $this->view->dateFrom = $thisWeekStartDate;
     $this->view->dateTo = $thisWeekEndDay;
     //		$resultInfo= Needs_Tools::showProjectedDashboard($thisWeekStartDate,$thisWeekEndDay);
     //		if ($resultInfo){
     //			$this->view->foodCost=$resultInfo["foodCost"];
     //			$this->view->laborCost=$resultInfo["laborCost"];
     //			$this->view->idShop=$resultInfo["idShop"];
     //		}else{
     //                        $this->view->foodCost='';
     //			$this->view->laborCost='';
     //			$this->view->idShop='';
     //                }
     $resultIncomeExpense = Needs_Tools::showIncomeExpensesDashboard(date('Y'), date('m'));
     if ($resultIncomeExpense) {
         $value = array();
         foreach ($resultIncomeExpense as $values) {
             $value[] = $values->getPrice();
         }
         $this->view->incomeAmount = isset($value[1]) ? $value[1] : 0;
         $this->view->expensesAmount = isset($value[0]) ? $value[0] : 0;
     } else {
         $this->view->incomeAmount = 0;
         $this->view->expensesAmount = 0;
     }
     $date = date('Y-m-d');
     $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));
     $resultIncomeExpenseLastMonth = Needs_Tools::showIncomeExpensesDashboard(date('Y', $newdate), date('m', $newdate));
     if ($resultIncomeExpenseLastMonth) {
         $value = array();
         foreach ($resultIncomeExpenseLastMonth as $values) {
             $value[] = $values->getPrice();
         }
         $this->view->incomeAmountLastMonth = isset($value[1]) ? $value[1] : 0;
         $this->view->expensesAmountLastMonth = isset($value[0]) ? $value[0] : 0;
     } else {
         $this->view->incomeAmountLastMonth = 0;
         $this->view->expensesAmountLastMonth = 0;
     }
     $this->view->newdate = $newdate;
     //$this->view->form = $form;
 }
Esempio n. 2
0
File: Tools.php Progetto: valizr/MMA
 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;
     }
 }
Esempio n. 3
0
 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');
         //			}
     }
 }