<?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'];
	$harga 	= $_POST['harga'];
	$kasir 	= $_SESSION['nama'];


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


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

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

}
elseif ($module=='sales' AND $act=='delitem'){
	$id=$_GET['id'];	
	mysql_query("Delete from tmpbelitax where id = $id");
	header('location:add.php');
}elseif ($module=='sales' AND $act=='delinv'){
	$id=$_GET['id'];	
	mysql_query("update belitax set status = 'D' where billno = $id");
	header('location:data.php');
}elseif ($module=='sales' AND $act=='addall'){
	$dt1 = date("Y-m-d");
	$cust 	= $_POST['cust'];
	$ket 	= $_POST['ket'];
	$kasir 	= $_SESSION['nama'];
	mysql_query("INSERT INTO belitax(billdate,cust,ket,kasir,isretur) VALUES('$dt1','$cust','$ket','$kasir','Y')");
	
	
	$billno = mysql_insert_id();
	$cek = mysql_query("Select * from tmpbelitax where kasir = '$kasir'");
	while ($r=mysql_fetch_array($cek)){	
		$produk = $r['produk'];
		$qty = $r['qty'] * -1;
		$harga = $r['harga'];

		mysql_query("INSERT INTO belitaxdetail(billno,produk,qty,harga) VALUES('$billno','$produk','$qty','$harga')");
	}
	mysql_query("delete from tmpbelitax where kasir = '$kasir'");
	include "updatestok2.php";
	header('location:data.php');
}
elseif ($module=='sales' AND $act=='editket'){
	$id=$_GET['id'];
	mysql_query("Update belitax set ket = '$_POST[ket]' where billno = $id");
	header('location:view.php?id='.$id);

}

elseif ($module=='sales' AND $act=='validasi'){
	$id = $_GET[id];
	$dtV = date("Y-m-d");
	$dtV2 = date("H:i:s");
	
	mysql_query("Update belitax set valtime = '$dtV',valtm = '$dtV2', status = 'V' where billno = $id");
	header('location:data.php');

}
elseif ($module=='sales' AND $act=='validasiover'){
	$id = $_GET[id];
	$dtV = date("Y-m-d");
	$dtV2 = date("H:i:s");
	if($_SESSION['nama'] == 'KTR2'){
		mysql_query("Update orders set valtime = '$dtV',valtm = '$dtV2', status = 'Valid', over = '1' where billno = $id");
	}else{
		mysql_query("Update orders set billdate = '$dtV' ,valtime = '$dtV', valtm = '$dtV2', over = '1', status = 'Valid' where billno = $id");
	}
	header('location:edit.php?id='.$id);

}
elseif ($module=='sales' AND $act=='ordadd'){
	$dt1 = date("Y-m-d");
	$data = $_POST['choices'];
	mysql_query("INSERT INTO orderdetails(billno,code,qty) VALUES('$_GET[id]','$data[0]','$_POST[qty]')");
	header('location:edit.php?id='.$_GET[id]);

}
elseif ($module=='cust' AND $act=='edit'){
	//mysql_query("update customers set customername = '$_POST[nama]', address ='$_POST[alamat]', phone = '$_POST[telp]',wilayah = '$_POST[wilayah]' where customerid = $_GET[id]");
	header('location:data.php');

}
elseif ($module=='sales' AND $act=='delprodadd'){
	$urut = $_GET[urut];
	mysql_query("delete from orderdetails where urut = $urut");
	header('location:edit.php?id='.$_GET[id]);

}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');

}

?>
