0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 13.59.217.1


Current Path : /proc/thread-self/root/var/www/html/mcu/custom_src/
Upload File :
Current File : //proc/thread-self/root/var/www/html/mcu/custom_src/report_setup.php

<?php
function getEmployeeConditionfileds($aobj_context)
{
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 

	$get_emp_fileds="select sus.internal_code,name as ele_name from 
									s_user_schema_elements  sus
									inner join s_user_schema s on s.internal_code=sus.ref_s_user_schema_code
									where module_name='Employee' order by sus.sequence,sus.internal_code";  	
	$lobj_details_emp_fileds = $aobj_context->mobj_db->getAll($get_emp_fileds);
	
	$arr['fields']=$lobj_details_emp_fileds;
	$get_operator="select internal_code,operator from operators"; 
	$lobj_details_operator = $aobj_context->mobj_db->getAll($get_operator);  				
	$arr['oper']=$lobj_details_operator;
	if($lobj_details_emp_fileds)
   {	
	 echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
	return;
   }
}
 
function getSearchedEmployeeFields($aobj_context,$value) 
{

require_once($aobj_context->main_src."/custom_src/employeeClass.php");

$emp_obj=new employeeClass($aobj_context);
$emp_obj->employee();
 
	if(!empty($value))
	{
		$get_data="select internal_code,
						concat({$emp_obj->employee_name},'-',{$emp_obj->employee_code}) as emp_code
						from {$emp_obj->employee_table} where 
						{$emp_obj->employee_name} like '{$value}%' order by  {$emp_obj->employee_name} limit 15 ";
		$obj_get_employee_fields = $aobj_context->mobj_db->GetAll($get_data);
		if(empty($obj_get_employee_fields))
		{	
		$get_data="select internal_code,
						concat({$emp_obj->employee_code},'-',{$emp_obj->employee_name}) as emp_code
						from {$emp_obj->employee_table} where 
						{$emp_obj->employee_code} like '{$value}%' order by  {$emp_obj->employee_code} limit 15";
		$obj_get_employee_fields = $aobj_context->mobj_db->GetAll($get_data);
		}
		 
	}	 
	else
	{
	  $get_data="select internal_code,
						concat({$emp_obj->employee_code},'-',{$emp_obj->employee_name}) as emp_code
						from {$emp_obj->employee_table}  order by  {$emp_obj->employee_code} limit 15";
		$obj_get_employee_fields = $aobj_context->mobj_db->GetAll($get_data);
	}
	return $obj_get_employee_fields ;
}

function getReportEmpDetailsCriteria($aobj_context)
{
	$value=trim($aobj_context->mobj_data["value"]);
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	$obj_get_employee_fields=getSearchedEmployeeFields($aobj_context,$value);

	$str_emp="<table   width='50%' align='right' border='0' cellpadding='' cellspacing=''>";
	$str_emp.="<tr>";
	$str_emp.="<td style='width:180px;'>";
	$str_emp.="<div id='report_setup_employee_div' style='padding:2px;overflow-y:scroll;overflow-y:auto;width:260px;height:250px;border:1px solid #cccccc;'>";

		for($mdata = 0 ; $mdata < count($obj_get_employee_fields) ; $mdata++)
		{     
		$field_data_id =  $obj_get_employee_fields[$mdata][emp_code];

		$internal_code = $obj_get_employee_fields[$mdata][internal_code];
		$str_emp.="<input type='checkbox' id = 'emp_sal_process_int_code_$internal_code' name='{$internal_code}' /><label for='checkOption1'>{$field_data_id}</label><br />";
		}
	   $str_emp.="</div></td>";
		$str_emp.="</tr></table>";	
		
		$arr['emp_html']=$str_emp;
		$arr['emp_table_data']=$obj_get_employee_fields;		
		
		echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"Success");	
  }	
  
  function 	getReportEnableCriteria($aobj_context)
    {
		$value=trim($aobj_context->mobj_data["value"]);
		$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
		$obj_get_employee_fields=getSearchedEmployeeFields($aobj_context,$value);
	
		$get_details="(select   su.internal_code,name as module_name ,ref_module_code,s.internal_code as schema_id  from
			s_user_schema s inner join s_user_schema_elements su on 
			su.ref_s_user_schema_code=s.internal_code
			inner join s_ref_type t on t.internal_code=su.s_ref_type_meta
			inner join s_ref_type t1 on t1.internal_code=su.data_type
			where  module_name='Employee' and is_multiple_group=0
			and ((
			t1.value in('List Of Values','Reference Data')) or (t.value='meta' and is_unique=1))) ";
			$lobj_details = $aobj_context->mobj_db->getAll($get_details);  
			//echo $get_details;
			$criteria_table="<div><table  width='100%' align='left' border='0' cellspacing='1' cellpadding='1'>"; 
			foreach($lobj_details as $key=>$val)			
			{
					    
			    $criteria_table.="<tr>";
				$criteria_table.="<tr><td align='right'>{$val[module_name]}:</td>";				
			    $criteria_table.="<td align='left'><div id='input_div_emp_report_criteria' class='imageInputDateMonth' style='float:left;width:162px;'>";
				$criteria_table.="<input  style='border:0px solid #c8c8c8; width:138px; height:16px;' class='inputWithImge ElementCount' id='emp_report_criteria_{$val[internal_code]}' name='emp_report_criteria_{$val[internal_code]}' type='text' style='width:137px;' value=''/>";		
				$criteria_table.="<a href='javascript:;'  style='text-decoration:none' id='pop_up_emp_report_criteria'>";
				$criteria_table.="<img  src='images/search-glass.gif' class='img' border = '0'  onclick=ReportSetupPopupDetails('{$val[internal_code]}')></a>"; 
				$criteria_table.="<input type='hidden' id='hidden_employee_salary_process_module_code' /><input type='hidden' id='hidden_employee_salary_process_int_code' />";  
				$criteria_table.="</td></tr>";  		
			}	
			
			$criteria_table.="</table></div>";
			$arr['criteria_html']=$criteria_table;			
			$arr['criteria_table_data']=$lobj_details;
			echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success"); 
	}

