 <?php   
include('includes/AccountGroupMaster_Class.php');
$table='companies';
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$msgErr='';
$status=true;
$targetpage = "index.php?route=Setup/CompanyMaster&Application=".$_REQUEST['Application']."&modid=".$_REQUEST['modid']."";
function extension($filename)
	{
		$name_brk=explode('.',$filename);
		return  $name_brk[1];
	}
        
       
if($_REQUEST['Save'])
{
   
    $coyname=$_REQUEST['CompanyName'];
    $CompanyName =$_REQUEST['CompanyName'];
    $Identification =$_REQUEST['Identification'];
    $Address1 =$_REQUEST['Address1'];
    $Address2 =$_REQUEST['Address2'];
    $Address3 =$_REQUEST['Address3'];
    $com_type=$_REQUEST['com_type'];
      $com_process=$_REQUEST['com_process'];
      $commodity=$_REQUEST['commodity'];
      $group_id=$_REQUEST['group_id'];
    $City=$_REQUEST['City'];
    $State=$_REQUEST['State'];
    $Zipcode =$_REQUEST['Zipcode'];
    $Country =$_REQUEST['Country'];
    $Phone =$_REQUEST['Phone'];
    $Fax=$_REQUEST['Fax'];
    $email=$_REQUEST['email'];
    $website=$_REQUEST['website'];

    $Branch_Permission =$_REQUEST['Branch_Permission'];
    $HomePage=$_REQUEST['HomePage'];
    $PersonalAccountNo =$_REQUEST['PersonalAccountNo'];
    $TAN=$_REQUEST['TAN'];
    $TIN_STRegNo =$_REQUEST['TIN_STRegNo'];
    $DataBaseName =$_REQUEST['DataBaseName'];
    $BookPeriodStart =$_REQUEST['BookPeriodStart'];
    $BookPeriodEnd =$_REQUEST['BookPeriodEnd'];
    $AccountingYearStart =$_REQUEST['AccountingYearStart'];
    $AccountingYearEnd =$_REQUEST['AccountingYearEnd'];	

    if(empty($_REQUEST['CompanyName']))
    {
            unset($_SESSION['daction']);
       $msgErr[]='Please Enter CompanyName';
       $status=false;
    }
    if(empty($_REQUEST['DataBaseName']))
    {
            unset($_SESSION['daction']);
       $msgErr[]='Please Enter DataBase Name';
       $status=false;
    }
            $condition="CompanyName='".$_REQUEST['CompanyName']."' ";
            $allready=$s->GetRecord($table,  $condition);
            $row=DB_query($allready,$db);
            if(DB_num_rows($row)>0 && $action!='Edit')
            {
                     $msgErr[]='CompanyName Already Exist.Please Try Again...';
                     $status=false;
            }
		
} 

//************************Delete*********************************************** 
if( $action=='del')
{
	$condition="CompanyId='".$_REQUEST['CompanyId']."'";
	$s->DeleteRecord($table,$condition);
	 
	 $s->pageLocation($targetpage.'&daction=Deleted');

}
 
  
//************************Edit*********************************************** 

if(!$_REQUEST['Save'] &&  $status && $action=='Edit')
{
  	$condition="CompanyId='".$_REQUEST['CompanyId']."'";
	$allready=$s->GetRecord($table,  $condition);
	$Select=DB_query($allready,$db);
	$RData=DB_fetch_array($Select);		
	$CompanyName=$RData['CompanyName'];
	$Identification=$RData['Identification'];
        $com_type=$RData['com_type'];
        $com_process=$RData['com_process'];
        $commodity=$RData['commodity'];
        $group_id=$RData['group_id'];
	$Address1=$RData['Address1'];
	$Address2=$RData['Address2'];
	$Address3=$RData['Address3'];
        
	$City=$RData['City'];
	$State=$RData['State'];
	$Zipcode=$RData['Zipcode'];
	$Country=$RData['Country'];
	$Phone=$RData['Phone'];
	$Fax=$RData['fax'];
	$email=$RData['email'];
	$website=$RData['website'];
	$Branch_Permission=$RData['Branch_Permission'];
	$HomePage=$RData['HomePage'];
	$PersonalAccountNo=$RData['PersonalAccountNo'];
	$TAN=$RData['TAN'];
	$TIN_STRegNo=$RData['TIN_STRegNo'];
	$DataBaseName=$RData['DataBaseName'];
	$DataBaseName=$_SESSION['DatabaseName'] ;
	$BookPeriodStart=ConvertSQLDate($RData['BookPeriodStart']);
	$BookPeriodEnd=ConvertSQLDate($RData['BookPeriodEnd']);
	$AccountingYearStart=ConvertSQLDate($RData['AccountingYearStart']);
	$AccountingYearEnd=ConvertSQLDate($RData['AccountingYearEnd']);
    $module_allowed=$RData['modules_allowed'];
	
 }
 

