<?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 Order</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 Order
							</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">
  <style>
    .datepicker-wrapper {
      position: relative;
    }
  </style>
  <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">
<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>
  function searchCustomer(customerId) {
    // Perform an AJAX request to retrieve customer details
    $.ajax({
      type: "GET",
      url: "getcustomer.php",
      data: { customer: customerId },
      cache: false,
      success: function (html) {
        // Parse the returned HTML and populate the customer details
        var doorno = $(html).filter('#doorno').text();
        var street = $(html).filter('#street').text();
        var village = $(html).filter('#village').text();
        var mobile1 = $(html).filter('#mobile1').text();
        var mobile2 = $(html).filter('#mobile2').text();

        $('.doorno').val(doorno);
        $('.street').val(street);
        $('.village').val(village);
        $('.mobile1').val(mobile1);
        $('.mobile2').val(mobile2);
      }
    });
  }
</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();

  

  //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 bind() {

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

  $(".qty").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: 25ch; 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: 25ch; 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: 10ch; 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:50px;' placeholder='Unit' autocomplete='off' readonly='true' /></td><td style='padding-top:10px;'><input style='width: 10ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;' type='text' name='qty["+ maxRowNum +"]' class='qty' style='width:50px;' placeholder='Qty' autocomplete='off' /></td><td style='padding-top:10px;'><input style='width: 10ch; 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: 10ch; 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: 10ch; 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: 10ch; 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-bottom:5px;'><span class='price'>0.00</span></td></tr>");
	
    if ($(".delete").length > 0) $(".delete").show();
	    bind();
		
		//alert("ds");
		
		  });
		  
		  
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 unit=$(html).filter('#unit').text();

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

}

});

});



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

 var customer=$('.customer').val();

 var dataString = 'customer='+ customer;

//alert(dataString);

   $.ajax

({

type: "GET",

url: "getcustomer.php",

data: dataString,

cache: false,

success: function(html)

{

//alert(html);	

var doorno=$(html).filter('#doorno').text();
var street=$(html).filter('#street').text();
var village=$(html).filter('#village').text();
var mobile1=$(html).filter('#mobile1').text();
var mobile2=$(html).filter('#mobile2').text();

$('.doorno').val(doorno);
$('.street').val(street);
$('.village').val(village);
$('.mobile1').val(mobile1);
$('.mobile2').val(mobile2);

}

});

});



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

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

		$customer=$_POST['customer'];

		$orderno=$_POST['orderno'];
		
		$ordno=$_POST['ordno'];

		$product=$_POST['product'];

		$rate=$_POST['rate'];

		$qty=$_POST['qty'];

		$cgst=$_POST['cgst'];

		$sgst=$_POST['sgst'];

		$igst=$_POST['igst'];

		$row=$_POST['row'];
		
		$ordno=$_POST['ordno'];
		
		$dbrowno=$_POST['dbrowno'];
		
		$factory=$_POST['factory'];
		
		$expecteddate=$_POST['expecteddate'];
		
		$confirmeddate=$_POST['confirmeddate'];

		$date=date('Y-m-d',strtotime($date));

if($customer)
{
	
			$array=array();
			
			foreach($row as $rnn)
			{				
			$dbrn=$dbrowno[$rnn];
				
			array_push($array,$dbrn);
			}
			
			
				$gv=mysqli_query($conn,"select * from sales_order where orderno='$orderno' order by ID asc");
				while($gv1=mysqli_fetch_assoc($gv))
				{
					
					if(in_array($gv1['ID'], $array)) {
									
					echo"Found";
						
					}
					
					else
					{
					
					$del=mysqli_query($conn,"delete from sales_order where ID='$gv1[ID]'");
						
					}
					
				}


foreach($row as $rw)
{
				$prod=$product[$rw];

				$cos=$rate[$rw];

				$qt=$qty[$rw];

				$dis=$discount[$rw];

				$cgs=$cgst[$rw];

				$sgs=$sgst[$rw];

				$igs=$igst[$rw];
				
				$dbrno=$dbrowno[$rw];

$totalrate=$cos*$qt;

				

				$totalrate=$totalrate;

				

				$cgsam=$totalrate*$cgs/100;

				$sgsam=$totalrate*$sgs/100;

				$igsam=$totalrate*$igs/100;

				

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

if($dbrno=='')
{

$insert="INSERT into sales_order(date,customer,product,rate,qty,total,orderno,cgst,sgst,igst,cgst_amt,sgst_amt,igst_amt,ordno,financial,factory,expecteddate,confirmeddate)
values('$date','$customer','$prod','$cos','$qt','$finalrate','$orderno','$cgs','$sgs','$igs','$cgsam','$sgsam','$igsam','$ordno','$financial','$factory','$expecteddate','$confirmeddate')";
mysqli_query($conn,$insert) or die(mysqli_error($conn));

}

else
{

$update=mysqli_query($conn,"update sales_order set date='$date',customer='$customer',product='$prod',rate='$cos',qty='$qt',total='$finalrate',orderno='$orderno',cgst='$cgs',sgst='$sgs',igst='$igs',cgst_amt='$cgsam',sgst_amt='$sgsam',igst_amt='$igsam',ordno='$ordno',financial='$financial',factory='$factory',expecteddate='$expecteddate',confirmeddate='$confirmeddate' where ID='$dbrno'");
	
}

}

}


