Beispiel #1
0
 function init()
 {
     // Set the method for the display form to POST
     $this->setMethod('post');
     $this->addAttribs(array('id' => 'addExpense', 'class' => ''));
     $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
     $control = new Zend_Form_Element_Hidden('control');
     $control->setValue('addExpense');
     $this->addElement($control);
     // begin inputs
     $name = new Zend_Form_Element_Text('name');
     $name->setAttribs(array('class' => 'text validate[required] rightAdd', 'placeholder' => Zend_Registry::get('translate')->_('admin_recurrent_expense_description')));
     $name->setRequired(true);
     $this->addElement($name);
     $price = new Zend_Form_Element_Text('price');
     $price->setAttribs(array('class' => 'text validate[required] rightAdd', 'placeholder' => Zend_Registry::get('translate')->_('admin_price')));
     $price->setRequired(true);
     $this->addElement($price);
     //BEGIN: Date
     $date = new Zend_Form_Element_Text('date');
     $date->setAttribs(array('class' => 'rightAdd dateSearch w_315', 'placeholder' => 'Date'));
     $date->setLabel('Select day');
     $this->addElement($date);
     // END: Date
     //BEGIN:Id Group
     $idGroup = new Zend_Form_Element_Select('idGroup');
     $options = array();
     $pm = new Default_Model_Groups();
     $select = $pm->getMapper()->getDbTable()->select()->where('NOT deleted')->order('name ASC');
     $result = $pm->fetchAll($select);
     if (NULL != $result) {
         foreach ($result as $value) {
             $options[$value->getId()] = $value->getName();
         }
     }
     $idGroup->addMultiOptions($options);
     $idGroup->addValidator(new Zend_Validate_InArray(array_keys($options)));
     $idGroup->setAttribs(array('class' => 'select'));
     $idGroup->setRequired(false);
     $this->addElement($idGroup);
     //END:Id Group
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setValue(Zend_Registry::get('translate')->_('admin_add_recurrent_expense'));
     $submit->setAttribs(array('class' => 'submit'));
     $submit->setIgnore(true);
     $this->addElement($submit);
 }
Beispiel #2
0
 function init()
 {
     $this->setMethod('post');
     $this->addAttribs(array('id' => 'filterForm', 'class' => ''));
     $this->setAction(WEBROOT . 'recurrent-expenses');
     // BEGIN: nume text
     $nameSearch = new Zend_Form_Element_Text('nameSearch');
     $nameSearch->setAttribs(array('class' => 'text large', 'placeholder' => Zend_Registry::get('translate')->_('admin_name')));
     $nameSearch->setRequired(false);
     $this->addElement($nameSearch);
     // END: nume text
     // BEGIN: prenume text
     $idGroupSearch = new Zend_Form_Element_Select('idGroupSearch');
     $options = array('' => Zend_Registry::get('translate')->_('admin_select_expense'));
     $groups = new Default_Model_Groups();
     $select = $groups->getMapper()->getDbTable()->select()->where('type=?', 0)->where('NOT deleted')->order('name ASC');
     $result = $groups->fetchAll($select);
     if (NULL != $result) {
         foreach ($result as $value) {
             $options[$value->getId()] = $value->getName();
         }
     }
     $idGroupSearch->addMultiOptions($options);
     $idGroupSearch->addValidator(new Zend_Validate_InArray(array_keys($options)));
     $idGroupSearch->setAttribs(array('class' => 'select uniformSelect filter_selector'));
     $idGroupSearch->setRequired(false);
     $this->addElement($idGroupSearch);
     // END: prenume text
     // BEGIN: fromDate text
     $fromDate = new Zend_Form_Element_Text('fromDate');
     $fromDate->setAttribs(array('class' => 'text large', 'placeholder' => Zend_Registry::get('translate')->_('admin_from_date')));
     $fromDate->setRequired(false);
     $this->addElement($fromDate);
     // END: fromDate text
     // BEGIN: toDate text
     $toDate = new Zend_Form_Element_Text('toDate');
     $toDate->setAttribs(array('class' => 'text large', 'placeholder' => Zend_Registry::get('translate')->_('admin_to_date')));
     $toDate->setRequired(false);
     $this->addElement($toDate);
     // END: toDate text
     $search = new Zend_Form_Element_Submit('searchProduct');
     $search->setValue(Zend_Registry::get('translate')->_('admin_filter'));
     $search->setAttribs(array('class' => 'submit'));
     $search->setIgnore(true);
     $this->addElement($search);
 }