function getReportEnableEmployeeFields($aobj_context)
{
	 
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
	$internal_code=$aobj_context->mobj_data["internal_code"];
	$e_data_header="<table align='center' cellspacing='0' cellpadding='0' border='0' width='97%'>";
	$e_data_header.="<th align='left' colspan='7' class='ui-jqgrid-titlebar ui-widget-header ui-corner-tl ui-corner-tr ui-helper' style='font-size:12px; padding-left:6px; height:24px;'>Employee Fields</th>";	
	$e_data_header.="<tr class='ui-state-default ui-jqgrid-hdiv'></tr>";
	$e_data_header.="<td align=center style='padding:2px; width:58px; border-left:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Col Seq</td>";
	$e_data_header.="<td align=center style='padding:2px; width:88px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Fields</td>";
	$e_data_header.="<td align=center style='padding:2px; width:55px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Select<input style='width'type=checkbox id='select_emp_fields' onclick='selectAllEmpFields();'></td>";
	$e_data_header.="<td align=center style='padding:2px; width:48px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Group By</td>";
	$e_data_header.="<td align=center style='padding:2px; width:58px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Order By</td>";
	$e_data_header.="<td align=center style='padding:2px; width:88px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Order Type</td>";
	$e_data_header.="<td align=center style='padding:2px; width:60px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Order Seq</td>";
	$e_data_header.="</tr>";
	$get_emp_fields=" select internal_code,name,
						ifnull(column_seq,1) as column_seq,
						ifnull(is_selected,0) as is_selected,
						ifnull(is_group_by,0) as is_group_by,
						ifnull(is_order_by,0) as is_order_by,
						ifnull(order_type,'asc') as order_type,
						ifnull(order_by_seq,1) as order_by_seq
						from (select sus.internal_code,name from 
						s_user_schema_elements  sus
						inner join s_user_schema s on s.internal_code=sus.ref_s_user_schema_code
						where module_name='Employee' order by sus.sequence) a
						left join (select ref_emp_field_code,
						column_seq,
						is_selected,
						is_group_by,
						is_order_by,
						order_type,
						order_by_seq from report_header rh inner join report_detail_emp_columns rde
						on rde.ref_report_header_code=rh.internal_code
						where rh.internal_code={$internal_code}) b on a.internal_code=b.ref_emp_field_code";
	$lobj_get_emp_fields = $aobj_context->mobj_db->getAll($get_emp_fields);
	$k=0;
	foreach($lobj_get_emp_fields as $key=>$val)
		{
			$ass_cheked='';
			$des_cheked='';
			if($k%2==0)
				$class='tbl_row';
				else
				$class='tbl_row1';  
			$emp_col_seq=($val['column_seq']==1)?($k+1):$val['column_seq'];
			$emp_is_selected=($val['is_selected']==1)?'checked':'';
			$emp_is_grouped=($val['is_group_by']==1)?'checked':'';
			$emp_is_ordered=($val['is_order_by']==1)?'checked':'';
			if($val['order_type']=='asc')
			$ass_cheked=' checked=checked ';
			else 
			$des_cheked=' checked=checked ';
			$emp_order_seq=$val['order_by_seq'];
			 $e_data.="<tr class='ui-widget-content jqgrow'>";
			 $e_data.="<td  class='tbl_row_new' align=center style='border-left:1px solid #C5DBEC; border-right:1px solid #C5DBEC;  padding:2px;'><input type=text style='border:1px solid #C5DBEC; width:50px;' value= ".$emp_col_seq." id='report_emp_col_seq_{$val[internal_code]}'> </td>";
			 $e_data.="<td  class='tbl_row_new' style='border-right:1px solid #C5DBEC; padding:2px;' id='report_emp_col_name_{$val[internal_code]}'>{$val[name]}</td>";
			 $e_data.="<td  class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC; padding:2px;'><input type=checkbox {$emp_is_selected} id='report_emp_select_{$val[internal_code]}'> </td>";
			 $e_data.="<td  class='tbl_row_new' align=center style=' border-right:1px solid #C5DBEC;  padding:2px;'><input type=checkbox {$emp_is_grouped} id='report_emp_group_by_{$val[internal_code]}'> </td>";
			 $e_data.="<td  class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;'><input type=checkbox {$emp_is_ordered} id='report_emp_order_by_{$val[internal_code]}'> </td>";
			 $e_data.="<td  class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;'>Asc:<input type=radio name=radio_report_{$val[internal_code]}   {$ass_cheked} id='report_emp_order_type_asc_{$val[internal_code]}'> Desc:<input name=radio_report_{$val[internal_code]} {$des_cheked} type=radio id='report_emp_order_type_des_{$val[internal_code]}'></td>";
			 $e_data.="<td  class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;'><input style='width:50px; border:1px solid #C5DBEC;'type=text value={$emp_order_seq} id='report_emp_order_seq_{$val[internal_code]}'> </td>";
				$e_data.="</tr>";
			 $k++;	
		}	
	$arr['html']=$e_data_header.$e_data."</table>";
	$arr['table_data']=$lobj_get_emp_fields;
	echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
}
function getReportEnableSalFields($aobj_context)
{
	 require_once($aobj_context->main_src."/custom_src/salcompclass.php");
	$check_type_obj=new SalCompClass($aobj_context);
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
	$internal_code=$aobj_context->mobj_data["internal_code"];
	
	$earn_sal_data="<table align='left' cellspacing='0' cellpadding='0' border='0' width='48%'>";
	$earn_sal_data.="<th align='left' colspan='7' class='ui-jqgrid-titlebar ui-widget-header ui-corner-tl ui-corner-tr ui-helper' style='font-size:12px; padding-left:6px; height:24px;'>Earnings</th>";		
	$earn_sal_data.="<tr class='ui-state-default ui-jqgrid-hdiv'></tr>";
	$earn_sal_data.="<td align=center style='padding:2px; width:20px; border-left:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Col Seq</td>";
	$earn_sal_data.="<td align=center style='padding:2px; width:120px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Fields</td>";
	$earn_sal_data.="<td align=center style='padding:2px; width:25px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Select<input type=checkbox id='select_sal_fields' onclick='selectAllSalFields();'></td>";
	$earn_sal_data.="<td align=center style='padding:2px; width:50px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;display:none;' >Order By</td>";
	$earn_sal_data.="<td align=center style='padding:2px; width:50px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;display:none;'>Order Type</td>";
	$earn_sal_data.="<td align=center style='padding:2px; width:58px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;display:none;'>Order Seq</td>";
	$earn_sal_data.="<td align=center style='padding:2px; width:25px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Sum Into</td>";
	$earn_sal_data.="</tr>";
	
	$ded_sal_data="<table align='left' cellspacing='0' cellpadding='0' border='0' width='48%'>";
	$ded_sal_data.="<th align='left' colspan='7' class='ui-jqgrid-titlebar ui-widget-header ui-corner-tl ui-corner-tr ui-helper' style='font-size:12px; padding-left:6px; height:24px;'>Deductions</th>";		
	$ded_sal_data.="<tr class='ui-state-default ui-jqgrid-hdiv'></tr>";
	$ded_sal_data.="<td align=center style='padding:2px; width:20px; border-left:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Col Seq</td>";
	$ded_sal_data.="<td align=center style='padding:2px; width:120px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Fields</td>";
	$ded_sal_data.="<td align=center style='padding:2px; width:25px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Select<input type=checkbox id='select_sal_fields' onclick='selectAllSalFields();'></td>";
	$ded_sal_data.="<td align=center style='padding:2px; width:508px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;display:none;' >Order By</td>";
	$ded_sal_data.="<td align=center style='padding:2px; width:50px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;display:none;'>Order Type</td>";
	$ded_sal_data.="<td align=center style='padding:2px; width:58px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;display:none;'>Order Seq</td>";
	$ded_sal_data.="<td align=center style='padding:2px; width:25px; border-bottom:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>Sum Into</td>";
	$ded_sal_data.="</tr>";

	
	$obj_mapping="select internal_code,component,
						ifnull(column_seq,1) as column_seq,
						ifnull(is_selected,0) as is_selected,
						ifnull(is_order_by,0) as is_order_by,
						ifnull(order_type,'asc') as order_type,
						ifnull(order_by_seq,1) as order_by_seq,
						ifnull(sum_into,' ') as sum_into,type 
						from  
						(select c.internal_code  ,
						{$check_type_obj->salary_comp_field_name} as component,
						{$check_type_obj->salary_comp_type_field_name} as type,
						ifnull({$check_type_obj->salary_cal_type},'') as cal_type,
						ifnull({$check_type_obj->salary_remb_type},'') as reimb_type,
						ifnull({$check_type_obj->round_off_field_name},'') as round_off, 
						ifnull({$check_type_obj->salary_comp_sequence},0) as sequence 
						from {$check_type_obj->salary_comp_table_name} c  
						inner join {$check_type_obj->salary_comp_type_table_name} d on 
						d.internal_code={$check_type_obj->salary_comp_type}
						and {$check_type_obj->salary_comp_type_field_name}<>'SPECIAL FIELDS'
						left join {$check_type_obj->round_off_table} r on
						r.internal_code={$check_type_obj->salary_comp_round_off} order by type desc,sequence ) a
						left join (select ref_sal_field_code,
						column_seq,
						is_selected,
						is_order_by,
						order_type,
						order_by_seq,sum_into
						from report_header rh inner join report_detail_sal_columns rds
						on rds.ref_report_header_code=rh.internal_code
						where rh.internal_code={$internal_code}) b on a.internal_code=b.ref_sal_field_code";
	$lobj_obj_mapping = $aobj_context->mobj_db->getAll($obj_mapping);
/* 	echo "<pre>";
    print_r($lobj_obj_mapping); die();
	die();  */
	$k=0;	
	$ded_flag=0;	
	$earn_sal_cnt=0;
	$ded_sal_cnt=0;
	foreach($lobj_obj_mapping as $key=>$val)
		{
		$ass_cheked='';
		$des_cheked='';
			
			$sal_col_seq=($val['column_seq']==1)?($k+25):$val['column_seq'];
			$sal_is_selected=($val['is_selected']==1)?'checked':'';
			$sal_is_ordered=($val['is_order_by']==1)?'checked':'';
			if($val['order_type']=='asc')
			$ass_cheked=' checked=checked ';
			else 
			$des_cheked=' checked=checked ';
			$sal_order_seq=$val['order_by_seq'];
			$sal_sum_into=$val['sum_into'];
			
			if($val[type]=='EARNINGS')	
			 {
				 $earn_sal_data.="<tr class='ui-widget-content jqgrow' >";
				 $earn_sal_data.="<td  class='tbl_row_new' align=center style='border-left:1px solid #C5DBEC; border-right:1px solid #C5DBEC; padding:2px;'><input type=text style='border:1px solid #C5DBEC; width:50px;' value= ".$sal_col_seq." id='report_sal_col_seq_{$val[internal_code]}'> </td>";
				 $earn_sal_data.="<td  class='tbl_row_new'style='border-right:1px solid #C5DBEC; padding:2px;' id='report_sal_col_name_{$val[internal_code]}'>{$val[component]}</td>";
				 $earn_sal_data.="<td class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;'><input type=checkbox {$sal_is_selected} id='report_sal_select_{$val[internal_code]}'> </td>";
				 $earn_sal_data.="<td class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;display:none;'><input type=checkbox {$sal_is_ordered}  id='report_sal_order_by_{$val[internal_code]}'> </td>";
				 $earn_sal_data.="<td class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;display:none;'>Asc:<input type=radio name=radio_report_sal_{$val[internal_code]}  {$ass_cheked} id='report_sal_order_type_asc_{$val[internal_code]}'> Desc:<input name=radio_report_sal_{$val[internal_code]} type=radio {$des_cheked} id='report_emp_order_type_des_{$val[internal_code]}'></td>";
				 $earn_sal_data.="<td class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;display:none;'><input style='border:1px solid #C5DBEC; width:50px' type=text value={$sal_order_seq} id='report_sal_order_seq_{$val[internal_code]}'> </td>";
				 $earn_sal_data.="<td class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;'><input type=text style='border:1px solid #C5DBEC; width:80px;'   value='{$sal_sum_into}'  id='report_sal_sum_into_{$val[internal_code]}'> </td>";
				 $earn_sal_data.="</tr>";
				 $k++;	
                 $earn_sal_cnt++;				 
			 }			 
			 
			else if($val[type]=='DEDUCTIONS')
			{
				 $ded_sal_data.="<tr class='ui-widget-content jqgrow' >";
				 $ded_sal_data.="<td  class='tbl_row_new' align=center style='border-left:1px solid #C5DBEC; border-right:1px solid #C5DBEC; padding:2px;'><input type=text style='border:1px solid #C5DBEC; width:50px;' value= ".$sal_col_seq." id='report_sal_col_seq_{$val[internal_code]}'> </td>";
				 $ded_sal_data.="<td  class='tbl_row_new'style='border-right:1px solid #C5DBEC; padding:2px;' id='report_sal_col_name_{$val[internal_code]}'>{$val[component]}</td>";
				 $ded_sal_data.="<td class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;'><input type=checkbox {$sal_is_selected} id='report_sal_select_{$val[internal_code]}'> </td>";
				 $ded_sal_data.="<td class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;display:none;'><input type=checkbox {$sal_is_ordered}  id='report_sal_order_by_{$val[internal_code]}'> </td>";
				 $ded_sal_data.="<td class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;display:none;'>Asc:<input type=radio name=radio_report_sal_{$val[internal_code]}  {$ass_cheked} id='report_sal_order_type_asc_{$val[internal_code]}'> Desc:<input name=radio_report_sal_{$val[internal_code]} type=radio {$des_cheked} id='report_emp_order_type_des_{$val[internal_code]}'></td>";
				 $ded_sal_data.="<td class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;display:none;'><input style='border:1px solid #C5DBEC; width:50px' type=text value={$sal_order_seq} id='report_sal_order_seq_{$val[internal_code]}'> </td>";
				 $ded_sal_data.="<td class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC;  padding:2px;'><input type=text style='border:1px solid #C5DBEC; width:80px;'   value='{$sal_sum_into}'  id='report_sal_sum_into_{$val[internal_code]}'> </td>";				 
				 $ded_sal_data.="</tr>";
				 $k++;	
				 $ded_sal_cnt++;			
			}							
		}
		
		for($ed=0;$ed<($earn_sal_cnt-$ded_sal_cnt);$ed++)
		{  
			$ded_sal_data.="<tr class='ui-widget-content jqgrow'>";
			$ded_sal_data.="<td class='tbl_row_new' style='padding:2px;  border-left:1px solid #C5DBEC; height:24px; border-right:1px solid #C5DBEC;'>&nbsp;</td>";
			$ded_sal_data.="<td class='tbl_row_new' style='padding:2px;  border-right:1px solid #C5DBEC;' align='right'> &nbsp; </td>";
			$ded_sal_data.="<td class='tbl_row_new' style='padding:2px;  border-right:1px solid #C5DBEC;' align='right'> &nbsp; </td>";
			$ded_sal_data.="<td class='tbl_row_new' style='padding:2px;  border-right:1px solid #C5DBEC;' align='right'> &nbsp; </td>";
			$ded_sal_data.="</tr>";
		}	
		
		for($ed=0;$ed<($ded_sal_cnt-$earn_sal_cnt);$ed++)
		{  
			$earn_sal_data.="<tr class='ui-widget-content jqgrow'>";
			$earn_sal_data.="<td class='tbl_row_new' style='padding:2px;  border-left:1px solid #C5DBEC; border-right:1px solid #C5DBEC;'>&nbsp;</td>";
			$earn_sal_data.="<td class='tbl_row_new' style='padding:2px;  border-right:1px solid #C5DBEC;' align='right'> &nbsp; </td>";
			$earn_sal_data.="<td class='tbl_row_new' style='padding:2px;  border-right:1px solid #C5DBEC;' align='right'> &nbsp; </td>";
			$earn_sal_data.="<td class='tbl_row_new' style='padding:2px;  border-right:1px solid #C5DBEC;' align='right'> &nbsp; </td>";
			$earn_sal_data.="</tr>";
		}		
		
		$arr['html']=$earn_sal_data."</table>"."<div style='float:left; width:20px;'>&nbsp;</div>".$ded_sal_data."</table>";
		$arr['table_data']=$lobj_obj_mapping;
		echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");									
}