if($insert || $update)
{
	
header("location:viewsalesorder.php?id=".$orderno."&s=2" . urlencode($Message));

}

else{

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

}

}

else
{
	
$id=$_GET['id'];

$chk=mysqli_query($conn,"SELECT *,sum(total) as total from sales_order where orderno='$id'") or die("Unable to get new inovice number.");
$chk1=mysqli_fetch_assoc($chk);

$cus=mysqli_query($conn,"select * from customer where ID='$chk1[customer]'");
$cus1=mysqli_fetch_assoc($cus);

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

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

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

<input type="hidden" name="orderno" id="required" title="*" value="'.$chk1['orderno'].'" readonly="true" />

<input type="text" name="ordno" id="required" title="*" value="'.$chk1['ordno'].'" readonly="true" style="width: 30ch; margin-bottom:10px;padding-left:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;background-color: rgb(240, 240, 240);" style="width: 30ch; margin-bottom:10px" />

</td><td style="width:75px;"></td><td>Date <span class="red"></span></td><td> <input style="width: 30ch; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" style="width: 30ch; margin-bottom:10px" type="text" name="date" id="datepicker" title="*" class="datepicker" value="'.date('d-m-Y',strtotime($chk1['date'])).'" autocomplete="off" /required></td></tr>

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

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

<tr>
  <td>Customer <span class="red"></span></td>
  <td>
  <select name="customer" class="customer" id="required" title="*" style="width: 30ch; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" onchange="searchCustomer(this.value)">
    <option value="">Select Customer</option>';
   
    $sup = mysqli_query($conn, "SELECT * FROM customer ORDER BY ID ASC");
    while ($sup1 = mysqli_fetch_assoc($sup)) {
      $selected = ($sup1['ID'] == $chk1['customer']) ? 'selected' : '';
      echo '<option value="' . $sup1['ID'] . '" ' . $selected . '>' . $sup1['name'] . '</option>';
    }
	  

echo'</select></td><td style="width:55px;"></td><td>Door No.</td><td> <input style="width: 30ch;padding-left:10px; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;background-color: rgb(240, 240, 240);" style="width: 30ch; margin-bottom:10px" type="text" readonly="true" class="doorno" value="'.$cus1['doorno'].'" /></td></tr>

<tr><td>Street</td><td> <input style="width: 30ch;padding-left:10px; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;background-color: rgb(240, 240, 240);" style="width: 30ch; margin-bottom:10px"padding-left:10px; type="text" readonly="true" class="street" value="'.$cus1['street'].'" /></td><td style="width:55px;"></td><td>Village</td><td> <input  style="width: 30ch;padding-left:10px; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;background-color: rgb(240, 240, 240);" style="width: 30ch; margin-bottom:10px" type="text" readonly="true" class="village" value="'.$cus1['village'].'" /></td></tr>

<tr><td>Mobile 1</td><td> <input style="width: 30ch;padding-left:10px; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;background-color: rgb(240, 240, 240);" style="width: 30ch; margin-bottom:10px" type="text" readonly="true" class="mobile1" value="'.$cus1['mobile1'].'" /></td><td style="width:55px;"></td><td>Mobile 2</td><td> <input style="width: 30ch; margin-bottom:10px;padding-left:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;background-color: rgb(240, 240, 240);" style="width: 30ch; margin-bottom:10px" type="text" readonly="true" class="mobile2" value="'.$cus1['mobile2'].'" /></td></tr>

<tr><td style="width:13%;">Executive</td><td> <select style="width: 30ch;  margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;background-color: " style="width: 30ch; margin-bottom:10px" name="executive" style="width:220px;"><option value="">Select Executive</option>';

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

echo'</select></td>

<td style="width:75px;"></td><td>Factory</td><td> <select style="width: 30ch; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" 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))
{
	$fc="<option value='".$fac1['ID']."'>".$fac1['factory']."</option>";
	$fc=str_replace("<option value='".$chk1['factory']."'","<option value='".$chk1['factory']."' selected",$fc);
	echo $fc;
}

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

