<?php
class CT_incomingitem 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_bc23", 'mdl_bc23');
		$this->load->model("inventory/mdl_incoming", 'mdl_incoming');
	}

	function index(){
		
		$this->load->view('inventory/view_incomingitem');
	
	}
	
	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']:'tbl_data_in_hdr.id_data_in_hdr'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction	
		
		$where = " tbl_data_in_hdr.doc_in_from_id IN (2,3,4,5) ";
		
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){
					
					if ( $k->field == "doc_in_no" ) {
						$searchString = $k->data;
						$where .= " and tbl_data_in_hdr.doc_in_no like  '%".$searchString."%'"; 
					} else if ( $k->field == "doc_in_date" ) {
						$searchString = $k->data;
						$where .= " and tbl_data_in_hdr.doc_in_date =  '$searchString'"; 
					} else if ( $k->field == "doc_in_from_name" ) {
						$searchString = $k->data;
						$where .= " and enum_data_in_from.doc_in_from_name like  '%".$searchString."%'"; 
					} else if ( $k->field == "noinv" ) {
						$searchString = $k->data;
						$where .= " and tbl_bc_in_hdr.noinv like  '%".$searchString."%'"; 
					}  else if ( $k->field == "tginv" ) {
						$searchString = $k->data;
						$where .= " and tbl_bc_in_hdr.tginv  =  '$searchString'"; 
					} else if ( $k->field == "nobl" ) {
						$searchString = $k->data;
						$where .= " and tbl_bc_in_hdr.nobl like  '%".$searchString."%'"; 
					}  else if ( $k->field == "tglbl" ) {
						$searchString = $k->data;
						$where .= " and tbl_bc_in_hdr.tglbl  =  '$searchString'"; 
					} else if ( $k->field == "status" ) {
						$searchString = $k->data;
						$where .= " and tbl_data_in_hdr.status like  '%".$searchString."%'"; 
					} 
				}
			}
		}
		
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_incoming->dataincoming_all($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_incoming->dataincoming_CountAll($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){
			$responce->rows[$i]['id_data_in_hdr']=$r->id_data_in_hdr; 
			$responce->rows[$i]['doc_in_no']=$r->doc_in_no; 
			$responce->rows[$i]['doc_in_date']=$r->doc_in_date; 
			$responce->rows[$i]['status']=$r->status;
			$responce->rows[$i]['doc_in_from_name']=$r->doc_in_from_name;
			$responce->rows[$i]['id_terkait']=$r->id_terkait;
			$responce->rows[$i]['id_bc_in_hdr']=$r->id_bc_in_hdr;
			$responce->rows[$i]['noinv']=$r->noinv;
			$responce->rows[$i]['tginv']=$r->tginv;
			$responce->rows[$i]['nobl']=$r->nobl;
			$responce->rows[$i]['tglbl']=$r->tglbl;
			$responce->rows[$i]['doc_in_from_id']=$r->doc_in_from_id;
			$i++;
		}
		echo json_encode($responce);
		
	}
	
	function viewcreatedata_incoming(){
	
		$this->load->view('inventory/view_incoming_create_item');
		
	}
	
	function loaddatadokbc(){
		$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 = " statusdok = 'DATA SENT TO INVENTORY' ";
		
		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 tginv =  '$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_incoming->bchdrdataAll($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_incoming->bchdrdataCountAll($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]['tglbl']=$r->tglbl;
			$responce->rows[$i]['nobl']=$r->nobl;
			$i++;
		}
		echo json_encode($responce);
	}
	
	function view_incoming_item_sumary(){
	
		$idhdrbc23 = (isset($_POST['idhdrbc23']) && !empty($_POST['idhdrbc23']))?$_POST['idhdrbc23']:die('{"sts":"ERROR","desc":" Param idhdrbc23 Tidak Ditemukan"}');
		
		// if ($nobc23 == ""){
			// $nobc23 = 'KOSONG';
		// }
		
		$data["idhdrbc23"] = $idhdrbc23;
	
		
		$this->load->view('inventory/view_incoming_item_sumary',$data);
	
	}
	
	function approvedincoming(){
	
		$id_hdr = (isset($_POST['id_hdr']) && !empty($_POST['id_hdr']))?$_POST['id_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"}');
		//echo $doc_in_from_id; die();
		
		$in_inv = $this->db->query("
			
			EXEC [spi_incoming] 
			@id_hdr = $id_hdr, @doc_in_from_id = $doc_in_from_id
			");
		$rs = $in_inv->result_array();
        //$r = $in_inv->result();		
		//var_dump($rs);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	
	
	}
	
	function view_incoming_approved(){
		$idx = (isset($_POST['idx']) && !empty($_POST['idx']))?$_POST['idx']:die('{"sts":"ERROR","desc":" Param idx 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 doc_in_from_id Tidak Ditemukan"}');
		$doc_in_no = (isset($_POST['doc_in_no']) && !empty($_POST['doc_in_no']))?$_POST['doc_in_no']:die('{"sts":"ERROR","desc":" Param doc_in_no Tidak Ditemukan"}');
		$idterkait = (isset($_POST['idterkait']) && !empty($_POST['idterkait']))?$_POST['idterkait']:die('{"sts":"ERROR","desc":" Param idterkait Tidak Ditemukan"}');
		$typedok = (isset($_POST['typedok']) && !empty($_POST['typedok']))?$_POST['typedok']:die('{"sts":"ERROR","desc":" Param typedok Tidak Ditemukan"}');
		$doc_in_date = (isset($_POST['doc_in_date']) && !empty($_POST['doc_in_date']))?$_POST['doc_in_date']:'';
		$noinv = (isset($_POST['noinv']) && !empty($_POST['noinv']))?$_POST['noinv']:'';
		$tginv = (isset($_POST['tginv']) && !empty($_POST['tginv']))?$_POST['tginv']:'';
		
		$car='';
		$bcno = '';
		$bctg='';
	
			$q = $this->db->query("
				select  
				CAR
				,[BC23No]
				,convert(varchar,[BC23Tg],101) as BC23Tg
				FROM [dbo].[tbl_bc_in_hdr] where [typedok]='$typedok' and id_bc_in_hdr=$idterkait
			");
			$rs = $q->result_array();
			
			$car='';
			$bcno = '';
			$bctg='';
			foreach ($rs as $row){
				$car = $row['CAR'];	
				$bcno = $row['BC23No'];	
				$bctg = $row['BC23Tg'];	
			}
			
		$data["idx"] = $idx;
		$data["doc_in_from_id"] = $doc_in_from_id;
		$data["doc_in_no"] = $doc_in_no;
		$data["typedok"] = $typedok;
		$data["doc_in_date"] = $doc_in_date;
		$data["noinv"] = $noinv;
		$data["tginv"] = $tginv;
		$data["idterkait"] = $idterkait;
		
		$data["car"] = $car;
		$data["bcno"] = $bcno;
		$data["bctg"] = $bctg;
		
		$this->load->view('inventory/view_incoming_approved',$data);
	
	
	}
	function incoming_data_approved(){
		$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"}');
		$doc_in_no = (isset($_POST['doc_in_no']) && !empty($_POST['doc_in_no']))?$_POST['doc_in_no']:die('{"sts":"ERROR","desc":" Param  Tidak Ditemukan"}');
		$incoming_recieve_date = (isset($_POST['incoming_recieve_date']) && !empty($_POST['incoming_recieve_date']))?$_POST['incoming_recieve_date']:die('{"sts":"ERROR","desc":" Param  DATE Tidak Ditemukan"}');
		$id_data_in_hdr = (isset($_POST['id_data_in_hdr']) && !empty($_POST['id_data_in_hdr']))?$_POST['id_data_in_hdr']:die('{"sts":"ERROR","desc":" Param  id_data_in_hdr Tidak Ditemukan"}');
		$id_terkait = (isset($_POST['id_terkait']) && !empty($_POST['id_terkait']))?$_POST['id_terkait']:die('{"sts":"ERROR","desc":" Param  id_terkait Tidak Ditemukan"}');
		
		
		if (strlen($incoming_recieve_date) != 10){
			echo '{"sts":"ERROR","desc":" Tanggal Salah"}';
			die();
		} 
		
		$pos = strpos($incoming_recieve_date, '/');
		
		if ($pos != 2) {
				echo '{"sts":"ERROR","desc":" Tanggal Salah"}';
				die();
			}
		
		$user = $this->session->userdata('DX_user_id');
		
		$in_inv = $this->db->query("
			
			EXEC [spi_incoming_approved] 
			@doc_in_from_id = $doc_in_from_id,
			@doc_in_no = '$doc_in_no',
			@doc_in_date = '$incoming_recieve_date',
			@id_data_in_hdr = $id_data_in_hdr,
			@id_terkait = $id_terkait,
			@user = $user
			");
		$rs = $in_inv->result_array();
        //$r = $in_inv->result();		
		//var_dump($rs);die();
		foreach ($rs as $row){
			$responce = array("sts" => $row['status'], "desc" => $row['description']);
		}  
		echo json_encode($responce);
	
		
	
	}
	
	function view_incoming_dtl(){
	
		
		$id_incominghdr = (isset($_POST['id_incominghdr']) && !empty($_POST['id_incominghdr']))?$_POST['id_incominghdr']:die('{"sts":"ERROR","desc":" Param id_incominghdr Tidak Ditemukan"}');
		$data["id_incominghdr"] = $id_incominghdr;
		$this->load->view('inventory/view_incoming_dtl',$data);
	
	}
	
	function data_incoming_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_data_in_dtl'; // get index row - i.e. user click to sort
        $sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction
		
		$id_incominghdr = (isset($_POST['id_incominghdr']) && !empty($_POST['id_incominghdr']))?$_POST['id_incominghdr']:die('{"sts":"ERROR","desc":" Param id_incominghdr Tidak Ditemukan"}');
		
		$where = " id_data_in_hdr=$id_incominghdr ";
		
		if ($search == 'true'){
			if (!empty($filters)){
				$array = json_decode($filters);
				foreach($array->rules as $arr=>$k){
					
					if ( $k->field == "part_name_customs" ) {
						$searchString = $k->data;
						$where .= " and part_name_customs like  '%".$searchString."%'"; 
					} else if ( $k->field == "part_number" ) {
						$searchString = $k->data;
						$where .= " and part_number like  '%".$searchString."%'"; 
					} else if ( $k->field == "qty_in" ) {
						$searchString = $k->data;
						$where .= " and qty_in =  $searchString"; 
					} else if ( $k->field == "unit_in" ) {
						$searchString = $k->data;
						$where .= " and unit_in like  '%".$searchString."%'"; 
					}  else if ( $k->field == "box" ) {
						$searchString = $k->data;
						$where .= " and box  =  $searchString"; 
					}  else if ( $k->field == "pack" ) {
						$searchString = $k->data;
						$where .= " and pack =  $searchString";
					} 
				}
			}
		}
		
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->mdl_incoming->data_incoming_dtl_All($limit,$start,$sidx,$sord, $where);
        $count = $this->mdl_incoming->data_incoming_dtl_CountAll($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){
			$responce->rows[$i]['id_data_in_dtl']=$r->id_data_in_dtl; 
			$responce->rows[$i]['id_data_in_hdr']=$r->id_data_in_hdr; 
			$responce->rows[$i]['doc_in_from_id']=$r->doc_in_from_id; 
			$responce->rows[$i]['id_part_number']=$r->id_part_number;
			$responce->rows[$i]['part_name_customs']=$r->part_name_customs;
			$responce->rows[$i]['part_number']=$r->part_number;
			$responce->rows[$i]['qty_in']=$r->qty_in;
			$responce->rows[$i]['qty_out']=$r->qty_out;
			$responce->rows[$i]['unit_in']=$r->unit_in;
			$responce->rows[$i]['unit_konversi']=$r->unit_konversi;
			$responce->rows[$i]['pengali']=$r->pengali;
			$responce->rows[$i]['box']=$r->box;
			$responce->rows[$i]['pack']=$r->pack;
			$responce->rows[$i]['harga']=$r->harga;
			$responce->rows[$i]['kdval']=$r->kdval;
			$responce->rows[$i]['type_brg']=$r->type_brg;
			$i++;
		}
		echo json_encode($responce);
		
	
	}
	
	
	
	
  
  
  
 }