<?php 
session_start();
ob_start(); 
include "header.php";
//$objIms->Semifinisheditem_alter();
?>
<link href="../css/select2.css" rel="stylesheet" />

<?php

if(isset($_POST["del"]))
{
	$tem_id=$_POST["del"];
	
	$del="delete from tmp_purchase_details where id=$tem_id and session_login_id = '".$_SESSION['login_id']."'";
	mysql_query($del);

}



if(isset($_POST["additems"]))
{
	$item_id=$_POST["item_id"];
	$item_nm=$_POST["item_nm"];
	$qty=$_POST["qty"];
	$unit=explode("/",$_POST["unit"]);
	$unit_id=$unit[0];
	$unit_name=$unit[1];
	$price=$_POST["price"];
	$sell_price=$_POST["sell_price"];
	
	$discount=$_POST["discount"];
	$cgst=$_POST["cgst"];
	$sgst=$_POST["sgst"];
	$igst=$_POST["igst"];
	
	
	if(($item_id>0) and ($qty>0) and ($price>0) and ($unit_id>0))
	{
	
							$sql2="insert into tmp_purchase_details(item_id,item_name,qty,pur_price,unit_id,unit_name,sell_price,discount,cgst,sgst,igst,session_login_id) values('$item_id','$item_nm','$qty','$price','$unit_id','$unit_name','$sell_price','$discount','$cgst','$sgst','$igst','".$_SESSION['login_id']."')";
				  			$final2=mysql_query($sql2);
						
						
	}
}

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"];
	$cheque_date =date('Y-m-d',strtotime($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"];
	$sql_1="select * from tmp_purchase_details where session_login_id = '".$_SESSION['login_id']."'";
	$res_1=mysql_query($sql_1);
	if((mysql_num_rows($res_1)>0))
	{
	
			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,session_login_id) values('$order_no','$order_date','$stampdate','$vendor_id','$totdiscount','$result','$round_off','$freight_charge','".$_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);
				
				
					
					while($result=mysql_fetch_array($res_1))
					{
					$item_id=$result["item_id"];
					$qty=$result["qty"];
					$pur_price=$result["pur_price"];
					$unit_id=$result["unit_id"];
					$sell_price=$result["sell_price"];
					$discount=$result["discount"];
					$cgst=$result["cgst"];
					$sgst=$result["sgst"];
					$igst=$result["igst"];
					
					$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','$stampdate', '".$_SESSION['login_id']."')";
					$res_bank=mysql_query($sql_bank);


					 $sql_insw="INSERT INTO `tbl_cheque_detail` (`account_id`, `bank_name`, `branch_name`, `checque_no`, `checque_date` , `session_login_id`) VALUES ('$accid', '$bank_name', '$branch_name', '$cheque_no', '$cheque_date', '".$_SESSION['login_id']."');";
					 
					 mysql_query($sql_insw);
					}
					}
				
				
			    
			
				$sql="delete from tmp_purchase_details where session_login_id = '".$_SESSION['login_id']."'";
				$rest=mysql_query($sql);
				
				?>
				<script type="text/javascript"> 
				alert('Success');
				</script>
				<?php
				
				 header("location:purchase_view.php?uid=".md5($lastid));	
			}
	}
	
}

?>

	 <?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...............................................................	
