<?php
class CT_bc271 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');
		$this->load->model("exim/mdl_bc23", 'mdl_bc23');
		$this->load->model("exim/mdl_bc40", 'mdl_bc40');
		$this->load->model("exim/mdl_invoice", 'mdl_invoice');
		$this->load->helper('afunction');
		
	}

	function index(){

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

	
	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'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$where = " 1=1 and typedok='BC271' ";
		if (isset($_POST['tglawal']) and isset($_POST['tglakhir'])){
			$tglawal=$_POST['tglawal'];
			$tglakhir=$_POST['tglakhir'];
			$where .= " and BC23Tg between '$tglawal' and '$tglakhir' ";
		}			
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){
					
					if ( $k->field == "nobl" ) {
						$searchString = $k->data;
						$where .= " and nobl like  '%".$searchString."%'"; 
					} else if ( $k->field == "tglbl" ) {
						$searchString = $k->data;
						$where .= " and tglbl =  '$searchString'"; 
					} else if ( $k->field == "CAR" ) {
						$searchString = $k->data;
						$where .= " and CAR like  '%".$searchString."%'"; 
					} else if ( $k->field == "KdKpbc" ) {
						$searchString = $k->data;
						$where .= " and KdKpbc like  '%".$searchString."%'"; 
					} else if ( $k->field == "PasokNama" ) {
						$searchString = $k->data;
						$where .= " and PasokNama like  '%".$searchString."%'"; 
					} else if ( $k->field == "BC23No" ) {
						$searchString = $k->data;
						$where .= " and BC23No like  '%".$searchString."%'"; 
					} else if ( $k->field == "BC23Tg" ) {
						$searchString = $k->data;
						$where .= " and BC23Tg like  '%".$searchString."%'"; 
					} else if ( $k->field == "JmBrg" ) {
						$searchString = $k->data;
						$where .= " and JmBrg = $searchString"; 
					} else if ( $k->field == "Status" ) {
						$searchString = $k->data;
						$where .= " and Status like  '%".$searchString."%'"; 
					}  else if ( $k->field == "statusdok" ) {
						$searchString = $k->data;
						$where .= " and statusdok like  '%".$searchString."%'"; 
					} 
				}
			}
		}
		
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc23->bc23hdrdataAll($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_bc23->bc23hdrdataCountAll($where);
	//	var_dump($records); die();
		
		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){
			if($r->Status == null){
				$status = '-';
				
			} else { $status=$r->Status;  }
			
			$responce->rows[$i]['id_bc_in_hdr']=$r->id_bc_in_hdr; 
			$responce->rows[$i]['CAR']=$r->CAR; 
			$responce->rows[$i]['KdKpbc']=$r->KdKpbc; 
			$responce->rows[$i]['Tujuan']=$r->Tujuan; 
			$responce->rows[$i]['JnsBarang']=$r->JnsBarang; 
			$responce->rows[$i]['TujuanKirim']=$r->TujuanKirim; 
			$responce->rows[$i]['PasokNama']=$r->PasokNama; 
			$responce->rows[$i]['PasokAlmt']=$r->PasokAlmt; 
			$responce->rows[$i]['PasokNeg']=$r->PasokNeg; 
			$responce->rows[$i]['UsahaId']=$r->UsahaId; 
			$responce->rows[$i]['UsahaNpwp']=$r->UsahaNpwp; 
			$responce->rows[$i]['KdTPB']=$r->KdTPB; 
			$responce->rows[$i]['Registrasi']=$r->Registrasi; 
			$responce->rows[$i]['UsahaNama']=$r->UsahaNama; 
			$responce->rows[$i]['UsahaAlmt']=$r->UsahaAlmt; 
			$responce->rows[$i]['UsahaStatus']=$r->UsahaStatus; 
			$responce->rows[$i]['ApiKd']=$r->ApiKd; 
			$responce->rows[$i]['ApiNo']=$r->ApiNo; 
			$responce->rows[$i]['PpjkId']=$r->PpjkId; 
			$responce->rows[$i]['PpjkNpwp']=$r->PpjkNpwp; 
			$responce->rows[$i]['PpjkNama']=$r->PpjkNama; 
			$responce->rows[$i]['PpjkAlmt']=$r->PpjkAlmt; 
			$responce->rows[$i]['PpjkNo']=$r->PpjkNo; 
			$responce->rows[$i]['PpjkTg']=$r->PpjkTg; 
			$responce->rows[$i]['IndId']=$r->IndId; 
			$responce->rows[$i]['IndNpwp']=$r->IndNpwp; 
			$responce->rows[$i]['IndNama']=$r->IndNama; 
			$responce->rows[$i]['IndAlmt']=$r->IndAlmt; 
			$responce->rows[$i]['Moda']=$r->Moda; 
			$responce->rows[$i]['AngkutNama']=$r->AngkutNama; 
			$responce->rows[$i]['AngkutNo']=$r->AngkutNo; 
			$responce->rows[$i]['AngkutFl']=$r->AngkutFl; 
			$responce->rows[$i]['PelBkr']=$r->PelBkr; 
			$responce->rows[$i]['PelMuat']=$r->PelMuat; 
			$responce->rows[$i]['PelTransit']=$r->PelTransit; 
			$responce->rows[$i]['BC23No']=$r->BC23No; 
			$responce->rows[$i]['BC23Tg']=$r->BC23Tg; 
			$responce->rows[$i]['KdKpbcBongkar']=$r->KdKpbcBongkar; 
			$responce->rows[$i]['KdKpbcAwas']=$r->KdKpbcAwas; 
			$responce->rows[$i]['DokTupKd']=$r->DokTupKd; 
			$responce->rows[$i]['DokTupNo']=$r->DokTupNo; 
			$responce->rows[$i]['DokTupTg']=$r->DokTupTg; 
			$responce->rows[$i]['PosNo']=$r->PosNo; 
			$responce->rows[$i]['PosSub']=$r->PosSub; 
			$responce->rows[$i]['TmpTbn']=$r->TmpTbn; 
			$responce->rows[$i]['KdVal']=$r->KdVal; 
			$responce->rows[$i]['Ndpbm']=$r->Ndpbm; 
			$responce->rows[$i]['NilInv']=$r->NilInv; 
			$responce->rows[$i]['Freight']=$r->Freight; 
			$responce->rows[$i]['BTambahan']=$r->BTambahan; 
			$responce->rows[$i]['Diskon']=$r->Diskon; 
			$responce->rows[$i]['KdAss']=$r->KdAss; 
			$responce->rows[$i]['Asuransi']=$r->Asuransi; 
			$responce->rows[$i]['KdHrg']=$r->KdHrg; 
			$responce->rows[$i]['Fob']=$r->Fob; 
			$responce->rows[$i]['Cif']=$r->Cif; 
			$responce->rows[$i]['Bruto']=$r->Bruto; 
			$responce->rows[$i]['Netto']=$r->Netto; 
			$responce->rows[$i]['JmCont']=$r->JmCont; 
			$responce->rows[$i]['JmBrg']=$r->JmBrg; 
			$responce->rows[$i]['TglTtd']=$r->TglTtd; 
			$responce->rows[$i]['KotaTtd']=$r->KotaTtd; 
			$responce->rows[$i]['Namattd']=$r->Namattd; 
			$responce->rows[$i]['ContakPerson']=$r->ContakPerson; 
			$responce->rows[$i]['NoPhone']=$r->NoPhone; 
			$responce->rows[$i]['NoFax']=$r->NoFax; 
			$responce->rows[$i]['Email']=$r->Email; 
			$responce->rows[$i]['Status']=$status;//$r->Status; 
			$responce->rows[$i]['Snrf']=$r->Snrf; 
			$responce->rows[$i]['Lengkap']=$r->Lengkap; 
			$responce->rows[$i]['PosSubSub']=$r->PosSubSub; 
			$responce->rows[$i]['NoKontrak']=$r->NoKontrak; 
			$responce->rows[$i]['TgKontrak']=$r->TgKontrak; 
			$responce->rows[$i]['HargaRp']=$r->HargaRp; 
			$responce->rows[$i]['TmpPeriksaFisik']=$r->TmpPeriksaFisik; 
			$responce->rows[$i]['AlmtPeriksaFisik']=$r->AlmtPeriksaFisik; 
			$responce->rows[$i]['TgPeriksaFisik']=$r->TgPeriksaFisik; 
			$responce->rows[$i]['WkPeriksaFisik']=$r->WkPeriksaFisik; 
			$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]['noinv']=$r->noinv; 
			$responce->rows[$i]['tglinv']=$r->tglinv;
			$responce->rows[$i]['inv_hdr_id']=$r->inv_hdr_id;
			$responce->rows[$i]['nobl']=$r->nobl;
			$responce->rows[$i]['tglbl']=$r->tglbl;
			$responce->rows[$i]['bc_in_from_in']=$r->bc_in_from_in;
			$i++;
		}
		echo json_encode($responce);
		
	}
	
	function view_bc271_nonhib(){
		$q = $this->db->query("
			SELECT     v_nonhib_inv_dtl.INVOICE_NO, v_nonhib_inv_dtl.partnumberx, tbl_data_part_hs.part_no, v_nonhib_inv_dtl.VENDOR, tbl_data_supplier.supplier_country
			FROM         v_nonhib_inv_dtl LEFT OUTER JOIN
								  tbl_data_supplier ON v_nonhib_inv_dtl.VENDOR = tbl_data_supplier.subcode_as400 LEFT OUTER JOIN
								  tbl_data_part_hs ON replace(v_nonhib_inv_dtl.partnumberx, CHAR(32), '') = tbl_data_part_hs.part_no2
			where tbl_data_part_hs.part_no is null and tbl_data_supplier.supplier_country= 'ID'
			GROUP BY v_nonhib_inv_dtl.INVOICE_NO, v_nonhib_inv_dtl.partnumberx, tbl_data_part_hs.part_no, v_nonhib_inv_dtl.VENDOR, tbl_data_supplier.supplier_country


		");
		$rs = $q->result_array();
		$datanull='';
		foreach ($rs as $row){
			$datanull.=$row['INVOICE_NO'].'|';		
		}
		if ($datanull != ''){
			$data["test"] = 'Part Number di Data Part HS Not Match Di Invoice Berikut, Silahkan Cek Di View Data : ' . $datanull;
		} else {
			$data["test"]=$datanull;
		}
		$this->load->view('exim/view_bc271_nonhib', $data);
	}
	
	function loaddata_bc271_nonhib(){
		$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_nonhib_hdr'; // get index row - i.e. user click to sort
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		//$where = " 1=1 and tbl_data_supplier.supplier_country='ID' ";
		$where = " 1=1  ";
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){
					
					if ( $k->field == "noinv" ) {
						$searchString = $k->data;
						$where .= " and noinv like  '%".$searchString."%'"; 
					} else if ( $k->field == "tglinv" ) {
						$searchString = $k->data;
						$where .= " and tglinv  =  '$searchString'"; 
					} else if ( $k->field == "vendor" ) {
						$searchString = $k->data;
						$where .= " and vendor like  '%".$searchString."%'"; 
					}  else if ( $k->field == "status" ) {
						$searchString = $k->data;
						if($searchString !=''){
							$where .= " and status =  '$searchString' "; 
						} else { 
							$where .= "  and status =  'New' ";  
						}
						if ($searchString=='2'){
							$where = ' 1=1 ';
						}
					} 
				}
			}
		} else {
			$where .= " and status='new'  ";
		}
		
				
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc27->bc271datanonhibhdrAll($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_bc27->bc271datanonhibhdrcountAll($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){
			if ($r->status == 0){ $stat = "New"; } else { $stat = "Not New"; };
			if ($r->tgbl == '2000-10-23'){ $tgbl = ""; } else { $tgbl = $r->tgbl; };	
				
			$responce->rows[$i]['id_nonhib_hdr']=$r->id_nonhib_hdr; 
			$responce->rows[$i]['from_file_name']=$r->from_file_name; 
			$responce->rows[$i]['totalitemfile']=$r->totalitemfile; 
			$responce->rows[$i]['exec_date']=$r->exec_date;
			$responce->rows[$i]['status']= $r->status;
			$responce->rows[$i]['itemcount']=$r->itemcount;
			$responce->rows[$i]['noinv']=$r->noinv;
			$responce->rows[$i]['tglinv']=$r->tglinv;
			$responce->rows[$i]['tglinv2']=$r->tglinv2;
			$responce->rows[$i]['nobl']=trim($r->nobl);
			$responce->rows[$i]['tgbl']=$tgbl;
			$responce->rows[$i]['vendor']=$r->vendor;
			$i++;
		}
		echo json_encode($responce);
	}
	
	function view_bc271_nonhibaddnoajudata(){
		
		$this->load->view('exim/view_bc271_nonhibaddnoajudata');
		
	}
	function loaddata_groupinv_nonhib(){
		$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_nonhib_hdr'; // get index row - i.e. user click to sort
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		//$where = " status='new' ";
		$nobl = (isset($_POST['nobl']) && !empty($_POST['nobl']))?$_POST['nobl']:'';
		$tgbl = (isset($_POST['tgbl']) && !empty($_POST['tgbl']))?$_POST['tgbl']:'';
		
		
		//$where = " a.status_inv=0 ";
		$where = " 1=1 ";
		$where .= " and nobl =  '".$nobl."'";
		$where .= " and tgbl =  '".$tgbl."'";
		
			
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc27->bc271datanonhibhdrAll($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_bc27->bc271datanonhibhdrcountAll($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){
			if ($r->status == 0){ $stat = "New"; } else { $stat = "Not New"; };
			if ($r->tgbl =='1900-10-23'){ $tgbl = ""; } else { $tgbl = $r->tgbl; };	

			 if ($r->status == 'new'){
					  $status = 'INVOICE NEW ADDED';
			} else if ($r->status == 'DATA PROCESSED'){
				 $status = 'DATA ALREADY PROCESSED';
			}	
			
			if ($r->status == 'new'){
					  $statusx = 0;
			} else {
				 $statusx = 1;
			}	
			
			$responce->rows[$i]['id_nonhib_hdr']=$r->id_nonhib_hdr; 
			$responce->rows[$i]['from_file_name']=$r->from_file_name; 
			$responce->rows[$i]['totalitemfile']=$r->totalitemfile; 
			$responce->rows[$i]['exec_date']=$r->exec_date;
			$responce->rows[$i]['status']= $status;//$r->status;
			$responce->rows[$i]['itemcount']=$r->itemcount;
			$responce->rows[$i]['noinv']=$r->noinv;
			$responce->rows[$i]['tglinv']=$r->tglinv;
			$responce->rows[$i]['tglinv2']=$r->tglinv2;
			$responce->rows[$i]['nobl']=$r->nobl;
			$responce->rows[$i]['tgbl']=$r->tgbl;
			$responce->rows[$i]['statusx']=$statusx;
			$i++;
		}
		echo json_encode($responce);
	
	}
	
	function prosesgroupinv_nonhib(){
		
		$datadiff = (isset($_POST['datadiff']) && !empty($_POST['datadiff']))?$_POST['datadiff']:die('{"sts":"ERROR","desc":" Data  Tidak Ditemukan"}'); 
		$datadiff=json_decode($datadiff);
		$datacsv = '';
		$databl = '';
		foreach ($datadiff as $data ){
		    $inv_hdr_id = (isset($data->id_nonhib_hdr) && !empty($data->id_nonhib_hdr ))?$data->id_nonhib_hdr :die('{"sts":"ERROR","desc":" Param inv_hdr_id Tidak Ditemukan"}');
			$invno = (isset($data->noinv) && !empty($data->noinv ))?$data->noinv :die('{"sts":"ERROR","desc":" Param invno Tidak Ditemukan"}');
			$tglinv = (isset($data->tglinv) && !empty($data->tglinv ))?$data->tglinv :die('{"sts":"ERROR","desc":" Param invno Tidak Ditemukan"}');
			$nobl= (isset($data->nobl) && !empty($data->nobl ))?$data->nobl :'';
			$tgbl= (isset($data->tgbl) && !empty($data->tgbl ))?$data->tgbl :'';
			$datacsv .= $inv_hdr_id . ',' . $invno . ',' .$tglinv; 
			$datacsv .= "|";
			$databl .=  $nobl;
		}
		
		if ($databl != ''){
			$responce = array("sts" => '00', "desc" => 'Data Dok Group sudah ada, Mohon periksa kembali datanya atau lakukan cancel utk Group Ulang');
			echo json_encode($responce);
			die();
		}
		//echo $datacsv;	die();
	    //var_dump($datadiff); die();
		$datacsv=substr($datacsv, 0, strlen($datacsv) - 1); 
		//echo $datacsv; die();
		
		$qry = $this->db->query("
		
			 EXEC ('sp_groupinv_bc271 @datadiff=''$datacsv'', @cmd=''proses''   ') 
			
		 ");
		 $rs = $qry->result_array();
        // $r = $qry->result();		
		// var_dump($r);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
		
	
	}
	
	function cancelgroupinv_nonhib(){
		$datadiff = (isset($_POST['datadiff']) && !empty($_POST['datadiff']))?$_POST['datadiff']:die('{"sts":"ERROR","desc":" Data  Tidak Ditemukan"}'); 
		
		$datadiff=json_decode($datadiff);
		$datacsv = '';
		foreach ($datadiff as $data ){
			$datacsv .= $data->id_nonhib_hdr . ',' . $data->noinv . ',' . '-' . ',' . '1900-10-23'; 
			$datacsv .= "|";
		}
		$datacsv=substr($datacsv, 0, strlen($datacsv) - 1); 
		 // echo $datacsv;	
		//var_dump($datadiff); die();
		// echo "
		
			 // EXEC ('spu_nonhib_bl @datadiff=''$datacsv'', @nobl=''$nobl'', @tgbl=''$tgbl'' ') 
			
		 // ";
		 // die();
		 
		$qry = $this->db->query("
			BEGIN TRY
			 EXEC ('sp_groupinv_bc271 @datadiff=''$datacsv'',@cmd=''cancel'' ') 
			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){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	}
	
	function view_bc271_nonhibprosesinsertinv(){
		$nobl = (isset($_POST['nobl']) or !empty($_POST['nobl']))?$_POST['nobl']:die('{"sts":"ERROR","desc":" Param nobl Tidak Ditemukan"}');
		$tgbl = (isset($_POST['tgbl']) or !empty($_POST['tgbl']))?$_POST['tgbl']:die('{"sts":"ERROR","desc":" Param tgbl Tidak Ditemukan"}');
		$data["tgbl"] = $tgbl;
		$data["nobl"] = $nobl;
		
		$this->load->view('exim/view_bc271_nonhibprosesinsertinv', $data);
	
	}
	
	function listinvbl_nonhib_proses(){
	
	
	
	
	}
	
	function updatestatusproses_nonhib(){
		$datanoinv = (isset($_POST['noinv']) or !empty($_POST['noinv']))?$_POST['noinv']:die('{"sts":"ERROR","desc":" Param INV Tidak Ditemukan"}');
		$nobl = (isset($_POST['nobl']) or !empty($_POST['nobl']))?$_POST['nobl']:die('{"sts":"ERROR","desc":" Param nobl Tidak Ditemukan"}');
		$tgbl= (isset($_POST['tgbl']) or !empty($_POST['tgbl']))?$_POST['tgbl']:die('{"sts":"ERROR","desc":" Param tg bl Tidak Ditemukan"}');
		$typebc = 'BC271';
		$datanoinv=json_decode($datanoinv);
		$datacsv = '';
		foreach ($datanoinv as $data ){
			$datacsv .= $data->id_nonhib_hdr . ',' . trim($data->noinv); 
			$datacsv .= "|";
		}
		// echo $datacsv;	
		// var_dump($datanoinv); die();
		$datacsv = substr($datacsv, 0,  strlen($datacsv) -1); 
		//echo "EXEC [sp_nonhib_insert] @datanoinv ='$datacsv', @typebc='$typebc', @tgbl='$tgbl', @nobl='$nobl' "; die();
		$qry = $this->db->query("
			
			EXEC [sp_nonhib_insert] @datanoinv ='$datacsv', @typebc='$typebc', @tgbl='$tgbl', @nobl='$nobl' 
		
		");
		$rs = $qry->result_array();	
		// var_dump($rs);
		// die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	}
	
	function recalculate_new_inv_bl_nonhib(){
		$typebc = 'BC271';
		$noinv = (isset($_POST['noinv']) && !empty($_POST['noinv']))?$_POST['noinv']:die('{"sts":"ERROR","desc":" Param INV Tidak Ditemukan"}');
		$nobl = (isset($_POST['nobl']) && !empty($_POST['nobl']))?$_POST['nobl']:die('{"sts":"ERROR","desc":" Param nobl Tidak Ditemukan"}');
		$tgbl= (isset($_POST['tgbl']) && !empty($_POST['tgbl']))?$_POST['tgbl']:die('{"sts":"ERROR","desc":" Param tg bl Tidak Ditemukan"}');
		
		$noinv=json_decode($noinv);
		
		$noinvcsv = '';
		foreach ($noinv as $data ){
			if ($data->statusx == 0){
				$id_nonhib_hdr = (isset($data->id_nonhib_hdr) && !empty($data->id_nonhib_hdr ))?$data->id_nonhib_hdr :die('{"sts":"ERROR","desc":" Param id_nonhib_hdr Tidak Ditemukan"}');
				$invno = (isset($data->noinv) && !empty($data->noinv ))?$data->noinv :die('{"sts":"ERROR","desc":" Param noinv Tidak Ditemukan"}');
				$noinvcsv .= $id_nonhib_hdr. ',' . $invno; 
				$noinvcsv .= "|";
			}
		}
		$listinv = substr($noinvcsv, 0,  strlen($noinvcsv) -1); 
		// echo "
			// EXEC [sp_nonhib_insertcb23_recalculate_new_inv_bl] @nobl = N'$nobl', @tgbl = '$tgbl', @typebc = N'$typebc',@noinv = '$listinv'
		// ";
		// var_dump($noinv); die();
		 // die();
		$qry = $this->db->query("
			
			EXEC [sp_nonhib_insertcb23_recalculate_new_inv_bl] @nobl = N'$nobl', @tgbl = '$tgbl', @typebc = N'$typebc',@noinv = '$listinv'
			
		");
		$rs = $qry->result_array();	
		// var_dump($rs);
		// die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
		
	}
	
	function view_bc271_dtl(){
		$idhdrbc271 = (isset($_POST['idhdrbc271']) && !empty($_POST['idhdrbc271']))?$_POST['idhdrbc271']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$inv_hdr_idbc271 = (isset($_POST['inv_hdr_idbc271']) && !empty($_POST['inv_hdr_idbc271']))?$_POST['inv_hdr_idbc271']:'lihat doc';
		$noinv  = (isset($_POST['noinv']) && !empty($_POST['noinv']))?$_POST['noinv']:'lihat doc';
		$car= (isset($_POST['car']) && !empty($_POST['car']))?$_POST['car']:'-';
		$gabinv  = (isset($_POST['gabinv']) && !empty($_POST['gabinv']))?$_POST['gabinv']:'lihat doc';
		$tglgabinv  = (isset($_POST['tglgabinv']) && !empty($_POST['tglgabinv']))?$_POST['tglgabinv']:'lihat doc';
		$DokTupTg  = (isset($_POST['DokTupTg']) && !empty($_POST['DokTupTg']))?$_POST['DokTupTg']:'';
		$BC23No  = (isset($_POST['BC23No']) && !empty($_POST['BC23No']))?$_POST['BC23No']:'';
		$BC23Tg  = (isset($_POST['BC23Tg']) && !empty($_POST['BC23Tg']))?$_POST['BC23Tg']:'';
		
		
		$data["idhdrbc271"] = $idhdrbc271; 
		$data["inv_hdr_idbc271"] = $inv_hdr_idbc271; 
		$data["noinv"] = $noinv;
		$data["car"] = $car;
		$data["gabinv"] = $gabinv;
		$data["tglgabinv"] = $tglgabinv;
		$data["DokTupTg"] = $DokTupTg;
		$data["BC23No"] = $BC23No;
		$data["BC23Tg"] = $BC23Tg;
		
		$this->load->view('exim/view_bc271_dtl', $data);
	
	}
	
	function loaddataheader(){
		$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'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		$idy = (isset($_POST['idhdrbc271']) or !empty($_POST['idhdrbc271']))?$_POST['idhdrbc271']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$where = " id_bc_in_hdr=$idy ";
		
				
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc23->bc23hdrdataAll($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_bc23->bc23hdrdataCountAll($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){
			if($r->Status == null){
				$status = 'New';
				
			} else { $status=$r->Status;  }
			
			$responce->rows[$i]['id_bc_in_hdr']=$r->id_bc_in_hdr; 
			$responce->rows[$i]['CAR']=$r->CAR; 
			$responce->rows[$i]['KdKpbc']=$r->KdKpbc; 
			$responce->rows[$i]['Tujuan']=$r->Tujuan; 
			$responce->rows[$i]['JnsBarang']=$r->JnsBarang; 
			$responce->rows[$i]['TujuanKirim']=$r->TujuanKirim; 
			$responce->rows[$i]['PasokNama']=$r->PasokNama; 
			$responce->rows[$i]['PasokAlmt']=$r->PasokAlmt; 
			$responce->rows[$i]['PasokNeg']=$r->PasokNeg; 
			$responce->rows[$i]['UsahaId']=$r->UsahaId; 
			$responce->rows[$i]['UsahaNpwp']=$r->UsahaNpwp; 
			$responce->rows[$i]['KdTPB']=$r->KdTPB; 
			$responce->rows[$i]['Registrasi']=$r->Registrasi; 
			$responce->rows[$i]['UsahaNama']=$r->UsahaNama; 
			$responce->rows[$i]['UsahaAlmt']=$r->UsahaAlmt; 
			$responce->rows[$i]['UsahaStatus']=$r->UsahaStatus; 
			$responce->rows[$i]['ApiKd']=$r->ApiKd; 
			$responce->rows[$i]['ApiNo']=$r->ApiNo; 
			$responce->rows[$i]['PpjkId']=$r->PpjkId; 
			$responce->rows[$i]['PpjkNpwp']=$r->PpjkNpwp; 
			$responce->rows[$i]['PpjkNama']=$r->PpjkNama; 
			$responce->rows[$i]['PpjkAlmt']=$r->PpjkAlmt; 
			$responce->rows[$i]['PpjkNo']=$r->PpjkNo; 
			$responce->rows[$i]['PpjkTg']=$r->PpjkTg; 
			$responce->rows[$i]['IndId']=$r->IndId; 
			$responce->rows[$i]['IndNpwp']=$r->IndNpwp; 
			$responce->rows[$i]['IndNama']=$r->IndNama; 
			$responce->rows[$i]['IndAlmt']=$r->IndAlmt; 
			$responce->rows[$i]['Moda']=$r->Moda; 
			$responce->rows[$i]['AngkutNama']=$r->AngkutNama; 
			$responce->rows[$i]['AngkutNo']=$r->AngkutNo; 
			$responce->rows[$i]['AngkutFl']=$r->AngkutFl; 
			$responce->rows[$i]['PelBkr']=$r->PelBkr; 
			$responce->rows[$i]['PelMuat']=$r->PelMuat; 
			$responce->rows[$i]['PelTransit']=$r->PelTransit; 
			$responce->rows[$i]['BC23No']=$r->BC23No; 
			$responce->rows[$i]['BC23Tg']=$r->BC23Tg; 
			$responce->rows[$i]['KdKpbcBongkar']=$r->KdKpbcBongkar; 
			$responce->rows[$i]['KdKpbcAwas']=$r->KdKpbcAwas; 
			$responce->rows[$i]['DokTupKd']=$r->DokTupKd; 
			$responce->rows[$i]['DokTupNo']=$r->DokTupNo; 
			$responce->rows[$i]['DokTupTg']=$r->DokTupTg; 
			$responce->rows[$i]['PosNo']=$r->PosNo; 
			$responce->rows[$i]['PosSub']=$r->PosSub; 
			$responce->rows[$i]['TmpTbn']=$r->TmpTbn; 
			$responce->rows[$i]['KdVal']=$r->KdVal; 
			$responce->rows[$i]['Ndpbm']=$r->Ndpbm; 
			$responce->rows[$i]['NilInv']=$r->NilInv; 
			$responce->rows[$i]['Freight']=$r->Freight; 
			$responce->rows[$i]['BTambahan']=$r->BTambahan; 
			$responce->rows[$i]['Diskon']=$r->Diskon; 
			$responce->rows[$i]['KdAss']=$r->KdAss; 
			$responce->rows[$i]['Asuransi']=$r->Asuransi; 
			$responce->rows[$i]['KdHrg']=$r->KdHrg; 
			$responce->rows[$i]['Fob']=$r->Fob; 
			$responce->rows[$i]['Cif']=$r->Cif; 
			$responce->rows[$i]['Bruto']=$r->Bruto; 
			$responce->rows[$i]['Netto']=$r->Netto; 
			$responce->rows[$i]['JmCont']=$r->JmCont; 
			$responce->rows[$i]['JmBrg']=$r->JmBrg; 
			$responce->rows[$i]['TglTtd']=$r->TglTtd; 
			$responce->rows[$i]['KotaTtd']=$r->KotaTtd; 
			$responce->rows[$i]['Namattd']=$r->Namattd; 
			$responce->rows[$i]['ContakPerson']=$r->ContakPerson; 
			$responce->rows[$i]['NoPhone']=$r->NoPhone; 
			$responce->rows[$i]['NoFax']=$r->NoFax; 
			$responce->rows[$i]['Email']=$r->Email; 
			$responce->rows[$i]['Status']=$status;//$r->Status; 
			$responce->rows[$i]['Snrf']=$r->Snrf; 
			$responce->rows[$i]['Lengkap']=$r->Lengkap; 
			$responce->rows[$i]['PosSubSub']=$r->PosSubSub; 
			$responce->rows[$i]['NoKontrak']=$r->NoKontrak; 
			$responce->rows[$i]['TgKontrak']=$r->TgKontrak; 
			$responce->rows[$i]['HargaRp']=$r->HargaRp; 
			$responce->rows[$i]['TmpPeriksaFisik']=$r->TmpPeriksaFisik; 
			$responce->rows[$i]['AlmtPeriksaFisik']=$r->AlmtPeriksaFisik; 
			$responce->rows[$i]['TgPeriksaFisik']=$r->TgPeriksaFisik; 
			$responce->rows[$i]['WkPeriksaFisik']=$r->WkPeriksaFisik; 
			$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]['noinv']=$r->noinv; 
			$responce->rows[$i]['tglinv']=$r->tglinv;
			$responce->rows[$i]['inv_hdr_id']=$r->inv_hdr_id;
			
			$i++;
		}
		echo json_encode($responce);
		
	}
	
	
	function loaddata_bc271_dtl(){
		$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'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$idhdr = (isset($_POST['idhdrbc271']) && !empty($_POST['idhdrbc271']))?$_POST['idhdrbc271']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		$where = " id_bc_in_hdr=$idhdr ";
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc23->bc23detildataAll($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_bc23->bc23detildataCountAll($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_in_dtl']=$r->id_bc_in_dtl; 
			$responce->rows[$i]['id_bc_in_hdr']=$r->id_bc_in_hdr; 
			$responce->rows[$i]['CAR']=$r->CAR; 
			$responce->rows[$i]['Serial']=$r->Serial; 
			$responce->rows[$i]['JnsBarangDtl']=$r->JnsBarangDtl; 
			$responce->rows[$i]['TujuanKirimDtl']=$r->TujuanKirimDtl; 
			$responce->rows[$i]['NoHs']=$r->NoHs; 
			$responce->rows[$i]['SeriTrp']=$r->SeriTrp; 
			$responce->rows[$i]['BrgUrai']=$r->BrgUrai; 
			$responce->rows[$i]['Merk']=$r->Merk; 
			$responce->rows[$i]['Tipe']=$r->Tipe; 
			$responce->rows[$i]['SpfLain']=$r->SpfLain; 
			$responce->rows[$i]['KdBrg']=$r->KdBrg; 
			$responce->rows[$i]['Penggunaan']=$r->Penggunaan; 
			$responce->rows[$i]['KemasJn']=$r->KemasJn;
			$responce->rows[$i]['KemasJm']=$r->KemasJm;
			$responce->rows[$i]['KdFasDtl']=$r->KdFasDtl;
			$responce->rows[$i]['BrgAsal']=$r->BrgAsal;
			$responce->rows[$i]['DNilInv']=$r->DNilInv;
			$responce->rows[$i]['KdSat']=$r->KdSat;
			$responce->rows[$i]['JmlSat']=$r->JmlSat;
			$responce->rows[$i]['NettoDtl']=$r->NettoDtl;
			$responce->rows[$i]['SatBmJm']=$r->SatBmJm;
			$responce->rows[$i]['SatCukJm']=$r->SatCukJm;
			$responce->rows[$i]['DtlOk']=$r->DtlOk;
			$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;
			$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']:'id'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$idhdr = (isset($_POST['idhdrbc271']) && !empty($_POST['idhdrbc271']))?$_POST['idhdrbc271']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		$where = " id_bc_in_hdr=$idhdr ";
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc23->bc23dokdataAll($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_bc23->bc23dokdataCountAll($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_in_dok']=$r->id_bc_in_dok; 
			$responce->rows[$i]['id_bc_in_hdr']=$r->id_bc_in_hdr; 
			$responce->rows[$i]['CAR']=$r->CAR; 
			$responce->rows[$i]['DokKd']=$r->DokKd; 
			$responce->rows[$i]['uraian']=$r->uraian; 
			$responce->rows[$i]['DokNo']=$r->DokNo; 
			$responce->rows[$i]['DokTg']=$r->DokTg; 
			
			$i++;
		}
		echo json_encode($responce);
		
	}
	function loaddatacon(){
		$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'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$idhdr = (isset($_POST['idhdrbc271']) && !empty($_POST['idhdrbc271']))?$_POST['idhdrbc271']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		$where = " id_bc_in_hdr=$idhdr ";
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc23->bc23condataAll($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_bc23->bc23condataCountAll($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_in_con']=$r->id_bc_in_con; 
			$responce->rows[$i]['id_bc_in_hdr']=$r->id_bc_in_hdr; 
			$responce->rows[$i]['CAR']=$r->CAR; 
			$responce->rows[$i]['ContNo']=$r->ContNo; 
			$responce->rows[$i]['ContUkur']=$r->ContUkur; 
			$responce->rows[$i]['ContTipe']=$r->ContTipe; 
			
			$i++;
		}
		echo json_encode($responce);
		
	}
	
	function updatenoaju_bc271(){
		$idhdrbc271 = (isset($_POST['idhdrbc271']) && !empty($_POST['idhdrbc271']))?$_POST['idhdrbc271']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$bc271noaju = (isset($_POST['bc271noaju']) && !empty($_POST['bc271noaju']))?$_POST['bc271noaju']:'';
		$bc271tglaju  = (isset($_POST['bc271tglaju']) && !empty($_POST['bc271tglaju']))?$_POST['bc271tglaju']:'';
		$bc271nobc271= (isset($_POST['bc271nobc271']) && !empty($_POST['bc271nobc271']))?$_POST['bc271nobc271']:'';
		$bc271tglbc271= (isset($_POST['bc271tglbc271']) && !empty($_POST['bc271tglbc271']))?$_POST['bc271tglbc271']:'';
		$username = $this->session->userdata('DX_username');
		
		// if ($bc271tglaju != ''){
			// $bc271tglajux = explode('/', $bc271tglaju);
			// $bc271tglaju = 	$bc271tglajux[1]. '/' . $bc271tglajux[0]. '/' . $bc271tglajux[2];
		// }
		
		// if ($bc271tglbc271 != ''){
			// $bc271tglbc271x = explode('/', $bc271tglbc271);
			// $bc271tglbc271 = 	$bc271tglbc271x[1]. '/' . $bc271tglbc271x[0]. '/' . $bc271tglbc271x[2];
		// }
		
		//echo $bc271tglaju; die();
		/* echo " exec(' spu_updatenobc271 @idbc271hdr=$idhdrbc271,@userid=''$username'', @noajubc271=''$bc271noaju'', @tgajubc271=''$bc271tglaju'', @nobc271=''$bc271nobc271'', @tglbc271=''$bc271tglbc271'' ')
			";die(); */
		
		$qry = $this->db->query("
			BEGIN TRY
			
			 exec(' spu_updatenobc271 @idbc271hdr=$idhdrbc271,@userid=''$username'', @noajubc271=''$bc271noaju'', @tgajubc271=''$bc271tglaju'', @nobc271=''$bc271nobc271'', @tglbc271=''$bc271tglbc271'' ')
			
			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_bc271_move(){
		$id_inv_hdr = (isset($_POST['inv_hdr_idbc23']) && !empty($_POST['inv_hdr_idbc23']))?$_POST['inv_hdr_idbc23']:die('{"sts":"ERROR","desc":" Param id_inv_hdr Tidak Ditemukan"}');
		$noinv = (isset($_POST['noinv']) && !empty($_POST['noinv']))?$_POST['noinv']:die('{"sts":"ERROR","desc":" Param noinv Tidak Ditemukan"}');
		$idhdrbc23 = (isset($_POST['idhdrbc23']) && !empty($_POST['idhdrbc23']))?$_POST['idhdrbc23']:die('{"sts":"ERROR","desc":" Param idhdrbc23 Tidak Ditemukan"}');
		$nobc23 = (isset($_POST['nobc23']) && !empty($_POST['nobc23']))?$_POST['nobc23']:'KOSONG';
		
		// if ($nobc23 == ""){
			// $nobc23 = 'KOSONG';
		// }
		
		$data["noinv"] = $noinv;
		$data["id_inv_hdr"] = $id_inv_hdr;
		$data["idhdrbc23"] = $idhdrbc23;
		$data["nobc23"] = $nobc23;
		
		
		
		$this->load->view('exim/view_bc271_move', $data);
	
	}
	
	function execdatabc27pasi(){
		$username = $this->session->userdata('DX_username');

		$qry = $this->db->query("
			BEGIN TRY
			 SET ANSI_NULLS ON
			 SET ANSI_WARNINGS ON
			 exec(' [sp_loadbc27pasi] @username=''$username'' ')
			
			END TRY
			BEGIN CATCH 
				SELECT 
				'error' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
			");
		 
		 $rs = $qry->result_array();
		 // $r = $qry->result();		
		 //var_dump($rs);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	}
	
	function view_bc271_loadpasi(){
		$data["x"]="x";
			
		$this->load->view('exim/view_bc271_loadpasi', $data);
	}
	
	function loaddatabc27pasi(){
		$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_bc271_hdr'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$where = " status='New' ";
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc27->bc27pasidataAll($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_bc27->bc27pasidataCountAll($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_bc271_hdr']=$r->id_bc271_hdr;
			  $responce->rows[$i]['CAR']=$r->CAR;
			  $responce->rows[$i]['KdKpbc']=$r->KdKpbc;
			  $responce->rows[$i]['KdKpbcBongkar']=$r->KdKpbcBongkar;
			  $responce->rows[$i]['KdKpbcAwas']=$r->KdKpbcAwas;
			  $responce->rows[$i]['PasokNama']=$r->PasokNama;
			  $responce->rows[$i]['PasokAlmt1']=$r->PasokAlmt1;
			  $responce->rows[$i]['Moda']=$r->Moda;
			  $responce->rows[$i]['KdVal']=$r->KdVal;
			  $responce->rows[$i]['Cif']=$r->Cif;
			  $responce->rows[$i]['Bruto']=$r->Bruto;
			  $responce->rows[$i]['Netto']=$r->Netto;
			  $responce->rows[$i]['NilSerah']=$r->NilSerah;
			  $responce->rows[$i]['Nodaf']=$r->Nodaf;
			  $responce->rows[$i]['Tgldaf']=$r->Tgldaf;
			  $responce->rows[$i]['UsahaNama']=$r->UsahaNama;
			  $responce->rows[$i]['UsahaNPWP']=$r->UsahaNPWP;
			  $responce->rows[$i]['UsahaAlamat1']=$r->UsahaAlamat1;
			  $responce->rows[$i]['UsahaAlamat2']=$r->UsahaAlamat2;
			  $responce->rows[$i]['UsahaSkep']=$r->UsahaSkep;
			  $responce->rows[$i]['PasokAlmt2']=$r->PasokAlmt2;
			  $responce->rows[$i]['PasokSkep']=$r->PasokSkep;
			  $responce->rows[$i]['PasokNPWP']=$r->PasokNPWP;
			  $responce->rows[$i]['NoInvoice']=$r->NoInvoice;
			  $responce->rows[$i]['TgInvoice']=$r->TgInvoice;
			  $responce->rows[$i]['NoPackinglist']=$r->NoPackinglist;
			  $responce->rows[$i]['TgPackinglist']=$r->TgPackinglist;
			  $responce->rows[$i]['NoKontrak']=$r->NoKontrak;
			  $responce->rows[$i]['TgKontrak']=$r->TgKontrak;
			  $responce->rows[$i]['SuratJalan']=$r->SuratJalan;
			  $responce->rows[$i]['TgSuratjalan']=$r->TgSuratjalan;
			  $responce->rows[$i]['SuratKep']=$r->SuratKep;
			  $responce->rows[$i]['TgSuratKep']=$r->TgSuratKep;
			  $responce->rows[$i]['SuratLain']=$r->SuratLain;
			  $responce->rows[$i]['TgSuratLain']=$r->TgSuratLain;
			  $responce->rows[$i]['NoBc27Asal']=$r->NoBc27Asal;
			  $responce->rows[$i]['TgBc27Asal']=$r->TgBc27Asal;
			  $responce->rows[$i]['Nopol']=$r->Nopol;
			  $responce->rows[$i]['MrkNoKms']=$r->MrkNoKms;
			  $responce->rows[$i]['JmlJnsKms']=$r->JmlJnsKms;
			  $responce->rows[$i]['NoSeg']=$r->NoSeg;
			  $responce->rows[$i]['CtBcTuj1']=$r->CtBcTuj1;
			  $responce->rows[$i]['CtBcTuj2']=$r->CtBcTuj2;
			  $responce->rows[$i]['Volume']=$r->Volume;
			  $responce->rows[$i]['Tgl_Keluar']=$r->Tgl_Keluar;
			  $responce->rows[$i]['No_Keluar']=$r->No_Keluar;
			  $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]['status']=$r->status;
			  $responce->rows[$i]['id_bc271_hdr_pasi']=$r->id_bc271_hdr_pasi;
			
			$i++;
		}
		echo json_encode($responce);
	}
	
	function loaddatabc27pasi_dtl(){
		$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_bc271_detail'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$idhdrbc271 = (isset($_POST['id_bc271_hdr']) && !empty($_POST['id_bc271_hdr']))?$_POST['id_bc271_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$where = " id_bc271_hdr=$idhdrbc271 ";
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc27->bc27pasi_dtl_dataAll($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_bc27->bc27pasi_dtl_dataCountAll($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_bc271_detail']=$r->id_bc271_detail;
			  $responce->rows[$i]['id_bc271_hdr']=$r->id_bc271_hdr;
			  $responce->rows[$i]['CAR']=$r->CAR;
			  $responce->rows[$i]['NoHS']=$r->NoHS;
			  $responce->rows[$i]['BrgUrai']=$r->BrgUrai;
			  $responce->rows[$i]['Merk']=$r->Merk;
			  $responce->rows[$i]['Tipe']=$r->Tipe;
			  $responce->rows[$i]['SpfLain']=$r->SpfLain;
			  $responce->rows[$i]['KdBrg']=$r->KdBrg;
			  $responce->rows[$i]['KdSat']=$r->KdSat;
			  $responce->rows[$i]['JmlSat']=$r->JmlSat;
			  $responce->rows[$i]['NettoDtl']=$r->NettoDtl;
			  $responce->rows[$i]['DSerah']=$r->DSerah;
			  $responce->rows[$i]['DVol']=$r->DVol;
			  $responce->rows[$i]['NoUrut']=$r->NoUrut;
			  $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]['Status']=$r->Status;
		
			$i++;
		}
		echo json_encode($responce);
	}
	
	function prosesdatabc27pasi(){
		$username = $this->session->userdata('DX_username');
		$id_bc271_hdr = (isset($_POST['id_bc271_hdr']) && !empty($_POST['id_bc271_hdr']))?$_POST['id_bc271_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		$qry = $this->db->query("
			BEGIN TRY
			 SET ANSI_NULLS ON
			 SET ANSI_WARNINGS ON
			 exec(' [spi_insertbc27pasi] @username=''$username'', @id_bc271_hdr=$id_bc271_hdr ')
			
			END TRY
			BEGIN CATCH 
				SELECT 
				'error' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
			");
		 
		 $rs = $qry->result_array();
		 // $r = $qry->result();		
		 //var_dump($rs);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	}
	
	function view_bc271_proses_pasi(){
		$id_bc_in_hdr = (isset($_POST['id_bc_in_hdr']) && !empty($_POST['id_bc_in_hdr']))?$_POST['id_bc_in_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$doc_in_from_id = (isset($_POST['doc_in_from_id']) && !empty($_POST['doc_in_from_id']))?$_POST['doc_in_from_id']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		$data["id_bc_in_hdr"]=$id_bc_in_hdr;
		$data["doc_in_from_id"]=$doc_in_from_id;
		$this->load->view('exim/view_bc271_proses_pasi', $data);
	}
	
	function prosesdatabc27pasi_in(){
		$id_bc_in_hdr = (isset($_POST['id_bc_in_hdr']) && !empty($_POST['id_bc_in_hdr']))?$_POST['id_bc_in_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$doc_in_from_id = (isset($_POST['doc_in_from_id']) && !empty($_POST['doc_in_from_id']))?$_POST['doc_in_from_id']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$uid = $this->session->userdata('DX_username');
		
				
		$qry = $this->db->query("
			BEGIN TRY
			SET ANSI_NULLS ON
			SET ANSI_WARNINGS ON
			 exec(' [spi_incoming_bc27pasi] @id_hdr=$id_bc_in_hdr, @doc_in_from_id=$doc_in_from_id, @username=''$uid'' ')
			
			END TRY
			BEGIN CATCH 
				SELECT 
				'error' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
			");
		 
		 $rs = $qry->result_array();
		 // $r = $qry->result();		
		 //var_dump($rs);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	}
	
	function prosesdatabc27pasi_out(){
		$id_bc_in_hdr = (isset($_POST['id_bc_in_hdr']) && !empty($_POST['id_bc_in_hdr']))?$_POST['id_bc_in_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$doc_in_from_id = (isset($_POST['doc_in_from_id']) && !empty($_POST['doc_in_from_id']))?$_POST['doc_in_from_id']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$uid = $this->session->userdata('DX_username');
		
		$q = $this->db->query("
			SELECT [id_data_in_hdr] FROM [dbo].[tbl_data_in_hdr]
				where id_terkait =$id_bc_in_hdr
		");
		$rs = $q->result_array();
		
		$id_data_in_hdr='';
		foreach ($rs as $row){
			$id_data_in_hdr=$row['id_data_in_hdr'];		
		}
		if ($id_data_in_hdr == ''){
			die('{"sts":"ERROR","desc":" Data In Param Tidak Ditemukan"}');	
		}
		
		$qry = $this->db->query("
			BEGIN TRY
			SET ANSI_NULLS ON
			SET ANSI_WARNINGS ON
			 exec(' [spi_incoming_bc27pasi_out] @id_data_in_hdr=$id_data_in_hdr, @user=''$uid'' ')
			
			END TRY
			BEGIN CATCH 
				SELECT 
				'error' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
			");
		 
		 $rs = $qry->result_array();
		 // $r = $qry->result();		
		 //var_dump($rs);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	}
	
	
	function prosesdatabc27pasi_in_out(){
		$id_bc_in_hdr = (isset($_POST['id_bc_in_hdr']) && !empty($_POST['id_bc_in_hdr']))?$_POST['id_bc_in_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$doc_in_from_id = (isset($_POST['doc_in_from_id']) && !empty($_POST['doc_in_from_id']))?$_POST['doc_in_from_id']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		$uid = $this->session->userdata('DX_username');
		
				
		$qry = $this->db->query("
			BEGIN TRY
			SET ANSI_NULLS ON
			SET ANSI_WARNINGS ON
			 exec(' [spi_incoming_bc27pasi] @id_hdr=$id_bc_in_hdr, @doc_in_from_id=$doc_in_from_id, @username=''$uid'' ')
			
			END TRY
			BEGIN CATCH 
				SELECT 
				'error' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
			");
		 
		 $rs = $qry->result_array();
		
		$q = $this->db->query("
			SELECT [id_data_in_hdr] FROM [dbo].[tbl_data_in_hdr]
				where id_terkait =$id_bc_in_hdr
		");
		$rs = $q->result_array();
		
		$id_data_in_hdr='';
		foreach ($rs as $row){
			$id_data_in_hdr=$row['id_data_in_hdr'];		
		}
		if ($id_data_in_hdr == ''){
			die('{"sts":"ERROR","desc":" Data In Param Tidak Ditemukan"}');	
		}
		$qry = $this->db->query("
			BEGIN TRY
			SET ANSI_NULLS ON
			SET ANSI_WARNINGS ON
			 exec(' [spi_incoming_bc27pasi_out] @id_data_in_hdr=$id_data_in_hdr, @user=''$uid'' ')
			
			END TRY
			BEGIN CATCH 
				SELECT 
				'error' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
			");
		 
		 $rs = $qry->result_array();
		 // $r = $qry->result();		
		 //var_dump($rs);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	}
	
	
	function viewformbc27hdr_print(){
		
		
		
	/* 	$car=(isset($_GET['car']) && !empty($_GET['car']))?$_GET['car']:die('{"sts":"ERROR","desc":" 1 Param Tidak Ditemukan"}');	
		$KdKpbc=(isset($_GET['KdKpbc']) && !empty($_GET['KdKpbc']))?$_GET['KdKpbc']:die('{"sts":"ERROR","desc":" 3 Param Tidak Ditemukan"}');
		$KdKpbcBongkar=(isset($_GET['KdKpbcBongkar']) && !empty($_GET['KdKpbcBongkar']))?$_GET['KdKpbcBongkar']:die('{"sts":"ERROR","desc":" 4 Param Tidak Ditemukan"}');
		$KdKpbcAwas=(isset($_GET['KdKpbcAwas']) && !empty($_GET['KdKpbcAwas']))?$_GET['KdKpbcAwas']:die('{"sts":"ERROR","desc":" 5 Param Tidak Ditemukan"}');
		$PasokNama=(isset($_GET['PasokNama']) && !empty($_GET['PasokNama']))?$_GET['PasokNama']:die('{"sts":"ERROR","desc":" 6 Param Tidak Ditemukan"}');
		$PasokAlmt1=(isset($_GET['PasokAlmt1']) && !empty($_GET['PasokAlmt1']))?$_GET['PasokAlmt1']:die('{"sts":"ERROR","desc":" 7 Param Tidak Ditemukan"}');
		$Moda=(isset($_GET['Moda']) && !empty($_GET['Moda']))?$_GET['Moda']:die('{"sts":"ERROR","desc":" 8 Param Tidak Ditemukan"}');
		$KdVal=(isset($_GET['KdVal']) && !empty($_GET['KdVal']))?$_GET['KdVal']:die('{"sts":"ERROR","desc":" 9 Param Tidak Ditemukan"}');
		$Cif=(isset($_GET['Cif']) && !empty($_GET['Cif']))?$_GET['Cif']:die('{"sts":"ERROR","desc":" 10 Param Tidak Ditemukan"}');
		$Bruto=(isset($_GET['Bruto']) && !empty($_GET['Bruto']))?$_GET['Bruto']:die('{"sts":"ERROR","desc":" 11 Param Tidak Ditemukan"}');
		$Netto=(isset($_GET['Netto']) && !empty($_GET['Netto']))?$_GET['Netto']:die('{"sts":"ERROR","desc":" 12 Param Tidak Ditemukan"}');
		$NilSerah=(isset($_GET['NilSerah']) && !empty($_GET['NilSerah']))?$_GET['NilSerah']:die('{"sts":"ERROR","desc":" 13 Param Tidak Ditemukan"}');
		$Nodaf=(isset($_GET['Nodaf']) && !empty($_GET['Nodaf']))?$_GET['Nodaf']:die('{"sts":"ERROR","desc":" 14 Param Tidak Ditemukan"}');
		$Tgldaf=(isset($_GET['Tgldaf']) && !empty($_GET['Tgldaf']))?$_GET['Tgldaf']:die('{"sts":"ERROR","desc":" 15 Param Tidak Ditemukan"}');
		$UsahaNama=(isset($_GET['UsahaNama'])  &&  !empty($_GET['UsahaNama']))?$_GET['UsahaNama']:die('{"sts":"ERROR","desc":" 16 Param Tidak Ditemukan"}');
		$UsahaNPWP=(isset($_GET['UsahaNPWP'])  &&  !empty($_GET['UsahaNPWP']))?$_GET['UsahaNPWP']:die('{"sts":"ERROR","desc":" 17 Param Tidak Ditemukan"}');
		$UsahaAlamat1=(isset($_GET['UsahaAlamat1'])  &&  !empty($_GET['UsahaAlamat1']))?$_GET['UsahaAlamat1']:die('{"sts":"ERROR","desc":" 18 Param Tidak Ditemukan"}');
		$UsahaAlamat2=(isset($_GET['UsahaAlamat2'])  &&  !empty($_GET['UsahaAlamat2']))?$_GET['UsahaAlamat2']:die('{"sts":"ERROR","desc":" 19 Param Tidak Ditemukan"}');
		$UsahaSkep=(isset($_GET['UsahaSkep'])  &&  !empty($_GET['UsahaSkep']))?$_GET['UsahaSkep']:die('{"sts":"ERROR","desc":" 20 Param Tidak Ditemukan"}');
		$PasokAlmt2=(isset($_GET['PasokAlmt2'])  &&  !empty($_GET['PasokAlmt2']))?$_GET['PasokAlmt2']:die('{"sts":"ERROR","desc":" 21 Param Tidak Ditemukan"}');
		$PasokSkep=(isset($_GET['PasokSkep'])  &&  !empty($_GET['PasokSkep']))?$_GET['PasokSkep']:die('{"sts":"ERROR","desc":" 22 Param Tidak Ditemukan"}');
		$PasokNPWP=(isset($_GET['PasokNPWP'])  &&  !empty($_GET['PasokNPWP']))?$_GET['PasokNPWP']:die('{"sts":"ERROR","desc":" 23 Param Tidak Ditemukan"}');
		$NoInvoice=(isset($_GET['NoInvoice'])  &&  !empty($_GET['NoInvoice']))?$_GET['NoInvoice']:die('{"sts":"ERROR","desc":" 24 Param Tidak Ditemukan"}');
		$TgInvoice=(isset($_GET['TgInvoice'])  &&  !empty($_GET['TgInvoice']))?$_GET['TgInvoice']:die('{"sts":"ERROR","desc":" 25 Param Tidak Ditemukan"}');
		$NoPackinglist=(isset($_GET['NoPackinglist'])  &&  !empty($_GET['NoPackinglist']))?$_GET['NoPackinglist']:die('{"sts":"ERROR","desc":" 26 Param Tidak Ditemukan"}');
		$TgPackinglist=(isset($_GET['TgPackinglist'])  &&  !empty($_GET['TgPackinglist']))?$_GET['TgPackinglist']:die('{"sts":"ERROR","desc":" 27 Param Tidak Ditemukan"}');
		$NoKontrak=(isset($_GET['NoKontrak'])  &&  !empty($_GET['NoKontrak']))?$_GET['NoKontrak']:die('{"sts":"ERROR","desc":" 28 Param Tidak Ditemukan"}');
		$TgKontrak=(isset($_GET['TgKontrak'])  &&  !empty($_GET['TgKontrak']))?$_GET['TgKontrak']:die('{"sts":"ERROR","desc":" 29 Param Tidak Ditemukan"}');
		$SuratJalan=(isset($_GET['SuratJalan'])  &&  !empty($_GET['SuratJalan']))?$_GET['SuratJalan']:die('{"sts":"ERROR","desc":" 30 Param Tidak Ditemukan"}');
		$TgSuratjalan=(isset($_GET['TgSuratjalan'])  &&  !empty($_GET['TgSuratjalan']))?$_GET['TgSuratjalan']:die('{"sts":"ERROR","desc":" 31 Param Tidak Ditemukan"}');
		$SuratKep=(isset($_GET['SuratKep'])  &&  !empty($_GET['SuratKep']))?$_GET['SuratKep']:die('{"sts":"ERROR","desc":" 32 Param Tidak Ditemukan"}');
		$TgSuratKep=(isset($_GET['TgSuratKep'])  &&  !empty($_GET['TgSuratKep']))?$_GET['TgSuratKep']:die('{"sts":"ERROR","desc":" 33 Param Tidak Ditemukan"}');
		$SuratLain=(isset($_GET['SuratLain'])  &&  !empty($_GET['SuratLain']))?$_GET['SuratLain']:die('{"sts":"ERROR","desc":" 34 Param Tidak Ditemukan"}');
		$TgSuratLain=(isset($_GET['TgSuratLain'])  &&  !empty($_GET['TgSuratLain']))?$_GET['TgSuratLain']:die('{"sts":"ERROR","desc":" 35 Param Tidak Ditemukan"}');
		$NoBc27Asal=(isset($_GET['NoBc27Asal'])  &&  !empty($_GET['NoBc27Asal']))?$_GET['NoBc27Asal']:die('{"sts":"ERROR","desc":" 36 Param Tidak Ditemukan"}');
		$TgBc27Asal=(isset($_GET['TgBc27Asal'])  &&  !empty($_GET['TgBc27Asal']))?$_GET['TgBc27Asal']:die('{"sts":"ERROR","desc":" 37 Param Tidak Ditemukan"}');
		$Nopol=(isset($_GET['Nopol'])  &&  !empty($_GET['Nopol']))?$_GET['Nopol']:die('{"sts":"ERROR","desc":" 38 Param Tidak Ditemukan"}');
		$MrkNoKms=(isset($_GET['MrkNoKms'])  &&  !empty($_GET['MrkNoKms']))?$_GET['MrkNoKms']:die('{"sts":"ERROR","desc":" 39Param Tidak Ditemukan"}');
		$JmlJnsKms= (isset($_GET['JmlJnsKms'])  &&  !empty($_GET['JmlJnsKms']))?$_GET['JmlJnsKms']:die('{"sts":"ERROR","desc":" 40 Param Tidak Ditemukan"}');
		$NoSeg= (isset($_GET['NoSeg'])  &&  !empty($_GET['NoSeg']))?$_GET['NoSeg']:die('{"sts":"ERROR","desc":" 41 Param Tidak Ditemukan"}');
		$CtBcTuj1= (isset($_GET['CtBcTuj1'])  &&  !empty($_GET['CtBcTuj1']))?$_GET['CtBcTuj1']:die('{"sts":"ERROR","desc":" 42 Param Tidak Ditemukan"}');
		$CtBcTuj2= (isset($_GET['CtBcTuj2'])  &&  !empty($_GET['CtBcTuj2']))?$_GET['CtBcTuj2']:die('{"sts":"ERROR","desc":" 43 Param Tidak Ditemukan"}');
		$Volume= (isset($_GET['Volume'])  &&  !empty($_GET['Volume']))?$_GET['Volume']:die('{"sts":"ERROR","desc":" 44 Param Tidak Ditemukan"}');
		$ri_no= (isset($_GET['ri_no'])  );
		$ri_date= (isset($_GET['ri_date'])  );
		$create_date=(isset($_GET['create_date'])  &&  !empty($_GET['create_date']))?$_GET['create_date']:die('{"sts":"ERROR","desc":" 47 Param Tidak Ditemukan"}');
		$create_by= (isset($_GET['create_by'])  &&  !empty($_GET['create_by']))?$_GET['create_by']:die('{"sts":"ERROR","desc":" 48 Param Tidak Ditemukan"}');
		$update_date=(isset($_GET['update_date'])	);
		$update_by=(isset($_GET['update_by'])	);
	 */
	
		/*$base_url= base_url();
		$base_url="http://localhost:8080/pasi/";
		$tanggal = date("Y-m-d");
		$nama_file= './upload/BC27_FORM_'.$tanggal.'.pdf';

		$a= 'C:\xampp\htdocs\pasi\html2pdf\wkhtmltopdf.exe -s Letter "'.$base_url.'upload/view_bc27_form_hdr_print.php?KdKpbc='.$KdKpbc.'&car='.$car.'&KdKpbcBongkar='.$KdKpbcBongkar.'&KdKpbcAwas='.$KdKpbcAwas.'&PasokNama='.$PasokNama.'&PasokAlmt1='.$PasokAlmt1.'&Moda='.$Moda.'&KdVal='.$KdVal.'&Cif='.$Cif.'&Bruto='.$Bruto.'&Netto='.$Netto.'&NilSerah='.$NilSerah.'&Nodaf='.$Nodaf.'&Tgldaf='.$Tgldaf.'&UsahaNama='.$UsahaNama.'&UsahaNPWP='.$UsahaNPWP.'&UsahaAlamat1='.$UsahaAlamat1.'&UsahaAlamat2='.$UsahaAlamat2.'&UsahaSkep='.$UsahaSkep.'&PasokAlmt2='.$PasokAlmt2.'&PasokSkep='.$PasokSkep.'&PasokNPWP='.$PasokNPWP.'&NoInvoice='.$NoInvoice.'&TgInvoice='.$TgInvoice.'&NoPackinglist='.$NoPackinglist.'&TgPackinglist='.$TgPackinglist.'&NoKontrak='.$NoKontrak.'&TgKontrak='.$TgKontrak.'&SuratJalan='.$SuratJalan.'&TgSuratjalan='.$TgSuratjalan.'&SuratKep='.$SuratKep.'&TgSuratKep='.$TgSuratKep.'&SuratLain='.$SuratLain.'&TgSuratLain='.$TgSuratLain.'&NoBc27Asal='.$NoBc27Asal.'&TgBc27Asal='.$TgBc27Asal.'&Nopol='.$Nopol.'&MrkNoKms='.$MrkNoKms.'&JmlJnsKms='.$JmlJnsKms.'&NoSeg='.$NoSeg.'&CtBcTuj1='.$CtBcTuj1.'&CtBcTuj2='.$CtBcTuj2.'&Volume='.$Volume.'&ri_no='.$ri_no.'&ri_date='.$ri_date.'&create_date='.$create_date.'&create_by='.$create_by.'&update_date='.$update_date.'&update_by='.$update_by.'" '.$nama_file ;
		//echo $a;die();
		exec ($a);
		$file = $nama_file;;
		if(!file)
		{
				 // File doesn't exist, output error
				 die('file not found');
			 }
			 else
			 {
				header('Content-Description: File Transfer');
				header('Content-Type: application/octet-stream');
				header('Content-Disposition: attachment; filename='.basename($file));
				header('Content-Transfer-Encoding: binary');
				header('Expires: 0');
				header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
				header('Pragma: public');
				header('Content-Length: ' . filesize($file));
				ob_clean();
				flush();
				readfile($file);
				unlink($file);
				exit;
			 }
		
		
		
		
		$file = $nama_file;;
		$pdf = file_get_contents($file);

		header('Content-Type: application/pdf');
		header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
		header('Pragma: public');
		header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
		header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
		header('Content-Length: '.strlen($pdf));
		header('Content-Disposition: inline; filename="'.basename($file).'";');
		ob_clean(); 
		flush(); 
		echo $pdf;

		unlink($file);
		*/
		
		
			$id_bc271=(isset($_POST['id_bc271']) && !empty($_POST['id_bc271']))?$_POST['id_bc271']:die('{"sts":"ERROR","desc":" 1 Param Tidak Ditemukan"}');
			
			
			
		?>
		<head>
			
		</head>
		<body>
		<div id="iddivformheaderbc271" >
		<table width='940' border='0' cellspacing='0' cellpadding='2'>
		  <tr>
			<td width='134' rowspan='2'  style='border-top:thin #000000 solid;border-left:thin #000000 solid;border-right:thin #000000 solid;'><div align='center'>BC 2.7</div></td>
			<td width='817'  style='border-top:thin #000000 solid;border-right:thin #000000 solid;'><div align='center'>PEMBERITAHUAN PENGELUARAN BARANG UNTUK DI ANGKUT DARI </div></td>
		  </tr>
		  <tr>
			<td  style='border-right:thin #000000 solid;'><div align='center'>TEMPAT PENIMBUNAN BERIKAT KE TEMPAT PENIMBUNAN BERIKAT LAINNYA</div></td>
		  </tr>
		</table>
		<table width='940' border='0' cellspacing='0' cellpadding='2'>
		  <tr>
			<td colspan='9' style='border-top:thin #000000 solid;border-left:thin #000000 solid;border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan='2' style='border-left:thin #000000 solid;font-family:'Times New Roman', Times, serif;font-weight:bold; font-size:10px;'>&nbsp;NOMOR PENGAJUAN </td>
			<td width='11'>:</td>
			<td colspan='2'>".$car."</td>
			<td width='147'></td>
			<td width='224'>&nbsp;</td>
			<td width='6'>&nbsp;</td>
			<td width='154'  style='border-right:thin #000000 solid;'>Halaman 1 dari ....</td>
		  </tr>
		  <tr>
			<td width='135'  style='border-left:thin #000000 solid;'>&nbsp;A.&nbsp;&nbsp;&nbsp;&nbsp;KANTOR PABEAN</td>
			<td width='39'>&nbsp;</td>
			<td>:</td>
			<td width='50'>".$KdKpbc."</td>
			<td width='138'>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td style='border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan='2'  style='border-left:thin #000000 solid;'><blockquote>
			<p>1. Kantor asal</p>
			</blockquote></td>
			<td>:</td>
			<td>".$KdKpbcAwas."</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td style='border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan='2'  style='border-left:thin #000000 solid;'><blockquote>
			<p>2. Kantor Tujuan</p>
			</blockquote></td>
			<td>:</td>
			<td>".$KdKpbcBongkar."</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td><span  >&nbsp;D.&nbsp;&nbsp;&nbsp;TUJUAN PENGIRIMAN</span></td>
			<td>:</td>
			<td style='border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan='2'  style='border-left:thin #000000 solid;'>&nbsp;B.&nbsp;&nbsp;&nbsp;JENIS TPB ASAL</td>
			<td>:&nbsp;</td>
			<td colspan='2' >KAWASAN BERIKAT</td>
			<td>&nbsp;</td>
			<td colspan='3'  style='border-top:thin #000000 solid;border-left:thin #000000 solid;border-right:thin #000000 solid;'>F.&nbsp;&nbsp;KOLOM KHUSUS BEA DAN CUKAI</td>
		  </tr>
		  <tr>
			<td colspan='2' style='border-left:thin #000000 solid;'><span  style=';border-left:thin #000000 solid;'>&nbsp;C.&nbsp;&nbsp;&nbsp;JENIS TPB TUJUAN</span></td>
			<td>:</td>
			<td colspan='2'><span >KAWASAN BERIKAT</span></td>
			<td>&nbsp;</td>
			<td colspan='3' style='border-left:thin #000000 solid;border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		  <tr>
			<td style='border-left:thin #000000 solid;'>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td  style='border-left:thin #000000 solid;'>&nbsp;&nbsp;&nbsp;&nbsp;Nomor Pendaftaran</td>
			<td>:</td>
			<td style='border-right:thin #000000 solid;'>".$Nodaf."</td>
		  </tr>
		  <tr>
			<td style='border-left:thin #000000 solid;'>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td  style='border-left:thin #000000 solid;'>&nbsp;&nbsp;&nbsp;&nbsp;Tanggal</td>
			<td>:</td>
			<td style='border-right:thin #000000 solid;'>".$Tgldaf."</td>
		  </tr>
		</table>
		<table width='940' border='0' cellspacing='0' cellpadding='2'>
		  <tr>
			<td colspan='7'  style='border-top:thin #000000 solid;border-bottom:thin #000000 solid;border-left:thin #000000 solid;border-right:thin #000000 solid;'>E. DATA PEMBERITAHUAN</td>
		  </tr>
		  <tr>
			<td colspan='4'  style='border-left:thin #000000 solid;border-bottom:thin #000000 solid;'>PENGUSAHA TPB</td>
			<td colspan='3'  style='border-left:thin #000000 solid;border-right:thin #000000 solid;border-bottom:thin #000000 solid;'>TPB TUJUAN BARANG</td>
		  </tr>
		  <tr>
			<td width='148'  style='border-left:thin #000000 solid;'>1. NPWP</td>
			<td width='6'>:</td>
			<td colspan='2'>".$UsahaNPWP."</td>
			<td width='128'  style='border-left:thin #000000 solid;'>5. NPWP</td>
			<td width='24'>:</td>
			<td width='242' style='border-right:thin #000000 solid;'>".$PasokNPWP."</td>
		  </tr>
		  <tr>
			<td  style='border-left:thin #000000 solid;'>2. Nama</td>
			<td>:</td>
			<td colspan='2'>".$UsahaNama."</td>
			<td  style='border-left:thin #000000 solid;'>6. Nama</td>
			<td>:</td>
			<td style='border-right:thin #000000 solid;'>".$PasokNama."</td>
		  </tr>
		  <tr>
			<td  style='border-left:thin #000000 solid;'>3. Alamat</td>
			<td>:</td>
			<td colspan='2'>".$UsahaAlamat1."</td>
			<td  style='border-left:thin #000000 solid;'>7. Alamat</td>
			<td>:</td>
			<td style='border-right:thin #000000 solid;'>".$PasokAlmt1."</td>
		  </tr>
		  <tr>
			<td style='border-left:thin #000000 solid;'>&nbsp;</td>
			<td>&nbsp;</td>
			<td colspan='2'>".$UsahaAlamat2."</td>
			<td style='border-left:thin #000000 solid;'>&nbsp;</td>
			<td>&nbsp;</td>
			<td style='border-right:thin #000000 solid;'>".$PasokAlmt2."</td>
		  </tr>
		  <tr>
			<td  style='border-left:thin #000000 solid;'>4. No Izin TPB</td>
			<td>:</td>
			<td width='234'>".$UsahaSkep."</td>
			<td width='130'>&nbsp;</td>
			<td style='border-left:thin #000000 solid;'><span  style=';border-left:thin #000000 solid;'>8. No Izin TPB</span></td>
			<td>&nbsp;</td>
			<td style='border-right:thin #000000 solid;'>".$PasokSkep."</td>
		  </tr>
		  <tr>
			<td colspan='4'   style='border-top:thin #000000 solid;border-bottom:thin #000000 solid;border-left:thin #000000 solid;'>DOKUMEN PELENGKAP PABEAN</td>
			<td colspan='3'  style='border-top:thin #000000 solid;border-bottom:thin #000000 solid;border-left:thin #000000 solid;border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		</table>
		<table width='940' border='0' cellspacing='0' cellpadding='2'>
		  <tr>
			<td width='112'  style='border-left:thin #000000 solid;'>9. Invoice</td>
			<td width='12'>&nbsp;:</td>
			<td colspan='3'>".$NoInvoice."</td>
			<td width='17' >Tgl</td>
			<td colspan='3'>".$TgInvoice."</td>
			<td width='88' >12. Surat jalan</td>
			<td width='6'>:</td>
			<td width='120' >".$SuratJalan."</td>
			<td colspan='2' style='border-right:thin #000000 solid;' ><span >Tgl : ".$TgSuratjalan."</span></td>
		  </tr>
		  <tr>
			<td  style='border-left:thin #000000 solid;'>10. Packing List</td>
			<td>&nbsp;:</td>
			<td colspan='3'>".$NoPackinglist."</td>
			<td >Tgl</td>
			<td colspan='3'>".$TgPackinglist."</td>
			<td colspan='3'><span >13. Surat Keputusan/Persetujuan</span></td>
			<td colspan='2'style='border-right:thin #000000 solid;'>:<span >
			  ".$SuratKep."
			</span></td>
		  </tr>
		  <tr>
			<td style='border-left:thin #000000 solid;'><span  style='border-left:thin #000000 solid;'>11.kontrak</span></td>
			<td>&nbsp;:</td>
			<td colspan='3'>".$NoKontrak."</td>
			<td><span >Tgl</span></td>
			<td colspan='2'>".$TgKontrak."</td>
			<td width='12'>&nbsp;</td>
			<td colspan='3' >&nbsp;</td>
			<td colspan='2'style='border-right:thin #000000 solid;'><span >Tgl</span>&nbsp;".$TgSuratKep."</td>
		  </tr>
		  <tr>
			<td style='border-left:thin #000000 solid;'>&nbsp;</td>
			<td>&nbsp;</td>
			<td width='45'>&nbsp;</td>
			<td width='6'>&nbsp;</td>
			<td width='143'>&nbsp;</td>
			<td>&nbsp;</td>
			<td width='33'>&nbsp;</td>
			<td width='83'>&nbsp;</td>
			<td>&nbsp;</td>
			<td colspan='3'><span >14. Jenis/Nomor/tanggal dokumen lainnya</span></td>
			<td colspan='2'style='border-right:thin #000000 solid;'>:<span >".$SuratLain."
			</span></td>
		  </tr>
		  <tr>
			<td style='border-left:thin #000000 solid;'>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td colspan='2'style='border-right:thin #000000 solid;'><span >Tgl</span>&nbsp;".$TgSuratLain."</td>
		  </tr>
		  <tr>
			<td colspan='14'  style='border-top:thin #000000 solid;border-bottom:thin #000000 solid;border-left:thin #000000 solid;border-right:thin #000000 solid;'>RIWAYAT BARANG</td>
		  </tr>
		  <tr>
			<td colspan='3'  style='border-left:thin #000000 solid;'>15. Nomor dan tanggal BC 2.7 asal</td>
			<td>:</td>
			<td>".$NoBc27Asal."</td>
			<td>&nbsp;</td>
			<td >TGL :</td>
			<td colspan='3'>".$TgBc27Asal."</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td width='88'>&nbsp;</td>
			<td width='119' style='border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
			<tr>
			<td colspan='14'  style='border-top:thin #000000 solid;border-bottom:thin #000000 solid;border-left:thin #000000 solid;border-right:thin #000000 solid;'>DATA PERDANGANGAN</td>
		  </tr>
		  <tr>
			<td colspan='3'  style='border-left:thin #000000 solid;'>16. Jenis valuta asing</td>
			<td>:</td>
			<td>".$KdVal."</td>
			<td>&nbsp;</td>
			<td >&nbsp;</td>
			<td>&nbsp;</td>
			<td colspan='2'><span  S>18. Harga Penyerahan</span></td>
			<td>:</td>
			<td>".$NilSerah."</td>
			<td>&nbsp;</td>
			<td style='border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan='3'  style='border-left:thin #000000 solid;'>17. CIF</td>
			<td>:</td>
			<td>".$Cif."</td>
			<td>&nbsp;</td>
			<td >&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td style='border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan='11' style='border-left:thin #000000 solid;border-top:thin #000000 solid;border-bottom:thin #000000 solid;'>DATA PENGANGKUTAN</td>
			<td colspan='3' style='border-right:thin #000000 solid;border-top:thin #000000 solid;border-bottom:thin #000000 solid;border-left:thin #000000 solid;'><blockquote>
			  <p>SEGEL ( DIISI OLEH BEA DAN CUKAI )</p>
			</blockquote></td>
		  </tr>
		  <tr>
			<td colspan='2'  style='border-left:thin #000000 solid;'>19. Jenis Sarana Angkut</td>
			<td colspan='4'>:
			".$Moda."</td>
			<td colspan='2'><span  >19. No Polisi</span></td>
			<td>:</td>
			<td>".$Nopol."</td>
			<td>&nbsp;</td>
			<td colspan='2' style='border-left:thin #000000 solid;border-right:thin #000000 solid;border-bottom:thin #000000 solid;'><blockquote>
			  <blockquote>BC Asal</blockquote>
			</blockquote></td>
			<td rowspan='2'  style='border-right:thin #000000 solid;border-bottom:thin #000000 solid;'><p>23. Catatan BC Tujuan</p></td>
		  </tr>
		  <tr>
			<td colspan='2' style='border-left:thin #000000 solid;'>&nbsp;</td>
			<td colspan='4'>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td  style='border-left:thin #000000 solid;border-right:thin #000000 solid;border-bottom:thin #000000 solid;'>21. No. Segel</td>
			<td  style='border-right:thin #000000 solid;border-bottom:thin #000000 solid;'>22. Jenis</td>
		  </tr>
			  <tr>
			<td colspan='11' style='border-left:thin #000000 solid;border-top:thin #000000 solid;border-bottom:thin #000000 solid;'>Data Peti Kemas Dan pengemas</td>
		   <td rowspan='3' style='border-left:thin #000000 solid;border-right:thin #000000 solid;border-bottom:thin #000000 solid;'>".$NoSeg."</td>
			<td rowspan='3' style='border-right:thin #000000 solid;border-bottom:thin #000000 solid;'><p >KERTAS</p></td>
			<td rowspan='3' style='border-right:thin #000000 solid;border-bottom:thin #000000 solid;'>".$CtBcTuj1." ".$CtBcTuj2."</td>
		  </tr>
		  <tr>
			<td colspan='6'  style='border-left:thin #000000 solid;'>24. Merek &amp; No Kemasan / Peti Kemas dan jumlah Peti Kemas</td>
			<td colspan='5' >25. Jumlah Jenis Kemasan</td>
		  </tr>
		  <tr>
			<td colspan='6'  style='border-left:thin #000000 solid;'>".$MrkNoKms."</td>
			<td colspan='5'>".$JmlJnsKms."</td>
		  </tr>
		  <tr>
			<td colspan='14'  style='border-top:thin #000000 solid;border-bottom:thin #000000 solid;border-left:thin #000000 solid;border-right:thin #000000 solid;'>DATA BARANG</td>
		  </tr>
		  <tr>
			<td  style='border-left:thin #000000 solid;'>26. Volume (m3)</td>
			<td colspan='6'>:".$Volume."</td>
			<td colspan='2' >27. Berat Kotor (kg) :</td>
			<td colspan='3'>".$Bruto."</td>
			<td colspan='2'  style='border-right:thin #000000 solid;'>28. Berat Bersih :
			  ".$Netto."</td>
		  </tr>
		</table>
		 <table width='940' border='0' cellspacing='0' cellpadding='2'>
		  
				<td width='27'  style=';border-left:thin #000000 solid;border-top:thin #000000 solid;'>29.</td>
				<td width='442'  style=';border-top:thin #000000 solid;border-left:thin #000000 solid;'>30.</td>
			<td width='281'  style=';border-left:thin #000000 solid;border-top:thin #000000 solid;'>31.</td>
			<td width='174'  style=';border-left:thin #000000 solid;border-right:thin #000000 solid;border-top:thin #000000 solid;'>32.</td>
		  </tr>
		  <tr>
			<td  style=';border-left:thin #000000 solid;'>No.</td>
			<td  style=';border-left:thin #000000 solid;'> Uraian jumlah dan jenis barang secara lengkap, kode barang, merk, tipe, ukuran, </td>
			<td  style=';border-left:thin #000000 solid;'>- Jumlah dan Jenis Satuan</td>
			<td  style=';border-left:thin #000000 solid;border-right:thin #000000 solid;'>- Nilai CIF </td>
		  </tr>
		  <tr>
			<td rowspan='3' style=';border-left:thin #000000 solid;border-bottom:thin #000000 solid;'>&nbsp;</td>
			<td  style=';border-left:thin #000000 solid;'> dan spesifikasi lain</td>
			<td  style=';border-left:thin #000000 solid;'>- Berat Bersih (kg)</td>
			<td  style=';border-left:thin #000000 solid;border-right:thin #000000 solid;'>-Harga</td>
		  </tr>
		  <tr>
			<td style=';border-left:thin #000000 solid;'></td>
			<td  style=';border-left:thin #000000 solid;'>- Volume</td>
			<td  style=';border-left:thin #000000 solid;border-right:thin #000000 solid;'>Penyerahan</td>
		  </tr>
		  <tr>
			<td style=';border-left:thin #000000 solid;border-bottom:thin #000000 solid;'>&nbsp;</td>
			<td style=';border-left:thin #000000 solid;border-bottom:thin #000000 solid;'>&nbsp;</td>
			<td style=';border-left:thin #000000 solid;border-bottom:thin #000000 solid;border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		  <tr>
			<td style=';border-left:thin #000000 solid;'>&nbsp;</td>
			<td style=';border-left:thin #000000 solid;'>&nbsp;</td>
			<td style=';border-left:thin #000000 solid;'>&nbsp;</td>
			<td style=';border-left:thin #000000 solid;border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		  <tr>
			<td  style=';border-left:thin #000000 solid;'>&nbsp;</td>
			<td  style=';border-left:thin #000000 solid;'>&nbsp;</td>
			<td  style=';border-left:thin #000000 solid;'>&nbsp;</td>
			<td  style=';border-left:thin #000000 solid;border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		</table>
		<table width='940' border='0' cellspacing='0' cellpadding='2'>
		  <tr>
			<td width='458'  style='border-top:thin #000000 solid;border-bottom:thin #000000 solid;border-left:thin #000000 solid;'>&nbsp;G.&nbsp;&nbsp;&nbsp;UNTUK PEJABAT BEA DAN CUKAI</td>
			<td colspan='2'  style='border-top:thin #000000 solid;border-bottom:thin #000000 solid;border-left:thin #000000 solid;border-right:thin #000000 solid;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E.&nbsp;&nbsp;&nbsp;TANDA TANGAN PENGUSAHA TPB</td>
		  </tr>
		  <tr>
			<td rowspan='6' style='border-left:thin #000000 solid;border-bottom:thin #000000 solid;'>&nbsp;</td>
			<td colspan='2'  style='border-left:thin #000000 solid;border-right:thin #000000 solid;'>&nbsp;Dengan ini saya menyatakan bertanggung jawab atas kebenaran hal hal</td>
		  </tr>
		  <tr>
			<td width='44' rowspan='5' style='border-left:thin #000000 solid;border-bottom:thin #000000 solid;'>&nbsp;</td>
			<td width='449'  style='border-right:thin #000000 solid;'>yang diberitahukan dalam pemberitahuan pabean ini.</td>
		  </tr>
		  <tr>
			<td  style='border-right:thin #000000 solid;'>.....,............</td>
		  </tr>
		  <tr>
			<td style='border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		  <tr>
			<td style='border-right:thin #000000 solid;'>&nbsp;</td>
		  </tr>
		  <tr>
			<td  style='border-bottom:thin #000000 solid;border-right:thin #000000 solid;'>(................................................)</td>
		  </tr>
		</table>
		</div>
		<body>
		<?php
	}
	
	function printToExcel() {
		if (empty($_POST["cetak_html_bc271"])) {
		?>
		<table>
			<tr>
				<td>
					<form action='' method="POST" target="_blank">
						<input name="cetak_html_bc271" type="hidden" value="printmeexcel_bc271">
						<input type="submit" name="tombol" value="CETAK LAPORAN KE EXCEL">
					</form>
				</td>
			</tr>
		</table>
		<?php
		}
	}
	
	function headerToExcel($filename){
		if (empty($_POST["cetak_html_bc271"])) { }
		else if($_POST["cetak_html_bc271"]=="printmeexcel_bc271") {
			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 htmltoexcel(){
	?>	
	<html>
    <head>
		
		<script type="text/javascript">
			var tableToExcel = (function() {
			  var uri = 'data:application/vnd.ms-excel;base64,', 
			  template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
				, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
				, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
			  return function(table, name, filename) {
				if (!table.nodeType) table = document.getElementById(table)
				var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
				//window.location.href = uri + base64(format(template, ctx))
				document.getElementById("dlink").href = uri + base64(format(template, ctx));
				document.getElementById("dlink").download = filename;
				document.getElementById("dlink").click();

				
			  }
			})()
		</script>
	</head>	
	<body>
		<a id="dlink"  style="display:none;"></a>
		<input type="button" onclick="tableToExcel('testTable', 'W3C Example Table', 'myfile.xls')" value="Export to Excel">
		<table id="testTable" summary="Code page support in different versions of MS Windows." rules="groups" frame="hsides" border="2">
		<caption>CODE-PAGE SUPPORT IN MICROSOFT WINDOWS</caption>
		<colgroup align="center"></colgroup>
		<colgroup align="left"></colgroup>
		<colgroup span="2" align="center"></colgroup>
		<colgroup span="3" align="center"></colgroup>
		<thead valign="top">
		<tr>
		<th>Code-Page<br>ID</th>
		<th>Name</th>
		<th>ACP</th>
		<th>OEMCP</th>
		<th>Windows<br>NT 3.1</th>
		<th>Windows<br>NT 3.51</th>
		<th>Windows<br>95</th>
		</tr>
		</thead>
		<tbody>
		<tr>
		<td>1200</td><td style="background-color: #00f; color: #fff">Unicode (BMP of ISO/IEC-10646)</td>
		<td></td><td></td><td>X</td><td>X</td><td>*</td></tr><tr><td>1250</td><td style="font-weight: bold">Windows 3.1 Eastern European</td><td>X</td><td></td><td>X</td><td>X</td><td>X</td></tr><tr><td>1251</td><td>Windows 3.1 Cyrillic</td><td>X</td><td></td><td>X</td><td>X</td><td>X</td></tr><tr><td>1252</td><td>Windows 3.1 US (ANSI)</td><td>X</td><td></td><td>X</td><td>X</td><td>X</td></tr><tr><td>1253</td><td>Windows 3.1 Greek</td><td>X</td><td></td><td>X</td><td>X</td><td>X</td></tr><tr><td>1254</td><td>Windows 3.1 Turkish</td><td>X</td><td></td><td>X</td><td>X</td><td>X</td></tr><tr><td>1255</td><td>Hebrew</td><td>X</td><td></td><td></td><td></td><td>X</td></tr><tr><td>1256</td><td>Arabic</td><td>X</td><td></td><td></td><td></td><td>X</td></tr><tr><td>1257</td><td>Baltic</td><td>X</td><td></td><td></td><td></td><td>X</td></tr><tr><td>1361</td><td>Korean (Johab)</td><td>X</td><td></td><td></td><td>**</td><td>X</td></tr></tbody><tbody><tr><td>437</td><td>MS-DOS United States</td><td></td><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td>708</td><td>Arabic (ASMO 708)</td><td></td><td>X</td><td></td><td></td><td>X</td></tr><tr><td>709</td><td>Arabic (ASMO 449+, BCON V4)</td><td></td><td>X</td><td></td><td></td><td>X</td></tr><tr><td>710</td><td>Arabic (Transparent Arabic)</td><td></td><td>X</td><td></td><td></td><td>X</td></tr><tr><td>720</td><td>Arabic (Transparent ASMO)</td><td></td><td>X</td><td></td><td></td><td>X</td></tr>
		</tbody>
		</table>


		</body>
	</html>	
	
	
	
	<?php
	}
	
	function htmltoexcelbc271(){
		$id_bc271=(isset($_POST['id_bc271']) && !empty($_POST['id_bc271']))?$_POST['id_bc271']:die('{"sts":"ERROR","desc":" 1 Param Tidak Ditemukan"}');
		
	?>
		<script type="text/javascript">
		
		$(function() {
 
			$('#download').click(function(event) {
		 
				event.preventDefault();
				document.location.href = '<?php echo base_url().'exim/ct_bc271/savetoexcelbc271'; ?>'+'?id_bc271=<?php echo $id_bc271 ?>'
			});
		 
		});
		
		</script>
		<button id="download">Download file</button>
		
	<?php
	}
	
	function savetoexcelbc271(){
		
		$id_bc271 = (isset($_REQUEST['id_bc271']) && !empty($_REQUEST['id_bc271']))?$_REQUEST['id_bc271']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		$rshdr= $this->db->query("
			SELECT [id_bc_in_hdr]
			  ,[CAR]
			  ,[KdKpbc]
			  ,[Tujuan]
			  ,[JnsBarang]
			  ,[TujuanKirim]
			  ,[PasokNama]
			  ,[PasokAlmt]
			  ,[PasokNeg]
			  ,[UsahaId]
			  ,[UsahaNpwp]
			  ,[KdTPB]
			  ,[Registrasi]
			  ,[UsahaNama]
			  ,[UsahaAlmt]
			  ,[UsahaStatus]
			  ,[ApiKd]
			  ,[ApiNo]
			  ,[PpjkId]
			  ,[PpjkNpwp]
			  ,[PpjkNama]
			  ,[PpjkAlmt]
			  ,[PpjkNo]
			  ,[PpjkTg]
			  ,[IndId]
			  ,[IndNpwp]
			  ,[IndNama]
			  ,[IndAlmt]
			  ,[Moda]
			  ,[AngkutNama]
			  ,[AngkutNo]
			  ,[AngkutFl]
			  ,[PelBkr]
			  ,[PelMuat]
			  ,[PelTransit]
			  ,[BC23No]
			  ,convert(varchar,[BC23Tg], 106) as BC23Tg
			  ,[KdKpbcBongkar]
			  ,[KdKpbcAwas]
			  ,[DokTupKd]
			  ,[DokTupNo]
			  ,[DokTupTg]
			  ,[PosNo]
			  ,[PosSub]
			  ,[TmpTbn]
			  ,[KdVal]
			  ,[Ndpbm]
			  ,[NilInv]
			  ,[Freight]
			  ,[BTambahan]
			  ,[Diskon]
			  ,[KdAss]
			  ,[Asuransi]
			  ,[KdHrg]
			  ,[Fob]
			  ,[Cif]
			  ,[Bruto]
			  ,[Netto]
			  ,[JmCont]
			  ,[JmBrg]
			  ,[TglTtd]
			  ,[KotaTtd]
			  ,[Namattd]
			  ,[ContakPerson]
			  ,[NoPhone]
			  ,[NoFax]
			  ,[Email]
			  ,[Status]
			  ,[Snrf]
			  ,[Lengkap]
			  ,[PosSubSub]
			  ,[NoKontrak]
			  ,[TgKontrak]
			  ,[HargaRp]
			  ,[TmpPeriksaFisik]
			  ,[AlmtPeriksaFisik]
			  ,[TgPeriksaFisik]
			  ,[WkPeriksaFisik]
			  ,[create_date]
			  ,[create_by]
			  ,[update_date]
			  ,[update_by]
			  ,[typedok]
			  ,[statusdok]
			  ,[noinv]
			  ,[tginv]
			  ,[inv_hdr_id]
			  ,[bc_in_from_in]
			  ,[nopol]
			  ,[nobl]
			  ,[tglbl]
			  ,[tgaju]
		  FROM [dbo].[tbl_bc_in_hdr]
		  where [typedok] = 'bc271' and  id_bc_in_hdr=$id_bc271 
			");
		
		$qryhdr = $rshdr->result_array();
		
		$BC23No = '';
		$BC23Tg = '';
		foreach($qryhdr as $rowhdr){
			$BC23No = $rowhdr['BC23No'];
			$BC23Tg = $rowhdr['BC23Tg'];
		}
		
				
		$datenow = date('Y-m-d');
		$filename =  "BC27_".$BC23No."_$datenow";
		
		include_once ( APPPATH."libraries/PHPExcel/IOFactory.php");	
		
		$objTpl = PHPExcel_IOFactory::load(APPPATH."libraries/PHPExcel/templates/bc271.xls");	
		$objTpl->setActiveSheetIndex(0);  //set first sheet as active
		
		$objTpl->getActiveSheet()->setCellValue('D6', ':'.$BC23No);
		$objTpl->getActiveSheet()->setCellValue('I11', ':'.$BC23Tg);
		
		
		
		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!	
			
	?>
		
		
	<?php	
			
			
			
	
	}
	//-----------bc271hib
	
	
	function loaddatahib_bc271(){
		
		
		$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']:'inv_hdr_id'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		//$where = " a.status_inv=0 ";
		$where = " b.supplier_country = 'ID' ";
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){
					
					if ( $k->field == "r3" ) {
						$searchString = $k->data;
						$where .= " and r3 like  '%".$searchString."%'"; 
					}  else if ( $k->field == "supplier_name" ) {
						$searchString = $k->data;
						$where .= " and b.supplier_name like  '%".$searchString."%'"; 
					}  else if ( $k->field == "r4" ) {
						$searchString = $k->data;
						$where .= " and r4 like  '%".$searchString."%'"; 
					}  else if ( $k->field == "r20" ) {
						$searchString = $k->data;
						$where .= " and r20 like  '%".$searchString."%'"; 
					}  else if ( $k->field == "nobl" ) {
						$searchString = $k->data;
						$where .= " and nobl like  '%".$searchString."%'"; 
					}  else if ( $k->field == "tgbl" ) {
						$searchString = $k->data;
						$where .= " and tgbl =  '$searchString'"; 
					} else if ( $k->field == "r2" ) {
						$searchString = $k->data;
						$where .= " and r2 like  '%".$searchString."%'"; 
					} else if ( $k->field == "status_inv" ) {
						$searchString = $k->data;
							if ($searchString==1){ 
								$where = " a.status_inv=$searchString  "; 
							} else if ($searchString==2){ 
								$where .= " "; 
								//$where .= " or a.status_inv=1  "; 
							} else if ($searchString=='-'){ 
								$where .= " and a.status_inv=0  "; 
							} else {
								$where .= " and (a.status_inv=0  or a.status_inv='$searchString') "; 
							}
					} else if ( $k->field == "status_inv" && $k->field == "r2" )  {
						$searchString = $k->data;
						$where = " r3 like  '%".$searchString."%'"; 
					
					}
				
				}
			}
		} else {
		
			$where .= "  and a.status_inv=0 ";
		}
		
	//	echo $where;
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_bc40->inv_all($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_bc40->inv_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){
			if ($r->status_inv == 0){ $stat = "New"; } else { $stat = "Not New"; };
			if ($r->tgbl =='1900-10-23'){ $tgbl = ""; } else { $tgbl = $r->tgbl; };	
			$responce->rows[$i]['inv_hdr_id']=$r->inv_hdr_id; 
			$responce->rows[$i]['r3']=$r->r3; 
			$responce->rows[$i]['r2']=$r->r2; 
			$responce->rows[$i]['r4']=$r->r4;
			$responce->rows[$i]['r5']= inv_parsedate($r->r5); //$r->r5;
			$responce->rows[$i]['r20']=$r->r20;
			$responce->rows[$i]['supplier_name']=$r->supplier_name; 
			$responce->rows[$i]['date_create']=$r->date_create; 
			$responce->rows[$i]['status_inv']=$stat;
			$responce->rows[$i]['nobl']=$r->nobl;
			$responce->rows[$i]['tgbl']=$tgbl;
			
			$i++;
		}
		echo json_encode($responce);
		
	}
	
	function view_bc271_hib(){
		$q = $this->db->query("
			SELECT     v_noinv_dtl.noinv
			FROM         v_noinv_dtl LEFT OUTER JOIN
								  tbl_data_part_hs ON replace(v_noinv_dtl.partnumber,' ','') = tbl_data_part_hs.part_no2
			where tbl_data_part_hs.part_no is null
			group by v_noinv_dtl.noinv
		");
		$rs = $q->result_array();
		$datanull='';
		foreach ($rs as $row){
			$datanull.=$row['noinv'].'|';		
		}
		if ($datanull != ''){
			$data["test"] = 'Part Number di Data Part HS Not Match Di Invoice Berikut, Silahkan Cek Di View Data : ' . $datanull;
		} else {
			$data["test"]=$datanull;
		}
		$this->load->view('exim/view_bc271_hib', $data);
		

	
	
	}
	function view_bc271_group_invoice(){
	
		$data["test"] = "";
		$this->load->view('exim/view_bc271_group_invoice', $data);
	
	}
	
	function prosesdatabl(){
		
		$datadiff = (isset($_POST['datadiff']) && !empty($_POST['datadiff']))?$_POST['datadiff']:'0'; 
		$datadiff=json_decode($datadiff);
		$datacsv = '';
		foreach ($datadiff as $data ){
			$inv_hdr_id = (isset($data->inv_hdr_id) && !empty($data->inv_hdr_id ))?$data->inv_hdr_id :die('{"sts":"ERROR","desc":" Param inv_hdr_id Tidak Ditemukan"}');
			$invno = (isset($data->invno) && !empty($data->invno ))?$data->invno :die('{"sts":"ERROR","desc":" Param invno Tidak Ditemukan"}');
			
			$datacsv .= $inv_hdr_id . ',' . $invno; 
			$datacsv .= "|";
		}
		// echo $datacsv;	
		// var_dump($datadiff); die();
		
		
		$qry = $this->db->query("
		
			BEGIN TRY
			
				EXEC ('[spi_invoiceupdatebl_bc40_27] @datadiff=''$datacsv'', @cmd=''proses'', @typebc=''BC271''  ') 
			END TRY
			BEGIN CATCH 
				SELECT 
				'error' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
		 ");
		 $rs = $qry->result_array();
        // $r = $qry->result();		
		// var_dump($r);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
		
	
	}
	function canceldatabl(){
		
		$datadiff = (isset($_POST['datadiff']) or !empty($_POST['datadiff']))?$_POST['datadiff']:'0'; 
		$datadiff=json_decode($datadiff);
		$datacsv = '';
		foreach ($datadiff as $data ){
			$datacsv .= $data->inv_hdr_id . ',' . $data->invno . ',' . $data->blawbno . ',' . '1900-10-23'; 
			$datacsv .= "|";
		}
		 // echo $datacsv;	
		// var_dump($datadiff); die();
		
		// echo "
		
			 // EXEC ('spi_invoiceupdatebl @datadiff=''$datacsv'', @nobl=''$nobl'', @tgbl=''$tgbl'', @cmd=''cancel'' ') 
			
		 // "; die();
		
		$qry = $this->db->query("
			BEGIN TRY	
			 EXEC ('spi_invoiceupdatebl_bc40_27 @datadiff=''$datacsv'', @cmd=''cancel'', @typebc=''BC271'' ') 
			END TRY
			BEGIN CATCH 
				SELECT 
				'error' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
		 ");
		$rs = $qry->result_array();
        // $r = $qry->result();		
		// var_dump($r);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	
	}
	
	function view_bc271_prosesinsertinv(){
		$nobl = (isset($_POST['nobl']) or !empty($_POST['nobl']))?$_POST['nobl']:die('{"sts":"ERROR","desc":" Param nobl Tidak Ditemukan"}');
		$tgbl = (isset($_POST['tgbl']) or !empty($_POST['tgbl']))?$_POST['tgbl']:die('{"sts":"ERROR","desc":" Param tgbl Tidak Ditemukan"}');
		$data["tgbl"] = $tgbl;
		$data["nobl"] = $nobl;
		$this->load->view('exim/view_bc271_prosesinsertinv',$data);
	
	}
	
	function loaddatanonobl(){
		$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']:'inv_hdr_id'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$nobl = (isset($_POST['nobl']) && !empty($_POST['nobl']))?$_POST['nobl']:'';
		$tgbl = (isset($_POST['tgbl']) && !empty($_POST['tgbl']))?$_POST['tgbl']:'';
		
		
		//$where = " a.status_inv=0 ";
		$where = " 1=1 ";
		$where .= " and nobl =  '".$nobl."'";
		$where .= " and tgbl =  '".$tgbl."'";
		
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_invoice->inv_all($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_invoice->inv_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){
		    if ($r->status_inv == 0){
					  $status_inv = 'INVOICE NEW ADDED';
			} else if ($r->status_inv == 1){
				 $status_inv = 'DATA ALREADY PROCESSED';
			}
			$responce->rows[$i]['inv_hdr_id']=$r->inv_hdr_id; 
			$responce->rows[$i]['invno']=$r->r3; 
			$responce->rows[$i]['blawbno']=$r->nobl; 
			$responce->rows[$i]['tglblawb']=$r->tgbl;
			$responce->rows[$i]['status_inv']=$status_inv;
			$responce->rows[$i]['status_invx']=$r->status_inv;
			
			
			$i++;
		}
		echo json_encode($responce);
		
	}
	
	function updatestatusproses(){
		$typebc = 'BC271';
		$noinv = (isset($_POST['noinv']) && !empty($_POST['noinv']))?$_POST['noinv']:die('{"sts":"ERROR","desc":" Param INV Tidak Ditemukan"}');
		$nobl = (isset($_POST['nobl']) && !empty($_POST['nobl']))?$_POST['nobl']:die('{"sts":"ERROR","desc":" Param nobl Tidak Ditemukan"}');
		$tgbl= (isset($_POST['tgbl']) && !empty($_POST['tgbl']))?$_POST['tgbl']:die('{"sts":"ERROR","desc":" Param tg bl Tidak Ditemukan"}');
		
		$noinv=json_decode($noinv);
		$noinvcsv = '';
		foreach ($noinv as $data ){
			$inv_hdr_id = (isset($data->inv_hdr_id) && !empty($data->inv_hdr_id ))?$data->inv_hdr_id :die('{"sts":"ERROR","desc":" Param inv_hdr_id Tidak Ditemukan"}');
			$invno = (isset($data->invno) && !empty($data->invno ))?$data->invno :die('{"sts":"ERROR","desc":" Param invno Tidak Ditemukan"}');
			$noinvcsv .= $inv_hdr_id. ',' . $invno; 
			$noinvcsv .= "|";
		}
		$listinv = substr($noinvcsv, 0,  strlen($noinvcsv) -1); 
		 // echo "EXEC  [sp_insertbc23] @nobl = N'$nobl', @tgbl = '$tgbl', @typebc = N'$typebc',@noinv = '$listinv'";
		 // var_dump($noinv); die();
		$typebc = 'BC271';
		$qry = $this->db->query("
			BEGIN TRY
				EXEC  [sp_insertbc23] @nobl = N'$nobl', @tgbl = '$tgbl', @typebc = N'$typebc',@noinv = '$listinv'
			END TRY
			BEGIN CATCH 
				SELECT 
				'error' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
		");
		$rs = $qry->result_array();	
		// var_dump($rs);
		// die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
		
		
		
	}
	
	function recalculate_new_inv_bl(){
		$typebc = 'BC271';
		$noinv = (isset($_POST['noinv']) && !empty($_POST['noinv']))?$_POST['noinv']:die('{"sts":"ERROR","desc":" Param INV Tidak Ditemukan"}');
		$nobl = (isset($_POST['nobl']) && !empty($_POST['nobl']))?$_POST['nobl']:die('{"sts":"ERROR","desc":" Param nobl Tidak Ditemukan"}');
		$tgbl= (isset($_POST['tgbl']) && !empty($_POST['tgbl']))?$_POST['tgbl']:die('{"sts":"ERROR","desc":" Param tg bl Tidak Ditemukan"}');
		
		$noinv=json_decode($noinv);
		$noinvcsv = '';
		foreach ($noinv as $data ){
			$inv_hdr_id = (isset($data->inv_hdr_id) && !empty($data->inv_hdr_id ))?$data->inv_hdr_id :die('{"sts":"ERROR","desc":" Param inv_hdr_id Tidak Ditemukan"}');
			$invno = (isset($data->invno) && !empty($data->invno ))?$data->invno :die('{"sts":"ERROR","desc":" invno Param invno Tidak Ditemukan"}');
			$noinvcsv .= $inv_hdr_id. ',' . $invno; 
			$noinvcsv .= "|";
		}
		$listinv = substr($noinvcsv, 0,  strlen($noinvcsv) -1); 
		 //echo "EXEC  [sp_insertcb23_recalculate_new_inv_bl] @nobl = N'$nobl', @tgbl = '$tgbl', @typebc = N'$typebc',@noinv = '$listinv'";
		 // var_dump($noinv); die();
		$typebc = 'BC271';
		$qry = $this->db->query("
			EXEC [sp_insertcb23_recalculate_new_inv_bl] @nobl = N'$nobl', @tgbl = '$tgbl', @typebc = N'$typebc',@noinv = '$listinv'
		");
		$rs = $qry->result_array();	
		//var_dump($rs);
		//die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
		
	}
	function recalculatedatabl(){
	
		$nobl = (isset($_POST['nobl']) && !empty($_POST['nobl']))?$_POST['nobl']:die('{"sts":"ERROR","desc":" Param  Tidak Ditemukan"}'); 
		$tgbl = (isset($_POST['tgbl']) && !empty($_POST['tgbl']))?$_POST['tgbl']:die('{"sts":"ERROR","desc":" Param  Tidak Ditemukan"}');
		
		$datadiff = (isset($_POST['datadiff']) && !empty($_POST['datadiff']))?$_POST['datadiff']:'0'; 
		$datadiff=json_decode($datadiff);
		$datacsv = '';
		foreach ($datadiff as $data ){
			$inv_hdr_id = (isset($data->inv_hdr_id) && !empty($data->inv_hdr_id ))?$data->inv_hdr_id :die('{"sts":"ERROR","desc":" Param inv_hdr_id Tidak Ditemukan"}');
			$invno = (isset($data->invno) && !empty($data->invno ))?$data->invno :die('{"sts":"ERROR","desc":" Param invno Tidak Ditemukan"}');
			$blawbno = (isset($data->blawbno) && !empty($data->blawbno ))?$data->blawbno :die('{"sts":"ERROR","desc":" Param blawbno Tidak Ditemukan"}');
			$tglblawb = (isset($data->tglblawb) && !empty($data->tglblawb ))?$data->tglblawb :die('{"sts":"ERROR","desc":" Param tglblawb Tidak Ditemukan"}');
			
			$datacsv .= $inv_hdr_id . ',' . $invno . ',' . $blawbno . ',' . $tglblawb; 
			$datacsv .= "|";
		}
		// echo $datacsv;	
		// var_dump($datadiff); die();
		
		
		$qry = $this->db->query("
			BEGIN TRY
			 EXEC ('spu_insertbc23_bl @datadiff=''$datacsv'', @nobl=''$nobl'', @tgbl=''$tgbl''  ') 
			END TRY
			BEGIN CATCH 
				SELECT 
				'error' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
		 ");
		 $rs = $qry->result_array();
        // $r = $qry->result();		
		// var_dump($r);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	
	}
	
	function cancelbcinvoicebc(){
	
		$nobl = (isset($_POST['nobl']) && !empty($_POST['nobl']))?$_POST['nobl']:die('{"sts":"ERROR","desc":" Param  Tidak Ditemukan"}'); 
		$tgbl = (isset($_POST['tgbl']) && !empty($_POST['tgbl']))?$_POST['tgbl']:die('{"sts":"ERROR","desc":" Param  Tidak Ditemukan"}');
		
		/* echo " EXEC ('spu_invoicenonhib_del_bc40_27 @nobl=''$nobl'', @tgbl=''$tgbl'', @typebc=''BC40''  ')  ";
		die();
		 */
		$qry = $this->db->query("
			BEGIN TRY
			 EXEC ('spu_invoicenonhib_del_bc40_27 @nobl=''$nobl'', @tgbl=''$tgbl'', @typebc=''BC271''  ') 
			END TRY
			BEGIN CATCH 
				SELECT 
				'error' AS status
				,ERROR_MESSAGE() AS description;
				
			END CATCH;
			
		 ");
		 $rs = $qry->result_array();
        // $r = $qry->result();		
		// var_dump($r);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	
	}
	/*
	function cancel_car(){
		$id_bc_in_hdr = (isset($_POST['id_bc_in_hdr']) && !empty($_POST['id_bc_in_hdr']))?$_POST['id_bc_in_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		//$doc_in_from_id = (isset($_POST['doc_in_from_id']) && !empty($_POST['doc_in_from_id']))?$_POST['doc_in_from_id']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		
		$in_inv = $this->db->query("
			declare @nobl varchar(50), @tglbl date, @jnsinv varchar(50)
			declare @id_data_in_hdr bigint
			
			--if (select count(*) from [tbl_data_in_hdr] where id_terkait=$id_bc_in_hdr and doc_in_from_id=5) > 0 
			--begin
			--	select '06' as status, ' DATA SUDAH DIPROSES.. CANCEL DAHULU, KALO DAH APPROVE KAGAK BISA' as description
			--	return
			--end
			
			set @id_data_in_hdr = (select id_data_in_hdr from [tbl_data_in_hdr] where id_terkait=$id_bc_in_hdr and doc_in_from_id=4)
			delete from [tbl_data_in_hdr_h_status] where id_data_in_hdr = @id_data_in_hdr
			delete from [tbl_data_in_dtl] where id_data_in_hdr = @id_data_in_hdr
			delete from [tbl_data_in_hdr] where id_data_in_hdr = @id_data_in_hdr
			
			
			
			set @nobl = (select nobl from [tbl_bc_in_hdr] where id_bc_in_hdr = $id_bc_in_hdr)
			set @tglbl = (select tglbl from [tbl_bc_in_hdr] where id_bc_in_hdr = $id_bc_in_hdr)
			
						
			if (select count(*) from [dbo].[tbl_inv_hdr] where [nobl] = @nobl and [tgbl]=@tglbl) > 0
			begin
				
			    set @jnsinv='HIB'
				
			end
			if  @jnsinv = 'HIB'
			begin
				if (select count(*) from tbl_bc_in_hdr where JnsBarang = '01' and id_bc_in_hdr = $id_bc_in_hdr and bc_in_from_in='INV HIB' and nobl=@nobl and [tglbl]=@tglbl ) > 0 
				begin
					update  [dbo].[tbl_inv_hdr]  set nobl = '-', tgbl = NULL, status_inv = 0, nobc=0, car=0  where [nobl] = @nobl and [tgbl]=@tglbl

					delete from [dbo].[tbl_bc_in_hdr_h_status] where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_dtl where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_dtl_partnumber where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_dok where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_con where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_kms where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_fas where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_hdr where id_bc_in_hdr = $id_bc_in_hdr
					
				end
				
			end
			else
			begin
				delete from [dbo].[tbl_bc_in_hdr_h_status] where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_dtl where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_dok where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_con where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_kms where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_fas where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_hdr where id_bc_in_hdr = $id_bc_in_hdr
			end
			
			select '00' as status, ' SUKSES UPDATED ' + @jnsinv + '  ' + @nobl +'  '+ cast(@tglbl as varchar)  as description
				
			");
		$rs = $in_inv->result_array();
        //$r = $in_inv->result();		
		//var_dump($r);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	
	
	
	}
	*/
	
	function cancel_car(){
		$id_bc_in_hdr = (isset($_POST['id_bc_in_hdr']) && !empty($_POST['id_bc_in_hdr']))?$_POST['id_bc_in_hdr']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		//$doc_in_from_id = (isset($_POST['doc_in_from_id']) && !empty($_POST['doc_in_from_id']))?$_POST['doc_in_from_id']:die('{"sts":"ERROR","desc":" Param Tidak Ditemukan"}');
		
		
		$in_inv = $this->db->query("
			declare @nobl varchar(50), @tglbl date, @jnsinv varchar(50)
			declare @id_data_in_hdr bigint
			declare @bc_in_from_in varchar(20)
			
			if (select count(*) from [tbl_data_in_hdr] where id_terkait=$id_bc_in_hdr and doc_in_from_id=4  and [status] = 'APPROVED') > 0 
			begin
				select '06' as status, ' DATA SUDAH DIPROSES.. CANCEL DAHULU, KALO DAH APPROVE KAGAK BISA' as description
				return
			end
			
			
			set @nobl = (select nobl from [tbl_bc_in_hdr] where id_bc_in_hdr = $id_bc_in_hdr)
			set @tglbl = (select tglbl from [tbl_bc_in_hdr] where id_bc_in_hdr = $id_bc_in_hdr)
			
			set @bc_in_from_in = (select bc_in_from_in from  tbl_bc_in_hdr where id_bc_in_hdr = $id_bc_in_hdr )
			if 	@bc_in_from_in = 'COO'
			begin
				set @id_data_in_hdr = (select id_data_in_hdr from [tbl_data_in_hdr] where id_terkait=$id_bc_in_hdr and doc_in_from_id=4)
				delete from [tbl_data_in_hdr_h_status] where id_data_in_hdr = @id_data_in_hdr
				delete from [tbl_data_in_dtl] where id_data_in_hdr = @id_data_in_hdr
				delete from [tbl_data_in_hdr] where id_data_in_hdr = @id_data_in_hdr
				
				delete from [dbo].[tbl_bc_in_hdr_h_status] where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_dtl where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_dtl_partnumber where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_dok where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_con where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_kms where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_fas where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_hdr where id_bc_in_hdr = $id_bc_in_hdr
				
				
				update  [dbo].[tbl_coo_data]  set [nobl] = NULL, [tgbl] = NULL, [id_bc_in_hdr] = NULL, [nobc]=NULL, [tglbc]=NULL, [car]=NULL, [type_bc] = NULL, [status_inv] = 'NEW'
 				where nobl = @nobl and tgbl = @tglbl and id_bc_in_hdr = $id_bc_in_hdr
				select '00' as status, ' SUKSES UPDATED ' + @bc_in_from_in + ' NO GROUP/BL/SRT JLN: ' + @nobl +'  '+ cast(@tglbl as varchar)  as description
				return
			end
			
			set @id_data_in_hdr = (select id_data_in_hdr from [tbl_data_in_hdr] where id_terkait=$id_bc_in_hdr and doc_in_from_id=4)
			delete from [tbl_data_in_hdr_h_status] where id_data_in_hdr = @id_data_in_hdr
			delete from [tbl_data_in_dtl] where id_data_in_hdr = @id_data_in_hdr
			delete from [tbl_data_in_hdr] where id_data_in_hdr = @id_data_in_hdr
						
			if (select count(*) from [dbo].[tbl_inv_hdr] where [nobl] = @nobl and [tgbl]=@tglbl) > 0
			begin
				
			    set @jnsinv='HIB'
				
			end
			if  @jnsinv = 'HIB'
			begin
				if (select count(*) from tbl_bc_in_hdr where JnsBarang = '01' and id_bc_in_hdr = $id_bc_in_hdr and bc_in_from_in='INV HIB' and nobl=@nobl and [tglbl]=@tglbl ) > 0 
				begin
					update  [dbo].[tbl_inv_hdr]  set nobl = '-', tgbl = NULL, status_inv = 0, nobc=0, car=0  where [nobl] = @nobl and [tgbl]=@tglbl

					delete from [dbo].[tbl_bc_in_hdr_h_status] where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_dtl where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_dtl_partnumber where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_dok where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_con where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_kms where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_fas where id_bc_in_hdr = $id_bc_in_hdr
					delete from [dbo].tbl_bc_in_hdr where id_bc_in_hdr = $id_bc_in_hdr
					
				end
				
			end 
			else
			begin
				delete from [dbo].[tbl_bc_in_hdr_h_status] where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_dtl where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_dok where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_con where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_kms where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_fas where id_bc_in_hdr = $id_bc_in_hdr
				delete from [dbo].tbl_bc_in_hdr where id_bc_in_hdr = $id_bc_in_hdr
			end
			
			
			
			
			select '00' as status, ' SUKSES UPDATED ' + @jnsinv + '  ' + @nobl +'  '+ cast(@tglbl as varchar)  as description
				
			");
		$rs = $in_inv->result_array();
        //$r = $in_inv->result();		
		//var_dump($r);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	
	
	
	}
	
	function view_bc271_search(){
	
		$this->load->view('exim/view_bc271_search');
	
	}
	
	
	
 }