<?php 
$PageSecurity = 11;
$title = _('Currency Master');
include('includes/SQL_CommonFunctions.inc');
?>
<style type="text/css">
  .cap{
    text-transform:uppercase
    };
</style>
<?php 
if($_REQUEST['action']=='delete' && $_GET['id']!='')
{
	$del_sql=DB_query("Delete from currency_master_conversion where id='".$_GET['id']."'",$db);
	echo "<script>location.href='index.php?route=currency_master_conversion&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['Submit'] != '')
{
	$sql="INSERT INTO currency_master_conversion(country,currency,currency_conversion,rate,effective_date,CompanyId) VALUES('".$_REQUEST['country']."','".$_REQUEST['currency']."','".$_REQUEST['currency_conversion']."','".$_REQUEST['rate']."','".FormatDateForSQL1($_REQUEST['effective_date'])."','".$_SESSION['ACGCompanyId']."')";

	$result=DB_query($sql,$db);
	prnMsg( _('Record Inserted Successfully!'),'success');
	echo "<script>location.href='index.php?route=currency_master_conversion&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_GET['id']!='' && $_GET['action']=='edit' && !isset($_REQUEST['Update']))
{
	$get_sql=DB_query("Select * from currency_master_conversion where id='".$_GET['id']."'",$db);
	$get_row=DB_fetch_array($get_sql);
	
	$_REQUEST['country']=$get_row['country'];
	$_REQUEST['currency']=$get_row['currency'];
	$_REQUEST['currency_conversion']=$get_row['currency_conversion'];
	$_REQUEST['rate']=$get_row['rate'];
	$_REQUEST['effective_date']=$get_row['effective_date'];
}
if($_REQUEST['Update'] != '' && $_REQUEST['row_id']!='')
{
$update_sql="Update currency_master_conversion SET country='".$_REQUEST['country']."', currency='".$_REQUEST['currency']."',  currency_conversion='".$_REQUEST['currency_conversion']."', rate='".$_REQUEST['rate']."', effective_date='".FormatDateForSQL1($_REQUEST['effective_date'])."' where id='".$_REQUEST['row_id']."' ";
$update_res=DB_query($update_sql,$db);
prnMsg( _('Record Updated Successfully!'),'success');
echo "<script>location.href='index.php?route=currency_master_conversion&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?><link rel="stylesheet" href="css/new_mxerp.css">
<h2 align="center"><strong>Currency Master</strong></h2>
<form action="" method="post">
<div class="body_contain">
<div class="tab_div">
<table width="100%" border="0">
<tr class="row1">
	<td valign="top">
		<table width="100%">
  			<tr>
				<td class="tabledata1"><strong>Country</strong></td>
    			<td><label><select name="country" style="width:100%">
	  			<?php 
	  			$countrysql=DB_query("select * from country_master",$db);
	  			while($countryrow=DB_fetch_array($countrysql)){
	 			?>
	  				<option value="<?php echo $countryrow['id'];?>"<?php echo ($_REQUEST['country']==$countryrow['id']?'selected':'')?>><?php echo $countryrow['country'];?></option>
	  			<?php }?>
      			</select></label></td>
    			<td><strong>Currency</strong></td>
    			<td><input name="" type="text" value="1" size="3" readonly /><select name="currency" style="width:78%">
	  			<?php 
	  			$currencysql=DB_query("select * from currency_master",$db);
	 			 while($currencyrow=DB_fetch_array($currencysql)){
	  			?>
	  			<option value="<?php echo $currencyrow['id'];?>"<?php echo ($_REQUEST['currency']==$currencyrow['id']?'selected':'')?>><?php echo $currencyrow['currency'];?></option>
	  <?php }?>
      			</select>
				</td>
  			</tr>
		</table>
	</td>
	<td style="text-align:center"><font size="+3">=</font></td>
	<td valign="top">
		<table width="100%">
  			<tr>
  			  <td width="40%"><input name="rate" type="text" id="rate" value="<?php if($_REQUEST['rate']!=''){echo $_REQUEST['rate'];}else{echo "Enter conversion rate";}?>"  style="width:100%"class="cap"></td>
				<td><strong>Conversion Currency</strong></td>
    			<td><select name="currency_conversion" style="width:100%">
                  <?php 
	  			$currencysql1=DB_query("select * from currency_master",$db);
	  			while($currencyrow1=DB_fetch_array($currencysql1)){
	  			?>
                  <option value="<?php echo $currencyrow1['id'];?>"<?php echo ($_REQUEST['currency_conversion']==$currencyrow1['id']?'selected':'')?>><?php echo $currencyrow1['currency'];?></option>
                  <?php }?>
                </select></td>
  			</tr>
  			<tr></tr>
		</table>
	</td>
</tr>
</table></div>
</div>
<table border="0" cellspacing="1" cellpadding="2" align="center" style="border:#999999 1px solid;">
  <tr class="row1">
    <td class="tabledata1"><strong>Effective Date</strong></td>
    <td class="tabledata1">
	<input name="effective_date" type="text" id="effective_date" value="<?php if($_REQUEST['effective_date']!='')echo ConvertSQLDate($_REQUEST['effective_date']);?>" size="30" readonly class="datepicker cap"></td>
  </tr>
</table>



<p align="center">
<?php if($_GET['action']=='edit'){?>
<input type="submit" value="Update" name="Update" onclick="return validate();">
<input type="hidden" name="row_id" value="<?php echo $_GET['id'];?>" id="row_id">
<?php } else {?>
<input type="submit" value="Submit" name="Submit" onclick="return validate();">
<?php }?>
</p>
</form>
<?php 
$curr_sql=DB_query("Select * from currency_master_conversion",$db);
?>
<table width="70%" border="0" cellspacing="1" cellpadding="2" align="center">
<tr class="row1">
<td class="tabledata1" colspan="4"></td>
<td class="tabledata1"><strong>Effective Since</strong></td>
<td class="tabledata1" colspan="2"></td>
</tr>
<?php
if(DB_num_rows($curr_sql)>0){
while($curr_row=DB_fetch_array($curr_sql))
{ 
?>
<tr class="row1">
<td class="tabledata1">1&nbsp;&nbsp;<?php echo $s->getField('currency_master','id',$curr_row['currency'],'currency');?></td>
<td style="text-align:center"><font size="+2">=</font></td>
<td class="tabledata1" style="text-align:right"><?php echo $curr_row['rate'];?></td>
<td class="tabledata1"><?php echo $s->getField('currency_master','id',$curr_row['currency_conversion'],'currency');?></td>
<td class="tabledata1"><?php echo ConvertSQLDate($curr_row['effective_date']);?></td>
<td class="tabledata1"><a href="index.php?route=currency_master_conversion&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $curr_row['id'];?>&action=edit">Edit</a></td>
<td class="tabledata1"><a href="index.php?route=currency_master_conversion&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $curr_row['id'];?>&action=delete" onClick="return confirm('Are you sure you want to delete this record?')">Delete</a></td>
</tr>
<?php } }
else
{?>
<tr>
<td colspan="7"><h3 align="center"><strong><font color="#FF0000">NO RECORD FOUND!</font></strong></h3></td>
</tr>
<?php 
}?>
</table>
<script language="javascript" type="text/javascript">
function validate(){
	if(document.getElementById("effective_date").value==''){
		alert('Effective date is required');
		document.getElementById("effective_date").focus();
		return false;
	}
}
</script>