diff --git a/.gitignore b/.gitignore
index 6a93dffa5f3..3de41031d36 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@ hrjob/build
bin/setup.conf
hrabsence/build
/nbproject/private/
+core-fork-last-commit-patched.txt
# Exclude sass cache from all extension directories
*/.sass-cache/
diff --git a/Jenkinsfile b/Jenkinsfile
index 31be1839ff0..61cc6457c07 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -23,7 +23,7 @@ pipeline {
stages {
stage('Pre-tasks execution') {
steps {
- sendBuildStartdNotification()
+ sendBuildStartNotification()
// Print all Environment variables
sh 'printenv | sort'
@@ -189,26 +189,34 @@ pipeline {
/*
* Sends a notification when the build starts
*/
-def sendBuildStartdNotification() {
- def message = 'Building ' + getBuildTargetLink() + '. ' + getReportLink()
+def sendBuildStartNotification() {
+ def msgHipChat = 'Building ' + getBuildTargetLink('hipchat') + '. ' + getReportLink('hipchat')
+ def msgSlack = 'Building ' + getBuildTargetLink('slack') + '. ' + getReportLink('slack')
- sendHipchatNotification('YELLOW', message)
+ sendHipchatNotification('YELLOW', msgHipChat)
+ sendSlackNotification('warning', msgSlack)
}
/*
* Sends a notification when the build is completed successfully
*/
def sendBuildSuccessNotification() {
- def message = getBuildTargetLink() + ' built successfully. Time: $BUILD_DURATION. ' + getReportLink()
- sendHipchatNotification('GREEN', message)
+ def msgHipChat = getBuildTargetLink('hipchat') + ' built successfully. Time: $BUILD_DURATION. ' + getReportLink('hipchat')
+ def msgSlack = getBuildTargetLink('slack') + ' built successfully. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink('slack')
+
+ sendHipchatNotification('GREEN', msgHipChat)
+ sendSlackNotification('good', msgSlack)
}
/*
* Sends a notification when the build fails
*/
def sendBuildFailureNotification() {
- def message = 'Failed to build ' + getBuildTargetLink() + '. Time: $BUILD_DURATION. No. of failed tests: ${TEST_COUNTS,var=\"fail\"}. ' + getReportLink()
- sendHipchatNotification('RED', message)
+ def msgHipChat = 'Failed to build ' + getBuildTargetLink('hipchat') + '. Time: $BUILD_DURATION. No. of failed tests: ${TEST_COUNTS,var=\"fail\"}. ' + getReportLink('hipchat')
+ def msgSlack = 'Failed to build ' + getBuildTargetLink('slack') + '. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink('slack')
+
+ sendHipchatNotification('RED', msgHipChat)
+ sendSlackNotification('danger', msgSlack)
}
/*
@@ -218,16 +226,38 @@ def sendHipchatNotification(String color, String message) {
hipchatSend color: color, message: message, notify: true
}
+/*
+ * Sends a notification to Slack
+ */
+def sendSlackNotification(String color, String message) {
+ slackSend color: color, message: message, notify: true
+}
+
+/*
+ * Returns the build duration without the "and counting" suffix
+ */
+def getBuildDuration(build) {
+ return build.durationString.replace(' and counting', '')
+}
+
/*
* Returns a link to what is being built. If it's a PR, then it's a link to the pull request itself.
* If it's a branch, then it's a link in the format http://github.com/org/repo/tree/branch
*/
-def getBuildTargetLink() {
- if(buildIsForAPullRequest()) {
- return "\"${env.CHANGE_TITLE}\""
+def getBuildTargetLink(String client) {
+ def link = ''
+ def forPR = buildIsForAPullRequest()
+
+ switch (client) {
+ case 'hipchat':
+ link = forPR ? "\"${env.CHANGE_TITLE}\"" : '"' + env.BRANCH_NAME + '"'
+ break;
+ case 'slack':
+ link = forPR ? "<${env.CHANGE_URL}|${env.CHANGE_TITLE}>" : '<' + getRepositoryUrlForBuildBranch() + '|' + env.BRANCH_NAME + '>'
+ break;
}
- return '"' + env.BRANCH_NAME + '"'
+ return link
}
/*
@@ -250,8 +280,19 @@ def getRepositoryUrlForBuildBranch() {
/*
* Returns the Blue Ocean build report URL for the current job
*/
-def getReportLink() {
- return 'Click here to see the build report'
+def getReportLink(String client) {
+ def link = ''
+
+ switch (client) {
+ case 'hipchat':
+ link = 'Click here to see the build report'
+ break
+ case 'slack':
+ link = "Click <${env.RUN_DISPLAY_URL}|here> to see the build report"
+ break
+ }
+
+ return link
}
def cloneCiviHRRepositories(String envBranch) {
diff --git a/bin/apply-core-fork-patch.sh b/bin/apply-core-fork-patch.sh
new file mode 100755
index 00000000000..17889610737
--- /dev/null
+++ b/bin/apply-core-fork-patch.sh
@@ -0,0 +1,131 @@
+#!/bin/bash
+
+set -e
+
+API_URL_BASE="https://api.github.com/repos/compucorp/civicrm-core"
+LAST_COMMIT_PATCHED_FILE="core-fork-last-commit-patched.txt"
+PATCH_FILE="fork-patch.diff"
+
+civiRoot=""
+
+#######################################
+# Applies the patch on the core files
+#
+# Globals:
+# $civiRoot
+# $PATCH_FILE
+# Arguments:
+# None
+# Returns:
+# None
+#######################################
+applyPatch () {
+ (cd "$civiRoot" && patch -p1 < "$PATCH_FILE" >> /dev/null)
+}
+
+#######################################
+# Creates a diff patch file by sending a request to the given GitHub API url
+#
+# Globals:
+# $API_URL_BASE
+# $civiRoot
+# $PATCH_FILE
+# Arguments:
+# $1 base commit of the comparison
+# $2 head commit of the comparison
+# Returns:
+# None
+#######################################
+createPatch () {
+ curl "$API_URL_BASE/compare/$1...$2" -s -H "Accept: application/vnd.github.v3.diff" > "$civiRoot/$PATCH_FILE"
+}
+
+#######################################
+# Programmatically gets the current CiviCRM version
+#
+# Globals:
+# None
+# Arguments:
+# None
+# Returns:
+# String
+#######################################
+getCiviVersion () {
+ drush eval "civicrm_initialize(); echo CRM_Utils_System::version();"
+}
+
+#######################################
+# Uses Python to read the property's value of a JSON file
+#
+# Globals:
+# None
+# Arguments:
+# $1 JSON file
+# $2 property name
+# Returns:
+# String
+#######################################
+JSONValue () {
+ python -c "import sys, json; print json.load(sys.stdin)['$2']" < "$1"
+}
+
+#######################################
+# Returns the civicrm root path
+#
+# Globals:
+# None
+# Arguments:
+# None
+# Returns:
+# String
+#######################################
+setCivicrmRootPath () {
+ civiRoot=$(drush eval "civicrm_initialize(); echo \\Civi::paths()->getPath('[civicrm.root]/.')")
+}
+
+#######################################
+# Updates the reference, in the LAST_COMMIT_PATCHED_FILE, to the last commit
+# patched onto the core files
+#
+# Globals:
+# $civiRoot
+# $LAST_COMMIT_PATCHED_FILE
+# Arguments:
+# None
+# Returns:
+# None
+#######################################
+updateLastCommitPatched () {
+ # It uses the same file as temporary recipient of the full commit data
+ curl "$API_URL_BASE/commits/$1" -s > "$LAST_COMMIT_PATCHED_FILE"
+ sha=$(JSONValue "$LAST_COMMIT_PATCHED_FILE" "sha")
+
+ echo "$sha" > "$LAST_COMMIT_PATCHED_FILE"
+}
+
+# ---------------
+
+touch -a $LAST_COMMIT_PATCHED_FILE
+setCivicrmRootPath
+
+civiVersion=$(getCiviVersion)
+lastCommitPatched=$(cat "$LAST_COMMIT_PATCHED_FILE")
+patchesBranch="$civiVersion-patches"
+[ ! -z "$lastCommitPatched" ] && baseHead=$lastCommitPatched || baseHead=$civiVersion
+
+echo "Fetching compucorp:civicrm-core patch..."
+createPatch "$baseHead" "$patchesBranch"
+
+if [ -s "$civiRoot/$PATCH_FILE" ]; then
+ echo "Applying compucorp:civicrm-core patch..."
+ applyPatch
+
+ echo "Updating reference to SHA of last commit patched..."
+ updateLastCommitPatched "$patchesBranch"
+
+ echo "Patch applied"
+else
+ echo "Patch was empty, no diffs found"
+fi
+
+rm "$civiRoot/$PATCH_FILE"
diff --git a/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php b/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php
index 372818cfdad..3e58b5465f2 100644
--- a/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php
+++ b/com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php
@@ -45,6 +45,70 @@ public function upgrade_1004() {
return TRUE;
}
+ /**
+ * Adds a submenu containing links to edit job role option groups
+ *
+ * @return bool
+ */
+ public function upgrade_1005() {
+ $domain = CRM_Core_Config::domainID();
+ $params = ['return' => 'id', 'name' => 'Administer', 'domain_id' => $domain];
+ $administerId = (int) civicrm_api3('Navigation', 'getvalue', $params);
+
+ $permission = 'access CiviCRM';
+ $parent = $this->createNavItem('Job Roles', $permission, $administerId);
+ $parentId = $parent['id'];
+
+ // Weight cannot be set when creating for the first time
+ civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -99]);
+
+ // If we don't flush it will not recognize newly created parent_id
+ CRM_Core_PseudoConstant::flush();
+
+ $optionGroupLinks = [
+ 'Locations' => 'hrjc_location',
+ 'Regions' => 'hrjc_region',
+ 'Departments' => 'hrjc_department',
+ 'Levels' => 'hrjc_level_type',
+ 'Cost Centres' => 'cost_centres',
+ ];
+
+ foreach ($optionGroupLinks as $itemName => $optionGroup) {
+ $link = 'civicrm/admin/options/' . $optionGroup . '?reset=1';
+ $this->createNavItem($itemName, $permission, $parentId, ['url' => $link]);
+ }
+
+ return TRUE;
+ }
+
+ /**
+ * Creates a navigation menu item using the API
+ *
+ * @param string $name
+ * @param string $permission
+ * @param int $parentID
+ * @param array $params
+ *
+ * @return array
+ */
+ private function createNavItem($name, $permission, $parentID, $params = []) {
+ $params = array_merge([
+ 'name' => $name,
+ 'label' => ts($name),
+ 'permission' => $permission,
+ 'parent_id' => $parentID,
+ 'is_active' => 1,
+ ], $params);
+
+ $existing = civicrm_api3('Navigation', 'get', $params);
+
+ if ($existing['count'] > 0) {
+ return array_shift($existing['values']);
+ }
+
+ return civicrm_api3('Navigation', 'create', $params);
+ }
+
/**
* Creates new Option Group for Cost Centres
*/
diff --git a/com.civicrm.hrjobroles/info.xml b/com.civicrm.hrjobroles/info.xml
index 3f08b059f5a..869358d8eee 100644
--- a/com.civicrm.hrjobroles/info.xml
+++ b/com.civicrm.hrjobroles/info.xml
@@ -8,8 +8,8 @@
When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.
","People I approve filter displays only staff members who you approve leave for.
","People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.
"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:r.contactId}).leaveManagees().then(function(e){r.lookupContacts=e}).then(o)}}}function o(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:r.filters.userSettings.department?r.filters.userSettings.department.value:null,level_type:r.filters.userSettings.level_type?r.filters.userSettings.level_type.value:null,location:r.filters.userSettings.location?r.filters.userSettings.location.value:null,region:r.filters.userSettings.region?r.filters.userSettings.region.value:null,id:{IN:r.filters.userSettings.contact?[r.filters.userSettings.contact.id]:r.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var r;return{init:function(e){return r=e,r.showContactName=!0,r.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function o(a,o,s,r,i,c,u,l,d,m){function f(){for(var e=[],t=n(O.selectedPeriod.start_date).clone().startOf("month"),a=n(O.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(A(t)),t.add(1,"month");O.months=e}function p(){r.$new().$watch(function(){return O.selectedMonths},function(t,n){null===n||e.equals(t,n)||w()})}function h(e){O.injectMonths=!0,L("injected").then(function(){w(e)}).then(function(){O.loading.calendar=!1})}function v(){S=a("LeaveCalendar"+t.capitalize(M)+"Controller").init(O)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){O.absencePeriods=t.sortBy(e,"start_date"),O.selectedPeriod=t.find(O.absencePeriods,function(e){return!!e.current})}).then(f).then(I)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return S.loadContacts().then(function(e){O.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){O.filters.optionValues.regions=e.hrjc_region,O.filters.optionValues.locations=e.hrjc_location,O.filters.optionValues.levelTypes=e.hrjc_level_type,O.filters.optionValues.departments=e.hrjc_department})}function P(){return l.all()}function D(){return o.all([_(),P(),y()]).then(function(e){O.supportData.absenceTypes=e[0],O.supportData.publicHolidays=e[1],O.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,O.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,O.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,O.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function R(){var e=o.resolve();return O.injectMonths&&(e=L("destroyed"),O.injectMonths=!1),e}function A(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function T(e){e=t.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){O.loading.calendar=!0}).then(R).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function w(e){var n=O.selectedMonths.length?O.months.filter(function(e){return t.includes(O.selectedMonths,e.index)}):O.months;r.$emit("LeaveCalendar::showMonths",n,!!e)}function I(){O.selectedMonths=[n().month()]}function k(){return O.roleOverride?o.resolve().then(function(){M=O.roleOverride}):o.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){M=e[0]?"admin":e[1]?"manager":"staff"})}function L(e){return o(function(n){var a=0,o=r.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===O.months.length&&(o(),n())})})}s.debug("Component: leave-calendar");var S,M,O=this;O.absencePeriods=[],O.contacts=[],O.contactIdsToReduceTo=null,O.injectMonths=!1,O.months=[],O.selectedMonths=null,O.selectedPeriod=null,O.showContactName=!1,O.showFilters=!1,O.supportData={},O.loading={calendar:!0,page:!0},O.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},O.labelPeriod=b,O.refresh=T,function(){k().then(p).then(v).then(R).then(g).then(function(){return o.all([q(),D()])}).then(function(){return O.showFilters?C():t.noop}).then(function(){h()}).then(function(){O.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,o){"use strict";function s(){y.calculationUnit=r(y.supportData.calculationUnits,"value",b.calculation_unit)}function r(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(y.contactData.leaveRequest.from_date).isSame(y.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+y.calculationUnit.name+"-on-"+e+"-tooltip"}function c(){b=r(y.supportData.absenceTypes,"id",y.contactData.leaveRequest.type_id),y.contactData.leaveRequest["type_id.title"]=b.title}function u(){"days"===y.calculationUnit.name&&(g=r(y.supportData.dayTypes,"value",y.contactData.leaveRequest.from_date_type),_=r(y.supportData.dayTypes,"value",y.contactData.leaveRequest.to_date_type),y.contactData.leaveRequest["from_date_type.label"]=g.label,y.contactData.leaveRequest["to_date_type.label"]=_.label)}function l(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function d(){y.dates.from=new Date(y.contactData.leaveRequest.from_date),y.dates.to=new Date(y.contactData.leaveRequest.to_date)}function m(){y.contactData.isAccruedTOIL?y.label="AT":"days"===y.calculationUnit.name?f():p()}function f(){y.label=y.contactData.isAM?"AM":y.contactData.isPM?"PM":""}function p(){var e=t(y.contactData.leaveRequest.from_date).isSame(y.date,"day"),n=t(y.contactData.leaveRequest.to_date).isSame(y.date,"day");y.label=e?t(y.contactData.leaveRequest.from_date).format("HH:mm"):n?t(y.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){y.tooltipTemplate=y.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){y.contactData&&y.contactData.leaveRequest&&(c(),s(),u(),m(),d(),h()) -})}n.debug("Component: leave-calendar-day");var b,g,_,y=this;y.calculationUnit="",y.dates={from:null,to:null},y.label="",y.tooltipTemplate=null,y.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(e){_([e]),N(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),o=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(H.period.start_date)&&o.isSameOrBefore(H.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return U[e]}function f(){return H.showOnlyWithLeaveRequests?H.contacts.filter(function(e){return Object.keys(W[e.id]||{}).length}):H.contacts}function p(e){return t(e,c.serverDateFormat)}function h(e){S(e),N(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function b(){return H.contactIdsToReduceTo&&(H.contacts=H.contacts.filter(function(t){return e.includes(H.contactIdsToReduceTo,t.contact_id)||e.find(W,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function g(){H.supportData.dayTypes=e.indexBy(H.supportData.dayTypes,"name"),H.supportData.leaveRequestStatuses=e.indexBy(H.supportData.leaveRequestStatuses,"value"),H.supportData.publicHolidays=e.transform(H.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function _(e){return e.forEach(function(e){var t=R(e);W[e.contact_id]=W[e.contact_id]||{},t.forEach(function(t){W[e.contact_id][t.date]=e})}),a.resolve()}function y(){F.push(o.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",u)),F.push(i.subscribe("LeaveRequest::edit",B)),F.push(i.subscribe("LeaveRequest::updatedByManager",B)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):B(e.leaveRequest)}))}function q(e,n,a){var o=H.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?o.value===n.from_date_type:t(a).isSame(n.to_date,"day")?o.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function P(e){return!!H.supportData.publicHolidays[p(e).valueOf()]}function D(t){var n=H.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],n)}function R(n){for(var a=[],o=t(n.from_date).clone(),s=t(n.to_date);o.isSameOrBefore(s);)o.month()===H.month.index&&o.year()===H.month.year&&a.push(e.find(H.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function A(t){return e.find(W[t.contact_id],function(e){return t.id===e.id})}function T(t){var n=e.find(H.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function w(){return[T(c.statusNames.approved),T(c.statusNames.adminApproved),T(c.statusNames.awaitingApproval),T(c.statusNames.moreInformationRequired)]}function I(){return H.month.loading=!0,a.all([L(),k()]).then(b).then($).then(function(){j=!0}).then(function(){H.month.loading=!1})}function k(){return r.all({from_date:{to:H.month.days[H.month.days.length-1].date},to_date:{from:H.month.days[0].date},status_id:{IN:w()},contact_id:{IN:H.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(H.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return _(e.list)})}function L(){var t=H.month.days[0].date,n=H.month.days[H.month.days.length-1].date;return s.get(H.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function S(t){W[t.contact_id]=e.omit(W[t.contact_id],function(e){return e.id===t.id})}function M(){o.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function O(t,n,o){var s,r;return t.contactsData[n]=t.contactsData[n]||{},r=m(n),s=!0===o?a.resolve():a.all([r.isWeekend(p(t.date)),r.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:P(t.date)})}),s.then(function(){return W[n]?W[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?C(a,"toil"):null,isRequested:a?D(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function $(){return a.all(H.month.days.map(function(e){return a.all(H.contacts.map(function(t){return O(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===H.month.index})?H.visible=!1:(H.currentPage=0,H.visible=!0,(a||!j)&&I())}function E(t){var n=e.find(H.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function B(e){var t=A(e);t&&(h(t),-1!==w().indexOf(e.status_id)&&u(e))}function N(e){return a.all(R(e).map(function(t){return O(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var j=!1,F=[],U={},W={},H=this;H.currentPage=0,H.pageSize=20,H.visible=!1,H.showContactName=!!H.showContactName,H.showOnlyWithLeaveRequests=!!H.showOnlyWithLeaveRequests,H.$onDestroy=M,H.contactsList=f,H.getContactUrl=v,function(){var e=t().month(H.month.index).year(H.month.year);g(),y(),H.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function o(){var t=n.defer();return a.open(e.defaults(s(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,o,s,r,i,c,u){function l(t){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?o.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([C.awaitingApproval,C.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function f(t){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(r.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=P[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,t,n,a,o){e.stopPropagation(),s.openModal(t,n,a,o)}function b(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function g(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(P,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&_(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:P[e].label,isDirectAction:P[e].isDirectAction}})}function _(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,P={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,o,s,r,i,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,r.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l,d,m,f){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,c.serverDateFormat).toDate()}function v(e){return t(e).format(c.serverDateFormat)}function b(e){var t;return r.resolve().then(function(){J(e),"from"===e&&Q(),N("hours")&&(y(e),"from"!==e||pe.uiOptions.multipleDays||y("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return P(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return r.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return G()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(N("hours"))return H(e).then(function(){ne(e,!0)})}).then(function(){if(se(),!t)return V();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(I)}function g(){return se(),V()}function _(){return pe.uiOptions.toDate=null,J("to"),r.resolve().then(function(){if(N("hours")&&pe.uiOptions.fromDate)return y("from"),!pe.uiOptions.multipleDays&&y("to"),H("from").then(function(){ne("from",!0)}).then(se)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&V)}function y(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&s&&o&&(s=A(s).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=A(o).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function C(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):D(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):r.reject([])}function P(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function D(e,n){return e=t(e),r.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function R(){return pe.request?pe.request.request_type:pe.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function T(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(K).catch(I)}function w(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function I(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function k(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?V():T()}function L(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function S(e){s.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){N("days")||+e==+t||(re(),pe.performBalanceChangeCalculation())})}function M(){fe.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){ue()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",V))}function O(){pe.isMode("edit")&&(pe.isLeaveStatus(c.statusNames.approved)||pe.isLeaveStatus(c.statusNames.adminApproved))&&(me={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function $(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(w(a.min,n)<=0||w(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return r.all(e.map(H)).then(function(){["from","to"].forEach(function(e){$(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(re)}function E(){["from","to"].forEach(function(e){S(e),B(e)})}function B(e){s.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){N("days")||t===n||(se(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function N(e){return pe.selectedAbsenceType.calculation_unit_name===e}function j(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return C(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function W(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function H(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},I(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):r.resolve()}function G(){return u.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function Y(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function V(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(K).catch(I).finally(function(){pe.loading.balanceChange=!1})):r.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function X(){return v(pe.request.from_date)===v(pe.request.to_date)}function Q(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,J("to"))}function J(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,se(),re(),ie()}function K(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&X()||pe.isMode("create")&&(j("sickness")||N("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,r.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",o=n.times[a],s=n.multipleDays&&"to"===a?o.min:n.times.from.time,r=n.multipleDays&&"from"===a?o.max:n.times.to.time,i=he[a].number_of_hours?w(s,r).toString():"0";o.maxAmount=i,t&&(o.amount=o.maxAmount)}function ae(){me&&me.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=me.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function oe(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function se(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),N("hours")&&!j("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function re(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ce(){e.forEach(fe,function(e){e()})}function ue(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return oe(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),r.resolve().then(e&&ee).then(function(){if(e&&N("hours"))return H("from").then(function(){ne("from",!0)})}).then(e&&se).then(V)}function le(e){return pe.absenceTypes=e,oe(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,J("to")),ae(),V()}function de(e){var t=A(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(A(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var me=null,fe=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=c.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:Y},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=b,pe.dateTypeChangeHandler=g,pe.daysSelectionModeChangeHandler=_,pe.isLeaveType=j,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=V,pe.$onDestroy=ce,function(){n("RequestModalDetails"+e.capitalize(R(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",pe),M(),pe.initChildController().then(function(){return r.all([G(),W()])}).then(!pe.isMode("create")&&L).then(ee).then(function(){if(!pe.isMode("create")&&N("hours"))return x().then(se)}).then(!pe.isMode("create")&&Z).then(O).then(ae).then(k).then(function(){pe.isMode("view")||j("toil")||E()}).catch(I).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,o,s,r,i,c,u,l){function d(){return k.fileUploader&&k.fileUploader.queue.length>0}function m(){return k.getFilesAmount()When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.
","People I approve filter displays only staff members who you approve leave for.
","People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.
"].join(""))}t.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,u()}}}t.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(e,n,t){function a(){return{loadContacts:function(){return t.init({id:i.contactId}).leaveManagees().then(function(e){i.lookupContacts=e}).then(o)}}}function o(){return n.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:i.filters.userSettings.department?i.filters.userSettings.department.value:null,level_type:i.filters.userSettings.level_type?i.filters.userSettings.level_type.value:null,location:i.filters.userSettings.location?i.filters.userSettings.location.value:null,region:i.filters.userSettings.region?i.filters.userSettings.region.value:null,id:{IN:i.filters.userSettings.contact?[i.filters.userSettings.contact.id]:i.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var i;return{init:function(e){return i=e,i.showContactName=!0,i.showFilters=!0,a()}}}t.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(e,n){function t(){return{loadContacts:function(){return n.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,t()}}}t.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,n,t,a){function o(a,o,s,i,r,c,u,l,d,m){function f(){for(var e=[],n=t(M.selectedPeriod.start_date).clone().startOf("month"),a=t(M.selectedPeriod.end_date).clone().endOf("month");n.isBefore(a);)e.push(A(n)),n.add(1,"month");M.months=e}function p(){i.$new().$watch(function(){return M.selectedMonths},function(n,t){null===t||e.equals(n,t)||I()})}function h(e){M.injectMonths=!0,S("injected").then(function(){I(e)}).then(function(){M.loading.calendar=!1})}function v(){k=a("LeaveCalendar"+n.capitalize(L)+"Controller").init(M)}function b(e){return e.current?"Current Period ("+e.title+")":e.title}function g(){return c.all().then(function(e){M.absencePeriods=n.sortBy(e,"start_date"),M.selectedPeriod=n.find(M.absencePeriods,function(e){return!!e.current})}).then(f).then(w)}function _(){return u.all().then(u.loadCalculationUnits)}function y(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return k.loadContacts().then(function(e){M.contacts=e})}function C(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function T(){return l.all()}function D(){return o.all([_(),T(),y()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=n.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function P(){var e=o.resolve();return M.injectMonths&&(e=S("destroyed"),M.injectMonths=!1),e}function A(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function R(e){e=n.includes(["contacts","period"],e)?e:"period",o.resolve().then(function(){M.loading.calendar=!0}).then(P).then("period"===e?f:n.noop).then("contacts"===e?q:n.noop).then(function(){h("contacts"===e)})}function I(e){var t=M.selectedMonths.length?M.months.filter(function(e){return n.includes(M.selectedMonths,e.index)}):M.months;i.$emit("LeaveCalendar::showMonths",t,!!e)}function w(){M.selectedMonths=[t().month()]}function O(){return M.roleOverride?o.resolve().then(function(){L=M.roleOverride}):o.all([m(r.permissions.admin.administer),m(r.permissions.ssp.manage)]).then(function(e){L=e[0]?"admin":e[1]?"manager":"staff"})}function S(e){return o(function(t){var a=0,o=i.$on("LeaveCalendar::month"+n.capitalize(e),function(){++a===M.months.length&&(o(),t())})})}s.debug("Component: leave-calendar");var k,L,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=b,M.refresh=R,function(){O().then(p).then(v).then(P).then(g).then(function(){return o.all([q(),D()])}).then(function(){return M.showFilters?C():n.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",o]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,n,t){function a(t,a,o,s){"use strict";function i(e,n,t,a,o){e.stopPropagation(),s.openModal(n,t,a,o)}function r(e){return e.isAM?"AM":e.isPM?"PM":""}function c(e){var t=n(e.from_date).isSame(b.date,"day"),a=n(e.to_date).isSame(b.date,"day");return t?n(e.from_date).format("HH:mm"):a?n(e.to_date).format("HH:mm"):""}function u(n,t){b.contactData.leaveRequestsAttributes[n.id].absenceTypeTitle=e.find(b.supportData.absenceTypes,{id:n.type_id}).title}function l(n,t){var a=e.find(b.supportData.absenceTypes,{id:n.type_id}),o=e.find(b.supportData.calculationUnits,{value:a.calculation_unit});t.unit=o.name}function d(e,n){n.from_date=new Date(e.from_date),n.to_date=new Date(e.to_date)}function m(n,t){"days"===t.unit&&(t.from_date_type=e.find(b.supportData.dayTypes,{value:n.from_date_type}).label,t.to_date_type=e.find(b.supportData.dayTypes,{value:n.to_date_type}).label)}function f(e,n){var t="";t=n.isAccruedTOIL?"AT":"days"===n.unit?r(n):c(e),n.label=t}function p(e){var n=b.contactData.leaveRequestsAttributes[e.id];[l,m,f,d,u].forEach(function(t){t.call(this,e,n)})}function h(e,n){o(function(){b.tooltip[e+"_hovered"]=n,b.tooltip.show=b.tooltip.day_cell_hovered||b.tooltip.tooltip_hovered},n?0:100)}function v(){a.$watch("day.contactData.leaveRequests",function(){b.contactData&&b.contactData.leaveRequests&&b.contactData.leaveRequests.forEach(p)},!0)}t.debug("Component: leave-calendar-day");var b=this;b.tooltip={show:!1,day_cell_hovered:!1,tooltip_hovered:!1},b.openLeavePopup=i,b.toggleTooltip=h,function(){v()}()}t.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){ +return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","$timeout","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function n(e){function n(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var t=this;t.legendCollapsed=!0,t.getAbsenceTypeStyle=n}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",n]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(e){q([e]),j(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(t){var a=n(),o=t.clone().startOf("month");return e.map(e.times(t.daysInMonth()),function(){var e={date:o.format("YYYY-MM-DD"),name:o.format("ddd"),index:o.format("D"),current:a.isSame(o,"day"),enabled:o.isSameOrAfter(V.period.start_date)&&o.isSameOrBefore(V.period.end_date),contactsData:{}};return o.add(1,"day"),e})}function m(e){return G[e]}function f(){return V.showOnlyWithLeaveRequests?V.contacts.filter(function(e){return Object.keys(Y[e.id]||{}).length}):V.contacts}function p(e){return n(e,c.serverDateFormat)}function h(e){var n=b(e);n&&(M(n),j(n))}function v(n){var t={request_type:"toil"};return e.some(n,t)&&!e.every(n,t)?e.filter(n,t):n}function b(n){var t;return e.find(Y[n.contact_id],function(a){return t=e.find(a,function(e){return+e.id==+n.id})}),t}function g(e){return CRM.url("civicrm/contact/view",{cid:e})}function _(e,t){var a={};return t.forEach(function(t){a[t.id]={styles:F(t),isAccruedTOIL:D(t,"toil"),isRequested:A(t),isAM:T("half_day_am",t,e.date),isPM:T("half_day_pm",t,e.date),isSingleDay:n(t.from_date).isSame(t.to_date,"day")}}),a}function y(){V.supportData.dayTypes=e.indexBy(V.supportData.dayTypes,"name"),V.supportData.leaveRequestStatuses=e.indexBy(V.supportData.leaveRequestStatuses,"value"),V.supportData.publicHolidays=e.transform(V.supportData.publicHolidays,function(e,n){e[p(n.date).valueOf()]=n},{})}function q(e){return e.forEach(function(e){var n=R(e);Y[e.contact_id]=Y[e.contact_id]||{},n.forEach(function(n){Y[e.contact_id][n.date]||(Y[e.contact_id][n.date]=[]),Y[e.contact_id][n.date].push(e)})}),a.resolve()}function C(){H.push(o.$on("LeaveCalendar::showMonths",B)),H.push(r.subscribe("LeaveRequest::new",u)),H.push(r.subscribe("LeaveRequest::edit",N)),H.push(r.subscribe("LeaveRequest::updatedByManager",N)),H.push(r.subscribe("LeaveRequest::delete",h)),H.push(r.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):N(e.leaveRequest)}))}function T(e,t,a){var o=V.supportData.dayTypes[e];return n(a).isSame(t.from_date,"day")?o.value===t.from_date_type:n(a).isSame(t.to_date,"day")?o.value===t.to_date_type:void 0}function D(e,n){return e.request_type===n}function P(e){return!!V.supportData.publicHolidays[p(e).valueOf()]}function A(n){var t=V.supportData.leaveRequestStatuses[n.status_id].name;return e.contains([c.statusNames.awaitingApproval,c.statusNames.moreInformationRequired],t)}function R(t){for(var a=[],o=n(t.from_date).clone(),s=n(t.to_date);o.isSameOrBefore(s);)o.month()===V.month.index&&o.year()===V.month.year&&a.push(e.find(V.month.days,function(e){return e.date===o.format("YYYY-MM-DD")})),o.add(1,"day");return a}function I(n){var t=e.find(V.supportData.leaveRequestStatuses,function(e){return e.name===n});return t?t.value:null}function w(){return[I(c.statusNames.approved),I(c.statusNames.adminApproved),I(c.statusNames.awaitingApproval),I(c.statusNames.moreInformationRequired)]}function O(){return V.month.loading=!0,a.all([k(),S()]).then(L).then(E).then(function(){W=!0,V.month.loading=!1})}function S(){return i.all({from_date:{to:V.month.days[V.month.days.length-1].date},to_date:{from:V.month.days[0].date},status_id:{IN:w()},contact_id:{IN:V.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(V.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return q(e.list)})}function k(){var n=V.month.days[0].date,t=V.month.days[V.month.days.length-1].date;return s.get(V.contacts.map(function(e){return e.id}),n,t).then(function(n){G=e.indexBy(n,"contact_id")})}function L(){return V.contactIdsToReduceTo&&(V.contacts=V.contacts.filter(function(n){return e.includes(V.contactIdsToReduceTo,n.contact_id)||e.find(Y,function(e){return e.contact_id===n.contact_id})})),a.resolve()}function M(n){var t=R(n);Y[n.contact_id]=Y[n.contact_id]||{},t.forEach(function(t){e.remove(Y[n.contact_id][t.date],function(e){return e.id===n.id})})}function x(){o.$emit("LeaveCalendar::monthDestroyed"),H.map(function(e){e.remove?e.remove():e()})}function $(n,t,o){var s,i;return n.contactsData[t]=n.contactsData[t]||{},i=m(t),s=!0===o?a.resolve():a.all([i.isWeekend(p(n.date)),i.isNonWorkingDay(p(n.date))]).then(function(a){e.assign(n.contactsData[t],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:P(n.date)})}),s.then(function(){return Y[t]&&Y[t][n.date]?Y[t][n.date]:[]}).then(function(a){a=U(a),e.assign(n.contactsData[t],{leaveRequests:a,leaveRequestsToShowInCell:v(a),leaveRequestsAttributes:_(n,a)})})}function E(){return a.all(V.month.days.map(function(e){return a.all(V.contacts.map(function(n){return $(e,n.id)}))}))}function B(n,t,a){!e.find(t,function(e){return e.index===V.month.index})?V.visible=!1:(V.currentPage=0,V.visible=!0,(a||!W)&&O())}function U(t){return e.sortBy(t,function(e){return+n(e.from_date).format("X")+(T("half_day_pm",e,e.from_date)?1:0)})}function F(n){var t=e.find(V.supportData.absenceTypes,function(e){return e.id===n.type_id});return n.balance_change>0?{borderColor:t.color}:{borderColor:t.color,backgroundColor:t.color}}function N(e){h(e),-1!==w().indexOf(e.status_id)&&u(e)}function j(e){return a.all(R(e).map(function(n){return $(n,e.contact_id,!0)}))}t.debug("Component: leave-calendar-month");var W=!1,H=[],G={},Y={},V=this;V.currentPage=0,V.pageSize=20,V.visible=!1,V.showContactName=!!V.showContactName,V.showOnlyWithLeaveRequests=!!V.showOnlyWithLeaveRequests,V.$onDestroy=x,V.contactsList=f,V.getContactUrl=g,function(){var e=n().month(V.month.index).year(V.month.year);y(),C(),V.month=l(e),o.$emit("LeaveCalendar::monthInjected")}()}t.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,n){"use strict";function t(n,t,a){function o(){var n=t.defer();return a.open(e.defaults(s(),{onConfirm:function(){n.resolve(!0)}})),n.promise}function s(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return n.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:s,promptBalanceChangeRecalculation:o}}n.factory("LeaveRequestService",t),t.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,n,t){function a(t,a,o,s,i,r,c,u){function l(n){y=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],n)||"toil"===q.leaveRequest.request_type?o.open(h(n)):f(n)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(t){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||("manager"===q.role?e.includes([C.awaitingApproval,C.moreInformationRequired],t):"3"===a?n().isBefore(q.leaveRequest.from_date):"2"===a)}function f(n){o.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(t){return t?e.assign(i.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){s.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(n)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var n=T[e].dialog;return{title:"Confirm "+n.title+"?",copyCancel:"Cancel",copyConfirm:n.btnLabel,classConfirm:"btn-"+n.btnClass,msg:n.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){b(e)}).catch(function(e){u.error("Error:",e)})}}}function v(e,n,t,a,o){e.stopPropagation(),s.openModal(n,t,a,o)}function b(n){var t=e.find(q.leaveRequestStatuses,function(e){return e.name===c.statusNames.awaitingApproval}).value;y===t&&r.publish("ManagerBadge:: Update Count"),r.publish("LeaveRequest::statusUpdate",{status:n,leaveRequest:q.leaveRequest})}function g(){var n=q.leaveRequestStatuses[q.leaveRequest.status_id].name,t=e.compact(e.map(T,function(t,a){return e.includes(t.allowedStatuses,n)?a:null}));!m(n)&&e.pull(t,"cancel"),"admin"!==q.role&&e.pull(t,"delete"),"staff"===q.role&&e.pull(t,"approve","reject"),"staff"!==q.role&&_(t),d()&&t.push("delete"),q.allowedActions=e.map(t,function(e){return{key:e,label:T[e].label,isDirectAction:T[e].isDirectAction}})}function _(n){e.each(n,function(t,a){"edit"===t&&(n[a]="respond"),e.includes(["respond","view"],t)&&(n[a]="edit")})}t.debug("Component: leave-request-action-dropdown");var y,q=this,C=c.statusNames,T={edit:{label:"Edit",allowedStatuses:[C.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[C.moreInformationRequired]},view:{label:"View",allowedStatuses:[C.approved,C.rejected,C.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[C.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.approved,C.rejected,C.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[C.awaitingApproval,C.moreInformationRequired,C.approved,C.rejected,C.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),g()}()}t.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){q.request.comments.push({contact_id:y,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return n.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===y?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function b(){var n=e.indexBy(q.request.comments,"contact_id"),t=Object.keys(n);return r.all({id:{IN:t}},{page:1,size:0}).then(function(n){q.comment.contacts=e.indexBy(n.list,"contact_id")})}function g(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&b()})}function _(){return q.loading.component=!0,c.get().then(function(e){y=e.contactId}).then(function(){q.loading.component=!1})}t.debug("Component: leave-request-popup-comments-tab");var y=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=u,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){o.$emit("LeaveRequestPopup::addTab",q),g(),_()}()}t.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,n,t){function a(t,a,o,s,i,r,c,u,l,d,m){function f(){ne.balance.closing=ne.balance.opening+ne.balance.change.amount}function p(e){return n(e,c.serverDateFormat).toDate()}function h(e){return n(e).format(c.serverDateFormat)}function v(e){var n;return i.resolve().then(function(){N(e),"from"===e&&F(),S("hours")&&(_(e),"from"!==e||ne.uiOptions.multipleDays||_("to")),ne.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(n=e.id!==ne.period.id,n&&(ne.period=e),!ne.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(n)return x()}).then(function(){return ne.onDateChangeExtended&&ne.onDateChangeExtended(e)}).then(function(){if(V(),!n)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(y)}function b(){return V(),E()}function g(){return ne.uiOptions.toDate=null,N("to"),i.resolve().then(V).then(ne.setDaysSelectionModeExtended).then(y).then(!ne.uiOptions.multipleDays&&E)}function _(e){ne.uiOptions.times[e].loading=!0}function y(){["from","to"].forEach(function(e){ne.loading[e+"DayTypes"]=!1,S("hours")&&(ne.uiOptions.times[e].loading=!1)})}function q(t){var a=n(ne.uiOptions[t+"Date"]).format(ne.uiOptions.userDateFormat.toUpperCase());return e.find(ne.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(){return ne.request?ne.request.request_type:ne.leaveType||null}function T(e){return n().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return z(),ne.loading.balanceChange=!0,ne.request.getBalanceChangeBreakdown().then(j).catch(P)}function P(n){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(n)?n:[n]),ne.loading.fromDayTypes=!1,ne.loading.balanceChange=!1,ne.loading.tab=!1,ne.loading.toDayTypes=!1}function A(){return ne.isMode("create")||ne.forceRecalculateBalanceChange?E():D()}function R(){var e=ne.request.attributes();return ne.uiOptions.fromDate=p(ne.request.from_date),ne.request.to_date=e.to_date,ne.request.to_date_type=e.to_date_type,ne.uiOptions.toDate=p(ne.request.to_date),ne.initDayTypesExtended?ne.initDayTypesExtended():i.resolve()}function I(){ee.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){Q()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,n){J(n)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function w(){ne.isMode("edit")&&(ne.isLeaveStatus(c.statusNames.approved)||ne.isLeaveStatus(c.statusNames.adminApproved))&&(Z={absenceTypeId:ne.request.type_id,value:ne.selectedAbsenceType.remainder-ne.request.balance_change})}function O(){o.$watch(function(){return ne.uiOptions.times.from.time},function(e,n){e!==n&&(ne.uiOptions.multipleDays||(K(e),V()))})}function S(e){return ne.selectedAbsenceType.calculation_unit_name===e}function k(e){return ne.request.request_type===e}function L(n){return e.includes(["weekend","non_working_day","public_holiday"],n)}function M(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){ne.requestDayTypes=e})}function x(){return u.get(ne.request.contact_id,ne.period.start_date,ne.period.end_date).then(function(e){ne.calendar=e})}function $(){var e=(ne.pagination.currentPage-1)*ne.pagination.numPerPage,n=e+ne.pagination.numPerPage;ne.pagination.filteredbreakdown=ne.balance.change.breakdown.slice(e,n)}function E(){return z(),ne.canCalculateChange()?(ne.loading.balanceChange=!0,ne.request.change_balance=!0,ne.calculateBalanceChange().then(j).catch(P).finally(function(){ne.loading.balanceChange=!1})):i.resolve()}function B(){ne.pagination.totalItems=ne.balance.change.breakdown.length,ne.pagination.filteredbreakdown=ne.balance.change.breakdown,ne.pagination.pageChanged()}function U(){return h(ne.request.from_date)===h(ne.request.to_date)}function F(){ne.uiOptions.toDate&&ne.uiOptions.fromDate&&ne.uiOptions.multipleDays&&n(ne.uiOptions.toDate).isSameOrBefore(ne.uiOptions.fromDate)&&(ne.uiOptions.toDate=null,N("to"))}function N(e){ne.resetUIInputsExtended&&ne.resetUIInputsExtended(e),V(),z()}function j(e){ne.balance.change=e,ne.request.balance_change=e.amount,f(),B(),ne.loading.balanceChange=!1}function W(){var e,t,a;ne.uiOptions.fromDate?(e=n(ne.uiOptions.fromDate).add(1,"day").toDate(),a=e,t=e):(a=p(ne.period.start_date),t=ne.uiOptions.date.to.options.minDate),ne.uiOptions.date.to.options.initDate=t,ne.uiOptions.date.to.options.minDate=a,ne.uiOptions.date.to.options.maxDate=p(ne.period.end_date)}function H(){return!ne.isMode("create")&&U()||ne.isMode("create")&&(k("sickness")||S("hours"))?ne.uiOptions.multipleDays=!1:ne.uiOptions.multipleDays=!0,i.resolve().then(ne.setDaysSelectionModeExtended)}function G(){Z&&Z.absenceTypeId===ne.selectedAbsenceType.id?ne.balance.opening=Z.value||0:ne.balance.opening=ne.selectedAbsenceType.remainder}function Y(){ne.selectedAbsenceType=e.find(ne.absenceTypes,function(e){return e.id===ne.request.type_id})}function V(){var e=ne.uiOptions,n=e.times;ne.request.from_date=e.fromDate?h(e.fromDate):null,ne.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(ne.request.to_date=ne.request.from_date,ne.request.to_date_type=ne.request.from_date_type),(S("hours")||k("toil"))&&(ne.request.from_date=ne.request.from_date&&n.from.time?ne.request.from_date+" "+n.from.time:null,ne.request.to_date=ne.request.to_date&&n.to.time?ne.request.to_date+" "+n.to.time:null)}function z(){ne.uiOptions.showBalance=ne.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function Q(){var e,n=ne.selectedAbsenceType.calculation_unit_name;return Y(),e=n!==ne.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&H).then(e&&ne.onAbsenceTypeUpdateExtended).then(e&&V).then(y).then(E)}function J(e){return ne.absenceTypes=e,Y(),n(ne.uiOptions.toDate).isAfter(ne.period.end_date)&&(ne.uiOptions.toDate=void 0,N("to")),G(),E()}function K(e){var n=T(e).add(ne.uiOptions.time_interval,"minutes");n.isAfter(T(ne.uiOptions.times.to.max))||(ne.uiOptions.times.to.min=n.format("HH:mm"),n.isAfter(T(ne.uiOptions.times.to.time))&&(ne.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],ne=this;ne.canManage=!1,ne.calendar={},ne.errors=[],ne.isRequired=!0,ne.requestDayTypes=[],ne.statusNames=c.statusNames,ne.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},ne.pagination={currentPage:1,filteredbreakdown:ne.balance.change.breakdown,numPerPage:7,totalItems:ne.balance.change.breakdown.length,pageChanged:$},ne.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:r.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},ne.convertDateFormatFromServer=p,ne.convertDateToServerFormat=h,ne.dateChangeHandler=v,ne.dateTypeChangeHandler=b,ne.daysSelectionModeChangeHandler=g,ne.disableAndShowLoadingTimeInput=_,ne.getMomentDateWithGivenTime=T,ne.handleError=P,ne.isCalculationUnit=S,ne.isLeaveType=k,ne.isNotWorkingDay=L,ne.performBalanceChangeCalculation=E,ne.setRequestDateTimesAndDateTypes=V,ne.updateEndTimeInputMinTime=K,ne.$onDestroy=X,function(){t("RequestModalDetails"+e.capitalize(C(ne.leaveType,ne.request))+"Controller",{detailsController:ne}),ne.canManage=ne.isRole("manager")||ne.isRole("admin"),ne.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",ne),I(),ne.initChildController().then(function(){return i.all([x(),M()])}).then(!ne.isMode("create")&&R).then(H).then(function(){if(!ne.isMode("create"))return i.resolve().then(ne.initTimesExtended).then(V)}).then(!ne.isMode("create")&&W).then(w).then(G).then(A).then(O).then(!ne.isMode("view")&&ne.initWatchersExtended).catch(P).finally(function(){ne.loading.tab=!1})}()}t.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,n,t){function a(t,a,o,s,i,r,c,u,l){function d(){return O.fileUploader&&O.fileUploader.queue.length>0}function m(){return O.getFilesAmount()People I approve filter displays only staff members who you approve leave for.
","People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.
"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");M.months=e}function p(){s.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){M.injectMonths=!0,I("injected").then(function(){R(e)}).then(function(){M.loading.calendar=!1})}function v(){O=a("LeaveCalendar"+t.capitalize(L)+"Controller").init(M)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return O.loadContacts().then(function(e){M.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function w(){return r.all([y(),C(),_()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return M.injectMonths&&(e=I("destroyed"),M.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){M.loading.calendar=!0}).then(A).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){M.selectedMonths=[n().month()]}function T(){return M.roleOverride?r.resolve().then(function(){L=M.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){L=e[0]?"admin":e[1]?"manager":"staff"})}function I(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var O,L,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=g,M.refresh=D,function(){T().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),w()])}).then(function(){return M.showFilters?$():t.noop}).then(function(){h()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){O(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function w(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([I(),T()]).then(g).then(k).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:R()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function I(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function O(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function L(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function M(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?w(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function k(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return M(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function E(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=L,W.contactsList=m,W.getContactUrl=v,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}), -define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return C(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return V()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return W(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),W("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):w(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function C(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function w(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function A(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function R(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():D()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function O(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function L(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function M(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(R(a.min,n)<=0||R(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(W)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){O(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function W(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function V(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return v(pe.request.from_date)===v(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=he[a].number_of_hours?R(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return W("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(A(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),L(),pe.initChildController().then(function(){return s.all([V(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return x().then(oe)}).then(!pe.isMode("create")&&Z).then(M).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()People I approve filter displays only staff members who you approve leave for.
","People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.
"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(x.selectedPeriod.start_date).clone().startOf("month"),a=n(x.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");x.months=e}function p(){s.$new().$watch(function(){return x.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){x.injectMonths=!0,O("injected").then(function(){R(e)}).then(function(){x.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(E)+"Controller").init(x)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){x.absencePeriods=t.sortBy(e,"start_date"),x.selectedPeriod=t.find(x.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){x.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){x.filters.optionValues.regions=e.hrjc_region,x.filters.optionValues.locations=e.hrjc_location,x.filters.optionValues.levelTypes=e.hrjc_level_type,x.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){x.supportData.absenceTypes=e[0],x.supportData.publicHolidays=e[1],x.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,x.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,x.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,x.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return x.injectMonths&&(e=O("destroyed"),x.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){x.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=x.selectedMonths.length?x.months.filter(function(e){return t.includes(x.selectedMonths,e.index)}):x.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){x.selectedMonths=[n().month()]}function T(){return x.roleOverride?r.resolve().then(function(){E=x.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){E=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===x.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,E,x=this;x.absencePeriods=[],x.contacts=[],x.contactIdsToReduceTo=null,x.injectMonths=!1,x.months=[],x.selectedMonths=null,x.selectedPeriod=null,x.showContactName=!1,x.showFilters=!1,x.supportData={},x.loading={calendar:!0,page:!0},x.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},x.labelPeriod=g,x.refresh=D,function(){T().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return x.showFilters?$():t.noop}).then(function(){h()}).then(function(){x.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r,o){"use strict";function s(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function i(e){return e.isAM?"AM":e.isPM?"PM":""}function u(e){var n=t(e.from_date).isSame(g.date,"day"),a=t(e.to_date).isSame(g.date,"day");return n?t(e.from_date).format("HH:mm"):a?t(e.to_date).format("HH:mm"):""}function c(t,n){g.contactData.leaveRequestsAttributes[t.id].absenceTypeTitle=e.find(g.supportData.absenceTypes,{id:t.type_id}).title}function l(t,n){var a=e.find(g.supportData.absenceTypes,{id:t.type_id}),r=e.find(g.supportData.calculationUnits,{value:a.calculation_unit});n.unit=r.name}function d(e,t){t.from_date=new Date(e.from_date),t.to_date=new Date(e.to_date)}function f(t,n){"days"===n.unit&&(n.from_date_type=e.find(g.supportData.dayTypes,{value:t.from_date_type}).label,n.to_date_type=e.find(g.supportData.dayTypes,{value:t.to_date_type}).label)}function m(e,t){var n="";n=t.isAccruedTOIL?"AT":"days"===t.unit?i(t):u(e),t.label=n}function p(e){var t=g.contactData.leaveRequestsAttributes[e.id];[l,f,m,d,c].forEach(function(n){n.call(this,e,t)})}function h(e,t){r(function(){g.tooltip[e+"_hovered"]=t,g.tooltip.show=g.tooltip.day_cell_hovered||g.tooltip.tooltip_hovered},t?0:100)}function v(){a.$watch("day.contactData.leaveRequests",function(){g.contactData&&g.contactData.leaveRequests&&g.contactData.leaveRequests.forEach(p)},!0)}n.debug("Component: leave-calendar-day");var g=this;g.tooltip={show:!1,day_cell_hovered:!1,tooltip_hovered:!1},g.openLeavePopup=s,g.toggleTooltip=h,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","$timeout","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){q([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(Y.period.start_date)&&r.isSameOrBefore(Y.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return V[e]}function m(){return Y.showOnlyWithLeaveRequests?Y.contacts.filter(function(e){return Object.keys(G[e.id]||{}).length}):Y.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){var t=g(e);t&&(x(t),U(t))}function v(t){var n={request_type:"toil"};return e.some(t,n)&&!e.every(t,n)?e.filter(t,n):t}function g(t){var n;return e.find(G[t.contact_id],function(a){return n=e.find(a,function(e){return+e.id==+t.id})}),n}function b(e){return CRM.url("civicrm/contact/view",{cid:e})}function y(e,n){var a={};return n.forEach(function(n){a[n.id]={styles:N(n),isAccruedTOIL:A(n,"toil"),isRequested:P(n),isAM:C("half_day_am",n,e.date),isPM:C("half_day_pm",n,e.date),isSingleDay:t(n.from_date).isSame(n.to_date,"day")}}),a}function _(){Y.supportData.dayTypes=e.indexBy(Y.supportData.dayTypes,"name"),Y.supportData.leaveRequestStatuses=e.indexBy(Y.supportData.leaveRequestStatuses,"value"),Y.supportData.publicHolidays=e.transform(Y.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function q(e){return e.forEach(function(e){var t=D(e);G[e.contact_id]=G[e.contact_id]||{},t.forEach(function(t){G[e.contact_id][t.date]||(G[e.contact_id][t.date]=[]),G[e.contact_id][t.date].push(e)})}),a.resolve()}function $(){W.push(r.$on("LeaveCalendar::showMonths",j)),W.push(i.subscribe("LeaveRequest::new",c)),W.push(i.subscribe("LeaveRequest::edit",F)),W.push(i.subscribe("LeaveRequest::updatedByManager",F)),W.push(i.subscribe("LeaveRequest::delete",h)),W.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):F(e.leaveRequest)}))}function C(e,n,a){var r=Y.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function A(e,t){return e.request_type===t}function w(e){return!!Y.supportData.publicHolidays[p(e).valueOf()]}function P(t){var n=Y.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function D(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===Y.month.index&&r.year()===Y.month.year&&a.push(e.find(Y.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function R(t){var n=e.find(Y.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function S(){return[R(u.statusNames.approved),R(u.statusNames.adminApproved),R(u.statusNames.awaitingApproval),R(u.statusNames.moreInformationRequired)]}function T(){return Y.month.loading=!0,a.all([I(),O()]).then(E).then(k).then(function(){H=!0,Y.month.loading=!1})}function O(){return s.all({from_date:{to:Y.month.days[Y.month.days.length-1].date},to_date:{from:Y.month.days[0].date},status_id:{IN:S()},contact_id:{IN:Y.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(Y.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return q(e.list)})}function I(){var t=Y.month.days[0].date,n=Y.month.days[Y.month.days.length-1].date;return o.get(Y.contacts.map(function(e){return e.id}),t,n).then(function(t){V=e.indexBy(t,"contact_id")})}function E(){return Y.contactIdsToReduceTo&&(Y.contacts=Y.contacts.filter(function(t){return e.includes(Y.contactIdsToReduceTo,t.contact_id)||e.find(G,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function x(t){var n=D(t);G[t.contact_id]=G[t.contact_id]||{},n.forEach(function(n){e.remove(G[t.contact_id][n.date],function(e){return e.id===t.id})})}function M(){r.$emit("LeaveCalendar::monthDestroyed"),W.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:w(t.date)})}),o.then(function(){return G[n]&&G[n][t.date]?G[n][t.date]:[]}).then(function(a){a=B(a),e.assign(t.contactsData[n],{leaveRequests:a,leaveRequestsToShowInCell:v(a),leaveRequestsAttributes:y(t,a)})})}function k(){return a.all(Y.month.days.map(function(e){return a.all(Y.contacts.map(function(t){return L(e,t.id)}))}))}function j(t,n,a){!e.find(n,function(e){return e.index===Y.month.index})?Y.visible=!1:(Y.currentPage=0,Y.visible=!0,(a||!H)&&T())}function B(n){return e.sortBy(n,function(e){return+t(e.from_date).format("X")+(C("half_day_pm",e,e.from_date)?1:0)})}function N(t){var n=e.find(Y.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function F(e){h(e),-1!==S().indexOf(e.status_id)&&c(e)}function U(e){return a.all(D(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var H=!1,W=[],V={},G={},Y=this;Y.currentPage=0,Y.pageSize=20,Y.visible=!1,Y.showContactName=!!Y.showContactName,Y.showOnlyWithLeaveRequests=!!Y.showOnlyWithLeaveRequests,Y.$onDestroy=M,Y.contactsList=m,Y.getContactUrl=b,function(){var e=t().month(Y.month.index).year(Y.month.year);_(),$(),Y.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||("manager"===q.role?e.includes([$.awaitingApproval,$.moreInformationRequired],n):"3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a)}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}), +a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return M()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function R(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){K(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function T(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function E(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function x(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function M(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function L(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function J(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function K(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:L},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=E,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),R(),te.initChildController().then(function(){return s.all([M(),x()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(T).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.
","People I approve filter displays only staff members who you approve leave for.
","People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.
"].join(""))}n.debug("LeaveCalendarAdminController");var v,h;return{init:function(e){return h=e,h.showContactDetailsLink=!0,h.showContactName=!0,h.showFilters=!0,h.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],h.filters.userSettings.assignedTo=h.filtersByAssignee[0],h.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(M.selectedPeriod.start_date).clone().startOf("month"),a=n(M.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");M.months=e}function p(){s.$new().$watch(function(){return M.selectedMonths},function(t,n){null===n||e.equals(t,n)||D()})}function v(e){M.injectMonths=!0,I("injected").then(function(){D(e)}).then(function(){M.loading.calendar=!1})}function h(){O=a("LeaveCalendar"+t.capitalize(L)+"Controller").init(M)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){M.absencePeriods=t.sortBy(e,"start_date"),M.selectedPeriod=t.find(M.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return O.loadContacts().then(function(e){M.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){M.filters.optionValues.regions=e.hrjc_region,M.filters.optionValues.locations=e.hrjc_location,M.filters.optionValues.levelTypes=e.hrjc_level_type,M.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){M.supportData.absenceTypes=e[0],M.supportData.publicHolidays=e[1],M.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,M.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,M.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,M.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return M.injectMonths&&(e=I("destroyed"),M.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function R(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){M.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){v("contacts"===e)})}function D(e){var n=M.selectedMonths.length?M.months.filter(function(e){return t.includes(M.selectedMonths,e.index)}):M.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){M.selectedMonths=[n().month()]}function T(){return M.roleOverride?r.resolve().then(function(){L=M.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){L=e[0]?"admin":e[1]?"manager":"staff"})}function I(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===M.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var O,L,M=this;M.absencePeriods=[],M.contacts=[],M.contactIdsToReduceTo=null,M.injectMonths=!1,M.months=[],M.selectedMonths=null,M.selectedPeriod=null,M.showContactName=!1,M.showFilters=!1,M.supportData={},M.loading={calendar:!0,page:!0},M.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},M.labelPeriod=g,M.refresh=R,function(){T().then(p).then(h).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return M.showFilters?$():t.noop}).then(function(){v()}).then(function(){M.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function v(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function h(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),v())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){h()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(W.period.start_date)&&r.isSameOrBefore(W.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return W.showOnlyWithLeaveRequests?W.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):W.contacts}function p(e){return t(e,u.serverDateFormat)}function v(e){O(e),B(e)}function h(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return W.contactIdsToReduceTo&&(W.contacts=W.contacts.filter(function(t){return e.includes(W.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){W.supportData.dayTypes=e.indexBy(W.supportData.dayTypes,"name"),W.supportData.leaveRequestStatuses=e.indexBy(W.supportData.leaveRequestStatuses,"value"),W.supportData.publicHolidays=e.transform(W.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=w(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",x)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",v)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?v(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=W.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function C(e){return!!W.supportData.publicHolidays[p(e).valueOf()]}function A(t){var n=W.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function w(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===W.month.index&&r.year()===W.month.year&&a.push(e.find(W.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function R(t){var n=e.find(W.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function D(){return[R(u.statusNames.approved),R(u.statusNames.adminApproved),R(u.statusNames.awaitingApproval),R(u.statusNames.moreInformationRequired)]}function S(){return W.month.loading=!0,a.all([I(),T()]).then(g).then(k).then(function(){N=!0}).then(function(){W.month.loading=!1})}function T(){return s.all({from_date:{to:W.month.days[W.month.days.length-1].date},to_date:{from:W.month.days[0].date},status_id:{IN:D()},contact_id:{IN:W.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(W.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function I(){var t=W.month.days[0].date,n=W.month.days[W.month.days.length-1].date;return o.get(W.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function O(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function L(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function M(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:C(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?A(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function k(){return a.all(W.month.days.map(function(e){return a.all(W.contacts.map(function(t){return M(e,t.id)}))}))}function x(t,n,a){!e.find(n,function(e){return e.index===W.month.index})?W.visible=!1:(W.currentPage=0,W.visible=!0,(a||!N)&&S())}function E(t){var n=e.find(W.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(v(t),-1!==D().indexOf(e.status_id)&&c(e))}function B(e){return a.all(w(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},W=this;W.currentPage=0,W.pageSize=20,W.visible=!1,W.showContactName=!!W.showContactName,W.showOnlyWithLeaveRequests=!!W.showOnlyWithLeaveRequests,W.$onDestroy=L,W.contactsList=m,W.getContactUrl=h,function(){var e=t().month(W.month.index).year(W.month.year);b(),_(),W.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}), -define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(v(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):v(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function v(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function h(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=h,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function v(e){return q.mode===e}function h(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=v,q.onBeforeSubmit=h,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function v(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return C(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return V()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return W(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),W("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=h(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):A(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function C(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function A(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function w(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function R(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function D(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():R()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=v(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=v(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function O(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function L(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function M(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(D(a.min,n)<=0||D(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function x(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(W)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){O(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function W(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(h(t)).then(function(t){ve[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return ve[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function V(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return h(pe.request.from_date)===h(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=v(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=v(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=ve[a].number_of_hours?D(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?h(e.fromDate):null,pe.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return W("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,ve={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=v,pe.convertDateToServerFormat=h,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(w(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),L(),pe.initChildController().then(function(){return s.all([V(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return x().then(oe)}).then(!pe.isMode("create")&&Z).then(M).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.
","People I approve filter displays only staff members who you approve leave for.
","People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.
"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||S()})}function h(e){E.injectMonths=!0,O("injected").then(function(){S(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(m).then(T)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function C(){return l.all()}function A(){return r.all([y(),C(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(w).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function S(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function T(){E.selectedMonths=[n().month()]}function R(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){R().then(p).then(v).then(w).then(b).then(function(){return r.all([q(),A()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r,o){"use strict";function s(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function i(e){return e.isAM?"AM":e.isPM?"PM":""}function u(e){var n=t(e.from_date).isSame(g.date,"day"),a=t(e.to_date).isSame(g.date,"day");return n?t(e.from_date).format("HH:mm"):a?t(e.to_date).format("HH:mm"):""}function c(t,n){g.contactData.leaveRequestsAttributes[t.id].absenceTypeTitle=e.find(g.supportData.absenceTypes,{id:t.type_id}).title}function l(t,n){var a=e.find(g.supportData.absenceTypes,{id:t.type_id}),r=e.find(g.supportData.calculationUnits,{value:a.calculation_unit});n.unit=r.name}function d(e,t){t.from_date=new Date(e.from_date),t.to_date=new Date(e.to_date)}function f(t,n){"days"===n.unit&&(n.from_date_type=e.find(g.supportData.dayTypes,{value:t.from_date_type}).label,n.to_date_type=e.find(g.supportData.dayTypes,{value:t.to_date_type}).label)}function m(e,t){var n="";n=t.isAccruedTOIL?"AT":"days"===t.unit?i(t):u(e),t.label=n}function p(e){var t=g.contactData.leaveRequestsAttributes[e.id];[l,f,m,d,c].forEach(function(n){n.call(this,e,t)})}function h(e,t){r(function(){g.tooltip[e+"_hovered"]=t,g.tooltip.show=g.tooltip.day_cell_hovered||g.tooltip.tooltip_hovered},t?0:100)}function v(){a.$watch("day.contactData.leaveRequests",function(){g.contactData&&g.contactData.leaveRequests&&g.contactData.leaveRequests.forEach(p)},!0)}n.debug("Component: leave-calendar-day");var g=this;g.tooltip={show:!1,day_cell_hovered:!1,tooltip_hovered:!1},g.openLeavePopup=s,g.toggleTooltip=h,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","$timeout","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){q([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(Y.period.start_date)&&r.isSameOrBefore(Y.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return V[e]}function m(){return Y.showOnlyWithLeaveRequests?Y.contacts.filter(function(e){return Object.keys(G[e.id]||{}).length}):Y.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){var t=g(e);t&&(E(t),U(t))}function v(t){var n={request_type:"toil"};return e.some(t,n)&&!e.every(t,n)?e.filter(t,n):t}function g(t){var n;return e.find(G[t.contact_id],function(a){return n=e.find(a,function(e){return+e.id==+t.id})}),n}function b(e){return CRM.url("civicrm/contact/view",{cid:e})}function y(e,n){var a={};return n.forEach(function(n){a[n.id]={styles:N(n),isAccruedTOIL:A(n,"toil"),isRequested:P(n),isAM:C("half_day_am",n,e.date),isPM:C("half_day_pm",n,e.date),isSingleDay:t(n.from_date).isSame(n.to_date,"day")}}),a}function _(){Y.supportData.dayTypes=e.indexBy(Y.supportData.dayTypes,"name"),Y.supportData.leaveRequestStatuses=e.indexBy(Y.supportData.leaveRequestStatuses,"value"),Y.supportData.publicHolidays=e.transform(Y.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function q(e){return e.forEach(function(e){var t=D(e);G[e.contact_id]=G[e.contact_id]||{},t.forEach(function(t){G[e.contact_id][t.date]||(G[e.contact_id][t.date]=[]),G[e.contact_id][t.date].push(e)})}),a.resolve()}function $(){W.push(r.$on("LeaveCalendar::showMonths",j)),W.push(i.subscribe("LeaveRequest::new",c)),W.push(i.subscribe("LeaveRequest::edit",F)),W.push(i.subscribe("LeaveRequest::updatedByManager",F)),W.push(i.subscribe("LeaveRequest::delete",h)),W.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):F(e.leaveRequest)}))}function C(e,n,a){var r=Y.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function A(e,t){return e.request_type===t}function w(e){return!!Y.supportData.publicHolidays[p(e).valueOf()]}function P(t){var n=Y.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function D(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===Y.month.index&&r.year()===Y.month.year&&a.push(e.find(Y.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function S(t){var n=e.find(Y.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function T(){return[S(u.statusNames.approved),S(u.statusNames.adminApproved),S(u.statusNames.awaitingApproval),S(u.statusNames.moreInformationRequired)]}function R(){return Y.month.loading=!0,a.all([I(),O()]).then(x).then(k).then(function(){H=!0,Y.month.loading=!1})}function O(){return s.all({from_date:{to:Y.month.days[Y.month.days.length-1].date},to_date:{from:Y.month.days[0].date},status_id:{IN:T()},contact_id:{IN:Y.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(Y.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return q(e.list)})}function I(){var t=Y.month.days[0].date,n=Y.month.days[Y.month.days.length-1].date;return o.get(Y.contacts.map(function(e){return e.id}),t,n).then(function(t){V=e.indexBy(t,"contact_id")})}function x(){return Y.contactIdsToReduceTo&&(Y.contacts=Y.contacts.filter(function(t){return e.includes(Y.contactIdsToReduceTo,t.contact_id)||e.find(G,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function E(t){var n=D(t);G[t.contact_id]=G[t.contact_id]||{},n.forEach(function(n){e.remove(G[t.contact_id][n.date],function(e){return e.id===t.id})})}function L(){r.$emit("LeaveCalendar::monthDestroyed"),W.map(function(e){e.remove?e.remove():e()})}function M(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:w(t.date)})}),o.then(function(){return G[n]&&G[n][t.date]?G[n][t.date]:[]}).then(function(a){a=B(a),e.assign(t.contactsData[n],{leaveRequests:a,leaveRequestsToShowInCell:v(a),leaveRequestsAttributes:y(t,a)})})}function k(){return a.all(Y.month.days.map(function(e){return a.all(Y.contacts.map(function(t){return M(e,t.id)}))}))}function j(t,n,a){!e.find(n,function(e){return e.index===Y.month.index})?Y.visible=!1:(Y.currentPage=0,Y.visible=!0,(a||!H)&&R())}function B(n){return e.sortBy(n,function(e){return+t(e.from_date).format("X")+(C("half_day_pm",e,e.from_date)?1:0)})}function N(t){var n=e.find(Y.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function F(e){h(e),-1!==T().indexOf(e.status_id)&&c(e)}function U(e){return a.all(D(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var H=!1,W=[],V={},G={},Y=this;Y.currentPage=0,Y.pageSize=20,Y.visible=!1,Y.showContactName=!!Y.showContactName,Y.showOnlyWithLeaveRequests=!!Y.showOnlyWithLeaveRequests,Y.$onDestroy=L,Y.contactsList=m,Y.getContactUrl=b,function(){var e=t().month(Y.month.index).year(Y.month.year);_(),$(),Y.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o, +promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||("manager"===q.role?e.includes([$.awaitingApproval,$.moreInformationRequired],n):"3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a)}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=C[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(C,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:C[e].label,isDirectAction:C[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,C={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,t){"use strict";t.factory("WorkPatternAPI",["$log","api",function(t,n){function a(t){var n=e.clone(t);return n.workPattern=n["api.WorkPattern.get"].values[0],delete n["api.WorkPattern.get"],n}return t.debug("WorkPatternAPI"),n.extend({assignWorkPattern:function(t,n,a,r,o,s){return this.sendPOST("ContactWorkPattern","create",e.assign({},s,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,change_reason:o})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(n,a,r,o){return t.debug("WorkPatternAPI.getCalendar",n,a,r,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:r}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,r){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),r).then(function(e){return e=e.values,e.map(a)})}})}])}),define("leave-absences/shared/instances/calendar.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t,n){"use strict";n.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(n,a,r,o,s){function i(t,n){return c().then(function(a){var r=this.days[u(t).valueOf()];return!!r&&e.find(a,function(e){return e.name===n}).value===r.type}.bind(this))}function u(e){return t(e,o.serverDateFormat).clone()}function c(){return l=l||s.valuesOf("hrleaveandabsences_work_day_type")}var l;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return i.call(this,e,"non_working_day")},isWeekend:function(e){return i.call(this,e,"weekend")},isWorkingDay:function(e){return i.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[u(e.date).valueOf()]=e}),e(t).omit("calendar").assign({days:n}).value()}})}])}),define("leave-absences/shared/models/calendar.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/calendar.instance"],function(e,t){"use strict";t.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(t,n,a,r){return t.debug("Calendar"),n.extend({get:function(n,o,s,i){return t.debug("Calendar.get"),a.getCalendar(n,o,s,i).then(function(t){var a=t.values.map(function(e){return r.init(e)});return e.isArray(n)?a:a[0]})}})}])}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f){function m(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(w).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function C(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function A(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(w)}function w(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():A()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function S(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){K(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function T(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function R(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(w).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,m(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function J(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function K(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=C(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(C(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(C(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=C,te.handleError=w,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),S(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(T).then(V).then(P).then(R).then(!te.isMode("view")&&te.initWatchersExtended).catch(w).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return R.fileUploader&&R.fileUploader.queue.length>0}function f(){return R.getFilesAmount()When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.
","People I approve filter displays only staff members who you approve leave for.
","People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.
"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,f){function m(){for(var e=[],t=n(L.selectedPeriod.start_date).clone().startOf("month"),a=n(L.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");L.months=e}function p(){s.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||R()})}function h(e){L.injectMonths=!0,I("injected").then(function(){R(e)}).then(function(){L.loading.calendar=!1})}function v(){x=a("LeaveCalendar"+t.capitalize(O)+"Controller").init(L)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(m).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return x.loadContacts().then(function(e){L.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){L.filters.optionValues.regions=e.hrjc_region,L.filters.optionValues.locations=e.hrjc_location,L.filters.optionValues.levelTypes=e.hrjc_level_type,L.filters.optionValues.departments=e.hrjc_department})}function w(){return l.all()}function C(){return r.all([y(),w(),_()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return L.injectMonths&&(e=I("destroyed"),L.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){ -e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then(A).then("period"===e?m:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function R(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){L.selectedMonths=[n().month()]}function T(){return L.roleOverride?r.resolve().then(function(){O=L.roleOverride}):r.all([f(i.permissions.admin.administer),f(i.permissions.ssp.manage)]).then(function(e){O=e[0]?"admin":e[1]?"manager":"staff"})}function I(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var x,O,L=this;L.absencePeriods=[],L.contacts=[],L.contactIdsToReduceTo=null,L.injectMonths=!1,L.months=[],L.selectedMonths=null,L.selectedPeriod=null,L.showContactName=!1,L.showFilters=!1,L.supportData={},L.loading={calendar:!0,page:!0},L.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},L.labelPeriod=g,L.refresh=D,function(){T().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),C()])}).then(function(){return L.showFilters?$():t.noop}).then(function(){h()}).then(function(){L.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r){"use strict";function o(){_.calculationUnit=s(_.supportData.calculationUnits,"value",g.calculation_unit)}function s(t,n,a){return e.find(t,function(e){return+e[n]==+a})}function i(){var e,n;return n=t(_.contactData.leaveRequest.from_date).isSame(_.contactData.leaveRequest.to_date,"day"),e=n?"single-date":"multiple-dates","type-"+_.calculationUnit.name+"-on-"+e+"-tooltip"}function u(){g=s(_.supportData.absenceTypes,"id",_.contactData.leaveRequest.type_id),_.contactData.leaveRequest["type_id.title"]=g.title}function c(){"days"===_.calculationUnit.name&&(b=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.from_date_type),y=s(_.supportData.dayTypes,"value",_.contactData.leaveRequest.to_date_type),_.contactData.leaveRequest["from_date_type.label"]=b.label,_.contactData.leaveRequest["to_date_type.label"]=y.label)}function l(e,t,n,a,o){e.stopPropagation(),r.openModal(t,n,a,o)}function d(){_.dates.from=new Date(_.contactData.leaveRequest.from_date),_.dates.to=new Date(_.contactData.leaveRequest.to_date)}function f(){_.contactData.isAccruedTOIL?_.label="AT":"days"===_.calculationUnit.name?m():p()}function m(){_.label=_.contactData.isAM?"AM":_.contactData.isPM?"PM":""}function p(){var e=t(_.contactData.leaveRequest.from_date).isSame(_.date,"day"),n=t(_.contactData.leaveRequest.to_date).isSame(_.date,"day");_.label=e?t(_.contactData.leaveRequest.from_date).format("HH:mm"):n?t(_.contactData.leaveRequest.to_date).format("HH:mm"):""}function h(){_.tooltipTemplate=_.contactData.isAccruedTOIL?"accrued-toil-tooltip":i()}function v(){a.$watch("day.contactData.leaveRequest",function(){_.contactData&&_.contactData.leaveRequest&&(u(),o(),c(),f(),d(),h())})}n.debug("Component: leave-calendar-day");var g,b,y,_=this;_.calculationUnit="",_.dates={from:null,to:null},_.label="",_.tooltipTemplate=null,_.openLeavePopup=l,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){y([e]),B(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(V.period.start_date)&&r.isSameOrBefore(V.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function f(e){return U[e]}function m(){return V.showOnlyWithLeaveRequests?V.contacts.filter(function(e){return Object.keys(H[e.id]||{}).length}):V.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){x(e),B(e)}function v(e){return CRM.url("civicrm/contact/view",{cid:e})}function g(){return V.contactIdsToReduceTo&&(V.contacts=V.contacts.filter(function(t){return e.includes(V.contactIdsToReduceTo,t.contact_id)||e.find(H,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function b(){V.supportData.dayTypes=e.indexBy(V.supportData.dayTypes,"name"),V.supportData.leaveRequestStatuses=e.indexBy(V.supportData.leaveRequestStatuses,"value"),V.supportData.publicHolidays=e.transform(V.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function y(e){return e.forEach(function(e){var t=A(e);H[e.contact_id]=H[e.contact_id]||{},t.forEach(function(t){H[e.contact_id][t.date]=e})}),a.resolve()}function _(){F.push(r.$on("LeaveCalendar::showMonths",M)),F.push(i.subscribe("LeaveRequest::new",c)),F.push(i.subscribe("LeaveRequest::edit",j)),F.push(i.subscribe("LeaveRequest::updatedByManager",j)),F.push(i.subscribe("LeaveRequest::delete",h)),F.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):j(e.leaveRequest)}))}function q(e,n,a){var r=V.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function $(e,t){return e.request_type===t}function w(e){return!!V.supportData.publicHolidays[p(e).valueOf()]}function C(t){var n=V.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function A(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===V.month.index&&r.year()===V.month.year&&a.push(e.find(V.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function P(t){return e.find(H[t.contact_id],function(e){return t.id===e.id})}function D(t){var n=e.find(V.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function R(){return[D(u.statusNames.approved),D(u.statusNames.adminApproved),D(u.statusNames.awaitingApproval),D(u.statusNames.moreInformationRequired)]}function S(){return V.month.loading=!0,a.all([I(),T()]).then(g).then(k).then(function(){N=!0}).then(function(){V.month.loading=!1})}function T(){return s.all({from_date:{to:V.month.days[V.month.days.length-1].date},to_date:{from:V.month.days[0].date},status_id:{IN:R()},contact_id:{IN:V.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(V.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return y(e.list)})}function I(){var t=V.month.days[0].date,n=V.month.days[V.month.days.length-1].date;return o.get(V.contacts.map(function(e){return e.id}),t,n).then(function(t){U=e.indexBy(t,"contact_id")})}function x(t){H[t.contact_id]=e.omit(H[t.contact_id],function(e){return e.id===t.id})}function O(){r.$emit("LeaveCalendar::monthDestroyed"),F.map(function(e){e.remove?e.remove():e()})}function L(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=f(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:w(t.date)})}),o.then(function(){return H[n]?H[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?E(a):null,isAccruedTOIL:a?$(a,"toil"):null,isRequested:a?C(a):null,isAM:a?q("half_day_am",a,t.date):null,isPM:a?q("half_day_pm",a,t.date):null})})}function k(){return a.all(V.month.days.map(function(e){return a.all(V.contacts.map(function(t){return L(e,t.id)}))}))}function M(t,n,a){!e.find(n,function(e){return e.index===V.month.index})?V.visible=!1:(V.currentPage=0,V.visible=!0,(a||!N)&&S())}function E(t){var n=e.find(V.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function j(e){var t=P(e);t&&(h(t),-1!==R().indexOf(e.status_id)&&c(e))}function B(e){return a.all(A(e).map(function(t){return L(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var N=!1,F=[],U={},H={},V=this;V.currentPage=0,V.pageSize=20,V.visible=!1,V.showContactName=!!V.showContactName,V.showOnlyWithLeaveRequests=!!V.showOnlyWithLeaveRequests,V.$onDestroy=O,V.contactsList=m,V.getContactUrl=v,function(){var e=t().month(V.month.index).year(V.month.year);b(),_(),V.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):m(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function f(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||!!e.includes([$.awaitingApproval,$.moreInformationRequired],n)&&("manager"===q.role||("3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a))}function m(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=w[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(w,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!f(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:w[e].label,isDirectAction:w[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,w={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function f(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function m(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=f,q.getActiveComments=m,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,f,m){function p(){pe.balance.closing=pe.balance.opening+pe.balance.change.amount}function h(e){return t(e,u.serverDateFormat).toDate()}function v(e){return t(e).format(u.serverDateFormat)}function g(e){var t;return s.resolve().then(function(){X(e),"from"===e&&K(),B("hours")&&(_(e),"from"!==e||pe.uiOptions.multipleDays||_("to")),pe.loading[e+"DayTypes"]=!0}).then(pe.onDateChangeExtended).then(function(){return w(e)}).then(function(e){if(t=e.id!==pe.period.id,t&&(pe.period=e),!pe.period.id)return s.reject("Please change date as it is not in any absence period")}).then(Z).then(function(){if(t)return W()}).then(function(){return U(pe.uiOptions[e+"Date"],e)}).then(function(){if(B("hours"))return V(e).then(function(){ne(e,!0)})}).then(function(){if(oe(),!t)return Y();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(S)}function b(){return oe(),Y()}function y(){return pe.uiOptions.toDate=null,X("to"),s.resolve().then(function(){if(B("hours")&&pe.uiOptions.fromDate)return _("from"),!pe.uiOptions.multipleDays&&_("to"),V("from").then(function(){ne("from",!0)}).then(oe)}).then(pe.setDaysSelectionModeExtended).then(!pe.uiOptions.multipleDays&&Y)}function _(e){var t=pe.uiOptions.times[e];t.loading=!0,t.disabled=!0}function q(t,n){var a=pe.uiOptions.times[t],r=e.clone(n.time_from),o=e.clone(n.time_to);pe.uiOptions.multipleDays||("from"===t&&o&&r&&(o=P(o).subtract(pe.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&r&&o&&(r=P(r).add(pe.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=r||"00:00",a.max=o||"00:00",a.time="to"===t?a.max:a.min,a.disabled=!1}function $(t,n){return t?(t=v(t),d.isPublicHoliday(t).then(function(n){return n?pe.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):C(t,pe.requestDayTypes).then(function(t){return t.length?t:pe.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return te(n,e),e})):s.reject([])}function w(n){var a=t(pe.uiOptions[n+"Date"]).format(pe.uiOptions.userDateFormat.toUpperCase());return e.find(pe.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function C(e,n){return e=t(e),s.all([pe.calendar.isNonWorkingDay(e),pe.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?n.filter(function(t){return t.name===e}):[]})}function A(){return pe.request?pe.request.request_type:pe.leaveType||null}function P(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return ie(),pe.loading.balanceChange=!0,pe.request.getBalanceChangeBreakdown().then(Q).catch(S)}function R(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function S(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),pe.loading.fromDayTypes=!1,pe.loading.balanceChange=!1,pe.loading.tab=!1,pe.loading.toDayTypes=!1}function T(){return pe.isMode("create")||pe.forceRecalculateBalanceChange?Y():D()}function I(){var e=pe.request.attributes();return pe.uiOptions.fromDate=h(pe.request.from_date),U(pe.uiOptions.fromDate,"from").then(function(){return pe.request.to_date=e.to_date,pe.request.to_date_type=e.to_date_type,pe.uiOptions.toDate=h(pe.request.to_date),U(pe.uiOptions.toDate,"to")})}function x(e){o.$watch("detailsTab.uiOptions.times."+e+".amount",function(e,t){B("days")||+e==+t||(se(),pe.performBalanceChangeCalculation())})}function O(){me.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){ce()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){le(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",Y))}function L(){pe.isMode("edit")&&(pe.isLeaveStatus(u.statusNames.approved)||pe.isLeaveStatus(u.statusNames.adminApproved))&&(fe={absenceTypeId:pe.request.type_id,value:pe.selectedAbsenceType.remainder-pe.request.balance_change})}function k(e){var n=t(pe.request[e+"_date"]).format("HH:mm"),a=pe.uiOptions.times[e];(R(a.min,n)<=0||R(a.max,n)>=0)&&(n="from"===e?a.min:a.max),pe.uiOptions.times[e].time=n}function M(){var e=pe.uiOptions.multipleDays?["from","to"]:["from"],t=pe.uiOptions.times;return s.all(e.map(V)).then(function(){["from","to"].forEach(function(e){k(e),ne(e),t[e].amount=Math.min(pe.request[e+"_date_amount"],t[e].maxAmount).toString()}),pe.uiOptions.multipleDays||de(pe.uiOptions.times.from.time)}).then(se)}function E(){["from","to"].forEach(function(e){x(e),j(e)})}function j(e){o.$watch("detailsTab.uiOptions.times."+e+".time",function(t,n){B("days")||t===n||(oe(),t&&(!pe.uiOptions.multipleDays&&"from"===e&&de(t),ne(e,!0)))})}function B(e){return pe.selectedAbsenceType.calculation_unit_name===e}function N(e){return pe.request.request_type===e}function F(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function U(e,t){return $(e,t).then(function(){pe.loading[t+"DayTypes"]=!1})}function H(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){pe.requestDayTypes=e})}function V(e){var t=pe.uiOptions[e+"Date"],n=pe.uiOptions.times[e],a=!pe.uiOptions.multipleDays;return t?pe.request.getWorkDayForDate(v(t)).then(function(t){he[e]=t,q(e,t),a&&"from"===e&&q("to",t)}).catch(function(t){return he[e]={},S(t)}).finally(function(){n.loading=!1,a&&(pe.uiOptions.times.to.loading=!1)}):s.resolve()}function W(){return c.get(pe.request.contact_id,pe.period.start_date,pe.period.end_date).then(function(e){pe.calendar=e})}function G(){var e=(pe.pagination.currentPage-1)*pe.pagination.numPerPage,t=e+pe.pagination.numPerPage;pe.pagination.filteredbreakdown=pe.balance.change.breakdown.slice(e,t)}function Y(){return ie(),pe.canCalculateChange()?(pe.loading.balanceChange=!0,pe.request.change_balance=!0,pe.calculateBalanceChange().then(Q).catch(S).finally(function(){pe.loading.balanceChange=!1})):s.resolve()}function z(){pe.pagination.totalItems=pe.balance.change.breakdown.length,pe.pagination.filteredbreakdown=pe.balance.change.breakdown,pe.pagination.pageChanged()}function J(){return v(pe.request.from_date)===v(pe.request.to_date)}function K(){pe.uiOptions.toDate&&pe.uiOptions.fromDate&&pe.uiOptions.multipleDays&&t(pe.uiOptions.toDate).isSameOrBefore(pe.uiOptions.fromDate)&&(pe.uiOptions.toDate=null,X("to"))}function X(t){var n=pe.uiOptions.times[t];pe["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0",n.loading=!1,oe(),se(),ie()}function Q(e){pe.balance.change=e,pe.request.balance_change=e.amount,p(),z(),pe.loading.balanceChange=!1}function Z(){var e,n,a;pe.uiOptions.fromDate?(e=t(pe.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=h(pe.period.start_date),n=pe.uiOptions.date.to.options.minDate),pe.uiOptions.date.to.options.initDate=n,pe.uiOptions.date.to.options.minDate=a,pe.uiOptions.date.to.options.maxDate=h(pe.period.end_date)}function ee(){return!pe.isMode("create")&&J()||pe.isMode("create")&&(N("sickness")||B("hours"))?pe.uiOptions.multipleDays=!1:pe.uiOptions.multipleDays=!0,s.resolve().then(pe.setDaysSelectionModeExtended)}function te(t,n){var a="request"+e.startCase(t)+"DayTypes";pe[a]=n,pe.isMode("create")&&(pe.request[t+"_date_type"]=pe[a][0].value)}function ne(e,t){var n=pe.uiOptions,a=n.multipleDays?e:"from",r=n.times[a],o=n.multipleDays&&"to"===a?r.min:n.times.from.time,s=n.multipleDays&&"from"===a?r.max:n.times.to.time,i=he[a].number_of_hours?R(o,s).toString():"0";r.maxAmount=i,t&&(r.amount=r.maxAmount)}function ae(){fe&&fe.absenceTypeId===pe.selectedAbsenceType.id?pe.balance.opening=fe.value||0:pe.balance.opening=pe.selectedAbsenceType.remainder}function re(){pe.selectedAbsenceType=e.find(pe.absenceTypes,function(e){return e.id===pe.request.type_id})}function oe(){var e=pe.uiOptions,t=e.times;pe.request.from_date=e.fromDate?v(e.fromDate):null,pe.request.to_date=e.toDate?v(e.toDate):null,!e.multipleDays&&e.fromDate&&(pe.request.to_date=pe.request.from_date,pe.request.to_date_type=pe.request.from_date_type),B("hours")&&!N("toil")&&(pe.request.from_date=pe.request.from_date&&t.from.time?pe.request.from_date+" "+t.from.time:null,pe.request.to_date=pe.request.to_date&&t.to.time?pe.request.to_date+" "+t.to.time:null)}function se(){var e=pe.uiOptions.times;pe.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,pe.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function ie(){pe.uiOptions.showBalance=pe.canCalculateChange()}function ue(){e.forEach(me,function(e){e()})}function ce(){var e,t=pe.selectedAbsenceType.calculation_unit_name;return re(),e=t!==pe.selectedAbsenceType.calculation_unit_name,ae(),s.resolve().then(e&&ee).then(function(){if(e&&B("hours"))return V("from").then(function(){ne("from",!0)})}).then(e&&oe).then(Y)}function le(e){return pe.absenceTypes=e,re(),t(pe.uiOptions.toDate).isAfter(pe.period.end_date)&&(pe.uiOptions.toDate=void 0,X("to")),ae(),Y()}function de(e){var t=P(e).add(pe.uiOptions.time_interval,"minutes");t.isAfter(P(pe.uiOptions.times.to.max))||(pe.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(P(pe.uiOptions.times.to.time))&&(pe.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var fe=null,me=[],pe=this,he={};pe.canManage=!1,pe.calendar={},pe.errors=[],pe.isRequired=!0,pe.requestDayTypes=[],pe.statusNames=u.statusNames,pe.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},pe.pagination={currentPage:1,filteredbreakdown:pe.balance.change.breakdown,numPerPage:7,totalItems:pe.balance.change.breakdown.length,pageChanged:G},pe.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},pe.convertDateFormatFromServer=h,pe.convertDateToServerFormat=v,pe.dateChangeHandler=g,pe.dateTypeChangeHandler=b,pe.daysSelectionModeChangeHandler=y,pe.isLeaveType=N,pe.isNotWorkingDay=F,pe.performBalanceChangeCalculation=Y,pe.$onDestroy=ue,function(){n("RequestModalDetails"+e.capitalize(A(pe.leaveType,pe.request))+"Controller",{detailsController:pe}),pe.canManage=pe.isRole("manager")||pe.isRole("admin"),pe.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",pe),O(),pe.initChildController().then(function(){return s.all([W(),H()])}).then(!pe.isMode("create")&&I).then(ee).then(function(){if(!pe.isMode("create")&&B("hours"))return M().then(oe)}).then(!pe.isMode("create")&&Z).then(L).then(ae).then(T).then(function(){pe.isMode("view")||N("toil")||E()}).catch(S).finally(function(){pe.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","PublicHoliday","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return T.fileUploader&&T.fileUploader.queue.length>0}function f(){return T.getFilesAmount()When All filter is selected, all staff members with contracts which are active in the selected absence period are displayed.
","People I approve filter displays only staff members who you approve leave for.
","People without approver filter displays all staff members with contracts which are active in the selected absence period and who do not have any leave approver assigned.
"].join(""))}n.debug("LeaveCalendarAdminController");var h,v;return{init:function(e){return v=e,v.showContactDetailsLink=!0,v.showContactName=!0,v.showFilters=!0,v.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],v.filters.userSettings.assignedTo=v.filtersByAssignee[0],v.showAdminFilteringHint=p,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t,n){function a(){return{loadContacts:function(){return n.init({id:s.contactId}).leaveManagees().then(function(e){s.lookupContacts=e}).then(r)}}}function r(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){return{department:s.filters.userSettings.department?s.filters.userSettings.department.value:null,level_type:s.filters.userSettings.level_type?s.filters.userSettings.level_type.value:null,location:s.filters.userSettings.location?s.filters.userSettings.location.value:null,region:s.filters.userSettings.region?s.filters.userSettings.region.value:null,id:{IN:s.filters.userSettings.contact?[s.filters.userSettings.contact.id]:s.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,a()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance",a])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all({id:{in:[a.contactId]}}).then(function(e){return e.list})}}}e.debug("LeaveCalendarStaffController");var a;return{init:function(e){return a=e,a.filters.userSettings.contacts_with_leaves=!1,n()}}}n.controller("LeaveCalendarStaffController",["$log","Contact",a])}),define("leave-absences/shared/components/leave-calendar.component",["common/angular","common/lodash","common/moment","leave-absences/shared/modules/components","leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-manager.controller","leave-absences/shared/controllers/sub-controllers/leave-calendar-staff.controller"],function(e,t,n,a){function r(a,r,o,s,i,u,c,l,d,m){function f(){for(var e=[],t=n(E.selectedPeriod.start_date).clone().startOf("month"),a=n(E.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(P(t)),t.add(1,"month");E.months=e}function p(){s.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||T()})}function h(e){E.injectMonths=!0,O("injected").then(function(){T(e)}).then(function(){E.loading.calendar=!1})}function v(){I=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(E)}function g(e){return e.current?"Current Period ("+e.title+")":e.title}function b(){return u.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(f).then(S)}function y(){return c.all().then(c.loadCalculationUnits)}function _(){return d.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function q(){return I.loadContacts().then(function(e){E.contacts=e})}function $(){return d.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){E.filters.optionValues.regions=e.hrjc_region,E.filters.optionValues.locations=e.hrjc_location,E.filters.optionValues.levelTypes=e.hrjc_level_type,E.filters.optionValues.departments=e.hrjc_department})}function w(){return l.all()}function C(){return r.all([y(),w(),_()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.calculationUnits=e[2].hrleaveandabsences_absence_type_calculation_unit,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type,E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.toilAmounts=t.indexBy(e[2].hrleaveandabsences_toil_amounts,"value")})}function A(){var e=r.resolve();return E.injectMonths&&(e=O("destroyed"),E.injectMonths=!1),e}function P(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),shortName:e.format("MMM")}}function D(e){ +e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then(A).then("period"===e?f:t.noop).then("contacts"===e?q:t.noop).then(function(){h("contacts"===e)})}function T(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;s.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){E.selectedMonths=[n().month()]}function R(){return E.roleOverride?r.resolve().then(function(){x=E.roleOverride}):r.all([m(i.permissions.admin.administer),m(i.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function O(e){return r(function(n){var a=0,r=s.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}o.debug("Component: leave-calendar");var I,x,E=this;E.absencePeriods=[],E.contacts=[],E.contactIdsToReduceTo=null,E.injectMonths=!1,E.months=[],E.selectedMonths=null,E.selectedPeriod=null,E.showContactName=!1,E.showFilters=!1,E.supportData={},E.loading={calendar:!0,page:!0},E.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null}},E.labelPeriod=g,E.refresh=D,function(){R().then(p).then(v).then(A).then(b).then(function(){return r.all([q(),C()])}).then(function(){return E.showFilters?$():t.noop}).then(function(){h()}).then(function(){E.loading.page=!1})}()}a.component("leaveCalendar",{bindings:{contactId:"<",roleOverride:"@?"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","shared-settings","AbsencePeriod","AbsenceType","PublicHoliday","OptionGroup","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n,a,r,o){"use strict";function s(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function i(e){return e.isAM?"AM":e.isPM?"PM":""}function u(e){var n=t(e.from_date).isSame(g.date,"day"),a=t(e.to_date).isSame(g.date,"day");return n?t(e.from_date).format("HH:mm"):a?t(e.to_date).format("HH:mm"):""}function c(t,n){g.contactData.leaveRequestsAttributes[t.id].absenceTypeTitle=e.find(g.supportData.absenceTypes,{id:t.type_id}).title}function l(t,n){var a=e.find(g.supportData.absenceTypes,{id:t.type_id}),r=e.find(g.supportData.calculationUnits,{value:a.calculation_unit});n.unit=r.name}function d(e,t){t.from_date=new Date(e.from_date),t.to_date=new Date(e.to_date)}function m(t,n){"days"===n.unit&&(n.from_date_type=e.find(g.supportData.dayTypes,{value:t.from_date_type}).label,n.to_date_type=e.find(g.supportData.dayTypes,{value:t.to_date_type}).label)}function f(e,t){var n="";n=t.isAccruedTOIL?"AT":"days"===t.unit?i(t):u(e),t.label=n}function p(e){var t=g.contactData.leaveRequestsAttributes[e.id];[l,m,f,d,c].forEach(function(n){n.call(this,e,t)})}function h(e,t){r(function(){g.tooltip[e+"_hovered"]=t,g.tooltip.show=g.tooltip.day_cell_hovered||g.tooltip.tooltip_hovered},t?0:100)}function v(){a.$watch("day.contactData.leaveRequests",function(){g.contactData&&g.contactData.leaveRequests&&g.contactData.leaveRequests.forEach(p)},!0)}n.debug("Component: leave-calendar-day");var g=this;g.tooltip={show:!1,day_cell_hovered:!1,tooltip_hovered:!1},g.openLeavePopup=s,g.toggleTooltip=h,function(){v()}()}n.component("leaveCalendarDay",{bindings:{contactData:"<",date:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:a}),a.$inject=["$log","$scope","$timeout","LeavePopup"]}),define("leave-absences/shared/components/leave-calendar-legend.component",["leave-absences/shared/modules/components"],function(e){function t(e){function t(e){return{backgroundColor:e.color,borderColor:e.color}}e.debug("Component: leave-calendar-legend");var n=this;n.legendCollapsed=!0,n.getAbsenceTypeStyle=t}e.component("leaveCalendarLegend",{bindings:{absenceTypes:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-legend.html"}],controllerAs:"legend",controller:["$log",t]})}),define("leave-absences/shared/components/leave-calendar-month.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(e){q([e]),U(e)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:d(e)}}function d(n){var a=t(),r=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:r.format("YYYY-MM-DD"),name:r.format("ddd"),index:r.format("D"),current:a.isSame(r,"day"),enabled:r.isSameOrAfter(Y.period.start_date)&&r.isSameOrBefore(Y.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function m(e){return V[e]}function f(){return Y.showOnlyWithLeaveRequests?Y.contacts.filter(function(e){return Object.keys(G[e.id]||{}).length}):Y.contacts}function p(e){return t(e,u.serverDateFormat)}function h(e){var t=g(e);t&&(E(t),U(t))}function v(t){var n={request_type:"toil"};return e.some(t,n)&&!e.every(t,n)?e.filter(t,n):t}function g(t){var n;return e.find(G[t.contact_id],function(a){return n=e.find(a,function(e){return+e.id==+t.id})}),n}function b(e){return CRM.url("civicrm/contact/view",{cid:e})}function y(e,n){var a={};return n.forEach(function(n){a[n.id]={styles:N(n),isAccruedTOIL:C(n,"toil"),isRequested:P(n),isAM:w("half_day_am",n,e.date),isPM:w("half_day_pm",n,e.date),isSingleDay:t(n.from_date).isSame(n.to_date,"day")}}),a}function _(){Y.supportData.dayTypes=e.indexBy(Y.supportData.dayTypes,"name"),Y.supportData.leaveRequestStatuses=e.indexBy(Y.supportData.leaveRequestStatuses,"value"),Y.supportData.publicHolidays=e.transform(Y.supportData.publicHolidays,function(e,t){e[p(t.date).valueOf()]=t},{})}function q(e){return e.forEach(function(e){var t=D(e);G[e.contact_id]=G[e.contact_id]||{},t.forEach(function(t){G[e.contact_id][t.date]||(G[e.contact_id][t.date]=[]),G[e.contact_id][t.date].push(e)})}),a.resolve()}function $(){W.push(r.$on("LeaveCalendar::showMonths",j)),W.push(i.subscribe("LeaveRequest::new",c)),W.push(i.subscribe("LeaveRequest::edit",F)),W.push(i.subscribe("LeaveRequest::updatedByManager",F)),W.push(i.subscribe("LeaveRequest::delete",h)),W.push(i.subscribe("LeaveRequest::statusUpdate",function(e){"delete"===e.status?h(e.leaveRequest):F(e.leaveRequest)}))}function w(e,n,a){var r=Y.supportData.dayTypes[e];return t(a).isSame(n.from_date,"day")?r.value===n.from_date_type:t(a).isSame(n.to_date,"day")?r.value===n.to_date_type:void 0}function C(e,t){return e.request_type===t}function A(e){return!!Y.supportData.publicHolidays[p(e).valueOf()]}function P(t){var n=Y.supportData.leaveRequestStatuses[t.status_id].name;return e.contains([u.statusNames.awaitingApproval,u.statusNames.moreInformationRequired],n)}function D(n){for(var a=[],r=t(n.from_date).clone(),o=t(n.to_date);r.isSameOrBefore(o);)r.month()===Y.month.index&&r.year()===Y.month.year&&a.push(e.find(Y.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function T(t){var n=e.find(Y.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function S(){return[T(u.statusNames.approved),T(u.statusNames.adminApproved),T(u.statusNames.awaitingApproval),T(u.statusNames.moreInformationRequired)]}function R(){return Y.month.loading=!0,a.all([I(),O()]).then(x).then(k).then(function(){H=!0,Y.month.loading=!1})}function O(){return s.all({from_date:{to:Y.month.days[Y.month.days.length-1].date},to_date:{from:Y.month.days[0].date},status_id:{IN:S()},contact_id:{IN:Y.contacts.map(function(e){return e.id})},type_id:{IN:e.pluck(Y.supportData.absenceTypes,"id")}},null,null,null,!1).then(function(e){return q(e.list)})}function I(){var t=Y.month.days[0].date,n=Y.month.days[Y.month.days.length-1].date;return o.get(Y.contacts.map(function(e){return e.id}),t,n).then(function(t){V=e.indexBy(t,"contact_id")})}function x(){return Y.contactIdsToReduceTo&&(Y.contacts=Y.contacts.filter(function(t){return e.includes(Y.contactIdsToReduceTo,t.contact_id)||e.find(G,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function E(t){var n=D(t);G[t.contact_id]=G[t.contact_id]||{},n.forEach(function(n){e.remove(G[t.contact_id][n.date],function(e){return e.id===t.id})})}function L(){r.$emit("LeaveCalendar::monthDestroyed"),W.map(function(e){e.remove?e.remove():e()})}function M(t,n,r){var o,s;return t.contactsData[n]=t.contactsData[n]||{},s=m(n),o=!0===r?a.resolve():a.all([s.isWeekend(p(t.date)),s.isNonWorkingDay(p(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:A(t.date)})}),o.then(function(){return G[n]&&G[n][t.date]?G[n][t.date]:[]}).then(function(a){a=B(a),e.assign(t.contactsData[n],{leaveRequests:a,leaveRequestsToShowInCell:v(a),leaveRequestsAttributes:y(t,a)})})}function k(){return a.all(Y.month.days.map(function(e){return a.all(Y.contacts.map(function(t){return M(e,t.id)}))}))}function j(t,n,a){!e.find(n,function(e){return e.index===Y.month.index})?Y.visible=!1:(Y.currentPage=0,Y.visible=!0,(a||!H)&&R())}function B(n){return e.sortBy(n,function(e){return+t(e.from_date).format("X")+(w("half_day_pm",e,e.from_date)?1:0)})}function N(t){var n=e.find(Y.supportData.absenceTypes,function(e){return e.id===t.type_id});return t.balance_change>0?{borderColor:n.color}:{borderColor:n.color,backgroundColor:n.color}}function F(e){h(e),-1!==S().indexOf(e.status_id)&&c(e)}function U(e){return a.all(D(e).map(function(t){return M(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var H=!1,W=[],V={},G={},Y=this;Y.currentPage=0,Y.pageSize=20,Y.visible=!1,Y.showContactName=!!Y.showContactName,Y.showOnlyWithLeaveRequests=!!Y.showOnlyWithLeaveRequests,Y.$onDestroy=L,Y.contactsList=f,Y.getContactUrl=b,function(){var e=t().month(Y.month.index).year(Y.month.year);_(),$(),Y.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",contactIdsToReduceTo:"<",month:"<",period:"<",showContactName:"<",showContactDetailsLink:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","pubSub","shared-settings",a]})}),define("leave-absences/shared/modules/services",["common/angular","common/modules/services"],function(e){"use strict";return e.module("leave-absences.services",["common.services"])}),define("leave-absences/shared/services/leave-request.service",["common/lodash","leave-absences/shared/modules/services"],function(e,t){"use strict";function n(t,n,a){function r(){var t=n.defer();return a.open(e.defaults(o(),{onConfirm:function(){t.resolve(!0)}})),t.promise}function o(){return{title:"Recalculate Balance Change?",copyCancel:"Cancel",copyConfirm:"Yes",classConfirm:"btn-warning",msg:"The leave balance change has updated since this leave request was created. Do you want to recalculate the balance change?"}}return t.debug("LeaveRequest"),{getBalanceChangeRecalculationPromptOptions:o,promptBalanceChangeRecalculation:r}}t.factory("LeaveRequestService",n),n.$inject=["$log","$q","dialog"]}),define("leave-absences/shared/components/leave-request-actions.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/services/notification.service","common/services/pub-sub","leave-absences/shared/services/leave-request.service"],function(e,t,n){function a(n,a,r,o,s,i,u,c){function l(t){_=q.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===q.leaveRequest.request_type?r.open(h(t)):f(t)}function d(){return"admin"===q.role&&"public_holiday"===q.leaveRequest.request_type}function m(n){var a=q.absenceTypes[q.leaveRequest.type_id].allow_request_cancelation;return"admin"===q.role||("manager"===q.role?e.includes([$.awaitingApproval,$.moreInformationRequired],n):"3"===a?t().isBefore(q.leaveRequest.from_date):"2"===a)}function f(t){r.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return q.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(s.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){o.openModal(q.leaveRequest,q.leaveRequest.request_type,q.leaveRequest.contact_id,"my-leave"===a.section,!0)}}):h(t)})}})}function p(){e.isArray(q.leaveRequestStatuses)&&(q.leaveRequestStatuses=e.indexBy(q.leaveRequestStatuses,"value")),e.isArray(q.absenceTypes)&&(q.absenceTypes=e.indexBy(q.absenceTypes,"id"))}function h(e){var t=w[e].dialog;return{title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return q.leaveRequest[e]().then(function(){g(e)}).catch(function(e){c.error("Error:",e)})}}}function v(e,t,n,a,r){e.stopPropagation(),o.openModal(t,n,a,r)}function g(t){var n=e.find(q.leaveRequestStatuses,function(e){return e.name===u.statusNames.awaitingApproval}).value;_===n&&i.publish("ManagerBadge:: Update Count"),i.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:q.leaveRequest})}function b(){var t=q.leaveRequestStatuses[q.leaveRequest.status_id].name,n=e.compact(e.map(w,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!m(t)&&e.pull(n,"cancel"),"admin"!==q.role&&e.pull(n,"delete"),"staff"===q.role&&e.pull(n,"approve","reject"),"staff"!==q.role&&y(n),d()&&n.push("delete"),q.allowedActions=e.map(n,function(e){return{key:e,label:w[e].label,isDirectAction:w[e].isDirectAction}})}function y(t){e.each(t,function(n,a){"edit"===n&&(t[a]="respond"),e.includes(["respond","view"],n)&&(t[a]="edit")})}n.debug("Component: leave-request-action-dropdown");var _,q=this,$=u.statusNames,w={edit:{label:"Edit",allowedStatuses:[$.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[$.moreInformationRequired]},view:{label:"View",allowedStatuses:[$.approved,$.rejected,$.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[$.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.approved,$.rejected,$.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[$.awaitingApproval,$.moreInformationRequired,$.approved,$.rejected,$.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};q.allowedActions=[],q.action=l,q.openLeavePopup=v,function(){p(),b()}()}n.component("leaveRequestActions",{bindings:{leaveRequest:"<",leaveRequestStatuses:"<",absenceTypes:"<",role:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-actions.html"}],controllerAs:"actions",controller:a}),a.$inject=["$log","$rootScope","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService"]}),define("leave-absences/shared/components/leave-request-popup-comments-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/hr-settings","common/models/session.model"],function(e,t,n){function a(n,a,r,o,s,i,u){function c(){q.request.comments.push({contact_id:_,leave_request_id:q.request.id,text:q.comment.text}),q.comment.text=""}function l(){return q.comment.text.length>0}function d(e){return!e.comment_id||q.canManage}function m(e){return t.utc(e,s.serverDateTimeFormat).local().format(o.DATE_FORMAT.toUpperCase()+" HH:mm")}function f(){return q.request.comments.filter(function(e){return!e.toBeDeleted})}function p(e){return e===_?"Me":q.comment.contacts[e]?q.comment.contacts[e].display_name:void 0}function h(e){return q.mode===e}function v(){q.comment.text.length&&q.addComment()}function g(){var t=e.indexBy(q.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){q.comment.contacts=e.indexBy(t.list,"contact_id")})}function b(){return q.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),q.request.comments.length&&g()})}function y(){return q.loading.component=!0,u.get().then(function(e){_=e.contactId}).then(function(){q.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var _=null,q=this;q.loading={component:!0},q.comment={text:"",contacts:{}},q.addComment=c,q.canRemoveComment=d,q.canSubmit=l,q.formatDateTime=m,q.getActiveComments=f,q.getCommentorName=p,q.isMode=h,q.onBeforeSubmit=v,function(){r.$emit("LeaveRequestPopup::addTab",q),b(),y()}()}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","$scope","HR_settings","shared-settings","Contact","Session",a]})}),define("leave-absences/shared/components/leave-request-popup-details-tab.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/models/session.model","leave-absences/shared/models/calendar.model"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l,d,m){function f(){te.balance.closing=te.balance.opening+te.balance.change.amount}function p(e){return t(e,u.serverDateFormat).toDate()}function h(e){return t(e).format(u.serverDateFormat)}function v(e){var t;return s.resolve().then(function(){F(e),"from"===e&&N(),O("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return q(e)}).then(function(e){if(t=e.id!==te.period.id,t&&(te.period=e),!te.period.id)return s.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(t)return L()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(Y(),!t)return k();r.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(A).finally(_)}function g(){return Y(),k()}function b(){return te.uiOptions.toDate=null,F("to"),s.resolve().then(Y).then(te.setDaysSelectionModeExtended).then(_).then(!te.uiOptions.multipleDays&&k)}function y(e){te.uiOptions.times[e].loading=!0}function _(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,O("hours")&&(te.uiOptions.times[e].loading=!1)})}function q(n){var a=t(te.uiOptions[n+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function $(){return te.request?te.request.request_type:te.leaveType||null}function w(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function C(){return z(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(U).catch(A)}function A(t){r.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?k():C()}function D(){var e=te.request.attributes();return te.uiOptions.fromDate=p(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=p(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():s.resolve()}function T(){ee.push(r.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),r.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){K(t)}),r.$on("LeaveRequestPopup::recalculateBalanceChange",k))}function S(){te.isMode("edit")&&(te.isLeaveStatus(u.statusNames.approved)||te.isLeaveStatus(u.statusNames.adminApproved))&&(Z={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function R(){r.$watch(function(){return te.uiOptions.times.from.time},function(e,t){e!==t&&(te.uiOptions.multipleDays||(Q(e),Y()))})}function O(e){return te.selectedAbsenceType.calculation_unit_name===e}function I(e){return te.request.request_type===e}function x(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function E(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function L(){return c.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function M(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,t=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,t)}function k(){return z(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(U).catch(A).finally(function(){te.loading.balanceChange=!1})):s.resolve()}function j(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function B(){return h(te.request.from_date)===h(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&t(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,F("to"))}function F(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),Y(),z()}function U(e){te.balance.change=e,te.request.balance_change=e.amount,f(),j(),te.loading.balanceChange=!1}function H(){var e,n,a;te.uiOptions.fromDate?(e=t(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=p(te.period.start_date),n=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=n,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=p(te.period.end_date)}function W(){return!te.isMode("create")&&B()||te.isMode("create")&&(I("sickness")||O("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,s.resolve().then(te.setDaysSelectionModeExtended)}function V(){Z&&Z.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=Z.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function G(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function Y(){var e=te.uiOptions,t=e.times;te.request.from_date=e.fromDate?h(e.fromDate):null,te.request.to_date=e.toDate?h(e.toDate):null,!e.multipleDays&&e.fromDate&&(te.request.to_date=te.request.from_date,te.request.to_date_type=te.request.from_date_type),(O("hours")||I("toil"))&&(te.request.from_date=te.request.from_date&&t.from.time?te.request.from_date+" "+t.from.time:null,te.request.to_date=te.request.to_date&&t.to.time?te.request.to_date+" "+t.to.time:null)}function z(){te.uiOptions.showBalance=te.canCalculateChange()}function X(){e.forEach(ee,function(e){e()})}function J(){var e,t=te.selectedAbsenceType.calculation_unit_name;return G(),e=t!==te.selectedAbsenceType.calculation_unit_name,V(),s.resolve().then(e&&W).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&Y).then(_).then(k)}function K(e){return te.absenceTypes=e,G(),t(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,F("to")),V(),k()}function Q(e){var t=w(e).add(te.uiOptions.time_interval,"minutes");t.isAfter(w(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(w(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var Z=null,ee=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=u.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:te.balance.change.breakdown,numPerPage:7,totalItems:te.balance.change.breakdown.length,pageChanged:M},te.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:i.DATE_FORMAT,showBalance:!1,date:{from:{show:!1,options:{startingDay:1,showWeeks:!1}},to:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}},expiry:{show:!1,options:{minDate:null,maxDate:null,startingDay:1,showWeeks:!1}}},times:{from:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""},to:{amount:0,amountExpanded:!1,loading:!1,max:"00:00",maxAmount:0,min:"00:00",time:""}},time_interval:15},te.convertDateFormatFromServer=p,te.convertDateToServerFormat=h,te.dateChangeHandler=v,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=b,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=w,te.handleError=A,te.isCalculationUnit=O,te.isLeaveType=I,te.isNotWorkingDay=x,te.performBalanceChangeCalculation=k,te.setRequestDateTimesAndDateTypes=Y,te.updateEndTimeInputMinTime=Q,te.$onDestroy=X,function(){n("RequestModalDetails"+e.capitalize($(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,o.$emit("LeaveRequestPopup::addTab",te),T(),te.initChildController().then(function(){return s.all([L(),E()])}).then(!te.isMode("create")&&D).then(W).then(function(){if(!te.isMode("create"))return s.resolve().then(te.initTimesExtended).then(Y)}).then(!te.isMode("create")&&H).then(S).then(V).then(P).then(R).then(!te.isMode("view")&&te.initWatchersExtended).catch(A).finally(function(){te.loading.tab=!1})}()}n.component("leaveRequestPopupDetailsTab",{bindings:{absencePeriods:"<",absenceTypes:"<",balance:"=",request:"<",isLeaveStatus:"<",leaveType:"<",isMode:"<",isSelfRecord:"<",period:"=",isRole:"<",selectedAbsenceType:"=",forceRecalculateBalanceChange:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-details-tab.html"}],controllerAs:"detailsTab",controller:a}),a.$inject=["$controller","$log","$rootScope","$scope","$q","HR_settings","shared-settings","Calendar","OptionGroup","LeaveRequest","$timeout"]}),define("leave-absences/shared/components/leave-request-popup-files-tab",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/file-upload","common/services/file-mime-types","common/services/hr-settings"],function(e,t,n){function a(n,a,r,o,s,i,u,c,l){function d(){return R.fileUploader&&R.fileUploader.queue.length>0}function m(){return R.getFilesAmount()+ |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
+ | {{contact.display_name}} {{contact.display_name}} | @@ -50,7 +50,7 @@||||||||
+ |
@@ -19,7 +19,7 @@
ng-change="detailsTab.dateChangeHandler('from')"/>
+
@@ -71,7 +71,7 @@
ng-change="detailsTab.dateChangeHandler('to')"/>
+
-
-
-
+
- {{detailsTab.uiOptions.times.to.amount | timeUnitApplier : detailsTab.selectedAbsenceType.calculation_unit_name}}
- for {{detailsTab.uiOptions.toDate | formatDate}} or
-
- set custom deduction
-
+
+
+
+
+
+ {{detailsTab.uiOptions.times.to.amount | timeUnitApplier : detailsTab.selectedAbsenceType.calculation_unit_name}}
+ for {{detailsTab.uiOptions.toDate | formatDate}} or
+
+ set custom deduction
-
-
+
- Customise deduction for
- {{detailsTab.uiOptions.toDate | formatDate}}
-
- - (eg. subtract break time) -
-
-
-
-
+
+
-
-
+ Customise deduction for
+ {{detailsTab.uiOptions.toDate | formatDate}}
+
+ + (eg. subtract break time) +
+
+
+
+
+
+
-
-
+
+
+
+
+
+
-
+
+
+
+
+
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html
index 47936040869..e93c7512364 100644
--- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html
+++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-popup/details-tab/toil.html
@@ -1,51 +1,34 @@
-
-
-
-
-
-
+
+
+
+
+ {{detailsTab.uiOptions.toil_duration_in_hours | timeUnitApplier : 'hours'}}
+ of overtime worked
+
+ Customise this amount
+
+
+
+
-
-
-
@@ -56,29 +39,37 @@
+
+
+
+
+
-
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-record-actions.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-record-actions.html
index d17bf608bd7..81d404e95cb 100644
--- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-record-actions.html
+++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/leave-request-record-actions.html
@@ -1,14 +1,30 @@
-
-
-
+
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/manage-leave-requests.html b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/manage-leave-requests.html
index 58785da6898..e697cd1ed5f 100644
--- a/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/manage-leave-requests.html
+++ b/uk.co.compucorp.civicrm.hrleaveandabsences/views/shared/components/manage-leave-requests.html
@@ -184,17 +184,8 @@
+
+
+
+
+
Manager Absence Approval 0 ? "+" : ""}}{{request.balance_change | timeUnitApplier : absenceType.calculation_unit_name}} |
- - {{request.from_date | formatDate : null : request.request_type !== 'toil' ? unit : null}} - - - - {{request.to_date | formatDate : null : request.request_type !== 'toil' ? unit : null}} - - - - - {{request.to_date.slice(11, 16)}} - - | +{{vm.getLeaveStatusByValue(request.status_id)}} |
|
- - {{request.from_date | formatDate : null : request.request_type !== 'toil' ? unit : null}} - - - - {{request.to_date | formatDate : null : request.request_type !== 'toil' ? unit : null}} - - - - - {{request.to_date.slice(11, 16)}} - - | +{{report.leaveRequestStatuses[request.status_id].label}} |
diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml
new file mode 100644
index 00000000000..611be1a0d4b
--- /dev/null
+++ b/uk.co.compucorp.civicrm.hrleaveandabsences/xml/option_groups/work_pattern_change_reason_install.xml
@@ -0,0 +1,52 @@
+
+
+ |