<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class CT_monthlyreport extends CI_Controller {
    function __construct()
    {
        parent::__construct();
		if (!$this->dx_auth->is_logged_in()) {
            header('HTTP/1.1 401 Unauthorize');die('expire');
        }

        $uid = $this->session->userdata('DX_user_id');

        if(!permissionAuth(2) && $uid != RID){
            header('HTTP/1.1 401 Unauthorize');die('noaccess');
        }

        $session_arr = $this->session->userdata('DX_permission');
        $u_readonly = $session_arr['readonly']; 
    }
    
	function in23(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_rpMonthlyIncoming_BC23');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_in23',$data);
		
	}
	
	function load_in23(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_rpMonthlyIncoming_BC23';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	} 
	
	function print_in23(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_rpMonthlyIncoming_BC23'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	
	/* ======================================================================================================= */
	
	function out30(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_rpMonthlyOutgoing_BC30');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_out30',$data);
		
	}
	
	function load_out30(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_rpMonthlyOutgoing_BC30';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	} 
	
	function print_out30(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_rpMonthlyOutgoing_BC30'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	
	/* ======================================================================================================= */
	
	function bc23(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_BC23');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_bc23',$data);
		
	}
	
    function load_bc23(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_BC23';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_bc23(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_BC23'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	
	/* ======================================================================================================= */
	function bc262(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_262');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_bc262',$data);
		
	}
	
	function load_bc262(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_262';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_bc262(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_262'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	/* ======================================================================================================= */
	
	function bc27(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_BC27_IN');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_bc27',$data);
		
	}
	
	function load_bc27(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_BC27_IN';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_bc27(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_BC27_IN'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	
	/* ======================================================================================================= */
	
	function bc40(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_BC40');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_bc40',$data);
		
	}
	
	function load_bc40(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_BC40';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_bc40(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_BC40'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	
	/* ======================================================================================================= */
	function bc25(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_BC25');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_bc25',$data);
		
	}
	
	function load_bc25(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_BC25';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_bc25(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_BC25'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	
	/* ======================================================================================================= */
	function bc261(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_261');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_bc261',$data);
		
	}
	
	function load_bc261(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_261';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';		
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_bc261(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_261'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	
	/* ======================================================================================================= */
	function bc271(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_BC27_OUT');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_bc271',$data);
		
	}
	
	function load_bc271(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_BC27_OUT';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_bc271(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_BC27_OUT'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	/* ======================================================================================================= */
	function bc30(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_BC30');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_bc30',$data);
		
	}
	
	function load_bc30(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_BC30';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_bc30(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_BC30'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	/* ======================================================================================================= */
	function bc41(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_BC41');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_bc41',$data);
		
	}
	
	function load_bc41(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_BC41';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_bc41(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_BC41'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	/* ======================================================================================================= */
	
	function dpil(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_KB_DPIL');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_dpil',$data);
		
	}
	
	function load_dpil(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_KB_DPIL';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_dpil(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_KB_DPIL'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	/* ======================================================================================================= */
	function kb(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_KB_KB');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_kb',$data);
		
	}
	
	function load_kb(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_KB_KB';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_kb(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_KB_KB'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	/* ======================================================================================================= */
	function ekonomi(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_KB_EKONOMI');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_ekonomi',$data);
		
	}
	
	function load_ekonomi(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_KB_EKONOMI';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_ekonomi(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_KB_EKONOMI'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	/* ======================================================================================================= */
	
	function ekspor(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_KB_EKSPOR');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_ekspor',$data);
		
	}
	
	function load_ekspor(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_KB_EKSPOR';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_ekspor(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_KB_EKSPOR'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	/* ======================================================================================================= */
		
	function  retur(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_RETURN');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_return',$data);
		
	}
	
	function load_retur(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_RETURN';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		 
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'start_date',$start_date);   
		AddField($xmldoc,'end_date',$end_date);   
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		foreach ($rows as $per_row) {
				foreach ($def_col as $key => $value) {
				 $responce->rows[$i][$key]=getXMLValue($per_row,$def_col[$key]['db'] );
				} 
		$i++;
		} 
		echo json_encode($responce);
		
	}  

	function print_retur(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_RETURN'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'start_date',$start_date);   
	    AddField($xmldata,'end_date',$end_date);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	
	/* ======================================================================================================= */
	
	function rekap(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_REKAP');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['periode_rekap'] 		= date("Y_m");
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_rekap',$data);
		
	}
	
    function load_rekap(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_REKAP';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		$periode_rekap =  isset($_POST['periode_rekap'])?$_POST['periode_rekap']:date("Y_m");
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'periode_rekap',$periode_rekap); 
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		$responce->rows[$i]['no']= 1;
		$responce->rows[$i]['nama_pt']= $detail['nama_pt'];
		$responce->rows[$i]['param3']= $detail['param3'];
		$responce->rows[$i]['param4']= $detail['param4'];
		$responce->rows[$i]['param5']= $detail['param5'];
		$responce->rows[$i]['param6']= $detail['param6'];
		$responce->rows[$i]['param7']= $detail['param7'];
		$responce->rows[$i]['param8']= $detail['param8'];
		$responce->rows[$i]['param9']= $detail['param9'];
		$responce->rows[$i]['param10']= $detail['param10'];
		$responce->rows[$i]['param11']= $detail['param11'];
		$responce->rows[$i]['param12']= $detail['param12'];
		$responce->rows[$i]['param13']= $detail['param13'];
		$responce->rows[$i]['param14']= $detail['param14'];
		$responce->rows[$i]['param15']= $detail['param15'];
		$responce->rows[$i]['param16']= $detail['param16'];
		$responce->rows[$i]['param17']= $detail['param17'];
		$responce->rows[$i]['param18']= $detail['param18'];
		$responce->rows[$i]['param19']= $detail['param19'];
		$responce->rows[$i]['param20']= $detail['param20'];
		$responce->rows[$i]['param21']= $detail['param21'];
		$responce->rows[$i]['param22']= $detail['param22'];
		$responce->rows[$i]['param23']= $detail['param23'];
		$responce->rows[$i]['param24']= $detail['param24'];
		$responce->rows[$i]['param25']= $detail['param25'];
		$responce->rows[$i]['param26']= $detail['param26'];
		$responce->rows[$i]['param27']= $detail['param27'];
		$responce->rows[$i]['param28']= $detail['param28'];
		
		
		echo json_encode($responce);
		
	}  

	function print_rekap(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		$periode_rekap =  isset($_POST['periode_rekap'])?$_POST['periode_rekap']:date("Y_m");	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_REKAP'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'periode_rekap',$periode_rekap);
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	
	
	//============================================================================================
	
	function devisa(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_DEVISA');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['periode_devisa'] 		= date("Y_m");
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_devisa',$data);
		
	}
	
	function load_devisa(){
		$def_col= array();
		$spt='dbo.MG_PEMI_RPT_DEVISA';  
		$def_col['rownumber']=array("db" => "rn" ,"sc" => "rn","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"text", "bypassvalue"=>"");
		  
		
		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
		$show_cancel =  isset($_POST['show_cancel'])?$_POST['show_cancel']:'';		
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		$periode_devisa =  isset($_POST['periode_devisa'])?$_POST['periode_devisa']:date("Y_m");	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 

 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'20130128';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'20130528';

		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
		 
		$fsidx=$def_col[$sidx]; 
		if ($fsidx !=null) 
			$sidx=$fsidx['db']; 
		else 
			$sidx='r1'; //DEFAULT SORT KALU GA ADA  
			 
		$xmldoc =  XMLbasic($spt); 
		paramView($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc,'mode','1');
		AddField($xmldoc,'format',''); 
		AddField($xmldoc,'periode_devisa',$periode_devisa);  
		AddField($xmldoc,'source',$source);

		if ($search == 'true'){ 
			if (!empty($filters)){ 
				$array = json_decode($filters); 
				foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
						if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']){
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1'); 
								}  
							} 
							elseif ($fcr['ctype']=='text'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
								 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
				 } 
			 } 
		}  
		 
		connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 

		$sordby = $detail['sort']; 
		$sordtype = $detail['desc'];
		$record = $detail['rowspage']; 
		$totalrow = $detail['rows']; 
		if ($detail['pages'])
		$totalpages = $detail['pages'];   
		
        $responce->page = $page;
		$responce->records = $totalrow ; 
 		
       	if ($detail['pages'])
        $responce->total = $totalpages;

		$i=0; 
		$responce->rows[$i]['no']= 1;
		$responce->rows[$i]['nama_pt']= $detail['nama_pt'];
		$responce->rows[$i]['param3']= $detail['param3'];
		$responce->rows[$i]['param4']= $detail['param4'];
		$responce->rows[$i]['param5']= $detail['param5'];
		$responce->rows[$i]['param6']= $detail['param6'];
		$responce->rows[$i]['param7']= $detail['param7'];
		$responce->rows[$i]['param8']= $detail['param8'];
		$responce->rows[$i]['param9']= $detail['param9'];
		$responce->rows[$i]['param10']= $detail['param10'];
		$responce->rows[$i]['param11']= $detail['param11'];
		$responce->rows[$i]['param12']= $detail['param12'];
		$responce->rows[$i]['param13']= $detail['param13'];
		$responce->rows[$i]['param14']= $detail['param14'];
		
		$i++;
		
		echo json_encode($responce);
	}  

	function print_devisa(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		$periode_devisa =  isset($_POST['periode_devisa'])?$_POST['periode_devisa']:date("Y_m");	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_DEVISA'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'periode_devisa',$periode_devisa); 
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	/* ======================================================================================================= */
	
	function  pengantar(){
		$xmldoc =  XMLbasic('dbo.MG_PEMI_RPT_PENGANTAR');
		$str = $xmldoc->saveXML();
		connectwebservice($str, '',$sts,$des,$rows,$detail);
		$i=0;
		$data['rID'][$i]='';
		if ($rows != null){
			foreach ($rows as $per_row) {
				$data['rID'][$i] 	=	getXMLValue($per_row,'rID');
				
				$i++;
			}
		}
		
		$data['end_date'] 		= date("Y-m-d");
		$data['start_date'] 	= date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
		
		
		$data['end_date_grid'] 	= date("Ymd");		
		$data['start_date_grid']= date("Ymd", strtotime( date( "Ymd", strtotime( date("Ymd") ) ) . "-1 month" ) );
		
		
        $this->load->view('reports/monthly_report/view_pengantar',$data);
		
	}
	
	function print_pengantar(){
 		$start_date = isset($_POST['start_date'])?$_POST['start_date']:'';
		$end_date = isset($_POST['end_date'])?$_POST['end_date']:'';
		$format 	= isset($_POST['format'])?$_POST['format']:'';
 		$mode		= "2";
		$source =  isset($_POST['source'])?$_POST['source']:'All';	
		$periode_pengantar =  isset($_POST['periode_pengantar'])?$_POST['periode_pengantar']:date("Y_m");	
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'r1'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
        if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; }
		 
		$xmldata = XMLbasic('dbo.MG_PEMI_RPT_PENGANTAR'); 
		AddField($xmldata,'data_by',$this->session->userdata('DX_user_id'));
    	AddField($xmldata,'periode_pengantar',$periode_pengantar); 
     	AddField($xmldata,'mode',$mode);
		AddField($xmldata,'format',$format);
		AddField($xmldata,'temp_folder',sys_get_temp_dir()); 
		AddField($xmldata,'source',$source);  


		connectwebservice($xmldata->saveXML(), '',$stsno,$stsdes,$rows,$detail);
		#print_r(connectwebservice()); 
		$namafile='';
		$data = ''; // data passed to a function or via $_POST['data']
		if ($stsno=='00'){
		saveMyFile($rows,$namafile,$savedFile);
		}
		$responce = array("sts" => $stsno, "desc" => ' '.$stsdes, "filename" => ''.$savedFile, "filenamex" => ''.$namafile );

		$this->print_sp3k($savedFile, $namafile);
		echo json_encode($responce);

 	}
	
	function print_sp3k ($filename, $filenamex ){
		printMyFile($filename ,$filenamex); 
	}
}
    



?>