
<?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");
	}
	
	$data = $_POST['choices'];
	$cust = $_POST['choices222'];
	
	$price = $_POST['harga'];
	$antar = $_POST['antar'];
	$kasir = $_SESSION['nama'];
	if ($kasir == "juli"){
		$kasir = "KTR";
	}
	if ($data[0] == "" or $data[0] == 0){
		echo "<link href=../config/adminstyle.css rel=stylesheet type=text/css>";
		  echo "<center>ORDER GAGAL!<br> 
				Anda belum mengisi produk.<br>";
		  echo "<a href='add.php'><b>ULANGI LAGI</b></a></center>";
	}else{
	mysql_query("INSERT INTO orders(billdate,Customerid,grandtotal,code,qty,price,antar,keterangan,kasir,bonus,ida) VALUES('$dt1','$cust[0]','0','$data[0]','$_POST[qty]','$price','$antar','$_POST[ket]','$kasir','$_POST[bonus]','$_POST[ket2]')");
	header('location:data.php');
	}

}
elseif ($module=='sales' AND $act=='edit'){
	$price = $_POST['harga'];
	$price = str_replace(".","",$price);
	$price = str_replace(",","",$price);
	$id = $_GET[id];
	$status = mysql_result(mysql_query("select status from orders where billno = $_GET[id]"),0);
	if($status == "New"){
		mysql_query("Update orders set bonus = '$_POST[bonus]',qty = '$_POST[qty]', price = '$price',antar = '$_POST[antar]',keterangan = '$_POST[ket]' where billno = $id");
	}else{
		mysql_query("Update orders set ida = '$_POST[ket2]', keterangan = '$_POST[ket]' where billno = $id");
	}
	header('location:data.php');

}
elseif ($module=='sales' AND $act=='batal'){
	$id = $_GET[id];
	mysql_query("Update orders set batal = '1' where billno = $id");

	header('location:data.php');

}
elseif ($module=='sales' AND $act=='proses'){
	$id = $_GET[id];

	mysql_query("Update ordercust set lacak = 'On Progress' where billno = $id");
	header('location:data.php');

}
elseif ($module=='sales' AND $act=='validasiover'){
	$id = $_GET[id];
	mysql_query("Update orders set 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');

}

?>
