Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\models;
- use Yii;
- use yii\db\Query;
- use yii\base\Model;
- use app\modules\personnel\models\Employee;
- class Site extends Model
- {
- private $query;
- private $employee_amount;
- public function __construct()
- {
- $this->query = new Query;
- $this->employee_amount = Employee::find()->count();
- }
- public function getDataGenderGrafik()
- {
- /* ##### GENDER ##### */
- // Get all employee with select field education_id
- $this->query->select('gender_id')->from('employees');
- $employee_gender_id = $this->query->all();
- // Loop value from $employee_gender_id
- foreach ($employee_gender_id as $value) {
- if ($value['gender_id'] == 1177) {
- $gender_group['male'][] = $value;
- } else {
- $gender_group['female'][] = $value;
- }
- }
- // Set $count_edu_group into array
- $count_gender_group = [];
- // Loop again with use $gender_group
- foreach ($gender_group as $gender_groups => $gender_group_value) {
- $count_gender_group[$gender_groups] = count($gender_group_value);
- }
- // Count
- $employee_gender['male'] = $count_gender_group['male'] / $this->employee_amount * 100;
- $employee_gender['female'] = $count_gender_group['female'] / $this->employee_amount * 100;
- return $employee_gender;
- }
- public function getDataEducationGrafik()
- {
- // Get all employee with select field education_id
- $this->query->select('education_id')->from('employees');
- $employee_education_id = $this->query->all();
- // Loop value from $employee_education_id
- foreach ($employee_education_id as $value) {
- if ($value['education_id'] == 1219) {
- $edu_group['s1'][] = $value;
- } elseif ($value['education_id'] == 1220) {
- $edu_group['s2'][] = $value;
- } elseif ($value['education_id'] == 1221) {
- $edu_group['s3'][] = $value;
- } else {
- $edu_group['others'][] = $value;
- }
- }
- // Set $count_edu_group into array
- $count_edu_group = [];
- // Loop again with use $edu_group
- foreach ($edu_group as $edu_groups => $edu_group_value) {
- $count_edu_group[$edu_groups] = count($edu_group_value);
- }
- // Count
- $employee_education['s1'] = $count_edu_group['s1'] / $this->employee_amount * 100;
- $employee_education['s2'] = $count_edu_group['s2'] / $this->employee_amount * 100;
- $employee_education['s3'] = $count_edu_group['s3'] / $this->employee_amount * 100;
- $employee_education['others'] = $count_edu_group['others'] / $this->employee_amount * 100;
- return $employee_education;
- }
- public function getDataDateBirthGrafik()
- {
- $formatter = \Yii::$app->formatter;
- $date_linux = Yii::$app->formatter->asdateTime('now', 'php:Y-m-d');
- // Get array of birth_date and return record on query result
- $this->query->select('birth_date')->from('employees');
- $employee_birth_date = $this->query->all();
- // Loop value from $employee_birth_date
- foreach ($employee_birth_date as $value) {
- // Set into normal format Date
- $cli_birth_date = Yii::$app->formatter->asDate($value['birth_date']);
- // Set
- $cli_birth_year = date('Y', strtotime($cli_birth_date));
- $age = date('Y', strtotime($date_linux)) - $cli_birth_year;
- if ($age < 35) {
- $age_group['below_35'][] = $age;
- } elseif ($age > 40) {
- $age_group['above_40'][] = $age;
- } else {
- $age_group['35_to_40'][] = $age;
- }
- }
- // Set $count_datebirth_group into array
- $count_datebirth_group = [];
- // Loop again with use $age_group
- foreach ($age_group as $age_groups => $age_group_value) {
- $count_datebirth_group[$age_groups] = count($age_group_value);
- // count_datebirth_group['below_35']
- // count_datebirth_group['above_40']
- // count_datebirth_group['35_to_40']
- }
- $date_birth['below_35'] = $count_datebirth_group['below_35'] / $this->employee_amount * 100;
- $date_birth['above_40'] = $count_datebirth_group['above_40'] / $this->employee_amount * 100;
- $date_birth['between_35_to_40'] = $count_datebirth_group['35_to_40'] / $this->employee_amount * 100;
- return $date_birth;
- }
- public function getDataEmployeeStatusGrafik()
- {
- // Get all employee with select field education_id
- $this->query->select('employment_status_id')->from('employees');
- $employment_status_id = $this->query->all();
- // Loop value from $employee_education_id
- foreach ($employment_status_id as $value) {
- if ($value['employment_status_id'] == 1283) {
- $emp_stat_group['pns'][] = $value;
- } elseif ($value['employment_status_id'] == 232260) {
- $emp_stat_group['tetap'][] = $value;
- } elseif ($value['employment_status_id'] == 1284) {
- $emp_stat_group['tidak_tetap'][] = $value;
- } else {
- $emp_stat_group['outsrc'][] = $value;
- }
- }
- // Set $count_employstatus_group into array
- $count_employstatus_group = [];
- // Loop again with use $emp_stat_group
- foreach ($emp_stat_group as $emp_stat_groups => $emp_stat_groupval) {
- $count_employstatus_group[$emp_stat_groups] = count($emp_stat_groupval);
- }
- // Count
- $employ_status['pegawai_negeri_sipil'] = $count_employstatus_group['pns'] / $this->employee_amount * 100;
- $employ_status['pegawai_tetap'] = $count_employstatus_group['tetap'] / $this->employee_amount * 100;
- $employ_status['pegawai_tidak_tetap'] = $count_employstatus_group['tidak_tetap'] / $this->employee_amount * 100;
- $employ_status['pegawai_outsourcing'] = $count_employstatus_group['outsrc'] / $this->employee_amount * 100;
- return $employ_status;
- }
- public function getDataEmployeeRankGrafik()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment