<?php
@session_start();
@ob_start();

include "header.php"; 
//$objIms->bankdet_alter();
?>
<script type="text/javascript">
	$(document).ready(function() {                
				$("#FORMNAME1").validate({
                    rules: {
					
                   branch_name:"required",
				  bank_name:"required",
				  accno:"required",
					},
		messages: {
			
					 branch_name: "",
					 bank_name: "",
						accno:"",		
				},
		  });                
            });
//---auto search-----
</script>
<!-- Page wrapper  -->
        <div class="page-wrapper">
            <!-- Bread crumb -->
            <div class="row page-titles">
                <div class="col-md-5 align-self-center">
                    <h3 class="text-primary"></h3> </div>
                <div class="col-md-7 align-self-center">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="javascript:void(0)">Home</a></li>
                        <li class="breadcrumb-item active">Add Amount</li>
                    </ol>
                </div>
            </div>
            <!-- End Bread crumb -->
            <!-- Container fluid  -->
             <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row justify-content-center">
                    <div class="col-lg-6">
                        <div class="card">
						<h4>Add Amount</h4>
						<hr />
    <form method="post" id="FORMNAME1">
	<?php // echo $objIms->error;?>
	
	
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Bank <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                               <select name="bank" id="bank" 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>
                                            </div>
                                        </div>
										
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Amount <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input name="amt" type="text" style="width:200px;" class="form-control" id="amt" onkeypress="return isNumber(event,this);" required/>
                                            </div>
                                        </div>
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Date <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input name="a_date" type="date" id="a_date" class="form-control" style="width:200px;"required />
                                            </div>
                                        </div>
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Purpose <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <textarea name="remark" id="remark" class="form-control" style="width:200px;" required/></textarea>
                                            </div>
                                        </div>
										<div class="form-group row">
                                            <div class="col-lg-8 ml-auto">
                                                <input type ="submit" name="Save"  class="btn btn-info"/>
                                            </div>
                                        </div>


</form>
<?php
if(isset($_POST['Save'])){
$a_date= date('d-m-Y', strtotime($_REQUEST['a_date']));
$type = 'Added To Bank';
$aa_date = $objIms->DateToInt($a_date);

$sql_ins="INSERT INTO `tbl_account` (`bank_id`, `Dr_Amt`, `sales_type`, `remark`, `trans_date`, `session_login_id`) VALUES ('".$_POST['bank']."', '".$_POST['amt']."', '$type', '".$_POST['remark']."', '$aa_date', '".$_SESSION['login_id']."');";
				$res_ins=mysql_query($sql_ins);

 $sql_bank = "insert into tbl_bank (bankdet_id, head, debit, stampdate, session_login_id) values('".$_POST['bank']."', 'cash deposite',  '".$_POST['amt']."',  '$aa_date', '".$_SESSION['login_id']."');";
$res_bank = mysql_query($sql_bank);

$sql_cash = "insert into cash_detail(sales_type, cr_amount, stampdate, session_login_id) values('cash deposite',  '".$_POST['amt']."', '$aa_date', '".$_SESSION['login_id']."');";
$res_cash = mysql_query($sql_cash);
        ?>
				
				<script>
				alert('Success');
				</script>
				<?php
				

}
?>
</div>

                            </div>
						
                            
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->
<?php include 'footer.php' ?>
<script type="text/javascript">
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>