Как сделать цикл для экспорта посещаемости нескольких пользователей в Excel, используя codeigniter

$getdateRangeVal = $this->getdaterange($from, $to);
$arrstatus = array();
$arrEmp = array();
foreach($_data as $mp) {
$empdata[] = array(
'emp_primary' => $mp->emp_primary,
'date' => $mp->date,
);
}



foreach ($_data as $value) {
$arrstatus[$value->emp_primary] = $value;
for($i = 0; $i<sizeof($getdateRangeVal); $i++){
$compare = array("date"=>$getdateRangeVal[$i],"emp_primary"=>$value->emp_primary);
$key = array_search($compare, $empdata);
if(strlen($key) > 0) {

$arrstatus[$value->emp_primary]->dateRange[] = array(
"status" => "P",
"getdateRangeVal" => $getdateRangeVal[$i],
"intime" => $_data[$key]->in_time,
"outtime" => $_data[$key]->out_time,
"totaltime" => $_data[$key]->total_time,
);
} else {
$arrstatus[$value->emp_primary]->dateRange[] = array(
"status"=>"A",
"getdateRangeVal"=>$getdateRangeVal[$i],
"intime" => "",
"outtime" => "",
"totaltime" => "",
);

}
}
}


$sheet->setCellValue('A5', 'EMP ID');
$sheet->setCellValue('D5', 'EMP NAME');
$sheet->setCellValue('A6', 'Days');
$sheet->setCellValue('A7', 'Status');
$sheet->setCellValue('A8', 'IN time');
$sheet->setCellValue('A9', 'Out time');
$sheet->setCellValue('A10', 'Total time');

$arr = array(

'0' => 'B',
'1' => 'C',
'2' => 'D',
'3' => 'E',
'4' => 'F',
'5' => 'G',
'6' => 'H',
'7' => 'I',
'8' => 'J',
'9' => 'K',
'10' => 'L',
'11' => 'M',
'12' => 'N',
'13' => 'O',
'14' => 'P',
'15' => 'Q',
'16' => 'R',
'17' => 'S',
'18' => 'T',
'19' => 'U',
'20' => 'V',
'21' => 'W',
'22' => 'X',
'23' => 'Y',
'24' => 'Z',
'25' => 'AA',
'26' => 'AB',
'27' => 'AC',
'28' => 'AD',
'29' => 'AE',
'30' => 'AF',
);

$i= 0;

$rowCount = 6;
$statusCount = 7;
$inCount = 8;
$outCount = 9;
$totalCount = 10;
$employeeId= $empdata[$i]['emp_primary'];

foreach($arrstatus[$employeeId]->dateRange as $val){
$sheet->setCellValue($arr[$i].$rowCount, date('j D',strtotime($val['getdateRangeVal'])));
if($val['status'] == 'P'){
$sheet->setCellValue($arr[$i].$statusCount, $val['status']);
}else{
$sheet->setCellValue($arr[$i].$statusCount, $val['status']);
}
$sheet->setCellValue($arr[$i].$inCount,$val['intime']);
$sheet->setCellValue($arr[$i].$outCount, $val['outtime']);
$sheet->setCellValue($arr[$i].$totalCount, $val['totaltime']);
$i++;

}

===================================

Это мои данные

Array
(
[1] => stdClass Object
(
[firstname] => Amol
[lastname] => Auti
[enrollment] => 123456789
[designation] => Android Developer
[department] => Development
[emp_primary] => 1
[emp_id] => 1001
[company_name] => Maverick Solution
[logo] => logo-1-1535090442cbrand-img6.png
[company_address] => Cidco N-4
[id] => 5
[in_time] => 09:00:00
[out_time] => 9:00:00
[total_time] => 00:00:00.000000
[date] => 2018-08-06
[device_id] => 12:12:12:12
[dateRange] => Array
(
[0] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-01
[intime] =>
[outtime] =>
[totaltime] =>
)

[1] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-02
[intime] =>
[outtime] =>
[totaltime] =>
)

[2] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-03
[intime] =>
[outtime] =>
[totaltime] =>
)

