Skip to content

Commit

Permalink
Merge pull request #404 from compucorp/PCHR-2590-leave-in-hours
Browse files Browse the repository at this point in the history
PCHR-2590: Leave in Hours
  • Loading branch information
igorpavlov authored Nov 27, 2017
2 parents 8ae805b + 6408e5a commit da8be1e
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 260 deletions.
6 changes: 5 additions & 1 deletion civihr_employee_portal/civihr_employee_portal.module
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use Drupal\civihr_employee_portal\Forms\OnboardingWizardCustomizationForm;
use Drupal\civihr_employee_portal\Mail\PasswordResetSystemMail;
use Drupal\civihr_employee_portal\Helpers\ImageResizer;
use Drupal\civihr_employee_portal\Forms\ContactForm;
use CRM_HRLeaveAndAbsences_BAO_AbsenceType as AbsenceType;
use Drupal\civihr_employee_portal\Helpers\Webform\WebformExportCustomFieldConvertor;
use Drupal\civihr_employee_portal\Page\HRDetailsPage;

Expand Down Expand Up @@ -406,6 +407,8 @@ function _rebuild_length_of_service_view() {
function _rebuild_absence_activity_view() {
$civi_settings = parse_url(CIVICRM_DSN);
$civi_db_name = trim($civi_settings['path'], '/');
$calculationUnitOptions = array_flip(AbsenceType::buildOptions('calculation_unit', 'validate'));
$hoursUnit = $calculationUnitOptions['hours'];

db_query('DROP VIEW IF EXISTS absence_activity');
db_query("CREATE VIEW absence_activity AS
Expand All @@ -420,7 +423,8 @@ function _rebuild_absence_activity_view() {
lr.to_date AS absence_end_date,
DATE_FORMAT(DATE(lr.to_date), '%Y-%m') AS absence_end_date_month,
CONCAT(IF (DATE_FORMAT(lrd.date, '%w') = 0, 7, DATE_FORMAT(lrd.date, '%w')), '. ', DATE_FORMAT(lrd.date, '%W')) AS absence_day_of_week,
ABS(bc.amount) as absence_duration,
IF(at.calculation_unit != {$hoursUnit}, ABS(bc.amount), NULL) as absence_duration_days,
IF(at.calculation_unit = {$hoursUnit}, ABS(bc.amount), NULL) as absence_duration_hours,
IF(lr.request_type != 'toil', ABS(bc.amount), NULL) AS absence_amount_taken,
IF(lr.request_type = 'toil', bc.amount, NULL) AS absence_amount_accrued,
IF(lr.request_type = 'toil', -bc.amount, -bc.amount) AS absence_absolute_amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,15 @@ function civihr_employee_portal_features_views_default_views() {
$handler->display->display_options['fields']['absence_end_date_month']['relationship'] = 'absence_activity';
$handler->display->display_options['fields']['absence_end_date_month']['label'] = 'Absence end month';
/* Field: Absence Activity entity: Absence duration in days */
$handler->display->display_options['fields']['absence_duration']['id'] = 'absence_duration';
$handler->display->display_options['fields']['absence_duration']['table'] = 'absence_activity';
$handler->display->display_options['fields']['absence_duration']['field'] = 'absence_duration';
$handler->display->display_options['fields']['absence_duration']['relationship'] = 'absence_activity';
$handler->display->display_options['fields']['absence_duration_days']['id'] = 'absence_duration_days';
$handler->display->display_options['fields']['absence_duration_days']['table'] = 'absence_activity';
$handler->display->display_options['fields']['absence_duration_days']['field'] = 'absence_duration_days';
$handler->display->display_options['fields']['absence_duration_days']['relationship'] = 'absence_activity';
/* Field: Absence Activity entity: Absence duration in hours */
$handler->display->display_options['fields']['absence_duration_hours']['id'] = 'absence_duration_hours';
$handler->display->display_options['fields']['absence_duration_hours']['table'] = 'absence_activity';
$handler->display->display_options['fields']['absence_duration_hours']['field'] = 'absence_duration_hours';
$handler->display->display_options['fields']['absence_duration_hours']['relationship'] = 'absence_activity';
/* Field: Absence Activity entity: Absence_type */
$handler->display->display_options['fields']['absence_type']['id'] = 'absence_type';
$handler->display->display_options['fields']['absence_type']['table'] = 'absence_activity';
Expand Down Expand Up @@ -994,6 +999,7 @@ function civihr_employee_portal_features_views_default_views() {
t('Absence end date'),
t('Absence end month'),
t('Absence duration in days'),
t('Absence duration in hours'),
t('Absence type'),
t('Sickness reason'),
t('Absence status'),
Expand Down
Loading

0 comments on commit da8be1e

Please sign in to comment.