<?php
session_start();
@ob_start();
include "../../config/koneksi.php";

$module=$_GET['module'];
$act=$_GET['act'];

if ($module=='sales' AND $act=='add'){
	if($_SESSION['nama'] == 'KTR2'){
		$dtt = new DateTime($_POST['sls']);
		$dt1 = date_format($dtt, 'Y-m-d');
	}
	else{
		$dt1 = date("Y-m-d");
	}
	$produk = $_POST['produk'];
	$qty 	= $_POST['qty'];

	$kasir 	= $_SESSION['nama'];


	mysql_query("INSERT INTO tmpmutasitax(produk,qty,kasir) VALUES('$produk','$qty','$kasir')");
	header('location:add.php');


}elseif ($module=='view' AND $act=='penjualancs'){
	$awal = $_POST['awal'];
	$akhir = $_POST['akhir'];
	header('location:data.php?tglawal='.$awal.'&tglakhir='.$akhir);

}elseif ($module=='sales' AND $act=='delitem'){
	$id=$_GET['id'];	
	mysql_query("Delete from tmpmutasitax where id = $id");
	header('location:add.php');
}elseif ($module=='sales' AND $act=='filter'){
	$bank=$_POST['bank'];
	header('location:pembayaran.php?bank='.$bank);
}elseif ($module=='sales' AND $act=='edit'){
	$id=$_GET['id'];
	$page=$_GET['page'];
	
	$qty = $_POST['qty'];

	mysql_query("Update mutasitax set qty = '$qty' where id = $id");
	header('location:edit.php?id='.$page);
}elseif ($module=='sales' AND $act=='edittgl'){
	$page=$_GET['page'];
	
	$tgl = $_POST['tgl'];
	mysql_query("Update mutasitaxm set billdate = '$tgl' where billno = $page");
	header('location:edit.php?id='.$page);

}elseif ($module=='sales' AND $act=='editfrom'){
	$page=$_GET['page'];
	
	$cust = $_POST['xfrom'];
	mysql_query("Update mutasitaxm set gudang = '$cust' where billno = $page");
	header('location:edit.php?id='.$page);

}elseif ($module=='sales' AND $act=='editto'){
	$page=$_GET['page'];
	
	$cust = $_POST['xto'];
	mysql_query("Update mutasitaxm set gudang2 = '$cust' where billno = $page");
	header('location:edit.php?id='.$page);

}elseif ($module=='promo' AND $act=='edit'){
	$promo=$_POST['promo'];
	$promo = str_replace(".","",$promo);
	$promo = str_replace(",","",$promo);
	$id=$_GET['id'];
	mysql_query("Update tmpjualcs set promo = '$promo' where id = $id");
	header('location:add.php');
}elseif ($module=='sales' AND $act=='delinv'){
	$id=$_GET['id'];	
	mysql_query("update mutasim set status = 'N' where billno = $id");
	header('location:data.php');
}elseif ($module=='sales' AND $act=='lunas'){
	$id=$_GET['id'];
	$kasir=$_SESSION['nama'];	
	$dt1 = date("Y-m-d");
	mysql_query("update jualcs set byrby = '$kasir',byrdate = '$dt1'  where billno = $id");
	header('location:data.php');
}elseif ($module=='sales' AND $act=='addall'){
	$dt1 = $_POST['tgl'];
	$gd1 	= $_POST['gd1'];
	$gd2 	= $_POST['gd2'];
	$ket 	= $_POST['ket'];
	$kasir 	= $_SESSION['nama'];


		mysql_query("INSERT INTO mutasitaxm(billdate,gudang,gudang2,kasir,xket) VALUES('$dt1','$gd1','$gd2','$kasir','$ket')");
			
			
			$billno = mysql_insert_id();
			$cek = mysql_query("Select * from tmpmutasitax where kasir = '$kasir'");
			while ($r=mysql_fetch_array($cek)){	
				$produk = $r['produk'];
				$qty = $r['qty'];

				mysql_query("INSERT INTO mutasitax(mutasi,produk,qty) VALUES('$billno','$produk','$qty')");
			}
			mysql_query("delete from tmpmutasitax where kasir = '$kasir'");
			include "updatestok2.php";
			header('location:data.php');
	
}

elseif ($module=='sales' AND $act=='validasibyr'){
	$id = $_GET[id];
	$dtV = date("Y-m-d H:i:s");
	$kasir = $_SESSION['nama'];
	
	mysql_query("Update jualcs set byrby = '$kasir', valbyr = '$dtV',bayar = 'Y' where billno = $id");
	header('location:pembayaran.php');

}elseif ($module=='sales' AND $act=='validasibyrwh'){
	$id = $_GET[id];
	$dtV = date("Y-m-d H:i:s");
	$kasir = $_SESSION['nama'];
	
	mysql_query("Update jualcs set byrby2 = '$kasir', valbyr2 = '$dtV',bayar2 = 'Y' where billno = $id");
	header('location:pembayaran.php');

}elseif ($module=='sales' AND $act=='validasikrm'){
	$id = $_GET[id];
	$dtV = date("Y-m-d H:i:s");
	$kasir = $_SESSION['nama']; 
	
	mysql_query("Update jualcs set krmby = '$kasir', valkrm = '$dtV',kirim = 'Y' where billno = $id");
	header('location:data.php');

}

elseif ($module=='sales' AND $act=='profile'){
	$uid=$_SESSION['idm'];
	$pass = $_POST['pass1'];
	mysql_query("update admins set pass = '$pass' where pk = $uid");
	header('location:profile.php');

}

elseif ($module=='sales' AND $act=='ap1'){
	$id = $_GET[id];
	mysql_query("Update jualcs set fol1 = 'Y' where billno = $id");
	header('location:crm.php');

}
elseif ($module=='sales' AND $act=='uap1'){
	$id = $_GET[id];
	mysql_query("Update jualcs set fol1 = 'N' where billno = $id");
	header('location:crm.php');

}elseif ($module=='sales' AND $act=='ap2'){
	$id = $_GET[id];
	mysql_query("Update jualcs set fol2 = 'Y' where billno = $id");
	header('location:crm.php');

}
elseif ($module=='sales' AND $act=='uap2'){
	$id = $_GET[id];
	mysql_query("Update jualcs set fol2 = 'N' where billno = $id");
	header('location:crm.php');

}elseif ($module=='sales' AND $act=='ap3'){
	$id = $_GET[id];
	mysql_query("Update jualcs set fol3 = 'Y' where billno = $id");
	header('location:crm.php');

}
elseif ($module=='sales' AND $act=='uap3'){
	$id = $_GET[id];
	mysql_query("Update jualcs set fol3 = 'N' where billno = $id");
	header('location:crm.php');

}elseif ($module=='sales' AND $act=='ap4'){
	$id = $_GET[id];
	mysql_query("Update jualcs set fol4 = 'Y' where billno = $id");
	header('location:crm.php');

}
elseif ($module=='sales' AND $act=='uap4'){
	$id = $_GET[id];
	mysql_query("Update jualcs set fol4 = 'N' where billno = $id");
	header('location:crm.php');

}elseif ($module=='sales' AND $act=='ap5'){
	$id = $_GET[id];
	mysql_query("Update jualcs set fol5 = 'Y' where billno = $id");
	header('location:crm.php');

}
elseif ($module=='sales' AND $act=='uap5'){
	$id = $_GET[id];
	mysql_query("Update jualcs set fol5 = 'N' where billno = $id");
	header('location:crm.php');

}

?>
