From 6780b2b0304b07ea327b4b16383600cb934ba16a Mon Sep 17 00:00:00 2001 From: "venbatechnologies@gmail.com" Date: Thu, 24 May 2018 16:22:21 +0530 Subject: [PATCH] issues fixes --- application/controllers/report.php | 98 +++-------- application/models/dahsboard_model.php | 155 +++++++++++++----- .../cashbook_cumulative_month_report.php | 19 ++- application/views/cashbookmonthlyexpenses.php | 32 ++-- application/views/cashbooktoday.php | 22 +-- application/views/cashbookyearlyexpenses.php | 34 ++-- application/views/reportcashbook.php | 104 +++++------- 7 files changed, 230 insertions(+), 234 deletions(-) diff --git a/application/controllers/report.php b/application/controllers/report.php index d4d68894..08efbebc 100755 --- a/application/controllers/report.php +++ b/application/controllers/report.php @@ -1022,15 +1022,11 @@ class report extends BaseController $data['getTotalcapitalPoCount'] = $this->dahsboard_Model->getTotalcapitalPoCount(); $data['getTotalrevenuePoCount'] = $this->dahsboard_Model->getTotalrevenuePoCount(); $data['cashbook']=$this->dahsboard_Model->cashbook(); - - $income="RECEIPT"; - $expense="PAYMENT"; - $data['monthlywiseincome']=$this->dahsboard_Model->monthwise_data($income); - $data['monthlywiseexpense']=$this->dahsboard_Model->monthwise_data($expense); - $data['todayincome']=$this->dahsboard_Model->today_data($income); - $data['todayexpense']=$this->dahsboard_Model->today_data($expense); - $data['yearincome']=$this->dahsboard_Model->yearwise_data($income); - $data['yearexpense']=$this->dahsboard_Model->yearwise_data($expense); + + $data['dailyIncomeExpense']=$this->dahsboard_Model->today_data(); + $data['monthlyIncomeExpense']=$this->dahsboard_Model->monthwise_data(); + $data['yearlyIncomeExpense']=$this->dahsboard_Model->yearwise_data(); + $data['gettoptotal1'] = $this->dahsboard_Model->gettoptotal(); $data['tdy']=$this->dahsboard_Model->today(); //echo ($data['tdy']); @@ -1053,60 +1049,20 @@ class report extends BaseController $premonth = $premonth == '00' ? '12' : $premonth; $yearvalue = $premonth == '12' ? $year-1 : $year; $preyear = $yearvalue-1; - - $data['b4finyeartotal']=$this->dahsboard_Model->yearbeforetotal($preyear,$yearvalue); - $data['prevmonthtotal']=$this->dahsboard_Model->monthbeforetotal($premonth,$yearvalue); - $data['yesterdaytotal'] = $this->dahsboard_Model->daybeforetotal($yesterday); + + $data['yearlybalances']=$this->dahsboard_Model->getYearlyOpeningAmt($yearvalue); + $lastdate =cal_days_in_month(CAL_GREGORIAN,$premonth,$yearvalue); + $dateformat = '20'.$yearvalue.'-'.$premonth.'-'.$lastdate; + $data['monthlybalances']=$this->dahsboard_Model->getMonthlyOpeningAmt($dateformat); + $data['yesterdaybalances'] = $this->dahsboard_Model->getDailyOpeningAmt($yesterday); $this->loadviews("reportcashbook",$this->global,$data, NULL); } - // public function monthexpensess() - // { - - // $this->global['pageTitle'] = 'Cashbook - monthly expenses Reports - '; - - - - // $data['monthlyreport']=$this->dahsboard_Model->monthexpensereport(); - // // $data['monthlyincreport']=$this->dahsboard_Model->monthincomereport(); - // $data['Indiancurrency']=$this->dahsboard_Model->INRSymbol(); - - - // $this->loadviews("cashbookmonthlyexpenses",$this->global,$data, NULL); - - - - // } - // public function yearexpensess() - // { - - // $this->global['pageTitle'] = 'Cashbook - yearly expenses Reports - '; - - // $fyear = $this->input->post('financialyear'); - - // $fa=substr( $fyear,0,-5); - // $aa=substr( $fyear,5,5); - // //echo $fyear; - // //$data['yearlyincreport']=$this->dahsboard_Model->yearincomereport(); - // $data['yearlyreport']=$this->dahsboard_Model->yearexpensereport($fa,$aa); - // $data['financialyear']=$this->dahsboard_Model->cashbookfinyear(); - // //print_r($data['finyear']); - // $data['Indiancurrency']=$this->dahsboard_Model->INRSymbol(); - - - // $this->loadviews("cashbookyearlyexpenses",$this->global,$data, NULL); - - - // } public function monthexpenses() { - // $this->global['pageTitle'] = 'Cashbook - Cashbook Monthly Reports '; - // $data['monthlyreport']=$this->dahsboard_Model->monthexpensereport(); - // // $data['monthlyincreport']=$this->dahsboard_Model->monthincomereport(); - // $data['Indiancurrency']=$this->dahsboard_Model->INRSymbol(); - $monthyearvalue = $this->input->post('monthyear'); + $monthyearvalue = $this->input->post('monthyear'); $this->global['pageTitle'] = ' Cashbook - Cashbook Monthly Reports'; if($monthyearvalue == ''){ @@ -1119,19 +1075,16 @@ class report extends BaseController $data['monthyearvalue'] = $monthyearvalue; $monthyear = explode("-",$monthyearvalue); - $month = $monthyear[0]; + $month = $monthyear[0]; $year = $monthyear[1]; - - + $premonth = $monthyear[0]-1; $premonth = $premonth < 10 ? '0'.$premonth : ''.$premonth; $premonth = $premonth == '00' ? '12' : $premonth; - - $yearvalue = $premonth == '12' ? $year-1 : $year; - - $data['prevmonthtotal']=$this->dahsboard_Model->monthbeforetotal($premonth,$yearvalue); - - //$data['monthlyreport']=$this->dahsboard_Model->month_incexp_report($month,$year); + $yearvalue = $premonth == '12' ? $year-1 : $year; + $lastdate = cal_days_in_month(CAL_GREGORIAN,$premonth,$yearvalue); + $dateformat = $yearvalue.'-'.$premonth.'-'.$lastdate; + $data['monthlybalances']=$this->dahsboard_Model->getMonthlyOpeningAmt($dateformat); $data['monthlyreport']=$this->dahsboard_Model->monthexpensereport($month,$year); } @@ -1141,8 +1094,7 @@ class report extends BaseController } public function yearexpenses() { - // public function yearly_incexp() - // { + $this->global['pageTitle'] = 'Cashbook - Cashbook Yearly Reports'; $data['financialyear']=$this->dahsboard_Model->cashbookfinyear(); @@ -1156,20 +1108,18 @@ class report extends BaseController }else{ $data['fyears'] = $fyear; - //echo $data['fyears']; + $fa=substr( $fyear,0,-5); $aa=substr( $fyear,5,5); + $finyear = explode("-",$fyear); - $b4oneyear = $finyear[0] -1; - $b4twoyear = $finyear[1] -1; + $prev_year = $finyear[0]; $data['yearlyreport']=$this->dahsboard_Model->yearexpensereport($fa,$aa); - $data['b4finyeartotal']=$this->dahsboard_Model->yearbeforetotal($b4oneyear,$b4twoyear); + $data['yearlybalances']=$this->dahsboard_Model->getYearlyOpeningAmt($prev_year); - - //$this->loadviews("cashbookyearlyreport",$this->global,$data, NULL); } $this->loadviews("cashbookyearlyexpenses",$this->global,$data, NULL); @@ -1235,7 +1185,7 @@ class report extends BaseController $currentdate = $now->format('Y-m-d'); // MySQL datetime format $yesterday = date('Y-m-d', strtotime("-1 day")); - $data['yesterdaytotal'] = $this->dahsboard_Model->daybeforetotal($yesterday); + $data['yesterdaybalances'] = $this->dahsboard_Model->getDailyOpeningAmt($yesterday); $data['Indiancurrency']=$this->dahsboard_Model->INRSymbol(); $this->loadviews("cashbooktoday",$this->global,$data, NULL); } diff --git a/application/models/dahsboard_model.php b/application/models/dahsboard_model.php index 901a1d64..76e24d0d 100755 --- a/application/models/dahsboard_model.php +++ b/application/models/dahsboard_model.php @@ -2263,22 +2263,30 @@ if ($cname!= ''){ } //home--report--Day Wise Report // - function today_data($value='') + function today_data() { - $sql="SELECT type,Sum(total) as todaydata FROM t_income_expense WHERE type = ? AND DATE(date) = CURRENT_DATE"; - $query = $this->db->query($sql,array($value)); + $sql="SELECT sum(if(type = 'RECEIPT',total,0)) as daily_income_amt, + sum(if(type = 'PAYMENT',total,0)) as daily_expenses_amt + FROM t_income_expense + WHERE DATE(date) = CURRENT_DATE"; + $query = $this->db->query($sql); return $query->result(); } - function monthwise_data($value='') + function monthwise_data() { - $sql="SELECT type,Sum(total) as monthlydata FROM t_income_expense WHERE type = ? AND MONTH(date) = MONTH(curdate())"; - $query = $this->db->query($sql,array($value)); + //$sql="SELECT type,Sum(total) as monthlydata FROM t_income_expense WHERE type = ? AND MONTH(date) = MONTH(curdate())"; + $sql="SELECT sum(if(type = 'RECEIPT',total,0)) as monthly_income_amt, + sum(if(type = 'PAYMENT',total,0)) as monthly_expenses_amt + FROM t_income_expense + WHERE YEAR(date) = YEAR(curdate()) AND MONTH(date) = MONTH(curdate())"; + $query = $this->db->query($sql); + //,array($value)); return $query->result(); } - function yearwise_data($value='') + function yearwise_data() { if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); @@ -2289,13 +2297,47 @@ if ($cname!= ''){ $fa=substr($ab,0,-5); $aa=substr($ab,5,5); - $sql="SELECT type,sum(total) as yearlydata from t_income_expense - where - type = ? and (date >= '".$fa."-04-01' and date <= '".$aa."-03-31')"; - $query = $this->db->query($sql,array($value)); + $sql="SELECT sum(if(type = 'RECEIPT',total,0)) as yearly_income_amt, + sum(if(type = 'PAYMENT',total,0)) as yearly_expenses_amt + FROM t_income_expense + WHERE (date >= '".$fa."-04-01' and date <= '".$aa."-03-31')"; + $query = $this->db->query($sql); return $query->result(); } + // function today_data($value='') + // { + // $sql="SELECT type,Sum(total) as todaydata FROM t_income_expense WHERE type = ? AND DATE(date) = CURRENT_DATE"; + // $query = $this->db->query($sql,array($value)); + // return $query->result(); + + // } + + // function monthwise_data($value='') + // { + // $sql="SELECT type,Sum(total) as monthlydata FROM t_income_expense WHERE type = ? AND MONTH(date) = MONTH(curdate())"; + // $query = $this->db->query($sql,array($value)); + // return $query->result(); + + // } + // function yearwise_data($value='') + // { + // if (date('m') >= 4) { + // $yearl = date('Y').'-'.(date('Y')+1); + // } else { + // $yearl = (date('Y')-1).'-'.date('Y'); + // } + // $ab=$yearl; + // $fa=substr($ab,0,-5); + // $aa=substr($ab,5,5); + + // $sql="SELECT type,sum(total) as yearlydata from t_income_expense + // where + // type = ? and (date >= '".$fa."-04-01' and date <= '".$aa."-03-31')"; + // $query = $this->db->query($sql,array($value)); + // return $query->result(); + + // } function departmentwise($sid='',$d='',$c='') { $sql="SELECT date_format(tinc.date,'%d-%m-%Y')as date, @@ -2542,40 +2584,73 @@ function INRSymbol() return $query->result(); } - function monthbeforetotal($month,$year){ +// function monthbeforetotal($month,$year){ - $sql="SELECT month(date) as monthnum ,year(date) as yearnum, - sum(if(type = 'PAYMENT',total,0)) as payment_amt, - sum(if(type = 'RECEIPT',total,0)) as receipt_amt - FROM t_income_expense - WHERE - month(date) = '".$month."'and year(date) = '".$year."'"; - $query = $this->db->query($sql); - return $query->result(); +// $sql="SELECT month(date) as monthnum ,year(date) as yearnum, +// sum(if(type = 'PAYMENT',total,0)) as payment_amt, +// sum(if(type = 'RECEIPT',total,0)) as receipt_amt +// FROM t_income_expense +// WHERE +// month(date) = '".$month."'and year(date) = '".$year."'"; +// $query = $this->db->query($sql); +// return $query->result(); - } +// } - function yearbeforetotal($pre,$curr){ - $sql="SELECT - sum(if(type = 'PAYMENT',total,0)) as payment_amt, - sum(if(type = 'RECEIPT',total,0)) as receipt_amt - FROM t_income_expense - where date >= '".$pre."-04-01' and date <= '".$curr."-03-31'"; - $query = $this->db->query($sql); - return $query->result(); - //print_r($query->result()); +// function yearbeforetotal($pre,$curr){ +// $sql="SELECT +// sum(if(type = 'PAYMENT',total,0)) as payment_amt, +// sum(if(type = 'RECEIPT',total,0)) as receipt_amt +// FROM t_income_expense +// where date >= '".$pre."-04-01' and date <= '".$curr."-03-31'"; +// $query = $this->db->query($sql); +// return $query->result(); +// //print_r($query->result()); - } +// } -function daybeforetotal($yesterday){ - $sql="select date, - sum(if(type = 'PAYMENT',total,0)) as payment_amt, - sum(if(type = 'RECEIPT',total,0)) as receipt_amt - from t_income_expense - where date = ? "; - $query = $this->db->query($sql,array($yesterday)); - return $query->result(); - } +// function daybeforetotal($yesterday){ +// $sql="select date, +// sum(if(type = 'PAYMENT',total,0)) as payment_amt, +// sum(if(type = 'RECEIPT',total,0)) as receipt_amt +// from t_income_expense +// where date = ? "; +// $query = $this->db->query($sql,array($yesterday)); +// return $query->result(); +// } + + +function getYearlyOpeningAmt($prev_year){ + $sql="SELECT min(date),(sum(if(type = 'RECEIPT',total,0)) - sum(if(type = 'PAYMENT',total,0)) ) as opening_amt + FROM t_income_expense + WHERE date >= (select min(date) from t_income_expense) and date <= '".$prev_year."-03-31' "; + $query = $this->db->query($sql); + return $query->result(); + //print_r($query->result()); + +} + + +function getMonthlyOpeningAmt($dateformat){ + //echo $dateformat; + //die(); +$sql="SELECT month('".$dateformat."') as monthnum ,year('".$dateformat."') as yearnum, + (sum(if(type = 'RECEIPT',total,0)) - sum(if(type = 'PAYMENT',total,0))) as opening_amt + FROM t_income_expense + WHERE date >= (select min(date) from t_income_expense) and date <= '".$dateformat."'"; + //WHERE month(date) between (select month(min(date)) from t_income_expense) and '".$month."' and year(date) = '".$year."'"; + $query = $this->db->query($sql); + return $query->result(); + +} + +function getDailyOpeningAmt($yesterday){ + $sql="select date,(sum(if(type = 'RECEIPT',total,0)) - sum(if(type = 'PAYMENT',total,0))) as opening_amt + from t_income_expense + where date between (select min(date) from t_income_expense) and '".$yesterday."'"; + $query = $this->db->query($sql); + return $query->result(); + } function accountname() { diff --git a/application/views/cashbook_cumulative_month_report.php b/application/views/cashbook_cumulative_month_report.php index 03172a06..ddd762ba 100755 --- a/application/views/cashbook_cumulative_month_report.php +++ b/application/views/cashbook_cumulative_month_report.php @@ -1,9 +1,8 @@ = 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { @@ -140,7 +139,7 @@ if (date('m') >= 4) { January February March - Total + Total Receipt  () @@ -166,6 +165,8 @@ if (date('m') >= 4) { Receipt  () Payment  () Recepit  () + Payment  () + Recepit  () Payment  () @@ -204,7 +205,8 @@ if (date('m') >= 4) { FebExpense,2,'.',''); echo number_format($d->FebExpense,2,'.',''); ?> MarIncome,2,'.',''); echo number_format($d->MarIncome,2,'.',''); ?> MarExpense,2,'.',''); echo number_format($d->MarExpense,2,'.',''); ?> - overalltotal,2,'.',''); echo number_format($d->overalltotal,2,'.',''); ?> + receiptoverall,2,'.',''); echo number_format($d->receiptoverall,2,'.',''); ?> + paymentoverall,2,'.',''); echo number_format($d->paymentoverall,2,'.',''); ?> @@ -235,7 +237,8 @@ if (date('m') >= 4) { - + + @@ -288,6 +291,4 @@ $(document).ready(function() { } ); - - - \ No newline at end of file + \ No newline at end of file diff --git a/application/views/cashbookmonthlyexpenses.php b/application/views/cashbookmonthlyexpenses.php index 9832eb94..07c6fab4 100755 --- a/application/views/cashbookmonthlyexpenses.php +++ b/application/views/cashbookmonthlyexpenses.php @@ -1,9 +1,10 @@ payment_amt; - $payamt = $prevttl->payment_amt; - // $recamt = $prevmonthtotal[0]->receipt_amt; - $recamt = $prevttl->receipt_amt; + // $payamt = $monthlybalances[0]->payment_amt; + //$payamt = $prevttl->payment_amt; + $opening_balances = $prevttl->opening_amt; + // $recamt = $monthlybalances[0]->receipt_amt; + //$recamt = $prevttl->receipt_amt; }} if(!empty($monthyearvalue)) { @@ -80,8 +82,8 @@ $(function() { $('#monthyear').datepicker( { - //minDate : new Date(year-SIAStartYear,0,1), - //maxDate :'now', + minDate : new Date(year-SIAStartYear,0,1), + maxDate :'now', changeMonth: true, changeYear: true, showButtonPanel: true, @@ -143,8 +145,8 @@ $(function() { Previous Month Balance(Opening Balances)   - - + +   @@ -164,7 +166,7 @@ $(function() { expense,2,'.',''); echo number_format($mr->expense,2,'.','');?> - +   - + diff --git a/application/views/cashbooktoday.php b/application/views/cashbooktoday.php index c86f026e..0297b680 100755 --- a/application/views/cashbooktoday.php +++ b/application/views/cashbooktoday.php @@ -1,9 +1,7 @@ date; - $payamt = $ttl->payment_amt; - $recamt = $ttl->receipt_amt; + // $strdayttl = $ttl->date; + // $payamt = $ttl->payment_amt; + // $recamt = $ttl->receipt_amt; + $opening_balances = $ttl->opening_amt; }} ?> @@ -74,8 +73,9 @@ $tvt=0.00;       - - + + +     @@ -122,7 +122,8 @@ $tvt=0.00; ?> - + +     - + + diff --git a/application/views/cashbookyearlyexpenses.php b/application/views/cashbookyearlyexpenses.php index c3889c58..f6050b49 100755 --- a/application/views/cashbookyearlyexpenses.php +++ b/application/views/cashbookyearlyexpenses.php @@ -3,29 +3,18 @@ $inrsymbol=''; $finyear =''; $ti=0.00; $tvt=0.00; -$in=0.00; -$payamt=0.00; -$recamt = 0.00; +$opening_balances = 0.00; $zero=0.00; $curr_balances=0.00; //print_r($fyears); -if(!empty($Indiancurrency)) - { - foreach ($Indiancurrency as $inr) - { - $inrsymbol = $inr->FontCode2000; - }} - - - if(!empty($b4finyeartotal)){ - foreach ($b4finyeartotal as $prevttl) - { - //$payamt = $b4finyeartotal[0]->payment_amt; - //$recamt = $b4finyeartotal[0]->receipt_amt; - $payamt = $prevttl->payment_amt; - $recamt = $prevttl->receipt_amt; - }} +if(!empty($yearlybalances)){ + foreach ($yearlybalances as $prevttl) + { + + $opening_balances = $prevttl->opening_amt ; + + }} ?> @@ -112,8 +101,7 @@ if(!empty($Indiancurrency)) Previous Year Balance(opening balances) - - + @@ -132,7 +120,7 @@ if(!empty($Indiancurrency)) exp,2,'.',''); echo number_format($yr->exp,2,'.','');?> - + Total - + diff --git a/application/views/reportcashbook.php b/application/views/reportcashbook.php index 3a50f9ea..4b213cc2 100755 --- a/application/views/reportcashbook.php +++ b/application/views/reportcashbook.php @@ -1,5 +1,3 @@ - - todaydata; + $today_in = $t->daily_income_amt; + $today_ex = $t->daily_expenses_amt; }} - - if(!empty($todayexpense)) - { - foreach ($todayexpense as $te) - { - $today_ex=$te->todaydata; - }} - - if(!empty($monthlywiseincome)) - { - foreach ($monthlywiseincome as $mi) - { - $month_in = $mi->monthlydata; - }} - - if(!empty($monthlywiseexpense)) - { - foreach ($monthlywiseexpense as $me) - { - $month_ex = $me->monthlydata; - }} - if(!empty($yearexpense)) - { - foreach ($yearexpense as $ye) - { - $year_ex=$ye->yearlydata; - }} + - if(!empty($yearincome)) - { - foreach ($yearincome as $yi) - { - $year_in = $yi->yearlydata; - }} - -if(!empty($yesterdaytotal)) +if(!empty($monthlyIncomeExpense)) { - foreach ($yesterdaytotal as $ttl) + foreach ($monthlyIncomeExpense as $m) + { + $month_in = $m->monthly_income_amt; + $month_ex = $m->monthly_expenses_amt; + }} + +if(!empty($yearlyIncomeExpense)) +{ + foreach ($yearlyIncomeExpense as $y) + { + $year_in = $y->yearly_income_amt; + $year_ex = $y->yearly_expenses_amt; + }} + +if(!empty($yesterdaybalances)) +{ + foreach ($yesterdaybalances as $ttl) { $strdaydate = $ttl->date; - $strday_balances = ($ttl->payment_amt)-($ttl->receipt_amt); - $payamt = $ttl->payment_amt; - $recamt = $ttl->receipt_amt; - } -} -if(!empty($prevmonthtotal)) + $strday_balances = $ttl->opening_amt; + }} + +if(!empty($monthlybalances)) { - foreach ($prevmonthtotal as $prevttl){ - $premonth_balances = ($prevttl->payment_amt) - ($prevttl->receipt_amt); + foreach ($monthlybalances as $prevttl){ + //$premonth_balances = ($prevttl->payment_amt) - ($prevttl->receipt_amt); + $premonth_balances = $prevttl->opening_amt; } } -if(!empty($b4finyeartotal)){ - foreach ($b4finyeartotal as $preyearttl) + +if(!empty($yearlybalances)){ + foreach ($yearlybalances as $preyearttl) { - $preyear_balances = ($preyearttl->payment_amt) - ($preyearttl->receipt_amt); + //$preyear_balances = ($preyearttl->payment_amt) - ($preyearttl->receipt_amt); + $preyear_balances = $preyearttl->opening_amt; } } ?> - - - -