<?php   
$PageSecurity = 1;
 $table='paymentterms';
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$msgErr='';
$status=true;
if($_REQUEST['Save'])
{
	if(empty($_REQUEST['terms']))
	{
	   $msgErr[]='Please Enter Term Code  ';
	   $status=false;
	}
	 
	 
	 	$condition="terms='".$_REQUEST['terms']."'";
		$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="termsindicator='".$_REQUEST['ID']."'";
	$s->DeleteRecord($table,$condition);
	prnMsg( _('Record deleted successfully'),'success');
	$s->pageLocation('index.php?route=PaymentTerms&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
 
  
//************************Edit*********************************************** 

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

if($_REQUEST['Save'] &&  $status && $action=='Edit')
{
 $data['terms']=$_REQUEST['terms_condition'];
 $data['terms_condition']=$_REQUEST['terms'];
 
 $cond="termsindicator='".$_REQUEST['ID']."'";
	$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=PaymentTerms&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
 
//************************INSERT*********************************************** 
if($_REQUEST['Save'] &&  $status && $action=='')
{
 $data['terms']=$_REQUEST['terms_condition'];
   $data['terms_condition']=$_REQUEST['terms'];
 // $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=PaymentTerms&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
?>
<form action="" method="post">
<table width="50%" border="0" cellspacing="3" cellpadding="3">
  <tr>
    <td colspan="2"><h1>Payment Terms</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%"> Term Code: </th>
    <td width="65%"><input name="terms" type="text" size="27"  value="<?php echo $terms_condition;?>"></td>
  </tr>
  <tr>
    <th><strong>Description</strong></th>
    <td>
	<textarea name="terms_condition" cols="30" rows="2"><?php echo $terms;?></textarea>
	
	 </td>
  </tr>
  
  
  <tr>
    <td>&nbsp;</td>
    <td> 
	
      <input type="submit" name="Save" value="Save">    </td>
  </tr>
</table>
</form>


<table width="70%" border="0" cellspacing="2" cellpadding="2">
   <tr>
     <th> ID </th>
   <!--  <th>GROUP CODE </th>-->
     <th>Terms Code</th>
     <th>Description</th>
	 
     <th>EDIT</th>
     <th>DELETE</th>
   </tr>
   <?php 
      // LIMIT $startpoint,$perpage
   $GetRecord = "Select * from $table order by termsindicator   ";
   $ResultData = DB_query($GetRecord,$db);
   $i=1;
   if(DB_num_rows($ResultData)==0)
   echo "<td>--No Record--</td>";
   
   while($RowData = DB_fetch_array($ResultData))
   {?>
 <tr align="center" bgcolor="#FFFFFF" valign="top"> 
   <td width="20%"><div align="center"><?php echo $i;//.$RowData['VoucherType']; ?></div>	  </td>
    
 	     <td width="20%"><?php echo $RowData['terms_condition']; ?></td>
  <td width="20%"><?php echo $RowData['terms']; ?></td>
   
   <td width="20%"><div align="center"><a href="index.php?route=PaymentTerms&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid']?>&action=Edit&ID=<?php echo $RowData['termsindicator']; ?>"><img src="images/icon-edit.png"  width="10" height="10"/></a></div></td>
	<td width="20%"><div align="center"><a href="index.php?route=PaymentTerms&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid']?>&action=del&ID=<?php echo $RowData['termsindicator']; ?>" onclick="return confirm('Do You Want To Delete This Record')"><img src="images/Icon_Delete.png" width="10" height="10" /></a></div></td>	
  </tr>
 
	<?php $i++;}   
   ?> 
   <tr>
 </table>
