%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php class Budget_model extends CI_Model { function __construct() { parent::__construct(); $this->months=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; } function setCond(){ $qs=trimArray($this->input->get()); $channel_ids=$this->userChannelIds(); if($channel_ids){ $this->db->where_in("b.channel_id", $channel_ids); } if($qs['medium_id']){ $this->db->where("c.medium_id", $qs['medium_id']); } if($qs['channel_id']){ $this->db->where("b.channel_id", $qs['channel_id']); } if($qs['k']){ $this->db->group_start(); $this->db->like("b.particular", $qs['k'])->or_like("b.amount", $qs['k'])->or_like("b.gst", $qs['k'])->or_like("b.payable_amount", $qs['k']); $this->db->group_end(); } } function lists($all=false){ $qs=trimArray($this->input->get()); $this->setCond(); $this->db->select("b.*, m.id medium_id, m.name medium, c.name channel, u.name created_by_name, u.type created_by_type") ->from("budgets b") ->join("budget_channels c", "c.id=b.channel_id") ->join("budget_mediums m", "m.id=c.medium_id") ->join("users u", "u.id=b.created_by") ->order_by("b.month", "DESC") ->order_by("b.id", "DESC"); if($all){ $rs['data']=$this->db->get()->result_array(); }else{ $rs=$this->dba->pagedRowsNew($qs['p'], $qs['ps']); } foreach($rs['data'] as &$r){ $r['month_name']=$this->months[$r['month']-1]; } $this->setCond(); $f="SUM(amount) amount, SUM(payable_amount-amount) gst, SUM(payable_amount) payable_amount"; $rs['total']=$this->db->select($f)->from("budgets b")->join("budget_channels c", "c.id=b.channel_id")->get()->row_array("amount, gst, payable_amount"); $rs['total']['amount']=(float)$rs['total']['amount']; $rs['total']['gst']=(float)$rs['total']['gst']; $rs['total']['payable_amount']=(float)$rs['total']['payable_amount']; return $rs; } function budgetReport(){ $total=[ 'month_wise'=>[], 'total'=>0 ]; $months=$this->db->select("YEAR(from_date) yy, month") ->from("budgets") ->group_by("YEAR(from_date)")->group_by("month") ->order_by("YEAR(from_date)")->order_by("month") ->get() ->result_array(); $monthWise=[]; foreach($months as &$ym){ $mm=$ym['yy'].'-'.$ym['month']; $ym['mm']=$mm; $monthWise[$mm]=0; } $total['month_wise']=$monthWise; $mediums=$this->db->select("id, name") ->from("budget_mediums") ->order_by("disp_odr") ->get() ->result_array(); foreach($mediums as &$m){ $m['month_wise']=$monthWise; $m['total']=0; $m['channels']=$this->db->select("id, name")->order_by("disp_odr")->get_where("budget_channels", ['medium_id'=>$m['id']])->result_array(); foreach($m['channels'] as &$c){ $f="id, YEAR(from_date) yy, month, SUM(payable_amount) payable_amount"; $records=$this->db->select($f) ->from("budgets") ->where('channel_id', $c['id']) ->group_by("YEAR(from_date)")->group_by("month") ->order_by("YEAR(from_date)")->order_by("month") ->get()->result_array(); $monthWiseChannel=[]; foreach($records as $r){ $mm=$r['yy'].'-'.$r['month']; $monthWiseChannel[$mm]=(int)$r['payable_amount']; $m['month_wise'][$mm]+=$monthWiseChannel[$mm]; $total['month_wise'][$mm]+=$monthWiseChannel[$mm]; } $c['month_wise']=$monthWiseChannel; $c['total']=0; foreach($monthWiseChannel as $amt){ $c['total']+=$amt; $m['total']+=$amt; $total['total']+=$amt; } unset($records); } } return ['months'=>$months, 'result'=>$mediums, 'total'=>$total]; pr($mediums); die; } function delete($id){ $this->db->db_debug=FALSE; $this->db->delete("budgets", ['id'=>$id]); return $this->db->affected_rows()>0; } function mediums($all=false){ $qs=trimArray($this->input->get()); $channel_ids=$this->userChannelIds(); if($channel_ids){ $mediums=$this->db->select("DISTINCT medium_id", false)->from("budget_channels")->where_in("id", $channel_ids)->get()->result_array(); $medium_ids=[0]; foreach($mediums as $m){ $medium_ids[]=$m['medium_id']; } $this->db->where_in("m.id", $medium_ids); } if(strlen($qs['status'])){ $this->db->where("m.status", $qs['status']); } if($qs['k']){ $this->db->group_start(); $this->db->like("m.name", $qs['k']); $this->db->group_end(); } $this->db->select("m.*") ->from("budget_mediums m") ->order_by("m.disp_odr"); if($all){ $rs['data']=$this->db->get()->result_array(); }else{ $rs=$this->dba->pagedRowsNew($qs['p'], $qs['ps']); } foreach($rs['data'] as &$r){ $r['channels_count']=$this->db->where('medium_id', $r['id'])->count_all_results('budget_channels'); } return $rs; } function deleteMedium($id){ $this->db->db_debug=FALSE; $this->db->delete("budget_mediums", ['id'=>$id]); return $this->db->affected_rows()>0; } function channels($all=false){ $qs=trimArray($this->input->get()); $channel_ids=$this->userChannelIds(); if($channel_ids){ $this->db->where_in("c.id", $channel_ids); } if(strlen($qs['status'])){ $this->db->where("c.status", $qs['status']); } if($qs['medium_id']){ $this->db->where("c.medium_id", $qs['medium_id']); } if($qs['k']){ $this->db->group_start(); $this->db->like("c.name", $qs['k']); $this->db->group_end(); } $this->db->select("c.*, m.name medium") ->from("budget_channels c") ->join("budget_mediums m", "m.id=c.medium_id") ->order_by("m.disp_odr") ->order_by("c.disp_odr"); if($all){ $rs['data']=$this->db->get()->result_array(); }else{ $rs=$this->dba->pagedRowsNew($qs['p'], $qs['ps']); } foreach($rs['data'] as &$r){ } return $rs; } function deleteChannel($id){ $this->db->db_debug=FALSE; $this->db->delete("budget_channels", ['id'=>$id]); return $this->db->affected_rows()>0; } function users($all=false){ $qs=trimArray($this->input->get()); if(strlen($qs['status'])){ $this->db->where("u.status", $qs['status']); } if($qs['type']){ $this->db->where("u.type", $qs['type']); } if($qs['types']){ $this->db->where_in("u.type", explode(",", $qs['types'])); } if($qs['k']){ $this->db->group_start(); $this->db->like("u.name", $qs['k'])->or_like("u.email", $qs['k']); $this->db->group_end(); } $this->db->select("u.id, u.name, u.email, u.type, u.reporting_type, u.budget_channel_ids, u.status") ->from("users u") ->where(["u.type!="=>"ADMIN", "u.type!="=>"PUBLISHER"]) ->order_by("u.name"); if($all){ $rs['data']=$this->db->get()->result_array(); }else{ $rs=$this->dba->pagedRowsNew($qs['p'], $qs['ps']); } foreach($rs['data'] as &$r){ $r['status']=(int)$r['status']; $r['budget_channel_ids']=$r['budget_channel_ids']?explode(",", $r['budget_channel_ids']):[]; } return $rs; } function userChannelIds(){ $channels=$this->db->select("budget_channel_ids")->get_where("users", ['id'=>USER_ID])->row("budget_channel_ids"); return $channels?explode(",", $channels):[]; } } //End of file