billing

0
22

<?php
session_start();
error_reporting(0);
include_once('dbconnect/dbconnection.php');
date_default_timezone_set('Asia/calcutta');
if($_SESSION['id']=='')
{
header("Location:index.php");
exit;
}
if(isset($_GET['uid'])){
$id=$_GET['uid'];
//echo $id;die;
$sql = "SELECT * FROM `temp_billing` WHERE `id`='$id'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$tempQty=$row["quantity"];
$tempmetre=$row["metre"];
$productId=$row["product_id"];

$sql = "SELECT * FROM `products` WHERE `id`='$productId'";
$result=mysql_query($sql);
$row1=mysql_fetch_array($result);
$productQty=$row1["qty"];
$totalQty=$tempQty+$productQty;
$metreqty=$row1["metre"];
$totalmetre=$tempQty+$metreqty;
if($productQty>=0){

$query_run2=mysql_query("update products set qty='$totalQty' where id='$productId'") or die(mysql_error());
}else if($row1['metre']>=0){

$query_run2=mysql_query("update products set metre='$totalmetre' where id='$productId'") or die(mysql_error());
}
$sql = "DELETE FROM `temp_billing` WHERE `id`='$id'";
mysql_query($sql);
header('Location:billing.php');
}

if (isset($_POST['add'])) {
$cus_name = $_POST['cus_name'];
setcookie(cus_name, $cus_name, time() + (86400 * 30));
$bill_date = $_POST['bill_date'];
setcookie(bill_date, $bill_date, time() + (86400 * 30));
//$cus_num = $_POST['cus_num'];
//setcookie(cus_num, $cus_num, time() + (86400 * 30));
//$categories = $_POST['categories'];
$products = mysql_real_escape_string($_POST['products']);
$hsn_code = mysql_real_escape_string($_POST['hsn_code']);
$quantity = mysql_real_escape_string($_POST['quantity']);
$item_num = mysql_real_escape_string($_POST['item_num']);
$item_size = mysql_real_escape_string($_POST['item_size']);
//$batch = mysql_real_escape_string($_POST['batch']);

//$expiry = mysql_real_escape_string($_POST['expiry']);
//$free = mysql_real_escape_string($_POST['free']);
$mrpprice = mysql_real_escape_string($_POST['mrpprice']);


$price = mysql_real_escape_string($_POST['price']);
$discount = mysql_real_escape_string($_POST['discount']);
$tax = mysql_real_escape_string($_POST['tax']);
$sgst=$tax/2;
$cgst=$tax/2;
$igst = mysql_real_escape_string($_POST['igst']);
$tprice = $_POST['tprice'];
//$purchase_date =date('Y-m-d');
$purchase_date =date('Y-m-d',strtotime($bill_date));
//$quantityPrice=$quantity*$price;

$sql="insert into temp_billing set customer_name='$cus_name',
customer_phone='$cus_num', product_id='$products',hsn_code='$hsn_code',item_num='$item_num',item_size='$item_size',
quantity ='$quantity',purchase_date ='$purchase_date', price='$price',mrpprice='$mrpprice', discount='$discount', tax='$sgst',cgst='$cgst',igst='$igst', total='$tprice' ";
$query_run1=mysql_query($sql) or die(mysql_error());

$sql="select qty,metre from products where id=$products";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);


if($row['qty']){
$totalQty=$row['qty']-$quantity;
$query_run3=mysql_query("update products set qty='$totalQty' where id='$products'") or die(mysql_error());
}else if($row['metre'])
{
$totalQty=$row['metre']-$quantity;
$query_run3=mysql_query("update products set metre='$totalQty' where id='$products'") or die(mysql_error());

}
$_POST['products']="";
$_POST['hsn_code']="";
$_POST['quantity']="";
$_POST['mrpprice']="";
$_POST['price']="";
$_POST['discount']="";
$_POST['tax']="";
$_POST['tprice']="";
$purchase_date ="";
header('Location:billing.php');
}

$sn = 1;
$start=0;
$query_run=mysql_query("select * from `temp_billing`");
//header('Location:billing.php');

