function edit(Default_Model_Expenses $model) { $expenseId = new Zend_Form_Element_Hidden('expenseId'); $expenseId->setValue($model->getId()); $this->addElement($expenseId); $this->name->setValue($model->getName()); $this->name->setLabel(Zend_Registry::get('translate')->_('admin_name')); $this->price->setValue($model->getPrice()); $this->price->setLabel(Zend_Registry::get('translate')->_('admin_price')); $this->date->setValue(date('m/d/Y', strtotime($model->getDate()))); $this->date->setLabel(Zend_Registry::get('translate')->_('admin_date')); $productGroups = new Default_Model_ProductGroups(); $select = $productGroups->getMapper()->getDbTable()->select()->where('idProduct=?', $model->getId()); $result = $productGroups->fetchAll($select); if (NULL != $result) { foreach ($result as $value) { $options[$value->getId()] = $value->getIdGroup(); } } $this->idGroup->setValue($options); $this->idGroup->setLabel(Zend_Registry::get('translate')->_('category')); $this->submit->setValue(Zend_Registry::get('translate')->_('admin_edit_expense')); }
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 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; }
public function deleteAction() { $userId = NULL; $auth = Zend_Auth::getInstance(); $authAccount = $auth->getStorage()->read(); if (null != $authAccount) { if (null != $authAccount->getId()) { $userId = $authAccount->getId(); } } $id = $this->getRequest()->getParam('id'); $model = new Default_Model_Expenses(); if ($model->find($id)) { if ($expenseId = $model->delete()) { Needs_Tools::DeleteLegaturi($expenseId); $this->_flashMessenger->addMessage("<div class='success canhide'><p>Expense was deleted successfully!<a href='javascript:;'></a></p></div>"); } else { $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Expense was not deleted!<a href='javascript:;'></a></p></div>"); } $this->_redirect('expenses'); } }
public function saveExpenseincomePriceAction() { $return = ''; $id = (int) $this->getRequest()->getParam('id'); if ($id) { $post = $this->getRequest()->getPost(); $model = new Default_Model_Expenses(); $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); }
public function delete(Default_Model_Expenses $value) { $id = $value->getId(); $data = array('deleted' => '1'); $this->getDbTable()->update($data, array('id = ?' => $id)); //logs action done //$user_name = $value->getUserName()->getName().' '.$value->getUserName()->getSurname(); $product_name = $value->getName(); $action_done = ' User deleted the expense ' . $product_name . ' '; Needs_Logs::DbLogTracking(0, $id, 'expenses', 'stergere', $action_done); //end logs action done return $id; }