function getReportEnableSummaryFields($aobj_context)
{
	 require_once($aobj_context->main_src."/custom_src/salcompclass.php");
	$check_type_obj=new SalCompClass($aobj_context);
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
	$internal_code=$aobj_context->mobj_data["internal_code"];
	$sal_data_header="<table align='center' cellspacing='0' cellpadding='0' border='0' width='80%'>";
	$sal_data_header.="<th align='left' colspan='3' class='ui-jqgrid-titlebar ui-widget-header ui-corner-tl ui-corner-tr ui-helper' style='font-size:12px; padding-left:6px; height:24px;'>Summary Fields</th>";		
	$sal_data_header.="<tr class='ui-state-default ui-jqgrid-hdiv'></tr>";	
	$sal_data_header.="<td align=center style='padding:2px; width:58px; border-left:1px solid #ccc; border-right:1px solid #ccc;'>Col Seq</td>";
	$sal_data_header.="<td align=center style='padding:2px; width:88px; border-left:0px solid #ccc; border-right:1px solid #ccc;'>Fields</td>";
	$sal_data_header.="<td align=center style='padding:2px; width:48px; border-left:0px solid #ccc; border-right:1px solid #ccc;'>Select</td>";
	$sal_data_header.="</tr>";

	
	$get_heads=" select internal_code,
						ifnull(column_seq,1) as column_seq,
						summary_field,
						ifnull(is_selected ,0) as is_selected 
						from 
						(select internal_code,summary_field from report_summary_heads
						where type='Report'
						order by sequence) a  left join 
						(select ref_summary_heads_code,
						column_seq,
						is_selected  from report_header rh inner join report_detail_summary_columns rde
						on rde.ref_report_header_code=rh.internal_code
						where rh.internal_code={$internal_code}) b on 
						a.internal_code=b.ref_summary_heads_code";
	$lobj_get_heads = $aobj_context->mobj_db->getAll($get_heads);
	 
	$k=0;									
	foreach($lobj_get_heads as $key=>$val)
		{
		$ass_cheked='';
		$des_cheked='';
			if($k%2==0)
				$class='tbl_row';
				else
				$class='tbl_row1';  
			$sal_col_seq=($val['column_seq']==1)?($k+60):$val['column_seq'];
			$sal_is_selected=($val['is_selected']==1)?'checked':'';
			// echo $sal_is_selected.'-->';
			 $sal_data_details.="<tr class='ui-widget-content jqgrow' >";
			 $sal_data_details.="<td class='tbl_row_new' align=center style='border-left:1px solid #C5DBEC; border-right:1px solid #C5DBEC; padding:2px;'><input type=text style='border:1px solid #C5DBEC;width:50px;' value= ".$sal_col_seq." id='report_summary_col_seq_{$val[internal_code]}'> </td>";
			 $sal_data_details.="<td class='tbl_row_new' style='border-right:1px solid #C5DBEC; padding:2px;' id='report_summary_col_name_{$val[internal_code]}'>{$val[summary_field]}</td>";
			 $sal_data_details.="<td class='tbl_row_new' align=center style='border-right:1px solid #C5DBEC; padding:2px;'><input type=checkbox {$sal_is_selected} id='report_summary_select_{$val[internal_code]}'> </td>";
 		 	$sal_data_details.="</tr>";
			 $k++;	
		} 	
		
		$arr['html']=$sal_data_header.$sal_data_details."</table>";
		$arr['table_data']=$lobj_get_heads;
		echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");									
}
function saveSalarySetupReportHeader($aobj_context)
{
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
	$internal_code=$aobj_context->mobj_data["internal_code"];
	$report_name=$aobj_context->mobj_data["report_name"];
	$from_date=$aobj_context->mobj_data["from_date"];
	$to_date=$aobj_context->mobj_data["to_date"];
	$report_setup_cross_tab=$aobj_context->mobj_data["report_setup_cross_tab"];
	$report_setup_col_total=$aobj_context->mobj_data["report_setup_col_total"];
	$report_setup_row_total=$aobj_context->mobj_data["report_setup_row_total"];
	$report_setup_sub_total=$aobj_context->mobj_data["report_setup_sub_total"];
	$report_setup_sub_field=$aobj_context->mobj_data["report_setup_sub_field"];
	$report_setup_sl_no=$aobj_context->mobj_data["report_setup_sl_no"];
	$report_freeze_cells=$aobj_context->mobj_data["report_freeze_cells"];
		if($internal_code==0)
		{
			$get_duplicate_report="select count(*) as count from report_header where report_name='{$report_name}'";
			$lobj_get_duplicate_report = $aobj_context->mobj_db->getRow($get_duplicate_report);
		 
				if($lobj_get_duplicate_report['count']==0)
				{
						$lstr_qry = "insert into 
									report_header( 
									report_name,
									from_date,
									to_date,
									is_cross_tab,
									is_row_total,
									is_col_tot,
									is_sub_tot,
									sub_tot_field,
									is_sl_no,
									freeze_cells,
									created_by,
									created_date,
									modified_by,
									modified_date)
									values ( '".$report_name."',
									'{$from_date}',
									'{$to_date}',
									{$report_setup_cross_tab},
									{$report_setup_row_total},
									{$report_setup_col_total},
									{$report_setup_sub_total},
									'{$report_setup_sub_field}',
									'{$report_setup_sl_no}',
									'{$report_freeze_cells}',
									{$_SESSION['user_id']},
									now(),
									{$_SESSION['user_id']},
									now()									
									)";  
						 	
					
						$lobj_rs = $aobj_context->mobj_db->Execute($lstr_qry);  	 
	 					$last_inserted_id  = $aobj_context->mobj_db->Insert_ID();
					    if($lobj_rs)
					    {
					        $rdata['last_insert_id'] = $last_inserted_id;
					        print_r($aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"));
					        return $rdata;
					     }
					    else
					    {
					        $rdata = "insertion Failed.";
					        print_r($aobj_context->mobj_output->ToJSONEnvelope($rdata,-1,"Failure"));  
							return $rdata;			
					    }    
				}
				else 	
				{
				     $rdata = "Report Name Already Exstis!";
			        print_r($aobj_context->mobj_output->ToJSONEnvelope($rdata,-1,"success"));
			        return $rdata;
			    }
		}
		else
		{
			$update_report_header="update report_header set report_name='{$report_name}',
									from_date='{$from_date}',
									to_date='{$to_date}',
									is_cross_tab={$report_setup_cross_tab},
									is_row_total={$report_setup_row_total},
									is_col_tot={$report_setup_col_total},
									is_sub_tot={$report_setup_sub_total},
									is_sl_no={$report_setup_sl_no},
									freeze_cells='{$report_freeze_cells}',
									sub_tot_field='{$report_setup_sub_field}',
									modified_by={$_SESSION['user_id']},
									modified_date=now()
									where internal_code={$internal_code}";
			$lobj_rs = $aobj_context->mobj_db->Execute($update_report_header); 
			 
			if($lobj_rs)
					    {
					        $rdata['last_insert_id'] =  $internal_code;
					        print_r($aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"));
					        return $rdata;
					     }
					    else
					    {
					        $rdata = "Updation Failed.";
					        print_r($aobj_context->mobj_output->ToJSONEnvelope($rdata,-1,"Failure"));  
							return $rdata;			
					    } 			
		}
}
function saveReportSetupResult($aobj_context)
{
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
	 require_once($aobj_context->main_src."/src/json.php");
	$json = new Services_JSON();
	$report_id = ($aobj_context->mobj_data["report_id"]);
	 
	$lstr_param = stripslashes($aobj_context->mobj_data["emp_details"]);
	$mobj_jsondata = $json->decode($lstr_param);
	$larr_emp_data = get_object_vars($mobj_jsondata);
	
	$lstr_param1 = stripslashes($aobj_context->mobj_data["sal_details"]);
	$mobj_jsondata1 = $json->decode($lstr_param1);
	$larr_sal_data = get_object_vars($mobj_jsondata1);  
	
	$lstr_param2 = stripslashes($aobj_context->mobj_data["summary_details"]);
	$mobj_jsondata2 = $json->decode($lstr_param2);
	$larr_summary_data = get_object_vars($mobj_jsondata2); 
	
	$lstr_param3 = stripslashes($aobj_context->mobj_data["report_conditions"]);
	$mobj_jsondata3 = $json->decode($lstr_param3);
	$larr_report_conditions = get_object_vars($mobj_jsondata3); 
	
	
	$delete_from_report_detail_emp_columns="delete from report_detail_emp_columns where ref_report_header_code={$report_id}";
	$delete_from_report_detail_sal_columns="delete from report_detail_sal_columns where ref_report_header_code={$report_id}";
	$delete_from_report_detail_summary_columns="delete from report_detail_summary_columns where ref_report_header_code={$report_id}";
	$delete_from_report_detail_conditions_columns="delete from report_detail_conditions where ref_report_header_code={$report_id}";
	$lobj_del_emp = $aobj_context->mobj_db->Execute($delete_from_report_detail_emp_columns);  
	$lobj_del_sal = $aobj_context->mobj_db->Execute($delete_from_report_detail_sal_columns);  
	$lobj_del_summary = $aobj_context->mobj_db->Execute($delete_from_report_detail_summary_columns);  
	$lobj_del_conditions = $aobj_context->mobj_db->Execute($delete_from_report_detail_conditions_columns);  
		 
		for( $i = 0; $i < count($larr_emp_data); $i++ )
		{
			$insert_into_emp_data="insert into report_detail_emp_columns(ref_report_header_code,
									ref_emp_field_code,
									column_seq,
									is_selected,
									is_group_by,
									is_order_by,
									order_type,
									order_by_seq)
									values (
									{$report_id},
									{$larr_emp_data[$i]->emp_field_id},
									{$larr_emp_data[$i]->emp_col_seq},
									{$larr_emp_data[$i]->emp_select},
									{$larr_emp_data[$i]->emp_group_by},
									{$larr_emp_data[$i]->emp_order_by},
									'{$larr_emp_data[$i]->emp_order_type}',
									{$larr_emp_data[$i]->emp_order_col_seq})";
								
				$lobj_insert_into_emp_data = $aobj_context->mobj_db->Execute($insert_into_emp_data);  					
		}	

		for( $k = 0; $k < count($larr_sal_data); $k++ )
		{
			$insert_into_sal_data="insert into report_detail_sal_columns(ref_report_header_code,
										ref_sal_field_code,
										column_seq,
										is_selected,
										is_order_by,
										order_type,
										order_by_seq,
										sum_into)
									values (
									{$report_id},
									{$larr_sal_data[$k]->sal_field_id},
									{$larr_sal_data[$k]->sal_col_seq},
									{$larr_sal_data[$k]->sal_select},
									{$larr_sal_data[$k]->sal_order_by},
									'{$larr_sal_data[$k]->sal_order_type}',
									{$larr_sal_data[$k]->sal_order_col_seq},
									'{$larr_sal_data[$k]->sal_sum_into}')";
				$lobj_insert_into_sal_data = $aobj_context->mobj_db->Execute($insert_into_sal_data);  	
	 	}
		for( $l = 0; $l < count($larr_summary_data); $l++ )
		{
			$insert_into_summary_data="insert into report_detail_summary_columns(ref_report_header_code,
										ref_summary_heads_code,
										column_seq,
										is_selected)
										values (
										{$report_id},
										{$larr_summary_data[$l]->summary_field_id},
										{$larr_summary_data[$l]->summary_col_seq},
										{$larr_summary_data[$l]->summary_select}
										 )";
				$lobj_insert_into_summary_data = $aobj_context->mobj_db->Execute($insert_into_summary_data);  	
				//echo $insert_into_summary_data;
	 			
		}
		for( $i = 0; $i < count($larr_report_conditions); $i++ )
		{
			$insert_into_conditions_data="insert into report_detail_conditions(ref_report_header_code,
									ref_ele_code,
									operator,
									value,
									and_or )
									values (
									{$report_id},
									{$larr_report_conditions[$i]->ele_id},
									'{$larr_report_conditions[$i]->operator}',
									'{$larr_report_conditions[$i]->value}',
									'{$larr_report_conditions[$i]->and_or}' )";
								
				$lobj_insert_into_conditions_data = $aobj_context->mobj_db->Execute($insert_into_conditions_data);  					
		}	
	 if($lobj_insert_into_emp_data)
					    {
					        $rdata = "Inserted Successfully";
					        print_r($aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"));
					        return $rdata;
					     }
					    else
					    {
					        $rdata = "insertion Failed.";
					        print_r($aobj_context->mobj_output->ToJSONEnvelope($rdata,-1,"Failure"));  
							return $rdata;			
					    }  	
}
function displayReportsSetup($aobj_context)
{
	 include_once($aobj_context->main_src.'/src/display_details_in_grid_custom.php');
		$display_obj=new display_details_in_grid($aobj_context);
		$display_obj->table_cols=array('report_name');
		$display_obj->display_qry="select internal_code as id,report_name  from 
					report_header where 1=1";
		 
		$display_obj->DisplayDetailsInGrid();
}
/*  function deletereportSetup($aobj_context)
 {
 
			$lstr_ids = $aobj_context->mobj_data["id"];	 

		$lstr_qry = "delete  
					from report_header 
					where internal_code in (".$lstr_ids.")"; 
			  $lobj_rs = $aobj_context->mobj_db->Execute($lstr_qry);
		 
			  
     
        if($lobj_rs) 
		{
		$rdata="Deleted Successfully";
            echo $aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"); 
		return 	$rdata;
		}
		 else
		{	$rdata="Deletion Failed";
            echo $aobj_context->mobj_output->ToJSONEnvelope($rdata,-1,"Failure");
			return 	$rdata;
		}
	
 } */