?>
<?php include("header.php");?>
<?php include("topmenu.php");?>
<script src="js/jquery-1.11.3.min.js"></script>
<!--<script src="js/jquery-migrate-1.2.1.min.js"></script>-->

<!--comment-->

<link href="css/bootstrap.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="css/css-table.css" />
<script src="js/select2.min.js"></script>
<link rel="stylesheet" href="css/select2.min.css">
<style>
.header-border{
background-color:#f5f5f5;
}

</style>



<div class="ts-main-content">
<?php //include("leftmenu.php");?>
<div class="content-wrapper" style="margin-left:0px;">
<div class="container-fluid">

<div class="row">
<div class="col-md-12">

<!--Start table-->
<div class="panel panel-default panels">
<div class="panel-heading">
<a href="dashboard.php" class="btb btn-success btn-sm">
<span class="fa fa fa-arrow-left"> BACK </span></a>
</div>

<form name="addbilling" method="post" >
<div class="panel-body">
<!--First table-->
<div class="table-responsive panelss" >
<table class="table table-bordered table-striped">
<thead class="header-borde">
<tr>
<th width="50%" >Retailer Name</th>
<th width="50%" >Date</th>
<!--<th>Customer Name</th>
<th>Customer Contact</th>-->

</tr>
</thead>
<tbody>
<tr>
<td width="23%">

<select style="overflow: visible;" class="form-control select2" name="cus_name" data-hide-disabled="true" data-live-search="true" required>
<option value="">-----SELECT-----</option>
<?php
$sql="select * from retailers order by name";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)){?>
<option value="<?php echo$row['id']; ?>" <?php if($_COOKIE['cus_name']==$row['id']){echo 'selected';}?>><?php echo $row['name'].'('.$row['contact_number'].')'; ?></option>
<?php }?>
</select>
</td>
<td width="23%">
<input type="date" class="" name="bill_date" value="<?php echo $_COOKIE['bill_date']; ?>" required>
</td>

<!--<td><input type="text" class="form-control" name="cus_name" id="cus_name" value="<?php //echo $_COOKIE['cus_name']; ?>"></td>
<td><input type="text" class="form-control" name="cus_num" id="cus_num" value="<?php //echo $_COOKIE['cus_num']; ?>"></td>-->

</tr>

</tbody>
</table></div>
<!--End first table-->

<!--second table-->
<div class="table-responsive panelsss">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th width="23%">Product / Barcode</th>
<th width="4%">Remaining Quantity</th>
<th width="7%">Item No.</th>
<th width="7%">Size</th>
<th width="7%">Quantity</th>

<!--<th width="8%">Purchase Price</th>-->
<th width="8%">MRP</th>
<th width="10%">Selling Price</th>
<th width="7%">Discount (%)</th>
<th width="7%">SGST+CGST (%)</th>
<th width="7%">IGST(%)</th>
<th width="15%">Total</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>

<td>
<select class="form-control productName" name="products" id="products" required="required"></select>
<!--<input type="text" class="form-control" name="hsn_code" autocomplete="off" id="hsn_code">-->
</td>


<td id="rem_quantity" align="center"></td>
<td><input type="text" class="form-control" name="item_num" autocomplete="off" id="item_num"></td>
<td><input type="text" class="form-control" name="item_size" autocomplete="off" id="item_size"></td>
<td>
<input type="text" class="form-control" name="quantity" autocomplete="off" required id="quantity" disabled>
<span id="quantity_error" style="color:#FF0000; float:left; display:none; ">*Required</span>
</td>


<!--<td><input type="text" class="form-control" name="price1" autocomplete="off" id="price1" readonly></td>-->
<td><input type="text" class="form-control" name="mrpprice" autocomplete="off" id="mrpprice" readonly></td>
<td><input type="text" class="form-control" required name="price" autocomplete="off" id="price" ></td>
<td><input type="text" class="form-control" name="discount" autocomplete="off" id="discount" ></td>
<td><input type="text" class="form-control" name="tax" autocomplete="off" id="tax" ></td>
<td><input type="text" class="form-control" name="igst" autocomplete="off" id="igst" ></td>
<td><input type="text" class="form-control" name="tprice" autocomplete="off" id="tprice" readonly></td>
<td><input type="submit" name="add" value="add" id="add" class="btn btn-success"></td>