Beispiel #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_Groups();
         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
     }
 }
Beispiel #4
0
 function init()
 {
     // Set the method for the display form to POST
     $this->setMethod('post');
     $this->setAction(WEBROOT . 'statistics');
     $this->addAttribs(array('id' => 'filterComplexForm', 'class' => ''));
     $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
     //BEGIN:Id Category Expenses
     $idCategoryE = new Zend_Form_Element_Multiselect('idCategoryE');
     $options = array('1' => strtoupper(Zend_Registry::get('translate')->_('admin_expenses')));
     $categories = new Default_Model_Groups();
     $select = $categories->getMapper()->getDbTable()->select()->where('NOT deleted')->where('type=?', 0)->order('name ASC');
     $result = $categories->fetchAll($select);
     if (NULL != $result) {
         foreach ($result as $value) {
             $options[$value->getId()] = $value->getName();
         }
     }
     $idCategoryE->setMultiOptions($options);
     $idCategoryE->addValidator(new Zend_Validate_InArray(array_keys($options)));
     $idCategoryE->setAttribs(array('class' => 'rightAdd form_selector', 'id' => 'idCategoryE'));
     $idCategoryE->setRequired(false);
     $this->addElement($idCategoryE);
     //END:Id Category Expenses
     //BEGIN:Id Category Income
     $idCategoryI = new Zend_Form_Element_Multiselect('idCategoryI');
     $options = array('2' => strtoupper(Zend_Registry::get('translate')->_('admin_income')));
     $categories = new Default_Model_Groups();
     $select = $categories->getMapper()->getDbTable()->select()->where('NOT deleted')->where('type=?', 1)->order('name ASC');
     $result = $categories->fetchAll($select);
     if (NULL != $result) {
         foreach ($result as $value) {
             $options[$value->getId()] = " " . $value->getName();
         }
     }
     $idCategoryI->setMultiOptions($options);
     $idCategoryI->addValidator(new Zend_Validate_InArray(array_keys($options)));
     $idCategoryI->setAttribs(array('class' => 'rightAdd form_selector', 'id' => 'idCategoryI'));
     $idCategoryI->setRequired(false);
     $this->addElement($idCategoryI);
     //END:Id Category Income
     //BEGIN:Timeframe
     $timeframe = new Zend_Form_Element_Select('timeframe');
     $options = array('m' => Zend_Registry::get('translate')->_('admin_monthly'), 'w' => Zend_Registry::get('translate')->_('admin_weekly'), 'd' => Zend_Registry::get('translate')->_('admin_daily'));
     $timeframe->setMultiOptions($options);
     $timeframe->addValidator(new Zend_Validate_InArray(array_keys($options)));
     $timeframe->setAttribs(array('class' => 'rightAdd validate[required] form_selector', 'id' => 'timeframe'));
     $timeframe->setRequired(true);
     $timeframe->setValue('m');
     $this->addElement($timeframe);
     //END:Timeframe
     // BEGIN: data
     $dataStart = new Zend_Form_Element_Text('dataStartC');
     $dataStart->setAttribs(array('class' => 'data_inceput_c validate[required]', 'placeholder' => Zend_Registry::get('translate')->_('admin_from_date')));
     $dataStart->setRequired(true);
     $this->addElement($dataStart);
     $dataEnd = new Zend_Form_Element_Text('dataEndC');
     $dataEnd->setAttribs(array('class' => 'data_sfarsit_c validate[required]', 'placeholder' => Zend_Registry::get('translate')->_('admin_to_date')));
     $this->addElement($dataEnd);
     // END: data
     $submit = new Zend_Form_Element_Submit('submitC');
     $submit->setValue(Zend_Registry::get('translate')->_('admin_menu_form_search'));
     $submit->setAttribs(array('class' => 'submit'));
     $submit->setRequired(true);
     $this->addElement($submit);
     $submitReportE = new Zend_Form_Element_Submit('submitReportE');
     $submitReportE->setAttribs(array('class' => 'submitReport'));
     $submitReportE->setRequired(true);
     $this->addElement($submitReportE);
     $submitReportI = new Zend_Form_Element_Submit('submitReportI');
     $submitReportI->setAttribs(array('class' => 'submitReport'));
     $submitReportI->setRequired(true);
     $this->addElement($submitReportI);
 }