function getReportSetupName($aobj_context)
{
$internal_code = $aobj_context->mobj_data["internal_code"];	 
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
		$lstr_qry = "select report_name,
					DATE_FORMAT(from_date,'%d/%m/%Y') as from_date,  
					DATE_FORMAT(to_date,'%d/%m/%Y') as to_date ,
					is_cross_tab,
					is_row_total,
					is_col_tot,
					is_sub_tot,
					sub_tot_field,
					is_sl_no,freeze_cells
					from report_header 
					where internal_code ={$internal_code}"; 
			  $lobj_rs = $aobj_context->mobj_db->getRow($lstr_qry);
			$rdata['report_name']= $lobj_rs[report_name];
			$rdata['from_date']= $lobj_rs[from_date];
			$rdata['to_date']= $lobj_rs[to_date];
			$rdata['is_cross_tab']= $lobj_rs[is_cross_tab];
			$rdata['is_row_total']= $lobj_rs[is_row_total];
			$rdata['is_col_tot']= $lobj_rs[is_col_tot];
			$rdata['is_sub_tot']= $lobj_rs[is_sub_tot];
			$rdata['sub_tot_field']= $lobj_rs[sub_tot_field];
			$rdata['is_sl_no']= $lobj_rs[is_sl_no];
			$rdata['freeze_cells']= $lobj_rs[freeze_cells];
			
		$get_report_conditions="select * from report_detail_conditions where ref_report_header_code={$internal_code} order by internal_code";	
         $lobj_get_report_conditions = $aobj_context->mobj_db->getAll($get_report_conditions); 
		 $rdata['conditions']= $lobj_get_report_conditions;
		 echo $aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"); 
			return 	$rdata;  
}
function GenerateFinalReportSetupDetails($aobj_context)
{
	 require_once($aobj_context->main_src."/custom_src/salcompclass.php");
	require_once("TarkaFormatStyles.php");
	$check_type_obj=new SalCompClass($aobj_context);
	 require_once($aobj_context->main_src."/src/json.php");
	  require_once($aobj_context->main_src."/custom_src/employeeClass.php");
	  require_once($aobj_context->main_src."/src/format.php");
	$obj_comp = new employeeClass($aobj_context);
	$obj_comp->company();
	$obj_comp->employee();
	
	$json = new Services_JSON();
	$objfrmt = new FormatStyle();
	$excel_writer=$aobj_context->main_src."/Excel_Writer/Writer.php";

	include($excel_writer);				
	$root_xls_file_download=$aobj_context->main_src."/Report_details/output/user_report_".$_SESSION['user_id']."_".$report_id.".xls";
	
	// formats
	
	//$Data_Right->setNumFormat('##,##,##,##,##0.00');
	//$Title_Right->setNumFormat('##,##,##,##,##0.00');
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
	$report_id = ($aobj_context->mobj_data["report_id"]);
	$select_report_name="select report_name from report_header where internal_code={$report_id}";
	$obj_select_report_name =  $aobj_context->mobj_db->GetRow($select_report_name);
	$report_name=$obj_select_report_name[report_name];
	$schema_id = ($aobj_context->mobj_data["schema_id"]);
	$cond = stripslashes($aobj_context->mobj_data["cond"]);
	$emp_ids=addslashes(trim($aobj_context->mobj_data["emp_ids"]));
	if($emp_ids<>0)
	$emp_ids=substr($emp_ids,0,strlen($emp_ids)-1);
	$workbook = new Spreadsheet_Excel_Writer();
 
	$worksheet =& $workbook->addWorksheet("Sheet1");
	//$worksheet->hideScreenGridlines();  
	$Title_Center =& $workbook->addFormat($objfrmt->Title_Center);
	$Title_Right =& $workbook->addFormat($objfrmt->Title_Right);
	$Title_Left =& $workbook->addFormat($objfrmt->Title_Left);
	$Data_Right =& $workbook->addFormat($objfrmt->Data_Right);
	$Data_Left =& $workbook->addFormat($objfrmt->Data_Left);
	$Data_Left_B =& $workbook->addFormat($objfrmt->Data_Left_B);
	$Data_Right =& $workbook->addFormat();
	 $worksheet->setColumn(0,50,15);
		
	 $orignial_date =   ($aobj_context->mobj_data["from_date"]);
	$from_date = strtotime($aobj_context->mobj_data["from_date"]);
	
 
	$to_date = strtotime($aobj_context->mobj_data["to_date"]);
	$main_src_obj=(explode("/",$_SERVER["REQUEST_URI"]));
	$main_src=$main_src_obj[1];
	$from_date_string=date('Y',$from_date).'-'.date('m',$from_date);
	$to_date_string=date('Y',$to_date).'-'.date('m',$to_date);
	// echo date('M-Y',$from_date); die();
	if(empty($from_date))
	{
	$report_display_date =  " as on -  ".date('M' ).' - '.date('Y' );
	}
	else if(date('m',$from_date)!=date('m',$to_date))
	{
	$report_display_date =  " FOR THE PERIOD ". date('M-Y',$from_date)." - ".date('M-Y',$to_date);
	}
	else 
	{
	$report_display_date =  " for the Month of  ".date('M',$from_date). ' - ' .date('Y',$from_date);
	}
	$aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=100000");
	$aobj_context->mobj_db->execute("set @a:=0");
 	$select_ref_module_code="select GROUP_CONCAT(join_table_name SEPARATOR ' ') as qry from 
	(select   @a:=@a+1,ref_module_code,
	concat(' left join module_',ref_module_code, ' as module_',ref_module_code,'_',sus.internal_code,' on module_',ref_module_code,'_',sus.internal_code,'.internal_code =module_',s.internal_code,'.m_',ref_s_user_schema_code, '_ele_',sus.internal_code) 
	as join_table_name
	from s_user_schema_elements sus
	inner join s_user_schema s on s.internal_code=sus.ref_s_user_schema_code
	where module_name='Employee'   
	and is_multiple_group=0 and ref_module_code>0)j";
	$obj_select_ref_module_code =  $aobj_context->mobj_db->GetRow($select_ref_module_code);
	
	$join_qry=(count($obj_select_ref_module_code)>0)?$obj_select_ref_module_code[qry]:'';
	 $aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=1000000");
	$get_emp_conditions="select GROUP_CONCAT( ' ' ,db_field, ' ' ,operator,' ',
    if(operator='Like',concat(\"'%\",value,\"%'\"),if(operator='In',concat(\"(\",value,\")\"),if(operator='Not In',concat(\"(\",value,\")\"),concat(\"'\",value,\"'\")))),' ',and_or separator '' ) as emp_conds
						from report_detail_conditions rdc 
						inner join s_user_schema_elements sus on sus.internal_code=ref_ele_code 
						where rdc.ref_report_header_code={$report_id}";
						
	$obj_get_emp_conditions =  $aobj_context->mobj_db->GetRow($get_emp_conditions);
	$emp_general_conditions='';
	if(!is_null($obj_get_emp_conditions[emp_conds]))
	{
	$pos = strrpos($obj_get_emp_conditions[emp_conds], "And");
	if ($pos === false)
	$emp_general_conditions=' and (' .substr($obj_get_emp_conditions[emp_conds],0,strlen($obj_get_emp_conditions[emp_conds])-2).")";
	else
	$emp_general_conditions=' and (' .substr($obj_get_emp_conditions[emp_conds],0,strlen($obj_get_emp_conditions[emp_conds])-3).")";
	}
 
		$groupby_cols= substr($groupby_cols,0,strlen($groupby_cols)-1);
	 

		
		$get_display_cols="select GROUP_CONCAT(field_name) as field_name  from 
								((select table_name,name,field_name as grid_field_name,
									if(ref_module_code<>0,
									concat('module_',ref_module_code,'_',ele_ic_code,'.',field_id1,' as ',field_name),
									if(data_type='Date',
									concat('DATE_FORMAT(','module_',internal_code,'.',field_name,',\'%d/%m/%Y\') as  ',field_name)
									,
									concat('module_',internal_code,'.',field_name))
									) as 
									field_name
									,ref_module_code from 
									(select  s.internal_code, t1.value as data_type,ref_module_code,concat('module_',s.internal_code) as table_name ,
									field_id,su.internal_code as ele_ic_code,field_id1,
									su.name,ifnull(multiple,0) as multiple,ifnull(ug.name,'0None') as group_name,concat('m_',s.internal_code,'_ele_',su.internal_code) as field_name from s_user_schema s inner join s_user_schema_elements su on 
									su.ref_s_user_schema_code=s.internal_code
									inner join s_ref_type t on t.internal_code=su.s_ref_type_meta
									inner join s_ref_type t1 on t1.internal_code=data_type
									left join s_user_schema_group ug on ug.internal_code=su.ref_s_user_schema_group_code
									left join module_meta_columns mmc on mmc.module_id=su.ref_module_code
									where  s.module_name='Employee'   and t.value='Meta'   
									order by ug.sequence,su.sequence,su.internal_code ) l 
									where   multiple=0 )) a ";
						$lobj_get_display_cols = $aobj_context->mobj_db->GetRow($get_display_cols);					
		$selected_ids=($emp_ids>0)?" and  internal_code in ({$emp_ids})":"";		
		$sel_criteria="(select module_{$schema_id}.internal_code  ,
							{$lobj_get_display_cols[field_name]} 
							from   module_{$schema_id} {$join_qry}) a 
							where internal_code>0 {$cond} {$selected_ids}  {$emp_general_conditions}";
				// echo $cond;die();		 
		  		
			$col_seq="order by column_seq";				
			$order_seq="order by order_by_seq";				
			$emp_cols="select concat('m_{$schema_id}_ele_',ref_emp_field_code) as field_id,
							concat('a.m_{$schema_id}_ele_',ref_emp_field_code,' as \'',sus.name,'\'') as display_name,
							sus.name as excel_display,
							is_selected,
							is_group_by,
							is_order_by,
							order_type,
							order_by_seq from report_header rh 
							inner join 
							report_detail_emp_columns rde on rh.internal_code=rde.ref_report_header_code
							inner join s_user_schema_elements sus on sus.internal_code=ref_emp_field_code
							where (is_selected=1 or is_group_by=1) 
							and rh.internal_code={$report_id} ";
			//echo$emp_cols;				
			$col_seq_qry=$emp_cols.$col_seq;	
 			 
			$lobj_get_emp_cols_groups = $aobj_context->mobj_db->GetAll($col_seq_qry);
			$groupby_cols='';
			$groupby_join_cols='';
			//$cross_tab_group_cols='';
			$final_display_col_names='';// Employee Display Cols
			$display_field_name='';
			$order_col_seq='';
			$order_col_excel_seq='';
			$final_excel_display_col='';
			$sum_into=',sum_into';
			$sum_of_tot=" , total";
			$sum_of_atot=" , a_tot";
			$groupby_join_cols=' on ';
			foreach($lobj_get_emp_cols_groups as $key=>$val)
			{
				$final_display_col_names.=$val[display_name].',';
				$final_excel_display_col.=$val[excel_display].',';
				
				if($val[is_group_by]=='1')
				{  
				$groupby_cols.=$val[field_id].',';
				$groupby_join_cols.=" a.{$val[field_id]}=summary.{$val[field_id]}";
				}
				$display_field_name.=$val[field_id].',';
			}
			if(!empty($groupby_cols))
			{ 
			$groupby_cols="group by ".$groupby_cols ;
			$groupby_cols= substr($groupby_cols,0,strlen($groupby_cols)-1);
			//$cross_tab_group_cols=$groupby_cols;
			$groupby_cols.= ", sum_into";
			$sum_of_tot=", sum(total) ";
			$sum_of_atot=", sum(a_tot) ";
			
			} 
			
			 $final_display_col_names= substr($final_display_col_names,0,strlen($final_display_col_names)-1);
			 $display_field_name= substr($display_field_name,0,strlen($display_field_name)-1);
			 $final_excel_display_col= substr($final_excel_display_col,0,strlen($final_excel_display_col)-1);
			 
			$corder_seq_qry=$emp_cols.$order_seq;	
 		
			$lobj_corder_seq_qry = $aobj_context->mobj_db->GetAll($corder_seq_qry); 
			 
			foreach($lobj_corder_seq_qry as $key_1=>$val_1)
			{
				$order_col_seq.=$val_1[field_id] ." ".$val_1[order_type].",";
				if($val_1['excel_display']=='Code')
				 $order_col_excel_seq.= "lpad(".$val_1[field_id] .",11,'0') ".$val_1[order_type].",";
				else
				 $order_col_excel_seq.= $val_1[field_id] ." ".$val_1[order_type].",";
			}
			if(!empty($order_col_seq))
			{
			$order_col_seq=' order by '.substr($order_col_seq,0,strlen($order_col_seq)-1);
			$order_col_excel_seq=  substr($order_col_excel_seq,0,strlen($order_col_excel_seq)-1);
			//$order_col_excel_seq=' order by '.substr($order_col_excel_seq,0,strlen($order_col_excel_seq)-1);
			} 
			//echo $order_col_excel_seq; die();
			$get_emp_details="select internal_code as emp_code,{$display_field_name} 
								from {$sel_criteria}
								 {$order_col_seq}";
		//echo $get_emp_details; die();
		#get summary heads
				$summary_fields='';
				$summary_display_cols='';
				$summary_excel_display_cols='';
				$summary_field_join='';
				 $aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=100000");
				$get_summary_heads="select  
								ifnull(GROUP_CONCAT(db_field ,' as ',as_field),0) as summary_field,
								ifnull(GROUP_CONCAT('sum(',db_field,')   as ',as_field),0) as group_summary_field,
								GROUP_CONCAT(concat(as_field,' as \'',summary_field,'\''))  as display_summary_field,
								GROUP_CONCAT(summary_field) as excel_summary_cols								
								from
								(select summary_field,db_field,as_field
								from report_header rh 
								inner join 
								report_detail_summary_columns rde on rh.internal_code=rde.ref_report_header_code
								inner join report_summary_heads sus on sus.internal_code=ref_summary_heads_code
								where is_selected=1 and   rh.internal_code={$report_id} order by column_seq)a";	
					$lobj_get_summary_heads = $aobj_context->mobj_db->GetRow($get_summary_heads);
				 
					if($lobj_get_summary_heads['summary_field']!='0')
					{
					$summary_fields=' ,'.$lobj_get_summary_heads['summary_field'];
					$group_summary_field=' ,'.$lobj_get_summary_heads['group_summary_field'];
					$summary_display_cols=' ,'.$lobj_get_summary_heads['display_summary_field'];
					$summary_excel_display_cols=$lobj_get_summary_heads['excel_summary_cols'];
					$summary_field_join=" inner join  employee_monthly_salary_summary emss on emss.ref_employee_code= emp.emp_code and 
					concat(processed_year,'-',if(processed_month<10,'0',''),processed_month) between '{$from_date_string}' and '{$to_date_string}' 
					  ";
					}
					
		#get Sal Details
				$sal_cols="(select 
							is_selected,
						 	is_order_by,
							ref_sal_field_code,
							order_type,
							order_by_seq,
							if(trim(sum_into)='',{$check_type_obj->salary_comp_field_name},trim(sum_into)) as sum_into 
							from (select  
							is_selected,
						 	is_order_by,
							ref_sal_field_code,
							order_type,
							order_by_seq,
							column_seq,
							sum_into
							 from report_header rh 
							inner join 
							report_detail_sal_columns rde on rh.internal_code=rde.ref_report_header_code
							where (is_selected=1  ) 
							and rh.internal_code={$report_id}) a  
							inner join {$check_type_obj->salary_comp_table_name} b on a.ref_sal_field_code=b.internal_code 
							order  by column_seq) ";
			 	 		
			$sal_col_seq_qry=$sal_cols;	
			$sal_excel_display_cols='';
			$sal_display_field_name='';
			$sal_order_col_seq='';
			
			$lobj_sal_col_seq_qry = $aobj_context->mobj_db->GetAll($sal_col_seq_qry);
			$group_conat_sal_cols=' ';
			 $emp_monthly_sal=' ';$is_bold="";
			  
			if(!empty($lobj_sal_col_seq_qry ))
			{
			$is_bold=" ,is_bold";
			$group_conat_sal_cols=",group_concat(concat(sum_into,'->',is_bold,'!',amount,'~',a_tot)) as concate_sal_heads,group_concat(distinct is_bold) as is_bold ";
			$emp_monthly_sal=" inner join (select rr.*,sum(inner_total) as total,
								sum(arrears_total) as a_tot,
								if(sum(inner_total+arrears_total)=sum(original_amount) 
								or component_name='Income Tax' or component_name='IT' ,0,1) as is_bold
								from 
								(select 
								is_selected,
								is_order_by,
								ref_sal_field_code,
								order_type,
								order_by_seq,
								if(sum_into='',component_name,sum_into) as sum_into,
								component_name,
								sum(amount) as inner_total,
								sum(arrears) as arrears_total,
								sum(original_amount) as original_amount,
								ems.ref_employee_code,
								ref_salary_component   from 
								{$sal_cols} r
								inner join 
								employee_monthly_salary ems on ems.ref_salary_component=r.ref_sal_field_code
								inner join employee_monthly_salary_summary emss on ems.ref_employee_code=emss.ref_employee_code
								and ems.month=emss.processed_month and ems.year=emss.processed_year and net_pay<>0
								where concat(year,'-',if(month<10,'0',''),month) 
								between '{$from_date_string}' and '{$to_date_string}' 
								group by ref_employee_code,if(sum_into='',component_name,sum_into),component_name
								 having inner_total+arrears_total<>0) rr
								group by ref_employee_code,sum_into ) sal on 
								emp.emp_code=sal.ref_employee_code  ";
			 				
			}
			else
			{
			$sum_into=",'' ";
			$sum_of_tot=" , 0 ";
			$sum_of_atot=" , 0 ";
			}
			//echo $sal_col_seq_qry.'aaa';
			foreach($lobj_sal_col_seq_qry as $key=>$val)
			{
				$pos = strpos($sal_excel_display_cols, $val[sum_into]);
				if ($pos === false) {
				$sal_excel_display_cols.=$val[sum_into].',';
				}
			}  
			 $sal_excel_display_cols=substr($sal_excel_display_cols,0,strlen($sal_excel_display_cols)-1);
			
			$get_report_name = "select report_name,is_cross_tab,is_sl_no,is_row_total,
				is_col_tot,is_sub_tot,sub_tot_field,freeze_cells from report_header where internal_code=".$report_id;
			$obj_report_name = $aobj_context->mobj_db->GetRow($get_report_name);
			$report_name = $obj_report_name['report_name'];
			$is_cross_tab = $obj_report_name['is_cross_tab'];
			$is_row_total = $obj_report_name['is_row_total'];
			$is_sl_no = $obj_report_name['is_sl_no'];
			$is_col_tot = $obj_report_name['is_col_tot'];
			$is_sub_tot = $obj_report_name['is_sub_tot'];
			$sub_tot_field = $obj_report_name['sub_tot_field'];
			$is_sl_nos = $obj_report_name['is_sl_no'];
			$freeze_cells = $obj_report_name['freeze_cells'];
			//echo  $get_report_name; die();
			PopulateHeaders($aobj_context,$obj_comp,$worksheet,$Title_Left,$report_name,$report_display_date);	  	
			$aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=1000000");	
			$cross_tab_cols=($is_cross_tab==1)?",".$display_field_name:'';	
			
			     	 
			 
				if(!empty($groupby_cols) && $lobj_get_summary_heads['summary_field']!='0')
				{ 
				$get_emp_result="(select {$display_field_name}, {$final_display_col_names} {$cross_tab_cols} 		{$group_conat_sal_cols}   from 
								(select {$display_field_name}   {$sum_into} 
								{$sum_of_tot} as amount
								{$sum_of_atot} as a_tot {$is_bold}
								from 
								({$get_emp_details}) emp
								{$emp_monthly_sal} 
								{$groupby_cols} ) a group by {$order_col_excel_seq})";
								 
					$groupby_cols=substr($groupby_cols,0,strlen($groupby_cols)-10);		
					$get_emp_summary="(select {$display_field_name} {$group_summary_field}  
								from 
								({$get_emp_details}) emp
								{$summary_field_join} 
								{$groupby_cols} ) ";	
					 			
					$get_final_result=" select  {$final_display_col_names} {$cross_tab_cols}
								,concate_sal_heads 
								{$summary_display_cols}  from
								({$get_emp_result})  a 
								inner join 	{$get_emp_summary} summary
								{$groupby_join_cols}
								";			
				 	$lobj_get_final_result = $aobj_context->mobj_db->GetAll($get_final_result);		
				}
				else
				{
				$get_final_result="(select  {$final_display_col_names} {$cross_tab_cols} {$group_conat_sal_cols} 
								{$summary_display_cols}  from 
								(select {$display_field_name} {$summary_fields} {$sum_into} 
								{$sum_of_tot} as amount
								{$sum_of_atot} as a_tot {$is_bold}
								from 
								({$get_emp_details}) emp
								{$emp_monthly_sal} 
								 {$summary_field_join} 
								{$groupby_cols} ) a group by {$order_col_excel_seq}  )  "	;	//order_col_excel_seq
			   			
				$lobj_get_final_result = $aobj_context->mobj_db->GetAll($get_final_result);
				}
			 
				  // getting all display column for excel by union format	
 			$get_union_display_cols="select * from (
									 select summary_field as display_fields ,column_seq
									from report_header rh 
									inner join 
									report_detail_summary_columns rde on rh.internal_code=rde.ref_report_header_code
									inner join report_summary_heads sus on sus.internal_code=ref_summary_heads_code
									where is_selected=1 and  rh.internal_code={$report_id}  
									union
									select  
									sus.name as excel_display,column_seq
									from report_header rh 
									inner join 
									report_detail_emp_columns rde on rh.internal_code=rde.ref_report_header_code
									inner join s_user_schema_elements sus on sus.internal_code=ref_emp_field_code
									where (is_selected=1 or is_group_by=1) 
									and rh.internal_code={$report_id} 
									union
									select  
									 if(trim(sum_into)='',{$check_type_obj->salary_comp_field_name},
									 trim(sum_into)) as sum_into,column_seq 
									from (select is_selected, is_order_by, ref_sal_field_code, order_type, 
									order_by_seq, column_seq, sum_into from report_header rh 
									inner join report_detail_sal_columns rde on 
									rh.internal_code=rde.ref_report_header_code
									inner join (select distinct ref_salary_component    from 
										employee_monthly_salary   
										where concat(year,'-',if(month<10,'0',''),month) 
										between '{$from_date_string}' and '{$to_date_string}' 
										and  amount<>0) dist_sal_cmp 
										on dist_sal_cmp.ref_salary_component=rde.ref_sal_field_code
									where
									 (is_selected=1 ) and rh.internal_code={$report_id}) a 
									inner join {$check_type_obj->salary_comp_table_name} b 
									on a.ref_sal_field_code=b.internal_code
									 group by if(trim(sum_into)='',{$check_type_obj->salary_comp_field_name},
									 trim(sum_into))

									 
									 union  

									 
									 select if(trim(sum_into)='',concat({$check_type_obj->salary_comp_field_name},' Arrears'), 
									concat(trim(sum_into),' Arrears')) as sum_into
								  ,(column_seq+0.0001) as  column_seq
									from (select is_selected, is_order_by, ref_sal_field_code, order_type, 
									order_by_seq, column_seq, sum_into from report_header rh 
									inner join report_detail_sal_columns rde on 
									rh.internal_code=rde.ref_report_header_code
									inner join (select distinct ref_salary_component    from 
									employee_monthly_salary  ems
									inner join employee_monthly_salary_summary emss 
									on ems.ref_employee_code=emss.ref_employee_code
									and ems.month=emss.processed_month and ems.year=emss.processed_year 
									and net_pay<>0
									where concat(year,'-',if(month<10,'0',''),month) 
										between '{$from_date_string}' and '{$to_date_string}' 
										and  arrears<>0) dist_sal_cmp 
										on dist_sal_cmp.ref_salary_component=rde.ref_sal_field_code
									where
									 (is_selected=1 ) and rh.internal_code={$report_id}) a 
									inner join {$check_type_obj->salary_comp_table_name} b 
									on a.ref_sal_field_code=b.internal_code
									 group by if(trim(sum_into)='',{$check_type_obj->salary_comp_field_name},
									 trim(sum_into)) order by column_seq
									 )a
									 order by column_seq"; 
					  	 
			$lobj_get_union_display_cols = $aobj_context->mobj_db->GetAll($get_union_display_cols);
			//echo $get_union_display_cols; die();
			if($is_cross_tab==0)
			populateNonCrossTabReport($lobj_get_final_result,$lobj_get_union_display_cols,$is_sub_tot,$sub_tot_field,$worksheet,$Title_Center,$is_row_total,$is_col_tot,$Title_Right,$is_sl_nos,$freeze_cells,$Data_Right,$Data_Left,$Data_Left_B);
			else
			populateCrossTabReport($aobj_context,$get_final_result,$cross_tab_cols,$final_excel_display_col,$worksheet,$Title_Center,$Title_Right,$is_sl_nos,$freeze_cells);
		if(strtolower($report_name) =='salary register' || strtolower($report_name) =='salaryregister')
		{
			$get_dates="select 
						date_format(date_sub('{$orignial_date}',interval  1 month),'%m') as prev_month,
						date_format(date_sub('{$orignial_date}',interval  1 month),'%Y') as prev_year,
						date_format(date_sub('{$orignial_date}',interval  1 month),'%b-%Y') as from_date_string,							
						date_format( '{$orignial_date}','%Y') as cur_year,	 
						date_format( '{$orignial_date}','%m') as cur_month,
						date_format( '{$orignial_date}','%b-%Y') as to_date_string 
						";
			 $obj_get_dates = $aobj_context->mobj_db->GetRow($get_dates);
			 $end_process_month=$obj_get_dates[cur_month];
			 $end_process_year=$obj_get_dates[cur_year];
			 $start_process_month=$obj_get_dates[prev_month];
			 $start_process_year=$obj_get_dates[prev_year];
			 $to_date_string=$obj_get_dates[to_date_string];
			 $from_date_string=$obj_get_dates[from_date_string];
			require_once($aobj_context->main_src."/custom_src/emp_joining_details.php");
			$obj=new EmployeeJoiningDetails($aobj_context);
			$obj->start_process_month=$start_process_month;
			$obj->start_process_year=$start_process_year;
			$obj->end_process_year=$end_process_year;
			$obj->end_process_month=$end_process_month;
			$obj->from_date_string=$from_date_string;
			$obj->to_date_string=$to_date_string;
			$obj->getData();
			populateConsolidatedEarningDedutionReport($aobj_context,$obj_comp,$worksheet,$workbook,$Title_Left,$Data_Right,$report_name,$report_display_date,$orignial_date,$obj);
			populateEmployeeWiseComparisionReport($aobj_context,$obj_comp,$worksheet,$workbook,$Title_Left,$Data_Right,$report_name,$report_display_date,$orignial_date,$obj);
		}
		$workbook->send("{$report_name}.xls");		
		$workbook->close();
}
function PopulateHeaders($aobj_context,$obj_comp,$worksheet,$Title_Left,$report_name,$report_display_date)
{
	$get_company_name = "select {$obj_comp->company_name} as Company from {$obj_comp->company_table}";
			$obj_company_name = $aobj_context->mobj_db->GetRow($get_company_name);
			$company_name = $obj_company_name['Company'];	
			$_SESSION['report_company_name']=	$company_name;
			$worksheet->write(0,0,$company_name, $Title_Left);
			$worksheet->mergeCells(0,0,0,4);
		$worksheet->write(1,0,$report_name.$report_display_date , $Title_Left);
			$worksheet->mergeCells(1,0,1,4);			
}
function populateEmployeeWiseComparisionReport($aobj_context,$obj_comp,$worksheet,$workbook,$Title_Left,$Data_Right,$report_name,$report_display_date,$orignial_date,$obj)
{
 
		$worksheet =& $workbook->addWorksheet('Comparision Report');
		$company_name=	$_SESSION['report_company_name'];
		$worksheet->write(0,0,$company_name, $Title_Left);
		$worksheet->mergeCells(0,0,0,8);
		$worksheet->write(1,0,"Employee Wise Compariosion Report for the month".$report_display_date , $Title_Left);
		$worksheet->mergeCells(1,0,1,8);	
		//$Data_Right->setNumFormat('##,##,##,##,##0.00');
		$get_dates="select 
						date_format(date_sub('{$orignial_date}',interval  1 month),'%m') as prev_month,
						date_format(date_sub('{$orignial_date}',interval  1 month),'%Y') as prev_year,
						date_format(date_sub('{$orignial_date}',interval  1 month),'%b-%Y') as from_date_string,							
						date_format( '{$orignial_date}','%Y') as cur_year,	 
						date_format( '{$orignial_date}','%m') as cur_month,
						date_format( '{$orignial_date}','%b-%Y') as to_date_string 
						";
		 $obj_get_dates = $aobj_context->mobj_db->GetRow($get_dates);
		 $end_process_month=$obj_get_dates[cur_month];
		 $end_process_year=$obj_get_dates[cur_year];
		 $start_process_month=$obj_get_dates[prev_month];
		 $start_process_year=$obj_get_dates[prev_year];
		 $to_date_string=$obj_get_dates[to_date_string];
		 $from_date_string=$obj_get_dates[from_date_string];
		 
		 	include_once($aobj_context->main_src."/src/salcompclass.php");	
		$check_type_obj=new SalCompClass($aobj_context);
		 $obj_mapping="(select c.internal_code as ref_component_code,
									{$check_type_obj->salary_comp_field_name} as component,
									{$check_type_obj->salary_comp_type_field_name} as type
									  from {$check_type_obj->salary_comp_table_name} c 
										inner join {$check_type_obj->salary_comp_type_table_name} d on 
										d.internal_code={$check_type_obj->salary_comp_type}
										where {$check_type_obj->salary_comp_type_field_name}<> 'SPECIAL FIELDS'
										order by 
										{$check_type_obj->salary_comp_type_field_name} desc,
										ifnull({$check_type_obj->salary_comp_sequence},'0') )";
					$lobj_map = $aobj_context->mobj_db->GetAll($obj_mapping);
					 
		$row=3;
		$worksheet->write( $row, 0, 'EMPCODE',$Title_Left);
		$worksheet->write( $row, 1, 'EMP NAME',$Title_Left);		
		$k=2;
		$cell_ids= array();
		$total_cell_ids= array();
		//echo (count($lobj_map)); die();
		//echo ($lobj_map[1][component_name]); die();
		// var_dump($lobj_map[0][]);die();
		
	for($i=0;$i<count($lobj_map);$i++)	
	{
	//echo $lobj_map[$i]['component_name']; die();
	$worksheet->write($row,$k ,$lobj_map[$i]['component'],$Title_Left);
	$cell_ids[$lobj_map[$i]['component']]=$k;
	$total_cell_ids[$lobj_map[$i]['component']]=0;
	 $k++;
	}