if($_REQUEST['Save'] &&  $status && $action=='Edit')
{
 	
        $data['coyname'] =$_REQUEST['CompanyName'];
 	$data['CompanyName'] =$_REQUEST['CompanyName'];
	$data['Identification'] =$_REQUEST['Identification'];
        $data['com_type'] =$_REQUEST['com_type'];
        $data['com_process'] =$_REQUEST['com_process'];
        $data['commodity'] =$_REQUEST['commodity'];
         $data['group_id'] =$_REQUEST['group_id'];
	$data['Address1'] =$_REQUEST['Address1'];
	$data['Address2'] =$_REQUEST['Address2'];
	$data['Address3'] =$_REQUEST['Address3'];
	$data['City'] =$_REQUEST['City'];
	$data['State'] =$_REQUEST['State'];
	$data['Zipcode'] =$_REQUEST['Zipcode'];
	$data['Country'] =$_REQUEST['Country'];
	$data['Phone'] =$_REQUEST['Phone'];
	$data['Fax'] =$_REQUEST['Fax'];
	$data['email'] =$_REQUEST['email'];
	$data['website'] =$_REQUEST['website'];
	$data['Branch_Permission'] =$_REQUEST['Branch_Permission'];	
	$data['HomePage'] =$_REQUEST['HomePage'];
	$data['PersonalAccountNo'] =$_REQUEST['PersonalAccountNo'];
	$data['TAN'] =$_REQUEST['TAN'];
	$data['TIN_STRegNo'] =$_REQUEST['TIN_STRegNo'];
	$data['DataBaseName'] =$_REQUEST['DataBaseName'];
	$data['BookPeriodStart'] =FormatDateForSQL($_REQUEST['BookPeriodStart']);
	$data['BookPeriodEnd'] =FormatDateForSQL($_REQUEST['BookPeriodEnd']);
 	$data['AccountingYearStart'] =FormatDateForSQL($_REQUEST['AccountingYearStart']);
	$data['AccountingYearEnd'] =FormatDateForSQL($_REQUEST['AccountingYearEnd']);
	for($i=0;$i<count($_REQUEST['moduleid']);$i++)
	{
	 if($_REQUEST['moduleid'][$i]!='')
	 {
	 	$moduleid1[]=$_REQUEST['moduleid'][$i];
	 }
	}	
	
	
	$CompanyLogo=$_FILES['Logo']['name'];
	
	if($CompanyLogo!='')
	{
		$type=extension($CompanyLogo);
	   	$tmp_name=$_FILES['Logo']['tmp_name'];
		$path="Setup/CompanyLogo/".$CompanyLogo;
		$file_copy=copy($tmp_name,$path);
		
		
	if(!$file_copy)
	{
				echo "<strong>Copy Unsuccessful</strong>";
	}
		$CompanyLogo1=trim($new_name);
		$data['CompanyLogo']=$CompanyLogo;
		
	}
	

	if(count($moduleid1)>0){
	$data['modules_allowed']=implode(',',array_unique($moduleid1));
        }
	
    $cond="CompanyId='".$_REQUEST['CompanyId']."'";
 	$update= $s->EditRecord($table, $data, $cond);
	$row=DB_query($update,$db);
	if(!$row)
	{
	   die('Error'.DB_error());
	}
	
	$fycount = $_REQUEST['edityear_start'];
	for($i =0; $i<count($fycount); $i++){
		if($_REQUEST['edityear_start'][$i] !='' && $_REQUEST['edityear_end'][$i] != ''){
			$YEARDATA = array(
						'year_start'=> FormatDateForSQL($_REQUEST['edityear_start'][$i]),
						'year_end'=> FormatDateForSQL($_REQUEST['edityear_end'][$i]),
						'CompanyId'=>$_REQUEST['CompanyId'],
						'modified_by'=>$_SESSION['UserID'],
						'modified_date' => date('Y-m-d')
						);
			$update= $s->EditRecord('company_financial_years', $YEARDATA, $cond);
			$row=DB_query($update,$db);
		}
	}
	
	$fycount = $_REQUEST['year_start'];
	for($i =0; $i<count($fycount); $i++){
		if($_REQUEST['year_start'][$i] !='' && $_REQUEST['year_end'][$i] != ''){
			$YEARDATA = array(
						'year_start' => FormatDateForSQL($_REQUEST['year_start'][$i]),
						'year_end' => FormatDateForSQL($_REQUEST['year_end'][$i]),
						'CompanyId' => $_REQUEST['CompanyId'],
						'created_by' => $_SESSION['UserID'], 
						'created_date' => date('Y-m-d')
						);
			
			$insertyear =  $s->InsertRecord('company_financial_years', $YEARDATA);
			$row=DB_query($insertyear,$db);
		}
	}
  $s->pageLocation($targetpage.'&daction=Updated');
}
 
