<?php
class CT_pasi_ceisa_bc_27 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');
		} 
	} 
	
	function index(){
	 	$data['bc_prefix'] ='27';
		$this->load->view('pasi_ceisa_bc_in/view_pasi_ceisa_bc_27', $data);
	} 
	 
    function loaddata(){; 
		$def_col= array();  
		$spt='dbo.SPX_HEADER_BC_27'; 
		$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"int", "bypassvalue"=>"-100");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r1","ctype"=>"int", "bypassvalue"=>"-100");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
 		$def_col['rc']=array("db" => "rc" ,"sc" => "rc","ctype"=>"text", "bypassvalue"=>"");
		$def_col['rsk']=array("db" => "rsk" ,"sc" => "rsk","ctype"=>"text", "bypassvalue"=>"");
 		$def_col['rg']=array("db" => "rg" ,"sc" => "rg","ctype"=>"int", "bypassvalue"=>"-100");
 			
 		$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']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rID'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 
  	  
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		  
		$xmldoc =  XMLbasic($spt); 
		paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
  		$adaSearchStatus=0;
		
        if ($search == 'true'){ 
            if (!empty($filters)){ 
				$array = json_decode($filters); 
                foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
	 					if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) { 
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1');  
									  if (($fcr['sc'])=='r2' || ($fcr['sc'])=='r1'){
										$adaSearchStatus=1;
									  }
								}
							 
							} 
							elseif ($fcr['ctype']=='text'){ 
					        	$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
							     addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
                 } 
             } 
	   }  
  
		if ($adaSearchStatus==0){
			addSearchNum($xmldoc,'r1','-1','3','-1'); 
		}
		$str = $xmldoc->saveXML(); 
		// print_r($adaSearchStatus);		
		// print_r($str);die();
	 	 exec_sp_json($xmldoc, 'dbo.SP_X_HEADER_BC_27',$sts,$des,$rows,$detail);  
	 	echo $rows; 
		}
		
	function edit_form(){	 
			$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
			$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('Pilih Dokumen ');   
			$cust_code = isset($_POST['cust_code'])?$_POST['cust_code']:'';  //1 add
			$data['cust_code'] = $cust_code;
			$data['id_header'] = $id_header;
			$data['bc_prefix'] = $bc_prefix;
			
			$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
			 $xmldoc =  XMLbasic('json'); 
			AddField($xmldoc ,'bc_prefix',$bc_prefix); 
			$str = $xmldoc->saveXML();  
			exec_sp_array($xmldoc, 'dbo.GET_SETTING_DEFAULT_CEISA',$sts,$des,$rows,$detail);   
			//print_r($detail);die();
			if ($sts=='00')
			$data['KURS'] = $detail['KURS'];
			else
			$data['KURS'] =1;
		
			$this->load->view('pasi_ceisa_bc_in/view_pasi_ceisa_bc_27_edit_form', $data);
	}   
	
	
	
function __purpose($bc_prefix){; 
	$spt='dbo.MG_MS_CMB_PURPOSE'; 
	$xmldoc =  XMLbasic($spt); 
		AddField($xmldoc ,'bc_prefix',$bc_prefix); 
		
	$str = $xmldoc->saveXML(); 
	// print_r($adaSearchStatus);		
	// print_r($str);die();
		wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
		return $rows; 
	}
	

function __type_item($bc_prefix){; 
	$spt='dbo.MG_MS_CMB_PURPOSE'; 
	$xmldoc =  XMLbasic($spt); 
		AddField($xmldoc ,'bc_prefix',$bc_prefix); 
		
	$str = $xmldoc->saveXML(); 
	// print_r($adaSearchStatus);		
	// print_r($str);die();
		wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
		return $rows; 
	}
	