<tr><td>Expected Date</td><td> <input style="width: 30ch;padding-left:10px; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" style="width: 30ch; margin-bottom:10px" type="text" name="expecteddate" value="'.$chk1['expecteddate'].'" autocomplete="off" /></td><td style="width:55px;"></td><td>Confirmed Date</td><td> <input style="width: 30ch; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" style="width: 30ch; margin-bottom:10px" type="text" name="confirmeddate" value="'.$chk1['confirmeddate'].'" autocomplete="off" /></td></tr>

</table><br />

<br />

<br><table width="90%" 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;">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>';
			
			
			$pur_details=mysqli_query($conn,"SELECT * from sales_order where orderno='$id' order by ID asc") or die("Unable to get purchase details.");
			$tmpid=0;			
			while($details1=mysqli_fetch_assoc($pur_details))			
			{
			
			$tmpid=$tmpid+1;
			
			$pcr=mysqli_query($conn,"select * from product where ID='$details1[product]'");
			$pcr1=mysqli_fetch_assoc($pcr);
			
			    echo'<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['.$tmpid.']" class="row" value="'.$tmpid.'" />
				
				<input type="hidden" name="dbrowno['.$tmpid.']" value="'.$details1['ID'].'" />
				
				<select style="width: 25ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;" name="category['.$tmpid.']" 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))
				{
					$pcate="<option value='".$cate1['ID']."'>".$cate1['category']."</option>";
					$pcate=str_replace("<option value='".$pcr1['category']."'","<option value='".$pcr1['category']."' selected",$pcate);
					echo $pcate;
				}
				
				echo'</select></td>
		
				<td id="page" style="padding-top:11px;"><select style="width: 25ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;" name="product['.$tmpid.']" style="width:170px;">
				<option value="" selected="selected">Select Product</option>';
				
				$prod=mysqli_query($conn,"select * from product order by category asc");
				while($prod1=mysqli_fetch_assoc($prod))
				{
					$ppro="<option value='".$prod1['ID']."'>".$prod1['product']."</option>";
					$ppro=str_replace("<option value='".$details1['product']."'","<option value='".$details1['product']."' selected",$ppro);
					echo $ppro;
				}
				
				echo'</select></td>
				
				<td id="page" style="padding-top:11px;"><input style="width: 10ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;background-color: rgb(240, 240, 240);" type="text" name="unit['.$tmpid.']" class="unit" style="width:45px;" placeholder="Unit" value="'.$pcr1['unit'].'" autocomplete="off" readonly="true" /></td>
				
				<td id="page" style="padding-top:11px;"><input style="width: 10ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;" type="text" name="qty['.$tmpid.']" class="qty" style="width:45px;" placeholder="Qty" value="'.$details1['qty'].'" autocomplete="off" /></td>
		
				<td id="page" style="padding-top:11px;"><input style="width: 10ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;" type="text" name="rate['.$tmpid.']" class="rate" style="width:50px;" placeholder="Rate" value="'.$details1['rate'].'" autocomplete="off" /></td>
				
				<td id="page" style="padding-top:11px;"><input style="width: 10ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;" type="text" name="cgst['.$tmpid.']" style="width:45px;" class="cgst" placeholder="CGST" value="'.$details1['cgst'].'" autocomplete="off" /></td>
		
				<td id="page" style="padding-top:11px;"><input style="width: 10ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;" type="text" name="sgst['.$tmpid.']" style="width:45px;" class="sgst" placeholder="SGST" value="'.$details1['sgst'].'" autocomplete="off" /></td>
		
				<td id="page" style="padding-top:11px;"><input style="width: 10ch; margin-bottom:10px;border-radius: 4px;border: 1px solid #c0c0c0;height:34px;" type="text" name="igst['.$tmpid.']" style="width:45px;" class="igst" placeholder="IGST" value="'.$details1['igst'].'" autocomplete="off" /></td>
		
				<td id="page" style="padding-bottom:5px;"><span class="price">'.$details1['total'].'</span></td>
			  
			    </tr>';
						
			}
		
			?>
		
				  <script>
		
				  maxRowNum ="<?PHP echo ($tmpid); ?>";
		
				  </script>
				
			  <tr id="hiderow">
			  
		      <td id="page" colspan="9"><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"><?php echo $chk1['total']; ?></div></td></tr>
			  
			  <tr><td colspan="3" style="text-align:center;"><button id="save" type="submit" class="btn btn-sm btn-primary" name="submit" value="Add">Save</button></td></tr>
			  
			  </table>
			  
			  </td></tr></table>
			  
</center>

<br />

<?php

echo'</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();
?>