<?php   
$PageSecurity = 1;
include('includes/AccountGroupMaster_Class.php');
include('includes/PaginationClass.php');
$table='voucher_master';
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$msgErr='';
$status=true;
if($_REQUEST['Save'])
{
	if(empty($_REQUEST['GroupName']))
	{
	   $msgErr[]='Please Enter Group Name';
	   $status=false;
	}
	 
	 
	 	$condition="GroupName='".$_REQUEST['GroupName']."'";
		$allready=$s->GetRecord($table,  $condition);
		$row=DB_query($allready,$db);
		if(DB_num_rows($row)>0 && $action!='Edit')
		{
			 $msgErr[]='All Ready Exist';
			 $status=false;
		}
		
} 

//************************Delete*********************************************** 
if( $action=='del')
{
	$condition="VoucherType='".$_REQUEST['VoucherType']."'";
	$s->DeleteRecord($table,$condition);
	prnMsg( _('Record deleted successfully'),'success');
	$s->pageLocation('index.php?route=Voucher_Master&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
 
  
//************************Edit*********************************************** 

if(!$_REQUEST['Save'] &&  $status && $action=='Edit')
{
	$condition="VoucherType='".$_REQUEST['VoucherType']."'";
	$allready=$s->GetRecord($table,  $condition);
	$Select=DB_query($allready,$db);
	$RData=DB_fetch_array($Select);		
	$GroupName=$RData['GroupName'];
	$VPrefix=$RData['VPrefix'];
	$voucher_num=$RData['voucher_num'];
}
 

if($_REQUEST['Save'] &&  $status && $action=='Edit')
{
 $data['GroupName']=$_REQUEST['GroupName'];
 $data['VPrefix']=$_REQUEST['VPrefix'];
 $data['voucher_num']=$_REQUEST['voucher_num'];	

 $cond="VoucherType='".$_REQUEST['VoucherType']."'";
	$update= $s->EditRecord($table, $data, $cond);
	$row=DB_query($update,$db);
	if(!$row)
	{
	   die('Error'.DB_error());
	}
  prnMsg( _('Record Updated successfully'),'success');
	$s->pageLocation('index.php?route=Voucher_Master&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
 
//************************INSERT*********************************************** 
if($_REQUEST['Save'] &&  $status && $action=='')
{
 $data['GroupName']=$_REQUEST['GroupName'];
   $data['VPrefix']=$_REQUEST['VPrefix'];
  $data['voucher_num']=$_REQUEST['voucher_num'];
// $data['Predefined']=$_REQUEST['Predefined'];
	$insert= $s->insertRecord($table, $data);
	$row=DB_query($insert,$db);
	if(!$row)
	{
	   die('Error'.DB_error());
	}
prnMsg( _('Record Inserted successfully'),'success');
	$s->pageLocation('index.php?route=Voucher_Master&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
?>
<form action="" method="post">
<table width="50%" border="0" cellspacing="3" cellpadding="3">
  <tr>
    <td colspan="2"><h1>Voucher Master</h1></td>
  </tr>
  
  <?php if(isset($daction))
  {?>
    <tr>
  
    <td colspan="2" ><div class="success"><?php echo "Record ".$daction." Successfully" ?></div></td>
  </tr>
  <?php }
  if(isset($msgErr)&&$msgErr!='' )
   {?>
    <tr>
  
    <td colspan="2" ><div class="error"><?php 
for($kp=0;$kp<count($msgErr);$kp++)
 {
		echo  $msgErr[$kp].'<br>';
 }
  ?></div></td>
  </tr>
  
   <?php }?>
   
   
  <tr>
    <th width="35%"><strong>GROUP NAME </strong></th>
    <td width="65%"><input name="GroupName" type="text" size="27"  value="<?php echo $GroupName;?>"></td>
  </tr>
  <tr>
    <th><strong>VPREFIX</strong></th>
    <td><input name="VPrefix" type="text" value="<?php echo $VPrefix;?>" />	</td>
  </tr>
  
    <tr>
    <th>Voucher Numbering</th>
    <td><input name="voucher_num" type="radio" value="1" <?php echo ($voucher_num==1?'checked':'')?>  />Auto
	<input name="voucher_num" type="radio" value="2"  <?php echo  ($voucher_num==2?'checked':'')?>/>Manual	</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td> 
	
      <input type="submit" name="Save" value="Save">    </td>
  </tr>
</table>
</form>
<?php include('ViewVocuherMaster.php') ?> 
