<?php include('includes/Class_Branch.php');
include('includes/AccountGroupMaster_Class.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$rurl="&modid=".$modid."&frmid=".$frmid;
$targetpage="index.php?route=Account/ReceiptBankCheck_Issue".$rurl;
$msgErr=array();?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Receipt Bank Cheque Issue</h1>
 
 <?php  if($_REQUEST['Save'] )
 {
    
	$dataArray['ledger_id']=$_REQUEST['ledger_id'];
	$dataArray['issue_date']=FormatDateForSQL($_REQUEST['issue_date']);
	$dataArray['checkno_from']=$_REQUEST['checkno_from'];
	$dataArray['checkno_to']=$_REQUEST['checkno_to'];
	//$dataArray['status']=$_REQUEST['status'];
	if($_REQUEST['action']=='Edit')
	{
		$cond="id='".$_REQUEST['id']."'";
		$s->RecordEdit('receiptbankcheckissue', $dataArray, $cond);
	}
	else{
		$s-> RecordInsert('receiptbankcheckissue', $dataArray);
		}
 
	$s->pageLocation($targetpage."&daction=Updated");
 } 
 
 if($daction!='')
 {
   echo "<div class='success'> Record ".$daction." Successfully </div>";
 }
 ?>
 
 <form action="" method="post">
<?php 
function CategoryShow($pcode, $PcateID, $dashVal )
	{
	    global $db;
		  static $i=0;;
		 
 	       $sqlCate = "select * from accountgroupmaster  where  MainGroupId = '".$PcateID."'";
 		$rsCate  = DB_query($sqlCate,$db);	
 		if(DB_num_rows($rsCate)>0)
		{
			while($rowCate = DB_fetch_array($rsCate))
			{
  				  $arr1[]=$rowCate['GroupId'];
 				   CategoryShow($pcode,$rowCate['GroupId'], $dashVal  );
 			}
 		}
	// print_r($arr1);
			return($arr1);		
	}
	 
 $LCR=array('bank');
		$arr1=array();$arr2=array();
		//print_r($LDR);
		if($LCR!=''){
		$LRX=implode("','",$LCR);
	    $sqlCate = "select * from  accountgroupmaster  where    MainGroupId   = 0  and GroupName in('$LRX') ";
		$rsCate  = DB_query($sqlCate,$db);
		if(DB_num_rows($rsCate)>0)
		{
			while($rowCate =DB_fetch_array($rsCate))
			{
 			  	$arr1[]=$rowCate['GroupId'];
  				$arr1[]= CategoryShow($pcode, $rowCate['GroupId'], $dashVal );
 			}
		}
		$rx=array();
		for($l=0;$l<count($arr1);$l++)
		{
		// echo $arr1[$l].'<br>';
		 if(is_array($arr1[$l]))
		 $rx[]=implode(',',$arr1[$l]);
		 else
		  $rx[]=$arr1[$l];
			 
		}
		$undergroup= implode(',',$rx );
		}else{
		$undergroup='';	
		}	 
	 
	 
	 if($_REQUEST['action']=='Edit')
	 {	
	$query="select *  from receiptbankcheckissue  where id='".$_REQUEST['id']."' ";
	$result=DB_query($query,$db);
	$myrow=DB_fetch_array($result);
 	$ledger_id=$myrow['ledger_id'];
	$issue_date=$myrow['issue_date'];
	$checkno_from=$myrow['checkno_from'];
	$checkno_to=$myrow['checkno_to'];
	$status=$myrow['status']; 	 
	 }
	 
if($_REQUEST['action']=='Close')
{
	$cond3="id='".$_REQUEST['id']."'";
	$data3['status']='1';
	$s->RecordEdit('receiptbankcheckissue', $data3, $cond3);	
	$s->pageLocation($targetpage."&daction=Cloded");
}

$undergroup1="in('bank')";	 
?>
	 
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
    <td width="13%" align="right">Bank Name</td>
    <td width="35%"><select name="ledger_id" id="ledger_id" >
	<?php echo  $AccountMaster-> AccountLeger( $ledger_id,'ledger_id','ledger_id',$undergroup1); ?>	
	</select></td>
	<td width="13%" align="right">Issue Date</td>
	<td><input name="issue_date" type="text" class="datepicker"  value="<?php  echo $issue_date?>" onchange="validate_date(this.id)" onkeypress="return isNumberKey1(event)" /></td>
</tr>
<tr class="row1">
    <td align="right">Cheque No. From</td>
    <td><input name="checkno_from" type="text"  value="<?php  echo $checkno_from;?>" onkeypress="return isNumberKey(event)"  /></td>
  	<td align="right">Cheque No. To</td>
    <td><input name="checkno_to" type="text"  value="<?php  echo $checkno_to;?>" onkeypress="return isNumberKey(event)" /></td>
</tr>

<!--<tr class="row1">
    <td class="tabledata1">Status</td>
    <td colspan="4"><select name="status" id="status" style="width:150px;">
			<option value="0" <?php echo($status=='0'?'selected':''); ?>>Active</option>
			<option value="1" <?php echo($status=='1'?'selected':''); ?>>Inactive</option>
		</select>
	</td>
</tr>-->
<?php
if(isset($_REQUEST['action']))
$button="Update";	
else
$button="Save";

 ?>
<tr class="row1">
	<td style="text-align:center;" colspan="4"><input name="Save" type="submit" class="search" value="<?php echo $button; ?>" /></td>
</tr>
</table>
</form>
<br>
<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
<tr> 
	<th width="4%">S. No.</th>
	<th>Bank Name</th>
	<th width="10%">Issue Date</th>
	<th width="7%">From</th>
	<th width="7%">To</th> 
	<th width="4%" style="text-align:center;">Edit</th>
	<th width="4%" style="text-align:center;">View</th>
	<th width="4%" style="text-align:center;">Close</th>
</tr>
  <?php $j=0;
    $ResultData=DB_query("select *  from receiptbankcheckissue where 1=1 ",$db);
    while($RowData = DB_fetch_array($ResultData))
   {  if($j++%2==0)
     $bgcolor="#e4e4e4";
	 else{
	 $bgcolor="#FFFFFF";
	 }
	 ?>
   <tr bgcolor="<?php //echo $bgcolor;?>">
   <td><?php echo $j ?></td>
    <td><?php echo $s->getField('accountledger','AccountsID',$RowData['ledger_id'],'AccountName');;?> </td>
    <td><?php echo 
ConvertSQLDate($RowData['issue_date'] )?></td>
    <td><?php echo $RowData['checkno_from']; ?></td>
    <td><?php echo $RowData['checkno_to']; ?></td>
    <td class="text-center"><a href="<?php  echo $targetpage;?>&action=Edit&id=<?php echo $RowData['id']?>"><img src="images/icon-edit.png" width="15" height="15" title="Edit" /></a></td>
	 <td class="text-center"><a href="#" onclick='popup("CheckIssueDetails.php?id=<?php  echo $RowData['id'].$rurl;?>",700,450)'><img src="images/search.gif" height="15" width="15" title="View" /></a></td>
	 <td class="text-center">
	 <?php if($RowData['status']!='1'){ ?>
	 <a href="<?php  echo $targetpage;?>&action=Close&id=<?php echo $RowData['id']?>" onclick='return confirm("Are You Sure You Want To Close");'><img src="images/Icon_Delete.png" width="15" height="15" title="Delete" /></a>
	 <?php }else{?>
	 	<img src="images/Icon_Delete.png" width="15" height="15" style="opacity:0.5;" title="Closed" />
	 <?php } ?>
	 </td>
  </tr>
  <?php } ?>
</table>
</div>
</div>
<script type="text/javascript">
function validate_date(str)
	{
		 var ExpiryDate = document.getElementById(str).value;   
		 
    if (isDate(ExpiryDate)) { 
    	return true;
      }
      else{
      	alert("invalid date format");
         document.getElementById(str).value='';
         document.getElementById(str).focus='';
         return false;
         } 

	}

  function isDate(txtDate, separator) {
    var aoDate,           // needed for creating array and object
        ms,               // date in milliseconds
        month, day, year; // (integer) month, day and year
    // if separator is not defined then set '/'
    if (separator === undefined) {
        separator = '/';
    }
    // split input date to month, day and year
    aoDate = txtDate.split(separator);
    // array length should be exactly 3 (no more no less)
    if (aoDate.length !== 3) {
        return false;
    }
    // define month, day and year from array (expected format is m/d/yyyy)
    // subtraction will cast variables to integer implicitly
    month = aoDate[1] - 1; // because months in JS start from 0
    day = aoDate[0] - 0;
    year = aoDate[2] - 0;
    // test year range
    if (year < 1000 || year > 3000) {
        return false;
    }
    // convert input date to milliseconds
    ms = (new Date(year, month, day)).getTime();
    // initialize Date() object from milliseconds (reuse aoDate variable)
    aoDate = new Date();
    aoDate.setTime(ms);
    // compare input date and parts from Date() object
    // if difference exists then input date is not valid
    if (aoDate.getFullYear() !== year ||
        aoDate.getMonth() !== month ||
        aoDate.getDate() !== day) {
        return false;
    }
    // date is OK, return true
    return true;
}


function isNumberKey1(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
         // alert(charCode);
          if (charCode != 46 && charCode != 47 && charCode > 31 
            && (charCode < 47 || charCode > 57))
             return false;

          return true;
       } 

function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       } 
</script>