
<?php

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

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

		mysql_query("INSERT INTO jualcsdetail(billno,produk,qty,harga) VALUES('$billno','$produk','$qty','$harga')");
	}
	mysql_query("delete from tmpjualcs where kasir = '$kasir'");
	header('location:data.php');
}

elseif ($module=='sales' AND $act=='validasi'){
	$id = $_GET[id];
	$dtV = date("Y-m-d");
	$dtV2 = date("H:i:s");
	
	mysql_query("Update jualcs set valtime = '$dtV',valtm = '$dtV2', status = 'V' 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');

}

?>
