PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.3.13
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.3.13
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / modules / hrm / includes / functions-reporting.php

functions-reporting.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.3.13, at modules/hrm/includes/functions-reporting.php

355 lines 9.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Get All Reporting Titles
4 *
5 * @return array
6 */
7 function erp_hr_get_reports() {
8
9 $reports = [
10 'age-profile' => [
11 'title' => __( 'Age Profile', 'erp' ),
12 'description' => __( 'Shows age breakdown data in your company in different departments.', 'erp' )
13 ],
14 'gender-profile' => [
15 'title' => __( 'Gender Profile', 'erp' ),
16 'description' => __( 'Shows differentiation data by age in your company.', 'erp' )
17 ],
18 'headcount' => [
19 'title' => __( 'Head Count', 'erp' ),
20 'description' => __( 'Displays actual number of individuals in your company in different departments.', 'erp' )
21 ],
22 'salary-history' => [
23 'title' => __( 'Salary History', 'erp' ),
24 'description' => __( 'Shows Salary History of the employees of your company.', 'erp' ),
25 ],
26 'years-of-service' => [
27 'title' => __( 'Years of Service', 'erp' ),
28 'description' => __( 'Shows longevity and experience report of the employees of your company.', 'erp' )
29 ],
30 'leaves' => [
31 'title' => __( 'Leaves Reports', 'erp' ),
32 'description' => __( 'Shows leaves report.', 'erp' )
33 ]
34 ];
35
36 return apply_filters( 'erp_hr_reports', $reports );
37 }
38
39 /**
40 * Get report breakdown by age
41 *
42 * @return array
43 */
44 function get_employee_breakdown_by_age( $employees ) {
45
46 $_under18 = 0;
47 $_18_to_25 = 0;
48 $_26_to_35 = 0;
49 $_36_to_45 = 0;
50 $_46_to_55 = 0;
51 $_56_to_65 = 0;
52 $_65_plus = 0;
53
54 foreach ( $employees as $employee ) {
55
56 if ( !is_valid_date( $employee->date_of_birth ) ) {
57 continue;
58 }
59
60 $dob = new DateTime( $employee->date_of_birth );
61 $now = new DateTime();
62 $interval = $now->diff( $dob );
63 $age = $interval->y;
64
65 if ( $age > 0 && $age <18 ) {
66
67 $_under18++;
68 continue;
69 }
70
71 if ( $age >= 18 && $age <= 25 ) {
72
73 $_18_to_25++;
74 continue;
75 }
76
77 if ( $age >= 26 && $age <= 35 ) {
78
79 $_26_to_35++;
80 continue;
81 }
82
83 if ( $age >= 36 && $age <= 45 ) {
84
85 $_36_to_45++;
86 continue;
87 }
88
89 if ( $age >= 46 && $age <= 55 ) {
90
91 $_46_to_55++;
92 continue;
93 }
94
95 if ( $age >= 56 && $age <= 65 ) {
96
97 $_56_to_65++;
98 continue;
99 }
100
101 if ( $age > 65 ) {
102
103 $_65_plus++;
104 }
105 }
106
107 $count = [
108 '_under_18' => $_under18,
109 '_18_to_25' => $_18_to_25,
110 '_26_to_35' => $_26_to_35,
111 '_36_to_45' => $_36_to_45,
112 '_46_to_55' => $_46_to_55,
113 '_56_to_65' => $_56_to_65,
114 '_65_plus' => $_65_plus,
115 ];
116
117 return $count;
118 }
119
120 /**
121 * Counts diffrenet genders in employees
122 *
123 * @return array
124 */
125 function erp_hr_get_gender_count( $department = null ) {
126
127 global $wpdb;
128
129 if ( null == $department ) {
130 $all_user_id = $wpdb->get_col( "SELECT user_id FROM {$wpdb->prefix}erp_hr_employees" );
131
132 } else {
133 $all_user_id = $wpdb->get_col( "SELECT user_id FROM {$wpdb->prefix}erp_hr_employees WHERE department = $department" );
134 }
135
136 if ( $all_user_id ) {
137
138 foreach ( $all_user_id as $user_id ) {
139 $gender_single = get_user_meta( $user_id, 'gender', true );
140
141 if ( is_string( $gender_single ) ) {
142 $gender_all[] = $gender_single;
143 }
144 }
145
146 $gender_counted = array_count_values( $gender_all );
147 }
148
149 $gender['male'] = isset( $gender_counted['male'] ) ? $gender_counted['male'] : 0;
150 $gender['female'] = isset( $gender_counted['female'] ) ? $gender_counted['female'] : 0;
151 $gender['other'] = isset( $gender_counted['other'] ) ? $gender_counted['other'] : 0;
152
153 return $gender;
154 }
155
156 /**
157 * Gets data for Employee Breakdown Table on ERP HR Reporting
158 *
159 * @return object
160 */
161 function erp_hr_get_age_breakdown_data() {
162
163 $employees = new \WeDevs\ERP\HRM\Models\Employee();
164 $departments = erp_hr_get_departments();
165 $age_breakdown_data = [];
166 $tot_under18 = 0;
167 $tot_18_to_25 = 0;
168 $tot_26_to_35 = 0;
169 $tot_36_to_45 = 0;
170 $tot_46_to_55 = 0;
171 $tot_56_to_65 = 0;
172 $tot_65plus = 0;
173
174 foreach( $departments as $department ) {
175
176 $emp_by_dept = $employees->where( 'department', $department->id )->get();
177 $emp_by_dept_data = get_employee_breakdown_by_age( $emp_by_dept );
178
179 $tot_under18 += $emp_by_dept_data['_under_18'];
180 $tot_18_to_25 += $emp_by_dept_data['_18_to_25'];
181 $tot_26_to_35 += $emp_by_dept_data['_26_to_35'];
182 $tot_36_to_45 += $emp_by_dept_data['_36_to_45'];
183 $tot_46_to_55 += $emp_by_dept_data['_46_to_55'];
184 $tot_56_to_65 += $emp_by_dept_data['_56_to_65'];
185 $tot_65plus += $emp_by_dept_data['_65_plus'];
186
187 $age_breakdown_data[] = [
188 'department' => $department->title,
189 '_under18' => $emp_by_dept_data['_under_18'],
190 '_18_to_25' => $emp_by_dept_data['_18_to_25'],
191 '_26_to_35' => $emp_by_dept_data['_26_to_35'],
192 '_36_to_45' => $emp_by_dept_data['_36_to_45'],
193 '_46_to_55' => $emp_by_dept_data['_46_to_55'],
194 '_56_to_65' => $emp_by_dept_data['_56_to_65'],
195 '_65_plus' => $emp_by_dept_data['_65_plus']
196 ];
197 }
198
199 $age_breakdown_data[] = [
200 'department' => 'Total',
201 '_under18' => $tot_under18,
202 '_18_to_25' => $tot_18_to_25,
203 '_26_to_35' => $tot_26_to_35,
204 '_36_to_45' => $tot_36_to_45,
205 '_46_to_55' => $tot_46_to_55,
206 '_56_to_65' => $tot_56_to_65,
207 '_65_plus' => $tot_65plus
208 ];
209
210 $age_breakdown_data = erp_array_to_object( $age_breakdown_data );
211
212 return $age_breakdown_data;
213 }
214
215 /**
216 * Get count Employee Breakdown Table rows on ERP HR Reporting
217 *
218 * @return int
219 */
220 function erp_hr_count_age_breakdown() {
221
222 $count = count( erp_hr_get_departments() );
223
224 return ++$count;
225 }
226
227 /**
228 * Get data for Gender Ratio List Table
229 *
230 *@return array
231 */
232 function erp_hr_get_gender_ratio_data() {
233
234 $gender_count = erp_hr_get_gender_count();
235 $gender_total = $gender_count['male'] + $gender_count['female'] + $gender_count['other'];
236
237 $gender_ratio_data = [
238 'male' => [
239 'gender' => 'Male',
240 'count' => $gender_count['male'],
241 'percentage' => number_format( ( $gender_count['male'] * 100 ) / $gender_total, 2 ) . '%'
242 ],
243 'female' => [
244 'gender' => 'Female',
245 'count' => $gender_count['female'],
246 'percentage' => number_format( ( $gender_count['female'] * 100 ) / $gender_total, 2 ) . '%'
247 ],
248 'other' => [
249 'gender' => 'Unspecified',
250 'count' => $gender_count['other'],
251 'percentage' => number_format( ( $gender_count['other'] * 100 ) / $gender_total, 2 ) . '%'
252 ],
253 'total' => [
254 'gender' => 'Total',
255 'count' => $gender_total,
256 'percentage' => '100%'
257 ],
258 ];
259
260 $gender_ratio_data = erp_array_to_object( $gender_ratio_data );
261
262 return $gender_ratio_data;
263 }
264
265 /**
266 * Returns Employee headcount by date/month
267 *
268 * @return number
269 */
270 function erp_hr_get_headcount( $date = '', $dept = '', $query_type = '' ) {
271
272 global $wpdb;
273
274 $count = 0;
275 $all_user_data = $wpdb->get_results( "SELECT user_id, department, hiring_date, termination_date FROM {$wpdb->prefix}erp_hr_employees ", ARRAY_A );
276
277 if ( 'date' == $query_type ) {
278
279 $date = strtotime( $date );
280
281 foreach ( $all_user_data as $user_data ) {
282
283 $date_start = strtotime( $user_data['hiring_date'] );
284 $date_last = '0000-00-00' == $user_data['termination_date'] ? strtotime( 'now' ) : strtotime( $user_data['termination_date'] );
285
286 if( $date >= $date_start && $date <= $date_last ) {
287 $count++;
288 }
289 }
290 }
291
292 if ( 'month' == $query_type ) {
293
294 foreach ($all_user_data as $user_data ) {
295
296 if ( '0000-00-00' == $user_data['hiring_date'] ) {
297 continue;
298 }
299
300 if ( $dept && $dept != $user_data['department'] ) {
301 continue;
302 }
303
304 $date_start = $user_data['hiring_date'];
305 $date_last = '0000-00-00' == $user_data['termination_date'] ? current_time( 'Y-m-d' ) : $user_data['termination_date'];
306
307 $start = ( new DateTime( $date_start ) )->modify( 'first day of this month' );
308 $end = ( new DateTime( $date_last ) )->modify( 'last day of this month' );
309 $interval = DateInterval::createFromDateString( '1 month' );
310 $period = new DatePeriod( $start, $interval, $end );
311
312 foreach ( $period as $months ) {
313
314 if ( $date == $months->format('Y-m') ) {
315
316 $count++;
317 break;
318 }
319 }
320 }
321 }
322
323 return $count;
324 }
325
326 /**
327 * Check if a string is valid date
328 *
329 * @since 0.1
330 *
331 * @return bool
332 */
333 function is_valid_date( $str ) {
334
335 try {
336
337 $dt = new DateTime( trim( $str ) );
338
339 } catch( Exception $e ) {
340
341 return false;
342 }
343
344 $month = $dt->format( 'm' );
345 $day = $dt->format( 'd' );
346 $year = $dt->format( 'Y' );
347
348 if( checkdate( $month, $day, $year) ) {
349 return true;
350 } else {
351 return false;
352 }
353 }
354
355