<?php 
session_start();
ob_start(); 
include "header.php";
//$objIms->Semifinisheditem_alter();
?>



<?php

/*if(isset($_POST["del"]))
{
	$tem_id=$_POST["del"];
	
	$del="delete from tmp_purchase_details where id=$tem_id";
	mysql_query($del);

}
*/




if(isset($_POST["Save"]))
{
	$order_no=$_POST["order_no"];
	
	$or_date = date('d-m-Y', strtotime($_POST['order_date']));	
	$order_date=$objIms->DateToInt($or_date);
	$stampdate=$objIms->DateToInt(date('d-m-Y'));	
	$vendor_id=$_POST["supplier_name"];	
	$totamt=$_POST["totamt"];
	$pay_type=$_POST["pay_type"];	
	$result=$_POST["grand_total"];
	$round_off=$_POST["round_off"];
	$totdiscount=$_POST["totdiscount"];
	$freight_charge=$_POST["freight_chrg"];
	$payment_mode=$_POST["payment_mode"];
	$bank_id=$_POST["bank"];
	$cheque_no=$_POST["cheque_no"];
	$cheque_date=$_POST["cheque_date"];
	$bank_name=$_POST["bank_name"];
	$branch_name=$_POST["branch_name"];
	$sql2 = "select * from tbl_supplier where id = '$vendor_id' and session_login_id = '".$_SESSION['login_id']."'";
	$res2 = mysql_query($sql2);
	$row1 =mysql_fetch_assoc($res2);
	$c_name = $row1["supplier_name"];
	
			if(($order_no<>"") && ($vendor_id<>""))
			{
				$sql_insmas="insert into tbl_purchase_master(order_no,purchase_date,stampdate,supplier_id,discount, grand_tot, round_off,freight_charge,order_id,session_login_id) values('$order_no','$order_date','$stampdate','$vendor_id','$totdiscount','$result','$round_off','$freight_charge','".$_REQUEST['order_id']."','".$_SESSION['login_id']."')";
				
				$res_insmas=mysql_query($sql_insmas);
				$lastid=mysql_insert_id();
				
				$pur_no='PUR/'.date('M').'/'.date('Y').'/'.$lastid;
				$sql_upmas="Update tbl_purchase_master set receiving_no='$pur_no' where id='$lastid' and session_login_id = '".$_SESSION['login_id']."'";
				$res_upmas=mysql_query($sql_upmas);
				
				
					
					$countowner=$_POST["count"];
		   
		   for($co=1;$co<=$countowner;$co++)
			{
					$item_id=$_POST["item_id$co"];
					$qty=$_POST["qty$co"];
					$pur_price=$_POST["price$co"];
					$unit_id=$_POST["unit_id$co"];
					$sell_price=$_POST["sell_price$co"];
					$discount=$_POST["discount$co"];
					$cgst=$_POST["cgst$co"];
					$sgst=$_POST["sgst$co"];
					$igst=$_POST["igst$co"];
					 if(($qty!='' || $qty!='0')and($sell_price!='' || $sell_price!='0')and($pur_price!='' || $pur_price!='0')){
					$sql4="insert into tbl_purchase_details(purmas_id,item_id,pur_qty,pur_price,unit_id,sell_price,discount,cgst,sgst,igst,session_login_id)values('$lastid','$item_id','$qty','$pur_price','$unit_id','$sell_price','$discount','$cgst','$sgst','$igst','".$_SESSION['login_id']."')";
					//echo $sql4;
					$rs1=mysql_query($sql4);
					$sel="select * from tbl_stock where session_login_id = '".$_SESSION['login_id']."' and item_id='$item_id' and unit_id='$unit_id' and unit_price='$pur_price' and sell_price='$sell_price'";
					$query=mysql_query($sel);
					if(mysql_num_rows($query)>0)
					{
					$rsq=mysql_fetch_array($query);
					$tot_qty=$rsq["tot_qty"]+$qty;
					$update="update tbl_stock set tot_qty='$tot_qty' where session_login_id = '".$_SESSION['login_id']."' and item_id='$item_id' and unit_id='$unit_id' and unit_price='$pur_price' and sell_price='$sell_price'";
					mysql_query($update);
					}
					else
					{
					$sqls="insert into tbl_stock(item_id,unit_id,tot_qty,unit_price,sell_price,session_login_id)values('$item_id','$unit_id','$qty','$pur_price','$sell_price','".$_SESSION['login_id']."')";
					//echo $sql4;
					$rss=mysql_query($sqls);
					}
					
					}
					
					}
					
					
					
					
					$invoice_no=$objIms->trasaction_no();
					if($pay_type=='Debit1')
					{
					 $sql_ins="insert into tbl_account(invoice_no,mas_id,trans_date,actual_amt,Dr_Amt,sales_type,cash_type,discount, grand_tot, payment_mode,session_login_id) values('$invoice_no','$lastid','$stampdate','$round_off','$round_off','Purchase','$pay_type','$totdiscount','$result','Due','".$_SESSION['login_id']."')";
					
					 $res_ins=mysql_query($sql_ins);


				 $sql_ins="insert into supplier_details(name_id,name,cr_amount, sales_type, pur_mstr_id, stampdate,session_login_id) values('$vendor_id','$c_name','$round_off','Purchase','$lastid','$order_date','".$_SESSION['login_id']."')";
					 
					$res_ins=mysql_query($sql_ins);

					}
					else
					{
					if($payment_mode=='Cash'){	
					 $sql_ins="insert into tbl_account(invoice_no,mas_id,trans_date,actual_amt,Dr_Amt,sales_type,cash_type,clear,discount, grand_tot,payment_mode,session_login_id) values('$invoice_no','$lastid','$stampdate','$round_off','$round_off','Purchase','$pay_type',1,'$totdiscount','$result','$payment_mode','".$_SESSION['login_id']."')";
					
					 $res_ins=mysql_query($sql_ins);
					 $accid=mysql_insert_id();
					 $sql_cash="insert into cash_detail(sales_type, cr_amount, Pur_pay_id, stampdate,session_login_id) values('Purchase_cash', '$round_off', '$lastid', '$stampdate','".$_SESSION['login_id']."');";
					 $res_cash=mysql_query($sql_cash);
					 }
					 else{
				 $sql_ins="insert into tbl_account(invoice_no,mas_id,trans_date,actual_amt,Dr_Amt,sales_type,cash_type,clear,discount, grand_tot,payment_mode,bank_id,session_login_id) values('$invoice_no','$lastid','$stampdate','$round_off','$round_off','Purchase','$pay_type',1,'$totdiscount','$result','$payment_mode','$bank_id','".$_SESSION['login_id']."')";
					  
					 $res_ins=mysql_query($sql_ins);
					 $accid=mysql_insert_id();
			        $sql_bank ="insert into tbl_bank(head, bankdet_id, credit, stampdate,session_login_id ) values('Purchase', '$bank_id', '$round_off','$order_date','".$_SESSION['login_id']."')";
					$res_bank=mysql_query($sql_bank);


					 $sql_insw="insert into tbl_cheque_details(account_id,chqdate,chqno,chqbank,chqbranch,session_login_id)values('$accid','$cheque_date','$cheque_no','$bank_name','$branch_name','".$_SESSION['login_id']."')";
					 mysql_query($sql_insw);
					}
					}
				
				
			   
			
				
				
				?>
				<script type="text/javascript"> 
				alert('Success');
				</script>
				<?php
				
				 header("location:poraise_list.php?cmd=Clear");	
				 
			}
		
}