//	echo $obj_mapping; die();
$get_employee_details= " select code,name,group_concat(component,'->',difference) as amount from 
							(select {$obj_comp->employee_name} as name,
							{$obj_comp->employee_code} as code,
							ems_end.component_name as component , 
							ems_end.amount+ems_end.arrears as ems_end_amount,
							ems_start.component_name as ems_start_component, 
							ems_start.amount+ems_start.arrears as ems_start_amount,
							ifnull(ems_end.amount,0)+ifnull(ems_end.arrears,0)-(ifnull(ems_start.amount,0)+ifnull(ems_start.arrears,0)) as difference
							from {$obj_comp->employee_table} emp
							inner join employee_monthly_salary ems_end  on 
							ems_end.ref_employee_code = emp.internal_code
							and ems_end.month ={$end_process_month} 
							and ems_end.year ={$end_process_year} 							
							left join employee_monthly_salary ems_start  on 
							ems_start.ref_employee_code = emp.internal_code
							and ems_start.month ={$start_process_month} 
							and ems_start.year ={$start_process_year} 
							and ems_start.type<>'SPECIAL FIELDS'
							and ems_end.type<>'SPECIAL FIELDS'
							and ems_end.ref_salary_component = ems_start.ref_salary_component
							union
							select {$obj_comp->employee_name} as name,
							{$obj_comp->employee_code} as code,
							ems_start.component_name as component , 
							ems_end.amount+ems_end.arrears as ems_end_amount,
							ems_start.component_name as ems_start_component, 
							ems_start.amount+ems_start.arrears as ems_start_amount,
							ifnull(ems_end.amount,0)+ifnull(ems_end.arrears,0)-(ifnull(ems_start.amount,0)+ifnull(ems_start.arrears,0)) as difference
							from {$obj_comp->employee_table} emp
							inner join employee_monthly_salary ems_start  on 
							ems_start.ref_employee_code = emp.internal_code
							and ems_start.month ={$start_process_month} 
							and ems_start.year ={$start_process_year} 							
							left join employee_monthly_salary ems_end  on 
							ems_end.ref_employee_code = emp.internal_code
							and ems_end.month ={$end_process_month} 
							and ems_end.year ={$end_process_year} 
							and ems_end.type<>'SPECIAL FIELDS'
							and ems_end.type<>'SPECIAL FIELDS'
							and ems_end.ref_salary_component = ems_start.ref_salary_component
							)	 a group by code,name";	
				
			 
			 
		$aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=1000000");		
		$obj_employee_details = $aobj_context->mobj_db->GetAll($get_employee_details);
	 	$worksheet->setColumn(1,1,25);
	$row=4;
	for($k=0;$k<count($obj_employee_details);$k++)
			{
				$worksheet->writeString( $row, 0, $obj_employee_details[$k]['code'],$Data_Left); 
				$worksheet->writeString( $row, 1, $obj_employee_details[$k]['name'],$Data_Left); 
				$comma_split=explode(',',$obj_employee_details[$k]['amount']);
						foreach($comma_split as $c_key )
						{
						 $arrow_split=explode('->',$c_key);
						 if($cell_ids[$arrow_split[0]])
						 {
						 $worksheet->write($row,$cell_ids[$arrow_split[0]],$arrow_split[1],$Data_Right); 
						 $total_cell_ids[$arrow_split[0]]= $total_cell_ids[$arrow_split[0]]+$arrow_split[1];
						 }
						}
						$row++;
			}
	$row++;
 $worksheet->write($row,0,'',$Data_Right); 	
 $worksheet->write($row,1,"Total",$Title_Left); 	
