From ab37348c198d5aef505d89a6046c291c89c854bc Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Thu, 2 Aug 2018 10:51:50 +0100 Subject: [PATCH 1/2] PCHR-4094: Add admin to managees list --- .../js/dist/absence-tab.min.js | 2 +- .../js/dist/admin-dashboard.min.js | 4 ++-- .../js/dist/manager-leave.min.js | 8 ++++---- .../js/dist/my-leave.min.js | 2 +- .../shared/controllers/request.controller.js | 5 +---- .../js/test/shared/controllers/request.controller.spec.js | 6 +++--- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/absence-tab.min.js index e696b5eda7a..39da60dd7b6 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/absence-tab.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){e.config({paths:{mocks:"../test/mocks"}}),e.config({paths:{mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(n){return n.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",sourcePath:e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,n,t){"use strict";t.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(t,a,o){return t.debug("AbsenceTypeAPI"),a.extend({all:function(n){return t.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(n||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return t.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:n(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,n){return e.debug("AbsenceTypeInstance"),n.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,n){"use strict";n.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(n,t,a,o,s,i){return n.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,n,t){return s.calculateToilExpiryDate(e,n,t)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(n){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(t){return t=e.indexBy(t,"value"),e.map(n,function(n){return e.assign(n,{calculation_unit_label:t[n.calculation_unit].label,calculation_unit_name:t[n.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,n){"use strict";n.factory("WorkPatternAPI",["$log","api",function(n,t){function a(n){var t=e.clone(n);return t.workPattern=t["api.WorkPattern.get"].values[0],delete t["api.WorkPattern.get"],t}return n.debug("WorkPatternAPI"),t.extend({assignWorkPattern:function(n,t,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:n,pattern_id:t,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(t,a,o,s){return n.debug("WorkPatternAPI.getCalendar",t,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(t)?{IN:t}:t,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(n,t,o){return this.sendGET("ContactWorkPattern","get",e.assign({},t,{contact_id:n,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).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,n,t){"use strict";t.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(t,a,o,s,i){function r(n,t){return u().then(function(a){var o=this.days[c(n).valueOf()];return!!o&&e.find(a,function(e){return e.name===t}).value===o.type}.bind(this))}function c(e){return n(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(n){var t={};return n.calendar.forEach(function(e){t[c(e.date).valueOf()]=e}),e(n).omit("calendar").assign({days:t}).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,n){"use strict";n.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(n,t,a,o){return n.debug("Calendar"),t.extend({get:function(t,s,i,r){return n.debug("Calendar.get"),a.getCalendar(t,s,i,r).then(function(n){var a=n.values.map(function(e){return o.init(e)});return e.isArray(t)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,t){function a(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(t.remainder=a[0].remainder),delete t["api.LeavePeriodEntitlement.getremainder"],t}function o(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return t.value=a,delete t["api.LeavePeriodEntitlement.getentitlement"],t}return e.debug("EntitlementAPI"),t.extend({all:function(n,t){return e.debug("EntitlementAPI.all"),n["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},t&&(n["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",n,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),t&&(e=e.map(a)),e})},breakdown:function(n){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",n).then(function(e){return e.values})},getLeaveBalances:function(n,t,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",n,t,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,n){return e.debug("EntitlementLogAPI"),n.extend({all:function(n){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",n,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,n,t){return e.debug("EntitlementInstance"),n.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return t.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,n){"use strict";n.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(n,t,a,o,s){return n.debug("Entitlement"),t.extend({all:function(e,n){return a.all(this.processFilters(e),n).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(n,t){return a.breakdown(n).then(function(n){return t?(t.map(function(t){var a=e.find(n,function(e){return e.id===t.id});return a&&(t.breakdown=a.breakdown),t}),t):n.map(function(e){return o.init(e,!0)})})},logs:function(n){return n=e.cloneDeep(n||{}),n.contact_id&&(n["entitlement_id.contact_id"]=n.contact_id,delete n.contact_id),n.period_id&&(n["entitlement_id.period_id"]=n.period_id,delete n.period_id),n.return=n.return||[],n.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(n)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,t,a){return e.debug("LeaveRequestAPI"),t.extend({all:function(n,t,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return n&&n.contact_id&&n.contact_id.IN&&0===n.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",n,t,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return t.contact_id&&t.period_id||o.reject("contact_id and period_id are mandatory"),t=n.defaults(t,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",t,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange",t),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){return e.values.breakdown=n.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,n){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:n.toString()},!1)},create:function(n){return e.debug("LeaveRequestAPI.create",n),this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,attachment_id:t}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,t){return t=n.assign({},t,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",t).then(function(e){return e.values})},find:function(n){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:n},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",t,!1).then(function(e){return e.values})},getComments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",t,!1).then(function(e){return e.values})},isManagedBy:function(n,t){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:n,contact_id:t}).then(function(e){return e.values})},isValid:function(t){e.debug("LeaveRequestAPI.isValid",t);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",t).then(function(e){e.count>0?o.reject(n(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,text:t.text,contact_id:t.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(n){return e.debug("LeaveRequestAPI.update",n),n.id?this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,n,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(t,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var n=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=n,t.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return t.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function f(e){return n.duration(e.time_to).subtract(n.duration(e.time_from)).asHours()}function p(n){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return e.find(t,function(e){return e.name===n})})}function h(n){var a=e.cloneDeep(n),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return t.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(n){return s.amount=n[0].time_from?Math.min(this.from_date_amount,f(n[0])):0,o&&(i.amount=n[1].time_from?Math.min(this.to_date_amount,f(n[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,n){return e+n.amount},0),a}.bind(this))}function v(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(n){return function(){return r.saveComment(e,n)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),t.all(n)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(n){var t=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===n&&e.pull(t,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,t)).then(function(e){return"hours"===n?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return t.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(n){if(n.comment_id)return void(n.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return n.created_at===e.created_at&&n.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(n){return{amount:e.reduce(n.values,function(e,n){return e+parseFloat(n.amount)},0),breakdown:n.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return t.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):a(s.permissions.admin.administer).then(function(n){return n?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):t.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,n,t,a){return e.debug("LeaveRequest"),n.extend({all:function(e,n,o,s,i){return t.all(this.processFilters(e),n,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return t.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return t.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,n){return e.debug("WorkPatternInstance"),n.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,n){"use strict";n.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(n,t,a,o){return n.debug("WorkPattern"),t.extend({assignWorkPattern:function(e,n,t,o,s,i){return a.assignWorkPattern(e,n,t,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(n){return o.init(e.first(n),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,n,t){return a.workPatternsOf(e,n,t).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,n,t){function a(n,t,a,o,s,i,r){function c(){return{loadContacts:function(){return l.loadContactsForAdmin()}}}function u(e){i.info("",["

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 l,d;return{init:function(n){return d=n,l=r.init(d),d.filters.userSettings.assignedTo=e.find(d.filtersByAssignee,{type:"me"}),d.showContactDetailsLink=!0,d.showContactName=!0,d.showFilters=!0,d.showAdminFilteringHint=u,c()}}}t.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService","LeaveCalendarService",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(n,t,a,o){function s(){return{loadContacts:function(){return i.loadLookUpAndFilteredContacts()}}}n.debug("LeaveCalendarManagerController");var i,r;return{init:function(n){return r=n,i=o.init(r),r.filters.userSettings.assignedTo=e.find(r.filtersByAssignee,{type:"me"}),r.showContactName=!0,r.showFilters=!0,s()}}}t.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance","LeaveCalendarService",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,t,a){function o(){return{loadContacts:function(){return i.displaySingleContact?s.loadFilteredContacts():"admin"===i.userPermissionRole?s.loadContactsForAdmin():s.loadLookUpAndFilteredContacts()}}}e.debug("LeaveCalendarStaffController");var s,i;return{init:function(e){return i=e,s=a.init(i),i.filters.userSettings.contacts_with_leaves=!0,i.showTheseContacts=[i.contactId],i.showContactName=!0,i.showFilters=!0,i.displaySingleContact&&(i.showFilters=!1,i.lookupContacts=[{id:i.contactId}]),o()}}}t.controller("LeaveCalendarStaffController",["$log","$q","Contact","LeaveCalendarService",a])}),define("leave-absences/shared/components/leave-calendar.component",["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){function a(t,a,o,s,i,r,c,u,l,d){function m(){U().then(g).then(b).then(y).then(w).then(function(){return a.all([C(),D(),I(),H.showFilters?P():e.noop])}).then(function(){f(),_(),B()}).then(function(){H.loading.page=!1})}function f(){H.supportData.absenceTypes.push({id:"",title:"Leave",color:"#4D4D68",calculation_unit:e.chain(H.supportData.calculationUnits).find({name:"days"}).get("value").value()})}function p(){for(var e=[],t=n(H.selectedPeriod.start_date).clone().startOf("month"),a=n(H.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(S(t)),t.add(1,"month");H.months=e}function h(){return e.includes(["admin","manager"],H.userPermissionRole)}function v(e){return e.format("YYYY-MM")}function b(){s.$on("LeaveCalendar::updateFiltersByAbsenceType",function(e,n){H.supportData.absenceTypesToFilterBy=n,M(!0)})}function g(){s.$new().$watch(function(){return H.selectedMonthIndex},function(e,n){null!==n&&e!==n&&(F(),B(),M())})}function _(e){H.injectMonth=!0,N("injected").then(function(){M(e)}).then(function(){H.loading.calendar=!1})}function y(){j=t("LeaveCalendar"+e.capitalize(W)+"Controller").init(H)}function q(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return r.all().then(function(n){H.absencePeriods=e.sortBy(n,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!!e.current})}).then(p).then($)}function T(){return c.all().then(c.loadCalculationUnits)}function A(){return l.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function D(){return j.loadContacts().then(function(e){H.contacts=e})}function P(){return l.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){H.filters.optionValues.regions=e.hrjc_region,H.filters.optionValues.locations=e.hrjc_location,H.filters.optionValues.levelTypes=e.hrjc_level_type,H.filters.optionValues.departments=e.hrjc_department})}function R(){return u.all()}function I(){return a.all([T(),R(),A()]).then(function(n){H.supportData.absenceTypes=n[0],H.supportData.publicHolidays=n[1],H.supportData.calculationUnits=n[2].hrleaveandabsences_absence_type_calculation_unit,H.supportData.dayTypes=n[2].hrleaveandabsences_leave_request_day_type,H.supportData.leaveRequestStatuses=n[2].hrleaveandabsences_leave_request_status,H.supportData.toilAmounts=e.indexBy(n[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=a.resolve();return H.injectMonth&&(e=N("destroyed"),H.injectMonth=!1),e}function S(e){return{index:v(e),month:e.month(),year:e.year(),name:e.format("MMMM"),moment:n().year(e.year()).month(e.month())}}function k(){var n=H.selectedPeriod.id;H.selectedPeriod=e.find(H.absencePeriods,function(e){return!!e.current}),n!==H.selectedPeriod.id&&p(),$(),B(),O("month")}function L(e){var t="previous"===e?"subtract":"add";F(n(H.selectedMonth.moment)[t](1,"month")),B(),O("month")}function O(n){n=e.includes(["contacts","period","month"],n)?n:"period",a.resolve().then(w).then("period"===n&&p).then("period"===n&&x).then("contacts"===n&&D).then("month"===n&&B).then(function(){_("contacts"===n)})}function M(e){s.$emit("LeaveCalendar::showMonth",!!e)}function $(){F(n())}function x(){F(H.months[0].moment)}function E(t){var a="previous"===t?"first":"last",o=e[a](H.months),s=n().year(o.year).month(o.month);H.monthPaginatorsAvailability[t]=!H.selectedMonth.moment.isSame(s,"month")}function B(){E("previous"),E("next")}function F(n){n&&(H.selectedMonthIndex=v(n)),H.selectedMonth=e.find(H.months,{index:H.selectedMonthIndex})}function U(){return a.all([d(i.permissions.admin.administer),d(i.permissions.ssp.manage)]).then(function(e){H.userPermissionRole=e[0]?"admin":e[1]?"manager":"staff",W=H.roleOverride?H.roleOverride:H.userPermissionRole})}function N(n){return a(function(t){var a=s.$on("LeaveCalendar::month"+e.capitalize(n),function(){a(),t()})})}o.debug("Component: leave-calendar");var j,W,H=this;H.absencePeriods=[],H.contacts=[],H.contactIdsToReduceTo=null,H.injectMonth=!1,H.months=[],H.selectedMonth={},H.selectedMonthIndex="",H.selectedPeriod=null,H.showContactName=!1,H.showFilters=!1,H.userPermissionRole="staff",H.loading={calendar:!0,page:!0},H.filters={hideOnMobile:!0,optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null},absenceTypes:{}},H.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],H.filters.userSettings.assignedTo=H.filtersByAssignee[2],H.monthPaginatorsAvailability={previous:!0,next:!0},H.supportData={absenceTypesToFilterBy:[]},H.$onInit=m,H.canManageRequests=h,H.labelPeriod=q,H.navigateToCurrentMonth=k,H.paginateMonth=L,H.refresh=O}t.component("leaveCalendar",{bindings:{contactId:"<",displaySingleContact:"0,t={from_date:{to:Q.month.days[Q.month.days.length-1].date+" 23:59:59"},to_date:{from:Q.month.days[0].date+" 00:00:00"},status_id:{IN:L()},contact_id:{IN:Q.contacts.map(function(e){return e.id})},type_id:{IN:n?Q.supportData.absenceTypesToFilterBy:e.pluck(Q.supportData.absenceTypes,"id")}};return _(),i.all(t,null,null,null,!1).then(function(e){return X={},n&&(e.list=q(e.list)),A(e.list)})}function $(){var n=Q.month.days[0].date,t=Q.month.days[Q.month.days.length-1].date;return s.get(Q.contacts.map(function(e){return e.id}),n,t).then(function(n){z=e.indexBy(n,"contact_id")})}function x(){return Q.contactIdsToReduceTo&&(Q.contacts=Q.contacts.filter(function(n){return e.includes(Q.contactIdsToReduceTo,n.contact_id)||e.find(X,function(e){return e.contact_id===n.contact_id})})),a.resolve()}function E(n){var t=S(n);X[n.contact_id]=X[n.contact_id]||{},t.forEach(function(t){e.remove(X[n.contact_id][t.date],function(e){return e.id===n.id})})}function B(){o.$emit("LeaveCalendar::monthDestroyed"),V.map(function(e){e.remove?e.remove():e()})}function F(n,t,o){var s,i;return n.contactsData[t]=n.contactsData[t]||{},i=f(t),s=!0===o?a.resolve():a.all([i.isWeekend(h(n.date)),i.isNonWorkingDay(h(n.date))]).then(function(a){e.assign(n.contactsData[t],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:I(n.date)})}),s.then(function(){return X[t]&&X[t][n.date]?X[t][n.date]:[]}).then(function(a){a=j(a),e.assign(n.contactsData[t],{leaveRequests:a,leaveRequestsToShowInCell:b(a),leaveRequestsAttributes:C(n,a)})})}function U(){return a.all(Q.month.days.map(function(e){return a.all(Q.contacts.map(function(n){return F(e,n.id)}))}))}function N(e,n){Q.currentPage=0,Q.visible=!0,(n||!G)&&O()}function j(t){return e.sortBy(t,function(e){return+n(e.from_date).format("X")+(P("half_day_pm",e,e.from_date)?1:0)})}function W(n){var t=e.find(Q.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 H(e){v(e),-1!==L().indexOf(e.status_id)&&l(e)}function Y(e){return a.all(S(e).map(function(n){return F(n,e.contact_id,!0)}))}t.debug("Component: leave-calendar-month");var G=!1,V=[],z={},X={},Q=this;Q.currentPage=0,Q.pageSize=20,Q.visible=!1,Q.showContactName=!!Q.showContactName,Q.showOnlyWithLeaveRequests=!!Q.showOnlyWithLeaveRequests,Q.$onDestroy=B,Q.$onInit=u,Q.contactsList=p,Q.getContactUrl=y}t.component("leaveCalendarMonth",{bindings:{showTheseContacts:"<",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/models/contact","common/models/session.model","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,l,d,m){function f(){a.resolve().then(y).then(C).then(function(){return _()&&"admin"!==k.role&&R()}).then(P).finally(function(){k.loading.component=!1})}function p(n){S=k.leaveRequest.status_id,e.includes(["cancel","reject","delete"],n)||"toil"===k.leaveRequest.request_type?i.open(q(n)):b(n)}function h(){return"admin"===k.role&&"public_holiday"===k.leaveRequest.request_type}function v(t){var a=k.absenceTypes[k.leaveRequest.type_id].allow_request_cancelation;return"admin"===k.role||("manager"===k.role?e.includes([L.awaitingApproval,L.moreInformationRequired],t):"3"===a?n().isBefore(k.leaveRequest.from_date):"2"===a)}function b(n){i.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return k.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(t){return t?e.assign(c.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){A(n)}}):q(n)})}})}function g(){return s.find(w).then(function(e){return e.checkIfSelfLeaveApprover()})}function _(){return w===k.leaveRequest.contact_id}function y(){e.isArray(k.leaveRequestStatuses)&&(k.leaveRequestStatuses=e.indexBy(k.leaveRequestStatuses,"value")),e.isArray(k.absenceTypes)&&(k.absenceTypes=e.indexBy(k.absenceTypes,"id"))}function q(e){var n=O[e].dialog;return{title:"Confirm "+n.title+"?",copyCancel:"Cancel",copyConfirm:n.btnLabel,classConfirm:"btn-"+n.btnClass,msg:n.msg,onConfirm:function(){return k.leaveRequest[e]().then(function(){D(e)}).catch(function(e){d.error("Error:",e)})}}}function C(){return m.get().then(function(e){w=e.contactId})}function T(e,n){e.stopPropagation(),r.openModal(n)}function A(e){r.openModal({leaveRequest:k.leaveRequest,leaveType:k.leaveRequest.request_type,selectedContactId:k.leaveRequest.contact_id,forceRecalculateBalanceChange:!0,defaultStatus:l.statusNames[M[e]]})}function D(n){var t=e.find(k.leaveRequestStatuses,function(e){return e.name===l.statusNames.awaitingApproval}).value;S===t&&u.publish("ManagerBadge:: Update Count"),u.publish("LeaveRequest::statusUpdate",{status:n,leaveRequest:k.leaveRequest})}function P(){var n=k.leaveRequestStatuses[k.leaveRequest.status_id].name,t=e.compact(e.map(O,function(t,a){return e.includes(t.allowedStatuses,n)?a:null}));!v(n)&&e.pull(t,"cancel"),"admin"!==k.role&&e.pull(t,"delete"),"staff"===k.role&&e.pull(t,"approve","reject"),"staff"!==k.role&&I(t),h()&&t.push("delete"),k.allowedActions=e.map(t,function(e){return{key:e,label:O[e].label,isDirectAction:O[e].isDirectAction}})}function R(){return g().then(function(e){e&&(k.role="admin")})}function I(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 w,S,k=this,L=l.statusNames,O={edit:{label:"Edit",allowedStatuses:[L.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[L.moreInformationRequired]},view:{label:"View",allowedStatuses:[L.approved,L.rejected,L.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[L.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[L.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[L.awaitingApproval,L.approved,L.rejected,L.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[L.awaitingApproval,L.moreInformationRequired,L.approved,L.rejected,L.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}},M={approve:"approved"};k.allowedActions=[],k.loading={component:!0},k.$onInit=f,k.action=p,k.openLeavePopup=T}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","$q","$rootScope","Contact","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService","Session"]}),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(){o.$emit("LeaveRequestPopup::addTab",C),_(),y()}function l(){C.request.comments.push({contact_id:q,leave_request_id:C.request.id,text:C.comment.text}),C.comment.text=""}function d(){return C.comment.text.length>0}function m(e){return!e.comment_id||C.canManage}function f(e){return n.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function p(){return C.request.comments.filter(function(e){return!e.toBeDeleted})}function h(e){return e===q?"Me":C.comment.contacts[e]?C.comment.contacts[e].display_name:void 0}function v(e){return C.mode===e}function b(){C.comment.text.length&&C.addComment()}function g(){var n=e.indexBy(C.request.comments,"contact_id"),t=Object.keys(n);return r.all({id:{IN:t}},{page:1,size:0}).then(function(n){C.comment.contacts=e.indexBy(n.list,"contact_id")})}function _(){return C.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),C.request.comments.length&&g()})}function y(){return C.loading.component=!0,c.get().then(function(e){q=e.contactId}).then(function(){C.loading.component=!1})}t.debug("Component: leave-request-popup-comments-tab");var q=null,C=this;C.loading={component:!0},C.comment={text:"",contacts:{}},C.$onInit=u,C.addComment=l,C.canRemoveComment=m,C.canSubmit=d,C.formatDateTime=f,C.getActiveComments=p,C.getCommentorName=h,C.isMode=v,C.onBeforeSubmit=b}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(){t("RequestModalDetails"+e.capitalize(T(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),w(),te.initChildController().then(function(){return i.all([x(),$()])}).then(!te.isMode("create")&&I).then(Y).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(z)}).then(!te.isMode("create")&&H).then(S).then(G).then(R).then(k).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).then(function(){te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.totalItems=te.balance.change.breakdown.length}).finally(function(){te.loading.tab=!1})}function p(){te.balance.closing=te.balance.opening+te.balance.change.amount}function h(e){return n(e,c.serverDateFormat).toDate()}function v(e){return n(e).format(c.serverDateFormat)}function b(e){var n;return i.resolve().then(function(){j(e),"from"===e&&N(),L("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return C(e)}).then(function(e){if(n=e.id!==te.period.id,n&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(n)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(z(),!n)return B();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(q)}function g(){return z(),B()}function _(){return te.uiOptions.toDate=null,j("to"),i.resolve().then(z).then(te.setDaysSelectionModeExtended).then(q).then(!te.uiOptions.multipleDays&&B)}function y(e){te.uiOptions.times[e].loading=!0}function q(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,L("hours")&&(te.uiOptions.times[e].loading=!1)})}function C(t){var a=n(te.uiOptions[t+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function T(){return te.request?te.request.request_type:te.leaveType||null}function A(e){return n().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return X(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(W).catch(P)}function P(n){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(n)?n:[n]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function R(){return te.isMode("create")||te.forceRecalculateBalanceChange?B():D()}function I(){var e=te.request.attributes();return te.uiOptions.fromDate=h(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=h(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function w(){ne.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,n){K(n)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",B))}function S(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(ee={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function k(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,n){e!==n&&(te.uiOptions.multipleDays||(Z(e),z()))})}function L(e){return te.selectedAbsenceType.calculation_unit_name===e}function O(e){return te.request.request_type===e}function M(n){return e.includes(["weekend","non_working_day","public_holiday"],n)}function $(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,n=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,n)}function B(){return X(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(W).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function F(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return v(te.request.from_date)===v(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&n(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,j("to"))}function j(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),z(),X()}function W(e){te.balance.change=e,te.request.balance_change=e.amount,p(),F(),te.loading.balanceChange=!1}function H(){var e,t,a;te.uiOptions.fromDate?(e=n(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,t=e):(a=h(te.period.start_date),t=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=t,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=h(te.period.end_date)}function Y(){return!te.isMode("create")&&U()||te.isMode("create")&&(O("sickness")||L("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){ee&&ee.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=ee.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function V(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function z(){var e=te.uiOptions,n=e.times;te.request.from_date=e.fromDate?v(e.fromDate):null,te.request.to_date=e.toDate?v(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),(L("hours")||O("toil"))&&(te.request.from_date=te.request.from_date&&n.from.time?te.request.from_date+" "+n.from.time:null,te.request.to_date=te.request.to_date&&n.to.time?te.request.to_date+" "+n.to.time:null)}function X(){te.uiOptions.showBalance=te.canCalculateChange()}function Q(){e.forEach(ne,function(e){e()})}function J(){var e,n=te.selectedAbsenceType.calculation_unit_name;return V(),e=n!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&Y).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&z).then(q).then(B)}function K(e){return te.absenceTypes=e,V(),n(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,j("to")),G(),B()}function Z(e){var n=A(e).add(te.uiOptions.time_interval,"minutes");n.isAfter(A(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=n.format("HH:mm"),n.isAfter(A(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var ee=null,ne=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:[],numPerPage:7,totalItems:0,pageChanged:E},te.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},te.$onInit=f,te.convertDateFormatFromServer=h,te.convertDateToServerFormat=v,te.dateChangeHandler=b,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=_,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=A,te.handleError=P,te.isCalculationUnit=L,te.isLeaveType=O,te.isNotWorkingDay=M,te.performBalanceChangeCalculation=B,te.setRequestDateTimesAndDateTypes=z,te.updateEndTimeInputMinTime=Z,te.$onDestroy=Q}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(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",k),_(),a.all([A(),C()]).then(y).finally(function(){k.filesLoaded=!0})}function m(){return k.fileUploader&&k.fileUploader.queue.length>0}function f(){return k.getFilesAmount()0?I.map(function(e){return e.label}).join(", "):""}function C(){return k.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function T(){return a.all(I.map(function(e){return l.getMimeTypeFor(e.label).then(function(n){S[e.label]=n})})).catch(function(){S=null})}function A(){return c.valuesOf("safe_file_extension").then(function(e){I=e})}function D(e){return!e.attachment_id||k.canManage}function P(){e.forEach(w,function(e){e()})}function R(e,n){k.fileUploader.queue&&k.fileUploader.queue.length>0?k.fileUploader.uploadAll({entityID:k.request.id}).then(function(){n()}).catch(n):n()}t.debug("Component: leave-request-popup-files-tab");var I=[],w=[],S={},k=Object.create(this);return k.filesLoaded=!1,k.fileUploader=null,k.today=Date.now(),k.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",k.userDateFormat=i.DATE_FORMAT,k.$onDestroy=P,k.$onInit=d,k.canRemoveAttachment=D,k.canSubmit=m,k.canUploadMore=f,k.formatDateTime=p,k.getAuthorName=h,k.getFilesAmount=v,k.listFileTypes=q,k}t.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function n(e,n,t){function a(){s=t.parse(),s.openModal&&o({leaveType:s.openModal,selectedContactId:i.selectedContactId})}function o(e){n.openModal(e)}e.debug("Component: leave-request-record-actions");var s,i=this;i.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],i.$onInit=a,i.openLeavePopup=o}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",n]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,n,t){function a(n,t,a,o,s,i,r,c,u,l,d,m){function f(){t.all([q(),E(),A(),T()]).then(function(){z.loading.page=!1}).then(function(){return t.all([R(),P()])}).then(B).then(function(){z.loading.content=!1}),N()}function p(e,n){n.data.push(e),n.dataIndex[e.id]=e}function h(){z.absenceTypes=z.absenceTypes.map(function(n){var t=e.find(z.entitlements,function(e){return e.type_id===n.id});return n.entitlement=t?t.value:0,n.remainder=t?t.remainder:{current:0,future:0},n})}function v(e){j(e),z.sections.other.open&&p(e,z.sections.other)}function b(){Object.values(z.sections).forEach(function(e){e.data=[]})}function g(){z.absenceTypesFiltered=z.absenceTypes.filter(function(e){return!(0===e.entitlement&&"1"!==e.allow_overuse&&"1"!==e.allow_accruals_request)})}function _(e){var n=V[e.status];n?n(e.leaveRequest):z.refresh()}function y(n){n.dataIndex=e.indexBy(n.data,"id")}function q(){return z.role="staff","absence-tab"===a.section?(z.role="admin",t.resolve()):o(m.permissions.admin.administer).then(function(e){e&&(z.role="admin")})}function C(e){return e.current?"Current Period ("+e.title+")":e.title}function T(){return s.all().then(function(n){z.absencePeriods=e.sortBy(n,"start_date"),z.selectedPeriod=e.find(z.absencePeriods,function(e){return!0===e.current})})}function A(){return i.all().then(i.loadCalculationUnits).then(function(n){z.absenceTypes=n,z.absenceTypesIndexed=e.indexBy(n,"id")})}function D(){return k("approved",{status_id:G(m.statusNames.approved)})}function P(){var n={contact_id:z.contactId,period_id:z.selectedPeriod.id};return t.all([c.balanceChangeByAbsenceType(e.assign({},n,{public_holiday:!0})),c.balanceChangeByAbsenceType(e.assign({},n,{expired:!0})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.approved)]}})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}}))]).then(function(e){z.absenceTypes.forEach(function(n){n.balanceChanges={holidays:e[0][n.id],expired:e[1][n.id],approved:e[2][n.id],pending:e[3][n.id]}})})}function R(){return r.all({contact_id:z.contactId,period_id:z.selectedPeriod.id},!0).then(function(e){z.entitlements=e})}function I(){return r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id},z.entitlements).then(function(){return F(z.entitlements)}).then(function(e){z.sections.entitlements.data=e})}function w(){return t.all([r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id,expired:!0}),S({request_type:"toil",expired:!0})]).then(function(e){return t.all({expiredBalanceChangesFlatten:F(e[0]),expiredTOILS:U(e[1].list)})}).then(function(n){z.sections.expired.data=n.expiredBalanceChangesFlatten.concat(n.expiredTOILS),z.sections.expired.data=e.sortBy(z.sections.expired.data,"expiry_date")})}function S(n){return c.all(e.assign({contact_id:z.contactId,from_date:{from:z.selectedPeriod.start_date},to_date:{to:z.selectedPeriod.end_date},type_id:{IN:z.absenceTypes.map(function(e){return e.id})}},n),null,"from_date ASC",null,!1)}function k(e,n){return S(n).then(function(n){z.sections[e].data=n.list})}function L(){return t.all(Object.values(z.sections).filter(function(e){return e.open}).map(x))}function O(){return k("other",{status_id:{in:[G(m.statusNames.rejected),G(m.statusNames.cancelled)]}})}function M(){return k("pending",{status_id:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}})}function $(){return k("holidays",{public_holiday:!0})}function x(e){return e.loading=!0,e.loadLeaveRequests().then(y.bind(this,e)).then(function(){e.loading=!1})}function E(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){z.leaveRequestStatuses=e.indexBy(n,"value")})}function B(){h(),g()}function F(n){return t.resolve().then(function(){return n.map(function(n){var t=e.find(z.entitlements,function(e){return e.id===n.id});return n.breakdown.map(function(n){return e.assign(e.clone(n),{type_id:t.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})} -function U(n){return t.resolve().then(function(){return n.map(function(n){return e.assign({},n,{expiry_date:n.toil_expiry_date,amount:n.toil_to_accrue,type:{label:"Accrued TOIL"}})})})}function N(){l.subscribe("LeaveRequest::new",function(){z.refresh()}),l.subscribe("LeaveRequest::edit",function(){z.refresh()}),l.subscribe("LeaveRequest::statusUpdate",_),l.subscribe("LeaveRequest::delete",function(e){j(e)})}function j(n){e.forEach(z.sections,function(t,a){t.dataIndex[n.id]&&(e.remove(t.data,function(e){return e.id===n.id}),delete t.dataIndex[n.id],"other"!==a&&W(n,a))})}function W(n,t){var a=["future","current"],o=z.absenceTypesIndexed[n.type_id];"pending"===t&&e.pull(a,"current"),o.balanceChanges[t]-=n.balance_change,a.forEach(function(e){o.remainder[e]-=n.balance_change})}function H(){z.loading.content=!0,t.all([R(),P()]).then(B).then(function(){z.loading.content=!1}).then(function(){return t.all([L(),b()])})}function Y(e){var n=z.sections[e];n.open=!n.open,n.open&&!n.data.length&&x(n)}function G(n){return e.find(z.leaveRequestStatuses,function(e){return e.name===n}).value}n.debug("Component: staff-leave-report");var V={delete:j,cancel:v},z=this;z.absencePeriods=[],z.absenceTypes=[],z.absenceTypesFiltered=[],z.absenceTypesIndexed={},z.dateFormat=d.DATE_FORMAT,z.leaveRequestStatuses={},z.selectedPeriod=null,z.role=null,z.loading={content:!0,page:!0},z.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:$},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:M},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O}},z.$onInit=f,z.labelPeriod=C,z.refresh=H,z.toggleSection=Y}t.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:a}),a.$inject=["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,n=!!e.from_date&&!!e.to_date,t=i.selectedAbsenceType.calculation_unit_name;return"days"===t?n=n&&!!e.from_date_type&&!!e.to_date_type:"hours"===t&&(n=n&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),n}function d(){return i.canCalculateChange()}function m(n,t){var a=i.uiOptions.times[n],o=e.clone(t.time_from),s=e.clone(t.time_to);i.uiOptions.multipleDays||("from"===n&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===n&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===n?a.max:a.min}function f(n,t){return n?(n=i.convertDateToServerFormat(n),v(n).then(function(t){return t?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(n,i.requestDayTypes).then(function(n){return n.length?n:i.requestDayTypes.filter(function(n){return e.includes(["all_day","half_day_am","half_day_pm"],n.name)})})}).then(function(e){return I(t,e),e})):o.reject([])}function p(e,t){return e=n(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(n){return n.name===e}):[]})}function h(e,t){return n.duration(t).subtract(n.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function _(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,n){i.isCalculationUnit("days")||+e==+n||(i.isRole("staff")&&(i.request.change_balance=!0),k(),i.performBalanceChangeCalculation())})}function y(e){var t=n(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,t)<=0||h(a.max,t)>=0)&&(t="from"===e?a.min:a.max),i.uiOptions.times[e].time=t}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],n=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(P)).then(function(){["from","to"].forEach(function(e){y(e),S(e),n[e].amount=Math.min(i.request[e+"_date_amount"],n[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(k)}function C(){["from","to"].forEach(function(e){_(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(n,t){i.isCalculationUnit("days")||n===t||(i.setRequestDateTimesAndDateTypes(),n&&S(e,!0))})}function A(e,n){return f(e,n).then(function(){i.loading[n+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return P(e).then(function(){S(e,!0)})})}function P(e){var n=i.uiOptions[e+"Date"],t=!i.uiOptions.multipleDays;return n?i.request.getWorkDayForDate(i.convertDateToServerFormat(n)).then(function(n){O[e]=n,m(e,n),t&&"from"===e&&m("to",n)}).catch(function(n){return O[e]={},i.handleError(n)}).finally(function(){i.uiOptions.times[e].loading=!1,t&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function R(n){var t=i.uiOptions.times[n];i["request"+e.startCase(n)+"DayTypes"]=[],t.time="",t.min="00:00",t.max="00:00",t.amount="0",t.maxAmount="0"}function I(n,t){var a="request"+e.startCase(n)+"DayTypes";i[a]=t,i.isMode("create")&&(i.request[n+"_date_type"]=i[a][0].value)}function w(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),P("from").then(function(){S("from",!0)})):o.resolve()}function S(e,n){var t=i.uiOptions,a=t.multipleDays?e:"from",o=t.times[a],s=t.multipleDays&&"to"===a?o.min:t.times.from.time,r=t.multipleDays&&"from"===a?o.max:t.times.to.time,c=O[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,n&&(o.amount=o.maxAmount)}function k(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function L(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?P("from").then(function(){S("from",!0)}):o.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=L,i.onDateChangeExtended=D,i.resetUIInputsExtended=R,i.setDaysSelectionModeExtended=w}t.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(n){var t=r.request.getDocumentArray();return!!e.find(t,function(e){return e===n})}function d(n){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===n})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(n){return i.valuesOf("hrleaveandabsences_sickness_reason",n).then(function(n){r.sicknessReasons=e.indexBy(n,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}t.debug("RequestModalDetailsSicknessController"),n("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}n.controller("RequestModalDetailsSicknessController",t),t.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=n.duration(n(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,n=!c.uiOptions.multipleDays&&!!c.request.from_date,t=n||e,a=N.from_date!==c.request.from_date||N.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&t&&W.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,n=c.request;return b({hasErrors:e?!n.to_date&&!n.from_date:!n.from_date,label:e?"To Date":"From Date",value:n.to_date})}function b(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(n(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&W.hasExpirationFromAdminSettings,n=W.hasPreviousExpirationDate,t=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=t&&(a||e||n)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return W.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){W.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&L(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function R(){c.isMode("view")||(T(),A(),P())}function I(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function w(){return l(),O(),F()}function S(){return $(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:O(),F()}function k(e){c.uiOptions.times[e].time=""}function L(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){N=e.cloneDeep(c.request.attributes())}function $(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?L():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function U(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var N,j=!c.isMode("create"),W={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=R,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=k,c.setDaysSelectionModeExtended=S,c.updateExpiryDate=U,function(){M(),$(),B(),!c.isMode("create")&&_()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,t,a){return e.debug("AbsencePeriodInstance"),t.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var t=n();return e.current=!1,n(e.start_date).isSameOrBefore(t,"day")&&n(e.end_date).isSameOrAfter(t,"day")&&(e.current=!0),e},isInPeriod:function(e){var t=a.DATE_FORMAT.toUpperCase(),o=n(e,t);return n(this.start_date).isSameOrBefore(o)&&n(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,n){return e.debug("AbsencePeriodAPI"),n.extend({all:function(n){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,t,a,o,s){return e.debug("AbsencePeriod"),t.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=n().format(s.serverDateFormat),t={start_date:{"<=":e},end_date:{">=":e}};return a.all(t).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,n){return e.debug("PublicHolidayAPI"),n.extend({all:function(n){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,n){return e.debug("PublicHolidayInstance"),n.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,n){"use strict";n.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(n,t,a,o,s){return n.debug("PublicHoliday"),t.extend({all:function(e){return n.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(t){n.debug("PublicHoliday.isPublicHoliday",t);var o=e(t).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C){function T(e){"days"===Ue.selectedAbsenceType.calculation_unit_name?delete Ue.request[e+"_date_amount"]:delete Ue.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return Le.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function P(){var e=Ue.requestStatuses[_.statusNames.awaitingApproval].value;$e.status_id===e&&e!==Ue.request.status_id&&d.publish("ManagerBadge:: Update Count")}function R(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!Ue.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function S(){var e=R();return Ue.isMode("edit")&&(e=e&&(G()||I())),Ue.canManage&&Ue.requestStatuses&&(e=e&&!!Ue.getStatusFromValue(Ue.newStatusOnSave)),(e=e&&!!Ue.period.id)&&!Ue.isMode("view")}function k(){Ue.isSelfRecord&&!Ue.isSelfLeaveApprover?Ue.request.status_id=Ue.requestStatuses[_.statusNames.awaitingApproval].value:Ue.canManage&&(Ue.request.status_id=Ue.newStatusOnSave||Ue.request.status_id)}function L(){if(Ue.isMode("edit")&&!Ue.isRole("staff")&&"toil"!==j())return Ue.request.calculateBalanceChange(Ue.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ue.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==j()&&!Ue.request.change_balance}function M(){Ue.errors=[]}function $(){return Ue.request.create().then(Re).then(function(){ge("LeaveRequest::new")})}function x(){se()&&!Ue.isRole("staff")&&(Ue.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ue.request.delete().then(function(){Ue.dismissModal(),d.publish("LeaveRequest::delete",Ue.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(Ue.getStatusFromValue(Ue.request.status_id).name)}function N(e){return t.map(Oe[e],function(e){return Ue.requestStatuses[e]})}function j(){return Ue.request?Ue.request.request_type:Ue.leaveType||null}function W(){return!Ue.request||e.equals({},Ue.requestStatuses)?[]:Ue.request.status_id?U():N("none")}function H(e){return t.find(Ue.requestStatuses,function(n){return n.value===e})}function Y(e){Ue.errors=t.isArray(e)?e:[e],Ue.loading.absenceTypes=!1,Ue.submitting=!1}function G(){return!e.equals($e,Ue.request.attributes())||Ue.canManage&&Ue.newStatusOnSave}function V(){return Ue.postContactSelection=!0,Ue.staffMemberSelectionComplete=!1,Ue.request.contact_id?o.resolve().then(me).then(fe).then(ye).then(Ce).then(oe).then(Q).then(Ue.isMode("edit")?Te:t.noop).then(function(){Ue.postContactSelection=!1,Ue.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Oe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function X(){Ue.canManage=Ue.isRole("manager")||Ue.isRole("admin")}function Q(){return Ue.canManage?f.find(Ue.request.contact_id).then(function(e){Ue.contactName=e.display_name}):o.resolve()}function J(){Ue.isRole("admin")&&Ue.isSelfRecord&&(Ue.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+Le.id==+t.get(Ue,"leaveRequest.contact_id"),a=!t.get(Ue,"leaveRequest.id");Ue.isSelfRecord=e&&a||n}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(ye).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ue.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Ie),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ue.request=Ue.leaveRequest||null,e=j(),n=Ue.initRequestAttributes(),"leave"===e?Ue.request=g.init(n):"sickness"===e?Ue.request=y.init(n):"toil"===e&&(Ue.request=q.init(n))}function ne(){var e={};return Ue.request?e=Ue.request.attributes():Ue.canManage||(e={contact_id:Le.id}),e}function te(){return Be="staff",ae().then(Ue.isSelfRecord&&!Ue.isRole("admin")&&D)}function ae(){return c(_.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(_.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ue.defaultStatus?Ue.newStatusOnSave=Ue.requestStatuses[_.statusNames[Ue.defaultStatus]].value:(Ue.isRole("admin")||Ue.isMode("create")&&Ue.isRole("manager"))&&(Ue.newStatusOnSave=Ue.requestStatuses[_.statusNames.approved].value)}function se(){return!Ue.request.status_id||!t.includes(["cancelled","rejected"],H(Ue.request.status_id).name)}function ie(e){var n=Ue.getStatusFromValue(Ue.request.status_id);return!!n&&n.name===e}function re(e){return Ue.request&&Ue.request.request_type===e}function ce(e){return Ue.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ue.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){ke={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ue.loading.entitlements=!0,v.all({contact_id:Ue.request.contact_id,period_id:Ue.period.id,type_id:{IN:ke.ids}},!0).finally(function(){Ue.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){Le=e})}function he(){return Ue.selectedContactId?f.find(Ue.selectedContactId).then(function(e){Ue.managedContacts=[e]}):Ue.isRole("admin")?f.all().then(function(e){Ue.managedContacts=t.remove(e.list,function(e){return e.id!==Le.id})}):Le.leaveManagees().then(function(e){Ue.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ue.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){P(),d.publish(e,Ue.request),Ue.errors=[],Ue.dismissModal()}function _e(){["from","to"].forEach(function(e){Ue.request[e+"_date"]=$e[e+"_date"]})}function ye(e){if(Ue.absenceTypes=be(ke.types,e),!Ue.absenceTypes.length)return o.reject(Ee)}function qe(){Ue.period=t.find(Ue.absencePeriods,function(e){return Ue.isMode("create")?e.current:ue(Ue.request,e)})}function Ce(){Ue.isMode("create")?(Ue.selectedAbsenceType=Ue.absenceTypes[0],Ue.request.type_id=Ue.selectedAbsenceType.id):Ue.selectedAbsenceType=t.find(Ue.absenceTypes,function(e){return e.id===Ue.request.type_id})}function Te(){$e=e.copy(Ue.request.attributes())}function Ae(){var e;Ue.request.id?(e=[Ue.requestStatuses[_.statusNames.approved].value,Ue.requestStatuses[_.statusNames.adminApproved].value,Ue.requestStatuses[_.statusNames.rejected].value,Ue.requestStatuses[_.statusNames.cancelled].value],Ue.mode="edit",Ue.isRole("staff")&&e.indexOf(Ue.request.status_id)>-1&&(Ue.mode="view")):Ue.mode="create"}function De(){var e=Ue.request.status_id;if(!Ue.isMode("view")&&!Ue.submitting)return Ue.submitting=!0,k(),A(),Ue.request.isValid().then(se()&&L).then(x).then(O()&&_e).then(Pe).then(function(){return Ue.isMode("edit")?Se():$()}).catch(function(n){Ue.request.status_id=e,n&&Y(n)}).finally(function(){Ue.submitting=!1})}function Pe(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Re(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Ie(){xe.forEach(function(e){e()})}function we(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Se(){return Ue.request.update().then(Re).then(function(){Ue.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ue.isRole("staff")||Ue.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var ke,Le,Oe={},Me=0,$e={},xe=[],Ee="No entitlement",Be="",Fe=[],Ue=t.assign(this,m);Ue.absencePeriods=[],Ue.absenceTypes=[],Ue.canManage=!1,Ue.contactName=null,Ue.errors=[],Ue.isSelfLeaveApprover=!1,Ue.loading={absenceTypes:!0,entitlements:!0},Ue.managedContacts=[],Ue.mode="",Ue.newStatusOnSave=null,Ue.period={},Ue.postContactSelection=!1,Ue.requestStatuses={},Ue.selectedAbsenceType={},Ue.staffMemberSelectionComplete=!1,Ue.submitting=!1,Ue.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ue.canChangeAbsenceType=w,Ue.canSubmit=S,Ue.closeAlert=M,Ue.deleteLeaveRequest=E,Ue.dismissModal=B,Ue.getStatuses=W,Ue.getStatusFromValue=H,Ue.initAfterContactSelection=V,Ue.initRequestAttributes=ne,Ue.isLeaveStatus=ie,Ue.isLeaveType=re,Ue.isMode=ce,Ue.isRole=le,Ue.submit=De,Ue.updateAbsenceType=we,function(){Ue.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ue.canManage&&!Ue.isMode("edit")&&he()}).then(function(){if(Ue.selectedContactId&&(Ue.request.contact_id=Ue.selectedContactId),Ue.request.contact_id)return Ue.initAfterContactSelection()}).catch(Y).finally(function(){Ue.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}), +function U(n){return t.resolve().then(function(){return n.map(function(n){return e.assign({},n,{expiry_date:n.toil_expiry_date,amount:n.toil_to_accrue,type:{label:"Accrued TOIL"}})})})}function N(){l.subscribe("LeaveRequest::new",function(){z.refresh()}),l.subscribe("LeaveRequest::edit",function(){z.refresh()}),l.subscribe("LeaveRequest::statusUpdate",_),l.subscribe("LeaveRequest::delete",function(e){j(e)})}function j(n){e.forEach(z.sections,function(t,a){t.dataIndex[n.id]&&(e.remove(t.data,function(e){return e.id===n.id}),delete t.dataIndex[n.id],"other"!==a&&W(n,a))})}function W(n,t){var a=["future","current"],o=z.absenceTypesIndexed[n.type_id];"pending"===t&&e.pull(a,"current"),o.balanceChanges[t]-=n.balance_change,a.forEach(function(e){o.remainder[e]-=n.balance_change})}function H(){z.loading.content=!0,t.all([R(),P()]).then(B).then(function(){z.loading.content=!1}).then(function(){return t.all([L(),b()])})}function Y(e){var n=z.sections[e];n.open=!n.open,n.open&&!n.data.length&&x(n)}function G(n){return e.find(z.leaveRequestStatuses,function(e){return e.name===n}).value}n.debug("Component: staff-leave-report");var V={delete:j,cancel:v},z=this;z.absencePeriods=[],z.absenceTypes=[],z.absenceTypesFiltered=[],z.absenceTypesIndexed={},z.dateFormat=d.DATE_FORMAT,z.leaveRequestStatuses={},z.selectedPeriod=null,z.role=null,z.loading={content:!0,page:!0},z.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:$},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:M},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O}},z.$onInit=f,z.labelPeriod=C,z.refresh=H,z.toggleSection=Y}t.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:a}),a.$inject=["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,n=!!e.from_date&&!!e.to_date,t=i.selectedAbsenceType.calculation_unit_name;return"days"===t?n=n&&!!e.from_date_type&&!!e.to_date_type:"hours"===t&&(n=n&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),n}function d(){return i.canCalculateChange()}function m(n,t){var a=i.uiOptions.times[n],o=e.clone(t.time_from),s=e.clone(t.time_to);i.uiOptions.multipleDays||("from"===n&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===n&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===n?a.max:a.min}function f(n,t){return n?(n=i.convertDateToServerFormat(n),v(n).then(function(t){return t?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(n,i.requestDayTypes).then(function(n){return n.length?n:i.requestDayTypes.filter(function(n){return e.includes(["all_day","half_day_am","half_day_pm"],n.name)})})}).then(function(e){return I(t,e),e})):o.reject([])}function p(e,t){return e=n(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(n){return n.name===e}):[]})}function h(e,t){return n.duration(t).subtract(n.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function _(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,n){i.isCalculationUnit("days")||+e==+n||(i.isRole("staff")&&(i.request.change_balance=!0),k(),i.performBalanceChangeCalculation())})}function y(e){var t=n(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,t)<=0||h(a.max,t)>=0)&&(t="from"===e?a.min:a.max),i.uiOptions.times[e].time=t}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],n=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(P)).then(function(){["from","to"].forEach(function(e){y(e),S(e),n[e].amount=Math.min(i.request[e+"_date_amount"],n[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(k)}function C(){["from","to"].forEach(function(e){_(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(n,t){i.isCalculationUnit("days")||n===t||(i.setRequestDateTimesAndDateTypes(),n&&S(e,!0))})}function A(e,n){return f(e,n).then(function(){i.loading[n+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return P(e).then(function(){S(e,!0)})})}function P(e){var n=i.uiOptions[e+"Date"],t=!i.uiOptions.multipleDays;return n?i.request.getWorkDayForDate(i.convertDateToServerFormat(n)).then(function(n){O[e]=n,m(e,n),t&&"from"===e&&m("to",n)}).catch(function(n){return O[e]={},i.handleError(n)}).finally(function(){i.uiOptions.times[e].loading=!1,t&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function R(n){var t=i.uiOptions.times[n];i["request"+e.startCase(n)+"DayTypes"]=[],t.time="",t.min="00:00",t.max="00:00",t.amount="0",t.maxAmount="0"}function I(n,t){var a="request"+e.startCase(n)+"DayTypes";i[a]=t,i.isMode("create")&&(i.request[n+"_date_type"]=i[a][0].value)}function w(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),P("from").then(function(){S("from",!0)})):o.resolve()}function S(e,n){var t=i.uiOptions,a=t.multipleDays?e:"from",o=t.times[a],s=t.multipleDays&&"to"===a?o.min:t.times.from.time,r=t.multipleDays&&"from"===a?o.max:t.times.to.time,c=O[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,n&&(o.amount=o.maxAmount)}function k(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function L(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?P("from").then(function(){S("from",!0)}):o.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=L,i.onDateChangeExtended=D,i.resetUIInputsExtended=R,i.setDaysSelectionModeExtended=w}t.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(n){var t=r.request.getDocumentArray();return!!e.find(t,function(e){return e===n})}function d(n){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===n})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(n){return i.valuesOf("hrleaveandabsences_sickness_reason",n).then(function(n){r.sicknessReasons=e.indexBy(n,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}t.debug("RequestModalDetailsSicknessController"),n("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}n.controller("RequestModalDetailsSicknessController",t),t.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=n.duration(n(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,n=!c.uiOptions.multipleDays&&!!c.request.from_date,t=n||e,a=N.from_date!==c.request.from_date||N.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&t&&W.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,n=c.request;return b({hasErrors:e?!n.to_date&&!n.from_date:!n.from_date,label:e?"To Date":"From Date",value:n.to_date})}function b(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(n(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&W.hasExpirationFromAdminSettings,n=W.hasPreviousExpirationDate,t=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=t&&(a||e||n)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return W.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){W.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&L(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function R(){c.isMode("view")||(T(),A(),P())}function I(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function w(){return l(),O(),F()}function S(){return $(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:O(),F()}function k(e){c.uiOptions.times[e].time=""}function L(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){N=e.cloneDeep(c.request.attributes())}function $(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?L():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function U(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var N,j=!c.isMode("create"),W={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=R,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=k,c.setDaysSelectionModeExtended=S,c.updateExpiryDate=U,function(){M(),$(),B(),!c.isMode("create")&&_()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,t,a){return e.debug("AbsencePeriodInstance"),t.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var t=n();return e.current=!1,n(e.start_date).isSameOrBefore(t,"day")&&n(e.end_date).isSameOrAfter(t,"day")&&(e.current=!0),e},isInPeriod:function(e){var t=a.DATE_FORMAT.toUpperCase(),o=n(e,t);return n(this.start_date).isSameOrBefore(o)&&n(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,n){return e.debug("AbsencePeriodAPI"),n.extend({all:function(n){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,t,a,o,s){return e.debug("AbsencePeriod"),t.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=n().format(s.serverDateFormat),t={start_date:{"<=":e},end_date:{">=":e}};return a.all(t).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,n){return e.debug("PublicHolidayAPI"),n.extend({all:function(n){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,n){return e.debug("PublicHolidayInstance"),n.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,n){"use strict";n.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(n,t,a,o,s){return n.debug("PublicHoliday"),t.extend({all:function(e){return n.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(t){n.debug("PublicHoliday.isPublicHoliday",t);var o=e(t).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C){function T(e){"days"===Ue.selectedAbsenceType.calculation_unit_name?delete Ue.request[e+"_date_amount"]:delete Ue.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return Le.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function P(){var e=Ue.requestStatuses[_.statusNames.awaitingApproval].value;$e.status_id===e&&e!==Ue.request.status_id&&d.publish("ManagerBadge:: Update Count")}function R(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!Ue.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function S(){var e=R();return Ue.isMode("edit")&&(e=e&&(G()||I())),Ue.canManage&&Ue.requestStatuses&&(e=e&&!!Ue.getStatusFromValue(Ue.newStatusOnSave)),(e=e&&!!Ue.period.id)&&!Ue.isMode("view")}function k(){Ue.isSelfRecord&&!Ue.isSelfLeaveApprover?Ue.request.status_id=Ue.requestStatuses[_.statusNames.awaitingApproval].value:Ue.canManage&&(Ue.request.status_id=Ue.newStatusOnSave||Ue.request.status_id)}function L(){if(Ue.isMode("edit")&&!Ue.isRole("staff")&&"toil"!==j())return Ue.request.calculateBalanceChange(Ue.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ue.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==j()&&!Ue.request.change_balance}function M(){Ue.errors=[]}function $(){return Ue.request.create().then(Re).then(function(){ge("LeaveRequest::new")})}function x(){se()&&!Ue.isRole("staff")&&(Ue.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ue.request.delete().then(function(){Ue.dismissModal(),d.publish("LeaveRequest::delete",Ue.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(Ue.getStatusFromValue(Ue.request.status_id).name)}function N(e){return t.map(Oe[e],function(e){return Ue.requestStatuses[e]})}function j(){return Ue.request?Ue.request.request_type:Ue.leaveType||null}function W(){return!Ue.request||e.equals({},Ue.requestStatuses)?[]:Ue.request.status_id?U():N("none")}function H(e){return t.find(Ue.requestStatuses,function(n){return n.value===e})}function Y(e){Ue.errors=t.isArray(e)?e:[e],Ue.loading.absenceTypes=!1,Ue.submitting=!1}function G(){return!e.equals($e,Ue.request.attributes())||Ue.canManage&&Ue.newStatusOnSave}function V(){return Ue.postContactSelection=!0,Ue.staffMemberSelectionComplete=!1,Ue.request.contact_id?o.resolve().then(me).then(fe).then(ye).then(Ce).then(oe).then(Q).then(Ue.isMode("edit")?Te:t.noop).then(function(){Ue.postContactSelection=!1,Ue.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Oe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function X(){Ue.canManage=Ue.isRole("manager")||Ue.isRole("admin")}function Q(){return Ue.canManage?f.find(Ue.request.contact_id).then(function(e){Ue.contactName=e.display_name}):o.resolve()}function J(){Ue.isRole("admin")&&Ue.isSelfRecord&&(Ue.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+Le.id==+t.get(Ue,"leaveRequest.contact_id"),a=!t.get(Ue,"leaveRequest.id");Ue.isSelfRecord=e&&a||n}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(ye).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ue.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Ie),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ue.request=Ue.leaveRequest||null,e=j(),n=Ue.initRequestAttributes(),"leave"===e?Ue.request=g.init(n):"sickness"===e?Ue.request=y.init(n):"toil"===e&&(Ue.request=q.init(n))}function ne(){var e={};return Ue.request?e=Ue.request.attributes():Ue.canManage||(e={contact_id:Le.id}),e}function te(){return Be="staff",ae().then(Ue.isSelfRecord&&!Ue.isRole("admin")&&D)}function ae(){return c(_.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(_.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ue.defaultStatus?Ue.newStatusOnSave=Ue.requestStatuses[_.statusNames[Ue.defaultStatus]].value:(Ue.isRole("admin")||Ue.isMode("create")&&Ue.isRole("manager"))&&(Ue.newStatusOnSave=Ue.requestStatuses[_.statusNames.approved].value)}function se(){return!Ue.request.status_id||!t.includes(["cancelled","rejected"],H(Ue.request.status_id).name)}function ie(e){var n=Ue.getStatusFromValue(Ue.request.status_id);return!!n&&n.name===e}function re(e){return Ue.request&&Ue.request.request_type===e}function ce(e){return Ue.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ue.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){ke={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ue.loading.entitlements=!0,v.all({contact_id:Ue.request.contact_id,period_id:Ue.period.id,type_id:{IN:ke.ids}},!0).finally(function(){Ue.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){Le=e})}function he(){return Ue.selectedContactId?f.find(Ue.selectedContactId).then(function(e){Ue.managedContacts=[e]}):Ue.isRole("admin")?f.all().then(function(e){console.log(e.list),Ue.managedContacts=e.list}):Le.leaveManagees().then(function(e){Ue.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ue.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){P(),d.publish(e,Ue.request),Ue.errors=[],Ue.dismissModal()}function _e(){["from","to"].forEach(function(e){Ue.request[e+"_date"]=$e[e+"_date"]})}function ye(e){if(Ue.absenceTypes=be(ke.types,e),!Ue.absenceTypes.length)return o.reject(Ee)}function qe(){Ue.period=t.find(Ue.absencePeriods,function(e){return Ue.isMode("create")?e.current:ue(Ue.request,e)})}function Ce(){Ue.isMode("create")?(Ue.selectedAbsenceType=Ue.absenceTypes[0],Ue.request.type_id=Ue.selectedAbsenceType.id):Ue.selectedAbsenceType=t.find(Ue.absenceTypes,function(e){return e.id===Ue.request.type_id})}function Te(){$e=e.copy(Ue.request.attributes())}function Ae(){var e;Ue.request.id?(e=[Ue.requestStatuses[_.statusNames.approved].value,Ue.requestStatuses[_.statusNames.adminApproved].value,Ue.requestStatuses[_.statusNames.rejected].value,Ue.requestStatuses[_.statusNames.cancelled].value],Ue.mode="edit",Ue.isRole("staff")&&e.indexOf(Ue.request.status_id)>-1&&(Ue.mode="view")):Ue.mode="create"}function De(){var e=Ue.request.status_id;if(!Ue.isMode("view")&&!Ue.submitting)return Ue.submitting=!0,k(),A(),Ue.request.isValid().then(se()&&L).then(x).then(O()&&_e).then(Pe).then(function(){return Ue.isMode("edit")?Se():$()}).catch(function(n){Ue.request.status_id=e,n&&Y(n)}).finally(function(){Ue.submitting=!1})}function Pe(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Re(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Ie(){xe.forEach(function(e){e()})}function we(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Se(){return Ue.request.update().then(Re).then(function(){Ue.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ue.isRole("staff")||Ue.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var ke,Le,Oe={},Me=0,$e={},xe=[],Ee="No entitlement",Be="",Fe=[],Ue=t.assign(this,m);Ue.absencePeriods=[],Ue.absenceTypes=[],Ue.canManage=!1,Ue.contactName=null,Ue.errors=[],Ue.isSelfLeaveApprover=!1,Ue.loading={absenceTypes:!0,entitlements:!0},Ue.managedContacts=[],Ue.mode="",Ue.newStatusOnSave=null,Ue.period={},Ue.postContactSelection=!1,Ue.requestStatuses={},Ue.selectedAbsenceType={},Ue.staffMemberSelectionComplete=!1,Ue.submitting=!1,Ue.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ue.canChangeAbsenceType=w,Ue.canSubmit=S,Ue.closeAlert=M,Ue.deleteLeaveRequest=E,Ue.dismissModal=B,Ue.getStatuses=W,Ue.getStatusFromValue=H,Ue.initAfterContactSelection=V,Ue.initRequestAttributes=ne,Ue.isLeaveStatus=ie,Ue.isLeaveType=re,Ue.isMode=ce,Ue.isRole=le,Ue.submit=De,Ue.updateAbsenceType=we,function(){Ue.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ue.canManage&&!Ue.isMode("edit")&&he()}).then(function(){if(Ue.selectedContactId&&(Ue.request.contact_id=Ue.selectedContactId),Ue.request.contact_id)return Ue.initAfterContactSelection()}).catch(Y).finally(function(){Ue.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}), define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,n){"use strict";function t(e,n,t,a,o,s,i,r,c){function u(e){return r.get().then(function(n){return e.roleOf(n.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:n.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(n){n?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}n.factory("LeavePopup",t),t.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(n){function t(n,t,a){function o(){a.getDateFormat()}n.debug("Component: absence-tab-container"),t.section="absence-tab";var s=this;s.contactId=e.adminId,s.$onInit=o}n.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:t}),t.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,n){function t(e,n,t){function a(){o().finally(function(){s.loading.component=!1})}function o(){return t.all().then(t.loadCalculationUnits).then(function(e){s.absenceTypes=e})}n.debug("Component: absence-tab-entitlements");var s=this;s.absenceTypes=[],s.loading={component:!0},s.$onInit=a}n.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:t}),t.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return t.all([l(),d(!0)]).finally(function(){f.loading.content=!1})}function u(e){f.errorMessage=e}function l(){return r.get({is_active:!0}).then(function(e){f.workPatterns=e})}function d(e){return s.valuesOf("hrleaveandabsences_work_pattern_change_reason",e).then(function(e){f.changeReasons=e})}function m(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_work_pattern_change_reason?reset=1").on("crmUnload",function(){d(!1)})}n.debug("Component: absence-tab-custom-work-pattern-modal");var f=Object.create(this);return f.changeReasons=[],f.errorMessage="",f.saveInProgress=!1,f.workPatterns=[],f.loading={content:!0},f.selected={workPattern:null,effectiveDate:null,changeReason:null},f.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},f.$onInit=c,f.openWorkPatternChangeReasonEditor=m,f.closeModal=function(){f.dismiss({$value:"cancel"})},f.closeAlert=function(){f.errorMessage=""},f.save=function(){var n=e(f.selected.effectiveDate).format(i.serverDateFormat);return f.saveInProgress=!0,r.assignWorkPattern(f.contactId,f.selected.workPattern.id,n,null,f.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),f.closeModal()}).catch(u).finally(function(){f.saveInProgress=!1})},f}n.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","crmAngService","OptionGroup","shared-settings","WorkPatternAPI",t]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,n,t){function a(t,a,o,s,i,r,c,u,l,d){function m(){y.linkToWorkPatternListingPage=g(),v([h(),p(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){v()})}function f(){return d.workPatternsOf(y.contactId,{},!1).then(function(e){y.customWorkPatterns=e})}function p(){return d.default().then(function(e){y.defaultWorkPattern=e})}function h(){return l.valuesOf("hrleaveandabsences_work_pattern_change_reason").then(function(n){_=e.indexBy(n,"value")})}function v(e){var n=[f()];return e&&(n=n.concat(e)),y.loading.workPattern=!0,a.all(n).then(function(){b()}).finally(function(){y.loading.workPattern=!1})}function b(){var t,a=u.DATE_FORMAT.toUpperCase();y.customWorkPatterns=e(y.customWorkPatterns).map(function(e){return t=_[e.change_reason],e.change_reason_label=t?t.label:"",e.effective_date=e.effective_date?n(e.effective_date).format(a):"",e}).sortBy(function(e){return-n(e.effective_date,a).valueOf()}).value()}function g(){var e=CRM.url("civicrm/contact/view",{cid:y.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:y.contactId,returnUrl:e})}t.debug("Component: absence-tab-work-patterns");var _=[],y=Object.create(this);return y.customWorkPatterns=[],y.defaultWorkPattern=null,y.loading={workPattern:!0},y.$onInit=m,y.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){v()})}})},y.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},y}t.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,n,t){function a(t,a,o,s,i){function r(){v().then(b).then(g).then(c).then(u).then(_).then(p).finally(function(){T.loading.component=!1})}function c(){return d().then(function(e){C=C.concat(e)})}function u(){var n=e.groupBy(C,"created_date");T.changeLogRows=e.map(n,m).sort(function(e,n){return n.date.diff(e.date)})}function l(e,n){var t,a,o=f(e);e.entitlements.forEach(function(s,i){t=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),n(s,t,a)})}function d(){return o.all({contact_id:T.contactId,period_id:T.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function m(t,a){var o,s,i;return s=e.indexBy(t,"entitlement_id.type_id"),i=T.absenceTypes.map(function(n){return o=s[n.id],e.extend({calculation_unit:n.calculation_unit_name},o)}),{date:n(a),entitlements:i}}function f(e){var n;return n=T.changeLogRows.indexOf(e),T.changeLogRows[n+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function p(){for(var n,t,a,o=T.changeLogRows.length-1;o>=0;o--)if(n=T.changeLogRows[o],t=e.pluck(n.entitlements,"comment"),a=e.compact(t),1===a.length){var s=e.findIndex(t,"length");n.highlightedEntitlement=n.entitlements[s]}else a.length>1&&y(o)}function h(e,n){T.changeLogRows.splice(n,0,e)}function v(){return t.all({id:T.periodId}).then(function(e){T.absencePeriod=e[0]})}function b(e){return a.all().then(a.loadCalculationUnits).then(function(e){T.absenceTypes=e})}function g(){return o.logs({contact_id:T.contactId,period_id:T.periodId}).then(function(e){C=e})}function _(){var e,n;if(!(T.changeLogRows.length<=1))for(e=T.changeLogRows.length-2,n=T.changeLogRows.length-1;e>=0;){var t=T.changeLogRows[e],a=T.changeLogRows[n];t.entitlements.forEach(function(e,n){var t=a.entitlements[n];e.comment===t.comment&&delete e.comment}),e--,n--}}function y(e){var n,t,a=T.changeLogRows[e];l(a,function(o,s,i){o.comment&&(n=s.concat(o).concat(i),t={date:a.date.clone(),entitlements:n},t.highlightedEntitlement=o,h(t,e++))}),q(e)}function q(e){T.changeLogRows.splice(e,1)}var C=[],T=this;T.absencePeriod=null,T.absenceTypes=[],T.changeLogRows=[],T.loading={component:!0},T.$onInit=r}t.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(n,t,a){function o(a,o,s,i,r,c,u,l,d){function m(){g().then(b).then(v).then(f).then(p).then(y).finally(function(){A.loading.absencePeriods=!1})}function f(){A.absencePeriods=n.chain(A.absencePeriods).filter(function(e){return n.find(C,function(n){return n.period_id===e.id})}).sortBy(function(e){return-t(e.start_date).valueOf()}).value()}function p(){A.absenceTypes=n.filter(A.absenceTypes,function(e){return n.find(C,function(n){return n.type_id===e.id})})}function h(n){var t=e.url("civicrm/contact/view",{cid:A.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:n,cid:A.contactId,returnUrl:t})}function v(){return c.all().then(function(e){A.absencePeriods=e})}function b(){var e=n.uniq(n.map(C,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){T=n.indexBy(e.list,"contact_id")})}function g(){return u.all({contact_id:A.contactId}).then(function(e){C=e})}function _(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(n){this.contactId=A.contactId,this.dismiss=n.dismiss,this.periodId=e}],controllerAs:"modal"})}function y(){A.absencePeriods=n.map(A.absencePeriods,function(e){var t=n.map(A.absenceTypes,function(t){var a=n.find(C,function(n){return n.type_id===t.id&&n.period_id===e.id});return a?{amount:a.value,calculation_unit:t.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:T[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:t}})}function q(e){var n=e.message+"

Last updated:
By: "+e.author_name+"
Date: "+t.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
";d.info("Calculation comment:",n)}a.debug("Component: annual-entitlements");var C=[],T=[],A=this;A.absencePeriods=[],A.loading={absencePeriods:!0},A.$onInit=m,A.getEditEntitlementsPageURL=h,A.openAnnualEntitlementChangeLog=_,A.showComment=q}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,n,t){function a(t,a,o,s,i,r){function c(){r.getDateFormat().then(d).then(u).then(m).finally(function(){f.loading.contracts=!1})}function u(){f.absenceTypes=e.filter(f.absenceTypes,function(n){return e.find(f.contracts,function(t){return e.find(t.info.leave,function(e){return e.leave_type===n.id})})})}function l(e){var t=o.DATE_FORMAT.toUpperCase();return e?n(e).format(t):""}function d(){return i.all({contact_id:f.contactId}).then(function(e){f.contracts=e})}function m(){f.contracts=e.sortBy(f.contracts,function(e){return n(e.info.details.period_start_date)}).map(function(n){var t=n.info,a=t.details,o=e.map(f.absenceTypes,function(n){var a=e.filter(t.leave,function(e){return e.leave_type===n.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:n.calculation_unit_name}});return{position:a.position,start_date:l(a.period_start_date),end_date:l(a.period_end_date),absences:o}})}t.debug("Component: contract-entitlements");var f=this;f.contracts=[],f.loading={contracts:!0},f.$onInit=c}t.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(n){return n.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,n,t,a){t.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,n.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,n,t,a){e.debug("app.run"),n.sharedPathTpl=t.sharedPathTpl,n.settings=a}]),e}),function(e,n){var t=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";n.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":t+"/shared","leave-absences/absence-tab":t+"/absence-tab"}}),n(["leave-absences/shared/config"],function(){n(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/admin-dashboard.min.js index 23713ce42a9..c478dc1ef8a 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/admin-dashboard.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){e.config({paths:{mocks:"../test/mocks"}}),e.config({paths:{mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(n){return n.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",sourcePath:e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,n,t){function a(t){function a(e){e.absencePeriods&&u.absencePeriods.length&&(u.filters.period_id=s().id),e.absenceTypes&&u.absenceTypes.length&&(u.filters.type_id=i().id),(e.loggedInContactId||e.userRole)&&(u.filters.managed_by="manager"===u.userRole?u.loggedInContactId:void 0),o()&&u.submitFilters()}function o(){return e.every(u.filters,function(e){return null!==e})}function s(){return e.find(u.absencePeriods,function(e){return e.current})||u.absencePeriods.reduce(function(e,t){return n(e.end_date).isAfter(t.end_date)?e:t})}function i(){return u.absenceTypes.reduce(function(e,n){return e.title.localeCompare(n.title)?e:n})}function r(e){return e.current?"Current Period ("+e.title+")":e.title}function c(){t.$emit("LeaveBalanceFilters::update",u.filters)}var u=this;u.filters={period_id:null,type_id:null,managed_by:null},u.$onChanges=a,u.labelPeriod=r,u.submitFilters=c}t.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,t){function a(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(t.remainder=a[0].remainder),delete t["api.LeavePeriodEntitlement.getremainder"],t}function o(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return t.value=a,delete t["api.LeavePeriodEntitlement.getentitlement"],t}return e.debug("EntitlementAPI"),t.extend({all:function(n,t){return e.debug("EntitlementAPI.all"),n["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},t&&(n["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",n,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),t&&(e=e.map(a)),e})},breakdown:function(n){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",n).then(function(e){return e.values})},getLeaveBalances:function(n,t,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",n,t,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,n){return e.extend({all:function(e,t,a,o,s){return n.getLeaveBalances(this.processFilters(e),t,a,o,s)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,n,t){function a(t,a,o,s,i,r,c,u,l,d,m){function f(){q(),b().then(function(){P.loading.component=!1})}function p(){return o.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function h(){return s.all().then(s.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function v(){return i.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function b(){return t.all([p(),h(),v(),g(),C()]).catch(function(e){c.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function y(){return P.loading.report=!0,r.all(R,P.pagination,void 0,void 0,!1).then(function(e){P.report=_(e.list),P.reportCount=e.total}).catch(function(e){c.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function _(t){return t.map(function(t){return t=e.copy(t),t.absence_types=n.indexBy(t.absence_types,function(e){return e.id}),t})}function q(){a.$on("LeaveBalanceFilters::update",A),u.subscribe("LeaveRequest::new",T)}function C(){return m(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function T(e){A(e,R)}function A(e,n){R=n,P.pagination.page=1,D(),P.loadReportCurrentPage()}function D(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+R.type_id})}var R={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.$onInit=f,P.loadReportCurrentPage=y}t.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,n,t){function a(n,t,a,o,s,i,r){function c(){return{loadContacts:function(){return l.loadContactsForAdmin()}}}function u(e){i.info("",["

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 l,d;return{init:function(n){return d=n,l=r.init(d),d.filters.userSettings.assignedTo=e.find(d.filtersByAssignee,{type:"me"}),d.showContactDetailsLink=!0,d.showContactName=!0,d.showFilters=!0,d.showAdminFilteringHint=u,c()}}}t.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService","LeaveCalendarService",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(n,t,a,o){function s(){return{loadContacts:function(){return i.loadLookUpAndFilteredContacts()}}}n.debug("LeaveCalendarManagerController");var i,r;return{init:function(n){return r=n,i=o.init(r),r.filters.userSettings.assignedTo=e.find(r.filtersByAssignee,{type:"me"}),r.showContactName=!0,r.showFilters=!0,s()}}}t.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance","LeaveCalendarService",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,t,a){function o(){return{loadContacts:function(){return i.displaySingleContact?s.loadFilteredContacts():"admin"===i.userPermissionRole?s.loadContactsForAdmin():s.loadLookUpAndFilteredContacts()}}}e.debug("LeaveCalendarStaffController");var s,i;return{init:function(e){return i=e,s=a.init(i),i.filters.userSettings.contacts_with_leaves=!0,i.showTheseContacts=[i.contactId],i.showContactName=!0,i.showFilters=!0,i.displaySingleContact&&(i.showFilters=!1,i.lookupContacts=[{id:i.contactId}]),o()}}}t.controller("LeaveCalendarStaffController",["$log","$q","Contact","LeaveCalendarService",a])}),define("leave-absences/shared/components/leave-calendar.component",["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){function a(t,a,o,s,i,r,c,u,l,d){function m(){U().then(g).then(b).then(_).then(I).then(function(){return a.all([C(),D(),S(),W.showFilters?R():e.noop])}).then(function(){f(),y(),B()}).then(function(){W.loading.page=!1})}function f(){W.supportData.absenceTypes.push({id:"",title:"Leave",color:"#4D4D68",calculation_unit:e.chain(W.supportData.calculationUnits).find({name:"days"}).get("value").value()})}function p(){for(var e=[],t=n(W.selectedPeriod.start_date).clone().startOf("month"),a=n(W.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(L(t)),t.add(1,"month");W.months=e}function h(){return e.includes(["admin","manager"],W.userPermissionRole)}function v(e){return e.format("YYYY-MM")}function b(){s.$on("LeaveCalendar::updateFiltersByAbsenceType",function(e,n){W.supportData.absenceTypesToFilterBy=n,M(!0)})}function g(){s.$new().$watch(function(){return W.selectedMonthIndex},function(e,n){null!==n&&e!==n&&(F(),B(),M())})}function y(e){W.injectMonth=!0,N("injected").then(function(){M(e)}).then(function(){W.loading.calendar=!1})}function _(){j=t("LeaveCalendar"+e.capitalize(H)+"Controller").init(W)}function q(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return r.all().then(function(n){W.absencePeriods=e.sortBy(n,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current})}).then(p).then($)}function T(){return c.all().then(c.loadCalculationUnits)}function A(){return l.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function D(){return j.loadContacts().then(function(e){W.contacts=e})}function R(){return l.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){W.filters.optionValues.regions=e.hrjc_region,W.filters.optionValues.locations=e.hrjc_location,W.filters.optionValues.levelTypes=e.hrjc_level_type,W.filters.optionValues.departments=e.hrjc_department})}function P(){return u.all()}function S(){return a.all([T(),P(),A()]).then(function(n){W.supportData.absenceTypes=n[0],W.supportData.publicHolidays=n[1],W.supportData.calculationUnits=n[2].hrleaveandabsences_absence_type_calculation_unit,W.supportData.dayTypes=n[2].hrleaveandabsences_leave_request_day_type,W.supportData.leaveRequestStatuses=n[2].hrleaveandabsences_leave_request_status,W.supportData.toilAmounts=e.indexBy(n[2].hrleaveandabsences_toil_amounts,"value")})}function I(){var e=a.resolve();return W.injectMonth&&(e=N("destroyed"),W.injectMonth=!1),e}function L(e){return{index:v(e),month:e.month(),year:e.year(),name:e.format("MMMM"),moment:n().year(e.year()).month(e.month())}}function w(){var n=W.selectedPeriod.id;W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current}),n!==W.selectedPeriod.id&&p(),$(),B(),O("month")}function k(e){var t="previous"===e?"subtract":"add";F(n(W.selectedMonth.moment)[t](1,"month")),B(),O("month")}function O(n){n=e.includes(["contacts","period","month"],n)?n:"period",a.resolve().then(I).then("period"===n&&p).then("period"===n&&x).then("contacts"===n&&D).then("month"===n&&B).then(function(){y("contacts"===n)})}function M(e){s.$emit("LeaveCalendar::showMonth",!!e)}function $(){F(n())}function x(){F(W.months[0].moment)}function E(t){var a="previous"===t?"first":"last",o=e[a](W.months),s=n().year(o.year).month(o.month);W.monthPaginatorsAvailability[t]=!W.selectedMonth.moment.isSame(s,"month")}function B(){E("previous"),E("next")}function F(n){n&&(W.selectedMonthIndex=v(n)),W.selectedMonth=e.find(W.months,{index:W.selectedMonthIndex})}function U(){return a.all([d(i.permissions.admin.administer),d(i.permissions.ssp.manage)]).then(function(e){W.userPermissionRole=e[0]?"admin":e[1]?"manager":"staff",H=W.roleOverride?W.roleOverride:W.userPermissionRole})}function N(n){return a(function(t){var a=s.$on("LeaveCalendar::month"+e.capitalize(n),function(){a(),t()})})}o.debug("Component: leave-calendar");var j,H,W=this;W.absencePeriods=[],W.contacts=[],W.contactIdsToReduceTo=null,W.injectMonth=!1,W.months=[],W.selectedMonth={},W.selectedMonthIndex="",W.selectedPeriod=null,W.showContactName=!1,W.showFilters=!1,W.userPermissionRole="staff",W.loading={calendar:!0,page:!0},W.filters={hideOnMobile:!0,optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null},absenceTypes:{}},W.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],W.filters.userSettings.assignedTo=W.filtersByAssignee[2],W.monthPaginatorsAvailability={previous:!0,next:!0},W.supportData={absenceTypesToFilterBy:[]},W.$onInit=m,W.canManageRequests=h,W.labelPeriod=q,W.navigateToCurrentMonth=w,W.paginateMonth=k,W.refresh=O}t.component("leaveCalendar",{bindings:{contactId:"<",displaySingleContact:"0,t={from_date:{to:Q.month.days[Q.month.days.length-1].date+" 23:59:59"},to_date:{from:Q.month.days[0].date+" 00:00:00"},status_id:{IN:k()},contact_id:{IN:Q.contacts.map(function(e){return e.id})},type_id:{IN:n?Q.supportData.absenceTypesToFilterBy:e.pluck(Q.supportData.absenceTypes,"id")}};return y(),i.all(t,null,null,null,!1).then(function(e){return X={},n&&(e.list=q(e.list)),A(e.list)})}function $(){var n=Q.month.days[0].date,t=Q.month.days[Q.month.days.length-1].date;return s.get(Q.contacts.map(function(e){return e.id}),n,t).then(function(n){z=e.indexBy(n,"contact_id")})}function x(){return Q.contactIdsToReduceTo&&(Q.contacts=Q.contacts.filter(function(n){return e.includes(Q.contactIdsToReduceTo,n.contact_id)||e.find(X,function(e){return e.contact_id===n.contact_id})})),a.resolve()}function E(n){var t=L(n);X[n.contact_id]=X[n.contact_id]||{},t.forEach(function(t){e.remove(X[n.contact_id][t.date],function(e){return e.id===n.id})})}function B(){o.$emit("LeaveCalendar::monthDestroyed"),V.map(function(e){e.remove?e.remove():e()})}function F(n,t,o){var s,i;return n.contactsData[t]=n.contactsData[t]||{},i=f(t),s=!0===o?a.resolve():a.all([i.isWeekend(h(n.date)),i.isNonWorkingDay(h(n.date))]).then(function(a){e.assign(n.contactsData[t],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:S(n.date)})}),s.then(function(){return X[t]&&X[t][n.date]?X[t][n.date]:[]}).then(function(a){a=j(a),e.assign(n.contactsData[t],{leaveRequests:a,leaveRequestsToShowInCell:b(a),leaveRequestsAttributes:C(n,a)})})}function U(){return a.all(Q.month.days.map(function(e){return a.all(Q.contacts.map(function(n){return F(e,n.id)}))}))}function N(e,n){Q.currentPage=0,Q.visible=!0,(n||!G)&&O()}function j(t){return e.sortBy(t,function(e){return+n(e.from_date).format("X")+(R("half_day_pm",e,e.from_date)?1:0)})}function H(n){var t=e.find(Q.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 W(e){v(e),-1!==k().indexOf(e.status_id)&&l(e)}function Y(e){return a.all(L(e).map(function(n){return F(n,e.contact_id,!0)}))}t.debug("Component: leave-calendar-month");var G=!1,V=[],z={},X={},Q=this;Q.currentPage=0,Q.pageSize=20,Q.visible=!1,Q.showContactName=!!Q.showContactName,Q.showOnlyWithLeaveRequests=!!Q.showOnlyWithLeaveRequests,Q.$onDestroy=B,Q.$onInit=u,Q.contactsList=p,Q.getContactUrl=_}t.component("leaveCalendarMonth",{bindings:{showTheseContacts:"<",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/models/contact","common/models/session.model","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,l,d,m){function f(){a.resolve().then(_).then(C).then(function(){return y()&&"admin"!==w.role&&P()}).then(R).finally(function(){w.loading.component=!1})}function p(n){L=w.leaveRequest.status_id,e.includes(["cancel","reject","delete"],n)||"toil"===w.leaveRequest.request_type?i.open(q(n)):b(n)}function h(){return"admin"===w.role&&"public_holiday"===w.leaveRequest.request_type}function v(t){var a=w.absenceTypes[w.leaveRequest.type_id].allow_request_cancelation;return"admin"===w.role||("manager"===w.role?e.includes([k.awaitingApproval,k.moreInformationRequired],t):"3"===a?n().isBefore(w.leaveRequest.from_date):"2"===a)}function b(n){i.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return w.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(t){return t?e.assign(c.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){A(n)}}):q(n)})}})}function g(){return s.find(I).then(function(e){return e.checkIfSelfLeaveApprover()})}function y(){return I===w.leaveRequest.contact_id}function _(){e.isArray(w.leaveRequestStatuses)&&(w.leaveRequestStatuses=e.indexBy(w.leaveRequestStatuses,"value")),e.isArray(w.absenceTypes)&&(w.absenceTypes=e.indexBy(w.absenceTypes,"id"))}function q(e){var n=O[e].dialog;return{title:"Confirm "+n.title+"?",copyCancel:"Cancel",copyConfirm:n.btnLabel,classConfirm:"btn-"+n.btnClass,msg:n.msg,onConfirm:function(){return w.leaveRequest[e]().then(function(){D(e)}).catch(function(e){d.error("Error:",e)})}}}function C(){return m.get().then(function(e){I=e.contactId})}function T(e,n){e.stopPropagation(),r.openModal(n)}function A(e){r.openModal({leaveRequest:w.leaveRequest,leaveType:w.leaveRequest.request_type,selectedContactId:w.leaveRequest.contact_id,forceRecalculateBalanceChange:!0,defaultStatus:l.statusNames[M[e]]})}function D(n){var t=e.find(w.leaveRequestStatuses,function(e){return e.name===l.statusNames.awaitingApproval}).value;L===t&&u.publish("ManagerBadge:: Update Count"),u.publish("LeaveRequest::statusUpdate",{status:n,leaveRequest:w.leaveRequest})}function R(){var n=w.leaveRequestStatuses[w.leaveRequest.status_id].name,t=e.compact(e.map(O,function(t,a){return e.includes(t.allowedStatuses,n)?a:null}));!v(n)&&e.pull(t,"cancel"),"admin"!==w.role&&e.pull(t,"delete"),"staff"===w.role&&e.pull(t,"approve","reject"),"staff"!==w.role&&S(t),h()&&t.push("delete"),w.allowedActions=e.map(t,function(e){return{key:e,label:O[e].label,isDirectAction:O[e].isDirectAction}})}function P(){return g().then(function(e){e&&(w.role="admin")})}function S(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 I,L,w=this,k=l.statusNames,O={edit:{label:"Edit",allowedStatuses:[k.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[k.moreInformationRequired]},view:{label:"View",allowedStatuses:[k.approved,k.rejected,k.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[k.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[k.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[k.awaitingApproval,k.approved,k.rejected,k.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[k.awaitingApproval,k.moreInformationRequired,k.approved,k.rejected,k.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}},M={approve:"approved"};w.allowedActions=[],w.loading={component:!0},w.$onInit=f,w.action=p,w.openLeavePopup=T}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","$q","$rootScope","Contact","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService","Session"]}),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(){o.$emit("LeaveRequestPopup::addTab",C),y(),_()}function l(){C.request.comments.push({contact_id:q,leave_request_id:C.request.id,text:C.comment.text}),C.comment.text=""}function d(){return C.comment.text.length>0}function m(e){return!e.comment_id||C.canManage}function f(e){return n.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function p(){return C.request.comments.filter(function(e){return!e.toBeDeleted})}function h(e){return e===q?"Me":C.comment.contacts[e]?C.comment.contacts[e].display_name:void 0}function v(e){return C.mode===e}function b(){C.comment.text.length&&C.addComment()}function g(){var n=e.indexBy(C.request.comments,"contact_id"),t=Object.keys(n);return r.all({id:{IN:t}},{page:1,size:0}).then(function(n){C.comment.contacts=e.indexBy(n.list,"contact_id")})}function y(){return C.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),C.request.comments.length&&g()})}function _(){return C.loading.component=!0,c.get().then(function(e){q=e.contactId}).then(function(){C.loading.component=!1})}t.debug("Component: leave-request-popup-comments-tab");var q=null,C=this;C.loading={component:!0},C.comment={text:"",contacts:{}},C.$onInit=u,C.addComment=l,C.canRemoveComment=m,C.canSubmit=d,C.formatDateTime=f,C.getActiveComments=p,C.getCommentorName=h,C.isMode=v,C.onBeforeSubmit=b}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/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,n){"use strict";n.factory("WorkPatternAPI",["$log","api",function(n,t){function a(n){var t=e.clone(n);return t.workPattern=t["api.WorkPattern.get"].values[0],delete t["api.WorkPattern.get"],t}return n.debug("WorkPatternAPI"),t.extend({assignWorkPattern:function(n,t,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:n,pattern_id:t,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(t,a,o,s){return n.debug("WorkPatternAPI.getCalendar",t,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(t)?{IN:t}:t,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(n,t,o){return this.sendGET("ContactWorkPattern","get",e.assign({},t,{contact_id:n,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).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,n,t){"use strict";t.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(t,a,o,s,i){function r(n,t){return u().then(function(a){var o=this.days[c(n).valueOf()];return!!o&&e.find(a,function(e){return e.name===t}).value===o.type}.bind(this))}function c(e){return n(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(n){var t={};return n.calendar.forEach(function(e){t[c(e.date).valueOf()]=e}),e(n).omit("calendar").assign({days:t}).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,n){"use strict";n.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(n,t,a,o){return n.debug("Calendar"),t.extend({get:function(t,s,i,r){return n.debug("Calendar.get"),a.getCalendar(t,s,i,r).then(function(n){var a=n.values.map(function(e){return o.init(e)});return e.isArray(t)?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,n,t){function a(t,a,o,s,i,r,c,u,l,d,m){function f(){t("RequestModalDetails"+e.capitalize(T(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),$()])}).then(!te.isMode("create")&&S).then(Y).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(z)}).then(!te.isMode("create")&&W).then(L).then(G).then(P).then(w).then(!te.isMode("view")&&te.initWatchersExtended).catch(R).then(function(){te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.totalItems=te.balance.change.breakdown.length}).finally(function(){te.loading.tab=!1})}function p(){te.balance.closing=te.balance.opening+te.balance.change.amount}function h(e){return n(e,c.serverDateFormat).toDate()}function v(e){return n(e).format(c.serverDateFormat)}function b(e){var n;return i.resolve().then(function(){j(e),"from"===e&&N(),k("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return C(e)}).then(function(e){if(n=e.id!==te.period.id,n&&(te.period=e),!te.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 te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(z(),!n)return B();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(R).finally(q)}function g(){return z(),B()}function y(){return te.uiOptions.toDate=null,j("to"),i.resolve().then(z).then(te.setDaysSelectionModeExtended).then(q).then(!te.uiOptions.multipleDays&&B)}function _(e){te.uiOptions.times[e].loading=!0}function q(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,k("hours")&&(te.uiOptions.times[e].loading=!1)})}function C(t){var a=n(te.uiOptions[t+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function T(){return te.request?te.request.request_type:te.leaveType||null}function A(e){return n().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return X(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(H).catch(R)}function R(n){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(n)?n:[n]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?B():D()}function S(){var e=te.request.attributes();return te.uiOptions.fromDate=h(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=h(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ne.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,n){K(n)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",B))}function L(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(ee={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function w(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,n){e!==n&&(te.uiOptions.multipleDays||(Z(e),z()))})}function k(e){return te.selectedAbsenceType.calculation_unit_name===e}function O(e){return te.request.request_type===e}function M(n){return e.includes(["weekend","non_working_day","public_holiday"],n)}function $(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,n=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,n)}function B(){return X(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(H).catch(R).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function F(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return v(te.request.from_date)===v(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&n(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,j("to"))}function j(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),z(),X()}function H(e){te.balance.change=e,te.request.balance_change=e.amount,p(),F(),te.loading.balanceChange=!1}function W(){var e,t,a;te.uiOptions.fromDate?(e=n(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,t=e):(a=h(te.period.start_date),t=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=t,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=h(te.period.end_date)}function Y(){return!te.isMode("create")&&U()||te.isMode("create")&&(O("sickness")||k("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){ee&&ee.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=ee.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function V(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function z(){var e=te.uiOptions,n=e.times;te.request.from_date=e.fromDate?v(e.fromDate):null,te.request.to_date=e.toDate?v(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),(k("hours")||O("toil"))&&(te.request.from_date=te.request.from_date&&n.from.time?te.request.from_date+" "+n.from.time:null,te.request.to_date=te.request.to_date&&n.to.time?te.request.to_date+" "+n.to.time:null)}function X(){te.uiOptions.showBalance=te.canCalculateChange()}function Q(){e.forEach(ne,function(e){e()})}function J(){var e,n=te.selectedAbsenceType.calculation_unit_name;return V(),e=n!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&Y).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&z).then(q).then(B)}function K(e){return te.absenceTypes=e,V(),n(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,j("to")),G(),B()}function Z(e){var n=A(e).add(te.uiOptions.time_interval,"minutes");n.isAfter(A(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=n.format("HH:mm"),n.isAfter(A(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var ee=null,ne=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:[],numPerPage:7,totalItems:0,pageChanged:E},te.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},te.$onInit=f,te.convertDateFormatFromServer=h,te.convertDateToServerFormat=v,te.dateChangeHandler=b,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=y,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=A,te.handleError=R,te.isCalculationUnit=k,te.isLeaveType=O,te.isNotWorkingDay=M,te.performBalanceChangeCalculation=B,te.setRequestDateTimesAndDateTypes=z,te.updateEndTimeInputMinTime=Z,te.$onDestroy=Q}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(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",w),y(),a.all([A(),C()]).then(_).finally(function(){w.filesLoaded=!0})}function m(){return w.fileUploader&&w.fileUploader.queue.length>0}function f(){return w.getFilesAmount()0?S.map(function(e){return e.label}).join(", "):""}function C(){return w.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function T(){return a.all(S.map(function(e){return l.getMimeTypeFor(e.label).then(function(n){L[e.label]=n})})).catch(function(){L=null})}function A(){return c.valuesOf("safe_file_extension").then(function(e){S=e})}function D(e){return!e.attachment_id||w.canManage}function R(){e.forEach(I,function(e){e()})}function P(e,n){w.fileUploader.queue&&w.fileUploader.queue.length>0?w.fileUploader.uploadAll({entityID:w.request.id}).then(function(){n()}).catch(n):n()}t.debug("Component: leave-request-popup-files-tab");var S=[],I=[],L={},w=Object.create(this);return w.filesLoaded=!1,w.fileUploader=null,w.today=Date.now(),w.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",w.userDateFormat=i.DATE_FORMAT,w.$onDestroy=R,w.$onInit=d,w.canRemoveAttachment=D,w.canSubmit=m,w.canUploadMore=f,w.formatDateTime=p,w.getAuthorName=h,w.getFilesAmount=v,w.listFileTypes=q,w}t.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function n(e,n,t){function a(){s=t.parse(),s.openModal&&o({leaveType:s.openModal,selectedContactId:i.selectedContactId})}function o(e){n.openModal(e)}e.debug("Component: leave-request-record-actions");var s,i=this;i.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],i.$onInit=a,i.openLeavePopup=o}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",n]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,n){function t(n,t,a,o,s,i,r,c,u,l,d,m){"use strict";function f(){s(r.permissions.admin.administer).then(function(e){H.isAdmin=e,t.all([A(),D(),k(),P(),L(),I(),O()]).then(function(){H.loading.page=!1,R()}),N()})}function p(){H.filters.leaveRequest.contact_id=null,H.refresh()}function h(){var e=H.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function v(e){return"all"===e.name||""===e?H.leaveRequests.filter.list.length:H.leaveRequests.filter.list.filter(function(n){return n.status_id===e.value}).length}function b(n){return e.find(H.absenceTypes,{id:n})}function g(e){return new Array(e||0)}function y(n){var t=e.find(H.leaveRequestStatuses,function(e){return e.value===n});return t?t.label:null}function _(e){switch(e){case r.statusNames.approved:return"badge-success";case r.statusNames.rejected:return"badge-danger";case r.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function q(n){return e.find(H.leaveRequestStatuses,function(e){return e.name===n}).value}function C(n){var t=e.find(H.filteredUsers,function(e){return e.id===n});return t?t.display_name:null}function T(e){return e.current?"Current Period ("+e.title+")":e.title}function A(){return c.all().then(function(n){H.absencePeriods=e.sortBy(n,"start_date"),H.filters.leaveRequest.selectedPeriod=e.find(H.absencePeriods,function(e){return!!e.current})})}function D(){return u.all().then(u.loadCalculationUnits).then(function(e){H.absenceTypes=e})}function R(e){return(H.isAdmin?o.all(h()):o.leaveManagees(H.contactId,h())).then(function(n){return H.filteredUsers=H.isAdmin?n.list:n,e?S(e):t.all([S("table"),S("filter")])}).then(function(){H.filters.leaveRequest.leaveStatus!==W&&0===H.leaveRequests.table.list.length&&H.refresh(1,!0)})}function P(){return i.valuesOf("hrjc_department").then(function(e){H.departments=e})}function S(e){var n="filter"!==e,t="table"===e?e:"content",a="filter"===e?{size:0}:H.pagination,o="filter"===e?{return:["status_id"]}:{};return H.loading[t]=!0,l.all(w(n),a,"from_date DESC",o,!1).then(function(n){H.leaveRequests[e]=n}).catch(function(){H.leaveRequests[e].list=[]}).finally(function(){H.loading[t]=!1})}function I(){return i.valuesOf("hrjc_level_type").then(function(e){H.levelTypes=e})}function L(){return i.valuesOf("hrjc_location").then(function(e){H.locations=e})}function w(n){var t=H.filters.leaveRequest;return{contact_id:$(),managed_by:H.isAdmin&&"me"!==t.assignedTo.type?void 0:H.contactId,status_id:E(n),type_id:t.selectedAbsenceTypes?t.selectedAbsenceTypes.id:{IN:e.pluck(H.absenceTypes,"id")},from_date:{from:t.selectedPeriod.start_date},to_date:{to:t.selectedPeriod.end_date},unassigned:"unassigned"===t.assignedTo.type||void 0}}function k(){return i.valuesOf("hrjc_region").then(function(e){H.regions=e})}function O(){return i.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){H.leaveRequestStatuses=e.concat(H.leaveRequestStatuses)})}function M(e){d.openModal(e)}function $(){return H.filteredUsers.length>0&&H.filters.leaveRequest.contact_id?H.filters.leaveRequest.contact_id:{IN:H.filteredUsers.map(function(e){return e.id})}}function x(e){var n=[q(r.statusNames.moreInformationRequired),q(r.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(n)),e}function E(e){var n=H.filters.leaveRequest,t=[];if(e&&n.leaveStatus&&n.leaveStatus.value&&t.push(n.leaveStatus.value),n.pending_requests&&(t=x(t)),t.length)return{IN:t}}function B(e,n,t){e="number"==typeof e?e:1,n&&(H.filters.leaveRequest.leaveStatus=W),(e<=H.totalNoOfPages()||0===H.totalNoOfPages())&&(H.pagination.page=e,R(t))}function F(e){H.filters.leaveRequest.leaveStatus=e,H.refresh(1,!1,"table")}function U(e){H.filters.leaveRequest.assignedTo=e,H.refresh()}function N(){m.subscribe("LeaveRequest::updatedByManager",function(){H.refresh()}),m.subscribe("LeaveRequest::new",function(){H.refresh()}),m.subscribe("LeaveRequest::edit",function(){H.refresh()}),m.subscribe("LeaveRequest::delete",function(){H.refresh()}),m.subscribe("LeaveRequest::statusUpdate",function(){H.refresh()})}function j(){return Math.ceil(H.leaveRequests.table.total/H.pagination.size)}n.debug("Component: manage-leave-requests");var H=this,W={name:"all",label:"All"};H.absencePeriods=[],H.absenceTypes=[],H.filteredUsers=[],H.isFilterExpanded=!1,H.isAdmin=!1,H.leaveRequests={table:{list:[]},filter:{list:[]}},H.leaveRequestStatuses=[W],H.loading={content:!0,page:!0,table:!0},H.pagination={page:1,size:7},H.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],H.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:H.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:H.filtersByAssignee[0]}},H.$onInit=f,H.clearStaffSelection=p,H.countLeaveRequestByStatus=v,H.getAbsenceTypeByID=b,H.getArrayOfSize=g,H.getLeaveStatusByValue=y,H.getNavBadge=_,H.getUserNameByID=C,H.labelPeriod=T,H.openLeavePopup=M,H.refresh=B,H.refreshWithFilter=F,H.refreshWithFilterByAssignee=U,H.totalNoOfPages=j}n.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:t}),t.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,n=!!e.from_date&&!!e.to_date,t=i.selectedAbsenceType.calculation_unit_name;return"days"===t?n=n&&!!e.from_date_type&&!!e.to_date_type:"hours"===t&&(n=n&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),n}function d(){return i.canCalculateChange()}function m(n,t){var a=i.uiOptions.times[n],o=e.clone(t.time_from),s=e.clone(t.time_to);i.uiOptions.multipleDays||("from"===n&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===n&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===n?a.max:a.min}function f(n,t){return n?(n=i.convertDateToServerFormat(n),v(n).then(function(t){return t?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(n,i.requestDayTypes).then(function(n){return n.length?n:i.requestDayTypes.filter(function(n){return e.includes(["all_day","half_day_am","half_day_pm"],n.name)})})}).then(function(e){return S(t,e),e})):o.reject([])}function p(e,t){return e=n(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(n){return n.name===e}):[]})}function h(e,t){return n.duration(t).subtract(n.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function y(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,n){i.isCalculationUnit("days")||+e==+n||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function _(e){var t=n(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,t)<=0||h(a.max,t)>=0)&&(t="from"===e?a.min:a.max),i.uiOptions.times[e].time=t}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],n=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(R)).then(function(){["from","to"].forEach(function(e){_(e),L(e),n[e].amount=Math.min(i.request[e+"_date_amount"],n[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function C(){["from","to"].forEach(function(e){y(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(n,t){i.isCalculationUnit("days")||n===t||(i.setRequestDateTimesAndDateTypes(),n&&L(e,!0))})}function A(e,n){return f(e,n).then(function(){i.loading[n+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return R(e).then(function(){L(e,!0)})})}function R(e){var n=i.uiOptions[e+"Date"],t=!i.uiOptions.multipleDays;return n?i.request.getWorkDayForDate(i.convertDateToServerFormat(n)).then(function(n){O[e]=n,m(e,n),t&&"from"===e&&m("to",n)}).catch(function(n){return O[e]={},i.handleError(n)}).finally(function(){i.uiOptions.times[e].loading=!1,t&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(n){var t=i.uiOptions.times[n];i["request"+e.startCase(n)+"DayTypes"]=[],t.time="",t.min="00:00",t.max="00:00",t.amount="0",t.maxAmount="0"}function S(n,t){var a="request"+e.startCase(n)+"DayTypes";i[a]=t,i.isMode("create")&&(i.request[n+"_date_type"]=i[a][0].value)}function I(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),R("from").then(function(){L("from",!0)})):o.resolve()}function L(e,n){var t=i.uiOptions,a=t.multipleDays?e:"from",o=t.times[a],s=t.multipleDays&&"to"===a?o.min:t.times.from.time,r=t.multipleDays&&"from"===a?o.max:t.times.to.time,c=O[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,n&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function k(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?R("from").then(function(){L("from",!0)}):o.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=k,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=I}t.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(n){var t=r.request.getDocumentArray();return!!e.find(t,function(e){return e===n})}function d(n){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===n})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(n){return i.valuesOf("hrleaveandabsences_sickness_reason",n).then(function(n){r.sicknessReasons=e.indexBy(n,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}t.debug("RequestModalDetailsSicknessController"),n("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}n.controller("RequestModalDetailsSicknessController",t),t.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=n.duration(n(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,n=!c.uiOptions.multipleDays&&!!c.request.from_date,t=n||e,a=N.from_date!==c.request.from_date||N.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&t&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,n=c.request;return b({hasErrors:e?!n.to_date&&!n.from_date:!n.from_date,label:e?"To Date":"From Date",value:n.to_date})}function b(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(n(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&H.hasExpirationFromAdminSettings,n=H.hasPreviousExpirationDate,t=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=t&&(a||e||n)}function y(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",_().then(g).then(C).then(S)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue -},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&k(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function P(){c.isMode("view")||(T(),A(),R())}function S(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function I(){return l(),O(),F()}function L(){return $(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:O(),F()}function w(e){c.uiOptions.times[e].time=""}function k(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){N=e.cloneDeep(c.request.attributes())}function $(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?k():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){S(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function U(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var N,j=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=I,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=w,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=U,function(){M(),$(),B(),!c.isMode("create")&&y()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,t,a){return e.debug("AbsencePeriodInstance"),t.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var t=n();return e.current=!1,n(e.start_date).isSameOrBefore(t,"day")&&n(e.end_date).isSameOrAfter(t,"day")&&(e.current=!0),e},isInPeriod:function(e){var t=a.DATE_FORMAT.toUpperCase(),o=n(e,t);return n(this.start_date).isSameOrBefore(o)&&n(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,n){return e.debug("AbsencePeriodAPI"),n.extend({all:function(n){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,t,a,o,s){return e.debug("AbsencePeriod"),t.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=n().format(s.serverDateFormat),t={start_date:{"<=":e},end_date:{">=":e}};return a.all(t).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,n,t){"use strict";t.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(t,a,o){return t.debug("AbsenceTypeAPI"),a.extend({all:function(n){return t.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(n||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return t.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:n(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,n){return e.debug("AbsenceTypeInstance"),n.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,n){"use strict";n.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(n,t,a,o,s,i){return n.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,n,t){return s.calculateToilExpiryDate(e,n,t)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(n){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(t){return t=e.indexBy(t,"value"),e.map(n,function(n){return e.assign(n,{calculation_unit_label:t[n.calculation_unit].label,calculation_unit_name:t[n.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,n){return e.debug("EntitlementLogAPI"),n.extend({all:function(n){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",n,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,n,t){return e.debug("EntitlementInstance"),n.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return t.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,n){"use strict";n.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(n,t,a,o,s){return n.debug("Entitlement"),t.extend({all:function(e,n){return a.all(this.processFilters(e),n).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(n,t){return a.breakdown(n).then(function(n){return t?(t.map(function(t){var a=e.find(n,function(e){return e.id===t.id});return a&&(t.breakdown=a.breakdown),t}),t):n.map(function(e){return o.init(e,!0)})})},logs:function(n){return n=e.cloneDeep(n||{}),n.contact_id&&(n["entitlement_id.contact_id"]=n.contact_id,delete n.contact_id),n.period_id&&(n["entitlement_id.period_id"]=n.period_id,delete n.period_id),n.return=n.return||[],n.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(n)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,t,a){return e.debug("LeaveRequestAPI"),t.extend({all:function(n,t,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return n&&n.contact_id&&n.contact_id.IN&&0===n.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",n,t,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return t.contact_id&&t.period_id||o.reject("contact_id and period_id are mandatory"),t=n.defaults(t,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",t,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange",t),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){return e.values.breakdown=n.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,n){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:n.toString()},!1)},create:function(n){return e.debug("LeaveRequestAPI.create",n),this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,attachment_id:t}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,t){return t=n.assign({},t,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",t).then(function(e){return e.values})},find:function(n){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:n},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",t,!1).then(function(e){return e.values})},getComments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",t,!1).then(function(e){return e.values})},isManagedBy:function(n,t){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:n,contact_id:t}).then(function(e){return e.values})},isValid:function(t){e.debug("LeaveRequestAPI.isValid",t);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",t).then(function(e){e.count>0?o.reject(n(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,text:t.text,contact_id:t.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(n){return e.debug("LeaveRequestAPI.update",n),n.id?this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,n,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(t,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var n=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=n,t.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return t.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function f(e){return n.duration(e.time_to).subtract(n.duration(e.time_from)).asHours()}function p(n){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return e.find(t,function(e){return e.name===n})})}function h(n){var a=e.cloneDeep(n),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return t.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(n){return s.amount=n[0].time_from?Math.min(this.from_date_amount,f(n[0])):0,o&&(i.amount=n[1].time_from?Math.min(this.to_date_amount,f(n[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,n){return e+n.amount},0),a}.bind(this))}function v(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(n){return function(){return r.saveComment(e,n)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),t.all(n)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(n){var t=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===n&&e.pull(t,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,t)).then(function(e){return"hours"===n?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return t.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(n){if(n.comment_id)return void(n.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return n.created_at===e.created_at&&n.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(n){return{amount:e.reduce(n.values,function(e,n){return e+parseFloat(n.amount)},0),breakdown:n.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return t.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):a(s.permissions.admin.administer).then(function(n){return n?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):t.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,n,t,a){return e.debug("LeaveRequest"),n.extend({all:function(e,n,o,s,i){return t.all(this.processFilters(e),n,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return t.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return t.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,n){return e.debug("PublicHolidayAPI"),n.extend({all:function(n){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,n){return e.debug("PublicHolidayInstance"),n.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,n){"use strict";n.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(n,t,a,o,s){return n.debug("PublicHoliday"),t.extend({all:function(e){return n.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(t){n.debug("PublicHoliday.isPublicHoliday",t);var o=e(t).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,y,_,q,C){function T(e){"days"===Ue.selectedAbsenceType.calculation_unit_name?delete Ue.request[e+"_date_amount"]:delete Ue.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return ke.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function R(){var e=Ue.requestStatuses[y.statusNames.awaitingApproval].value;$e.status_id===e&&e!==Ue.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!Ue.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ue.isMode("edit")&&(e=e&&(G()||S())),Ue.canManage&&Ue.requestStatuses&&(e=e&&!!Ue.getStatusFromValue(Ue.newStatusOnSave)),(e=e&&!!Ue.period.id)&&!Ue.isMode("view")}function w(){Ue.isSelfRecord&&!Ue.isSelfLeaveApprover?Ue.request.status_id=Ue.requestStatuses[y.statusNames.awaitingApproval].value:Ue.canManage&&(Ue.request.status_id=Ue.newStatusOnSave||Ue.request.status_id)}function k(){if(Ue.isMode("edit")&&!Ue.isRole("staff")&&"toil"!==j())return Ue.request.calculateBalanceChange(Ue.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ue.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==j()&&!Ue.request.change_balance}function M(){Ue.errors=[]}function $(){return Ue.request.create().then(Pe).then(function(){ge("LeaveRequest::new")})}function x(){se()&&!Ue.isRole("staff")&&(Ue.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ue.request.delete().then(function(){Ue.dismissModal(),d.publish("LeaveRequest::delete",Ue.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(Ue.getStatusFromValue(Ue.request.status_id).name)}function N(e){return t.map(Oe[e],function(e){return Ue.requestStatuses[e]})}function j(){return Ue.request?Ue.request.request_type:Ue.leaveType||null}function H(){return!Ue.request||e.equals({},Ue.requestStatuses)?[]:Ue.request.status_id?U():N("none")}function W(e){return t.find(Ue.requestStatuses,function(n){return n.value===e})}function Y(e){Ue.errors=t.isArray(e)?e:[e],Ue.loading.absenceTypes=!1,Ue.submitting=!1}function G(){return!e.equals($e,Ue.request.attributes())||Ue.canManage&&Ue.newStatusOnSave}function V(){return Ue.postContactSelection=!0,Ue.staffMemberSelectionComplete=!1,Ue.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ue.isMode("edit")?Te:t.noop).then(function(){Ue.postContactSelection=!1,Ue.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Oe.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ue.canManage=Ue.isRole("manager")||Ue.isRole("admin")}function Q(){return Ue.canManage?f.find(Ue.request.contact_id).then(function(e){Ue.contactName=e.display_name}):o.resolve()}function J(){Ue.isRole("admin")&&Ue.isSelfRecord&&(Ue.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+ke.id==+t.get(Ue,"leaveRequest.contact_id"),a=!t.get(Ue,"leaveRequest.id");Ue.isSelfRecord=e&&a||n}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ue.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Se),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ue.request=Ue.leaveRequest||null,e=j(),n=Ue.initRequestAttributes(),"leave"===e?Ue.request=g.init(n):"sickness"===e?Ue.request=_.init(n):"toil"===e&&(Ue.request=q.init(n))}function ne(){var e={};return Ue.request?e=Ue.request.attributes():Ue.canManage||(e={contact_id:ke.id}),e}function te(){return Be="staff",ae().then(Ue.isSelfRecord&&!Ue.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ue.defaultStatus?Ue.newStatusOnSave=Ue.requestStatuses[y.statusNames[Ue.defaultStatus]].value:(Ue.isRole("admin")||Ue.isMode("create")&&Ue.isRole("manager"))&&(Ue.newStatusOnSave=Ue.requestStatuses[y.statusNames.approved].value)}function se(){return!Ue.request.status_id||!t.includes(["cancelled","rejected"],W(Ue.request.status_id).name)}function ie(e){var n=Ue.getStatusFromValue(Ue.request.status_id);return!!n&&n.name===e}function re(e){return Ue.request&&Ue.request.request_type===e}function ce(e){return Ue.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ue.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){we={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ue.loading.entitlements=!0,v.all({contact_id:Ue.request.contact_id,period_id:Ue.period.id,type_id:{IN:we.ids}},!0).finally(function(){Ue.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){ke=e})}function he(){return Ue.selectedContactId?f.find(Ue.selectedContactId).then(function(e){Ue.managedContacts=[e]}):Ue.isRole("admin")?f.all().then(function(e){Ue.managedContacts=t.remove(e.list,function(e){return e.id!==ke.id})}):ke.leaveManagees().then(function(e){Ue.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ue.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){R(),d.publish(e,Ue.request),Ue.errors=[],Ue.dismissModal()}function ye(){["from","to"].forEach(function(e){Ue.request[e+"_date"]=$e[e+"_date"]})}function _e(e){if(Ue.absenceTypes=be(we.types,e),!Ue.absenceTypes.length)return o.reject(Ee)}function qe(){Ue.period=t.find(Ue.absencePeriods,function(e){return Ue.isMode("create")?e.current:ue(Ue.request,e)})}function Ce(){Ue.isMode("create")?(Ue.selectedAbsenceType=Ue.absenceTypes[0],Ue.request.type_id=Ue.selectedAbsenceType.id):Ue.selectedAbsenceType=t.find(Ue.absenceTypes,function(e){return e.id===Ue.request.type_id})}function Te(){$e=e.copy(Ue.request.attributes())}function Ae(){var e;Ue.request.id?(e=[Ue.requestStatuses[y.statusNames.approved].value,Ue.requestStatuses[y.statusNames.adminApproved].value,Ue.requestStatuses[y.statusNames.rejected].value,Ue.requestStatuses[y.statusNames.cancelled].value],Ue.mode="edit",Ue.isRole("staff")&&e.indexOf(Ue.request.status_id)>-1&&(Ue.mode="view")):Ue.mode="create"}function De(){var e=Ue.request.status_id;if(!Ue.isMode("view")&&!Ue.submitting)return Ue.submitting=!0,w(),A(),Ue.request.isValid().then(se()&&k).then(x).then(O()&&ye).then(Re).then(function(){return Ue.isMode("edit")?Le():$()}).catch(function(n){Ue.request.status_id=e,n&&Y(n)}).finally(function(){Ue.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise} -function Se(){xe.forEach(function(e){e()})}function Ie(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ue.request.update().then(Pe).then(function(){Ue.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ue.isRole("staff")||Ue.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var we,ke,Oe={},Me=0,$e={},xe=[],Ee="No entitlement",Be="",Fe=[],Ue=t.assign(this,m);Ue.absencePeriods=[],Ue.absenceTypes=[],Ue.canManage=!1,Ue.contactName=null,Ue.errors=[],Ue.isSelfLeaveApprover=!1,Ue.loading={absenceTypes:!0,entitlements:!0},Ue.managedContacts=[],Ue.mode="",Ue.newStatusOnSave=null,Ue.period={},Ue.postContactSelection=!1,Ue.requestStatuses={},Ue.selectedAbsenceType={},Ue.staffMemberSelectionComplete=!1,Ue.submitting=!1,Ue.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ue.canChangeAbsenceType=I,Ue.canSubmit=L,Ue.closeAlert=M,Ue.deleteLeaveRequest=E,Ue.dismissModal=B,Ue.getStatuses=H,Ue.getStatusFromValue=W,Ue.initAfterContactSelection=V,Ue.initRequestAttributes=ne,Ue.isLeaveStatus=ie,Ue.isLeaveType=re,Ue.isMode=ce,Ue.isRole=le,Ue.submit=De,Ue.updateAbsenceType=Ie,function(){Ue.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ue.canManage&&!Ue.isMode("edit")&&he()}).then(function(){if(Ue.selectedContactId&&(Ue.request.contact_id=Ue.selectedContactId),Ue.request.contact_id)return Ue.initAfterContactSelection()}).catch(Y).finally(function(){Ue.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,n){"use strict";function t(e,n,t,a,o,s,i,r,c){function u(e){return r.get().then(function(n){return e.roleOf(n.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:n.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(n){n?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}n.factory("LeavePopup",t),t.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(n){return n.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","common/lodash","leave-absences/admin-dashboard/modules/settings"],function(e,n){function t(e){e.settings.ga={userId:n.get(CRM,"vars.session.contact_id")},e.withAutoBase(!0)}return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","$analyticsProvider","settings",function(e,n,a,o,s,i,r){var c={format:["DateFormat",function(e){return e.getDateFormat()}]};n.defaults.stripTrailingSlashes=!1,o.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",t(i),s.debugEnabled(r.debug),a.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:c}).state("calendar",{url:"/calendar",template:'',resolve:c}).state("leave-balances",{url:"/leave-balances",template:"",resolve:c})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function n(e,n){e.debug("Component: admin-dashboard-container"),n.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",n]})}),define("leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component",[],function(){function e(e,n,t,a){function o(){i(),s()}function s(){return t("can administer calendar feeds").then(function(e){c.canCreateNewFeed=!!e})}function i(){return c.loading.feeds=!0,e.all().then(function(e){c.feeds=e}).finally(function(){c.loading.feeds=!1})}function r(e,t){n.open(e,t)}var c=this;c.canCreateNewFeed=!1,c.feeds=[],c.loading={feeds:!1},c.$onInit=o,c.openLinkModal=r}return e.$inject=["CalendarFeed","CalendarFeedsLinkModal","checkPermissions","shared-settings"],{__name:"calendarFeedsDropdownButton",bindings:{dropdownPosition:"@"},controller:e,controllerAs:"dropdownButton",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.html"}]}}),define("leave-absences/calendar-feeds/calendar-feeds.core",["common/angular","leave-absences/shared/modules/shared-settings"],function(e){e.module("calendar-feeds.core",["leave-absences.settings"])}),define("leave-absences/calendar-feeds/services/apis/calendar-feed.api",["common/lodash"],function(e){"use strict";function n(e,n,t){function a(){return this.sendGET("LeaveRequestCalendarFeedConfig","get",{is_active:!0}).then(function(e){return e.values})}return e.debug("CalendarFeedAPI"),t.extend({all:a})}return n.__name="CalendarFeedAPI",n.$inject=["$log","$q","api"],n}),define("leave-absences/calendar-feeds/services/models/calendar-feed.model",[],function(){"use strict";function e(e,n,t){function a(){return n.all().then(function(e){return e.map(function(e){return t.init(e)})})}return e.extend({all:a})}return e.__name="CalendarFeed",e.$inject=["Model","CalendarFeedAPI","CalendarFeedInstance"],e}),define("leave-absences/calendar-feeds/services/models/calendar-feed.instance",[],function(){"use strict";function e(e){return e.extend({})}return e.__name="CalendarFeedInstance",e.$inject=["ModelInstance"],e}),define("leave-absences/calendar-feeds/calendar-feeds.models",["common/angular","leave-absences/calendar-feeds/services/apis/calendar-feed.api","leave-absences/calendar-feeds/services/models/calendar-feed.model","leave-absences/calendar-feeds/services/models/calendar-feed.instance","common/models/model","common/services/api"],function(e,n,t,a){e.module("calendar-feeds.models",["common.apis","common.models"]).factory(n.__name,n).factory(t.__name,t).factory(a.__name,a)}),define("leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component",["common/lodash"],function(e){return{__name:"calendarFeedsLinkModal",bindings:{dismiss:"<",url:"<",title:"<"},controller:e.noop,controllerAs:"linkModal",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/link-modal/components/calendar-feeds-link-modal.html"}]}}),define("leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service",[],function(){function e(e,n,t){function a(e,a){var s=o(),i=t+"civicrm/calendar-feed?hash="+a;n.open({controllerAs:"modal",size:"md",template:'',controller:["$uibModalInstance","title","url",function(e,n,t){this.dismiss=e.dismiss,this.title=n,this.url=t}],appendTo:s,resolve:{title:function(){return e},url:function(){return i}}})}function o(){var n=e.find("#bootstrap-theme");return 0===n.length&&(n=e.find("body")),n.eq(0)}return{open:a}}return e.__name="CalendarFeedsLinkModal",e.$inject=["$document","$uibModal","HOST_URL"],e}),define("leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive",["common/lodash"],function(e){function n(n,t){function a(e,t,a,o){function s(){r(),u()}function i(){l[0].setSelectionRange(0,0),l.blur()}function r(){c(),document.execCommand("copy"),i()}function c(){l.focus(),l[0].setSelectionRange(0,l.val().length)}function u(){m.justCopied=!0,d&&n.cancel(d),d=n(function(){m.justCopied=!1},2e3)}var l,d,m=e.input;m.model=o.model,m.justCopied=!1,m.copy=s,m.selectInputText=c,function(){l=t.find("input")}()}var o=t.sourcePath+"calendar-feeds/link-modal/directives/input-with-copy-button.html";return{controller:e.noop,controllerAs:"input",link:a,restrict:"E",scope:{},templateUrl:o,require:{model:"^ngModel"}}}return n.__name="inputWithCopyButton",n.$inject=["$timeout","shared-settings"],n}),define("leave-absences/calendar-feeds/link-modal/link-modal.core",["common/angular","common/angularBootstrap"],function(e){e.module("calendar-feeds.link-modal.core",["ui.bootstrap"])}),function(e){define("leave-absences/calendar-feeds/link-modal/link-modal.constants",["common/angular"],function(n){"use strict";n.module("calendar-feeds.link-modal.constants",[]).constant("HOST_URL",e.absoluteUrl("/"))})}(Drupal),define("leave-absences/calendar-feeds/link-modal/link-modal.module",["common/angular","leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component","leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service","leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/link-modal/link-modal.core","leave-absences/calendar-feeds/link-modal/link-modal.constants"],function(e,n,t,a){e.module("calendar-feeds.link-modal",["calendar-feeds.core","calendar-feeds.link-modal.core","calendar-feeds.link-modal.constants"]).component(n.__name,n).directive(a.__name,a).factory(t.__name,t)}),define("leave-absences/calendar-feeds/dropdown-button/dropdown-button.module",["common/angular","leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component","common/services/check-permissions","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/calendar-feeds.models","leave-absences/calendar-feeds/link-modal/link-modal.module"],function(e,n){e.module("calendar-feeds.dropdown-button",["common.services","calendar-feeds.core","calendar-feeds.models","calendar-feeds.link-modal"]).component(n.__name,n)}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/angulartics","common/angulartics-google-tag-manager","common/angularUiRouter","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container","leave-absences/calendar-feeds/dropdown-button/dropdown-button.module"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","angulartics","angulartics.google.tagmanager","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components","calendar-feeds.dropdown-button"]).run(["$log","$rootScope","shared-settings","settings",function(e,n,t,a){e.debug("app.run"),n.sharedPathTpl=t.sharedPathTpl,n.settings=a}]),e}),function(e,n){var t=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";n.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":t+"/shared","leave-absences/admin-dashboard":t+"/admin-dashboard"}}),n(["leave-absences/shared/config"],function(){n(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); +},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&k(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function P(){c.isMode("view")||(T(),A(),R())}function S(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function I(){return l(),O(),F()}function L(){return $(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:O(),F()}function w(e){c.uiOptions.times[e].time=""}function k(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){N=e.cloneDeep(c.request.attributes())}function $(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?k():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){S(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function U(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var N,j=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=I,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=w,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=U,function(){M(),$(),B(),!c.isMode("create")&&y()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,t,a){return e.debug("AbsencePeriodInstance"),t.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var t=n();return e.current=!1,n(e.start_date).isSameOrBefore(t,"day")&&n(e.end_date).isSameOrAfter(t,"day")&&(e.current=!0),e},isInPeriod:function(e){var t=a.DATE_FORMAT.toUpperCase(),o=n(e,t);return n(this.start_date).isSameOrBefore(o)&&n(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,n){return e.debug("AbsencePeriodAPI"),n.extend({all:function(n){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,t,a,o,s){return e.debug("AbsencePeriod"),t.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=n().format(s.serverDateFormat),t={start_date:{"<=":e},end_date:{">=":e}};return a.all(t).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,n,t){"use strict";t.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(t,a,o){return t.debug("AbsenceTypeAPI"),a.extend({all:function(n){return t.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(n||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return t.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:n(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,n){return e.debug("AbsenceTypeInstance"),n.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,n){"use strict";n.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(n,t,a,o,s,i){return n.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,n,t){return s.calculateToilExpiryDate(e,n,t)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(n){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(t){return t=e.indexBy(t,"value"),e.map(n,function(n){return e.assign(n,{calculation_unit_label:t[n.calculation_unit].label,calculation_unit_name:t[n.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,n){return e.debug("EntitlementLogAPI"),n.extend({all:function(n){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",n,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,n,t){return e.debug("EntitlementInstance"),n.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return t.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,n){"use strict";n.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(n,t,a,o,s){return n.debug("Entitlement"),t.extend({all:function(e,n){return a.all(this.processFilters(e),n).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(n,t){return a.breakdown(n).then(function(n){return t?(t.map(function(t){var a=e.find(n,function(e){return e.id===t.id});return a&&(t.breakdown=a.breakdown),t}),t):n.map(function(e){return o.init(e,!0)})})},logs:function(n){return n=e.cloneDeep(n||{}),n.contact_id&&(n["entitlement_id.contact_id"]=n.contact_id,delete n.contact_id),n.period_id&&(n["entitlement_id.period_id"]=n.period_id,delete n.period_id),n.return=n.return||[],n.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(n)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,t,a){return e.debug("LeaveRequestAPI"),t.extend({all:function(n,t,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return n&&n.contact_id&&n.contact_id.IN&&0===n.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",n,t,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return t.contact_id&&t.period_id||o.reject("contact_id and period_id are mandatory"),t=n.defaults(t,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",t,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange",t),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){return e.values.breakdown=n.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,n){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:n.toString()},!1)},create:function(n){return e.debug("LeaveRequestAPI.create",n),this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,attachment_id:t}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,t){return t=n.assign({},t,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",t).then(function(e){return e.values})},find:function(n){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:n},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",t,!1).then(function(e){return e.values})},getComments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",t,!1).then(function(e){return e.values})},isManagedBy:function(n,t){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:n,contact_id:t}).then(function(e){return e.values})},isValid:function(t){e.debug("LeaveRequestAPI.isValid",t);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",t).then(function(e){e.count>0?o.reject(n(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,text:t.text,contact_id:t.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(n){return e.debug("LeaveRequestAPI.update",n),n.id?this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,n,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(t,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var n=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=n,t.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return t.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function f(e){return n.duration(e.time_to).subtract(n.duration(e.time_from)).asHours()}function p(n){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return e.find(t,function(e){return e.name===n})})}function h(n){var a=e.cloneDeep(n),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return t.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(n){return s.amount=n[0].time_from?Math.min(this.from_date_amount,f(n[0])):0,o&&(i.amount=n[1].time_from?Math.min(this.to_date_amount,f(n[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,n){return e+n.amount},0),a}.bind(this))}function v(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(n){return function(){return r.saveComment(e,n)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),t.all(n)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(n){var t=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===n&&e.pull(t,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,t)).then(function(e){return"hours"===n?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return t.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(n){if(n.comment_id)return void(n.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return n.created_at===e.created_at&&n.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(n){return{amount:e.reduce(n.values,function(e,n){return e+parseFloat(n.amount)},0),breakdown:n.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return t.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):a(s.permissions.admin.administer).then(function(n){return n?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):t.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,n,t,a){return e.debug("LeaveRequest"),n.extend({all:function(e,n,o,s,i){return t.all(this.processFilters(e),n,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return t.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return t.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,n){return e.debug("PublicHolidayAPI"),n.extend({all:function(n){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,n){return e.debug("PublicHolidayInstance"),n.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,n){"use strict";n.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(n,t,a,o,s){return n.debug("PublicHoliday"),t.extend({all:function(e){return n.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(t){n.debug("PublicHoliday.isPublicHoliday",t);var o=e(t).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,y,_,q,C){function T(e){"days"===Ue.selectedAbsenceType.calculation_unit_name?delete Ue.request[e+"_date_amount"]:delete Ue.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return ke.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function R(){var e=Ue.requestStatuses[y.statusNames.awaitingApproval].value;$e.status_id===e&&e!==Ue.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!Ue.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ue.isMode("edit")&&(e=e&&(G()||S())),Ue.canManage&&Ue.requestStatuses&&(e=e&&!!Ue.getStatusFromValue(Ue.newStatusOnSave)),(e=e&&!!Ue.period.id)&&!Ue.isMode("view")}function w(){Ue.isSelfRecord&&!Ue.isSelfLeaveApprover?Ue.request.status_id=Ue.requestStatuses[y.statusNames.awaitingApproval].value:Ue.canManage&&(Ue.request.status_id=Ue.newStatusOnSave||Ue.request.status_id)}function k(){if(Ue.isMode("edit")&&!Ue.isRole("staff")&&"toil"!==j())return Ue.request.calculateBalanceChange(Ue.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ue.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==j()&&!Ue.request.change_balance}function M(){Ue.errors=[]}function $(){return Ue.request.create().then(Pe).then(function(){ge("LeaveRequest::new")})}function x(){se()&&!Ue.isRole("staff")&&(Ue.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ue.request.delete().then(function(){Ue.dismissModal(),d.publish("LeaveRequest::delete",Ue.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(Ue.getStatusFromValue(Ue.request.status_id).name)}function N(e){return t.map(Oe[e],function(e){return Ue.requestStatuses[e]})}function j(){return Ue.request?Ue.request.request_type:Ue.leaveType||null}function H(){return!Ue.request||e.equals({},Ue.requestStatuses)?[]:Ue.request.status_id?U():N("none")}function W(e){return t.find(Ue.requestStatuses,function(n){return n.value===e})}function Y(e){Ue.errors=t.isArray(e)?e:[e],Ue.loading.absenceTypes=!1,Ue.submitting=!1}function G(){return!e.equals($e,Ue.request.attributes())||Ue.canManage&&Ue.newStatusOnSave}function V(){return Ue.postContactSelection=!0,Ue.staffMemberSelectionComplete=!1,Ue.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ue.isMode("edit")?Te:t.noop).then(function(){Ue.postContactSelection=!1,Ue.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Oe.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ue.canManage=Ue.isRole("manager")||Ue.isRole("admin")}function Q(){return Ue.canManage?f.find(Ue.request.contact_id).then(function(e){Ue.contactName=e.display_name}):o.resolve()}function J(){Ue.isRole("admin")&&Ue.isSelfRecord&&(Ue.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+ke.id==+t.get(Ue,"leaveRequest.contact_id"),a=!t.get(Ue,"leaveRequest.id");Ue.isSelfRecord=e&&a||n}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ue.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Se),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ue.request=Ue.leaveRequest||null,e=j(),n=Ue.initRequestAttributes(),"leave"===e?Ue.request=g.init(n):"sickness"===e?Ue.request=_.init(n):"toil"===e&&(Ue.request=q.init(n))}function ne(){var e={};return Ue.request?e=Ue.request.attributes():Ue.canManage||(e={contact_id:ke.id}),e}function te(){return Be="staff",ae().then(Ue.isSelfRecord&&!Ue.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ue.defaultStatus?Ue.newStatusOnSave=Ue.requestStatuses[y.statusNames[Ue.defaultStatus]].value:(Ue.isRole("admin")||Ue.isMode("create")&&Ue.isRole("manager"))&&(Ue.newStatusOnSave=Ue.requestStatuses[y.statusNames.approved].value)}function se(){return!Ue.request.status_id||!t.includes(["cancelled","rejected"],W(Ue.request.status_id).name)}function ie(e){var n=Ue.getStatusFromValue(Ue.request.status_id);return!!n&&n.name===e}function re(e){return Ue.request&&Ue.request.request_type===e}function ce(e){return Ue.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ue.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){we={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ue.loading.entitlements=!0,v.all({contact_id:Ue.request.contact_id,period_id:Ue.period.id,type_id:{IN:we.ids}},!0).finally(function(){Ue.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){ke=e})}function he(){return Ue.selectedContactId?f.find(Ue.selectedContactId).then(function(e){Ue.managedContacts=[e]}):Ue.isRole("admin")?f.all().then(function(e){console.log(e.list),Ue.managedContacts=e.list}):ke.leaveManagees().then(function(e){Ue.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ue.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){R(),d.publish(e,Ue.request),Ue.errors=[],Ue.dismissModal()}function ye(){["from","to"].forEach(function(e){Ue.request[e+"_date"]=$e[e+"_date"]})}function _e(e){if(Ue.absenceTypes=be(we.types,e),!Ue.absenceTypes.length)return o.reject(Ee)}function qe(){Ue.period=t.find(Ue.absencePeriods,function(e){return Ue.isMode("create")?e.current:ue(Ue.request,e)})}function Ce(){Ue.isMode("create")?(Ue.selectedAbsenceType=Ue.absenceTypes[0],Ue.request.type_id=Ue.selectedAbsenceType.id):Ue.selectedAbsenceType=t.find(Ue.absenceTypes,function(e){return e.id===Ue.request.type_id})}function Te(){$e=e.copy(Ue.request.attributes())}function Ae(){var e;Ue.request.id?(e=[Ue.requestStatuses[y.statusNames.approved].value,Ue.requestStatuses[y.statusNames.adminApproved].value,Ue.requestStatuses[y.statusNames.rejected].value,Ue.requestStatuses[y.statusNames.cancelled].value],Ue.mode="edit",Ue.isRole("staff")&&e.indexOf(Ue.request.status_id)>-1&&(Ue.mode="view")):Ue.mode="create"}function De(){var e=Ue.request.status_id;if(!Ue.isMode("view")&&!Ue.submitting)return Ue.submitting=!0,w(),A(),Ue.request.isValid().then(se()&&k).then(x).then(O()&&ye).then(Re).then(function(){return Ue.isMode("edit")?Le():$()}).catch(function(n){Ue.request.status_id=e,n&&Y(n)}).finally(function(){Ue.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Se(){ +xe.forEach(function(e){e()})}function Ie(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ue.request.update().then(Pe).then(function(){Ue.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ue.isRole("staff")||Ue.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var we,ke,Oe={},Me=0,$e={},xe=[],Ee="No entitlement",Be="",Fe=[],Ue=t.assign(this,m);Ue.absencePeriods=[],Ue.absenceTypes=[],Ue.canManage=!1,Ue.contactName=null,Ue.errors=[],Ue.isSelfLeaveApprover=!1,Ue.loading={absenceTypes:!0,entitlements:!0},Ue.managedContacts=[],Ue.mode="",Ue.newStatusOnSave=null,Ue.period={},Ue.postContactSelection=!1,Ue.requestStatuses={},Ue.selectedAbsenceType={},Ue.staffMemberSelectionComplete=!1,Ue.submitting=!1,Ue.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ue.canChangeAbsenceType=I,Ue.canSubmit=L,Ue.closeAlert=M,Ue.deleteLeaveRequest=E,Ue.dismissModal=B,Ue.getStatuses=H,Ue.getStatusFromValue=W,Ue.initAfterContactSelection=V,Ue.initRequestAttributes=ne,Ue.isLeaveStatus=ie,Ue.isLeaveType=re,Ue.isMode=ce,Ue.isRole=le,Ue.submit=De,Ue.updateAbsenceType=Ie,function(){Ue.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ue.canManage&&!Ue.isMode("edit")&&he()}).then(function(){if(Ue.selectedContactId&&(Ue.request.contact_id=Ue.selectedContactId),Ue.request.contact_id)return Ue.initAfterContactSelection()}).catch(Y).finally(function(){Ue.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,n){"use strict";function t(e,n,t,a,o,s,i,r,c){function u(e){return r.get().then(function(n){return e.roleOf(n.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:n.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(n){n?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}n.factory("LeavePopup",t),t.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(n){return n.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","common/lodash","leave-absences/admin-dashboard/modules/settings"],function(e,n){function t(e){e.settings.ga={userId:n.get(CRM,"vars.session.contact_id")},e.withAutoBase(!0)}return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","$analyticsProvider","settings",function(e,n,a,o,s,i,r){var c={format:["DateFormat",function(e){return e.getDateFormat()}]};n.defaults.stripTrailingSlashes=!1,o.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",t(i),s.debugEnabled(r.debug),a.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:c}).state("calendar",{url:"/calendar",template:'',resolve:c}).state("leave-balances",{url:"/leave-balances",template:"",resolve:c})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function n(e,n){e.debug("Component: admin-dashboard-container"),n.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",n]})}),define("leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component",[],function(){function e(e,n,t,a){function o(){i(),s()}function s(){return t("can administer calendar feeds").then(function(e){c.canCreateNewFeed=!!e})}function i(){return c.loading.feeds=!0,e.all().then(function(e){c.feeds=e}).finally(function(){c.loading.feeds=!1})}function r(e,t){n.open(e,t)}var c=this;c.canCreateNewFeed=!1,c.feeds=[],c.loading={feeds:!1},c.$onInit=o,c.openLinkModal=r}return e.$inject=["CalendarFeed","CalendarFeedsLinkModal","checkPermissions","shared-settings"],{__name:"calendarFeedsDropdownButton",bindings:{dropdownPosition:"@"},controller:e,controllerAs:"dropdownButton",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.html"}]}}),define("leave-absences/calendar-feeds/calendar-feeds.core",["common/angular","leave-absences/shared/modules/shared-settings"],function(e){e.module("calendar-feeds.core",["leave-absences.settings"])}),define("leave-absences/calendar-feeds/services/apis/calendar-feed.api",["common/lodash"],function(e){"use strict";function n(e,n,t){function a(){return this.sendGET("LeaveRequestCalendarFeedConfig","get",{is_active:!0}).then(function(e){return e.values})}return e.debug("CalendarFeedAPI"),t.extend({all:a})}return n.__name="CalendarFeedAPI",n.$inject=["$log","$q","api"],n}),define("leave-absences/calendar-feeds/services/models/calendar-feed.model",[],function(){"use strict";function e(e,n,t){function a(){return n.all().then(function(e){return e.map(function(e){return t.init(e)})})}return e.extend({all:a})}return e.__name="CalendarFeed",e.$inject=["Model","CalendarFeedAPI","CalendarFeedInstance"],e}),define("leave-absences/calendar-feeds/services/models/calendar-feed.instance",[],function(){"use strict";function e(e){return e.extend({})}return e.__name="CalendarFeedInstance",e.$inject=["ModelInstance"],e}),define("leave-absences/calendar-feeds/calendar-feeds.models",["common/angular","leave-absences/calendar-feeds/services/apis/calendar-feed.api","leave-absences/calendar-feeds/services/models/calendar-feed.model","leave-absences/calendar-feeds/services/models/calendar-feed.instance","common/models/model","common/services/api"],function(e,n,t,a){e.module("calendar-feeds.models",["common.apis","common.models"]).factory(n.__name,n).factory(t.__name,t).factory(a.__name,a)}),define("leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component",["common/lodash"],function(e){return{__name:"calendarFeedsLinkModal",bindings:{dismiss:"<",url:"<",title:"<"},controller:e.noop,controllerAs:"linkModal",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/link-modal/components/calendar-feeds-link-modal.html"}]}}),define("leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service",[],function(){function e(e,n,t){function a(e,a){var s=o(),i=t+"civicrm/calendar-feed?hash="+a;n.open({controllerAs:"modal",size:"md",template:'',controller:["$uibModalInstance","title","url",function(e,n,t){this.dismiss=e.dismiss,this.title=n,this.url=t}],appendTo:s,resolve:{title:function(){return e},url:function(){return i}}})}function o(){var n=e.find("#bootstrap-theme");return 0===n.length&&(n=e.find("body")),n.eq(0)}return{open:a}}return e.__name="CalendarFeedsLinkModal",e.$inject=["$document","$uibModal","HOST_URL"],e}),define("leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive",["common/lodash"],function(e){function n(n,t){function a(e,t,a,o){function s(){r(),u()}function i(){l[0].setSelectionRange(0,0),l.blur()}function r(){c(),document.execCommand("copy"),i()}function c(){l.focus(),l[0].setSelectionRange(0,l.val().length)}function u(){m.justCopied=!0,d&&n.cancel(d),d=n(function(){m.justCopied=!1},2e3)}var l,d,m=e.input;m.model=o.model,m.justCopied=!1,m.copy=s,m.selectInputText=c,function(){l=t.find("input")}()}var o=t.sourcePath+"calendar-feeds/link-modal/directives/input-with-copy-button.html";return{controller:e.noop,controllerAs:"input",link:a,restrict:"E",scope:{},templateUrl:o,require:{model:"^ngModel"}}}return n.__name="inputWithCopyButton",n.$inject=["$timeout","shared-settings"],n}),define("leave-absences/calendar-feeds/link-modal/link-modal.core",["common/angular","common/angularBootstrap"],function(e){e.module("calendar-feeds.link-modal.core",["ui.bootstrap"])}),function(e){define("leave-absences/calendar-feeds/link-modal/link-modal.constants",["common/angular"],function(n){"use strict";n.module("calendar-feeds.link-modal.constants",[]).constant("HOST_URL",e.absoluteUrl("/"))})}(Drupal),define("leave-absences/calendar-feeds/link-modal/link-modal.module",["common/angular","leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component","leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service","leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/link-modal/link-modal.core","leave-absences/calendar-feeds/link-modal/link-modal.constants"],function(e,n,t,a){e.module("calendar-feeds.link-modal",["calendar-feeds.core","calendar-feeds.link-modal.core","calendar-feeds.link-modal.constants"]).component(n.__name,n).directive(a.__name,a).factory(t.__name,t)}),define("leave-absences/calendar-feeds/dropdown-button/dropdown-button.module",["common/angular","leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component","common/services/check-permissions","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/calendar-feeds.models","leave-absences/calendar-feeds/link-modal/link-modal.module"],function(e,n){e.module("calendar-feeds.dropdown-button",["common.services","calendar-feeds.core","calendar-feeds.models","calendar-feeds.link-modal"]).component(n.__name,n)}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/angulartics","common/angulartics-google-tag-manager","common/angularUiRouter","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container","leave-absences/calendar-feeds/dropdown-button/dropdown-button.module"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","angulartics","angulartics.google.tagmanager","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components","calendar-feeds.dropdown-button"]).run(["$log","$rootScope","shared-settings","settings",function(e,n,t,a){e.debug("app.run"),n.sharedPathTpl=t.sharedPathTpl,n.settings=a}]),e}),function(e,n){var t=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";n.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":t+"/shared","leave-absences/admin-dashboard":t+"/admin-dashboard"}}),n(["leave-absences/shared/config"],function(){n(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/manager-leave.min.js index 3fb8c654d79..873791b9030 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/manager-leave.min.js @@ -1,5 +1,5 @@ -!function(e){define("leave-absences/shared/config",[],function(){e.config({paths:{mocks:"../test/mocks"}}),e.config({paths:{mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",sourcePath:e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&u.absencePeriods.length&&(u.filters.period_id=s().id),e.absenceTypes&&u.absenceTypes.length&&(u.filters.type_id=i().id),(e.loggedInContactId||e.userRole)&&(u.filters.managed_by="manager"===u.userRole?u.loggedInContactId:void 0),o()&&u.submitFilters()}function o(){return e.every(u.filters,function(e){return null!==e})}function s(){return e.find(u.absencePeriods,function(e){return e.current})||u.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function i(){return u.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function r(e){return e.current?"Current Period ("+e.title+")":e.title}function c(){n.$emit("LeaveBalanceFilters::update",u.filters)}var u=this;u.filters={period_id:null,type_id:null,managed_by:null},u.$onChanges=a,u.labelPeriod=r,u.submitFilters=c}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,o,s){return t.getLeaveBalances(this.processFilters(e),n,a,o,s)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){q(),b().then(function(){P.loading.component=!1})}function p(){return o.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function v(){return s.all().then(s.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return i.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function b(){return n.all([p(),v(),h(),g(),C()]).catch(function(e){c.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function y(){return P.loading.report=!0,r.all(R,P.pagination,void 0,void 0,!1).then(function(e){P.report=_(e.list),P.reportCount=e.total}).catch(function(e){c.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function _(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function q(){a.$on("LeaveBalanceFilters::update",A),u.subscribe("LeaveRequest::new",T)}function C(){return m(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function T(e){A(e,R)}function A(e,t){R=t,P.pagination.page=1,D(),P.loadReportCurrentPage()}function D(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+R.type_id})}var R={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.$onInit=f,P.loadReportCurrentPage=y}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(t,n,a,o,s,i,r){function c(){return{loadContacts:function(){return l.loadContactsForAdmin()}}}function u(e){i.info("",["

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 l,d;return{init:function(t){return d=t,l=r.init(d),d.filters.userSettings.assignedTo=e.find(d.filtersByAssignee,{type:"me"}),d.showContactDetailsLink=!0,d.showContactName=!0,d.showFilters=!0,d.showAdminFilteringHint=u,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService","LeaveCalendarService",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(t,n,a,o){function s(){return{loadContacts:function(){return i.loadLookUpAndFilteredContacts()}}}t.debug("LeaveCalendarManagerController");var i,r;return{init:function(t){return r=t,i=o.init(r),r.filters.userSettings.assignedTo=e.find(r.filtersByAssignee,{type:"me"}),r.showContactName=!0,r.showFilters=!0,s()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance","LeaveCalendarService",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,n,a){function o(){return{loadContacts:function(){return i.displaySingleContact?s.loadFilteredContacts():"admin"===i.userPermissionRole?s.loadContactsForAdmin():s.loadLookUpAndFilteredContacts()}}}e.debug("LeaveCalendarStaffController");var s,i;return{init:function(e){return i=e,s=a.init(i),i.filters.userSettings.contacts_with_leaves=!0,i.showTheseContacts=[i.contactId],i.showContactName=!0,i.showFilters=!0,i.displaySingleContact&&(i.showFilters=!1,i.lookupContacts=[{id:i.contactId}]),o()}}}n.controller("LeaveCalendarStaffController",["$log","$q","Contact","LeaveCalendarService",a])}),define("leave-absences/shared/components/leave-calendar.component",["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){function a(n,a,o,s,i,r,c,u,l,d){function m(){N().then(g).then(b).then(_).then(I).then(function(){return a.all([C(),D(),S(),W.showFilters?R():e.noop])}).then(function(){f(),y(),E()}).then(function(){W.loading.page=!1})}function f(){W.supportData.absenceTypes.push({id:"",title:"Leave",color:"#4D4D68",calculation_unit:e.chain(W.supportData.calculationUnits).find({name:"days"}).get("value").value()})}function p(){for(var e=[],n=t(W.selectedPeriod.start_date).clone().startOf("month"),a=t(W.selectedPeriod.end_date).clone().endOf("month");n.isBefore(a);)e.push(L(n)),n.add(1,"month");W.months=e}function v(){return e.includes(["admin","manager"],W.userPermissionRole)}function h(e){return e.format("YYYY-MM")}function b(){s.$on("LeaveCalendar::updateFiltersByAbsenceType",function(e,t){W.supportData.absenceTypesToFilterBy=t,$(!0)})}function g(){s.$new().$watch(function(){return W.selectedMonthIndex},function(e,t){null!==t&&e!==t&&(F(),E(),$())})}function y(e){W.injectMonth=!0,U("injected").then(function(){$(e)}).then(function(){W.loading.calendar=!1})}function _(){j=n("LeaveCalendar"+e.capitalize(H)+"Controller").init(W)}function q(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return r.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current})}).then(p).then(k)}function T(){return c.all().then(c.loadCalculationUnits)}function A(){return l.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function D(){return j.loadContacts().then(function(e){W.contacts=e})}function R(){return l.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){W.filters.optionValues.regions=e.hrjc_region,W.filters.optionValues.locations=e.hrjc_location,W.filters.optionValues.levelTypes=e.hrjc_level_type,W.filters.optionValues.departments=e.hrjc_department})}function P(){return u.all()}function S(){return a.all([T(),P(),A()]).then(function(t){W.supportData.absenceTypes=t[0],W.supportData.publicHolidays=t[1],W.supportData.calculationUnits=t[2].hrleaveandabsences_absence_type_calculation_unit,W.supportData.dayTypes=t[2].hrleaveandabsences_leave_request_day_type,W.supportData.leaveRequestStatuses=t[2].hrleaveandabsences_leave_request_status,W.supportData.toilAmounts=e.indexBy(t[2].hrleaveandabsences_toil_amounts,"value")})}function I(){var e=a.resolve();return W.injectMonth&&(e=U("destroyed"),W.injectMonth=!1),e}function L(e){return{index:h(e),month:e.month(),year:e.year(),name:e.format("MMMM"),moment:t().year(e.year()).month(e.month())}}function O(){var t=W.selectedPeriod.id;W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current}),t!==W.selectedPeriod.id&&p(),k(),E(),w("month")}function M(e){var n="previous"===e?"subtract":"add";F(t(W.selectedMonth.moment)[n](1,"month")),E(),w("month")}function w(t){t=e.includes(["contacts","period","month"],t)?t:"period",a.resolve().then(I).then("period"===t&&p).then("period"===t&&x).then("contacts"===t&&D).then("month"===t&&E).then(function(){y("contacts"===t)})}function $(e){s.$emit("LeaveCalendar::showMonth",!!e)}function k(){F(t())}function x(){F(W.months[0].moment)}function B(n){var a="previous"===n?"first":"last",o=e[a](W.months),s=t().year(o.year).month(o.month);W.monthPaginatorsAvailability[n]=!W.selectedMonth.moment.isSame(s,"month")}function E(){B("previous"),B("next")}function F(t){t&&(W.selectedMonthIndex=h(t)),W.selectedMonth=e.find(W.months,{index:W.selectedMonthIndex})}function N(){return a.all([d(i.permissions.admin.administer),d(i.permissions.ssp.manage)]).then(function(e){W.userPermissionRole=e[0]?"admin":e[1]?"manager":"staff",H=W.roleOverride?W.roleOverride:W.userPermissionRole})}function U(t){return a(function(n){var a=s.$on("LeaveCalendar::month"+e.capitalize(t),function(){a(),n()})})}o.debug("Component: leave-calendar");var j,H,W=this;W.absencePeriods=[],W.contacts=[],W.contactIdsToReduceTo=null,W.injectMonth=!1,W.months=[],W.selectedMonth={},W.selectedMonthIndex="",W.selectedPeriod=null,W.showContactName=!1,W.showFilters=!1,W.userPermissionRole="staff",W.loading={calendar:!0,page:!0},W.filters={hideOnMobile:!0,optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null},absenceTypes:{}},W.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],W.filters.userSettings.assignedTo=W.filtersByAssignee[2],W.monthPaginatorsAvailability={previous:!0,next:!0},W.supportData={absenceTypesToFilterBy:[]},W.$onInit=m,W.canManageRequests=v,W.labelPeriod=q,W.navigateToCurrentMonth=O,W.paginateMonth=M,W.refresh=w}n.component("leaveCalendar",{bindings:{contactId:"<",displaySingleContact:"0,n={from_date:{to:Q.month.days[Q.month.days.length-1].date+" 23:59:59"},to_date:{from:Q.month.days[0].date+" 00:00:00"},status_id:{IN:M()},contact_id:{IN:Q.contacts.map(function(e){return e.id})},type_id:{IN:t?Q.supportData.absenceTypesToFilterBy:e.pluck(Q.supportData.absenceTypes,"id")}};return y(),i.all(n,null,null,null,!1).then(function(e){return X={},t&&(e.list=q(e.list)),A(e.list)})}function k(){var t=Q.month.days[0].date,n=Q.month.days[Q.month.days.length-1].date;return s.get(Q.contacts.map(function(e){return e.id}),t,n).then(function(t){z=e.indexBy(t,"contact_id")})}function x(){return Q.contactIdsToReduceTo&&(Q.contacts=Q.contacts.filter(function(t){return e.includes(Q.contactIdsToReduceTo,t.contact_id)||e.find(X,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function B(t){var n=L(t);X[t.contact_id]=X[t.contact_id]||{},n.forEach(function(n){e.remove(X[t.contact_id][n.date],function(e){return e.id===t.id})})}function E(){o.$emit("LeaveCalendar::monthDestroyed"),V.map(function(e){e.remove?e.remove():e()})}function F(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=f(n),s=!0===o?a.resolve():a.all([i.isWeekend(v(t.date)),i.isNonWorkingDay(v(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:S(t.date)})}),s.then(function(){return X[n]&&X[n][t.date]?X[n][t.date]:[]}).then(function(a){a=j(a),e.assign(t.contactsData[n],{leaveRequests:a,leaveRequestsToShowInCell:b(a),leaveRequestsAttributes:C(t,a)})})}function N(){return a.all(Q.month.days.map(function(e){return a.all(Q.contacts.map(function(t){return F(e,t.id)}))}))}function U(e,t){Q.currentPage=0,Q.visible=!0,(t||!G)&&w()}function j(n){return e.sortBy(n,function(e){return+t(e.from_date).format("X")+(R("half_day_pm",e,e.from_date)?1:0)})}function H(t){var n=e.find(Q.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 W(e){h(e),-1!==M().indexOf(e.status_id)&&l(e)}function Y(e){return a.all(L(e).map(function(t){return F(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var G=!1,V=[],z={},X={},Q=this;Q.currentPage=0,Q.pageSize=20,Q.visible=!1,Q.showContactName=!!Q.showContactName,Q.showOnlyWithLeaveRequests=!!Q.showOnlyWithLeaveRequests,Q.$onDestroy=E,Q.$onInit=u,Q.contactsList=p,Q.getContactUrl=_}n.component("leaveCalendarMonth",{bindings:{showTheseContacts:"<",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/models/contact","common/models/session.model","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,i,r,c,u,l,d,m){function f(){a.resolve().then(_).then(C).then(function(){return y()&&"admin"!==O.role&&P()}).then(R).finally(function(){O.loading.component=!1})}function p(t){L=O.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===O.leaveRequest.request_type?i.open(q(t)):b(t)}function v(){return"admin"===O.role&&"public_holiday"===O.leaveRequest.request_type}function h(n){var a=O.absenceTypes[O.leaveRequest.type_id].allow_request_cancelation;return"admin"===O.role||("manager"===O.role?e.includes([M.awaitingApproval,M.moreInformationRequired],n):"3"===a?t().isBefore(O.leaveRequest.from_date):"2"===a)}function b(t){i.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return O.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(c.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){A(t)}}):q(t)})}})}function g(){return s.find(I).then(function(e){return e.checkIfSelfLeaveApprover()})}function y(){return I===O.leaveRequest.contact_id}function _(){e.isArray(O.leaveRequestStatuses)&&(O.leaveRequestStatuses=e.indexBy(O.leaveRequestStatuses,"value")),e.isArray(O.absenceTypes)&&(O.absenceTypes=e.indexBy(O.absenceTypes,"id"))}function q(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 O.leaveRequest[e]().then(function(){D(e)}).catch(function(e){d.error("Error:",e)})}}}function C(){return m.get().then(function(e){I=e.contactId})}function T(e,t){e.stopPropagation(),r.openModal(t)}function A(e){r.openModal({leaveRequest:O.leaveRequest,leaveType:O.leaveRequest.request_type,selectedContactId:O.leaveRequest.contact_id,forceRecalculateBalanceChange:!0,defaultStatus:l.statusNames[$[e]]})}function D(t){var n=e.find(O.leaveRequestStatuses,function(e){return e.name===l.statusNames.awaitingApproval}).value;L===n&&u.publish("ManagerBadge:: Update Count"),u.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:O.leaveRequest})}function R(){var t=O.leaveRequestStatuses[O.leaveRequest.status_id].name,n=e.compact(e.map(w,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!h(t)&&e.pull(n,"cancel"),"admin"!==O.role&&e.pull(n,"delete"),"staff"===O.role&&e.pull(n,"approve","reject"),"staff"!==O.role&&S(n),v()&&n.push("delete"),O.allowedActions=e.map(n,function(e){return{key:e,label:w[e].label,isDirectAction:w[e].isDirectAction}})}function P(){return g().then(function(e){e&&(O.role="admin")})}function S(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 I,L,O=this,M=l.statusNames,w={edit:{label:"Edit",allowedStatuses:[M.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[M.moreInformationRequired]},view:{label:"View",allowedStatuses:[M.approved,M.rejected,M.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[M.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[M.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[M.awaitingApproval,M.approved,M.rejected,M.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[M.awaitingApproval,M.moreInformationRequired,M.approved,M.rejected,M.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}},$={approve:"approved"};O.allowedActions=[],O.loading={component:!0},O.$onInit=f,O.action=p,O.openLeavePopup=T}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","$q","$rootScope","Contact","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService","Session"]}),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,i,r,c){function u(){o.$emit("LeaveRequestPopup::addTab",C),y(),_()}function l(){C.request.comments.push({contact_id:q,leave_request_id:C.request.id,text:C.comment.text}),C.comment.text=""}function d(){return C.comment.text.length>0}function m(e){return!e.comment_id||C.canManage}function f(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function p(){return C.request.comments.filter(function(e){return!e.toBeDeleted})}function v(e){return e===q?"Me":C.comment.contacts[e]?C.comment.contacts[e].display_name:void 0}function h(e){return C.mode===e}function b(){C.comment.text.length&&C.addComment()}function g(){var t=e.indexBy(C.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){C.comment.contacts=e.indexBy(t.list,"contact_id")})}function y(){return C.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),C.request.comments.length&&g()})}function _(){return C.loading.component=!0,c.get().then(function(e){q=e.contactId}).then(function(){C.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var q=null,C=this;C.loading={component:!0},C.comment={text:"",contacts:{}},C.$onInit=u,C.addComment=l,C.canRemoveComment=m,C.canSubmit=d,C.formatDateTime=f,C.getActiveComments=p,C.getCommentorName=v,C.isMode=h,C.onBeforeSubmit=b}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,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).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,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).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,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(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,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.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,o,s,i,r,c,u,l,d,m){function f(){n("RequestModalDetails"+e.capitalize(T(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(),k()])}).then(!ne.isMode("create")&&S).then(Y).then(function(){if(!ne.isMode("create"))return i.resolve().then(ne.initTimesExtended).then(z)}).then(!ne.isMode("create")&&W).then(L).then(G).then(P).then(O).then(!ne.isMode("view")&&ne.initWatchersExtended).catch(R).then(function(){ne.pagination.filteredbreakdown=ne.balance.change.breakdown,ne.pagination.totalItems=ne.balance.change.breakdown.length}).finally(function(){ne.loading.tab=!1})}function p(){ne.balance.closing=ne.balance.opening+ne.balance.change.amount}function v(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function b(e){var t;return i.resolve().then(function(){j(e),"from"===e&&U(),M("hours")&&(_(e),"from"!==e||ne.uiOptions.multipleDays||_("to")),ne.loading[e+"DayTypes"]=!0}).then(function(){return C(e)}).then(function(e){if(t=e.id!==ne.period.id,t&&(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(t)return x()}).then(function(){return ne.onDateChangeExtended&&ne.onDateChangeExtended(e)}).then(function(){if(z(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(R).finally(q)}function g(){return z(),E()}function y(){return ne.uiOptions.toDate=null,j("to"),i.resolve().then(z).then(ne.setDaysSelectionModeExtended).then(q).then(!ne.uiOptions.multipleDays&&E)}function _(e){ne.uiOptions.times[e].loading=!0}function q(){["from","to"].forEach(function(e){ne.loading[e+"DayTypes"]=!1,M("hours")&&(ne.uiOptions.times[e].loading=!1)})}function C(n){var a=t(ne.uiOptions[n+"Date"]).format(ne.uiOptions.userDateFormat.toUpperCase());return e.find(ne.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function T(){return ne.request?ne.request.request_type:ne.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return X(),ne.loading.balanceChange=!0,ne.request.getBalanceChangeBreakdown().then(H).catch(R)}function R(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),ne.loading.fromDayTypes=!1,ne.loading.balanceChange=!1,ne.loading.tab=!1,ne.loading.toDayTypes=!1}function P(){return ne.isMode("create")||ne.forceRecalculateBalanceChange?E():D()}function S(){var e=ne.request.attributes();return ne.uiOptions.fromDate=v(ne.request.from_date),ne.request.to_date=e.to_date,ne.request.to_date_type=e.to_date_type,ne.uiOptions.toDate=v(ne.request.to_date),ne.initDayTypesExtended?ne.initDayTypesExtended():i.resolve()}function I(){te.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){K(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function L(){ne.isMode("edit")&&(ne.isLeaveStatus(c.statusNames.approved)||ne.isLeaveStatus(c.statusNames.adminApproved))&&(ee={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,t){e!==t&&(ne.uiOptions.multipleDays||(Z(e),z()))})}function M(e){return ne.selectedAbsenceType.calculation_unit_name===e}function w(e){return ne.request.request_type===e}function $(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function k(){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 B(){var e=(ne.pagination.currentPage-1)*ne.pagination.numPerPage,t=e+ne.pagination.numPerPage;ne.pagination.filteredbreakdown=ne.balance.change.breakdown.slice(e,t)}function E(){return X(),ne.canCalculateChange()?(ne.loading.balanceChange=!0,ne.request.change_balance=!0,ne.calculateBalanceChange().then(H).catch(R).finally(function(){ne.loading.balanceChange=!1})):i.resolve()}function F(){ne.pagination.totalItems=ne.balance.change.breakdown.length,ne.pagination.filteredbreakdown=ne.balance.change.breakdown,ne.pagination.pageChanged()}function N(){return h(ne.request.from_date)===h(ne.request.to_date)}function U(){ne.uiOptions.toDate&&ne.uiOptions.fromDate&&ne.uiOptions.multipleDays&&t(ne.uiOptions.toDate).isSameOrBefore(ne.uiOptions.fromDate)&&(ne.uiOptions.toDate=null,j("to"))}function j(e){ne.resetUIInputsExtended&&ne.resetUIInputsExtended(e),z(),X()}function H(e){ne.balance.change=e,ne.request.balance_change=e.amount,p(),F(),ne.loading.balanceChange=!1}function W(){var e,n,a;ne.uiOptions.fromDate?(e=t(ne.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=v(ne.period.start_date),n=ne.uiOptions.date.to.options.minDate),ne.uiOptions.date.to.options.initDate=n,ne.uiOptions.date.to.options.minDate=a,ne.uiOptions.date.to.options.maxDate=v(ne.period.end_date)}function Y(){return!ne.isMode("create")&&N()||ne.isMode("create")&&(w("sickness")||M("hours"))?ne.uiOptions.multipleDays=!1:ne.uiOptions.multipleDays=!0,i.resolve().then(ne.setDaysSelectionModeExtended)}function G(){ee&&ee.absenceTypeId===ne.selectedAbsenceType.id?ne.balance.opening=ee.value||0:ne.balance.opening=ne.selectedAbsenceType.remainder}function V(){ne.selectedAbsenceType=e.find(ne.absenceTypes,function(e){return e.id===ne.request.type_id})}function z(){var e=ne.uiOptions,t=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),(M("hours")||w("toil"))&&(ne.request.from_date=ne.request.from_date&&t.from.time?ne.request.from_date+" "+t.from.time:null,ne.request.to_date=ne.request.to_date&&t.to.time?ne.request.to_date+" "+t.to.time:null)}function X(){ne.uiOptions.showBalance=ne.canCalculateChange()}function Q(){e.forEach(te,function(e){e()})}function J(){var e,t=ne.selectedAbsenceType.calculation_unit_name;return V(),e=t!==ne.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&Y).then(e&&ne.onAbsenceTypeUpdateExtended).then(e&&z).then(q).then(E)}function K(e){return ne.absenceTypes=e,V(),t(ne.uiOptions.toDate).isAfter(ne.period.end_date)&&(ne.uiOptions.toDate=void 0,j("to")),G(),E()}function Z(e){var t=A(e).add(ne.uiOptions.time_interval,"minutes");t.isAfter(A(ne.uiOptions.times.to.max))||(ne.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(ne.uiOptions.times.to.time))&&(ne.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var ee=null,te=[],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:[],numPerPage:7,totalItems:0,pageChanged:B},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.$onInit=f,ne.convertDateFormatFromServer=v,ne.convertDateToServerFormat=h,ne.dateChangeHandler=b,ne.dateTypeChangeHandler=g,ne.daysSelectionModeChangeHandler=y,ne.disableAndShowLoadingTimeInput=_,ne.getMomentDateWithGivenTime=A,ne.handleError=R,ne.isCalculationUnit=M,ne.isLeaveType=w,ne.isNotWorkingDay=$,ne.performBalanceChangeCalculation=E,ne.setRequestDateTimesAndDateTypes=z,ne.updateEndTimeInputMinTime=Z,ne.$onDestroy=Q}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,o,s,i,r,c,u,l){function d(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),y(),a.all([A(),C()]).then(_).finally(function(){O.filesLoaded=!0})}function m(){return O.fileUploader&&O.fileUploader.queue.length>0}function f(){return O.getFilesAmount()0?S.map(function(e){return e.label}).join(", "):""}function C(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function T(){return a.all(S.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){L[e.label]=t})})).catch(function(){L=null})}function A(){return c.valuesOf("safe_file_extension").then(function(e){S=e})}function D(e){return!e.attachment_id||O.canManage}function R(){e.forEach(I,function(e){e()})}function P(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var S=[],I=[],L={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=R,O.$onInit=d,O.canRemoveAttachment=D,O.canSubmit=m,O.canUploadMore=f,O.formatDateTime=p,O.getAuthorName=v,O.getFilesAmount=h,O.listFileTypes=q,O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(){s=n.parse(),s.openModal&&o({leaveType:s.openModal,selectedContactId:i.selectedContactId})}function o(e){t.openModal(e)}e.debug("Component: leave-request-record-actions");var s,i=this;i.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],i.$onInit=a,i.openLeavePopup=o}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,o,s,i,r,c,u,l,d,m){"use strict";function f(){s(r.permissions.admin.administer).then(function(e){H.isAdmin=e,n.all([A(),D(),M(),P(),L(),I(),w()]).then(function(){H.loading.page=!1,R()}),U()})}function p(){H.filters.leaveRequest.contact_id=null,H.refresh()}function v(){var e=H.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?H.leaveRequests.filter.list.length:H.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function b(t){return e.find(H.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function y(t){var n=e.find(H.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function _(e){switch(e){case r.statusNames.approved:return"badge-success";case r.statusNames.rejected:return"badge-danger";case r.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function q(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}function C(t){var n=e.find(H.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function T(e){return e.current?"Current Period ("+e.title+")":e.title}function A(){return c.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.filters.leaveRequest.selectedPeriod=e.find(H.absencePeriods,function(e){return!!e.current})})}function D(){return u.all().then(u.loadCalculationUnits).then(function(e){H.absenceTypes=e})}function R(e){return(H.isAdmin?o.all(v()):o.leaveManagees(H.contactId,v())).then(function(t){return H.filteredUsers=H.isAdmin?t.list:t,e?S(e):n.all([S("table"),S("filter")])}).then(function(){H.filters.leaveRequest.leaveStatus!==W&&0===H.leaveRequests.table.list.length&&H.refresh(1,!0)})}function P(){return i.valuesOf("hrjc_department").then(function(e){H.departments=e})}function S(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:H.pagination,o="filter"===e?{return:["status_id"]}:{};return H.loading[n]=!0,l.all(O(t),a,"from_date DESC",o,!1).then(function(t){H.leaveRequests[e]=t}).catch(function(){H.leaveRequests[e].list=[]}).finally(function(){H.loading[n]=!1})}function I(){return i.valuesOf("hrjc_level_type").then(function(e){H.levelTypes=e})}function L(){return i.valuesOf("hrjc_location").then(function(e){H.locations=e})}function O(t){var n=H.filters.leaveRequest;return{contact_id:k(),managed_by:H.isAdmin&&"me"!==n.assignedTo.type?void 0:H.contactId,status_id:B(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(H.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function M(){return i.valuesOf("hrjc_region").then(function(e){H.regions=e})}function w(){return i.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){H.leaveRequestStatuses=e.concat(H.leaveRequestStatuses)})}function $(e){d.openModal(e)}function k(){return H.filteredUsers.length>0&&H.filters.leaveRequest.contact_id?H.filters.leaveRequest.contact_id:{IN:H.filteredUsers.map(function(e){return e.id})}}function x(e){var t=[q(r.statusNames.moreInformationRequired),q(r.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function B(e){var t=H.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=x(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(H.filters.leaveRequest.leaveStatus=W),(e<=H.totalNoOfPages()||0===H.totalNoOfPages())&&(H.pagination.page=e,R(n))}function F(e){H.filters.leaveRequest.leaveStatus=e,H.refresh(1,!1,"table")}function N(e){H.filters.leaveRequest.assignedTo=e,H.refresh()}function U(){m.subscribe("LeaveRequest::updatedByManager",function(){H.refresh()}),m.subscribe("LeaveRequest::new",function(){H.refresh()}),m.subscribe("LeaveRequest::edit",function(){H.refresh()}),m.subscribe("LeaveRequest::delete",function(){H.refresh()}),m.subscribe("LeaveRequest::statusUpdate",function(){H.refresh()})}function j(){return Math.ceil(H.leaveRequests.table.total/H.pagination.size)}t.debug("Component: manage-leave-requests");var H=this,W={name:"all",label:"All"};H.absencePeriods=[],H.absenceTypes=[],H.filteredUsers=[],H.isFilterExpanded=!1,H.isAdmin=!1,H.leaveRequests={table:{list:[]},filter:{list:[]}},H.leaveRequestStatuses=[W],H.loading={content:!0,page:!0,table:!0},H.pagination={page:1,size:7},H.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],H.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:H.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:H.filtersByAssignee[0]}},H.$onInit=f,H.clearStaffSelection=p,H.countLeaveRequestByStatus=h,H.getAbsenceTypeByID=b,H.getArrayOfSize=g,H.getLeaveStatusByValue=y,H.getNavBadge=_,H.getUserNameByID=C,H.labelPeriod=T,H.openLeavePopup=$,H.refresh=E,H.refreshWithFilter=F,H.refreshWithFilterByAssignee=N,H.totalNoOfPages=j}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function d(){return i.canCalculateChange()}function m(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.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}function f(t,n){return t?(t=i.convertDateToServerFormat(t),h(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return S(n,e),e})):o.reject([])}function p(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.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 v(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function y(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),O(),i.performBalanceChangeCalculation())})}function _(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(v(a.min,n)<=0||v(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(R)).then(function(){["from","to"].forEach(function(e){_(e),L(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(O)}function C(){["from","to"].forEach(function(e){y(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&L(e,!0))})}function A(e,t){return f(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return R(e).then(function(){L(e,!0)})})}function R(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){w[e]=t,m(e,t),n&&"from"===e&&m("to",t)}).catch(function(t){return w[e]={},i.handleError(t)}).finally(function(){i.uiOptions.times[e].loading=!1,n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function S(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function I(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),R("from").then(function(){L("from",!0)})):o.resolve()}function L(e,t){var n=i.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,c=w[a].number_of_hours?v(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function O(){var e=i.uiOptions.times -;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function M(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?R("from").then(function(){L("from",!0)}):o.resolve()}var w={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=M,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=I}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),v(),f(!0)])}function l(t){var n=r.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function d(t){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===t})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(t){return i.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){r.sicknessReasons=e.indexBy(t,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function v(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=U.from_date!==c.request.from_date||U.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function v(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function h(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function y(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",_().then(g).then(C).then(S)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&c.isCalculationUnit("hours")&&M(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),F(),l(),w())})})}function P(){c.isMode("view")||(T(),A(),R())}function S(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function I(){return l(),w(),F()}function L(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:w(),F()}function O(e){c.uiOptions.times[e].time=""}function M(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function w(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function $(){U=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),w(),c.isCalculationUnit("hours")?M():c.request.toil_to_accrue=null}function B(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){S(!1)})}function E(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function N(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,j=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=v,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=I,c.openToilInDaysAccrualOptionsEditor=B,c.resetUIInputsExtended=O,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=N,function(){$(),k(),E(),!c.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,t,n){"use strict";function a(n,a,o,s){function i(n){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var t=e.get(n,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return n.lookupContacts=e,a.all([d(),"me"!==t?u():a.resolve(null)])}).then(function(e){var t=e[0];return n.contactIdsToReduceTo=e[1],t})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return t(a.period_start_date).isSameOrBefore(n.selectedPeriod.end_date)&&(t(a.period_end_date).isSameOrAfter(n.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return h?a.resolve(h):s.all()}function d(){return o.all(v(),null,"display_name").then(function(e){return e.list})}function m(){var t=e.get(n,"filters.userSettings.assignedTo.type","all");return(0,b[t])()}function f(){return m().then(function(e){n.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(n.contactId)}function v(){var t={department:e.get(n,"filters.userSettings.department.value",null),level_type:e.get(n,"filters.userSettings.level_type.value",null),location:e.get(n,"filters.userSettings.location.value",null),region:e.get(n,"filters.userSettings.region.value",null)},a=!!n.filters.userSettings.contact,o=e.isArray(n.lookupContacts)&&n.lookupContacts.length,s="all"!==e.get(n,"filters.userSettings.assignedTo.type","all");return a?t.id={IN:[n.filters.userSettings.contact.id]}:(s||o)&&(t.id={IN:e.pluck(n.lookupContacts,"id")}),t}var h,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return n.debug("LeaveCalendarService"),{init:i}}n.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(n){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return n.contact_id&&n.period_id||o.reject("contact_id and period_id are mandatory"),n=t.defaults(n,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",n,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){return e.debug("LeaveRequestAPI.update",t),t.id?this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([h.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return n.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,v,h,b,g,y,_,q,C){function T(e){"days"===Ne.selectedAbsenceType.calculation_unit_name?delete Ne.request[e+"_date_amount"]:delete Ne.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return Me.checkIfSelfLeaveApprover().then(function(e){e&&(Ee="admin")})}function R(){var e=Ne.requestStatuses[y.statusNames.awaitingApproval].value;ke.status_id===e&&e!==Ne.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!Ne.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ne.isMode("edit")&&(e=e&&(G()||S())),Ne.canManage&&Ne.requestStatuses&&(e=e&&!!Ne.getStatusFromValue(Ne.newStatusOnSave)),(e=e&&!!Ne.period.id)&&!Ne.isMode("view")}function O(){Ne.isSelfRecord&&!Ne.isSelfLeaveApprover?Ne.request.status_id=Ne.requestStatuses[y.statusNames.awaitingApproval].value:Ne.canManage&&(Ne.request.status_id=Ne.newStatusOnSave||Ne.request.status_id)}function M(){if(Ne.isMode("edit")&&!Ne.isRole("staff")&&"toil"!==j())return Ne.request.calculateBalanceChange(Ne.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ne.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function w(){return"toil"!==j()&&!Ne.request.change_balance}function $(){Ne.errors=[]}function k(){return Ne.request.create().then(Pe).then(function(){ge("LeaveRequest::new")})}function x(){se()&&!Ne.isRole("staff")&&(Ne.request.change_balance=!0)}function B(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ne.request.delete().then(function(){Ne.dismissModal(),d.publish("LeaveRequest::delete",Ne.request)})}})}function E(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return U(Ne.getStatusFromValue(Ne.request.status_id).name)}function U(e){return n.map(we[e],function(e){return Ne.requestStatuses[e]})}function j(){return Ne.request?Ne.request.request_type:Ne.leaveType||null}function H(){return!Ne.request||e.equals({},Ne.requestStatuses)?[]:Ne.request.status_id?N():U("none")}function W(e){return n.find(Ne.requestStatuses,function(t){return t.value===e})}function Y(e){Ne.errors=n.isArray(e)?e:[e],Ne.loading.absenceTypes=!1,Ne.submitting=!1}function G(){return!e.equals(ke,Ne.request.attributes())||Ne.canManage&&Ne.newStatusOnSave}function V(){return Ne.postContactSelection=!0,Ne.staffMemberSelectionComplete=!1,Ne.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ne.isMode("edit")?Te:n.noop).then(function(){Ne.postContactSelection=!1,Ne.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Be)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];we.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],we.awaiting_approval=e,we.more_information_required=e,we.rejected=e,we.approved=e,we.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ne.canManage=Ne.isRole("manager")||Ne.isRole("admin")}function Q(){return Ne.canManage?f.find(Ne.request.contact_id).then(function(e){Ne.contactName=e.display_name}):o.resolve()}function J(){Ne.isRole("admin")&&Ne.isSelfRecord&&(Ne.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,t=+Me.id==+n.get(Ne,"leaveRequest.contact_id"),a=!n.get(Ne,"leaveRequest.id");Ne.isSelfRecord=e&&a||t}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ne.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){Y(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){$e++})),i.$on("$destroy",Se),i.$on("LeaveRequestPopup::addTab",function(e,t){Fe.push(t)})}function ee(){var e,t;Ne.request=Ne.leaveRequest||null,e=j(),t=Ne.initRequestAttributes(),"leave"===e?Ne.request=g.init(t):"sickness"===e?Ne.request=_.init(t):"toil"===e&&(Ne.request=q.init(t))}function te(){var e={};return Ne.request?e=Ne.request.attributes():Ne.canManage||(e={contact_id:Me.id}),e}function ne(){return Ee="staff",ae().then(Ne.isSelfRecord&&!Ne.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Ee="admin")}).then(function(){return"admin"!==Ee&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Ee="manager")})}function oe(){Ne.defaultStatus?Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames[Ne.defaultStatus]].value:(Ne.isRole("admin")||Ne.isMode("create")&&Ne.isRole("manager"))&&(Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames.approved].value)}function se(){return!Ne.request.status_id||!n.includes(["cancelled","rejected"],W(Ne.request.status_id).name)}function ie(e){var t=Ne.getStatusFromValue(Ne.request.status_id);return!!t&&t.name===e}function re(e){return Ne.request&&Ne.request.request_type===e}function ce(e){return Ne.mode===e}function ue(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date,"day")&&o.isSameOrBefore(t.end_date,"day")}function le(e){return Ee===e}function de(){return p.all().then(function(e){Ne.absencePeriods=e})}function me(){return v.all(F()).then(v.loadCalculationUnits).then(function(e){Oe={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ne.loading.entitlements=!0,h.all({contact_id:Ne.request.contact_id,period_id:Ne.period.id,type_id:{IN:Oe.ids}},!0).finally(function(){Ne.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){Me=e})}function ve(){return Ne.selectedContactId?f.find(Ne.selectedContactId).then(function(e){Ne.managedContacts=[e]}):Ne.isRole("admin")?f.all().then(function(e){Ne.managedContacts=n.remove(e.list,function(e){return e.id!==Me.id})}):Me.leaveManagees().then(function(e){Ne.managedContacts=e})}function he(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ne.requestStatuses=n.indexBy(e,"name")})}function be(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){R(),d.publish(e,Ne.request),Ne.errors=[],Ne.dismissModal()}function ye(){["from","to"].forEach(function(e){Ne.request[e+"_date"]=ke[e+"_date"]})}function _e(e){if(Ne.absenceTypes=be(Oe.types,e),!Ne.absenceTypes.length)return o.reject(Be)}function qe(){Ne.period=n.find(Ne.absencePeriods,function(e){return Ne.isMode("create")?e.current:ue(Ne.request,e)})}function Ce(){Ne.isMode("create")?(Ne.selectedAbsenceType=Ne.absenceTypes[0],Ne.request.type_id=Ne.selectedAbsenceType.id):Ne.selectedAbsenceType=n.find(Ne.absenceTypes,function(e){return e.id===Ne.request.type_id})}function Te(){ke=e.copy(Ne.request.attributes())}function Ae(){var e;Ne.request.id?(e=[Ne.requestStatuses[y.statusNames.approved].value,Ne.requestStatuses[y.statusNames.adminApproved].value,Ne.requestStatuses[y.statusNames.rejected].value,Ne.requestStatuses[y.statusNames.cancelled].value],Ne.mode="edit",Ne.isRole("staff")&&e.indexOf(Ne.request.status_id)>-1&&(Ne.mode="view")):Ne.mode="create"}function De(){var e=Ne.request.status_id;if(!Ne.isMode("view")&&!Ne.submitting)return Ne.submitting=!0,O(),A(),Ne.request.isValid().then(se()&&M).then(x).then(w()&&ye).then(Re).then(function(){return Ne.isMode("edit")?Le():k() -}).catch(function(t){Ne.request.status_id=e,t&&Y(t)}).finally(function(){Ne.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&n.push(e),++a===$e&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return $e>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Se(){xe.forEach(function(e){e()})}function Ie(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ne.request.update().then(Pe).then(function(){Ne.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ne.isRole("staff")||Ne.isRole("admin"))&&ge("LeaveRequest::edit")})}t.debug("RequestCtrl");var Oe,Me,we={},$e=0,ke={},xe=[],Be="No entitlement",Ee="",Fe=[],Ne=n.assign(this,m);Ne.absencePeriods=[],Ne.absenceTypes=[],Ne.canManage=!1,Ne.contactName=null,Ne.errors=[],Ne.isSelfLeaveApprover=!1,Ne.loading={absenceTypes:!0,entitlements:!0},Ne.managedContacts=[],Ne.mode="",Ne.newStatusOnSave=null,Ne.period={},Ne.postContactSelection=!1,Ne.requestStatuses={},Ne.selectedAbsenceType={},Ne.staffMemberSelectionComplete=!1,Ne.submitting=!1,Ne.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ne.canChangeAbsenceType=I,Ne.canSubmit=L,Ne.closeAlert=$,Ne.deleteLeaveRequest=B,Ne.dismissModal=E,Ne.getStatuses=H,Ne.getStatusFromValue=W,Ne.initAfterContactSelection=V,Ne.initRequestAttributes=te,Ne.isLeaveStatus=ie,Ne.isLeaveType=re,Ne.isMode=ce,Ne.isRole=le,Ne.submit=De,Ne.updateAbsenceType=Ie,function(){Ne.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([ne(),de(),he()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ne.canManage&&!Ne.isMode("edit")&&ve()}).then(function(){if(Ne.selectedContactId&&(Ne.request.contact_id=Ne.selectedContactId),Ne.request.contact_id)return Ne.initAfterContactSelection()}).catch(Y).finally(function(){Ne.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(o.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var o=this;o.tabName=n.current.name,o.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e,t){define("leave-absences/manager-leave/modules/config",["common/angular","common/lodash","leave-absences/manager-leave/modules/settings"],function(t,n){function a(t){t.withAutoBase(!0),t.settings.ga={userId:n.get(e,"vars.session.contact_id")}}return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","$analyticsProvider","settings",function(t,n,o,s,i,r,c){s.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.defaults.stripTrailingSlashes=!1,o.otherwise("/manager-leave/requests"),a(r),i.debugEnabled(c.debug),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM,Drupal),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/angulartics","common/angulartics-google-tag-manager","common/angularUiRouter","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","angulartics","angulartics.google.tagmanager","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){e.config({paths:{mocks:"../test/mocks"}}),e.config({paths:{mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",sourcePath:e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&u.absencePeriods.length&&(u.filters.period_id=s().id),e.absenceTypes&&u.absenceTypes.length&&(u.filters.type_id=i().id),(e.loggedInContactId||e.userRole)&&(u.filters.managed_by="manager"===u.userRole?u.loggedInContactId:void 0),o()&&u.submitFilters()}function o(){return e.every(u.filters,function(e){return null!==e})}function s(){return e.find(u.absencePeriods,function(e){return e.current})||u.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function i(){return u.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function r(e){return e.current?"Current Period ("+e.title+")":e.title}function c(){n.$emit("LeaveBalanceFilters::update",u.filters)}var u=this;u.filters={period_id:null,type_id:null,managed_by:null},u.$onChanges=a,u.labelPeriod=r,u.submitFilters=c}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,o,s){return t.getLeaveBalances(this.processFilters(e),n,a,o,s)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){q(),g().then(function(){P.loading.component=!1})}function p(){return o.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function v(){return s.all().then(s.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return i.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function g(){return n.all([p(),v(),h(),b(),C()]).catch(function(e){c.error("Error",e)})}function b(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function y(){return P.loading.report=!0,r.all(R,P.pagination,void 0,void 0,!1).then(function(e){P.report=_(e.list),P.reportCount=e.total}).catch(function(e){c.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function _(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function q(){a.$on("LeaveBalanceFilters::update",A),u.subscribe("LeaveRequest::new",T)}function C(){return m(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function T(e){A(e,R)}function A(e,t){R=t,P.pagination.page=1,D(),P.loadReportCurrentPage()}function D(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+R.type_id})}var R={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.$onInit=f,P.loadReportCurrentPage=y}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(t,n,a,o,s,i,r){function c(){return{loadContacts:function(){return l.loadContactsForAdmin()}}}function u(e){i.info("",["

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 l,d;return{init:function(t){return d=t,l=r.init(d),d.filters.userSettings.assignedTo=e.find(d.filtersByAssignee,{type:"me"}),d.showContactDetailsLink=!0,d.showContactName=!0,d.showFilters=!0,d.showAdminFilteringHint=u,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService","LeaveCalendarService",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(t,n,a,o){function s(){return{loadContacts:function(){return i.loadLookUpAndFilteredContacts()}}}t.debug("LeaveCalendarManagerController");var i,r;return{init:function(t){return r=t,i=o.init(r),r.filters.userSettings.assignedTo=e.find(r.filtersByAssignee,{type:"me"}),r.showContactName=!0,r.showFilters=!0,s()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance","LeaveCalendarService",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,n,a){function o(){return{loadContacts:function(){return i.displaySingleContact?s.loadFilteredContacts():"admin"===i.userPermissionRole?s.loadContactsForAdmin():s.loadLookUpAndFilteredContacts()}}}e.debug("LeaveCalendarStaffController");var s,i;return{init:function(e){return i=e,s=a.init(i),i.filters.userSettings.contacts_with_leaves=!0,i.showTheseContacts=[i.contactId],i.showContactName=!0,i.showFilters=!0,i.displaySingleContact&&(i.showFilters=!1,i.lookupContacts=[{id:i.contactId}]),o()}}}n.controller("LeaveCalendarStaffController",["$log","$q","Contact","LeaveCalendarService",a])}),define("leave-absences/shared/components/leave-calendar.component",["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){function a(n,a,o,s,i,r,c,u,l,d){function m(){N().then(b).then(g).then(_).then(I).then(function(){return a.all([C(),D(),S(),W.showFilters?R():e.noop])}).then(function(){f(),y(),E()}).then(function(){W.loading.page=!1})}function f(){W.supportData.absenceTypes.push({id:"",title:"Leave",color:"#4D4D68",calculation_unit:e.chain(W.supportData.calculationUnits).find({name:"days"}).get("value").value()})}function p(){for(var e=[],n=t(W.selectedPeriod.start_date).clone().startOf("month"),a=t(W.selectedPeriod.end_date).clone().endOf("month");n.isBefore(a);)e.push(L(n)),n.add(1,"month");W.months=e}function v(){return e.includes(["admin","manager"],W.userPermissionRole)}function h(e){return e.format("YYYY-MM")}function g(){s.$on("LeaveCalendar::updateFiltersByAbsenceType",function(e,t){W.supportData.absenceTypesToFilterBy=t,$(!0)})}function b(){s.$new().$watch(function(){return W.selectedMonthIndex},function(e,t){null!==t&&e!==t&&(F(),E(),$())})}function y(e){W.injectMonth=!0,U("injected").then(function(){$(e)}).then(function(){W.loading.calendar=!1})}function _(){j=n("LeaveCalendar"+e.capitalize(H)+"Controller").init(W)}function q(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return r.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current})}).then(p).then(k)}function T(){return c.all().then(c.loadCalculationUnits)}function A(){return l.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function D(){return j.loadContacts().then(function(e){W.contacts=e})}function R(){return l.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){W.filters.optionValues.regions=e.hrjc_region,W.filters.optionValues.locations=e.hrjc_location,W.filters.optionValues.levelTypes=e.hrjc_level_type,W.filters.optionValues.departments=e.hrjc_department})}function P(){return u.all()}function S(){return a.all([T(),P(),A()]).then(function(t){W.supportData.absenceTypes=t[0],W.supportData.publicHolidays=t[1],W.supportData.calculationUnits=t[2].hrleaveandabsences_absence_type_calculation_unit,W.supportData.dayTypes=t[2].hrleaveandabsences_leave_request_day_type,W.supportData.leaveRequestStatuses=t[2].hrleaveandabsences_leave_request_status,W.supportData.toilAmounts=e.indexBy(t[2].hrleaveandabsences_toil_amounts,"value")})}function I(){var e=a.resolve();return W.injectMonth&&(e=U("destroyed"),W.injectMonth=!1),e}function L(e){return{index:h(e),month:e.month(),year:e.year(),name:e.format("MMMM"),moment:t().year(e.year()).month(e.month())}}function O(){var t=W.selectedPeriod.id;W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current}),t!==W.selectedPeriod.id&&p(),k(),E(),w("month")}function M(e){var n="previous"===e?"subtract":"add";F(t(W.selectedMonth.moment)[n](1,"month")),E(),w("month")}function w(t){t=e.includes(["contacts","period","month"],t)?t:"period",a.resolve().then(I).then("period"===t&&p).then("period"===t&&x).then("contacts"===t&&D).then("month"===t&&E).then(function(){y("contacts"===t)})}function $(e){s.$emit("LeaveCalendar::showMonth",!!e)}function k(){F(t())}function x(){F(W.months[0].moment)}function B(n){var a="previous"===n?"first":"last",o=e[a](W.months),s=t().year(o.year).month(o.month);W.monthPaginatorsAvailability[n]=!W.selectedMonth.moment.isSame(s,"month")}function E(){B("previous"),B("next")}function F(t){t&&(W.selectedMonthIndex=h(t)),W.selectedMonth=e.find(W.months,{index:W.selectedMonthIndex})}function N(){return a.all([d(i.permissions.admin.administer),d(i.permissions.ssp.manage)]).then(function(e){W.userPermissionRole=e[0]?"admin":e[1]?"manager":"staff",H=W.roleOverride?W.roleOverride:W.userPermissionRole})}function U(t){return a(function(n){var a=s.$on("LeaveCalendar::month"+e.capitalize(t),function(){a(),n()})})}o.debug("Component: leave-calendar");var j,H,W=this;W.absencePeriods=[],W.contacts=[],W.contactIdsToReduceTo=null,W.injectMonth=!1,W.months=[],W.selectedMonth={},W.selectedMonthIndex="",W.selectedPeriod=null,W.showContactName=!1,W.showFilters=!1,W.userPermissionRole="staff",W.loading={calendar:!0,page:!0},W.filters={hideOnMobile:!0,optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null},absenceTypes:{}},W.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],W.filters.userSettings.assignedTo=W.filtersByAssignee[2],W.monthPaginatorsAvailability={previous:!0,next:!0},W.supportData={absenceTypesToFilterBy:[]},W.$onInit=m,W.canManageRequests=v,W.labelPeriod=q,W.navigateToCurrentMonth=O,W.paginateMonth=M,W.refresh=w}n.component("leaveCalendar",{bindings:{contactId:"<",displaySingleContact:"0,n={from_date:{to:Q.month.days[Q.month.days.length-1].date+" 23:59:59"},to_date:{from:Q.month.days[0].date+" 00:00:00"},status_id:{IN:M()},contact_id:{IN:Q.contacts.map(function(e){return e.id})},type_id:{IN:t?Q.supportData.absenceTypesToFilterBy:e.pluck(Q.supportData.absenceTypes,"id")}};return y(),i.all(n,null,null,null,!1).then(function(e){return X={},t&&(e.list=q(e.list)),A(e.list)})}function k(){var t=Q.month.days[0].date,n=Q.month.days[Q.month.days.length-1].date;return s.get(Q.contacts.map(function(e){return e.id}),t,n).then(function(t){z=e.indexBy(t,"contact_id")})}function x(){return Q.contactIdsToReduceTo&&(Q.contacts=Q.contacts.filter(function(t){return e.includes(Q.contactIdsToReduceTo,t.contact_id)||e.find(X,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function B(t){var n=L(t);X[t.contact_id]=X[t.contact_id]||{},n.forEach(function(n){e.remove(X[t.contact_id][n.date],function(e){return e.id===t.id})})}function E(){o.$emit("LeaveCalendar::monthDestroyed"),V.map(function(e){e.remove?e.remove():e()})}function F(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=f(n),s=!0===o?a.resolve():a.all([i.isWeekend(v(t.date)),i.isNonWorkingDay(v(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:S(t.date)})}),s.then(function(){return X[n]&&X[n][t.date]?X[n][t.date]:[]}).then(function(a){a=j(a),e.assign(t.contactsData[n],{leaveRequests:a,leaveRequestsToShowInCell:g(a),leaveRequestsAttributes:C(t,a)})})}function N(){return a.all(Q.month.days.map(function(e){return a.all(Q.contacts.map(function(t){return F(e,t.id)}))}))}function U(e,t){Q.currentPage=0,Q.visible=!0,(t||!G)&&w()}function j(n){return e.sortBy(n,function(e){return+t(e.from_date).format("X")+(R("half_day_pm",e,e.from_date)?1:0)})}function H(t){var n=e.find(Q.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 W(e){h(e),-1!==M().indexOf(e.status_id)&&l(e)}function Y(e){return a.all(L(e).map(function(t){return F(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var G=!1,V=[],z={},X={},Q=this;Q.currentPage=0,Q.pageSize=20,Q.visible=!1,Q.showContactName=!!Q.showContactName,Q.showOnlyWithLeaveRequests=!!Q.showOnlyWithLeaveRequests,Q.$onDestroy=E,Q.$onInit=u,Q.contactsList=p,Q.getContactUrl=_}n.component("leaveCalendarMonth",{bindings:{showTheseContacts:"<",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/models/contact","common/models/session.model","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,i,r,c,u,l,d,m){function f(){a.resolve().then(_).then(C).then(function(){return y()&&"admin"!==O.role&&P()}).then(R).finally(function(){O.loading.component=!1})}function p(t){L=O.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===O.leaveRequest.request_type?i.open(q(t)):g(t)}function v(){return"admin"===O.role&&"public_holiday"===O.leaveRequest.request_type}function h(n){var a=O.absenceTypes[O.leaveRequest.type_id].allow_request_cancelation;return"admin"===O.role||("manager"===O.role?e.includes([M.awaitingApproval,M.moreInformationRequired],n):"3"===a?t().isBefore(O.leaveRequest.from_date):"2"===a)}function g(t){i.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return O.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(c.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){A(t)}}):q(t)})}})}function b(){return s.find(I).then(function(e){return e.checkIfSelfLeaveApprover()})}function y(){return I===O.leaveRequest.contact_id}function _(){e.isArray(O.leaveRequestStatuses)&&(O.leaveRequestStatuses=e.indexBy(O.leaveRequestStatuses,"value")),e.isArray(O.absenceTypes)&&(O.absenceTypes=e.indexBy(O.absenceTypes,"id"))}function q(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 O.leaveRequest[e]().then(function(){D(e)}).catch(function(e){d.error("Error:",e)})}}}function C(){return m.get().then(function(e){I=e.contactId})}function T(e,t){e.stopPropagation(),r.openModal(t)}function A(e){r.openModal({leaveRequest:O.leaveRequest,leaveType:O.leaveRequest.request_type,selectedContactId:O.leaveRequest.contact_id,forceRecalculateBalanceChange:!0,defaultStatus:l.statusNames[$[e]]})}function D(t){var n=e.find(O.leaveRequestStatuses,function(e){return e.name===l.statusNames.awaitingApproval}).value;L===n&&u.publish("ManagerBadge:: Update Count"),u.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:O.leaveRequest})}function R(){var t=O.leaveRequestStatuses[O.leaveRequest.status_id].name,n=e.compact(e.map(w,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!h(t)&&e.pull(n,"cancel"),"admin"!==O.role&&e.pull(n,"delete"),"staff"===O.role&&e.pull(n,"approve","reject"),"staff"!==O.role&&S(n),v()&&n.push("delete"),O.allowedActions=e.map(n,function(e){return{key:e,label:w[e].label,isDirectAction:w[e].isDirectAction}})}function P(){return b().then(function(e){e&&(O.role="admin")})}function S(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 I,L,O=this,M=l.statusNames,w={edit:{label:"Edit",allowedStatuses:[M.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[M.moreInformationRequired]},view:{label:"View",allowedStatuses:[M.approved,M.rejected,M.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[M.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[M.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[M.awaitingApproval,M.approved,M.rejected,M.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[M.awaitingApproval,M.moreInformationRequired,M.approved,M.rejected,M.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}},$={approve:"approved"};O.allowedActions=[],O.loading={component:!0},O.$onInit=f,O.action=p,O.openLeavePopup=T}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","$q","$rootScope","Contact","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService","Session"]}),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,i,r,c){function u(){o.$emit("LeaveRequestPopup::addTab",C),y(),_()}function l(){C.request.comments.push({contact_id:q,leave_request_id:C.request.id,text:C.comment.text}),C.comment.text=""}function d(){return C.comment.text.length>0}function m(e){return!e.comment_id||C.canManage}function f(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function p(){return C.request.comments.filter(function(e){return!e.toBeDeleted})}function v(e){return e===q?"Me":C.comment.contacts[e]?C.comment.contacts[e].display_name:void 0}function h(e){return C.mode===e}function g(){C.comment.text.length&&C.addComment()}function b(){var t=e.indexBy(C.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){C.comment.contacts=e.indexBy(t.list,"contact_id")})}function y(){return C.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),C.request.comments.length&&b()})}function _(){return C.loading.component=!0,c.get().then(function(e){q=e.contactId}).then(function(){C.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var q=null,C=this;C.loading={component:!0},C.comment={text:"",contacts:{}},C.$onInit=u,C.addComment=l,C.canRemoveComment=m,C.canSubmit=d,C.formatDateTime=f,C.getActiveComments=p,C.getCommentorName=v,C.isMode=h,C.onBeforeSubmit=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/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,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).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,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).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,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(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,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.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,o,s,i,r,c,u,l,d,m){function f(){n("RequestModalDetails"+e.capitalize(T(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(),k()])}).then(!ne.isMode("create")&&S).then(Y).then(function(){if(!ne.isMode("create"))return i.resolve().then(ne.initTimesExtended).then(z)}).then(!ne.isMode("create")&&W).then(L).then(G).then(P).then(O).then(!ne.isMode("view")&&ne.initWatchersExtended).catch(R).then(function(){ne.pagination.filteredbreakdown=ne.balance.change.breakdown,ne.pagination.totalItems=ne.balance.change.breakdown.length}).finally(function(){ne.loading.tab=!1})}function p(){ne.balance.closing=ne.balance.opening+ne.balance.change.amount}function v(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function g(e){var t;return i.resolve().then(function(){j(e),"from"===e&&U(),M("hours")&&(_(e),"from"!==e||ne.uiOptions.multipleDays||_("to")),ne.loading[e+"DayTypes"]=!0}).then(function(){return C(e)}).then(function(e){if(t=e.id!==ne.period.id,t&&(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(t)return x()}).then(function(){return ne.onDateChangeExtended&&ne.onDateChangeExtended(e)}).then(function(){if(z(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(R).finally(q)}function b(){return z(),E()}function y(){return ne.uiOptions.toDate=null,j("to"),i.resolve().then(z).then(ne.setDaysSelectionModeExtended).then(q).then(!ne.uiOptions.multipleDays&&E)}function _(e){ne.uiOptions.times[e].loading=!0}function q(){["from","to"].forEach(function(e){ne.loading[e+"DayTypes"]=!1,M("hours")&&(ne.uiOptions.times[e].loading=!1)})}function C(n){var a=t(ne.uiOptions[n+"Date"]).format(ne.uiOptions.userDateFormat.toUpperCase());return e.find(ne.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function T(){return ne.request?ne.request.request_type:ne.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return X(),ne.loading.balanceChange=!0,ne.request.getBalanceChangeBreakdown().then(H).catch(R)}function R(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),ne.loading.fromDayTypes=!1,ne.loading.balanceChange=!1,ne.loading.tab=!1,ne.loading.toDayTypes=!1}function P(){return ne.isMode("create")||ne.forceRecalculateBalanceChange?E():D()}function S(){var e=ne.request.attributes();return ne.uiOptions.fromDate=v(ne.request.from_date),ne.request.to_date=e.to_date,ne.request.to_date_type=e.to_date_type,ne.uiOptions.toDate=v(ne.request.to_date),ne.initDayTypesExtended?ne.initDayTypesExtended():i.resolve()}function I(){te.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){K(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function L(){ne.isMode("edit")&&(ne.isLeaveStatus(c.statusNames.approved)||ne.isLeaveStatus(c.statusNames.adminApproved))&&(ee={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,t){e!==t&&(ne.uiOptions.multipleDays||(Z(e),z()))})}function M(e){return ne.selectedAbsenceType.calculation_unit_name===e}function w(e){return ne.request.request_type===e}function $(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function k(){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 B(){var e=(ne.pagination.currentPage-1)*ne.pagination.numPerPage,t=e+ne.pagination.numPerPage;ne.pagination.filteredbreakdown=ne.balance.change.breakdown.slice(e,t)}function E(){return X(),ne.canCalculateChange()?(ne.loading.balanceChange=!0,ne.request.change_balance=!0,ne.calculateBalanceChange().then(H).catch(R).finally(function(){ne.loading.balanceChange=!1})):i.resolve()}function F(){ne.pagination.totalItems=ne.balance.change.breakdown.length,ne.pagination.filteredbreakdown=ne.balance.change.breakdown,ne.pagination.pageChanged()}function N(){return h(ne.request.from_date)===h(ne.request.to_date)}function U(){ne.uiOptions.toDate&&ne.uiOptions.fromDate&&ne.uiOptions.multipleDays&&t(ne.uiOptions.toDate).isSameOrBefore(ne.uiOptions.fromDate)&&(ne.uiOptions.toDate=null,j("to"))}function j(e){ne.resetUIInputsExtended&&ne.resetUIInputsExtended(e),z(),X()}function H(e){ne.balance.change=e,ne.request.balance_change=e.amount,p(),F(),ne.loading.balanceChange=!1}function W(){var e,n,a;ne.uiOptions.fromDate?(e=t(ne.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=v(ne.period.start_date),n=ne.uiOptions.date.to.options.minDate),ne.uiOptions.date.to.options.initDate=n,ne.uiOptions.date.to.options.minDate=a,ne.uiOptions.date.to.options.maxDate=v(ne.period.end_date)}function Y(){return!ne.isMode("create")&&N()||ne.isMode("create")&&(w("sickness")||M("hours"))?ne.uiOptions.multipleDays=!1:ne.uiOptions.multipleDays=!0,i.resolve().then(ne.setDaysSelectionModeExtended)}function G(){ee&&ee.absenceTypeId===ne.selectedAbsenceType.id?ne.balance.opening=ee.value||0:ne.balance.opening=ne.selectedAbsenceType.remainder}function V(){ne.selectedAbsenceType=e.find(ne.absenceTypes,function(e){return e.id===ne.request.type_id})}function z(){var e=ne.uiOptions,t=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),(M("hours")||w("toil"))&&(ne.request.from_date=ne.request.from_date&&t.from.time?ne.request.from_date+" "+t.from.time:null,ne.request.to_date=ne.request.to_date&&t.to.time?ne.request.to_date+" "+t.to.time:null)}function X(){ne.uiOptions.showBalance=ne.canCalculateChange()}function Q(){e.forEach(te,function(e){e()})}function J(){var e,t=ne.selectedAbsenceType.calculation_unit_name;return V(),e=t!==ne.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&Y).then(e&&ne.onAbsenceTypeUpdateExtended).then(e&&z).then(q).then(E)}function K(e){return ne.absenceTypes=e,V(),t(ne.uiOptions.toDate).isAfter(ne.period.end_date)&&(ne.uiOptions.toDate=void 0,j("to")),G(),E()}function Z(e){var t=A(e).add(ne.uiOptions.time_interval,"minutes");t.isAfter(A(ne.uiOptions.times.to.max))||(ne.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(ne.uiOptions.times.to.time))&&(ne.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var ee=null,te=[],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:[],numPerPage:7,totalItems:0,pageChanged:B},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.$onInit=f,ne.convertDateFormatFromServer=v,ne.convertDateToServerFormat=h,ne.dateChangeHandler=g,ne.dateTypeChangeHandler=b,ne.daysSelectionModeChangeHandler=y,ne.disableAndShowLoadingTimeInput=_,ne.getMomentDateWithGivenTime=A,ne.handleError=R,ne.isCalculationUnit=M,ne.isLeaveType=w,ne.isNotWorkingDay=$,ne.performBalanceChangeCalculation=E,ne.setRequestDateTimesAndDateTypes=z,ne.updateEndTimeInputMinTime=Z,ne.$onDestroy=Q}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,o,s,i,r,c,u,l){function d(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),y(),a.all([A(),C()]).then(_).finally(function(){O.filesLoaded=!0})}function m(){return O.fileUploader&&O.fileUploader.queue.length>0}function f(){return O.getFilesAmount()0?S.map(function(e){return e.label}).join(", "):""}function C(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function T(){return a.all(S.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){L[e.label]=t})})).catch(function(){L=null})}function A(){return c.valuesOf("safe_file_extension").then(function(e){S=e})}function D(e){return!e.attachment_id||O.canManage}function R(){e.forEach(I,function(e){e()})}function P(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var S=[],I=[],L={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=R,O.$onInit=d,O.canRemoveAttachment=D,O.canSubmit=m,O.canUploadMore=f,O.formatDateTime=p,O.getAuthorName=v,O.getFilesAmount=h,O.listFileTypes=q,O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(){s=n.parse(),s.openModal&&o({leaveType:s.openModal,selectedContactId:i.selectedContactId})}function o(e){t.openModal(e)}e.debug("Component: leave-request-record-actions");var s,i=this;i.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],i.$onInit=a,i.openLeavePopup=o}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,o,s,i,r,c,u,l,d,m){"use strict";function f(){s(r.permissions.admin.administer).then(function(e){H.isAdmin=e,n.all([A(),D(),M(),P(),L(),I(),w()]).then(function(){H.loading.page=!1,R()}),U()})}function p(){H.filters.leaveRequest.contact_id=null,H.refresh()}function v(){var e=H.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?H.leaveRequests.filter.list.length:H.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function g(t){return e.find(H.absenceTypes,{id:t})}function b(e){return new Array(e||0)}function y(t){var n=e.find(H.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function _(e){switch(e){case r.statusNames.approved:return"badge-success";case r.statusNames.rejected:return"badge-danger";case r.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function q(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}function C(t){var n=e.find(H.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function T(e){return e.current?"Current Period ("+e.title+")":e.title}function A(){return c.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.filters.leaveRequest.selectedPeriod=e.find(H.absencePeriods,function(e){return!!e.current})})}function D(){return u.all().then(u.loadCalculationUnits).then(function(e){H.absenceTypes=e})}function R(e){return(H.isAdmin?o.all(v()):o.leaveManagees(H.contactId,v())).then(function(t){return H.filteredUsers=H.isAdmin?t.list:t,e?S(e):n.all([S("table"),S("filter")])}).then(function(){H.filters.leaveRequest.leaveStatus!==W&&0===H.leaveRequests.table.list.length&&H.refresh(1,!0)})}function P(){return i.valuesOf("hrjc_department").then(function(e){H.departments=e})}function S(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:H.pagination,o="filter"===e?{return:["status_id"]}:{};return H.loading[n]=!0,l.all(O(t),a,"from_date DESC",o,!1).then(function(t){H.leaveRequests[e]=t}).catch(function(){H.leaveRequests[e].list=[]}).finally(function(){H.loading[n]=!1})}function I(){return i.valuesOf("hrjc_level_type").then(function(e){H.levelTypes=e})}function L(){return i.valuesOf("hrjc_location").then(function(e){H.locations=e})}function O(t){var n=H.filters.leaveRequest;return{contact_id:k(),managed_by:H.isAdmin&&"me"!==n.assignedTo.type?void 0:H.contactId,status_id:B(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(H.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function M(){return i.valuesOf("hrjc_region").then(function(e){H.regions=e})}function w(){return i.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){H.leaveRequestStatuses=e.concat(H.leaveRequestStatuses)})}function $(e){d.openModal(e)}function k(){return H.filteredUsers.length>0&&H.filters.leaveRequest.contact_id?H.filters.leaveRequest.contact_id:{IN:H.filteredUsers.map(function(e){return e.id})}}function x(e){var t=[q(r.statusNames.moreInformationRequired),q(r.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function B(e){var t=H.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=x(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(H.filters.leaveRequest.leaveStatus=W),(e<=H.totalNoOfPages()||0===H.totalNoOfPages())&&(H.pagination.page=e,R(n))}function F(e){H.filters.leaveRequest.leaveStatus=e,H.refresh(1,!1,"table")}function N(e){H.filters.leaveRequest.assignedTo=e,H.refresh()}function U(){m.subscribe("LeaveRequest::updatedByManager",function(){H.refresh()}),m.subscribe("LeaveRequest::new",function(){H.refresh()}),m.subscribe("LeaveRequest::edit",function(){H.refresh()}),m.subscribe("LeaveRequest::delete",function(){H.refresh()}),m.subscribe("LeaveRequest::statusUpdate",function(){H.refresh()})}function j(){return Math.ceil(H.leaveRequests.table.total/H.pagination.size)}t.debug("Component: manage-leave-requests");var H=this,W={name:"all",label:"All"};H.absencePeriods=[],H.absenceTypes=[],H.filteredUsers=[],H.isFilterExpanded=!1,H.isAdmin=!1,H.leaveRequests={table:{list:[]},filter:{list:[]}},H.leaveRequestStatuses=[W],H.loading={content:!0,page:!0,table:!0},H.pagination={page:1,size:7},H.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],H.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:H.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:H.filtersByAssignee[0]}},H.$onInit=f,H.clearStaffSelection=p,H.countLeaveRequestByStatus=h,H.getAbsenceTypeByID=g,H.getArrayOfSize=b,H.getLeaveStatusByValue=y,H.getNavBadge=_,H.getUserNameByID=C,H.labelPeriod=T,H.openLeavePopup=$,H.refresh=E,H.refreshWithFilter=F,H.refreshWithFilterByAssignee=N,H.totalNoOfPages=j}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function d(){return i.canCalculateChange()}function m(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.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}function f(t,n){return t?(t=i.convertDateToServerFormat(t),h(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return S(n,e),e})):o.reject([])}function p(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.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 v(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function g(){return o.resolve()}function b(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function y(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),O(),i.performBalanceChangeCalculation())})}function _(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(v(a.min,n)<=0||v(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(R)).then(function(){["from","to"].forEach(function(e){_(e),L(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(O)}function C(){["from","to"].forEach(function(e){y(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&L(e,!0))})}function A(e,t){return f(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return R(e).then(function(){L(e,!0)})})}function R(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){w[e]=t,m(e,t),n&&"from"===e&&m("to",t)}).catch(function(t){return w[e]={},i.handleError(t)}).finally(function(){i.uiOptions.times[e].loading=!1,n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function S(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function I(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),R("from").then(function(){L("from",!0)})):o.resolve()}function L(e,t){var n=i.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,c=w[a].number_of_hours?v(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function O(){var e=i.uiOptions.times +;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function M(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?R("from").then(function(){L("from",!0)}):o.resolve()}var w={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=g,i.initDayTypesExtended=b,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=M,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=I}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),v(),f(!0)])}function l(t){var n=r.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function d(t){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===t})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(t){return i.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){r.sicknessReasons=e.indexBy(t,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function v(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=U.from_date!==c.request.from_date||U.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function v(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function h(){var e=c.uiOptions.multipleDays,t=c.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=c.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function y(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",_().then(b).then(C).then(S)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&c.isCalculationUnit("hours")&&M(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),F(),l(),w())})})}function P(){c.isMode("view")||(T(),A(),R())}function S(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function I(){return l(),w(),F()}function L(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:w(),F()}function O(e){c.uiOptions.times[e].time=""}function M(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function w(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function $(){U=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),w(),c.isCalculationUnit("hours")?M():c.request.toil_to_accrue=null}function B(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){S(!1)})}function E(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function N(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,j=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=v,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=I,c.openToilInDaysAccrualOptionsEditor=B,c.resetUIInputsExtended=O,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=N,function(){$(),k(),E(),!c.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,t,n){"use strict";function a(n,a,o,s){function i(n){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var t=e.get(n,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return n.lookupContacts=e,a.all([d(),"me"!==t?u():a.resolve(null)])}).then(function(e){var t=e[0];return n.contactIdsToReduceTo=e[1],t})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return t(a.period_start_date).isSameOrBefore(n.selectedPeriod.end_date)&&(t(a.period_end_date).isSameOrAfter(n.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return h?a.resolve(h):s.all()}function d(){return o.all(v(),null,"display_name").then(function(e){return e.list})}function m(){var t=e.get(n,"filters.userSettings.assignedTo.type","all");return(0,g[t])()}function f(){return m().then(function(e){n.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(n.contactId)}function v(){var t={department:e.get(n,"filters.userSettings.department.value",null),level_type:e.get(n,"filters.userSettings.level_type.value",null),location:e.get(n,"filters.userSettings.location.value",null),region:e.get(n,"filters.userSettings.region.value",null)},a=!!n.filters.userSettings.contact,o=e.isArray(n.lookupContacts)&&n.lookupContacts.length,s="all"!==e.get(n,"filters.userSettings.assignedTo.type","all");return a?t.id={IN:[n.filters.userSettings.contact.id]}:(s||o)&&(t.id={IN:e.pluck(n.lookupContacts,"id")}),t}var h,g={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return n.debug("LeaveCalendarService"),{init:i}}n.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(n){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return n.contact_id&&n.period_id||o.reject("contact_id and period_id are mandatory"),n=t.defaults(n,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",n,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){return e.debug("LeaveRequestAPI.update",t),t.id?this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([h.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return n.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,v,h,g,b,y,_,q,C){function T(e){"days"===Ne.selectedAbsenceType.calculation_unit_name?delete Ne.request[e+"_date_amount"]:delete Ne.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return Me.checkIfSelfLeaveApprover().then(function(e){e&&(Ee="admin")})}function R(){var e=Ne.requestStatuses[y.statusNames.awaitingApproval].value;ke.status_id===e&&e!==Ne.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!Ne.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ne.isMode("edit")&&(e=e&&(G()||S())),Ne.canManage&&Ne.requestStatuses&&(e=e&&!!Ne.getStatusFromValue(Ne.newStatusOnSave)),(e=e&&!!Ne.period.id)&&!Ne.isMode("view")}function O(){Ne.isSelfRecord&&!Ne.isSelfLeaveApprover?Ne.request.status_id=Ne.requestStatuses[y.statusNames.awaitingApproval].value:Ne.canManage&&(Ne.request.status_id=Ne.newStatusOnSave||Ne.request.status_id)}function M(){if(Ne.isMode("edit")&&!Ne.isRole("staff")&&"toil"!==j())return Ne.request.calculateBalanceChange(Ne.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ne.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function w(){return"toil"!==j()&&!Ne.request.change_balance}function $(){Ne.errors=[]}function k(){return Ne.request.create().then(Pe).then(function(){be("LeaveRequest::new")})}function x(){se()&&!Ne.isRole("staff")&&(Ne.request.change_balance=!0)}function B(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ne.request.delete().then(function(){Ne.dismissModal(),d.publish("LeaveRequest::delete",Ne.request)})}})}function E(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return U(Ne.getStatusFromValue(Ne.request.status_id).name)}function U(e){return n.map(we[e],function(e){return Ne.requestStatuses[e]})}function j(){return Ne.request?Ne.request.request_type:Ne.leaveType||null}function H(){return!Ne.request||e.equals({},Ne.requestStatuses)?[]:Ne.request.status_id?N():U("none")}function W(e){return n.find(Ne.requestStatuses,function(t){return t.value===e})}function Y(e){Ne.errors=n.isArray(e)?e:[e],Ne.loading.absenceTypes=!1,Ne.submitting=!1}function G(){return!e.equals(ke,Ne.request.attributes())||Ne.canManage&&Ne.newStatusOnSave}function V(){return Ne.postContactSelection=!0,Ne.staffMemberSelectionComplete=!1,Ne.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ne.isMode("edit")?Te:n.noop).then(function(){Ne.postContactSelection=!1,Ne.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Be)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];we.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],we.awaiting_approval=e,we.more_information_required=e,we.rejected=e,we.approved=e,we.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ne.canManage=Ne.isRole("manager")||Ne.isRole("admin")}function Q(){return Ne.canManage?f.find(Ne.request.contact_id).then(function(e){Ne.contactName=e.display_name}):o.resolve()}function J(){Ne.isRole("admin")&&Ne.isSelfRecord&&(Ne.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,t=+Me.id==+n.get(Ne,"leaveRequest.contact_id"),a=!n.get(Ne,"leaveRequest.id");Ne.isSelfRecord=e&&a||t}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ne.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){Y(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){$e++})),i.$on("$destroy",Se),i.$on("LeaveRequestPopup::addTab",function(e,t){Fe.push(t)})}function ee(){var e,t;Ne.request=Ne.leaveRequest||null,e=j(),t=Ne.initRequestAttributes(),"leave"===e?Ne.request=b.init(t):"sickness"===e?Ne.request=_.init(t):"toil"===e&&(Ne.request=q.init(t))}function te(){var e={};return Ne.request?e=Ne.request.attributes():Ne.canManage||(e={contact_id:Me.id}),e}function ne(){return Ee="staff",ae().then(Ne.isSelfRecord&&!Ne.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Ee="admin")}).then(function(){return"admin"!==Ee&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Ee="manager")})}function oe(){Ne.defaultStatus?Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames[Ne.defaultStatus]].value:(Ne.isRole("admin")||Ne.isMode("create")&&Ne.isRole("manager"))&&(Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames.approved].value)}function se(){return!Ne.request.status_id||!n.includes(["cancelled","rejected"],W(Ne.request.status_id).name)}function ie(e){var t=Ne.getStatusFromValue(Ne.request.status_id);return!!t&&t.name===e}function re(e){return Ne.request&&Ne.request.request_type===e}function ce(e){return Ne.mode===e}function ue(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date,"day")&&o.isSameOrBefore(t.end_date,"day")}function le(e){return Ee===e}function de(){return p.all().then(function(e){Ne.absencePeriods=e})}function me(){return v.all(F()).then(v.loadCalculationUnits).then(function(e){Oe={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ne.loading.entitlements=!0,h.all({contact_id:Ne.request.contact_id,period_id:Ne.period.id,type_id:{IN:Oe.ids}},!0).finally(function(){Ne.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){Me=e})}function ve(){return Ne.selectedContactId?f.find(Ne.selectedContactId).then(function(e){Ne.managedContacts=[e]}):Ne.isRole("admin")?f.all().then(function(e){console.log(e.list),Ne.managedContacts=e.list}):Me.leaveManagees().then(function(e){Ne.managedContacts=e})}function he(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ne.requestStatuses=n.indexBy(e,"name")})}function ge(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function be(e){R(),d.publish(e,Ne.request),Ne.errors=[],Ne.dismissModal()}function ye(){["from","to"].forEach(function(e){Ne.request[e+"_date"]=ke[e+"_date"]})}function _e(e){if(Ne.absenceTypes=ge(Oe.types,e),!Ne.absenceTypes.length)return o.reject(Be)}function qe(){Ne.period=n.find(Ne.absencePeriods,function(e){return Ne.isMode("create")?e.current:ue(Ne.request,e)})}function Ce(){Ne.isMode("create")?(Ne.selectedAbsenceType=Ne.absenceTypes[0],Ne.request.type_id=Ne.selectedAbsenceType.id):Ne.selectedAbsenceType=n.find(Ne.absenceTypes,function(e){return e.id===Ne.request.type_id})}function Te(){ke=e.copy(Ne.request.attributes())}function Ae(){var e;Ne.request.id?(e=[Ne.requestStatuses[y.statusNames.approved].value,Ne.requestStatuses[y.statusNames.adminApproved].value,Ne.requestStatuses[y.statusNames.rejected].value,Ne.requestStatuses[y.statusNames.cancelled].value],Ne.mode="edit",Ne.isRole("staff")&&e.indexOf(Ne.request.status_id)>-1&&(Ne.mode="view")):Ne.mode="create"}function De(){var e=Ne.request.status_id;if(!Ne.isMode("view")&&!Ne.submitting)return Ne.submitting=!0,O(),A(),Ne.request.isValid().then(se()&&M).then(x).then(w()&&ye).then(Re).then(function(){return Ne.isMode("edit")?Le():k()}).catch(function(t){ +Ne.request.status_id=e,t&&Y(t)}).finally(function(){Ne.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&n.push(e),++a===$e&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return $e>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Se(){xe.forEach(function(e){e()})}function Ie(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ne.request.update().then(Pe).then(function(){Ne.isRole("manager")?be("LeaveRequest::updatedByManager"):(Ne.isRole("staff")||Ne.isRole("admin"))&&be("LeaveRequest::edit")})}t.debug("RequestCtrl");var Oe,Me,we={},$e=0,ke={},xe=[],Be="No entitlement",Ee="",Fe=[],Ne=n.assign(this,m);Ne.absencePeriods=[],Ne.absenceTypes=[],Ne.canManage=!1,Ne.contactName=null,Ne.errors=[],Ne.isSelfLeaveApprover=!1,Ne.loading={absenceTypes:!0,entitlements:!0},Ne.managedContacts=[],Ne.mode="",Ne.newStatusOnSave=null,Ne.period={},Ne.postContactSelection=!1,Ne.requestStatuses={},Ne.selectedAbsenceType={},Ne.staffMemberSelectionComplete=!1,Ne.submitting=!1,Ne.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ne.canChangeAbsenceType=I,Ne.canSubmit=L,Ne.closeAlert=$,Ne.deleteLeaveRequest=B,Ne.dismissModal=E,Ne.getStatuses=H,Ne.getStatusFromValue=W,Ne.initAfterContactSelection=V,Ne.initRequestAttributes=te,Ne.isLeaveStatus=ie,Ne.isLeaveType=re,Ne.isMode=ce,Ne.isRole=le,Ne.submit=De,Ne.updateAbsenceType=Ie,function(){Ne.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([ne(),de(),he()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ne.canManage&&!Ne.isMode("edit")&&ve()}).then(function(){if(Ne.selectedContactId&&(Ne.request.contact_id=Ne.selectedContactId),Ne.request.contact_id)return Ne.initAfterContactSelection()}).catch(Y).finally(function(){Ne.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(o.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var o=this;o.tabName=n.current.name,o.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e,t){define("leave-absences/manager-leave/modules/config",["common/angular","common/lodash","leave-absences/manager-leave/modules/settings"],function(t,n){function a(t){t.withAutoBase(!0),t.settings.ga={userId:n.get(e,"vars.session.contact_id")}}return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","$analyticsProvider","settings",function(t,n,o,s,i,r,c){s.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.defaults.stripTrailingSlashes=!1,o.otherwise("/manager-leave/requests"),a(r),i.debugEnabled(c.debug),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM,Drupal),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/angulartics","common/angulartics-google-tag-manager","common/angularUiRouter","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","angulartics","angulartics.google.tagmanager","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/my-leave.min.js index 5485d3bd042..6c1c264aba6 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/my-leave.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){e.config({paths:{mocks:"../test/mocks"}}),e.config({paths:{mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(n){return n.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",sourcePath:e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,t,a){return e.debug("AbsencePeriodInstance"),t.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var t=n();return e.current=!1,n(e.start_date).isSameOrBefore(t,"day")&&n(e.end_date).isSameOrAfter(t,"day")&&(e.current=!0),e},isInPeriod:function(e){var t=a.DATE_FORMAT.toUpperCase(),o=n(e,t);return n(this.start_date).isSameOrBefore(o)&&n(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,n){return e.debug("AbsencePeriodAPI"),n.extend({all:function(n){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,t,a,o,s){return e.debug("AbsencePeriod"),t.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=n().format(s.serverDateFormat),t={start_date:{"<=":e},end_date:{">=":e}};return a.all(t).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,n,t){"use strict";t.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(t,a,o){return t.debug("AbsenceTypeAPI"),a.extend({all:function(n){return t.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(n||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return t.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:n(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,n){return e.debug("AbsenceTypeInstance"),n.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,n){"use strict";n.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(n,t,a,o,s,i){return n.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,n,t){return s.calculateToilExpiryDate(e,n,t)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(n){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(t){return t=e.indexBy(t,"value"),e.map(n,function(n){return e.assign(n,{calculation_unit_label:t[n.calculation_unit].label,calculation_unit_name:t[n.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,n){"use strict";n.factory("WorkPatternAPI",["$log","api",function(n,t){function a(n){var t=e.clone(n);return t.workPattern=t["api.WorkPattern.get"].values[0],delete t["api.WorkPattern.get"],t}return n.debug("WorkPatternAPI"),t.extend({assignWorkPattern:function(n,t,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:n,pattern_id:t,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(t,a,o,s){return n.debug("WorkPatternAPI.getCalendar",t,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(t)?{IN:t}:t,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(n,t,o){return this.sendGET("ContactWorkPattern","get",e.assign({},t,{contact_id:n,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).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,n,t){"use strict";t.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(t,a,o,s,i){function r(n,t){return u().then(function(a){var o=this.days[c(n).valueOf()];return!!o&&e.find(a,function(e){return e.name===t}).value===o.type}.bind(this))}function c(e){return n(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(n){var t={};return n.calendar.forEach(function(e){t[c(e.date).valueOf()]=e}),e(n).omit("calendar").assign({days:t}).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,n){"use strict";n.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(n,t,a,o){return n.debug("Calendar"),t.extend({get:function(t,s,i,r){return n.debug("Calendar.get"),a.getCalendar(t,s,i,r).then(function(n){var a=n.values.map(function(e){return o.init(e)});return e.isArray(t)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,t){function a(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(t.remainder=a[0].remainder),delete t["api.LeavePeriodEntitlement.getremainder"],t}function o(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return t.value=a,delete t["api.LeavePeriodEntitlement.getentitlement"],t}return e.debug("EntitlementAPI"),t.extend({all:function(n,t){return e.debug("EntitlementAPI.all"),n["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},t&&(n["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",n,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),t&&(e=e.map(a)),e})},breakdown:function(n){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",n).then(function(e){return e.values})},getLeaveBalances:function(n,t,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",n,t,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,n){return e.debug("EntitlementLogAPI"),n.extend({all:function(n){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",n,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,n,t){return e.debug("EntitlementInstance"),n.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return t.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,n){"use strict";n.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(n,t,a,o,s){return n.debug("Entitlement"),t.extend({all:function(e,n){return a.all(this.processFilters(e),n).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(n,t){return a.breakdown(n).then(function(n){return t?(t.map(function(t){var a=e.find(n,function(e){return e.id===t.id});return a&&(t.breakdown=a.breakdown),t}),t):n.map(function(e){return o.init(e,!0)})})},logs:function(n){return n=e.cloneDeep(n||{}),n.contact_id&&(n["entitlement_id.contact_id"]=n.contact_id,delete n.contact_id),n.period_id&&(n["entitlement_id.period_id"]=n.period_id,delete n.period_id),n.return=n.return||[],n.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(n)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,t,a){return e.debug("LeaveRequestAPI"),t.extend({all:function(n,t,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return n&&n.contact_id&&n.contact_id.IN&&0===n.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",n,t,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return t.contact_id&&t.period_id||o.reject("contact_id and period_id are mandatory"),t=n.defaults(t,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",t,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange",t),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){return e.values.breakdown=n.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,n){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:n.toString()},!1)},create:function(n){return e.debug("LeaveRequestAPI.create",n),this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,attachment_id:t}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,t){return t=n.assign({},t,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",t).then(function(e){return e.values})},find:function(n){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:n},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",t,!1).then(function(e){return e.values})},getComments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",t,!1).then(function(e){return e.values})},isManagedBy:function(n,t){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:n,contact_id:t}).then(function(e){return e.values})},isValid:function(t){e.debug("LeaveRequestAPI.isValid",t);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",t).then(function(e){e.count>0?o.reject(n(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,text:t.text,contact_id:t.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(n){return e.debug("LeaveRequestAPI.update",n),n.id?this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,n,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(t,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var n=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=n,t.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return t.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function f(e){return n.duration(e.time_to).subtract(n.duration(e.time_from)).asHours()}function p(n){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return e.find(t,function(e){return e.name===n})})}function h(n){var a=e.cloneDeep(n),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return t.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(n){return s.amount=n[0].time_from?Math.min(this.from_date_amount,f(n[0])):0,o&&(i.amount=n[1].time_from?Math.min(this.to_date_amount,f(n[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,n){return e+n.amount},0),a}.bind(this))}function v(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(n){return function(){return r.saveComment(e,n)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),t.all(n)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(n){var t=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===n&&e.pull(t,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,t)).then(function(e){return"hours"===n?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return t.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(n){if(n.comment_id)return void(n.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return n.created_at===e.created_at&&n.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(n){return{amount:e.reduce(n.values,function(e,n){return e+parseFloat(n.amount)},0),breakdown:n.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return t.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):a(s.permissions.admin.administer).then(function(n){return n?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):t.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,n,t,a){return e.debug("LeaveRequest"),n.extend({all:function(e,n,o,s,i){return t.all(this.processFilters(e),n,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return t.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return t.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,n){return e.debug("PublicHolidayAPI"),n.extend({all:function(n){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,n){return e.debug("PublicHolidayInstance"),n.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,n){"use strict";n.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(n,t,a,o,s){return n.debug("PublicHoliday"),t.extend({all:function(e){return n.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(t){n.debug("PublicHoliday.isPublicHoliday",t);var o=e(t).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,n,t){function a(n,t,a,o,s,i,r){function c(){return{loadContacts:function(){return l.loadContactsForAdmin()}}}function u(e){i.info("",["

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 l,d;return{init:function(n){return d=n,l=r.init(d),d.filters.userSettings.assignedTo=e.find(d.filtersByAssignee,{type:"me"}),d.showContactDetailsLink=!0,d.showContactName=!0,d.showFilters=!0,d.showAdminFilteringHint=u,c()}}}t.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService","LeaveCalendarService",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(n,t,a,o){function s(){return{loadContacts:function(){return i.loadLookUpAndFilteredContacts()}}}n.debug("LeaveCalendarManagerController");var i,r;return{init:function(n){return r=n,i=o.init(r),r.filters.userSettings.assignedTo=e.find(r.filtersByAssignee,{type:"me"}),r.showContactName=!0,r.showFilters=!0,s()}}}t.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance","LeaveCalendarService",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,t,a){function o(){return{loadContacts:function(){return i.displaySingleContact?s.loadFilteredContacts():"admin"===i.userPermissionRole?s.loadContactsForAdmin():s.loadLookUpAndFilteredContacts()}}}e.debug("LeaveCalendarStaffController");var s,i;return{init:function(e){return i=e,s=a.init(i),i.filters.userSettings.contacts_with_leaves=!0,i.showTheseContacts=[i.contactId],i.showContactName=!0,i.showFilters=!0,i.displaySingleContact&&(i.showFilters=!1,i.lookupContacts=[{id:i.contactId}]),o()}}}t.controller("LeaveCalendarStaffController",["$log","$q","Contact","LeaveCalendarService",a])}),define("leave-absences/shared/components/leave-calendar.component",["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){function a(t,a,o,s,i,r,c,u,l,d){function m(){N().then(g).then(b).then(_).then(S).then(function(){return a.all([C(),D(),I(),W.showFilters?R():e.noop])}).then(function(){f(),y(),B()}).then(function(){W.loading.page=!1})}function f(){W.supportData.absenceTypes.push({id:"",title:"Leave",color:"#4D4D68",calculation_unit:e.chain(W.supportData.calculationUnits).find({name:"days"}).get("value").value()})}function p(){for(var e=[],t=n(W.selectedPeriod.start_date).clone().startOf("month"),a=n(W.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(L(t)),t.add(1,"month");W.months=e}function h(){return e.includes(["admin","manager"],W.userPermissionRole)}function v(e){return e.format("YYYY-MM")}function b(){s.$on("LeaveCalendar::updateFiltersByAbsenceType",function(e,n){W.supportData.absenceTypesToFilterBy=n,M(!0)})}function g(){s.$new().$watch(function(){return W.selectedMonthIndex},function(e,n){null!==n&&e!==n&&(F(),B(),M())})}function y(e){W.injectMonth=!0,j("injected").then(function(){M(e)}).then(function(){W.loading.calendar=!1})}function _(){U=t("LeaveCalendar"+e.capitalize(H)+"Controller").init(W)}function q(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return r.all().then(function(n){W.absencePeriods=e.sortBy(n,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current})}).then(p).then(x)}function T(){return c.all().then(c.loadCalculationUnits)}function A(){return l.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function D(){return U.loadContacts().then(function(e){W.contacts=e})}function R(){return l.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){W.filters.optionValues.regions=e.hrjc_region,W.filters.optionValues.locations=e.hrjc_location,W.filters.optionValues.levelTypes=e.hrjc_level_type,W.filters.optionValues.departments=e.hrjc_department})}function P(){return u.all()}function I(){return a.all([T(),P(),A()]).then(function(n){W.supportData.absenceTypes=n[0],W.supportData.publicHolidays=n[1],W.supportData.calculationUnits=n[2].hrleaveandabsences_absence_type_calculation_unit,W.supportData.dayTypes=n[2].hrleaveandabsences_leave_request_day_type,W.supportData.leaveRequestStatuses=n[2].hrleaveandabsences_leave_request_status,W.supportData.toilAmounts=e.indexBy(n[2].hrleaveandabsences_toil_amounts,"value")})}function S(){var e=a.resolve();return W.injectMonth&&(e=j("destroyed"),W.injectMonth=!1),e}function L(e){return{index:v(e),month:e.month(),year:e.year(),name:e.format("MMMM"),moment:n().year(e.year()).month(e.month())}}function w(){var n=W.selectedPeriod.id;W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current}),n!==W.selectedPeriod.id&&p(),x(),B(),O("month")}function k(e){var t="previous"===e?"subtract":"add";F(n(W.selectedMonth.moment)[t](1,"month")),B(),O("month")}function O(n){n=e.includes(["contacts","period","month"],n)?n:"period",a.resolve().then(S).then("period"===n&&p).then("period"===n&&$).then("contacts"===n&&D).then("month"===n&&B).then(function(){y("contacts"===n)})}function M(e){s.$emit("LeaveCalendar::showMonth",!!e)}function x(){F(n())}function $(){F(W.months[0].moment)}function E(t){var a="previous"===t?"first":"last",o=e[a](W.months),s=n().year(o.year).month(o.month);W.monthPaginatorsAvailability[t]=!W.selectedMonth.moment.isSame(s,"month")}function B(){E("previous"),E("next")}function F(n){n&&(W.selectedMonthIndex=v(n)),W.selectedMonth=e.find(W.months,{index:W.selectedMonthIndex})}function N(){return a.all([d(i.permissions.admin.administer),d(i.permissions.ssp.manage)]).then(function(e){W.userPermissionRole=e[0]?"admin":e[1]?"manager":"staff",H=W.roleOverride?W.roleOverride:W.userPermissionRole})}function j(n){return a(function(t){var a=s.$on("LeaveCalendar::month"+e.capitalize(n),function(){a(),t()})})}o.debug("Component: leave-calendar");var U,H,W=this;W.absencePeriods=[],W.contacts=[],W.contactIdsToReduceTo=null,W.injectMonth=!1,W.months=[],W.selectedMonth={},W.selectedMonthIndex="",W.selectedPeriod=null,W.showContactName=!1,W.showFilters=!1,W.userPermissionRole="staff",W.loading={calendar:!0,page:!0},W.filters={hideOnMobile:!0,optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null},absenceTypes:{}},W.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],W.filters.userSettings.assignedTo=W.filtersByAssignee[2],W.monthPaginatorsAvailability={previous:!0,next:!0},W.supportData={absenceTypesToFilterBy:[]},W.$onInit=m,W.canManageRequests=h,W.labelPeriod=q,W.navigateToCurrentMonth=w,W.paginateMonth=k,W.refresh=O}t.component("leaveCalendar",{bindings:{contactId:"<",displaySingleContact:"0,t={from_date:{to:Q.month.days[Q.month.days.length-1].date+" 23:59:59"},to_date:{from:Q.month.days[0].date+" 00:00:00"},status_id:{IN:k()},contact_id:{IN:Q.contacts.map(function(e){return e.id})},type_id:{IN:n?Q.supportData.absenceTypesToFilterBy:e.pluck(Q.supportData.absenceTypes,"id")}};return y(),i.all(t,null,null,null,!1).then(function(e){return X={},n&&(e.list=q(e.list)),A(e.list)})}function x(){var n=Q.month.days[0].date,t=Q.month.days[Q.month.days.length-1].date;return s.get(Q.contacts.map(function(e){return e.id}),n,t).then(function(n){z=e.indexBy(n,"contact_id")})}function $(){return Q.contactIdsToReduceTo&&(Q.contacts=Q.contacts.filter(function(n){return e.includes(Q.contactIdsToReduceTo,n.contact_id)||e.find(X,function(e){return e.contact_id===n.contact_id})})),a.resolve()}function E(n){var t=L(n);X[n.contact_id]=X[n.contact_id]||{},t.forEach(function(t){e.remove(X[n.contact_id][t.date],function(e){return e.id===n.id})})}function B(){o.$emit("LeaveCalendar::monthDestroyed"),V.map(function(e){e.remove?e.remove():e()})}function F(n,t,o){var s,i;return n.contactsData[t]=n.contactsData[t]||{},i=f(t),s=!0===o?a.resolve():a.all([i.isWeekend(h(n.date)),i.isNonWorkingDay(h(n.date))]).then(function(a){e.assign(n.contactsData[t],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:I(n.date)})}),s.then(function(){return X[t]&&X[t][n.date]?X[t][n.date]:[]}).then(function(a){a=U(a),e.assign(n.contactsData[t],{leaveRequests:a,leaveRequestsToShowInCell:b(a),leaveRequestsAttributes:C(n,a)})})}function N(){return a.all(Q.month.days.map(function(e){return a.all(Q.contacts.map(function(n){return F(e,n.id)}))}))}function j(e,n){Q.currentPage=0,Q.visible=!0,(n||!G)&&O()}function U(t){return e.sortBy(t,function(e){return+n(e.from_date).format("X")+(R("half_day_pm",e,e.from_date)?1:0)})}function H(n){var t=e.find(Q.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 W(e){v(e),-1!==k().indexOf(e.status_id)&&l(e)}function Y(e){return a.all(L(e).map(function(n){return F(n,e.contact_id,!0)}))}t.debug("Component: leave-calendar-month");var G=!1,V=[],z={},X={},Q=this;Q.currentPage=0,Q.pageSize=20,Q.visible=!1,Q.showContactName=!!Q.showContactName,Q.showOnlyWithLeaveRequests=!!Q.showOnlyWithLeaveRequests,Q.$onDestroy=B,Q.$onInit=u,Q.contactsList=p,Q.getContactUrl=_}t.component("leaveCalendarMonth",{bindings:{showTheseContacts:"<",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/models/contact","common/models/session.model","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,l,d,m){function f(){a.resolve().then(_).then(C).then(function(){return y()&&"admin"!==w.role&&P()}).then(R).finally(function(){w.loading.component=!1})}function p(n){L=w.leaveRequest.status_id,e.includes(["cancel","reject","delete"],n)||"toil"===w.leaveRequest.request_type?i.open(q(n)):b(n)}function h(){return"admin"===w.role&&"public_holiday"===w.leaveRequest.request_type}function v(t){var a=w.absenceTypes[w.leaveRequest.type_id].allow_request_cancelation;return"admin"===w.role||("manager"===w.role?e.includes([k.awaitingApproval,k.moreInformationRequired],t):"3"===a?n().isBefore(w.leaveRequest.from_date):"2"===a)}function b(n){i.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return w.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(t){return t?e.assign(c.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){A(n)}}):q(n)})}})}function g(){return s.find(S).then(function(e){return e.checkIfSelfLeaveApprover()})}function y(){return S===w.leaveRequest.contact_id}function _(){e.isArray(w.leaveRequestStatuses)&&(w.leaveRequestStatuses=e.indexBy(w.leaveRequestStatuses,"value")),e.isArray(w.absenceTypes)&&(w.absenceTypes=e.indexBy(w.absenceTypes,"id"))}function q(e){var n=O[e].dialog;return{title:"Confirm "+n.title+"?",copyCancel:"Cancel",copyConfirm:n.btnLabel,classConfirm:"btn-"+n.btnClass,msg:n.msg,onConfirm:function(){return w.leaveRequest[e]().then(function(){D(e)}).catch(function(e){d.error("Error:",e)})}}}function C(){return m.get().then(function(e){S=e.contactId})}function T(e,n){e.stopPropagation(),r.openModal(n)}function A(e){r.openModal({leaveRequest:w.leaveRequest,leaveType:w.leaveRequest.request_type,selectedContactId:w.leaveRequest.contact_id,forceRecalculateBalanceChange:!0,defaultStatus:l.statusNames[M[e]]})}function D(n){var t=e.find(w.leaveRequestStatuses,function(e){return e.name===l.statusNames.awaitingApproval}).value;L===t&&u.publish("ManagerBadge:: Update Count"),u.publish("LeaveRequest::statusUpdate",{status:n,leaveRequest:w.leaveRequest})}function R(){var n=w.leaveRequestStatuses[w.leaveRequest.status_id].name,t=e.compact(e.map(O,function(t,a){return e.includes(t.allowedStatuses,n)?a:null}));!v(n)&&e.pull(t,"cancel"),"admin"!==w.role&&e.pull(t,"delete"),"staff"===w.role&&e.pull(t,"approve","reject"),"staff"!==w.role&&I(t),h()&&t.push("delete"),w.allowedActions=e.map(t,function(e){return{key:e,label:O[e].label,isDirectAction:O[e].isDirectAction}})}function P(){return g().then(function(e){e&&(w.role="admin")})}function I(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 S,L,w=this,k=l.statusNames,O={edit:{label:"Edit",allowedStatuses:[k.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[k.moreInformationRequired]},view:{label:"View",allowedStatuses:[k.approved,k.rejected,k.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[k.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[k.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[k.awaitingApproval,k.approved,k.rejected,k.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[k.awaitingApproval,k.moreInformationRequired,k.approved,k.rejected,k.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}},M={approve:"approved"};w.allowedActions=[],w.loading={component:!0},w.$onInit=f,w.action=p,w.openLeavePopup=T}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","$q","$rootScope","Contact","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService","Session"]}),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(){o.$emit("LeaveRequestPopup::addTab",C),y(),_()}function l(){C.request.comments.push({contact_id:q,leave_request_id:C.request.id,text:C.comment.text}),C.comment.text=""}function d(){return C.comment.text.length>0}function m(e){return!e.comment_id||C.canManage}function f(e){return n.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function p(){return C.request.comments.filter(function(e){return!e.toBeDeleted})}function h(e){return e===q?"Me":C.comment.contacts[e]?C.comment.contacts[e].display_name:void 0}function v(e){return C.mode===e}function b(){C.comment.text.length&&C.addComment()}function g(){var n=e.indexBy(C.request.comments,"contact_id"),t=Object.keys(n);return r.all({id:{IN:t}},{page:1,size:0}).then(function(n){C.comment.contacts=e.indexBy(n.list,"contact_id")})}function y(){return C.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),C.request.comments.length&&g()})}function _(){return C.loading.component=!0,c.get().then(function(e){q=e.contactId}).then(function(){C.loading.component=!1})}t.debug("Component: leave-request-popup-comments-tab");var q=null,C=this;C.loading={component:!0},C.comment={text:"",contacts:{}},C.$onInit=u,C.addComment=l,C.canRemoveComment=m,C.canSubmit=d,C.formatDateTime=f,C.getActiveComments=p,C.getCommentorName=h,C.isMode=v,C.onBeforeSubmit=b}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(){t("RequestModalDetails"+e.capitalize(T(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),S(),te.initChildController().then(function(){return i.all([$(),x()])}).then(!te.isMode("create")&&I).then(Y).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(z)}).then(!te.isMode("create")&&W).then(L).then(G).then(P).then(w).then(!te.isMode("view")&&te.initWatchersExtended).catch(R).then(function(){te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.totalItems=te.balance.change.breakdown.length}).finally(function(){te.loading.tab=!1})}function p(){te.balance.closing=te.balance.opening+te.balance.change.amount}function h(e){return n(e,c.serverDateFormat).toDate()}function v(e){return n(e).format(c.serverDateFormat)}function b(e){var n;return i.resolve().then(function(){U(e),"from"===e&&j(),k("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return C(e)}).then(function(e){if(n=e.id!==te.period.id,n&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(n)return $()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(z(),!n)return B();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(R).finally(q)}function g(){return z(),B()}function y(){return te.uiOptions.toDate=null,U("to"),i.resolve().then(z).then(te.setDaysSelectionModeExtended).then(q).then(!te.uiOptions.multipleDays&&B)}function _(e){te.uiOptions.times[e].loading=!0}function q(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,k("hours")&&(te.uiOptions.times[e].loading=!1)})}function C(t){var a=n(te.uiOptions[t+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function T(){return te.request?te.request.request_type:te.leaveType||null}function A(e){return n().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return X(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(H).catch(R)}function R(n){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(n)?n:[n]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?B():D()}function I(){var e=te.request.attributes();return te.uiOptions.fromDate=h(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=h(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function S(){ne.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,n){K(n)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",B))}function L(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(ee={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function w(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,n){e!==n&&(te.uiOptions.multipleDays||(Z(e),z()))})}function k(e){return te.selectedAbsenceType.calculation_unit_name===e}function O(e){return te.request.request_type===e}function M(n){return e.includes(["weekend","non_working_day","public_holiday"],n)}function x(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function $(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,n=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,n)}function B(){return X(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(H).catch(R).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function F(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function N(){return v(te.request.from_date)===v(te.request.to_date)}function j(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&n(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),z(),X()}function H(e){te.balance.change=e,te.request.balance_change=e.amount,p(),F(),te.loading.balanceChange=!1}function W(){var e,t,a;te.uiOptions.fromDate?(e=n(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,t=e):(a=h(te.period.start_date),t=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=t,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=h(te.period.end_date)}function Y(){return!te.isMode("create")&&N()||te.isMode("create")&&(O("sickness")||k("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){ee&&ee.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=ee.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function V(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function z(){var e=te.uiOptions,n=e.times;te.request.from_date=e.fromDate?v(e.fromDate):null,te.request.to_date=e.toDate?v(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),(k("hours")||O("toil"))&&(te.request.from_date=te.request.from_date&&n.from.time?te.request.from_date+" "+n.from.time:null,te.request.to_date=te.request.to_date&&n.to.time?te.request.to_date+" "+n.to.time:null)}function X(){te.uiOptions.showBalance=te.canCalculateChange()}function Q(){e.forEach(ne,function(e){e()})}function J(){var e,n=te.selectedAbsenceType.calculation_unit_name;return V(),e=n!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&Y).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&z).then(q).then(B)}function K(e){return te.absenceTypes=e,V(),n(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),G(),B()}function Z(e){var n=A(e).add(te.uiOptions.time_interval,"minutes");n.isAfter(A(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=n.format("HH:mm"),n.isAfter(A(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var ee=null,ne=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:[],numPerPage:7,totalItems:0,pageChanged:E},te.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},te.$onInit=f,te.convertDateFormatFromServer=h,te.convertDateToServerFormat=v,te.dateChangeHandler=b,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=y,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=A,te.handleError=R,te.isCalculationUnit=k,te.isLeaveType=O,te.isNotWorkingDay=M,te.performBalanceChangeCalculation=B,te.setRequestDateTimesAndDateTypes=z,te.updateEndTimeInputMinTime=Z,te.$onDestroy=Q}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(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",w),y(),a.all([A(),C()]).then(_).finally(function(){w.filesLoaded=!0})}function m(){return w.fileUploader&&w.fileUploader.queue.length>0}function f(){return w.getFilesAmount()0?I.map(function(e){return e.label}).join(", "):""}function C(){return w.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function T(){return a.all(I.map(function(e){return l.getMimeTypeFor(e.label).then(function(n){L[e.label]=n})})).catch(function(){L=null})}function A(){return c.valuesOf("safe_file_extension").then(function(e){I=e})}function D(e){return!e.attachment_id||w.canManage}function R(){e.forEach(S,function(e){e()})}function P(e,n){w.fileUploader.queue&&w.fileUploader.queue.length>0?w.fileUploader.uploadAll({entityID:w.request.id}).then(function(){n()}).catch(n):n()}t.debug("Component: leave-request-popup-files-tab");var I=[],S=[],L={},w=Object.create(this);return w.filesLoaded=!1,w.fileUploader=null,w.today=Date.now(),w.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",w.userDateFormat=i.DATE_FORMAT,w.$onDestroy=R,w.$onInit=d,w.canRemoveAttachment=D,w.canSubmit=m,w.canUploadMore=f,w.formatDateTime=p,w.getAuthorName=h,w.getFilesAmount=v,w.listFileTypes=q,w}t.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function n(e,n,t){function a(){s=t.parse(),s.openModal&&o({leaveType:s.openModal,selectedContactId:i.selectedContactId})}function o(e){n.openModal(e)}e.debug("Component: leave-request-record-actions");var s,i=this;i.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],i.$onInit=a,i.openLeavePopup=o}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",n]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,n,t){function a(n,t,a,o,s,i,r,c,u,l,d,m){function f(){t.all([q(),E(),A(),T()]).then(function(){z.loading.page=!1}).then(function(){return t.all([P(),R()])}).then(B).then(function(){z.loading.content=!1}),j()}function p(e,n){n.data.push(e),n.dataIndex[e.id]=e}function h(){z.absenceTypes=z.absenceTypes.map(function(n){var t=e.find(z.entitlements,function(e){return e.type_id===n.id});return n.entitlement=t?t.value:0,n.remainder=t?t.remainder:{current:0,future:0},n})}function v(e){U(e),z.sections.other.open&&p(e,z.sections.other)}function b(){Object.values(z.sections).forEach(function(e){e.data=[]})}function g(){z.absenceTypesFiltered=z.absenceTypes.filter(function(e){return!(0===e.entitlement&&"1"!==e.allow_overuse&&"1"!==e.allow_accruals_request)})}function y(e){var n=V[e.status];n?n(e.leaveRequest):z.refresh()}function _(n){n.dataIndex=e.indexBy(n.data,"id")}function q(){return z.role="staff","absence-tab"===a.section?(z.role="admin",t.resolve()):o(m.permissions.admin.administer).then(function(e){e&&(z.role="admin")})}function C(e){return e.current?"Current Period ("+e.title+")":e.title}function T(){return s.all().then(function(n){z.absencePeriods=e.sortBy(n,"start_date"),z.selectedPeriod=e.find(z.absencePeriods,function(e){return!0===e.current})})}function A(){return i.all().then(i.loadCalculationUnits).then(function(n){z.absenceTypes=n,z.absenceTypesIndexed=e.indexBy(n,"id")})}function D(){return w("approved",{status_id:G(m.statusNames.approved)})}function R(){var n={contact_id:z.contactId,period_id:z.selectedPeriod.id};return t.all([c.balanceChangeByAbsenceType(e.assign({},n,{public_holiday:!0})),c.balanceChangeByAbsenceType(e.assign({},n,{expired:!0 -})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.approved)]}})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}}))]).then(function(e){z.absenceTypes.forEach(function(n){n.balanceChanges={holidays:e[0][n.id],expired:e[1][n.id],approved:e[2][n.id],pending:e[3][n.id]}})})}function P(){return r.all({contact_id:z.contactId,period_id:z.selectedPeriod.id},!0).then(function(e){z.entitlements=e})}function I(){return r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id},z.entitlements).then(function(){return F(z.entitlements)}).then(function(e){z.sections.entitlements.data=e})}function S(){return t.all([r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id,expired:!0}),L({request_type:"toil",expired:!0})]).then(function(e){return t.all({expiredBalanceChangesFlatten:F(e[0]),expiredTOILS:N(e[1].list)})}).then(function(n){z.sections.expired.data=n.expiredBalanceChangesFlatten.concat(n.expiredTOILS),z.sections.expired.data=e.sortBy(z.sections.expired.data,"expiry_date")})}function L(n){return c.all(e.assign({contact_id:z.contactId,from_date:{from:z.selectedPeriod.start_date},to_date:{to:z.selectedPeriod.end_date},type_id:{IN:z.absenceTypes.map(function(e){return e.id})}},n),null,"from_date ASC",null,!1)}function w(e,n){return L(n).then(function(n){z.sections[e].data=n.list})}function k(){return t.all(Object.values(z.sections).filter(function(e){return e.open}).map($))}function O(){return w("other",{status_id:{in:[G(m.statusNames.rejected),G(m.statusNames.cancelled)]}})}function M(){return w("pending",{status_id:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}})}function x(){return w("holidays",{public_holiday:!0})}function $(e){return e.loading=!0,e.loadLeaveRequests().then(_.bind(this,e)).then(function(){e.loading=!1})}function E(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){z.leaveRequestStatuses=e.indexBy(n,"value")})}function B(){h(),g()}function F(n){return t.resolve().then(function(){return n.map(function(n){var t=e.find(z.entitlements,function(e){return e.id===n.id});return n.breakdown.map(function(n){return e.assign(e.clone(n),{type_id:t.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function N(n){return t.resolve().then(function(){return n.map(function(n){return e.assign({},n,{expiry_date:n.toil_expiry_date,amount:n.toil_to_accrue,type:{label:"Accrued TOIL"}})})})}function j(){l.subscribe("LeaveRequest::new",function(){z.refresh()}),l.subscribe("LeaveRequest::edit",function(){z.refresh()}),l.subscribe("LeaveRequest::statusUpdate",y),l.subscribe("LeaveRequest::delete",function(e){U(e)})}function U(n){e.forEach(z.sections,function(t,a){t.dataIndex[n.id]&&(e.remove(t.data,function(e){return e.id===n.id}),delete t.dataIndex[n.id],"other"!==a&&H(n,a))})}function H(n,t){var a=["future","current"],o=z.absenceTypesIndexed[n.type_id];"pending"===t&&e.pull(a,"current"),o.balanceChanges[t]-=n.balance_change,a.forEach(function(e){o.remainder[e]-=n.balance_change})}function W(){z.loading.content=!0,t.all([P(),R()]).then(B).then(function(){z.loading.content=!1}).then(function(){return t.all([k(),b()])})}function Y(e){var n=z.sections[e];n.open=!n.open,n.open&&!n.data.length&&$(n)}function G(n){return e.find(z.leaveRequestStatuses,function(e){return e.name===n}).value}n.debug("Component: staff-leave-report");var V={delete:U,cancel:v},z=this;z.absencePeriods=[],z.absenceTypes=[],z.absenceTypesFiltered=[],z.absenceTypesIndexed={},z.dateFormat=d.DATE_FORMAT,z.leaveRequestStatuses={},z.selectedPeriod=null,z.role=null,z.loading={content:!0,page:!0},z.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:x},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:M},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O}},z.$onInit=f,z.labelPeriod=C,z.refresh=W,z.toggleSection=Y}t.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:a}),a.$inject=["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,n=!!e.from_date&&!!e.to_date,t=i.selectedAbsenceType.calculation_unit_name;return"days"===t?n=n&&!!e.from_date_type&&!!e.to_date_type:"hours"===t&&(n=n&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),n}function d(){return i.canCalculateChange()}function m(n,t){var a=i.uiOptions.times[n],o=e.clone(t.time_from),s=e.clone(t.time_to);i.uiOptions.multipleDays||("from"===n&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===n&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===n?a.max:a.min}function f(n,t){return n?(n=i.convertDateToServerFormat(n),v(n).then(function(t){return t?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(n,i.requestDayTypes).then(function(n){return n.length?n:i.requestDayTypes.filter(function(n){return e.includes(["all_day","half_day_am","half_day_pm"],n.name)})})}).then(function(e){return I(t,e),e})):o.reject([])}function p(e,t){return e=n(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(n){return n.name===e}):[]})}function h(e,t){return n.duration(t).subtract(n.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function y(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,n){i.isCalculationUnit("days")||+e==+n||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function _(e){var t=n(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,t)<=0||h(a.max,t)>=0)&&(t="from"===e?a.min:a.max),i.uiOptions.times[e].time=t}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],n=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(R)).then(function(){["from","to"].forEach(function(e){_(e),L(e),n[e].amount=Math.min(i.request[e+"_date_amount"],n[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function C(){["from","to"].forEach(function(e){y(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(n,t){i.isCalculationUnit("days")||n===t||(i.setRequestDateTimesAndDateTypes(),n&&L(e,!0))})}function A(e,n){return f(e,n).then(function(){i.loading[n+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return R(e).then(function(){L(e,!0)})})}function R(e){var n=i.uiOptions[e+"Date"],t=!i.uiOptions.multipleDays;return n?i.request.getWorkDayForDate(i.convertDateToServerFormat(n)).then(function(n){O[e]=n,m(e,n),t&&"from"===e&&m("to",n)}).catch(function(n){return O[e]={},i.handleError(n)}).finally(function(){i.uiOptions.times[e].loading=!1,t&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(n){var t=i.uiOptions.times[n];i["request"+e.startCase(n)+"DayTypes"]=[],t.time="",t.min="00:00",t.max="00:00",t.amount="0",t.maxAmount="0"}function I(n,t){var a="request"+e.startCase(n)+"DayTypes";i[a]=t,i.isMode("create")&&(i.request[n+"_date_type"]=i[a][0].value)}function S(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),R("from").then(function(){L("from",!0)})):o.resolve()}function L(e,n){var t=i.uiOptions,a=t.multipleDays?e:"from",o=t.times[a],s=t.multipleDays&&"to"===a?o.min:t.times.from.time,r=t.multipleDays&&"from"===a?o.max:t.times.to.time,c=O[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,n&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function k(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?R("from").then(function(){L("from",!0)}):o.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=k,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=S}t.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(n){var t=r.request.getDocumentArray();return!!e.find(t,function(e){return e===n})}function d(n){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===n})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(n){return i.valuesOf("hrleaveandabsences_sickness_reason",n).then(function(n){r.sicknessReasons=e.indexBy(n,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}t.debug("RequestModalDetailsSicknessController"),n("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}n.controller("RequestModalDetailsSicknessController",t),t.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=n.duration(n(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,n=!c.uiOptions.multipleDays&&!!c.request.from_date,t=n||e,a=j.from_date!==c.request.from_date||j.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&t&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,n=c.request;return b({hasErrors:e?!n.to_date&&!n.from_date:!n.from_date,label:e?"To Date":"From Date",value:n.to_date})}function b(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(n(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&H.hasExpirationFromAdminSettings,n=H.hasPreviousExpirationDate,t=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=t&&(a||e||n)}function y(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",_().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&k(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function P(){c.isMode("view")||(T(),A(),R())}function I(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function S(){return l(),O(),F()}function L(){return x(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),U?U=!1:O(),F()}function w(e){c.uiOptions.times[e].time=""}function k(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){j=e.cloneDeep(c.request.attributes())}function x(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function $(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?k():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function N(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var j,U=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=$,c.onDateChangeExtended=S,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=w,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=N,function(){M(),x(),B(),!c.isMode("create")&&y()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,y,_,q,C){function T(e){"days"===Ne.selectedAbsenceType.calculation_unit_name?delete Ne.request[e+"_date_amount"]:delete Ne.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return ke.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function R(){var e=Ne.requestStatuses[y.statusNames.awaitingApproval].value;xe.status_id===e&&e!==Ne.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Ne.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ne.isMode("edit")&&(e=e&&(G()||I())),Ne.canManage&&Ne.requestStatuses&&(e=e&&!!Ne.getStatusFromValue(Ne.newStatusOnSave)),(e=e&&!!Ne.period.id)&&!Ne.isMode("view")}function w(){Ne.isSelfRecord&&!Ne.isSelfLeaveApprover?Ne.request.status_id=Ne.requestStatuses[y.statusNames.awaitingApproval].value:Ne.canManage&&(Ne.request.status_id=Ne.newStatusOnSave||Ne.request.status_id)}function k(){if(Ne.isMode("edit")&&!Ne.isRole("staff")&&"toil"!==U())return Ne.request.calculateBalanceChange(Ne.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ne.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==U()&&!Ne.request.change_balance}function M(){Ne.errors=[]}function x(){return Ne.request.create().then(Pe).then(function(){ge("LeaveRequest::new")})}function $(){se()&&!Ne.isRole("staff")&&(Ne.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ne.request.delete().then(function(){Ne.dismissModal(),d.publish("LeaveRequest::delete",Ne.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return j(Ne.getStatusFromValue(Ne.request.status_id).name)}function j(e){return t.map(Oe[e],function(e){return Ne.requestStatuses[e]})}function U(){return Ne.request?Ne.request.request_type:Ne.leaveType||null}function H(){return!Ne.request||e.equals({},Ne.requestStatuses)?[]:Ne.request.status_id?N():j("none")}function W(e){return t.find(Ne.requestStatuses,function(n){return n.value===e})}function Y(e){Ne.errors=t.isArray(e)?e:[e],Ne.loading.absenceTypes=!1,Ne.submitting=!1}function G(){return!e.equals(xe,Ne.request.attributes())||Ne.canManage&&Ne.newStatusOnSave}function V(){return Ne.postContactSelection=!0,Ne.staffMemberSelectionComplete=!1,Ne.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ne.isMode("edit")?Te:t.noop).then(function(){Ne.postContactSelection=!1,Ne.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Oe.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ne.canManage=Ne.isRole("manager")||Ne.isRole("admin")}function Q(){return Ne.canManage?f.find(Ne.request.contact_id).then(function(e){Ne.contactName=e.display_name}):o.resolve()}function J(){Ne.isRole("admin")&&Ne.isSelfRecord&&(Ne.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+ke.id==+t.get(Ne,"leaveRequest.contact_id"),a=!t.get(Ne,"leaveRequest.id");Ne.isSelfRecord=e&&a||n}function Z(){$e.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ne.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Ie),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ne.request=Ne.leaveRequest||null,e=U(),n=Ne.initRequestAttributes(),"leave"===e?Ne.request=g.init(n):"sickness"===e?Ne.request=_.init(n):"toil"===e&&(Ne.request=q.init(n))}function ne(){var e={};return Ne.request?e=Ne.request.attributes():Ne.canManage||(e={contact_id:ke.id}),e}function te(){return Be="staff",ae().then(Ne.isSelfRecord&&!Ne.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ne.defaultStatus?Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames[Ne.defaultStatus]].value:(Ne.isRole("admin")||Ne.isMode("create")&&Ne.isRole("manager"))&&(Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames.approved].value)}function se(){return!Ne.request.status_id||!t.includes(["cancelled","rejected"],W(Ne.request.status_id).name)}function ie(e){var n=Ne.getStatusFromValue(Ne.request.status_id);return!!n&&n.name===e}function re(e){return Ne.request&&Ne.request.request_type===e}function ce(e){return Ne.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ne.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){we={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ne.loading.entitlements=!0,v.all({contact_id:Ne.request.contact_id,period_id:Ne.period.id,type_id:{IN:we.ids}},!0).finally(function(){Ne.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){ke=e})}function he(){return Ne.selectedContactId?f.find(Ne.selectedContactId).then(function(e){Ne.managedContacts=[e]}):Ne.isRole("admin")?f.all().then(function(e){Ne.managedContacts=t.remove(e.list,function(e){return e.id!==ke.id})}):ke.leaveManagees().then(function(e){Ne.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ne.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){R(),d.publish(e,Ne.request),Ne.errors=[],Ne.dismissModal()}function ye(){["from","to"].forEach(function(e){Ne.request[e+"_date"]=xe[e+"_date"]})}function _e(e){if(Ne.absenceTypes=be(we.types,e),!Ne.absenceTypes.length)return o.reject(Ee)}function qe(){Ne.period=t.find(Ne.absencePeriods,function(e){return Ne.isMode("create")?e.current:ue(Ne.request,e)})}function Ce(){Ne.isMode("create")?(Ne.selectedAbsenceType=Ne.absenceTypes[0],Ne.request.type_id=Ne.selectedAbsenceType.id):Ne.selectedAbsenceType=t.find(Ne.absenceTypes,function(e){return e.id===Ne.request.type_id})}function Te(){xe=e.copy(Ne.request.attributes())}function Ae(){var e;Ne.request.id?(e=[Ne.requestStatuses[y.statusNames.approved].value,Ne.requestStatuses[y.statusNames.adminApproved].value,Ne.requestStatuses[y.statusNames.rejected].value,Ne.requestStatuses[y.statusNames.cancelled].value],Ne.mode="edit",Ne.isRole("staff")&&e.indexOf(Ne.request.status_id)>-1&&(Ne.mode="view")):Ne.mode="create"}function De(){var e=Ne.request.status_id;if(!Ne.isMode("view")&&!Ne.submitting)return Ne.submitting=!0,w(),A(),Ne.request.isValid().then(se()&&k).then($).then(O()&&ye).then(Re).then(function(){return Ne.isMode("edit")?Le():x()}).catch(function(n){Ne.request.status_id=e,n&&Y(n)}).finally(function(){Ne.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Ie(){$e.forEach(function(e){e()})}function Se(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ne.request.update().then(Pe).then(function(){Ne.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ne.isRole("staff")||Ne.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var we,ke,Oe={},Me=0,xe={},$e=[],Ee="No entitlement",Be="",Fe=[],Ne=t.assign(this,m);Ne.absencePeriods=[],Ne.absenceTypes=[],Ne.canManage=!1,Ne.contactName=null,Ne.errors=[],Ne.isSelfLeaveApprover=!1,Ne.loading={absenceTypes:!0,entitlements:!0},Ne.managedContacts=[],Ne.mode="",Ne.newStatusOnSave=null,Ne.period={},Ne.postContactSelection=!1,Ne.requestStatuses={},Ne.selectedAbsenceType={},Ne.staffMemberSelectionComplete=!1,Ne.submitting=!1,Ne.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ne.canChangeAbsenceType=S,Ne.canSubmit=L,Ne.closeAlert=M,Ne.deleteLeaveRequest=E,Ne.dismissModal=B,Ne.getStatuses=H,Ne.getStatusFromValue=W,Ne.initAfterContactSelection=V,Ne.initRequestAttributes=ne,Ne.isLeaveStatus=ie,Ne.isLeaveType=re,Ne.isMode=ce,Ne.isRole=le,Ne.submit=De,Ne.updateAbsenceType=Se,function(){Ne.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ne.canManage&&!Ne.isMode("edit")&&he()}).then(function(){if(Ne.selectedContactId&&(Ne.request.contact_id=Ne.selectedContactId),Ne.request.contact_id)return Ne.initAfterContactSelection()}).catch(Y).finally(function(){Ne.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,n){"use strict";function t(e,n,t,a,o,s,i,r,c){function u(e){return r.get().then(function(n){return e.roleOf(n.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:n.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(n){n?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}n.factory("LeavePopup",t), +})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.approved)]}})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}}))]).then(function(e){z.absenceTypes.forEach(function(n){n.balanceChanges={holidays:e[0][n.id],expired:e[1][n.id],approved:e[2][n.id],pending:e[3][n.id]}})})}function P(){return r.all({contact_id:z.contactId,period_id:z.selectedPeriod.id},!0).then(function(e){z.entitlements=e})}function I(){return r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id},z.entitlements).then(function(){return F(z.entitlements)}).then(function(e){z.sections.entitlements.data=e})}function S(){return t.all([r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id,expired:!0}),L({request_type:"toil",expired:!0})]).then(function(e){return t.all({expiredBalanceChangesFlatten:F(e[0]),expiredTOILS:N(e[1].list)})}).then(function(n){z.sections.expired.data=n.expiredBalanceChangesFlatten.concat(n.expiredTOILS),z.sections.expired.data=e.sortBy(z.sections.expired.data,"expiry_date")})}function L(n){return c.all(e.assign({contact_id:z.contactId,from_date:{from:z.selectedPeriod.start_date},to_date:{to:z.selectedPeriod.end_date},type_id:{IN:z.absenceTypes.map(function(e){return e.id})}},n),null,"from_date ASC",null,!1)}function w(e,n){return L(n).then(function(n){z.sections[e].data=n.list})}function k(){return t.all(Object.values(z.sections).filter(function(e){return e.open}).map($))}function O(){return w("other",{status_id:{in:[G(m.statusNames.rejected),G(m.statusNames.cancelled)]}})}function M(){return w("pending",{status_id:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}})}function x(){return w("holidays",{public_holiday:!0})}function $(e){return e.loading=!0,e.loadLeaveRequests().then(_.bind(this,e)).then(function(){e.loading=!1})}function E(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){z.leaveRequestStatuses=e.indexBy(n,"value")})}function B(){h(),g()}function F(n){return t.resolve().then(function(){return n.map(function(n){var t=e.find(z.entitlements,function(e){return e.id===n.id});return n.breakdown.map(function(n){return e.assign(e.clone(n),{type_id:t.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function N(n){return t.resolve().then(function(){return n.map(function(n){return e.assign({},n,{expiry_date:n.toil_expiry_date,amount:n.toil_to_accrue,type:{label:"Accrued TOIL"}})})})}function j(){l.subscribe("LeaveRequest::new",function(){z.refresh()}),l.subscribe("LeaveRequest::edit",function(){z.refresh()}),l.subscribe("LeaveRequest::statusUpdate",y),l.subscribe("LeaveRequest::delete",function(e){U(e)})}function U(n){e.forEach(z.sections,function(t,a){t.dataIndex[n.id]&&(e.remove(t.data,function(e){return e.id===n.id}),delete t.dataIndex[n.id],"other"!==a&&H(n,a))})}function H(n,t){var a=["future","current"],o=z.absenceTypesIndexed[n.type_id];"pending"===t&&e.pull(a,"current"),o.balanceChanges[t]-=n.balance_change,a.forEach(function(e){o.remainder[e]-=n.balance_change})}function W(){z.loading.content=!0,t.all([P(),R()]).then(B).then(function(){z.loading.content=!1}).then(function(){return t.all([k(),b()])})}function Y(e){var n=z.sections[e];n.open=!n.open,n.open&&!n.data.length&&$(n)}function G(n){return e.find(z.leaveRequestStatuses,function(e){return e.name===n}).value}n.debug("Component: staff-leave-report");var V={delete:U,cancel:v},z=this;z.absencePeriods=[],z.absenceTypes=[],z.absenceTypesFiltered=[],z.absenceTypesIndexed={},z.dateFormat=d.DATE_FORMAT,z.leaveRequestStatuses={},z.selectedPeriod=null,z.role=null,z.loading={content:!0,page:!0},z.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:x},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:M},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O}},z.$onInit=f,z.labelPeriod=C,z.refresh=W,z.toggleSection=Y}t.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:a}),a.$inject=["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,n=!!e.from_date&&!!e.to_date,t=i.selectedAbsenceType.calculation_unit_name;return"days"===t?n=n&&!!e.from_date_type&&!!e.to_date_type:"hours"===t&&(n=n&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),n}function d(){return i.canCalculateChange()}function m(n,t){var a=i.uiOptions.times[n],o=e.clone(t.time_from),s=e.clone(t.time_to);i.uiOptions.multipleDays||("from"===n&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===n&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===n?a.max:a.min}function f(n,t){return n?(n=i.convertDateToServerFormat(n),v(n).then(function(t){return t?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(n,i.requestDayTypes).then(function(n){return n.length?n:i.requestDayTypes.filter(function(n){return e.includes(["all_day","half_day_am","half_day_pm"],n.name)})})}).then(function(e){return I(t,e),e})):o.reject([])}function p(e,t){return e=n(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(n){return n.name===e}):[]})}function h(e,t){return n.duration(t).subtract(n.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function y(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,n){i.isCalculationUnit("days")||+e==+n||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function _(e){var t=n(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,t)<=0||h(a.max,t)>=0)&&(t="from"===e?a.min:a.max),i.uiOptions.times[e].time=t}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],n=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(R)).then(function(){["from","to"].forEach(function(e){_(e),L(e),n[e].amount=Math.min(i.request[e+"_date_amount"],n[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function C(){["from","to"].forEach(function(e){y(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(n,t){i.isCalculationUnit("days")||n===t||(i.setRequestDateTimesAndDateTypes(),n&&L(e,!0))})}function A(e,n){return f(e,n).then(function(){i.loading[n+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return R(e).then(function(){L(e,!0)})})}function R(e){var n=i.uiOptions[e+"Date"],t=!i.uiOptions.multipleDays;return n?i.request.getWorkDayForDate(i.convertDateToServerFormat(n)).then(function(n){O[e]=n,m(e,n),t&&"from"===e&&m("to",n)}).catch(function(n){return O[e]={},i.handleError(n)}).finally(function(){i.uiOptions.times[e].loading=!1,t&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(n){var t=i.uiOptions.times[n];i["request"+e.startCase(n)+"DayTypes"]=[],t.time="",t.min="00:00",t.max="00:00",t.amount="0",t.maxAmount="0"}function I(n,t){var a="request"+e.startCase(n)+"DayTypes";i[a]=t,i.isMode("create")&&(i.request[n+"_date_type"]=i[a][0].value)}function S(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),R("from").then(function(){L("from",!0)})):o.resolve()}function L(e,n){var t=i.uiOptions,a=t.multipleDays?e:"from",o=t.times[a],s=t.multipleDays&&"to"===a?o.min:t.times.from.time,r=t.multipleDays&&"from"===a?o.max:t.times.to.time,c=O[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,n&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function k(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?R("from").then(function(){L("from",!0)}):o.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=k,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=S}t.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(n){var t=r.request.getDocumentArray();return!!e.find(t,function(e){return e===n})}function d(n){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===n})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(n){return i.valuesOf("hrleaveandabsences_sickness_reason",n).then(function(n){r.sicknessReasons=e.indexBy(n,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}t.debug("RequestModalDetailsSicknessController"),n("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}n.controller("RequestModalDetailsSicknessController",t),t.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=n.duration(n(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,n=!c.uiOptions.multipleDays&&!!c.request.from_date,t=n||e,a=j.from_date!==c.request.from_date||j.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&t&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,n=c.request;return b({hasErrors:e?!n.to_date&&!n.from_date:!n.from_date,label:e?"To Date":"From Date",value:n.to_date})}function b(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(n(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&H.hasExpirationFromAdminSettings,n=H.hasPreviousExpirationDate,t=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=t&&(a||e||n)}function y(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",_().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&k(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function P(){c.isMode("view")||(T(),A(),R())}function I(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function S(){return l(),O(),F()}function L(){return x(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),U?U=!1:O(),F()}function w(e){c.uiOptions.times[e].time=""}function k(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){j=e.cloneDeep(c.request.attributes())}function x(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function $(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?k():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function N(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var j,U=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=$,c.onDateChangeExtended=S,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=w,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=N,function(){M(),x(),B(),!c.isMode("create")&&y()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,y,_,q,C){function T(e){"days"===Ne.selectedAbsenceType.calculation_unit_name?delete Ne.request[e+"_date_amount"]:delete Ne.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return ke.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function R(){var e=Ne.requestStatuses[y.statusNames.awaitingApproval].value;xe.status_id===e&&e!==Ne.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Ne.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ne.isMode("edit")&&(e=e&&(G()||I())),Ne.canManage&&Ne.requestStatuses&&(e=e&&!!Ne.getStatusFromValue(Ne.newStatusOnSave)),(e=e&&!!Ne.period.id)&&!Ne.isMode("view")}function w(){Ne.isSelfRecord&&!Ne.isSelfLeaveApprover?Ne.request.status_id=Ne.requestStatuses[y.statusNames.awaitingApproval].value:Ne.canManage&&(Ne.request.status_id=Ne.newStatusOnSave||Ne.request.status_id)}function k(){if(Ne.isMode("edit")&&!Ne.isRole("staff")&&"toil"!==U())return Ne.request.calculateBalanceChange(Ne.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ne.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==U()&&!Ne.request.change_balance}function M(){Ne.errors=[]}function x(){return Ne.request.create().then(Pe).then(function(){ge("LeaveRequest::new")})}function $(){se()&&!Ne.isRole("staff")&&(Ne.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ne.request.delete().then(function(){Ne.dismissModal(),d.publish("LeaveRequest::delete",Ne.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return j(Ne.getStatusFromValue(Ne.request.status_id).name)}function j(e){return t.map(Oe[e],function(e){return Ne.requestStatuses[e]})}function U(){return Ne.request?Ne.request.request_type:Ne.leaveType||null}function H(){return!Ne.request||e.equals({},Ne.requestStatuses)?[]:Ne.request.status_id?N():j("none")}function W(e){return t.find(Ne.requestStatuses,function(n){return n.value===e})}function Y(e){Ne.errors=t.isArray(e)?e:[e],Ne.loading.absenceTypes=!1,Ne.submitting=!1}function G(){return!e.equals(xe,Ne.request.attributes())||Ne.canManage&&Ne.newStatusOnSave}function V(){return Ne.postContactSelection=!0,Ne.staffMemberSelectionComplete=!1,Ne.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ne.isMode("edit")?Te:t.noop).then(function(){Ne.postContactSelection=!1,Ne.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Oe.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ne.canManage=Ne.isRole("manager")||Ne.isRole("admin")}function Q(){return Ne.canManage?f.find(Ne.request.contact_id).then(function(e){Ne.contactName=e.display_name}):o.resolve()}function J(){Ne.isRole("admin")&&Ne.isSelfRecord&&(Ne.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+ke.id==+t.get(Ne,"leaveRequest.contact_id"),a=!t.get(Ne,"leaveRequest.id");Ne.isSelfRecord=e&&a||n}function Z(){$e.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ne.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Ie),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ne.request=Ne.leaveRequest||null,e=U(),n=Ne.initRequestAttributes(),"leave"===e?Ne.request=g.init(n):"sickness"===e?Ne.request=_.init(n):"toil"===e&&(Ne.request=q.init(n))}function ne(){var e={};return Ne.request?e=Ne.request.attributes():Ne.canManage||(e={contact_id:ke.id}),e}function te(){return Be="staff",ae().then(Ne.isSelfRecord&&!Ne.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ne.defaultStatus?Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames[Ne.defaultStatus]].value:(Ne.isRole("admin")||Ne.isMode("create")&&Ne.isRole("manager"))&&(Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames.approved].value)}function se(){return!Ne.request.status_id||!t.includes(["cancelled","rejected"],W(Ne.request.status_id).name)}function ie(e){var n=Ne.getStatusFromValue(Ne.request.status_id);return!!n&&n.name===e}function re(e){return Ne.request&&Ne.request.request_type===e}function ce(e){return Ne.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ne.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){we={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ne.loading.entitlements=!0,v.all({contact_id:Ne.request.contact_id,period_id:Ne.period.id,type_id:{IN:we.ids}},!0).finally(function(){Ne.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){ke=e})}function he(){return Ne.selectedContactId?f.find(Ne.selectedContactId).then(function(e){Ne.managedContacts=[e]}):Ne.isRole("admin")?f.all().then(function(e){console.log(e.list),Ne.managedContacts=e.list}):ke.leaveManagees().then(function(e){Ne.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ne.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){R(),d.publish(e,Ne.request),Ne.errors=[],Ne.dismissModal()}function ye(){["from","to"].forEach(function(e){Ne.request[e+"_date"]=xe[e+"_date"]})}function _e(e){if(Ne.absenceTypes=be(we.types,e),!Ne.absenceTypes.length)return o.reject(Ee)}function qe(){Ne.period=t.find(Ne.absencePeriods,function(e){return Ne.isMode("create")?e.current:ue(Ne.request,e)})}function Ce(){Ne.isMode("create")?(Ne.selectedAbsenceType=Ne.absenceTypes[0],Ne.request.type_id=Ne.selectedAbsenceType.id):Ne.selectedAbsenceType=t.find(Ne.absenceTypes,function(e){return e.id===Ne.request.type_id})}function Te(){xe=e.copy(Ne.request.attributes())}function Ae(){var e;Ne.request.id?(e=[Ne.requestStatuses[y.statusNames.approved].value,Ne.requestStatuses[y.statusNames.adminApproved].value,Ne.requestStatuses[y.statusNames.rejected].value,Ne.requestStatuses[y.statusNames.cancelled].value],Ne.mode="edit",Ne.isRole("staff")&&e.indexOf(Ne.request.status_id)>-1&&(Ne.mode="view")):Ne.mode="create"}function De(){var e=Ne.request.status_id;if(!Ne.isMode("view")&&!Ne.submitting)return Ne.submitting=!0,w(),A(),Ne.request.isValid().then(se()&&k).then($).then(O()&&ye).then(Re).then(function(){return Ne.isMode("edit")?Le():x()}).catch(function(n){Ne.request.status_id=e,n&&Y(n)}).finally(function(){Ne.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Ie(){$e.forEach(function(e){e()})}function Se(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ne.request.update().then(Pe).then(function(){Ne.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ne.isRole("staff")||Ne.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var we,ke,Oe={},Me=0,xe={},$e=[],Ee="No entitlement",Be="",Fe=[],Ne=t.assign(this,m);Ne.absencePeriods=[],Ne.absenceTypes=[],Ne.canManage=!1,Ne.contactName=null,Ne.errors=[],Ne.isSelfLeaveApprover=!1,Ne.loading={absenceTypes:!0,entitlements:!0},Ne.managedContacts=[],Ne.mode="",Ne.newStatusOnSave=null,Ne.period={},Ne.postContactSelection=!1,Ne.requestStatuses={},Ne.selectedAbsenceType={},Ne.staffMemberSelectionComplete=!1,Ne.submitting=!1,Ne.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ne.canChangeAbsenceType=S,Ne.canSubmit=L,Ne.closeAlert=M,Ne.deleteLeaveRequest=E,Ne.dismissModal=B,Ne.getStatuses=H,Ne.getStatusFromValue=W,Ne.initAfterContactSelection=V,Ne.initRequestAttributes=ne,Ne.isLeaveStatus=ie,Ne.isLeaveType=re,Ne.isMode=ce,Ne.isRole=le,Ne.submit=De,Ne.updateAbsenceType=Se,function(){Ne.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ne.canManage&&!Ne.isMode("edit")&&he()}).then(function(){if(Ne.selectedContactId&&(Ne.request.contact_id=Ne.selectedContactId),Ne.request.contact_id)return Ne.initAfterContactSelection()}).catch(Y).finally(function(){Ne.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,n){"use strict";function t(e,n,t,a,o,s,i,r,c){function u(e){return r.get().then(function(n){return e.roleOf(n.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:n.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(n){n?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}n.factory("LeavePopup",t), t.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component",[],function(){function e(e,n,t,a){function o(){i(),s()}function s(){return t("can administer calendar feeds").then(function(e){c.canCreateNewFeed=!!e})}function i(){return c.loading.feeds=!0,e.all().then(function(e){c.feeds=e}).finally(function(){c.loading.feeds=!1})}function r(e,t){n.open(e,t)}var c=this;c.canCreateNewFeed=!1,c.feeds=[],c.loading={feeds:!1},c.$onInit=o,c.openLinkModal=r}return e.$inject=["CalendarFeed","CalendarFeedsLinkModal","checkPermissions","shared-settings"],{__name:"calendarFeedsDropdownButton",bindings:{dropdownPosition:"@"},controller:e,controllerAs:"dropdownButton",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.html"}]}}),define("leave-absences/calendar-feeds/calendar-feeds.core",["common/angular","leave-absences/shared/modules/shared-settings"],function(e){e.module("calendar-feeds.core",["leave-absences.settings"])}),define("leave-absences/calendar-feeds/services/apis/calendar-feed.api",["common/lodash"],function(e){"use strict";function n(e,n,t){function a(){return this.sendGET("LeaveRequestCalendarFeedConfig","get",{is_active:!0}).then(function(e){return e.values})}return e.debug("CalendarFeedAPI"),t.extend({all:a})}return n.__name="CalendarFeedAPI",n.$inject=["$log","$q","api"],n}),define("leave-absences/calendar-feeds/services/models/calendar-feed.model",[],function(){"use strict";function e(e,n,t){function a(){return n.all().then(function(e){return e.map(function(e){return t.init(e)})})}return e.extend({all:a})}return e.__name="CalendarFeed",e.$inject=["Model","CalendarFeedAPI","CalendarFeedInstance"],e}),define("leave-absences/calendar-feeds/services/models/calendar-feed.instance",[],function(){"use strict";function e(e){return e.extend({})}return e.__name="CalendarFeedInstance",e.$inject=["ModelInstance"],e}),define("leave-absences/calendar-feeds/calendar-feeds.models",["common/angular","leave-absences/calendar-feeds/services/apis/calendar-feed.api","leave-absences/calendar-feeds/services/models/calendar-feed.model","leave-absences/calendar-feeds/services/models/calendar-feed.instance","common/models/model","common/services/api"],function(e,n,t,a){e.module("calendar-feeds.models",["common.apis","common.models"]).factory(n.__name,n).factory(t.__name,t).factory(a.__name,a)}),define("leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component",["common/lodash"],function(e){return{__name:"calendarFeedsLinkModal",bindings:{dismiss:"<",url:"<",title:"<"},controller:e.noop,controllerAs:"linkModal",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/link-modal/components/calendar-feeds-link-modal.html"}]}}),define("leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service",[],function(){function e(e,n,t){function a(e,a){var s=o(),i=t+"civicrm/calendar-feed?hash="+a;n.open({controllerAs:"modal",size:"md",template:'',controller:["$uibModalInstance","title","url",function(e,n,t){this.dismiss=e.dismiss,this.title=n,this.url=t}],appendTo:s,resolve:{title:function(){return e},url:function(){return i}}})}function o(){var n=e.find("#bootstrap-theme");return 0===n.length&&(n=e.find("body")),n.eq(0)}return{open:a}}return e.__name="CalendarFeedsLinkModal",e.$inject=["$document","$uibModal","HOST_URL"],e}),define("leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive",["common/lodash"],function(e){function n(n,t){function a(e,t,a,o){function s(){r(),u()}function i(){l[0].setSelectionRange(0,0),l.blur()}function r(){c(),document.execCommand("copy"),i()}function c(){l.focus(),l[0].setSelectionRange(0,l.val().length)}function u(){m.justCopied=!0,d&&n.cancel(d),d=n(function(){m.justCopied=!1},2e3)}var l,d,m=e.input;m.model=o.model,m.justCopied=!1,m.copy=s,m.selectInputText=c,function(){l=t.find("input")}()}var o=t.sourcePath+"calendar-feeds/link-modal/directives/input-with-copy-button.html";return{controller:e.noop,controllerAs:"input",link:a,restrict:"E",scope:{},templateUrl:o,require:{model:"^ngModel"}}}return n.__name="inputWithCopyButton",n.$inject=["$timeout","shared-settings"],n}),define("leave-absences/calendar-feeds/link-modal/link-modal.core",["common/angular","common/angularBootstrap"],function(e){e.module("calendar-feeds.link-modal.core",["ui.bootstrap"])}),function(e){define("leave-absences/calendar-feeds/link-modal/link-modal.constants",["common/angular"],function(n){"use strict";n.module("calendar-feeds.link-modal.constants",[]).constant("HOST_URL",e.absoluteUrl("/"))})}(Drupal),define("leave-absences/calendar-feeds/link-modal/link-modal.module",["common/angular","leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component","leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service","leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/link-modal/link-modal.core","leave-absences/calendar-feeds/link-modal/link-modal.constants"],function(e,n,t,a){e.module("calendar-feeds.link-modal",["calendar-feeds.core","calendar-feeds.link-modal.core","calendar-feeds.link-modal.constants"]).component(n.__name,n).directive(a.__name,a).factory(t.__name,t)}),define("leave-absences/calendar-feeds/dropdown-button/dropdown-button.module",["common/angular","leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component","common/services/check-permissions","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/calendar-feeds.models","leave-absences/calendar-feeds/link-modal/link-modal.module"],function(e,n){e.module("calendar-feeds.dropdown-button",["common.services","calendar-feeds.core","calendar-feeds.models","calendar-feeds.link-modal"]).component(n.__name,n)}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,n,t){function a(){t.go(o.tabName)}e.debug("Component: my-leave-container"),n.section="my-leave";var o=this;o.tabName=t.current.name,o.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(n){return n.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e,n){define("leave-absences/my-leave/modules/config",["common/angular","common/lodash","leave-absences/my-leave/modules/settings"],function(n,t){function a(n){n.withAutoBase(!0),n.settings.ga={userId:t.get(e,"vars.session.contact_id")}}return n.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","$analyticsProvider","settings",function(n,t,o,s,i,r,c){a(r),i.debugEnabled(c.debug),s.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",t.defaults.stripTrailingSlashes=!1,o.otherwise("/my-leave/report"),n.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,n){e["leave-request-id"]&&n.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM,Drupal),define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/angulartics","common/angulartics-google-tag-manager","common/angularUiRouter","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/calendar-feeds/dropdown-button/dropdown-button.module","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","angulartics","angulartics.google.tagmanager","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","calendar-feeds.dropdown-button","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,n,t,a){e.debug("app.run"),n.sharedPathTpl=t.sharedPathTpl,n.settings=a}]),e}),function(e,n){var t=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";n.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":t+"/shared","leave-absences/my-leave":t+"/my-leave"}}),n(["leave-absences/shared/config"],function(){n(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/my-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/src/leave-absences/shared/controllers/request.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/src/leave-absences/shared/controllers/request.controller.js index 4ee1ce96839..b2bd6eaa76c 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/src/leave-absences/shared/controllers/request.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/src/leave-absences/shared/controllers/request.controller.js @@ -828,10 +828,7 @@ define([ // In case of general administration return Contact.all() .then(function (contacts) { - vm.managedContacts = _.remove(contacts.list, function (contact) { - // Removes the admin from the list of contacts - return contact.id !== loggedInContact.id; - }); + vm.managedContacts = contacts.list; }); } else { // In any other case (including managing) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/test/shared/controllers/request.controller.spec.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/test/shared/controllers/request.controller.spec.js index d223c22c9a7..a2437284e9e 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/test/shared/controllers/request.controller.spec.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/test/shared/controllers/request.controller.spec.js @@ -1132,7 +1132,7 @@ describe('admin opens leave request popup in create mode', function () { var leaveRequest; - var adminId = '206'; + var adminId = CRM.vars.leaveAndAbsences.contactId.toString(); beforeEach(function () { leaveRequest = LeaveRequestInstance.init(); @@ -1151,8 +1151,8 @@ expect(controller.isRole('admin')).toBeTruthy(); }); - it('does not contain admin in the list of managees', function () { - expect(_.find(controller.managedContacts, { 'id': adminId })).toBeUndefined(); + it('contains admin in the list of managees', function () { + expect(!!_.find(controller.managedContacts, { 'id': adminId })).toBe(true); }); }); }); From 0659b912f5b62d5e1e75b6333820e8ca4ceddf7d Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Thu, 2 Aug 2018 11:28:01 +0100 Subject: [PATCH 2/2] PCHR-4094: PR Feedback --- .../js/dist/absence-tab.min.js | 2 +- .../js/dist/admin-dashboard.min.js | 4 ++-- .../js/dist/manager-leave.min.js | 8 ++++---- .../js/dist/my-leave.min.js | 4 ++-- .../shared/controllers/request.controller.js | 3 +++ 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/absence-tab.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/absence-tab.min.js index 39da60dd7b6..815bb77154d 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/absence-tab.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/absence-tab.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){e.config({paths:{mocks:"../test/mocks"}}),e.config({paths:{mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(n){return n.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",sourcePath:e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,n,t){"use strict";t.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(t,a,o){return t.debug("AbsenceTypeAPI"),a.extend({all:function(n){return t.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(n||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return t.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:n(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,n){return e.debug("AbsenceTypeInstance"),n.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,n){"use strict";n.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(n,t,a,o,s,i){return n.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,n,t){return s.calculateToilExpiryDate(e,n,t)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(n){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(t){return t=e.indexBy(t,"value"),e.map(n,function(n){return e.assign(n,{calculation_unit_label:t[n.calculation_unit].label,calculation_unit_name:t[n.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,n){"use strict";n.factory("WorkPatternAPI",["$log","api",function(n,t){function a(n){var t=e.clone(n);return t.workPattern=t["api.WorkPattern.get"].values[0],delete t["api.WorkPattern.get"],t}return n.debug("WorkPatternAPI"),t.extend({assignWorkPattern:function(n,t,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:n,pattern_id:t,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(t,a,o,s){return n.debug("WorkPatternAPI.getCalendar",t,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(t)?{IN:t}:t,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(n,t,o){return this.sendGET("ContactWorkPattern","get",e.assign({},t,{contact_id:n,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).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,n,t){"use strict";t.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(t,a,o,s,i){function r(n,t){return u().then(function(a){var o=this.days[c(n).valueOf()];return!!o&&e.find(a,function(e){return e.name===t}).value===o.type}.bind(this))}function c(e){return n(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(n){var t={};return n.calendar.forEach(function(e){t[c(e.date).valueOf()]=e}),e(n).omit("calendar").assign({days:t}).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,n){"use strict";n.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(n,t,a,o){return n.debug("Calendar"),t.extend({get:function(t,s,i,r){return n.debug("Calendar.get"),a.getCalendar(t,s,i,r).then(function(n){var a=n.values.map(function(e){return o.init(e)});return e.isArray(t)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,t){function a(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(t.remainder=a[0].remainder),delete t["api.LeavePeriodEntitlement.getremainder"],t}function o(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return t.value=a,delete t["api.LeavePeriodEntitlement.getentitlement"],t}return e.debug("EntitlementAPI"),t.extend({all:function(n,t){return e.debug("EntitlementAPI.all"),n["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},t&&(n["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",n,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),t&&(e=e.map(a)),e})},breakdown:function(n){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",n).then(function(e){return e.values})},getLeaveBalances:function(n,t,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",n,t,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,n){return e.debug("EntitlementLogAPI"),n.extend({all:function(n){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",n,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,n,t){return e.debug("EntitlementInstance"),n.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return t.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,n){"use strict";n.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(n,t,a,o,s){return n.debug("Entitlement"),t.extend({all:function(e,n){return a.all(this.processFilters(e),n).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(n,t){return a.breakdown(n).then(function(n){return t?(t.map(function(t){var a=e.find(n,function(e){return e.id===t.id});return a&&(t.breakdown=a.breakdown),t}),t):n.map(function(e){return o.init(e,!0)})})},logs:function(n){return n=e.cloneDeep(n||{}),n.contact_id&&(n["entitlement_id.contact_id"]=n.contact_id,delete n.contact_id),n.period_id&&(n["entitlement_id.period_id"]=n.period_id,delete n.period_id),n.return=n.return||[],n.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(n)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,t,a){return e.debug("LeaveRequestAPI"),t.extend({all:function(n,t,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return n&&n.contact_id&&n.contact_id.IN&&0===n.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",n,t,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return t.contact_id&&t.period_id||o.reject("contact_id and period_id are mandatory"),t=n.defaults(t,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",t,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange",t),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){return e.values.breakdown=n.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,n){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:n.toString()},!1)},create:function(n){return e.debug("LeaveRequestAPI.create",n),this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,attachment_id:t}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,t){return t=n.assign({},t,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",t).then(function(e){return e.values})},find:function(n){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:n},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",t,!1).then(function(e){return e.values})},getComments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",t,!1).then(function(e){return e.values})},isManagedBy:function(n,t){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:n,contact_id:t}).then(function(e){return e.values})},isValid:function(t){e.debug("LeaveRequestAPI.isValid",t);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",t).then(function(e){e.count>0?o.reject(n(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,text:t.text,contact_id:t.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(n){return e.debug("LeaveRequestAPI.update",n),n.id?this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,n,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(t,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var n=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=n,t.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return t.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function f(e){return n.duration(e.time_to).subtract(n.duration(e.time_from)).asHours()}function p(n){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return e.find(t,function(e){return e.name===n})})}function h(n){var a=e.cloneDeep(n),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return t.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(n){return s.amount=n[0].time_from?Math.min(this.from_date_amount,f(n[0])):0,o&&(i.amount=n[1].time_from?Math.min(this.to_date_amount,f(n[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,n){return e+n.amount},0),a}.bind(this))}function v(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(n){return function(){return r.saveComment(e,n)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),t.all(n)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(n){var t=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===n&&e.pull(t,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,t)).then(function(e){return"hours"===n?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return t.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(n){if(n.comment_id)return void(n.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return n.created_at===e.created_at&&n.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(n){return{amount:e.reduce(n.values,function(e,n){return e+parseFloat(n.amount)},0),breakdown:n.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return t.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):a(s.permissions.admin.administer).then(function(n){return n?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):t.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,n,t,a){return e.debug("LeaveRequest"),n.extend({all:function(e,n,o,s,i){return t.all(this.processFilters(e),n,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return t.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return t.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/instances/work-pattern.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("WorkPatternInstance",["$log","ModelInstance",function(e,n){return e.debug("WorkPatternInstance"),n.extend({})}])}),define("leave-absences/shared/models/work-pattern.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/work-pattern.api","leave-absences/shared/instances/work-pattern.instance"],function(e,n){"use strict";n.factory("WorkPattern",["$log","Model","WorkPatternAPI","WorkPatternInstance",function(n,t,a,o){return n.debug("WorkPattern"),t.extend({assignWorkPattern:function(e,n,t,o,s,i){return a.assignWorkPattern(e,n,t,o,s,i)},default:function(){return a.get({is_default:!0}).then(function(n){return o.init(e.first(n),!0)})},unassignWorkPattern:function(e){return a.unassignWorkPattern(e)},workPatternsOf:function(e,n,t){return a.workPatternsOf(e,n,t).then(function(e){return e.map(function(e){return o.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,n,t){function a(n,t,a,o,s,i,r){function c(){return{loadContacts:function(){return l.loadContactsForAdmin()}}}function u(e){i.info("",["

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 l,d;return{init:function(n){return d=n,l=r.init(d),d.filters.userSettings.assignedTo=e.find(d.filtersByAssignee,{type:"me"}),d.showContactDetailsLink=!0,d.showContactName=!0,d.showFilters=!0,d.showAdminFilteringHint=u,c()}}}t.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService","LeaveCalendarService",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(n,t,a,o){function s(){return{loadContacts:function(){return i.loadLookUpAndFilteredContacts()}}}n.debug("LeaveCalendarManagerController");var i,r;return{init:function(n){return r=n,i=o.init(r),r.filters.userSettings.assignedTo=e.find(r.filtersByAssignee,{type:"me"}),r.showContactName=!0,r.showFilters=!0,s()}}}t.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance","LeaveCalendarService",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,t,a){function o(){return{loadContacts:function(){return i.displaySingleContact?s.loadFilteredContacts():"admin"===i.userPermissionRole?s.loadContactsForAdmin():s.loadLookUpAndFilteredContacts()}}}e.debug("LeaveCalendarStaffController");var s,i;return{init:function(e){return i=e,s=a.init(i),i.filters.userSettings.contacts_with_leaves=!0,i.showTheseContacts=[i.contactId],i.showContactName=!0,i.showFilters=!0,i.displaySingleContact&&(i.showFilters=!1,i.lookupContacts=[{id:i.contactId}]),o()}}}t.controller("LeaveCalendarStaffController",["$log","$q","Contact","LeaveCalendarService",a])}),define("leave-absences/shared/components/leave-calendar.component",["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){function a(t,a,o,s,i,r,c,u,l,d){function m(){U().then(g).then(b).then(y).then(w).then(function(){return a.all([C(),D(),I(),H.showFilters?P():e.noop])}).then(function(){f(),_(),B()}).then(function(){H.loading.page=!1})}function f(){H.supportData.absenceTypes.push({id:"",title:"Leave",color:"#4D4D68",calculation_unit:e.chain(H.supportData.calculationUnits).find({name:"days"}).get("value").value()})}function p(){for(var e=[],t=n(H.selectedPeriod.start_date).clone().startOf("month"),a=n(H.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(S(t)),t.add(1,"month");H.months=e}function h(){return e.includes(["admin","manager"],H.userPermissionRole)}function v(e){return e.format("YYYY-MM")}function b(){s.$on("LeaveCalendar::updateFiltersByAbsenceType",function(e,n){H.supportData.absenceTypesToFilterBy=n,M(!0)})}function g(){s.$new().$watch(function(){return H.selectedMonthIndex},function(e,n){null!==n&&e!==n&&(F(),B(),M())})}function _(e){H.injectMonth=!0,N("injected").then(function(){M(e)}).then(function(){H.loading.calendar=!1})}function y(){j=t("LeaveCalendar"+e.capitalize(W)+"Controller").init(H)}function q(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return r.all().then(function(n){H.absencePeriods=e.sortBy(n,"start_date"),H.selectedPeriod=e.find(H.absencePeriods,function(e){return!!e.current})}).then(p).then($)}function T(){return c.all().then(c.loadCalculationUnits)}function A(){return l.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function D(){return j.loadContacts().then(function(e){H.contacts=e})}function P(){return l.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){H.filters.optionValues.regions=e.hrjc_region,H.filters.optionValues.locations=e.hrjc_location,H.filters.optionValues.levelTypes=e.hrjc_level_type,H.filters.optionValues.departments=e.hrjc_department})}function R(){return u.all()}function I(){return a.all([T(),R(),A()]).then(function(n){H.supportData.absenceTypes=n[0],H.supportData.publicHolidays=n[1],H.supportData.calculationUnits=n[2].hrleaveandabsences_absence_type_calculation_unit,H.supportData.dayTypes=n[2].hrleaveandabsences_leave_request_day_type,H.supportData.leaveRequestStatuses=n[2].hrleaveandabsences_leave_request_status,H.supportData.toilAmounts=e.indexBy(n[2].hrleaveandabsences_toil_amounts,"value")})}function w(){var e=a.resolve();return H.injectMonth&&(e=N("destroyed"),H.injectMonth=!1),e}function S(e){return{index:v(e),month:e.month(),year:e.year(),name:e.format("MMMM"),moment:n().year(e.year()).month(e.month())}}function k(){var n=H.selectedPeriod.id;H.selectedPeriod=e.find(H.absencePeriods,function(e){return!!e.current}),n!==H.selectedPeriod.id&&p(),$(),B(),O("month")}function L(e){var t="previous"===e?"subtract":"add";F(n(H.selectedMonth.moment)[t](1,"month")),B(),O("month")}function O(n){n=e.includes(["contacts","period","month"],n)?n:"period",a.resolve().then(w).then("period"===n&&p).then("period"===n&&x).then("contacts"===n&&D).then("month"===n&&B).then(function(){_("contacts"===n)})}function M(e){s.$emit("LeaveCalendar::showMonth",!!e)}function $(){F(n())}function x(){F(H.months[0].moment)}function E(t){var a="previous"===t?"first":"last",o=e[a](H.months),s=n().year(o.year).month(o.month);H.monthPaginatorsAvailability[t]=!H.selectedMonth.moment.isSame(s,"month")}function B(){E("previous"),E("next")}function F(n){n&&(H.selectedMonthIndex=v(n)),H.selectedMonth=e.find(H.months,{index:H.selectedMonthIndex})}function U(){return a.all([d(i.permissions.admin.administer),d(i.permissions.ssp.manage)]).then(function(e){H.userPermissionRole=e[0]?"admin":e[1]?"manager":"staff",W=H.roleOverride?H.roleOverride:H.userPermissionRole})}function N(n){return a(function(t){var a=s.$on("LeaveCalendar::month"+e.capitalize(n),function(){a(),t()})})}o.debug("Component: leave-calendar");var j,W,H=this;H.absencePeriods=[],H.contacts=[],H.contactIdsToReduceTo=null,H.injectMonth=!1,H.months=[],H.selectedMonth={},H.selectedMonthIndex="",H.selectedPeriod=null,H.showContactName=!1,H.showFilters=!1,H.userPermissionRole="staff",H.loading={calendar:!0,page:!0},H.filters={hideOnMobile:!0,optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null},absenceTypes:{}},H.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],H.filters.userSettings.assignedTo=H.filtersByAssignee[2],H.monthPaginatorsAvailability={previous:!0,next:!0},H.supportData={absenceTypesToFilterBy:[]},H.$onInit=m,H.canManageRequests=h,H.labelPeriod=q,H.navigateToCurrentMonth=k,H.paginateMonth=L,H.refresh=O}t.component("leaveCalendar",{bindings:{contactId:"<",displaySingleContact:"0,t={from_date:{to:Q.month.days[Q.month.days.length-1].date+" 23:59:59"},to_date:{from:Q.month.days[0].date+" 00:00:00"},status_id:{IN:L()},contact_id:{IN:Q.contacts.map(function(e){return e.id})},type_id:{IN:n?Q.supportData.absenceTypesToFilterBy:e.pluck(Q.supportData.absenceTypes,"id")}};return _(),i.all(t,null,null,null,!1).then(function(e){return X={},n&&(e.list=q(e.list)),A(e.list)})}function $(){var n=Q.month.days[0].date,t=Q.month.days[Q.month.days.length-1].date;return s.get(Q.contacts.map(function(e){return e.id}),n,t).then(function(n){z=e.indexBy(n,"contact_id")})}function x(){return Q.contactIdsToReduceTo&&(Q.contacts=Q.contacts.filter(function(n){return e.includes(Q.contactIdsToReduceTo,n.contact_id)||e.find(X,function(e){return e.contact_id===n.contact_id})})),a.resolve()}function E(n){var t=S(n);X[n.contact_id]=X[n.contact_id]||{},t.forEach(function(t){e.remove(X[n.contact_id][t.date],function(e){return e.id===n.id})})}function B(){o.$emit("LeaveCalendar::monthDestroyed"),V.map(function(e){e.remove?e.remove():e()})}function F(n,t,o){var s,i;return n.contactsData[t]=n.contactsData[t]||{},i=f(t),s=!0===o?a.resolve():a.all([i.isWeekend(h(n.date)),i.isNonWorkingDay(h(n.date))]).then(function(a){e.assign(n.contactsData[t],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:I(n.date)})}),s.then(function(){return X[t]&&X[t][n.date]?X[t][n.date]:[]}).then(function(a){a=j(a),e.assign(n.contactsData[t],{leaveRequests:a,leaveRequestsToShowInCell:b(a),leaveRequestsAttributes:C(n,a)})})}function U(){return a.all(Q.month.days.map(function(e){return a.all(Q.contacts.map(function(n){return F(e,n.id)}))}))}function N(e,n){Q.currentPage=0,Q.visible=!0,(n||!G)&&O()}function j(t){return e.sortBy(t,function(e){return+n(e.from_date).format("X")+(P("half_day_pm",e,e.from_date)?1:0)})}function W(n){var t=e.find(Q.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 H(e){v(e),-1!==L().indexOf(e.status_id)&&l(e)}function Y(e){return a.all(S(e).map(function(n){return F(n,e.contact_id,!0)}))}t.debug("Component: leave-calendar-month");var G=!1,V=[],z={},X={},Q=this;Q.currentPage=0,Q.pageSize=20,Q.visible=!1,Q.showContactName=!!Q.showContactName,Q.showOnlyWithLeaveRequests=!!Q.showOnlyWithLeaveRequests,Q.$onDestroy=B,Q.$onInit=u,Q.contactsList=p,Q.getContactUrl=y}t.component("leaveCalendarMonth",{bindings:{showTheseContacts:"<",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/models/contact","common/models/session.model","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,l,d,m){function f(){a.resolve().then(y).then(C).then(function(){return _()&&"admin"!==k.role&&R()}).then(P).finally(function(){k.loading.component=!1})}function p(n){S=k.leaveRequest.status_id,e.includes(["cancel","reject","delete"],n)||"toil"===k.leaveRequest.request_type?i.open(q(n)):b(n)}function h(){return"admin"===k.role&&"public_holiday"===k.leaveRequest.request_type}function v(t){var a=k.absenceTypes[k.leaveRequest.type_id].allow_request_cancelation;return"admin"===k.role||("manager"===k.role?e.includes([L.awaitingApproval,L.moreInformationRequired],t):"3"===a?n().isBefore(k.leaveRequest.from_date):"2"===a)}function b(n){i.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return k.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(t){return t?e.assign(c.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){A(n)}}):q(n)})}})}function g(){return s.find(w).then(function(e){return e.checkIfSelfLeaveApprover()})}function _(){return w===k.leaveRequest.contact_id}function y(){e.isArray(k.leaveRequestStatuses)&&(k.leaveRequestStatuses=e.indexBy(k.leaveRequestStatuses,"value")),e.isArray(k.absenceTypes)&&(k.absenceTypes=e.indexBy(k.absenceTypes,"id"))}function q(e){var n=O[e].dialog;return{title:"Confirm "+n.title+"?",copyCancel:"Cancel",copyConfirm:n.btnLabel,classConfirm:"btn-"+n.btnClass,msg:n.msg,onConfirm:function(){return k.leaveRequest[e]().then(function(){D(e)}).catch(function(e){d.error("Error:",e)})}}}function C(){return m.get().then(function(e){w=e.contactId})}function T(e,n){e.stopPropagation(),r.openModal(n)}function A(e){r.openModal({leaveRequest:k.leaveRequest,leaveType:k.leaveRequest.request_type,selectedContactId:k.leaveRequest.contact_id,forceRecalculateBalanceChange:!0,defaultStatus:l.statusNames[M[e]]})}function D(n){var t=e.find(k.leaveRequestStatuses,function(e){return e.name===l.statusNames.awaitingApproval}).value;S===t&&u.publish("ManagerBadge:: Update Count"),u.publish("LeaveRequest::statusUpdate",{status:n,leaveRequest:k.leaveRequest})}function P(){var n=k.leaveRequestStatuses[k.leaveRequest.status_id].name,t=e.compact(e.map(O,function(t,a){return e.includes(t.allowedStatuses,n)?a:null}));!v(n)&&e.pull(t,"cancel"),"admin"!==k.role&&e.pull(t,"delete"),"staff"===k.role&&e.pull(t,"approve","reject"),"staff"!==k.role&&I(t),h()&&t.push("delete"),k.allowedActions=e.map(t,function(e){return{key:e,label:O[e].label,isDirectAction:O[e].isDirectAction}})}function R(){return g().then(function(e){e&&(k.role="admin")})}function I(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 w,S,k=this,L=l.statusNames,O={edit:{label:"Edit",allowedStatuses:[L.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[L.moreInformationRequired]},view:{label:"View",allowedStatuses:[L.approved,L.rejected,L.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[L.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[L.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[L.awaitingApproval,L.approved,L.rejected,L.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[L.awaitingApproval,L.moreInformationRequired,L.approved,L.rejected,L.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}},M={approve:"approved"};k.allowedActions=[],k.loading={component:!0},k.$onInit=f,k.action=p,k.openLeavePopup=T}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","$q","$rootScope","Contact","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService","Session"]}),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(){o.$emit("LeaveRequestPopup::addTab",C),_(),y()}function l(){C.request.comments.push({contact_id:q,leave_request_id:C.request.id,text:C.comment.text}),C.comment.text=""}function d(){return C.comment.text.length>0}function m(e){return!e.comment_id||C.canManage}function f(e){return n.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function p(){return C.request.comments.filter(function(e){return!e.toBeDeleted})}function h(e){return e===q?"Me":C.comment.contacts[e]?C.comment.contacts[e].display_name:void 0}function v(e){return C.mode===e}function b(){C.comment.text.length&&C.addComment()}function g(){var n=e.indexBy(C.request.comments,"contact_id"),t=Object.keys(n);return r.all({id:{IN:t}},{page:1,size:0}).then(function(n){C.comment.contacts=e.indexBy(n.list,"contact_id")})}function _(){return C.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),C.request.comments.length&&g()})}function y(){return C.loading.component=!0,c.get().then(function(e){q=e.contactId}).then(function(){C.loading.component=!1})}t.debug("Component: leave-request-popup-comments-tab");var q=null,C=this;C.loading={component:!0},C.comment={text:"",contacts:{}},C.$onInit=u,C.addComment=l,C.canRemoveComment=m,C.canSubmit=d,C.formatDateTime=f,C.getActiveComments=p,C.getCommentorName=h,C.isMode=v,C.onBeforeSubmit=b}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(){t("RequestModalDetails"+e.capitalize(T(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),w(),te.initChildController().then(function(){return i.all([x(),$()])}).then(!te.isMode("create")&&I).then(Y).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(z)}).then(!te.isMode("create")&&H).then(S).then(G).then(R).then(k).then(!te.isMode("view")&&te.initWatchersExtended).catch(P).then(function(){te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.totalItems=te.balance.change.breakdown.length}).finally(function(){te.loading.tab=!1})}function p(){te.balance.closing=te.balance.opening+te.balance.change.amount}function h(e){return n(e,c.serverDateFormat).toDate()}function v(e){return n(e).format(c.serverDateFormat)}function b(e){var n;return i.resolve().then(function(){j(e),"from"===e&&N(),L("hours")&&(y(e),"from"!==e||te.uiOptions.multipleDays||y("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return C(e)}).then(function(e){if(n=e.id!==te.period.id,n&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(H).then(function(){if(n)return x()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(z(),!n)return B();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(P).finally(q)}function g(){return z(),B()}function _(){return te.uiOptions.toDate=null,j("to"),i.resolve().then(z).then(te.setDaysSelectionModeExtended).then(q).then(!te.uiOptions.multipleDays&&B)}function y(e){te.uiOptions.times[e].loading=!0}function q(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,L("hours")&&(te.uiOptions.times[e].loading=!1)})}function C(t){var a=n(te.uiOptions[t+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function T(){return te.request?te.request.request_type:te.leaveType||null}function A(e){return n().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return X(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(W).catch(P)}function P(n){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(n)?n:[n]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function R(){return te.isMode("create")||te.forceRecalculateBalanceChange?B():D()}function I(){var e=te.request.attributes();return te.uiOptions.fromDate=h(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=h(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function w(){ne.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,n){K(n)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",B))}function S(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(ee={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function k(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,n){e!==n&&(te.uiOptions.multipleDays||(Z(e),z()))})}function L(e){return te.selectedAbsenceType.calculation_unit_name===e}function O(e){return te.request.request_type===e}function M(n){return e.includes(["weekend","non_working_day","public_holiday"],n)}function $(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,n=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,n)}function B(){return X(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(W).catch(P).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function F(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return v(te.request.from_date)===v(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&n(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,j("to"))}function j(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),z(),X()}function W(e){te.balance.change=e,te.request.balance_change=e.amount,p(),F(),te.loading.balanceChange=!1}function H(){var e,t,a;te.uiOptions.fromDate?(e=n(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,t=e):(a=h(te.period.start_date),t=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=t,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=h(te.period.end_date)}function Y(){return!te.isMode("create")&&U()||te.isMode("create")&&(O("sickness")||L("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){ee&&ee.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=ee.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function V(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function z(){var e=te.uiOptions,n=e.times;te.request.from_date=e.fromDate?v(e.fromDate):null,te.request.to_date=e.toDate?v(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),(L("hours")||O("toil"))&&(te.request.from_date=te.request.from_date&&n.from.time?te.request.from_date+" "+n.from.time:null,te.request.to_date=te.request.to_date&&n.to.time?te.request.to_date+" "+n.to.time:null)}function X(){te.uiOptions.showBalance=te.canCalculateChange()}function Q(){e.forEach(ne,function(e){e()})}function J(){var e,n=te.selectedAbsenceType.calculation_unit_name;return V(),e=n!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&Y).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&z).then(q).then(B)}function K(e){return te.absenceTypes=e,V(),n(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,j("to")),G(),B()}function Z(e){var n=A(e).add(te.uiOptions.time_interval,"minutes");n.isAfter(A(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=n.format("HH:mm"),n.isAfter(A(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var ee=null,ne=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:[],numPerPage:7,totalItems:0,pageChanged:E},te.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},te.$onInit=f,te.convertDateFormatFromServer=h,te.convertDateToServerFormat=v,te.dateChangeHandler=b,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=_,te.disableAndShowLoadingTimeInput=y,te.getMomentDateWithGivenTime=A,te.handleError=P,te.isCalculationUnit=L,te.isLeaveType=O,te.isNotWorkingDay=M,te.performBalanceChangeCalculation=B,te.setRequestDateTimesAndDateTypes=z,te.updateEndTimeInputMinTime=Z,te.$onDestroy=Q}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(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",k),_(),a.all([A(),C()]).then(y).finally(function(){k.filesLoaded=!0})}function m(){return k.fileUploader&&k.fileUploader.queue.length>0}function f(){return k.getFilesAmount()0?I.map(function(e){return e.label}).join(", "):""}function C(){return k.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function T(){return a.all(I.map(function(e){return l.getMimeTypeFor(e.label).then(function(n){S[e.label]=n})})).catch(function(){S=null})}function A(){return c.valuesOf("safe_file_extension").then(function(e){I=e})}function D(e){return!e.attachment_id||k.canManage}function P(){e.forEach(w,function(e){e()})}function R(e,n){k.fileUploader.queue&&k.fileUploader.queue.length>0?k.fileUploader.uploadAll({entityID:k.request.id}).then(function(){n()}).catch(n):n()}t.debug("Component: leave-request-popup-files-tab");var I=[],w=[],S={},k=Object.create(this);return k.filesLoaded=!1,k.fileUploader=null,k.today=Date.now(),k.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",k.userDateFormat=i.DATE_FORMAT,k.$onDestroy=P,k.$onInit=d,k.canRemoveAttachment=D,k.canSubmit=m,k.canUploadMore=f,k.formatDateTime=p,k.getAuthorName=h,k.getFilesAmount=v,k.listFileTypes=q,k}t.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function n(e,n,t){function a(){s=t.parse(),s.openModal&&o({leaveType:s.openModal,selectedContactId:i.selectedContactId})}function o(e){n.openModal(e)}e.debug("Component: leave-request-record-actions");var s,i=this;i.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],i.$onInit=a,i.openLeavePopup=o}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",n]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,n,t){function a(n,t,a,o,s,i,r,c,u,l,d,m){function f(){t.all([q(),E(),A(),T()]).then(function(){z.loading.page=!1}).then(function(){return t.all([R(),P()])}).then(B).then(function(){z.loading.content=!1}),N()}function p(e,n){n.data.push(e),n.dataIndex[e.id]=e}function h(){z.absenceTypes=z.absenceTypes.map(function(n){var t=e.find(z.entitlements,function(e){return e.type_id===n.id});return n.entitlement=t?t.value:0,n.remainder=t?t.remainder:{current:0,future:0},n})}function v(e){j(e),z.sections.other.open&&p(e,z.sections.other)}function b(){Object.values(z.sections).forEach(function(e){e.data=[]})}function g(){z.absenceTypesFiltered=z.absenceTypes.filter(function(e){return!(0===e.entitlement&&"1"!==e.allow_overuse&&"1"!==e.allow_accruals_request)})}function _(e){var n=V[e.status];n?n(e.leaveRequest):z.refresh()}function y(n){n.dataIndex=e.indexBy(n.data,"id")}function q(){return z.role="staff","absence-tab"===a.section?(z.role="admin",t.resolve()):o(m.permissions.admin.administer).then(function(e){e&&(z.role="admin")})}function C(e){return e.current?"Current Period ("+e.title+")":e.title}function T(){return s.all().then(function(n){z.absencePeriods=e.sortBy(n,"start_date"),z.selectedPeriod=e.find(z.absencePeriods,function(e){return!0===e.current})})}function A(){return i.all().then(i.loadCalculationUnits).then(function(n){z.absenceTypes=n,z.absenceTypesIndexed=e.indexBy(n,"id")})}function D(){return k("approved",{status_id:G(m.statusNames.approved)})}function P(){var n={contact_id:z.contactId,period_id:z.selectedPeriod.id};return t.all([c.balanceChangeByAbsenceType(e.assign({},n,{public_holiday:!0})),c.balanceChangeByAbsenceType(e.assign({},n,{expired:!0})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.approved)]}})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}}))]).then(function(e){z.absenceTypes.forEach(function(n){n.balanceChanges={holidays:e[0][n.id],expired:e[1][n.id],approved:e[2][n.id],pending:e[3][n.id]}})})}function R(){return r.all({contact_id:z.contactId,period_id:z.selectedPeriod.id},!0).then(function(e){z.entitlements=e})}function I(){return r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id},z.entitlements).then(function(){return F(z.entitlements)}).then(function(e){z.sections.entitlements.data=e})}function w(){return t.all([r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id,expired:!0}),S({request_type:"toil",expired:!0})]).then(function(e){return t.all({expiredBalanceChangesFlatten:F(e[0]),expiredTOILS:U(e[1].list)})}).then(function(n){z.sections.expired.data=n.expiredBalanceChangesFlatten.concat(n.expiredTOILS),z.sections.expired.data=e.sortBy(z.sections.expired.data,"expiry_date")})}function S(n){return c.all(e.assign({contact_id:z.contactId,from_date:{from:z.selectedPeriod.start_date},to_date:{to:z.selectedPeriod.end_date},type_id:{IN:z.absenceTypes.map(function(e){return e.id})}},n),null,"from_date ASC",null,!1)}function k(e,n){return S(n).then(function(n){z.sections[e].data=n.list})}function L(){return t.all(Object.values(z.sections).filter(function(e){return e.open}).map(x))}function O(){return k("other",{status_id:{in:[G(m.statusNames.rejected),G(m.statusNames.cancelled)]}})}function M(){return k("pending",{status_id:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}})}function $(){return k("holidays",{public_holiday:!0})}function x(e){return e.loading=!0,e.loadLeaveRequests().then(y.bind(this,e)).then(function(){e.loading=!1})}function E(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){z.leaveRequestStatuses=e.indexBy(n,"value")})}function B(){h(),g()}function F(n){return t.resolve().then(function(){return n.map(function(n){var t=e.find(z.entitlements,function(e){return e.id===n.id});return n.breakdown.map(function(n){return e.assign(e.clone(n),{type_id:t.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})} -function U(n){return t.resolve().then(function(){return n.map(function(n){return e.assign({},n,{expiry_date:n.toil_expiry_date,amount:n.toil_to_accrue,type:{label:"Accrued TOIL"}})})})}function N(){l.subscribe("LeaveRequest::new",function(){z.refresh()}),l.subscribe("LeaveRequest::edit",function(){z.refresh()}),l.subscribe("LeaveRequest::statusUpdate",_),l.subscribe("LeaveRequest::delete",function(e){j(e)})}function j(n){e.forEach(z.sections,function(t,a){t.dataIndex[n.id]&&(e.remove(t.data,function(e){return e.id===n.id}),delete t.dataIndex[n.id],"other"!==a&&W(n,a))})}function W(n,t){var a=["future","current"],o=z.absenceTypesIndexed[n.type_id];"pending"===t&&e.pull(a,"current"),o.balanceChanges[t]-=n.balance_change,a.forEach(function(e){o.remainder[e]-=n.balance_change})}function H(){z.loading.content=!0,t.all([R(),P()]).then(B).then(function(){z.loading.content=!1}).then(function(){return t.all([L(),b()])})}function Y(e){var n=z.sections[e];n.open=!n.open,n.open&&!n.data.length&&x(n)}function G(n){return e.find(z.leaveRequestStatuses,function(e){return e.name===n}).value}n.debug("Component: staff-leave-report");var V={delete:j,cancel:v},z=this;z.absencePeriods=[],z.absenceTypes=[],z.absenceTypesFiltered=[],z.absenceTypesIndexed={},z.dateFormat=d.DATE_FORMAT,z.leaveRequestStatuses={},z.selectedPeriod=null,z.role=null,z.loading={content:!0,page:!0},z.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:$},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:M},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O}},z.$onInit=f,z.labelPeriod=C,z.refresh=H,z.toggleSection=Y}t.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:a}),a.$inject=["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,n=!!e.from_date&&!!e.to_date,t=i.selectedAbsenceType.calculation_unit_name;return"days"===t?n=n&&!!e.from_date_type&&!!e.to_date_type:"hours"===t&&(n=n&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),n}function d(){return i.canCalculateChange()}function m(n,t){var a=i.uiOptions.times[n],o=e.clone(t.time_from),s=e.clone(t.time_to);i.uiOptions.multipleDays||("from"===n&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===n&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===n?a.max:a.min}function f(n,t){return n?(n=i.convertDateToServerFormat(n),v(n).then(function(t){return t?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(n,i.requestDayTypes).then(function(n){return n.length?n:i.requestDayTypes.filter(function(n){return e.includes(["all_day","half_day_am","half_day_pm"],n.name)})})}).then(function(e){return I(t,e),e})):o.reject([])}function p(e,t){return e=n(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(n){return n.name===e}):[]})}function h(e,t){return n.duration(t).subtract(n.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function _(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,n){i.isCalculationUnit("days")||+e==+n||(i.isRole("staff")&&(i.request.change_balance=!0),k(),i.performBalanceChangeCalculation())})}function y(e){var t=n(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,t)<=0||h(a.max,t)>=0)&&(t="from"===e?a.min:a.max),i.uiOptions.times[e].time=t}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],n=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(P)).then(function(){["from","to"].forEach(function(e){y(e),S(e),n[e].amount=Math.min(i.request[e+"_date_amount"],n[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(k)}function C(){["from","to"].forEach(function(e){_(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(n,t){i.isCalculationUnit("days")||n===t||(i.setRequestDateTimesAndDateTypes(),n&&S(e,!0))})}function A(e,n){return f(e,n).then(function(){i.loading[n+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return P(e).then(function(){S(e,!0)})})}function P(e){var n=i.uiOptions[e+"Date"],t=!i.uiOptions.multipleDays;return n?i.request.getWorkDayForDate(i.convertDateToServerFormat(n)).then(function(n){O[e]=n,m(e,n),t&&"from"===e&&m("to",n)}).catch(function(n){return O[e]={},i.handleError(n)}).finally(function(){i.uiOptions.times[e].loading=!1,t&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function R(n){var t=i.uiOptions.times[n];i["request"+e.startCase(n)+"DayTypes"]=[],t.time="",t.min="00:00",t.max="00:00",t.amount="0",t.maxAmount="0"}function I(n,t){var a="request"+e.startCase(n)+"DayTypes";i[a]=t,i.isMode("create")&&(i.request[n+"_date_type"]=i[a][0].value)}function w(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),P("from").then(function(){S("from",!0)})):o.resolve()}function S(e,n){var t=i.uiOptions,a=t.multipleDays?e:"from",o=t.times[a],s=t.multipleDays&&"to"===a?o.min:t.times.from.time,r=t.multipleDays&&"from"===a?o.max:t.times.to.time,c=O[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,n&&(o.amount=o.maxAmount)}function k(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function L(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?P("from").then(function(){S("from",!0)}):o.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=L,i.onDateChangeExtended=D,i.resetUIInputsExtended=R,i.setDaysSelectionModeExtended=w}t.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(n){var t=r.request.getDocumentArray();return!!e.find(t,function(e){return e===n})}function d(n){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===n})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(n){return i.valuesOf("hrleaveandabsences_sickness_reason",n).then(function(n){r.sicknessReasons=e.indexBy(n,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}t.debug("RequestModalDetailsSicknessController"),n("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}n.controller("RequestModalDetailsSicknessController",t),t.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=n.duration(n(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,n=!c.uiOptions.multipleDays&&!!c.request.from_date,t=n||e,a=N.from_date!==c.request.from_date||N.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&t&&W.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,n=c.request;return b({hasErrors:e?!n.to_date&&!n.from_date:!n.from_date,label:e?"To Date":"From Date",value:n.to_date})}function b(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(n(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&W.hasExpirationFromAdminSettings,n=W.hasPreviousExpirationDate,t=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=t&&(a||e||n)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return W.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){W.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&L(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function R(){c.isMode("view")||(T(),A(),P())}function I(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function w(){return l(),O(),F()}function S(){return $(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:O(),F()}function k(e){c.uiOptions.times[e].time=""}function L(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){N=e.cloneDeep(c.request.attributes())}function $(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?L():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function U(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var N,j=!c.isMode("create"),W={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=R,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=k,c.setDaysSelectionModeExtended=S,c.updateExpiryDate=U,function(){M(),$(),B(),!c.isMode("create")&&_()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,t,a){return e.debug("AbsencePeriodInstance"),t.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var t=n();return e.current=!1,n(e.start_date).isSameOrBefore(t,"day")&&n(e.end_date).isSameOrAfter(t,"day")&&(e.current=!0),e},isInPeriod:function(e){var t=a.DATE_FORMAT.toUpperCase(),o=n(e,t);return n(this.start_date).isSameOrBefore(o)&&n(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,n){return e.debug("AbsencePeriodAPI"),n.extend({all:function(n){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,t,a,o,s){return e.debug("AbsencePeriod"),t.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=n().format(s.serverDateFormat),t={start_date:{"<=":e},end_date:{">=":e}};return a.all(t).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,n){return e.debug("PublicHolidayAPI"),n.extend({all:function(n){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,n){return e.debug("PublicHolidayInstance"),n.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,n){"use strict";n.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(n,t,a,o,s){return n.debug("PublicHoliday"),t.extend({all:function(e){return n.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(t){n.debug("PublicHoliday.isPublicHoliday",t);var o=e(t).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C){function T(e){"days"===Ue.selectedAbsenceType.calculation_unit_name?delete Ue.request[e+"_date_amount"]:delete Ue.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return Le.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function P(){var e=Ue.requestStatuses[_.statusNames.awaitingApproval].value;$e.status_id===e&&e!==Ue.request.status_id&&d.publish("ManagerBadge:: Update Count")}function R(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!Ue.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function S(){var e=R();return Ue.isMode("edit")&&(e=e&&(G()||I())),Ue.canManage&&Ue.requestStatuses&&(e=e&&!!Ue.getStatusFromValue(Ue.newStatusOnSave)),(e=e&&!!Ue.period.id)&&!Ue.isMode("view")}function k(){Ue.isSelfRecord&&!Ue.isSelfLeaveApprover?Ue.request.status_id=Ue.requestStatuses[_.statusNames.awaitingApproval].value:Ue.canManage&&(Ue.request.status_id=Ue.newStatusOnSave||Ue.request.status_id)}function L(){if(Ue.isMode("edit")&&!Ue.isRole("staff")&&"toil"!==j())return Ue.request.calculateBalanceChange(Ue.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ue.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==j()&&!Ue.request.change_balance}function M(){Ue.errors=[]}function $(){return Ue.request.create().then(Re).then(function(){ge("LeaveRequest::new")})}function x(){se()&&!Ue.isRole("staff")&&(Ue.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ue.request.delete().then(function(){Ue.dismissModal(),d.publish("LeaveRequest::delete",Ue.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(Ue.getStatusFromValue(Ue.request.status_id).name)}function N(e){return t.map(Oe[e],function(e){return Ue.requestStatuses[e]})}function j(){return Ue.request?Ue.request.request_type:Ue.leaveType||null}function W(){return!Ue.request||e.equals({},Ue.requestStatuses)?[]:Ue.request.status_id?U():N("none")}function H(e){return t.find(Ue.requestStatuses,function(n){return n.value===e})}function Y(e){Ue.errors=t.isArray(e)?e:[e],Ue.loading.absenceTypes=!1,Ue.submitting=!1}function G(){return!e.equals($e,Ue.request.attributes())||Ue.canManage&&Ue.newStatusOnSave}function V(){return Ue.postContactSelection=!0,Ue.staffMemberSelectionComplete=!1,Ue.request.contact_id?o.resolve().then(me).then(fe).then(ye).then(Ce).then(oe).then(Q).then(Ue.isMode("edit")?Te:t.noop).then(function(){Ue.postContactSelection=!1,Ue.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Oe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function X(){Ue.canManage=Ue.isRole("manager")||Ue.isRole("admin")}function Q(){return Ue.canManage?f.find(Ue.request.contact_id).then(function(e){Ue.contactName=e.display_name}):o.resolve()}function J(){Ue.isRole("admin")&&Ue.isSelfRecord&&(Ue.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+Le.id==+t.get(Ue,"leaveRequest.contact_id"),a=!t.get(Ue,"leaveRequest.id");Ue.isSelfRecord=e&&a||n}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(ye).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ue.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Ie),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ue.request=Ue.leaveRequest||null,e=j(),n=Ue.initRequestAttributes(),"leave"===e?Ue.request=g.init(n):"sickness"===e?Ue.request=y.init(n):"toil"===e&&(Ue.request=q.init(n))}function ne(){var e={};return Ue.request?e=Ue.request.attributes():Ue.canManage||(e={contact_id:Le.id}),e}function te(){return Be="staff",ae().then(Ue.isSelfRecord&&!Ue.isRole("admin")&&D)}function ae(){return c(_.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(_.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ue.defaultStatus?Ue.newStatusOnSave=Ue.requestStatuses[_.statusNames[Ue.defaultStatus]].value:(Ue.isRole("admin")||Ue.isMode("create")&&Ue.isRole("manager"))&&(Ue.newStatusOnSave=Ue.requestStatuses[_.statusNames.approved].value)}function se(){return!Ue.request.status_id||!t.includes(["cancelled","rejected"],H(Ue.request.status_id).name)}function ie(e){var n=Ue.getStatusFromValue(Ue.request.status_id);return!!n&&n.name===e}function re(e){return Ue.request&&Ue.request.request_type===e}function ce(e){return Ue.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ue.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){ke={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ue.loading.entitlements=!0,v.all({contact_id:Ue.request.contact_id,period_id:Ue.period.id,type_id:{IN:ke.ids}},!0).finally(function(){Ue.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){Le=e})}function he(){return Ue.selectedContactId?f.find(Ue.selectedContactId).then(function(e){Ue.managedContacts=[e]}):Ue.isRole("admin")?f.all().then(function(e){console.log(e.list),Ue.managedContacts=e.list}):Le.leaveManagees().then(function(e){Ue.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ue.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){P(),d.publish(e,Ue.request),Ue.errors=[],Ue.dismissModal()}function _e(){["from","to"].forEach(function(e){Ue.request[e+"_date"]=$e[e+"_date"]})}function ye(e){if(Ue.absenceTypes=be(ke.types,e),!Ue.absenceTypes.length)return o.reject(Ee)}function qe(){Ue.period=t.find(Ue.absencePeriods,function(e){return Ue.isMode("create")?e.current:ue(Ue.request,e)})}function Ce(){Ue.isMode("create")?(Ue.selectedAbsenceType=Ue.absenceTypes[0],Ue.request.type_id=Ue.selectedAbsenceType.id):Ue.selectedAbsenceType=t.find(Ue.absenceTypes,function(e){return e.id===Ue.request.type_id})}function Te(){$e=e.copy(Ue.request.attributes())}function Ae(){var e;Ue.request.id?(e=[Ue.requestStatuses[_.statusNames.approved].value,Ue.requestStatuses[_.statusNames.adminApproved].value,Ue.requestStatuses[_.statusNames.rejected].value,Ue.requestStatuses[_.statusNames.cancelled].value],Ue.mode="edit",Ue.isRole("staff")&&e.indexOf(Ue.request.status_id)>-1&&(Ue.mode="view")):Ue.mode="create"}function De(){var e=Ue.request.status_id;if(!Ue.isMode("view")&&!Ue.submitting)return Ue.submitting=!0,k(),A(),Ue.request.isValid().then(se()&&L).then(x).then(O()&&_e).then(Pe).then(function(){return Ue.isMode("edit")?Se():$()}).catch(function(n){Ue.request.status_id=e,n&&Y(n)}).finally(function(){Ue.submitting=!1})}function Pe(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Re(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Ie(){xe.forEach(function(e){e()})}function we(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Se(){return Ue.request.update().then(Re).then(function(){Ue.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ue.isRole("staff")||Ue.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var ke,Le,Oe={},Me=0,$e={},xe=[],Ee="No entitlement",Be="",Fe=[],Ue=t.assign(this,m);Ue.absencePeriods=[],Ue.absenceTypes=[],Ue.canManage=!1,Ue.contactName=null,Ue.errors=[],Ue.isSelfLeaveApprover=!1,Ue.loading={absenceTypes:!0,entitlements:!0},Ue.managedContacts=[],Ue.mode="",Ue.newStatusOnSave=null,Ue.period={},Ue.postContactSelection=!1,Ue.requestStatuses={},Ue.selectedAbsenceType={},Ue.staffMemberSelectionComplete=!1,Ue.submitting=!1,Ue.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ue.canChangeAbsenceType=w,Ue.canSubmit=S,Ue.closeAlert=M,Ue.deleteLeaveRequest=E,Ue.dismissModal=B,Ue.getStatuses=W,Ue.getStatusFromValue=H,Ue.initAfterContactSelection=V,Ue.initRequestAttributes=ne,Ue.isLeaveStatus=ie,Ue.isLeaveType=re,Ue.isMode=ce,Ue.isRole=le,Ue.submit=De,Ue.updateAbsenceType=we,function(){Ue.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ue.canManage&&!Ue.isMode("edit")&&he()}).then(function(){if(Ue.selectedContactId&&(Ue.request.contact_id=Ue.selectedContactId),Ue.request.contact_id)return Ue.initAfterContactSelection()}).catch(Y).finally(function(){Ue.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}), +function U(n){return t.resolve().then(function(){return n.map(function(n){return e.assign({},n,{expiry_date:n.toil_expiry_date,amount:n.toil_to_accrue,type:{label:"Accrued TOIL"}})})})}function N(){l.subscribe("LeaveRequest::new",function(){z.refresh()}),l.subscribe("LeaveRequest::edit",function(){z.refresh()}),l.subscribe("LeaveRequest::statusUpdate",_),l.subscribe("LeaveRequest::delete",function(e){j(e)})}function j(n){e.forEach(z.sections,function(t,a){t.dataIndex[n.id]&&(e.remove(t.data,function(e){return e.id===n.id}),delete t.dataIndex[n.id],"other"!==a&&W(n,a))})}function W(n,t){var a=["future","current"],o=z.absenceTypesIndexed[n.type_id];"pending"===t&&e.pull(a,"current"),o.balanceChanges[t]-=n.balance_change,a.forEach(function(e){o.remainder[e]-=n.balance_change})}function H(){z.loading.content=!0,t.all([R(),P()]).then(B).then(function(){z.loading.content=!1}).then(function(){return t.all([L(),b()])})}function Y(e){var n=z.sections[e];n.open=!n.open,n.open&&!n.data.length&&x(n)}function G(n){return e.find(z.leaveRequestStatuses,function(e){return e.name===n}).value}n.debug("Component: staff-leave-report");var V={delete:j,cancel:v},z=this;z.absencePeriods=[],z.absenceTypes=[],z.absenceTypesFiltered=[],z.absenceTypesIndexed={},z.dateFormat=d.DATE_FORMAT,z.leaveRequestStatuses={},z.selectedPeriod=null,z.role=null,z.loading={content:!0,page:!0},z.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:w},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:$},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:M},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O}},z.$onInit=f,z.labelPeriod=C,z.refresh=H,z.toggleSection=Y}t.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:a}),a.$inject=["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,n=!!e.from_date&&!!e.to_date,t=i.selectedAbsenceType.calculation_unit_name;return"days"===t?n=n&&!!e.from_date_type&&!!e.to_date_type:"hours"===t&&(n=n&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),n}function d(){return i.canCalculateChange()}function m(n,t){var a=i.uiOptions.times[n],o=e.clone(t.time_from),s=e.clone(t.time_to);i.uiOptions.multipleDays||("from"===n&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===n&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===n?a.max:a.min}function f(n,t){return n?(n=i.convertDateToServerFormat(n),v(n).then(function(t){return t?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(n,i.requestDayTypes).then(function(n){return n.length?n:i.requestDayTypes.filter(function(n){return e.includes(["all_day","half_day_am","half_day_pm"],n.name)})})}).then(function(e){return I(t,e),e})):o.reject([])}function p(e,t){return e=n(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(n){return n.name===e}):[]})}function h(e,t){return n.duration(t).subtract(n.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function _(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,n){i.isCalculationUnit("days")||+e==+n||(i.isRole("staff")&&(i.request.change_balance=!0),k(),i.performBalanceChangeCalculation())})}function y(e){var t=n(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,t)<=0||h(a.max,t)>=0)&&(t="from"===e?a.min:a.max),i.uiOptions.times[e].time=t}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],n=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(P)).then(function(){["from","to"].forEach(function(e){y(e),S(e),n[e].amount=Math.min(i.request[e+"_date_amount"],n[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(k)}function C(){["from","to"].forEach(function(e){_(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(n,t){i.isCalculationUnit("days")||n===t||(i.setRequestDateTimesAndDateTypes(),n&&S(e,!0))})}function A(e,n){return f(e,n).then(function(){i.loading[n+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return P(e).then(function(){S(e,!0)})})}function P(e){var n=i.uiOptions[e+"Date"],t=!i.uiOptions.multipleDays;return n?i.request.getWorkDayForDate(i.convertDateToServerFormat(n)).then(function(n){O[e]=n,m(e,n),t&&"from"===e&&m("to",n)}).catch(function(n){return O[e]={},i.handleError(n)}).finally(function(){i.uiOptions.times[e].loading=!1,t&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function R(n){var t=i.uiOptions.times[n];i["request"+e.startCase(n)+"DayTypes"]=[],t.time="",t.min="00:00",t.max="00:00",t.amount="0",t.maxAmount="0"}function I(n,t){var a="request"+e.startCase(n)+"DayTypes";i[a]=t,i.isMode("create")&&(i.request[n+"_date_type"]=i[a][0].value)}function w(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),P("from").then(function(){S("from",!0)})):o.resolve()}function S(e,n){var t=i.uiOptions,a=t.multipleDays?e:"from",o=t.times[a],s=t.multipleDays&&"to"===a?o.min:t.times.from.time,r=t.multipleDays&&"from"===a?o.max:t.times.to.time,c=O[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,n&&(o.amount=o.maxAmount)}function k(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function L(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?P("from").then(function(){S("from",!0)}):o.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=L,i.onDateChangeExtended=D,i.resetUIInputsExtended=R,i.setDaysSelectionModeExtended=w}t.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(n){var t=r.request.getDocumentArray();return!!e.find(t,function(e){return e===n})}function d(n){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===n})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(n){return i.valuesOf("hrleaveandabsences_sickness_reason",n).then(function(n){r.sicknessReasons=e.indexBy(n,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}t.debug("RequestModalDetailsSicknessController"),n("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}n.controller("RequestModalDetailsSicknessController",t),t.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=n.duration(n(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,n=!c.uiOptions.multipleDays&&!!c.request.from_date,t=n||e,a=N.from_date!==c.request.from_date||N.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&t&&W.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,n=c.request;return b({hasErrors:e?!n.to_date&&!n.from_date:!n.from_date,label:e?"To Date":"From Date",value:n.to_date})}function b(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(n(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&W.hasExpirationFromAdminSettings,n=W.hasPreviousExpirationDate,t=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=t&&(a||e||n)}function _(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function y(){return W.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){W.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",y().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&L(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function P(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function R(){c.isMode("view")||(T(),A(),P())}function I(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function w(){return l(),O(),F()}function S(){return $(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:O(),F()}function k(e){c.uiOptions.times[e].time=""}function L(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){N=e.cloneDeep(c.request.attributes())}function $(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?L():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function U(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var N,j=!c.isMode("create"),W={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=R,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=w,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=k,c.setDaysSelectionModeExtended=S,c.updateExpiryDate=U,function(){M(),$(),B(),!c.isMode("create")&&_()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,t,a){return e.debug("AbsencePeriodInstance"),t.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var t=n();return e.current=!1,n(e.start_date).isSameOrBefore(t,"day")&&n(e.end_date).isSameOrAfter(t,"day")&&(e.current=!0),e},isInPeriod:function(e){var t=a.DATE_FORMAT.toUpperCase(),o=n(e,t);return n(this.start_date).isSameOrBefore(o)&&n(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,n){return e.debug("AbsencePeriodAPI"),n.extend({all:function(n){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,t,a,o,s){return e.debug("AbsencePeriod"),t.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=n().format(s.serverDateFormat),t={start_date:{"<=":e},end_date:{">=":e}};return a.all(t).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,n){return e.debug("PublicHolidayAPI"),n.extend({all:function(n){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,n){return e.debug("PublicHolidayInstance"),n.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,n){"use strict";n.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(n,t,a,o,s){return n.debug("PublicHoliday"),t.extend({all:function(e){return n.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(t){n.debug("PublicHoliday.isPublicHoliday",t);var o=e(t).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,_,y,q,C){function T(e){"days"===Ue.selectedAbsenceType.calculation_unit_name?delete Ue.request[e+"_date_amount"]:delete Ue.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return Le.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function P(){var e=Ue.requestStatuses[_.statusNames.awaitingApproval].value;$e.status_id===e&&e!==Ue.request.status_id&&d.publish("ManagerBadge:: Update Count")}function R(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function w(){return!Ue.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function S(){var e=R();return Ue.isMode("edit")&&(e=e&&(G()||I())),Ue.canManage&&Ue.requestStatuses&&(e=e&&!!Ue.getStatusFromValue(Ue.newStatusOnSave)),(e=e&&!!Ue.period.id)&&!Ue.isMode("view")}function k(){Ue.isSelfRecord&&!Ue.isSelfLeaveApprover?Ue.request.status_id=Ue.requestStatuses[_.statusNames.awaitingApproval].value:Ue.canManage&&(Ue.request.status_id=Ue.newStatusOnSave||Ue.request.status_id)}function L(){if(Ue.isMode("edit")&&!Ue.isRole("staff")&&"toil"!==j())return Ue.request.calculateBalanceChange(Ue.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ue.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==j()&&!Ue.request.change_balance}function M(){Ue.errors=[]}function $(){return Ue.request.create().then(Re).then(function(){ge("LeaveRequest::new")})}function x(){se()&&!Ue.isRole("staff")&&(Ue.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ue.request.delete().then(function(){Ue.dismissModal(),d.publish("LeaveRequest::delete",Ue.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(Ue.getStatusFromValue(Ue.request.status_id).name)}function N(e){return t.map(Oe[e],function(e){return Ue.requestStatuses[e]})}function j(){return Ue.request?Ue.request.request_type:Ue.leaveType||null}function W(){return!Ue.request||e.equals({},Ue.requestStatuses)?[]:Ue.request.status_id?U():N("none")}function H(e){return t.find(Ue.requestStatuses,function(n){return n.value===e})}function Y(e){Ue.errors=t.isArray(e)?e:[e],Ue.loading.absenceTypes=!1,Ue.submitting=!1}function G(){return!e.equals($e,Ue.request.attributes())||Ue.canManage&&Ue.newStatusOnSave}function V(){return Ue.postContactSelection=!0,Ue.staffMemberSelectionComplete=!1,Ue.request.contact_id?o.resolve().then(me).then(fe).then(ye).then(Ce).then(oe).then(Q).then(Ue.isMode("edit")?Te:t.noop).then(function(){Ue.postContactSelection=!1,Ue.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];Oe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function X(){Ue.canManage=Ue.isRole("manager")||Ue.isRole("admin")}function Q(){return Ue.canManage?f.find(Ue.request.contact_id).then(function(e){Ue.contactName=e.display_name}):o.resolve()}function J(){Ue.isRole("admin")&&Ue.isSelfRecord&&(Ue.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+Le.id==+t.get(Ue,"leaveRequest.contact_id"),a=!t.get(Ue,"leaveRequest.id");Ue.isSelfRecord=e&&a||n}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(ye).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ue.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Ie),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ue.request=Ue.leaveRequest||null,e=j(),n=Ue.initRequestAttributes(),"leave"===e?Ue.request=g.init(n):"sickness"===e?Ue.request=y.init(n):"toil"===e&&(Ue.request=q.init(n))}function ne(){var e={};return Ue.request?e=Ue.request.attributes():Ue.canManage||(e={contact_id:Le.id}),e}function te(){return Be="staff",ae().then(Ue.isSelfRecord&&!Ue.isRole("admin")&&D)}function ae(){return c(_.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(_.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ue.defaultStatus?Ue.newStatusOnSave=Ue.requestStatuses[_.statusNames[Ue.defaultStatus]].value:(Ue.isRole("admin")||Ue.isMode("create")&&Ue.isRole("manager"))&&(Ue.newStatusOnSave=Ue.requestStatuses[_.statusNames.approved].value)}function se(){return!Ue.request.status_id||!t.includes(["cancelled","rejected"],H(Ue.request.status_id).name)}function ie(e){var n=Ue.getStatusFromValue(Ue.request.status_id);return!!n&&n.name===e}function re(e){return Ue.request&&Ue.request.request_type===e}function ce(e){return Ue.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ue.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){ke={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ue.loading.entitlements=!0,v.all({contact_id:Ue.request.contact_id,period_id:Ue.period.id,type_id:{IN:ke.ids}},!0).finally(function(){Ue.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){Le=e})}function he(){return Ue.selectedContactId?f.find(Ue.selectedContactId).then(function(e){Ue.managedContacts=[e]}):Ue.isRole("admin")?f.all().then(function(e){Ue.managedContacts=e.list}):Le.leaveManagees().then(function(e){Ue.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ue.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){P(),d.publish(e,Ue.request),Ue.errors=[],Ue.dismissModal()}function _e(){["from","to"].forEach(function(e){Ue.request[e+"_date"]=$e[e+"_date"]})}function ye(e){if(Ue.absenceTypes=be(ke.types,e),!Ue.absenceTypes.length)return o.reject(Ee)}function qe(){Ue.period=t.find(Ue.absencePeriods,function(e){return Ue.isMode("create")?e.current:ue(Ue.request,e)})}function Ce(){Ue.isMode("create")?(Ue.selectedAbsenceType=Ue.absenceTypes[0],Ue.request.type_id=Ue.selectedAbsenceType.id):Ue.selectedAbsenceType=t.find(Ue.absenceTypes,function(e){return e.id===Ue.request.type_id})}function Te(){$e=e.copy(Ue.request.attributes())}function Ae(){var e;Ue.request.id?(e=[Ue.requestStatuses[_.statusNames.approved].value,Ue.requestStatuses[_.statusNames.adminApproved].value,Ue.requestStatuses[_.statusNames.rejected].value,Ue.requestStatuses[_.statusNames.cancelled].value],Ue.mode="edit",Ue.isRole("staff")&&e.indexOf(Ue.request.status_id)>-1&&(Ue.mode="view")):Ue.mode="create"}function De(){var e=Ue.request.status_id;if(!Ue.isMode("view")&&!Ue.submitting)return Ue.submitting=!0,k(),A(),Ue.request.isValid().then(se()&&L).then(x).then(O()&&_e).then(Pe).then(function(){return Ue.isMode("edit")?Se():$()}).catch(function(n){Ue.request.status_id=e,n&&Y(n)}).finally(function(){Ue.submitting=!1})}function Pe(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Re(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Ie(){xe.forEach(function(e){e()})}function we(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Se(){return Ue.request.update().then(Re).then(function(){Ue.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ue.isRole("staff")||Ue.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var ke,Le,Oe={},Me=0,$e={},xe=[],Ee="No entitlement",Be="",Fe=[],Ue=t.assign(this,m);Ue.absencePeriods=[],Ue.absenceTypes=[],Ue.canManage=!1,Ue.contactName=null,Ue.errors=[],Ue.isSelfLeaveApprover=!1,Ue.loading={absenceTypes:!0,entitlements:!0},Ue.managedContacts=[],Ue.mode="",Ue.newStatusOnSave=null,Ue.period={},Ue.postContactSelection=!1,Ue.requestStatuses={},Ue.selectedAbsenceType={},Ue.staffMemberSelectionComplete=!1,Ue.submitting=!1,Ue.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ue.canChangeAbsenceType=w,Ue.canSubmit=S,Ue.closeAlert=M,Ue.deleteLeaveRequest=E,Ue.dismissModal=B,Ue.getStatuses=W,Ue.getStatusFromValue=H,Ue.initAfterContactSelection=V,Ue.initRequestAttributes=ne,Ue.isLeaveStatus=ie,Ue.isLeaveType=re,Ue.isMode=ce,Ue.isRole=le,Ue.submit=De,Ue.updateAbsenceType=we,function(){Ue.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ue.canManage&&!Ue.isMode("edit")&&he()}).then(function(){if(Ue.selectedContactId&&(Ue.request.contact_id=Ue.selectedContactId),Ue.request.contact_id)return Ue.initAfterContactSelection()}).catch(Y).finally(function(){Ue.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}), define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,n){"use strict";function t(e,n,t,a,o,s,i,r,c){function u(e){return r.get().then(function(n){return e.roleOf(n.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:n.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(n){n?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}n.factory("LeavePopup",t),t.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/absence-tab/modules/components",["common/angular"],function(e){return e.module("absence-tab.components",[])}),function(e){define("leave-absences/absence-tab/components/absence-tab-container.component",["leave-absences/absence-tab/modules/components"],function(n){function t(n,t,a){function o(){a.getDateFormat()}n.debug("Component: absence-tab-container"),t.section="absence-tab";var s=this;s.contactId=e.adminId,s.$onInit=o}n.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:t}),t.$inject=["$log","$rootScope","DateFormat"]})}(CRM),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["common/lodash","leave-absences/absence-tab/modules/components"],function(e,n){function t(e,n,t){function a(){o().finally(function(){s.loading.component=!1})}function o(){return t.all().then(t.loadCalculationUnits).then(function(e){s.absenceTypes=e})}n.debug("Component: absence-tab-entitlements");var s=this;s.absenceTypes=[],s.loading={component:!0},s.$onInit=a}n.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:t}),t.$inject=["$q","$log","AbsenceType"]}),define("leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component",["common/moment","leave-absences/absence-tab/modules/components"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return t.all([l(),d(!0)]).finally(function(){f.loading.content=!1})}function u(e){f.errorMessage=e}function l(){return r.get({is_active:!0}).then(function(e){f.workPatterns=e})}function d(e){return s.valuesOf("hrleaveandabsences_work_pattern_change_reason",e).then(function(e){f.changeReasons=e})}function m(){o.loadForm("/civicrm/admin/options/hrleaveandabsences_work_pattern_change_reason?reset=1").on("crmUnload",function(){d(!1)})}n.debug("Component: absence-tab-custom-work-pattern-modal");var f=Object.create(this);return f.changeReasons=[],f.errorMessage="",f.saveInProgress=!1,f.workPatterns=[],f.loading={content:!0},f.selected={workPattern:null,effectiveDate:null,changeReason:null},f.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},f.$onInit=c,f.openWorkPatternChangeReasonEditor=m,f.closeModal=function(){f.dismiss({$value:"cancel"})},f.closeAlert=function(){f.errorMessage=""},f.save=function(){var n=e(f.selected.effectiveDate).format(i.serverDateFormat);return f.saveInProgress=!0,r.assignWorkPattern(f.contactId,f.selected.workPattern.id,n,null,f.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),f.closeModal()}).catch(u).finally(function(){f.saveInProgress=!1})},f}n.component("absenceTabCustomWorkPatternModal",{bindings:{contactId:"<",dismiss:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-custom-work-pattern-modal.html"}],controllerAs:"workPatternModal",controller:["$log","$q","$rootScope","crmAngService","OptionGroup","shared-settings","WorkPatternAPI",t]})}),define("leave-absences/absence-tab/components/absence-tab-work-patterns.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","leave-absences/absence-tab/components/absence-tab-custom-work-pattern-modal.component"],function(e,n,t){function a(t,a,o,s,i,r,c,u,l,d){function m(){y.linkToWorkPatternListingPage=g(),v([h(),p(),c.getDateFormat()]),s.$on("CustomWorkPattern::Added",function(){v()})}function f(){return d.workPatternsOf(y.contactId,{},!1).then(function(e){y.customWorkPatterns=e})}function p(){return d.default().then(function(e){y.defaultWorkPattern=e})}function h(){return l.valuesOf("hrleaveandabsences_work_pattern_change_reason").then(function(n){_=e.indexBy(n,"value")})}function v(e){var n=[f()];return e&&(n=n.concat(e)),y.loading.workPattern=!0,a.all(n).then(function(){b()}).finally(function(){y.loading.workPattern=!1})}function b(){var t,a=u.DATE_FORMAT.toUpperCase();y.customWorkPatterns=e(y.customWorkPatterns).map(function(e){return t=_[e.change_reason],e.change_reason_label=t?t.label:"",e.effective_date=e.effective_date?n(e.effective_date).format(a):"",e}).sortBy(function(e){return-n(e.effective_date,a).valueOf()}).value()}function g(){var e=CRM.url("civicrm/contact/view",{cid:y.contactId,selectedChild:"absence"});return CRM.url("civicrm/admin/leaveandabsences/work_patterns",{cid:y.contactId,returnUrl:e})}t.debug("Component: absence-tab-work-patterns");var _=[],y=Object.create(this);return y.customWorkPatterns=[],y.defaultWorkPattern=null,y.loading={workPattern:!0},y.$onInit=m,y.deleteWorkPattern=function(e){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){d.unassignWorkPattern(e).then(function(){v()})}})},y.openModal=function(){i.open({appendTo:o.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},y}t.component("absenceTabWorkPatterns",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-work-patterns.html"}],controllerAs:"workpatterns",controller:["$log","$q","$rootElement","$rootScope","$uibModal","dialog","DateFormat","HR_settings","OptionGroup","WorkPattern",a]})}),define("leave-absences/absence-tab/components/annual-entitlement-change-log.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,n,t){function a(t,a,o,s,i){function r(){v().then(b).then(g).then(c).then(u).then(_).then(p).finally(function(){T.loading.component=!1})}function c(){return d().then(function(e){C=C.concat(e)})}function u(){var n=e.groupBy(C,"created_date");T.changeLogRows=e.map(n,m).sort(function(e,n){return n.date.diff(e.date)})}function l(e,n){var t,a,o=f(e);e.entitlements.forEach(function(s,i){t=o.entitlements.slice(0,i),a=e.entitlements.slice(i+1),n(s,t,a)})}function d(){return o.all({contact_id:T.contactId,period_id:T.periodId},!1).then(function(e){return e.map(function(e){return{comment:e.comment,contact_id:e.contact_id,created_date:e.created_date,editor_id:e.editor_id,entitlement_amount:e.value,entitlement_id:e.id,"entitlement_id.type_id":e.type_id}})})}function m(t,a){var o,s,i;return s=e.indexBy(t,"entitlement_id.type_id"),i=T.absenceTypes.map(function(n){return o=s[n.id],e.extend({calculation_unit:n.calculation_unit_name},o)}),{date:n(a),entitlements:i}}function f(e){var n;return n=T.changeLogRows.indexOf(e),T.changeLogRows[n+1]||{date:e.date.clone(),entitlements:e.entitlements.map(function(){return{}})}}function p(){for(var n,t,a,o=T.changeLogRows.length-1;o>=0;o--)if(n=T.changeLogRows[o],t=e.pluck(n.entitlements,"comment"),a=e.compact(t),1===a.length){var s=e.findIndex(t,"length");n.highlightedEntitlement=n.entitlements[s]}else a.length>1&&y(o)}function h(e,n){T.changeLogRows.splice(n,0,e)}function v(){return t.all({id:T.periodId}).then(function(e){T.absencePeriod=e[0]})}function b(e){return a.all().then(a.loadCalculationUnits).then(function(e){T.absenceTypes=e})}function g(){return o.logs({contact_id:T.contactId,period_id:T.periodId}).then(function(e){C=e})}function _(){var e,n;if(!(T.changeLogRows.length<=1))for(e=T.changeLogRows.length-2,n=T.changeLogRows.length-1;e>=0;){var t=T.changeLogRows[e],a=T.changeLogRows[n];t.entitlements.forEach(function(e,n){var t=a.entitlements[n];e.comment===t.comment&&delete e.comment}),e--,n--}}function y(e){var n,t,a=T.changeLogRows[e];l(a,function(o,s,i){o.comment&&(n=s.concat(o).concat(i),t={date:a.date.clone(),entitlements:n},t.highlightedEntitlement=o,h(t,e++))}),q(e)}function q(e){T.changeLogRows.splice(e,1)}var C=[],T=this;T.absencePeriod=null,T.absenceTypes=[],T.changeLogRows=[],T.loading={component:!0},T.$onInit=r}t.component("annualEntitlementChangeLog",{bindings:{contactId:"<",periodId:"<",dismissModal:"&"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlement-change-log.html"}],controllerAs:"changeLog",controller:a}),a.$inject=["AbsencePeriod","AbsenceType","Entitlement","OptionGroup","shared-settings"]}),function(e){define("leave-absences/absence-tab/components/annual-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contact"],function(n,t,a){function o(a,o,s,i,r,c,u,l,d){function m(){g().then(b).then(v).then(f).then(p).then(y).finally(function(){A.loading.absencePeriods=!1})}function f(){A.absencePeriods=n.chain(A.absencePeriods).filter(function(e){return n.find(C,function(n){return n.period_id===e.id})}).sortBy(function(e){return-t(e.start_date).valueOf()}).value()}function p(){A.absenceTypes=n.filter(A.absenceTypes,function(e){return n.find(C,function(n){return n.type_id===e.id})})}function h(n){var t=e.url("civicrm/contact/view",{cid:A.contactId,selectedChild:"absence"});return e.url("civicrm/admin/leaveandabsences/periods/manage_entitlements",{id:n,cid:A.contactId,returnUrl:t})}function v(){return c.all().then(function(e){A.absencePeriods=e})}function b(){var e=n.uniq(n.map(C,function(e){return e.editor_id}));return l.all({id:{IN:e}}).then(function(e){T=n.indexBy(e.list,"contact_id")})}function g(){return u.all({contact_id:A.contactId}).then(function(e){C=e})}function _(e){i.open({appendTo:s.children().eq(0),templateUrl:"annual-entitlement-change-log-modal",controller:["$uibModalInstance",function(n){this.contactId=A.contactId,this.dismiss=n.dismiss,this.periodId=e}],controllerAs:"modal"})}function y(){A.absencePeriods=n.map(A.absencePeriods,function(e){var t=n.map(A.absenceTypes,function(t){var a=n.find(C,function(n){return n.type_id===t.id&&n.period_id===e.id});return a?{amount:a.value,calculation_unit:t.calculation_unit_name,comment:a.comment?{message:a.comment,author_name:T[a.editor_id].display_name,date:a.created_date}:null}:null});return{id:e.id,title:e.title,entitlements:t}})}function q(e){var n=e.message+"

Last updated:
By: "+e.author_name+"
Date: "+t.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
";d.info("Calculation comment:",n)}a.debug("Component: annual-entitlements");var C=[],T=[],A=this;A.absencePeriods=[],A.loading={absencePeriods:!0},A.$onInit=m,A.getEditEntitlementsPageURL=h,A.openAnnualEntitlementChangeLog=_,A.showComment=q}a.component("annualEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:o}),o.$inject=["$log","$q","$rootElement","$uibModal","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService"]})}(CRM),define("leave-absences/absence-tab/components/contract-entitlements.component",["common/lodash","common/moment","leave-absences/absence-tab/modules/components","common/models/contract"],function(e,n,t){function a(t,a,o,s,i,r){function c(){r.getDateFormat().then(d).then(u).then(m).finally(function(){f.loading.contracts=!1})}function u(){f.absenceTypes=e.filter(f.absenceTypes,function(n){return e.find(f.contracts,function(t){return e.find(t.info.leave,function(e){return e.leave_type===n.id})})})}function l(e){var t=o.DATE_FORMAT.toUpperCase();return e?n(e).format(t):""}function d(){return i.all({contact_id:f.contactId}).then(function(e){f.contracts=e})}function m(){f.contracts=e.sortBy(f.contracts,function(e){return n(e.info.details.period_start_date)}).map(function(n){var t=n.info,a=t.details,o=e.map(f.absenceTypes,function(n){var a=e.filter(t.leave,function(e){return e.leave_type===n.id})[0];return{amount:a?a.leave_amount:"",calculation_unit:n.calculation_unit_name}});return{position:a.position,start_date:l(a.period_start_date),end_date:l(a.period_end_date),absences:o}})}t.debug("Component: contract-entitlements");var f=this;f.contracts=[],f.loading={contracts:!0},f.$onInit=c}t.component("contractEntitlements",{bindings:{absenceTypes:"<",contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:a}),a.$inject=["$log","$q","HR_settings","AbsenceType","Contract","DateFormat"]}),function(e){define("leave-absences/absence-tab/modules/settings",["common/angular"],function(n){return n.module("absence-tab.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.contactId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/absence-tab/"})})}(CRM),define("leave-absences/absence-tab/modules/config",["common/angular","leave-absences/absence-tab/modules/settings"],function(e){return e.module("absence-tab.config",["absence-tab.settings"]).config(["$resourceProvider","$httpProvider","$logProvider","settings",function(e,n,t,a){t.debugEnabled(a.debug),e.defaults.stripTrailingSlashes=!1,n.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}])}),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/modules/directives","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/work-pattern.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/absence-tab/components/absence-tab-container.component","leave-absences/absence-tab/components/absence-tab-entitlements.component","leave-absences/absence-tab/components/absence-tab-work-patterns.component","leave-absences/absence-tab/components/annual-entitlement-change-log.component","leave-absences/absence-tab/components/annual-entitlements.component","leave-absences/absence-tab/components/contract-entitlements.component","leave-absences/absence-tab/modules/config"],function(e){return e.module("absence-tab",["ngResource","ui.bootstrap","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.services","common.mocks","leave-absences.settings","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","absence-tab.config","absence-tab.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,n,t,a){e.debug("app.run"),n.sharedPathTpl=t.sharedPathTpl,n.settings=a}]),e}),function(e,n){var t=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";n.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":t+"/shared","leave-absences/absence-tab":t+"/absence-tab"}}),n(["leave-absences/shared/config"],function(){n(["leave-absences/absence-tab/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("absenceTabReady"):function(){var e=document.createEvent("Event");return e.initEvent("absenceTabReady",!0,!0),e}())})})}(CRM,require),define("absence-tab",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/absence-tab.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/admin-dashboard.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/admin-dashboard.min.js index c478dc1ef8a..f607a46ba58 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/admin-dashboard.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/admin-dashboard.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){e.config({paths:{mocks:"../test/mocks"}}),e.config({paths:{mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(n){return n.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",sourcePath:e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,n,t){function a(t){function a(e){e.absencePeriods&&u.absencePeriods.length&&(u.filters.period_id=s().id),e.absenceTypes&&u.absenceTypes.length&&(u.filters.type_id=i().id),(e.loggedInContactId||e.userRole)&&(u.filters.managed_by="manager"===u.userRole?u.loggedInContactId:void 0),o()&&u.submitFilters()}function o(){return e.every(u.filters,function(e){return null!==e})}function s(){return e.find(u.absencePeriods,function(e){return e.current})||u.absencePeriods.reduce(function(e,t){return n(e.end_date).isAfter(t.end_date)?e:t})}function i(){return u.absenceTypes.reduce(function(e,n){return e.title.localeCompare(n.title)?e:n})}function r(e){return e.current?"Current Period ("+e.title+")":e.title}function c(){t.$emit("LeaveBalanceFilters::update",u.filters)}var u=this;u.filters={period_id:null,type_id:null,managed_by:null},u.$onChanges=a,u.labelPeriod=r,u.submitFilters=c}t.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,t){function a(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(t.remainder=a[0].remainder),delete t["api.LeavePeriodEntitlement.getremainder"],t}function o(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return t.value=a,delete t["api.LeavePeriodEntitlement.getentitlement"],t}return e.debug("EntitlementAPI"),t.extend({all:function(n,t){return e.debug("EntitlementAPI.all"),n["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},t&&(n["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",n,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),t&&(e=e.map(a)),e})},breakdown:function(n){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",n).then(function(e){return e.values})},getLeaveBalances:function(n,t,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",n,t,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,n){return e.extend({all:function(e,t,a,o,s){return n.getLeaveBalances(this.processFilters(e),t,a,o,s)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,n,t){function a(t,a,o,s,i,r,c,u,l,d,m){function f(){q(),b().then(function(){P.loading.component=!1})}function p(){return o.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function h(){return s.all().then(s.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function v(){return i.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function b(){return t.all([p(),h(),v(),g(),C()]).catch(function(e){c.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function y(){return P.loading.report=!0,r.all(R,P.pagination,void 0,void 0,!1).then(function(e){P.report=_(e.list),P.reportCount=e.total}).catch(function(e){c.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function _(t){return t.map(function(t){return t=e.copy(t),t.absence_types=n.indexBy(t.absence_types,function(e){return e.id}),t})}function q(){a.$on("LeaveBalanceFilters::update",A),u.subscribe("LeaveRequest::new",T)}function C(){return m(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function T(e){A(e,R)}function A(e,n){R=n,P.pagination.page=1,D(),P.loadReportCurrentPage()}function D(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+R.type_id})}var R={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.$onInit=f,P.loadReportCurrentPage=y}t.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,n,t){function a(n,t,a,o,s,i,r){function c(){return{loadContacts:function(){return l.loadContactsForAdmin()}}}function u(e){i.info("",["

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 l,d;return{init:function(n){return d=n,l=r.init(d),d.filters.userSettings.assignedTo=e.find(d.filtersByAssignee,{type:"me"}),d.showContactDetailsLink=!0,d.showContactName=!0,d.showFilters=!0,d.showAdminFilteringHint=u,c()}}}t.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService","LeaveCalendarService",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(n,t,a,o){function s(){return{loadContacts:function(){return i.loadLookUpAndFilteredContacts()}}}n.debug("LeaveCalendarManagerController");var i,r;return{init:function(n){return r=n,i=o.init(r),r.filters.userSettings.assignedTo=e.find(r.filtersByAssignee,{type:"me"}),r.showContactName=!0,r.showFilters=!0,s()}}}t.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance","LeaveCalendarService",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,t,a){function o(){return{loadContacts:function(){return i.displaySingleContact?s.loadFilteredContacts():"admin"===i.userPermissionRole?s.loadContactsForAdmin():s.loadLookUpAndFilteredContacts()}}}e.debug("LeaveCalendarStaffController");var s,i;return{init:function(e){return i=e,s=a.init(i),i.filters.userSettings.contacts_with_leaves=!0,i.showTheseContacts=[i.contactId],i.showContactName=!0,i.showFilters=!0,i.displaySingleContact&&(i.showFilters=!1,i.lookupContacts=[{id:i.contactId}]),o()}}}t.controller("LeaveCalendarStaffController",["$log","$q","Contact","LeaveCalendarService",a])}),define("leave-absences/shared/components/leave-calendar.component",["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){function a(t,a,o,s,i,r,c,u,l,d){function m(){U().then(g).then(b).then(_).then(I).then(function(){return a.all([C(),D(),S(),W.showFilters?R():e.noop])}).then(function(){f(),y(),B()}).then(function(){W.loading.page=!1})}function f(){W.supportData.absenceTypes.push({id:"",title:"Leave",color:"#4D4D68",calculation_unit:e.chain(W.supportData.calculationUnits).find({name:"days"}).get("value").value()})}function p(){for(var e=[],t=n(W.selectedPeriod.start_date).clone().startOf("month"),a=n(W.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(L(t)),t.add(1,"month");W.months=e}function h(){return e.includes(["admin","manager"],W.userPermissionRole)}function v(e){return e.format("YYYY-MM")}function b(){s.$on("LeaveCalendar::updateFiltersByAbsenceType",function(e,n){W.supportData.absenceTypesToFilterBy=n,M(!0)})}function g(){s.$new().$watch(function(){return W.selectedMonthIndex},function(e,n){null!==n&&e!==n&&(F(),B(),M())})}function y(e){W.injectMonth=!0,N("injected").then(function(){M(e)}).then(function(){W.loading.calendar=!1})}function _(){j=t("LeaveCalendar"+e.capitalize(H)+"Controller").init(W)}function q(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return r.all().then(function(n){W.absencePeriods=e.sortBy(n,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current})}).then(p).then($)}function T(){return c.all().then(c.loadCalculationUnits)}function A(){return l.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function D(){return j.loadContacts().then(function(e){W.contacts=e})}function R(){return l.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){W.filters.optionValues.regions=e.hrjc_region,W.filters.optionValues.locations=e.hrjc_location,W.filters.optionValues.levelTypes=e.hrjc_level_type,W.filters.optionValues.departments=e.hrjc_department})}function P(){return u.all()}function S(){return a.all([T(),P(),A()]).then(function(n){W.supportData.absenceTypes=n[0],W.supportData.publicHolidays=n[1],W.supportData.calculationUnits=n[2].hrleaveandabsences_absence_type_calculation_unit,W.supportData.dayTypes=n[2].hrleaveandabsences_leave_request_day_type,W.supportData.leaveRequestStatuses=n[2].hrleaveandabsences_leave_request_status,W.supportData.toilAmounts=e.indexBy(n[2].hrleaveandabsences_toil_amounts,"value")})}function I(){var e=a.resolve();return W.injectMonth&&(e=N("destroyed"),W.injectMonth=!1),e}function L(e){return{index:v(e),month:e.month(),year:e.year(),name:e.format("MMMM"),moment:n().year(e.year()).month(e.month())}}function w(){var n=W.selectedPeriod.id;W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current}),n!==W.selectedPeriod.id&&p(),$(),B(),O("month")}function k(e){var t="previous"===e?"subtract":"add";F(n(W.selectedMonth.moment)[t](1,"month")),B(),O("month")}function O(n){n=e.includes(["contacts","period","month"],n)?n:"period",a.resolve().then(I).then("period"===n&&p).then("period"===n&&x).then("contacts"===n&&D).then("month"===n&&B).then(function(){y("contacts"===n)})}function M(e){s.$emit("LeaveCalendar::showMonth",!!e)}function $(){F(n())}function x(){F(W.months[0].moment)}function E(t){var a="previous"===t?"first":"last",o=e[a](W.months),s=n().year(o.year).month(o.month);W.monthPaginatorsAvailability[t]=!W.selectedMonth.moment.isSame(s,"month")}function B(){E("previous"),E("next")}function F(n){n&&(W.selectedMonthIndex=v(n)),W.selectedMonth=e.find(W.months,{index:W.selectedMonthIndex})}function U(){return a.all([d(i.permissions.admin.administer),d(i.permissions.ssp.manage)]).then(function(e){W.userPermissionRole=e[0]?"admin":e[1]?"manager":"staff",H=W.roleOverride?W.roleOverride:W.userPermissionRole})}function N(n){return a(function(t){var a=s.$on("LeaveCalendar::month"+e.capitalize(n),function(){a(),t()})})}o.debug("Component: leave-calendar");var j,H,W=this;W.absencePeriods=[],W.contacts=[],W.contactIdsToReduceTo=null,W.injectMonth=!1,W.months=[],W.selectedMonth={},W.selectedMonthIndex="",W.selectedPeriod=null,W.showContactName=!1,W.showFilters=!1,W.userPermissionRole="staff",W.loading={calendar:!0,page:!0},W.filters={hideOnMobile:!0,optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null},absenceTypes:{}},W.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],W.filters.userSettings.assignedTo=W.filtersByAssignee[2],W.monthPaginatorsAvailability={previous:!0,next:!0},W.supportData={absenceTypesToFilterBy:[]},W.$onInit=m,W.canManageRequests=h,W.labelPeriod=q,W.navigateToCurrentMonth=w,W.paginateMonth=k,W.refresh=O}t.component("leaveCalendar",{bindings:{contactId:"<",displaySingleContact:"0,t={from_date:{to:Q.month.days[Q.month.days.length-1].date+" 23:59:59"},to_date:{from:Q.month.days[0].date+" 00:00:00"},status_id:{IN:k()},contact_id:{IN:Q.contacts.map(function(e){return e.id})},type_id:{IN:n?Q.supportData.absenceTypesToFilterBy:e.pluck(Q.supportData.absenceTypes,"id")}};return y(),i.all(t,null,null,null,!1).then(function(e){return X={},n&&(e.list=q(e.list)),A(e.list)})}function $(){var n=Q.month.days[0].date,t=Q.month.days[Q.month.days.length-1].date;return s.get(Q.contacts.map(function(e){return e.id}),n,t).then(function(n){z=e.indexBy(n,"contact_id")})}function x(){return Q.contactIdsToReduceTo&&(Q.contacts=Q.contacts.filter(function(n){return e.includes(Q.contactIdsToReduceTo,n.contact_id)||e.find(X,function(e){return e.contact_id===n.contact_id})})),a.resolve()}function E(n){var t=L(n);X[n.contact_id]=X[n.contact_id]||{},t.forEach(function(t){e.remove(X[n.contact_id][t.date],function(e){return e.id===n.id})})}function B(){o.$emit("LeaveCalendar::monthDestroyed"),V.map(function(e){e.remove?e.remove():e()})}function F(n,t,o){var s,i;return n.contactsData[t]=n.contactsData[t]||{},i=f(t),s=!0===o?a.resolve():a.all([i.isWeekend(h(n.date)),i.isNonWorkingDay(h(n.date))]).then(function(a){e.assign(n.contactsData[t],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:S(n.date)})}),s.then(function(){return X[t]&&X[t][n.date]?X[t][n.date]:[]}).then(function(a){a=j(a),e.assign(n.contactsData[t],{leaveRequests:a,leaveRequestsToShowInCell:b(a),leaveRequestsAttributes:C(n,a)})})}function U(){return a.all(Q.month.days.map(function(e){return a.all(Q.contacts.map(function(n){return F(e,n.id)}))}))}function N(e,n){Q.currentPage=0,Q.visible=!0,(n||!G)&&O()}function j(t){return e.sortBy(t,function(e){return+n(e.from_date).format("X")+(R("half_day_pm",e,e.from_date)?1:0)})}function H(n){var t=e.find(Q.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 W(e){v(e),-1!==k().indexOf(e.status_id)&&l(e)}function Y(e){return a.all(L(e).map(function(n){return F(n,e.contact_id,!0)}))}t.debug("Component: leave-calendar-month");var G=!1,V=[],z={},X={},Q=this;Q.currentPage=0,Q.pageSize=20,Q.visible=!1,Q.showContactName=!!Q.showContactName,Q.showOnlyWithLeaveRequests=!!Q.showOnlyWithLeaveRequests,Q.$onDestroy=B,Q.$onInit=u,Q.contactsList=p,Q.getContactUrl=_}t.component("leaveCalendarMonth",{bindings:{showTheseContacts:"<",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/models/contact","common/models/session.model","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,l,d,m){function f(){a.resolve().then(_).then(C).then(function(){return y()&&"admin"!==w.role&&P()}).then(R).finally(function(){w.loading.component=!1})}function p(n){L=w.leaveRequest.status_id,e.includes(["cancel","reject","delete"],n)||"toil"===w.leaveRequest.request_type?i.open(q(n)):b(n)}function h(){return"admin"===w.role&&"public_holiday"===w.leaveRequest.request_type}function v(t){var a=w.absenceTypes[w.leaveRequest.type_id].allow_request_cancelation;return"admin"===w.role||("manager"===w.role?e.includes([k.awaitingApproval,k.moreInformationRequired],t):"3"===a?n().isBefore(w.leaveRequest.from_date):"2"===a)}function b(n){i.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return w.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(t){return t?e.assign(c.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){A(n)}}):q(n)})}})}function g(){return s.find(I).then(function(e){return e.checkIfSelfLeaveApprover()})}function y(){return I===w.leaveRequest.contact_id}function _(){e.isArray(w.leaveRequestStatuses)&&(w.leaveRequestStatuses=e.indexBy(w.leaveRequestStatuses,"value")),e.isArray(w.absenceTypes)&&(w.absenceTypes=e.indexBy(w.absenceTypes,"id"))}function q(e){var n=O[e].dialog;return{title:"Confirm "+n.title+"?",copyCancel:"Cancel",copyConfirm:n.btnLabel,classConfirm:"btn-"+n.btnClass,msg:n.msg,onConfirm:function(){return w.leaveRequest[e]().then(function(){D(e)}).catch(function(e){d.error("Error:",e)})}}}function C(){return m.get().then(function(e){I=e.contactId})}function T(e,n){e.stopPropagation(),r.openModal(n)}function A(e){r.openModal({leaveRequest:w.leaveRequest,leaveType:w.leaveRequest.request_type,selectedContactId:w.leaveRequest.contact_id,forceRecalculateBalanceChange:!0,defaultStatus:l.statusNames[M[e]]})}function D(n){var t=e.find(w.leaveRequestStatuses,function(e){return e.name===l.statusNames.awaitingApproval}).value;L===t&&u.publish("ManagerBadge:: Update Count"),u.publish("LeaveRequest::statusUpdate",{status:n,leaveRequest:w.leaveRequest})}function R(){var n=w.leaveRequestStatuses[w.leaveRequest.status_id].name,t=e.compact(e.map(O,function(t,a){return e.includes(t.allowedStatuses,n)?a:null}));!v(n)&&e.pull(t,"cancel"),"admin"!==w.role&&e.pull(t,"delete"),"staff"===w.role&&e.pull(t,"approve","reject"),"staff"!==w.role&&S(t),h()&&t.push("delete"),w.allowedActions=e.map(t,function(e){return{key:e,label:O[e].label,isDirectAction:O[e].isDirectAction}})}function P(){return g().then(function(e){e&&(w.role="admin")})}function S(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 I,L,w=this,k=l.statusNames,O={edit:{label:"Edit",allowedStatuses:[k.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[k.moreInformationRequired]},view:{label:"View",allowedStatuses:[k.approved,k.rejected,k.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[k.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[k.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[k.awaitingApproval,k.approved,k.rejected,k.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[k.awaitingApproval,k.moreInformationRequired,k.approved,k.rejected,k.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}},M={approve:"approved"};w.allowedActions=[],w.loading={component:!0},w.$onInit=f,w.action=p,w.openLeavePopup=T}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","$q","$rootScope","Contact","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService","Session"]}),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(){o.$emit("LeaveRequestPopup::addTab",C),y(),_()}function l(){C.request.comments.push({contact_id:q,leave_request_id:C.request.id,text:C.comment.text}),C.comment.text=""}function d(){return C.comment.text.length>0}function m(e){return!e.comment_id||C.canManage}function f(e){return n.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function p(){return C.request.comments.filter(function(e){return!e.toBeDeleted})}function h(e){return e===q?"Me":C.comment.contacts[e]?C.comment.contacts[e].display_name:void 0}function v(e){return C.mode===e}function b(){C.comment.text.length&&C.addComment()}function g(){var n=e.indexBy(C.request.comments,"contact_id"),t=Object.keys(n);return r.all({id:{IN:t}},{page:1,size:0}).then(function(n){C.comment.contacts=e.indexBy(n.list,"contact_id")})}function y(){return C.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),C.request.comments.length&&g()})}function _(){return C.loading.component=!0,c.get().then(function(e){q=e.contactId}).then(function(){C.loading.component=!1})}t.debug("Component: leave-request-popup-comments-tab");var q=null,C=this;C.loading={component:!0},C.comment={text:"",contacts:{}},C.$onInit=u,C.addComment=l,C.canRemoveComment=m,C.canSubmit=d,C.formatDateTime=f,C.getActiveComments=p,C.getCommentorName=h,C.isMode=v,C.onBeforeSubmit=b}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/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,n){"use strict";n.factory("WorkPatternAPI",["$log","api",function(n,t){function a(n){var t=e.clone(n);return t.workPattern=t["api.WorkPattern.get"].values[0],delete t["api.WorkPattern.get"],t}return n.debug("WorkPatternAPI"),t.extend({assignWorkPattern:function(n,t,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:n,pattern_id:t,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(t,a,o,s){return n.debug("WorkPatternAPI.getCalendar",t,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(t)?{IN:t}:t,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(n,t,o){return this.sendGET("ContactWorkPattern","get",e.assign({},t,{contact_id:n,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).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,n,t){"use strict";t.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(t,a,o,s,i){function r(n,t){return u().then(function(a){var o=this.days[c(n).valueOf()];return!!o&&e.find(a,function(e){return e.name===t}).value===o.type}.bind(this))}function c(e){return n(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(n){var t={};return n.calendar.forEach(function(e){t[c(e.date).valueOf()]=e}),e(n).omit("calendar").assign({days:t}).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,n){"use strict";n.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(n,t,a,o){return n.debug("Calendar"),t.extend({get:function(t,s,i,r){return n.debug("Calendar.get"),a.getCalendar(t,s,i,r).then(function(n){var a=n.values.map(function(e){return o.init(e)});return e.isArray(t)?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,n,t){function a(t,a,o,s,i,r,c,u,l,d,m){function f(){t("RequestModalDetails"+e.capitalize(T(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),I(),te.initChildController().then(function(){return i.all([x(),$()])}).then(!te.isMode("create")&&S).then(Y).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(z)}).then(!te.isMode("create")&&W).then(L).then(G).then(P).then(w).then(!te.isMode("view")&&te.initWatchersExtended).catch(R).then(function(){te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.totalItems=te.balance.change.breakdown.length}).finally(function(){te.loading.tab=!1})}function p(){te.balance.closing=te.balance.opening+te.balance.change.amount}function h(e){return n(e,c.serverDateFormat).toDate()}function v(e){return n(e).format(c.serverDateFormat)}function b(e){var n;return i.resolve().then(function(){j(e),"from"===e&&N(),k("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return C(e)}).then(function(e){if(n=e.id!==te.period.id,n&&(te.period=e),!te.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 te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(z(),!n)return B();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(R).finally(q)}function g(){return z(),B()}function y(){return te.uiOptions.toDate=null,j("to"),i.resolve().then(z).then(te.setDaysSelectionModeExtended).then(q).then(!te.uiOptions.multipleDays&&B)}function _(e){te.uiOptions.times[e].loading=!0}function q(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,k("hours")&&(te.uiOptions.times[e].loading=!1)})}function C(t){var a=n(te.uiOptions[t+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function T(){return te.request?te.request.request_type:te.leaveType||null}function A(e){return n().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return X(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(H).catch(R)}function R(n){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(n)?n:[n]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?B():D()}function S(){var e=te.request.attributes();return te.uiOptions.fromDate=h(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=h(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function I(){ne.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,n){K(n)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",B))}function L(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(ee={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function w(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,n){e!==n&&(te.uiOptions.multipleDays||(Z(e),z()))})}function k(e){return te.selectedAbsenceType.calculation_unit_name===e}function O(e){return te.request.request_type===e}function M(n){return e.includes(["weekend","non_working_day","public_holiday"],n)}function $(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function x(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,n=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,n)}function B(){return X(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(H).catch(R).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function F(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function U(){return v(te.request.from_date)===v(te.request.to_date)}function N(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&n(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,j("to"))}function j(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),z(),X()}function H(e){te.balance.change=e,te.request.balance_change=e.amount,p(),F(),te.loading.balanceChange=!1}function W(){var e,t,a;te.uiOptions.fromDate?(e=n(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,t=e):(a=h(te.period.start_date),t=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=t,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=h(te.period.end_date)}function Y(){return!te.isMode("create")&&U()||te.isMode("create")&&(O("sickness")||k("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){ee&&ee.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=ee.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function V(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function z(){var e=te.uiOptions,n=e.times;te.request.from_date=e.fromDate?v(e.fromDate):null,te.request.to_date=e.toDate?v(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),(k("hours")||O("toil"))&&(te.request.from_date=te.request.from_date&&n.from.time?te.request.from_date+" "+n.from.time:null,te.request.to_date=te.request.to_date&&n.to.time?te.request.to_date+" "+n.to.time:null)}function X(){te.uiOptions.showBalance=te.canCalculateChange()}function Q(){e.forEach(ne,function(e){e()})}function J(){var e,n=te.selectedAbsenceType.calculation_unit_name;return V(),e=n!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&Y).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&z).then(q).then(B)}function K(e){return te.absenceTypes=e,V(),n(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,j("to")),G(),B()}function Z(e){var n=A(e).add(te.uiOptions.time_interval,"minutes");n.isAfter(A(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=n.format("HH:mm"),n.isAfter(A(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var ee=null,ne=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:[],numPerPage:7,totalItems:0,pageChanged:E},te.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},te.$onInit=f,te.convertDateFormatFromServer=h,te.convertDateToServerFormat=v,te.dateChangeHandler=b,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=y,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=A,te.handleError=R,te.isCalculationUnit=k,te.isLeaveType=O,te.isNotWorkingDay=M,te.performBalanceChangeCalculation=B,te.setRequestDateTimesAndDateTypes=z,te.updateEndTimeInputMinTime=Z,te.$onDestroy=Q}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(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",w),y(),a.all([A(),C()]).then(_).finally(function(){w.filesLoaded=!0})}function m(){return w.fileUploader&&w.fileUploader.queue.length>0}function f(){return w.getFilesAmount()0?S.map(function(e){return e.label}).join(", "):""}function C(){return w.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function T(){return a.all(S.map(function(e){return l.getMimeTypeFor(e.label).then(function(n){L[e.label]=n})})).catch(function(){L=null})}function A(){return c.valuesOf("safe_file_extension").then(function(e){S=e})}function D(e){return!e.attachment_id||w.canManage}function R(){e.forEach(I,function(e){e()})}function P(e,n){w.fileUploader.queue&&w.fileUploader.queue.length>0?w.fileUploader.uploadAll({entityID:w.request.id}).then(function(){n()}).catch(n):n()}t.debug("Component: leave-request-popup-files-tab");var S=[],I=[],L={},w=Object.create(this);return w.filesLoaded=!1,w.fileUploader=null,w.today=Date.now(),w.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",w.userDateFormat=i.DATE_FORMAT,w.$onDestroy=R,w.$onInit=d,w.canRemoveAttachment=D,w.canSubmit=m,w.canUploadMore=f,w.formatDateTime=p,w.getAuthorName=h,w.getFilesAmount=v,w.listFileTypes=q,w}t.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function n(e,n,t){function a(){s=t.parse(),s.openModal&&o({leaveType:s.openModal,selectedContactId:i.selectedContactId})}function o(e){n.openModal(e)}e.debug("Component: leave-request-record-actions");var s,i=this;i.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],i.$onInit=a,i.openLeavePopup=o}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",n]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,n){function t(n,t,a,o,s,i,r,c,u,l,d,m){"use strict";function f(){s(r.permissions.admin.administer).then(function(e){H.isAdmin=e,t.all([A(),D(),k(),P(),L(),I(),O()]).then(function(){H.loading.page=!1,R()}),N()})}function p(){H.filters.leaveRequest.contact_id=null,H.refresh()}function h(){var e=H.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function v(e){return"all"===e.name||""===e?H.leaveRequests.filter.list.length:H.leaveRequests.filter.list.filter(function(n){return n.status_id===e.value}).length}function b(n){return e.find(H.absenceTypes,{id:n})}function g(e){return new Array(e||0)}function y(n){var t=e.find(H.leaveRequestStatuses,function(e){return e.value===n});return t?t.label:null}function _(e){switch(e){case r.statusNames.approved:return"badge-success";case r.statusNames.rejected:return"badge-danger";case r.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function q(n){return e.find(H.leaveRequestStatuses,function(e){return e.name===n}).value}function C(n){var t=e.find(H.filteredUsers,function(e){return e.id===n});return t?t.display_name:null}function T(e){return e.current?"Current Period ("+e.title+")":e.title}function A(){return c.all().then(function(n){H.absencePeriods=e.sortBy(n,"start_date"),H.filters.leaveRequest.selectedPeriod=e.find(H.absencePeriods,function(e){return!!e.current})})}function D(){return u.all().then(u.loadCalculationUnits).then(function(e){H.absenceTypes=e})}function R(e){return(H.isAdmin?o.all(h()):o.leaveManagees(H.contactId,h())).then(function(n){return H.filteredUsers=H.isAdmin?n.list:n,e?S(e):t.all([S("table"),S("filter")])}).then(function(){H.filters.leaveRequest.leaveStatus!==W&&0===H.leaveRequests.table.list.length&&H.refresh(1,!0)})}function P(){return i.valuesOf("hrjc_department").then(function(e){H.departments=e})}function S(e){var n="filter"!==e,t="table"===e?e:"content",a="filter"===e?{size:0}:H.pagination,o="filter"===e?{return:["status_id"]}:{};return H.loading[t]=!0,l.all(w(n),a,"from_date DESC",o,!1).then(function(n){H.leaveRequests[e]=n}).catch(function(){H.leaveRequests[e].list=[]}).finally(function(){H.loading[t]=!1})}function I(){return i.valuesOf("hrjc_level_type").then(function(e){H.levelTypes=e})}function L(){return i.valuesOf("hrjc_location").then(function(e){H.locations=e})}function w(n){var t=H.filters.leaveRequest;return{contact_id:$(),managed_by:H.isAdmin&&"me"!==t.assignedTo.type?void 0:H.contactId,status_id:E(n),type_id:t.selectedAbsenceTypes?t.selectedAbsenceTypes.id:{IN:e.pluck(H.absenceTypes,"id")},from_date:{from:t.selectedPeriod.start_date},to_date:{to:t.selectedPeriod.end_date},unassigned:"unassigned"===t.assignedTo.type||void 0}}function k(){return i.valuesOf("hrjc_region").then(function(e){H.regions=e})}function O(){return i.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){H.leaveRequestStatuses=e.concat(H.leaveRequestStatuses)})}function M(e){d.openModal(e)}function $(){return H.filteredUsers.length>0&&H.filters.leaveRequest.contact_id?H.filters.leaveRequest.contact_id:{IN:H.filteredUsers.map(function(e){return e.id})}}function x(e){var n=[q(r.statusNames.moreInformationRequired),q(r.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(n)),e}function E(e){var n=H.filters.leaveRequest,t=[];if(e&&n.leaveStatus&&n.leaveStatus.value&&t.push(n.leaveStatus.value),n.pending_requests&&(t=x(t)),t.length)return{IN:t}}function B(e,n,t){e="number"==typeof e?e:1,n&&(H.filters.leaveRequest.leaveStatus=W),(e<=H.totalNoOfPages()||0===H.totalNoOfPages())&&(H.pagination.page=e,R(t))}function F(e){H.filters.leaveRequest.leaveStatus=e,H.refresh(1,!1,"table")}function U(e){H.filters.leaveRequest.assignedTo=e,H.refresh()}function N(){m.subscribe("LeaveRequest::updatedByManager",function(){H.refresh()}),m.subscribe("LeaveRequest::new",function(){H.refresh()}),m.subscribe("LeaveRequest::edit",function(){H.refresh()}),m.subscribe("LeaveRequest::delete",function(){H.refresh()}),m.subscribe("LeaveRequest::statusUpdate",function(){H.refresh()})}function j(){return Math.ceil(H.leaveRequests.table.total/H.pagination.size)}n.debug("Component: manage-leave-requests");var H=this,W={name:"all",label:"All"};H.absencePeriods=[],H.absenceTypes=[],H.filteredUsers=[],H.isFilterExpanded=!1,H.isAdmin=!1,H.leaveRequests={table:{list:[]},filter:{list:[]}},H.leaveRequestStatuses=[W],H.loading={content:!0,page:!0,table:!0},H.pagination={page:1,size:7},H.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],H.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:H.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:H.filtersByAssignee[0]}},H.$onInit=f,H.clearStaffSelection=p,H.countLeaveRequestByStatus=v,H.getAbsenceTypeByID=b,H.getArrayOfSize=g,H.getLeaveStatusByValue=y,H.getNavBadge=_,H.getUserNameByID=C,H.labelPeriod=T,H.openLeavePopup=M,H.refresh=B,H.refreshWithFilter=F,H.refreshWithFilterByAssignee=U,H.totalNoOfPages=j}n.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:t}),t.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,n=!!e.from_date&&!!e.to_date,t=i.selectedAbsenceType.calculation_unit_name;return"days"===t?n=n&&!!e.from_date_type&&!!e.to_date_type:"hours"===t&&(n=n&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),n}function d(){return i.canCalculateChange()}function m(n,t){var a=i.uiOptions.times[n],o=e.clone(t.time_from),s=e.clone(t.time_to);i.uiOptions.multipleDays||("from"===n&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===n&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===n?a.max:a.min}function f(n,t){return n?(n=i.convertDateToServerFormat(n),v(n).then(function(t){return t?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(n,i.requestDayTypes).then(function(n){return n.length?n:i.requestDayTypes.filter(function(n){return e.includes(["all_day","half_day_am","half_day_pm"],n.name)})})}).then(function(e){return S(t,e),e})):o.reject([])}function p(e,t){return e=n(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(n){return n.name===e}):[]})}function h(e,t){return n.duration(t).subtract(n.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function y(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,n){i.isCalculationUnit("days")||+e==+n||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function _(e){var t=n(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,t)<=0||h(a.max,t)>=0)&&(t="from"===e?a.min:a.max),i.uiOptions.times[e].time=t}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],n=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(R)).then(function(){["from","to"].forEach(function(e){_(e),L(e),n[e].amount=Math.min(i.request[e+"_date_amount"],n[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function C(){["from","to"].forEach(function(e){y(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(n,t){i.isCalculationUnit("days")||n===t||(i.setRequestDateTimesAndDateTypes(),n&&L(e,!0))})}function A(e,n){return f(e,n).then(function(){i.loading[n+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return R(e).then(function(){L(e,!0)})})}function R(e){var n=i.uiOptions[e+"Date"],t=!i.uiOptions.multipleDays;return n?i.request.getWorkDayForDate(i.convertDateToServerFormat(n)).then(function(n){O[e]=n,m(e,n),t&&"from"===e&&m("to",n)}).catch(function(n){return O[e]={},i.handleError(n)}).finally(function(){i.uiOptions.times[e].loading=!1,t&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(n){var t=i.uiOptions.times[n];i["request"+e.startCase(n)+"DayTypes"]=[],t.time="",t.min="00:00",t.max="00:00",t.amount="0",t.maxAmount="0"}function S(n,t){var a="request"+e.startCase(n)+"DayTypes";i[a]=t,i.isMode("create")&&(i.request[n+"_date_type"]=i[a][0].value)}function I(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),R("from").then(function(){L("from",!0)})):o.resolve()}function L(e,n){var t=i.uiOptions,a=t.multipleDays?e:"from",o=t.times[a],s=t.multipleDays&&"to"===a?o.min:t.times.from.time,r=t.multipleDays&&"from"===a?o.max:t.times.to.time,c=O[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,n&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function k(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?R("from").then(function(){L("from",!0)}):o.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=k,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=I}t.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(n){var t=r.request.getDocumentArray();return!!e.find(t,function(e){return e===n})}function d(n){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===n})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(n){return i.valuesOf("hrleaveandabsences_sickness_reason",n).then(function(n){r.sicknessReasons=e.indexBy(n,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}t.debug("RequestModalDetailsSicknessController"),n("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}n.controller("RequestModalDetailsSicknessController",t),t.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=n.duration(n(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,n=!c.uiOptions.multipleDays&&!!c.request.from_date,t=n||e,a=N.from_date!==c.request.from_date||N.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&t&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,n=c.request;return b({hasErrors:e?!n.to_date&&!n.from_date:!n.from_date,label:e?"To Date":"From Date",value:n.to_date})}function b(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(n(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&H.hasExpirationFromAdminSettings,n=H.hasPreviousExpirationDate,t=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=t&&(a||e||n)}function y(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",_().then(g).then(C).then(S)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue -},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&k(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function P(){c.isMode("view")||(T(),A(),R())}function S(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function I(){return l(),O(),F()}function L(){return $(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:O(),F()}function w(e){c.uiOptions.times[e].time=""}function k(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){N=e.cloneDeep(c.request.attributes())}function $(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?k():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){S(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function U(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var N,j=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=I,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=w,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=U,function(){M(),$(),B(),!c.isMode("create")&&y()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,t,a){return e.debug("AbsencePeriodInstance"),t.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var t=n();return e.current=!1,n(e.start_date).isSameOrBefore(t,"day")&&n(e.end_date).isSameOrAfter(t,"day")&&(e.current=!0),e},isInPeriod:function(e){var t=a.DATE_FORMAT.toUpperCase(),o=n(e,t);return n(this.start_date).isSameOrBefore(o)&&n(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,n){return e.debug("AbsencePeriodAPI"),n.extend({all:function(n){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,t,a,o,s){return e.debug("AbsencePeriod"),t.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=n().format(s.serverDateFormat),t={start_date:{"<=":e},end_date:{">=":e}};return a.all(t).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,n,t){"use strict";t.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(t,a,o){return t.debug("AbsenceTypeAPI"),a.extend({all:function(n){return t.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(n||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return t.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:n(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,n){return e.debug("AbsenceTypeInstance"),n.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,n){"use strict";n.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(n,t,a,o,s,i){return n.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,n,t){return s.calculateToilExpiryDate(e,n,t)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(n){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(t){return t=e.indexBy(t,"value"),e.map(n,function(n){return e.assign(n,{calculation_unit_label:t[n.calculation_unit].label,calculation_unit_name:t[n.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,n){return e.debug("EntitlementLogAPI"),n.extend({all:function(n){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",n,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,n,t){return e.debug("EntitlementInstance"),n.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return t.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,n){"use strict";n.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(n,t,a,o,s){return n.debug("Entitlement"),t.extend({all:function(e,n){return a.all(this.processFilters(e),n).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(n,t){return a.breakdown(n).then(function(n){return t?(t.map(function(t){var a=e.find(n,function(e){return e.id===t.id});return a&&(t.breakdown=a.breakdown),t}),t):n.map(function(e){return o.init(e,!0)})})},logs:function(n){return n=e.cloneDeep(n||{}),n.contact_id&&(n["entitlement_id.contact_id"]=n.contact_id,delete n.contact_id),n.period_id&&(n["entitlement_id.period_id"]=n.period_id,delete n.period_id),n.return=n.return||[],n.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(n)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,t,a){return e.debug("LeaveRequestAPI"),t.extend({all:function(n,t,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return n&&n.contact_id&&n.contact_id.IN&&0===n.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",n,t,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return t.contact_id&&t.period_id||o.reject("contact_id and period_id are mandatory"),t=n.defaults(t,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",t,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange",t),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){return e.values.breakdown=n.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,n){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:n.toString()},!1)},create:function(n){return e.debug("LeaveRequestAPI.create",n),this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,attachment_id:t}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,t){return t=n.assign({},t,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",t).then(function(e){return e.values})},find:function(n){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:n},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",t,!1).then(function(e){return e.values})},getComments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",t,!1).then(function(e){return e.values})},isManagedBy:function(n,t){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:n,contact_id:t}).then(function(e){return e.values})},isValid:function(t){e.debug("LeaveRequestAPI.isValid",t);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",t).then(function(e){e.count>0?o.reject(n(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,text:t.text,contact_id:t.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(n){return e.debug("LeaveRequestAPI.update",n),n.id?this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,n,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(t,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var n=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=n,t.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return t.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function f(e){return n.duration(e.time_to).subtract(n.duration(e.time_from)).asHours()}function p(n){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return e.find(t,function(e){return e.name===n})})}function h(n){var a=e.cloneDeep(n),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return t.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(n){return s.amount=n[0].time_from?Math.min(this.from_date_amount,f(n[0])):0,o&&(i.amount=n[1].time_from?Math.min(this.to_date_amount,f(n[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,n){return e+n.amount},0),a}.bind(this))}function v(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(n){return function(){return r.saveComment(e,n)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),t.all(n)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(n){var t=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===n&&e.pull(t,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,t)).then(function(e){return"hours"===n?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return t.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(n){if(n.comment_id)return void(n.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return n.created_at===e.created_at&&n.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(n){return{amount:e.reduce(n.values,function(e,n){return e+parseFloat(n.amount)},0),breakdown:n.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return t.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):a(s.permissions.admin.administer).then(function(n){return n?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):t.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,n,t,a){return e.debug("LeaveRequest"),n.extend({all:function(e,n,o,s,i){return t.all(this.processFilters(e),n,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return t.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return t.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,n){return e.debug("PublicHolidayAPI"),n.extend({all:function(n){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,n){return e.debug("PublicHolidayInstance"),n.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,n){"use strict";n.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(n,t,a,o,s){return n.debug("PublicHoliday"),t.extend({all:function(e){return n.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(t){n.debug("PublicHoliday.isPublicHoliday",t);var o=e(t).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,y,_,q,C){function T(e){"days"===Ue.selectedAbsenceType.calculation_unit_name?delete Ue.request[e+"_date_amount"]:delete Ue.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return ke.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function R(){var e=Ue.requestStatuses[y.statusNames.awaitingApproval].value;$e.status_id===e&&e!==Ue.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!Ue.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ue.isMode("edit")&&(e=e&&(G()||S())),Ue.canManage&&Ue.requestStatuses&&(e=e&&!!Ue.getStatusFromValue(Ue.newStatusOnSave)),(e=e&&!!Ue.period.id)&&!Ue.isMode("view")}function w(){Ue.isSelfRecord&&!Ue.isSelfLeaveApprover?Ue.request.status_id=Ue.requestStatuses[y.statusNames.awaitingApproval].value:Ue.canManage&&(Ue.request.status_id=Ue.newStatusOnSave||Ue.request.status_id)}function k(){if(Ue.isMode("edit")&&!Ue.isRole("staff")&&"toil"!==j())return Ue.request.calculateBalanceChange(Ue.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ue.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==j()&&!Ue.request.change_balance}function M(){Ue.errors=[]}function $(){return Ue.request.create().then(Pe).then(function(){ge("LeaveRequest::new")})}function x(){se()&&!Ue.isRole("staff")&&(Ue.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ue.request.delete().then(function(){Ue.dismissModal(),d.publish("LeaveRequest::delete",Ue.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(Ue.getStatusFromValue(Ue.request.status_id).name)}function N(e){return t.map(Oe[e],function(e){return Ue.requestStatuses[e]})}function j(){return Ue.request?Ue.request.request_type:Ue.leaveType||null}function H(){return!Ue.request||e.equals({},Ue.requestStatuses)?[]:Ue.request.status_id?U():N("none")}function W(e){return t.find(Ue.requestStatuses,function(n){return n.value===e})}function Y(e){Ue.errors=t.isArray(e)?e:[e],Ue.loading.absenceTypes=!1,Ue.submitting=!1}function G(){return!e.equals($e,Ue.request.attributes())||Ue.canManage&&Ue.newStatusOnSave}function V(){return Ue.postContactSelection=!0,Ue.staffMemberSelectionComplete=!1,Ue.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ue.isMode("edit")?Te:t.noop).then(function(){Ue.postContactSelection=!1,Ue.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Oe.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ue.canManage=Ue.isRole("manager")||Ue.isRole("admin")}function Q(){return Ue.canManage?f.find(Ue.request.contact_id).then(function(e){Ue.contactName=e.display_name}):o.resolve()}function J(){Ue.isRole("admin")&&Ue.isSelfRecord&&(Ue.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+ke.id==+t.get(Ue,"leaveRequest.contact_id"),a=!t.get(Ue,"leaveRequest.id");Ue.isSelfRecord=e&&a||n}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ue.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Se),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ue.request=Ue.leaveRequest||null,e=j(),n=Ue.initRequestAttributes(),"leave"===e?Ue.request=g.init(n):"sickness"===e?Ue.request=_.init(n):"toil"===e&&(Ue.request=q.init(n))}function ne(){var e={};return Ue.request?e=Ue.request.attributes():Ue.canManage||(e={contact_id:ke.id}),e}function te(){return Be="staff",ae().then(Ue.isSelfRecord&&!Ue.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ue.defaultStatus?Ue.newStatusOnSave=Ue.requestStatuses[y.statusNames[Ue.defaultStatus]].value:(Ue.isRole("admin")||Ue.isMode("create")&&Ue.isRole("manager"))&&(Ue.newStatusOnSave=Ue.requestStatuses[y.statusNames.approved].value)}function se(){return!Ue.request.status_id||!t.includes(["cancelled","rejected"],W(Ue.request.status_id).name)}function ie(e){var n=Ue.getStatusFromValue(Ue.request.status_id);return!!n&&n.name===e}function re(e){return Ue.request&&Ue.request.request_type===e}function ce(e){return Ue.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ue.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){we={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ue.loading.entitlements=!0,v.all({contact_id:Ue.request.contact_id,period_id:Ue.period.id,type_id:{IN:we.ids}},!0).finally(function(){Ue.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){ke=e})}function he(){return Ue.selectedContactId?f.find(Ue.selectedContactId).then(function(e){Ue.managedContacts=[e]}):Ue.isRole("admin")?f.all().then(function(e){console.log(e.list),Ue.managedContacts=e.list}):ke.leaveManagees().then(function(e){Ue.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ue.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){R(),d.publish(e,Ue.request),Ue.errors=[],Ue.dismissModal()}function ye(){["from","to"].forEach(function(e){Ue.request[e+"_date"]=$e[e+"_date"]})}function _e(e){if(Ue.absenceTypes=be(we.types,e),!Ue.absenceTypes.length)return o.reject(Ee)}function qe(){Ue.period=t.find(Ue.absencePeriods,function(e){return Ue.isMode("create")?e.current:ue(Ue.request,e)})}function Ce(){Ue.isMode("create")?(Ue.selectedAbsenceType=Ue.absenceTypes[0],Ue.request.type_id=Ue.selectedAbsenceType.id):Ue.selectedAbsenceType=t.find(Ue.absenceTypes,function(e){return e.id===Ue.request.type_id})}function Te(){$e=e.copy(Ue.request.attributes())}function Ae(){var e;Ue.request.id?(e=[Ue.requestStatuses[y.statusNames.approved].value,Ue.requestStatuses[y.statusNames.adminApproved].value,Ue.requestStatuses[y.statusNames.rejected].value,Ue.requestStatuses[y.statusNames.cancelled].value],Ue.mode="edit",Ue.isRole("staff")&&e.indexOf(Ue.request.status_id)>-1&&(Ue.mode="view")):Ue.mode="create"}function De(){var e=Ue.request.status_id;if(!Ue.isMode("view")&&!Ue.submitting)return Ue.submitting=!0,w(),A(),Ue.request.isValid().then(se()&&k).then(x).then(O()&&ye).then(Re).then(function(){return Ue.isMode("edit")?Le():$()}).catch(function(n){Ue.request.status_id=e,n&&Y(n)}).finally(function(){Ue.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Se(){ -xe.forEach(function(e){e()})}function Ie(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ue.request.update().then(Pe).then(function(){Ue.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ue.isRole("staff")||Ue.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var we,ke,Oe={},Me=0,$e={},xe=[],Ee="No entitlement",Be="",Fe=[],Ue=t.assign(this,m);Ue.absencePeriods=[],Ue.absenceTypes=[],Ue.canManage=!1,Ue.contactName=null,Ue.errors=[],Ue.isSelfLeaveApprover=!1,Ue.loading={absenceTypes:!0,entitlements:!0},Ue.managedContacts=[],Ue.mode="",Ue.newStatusOnSave=null,Ue.period={},Ue.postContactSelection=!1,Ue.requestStatuses={},Ue.selectedAbsenceType={},Ue.staffMemberSelectionComplete=!1,Ue.submitting=!1,Ue.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ue.canChangeAbsenceType=I,Ue.canSubmit=L,Ue.closeAlert=M,Ue.deleteLeaveRequest=E,Ue.dismissModal=B,Ue.getStatuses=H,Ue.getStatusFromValue=W,Ue.initAfterContactSelection=V,Ue.initRequestAttributes=ne,Ue.isLeaveStatus=ie,Ue.isLeaveType=re,Ue.isMode=ce,Ue.isRole=le,Ue.submit=De,Ue.updateAbsenceType=Ie,function(){Ue.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ue.canManage&&!Ue.isMode("edit")&&he()}).then(function(){if(Ue.selectedContactId&&(Ue.request.contact_id=Ue.selectedContactId),Ue.request.contact_id)return Ue.initAfterContactSelection()}).catch(Y).finally(function(){Ue.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,n){"use strict";function t(e,n,t,a,o,s,i,r,c){function u(e){return r.get().then(function(n){return e.roleOf(n.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:n.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(n){n?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}n.factory("LeavePopup",t),t.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(n){return n.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","common/lodash","leave-absences/admin-dashboard/modules/settings"],function(e,n){function t(e){e.settings.ga={userId:n.get(CRM,"vars.session.contact_id")},e.withAutoBase(!0)}return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","$analyticsProvider","settings",function(e,n,a,o,s,i,r){var c={format:["DateFormat",function(e){return e.getDateFormat()}]};n.defaults.stripTrailingSlashes=!1,o.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",t(i),s.debugEnabled(r.debug),a.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:c}).state("calendar",{url:"/calendar",template:'',resolve:c}).state("leave-balances",{url:"/leave-balances",template:"",resolve:c})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function n(e,n){e.debug("Component: admin-dashboard-container"),n.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",n]})}),define("leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component",[],function(){function e(e,n,t,a){function o(){i(),s()}function s(){return t("can administer calendar feeds").then(function(e){c.canCreateNewFeed=!!e})}function i(){return c.loading.feeds=!0,e.all().then(function(e){c.feeds=e}).finally(function(){c.loading.feeds=!1})}function r(e,t){n.open(e,t)}var c=this;c.canCreateNewFeed=!1,c.feeds=[],c.loading={feeds:!1},c.$onInit=o,c.openLinkModal=r}return e.$inject=["CalendarFeed","CalendarFeedsLinkModal","checkPermissions","shared-settings"],{__name:"calendarFeedsDropdownButton",bindings:{dropdownPosition:"@"},controller:e,controllerAs:"dropdownButton",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.html"}]}}),define("leave-absences/calendar-feeds/calendar-feeds.core",["common/angular","leave-absences/shared/modules/shared-settings"],function(e){e.module("calendar-feeds.core",["leave-absences.settings"])}),define("leave-absences/calendar-feeds/services/apis/calendar-feed.api",["common/lodash"],function(e){"use strict";function n(e,n,t){function a(){return this.sendGET("LeaveRequestCalendarFeedConfig","get",{is_active:!0}).then(function(e){return e.values})}return e.debug("CalendarFeedAPI"),t.extend({all:a})}return n.__name="CalendarFeedAPI",n.$inject=["$log","$q","api"],n}),define("leave-absences/calendar-feeds/services/models/calendar-feed.model",[],function(){"use strict";function e(e,n,t){function a(){return n.all().then(function(e){return e.map(function(e){return t.init(e)})})}return e.extend({all:a})}return e.__name="CalendarFeed",e.$inject=["Model","CalendarFeedAPI","CalendarFeedInstance"],e}),define("leave-absences/calendar-feeds/services/models/calendar-feed.instance",[],function(){"use strict";function e(e){return e.extend({})}return e.__name="CalendarFeedInstance",e.$inject=["ModelInstance"],e}),define("leave-absences/calendar-feeds/calendar-feeds.models",["common/angular","leave-absences/calendar-feeds/services/apis/calendar-feed.api","leave-absences/calendar-feeds/services/models/calendar-feed.model","leave-absences/calendar-feeds/services/models/calendar-feed.instance","common/models/model","common/services/api"],function(e,n,t,a){e.module("calendar-feeds.models",["common.apis","common.models"]).factory(n.__name,n).factory(t.__name,t).factory(a.__name,a)}),define("leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component",["common/lodash"],function(e){return{__name:"calendarFeedsLinkModal",bindings:{dismiss:"<",url:"<",title:"<"},controller:e.noop,controllerAs:"linkModal",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/link-modal/components/calendar-feeds-link-modal.html"}]}}),define("leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service",[],function(){function e(e,n,t){function a(e,a){var s=o(),i=t+"civicrm/calendar-feed?hash="+a;n.open({controllerAs:"modal",size:"md",template:'',controller:["$uibModalInstance","title","url",function(e,n,t){this.dismiss=e.dismiss,this.title=n,this.url=t}],appendTo:s,resolve:{title:function(){return e},url:function(){return i}}})}function o(){var n=e.find("#bootstrap-theme");return 0===n.length&&(n=e.find("body")),n.eq(0)}return{open:a}}return e.__name="CalendarFeedsLinkModal",e.$inject=["$document","$uibModal","HOST_URL"],e}),define("leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive",["common/lodash"],function(e){function n(n,t){function a(e,t,a,o){function s(){r(),u()}function i(){l[0].setSelectionRange(0,0),l.blur()}function r(){c(),document.execCommand("copy"),i()}function c(){l.focus(),l[0].setSelectionRange(0,l.val().length)}function u(){m.justCopied=!0,d&&n.cancel(d),d=n(function(){m.justCopied=!1},2e3)}var l,d,m=e.input;m.model=o.model,m.justCopied=!1,m.copy=s,m.selectInputText=c,function(){l=t.find("input")}()}var o=t.sourcePath+"calendar-feeds/link-modal/directives/input-with-copy-button.html";return{controller:e.noop,controllerAs:"input",link:a,restrict:"E",scope:{},templateUrl:o,require:{model:"^ngModel"}}}return n.__name="inputWithCopyButton",n.$inject=["$timeout","shared-settings"],n}),define("leave-absences/calendar-feeds/link-modal/link-modal.core",["common/angular","common/angularBootstrap"],function(e){e.module("calendar-feeds.link-modal.core",["ui.bootstrap"])}),function(e){define("leave-absences/calendar-feeds/link-modal/link-modal.constants",["common/angular"],function(n){"use strict";n.module("calendar-feeds.link-modal.constants",[]).constant("HOST_URL",e.absoluteUrl("/"))})}(Drupal),define("leave-absences/calendar-feeds/link-modal/link-modal.module",["common/angular","leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component","leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service","leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/link-modal/link-modal.core","leave-absences/calendar-feeds/link-modal/link-modal.constants"],function(e,n,t,a){e.module("calendar-feeds.link-modal",["calendar-feeds.core","calendar-feeds.link-modal.core","calendar-feeds.link-modal.constants"]).component(n.__name,n).directive(a.__name,a).factory(t.__name,t)}),define("leave-absences/calendar-feeds/dropdown-button/dropdown-button.module",["common/angular","leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component","common/services/check-permissions","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/calendar-feeds.models","leave-absences/calendar-feeds/link-modal/link-modal.module"],function(e,n){e.module("calendar-feeds.dropdown-button",["common.services","calendar-feeds.core","calendar-feeds.models","calendar-feeds.link-modal"]).component(n.__name,n)}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/angulartics","common/angulartics-google-tag-manager","common/angularUiRouter","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container","leave-absences/calendar-feeds/dropdown-button/dropdown-button.module"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","angulartics","angulartics.google.tagmanager","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components","calendar-feeds.dropdown-button"]).run(["$log","$rootScope","shared-settings","settings",function(e,n,t,a){e.debug("app.run"),n.sharedPathTpl=t.sharedPathTpl,n.settings=a}]),e}),function(e,n){var t=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";n.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":t+"/shared","leave-absences/admin-dashboard":t+"/admin-dashboard"}}),n(["leave-absences/shared/config"],function(){n(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); +},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&k(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function P(){c.isMode("view")||(T(),A(),R())}function S(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function I(){return l(),O(),F()}function L(){return $(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:O(),F()}function w(e){c.uiOptions.times[e].time=""}function k(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){N=e.cloneDeep(c.request.attributes())}function $(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?k():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){S(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function U(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var N,j=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=I,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=w,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=U,function(){M(),$(),B(),!c.isMode("create")&&y()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,t,a){return e.debug("AbsencePeriodInstance"),t.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var t=n();return e.current=!1,n(e.start_date).isSameOrBefore(t,"day")&&n(e.end_date).isSameOrAfter(t,"day")&&(e.current=!0),e},isInPeriod:function(e){var t=a.DATE_FORMAT.toUpperCase(),o=n(e,t);return n(this.start_date).isSameOrBefore(o)&&n(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,n){return e.debug("AbsencePeriodAPI"),n.extend({all:function(n){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,t,a,o,s){return e.debug("AbsencePeriod"),t.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=n().format(s.serverDateFormat),t={start_date:{"<=":e},end_date:{">=":e}};return a.all(t).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,n,t){"use strict";t.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(t,a,o){return t.debug("AbsenceTypeAPI"),a.extend({all:function(n){return t.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(n||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return t.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:n(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,n){return e.debug("AbsenceTypeInstance"),n.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,n){"use strict";n.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(n,t,a,o,s,i){return n.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,n,t){return s.calculateToilExpiryDate(e,n,t)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(n){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(t){return t=e.indexBy(t,"value"),e.map(n,function(n){return e.assign(n,{calculation_unit_label:t[n.calculation_unit].label,calculation_unit_name:t[n.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,n){return e.debug("EntitlementLogAPI"),n.extend({all:function(n){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",n,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,n,t){return e.debug("EntitlementInstance"),n.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return t.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,n){"use strict";n.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(n,t,a,o,s){return n.debug("Entitlement"),t.extend({all:function(e,n){return a.all(this.processFilters(e),n).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(n,t){return a.breakdown(n).then(function(n){return t?(t.map(function(t){var a=e.find(n,function(e){return e.id===t.id});return a&&(t.breakdown=a.breakdown),t}),t):n.map(function(e){return o.init(e,!0)})})},logs:function(n){return n=e.cloneDeep(n||{}),n.contact_id&&(n["entitlement_id.contact_id"]=n.contact_id,delete n.contact_id),n.period_id&&(n["entitlement_id.period_id"]=n.period_id,delete n.period_id),n.return=n.return||[],n.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(n)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,t,a){return e.debug("LeaveRequestAPI"),t.extend({all:function(n,t,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return n&&n.contact_id&&n.contact_id.IN&&0===n.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",n,t,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return t.contact_id&&t.period_id||o.reject("contact_id and period_id are mandatory"),t=n.defaults(t,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",t,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange",t),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){return e.values.breakdown=n.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,n){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:n.toString()},!1)},create:function(n){return e.debug("LeaveRequestAPI.create",n),this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,attachment_id:t}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,t){return t=n.assign({},t,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",t).then(function(e){return e.values})},find:function(n){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:n},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",t,!1).then(function(e){return e.values})},getComments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",t,!1).then(function(e){return e.values})},isManagedBy:function(n,t){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:n,contact_id:t}).then(function(e){return e.values})},isValid:function(t){e.debug("LeaveRequestAPI.isValid",t);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",t).then(function(e){e.count>0?o.reject(n(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,text:t.text,contact_id:t.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(n){return e.debug("LeaveRequestAPI.update",n),n.id?this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,n,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(t,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var n=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=n,t.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return t.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function f(e){return n.duration(e.time_to).subtract(n.duration(e.time_from)).asHours()}function p(n){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return e.find(t,function(e){return e.name===n})})}function h(n){var a=e.cloneDeep(n),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return t.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(n){return s.amount=n[0].time_from?Math.min(this.from_date_amount,f(n[0])):0,o&&(i.amount=n[1].time_from?Math.min(this.to_date_amount,f(n[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,n){return e+n.amount},0),a}.bind(this))}function v(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(n){return function(){return r.saveComment(e,n)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),t.all(n)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(n){var t=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===n&&e.pull(t,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,t)).then(function(e){return"hours"===n?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return t.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(n){if(n.comment_id)return void(n.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return n.created_at===e.created_at&&n.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(n){return{amount:e.reduce(n.values,function(e,n){return e+parseFloat(n.amount)},0),breakdown:n.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return t.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):a(s.permissions.admin.administer).then(function(n){return n?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):t.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,n,t,a){return e.debug("LeaveRequest"),n.extend({all:function(e,n,o,s,i){return t.all(this.processFilters(e),n,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return t.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return t.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,n){return e.debug("PublicHolidayAPI"),n.extend({all:function(n){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,n){return e.debug("PublicHolidayInstance"),n.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,n){"use strict";n.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(n,t,a,o,s){return n.debug("PublicHoliday"),t.extend({all:function(e){return n.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(t){n.debug("PublicHoliday.isPublicHoliday",t);var o=e(t).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,y,_,q,C){function T(e){"days"===Ue.selectedAbsenceType.calculation_unit_name?delete Ue.request[e+"_date_amount"]:delete Ue.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return ke.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function R(){var e=Ue.requestStatuses[y.statusNames.awaitingApproval].value;$e.status_id===e&&e!==Ue.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!Ue.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ue.isMode("edit")&&(e=e&&(G()||S())),Ue.canManage&&Ue.requestStatuses&&(e=e&&!!Ue.getStatusFromValue(Ue.newStatusOnSave)),(e=e&&!!Ue.period.id)&&!Ue.isMode("view")}function w(){Ue.isSelfRecord&&!Ue.isSelfLeaveApprover?Ue.request.status_id=Ue.requestStatuses[y.statusNames.awaitingApproval].value:Ue.canManage&&(Ue.request.status_id=Ue.newStatusOnSave||Ue.request.status_id)}function k(){if(Ue.isMode("edit")&&!Ue.isRole("staff")&&"toil"!==j())return Ue.request.calculateBalanceChange(Ue.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ue.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==j()&&!Ue.request.change_balance}function M(){Ue.errors=[]}function $(){return Ue.request.create().then(Pe).then(function(){ge("LeaveRequest::new")})}function x(){se()&&!Ue.isRole("staff")&&(Ue.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ue.request.delete().then(function(){Ue.dismissModal(),d.publish("LeaveRequest::delete",Ue.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function U(){return N(Ue.getStatusFromValue(Ue.request.status_id).name)}function N(e){return t.map(Oe[e],function(e){return Ue.requestStatuses[e]})}function j(){return Ue.request?Ue.request.request_type:Ue.leaveType||null}function H(){return!Ue.request||e.equals({},Ue.requestStatuses)?[]:Ue.request.status_id?U():N("none")}function W(e){return t.find(Ue.requestStatuses,function(n){return n.value===e})}function Y(e){Ue.errors=t.isArray(e)?e:[e],Ue.loading.absenceTypes=!1,Ue.submitting=!1}function G(){return!e.equals($e,Ue.request.attributes())||Ue.canManage&&Ue.newStatusOnSave}function V(){return Ue.postContactSelection=!0,Ue.staffMemberSelectionComplete=!1,Ue.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ue.isMode("edit")?Te:t.noop).then(function(){Ue.postContactSelection=!1,Ue.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Oe.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ue.canManage=Ue.isRole("manager")||Ue.isRole("admin")}function Q(){return Ue.canManage?f.find(Ue.request.contact_id).then(function(e){Ue.contactName=e.display_name}):o.resolve()}function J(){Ue.isRole("admin")&&Ue.isSelfRecord&&(Ue.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+ke.id==+t.get(Ue,"leaveRequest.contact_id"),a=!t.get(Ue,"leaveRequest.id");Ue.isSelfRecord=e&&a||n}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ue.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Se),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ue.request=Ue.leaveRequest||null,e=j(),n=Ue.initRequestAttributes(),"leave"===e?Ue.request=g.init(n):"sickness"===e?Ue.request=_.init(n):"toil"===e&&(Ue.request=q.init(n))}function ne(){var e={};return Ue.request?e=Ue.request.attributes():Ue.canManage||(e={contact_id:ke.id}),e}function te(){return Be="staff",ae().then(Ue.isSelfRecord&&!Ue.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ue.defaultStatus?Ue.newStatusOnSave=Ue.requestStatuses[y.statusNames[Ue.defaultStatus]].value:(Ue.isRole("admin")||Ue.isMode("create")&&Ue.isRole("manager"))&&(Ue.newStatusOnSave=Ue.requestStatuses[y.statusNames.approved].value)}function se(){return!Ue.request.status_id||!t.includes(["cancelled","rejected"],W(Ue.request.status_id).name)}function ie(e){var n=Ue.getStatusFromValue(Ue.request.status_id);return!!n&&n.name===e}function re(e){return Ue.request&&Ue.request.request_type===e}function ce(e){return Ue.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ue.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){we={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ue.loading.entitlements=!0,v.all({contact_id:Ue.request.contact_id,period_id:Ue.period.id,type_id:{IN:we.ids}},!0).finally(function(){Ue.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){ke=e})}function he(){return Ue.selectedContactId?f.find(Ue.selectedContactId).then(function(e){Ue.managedContacts=[e]}):Ue.isRole("admin")?f.all().then(function(e){Ue.managedContacts=e.list}):ke.leaveManagees().then(function(e){Ue.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ue.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){R(),d.publish(e,Ue.request),Ue.errors=[],Ue.dismissModal()}function ye(){["from","to"].forEach(function(e){Ue.request[e+"_date"]=$e[e+"_date"]})}function _e(e){if(Ue.absenceTypes=be(we.types,e),!Ue.absenceTypes.length)return o.reject(Ee)}function qe(){Ue.period=t.find(Ue.absencePeriods,function(e){return Ue.isMode("create")?e.current:ue(Ue.request,e)})}function Ce(){Ue.isMode("create")?(Ue.selectedAbsenceType=Ue.absenceTypes[0],Ue.request.type_id=Ue.selectedAbsenceType.id):Ue.selectedAbsenceType=t.find(Ue.absenceTypes,function(e){return e.id===Ue.request.type_id})}function Te(){$e=e.copy(Ue.request.attributes())}function Ae(){var e;Ue.request.id?(e=[Ue.requestStatuses[y.statusNames.approved].value,Ue.requestStatuses[y.statusNames.adminApproved].value,Ue.requestStatuses[y.statusNames.rejected].value,Ue.requestStatuses[y.statusNames.cancelled].value],Ue.mode="edit",Ue.isRole("staff")&&e.indexOf(Ue.request.status_id)>-1&&(Ue.mode="view")):Ue.mode="create"}function De(){var e=Ue.request.status_id;if(!Ue.isMode("view")&&!Ue.submitting)return Ue.submitting=!0,w(),A(),Ue.request.isValid().then(se()&&k).then(x).then(O()&&ye).then(Re).then(function(){return Ue.isMode("edit")?Le():$()}).catch(function(n){Ue.request.status_id=e,n&&Y(n)}).finally(function(){Ue.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Se(){xe.forEach(function(e){e()})} +function Ie(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ue.request.update().then(Pe).then(function(){Ue.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ue.isRole("staff")||Ue.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var we,ke,Oe={},Me=0,$e={},xe=[],Ee="No entitlement",Be="",Fe=[],Ue=t.assign(this,m);Ue.absencePeriods=[],Ue.absenceTypes=[],Ue.canManage=!1,Ue.contactName=null,Ue.errors=[],Ue.isSelfLeaveApprover=!1,Ue.loading={absenceTypes:!0,entitlements:!0},Ue.managedContacts=[],Ue.mode="",Ue.newStatusOnSave=null,Ue.period={},Ue.postContactSelection=!1,Ue.requestStatuses={},Ue.selectedAbsenceType={},Ue.staffMemberSelectionComplete=!1,Ue.submitting=!1,Ue.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ue.canChangeAbsenceType=I,Ue.canSubmit=L,Ue.closeAlert=M,Ue.deleteLeaveRequest=E,Ue.dismissModal=B,Ue.getStatuses=H,Ue.getStatusFromValue=W,Ue.initAfterContactSelection=V,Ue.initRequestAttributes=ne,Ue.isLeaveStatus=ie,Ue.isLeaveType=re,Ue.isMode=ce,Ue.isRole=le,Ue.submit=De,Ue.updateAbsenceType=Ie,function(){Ue.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ue.canManage&&!Ue.isMode("edit")&&he()}).then(function(){if(Ue.selectedContactId&&(Ue.request.contact_id=Ue.selectedContactId),Ue.request.contact_id)return Ue.initAfterContactSelection()}).catch(Y).finally(function(){Ue.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,n){"use strict";function t(e,n,t,a,o,s,i,r,c){function u(e){return r.get().then(function(n){return e.roleOf(n.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:n.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(n){n?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}n.factory("LeavePopup",t),t.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),function(e){define("leave-absences/admin-dashboard/modules/settings",["common/angular"],function(n){return n.module("admin-dashboard.settings",[]).constant("settings",{contactId:e.vars.leaveAndAbsences.loggedInUserId,debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/admin-dashboard/"})})}(CRM),define("leave-absences/admin-dashboard/modules/config",["common/angular","common/lodash","leave-absences/admin-dashboard/modules/settings"],function(e,n){function t(e){e.settings.ga={userId:n.get(CRM,"vars.session.contact_id")},e.withAutoBase(!0)}return e.module("admin-dashboard.config",["admin-dashboard.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","$analyticsProvider","settings",function(e,n,a,o,s,i,r){var c={format:["DateFormat",function(e){return e.getDateFormat()}]};n.defaults.stripTrailingSlashes=!1,o.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",t(i),s.debugEnabled(r.debug),a.otherwise("/requests"),e.state("requests",{url:"/requests",template:'',resolve:c}).state("calendar",{url:"/calendar",template:'',resolve:c}).state("leave-balances",{url:"/leave-balances",template:"",resolve:c})}])}),define("leave-absences/admin-dashboard/modules/components",["common/angular"],function(e){return e.module("admin-dashboard.components",[])}),define("leave-absences/admin-dashboard/components/admin-dashboard-container",["leave-absences/admin-dashboard/modules/components"],function(e){function n(e,n){e.debug("Component: admin-dashboard-container"),n.section="admin-dashboard"}e.component("adminDashboardContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/admin-dashboard-container.html"}],controllerAs:"vm",controller:["$log","$rootScope",n]})}),define("leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component",[],function(){function e(e,n,t,a){function o(){i(),s()}function s(){return t("can administer calendar feeds").then(function(e){c.canCreateNewFeed=!!e})}function i(){return c.loading.feeds=!0,e.all().then(function(e){c.feeds=e}).finally(function(){c.loading.feeds=!1})}function r(e,t){n.open(e,t)}var c=this;c.canCreateNewFeed=!1,c.feeds=[],c.loading={feeds:!1},c.$onInit=o,c.openLinkModal=r}return e.$inject=["CalendarFeed","CalendarFeedsLinkModal","checkPermissions","shared-settings"],{__name:"calendarFeedsDropdownButton",bindings:{dropdownPosition:"@"},controller:e,controllerAs:"dropdownButton",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.html"}]}}),define("leave-absences/calendar-feeds/calendar-feeds.core",["common/angular","leave-absences/shared/modules/shared-settings"],function(e){e.module("calendar-feeds.core",["leave-absences.settings"])}),define("leave-absences/calendar-feeds/services/apis/calendar-feed.api",["common/lodash"],function(e){"use strict";function n(e,n,t){function a(){return this.sendGET("LeaveRequestCalendarFeedConfig","get",{is_active:!0}).then(function(e){return e.values})}return e.debug("CalendarFeedAPI"),t.extend({all:a})}return n.__name="CalendarFeedAPI",n.$inject=["$log","$q","api"],n}),define("leave-absences/calendar-feeds/services/models/calendar-feed.model",[],function(){"use strict";function e(e,n,t){function a(){return n.all().then(function(e){return e.map(function(e){return t.init(e)})})}return e.extend({all:a})}return e.__name="CalendarFeed",e.$inject=["Model","CalendarFeedAPI","CalendarFeedInstance"],e}),define("leave-absences/calendar-feeds/services/models/calendar-feed.instance",[],function(){"use strict";function e(e){return e.extend({})}return e.__name="CalendarFeedInstance",e.$inject=["ModelInstance"],e}),define("leave-absences/calendar-feeds/calendar-feeds.models",["common/angular","leave-absences/calendar-feeds/services/apis/calendar-feed.api","leave-absences/calendar-feeds/services/models/calendar-feed.model","leave-absences/calendar-feeds/services/models/calendar-feed.instance","common/models/model","common/services/api"],function(e,n,t,a){e.module("calendar-feeds.models",["common.apis","common.models"]).factory(n.__name,n).factory(t.__name,t).factory(a.__name,a)}),define("leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component",["common/lodash"],function(e){return{__name:"calendarFeedsLinkModal",bindings:{dismiss:"<",url:"<",title:"<"},controller:e.noop,controllerAs:"linkModal",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/link-modal/components/calendar-feeds-link-modal.html"}]}}),define("leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service",[],function(){function e(e,n,t){function a(e,a){var s=o(),i=t+"civicrm/calendar-feed?hash="+a;n.open({controllerAs:"modal",size:"md",template:'',controller:["$uibModalInstance","title","url",function(e,n,t){this.dismiss=e.dismiss,this.title=n,this.url=t}],appendTo:s,resolve:{title:function(){return e},url:function(){return i}}})}function o(){var n=e.find("#bootstrap-theme");return 0===n.length&&(n=e.find("body")),n.eq(0)}return{open:a}}return e.__name="CalendarFeedsLinkModal",e.$inject=["$document","$uibModal","HOST_URL"],e}),define("leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive",["common/lodash"],function(e){function n(n,t){function a(e,t,a,o){function s(){r(),u()}function i(){l[0].setSelectionRange(0,0),l.blur()}function r(){c(),document.execCommand("copy"),i()}function c(){l.focus(),l[0].setSelectionRange(0,l.val().length)}function u(){m.justCopied=!0,d&&n.cancel(d),d=n(function(){m.justCopied=!1},2e3)}var l,d,m=e.input;m.model=o.model,m.justCopied=!1,m.copy=s,m.selectInputText=c,function(){l=t.find("input")}()}var o=t.sourcePath+"calendar-feeds/link-modal/directives/input-with-copy-button.html";return{controller:e.noop,controllerAs:"input",link:a,restrict:"E",scope:{},templateUrl:o,require:{model:"^ngModel"}}}return n.__name="inputWithCopyButton",n.$inject=["$timeout","shared-settings"],n}),define("leave-absences/calendar-feeds/link-modal/link-modal.core",["common/angular","common/angularBootstrap"],function(e){e.module("calendar-feeds.link-modal.core",["ui.bootstrap"])}),function(e){define("leave-absences/calendar-feeds/link-modal/link-modal.constants",["common/angular"],function(n){"use strict";n.module("calendar-feeds.link-modal.constants",[]).constant("HOST_URL",e.absoluteUrl("/"))})}(Drupal),define("leave-absences/calendar-feeds/link-modal/link-modal.module",["common/angular","leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component","leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service","leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/link-modal/link-modal.core","leave-absences/calendar-feeds/link-modal/link-modal.constants"],function(e,n,t,a){e.module("calendar-feeds.link-modal",["calendar-feeds.core","calendar-feeds.link-modal.core","calendar-feeds.link-modal.constants"]).component(n.__name,n).directive(a.__name,a).factory(t.__name,t)}),define("leave-absences/calendar-feeds/dropdown-button/dropdown-button.module",["common/angular","leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component","common/services/check-permissions","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/calendar-feeds.models","leave-absences/calendar-feeds/link-modal/link-modal.module"],function(e,n){e.module("calendar-feeds.dropdown-button",["common.services","calendar-feeds.core","calendar-feeds.models","calendar-feeds.link-modal"]).component(n.__name,n)}),define("leave-absences/admin-dashboard/app",["common/angular","common/angularBootstrap","common/angulartics","common/angulartics-google-tag-manager","common/angularUiRouter","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/admin-dashboard/modules/config","leave-absences/admin-dashboard/components/admin-dashboard-container","leave-absences/calendar-feeds/dropdown-button/dropdown-button.module"],function(e){return e.module("admin-dashboard",["ngAnimate","ngResource","angulartics","angulartics.google.tagmanager","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.mocks","leave-absences.components","leave-absences.controllers","leave-absences.settings","leave-absences.services","admin-dashboard.config","admin-dashboard.components","calendar-feeds.dropdown-button"]).run(["$log","$rootScope","shared-settings","settings",function(e,n,t,a){e.debug("app.run"),n.sharedPathTpl=t.sharedPathTpl,n.settings=a}]),e}),function(e,n){var t=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";n.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":t+"/shared","leave-absences/admin-dashboard":t+"/admin-dashboard"}}),n(["leave-absences/shared/config"],function(){n(["leave-absences/admin-dashboard/app"],function(){document.dispatchEvent("function"==typeof window.CustomEvent?new CustomEvent("adminDashboardReady"):function(){var e=document.createEvent("Event");return e.initEvent("adminDashboardReady",!0,!0),e}())})})}(CRM,require),define("admin-dashboard",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/admin-dashboard.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/manager-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/manager-leave.min.js index 873791b9030..f22ea9ca627 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/manager-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/manager-leave.min.js @@ -1,5 +1,5 @@ -!function(e){define("leave-absences/shared/config",[],function(){e.config({paths:{mocks:"../test/mocks"}}),e.config({paths:{mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",sourcePath:e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&u.absencePeriods.length&&(u.filters.period_id=s().id),e.absenceTypes&&u.absenceTypes.length&&(u.filters.type_id=i().id),(e.loggedInContactId||e.userRole)&&(u.filters.managed_by="manager"===u.userRole?u.loggedInContactId:void 0),o()&&u.submitFilters()}function o(){return e.every(u.filters,function(e){return null!==e})}function s(){return e.find(u.absencePeriods,function(e){return e.current})||u.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function i(){return u.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function r(e){return e.current?"Current Period ("+e.title+")":e.title}function c(){n.$emit("LeaveBalanceFilters::update",u.filters)}var u=this;u.filters={period_id:null,type_id:null,managed_by:null},u.$onChanges=a,u.labelPeriod=r,u.submitFilters=c}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,o,s){return t.getLeaveBalances(this.processFilters(e),n,a,o,s)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){q(),g().then(function(){P.loading.component=!1})}function p(){return o.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function v(){return s.all().then(s.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return i.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function g(){return n.all([p(),v(),h(),b(),C()]).catch(function(e){c.error("Error",e)})}function b(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function y(){return P.loading.report=!0,r.all(R,P.pagination,void 0,void 0,!1).then(function(e){P.report=_(e.list),P.reportCount=e.total}).catch(function(e){c.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function _(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function q(){a.$on("LeaveBalanceFilters::update",A),u.subscribe("LeaveRequest::new",T)}function C(){return m(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function T(e){A(e,R)}function A(e,t){R=t,P.pagination.page=1,D(),P.loadReportCurrentPage()}function D(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+R.type_id})}var R={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.$onInit=f,P.loadReportCurrentPage=y}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(t,n,a,o,s,i,r){function c(){return{loadContacts:function(){return l.loadContactsForAdmin()}}}function u(e){i.info("",["

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 l,d;return{init:function(t){return d=t,l=r.init(d),d.filters.userSettings.assignedTo=e.find(d.filtersByAssignee,{type:"me"}),d.showContactDetailsLink=!0,d.showContactName=!0,d.showFilters=!0,d.showAdminFilteringHint=u,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService","LeaveCalendarService",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(t,n,a,o){function s(){return{loadContacts:function(){return i.loadLookUpAndFilteredContacts()}}}t.debug("LeaveCalendarManagerController");var i,r;return{init:function(t){return r=t,i=o.init(r),r.filters.userSettings.assignedTo=e.find(r.filtersByAssignee,{type:"me"}),r.showContactName=!0,r.showFilters=!0,s()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance","LeaveCalendarService",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,n,a){function o(){return{loadContacts:function(){return i.displaySingleContact?s.loadFilteredContacts():"admin"===i.userPermissionRole?s.loadContactsForAdmin():s.loadLookUpAndFilteredContacts()}}}e.debug("LeaveCalendarStaffController");var s,i;return{init:function(e){return i=e,s=a.init(i),i.filters.userSettings.contacts_with_leaves=!0,i.showTheseContacts=[i.contactId],i.showContactName=!0,i.showFilters=!0,i.displaySingleContact&&(i.showFilters=!1,i.lookupContacts=[{id:i.contactId}]),o()}}}n.controller("LeaveCalendarStaffController",["$log","$q","Contact","LeaveCalendarService",a])}),define("leave-absences/shared/components/leave-calendar.component",["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){function a(n,a,o,s,i,r,c,u,l,d){function m(){N().then(b).then(g).then(_).then(I).then(function(){return a.all([C(),D(),S(),W.showFilters?R():e.noop])}).then(function(){f(),y(),E()}).then(function(){W.loading.page=!1})}function f(){W.supportData.absenceTypes.push({id:"",title:"Leave",color:"#4D4D68",calculation_unit:e.chain(W.supportData.calculationUnits).find({name:"days"}).get("value").value()})}function p(){for(var e=[],n=t(W.selectedPeriod.start_date).clone().startOf("month"),a=t(W.selectedPeriod.end_date).clone().endOf("month");n.isBefore(a);)e.push(L(n)),n.add(1,"month");W.months=e}function v(){return e.includes(["admin","manager"],W.userPermissionRole)}function h(e){return e.format("YYYY-MM")}function g(){s.$on("LeaveCalendar::updateFiltersByAbsenceType",function(e,t){W.supportData.absenceTypesToFilterBy=t,$(!0)})}function b(){s.$new().$watch(function(){return W.selectedMonthIndex},function(e,t){null!==t&&e!==t&&(F(),E(),$())})}function y(e){W.injectMonth=!0,U("injected").then(function(){$(e)}).then(function(){W.loading.calendar=!1})}function _(){j=n("LeaveCalendar"+e.capitalize(H)+"Controller").init(W)}function q(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return r.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current})}).then(p).then(k)}function T(){return c.all().then(c.loadCalculationUnits)}function A(){return l.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function D(){return j.loadContacts().then(function(e){W.contacts=e})}function R(){return l.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){W.filters.optionValues.regions=e.hrjc_region,W.filters.optionValues.locations=e.hrjc_location,W.filters.optionValues.levelTypes=e.hrjc_level_type,W.filters.optionValues.departments=e.hrjc_department})}function P(){return u.all()}function S(){return a.all([T(),P(),A()]).then(function(t){W.supportData.absenceTypes=t[0],W.supportData.publicHolidays=t[1],W.supportData.calculationUnits=t[2].hrleaveandabsences_absence_type_calculation_unit,W.supportData.dayTypes=t[2].hrleaveandabsences_leave_request_day_type,W.supportData.leaveRequestStatuses=t[2].hrleaveandabsences_leave_request_status,W.supportData.toilAmounts=e.indexBy(t[2].hrleaveandabsences_toil_amounts,"value")})}function I(){var e=a.resolve();return W.injectMonth&&(e=U("destroyed"),W.injectMonth=!1),e}function L(e){return{index:h(e),month:e.month(),year:e.year(),name:e.format("MMMM"),moment:t().year(e.year()).month(e.month())}}function O(){var t=W.selectedPeriod.id;W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current}),t!==W.selectedPeriod.id&&p(),k(),E(),w("month")}function M(e){var n="previous"===e?"subtract":"add";F(t(W.selectedMonth.moment)[n](1,"month")),E(),w("month")}function w(t){t=e.includes(["contacts","period","month"],t)?t:"period",a.resolve().then(I).then("period"===t&&p).then("period"===t&&x).then("contacts"===t&&D).then("month"===t&&E).then(function(){y("contacts"===t)})}function $(e){s.$emit("LeaveCalendar::showMonth",!!e)}function k(){F(t())}function x(){F(W.months[0].moment)}function B(n){var a="previous"===n?"first":"last",o=e[a](W.months),s=t().year(o.year).month(o.month);W.monthPaginatorsAvailability[n]=!W.selectedMonth.moment.isSame(s,"month")}function E(){B("previous"),B("next")}function F(t){t&&(W.selectedMonthIndex=h(t)),W.selectedMonth=e.find(W.months,{index:W.selectedMonthIndex})}function N(){return a.all([d(i.permissions.admin.administer),d(i.permissions.ssp.manage)]).then(function(e){W.userPermissionRole=e[0]?"admin":e[1]?"manager":"staff",H=W.roleOverride?W.roleOverride:W.userPermissionRole})}function U(t){return a(function(n){var a=s.$on("LeaveCalendar::month"+e.capitalize(t),function(){a(),n()})})}o.debug("Component: leave-calendar");var j,H,W=this;W.absencePeriods=[],W.contacts=[],W.contactIdsToReduceTo=null,W.injectMonth=!1,W.months=[],W.selectedMonth={},W.selectedMonthIndex="",W.selectedPeriod=null,W.showContactName=!1,W.showFilters=!1,W.userPermissionRole="staff",W.loading={calendar:!0,page:!0},W.filters={hideOnMobile:!0,optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null},absenceTypes:{}},W.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],W.filters.userSettings.assignedTo=W.filtersByAssignee[2],W.monthPaginatorsAvailability={previous:!0,next:!0},W.supportData={absenceTypesToFilterBy:[]},W.$onInit=m,W.canManageRequests=v,W.labelPeriod=q,W.navigateToCurrentMonth=O,W.paginateMonth=M,W.refresh=w}n.component("leaveCalendar",{bindings:{contactId:"<",displaySingleContact:"0,n={from_date:{to:Q.month.days[Q.month.days.length-1].date+" 23:59:59"},to_date:{from:Q.month.days[0].date+" 00:00:00"},status_id:{IN:M()},contact_id:{IN:Q.contacts.map(function(e){return e.id})},type_id:{IN:t?Q.supportData.absenceTypesToFilterBy:e.pluck(Q.supportData.absenceTypes,"id")}};return y(),i.all(n,null,null,null,!1).then(function(e){return X={},t&&(e.list=q(e.list)),A(e.list)})}function k(){var t=Q.month.days[0].date,n=Q.month.days[Q.month.days.length-1].date;return s.get(Q.contacts.map(function(e){return e.id}),t,n).then(function(t){z=e.indexBy(t,"contact_id")})}function x(){return Q.contactIdsToReduceTo&&(Q.contacts=Q.contacts.filter(function(t){return e.includes(Q.contactIdsToReduceTo,t.contact_id)||e.find(X,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function B(t){var n=L(t);X[t.contact_id]=X[t.contact_id]||{},n.forEach(function(n){e.remove(X[t.contact_id][n.date],function(e){return e.id===t.id})})}function E(){o.$emit("LeaveCalendar::monthDestroyed"),V.map(function(e){e.remove?e.remove():e()})}function F(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=f(n),s=!0===o?a.resolve():a.all([i.isWeekend(v(t.date)),i.isNonWorkingDay(v(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:S(t.date)})}),s.then(function(){return X[n]&&X[n][t.date]?X[n][t.date]:[]}).then(function(a){a=j(a),e.assign(t.contactsData[n],{leaveRequests:a,leaveRequestsToShowInCell:g(a),leaveRequestsAttributes:C(t,a)})})}function N(){return a.all(Q.month.days.map(function(e){return a.all(Q.contacts.map(function(t){return F(e,t.id)}))}))}function U(e,t){Q.currentPage=0,Q.visible=!0,(t||!G)&&w()}function j(n){return e.sortBy(n,function(e){return+t(e.from_date).format("X")+(R("half_day_pm",e,e.from_date)?1:0)})}function H(t){var n=e.find(Q.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 W(e){h(e),-1!==M().indexOf(e.status_id)&&l(e)}function Y(e){return a.all(L(e).map(function(t){return F(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var G=!1,V=[],z={},X={},Q=this;Q.currentPage=0,Q.pageSize=20,Q.visible=!1,Q.showContactName=!!Q.showContactName,Q.showOnlyWithLeaveRequests=!!Q.showOnlyWithLeaveRequests,Q.$onDestroy=E,Q.$onInit=u,Q.contactsList=p,Q.getContactUrl=_}n.component("leaveCalendarMonth",{bindings:{showTheseContacts:"<",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/models/contact","common/models/session.model","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,i,r,c,u,l,d,m){function f(){a.resolve().then(_).then(C).then(function(){return y()&&"admin"!==O.role&&P()}).then(R).finally(function(){O.loading.component=!1})}function p(t){L=O.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===O.leaveRequest.request_type?i.open(q(t)):g(t)}function v(){return"admin"===O.role&&"public_holiday"===O.leaveRequest.request_type}function h(n){var a=O.absenceTypes[O.leaveRequest.type_id].allow_request_cancelation;return"admin"===O.role||("manager"===O.role?e.includes([M.awaitingApproval,M.moreInformationRequired],n):"3"===a?t().isBefore(O.leaveRequest.from_date):"2"===a)}function g(t){i.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return O.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(c.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){A(t)}}):q(t)})}})}function b(){return s.find(I).then(function(e){return e.checkIfSelfLeaveApprover()})}function y(){return I===O.leaveRequest.contact_id}function _(){e.isArray(O.leaveRequestStatuses)&&(O.leaveRequestStatuses=e.indexBy(O.leaveRequestStatuses,"value")),e.isArray(O.absenceTypes)&&(O.absenceTypes=e.indexBy(O.absenceTypes,"id"))}function q(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 O.leaveRequest[e]().then(function(){D(e)}).catch(function(e){d.error("Error:",e)})}}}function C(){return m.get().then(function(e){I=e.contactId})}function T(e,t){e.stopPropagation(),r.openModal(t)}function A(e){r.openModal({leaveRequest:O.leaveRequest,leaveType:O.leaveRequest.request_type,selectedContactId:O.leaveRequest.contact_id,forceRecalculateBalanceChange:!0,defaultStatus:l.statusNames[$[e]]})}function D(t){var n=e.find(O.leaveRequestStatuses,function(e){return e.name===l.statusNames.awaitingApproval}).value;L===n&&u.publish("ManagerBadge:: Update Count"),u.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:O.leaveRequest})}function R(){var t=O.leaveRequestStatuses[O.leaveRequest.status_id].name,n=e.compact(e.map(w,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!h(t)&&e.pull(n,"cancel"),"admin"!==O.role&&e.pull(n,"delete"),"staff"===O.role&&e.pull(n,"approve","reject"),"staff"!==O.role&&S(n),v()&&n.push("delete"),O.allowedActions=e.map(n,function(e){return{key:e,label:w[e].label,isDirectAction:w[e].isDirectAction}})}function P(){return b().then(function(e){e&&(O.role="admin")})}function S(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 I,L,O=this,M=l.statusNames,w={edit:{label:"Edit",allowedStatuses:[M.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[M.moreInformationRequired]},view:{label:"View",allowedStatuses:[M.approved,M.rejected,M.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[M.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[M.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[M.awaitingApproval,M.approved,M.rejected,M.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[M.awaitingApproval,M.moreInformationRequired,M.approved,M.rejected,M.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}},$={approve:"approved"};O.allowedActions=[],O.loading={component:!0},O.$onInit=f,O.action=p,O.openLeavePopup=T}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","$q","$rootScope","Contact","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService","Session"]}),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,i,r,c){function u(){o.$emit("LeaveRequestPopup::addTab",C),y(),_()}function l(){C.request.comments.push({contact_id:q,leave_request_id:C.request.id,text:C.comment.text}),C.comment.text=""}function d(){return C.comment.text.length>0}function m(e){return!e.comment_id||C.canManage}function f(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function p(){return C.request.comments.filter(function(e){return!e.toBeDeleted})}function v(e){return e===q?"Me":C.comment.contacts[e]?C.comment.contacts[e].display_name:void 0}function h(e){return C.mode===e}function g(){C.comment.text.length&&C.addComment()}function b(){var t=e.indexBy(C.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){C.comment.contacts=e.indexBy(t.list,"contact_id")})}function y(){return C.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),C.request.comments.length&&b()})}function _(){return C.loading.component=!0,c.get().then(function(e){q=e.contactId}).then(function(){C.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var q=null,C=this;C.loading={component:!0},C.comment={text:"",contacts:{}},C.$onInit=u,C.addComment=l,C.canRemoveComment=m,C.canSubmit=d,C.formatDateTime=f,C.getActiveComments=p,C.getCommentorName=v,C.isMode=h,C.onBeforeSubmit=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/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,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).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,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).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,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(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,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.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,o,s,i,r,c,u,l,d,m){function f(){n("RequestModalDetails"+e.capitalize(T(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(),k()])}).then(!ne.isMode("create")&&S).then(Y).then(function(){if(!ne.isMode("create"))return i.resolve().then(ne.initTimesExtended).then(z)}).then(!ne.isMode("create")&&W).then(L).then(G).then(P).then(O).then(!ne.isMode("view")&&ne.initWatchersExtended).catch(R).then(function(){ne.pagination.filteredbreakdown=ne.balance.change.breakdown,ne.pagination.totalItems=ne.balance.change.breakdown.length}).finally(function(){ne.loading.tab=!1})}function p(){ne.balance.closing=ne.balance.opening+ne.balance.change.amount}function v(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function g(e){var t;return i.resolve().then(function(){j(e),"from"===e&&U(),M("hours")&&(_(e),"from"!==e||ne.uiOptions.multipleDays||_("to")),ne.loading[e+"DayTypes"]=!0}).then(function(){return C(e)}).then(function(e){if(t=e.id!==ne.period.id,t&&(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(t)return x()}).then(function(){return ne.onDateChangeExtended&&ne.onDateChangeExtended(e)}).then(function(){if(z(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(R).finally(q)}function b(){return z(),E()}function y(){return ne.uiOptions.toDate=null,j("to"),i.resolve().then(z).then(ne.setDaysSelectionModeExtended).then(q).then(!ne.uiOptions.multipleDays&&E)}function _(e){ne.uiOptions.times[e].loading=!0}function q(){["from","to"].forEach(function(e){ne.loading[e+"DayTypes"]=!1,M("hours")&&(ne.uiOptions.times[e].loading=!1)})}function C(n){var a=t(ne.uiOptions[n+"Date"]).format(ne.uiOptions.userDateFormat.toUpperCase());return e.find(ne.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function T(){return ne.request?ne.request.request_type:ne.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return X(),ne.loading.balanceChange=!0,ne.request.getBalanceChangeBreakdown().then(H).catch(R)}function R(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),ne.loading.fromDayTypes=!1,ne.loading.balanceChange=!1,ne.loading.tab=!1,ne.loading.toDayTypes=!1}function P(){return ne.isMode("create")||ne.forceRecalculateBalanceChange?E():D()}function S(){var e=ne.request.attributes();return ne.uiOptions.fromDate=v(ne.request.from_date),ne.request.to_date=e.to_date,ne.request.to_date_type=e.to_date_type,ne.uiOptions.toDate=v(ne.request.to_date),ne.initDayTypesExtended?ne.initDayTypesExtended():i.resolve()}function I(){te.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){K(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function L(){ne.isMode("edit")&&(ne.isLeaveStatus(c.statusNames.approved)||ne.isLeaveStatus(c.statusNames.adminApproved))&&(ee={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,t){e!==t&&(ne.uiOptions.multipleDays||(Z(e),z()))})}function M(e){return ne.selectedAbsenceType.calculation_unit_name===e}function w(e){return ne.request.request_type===e}function $(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function k(){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 B(){var e=(ne.pagination.currentPage-1)*ne.pagination.numPerPage,t=e+ne.pagination.numPerPage;ne.pagination.filteredbreakdown=ne.balance.change.breakdown.slice(e,t)}function E(){return X(),ne.canCalculateChange()?(ne.loading.balanceChange=!0,ne.request.change_balance=!0,ne.calculateBalanceChange().then(H).catch(R).finally(function(){ne.loading.balanceChange=!1})):i.resolve()}function F(){ne.pagination.totalItems=ne.balance.change.breakdown.length,ne.pagination.filteredbreakdown=ne.balance.change.breakdown,ne.pagination.pageChanged()}function N(){return h(ne.request.from_date)===h(ne.request.to_date)}function U(){ne.uiOptions.toDate&&ne.uiOptions.fromDate&&ne.uiOptions.multipleDays&&t(ne.uiOptions.toDate).isSameOrBefore(ne.uiOptions.fromDate)&&(ne.uiOptions.toDate=null,j("to"))}function j(e){ne.resetUIInputsExtended&&ne.resetUIInputsExtended(e),z(),X()}function H(e){ne.balance.change=e,ne.request.balance_change=e.amount,p(),F(),ne.loading.balanceChange=!1}function W(){var e,n,a;ne.uiOptions.fromDate?(e=t(ne.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=v(ne.period.start_date),n=ne.uiOptions.date.to.options.minDate),ne.uiOptions.date.to.options.initDate=n,ne.uiOptions.date.to.options.minDate=a,ne.uiOptions.date.to.options.maxDate=v(ne.period.end_date)}function Y(){return!ne.isMode("create")&&N()||ne.isMode("create")&&(w("sickness")||M("hours"))?ne.uiOptions.multipleDays=!1:ne.uiOptions.multipleDays=!0,i.resolve().then(ne.setDaysSelectionModeExtended)}function G(){ee&&ee.absenceTypeId===ne.selectedAbsenceType.id?ne.balance.opening=ee.value||0:ne.balance.opening=ne.selectedAbsenceType.remainder}function V(){ne.selectedAbsenceType=e.find(ne.absenceTypes,function(e){return e.id===ne.request.type_id})}function z(){var e=ne.uiOptions,t=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),(M("hours")||w("toil"))&&(ne.request.from_date=ne.request.from_date&&t.from.time?ne.request.from_date+" "+t.from.time:null,ne.request.to_date=ne.request.to_date&&t.to.time?ne.request.to_date+" "+t.to.time:null)}function X(){ne.uiOptions.showBalance=ne.canCalculateChange()}function Q(){e.forEach(te,function(e){e()})}function J(){var e,t=ne.selectedAbsenceType.calculation_unit_name;return V(),e=t!==ne.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&Y).then(e&&ne.onAbsenceTypeUpdateExtended).then(e&&z).then(q).then(E)}function K(e){return ne.absenceTypes=e,V(),t(ne.uiOptions.toDate).isAfter(ne.period.end_date)&&(ne.uiOptions.toDate=void 0,j("to")),G(),E()}function Z(e){var t=A(e).add(ne.uiOptions.time_interval,"minutes");t.isAfter(A(ne.uiOptions.times.to.max))||(ne.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(ne.uiOptions.times.to.time))&&(ne.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var ee=null,te=[],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:[],numPerPage:7,totalItems:0,pageChanged:B},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.$onInit=f,ne.convertDateFormatFromServer=v,ne.convertDateToServerFormat=h,ne.dateChangeHandler=g,ne.dateTypeChangeHandler=b,ne.daysSelectionModeChangeHandler=y,ne.disableAndShowLoadingTimeInput=_,ne.getMomentDateWithGivenTime=A,ne.handleError=R,ne.isCalculationUnit=M,ne.isLeaveType=w,ne.isNotWorkingDay=$,ne.performBalanceChangeCalculation=E,ne.setRequestDateTimesAndDateTypes=z,ne.updateEndTimeInputMinTime=Z,ne.$onDestroy=Q}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,o,s,i,r,c,u,l){function d(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),y(),a.all([A(),C()]).then(_).finally(function(){O.filesLoaded=!0})}function m(){return O.fileUploader&&O.fileUploader.queue.length>0}function f(){return O.getFilesAmount()0?S.map(function(e){return e.label}).join(", "):""}function C(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function T(){return a.all(S.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){L[e.label]=t})})).catch(function(){L=null})}function A(){return c.valuesOf("safe_file_extension").then(function(e){S=e})}function D(e){return!e.attachment_id||O.canManage}function R(){e.forEach(I,function(e){e()})}function P(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var S=[],I=[],L={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=R,O.$onInit=d,O.canRemoveAttachment=D,O.canSubmit=m,O.canUploadMore=f,O.formatDateTime=p,O.getAuthorName=v,O.getFilesAmount=h,O.listFileTypes=q,O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(){s=n.parse(),s.openModal&&o({leaveType:s.openModal,selectedContactId:i.selectedContactId})}function o(e){t.openModal(e)}e.debug("Component: leave-request-record-actions");var s,i=this;i.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],i.$onInit=a,i.openLeavePopup=o}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,o,s,i,r,c,u,l,d,m){"use strict";function f(){s(r.permissions.admin.administer).then(function(e){H.isAdmin=e,n.all([A(),D(),M(),P(),L(),I(),w()]).then(function(){H.loading.page=!1,R()}),U()})}function p(){H.filters.leaveRequest.contact_id=null,H.refresh()}function v(){var e=H.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?H.leaveRequests.filter.list.length:H.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function g(t){return e.find(H.absenceTypes,{id:t})}function b(e){return new Array(e||0)}function y(t){var n=e.find(H.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function _(e){switch(e){case r.statusNames.approved:return"badge-success";case r.statusNames.rejected:return"badge-danger";case r.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function q(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}function C(t){var n=e.find(H.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function T(e){return e.current?"Current Period ("+e.title+")":e.title}function A(){return c.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.filters.leaveRequest.selectedPeriod=e.find(H.absencePeriods,function(e){return!!e.current})})}function D(){return u.all().then(u.loadCalculationUnits).then(function(e){H.absenceTypes=e})}function R(e){return(H.isAdmin?o.all(v()):o.leaveManagees(H.contactId,v())).then(function(t){return H.filteredUsers=H.isAdmin?t.list:t,e?S(e):n.all([S("table"),S("filter")])}).then(function(){H.filters.leaveRequest.leaveStatus!==W&&0===H.leaveRequests.table.list.length&&H.refresh(1,!0)})}function P(){return i.valuesOf("hrjc_department").then(function(e){H.departments=e})}function S(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:H.pagination,o="filter"===e?{return:["status_id"]}:{};return H.loading[n]=!0,l.all(O(t),a,"from_date DESC",o,!1).then(function(t){H.leaveRequests[e]=t}).catch(function(){H.leaveRequests[e].list=[]}).finally(function(){H.loading[n]=!1})}function I(){return i.valuesOf("hrjc_level_type").then(function(e){H.levelTypes=e})}function L(){return i.valuesOf("hrjc_location").then(function(e){H.locations=e})}function O(t){var n=H.filters.leaveRequest;return{contact_id:k(),managed_by:H.isAdmin&&"me"!==n.assignedTo.type?void 0:H.contactId,status_id:B(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(H.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function M(){return i.valuesOf("hrjc_region").then(function(e){H.regions=e})}function w(){return i.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){H.leaveRequestStatuses=e.concat(H.leaveRequestStatuses)})}function $(e){d.openModal(e)}function k(){return H.filteredUsers.length>0&&H.filters.leaveRequest.contact_id?H.filters.leaveRequest.contact_id:{IN:H.filteredUsers.map(function(e){return e.id})}}function x(e){var t=[q(r.statusNames.moreInformationRequired),q(r.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function B(e){var t=H.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=x(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(H.filters.leaveRequest.leaveStatus=W),(e<=H.totalNoOfPages()||0===H.totalNoOfPages())&&(H.pagination.page=e,R(n))}function F(e){H.filters.leaveRequest.leaveStatus=e,H.refresh(1,!1,"table")}function N(e){H.filters.leaveRequest.assignedTo=e,H.refresh()}function U(){m.subscribe("LeaveRequest::updatedByManager",function(){H.refresh()}),m.subscribe("LeaveRequest::new",function(){H.refresh()}),m.subscribe("LeaveRequest::edit",function(){H.refresh()}),m.subscribe("LeaveRequest::delete",function(){H.refresh()}),m.subscribe("LeaveRequest::statusUpdate",function(){H.refresh()})}function j(){return Math.ceil(H.leaveRequests.table.total/H.pagination.size)}t.debug("Component: manage-leave-requests");var H=this,W={name:"all",label:"All"};H.absencePeriods=[],H.absenceTypes=[],H.filteredUsers=[],H.isFilterExpanded=!1,H.isAdmin=!1,H.leaveRequests={table:{list:[]},filter:{list:[]}},H.leaveRequestStatuses=[W],H.loading={content:!0,page:!0,table:!0},H.pagination={page:1,size:7},H.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],H.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:H.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:H.filtersByAssignee[0]}},H.$onInit=f,H.clearStaffSelection=p,H.countLeaveRequestByStatus=h,H.getAbsenceTypeByID=g,H.getArrayOfSize=b,H.getLeaveStatusByValue=y,H.getNavBadge=_,H.getUserNameByID=C,H.labelPeriod=T,H.openLeavePopup=$,H.refresh=E,H.refreshWithFilter=F,H.refreshWithFilterByAssignee=N,H.totalNoOfPages=j}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function d(){return i.canCalculateChange()}function m(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.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}function f(t,n){return t?(t=i.convertDateToServerFormat(t),h(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return S(n,e),e})):o.reject([])}function p(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.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 v(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function g(){return o.resolve()}function b(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function y(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),O(),i.performBalanceChangeCalculation())})}function _(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(v(a.min,n)<=0||v(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(R)).then(function(){["from","to"].forEach(function(e){_(e),L(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(O)}function C(){["from","to"].forEach(function(e){y(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&L(e,!0))})}function A(e,t){return f(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return R(e).then(function(){L(e,!0)})})}function R(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){w[e]=t,m(e,t),n&&"from"===e&&m("to",t)}).catch(function(t){return w[e]={},i.handleError(t)}).finally(function(){i.uiOptions.times[e].loading=!1,n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function S(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function I(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),R("from").then(function(){L("from",!0)})):o.resolve()}function L(e,t){var n=i.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,c=w[a].number_of_hours?v(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function O(){var e=i.uiOptions.times -;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function M(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?R("from").then(function(){L("from",!0)}):o.resolve()}var w={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=g,i.initDayTypesExtended=b,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=M,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=I}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),v(),f(!0)])}function l(t){var n=r.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function d(t){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===t})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(t){return i.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){r.sicknessReasons=e.indexBy(t,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function v(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=U.from_date!==c.request.from_date||U.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function v(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function h(){var e=c.uiOptions.multipleDays,t=c.request;return g({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function g(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function b(){var e=c.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function y(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",_().then(b).then(C).then(S)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&c.isCalculationUnit("hours")&&M(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),F(),l(),w())})})}function P(){c.isMode("view")||(T(),A(),R())}function S(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function I(){return l(),w(),F()}function L(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:w(),F()}function O(e){c.uiOptions.times[e].time=""}function M(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function w(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function $(){U=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),w(),c.isCalculationUnit("hours")?M():c.request.toil_to_accrue=null}function B(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){S(!1)})}function E(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function N(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,j=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=v,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=I,c.openToilInDaysAccrualOptionsEditor=B,c.resetUIInputsExtended=O,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=N,function(){$(),k(),E(),!c.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,t,n){"use strict";function a(n,a,o,s){function i(n){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var t=e.get(n,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return n.lookupContacts=e,a.all([d(),"me"!==t?u():a.resolve(null)])}).then(function(e){var t=e[0];return n.contactIdsToReduceTo=e[1],t})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return t(a.period_start_date).isSameOrBefore(n.selectedPeriod.end_date)&&(t(a.period_end_date).isSameOrAfter(n.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return h?a.resolve(h):s.all()}function d(){return o.all(v(),null,"display_name").then(function(e){return e.list})}function m(){var t=e.get(n,"filters.userSettings.assignedTo.type","all");return(0,g[t])()}function f(){return m().then(function(e){n.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(n.contactId)}function v(){var t={department:e.get(n,"filters.userSettings.department.value",null),level_type:e.get(n,"filters.userSettings.level_type.value",null),location:e.get(n,"filters.userSettings.location.value",null),region:e.get(n,"filters.userSettings.region.value",null)},a=!!n.filters.userSettings.contact,o=e.isArray(n.lookupContacts)&&n.lookupContacts.length,s="all"!==e.get(n,"filters.userSettings.assignedTo.type","all");return a?t.id={IN:[n.filters.userSettings.contact.id]}:(s||o)&&(t.id={IN:e.pluck(n.lookupContacts,"id")}),t}var h,g={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return n.debug("LeaveCalendarService"),{init:i}}n.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(n){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return n.contact_id&&n.period_id||o.reject("contact_id and period_id are mandatory"),n=t.defaults(n,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",n,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){return e.debug("LeaveRequestAPI.update",t),t.id?this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([h.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return n.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,v,h,g,b,y,_,q,C){function T(e){"days"===Ne.selectedAbsenceType.calculation_unit_name?delete Ne.request[e+"_date_amount"]:delete Ne.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return Me.checkIfSelfLeaveApprover().then(function(e){e&&(Ee="admin")})}function R(){var e=Ne.requestStatuses[y.statusNames.awaitingApproval].value;ke.status_id===e&&e!==Ne.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!Ne.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ne.isMode("edit")&&(e=e&&(G()||S())),Ne.canManage&&Ne.requestStatuses&&(e=e&&!!Ne.getStatusFromValue(Ne.newStatusOnSave)),(e=e&&!!Ne.period.id)&&!Ne.isMode("view")}function O(){Ne.isSelfRecord&&!Ne.isSelfLeaveApprover?Ne.request.status_id=Ne.requestStatuses[y.statusNames.awaitingApproval].value:Ne.canManage&&(Ne.request.status_id=Ne.newStatusOnSave||Ne.request.status_id)}function M(){if(Ne.isMode("edit")&&!Ne.isRole("staff")&&"toil"!==j())return Ne.request.calculateBalanceChange(Ne.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ne.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function w(){return"toil"!==j()&&!Ne.request.change_balance}function $(){Ne.errors=[]}function k(){return Ne.request.create().then(Pe).then(function(){be("LeaveRequest::new")})}function x(){se()&&!Ne.isRole("staff")&&(Ne.request.change_balance=!0)}function B(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ne.request.delete().then(function(){Ne.dismissModal(),d.publish("LeaveRequest::delete",Ne.request)})}})}function E(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return U(Ne.getStatusFromValue(Ne.request.status_id).name)}function U(e){return n.map(we[e],function(e){return Ne.requestStatuses[e]})}function j(){return Ne.request?Ne.request.request_type:Ne.leaveType||null}function H(){return!Ne.request||e.equals({},Ne.requestStatuses)?[]:Ne.request.status_id?N():U("none")}function W(e){return n.find(Ne.requestStatuses,function(t){return t.value===e})}function Y(e){Ne.errors=n.isArray(e)?e:[e],Ne.loading.absenceTypes=!1,Ne.submitting=!1}function G(){return!e.equals(ke,Ne.request.attributes())||Ne.canManage&&Ne.newStatusOnSave}function V(){return Ne.postContactSelection=!0,Ne.staffMemberSelectionComplete=!1,Ne.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ne.isMode("edit")?Te:n.noop).then(function(){Ne.postContactSelection=!1,Ne.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Be)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];we.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],we.awaiting_approval=e,we.more_information_required=e,we.rejected=e,we.approved=e,we.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ne.canManage=Ne.isRole("manager")||Ne.isRole("admin")}function Q(){return Ne.canManage?f.find(Ne.request.contact_id).then(function(e){Ne.contactName=e.display_name}):o.resolve()}function J(){Ne.isRole("admin")&&Ne.isSelfRecord&&(Ne.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,t=+Me.id==+n.get(Ne,"leaveRequest.contact_id"),a=!n.get(Ne,"leaveRequest.id");Ne.isSelfRecord=e&&a||t}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ne.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){Y(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){$e++})),i.$on("$destroy",Se),i.$on("LeaveRequestPopup::addTab",function(e,t){Fe.push(t)})}function ee(){var e,t;Ne.request=Ne.leaveRequest||null,e=j(),t=Ne.initRequestAttributes(),"leave"===e?Ne.request=b.init(t):"sickness"===e?Ne.request=_.init(t):"toil"===e&&(Ne.request=q.init(t))}function te(){var e={};return Ne.request?e=Ne.request.attributes():Ne.canManage||(e={contact_id:Me.id}),e}function ne(){return Ee="staff",ae().then(Ne.isSelfRecord&&!Ne.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Ee="admin")}).then(function(){return"admin"!==Ee&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Ee="manager")})}function oe(){Ne.defaultStatus?Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames[Ne.defaultStatus]].value:(Ne.isRole("admin")||Ne.isMode("create")&&Ne.isRole("manager"))&&(Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames.approved].value)}function se(){return!Ne.request.status_id||!n.includes(["cancelled","rejected"],W(Ne.request.status_id).name)}function ie(e){var t=Ne.getStatusFromValue(Ne.request.status_id);return!!t&&t.name===e}function re(e){return Ne.request&&Ne.request.request_type===e}function ce(e){return Ne.mode===e}function ue(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date,"day")&&o.isSameOrBefore(t.end_date,"day")}function le(e){return Ee===e}function de(){return p.all().then(function(e){Ne.absencePeriods=e})}function me(){return v.all(F()).then(v.loadCalculationUnits).then(function(e){Oe={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ne.loading.entitlements=!0,h.all({contact_id:Ne.request.contact_id,period_id:Ne.period.id,type_id:{IN:Oe.ids}},!0).finally(function(){Ne.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){Me=e})}function ve(){return Ne.selectedContactId?f.find(Ne.selectedContactId).then(function(e){Ne.managedContacts=[e]}):Ne.isRole("admin")?f.all().then(function(e){console.log(e.list),Ne.managedContacts=e.list}):Me.leaveManagees().then(function(e){Ne.managedContacts=e})}function he(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ne.requestStatuses=n.indexBy(e,"name")})}function ge(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function be(e){R(),d.publish(e,Ne.request),Ne.errors=[],Ne.dismissModal()}function ye(){["from","to"].forEach(function(e){Ne.request[e+"_date"]=ke[e+"_date"]})}function _e(e){if(Ne.absenceTypes=ge(Oe.types,e),!Ne.absenceTypes.length)return o.reject(Be)}function qe(){Ne.period=n.find(Ne.absencePeriods,function(e){return Ne.isMode("create")?e.current:ue(Ne.request,e)})}function Ce(){Ne.isMode("create")?(Ne.selectedAbsenceType=Ne.absenceTypes[0],Ne.request.type_id=Ne.selectedAbsenceType.id):Ne.selectedAbsenceType=n.find(Ne.absenceTypes,function(e){return e.id===Ne.request.type_id})}function Te(){ke=e.copy(Ne.request.attributes())}function Ae(){var e;Ne.request.id?(e=[Ne.requestStatuses[y.statusNames.approved].value,Ne.requestStatuses[y.statusNames.adminApproved].value,Ne.requestStatuses[y.statusNames.rejected].value,Ne.requestStatuses[y.statusNames.cancelled].value],Ne.mode="edit",Ne.isRole("staff")&&e.indexOf(Ne.request.status_id)>-1&&(Ne.mode="view")):Ne.mode="create"}function De(){var e=Ne.request.status_id;if(!Ne.isMode("view")&&!Ne.submitting)return Ne.submitting=!0,O(),A(),Ne.request.isValid().then(se()&&M).then(x).then(w()&&ye).then(Re).then(function(){return Ne.isMode("edit")?Le():k()}).catch(function(t){ -Ne.request.status_id=e,t&&Y(t)}).finally(function(){Ne.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&n.push(e),++a===$e&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return $e>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Se(){xe.forEach(function(e){e()})}function Ie(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ne.request.update().then(Pe).then(function(){Ne.isRole("manager")?be("LeaveRequest::updatedByManager"):(Ne.isRole("staff")||Ne.isRole("admin"))&&be("LeaveRequest::edit")})}t.debug("RequestCtrl");var Oe,Me,we={},$e=0,ke={},xe=[],Be="No entitlement",Ee="",Fe=[],Ne=n.assign(this,m);Ne.absencePeriods=[],Ne.absenceTypes=[],Ne.canManage=!1,Ne.contactName=null,Ne.errors=[],Ne.isSelfLeaveApprover=!1,Ne.loading={absenceTypes:!0,entitlements:!0},Ne.managedContacts=[],Ne.mode="",Ne.newStatusOnSave=null,Ne.period={},Ne.postContactSelection=!1,Ne.requestStatuses={},Ne.selectedAbsenceType={},Ne.staffMemberSelectionComplete=!1,Ne.submitting=!1,Ne.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ne.canChangeAbsenceType=I,Ne.canSubmit=L,Ne.closeAlert=$,Ne.deleteLeaveRequest=B,Ne.dismissModal=E,Ne.getStatuses=H,Ne.getStatusFromValue=W,Ne.initAfterContactSelection=V,Ne.initRequestAttributes=te,Ne.isLeaveStatus=ie,Ne.isLeaveType=re,Ne.isMode=ce,Ne.isRole=le,Ne.submit=De,Ne.updateAbsenceType=Ie,function(){Ne.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([ne(),de(),he()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ne.canManage&&!Ne.isMode("edit")&&ve()}).then(function(){if(Ne.selectedContactId&&(Ne.request.contact_id=Ne.selectedContactId),Ne.request.contact_id)return Ne.initAfterContactSelection()}).catch(Y).finally(function(){Ne.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(o.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var o=this;o.tabName=n.current.name,o.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e,t){define("leave-absences/manager-leave/modules/config",["common/angular","common/lodash","leave-absences/manager-leave/modules/settings"],function(t,n){function a(t){t.withAutoBase(!0),t.settings.ga={userId:n.get(e,"vars.session.contact_id")}}return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","$analyticsProvider","settings",function(t,n,o,s,i,r,c){s.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.defaults.stripTrailingSlashes=!1,o.otherwise("/manager-leave/requests"),a(r),i.debugEnabled(c.debug),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM,Drupal),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/angulartics","common/angulartics-google-tag-manager","common/angularUiRouter","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","angulartics","angulartics.google.tagmanager","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); +!function(e){define("leave-absences/shared/config",[],function(){e.config({paths:{mocks:"../test/mocks"}}),e.config({paths:{mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(t){return t.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",sourcePath:e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,n,a){return e.debug("AbsencePeriodInstance"),n.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var n=t();return e.current=!1,t(e.start_date).isSameOrBefore(n,"day")&&t(e.end_date).isSameOrAfter(n,"day")&&(e.current=!0),e},isInPeriod:function(e){var n=a.DATE_FORMAT.toUpperCase(),o=t(e,n);return t(this.start_date).isSameOrBefore(o)&&t(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,t){return e.debug("AbsencePeriodAPI"),t.extend({all:function(t){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,t){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,n,a,o,s){return e.debug("AbsencePeriod"),n.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=t().format(s.serverDateFormat),n={start_date:{"<=":e},end_date:{">=":e}};return a.all(n).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,t,n){"use strict";n.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(n,a,o){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(t||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,t){return e.debug("AbsenceTypeInstance"),t.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,t){"use strict";t.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(t,n,a,o,s,i){return t.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,t,n){return s.calculateToilExpiryDate(e,t,n)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(t){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(n){return n=e.indexBy(n,"value"),e.map(t,function(t){return e.assign(t,{calculation_unit_label:n[t.calculation_unit].label,calculation_unit_name:n[t.calculation_unit].name})})})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/components/leave-balance-tab-filters.component",["common/lodash","common/moment","leave-absences/shared/modules/components"],function(e,t,n){function a(n){function a(e){e.absencePeriods&&u.absencePeriods.length&&(u.filters.period_id=s().id),e.absenceTypes&&u.absenceTypes.length&&(u.filters.type_id=i().id),(e.loggedInContactId||e.userRole)&&(u.filters.managed_by="manager"===u.userRole?u.loggedInContactId:void 0),o()&&u.submitFilters()}function o(){return e.every(u.filters,function(e){return null!==e})}function s(){return e.find(u.absencePeriods,function(e){return e.current})||u.absencePeriods.reduce(function(e,n){return t(e.end_date).isAfter(n.end_date)?e:n})}function i(){return u.absenceTypes.reduce(function(e,t){return e.title.localeCompare(t.title)?e:t})}function r(e){return e.current?"Current Period ("+e.title+")":e.title}function c(){n.$emit("LeaveBalanceFilters::update",u.filters)}var u=this;u.filters={period_id:null,type_id:null,managed_by:null},u.$onChanges=a,u.labelPeriod=r,u.submitFilters=c}n.component("leaveBalanceTabFilters",{controller:a,controllerAs:"balanceFilters",bindings:{absencePeriods:"<",absenceTypes:"<",loggedInContactId:"<",lookupContacts:"<",userRole:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab-filters.html"}]}),a.$inject=["$scope"]}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,n){function a(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(n.remainder=a[0].remainder),delete n["api.LeavePeriodEntitlement.getremainder"],n}function o(e){var n=t.clone(e),a=n["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return n.value=a,delete n["api.LeavePeriodEntitlement.getentitlement"],n}return e.debug("EntitlementAPI"),n.extend({all:function(t,n){return e.debug("EntitlementAPI.all"),t["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},n&&(t["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",t,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),n&&(e=e.map(a)),e})},breakdown:function(t){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",t).then(function(e){return e.values})},getLeaveBalances:function(t,n,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",t,n,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/entitlement.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","EntitlementAPI",function(e,t){return e.extend({all:function(e,n,a,o,s){return t.getLeaveBalances(this.processFilters(e),n,a,o,s)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/components/leave-balance-tab-filters.component","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service","common/services/pub-sub"],function(e,t,n){function a(n,a,o,s,i,r,c,u,l,d,m){function f(){q(),b().then(function(){P.loading.component=!1})}function p(){return o.all({options:{sort:"title ASC"}}).then(function(e){P.absencePeriods=e})}function v(){return s.all().then(s.loadCalculationUnits).then(function(e){P.absenceTypes=e})}function h(){return i.all(null,null,"sort_name ASC").then(function(e){P.lookupContacts=e.list})}function b(){return n.all([p(),v(),h(),g(),C()]).catch(function(e){c.error("Error",e)})}function g(){return l.get().then(function(e){P.loggedInContactId=e.contactId})}function y(){return P.loading.report=!0,r.all(R,P.pagination,void 0,void 0,!1).then(function(e){P.report=_(e.list),P.reportCount=e.total}).catch(function(e){c.error("Error",e.error_message)}).finally(function(){P.loading.report=!1})}function _(n){return n.map(function(n){return n=e.copy(n),n.absence_types=t.indexBy(n.absence_types,function(e){return e.id}),n})}function q(){a.$on("LeaveBalanceFilters::update",A),u.subscribe("LeaveRequest::new",T)}function C(){return m(d.permissions.admin.administer).then(function(e){P.userRole=e?"admin":"manager"})}function T(e){A(e,R)}function A(e,t){R=t,P.pagination.page=1,D(),P.loadReportCurrentPage()}function D(){P.selectedAbsenceTypes=P.absenceTypes.filter(function(e){return+e.id==+R.type_id})}var R={},P=this;P.absencePeriods=[],P.absenceTypes=[],P.loading={component:!0,report:!0},P.loggedInContactId=null,P.lookupContacts=[],P.pagination={page:1,size:50},P.report=[],P.reportCount=0,P.userRole=null,P.$onInit=f,P.loadReportCurrentPage=y}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","$rootScope","AbsencePeriod","AbsenceType","Contact","LeaveBalanceReport","notificationService","pubSub","Session","shared-settings","checkPermissions"]}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,t,n){function a(t,n,a,o,s,i,r){function c(){return{loadContacts:function(){return l.loadContactsForAdmin()}}}function u(e){i.info("",["

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 l,d;return{init:function(t){return d=t,l=r.init(d),d.filters.userSettings.assignedTo=e.find(d.filtersByAssignee,{type:"me"}),d.showContactDetailsLink=!0,d.showContactName=!0,d.showFilters=!0,d.showAdminFilteringHint=u,c()}}}n.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService","LeaveCalendarService",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(t,n,a,o){function s(){return{loadContacts:function(){return i.loadLookUpAndFilteredContacts()}}}t.debug("LeaveCalendarManagerController");var i,r;return{init:function(t){return r=t,i=o.init(r),r.filters.userSettings.assignedTo=e.find(r.filtersByAssignee,{type:"me"}),r.showContactName=!0,r.showFilters=!0,s()}}}n.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance","LeaveCalendarService",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,n,a){function o(){return{loadContacts:function(){return i.displaySingleContact?s.loadFilteredContacts():"admin"===i.userPermissionRole?s.loadContactsForAdmin():s.loadLookUpAndFilteredContacts()}}}e.debug("LeaveCalendarStaffController");var s,i;return{init:function(e){return i=e,s=a.init(i),i.filters.userSettings.contacts_with_leaves=!0,i.showTheseContacts=[i.contactId],i.showContactName=!0,i.showFilters=!0,i.displaySingleContact&&(i.showFilters=!1,i.lookupContacts=[{id:i.contactId}]),o()}}}n.controller("LeaveCalendarStaffController",["$log","$q","Contact","LeaveCalendarService",a])}),define("leave-absences/shared/components/leave-calendar.component",["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){function a(n,a,o,s,i,r,c,u,l,d){function m(){N().then(g).then(b).then(_).then(I).then(function(){return a.all([C(),D(),S(),W.showFilters?R():e.noop])}).then(function(){f(),y(),E()}).then(function(){W.loading.page=!1})}function f(){W.supportData.absenceTypes.push({id:"",title:"Leave",color:"#4D4D68",calculation_unit:e.chain(W.supportData.calculationUnits).find({name:"days"}).get("value").value()})}function p(){for(var e=[],n=t(W.selectedPeriod.start_date).clone().startOf("month"),a=t(W.selectedPeriod.end_date).clone().endOf("month");n.isBefore(a);)e.push(L(n)),n.add(1,"month");W.months=e}function v(){return e.includes(["admin","manager"],W.userPermissionRole)}function h(e){return e.format("YYYY-MM")}function b(){s.$on("LeaveCalendar::updateFiltersByAbsenceType",function(e,t){W.supportData.absenceTypesToFilterBy=t,$(!0)})}function g(){s.$new().$watch(function(){return W.selectedMonthIndex},function(e,t){null!==t&&e!==t&&(F(),E(),$())})}function y(e){W.injectMonth=!0,U("injected").then(function(){$(e)}).then(function(){W.loading.calendar=!1})}function _(){j=n("LeaveCalendar"+e.capitalize(H)+"Controller").init(W)}function q(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return r.all().then(function(t){W.absencePeriods=e.sortBy(t,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current})}).then(p).then(k)}function T(){return c.all().then(c.loadCalculationUnits)}function A(){return l.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function D(){return j.loadContacts().then(function(e){W.contacts=e})}function R(){return l.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){W.filters.optionValues.regions=e.hrjc_region,W.filters.optionValues.locations=e.hrjc_location,W.filters.optionValues.levelTypes=e.hrjc_level_type,W.filters.optionValues.departments=e.hrjc_department})}function P(){return u.all()}function S(){return a.all([T(),P(),A()]).then(function(t){W.supportData.absenceTypes=t[0],W.supportData.publicHolidays=t[1],W.supportData.calculationUnits=t[2].hrleaveandabsences_absence_type_calculation_unit,W.supportData.dayTypes=t[2].hrleaveandabsences_leave_request_day_type,W.supportData.leaveRequestStatuses=t[2].hrleaveandabsences_leave_request_status,W.supportData.toilAmounts=e.indexBy(t[2].hrleaveandabsences_toil_amounts,"value")})}function I(){var e=a.resolve();return W.injectMonth&&(e=U("destroyed"),W.injectMonth=!1),e}function L(e){return{index:h(e),month:e.month(),year:e.year(),name:e.format("MMMM"),moment:t().year(e.year()).month(e.month())}}function O(){var t=W.selectedPeriod.id;W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current}),t!==W.selectedPeriod.id&&p(),k(),E(),w("month")}function M(e){var n="previous"===e?"subtract":"add";F(t(W.selectedMonth.moment)[n](1,"month")),E(),w("month")}function w(t){t=e.includes(["contacts","period","month"],t)?t:"period",a.resolve().then(I).then("period"===t&&p).then("period"===t&&x).then("contacts"===t&&D).then("month"===t&&E).then(function(){y("contacts"===t)})}function $(e){s.$emit("LeaveCalendar::showMonth",!!e)}function k(){F(t())}function x(){F(W.months[0].moment)}function B(n){var a="previous"===n?"first":"last",o=e[a](W.months),s=t().year(o.year).month(o.month);W.monthPaginatorsAvailability[n]=!W.selectedMonth.moment.isSame(s,"month")}function E(){B("previous"),B("next")}function F(t){t&&(W.selectedMonthIndex=h(t)),W.selectedMonth=e.find(W.months,{index:W.selectedMonthIndex})}function N(){return a.all([d(i.permissions.admin.administer),d(i.permissions.ssp.manage)]).then(function(e){W.userPermissionRole=e[0]?"admin":e[1]?"manager":"staff",H=W.roleOverride?W.roleOverride:W.userPermissionRole})}function U(t){return a(function(n){var a=s.$on("LeaveCalendar::month"+e.capitalize(t),function(){a(),n()})})}o.debug("Component: leave-calendar");var j,H,W=this;W.absencePeriods=[],W.contacts=[],W.contactIdsToReduceTo=null,W.injectMonth=!1,W.months=[],W.selectedMonth={},W.selectedMonthIndex="",W.selectedPeriod=null,W.showContactName=!1,W.showFilters=!1,W.userPermissionRole="staff",W.loading={calendar:!0,page:!0},W.filters={hideOnMobile:!0,optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null},absenceTypes:{}},W.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],W.filters.userSettings.assignedTo=W.filtersByAssignee[2],W.monthPaginatorsAvailability={previous:!0,next:!0},W.supportData={absenceTypesToFilterBy:[]},W.$onInit=m,W.canManageRequests=v,W.labelPeriod=q,W.navigateToCurrentMonth=O,W.paginateMonth=M,W.refresh=w}n.component("leaveCalendar",{bindings:{contactId:"<",displaySingleContact:"0,n={from_date:{to:Q.month.days[Q.month.days.length-1].date+" 23:59:59"},to_date:{from:Q.month.days[0].date+" 00:00:00"},status_id:{IN:M()},contact_id:{IN:Q.contacts.map(function(e){return e.id})},type_id:{IN:t?Q.supportData.absenceTypesToFilterBy:e.pluck(Q.supportData.absenceTypes,"id")}};return y(),i.all(n,null,null,null,!1).then(function(e){return X={},t&&(e.list=q(e.list)),A(e.list)})}function k(){var t=Q.month.days[0].date,n=Q.month.days[Q.month.days.length-1].date;return s.get(Q.contacts.map(function(e){return e.id}),t,n).then(function(t){z=e.indexBy(t,"contact_id")})}function x(){return Q.contactIdsToReduceTo&&(Q.contacts=Q.contacts.filter(function(t){return e.includes(Q.contactIdsToReduceTo,t.contact_id)||e.find(X,function(e){return e.contact_id===t.contact_id})})),a.resolve()}function B(t){var n=L(t);X[t.contact_id]=X[t.contact_id]||{},n.forEach(function(n){e.remove(X[t.contact_id][n.date],function(e){return e.id===t.id})})}function E(){o.$emit("LeaveCalendar::monthDestroyed"),V.map(function(e){e.remove?e.remove():e()})}function F(t,n,o){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=f(n),s=!0===o?a.resolve():a.all([i.isWeekend(v(t.date)),i.isNonWorkingDay(v(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:S(t.date)})}),s.then(function(){return X[n]&&X[n][t.date]?X[n][t.date]:[]}).then(function(a){a=j(a),e.assign(t.contactsData[n],{leaveRequests:a,leaveRequestsToShowInCell:b(a),leaveRequestsAttributes:C(t,a)})})}function N(){return a.all(Q.month.days.map(function(e){return a.all(Q.contacts.map(function(t){return F(e,t.id)}))}))}function U(e,t){Q.currentPage=0,Q.visible=!0,(t||!G)&&w()}function j(n){return e.sortBy(n,function(e){return+t(e.from_date).format("X")+(R("half_day_pm",e,e.from_date)?1:0)})}function H(t){var n=e.find(Q.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 W(e){h(e),-1!==M().indexOf(e.status_id)&&l(e)}function Y(e){return a.all(L(e).map(function(t){return F(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var G=!1,V=[],z={},X={},Q=this;Q.currentPage=0,Q.pageSize=20,Q.visible=!1,Q.showContactName=!!Q.showContactName,Q.showOnlyWithLeaveRequests=!!Q.showOnlyWithLeaveRequests,Q.$onDestroy=E,Q.$onInit=u,Q.contactsList=p,Q.getContactUrl=_}n.component("leaveCalendarMonth",{bindings:{showTheseContacts:"<",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/models/contact","common/models/session.model","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,i,r,c,u,l,d,m){function f(){a.resolve().then(_).then(C).then(function(){return y()&&"admin"!==O.role&&P()}).then(R).finally(function(){O.loading.component=!1})}function p(t){L=O.leaveRequest.status_id,e.includes(["cancel","reject","delete"],t)||"toil"===O.leaveRequest.request_type?i.open(q(t)):b(t)}function v(){return"admin"===O.role&&"public_holiday"===O.leaveRequest.request_type}function h(n){var a=O.absenceTypes[O.leaveRequest.type_id].allow_request_cancelation;return"admin"===O.role||("manager"===O.role?e.includes([M.awaitingApproval,M.moreInformationRequired],n):"3"===a?t().isBefore(O.leaveRequest.from_date):"2"===a)}function b(t){i.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return O.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(n){return n?e.assign(c.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){A(t)}}):q(t)})}})}function g(){return s.find(I).then(function(e){return e.checkIfSelfLeaveApprover()})}function y(){return I===O.leaveRequest.contact_id}function _(){e.isArray(O.leaveRequestStatuses)&&(O.leaveRequestStatuses=e.indexBy(O.leaveRequestStatuses,"value")),e.isArray(O.absenceTypes)&&(O.absenceTypes=e.indexBy(O.absenceTypes,"id"))}function q(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 O.leaveRequest[e]().then(function(){D(e)}).catch(function(e){d.error("Error:",e)})}}}function C(){return m.get().then(function(e){I=e.contactId})}function T(e,t){e.stopPropagation(),r.openModal(t)}function A(e){r.openModal({leaveRequest:O.leaveRequest,leaveType:O.leaveRequest.request_type,selectedContactId:O.leaveRequest.contact_id,forceRecalculateBalanceChange:!0,defaultStatus:l.statusNames[$[e]]})}function D(t){var n=e.find(O.leaveRequestStatuses,function(e){return e.name===l.statusNames.awaitingApproval}).value;L===n&&u.publish("ManagerBadge:: Update Count"),u.publish("LeaveRequest::statusUpdate",{status:t,leaveRequest:O.leaveRequest})}function R(){var t=O.leaveRequestStatuses[O.leaveRequest.status_id].name,n=e.compact(e.map(w,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!h(t)&&e.pull(n,"cancel"),"admin"!==O.role&&e.pull(n,"delete"),"staff"===O.role&&e.pull(n,"approve","reject"),"staff"!==O.role&&S(n),v()&&n.push("delete"),O.allowedActions=e.map(n,function(e){return{key:e,label:w[e].label,isDirectAction:w[e].isDirectAction}})}function P(){return g().then(function(e){e&&(O.role="admin")})}function S(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 I,L,O=this,M=l.statusNames,w={edit:{label:"Edit",allowedStatuses:[M.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[M.moreInformationRequired]},view:{label:"View",allowedStatuses:[M.approved,M.rejected,M.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[M.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[M.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[M.awaitingApproval,M.approved,M.rejected,M.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[M.awaitingApproval,M.moreInformationRequired,M.approved,M.rejected,M.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}},$={approve:"approved"};O.allowedActions=[],O.loading={component:!0},O.$onInit=f,O.action=p,O.openLeavePopup=T}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","$q","$rootScope","Contact","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService","Session"]}),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,i,r,c){function u(){o.$emit("LeaveRequestPopup::addTab",C),y(),_()}function l(){C.request.comments.push({contact_id:q,leave_request_id:C.request.id,text:C.comment.text}),C.comment.text=""}function d(){return C.comment.text.length>0}function m(e){return!e.comment_id||C.canManage}function f(e){return t.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function p(){return C.request.comments.filter(function(e){return!e.toBeDeleted})}function v(e){return e===q?"Me":C.comment.contacts[e]?C.comment.contacts[e].display_name:void 0}function h(e){return C.mode===e}function b(){C.comment.text.length&&C.addComment()}function g(){var t=e.indexBy(C.request.comments,"contact_id"),n=Object.keys(t);return r.all({id:{IN:n}},{page:1,size:0}).then(function(t){C.comment.contacts=e.indexBy(t.list,"contact_id")})}function y(){return C.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),C.request.comments.length&&g()})}function _(){return C.loading.component=!0,c.get().then(function(e){q=e.contactId}).then(function(){C.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var q=null,C=this;C.loading={component:!0},C.comment={text:"",contacts:{}},C.$onInit=u,C.addComment=l,C.canRemoveComment=m,C.canSubmit=d,C.formatDateTime=f,C.getActiveComments=p,C.getCommentorName=v,C.isMode=h,C.onBeforeSubmit=b}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,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:o,change_reason:s})).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,o,s){return t.debug("WorkPatternAPI.getCalendar",n,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,o){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).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,o,s,i){function r(t,n){return u().then(function(a){var o=this.days[c(t).valueOf()];return!!o&&e.find(a,function(e){return e.name===n}).value===o.type}.bind(this))}function c(e){return t(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(t){var n={};return t.calendar.forEach(function(e){n[c(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,o){return t.debug("Calendar"),n.extend({get:function(n,s,i,r){return t.debug("Calendar.get"),a.getCalendar(n,s,i,r).then(function(t){var a=t.values.map(function(e){return o.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,o,s,i,r,c,u,l,d,m){function f(){n("RequestModalDetails"+e.capitalize(T(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(),k()])}).then(!ne.isMode("create")&&S).then(Y).then(function(){if(!ne.isMode("create"))return i.resolve().then(ne.initTimesExtended).then(z)}).then(!ne.isMode("create")&&W).then(L).then(G).then(P).then(O).then(!ne.isMode("view")&&ne.initWatchersExtended).catch(R).then(function(){ne.pagination.filteredbreakdown=ne.balance.change.breakdown,ne.pagination.totalItems=ne.balance.change.breakdown.length}).finally(function(){ne.loading.tab=!1})}function p(){ne.balance.closing=ne.balance.opening+ne.balance.change.amount}function v(e){return t(e,c.serverDateFormat).toDate()}function h(e){return t(e).format(c.serverDateFormat)}function b(e){var t;return i.resolve().then(function(){j(e),"from"===e&&U(),M("hours")&&(_(e),"from"!==e||ne.uiOptions.multipleDays||_("to")),ne.loading[e+"DayTypes"]=!0}).then(function(){return C(e)}).then(function(e){if(t=e.id!==ne.period.id,t&&(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(t)return x()}).then(function(){return ne.onDateChangeExtended&&ne.onDateChangeExtended(e)}).then(function(){if(z(),!t)return E();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(R).finally(q)}function g(){return z(),E()}function y(){return ne.uiOptions.toDate=null,j("to"),i.resolve().then(z).then(ne.setDaysSelectionModeExtended).then(q).then(!ne.uiOptions.multipleDays&&E)}function _(e){ne.uiOptions.times[e].loading=!0}function q(){["from","to"].forEach(function(e){ne.loading[e+"DayTypes"]=!1,M("hours")&&(ne.uiOptions.times[e].loading=!1)})}function C(n){var a=t(ne.uiOptions[n+"Date"]).format(ne.uiOptions.userDateFormat.toUpperCase());return e.find(ne.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function T(){return ne.request?ne.request.request_type:ne.leaveType||null}function A(e){return t().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return X(),ne.loading.balanceChange=!0,ne.request.getBalanceChangeBreakdown().then(H).catch(R)}function R(t){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(t)?t:[t]),ne.loading.fromDayTypes=!1,ne.loading.balanceChange=!1,ne.loading.tab=!1,ne.loading.toDayTypes=!1}function P(){return ne.isMode("create")||ne.forceRecalculateBalanceChange?E():D()}function S(){var e=ne.request.attributes();return ne.uiOptions.fromDate=v(ne.request.from_date),ne.request.to_date=e.to_date,ne.request.to_date_type=e.to_date_type,ne.uiOptions.toDate=v(ne.request.to_date),ne.initDayTypesExtended?ne.initDayTypesExtended():i.resolve()}function I(){te.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,t){K(t)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",E))}function L(){ne.isMode("edit")&&(ne.isLeaveStatus(c.statusNames.approved)||ne.isLeaveStatus(c.statusNames.adminApproved))&&(ee={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,t){e!==t&&(ne.uiOptions.multipleDays||(Z(e),z()))})}function M(e){return ne.selectedAbsenceType.calculation_unit_name===e}function w(e){return ne.request.request_type===e}function $(t){return e.includes(["weekend","non_working_day","public_holiday"],t)}function k(){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 B(){var e=(ne.pagination.currentPage-1)*ne.pagination.numPerPage,t=e+ne.pagination.numPerPage;ne.pagination.filteredbreakdown=ne.balance.change.breakdown.slice(e,t)}function E(){return X(),ne.canCalculateChange()?(ne.loading.balanceChange=!0,ne.request.change_balance=!0,ne.calculateBalanceChange().then(H).catch(R).finally(function(){ne.loading.balanceChange=!1})):i.resolve()}function F(){ne.pagination.totalItems=ne.balance.change.breakdown.length,ne.pagination.filteredbreakdown=ne.balance.change.breakdown,ne.pagination.pageChanged()}function N(){return h(ne.request.from_date)===h(ne.request.to_date)}function U(){ne.uiOptions.toDate&&ne.uiOptions.fromDate&&ne.uiOptions.multipleDays&&t(ne.uiOptions.toDate).isSameOrBefore(ne.uiOptions.fromDate)&&(ne.uiOptions.toDate=null,j("to"))}function j(e){ne.resetUIInputsExtended&&ne.resetUIInputsExtended(e),z(),X()}function H(e){ne.balance.change=e,ne.request.balance_change=e.amount,p(),F(),ne.loading.balanceChange=!1}function W(){var e,n,a;ne.uiOptions.fromDate?(e=t(ne.uiOptions.fromDate).add(1,"day").toDate(),a=e,n=e):(a=v(ne.period.start_date),n=ne.uiOptions.date.to.options.minDate),ne.uiOptions.date.to.options.initDate=n,ne.uiOptions.date.to.options.minDate=a,ne.uiOptions.date.to.options.maxDate=v(ne.period.end_date)}function Y(){return!ne.isMode("create")&&N()||ne.isMode("create")&&(w("sickness")||M("hours"))?ne.uiOptions.multipleDays=!1:ne.uiOptions.multipleDays=!0,i.resolve().then(ne.setDaysSelectionModeExtended)}function G(){ee&&ee.absenceTypeId===ne.selectedAbsenceType.id?ne.balance.opening=ee.value||0:ne.balance.opening=ne.selectedAbsenceType.remainder}function V(){ne.selectedAbsenceType=e.find(ne.absenceTypes,function(e){return e.id===ne.request.type_id})}function z(){var e=ne.uiOptions,t=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),(M("hours")||w("toil"))&&(ne.request.from_date=ne.request.from_date&&t.from.time?ne.request.from_date+" "+t.from.time:null,ne.request.to_date=ne.request.to_date&&t.to.time?ne.request.to_date+" "+t.to.time:null)}function X(){ne.uiOptions.showBalance=ne.canCalculateChange()}function Q(){e.forEach(te,function(e){e()})}function J(){var e,t=ne.selectedAbsenceType.calculation_unit_name;return V(),e=t!==ne.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&Y).then(e&&ne.onAbsenceTypeUpdateExtended).then(e&&z).then(q).then(E)}function K(e){return ne.absenceTypes=e,V(),t(ne.uiOptions.toDate).isAfter(ne.period.end_date)&&(ne.uiOptions.toDate=void 0,j("to")),G(),E()}function Z(e){var t=A(e).add(ne.uiOptions.time_interval,"minutes");t.isAfter(A(ne.uiOptions.times.to.max))||(ne.uiOptions.times.to.min=t.format("HH:mm"),t.isAfter(A(ne.uiOptions.times.to.time))&&(ne.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var ee=null,te=[],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:[],numPerPage:7,totalItems:0,pageChanged:B},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.$onInit=f,ne.convertDateFormatFromServer=v,ne.convertDateToServerFormat=h,ne.dateChangeHandler=b,ne.dateTypeChangeHandler=g,ne.daysSelectionModeChangeHandler=y,ne.disableAndShowLoadingTimeInput=_,ne.getMomentDateWithGivenTime=A,ne.handleError=R,ne.isCalculationUnit=M,ne.isLeaveType=w,ne.isNotWorkingDay=$,ne.performBalanceChangeCalculation=E,ne.setRequestDateTimesAndDateTypes=z,ne.updateEndTimeInputMinTime=Z,ne.$onDestroy=Q}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,o,s,i,r,c,u,l){function d(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",O),y(),a.all([A(),C()]).then(_).finally(function(){O.filesLoaded=!0})}function m(){return O.fileUploader&&O.fileUploader.queue.length>0}function f(){return O.getFilesAmount()0?S.map(function(e){return e.label}).join(", "):""}function C(){return O.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function T(){return a.all(S.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){L[e.label]=t})})).catch(function(){L=null})}function A(){return c.valuesOf("safe_file_extension").then(function(e){S=e})}function D(e){return!e.attachment_id||O.canManage}function R(){e.forEach(I,function(e){e()})}function P(e,t){O.fileUploader.queue&&O.fileUploader.queue.length>0?O.fileUploader.uploadAll({entityID:O.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var S=[],I=[],L={},O=Object.create(this);return O.filesLoaded=!1,O.fileUploader=null,O.today=Date.now(),O.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",O.userDateFormat=i.DATE_FORMAT,O.$onDestroy=R,O.$onInit=d,O.canRemoveAttachment=D,O.canSubmit=m,O.canUploadMore=f,O.formatDateTime=p,O.getAuthorName=v,O.getFilesAmount=h,O.listFileTypes=q,O}n.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function t(e,t,n){function a(){s=n.parse(),s.openModal&&o({leaveType:s.openModal,selectedContactId:i.selectedContactId})}function o(e){t.openModal(e)}e.debug("Component: leave-request-record-actions");var s,i=this;i.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],i.$onInit=a,i.openLeavePopup=o}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",t]})}),define("leave-absences/shared/components/manage-leave-requests.component",["common/lodash","leave-absences/shared/modules/components","common/models/contact","common/services/pub-sub"],function(e,t){function n(t,n,a,o,s,i,r,c,u,l,d,m){"use strict";function f(){s(r.permissions.admin.administer).then(function(e){H.isAdmin=e,n.all([A(),D(),M(),P(),L(),I(),w()]).then(function(){H.loading.page=!1,R()}),U()})}function p(){H.filters.leaveRequest.contact_id=null,H.refresh()}function v(){var e=H.filters.contact;return{department:e.department,level_type:e.level_type,location:e.location,region:e.region}}function h(e){return"all"===e.name||""===e?H.leaveRequests.filter.list.length:H.leaveRequests.filter.list.filter(function(t){return t.status_id===e.value}).length}function b(t){return e.find(H.absenceTypes,{id:t})}function g(e){return new Array(e||0)}function y(t){var n=e.find(H.leaveRequestStatuses,function(e){return e.value===t});return n?n.label:null}function _(e){switch(e){case r.statusNames.approved:return"badge-success";case r.statusNames.rejected:return"badge-danger";case r.statusNames.cancelled:case"all":return"";default:return"badge-primary"}}function q(t){return e.find(H.leaveRequestStatuses,function(e){return e.name===t}).value}function C(t){var n=e.find(H.filteredUsers,function(e){return e.id===t});return n?n.display_name:null}function T(e){return e.current?"Current Period ("+e.title+")":e.title}function A(){return c.all().then(function(t){H.absencePeriods=e.sortBy(t,"start_date"),H.filters.leaveRequest.selectedPeriod=e.find(H.absencePeriods,function(e){return!!e.current})})}function D(){return u.all().then(u.loadCalculationUnits).then(function(e){H.absenceTypes=e})}function R(e){return(H.isAdmin?o.all(v()):o.leaveManagees(H.contactId,v())).then(function(t){return H.filteredUsers=H.isAdmin?t.list:t,e?S(e):n.all([S("table"),S("filter")])}).then(function(){H.filters.leaveRequest.leaveStatus!==W&&0===H.leaveRequests.table.list.length&&H.refresh(1,!0)})}function P(){return i.valuesOf("hrjc_department").then(function(e){H.departments=e})}function S(e){var t="filter"!==e,n="table"===e?e:"content",a="filter"===e?{size:0}:H.pagination,o="filter"===e?{return:["status_id"]}:{};return H.loading[n]=!0,l.all(O(t),a,"from_date DESC",o,!1).then(function(t){H.leaveRequests[e]=t}).catch(function(){H.leaveRequests[e].list=[]}).finally(function(){H.loading[n]=!1})}function I(){return i.valuesOf("hrjc_level_type").then(function(e){H.levelTypes=e})}function L(){return i.valuesOf("hrjc_location").then(function(e){H.locations=e})}function O(t){var n=H.filters.leaveRequest;return{contact_id:k(),managed_by:H.isAdmin&&"me"!==n.assignedTo.type?void 0:H.contactId,status_id:B(t),type_id:n.selectedAbsenceTypes?n.selectedAbsenceTypes.id:{IN:e.pluck(H.absenceTypes,"id")},from_date:{from:n.selectedPeriod.start_date},to_date:{to:n.selectedPeriod.end_date},unassigned:"unassigned"===n.assignedTo.type||void 0}}function M(){return i.valuesOf("hrjc_region").then(function(e){H.regions=e})}function w(){return i.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){H.leaveRequestStatuses=e.concat(H.leaveRequestStatuses)})}function $(e){d.openModal(e)}function k(){return H.filteredUsers.length>0&&H.filters.leaveRequest.contact_id?H.filters.leaveRequest.contact_id:{IN:H.filteredUsers.map(function(e){return e.id})}}function x(e){var t=[q(r.statusNames.moreInformationRequired),q(r.statusNames.awaitingApproval)];return 0===e.length&&(e=e.concat(t)),e}function B(e){var t=H.filters.leaveRequest,n=[];if(e&&t.leaveStatus&&t.leaveStatus.value&&n.push(t.leaveStatus.value),t.pending_requests&&(n=x(n)),n.length)return{IN:n}}function E(e,t,n){e="number"==typeof e?e:1,t&&(H.filters.leaveRequest.leaveStatus=W),(e<=H.totalNoOfPages()||0===H.totalNoOfPages())&&(H.pagination.page=e,R(n))}function F(e){H.filters.leaveRequest.leaveStatus=e,H.refresh(1,!1,"table")}function N(e){H.filters.leaveRequest.assignedTo=e,H.refresh()}function U(){m.subscribe("LeaveRequest::updatedByManager",function(){H.refresh()}),m.subscribe("LeaveRequest::new",function(){H.refresh()}),m.subscribe("LeaveRequest::edit",function(){H.refresh()}),m.subscribe("LeaveRequest::delete",function(){H.refresh()}),m.subscribe("LeaveRequest::statusUpdate",function(){H.refresh()})}function j(){return Math.ceil(H.leaveRequests.table.total/H.pagination.size)}t.debug("Component: manage-leave-requests");var H=this,W={name:"all",label:"All"};H.absencePeriods=[],H.absenceTypes=[],H.filteredUsers=[],H.isFilterExpanded=!1,H.isAdmin=!1,H.leaveRequests={table:{list:[]},filter:{list:[]}},H.leaveRequestStatuses=[W],H.loading={content:!0,page:!0,table:!0},H.pagination={page:1,size:7},H.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],H.filters={contact:{department:null,level_type:null,location:null,region:null},leaveRequest:{leaveStatus:H.leaveRequestStatuses[0],pending_requests:!0,contact_id:null,selectedPeriod:null,selectedAbsenceTypes:null,assignedTo:H.filtersByAssignee[0]}},H.$onInit=f,H.clearStaffSelection=p,H.countLeaveRequestByStatus=h,H.getAbsenceTypeByID=b,H.getArrayOfSize=g,H.getLeaveStatusByValue=y,H.getNavBadge=_,H.getUserNameByID=C,H.labelPeriod=T,H.openLeavePopup=$,H.refresh=E,H.refreshWithFilter=F,H.refreshWithFilterByAssignee=N,H.totalNoOfPages=j}t.component("manageLeaveRequests",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/manage-leave-requests.html"}],controllerAs:"vm",controller:n}),n.$inject=["$log","$q","$rootScope","Contact","checkPermissions","OptionGroup","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","LeavePopup","pubSub"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,t=!!e.from_date&&!!e.to_date,n=i.selectedAbsenceType.calculation_unit_name;return"days"===n?t=t&&!!e.from_date_type&&!!e.to_date_type:"hours"===n&&(t=t&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),t}function d(){return i.canCalculateChange()}function m(t,n){var a=i.uiOptions.times[t],o=e.clone(n.time_from),s=e.clone(n.time_to);i.uiOptions.multipleDays||("from"===t&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===t&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.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}function f(t,n){return t?(t=i.convertDateToServerFormat(t),h(t).then(function(n){return n?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(t,i.requestDayTypes).then(function(t){return t.length?t:i.requestDayTypes.filter(function(t){return e.includes(["all_day","half_day_am","half_day_pm"],t.name)})})}).then(function(e){return S(n,e),e})):o.reject([])}function p(e,n){return e=t(e),o.all([i.calendar.isNonWorkingDay(e),i.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 v(e,n){return t.duration(n).subtract(t.duration(e)).asHours()}function h(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function y(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,t){i.isCalculationUnit("days")||+e==+t||(i.isRole("staff")&&(i.request.change_balance=!0),O(),i.performBalanceChangeCalculation())})}function _(e){var n=t(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(v(a.min,n)<=0||v(a.max,n)>=0)&&(n="from"===e?a.min:a.max),i.uiOptions.times[e].time=n}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],t=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(R)).then(function(){["from","to"].forEach(function(e){_(e),L(e),t[e].amount=Math.min(i.request[e+"_date_amount"],t[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(O)}function C(){["from","to"].forEach(function(e){y(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(t,n){i.isCalculationUnit("days")||t===n||(i.setRequestDateTimesAndDateTypes(),t&&L(e,!0))})}function A(e,t){return f(e,t).then(function(){i.loading[t+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return R(e).then(function(){L(e,!0)})})}function R(e){var t=i.uiOptions[e+"Date"],n=!i.uiOptions.multipleDays;return t?i.request.getWorkDayForDate(i.convertDateToServerFormat(t)).then(function(t){w[e]=t,m(e,t),n&&"from"===e&&m("to",t)}).catch(function(t){return w[e]={},i.handleError(t)}).finally(function(){i.uiOptions.times[e].loading=!1,n&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(t){var n=i.uiOptions.times[t];i["request"+e.startCase(t)+"DayTypes"]=[],n.time="",n.min="00:00",n.max="00:00",n.amount="0",n.maxAmount="0"}function S(t,n){var a="request"+e.startCase(t)+"DayTypes";i[a]=n,i.isMode("create")&&(i.request[t+"_date_type"]=i[a][0].value)}function I(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),R("from").then(function(){L("from",!0)})):o.resolve()}function L(e,t){var n=i.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,c=w[a].number_of_hours?v(s,r).toString():"0";o.maxAmount=c,t&&(o.amount=o.maxAmount)}function O(){var e=i.uiOptions.times +;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function M(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?R("from").then(function(){L("from",!0)}):o.resolve()}var w={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=M,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=I}n.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,t){function n(t,n,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),v(),f(!0)])}function l(t){var n=r.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function d(t){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===t})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(t){return i.valuesOf("hrleaveandabsences_sickness_reason",t).then(function(t){r.sicknessReasons=e.indexBy(t,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function v(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}n.debug("RequestModalDetailsSicknessController"),t("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}t.controller("RequestModalDetailsSicknessController",n),n.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,t,n){function a(n,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=t.duration(t(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return h().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,t=!c.uiOptions.multipleDays&&!!c.request.from_date,n=t||e,a=U.from_date!==c.request.from_date||U.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&n&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function v(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function h(){var e=c.uiOptions.multipleDays,t=c.request;return b({hasErrors:e?!t.to_date&&!t.from_date:!t.from_date,label:e?"To Date":"From Date",value:t.to_date})}function b(e){if(e.hasErrors){var n="Please select "+e.label+" to find expiry date";return a.reject([n])}return e.value?a.resolve(t(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&H.hasExpirationFromAdminSettings,t=H.hasPreviousExpirationDate,n=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=n&&(a||e||t)}function y(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",_().then(g).then(C).then(S)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,t){+e!=+t&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,t){e!==t&&c.isCalculationUnit("hours")&&M(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=t(c.request.from_date).format("HH:mm"),e.to.time=t(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,t){e!==t&&(c.setRequestDateTimesAndDateTypes(),F(),l(),w())})})}function P(){c.isMode("view")||(T(),A(),R())}function S(t){return i.valuesOf("hrleaveandabsences_toil_amounts",t).then(function(t){c.toilAmounts=e.sortBy(t,function(e){return+e.weight})})}function I(){return l(),w(),F()}function L(){return k(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),j?j=!1:w(),F()}function O(e){c.uiOptions.times[e].time=""}function M(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function w(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function $(){U=e.cloneDeep(c.request.attributes())}function k(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function x(){c.setRequestDateTimesAndDateTypes(),l(),w(),c.isCalculationUnit("hours")?M():c.request.toil_to_accrue=null}function B(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){S(!1)})}function E(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function N(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}n.debug("RequestModalDetailsToilController");var U,j=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=v,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=x,c.onDateChangeExtended=I,c.openToilInDaysAccrualOptionsEditor=B,c.resetUIInputsExtended=O,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=N,function(){$(),k(),E(),!c.isMode("create")&&y()}()}n.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,t,n){"use strict";function a(n,a,o,s){function i(n){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var t=e.get(n,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return n.lookupContacts=e,a.all([d(),"me"!==t?u():a.resolve(null)])}).then(function(e){var t=e[0];return n.contactIdsToReduceTo=e[1],t})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return t(a.period_start_date).isSameOrBefore(n.selectedPeriod.end_date)&&(t(a.period_end_date).isSameOrAfter(n.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return h?a.resolve(h):s.all()}function d(){return o.all(v(),null,"display_name").then(function(e){return e.list})}function m(){var t=e.get(n,"filters.userSettings.assignedTo.type","all");return(0,b[t])()}function f(){return m().then(function(e){n.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(n.contactId)}function v(){var t={department:e.get(n,"filters.userSettings.department.value",null),level_type:e.get(n,"filters.userSettings.level_type.value",null),location:e.get(n,"filters.userSettings.location.value",null),region:e.get(n,"filters.userSettings.region.value",null)},a=!!n.filters.userSettings.contact,o=e.isArray(n.lookupContacts)&&n.lookupContacts.length,s="all"!==e.get(n,"filters.userSettings.assignedTo.type","all");return a?t.id={IN:[n.filters.userSettings.contact.id]}:(s||o)&&(t.id={IN:e.pluck(n.lookupContacts,"id")}),t}var h,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return n.debug("LeaveCalendarService"),{init:i}}n.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,t){return e.debug("EntitlementLogAPI"),t.extend({all:function(t){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",t,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,t,n){return e.debug("EntitlementInstance"),t.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return n.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(t,n,a,o,s){return t.debug("Entitlement"),n.extend({all:function(e,t){return a.all(this.processFilters(e),t).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(t,n){return a.breakdown(t).then(function(t){return n?(n.map(function(n){var a=e.find(t,function(e){return e.id===n.id});return a&&(n.breakdown=a.breakdown),n}),n):t.map(function(e){return o.init(e,!0)})})},logs:function(t){return t=e.cloneDeep(t||{}),t.contact_id&&(t["entitlement_id.contact_id"]=t.contact_id,delete t.contact_id),t.period_id&&(t["entitlement_id.period_id"]=t.period_id,delete t.period_id),t.return=t.return||[],t.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(t)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,t){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,n,a){return e.debug("LeaveRequestAPI"),n.extend({all:function(t,n,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",t,n,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(n){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return n.contact_id&&n.period_id||o.reject("contact_id and period_id are mandatory"),n=t.defaults(n,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",n,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(n){return e.debug("LeaveRequestAPI.calculateBalanceChange",n),this.sendPOST("LeaveRequest","calculatebalancechange",n).then(function(e){return e.values.breakdown=t.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,t){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:t.toString()},!1)},create:function(t){return e.debug("LeaveRequestAPI.create",t),this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,attachment_id:n}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,n){return n=t.assign({},n,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",n).then(function(e){return e.values})},find:function(t){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:t},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",n,!1).then(function(e){return e.values})},getComments:function(e,n){return n=t.assign({},n,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",n,!1).then(function(e){return e.values})},isManagedBy:function(t,n){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:t,contact_id:n}).then(function(e){return e.values})},isValid:function(n){e.debug("LeaveRequestAPI.isValid",n);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?o.reject(t(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,n,a){return a=t.assign({},a,{leave_request_id:e,text:n.text,contact_id:n.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(t){return e.debug("LeaveRequestAPI.update",t),t.id?this.sendPOST("LeaveRequest","create",t).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,t,n){"use strict";n.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(n,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var t=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=t,n.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return n.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var t=[];return e.forEach(this.files,function(e){e.toBeDeleted&&t.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),n.all(t)}function f(e){return t.duration(e.time_to).subtract(t.duration(e.time_from)).asHours()}function p(t){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){return e.find(n,function(e){return e.name===t})})}function v(t){var a=e.cloneDeep(t),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return n.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(t){return s.amount=t[0].time_from?Math.min(this.from_date_amount,f(t[0])):0,o&&(i.amount=t[1].time_from?Math.min(this.to_date_amount,f(t[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,t){return e+t.amount},0),a}.bind(this))}function h(){var e=this.id,t=[];return t.push(n.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return r.saveComment(e,t)}}))),t=t.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),n.all(t)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(t){var n=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===t&&e.pull(n,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,n)).then(function(e){return"hours"===t?v.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return n.all([h.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,n.all([h.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){if(t.comment_id)return void(t.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(t){return{amount:e.reduce(t.values,function(e,t){return e+parseFloat(t.amount)},0),breakdown:t.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return n.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):n.resolve()},roleOf:function(e){return this.contact_id===e?n.resolve("owner"):a(s.permissions.admin.administer).then(function(t){return t?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):n.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,o,s,i){return n.all(this.processFilters(e),t,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return n.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return n.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,t){return e.debug("PublicHolidayAPI"),t.extend({all:function(t){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",t).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,t){return e.debug("PublicHolidayInstance"),t.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,t){"use strict";t.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(t,n,a,o,s){return t.debug("PublicHoliday"),n.extend({all:function(e){return t.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var o=e(n).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},n.defaultCustomData(),t)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(t){var n=this.getDocumentArray(),a=n.indexOf(t);e.contains(n,t)?n.splice(a,1):n.push(t),this.sickness_required_documents=n.join(",")},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,t){"use strict";t.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(t,n){return n.extend({defaultCustomData:function(){var t={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},n.defaultCustomData(),t)},toAPIFilter:function(t,n,a){e.includes(["balance_change","dates","comments","files"],a)||(t[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,t,n,a){"use strict";function o(t,o,s,i,r,c,u,l,d,m,f,p,v,h,b,g,y,_,q,C){function T(e){"days"===Ne.selectedAbsenceType.calculation_unit_name?delete Ne.request[e+"_date_amount"]:delete Ne.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return Me.checkIfSelfLeaveApprover().then(function(e){e&&(Ee="admin")})}function R(){var e=Ne.requestStatuses[y.statusNames.awaitingApproval].value;ke.status_id===e&&e!==Ne.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return!Ne.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ne.isMode("edit")&&(e=e&&(G()||S())),Ne.canManage&&Ne.requestStatuses&&(e=e&&!!Ne.getStatusFromValue(Ne.newStatusOnSave)),(e=e&&!!Ne.period.id)&&!Ne.isMode("view")}function O(){Ne.isSelfRecord&&!Ne.isSelfLeaveApprover?Ne.request.status_id=Ne.requestStatuses[y.statusNames.awaitingApproval].value:Ne.canManage&&(Ne.request.status_id=Ne.newStatusOnSave||Ne.request.status_id)}function M(){if(Ne.isMode("edit")&&!Ne.isRole("staff")&&"toil"!==j())return Ne.request.calculateBalanceChange(Ne.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ne.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function w(){return"toil"!==j()&&!Ne.request.change_balance}function $(){Ne.errors=[]}function k(){return Ne.request.create().then(Pe).then(function(){ge("LeaveRequest::new")})}function x(){se()&&!Ne.isRole("staff")&&(Ne.request.change_balance=!0)}function B(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ne.request.delete().then(function(){Ne.dismissModal(),d.publish("LeaveRequest::delete",Ne.request)})}})}function E(){r.dismiss({$value:"cancel"})}function F(){var e=j();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return U(Ne.getStatusFromValue(Ne.request.status_id).name)}function U(e){return n.map(we[e],function(e){return Ne.requestStatuses[e]})}function j(){return Ne.request?Ne.request.request_type:Ne.leaveType||null}function H(){return!Ne.request||e.equals({},Ne.requestStatuses)?[]:Ne.request.status_id?N():U("none")}function W(e){return n.find(Ne.requestStatuses,function(t){return t.value===e})}function Y(e){Ne.errors=n.isArray(e)?e:[e],Ne.loading.absenceTypes=!1,Ne.submitting=!1}function G(){return!e.equals(ke,Ne.request.attributes())||Ne.canManage&&Ne.newStatusOnSave}function V(){return Ne.postContactSelection=!0,Ne.staffMemberSelectionComplete=!1,Ne.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ne.isMode("edit")?Te:n.noop).then(function(){Ne.postContactSelection=!1,Ne.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Be)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];we.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],we.awaiting_approval=e,we.more_information_required=e,we.rejected=e,we.approved=e,we.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ne.canManage=Ne.isRole("manager")||Ne.isRole("admin")}function Q(){return Ne.canManage?f.find(Ne.request.contact_id).then(function(e){Ne.contactName=e.display_name}):o.resolve()}function J(){Ne.isRole("admin")&&Ne.isSelfRecord&&(Ne.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,t=+Me.id==+n.get(Ne,"leaveRequest.contact_id"),a=!n.get(Ne,"leaveRequest.id");Ne.isSelfRecord=e&&a||t}function Z(){xe.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ne.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,t){Y(t)}),s.$on("LeaveRequestPopup::childComponent::register",function(){$e++})),i.$on("$destroy",Se),i.$on("LeaveRequestPopup::addTab",function(e,t){Fe.push(t)})}function ee(){var e,t;Ne.request=Ne.leaveRequest||null,e=j(),t=Ne.initRequestAttributes(),"leave"===e?Ne.request=g.init(t):"sickness"===e?Ne.request=_.init(t):"toil"===e&&(Ne.request=q.init(t))}function te(){var e={};return Ne.request?e=Ne.request.attributes():Ne.canManage||(e={contact_id:Me.id}),e}function ne(){return Ee="staff",ae().then(Ne.isSelfRecord&&!Ne.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Ee="admin")}).then(function(){return"admin"!==Ee&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Ee="manager")})}function oe(){Ne.defaultStatus?Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames[Ne.defaultStatus]].value:(Ne.isRole("admin")||Ne.isMode("create")&&Ne.isRole("manager"))&&(Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames.approved].value)}function se(){return!Ne.request.status_id||!n.includes(["cancelled","rejected"],W(Ne.request.status_id).name)}function ie(e){var t=Ne.getStatusFromValue(Ne.request.status_id);return!!t&&t.name===e}function re(e){return Ne.request&&Ne.request.request_type===e}function ce(e){return Ne.mode===e}function ue(e,t){var n=a(e.from_date),o=a(e.to_date);return n.isSameOrAfter(t.start_date,"day")&&o.isSameOrBefore(t.end_date,"day")}function le(e){return Ee===e}function de(){return p.all().then(function(e){Ne.absencePeriods=e})}function me(){return v.all(F()).then(v.loadCalculationUnits).then(function(e){Oe={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ne.loading.entitlements=!0,h.all({contact_id:Ne.request.contact_id,period_id:Ne.period.id,type_id:{IN:Oe.ids}},!0).finally(function(){Ne.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){Me=e})}function ve(){return Ne.selectedContactId?f.find(Ne.selectedContactId).then(function(e){Ne.managedContacts=[e]}):Ne.isRole("admin")?f.all().then(function(e){Ne.managedContacts=e.list}):Me.leaveManagees().then(function(e){Ne.managedContacts=e})}function he(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ne.requestStatuses=n.indexBy(e,"name")})}function be(e,t){var a;return n.compact(e.map(function(e){if(a=n.find(t,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){R(),d.publish(e,Ne.request),Ne.errors=[],Ne.dismissModal()}function ye(){["from","to"].forEach(function(e){Ne.request[e+"_date"]=ke[e+"_date"]})}function _e(e){if(Ne.absenceTypes=be(Oe.types,e),!Ne.absenceTypes.length)return o.reject(Be)}function qe(){Ne.period=n.find(Ne.absencePeriods,function(e){return Ne.isMode("create")?e.current:ue(Ne.request,e)})}function Ce(){Ne.isMode("create")?(Ne.selectedAbsenceType=Ne.absenceTypes[0],Ne.request.type_id=Ne.selectedAbsenceType.id):Ne.selectedAbsenceType=n.find(Ne.absenceTypes,function(e){return e.id===Ne.request.type_id})}function Te(){ke=e.copy(Ne.request.attributes())}function Ae(){var e;Ne.request.id?(e=[Ne.requestStatuses[y.statusNames.approved].value,Ne.requestStatuses[y.statusNames.adminApproved].value,Ne.requestStatuses[y.statusNames.rejected].value,Ne.requestStatuses[y.statusNames.cancelled].value],Ne.mode="edit",Ne.isRole("staff")&&e.indexOf(Ne.request.status_id)>-1&&(Ne.mode="view")):Ne.mode="create"}function De(){var e=Ne.request.status_id;if(!Ne.isMode("view")&&!Ne.submitting)return Ne.submitting=!0,O(),A(),Ne.request.isValid().then(se()&&M).then(x).then(w()&&ye).then(Re).then(function(){return Ne.isMode("edit")?Le():k()}).catch(function(t){Ne.request.status_id=e, +t&&Y(t)}).finally(function(){Ne.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&n.push(e),++a===$e&&(n.length>0?t.reject(n):t.resolve())}var t=o.defer(),n=[],a=0;return $e>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function Se(){xe.forEach(function(e){e()})}function Ie(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ne.request.update().then(Pe).then(function(){Ne.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ne.isRole("staff")||Ne.isRole("admin"))&&ge("LeaveRequest::edit")})}t.debug("RequestCtrl");var Oe,Me,we={},$e=0,ke={},xe=[],Be="No entitlement",Ee="",Fe=[],Ne=n.assign(this,m);Ne.absencePeriods=[],Ne.absenceTypes=[],Ne.canManage=!1,Ne.contactName=null,Ne.errors=[],Ne.isSelfLeaveApprover=!1,Ne.loading={absenceTypes:!0,entitlements:!0},Ne.managedContacts=[],Ne.mode="",Ne.newStatusOnSave=null,Ne.period={},Ne.postContactSelection=!1,Ne.requestStatuses={},Ne.selectedAbsenceType={},Ne.staffMemberSelectionComplete=!1,Ne.submitting=!1,Ne.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ne.canChangeAbsenceType=I,Ne.canSubmit=L,Ne.closeAlert=$,Ne.deleteLeaveRequest=B,Ne.dismissModal=E,Ne.getStatuses=H,Ne.getStatusFromValue=W,Ne.initAfterContactSelection=V,Ne.initRequestAttributes=te,Ne.isLeaveStatus=ie,Ne.isLeaveType=re,Ne.isMode=ce,Ne.isRole=le,Ne.submit=De,Ne.updateAbsenceType=Ie,function(){Ne.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([ne(),de(),he()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ne.canManage&&!Ne.isMode("edit")&&ve()}).then(function(){if(Ne.selectedContactId&&(Ne.request.contact_id=Ne.selectedContactId),Ne.request.contact_id)return Ne.initAfterContactSelection()}).catch(Y).finally(function(){Ne.loading.absenceTypes=!1})}()}t.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,t){"use strict";function n(e,t,n,a,o,s,i,r,c){function u(e){return r.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:t.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(t){t?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/manager-leave/modules/components",["common/angular"],function(e){return e.module("manager-leave.components",[])}),define("leave-absences/manager-leave/components/manager-leave-container",["leave-absences/manager-leave/modules/components"],function(e){e.component("managerLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/manager-leave-container.html"}],controller:["$log","$rootScope","$state",function(e,t,n){function a(){n.go(o.tabName)}e.debug("Component: manager-leave-container"),t.section="manager-leave";var o=this;o.tabName=n.current.name,o.changeTab=a}],controllerAs:"managerLeave"})}),function(e){define("leave-absences/manager-leave/modules/settings",["common/angular"],function(t){return t.module("manager-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/"})})}(CRM),function(e,t){define("leave-absences/manager-leave/modules/config",["common/angular","common/lodash","leave-absences/manager-leave/modules/settings"],function(t,n){function a(t){t.withAutoBase(!0),t.settings.ga={userId:n.get(e,"vars.session.contact_id")}}return t.module("manager-leave.config",["manager-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","$analyticsProvider","settings",function(t,n,o,s,i,r,c){s.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.defaults.stripTrailingSlashes=!1,o.otherwise("/manager-leave/requests"),a(r),i.debugEnabled(c.debug),t.state("manager-leave",{abstract:!0,url:"/manager-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("manager-leave.requests",{url:"/requests?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,t){e["leave-request-id"]&&t.openModalByID(e["leave-request-id"])}]}).state("manager-leave.calendar",{url:"/calendar",template:''}).state("manager-leave.leave-balances",{url:"/leave-balances",template:""})}])})}(CRM,Drupal),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/angulartics","common/angulartics-google-tag-manager","common/angularUiRouter","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/modules/dialog","common/services/angular-date/date-format","common/services/check-permissions","common/services/crm-ang.service","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/components/leave-balance-tab.component","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/manage-leave-requests.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/manager-leave/components/manager-leave-container","leave-absences/manager-leave/modules/config"],function(e){return e.module("manager-leave",["ngResource","ngAnimate","angulartics","angulartics.google.tagmanager","ui.bootstrap","ui.router","ui.select","textAngular","common.angularDate","common.dialog","common.filters","common.models","common.directives","common.mocks","leave-absences.models","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","manager-leave.config","manager-leave.components"]).run(["$log","$rootScope","shared-settings","settings",function(e,t,n,a){e.debug("app.run"),t.sharedPathTpl=n.sharedPathTpl,t.settings=a}]),e}),function(e,t){var n=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";t.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":n+"/shared","leave-absences/manager-leave":n+"/manager-leave"}}),t(["leave-absences/shared/config"],function(){t(["leave-absences/manager-leave/app","leave-absences/shared/models/leave-request.model"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-manager-leave]"),["manager-leave"])})})}(CRM,require),define("manager-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/manager-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/my-leave.min.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/my-leave.min.js index 6c1c264aba6..b59c41367d2 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/my-leave.min.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/my-leave.min.js @@ -1,5 +1,5 @@ !function(e){define("leave-absences/shared/config",[],function(){e.config({paths:{mocks:"../test/mocks"}}),e.config({paths:{mocks:CRM.vars.leaveAndAbsences.baseURL+"/js/test/mocks"}})})}(require),function(e){define("leave-absences/shared/modules/shared-settings",["common/angular"],function(n){return n.module("leave-absences.settings",[]).constant("shared-settings",{attachmentToken:e.vars.leaveAndAbsences.attachmentToken,debug:e.debug,managerPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/manager-leave/",sharedPathTpl:e.vars.leaveAndAbsences.baseURL+"/views/shared/",sourcePath:e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences/",serverDateFormat:"YYYY-MM-DD",serverDateTimeFormat:"YYYY-MM-DD HH:mm:ss",permissions:{admin:{access:"access leave and absences",administer:"administer leave and absences"},ssp:{access:"access leave and absences in ssp",manage:"manage leave and absences in ssp"}},fileUploader:{queueLimit:10},statusNames:{approved:"approved",adminApproved:"admin_approved",awaitingApproval:"awaiting_approval",moreInformationRequired:"more_information_required",rejected:"rejected",cancelled:"cancelled"}})})}(CRM),define("leave-absences/shared/modules/apis",["common/angular","common/modules/apis","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.apis",["common.apis","leave-absences.settings"])}),define("leave-absences/shared/modules/models-instances",["common/angular","common/models/instances/instance","common/modules/services","common/modules/models","common/services/check-permissions","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models.instances",["common.models","common.models.instances","common.services","leave-absences.settings"])}),define("leave-absences/shared/modules/models",["common/angular","common/modules/models","common/modules/services","leave-absences/shared/modules/apis","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/instances/absence-period.instance",["leave-absences/shared/modules/models-instances","common/moment","common/models/instances/instance","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriodInstance",["$log","ModelInstance","HR_settings",function(e,t,a){return e.debug("AbsencePeriodInstance"),t.extend({defaultCustomData:function(){return{current:!1}},transformAttributes:function(e){var t=n();return e.current=!1,n(e.start_date).isSameOrBefore(t,"day")&&n(e.end_date).isSameOrAfter(t,"day")&&(e.current=!0),e},isInPeriod:function(e){var t=a.DATE_FORMAT.toUpperCase(),o=n(e,t);return n(this.start_date).isSameOrBefore(o)&&n(this.end_date).isSameOrAfter(o)}})}])}),define("leave-absences/shared/apis/absence-period.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("AbsencePeriodAPI",["$log","api",function(e,n){return e.debug("AbsencePeriodAPI"),n.extend({all:function(n){return e.debug("AbsencePeriodAPI"),this.sendGET("AbsencePeriod","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/models/absence-period.model",["leave-absences/shared/modules/models","common/moment","leave-absences/shared/modules/shared-settings","leave-absences/shared/instances/absence-period.instance","leave-absences/shared/apis/absence-period.api","common/models/model","common/services/hr-settings"],function(e,n){"use strict";e.factory("AbsencePeriod",["$log","Model","AbsencePeriodAPI","AbsencePeriodInstance","shared-settings",function(e,t,a,o,s){return e.debug("AbsencePeriod"),t.extend({all:function(e){return a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},current:function(){var e=n().format(s.serverDateFormat),t={start_date:{"<=":e},end_date:{">=":e}};return a.all(t).then(function(e){return e&&e.length?o.init(e[0],!0):null})}})}])}),define("leave-absences/shared/apis/absence-type.api",["common/lodash","common/moment","leave-absences/shared/modules/apis","common/services/api"],function(e,n,t){"use strict";t.factory("AbsenceTypeAPI",["$log","api","shared-settings",function(t,a,o){return t.debug("AbsenceTypeAPI"),a.extend({all:function(n){return t.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaultsDeep(n||{},{is_active:!0,options:{sort:"weight ASC"}})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,i){return t.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:n(s).format(o.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",i).then(function(e){return e.values.expiry_date})}})}])}),define("leave-absences/shared/instances/absence-type.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("AbsenceTypeInstance",["$log","ModelInstance",function(e,n){return e.debug("AbsenceTypeInstance"),n.extend({})}])}),define("leave-absences/shared/models/absence-type.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","common/models/option-group","leave-absences/shared/apis/absence-type.api","leave-absences/shared/instances/absence-type.instance"],function(e,n){"use strict";n.factory("AbsenceType",["$log","$q","Model","OptionGroup","AbsenceTypeAPI","AbsenceTypeInstance",function(n,t,a,o,s,i){return n.debug("AbsenceType"),a.extend({all:function(e){return s.all(e).then(function(e){return e.map(function(e){return i.init(e,!0)})})},calculateToilExpiryDate:function(e,n,t){return s.calculateToilExpiryDate(e,n,t)},canExpire:function(e){return s.all({accrual_expiration_unit:{"IS NOT NULL":1},accrual_expiration_duration:{"IS NOT NULL":1},allow_accruals_request:1,id:e,options:{limit:1},return:["id"]}).then(function(e){return e.length>0})},loadCalculationUnits:function(n){return o.valuesOf("hrleaveandabsences_absence_type_calculation_unit").then(function(t){return t=e.indexBy(t,"value"),e.map(n,function(n){return e.assign(n,{calculation_unit_label:t[n.calculation_unit].label,calculation_unit_name:t[n.calculation_unit].name})})})}})}])}),define("leave-absences/shared/apis/work-pattern.api",["common/lodash","leave-absences/shared/modules/apis","common/services/api"],function(e,n){"use strict";n.factory("WorkPatternAPI",["$log","api",function(n,t){function a(n){var t=e.clone(n);return t.workPattern=t["api.WorkPattern.get"].values[0],delete t["api.WorkPattern.get"],t}return n.debug("WorkPatternAPI"),t.extend({assignWorkPattern:function(n,t,a,o,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:n,pattern_id:t,effective_date:a,effective_end_date:o,change_reason:s})).then(function(e){return e.values})},get:function(e){return this.sendGET("WorkPattern","get",e||{}).then(function(e){return e.values})},getCalendar:function(t,a,o,s){return n.debug("WorkPatternAPI.getCalendar",t,a,o,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{contact_id:e.isArray(t)?{IN:t}:t,start_date:a,end_date:o}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(n,t,o){return this.sendGET("ContactWorkPattern","get",e.assign({},t,{contact_id:n,"api.WorkPattern.get":{id:"$value.pattern_id"}}),o).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,n,t){"use strict";t.factory("CalendarInstance",["$log","$q","ModelInstance","shared-settings","OptionGroup",function(t,a,o,s,i){function r(n,t){return u().then(function(a){var o=this.days[c(n).valueOf()];return!!o&&e.find(a,function(e){return e.name===t}).value===o.type}.bind(this))}function c(e){return n(e,s.serverDateFormat).clone()}function u(){return l=l||i.valuesOf("hrleaveandabsences_work_day_type")}var l;return o.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return r.call(this,e,"non_working_day")},isWeekend:function(e){return r.call(this,e,"weekend")},isWorkingDay:function(e){return r.call(this,e,"working_day")},transformAttributes:function(n){var t={};return n.calendar.forEach(function(e){t[c(e.date).valueOf()]=e}),e(n).omit("calendar").assign({days:t}).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,n){"use strict";n.factory("Calendar",["$log","Model","WorkPatternAPI","CalendarInstance",function(n,t,a,o){return n.debug("Calendar"),t.extend({get:function(t,s,i,r){return n.debug("Calendar.get"),a.getCalendar(t,s,i,r).then(function(n){var a=n.values.map(function(e){return o.init(e)});return e.isArray(t)?a:a[0]})}})}])}),define("leave-absences/shared/apis/entitlement.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("EntitlementAPI",["$log","api",function(e,t){function a(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getremainder"].values;return a.length&&(t.remainder=a[0].remainder),delete t["api.LeavePeriodEntitlement.getremainder"],t}function o(e){var t=n.clone(e),a=t["api.LeavePeriodEntitlement.getentitlement"].values[0].entitlement;return t.value=a,delete t["api.LeavePeriodEntitlement.getentitlement"],t}return e.debug("EntitlementAPI"),t.extend({all:function(n,t){return e.debug("EntitlementAPI.all"),n["api.LeavePeriodEntitlement.getentitlement"]={entitlement_id:"$value.id"},t&&(n["api.LeavePeriodEntitlement.getremainder"]={entitlement_id:"$value.id",include_future:!0}),this.sendGET("LeavePeriodEntitlement","get",n,!1).then(function(e){return e.values}).then(function(e){return e=e.map(o),t&&(e=e.map(a)),e})},breakdown:function(n){return e.debug("EntitlementAPI.breakdown"),this.sendGET("LeavePeriodEntitlement","getbreakdown",n).then(function(e){return e.values})},getLeaveBalances:function(n,t,a,o,s){return e.debug("EntitlementAPI.getLeaveBalances"),this.getAll("LeavePeriodEntitlement",n,t,a,o,"getLeaveBalances",s)}})}])}),define("leave-absences/shared/apis/entitlement-log.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("EntitlementLogAPI",["$log","api",function(e,n){return e.debug("EntitlementLogAPI"),n.extend({all:function(n){return e.debug("EntitlementLogAPI.all"),this.sendGET("LeavePeriodEntitlementLog","get",n,!1).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/entitlement.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("EntitlementInstance",["$log","ModelInstance","EntitlementAPI",function(e,n,t){return e.debug("EntitlementInstance"),n.extend({defaultCustomData:function(){return{remainder:{current:0,future:0},breakdown:[]}},getBreakdown:function(){return t.breakdown({entitlement_id:this.id}).then(function(e){this.breakdown=e}.bind(this))}})}])}),define("leave-absences/shared/models/entitlement.model",["common/lodash","leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/entitlement.api","leave-absences/shared/apis/entitlement-log.api","leave-absences/shared/instances/entitlement.instance"],function(e,n){"use strict";n.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance","EntitlementLogAPI",function(n,t,a,o,s){return n.debug("Entitlement"),t.extend({all:function(e,n){return a.all(this.processFilters(e),n).then(function(e){return e.map(function(e){return o.init(e,!0)})})},breakdown:function(n,t){return a.breakdown(n).then(function(n){return t?(t.map(function(t){var a=e.find(n,function(e){return e.id===t.id});return a&&(t.breakdown=a.breakdown),t}),t):n.map(function(e){return o.init(e,!0)})})},logs:function(n){return n=e.cloneDeep(n||{}),n.contact_id&&(n["entitlement_id.contact_id"]=n.contact_id,delete n.contact_id),n.period_id&&(n["entitlement_id.period_id"]=n.period_id,delete n.period_id),n.return=n.return||[],n.return.push("entitlement_id","entitlement_id.type_id","editor_id","entitlement_amount","comment","created_date"),s.all(n)}})}])}),define("leave-absences/shared/apis/leave-request.api",["leave-absences/shared/modules/apis","common/lodash","common/services/api"],function(e,n){"use strict";e.factory("LeaveRequestAPI",["$log","api","$q","shared-settings",function(e,t,a){return e.debug("LeaveRequestAPI"),t.extend({all:function(n,t,o,s,i){e.debug("LeaveRequestAPI.all");var r=a.defer();return n&&n.contact_id&&n.contact_id.IN&&0===n.contact_id.IN.length?r.resolve({list:[],total:0,allIds:[]}):r.resolve(this.getAll("LeaveRequest",n,t,o,s,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();return t.contact_id&&t.period_id||o.reject("contact_id and period_id are mandatory"),t=n.defaults(t,{statuses:null,public_holiday:!1}),this.sendGET("LeaveRequest","getbalancechangebyabsencetype",t,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange",t),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){return e.values.breakdown=n.values(e.values.breakdown),e.values})},getBalanceChangeBreakdown:function(e){return this.sendGET("LeaveRequest","getBreakdown",{leave_request_id:e},!1)},getWorkDayForDate:function(e,n){return this.sendGET("LeaveRequest","getWorkDayForDate",{leave_date:e,contact_id:n.toString()},!1)},create:function(n){return e.debug("LeaveRequestAPI.create",n),this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]})},delete:function(e){return this.sendPOST("LeaveRequest","delete",{id:e})},deleteAttachment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,attachment_id:t}),this.sendPOST("LeaveRequest","deleteattachment",a).then(function(e){return e.values})},deleteComment:function(e,t){return t=n.assign({},t,{comment_id:e}),this.sendPOST("LeaveRequest","deletecomment",t).then(function(e){return e.values})},find:function(n){return e.debug("LeaveRequestAPI.find"),this.sendGET("LeaveRequest","getFull",{id:n},!1).then(function(e){return 0===e.values.length?a.reject("LeaveRequest not found with this ID"):e.values[0]})},getAttachments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getattachments",t,!1).then(function(e){return e.values})},getComments:function(e,t){return t=n.assign({},t,{leave_request_id:e}),this.sendGET("LeaveRequest","getcomment",t,!1).then(function(e){return e.values})},isManagedBy:function(n,t){return e.debug("LeaveRequestAPI.isManagedBy"),this.sendPOST("LeaveRequest","isManagedBy",{leave_request_id:n,contact_id:t}).then(function(e){return e.values})},isValid:function(t){e.debug("LeaveRequestAPI.isValid",t);var o=a.defer();return this.sendPOST("LeaveRequest","isValid",t).then(function(e){e.count>0?o.reject(n(e.values).map().flatten().value()):o.resolve(e.values)}),o.promise},saveComment:function(e,t,a){return a=n.assign({},a,{leave_request_id:e,text:t.text,contact_id:t.contact_id}),this.sendPOST("LeaveRequest","addcomment",a).then(function(e){return e.values})},update:function(n){return e.debug("LeaveRequestAPI.update",n),n.id?this.sendPOST("LeaveRequest","create",n).then(function(e){return e.values[0]}):a.reject("id is mandatory field")}})}])}),define("leave-absences/shared/instances/leave-request.instance",["common/lodash","common/moment","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance","leave-absences/shared/models/absence-type.model"],function(e,n,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI","AbsenceType",function(t,a,o,s,i,r,c){function u(e){return p(e).then(function(e){var n=this.status_id;return this.status_id=e.value,this.update().catch(function(e){return this.status_id=n,t.reject(e)}.bind(this))}.bind(this))}function l(){return c.all({id:this.type_id}).then(c.loadCalculationUnits).then(function(e){return t.all({calculatedBalanceChange:this.calculateBalanceChange(e[0].calculation_unit_name),currentBalanceChange:this.getBalanceChangeBreakdown()})}.bind(this)).then(function(e){return+e.currentBalanceChange.amount!=+e.calculatedBalanceChange.amount})}function d(e){return p(e).then(function(e){return this.status_id===e.value}.bind(this))}function m(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(r.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function f(e){return n.duration(e.time_to).subtract(n.duration(e.time_from)).asHours()}function p(n){return o.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return e.find(t,function(e){return e.name===n})})}function h(n){var a=e.cloneDeep(n),o=a.breakdown.length>1,s=e.first(e.values(a.breakdown)),i=e.last(e.values(a.breakdown));return t.all([this.getWorkDayForDate(s.date),o&&this.getWorkDayForDate(i.date)]).then(function(n){return s.amount=n[0].time_from?Math.min(this.from_date_amount,f(n[0])):0,o&&(i.amount=n[1].time_from?Math.min(this.to_date_amount,f(n[1])):0),a.amount=-1*e.reduce(a.breakdown,function(e,n){return e+n.amount},0),a}.bind(this))}function v(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(n){return function(){return r.saveComment(e,n)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return r.deleteComment(e.comment_id)})),t.all(n)}return i.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},calculateBalanceChange:function(n){var t=["contact_id","from_date","to_date","type_id","from_date_type","to_date_type"];return"hours"===n&&e.pull(t,"from_date_type","to_date_type"),r.calculateBalanceChange(e.pick(this,t)).then(function(e){return"hours"===n?h.call(this,e):e}.bind(this))},cancel:function(){return u.call(this,s.statusNames.cancelled)},approve:function(){return u.call(this,s.statusNames.approved)},checkIfBalanceChangeNeedsRecalculation:function(){return l.call(this)},reject:function(){return u.call(this,s.statusNames.rejected)},sendBack:function(){return u.call(this,s.statusNames.moreInformationRequired)},update:function(){return r.update(this.toAPI()).then(function(){return t.all([v.call(this),m.call(this)])}.bind(this))},create:function(){return r.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([v.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(n){if(n.comment_id)return void(n.toBeDeleted=!0);this.comments=e.reject(this.comments,function(e){return n.created_at===e.created_at&&n.text===e.text})},delete:function(){return r.delete(this.id)},getBalanceChangeBreakdown:function(){return r.getBalanceChangeBreakdown(this.id).then(function(n){return{amount:e.reduce(n.values,function(e,n){return e+parseFloat(n.amount)},0),breakdown:n.values.map(function(e){return{amount:Math.abs(parseFloat(e.amount)),date:e.date,type:{id:e.id,value:e.type,label:e.label}}})}})},getWorkDayForDate:function(e){return r.getWorkDayForDate(e,this.contact_id).then(function(e){return e.values}).catch(function(e){return t.reject(e)})},isValid:function(){return r.isValid(this.toAPI())},isApproved:function(){return d.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return d.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return d.call(this,s.statusNames.cancelled)},isRejected:function(){return d.call(this,s.statusNames.rejected)},isSentBack:function(){return d.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?r.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):a(s.permissions.admin.administer).then(function(n){return n?"admin":r.isManagedBy(this.id,e).then(function(e){return e?"manager":"none"})}.bind(this))},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])},loadAttachments:function(){return this.id?r.getAttachments(this.id).then(function(e){this.files=e}.bind(this)):t.resolve()}})}])}),define("leave-absences/shared/models/leave-request.model",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/leave-request.api","leave-absences/shared/instances/leave-request.instance"],function(e){"use strict";e.factory("LeaveRequest",["$log","Model","LeaveRequestAPI","LeaveRequestInstance",function(e,n,t,a){return e.debug("LeaveRequest"),n.extend({all:function(e,n,o,s,i){return t.all(this.processFilters(e),n,o,s,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e){return t.balanceChangeByAbsenceType(this.processFilters(e))},find:function(e){return t.find(e).then(function(e){return a.init(e,!0)})}})}])}),define("leave-absences/shared/apis/public-holiday.api",["leave-absences/shared/modules/apis","common/services/api"],function(e){"use strict";e.factory("PublicHolidayAPI",["$log","api",function(e,n){return e.debug("PublicHolidayAPI"),n.extend({all:function(n){return e.debug("PublicHolidayAPI"),this.sendGET("PublicHoliday","get",n).then(function(e){return e.values})}})}])}),define("leave-absences/shared/instances/public-holiday.instance",["leave-absences/shared/modules/models-instances","common/models/instances/instance"],function(e){"use strict";e.factory("PublicHolidayInstance",["$log","ModelInstance",function(e,n){return e.debug("PublicHolidayInstance"),n.extend({})}])}),define("leave-absences/shared/models/public-holiday.model",["common/moment","leave-absences/shared/modules/models","common/models/model","common/services/hr-settings","leave-absences/shared/apis/public-holiday.api","leave-absences/shared/instances/public-holiday.instance"],function(e,n){"use strict";n.factory("PublicHoliday",["$log","Model","PublicHolidayAPI","PublicHolidayInstance","shared-settings",function(n,t,a,o,s){return n.debug("PublicHoliday"),t.extend({all:function(e){return n.debug("PublicHoliday.all",e),a.all(e).then(function(e){return e.map(function(e){return o.init(e,!0)})})},isPublicHoliday:function(t){n.debug("PublicHoliday.isPublicHoliday",t);var o=e(t).format(s.serverDateFormat),i={date:o};return a.all(i).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular","common/modules/directives","common/modules/models","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/models"],function(e){return e.module("leave-absences.components",["common.directives","common.models","leave-absences.settings","leave-absences.models"])}),define("leave-absences/shared/modules/controllers",["common/angular","common/angularBootstrap","leave-absences/shared/modules/models","leave-absences/shared/modules/models-instances","leave-absences/shared/modules/shared-settings"],function(e){return e.module("leave-absences.controllers",["ui.select","leave-absences.models","leave-absences.models.instances","leave-absences.settings"])}),define("leave-absences/shared/controllers/sub-controllers/leave-calendar-admin.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers","common/models/contract","common/services/notification.service"],function(e,n,t){function a(n,t,a,o,s,i,r){function c(){return{loadContacts:function(){return l.loadContactsForAdmin()}}}function u(e){i.info("",["

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 l,d;return{init:function(n){return d=n,l=r.init(d),d.filters.userSettings.assignedTo=e.find(d.filtersByAssignee,{type:"me"}),d.showContactDetailsLink=!0,d.showContactName=!0,d.showFilters=!0,d.showAdminFilteringHint=u,c()}}}t.controller("LeaveCalendarAdminController",["$log","$q","Contact","ContactInstance","Contract","notificationService","LeaveCalendarService",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(n,t,a,o){function s(){return{loadContacts:function(){return i.loadLookUpAndFilteredContacts()}}}n.debug("LeaveCalendarManagerController");var i,r;return{init:function(n){return r=n,i=o.init(r),r.filters.userSettings.assignedTo=e.find(r.filtersByAssignee,{type:"me"}),r.showContactName=!0,r.showFilters=!0,s()}}}t.controller("LeaveCalendarManagerController",["$log","Contact","ContactInstance","LeaveCalendarService",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,t,a){function o(){return{loadContacts:function(){return i.displaySingleContact?s.loadFilteredContacts():"admin"===i.userPermissionRole?s.loadContactsForAdmin():s.loadLookUpAndFilteredContacts()}}}e.debug("LeaveCalendarStaffController");var s,i;return{init:function(e){return i=e,s=a.init(i),i.filters.userSettings.contacts_with_leaves=!0,i.showTheseContacts=[i.contactId],i.showContactName=!0,i.showFilters=!0,i.displaySingleContact&&(i.showFilters=!1,i.lookupContacts=[{id:i.contactId}]),o()}}}t.controller("LeaveCalendarStaffController",["$log","$q","Contact","LeaveCalendarService",a])}),define("leave-absences/shared/components/leave-calendar.component",["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){function a(t,a,o,s,i,r,c,u,l,d){function m(){N().then(g).then(b).then(_).then(S).then(function(){return a.all([C(),D(),I(),W.showFilters?R():e.noop])}).then(function(){f(),y(),B()}).then(function(){W.loading.page=!1})}function f(){W.supportData.absenceTypes.push({id:"",title:"Leave",color:"#4D4D68",calculation_unit:e.chain(W.supportData.calculationUnits).find({name:"days"}).get("value").value()})}function p(){for(var e=[],t=n(W.selectedPeriod.start_date).clone().startOf("month"),a=n(W.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(L(t)),t.add(1,"month");W.months=e}function h(){return e.includes(["admin","manager"],W.userPermissionRole)}function v(e){return e.format("YYYY-MM")}function b(){s.$on("LeaveCalendar::updateFiltersByAbsenceType",function(e,n){W.supportData.absenceTypesToFilterBy=n,M(!0)})}function g(){s.$new().$watch(function(){return W.selectedMonthIndex},function(e,n){null!==n&&e!==n&&(F(),B(),M())})}function y(e){W.injectMonth=!0,j("injected").then(function(){M(e)}).then(function(){W.loading.calendar=!1})}function _(){U=t("LeaveCalendar"+e.capitalize(H)+"Controller").init(W)}function q(e){return e.current?"Current Period ("+e.title+")":e.title}function C(){return r.all().then(function(n){W.absencePeriods=e.sortBy(n,"start_date"),W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current})}).then(p).then(x)}function T(){return c.all().then(c.loadCalculationUnits)}function A(){return l.valuesOf(["hrleaveandabsences_absence_type_calculation_unit","hrleaveandabsences_leave_request_day_type","hrleaveandabsences_leave_request_status","hrleaveandabsences_toil_amounts"])}function D(){return U.loadContacts().then(function(e){W.contacts=e})}function R(){return l.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){W.filters.optionValues.regions=e.hrjc_region,W.filters.optionValues.locations=e.hrjc_location,W.filters.optionValues.levelTypes=e.hrjc_level_type,W.filters.optionValues.departments=e.hrjc_department})}function P(){return u.all()}function I(){return a.all([T(),P(),A()]).then(function(n){W.supportData.absenceTypes=n[0],W.supportData.publicHolidays=n[1],W.supportData.calculationUnits=n[2].hrleaveandabsences_absence_type_calculation_unit,W.supportData.dayTypes=n[2].hrleaveandabsences_leave_request_day_type,W.supportData.leaveRequestStatuses=n[2].hrleaveandabsences_leave_request_status,W.supportData.toilAmounts=e.indexBy(n[2].hrleaveandabsences_toil_amounts,"value")})}function S(){var e=a.resolve();return W.injectMonth&&(e=j("destroyed"),W.injectMonth=!1),e}function L(e){return{index:v(e),month:e.month(),year:e.year(),name:e.format("MMMM"),moment:n().year(e.year()).month(e.month())}}function w(){var n=W.selectedPeriod.id;W.selectedPeriod=e.find(W.absencePeriods,function(e){return!!e.current}),n!==W.selectedPeriod.id&&p(),x(),B(),O("month")}function k(e){var t="previous"===e?"subtract":"add";F(n(W.selectedMonth.moment)[t](1,"month")),B(),O("month")}function O(n){n=e.includes(["contacts","period","month"],n)?n:"period",a.resolve().then(S).then("period"===n&&p).then("period"===n&&$).then("contacts"===n&&D).then("month"===n&&B).then(function(){y("contacts"===n)})}function M(e){s.$emit("LeaveCalendar::showMonth",!!e)}function x(){F(n())}function $(){F(W.months[0].moment)}function E(t){var a="previous"===t?"first":"last",o=e[a](W.months),s=n().year(o.year).month(o.month);W.monthPaginatorsAvailability[t]=!W.selectedMonth.moment.isSame(s,"month")}function B(){E("previous"),E("next")}function F(n){n&&(W.selectedMonthIndex=v(n)),W.selectedMonth=e.find(W.months,{index:W.selectedMonthIndex})}function N(){return a.all([d(i.permissions.admin.administer),d(i.permissions.ssp.manage)]).then(function(e){W.userPermissionRole=e[0]?"admin":e[1]?"manager":"staff",H=W.roleOverride?W.roleOverride:W.userPermissionRole})}function j(n){return a(function(t){var a=s.$on("LeaveCalendar::month"+e.capitalize(n),function(){a(),t()})})}o.debug("Component: leave-calendar");var U,H,W=this;W.absencePeriods=[],W.contacts=[],W.contactIdsToReduceTo=null,W.injectMonth=!1,W.months=[],W.selectedMonth={},W.selectedMonthIndex="",W.selectedPeriod=null,W.showContactName=!1,W.showFilters=!1,W.userPermissionRole="staff",W.loading={calendar:!0,page:!0},W.filters={hideOnMobile:!0,optionValues:{},userSettings:{contact:null,contacts_with_leaves:!0,department:null,level_type:null,location:null,region:null},absenceTypes:{}},W.filtersByAssignee=[{type:"me",label:"People I approve"},{type:"unassigned",label:"People without approver"},{type:"all",label:"All"}],W.filters.userSettings.assignedTo=W.filtersByAssignee[2],W.monthPaginatorsAvailability={previous:!0,next:!0},W.supportData={absenceTypesToFilterBy:[]},W.$onInit=m,W.canManageRequests=h,W.labelPeriod=q,W.navigateToCurrentMonth=w,W.paginateMonth=k,W.refresh=O}t.component("leaveCalendar",{bindings:{contactId:"<",displaySingleContact:"0,t={from_date:{to:Q.month.days[Q.month.days.length-1].date+" 23:59:59"},to_date:{from:Q.month.days[0].date+" 00:00:00"},status_id:{IN:k()},contact_id:{IN:Q.contacts.map(function(e){return e.id})},type_id:{IN:n?Q.supportData.absenceTypesToFilterBy:e.pluck(Q.supportData.absenceTypes,"id")}};return y(),i.all(t,null,null,null,!1).then(function(e){return X={},n&&(e.list=q(e.list)),A(e.list)})}function x(){var n=Q.month.days[0].date,t=Q.month.days[Q.month.days.length-1].date;return s.get(Q.contacts.map(function(e){return e.id}),n,t).then(function(n){z=e.indexBy(n,"contact_id")})}function $(){return Q.contactIdsToReduceTo&&(Q.contacts=Q.contacts.filter(function(n){return e.includes(Q.contactIdsToReduceTo,n.contact_id)||e.find(X,function(e){return e.contact_id===n.contact_id})})),a.resolve()}function E(n){var t=L(n);X[n.contact_id]=X[n.contact_id]||{},t.forEach(function(t){e.remove(X[n.contact_id][t.date],function(e){return e.id===n.id})})}function B(){o.$emit("LeaveCalendar::monthDestroyed"),V.map(function(e){e.remove?e.remove():e()})}function F(n,t,o){var s,i;return n.contactsData[t]=n.contactsData[t]||{},i=f(t),s=!0===o?a.resolve():a.all([i.isWeekend(h(n.date)),i.isNonWorkingDay(h(n.date))]).then(function(a){e.assign(n.contactsData[t],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:I(n.date)})}),s.then(function(){return X[t]&&X[t][n.date]?X[t][n.date]:[]}).then(function(a){a=U(a),e.assign(n.contactsData[t],{leaveRequests:a,leaveRequestsToShowInCell:b(a),leaveRequestsAttributes:C(n,a)})})}function N(){return a.all(Q.month.days.map(function(e){return a.all(Q.contacts.map(function(n){return F(e,n.id)}))}))}function j(e,n){Q.currentPage=0,Q.visible=!0,(n||!G)&&O()}function U(t){return e.sortBy(t,function(e){return+n(e.from_date).format("X")+(R("half_day_pm",e,e.from_date)?1:0)})}function H(n){var t=e.find(Q.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 W(e){v(e),-1!==k().indexOf(e.status_id)&&l(e)}function Y(e){return a.all(L(e).map(function(n){return F(n,e.contact_id,!0)}))}t.debug("Component: leave-calendar-month");var G=!1,V=[],z={},X={},Q=this;Q.currentPage=0,Q.pageSize=20,Q.visible=!1,Q.showContactName=!!Q.showContactName,Q.showOnlyWithLeaveRequests=!!Q.showOnlyWithLeaveRequests,Q.$onDestroy=B,Q.$onInit=u,Q.contactsList=p,Q.getContactUrl=_}t.component("leaveCalendarMonth",{bindings:{showTheseContacts:"<",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/models/contact","common/models/session.model","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,l,d,m){function f(){a.resolve().then(_).then(C).then(function(){return y()&&"admin"!==w.role&&P()}).then(R).finally(function(){w.loading.component=!1})}function p(n){L=w.leaveRequest.status_id,e.includes(["cancel","reject","delete"],n)||"toil"===w.leaveRequest.request_type?i.open(q(n)):b(n)}function h(){return"admin"===w.role&&"public_holiday"===w.leaveRequest.request_type}function v(t){var a=w.absenceTypes[w.leaveRequest.type_id].allow_request_cancelation;return"admin"===w.role||("manager"===w.role?e.includes([k.awaitingApproval,k.moreInformationRequired],t):"3"===a?n().isBefore(w.leaveRequest.from_date):"2"===a)}function b(n){i.open({title:"Verifying balance...",loading:!0,optionsPromise:function(){return w.leaveRequest.checkIfBalanceChangeNeedsRecalculation().then(function(t){return t?e.assign(c.getBalanceChangeRecalculationPromptOptions(),{onCloseAfterConfirm:function(){A(n)}}):q(n)})}})}function g(){return s.find(S).then(function(e){return e.checkIfSelfLeaveApprover()})}function y(){return S===w.leaveRequest.contact_id}function _(){e.isArray(w.leaveRequestStatuses)&&(w.leaveRequestStatuses=e.indexBy(w.leaveRequestStatuses,"value")),e.isArray(w.absenceTypes)&&(w.absenceTypes=e.indexBy(w.absenceTypes,"id"))}function q(e){var n=O[e].dialog;return{title:"Confirm "+n.title+"?",copyCancel:"Cancel",copyConfirm:n.btnLabel,classConfirm:"btn-"+n.btnClass,msg:n.msg,onConfirm:function(){return w.leaveRequest[e]().then(function(){D(e)}).catch(function(e){d.error("Error:",e)})}}}function C(){return m.get().then(function(e){S=e.contactId})}function T(e,n){e.stopPropagation(),r.openModal(n)}function A(e){r.openModal({leaveRequest:w.leaveRequest,leaveType:w.leaveRequest.request_type,selectedContactId:w.leaveRequest.contact_id,forceRecalculateBalanceChange:!0,defaultStatus:l.statusNames[M[e]]})}function D(n){var t=e.find(w.leaveRequestStatuses,function(e){return e.name===l.statusNames.awaitingApproval}).value;L===t&&u.publish("ManagerBadge:: Update Count"),u.publish("LeaveRequest::statusUpdate",{status:n,leaveRequest:w.leaveRequest})}function R(){var n=w.leaveRequestStatuses[w.leaveRequest.status_id].name,t=e.compact(e.map(O,function(t,a){return e.includes(t.allowedStatuses,n)?a:null}));!v(n)&&e.pull(t,"cancel"),"admin"!==w.role&&e.pull(t,"delete"),"staff"===w.role&&e.pull(t,"approve","reject"),"staff"!==w.role&&I(t),h()&&t.push("delete"),w.allowedActions=e.map(t,function(e){return{key:e,label:O[e].label,isDirectAction:O[e].isDirectAction}})}function P(){return g().then(function(e){e&&(w.role="admin")})}function I(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 S,L,w=this,k=l.statusNames,O={edit:{label:"Edit",allowedStatuses:[k.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[k.moreInformationRequired]},view:{label:"View",allowedStatuses:[k.approved,k.rejected,k.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[k.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[k.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[k.awaitingApproval,k.approved,k.rejected,k.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[k.awaitingApproval,k.moreInformationRequired,k.approved,k.rejected,k.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}},M={approve:"approved"};w.allowedActions=[],w.loading={component:!0},w.$onInit=f,w.action=p,w.openLeavePopup=T}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","$q","$rootScope","Contact","dialog","LeavePopup","LeaveRequestService","pubSub","shared-settings","notificationService","Session"]}),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(){o.$emit("LeaveRequestPopup::addTab",C),y(),_()}function l(){C.request.comments.push({contact_id:q,leave_request_id:C.request.id,text:C.comment.text}),C.comment.text=""}function d(){return C.comment.text.length>0}function m(e){return!e.comment_id||C.canManage}function f(e){return n.utc(e,i.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")}function p(){return C.request.comments.filter(function(e){return!e.toBeDeleted})}function h(e){return e===q?"Me":C.comment.contacts[e]?C.comment.contacts[e].display_name:void 0}function v(e){return C.mode===e}function b(){C.comment.text.length&&C.addComment()}function g(){var n=e.indexBy(C.request.comments,"contact_id"),t=Object.keys(n);return r.all({id:{IN:t}},{page:1,size:0}).then(function(n){C.comment.contacts=e.indexBy(n.list,"contact_id")})}function y(){return C.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),C.request.comments.length&&g()})}function _(){return C.loading.component=!0,c.get().then(function(e){q=e.contactId}).then(function(){C.loading.component=!1})}t.debug("Component: leave-request-popup-comments-tab");var q=null,C=this;C.loading={component:!0},C.comment={text:"",contacts:{}},C.$onInit=u,C.addComment=l,C.canRemoveComment=m,C.canSubmit=d,C.formatDateTime=f,C.getActiveComments=p,C.getCommentorName=h,C.isMode=v,C.onBeforeSubmit=b}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(){t("RequestModalDetails"+e.capitalize(T(te.leaveType,te.request))+"Controller",{detailsController:te}),te.canManage=te.isRole("manager")||te.isRole("admin"),te.loading.tab=!0,s.$emit("LeaveRequestPopup::addTab",te),S(),te.initChildController().then(function(){return i.all([$(),x()])}).then(!te.isMode("create")&&I).then(Y).then(function(){if(!te.isMode("create"))return i.resolve().then(te.initTimesExtended).then(z)}).then(!te.isMode("create")&&W).then(L).then(G).then(P).then(w).then(!te.isMode("view")&&te.initWatchersExtended).catch(R).then(function(){te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.totalItems=te.balance.change.breakdown.length}).finally(function(){te.loading.tab=!1})}function p(){te.balance.closing=te.balance.opening+te.balance.change.amount}function h(e){return n(e,c.serverDateFormat).toDate()}function v(e){return n(e).format(c.serverDateFormat)}function b(e){var n;return i.resolve().then(function(){U(e),"from"===e&&j(),k("hours")&&(_(e),"from"!==e||te.uiOptions.multipleDays||_("to")),te.loading[e+"DayTypes"]=!0}).then(function(){return C(e)}).then(function(e){if(n=e.id!==te.period.id,n&&(te.period=e),!te.period.id)return i.reject("Please change date as it is not in any absence period")}).then(W).then(function(){if(n)return $()}).then(function(){return te.onDateChangeExtended&&te.onDateChangeExtended(e)}).then(function(){if(z(),!n)return B();o.$broadcast("LeaveRequestPopup::absencePeriodChanged")}).catch(R).finally(q)}function g(){return z(),B()}function y(){return te.uiOptions.toDate=null,U("to"),i.resolve().then(z).then(te.setDaysSelectionModeExtended).then(q).then(!te.uiOptions.multipleDays&&B)}function _(e){te.uiOptions.times[e].loading=!0}function q(){["from","to"].forEach(function(e){te.loading[e+"DayTypes"]=!1,k("hours")&&(te.uiOptions.times[e].loading=!1)})}function C(t){var a=n(te.uiOptions[t+"Date"]).format(te.uiOptions.userDateFormat.toUpperCase());return e.find(te.absencePeriods,function(e){return e.isInPeriod(a)})||{}}function T(){return te.request?te.request.request_type:te.leaveType||null}function A(e){return n().set({hours:e.split(":")[0],minutes:e.split(":")[1]})}function D(){return X(),te.loading.balanceChange=!0,te.request.getBalanceChangeBreakdown().then(H).catch(R)}function R(n){o.$broadcast("LeaveRequestPopup::handleError",e.isArray(n)?n:[n]),te.loading.fromDayTypes=!1,te.loading.balanceChange=!1,te.loading.tab=!1,te.loading.toDayTypes=!1}function P(){return te.isMode("create")||te.forceRecalculateBalanceChange?B():D()}function I(){var e=te.request.attributes();return te.uiOptions.fromDate=h(te.request.from_date),te.request.to_date=e.to_date,te.request.to_date_type=e.to_date_type,te.uiOptions.toDate=h(te.request.to_date),te.initDayTypesExtended?te.initDayTypesExtended():i.resolve()}function S(){ne.push(o.$on("LeaveRequestPopup::absenceTypeChanged",function(){J()}),o.$on("LeaveRequestPopup::absencePeriodBalancesUpdated",function(e,n){K(n)}),o.$on("LeaveRequestPopup::recalculateBalanceChange",B))}function L(){te.isMode("edit")&&(te.isLeaveStatus(c.statusNames.approved)||te.isLeaveStatus(c.statusNames.adminApproved))&&(ee={absenceTypeId:te.request.type_id,value:te.selectedAbsenceType.remainder-te.request.balance_change})}function w(){o.$watch(function(){return te.uiOptions.times.from.time},function(e,n){e!==n&&(te.uiOptions.multipleDays||(Z(e),z()))})}function k(e){return te.selectedAbsenceType.calculation_unit_name===e}function O(e){return te.request.request_type===e}function M(n){return e.includes(["weekend","non_working_day","public_holiday"],n)}function x(){return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(e){te.requestDayTypes=e})}function $(){return u.get(te.request.contact_id,te.period.start_date,te.period.end_date).then(function(e){te.calendar=e})}function E(){var e=(te.pagination.currentPage-1)*te.pagination.numPerPage,n=e+te.pagination.numPerPage;te.pagination.filteredbreakdown=te.balance.change.breakdown.slice(e,n)}function B(){return X(),te.canCalculateChange()?(te.loading.balanceChange=!0,te.request.change_balance=!0,te.calculateBalanceChange().then(H).catch(R).finally(function(){te.loading.balanceChange=!1})):i.resolve()}function F(){te.pagination.totalItems=te.balance.change.breakdown.length,te.pagination.filteredbreakdown=te.balance.change.breakdown,te.pagination.pageChanged()}function N(){return v(te.request.from_date)===v(te.request.to_date)}function j(){te.uiOptions.toDate&&te.uiOptions.fromDate&&te.uiOptions.multipleDays&&n(te.uiOptions.toDate).isSameOrBefore(te.uiOptions.fromDate)&&(te.uiOptions.toDate=null,U("to"))}function U(e){te.resetUIInputsExtended&&te.resetUIInputsExtended(e),z(),X()}function H(e){te.balance.change=e,te.request.balance_change=e.amount,p(),F(),te.loading.balanceChange=!1}function W(){var e,t,a;te.uiOptions.fromDate?(e=n(te.uiOptions.fromDate).add(1,"day").toDate(),a=e,t=e):(a=h(te.period.start_date),t=te.uiOptions.date.to.options.minDate),te.uiOptions.date.to.options.initDate=t,te.uiOptions.date.to.options.minDate=a,te.uiOptions.date.to.options.maxDate=h(te.period.end_date)}function Y(){return!te.isMode("create")&&N()||te.isMode("create")&&(O("sickness")||k("hours"))?te.uiOptions.multipleDays=!1:te.uiOptions.multipleDays=!0,i.resolve().then(te.setDaysSelectionModeExtended)}function G(){ee&&ee.absenceTypeId===te.selectedAbsenceType.id?te.balance.opening=ee.value||0:te.balance.opening=te.selectedAbsenceType.remainder}function V(){te.selectedAbsenceType=e.find(te.absenceTypes,function(e){return e.id===te.request.type_id})}function z(){var e=te.uiOptions,n=e.times;te.request.from_date=e.fromDate?v(e.fromDate):null,te.request.to_date=e.toDate?v(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),(k("hours")||O("toil"))&&(te.request.from_date=te.request.from_date&&n.from.time?te.request.from_date+" "+n.from.time:null,te.request.to_date=te.request.to_date&&n.to.time?te.request.to_date+" "+n.to.time:null)}function X(){te.uiOptions.showBalance=te.canCalculateChange()}function Q(){e.forEach(ne,function(e){e()})}function J(){var e,n=te.selectedAbsenceType.calculation_unit_name;return V(),e=n!==te.selectedAbsenceType.calculation_unit_name,G(),i.resolve().then(e&&Y).then(e&&te.onAbsenceTypeUpdateExtended).then(e&&z).then(q).then(B)}function K(e){return te.absenceTypes=e,V(),n(te.uiOptions.toDate).isAfter(te.period.end_date)&&(te.uiOptions.toDate=void 0,U("to")),G(),B()}function Z(e){var n=A(e).add(te.uiOptions.time_interval,"minutes");n.isAfter(A(te.uiOptions.times.to.max))||(te.uiOptions.times.to.min=n.format("HH:mm"),n.isAfter(A(te.uiOptions.times.to.time))&&(te.uiOptions.times.to.time=""))}a.debug("Component: leave-request-popup-details-tab");var ee=null,ne=[],te=this;te.canManage=!1,te.calendar={},te.errors=[],te.isRequired=!0,te.requestDayTypes=[],te.statusNames=c.statusNames,te.loading={tab:!1,balanceChange:!1,fromDayTypes:!1,toDayTypes:!1},te.pagination={currentPage:1,filteredbreakdown:[],numPerPage:7,totalItems:0,pageChanged:E},te.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},te.$onInit=f,te.convertDateFormatFromServer=h,te.convertDateToServerFormat=v,te.dateChangeHandler=b,te.dateTypeChangeHandler=g,te.daysSelectionModeChangeHandler=y,te.disableAndShowLoadingTimeInput=_,te.getMomentDateWithGivenTime=A,te.handleError=R,te.isCalculationUnit=k,te.isLeaveType=O,te.isNotWorkingDay=M,te.performBalanceChangeCalculation=B,te.setRequestDateTimesAndDateTypes=z,te.updateEndTimeInputMinTime=Z,te.$onDestroy=Q}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(){o.$broadcast("LeaveRequestPopup::childComponent::register"),s.$emit("LeaveRequestPopup::addTab",w),y(),a.all([A(),C()]).then(_).finally(function(){w.filesLoaded=!0})}function m(){return w.fileUploader&&w.fileUploader.queue.length>0}function f(){return w.getFilesAmount()0?I.map(function(e){return e.label}).join(", "):""}function C(){return w.request.loadAttachments().then(function(){o.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function T(){return a.all(I.map(function(e){return l.getMimeTypeFor(e.label).then(function(n){L[e.label]=n})})).catch(function(){L=null})}function A(){return c.valuesOf("safe_file_extension").then(function(e){I=e})}function D(e){return!e.attachment_id||w.canManage}function R(){e.forEach(S,function(e){e()})}function P(e,n){w.fileUploader.queue&&w.fileUploader.queue.length>0?w.fileUploader.uploadAll({entityID:w.request.id}).then(function(){n()}).catch(n):n()}t.debug("Component: leave-request-popup-files-tab");var I=[],S=[],L={},w=Object.create(this);return w.filesLoaded=!1,w.fileUploader=null,w.today=Date.now(),w.userDateFormatWithTime=i.DATE_FORMAT+" HH:mm",w.userDateFormat=i.DATE_FORMAT,w.$onDestroy=R,w.$onInit=d,w.canRemoveAttachment=D,w.canSubmit=m,w.canUploadMore=f,w.formatDateTime=p,w.getAuthorName=h,w.getFilesAmount=v,w.listFileTypes=q,w}t.component("leaveRequestPopupFilesTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-popup/leave-request-popup-files-tab.html"}],controllerAs:"filesTab",controller:["$log","$q","$rootScope","$scope","HR_settings","shared-settings","OptionGroup","FileUpload","fileMimeTypes",a]})}),define("leave-absences/shared/components/leave-request-record-actions.component",["leave-absences/shared/modules/components","common/services/hr-settings","common/services/before-hash-query-params.service"],function(e){function n(e,n,t){function a(){s=t.parse(),s.openModal&&o({leaveType:s.openModal,selectedContactId:i.selectedContactId})}function o(e){n.openModal(e)}e.debug("Component: leave-request-record-actions");var s,i=this;i.leaveRequestOptions=[{type:"leave",icon:"briefcase",label:"Leave"},{type:"sickness",icon:"stethoscope",label:"Sickness"}],i.$onInit=a,i.openLeavePopup=o}e.component("leaveRequestRecordActions",{bindings:{contactId:"<",selectedContactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-request-record-actions.html"}],controllerAs:"vm",controller:["$log","LeavePopup","beforeHashQueryParams",n]})}),define("leave-absences/shared/components/staff-leave-report.component",["common/lodash","common/moment","leave-absences/shared/modules/components","common/services/pub-sub"],function(e,n,t){function a(n,t,a,o,s,i,r,c,u,l,d,m){function f(){t.all([q(),E(),A(),T()]).then(function(){z.loading.page=!1}).then(function(){return t.all([P(),R()])}).then(B).then(function(){z.loading.content=!1}),j()}function p(e,n){n.data.push(e),n.dataIndex[e.id]=e}function h(){z.absenceTypes=z.absenceTypes.map(function(n){var t=e.find(z.entitlements,function(e){return e.type_id===n.id});return n.entitlement=t?t.value:0,n.remainder=t?t.remainder:{current:0,future:0},n})}function v(e){U(e),z.sections.other.open&&p(e,z.sections.other)}function b(){Object.values(z.sections).forEach(function(e){e.data=[]})}function g(){z.absenceTypesFiltered=z.absenceTypes.filter(function(e){return!(0===e.entitlement&&"1"!==e.allow_overuse&&"1"!==e.allow_accruals_request)})}function y(e){var n=V[e.status];n?n(e.leaveRequest):z.refresh()}function _(n){n.dataIndex=e.indexBy(n.data,"id")}function q(){return z.role="staff","absence-tab"===a.section?(z.role="admin",t.resolve()):o(m.permissions.admin.administer).then(function(e){e&&(z.role="admin")})}function C(e){return e.current?"Current Period ("+e.title+")":e.title}function T(){return s.all().then(function(n){z.absencePeriods=e.sortBy(n,"start_date"),z.selectedPeriod=e.find(z.absencePeriods,function(e){return!0===e.current})})}function A(){return i.all().then(i.loadCalculationUnits).then(function(n){z.absenceTypes=n,z.absenceTypesIndexed=e.indexBy(n,"id")})}function D(){return w("approved",{status_id:G(m.statusNames.approved)})}function R(){var n={contact_id:z.contactId,period_id:z.selectedPeriod.id};return t.all([c.balanceChangeByAbsenceType(e.assign({},n,{public_holiday:!0})),c.balanceChangeByAbsenceType(e.assign({},n,{expired:!0 -})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.approved)]}})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}}))]).then(function(e){z.absenceTypes.forEach(function(n){n.balanceChanges={holidays:e[0][n.id],expired:e[1][n.id],approved:e[2][n.id],pending:e[3][n.id]}})})}function P(){return r.all({contact_id:z.contactId,period_id:z.selectedPeriod.id},!0).then(function(e){z.entitlements=e})}function I(){return r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id},z.entitlements).then(function(){return F(z.entitlements)}).then(function(e){z.sections.entitlements.data=e})}function S(){return t.all([r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id,expired:!0}),L({request_type:"toil",expired:!0})]).then(function(e){return t.all({expiredBalanceChangesFlatten:F(e[0]),expiredTOILS:N(e[1].list)})}).then(function(n){z.sections.expired.data=n.expiredBalanceChangesFlatten.concat(n.expiredTOILS),z.sections.expired.data=e.sortBy(z.sections.expired.data,"expiry_date")})}function L(n){return c.all(e.assign({contact_id:z.contactId,from_date:{from:z.selectedPeriod.start_date},to_date:{to:z.selectedPeriod.end_date},type_id:{IN:z.absenceTypes.map(function(e){return e.id})}},n),null,"from_date ASC",null,!1)}function w(e,n){return L(n).then(function(n){z.sections[e].data=n.list})}function k(){return t.all(Object.values(z.sections).filter(function(e){return e.open}).map($))}function O(){return w("other",{status_id:{in:[G(m.statusNames.rejected),G(m.statusNames.cancelled)]}})}function M(){return w("pending",{status_id:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}})}function x(){return w("holidays",{public_holiday:!0})}function $(e){return e.loading=!0,e.loadLeaveRequests().then(_.bind(this,e)).then(function(){e.loading=!1})}function E(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){z.leaveRequestStatuses=e.indexBy(n,"value")})}function B(){h(),g()}function F(n){return t.resolve().then(function(){return n.map(function(n){var t=e.find(z.entitlements,function(e){return e.id===n.id});return n.breakdown.map(function(n){return e.assign(e.clone(n),{type_id:t.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function N(n){return t.resolve().then(function(){return n.map(function(n){return e.assign({},n,{expiry_date:n.toil_expiry_date,amount:n.toil_to_accrue,type:{label:"Accrued TOIL"}})})})}function j(){l.subscribe("LeaveRequest::new",function(){z.refresh()}),l.subscribe("LeaveRequest::edit",function(){z.refresh()}),l.subscribe("LeaveRequest::statusUpdate",y),l.subscribe("LeaveRequest::delete",function(e){U(e)})}function U(n){e.forEach(z.sections,function(t,a){t.dataIndex[n.id]&&(e.remove(t.data,function(e){return e.id===n.id}),delete t.dataIndex[n.id],"other"!==a&&H(n,a))})}function H(n,t){var a=["future","current"],o=z.absenceTypesIndexed[n.type_id];"pending"===t&&e.pull(a,"current"),o.balanceChanges[t]-=n.balance_change,a.forEach(function(e){o.remainder[e]-=n.balance_change})}function W(){z.loading.content=!0,t.all([P(),R()]).then(B).then(function(){z.loading.content=!1}).then(function(){return t.all([k(),b()])})}function Y(e){var n=z.sections[e];n.open=!n.open,n.open&&!n.data.length&&$(n)}function G(n){return e.find(z.leaveRequestStatuses,function(e){return e.name===n}).value}n.debug("Component: staff-leave-report");var V={delete:U,cancel:v},z=this;z.absencePeriods=[],z.absenceTypes=[],z.absenceTypesFiltered=[],z.absenceTypesIndexed={},z.dateFormat=d.DATE_FORMAT,z.leaveRequestStatuses={},z.selectedPeriod=null,z.role=null,z.loading={content:!0,page:!0},z.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:x},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:M},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O}},z.$onInit=f,z.labelPeriod=C,z.refresh=W,z.toggleSection=Y}t.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:a}),a.$inject=["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,n=!!e.from_date&&!!e.to_date,t=i.selectedAbsenceType.calculation_unit_name;return"days"===t?n=n&&!!e.from_date_type&&!!e.to_date_type:"hours"===t&&(n=n&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),n}function d(){return i.canCalculateChange()}function m(n,t){var a=i.uiOptions.times[n],o=e.clone(t.time_from),s=e.clone(t.time_to);i.uiOptions.multipleDays||("from"===n&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===n&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===n?a.max:a.min}function f(n,t){return n?(n=i.convertDateToServerFormat(n),v(n).then(function(t){return t?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(n,i.requestDayTypes).then(function(n){return n.length?n:i.requestDayTypes.filter(function(n){return e.includes(["all_day","half_day_am","half_day_pm"],n.name)})})}).then(function(e){return I(t,e),e})):o.reject([])}function p(e,t){return e=n(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(n){return n.name===e}):[]})}function h(e,t){return n.duration(t).subtract(n.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function y(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,n){i.isCalculationUnit("days")||+e==+n||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function _(e){var t=n(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,t)<=0||h(a.max,t)>=0)&&(t="from"===e?a.min:a.max),i.uiOptions.times[e].time=t}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],n=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(R)).then(function(){["from","to"].forEach(function(e){_(e),L(e),n[e].amount=Math.min(i.request[e+"_date_amount"],n[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function C(){["from","to"].forEach(function(e){y(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(n,t){i.isCalculationUnit("days")||n===t||(i.setRequestDateTimesAndDateTypes(),n&&L(e,!0))})}function A(e,n){return f(e,n).then(function(){i.loading[n+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return R(e).then(function(){L(e,!0)})})}function R(e){var n=i.uiOptions[e+"Date"],t=!i.uiOptions.multipleDays;return n?i.request.getWorkDayForDate(i.convertDateToServerFormat(n)).then(function(n){O[e]=n,m(e,n),t&&"from"===e&&m("to",n)}).catch(function(n){return O[e]={},i.handleError(n)}).finally(function(){i.uiOptions.times[e].loading=!1,t&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(n){var t=i.uiOptions.times[n];i["request"+e.startCase(n)+"DayTypes"]=[],t.time="",t.min="00:00",t.max="00:00",t.amount="0",t.maxAmount="0"}function I(n,t){var a="request"+e.startCase(n)+"DayTypes";i[a]=t,i.isMode("create")&&(i.request[n+"_date_type"]=i[a][0].value)}function S(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),R("from").then(function(){L("from",!0)})):o.resolve()}function L(e,n){var t=i.uiOptions,a=t.multipleDays?e:"from",o=t.times[a],s=t.multipleDays&&"to"===a?o.min:t.times.from.time,r=t.multipleDays&&"from"===a?o.max:t.times.to.time,c=O[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,n&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function k(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?R("from").then(function(){L("from",!0)}):o.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=k,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=S}t.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(n){var t=r.request.getDocumentArray();return!!e.find(t,function(e){return e===n})}function d(n){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===n})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(n){return i.valuesOf("hrleaveandabsences_sickness_reason",n).then(function(n){r.sicknessReasons=e.indexBy(n,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}t.debug("RequestModalDetailsSicknessController"),n("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}n.controller("RequestModalDetailsSicknessController",t),t.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=n.duration(n(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,n=!c.uiOptions.multipleDays&&!!c.request.from_date,t=n||e,a=j.from_date!==c.request.from_date||j.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&t&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,n=c.request;return b({hasErrors:e?!n.to_date&&!n.from_date:!n.from_date,label:e?"To Date":"From Date",value:n.to_date})}function b(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(n(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&H.hasExpirationFromAdminSettings,n=H.hasPreviousExpirationDate,t=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=t&&(a||e||n)}function y(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",_().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&k(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function P(){c.isMode("view")||(T(),A(),R())}function I(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function S(){return l(),O(),F()}function L(){return x(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),U?U=!1:O(),F()}function w(e){c.uiOptions.times[e].time=""}function k(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){j=e.cloneDeep(c.request.attributes())}function x(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function $(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?k():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function N(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var j,U=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=$,c.onDateChangeExtended=S,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=w,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=N,function(){M(),x(),B(),!c.isMode("create")&&y()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,y,_,q,C){function T(e){"days"===Ne.selectedAbsenceType.calculation_unit_name?delete Ne.request[e+"_date_amount"]:delete Ne.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return ke.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function R(){var e=Ne.requestStatuses[y.statusNames.awaitingApproval].value;xe.status_id===e&&e!==Ne.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Ne.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ne.isMode("edit")&&(e=e&&(G()||I())),Ne.canManage&&Ne.requestStatuses&&(e=e&&!!Ne.getStatusFromValue(Ne.newStatusOnSave)),(e=e&&!!Ne.period.id)&&!Ne.isMode("view")}function w(){Ne.isSelfRecord&&!Ne.isSelfLeaveApprover?Ne.request.status_id=Ne.requestStatuses[y.statusNames.awaitingApproval].value:Ne.canManage&&(Ne.request.status_id=Ne.newStatusOnSave||Ne.request.status_id)}function k(){if(Ne.isMode("edit")&&!Ne.isRole("staff")&&"toil"!==U())return Ne.request.calculateBalanceChange(Ne.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ne.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==U()&&!Ne.request.change_balance}function M(){Ne.errors=[]}function x(){return Ne.request.create().then(Pe).then(function(){ge("LeaveRequest::new")})}function $(){se()&&!Ne.isRole("staff")&&(Ne.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ne.request.delete().then(function(){Ne.dismissModal(),d.publish("LeaveRequest::delete",Ne.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return j(Ne.getStatusFromValue(Ne.request.status_id).name)}function j(e){return t.map(Oe[e],function(e){return Ne.requestStatuses[e]})}function U(){return Ne.request?Ne.request.request_type:Ne.leaveType||null}function H(){return!Ne.request||e.equals({},Ne.requestStatuses)?[]:Ne.request.status_id?N():j("none")}function W(e){return t.find(Ne.requestStatuses,function(n){return n.value===e})}function Y(e){Ne.errors=t.isArray(e)?e:[e],Ne.loading.absenceTypes=!1,Ne.submitting=!1}function G(){return!e.equals(xe,Ne.request.attributes())||Ne.canManage&&Ne.newStatusOnSave}function V(){return Ne.postContactSelection=!0,Ne.staffMemberSelectionComplete=!1,Ne.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ne.isMode("edit")?Te:t.noop).then(function(){Ne.postContactSelection=!1,Ne.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Oe.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ne.canManage=Ne.isRole("manager")||Ne.isRole("admin")}function Q(){return Ne.canManage?f.find(Ne.request.contact_id).then(function(e){Ne.contactName=e.display_name}):o.resolve()}function J(){Ne.isRole("admin")&&Ne.isSelfRecord&&(Ne.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+ke.id==+t.get(Ne,"leaveRequest.contact_id"),a=!t.get(Ne,"leaveRequest.id");Ne.isSelfRecord=e&&a||n}function Z(){$e.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ne.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Ie),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ne.request=Ne.leaveRequest||null,e=U(),n=Ne.initRequestAttributes(),"leave"===e?Ne.request=g.init(n):"sickness"===e?Ne.request=_.init(n):"toil"===e&&(Ne.request=q.init(n))}function ne(){var e={};return Ne.request?e=Ne.request.attributes():Ne.canManage||(e={contact_id:ke.id}),e}function te(){return Be="staff",ae().then(Ne.isSelfRecord&&!Ne.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ne.defaultStatus?Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames[Ne.defaultStatus]].value:(Ne.isRole("admin")||Ne.isMode("create")&&Ne.isRole("manager"))&&(Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames.approved].value)}function se(){return!Ne.request.status_id||!t.includes(["cancelled","rejected"],W(Ne.request.status_id).name)}function ie(e){var n=Ne.getStatusFromValue(Ne.request.status_id);return!!n&&n.name===e}function re(e){return Ne.request&&Ne.request.request_type===e}function ce(e){return Ne.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ne.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){we={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ne.loading.entitlements=!0,v.all({contact_id:Ne.request.contact_id,period_id:Ne.period.id,type_id:{IN:we.ids}},!0).finally(function(){Ne.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){ke=e})}function he(){return Ne.selectedContactId?f.find(Ne.selectedContactId).then(function(e){Ne.managedContacts=[e]}):Ne.isRole("admin")?f.all().then(function(e){console.log(e.list),Ne.managedContacts=e.list}):ke.leaveManagees().then(function(e){Ne.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ne.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){R(),d.publish(e,Ne.request),Ne.errors=[],Ne.dismissModal()}function ye(){["from","to"].forEach(function(e){Ne.request[e+"_date"]=xe[e+"_date"]})}function _e(e){if(Ne.absenceTypes=be(we.types,e),!Ne.absenceTypes.length)return o.reject(Ee)}function qe(){Ne.period=t.find(Ne.absencePeriods,function(e){return Ne.isMode("create")?e.current:ue(Ne.request,e)})}function Ce(){Ne.isMode("create")?(Ne.selectedAbsenceType=Ne.absenceTypes[0],Ne.request.type_id=Ne.selectedAbsenceType.id):Ne.selectedAbsenceType=t.find(Ne.absenceTypes,function(e){return e.id===Ne.request.type_id})}function Te(){xe=e.copy(Ne.request.attributes())}function Ae(){var e;Ne.request.id?(e=[Ne.requestStatuses[y.statusNames.approved].value,Ne.requestStatuses[y.statusNames.adminApproved].value,Ne.requestStatuses[y.statusNames.rejected].value,Ne.requestStatuses[y.statusNames.cancelled].value],Ne.mode="edit",Ne.isRole("staff")&&e.indexOf(Ne.request.status_id)>-1&&(Ne.mode="view")):Ne.mode="create"}function De(){var e=Ne.request.status_id;if(!Ne.isMode("view")&&!Ne.submitting)return Ne.submitting=!0,w(),A(),Ne.request.isValid().then(se()&&k).then($).then(O()&&ye).then(Re).then(function(){return Ne.isMode("edit")?Le():x()}).catch(function(n){Ne.request.status_id=e,n&&Y(n)}).finally(function(){Ne.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Ie(){$e.forEach(function(e){e()})}function Se(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ne.request.update().then(Pe).then(function(){Ne.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ne.isRole("staff")||Ne.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var we,ke,Oe={},Me=0,xe={},$e=[],Ee="No entitlement",Be="",Fe=[],Ne=t.assign(this,m);Ne.absencePeriods=[],Ne.absenceTypes=[],Ne.canManage=!1,Ne.contactName=null,Ne.errors=[],Ne.isSelfLeaveApprover=!1,Ne.loading={absenceTypes:!0,entitlements:!0},Ne.managedContacts=[],Ne.mode="",Ne.newStatusOnSave=null,Ne.period={},Ne.postContactSelection=!1,Ne.requestStatuses={},Ne.selectedAbsenceType={},Ne.staffMemberSelectionComplete=!1,Ne.submitting=!1,Ne.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ne.canChangeAbsenceType=S,Ne.canSubmit=L,Ne.closeAlert=M,Ne.deleteLeaveRequest=E,Ne.dismissModal=B,Ne.getStatuses=H,Ne.getStatusFromValue=W,Ne.initAfterContactSelection=V,Ne.initRequestAttributes=ne,Ne.isLeaveStatus=ie,Ne.isLeaveType=re,Ne.isMode=ce,Ne.isRole=le,Ne.submit=De,Ne.updateAbsenceType=Se,function(){Ne.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ne.canManage&&!Ne.isMode("edit")&&he()}).then(function(){if(Ne.selectedContactId&&(Ne.request.contact_id=Ne.selectedContactId),Ne.request.contact_id)return Ne.initAfterContactSelection()}).catch(Y).finally(function(){Ne.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,n){"use strict";function t(e,n,t,a,o,s,i,r,c){function u(e){return r.get().then(function(n){return e.roleOf(n.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:n.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(n){n?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}n.factory("LeavePopup",t), -t.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"]}),define("leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component",[],function(){function e(e,n,t,a){function o(){i(),s()}function s(){return t("can administer calendar feeds").then(function(e){c.canCreateNewFeed=!!e})}function i(){return c.loading.feeds=!0,e.all().then(function(e){c.feeds=e}).finally(function(){c.loading.feeds=!1})}function r(e,t){n.open(e,t)}var c=this;c.canCreateNewFeed=!1,c.feeds=[],c.loading={feeds:!1},c.$onInit=o,c.openLinkModal=r}return e.$inject=["CalendarFeed","CalendarFeedsLinkModal","checkPermissions","shared-settings"],{__name:"calendarFeedsDropdownButton",bindings:{dropdownPosition:"@"},controller:e,controllerAs:"dropdownButton",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.html"}]}}),define("leave-absences/calendar-feeds/calendar-feeds.core",["common/angular","leave-absences/shared/modules/shared-settings"],function(e){e.module("calendar-feeds.core",["leave-absences.settings"])}),define("leave-absences/calendar-feeds/services/apis/calendar-feed.api",["common/lodash"],function(e){"use strict";function n(e,n,t){function a(){return this.sendGET("LeaveRequestCalendarFeedConfig","get",{is_active:!0}).then(function(e){return e.values})}return e.debug("CalendarFeedAPI"),t.extend({all:a})}return n.__name="CalendarFeedAPI",n.$inject=["$log","$q","api"],n}),define("leave-absences/calendar-feeds/services/models/calendar-feed.model",[],function(){"use strict";function e(e,n,t){function a(){return n.all().then(function(e){return e.map(function(e){return t.init(e)})})}return e.extend({all:a})}return e.__name="CalendarFeed",e.$inject=["Model","CalendarFeedAPI","CalendarFeedInstance"],e}),define("leave-absences/calendar-feeds/services/models/calendar-feed.instance",[],function(){"use strict";function e(e){return e.extend({})}return e.__name="CalendarFeedInstance",e.$inject=["ModelInstance"],e}),define("leave-absences/calendar-feeds/calendar-feeds.models",["common/angular","leave-absences/calendar-feeds/services/apis/calendar-feed.api","leave-absences/calendar-feeds/services/models/calendar-feed.model","leave-absences/calendar-feeds/services/models/calendar-feed.instance","common/models/model","common/services/api"],function(e,n,t,a){e.module("calendar-feeds.models",["common.apis","common.models"]).factory(n.__name,n).factory(t.__name,t).factory(a.__name,a)}),define("leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component",["common/lodash"],function(e){return{__name:"calendarFeedsLinkModal",bindings:{dismiss:"<",url:"<",title:"<"},controller:e.noop,controllerAs:"linkModal",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/link-modal/components/calendar-feeds-link-modal.html"}]}}),define("leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service",[],function(){function e(e,n,t){function a(e,a){var s=o(),i=t+"civicrm/calendar-feed?hash="+a;n.open({controllerAs:"modal",size:"md",template:'',controller:["$uibModalInstance","title","url",function(e,n,t){this.dismiss=e.dismiss,this.title=n,this.url=t}],appendTo:s,resolve:{title:function(){return e},url:function(){return i}}})}function o(){var n=e.find("#bootstrap-theme");return 0===n.length&&(n=e.find("body")),n.eq(0)}return{open:a}}return e.__name="CalendarFeedsLinkModal",e.$inject=["$document","$uibModal","HOST_URL"],e}),define("leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive",["common/lodash"],function(e){function n(n,t){function a(e,t,a,o){function s(){r(),u()}function i(){l[0].setSelectionRange(0,0),l.blur()}function r(){c(),document.execCommand("copy"),i()}function c(){l.focus(),l[0].setSelectionRange(0,l.val().length)}function u(){m.justCopied=!0,d&&n.cancel(d),d=n(function(){m.justCopied=!1},2e3)}var l,d,m=e.input;m.model=o.model,m.justCopied=!1,m.copy=s,m.selectInputText=c,function(){l=t.find("input")}()}var o=t.sourcePath+"calendar-feeds/link-modal/directives/input-with-copy-button.html";return{controller:e.noop,controllerAs:"input",link:a,restrict:"E",scope:{},templateUrl:o,require:{model:"^ngModel"}}}return n.__name="inputWithCopyButton",n.$inject=["$timeout","shared-settings"],n}),define("leave-absences/calendar-feeds/link-modal/link-modal.core",["common/angular","common/angularBootstrap"],function(e){e.module("calendar-feeds.link-modal.core",["ui.bootstrap"])}),function(e){define("leave-absences/calendar-feeds/link-modal/link-modal.constants",["common/angular"],function(n){"use strict";n.module("calendar-feeds.link-modal.constants",[]).constant("HOST_URL",e.absoluteUrl("/"))})}(Drupal),define("leave-absences/calendar-feeds/link-modal/link-modal.module",["common/angular","leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component","leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service","leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/link-modal/link-modal.core","leave-absences/calendar-feeds/link-modal/link-modal.constants"],function(e,n,t,a){e.module("calendar-feeds.link-modal",["calendar-feeds.core","calendar-feeds.link-modal.core","calendar-feeds.link-modal.constants"]).component(n.__name,n).directive(a.__name,a).factory(t.__name,t)}),define("leave-absences/calendar-feeds/dropdown-button/dropdown-button.module",["common/angular","leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component","common/services/check-permissions","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/calendar-feeds.models","leave-absences/calendar-feeds/link-modal/link-modal.module"],function(e,n){e.module("calendar-feeds.dropdown-button",["common.services","calendar-feeds.core","calendar-feeds.models","calendar-feeds.link-modal"]).component(n.__name,n)}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,n,t){function a(){t.go(o.tabName)}e.debug("Component: my-leave-container"),n.section="my-leave";var o=this;o.tabName=t.current.name,o.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(n){return n.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e,n){define("leave-absences/my-leave/modules/config",["common/angular","common/lodash","leave-absences/my-leave/modules/settings"],function(n,t){function a(n){n.withAutoBase(!0),n.settings.ga={userId:t.get(e,"vars.session.contact_id")}}return n.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","$analyticsProvider","settings",function(n,t,o,s,i,r,c){a(r),i.debugEnabled(c.debug),s.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",t.defaults.stripTrailingSlashes=!1,o.otherwise("/my-leave/report"),n.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,n){e["leave-request-id"]&&n.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM,Drupal),define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/angulartics","common/angulartics-google-tag-manager","common/angularUiRouter","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/calendar-feeds/dropdown-button/dropdown-button.module","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","angulartics","angulartics.google.tagmanager","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","calendar-feeds.dropdown-button","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,n,t,a){e.debug("app.run"),n.sharedPathTpl=t.sharedPathTpl,n.settings=a}]),e}),function(e,n){var t=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";n.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":t+"/shared","leave-absences/my-leave":t+"/my-leave"}}),n(["leave-absences/shared/config"],function(){n(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); +})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.approved)]}})),c.balanceChangeByAbsenceType(e.assign({},n,{statuses:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}}))]).then(function(e){z.absenceTypes.forEach(function(n){n.balanceChanges={holidays:e[0][n.id],expired:e[1][n.id],approved:e[2][n.id],pending:e[3][n.id]}})})}function P(){return r.all({contact_id:z.contactId,period_id:z.selectedPeriod.id},!0).then(function(e){z.entitlements=e})}function I(){return r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id},z.entitlements).then(function(){return F(z.entitlements)}).then(function(e){z.sections.entitlements.data=e})}function S(){return t.all([r.breakdown({contact_id:z.contactId,period_id:z.selectedPeriod.id,expired:!0}),L({request_type:"toil",expired:!0})]).then(function(e){return t.all({expiredBalanceChangesFlatten:F(e[0]),expiredTOILS:N(e[1].list)})}).then(function(n){z.sections.expired.data=n.expiredBalanceChangesFlatten.concat(n.expiredTOILS),z.sections.expired.data=e.sortBy(z.sections.expired.data,"expiry_date")})}function L(n){return c.all(e.assign({contact_id:z.contactId,from_date:{from:z.selectedPeriod.start_date},to_date:{to:z.selectedPeriod.end_date},type_id:{IN:z.absenceTypes.map(function(e){return e.id})}},n),null,"from_date ASC",null,!1)}function w(e,n){return L(n).then(function(n){z.sections[e].data=n.list})}function k(){return t.all(Object.values(z.sections).filter(function(e){return e.open}).map($))}function O(){return w("other",{status_id:{in:[G(m.statusNames.rejected),G(m.statusNames.cancelled)]}})}function M(){return w("pending",{status_id:{in:[G(m.statusNames.awaitingApproval),G(m.statusNames.moreInformationRequired)]}})}function x(){return w("holidays",{public_holiday:!0})}function $(e){return e.loading=!0,e.loadLeaveRequests().then(_.bind(this,e)).then(function(){e.loading=!1})}function E(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(n){z.leaveRequestStatuses=e.indexBy(n,"value")})}function B(){h(),g()}function F(n){return t.resolve().then(function(){return n.map(function(n){var t=e.find(z.entitlements,function(e){return e.id===n.id});return n.breakdown.map(function(n){return e.assign(e.clone(n),{type_id:t.type_id})})})}).then(function(e){return Array.prototype.concat.apply([],e)})}function N(n){return t.resolve().then(function(){return n.map(function(n){return e.assign({},n,{expiry_date:n.toil_expiry_date,amount:n.toil_to_accrue,type:{label:"Accrued TOIL"}})})})}function j(){l.subscribe("LeaveRequest::new",function(){z.refresh()}),l.subscribe("LeaveRequest::edit",function(){z.refresh()}),l.subscribe("LeaveRequest::statusUpdate",y),l.subscribe("LeaveRequest::delete",function(e){U(e)})}function U(n){e.forEach(z.sections,function(t,a){t.dataIndex[n.id]&&(e.remove(t.data,function(e){return e.id===n.id}),delete t.dataIndex[n.id],"other"!==a&&H(n,a))})}function H(n,t){var a=["future","current"],o=z.absenceTypesIndexed[n.type_id];"pending"===t&&e.pull(a,"current"),o.balanceChanges[t]-=n.balance_change,a.forEach(function(e){o.remainder[e]-=n.balance_change})}function W(){z.loading.content=!0,t.all([P(),R()]).then(B).then(function(){z.loading.content=!1}).then(function(){return t.all([k(),b()])})}function Y(e){var n=z.sections[e];n.open=!n.open,n.open&&!n.data.length&&$(n)}function G(n){return e.find(z.leaveRequestStatuses,function(e){return e.name===n}).value}n.debug("Component: staff-leave-report");var V={delete:U,cancel:v},z=this;z.absencePeriods=[],z.absenceTypes=[],z.absenceTypesFiltered=[],z.absenceTypesIndexed={},z.dateFormat=d.DATE_FORMAT,z.leaveRequestStatuses={},z.selectedPeriod=null,z.role=null,z.loading={content:!0,page:!0},z.sections={approved:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:D},entitlements:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:I},expired:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:S},holidays:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:x},pending:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:M},other:{open:!1,data:[],dataIndex:{},loading:!1,loadLeaveRequests:O}},z.$onInit=f,z.labelPeriod=C,z.refresh=W,z.toggleSection=Y}t.component("staffLeaveReport",{bindings:{contactId:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/staff-leave-report.html"}],controllerAs:"report",controller:a}),a.$inject=["$log","$q","$rootScope","checkPermissions","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","OptionGroup","pubSub","HR_settings","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return i.request.calculateBalanceChange(i.selectedAbsenceType.calculation_unit_name)}function l(){var e=i.request,n=!!e.from_date&&!!e.to_date,t=i.selectedAbsenceType.calculation_unit_name;return"days"===t?n=n&&!!e.from_date_type&&!!e.to_date_type:"hours"===t&&(n=n&&!isNaN(+e.from_date_amount)&&!isNaN(+e.to_date_amount)),n}function d(){return i.canCalculateChange()}function m(n,t){var a=i.uiOptions.times[n],o=e.clone(t.time_from),s=e.clone(t.time_to);i.uiOptions.multipleDays||("from"===n&&s&&o&&(s=i.getMomentDateWithGivenTime(s).subtract(i.uiOptions.time_interval,"minutes").format("HH:mm")),"to"===n&&o&&s&&(o=i.getMomentDateWithGivenTime(o).add(i.uiOptions.time_interval,"minutes").format("HH:mm"))),a.min=o||"00:00",a.max=s||"00:00",a.time="to"===n?a.max:a.min}function f(n,t){return n?(n=i.convertDateToServerFormat(n),v(n).then(function(t){return t?i.requestDayTypes.filter(function(e){return"public_holiday"===e.name}):p(n,i.requestDayTypes).then(function(n){return n.length?n:i.requestDayTypes.filter(function(n){return e.includes(["all_day","half_day_am","half_day_pm"],n.name)})})}).then(function(e){return I(t,e),e})):o.reject([])}function p(e,t){return e=n(e),o.all([i.calendar.isNonWorkingDay(e),i.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(n){return n.name===e}):[]})}function h(e,t){return n.duration(t).subtract(n.duration(e)).asHours()}function v(e){return c.all({public_holiday:1,contact_id:i.request.contact_id,from_date:{from:e},to_date:{to:e}}).then(function(e){return!!e.list.length})}function b(){return o.resolve()}function g(){return A(i.uiOptions.fromDate,"from").then(function(){return A(i.uiOptions.toDate,"to")})}function y(e){s.$watch(function(){return i.uiOptions.times[e].amount},function(e,n){i.isCalculationUnit("days")||+e==+n||(i.isRole("staff")&&(i.request.change_balance=!0),w(),i.performBalanceChangeCalculation())})}function _(e){var t=n(i.request[e+"_date"]).format("HH:mm"),a=i.uiOptions.times[e];(h(a.min,t)<=0||h(a.max,t)>=0)&&(t="from"===e?a.min:a.max),i.uiOptions.times[e].time=t}function q(){var e=i.uiOptions.multipleDays?["from","to"]:["from"],n=i.uiOptions.times;if(i.isCalculationUnit("hours"))return o.all(e.map(R)).then(function(){["from","to"].forEach(function(e){_(e),L(e),n[e].amount=Math.min(i.request[e+"_date_amount"],n[e].maxAmount).toString()}),i.uiOptions.multipleDays||i.updateEndTimeInputMinTime(i.uiOptions.times.from.time)}).then(w)}function C(){["from","to"].forEach(function(e){y(e),T(e)})}function T(e){s.$watch(function(){return i.uiOptions.times[e].time},function(n,t){i.isCalculationUnit("days")||n===t||(i.setRequestDateTimesAndDateTypes(),n&&L(e,!0))})}function A(e,n){return f(e,n).then(function(){i.loading[n+"DayTypes"]=!1})}function D(e){return A(i.uiOptions[e+"Date"],e).then(function(){if(i.isCalculationUnit("hours"))return R(e).then(function(){L(e,!0)})})}function R(e){var n=i.uiOptions[e+"Date"],t=!i.uiOptions.multipleDays;return n?i.request.getWorkDayForDate(i.convertDateToServerFormat(n)).then(function(n){O[e]=n,m(e,n),t&&"from"===e&&m("to",n)}).catch(function(n){return O[e]={},i.handleError(n)}).finally(function(){i.uiOptions.times[e].loading=!1,t&&(i.uiOptions.times.to.loading=!1)}):o.resolve()}function P(n){var t=i.uiOptions.times[n];i["request"+e.startCase(n)+"DayTypes"]=[],t.time="",t.min="00:00",t.max="00:00",t.amount="0",t.maxAmount="0"}function I(n,t){var a="request"+e.startCase(n)+"DayTypes";i[a]=t,i.isMode("create")&&(i.request[n+"_date_type"]=i[a][0].value)}function S(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?(i.disableAndShowLoadingTimeInput("from"),!i.uiOptions.multipleDays&&i.disableAndShowLoadingTimeInput("to"),R("from").then(function(){L("from",!0)})):o.resolve()}function L(e,n){var t=i.uiOptions,a=t.multipleDays?e:"from",o=t.times[a],s=t.multipleDays&&"to"===a?o.min:t.times.from.time,r=t.multipleDays&&"from"===a?o.max:t.times.to.time,c=O[a].number_of_hours?h(s,r).toString():"0";o.maxAmount=c,n&&(o.amount=o.maxAmount)}function w(){var e=i.uiOptions.times;i.request.from_date_amount=isNaN(+e.from.amount)?null:e.from.amount,i.request.to_date_amount=isNaN(+e.to.amount)?null:e.to.amount}function k(){return i.isCalculationUnit("hours")&&i.uiOptions.fromDate?R("from").then(function(){L("from",!0)}):o.resolve()}var O={};a.debug("RequestModalDetailsLeaveController"),i.calculateBalanceChange=u,i.canCalculateChange=l,i.canSubmit=d,i.initChildController=b,i.initDayTypesExtended=g,i.initTimesExtended=q,i.initWatchersExtended=C,i.onAbsenceTypeUpdateExtended=k,i.onDateChangeExtended=D,i.resetUIInputsExtended=P,i.setDaysSelectionModeExtended=S}t.controller("RequestModalDetailsLeaveController",a),a.$inject=["$controller","$log","$q","$rootScope","detailsController","PublicHoliday","LeaveRequest"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller",["common/lodash","leave-absences/shared/modules/controllers"],function(e,n){function t(n,t,a,o,s,i,r){function c(){return!(!r.canCalculateChange()||!r.request.sickness_reason)}function u(){return a.all([m(),h(),f(!0)])}function l(n){var t=r.request.getDocumentArray();return!!e.find(t,function(e){return e===n})}function d(n){return!!e.find(r.sicknessDocumentTypes,function(e){return e.value===n})}function m(){return i.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){r.sicknessDocumentTypes=e})}function f(n){return i.valuesOf("hrleaveandabsences_sickness_reason",n).then(function(n){r.sicknessReasons=e.indexBy(n,"name")})}function p(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_sickness_reason?reset=1").on("crmUnload",function(){f(!1)})}function h(){r.showSicknessOptionsEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}t.debug("RequestModalDetailsSicknessController"),n("RequestModalDetailsLeaveController",{detailsController:r}),r.canSubmit=c,r.initChildController=u,r.isChecked=l,r.isDocumentInRequest=d,r.openSicknessReasonOptionsEditor=p}n.controller("RequestModalDetailsSicknessController",t),t.$inject=["$controller","$log","$q","$rootScope","crmAngService","api.optionGroup","detailsController"]}),define("leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller",["common/lodash","common/moment","leave-absences/shared/modules/controllers"],function(e,n,t){function a(t,a,o,s,i,r,c){function u(){return c.balance.change.amount=+c.request.toil_to_accrue,a.resolve(c.balance.change)}function l(){if(!c.request.from_date||!c.request.to_date)return c.uiOptions.max_toil_duration_and_accrual=null,void(c.uiOptions.toil_duration_in_hours=null);c.uiOptions.max_toil_duration_and_accrual=n.duration(n(c.request.to_date).diff(c.request.from_date)).asHours()}function d(){return v().catch(function(e){return e.length&&(c.errors=e),a.reject(e)}).then(function(e){return r.calculateToilExpiryDate(c.request.type_id,e)}).then(function(e){return c.request.toil_expiry_date=e,c.uiOptions.expiryDate=new Date(e),e})}function m(){return!!c.request.toil_to_accrue}function f(){var e=c.uiOptions.multipleDays&&!!c.request.to_date,n=!c.uiOptions.multipleDays&&!!c.request.from_date,t=n||e,a=j.from_date!==c.request.from_date||j.to_date!==c.request.to_date;return c.canDisplayToilExpirationField&&t&&H.hasExpirationFromAdminSettings&&a}function p(){return!!(c.request.from_date&&c.request.to_date&&c.request.toil_duration&&c.request.toil_to_accrue)}function h(){c.request.toil_expiry_date=!1,c.uiOptions.expiryDate=null}function v(){var e=c.uiOptions.multipleDays,n=c.request;return b({hasErrors:e?!n.to_date&&!n.from_date:!n.from_date,label:e?"To Date":"From Date",value:n.to_date})}function b(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(n(e.value).format("YYYY-MM-DD")):a.reject([])}function g(){var e=c.isMode("create")&&H.hasExpirationFromAdminSettings,n=H.hasPreviousExpirationDate,t=c.isLeaveType("toil"),a=c.canManage;c.canDisplayToilExpirationField=t&&(a||e||n)}function y(){c.uiOptions.toil_duration_in_hours=c.request.toil_duration/60}function _(){return H.hasPreviousExpirationDate=c.isMode("edit")&&!!c.request.toil_expiry_date,r.canExpire(c.request.type_id).then(function(e){H.hasExpirationFromAdminSettings=e})}function q(){return c.request.to_date_type=c.request.from_date_type="1",_().then(g).then(C).then(I)}function C(){c.canManage&&(c.uiOptions.expiryDate=c.convertDateFormatFromServer(c.request.toil_expiry_date))}function T(){o.$watch(function(){return c.request.toil_to_accrue},function(e,n){+e!=+n&&c.performBalanceChangeCalculation()})}function A(){o.$watch(function(){return c.uiOptions.toil_duration_in_hours},function(e,n){e!==n&&c.isCalculationUnit("hours")&&k(),c.request.toil_duration=c.uiOptions.toil_duration_in_hours?60*c.uiOptions.toil_duration_in_hours:null})}function D(){var e=c.uiOptions.times;e.from.time=n(c.request.from_date).format("HH:mm"),e.to.time=n(c.request.to_date).format("HH:mm"),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time)}function R(){["from","to"].forEach(function(e){o.$watch(function(){return c.uiOptions.times[e].time},function(e,n){e!==n&&(c.setRequestDateTimesAndDateTypes(),F(),l(),O())})})}function P(){c.isMode("view")||(T(),A(),R())}function I(n){return i.valuesOf("hrleaveandabsences_toil_amounts",n).then(function(n){c.toilAmounts=e.sortBy(n,function(e){return+e.weight})})}function S(){return l(),O(),F()}function L(){return x(),c.uiOptions.multipleDays||c.updateEndTimeInputMinTime(c.uiOptions.times.from.time),l(),U?U=!1:O(),F()}function w(e){c.uiOptions.times[e].time=""}function k(){c.request.toil_to_accrue=c.uiOptions.toil_duration_in_hours}function O(){c.uiOptions.toil_duration_in_hours=c.uiOptions.max_toil_duration_and_accrual}function M(){j=e.cloneDeep(c.request.attributes())}function x(){c.uiOptions.multipleDays?["from","to"].forEach(function(e){c.uiOptions.times[e].min="00:00",c.uiOptions.times[e].max="23:45"}):(c.uiOptions.times.from.min="00:00",c.uiOptions.times.from.max="23:30",c.uiOptions.times.to.min="00:15",c.uiOptions.times.to.max="23:45")}function $(){c.setRequestDateTimesAndDateTypes(),l(),O(),c.isCalculationUnit("hours")?k():c.request.toil_to_accrue=null}function E(){s.loadForm("/civicrm/admin/options/hrleaveandabsences_toil_amounts?reset=1").on("crmUnload",function(){I(!1)})}function B(){c.showTOILAccrualsOptionEditorIcon=e.includes(["admin-dashboard","absence-tab"],o.section)}function F(){return f()?d().catch(a.resolve):a.resolve()}function N(){c.uiOptions.expiryDate&&(c.request.toil_expiry_date=c.convertDateToServerFormat(c.uiOptions.expiryDate))}t.debug("RequestModalDetailsToilController");var j,U=!c.isMode("create"),H={hasPreviousExpirationDate:null,hasExpirationFromAdminSettings:null};c.canDisplayToilExpirationField=!1,c.calculateBalanceChange=u,c.canCalculateChange=m,c.canSubmit=p,c.clearExpiryDate=h,c.initChildController=q,c.initTimesExtended=D,c.initWatchersExtended=P,c.onAbsenceTypeUpdateExtended=$,c.onDateChangeExtended=S,c.openToilInDaysAccrualOptionsEditor=E,c.resetUIInputsExtended=w,c.setDaysSelectionModeExtended=L,c.updateExpiryDate=N,function(){M(),x(),B(),!c.isMode("create")&&y()}()}t.controller("RequestModalDetailsToilController",a),a.$inject=["$log","$q","$rootScope","crmAngService","OptionGroup","AbsenceType","detailsController"]}),define("leave-absences/shared/services/leave-calendar.service",["common/lodash","common/moment","leave-absences/shared/modules/services"],function(e,n,t){"use strict";function a(t,a,o,s){function i(t){function i(){return o.all().then(function(e){return e.list})}function r(){return o.leaveManagees(void 0,{unassigned:!0})}function c(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return m().then(function(e){return t.lookupContacts=e,a.all([d(),"me"!==n?u():a.resolve(null)])}).then(function(e){var n=e[0];return t.contactIdsToReduceTo=e[1],n})}function u(){return l().then(function(a){var o=a.filter(function(e){var a=e.info.details;return n(a.period_start_date).isSameOrBefore(t.selectedPeriod.end_date)&&(n(a.period_end_date).isSameOrAfter(t.selectedPeriod.start_date)||!a.period_end_date)});return e.uniq(o.map(function(e){return e.contact_id}))})}function l(){return v?a.resolve(v):s.all()}function d(){return o.all(h(),null,"display_name").then(function(e){return e.list})}function m(){var n=e.get(t,"filters.userSettings.assignedTo.type","all");return(0,b[n])()}function f(){return m().then(function(e){t.lookupContacts=e}).then(d)}function p(){return o.leaveManagees(t.contactId)}function h(){var n={department:e.get(t,"filters.userSettings.department.value",null),level_type:e.get(t,"filters.userSettings.level_type.value",null),location:e.get(t,"filters.userSettings.location.value",null),region:e.get(t,"filters.userSettings.region.value",null)},a=!!t.filters.userSettings.contact,o=e.isArray(t.lookupContacts)&&t.lookupContacts.length,s="all"!==e.get(t,"filters.userSettings.assignedTo.type","all");return a?n.id={IN:[t.filters.userSettings.contact.id]}:(s||o)&&(n.id={IN:e.pluck(t.lookupContacts,"id")}),n}var v,b={all:i,me:p,unassigned:r};return{loadContactsForAdmin:c,loadFilteredContacts:d,loadLookUpContacts:m,loadLookUpAndFilteredContacts:f}}return t.debug("LeaveCalendarService"),{init:i}}t.factory("LeaveCalendarService",a),a.$inject=["$log","$q","Contact","Contract"]}),define("leave-absences/shared/instances/sickness-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("SicknessRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={sickness_reason:null,sickness_required_documents:"",request_type:"sickness"};return e.assign({},t.defaultCustomData(),n)},getDocumentArray:function(){return this.sickness_required_documents?this.sickness_required_documents.split(","):[]},toggleDocument:function(n){var t=this.getDocumentArray(),a=t.indexOf(n);e.contains(t,n)?t.splice(a,1):t.push(n),this.sickness_required_documents=t.join(",")},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/instances/toil-request.instance",["common/lodash","leave-absences/shared/modules/models-instances","leave-absences/shared/instances/leave-request.instance"],function(e,n){"use strict";n.factory("TOILRequestInstance",["LeaveRequestAPI","LeaveRequestInstance",function(n,t){return t.extend({defaultCustomData:function(){var n={from_date_amount:0,to_date_amount:0,request_type:"toil"};return e.assign({},t.defaultCustomData(),n)},toAPIFilter:function(n,t,a){e.includes(["balance_change","dates","comments","files"],a)||(n[a]=this[a])}})}])}),define("leave-absences/shared/controllers/request.controller",["common/angular","leave-absences/shared/modules/controllers","common/lodash","common/moment","common/models/contact","common/services/api/option-group","common/services/hr-settings","common/services/pub-sub","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/instances/leave-request.instance","leave-absences/shared/instances/sickness-request.instance","leave-absences/shared/instances/toil-request.instance","leave-absences/shared/services/leave-request.service"],function(e,n,t,a){"use strict";function o(n,o,s,i,r,c,u,l,d,m,f,p,h,v,b,g,y,_,q,C){function T(e){"days"===Ne.selectedAbsenceType.calculation_unit_name?delete Ne.request[e+"_date_amount"]:delete Ne.request[e+"_date_type"]}function A(){["from","to"].forEach(T)}function D(){return ke.checkIfSelfLeaveApprover().then(function(e){e&&(Be="admin")})}function R(){var e=Ne.requestStatuses[y.statusNames.awaitingApproval].value;xe.status_id===e&&e!==Ne.request.status_id&&d.publish("ManagerBadge:: Update Count")}function P(){return Fe.filter(function(e){return e.isRequired}).every(function(e){return e.canSubmit&&e.canSubmit()})}function I(){return Fe.filter(function(e){return!e.isRequired}).some(function(e){return e.canSubmit&&e.canSubmit()})}function S(){return!Ne.loading.entitlements&&(!!le("admin")||!ce("view")&&!(le("manager")&&!ce("create")))}function L(){var e=P();return Ne.isMode("edit")&&(e=e&&(G()||I())),Ne.canManage&&Ne.requestStatuses&&(e=e&&!!Ne.getStatusFromValue(Ne.newStatusOnSave)),(e=e&&!!Ne.period.id)&&!Ne.isMode("view")}function w(){Ne.isSelfRecord&&!Ne.isSelfLeaveApprover?Ne.request.status_id=Ne.requestStatuses[y.statusNames.awaitingApproval].value:Ne.canManage&&(Ne.request.status_id=Ne.newStatusOnSave||Ne.request.status_id)}function k(){if(Ne.isMode("edit")&&!Ne.isRole("staff")&&"toil"!==U())return Ne.request.calculateBalanceChange(Ne.selectedAbsenceType.calculation_unit_name).then(function(e){if(+Ne.balance.change.amount!=+e.amount)return C.promptBalanceChangeRecalculation().then(function(){s.$emit("LeaveRequestPopup::recalculateBalanceChange")}),o.reject()})}function O(){return"toil"!==U()&&!Ne.request.change_balance}function M(){Ne.errors=[]}function x(){return Ne.request.create().then(Pe).then(function(){ge("LeaveRequest::new")})}function $(){se()&&!Ne.isRole("staff")&&(Ne.request.change_balance=!0)}function E(){l.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return Ne.request.delete().then(function(){Ne.dismissModal(),d.publish("LeaveRequest::delete",Ne.request)})}})}function B(){r.dismiss({$value:"cancel"})}function F(){var e=U();return"leave"===e?{is_sick:!1}:"sickness"===e?{is_sick:!0}:"toil"===e?{allow_accruals_request:!0}:void 0}function N(){return j(Ne.getStatusFromValue(Ne.request.status_id).name)}function j(e){return t.map(Oe[e],function(e){return Ne.requestStatuses[e]})}function U(){return Ne.request?Ne.request.request_type:Ne.leaveType||null}function H(){return!Ne.request||e.equals({},Ne.requestStatuses)?[]:Ne.request.status_id?N():j("none")}function W(e){return t.find(Ne.requestStatuses,function(n){return n.value===e})}function Y(e){Ne.errors=t.isArray(e)?e:[e],Ne.loading.absenceTypes=!1,Ne.submitting=!1}function G(){return!e.equals(xe,Ne.request.attributes())||Ne.canManage&&Ne.newStatusOnSave}function V(){return Ne.postContactSelection=!0,Ne.staffMemberSelectionComplete=!1,Ne.request.contact_id?o.resolve().then(me).then(fe).then(_e).then(Ce).then(oe).then(Q).then(Ne.isMode("edit")?Te:t.noop).then(function(){Ne.postContactSelection=!1,Ne.staffMemberSelectionComplete=!0}).catch(function(e){if(e!==Ee)return o.reject(e)}):o.reject("The contact id was not set")}function z(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Oe.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Oe.awaiting_approval=e,Oe.more_information_required=e,Oe.rejected=e,Oe.approved=e,Oe.cancelled=[y.statusNames.awaitingApproval].concat(e)}function X(){Ne.canManage=Ne.isRole("manager")||Ne.isRole("admin")}function Q(){return Ne.canManage?f.find(Ne.request.contact_id).then(function(e){Ne.contactName=e.display_name}):o.resolve()}function J(){Ne.isRole("admin")&&Ne.isSelfRecord&&(Ne.isSelfLeaveApprover=!0)}function K(){var e="my-leave"===s.section,n=+ke.id==+t.get(Ne,"leaveRequest.contact_id"),a=!t.get(Ne,"leaveRequest.id");Ne.isSelfRecord=e&&a||n}function Z(){$e.push(s.$on("LeaveRequestPopup::requestObjectUpdated",Te),s.$on("LeaveRequestPopup::absencePeriodChanged",function(){fe().then(_e).then(function(){s.$emit("LeaveRequestPopup::absencePeriodBalancesUpdated",Ne.absenceTypes)})}),s.$on("LeaveRequestPopup::handleError",function(e,n){Y(n)}),s.$on("LeaveRequestPopup::childComponent::register",function(){Me++})),i.$on("$destroy",Ie),i.$on("LeaveRequestPopup::addTab",function(e,n){Fe.push(n)})}function ee(){var e,n;Ne.request=Ne.leaveRequest||null,e=U(),n=Ne.initRequestAttributes(),"leave"===e?Ne.request=g.init(n):"sickness"===e?Ne.request=_.init(n):"toil"===e&&(Ne.request=q.init(n))}function ne(){var e={};return Ne.request?e=Ne.request.attributes():Ne.canManage||(e={contact_id:ke.id}),e}function te(){return Be="staff",ae().then(Ne.isSelfRecord&&!Ne.isRole("admin")&&D)}function ae(){return c(y.permissions.admin.administer).then(function(e){e&&(Be="admin")}).then(function(){return"admin"!==Be&&c(y.permissions.ssp.manage)}).then(function(e){e&&(Be="manager")})}function oe(){Ne.defaultStatus?Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames[Ne.defaultStatus]].value:(Ne.isRole("admin")||Ne.isMode("create")&&Ne.isRole("manager"))&&(Ne.newStatusOnSave=Ne.requestStatuses[y.statusNames.approved].value)}function se(){return!Ne.request.status_id||!t.includes(["cancelled","rejected"],W(Ne.request.status_id).name)}function ie(e){var n=Ne.getStatusFromValue(Ne.request.status_id);return!!n&&n.name===e}function re(e){return Ne.request&&Ne.request.request_type===e}function ce(e){return Ne.mode===e}function ue(e,n){var t=a(e.from_date),o=a(e.to_date);return t.isSameOrAfter(n.start_date,"day")&&o.isSameOrBefore(n.end_date,"day")}function le(e){return Be===e}function de(){return p.all().then(function(e){Ne.absencePeriods=e})}function me(){return h.all(F()).then(h.loadCalculationUnits).then(function(e){we={types:e,ids:e.map(function(e){return e.id})}})}function fe(){return Ne.loading.entitlements=!0,v.all({contact_id:Ne.request.contact_id,period_id:Ne.period.id,type_id:{IN:we.ids}},!0).finally(function(){Ne.loading.entitlements=!1})}function pe(){return f.getLoggedIn().then(function(e){ke=e})}function he(){return Ne.selectedContactId?f.find(Ne.selectedContactId).then(function(e){Ne.managedContacts=[e]}):Ne.isRole("admin")?f.all().then(function(e){Ne.managedContacts=e.list}):ke.leaveManagees().then(function(e){Ne.managedContacts=e})}function ve(){return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(e){Ne.requestStatuses=t.indexBy(e,"name")})}function be(e,n){var a;return t.compact(e.map(function(e){if(a=t.find(n,{type_id:e.id}))return{id:a.type_id,title:e.title+" ( "+a.remainder.current+" ) ",remainder:a.remainder.current,allow_overuse:e.allow_overuse,calculation_unit_name:e.calculation_unit_name}}))}function ge(e){R(),d.publish(e,Ne.request),Ne.errors=[],Ne.dismissModal()}function ye(){["from","to"].forEach(function(e){Ne.request[e+"_date"]=xe[e+"_date"]})}function _e(e){if(Ne.absenceTypes=be(we.types,e),!Ne.absenceTypes.length)return o.reject(Ee)}function qe(){Ne.period=t.find(Ne.absencePeriods,function(e){return Ne.isMode("create")?e.current:ue(Ne.request,e)})}function Ce(){Ne.isMode("create")?(Ne.selectedAbsenceType=Ne.absenceTypes[0],Ne.request.type_id=Ne.selectedAbsenceType.id):Ne.selectedAbsenceType=t.find(Ne.absenceTypes,function(e){return e.id===Ne.request.type_id})}function Te(){xe=e.copy(Ne.request.attributes())}function Ae(){var e;Ne.request.id?(e=[Ne.requestStatuses[y.statusNames.approved].value,Ne.requestStatuses[y.statusNames.adminApproved].value,Ne.requestStatuses[y.statusNames.rejected].value,Ne.requestStatuses[y.statusNames.cancelled].value],Ne.mode="edit",Ne.isRole("staff")&&e.indexOf(Ne.request.status_id)>-1&&(Ne.mode="view")):Ne.mode="create"}function De(){var e=Ne.request.status_id;if(!Ne.isMode("view")&&!Ne.submitting)return Ne.submitting=!0,w(),A(),Ne.request.isValid().then(se()&&k).then($).then(O()&&ye).then(Re).then(function(){return Ne.isMode("edit")?Le():x()}).catch(function(n){Ne.request.status_id=e,n&&Y(n)}).finally(function(){Ne.submitting=!1})}function Re(){return o.all(Fe.map(function(e){return e.onBeforeSubmit&&e.onBeforeSubmit()}))}function Pe(){function e(e){e&&t.push(e),++a===Me&&(t.length>0?n.reject(t):n.resolve())}var n=o.defer(),t=[],a=0;return Me>0?s.$broadcast("LeaveRequestPopup::submit",e):n.resolve(),n.promise}function Ie(){$e.forEach(function(e){e()})}function Se(){s.$broadcast("LeaveRequestPopup::absenceTypeChanged")}function Le(){return Ne.request.update().then(Pe).then(function(){Ne.isRole("manager")?ge("LeaveRequest::updatedByManager"):(Ne.isRole("staff")||Ne.isRole("admin"))&&ge("LeaveRequest::edit")})}n.debug("RequestCtrl");var we,ke,Oe={},Me=0,xe={},$e=[],Ee="No entitlement",Be="",Fe=[],Ne=t.assign(this,m);Ne.absencePeriods=[],Ne.absenceTypes=[],Ne.canManage=!1,Ne.contactName=null,Ne.errors=[],Ne.isSelfLeaveApprover=!1,Ne.loading={absenceTypes:!0,entitlements:!0},Ne.managedContacts=[],Ne.mode="",Ne.newStatusOnSave=null,Ne.period={},Ne.postContactSelection=!1,Ne.requestStatuses={},Ne.selectedAbsenceType={},Ne.staffMemberSelectionComplete=!1,Ne.submitting=!1,Ne.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},Ne.canChangeAbsenceType=S,Ne.canSubmit=L,Ne.closeAlert=M,Ne.deleteLeaveRequest=E,Ne.dismissModal=B,Ne.getStatuses=H,Ne.getStatusFromValue=W,Ne.initAfterContactSelection=V,Ne.initRequestAttributes=ne,Ne.isLeaveStatus=ie,Ne.isLeaveType=re,Ne.isMode=ce,Ne.isRole=le,Ne.submit=De,Ne.updateAbsenceType=Se,function(){Ne.loading.absenceTypes=!0,z(),Z(),pe().then(K).then(function(){return o.all([te(),de(),ve()])}).then(X).then(J).then(ee).then(Ae).then(qe).then(function(){return Ne.canManage&&!Ne.isMode("edit")&&he()}).then(function(){if(Ne.selectedContactId&&(Ne.request.contact_id=Ne.selectedContactId),Ne.request.contact_id)return Ne.initAfterContactSelection()}).catch(Y).finally(function(){Ne.loading.absenceTypes=!1})}()}n.controller("RequestCtrl",o),o.$inject=["$log","$q","$rootScope","$scope","$uibModalInstance","checkPermissions","api.optionGroup","dialog","pubSub","directiveOptions","Contact","AbsencePeriod","AbsenceType","Entitlement","LeaveRequest","LeaveRequestInstance","shared-settings","SicknessRequestInstance","TOILRequestInstance","LeaveRequestService"]}),define("leave-absences/shared/services/leave-popup.service",["common/lodash","common/modules/angular-date","leave-absences/shared/modules/services","common/services/angular-date/date-format","common/services/notification.service","leave-absences/shared/controllers/request.controller"],function(e,n){"use strict";function t(e,n,t,a,o,s,i,r,c){function u(e){return r.get().then(function(n){return e.roleOf(n.contactId)}).then(function(e){return"none"!==e})}function l(e){a.open({appendTo:n.children().eq(0),templateUrl:s.sharedPathTpl+"components/leave-request-popup/leave-request-popup.html",controller:"RequestCtrl",controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return e},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function d(e){return c.find(e).then(function(e){return u(e).then(function(n){n?l({leaveRequest:e,leaveType:e.request_type,selectedContactId:e.contact_id}):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return e.debug("LeavePopup"),{openModal:l,openModalByID:d}}n.factory("LeavePopup",t),t.$inject=["$log","$rootElement","$rootScope","$uibModal","notificationService","shared-settings","DateFormat","Session","LeaveRequest"] +}),define("leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component",[],function(){function e(e,n,t,a){function o(){i(),s()}function s(){return t("can administer calendar feeds").then(function(e){c.canCreateNewFeed=!!e})}function i(){return c.loading.feeds=!0,e.all().then(function(e){c.feeds=e}).finally(function(){c.loading.feeds=!1})}function r(e,t){n.open(e,t)}var c=this;c.canCreateNewFeed=!1,c.feeds=[],c.loading={feeds:!1},c.$onInit=o,c.openLinkModal=r}return e.$inject=["CalendarFeed","CalendarFeedsLinkModal","checkPermissions","shared-settings"],{__name:"calendarFeedsDropdownButton",bindings:{dropdownPosition:"@"},controller:e,controllerAs:"dropdownButton",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.html"}]}}),define("leave-absences/calendar-feeds/calendar-feeds.core",["common/angular","leave-absences/shared/modules/shared-settings"],function(e){e.module("calendar-feeds.core",["leave-absences.settings"])}),define("leave-absences/calendar-feeds/services/apis/calendar-feed.api",["common/lodash"],function(e){"use strict";function n(e,n,t){function a(){return this.sendGET("LeaveRequestCalendarFeedConfig","get",{is_active:!0}).then(function(e){return e.values})}return e.debug("CalendarFeedAPI"),t.extend({all:a})}return n.__name="CalendarFeedAPI",n.$inject=["$log","$q","api"],n}),define("leave-absences/calendar-feeds/services/models/calendar-feed.model",[],function(){"use strict";function e(e,n,t){function a(){return n.all().then(function(e){return e.map(function(e){return t.init(e)})})}return e.extend({all:a})}return e.__name="CalendarFeed",e.$inject=["Model","CalendarFeedAPI","CalendarFeedInstance"],e}),define("leave-absences/calendar-feeds/services/models/calendar-feed.instance",[],function(){"use strict";function e(e){return e.extend({})}return e.__name="CalendarFeedInstance",e.$inject=["ModelInstance"],e}),define("leave-absences/calendar-feeds/calendar-feeds.models",["common/angular","leave-absences/calendar-feeds/services/apis/calendar-feed.api","leave-absences/calendar-feeds/services/models/calendar-feed.model","leave-absences/calendar-feeds/services/models/calendar-feed.instance","common/models/model","common/services/api"],function(e,n,t,a){e.module("calendar-feeds.models",["common.apis","common.models"]).factory(n.__name,n).factory(t.__name,t).factory(a.__name,a)}),define("leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component",["common/lodash"],function(e){return{__name:"calendarFeedsLinkModal",bindings:{dismiss:"<",url:"<",title:"<"},controller:e.noop,controllerAs:"linkModal",templateUrl:["shared-settings",function(e){return e.sourcePath+"calendar-feeds/link-modal/components/calendar-feeds-link-modal.html"}]}}),define("leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service",[],function(){function e(e,n,t){function a(e,a){var s=o(),i=t+"civicrm/calendar-feed?hash="+a;n.open({controllerAs:"modal",size:"md",template:'',controller:["$uibModalInstance","title","url",function(e,n,t){this.dismiss=e.dismiss,this.title=n,this.url=t}],appendTo:s,resolve:{title:function(){return e},url:function(){return i}}})}function o(){var n=e.find("#bootstrap-theme");return 0===n.length&&(n=e.find("body")),n.eq(0)}return{open:a}}return e.__name="CalendarFeedsLinkModal",e.$inject=["$document","$uibModal","HOST_URL"],e}),define("leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive",["common/lodash"],function(e){function n(n,t){function a(e,t,a,o){function s(){r(),u()}function i(){l[0].setSelectionRange(0,0),l.blur()}function r(){c(),document.execCommand("copy"),i()}function c(){l.focus(),l[0].setSelectionRange(0,l.val().length)}function u(){m.justCopied=!0,d&&n.cancel(d),d=n(function(){m.justCopied=!1},2e3)}var l,d,m=e.input;m.model=o.model,m.justCopied=!1,m.copy=s,m.selectInputText=c,function(){l=t.find("input")}()}var o=t.sourcePath+"calendar-feeds/link-modal/directives/input-with-copy-button.html";return{controller:e.noop,controllerAs:"input",link:a,restrict:"E",scope:{},templateUrl:o,require:{model:"^ngModel"}}}return n.__name="inputWithCopyButton",n.$inject=["$timeout","shared-settings"],n}),define("leave-absences/calendar-feeds/link-modal/link-modal.core",["common/angular","common/angularBootstrap"],function(e){e.module("calendar-feeds.link-modal.core",["ui.bootstrap"])}),function(e){define("leave-absences/calendar-feeds/link-modal/link-modal.constants",["common/angular"],function(n){"use strict";n.module("calendar-feeds.link-modal.constants",[]).constant("HOST_URL",e.absoluteUrl("/"))})}(Drupal),define("leave-absences/calendar-feeds/link-modal/link-modal.module",["common/angular","leave-absences/calendar-feeds/link-modal/components/calendar-feeds-link-modal.component","leave-absences/calendar-feeds/link-modal/services/calendar-feeds-link-modal.service","leave-absences/calendar-feeds/link-modal/directives/input-with-copy-button.directive","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/link-modal/link-modal.core","leave-absences/calendar-feeds/link-modal/link-modal.constants"],function(e,n,t,a){e.module("calendar-feeds.link-modal",["calendar-feeds.core","calendar-feeds.link-modal.core","calendar-feeds.link-modal.constants"]).component(n.__name,n).directive(a.__name,a).factory(t.__name,t)}),define("leave-absences/calendar-feeds/dropdown-button/dropdown-button.module",["common/angular","leave-absences/calendar-feeds/dropdown-button/components/calendar-feeds-dropdown-button.component","common/services/check-permissions","leave-absences/calendar-feeds/calendar-feeds.core","leave-absences/calendar-feeds/calendar-feeds.models","leave-absences/calendar-feeds/link-modal/link-modal.module"],function(e,n){e.module("calendar-feeds.dropdown-button",["common.services","calendar-feeds.core","calendar-feeds.models","calendar-feeds.link-modal"]).component(n.__name,n)}),define("leave-absences/my-leave/modules/components",["common/angular"],function(e){return e.module("my-leave.components",[])}),define("leave-absences/my-leave/components/my-leave-container.component",["leave-absences/my-leave/modules/components"],function(e){e.component("myLeaveContainer",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/my-leave-container.html"}],controllerAs:"myleave",controller:["$log","$rootScope","$state",function(e,n,t){function a(){t.go(o.tabName)}e.debug("Component: my-leave-container"),n.section="my-leave";var o=this;o.tabName=t.current.name,o.changeTab=a}]})}),function(e){define("leave-absences/my-leave/modules/settings",["common/angular"],function(n){return n.module("my-leave.settings",[]).constant("settings",{debug:e.debug,pathTpl:e.vars.leaveAndAbsences.baseURL+"/views/my-leave/"})})}(CRM),function(e,n){define("leave-absences/my-leave/modules/config",["common/angular","common/lodash","leave-absences/my-leave/modules/settings"],function(n,t){function a(n){n.withAutoBase(!0),n.settings.ga={userId:t.get(e,"vars.session.contact_id")}}return n.module("my-leave.config",["my-leave.settings"]).config(["$stateProvider","$resourceProvider","$urlRouterProvider","$httpProvider","$logProvider","$analyticsProvider","settings",function(n,t,o,s,i,r,c){a(r),i.debugEnabled(c.debug),s.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",t.defaults.stripTrailingSlashes=!1,o.otherwise("/my-leave/report"),n.state("my-leave",{abstract:!0,url:"/my-leave",template:'',resolve:{contactId:function(){return e.vars.leaveAndAbsences.contactId},format:["DateFormat",function(e){return e.getDateFormat()}]}}).state("my-leave.report",{url:"/report?leave-request-id",template:'',onEnter:["$stateParams","LeavePopup",function(e,n){e["leave-request-id"]&&n.openModalByID(e["leave-request-id"])}]}).state("my-leave.calendar",{url:"/calendar",template:''})}])})}(CRM,Drupal),define("leave-absences/my-leave/app",["common/angular","common/angularBootstrap","common/angulartics","common/angulartics-google-tag-manager","common/angularUiRouter","common/text-angular","common/directives/loading","common/directives/scroll-shadows.directive","common/directives/time-amount-picker.directive","common/directives/timepicker-select.directive","common/filters/angular-date/format-date","common/filters/time-unit-applier.filter","common/models/option-group","common/modules/dialog","common/services/check-permissions","common/services/crm-ang.service","common/services/angular-date/date-format","leave-absences/shared/modules/shared-settings","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/components/leave-calendar.component","leave-absences/shared/components/leave-calendar-day.component","leave-absences/shared/components/leave-calendar-legend.component","leave-absences/shared/components/leave-calendar-month.component","leave-absences/shared/components/leave-request-actions.component","leave-absences/shared/components/leave-request-popup-comments-tab.component","leave-absences/shared/components/leave-request-popup-details-tab.component","leave-absences/shared/components/leave-request-popup-files-tab","leave-absences/shared/components/leave-request-record-actions.component","leave-absences/shared/components/staff-leave-report.component","leave-absences/shared/controllers/sub-controllers/request-modal-details-leave.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-sickness.controller","leave-absences/shared/controllers/sub-controllers/request-modal-details-toil.controller","leave-absences/shared/models/absence-period.model","leave-absences/shared/models/absence-type.model","leave-absences/shared/models/calendar.model","leave-absences/shared/models/entitlement.model","leave-absences/shared/models/leave-request.model","leave-absences/shared/models/public-holiday.model","leave-absences/shared/modules/shared-settings","leave-absences/shared/modules/shared-settings","leave-absences/shared/services/leave-calendar.service","leave-absences/shared/services/leave-popup.service","leave-absences/calendar-feeds/dropdown-button/dropdown-button.module","leave-absences/my-leave/components/my-leave-container.component","leave-absences/my-leave/modules/config"],function(e){return e.module("my-leave",["ngResource","ngAnimate","angulartics","angulartics.google.tagmanager","ui.bootstrap","ui.router","textAngular","common.angularDate","common.dialog","common.directives","common.filters","common.mocks","common.models","common.services","leave-absences.components","leave-absences.controllers","leave-absences.models","leave-absences.services","leave-absences.settings","calendar-feeds.dropdown-button","my-leave.components","my-leave.config"]).run(["$log","$rootScope","shared-settings","settings",function(e,n,t,a){e.debug("app.run"),n.sharedPathTpl=t.sharedPathTpl,n.settings=a}]),e}),function(e,n){var t=e.vars.leaveAndAbsences.baseURL+"/js/src/leave-absences";n.config({urlArgs:"bust="+(new Date).getTime(),paths:{"leave-absences/shared":t+"/shared","leave-absences/my-leave":t+"/my-leave"}}),n(["leave-absences/shared/config"],function(){n(["leave-absences/my-leave/app"],function(e){e.bootstrap(document.querySelector("[data-leave-absences-my-leave]"),["my-leave"])})})}(CRM,require),define("my-leave",function(){}); //# sourceMappingURL=/sites/all/modules/civicrm/tools/extensions/civihr/uk.co.compucorp.civicrm.hrleaveandabsences/js/dist/my-leave.js.map \ No newline at end of file diff --git a/uk.co.compucorp.civicrm.hrleaveandabsences/js/src/leave-absences/shared/controllers/request.controller.js b/uk.co.compucorp.civicrm.hrleaveandabsences/js/src/leave-absences/shared/controllers/request.controller.js index b2bd6eaa76c..3593c95427c 100644 --- a/uk.co.compucorp.civicrm.hrleaveandabsences/js/src/leave-absences/shared/controllers/request.controller.js +++ b/uk.co.compucorp.civicrm.hrleaveandabsences/js/src/leave-absences/shared/controllers/request.controller.js @@ -814,6 +814,9 @@ define([ /** * Loads the managees of currently logged in user + * If a contact is pre-selected, then a single managee is loaded. + * If user is an admin, then all contacts, including the admin, are loaded. + * If user is a manager, then only contacts they manage are loaded. * * @return {Promise} */