function __type_price($bc_prefix){; 
	$spt='dbo.MG_MS_CMB_TYPE_PRICE'; 
	$xmldoc =  XMLbasic($spt); 
		AddField($xmldoc ,'bc_prefix',$bc_prefix); 
		
	$str = $xmldoc->saveXML(); 
	// print_r($adaSearchStatus);		
	// print_r($str);die();
		wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
		return $rows; 
	}
		
				

	function save_header(){  
		

		$ID_HEADER 					= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
		$NOMOR_AJU 					= isset($_POST['NOMOR_AJU'])?$_POST['NOMOR_AJU']:''; // get the requested page 
		$PJT 						= isset($_POST['PJT'])?$_POST['PJT']:''; // get the requested page 
		$NOMOR_DAFTAR 				= isset($_POST['NOMOR_DAFTAR'])?$_POST['NOMOR_DAFTAR']:''; // get the requested page 
		$TANGGAL_DAFTAR 			= isset($_POST['TANGGAL_DAFTAR'])?$_POST['TANGGAL_DAFTAR']:''; // get the requested page 
		$NOMOR_BILLING				= isset($_POST['NOMOR_BILLING'])?$_POST['NOMOR_BILLING']:''; // get the requested page 
		$TANGGAL_BILLING 			= isset($_POST['TANGGAL_BILLING'])?$_POST['TANGGAL_BILLING']:''; // get the requested page 
		$KODE_PELA_BONGKAR 			= isset($_POST['KODE_PELA_BONGKAR'])?$_POST['KODE_PELA_BONGKAR']:''; // get the requested page 
		$KODE_KANTOR_BONGKAR 		= isset($_POST['KODE_KANTOR_BONGKAR'])?$_POST['KODE_KANTOR_BONGKAR']:''; // get the requested page 
		$KODE_TUJUAN 				= isset($_POST['KODE_TUJUAN'])?$_POST['KODE_TUJUAN']:''; // get the requested page 
		$ID_PEMASOK					= isset($_POST['ID_PEMASOK'])?$_POST['ID_PEMASOK']:'';
		$KODE_ID_PEMASOK			= isset($_POST['KODE_ID_PEMASOK'])?$_POST['KODE_ID_PEMASOK']:'';
		$NAMA_PEMASOK				= isset($_POST['NAMA_PEMASOK'])?$_POST['NAMA_PEMASOK']:'';
		$ALAMAT_PEMASOK				= isset($_POST['ALAMAT_PEMASOK'])?$_POST['ALAMAT_PEMASOK']:'';
		$KODE_NEGARA_PEMASOK		= isset($_POST['KODE_NEGARA_PEMASOK'])?$_POST['KODE_NEGARA_PEMASOK']:'';
		$ID_PENERIMA_BARANG			= isset($_POST['ID_PENERIMA_BARANG'])?$_POST['ID_PENERIMA_BARANG']:'';
		$KODE_ID_PENERIMA_BARANG	= isset($_POST['KODE_ID_PENERIMA_BARANG'])?$_POST['KODE_ID_PENERIMA_BARANG']:'';
		$NAMA_PENERIMA_BARANG		= isset($_POST['NAMA_PENERIMA_BARANG'])?$_POST['NAMA_PENERIMA_BARANG']:'';
		$NOMOR_IJIN_TPB_PENERIMA	= isset($_POST['NOMOR_IJIN_TPB_PENERIMA'])?$_POST['NOMOR_IJIN_TPB_PENERIMA']:'';				
		$KODE_JENIS_API_PENERIMA	= isset($_POST['KODE_JENIS_API_PENERIMA'])?$_POST['KODE_JENIS_API_PENERIMA']:'';
		$ID_PEMILIK 				= isset($_POST['ID_PEMILIK'])?$_POST['ID_PEMILIK']:'';
		$KODE_ID_PEMILIK			= isset($_POST['KODE_ID_PEMILIK'])?$_POST['KODE_ID_PEMILIK']:'';
		$NAMA_PEMILIK				= isset($_POST['NAMA_PEMILIK'])?$_POST['NAMA_PEMILIK']:'';
		$ALAMAT_PEMILIK				= isset($_POST['ALAMAT_PEMILIK'])?$_POST['ALAMAT_PEMILIK']:'';
		$KODE_JENIS_API_PEMILIK		= isset($_POST['KODE_JENIS_API_PEMILIK'])?$_POST['KODE_JENIS_API_PEMILIK']:'';
		$ID_PPJK	 				= isset($_POST['ID_PPJK'])?$_POST['ID_PPJK']:'';
		$KODE_ID_PPJK				= isset($_POST['KODE_ID_PPJK'])?$_POST['KODE_ID_PPJK']:'';
		$NAMA_PPJK					= isset($_POST['NAMA_PPJK'])?$_POST['NAMA_PPJK']:'';
		$ALAMAT_PPJK				= isset($_POST['ALAMAT_PPJK'])?$_POST['ALAMAT_PPJK']:'';
		$CARA_ANGKUT				= isset($_POST['CARA_ANGKUT'])?$_POST['CARA_ANGKUT']:'';
		$SARANA_ANGKUT 				= isset($_POST['SARANA_ANGKUT'])?$_POST['SARANA_ANGKUT']:'';
		$NOMOR_VOY_FLIGHT			= isset($_POST['NOMOR_VOY_FLIGHT'])?$_POST['NOMOR_VOY_FLIGHT']:'';
		$KODE_NEGARA_TUJUAN			= isset($_POST['KODE_NEGARA_TUJUAN'])?$_POST['KODE_NEGARA_TUJUAN']:'';
		$KODE_PEL_MUAT 				= isset($_POST['KODE_PEL_MUAT'])?$_POST['KODE_PEL_MUAT']:'';
		$KODE_PEL_TRANSIT			= isset($_POST['KODE_PEL_TRANSIT'])?$_POST['KODE_PEL_TRANSIT']:'';
		$KODE_PEL_BONGKAR 			= isset($_POST['KODE_PEL_BONGKAR'])?$_POST['KODE_PEL_BONGKAR']:'';
		$KODE_FASILITAS				= isset($_POST['KODE_FASILITAS'])?$_POST['KODE_FASILITAS']:'';
		$KODE_LC					= isset($_POST['KODE_LC'])?$_POST['KODE_LC']:'';
		$KODE_AWB					= isset($_POST['KODE_AWB'])?$_POST['KODE_AWB']:'';
		$KODE_BC11					= isset($_POST['KODE_BC11'])?$_POST['KODE_BC11']:'';
		$TANGGAL_BC11				= isset($_POST['TANGGAL_BC11'])?$_POST['TANGGAL_BC11']:'';
		$SUBPOS_BC11				= isset($_POST['SUBPOS_BC11'])?$_POST['SUBPOS_BC11']:'';
		$SUBSUBPOS_BC11				= isset($_POST['SUBSUBPOS_BC11'])?$_POST['SUBSUBPOS_BC11']:'';
		$PENIMBUNAN					= isset($_POST['PENIMBUNAN'])?$_POST['PENIMBUNAN']:'';
		$KODE_VALUTA				= isset($_POST['KODE_VALUTA'])?$_POST['KODE_VALUTA']:''; // get the requested page 
		$NDPBM						= isset($_POST['NDPBM'])?$_POST['NDPBM']:'0'; // get the requested page 
		$FOB						= isset($_POST['FOB'])?$_POST['FOB']:'0';
		$FREIGHT 					= isset($_POST['FREIGHT'])?$_POST['FREIGHT']:'0'; // get the requested page 
		$KODE_ASURANSI 				= isset($_POST['KODE_ASURANSI'])?$_POST['KODE_ASURANSI']:''; // get the requested page 
		$ASURANSI 					= isset($_POST['ASURANSI'])?$_POST['ASURANSI']:'0'; // get the requested page 
		$CIF 						= isset($_POST['CIF'])?$_POST['CIF']:'0';
		$CIF_RUPIAH 				= isset($_POST['CIF_RUPIAH'])?$_POST['CIF_RUPIAH']:'0';
		$JUMLAH_KONTAINER			= isset($_POST['JUMLAH_KONTAINER'])?$_POST['JUMLAH_KONTAINER']:'0'; // get the requested page 
		$JUMLAH_KEMASAN				= isset($_POST['JUMLAH_KEMASAN'])?$_POST['JUMLAH_KEMASAN']:'0';
		$JUMLAH_BARANG 				= isset($_POST['JUMLAH_BARANG'])?$_POST['JUMLAH_BARANG']:'0'; // get the requested page 
		$BRUTO		 				= isset($_POST['BRUTO'])?$_POST['BRUTO']:'0'; // get the requested page 
		$NETTO						= isset($_POST['NETTO'])?$_POST['NETTO']:'0'; // get the requested page 
		$VOLUME						= isset($_POST['VOLUME'])?$_POST['VOLUME']:'0'; // get the requested page 
		$KEMASAN	 				= isset($_POST['KEMASAN'])?$_POST['KEMASAN']:''; // get the requested page 
		$KODE_DOKUMEN_PABEAN		= isset($_POST['KODE_DOKUMEN_PABEAN'])?$_POST['KODE_DOKUMEN_PABEAN']:''; // get the requested page 
			



			
				$SPT='SP_X_BC_IN_23_UPDATE'; //'SP_T_BC_FROM_PO_CREATEX';  //($ID_HEADER=='-1')?'SP_T_BC_FROM_PO_CREATEX':'SP_T_BC_FROM_PO_CREATEX';
				
				$xmldoc =  XMLbasic('json');  
				AddField($xmldoc ,'ID_HEADER',$ID_HEADER);// get the requested page 
				AddField($xmldoc ,'NOMOR_AJU',$NOMOR_AJU); // get the requested page 
				AddField($xmldoc ,'PJT',$PJT); // get the requested page 
				AddField($xmldoc ,'NOMOR_DAFTAR',$NOMOR_DAFTAR); // get the requested page 
				AddField($xmldoc ,'TANGGAL_DAFTAR',$TANGGAL_DAFTAR); // get the requested page 
				AddField($xmldoc ,'NOMOR_BILLING',$NOMOR_BILLING); // get the requested page 
				AddField($xmldoc ,'TANGGAL_BILLING',$TANGGAL_BILLING); // get the requested page 
				AddField($xmldoc ,'KODE_ASAL_BARANG',$KODE_PELA_BONGKAR); // get the requested page 
				AddField($xmldoc ,'KODE_KANTOR_BONGKAR',$KODE_KANTOR_BONGKAR); // get the requested page 
				AddField($xmldoc ,'KODE_TUJUAN',$KODE_TUJUAN); // get the requested page 
				AddField($xmldoc ,'ID_PEMASOK',$ID_PEMASOK);
				AddField($xmldoc ,'KODE_ID_PEMASOK',$KODE_ID_PEMASOK);
				AddField($xmldoc ,'NAMA_PEMASOK',$NAMA_PEMASOK);
				AddField($xmldoc ,'ALAMAT_PEMASOK',$ALAMAT_PEMASOK);
				AddField($xmldoc ,'KODE_NEGARA_PEMASOK',$KODE_NEGARA_PEMASOK);
				AddField($xmldoc ,'ID_PENERIMA_BARANG',$ID_PENERIMA_BARANG);
				AddField($xmldoc ,'KODE_ID_PENERIMA_BARANG',$KODE_ID_PENERIMA_BARANG);
				AddField($xmldoc ,'NAMA_PENERIMA_BARANG',$NAMA_PENERIMA_BARANG);
				AddField($xmldoc ,'NOMOR_IJIN_TPB_PENERIMA',$NOMOR_IJIN_TPB_PENERIMA);				
				AddField($xmldoc ,'KODE_JENIS_API_PENERIMA',$KODE_JENIS_API_PENERIMA);
				AddField($xmldoc ,'ID_PEMILIK',$ID_PEMILIK);
				AddField($xmldoc ,'KODE_ID_PEMILIK',$KODE_ID_PEMILIK);
				AddField($xmldoc ,'NAMA_PEMILIK',$NAMA_PEMILIK);
				AddField($xmldoc ,'ALAMAT_PEMILIK',$ALAMAT_PEMILIK);
				AddField($xmldoc ,'KODE_JENIS_API_PEMILIK',$KODE_JENIS_API_PEMILIK);
				AddField($xmldoc ,'ID_PPJK',$ID_PPJK);
				AddField($xmldoc ,'KODE_ID_PPJK',$KODE_ID_PPJK);
				AddField($xmldoc ,'NAMA_PPJK',$NAMA_PPJK);
				AddField($xmldoc ,'ALAMAT_PPJK',$ALAMAT_PPJK);
				AddField($xmldoc ,'CARA_ANGKUT',$CARA_ANGKUT);
				AddField($xmldoc ,'SARANA_ANGKUT',$SARANA_ANGKUT);
				AddField($xmldoc ,'NOMOR_VOY_FLIGHT',$NOMOR_VOY_FLIGHT);
				AddField($xmldoc ,'KODE_NEGARA_TUJUAN',$KODE_NEGARA_TUJUAN);
				AddField($xmldoc ,'KODE_PEL_MUAT',$KODE_PEL_MUAT);
				AddField($xmldoc ,'KODE_PEL_TRANSIT',$KODE_PEL_TRANSIT);
				AddField($xmldoc ,'KODE_PEL_BONGKAR',$KODE_PEL_BONGKAR);
				AddField($xmldoc ,'KODE_FASILITAS',$KODE_FASILITAS);
				AddField($xmldoc ,'KODE_LC',$KODE_LC);
				AddField($xmldoc ,'KODE_AWB',$KODE_AWB);
				AddField($xmldoc ,'KODE_BC11',$KODE_BC11);
				AddField($xmldoc ,'TANGGAL_BC11',$TANGGAL_BC11);
				AddField($xmldoc ,'SUBPOS_BC11',$SUBPOS_BC11);
				AddField($xmldoc ,'SUBSUBPOS_BC11',$SUBSUBPOS_BC11);
				AddField($xmldoc ,'PENIMBUNAN',$PENIMBUNAN);
				AddField($xmldoc ,'KODE_VALUTA',$KODE_VALUTA); // get the requested page 
				AddField($xmldoc ,'NDPBM',$NDPBM); // get the requested page 
				AddField($xmldoc ,'FOB',$FOB);
				AddField($xmldoc ,'FREIGHT',$FREIGHT); // get the requested page 
				AddField($xmldoc ,'KODE_ASURANSI',$KODE_ASURANSI); // get the requested page 
				AddField($xmldoc ,'ASURANSI',$ASURANSI); // get the requested page 
				AddField($xmldoc ,'CIF',$CIF);
				AddField($xmldoc ,'CIF_RUPIAH',$CIF_RUPIAH);
				AddField($xmldoc ,'JUMLAH_KONTAINER',$JUMLAH_KONTAINER); // get the requested page 
				AddField($xmldoc ,'JUMLAH_KEMASAN',$JUMLAH_KEMASAN);
				AddField($xmldoc ,'JUMLAH_BARANG',$JUMLAH_BARANG); // get the requested page 
				AddField($xmldoc ,'BRUTO',$BRUTO); // get the requested page 
				AddField($xmldoc ,'NETTO',$NETTO); // get the requested page 
				AddField($xmldoc ,'VOLUME',$VOLUME); // get the requested page 
				AddField($xmldoc ,'KEMASAN',$KEMASAN); // get the requested page 
				AddField($xmldoc ,'KODE_DOKUMEN_PABEAN',$KODE_DOKUMEN_PABEAN); // get the requested page 
				AddField($xmldoc ,'bc_prefix','23'); // get the requested page 


				
				$str = $xmldoc->saveXML();
					// print_r($str);die();
				exec_sp_array($xmldoc, $SPT ,$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false)
				,'stsno' => $sts
				, 'stsmsg' => $des
				, 'detail' => $detail)
				); 
		}
		
	 function finish_header(){  
	
	
			$ID_HEADER 				= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
			$receive_no 					= isset($_POST['receive_no'])?$_POST['receive_no']:''; // get the requested page 
			$receive_date 			= isset($_POST['receive_date'])?$_POST['receive_date']:''; // get the requested page 
	
			$ndpbm_usd 			= isset($_POST['ndpbm_usd'])?$_POST['ndpbm_usd']:'0'; // get the requested page 
			$ndpbm_hdr 			= isset($_POST['ndpbm_hdr'])?$_POST['ndpbm_hdr']:'0'; // get the requested page 
		
			$finish_date 			= isset($_POST['finish_date'])?$_POST['finish_date']:''; // get the requested page 
			$finish_time 			= isset($_POST['finish_time'])?$_POST['finish_time']:''; // get the requested page 
						
			$SPT='MG_MS_BC_IN_FINISH';
			
			$xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'ID_HEADER',$ID_HEADER );
			AddField($xmldoc ,'receive_no',$receive_no );
			AddField($xmldoc ,'receive_date',$receive_date );
			AddField($xmldoc ,'ndpbm_usd',$ndpbm_usd );
			AddField($xmldoc ,'ndpbm_hdr',$ndpbm_hdr );
			AddField($xmldoc ,'finish_date',$finish_date );
			AddField($xmldoc ,'finish_time',$finish_time );
				
			$str = $xmldoc->saveXML();
				// print_r($str);die();
				wh_exec_sp_array($xmldoc, $SPT ,$sts,$des,$rows,$detail); 
			echo json_encode(array('valid'=>($sts=='00'?true:false)
			,'stsno' => $sts
			, 'stsmsg' => $des
			, 'detail' => $detail)
			); 
	}
					
	 function cancel_header(){  
					
	
			$ID_HEADER 				= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
			$info 					= isset($_POST['info'])?$_POST['info']:''; // get the requested page 
						
			$SPT='MG_MS_BC_IN_CANCEL';
			
			$xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'ID_HEADER',$ID_HEADER );
			AddField($xmldoc ,'info',$info ); 
				
			$str = $xmldoc->saveXML();
				// print_r($str);die();
				wh_exec_sp_array($xmldoc, $SPT ,$sts,$des,$rows,$detail); 
			echo json_encode(array('valid'=>($sts=='00'?true:false)
			,'stsno' => $sts
			, 'stsmsg' => $des
			, 'detail' => $detail)
			); 
	}
	
	function save_detail(){  
					
		
		$ID_HEADER 				= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
		$ID_BARANG 				= isset($_POST['ID_BARANG'])?$_POST['ID_BARANG']:'-1'; // get the requested page 

		$HARGA_PENYERAHAN 		= isset($_POST['HARGA_PENYERAHAN'])?$_POST['HARGA_PENYERAHAN']:''; // get the requested page 
		$JUMLAH_KEMASAN 		= isset($_POST['JUMLAH_KEMASAN'])?$_POST['JUMLAH_KEMASAN']:''; // get the requested page 
		$JUMLAH_SATUAN 			= isset($_POST['JUMLAH_SATUAN'])?$_POST['JUMLAH_SATUAN']:''; // get the requested page 
		$KODE_KEMASAN 			= isset($_POST['KODE_KEMASAN'])?$_POST['KODE_KEMASAN']:'0'; // get the requested page 
		$NETTO 					= isset($_POST['NETTO'])?$_POST['NETTO']:'0'; // get the requested page 
		$POS_TARIF 				= isset($_POST['POS_TARIF'])?$_POST['POS_TARIF']:'0'; // get the requested page 
		$SERI_BARANG 			= isset($_POST['SERI_BARANG'])?$_POST['SERI_BARANG']:'0'; // get the requested page 
		$VOLUME 				= isset($_POST['VOLUME'])?$_POST['VOLUME']:''; // get the requested page 
		$ms_item_id 			= isset($_POST['ms_item_id'])?$_POST['ms_item_id']:'-1'; // get the requested page 
		$KODE_NEGARA_ASAL 		= isset($_POST['KODE_NEGARA_ASAL'])?$_POST['KODE_NEGARA_ASAL']:''; // get the requested page 
			
			$BM 		= isset($_POST['BM'])?$_POST['BM']:''; // get the requested page 
		$PPNBM 	= isset($_POST['PPNBM'])?$_POST['PPNBM']:''; // get the requested page 
		$PPH 					= isset($_POST['PPH'])?$_POST['PPH']:''; // get the requested page 
			$PPN 					= isset($_POST['PPN'])?$_POST['PPN']:''; // get the requested page 
			$series 					= isset($_POST['series'])?$_POST['series']:''; // get the requested page 
			$TAHUN_PEMBUATAN 					= isset($_POST['TAHUN_PEMBUATAN'])?$_POST['TAHUN_PEMBUATAN']:''; // get the requested page 
			$po_no 					= isset($_POST['po_no'])?$_POST['po_no']:''; // get the requested page 
			$po_date 					= isset($_POST['po_date'])?$_POST['po_date']:''; // get the requested page 
		
		$SPT=($ID_BARANG=='-1')?'MG_MS_BC_IN_ITEM_ADD':'MG_MS_BC_IN_ITEM_EDIT';
		
		$xmldoc =  XMLbasic('json');  
		AddField($xmldoc ,'ID_HEADER',$ID_HEADER );
		AddField($xmldoc ,'ID_BARANG',$ID_BARANG );
		AddField($xmldoc ,'HARGA_PENYERAHAN',$HARGA_PENYERAHAN );
		AddField($xmldoc ,'JUMLAH_KEMASAN',$JUMLAH_KEMASAN );
		AddField($xmldoc ,'JUMLAH_SATUAN',$JUMLAH_SATUAN ); 
		AddField($xmldoc ,'KODE_KEMASAN',$KODE_KEMASAN ); 
		AddField($xmldoc ,'NETTO',$NETTO ); 
		AddField($xmldoc ,'POS_TARIF',$POS_TARIF ); 
		AddField($xmldoc ,'SERI_BARANG',$SERI_BARANG ); 
		AddField($xmldoc ,'VOLUME',$VOLUME ); 
		AddField($xmldoc ,'ms_item_id',$ms_item_id ); 
		AddField($xmldoc ,'KODE_NEGARA_ASAL',$KODE_NEGARA_ASAL ); 
		AddField($xmldoc ,'BM',$BM ); 
		AddField($xmldoc ,'PPNBM',$PPNBM ); 
		AddField($xmldoc ,'PPH',$PPH ); 
		AddField($xmldoc ,'PPN',$PPN );  ; 
		AddField($xmldoc ,'series',$series ); 
		AddField($xmldoc ,'TAHUN_PEMBUATAN',$TAHUN_PEMBUATAN );  
		AddField($xmldoc ,'po_no',$po_no ); 
		AddField($xmldoc ,'po_date',$po_date );  
		
		$str = $xmldoc->saveXML();
		// print_r($str);die();
			wh_exec_sp_array($xmldoc, $SPT ,$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false)
		,'stsno' => $sts
		, 'stsmsg' => $des
		, 'detail' => $detail)
		); 
		}
		
		
	function delete_detail(){  
		
		
		$ID_HEADER 				= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
		$ID_BARANG 				= isset($_POST['ID_BARANG'])?$_POST['ID_BARANG']:'-1'; // get the requested page 
	
		$SPT='MG_MS_BC_IN_ITEM_DELETE';
		
		$xmldoc =  XMLbasic('json');  
		AddField($xmldoc ,'ID_HEADER',$ID_HEADER );
		AddField($xmldoc ,'ID_BARANG',$ID_BARANG );
		
		$str = $xmldoc->saveXML();
		// print_r($str);die();
			wh_exec_sp_array($xmldoc, $SPT ,$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false)
		,'stsno' => $sts
		, 'stsmsg' => $des
		, 'detail' => $detail)
		); 
		}
		
		
			function mapping_all_item(){   
				$ID_HEADER 				= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
					$SPT='MG_MS_BC_IN_ITEM_MAPPING_AUTO';
				
				$xmldoc =  XMLbasic('json');  
				AddField($xmldoc ,'ID_HEADER',$ID_HEADER ); 
					
				$str = $xmldoc->saveXML();
					// print_r($str);die();
					wh_exec_sp_array($xmldoc, $SPT ,$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false)
				,'stsno' => $sts
				, 'stsmsg' => $des
				, 'detail' => $detail)
				); 
		}
		
					
	function create_bc_molts(){
			$supplier_id = isset($_POST['supplier_id'])?$_POST['supplier_id']:die('Pilih Customer');; // get the requested page 
				$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:die('Type BC tidak di ketahui');; // get the requested page 
			$lst_id = isset($_POST['lst_id'])?$_POST['lst_id']:die('pilih SA penyusun Dokument');; // get the requested page 
		
			$xmldoc =  XMLbasic('json'); 
			AddField($xmldoc ,'ms_supplier_customer_id',$supplier_id);
			AddField($xmldoc ,'bc_prefix',$bc_prefix); 
			
			for ($i = 0; $i <  count($lst_id); $i++) {
				$this->_insert_id_to_field($xmldoc,$lst_id[$i]);
			} 
			$str = $xmldoc->saveXML();  
		//print_r($str);die();
			wh_exec_sp_array($xmldoc, 'dbo.MG_MS_BC_IN_IMPORT_FROM_MOLTS',$sts,$des,$rows,$detail); 
			echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}
		
		
	function create_bc_invoce(){
			$supplier_id = isset($_POST['supplier_id'])?$_POST['supplier_id']:die('Pilih Customer');; // get the requested page 
				$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:die('Type BC tidak di ketahui');; // get the requested page 
			$lst_id = isset($_POST['lst_id'])?$_POST['lst_id']:die('pilih SA penyusun Dokument');; // get the requested page 
			$ms_manual_invoice_type_id = isset($_POST['invoice_prefix_id'])?$_POST['invoice_prefix_id']:'-1'; // get the direction 
				$KODE_VALUTA = isset($_POST['KODE_VALUTA'])?$_POST['KODE_VALUTA']:'-1'; // get the direction 
		
			$xmldoc =  XMLbasic('json'); 
			AddField($xmldoc ,'ms_supplier_customer_id',$supplier_id);
			AddField($xmldoc ,'bc_prefix',$bc_prefix); 
			AddField($xmldoc ,'ms_manual_invoice_type_id',$ms_manual_invoice_type_id); 
			AddField($xmldoc ,'KODE_VALUTA',$KODE_VALUTA); 
			
			for ($i = 0; $i <  count($lst_id); $i++) {
				$this->_insert_id_to_field($xmldoc,$lst_id[$i]);
			} 
			$str = $xmldoc->saveXML();  
			wh_exec_sp_array($xmldoc, 'dbo.MG_MS_BC_IN_IMPORT_FROM_INVOICE',$sts,$des,$rows,$detail); 
			echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}
 

 }