Advertisement
psi_mmobile

Untitled

Feb 7th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.31 KB | None | 0 0
  1. import { DataBaseService } from './../../core/services/data-base.service';
  2. import { HttpClient, HttpParams } from '@angular/common/http';
  3. import { Injectable } from '@angular/core';
  4. import { AppStateService } from 'src/app/core/services/application-state.service';
  5. import { filter } from 'rxjs/operators';
  6. import { BehaviorSubject, Observable } from 'rxjs';
  7. import { StandardORDSGETResponse } from 'src/app/shared/interface/StandardORDSGETResponse.interface';
  8. import { Person } from 'src/app/shared/interface/Person.interface';
  9. import { POIModel } from 'src/app/shared/BryntumModels/POIModel.class';
  10. import { Store } from '@bryntum/scheduler/scheduler.lite.umd.js';
  11. import { POI } from 'src/app/shared/interface/POI.interface';
  12. import { PoiRegistration } from 'src/app/shared/interface/PoiRegistration.interface';
  13. import { PoiRegistrationModel } from 'src/app/shared/BryntumModels/PoiRegistrationModel.class';
  14. import { Wbs } from 'src/app/shared/interface/Wbs.interface';
  15. import { WbsModel } from 'src/app/shared/BryntumModels/WbsModel.class';
  16.  
  17. @Injectable()
  18. export class TrackingService {
  19. constructor(
  20. private http: HttpClient,
  21. public dataBaseService: DataBaseService,
  22. private appState: AppStateService
  23. ) {}
  24.  
  25. private _currentCawRecord = new BehaviorSubject<PoiRegistration | null>(null);
  26. readonly currentCawRecord$ = this._currentCawRecord
  27. .asObservable()
  28. .pipe(filter((value) => !!value));
  29.  
  30. setCurrentCawRecord(cawRecord) {
  31. this._currentCawRecord.next(cawRecord);
  32. }
  33.  
  34. getCurrentCawRecord(): Observable<PoiRegistration> {
  35. return this.currentCawRecord$;
  36. }
  37.  
  38. private _cawStore = new BehaviorSubject<Store | null>(null);
  39. readonly cawStore$ = this._cawStore
  40. .asObservable()
  41. .pipe(filter((value) => !!value));
  42.  
  43. fetchCAWRecords(
  44. person,
  45. poi,
  46. warningCheckbox,
  47. exceptionsOnlyCheckbox,
  48. pplWithMissingDocs,
  49. nonAdminStatusCheckbox,
  50. cawFromDate,
  51. cawToDate
  52. ) {
  53. let params = new HttpParams();
  54. params = params.set('was_here_before', warningCheckbox);
  55. params = params.set('exceptions_only', exceptionsOnlyCheckbox);
  56. params = params.set('show_non_admin_status_only', nonAdminStatusCheckbox);
  57. params = params.set('display_only_ppl_missing_docs', pplWithMissingDocs);
  58. if (person) {
  59. params = params.set('person_id', person.person_id);
  60. }
  61. if (poi) {
  62. params = params.set('poi_id', poi.poi_id);
  63. }
  64. params = params.set('history_from', cawFromDate);
  65. params = params.set('history_to', cawToDate);
  66. this.http
  67. .get<StandardORDSGETResponse<PoiRegistration>>(
  68. `${this.dataBaseService.ordsTraxxeoURL}tracking/checkin`,
  69. { params }
  70. )
  71. .subscribe((caws) => {
  72. caws.items.forEach((item) => this.parseCAW(item));
  73. const store = new Store({ modelClass: PoiRegistrationModel });
  74. store.add(caws.items);
  75. store.commit();
  76. this._cawStore.next(store);
  77. this.setIsFetching(false);
  78. });
  79. }
  80.  
  81. private _isFetching = new BehaviorSubject<boolean>(false);
  82. readonly isFetching$ = this._isFetching.asObservable();
  83.  
  84. setIsFetching(value: boolean) {
  85. this._isFetching.next(value);
  86. }
  87. parseCAW(caw) {
  88. caw.id = caw.social_office_transaction_id;
  89. caw.selected = false;
  90. caw.workDate = caw.work_date ? new Date(caw.work_date) : null;
  91. caw.workDateWithTimeZone = caw.work_date_with_time_zone
  92. ? new Date(caw.work_date_with_time_zone)
  93. : null;
  94. caw.creationDate = caw.creation_date ? new Date(caw.creation_date) : null;
  95. caw.creationDateWithTimeZone = caw.creation_date_with_time_zone
  96. ? new Date(caw.creation_date_with_time_zone)
  97. : null;
  98. caw.cancelDate = caw.cancel_date ? new Date(caw.cancel_date) : null;
  99. caw.cancelDateWithTimeZone = caw.cancel_date_with_time_zone
  100. ? new Date(caw.cancel_date_with_time_zone)
  101. : null;
  102. if (caw.sot_admin_remark_translation) {
  103. caw.remarkArray = caw.sot_admin_remark_translation
  104. .split('\n')
  105. .filter((value) => value !== '')
  106. .map((value) => {
  107. return { remark: value };
  108. });
  109. // if (caw.remarkArray.length > 0) {
  110. // caw.remarkArray = caw.remarkArray.filter(
  111. // (value) => value.remark.length > 1
  112. // );
  113. // }
  114. } else {
  115. caw.remarkArray = new Array<string>();
  116. }
  117. }
  118.  
  119. private _selectedCAWPerson = new BehaviorSubject<Person>(null);
  120. readonly selectedCAWPerson$ = this._selectedCAWPerson.asObservable();
  121.  
  122. getCAWPersonFilterData() {
  123. return this.http.get<StandardORDSGETResponse<Person>>(
  124. this.dataBaseService.ordsTraxxeoURL + 'payroll/person'
  125. );
  126. }
  127.  
  128. setSelectedCAWPerson(person: Person) {
  129. this._selectedCAWPerson.next(person);
  130. }
  131.  
  132. private _selectedPOI = new BehaviorSubject<POI | null>(null);
  133. readonly selectedPOI$ = this._selectedPOI.asObservable();
  134.  
  135. setSelectedPOI(poi: POI) {
  136. this._selectedPOI.next(poi);
  137. }
  138.  
  139. private _pois = new BehaviorSubject<Store | null>(null);
  140. readonly pois$ = this._pois.asObservable().pipe(filter((poi) => !!poi));
  141.  
  142. fetchPOIs() {
  143. this.http
  144. .get<StandardORDSGETResponse<POI>>(
  145. `${this.dataBaseService.ordsTraxxeoURL}vehicle-owner/pois`
  146. )
  147. .subscribe((pois) => {
  148. const itemsWithUnfiltered = pois.items.map((item) => ({
  149. ...item,
  150. unfiltered: true
  151. }));
  152. const store = new Store({ modelClass: POIModel });
  153. store.add(itemsWithUnfiltered);
  154. store.commit();
  155. this._pois.next(store);
  156. });
  157. }
  158.  
  159. getCAWFilterPOIs() {
  160. return this.http.get<StandardORDSGETResponse<POI>>(
  161. `${this.dataBaseService.ordsTraxxeoURL}vehicle-owner/pois`
  162. );
  163. }
  164.  
  165. private _warningCheckbox = new BehaviorSubject<string | null>('N');
  166. readonly warningCheckbox$ = this._warningCheckbox
  167. .asObservable()
  168. .pipe(filter((value) => !!value));
  169.  
  170. setWarningCheckbox(value) {
  171. this._warningCheckbox.next(value);
  172. }
  173.  
  174. private _nonAdminStatusCheckbox = new BehaviorSubject<string | null>('N');
  175. readonly nonAdminStatusCheckbox$ = this._nonAdminStatusCheckbox
  176. .asObservable()
  177. .pipe(filter((value) => !!value));
  178.  
  179. setNonAdminStatusCheckbox(value) {
  180. this._nonAdminStatusCheckbox.next(value);
  181. }
  182.  
  183. private _exceptionsOnlyCheckbox = new BehaviorSubject<string | null>('N');
  184. readonly exceptionsOnlyCheckbox$ = this._exceptionsOnlyCheckbox
  185. .asObservable()
  186. .pipe(filter((value) => !!value));
  187.  
  188. setExceptionsOnlyCheckbox(value) {
  189. this._exceptionsOnlyCheckbox.next(value);
  190. }
  191.  
  192. private _pplWithMissingDocsCheckbox = new BehaviorSubject<string | null>('N');
  193. readonly pplWithMissingDocs$ = this._pplWithMissingDocsCheckbox
  194. .asObservable()
  195. .pipe(filter((value) => !!value));
  196.  
  197. setPplWithMissingDocsCheckbox(value) {
  198. this._pplWithMissingDocsCheckbox.next(value);
  199. }
  200.  
  201. private _cawFromDate = new BehaviorSubject<string | null>(null);
  202. readonly cawFromDate$ = this._cawFromDate
  203. .asObservable()
  204. .pipe(filter((value) => !!value));
  205.  
  206. setCawFromDate(value) {
  207. this._cawFromDate.next(value);
  208. }
  209.  
  210. private _cawToDate = new BehaviorSubject<string | null>(null);
  211. readonly cawToDate$ = this._cawToDate
  212. .asObservable()
  213. .pipe(filter((value) => !!value));
  214.  
  215. setCawToDate(value) {
  216. this._cawToDate.next(value);
  217. }
  218.  
  219. private _wbsList = new BehaviorSubject<Store | null>(null);
  220. readonly wbsList$ = this._wbsList.asObservable().pipe(filter((wbs) => !!wbs));
  221.  
  222. fetchWbsList() {
  223. this.http
  224. .get<StandardORDSGETResponse<Wbs>>(
  225. `${this.dataBaseService.ordsTraxxeoURL}admin/calendar-closing-period-wbs`
  226. )
  227. .subscribe((wbsList) => {
  228. const store = new Store({ modelClass: WbsModel });
  229. store.add(wbsList.items);
  230. store.commit();
  231. this._wbsList.next(store);
  232. });
  233. }
  234.  
  235. getWbsList() {
  236. return this.http.get<StandardORDSGETResponse<Wbs>>(
  237. `${this.dataBaseService.ordsTraxxeoURL}admin/calendar-closing-period-wbs`
  238. );
  239. }
  240.  
  241. updateCawRecord(cawRecord) {
  242. return this.http.put(
  243. this.dataBaseService.ordsTraxxeoURL + 'tracking/checkin',
  244. cawRecord
  245. );
  246. }
  247.  
  248. createCawRecord(cawRecord) {
  249. return this.http.post(
  250. this.dataBaseService.ordsTraxxeoURL + 'tracking/checkin',
  251. cawRecord
  252. );
  253. }
  254. }
  255.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement