|
@@ -0,0 +1,108 @@
|
|
|
|
|
+import { formatDate } from "@angular/common";
|
|
|
|
|
+import { inject } from "@angular/core";
|
|
|
|
|
+import { untilDestroy } from "angularlib/base.component";
|
|
|
|
|
+import { NotificationService } from "angularlib/notification/notification.service";
|
|
|
|
|
+import { DecoratorSubject } from "fis-commons/decorator";
|
|
|
|
|
+import { debounceNotification } from "fis-commons/notification/operators";
|
|
|
|
|
+import { skipUndefined } from "fis-commons/observable/operators";
|
|
|
|
|
+import { adjustISOTimezoneOffset } from "fis/fis.date";
|
|
|
|
|
+import { FISMessaging } from "fis/index";
|
|
|
|
|
+import { NotificationRequest } from "fis/tm/tm.i";
|
|
|
|
|
+import { firstValueFrom } from "rxjs";
|
|
|
|
|
+
|
|
|
|
|
+export class LeaveNotificationDecorator<T> extends DecoratorSubject<T> {
|
|
|
|
|
+ messaging = inject(FISMessaging);
|
|
|
|
|
+ notification = inject(NotificationService);
|
|
|
|
|
+ subscriptionId;
|
|
|
|
|
+ empRoleId;
|
|
|
|
|
+
|
|
|
|
|
+ constructor(
|
|
|
|
|
+ private component: any,
|
|
|
|
|
+ request?: NotificationRequest
|
|
|
|
|
+ ) {
|
|
|
|
|
+ super();
|
|
|
|
|
+ this.empRoleId = component.loginService.user?.fisInfo?.defaultEmpRoleId;
|
|
|
|
|
+ this.messaging.Notification(request).pipe(untilDestroy(component)).subscribe({
|
|
|
|
|
+ next: (notif:any) => {
|
|
|
|
|
+ if (!this.subscriptionId) this.subscriptionId = notif?.data?.SubscriptionData?.subscriptionId;
|
|
|
|
|
+ this.onReceiveNotification(notif)
|
|
|
|
|
+ this.next(notif);
|
|
|
|
|
+ },
|
|
|
|
|
+ error: error => this.error(error),
|
|
|
|
|
+ complete: () => this.complete()
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private async onReceiveNotification(notif) {
|
|
|
|
|
+ const OPERATION = notif.data?.data?.NotificationMicroserviceData?.uiMessage?.NotificationData?.Operation;
|
|
|
|
|
+ const DOCID = +notif.data?.data?.NotificationMicroserviceData?.uiMessage?.NotificationData?.ID;
|
|
|
|
|
+ const CODE = notif.data?.data?.NotificationMicroserviceData?.uiMessage?.NotificationData?.Code;
|
|
|
|
|
+ let leave;
|
|
|
|
|
+ let applicant;
|
|
|
|
|
+ await firstValueFrom(this.messaging.GetData({
|
|
|
|
|
+ serviceId: 'Leave Application Data',
|
|
|
|
|
+ parameter: `__clearSearchValue__=true,caching=false,code=${CODE}`
|
|
|
|
|
+ },{liveResponsesOnly:true}).pipe(skipUndefined(),debounceNotification(100))).then(res => {
|
|
|
|
|
+ leave = res.GenericFisData?.data?.DataService?.rows?.row[0]?.column;
|
|
|
|
|
+ }).catch(error => console.error(error));
|
|
|
|
|
+ if (leave) {
|
|
|
|
|
+ await firstValueFrom(this.messaging.GetData({
|
|
|
|
|
+ serviceId: 'Employee Role Data',
|
|
|
|
|
+ parameter: `roleId=${leave?.ps_doc_leave_emp_role_id},__clearSearchValue__=true,caching=false`
|
|
|
|
|
+ }).pipe(skipUndefined())).then(res => {
|
|
|
|
|
+ applicant = res.GenericFisData?.data?.DataService?.rows?.row[0]?.column || res.data?.GenericFisData?.data?.DataService?.rows?.row[0]?.column;
|
|
|
|
|
+ }).catch(error => console.error(error));
|
|
|
|
|
+ switch (OPERATION?.toLowerCase()) {
|
|
|
|
|
+ case 'new': {
|
|
|
|
|
+ this.notification.notify({
|
|
|
|
|
+ message:{
|
|
|
|
|
+ title:{key:'new_leave_applied',default:'New Leave Applied'},
|
|
|
|
|
+ desc: `${applicant?.pers_name}`,
|
|
|
|
|
+ timestamp: new Date(),
|
|
|
|
|
+ },
|
|
|
|
|
+ action: () => {this.component.cs.navigate('/leave/approval')}
|
|
|
|
|
+ });
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case 'modify': {
|
|
|
|
|
+ this.notification.notify({
|
|
|
|
|
+ message:{
|
|
|
|
|
+ title: {key:'leave_modified',default:'Leave Modified'},
|
|
|
|
|
+ desc: `${applicant?.pers_name}`,
|
|
|
|
|
+ timestamp: new Date(),
|
|
|
|
|
+ },
|
|
|
|
|
+ action: () => {this.component.cs.navigate('/leave/approval')}
|
|
|
|
|
+ });
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case 'post': {
|
|
|
|
|
+ if (leave?.ps_doc_leave_emp_role_id !== this.empRoleId) break;
|
|
|
|
|
+ const DATE_FROM = formatDate(adjustISOTimezoneOffset(leave.ps_doc_leave_ps_dt_from),'yyyy-MM-dd EEE',this.component.cs.appSettings.locale);
|
|
|
|
|
+ this.notification.notify({
|
|
|
|
|
+ message:{
|
|
|
|
|
+ title: {key:'leave_approved',default:'Leave Approved'},
|
|
|
|
|
+ desc: {key:`#{leave_date_from}: ${DATE_FROM}`,default:''},
|
|
|
|
|
+ timestamp: new Date(),
|
|
|
|
|
+ },
|
|
|
|
|
+ action: () => {this.component.cs.navigate('/leave',{type:'view',detailsTabIndex:1})}
|
|
|
|
|
+ });
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case 'cancel': {
|
|
|
|
|
+ if (leave?.ps_doc_leave_emp_role_id !== this.empRoleId) break;
|
|
|
|
|
+ const DATE_FROM = formatDate(adjustISOTimezoneOffset(leave.ps_doc_leave_ps_dt_from),'yyyy-MM-dd EEE',this.component.cs.appSettings.locale);
|
|
|
|
|
+ this.notification.notify({
|
|
|
|
|
+ message:{
|
|
|
|
|
+ title: {key:'leave_cancelled',default:'Leave Cancelled'},
|
|
|
|
|
+ desc: {key:`#{leave_date_from}: ${DATE_FROM}`,default:''},
|
|
|
|
|
+ timestamp: new Date(),
|
|
|
|
|
+ },
|
|
|
|
|
+ action: () => {this.component.cs.navigate('/leave',{type:'view',detailsTabIndex:2})}
|
|
|
|
|
+ });
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ default: break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|