<?php
$message 	 	= array();
$Act         	= isset($_REQUEST['Act']) ? $_REQUEST['Act'] : '';
$nomor          = isset($_REQUEST['nomor']) ? $_REQUEST['nomor'] : '';
$no_sj   		= isset($_REQUEST['no_sj']) ? $_REQUEST['no_sj'] : '';
$tgl_sj   		= isset($_REQUEST['tgl_sj']) ? $_REQUEST['tgl_sj'] : '';
$penerima 		= isset($_REQUEST['penerima']) ? $_REQUEST['penerima'] : '';
$no_invoice     = isset($_REQUEST['no_invoice']) ? $_REQUEST['no_invoice'] : '';
$tgl_invoice 	= isset($_REQUEST['tgl_invoice']) ? $_REQUEST['tgl_invoice'] : '';
$no_do 		    = isset($_REQUEST['no_do']) ? $_REQUEST['no_do'] : '';
$catatan 		= isset($_REQUEST['catatan']) ? $_REQUEST['catatan'] : '';
$jenis_dokpab 	= isset($_REQUEST['jenis_dokpab']) ? $_REQUEST['jenis_dokpab'] : '';
$no_dokpab 		= isset($_REQUEST['no_dokpab']) ? $_REQUEST['no_dokpab'] : '';
$tgl_dokpab 	= isset($_REQUEST['tgl_dokpab']) ? $_REQUEST['tgl_dokpab'] : '';
$pilih			= isset($_REQUEST['pilih']) ? $_REQUEST['pilih'] : '';
$pilih_reg		= isset($_REQUEST['pilih_reg']) ? $_REQUEST['pilih_reg'] : '';
$start_date		= isset($_REQUEST['start_date']) ? $_REQUEST['start_date'] : get_startdate();
$end_date		= isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : get_enddate();
$sumber			= isset($_REQUEST['sumber']) ? $_REQUEST['sumber'] : '';
$s_kat	    	= isset($_REQUEST['s_kat']) ? $_REQUEST['s_kat'] : '';
$s_name	    	= isset($_REQUEST['s_name']) ? $_REQUEST['s_name'] : '';
$tmp_id_header 	= isset($_REQUEST['tmp_id_header']) ? $_REQUEST['tmp_id_header'] : '';
$tmp_no_urut   	= isset($_REQUEST['tmp_no_urut']) ? $_REQUEST['tmp_no_urut'] : '';
$new_nomor 		= get_nomorout(1);
$new_nosj 		= get_nosjout(1);
//echo "$new_nomor==>$new_nosj";
$Act_Det 	 	= isset($_REQUEST['Act_Det']) ? $_REQUEST['Act_Det'] : '';
$outh_id 	 	= isset($_REQUEST['outh_id']) ? $_REQUEST['outh_id'] : '';
$outh_sjdate	= isset($_REQUEST['outh_sjdate']) ? $_REQUEST['outh_sjdate'] : '';
$cust_id    	= isset($_REQUEST['cust_id']) ? $_REQUEST['cust_id'] : '';
$cust_name   	= isset($_REQUEST['cust_name']) ? $_REQUEST['cust_name'] : '';
$outh_invno  	= isset($_REQUEST['outh_invno']) ? $_REQUEST['outh_invno'] : '';
$outh_invdate	= isset($_REQUEST['outh_invdate']) ? $_REQUEST['outh_invdate'] : '';
$outh_dono		= isset($_REQUEST['outh_dono']) ? $_REQUEST['outh_dono'] : '';
$tujuan	= isset($_REQUEST['tujuan']) ? $_REQUEST['tujuan'] : '';
$outh_docid	 	= isset($_REQUEST['outh_docid']) ? $_REQUEST['outh_docid'] : '';
$outh_docdate	= isset($_REQUEST['outh_docdate']) ? $_REQUEST['outh_docdate'] : '';
$outh_docno		= isset($_REQUEST['outh_docno']) ? $_REQUEST['outh_docno'] : '';
$id_det			= isset($_REQUEST['id_det']) ? $_REQUEST['id_det'] : '';
$id_deth		= isset($_REQUEST['id_deth']) ? $_REQUEST['id_deth'] : '';
$no_aju			= isset($_REQUEST['no_aju']) ? $_REQUEST['no_aju'] : '';
$tgl_aju		= isset($_REQUEST['tgl_aju']) ? $_REQUEST['tgl_aju'] : '';
$no_npe			= isset($_REQUEST['no_npe']) ? $_REQUEST['no_npe'] : '';
$tgl_npe		= isset($_REQUEST['tgl_npe']) ? $_REQUEST['tgl_npe'] : '';
$doc			= mysql_fetch_array(mysql_query("SELECT doc_type FROM document_type WHERE id='$outh_docid'"));
$cust			= mysql_fetch_array(mysql_query("SELECT cust_name FROM customer WHERE id='$cust_id'"));
$val_date       = get_validationdate($outh_docdate);
//if(empty($outh_id)){ 
	//$outh_sjno = get_sjno();
//}else{
	$outh_sjno = isset($_REQUEST['outh_sjno']) ? $_REQUEST['outh_sjno'] : get_sjno();
