<?php
session_start();
error_reporting(0);
include('includes/config.php'
;
if(isset($_POST['submit'])){
if(!empty($_SESSION['cart'])){
foreach($_POST['quantity'] as $key => $val){
if($val==0){
unset($_SESSION['cart'][$key]);
}else{
$_SESSION['cart'][$key]['quantity']=$val;
}
}
echo "<script>alert('Your Cart has been Updated');</script>";
}
}
// Code for Remove a Product from Cart
if(isset($_POST['remove_code']))
{
if(!empty($_SESSION['cart'])){
foreach($_POST['remove_code'] as $key){
unset($_SESSION['cart'][$key]);
}
echo "<script>alert('Your Cart has been Updated');</script>";
}
}
// code for insert product in order table
if(isset($_POST['ordersubmit']))
{
if(strlen($_SESSION['login'])==0)
{
header('location:login.php'
;
}
else{
$quantity=$_POST['quantity'];
$pdd=$_SESSION['pid'];
$value=array_combine($pdd,$quantity);
foreach($value as $qty=> $val34){
mysqli_query($con,"insert into orders(userId,productId,quantity) values('".$_SESSION['id']."','$qty','$val34'
"
;
header('location:payment-method.php'
;
}
}
}
?>
<!DOCTYPE html>
<html lang="en" style = "background-color: #07A612;">
<head>
<!-- Meta -->
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="description" content="">
<meta name="author" content="">
<meta name="keywords" content="MediaCenter, Template, eCommerce">
<meta name="robots" content="all">
<title>My Cart</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/main.css">
<link rel="stylesheet" href="assets/css/green.css">
<link rel="stylesheet" href="assets/css/owl.carousel.css">
<link rel="stylesheet" href="assets/css/owl.transitions.css">
<!--<link rel="stylesheet" href="assets/css/owl.theme.css">-->
<link href="assets/css/lightbox.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/animate.min.css">
<link rel="stylesheet" href="assets/css/rateit.css">
<link rel="stylesheet" href="assets/css/bootstrap-select.min.css">
<!-- Demo Purpose Only. Should be removed in production -->
<link rel="stylesheet" href="assets/css/config.css">
<link href="assets/css/green.css" rel="alternate stylesheet" title="Green color">
<link href="assets/css/blue.css" rel="alternate stylesheet" title="Blue color">
<link href="assets/css/red.css" rel="alternate stylesheet" title="Red color">
<link href="assets/css/orange.css" rel="alternate stylesheet" title="Orange color">
<link href="assets/css/dark-green.css" rel="alternate stylesheet" title="Darkgreen color">
<!-- Demo Purpose Only. Should be removed in production : END -->
<!-- Icons/Glyphs -->
<link rel="stylesheet" href="assets/css/font-awesome.min.css">
<!-- Fonts -->
<link href='http://fonts.googleapis.com/css?family=Roboto:300,400,500,700' rel='stylesheet' type='text/css'>
<!-- Favicon -->
<link rel="shortcut icon" href="assets/images/favicon.ico">
<!-- HTML5 elements and media queries Support for IE8 : HTML5 shim and Respond.js -->
<!--[if lt IE 9]>
<script src="assets/js/html5shiv.js"></script>
<script src="assets/js/respond.min.js"></script>
<![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body class="cnt-home">
<!-- ============================================== HEADER ============================================== -->
<header class="header-style-1">
<?php include('includes/top-header1.php'
;?>
<?php include('includes/main-header1.php'
;?>
</header>
<!-- ============================================== HEADER : END ============================================== -->
<div class="breadcrumb">
<div class="container">
<div class="breadcrumb-inner">
<ul class="list-inline list-unstyled">
<li><a href="home.php">Home</a></li>
<li class='active'>Avail Products</li>
</ul>
</div><!-- /.breadcrumb-inner -->
</div><!-- /.container -->
</div><!-- /.breadcrumb --><?php
require_once('auth.php'
;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="logo.jpg">
<!-- Bootstrap Core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- MetisMenu CSS -->
<link href="vendor/metisMenu/metisMenu.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="dist/css/sb-admin-2.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link href="src/facebox.css" media="screen" rel="stylesheet" type="text/css" />
<script src="lib/jquery.js" type="text/javascript"></script>
<script src="src/facebox.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('a[rel=facebox]'
.facebo
{
loadingImage : 'src/loading.gif',
closeImage : 'src/closelabel.png'
})
})
</script>
</head>
<body>
<?php include('navfixed.php'
;?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header"><a style = "color:green;" href="home.php"><i class="fa fa-undo fa-fw"></i></a>Payment | <?php echo $_GET['id']; ?> </h1>
</div>
<div id="maintable"><div style="margin-top: -19px; margin-bottom: 21px;">
</div>
<form action="incoming.php" method="post" class = "form-group" >
<input type="hidden" name="pt" class = "form-control" value="<?php echo $_GET['id']; ?>" />
<input type="hidden" name="invoice" class = "form-control" value="<?php echo $_GET['invoice']; ?>" />
<label>Select a Product</label><br />
<select name="product" style="width:800px;" class="chzn-select" onchange="$('#imageToSwap'
.attr('src', this.options[this.selectedIndex].value);">
<option></option>
<?php
include('connect.php'
;
$result = $db->prepare("SELECT FROM products"
;
$result->bindParam(':userid', $res);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<option value="../uploads/<?php echo $row['image_location'];?>"
<?php
if($row['qty_left'] <= 0)
{
echo'disabled';
}
?>
>
<?php echo $row['product_code'];?>
Product: <?php echo $row['product_name']; ?>
- Quantity Left: <?php echo $row['qty_left']; ?>
- Price: ₱<?php echo $row['price']; ?>
</option>
<?php
}
?>
</select>
<?php if($row['image_location'] != ""
: ?>
<img id="imageToSwap" class="profile" src="../uploads/<?php echo $row['image_location']; ?>" value = "<?php echo $row['image_location']; ?>" width="200px" height="200px" style="border:1px solid #333333;">
<?php else: ?>
<img id="imageToSwap" class="profile" src="../images/default.png" value = "<?php echo $row['image_location']; ?>"width="200px" height="200px" style="border:1px solid #333333;">
<?php endif; ?>
<br /><p> <?php echo $row['price']; ?> </p>
<label>Number of Item</label>
<input type="number" name="qty" value="1" min = "1" class = "form-control" autocomplete="off" style="width: 100px; padding-top: 6px; padding-bottom: 6px; margin-right: 4px;" />
<label>Discount</label>
<input type="text" name="discount" value="0" class = "form-control" autocomplete="off" style="width: 100px; padding-top: 6px; padding-bottom: 6px; margin-right: 4px;" readonly/>
<label>Value Add Tax:</label>
<input type="text" name="vat" value="0" class = "form-control" autocomplete="off" style="width: 100px; padding-top: 6px; padding-bottom: 6px; margin-right: 4px;" readonly/>
<br>
<input type="submit" name = "Submit" style = "background-color:green;"class="btn btn-primary" value="Add to Cart" class = "form-control" style="width: 123px;" />
</form>
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th> Product Code </th>
<th> Brand Name </th>
<th> Description Name </th>
<th> Category </th>
<th> Quantity </th>
<th> Price </th>
<th> Discount </th>
<th> VAT </th>
<th> Amount </th>
<th> Total Amount </th>
<!-- <th> Image </th>-->
<th> Delete </th>
</tr>
</thead>
<tbody>
<?php
$id=$_GET['invoice'];
include('connect.php'
;
$result = $db->prepare("SELECT * FROM sales_order WHERE invoice= :userid"
;
$result->bindParam(':userid', $id);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<tr class="record">
<td><?php echo $row['product']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['dname']; ?></td>
<td><?php echo $row['category']; ?></td>
<td><?php echo $row['qty']; ?></td>
<td>
<?php
$ppp=$row['price'];
echo formatMoney($ppp, true);
?>
</td>
<td>
<?php
$ddd=$row['discount'];
echo formatMoney($ddd, true);
?>
</td>
<td>
<?php
$fff=$row['vat'];
echo formatMoney($fff, true);
?>
</td>
<td>
<?php
$ccc=$row['amount'];
echo formatMoney($ccc, true);
?>
</td>
<td>
<?php
$dfdf=$row['total_amount'];
echo formatMoney($dfdf, true);
?>
</td>
<!-- <td>
<?php
?>
<?php if($row['image_location'] != ""
: ?>
<img src="../uploads/<?php echo $row['image_location']; ?>" width="100px" height="100px" style="border:1px solid #333333;">
<?php else: ?>
<img src="../images/default.png" width="100px" height="100px" style="border:1px solid #333333;">
<?php endif; ?>
</td>-->
<td><a href="delete.php?id=<?php echo $row['transaction_id']; ?>&invoice=<?php echo $_GET['invoice']; ?>&dle=<?php echo $_GET['id']; ?>&qty=<?php echo $row['qty'];?>&code=<?php echo $row['product'];?>"> Delete</a></td>
</tr>
<?php
}
?>
<tr>
<td colspan="9"><strong style="font-size: 12px; color: #222222;">Total:</strong></td>
<td colspan="3"><strong style="font-size: 12px; color: #222222;">
<?php
function formatMoney($number, $fractional=false) {
if ($fractional) {
$number = sprintf('%.2f', $number);
}
while (true) {
$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
if ($replaced != $number) {
$number = $replaced;
} else {
break;
}
}
return $number;
}
$sdsd=$_GET['invoice'];
$resultas = $db->prepare("SELECT sum(total_amount) FROM sales_order WHERE invoice= :a"
;
$resultas->bindParam(':a', $sdsd);
$resultas->execute();
for($i=0; $rowas = $resultas->fetch(); $i++){
$fgfg=$rowas['sum(total_amount)'];
echo formatMoney($fgfg, true);
}
?>
</strong></td>
</tr>
</tbody>
</table><br>
<strong> <input type="checkbox" id="check" /> NOTE: Please be informed that the minimum purchase is ₱1000 worth of products. If not, your order will be void. <br><br>
<a rel="facebox" id="submit1" style = "background-color:green;"class = "btn btn-primary" href="checkout.php?pt=<?php echo $_GET['id']?>&invoice=<?php echo $_GET['invoice']?>&total=<?php echo $fgfg ?>&cashier=<?php echo $session_cashier_name?>&p_amount=<?php echo $ccc?>"
disabled>Check Out</a>
<div class="clearfix"></div>
</div>
</div>
</div><br><br>
<!-- /#page-wrapper -->
<script>
$('#check'
.click(function() {
if ($(this).is(':checked'
) {
$('#submit1'
.removeAttr('disabled'
;
} else {
$('#submit1'
.attr('disabled', 'disabled'
;
}
});
</script>
<!-- jQuery -->
<script src="vendor/jquery/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="vendor/metisMenu/metisMenu.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="dist/js/sb-admin-2.js"></script>
<link href="vendor/chosen.min.css" rel="stylesheet" media="screen">
<script src="vendor/chosen.jquery.min.js"></script>
<script>
$(function() {
$(".chzn-select"
.chosen();
});
</script>
</body><?php include('includes/footer.php'
;?>
</html>
then this is the error page
<?php
session_start();
include('connect.php'
;
$a = $_POST['invoice'];
$b = $_POST['product'];
$c = $_POST['qty'];
$w = $_POST['pt'];
$r = $_POST['vat'];
$date = date('m/d/Y'
;
$month = date('F'
;
$year = date('Y'
;
$discount = $_POST['discount'];
$result = $db->prepare("SELECT * FROM products WHERE product_code= :userid"
;
$result->bindParam(':userid', $b);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
$asasa=$row['price'];
$name=$row['product_name'];
$dname=$row['description_name'];
$categ=$row['category'];
$qtyleft=$row['qty_left'];
}
//edit qty
$sql = "UPDATE products
SET qty_left=qty_left-?
WHERE product_code=?";
$q = $db->prepare($sql);
$q->execute(array($c,$b));
$fffffff=$asasa-$discount;
$d=$fffffff$c;
$z=$qtyleft-$c;
$vat=$d$r;
$total=$vat+$d;
// query
$sql = "INSERT INTO sales_order (invoice,product,qty,amount,name,price,discount,category,date,omonth,oyear,qtyleft,dname,vat,total_amount) VALUES (:a,:b,:c,:d,:e,:f,:g,:h,:i,:j,:k,:l,:m,:n,:o)";
$q = $db->prepare($sql);
$q->execute(array(':a'=>$a,':b'=>$b,':c'=>$c,':d'=>$d,':e'=>$name,':f'=>$asasa,':g'=>$discount,':h'=>$categ,':i'=>$date,':j'=>$month,':k'=>$year,':l'=>$z,':m'=>$dname,':n'=>$vat,':o'=>$total));
header("location: sales.php?id=$w&invoice=$a"
;
?>