<?php
class CT_bc27 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');
        }
		
			$this->load->model("exim/mdl_bc27", 'mdl_bc27');
  }
  
	function index(){

		$this->load->view('exim/view_bc27');
	}
	
	function loaddata(){
		$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_bc_out_hdr'; // get index row - i.e. user click to sort
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$q =(isset($_POST['q']) && !empty($_POST['q']))?$_POST['q']:'0';
		$id_bc_out_hdr =(isset($_POST['id_bc_out_hdr']) && !empty($_POST['id_bc_out_hdr']))?$_POST['id_bc_out_hdr']:'';
			
		$where = " 1=1 and typedok='BC27' ";
		
		if (isset($_POST['tglawal']) and isset($_POST['tglakhir'])){
			$tglawal=$_POST['tglawal'];
			$tglakhir=$_POST['tglakhir'];
			$where .= " and TGDAFT between '$tglawal' and '$tglakhir' ";
		}	
		
		if ($q=='66'){
			$where =" id_bc_out_hdr=$id_bc_out_hdr ";
		}
		

		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){
					
					if ( $k->field == "CAR" ) {
						$searchString = $k->data;
						$where .= " and CAR like  '%".$searchString."%'"; 
					} else if ( $k->field == "NAMABELI" ) {
						$searchString = $k->data;
						$where .= " and NAMABELI like  '%".$searchString."%'"; 
					} else if ( $k->field == "NEGBELI" ) {
						$searchString = $k->data;
						$where .= " and NEGBELI like  '%".$searchString."%'"; 
					} else if ( $k->field == "NOINV" ) {
						$searchString = $k->data;
						$where .= " and NOINV like  '%".$searchString."%'"; 
					} else if ( $k->field == "NilInv" ) {
						$searchString = $k->data;
						$where .= " and NilInv =  $searchString"; 
					} else if ( $k->field == "TGINV" ) {
						$searchString = $k->data;
						$where .= " and TGINV =  '$searchString'"; 
					} else if ( $k->field == "KDVAL" ) {
						$searchString = $k->data;
						$where .= " and KDVAL like  '%".$searchString."%'"; 
					}  else if ( $k->field == "statusdok" ) {
						$searchString = $k->data;
						$where .= " and statusdok like  '%".$searchString."%'"; 
					} else if ( $k->field == "NODAFT" ) {
						$searchString = $k->data;
						$where .= " and NODAFT like  '%".$searchString."%'"; 
					} 
			
				}
			}
		}	
			
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc27->bc27hdr_All($limit,$start,$sidx,$sord, $where);
		$count = $this->mdl_bc27->bc27hdr_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_bc_out_hdr']=$r->id_bc_out_hdr; 
			$responce->rows[$i]['CAR']=$r->CAR; 
			$responce->rows[$i]['JnEks']=$r->JnEks; 
			$responce->rows[$i]['KatEks']=$r->KatEks; 
			$responce->rows[$i]['JNPEB']=$r->JNPEB; 
			$responce->rows[$i]['JNEKSOld']=$r->JNEKSOld; 
			$responce->rows[$i]['JNLAIN']=$r->JNLAIN; 
			$responce->rows[$i]['JNDAG']=$r->JNDAG; 
			$responce->rows[$i]['JNBYR']=$r->JNBYR; 
			$responce->rows[$i]['IDEKS']=$r->IDEKS; 
			$responce->rows[$i]['NPWPEKS']=$r->NPWPEKS; 
			$responce->rows[$i]['NamaEks']=$r->NamaEks; 
			$responce->rows[$i]['AlmtEks']=$r->AlmtEks; 
			$responce->rows[$i]['NoSiup']=$r->NoSiup; 
			$responce->rows[$i]['TgSiup']=$r->TgSiup; 
			$responce->rows[$i]['JnPerus']=$r->JnPerus; 
			$responce->rows[$i]['NoTdp']=$r->NoTdp; 
			$responce->rows[$i]['TgTdp']=$r->TgTdp; 
			$responce->rows[$i]['Niper']=$r->Niper; 
			$responce->rows[$i]['StatusH']=$r->StatusH; 
			$responce->rows[$i]['IdQq']=$r->IdQq; 
			$responce->rows[$i]['NpwpQq']=$r->NpwpQq; 
			$responce->rows[$i]['NamaQq']=$r->NamaQq; 
			$responce->rows[$i]['AlmtQq']=$r->AlmtQq; 
			$responce->rows[$i]['NiperQq']=$r->NiperQq; 
			$responce->rows[$i]['NAMABELI']=$r->NAMABELI; 
			$responce->rows[$i]['ALMTBELI']=$r->ALMTBELI; 
			$responce->rows[$i]['NEGBELI']=$r->NEGBELI; 
			$responce->rows[$i]['IDPPJK']=$r->IDPPJK; 
			$responce->rows[$i]['NPWPPPJK']=$r->NPWPPPJK; 
			$responce->rows[$i]['NamaPpjk']=$r->NamaPpjk; 
			$responce->rows[$i]['AlmtPpjk']=$r->AlmtPpjk; 
			$responce->rows[$i]['NoPpjk']=$r->NoPpjk; 
			$responce->rows[$i]['TgPpjk']=$r->TgPpjk; 
			$responce->rows[$i]['MODA']=$r->MODA; 
			$responce->rows[$i]['TGEKS']=$r->TGEKS; 
			$responce->rows[$i]['CARRIER']=$r->CARRIER; 
			$responce->rows[$i]['VOY']=$r->VOY; 
			$responce->rows[$i]['NOSHIPORD']=$r->NOSHIPORD; 
			$responce->rows[$i]['TGSHIPORD']=$r->TGSHIPORD; 
			$responce->rows[$i]['PELMUAT']=$r->PELMUAT; 
			$responce->rows[$i]['PELBONGKAR']=$r->PELBONGKAR; 
			$responce->rows[$i]['PELTRANSIT']=$r->PELTRANSIT; 
			$responce->rows[$i]['NOINV']=$r->NOINV; 
			$responce->rows[$i]['TGINV']=$r->TGINV; 
			$responce->rows[$i]['NOLPSE']=$r->NOLPSE; 
			$responce->rows[$i]['TGLPSE']=$r->TGLPSE; 
			$responce->rows[$i]['PROPBRG']=$r->PROPBRG; 
			$responce->rows[$i]['NEGTUJU']=$r->NEGTUJU; 
			$responce->rows[$i]['FLSIE']=$r->FLSIE; 
			$responce->rows[$i]['FLKARANT']=$r->FLKARANT; 
			$responce->rows[$i]['FLSM']=$r->FLSM; 
			$responce->rows[$i]['FLIZLAIN']=$r->FLIZLAIN; 
			$responce->rows[$i]['DELIVERY']=$r->DELIVERY; 
			$responce->rows[$i]['KDVAL']=$r->KDVAL; 
			$responce->rows[$i]['KdHrg']=$r->KdHrg; 
			$responce->rows[$i]['NilInv']=$r->NilInv; 
			$responce->rows[$i]['FREIGHT']=$r->FREIGHT; 
			$responce->rows[$i]['ASURANSI']=$r->ASURANSI; 
			$responce->rows[$i]['KdAss']=$r->KdAss; 
			$responce->rows[$i]['FOB']=$r->FOB; 
			$responce->rows[$i]['MERK']=$r->MERK; 
			$responce->rows[$i]['JMCONT']=$r->JMCONT; 
			$responce->rows[$i]['BRUTO']=$r->BRUTO; 
			$responce->rows[$i]['NETTO']=$r->NETTO; 
			$responce->rows[$i]['JMBRG']=$r->JMBRG; 
			$responce->rows[$i]['JMBRGCTH']=$r->JMBRGCTH; 
			$responce->rows[$i]['JMBRGGAB']=$r->JMBRGGAB; 
			$responce->rows[$i]['JMBRGPJT']=$r->JMBRGPJT; 
			$responce->rows[$i]['NODAFT']=$r->NODAFT; 
			$responce->rows[$i]['TGDAFT']=$r->TGDAFT; 
			$responce->rows[$i]['KDKTR']=$r->KDKTR; 
			$responce->rows[$i]['KTRGATE']=$r->KTRGATE; 
			$responce->rows[$i]['NILPE']=$r->NILPE; 
			$responce->rows[$i]['KDBANK']=$r->KDBANK; 
			$responce->rows[$i]['LOKBANK']=$r->LOKBANK; 
			$responce->rows[$i]['NOSSP']=$r->NOSSP; 
			$responce->rows[$i]['TGSSP']=$r->TGSSP; 
			$responce->rows[$i]['JNTPB']=$r->JNTPB; 
			$responce->rows[$i]['LOKTPB']=$r->LOKTPB; 
			$responce->rows[$i]['KDLOKBRG']=$r->KDLOKBRG; 
			$responce->rows[$i]['KDKTRMUAT']=$r->KDKTRMUAT; 
			$responce->rows[$i]['KDKTRPRIKS']=$r->KDKTRPRIKS; 
			$responce->rows[$i]['TGSIAP']=$r->TGSIAP; 
			$responce->rows[$i]['WKSIAP']=$r->WKSIAP; 
			$responce->rows[$i]['ASALDATA']=$r->ASALDATA; 
			$responce->rows[$i]['TPNAME']=$r->TPNAME; 
			$responce->rows[$i]['PEBOK']=$r->PEBOK; 
			$responce->rows[$i]['LENGKAP']=$r->LENGKAP; 
			$responce->rows[$i]['JNPARTOF']=$r->JNPARTOF; 
			$responce->rows[$i]['BENDERA']=$r->BENDERA;
			$responce->rows[$i]['TTDPEB']=$r->TTDPEB;
			$responce->rows[$i]['STATUS']=$r->STATUS;
			$responce->rows[$i]['SNRF']=$r->SNRF;
			$responce->rows[$i] ['NOBCF'] =$r->NOBCF; 
			$responce->rows[$i] ['TGBCF'] =$r->TGBCF; 
			$responce->rows[$i] ['SERIBCF'] =$r->SERIBCF; 
			$responce->rows[$i] ['NOMOREDI'] =$r->NOMOREDI; 
			$responce->rows[$i] ['KMDT'] =$r->KMDT; 
			$responce->rows[$i] ['VOLUME'] =$r->VOLUME; 
			$responce->rows[$i] ['KDHANGGAR'] =$r->KDHANGGAR; 
			$responce->rows[$i] ['KONS']=$r->KONS; 
			$responce->rows[$i] ['JMLKMSPEB']=$r->JMLKMSPEB; 
			$responce->rows[$i] ['PELMUATEKS'] =$r->PELMUATEKS; 
			$responce->rows[$i] ['NILKURS']=$r->NILKURS; 
			$responce->rows[$i] ['PNBP'] =$r->PNBP; 
			$responce->rows[$i] ['NOBC11'] =$r->NOBC11; 
			$responce->rows[$i] ['TGBC11'] =$r->TGBC11; 
			$responce->rows[$i] ['POSBC11'] =$r->POSBC11; 
			$responce->rows[$i] ['SUBPOSBC11'] =$r->SUBPOSBC11; 
			$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] ['typedok'] =$r->typedok; 
			$responce->rows[$i] ['statusdok']=$r->statusdok; 
			$responce->rows[$i] ['noinv1'] =$r->noinv1; 
			$responce->rows[$i] ['tginv1'] =$r->tginv1; 
			$responce->rows[$i] ['inv_hdr_id'] =$r->inv_hdr_id; 
			$responce->rows[$i] ['bc_in_from_in'] =$r->bc_in_from_in; 
			$responce->rows[$i] ['nopol'] =$r->nopol; 
			$responce->rows[$i] ['doc_out_date'] =$r->doc_out_date; 
		
		
			$i++;
		}
		echo json_encode($responce);
			
        
		
		
    }
	
	 function view_bc27_getdata(){

		$this->load->view('exim/view_bc27_getdata');

	}
	
	function load_bc27_getadata(){
		$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']:'idpebhdr'; // get index row - i.e. user click to sort
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$status =(isset($_POST['statusbc27loaddatahdr']) && !empty($_POST['statusbc27loaddatahdr']))?$_POST['statusbc27loaddatahdr']:'XX';
			
		$where = " 1=1 ";
		
		if($status == '00'){
			
			$where = " 1=1 and status='00' ";
		};
		

		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){
					
					if ( $k->field == "gabinvoice" ) {
						$searchString = $k->data;
						$where .= " and gabinvoice like  '%".$searchString."%'"; 
					} else if ( $k->field == "laodeddate" ) {
						$searchString = $k->data;
						$where .= " and laodeddate =  '$searchString'"; 
					} else if ( $k->field == "NAMABELI" ) {
						$searchString = $k->data;
						$where .= " and NAMABELI like  '%".$searchString."%'"; 
					} else if ( $k->field == "NEGBELI" ) {
						$searchString = $k->data;
						$where .= " and NEGBELI like  '%".$searchString."%'"; 
					} else if ( $k->field == "NOINV" ) {
						$searchString = $k->data;
						$where .= " and NOINV like  '%".$searchString."%'"; 
					} else if ( $k->field == "NilInv" ) {
						$searchString = $k->data;
						$where .= " and NilInv =  $searchString"; 
					} else if ( $k->field == "TGINV" ) {
						$searchString = $k->data;
						$where .= " and TGINV =  '$searchString'"; 
					} else if ( $k->field == "KDVAL" ) {
						$searchString = $k->data;
						$where .= " and KDVAL like  '%".$searchString."%'"; 
					} 
			
				}
			}
		}	
			
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc27->bc27getdatahdr_All($limit,$start,$sidx,$sord, $where);
		$count = $this->mdl_bc27->bc27getdatahdr_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]['idbc27hdr']=$r->idbc27hdr; 
		  $responce->rows[$i]['CAR']=$r->CAR; 
		  $responce->rows[$i]['JnEks']=$r->JnEks; 
		  $responce->rows[$i]['KatEks']=$r->KatEks; 
		  $responce->rows[$i]['JNPEB']=$r->JNPEB; 
		  $responce->rows[$i]['JNEKSOld']=$r->JNEKSOld; 
		  $responce->rows[$i]['JNLAIN']=$r->JNLAIN; 
		  $responce->rows[$i]['JNDAG']=$r->JNDAG; 
		  $responce->rows[$i]['JNBYR']=$r->JNBYR; 
		  $responce->rows[$i]['IDEKS']=$r->IDEKS; 
		  $responce->rows[$i]['NPWPEKS']=$r->NPWPEKS; 
		  $responce->rows[$i]['NamaEks']=$r->NamaEks; 
		  $responce->rows[$i]['AlmtEks']=$r->AlmtEks; 
		  $responce->rows[$i]['NoSiup']=$r->NoSiup; 
		  $responce->rows[$i]['TgSiup']=$r->TgSiup; 
		  $responce->rows[$i]['JnPerus']=$r->JnPerus; 
		  $responce->rows[$i]['NoTdp']=$r->NoTdp; 
		  $responce->rows[$i]['TgTdp']=$r->TgTdp; 
		  $responce->rows[$i]['Niper']=$r->Niper; 
		  $responce->rows[$i]['StatusH']=$r->StatusH; 
		  $responce->rows[$i]['IdQq']=$r->IdQq; 
		  $responce->rows[$i]['NpwpQq']=$r->NpwpQq; 
		  $responce->rows[$i]['NamaQq']=$r->NamaQq; 
		  $responce->rows[$i]['AlmtQq']=$r->AlmtQq; 
		  $responce->rows[$i]['NiperQq']=$r->NiperQq; 
		  $responce->rows[$i]['NAMABELI']=$r->NAMABELI; 
		  $responce->rows[$i]['ALMTBELI']=$r->ALMTBELI; 
		  $responce->rows[$i]['NEGBELI']=$r->NEGBELI; 
		  $responce->rows[$i]['IDPPJK']=$r->IDPPJK; 
		  $responce->rows[$i]['NPWPPPJK']=$r->NPWPPPJK; 
		  $responce->rows[$i]['NamaPpjk']=$r->NamaPpjk; 
		  $responce->rows[$i]['AlmtPpjk']=$r->AlmtPpjk; 
		  $responce->rows[$i]['NoPpjk']=$r->NoPpjk; 
		  $responce->rows[$i]['TgPpjk']=$r->TgPpjk; 
		  $responce->rows[$i]['MODA']=$r->MODA; 
		  $responce->rows[$i]['TGEKS']=$r->TGEKS; 
		  $responce->rows[$i]['CARRIER']=$r->CARRIER; 
		  $responce->rows[$i]['VOY']=$r->VOY; 
		  $responce->rows[$i]['NOSHIPORD']=$r->NOSHIPORD; 
		  $responce->rows[$i]['TGSHIPORD']=$r->TGSHIPORD; 
		  $responce->rows[$i]['PELMUAT']=$r->PELMUAT; 
		  $responce->rows[$i]['PELBONGKAR']=$r->PELBONGKAR; 
		  $responce->rows[$i]['PELTRANSIT']=$r->PELTRANSIT; 
		  $responce->rows[$i]['NOINV']=$r->NOINV; 
		  $responce->rows[$i]['TGINV']=$r->TGINV; 
		  $responce->rows[$i]['NOLPSE']=$r->NOLPSE; 
		  $responce->rows[$i]['TGLPSE']=$r->TGLPSE; 
		  $responce->rows[$i]['PROPBRG']=$r->PROPBRG; 
		  $responce->rows[$i]['NEGTUJU']=$r->NEGTUJU; 
		  $responce->rows[$i]['FLSIE']=$r->FLSIE; 
		  $responce->rows[$i]['FLKARANT']=$r->FLKARANT; 
		  $responce->rows[$i]['FLSM']=$r->FLSM; 
		  $responce->rows[$i]['FLIZLAIN']=$r->FLIZLAIN; 
		  $responce->rows[$i]['DELIVERY']=$r->DELIVERY; 
		  $responce->rows[$i]['KDVAL']=$r->KDVAL; 
		  $responce->rows[$i]['KdHrg']=$r->KdHrg; 
		  $responce->rows[$i]['NilInv']=$r->NilInv; 
		  $responce->rows[$i]['FREIGHT']=$r->FREIGHT; 
		  $responce->rows[$i]['ASURANSI']=$r->ASURANSI; 
		  $responce->rows[$i]['KdAss']=$r->KdAss; 
		  $responce->rows[$i]['FOB']=$r->FOB; 
		  $responce->rows[$i]['MERK']=$r->MERK; 
		  $responce->rows[$i]['JMCONT']=$r->JMCONT; 
		  $responce->rows[$i]['BRUTO']=$r->BRUTO; 
		  $responce->rows[$i]['NETTO']=$r->NETTO; 
		  $responce->rows[$i]['JMBRG']=$r->JMBRG; 
		  $responce->rows[$i]['JMBRGCTH']=$r->JMBRGCTH; 
		  $responce->rows[$i]['JMBRGGAB']=$r->JMBRGGAB; 
		  $responce->rows[$i]['JMBRGPJT']=$r->JMBRGPJT; 
		  $responce->rows[$i]['NODAFT']=$r->NODAFT; 
		  $responce->rows[$i]['TGDAFT']=$r->TGDAFT; 
		  $responce->rows[$i]['KDKTR']=$r->KDKTR; 
		  $responce->rows[$i]['KTRGATE']=$r->KTRGATE; 
		  $responce->rows[$i]['NILPE']=$r->NILPE; 
		  $responce->rows[$i]['KDBANK']=$r->KDBANK; 
		  $responce->rows[$i]['LOKBANK']=$r->LOKBANK; 
		  $responce->rows[$i]['NOSSP']=$r->NOSSP; 
		  $responce->rows[$i]['TGSSP']=$r->TGSSP; 
		  $responce->rows[$i]['JNTPB']=$r->JNTPB; 
		  $responce->rows[$i]['LOKTPB']=$r->LOKTPB; 
		  $responce->rows[$i]['KDLOKBRG']=$r->KDLOKBRG; 
		  $responce->rows[$i]['KDKTRMUAT']=$r->KDKTRMUAT; 
		  $responce->rows[$i]['KDKTRPRIKS']=$r->KDKTRPRIKS; 
		  $responce->rows[$i]['TGSIAP']=$r->TGSIAP; 
		  $responce->rows[$i]['WKSIAP']=$r->WKSIAP; 
		  $responce->rows[$i]['ASALDATA']=$r->ASALDATA; 
		  $responce->rows[$i]['TPNAME']=$r->TPNAME; 
		  $responce->rows[$i]['PEBOK']=$r->PEBOK; 
		  $responce->rows[$i]['LENGKAP']=$r->LENGKAP; 
		  $responce->rows[$i]['JNPARTOF']=$r->JNPARTOF; 
		  $responce->rows[$i]['BENDERA']=$r->BENDERA;
		  $responce->rows[$i]['TTDPEB']=$r->TTDPEB;
		  $responce->rows[$i]['STATUS']=$r->STATUS;
		  $responce->rows[$i]['SNRF']=$r->SNRF;
		  $responce->rows[$i] ['NOBCF'] =$r->NOBCF; 
		  $responce->rows[$i] ['TGBCF'] =$r->TGBCF; 
		  $responce->rows[$i] ['SERIBCF'] =$r->SERIBCF; 
		  $responce->rows[$i] ['NOMOREDI'] =$r->NOMOREDI; 
		  $responce->rows[$i] ['KMDT'] =$r->KMDT; 
		  $responce->rows[$i] ['VOLUME'] =$r->VOLUME; 
		  $responce->rows[$i] ['KDHANGGAR'] =$r->KDHANGGAR; 
		  $responce->rows[$i] ['KONS']=$r->KONS; 
		  $responce->rows[$i] ['JMLKMSPEB']=$r->JMLKMSPEB; 
		  $responce->rows[$i] ['PELMUATEKS'] =$r->PELMUATEKS; 
		  $responce->rows[$i] ['NILKURS']=$r->NILKURS; 
		  $responce->rows[$i] ['PNBP'] =$r->PNBP; 
		  $responce->rows[$i] ['NOBC11'] =$r->NOBC11; 
		  $responce->rows[$i] ['TGBC11'] =$r->TGBC11; 
		  $responce->rows[$i] ['POSBC11'] =$r->POSBC11; 
		  $responce->rows[$i] ['SUBPOSBC11'] =$r->SUBPOSBC11; 
		  $responce->rows[$i] ['jnkemas']=$r->jnkemas; 
		  $responce->rows[$i] ['gabinvoice'] =$r->gabinvoice; 
		  $responce->rows[$i] ['filename'] =$r->filename; 
		  $responce->rows[$i] ['laodeddate'] =$r->laodeddate; 

			
			$i++;
		}
		echo json_encode($responce);
		
    }
  
	function getdatabc27(){

		$filename = (isset($_POST['filename']) && !empty($_POST['filename']))?$_POST['filename']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$id_bc27_upload = (isset($_POST['id_bc27_upload']) && !empty($_POST['id_bc27_upload']))?$_POST['id_bc27_upload']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$username = $this->session->userdata('DX_username');
		
	/* 	echo " exec('[spi_getdata_bc27] @filename=''$filename'', @idfile=$id_bc27_upload, @username=''$username'' ')";
	    die();  */
		$qry = $this->db->query("
			BEGIN TRY
			
			 exec('[spi_getdata_bc27] @filename=''$filename'', @idfile=$id_bc27_upload, @username=''$username'' ')
			
			END TRY
			BEGIN CATCH 
				SELECT 
				'06' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
			");
		 $rs = $qry->result_array();
		 // $r = $qry->result();		
		 // var_dump($r);die();
		 foreach ($rs as $row){
			 $status = $row['status'];
			 $msg = $row['description'];
		 }  
		 
		 echo json_encode(array('status' => $status, 'desc' => $msg));



	}
	
	function view_bc27_datauploaded(){
	
		$this->load->view('exim/view_bc27_datauploaded');
	
	}
	
	function prosesdatasa(){
	    $username = $this->session->userdata('DX_username');
		$idbc27hdr = (isset($_POST['idbc27hdr']) && !empty($_POST['idbc27hdr']))?$_POST['idbc27hdr']:die('{"sts":"ERROR","desc":"SA Param Tidak Ditemukan"}');
		$qry = $this->db->query("
			BEGIN TRY
			
			 exec('[spi_getdata_bc27] @idbc27hdr=$idbc27hdr, @userid=''$username'' ')
			
			END TRY
			BEGIN CATCH 
				SELECT 
				'06' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
			");
		 $rs = $qry->result_array();
		 // $r = $qry->result();		
		 // var_dump($r);die();
		 foreach ($rs as $row){
			 $status = $row['status'];
			 $msg = $row['description'];
		 }  
		 
		 echo json_encode(array('status' => $status, 'desc' => $msg));
	
	}
	function view_bc27_getassy(){
		$idbc27hdr = (isset($_POST['idbc27hdr']) && !empty($_POST['idbc27hdr']))?$_POST['idbc27hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$gabinvoice = (isset($_POST['gabinvoice']) && !empty($_POST['gabinvoice']))?$_POST['gabinvoice']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$data['idbc27hdr']=$idbc27hdr;
		$data['gabinvoice']=$gabinvoice;
		$this->load->view('exim/view_bc27_getassy', $data);
	
	}
	
	function data_bc27_getdatadetil(){
	
	$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']:'[idbc23dtl]'; // get index row - i.e. user click to sort
	$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
	
	// $gabinvoice = (isset($_POST['gabinvoice']) && !empty($_POST['gabinvoice']))?$_POST['gabinvoice']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
	$idbc27hdr = (isset($_POST['idbc27hdr']) && !empty($_POST['idbc27hdr']))?$_POST['idbc27hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
	
	$where = " 1=1 and idbc27hdr='$idbc27hdr' ";
	

	if ($search == 'true'){
		if (!empty($filters)){
			$array = json_decode($filters);
			foreach($array->rules as $arr=>$k){
				
				if ( $k->field == "[idbc23dtl]" ) {
					$searchString = $k->data;
					$where .= " and [idbc23dtl] like  '%".$searchString."%'"; 
				}
		
			}
		}
	}	
		
	$start = $limit*$page - $limit;
	if ($start<0) $start=0;
	
	$records = $this->mdl_bc27->bc27getdatadtl_All($limit,$start,$sidx,$sord, $where);
	$count = $this->mdl_bc27->bc27getdatadtl_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]['idbc27dtl']=$r->idbc27dtl;
		  $responce->rows[$i]['idbc27hdr']=$r->idbc27hdr;
		  $responce->rows[$i]['CAR']=$r->CAR;
		  $responce->rows[$i]['SERIBRG']=$r->SERIBRG;
		  $responce->rows[$i]['HS']=$r->HS;
		  $responce->rows[$i]['URBRG1']=$r->URBRG1;
		  $responce->rows[$i]['URBRG2']=$r->URBRG2;
		  $responce->rows[$i]['URBRG3']=$r->URBRG3;
		  $responce->rows[$i]['URBRG4']=$r->URBRG4;
		  $responce->rows[$i]['DMERK']=$r->DMERK;
		  $responce->rows[$i]['SIZE']=$r->SIZE;
		  $responce->rows[$i]['TYPE']=$r->TYPE;
		  $responce->rows[$i]['KDBRG']=$r->KDBRG;
		  $responce->rows[$i]['KDIZIN']=$r->KDIZIN;
		  $responce->rows[$i]['NOIZIN']=$r->NOIZIN;
		  $responce->rows[$i]['TGIZIN']=$r->TGIZIN;
		  $responce->rows[$i]['JMKOLI']=$r->JMKOLI;
		  $responce->rows[$i]['JNKOLI']=$r->JNKOLI;
		  $responce->rows[$i]['DNilInv']=$r->DNilInv;
		  $responce->rows[$i]['FOBPERBRG']=$r->FOBPERBRG;
		  $responce->rows[$i]['FOBPERSAT']=$r->FOBPERSAT;
		  $responce->rows[$i]['KDPE']=$r->KDPE;
		  $responce->rows[$i]['TARIPPE']=$r->TARIPPE;
		  $responce->rows[$i]['HPATOK']=$r->HPATOK;
		  $responce->rows[$i]['JMSATUAN']=$r->JMSATUAN;
		  $responce->rows[$i]['JNSATUAN']=$r->JNSATUAN;
		  $responce->rows[$i]['NETDET']=$r->NETDET;
		  $responce->rows[$i]['JMSATPE']=$r->JMSATPE;
		  $responce->rows[$i]['JNSATPE']=$r->JNSATPE;
		  $responce->rows[$i]['KDVALPE']=$r->KDVALPE;
		  $responce->rows[$i]['NILVALPE']=$r->NILVALPE;
		  $responce->rows[$i]['PEPERBRG']=$r->PEPERBRG;
		  $responce->rows[$i]['DTLOK']=$r->DTLOK;
		  $responce->rows[$i]['NCV']=$r->NCV;
		  $responce->rows[$i]['DVolume']=$r->DVolume;
		  $responce->rows[$i]['NegAsal']=$r->NegAsal;
		  $responce->rows[$i]['NOINV']=$r->NOINV;
		  $responce->rows[$i]['gabinvoice']=$r->gabinvoice;
	
		$i++;
	}
		echo json_encode($responce);
	
  
	}
	
	function prosesdatabc27(){
	    $username = $this->session->userdata('DX_username');
		$idbc27hdr = (isset($_POST['idbc27hdr']) && !empty($_POST['idbc27hdr']))?$_POST['idbc27hdr']:die('{"sts":"ERROR","desc":"SA Param Tidak Ditemukan"}');
		
		
		
		echo ""; die();
		
		//echo " exec('[spi_proses_bc27] @idbc27hdr=$idbc27hdr, @userid=''$username'' ')"; die();
		$qry = $this->db->query("
			BEGIN TRY
			
			 exec('[spi_proses_bc27] @idbc27hdr=$idbc27hdr, @userid=''$username'' ')
			
			END TRY
			BEGIN CATCH 
				SELECT 
				'06' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
			");
		 $rs = $qry->result_array();
		 // $r = $qry->result();		
		 // var_dump($r);die();
		 foreach ($rs as $row){
			 $status = $row['status'];
			 $msg = $row['description'];
		 }  
		 
		 echo json_encode(array('sts' => $status, 'desc' => $msg));
	
	}
	
	function update_bc27_sa_hdr(){
		$username = $this->session->userdata('DX_username');
		$idbc27hdr = (isset($_POST['id_bc_out_hdr']) && !empty($_POST['id_bc_out_hdr']))?$_POST['id_bc_out_hdr']:die('{"sts":"ERROR","desc":"SA Param Tidak Ditemukan"}');
		$nobc27 = (isset($_POST['nobc27']) && !empty($_POST['nobc27']))?$_POST['nobc27']:die('{"sts":"ERROR","desc":"NO BC Param Tidak Ditemukan"}');
		$tglbc27 = (isset($_POST['tglbc27']) && !empty($_POST['tglbc27']))?$_POST['tglbc27']:die('{"sts":"ERROR","desc":"TGL Param Tidak Ditemukan"}');
		$nilkursbc27 = (isset($_POST['nilkursbc27']) && !empty($_POST['nilkursbc27']))?$_POST['nilkursbc27']:0;
		
		if ($tglbc27 != ''){
			$tglbc27=explode('/' , $tglbc27);
			$tglbc27 = $tglbc27[1].'/'.$tglbc27[0].'/'.$tglbc27[2];
		}
		
		
		//echo " exec(' sp_insertmodulbc27 @idbc27hdr=$idbc27hdr, @userid=''$username'', @nobc27=''$nobc27'', @tglbc27=''$tglbc27'',@nilkurs=$nilkursbc27  ')"; die();
		$qry = $this->db->query("
			BEGIN TRY
			
			 exec(' sp_insertmodulbc27 @idbc27hdr=$idbc27hdr, @userid=''$username'', @nobc27=''$nobc27'', @tglbc27=''$tglbc27'' ,@nilkurs=$nilkursbc27  ')
			
			END TRY
			BEGIN CATCH 
				SELECT 
				'06' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
			");
		 $rs = $qry->result_array();
		 // $r = $qry->result();		
		 // var_dump($r);die();
		 foreach ($rs as $row){
			 $status = $row['status'];
			 $msg = $row['description'];
		 }  
		 
		 echo json_encode(array('sts' => $status, 'desc' => $msg));
	
		
	
	
	}
	function view_bc27_dtl(){
		$id_bc_out_hdr = (isset($_POST['id_bc_out_hdr']) && !empty($_POST['id_bc_out_hdr']))?$_POST['id_bc_out_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$CAR = (isset($_POST['CAR']) && !empty($_POST['CAR']))?$_POST['CAR']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		$q = $this->db->query("
			SELECT  filename, noprosesdata  from [tblbc27hdr] where noprosesdata=$CAR
		");
		
		$rs = $q->result_array();
		//var_dump($rs); die();
		$filename='';
		foreach ($rs as $row){
			$filename=$row['filename'];		
		}
		
		
		$q = $this->db->query("
			SELECT  id_terkait, doc_out_no, id_data_out_hdr  from [tbl_data_out_hdr] where id_terkait=$id_bc_out_hdr and doc_out_to_id=5
		");
		
		$rs = $q->result_array();
		//var_dump($rs); die();
		$id_data_out_hdr='';
		foreach ($rs as $row){
			$id_data_out_hdr=$row['id_data_out_hdr'];		
		}
		
		
		$q1 = $this->db->query("
			select [id_data_out_hdr]
			  ,[doc_out_no]
			  ,convert(varchar, [doc_out_date], 103) as doc_out_date
			  ,[doc_out_to_id]
			  ,[id_data_out_hdr_h_status]
			  ,[id_terkait]
			  ,convert(varchar, [approve_date], 103) as approve_date
			  FROM[tbl_data_out_hdr]
			  where id_terkait = $id_bc_out_hdr
		");
		
		$rs1 = $q1->result_array();
		//var_dump($rs); die();
		$doc_out_date='';
		$approve_date='';
		foreach ($rs1 as $row1){
			$doc_out_date=$row1['doc_out_date'];		
			$approve_date=$row1['approve_date'];		
		}
		
		$data["doc_out_date"]= $doc_out_date;
		$data["approve_date"]= $approve_date;
		$data["idhdrbc27"]	= $id_data_out_hdr;
		$data['filename']=$filename;
		$data['id_bc_out_hdr']=$id_bc_out_hdr;
	    $data['CAR']=$CAR;
	    $data['loading_indicator'] =  "<div class='loading_indicator'>loading...<br/><img src='./assets/images/loading.gif' alt='loading' /></div>";
		
		$this->load->view('exim/view_bc27_dtl', $data);
	
	}
	
	function loaddatadetil(){
		$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']:'[idpebdtl]'; // get index row - i.e. user click to sort
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		// $gabinvoice = (isset($_POST['gabinvoice']) && !empty($_POST['gabinvoice']))?$_POST['gabinvoice']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		 $idhdrbc27 = (isset($_POST['idhdrbc27']) && !empty($_POST['idhdrbc27']))?$_POST['idhdrbc27']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		 $where = " id_bc_out_hdr=$idhdrbc27 ";
		

		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){
					
					if ( $k->field == "[SERIBRG]" ) {
						$searchString = $k->data;
						$where .= " and [SERIBRG] = $searchString "; 
					} else if ( $k->field == "HS" ) {
						$searchString = $k->data;
						$where .= " and HS like  '%".$searchString."%'"; 
					} else if ( $k->field == "URBRG1" ) {
						$searchString = $k->data;
						$where .= " and URBRG1 like  '%".$searchString."%'"; 
					} else if ( $k->field == "URBRG2" ) {
						$searchString = $k->data;
						$where .= " and URBRG2 like  '%".$searchString."%'"; 
					} else if ( $k->field == "URBRG3" ) {
						$searchString = $k->data;
						$where .= " and URBRG3 like  '%".$searchString."%'"; 
					} else if ( $k->field == "URBRG4" ) {
						$searchString = $k->data;
						$where .= " and URBRG4 like  '%".$searchString."%'"; 
					} else if ( $k->field == "DMERK" ) {
						$searchString = $k->data;
						$where .= " and DMERK like  '%".$searchString."%'"; 
					}  else if ( $k->field == "SIZE" ) {
						$searchString = $k->data;
						$where .= " and SIZE like  '%".$searchString."%'"; 
					}  else if ( $k->field == "TYPE" ) {
						$searchString = $k->data;
						$where .= " and TYPE like  '%".$searchString."%'"; 
					}   else if ( $k->field == "KDBRG" ) {
						$searchString = $k->data;
						$where .= " and KDBRG like  '%".$searchString."%'"; 
					}  else if ( $k->field == "JNSATUAN" ) {
						$searchString = $k->data;
						$where .= " and JNSATUAN like  '%".$searchString."%'"; 
					} 
			
				}
			}
		}	
			
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc27->bc27datadtl_All($limit,$start,$sidx,$sord, $where);
		$count = $this->mdl_bc27->bc27datadtl_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_bc_out_dtl']=$r->id_bc_out_dtl;
			  $responce->rows[$i]['id_bc_out_hdr']=$r->id_bc_out_hdr;
			  $responce->rows[$i]['CAR']=$r->CAR;
			  $responce->rows[$i]['SERIBRG']=$r->SERIBRG;
			  $responce->rows[$i]['HS']=$r->HS;
			  $responce->rows[$i]['URBRG1']=$r->URBRG1;
			  $responce->rows[$i]['URBRG2']=$r->URBRG2;
			  $responce->rows[$i]['URBRG3']=$r->URBRG3;
			  $responce->rows[$i]['URBRG4']=$r->URBRG4;
			  $responce->rows[$i]['DMERK']=$r->DMERK;
			  $responce->rows[$i]['SIZE']=$r->SIZE;
			  $responce->rows[$i]['TYPE']=$r->TYPE;
			  $responce->rows[$i]['KDBRG']=$r->KDBRG;
			  $responce->rows[$i]['KDIZIN']=$r->KDIZIN;
			  $responce->rows[$i]['NOIZIN']=$r->NOIZIN;
			  $responce->rows[$i]['TGIZIN']=$r->TGIZIN;
			  $responce->rows[$i]['JMKOLI']=$r->JMKOLI;
			  $responce->rows[$i]['JNKOLI']=$r->JNKOLI;
			  $responce->rows[$i]['DNilInv']=$r->DNilInv;
			  $responce->rows[$i]['FOBPERBRG']=$r->FOBPERBRG;
			  $responce->rows[$i]['FOBPERSAT']=$r->FOBPERSAT;
			  $responce->rows[$i]['KDPE']=$r->KDPE;
			  $responce->rows[$i]['TARIPPE']=$r->TARIPPE;
			  $responce->rows[$i]['HPATOK']=$r->HPATOK;
			  $responce->rows[$i]['JMSATUAN']=$r->JMSATUAN;
			  $responce->rows[$i]['JNSATUAN']=$r->JNSATUAN;
			  $responce->rows[$i]['NETDET']=$r->NETDET;
			  $responce->rows[$i]['JMSATPE']=$r->JMSATPE;
			  $responce->rows[$i]['JNSATPE']=$r->JNSATPE;
			  $responce->rows[$i]['KDVALPE']=$r->KDVALPE;
			  $responce->rows[$i]['NILVALPE']=$r->NILVALPE;
			  $responce->rows[$i]['PEPERBRG']=$r->PEPERBRG;
			  $responce->rows[$i]['DTLOK']=$r->DTLOK;
			  $responce->rows[$i]['NCV']=$r->NCV;
			  $responce->rows[$i]['DVolume']=$r->DVolume;
			  $responce->rows[$i]['NegAsal']=$r->NegAsal;
			 
		
		$i++;
		}
		echo json_encode($responce);
	
		
	
	}
	
	function loaddatadok(){
		$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']:'[idpebdtl]'; // get index row - i.e. user click to sort
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		// $gabinvoice = (isset($_POST['gabinvoice']) && !empty($_POST['gabinvoice']))?$_POST['gabinvoice']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		 $idhdrbc27 = (isset($_POST['idhdrbc27']) && !empty($_POST['idhdrbc27']))?$_POST['idhdrbc27']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		 $where = " id_bc_out_hdr=$idhdrbc27 ";
		

		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){
					
					if ( $k->field == "[SERIBRG]" ) {
						$searchString = $k->data;
						$where .= " and [SERIBRG] = $searchString "; 
					} else if ( $k->field == "HS" ) {
						$searchString = $k->data;
						$where .= " and HS like  '%".$searchString."%'"; 
					} 
			
				}
			}
		}	
			
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc27->bc27datadok_All($limit,$start,$sidx,$sord, $where);
		$count = $this->mdl_bc27->bc27datadok_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_bc_out_dok']=$r->id_bc_out_dok;
			$responce->rows[$i]['id_bc_out_hdr']=$r->id_bc_out_hdr;
			$responce->rows[$i]['CAR']=$r->CAR;
			$responce->rows[$i]['KdDok']=$r->KdDok;
			$responce->rows[$i]['uraian']=$r->uraian;
			$responce->rows[$i]['NoDok']=$r->NoDok;
			$responce->rows[$i]['TgDok']=$r->TgDok;
			$i++;
		}
		echo json_encode($responce);
	
	}
	
	function printToExcel() {
		if (empty($_POST["cetak_html"])) {
		?>
		<table>
			<tr>
				<td>
										 
					<form action='' method="POST" target="_blank">
						<input name="cetak_html" type="hidden" value="printmeexcel">
						<input type="submit" name="tombol" value="CETAK LAPORAN KE EXCEL">
					</form>
				</td>
			</tr>
		</table>
		<?php
		}
	}
	
	function headerToExcel($filename){
		if (empty($_POST["cetak_html"])) { }
		else if($_POST["cetak_html"]=="printmeexcel") {
			header("Content-type:application/vnd.ms-excel");
			header("Content-disposition:attachment; filename=$filename.xls"); 
			header("Pragma:no-cache");
			header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
			header("Expires:0");
		}
	}
	
	function print_bc27_hdr(){
		$halke = '1';
		$this->load->helper('afunction');
		$id_bc_out_hdr = (isset($_REQUEST['id_bc_out_hdr']) && !empty($_REQUEST['id_bc_out_hdr']))?$_REQUEST['id_bc_out_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		

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

			SELECT [id_bc_out_hdr]
			  ,[CAR]
			  ,[JnEks]
			  ,[KatEks]
			  ,[JNPEB]
			  ,[JNEKSOld]
			  ,[JNLAIN]
			  ,[JNDAG]
			  ,[JNBYR]
			  ,[IDEKS]
			  ,[NPWPEKS]
			  ,[NamaEks]
			  ,[AlmtEks]
			  ,[NoSiup]
			  ,[TgSiup]
			  ,[JnPerus]
			  ,[NoTdp]
			  ,[TgTdp]
			  ,[Niper]
			  ,[StatusH]
			  ,[IdQq]
			  ,[NpwpQq]
			  ,[NamaQq]
			  ,[AlmtQq]
			  ,[NiperQq]
			  ,[NAMABELI]
			  ,[ALMTBELI]
			  ,[NEGBELI]
			  ,[IDPPJK]
			  ,[NPWPPPJK]
			  ,[NamaPpjk]
			  ,[AlmtPpjk]
			  ,[NoPpjk]
			  ,[TgPpjk]
			  ,[MODA]
			  ,[TGEKS]
			  ,[CARRIER]
			  ,[VOY]
			  ,[NOSHIPORD]
			  ,[TGSHIPORD]
			  ,[PELMUAT]
			  ,[PELBONGKAR]
			  ,[PELTRANSIT]
			  ,[NOINV]
			  ,[TGINV]
			  ,[NOLPSE]
			  ,[TGLPSE]
			  ,[PROPBRG]
			  ,[NEGTUJU]
			  ,[FLSIE]
			  ,[FLKARANT]
			  ,[FLSM]
			  ,[FLIZLAIN]
			  ,[DELIVERY]
			  ,[KDVAL]
			  ,[KdHrg]
			  ,[NilInv]
			  ,[FREIGHT]
			  ,[ASURANSI]
			  ,[KdAss]
			  ,[FOB]
			  ,[MERK]
			  ,[JMCONT]
			  ,[BRUTO]
			  ,[NETTO]
			  ,[JMBRG]
			  ,[JMBRGCTH]
			  ,[JMBRGGAB]
			  ,[JMBRGPJT]
			  ,[NODAFT]
			  ,convert(varchar, [TGDAFT], 106) as TGDAFT
			  ,[KDKTR]
			  ,[KTRGATE]
			  ,[NILPE]
			  ,[KDBANK]
			  ,[LOKBANK]
			  ,[NOSSP]
			  ,[TGSSP]
			  ,[JNTPB]
			  ,[LOKTPB]
			  ,[KDLOKBRG]
			  ,[KDKTRMUAT]
			  ,[KDKTRPRIKS]
			  ,[TGSIAP]
			  ,[WKSIAP]
			  ,[ASALDATA]
			  ,[TPNAME]
			  ,[PEBOK]
			  ,[LENGKAP]
			  ,[JNPARTOF]
			  ,[BENDERA]
			  ,[TTDPEB]
			  ,[STATUS]
			  ,[SNRF]
			  ,[NOBCF]
			  ,[TGBCF]
			  ,[SERIBCF]
			  ,[NOMOREDI]
			  ,[KMDT]
			  ,[VOLUME]
			  ,[KDHANGGAR]
			  ,[KONS]
			  ,[JMLKMSPEB]
			  ,[PELMUATEKS]
			  ,[NILKURS]
			  ,[PNBP]
			  ,[NOBC11]
			  ,[TGBC11]
			  ,[POSBC11]
			  ,[SUBPOSBC11]
			  ,[create_date]
			  ,[create_by]
			  ,[update_date]
			  ,[update_by]
			  ,[typedok]
			  ,[statusdok]
			  ,[noinv1]
			  ,[tginv1]
			  ,[inv_hdr_id]
			  ,[bc_in_from_in]
			  ,[nopol]
			  ,(SELECT TOP 1 [tblKpbc].[UrKdKpbc] FROM [tblKpbc] WHERE [tblKpbc].[KdKpbc] = [KDKTR]) AS KantorTujuan 
			  ,(SELECT TOP 1 [Registrasi] FROM [dbo].[tblImportir]) AS Registrasi
			  ,(SELECT SUM ([tbl_bc_out_dtl].DNilInv) FROM [dbo].[tbl_bc_out_dtl] where [tbl_bc_out_dtl].id_bc_out_hdr = [tbl_bc_out_hdr].id_bc_out_hdr) AS NilaiCIF
			  ,((SELECT SUM ([tbl_bc_out_dtl].DNilInv) FROM [dbo].[tbl_bc_out_dtl] where [tbl_bc_out_dtl].id_bc_out_hdr = [tbl_bc_out_hdr].id_bc_out_hdr)*[tbl_bc_out_hdr].NILKURS) as HargaPenyerahan
			  
			  FROM [dbo].[tbl_bc_out_hdr] WHERE 1=1 and typedok='BC27' 
			  and id_bc_out_hdr= $id_bc_out_hdr
		");
		
		
		$rs = $qry->result_array();
		$nodaft = '';
		$kantor_tujuan = '';
			
		$npwpeks = '';;
		$namaeks = '';
		$alamateks= '';
		
		$registrasi = '';
		$nilaiCIF = '';
		$hargaPenyerahan = '';
		$nilaikurs = '';
		$tgdaft = '';
		
		$npwpqq = '';
		$namabeli = '';
		
		$alamatbeli = '';
		$jmlbrg = 0;
		
		foreach($rs as $row){
			$nodaft = $row['NODAFT'];
			$kantor_tujuan = $row['KantorTujuan'];
			
			$npwpeks = $row['NPWPEKS'];
			$namaeks = $row['NamaEks'];
			$alamateks= $row['AlmtEks'];
			
			$registrasi = $row['Registrasi'];
			$nilaiCIF = $row['NilaiCIF'];
			$hargaPenyerahan = $row['HargaPenyerahan'];
			
			$nilaikurs = $row['NILKURS'];
			$tgdaft = $row['TGDAFT'];
			
			$npwpqq = $row['NpwpQq'];
			$namabeli = $row['NAMABELI'];
			
			$alamatbeli=$row['ALMTBELI'];
			$jmlbrg = $row['JMBRG'];
			
		}
		
		
		$qrydokinv = $this->db->query(
			"
				SELECT 
				   [NoDok]
				  ,convert(varchar, [TgDok], 106) as TgDok
			  FROM [dbo].[tbl_bc_out_dok]
			  where [id_bc_out_hdr] = $id_bc_out_hdr and kddok ='380'
			"
		);	
		
		$rsdokinv = $qrydokinv->result_array();
		$noinv = '';
		$tgdok = '';
		foreach ( $rsdokinv as $rowdokinv){
			
			$noinv .=  $rowdokinv['NoDok'] . ' ';
			$tgdok = $rowdokinv['TgDok'];
		}
		
		$qrypenerima = $this->db->query(
			"
				SELECT [id_pembeli]
				  ,[NAMABELI]
				  ,[ALMTBELI]
				  ,[NEGBELI]
				  ,[NOIJIN]
				  ,[NOKONTRAK]
				  ,[TGLIJIN]
			  FROM [tbl_nama_pembeli]
			  WHERE NAMABELI like '$namabeli'
			"
		);	
		
		$noijinpembeli = '';
		$nokontrak = '';
		
		$rspenerima = $qrypenerima->result_array();
		foreach ( $rspenerima as $rpenerima){
			
			$noijinpembeli =  $rpenerima['NOIJIN'] . ' ';
			$nokontrak =  $rpenerima['NOKONTRAK'] . ' ';
			
		}
		
		$datenow = date('Y-m-d');
		echo $this->printToExcel();
		echo $this->headerToExcel("BC27_$nodaft".'_'."$datenow");
		
		?>
		<html>
	<head>
		<style type="text/css">
			@page{/*0.5 0.47 0.5 0.38 0.3 0.3*/
				margin:.5in .47in .5in .38in;
				mso-header-margin:.3in;
				mso-footer-margin:.3in;
				mso-page-orientation:portrait;
				mso-horizontal-page-align:center;
				mso-number-format:\@;
			}
			td{
				/*max-width:900px;*/
				min-width:5px;
				width: auto;
				font-family:"Arial narrow";
				vertical-align: top;
				font-size:18px;
				text-align: left;
				mso-number-format:\@;
			}
			.td_spacing1{
				font-family:"Bookman Old Style";
				font-weight: bold;
				font-size:18px;
				text-align: center;
				vertical-align: top;
				padding:0px 5px 0px 5px;
			}
			
			.td_spacing2{
				font-family:"Bookman Old Style";
				font-weight: bold;
				font-size:18px;
				text-align: center;
				vertical-align: middle;
				padding:0px 5px 0px 5px;
			}
			
			/*mengatur tinggi baris*/
			.tr_spacing40{
				height:40px;
			}
			.tr_spacing50{
				height:50px;
			}
			.tr_spacing60{
				height:60px;
			}
			.tr_spacing100{
				height:100px;
			}
			.tr_spacing120{
				height:120px;
			}
			.tr_spacing160{
				height:160px;
			}
			.tr_spacing190{
				height:190px;
			}
			.tr_spacing80{
				height:80px;
			}
			.tr_spacing30{
				height:30px;
			}
			.tr_spacing20{
				height:20px;
			}
			.tr_spacing10{
				height:10px;
			}
			.tr_spacing5{
				height:10px;
			}
			
			/*mengatur lebar kolom*/
			.column1{
				min-width: 25px;
			}.column2{
				min-width: 50px;
			}.column3{
				width: 1px;
			}.column4{
				min-width: 150px;
			}.column5{
				min-width: 150px;
			}.column6{
				min-width: 40px;
			}.column7{
				min-width: 160px;
			}.column8{
				min-width: 80px;
			}.column9{
				min-width: 80px;
			}.column10{
				min-width: 200px;}
			
			.td_bold{
				font-weight: bold;
			}
			tr{
				height:28px;
			}
			
			table { border-collapse: collapse; }
            tr#border-black { border-top: solid black 1px;border-right: solid black 1px;border-bottom: solid black 1px;border-left: solid black 1px; }
			td#top{
				border-top: solid black 1px;
			}
			td#top-bottom{
				border-top: solid black 1px;border-bottom: solid black 1px;
			}
			td#top-left-right{
				border-top: solid black 1px;border-left: solid black 1px;border-right: solid black 1px;
			}	
			td#top-left-right-bottom{
				border-top: solid black 1px;border-left: solid black 1px;border-right: solid black 1px;border-bottom: solid black 1px;
			}	
			td#top-left{
				border-top: solid black 1px;border-left: solid black 1px;
			}
			td#top-left-bottom{
				border-top: solid black 1px;border-left: solid black 1px;border-bottom: solid black 1px;
			}
			td#top-right-bottom{
				border-top: solid black 1px;border-right: solid black 1px;border-bottom: solid black 1px;
			}
			td#top-right{
				border-top: solid black 1px;border-right: solid black 1px;
			}
			td#right{
				border-right: solid black 1px;
			}
			td#bottom{
				border-bottom: solid black 1px;
			}
			td#bottom-left-right{
				border-bottom: solid black 1px;border-left: solid black 1px;border-right: solid black 1px;
			}
			td#bottom-left{
				border-bottom: solid black 1px;border-left: solid black 1px;
			}
			td#bottom-right{
				border-bottom: solid black 1px;border-right: solid black 1px;
			}
			td#left{
				border-left: solid black 1px;
			}
			td#left-right{
				border-left: solid black 1px;border-right: solid black 1px;
			}
		</style>
	</head>
	<body>
		<table>
			<tr>
				<td rowspan=2 colspan="2" class="td_spacing2" id="top-left-right-bottom">BC.2.7</td>
				<td colspan="8" class="td_spacing1" id="top-left-right">PEMBERITAHUAN PENGELUARAN BARANG UNTUK DIANGKUT DARI TEMPAT</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td colspan="8" class="td_spacing1" id="bottom-left-right">PENIMBUNAN BERIKAT KE TEMPAT PENIMBUNAN BERIKAT LAINNYA</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td colspan="10" class="td_bold" id="top-left-right-bottom">HEADER</td>
				<!--<td>ASD</td>
				<td>SAD</td>
				<td>ASD</td>
				<td>ASD</td>
				<td>ASD</td>
				<td>ASASD</td>
				<td>ASD</td>
				<td>SAD</td>
				<td>ASD</td>-->
			</tr>
			<tr>
				<td id='left'></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td colspan="5" id="right" style="text-align:right;"><?php 
					if($jmlbrg==1){
						
						echo "Halaman 1 dari 1";
					
					} else { echo "Halaman 1 dari 2"; }
				?></td>
				<!--<td>ASASD</td>
				<td>ASD</td>
				<td>SAD</td>
				<td>ASD</td>-->
			</tr>
			<tr>
				<td colspan="2" class="td_bold" id="left">NOMOR PENGAJUAN </td>
				<!--<td></td>-->
				<td colspan="8" class="td_bold" id="right"><?php echo $nodaft ; ?></td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td class="td_bold" id="left">A.</td>
				<td colspan="4" class="td_bold">KANTOR PABEAN </td>
				<!--<td></td>
				<td></td>
				<td></td>-->
				<td class="td_bold">D.</td>
				<td class="td_bold">TUJUAN PENGIRIMAN</td>
				<td colspan="3" id="right">: DI JUAL</td>
				<!--<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td id="left"></td>
				<td>1. Kantor asal</td>
				<td></td>
				<td colspan="2">: KPPBC TANGERANG</td>
				<!--<td></td>-->
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td id="right"></td>
			</tr>
			<tr>
				<td id="left"></td>
				<td>2. Kantor Tujuan</td>
				<td></td>
				<td colspan="2"><?php echo $kantor_tujuan; ?></td>
				<!--<td></td>-->
				<td class="td_bold" id="top-left">G.</td>
				<td colspan="4" class="td_bold" id="top-right">KOLOM KHUSUS BEA DAN CUKAI </td>
				<!--<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td class="td_bold" id="left">B.</td>
				<td class="td_bold">JENIS TPB ASAL</td>
				<td></td>
				<td colspan="2">: KAWASAN BERIKAT</td>
				<!--<td></td>-->
				<td id="left"></td>
				<td>Nomor Pendaftaran</td>
				<td colspan="3" id="right"><?php echo $nodaft; ?></td>
				<!--<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td class="td_bold" id="left">C.</td>
				<td class="td_bold">JENIS TPB TUJUAN</td>
				<td></td>
				<td colspan="2">: KAWASAN BERIKAT</td>
				<!--<td></td>-->
				<td id="left"></td>
				<td>Tanggal</td>
				<td colspan="3" id="right">: <?php echo fnamabulan($tgdaft); ?></td>
				<!--<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td id="left">&nbsp;</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td id="left"></td>
				<td></td>
				<td></td>
				<td></td>
				<td id="right"></td>
			</tr>
			<tr>
				<td colspan="10" id="top-left-right-bottom">E. DATA PEMBERITAHUAN </td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td colspan="5" class="td_bold" id="top-left-right-bottom">TPB ASAL BARANG</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>-->
				<td colspan="5" class="td_bold" id='top-left-right-bottom'>TPB TUJUAN BARANG</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>	
			<tr>
				<td id="left">1.</td>
				<td>NPWP</td>
				<td colspan="3"><?php echo $npwpeks; ?></td>

				<!--<td></td>
				<td></td>-->
				<td>5.</td>
				<td>NPWP</td>
				<td colspan="3"  id="right"><?php echo $npwpeks; ?></td>
				<!--<td></td>
				<td></td>-->
			</tr> 									
	
			<tr>
				<td id="left">2.</td>
				<td>Nama</td>
				<td colspan="3"><?php  echo $this->config->item('namaperusahaan');  //echo $namaeks; ?></td>
				<!--<td></td>
				<td></td>-->
				<td>6.</td>
				<td>Nama</td>

				<td colspan="3" id="right"><?php echo $namabeli; ?>  </td>
				<!--<td></td>
				<td></td>-->
			</tr>
			<tr> 								

				<td id="left">3.</td>
				<td>Alamat</td>
				<td colspan="3"><?php echo $alamateks; ?></td>
				<!--<td></td>
				<td></td>-->
				<td>7.</td>
				<td>Alamat</td>
				<td colspan="3"  id="right"><?php echo $alamatbeli; ?></td>
				<!--<td></td>
				<td></td>-->
			</tr> 		
			<tr>
				<td id="left"></td>
				<td></td>
				<td colspan="3">TANGERANG	</td>
				<!--<td></td>
				<td></td>-->
				<td></td>
				<td></td>

				<td colspan="3" id="right"></td>
				<!--<td></td>
				<td></td>-->
			</tr>
			<tr> 		
				<td id="left">4.</td>
				<td>No. Izin TPB</td>
				<td colspan="3"><?php echo $registrasi; ?></td>
				<!--<td></td>
				<td></td>-->
				<td>8.</td>
				<td>No. Izin TPB</td>
				<td colspan="3" id="right">: 141 / KMK.04 / 2003</td>
				<!--<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td id="bottom-left-right" colspan="10">&nbsp;</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td colspan="10" class="td_bold" id='top-left-right-bottom'>DOKUMEN PELENGKAP PABEAN </td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td id="left">9.</td>
				<td><u>Invoice</u></td>
				<td colspan="2">: <?php echo $noinv ?></td>
				<!--<td></td>-->

				<td>: <?php echo fnamabulan($tgdok) ?></td>
				<td>12.</td>
				<td>Surat Jalan</td>

				<td><?php echo $nodaft ; ?></td>
				<td>Tanggal </td>
				<td id="right">: <?php echo fnamabulan($tgdaft); ?></td>
			</tr>
			<tr>	  
				<td id="left">10.</td>
				<td>Packing List</td>
				<td colspan="2">: <?php echo $noinv ?></td>
				<!--<td></td>-->

				<td>: <?php echo $tgdaft; ?></td>
				<td>13.</td>
				<td colspan="4" id="right">Surat Keputusan/Persetujuan	</td>
				<!--<td></td>-->
				<!--<td></td>
				<td></td>-->
			</tr>
			<tr> 	                  		

				<td id="left">11.</td>
				<td>Kontrak</td>
				<td colspan="3">:  <?php echo $nokontrak; ?></td>
				<!--<td></td>
				<td></td>-->
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td id="right"></td>
			</tr>
			<tr>	 	 

				<td id="left"></td>
				<td></td>
				<td colspan="2">Tgl, 01 Februari 2012</td>
				<!--<td></td>-->
				<td></td>
				<td>14.</td>
				<td>Lainnya</td>
				<td>:</td>
				<td></td>
				<td id="right"></td>
			</tr>
			<tr>
				<td id="left"></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td colspan="3" id="right">.................................................................</td>
				<!--<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td colspan="10" class="td_bold" id="top-left-right-bottom">RIWAYAT BARANG</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>	
				<td id="bottom-left">15.</td>
				<td colspan="9" id="bottom-right">Nomor dan tanggal BC 2.7 Asal :</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td colspan="10" class="td_bold" id="top-left-right-bottom">DATA PERDAGANGAN</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>						 		  	
				<td id="left">16.</td>
				<td>Jenis Valuta Asing</td>
				<td></td>
				<td></td>
				<td>: USD</td>
				<td>18.</td>
				<td>Harga Penyerahan</td>
				<td>RATE :</td>

				<td><?php echo $nilaikurs;  ?></td>
				<td id="right"></td>
			</tr>
			<tr>	
				<td id="bottom-left">17.</td>
				<td id="bottom">CIF</td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom"><?php echo $nilaiCIF;  ?></td>
				<td id="bottom"></td>
				<td id="bottom"><?php echo $hargaPenyerahan; ?></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
			</tr> 
			<tr>		
				<td colspan="5" class="td_bold" id='top-left-bottom'>DATA PENGANGKUTAN</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>-->
				<td id="bottom"></td>
				<td colspan="4" class="td_bold" id="top-right-bottom">SEGEL (DIISI OLEH BEA DAN CUKAI)</td>
				<!--<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr> 								
				<td id="left">19.</td>
				<td colspan="3">Jenis Sarana Pengangkut Darat</td>
				<!--<td></td>
				<td></td>-->
				<td>20. No. Polisi</td>
				<td></td>
				<td colspan="3" id="bottom-left-right">BC ASAL</td>
				<!--<td></td>
				<td></td>-->
				<td id="right">23. Catatan BC</td>
			</tr>
			<tr> 	
				<td id="bottom-left"></td>
				<td id="bottom">TRUCK</td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom-left-right">21. No Segel </td>
				<td colspan="2" id="bottom-left-right">22. Jenis</td>
				<!--<td></td>-->
				<td id="bottom-left-right">Tujuan</td>
			</tr>
			<tr>
				<td colspan="6" class="td_bold" id="bottom-left">DATA PETI KEMAS DAN PENGEMAS</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
				<td id="left"></td>
				<td id="left"></td>
				<td id="right"></td>
				<td id="right"></td>
			</tr>
			<tr>	
				<td id="left">24.</td>
				<td colspan="3">Merek dan No Kemasan/Peti Kemas</td>
				<!--<td></td>
				<td></td>-->
				<td>25. Jumlah dan Jenis Kemasan</td>
				<td></td>
				<td id="left">: <?php echo $nodaft; ?></td>
				<td id="left">KERTAS</td>
				<td id="right"></td>
				<td id="right"></td>
			</tr>
			<tr>

				<td id="left"></td>
				<td colspan="2">dan Jumlah Peti Kemas</td>
				<!--<td></td>-->
				<td></td>
				<td><u>54.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u>&nbsp;CT</td>
				<td></td>
				<td id="left"></td>
				<td id="left"></td>
				<td id="right"></td>
				<td id="right"></td>
			</tr>
			<tr>
				<td id="left">&nbsp;</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td id="left"></td>
				<td id="left"></td>
				<td id="right"></td>
				<td id="right"></td>
			</tr>
			<tr class="tr_spacing190">
				<td colspan="10" class="td_bold" id="top-left-right-bottom" style="vertical-align:bottom;">DATA BARANG</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>		
				<td id="left">26.</td>
				<td colspan="2">Volume (m3): ............</td>
				<!--<td></td>-->
				<td></td>
				<td>27.Berat Kotor (Kg):</td>
				<td></td>
				<td style="text-align:right;">16</td>
				<td colspan="2">28. Berat Bersih (kg) :</td>
				<!--<td></td>-->
				
				<td id="right"></td>
			</tr>				 					

			<tr>
				<td id="bottom-left"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom">[Harap diisi] </td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom-right">[Harap diisi]</td>
			</tr>
			<tr>	
				<td id="left-right">29.</td>
				<td>30.</td>
				<td></td>
				<td></td>
				<td id="right"></td>
				<td>31.</td>
				<td></td>
				<td id="right"></td>
				<td>32.</td>
				<td id="right"></td>
			</tr>
			<tr>	 
				<td id="left-right">No</td>
				<td colspan="4">Pos Tarif/HS, uraian jumlah dan jenis barang secara lengkap, kode</td>
				<!--<td></td>
				<td></td>
				<td></td>-->
				<td colspan="2" id="left">- Jumlah dan Jenis Satuan</td>
				<!--<td></td>-->
				<td id="right"></td>
				<td>- Nilai CIF :</td>
				<td id="right"></td>
			</tr>    								
					

			<tr>
				<td id="left-right"></td>
				<td colspan="3">barang merk, tipe, ukuran dan spesifikasi lain</td>
				<!--<td></td>
				<td></td>-->
				<td></td>
				<td colspan="2" id="left">- Berat Bersih (Kg)</td>
				<!--<td></td>-->
				<td></td>
				<td colspan="2" id="left-right">- Harga Penyerahan</td>
				<!--<td></td>-->
			</tr>
			<tr>
				<td id="left-right"></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td colspan="2" id="bottom-left">- Volume (m3)</td>
				<!--<td></td>-->
				<td id="bottom"></td>
				<td id="bottom-left">USD</td>
				<td id="bottom-right"></td>
			</tr>
			<tr>
				<td id="top-left-right-bottom"></td>
				<td id="top-bottom"></td>
				<td id="top-bottom"></td>
				<td colspan="2"  id="top-right-bottom">TERLAMPIR ( LIHAT LEMBAR LANJUTAN )</td>
				<!--<td></td>-->
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
			</tr>
			<tr>
				<td id="top-left-right-bottom">&nbsp;</td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
			</tr>
			<tr>
				<td id="top-left-right-bottom">&nbsp;</td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
			</tr>
			<tr>			
				<td id="bottom-left">F.</td>
				<td colspan="4" class="td_bold" id="bottom">TANDA TANGAN PENGUSAHA TPB</td>
				<!--<td></td>
				<td></td>
				<td></td>-->
				<td colspan="3" class="td_bold"id="bottom">H. UNTUK PEJABAT BEA DAN CUKAI</td>
				<!--<td></td>
				<td></td>-->
				<td id="bottom"></td>
				<td id="bottom-right"></td>
			</tr>
			<tr>
				<td colspan="5" id="left">Dengan ini saya menyatakan bertanggung jawab atas kebenaran hal - hal yang</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>-->
				<td colspan="3"id="left">Kantor Pabean Asal</td>
				<!--<td></td>
				<td></td>-->
				<td colspan="2"id="left-right">Kantor Pabean Tujuan </td>
				<!--<td></td>-->
			</tr>
			<tr>
				<td colspan="5"  id="left">diberitahukan dalam pemberitahuan pabean ini.	</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>-->
				<td id="left"></td>
				<td></td>
				<td id="right"></td>
				<td></td>
				<td id="right"></td>
			</tr>
			<tr>
				<td id="left"></td>
				<td colspan="4">.....................Tangerang.....................Tgl <?php echo $tgdaft; ?></td>
				<!--<td></td>
				<td></td>
				<td></td>-->
				<td id="left">Nama</td>
				<td colspan='2'>:..........................</td>
				<!--<td></td>-->
				<td id="left">Nama</td>
				<td id="right">:..........................</td>
			</tr>
			<tr>
				<td id="left"></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td id="left">NIP</td>
				<td colspan="2"  id="right">:..........................</td>
				<!--<td></td>-->
				<td>NIP</td>
				<td id="right">:..........................</td>
			</tr>
			<tr class="tr_spacing120">
				<td id="bottom-left"></td>
				<td colspan="4" class="td_bold" id="bottom-right" style="vertical-align:bottom;text-align:center;">( MUJIH )</td>
				<!--<td></td>
				<td></td>
				<td></td>-->
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
			</tr>
			<tr>
				<td class="column1"></td>
				<td class="column2"></td>
				<td class="column3"></td>
				<td class="column4"></td>
				<td class="column5"></td>
				<td class="column6"></td>
				<td class="column7"></td>
				<td class="column8"></td>
				<td class="column9"></td>
				<td class="column10"></td>
			</tr>
			
		</table> 
	</body>
