<?php
error_reporting(0);
session_start();
include('menu.php');
include('db_connect.php');
$acid = $_SESSION['acid'];
$pumpid = $_SESSION['pump'];
$user_id =$_SESSION['user_id'];
$vecno=$_POST['vecno'];
$vecno=preg_replace("#[^0-9a-z]#i","",$vecno);
$productname=$_POST['productname'];
$amount=$_POST['amount'];
$quantity=$_POST['quantity'];
$price=$_POST['price'];
$productname1=$_POST['productname1'];
$amount1=$_POST['amount1'];
$quantity1=$_POST['quantity1'];
$price1=$_POST['price1'];
$pread=$_POST['pread'];
$cread=$_POST['cread'];
$mil=$_POST['mil'];
$indno=$_POST['indno'];
$btype=$_POST['btype'];
$total = $_POST['amount'];
$total1 = $_POST['amount1'];
$gtotal = $total+$total1;
$cgst2="";
$sgst2="";
$cgst21="";
$sgst21="";
$tgst="";
$totgst="";
//product one
$pdname = mysqli_query($con,"select * from master_product where pdt_code = '$productname' or pd_name = '$productname'");
$pd = mysqli_fetch_array($pdname);
$pdt_id = $pd['pdt_id'];
$cat = mysqli_query($con,"select * from category where id = '$pdt_id'");
$cat_view = mysqli_fetch_array($cat);
$type = $cat_view['pdt_category'];
$cgst = $pd['cgst'];
$sgst = $pd['sgst'];
$cgst2 = $total * ($cgst/100);
$sgst2 = $total * ($sgst/100);
$tgst = $cgst2 + $sgst2;
//product two
$pdname1 = mysqli_query($con,"select * from master_product where pdt_code = '$productname1' or pd_name = '$productname1'");
$pd1 = mysqli_fetch_array($pdname1);
$pdt_id1 = $pd1['pdt_id'];
$cat1 = mysqli_query($con,"select * from category where id = '$pdt_id1'");
$cat_view1 = mysqli_fetch_array($cat1);
$type1 = $cat_view1['pdt_category'];
$productname1 = $pd1['pd_name'];
$cgst1 = $pd1['cgst'];
$sgst1 = $pd1['sgst'];
$cgst21 = $total1 * ($cgst1/100);
$sgst21 = $total1 * ($sgst1/100);
$totgst = $cgst21 + $sgst21;
//$productname=$_POST['productname'];
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.search-box input[type="text"]').on("keyup input", function(){
/* Get input value on change */
var inputVal = $(this).val();
var resultDropdown = $(this).siblings(".result");
if(inputVal.length){
$.get("vechicle_search.php", {term: inputVal}).done(function(data){
// Display the returned data in browser
resultDropdown.html(data);
});
} else{
resultDropdown.empty();
}
});
// Set search input value on click of result item
$(document).on("click", ".result p", function(){
$(this).parents(".search-box").find('input[type="text"]').val($(this).text());
$(this).parent(".result").empty();
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$('.search-box1 input[type="text"]').on("keyup input", function(){
/* Get input value on change */
var inputVal = $(this).val();
var resultDropdown = $(this).siblings(".result1");
if(inputVal.length){
$.get("product_search.php", {term: inputVal}).done(function(data){
// Display the returned data in browser
resultDropdown.html(data);
});
} else{
resultDropdown.empty();
}
});
// Set search input value on click of result item
$(document).on("click", ".result1 p", function(){
$(this).parents(".search-box1").find('input[type="text"]').val($(this).text());
$(this).parent(".result1").empty();
});
});
</script>
<div id="content">
<div id="content-header">
<div id="breadcrumb">
<a href="dashboard.php" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> Home</a><a href="sales.php" title="Go to Sales" class="tip-bottom">Sales</a>
</div>
</div>
<body>
<div class="container-fluid">
<div class="form">
<div class="span12">
<div class="widget-box">
<div class="widget-title"> <span class="icon"> <i class="icon-align-justify"></i> </span>
<h5>Sales-info</h5>
</div>
<div class="widget-content nopadding">
<form action="" method="post" class="form-vertical" name="sales_1_fm">
<div class="span3 control-group">
<label class="control-label">Vechicle No</label>
<div class="controls">
<div class="search-box">
<input type="text" id="vec" name="vecno" autocomplete="OFF" class="vecno" onchange="javascript:document.sales_1_fm.submit();"
value="<?php
if(isset($vecno))
{
echo $vecno;
}
?>">
<div class="result"></div>
</div>
</div>
</div>
<script>
document.getElementById('#vec').value="<?php if(isset($vecno)){ echo $vecno; } ?>";
</script>
<div class="span3 control-group">
<label class="control-label">Previous Reading</label>
<div class="controls">
<input type="text" name="pread" value="<?php
$sql1=mysqli_query($con,"select * from add_vechicle where vechicle_no='".$vecno."' or cus_name = '$vecno' ");
if($res1=mysqli_fetch_array($sql1))
{
echo $res1['starting_km'];
}
?>">
</div>
</div>
<div class="span3 control-group">
<label class="control-label">Current Reading</label>
<div class="controls">
<input type="text" name="cread" id="cread" value="<?php
if(isset($cread))
{
echo $cread;
}
?>">
</div>
</div>
<script>
document.getElementById('#cread').value="<?php if(isset($cread)){ echo $cread; } ?>";
</script>
<div class="span3 control-group">
<label class="control-label">Mileage</label>
<div class="controls">
<input type="text" name="mil" id="mil" value="<?php
if(isset($mil))
{
echo $mil;
}
?>">
</div>
</div>
<script>
document.getElementById('#mil').value="<?php if(isset($mil)){ echo $mil; } ?>";
</script>
<div class="span3 control-group">
<label class="control-label">Indent No</label>
<div class="controls">
<input type="text" name="indno" id="indno" value="<?php
if(isset($indno))
{
echo $indno;
}
?>">
</div>
</div>
<script>
document.getElementById('#indno').value="<?php if(isset($indno)){ echo $indno; } ?>";
</script>
<div class="span3 control-group">
<label class="control-label">Bill Type</label>
<div class="controls">
<select name="btype" id="bill">
<option value="credit">CREDIT SALES</option>
<option value="cash">CASH SALES</option>
<option value="fleet">FLEET CARD SALES</option>
<option value="card">CARD SALES</option>
<option value="density">DENSITY</option>
<option value="testing">TESTING</option>
</select>
</div>
</div>
<script>
document.getElementById('#bill').value="<?php if(isset($btype)){ echo $btype; } ?>";
</script>
<div class="control-group" style="padding-top:20px;">
<input type="submit" class="btn btn-success" name="save" value="Save">
<a href="print.php?vec_no=<?php echo $vecno; ?>billno=<?php echo $order_id; ?>" class="btn btn-success">PRINT</a>
</div>
<table class="table table-bordered table-striped">
<thead>
<td>S.NO</td>
<td>PRODUCT</td>
<td>RATE</td>
<td>AMOUNT</td>
<td>QUANTITY</td>
</thead>
<tbody class="detail">
<tr>
<td class="no">1</td>
<td> <div class="search-box1"><input type="text" autocomplete="OFF" id="productname" name="productname" id="pdname" onchange="javascript:document.sales_1_fm.submit();"
value="<?php
if(isset($productname))
{
echo $productname;
}
?>">
<div class="result1"></div>
</div>
</td>
<script>
document.getElementById('#productname').value="<?php if(isset($productname)){ echo $productname; } ?>";
</script>
<td><input type="text" id="price" name="price" value="<?php
$sql11=mysqli_query($con,"select * from master_product where pdt_code = '$productname' or pd_name = '$productname' ");
if($res11=mysqli_fetch_array($sql11))
{
echo $res11['sel_price'];
}
?>"></td>
<script>
document.getElementById('#price').value="<?php if(isset($price)){ echo $price; } ?>";
</script>
<td><input type="text" id="amount" name="amount" onchange="javascript:document.sales_1_fm.submit();" value="<?php
if(isset($amount))
{
echo $amount;
}
?>"></td>
<script>
document.getElementById('#amount').value="<?php if(isset($amount)){ echo $amount; } ?>";
</script>
<td><input type="text" id="quantity" name="quantity" value="<?php
if(isset($quantity))
{
echo $quantity = round($total/$price,2);
}
?>"></td>
<script>
document.getElementById('#id').value="<?php if(isset($quantity)){ echo $quantity; } ?>";
</script>
</tr>
<tr>
<td class="no">2</td>
<td><div class="search-box1"><input type="text" id="productname1" name="productname1" id="pdname" onchange="javascript:document.sales_1_fm.submit();"
value="<?php
/* $sql12=mysqli_query($con,"select * from master_product where pdt_code like '%$productname1%' or pd_name like'%$productname1%'");
if($res12=mysqli_fetch_array($sql12))
{
$productname1 = $res12['pd_name'];
} */
if(!empty($productname1))
{
echo $productname1;
}
?>">
<div class="result1"></div>
</div>
</td> <script>
document.getElementById('#productname1').value="<?php if(isset($productname1)){ echo $productname1; } ?>";
</script>
<td><input type="text" id="price1" name="price1" value="<?php
$sql12=mysqli_query($con,"select * from master_product where pdt_code = '$productname1' or pd_name = '$productname1'");
if($res12=mysqli_fetch_array($sql12))
{
echo $res12['sel_price'];
}
?>"></td>
<script>
document.getElementById('#price1').value="<?php if(isset($price1)){ echo $price1; } ?>";
</script>
<td><input type="text" id="amount1" name="amount1" onchange="javascript:document.sales_1_fm.submit();" value="<?php
if(isset($amount1))
{
echo $amount1;
}
?>"></td>
<script>
document.getElementById('#amount1').value="<?php if(isset($amount1)){ echo $amount; } ?>";
</script>
<td><input type="text" id="quantity1" name="quantity1" value="<?php
if(isset($quantity1))
{
echo $quantity1 = round($total1/$price1,2);
}
?>"></td>
<script>
document.getElementById('#quantity1').value="<?php if(isset($quantity1)){ echo $quantity1; } ?>";
</script>
</tr>
</tbody>
<tfoot>
<th></th>
<th></th>
<th style="color:#000;"><h5>OVERALL :</h5></th>
<th style="color:#000;text-align:center;" class="total"><h5><?php if($tgst!="0") { echo $tgst + $gtotal; } elseif($totgst!="0"){ echo $totgst + $gtotal; } else { echo 0; }?></h5></th>
<th></th>
</tfoot>
<tfoot>
<th></th>
<th></th>
<th style="color:#000;"><h5>TOTAL :</h5></th>
<th style="color:#000;text-align:center;" class="total"><h5><?php echo $gtotal; ?></h5></th>
<th></th>
</tfoot>
<tfoot>
<th></th>
<th></th>
<th style="color:#000;"><h5>CGST :</h5></th>
<th style="color:#000;text-align:center;" class="total"><h5><?php if($cgst2!="0") {echo $cgst2; } elseif($cgst21!="0"){ echo $cgst21; } else { echo 0; }?></h5></th>
<th></th>
</tfoot>
<tfoot>
<th></th>
<th></th>
<th style="color:#000;"><h5>SGST :</h5></th>
<th style="color:#000;text-align:center;" class="total"><h5><?php if($sgst2!="0") {echo $sgst2; } elseif($sgst21!="0"){ echo $sgst21; } else { echo 0; }?></h5></th>
<th></th>
</tfoot>
</table>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<?php
include('footer.php');
?>
</div>
</body>
<script type="text/javascript">
/* $(function()
{
$('#add').click(function()
{
addnewrow();
});
$('body').delegate('.remove','click',function()
{
$(this).parent().parent().remove();
});
$('body').delegate('.quantity,.price','keyup',function()
{
vartr=$(this).parent().parent();
varqty=tr.find('.quantity').val();
var price=tr.find('.price').val();
varamt =(qty * price)
tr.find('.amount').val(amt);
total();
});
});
function total()
{
var t=0;
$('.amount').each(function(i,e)
{
varamt =$(this).val()-0;
t+=amt;
});
$('.total').html(t);
}
function addnewrow()
{
var n=($('.detail tr').length-0)+1;
var tr = '<tr>'+
'<td class="no">'+n+'</td>'+
'<td><input type="text" class="form-control productname" name="productname[]"></td>'+
'<td><input type="text" class="form-control quantity" name="quantity[]"></td>'+
'<td><input type="text" class="form-control price" name="price[]"></td>'+
'<td><input type="text" class="form-control amount" name="amount[]"></td>'+
'<td><a href="#" class="remove">Delete</td>'+
'</tr>';
$('.detail').append(tr);
} */
</script>
<?php
if(isset($_POST['save']))
{
header("Location: print.php");
$date = date('Y-m-d');
$vecno=$_POST['vecno'];
$vecno=preg_replace("#[^0-9a-z]#i","",$vecno);
$pread=$_POST['pread'];
$cread=$_POST['cread'];
$mil=$_POST['mil'];
$indno=$_POST['indno'];
$btype=$_POST['btype'];
$sql = mysqli_query($con,"select max(order_id) as order_id from transaction_details ");
$res = mysqli_fetch_array($sql);
$id=$res['order_id'];
$stock1 = mysqli_query($con,"select * from master_stock where pdt_name = '$productname'");
$cap = mysqli_fetch_array($stock1);
$stock = $cap['curr_stock'];
$cust = mysqli_query($con,"select * from add_vechicle where vechicle_no ='$vecno' or cus_name = '$vecno'");
$views = mysqli_fetch_array($cust);
$cus_name = $views['cus_name'];
//if($stock!="")
//{
//BILL NO 1
if($id=="")
{
$id1="1";
mysqli_query($con,"insert into transaction(order_id,vechicle_no,customer_name,previous_reading,current_reading,mileage,indent_no,bill_type,total_amount,shift_id,pump_name,date,emp_id)
VALUES ('$id1','$vecno','$cus_name','$pread','$cread','$mil','$indno','$btype','$gtotal','$acid','$pumpid','$date','$user_id')");
//product one
$pdname = mysqli_query($con,"select * from master_product where pdt_code = '$productname' or pd_name = '$productname'");
$pd = mysqli_fetch_array($pdname);
$pdt_id = $pd['pdt_id'];
$productname = $pd['pd_name'];
$cat = mysqli_query($con,"select * from category where id = '$pdt_id");
$cat_view = mysqli_fetch_array($cat);
$type = $cat_view['pdt_category'];
//product two
$pdname1 = mysqli_query($con,"select * from master_product where pdt_code = '$productname1' or pd_name = '$productname1'");
$pd1 = mysqli_fetch_array($pdname1);
$pdt_id1 = $pd1['pdt_id'];
$productname1 = $pd1['pd_name'];
$cat1 = mysqli_query($con,"select * from category where id = '$pdt_id1'");
$cat_view1 = mysqli_fetch_array($cat1);
$type1 = $cat_view1['pdt_category'];
if(empty($_POST['productname1']))
{
mysqli_query($con,"INSERT INTO transaction_details (order_id,product_name,qty,unit_price,amount,type,shift_id,pump_name,addeddate,empid) values('".$id1."','".$productname."','".$_POST['quantity']."','".$_POST['price']."','".$_POST['amount']."','$type','$acid','$pumpid','".$date."','$user_id')");
}
else
{
$ins = "INSERT INTO transaction_details (order_id,product_name,qty,unit_price,amount,type,shift_id,pump_name,addeddate,empid) values('".$id1."','".$productname."','".$_POST['quantity']."','".$_POST['price']."','".$_POST['amount']."','$type','$acid','$pumpid','".$date."','$user_id');";
$ins .= "INSERT INTO transaction_details (order_id,product_name,qty,unit_price,amount,type,shift_id,pump_name,addeddate,empid) values('".$id1."','".$productname1."','".$_POST['quantity1']."','".$_POST['price1']."','".$_POST['amount1']."','$type1','$acid','$pumpid','".$date."','$user_id');";
mysqli_multi_query($con,$ins);
}
}
//BILL NO INCREMENT
else
{
$id = $res['order_id'] + 1;
mysqli_query($con,"insert into transaction(order_id,vechicle_no,customer_name,previous_reading,current_reading,mileage,indent_no,bill_type,total_amount,shift_id,pump_name,date,emp_id)
VALUES ('$id','$vecno','$cus_name','$pread','$cread','$mil','$indno','$btype','$gtotal','$acid','$pumpid','$date','$user_id')");
//product one
$pdname = mysqli_query($con,"select * from master_product where pdt_code = '$productname' or pd_name = '$productname'");
$pd = mysqli_fetch_array($pdname);
$pdt_id = $pd['pdt_id'];
$cat = mysqli_query($con,"select * from category where id = '$pdt_id'");
$cat_view = mysqli_fetch_array($cat);
$type = $cat_view['pdt_category'];
$productname = $pd['pd_name'];
//product two
$pdname1 = mysqli_query($con,"select * from master_product where pdt_code = '$productname1' or pd_name = '$productname1'");
$pd1 = mysqli_fetch_array($pdname1);
$pdt_id1 = $pd1['pdt_id'];
$cat1 = mysqli_query($con,"select * from category where id = '$pdt_id1'");
$cat_view1 = mysqli_fetch_array($cat1);
$type1 = $cat_view1['pdt_category'];
$productname1 = $pd1['pd_name'];
if(empty($_POST['productname1']))
{
mysqli_query($con,"INSERT INTO transaction_details (order_id,product_name,qty,unit_price,amount,type,shift_id,pump_name,addeddate,empid) values('".$id."','".$productname."','".$_POST['quantity']."','".$_POST['price']."','".$_POST['amount']."','$type','$acid','$pumpid','".$date."','$user_id')");
}
else
{
$ins = "INSERT INTO transaction_details (order_id,product_name,qty,unit_price,amount,type,shift_id,pump_name,addeddate,empid) values('".$id."','".$productname."','".$_POST['quantity']."','".$_POST['price']."','".$_POST['amount']."','$type','$acid','$pumpid','".$date."','$user_id');";
$ins .= "INSERT INTO transaction_details (order_id,product_name,qty,unit_price,amount,type,shift_id,pump_name,addeddate,empid) values('".$id."','".$productname1."','".$_POST['quantity1']."','".$_POST['price1']."','".$_POST['amount1']."','$type1','$acid','$pumpid','".$date."','$user_id');";
mysqli_multi_query($con,$ins);
}
}
header("Location: print.php");
//}
//else
//{
// echo "<script>alert('There is no stock for this product')</script>";
//}
}
?>
It would be useful if you could define what you mean by “not working”
You can’t do a header relocate after you’ve sent anything to the browser. You’ve sent your entire page to it prior to the header output, so you’ll just get a “headers already sent” message. Move all the form-processing code to the start of the script, prior to any output, and it should be better.
If that doesn’t work, we need more information.
You also really need to look into a bit more security, you’re placing user form input directly into your queries which can lead to trouble.
This is a seriously badly written script. TWENTY-TWO queries in the same page??? WOW!!!
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.