</tr>

</tbody>
</form>
</table></div>
<!--End second table-->

<!--third table-->
<?php $num = mysql_num_rows($query_run); if($num>0) { ?>
<div class="table-responsive">
<table class="table table-bordered table-striped">
<form name="deqQuantity" action="deq_quantity.php" method="post" enctype="multipart/form-data">
<thead>
<tr>
<th>S.N.</th>
<!--<th>Category Name</th>-->
<th>Product</th>
<th>Barcode</th>
<th>HSN Code</th>
<th>Item No.</th>
<th>Size</th>
<th>Quantity</th>

<th>Price</th>
<th>MRP</th>
<th>Discount (%)</th>
<th>SGST+CGST (%)</th>
<th>IGST (%)</th>
<th>Total</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$totalPrice=0;
$tdiscountSum=0;$ttaxSum=0;$tcgst=0;$tigst=0; $price=0;$tquantity=0;
while($w=mysql_fetch_array($query_run)){
$tdiscountSum=$tdiscountSum+$w['discount'];
$ttaxSum=$ttaxSum+$w['tax'];
$price=$price+$w['price'];$tcgst=$tcgst+$w['cgst'];$tigst=$tigst+$w['igst'];
$tquantity=$tquantity+$w['quantity'];$totalPrice=$totalPrice+$w['total'];
?>
<tr>
<td><?php echo $sn+$start; ?>.</td>
<td>
<?php
$products = $w['product_id'];
$sql = mysql_query("select * from products where id='$products'");
$product_name = mysql_fetch_array( $sql);
echo ucfirst($product_name['name']);
?></td>
<td><?php echo $product_name['barcode'];?></td>
<td><?php echo $product_name['hsn_code'];?></td>
<td><?php echo $w['item_num'];?></td>
<td><?php echo $w['item_size'];?></td>
<td><?php echo $w['quantity'];?></td>

<td><?php echo $w['price'];?></td>
<td><?php echo $w['mrpprice'];?></td>
<td><?php echo $w['discount'];?></td>
<td><?php echo $w['tax']+$w['cgst'];?></td>
<td><?php echo $w['igst'];?></td>
<td><?php echo number_format($w['price']*$w['quantity'],2);?></td>
<td> <a href="billing.php?uid=<?php echo $w['id'];?>" id="<?php echo $w['id'];?>" class="delbutton" title="Delete" onclick="return confirm('Are you sure want to delete this article!');">
<span class="glyphicon glyphicon-trash"></span>
</a> </td>
</tr>
<?php $sn++; } ?>


<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
T.Q=<?php

echo $tquantity;
?>
</td>
<td>Add Price:<?php echo $price;?></td>
<td></td>
<td></td>
<td>SGST+CGST:<?php
$sumsg=$ttaxSum+$tcgst;
echo $ttaxSum+$tcgst;?></td>
<td>IGST:
<?php echo $tigst;?>

</td>
<td>

<input type="text" class="form-control" name="totalprice1" value="<?php echo $totalPrice;//echo number_format($totalPrice,4); ?>" autocomplete="off" id="totalprice1" readonly>
</td>
<td>
<input type="submit" name="submit1" value="Payment" id="submit1" class="btn" style="background:rgb(74, 179, 198); color:white;">

</td>
</tr>
</tbody>
</form>
</table></div>
<?php } ?>
<!--End third table-->

</div>
</div>
</div>
</div>
</div>
</div>