[3] => Array
(
[status] => P
[getdateRangeVal] => 2018-08-04
[intime] => 09:00:00
[outtime] => 16:00:00
[totaltime] => 07:00:00.000000
)

[4] => Array
(
[status] => P
[getdateRangeVal] => 2018-08-05
[intime] => 09:00:00
[outtime] => 16:00:00
[totaltime] => 07:00:00.000000
)

[5] => Array
(
[status] => P
[getdateRangeVal] => 2018-08-06
[intime] => 09:00:00
[outtime] => 9:00:00
[totaltime] => 00:00:00.000000
)

[6] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-07
[intime] =>
[outtime] =>
[totaltime] =>
)

[7] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-08
[intime] =>
[outtime] =>
[totaltime] =>
)

[8] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-09
[intime] =>
[outtime] =>
[totaltime] =>
)

[9] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-10
[intime] =>
[outtime] =>
[totaltime] =>
)

)

)

[2] => stdClass Object
(
[firstname] => Sumit
[lastname] => Malusare
[enrollment] => 135454
[designation] => Web Developer
[department] => Development
[emp_primary] => 2
[emp_id] => 1002
[company_name] => Maverick Solution
[logo] => logo-1-1535090442cbrand-img6.png
[company_address] => Cidco N-4
[id] => 20
[in_time] => 09:00:00
[out_time] => 18:00:00
[total_time] => 09:00:00.000000
[date] => 2018-08-05
[device_id] => 12:12:12:12
[dateRange] => Array
(
[0] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-01
[intime] =>
[outtime] =>
[totaltime] =>
)

[1] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-02
[intime] =>
[outtime] =>
[totaltime] =>
)

[2] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-03
[intime] =>
[outtime] =>
[totaltime] =>
)

[3] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-04
[intime] =>
[outtime] =>
[totaltime] =>
)

[4] => Array
(
[status] => P
[getdateRangeVal] => 2018-08-05
[intime] => 09:00:00
[outtime] => 18:00:00
[totaltime] => 09:00:00.000000
)

[5] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-06
[intime] =>
[outtime] =>
[totaltime] =>
)

[6] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-07
[intime] =>
[outtime] =>
[totaltime] =>
)

[7] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-08
[intime] =>
[outtime] =>
[totaltime] =>
)

[8] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-09
[intime] =>
[outtime] =>
[totaltime] =>
)

[9] => Array
(
[status] => A
[getdateRangeVal] => 2018-08-10
[intime] =>
[outtime] =>
[totaltime] =>
)

)

)

)

===========================
Я должен напечатать так

Report - Attendance Sheet
Duration - 1-Aug-18 TO 10-Aug-18
Name    Amol Auti
Emp code    1001
Enrollment number   123456789
Department  Development Designation Android Developer
Date    1-Aug   2-Aug   3-Aug   4-Aug   5-Aug   6-Aug   7-Aug   8-Aug   9-Aug   10-Aug
Status  A   A   A   P   P   P   A   A   A   A
In Time -   -   -   09:00:00    09:00:00    09:00:00    -   -   -   -
Out Time    -   -   -   16:00:00    16:00:00    9:00:00 -   -   -   -
Total Time  -   -   -   07:00:00.000000 07:00:00.000000 00:00:00.000000 -   -   -   -
Name    Sumit Malusare  Emp code    1002
Enrollment number   135454
Department  Development
Designation Web Developer
Date    1-Aug   2-Aug   3-Aug   4-Aug   5-Aug   6-Aug   7-Aug   8-Aug   9-Aug   10-Aug
Status  A   A   A   A   P   A   A   A   A   A
In Time -   -   -   -   09:00:00    -   -   -   -   -
Out Time    -   -   -   -   18:00:00    -   -   -   -   -
Total Time  -   -   -   -   09:00:00.000000 -   -   -   -   -

0

Решение

Если вы собираетесь экспортировать это в Excel, вам нужно использовать библиотеку для этого.

Вот замечательный учебник о том, как конвертировать ваши данные в файл Excel.

https://arjunphp.com/how-to-use-phpexcel-with-codeigniter/.

это то, что я сейчас использую в своем проекте. надеюсь, это поможет.

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]