Hi,
i am doing my report for employee leave calculation.
my criteria for selection is : year, month,and department.
based on that i want to search that particular employee name Jack has taken leave 90 days. leave start date is :1-8-2014 to 31-10-2014. leave already approved.in my leave application table field leave_application_days:90 ,
my problem is that when i select august month it shows me 30 days.but when i give september then it will give 0 days.
is it possible to get date of september months start date ?
i have yar,month value…leave_start_date,end_date…
below is my code…
<?php
$this->breadcrumbs=array('Report',
'Employee Leave Info ',
);
if(isset($_POST['department']))
{
$dept=$_POST['department'];
}
$this->menu[]= array('label'=>'', 'url'=>array('EmployeeLeaveInfoReport','excel'=>'excel','months'=>$month,'year'=>$yr,'department'=>$dept),'linkOptions'=>array('class'=>'export-excel','title'=>'Export to Excel','target'=>'_blank'));
$months = array();
$year=date('Y');
for( $i = 1; $i <= 12; $i++ )
{
$months[ $i ] = strftime( '%B', mktime( 0, 0, 0, $i, 1 ));
}
for($j=2012;$j<=$year;$j++)
{
$yearValue[$j]=$j;
}
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'employee-leave-info-form',
'enableAjaxValidation'=>true,
)); ?>
<div class="row">
<?php echo CHtml::label(Yii::t('demo','Year'),'year'); ?>
<?php echo CHtml::dropdownlist('year','',$yearValue,array('prompt'=>'Select Year','options'=>array($yr=>array('selected'=>true))));
?>
</div>
<div class="row">
<?php echo CHtml::label(Yii::t('demo', 'Month'), 'month'); ?>
<?php echo CHtml::dropDownList('months', '' , $months, array('prompt'=>'Select Month','options' =>array($month=>array('selected'=>true)))); ?>
</div>
<div class="row">
<?php echo CHtml::label(Yii::t('demo', 'Department'), 'department'); ?>
<?php echo CHtml::dropDownList('department', '',CHtml::listData(Department::model()->findAll(array('condition'=>'department_organization_id='.Yii::app()->user->getState('org_id'))), 'department_id','department_name'),array('empty'=>'Select Department','options' =>array($dept=>array('selected'=>true)),));?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit', array('class'=>'submit')); ?>
</div>
<?php $this->endWidget(); ?>
</div> <!-- div form end-->
<?php
if(isset($yr)&& isset($month))
{
$month_value = $month;
$num = cal_days_in_month(CAL_GREGORIAN, $month_value, date('Y'));
$colspan=$num+9;
if($employee)
{
$m=0;
$day_count=0;
$org_data = Organization::model()->findByPk(Yii::app()->user->getState('org_id'));
//echo '<div class="table-title"><b> Employee Leave Info Report</b></div>';
echo "<table border='0' class='table_data'>";
echo "<thead>";
echo "<tr> <th colspan = ".$colspan." style=text-align:left;> ".CHtml::image(Yii::app()->controller->createUrl('/site/loadImage', array('id'=>Yii::app()->user->getState('org_id'))),'No Image',array('width'=>80,'height'=>55,'style'=>'float:left;margin-left:400px;')) ."
<big> <b>".$org_data->organization_name ."</big><br>". $org_data->address_line1." ".$org_data->address_line2."</br>"
. City::model()->findBypk(Organization::model()->findByPk(Yii::app()->user->getState('org_id'))->city)->city_name.", ".State::model()->findBypk(Organization::model()->findByPk(Yii::app()->user->getState('org_id'))->state)->state_name.", ".Country::model()->findBypk(Organization::model()->findByPk(Yii::app()->user->getState('org_id'))->country)->name."." ." </th> <br> </tr>";
echo "<tr><th colspan=15 ><big> Employee Leave Report For Month- ".date("F", mktime(0,0,0,$month)).'-'.$yr."</big></th></tr>";
echo "<tr><th rowspan=2 > <b>SI No.</b></th>";
echo "<th rowspan=2> <b> Employee Name </b></th>";
foreach($leave as $lv)
{
echo "<th>".$lv['leave_master_category']."</th>";
}
echo "</tr></thead>";
foreach($employee as $emp)
{
if(($m%2) == 0)
{
$class = "odd";
}
else
{
$class = "even";
}
echo '<tr class='.$class.'>';
echo '<td>';
echo ++$m;
echo '</td>';
echo "<td>";
echo $emp['title'].''.$emp['employee_first_name'].' '.$emp['employee_last_name'].' ( '.$emp['employee_name_alias'].' )';
echo "</td>";
$org = Yii::app()->user->getState('org_id');
$first = date('Y-m-d', mktime(0, 0, 0, $month_value, 1, date('Y')));
foreach($leave as $lv) //
{
$count=0;
$totalLeave=EmployeeLeaveApplication::model()->findAll(array('condition'=>
'(month(employee_leave_application_leave_start_date)='.$month_value.' OR
month(employee_leave_application_leave_end_date)='.$month_value.') AND
(year(employee_leave_application_leave_start_date)='.$yr.' OR
year(employee_leave_application_leave_end_date)='.$yr.') AND employee_leave_application_employee_code='.$emp['employee_id'].' AND employee_leave_application_leave_code='.$lv['leave_master_id'].' AND
employee_leave_application_org_id='.$org.' AND employee_leave_application_status_2=2'
));
$diff=0;
foreach($totalLeave as $leave_app)
{
$startdate_month=date_format(new DateTime($leave_app->employee_leave_application_leave_start_date), 'm');
$enddate_month=date_format(new DateTime($leave_app->employee_leave_application_leave_end_date), 'm');
$start_date=date_format(new DateTime($leave_app->employee_leave_application_leave_start_date),'d');
$end_date=date_format(new DateTime($leave_app->employee_leave_application_leave_end_date),'d');
//echo $startdate_month.' '.$enddate_month.' '.$start_date.' '.$end_date;exit;
if($startdate_month==$enddate_month)
$count+=$leave_app->employee_leave_application_days;
else
{
$month_days=cal_days_in_month(CAL_GREGORIAN,$month_value, $yr);
$start_date=date_format(new DateTime($leave_app->employee_leave_application_leave_start_date),'d');
$end_date=date_format(new DateTime($leave_app->employee_leave_application_leave_end_date),'d');
$count+=$month_days-$start_date;
}
$diff=$end_date-$start_date;
}
echo"<td>". $diff.' '.$count."</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
else
{
print "<h1 style=\"color:red;text-align:center\">No Record To Display</h1>";
} ?>
and this is my action code
public function actionEmployeeLeaveInfoReport()
{
$baseUrl = Yii::app()->baseUrl;
$cs = Yii::app()->getClientScript();
$cs->registerCssFile($baseUrl.'/css/report.css');
$model= new Department;
$dept=null;
$employee=array();
$month=null;
$yr=null;
$leave=0;
$query=null;
if( !empty($_POST['year']) || !empty($_REQUEST['year']) )
{
$yr = $_REQUEST['year'];
if( !empty($_REQUEST['months']) )
{
$month = $_REQUEST['months'];
if(!empty($_REQUEST['department']))
{
$dept= $_REQUEST['department'];
$query .= "emp.employee_transaction_department_id=".$dept. " AND ";
}
$employee =Yii::app()->db->createCommand()
->select('*')
->from('employee_transaction emp')
->join('employee_info emp_info', 'emp_info.employee_info_transaction_id = emp.employee_transaction_id')
->join('department d','d.department_id=emp.employee_transaction_department_id')
->where($query.'emp.employee_status =0 AND emp.employee_transaction_organization_id='.Yii::app()->user->getState('org_id').' order by department_name ASC, employee_first_name ASC' )
->queryAll();
$leave=Yii::app()->db->createCommand()
->select('leave_master_category,leave_master_id')
->from('leave_master lm')
->queryAll();
}
}
if(isset($_REQUEST['excel']))
{
Yii::app()->request->sendFile(date('YmdHis').'.xls',
$this->renderPartial('employee_leave_info_report_excel', array(
'month'=>$_REQUEST['months'],
'employee'=>$employee,
'yr'=>$yr,
'dept'=>$dept,
'leave'=>$leave,
),true));
}
$this->render('employee_leave_info_report',array('employee'=>$employee,'month'=>$month,'yr'=>$yr,'leave'=>$leave,'dept'=>$dept));
}