<?PHP
ob_start();
session_start();
include 'connect.php';
if(isset($_SESSION['adminemail']))
{
$user=$_SESSION['adminemail'];

$gtp=mysqli_query($conn,"select * from admin where username='$user'");
$gtp1=mysqli_fetch_assoc($gtp);

include 'top.php';
?>


<div id="page-wrapper" >
          <div id="page-inner">
<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">Home</a>
							</li>
							<li class="active">Sales</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

						<div class="page-header">
                        
<?php

$aca=mysqli_query($conn,"select * from financial where user='$user' order by ID desc");
$aca1=mysqli_fetch_assoc($aca);

$financial=$aca1['financial'];

?>
                        
                        <table style="width:100%;">
                        
                        <tr><td style="width:50%;">
                        
							<h1>
								Sales
							</h1>
                            
                            </td>
                            
                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">
                            
                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>
                            
                            </td></tr></table>
                            
						</div><!-- /.page-header -->
<br />

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->

                               
<script src="assets/js/jquery.js"></script>
 
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
  <script>
    $(function() {
      // Initialize the datepicker
      $("#datepicker").datepicker({
        format: "mm/dd/yyyy",
        autoclose: true,
        todayHighlight: true
      });

      // Adjust the positioning of the datepicker dropdown
      $("#datepicker").on("show", function(e) {
        var inputOffset = $(this).offset();
        var inputHeight = $(this).outerHeight();
        var datepickerDropdown = $(".datepicker-dropdown");

        datepickerDropdown.css({
          top: inputOffset.top + inputHeight + 10,
          left: inputOffset.left
        });
      });
    });
  </script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.min.css">
 <style>
    /* Custom CSS for Chosen select */
    .chosen-container {
      width: 25ch;
    }

    .chosen-container-single .chosen-single {
      border-radius: 4px;
      border: 1px solid #f0f0f0; /* Change the border color here */
      height:34px;
	  margin-bottom:10px;
      background-color: #fff;
      background-image: none;
      box-shadow: 0 0 0 1px #c0c0c0;
    }

    .chosen-container-single .chosen-single span {
      padding: 5px;
      text-transform: uppercase;
    }

    .chosen-container-single .chosen-search input[type="text"] {
      border-radius: 4px;
      border: 1px solid #c0c0c0;
      height: 34px;
    }

    .chosen-container-active .chosen-single {
      border-color: #7f7f7f;
      box-shadow: 0 0 0 1px #7f7f7f;
    }

    .chosen-container-active .chosen-single:hover {
      border-color: #7f7f7f;
      box-shadow: 0 0 0 1px #7f7f7f;
    }

    .chosen-container-active .chosen-search input[type="text"] {
      border-color: #7f7f7f;
    }
  </style>

<script>
$(function() {
  // Initialize the Chosen select element
  $(".chosen-select").chosen({
    width: '100%',
    disable_search_threshold: 10
  });
});
</script>
 <!-- Include Chosen library files -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.jquery.min.js"></script>

<script>
  $(document).ready(function() {
    // Initialize the Chosen select element
    $(".customer").chosen();
  });
</script> 
<script>
  $(document).ready(function() {
    // Initialize the Chosen select elements
    $(".executive").chosen();
    $(".customer").chosen();

    // Handle change event of executive dropdown
    $(".executive").change(function() {
      var executive = $(this).val();
      var dataString = 'executive=' + executive;

      $.ajax({
        type: "GET",
        url: "getcust.php",
        data: dataString,
        cache: false,
        success: function(resp) {
          $('.customer').html($('#customer', resp).html());
          $(".customer").trigger("chosen:updated"); // Refresh the Chosen select
        }
      });
    });
  });
</script>

<script>
	
jQuery(function($){
		   
	// simple jQuery validation script
	$('#work').submit(function(){
		
		var valid = true;
		var errormsg = 'This field is required!';
		var errorcn = 'error';
		
		$('.' + errorcn, this).remove();			
		
		$('#required', this).each(function(){
			var parent = $(this).parent();
			if( $(this).val() == '' ){
				var msg = $(this).attr('title');
				msg = (msg != '') ? msg : errormsg;
				$('<span style="font-size:13px;color:#FF0000; padding-left:3px;" class="'+ errorcn +'">'+ msg +'</span>')
					.appendTo(parent)
					.fadeIn('fast')
					.click(function(){ $(this).remove(); });
				valid = false;
			};
		});
		
		
	  //All Fields Empty
	  
	  var len=$('.item-row').length;

	  var r=0;

	  $('.row').each(function(i){

	  

	  var row = $(this).parents('.worker_row');

	  var category = row.find('.category').val();
	  
	  var product = row.find('.product').val();

	  var qty = row.find('.qty').val()*1;

	  var rate = row.find('.rate').val()*1;

	  

	  //alert(rn);

	  
	  if(category=='')

	  {

	  alert('Select Category');

	  

	  valid=false;

	  

	  }

	  else if(product=='')

	  {

	  alert('Select Product');

	  

	  valid=false;

	  

	  }

	  else if(qty=='')

	  {

	  alert('Enter qty');

	  

	  valid=false;

	  

	  }

	  else if(rate=='')

	  {

	  alert('Enter rate');

	  

	  valid=false;	  

	  }

		

	  });
		
		
		return valid;
		
		$('button:submit').prop('disabled', true);
		
	});
	
});	

</script>

<script type="text/javascript">

	//global var
	var maxRowNum = 1;
	var selectedId = 0;

function update_total() {

  var total = 0;

  $('.price').each(function(i){

    price = $(this).html().replace("Rs.","");

    if (!isNaN(price)) total += Number(price);

  });



  total = total.toFixed(2);

  //alert(total);

  $('.samount').html("Rs."+total);
  

}

function update_price() {

  var row = $(this).parents('.worker_row');

  

  //var price = row.find('.rate').val().replace("Rs.","") * row.find('.qty').val();

  

  var aam = row.find('.amt').html().replace("Rs.","")*1;

  

  var disc = row.find('.discount').val().replace("Rs.","")*1;

  

  var price=aam-disc;

  

  //alert(price);

  

  var cgst=row.find('.cgst').val()*1;

  var sgst=row.find('.sgst').val()*1;

  var igst=row.find('.igst').val()*1;

   

  var p1=price*cgst/100;

  var p2=price*sgst/100;

  var p3=price*igst/100;

  

  //alert(p1);

  

  var totalpr=price+p1+p2+p3;

  

  totalpr=totalpr.toFixed(2);

  

  isNaN(totalpr) ? row.find('.price').html("N/A") : row.find('.price').html(totalpr);

  update_total();

}



function update_sprice() {

  var row = $(this).parents('.worker_row');

  

  var price = row.find('.rate').val().replace("Rs.","") * row.find('.qty').val();

  price=price.toFixed(2);

  row.find('.amt').html(price);

  //discount update
  
  var tdisc = row.find('.disc').val().replace("Rs.","") * row.find('.qty').val();

  tdisc=tdisc.toFixed(2);

  row.find('.discount').val(tdisc);
  

  update_price();

  

}




function bind() {

  $(".rate").blur(update_sprice);
  
  $(".disc").blur(update_sprice);

  $(".qty").blur(update_sprice);

  $(".discount").blur(update_price);

  $(".cgst").blur(update_price);

  $(".sgst").blur(update_price);

  $(".igst").blur(update_price);
  
}

$(document).ready(function() {


bind();


$("#addrow").click(function(){
maxRowNum++;
//alert($max);
    $(".worker_row:last").after("<tr align='center' class='worker_row'><td id='page' class='item-name' style='padding-top:10px;'><input type='hidden' name='row["+ maxRowNum +"]' value='"+ maxRowNum +"' class='row'><div class='delete-wpr'>&nbsp;<a class='delete' href='javascript:;' title='Remove row'>X </a></div></td><td style='padding-top:10px;'><select style='width: 20ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;' name='category["+ maxRowNum +"]' class='category' style='width:170px;'><option value=''>Select Category</option><?php $cate=mysqli_query($conn,"select * from product_category order by category asc"); while($cate1=mysqli_fetch_assoc($cate)){ echo"<option value='".$cate1['ID']."'>".$cate1['category']."</option>"; } ?></select></td><td style='padding-top:10px;'><select style='width: 20ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;'  name='product["+ maxRowNum +"]' class='product' style='width:170px;'><option value='' selected='selected'>Select Product</option></select></td><td style='padding-top:10px;'><input style='width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;background-color: rgb(240, 240, 240);' type='text' name='unit["+ maxRowNum +"]' class='unit' style='width:45px;' placeholder='Unit' autocomplete='off' readonly='true' /></td><td style='padding-top:10px;'><input style='width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;' type='text' name='qty["+ maxRowNum +"]' class='qty' style='width:45px;' placeholder='Qty' autocomplete='off' /></td><td style='padding-top:10px;'><input style='width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;' type='text' name='rate["+ maxRowNum +"]' class='rate' style='width:50px;' placeholder='Rate' autocomplete='off' /></td><td style='padding-top:10px;'><input style='width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;' type='text' name='disc["+ maxRowNum +"]' class='disc' style='width:50px;' placeholder='Disc' autocomplete='off' /></td><td style='padding-top:10px;'><span class='amt'></span></td><td style='padding-top:10px;'><input style='width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;' type='text' name='discount["+ maxRowNum +"]' class='discount' style='width:45px;' placeholder='Discount' autocomplete='off' /></td><td style='padding-top:10px;'><input style='width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;' type='text' name='cgst["+ maxRowNum +"]' style='width:45px;' class='cgst' placeholder='CGST' autocomplete='off' /></td><td style='padding-top:10px;'><input style='width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;' type='text' name='sgst["+ maxRowNum +"]' style='width:45px;' class='sgst' placeholder='SGST' autocomplete='off' /></td><td style='padding-top:10px;'><input style='width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;' type='text' name='igst["+ maxRowNum +"]' style='width:45px;' class='igst' placeholder='IGST' autocomplete='off' /></td><td style='padding-top:10px;'><span class='price'>0.00</span></td></tr>");
	
    if ($(".delete").length > 0) $(".delete").show();
	    bind();		
		  });  		  
bind();

});


$(".category").live('change',function(){

  var row = $(this).parents('.worker_row');

  var category=row.find('.category').val();		  

 var dataString = 'category='+ category;

 //alert(dataString);

    $.ajax

({

type: "GET",

url: "getproduct.php",

data: dataString,

cache: false,

success: function( resp )

{

	//alert(resp);

	row.find('.product').html($('#material',resp).html());

}

});

});


$(".product").live('change',function(){

var row = $(this).parents('.worker_row');

 var product=row.find('.product').val();

 var dataString = 'product='+ product;

//alert(dataString);

   $.ajax

({

type: "GET",

url: "getrate.php",

data: dataString,

cache: false,

success: function(html)

{

//alert(html);

var rate=$(html).filter('#rate').text();

var unit=$(html).filter('#unit').text();

var disc=$(html).filter('#discount').text();

row.find('.rate').val(rate);
row.find('.unit').val(unit);
row.find('.disc').val(disc);

}

});

});



$(".executive").live('change',function() {

		  var executive=$(this).val();

		  var dataString = 'executive='+ executive;

		  //alert(dataString);

		  $.ajax

		  ({

		  type: "GET",

		  url: "getcust.php",

		  data: dataString,

		  cache: false,

		  success: function(resp)

		  {
			  
			  //alert(resp);
		  
		  $('.customer').html($('#customer',resp).html());

		  }

		  });

});


$(".delete").live('click',function(){
    $(this).parents('.worker_row').remove();
    update_total();
    if ($(".delete").length < 2) $(".delete").hide();
  });


$('.transport').live('change',function(){
	
	var vv=$(this).val();
	
		if($(this).val() == 'Own')
		{
	    	$(".own").slideDown('slow');
			$(".hire").slideUp('slow');
		}
		else if ($(this).val() == 'Hire')
		{
			$(".hire").slideDown('slow');
			$(".own").slideUp('slow');
		}

});


</script>


<?php
	
if(isset($_POST['submit']))
{
		$date=$_POST['date'];

		$customer=$_POST['customer'];

		$invoiceno=$_POST['invoiceno'];
		
		$invno=$_POST['invno'];

		$product=$_POST['product'];
		
		$code=$_POST['code'];

		$hsn=$_POST['hsn'];

		$rate=$_POST['rate'];

		$qty=$_POST['qty'];

		$discount=$_POST['discount'];
		
		$disc=$_POST['disc'];

		$cgst=$_POST['cgst'];

		$sgst=$_POST['sgst'];

		$igst=$_POST['igst'];

		$row=$_POST['row'];
		
		$factory=$_POST['factory'];
		
		$executive=$_POST['executive'];
		
		$pono=$_POST['pono'];
		
		$transport=$_POST['transport'];
		
		$vehicleno=$_POST['vehicleno'];
		
		$hvehicleno=$_POST['hvehicleno'];

		$date=date('Y-m-d',strtotime($date));
		
		
		if($transport=='Own')
		{
			$vehicleno=$vehicleno;
		}
		else
		{
			$vehicleno=$hvehicleno;
		}


		$csk=mysqli_query($conn,"select * from invoice where invoiceno='$invoiceno'");
		$csk1=mysqli_num_rows($csk);
		if($csk1>0)
		{
		$chk=mysqli_query($conn,"select max(invoiceno) as invoiceno from invoice");
		$chk1=mysqli_fetch_assoc($chk);
		$invoiceno=$chk1['invoiceno']+1;
		}
		else
		{
		$invoiceno=$invoiceno;
		}
		
		
		
		$chek=mysqli_query($conn,"select * from invoice where invno='$invno' and financial='$financial'");
		$chek1=mysqli_num_rows($chek);
		if($chek1>0)
		{
		$chck=mysqli_query($conn,"select max(invno) as invno from invoice where financial='$financial'");
		$chck1=mysqli_fetch_assoc($chck);
		$invno=$chck1['invno']+1;
		}
		else
		{
		$invno=$invno;
		}


if($customer)
{

foreach($row as $rw)
{

				$prod=$product[$rw];

				$cos=$rate[$rw];

				$qt=$qty[$rw];

				$dis=$discount[$rw];
				
				$ds=$disc[$rw];

				$cgs=$cgst[$rw];

				$sgs=$sgst[$rw];

				$igs=$igst[$rw];

				

				$totalrate=$cos*$qt;

				

				$totalrate=$totalrate-$dis;

				

				$cgsam=$totalrate*$cgs/100;

				$sgsam=$totalrate*$sgs/100;

				$igsam=$totalrate*$igs/100;

				

				$finalrate=$totalrate+$cgsam+$sgsam+$igsam;


$insert="INSERT into invoice(date,customer,product,rate,qty,discount,total,invoiceno,cgst,sgst,igst,cgst_amt,sgst_amt,igst_amt,invno,financial,factory,executive,pono,vehicleno,individualdiscount)

values('$date','$customer','$prod','$cos','$qt','$dis','$finalrate','$invoiceno','$cgs','$sgs','$igs','$cgsam','$sgsam','$igsam','$invno','$financial','$factory','$executive','$pono','$vehicleno','$ds')";

mysqli_query($conn,$insert) or die(mysqli_error($conn));

}

}


if($insert){
	
header("location:viewinvoice.php?id=".$invoiceno."&s=1" . urlencode($Message));

}

else{

echo "<script type='text/javascript'>alert('Field Missing.');</script><META HTTP-EQUIV = 'Refresh' Content = '1; URL =invoice.php'>";

}

}

else
{
if (isset($_GET['s'])) 
	{
	 $status=$_GET['s'];
		 if($status=='1')
		 {
		 echo '<div class="alert alert-success">
				<a class="close" data-dismiss="alert">x</a>
					<strong>Purchase Created Successfully !</strong>
			  </div>';
		}
	}
	
		$date=date('Y-m-d');
	
		$d=date("m",strtotime($date));
		if($d>03)
		{
		$y=date("Y",strtotime($date));
		$y1=$y+1;		
		
		$dd=date($y);
		$dd1=date($y1);	
		}
		elseif($d<=03)
		{
		$y1=date("Y",strtotime($date));
		$y=$y1-1;	
		
		$dd=date($y);
		$dd1=date($y1);	
		}
		
		$financial=$dd.'-'.$dd1;
	
$mx=mysqli_query($conn,"select MAX(invoiceno) as invoiceno from invoice") or die(mysqli_error($conn));
$mx1=mysqli_fetch_assoc($mx);
$neworder=$mx1['invoiceno']+1;

$nmx=mysqli_query($conn,"select MAX(invno) as invno from invoice where financial='$financial'") or die(mysqli_error($conn));
$nmx1=mysqli_fetch_assoc($nmx);
$neword=$nmx1['invno']+1;

$sel=mysqli_query($conn,"select * from admin where username='$user'");
$nmrw=mysqli_num_rows($sel);
$sel1=mysqli_fetch_assoc($sel);

//echo"$neword";

echo'<form action="invoice.php" method="post" id="work">

<center><table width="85%" id="page" style="line-height:35px;">

<tr><td style="width:13%;">Invoice No <span class="red"></span></td><td>

<input  type="hidden" name="invoiceno" id="required" title="*" value="'.$neworder.'" readonly="true" />

<input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="invno" id="required" title="*" value="'.$neword.'" readonly="true" />

</td><td style="width:75px;"></td><td style="width:13%;">Date <span class="red"></span></td><td> <input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="date" id="datepicker" title="*" class="datepicker" autocomplete="off" /required></td></tr>

<tr><td colspan="3">';

echo'</td><td style="width:55px;"></td><td></td></tr>

<tr>';

if($nmrw>0)
{
echo'<td style="width:13%;">Executive</td><td> <select  style="width: 30ch; margin-bottom:10px" name="executive" class="executive" style="width:220px;"><option value="">Select Executive</option>';

$exct=mysqli_query($conn,"select * from employee order by name asc");
while($exct1=mysqli_fetch_assoc($exct))
{
	echo"<option value='".$exct1['ID']."'>".$exct1['name']."</option>";
}

echo'</select></td>';
}
else
{

$empd=mysqli_query($conn,"select * from employee where username='$user'");
$empd1=mysqli_fetch_assoc($empd);

$usr=$empd1['ID'];

echo"<td></td><td><input type='hidden' name='executive' class='executive' value='".$usr."' /></td>";

}

echo'<td style="width:55px;"></td><td>Factory</td><td> <select class="form-control" style="width: 30ch; margin-bottom:10px" name="factory" style="width:220px;"><option value="">Select Factory</option>';

$fac=mysqli_query($conn,"select * from factory order by ID asc");
while($fac1=mysqli_fetch_assoc($fac))
{
	echo"<option value='".$fac1['ID']."'>".$fac1['factory']."</option>";
}

echo'</select></td></tr>

<tr><td style="width:13%;">Customer <span class="red"></span></td><td> <select  style="width: 30ch; margin-bottom:10px" name="customer" class="customer " id="required" title="*" style="width:220px;"><option value="" selected="selected">Select Customer</option>';

if($nmrw==0)
{

$empd=mysqli_query($conn,"select * from employee where username='$user'");
$empd1=mysqli_fetch_assoc($empd);

$usr=$empd1['ID'];

$sql=mysqli_query($conn,"SELECT * from customer where executive='$usr' order by name asc") or die(mysqli_error($conn));
while($result=mysqli_fetch_assoc($sql))
{
echo'<option value="'.$result['ID'].'">'.$result['name'].' ('.$result['mobile1'].')</option>';
}
}

echo'</select></td>

<td style="width:75px;"></td><td>Po.No. &amp; Date</td><td> <input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="pono" /></td></tr>

<tr><td style="width:13%;">Transport</td><td> <select  style="width: 30ch; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" name="transport" class="transport" style="width:220px;">

<option value="Own">OWN</option>
<option value="Hire">HIRE</option>

</select></td>

<td style="width:75px;"></td><td colspan="2"><div class="own">

<table style="width:100%;">

<tr><td style="width:26%;">Vehicle No.</td><td style="padding:0 3px;"></td><td><select  style="width: 30ch; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" name="vehicleno" style="width:220px;"><option value="">-- Select --</option>';

$ttr=mysqli_query($conn,"select * from transport order by ID asc");
while($ttr1=mysqli_fetch_assoc($ttr))
{
	echo"<option value='".$ttr1['vehicleno']."'>".$ttr1['vehicleno']."</option>";
}

echo'</td></tr>

</table></div>

<div class="hire" style="display:none;">

<table style="width:100%;">

<tr><td style="width:26%;">Vehicle No.</td><td style="padding:0 3px;"></td><td><input style="width: 30ch; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" type="text" name="hvehicleno" /></td></tr>

</table>

</div></td></tr>

</table><br />

<br /><table width="95%" style="line-height:25px; border:1px solid #dddddd; font-size:12px;">

			<tr height="25" bgcolor="#eaf5f8" border="1">
			
			<th width="3%"></th>
	
			<th style="width:10%; text-align:center;">Category</th>
		
			<th style="width:15%; text-align:center;">Product</th>
			
			<th style="width:7%; text-align:center;">Unit</th>
			
			<th style="width:7%; text-align:center;">Qty</th>
		
			<th style="width:7%; text-align:center;">Rate</th>
			
			<th style="width:7%; text-align:center;">Disc/Q</th>
		
			<th style="width:7%; text-align:center;">Amt</th>
		
			<th style="width:7%; text-align:center;">T.Disc.</th>
		
			<th style="width:7%; text-align:center;">CGST (%)</th>
		
			<th style="width:7%; text-align:center;">SGST (%)</th>
		
			<th style="width:7%; text-align:center;">IGST (%)</th>
		
			<th style="width:7%; text-align:center;">Amount</th>
			
			</tr>
			
			  <tr class="worker_row" align="center" style="margin-top:10px;">

		        <td id="page" style="padding-top:11px;"><a class="delete" href="javascript:;" title="Remove row">X</a></td>

				<td id="page" style="padding-top:11px;"><input type="hidden" name="row[1]" class="row" value="1" />
				
				<select style="width: 20ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;"  name="category[1]" class="category" style="width:170px;"><option value="">Select Category</option>';
				
				$cate=mysqli_query($conn,"select * from product_category order by category asc");
				while($cate1=mysqli_fetch_assoc($cate))
				{
					echo"<option value='".$cate1['ID']."'>".$cate1['category']."</option>";
				}
				
				echo'</select></td>
		
				<td id="page" style="padding-top:11px;"><select style="width: 20ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;"  name="product[1]" class="product" style="width:170px;"><option value="" selected="selected">Select Product</option></select></td>
				
				<td id="page" style="padding-top:11px;"><input style="width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;background-color: rgb(240, 240, 240);"  type="text" name="unit[1]" class="unit" style="width:45px;" placeholder="Unit" autocomplete="off" readonly="true" /></td>
				
				<td id="page" style="padding-top:11px;"><input style="width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;"  type="text" name="qty[1]" class="qty" style="width:45px;" placeholder="Qty" autocomplete="off" /></td>
		
				<td id="page" style="padding-top:11px;"><input style="width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;"  type="text" name="rate[1]" class="rate" style="width:50px;" placeholder="Rate" autocomplete="off" /></td>
				
				<td id="page" style="padding-top:11px;"><input style="width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;"  type="text" name="disc[1]" class="disc" style="width:50px;" placeholder="Disc" autocomplete="off" /></td>
				
				<td id="page" style="padding-top:11px;"><span class="amt"></span></td>
		
				<td id="page" style="padding-top:11px;"><input style="width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;"  type="text" name="discount[1]" class="discount" style="width:45px;" placeholder="Discount" autocomplete="off" /></td>
		
				<td id="page" style="padding-top:11px;"><input style="width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;"  type="text" name="cgst[1]" style="width:45px;" class="cgst" placeholder="CGST" autocomplete="off" /></td>
		
				<td id="page" style="padding-top:11px;"><input style="width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;"  type="text" name="sgst[1]" style="width:45px;" class="sgst" placeholder="SGST" autocomplete="off" /></td>
		
				<td id="page" style="padding-top:11px;"><input style="width: 9ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;"  type="text" name="igst[1]" style="width:45px;" class="igst" placeholder="IGST" autocomplete="off" /></td>
		
				<td id="page" style="padding-bottom:1px;"><span class="price">0.00</span></td>
			  
			  </tr>

			  <tr id="hiderow">
			  
		      <td id="page" colspan="11"><a id="addrow" href="javascript:;" title="Add a row">Add Row</a></td>
			  
		      </tr>
			 
			  </table>
			  
			  <br /><br />
			  
			  <table style="width:85%; margin:auto;">
			  
			  <tr><td style="width:80%;">
			  
			  
			  </td>
			  
			  <td style="width:20%;">
			  
			  <table style="line-height:35px;">
			  
			  <tr><td>Total</td><td style="padding:0 7px 0 7px;">:</td><td><div class="samount"></div></td></tr>
			  
			  <tr><td colspan="3" style="text-align:center;"><button id="save" type="submit" class="btn btn btn-primary" name="submit" value="Add">Save</button></td></tr>
			  
			  </table>
			  
			  </td></tr></table>
			  
</center>

<br />

</form>';

}
	
?>                             
                               
							<br>
<br>
	

								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					

</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->
			</div><!-- /.main-content -->
			</div><!-- /.main-content -->


<?php
include 'bottom.php';
}
else
{

 header("location:login.php");
}
ob_flush();
?>