1 import {Injectable} from '@angular/core';
2 import {Router} from '@angular/router';
3 import {Observable, of} from 'rxjs';
4 import {mergeMap, switchMap, tap} from 'rxjs/operators';
5 import {IdlObject} from '@eg/core/idl.service';
6 import {AuthService} from '@eg/core/auth.service';
7 import {PrintService} from '@eg/share/print/print.service';
8 import {PcrudService} from '@eg/core/pcrud.service';
10 // Some grid actions that are shared across booking grids
12 export interface CaptureInformation {
14 reservation: IdlObject;
16 new_copy_status?: number;
24 @Injectable({providedIn: 'root'})
25 export class ReservationActionsService {
28 private auth: AuthService,
29 private pcrud: PcrudService,
30 private printer: PrintService,
31 private router: Router,
35 manageReservationsByResource = (barcode: string) => {
36 this.router.navigate(['/staff', 'booking', 'manage_reservations', 'by_resource', barcode]);
39 printCaptureSlip = (templateData: CaptureInformation) => {
40 templateData.staff = this.auth.user();
41 templateData.workstation = this.auth.workstation();
43 templateName: 'booking_capture',
44 contextData: templateData,
45 printContext: 'receipt'
49 reprintCaptureSlip = (ids: number[]): Observable<CaptureInformation> => {
50 return this.fetchDataForCaptureSlip$(ids)
51 .pipe(tap((data) => this.printCaptureSlip(data)));
54 viewItemStatus = (barcode: string) => {
55 this.pcrud.search('acp', { 'barcode': barcode }, { limit: 1 })
57 window.open('/eg/staff/cat/item/' + acp.id());
61 notOneUniqueSelected = (ids: number[]) => {
62 return (new Set(ids).size !== 1);
65 private fetchDataForCaptureSlip$ = (ids: number[]): Observable<CaptureInformation> => {
66 return this.pcrud.search('bresv', {'id': ids}, {
69 'bresv': ['usr', 'current_resource', 'type'],
73 }).pipe(mergeMap((reservation: IdlObject) => this.assembleDataForCaptureSlip$(reservation)));
76 private assembleDataForCaptureSlip$ = (reservation: IdlObject): Observable<CaptureInformation> => {
77 let observable$ = of({
78 reservation: reservation,
81 if (reservation.pickup_lib() === this.auth.user().ws_ou()) {
82 observable$ = this.pcrud.search('artc', {'reservation': reservation.id()}, {limit: 1})
83 .pipe(switchMap(transit => {
85 reservation: reservation,