</html>
		<?php
	}
	
	function print_bc27_dtl(){
		
		$id_bc_out_hdr = (isset($_REQUEST['id_bc_out_hdr']) && !empty($_REQUEST['id_bc_out_hdr']))?$_REQUEST['id_bc_out_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		$qry = $this->db->query("

		SELECT [id_bc_out_hdr]
      ,[CAR]
      ,[JnEks]
      ,[KatEks]
      ,[JNPEB]
      ,[JNEKSOld]
      ,[JNLAIN]
      ,[JNDAG]
      ,[JNBYR]
      ,[IDEKS]
      ,[NPWPEKS]
      ,[NamaEks]
      ,[AlmtEks]
      ,[NoSiup]
      ,[TgSiup]
      ,[JnPerus]
      ,[NoTdp]
      ,[TgTdp]
      ,[Niper]
      ,[StatusH]
      ,[IdQq]
      ,[NpwpQq]
      ,[NamaQq]
      ,[AlmtQq]
      ,[NiperQq]
      ,[NAMABELI]
      ,[ALMTBELI]
      ,[NEGBELI]
      ,[IDPPJK]
      ,[NPWPPPJK]
      ,[NamaPpjk]
      ,[AlmtPpjk]
      ,[NoPpjk]
      ,[TgPpjk]
      ,[MODA]
      ,[TGEKS]
      ,[CARRIER]
      ,[VOY]
      ,[NOSHIPORD]
      ,[TGSHIPORD]
      ,[PELMUAT]
      ,[PELBONGKAR]
      ,[PELTRANSIT]
      ,[NOINV]
      ,[TGINV]
      ,[NOLPSE]
      ,[TGLPSE]
      ,[PROPBRG]
      ,[NEGTUJU]
      ,[FLSIE]
      ,[FLKARANT]
      ,[FLSM]
      ,[FLIZLAIN]
      ,[DELIVERY]
      ,[KDVAL]
      ,[KdHrg]
      ,[NilInv]
      ,[FREIGHT]
      ,[ASURANSI]
      ,[KdAss]
      ,[FOB]
      ,[MERK]
      ,[JMCONT]
      ,[BRUTO]
      ,[NETTO]
      ,[JMBRG]
      ,[JMBRGCTH]
      ,[JMBRGGAB]
      ,[JMBRGPJT]
      ,[NODAFT]
      ,convert(varchar,[TGDAFT], 106) as TGDAFT
      ,[KDKTR]
      ,[KTRGATE]
      ,[NILPE]
      ,[KDBANK]
      ,[LOKBANK]
      ,[NOSSP]
      ,[TGSSP]
      ,[JNTPB]
      ,[LOKTPB]
      ,[KDLOKBRG]
      ,[KDKTRMUAT]
      ,[KDKTRPRIKS]
      ,[TGSIAP]
      ,[WKSIAP]
      ,[ASALDATA]
      ,[TPNAME]
      ,[PEBOK]
      ,[LENGKAP]
      ,[JNPARTOF]
      ,[BENDERA]
      ,[TTDPEB]
      ,[STATUS]
      ,[SNRF]
      ,[NOBCF]
      ,[TGBCF]
      ,[SERIBCF]
      ,[NOMOREDI]
      ,[KMDT]
      ,[VOLUME]
      ,[KDHANGGAR]
      ,[KONS]
      ,[JMLKMSPEB]
      ,[PELMUATEKS]
      ,[NILKURS]
      ,[PNBP]
      ,[NOBC11]
      ,[TGBC11]
      ,[POSBC11]
      ,[SUBPOSBC11]
      ,[create_date]
      ,[create_by]
      ,[update_date]
      ,[update_by]
      ,[typedok]
      ,[statusdok]
      ,[noinv1]
      ,[tginv1]
      ,[inv_hdr_id]
      ,[bc_in_from_in]
      ,[nopol]
	  ,(SELECT TOP 1 [tblKpbc].[UrKdKpbc] FROM [tblKpbc] WHERE [tblKpbc].[KdKpbc] = [KDKTR]) AS KantorTujuan 
	  ,(SELECT TOP 1 [Registrasi] FROM [dbo].[tblImportir]) AS Registrasi
	  ,(SELECT SUM ([tbl_bc_out_dtl].DNilInv) FROM [dbo].[tbl_bc_out_dtl] where [tbl_bc_out_dtl].id_bc_out_hdr = [tbl_bc_out_hdr].id_bc_out_hdr) AS NilaiCIF
	  ,((SELECT SUM ([tbl_bc_out_dtl].DNilInv) FROM [dbo].[tbl_bc_out_dtl] where [tbl_bc_out_dtl].id_bc_out_hdr = [tbl_bc_out_hdr].id_bc_out_hdr)*[tbl_bc_out_hdr].NILKURS) as HargaPenyerahan
	  
  FROM [dbo].[tbl_bc_out_hdr] WHERE 1=1 and typedok='BC27' 
  and id_bc_out_hdr= $id_bc_out_hdr
		");
		
		
		$rs = $qry->result_array();
		$nodaft = '';
		$kantor_tujuan = '';
			
		$npwpeks = '';;
		$namaeks = '';
		$alamateks= '';
		
		$registrasi = '';
		$nilaiCIF = '';
		$hargaPenyerahan = '';
		$npwpqq = '';
		$tgdaft = '';
		
		foreach($rs as $row){
			$nodaft = $row['NODAFT'];
			$kantor_tujuan = $row['KantorTujuan'];
			
			$npwpeks = $row['NPWPEKS'];
			$namaeks = $row['NamaEks'];
			$alamateks= $row['AlmtEks'];
			
			$registrasi = $row['Registrasi'];
			$nilaiCIF = $row['NilaiCIF'];
			$hargaPenyerahan = $row['HargaPenyerahan'];
			$npwpqq = $row['NpwpQq'];
			$namabeli = $row['NAMABELI'];
			$tgdaft = $row['TGDAFT'];
			
		}
		
		$rs= $this->db->query("
		SELECT [id_bc_out_dtl]
	      ,[id_bc_out_hdr] ,[HS]
	      ,[URBRG1]
	      ,[JMSATUAN]
	      ,[JNSATUAN]
		  ,[DNilInv]
  		FROM [dbo].[tbl_bc_out_dtl] where id_bc_out_hdr = $id_bc_out_hdr
		");
		
		$hs = array();
		$urbrg1 = array();
		$jmsatuan = array();
		$jnsatuan = array();
		$dnil = array();
		$qrydetail = $rs->result_array();
		foreach($qrydetail as $row){
			$hs = $row['HS'];
			$urbrg1 = $row['URBRG1'];
			$jmsatuan = $row['JMSATUAN'];
			$jnsatuan = $row['JNSATUAN'];
			$dnil = $row['DNilInv'];
		}
		
		$num_rows = $rs->num_rows();
		
		$datenow = date('Y-m-d');
		echo $this->printToExcel();
		echo $this->headerToExcel("BC27_$nodaft".'_DETAIL_'."$datenow");
		
		
		
		?>
		<html>
	<head>
		<style>
			@page{/*0.17 0.45 0.16 0.45 0.17 0.16*/

				margin:.5in .47in .5in .38in;
				mso-header-margin:.17in;
				mso-footer-margin:.16in;
				mso-page-orientation:portrait;
				mso-horizontal-page-align:center;
				mso-number-format:\@;
			}
			td{
				/*max-width:900px;*/
				min-width:5px;
				width: auto;
				font-family:"Arial narrow";
				vertical-align: top;
				font-size:18px;
				text-align: left;
				mso-number-format:\@;
			}
			.td_spacing1{
				font-family:"Bookman Old Style";
				font-weight: bold;
				font-size:18px;
				text-align: center;
				vertical-align: top;
				padding:0px 5px 0px 5px;
			}
			.td_spacing2{
				font-family:"Bookman Old Style";
				font-weight: bold;
				font-size:18px;
				text-align: center;
				vertical-align: middle;
				padding:0px 5px 0px 5px;
			}
			/*mengatur tinggi baris*/
			.tr_spacing40{
				height:40px;
			}
			.tr_spacing50{
				height:50px;
			}
			.tr_spacing60{
				height:60px;
			}
			.tr_spacing100{
				height:100px;
			}
			.tr_spacing120{
				height:120px;
			}
			.tr_spacing160{
				height:160px;
			}
			.tr_spacing190{
				height:190px;
			}
			.tr_spacing80{
				height:80px;
			}
			.tr_spacing30{
				height:30px;
			}
			.tr_spacing20{
				height:20px;
			}
			.tr_spacing10{
				height:10px;
			}
			.tr_spacing5{
				height:10px;
			}
			
			/*mengatur lebar kolom*/
			.column1{
				min-width: 25px;
			}.column2{
				min-width: 50px;
			}.column3{
				width: 10px;
			}.column4{
				min-width: 150px;
			}.column5{
				min-width: 200px;
			}.column6{
				min-width: 40px;
			}.column7{
				min-width: 160px;
			}.column8{
				min-width: 80px;
			}.column9{
				min-width: 80px;
			}.column10{
				min-width: 200px;}
			
			.td_bold{
				font-weight: bold;
			}
			tr{
				height:28px;
			}
			
			table { border-collapse: collapse; }
            tr#border-black { border-top: solid black 1px;border-right: solid black 1px;border-bottom: solid black 1px;border-left: solid black 1px; }
			td#top{
				border-top: solid black 1px;
			}
			td#top-bottom{
				border-top: solid black 1px;border-bottom: solid black 1px;
			}
			td#top-left-right{
				border-top: solid black 1px;border-left: solid black 1px;border-right: solid black 1px;
			}	
			td#top-left-right-bottom{
				border-top: solid black 1px;border-left: solid black 1px;border-right: solid black 1px;border-bottom: solid black 1px;
			}	
			td#top-left{
				border-top: solid black 1px;border-left: solid black 1px;
			}
			td#top-left-bottom{
				border-top: solid black 1px;border-left: solid black 1px;border-bottom: solid black 1px;
			}
			td#top-right-bottom{
				border-top: solid black 1px;border-right: solid black 1px;border-bottom: solid black 1px;
			}
			td#top-right{
				border-top: solid black 1px;border-right: solid black 1px;
			}
			td#right{
				border-right: solid black 1px;
			}
			td#bottom{
				border-bottom: solid black 1px;
			}
			td#bottom-left-right{
				border-bottom: solid black 1px;border-left: solid black 1px;border-right: solid black 1px;
			}
			td#bottom-left{
				border-bottom: solid black 1px;border-left: solid black 1px;
			}
			td#bottom-right{
				border-bottom: solid black 1px;border-right: solid black 1px;
			}
			td#left{
				border-left: solid black 1px;
			}
			td#left-right{
				border-left: solid black 1px;border-right: solid black 1px;
			}
		</style>
	</head>
	<body>
		<table>
			<tr>
				<td rowspan=2 colspan="2" class="td_spacing2" id="top-left-right-bottom">BC.2.7</td>
				<td colspan="8" class="td_spacing1" id="top-left-right">LEMBAR LANJUTAN</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td colspan="8" class="td_spacing1" id="bottom-left-right">DATA BARANG</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td colspan="10" class="td_bold" id="top-left-right-bottom">HEADER</td>
				<!--<td>ASD</td>
				<td>SAD</td>
				<td>ASD</td>
				<td>ASD</td>
				<td>ASD</td>
				<td>ASASD</td>
				<td>ASD</td>
				<td>SAD</td>
				<td>ASD</td>-->
			</tr>
			<tr>
				<td id='left'></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td colspan="5" id="right" style="text-align:right;">Halaman 2 .....dari 2..........</td>
				<!--<td>ASASD</td>
				<td>ASD</td>
				<td>SAD</td>
				<td>ASD</td>-->
			</tr>
			<!-- baris 5 -->
			<tr>
				<td colspan="2" class="td_bold" id="left">NOMOR PENGAJUAN </td>
				<!--<td></td>-->
				<td colspan="8" class="td_bold" id="right"><?php echo $nodaft; ?></td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<!-- baris 6 -->
			<tr>
				<td class="td_bold" id="left">A.</td>
				<td colspan="4" class="td_bold">KANTOR PABEAN </td>
				<!--<td></td>
				<td></td>
				<td></td>-->
				<td class="td_bold">D.</td>
				<td class="td_bold">TUJUAN PENGIRIMAN</td>
				<td colspan="3" id="right">: DI JUAL</td>
				<!--<td></td>
				<td></td>-->
			</tr>
			<!-- baris 7 -->
			<tr>
				<td id="left"></td>
				<td>1. Kantor asal</td>
				<td></td>
				<td colspan="2">: KPPBC TANGERANG</td>
				<!--<td></td>-->
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td id="right"></td>
			</tr>
			<!-- baris 8 -->
			<tr>
				<td id="left"></td>
				<td>2. Kantor Tujuan</td>
				<td></td>
				<td colspan="2">: KPPBC TANJUNG EMAS</td>
				<!--<td></td>-->
				<td class="td_bold" id="top-left">G.</td>
				<td colspan="4" class="td_bold" id="top-right">KOLOM KHUSUS BEA DAN CUKAI </td>
				<!--<td></td>
				<td></td>
				<td></td>-->
			</tr>
			<!-- baris 9 -->
			<tr>
				<td class="td_bold" id="left">B.</td>
				<td class="td_bold">JENIS TPB ASAL</td>
				<td></td>
				<td colspan="2">: KAWASAN BERIKAT</td>
				<!--<td></td>-->
				<td id="left"></td>
				<td>Nomor Pendaftaran</td>
				<td colspan="3" id="right"><?php echo $nodaft; ?></td>
				<!--<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td class="td_bold" id="left">C.</td>
				<td class="td_bold">JENIS TPB TUJUAN</td>
				<td></td>
				<td colspan="2">: KAWASAN BERIKAT</td>
				<!--<td></td>-->
				<td id="left"></td>
				<td>Tanggal</td>
				<td colspan="3" id="right">: <?php echo $tgdaft; ?></td>
				<!--<td></td>
				<td></td>-->
			</tr>
			<tr>
				<td id="left">&nbsp;</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td id="left"></td>
				<td></td>
				<td></td>
				<td></td>
				<td id="right"></td>
			</tr>
			<tr>	
				<td id="top-left-right">29.</td>
				<td id="top">30.</td>
				<td id="top"></td>
				<td id="top"></td>
				<td id="top-right"></td>
				<td id="top">31.</td>
				<td id="top"></td>
				<td id="top-right"></td>
				<td id="top">32.</td>
				<td id="top-right"></td>
			</tr>
			<tr>	 
				<td id="left-right">No</td>
				<td colspan="4">Pos Tarif/HS, uraian jumlah dan jenis barang secara lengkap, kode</td>
				<!--<td></td>
				<td></td>
				<td></td>-->
				<td colspan="2" id="left">- Jumlah dan Jenis Satuan</td>
				<!--<td></td>-->
				<td id="right"></td>
				<td>- Nilai CIF :</td>
				<td id="right"></td>
			</tr>   
			<tr>
				<td id="left-right"></td>
				<td colspan="3">barang merk, tipe, ukuran dan spesifikasi lain</td>
				<!--<td></td>
				<td></td>-->
				<td></td>
				<td colspan="2" id="left">- Berat Bersih (Kg)</td>
				<!--<td></td>-->
				<td></td>
				<td colspan="2" id="left-right"></td>
				<!--<td></td>-->
			</tr>
			<tr>
				<td id="bottom-left-right"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td colspan="2" id="bottom-left">- Volume (m3)</td>
				<!--<td></td>-->
				<td id="bottom"></td>
				<td id="bottom-left"></td>
				<td id="bottom-right"></td>
			</tr>
			<tr>	
				<td id="top-left-right"></td>
				<td id="top"></td>
				<td id="top"></td>
				<td colspan="2" id="top-right">AUTOMOTIVE WIRING HARNESS</td>
				<!--<td id="top"></td>-->
				<td id="top"></td>
				<td id="top"></td>
				<td id="top-right"></td>
				<td id="top"></td>
				<td id="top-right"></td>
			</tr>
			<tr>	 
				<td id="left-right"></td>
				<td></td>
				<td></td>
				<td colspan="2" id="right">ASSY NUMBER :</td>
				<!--<td></td>-->
				<td></td>
				<td></td>
				<td id="right"></td>
				<td></td>
				<td id="right"></td>
			</tr>
			<!--LAKUKAN LOOPING-->
			<?php
			
			$tot_jmsatuan = 0;
			$tot_dnil = 0;
			
			$total_no = $num_rows;
			foreach($qrydetail as $idx=>$row){
				?>
				<tr>	 
					<td id="left-right"><?php echo $idx+1; ?></td>
					<td colspan="2"><?php echo $row['HS']; ?></td>
					<!--<td></td>-->
					<td colspan="2" id="right"><?php echo $row['URBRG1'] ?></td>
					<!--<td></td>-->
					<td></td>
					<td style="text-align:right;"><?php echo $row['JMSATUAN']; $tot_jmsatuan +=$row['JMSATUAN']; ?></td>
					<td id="right">&nbsp; <?php echo $row['JNSATUAN']; $tot_dnil += $row['DNilInv']; ?></td>
					<td></td>
					<td style="text-align:right" id="right"><?php echo $row['DNilInv']; ?></td>
				</tr>
				<?php
			}
			
			?>
			<tr>
				<td id="left-right"></td>
				<td colspan="2"></td>
				<!--<td></td>-->
				<td colspan="2" id="right"></td>
				<!--<td></td>-->
				<td style="font-weight:bold;">TOTAL</td>
				<td style="text-align:right;font-weight:bold;"><?php echo $tot_jmsatuan; ?></td>
				<td id="right" style="font-weight:bold;">&nbsp;<?PHP echo 'SET'; ?></td>
				<td></td>
				<td style="text-align:right;font-weight:bold;" id="right"><?php
				if(!isset($tot_dnil)){
					$tot_dnil = 0;
				}
				else{
					$tot_dnil = $tot_dnil;
				}
				echo $tot_dnil; ?></td>
			</tr>
			
			<?php
			$maxrow = 25;
			$rowbottom = $maxrow - $total_no;
			
			// Bila no yang dimasukkan > 25 baris bagaimana ?
			$i = 1;
			for($i=1;$i<$rowbottom;$i++){
				?>
				<tr>	 
					<td id="left-right"></td>
					<td colspan="2"></td>
					<!--<td></td>-->
					<td colspan="2" id="right"></td>
					<!--<td></td>-->
					<td></td>
					<td></td>
					<td id="right"></td>
					<td></td>
					<td id="right"></td>
				</tr>
				<?php
			}
			?>
			<!--END LOOPING-->
			<tr>			
				<td id="top-left-bottom">F.</td>
				<td colspan="4" class="td_bold" id="top-bottom">TANDA TANGAN PENGUSAHA TPB</td>
				<!--<td></td>
				<td></td>
				<td></td>-->
				<td colspan="3" class="td_bold"id="top-bottom">H. UNTUK PEJABAT BEA DAN CUKAI</td>
				<!--<td></td>
				<td></td>-->
				<td id="top-bottom"></td>
				<td id="top-right-bottom"></td>
			</tr>
			<tr>
				<td colspan="5" id="left">Dengan ini saya menyatakan bertanggung jawab atas kebenaran hal - hal yang</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>-->
				<td colspan="3"id="left">Kantor Pabean Asal</td>
				<!--<td></td>
				<td></td>-->
				<td colspan="2"id="left-right">Kantor Pabean Tujuan </td>
				<!--<td></td>-->
			</tr>
			<tr>
				<td colspan="5"  id="left">diberitahukan dalam pemberitahuan pabean ini.	</td>
				<!--<td></td>
				<td></td>
				<td></td>
				<td></td>-->
				<td id="left"></td>
				<td></td>
				<td id="right"></td>
				<td></td>
				<td id="right"></td>
			</tr>
			<tr>
				<td id="left"></td>
				<td colspan="4">.....................Tangerang.....................Tgl <?php echo  date('d-M-y') ?></td>
				<!--<td></td>
				<td></td>
				<td></td>-->
				<td id="left">Nama</td>
				<td colspan='2'>:..........................</td>
				<!--<td></td>-->
				<td id="left">Nama</td>
				<td id="right">:..........................</td>
			</tr>
			<tr>
				<td id="left"></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td id="left">NIP</td>
				<td colspan="2"  id="right">:..........................</td>
				<!--<td></td>-->
				<td>NIP</td>
				<td id="right">:..........................</td>
			</tr>
			<tr class="tr_spacing120">
				<td id="bottom-left"></td>
				<td colspan="4" class="td_bold" id="bottom-right" style="vertical-align:bottom;text-align:center;">( MUJIH )</td>
				<!--<td></td>
				<td></td>
				<td></td>-->
				<td id="bottom"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
				<td id="bottom"></td>
				<td id="bottom-right"></td>
			</tr>
			<tr>
				<td class="column1"></td>
				<td class="column2"></td>
				<td class="column3"></td>
				<td class="column4"></td>
				<td class="column5"></td>
				<td class="column6"></td>
				<td class="column7"></td>
				<td class="column8"></td>
				<td class="column9"></td>
				<td class="column10"></td>
			</tr>
		</table>
	</body>