foreach($total_cell_ids as $k=>$v)
 {
  $worksheet->write($row,$cell_ids[$k],$v,$Data_Right); 
 }
 			
 //echo $get_employee_details; die(); 
$worksheet->mergeCells(0,0,0,15);
$worksheet->mergeCells(1,0,1,14);

$row+=2;
$emp_data=$obj->fin_arr;
  foreach($emp_data as $emp_key=>$emp_val)
  {
	$worksheet->write($row,0,$emp_key); 
	$worksheet->mergeCells($row,0,$row,1);
	$worksheet->write($row,2,$emp_val); $row++;
  }	
   $doj_details_arr=$obj->doj_details_arr;
	$dor_details_arr=$obj->dor_details_arr;
	$row+=2;
   
	$worksheet->write($row,0,"DOJ Details ",$Data_Left);
	$worksheet->write($row,1,'',$Data_Left);
	$worksheet->write($row,2,'',$Data_Left);
	$worksheet->mergeCells($row,0,$row,2);
	$row+=1;
	$worksheet->write($row,0,"Code ",$Data_Left);
	$worksheet->write($row,1,'Name',$Data_Left);
	$worksheet->write($row,2,'Date Of Joining',$Data_Left);
 $row+=1;
	foreach($doj_details_arr as $doj_k=>$doj_v)
	{
		$worksheet->write($row,0,$doj_v['code'],$Data_Left);
		$worksheet->write($row,1,$doj_v['name'],$Data_Left);
		$worksheet->write($row,2,$doj_v['date'],$Data_Left);		 
		$row+=1;
	}
	$row+=2;
	$worksheet->write($row,0,"DOR Details ",$Data_Left);
	$worksheet->write($row,1,'',$Data_Left);
	$worksheet->write($row,2,'',$Data_Left);
	$worksheet->mergeCells($row,0,$row,2);
	$row+=1;
	$worksheet->write($row,0,"Code ",$Data_Left);
	$worksheet->write($row,1,'Name',$Data_Left);
	$worksheet->write($row,2,'Date Of Resign',$Data_Left);
 $row+=1;
	foreach($dor_details_arr as $dor_k=>$dor_v)
	{
		$worksheet->write($row,0,$dor_v['code'],$Data_Left);
		$worksheet->write($row,1,$dor_v['name'],$Data_Left);
		$worksheet->write($row,2,$dor_v['date'],$Data_Left);		 
		$row+=1;
	}
	
}
function populateConsolidatedEarningDedutionReport($aobj_context,$obj_comp,$worksheet,$workbook,$Title_Left,$Data_Right,$report_name,$report_display_date,$orignial_date,$obj)
{
		$worksheet =& $workbook->addWorksheet('Consolidated Variance Report');
		$company_name=	$_SESSION['report_company_name'];
		$worksheet->write(0,0,$company_name, $Title_Left);
		$worksheet->mergeCells(0,0,0,8);
		$worksheet->write(1,0,"Consolidated Earnings and Deductions Report for the month".$report_display_date , $Title_Left);
		$worksheet->mergeCells(1,0,1,8);	
		//$Data_Right->setNumFormat('##,##,##,##,##0.00');
		$get_dates="select 
						date_format(date_sub('{$orignial_date}',interval  1 month),'%m') as prev_month,
						date_format(date_sub('{$orignial_date}',interval  1 month),'%Y') as prev_year,
						date_format(date_sub('{$orignial_date}',interval  1 month),'%b-%Y') as from_date_string,							
						date_format( '{$orignial_date}','%Y') as cur_year,	 
						date_format( '{$orignial_date}','%m') as cur_month,
						date_format( '{$orignial_date}','%b-%Y') as to_date_string 
						";
		 $obj_get_dates = $aobj_context->mobj_db->GetRow($get_dates);
		 $end_process_month=$obj_get_dates[cur_month];
		 $end_process_year=$obj_get_dates[cur_year];
		 $start_process_month=$obj_get_dates[prev_month];
		 $start_process_year=$obj_get_dates[prev_year];
		 $to_date_string=$obj_get_dates[to_date_string];
		 $from_date_string=$obj_get_dates[from_date_string];
		$get_variance_details = "select  
							ems_end.component_name as component, 
							ems_end.type as type, 
							 sum(ifnull(ems_end.amount,0)+ifnull(ems_end.arrears,0)) as ems_end_amount,
							sum(ifnull(ems_start.amount,0)+ifnull(ems_start.arrears,0)) as ems_start_amount
							from {$obj_comp->employee_table} emp
							 inner join employee_monthly_salary ems_end  on 
							ems_end.ref_employee_code = emp.internal_code
							and ems_end.month ={$end_process_month} 
							and ems_end.year ={$end_process_year} 		
							and ems_end.amount+ems_end.arrears <> 0 	
							left join employee_monthly_salary ems_start  on 
							ems_start.ref_employee_code = emp.internal_code
							and ems_start.month ={$start_process_month} 
							and ems_start.year ={$start_process_year} 
							and ems_end.ref_salary_component = ems_start.ref_salary_component
							and ems_start.amount+ems_start.arrears  <> 0 
							 group by component
							 
							 union
							 select  
							  ems_start.component_name as component, ems_start.type as type,
							 sum(ifnull(ems_end.amount,0)+ifnull(ems_end.arrears,0)) as ems_end_amount,
							sum(ifnull(ems_start.amount,0)+ifnull(ems_start.arrears,0)) as ems_start_amount
							from {$obj_comp->employee_table} emp
							   inner join 
								employee_monthly_salary ems_start
								 on ems_start.ref_employee_code = emp.internal_code 
								and ems_start.month ={$start_process_month}  and ems_start.year ={$start_process_year}  
								left join employee_monthly_salary ems_end 
								on ems_end.ref_employee_code = emp.internal_code and ems_end.month ={$end_process_month} 
								 and ems_end.year ={$end_process_year}  and ems_end.amount+ems_end.arrears <> 0 
								and ems_end.ref_salary_component = ems_start.ref_salary_component 
								and ems_start.amount+ems_start.arrears <> 0 group by component 
							";					
	$aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=1000000");						
	 //echo $get_variance_details;die();
	$obj_global_result = $aobj_context->mobj_db->GetAll($get_variance_detailss);
	$row=5;
	$col=0;
	$i=0;
	$arr["E_Previous_month"]=0;
	$arr["E_Current_month"]=0;
	$arr["D_Previous_month"]=0;
	$arr["D_Current_month"]=0;
		$worksheet->write($row,0,"Previous Month",$Title_Left);
		$worksheet->write($row,1,'Component Name',$Title_Left);
		$worksheet->write($row,2,'Current Month',$Title_Left);
		$worksheet->write($row,3,"Previous Month",$Title_Left);
		$worksheet->write($row,4,"Component Name",$Title_Left);
		$worksheet->write($row,5,"Current Month",$Title_Left);
		$earning_row=$row+1;
		$ded_row=$row+1;
		$select_distinct_comp="select distinct type,component_name from employee_monthly_salary  order by type,component_name ";
		 $obj_select_distinct_comp = $aobj_context->mobj_db->GetAll($select_distinct_comp);
		 
		 foreach( $obj_select_distinct_comp as $comp_key=>$comp_val)
		 {
			 if($comp_val['type']=='EARNINGS')
			 {
			 $worksheet->write($earning_row,1,$comp_val['component_name'],$Data_Left);
			 $comp_row_arr[$comp_val['component_name']]=$earning_row;$earning_row++;
			 }
			 else if($comp_val['type']=='DEDUCTIONS')
			 {
			 $worksheet->write($ded_row,4,$comp_val['component_name'],$Data_Left);
			 $comp_row_arr[$comp_val['component_name']]=$ded_row;$ded_row++;
			 }		 
		 } 
	$get_cur_month="select  
							ems_end.component_name as component_name, 
							ems_end.type as type, 
							sum(ifnull(ems_end.amount,0)+ifnull(ems_end.arrears,0)) as ems_end_amount  
						 
							from {$obj_comp->employee_table} emp
							 
							inner join employee_monthly_salary ems_end  on 
							ems_end.ref_employee_code = emp.internal_code
							and ems_end.month ={$end_process_month} 
							and ems_end.year ={$end_process_year} 
							group by component_name"; 
		 $obj_get_cur_month = $aobj_context->mobj_db->GetAll($get_cur_month);	
 	 
		  foreach( $obj_get_cur_month as $cur_key=>$cur_val)
		 {
			 if($cur_val['type']=='EARNINGS')
			 {			 
				$worksheet->write( $comp_row_arr[$cur_val['component_name']],2,$cur_val['ems_end_amount'],$Data_Right);
				$arr["E_Current_month"]+=$cur_val['ems_end_amount'];
			 }
			 else if($cur_val['type']=='DEDUCTIONS')
			 {
				$worksheet->write( $comp_row_arr[$cur_val['component_name']],5,$cur_val['ems_end_amount'],$Data_Right);
				$arr["D_Current_month"]+=$cur_val['ems_end_amount'];
			 }		 
		 }
		 
		 $get_prev_month=" select
							ems_start.component_name as component_name, 
							ems_start.type as type, 
							sum(ifnull(ems_start.amount,0)+ifnull(ems_start.arrears,0)) as ems_start_amount  
						 
							from {$obj_comp->employee_table} emp
							 
							inner join employee_monthly_salary ems_start  on 
							ems_start.ref_employee_code = emp.internal_code
							and ems_start.month ={$start_process_month} 
							and ems_start.year ={$start_process_year} 
							group by component_name"; 
		 $obj_get_prev_month = $aobj_context->mobj_db->GetAll($get_prev_month);					
		  foreach( $obj_get_prev_month as $cur_key=>$cur_val)
		 {
			 if($cur_val['type']=='EARNINGS')
			 {			 
				$worksheet->write( $comp_row_arr[$cur_val['component_name']],0,$cur_val['ems_start_amount'],$Data_Right);
				$arr["E_Previous_month"]+=$cur_val['ems_start_amount'];
			 }
			 else if($cur_val['type']=='DEDUCTIONS')
			 {
				$worksheet->write( $comp_row_arr[$cur_val['component_name']],3,$cur_val['ems_start_amount'],$Data_Right);
				$arr["D_Previous_month"]+=$cur_val['ems_start_amount'];
			 }		 
		 }
		 
	//$Title_Left->setNumFormat('##,##,##,##,##0.00');
	for($k=$ded_row;$k<($earning_row);$k++)
		{
	 
		$worksheet->write($k,3,'',$Data_Left);
		$worksheet->write($k,4,''	,$Data_Left);
		$worksheet->write($k,5,''	,$Data_Left);
	 
		} 
		$row=max($ded_row,$earning_row);
		$worksheet->write($row,0,$arr["E_Previous_month"]	,$Data_Right);
		$worksheet->write($row,1,"Gross Earning"	,$Title_Left);
		$worksheet->write($row,2,$arr["E_Current_month"]	,$Data_Right);
		$worksheet->write($row,3,$arr["D_Previous_month"]	,$Data_Right);
		$worksheet->write($row,4,"Gross Deductions"	,$Title_Left);
		$worksheet->write($row,5,$arr["D_Current_month"]	,$Data_Right);
		$worksheet->setColumn(0,5,20);
		
		
		
		$row+=2;
	$emp_data=$obj->fin_arr;
  foreach($emp_data as $emp_key=>$emp_val)
  {
	$worksheet->write($row,0,$emp_key); 
	$worksheet->mergeCells($row,0,$row,1);
	$worksheet->write($row,2,$emp_val); $row++;
  }	
  $doj_details_arr=$obj->doj_details_arr;
			$dor_details_arr=$obj->dor_details_arr;
 
	$row+=2;
	$worksheet->write($row,0,"DOJ Details ",$Data_Left);
	$worksheet->write($row,1,'',$Data_Left);
	$worksheet->write($row,2,'',$Data_Left);
	$worksheet->mergeCells($row,0,$row,2);
	$row+=1;
	$worksheet->write($row,0,"Code ",$Data_Left);
	$worksheet->write($row,1,'Name',$Data_Left);
	$worksheet->write($row,2,'Date Of Joining',$Data_Left);
 $row+=1;
	foreach($doj_details_arr as $doj_k=>$doj_v)
	{
		$worksheet->write($row,0,$doj_v['code'],$Data_Left);
		$worksheet->write($row,1,$doj_v['name'],$Data_Left);
		$worksheet->write($row,2,$doj_v['date'],$Data_Left);		 
		$row+=1;
	}
	$row+=2;
	$worksheet->write($row,0,"DOR Details ",$Data_Left);
	$worksheet->write($row,1,'',$Data_Left);
	$worksheet->write($row,2,'',$Data_Left);
	$worksheet->mergeCells($row,0,$row,2);
	$row+=1;
	$worksheet->write($row,0,"Code ",$Data_Left);
	$worksheet->write($row,1,'Name',$Data_Left);
	$worksheet->write($row,2,'Date Of Resign',$Data_Left);
 $row+=1;
	foreach($dor_details_arr as $dor_k=>$dor_v)
	{
		$worksheet->write($row,0,$dor_v['code'],$Data_Left);
		$worksheet->write($row,1,$dor_v['name'],$Data_Left);
		$worksheet->write($row,2,$dor_v['date'],$Data_Left);		 
		$row+=1;
	}
		 
		
		
}
function populateNonCrossTabReport($lobj_get_final_result,$lobj_get_union_display_cols,$is_sub_tot,$sub_tot_field,$worksheet,$Title_Center,$is_row_total,$is_col_tot,$Title_Right,$is_sl_nos,$freeze_cells,$Data_Right,$Data_Left,$Data_Left_B)
{
 
 
			$row=5;
			$row_header = 3;
			$cell_ids= array();
			if($is_sl_nos)
			{
			$k=0;
			$worksheet->write($row_header,$k,"Sl No", $Title_Center);
			$cell_ids["Sl No"]=$k;
			$k=1;
			}
			else {
			$k=0;}
			for($l=0;$l<count($lobj_get_union_display_cols);$l++)
			{		
					$cell_ids[$lobj_get_union_display_cols[$l]['display_fields']]=$k;
					$worksheet->writeString($row_header,$k,$lobj_get_union_display_cols[$l]['display_fields'], $Title_Center);
					$k++;
			}
			
			$emp_fields_arr=array("Code","Name","Location","Department","Designation",
								"Grade","Date of Joining","Leave Days","Sl No","Paid Days",
								"Lop Days","Month Days","LOP Days");
			$summary_field_names[0]='Net Pay';
			$summary_field_names[1]='Total Deduction Arrears';
			$summary_field_names[2]='Gross Deduction';
			$summary_field_names[3]='Total Earning Arrears';
			$summary_field_names[4]='Gross Earning';
			$summary_field_names[5]='Gross Rate';
			 $summary_field_names[6]='Paid Days';
			 $summary_field_names[7]='Lop Days';
			 $summary_field_names[8]='Month Days';
			 $summary_field_names[9]='Leave Days';
			 
			 $summary_field_total_arr[0]='Net Pay';
			$summary_field_total_arr[1]='Total Deduction Arrears';
			$summary_field_total_arr[2]='Gross Deduction';
			$summary_field_total_arr[3]='Total Earning Arrears';
			$summary_field_total_arr[4]='Gross Earning';
			$summary_field_total_arr[5]='Gross Rate';
			$summary_field_total_arr[6]='OT Hours';
			 //$summary_field_total_arr[6]='Paid Days';
			 //$summary_field_total_arr[7]='Lop Days';
			 
			//$sub_total_col_name='Department';
			$previous_val='';
			$row_total=0;
			$net_pay_sum=0;
			$subtotal=array();
			$r_first=0;
			$sl_no=1;
			foreach($lobj_get_final_result as $lobj_get_final_result_key=>$lobj_get_final_result_val)
			{
			
				foreach($cell_ids as $wek=>$wev)
				{
					if(!in_array($wek,$emp_fields_arr))
					{
					$worksheet->write($row,$wev,0,$Data_Right); 
					}
				}				
				$is_bold_pos = strpos($lobj_get_final_result_val['is_bold'], "1");
				if ($is_bold_pos === false) {
				$is_bold="0";
				}
				else
				$is_bold="1";
				//$is_bold="0";
				 
			 	$row_total=0;
				$total_merge_cols=0;
				
				//to display the SUb Total
				if($sub_tot_field!='' && $is_sub_tot==1)
				{
						foreach($lobj_get_final_result_val as $sum_k=>$sum_v)
						{
							if($sum_k==$sub_tot_field)
							{
								if($r_first==0) 
								{$previous_val=$sum_v; $r_first=1;}
								else 
								{
									if($previous_val!=$sum_v)
									{	
									foreach($cell_ids as $wek=>$wev)
										{
											if(!in_array($wek,$emp_fields_arr))
											{
											$worksheet->write($row,$wev,'',$Data_Right); 
											 
											}
										}
										$row=$row+1;
										foreach($cell_ids as $wek=>$wev)//making location Total Zero first
										{
											if(!in_array($wek,$emp_fields_arr))
											{
											$worksheet->write($row,$wev,0,$Title_Right); 
											 
											}
										}
										foreach($sub_total_val as $s_k1=>$s_v1)
										{
										$worksheet->write($row,$cell_ids[$s_k1],$s_v1,$Title_Right); 
										}
										foreach($summary_field_name_sub_total as $s_k1=>$s_v1)
										{
										 $worksheet->write($row,$cell_ids[$s_k1],$s_v1,$Title_Right); 
										}
										$worksheet->write($row,0,$sub_tot_field." Total",$Title_Right); 
										 $row=$row+2;
										 foreach($cell_ids as $wek=>$wev)
										{
											if(!in_array($wek,$emp_fields_arr))
											{
											$worksheet->write($row,$wev,0,$Data_Right); 
											 
											}
										}
										  $sub_total_val ='';
										 $summary_field_name_sub_total ='';
										 $previous_val=$sum_v;
										$sl_no=1;	
									}
								}
							}
						}	
				} 
				//var_dump($lobj_get_final_result_val); die();
				foreach($lobj_get_final_result_val as $key_2=>$l_v)
				{					
									
					if($key_2!='concate_sal_heads' && $key_2!='is_bold' )
					{
					if(is_numeric($l_v) && $key_2!="Code")
						{
						$cell_format = ($is_bold0=='1')?$Title_Right:$Data_Right;
						}
						else
						{
						$cell_format = ($is_bold=='1' && ($key_2=="Name" or  $key_2=="Code"))?$Data_Left_B:$Data_Left;
						}
					 if(in_array($key_2,$summary_field_names))
					 {
					 $worksheet->write($row,$cell_ids[$key_2],addslashes($l_v),$cell_format);//  
					 }
					else  
					 $worksheet->writeString($row,$cell_ids[$key_2],addslashes($l_v),$cell_format);//  
						
						//to get the sum of the summary fields
						if (in_array($key_2, $summary_field_total_arr)) 
						{
							$row_total+=$l_v;
					 		$summary_field_name_total[$key_2]+=$l_v;
					 		$summary_field_name_sub_total[$key_2]+=$l_v;
							//$subtotal[$query_sub_total_value][$key_2]+=$l_v;
						}
						else $total_merge_cols++;
					}
					else
					{
					
						$comma_split=explode(',',$l_v);
						foreach($comma_split as $c_key )
						{
						 $arrow_split=explode('->',$c_key);
						 $bold_split=explode('!',$arrow_split[1]);
						 $tilde_split=explode("~",$bold_split[1]);
						 $cell_format = ( $bold_split[0]=='1')?$Title_Right:$Data_Right;
						 if($cell_ids[$arrow_split[0]])
						 $worksheet->write($row,$cell_ids[$arrow_split[0]],$tilde_split[0],$cell_format);
						  $salary_field_name_total[$arrow_split[0]]+=$tilde_split[0];
						   $sub_total_val[$arrow_split[0]]+=$tilde_split[0];
							if($tilde_split[1]<>0)
							{
							$arrear_field=$arrow_split[0]." Arrears";
							 if($cell_ids[$arrear_field])
							 $worksheet->write($row,$cell_ids[$arrear_field],$tilde_split[1],$cell_format);
							$salary_field_name_total[$arrear_field]+=$tilde_split[1];
							  $sub_total_val[$arrear_field]+=$tilde_split[1];
							}
						
						 $row_total+=$arrow_split[1];
						}
					}
					if($is_sl_nos)
					{
					$worksheet->write($row,$cell_ids['Sl No'],$sl_no,$cell_format);
					}
					
				}
				
				if($is_row_total==1) {
				  $worksheet->write($row,$k,$row_total,$Title_Right); }  // to write row total here 	
					$row++;
					$sl_no++;
				
			} 
				if($is_row_total==1) $worksheet->write($row_header,$k,'Total', $Title_Center);//for   Rpw Total
				 
				  if($sub_tot_field!='' && $is_sub_tot==1)
					{
					
					 
					foreach($sub_total_val as $s_k1=>$s_v1)
								{
								if($cell_ids[$s_k1])
								$worksheet->write($row,$cell_ids[$s_k1],$s_v1,$Title_Right); 
								}
					foreach($summary_field_name_sub_total as $s_k1=>$s_v1)
								{
								if($cell_ids[$s_k1])
								 $worksheet->write($row,$cell_ids[$s_k1],$s_v1,$Title_Right); 
								}			
					$row+=1;			
					}				
				if($is_col_tot==1)
				{$row+=1;	
				 //$worksheet->mergeCells($row,0,$row,$total_merge_cols-2);
				 
				// $worksheet->write($row,(($total_merge_cols-2)<0)?0:($total_merge_cols-2),'Grand Total',$Title_Right); 
				 $worksheet->write($row,0,'Grand Total',$Title_Right); 
					// To display the Total value of summary fields as cols
					foreach($summary_field_name_total as $s_k=>$s_v)
					{
					if($cell_ids[$s_k])
					 $worksheet->write($row,$cell_ids[$s_k],$s_v,$Title_Right); 
					}
					// To display the Total value of salary fields
					foreach($salary_field_name_total as $sal_k=>$sal_v)
					{
					 if($cell_ids[$sal_k])
					 $worksheet->write($row,$cell_ids[$sal_k],$sal_v,$Title_Right); 
					}
				}
			   if(!empty($freeze_cells))
			   {
			   $split_freeze_arr=explode(",",$freeze_cells);
			   $worksheet->freezePanes($split_freeze_arr);
			   }
				 
}
function populateCrossTabReport($aobj_context,$get_final_result,$cross_tab_cols,$final_excel_display_col,$worksheet,$Title_Center,$Title_Right,$is_sl_nos,$freeze_cells)
{
	$row_cols=explode(',',substr($cross_tab_cols,1));
	$row_field=$row_cols[0];
	$col_field=$row_cols[1];
	 
	$final_excel_display_col=str_ireplace(',','/',$final_excel_display_col);
	 $get_all_col_fields="select distinct  {$col_field} as   name  from ({$get_final_result}) a order by 1";
	 $lobj_get_all_col_fields = $aobj_context->mobj_db->GetAll($get_all_col_fields);	
//echo $get_final_result; die();
	
		$row=4;
		$row_header = 3;
		if($is_sl_nos)
		{
		$worksheet->write($row_header,0,"Sl No", $Title_Center);
		$worksheet->write($row_header,1,$final_excel_display_col, $Title_Center);
		$k=2;
		}
		else
		{
		$worksheet->write($row_header,0,$final_excel_display_col, $Title_Center);
		$k=1;
		}
		$cell_ids= array();
		for($l=0;$l<count($lobj_get_all_col_fields);$l++)
		{	
				$cell_ids[$lobj_get_all_col_fields[$l]['name']]=$k;
				$worksheet->write($row_header,$k,$lobj_get_all_col_fields[$l]['name'], $Title_Center);
				$k++;
		}
		 
		$worksheet->write($row_header,$k,'Total',$Title_Center); 
		$get_final_data="select {$row_field},GROUP_CONCAT({$col_field},'~',concate_sal_heads) as amount 
		from ({$get_final_result}) a group by {$row_field}  "	;
		$aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=1000000");	
		$lobj_get_final_data = $aobj_context->mobj_db->GetAll($get_final_data);	
	 
		$cell_id=1;
		$sl_no=1;
		for($m=0;$m<count($lobj_get_final_data);$m++)
		{
				$row_total=0;
				
				
				if($is_sl_nos)
				{
				$worksheet->write($row,0,$sl_no, $Title_Center);
				$worksheet->write($row,1,$lobj_get_final_data[$m][$row_field]);
				}
				else
					$worksheet->write($row,0,$lobj_get_final_data[$m][$row_field]);
				$comma_split=explode(',',$lobj_get_final_data[$m]['amount']);
				//Assigning 0.0 to all Cells
					 foreach ($cell_ids as $j=>$v)
					{
					 $worksheet->write($row,$v,0.0); 
					}  
						foreach($comma_split as $c_key )
						{
						 $arrow_split=explode('->',$c_key);
						 $pos = strpos($arrow_split[0],'~');
						 $cell_name=substr($arrow_split[0],0,($pos));
						 
						 //echo $cell_name.$arrow_split[1]; die();
						 $worksheet->write($row,$cell_ids[$cell_name],$arrow_split[1]); 
						 $col_total[$cell_name]+=$arrow_split[1];
						 $row_total+=$arrow_split[1];
		 				}
			 $worksheet->write($row,$k, $row_total,$Title_Right); 			
			$row++;	
			$sl_no++;
		}
			// to display col Total
				$worksheet->write($row,0,"Total",$Title_Center);
				foreach($col_total as $sal_k=>$sal_v)
					{
					 $worksheet->write($row,$cell_ids[$sal_k],$sal_v,$Title_Right); 
					}
		 if(!empty($freeze_cells))
			   {
			   $split_freeze_arr=explode(",",$freeze_cells);
			   $worksheet->freezePanes($split_freeze_arr);
			   }			
}
function deletereportSetup($aobj_context)
{
	$id = ($aobj_context->mobj_data["id"]);
	
	$delete_header="delete from report_header where internal_code in({$id})";
	$delete_report_detail_conditions="delete from report_detail_conditions where ref_report_header_code in({$id})";
	$delete_report_detail_emp_columns="delete from report_detail_emp_columns where ref_report_header_code in({$id})";
	$delete_report_detail_sal_columns="delete from report_detail_sal_columns where ref_report_header_code in({$id})";
	$delete_report_detail_summary_columns="delete from report_detail_summary_columns where ref_report_header_code in({$id})";
	
	$lobj = $aobj_context->mobj_db->Execute($delete_header);
	$lobj = $aobj_context->mobj_db->Execute($delete_report_detail_conditions);
	$lobj = $aobj_context->mobj_db->Execute($delete_report_detail_emp_columns);
	$lobj = $aobj_context->mobj_db->Execute($delete_report_detail_sal_columns);
	$lobj = $aobj_context->mobj_db->Execute($delete_report_detail_summary_columns);
}
?>