?>

	 <?php 
//Generate order no..............................................
		/*function getTotalEmployees() {
		$query = "SELECT max(id) as numss FROM tbl_pur_order_master";
		 $totalrecord = mysql_fetch_array(mysql_query($query));
		$num = $totalrecord[numss]; 
		//	echo $totalrecord;		 
		++$num; // add 1;
		$len = strlen($num);
		for($i=$len; $i< 6; ++$i) {
		$num = '0'.$num;
		}
		return $num;
		}		

$mm=$db->findmm($date=date('d-m-Y'));
$yy=$db->findyy($date=date('d-m-Y'));

//$uresult=strtoupper($result) ;
$number = getTotalEmployees();
$order_no = 'P0/USC/'.$number.'/'.$mm.'-'.$yy;*/
//echo $order_no;			
//end...............................................................	
?>



		
	<script type="text/javascript">
	$(document).ready(function() {                
	$("#form1").validate({
	rules: {
	delv_location: "required",
	supplier_name: "required",
	pay_type:"required",
	freight_chrg:"required",
	},
	messages: {
	delv_location:"",
	supplier_name:"",
	pay_type:"",
	freight_chrg:"enter",
	},
	});                
	});
	
	
	
	
	
		
		
		
	</script>
		 <style>
			select.error { background-color:#ffa8a8; border: 1px dotted red;  }
			input.error{ background-color:#ffa8a8;   }
			textarea.error{ background-color:#ffa8a8; border: 1px dotted red;  }
			
			.tb > tbody > tr > td, .tb > tbody > tr > th, .tb > tfoot > tr > td, .tb > tfoot > tr > th, .tb > thead > tr > td, .tb > thead > tr > th { border:0px;
}
         </style>
		 
        <script type="text/javascript"> 
 		jQuery(document).ready(function(){
			$('#item_nm').autocomplete({source:'../ProgramFile/auto/suggest_POitem.php', minLength:1,
			select: function (event, ui) {
        	$("#item_id").val(ui.item.id); // display the selected id
       		$("#item_nm").val(ui.item.value); // display the selected text.
			
		    }
			});

}); 
</script>

<script type="application/javascript">
	function isNumberKey(evt)
	{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 46 || charCode > 57))
	return false;
	return true;
	}
	
	
	function calfreight(str)
	{
		var sumtot=document.getElementById("totamt").value;
		var calf=eval(str)+eval(sumtot);
		//alert(Math.round(eval(calf)));
		
		document.getElementById("grand_total").value=eval(calf);
		document.getElementById("round_off").value=Math.round(eval(calf));
		
	}
	
	
	function showpay(str)
	{
		if(str=='Cheque')
		{
			document.getElementById("showdiv").style.display='block';
		}
		else
		{
			document.getElementById("showdiv").style.display='none';
		}
	}
	</script>
<script type="text/javascript" language="javascript">

var e = document.getElementById("ddlViewBy");
var strUser = e.options[e.selectedIndex].text;
document.getElementById("tax_name")=strUser;
</script>	
<style type="text/css">
<!--
.table_bg{ border:#CCCCCC solid 1px; border-radius:5px; height:auto; width:auto; padding:20px; margin-bottom:10px;}


-->
</style>
<!-- Page wrapper  -->
        <div class="page-wrapper">
           
            <!-- Container fluid  -->
            <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
							<h4>Purchase <span style="float:right"><button onclick="goBack()" class="btn btn-info btn-sm">Go Back</button><script>
function goBack() {
    window.history.back();
}
</script></span></h4>
						
<form id="form1" name="form1" method="post" action="">
<p>&nbsp;</p>
<?php
 $sql_po="select * from tbl_poraise_master where md5(id)= '".$_GET['uid']."' and   session_login_id = '".$_SESSION['login_id']."'";
							
							$c_po=mysql_query($sql_po);
							
						$row_po=mysql_fetch_array($c_po);
?>
<table width="100%" cellpadding="4">
  <tr>
  <input name="order_id" type="hidden" class="required form-control" id="order_id" value="<?php echo $row_po["id"];?>"  style="width:200px; background-color:#FFF" required readonly="" />
    <td height="38" bgcolor="#FFFFFF" ><strong>Order   No</strong></td>
   
    <td bgcolor="#FFFFFF" ><input name="order_no" type="text" class="required form-control" id="order_no" value="<?php echo $_POST["order_no"];?>"  style="width:200px; background-color:#FFF" required /></td>
    <td width="8%" height="38"><strong>Supplier Name<span style="color:#F00; font-weight:bold;">*</span> </strong></td>
   
    <td width="31%"><select name="supplier_name" id="supplier_name" style="width:200px;" onchange="showadd(this.value)" class="required form-control" required>
        
        <?php 
							$sqlc="select * from tbl_supplier where id = '".$row_po['supplier_id']."' and   session_login_id = '".$_SESSION['login_id']."'";
							//echo $sqlc;
							$c=mysql_query($sqlc);
							if(mysql_num_rows($c)>0){
							while($cs=mysql_fetch_array($c))
							{?>
        <option value="<?=$cs["id"];?>" <?php if(($cs["id"])==$_POST["supplier_name"]){ ?> selected="selected" <?php }?>>
        <?=$cs["supplier_name"];?>
        </option>
        <?php }}?>
    </select></td>
    </tr>
  <tr>
    <td width="7%" height="34" bgcolor="#FFFFFF" ><strong>Purchase Date </strong></td>
   
    <td width="28%" bgcolor="#FFFFFF" ><?php if(($_POST["order_date"])=="") { $dt=date("d-m-Y");} else { $dt=$_POST["order_date"];}?>
        <input name="order_date" type="date" id="order_date"  style="width:185px; background-color:#FFF"  value="<?=$dt?>" class="tcal form-control" required/></td>
    <td><strong>Cash Type<span style="color:#F00; font-weight:bold;">*</span></strong></td>
    
    <td><select name="pay_type" id="pay_type" style="width:200px;" class="form-control" required >
      <option value="">---Please Select---</option>
      <option value="Debit1"<?php if($_POST["pay_type"]=='Debit1'){?> selected="selected"<?php }?>>Credit</option>
      <option value="Debit"<?php if($_POST["pay_type"]=='Debit'){?> selected="selected"<?php }?>>Payment</option>
    </select></td>
  </tr>
</table>
<div class="panel">
<div class="panel-heading"><strong>Item </strong></div>
        
			 <table id="example23" class="display nowrap table tb   " cellspacing="0" width="100%">
			 <tbody>
			 <?php 
			 $sql_po_det="select * from tbl_poraise_details where purmas_id= '".$row_po['id']."' and   session_login_id = '".$_SESSION['login_id']."'";
							
							$c_po_det=mysql_query($sql_po_det);
							$i=0;
						while($row_po_det=mysql_fetch_array($c_po_det)){
						$i++;
						
						$sql_pur_by_po="select *,sum(pur_qty)as rv_qty from tbl_purchase_details where   session_login_id = '".$_SESSION['login_id']."' and purmas_id  in(select id from tbl_purchase_master where order_id = '".$row_po['id']."' and   session_login_id = '".$_SESSION['login_id']."') group by item_id, unit_id, pur_price";
							
							$c_pur_by_po=mysql_query($sql_pur_by_po);
							
						$row_pur_by_po=mysql_fetch_array($c_pur_by_po);
			 ?>
            <tr  align="left">
            <td >Item Name</td>
            
            <td > <?php 
			 $sql_itm="select * from tbl_item where id= '".$row_po_det['item_id']."' and  session_login_id = '".$_SESSION['login_id']."'";
							
							$c_itm=mysql_query($sql_itm);
							
						$row_itm=mysql_fetch_array($c_itm);
			 ?><textarea  name="item_nm<?=$i?>" id="item_nm<?=$i?>" style="width:150px;" readonly="readonly"   /><?php echo  $row_itm['item_name'];?></textarea>
            <input type="hidden" name="item_id<?=$i?>" id="item_id<?=$i?>" value="<?php echo  $row_po_det['item_id'];?>" /></td>
            <td >Unit</td>
            
            <td ><select name="unit<?=$i?>" id="unit<?=$i?>" style="width:75px;" class="form-control" onchange="showadd(this.value)" >
             
              <?php 
							$sqlc="select * from tbl_unit where id = '".$row_po_det['unit_id']."' and   session_login_id = '".$_SESSION['login_id']."'";
							//echo $sqlc;
							$c=mysql_query($sqlc);
							if(mysql_num_rows($c)>0){
							while($cs=mysql_fetch_array($c))
							{?>
              <option value="<?=$cs["id"].'/'.$cs["unit_name"];?>" >
              <?=$cs["unit_name"];?>
              </option>
              <?php }}?>
            </select> <input type="hidden" name="unit_id<?=$i?>" id="unit_id<?=$i?>" value="<?php echo  $row_po_det['unit_id'];?>" /></td>
			<td >Order Qty</td>
            
            <td ><input type="text" name="or_qty<?=$i?>" id="or_qty<?php echo $i; ?>" style="width:75px" value="<?php echo $row_po_det['pur_qty'];?>" readonly=""/></td>
			<td >Recieve Qty</td>
            
            <td ><input type="text" name="rcv_qty<?=$i?>" id="rcv_qty<?php echo $i; ?>" style="width:65px" value="<?php if($row_pur_by_po['rv_qty']>0){ echo $row_pur_by_po['rv_qty'];}else{echo '0';}?>" readonly=""/></td>
            <td >Qty</td>
            
            <td ><input type="text" name="qty<?=$i?>" id="qty<?php echo $i; ?>" onkeyup="sum(<?php echo $i; ?>);" onkeypress="return isNumberKey(event)" style="width:65px" /></td>
           
			 <td >Pur Price(Per)</td>
            
            <td ><input type="text" name="price<?=$i?>" id="price<?php echo $i; ?>" onkeyup="sum(<?php echo $i; ?>);" value="<?php echo $row_po_det['price'];?>" onkeypress="return isNumber(event,this);" style="width:65px"   /></td>
			</tr>
            <tr height="32" align="left">
			
			<td>Sell Price(Per)</td>
			
			<td><input type="text" name="sell_price<?=$i?>" id="sell_price<?php echo $i; ?>"  onkeypress="return isNumber(event,this);" style="width:65px" /></td>
              <td>Discount(in %)</td>
              
              <td><input type="text" name="discount<?=$i?>" id="discount<?php echo $i; ?>" value="<?php echo $row_po_det['discount'];?>" onkeyup="sum(<?php echo $i; ?>);" onkeypress="return isNumber(event,this);" style="width:65px" />
			  <input type="hidden" name="dis<?=$i?>" id="dis<?php echo $i; ?>" value="0" style="width:65px" /></td>
              <td>CGST(in %)</td>
              
              <td><input type="text" name="cgst<?=$i?>" id="cgst<?php echo $i; ?>" value="<?php echo $row_po_det['cgst'];?>" onkeyup="sum(<?php echo $i; ?>);" onkeypress="return isNumber(event,this);" style="width:65px" readonly="" /></td>
              <td>SGST(in %)</td>
              
              <td><input type="text" name="sgst<?=$i?>" id="sgst<?php echo $i; ?>" value="<?php echo $row_po_det['sgst'];?>" onkeyup="sum(<?php echo $i; ?>);" onkeypress="return isNumber(event,this);"   style="width:65px" readonly=""/></td>
              <td>IGST(in %)</td>
              
              <td><input type="text" name="igst<?=$i?>" id="igst<?php echo $i; ?>" value="<?php echo $row_po_det['igst'];?>" onkeyup="sum(<?php echo $i; ?>);" onkeypress="return isNumber(event,this);"   style="width:65px" readonly=""/></td>
              
              </tr>
			   <tr>
													
		<td colspan="9" align="right"><b>Total Amount</b></td>
<td></td>
										<td colspan="2" align="right" > <div class="form-group">
                                   
                                        <input type="Text" id="amount<?php echo $i; ?>" name="amount<?=$i?>" value="0" class="form-control amount" readonly="">
										<input type="hidden" id="c_amt<?php echo $i; ?>" name="c_amt<?=$i?>" value="0" class="form-control amount" readonly="">
										<input type="hidden" id="s_amt<?php echo $i; ?>" name="s_amt<?=$i?>" value="0" class="form-control amount" readonly="">
										<input type="hidden" id="i_amt<?php echo $i; ?>" name="i_amt<?=$i?>" value="0" class="form-control amount" readonly="">
                                   
                                </div></td>
								</tr>
			 <tr> <td colspan="30"><hr /></td></tr>
			  <?php
			  }
			  ?><input type="hidden" id="abc" name="abc" value="<?php echo $i; ?>" class="form-control amount" readonly="">
			  <input type="hidden" id="count" name="count" value="<?php echo $i; ?>" class="form-control amount" readonly="">
			  </tbody>
           </table>
			
</div>
<script type="text/javascript">
var i;
function sum(i) { 
	check(i);
	 var txtFirstNumberValue = document.getElementById('qty'+i+'').value;
	 var txtSecondNumberValue = document.getElementById('price'+i+'').value;
	 var txtThirdNumberValue = document.getElementById('discount'+i+'').value;
     var txtForthNumberValue = document.getElementById('cgst'+i+'').value;
     var txtFivthNumberValue = document.getElementById('sgst'+i+'').value;
     var txtSixthNumberValue = document.getElementById('igst'+i+'').value;

	 var total = parseFloat(txtFirstNumberValue)*parseFloat(txtSecondNumberValue);
	 if (!isNaN(total)) {
	 document.getElementById('amount'+i+'').value = total;
		}
	 var disc_amt = (parseFloat(total)*parseFloat(txtThirdNumberValue))/100;
	 var disc = parseFloat(total)-parseFloat(disc_amt);
	 if (!isNaN(disc)) {
	 document.getElementById('amount'+i+'').value = disc;
	 document.getElementById('dis'+i+'').value = disc_amt;
		}
	var cgst1 = (parseFloat(disc) * parseFloat(txtForthNumberValue))/100;
	 if (!isNaN(cgst1)) {
	 var tcgst = parseFloat(cgst1) + parseFloat(disc);
	 document.getElementById('amount'+i+'').value = tcgst;
		}
	var sgst1 = (parseFloat(disc) * parseFloat(txtFivthNumberValue))/100;
	 if (!isNaN(sgst1)) {
	 var tsgst = parseFloat(sgst1) + parseFloat(tcgst);
	 document.getElementById('amount'+i+'').value = tsgst;
		}
	var igst1 = (parseFloat(disc) * parseFloat(txtSixthNumberValue))/100;
	 if (!isNaN(igst1)) {
	 var tigst = parseFloat(igst1) + parseFloat(tsgst);
	 document.getElementById('amount'+i+'').value = tigst;
		}
    	

xyz(i);
	}

function xyz(i)
{
	

var k;
var sum1 =0;
var dis_tot =0;
for(k=1; k<=i; k++){
var ttotal = document.getElementById("amount"+k).value;
var tdis = document.getElementById("dis"+k).value;

sum1 = parseFloat(sum1)+parseFloat(ttotal);
dis_tot = parseFloat(dis_tot)+parseFloat(tdis);
}

document.getElementById("grand_total").value=sum1;
document.getElementById("round_off").value=Math.round(sum1);
document.getElementById("totdiscount").value=dis_tot;
}

</script>
<script type="text/javascript">
	function abcd() { 

var txtSevenNumberValue = document.getElementById("freight_chrg").value;	
var f_total  = document.getElementById("grand_total").value;
var fght = parseFloat(f_total)+parseFloat(txtSevenNumberValue);
document.getElementById("grand_total").value = fght;

var g_tot = parseFloat(fght);
document.getElementById("round_off").value = Math.round(g_tot);
}



function check(i)
{
var o_qty = document.getElementById('or_qty'+i+'').value;
	 var r_qty = document.getElementById('rcv_qty'+i+'').value;
	 var pur_qty = document.getElementById('qty'+i+'').value;
	 var rest = parseFloat(o_qty)-parseFloat(r_qty);
	 if(parseFloat(pur_qty)>parseFloat(rest)){
	 alert('please check quantity.');
	 document.getElementById('qty'+i+'').value='0';
	 }
	
}
</script>

 <script type="text/javascript">
   function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
} 
function isNumber(evt, element) {
  var charCode = (evt.which) ? evt.which : event.keyCode
  if (charCode > 31 && (charCode < 48 || charCode > 57) && !(charCode == 46 || charCode == 8))
    return false;
  else {
    var len = $(element).val().length;
    var index = $(element).val().indexOf('.');
    if (index > 0 && charCode == 46) {
      return false;
    }
    if (index > 0) {
      var CharAfterdot = (len + 1) - index;
      if (CharAfterdot > 3) {
        return false;
      }
    }

  }
  return true;
}   
</script>

     <div class="panel">
           <!--  <div class="panel-heading"><strong>Item List of Purchase </strong></div>
            <p>&nbsp;</p>
            <div align="right">
             <table id="example23" class="display nowrap table table-stripped   " cellspacing="0" width="100%">
			<thead>
                
                <?php 
				 $sql_viewtmp="select *  from tmp_purchase_details where   session_login_id = '".$_SESSION['login_id']."'";
				$res_viewtmp=mysql_query($sql_viewtmp);
				if(mysql_num_rows($res_viewtmp)>0)
				{ 
					$i=1;
					$sums=0;
					$sumdisamt=0;
					?>
                
                <tr align="left">
                  <th >Si No</th>
              <th >Item Name</th>
             
            <th >Unit Name </th>
              <th >Order Qty</th>
             
              <th >Sell Price(Per) </th>
              <th >Pur Price(Per)</th>
              <th >Total</th>
              <th >Discount</th>
              <th >CGST(%)</th>
             
              <th >SGST(%)</th>
             
              <th >IGST(%)</th>
            
              <th >Total Price</th>
              <th >Delete</th>
                </tr>
				</thead>
				 <tbody>
                <?php
				while($rows=mysql_fetch_assoc($res_viewtmp))
					{
						
						
						
						
							
							
			?>
                
                <tr>
                  <td ><?php echo $i;?></td>
             
		    <td width="40%"><?php echo $rows["item_name"];?></td>
              
            <td ><?php echo $rows["unit_name"];?></td>
              <td ><?php echo $rows["qty"];?></td>
              
              <td ><?php echo $rows["sell_price"];?></td>
              <td ><?php echo $rows["pur_price"];?></td>
              <td ><?php  $totsum=($rows["qty"]*$rows["pur_price"]); echo number_format($totsum,2);?></td>
              <td ><?php  $discount=$totsum*($rows["discount"]/100); echo number_format($discount,2); $totprice=($totsum-$discount);?></td>
              <td ><?php echo $rows["cgst"];?></td>
             <!-- <td ><?php  $cgst=$totprice*($rows["cgst"]/100); echo number_format($cgst,2);?></td>-->
              <!-- <td ><?php echo $rows["sgst"];?></td> -->
             <!-- <td ><?php  $sgst=$totprice*($rows["sgst"]/100); echo number_format($sgst,2);?></td>-->
         <!--      <td ><?php echo $rows["igst"];?></td> -->
             <!-- <td ><?php  $igst=$totprice*($rows["igst"]/100); echo number_format($igst,2);?></td>-->
              <!-- <td ><input type="text" name="tootal" id="tootal" onkeypress="return isNumber(event,this);" </td>
              <td ><button type="submit" name="del" class="btn btn-danger" value="<?=$rows["id"]?>">Delete</button></td>
              </tr>  <?php $sums=$sums+($totamt);
			  $sumdisamt=$sumdisamt+$discount;
			  $i++;} ?>   
                <tr height="32">
                  <td>&nbsp;</td>
                <td colspan="10"><div align="right"><strong>Total : </strong></div></td>
                <td><?php echo number_format($sums,2);;?>
                  <input type="hidden" name="totamt" id="totamt" value="<?php echo $sums;?>" /> <input type="hidden" name="totdiscount" id="totdiscount" value="<?php echo $sumdisamt;?>" /></td>
                <td>&nbsp;</td>
              </tr>
                <tr height="32">
                  <td>&nbsp;</td>
                <td colspan="13"><div align="right"></div></td>
				    <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr> 
                <?php }?>
				</tbody>
              </table> -->

				
	
	<table width="100%" class="table table-bordered">
	<tr>
          
            <td><div align="right"><strong>Freight Charge(in Rs) </strong></div></td>
            <td><input type="text" name="freight_chrg" id="freight_chrg" onkeyup="abcd();" onkeypress="return isNumber(event,this);"  value="0" style="width:100px; border:none; background:#FFFFFF;">
			<input type="hidden" name="totdiscount" id="totdiscount" value="0" />
			</td>
          </tr>
          <tr>
        
            <td width="80%"><div align="right"><strong>Grand Total(in Rs)</strong></div></td>
            <td width="15%"><input type="text" name="grand_total" id="grand_total"  style="width:100px; border:none; background:#FFFFFF;" readonly value="<?php echo $sums;?>"/> </td>
          </tr>
        </table>
		<table width="100%" class="table table-bordered">
		  
          <tr>
            <td width="80%"><div align="right"><strong>Round Off</strong><strong>(in Rs)</strong></div></td>
            <td width="15%"> <input type="text" name="round_off" id="round_off" style="width:100px; border:none; background:#FFFFFF;" readonly value="<?php echo round($sums);?>"/></td>
          </tr>
		  
		   <tr><td colspan="" align="right">Pay From Bank</td>
			<td colspan=""><select name="bank" id="bank"  onchange="fetch()"   class="required form-control" required>
     
      <?php 
							$sqlc="select * from tbl_bank_detail where  session_login_id = '".$_SESSION['login_id']."'";
							//echo $sqlc;
							$c=mysql_query($sqlc);
							if(mysql_num_rows($c)>0){
							while($cs=mysql_fetch_array($c))
							{?>
      <option value="<?=$cs["id"];?>" >
      <?=$cs["bank_name"];?> (AC/NO:  <?=$cs["acc_no"];?>)
      </option>
      <?php }}?>
    </select></td>
			</tr>
		  
		  
          <tr>
            <td><div align="right"><strong>Payment Mode </strong></div></td>
            <td><select name="payment_mode" id="payment_mode"  class=" form-control" onchange="showpay(this.value)">
			<option value="Cash">Cash</option>
			<option value="Cheque">Cheque</option>
			</select></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>
		<div id="showdiv" style="display:none;">
		<table width="100%" class="table table-bordered">
  <tr>
    <td>Cheque No. </td>
    
    <td><input type="text" name="cheque_no" id="cheque_no" /></td>
    <td>Cheque Date </td>
    
    <td><input type="date" name="cheque_date" id="cheque_date" /></td>
  </tr>
  <tr>
    <td>Bank Name </td>
    
    <td><input type="text" name="bank_name" id="bank_name" /></td>
    <td>Branch Name </td>
    
    <td><input type="text" name="branch_name" id="branch_name" /></td>
  </tr>
</table>
</div>
            </div>
     </div>
	
		

   
<p></p>
		<br />
        <div align="center" style="color:#990000; font-weight:bold;">
          <?php   
		     echo $mas;
		  ?>
        </div>
    <table>     
          <tr>
            <td height="35" ><input type="submit" id="Save" name="Save" value="Save" class="btn btn-primary" style="margin:inherit; width:100px"/></td>
          </tr>
    </table>

</form>       </div>
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->
	<?php include 'footer.php' ?>

    <script src="../js/lib/jquery/jquery.min.js"></script>
    <script src="../js/lib/bootstrap/js/popper.min.js"></script>
    <script src="../js/lib/bootstrap/js/bootstrap.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="../js/jquery.slimscroll.js"></script>
    <!--Menu sidebar -->
    <script src="../js/sidebarmenu.js"></script>
    <!--stickey kit -->
    <script src="../js/lib/sticky-kit-master/dist/sticky-kit.min.js"></script>
    <!--Custom JavaScript -->
    <script src="../js/custom.min.js"></script>
<script type="text/javascript">
$(function() {

  $('#bank_name').keydown(function (e) {
  
    if (e.shiftKey || e.ctrlKey || e.altKey) {
    alert("only character allow");
      e.preventDefault();
      
    } else {
    
      var key = e.keyCode;
      
      if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) {
        alert("only character allow");
        e.preventDefault();
        
      }

    }
    
  });
  
});

$(function() {

  $('#branch_name').keydown(function (e) {
  
    if (e.shiftKey || e.ctrlKey || e.altKey) {
    alert("only character allow");
      e.preventDefault();
      
    } else {
    
      var key = e.keyCode;
      
      if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) {
        alert("only character allow");
        e.preventDefault();
        
      }

    }
    
  });
  
});

</script>
  

</body>

</html>