//}
$outd_prodid      = isset($_REQUEST['prodid']) ? $_REQUEST['prodid'] : '';
$outd_qty   	  = isset($_REQUEST['outdqty']) ? $_REQUEST['outdqty'] : '';
$outd_price   	  = isset($_REQUEST['outdprice']) ? $_REQUEST['outdprice'] : '';
$outd_currency    = isset($_REQUEST['outh_currency']) ? $_REQUEST['outh_currency'] : '';
$outd_weight  	  = isset($_REQUEST['outdweight']) ? $_REQUEST['outdweight'] : '';
$outd_stock  	  = isset($_REQUEST['prodstock']) ? $_REQUEST['prodstock'] : '';
$po_no	 	 	  = isset($_REQUEST['po_no']) ? $_REQUEST['po_no'] : '';
$outd_price_rate  = isset($_REQUEST['n_rate']) ? $_REQUEST['n_rate'] : '';
$outd_amount	  = isset($_REQUEST['outdamount']) ? $_REQUEST['outdamount'] : '';
$outd_price_usd   = isset($_REQUEST['n_usd']) ? $_REQUEST['n_usd'] : '';
$cust_npwp		  = isset($_REQUEST['cust_npwp']) ? $_REQUEST['cust_npwp'] : '';
$tipe_dokumen	    = isset($_REQUEST['tipe_dokumen']) ? $_REQUEST['tipe_dokumen'] : '';
$harga_dokumen	    = isset($_REQUEST['harga_dokumen']) ? $_REQUEST['harga_dokumen'] : 0;
$outh_scno		  = isset($_REQUEST['outh_scno']) ? $_REQUEST['outh_scno'] : '';
$outd_scno  	  = isset($_REQUEST['outdscno']) ? $_REQUEST['outdscno'] : '';
$bulan2    	 	  = substr($start_date,5,2);
$tahun2  	      = substr($start_date,0,4);
$no_urut  	  	  = isset($_REQUEST['outdnourut']) ? $_REQUEST['outdnourut'] : '';
$outh_keterangan  = isset($_REQUEST['outh_keterangan']) ? $_REQUEST['outh_keterangan'] : '';
if($Act =="SAVEM"){
	if($val_date=="NO"){
		echo "<font color='red'>Periode :$start_date s/d $end_date belum closing</font><br>";
		#reload
		require_once "addm_pengeluaran_bc261.php";
		exit;
	}elseif(empty($outd_price_rate) || $outd_price_rate==0){
		echo "<font color='red'>Kurs tanggal : $outh_docdate belum disetting</font><br>";
		#reload
		require_once "addm_pengeluaran_bc261.php";
		exit;
	}else{
		if(count($message)==0){	
			if(empty($outh_id)){
				#cek qty remain < qty terima
				if($po_no!="10"){
					foreach($pilih as $i => $id){
						$outd_qty		= $_REQUEST['outd_qty2'][$id];
						$outd_rmn		= $_REQUEST['outd_rmn'][$id];
						$prod_name		= $_REQUEST['prod_name2'][$id];
						$outd_qstk		= $_REQUEST['outd_qstk'][$id];
						if($outd_qty > $outd_rmn){
							echo "<font color='red'>Barang :$prod_name QTY INPUT Lebih besar dari QTY REMAIN($outd_qty > $outd_rmn)</font><br>";
							#reload
							require_once "addm_pengeluaran_bc261.php";
							exit;
						}elseif($outd_qty > $outd_qstk){
							echo "<font color='red'>Barang :$prod_name QTY INPUT Lebih besar dari QTY STOCK($outd_qty > $outd_qstk)</font><br>";
							#reload
							require_once "addm_pengeluaran_bc261.php";
							exit;
						}
					}
				}
				$qrySave=mysql_query("INSERT INTO outgoing SET outh_sjno='$outh_sjno', outh_sjdate='$outh_sjdate', outh_custid='$cust_id', 
								  outh_invno='$outh_invno', outh_invdate='$outh_invdate', outh_dono='$outh_dono',
								  tujuan='$tujuan', outh_docid='$outh_docid', outh_inputby='$user_id', sumber='MANUAL',
								  outh_inputdate='$datetime', outh_status=20, outh_docdate='$outh_docdate', outh_docno='$outh_docno', 
								  no_aju='$no_aju', tgl_aju='$tgl_aju', no_npe='$no_npe', tgl_npe='$tgl_npe', outh_doctype='$doc[doc_type]', nm_penerima='$cust[cust_name]',
								  id_penerima='$cust_npwp', outh_currency='$outd_currency', outh_rate='$outd_price_rate', po_no='$po_no', tipe_dokumen='$tipe_dokumen', harga_dokumen='$harga_dokumen',
								  outh_keterangan='$outh_keterangan'") 
								  or die ("Gagal query".mysql_error());
				if($qrySave){
					if($po_no=="10"){
						$data = mysql_fetch_object(mysql_query("SELECT MAX(id) id FROM outgoing"));
						$outh_id = $data->id;
						$query = mysql_query("SELECT * FROM outgoing_temp WHERE outd_inputby='$user_id' ORDER BY id ASC");
						while($dt=mysql_fetch_object($query)){
							$qrySave=mysql_query("INSERT INTO outgoing_detail SET outd_hid='$outh_id', outd_prodid='$dt->outd_prodid', 
												  outd_qty='$dt->outd_qty', outd_price='$dt->outd_price', outd_currency='$dt->outd_currency', 
												  outd_weight='$dt->outd_weight', outd_wunit='$dt->outd_wunit', outd_scno='$dt->outd_scno',
												  outd_price_rate='$dt->outd_price_rate', outd_price_usd='$dt->outd_price_usd', outd_price_satuan='$dt->outd_price_satuan',
												  no_urut='$dt->no_urut'")
												  or die ("Gagal query".mysql_error());
						}
						$qd = mysql_query("UPDATE outgoing_temp SET outd_hid='$outh_id' WHERE outd_inputby='$user_id'");
					}else{
						$data = mysql_fetch_object(mysql_query("SELECT MAX(id) id FROM outgoing"));
						$outh_id = $data->id;
						foreach($pilih as $i => $id){
							$outd_prodid	= $_REQUEST['outd_prodid2'][$id];
							$outd_qty		= $_REQUEST['outd_qty2'][$id];
							$pod_price		= $_REQUEST['pod_price'][$id];
							$outd_scno		= $_REQUEST['outd_scno2'][$id];							
							if($outd_currency=="IDR"){
								$outd_price		 = $outd_qty*$pod_price;
								$outd_price_usd  = 0;
							}else{
								$outd_price		 = ($outd_qty*$pod_price)*$outd_price_rate;
								$outd_price_usd  = $outd_qty*$pod_price;
							}
							$outd_weight	= $_REQUEST['outd_weight2'][$id];
							$no_urut		= $_REQUEST['no_urut2'][$id];
							if($outd_qty > 0){
								mysql_query("INSERT INTO outgoing_detail SET outd_hid='$outh_id', outd_prodid='$outd_prodid', outd_price_usd='$outd_price_usd',
											 outd_qty='$outd_qty', outd_price='$outd_price', outd_currency='$outd_currency', outd_price_rate='$outd_price_rate',
											 outd_weight='$outd_weight', outd_wunit='KG', no_urut='$no_urut', outd_price_satuan='$pod_price', outd_scno='$outd_scno'");
							}			 
						}
					}
				}	
				#Insert History User
				$itemp = mysql_query("INSERT INTO user_activity SET user_id='$user_id', user_act='Menambahkan transaksi pengeluaran No. $outh_sjno:$outh_docno', 
						 user_date='$date', user_time='$time'");
			}elseif(!empty($outh_id) && ($Act_Det <> "ADD_DET")){
				#cek qty stock
				foreach($id_det as $i => $id){
					$outd_qstk2		= $_REQUEST['outd_qstk2'][$id];
					$outd_qty		= $_REQUEST['outd_qty'][$id];
					$outd_codename	= $_REQUEST['outd_codename'][$id];
					if($outd_qty > $outd_qstk2){
						echo "<font color='red'>Barang :$outd_codename QTY INPUT Lebih besar dari QTY STOCK($outd_qty > $outd_qstk2)</font><br>";
						#reload
						require_once "addm_pengeluaran_bc261.php";
						exit;
					}
				}
				$qrySave=mysql_query("UPDATE outgoing SET outh_sjno='$outh_sjno', outh_sjdate='$outh_sjdate', outh_custid='$cust_id', 
									  outh_invno='$outh_invno', outh_invdate='$outh_invdate', outh_dono='$outh_dono',
									  tujuan='$tujuan', outh_docid='$outh_docid', outh_docdate='$outh_docdate', outh_docno='$outh_docno',
									  no_aju='$no_aju', tgl_aju='$tgl_aju', no_npe='$no_npe', tgl_npe='$tgl_npe', outh_doctype='$doc[doc_type]', nm_penerima='$cust[cust_name]',
									  id_penerima='$cust_npwp', outh_currency='$outd_currency', outh_rate='$outd_price_rate', outh_status=20, tipe_dokumen='$tipe_dokumen', harga_dokumen='$harga_dokumen',
									  outh_keterangan='$outh_keterangan' WHERE id='$outh_id'") or die ("Gagal query".mysql_error());
				if($qrySave){
				#Update Detail
					#delete temp
					mysql_query("DELETE FROM outgoing_temp WHERE outd_hid='$outh_id'");
					foreach($id_det as $i => $id){
						$outd_currency		= $_REQUEST['outd_currency'][$id];
						$outd_qty			= $_REQUEST['outd_qty'][$id];
						$outd_price_satuan	= $_REQUEST['outd_price_satuan'][$id];
						$outd_weight		= $_REQUEST['outd_weight'][$id];
						$outd_price_rate	= $_REQUEST['outd_price_rate'][$id];
						$outd_prodid		= $_REQUEST['outd_prodid'][$id];
						$outd_price			= $_REQUEST['outd_price'][$id];
						$outd_price_usd		= $_REQUEST['outd_price_usd'][$id];
						$outd_scno			= $_REQUEST['outd_scno'][$id];
						$no_urut			= $_REQUEST['no_urut'][$id];
						#detail
						mysql_query("UPDATE outgoing_detail SET outd_qty='$outd_qty', outd_price='$outd_price', outd_weight='$outd_weight',
						outd_price_usd='$outd_price_usd', outd_price_satuan='$outd_price_satuan', outd_currency='$outd_currency', outd_scno='$outd_scno', no_urut='$no_urut' WHERE id='$id' ");
						#insert temp
						mysql_query("INSERT INTO outgoing_temp SET outd_prodid='$outd_prodid', outd_qty='$outd_qty', outd_price='$outd_price', outd_currency='$outd_currency', 
						outd_hid='$outh_id', outd_weight='$outd_weight', outd_wunit='Kg', outd_price_rate='$outd_price_rate', outd_price_usd='$outd_price_usd', 
						outd_price_satuan='$outd_price_satuan', outd_scno='$outd_scno', no_urut='$no_urut'");
					}	
					#delete exbc
					mysql_query("DELETE FROM outgoing_dokasal WHERE outh_hid='$outh_id'");
					#Insert History User
					$itemp = mysql_query("INSERT INTO user_activity SET user_id='$user_id', user_act='Mengubah transaksi pengeluaran No. $outh_sjno:$outh_docno', 
							 user_date='$date', user_time='$time'");
				}							  
			}	
			if (count($message)==0 ){
				#Update Status
				$qd = mysql_query("UPDATE outgoing SET outh_status=11 WHERE id='$outh_id'");
				#get Exbc
				get_outexbc($start_date,$end_date,$outh_id);	
				#delete temp
				mysql_query("DELETE FROM outgoing_temp WHERE outd_hid='$outh_id'");
				#Update Status
				$qd = mysql_query("UPDATE outgoing SET outh_status=20 WHERE id='$outh_id'");
				#update status PO, jika sudah komplit qty PO.
				$qpo = mysql_fetch_array(mysql_query("SELECT SUM(a.pod_qty) qty_po FROM purchase_order_detail a INNER JOIN purchase_order b ON b.po_no=a.po_no
					   WHERE b.po_status=20 AND b.po_no='$po_no'"));
				$qin = mysql_fetch_array(mysql_query("SELECT SUM(a.outd_qty) qty_in FROM outgoing_detail a INNER JOIN outgoing b ON b.id=a.outd_hid
					   WHERE b.outh_status IN(15,20) AND b.po_no='$po_no'"));
				if($qpo['qty_po']==$qin['qty_in']){
					mysql_query("UPDATE purchase_order SET po_status=30 WHERE po_no='$po_no'");
				}else{
					mysql_query("UPDATE purchase_order SET po_status=20 WHERE po_no='$po_no'");
				}				
			}
			if($qrySave){
				$message[] = "Data Sukses tersimpan";	
				$status = "OK";
				
			}
		}	
	}
}		
if($Act =="DETAILM"){
	$qd = mysql_query("SELECT a.*,b.cust_name FROM outgoing a
					   LEFT JOIN customer b ON b.id=a.outh_custid					   	   
					   WHERE a.id='$outh_id'");
	$dd=mysql_fetch_object($qd);		
	$outh_id 		= $dd->id;			
	$outh_sjno		= $dd->outh_sjno;
	$outh_sjdate	= $dd->outh_sjdate;
	$cust_id 		= $dd->outh_custid;
	$cust_name		= $dd->cust_name;
	$outh_invno		= $dd->outh_invno;
	$outh_invdate   = $dd->outh_invdate;
	$outh_dono	    = $dd->outh_dono;
	$tujuan	= $dd->tujuan;
	$outh_docno		= $dd->outh_docno;
	$outh_docdate	= $dd->outh_docdate;
	$no_aju			= $dd->no_aju;
	$tgl_aju		= $dd->tgl_aju;
	$no_npe			= $dd->no_npe;
	$tgl_npe		= $dd->tgl_npe;
	$po_no			= $dd->po_no;
	$outd_currency  = $dd->outh_currency;
	$outd_price_rate= $dd->outh_rate;
	$cust_npwp		= $dd->id_penerima;
	if(isset($_REQUEST['flagdoc'])==1){
		$outh_docid		 = $_REQUEST['outh_docid'];
	}else{
		$outh_docid	    = $dd->outh_docid;
	}
	$outh_keterangan = $dd->outh_keterangan;
}	
if($Act == "DELETEM"){
	$qd = mysql_query("UPDATE outgoing SET outh_status=100 WHERE id='$outh_id'");
	if($qd){
		#Insert History User
		$itemp = mysql_query("INSERT INTO user_activity SET user_id='$user_id', user_act='Menghapus transaksi pengeluaran No. $outh_sjno', user_date='$date', user_time='$time'");
		$message[] = "Data Sukses terhapus !";	
		$status = "OK";
	}
}	
if($Act == "POSTINGM"){
	if($val_date=="NO"){
		$message[] = "Periode :$start_date s/d $end_date belum closing";
		$status    = "OK";
	}else{
		#Update Status
		$qd = mysql_query("UPDATE outgoing SET outh_status=20 WHERE id='$outh_id'");
		#update status PO, jika sudah komplit qty PO.
		$qpo = mysql_fetch_array(mysql_query("SELECT SUM(a.pod_qty) qty_po FROM purchase_order_detail a INNER JOIN purchase_order b ON b.po_no=a.po_no
			   WHERE b.po_status=20 AND b.po_no='$po_no'"));
		$qin = mysql_fetch_array(mysql_query("SELECT SUM(a.outd_qty) qty_in FROM outgoing_detail a INNER JOIN outgoing b ON b.id=a.outd_hid
			   WHERE b.outh_status IN(15,20) AND b.po_no='$po_no'"));
		if($qpo['qty_po']==$qin['qty_in']){
			mysql_query("UPDATE purchase_order SET po_status=30 WHERE po_no='$po_no'");
		}
		#Insert History User
		$itemp = mysql_query("INSERT INTO user_activity SET user_id='$user_id', user_act='Posting transaksi pengeluaran No. $outh_sjno', user_date='$date', 
				 user_time='$time'");
		$message[] = "Data Sukses diposting !";	
		$status = "OK";
	}
}
if(($Act_Det == "ADD_DETM") && (empty($outh_id))){ 
	if($val_date=="NO"){
		echo "<font color='red'>Periode :$start_date s/d $end_date belum closing</font><br>";
		#reload
		require_once "addm_pengeluaran_bc261.php";
		exit;
	}elseif(empty($outd_price_rate) || $outd_price_rate==0){
		echo "<font color='red'>Kurs tanggal : $outh_docdate belum disetting</font><br>";
		#reload
		require_once "addm_pengeluaran_bc261.php";
		exit;
	}else{
		mysql_query("INSERT INTO outgoing_temp SET outd_prodid='$outd_prodid', outd_qty='$outd_qty', outd_price='$outd_amount', outd_currency='$outd_currency', 
					 outd_weight='$outd_weight', outd_wunit='Kg',outd_inputby='$user_id', 
					 outd_price_rate='$outd_price_rate', outd_price_usd='$outd_price_usd', outd_price_satuan='$outd_price', outd_scno='$outd_scno',
					 no_urut='$no_urut' ");
	}
}elseif(($Act_Det == "ADD_DETM") && (!empty($outh_id))){
	if($val_date=="NO"){
		echo "<font color='red'>Periode :$start_date s/d $end_date belum closing</font><br>";
		#reload
		require_once "addm_pengeluaran_bc261.php";
		exit;
	}elseif(empty($outd_price_rate) || $outd_price_rate==0){
		echo "<font color='red'>Kurs tanggal : $outh_docdate belum disetting</font><br>";
		#reload
		require_once "addm_pengeluaran_bc261.php";
		exit;
	}else{
		mysql_query("INSERT INTO outgoing_detail SET outd_hid='$outh_id', outd_prodid='$outd_prodid', outd_qty='$outd_qty', outd_price='$outd_amount', 
					 outd_currency='$outd_currency', outd_weight='$outd_weight', outd_wunit='Kg',
					 outd_price_rate='$outd_price_rate', outd_price_usd='$outd_price_usd', outd_price_satuan='$outd_price', outd_scno='$outd_scno',
					 no_urut='$no_urut'");
	}
}
if(($Act_Det == "DELETE_DETM") && (empty($outh_id))){
	mysql_query("DELETE FROM outgoing_temp WHERE id='$id_deth'");
}elseif(($Act_Det == "DELETE_DETM") && (!empty($outh_id))){
	mysql_query("DELETE FROM outgoing_detail WHERE id='$id_deth'");
}
#Proses
if($Act=="PROCESS"){
	if(!empty($pilih)){	
		foreach ( $pilih as $i => $val)
		{
			$tgl_sj2  		= $_REQUEST['tgl_sj2'][$val];
			$tgl_dokpab2	= $_REQUEST['tgl_dokpab2'][$val];
			$id_header 		= $_REQUEST['id_header'][$val];
			$no_urut  		= $_REQUEST['no_urut'][$val];
			if($tgl_sj2=="0000-00-00"){
				$tglsj = $tgl_dokpab2;
			}else{
				$tglsj = $tgl_sj2;
			}
			#Update status temp
			mysql_query("UPDATE log_outgoing SET log_status=2, tgl_sj='$tglsj' WHERE id='$val' ");
			#pdate status temp dok asal import
			mysql_query("UPDATE log_outgoing_dokasal SET log_status=2  WHERE id_header='$id_header' AND no_urut='$no_urut' AND kode_dokasal=0");
			#pdate status temp dok asal lokal
			mysql_query("UPDATE log_outgoing_dokasal SET log_status=2  WHERE id_header='$id_header' AND no_urut='$no_urut' AND kode_dokasal=1");
		}
		require "add_pengeluaran_bc261.php";
	}else{
		require "add_pengeluaran_bc261.php";
	}	
}elseif($Act=="INV"){
	#Insert header pemasukan
	$qh=mysql_query("SELECT * FROM log_outgoing WHERE log_status = 2 AND jenis_dokpab='$jenis_dokpab' GROUP BY id_header");	
	while($dh=mysql_fetch_array($qh)){
		$ary_nomor 		= get_nomorout(1);
		$ary_nosj 		= get_nosjout(1);
		if(!empty($dh['no_sj'])){
			$no_sj = $dh['no_sj'];
		}else{
			$no_sj = $ary_nosj;
		}
		#Insert Pemasukan Headar
		mysql_query("INSERT INTO outgoing SET outh_sjno='$ary_nosj', outh_sjdate='$dh[tgl_sj]', outh_invno='$dh[no_invoice]', outh_doctype='$dh[jenis_dokpab]',
		             outh_invdate='$dh[tgl_invoice]', outh_dono='$dh[no_do]', outh_docno='$dh[no_dokpab]', outh_docdate='$dh[tgl_dokpab]', nm_penerima='".mysql_real_escape_string($dh['nm_penerima'])."',
					 outh_status=12, outh_inputby='$user_id', outh_inputdate='$datetime', outh_nomor='$dh[flag]', no_aju='$dh[no_aju]', tgl_aju='$dh[tgl_aju]',
					 no_sppb='$dh[no_sppb]', tgl_sppb='$dh[tgl_sppb]', no_ppb='$dh[no_ppb]', tgl_ppb='$dh[tgl_ppb]', no_npe='$dh[no_npe]', tgl_npe='$dh[tgl_npe]',
					 no_jaminan='$dh[no_jaminan]', tgl_jaminan='$dh[tgl_jaminan]', jumlah_jaminan='$dh[jumlah_jaminan]', jenis_dokpab_asal='$dh[jenis_dokpab_asal]',
					 no_dokpab_asal='$dh[no_dokpab_asal]', tgl_dokpab_asal='$dh[tgl_dokpab_asal]', jatuh_tempo='$dh[jatuh_tempo]', no_kontainer='$dh[no_kontainer]',
					 ukuran_kontainer='$dh[ukuran_kontainer]', tipe_kontainer='$dh[tipe_kontainer]', jumlah_kemasan='$dh[jumlah_kemasan]', kode_kemasan='$dh[kode_kemasan]',
					 jenis_kemasan='$dh[jenis_kemasan]', valuta='$dh[valuta]', sumber='CIESA', status_dokpab='$dh[status_dokpab]', id_header='$dh[id_header]',
					 no_izin='$dh[no_izin]', tgl_izin='$dh[tgl_izin]', id_penerima='$dh[id_penerima]', outh_currency='$dh[valuta]',tujuan='$dh[tujuan]', 
					 no_kontrak='$dh[no_kontrak]', tgl_kontrak='$dh[tgl_kontrak]', no_persetujuan='$dh[no_persetujuan]', tgl_persetujuan='$dh[tgl_persetujuan]', outh_rate='$dh[outh_rate]'");
		#Aktivitas User
		mysql_query("INSERT INTO user_activity SET user_id='$user_id',user_act='Menambahkan transaksi pengeluaran No. $ary_nosj', user_date='$date', user_time='$time'");
		$status=1;
	}
	if($status == 1){
		$qd = mysql_query("SELECT b.id,a.tgl_sj,a.kode,a.jumlah,a.valuta,a.nilai,a.berat,a.no_urut, a.kode_hs, a.cif_rupiah, a.non_rupiah, a.outd_scno
						  FROM log_outgoing a  INNER JOIN outgoing b ON b.id_header=a.id_header												 
						  WHERE a.log_status =2 AND a.jenis_dokpab='$jenis_dokpab' AND b.outh_status=12 ORDER BY b.id, a.no_urut ASC ");
		WHILE ($dd = mysql_fetch_array($qd))
		{
			$prd2 = mysql_fetch_array(mysql_query("SELECT id FROM product WHERE prod_code='$dd[kode]' AND prod_cat<>100"));
			if($dd['valuta'] =="IDR"){$unit_price=$dd['nilai']/$dd['jumlah'];}else{$unit_price=$dd['non_rupiah']/$dd['jumlah'];}
			mysql_query("INSERT INTO outgoing_detail SET outd_hid='$dd[id]', outd_prodid='$prd2[id]', 
						 outd_qty='$dd[jumlah]', outd_price='$dd[cif_rupiah]', outd_currency='$dd[valuta]', outd_price_satuan='$unit_price', 
						 outd_weight='$dd[berat]', outd_wunit='KG', no_urut='$dd[no_urut]', kode_hs='$dd[kode_hs]',outd_price_usd='$dd[non_rupiah]', outd_scno='$dd[outd_scno]'");
		}
		$status = 2;
	}
	if($status == 2){
		$qd2 = mysql_query("SELECT a.*, b.id outh_id FROM log_outgoing_dokasal a
						   INNER JOIN outgoing b ON b.id_header=a.id_header
						   WHERE a.log_status=2 AND b.outh_doctype='$jenis_dokpab' AND b.outh_status=12 ORDER BY a.no_urut,kode_dokasal, no_urut_dokpab ASC ");
		while($dd2 = mysql_fetch_array($qd2)){
			mysql_query("INSERT INTO outgoing_dokasal SET outh_hid='$dd2[outh_id]', no_urut='$dd2[no_urut]', no_urut_dokpab='$dd2[no_urut_dokpab]', 
			             kode_barang='$dd2[kode_barang]', nm_barang='$dd2[nm_barang]', satuan='$dd2[satuan]', jumlah='$dd2[jumlah]', nilai='$dd2[nilai]',
						 noaju_dokpab_asal='$dd2[noaju_dokpab_asal]', jenis_dokpab_asal='$dd2[jenis_dokpab_asal]', no_dokpab_asal='$dd2[no_dokpab_asal]',
						 tgl_dokpab_asal='$dd2[tgl_dokpab_asal]', nourut_dokpab_asal='$dd2[nourut_dokpab_asal]', kode_dokasal='$dd2[kode_dokasal]',
						 log_status=20, id_header='$dd2[id_header]'");
		}
		$status = 3;
	}
	if($status == 3){	
		#update status log dokumen asal
		mysql_query("UPDATE log_outgoing_dokasal SET log_status=3 WHERE log_status=2 AND jenis_dokpab='BC 2.6.1'");
		#update status log
		mysql_query("UPDATE log_outgoing SET log_status=3 WHERE log_status=2 AND jenis_dokpab='BC 2.6.1'");
		#Update Status
		mysql_query("UPDATE outgoing SET outh_status=20 WHERE outh_status=12 AND outh_doctype='BC 2.6.1'");
		
		$message[] = "Data Sukses dikirim.";	
		$status    = "OK";
	}		 
}elseif($Act=="REG"){
	$search = "";
	if(!empty($pilih_reg)){	
		foreach ( $pilih_reg as $i => $val)
		{
			$kd_barang   = $_REQUEST['kd_barang'][$val];
			$nm_barang   = $_REQUEST['nm_barang'][$val];
			$satuan      = $_REQUEST['satuan'][$val];
			$kd_kategori = $_REQUEST['kd_kategori'][$val];
			#Insert master barang
			if($kd_kategori != "BLANK"){
				#Update barang ke log outgoing
				mysql_query("UPDATE log_outgoing SET kode='$kd_barang', nm_barang='$nm_barang', satuan='$satuan' WHERE id='$val'");
				#Cek data di master barang
				$cek = mysql_fetch_array(mysql_query("SELECT prod_code FROM product WHERE prod_code='$kd_barang'"));
				if(empty($cek['prod_code'])){
					#Insert kode barau
					mysql_query("INSERT INTO product SET prod_code='$kd_barang', prod_name='$nm_barang', prod_sat='$satuan', prod_cat='$kd_kategori', prod_status=10");
					#Aktivitas user					
					mysql_query("INSERT INTO user_activity SET user_id='$user_id', user_act='Menambahkan data barang - $kd_barang', user_date='$date', user_time='$time'");
				}
			}
		}
		require "add_pengeluaran_bc261.php";
	}else{
		require "add_pengeluaran_bc261.php";
	}	
}elseif($Act=="DEL_TEMP"){
	#delete temp
	mysql_query("UPDATE log_outgoing SET log_status=5 WHERE log_status=1");
	$message[] = "Data Sukses dihapus.";
	require "add_pengeluaran_bc261.php";	
}elseif($Act=="DELDET_TEMP"){
	mysql_query("UPDATE log_outgoing SET log_status=1 WHERE id='".$_REQUEST['id_temp']."' ");
	#pdate status temp dok asal import
	mysql_query("UPDATE log_outgoing_dokasal SET log_status=1  WHERE id_header='$tmp_id_header' AND no_urut='$tmp_no_urut' AND kode_dokasal=0");
	#pdate status temp dok asal lokal
	mysql_query("UPDATE log_outgoing_dokasal SET log_status=1  WHERE id_header='$tmp_id_header' AND no_urut='$tmp_no_urut' AND kode_dokasal=1");
	require "add_pengeluaran_bc261.php";
}elseif($Act=="INF" || $Act=="GET" || $Act=="TEMP"){
	require "add_pengeluaran_bc261.php";
}elseif($Act == "SEL_PO"){
	$dd=mysql_fetch_array(mysql_query("SELECT a.*,b.cust_name, b.cust_npwp FROM purchase_order a INNER JOIN customer b ON b.id=a.po_idcust 
	WHERE a.po_no='$po_no' AND po_type='Sales'"));
	$po_no			= $dd['po_no'];
	$cust_id 		= $dd['po_idcust'];
	$cust_name		= $dd['cust_name'];
	$outd_currency	= $dd['po_currency'];
	$cust_npwp		= $dd['cust_npwp'];
	
	require "addm_pengeluaran_bc261.php";
}elseif($Act == "ADDM" || $Act == "DETAILM" || $Act_Det == "ADD_DETM" || $Act_Det == "DELETE_DETM" || $Act == "SEL_PO"){
	require_once "addm_pengeluaran_bc261.php";
}elseif($Act=="CANCEL" || $Act=="CLOSE"){
	echo "<meta http-equiv='refresh' content='0; url=?page=Data-Pengeluaran-BC261'>";	
	exit;
}elseif($Act=="UPL40" ){
	require "add40_pengeluaran_bc261.php";
}elseif($Act=="GET40" ){
	$data 	= new Spreadsheet_Excel_Reader($_FILES['userfile']['tmp_name']);
	#cek dokumen 
	$cekdok = 0; 
	$cek1	= $data->rowcount($sheet_index=0); #sheet Header
	for ($i=2; $i<=$cek1; $i++){
		$kode_dokumen 	= $data->val($i, 2, 0);
		if($kode_dokumen == "261"){
			$cekdok = 1;
		}
	}
	if($cekdok==1){
		$sheet8	= $data->rowcount($sheet_index=7); #sheet Barang
		for ($i=2; $i<=$sheet8; $i++){
			$no_aju	  			= $data->val($i, 1, 7);
			#tglaju
			$thnaju 			= substr($no_aju, 12,4);
			$blnaju 			= substr($no_aju, 16,2);
			$hriaju 			= substr($no_aju, 18,2);
			$tglaju2 			= "$thnaju-$blnaju-$hriaju";
			$no_urut  			= $data->val($i, 2, 7);
			$kode_hs  			= $data->val($i, 3, 7);
			$kode  	  			= $data->val($i, 4, 7);
			$nm_barang			= $data->val($i, 5, 7);
			$satuan				= $data->val($i, 10, 7);
			$jumlah				= $data->val($i, 11, 7);
			$kode_kemasan		= $data->val($i, 12, 7);
			$jumlah_kemasan		= $data->val($i, 13, 7);
			$berat				= $data->val($i, 20, 7);
			$non_rupiah			= $data->val($i, 26, 7);
			$cif_rupiah			= $data->val($i, 27, 7);
			$outh_rate			= $data->val($i, 28, 7);
			$cek = mysql_fetch_array(mysql_query("SELECT id, log_status FROM log_outgoing WHERE no_aju='$no_aju' AND no_urut='$no_urut' AND jenis_dokpab='BC 2.6.1' AND log_status<>5"));
			if(empty($cek['id'])){
				mysql_query("INSERT INTO log_outgoing SET no_aju='$no_aju', tgl_aju='$tglaju2', no_urut='$no_urut', kode_hs='$kode_hs', kode='$kode', nm_barang='$nm_barang', satuan='$satuan', 
				jumlah='$jumlah', kode_kemasan='$kode_kemasan', jumlah_kemasan='$jumlah_kemasan', berat='$berat', non_rupiah='$non_rupiah', cif_rupiah='$cif_rupiah', outh_rate='$outh_rate', 
				jenis_dokpab='BC 2.6.1', log_status=86, log_user='$user_id', log_input='$datetime'");
			}else{
				if($cek['log_status']==88){
					echo "<font color=red>Data Nomor Aju : $no_aju, no urut : $no_urut, sudah diupload</font><br>";	
				}	
			}
		}
		$sheet1	= $data->rowcount($sheet_index=0); #sheet Header
		for ($i=2; $i<=$sheet1; $i++){
			$no_aju	  	= $data->val($i, 1, 0);
			$valuta     = $data->val($i, 87, 0);
			$no_dokpab  = $data->val($i, 94, 0);
			$tgl_dokpab = date("Y-m-d",strtotime($data->val($i, 95, 0))); #$data->val($i, 95, 0);
			mysql_query("UPDATE log_outgoing SET no_dokpab='$no_dokpab', tgl_dokpab='$tgl_dokpab', tgl_sj='$tgl_dokpab', valuta='$valuta' WHERE no_aju='$no_aju' AND jenis_dokpab='BC 2.6.1' AND log_status=86");
		}
		$sheet2	= $data->rowcount($sheet_index=1); #sheet Etitas
		for ($i=2; $i<=$sheet2; $i++){
			$no_aju	  		= $data->val($i, 1, 1);
			$seri	    	= $data->val($i, 2, 1);
			$kode_entitas	= $data->val($i, 3, 1);
			$nm_penerima    = $data->val($i, 6, 1);
			if($kode_entitas==8){		
				mysql_query("UPDATE log_outgoing SET nm_penerima='$nm_penerima' WHERE no_aju='$no_aju' AND jenis_dokpab='BC 2.6.1' AND log_status=86");
			}
		}
		$sheet3	= $data->rowcount($sheet_index=2); #sheet Dokumen
		for ($i=2; $i<=$sheet3; $i++){
			$no_aju	  		= $data->val($i, 1, 2);
			$kode_dokumen	= $data->val($i, 3, 2);
			$no_dokumen	    = $data->val($i, 4, 2);
			$tgl_dokumen	= date("Y-m-d",strtotime($data->val($i, 5, 2)));
			if($kode_dokumen=="315"){		
				mysql_query("UPDATE log_outgoing SET no_invoice='$no_dokumen', tgl_invoice='$tgl_dokumen' WHERE no_aju='$no_aju' AND jenis_dokpab='BC 2.6.1' AND log_status=86");
			}								
		}
		$sheet5	= $data->rowcount($sheet_index=4); #sheet Kemasan
		for ($i=2; $i<=$sheet5; $i++){
			$no_aju	  		= $data->val($i, 1, 4);
			$kode_kemasan	= $data->val($i, 3, 4);
			$jumlah_kemasan = $data->val($i, 4, 4);
			mysql_query("UPDATE log_outgoing SET kode_kemasan='$kode_kemasan', jumlah_kemasan='$jumlah_kemasan' WHERE no_aju='$no_aju' AND jenis_dokpab='BC 2.6.1' AND log_status=86");
		}
		$sheet13	= $data->rowcount($sheet_index=12); #sheet bahanbaku
		for ($i=2; $i<=$sheet13; $i++){
			$no_aju	  		= $data->val($i, 1, 12);
			$no_dokpab_asal	= $data->val($i, 18, 12);
			$tgl_dokpab_asal= date("Y-m-d",strtotime($data->val($i, 19, 12)));
			mysql_query("UPDATE log_outgoing SET no_dokpab_asal='$no_dokpab_asal', tgl_dokpab_asal='$tgl_dokpab_asal' WHERE no_aju='$no_aju' AND jenis_dokpab='BC 2.6.1' AND log_status=86");
		}
	}else{
		echo "<font color=red><b>File excel bukan BC 2.6.1</b></font>";
	}
	require "add40_pengeluaran_bc261.php";
}elseif($Act=="TEMP40" ){	
	require "add40_pengeluaran_bc261.php";
}elseif($Act=="REG40"){
	if(!empty($pilih_reg)){	
		foreach ( $pilih_reg as $i => $val)
		{
			$kd_barang   = $_REQUEST['kd_barang'][$val];
			$nm_barang   = $_REQUEST['nm_barang'][$val];
			$satuan      = $_REQUEST['satuan'][$val];
			$kd_kategori = $_REQUEST['kd_kategori'][$val];
			#Insert master barang
			if($kd_kategori != "BLANK"){
				#Update kode branag ditemp
				mysql_query("UPDATE log_outgoing SET kode='$kd_barang', nm_barang='".mysql_real_escape_string($nm_barang)."', satuan='$satuan' WHERE id='$val'");
				#Insert ke master barang				
				mysql_query("INSERT INTO product SET prod_code='$kd_barang', prod_name='".mysql_real_escape_string($nm_barang)."', prod_sat='$satuan', prod_cat='$kd_kategori', prod_status=10");
				#Aktivitas user					
				mysql_query("INSERT INTO user_activity SET user_id='".$_SESSION['USER_ID']."', user_act='Menambahkan data barang - $kd_barang', 
				             user_date='$date', user_time='$time'");
			}
		}
		require "add40_pengeluaran_bc261.php";
	}else{
		require "add40_pengeluaran_bc261.php";
	}	
}elseif($Act=="DEL_TEMP40"){
	#delete all temp
	mysql_query("UPDATE log_outgoing SET log_status=5 WHERE log_status=86");
	#$status = "OK";	
	require_once "add40_pengeluaran_bc261.php";
}elseif($Act=="DELDET_TEMP40"){
	mysql_query("UPDATE log_outgoing SET log_status=86 WHERE id='".$_REQUEST['id_temp']."' ");
	require "add40_pengeluaran_bc261.php";
}elseif($Act=="PROCESS40"){
	if(!empty($pilih)){	
		foreach ( $pilih as $i => $val){
			#Update status temp
			mysql_query("UPDATE log_outgoing SET log_status=87 WHERE id='$val' ");
		}
		require "add40_pengeluaran_bc261.php";
	}else{
		require "add40_pengeluaran_bc261.php";
	}	
}elseif($Act=="INV40"){
	#Insert header pemasukan
	$qh=mysql_query("SELECT * FROM log_outgoing WHERE log_status =87 AND jenis_dokpab='BC 2.6.1' GROUP BY no_aju");	
	while($dh=mysql_fetch_array($qh)){
		$ary_nomor 		= get_nomorout(1);
		$ary_nosj 		= get_nosjout(1);
		if(!empty($dh['no_sj'])){
			$no_sj = $dh['no_sj'];
		}else{
			$no_sj = $ary_nosj;
		}
		#Insert Pemasukan Headar
		mysql_query("INSERT INTO outgoing SET outh_sjno='$no_sj', outh_sjdate='$dh[tgl_sj]', outh_invno='$dh[no_invoice]', outh_doctype='$dh[jenis_dokpab]',
		             outh_invdate='$dh[tgl_invoice]', outh_dono='$dh[no_do]', outh_docno='$dh[no_dokpab]', outh_docdate='$dh[tgl_dokpab]', nm_penerima='".mysql_real_escape_string($dh['nm_penerima'])."',
					 outh_status=87, outh_inputby='$user_id', outh_inputdate='$datetime', outh_nomor='$dh[flag]', no_aju='$dh[no_aju]', tgl_aju='$dh[tgl_aju]',
					 no_sppb='$dh[no_sppb]', tgl_sppb='$dh[tgl_sppb]', no_ppb='$dh[no_ppb]', tgl_ppb='$dh[tgl_ppb]', no_npe='$dh[no_npe]', tgl_npe='$dh[tgl_npe]',
					 no_jaminan='$dh[no_jaminan]', tgl_jaminan='$dh[tgl_jaminan]', jumlah_jaminan='$dh[jumlah_jaminan]', jenis_dokpab_asal='$dh[jenis_dokpab_asal]',
					 no_dokpab_asal='$dh[no_dokpab_asal]', tgl_dokpab_asal='$dh[tgl_dokpab_asal]', jatuh_tempo='$dh[jatuh_tempo]', no_kontainer='$dh[no_kontainer]',
					 ukuran_kontainer='$dh[ukuran_kontainer]', tipe_kontainer='$dh[tipe_kontainer]', jumlah_kemasan='$dh[jumlah_kemasan]', kode_kemasan='$dh[kode_kemasan]',
					 jenis_kemasan='$dh[jenis_kemasan]', valuta='$dh[valuta]', sumber='UPL40', status_dokpab='$dh[status_dokpab]', id_header='$dh[id_header]',
					 no_izin='$dh[no_izin]', tgl_izin='$dh[tgl_izin]', tujuan='$dh[tujuan]', no_kontrak='$dh[no_kontrak]', tgl_kontrak='$dh[tgl_kontrak]',
					 house_bl='$dh[house_bl]',master_bl='$dh[master_bl]', pos='$dh[pos]', nomor_manifes='$dh[nomor_manifes]', pelabuhan='$dh[pelabuhan]', 
					 harga_maklon='$dh[harga_maklon]', harga_fob='$dh[harga_fob]', tanggal_manifes='$dh[tanggal_manifes]', tipe_dokumen='$dh[tipe_dokumen]'");
		#Aktivitas User
		mysql_query("INSERT INTO user_activity SET user_id='$user_id', user_act='Menambahkan transaksi pengeluaran No. $no_sj', user_date='$date', user_time='$time'");
		$status = 1;
	}	
	//exit;
	if($status == 1){
		$qd = mysql_query("SELECT b.id,a.kode,a.jumlah,a.valuta,a.nilai,a.berat,a.no_urut,a.kode_hs, a.jenis_dokpab, a.no_dokpab, a.tgl_dokpab, a.tgl_sj, 
						  a.outd_scno, a.non_rupiah, a.cif_rupiah
						  FROM log_outgoing a 
						  INNER JOIN outgoing b ON b.no_aju=a.no_aju AND a.no_dokpab=b.outh_docno					 
						  WHERE a.log_status=87 AND b.outh_status=87 AND a.jenis_dokpab='BC 2.6.1'");						  
		while($dd = mysql_fetch_array($qd)){
			if($dd['valuta'] =="IDR"){
				$unit_price=$dd['cif_rupiah']/$dd['jumlah'];
				$nilai = $dd['cif_rupiah'];
				$harga_maklon = 0;
				$harga_fob = 0;
			}else{
				$unit_price=$dd['non_rupiah']/$dd['jumlah'];
				$nilai = $dd['cif_rupiah'];
				$harga_maklon = 0;
				$harga_fob = 0;
			}
			$prd2 = mysql_fetch_array(mysql_query("SELECT id FROM product WHERE prod_code='$dd[kode]' AND prod_cat<>100"));
			#Insert Detail
			mysql_query("INSERT INTO outgoing_detail SET outd_hid='$dd[id]', outd_prodid='$prd2[id]', 
						 outd_qty='$dd[jumlah]', outd_price='$nilai', outd_currency='$dd[valuta]', harga_maklon='$harga_maklon', harga_fob='$harga_fob',
						 outd_weight='$dd[berat]', outd_wunit='KG', no_urut='$dd[no_urut]', kode_hs='$dd[kode_hs]', outd_price_usd='$dd[non_rupiah]', outd_price_satuan='$unit_price'");
			#insert temp
			mysql_query("INSERT INTO outgoing_temp SET outd_prodid='$prd2[id]', outd_qty='$dd[jumlah]', outd_price='$nilai', outd_currency='$dd[valuta]', 
						outd_hid='$dd[id]', outd_weight='$dd[berat]', outd_wunit='KG',  outd_price_usd='$dd[non_rupiah]'");			 
		}
		$status = 2;
	}
	//exit;
	if($status == 2){
		#cek header outgoing
		$qh = mysql_query("SELECT id, outh_sjno FROM outgoing WHERE outh_status=87 AND sumber='UPL40' AND outh_doctype='BC 2.6.1' AND outh_inputby='$user_id' ORDER BY id ASC");
		while($dh=mysql_fetch_array($qh)){
			#cek item ditemp
			if (count($message)==0 ){
				#Update Status
				#$qd = mysql_query("UPDATE outgoing SET outh_status=14 WHERE id='$dh[id]'");
				#get Exbc
				get_outexbc($start_date,$end_date,$dh['id']);					
			}
			#delete temp
			mysql_query("DELETE FROM outgoing_temp WHERE outd_hid='$dh[id]'");
			#Update Status
			$qd = mysql_query("UPDATE outgoing SET outh_status=15 WHERE id='$dh[id]'");
			#Insert History User
			$itemp = mysql_query("INSERT INTO user_activity SET user_id='$user_id', user_act='Posting transaksi pengeluaran No. $dh[outh_sjno]', user_date='$date', 
					 user_time='$time'");
			#$status = "OK";
		}		
		$status = 3;
	}
	if($status == 3){	
		#update status log
		mysql_query("UPDATE log_outgoing SET log_status =88 WHERE log_status =87 AND jenis_dokpab='BC 2.6.1'");
		#update status
		mysql_query("UPDATE outgoing SET outh_status=20 WHERE outh_status=15 AND outh_doctype='BC 2.6.1' AND sumber='UPL40'");
		$message[] = "Data Sukses dikirim.";	
		$status    = "OK";
	}		 
}
#Messages
if (! count($message)==0 ){
	?>
		<script language="javascript">
			var pesan ='<?php 
							$Num=0;
							foreach ($message as $indeks=>$pesan_tampil) { 
								$Num++;
								echo $Num.'. '.$pesan_tampil.'\n';
							}
						?>';
			alert(pesan);
		</script>
	<?php  
	if ($status=="OK"){	
		echo "<meta http-equiv='refresh' content='0; url=?page=Data-Pengeluaran-BC261'>";	
		exit;
	}else{
		echo "<meta http-equiv='refresh' content='0; url=?page=Proses-Pengeluaran-BC261&Act=TEMP'>";
	}
}
?>