//************************INSERT*********************************************** 
if($_REQUEST['Save']  && $status  && $action=='AddNew')
{
		
	unset($_SESSION['daction']);
	
	$data['coyname'] =$_REQUEST['CompanyName'];
	$data['CompanyName'] =$_REQUEST['CompanyName'];
	$data['Identification'] =$_REQUEST['Identification'];
        $data['com_type'] =$_REQUEST['com_type'];
        $data['com_process'] =$_REQUEST['com_process'];
        $data['commodity'] =$_REQUEST['commodity'];   
        $data['group_id'] =$_REQUEST['group_id']; 
	$data['Address1'] =$_REQUEST['Address1'];
	$data['Address2'] =$_REQUEST['Address2'];
	$data['Address3'] =$_REQUEST['Address3'];
	$data['City'] =$_REQUEST['City'];
	$data['State'] =$_REQUEST['State'];
	$data['Zipcode'] =$_REQUEST['Zipcode'];
	$data['Country'] =$_REQUEST['Country'];
	$data['Phone'] =$_REQUEST['Phone'];
	$data['Fax'] =$_REQUEST['Fax'];
	$data['email'] =$_REQUEST['email'];
	$data['website'] =$_REQUEST['website'];
	$data['Branch_Permission'] =$_REQUEST['Branch_Permission'];
	$data['HomePage'] =$_REQUEST['HomePage'];
	$data['PersonalAccountNo'] =$_REQUEST['PersonalAccountNo'];
	$data['TAN'] =$_REQUEST['TAN'];
	$data['TIN_STRegNo'] =$_REQUEST['TIN_STRegNo'];
	$data['DataBaseName'] =$_REQUEST['DataBaseName'];
	$data['BookPeriodStart'] =FormatDateForSQL($_REQUEST['BookPeriodStart']);
	$data['BookPeriodEnd'] =FormatDateForSQL($_REQUEST['BookPeriodEnd']);
 	$data['AccountingYearStart'] =FormatDateForSQL($_REQUEST['AccountingYearStart']);
	$data['AccountingYearEnd'] =FormatDateForSQL($_REQUEST['AccountingYearEnd']);
	
	
	for($i=0;$i<count($_REQUEST['moduleid']);$i++)
	{
	 if($_REQUEST['moduleid'][$i]!='')
	 {
	 	$moduleid1[]=$_REQUEST['moduleid'][$i];
                
	 }
	}
      if(count($moduleid1)>0){
	$data['modules_allowed']=implode(',',array_unique($moduleid1));
      }
	
	//echo $data['modules_allowed'];
	
	
	$CompanyLogo=$_FILES['Logo']['name'];
	
	if($CompanyLogo!='')
	{
		$type=extension($CompanyLogo);
	
	   $tmp_name=$_FILES['Logo']['tmp_name'];
		$path="Setup/CompanyLogo/".$CompanyLogo;
		$file_copy=copy($tmp_name,$path);
		
		
		if(!$file_copy)
	
	{
			
				echo "<strong>Copy Unsuccessful</strong>";
 	
	}
		$CompanyLogo1=trim($new_name);
		
		
	}
	
	
	
	$data['CompanyLogo']=$CompanyLogo;
	
  print_r($data); die;
 	  $insert = $s->insertRecord($table, $data);
	
	$row=DB_query($insert,$db);
	if(!$row)
	{
	   die('Error'.DB_error());
	}

	$last_id=DB_Last_Insert_ID($db,'companies','CompanyId');
	$fycount = $_REQUEST['year_start'];
	for($i =0; $i<count($fycount); $i++){
	
		if($_REQUEST['year_start'][$i] !='' && $_REQUEST['year_end'][$i] != ''){
			$YEARDATA = array(
						'year_start' => FormatDateForSQL($_REQUEST['year_start'][$i]),
						'year_end' => FormatDateForSQL($_REQUEST['year_end'][$i]),
						'CompanyId' => $last_id,
						'created_by' => $_SESSION['UserID'], 
						'created_date' => date('Y-m-d')
						);
			
			$insertyear =  $s->InsertRecord('company_financial_years', $YEARDATA);
			$row=DB_query($insertyear,$db);
		}
	}
	$s->pageLocation($targetpage.'&daction=Inserted');
}
?>
<style type="text/css">
.mandatory{
 color:#FF0000;
}
</style>
<style type="text/css">

a{
color: #171717;
text-decoration: none;

}
a:hover{
color: #fff;

text-decoration: none;
}

#wrapper{
width:658px;
margin:auto;
}
.box{
background: #fff;

}
.boxholder{
clear: both;
padding: 5px;
border:#737373 5px solid;
padding-bottom:15px;

}
.tab{
float:left;
height:32px;
width:125px;
margin:0 1px 0 0;
text-align: center;
background:url(images/greentab.jpg) no-repeat;
}
.tabtxt{
margin: 0;
color: #fff;
font-size: 12px;
font-weight: bold;
padding: 9px 0 0 0;

}
.search {
width:auto;
padding-top:3px;
font-size:12px;
font-weight:bold;
background-color:#ddd4d4;
background-repeat: repeat-x;
padding-bottom:3px;
text-align:center;
border:#333333 solid 1px;
-moz-border-radius:3px;
/*-moz-box-shadow: 1px 2px 2px -1px #858585;*/
 }
</style>
<script type="text/javascript" src="js/prototype.lite.js"></script>
<script type="text/javascript" src="js/moo.fx.js"></script>
<script type="text/javascript" src="js/moo.fx.pack.js"></script>
<script language="javascript" type="text/javascript" src="js/basiccalendar.js"></script>

<script type="text/javascript">
function init(){
	var stretchers = document.getElementsByClassName('box');
	var toggles = document.getElementsByClassName('tab');
	var myAccordion = new fx.Accordion(
		toggles, stretchers, {opacity: false, height: true, duration: 600}
	);
	//hash functions
	var found = false;
	toggles.each(function(h3, i){
		var div = Element.find(h3, 'nextSibling');
			if (window.location.href.indexOf(h3.title) > 0) {
				myAccordion.showThisHideOpen(div);
				found = true;
			}
		});
		if (!found) myAccordion.showThisHideOpen(stretchers[0]);
}
</script>

<div class="body_contain">
<div class="">