<script>
$(document).ready(function(){
$(".select2").select2();

$( "#quantity" ).keyup(function() {
var quantity = $('#quantity').val();

if(isNaN(quantity)==true)
{
alert('Invalid Quantity !');
$('#quantity').val('');
}

});

$( "#price" ).keyup(function() {
var price = $('#price').val();

if(isNaN(price)==true)
{
alert('Invalid Selling Price !');
$('#price').val('');
}
else if(parseInt(price)<0)
{
alert('Invalid Selling Price !');
$('#price').val('');
}

});

$( "#discount" ).keyup(function() {
var discount = $('#discount').val();

if(isNaN(discount)==true)
{
alert('Invalid Discount !');
$('#discount').val('');
}

});

$( "#tax" ).keyup(function() {
var tax = $('#tax').val();

if(isNaN(tax)==true)
{
alert('Invalid Tax !');
$('#tax').val('');
}
else if(parseInt(tax)<0)
{
alert('Invalid Tax !');
$('#tax').val('');
}

});


//$(".select2").select2();
$('#products').on('change',function(){
//alert('hi');
var products = $('#products').val();
$.ajax({
type:'POST',
url:'remAjax.php',
data:'products='+products,
success:function(r){
$('#rem_quantity').html(r);
//alert(p);
}
});

$('#quantity').attr('disabled', false);
/*
$.ajax({
type:'POST',
url:'mrpAjax.php',
data:'products='+products,
success:function(q){
$('#mrpprice').val(q);
mrpprice = q;
}
});*/
$.ajax({
type:'POST',
url:'mrpAjax.php',
data:'products='+products,
success:function(q){
var res = q.split(",");
$('#mrpprice').val(res[0]);
$('#price1').val(res[1]);
//$('#hsn_code').val(res[2]);
$('#price').val(res[2]);
$('#discount').val(res[3]);
$('#tax').val(res[4]);
$('#igst').val(res[5]);
}
});
/*
$.ajax({
type:'POST',
url:'priceAjax.php',
data:'products='+products,
success:function(p){
$('#price1').val(p);
price1 = p;
}
});



$.ajax({
type:'POST',
url:'hsnAjax.php',
data:'products='+products,
success:function(q){
$('#hsn_code').val(r);
hsn_code = r;
}
});


$.ajax({
type:'POST',
url:'sellpriceAjax.php',
data:'products='+products,
success:function(q){
$('#price').val(q);
price = p;
}
});


$.ajax({
type:'POST',
url:'discountAjax.php',
data:'products='+products,
success:function(q){
$('#discount').val(q);
price = p;
}
});

$.ajax({
type:'POST',
url:'taxAjax.php',
data:'products='+products,
success:function(q){
$('#tax').val(q);
price = p;
}
});

$.ajax({
type:'POST',
url:'igstAjax.php',
data:'products='+products,
success:function(q){
$('#igst').val(q);
price = p;
}
});
*/
<!--- start quantity----->
$( "#quantity" ).keyup(function() {
var quantity = $('#quantity').val();
var price = $('#price').val();
var rem_quantity = $('#rem_quantity').text();
if(parseInt(quantity)>parseInt(rem_quantity) || parseInt(quantity)<=0 ){
alert('Insufficient quantity !');
$('#quantity').val('');
//$('#tprice').text('');
//return false;
//window.location.href = "http://localhost/furniture/billing.php";
}
else{
var discount = $('#discount').val();
var total = quantity*price;
var afterDiscount = (total * discount)/100;
var faterDisPrice = total-afterDiscount;
var discounttax = $('#tax').val();
var igst = $('#igst').val();
var afterDiscounttax = (faterDisPrice * discounttax)/100;
var afterDiscountigst = (faterDisPrice * igst)/100;
var faterDistaxPrice = faterDisPrice+afterDiscounttax+afterDiscountigst;

$('#tprice').val(faterDistaxPrice);

}
});
<!----end quantity---->



<!--- start selling price----->
$( "#price" ).keyup(function() {
var quantity = $('#quantity').val();
var price = $('#price').val();

var discount = $('#discount').val();
var total = quantity*price;
var afterDiscount = (total * discount)/100;
var faterDisPrice = total-afterDiscount;
var discounttax = $('#tax').val();
var igst = $('#igst').val();
var afterDiscounttax = (faterDisPrice * discounttax)/100;
var afterDiscountigst = (faterDisPrice * igst)/100;
var faterDistaxPrice = faterDisPrice+afterDiscounttax+afterDiscountigst;
$('#tprice').val(faterDistaxPrice);

});
<!----end quantity---->
<!--- start discount price----->
$( "#discount" ).keyup(function() {
var quantity = $('#quantity').val();
var price = $('#price').val();

var discount = $('#discount').val();
var total = quantity*price;
var afterDiscount = (total * discount)/100;
var faterDisPrice = total-afterDiscount;
var discounttax = $('#tax').val();
var igst = $('#igst').val();
var afterDiscounttax = (faterDisPrice * discounttax)/100;
var afterDiscountigst = (faterDisPrice * igst)/100;
var faterDistaxPrice = faterDisPrice+afterDiscounttax+afterDiscountigst;
$('#tprice').val(faterDistaxPrice);

});
<!----end discount---->
<!--- start CGST+SGST price----->
$( "#tax" ).keyup(function() {
var quantity = $('#quantity').val();
var price = $('#price').val();

var discount = $('#discount').val();
var total = quantity*price;
var afterDiscount = (total * discount)/100;
var faterDisPrice = total-afterDiscount;
var discounttax = $('#tax').val();
var igst = $('#igst').val();
var afterDiscounttax = (faterDisPrice * discounttax)/100;
var afterDiscountigst = (faterDisPrice * igst)/100;
var faterDistaxPrice = faterDisPrice+afterDiscounttax+afterDiscountigst;
$('#tprice').val(faterDistaxPrice);

});
<!----end CGST+SGST---->
<!--- start IGST price----->
$( "#igst" ).keyup(function() {
var quantity = $('#quantity').val();
var price = $('#price').val();

var discount = $('#discount').val();
var total = quantity*price;
var afterDiscount = (total * discount)/100;
var faterDisPrice = total-afterDiscount;
var discounttax = $('#tax').val();
var igst = $('#igst').val();
var afterDiscounttax = (faterDisPrice * discounttax)/100;
var afterDiscountigst = (faterDisPrice * igst)/100;
var faterDistaxPrice = faterDisPrice+afterDiscounttax+afterDiscountigst;
$('#tprice').val(faterDistaxPrice);

});
<!----end IGST---->






/*
<!----start discount---->
$( "#discount" ).keyup(function() {
var quantity = $('#quantity').val();
var discount = $('#discount').val();
var price = $('#price').val();

if(parseInt(discount)<0)
{
alert('Invalid Discount !');
$('#discount').val('');
}
if(quantity!='' && quantity>0){
if(discount!='' && discounttax=='')
{
var quantity = $('#quantity').val();
var total = quantity*price;
var discount = $(this).val();
var discounttax = $('#tax').val();
var afterDiscount = (total * discount)/100;
var faterDisPrice = total-afterDiscount;
$('#tprice').val(faterDisPrice);
}

if(discount=='' && discounttax!='')
{
var quantity = $('#quantity').val();
var discount = $(this).val();
var total = quantity*price;
var afterDiscount = (total * discount)/100;
var faterDisPrice = total-afterDiscount;
var discounttax = $('#tax').val();
//var tprice2 = $('#tprice').text();
var afterDiscounttax = (faterDisPrice * discounttax)/100;
var faterDistaxPrice = faterDisPrice+afterDiscounttax;
$('#tprice').val(faterDistaxPrice);
}
if(discount!='' && discounttax!='')
{
var quantity = $('#quantity').val();
var discount = $(this).val();
var total = quantity*price;
var afterDiscount = (total * discount)/100;
var faterDisPrice = total-afterDiscount;
var discounttax = $('#tax').val();
//var tprice2 = $('#tprice').text();
var afterDiscounttax = (faterDisPrice * discounttax)/100;
var faterDistaxPrice = faterDisPrice+afterDiscounttax;
$('#tprice').val(faterDistaxPrice);
}
if(discount=='' && discounttax=='')
{
var quantity = $('#quantity').val();
var total = parseFloat(Math.round((quantity*price) * 100) / 100).toFixed(2);

$('#tprice').val(total);
}
}
else
{
var total = 0*price;
$('#tprice').val(price);
}
});
<!----end discount---->
*/

/*
<!----start tax---->
$( "#tax" ).keyup(function() {
var quantity = $('#quantity').val();
var price = $('#price').val();
var discount = $('#discount').val();
var tax = $('#tax').val();

var total = quantity*price;

var afterDiscount = (total * discount)/100;

var faterDisPrice = total-afterDiscount;
var discounttax = $(this).val();
//var tprice2 = $('#tprice').text();

var afterDiscounttax = (faterDisPrice * discounttax)/100;

var faterDistaxPrice = faterDisPrice+afterDiscounttax;
$('#tprice').val(faterDistaxPrice);
});
<!----end tax---->
*/








/*
<!---insert billing insert--->
$('#add').on('click',function(){

var customerName1 = $('#cus_name').val();

var cus_contact1 = $('#cus_contact').val();

//var categories1 = $('#categories').val();
var products1 = $('#products').val();

var quantity1 = $('#quantity').val();

var price1 = $('#price').val();

var discount1 = $('#discount').val();
var tax1= $('#tax').val();
var tprice1 = $('#tprice').text();

if(quantity1!="" && price1!=''){
$.ajax({
type:"POST",
url:"insertbilling.php",
data: {
"cus_name": customerName1,
"cus_num": cus_contact1,
//"categories": categories1,
"products": products1,
"quantity": quantity1,
"price": price1,
"discount": discount1,
"tax": tax1,
"tprice": tprice1

},
});
}
});
<!---end billing insert--->
*/


});

});