</html>
		<?php
	}
	
	function prosesdatatofg(){
		$id_bc_out = (isset($_POST['id_bc_out']) && !empty($_POST['id_bc_out']))?$_POST['id_bc_out']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$typedok = (isset($_POST['typedok']) && !empty($_POST['typedok']))?$_POST['typedok']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		$username = $this->session->userdata('DX_username');
      
		$qry = $this->db->query("
			BEGIN TRY
			
			 exec('[spi_prosesdatatofg] @id_bc_out=$id_bc_out, @typedok=''$typedok'', @username=''$username'' ')
			
			END TRY
			BEGIN CATCH 
				SELECT 
				'06' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
			");
		 $rs = $qry->result_array();
		 // $r = $qry->result();		
		 // var_dump($r);die();
		 foreach ($rs as $row){
			 $status = $row['status'];
			 $msg = $row['description'];
		 }  
		//  echo json_encode($responce);
		 // $stmt = " exec('[spi_prosesdatatofg]') ";
		 // $qry = mssql_query($stmt); 
		 // $row = mssql_fetch_array($qry); 
		 // var_dump($row);die();
		
		
		$q = $this->db->query("
			SELECT  id_terkait, doc_out_no, id_data_out_hdr  from [tbl_data_out_hdr] where id_terkait=$id_bc_out and doc_out_to_id=5
		");
		
		$rs = $q->result_array();
		//var_dump($rs); die();
		$id_data_out_hdr='';
		foreach ($rs as $row){
			$id_data_out_hdr=$row['id_data_out_hdr'];		
		}
		
		
		$status = $status;
		$msg = $msg;
		
		echo json_encode(array('sts' => $status, 'desc' => $msg, 'id_data_out_hdr' =>$id_data_out_hdr ));
	
	}
	
	function savetoexcelbc27(){
		$id_bc_out_hdr = (isset($_REQUEST['id_bc_out_hdr']) && !empty($_REQUEST['id_bc_out_hdr']))?$_REQUEST['id_bc_out_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$datenow = date('Y-m-d');
		$filename =  "BC27_".$id_bc_out_hdr."_$datenow";
		
		$qry = $this->db->query("

			SELECT [id_bc_out_hdr]
			  ,[CAR]
			  ,[JnEks]
			  ,[KatEks]
			  ,[JNPEB]
			  ,[JNEKSOld]
			  ,[JNLAIN]
			  ,[JNDAG]
			  ,[JNBYR]
			  ,[IDEKS]
			  ,[NPWPEKS]
			  ,[NamaEks]
			  ,[AlmtEks]
			  ,[NoSiup]
			  ,[TgSiup]
			  ,[JnPerus]
			  ,[NoTdp]
			  ,[TgTdp]
			  ,[Niper]
			  ,[StatusH]
			  ,[IdQq]
			  ,[NpwpQq]
			  ,[NamaQq]
			  ,[AlmtQq]
			  ,[NiperQq]
			  ,[NAMABELI]
			  ,[ALMTBELI]
			  ,[NEGBELI]
			  ,[IDPPJK]
			  ,[NPWPPPJK]
			  ,[NamaPpjk]
			  ,[AlmtPpjk]
			  ,[NoPpjk]
			  ,[TgPpjk]
			  ,[MODA]
			  ,[TGEKS]
			  ,[CARRIER]
			  ,[VOY]
			  ,[NOSHIPORD]
			  ,[TGSHIPORD]
			  ,[PELMUAT]
			  ,[PELBONGKAR]
			  ,[PELTRANSIT]
			  ,[NOINV]
			  ,[TGINV]
			  ,[NOLPSE]
			  ,[TGLPSE]
			  ,[PROPBRG]
			  ,[NEGTUJU]
			  ,[FLSIE]
			  ,[FLKARANT]
			  ,[FLSM]
			  ,[FLIZLAIN]
			  ,[DELIVERY]
			  ,[KDVAL]
			  ,[KdHrg]
			  ,[NilInv]
			  ,[FREIGHT]
			  ,[ASURANSI]
			  ,[KdAss]
			  ,[FOB]
			  ,[MERK]
			  ,[JMCONT]
			  ,[BRUTO]
			  ,[NETTO]
			  ,[JMBRG]
			  ,[JMBRGCTH]
			  ,[JMBRGGAB]
			  ,[JMBRGPJT]
			  ,[NODAFT]
			  ,convert(varchar, [TGDAFT], 106) as TGDAFT
			  ,[KDKTR]
			  ,[KTRGATE]
			  ,[NILPE]
			  ,[KDBANK]
			  ,[LOKBANK]
			  ,[NOSSP]
			  ,[TGSSP]
			  ,[JNTPB]
			  ,[LOKTPB]
			  ,[KDLOKBRG]
			  ,[KDKTRMUAT]
			  ,[KDKTRPRIKS]
			  ,[TGSIAP]
			  ,[WKSIAP]
			  ,[ASALDATA]
			  ,[TPNAME]
			  ,[PEBOK]
			  ,[LENGKAP]
			  ,[JNPARTOF]
			  ,[BENDERA]
			  ,[TTDPEB]
			  ,[STATUS]
			  ,[SNRF]
			  ,[NOBCF]
			  ,[TGBCF]
			  ,[SERIBCF]
			  ,[NOMOREDI]
			  ,[KMDT]
			  ,[VOLUME]
			  ,[KDHANGGAR]
			  ,[KONS]
			  ,[JMLKMSPEB]
			  ,[PELMUATEKS]
			  ,[NILKURS]
			  ,[PNBP]
			  ,[NOBC11]
			  ,[TGBC11]
			  ,[POSBC11]
			  ,[SUBPOSBC11]
			  ,[create_date]
			  ,[create_by]
			  ,[update_date]
			  ,[update_by]
			  ,[typedok]
			  ,[statusdok]
			  ,[noinv1]
			  ,[tginv1]
			  ,[inv_hdr_id]
			  ,[bc_in_from_in]
			  ,[nopol]
			  ,(SELECT TOP 1 [tblKpbc].[UrKdKpbc] FROM [tblKpbc] WHERE [tblKpbc].[KdKpbc] = [KDKTR]) AS KantorTujuan 
			  ,(SELECT TOP 1 [Registrasi] FROM [dbo].[tblImportir]) AS Registrasi
			  ,(SELECT SUM ([tbl_bc_out_dtl].DNilInv) FROM [dbo].[tbl_bc_out_dtl] where [tbl_bc_out_dtl].id_bc_out_hdr = [tbl_bc_out_hdr].id_bc_out_hdr) AS NilaiCIF
			  ,((SELECT SUM ([tbl_bc_out_dtl].DNilInv) FROM [dbo].[tbl_bc_out_dtl] where [tbl_bc_out_dtl].id_bc_out_hdr = [tbl_bc_out_hdr].id_bc_out_hdr)*[tbl_bc_out_hdr].NILKURS) as HargaPenyerahan
			  
			  FROM [dbo].[tbl_bc_out_hdr] WHERE 1=1 and typedok='BC27' 
			  and id_bc_out_hdr= $id_bc_out_hdr
		");
		
				
		$rs = $qry->result_array();
		$nodaft = '';
		$kantor_tujuan = '';
			
		$npwpeks = '';;
		$namaeks = '';
		$alamateks= '';
		
		$kdval = '';
		$registrasi = '';
		$nilaiCIF = '';
		$hargaPenyerahan = '';
		$nilaikurs = '';
		$tgdaft = '';
		
		$npwpqq = '';
		$namabeli = '';
		
		$alamatbeli = '';
		$jmlbrg = 0;
		$brutto = 0;
		$netto = 0;
		foreach($rs as $row){
			$nodaft = $row['NODAFT'];
			$kantor_tujuan = $row['KantorTujuan'];
			
			$npwpeks = $row['NPWPEKS'];
			$namaeks = $row['NamaEks'];
			$alamateks= $row['AlmtEks'];
			
			$registrasi = $row['Registrasi'];
			$nilaiCIF = $row['NilaiCIF'];
			$hargaPenyerahan = $row['HargaPenyerahan'];
			
			$kdval = $row['KDVAL'];
			$nilaikurs = $row['NILKURS'];
			$tgdaft = $row['TGDAFT'];
			
			$npwpqq = $row['NpwpQq'];
			$namabeli = $row['NAMABELI'];
			
			$alamatbeli=$row['ALMTBELI'];
			$jmlbrg = $row['JMBRG'];
			
			$brutto =  $row['BRUTO'];
			$netto =  $row['NETTO'];
		}
		$vowels = array(" ","  ", ".");
		$namabeli1 = str_replace($vowels, "%", substr($namabeli,0, 20));
		
		$qrytbl_nama_pembeli = $this->db->query(
			"
			SELECT [NPWP]
			  ,[NAMABELI]
			  ,[ALMTBELI]
			  ,[ALMTBELI1]
			  ,[NEGBELI]
			  ,[NOIJIN]
			  ,[NOKONTRAK]
			  ,convert(varchar, [TGLIJIN], 106) as [TGLIJIN]
			  ,convert(varchar, [TGLKONTRAK], 106) as [TGLKONTRAK]
			  ,[KPBC] as KPBC 
		  FROM [dbo].[tbl_nama_pembeli]
		  where NAMABELI like '%$namabeli1%'
			"
		);
		
		$rsqrytbl_nama_pembeli = $qrytbl_nama_pembeli->result_array();
		//die($this->db->last_query());
		
		$kpbcx = ""; $ALMTBELI = ""; $ALMTBELI1 = "";
		$NAMABELI = ""; $NOIJIN = ""; $NOKONTRAK = "";
		$TGLKONTRAK = "";
		$NPWP = "";
		foreach($rsqrytbl_nama_pembeli as $rowqrytbl_nama_pembeli){
			
			$kpbcx = $rowqrytbl_nama_pembeli['KPBC'];
			$NAMABELI = $rowqrytbl_nama_pembeli['NAMABELI'];
			$ALMTBELI = $rowqrytbl_nama_pembeli['ALMTBELI'];
			$ALMTBELI1 = $rowqrytbl_nama_pembeli['ALMTBELI1'];
			$NOIJIN = $rowqrytbl_nama_pembeli['NOIJIN'];
			$NOKONTRAK = $rowqrytbl_nama_pembeli['NOKONTRAK'];
			$TGLKONTRAK = $rowqrytbl_nama_pembeli['TGLKONTRAK'];
			$NPWP = $rowqrytbl_nama_pembeli['NPWP'];
			
		}
		
		
		$qrydokinv = $this->db->query(
			"
				SELECT 
				   [NoDok]
				  ,convert(varchar, [TgDok], 106) as TgDok
			  FROM [dbo].[tbl_bc_out_dok]
			  where [id_bc_out_hdr] = $id_bc_out_hdr and kddok ='380'
			"
		);	
		
		$rsdokinv = $qrydokinv->result_array();
		$noinv = '';
		$tgdok = '';
		foreach ( $rsdokinv as $rowdokinv){
			
			$noinv .=  $rowdokinv['NoDok'] . ' ';
			$tgdok = $rowdokinv['TgDok'];
		}
		
		
		$rs= $this->db->query("
		SELECT [id_bc_out_dtl]
	      ,[id_bc_out_hdr] ,[HS]
	      ,[URBRG1]
	      ,[JMSATUAN]
	      ,[JNSATUAN]
		  ,[DNilInv]
  		FROM [dbo].[tbl_bc_out_dtl] where id_bc_out_hdr = $id_bc_out_hdr
		");
		
		$hs = array();
		$urbrg1 = array();
		$jmsatuan = array();
		$jnsatuan = array();
		$dnil = array();
		$qrydetail = $rs->result_array();
		
		
		$qrykms= $this->db->query("
			SELECT  SUM(isnull([JMKOLI], 0)) as JMKOLI
			FROM [dbo].[tbl_bc_out_dtl] where id_bc_out_hdr = $id_bc_out_hdr
		");
		
		$JMKOLI = 0;
		$rskms = $qrykms->result_array();
		foreach ($rskms as $rw) {
				
			$JMKOLI = $rw["JMKOLI"];
		}
		
		
		include_once ( APPPATH."libraries/PHPExcel.php");	
		include_once ( APPPATH."libraries/PHPExcel/IOFactory.php");	
		$phpExcel = new PHPExcel();
		$objTpl = PHPExcel_IOFactory::load(APPPATH."libraries/PHPExcel/templates/bc27.xls");	
		$objTpl->setActiveSheetIndex(0);  //set first sheet as active
		
		$objTpl->getActiveSheet()->setCellValue('D6', ': '.$nodaft);
		$objTpl->getActiveSheet()->setCellValue('E9', ': '.$kpbcx);
		$objTpl->getActiveSheet()->setCellValue('I16', ': '.$NAMABELI);
		$objTpl->getActiveSheet()->setCellValue('I17', ': '.$ALMTBELI);
		$objTpl->getActiveSheet()->setCellValue('I18', ': '.$ALMTBELI1);
		$objTpl->getActiveSheet()->setCellValue('I19', ': '.$NOIJIN);
		$objTpl->getActiveSheet()->setCellValue('I11', ': '.$tgdaft);
		$objTpl->getActiveSheet()->setCellValue('D24', ' '.$NOKONTRAK);
		$objTpl->getActiveSheet()->setCellValue('I15', ' '.$NPWP);

		$objTpl->getActiveSheet()->setCellValue('D25', 'TGL, '.$TGLKONTRAK);
		$objTpl->getActiveSheet()->setCellValue('F30', ':' . $kdval);
		$objTpl->getActiveSheet()->setCellValue('J45', '' . $kdval);
		$objTpl->getActiveSheet()->setCellValue('F31', $nilaiCIF);
		$objTpl->getActiveSheet()->setCellValue('J30', $nilaikurs);
		$objTpl->getActiveSheet()->setCellValue('D22', $noinv);
		$objTpl->getActiveSheet()->setCellValue('D23', $noinv);
		$objTpl->getActiveSheet()->setCellValue('C52', "......Tangerang......Tgl..... ".$tgdaft."...");
		$objTpl->getActiveSheet()->setCellValue('F41', $brutto);
		$objTpl->getActiveSheet()->setCellValue('K41', $netto);
		$objTpl->getActiveSheet()->setCellValue('F37', $JMKOLI);
		
		if ($kdval == 'IDR'){
			$objTpl->getActiveSheet()->setCellValue('H31', $nilaiCIF);
		}
		
		$objTpl->setActiveSheetIndex(1);
		$num_rows = $rs->num_rows();
		
		$i = 1;
		$j = '';
		$k = 18;
		$l = 0;
		$m = '';
		foreach($qrydetail as $rowdtl){
			
			
			
			$k = 18 + $i;
			$j = "$k";
			
			$objTpl->getActiveSheet()->setCellValue("B".$j, $i);
			$objTpl->getActiveSheet()->setCellValue("C".$j, substr($rowdtl["HS"], 0, 4). "." . substr($rowdtl["HS"], 4, 2) . "." . substr($rowdtl["HS"], 6, 2) . "." . substr($rowdtl["HS"], 8, 2));
			$objTpl->getActiveSheet()->setCellValue("E".$j, $rowdtl["URBRG1"]);
			$objTpl->getActiveSheet()->setCellValue("H".$j, $rowdtl["JMSATUAN"]);
			$objTpl->getActiveSheet()->setCellValue("I".$j, $rowdtl["JNSATUAN"]);
			$objTpl->getActiveSheet()->setCellValue("K".$j, $rowdtl["DNilInv"]);
			
			$i++;
		}
		$l = $num_rows + 19;
		$m = "$l";
		$o = $num_rows + 18;
		$p = "$o";
		$s = "=SUM(H19:H$o)";
		$t = "=SUM(K19:K$o)";
		
		$objTpl->getActiveSheet()->setCellValue("G".$m, "TOTAL");
		$objTpl->getActiveSheet()->setCellValue("I".$m, "SET");
		$objTpl->getActiveSheet()->setCellValue("H".$m, $s);
		$objTpl->getActiveSheet()->setCellValue("K".$m, $t);
		$objTpl->getActiveSheet()->getStyle("G".$m)->getFont()->setBold(true);	
		$objTpl->getActiveSheet()->getStyle("I".$m)->getFont()->setBold(true);	
		$objTpl->getActiveSheet()->getStyle("H".$m)->getFont()->setBold(true);			
		$objTpl->getActiveSheet()->getStyle("K".$m)->getFont()->setBold(true);	
		$styleArray = array(
		  'font' => array(
			'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE
		  )
		);
		$objTpl->getActiveSheet()->getStyle("H".$o)->applyFromArray($styleArray);
		$objTpl->getActiveSheet()->getStyle("K".$o)->applyFromArray($styleArray);
		unset($styleArray);
		$objTpl->setActiveSheetIndex(0);
		
		$datenow = date('Ymd');
		$filename =  "BC27_".trim($nodaft). "_" . trim($noinv)  ."_" . $datenow;
		
		header("Content-type:application/vnd.ms-excel");
		header("Content-disposition:attachment; filename=$filename"); 
		header("Pragma:no-cache");
		header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
		header("Expires:0");

		$objWriter = PHPExcel_IOFactory::createWriter($objTpl, 'Excel5');  //downloadable file is in Excel 2003 format (.xls)
		$objWriter->save('php://output');  //send it to user, of course you can save it to disk also!
		 
		exit; //done.. exiting!	
	
	
	}
	
	function cekkurs(){
		$tglinvbc27 = (isset($_POST['tglinvbc27']) && !empty($_POST['tglinvbc27']))?$_POST['tglinvbc27']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$kdvalbc27 = (isset($_POST['kdvalbc27']) && !empty($_POST['kdvalbc27']))?$_POST['kdvalbc27']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$qrykurs= $this->db->query("
			SELECT [id_kurs]
			  ,[KdKurs]
			  ,[TgAwal]
			  ,[TgAkhir]
			  ,[Nilai]
			  ,[Ket]
		  FROM [dbo].[tblKurs]
		  where [KdKurs] = '$kdvalbc27' and [TgAwal] <= '$tglinvbc27' and [TgAkhir] >= '$tglinvbc27'
		");
		
		$rs = $qrykurs->result_array();	
		$nilai = '';
		foreach ($rs as $row){
			$nilai = $row["Nilai"];
		 }  
		 
		if (!empty($nilai)){ 
			echo json_encode(array('sts' => '00', 'desc' => 'Sukses', 'nilai' => $nilai));
		} else {
		
			echo json_encode(array('sts' => '07', 'desc' => 'Kurs Belum ada, Silahkan update di menu Master Data->Kurs'));	
		}
	
	}
	
	function cancelnocar(){
		$uid = $this->session->userdata('DX_username');
		if ($uid != 'admin') {
			die('{"sts":"ERROR","desc":" Harus Admin"}');
		
		}
		$idhdrbc27 = (isset($_POST['idhdrbc27']) && !empty($_POST['idhdrbc27']))?$_POST['idhdrbc27']:die('{"sts":"ERROR","desc":" idhdrbc27 Param Tidak Ditemukan"}');
		$typedok = (isset($_POST['typedok']) && !empty($_POST['typedok']))?$_POST['typedok']:die('{"sts":"ERROR","desc":" typedok Param Tidak Ditemukan"}');
		
		$qry = $this->db->query("
			declare @bc_in_from_in varchar(50), @noprosesdata varchar(50)
			set @bc_in_from_in=(select top 1 bc_in_from_in from tbl_bc_out_hdr where id_bc_out_hdr=$idhdrbc27)
			set @noprosesdata = replace(@bc_in_from_in, 'SA', '') 
			
			if (select count(*) from tblbc27hdr where noprosesdata = replace(@bc_in_from_in, 'SA', '') ) = 0
			begin
				select '06' as status, 'Data SA tidak ditemukan..' as description
				return
			end
			
			declare @id_bc_out_hdr bigint
			declare @idpebhdr bigint
			
			set @id_bc_out_hdr = ( select id_bc_out_hdr from [dbo].[tbl_bc_out_hdr] where [bc_in_from_in] = @bc_in_from_in )
			
			declare @id_data_out_hdr bigint
			set @id_data_out_hdr = (select id_data_out_hdr from tbl_data_out_hdr  where id_terkait = @id_bc_out_hdr and doc_out_to_id=5)
			
			BEGIN TRY  
	           	BEGIN TRANSACTION
				delete from tbl_data_out_hdr_h_status where id_data_out_hdr=@id_data_out_hdr
				delete from tbl_data_out_dtl where id_data_out_hdr=@id_data_out_hdr and type_items='FG'
				delete from tbl_data_out_hdr where id_data_out_hdr=@id_data_out_hdr and doc_out_to_id=5 
				
				delete from [dbo].[tbl_bc_out_hdr_h_status] where [id_bc_out_hdr] = @id_bc_out_hdr
				delete from [dbo].[tbl_bc_out_kms] where [id_bc_out_hdr] = @id_bc_out_hdr
				delete from [dbo].[tbl_bc_out_con] where [id_bc_out_hdr] = @id_bc_out_hdr
				delete from [dbo].[tbl_bc_out_dok] where [id_bc_out_hdr] = @id_bc_out_hdr
				delete from [dbo].[tbl_bc_out_dtl] where [id_bc_out_hdr] = @id_bc_out_hdr
				delete from [dbo].[tbl_bc_out_hdr] where [id_bc_out_hdr] = @id_bc_out_hdr
				
				delete from [dbo].[tblbc27dtl] where [idbc27hdr] in (select idbc27hdr from tblbc27hdr where [noprosesdata] = @noprosesdata)
				delete from [dbo].[tblbc27hdr] where [noprosesdata] = @noprosesdata
				COMMIT
			END TRY	
			BEGIN CATCH
			-- Whoops, there was an error
			IF @@TRANCOUNT > 0
			 ROLLBACK

			-- Raise an error with the details of the exception
			DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
			Set @ErrMsg = ERROR_MESSAGE()
			set @ErrSeverity = ERROR_SEVERITY()
			select @ErrMsg as status,@ErrSeverity as description
			RAISERROR(@ErrMsg, @ErrSeverity, 1)
			END CATCH 
			
			select '00' as status, 'DATA CANCELED..Silahkan Upload ulang SA jika akan diulang' as description
			
			
		 ");
		 $rs = $qry->result_array();
		// $r = $qry->result();		
		//var_dump($rs);die();	
		
		
		
		
		foreach ($rs as $row){
			$status = $row['status'];
			$msg = $row['description'];
		}
		
		echo json_encode(array('sts' => $status, 'desc' => $msg));	
	
	
	}
	
	function view_bc27_search(){
	
		$this->load->view('exim/view_bc27_search');
	
	}
	
	function view_bc27_prosesdata(){
	
		$datadiff = (isset($_POST['datadiff']) && !empty($_POST['datadiff']))?$_POST['datadiff']:'0'; 
		$data['json'] = $datadiff;	
		$this->load->view('exim/view_bc27_prosesdata', $data);
	  
	}
	function proses_bc27_new(){
		$datadiff = (isset($_POST['datadiff']) && !empty($_POST['datadiff']))?$_POST['datadiff']:'0'; 
		$datadiff = json_decode($datadiff);
		$datacsv = '';
		$namabeli = '';
		foreach ($datadiff as $data){
			
			$idbc27hdr = (isset($data->idbc27hdr) && !empty($data->idbc27hdr))?$data->idbc27hdr :die('{"sts":"ERROR","desc":" Param idbc27hdr Tidak Ditemukan"}');
			$gabinvoice = (isset($data->gabinvoice) && !empty($data->gabinvoice))?$data->gabinvoice :die('{"sts":"ERROR","desc":" Param  Tidak Ditemukan"}');
			$NOINV = (isset($data->NOINV) && !empty($data->NOINV))?$data->NOINV :die('{"sts":"ERROR","desc":" Param  Tidak Ditemukan"}');
			$namabeli= (isset($data->NAMABELI) && !empty($data->NAMABELI))?$data->NAMABELI :die('{"sts":"ERROR","desc":" Param idbc27hdr Tidak Ditemukan"}');  
			$datacsv .= $idbc27hdr . ',' . $gabinvoice . ',' . $NOINV . ',' . $namabeli;
			$datacsv .= "|";
		}
		
		 
		//$userid=$this->session->userdata('DX_user_id');
		$userid=$this->session->userdata('DX_username');
		
		$qry = $this->db->query("

		 EXEC ('[spi_proses_bc27_new] @datadiff=''$datacsv'', @userid=''$userid'' ') 

		");
		$rs = $qry->result_array();
		// $r = $qry->result();		
		// var_dump($r);die();
		foreach ($rs as $row){
		$responce = array("sts" => $row['status'], "desc" => $row['description'].' Ok');
		}  
		echo json_encode($responce);
  
	}	
	
	function view_bc27_matching_ceisa(){
		$data["param"] = "";
		$this->load->view('exim/view_bc27_matching_ceisa', $data);
		
	}
	
	function datamodul_detil_ceisa(){
		
		$bc23dir = $this->config->item('APP_modulbc23');
		$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']:'car'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$tglawalbc27_ceisacar = (isset($_POST['tglawalbc27_ceisacar']) && !empty($_POST['tglawalbc27_ceisacar']))?$_POST['tglawalbc27_ceisacar']:date('Y-m-d');
		$tglakhirbc27_ceisacar = (isset($_POST['tglakhirbc27_ceisacar']) && !empty($_POST['tglakhirbc27_ceisacar']))?$_POST['tglakhirbc27_ceisacar']:date('Y-m-d');
		
		$car = (isset($_POST['car']) && !empty($_POST['car']))?$_POST['car']:'';
		
		$where = " 1=1 ";
		
		$where = " CAST(SUBSTRING(a.NOMOR_AJU,21,6) as int) < 500000 and c.KODE_DOKUMEN = '27' and  a.KODE_DOKUMEN_PABEAN ='27' and  convert(varchar(10),a.TANGGAL_AJU,126) between '$tglawalbc27_ceisacar' and '$tglakhirbc27_ceisacar' ";
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){
					if ( $k->field == "CAR" ) {
						$searchString = $k->data;
						$where .= " and a.NOMOR_AJU like  '%".$searchString."%'"; 
					} else if ( $k->field == "carx" ) {
						$searchString = $k->data;
						$where .= " and b.car like  '%".$searchString."%'"; 
					}  
				}
			}
		}
		
		
		if (!empty($car)){
			
			$where = " CAST(SUBSTRING(a.NOMOR_AJU,21,6) as int) < 500000 and c.KODE_DOKUMEN = '27' and a.NOMOR_AJU like '%$car%' and a.KODE_DOKUMEN_PABEAN ='27'  ";
		}
		
		$this->db->query("
			SET ANSI_NULLS ON
			SET ANSI_WARNINGS ON
		");
		
		$query = $this->db->query("
			
			select count(*) as cnt from openquery(TPBDB,'select * from tpb_header') a
			left outer join tbl_bc_out_hdr b on a.NOMOR_AJU = b.CAR
			inner join openquery(TPBDB,'select * from referensi_status')   c on c.KODE_STATUS = a.KODE_STATUS
			where $where 
			
		
		");
	
		
		$result = $query->result_array();
		
		$cnt = 0;
		foreach ($result as $row){
		
			$cnt = $row['cnt'];
		
		}
				
		$count=$cnt;
		if( $count >0 ) { $total_pages = ceil($count/$limit); } 
			else { $total_pages = 0; } 
		if ($page > $total_pages) $page=$total_pages; 
		$start = $limit*$page - $limit; // do not put $limit*($page - 1) if ($start<0) $start = 0;
		$batas = $count - (($page - 1) * $limit);
		
		 $q = $this->db->query("
			select top $limit car, convert(varchar(10), xdate, 126) as xdate,  carx, 
			sts,
			jnsbarang,NOMOR_DAFTAR,TANGGAL_DAFTAR,id_bc_out_hdr, ID,
			URAIAN_STATUS
			 from (
				select TOP $batas a.NOMOR_AJU as CAR, a.TANGGAL_AJU as xdate
				,b.car as carx, 
				a.KODE_STATUS as sts, a.KODE_DOKUMEN_PABEAN as jnsbarang 
				,a.NOMOR_DAFTAR as NOMOR_DAFTAR, CONVERT(varchar(10),a.TANGGAL_DAFTAR, 126) as TANGGAL_DAFTAR
				,b.id_bc_out_hdr ,a.ID as ID, c.URAIAN_STATUS
				from openquery(TPBDB,'select * from tpb_header') a 
				inner join openquery(TPBDB,'select * from referensi_status') c on c.KODE_STATUS = a.KODE_STATUS
				left outer join dbo.tbl_bc_out_hdr b on a.NOMOR_AJU = b.car
				where $where
				order by $sidx desc
			)  t1 Order By car $sord
			
			"); 
		$rs = $q->result_array();
		//echo $this->db->last_query(); die();
		
		// var_dump($rs);
		// die(); 
		
		$responce->page = $page;
		$responce->total = $total_pages;
		$responce->records =(integer) $count;
		$i=0;
		
		foreach ($rs as $r){
			
			$responce->rows[$i]["CAR"]=$r["car"];
			$responce->rows[$i]["carx"]=$r["carx"];
			$responce->rows[$i]["xdate"]=$r["xdate"];
	    	$responce->rows[$i]["NOMOR_DAFTAR"]=$r["NOMOR_DAFTAR"];
			$responce->rows[$i]["TANGGAL_DAFTAR"]=$r["TANGGAL_DAFTAR"]; 
			$responce->rows[$i]["sts"]=$r["sts"];
			$responce->rows[$i]["jnsbarang"]=$r["jnsbarang"];
			$responce->rows[$i]["id_bc_out_hdr"]=$r["id_bc_out_hdr"];
			$responce->rows[$i]["ID"]=$r["ID"];
			$responce->rows[$i]["URAIAN_STATUS"]=$r["URAIAN_STATUS"];
			$i++;
		}
		
		echo json_encode($responce);
		die();
	}
	
	function proses_get_replace_bc27_ceisa(){
		$car = (isset($_POST['carproses_matchbc27_ceisa']) && !empty($_POST['carproses_matchbc27_ceisa']))?$_POST['carproses_matchbc27_ceisa']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$id_ceisa = (isset($_POST['id_ceisa']) && !empty($_POST['id_ceisa']))?$_POST['id_ceisa']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$id_bc_out_hdr = (isset($_POST['id_bc_out_hdr']) && !empty($_POST['id_bc_out_hdr']))?$_POST['id_bc_out_hdr']:'';
		$username=$this->session->userdata('DX_username');
		
		
		
		$this->db->query("
			SET ANSI_NULLS ON
			SET ANSI_WARNINGS ON
		");
		if ($id_bc_out_hdr != ''){
			$matchcar = $this->db->query("
				declare @car varchar(50)
				declare @NOMOR_DAFTAR varchar(50)
				declare @TANGGAL_DAFTAR date
				
				set @car = (select car from tbl_bc_out_hdr where id_bc_out_hdr = $id_bc_out_hdr) 
				
				BEGIN TRY
				if	(select 
					count(*)	
					from openquery(TPBDB,'select * from tpb_header')
					where NOMOR_AJU = @car and KODE_DOKUMEN_PABEAN ='27') <> 1
				begin
					SELECT 
					'06' AS status
					,' CAR TIDAK DITEMUKAN ATAU LEBIH DARI SATU NOMOR AJU SAMA, GUNAKAN TARIK MANUAL' AS description
					return
				end	
				
				select 
					@NOMOR_DAFTAR=NOMOR_DAFTAR,
					@TANGGAL_DAFTAR=TANGGAL_DAFTAR	
				from openquery(TPBDB,'select * from tpb_header')
				where NOMOR_AJU = @car and KODE_DOKUMEN_PABEAN ='27'	
				
				update tbl_bc_out_hdr set NODAFT=@NOMOR_DAFTAR, TGDAFT=@TANGGAL_DAFTAR where id_bc_out_hdr = $id_bc_out_hdr  
				
				SELECT 
					'00' AS status
					,' NO DAFTAR : ' + @NOMOR_DAFTAR AS description;
				END TRY
				BEGIN CATCH 
					SELECT 
					'06' AS status
					,ERROR_MESSAGE() AS description;
					
				END CATCH;
				
			");
		} else {
			
			$q_con = $this->db->query("
				select count(*)  as cnt
				from openquery(TPBDB,'select * from tpb_kontainer')
				where id_header=$id_ceisa
			");
			
			$JMCON = 0;
			foreach ($q_con->result() as $r_con){
				$JMCON =  $r_con->cnt;
			}
			
				
			$matchcar = $this->db->query("
				declare @car varchar(50)
				declare @carceisa varchar(50)
				declare @NOMOR_DAFTAR varchar(50)
				declare @TANGGAL_DAFTAR date
				declare @id_ceisa bigint
				set @id_ceisa = $id_ceisa
				
				set @carceisa = (select NOMOR_AJU from openquery(TPBDB,'select * from tpb_header') where ID = @id_ceisa) 
				
				BEGIN TRY
					insert into [tbl_bc_out_hdr] (
						CAR
						,KatEks
						,IDEKS
						,NPWPEKS
						,NamaEks
						,AlmtEks
						,NAMABELI
						,ALMTBELI
						,CARRIER
						,MODA
						,KDVAL
						,NilInv
						,FOB
						,BRUTO
						,NETTO
						,JMBRG
						,NODAFT
						,TGDAFT
						,KDKTR
						,KTRGATE
						,JNTPB
						,TTDPEB
						,STATUS
						,NILKURS
						,NEGBELI
						,typedok
						,statusdok
						,bc_in_from_in
						,JMCONT 
						,[create_date]
					      ,[create_by]
					      ,[update_date]
					      ,[update_by]

					) select
					 NOMOR_AJU			
					,KODE_JENIS_TPB
					,KODE_ID_PENGUSAHA
					,ID_PENGUSAHA
					,NAMA_PENGUSAHA
					,SUBSTRING(ALAMAT_PENGUSAHA, 1, 70)
					,NAMA_PENERIMA_BARANG
					,SUBSTRING(ALAMAT_PENERIMA_BARANG, 1, 70)
					,NAMA_PENGANGKUT
					,'1'	
					,KODE_VALUTA
					,HARGA_PENYERAHAN
					,HARGA_PENYERAHAN
					,BRUTO
					,NETTO
					,JUMLAH_BARANG
					,NOMOR_DAFTAR
					,TANGGAL_DAFTAR
					,KODE_KANTOR
					,KODE_KANTOR
					,'KB'
					,NAMA_TTD
					,KODE_STATUS
					,NDPBM
					,'ID'
					,'BC27'
					,'DATA PROCESSED'
					,'CEISA_BC27'
					,$JMCON
					,GETDATE()
					,'$username'
					,GETDATE()
					,'$username'
					 from openquery(TPBDB,'select * from tpb_header') where ID = @id_ceisa
				declare @id_hdrx bigint
				set @id_hdrx = @@IDENTITY 
				
				insert into tbl_bc_out_dtl (
					id_bc_out_hdr
					,CAR
					,[SERIBRG]
					,URBRG1
					,URBRG2
					,URBRG3
					,URBRG4
					,DMERK
					,SIZE
					,TYPE
					,KDBRG
					,JMKOLI
					,JNKOLI
					,DNilInv
					,FOBPERBRG
					,JMSATUAN
					,JNSATUAN
					,NETDET
					,DVolume
					,NegAsal
					,HS
				) select
				@id_hdrx
				,@carceisa
				,SERI_BARANG
				,SUBSTRING(URAIAN,1,40)
				,SUBSTRING(URAIAN,41,80)
				,SUBSTRING(URAIAN,81,120)
				,SUBSTRING(URAIAN,121,160)
				,MERK
				,UKURAN
				,TIPE
				,KODE_BARANG
				,JUMLAH_KEMASAN
				,KODE_KEMASAN
				,HARGA_PENYERAHAN
				,HARGA_SATUAN
				,JUMLAH_SATUAN
				,KODE_SATUAN
				,NETTO
				,VOLUME
				,KODE_NEGARA_ASAL
				,POS_TARIF
				 from openquery(TPBDB,'select * from tpb_barang') where ID_HEADER = @id_ceisa
				
				insert into tbl_bc_out_dok (
					id_bc_out_hdr
					,CAR
					,[KdDok]
			      ,[NoDok]
			      ,[TgDok]
					
				) select
				@id_hdrx
				,@carceisa
				,SUBSTRING(KODE_JENIS_DOKUMEN, 1, 3)
				,NOMOR_DOKUMEN
				,CONVERT(varchar(10), TANGGAL_DOKUMEN, 126)
				 from openquery(TPBDB,'select * from tpb_dokumen') where ID_HEADER = @id_ceisa
				
				insert into tbl_bc_out_con (
					id_bc_out_hdr
					,CAR
					 ,[NoCont]
				      ,[Size]
				      ,[Type]
				      
					
				) select
				@id_hdrx
				,@carceisa
				,NOMOR_KONTAINER
				,KODE_UKURAN_KONTAINER
				,KODE_TIPE_KONTAINER
				 from openquery(TPBDB,'select * from tpb_kontainer') where ID_HEADER = @id_ceisa
				
				insert into tbl_bc_out_kms (
					id_bc_out_hdr
					,CAR
					,[JnKemas]
     				 ,[JmKemas]
					
				) select
				@id_hdrx
				,@carceisa
				,KODE_JENIS_KEMASAN
				,JUMLAH_KEMASAN
				 from openquery(TPBDB,'select * from tpb_kemasan') where ID_HEADER = @id_ceisa
					
				
				insert into [tbl_bc_out_bahan_baku] (
					[id_bc_out_hdr]
					,[CAR]
				    ,[ID]
			      ,[CIF]
			      ,[CIF_RUPIAH]
			      ,[HARGA_PENYERAHAN]
			      ,[HARGA_PEROLEHAN]
			      ,[JENIS_SATUAN]
			      ,[JUMLAH_SATUAN]
			      ,[KODE_ASAL_BAHAN_BAKU]
			      ,[KODE_BARANG]
			      ,[KODE_FASILITAS_DOKUMEN]
			      ,[KODE_JENIS_DOK_ASAL]
			      ,[KODE_KANTOR]
			      ,[KODE_SKEMA_TARIF]
			      ,[KODE_STATUS]
			      ,[MERK]
			      ,[NDPBM]
			      ,[NETTO]
			      ,[NOMOR_AJU_DOK_ASAL]
			      ,[NOMOR_DAFTAR_DOK_ASAL]
			      ,[POS_TARIF]
			      ,[SERI_BAHAN_BAKU]
			      ,[SERI_BARANG]
			      ,[SERI_BARANG_DOK_ASAL]
			      ,[SPESIFIKASI_LAIN]
			      ,[TANGGAL_DAFTAR_DOK_ASAL]
			      ,[TIPE]
			      ,[UKURAN]
			      ,[URAIAN]
			      ,[ID_BARANG]
			      ,[ID_HEADER]
				     
				) select
				@id_hdrx
				,@carceisa,
				ID,
				CIF,
				CIF_RUPIAH,
				HARGA_PENYERAHAN,
				HARGA_PEROLEHAN,
				JENIS_SATUAN,
				JUMLAH_SATUAN,
				KODE_ASAL_BAHAN_BAKU,
				KODE_BARANG,
				KODE_FASILITAS_DOKUMEN,
				KODE_JENIS_DOK_ASAL,
				KODE_KANTOR,
				KODE_SKEMA_TARIF,
				KODE_STATUS,
				MERK,
				NDPBM,
				NETTO,
				NOMOR_AJU_DOK_ASAL,
				NOMOR_DAFTAR_DOK_ASAL,
				POS_TARIF,
				SERI_BAHAN_BAKU,
				SERI_BARANG,
				SERI_BARANG_DOK_ASAL,
				SPESIFIKASI_LAIN,
				TANGGAL_DAFTAR_DOK_ASAL,
				TIPE,
				UKURAN,
				URAIAN,
				ID_BARANG,
				ID_HEADER

				 from openquery(TPBDB,'select * from tpb_bahan_baku') where ID_HEADER = @id_ceisa
					
				
				insert into [tbl_bc_out_bahan_baku_tarif] (
					[id_bc_out_hdr]
					,[CAR],
				  ID,
					JENIS_TARIF,
					JUMLAH_SATUAN,
					KODE_ASAL_BAHAN_BAKU,
					KODE_FASILITAS,
					KODE_KOMODITI_CUKAI,
					KODE_SATUAN,
					KODE_TARIF,
					NILAI_BAYAR,
					NILAI_FASILITAS,
					NILAI_SUDAH_DILUNASI,
					SERI_BAHAN_BAKU,
					SERI_BARANG,
					TARIF,
					TARIF_FASILITAS,
					ID_BAHAN_BAKU,
					ID_BARANG,
					ID_HEADER
				     
				) select
				@id_hdrx
				,@carceisa
				,ID,
				JENIS_TARIF,
				JUMLAH_SATUAN,
				KODE_ASAL_BAHAN_BAKU,
				KODE_FASILITAS,
				KODE_KOMODITI_CUKAI,
				KODE_SATUAN,
				KODE_TARIF,
				NILAI_BAYAR,
				NILAI_FASILITAS,
				NILAI_SUDAH_DILUNASI,
				SERI_BAHAN_BAKU,
				SERI_BARANG,
				TARIF,
				TARIF_FASILITAS,
				ID_BAHAN_BAKU,
				ID_BARANG,
				ID_HEADER

				 from openquery(TPBDB,'select * from tpb_bahan_baku_tarif') where ID_HEADER = @id_ceisa
					
				
					
					
				END TRY
				BEGIN CATCH 
					SELECT 
					'06' AS status
					,ERROR_MESSAGE() AS description;
					
				END CATCH;
				
				SELECT 
					'00' AS status
					,' DATA PROCESSED' AS description;
				
			");
		}	
		$rs = $matchcar->result_array();
        //$r = $matchcar->result();		
		//var_dump($rs);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	}
	
	function cekdokmacthing_ceisa(){
		$car = (isset($_POST['car']) && !empty($_POST['car']))?$_POST['car']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$bc23dir = $this->config->item('APP_modulbc23');
		
		
		$this->db->query("
			SET ANSI_NULLS ON
			SET ANSI_WARNINGS ON
		");
         $q = $this->db->query("
			select a.NOMOR_DOKUMEN as dokno, convert(varchar(10), a.TANGGAL_DOKUMEN, 126) as doktg, a.KODE_JENIS_DOKUMEN as dokkd
			 from
				openquery(TPBDB,'select * from tpb_dokumen') a inner join openquery(TPBDB,'select * from tpb_header') b
				on a.ID_HEADER = b.ID
				
				where NOMOR_AJU='$car'
			"); 
		$rs = $q->result_array();
		$i=0;	
		foreach ($rs as $r){
			
		 	$responce[$i]["dokno"]=$r["dokno"];
			$responce[$i]["doktg"]=$r["doktg"]; 
			$responce[$i]["dokkd"]=$r["dokkd"]; 
			$i++;
			
		}
		
		echo json_encode($responce);
		
	
	
	}
	
	
  
 }