<form action="" method="post" enctype="multipart/form-data" name="frm">
<?php
if($_REQUEST['action']=='AddNew' || $_REQUEST['action']=='Edit' && $_REQUEST['daction']=='')
{
 ?>
  <table width="100%" border="0" align="center" cellpadding="3" cellspacing="3">
  <tr>
    <td colspan="4"><h1> Company Master</h1></td>
  </tr>
  <?php 
  if(isset($_REQUEST['daction']))
  { 
	
  ?>
  <tr>
    <td colspan="4" ><div class="success"><?php echo "Record ".$_REQUEST['daction']." Successfully";
 	 
 	 ?></div></td>
  </tr>
  <?php 
 
  }
  if(isset($msgErr)&&$msgErr!='' )
   {?>
  <tr>
    <td colspan="4" ><div class="error">
        <?php 
for($kp=0;$kp<count($msgErr);$kp++)
 {
		echo  $msgErr[$kp].'<br>';
 }
  ?>
      </div></td>
  </tr>
  <?php }?>
  
  <tr>
    <td colspan="3" align="center">
	
	<div id="wrapper">
	<div id="content">
		<h3 class="tab" title="first" style="padding:0px; border:none;"><div class="tabtxt"><a href="#">COMPANY DETAILS</a></div></h3>
		<div class="tab"><h3 class="tabtxt" title="second" style="border:none;"><a href="#">ADDRESS DETAIL</a></h3></div>
		<!--<div class="tab"><h3 class="tabtxt" title="third" style="border:none;"><a href="#">COMMUNICATION</a></h3></div>-->
		<div class="tab"><h3 class="tabtxt" title="fourth" style="border:none;"><a href="#">STATUTORY DETAILS</a></h3></div>
		<div class="tab"><h3 class="tabtxt" title="fifth" style="border:none;"><a href="#">ASSIGN MODULE</a></h3></div>
		<div class="tab"><h3 class="tabtxt" title="sixth" style="border:none;"><a href="#">FINANCIAL YEARS</a></h3></div>
		<div class="boxholder">
			<div class="box">
			<table width="70%" border="1" align="center" cellpadding="2" cellspacing="0">
        <tr>
          <th width="38%" ><strong>Company Name :</strong></th>
          <td><strong>
            <input name="CompanyName" type="text" style="width:100%;"  value="<?php echo $CompanyName;?>" />
          </strong></td>
        </tr>
        <tr>
          <th><strong>Identification :</strong></th>
          <td><strong>
            <input name="Identification" type="text" style="width:100%;"  value="<?php echo $Identification;?>" />
          </strong></td>
        </tr>
       <tr>
          <th><strong>Company Logo :</strong></th>
          <td><strong>
            <input type="file" name="Logo"  style="width:100%;" readonly>
          </strong></td>
        </tr> <tr>
          <th><strong>Company Type :</strong></th>
          <td>
              <input type="radio" name="com_type" value="pr" <?php if($com_type=='pr') { echo "checked"; } ?>>Private &nbsp;&nbsp;&nbsp;
                  <input type="radio" name="com_type" <?php if($com_type=='gv') { echo "checked"; } ?> value="gv">Government&nbsp;&nbsp;&nbsp;
                  <br>
                  <input type="radio" name="com_type" <?php if($com_type=='sg') { echo "checked"; } ?> value="sg">Semi-government&nbsp;&nbsp;
                  
                  <input type="radio" name="com_type" <?php if($com_type=='ot') { echo "checked"; } ?> value="ot">Others &nbsp;&nbsp;
          </td>
        </tr> <tr>
          <th><strong>Company Process :</strong></th>
          <td><select name="com_process"  style="width:50%;">
                  <option value="">Select</option>
                  <option value="m" <?php if($com_process=='m') { echo "selected"; } ?>>Manufacturing</option>
                  <option value="t" <?php if($com_process=='t') { echo "selected"; } ?> >Trading</option>
                  <option value="d" <?php if($com_process=='d') { echo "selected"; } ?> >Distribution</option>
                  <option value="l" <?php if($com_process=='l') { echo "selected"; } ?> >Logistic</option>
                  <option value="sc" <?php if($com_process=='sc') { echo "selected"; } ?>>Supply Chain</option>
                  <option value="sp" <?php if($com_process=='sp') { echo "selected"; } ?>>Service Provider</option>
              </select>  
          </td>
        </tr> <tr>
          <th><strong>Commodity :</strong></th>
          <td><strong>
            <input type="text" name="commodity" value="<?php echo $commodity; ?>"  style="width:100%;" >
          </strong></td>
        </tr>
        <tr>
          <th><strong>Group :</strong></th>
          <td>
              <select name="group_id" id="all_group" style="width: 100px"> 
                <option>Select</option>
                <?php
               $group_sql=DB_query("select * from setup_groupmaster where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
               while($group_res=DB_fetch_assoc($group_sql))
               {
                   if($group_id==$group_res['id']){ $d="selected"; } 
                   else {$d='';}
                   echo '<option value="'.$group_res['id'].'" '.$d.' >'.$group_res['group_name'].'</option>';
               }
                ?>
            </select>
              <div class="userappear" style="float:right; padding-top:5px;">
                  <a class="pop1" style="text-decoration:none; font-size:14px; font-weight:normal; color:#b3c432; cursor:pointer; font-family:calibri; "><button value='' type='button'>Add New Group</button></a></div>
          </td>
        </tr>
      </table>
			</div>
		
			<div class="box">
			<fieldset>
      <legend> <strong>Address : </strong></legend>
      <table width="100%" border="0" cellspacing="0" cellpadding="3">
        <tr>
          <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td>Address</td>
                <td><input name="Address1" type="text" value="<?php  echo $Address1;?>" size="30"></td>
              </tr>
              <tr>
                <td></td>
                <td><input name="Address2" type="text" value="<?php  echo $Address2;?>" size="30"></td>
              </tr>
              <tr>
                <td></td>
                <td><input name="Address3" type="text" value="<?php  echo $Address3;?>" size="30"></td>
              </tr>
              <tr>
                <td>City</td>
                <td><select name="City" onchange="javascript:ajax_getstate_country(this)">
                        <option>Select</option>
                        <?php $sql=DB_query("select * from city_master",$db); 
                        while($res=DB_fetch_assoc($sql))
                        {
                            if($City==$res['id'])
                                $d='selected';
                            else
                                $d='';
                            echo '<option value="'.$res['id'].'" '.$d.'  >'.$res['city'].'</option>';
                        }
                        ?>
                    </select></td>
              </tr>
              <tr>
                <td>State</td>
                <td>
                    <input id='state' name="State" type="text" value="<?php  echo $State;?>" readonly>
                  &nbsp;Zip:
                  <input name="Zipcode" maxlength="6" type="text" value="<?php  echo $Zipcode;?>" size="10"></td>
              </tr>
              <tr>
                <td>Country</td>
                <td><input name="Country" readonly id='country' type="text" value="<?php  echo $Country;?>" size="30"></td>
              </tr>
			  <tr>
          <td>Phone</td>
          <td><input name="Phone" type="text" value="<?php  echo $Phone;?>" size="30"></td>
        </tr>
		<tr>
          <td>Fax </td>
          <td><input name="Fax" type="text" value="<?php  echo $Fax;?>" size="30"></td>
        </tr>
        <tr>
          <td>Email </td>
          <td><input name="email" type="text" value="<?php  echo $email;?>" size="30"></td>
        </tr>
        <tr>
          <td>Website </td>
          <td><input name="website" type="text" value="<?php  echo $website;?>" size="30"></td>
        </tr>
        <tr>
          <td>Home Page </td>
          <td><input name="HomePage" type="text" value="<?php  echo $HomePage;?>" size="30"></td>
        </tr>
        <tr>
          <td>Branch Permission</td>
          <td><input type="checkbox" name="Branch_Permission" value="1" <?php echo ($Branch_Permission==1?'checked':'') ?> />
             </td>
        </tr>
            </table></td>
        </tr>
      </table>
      </fieldset>
			</div>

			<!--<div class="box">
			<fieldset>
      <legend> <strong>Communication : </strong></legend>
      <table width="100%" border="0" cellspacing="5" cellpadding="3">
        <tr>
          <td>Phone</td>
          <td><input name="Phone" type="text" value="<?php  echo $Phone;?>" size="30"></td>
        </tr>
        <tr>
          <td>Fax </td>
          <td><input name="Fax" type="text" value="<?php  echo $Fax;?>" size="30"></td>
        </tr>
        <tr>
          <td>Email </td>
          <td><input name="email" type="text" value="<?php  echo $email;?>" size="30"></td>
        </tr>
        <tr>
          <td>Website </td>
          <td><input name="website" type="text" value="<?php  echo $website;?>" size="30"></td>
        </tr>
        <tr>
          <td>Home Page </td>
          <td><input name="HomePage" type="text" value="<?php  echo $HomePage;?>" size="30"></td>
        </tr>
        <tr>
          <td>Branch Permission</td>
          <td><input type="checkbox" name="Branch_Permission" value="1" <?php echo ($Branch_Permission==1?'checked':'') ?> />
             </td>
        </tr>
      </table>
      </fieldset>
			</div>-->
		
	<div class="box">
	<fieldset>
	  <legend> <strong>STATUTORY DETAILS: </strong></legend>
	  <table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
		  <td width="25%">Permanent Account No. </td>
		  <td width="35%"><input name="PersonalAccountNo" type="text" value="<?php  echo $PersonalAccountNo;?>" size="30"></td>
		  <td>TAN</td>
		  <td><input name="TAN" type="text" value="<?php  echo $TAN;?>" size="30"></td>
		</tr>
		<tr>
		  <td>TIN/S.T.Reg.No.</td>
		  <td><input name="TIN_STRegNo" type="text" value="<?php  echo $TIN_STRegNo;?>" size="30"></td>
		   <td>DataBase File Name</td>
		  <td><input name="DataBaseName" type="text" value="<?php  echo $DataBaseName;?>" size="30"></td>
		</tr>
		<tr>
		  <td>Book Period Start </td>
		  <td><input name="BookPeriodStart" type="text" value="<?php  echo $BookPeriodStart;?>" class="datepicker" size="30"></td>
		   <td>End</td>
		  <td><input name="BookPeriodEnd" type="text" value="<?php  echo $BookPeriodEnd;?>" class="datepicker" size="30"></td>
		</tr>
		<tr>
		  <td>Accounting Year Start </td>
		  <td><input name="AccountingYearStart" type="text" value="<?php  echo $AccountingYearStart;?>" size="30" class="datepicker"></td>
		   <td>End</td>
		  <td><input name="AccountingYearEnd" type="text" value="<?php  echo $AccountingYearEnd;?>" class="datepicker" size="30"></td>
		</tr>
		</table>
		</fieldset>
	</div>
			
			<div class="box">
			<fieldset>
  <legend> <strong>Module Assign </strong></legend>
			
			<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
 <tbody>
	
<tr>
	<td colspan="3">&nbsp;</td>
</tr>

  <tr>
  	<td valign="top" width="252">
	<fieldset><legend>forms</legend>
	
	<table style="margin-top:2px;" align="center" border="0" cellpadding="0" cellspacing="0" height="170" width="225">
	<tbody><tr><td width="225">
	<div style="height:170px; overflow:auto;">
			<div id="roleassign">
			<?php 
			$query1=DB_query("SELECT * FROM modules",$db);
	
   ?>
        <input type="checkbox" name="assigned" id="assigned_site" value="0" onclick="FProfileMaster(document.frm.frmnamerole)">All<br />
            <table  align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
<?php 
$i=1;
while($row=DB_fetch_array($query1))
{
?>
<tr><td><input type="checkbox" name="frmnamerole[]" id="frmname_<?php echo $i; ?>" value="<?php echo $row['id']; ?>" >	
<input type="hidden" name="form_name[]" id="form_name_<?php echo $i; ?>" value="<?php echo $row['modulename']; ?> " /></td>
<td><?php  echo $row['modulename'];?></td>
</tr>
<?php $i++; } ?></table>
			
			
			</div>
			
		</div></td></tr>  
		<tr>
			<td><div align="right"><input name="button" type="button" class="buttonsview" value=">>" onclick="swapdata()" /></div></td>
		</tr>    		
    </tbody></table>
	
	</fieldset>
	
	</td>
	
    <td width="364" valign="top">
    	<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
    		<tbody><tr>
    			<td>    				
    			</td>
    		</tr>
    	</tbody></table>
	<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
		 <tbody><tr>
		<td width="6%" height="25">&nbsp;</td>
		<td class="paddfeildbold" width="30%"><strong>Module</strong></td>
		<td class="paddfeildbold" width="30%"><strong>Module Identification No</strong></td>
		</tr>
	  	<tr>
	  <td colspan="4">
		<div style="height:270px; overflow:auto; ">
		<table align="center" border="0" cellpadding="1" cellspacing="0" width="100%">
			
			 
	  <tbody>
		<?php 		
		if($_REQUEST['action']=='Edit' && $_REQUEST['CompanyId']!='')
		{
			$k=1;
			if($module_allowed!='')
			{
			$sql2=DB_query("select * from modules where id in(".$module_allowed.") ",$db);
			while($row2=DB_fetch_array($sql2))
			{	
						
			?>
			<tr bgcolor="#CCCCCC">
		<td><input name="assign[<?php echo $k; ?>]" checked="checked" type="checkbox" id="assign_<?php echo $k; ?>"></td>
		<td><input name="modulename[<?php echo $k; ?>]" style="width:150px;" class="whitebox" readonly="readonly" value="<?php echo $row2['modulename'];?>" type="text" id="modulename_<?php echo $k; ?>" /></td>
		<td>
			<input type="text" name="moduleid[<?php echo $k; ?>]" id="moduleid_<?php echo $k; ?>" value="<?php echo $row2['id'];?>"  readonly="readonly" style="width:150px;"/></td>	
	 			</tr>	
		
			<?php 	
			$k++;}
		} }
		?>
		<?php 
		
		$form_count=DB_fetch_array(DB_query("SELECT COUNT(*) as formcount FROM `modules`WHERE STATUS='Y'",$db));
		$form_count_no=$form_count['formcount'];
		if($_REQUEST['action']=='Edit' && $_REQUEST['CompanyId']!='')
		{$counter=$k; $limit=$form_count_no-$k+1;}else{$counter=1;  $limit=$form_count_no;}
		for($i=$counter;$i<=70;$i++)
		{ ?>
		<tr bgcolor="#CCCCCC">
		<td><input name="assign[<?php echo $i; ?>]" checked="checked" type="checkbox" id="assign_<?php echo $i; ?>" onclick="select_all(<?php echo $i?>)" ></td>
		<td><input name="modulename[<?php echo $i; ?>]" style="width:150px;" class="whitebox" readonly="readonly"  type="text" id="modulename_<?php echo $i; ?>" />
			</td>	
	 	<td><input type="text" name="moduleid[<?php echo $i; ?>]" id="moduleid_<?php echo $i; ?>" value="" 
		style="width:150px;" readonly="readonly"/></td>
		</tr>
		<tr style="height:5px"><td></td></tr>
		<?php } ?>
				
		
		
	  	 </tbody>
		 
		 </table>
		</div>	</td>
	</tr>
		
		
</tbody></table>
</td>
  </tr>  
</tbody></table>
</fieldset>
</div>
<div class="box">
	<fieldset>
	  <legend> <strong>Financial Years: </strong></legend>
	  <table width="50%" align="center" border="0" cellpadding="2" cellspacing="1" style="border: solid 1px #999999;">
			<tr>
			<td><input type="button" value="Add" class="search" onclick="addRow('financialTable')"/></td>
			<td><input type="button" class="search"   onclick="deleteRowOrder('financialTable')" value="Delete" />
			<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />			</td>
			</tr>
			<tr>
			<th></th>
			<th><strong>From</strong></th>
			<th><strong>To</strong></th>
			</tr>
			<tbody id="financialTable">
			<tr>
    		<td><input name="delitem[]" type="checkbox"  id="delitem" /></td>
			<td><input name="year_start[]" id="year_start" type="text" onClick="buildCal('3',, "main", "month", "daysofweek", "days", 1))" style="width:100%;" class="datepicker"/></td>
	   		<td><input name="year_end[]" id="year_end" type="text" style="width:100%;" onClick="javascript:NewCal(this.id,'ddmmyyyy')"/></td>
			</tr>
			</tbody>
		</table>
			<br />
<br />
<?php if($_REQUEST['CompanyId'] !=''){?>
<table width="100%" border="1" cellspacing="1" cellpadding="2">
  <tr>
    <th width="10%"><strong>Srl. No.</strong></th>
    <th width="40%"><strong>From</strong></th>
    <th width="43%"><strong>To</strong></th>
	<th width="7%"></th>
  </tr>
  <span id="show_financial_years">
  <?php 
  		$k = 1;
		$fy_sql=DB_query("Select * from company_financial_years where CompanyId='".$_REQUEST['CompanyId']."'",$db);
		while($fy_row=DB_fetch_array($fy_sql))
		{
  ?>
  <tr id="fyear_<?php echo $fy_row['id']; ?>">
    <td><?php echo $k; ?></td>
    <td><?php echo date('d/m/Y',strtotime($fy_row['year_start'])); ?></td>
    <td><?php echo date('d/m/Y',strtotime($fy_row['year_end'])); ?></td>
	<td><a href="#" onclick="edit_year('<?php echo $fy_row['id'];?>','yes');"><img src="images/icon_edit.gif" alt="edit" title="edit" /></a></td>
</tr>
<tr id="editfyear_<?php echo $fy_row['id']; ?>" style="display:none">
    <td><?php echo $k; ?><input type="hidden" name="edityearid[]" id="edityearid<?php echo $fy_row['id']; ?>" value="<?php echo $fy_row['id']; ?>" /></td>
	
	<td width="40%">
		<input name="edityear_start[]" id="edityear_start_<?php echo $fy_row['id']; ?>" type="text" style="width:100%;" onClick="javascript:NewCal(this.id,'ddmmyyyy')" value="<?php echo date('d/m/Y',strtotime($fy_row['year_start'])); ?>" />	</td>
	
	<td width="43%"><input name="edityear_end[]" id="edityear_end_<?php echo $fy_row['id']; ?>" type="text" style="width:100%;" onClick="javascript:NewCal(this.id,'ddmmyyyy')" value="<?php echo date('d/m/Y',strtotime($fy_row['year_end'])); ?>" /></td>
	
	<td><a href="#" onclick="edit_year('<?php echo $fy_row['id'];?>','no');"><img src="images/delete_1.gif" alt="cancel" title="cancel" /></a></td>
</tr>
<?php
$k++;		}
?>
	</span>
</table>

<?php } ?>
	</fieldset>
</div>

		
		</div>
		
	<div style="clear:both;"></div>
	</div>
</div>
  <script type="text/javascript">
	Element.cleanWhitespace('content');
	init();
</script>
	
	</td>
    </tr>
  
  
  
    
    <tr>
      <td colspan="3"><div align="center"><input type="submit" name="Save" value="<?php echo ($action=='Edit'?"Update":"Save") ?>" /></div></td>
    </tr>
  </table>


<?php } ?>
</form>
<p align="left"><a href="index.php?route=Setup/CompanyMaster&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=AddNew"><input type="button" Value="AddNew" class="search" style="margin-bottom:10px;" /></a>

<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" style="border:#999999 solid 1px;">
  <tr>
    <th scope="col">Company Id</th>
    <th scope="col">Company Name</th>
    <th scope="col">Identification</th>
    <th scope="col">DataBase Name</th>
    <th scope="col">email</th>
    <th scope="col">Edit</th>
    <th scope="col">Delete</th>
  </tr>
  <tr bgcolor="#FFFFFF">
    <?php 
   $GetRecord = "Select * from companies ";
   $ResultData = DB_query($GetRecord,$db);
   $i=1;
   if(DB_num_rows($ResultData)==0)
   echo "<td colspan='3'>--No Record--</td>";
   
   while($RowData = DB_fetch_array($ResultData))
   {?>
    <td bgcolor="#FFFFFF"><div align="center"><?php echo $RowData['CompanyId']; ?></div></td>
    <td bgcolor="#FFFFFF"><?php echo $RowData['CompanyName']; ?> </td>
    <td bgcolor="#FFFFFF"><?php echo $RowData['Identification']; ?> </td>
    <td bgcolor="#FFFFFF"><?php echo $RowData['DataBaseName'];
	  ?> </td>
    <td bgcolor="#FFFFFF"><?php echo $RowData['email']; ?> </td>
    <td bgcolor="#FFFFFF"><div align="center"><a href="<?php echo $targetpage;?>&action=Edit&CompanyId=<?php echo $RowData['CompanyId']; ?>"><img src="images/icon_edit.gif"  width="10" height="10"/></a></div></td>
    <td bgcolor="#FFFFFF"><div align="center"><a href="<?php echo $targetpage;?>&action=del&CompanyId=<?php echo $RowData['CompanyId']; ?>"><img src="images/Icon_Delete.png" width="10" height="10" /></a></div></td>
  </tr>
  <?php $i++;}   
   ?>
</table>
</div></div>

<script>
function FProfileMaster(str)
{

   myCheckboxArray = document.frm.elements["frmnamerole[]"];
	var t=myCheckboxArray.length;
	
	if(document.getElementById('assigned_site').checked==true)
	{	
	
	if(t==undefined)	
	document.getElementById('frmname_'+1).checked=true;
	for (var i = 1; i <=t; i++)
	{
	document.getElementById('frmname_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)	
	document.getElementById('frmname_'+1).checked=false;
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('frmname_'+i).checked=false;	
	}
	}
	

	
}
function swapdata()
{
myCheckboxArray = document.frm.elements["frmnamerole[]"];
var t=myCheckboxArray.length;
//alert(t);
if(t!=undefined)
{
	for(var i=1;i<=t;i++)
	{
		if(document.getElementById("frmname_"+i).checked==true)
		{
			for(var k=1;k<=100;k++)
			{
				if(document.getElementById("moduleid_"+k).value==document.getElementById("frmname_"+i).value)
				{
					alert(document.getElementById("form_name_"+i).value+" already exists in the list");
					break;
				}
				else
				{
					if(document.getElementById("modulename_"+k).value=='' )
					{
							
						document.getElementById("modulename_"+k).value=document.getElementById("form_name_"+i).value;
						document.getElementById("moduleid_"+k).value=document.getElementById("frmname_"+i).value;
						
						break;
					}
					else
					{
						continue;
					}
				} 
			}
		}
	}

}
else
{
		if(document.getElementById("frmname_"+i).checked==true)
		{
			for(var k=1;k<=100;k++)
			{
				if(document.getElementById("moduleid_"+k).value==document.getElementById("frmname_"+i).value)
				{
					alert(document.getElementById("form_name_"+i).value+" already exists in the list");
					break;
				}
				else
				{
					if(document.getElementById("modulename_"+k).value=='' )
					{
						
						document.getElementById("modulename_"+k).value=document.getElementById("form_name_"+i).value;
						document.getElementById("moduleid_"+k).value=document.getElementById("frmname_"+i).value;
						
									
						break;
					}
					else
					{
						continue;
					}
				} 
			}
		}
	}
}

function deleteRowOrder(tableID) 
{
	try 
	{
	var table = document.getElementById(tableID);
	//alert(table);
	var rowCount = table.rows.length;
	//alert(rowCount);
	for(var i=0; i<rowCount; i++) 
	{
	var row = table.rows[i];
	var chkbox = row.cells[0].childNodes[0];
	if(null != chkbox && true == chkbox.checked) 
	{
	if(rowCount <= 1) 
	{
	alert("Cannot delete all the rows.");
	break;
	}
	table.deleteRow(i);
	rowCount--;
	i--;
	}
	}
	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		}
	catch(e) 
	{
	alert(e);
	}
}

function edit_year(yrsid,showVal){
	if(showVal=='yes'){
		document.getElementById('fyear_'+yrsid).style.display ='none';
		document.getElementById('editfyear_'+yrsid).style.display ='';
	
	}else{
		document.getElementById('fyear_'+yrsid).style.display='';
		document.getElementById('editfyear_'+yrsid).style.display='none';
	}
}

function ajax_getstate_country(str)
{
if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var data=xmlhttp.responseText.split("__");
                
		document.getElementById("state").value=data[0];
		document.getElementById("country").value=data[1];
	}
	}
        
	xmlhttp.open("POST","ajax_getstate_country.php?city="+str.value,true);
	xmlhttp.send();
}
//alert("fdfd");
function xyz()
{
    
window.opener.document.getElementById("form_add").reset();
}
function ajax_get_group_data()
{
  var val=document.getElementById("group_name").value;
   var code=document.getElementById("group_code").value;
   var flag=0;
   if(val=='')
       {
           alert('Please Enter Group name'); 
           flag=1;
          
       }
    if(code=='')
        {
             alert('Please Enter Group code'); 
             var flag=1;
            
        }
        if(flag==0){
        if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            
            document.getElementById("all_group").innerHTML=xmlhttp.responseText;
            //document.getElementById("pop1").style.display='none';
            disablePopup2();
            
            }
	}
        var group_code=document.getElementById("group_code").value;
        var group_name=document.getElementById("group_name").value;
     
        xmlhttp.open("POST","ajax_get_group_data.php?group_name="+group_name+"&group_code="+group_code,true);
	xmlhttp.send();
        }
}
function disablePopup2() {
    $("#pop1").fadeOut("normal");  
    $("#backgroundPopup1").fadeOut("normal");
    document.getElementById("form_add").reset();		
}

</script>

<div id="pop1"> 
    	
        <div class="close1"></div>
       	<span class="ecs_tooltip">Press Esc to close <span class="arrow"></span></span>
		<div id="popup_content1"> <!--your content start-->
           <?php include('./Setup/GroupMaster.php');?>
        </div> <!--your content end-->
    
    </div> <!--toPopup end-->
    
	<div class="loader"></div>
   	<div id="backgroundPopup1"></div>