<?php include_once("init.php");
include "\\layouts/db_connect.php"; 
				session_start('ERP');
					 if(isset($_SESSION['code'])) {
	  $code = $_SESSION['code'];
	  $scode = $_SESSION['code'];
	   $mfin = $_SESSION['mfin'];
		$staff = $_SESSION['name'];
		 $postt = $_SESSION['postt'];
	}
if(isset($_POST['payment'])){
					$_POST = $gump->sanitize($_POST);
                                
					$gump->validation_rules(array(
						'payment'=> 'required|max_len,100|min_len,1'
						
						
						

					));
				
					$gump->filter_rules(array(
						'payment'    	  => 'trim|sanitize_string|mysqli_escape'
						

					));
				
					$validated_data = $gump->run($_POST);
					$stock_name 	= "";
					$stockid 	= "";
					$payment     = "";
					$bill_no 	= "";
			

					if($validated_data === false) {
							echo $gump->get_readable_errors(true);
					} else {
                                            $username = $_SESSION['username'];
                                            
							$stockid=mysqli_real_escape_string($_POST['stockid']);
						
							$bill_no =mysqli_real_escape_string($_POST['bill_no']);
							$mfin =mysqli_real_escape_string($_POST['mfin']);
							$scode =mysqli_real_escape_string($_POST['scode']);
							$customer=mysqli_real_escape_string($_POST['supplier']);
							$address=mysqli_real_escape_string($_POST['address']);
								$branch=mysqli_real_escape_string($_POST['branch']);
							 $qwerty=mysqli_real_escape_string($_POST['bill_no']);
							  $bilno=mysqli_real_escape_string($_POST['bilno']);
							$contact=mysqli_real_escape_string($_POST['contact']);	
	$nitem=mysqli_real_escape_string($_POST['nitem']);	
	$tqty=mysqli_real_escape_string($_POST['tqty']);	
$pcard=mysqli_real_escape_string($_POST['pcard']);
						$cmpy=mysqli_real_escape_string($_POST['cmpy']);			
                                                        $stock_name=$_POST['stock_name'];
							$quty=$_POST['quty'];
							$cess=$_POST['cess'];
							$cessa=$_POST['cessa'];
							$rmk=$_POST['rmk'];
							$date=mysqli_real_escape_string($_POST['date']);
							$sell=$_POST['sell'];
							$hsn=$_POST['hsn'];
							$cgst=$_POST['cgst'];
							$sgst=$_POST['sgst'];
							$igst=$_POST['igst'];
							$cgsta=$_POST['cgsta'];
							$sgsta=$_POST['sgsta'];
							$igsta=$_POST['igsta'];

							$total=$_POST['total'];
							$payable=$_POST['subtotal'];
							
							$description=mysqli_real_escape_string($_POST['description']);
							$due=mysqli_real_escape_string($_POST['duedate']);
							$payment=mysqli_real_escape_string($_POST['payment']);
							$discount=mysqli_real_escape_string($_POST['discount']);
                                                        if($discount==""){
                                                            $discount=00;
                                                        }
							$dis_amount=mysqli_real_escape_string($_POST['dis_amount']);
							if($dis_amount==""){
                                                            $dis_amount=00;
                                                        }
                                                        $subtotal=mysqli_real_escape_string($_POST['payable']);
							$balance=mysqli_real_escape_string($_POST['balance']);
							$mode=mysqli_real_escape_string($_POST['mode']);
							$tax=mysqli_real_escape_string($_POST['tax']);
                                                        if($tax==""){
                                                            $tax=00;
                                                        }
							$tax_dis=mysqli_real_escape_string($_POST['tax_dis']);
                                                       $selected_date=$_POST['due'];
                                                        $selected_date=strtotime( $selected_date );
                                                        $mysqldate = date( 'Y-m-d H:i:s', $selected_date );
                                                        $due=$mysqldate;
									
					 
                                          $max = $db->maxOfAll("id", "otherentry");
					  $max=$max+1;
					  $autoid="SL".$max."";
  for($i=0;$i<count($stock_name);$i++)
                                            {
                        $name1=$stock_name[$i];
                        $quantity=$_POST['quty'][$i];
						$rmk1=$_POST['rmk'][$i];
			$rate=$_POST['sell'][$i];
			$rate2=$_POST['sell2'][$i];
			$hsn1=$_POST['hsn'][$i];
			$cgst1=$_POST['cgst'][$i];
			$cgsta11=$_POST['cgsta'][$i];
			$cess1=$_POST['cess'][$i];
			$cessa11=$_POST['cessa'][$i];
			
			$cgsta1 = $cgsta11 * $quantity;
			$sgst1=$_POST['sgst'][$i];
			$sgsta11=$_POST['sgsta'][$i];
			$sgsta1 = $sgsta11 * $quantity;
			$igst1=$_POST['igst'][$i];
			$igsta11=$_POST['igsta'][$i];
			$igsta1 = $sgsta11 * $quantity *2;
			
			$cessa1 = $cessa11 * $quantity;
			$total=$_POST['total'][$i];
			$tott=$total - $sgsta1 - $cgsta1;
			
			
			$selected_date=$_POST['date'];
		  	$selected_date=strtotime( $selected_date );
			$mysqldate = date( 'Y-m-d', $selected_date );
			$username = $_SESSION['username'];	
			$type = $cess1;
			$hpl = $name1;
			$name = $rate2;
			$pdate = $sgst1;
			$amt =  $quantity;
			$rmark = $igst1;
			$godown = $cessa11;
			$sql5 = mysqli_query($conn, "select * from customerdetails where hpl='$hpl' && mfin='$mfin'");
	$row5 = mysqli_fetch_array($sql5);
	$vno  = $row5['vno'];
	$vname  = $row5['vname']; 	$model  = $row5['model'];
	if($type=='Seized') {
			$insert=mysqli_query($conn, "insert into sizzing(mfin,scode,hpl,sizdate,sizdate2,vno,vname,model,name,godown)
											 values('$mfin','$scode','$hpl','$mysqldate','$mysqldate','$vno','$vname','$model','$name','$godown')");
											 
$update=mysqli_query($conn, "update customerdetails set status='Sized' where hpl='$hpl' && mfin='$mfin'");		
				$delete2=mysqli_query($conn, "delete from pending where mfin='$mfin' && hpl='$hpl'");         

	}
	$db->query("insert into otherentry (mfin,scode,postdate,postdate2,result,hpl,name,promdate,agentname,postamt,postamt2,remark) 
values('$mfin','$scode','$mysqldate','$mysqldate','$type','$hpl','$name','$pdate','$customer','$amt','$amt','$rmark')");	
           	         
			}		 $msg="Other Entries Added successfully Ref: ". $_POST['stockid']."" ;                  						
} }
                                       
				?>
<!DOCTYPE html>

<html lang="en">
<head>
	<meta charset="utf-8">
	<title>INFOSSEL BILLING - Add Sales</title>
	
	<!-- Stylesheets -->
	<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet'>
	<link rel="stylesheet" href="css/style.css">
        <link rel="stylesheet" href="js/date_pic/date_input.css">
        <link rel="stylesheet" href="lib/auto/css/jquery.autocomplete.css">
	
	<!-- Optimize for mobile devices -->
	<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
	
	<!-- jQuery & JS files -->
	<?php include_once("tpl/common_js.php"); ?>
	<script src="js/script.js"></script>  
        <script src="js/date_pic/jquery.date_input.js"></script>  
        <script src="lib/auto/js/jquery.autocomplete.js "></script>  
	 
        <script type="text/javascript">
$(function() {
    
    	$("#supplier").autocomplete("customer1.php", {
		width: 160,
		autoFill: true,
		selectFirst: true
	});
    	$("#item").autocomplete("stock.php", {
		width: 750,
		height: 315,
		autoFill: true,
		selectFirst: true
	});
        $("#item").blur(function()
			{
                          document.getElementById('total').value=document.getElementById('sell').value * document.getElementById('quty').value 
                        });
        $("#item").blur(function()
			{
			 
							
			 $.post('check_item_details.php', {stock_name1: $(this).val() },
				function(data){
                                                              
								$("#sell").val(data.sell);
								$("#sell2").val(data.sell2);
								$("#hsn").val(data.hsn);
								$("#cgst").val(data.cgst);
								$("#cess").val(data.cess);
								$("#cgsta").val(data.cgsta);
								$("#sgst").val(data.sgst);
								$("#sgsta").val(data.sgsta);
								
								$("#igst").val(data.igst);
								$("#igsta").val(data.igsta);
								
								$("#stock").val(data.stock);
								$('#guid').val(data.guid);
								if(data.sell!=undefined)
								$("#0").focus();
								var a = document.getElementById("sell2").value; 
var b = document.getElementById("cgst").value; 
var c = document.getElementById("cess").value; 
var d = document.getElementById("igst").value; 
document.getElementById("sell").value =((a*1)/(1+(((b*2)+(c*1))/100)));  
var a = document.getElementById("sell").value; 
var b = document.getElementById("sgst").value; 
var c = document.getElementById("cess").value; 
document.getElementById("sgsta").value =((a*b)/(100));  
document.getElementById("cgsta").value =((a*b)/(100)); 
document.getElementById("cessa").value =((a*c)/(100));   
								
							}, 'json');
											
					

			
			});
        $("#supplier").blur(function()
			{
			 
							
			 $.post('check_customer_details.php', {stock_name1: $(this).val() },
				function(data){
				
								$("#address").val(data.address);
								$("#contact1").val(data.contact1);
								$("#pcost").val(data.pcost);
								if(data.address!=undefined)
								$("#0").focus();
								
							}, 'json');
											
					

			
			});

		


		var hauteur=1000;
		$('.code').each(function(){
			if($(this).height()>hauteur) hauteur = $(this).height();
		});

		$('.code').each(function(){ $(this).height(hauteur); });
	});

        </script>
		<script>
	/*$.validator.setDefaults({
		submitHandler: function() { alert("submitted!"); }
	});*/
	
function numbersonly(e){
        var unicode=e.charCode? e.charCode : e.keyCode
        if (unicode!=8 && unicode!=46 && unicode!=37 && unicode!=27 && unicode!=38 && unicode!=39 && unicode!=40 && unicode!=9){ //if the key isn't the backspace key (which we should allow)
        if (unicode<48||unicode>57)
        return false
    }
    }
  
	
	</script>
        <script type="text/javascript">
           function remove_row(o) {
    var p=o.parentNode.parentNode;
         p.parentNode.removeChild(p);
           }
     function add_values(){
         if(unique_check()){
    
         if(document.getElementById('edit_guid').value==""){
     if(document.getElementById('item').value!="" && document.getElementById('quty').value!="" &&  document.getElementById('total').value!="" ){
     
                    if(document.getElementById('quty').value!=0){
                        code=document.getElementById('item').value;
  
    quty=document.getElementById('quty').value;
    rmk=document.getElementById('rmk').value;
    sell=document.getElementById('sell').value;
	   sell2=document.getElementById('sell2').value;
    disc=document.getElementById('stock').value;
    total=document.getElementById('total').value;
	
	 hsn=document.getElementById('hsn').value;
    cgst=document.getElementById('cgst').value;
    sgst=document.getElementById('sgst').value;
    igst=document.getElementById('igst').value;
	
    cgsta=document.getElementById('cgsta').value;
    sgsta=document.getElementById('sgsta').value;
    igsta=document.getElementById('igsta').value;
	cess=document.getElementById('cess').value;
    cessa=document.getElementById('cessa').value;
	
	
    item=document.getElementById('guid').value;
    main_total=document.getElementById('posnic_total').value;
    roll=parseInt(document.getElementById('roll_no').value);
document.getElementById('nitem').value=parseInt(document.getElementById('roll_no').value);
document.getElementById('payable_amount2').value=+parseInt(document.getElementById('quty').value) + +document.getElementById('payable_amount2').value;

	var z = document.getElementById("tqty").value; 
var q = document.getElementById("quty").value; 
document.getElementById("tqty").value =((z*1)+(q*1)); 
 
    $('<tr id='+item+'><td><lable id='+item+'roll class=jibi007 >'+roll+'</label></td><td><input type=hidden value='+item+' id='+item+'id ><input type=text name="stock_name[]"  id='+item+'st style="width: 150px" class="round  my_with" readonly="readonly" ></td><td><input type=text name=sell2[] readonly="readonly" value='+sell2+' id='+item+'ss class="round  my_with" style="text-align:right;"  ></td><td><input type=text name=sell[] readonly="readonly" value='+sell+' id='+item+'s class="round  my_with" style="text-align:right;"  ></td><td><input type=text name=cgst[] readonly="readonly" value='+cgst+' id='+item+'cg class="round  my_with" style="text-align:right;" ></td><td><input type=text name=sgst[] readonly="readonly" value='+sgst+' id='+item+'sg class="round  my_with" style="text-align:right;" ></td><td><input type=text name=igst[] readonly="readonly" value='+igst+' id='+item+'ig class="round  my_with" style="text-align:right;" ></td><td><input type=text name=quty[] readonly="readonly" value='+quty+' id='+item+'q class="round  my_with" style="text-align:right;" ></td><input type=hidden name=hsn[] readonly="readonly" value='+hsn+' id='+item+'hs class="round  my_with" style="text-align:right;" ><input type=hidden name=cgsta[] readonly="readonly" value='+cgsta+' id='+item+'cga class="round  my_with" style="text-align:right;" ><input type=hidden name=igsta[] readonly="readonly" value='+cgsta+' id='+item+'iga class="round  my_with" style="text-align:right;" ><input type=hidden name=sgsta[] readonly="readonly" value='+sgsta+' id='+item+'sga class="round  my_with" style="text-align:right;" ><input type=hidden name=cess[] readonly="readonly" value='+cess+' id='+item+'css class="round  my_with" style="text-align:right;" ><input type=hidden name=cessa[] readonly="readonly" value='+cessa+' id='+item+'cssa class="round  my_with" style="text-align:right;" ><input type=hidden name=rmk[] readonly="readonly" value='+rmk+' id='+item+'r class="round  my_with" style="text-align:right;" ><input type=hidden name=stock[] readonly="readonly" value='+disc+' id='+item+'p class="round  my_with" style="text-align:right;" ><td><input type=text name=jibi[] readonly="readonly" value='+total+' id='+item+'to class="round  my_with" style="width: 120px;margin-left:20px;text-align:right;" ><input type=hidden name=total[] id='+item+'my_tot value='+main_total+'> </td><td><input type=button value="" id='+item+' style="width:30px;border:none;height:30px;background:url(images/edit_new.png)" class="round" onclick="edit_stock_details(this.id)"  ></td><td><input type=button value="" id='+item+' style="width:30px;border:none;height:30px;background:url(images/close_new.png)" class="round" onclick=reduce_balance("'+item+'");$(this).closest("tr").remove(); ></td></tr>').fadeIn("slow").appendTo('#item_copy_final');
    

	document.getElementById('quty').value="";
	document.getElementById('rmk').value="";
    document.getElementById('sell').value="";  document.getElementById('sell2').value="";
    document.getElementById('stock').value="";
	
	document.getElementById('hsn').value="";
	document.getElementById('cgst').value="";
    document.getElementById('cgsta').value="";
    document.getElementById('sgst').value="";
	 document.getElementById('sgsta').value="";
	 document.getElementById('igst').value="";
	 document.getElementById('igsta').value="";
	 	document.getElementById('cess').value="";
    document.getElementById('cessa').value="";
	 
    document.getElementById('roll_no').value=roll+1;
    document.getElementById('total').value="";
    document.getElementById('item').value="";
    document.getElementById('guid').value="";
	
    if(document.getElementById('grand_total').value==""){
        document.getElementById('grand_total').value=main_total;
		 
    }else{
    document.getElementById('grand_total').value=parseFloat(document.getElementById('grand_total').value)+parseFloat(main_total);
    }
     document.getElementById('main_grand_total').value=parseFloat(document.getElementById('grand_total').value);
    document.getElementById(item+'st').value=code;
    document.getElementById(item+'to').value=total;
}else{
     alert('No Stock Available For This Item');
}
}else{
     alert('Please Select An Item');
    }
    }else{
    id=document.getElementById('edit_guid').value;
    document.getElementById(id+'st').value=document.getElementById('item').value;  
    document.getElementById(id+'q').value=document.getElementById('quty').value;
    document.getElementById(id+'r').value=document.getElementById('rmk').value;
    document.getElementById(id+'s').value=document.getElementById('sell').value;
	 document.getElementById(id+'ss').value=document.getElementById('sell2').value;
    document.getElementById(id+'p').value=document.getElementById('stock').value;
	 document.getElementById('nitem').value=document.getElementById('roll').value;
	 
	 document.getElementById(id+'hs').value=document.getElementById('hsn').value;  
    document.getElementById(id+'cg').value=document.getElementById('cgst').value;
    document.getElementById(id+'cga').value=document.getElementById('cgsta').value;
	 
	
    document.getElementById(id+'sg').value=document.getElementById('sgst').value;
    document.getElementById(id+'sga').value=document.getElementById('sgsta').value;
	
	document.getElementById(id+'ig').value=document.getElementById('igst').value;
    document.getElementById(id+'iga').value=document.getElementById('igsta').value;
    
	
	 document.getElementById(id+'css').value=document.getElementById('cess').value;
    document.getElementById(id+'cssa').value=document.getElementById('cessa').value;
	 
    document.getElementById('grand_total').value=parseFloat(document.getElementById('grand_total').value)+parseFloat(document.getElementById('posnic_total').value)-parseFloat(document.getElementById(id+'my_tot').value);
    document.getElementById('main_grand_total').value=parseFloat(document.getElementById('grand_total').value);
    document.getElementById(id+'to').value=document.getElementById('total').value;
    document.getElementById(id+'id').value=id;

    document.getElementById(id+'my_tot').value=document.getElementById('posnic_total').value
    document.getElementById('quty').value="";
    document.getElementById('rmk').value="";
    document.getElementById('sell').value="";
	document.getElementById('sell2').value="";
    document.getElementById('stock').value="";
    document.getElementById('total').value="";
	
	document.getElementById('hsn').value="";
    document.getElementById('cgst').value="";
    document.getElementById('sgst').value="";
    document.getElementById('igst').value="";
    document.getElementById('cgsta').value="";
	   document.getElementById('cess').value="";
    document.getElementById('cessa').value="";
    document.getElementById('sgsta').value="";
    document.getElementById('igsta').value="";
	
    document.getElementById('item').value="";
    document.getElementById('guid').value="";
    document.getElementById('edit_guid').value="";
    }
    }
    discount_amount();
    }
    function total_amount(){
    balance_amount();
               
        document.getElementById('total').value=(((document.getElementById('sell').value *1)  + (document.getElementById('cgsta').value *1) + (document.getElementById('cessa').value *1) + (document.getElementById('sgsta').value * 1)) * (document.getElementById('quty').value * 1))
    document.getElementById('posnic_total').value=document.getElementById('total').value;
      //  document.getElementById('total').value = '$ ' + parseFloat(document.getElementById('total').value).toFixed(2);
    if(document.getElementById('item').value===""){
       document.getElementById('item').focus();
   }
    }
   function edit_stock_details(id) {
     document.getElementById('item').value=document.getElementById(id+'st').value;
     document.getElementById('quty').value=document.getElementById(id+'q').value;
     document.getElementById('rmk').value=document.getElementById(id+'r').value;
    document.getElementById('sell').value=document.getElementById(id+'s').value;
	document.getElementById('sell2').value=document.getElementById(id+'ss').value;
    document.getElementById('stock').value=document.getElementById(id+'p').value;
    document.getElementById('total').value=document.getElementById(id+'to').value;
	
	document.getElementById('hsn').value=document.getElementById(id+'hs').value;
     document.getElementById('cgst').value=document.getElementById(id+'cg').value;
    document.getElementById('cgsta').value=document.getElementById(id+'cga').value;
	
	document.getElementById('igst').value=document.getElementById(id+'ig').value;
    document.getElementById('igsta').value=document.getElementById(id+'iga').value;
    
    document.getElementById('sgst').value=document.getElementById(id+'sg').value;
    document.getElementById('sgsta').value=document.getElementById(id+'sga').value;
	document.getElementById('cess').value=document.getElementById(id+'sg').value;
    document.getElementById('cessa').value=document.getElementById(id+'sga').value;
   
    document.getElementById('guid').value=id;
    document.getElementById('edit_guid').value=id;
     
   }
   function unique_check(){
      if(!document.getElementById(document.getElementById('guid').value) || document.getElementById('edit_guid').value==document.getElementById('guid').value){
            return true;
           
        }else{
           
            alert("This Item is already added In This Purchase");
            document.getElementById('item').focus();
             document.getElementById('quty').value="";
             document.getElementById('rmk').value="";
                document.getElementById('sell').value="";
				 document.getElementById('sell2').value="";
                document.getElementById('stock').value="";
				
				document.getElementById('hsn').focus();
             document.getElementById('cgst').value="";
             document.getElementById('sgst').value="";
             document.getElementById('igst').value="";
                document.getElementById('cgsta').value="";
                document.getElementById('sgsta').value="";
                document.getElementById('igsta').value="";
				document.getElementById('cess').value="";
                document.getElementById('cessa').value="";
				
                document.getElementById('total').value="";
                document.getElementById('item').value="";
                document.getElementById('guid').value="";
                document.getElementById('edit_guid').value="";
                return false;
   }
   }
   function quantity_chnage(e){
         var unicode=e.charCode? e.charCode : e.keyCode
                if (unicode!=13 && unicode!=9){
        }
       else{
         add_values();
          
            document.getElementById("item").focus();
           
        }
         if (unicode!=27){
        }
       else{
               
             document.getElementById("item").focus();
        }
   }
    function formatCurrency(fieldObj)
{
    if (isNaN(fieldObj.value)) { return false; }
    fieldObj.value = '$ ' + parseFloat(fieldObj.value).toFixed(2);
    return true;
}
function balance_amount(){
    if(document.getElementById('payable_amount').value!="" && document.getElementById('payment').value!=""){
    data=parseFloat(document.getElementById('payable_amount').value);
    document.getElementById('balance').value=data-parseFloat(document.getElementById('payment').value);
        if(parseFloat(document.getElementById('payable_amount').value) >= parseFloat(document.getElementById('payment').value)){
       
    }else{
        if(document.getElementById('payable_amount').value!=""){
         document.getElementById('balance').value='000.00';
         document.getElementById('payment').value=parseFloat(document.getElementById('payable_amount').value);
        }else{
            document.getElementById('balance').value='000.00';
         document.getElementById('payment').value="";
        }
    }
    }else{
        document.getElementById('balance').value="";
    }

    
}
function stock_size(){
    if(parseFloat(document.getElementById('quty').value) > parseFloat(document.getElementById('stock').value)){
       document.getElementById('quty').value=parseFloat(document.getElementById('stock').value);
    
    console.log();
        }
}
function discount_amount(){
 
        if(document.getElementById('grand_total').value!=""){
            document.getElementById('disacount_amount').value=parseFloat(document.getElementById('grand_total').value)*(parseFloat(document.getElementById('discount').value))/100;
        
        }
        if(document.getElementById('discount').value==""){
             document.getElementById('disacount_amount').value="";
        }
        
        discont=parseFloat(document.getElementById('disacount_amount').value);
    if(document.getElementById('disacount_amount').value==""){
        discont=0;
    }
    document.getElementById('payable_amount').value=parseFloat(document.getElementById('grand_total').value)-discont;
    if(parseFloat(document.getElementById('payment').value)>parseFloat(document.getElementById('payable_amount').value)){
    document.getElementById('payment').value=parseFloat(document.getElementById('payable_amount').value);
         
        }
    
}
function discount_as_amount(){
      if(parseFloat(document.getElementById('disacount_amount').value) > parseFloat(document.getElementById('grand_total').value))
document.getElementById('disacount_amount').value="";

    if(document.getElementById('grand_total').value!=""){
        if(parseFloat(document.getElementById('disacount_amount').value) < parseFloat(document.getElementById('grand_total').value))
       { discont=parseFloat(document.getElementById('disacount_amount').value);
        
         document.getElementById('payable_amount').value=parseFloat(document.getElementById('grand_total').value)-discont;
    if(parseFloat(document.getElementById('payment').value)>parseFloat(document.getElementById('payable_amount').value)){
    document.getElementById('payment').value=parseFloat(document.getElementById('payable_amount').value);
   
    }
    }else{
      // document.getElementById('disacount_amount').value=parseFloat(document.getElementById('grand_total').value)-1;
    }
}
}
function reduce_balance(id){
 var minus=parseFloat(document.getElementById(id+"my_tot").value);
  document.getElementById('grand_total').value=parseFloat(document.getElementById('grand_total').value)-minus;
  document.getElementById('main_grand_total').value=parseFloat(document.getElementById('grand_total').value);
   discount_amount();
   var elements = document.getElementsByClassName('jibi007');
var j=1;
var my_id=id+'roll';
for (var i = 0; i < elements.length; i++) {
    elements[0].value=1;
   if(parseFloat(document.getElementById(my_id).innerHTML)==i){
     elements[i].innerHTML =parseFloat(elements[i-1].innerHTML)
   }else{
       if(i!=0){
         elements[i].innerHTML =parseFloat(elements[i-1].innerHTML)+1;
        j++;
       }
   }
     document.getElementById('roll_no').value=elements.length;
}
   //console.log(id);
}
function discount_type(){
    if(document.getElementById('round').checked){
        document.getElementById("discount").readOnly=true;
        document.getElementById("disacount_amount").readOnly=false;
        if(parseFloat(document.getElementById('grand_total'))!=""){
            document.getElementById('disacount_amount').value="";
            document.getElementById('discount').value="";
            discount_amount();
        }
    }else{
        document.getElementById("discount").readOnly=false;
        document.getElementById("disacount_amount").readOnly=true;  
    }
}
function ac15(){
	
     if(document.getElementById('rou15').checked){
		  document.getElementById("disacount_amount").value="";
    document.getElementById('discount').disabled=false;
    document.getElementById("discount").readOnly=false;
        document.getElementById("disacount_amount").readOnly=true;  
        document.getElementById("disacount_amount").style.background="#D9DBDD";
		  document.getElementById('discount').value=14.5;
      discontt=parseFloat(document.getElementById('payable_amount').value)*(parseFloat(14.5))/100;
                       document.getElementById('payable_amount').value=parseFloat(document.getElementById('payable_amount').value)+discontt;
document.getElementById('disacount_amount').value=parseFloat(document.getElementById('payable_amount').value) - parseFloat(document.getElementById('main_grand_total').value);    balance_amount();
     }
}
function discount_type_per(){
     if(document.getElementById('round').checked){
          document.getElementById("disacount_amount").value="";
    document.getElementById('discount').disabled=false;
    document.getElementById("discount").readOnly=false;
        document.getElementById("disacount_amount").readOnly=true;  
        document.getElementById("disacount_amount").style.background="#D9DBDD";
    
     }else{
         document.getElementById("disacount_amount").style.background='white';
         document.getElementById('discount').disabled=true;
          document.getElementById("discount").readOnly=true;
        document.getElementById("disacount_amount").readOnly=false;
        if(parseFloat(document.getElementById('grand_total'))!=""){
            document.getElementById('disacount_amount').value="";
            document.getElementById('discount').value="";
            discount_amount();
        }
     }
}
        </script>
		<script> 
function add2() 
{ 
var a = document.getElementById("sell").value; 
var b = document.getElementById("sgst").value; 
var c = document.getElementById("cess").value; 
document.getElementById("sgsta").value =((a*b)/(100));  
document.getElementById("cgsta").value =((a*b)/(100)); 
document.getElementById("cessa").value =((a*c)/(100));  
} 
function add23() 
{ 
var a = document.getElementById("sell2").value; 
var b = document.getElementById("cgst").value;
var c = document.getElementById("cess").value; 
document.getElementById("sell").value =((a*1)/(1+(((b*2)+(c*1))/100)));  
var a = document.getElementById("sell").value; 
var b = document.getElementById("sgst").value; 
var c = document.getElementById("cess").value; 
document.getElementById("sgsta").value =((a*b)/(100));  
document.getElementById("cgsta").value =((a*b)/(100));   
document.getElementById("cessa").value =((a*c)/(100));   
} 

$('input').live("keypress", function(e) {
                /* ENTER PRESSED*/
                if (e.keyCode == 13) {
                    /* FOCUS ELEMENT */
                    var inputs = $(this).parents("form").eq(0).find(":input");
                    var idx = inputs.index(this);
 
                    if (idx == inputs.length - 1) {
                        inputs[0].select()
                    } else {
                        inputs[idx + 1].focus(); //  handles submit buttons
                        inputs[idx + 1].select();
                    }
                    return false;
                }
            });
</script>

</head>
<body>
						<div class="content-module-main cf">
		
			
					<?php
					//Gump is libarary for Validatoin
					 if(isset($_GET['msg'])){
                                                                              $data=$_GET['msg'];
                                            $msg='<p style=color:#153450;font-family:gfont-family:Georgia, Times New Roman, Times, serif>'.$data.'</p>';//
                                            ?>
                                                    
 <script  src="dist/js/jquery.ui.draggable.js"></script>
<script src="dist/js/jquery.alerts.js"></script>
<script src="dist/js/jquery.js"></script>
<link rel="stylesheet"  href="dist/js/jquery.alerts.css" >
<script type="text/javascript">
	
					jAlert('<?php echo  $msg; ?>', 'POSNIC');
</script>
                                                        <?php
                                        }
					?>
<form name="form1" method="post" id="form1" action="">
                                    <input type="hidden" id="posnic_total" >
                                    <input type="hidden" id="roll_no" value="1" >
                  <div class="mytable_row ">
				
                  <table class="form "  border="0" cellspacing="0" cellpadding="0" style="margin:15px 0 0 80px">
         
                               <?php
					  $max = $db->maxOfAll("id","otherentry");
					  $max=$max+1;
					  $autoid="PR".$max."";
					  ?>
					           <?php
					  $ono = $db->maxOfAll("id","otherentry");
					  $ono=$ono+1;
					  $qwerty=$ono;
					  $mfin=$_REQUEST['mfin'];
				      $scode=$_REQUEST['scode'];
					  ?>
					<tr>  <input name="stockid" type="hidden" id="stockid" readonly="readonly" maxlength="200"  class="round default-width-input" style="width:130px " value="<?php echo $autoid ?>" />
                       
                      <td>Date:</td>
                      <td><input  name="date" id="test1" placeholder="" value="<?php echo date('d-m-Y');?>" type="text" id="name" maxlength="200"  class="round default-width-input"  /></td>
                       <td>&nbsp; </td>  <td ><span class="man">*</span>S.No:<input type="hidden"> </td> 
                      
                      <td><input name="bill_no" placeholder="ENTER BILL NO" type="text" id="bill_no" maxlength="200" value="<?php echo $qwerty ?>"  class="round default-width-input" style="width:120px " />
					  
					  <input name="bilno" placeholder="ENTER BILL NO" type="hidden" id="bill_no" maxlength="200" value="<?php echo $ono ?>"  class="round default-width-input" style="width:120px " />
<input type="hidden" name="stype" placeholder="" id="stype" maxlength="200" value=""  class="round default-width-input" style="width:120px " >
<input type="hidden" name="mfin" placeholder=""  id="mfin" maxlength="200" value="<?php echo $mfin; ?>"  class="round default-width-input" style="width:120px " >
<input type="hidden" name="scode" placeholder="" id="scode" maxlength="200" value="<?php echo $scode; ?>"  class="round default-width-input" style="width:120px " >
									
					 					
					<input name="qwerty" placeholder="ENTER BILL NO" type="hidden" id="qwerty" maxlength="200" value="<?php echo $qwerty ?>"  class="round default-width-input" style="width:120px " /></td>
                       
                
					<td><span class="man">*</span>Customer:</td>
                      <td><input name="supplier" placeholder="ENTER CUSTOMER" type="text" id="supplier"  maxlength="200"  class="round default-width-input" value=""  style="width:130px " /></td>
 <input name="contact" placeholder="ENTER CONTACT" type="hidden" id="contact1" maxlength="200"  class="round default-width-input" onkeypress="return numbersonly(event)" style="width:120px " />
<input name="address" placeholder="ENTER ID" type="hidden" id="address" maxlength="200"  class="round default-width-input"  />
             <input name="pcost" placeholder="" type="hidden" id="pcost" maxlength="200" style="width:130px; color: #FFFFFF; background-color: #f44336; " class="round default-width-input"  />
			<input type="hidden" name="branch" placeholder="" type="text" id="branch" maxlength="200" style="width:130px; color: #FFFFFF; background-color: #f44336; " class="round default-width-input"  >
			
                        
                    </tr>

 <td><input type="hidden"  class="round"  name="cmpy"  style="width:150px;height:20px " ></td>	
          
				</div>
                   </table>
                  </div><br><div align="center">
				  <div align="center">
                  <input type="hidden" id="guid">
                  <input type="hidden" id="edit_guid">
                        
                  <table class="form" >
                      <tr>
                          <td>HPL:</td>
						  <td>Name:</td>
						   <td>Model:</td>
                          <td>Reg No:</td>
					
						    
			
							  <td>Post Date</td>
							   <td>Type</td> <td>Veh Gowdown</td>
							  <td>Remark</td>
						<td>Amount</td>
                         
                      </tr>
                        <tr>
                 
  <td><input name=""  type="text" id="item"   maxlength="200"  class="round default-width-input " style="width: 80px"   /></td>
  <td><input name=""  type="text" id="sell2" maxlength="200" style="width: 190px" class="round default-width-input my_with"   /></td>
  <td><input name=""  type="text" id="sell" maxlength="200" style="width: 90px" class="round default-width-input my_with"    /></td>
  <td><input name=""  type="text" id="cgst"  maxlength="200" style="width: 90px"  class="round default-width-input my_with"    /></td>
  <td><input name=""  type="text" id="sgst"  maxlength="200"  style="width:90px" class="round default-width-input my_with"    /></td>
  <td><select name=""  type="text" id="cess"  maxlength="200" class="round default-width-input my_with"    >
  
  <option>Select </option>
<option>Not Paid</option>
<option>Post Pond</option>
<option>Received</option>
<option>Seized</option>
<option>Spare Veh</option>
<option>Theft Veh</option>

</select></td> 
 <td><select name=""  type="text" id="cessa"  maxlength="200" class="round default-width-input my_with"    >
  
  <option value="">None</option>
	  <?php $sql5 = mysqli_query($conn, "select * from godown"); while($row5 = mysqli_fetch_array($sql5)) { ?>
	  <option value="<?php echo $row5['name']; ?>"><?php echo $row5['name']; ?></option> <?php } ?></select>

</select></td> 
  <td><input name=""  type="text" id="igst"  maxlength="200"  style="width:90px" class="round default-width-input my_with"    /></td>
  <td><input name=""  type="text" id="quty" style="width: 90px"  maxlength="200"   class="round default-width-input my_with" onKeyPress="quantity_chnage(event);return numbersonly(event)" onkeyup="total_amount();unique_check();stock_size();"    /></td>

	


		<input name=""  type="hidden" id="igsta"  maxlength="200"   class="round default-width-input my_with"    />
 	<input name=""  type="hidden" id="sgsta"  maxlength="200"   class="round default-width-input my_with"    />
  <input name=""  type="hidden" id="cgsta"  maxlength="200"   class="round default-width-input my_with"    />
 <input name=""  type="hidden" id="hsn"  maxlength="200"   class="round default-width-input my_with"    />

<input name=""  type="hidden" id="rmk"  maxlength="200" style="width: 60px"  class="round default-width-input my_with"    />
                 
				<input name=""  type="hidden" id="stock" readonly="readonly" maxlength="200" style="width: 60px"  class="round  my_with"  />
                      <input name=""  type="hidden" id="total" maxlength="200" style="width: 90px" class="round default-width-input " style="width:120px;  margin-left: 20px"  />
                      <td><input type="button" onclick="add_values()" onkeyup=" balance_amount();" id="add_new_code"  style="margin-left:30px; width:30px;height:30px;border:none;background:url(images/add_new.png)" class="round"> </td>
                     
                    </tr>
                  </table>
                          
                       <div style="overflow:auto ;max-height:250px;  ">
                           <table class="form" id="item_copy_final" style="margin-left:45px ">
                    
                    </table>
                   </div>
                     </div>
                  </div>
				  </br>
                       <div class="mytable_row "  style="overflow:auto ;max-height:200px;  ">
					   <div style="margin:0 0 0 50px">
                  <table class="form">
<input type="hidden" disabled class="round" onkeyup=" discount_amount(); " onkeypress="return numbersonly(event);" name="discount" id="discount" class="round" style="width:150px;height:13px " >
<input type="hidden"  onkeypress="return numbersonly(event);"  onkeyup=" discount_as_amount(); "  id="disacount_amount" name="dis_amount" class="round" style="width:150px;height:13px ">               
<input type="hidden" readonly="readonly" id="grand_total" name="subtotal" > 
<input type="hidden" id="main_grand_total" readonly="readonly" class="round default-width-input"  style="text-align:right;width:150px;height:13px; color: #FFFFFF; background-color: #f44336;" class="round" >
<input type="hidden" id="nitem" name="nitem" readonly="readonly" class="round"  style="text-align:right;width:150px;height:13px; color: #FFFFFF; background-color: #f44336;" class="round" >
<input type="hidden" id="tqty" name="tqty" readonly="readonly" class="round"  style="text-align:right;width:150px;height:13px; color: #FFFFFF; background-color: #f44336;" class="round" >
<input type="hidden" readonly="readonly" id="grand_total"  > <font face="arial" size="5.2">
<input type="hidden" id="payable_amount" readonly="readonly" name="payable" class="round"  style="text-align:right;width:200px;height:25px;  color: #FFFFFF; background-color: #2069b4; "></font></td>	                
<input type="text" id="payable_amount2" readonly="readonly" name="payable" class="round"  style="text-align:right;width:200px;height:25px;  color: #FFFFFF; background-color: #2069b4; "></font></td>	                

<input type="hidden" name="description" class="round">				
<input type="hidden" class="round" onkeyup=" balance_amount(); " value="0" onkeypress="return numbersonly(event);" name="payment" id="payment"   style="width:150px;height:13px " >
<input type="hidden"  class="round" readonly="readonly" id="balance" name="balance" value="0"  style="width:150px;height:14px ">               
<input type="hidden" name="mode" style="width:170px;height:30px;" class="round">
<input type="hidden" class="round" onkeypress="return numbersonly(event);" name="pcard" id="pcard" value="0" style="width:150px;height:13px " >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input  class="button round blue image-right ic-add text-upper" type="submit" name="Submit" value="Save this">
                     </td><td>			(Control + S)
                    </td>
                     <td> &nbsp;</td>	                 
				 </tr> 
		
                  
                   
                <input type="hidden" name="tax" onkeypress="return numbersonly(event);"   style="width:150px;height:13px " class="round default-width-input">         
           <input type="hidden" name="tax_dis"  style="width:180px;height:20px" class="round default-width-input"> 
                 
            
                       <!--Due Date:--><input type="hidden" name="duedate" id="" value="" class="round"  style="width:150px;height:13px ">
           
                  </table>
                
				</div>
                       </div>
                </form>
				</div> <!-- end content-module-main -->		
</body>
</html>