You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.2 KiB
PHP

<?php
session_start();
if($_SESSION['validUser'] !== TRUE)
{
header("location: ./index.php");
exit();
}
?>
<?php
include "./db_login.inc.php";
include "./func_lib.php";
$kodebarang = $_REQUEST['kodebarang'];
$barcode = strtoupper($_REQUEST['barcode']);
$nama = strtoupper($_REQUEST['nama']);
$jmlbeli = $_REQUEST['jmlbeli'];
$subtotal = $_REQUEST['subtotal'];
$hpbaru = convHrgP($_REQUEST['hpbaru']);
$hp = $_REQUEST['hpbaru'];
$hjbaru = $_REQUEST['hjbaru'];
$bathi = ($hjbaru-$hp)/$hp*100;
$disc = $_REQUEST['disc'];
$discrp = $_REQUEST['discrp'];
$ppn = $_REQUEST['ppn'];
$profit = number_format($bathi,2,'.',',');
$expdate = decTgl($_REQUEST['expdate']);
$pemakai = $_SESSION["useracc"];
$qry_createtmp = "CREATE TABLE IF NOT EXISTS `tPembelian$pemakai` (
`id` int(11) NOT NULL auto_increment,
`kode_barang` char(12) NOT NULL,
`barcode` varchar(30) default NULL,
`nm_brg` varchar(100) NOT NULL,
`jumlah` int(11) NOT NULL,
`subtotal` bigint(20) NOT NULL,
`disc` float NOT NULL,
`discrp` bigint(20) NOT NULL,
`profit` float NOT NULL,
`ppn` float NOT NULL,
`harga_pokok` varchar(30) NOT NULL,
`harga_jual` bigint(20) NOT NULL,
`exp` date default NULL,
PRIMARY KEY (`id`),
KEY `kd_brg` (`kode_barang`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
runQuery($qry_createtmp);
$harray = array();
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
if (!empty($kodebarang) AND !empty($nama) AND !empty($jmlbeli) AND !empty($subtotal))
{
$dtInsert = $mysqli->prepare("INSERT INTO `tPembelian$pemakai`(
`id`,
`kode_barang` ,
`barcode` ,
`nm_brg` ,
`jumlah` ,
`subtotal` ,
`disc`,
`discrp`,
`profit`,
`ppn`,
`harga_pokok` ,
`harga_jual`,
`exp`
)
VALUES (NULL,'$kodebarang','$barcode','$nama','$jmlbeli','$subtotal','$disc','$discrp',
'$profit','$ppn','$hpbaru','$hjbaru','$expdate')");
$dtInsert->execute();
if($dtInsert->affected_rows > 0) {
$harray[0] = 1;
$dtInsert->close();
} else {
$harray[0] = 0;
}
$mysqli->close();
}else{
$harray[0] = 2;
}
echo json_encode($harray);
?>