Beispiel #5
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;
 }
Beispiel #6
0
 public function indexAction()
 {
     // BEGIN:FILTERS
     $filters = array();
     //array with variables to send to pagination (filters)
     // END:FILTERS
     $params = array();
     if ($this->getRequest()->getParam('dataStart')) {
         $params['dataStart'] = $this->getRequest()->getParam('dataStart');
     }
     if ($this->getRequest()->getParam('dataEnd')) {
         $params['dataEnd'] = $this->getRequest()->getParam('dataEnd');
     }
     $formsearch = new Default_Form_SearchStatistics();
     $formsearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/statistics/search.phtml'))));
     $this->view->formsearch = $formsearch;
     if (empty($params)) {
         $params['dataStart'] = date('Y-m-01');
         $params['dataEnd'] = '';
     }
     $this->view->search = $params;
     $formsearchcomplex = new Default_Form_SearchComplexStatistics();
     $formsearchcomplex->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/statistics/search-complex.phtml'))));
     $this->view->formsearchcomplex = $formsearchcomplex;
     //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)->group('g.id')->setIntegrityCheck(false);
     if (!empty($params['dataStart'])) {
         $select->where('p.date >= ?', $params['dataStart']);
     }
     if (!empty($params['dataEnd'])) {
         $select->where('p.date <= ?', $params['dataEnd']);
     }
     if (empty($params['dataStart']) && empty($params['dataEnd'])) {
         $select->where('p.date>=?', date('Y-m-01'));
     }
     $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)->group('g.id')->setIntegrityCheck(false);
     if (!empty($params['dataStart'])) {
         $select2->where('p.date >= ?', $params['dataStart']);
     }
     if (!empty($params['dataEnd'])) {
         $select2->where('p.date <= ?', $params['dataEnd']);
     }
     if (empty($params['dataStart']) && empty($params['dataEnd'])) {
         $select2->where('p.date>=?', date('Y-m-01'));
     }
     $resultPieIncome = $groups2->fetchAll($select2);
     $this->view->resultPieIncome = $resultPieIncome;
     //END: Income PIE
     //START current month expenses / income / left
     $resultIncomeExpense = Needs_Tools::showIncomeExpensesDashboard(date('Y'), date('m'));
     if ($resultIncomeExpense) {
         $value = array();
         foreach ($resultIncomeExpense as $values) {
             $value[] = $values->getPrice();
         }
         if (isset($value[1])) {
             $this->view->incomeAmount = $value[1];
         } else {
             $this->view->incomeAmount = 0;
         }
         if (isset($value[0])) {
             $this->view->expensesAmount = $value[0];
         } else {
             $this->view->expensesAmount = 0;
         }
     } else {
         $this->view->incomeAmount = 0;
         $this->view->expensesAmount = 0;
     }
     //END current month expenses / income / left
     $categoryNames = array();
     $categoryRes = array();
     $monthly_stats = array();
     $line_color = array();
     $categoryNamesi = array();
     $categoryResi = array();
     $monthly_statsi = array();
     $line_colori = array();
     $i = 0;
     if ($this->getRequest()->getParam('idCategoryE')) {
         $params['idCategoryE'] = $this->getRequest()->getParam('idCategoryE');
     }
     if ($this->getRequest()->getParam('idCategoryI')) {
         $params['idCategoryI'] = $this->getRequest()->getParam('idCategoryI');
     }
     if ($this->getRequest()->getParam('dataStartC')) {
         $params['dataStartC'] = $this->getRequest()->getParam('dataStartC');
     }
     if ($this->getRequest()->getParam('dataEndC')) {
         $params['dataEndC'] = $this->getRequest()->getParam('dataEndC');
     }
     if ($this->getRequest()->getParam('timeframe')) {
         $params['timeframe'] = $this->getRequest()->getParam('timeframe');
     }
     if (isset($params['dataStartC']) || isset($params['dataEndC']) || isset($params['idCategoryE']) || isset($params['idCategoryI'])) {
         $value = array();
         if (empty($params['idCategoryE'])) {
             $params['idCategoryE'][0] = 1;
         }
         //expenses "category"
         if (empty($params['idCategoryI'])) {
             $params['idCategoryI'][0] = 2;
         }
         //income "category"
         $resultExpense = Needs_Tools::showExpensesDashboardbyDateCat($params['dataStartC'], $params['dataEndC'], $params['idCategoryE'], $params['timeframe']);
         $resultIncome = Needs_Tools::showIncomeDashboardbyDateCat($params['dataStartC'], $params['dataEndC'], $params['idCategoryI'], $params['timeframe']);
         $totalAmountCat = array();
         foreach ($resultExpense as $Expense => $values) {
             //echo($Expense."<br>");
             //print_r($values);
             foreach ($values as $cat => $value) {
                 //echo $cat."<br>";
                 //print_r($value);
                 $totalAmountCat[$cat] = isset($totalAmountCat[$cat]) ? $totalAmountCat[$cat] + $value[2] : $value[2];
                 $categoryRes[$cat] = $value[0];
                 $monthly_stats[$value[1]][$cat] = $value[2];
                 //monthly_stat[saptamana de forma data1/data2]=cheltuieli din sapt respectiva
                 $line_color[$cat] = $value[3];
                 //culoarea liniei pt categoria asta
             }
         }
         foreach ($categoryRes as $key => $value) {
             $categoryNames[$key] = $value . "-" . $totalAmountCat[$key];
         }
         asort($categoryNames);
         //order alphabetically
         $totalAmountCati = array();
         foreach ($resultIncome as $Income => $valuesi) {
             //echo($Income."<br>");
             //print_r($values);
             foreach ($valuesi as $cati => $valuei) {
                 //echo $cat."<br>";
                 //print_r($value);
                 $totalAmountCati[$cati] = isset($totalAmountCati[$cati]) ? $totalAmountCati[$cati] + $valuei[2] : $valuei[2];
                 $categoryResi[$cati] = $valuei[0];
                 $monthly_statsi[$valuei[1]][$cati] = $valuei[2];
                 //monthly_stat[saptamana de forma data1/data2]=cheltuieli din sapt respectiva
                 $line_colori[$cati] = $valuei[3];
                 //culoarea liniei pt categoria asta
             }
         }
         foreach ($categoryResi as $keyi => $valuei) {
             $categoryNamesi[$keyi] = $valuei . "-" . $totalAmountCati[$keyi];
         }
         asort($categoryNamesi);
         //order alphabetically
     } else {
         //                    $categoryNames[0]='Expenses';
         //                    $categoryNames[1]='Income';
         //                //for ($i=1;$i>=0;$i--){//show chart for last year as well.
         //                    for ($j=1;$j<(date('n')+1);$j++){
         //                        if (strlen($j)==1) $m="0".$j;
         //                        else $m=$j;
         //                        $resultIncomeExpense = Needs_Tools::showIncomeExpensesDashboard(date('Y')-$i, $m);
         //                        if ($resultIncomeExpense){
         //                            $value=array();
         //                            foreach ($resultIncomeExpense as $values){
         //                                $value[] = $values->getPrice();
         //                            }
         //                            if (isset($value[1])){
         //                            $monthly_stats[$m.'-'.(date('Y')-$i)][1]=$value[1];
         //                            }else $monthly_stats[$m.'-'.(date('Y')-$i)][1]=0;
         //                            if (isset($value[0])){
         //                            $monthly_stats[$m.'-'.(date('Y')-$i)][0]=$value[0];
         //                            }else $monthly_stats[$m.'-'.(date('Y')-$i)][0]=0;
         //                        }else{
         //                            $monthly_stats[$m.'-'.(date('Y')-$i)][0]=0;
         //                            $monthly_stats[$m.'-'.(date('Y')-$i)][1]=0;
         //                        }
         //                    }
         //                    $line_color[0]='#d43c2c';
         //                    $line_color[1]='#58a87d';
         //                //}//this shows income and expenses together when first loading the page
         //here i separate expenses and income each with its own graph.
         $categoryNames[0] = Zend_Registry::get('translate')->_('admin_expenses');
         $categoryNamesi[0] = Zend_Registry::get('translate')->_('admin_income');
         //for ($i=1;$i>=0;$i--){//show chart for last year as well.
         for ($j = 1; $j < date('n') + 1; $j++) {
             if (strlen($j) == 1) {
                 $m = "0" . $j;
             } else {
                 $m = $j;
             }
             $resultIncomeExpense = Needs_Tools::showIncomeExpensesDashboard(date('Y') - $i, $m);
             if ($resultIncomeExpense) {
                 $value = array();
                 foreach ($resultIncomeExpense as $values) {
                     $value[] = $values->getPrice();
                 }
                 if (isset($value[1])) {
                     $monthly_statsi[$m . '-' . (date('Y') - $i)][0] = $value[1];
                 } else {
                     $monthly_statsi[$m . '-' . (date('Y') - $i)][0] = 0;
                 }
                 if (isset($value[0])) {
                     $monthly_stats[$m . '-' . (date('Y') - $i)][0] = $value[0];
                 } else {
                     $monthly_stats[$m . '-' . (date('Y') - $i)][0] = 0;
                 }
             } else {
                 $monthly_stats[$m . '-' . (date('Y') - $i)][0] = 0;
                 $monthly_statsi[$m . '-' . (date('Y') - $i)][0] = 0;
             }
             $monthly_stats[$m . '-' . (date('Y') - $i)][1] = $m . '-' . (date('Y') - $i);
             //monthlystats[1]=the date
             $monthly_statsi[$m . '-' . (date('Y') - $i)][1] = $m . '-' . (date('Y') - $i);
             //monthlystats[1]=the date
         }
         $line_color[0] = '#d43c2c';
         $line_colori[0] = '#58a87d';
         //}
     }
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($formsearchcomplex->isValid($formData)) {
             $formsearchcomplex->populate($formData);
         }
     }
     if ($this->getRequest()->isPost()) {
         if ($this->getRequest()->getPost('submitReportE')) {
             $monthly_stats = array_filter($monthly_stats);
             $objPHPExcel = new PHPExcel();
             $objPHPExcel->getProperties()->setCreator("Money-Management-System")->setLastModifiedBy("Money-Management-System")->setTitle("Form")->setSubject(Zend_Registry::get('translate')->_('admin_expenses'))->setDescription(Zend_Registry::get('translate')->_('admin_expenses_chart'))->setKeywords("")->setCategory("");
             $col = 0;
             $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(0, 1, '');
             $col++;
             foreach ($categoryNames as $keys => $values) {
                 foreach ($monthly_stats as $monthlyStat => $valuesms) {
                     if (!array_key_exists($keys, $valuesms)) {
                         $valuesms[$keys] = 0;
                     }
                 }
                 $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($col, 1, $values);
                 $col++;
             }
             $row = 2;
             foreach ($monthly_stats as $monthlyStat => $values) {
                 //for each period: days/week intervals/months
                 $rowDate = $monthlyStat != '' ? $monthlyStat : '-';
                 $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(0, $row, $rowDate);
                 $col = 1;
                 foreach ($categoryNames as $keys => $value) {
                     if (array_key_exists($keys, $values)) {
                         $rowAmount = $values[$keys];
                     } else {
                         $rowAmount = 0;
                     }
                     $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($col, $row, $rowAmount);
                     $col++;
                 }
                 $row++;
             }
             $objPHPExcel->getActiveSheet()->setTitle(Zend_Registry::get('translate')->_('admin_expenses'));
             $objPHPExcel->setActiveSheetIndex(0);
             header('Content-Type: application/vnd.ms-excel');
             header('Content-Disposition: attachment;filename="' . date('Y-m-d-H-i-s') . '.xls"');
             /*header('Cache-Control: max-age=0');*/
             $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
             $objWriter->save('php://output');
             $this->_helper->viewRenderer->setNoRender();
             $this->_helper->getHelper('layout')->disableLayout();
         }
         //generate excel report for income
         if ($this->getRequest()->getPost('submitReportI')) {
             $monthly_stats = array_filter($monthly_stats);
             $objPHPExcel = new PHPExcel();
             $objPHPExcel->getProperties()->setCreator("Money-Management-System")->setLastModifiedBy("Money-Management-System")->setTitle("Form")->setSubject(Zend_Registry::get('translate')->_('admin_income'))->setDescription(Zend_Registry::get('translate')->_('admin_income_chart'))->setKeywords("")->setCategory("");
             $col = 0;
             $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(0, 1, '');
             $col++;
             foreach ($categoryNamesi as $keys => $values) {
                 foreach ($monthly_statsi as $monthlyStat => $valuesms) {
                     if (!array_key_exists($keys, $valuesms)) {
                         $valuesms[$keys] = 0;
                     }
                 }
                 $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($col, 1, $values);
                 $col++;
             }
             $row = 2;
             foreach ($monthly_statsi as $monthlyStat => $values) {
                 //for each period: days/week intervals/months
                 $rowDate = $monthlyStat != '' ? $monthlyStat : '-';
                 $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(0, $row, $rowDate);
                 $col = 1;
                 foreach ($categoryNamesi as $keys => $value) {
                     if (array_key_exists($keys, $values)) {
                         $rowAmount = $values[$keys];
                     } else {
                         $rowAmount = 0;
                     }
                     $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($col, $row, $rowAmount);
                     $col++;
                 }
                 $row++;
             }
             $objPHPExcel->getActiveSheet()->setTitle(Zend_Registry::get('translate')->_('admin_expenses'));
             $objPHPExcel->setActiveSheetIndex(0);
             header('Content-Type: application/vnd.ms-excel');
             header('Content-Disposition: attachment;filename="' . date('Y-m-d-H-i-s') . '.xls"');
             /*header('Cache-Control: max-age=0');*/
             $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
             $objWriter->save('php://output');
             $this->_helper->viewRenderer->setNoRender();
             $this->_helper->getHelper('layout')->disableLayout();
         }
     }
     $this->view->monthlyStats = array_filter($monthly_stats);
     $this->view->lineColor = $line_color;
     $this->view->categoryNames = $categoryNames;
     $this->view->monthlyStatsi = array_filter($monthly_statsi);
     $this->view->lineColori = $line_colori;
     $this->view->categoryNamesi = $categoryNamesi;
 }