<?php
class CT_reportcustoms 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');
        } 
        $CI =& get_instance(); 
	    $CI->db_pasi = $CI->load->database('pasi', TRUE);
		//$this->load->library("fpdf"); 
		$this->load->model("pasi_reports/mdl_reports", 'pasi_mdl_reports');	
  }

	function index(){
		$this->load->view('pasi_reports/view_reportcustoms');
	}
  
	function view_laporanpemasukanbarangperdokumen(){
		$data['tanggal'] = date('m/d/Y');	
		$this->load->view('pasi_reports/view_reportcustomspemasukanbarang', $data);
	}
	
	function view_laporanpengeluaranbarangperdokumen(){
		$data['tanggal'] = date('m/d/Y');
		$this->load->view('pasi_reports/view_reportcustomspengeluaranbarang',$data);
	}
	
	function view_laporanbarangwip(){
		$data['tanggal'] = date('m/d/Y');
		$this->load->view('pasi_reports/view_reportcustomsbarangwip',$data);	
	}
	
	function view_laporanbahanbaku(){
		$data['tanggal'] = date('d/m/Y');
		$this->load->view('pasi_reports/view_reportcustomsbahanbaku',$data);	
	}
	function view_laporanbarangjadi(){
		$data['tanggal'] = date('m/d/Y');
		$this->load->view('pasi_reports/view_reportcustomsbarangjadi',$data);		
	}
	function view_laporanbarangsisa(){
		$data['tanggal'] = date('m/d/Y');
		$this->load->view('pasi_reports/view_reportcustomsbarangsisa',$data);			
	}
	function view_laporanmesin(){
		$data['tanggal'] = date('m/d/Y');
		$this->load->view('pasi_reports/view_reportcustomsmesin',$data);			
	}
	
	function data_laporanpemasukanbarangperdokumen(){
  
		$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']:'';
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:20; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'id_incoming_rm'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$caritanggal = (isset($_POST['caritanggal']) && !empty($_POST['caritanggal']))?$_POST['caritanggal']:'';
		
		$tglawallaporanpemasukanbarang = (isset($_POST['tglawallaporanpemasukanbarang']) && !empty($_POST['tglawallaporanpemasukanbarang']))?$_POST['tglawallaporanpemasukanbarang']:'';
		$tglakhirlaporanpemasukanbarang = (isset($_POST['tglakhirlaporanpemasukanbarang']) && !empty($_POST['tglakhirlaporanpemasukanbarang']))?$_POST['tglakhirlaporanpemasukanbarang']:'';
		
		//$where = " 1 = 1 and tbl_pemasukan_barang.tgl_receive>= convert(date,'$tglawallaporanpemasukanbarang',103) and tbl_pemasukan_barang.tgl_receive  <= convert(date,'$tglakhirlaporanpemasukanbarang',103) ";
		$where = " 1 = 1 and tbl_pemasukan_barang.tgl_receive BETWEEN '$tglawallaporanpemasukanbarang' and '$tglakhirlaporanpemasukanbarang' ";
		//$where = " 1 = 1 and tbl_pemasukan_barang.tgl_receive BETWEEN '$tglawallaporanpemasukanbarang' and '$tglakhirlaporanpemasukanbarang' ";
		
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){

					if ( $k->field == "type_bc" ) {
						$searchString = $k->data;
						$where .= " and type_bc like  '%".$searchString."%'"; 	
					} else if ( $k->field == "no_daftar" ) {
						$searchString = $k->data;
						$where .= " and no_daftar like  '%".$searchString."%'";	
					} else if ( $k->field == "tgl_nodaf" ) {
						$searchString = $k->data;
						$where .= " and tgl_nodaf like  '%".$searchString."%'";	
					} else if ( $k->field == "no_receive" ) {
						$searchString = $k->data;
						$where .= " and no_receive like  '%".$searchString."%'";	
					}  else if ( $k->field == "tgl_receive" ) {
						$searchString = $k->data;
						$where .= " and tgl_receive like  '%".$searchString."%'";	
					}  else if ( $k->field == "pemasok" ) {
						$searchString = $k->data;
						$where .= " and pemasok like  '%".$searchString."%'";	
					} 
				}
			}
		}

		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->pasi_mdl_reports->datareportpemasukanbarangperdokumen_All($limit,$start,$sidx,$sord, $where);
		$count = $this->pasi_mdl_reports->datareportpemasukanbarangperdokumen_CountAll($where);
		if( $count > 0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } 
        if ($page > $total_pages) $page=$total_pages;
        
        $responce->page = $page;
		$responce->total = $total_pages;
		$responce->records =  $count;
		$i=0;
        
		foreach($records as $r){
 
			$responce->rows[$i]['id_incoming_rm']=$r->id_incoming_rm; 
			$responce->rows[$i]['type_bc']=$r->type_bc; 
			$responce->rows[$i]['no_daftar']=$r->no_daftar; 
			$responce->rows[$i]['tgl_nodaf']=$r->tgl_nodaf; 
			$responce->rows[$i]['no_receive']=$r->no_receive; 
			$responce->rows[$i]['tgl_receive']=$r->tgl_receive; 
			$responce->rows[$i]['pemasok']=$r->pemasok; 
			$responce->rows[$i]['kode_brg']=$r->kode_brg; 
			$responce->rows[$i]['nama_brg']=$r->nama_brg; 
			$responce->rows[$i]['satuan']=$r->satuan; 
			$responce->rows[$i]['jumlah']=$r->jumlah; 
			$responce->rows[$i]['nilai_barang']=$r->nilai_barang; 
			$responce->rows[$i]['create_date']=$r->create_date; 
			$responce->rows[$i]['create_by']=$r->create_by; 
			$responce->rows[$i]['update_date']=$r->update_date; 
			$responce->rows[$i]['update_by']=$r->update_by;
			$responce->rows[$i]['update_by']=$r->update_by;
			
			$i++;
			
		}
		echo json_encode($responce);
		
	}
	
	function data_laporanpengeluaranbarangperdokumen(){
 
		$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']:'';
		
		$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
        $limit = isset($_POST['rows'])?$_POST['rows']:20; // get how many rows we want to have into the grid
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'id_outgoing_rm'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$caritanggal = (isset($_POST['caritanggal']) && !empty($_POST['caritanggal']))?$_POST['caritanggal']:'';
		
		$tglawallaporanpengeluaranbarang = (isset($_POST['tglawallaporanpengeluaranbarang']) && !empty($_POST['tglawallaporanpengeluaranbarang']))?$_POST['tglawallaporanpengeluaranbarang']:'';
		$tglakhirlaporanpengeluaranbarang = (isset($_POST['tglakhirlaporanpengeluaranbarang']) && !empty($_POST['tglakhirlaporanpengeluaranbarang']))?$_POST['tglakhirlaporanpengeluaranbarang']:'';
		
		//$where = " 1 = 1 and tbl_pemasukan_barang.tgl_receive>= convert(date,'$tglawallaporanpemasukanbarang',103) and tbl_pemasukan_barang.tgl_receive  <= convert(date,'$tglakhirlaporanpemasukanbarang',103) ";
		$where = " 1 = 1 and tbl_outgoing_item.tgl_out BETWEEN '$tglawallaporanpengeluaranbarang' and '$tglakhirlaporanpengeluaranbarang' ";
		//$where = " 1 = 1 and tbl_pemasukan_barang.tgl_receive BETWEEN '$tglawallaporanpemasukanbarang' and '$tglakhirlaporanpemasukanbarang' ";
		
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){

					if ( $k->field == "type_bc" ) {
						$searchString = $k->data;
						$where .= " and type_bc like  '%".$searchString."%'"; 	
					} else if ( $k->field == "no_daftar" ) {
						$searchString = $k->data;
						$where .= " and no_daftar like  '%".$searchString."%'";	
					} else if ( $k->field == "tgl_nodaf" ) {
						$searchString = $k->data;
						$where .= " and tgl_nodaf like  '%".$searchString."%'";	
					} else if ( $k->field == "no_out" ) {
						$searchString = $k->data;
						$where .= " and no_out like  '%".$searchString."%'";	
					}  else if ( $k->field == "tgl_out" ) {
						$searchString = $k->data;
						$where .= " and tgl_out like  '%".$searchString."%'";	
					}  else if ( $k->field == "pembeli" ) {
						$searchString = $k->data;
						$where .= " and pembeli like  '%".$searchString."%'";	
					} 
				}
			}
		}

		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->pasi_mdl_reports->datareportpengeluaranbarangperdokumen_All($limit,$start,$sidx,$sord, $where);
		$count = $this->pasi_mdl_reports->datareportpengeluaranbarangperdokumen_CountAll($where);
		if( $count > 0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } 
        if ($page > $total_pages) $page=$total_pages;
        
        $responce->page = $page;
		$responce->total = $total_pages;
		$responce->records =  $count;
		$i=0;
        
		foreach($records as $r){
 
			$responce->rows[$i]['id_outgoing_rm']=$r->id_outgoing_rm; 
			$responce->rows[$i]['type_bc']=$r->type_bc; 
			$responce->rows[$i]['no_daftar']=$r->no_daftar; 
			$responce->rows[$i]['tgl_nodaf']=$r->tgl_nodaf; 
			$responce->rows[$i]['no_out']=$r->no_out; 
			$responce->rows[$i]['tgl_out']=$r->tgl_out; 
			$responce->rows[$i]['pembeli']=$r->pembeli; 
			$responce->rows[$i]['kode_brg']=$r->kode_brg; 
			$responce->rows[$i]['nama_brg']=$r->nama_brg; 
			$responce->rows[$i]['satuan']=$r->satuan; 
			$responce->rows[$i]['jumlah']=$r->jumlah; 
			$responce->rows[$i]['nilai_barang']=$r->nilai_barang; 
			$responce->rows[$i]['create_date']=$r->create_date; 
			$responce->rows[$i]['create_by']=$r->create_by; 
			$responce->rows[$i]['update_date']=$r->update_date; 
			$responce->rows[$i]['update_by']=$r->update_by;
			$responce->rows[$i]['update_by']=$r->update_by;
			
			$i++;
			
		}
		echo json_encode($responce);		
	}
	
	function data_laporanbahanbaku(){
		$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']:'';
		
		$page 	= isset($_POST['page'])?$_POST['page']:1; // get the requested page
		$limit 	= isset($_POST['rows'])?$_POST['rows']:20; // get how many rows we want to have into the grid
		$sidx 	= isset($_POST['sidx'])?$_POST['sidx']:'id_mutasi_bb'; // get index row - i.e. user click to sort
		$sord 	= isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
			
		$where = " 1=1 ";
		
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){

				if ( $k->field == "No_Invoice" ) {
						$searchString = $k->data;
						$where .= " and No_Invoice like  '%".$searchString."%'"; 	
					} 
				}
			}
		}
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->pasi_mdl_reports->datareportbahanbaku_All($limit,$start,$sidx,$sord, $where);
		$count = $this->pasi_mdl_reports->datareportbahanbaku_CountAll($where);
		if( $count > 0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } 
		if ($page > $total_pages) $page=$total_pages;
		
		$responce->page = $page;
		$responce->total = $total_pages;
		$responce->records =  $count;
		$i=0;
		foreach($records as $r){
		
			$responce->rows[$i]['id_mutasi_bb']=$r->id_mutasi_bb;
			$responce->rows[$i]['kdbrg']=$r->kdbrg;
			$responce->rows[$i]['nama_barang']=$r->nama_barang;
			$responce->rows[$i]['satuan']=$r->satuan;
			$responce->rows[$i]['stock_awal']=$r->stock_awal;
			$responce->rows[$i]['pemasukan']=$r->pemasukan;
			$responce->rows[$i]['pengeluaran']=$r->pengeluaran;
			$responce->rows[$i]['penyesuaian']=$r->penyesuaian;
			$responce->rows[$i]['saldo_akhir']=$r->saldo_akhir;
			$responce->rows[$i]['stock_opname']=$r->stock_opname;
			$responce->rows[$i]['selisih']=$r->selisih;
			$responce->rows[$i]['keterangan']=$r->keterangan;
			
			$i++;
		}
		echo json_encode($responce);		
			
	}
	
	function getLaporanBahanBaku(){
		$tglawallaporanbahanbaku  =(isset($_POST['tglawallaporanbahanbaku']) && !empty($_POST['tglawallaporanbahanbaku']))?$_POST['tglawallaporanbahanbaku']:'';
		$tglakhirlaporanbahanbaku =(isset($_POST['tglakhirlaporanbahanbaku']) && !empty($_POST['tglakhirlaporanbahanbaku']))?$_POST['tglakhirlaporanbahanbaku']:'';
		
		//echo "exec('sp_mutasi_bahan_baku_penolong @date_start=''$tglawallaporanbahanbaku'' , @date_end=''$tglakhirlaporanbahanbaku''')";die();
		
			$qry = $this->db_pasi->query("
			
				BEGIN TRY
					exec('sp_mutasi_bahan_baku_penolong @date_start=''$tglawallaporanbahanbaku'' , @date_end=''$tglakhirlaporanbahanbaku''')
				END TRY
				BEGIN CATCH
				SELECT 
					'06' AS STATUS
					,ERROR_MESSAGE() AS DESCRIPTION;
				END CATCH
				
			 ");
			 
		 $rs = $qry->result_array();
		 foreach ($rs as $row){
			 $responce = array("sts" => $row['STATUS'], "desc" => $row['DESCRIPTION']);
		 }  
		 echo json_encode($responce);
	}

	function view_reportcustomswip_excel(){

			$qry= $this->db_pasi->query("

				SELECT [id_mutasi_wip]
					  ,[date_start]
					  ,[date_end]
					  ,[kdbrg] as kodebarang
					  ,[nama_barang]  as namabarang
					  ,[satuan]  as satuan
					  ,[stock_awal]  as stock_awal
					  ,[pemasukan]  as pemasukan
					  ,[pengeluaran]  as pengeluaran
					  ,[saldo_akhir]  as saldoakhir
					  ,[keterangan] as keterangan
				FROM [DB_PASI_NEW].[dbo].[tbl_mutasi_wip]  			
				
			 ");
			$rs = $qry->result_array();
		
		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle('Sheet1');
		//set cell A1 content with some text
		//$this->excel->getActiveSheet()->setCellValue('A1', 'This is just some text value');
		//change the font size
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
		//make the font become bold
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
		//merge cell A1 until D1
		//$this->excel->getActiveSheet()->mergeCells('A1:D1');
		//set aligment to center for that merged cell (A1 to D1)
		//eta nya, iya pemasukannya jg.. jadi apa?  A.
		$this->excel->getActiveSheet()->setCellValue('A2', 'C. LAPORAN PERTANGGUNG JAWABAN POSISI BARANG DALAM PROSES');
		$this->excel->getActiveSheet()->setCellValue('A3', 'KAWASAN BERIKAT: P.T AUTOCOMP SYSTEMS INDONESIA');
		$this->excel->getActiveSheet()->setCellValue('A5', 'Alamat');
		$this->excel->getActiveSheet()->setCellValue('D5', ':     JL. RAYA SERANG KM 24 BALARAJA  TANGERANG');
		$this->excel->getActiveSheet()->setCellValue('A6', 'Periode');
		$this->excel->getActiveSheet()->setCellValue('D6', ': ');
		$this->excel->getActiveSheet()->setCellValue('F6', 's/d');
		$this->excel->getActiveSheet()->setCellValue('A8', 'NO. URUT');
		$this->excel->getActiveSheet()->setCellValue('B8', 'KODE BARANG');
		$this->excel->getActiveSheet()->setCellValue('C8', 'NAMA BARANG');
		$this->excel->getActiveSheet()->setCellValue('D8', 'SATUAN');
		$this->excel->getActiveSheet()->setCellValue('E8', 'STOCK AWAL');
		$this->excel->getActiveSheet()->setCellValue('F8', 'PEMASUKAN');
		$this->excel->getActiveSheet()->setCellValue('G8', 'PENGELUARAN');
		$this->excel->getActiveSheet()->setCellValue('H8', 'SALDO AKHIR');
		$this->excel->getActiveSheet()->setCellValue('I8', 'KETERANGAN');
		
		$i = 1;
		$j = '';
		$k = 8;
		
		foreach ($rs as $row){
			$k = 8 + $i;
			$j = "$k";
				$this->excel->getActiveSheet()->setCellValue("E6", $row['date_start']);
				$this->excel->getActiveSheet()->setCellValue("G6", $row['date_end']);
				$this->excel->getActiveSheet()->setCellValue("A".$j, $i);
				$this->excel->getActiveSheet()->setCellValue("B".$j, $row['kodebarang']);
				$this->excel->getActiveSheet()->setCellValue("C".$j, $row['namabarang']);
				$this->excel->getActiveSheet()->setCellValue("D".$j, $row['satuan']);
				$this->excel->getActiveSheet()->setCellValue("E".$j, $row['stock_awal']);
				$this->excel->getActiveSheet()->setCellValue("F".$j, $row['pemasukan']);
				$this->excel->getActiveSheet()->setCellValue("G".$j, $row['pengeluaran']);				
				$this->excel->getActiveSheet()->setCellValue('H'.$j, $row['saldoakhir']);
				$this->excel->getActiveSheet()->setCellValue('I'.$j, $row['keterangan']);				


				$i++;
		}
		
		$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		 
		$filename='laporanmutasiwip'.date('Ymd').'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
					 
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
			 

	}
	
	function view_reportcustomspemasukanbarang_excel(){

		$tglawallaporanpemasukanbarang  =(isset($_GET['tglawallaporanpemasukanbarang']) && !empty($_GET['tglawallaporanpemasukanbarang']))?$_GET['tglawallaporanpemasukanbarang']:'';
		$tglakhirlaporanpemasukanbarang  =(isset($_GET['tglakhirlaporanpemasukanbarang']) && !empty($_GET['tglakhirlaporanpemasukanbarang']))?$_GET['tglakhirlaporanpemasukanbarang']:'';
		
		
		//echo $tglawallaporanpemasukanbarang;die();
		
			$qry= $this->db_pasi->query("

				SELECT [id_incoming_rm]
				  ,[type_bc] as tipebc
				  ,[no_daftar] as nodaftar
				  ,[tgl_nodaf] as tgldaftar
				  ,[no_receive] as noreceive
				  ,[tgl_receive] as tglreceive
				  ,[pemasok] as pemasok
				  ,[kode_brg] as kodebrg
				  ,[nama_brg] as namabrg
				  ,[satuan] as satuan
				  ,[jumlah] as jumlah
				FROM [DB_PASI_NEW].[dbo].[tbl_pemasukan_barang]	 where tgl_nodaf between '$tglawallaporanpemasukanbarang' and '$tglakhirlaporanpemasukanbarang'
				
			 ");
			$rs = $qry->result_array();
		
		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle('Sheet1');
		//set cell A1 content with some text
		//$this->excel->getActiveSheet()->setCellValue('A1', 'This is just some text value');
		//change the font size
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
		//make the font become bold
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
		//merge cell A1 until D1
		//$this->excel->getActiveSheet()->mergeCells('A1:D1');
		//set aligment to center for that merged cell (A1 to D1)
		//mana lagi pengeluaran B.
		$this->excel->getActiveSheet()->setCellValue('A2', 'A. LAPORAN PERTANGGUNG JAWABAN PEMASUKAN BARANG PER DOKUMEN PABEAN');
		$this->excel->getActiveSheet()->setCellValue('A3', 'KAWASAN BERIKAT: P.T AUTOCOMP SYSTEMS INDONESIA');
		$this->excel->getActiveSheet()->setCellValue('A5', 'Alamat');
		$this->excel->getActiveSheet()->setCellValue('D5', ':     JL. RAYA SERANG KM 24 BALARAJA  TANGERANG');
		$this->excel->getActiveSheet()->setCellValue('A6', 'Periode ');
		$this->excel->getActiveSheet()->setCellValue('D6', ': ');
		$this->excel->getActiveSheet()->setCellValue('F6', $tglawallaporanpemasukanbarang.' s/d '.$tglakhirlaporanpemasukanbarang);
		$this->excel->getActiveSheet()->setCellValue('A8', 'NO. URUT');
		$this->excel->getActiveSheet()->setCellValue('B8', 'TIPE BC');
		$this->excel->getActiveSheet()->setCellValue('C8', 'NOMOR DAFTAR');
		$this->excel->getActiveSheet()->setCellValue('D8', 'TANGGAL DAFTAR');

		$this->excel->getActiveSheet()->setCellValue('E8', 'NOMOR PENERIMAAN');
		$this->excel->getActiveSheet()->setCellValue('F8', 'TANGGAL PENERIMAAN');
		$this->excel->getActiveSheet()->setCellValue('G8', 'NAMA PEMASOK');
		
		$this->excel->getActiveSheet()->setCellValue('H8', 'KODE BARANG');
		$this->excel->getActiveSheet()->setCellValue('I8', 'NAMA BARANG');
		$this->excel->getActiveSheet()->setCellValue('J8', 'SATUAN');
		$this->excel->getActiveSheet()->setCellValue('K8', 'JUMLAH');
		
		$i = 1;
		$j = '';
		$k = 8;

		foreach ($rs as $row){
			$k = 8 + $i;
			$j = "$k";
				//$this->excel->getActiveSheet()->setCellValue("E6", $row['date_start']);
				//$this->excel->getActiveSheet()->setCellValue("G6", $row['date_end']);
				$this->excel->getActiveSheet()->setCellValue("A".$j, $i);
				$this->excel->getActiveSheet()->setCellValue("B".$j, $row['tipebc']);
				$this->excel->getActiveSheet()->setCellValue("C".$j, $row['nodaftar']);
				$this->excel->getActiveSheet()->setCellValue("D".$j, $row['tgldaftar']);
				$this->excel->getActiveSheet()->setCellValue("E".$j, $row['noreceive']);
				$this->excel->getActiveSheet()->setCellValue("F".$j, $row['tglreceive']);
				$this->excel->getActiveSheet()->setCellValue("G".$j, $row['pemasok']);
				$this->excel->getActiveSheet()->setCellValue("H".$j, $row['kodebrg']);				

				$this->excel->getActiveSheet()->setCellValue('I'.$j, $row['namabrg']);
				$this->excel->getActiveSheet()->setCellValue('J'.$j, $row['satuan']);
				$this->excel->getActiveSheet()->setCellValue('K'.$j, $row['jumlah']);
				//$this->excel->getActiveSheet()->setCellValue('I'.$j, $row['keterangan']);				


				$i++;
		}
		
		$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		 
		$filename='laporanpemasukanbahanbaku'.date('Ymd').'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
					 
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
			 

	}

	function view_reportcustomspengeluaranbarang_excel(){

		$tglawallaporanpengeluaranbarang  =(isset($_GET['tglawallaporanpengeluaranbarang']) && !empty($_GET['tglawallaporanpengeluaranbarang']))?$_GET['tglawallaporanpengeluaranbarang']:'';
		$tglakhirlaporanpengeluaranbarang  =(isset($_GET['tglakhirlaporanpengeluaranbarang']) && !empty($_GET['tglakhirlaporanpengeluaranbarang']))?$_GET['tglakhirlaporanpengeluaranbarang']:'';
		
			$qry= $this->db_pasi->query("

			SELECT [id_outgoing_rm]
				  ,[type_bc] as tipebc
				  ,[no_daftar] as nodaftar
				  ,[tgl_nodaf] as tgldaftar
				  ,[no_out] as nokeluar
				  ,[tgl_out] as tglkeluar
				  ,[pembeli] as pembeli
				  ,[kode_brg] as kodebrg
				  ,[nama_brg] as namabrg
				  ,[satuan] as satuan
				  ,[jumlah] as jumlah
				  ,[nilai_barang] as nilaibarang
	  
				FROM [DB_PASI_NEW].[dbo].[tbl_outgoing_item]  where tgl_nodaf between '$tglawallaporanpengeluaranbarang' and '$tglakhirlaporanpengeluaranbarang'
				
			 ");
			$rs = $qry->result_array();
		
		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle('Sheet1');
		//set cell A1 content with some text
		//$this->excel->getActiveSheet()->setCellValue('A1', 'This is just some text value');
		//change the font size
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
		//make the font become bold
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
		//merge cell A1 until D1
		//$this->excel->getActiveSheet()->mergeCells('A1:D1');
		//set aligment to center for that merged cell (A1 to D1)

				  
		$this->excel->getActiveSheet()->setCellValue('A2', 'B. LAPORAN PERTANGGUNG JAWABAN PENGELUARAN BARANG PER DOKUMEN PABEAN');
		$this->excel->getActiveSheet()->setCellValue('A3', 'KAWASAN BERIKAT: P.T AUTOCOMP SYSTEMS INDONESIA');
		$this->excel->getActiveSheet()->setCellValue('A5', 'Alamat');
		$this->excel->getActiveSheet()->setCellValue('D5', ':     JL. RAYA SERANG KM 24 BALARAJA  TANGERANG');
		$this->excel->getActiveSheet()->setCellValue('A6', 'Periode');
		$this->excel->getActiveSheet()->setCellValue('D6', ': ');
		$this->excel->getActiveSheet()->setCellValue('F6', 's/d');
		$this->excel->getActiveSheet()->setCellValue('A8', 'NO. URUT');
		$this->excel->getActiveSheet()->setCellValue('B8', 'TIPE BC');
		$this->excel->getActiveSheet()->setCellValue('C8', 'NOMOR DAFTAR');
		$this->excel->getActiveSheet()->setCellValue('D8', 'TANGGAL DAFTAR');

		$this->excel->getActiveSheet()->setCellValue('E8', 'NOMOR KELUAR');
		$this->excel->getActiveSheet()->setCellValue('F8', 'TANGGAL KELUAR');
		$this->excel->getActiveSheet()->setCellValue('G8', 'NAMA PEMBELI');
		
		$this->excel->getActiveSheet()->setCellValue('H8', 'KODE BARANG');
		$this->excel->getActiveSheet()->setCellValue('I8', 'NAMA BARANG');
		$this->excel->getActiveSheet()->setCellValue('J8', 'SATUAN');
		$this->excel->getActiveSheet()->setCellValue('K8', 'JUMLAH');
		
		$i = 1;
		$j = '';
		$k = 8;
		
		foreach ($rs as $row){
			$k = 8 + $i;
			$j = "$k";
				//$this->excel->getActiveSheet()->setCellValue("E6", $row['date_start']);
				//$this->excel->getActiveSheet()->setCellValue("G6", $row['date_end']);
				$this->excel->getActiveSheet()->setCellValue("A".$j, $i);
				$this->excel->getActiveSheet()->setCellValue("B".$j, $row['tipebc']);
				$this->excel->getActiveSheet()->setCellValue("C".$j, $row['nodaftar']);
				$this->excel->getActiveSheet()->setCellValue("D".$j, $row['tgldaftar']);
				$this->excel->getActiveSheet()->setCellValue("E".$j, $row['nokeluar']);
				$this->excel->getActiveSheet()->setCellValue("F".$j, $row['tglkeluar']);
				$this->excel->getActiveSheet()->setCellValue("G".$j, $row['pembeli']);
				$this->excel->getActiveSheet()->setCellValue("H".$j, $row['kodebrg']);				
				$this->excel->getActiveSheet()->setCellValue('I'.$j, $row['namabrg']);
				$this->excel->getActiveSheet()->setCellValue('J'.$j, $row['satuan']);
				$this->excel->getActiveSheet()->setCellValue('K'.$j, $row['jumlah']);
				//$this->excel->getActiveSheet()->setCellValue('I'.$j, $row['keterangan']);				


				$i++;
		}
		
		$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		 
		$filename='laporanpengeluaranbarang'.date('Ymd').'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
					 
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
			 

	}
	
	function view_reportcustomsbahanbaku_excel(){

			$qry= $this->db_pasi->query("
			
				SELECT [id_mutasi_bb]
					  ,[date_start]
					  ,[date_end]
					  ,[kdbrg] as kodebarang
					  ,[nama_barang] as namabarang
					  ,[satuan] as satuan
					  ,[stock_awal] as stokawal
					  ,[pemasukan] as pemasukan
					  ,[pengeluaran] as pengeluaran
					  ,[penyesuaian] as penyesuaian
					  ,[saldo_akhir] as saldoakhir
					  ,[stock_opname] as stokopname
					  ,[selisih] as selisih
					  ,[keterangan] as keterangan
				  FROM [DB_PASI_NEW].[dbo].[tbl_mutasi_bahan_baku_penolong]
				
			 ");
			$rs = $qry->result_array();
		
		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle('Sheet1');
		//set cell A1 content with some text
		//$this->excel->getActiveSheet()->setCellValue('A1', 'This is just some text value');
		//change the font size
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
		//make the font become bold
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
		//merge cell A1 until D1
		//$this->excel->getActiveSheet()->mergeCells('A1:D1');
		//set aligment to center for that merged cell (A1 to D1)
		
		$this->excel->getActiveSheet()->setCellValue('A2', 'D.1 LAPORAN PERTANGGUNG JAWABAN MUTASI BAHAN BAKU DAN BAHAN PENOLONG');
		$this->excel->getActiveSheet()->setCellValue('A3', 'KAWASAN BERIKAT: P.T AUTOCOMP SYSTEMS INDONESIA');
		$this->excel->getActiveSheet()->setCellValue('A5', 'Alamat');
		$this->excel->getActiveSheet()->setCellValue('D5', ':     JL. RAYA SERANG KM 24 BALARAJA  TANGERANG');
		$this->excel->getActiveSheet()->setCellValue('A6', 'Periode');
		$this->excel->getActiveSheet()->setCellValue('D6', ': ');
		$this->excel->getActiveSheet()->setCellValue('F6', 's/d');
		$this->excel->getActiveSheet()->setCellValue('A8', 'NO. URUT');
		$this->excel->getActiveSheet()->setCellValue('B8', 'KODE BARANG');
		$this->excel->getActiveSheet()->setCellValue('D8', 'NAMA BARANG');
		$this->excel->getActiveSheet()->setCellValue('E8', 'SATUAN');

		$this->excel->getActiveSheet()->setCellValue('F8', 'SALDO AWAL');
		$this->excel->getActiveSheet()->setCellValue('G8', 'PEMASUKAN');
		$this->excel->getActiveSheet()->setCellValue('H8', 'PENGELUARAN');
		
		$this->excel->getActiveSheet()->setCellValue('I8', 'PENYESUAIAN');
		$this->excel->getActiveSheet()->setCellValue('J8', 'SALDO AKHIR');
		$this->excel->getActiveSheet()->setCellValue('L8', 'SELISIH');
		$this->excel->getActiveSheet()->setCellValue('M8', 'KETERANGAN');
		
		$i = 1;
		$j = '';
		$k = 8;
		
		foreach ($rs as $row){
			$k = 8 + $i;
			$j = "$k";
				$this->excel->getActiveSheet()->setCellValue("E6", $row['date_start']);
				$this->excel->getActiveSheet()->setCellValue("G6", $row['date_end']);
				$this->excel->getActiveSheet()->setCellValue("A".$j, $i);
				$this->excel->getActiveSheet()->setCellValue("B".$j, $row['kodebarang']);
				$this->excel->getActiveSheet()->setCellValue("D".$j, $row['namabarang']);
				$this->excel->getActiveSheet()->setCellValue("E".$j, $row['satuan']);
				$this->excel->getActiveSheet()->setCellValue("F".$j, $row['stokawal']);
				$this->excel->getActiveSheet()->setCellValue("G".$j, $row['pemasukan']);
				$this->excel->getActiveSheet()->setCellValue("H".$j, $row['pengeluaran']);
				$this->excel->getActiveSheet()->setCellValue("I".$j, $row['penyesuaian']);				

				$this->excel->getActiveSheet()->setCellValue('J'.$j, $row['saldoakhir']);
				$this->excel->getActiveSheet()->setCellValue('L'.$j, $row['stokopname']);
				$this->excel->getActiveSheet()->setCellValue('M'.$j, $row['selisih']);
				$this->excel->getActiveSheet()->setCellValue('I'.$j, $row['keterangan']);				


				$i++;
		}
		
		$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		 
		$filename='laporanmutasibahanbaku'.date('Ymd').'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
					 
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
			 

	}

	function data_laporanbarangjadi(){
		$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']:'';
		
		$page 	= isset($_POST['page'])?$_POST['page']:1; // get the requested page
		$limit 	= isset($_POST['rows'])?$_POST['rows']:20; // get how many rows we want to have into the grid
		$sidx 	= isset($_POST['sidx'])?$_POST['sidx']:'id_mutasi_bj'; // get index row - i.e. user click to sort
		$sord 	= isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
			
		$where = " 1=1 ";
		
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){

				if ( $k->field == "No_Invoice" ) {
						$searchString = $k->data;
						$where .= " and No_Invoice like  '%".$searchString."%'"; 	
					} 
				}
			}
		}
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->pasi_mdl_reports->datareportbarangjadi_All($limit,$start,$sidx,$sord, $where);
		$count = $this->pasi_mdl_reports->datareportbarangjadi_CountAll($where);
		if( $count > 0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } 
		if ($page > $total_pages) $page=$total_pages;
		
		$responce->page = $page;
		$responce->total = $total_pages;
		$responce->records =  $count;
		$i=0;
		foreach($records as $r){
		
			$responce->rows[$i]['id_mutasi_bj']=$r->id_mutasi_bj;
			$responce->rows[$i]['kdbrg']=$r->kdbrg;
			$responce->rows[$i]['nama_barang']=$r->nama_barang;
			$responce->rows[$i]['satuan']=$r->satuan;
			$responce->rows[$i]['stock_awal']=$r->stock_awal;
			$responce->rows[$i]['pemasukan']=$r->pemasukan;
			$responce->rows[$i]['pengeluaran']=$r->pengeluaran;
			$responce->rows[$i]['penyesuaian']=$r->penyesuaian;
			$responce->rows[$i]['saldo_akhir']=$r->saldo_akhir;
			$responce->rows[$i]['stock_opname']=$r->stock_opname;
			$responce->rows[$i]['selisih']=$r->selisih;
			$responce->rows[$i]['keterangan']=$r->keterangan;
			
			$i++;
		}
		echo json_encode($responce);		
	}
	
	function getLaporanBarangJadi(){
		$tglawallaporanbarangjadi  =(isset($_POST['tglawallaporanbarangjadi']) && !empty($_POST['tglawallaporanbarangjadi']))?$_POST['tglawallaporanbarangjadi']:'';
		$tglakhirlaporanbarangjadi =(isset($_POST['tglakhirlaporanbarangjadi']) && !empty($_POST['tglakhirlaporanbarangjadi']))?$_POST['tglakhirlaporanbarangjadi']:'';
		
		//echo "exec('sp_mutasi_bahan_baku_penolong @date_start=''$tglawallaporanbahanbaku'' , @date_end=''$tglakhirlaporanbahanbaku''')";die();
		
			$qry = $this->db_pasi->query("
			
				BEGIN TRY
					exec('sp_mutasi_barang_jadi @date_start=''$tglawallaporanbarangjadi'' , @date_end=''$tglakhirlaporanbarangjadi''')
				END TRY
				BEGIN CATCH
				SELECT 
					'06' AS STATUS
					,ERROR_MESSAGE() AS DESCRIPTION;
				END CATCH
				
			 ");
			 
		 $rs = $qry->result_array();
		 foreach ($rs as $row){
			 $responce = array("sts" => $row['STATUS'], "desc" => $row['DESCRIPTION']);
		 }  
		 echo json_encode($responce);
	}
	
	function view_reportcustomsbarangjadi_excel(){

			$qry= $this->db_pasi->query("
			
				SELECT [id_mutasi_bj]
					  ,[date_start]
					  ,[date_end]
					  ,[kdbrg] as kodebarang
					  ,[nama_barang] as namabarang
					  ,[satuan] as satuan
					  ,[stock_awal] as stokawal
					  ,[pemasukan] as pemasukan
					  ,[pengeluaran] as pengeluaran
					  ,[penyesuaian] as penyesuaian
					  ,[saldo_akhir] as saldoakhir
					  ,[stock_opname] as stokopname
					  ,[selisih] as selisih
					  ,[keterangan] as keterangan
				FROM [DB_PASI_NEW].[dbo].[tbl_mutasi_barang_jadi]	

				
			 ");
			$rs = $qry->result_array();
		
		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle('Sheet1');
		//set cell A1 content with some text
		//$this->excel->getActiveSheet()->setCellValue('A1', 'This is just some text value');
		//change the font size
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
		//make the font become bold
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
		//merge cell A1 until D1
		//$this->excel->getActiveSheet()->mergeCells('A1:D1');
		//set aligment to center for that merged cell (A1 to D1)
		
		$this->excel->getActiveSheet()->setCellValue('A2', 'D.2 LAPORAN PERTANGGUNG JAWABAN MUTASI BARANG JADI');
		$this->excel->getActiveSheet()->setCellValue('A3', 'KAWASAN BERIKAT: P.T AUTOCOMP SYSTEMS INDONESIA');
		$this->excel->getActiveSheet()->setCellValue('A5', 'Alamat');
		$this->excel->getActiveSheet()->setCellValue('D5', ':     JL. RAYA SERANG KM 24 BALARAJA  TANGERANG');
		$this->excel->getActiveSheet()->setCellValue('A6', 'Periode');
		$this->excel->getActiveSheet()->setCellValue('D6', ': ');
		$this->excel->getActiveSheet()->setCellValue('F6', 's/d');
		$this->excel->getActiveSheet()->setCellValue('A8', 'NO. URUT');
		$this->excel->getActiveSheet()->setCellValue('B8', 'KODE BARANG');
		$this->excel->getActiveSheet()->setCellValue('D8', 'NAMA BARANG');
		$this->excel->getActiveSheet()->setCellValue('E8', 'SATUAN');

		$this->excel->getActiveSheet()->setCellValue('F8', 'SALDO AWAL');
		$this->excel->getActiveSheet()->setCellValue('G8', 'PEMASUKAN');
		$this->excel->getActiveSheet()->setCellValue('H8', 'PENGELUARAN');
		
		$this->excel->getActiveSheet()->setCellValue('I8', 'PENYESUAIAN');
		$this->excel->getActiveSheet()->setCellValue('J8', 'SALDO AKHIR');
		$this->excel->getActiveSheet()->setCellValue('L8', 'SELISIH');
		$this->excel->getActiveSheet()->setCellValue('M8', 'KETERANGAN');
		
		$i = 1;
		$j = '';
		$k = 8;
		
		foreach ($rs as $row){
			$k = 8 + $i;
			$j = "$k";
				$this->excel->getActiveSheet()->setCellValue("E6", $row['date_start']);
				$this->excel->getActiveSheet()->setCellValue("G6", $row['date_end']);
				$this->excel->getActiveSheet()->setCellValue("A".$j, $i);
				$this->excel->getActiveSheet()->setCellValue("B".$j, $row['kodebarang']);
				$this->excel->getActiveSheet()->setCellValue("D".$j, $row['namabarang']);
				$this->excel->getActiveSheet()->setCellValue("E".$j, $row['satuan']);
				$this->excel->getActiveSheet()->setCellValue("F".$j, $row['stokawal']);
				$this->excel->getActiveSheet()->setCellValue("G".$j, $row['pemasukan']);
				$this->excel->getActiveSheet()->setCellValue("H".$j, $row['pengeluaran']);
				$this->excel->getActiveSheet()->setCellValue("I".$j, $row['penyesuaian']);				

				$this->excel->getActiveSheet()->setCellValue('J'.$j, $row['saldoakhir']);
				$this->excel->getActiveSheet()->setCellValue('L'.$j, $row['stokopname']);
				$this->excel->getActiveSheet()->setCellValue('M'.$j, $row['selisih']);
				$this->excel->getActiveSheet()->setCellValue('I'.$j, $row['keterangan']);				


				$i++;
		}
		
		$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		 
		$filename='laporanmutasibarangjadi'.date('Ymd').'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
					 
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
			 

	}
	
	function data_laporanmesin(){
		$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']:'';
		
		$page 	= isset($_POST['page'])?$_POST['page']:1; // get the requested page
		$limit 	= isset($_POST['rows'])?$_POST['rows']:20; // get how many rows we want to have into the grid
		$sidx 	= isset($_POST['sidx'])?$_POST['sidx']:'id_mutasi_machine'; // get index row - i.e. user click to sort
		$sord 	= isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
			
		$where = " 1=1 ";
		
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){

				if ( $k->field == "No_Invoice" ) {
						$searchString = $k->data;
						$where .= " and No_Invoice like  '%".$searchString."%'"; 	
					} 
				}
			}
		}
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->pasi_mdl_reports->datareportmutasimesin_All($limit,$start,$sidx,$sord, $where);
		$count = $this->pasi_mdl_reports->datareportmutasimesin_CountAll($where);
		if( $count > 0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } 
		if ($page > $total_pages) $page=$total_pages;
		
		$responce->page = $page;
		$responce->total = $total_pages;
		$responce->records =  $count;
		$i=0;
		foreach($records as $r){
		
			$responce->rows[$i]['id_mutasi_machine']=$r->id_mutasi_machine;
			$responce->rows[$i]['kdbrg']=$r->kdbrg;
			$responce->rows[$i]['nama_barang']=$r->nama_barang;
			$responce->rows[$i]['satuan']=$r->satuan;
			$responce->rows[$i]['stock_awal']=$r->stock_awal;
			$responce->rows[$i]['pemasukan']=$r->pemasukan;
			$responce->rows[$i]['pengeluaran']=$r->pengeluaran;
			$responce->rows[$i]['penyesuaian']=$r->penyesuaian;
			$responce->rows[$i]['saldo_akhir']=$r->saldo_akhir;
			$responce->rows[$i]['stock_opname']=$r->stock_opname;
			$responce->rows[$i]['selisih']=$r->selisih;
			$responce->rows[$i]['keterangan']=$r->keterangan;
			
			$i++;
		}
		echo json_encode($responce);		
	}
	
	function getLaporanMesin(){
		$tglawallaporanmesin  =(isset($_POST['tglawallaporanmesin']) && !empty($_POST['tglawallaporanmesin']))?$_POST['tglawallaporanmesin']:'';
		$tglakhirlaporanmesin =(isset($_POST['tglakhirlaporanmesin']) && !empty($_POST['tglakhirlaporanmesin']))?$_POST['tglakhirlaporanmesin']:'';
		
		//echo "exec('sp_mutasi_bahan_baku_penolong @date_start=''$tglawallaporanbahanbaku'' , @date_end=''$tglakhirlaporanbahanbaku''')";die();
		
			$qry = $this->db_pasi->query("
			
				BEGIN TRY
					exec('sp_mutasi_machine @date_start=''$tglawallaporanmesin'' , @date_end=''$tglakhirlaporanmesin''')
				END TRY
				BEGIN CATCH
				SELECT 
					'06' AS STATUS
					,ERROR_MESSAGE() AS DESCRIPTION;
				END CATCH
				
			 ");
			 
		 $rs = $qry->result_array();
		 foreach ($rs as $row){
			 $responce = array("sts" => $row['STATUS'], "desc" => $row['DESCRIPTION']);
		 }  
		 echo json_encode($responce);
	}

	function view_reportcustomsmesin_excel(){

			$qry= $this->db_pasi->query("
			
			SELECT [id_mutasi_machine]
				,[date_start]
				,[date_end]
				,[kdbrg] as kodebarang
				,[nama_barang] as namabarang
				,[satuan] as satuan
				,[stock_awal] as stokawal
				,[pemasukan] as pemasukan
				,[pengeluaran] as pengeluaran
				,[penyesuaian] as penyesuaian
				,[saldo_akhir] as saldoakhir
				,[stock_opname] as stokopname
				,[selisih] as selisih
				,[keterangan] as keterangan
			FROM [DB_PASI_NEW].[dbo].[tbl_mutasi_machine]

				
			 ");
			$rs = $qry->result_array();
		
		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle('Sheet1');
		//set cell A1 content with some text
		//$this->excel->getActiveSheet()->setCellValue('A1', 'This is just some text value');
		//change the font size
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
		//make the font become bold
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
		//merge cell A1 until D1
		//$this->excel->getActiveSheet()->mergeCells('A1:D1');
		//set aligment to center for that merged cell (A1 to D1)
		//wip jadi c gitu? ya
		$this->excel->getActiveSheet()->setCellValue('A2', 'D.4 LAPORAN PERTANGGUNGJAWABAN MUTASI MESIN DAN PERALATAN PERKANTORAN');
		$this->excel->getActiveSheet()->setCellValue('A3', 'KAWASAN BERIKAT: P.T AUTOCOMP SYSTEMS INDONESIA');
		$this->excel->getActiveSheet()->setCellValue('A5', 'Alamat');
		$this->excel->getActiveSheet()->setCellValue('D5', ':     JL. RAYA SERANG KM 24 BALARAJA  TANGERANG');
		$this->excel->getActiveSheet()->setCellValue('A6', 'Periode');
		$this->excel->getActiveSheet()->setCellValue('D6', ': ');
		$this->excel->getActiveSheet()->setCellValue('F6', 's/d');
		$this->excel->getActiveSheet()->setCellValue('A8', 'NO. URUT');
		$this->excel->getActiveSheet()->setCellValue('B8', 'KODE BARANG');
		$this->excel->getActiveSheet()->setCellValue('D8', 'NAMA BARANG');
		$this->excel->getActiveSheet()->setCellValue('E8', 'SATUAN');

		$this->excel->getActiveSheet()->setCellValue('F8', 'SALDO AWAL');
		$this->excel->getActiveSheet()->setCellValue('G8', 'PEMASUKAN');
		$this->excel->getActiveSheet()->setCellValue('H8', 'PENGELUARAN');
		
		$this->excel->getActiveSheet()->setCellValue('I8', 'PENYESUAIAN');
		$this->excel->getActiveSheet()->setCellValue('J8', 'SALDO AKHIR');
		$this->excel->getActiveSheet()->setCellValue('L8', 'SELISIH');
		$this->excel->getActiveSheet()->setCellValue('M8', 'KETERANGAN');
		
		$i = 1;
		$j = '';
		$k = 8;
		
		foreach ($rs as $row){
			$k = 8 + $i;
			$j = "$k";
				$this->excel->getActiveSheet()->setCellValue("E6", $row['date_start']);
				$this->excel->getActiveSheet()->setCellValue("G6", $row['date_end']);
				$this->excel->getActiveSheet()->setCellValue("A".$j, $i);
				$this->excel->getActiveSheet()->setCellValue("B".$j, $row['kodebarang']);
				$this->excel->getActiveSheet()->setCellValue("D".$j, $row['namabarang']);
				$this->excel->getActiveSheet()->setCellValue("E".$j, $row['satuan']);
				$this->excel->getActiveSheet()->setCellValue("F".$j, $row['stokawal']);
				$this->excel->getActiveSheet()->setCellValue("G".$j, $row['pemasukan']);
				$this->excel->getActiveSheet()->setCellValue("H".$j, $row['pengeluaran']);
				$this->excel->getActiveSheet()->setCellValue("I".$j, $row['penyesuaian']);				

				$this->excel->getActiveSheet()->setCellValue('J'.$j, $row['saldoakhir']);
				$this->excel->getActiveSheet()->setCellValue('L'.$j, $row['stokopname']);
				$this->excel->getActiveSheet()->setCellValue('M'.$j, $row['selisih']);
				$this->excel->getActiveSheet()->setCellValue('I'.$j, $row['keterangan']);				


				$i++;
		}
		
		$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		 
		$filename='laporanmutasimesin'.date('Ymd').'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
					 
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
			 

	}
	
	function data_laporanwip(){
		$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']:'';
		
		$page 	= isset($_POST['page'])?$_POST['page']:1; // get the requested page
		$limit 	= isset($_POST['rows'])?$_POST['rows']:20; // get how many rows we want to have into the grid
		$sidx 	= isset($_POST['sidx'])?$_POST['sidx']:'id_mutasi_wip'; // get index row - i.e. user click to sort
		$sord 	= isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
			
		$where = " 1=1 ";
		
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){

				if ( $k->field == "kdbrg" ) {
						$searchString = $k->data;
						$where .= " and kdbrg like  '%".$searchString."%'"; 	
					} 
				}
			}
		}
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->pasi_mdl_reports->datareportbarangwip_All($limit,$start,$sidx,$sord, $where);
		$count = $this->pasi_mdl_reports->datareportbarangwip_CountAll($where);
		if( $count > 0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } 
		if ($page > $total_pages) $page=$total_pages;
		
		$responce->page = $page;
		$responce->total = $total_pages;
		$responce->records =  $count;
		$i=0;
		foreach($records as $r){
		

			$responce->rows[$i]['id_mutasi_wip']=$r->id_mutasi_wip;
			$responce->rows[$i]['kdbrg']=$r->kdbrg;
			$responce->rows[$i]['nama_barang']=$r->nama_barang;
			$responce->rows[$i]['satuan']=$r->satuan;
			$responce->rows[$i]['stock_awal']=$r->stock_awal;
			$responce->rows[$i]['pemasukan']=$r->pemasukan;
			$responce->rows[$i]['pengeluaran']=$r->pengeluaran;
			$responce->rows[$i]['saldo_akhir']=$r->saldo_akhir;
			$responce->rows[$i]['keterangan']=$r->keterangan;
			
			$i++;
		}
		echo json_encode($responce);		
			

	}

	function getLaporanWIP(){
		$tglawallaporanbarangwip  =(isset($_POST['tglawallaporanbarangwip']) && !empty($_POST['tglawallaporanbarangwip']))?$_POST['tglawallaporanbarangwip']:'';
		$tglakhirlaporanbarangwip =(isset($_POST['tglakhirlaporanbarangwip']) && !empty($_POST['tglakhirlaporanbarangwip']))?$_POST['tglakhirlaporanbarangwip']:'';
		
		//echo "exec('sp_mutasi_wip @date_start=''$tglawallaporanbarangwip'' , @date_end=''$tglakhirlaporanbarangwip''')";die();
		
			$qry = $this->db_pasi->query("
			
				BEGIN TRY
					exec('sp_mutasi_wip @date_start=''$tglawallaporanbarangwip'' , @date_end=''$tglakhirlaporanbarangwip''')
				END TRY
				BEGIN CATCH
				SELECT 
					'06' AS STATUS
					,ERROR_MESSAGE() AS DESCRIPTION;
				END CATCH
				
			 ");
			 
		 $rs = $qry->result_array();
		 foreach ($rs as $row){
			 $responce = array("sts" => $row['STATUS'], "desc" => $row['DESCRIPTION']);
		 }  
		 echo json_encode($responce);
	}
	
	function data_laporanbarangsisa(){
		$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']:'';
		
		$page 	= isset($_POST['page'])?$_POST['page']:1; // get the requested page
		$limit 	= isset($_POST['rows'])?$_POST['rows']:20; // get how many rows we want to have into the grid
		$sidx 	= isset($_POST['sidx'])?$_POST['sidx']:'id_mutasi_scrap'; // get index row - i.e. user click to sort
		$sord 	= isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
			
		$where = " 1=1 ";
		
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){

				if ( $k->field == "No_Invoice" ) {
						$searchString = $k->data;
						$where .= " and No_Invoice like  '%".$searchString."%'"; 	
					} 
				}
			}
		}
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->pasi_mdl_reports->datareportbarangsisa_All($limit,$start,$sidx,$sord, $where);
		$count = $this->pasi_mdl_reports->datareportbarangsisa_CountAll($where);
		if( $count > 0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } 
		if ($page > $total_pages) $page=$total_pages;
		
		$responce->page = $page;
		$responce->total = $total_pages;
		$responce->records =  $count;
		$i=0;
		foreach($records as $r){
		
			$responce->rows[$i]['id_mutasi_scrap']=$r->id_mutasi_scrap;
			$responce->rows[$i]['kdbrg']=$r->kdbrg;
			$responce->rows[$i]['nama_barang']=$r->nama_barang;
			$responce->rows[$i]['satuan']=$r->satuan;
			$responce->rows[$i]['stock_awal']=$r->stock_awal;
			$responce->rows[$i]['pemasukan']=$r->pemasukan;
			$responce->rows[$i]['pengeluaran']=$r->pengeluaran;
			$responce->rows[$i]['penyesuaian']=$r->penyesuaian;
			$responce->rows[$i]['saldo_akhir']=$r->saldo_akhir;
			$responce->rows[$i]['stock_opname']=$r->stock_opname;
			$responce->rows[$i]['selisih']=$r->selisih;
			$responce->rows[$i]['keterangan']=$r->keterangan;
			
			$i++;
		}
		echo json_encode($responce);		
	}

	function view_reportcustomsscrap_excel(){

			$qry= $this->db_pasi->query("


			SELECT [id_mutasi_scrap]
				,[date_start]
				,[date_end]
				,[kdbrg] as kodebarang
				,[nama_barang] as namabarang
				,[satuan] as satuan
				,[stock_awal] as stokawal
				,[pemasukan] as pemasukan
				,[pengeluaran] as pengeluaran
				,[penyesuaian] as penyesuaian
				,[saldo_akhir] as saldoakhir
				,[stock_opname] as stokopname
				,[selisih] as selisih
				,[keterangan] as keterangan
			FROM [DB_PASI_NEW].[dbo].[tbl_mutasi_scrap]

				
			 ");
			$rs = $qry->result_array();
		
		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle('Sheet1');
		//set cell A1 content with some text
		//$this->excel->getActiveSheet()->setCellValue('A1', 'This is just some text value');
		//change the font size
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
		//make the font become bold
		//$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
		//merge cell A1 until D1
		//$this->excel->getActiveSheet()->mergeCells('A1:D1');
		//set aligment to center for that merged cell (A1 to D1)
		
		$this->excel->getActiveSheet()->setCellValue('A2', 'D.3 LAPORAN PERTANGGUNG JAWABAN MUTASI BARANG SISA DAN SCRAP');
		$this->excel->getActiveSheet()->setCellValue('A3', 'KAWASAN BERIKAT: P.T AUTOCOMP SYSTEMS INDONESIA');
		$this->excel->getActiveSheet()->setCellValue('A5', 'Alamat');
		$this->excel->getActiveSheet()->setCellValue('D5', ':     JL. RAYA SERANG KM 24 BALARAJA  TANGERANG');
		$this->excel->getActiveSheet()->setCellValue('A6', 'Periode');
		$this->excel->getActiveSheet()->setCellValue('D6', ': ');
		$this->excel->getActiveSheet()->setCellValue('F6', 's/d');
		$this->excel->getActiveSheet()->setCellValue('A8', 'NO. URUT');
		$this->excel->getActiveSheet()->setCellValue('B8', 'KODE BARANG');
		$this->excel->getActiveSheet()->setCellValue('D8', 'NAMA BARANG');
		$this->excel->getActiveSheet()->setCellValue('E8', 'SATUAN');

		$this->excel->getActiveSheet()->setCellValue('F8', 'SALDO AWAL');
		$this->excel->getActiveSheet()->setCellValue('G8', 'PEMASUKAN');
		$this->excel->getActiveSheet()->setCellValue('H8', 'PENGELUARAN');
		
		$this->excel->getActiveSheet()->setCellValue('I8', 'PENYESUAIAN');
		$this->excel->getActiveSheet()->setCellValue('J8', 'SALDO AKHIR');
		$this->excel->getActiveSheet()->setCellValue('L8', 'SELISIH');
		$this->excel->getActiveSheet()->setCellValue('M8', 'KETERANGAN');
		
		$i = 1;
		$j = '';
		$k = 8;
		
		foreach ($rs as $row){
			$k = 8 + $i;
			$j = "$k";
				$this->excel->getActiveSheet()->setCellValue("E6", $row['date_start']);
				$this->excel->getActiveSheet()->setCellValue("G6", $row['date_end']);
				$this->excel->getActiveSheet()->setCellValue("A".$j, $i);
				$this->excel->getActiveSheet()->setCellValue("B".$j, $row['kodebarang']);
				$this->excel->getActiveSheet()->setCellValue("D".$j, $row['namabarang']);
				$this->excel->getActiveSheet()->setCellValue("E".$j, $row['satuan']);
				$this->excel->getActiveSheet()->setCellValue("F".$j, $row['stokawal']);
				$this->excel->getActiveSheet()->setCellValue("G".$j, $row['pemasukan']);
				$this->excel->getActiveSheet()->setCellValue("H".$j, $row['pengeluaran']);
				$this->excel->getActiveSheet()->setCellValue("I".$j, $row['penyesuaian']);				

				$this->excel->getActiveSheet()->setCellValue('J'.$j, $row['saldoakhir']);
				$this->excel->getActiveSheet()->setCellValue('L'.$j, $row['stokopname']);
				$this->excel->getActiveSheet()->setCellValue('M'.$j, $row['selisih']);
				$this->excel->getActiveSheet()->setCellValue('I'.$j, $row['keterangan']);				


				$i++;
		}
		
		$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		 
		$filename='laporanmutasiscrap'.date('Ymd').'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
					 
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
			 

	}		
	function getLaporanScrap(){
		$tglawallaporanbarangsisa  =(isset($_POST['tglawallaporanbarangsisa']) && !empty($_POST['tglawallaporanbarangsisa']))?$_POST['tglawallaporanbarangsisa']:'';
		$tglakhirlaporanbarangsisa =(isset($_POST['tglakhirlaporanbarangsisa']) && !empty($_POST['tglakhirlaporanbarangsisa']))?$_POST['tglakhirlaporanbarangsisa']:'';
		
		//echo "exec('sp_mutasi_scrap @date_start=''$tglawallaporanbarangsisa'' , @date_end=''$tglakhirlaporanbarangsisa''')";die();
		
			$qry = $this->db_pasi->query("
			
				BEGIN TRY
					exec('sp_mutasi_scrap @date_start=''$tglawallaporanbarangsisa'' , @date_end=''$tglakhirlaporanbarangsisa''')
				END TRY
				BEGIN CATCH
				SELECT 
					'06' AS STATUS
					,ERROR_MESSAGE() AS DESCRIPTION;
				END CATCH
				
			 ");
			 
		 $rs = $qry->result_array();
		 foreach ($rs as $row){
			 $responce = array("sts" => $row['STATUS'], "desc" => $row['DESCRIPTION']);
		 }  
		 echo json_encode($responce);
	}
	
	function pdf_reportcustomspemasukanbarang_jasper(){
	
		$tglawallaporanpemasukanbarang = (isset($_GET['tglawallaporanpemasukanbarang']) && !empty($_GET['tglawallaporanpemasukanbarang']))?$_GET['tglawallaporanpemasukanbarang']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanpemasukanbarang = (isset($_GET['tglakhirlaporanpemasukanbarang']) && !empty($_GET['tglakhirlaporanpemasukanbarang']))?$_GET['tglakhirlaporanpemasukanbarang']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
	
		$tgawal =$tglawallaporanpemasukanbarang;
		$tgakhir =$tglakhirlaporanpemasukanbarang;
		
		$tglawallaporanpemasukanbarang = explode("/", $tglawallaporanpemasukanbarang);	
		$tglakhirlaporanpemasukanbarang = explode("/", $tglakhirlaporanpemasukanbarang);	

		//$tgawal =  $tglawallaporanpemasukanbarang[1].'/'.$tglawallaporanpemasukanbarang[0].'/'.$tglawallaporanpemasukanbarang[2];
		//$tgakhir = $tglakhirlaporanpemasukanbarang[1].'/'.$tglakhirlaporanpemasukanbarang[0].'/'.$tglakhirlaporanpemasukanbarang[2];
		
		
		
		
		$this->load->helper('afunction_helper');
		
		$periodetgawal = $tglawallaporanpemasukanbarang[0].' - '.fbulan($tglawallaporanpemasukanbarang[1]).' - '.$tglawallaporanpemasukanbarang[2];
		$periodetgakhir = $tglakhirlaporanpemasukanbarang[0].' - '.fbulan($tglakhirlaporanpemasukanbarang[1]).' - '.$tglakhirlaporanpemasukanbarang[2];

		$data['periodetgawal '] = $periodetgawal;
		$data['periodetgakhir '] = $periodetgakhir;
		
		$this->load->library('java_bridge');
		$cekjava=$this->java_bridge->checkJavaExtension(); 
		$bcreportdir = $this->config->item('APP_dirreport');
		
		
		if($cekjava){
			$irep = $bcreportdir.'\rpt_incoming.jrxml';
			$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
			
			$report = $compileManager->compileReport($irep);
			$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
			
			$params = new Java("java.util.HashMap");
			$params->put("tglawal",  $tgawal);
			$params->put("tglakhir",  $tgakhir);
			$params->put("prmperiode", $periodetgawal . ' S/D' . $periodetgakhir );
			$params->put("nama_perusahaan", "PT. AUTOCOMP SYSTEMS INDONESIA");
			
			$class = new JavaClass("java.lang.Class");
			$class->forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			$driverManager = new JavaClass("java.sql.DriverManager");
			
			//db username and password
			$conn = $driverManager->getConnection("jdbc:sqlserver://localhost:1433;databaseName=db_pasi_new", "sa", "P4ssword");
			$jasperPrint = $fillManager->fillReport($report, $params, $conn);
			$outputPath = realpath(".")."\ireport/"."pdfpenerimaanbrg.pdf";
			
				$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
				$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);

			header("Content-type: application/pdf");
			
			readfile($outputPath);
			
			@unlink($outputPath);
		}
		
	}

	function pdf_reportcustomspengeluaranbarang_jasper(){
	
		$tglawallaporanpengeluaranbarang = (isset($_GET['tglawallaporanpengeluaranbarang']) && !empty($_GET['tglawallaporanpengeluaranbarang']))?$_GET['tglawallaporanpengeluaranbarang']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanpengeluaranbarang = (isset($_GET['tglakhirlaporanpengeluaranbarang']) && !empty($_GET['tglakhirlaporanpengeluaranbarang']))?$_GET['tglakhirlaporanpengeluaranbarang']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');

		$tgawal =$tglawallaporanpengeluaranbarang;
		$tgakhir =$tglakhirlaporanpengeluaranbarang;
		
		$tglawallaporanpengeluaranbarang = explode("/", $tglawallaporanpengeluaranbarang);	
		$tglakhirlaporanpengeluaranbarang = explode("/", $tglakhirlaporanpengeluaranbarang);	

		//$tgawal =  $tglawallaporanpengeluaranbarang[1].'/'.$tglawallaporanpengeluaranbarang[0].'/'.$tglawallaporanpengeluaranbarang[2];
		//$tgakhir = $tglakhirlaporanpengeluaranbarang[1].'/'.$tglakhirlaporanpengeluaranbarang[0].'/'.$tglakhirlaporanpengeluaranbarang[2];
		
		$this->load->helper('afunction_helper');
		
		$periodetgawal = $tglawallaporanpengeluaranbarang[0].' - '.fbulan($tglawallaporanpengeluaranbarang[1]).' - '.$tglawallaporanpengeluaranbarang[2];
		$periodetgakhir = $tglakhirlaporanpengeluaranbarang[0].' - '.fbulan($tglakhirlaporanpengeluaranbarang[1]).' - '.$tglakhirlaporanpengeluaranbarang[2];

		$data['periodetgawal '] = $periodetgawal;
		$data['periodetgakhir '] = $periodetgakhir;
		
		$this->load->library('java_bridge');
		$cekjava=$this->java_bridge->checkJavaExtension(); 
		$bcreportdir = $this->config->item('APP_dirreport');
		
		
		if($cekjava){
			$irep = $bcreportdir.'\rpt_outgoing.jrxml';
			$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
			
			$report = $compileManager->compileReport($irep);
			$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
			
			$params = new Java("java.util.HashMap");
			$params->put("tglawal",  $tgawal);
			$params->put("tglakhir",  $tgakhir);
			$params->put("prmperiode", $periodetgawal . ' S/D' . $periodetgakhir );
			$params->put("nama_perusahaan", "PT. AUTOCOMP SYSTEMS INDONESIA");
			
			$class = new JavaClass("java.lang.Class");
			$class->forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			$driverManager = new JavaClass("java.sql.DriverManager");
			
			//db username and password
			$conn = $driverManager->getConnection("jdbc:sqlserver://localhost:1433;databaseName=db_pasi_new", "sa", "P4ssword");
			$jasperPrint = $fillManager->fillReport($report, $params, $conn);
			$outputPath = realpath(".")."\ireport/"."pdfpengeluaranbrg.pdf";
			
				$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
				$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);

			header("Content-type: application/pdf");
			
			readfile($outputPath);
			
			@unlink($outputPath);
		}
		
	}

	function pdf_reportcustomsbarangwip_jasper(){
	
		$tglawallaporanbarangwip = (isset($_GET['tglawallaporanbarangwip']) && !empty($_GET['tglawallaporanbarangwip']))?$_GET['tglawallaporanbarangwip']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanbarangwip = (isset($_GET['tglakhirlaporanbarangwip']) && !empty($_GET['tglakhirlaporanbarangwip']))?$_GET['tglakhirlaporanbarangwip']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		
		$tglawallaporanbarangwip = explode("/", $tglawallaporanbarangwip);	
		$tglakhirlaporanbarangwip = explode("/", $tglakhirlaporanbarangwip);	

		$tgawal =  $tglawallaporanbarangwip[1].'/'.$tglawallaporanbarangwip[0].'/'.$tglawallaporanbarangwip[2];
		$tgakhir = $tglakhirlaporanbarangwip[1].'/'.$tglakhirlaporanbarangwip[0].'/'.$tglakhirlaporanbarangwip[2];
		
		$this->load->helper('afunction_helper');
		
		$periodetgawal = $tglawallaporanbarangwip[0].' - '.fbulan($tglawallaporanbarangwip[1]).' - '.$tglawallaporanbarangwip[2];
		$periodetgakhir = $tglakhirlaporanbarangwip[0].' - '.fbulan($tglakhirlaporanbarangwip[1]).' - '.$tglakhirlaporanbarangwip[2];

		$data['periodetgawal '] = $periodetgawal;
		$data['periodetgakhir '] = $periodetgakhir;
		
		$this->load->library('java_bridge');
		$cekjava=$this->java_bridge->checkJavaExtension(); 
		$bcreportdir = $this->config->item('APP_dirreport');
		
		
		if($cekjava){
			$irep = $bcreportdir.'\rpt_wip.jrxml';
			$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
			
			$report = $compileManager->compileReport($irep);
			$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
			
			$params = new Java("java.util.HashMap");
			$params->put("tglawal",  $tgawal);
			$params->put("tglakhir",  $tgakhir);
			$params->put("prmperiode", $periodetgawal . ' S/D' . $periodetgakhir );
			$params->put("nama_perusahaan", "PT. AUTOCOMP SYSTEMS INDONESIA");
			
			$class = new JavaClass("java.lang.Class");
			$class->forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			$driverManager = new JavaClass("java.sql.DriverManager");
			
			//db username and password
			$conn = $driverManager->getConnection("jdbc:sqlserver://localhost:1433;databaseName=db_pasi_new", "sa", "P4ssword");
			$jasperPrint = $fillManager->fillReport($report, $params, $conn);
			$outputPath = realpath(".")."\ireport/"."pdfbarangwip.pdf";
			
				$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
				$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);

			header("Content-type: application/pdf");
			
			readfile($outputPath);
			
			@unlink($outputPath);
		}
		
	}
	
	function pdf_reportcustomsbahanbaku_jasper(){
	
		$tglawallaporanbahanbaku = (isset($_GET['tglawallaporanbahanbaku']) && !empty($_GET['tglawallaporanbahanbaku']))?$_GET['tglawallaporanbahanbaku']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanbahanbaku = (isset($_GET['tglakhirlaporanbahanbaku']) && !empty($_GET['tglakhirlaporanbahanbaku']))?$_GET['tglakhirlaporanbahanbaku']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		
		$tglawallaporanbahanbaku = explode("/", $tglawallaporanbahanbaku);	
		$tglakhirlaporanbahanbaku = explode("/", $tglakhirlaporanbahanbaku);	

		$tgawal =  $tglawallaporanbahanbaku[1].'/'.$tglawallaporanbahanbaku[0].'/'.$tglawallaporanbahanbaku[2];
		$tgakhir = $tglakhirlaporanbahanbaku[1].'/'.$tglakhirlaporanbahanbaku[0].'/'.$tglakhirlaporanbahanbaku[2];
		
		$this->load->helper('afunction_helper');
		
		$periodetgawal = $tglawallaporanbahanbaku[0].' - '.fbulan($tglawallaporanbahanbaku[1]).' - '.$tglawallaporanbahanbaku[2];
		$periodetgakhir = $tglakhirlaporanbahanbaku[0].' - '.fbulan($tglakhirlaporanbahanbaku[1]).' - '.$tglakhirlaporanbahanbaku[2];

		$data['periodetgawal '] = $periodetgawal;
		$data['periodetgakhir '] = $periodetgakhir;
		
		$this->load->library('java_bridge');
		$cekjava=$this->java_bridge->checkJavaExtension(); 
		$bcreportdir = $this->config->item('APP_dirreport');
		
		
		if($cekjava){
			$irep = $bcreportdir.'\rpt_mts_bb_bp.jrxml';
			$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
			
			$report = $compileManager->compileReport($irep);
			$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
			
			$params = new Java("java.util.HashMap");
			$params->put("tglawal",  $tgawal);
			$params->put("tglakhir",  $tgakhir);
			$params->put("prmperiode", $periodetgawal . ' S/D' . $periodetgakhir );
			$params->put("nama_perusahaan", "PT. AUTOCOMP SYSTEMS INDONESIA");
			
			$class = new JavaClass("java.lang.Class");
			$class->forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			$driverManager = new JavaClass("java.sql.DriverManager");
			
			//db username and password
			$conn = $driverManager->getConnection("jdbc:sqlserver://localhost:1433;databaseName=db_pasi_new", "sa", "P4ssword");
			$jasperPrint = $fillManager->fillReport($report, $params, $conn);
			$outputPath = realpath(".")."\ireport/"."pdfbahanbaku.pdf";
			
				$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
				$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);

			header("Content-type: application/pdf");
			
			readfile($outputPath);
			
			@unlink($outputPath);
		}
		
	}

	function pdf_reportcustomsbarangjadi_jasper(){
	
		$tglawallaporanbarangjadi = (isset($_GET['tglawallaporanbarangjadi']) && !empty($_GET['tglawallaporanbarangjadi']))?$_GET['tglawallaporanbarangjadi']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanbarangjadi = (isset($_GET['tglakhirlaporanbarangjadi']) && !empty($_GET['tglakhirlaporanbarangjadi']))?$_GET['tglakhirlaporanbarangjadi']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		
		$tglawallaporanbarangjadi = explode("/", $tglawallaporanbarangjadi);	
		$tglakhirlaporanbarangjadi = explode("/", $tglakhirlaporanbarangjadi);	

		$tgawal =  $tglawallaporanbarangjadi[1].'/'.$tglawallaporanbarangjadi[0].'/'.$tglawallaporanbarangjadi[2];
		$tgakhir = $tglakhirlaporanbarangjadi[1].'/'.$tglakhirlaporanbarangjadi[0].'/'.$tglakhirlaporanbarangjadi[2];
		
		$this->load->helper('afunction_helper');
		
		$periodetgawal = $tglawallaporanbarangjadi[0].' - '.fbulan($tglawallaporanbarangjadi[1]).' - '.$tglawallaporanbarangjadi[2];
		$periodetgakhir = $tglakhirlaporanbarangjadi[0].' - '.fbulan($tglakhirlaporanbarangjadi[1]).' - '.$tglakhirlaporanbarangjadi[2];

		$data['periodetgawal '] = $periodetgawal;
		$data['periodetgakhir '] = $periodetgakhir;
		
		$this->load->library('java_bridge');
		$cekjava=$this->java_bridge->checkJavaExtension(); 
		$bcreportdir = $this->config->item('APP_dirreport');
		
		
		if($cekjava){
			$irep = $bcreportdir.'\rpt_mts_fg.jrxml';
			$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
			
			$report = $compileManager->compileReport($irep);
			$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
			
			$params = new Java("java.util.HashMap");
			$params->put("tglawal",  $tgawal);
			$params->put("tglakhir",  $tgakhir);
			$params->put("prmperiode", $periodetgawal . ' S/D' . $periodetgakhir );
			$params->put("nama_perusahaan", "PT. AUTOCOMP SYSTEMS INDONESIA");
			
			$class = new JavaClass("java.lang.Class");
			$class->forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			$driverManager = new JavaClass("java.sql.DriverManager");
			
			//db username and password
			$conn = $driverManager->getConnection("jdbc:sqlserver://localhost:1433;databaseName=db_pasi_new", "sa", "P4ssword");
			$jasperPrint = $fillManager->fillReport($report, $params, $conn);
			$outputPath = realpath(".")."\ireport/"."pdfbarangjadi.pdf";
			
				$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
				$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);

			header("Content-type: application/pdf");
			
			readfile($outputPath);
			
			@unlink($outputPath);
		}
		
	}
	
	function pdf_reportcustomsbarangsisa_jasper(){
		$tglawallaporanbarangsisa = (isset($_GET['tglawallaporanbarangsisa']) && !empty($_GET['tglawallaporanbarangsisa']))?$_GET['tglawallaporanbarangsisa']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanbarangsisa = (isset($_GET['tglakhirlaporanbarangsisa']) && !empty($_GET['tglakhirlaporanbarangsisa']))?$_GET['tglakhirlaporanbarangsisa']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		
		$tglawallaporanbarangsisa = explode("/", $tglawallaporanbarangsisa);	
		$tglakhirlaporanbarangsisa = explode("/", $tglakhirlaporanbarangsisa);	

		$tgawal =  $tglawallaporanbarangsisa[1].'/'.$tglawallaporanbarangsisa[0].'/'.$tglawallaporanbarangsisa[2];
		$tgakhir = $tglakhirlaporanbarangsisa[1].'/'.$tglakhirlaporanbarangsisa[0].'/'.$tglakhirlaporanbarangsisa[2];
		
		$this->load->helper('afunction_helper');
		
		$periodetgawal = $tglawallaporanbarangsisa[0].' - '.fbulan($tglawallaporanbarangsisa[1]).' - '.$tglawallaporanbarangsisa[2];
		$periodetgakhir = $tglakhirlaporanbarangsisa[0].' - '.fbulan($tglakhirlaporanbarangsisa[1]).' - '.$tglakhirlaporanbarangsisa[2];

		$data['periodetgawal '] = $periodetgawal;
		$data['periodetgakhir '] = $periodetgakhir;
		
		$this->load->library('java_bridge');
		$cekjava=$this->java_bridge->checkJavaExtension(); 
		$bcreportdir = $this->config->item('APP_dirreport');
		
		
		if($cekjava){
			$irep = $bcreportdir.'\rpt_mts_ss_sc.jrxml';
			$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
			
			$report = $compileManager->compileReport($irep);
			$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
			
			$params = new Java("java.util.HashMap");
			$params->put("tglawal",  $tgawal);
			$params->put("tglakhir",  $tgakhir);
			$params->put("prmperiode", $periodetgawal . ' S/D' . $periodetgakhir );
			$params->put("nama_perusahaan", "PT. AUTOCOMP SYSTEMS INDONESIA");
			
			$class = new JavaClass("java.lang.Class");
			$class->forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			$driverManager = new JavaClass("java.sql.DriverManager");
			
			//db username and password
			$conn = $driverManager->getConnection("jdbc:sqlserver://localhost:1433;databaseName=db_pasi_new", "sa", "P4ssword");
			$jasperPrint = $fillManager->fillReport($report, $params, $conn);
			$outputPath = realpath(".")."\ireport/"."pdfbarangsisa.pdf";
			
				$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
				$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);

			header("Content-type: application/pdf");
			
			readfile($outputPath);
			
			@unlink($outputPath);
		}	
	
	}
	
	function pdf_reportcustomsmesin_jasper(){
		$tglawallaporanmesin = (isset($_GET['tglawallaporanmesin']) && !empty($_GET['tglawallaporanmesin']))?$_GET['tglawallaporanmesin']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanmesin = (isset($_GET['tglakhirlaporanmesin']) && !empty($_GET['tglakhirlaporanmesin']))?$_GET['tglakhirlaporanmesin']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		
		$tglawallaporanmesin = explode("/", $tglawallaporanmesin);	
		$tglakhirlaporanmesin = explode("/", $tglakhirlaporanmesin);	

		$tgawal =  $tglawallaporanmesin[1].'/'.$tglawallaporanmesin[0].'/'.$tglawallaporanmesin[2];
		$tgakhir = $tglakhirlaporanmesin[1].'/'.$tglakhirlaporanmesin[0].'/'.$tglakhirlaporanmesin[2];
		
		$this->load->helper('afunction_helper');
		
		$periodetgawal = $tglawallaporanmesin[0].' - '.fbulan($tglawallaporanmesin[1]).' - '.$tglawallaporanmesin[2];
		$periodetgakhir = $tglakhirlaporanmesin[0].' - '.fbulan($tglakhirlaporanmesin[1]).' - '.$tglakhirlaporanmesin[2];

		$data['periodetgawal '] = $periodetgawal;
		$data['periodetgakhir '] = $periodetgakhir;
		
		$this->load->library('java_bridge');
		$cekjava=$this->java_bridge->checkJavaExtension(); 
		$bcreportdir = $this->config->item('APP_dirreport');
		
		
		if($cekjava){
			$irep = $bcreportdir.'\rpt_mts_ms_pk.jrxml';
			$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
			
			$report = $compileManager->compileReport($irep);
			$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
			
			$params = new Java("java.util.HashMap");
			$params->put("tglawal",  $tgawal);
			$params->put("tglakhir",  $tgakhir);
			$params->put("prmperiode", $periodetgawal . ' S/D' . $periodetgakhir );
			$params->put("nama_perusahaan", "PT. AUTOCOMP SYSTEMS INDONESIA");
			
			$class = new JavaClass("java.lang.Class");
			$class->forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			$driverManager = new JavaClass("java.sql.DriverManager");
			
			//db username and password
			$conn = $driverManager->getConnection("jdbc:sqlserver://localhost:1433;databaseName=db_pasi_new", "sa", "P4ssword");
			$jasperPrint = $fillManager->fillReport($report, $params, $conn);
			$outputPath = realpath(".")."\ireport/"."pdfmesin.pdf";
			
				$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
				$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);

			header("Content-type: application/pdf");
			
			readfile($outputPath);
			
			@unlink($outputPath);
		}	
	}
	
	function pdf_reportcustomspemasukanbarang_jasper_xls(){
	
		$tglawallaporanpemasukanbarang = (isset($_GET['tglawallaporanpemasukanbarang']) && !empty($_GET['tglawallaporanpemasukanbarang']))?$_GET['tglawallaporanpemasukanbarang']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanpemasukanbarang = (isset($_GET['tglakhirlaporanpemasukanbarang']) && !empty($_GET['tglakhirlaporanpemasukanbarang']))?$_GET['tglakhirlaporanpemasukanbarang']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		
			
		$tglawallaporanpemasukanbarang = explode("/", $tglawallaporanpemasukanbarang);	
		$tglakhirlaporanpemasukanbarang = explode("/", $tglakhirlaporanpemasukanbarang);	
		
		
		$tgawal =  $tglawallaporanpemasukanbarang[1].'/'.$tglawallaporanpemasukanbarang[0].'/'.$tglawallaporanpemasukanbarang[2];
		$tgakhir = $tglakhirlaporanpemasukanbarang[1].'/'.$tglakhirlaporanpemasukanbarang[0].'/'.$tglakhirlaporanpemasukanbarang[2];
		
		$this->load->helper('afunction_helper');
		
		$periodetgawal = $tglawallaporanpemasukanbarang[0].' - '.fbulan($tglawallaporanpemasukanbarang[1]).' - '.$tglawallaporanpemasukanbarang[2];
		$periodetgakhir = $tglakhirlaporanpemasukanbarang[0].' - '.fbulan($tglakhirlaporanpemasukanbarang[1]).' - '.$tglakhirlaporanpemasukanbarang[2];
		
		$data['periodetgawal '] = $periodetgawal;
		$data['periodetgakhir '] = $periodetgakhir;
		
		$this->load->library('java_bridge');
		$cekjava=$this->java_bridge->checkJavaExtension(); 
		$bcreportdir = $this->config->item('APP_dirreport');
		
		
		if($cekjava){
			
			$irep = $bcreportdir.'\rpt_incoming.jrxml';
			$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
			$report = $compileManager->compileReport($irep);
			$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
			
			$params = new Java("java.util.HashMap");
			//$params->put("inputdata1", "This is a test string");
			$params->put("tglawal",  $tgawal);
			$params->put("tglakhir",  $tgakhir);
			$params->put("prmperiode", $periodetgawal . ' S/D' . $periodetgakhir );
			$params->put("nama_perusahaan", "PT. AUTOCOMP SYSTEM INDONESIA");
			
			$class = new JavaClass("java.lang.Class");
			$class->forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			$driverManager = new JavaClass("java.sql.DriverManager");

			//db username and password
			$conn = $driverManager->getConnection("jdbc:sqlserver://localhost:1433;databaseName=db_pasi", "sa", "P4ssword");
			
			$jasperPrint = $fillManager->fillReport($report, $params, $conn);
			$outputPath = realpath(".")."\ireport"."\xlspenerimaanbrg.xls";
			
			$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
			
			//$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);
			try {
				$exporter = new java("net.sf.jasperreports.engine.export.JRXlsExporter");
				$exporter->setParameter(java("net.sf.jasperreports.engine.export.JRXlsExporterParameter")->IS_ONE_PAGE_PER_SHEET, java("java.lang.Boolean")->TRUE);
				$exporter->setParameter(java("net.sf.jasperreports.engine.export.JRXlsExporterParameter")->IS_WHITE_PAGE_BACKGROUND, java("java.lang.Boolean")->FALSE);
				$exporter->setParameter(java("net.sf.jasperreports.engine.export.JRXlsExporterParameter")->IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, java("java.lang.Boolean")->TRUE);
				$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
				$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);
			} catch (JavaException $ex) {
				echo $ex;
			}
			
			header("Content-type: application/vnd.ms-excel");
			header("Content-Disposition: attachment; filename=xlspenerimaanbrg.xls");
			readfile($outputPath);
            //unlink($outputPath);		
			//@unlink($outputPath);
		}
		
	}
	

	function view_reportcustomspemasukanbarang_jasper(){
	
		$tglawallaporanpemasukanbarang = (isset($_POST['tglawallaporanpemasukanbarang']) && !empty($_POST['tglawallaporanpemasukanbarang']))?$_POST['tglawallaporanpemasukanbarang']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanpemasukanbarang = (isset($_POST['tglakhirlaporanpemasukanbarang']) && !empty($_POST['tglakhirlaporanpemasukanbarang']))?$_POST['tglakhirlaporanpemasukanbarang']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
	
		$data['tglawallaporanpemasukanbarang'] = $tglawallaporanpemasukanbarang;
		$data['tglakhirlaporanpemasukanbarang'] = $tglakhirlaporanpemasukanbarang;
		$this->load->view('pasi_reports/view_reportcustomspemasukanbarang_jasper', $data);
	}
	
	function view_reportcustomspengeluaranbarang_jasper(){
	
		$tglawallaporanpengeluaranbarang = (isset($_POST['tglawallaporanpengeluaranbarang']) && !empty($_POST['tglawallaporanpengeluaranbarang']))?$_POST['tglawallaporanpengeluaranbarang']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanpengeluaranbarang = (isset($_POST['tglakhirlaporanpengeluaranbarang']) && !empty($_POST['tglakhirlaporanpengeluaranbarang']))?$_POST['tglakhirlaporanpengeluaranbarang']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
	
		$data['tglawallaporanpengeluaranbarang'] = $tglawallaporanpengeluaranbarang;
		$data['tglakhirlaporanpengeluaranbarang'] = $tglakhirlaporanpengeluaranbarang;
		$this->load->view('pasi_reports/view_reportcustomspengeluaranbarang_jasper', $data);
	}
	
	function view_reportcustomsbarangwip_jasper(){
	
		$tglawallaporanbarangwip = (isset($_POST['tglawallaporanbarangwip']) && !empty($_POST['tglawallaporanbarangwip']))?$_POST['tglawallaporanbarangwip']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanbarangwip = (isset($_POST['tglakhirlaporanbarangwip']) && !empty($_POST['tglakhirlaporanbarangwip']))?$_POST['tglakhirlaporanbarangwip']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
	
		$data['tglawallaporanbarangwip'] = $tglawallaporanbarangwip;
		$data['tglakhirlaporanbarangwip'] = $tglakhirlaporanbarangwip;
		$this->load->view('pasi_reports/view_reportcustomsbarangwip_jasper', $data);
	}
	function view_reportcustomsbahanbaku_jasper(){
	
		$tglawallaporanbahanbaku = (isset($_POST['tglawallaporanbahanbaku']) && !empty($_POST['tglawallaporanbahanbaku']))?$_POST['tglawallaporanbahanbaku']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanbahanbaku = (isset($_POST['tglakhirlaporanbahanbaku']) && !empty($_POST['tglakhirlaporanbahanbaku']))?$_POST['tglakhirlaporanbahanbaku']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
	
		$data['tglawallaporanbahanbaku'] = $tglawallaporanbahanbaku;
		$data['tglakhirlaporanbahanbaku'] = $tglakhirlaporanbahanbaku;
		$this->load->view('pasi_reports/view_reportcustomsbahanbaku_jasper', $data);	
	}
	function view_reportcustomsbarangjadi_jasper(){
	
		$tglawallaporanbarangjadi = (isset($_POST['tglawallaporanbarangjadi']) && !empty($_POST['tglawallaporanbarangjadi']))?$_POST['tglawallaporanbarangjadi']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanbarangjadi = (isset($_POST['tglakhirlaporanbarangjadi']) && !empty($_POST['tglakhirlaporanbarangjadi']))?$_POST['tglakhirlaporanbarangjadi']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
	
		$data['tglawallaporanbarangjadi'] = $tglawallaporanbarangjadi;
		$data['tglakhirlaporanbarangjadi'] = $tglakhirlaporanbarangjadi;
		$this->load->view('pasi_reports/view_reportcustomsbarangjadi_jasper', $data);		
	
	}
	
	function view_reportcustomsbarangsisa_jasper(){
	
		$tglawallaporanbarangsisa = (isset($_POST['tglawallaporanbarangsisa']) && !empty($_POST['tglawallaporanbarangsisa']))?$_POST['tglawallaporanbarangsisa']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanbarangsisa = (isset($_POST['tglakhirlaporanbarangsisa']) && !empty($_POST['tglakhirlaporanbarangsisa']))?$_POST['tglakhirlaporanbarangsisa']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
	
		$data['tglawallaporanbarangsisa'] = $tglawallaporanbarangsisa;
		$data['tglakhirlaporanbarangsisa'] = $tglakhirlaporanbarangsisa;
		$this->load->view('pasi_reports/view_reportcustomsbarangsisa_jasper', $data);		
	
	}
	function view_reportcustomsmesin_jasper(){
	
		$tglawallaporanmesin = (isset($_POST['tglawallaporanmesin']) && !empty($_POST['tglawallaporanmesin']))?$_POST['tglawallaporanmesin']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
		$tglakhirlaporanmesin = (isset($_POST['tglakhirlaporanmesin']) && !empty($_POST['tglakhirlaporanmesin']))?$_POST['tglakhirlaporanmesin']:die('{"sts":"ERROR","desc":" Tanggal Start Param Tidak Ditemukan"}');
	
		$data['tglawallaporanmesin'] = $tglawallaporanmesin;
		$data['tglakhirlaporanmesin'] = $tglakhirlaporanmesin;
		$this->load->view('pasi_reports/view_reportcustomsmesin_jasper', $data);		
		
	}
	function printpdfincoming(){
		$tglawallaporanpemasukanbarang = (isset($_POST['tglawallaporanpemasukanbarang']) && !empty($_POST['tglawallaporanpemasukanbarang']))?$_POST['tglawallaporanpemasukanbarang']:'';
		$tglakhirlaporanpemasukanbarang = (isset($_POST['tglakhirlaporanpemasukanbarang']) && !empty($_POST['tglakhirlaporanpemasukanbarang']))?$_POST['tglakhirlaporanpemasukanbarang']:'';
		
		$tglawallaporanpemasukanbarang = explode("/", $tglawallaporanpemasukanbarang);	
		$tglakhirlaporanpemasukanbarang = explode("/", $tglakhirlaporanpemasukanbarang);	
		
		
		$tgawal =  $tglawallaporanpemasukanbarang[1].'/'.$tglawallaporanpemasukanbarang[0].'/'.$tglawallaporanpemasukanbarang[2];
		$tgakhir = $tglakhirlaporanpemasukanbarang[1].'/'.$tglakhirlaporanpemasukanbarang[0].'/'.$tglakhirlaporanpemasukanbarang[2];
		
		$this->load->helper('afunction_helper');
		echo fbulan($tglawallaporanpemasukanbarang[1]);
		echo fbulan($tglakhirlaporanpemasukanbarang[1]);
		
		$periodetgawal = $tglawallaporanpemasukanbarang[0].' - '.fbulan($tglawallaporanpemasukanbarang[1]).' - '.$tglawallaporanpemasukanbarang[2];
		$periodetgakhir = $tglakhirlaporanpemasukanbarang[0].' - '.fbulan($tglakhirlaporanpemasukanbarang[1]).' - '.$tglakhirlaporanpemasukanbarang[2];	
	}
	
	function pdfpemasukanbarangperdokumen(){
		$tglawallaporanpemasukanbarang = (isset($_REQUEST['tglawallaporanpemasukanbarang']) && !empty($_REQUEST['tglawallaporanpemasukanbarang']))?$_REQUEST['tglawallaporanpemasukanbarang']:'-';
		$tglakhirlaporanpemasukanbarang = (isset($_REQUEST['tglakhirlaporanpemasukanbarang']) && !empty($_REQUEST['tglakhirlaporanpemasukanbarang']))?$_REQUEST['tglakhirlaporanpemasukanbarang']:'-';
		
		$tgawal = substr($tglawallaporanpemasukanbarang, 3, 2).'/'.substr($tglawallaporanpemasukanbarang, 0, 2).'/'.substr($tglawallaporanpemasukanbarang, 6, 4);
		$tgakhir = substr($tglakhirlaporanpemasukanbarang, 3, 2).'/'.substr($tglakhirlaporanpemasukanbarang, 0, 2).'/'.substr($tglakhirlaporanpemasukanbarang, 6, 4);
		
		$this->load->library('Pdf');
		$this->pdf->SetSubject('TCPDF Tutorial');
		$this->pdf->SetKeywords('PDF','tcpdf','html');
		
		
		$this->pdf->SetMargins(1.5, 1.5, 1.5);
		$this->pdf->SetHeaderMargin(1);
		$this->pdf->SetFooterMargin(1);
		
        $this->pdf->SetFont('times', '', 9);
		$this->pdf->addPage( 'L', 'LETTER' );
		
		$html = '<table width="2000" border="0">
				  <tr>
					<td width="100">A.</td>
					<td width="1900">LAPORAN PEMASUKAN BARANG PER DOKUMEN PABEAN</td>
				  </tr>
				  <tr>
					<td width="100">&nbsp;</td>
					<td width="1900">KAWASAN BERIKAT PT. EDS MANUFACTURING INDONESIA</td>
				  </tr>
				  <tr>
					<td width="100">&nbsp;</td>
					<td width="1900">PERIODE: '. $tgawal .' S.D '. $tgakhir .'</td>
				  </tr>
				</table>
				';
	
	$this->pdf->writeHTML($html, true, false, true, false, '');
	
	$this->pdf->SetFont('Times','B',12); //jenis font : Times New Romans, Bold, ukuran 14
	$this->pdf->Cell(0,7,"Laporan ",0,'C',1); //TBLR (untuk garis)=> B = Bottom,// L = Left, R = Right//untuk garis, C = center
	$this->fpdf->ln(0.3);
	$this->fpdf->write(0,'Tampilan Table MySql Dengan FPDF');
	$this->fpdf->Cell(1,0.5,'ID',1,0,'C');
	$this->fpdf->Cell(2,0.5,'NPM',1,0,'C');
	$this->fpdf->Cell(5,0.5,'NAMA',1,0,'C');
	$this->fpdf->Cell(6,0.5,'ALAMAT',1,0,'C');
	$this->fpdf->Ln();
	$this->pdf->output();
	
	
	$html2 = '
			<table width="3000" border="1">
		  <tr>
			<td width="58" rowspan="2"><div align="center">No.</div>      <div align="center"></div></td>
			<td width="140" rowspan="2"><div align="center">Jenis Dokumen </div></td>
			<td colspan="2"><div align="center">Dokumen Pabean </div></td>
			<td colspan="2"><div align="center">Bukti Penerimaan Barang</div></td>
			<td width="176" rowspan="2"><div align="center">Pemasok/Pengirim</div></td>
			<td width="130" rowspan="2"><div align="center">Kode Barang</div></td>
			<td width="339" rowspan="2"><div align="center">Nama Barang</div></td>
			<td width="218" rowspan="2"><div align="center">Satuan</div></td>
			<td width="247" rowspan="2"><div align="center">Jumlah</div></td>
			<td width="297" rowspan="2"><div align="center">Nilai Barang</div></td>
		  </tr>
		  <tr>
			<td width="132"><div align="center">Nomor</div></td>
			<td width="123"><div align="center">Tanggal</div></td>
			<td width="119"><div align="center">Nomor</div></td>
			<td width="146"><div align="center">Tanggal</div></td>
		  </tr>
		</table>
			';
		
		//$this->pdf->writeHTML($html2, true, false, true, false, '');


// Print text using writeHTMLCell()
//$this->pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
		//$this->pdf->writeHTML($html, true, false, true, false, '');
		//$this->pdf->Output('example_001.pdf', 'I');
		$this->pdf->Output('example_001.pdf', 'FD');
	}
	
	
	function print_laporanpengeluaranperdok(){
		
		$tgawalpengeluaranbrgperdokumen= isset($_GET['tgawalpengeluaranbrgperdokumen'])?$_GET['tgawalpengeluaranbrgperdokumen']:'a';
		$tgakhirpengeluaranbrgperdokumen= isset($_GET['tgakhirpengeluaranbrgperdokumen'])?$_GET['tgakhirpengeluaranbrgperdokumen']:'a';
		
		$tgawalpengeluaranbrgperdokumen = explode("/", $tgawalpengeluaranbrgperdokumen);	
		$tgakhirpengeluaranbrgperdokumen = explode("/", $tgakhirpengeluaranbrgperdokumen);	
		
		
		$tgawal =  $tgawalpengeluaranbrgperdokumen[1].'/'.$tgawalpengeluaranbrgperdokumen[0].'/'.$tgawalpengeluaranbrgperdokumen[2];
		$tgakhir = $tgakhirpengeluaranbrgperdokumen[1].'/'.$tgakhirpengeluaranbrgperdokumen[0].'/'.$tgakhirpengeluaranbrgperdokumen[2];
		
		$this->load->helper('afunction_helper');
		//echo fbulan($tgawalpengeluaranbrgperdokumen[1]);
		//echo fbulan($tgakhirpengeluaranbrgperdokumen[1]);
		
		$periodetgawal = $tgawalpengeluaranbrgperdokumen[0].' - '.fbulan($tgawalpengeluaranbrgperdokumen[1]).' - '.$tgawalpengeluaranbrgperdokumen[2];
		$periodetgakhir = $tgakhirpengeluaranbrgperdokumen[0].' - '.fbulan($tgakhirpengeluaranbrgperdokumen[1]).' - '.$tgakhirpengeluaranbrgperdokumen[2];
		$periode = $periodetgawal . ' S/D ' . $periodetgakhir ;
		//echo $tgawal.$tgakhir;  die();
		$this->load->library('java_bridge');
		$cekjava=$this->java_bridge->checkJavaExtension(); 
		$bcreportdir = $this->config->item('APP_dirreport');
		
		if($cekjava){
			$irep = $bcreportdir.'\rpt_outgoing.jrxml';
			$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
			$report = $compileManager->compileReport($irep);
			$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
			
			$params = new Java("java.util.HashMap");
			//$params->put("inputdata1", "This is a test string");
			$params->put("tglawal", $tgawal);
			$params->put("tglakhir", $tgakhir);
			$params->put("periode", $periodetgawal);
			$params->put("nama_perusahaan", "PT. EDS MANUFACTURING INDONESIA");
		//	$params->put("number", 3.00);
			
			
			
			$class = new JavaClass("java.lang.Class");
			$class->forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			$driverManager = new JavaClass("java.sql.DriverManager");

			//db username and password
			$conn = $driverManager->getConnection("jdbc:sqlserver://localhost:1433;databaseName=db_pemi", "sa", "a1234567");
			
			$jasperPrint = $fillManager->fillReport($report, $params, $conn);
			$outputPath = realpath(".")."\ireport/"."pdfpengeluaranbrg.pdf";
			
				$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
				$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);

			header("Content-type: application/pdf");
			readfile($outputPath);
			//$data['outputPath'] = $outputPath; 
			//$data['outputPath'] = base_url().'ireport/output.pdf';
			@unlink($outputPath);
			
		}
	
	}
	
}

