данный отчет выводит данные
ниже выводится список всех сотрудников с данными полями |
собираем данные
//подразделения
$arSubdivisions = CIBlockSection::GetList(Array("SORT"=>"ASC"), Array("IBLOCK_ID" => 1), false, Array(), false);
$arResult['SUBDIVISION'] = [];
while($row = $arSubdivisions->Fetch()){
$arResult['SUBDIVISION'][$row['ID']] = [
"NAME" => $row['NAME']
];
}
$data = CUser::GetList(($by="ID"), ($order="ASC"),
array(
'GROUPS_ID' => ['11'], //группа сотрудники
'ACTIVE' => 'Y',
),
array(
'SELECT' => array("UF_GRADE","UF_DEPARTMENT"),
'NAV_PARAMS' => array(
'nTopCount' => 100
),
'FIELDS' => array(
'ID',
'NAME',
'LAST_NAME',
'PERSONAL_GENDER',
'PERSONAL_BIRTHDAY',
'PERSONAL_CITY'
),
)
);
$arResult["USERS"] = [];
$date = time();
$grade = 0;
$cnt = 0;
$age = 0;
$male = 0;
$female = 0;
$nomale = 0;
$findGender = 0;
$findDate = 0;
$arCities = [];
$arCitiesCnt = [];
while($arUser = $data->Fetch()) {
if($arUser["ID"]==812) continue; //сотрудник для тестов, не нужен в отчете
$cnt++;
$grade += intval($arUser["UF_GRADE"]);
if(!empty($arUser["PERSONAL_BIRTHDAY"])){
$age += date('Y',($date - strtotime($arUser["PERSONAL_BIRTHDAY"]))) - 1970;
$findDate++;
}
if(!empty($arUser['PERSONAL_GENDER'])){
if($arUser['PERSONAL_GENDER']=="M"){
$male++;
}
else{
$female++;
}
$findGender++;
}
else{
$nomale;
}
if(!empty($arUser['PERSONAL_CITY'])){
if(!in_array($arUser['PERSONAL_CITY'], $arCities)){
$arCities[] = $arUser['PERSONAL_CITY'];
$arCitiesCnt[] = 1;
}
else{
$arCitiesCnt[array_search($arUser['PERSONAL_CITY'],$arCities)] += 1;
}
}
$arUser["UF_DEPARTMENT"] = $arUser["UF_DEPARTMENT"][0];
$arResult["USERS"][$arUser["UF_DEPARTMENT"]][] = $arUser;
$arUser["UF_DEPARTMENT"] = $arResult["SUBDIVISION"][$arUser["UF_DEPARTMENT"]]["NAME"];
$arUser["PERSONAL_GENDER"] = str_replace(['M','F'], ['муж','жен'], $arUser["PERSONAL_GENDER"]);
$arResult["ROWS"][] = ['data'=>$arUser,'action'=>[]];
}
$arResult["TOTAL_USERS"] = $cnt;
$arResult["GRADE_MIDDLE"] = round($grade / $cnt, 2);
$arResult["MIDDLE_AGE"] = round($age/$findDate, 2);
$arResult["MALE"] = round($male*100/$findGender,2);
$arResult["FEMALE"] = round($female*100/$findGender,2);
//$arResult["NOMALE"] = $nomale;
$arResult["CITIES"] = $arCities;
$arResult["CITIES_CNT"] = $arCitiesCnt;
if(!CModule::IncludeModule("iblock")) {
ShowError("CIBlockSection_NOT_INSTALLED");
return false;
}
//подразделения
foreach ($arResult['SUBDIVISION'] as $id => &$arDivision) {
$grade = 0;
$cnt = 0;
$age = 0;
$male = 0;
$female = 0;
$findGender = 0;
$findDate = 0;
$arCities = [];
$arCitiesCnt = [];
foreach ($arResult["USERS"][$id] as $arUser) {
$cnt++;
$grade += intval($arUser["UF_GRADE"]);
if(!empty($arUser["PERSONAL_BIRTHDAY"])){
$age += date('Y',($date - strtotime($arUser["PERSONAL_BIRTHDAY"]))) - 1970;
$findDate++;
}
if(!empty($arUser['PERSONAL_GENDER'])){
if($arUser['PERSONAL_GENDER']=="M"){
$male++;
}
else{
$female++;
}
$findGender++;
}
if(!empty($arUser['PERSONAL_CITY'])){
if(!in_array($arUser['PERSONAL_CITY'], $arCities)){
$arCities[] = $arUser['PERSONAL_CITY'];
$arCitiesCnt[] = 1;
}
else{
$arCitiesCnt[array_search($arUser['PERSONAL_CITY'],$arCities)] += 1;
}
}
}
$arDivision = [
"NAME" => $arDivision['NAME'],
"TOTAL_USERS" => $cnt++,
"GRADE_MIDDLE" => round($grade / $cnt, 2),
"MIDDLE_AGE" =>$findDate ?round($age/$findDate, 2) : 0,
"MALE" => $findGender ? round($male*100/$findGender,2) : 0,
"FEMALE" => $findGender ? round($female*100/$findGender,2) : 0,
"CITIES" => $arCities,
"CITIES_CNT" => $arCitiesCnt
];
}
//для вывода списка сотрудников
$arResult['columns'] = [
['id' => 'ID', 'name' => 'ID', 'sort' => '1', 'default' => true],
['id' => 'LAST_NAME', 'name' => 'Фамилия', 'sort' => '2', 'default' => true],
['id' => 'NAME', 'name' => 'Имя', 'sort' => '3', 'default' => true],
['id' => 'PERSONAL_GENDER', 'name' => 'Пол', 'sort' => '1', 'default' => true],
['id' => 'PERSONAL_BIRTHDAY', 'name' => 'День рождения', 'sort' => '1', 'default' => true],
['id' => 'PERSONAL_CITY', 'name' => 'Город', 'sort' => '1', 'default' => true],
['id' => "UF_GRADE", 'name' => "Уровень(грейд)", 'sort' => '1', 'default' => true],
['id' => "UF_DEPARTMENT", 'name' => "Подразделение", 'sort' => '1', 'default' => true],
];
|
выводим
<h2>Компания</h2>
<table class="report" cellspacing="0">
<tr><td >Всего сотрудников</td><td><?=$arResult["TOTAL_USERS"]?></td></tr>
<tr><td>Средний грейд</td><td><?=$arResult["GRADE_MIDDLE"]?></td></tr>
<tr><td>Средний возраст</td><td><?=$arResult["MIDDLE_AGE"]?></td></tr>
<tr><td>Женщин</td><td><?=$arResult["FEMALE"]?>%</td></tr>
<tr><td>Мужчин</td><td><?=$arResult["MALE"]?>%</td></tr>
<tr><td>Города</td><td>
<?foreach ($arResult["CITIES"] as $keyCity => $city):?>
<?=$city?>(<?=$arResult["CITIES_CNT"][$keyCity]?>)
<?endforeach;?>
</td></tr>
<!-- <tr><td></td><td></td></tr> -->
</table>
<h2>По подразделениям</h2>
<table class="report" cellspacing="0">
<?foreach ($arResult['SUBDIVISION'] as $arDivision):?>
<tr><th colspan="2"><?=$arDivision["NAME"]?></th></tr>
<tr><td >Cотрудников</td><td><?=$arDivision["TOTAL_USERS"]?></td></tr>
<tr><td>Средний грейд</td><td><?=$arDivision["GRADE_MIDDLE"]?></td></tr>
<tr><td>Средний возраст</td><td><?=$arDivision["MIDDLE_AGE"]?></td></tr>
<tr><td>Женщин</td><td><?=$arDivision["FEMALE"]?>%</td></tr>
<tr><td>Мужчин</td><td><?=$arDivision["MALE"]?>%</td></tr>
<tr><td>Города</td><td>
<?foreach ($arDivision["CITIES"] as $keyCity => $city):?>
<?=$city?>(<?=$arDivision["CITIES_CNT"][$keyCity]?>)
<?endforeach;?>
</td></tr>
<?endforeach;?>
</table>
<h2>Список сотрудников</h2>
<?
$APPLICATION->IncludeComponent('bitrix:main.ui.grid', '', [
'GRID_ID' => "hr_report",
'COLUMNS' => $arResult['columns'],
'ROWS' => $arResult['ROWS'],
'SHOW_ROW_CHECKBOXES' => false,
'NAV_OBJECT' => $arResult['nav'],
'AJAX_MODE' => 'Y',
'AJAX_ID' => \CAjax::getComponentID('bitrix:main.ui.grid', '.default', ''),
'PAGE_SIZES' => [
['NAME' => '100', 'VALUE' => '100']
],
'AJAX_OPTION_JUMP' => 'N',
'SHOW_CHECK_ALL_CHECKBOXES' => false,
'SHOW_ROW_ACTIONS_MENU' => true,
'SHOW_GRID_SETTINGS_MENU' => true,
'SHOW_NAVIGATION_PANEL' => true,
'SHOW_PAGINATION' => false,
'SHOW_SELECTED_COUNTER' => true,
'SHOW_TOTAL_COUNTER' => true,
'SHOW_PAGESIZE' => true,
'SHOW_ACTION_PANEL' => true,
'ALLOW_COLUMNS_SORT' => true,
'ALLOW_COLUMNS_RESIZE' => true,
'ALLOW_HORIZONTAL_SCROLL' => true,
'ALLOW_SORT' => true,
'ALLOW_PIN_HEADER' => true,
'AJAX_OPTION_HISTORY' => 'N'
]); |