?>

 <style>
			select.error { background-color:#ffa8a8; border: 1px dotted red;  }
			input.error{ background-color:#ffa8a8;   }
			textarea.error{ background-color:#ffa8a8; border: 1px dotted red;  }
			
			/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
   
    z-index: 9; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 250;
    top: 0;
    width: 80%; /* Full width */
    
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
}

/* The Close Button */
.close {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}
/* The Close Button */
.close1 {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close1:hover,
.close1:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}
         </style>

		
	<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;  }
         </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>
						<hr />
<form id="form1" name="form1" method="post" action="">
<table width="100%" cellpadding="4">
  <tr>
    <td height="38" bgcolor="#FFFFFF" ><strong>Order   No</strong></td>
    <td bgcolor="#FFFFFF" ><strong>:</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"  /></td>
    <td width="20%" height="38"><strong>Supplier Name<span style="color:#F00; font-weight:bold;">*</span> </strong></td>
    <td width="2%"><strong>:</strong></td>
    <td width="31%"><p ><select name="supplier_name" id="supplier_name" style="width:200px; float: left;" onchange="sup_state()" class="required form-control">
        <option value="">---Please Select---</option>
        <?php 
							$sqlc="select * from tbl_supplier 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"];?>" <?php if(($cs["id"])==$_POST["supplier_name"]){ ?> selected="selected" <?php }?>>
        <?=$cs["supplier_name"];?>
        </option>
        <?php }}?>
    </select>
	<input type="hidden" name="state_code" id="state_code" value="<?php echo $_SESSION['state_code'];?>" readonly="" />
	<input type="hidden" name="sup_state_code" id="sup_state_code" value="<?php if(isset($_POST['sup_state_code'])) { echo  $_POST['sup_state_code']; }?>"  readonly=""/>
	<!--<button type="button" id="myBtn" style="float: left;position: relative; height: 40px" class="btn btn-sm btn-info">Add</button>--></p></td>
    </tr>
  <tr>
    <td width="7%" height="34" bgcolor="#FFFFFF" ><strong>Order Date </strong></td>
    <td width="1%" bgcolor="#FFFFFF" ><strong>:</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" /></td>
    <td><strong>Cash Type<span style="color:#F00; font-weight:bold;">*</span></strong></td>
    <td><strong>:</strong></td>
    <td><select name="pay_type" id="pay_type" style="width:200px;" class="form-control"  >
      <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>Add Item </strong></div>
           
			 <table id="example23" class="display nowrap table tbrd" cellspacing="0" width="100%">
			 <tbody>
            <tr  align="left">
            <td >Item Name&nbsp;&nbsp;</td>
            <td ><strong>:</strong></td>
            <td >
			<select name="item_nm" id="item_nm" onchange="fun()" class="form-control" style="width:150px;">
			<option value="">Select</option>
			<?php 
							$sqlitm="select * from tbl_item where session_login_id = '".$_SESSION['login_id']."'";
							//echo $sqlc;
							$citm=mysql_query($sqlitm);
							if(mysql_num_rows($citm)>0){
							while($row_itm=mysql_fetch_array($citm))
							{?>


        <option value="<?=$row_itm["item_name"];?>">
        <?=$row_itm["item_name"];?>
        </option>
        <?php }}?>
		</select>
            <input type="hidden" name="item_id" id="item_id" />
            </td>
            <td >Unit</td>
            <td ><strong>:</strong></td>
            <td ><select name="unit" id="unit" style="width:75px;" class="form-control" onchange="showadd(this.value)" >
              <option value="">Please Select</option>
              <?php 
							$sqlc="select * from tbl_unit 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["unit_name"];?>" >
              <?=$cs["unit_name"];?>
              </option>
              <?php }}?>
            </select></td>
            <td >Qty</td>
            <td ><strong>:</strong></td>
            <td ><input type="text" name="qty" id="qty" style="width:75px" onkeypress="return isNumberKey(event)"/></td>
            <td >Pur Price(Per)</td>
            <td ><strong>:</strong></td>
            <td ><input type="text" name="price" id="price" onkeypress="return isNumber(event,this);" style="width:75px" /></td>
			<td>Sell Price(Per)</td>
			<td><strong>:</strong></td>
			<td><input type="text" name="sell_price" id="sell_price" onkeypress="return isNumber(event,this);" style="width:75px" /></td>
			</tr>
            <tr height="32" align="left">
              <td>Discount(in %)</td>
              <td><strong>:</strong></td>
              <td><input type="text" name="discount" id="discount" onkeypress="return isNumber(event,this);" style="width:75px" /></td>
              <td>CGST(in %)</td>
              <td><strong>:</strong></td>
              <td><input type="text" name="cgst" id="cgst" onkeypress="return isNumber(event,this);" style="width:75px" readonly="" /></td>
              <td>SGST(in %)</td>
              <td><strong>:</strong></td>
              <td><input type="text" name="sgst" id="sgst" onkeypress="return isNumber(event,this);" style="width:75px" readonly="" /></td>
              <td>IGST(in %)</td>
              <td><strong>:</strong></td>
              <td><input type="text" name="igst" id="igst" onkeypress="return isNumber(event,this);" style="width:75px" readonly="" /></td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td><input type="submit" name="additems" id="additems" value="Add Items" class="btn btn-success" style="margin-top::0px" /></td>
              </tr>
			  </tbody>
           </table>
			
</div>
<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><?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"];?><?php  $cgst=$totprice*($rows["cgst"]/100);  number_format($cgst,2);?></td>
              <td ><?php echo $rows["sgst"];?><?php  $sgst=$totprice*($rows["sgst"]/100);  number_format($sgst,2);?></td>
              <td ><?php echo $rows["igst"];?><?php  $igst=$totprice*($rows["igst"]/100);  number_format($igst,2);?></td>
              <td ><?php   $totamt=$totprice+$cgst+$sgst+$igst; echo number_format($totamt,2);?></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" onkeypress="return isNumberKey(event)" style="width:100px; border:none; background:#FFFFFF;" onblur="calfreight(this.value)" 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"<?php if($_POST["payment_mode"]=='Cash'){?> selected="selected"<?php }?>>Cash</option>
           <option value="Cheque"<?php if($_POST["payment_mode"]=='Cheque'){?> selected="selected"<?php }?>>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><strong>:</strong></td>
    <td><input type="text" name="cheque_no" id="cheque_no" /></td>
    <td>Cheque Date </td>
    <td><strong>:</strong></td>
    <td><input type="date" name="cheque_date" id="cheque_date" /></td>
  </tr>
  <tr>
    <td>Bank Name </td>
    <td><strong>:</strong></td>
    <td><input type="text" name="bank_name" id="bank_name" /></td>
    <td>Branch Name </td>
    <td><strong>:</strong></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>
			<td>
			
</td>
          </tr>
    </table>

