Reputation: 1138
I want to create the leave report of employee in calender table view as attached image.
i have fetched employee from controller and stored in and array.
same way i am fetching the dates(based on selected year and month) in controller and stored in an array.
based on this employee and date, i am fetching the leaves of each employee and stored in an array.
controller
$month = 7;
$year = 2015;
for($d=1; $d<=31; $d++)//for dynamic dates as displayed in image
{
$time=mktime(12, 0, 0, $month, $d, $year);
if (date('m', $time)==$month)
$this->data['blk4'][]['date']=date('d', $time);
$this->data['blk5'][]['day']=date('D', $time);
$this->data['blk6'][]['fulldates']=date('Y-m-d',$time);
}
$data['employee'] = $this->teamprofile_model->allTeamMembers('team_profile_full_name', 'ASC');//fetching all amployee
foreach($data['employee'] as $d)//for each employee checking the leave
{
foreach($this->data['blk6'] as $date)//for each date
{
$this->db->where('employee_id',$d['team_profile_id']);
$this->db->where('leave_date',$date['dates']);
$Q=$this->db->get('leave_reports');
if($Q->num_rows() > 0)
{
foreach ($Q->result_array() as $row)
{
$data1[] = $row;
}
}
$this->data['blk8'][]['leave'] = $data1[0]['leave_time'];//stored leave of each employee in this array
$data1="";
}
}
HTML
<table class="footable table table-bordered table-hover" border="1">
<thead>
<tr>
<th>Employee</th>//display employee
<th><!--[blk4.date;block=th;comm]--><br/><!--[blk5.day;block=th;comm]--></th> //display dates as displying in above image
</tr>
</thead>
<tbody class="">
<tr>
<td><!--[blk7.all_team_members;block=tr;comm]--></td>//dynamic employee list
<td>here i want to display the leave stored in [blk8.leave]</td>
</tr>
</tbody>
</table>
but the problem is that the [blk8.leave] stored all employees leave of each dates so if i print it as [blk8.leave;block=td;comm] then it print all array value in one row. I want to break this array after month's end date that is 31.
output should be :
Upvotes: 1
Views: 469
Reputation: 5552
The problem is your Leave data is structured linearly while it need to be associated with a date.
TBS (TinyButStrong) as a built in feature for merging tables with dynamics columns (or other similar structure).
The example under is very similar to your problem, you can adapt it easily. http://www.tinybutstrong.com/examples.php?e=dyncol1
But the structure of your data should be amended. Here is an example of how the data could be:
$blk7 = array();
foreach($data['employee'] as $d)//for each employee checking the leave
{
$employee = array(
'team_profile_id' => $d['team_profile_id'],
'all_team_members' => $d['all_team_members'],
);
foreach($this->data['blk6'] as $date)//for each date
{
$this->db->where('employee_id',$d['team_profile_id']);
$this->db->where('leave_date',$date['dates']);
$Q=$this->db->get('leave_reports');
if($Q->num_rows() > 0)
{
foreach ($Q->result_array() as $row)
{
$data1[] = $row;
}
}
$column = 'leave_' . $date['dates'];
$employee[$column] = $data1[0]['leave_time'];//stored leave of each employee in this array
$data1="";
}
$blk7[] = $employee;
}
Upvotes: 1