</script>
<script>
$(document).ready(function(){
<!----start total discount---->
$( "#totaldiscount" ).keyup(function() {
var totaldiscount = $('#totaldiscount').val();
var totaltax = $('#totaltax').val();
var totalprice = $('#totalprice').val();


if(isNaN(totaldiscount)==true)
{
alert('Invalid Discount !');
$('#totaldiscount').val('');
}
else if(parseInt(totaldiscount)<0)
{
alert('Invalid Discount !');
$('#totaldiscount').val('');
}

var totaldiscount = $('#totaldiscount').val();
var afterDiscount = (totalprice * totaldiscount)/100;
var faterDisPrice = totalprice-afterDiscount;

var afterDiscounttax = (totalprice * totaltax)/100;


var faterDistaxPrice = faterDisPrice+afterDiscounttax;



$('#totalprice1').val(faterDistaxPrice);

});

<!----end total discount---->
<!----start total tax---->
$( "#totaltax" ).keyup(function() {
var totaldiscount = $('#totaldiscount').val();
var totaltax = $('#totaltax').val();
var totalprice = $('#totalprice').val();

if(isNaN(totaltax)==true)
{
alert('Invalid Tax !');
$('#totaltax').val('');
}
else if(parseInt(totaltax)<0)
{
alert('Invalid Tax !');
$('#totaltax').val('');
}
var totaltax = $('#totaltax').val();
var afterDiscount = (totalprice * totaldiscount)/100;
var faterDisPrice = totalprice-afterDiscount;

var afterDiscounttax = (faterDisPrice * totaltax)/100;
var faterDistaxPrice = faterDisPrice+afterDiscounttax;
$('#totalprice1').val(faterDistaxPrice);
});
<!----end total tax---->
});
</script>

<script>
$(document).ready(function(){
$( ".productName" ).select2({
ajax: {
url: "productsList.php",
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term // search term
};
},
processResults: function (data) {
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return {
results: data
};
},
cache: true
},
minimumInputLength: 1
});
});

</script>
// Ajax file //
<?php
session_start();
error_reporting();
include_once('dbconnect/dbconnection.php'); 
if(isset($_POST['products']) && !empty($_POST['products'])){ 
 $products=$_POST['products']; 
 $query=mysql_query("SELECT * FROM products WHERE id = '$products'"); 
 $row=mysql_fetch_assoc($query);
 $tax=$row['tax']+$row['ctax'];
 
 $details=$row['mrpprice'].','.$row['rate'].','.$row['sellprice'].','.$row['discount'].','.$tax.','.$row['itax'];
 //echo round($row['mrpprice'],2);
 echo $details;
 }
?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here