</form> 
	<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">&times;</span>
   <div class="card">
						
    <form method="post" id="FORMNAME2">
	<?php  echo $objIms->error;?>
	
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Supplier Name <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                 <input name="supplier_" type ="text" class="form-control" id="supplier_"  onkeypress="return AllowAlphabet(event)" maxlength="12" value="<?php echo $objIms->supplier_name?>" required="required" <?php echo $objIms->disableit;?>/>
                                        </div>
                                        </div>
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Address <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <textarea name="address" class="form-control" maxlength="50" id="address" <?php echo $objIms->disableit;?> ><?php echo $objIms->address;?></textarea>
                                            </div>
                                        </div>
										
											<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Contact No <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input name="contact_no" type ="text"  class="form-control" id="contact_no" onkeypress="return validate(event)" value="<?php echo $objIms->contact_no?>" required <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>

									<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Contact Person Name <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input type ="text" name="contact_person" class="form-control" id="contact_person" onkeypress="return AllowAlphabet(event)" maxlength="10" value="<?php echo $objIms->contact_person?>" required <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
										
									<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">GSTIN<span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                 <input name="gstin" type ="text" id="gstin" class="form-control" value="<?php echo $gstin; ?>" required="required" <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Email <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input type ="email" name="email" id="email" class="form-control" value="<?php echo $objIms->email_id?>"  <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
										
	

										 
	<div style="text-align: center;" >
		<button type="button" name="add_supplier" onclick="add_new()" class="btn btn-success m-t-15 waves-effect" >SAVE</button>
	</div>
</form>

  </div>

                                
                           
  </div>

</div>


</div>

      </div>
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->
			
     <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 src="../js/select2.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				var country = [];
				$("#item_nm").select2({
				  data: country
				});
			});
			/*function fun(){
			var item_name =$("#item_nm").val();
			$.ajax({
		type: "POST",
		url: "fetch_item.php",
		data: "item_name="+item_name,
		 dataType: 'json', 
		cache: false,
		success: function(data)
			{
				var item_id = data[0];
				
				$('#item_id').val(item_id)
				
				
				
			}
			});
   
			
			}*/
			function fun(){
			var item_name =$("#item_nm").val();
			var state_code =$("#state_code").val();
			var s_state_code =$("#sup_state_code").val();
			$.ajax({
		type: "POST",
		url: "fetch_item.php",
		data: "item_name="+item_name,
		 dataType: 'json', 
		cache: false,
		success: function(data)
			{
				var item_id = data[0];
				var cgst = data[1];
				var sgst = data[2];
				var igst = data[3];
				if(state_code == s_state_code){
				$('#cgst').val(cgst);
				$('#sgst').val(sgst);
				$('#igst').val('0');
				
				}
				if(state_code != s_state_code){
				$('#cgst').val('0');
				$('#sgst').val('0');
				$('#igst').val(igst);
				
				}
				
				$('#item_id').val(item_id);
				
				
				
			}
			});
   
			
			}
		</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>
<script>
// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal 
btn.onclick = function() {
    modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
</script>
<script>
function add_new(){

var supplier_name = $('#supplier_').val();
var contact_no = $('#contact_no').val();
var supplier_address = $('#address').val();
var contact_person = $('#contact_person').val();
var gst_no = $('#gstin').val();
var email = $('#email').val();


 $.ajax({
		type: "POST",
		url: "add_supplier_ajax.php",
		data: "supplier_name="+supplier_name+"&contact_no="+contact_no+"&supplier_address="+supplier_address+"&contact_person="+contact_person+"&gst_no="+gst_no+"&email="+email,
		 dataType: 'json', 
		cache: false,
		success: function(data)
			{
			
 modal.style.display = "none";
  var opt = data[2];
			document.getElementById("supplier_name").innerHTML=opt;

			}
			});
   
	


}

function sup_state(){
			var supplier_name =$("#supplier_name").val();
			$.ajax({
		type: "POST",
		url: "fetch_code.php",
		data: "supplier_id="+supplier_name+"&type=sup",
		 dataType: 'json', 
		cache: false,
		success: function(data)
			{
				var state = data[0];
				
				$('#sup_state_code').val(state)
				
				fun();
				
			}
			});
   
			
			}

</script>
<!-- <script>
// Get the modal
var modals = document.getElementById('myModal1');

// Get the button that opens the modal
var btn = document.getElementById("myBtn1");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close1")[0];

// When the user clicks the button, open the modal 
btn.onclick = function() {
    modals.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modals.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modals.style.display = "none";
    }
}
</script> -->
<!-- <script>
function add_items(){

var item_name = $('#item_').val();
var hsn_code = $('#hsn_code').val();


 $.ajax({
		type: "POST",
		url: "add_item_ajax.php",
		data: "item_name="+item_name+"&hsn_code="+hsn_code,
		 dataType: 'json', 
		cache: false,
		success: function(data)
			{
			
 modals.style.display = "none";
  var opt = data[2];
			document.getElementById("item_nm").innerHTML=opt;
			}
			});
   
	


}

</script> -->
</body>

</html>