1 import {Component, OnInit, AfterViewInit} from '@angular/core';
2 import {map, take} from 'rxjs/operators';
3 import {ActivatedRoute, ParamMap} from '@angular/router';
4 import {IdlObject} from '@eg/core/idl.service';
5 import {NetService} from '@eg/core/net.service';
6 import {AuthService} from '@eg/core/auth.service';
7 import {PcrudService} from '@eg/core/pcrud.service';
8 import {OrgService} from '@eg/core/org.service';
9 import {LineitemService} from './lineitem.service';
10 import {PrintService} from '@eg/share/print/print.service';
13 templateUrl: 'worksheet.component.html'
15 export class LineitemWorksheetComponent implements OnInit, AfterViewInit {
25 private route: ActivatedRoute,
26 private org: OrgService,
27 private net: NetService,
28 private auth: AuthService,
29 private pcrud: PcrudService,
30 private printer: PrintService,
31 private liService: LineitemService
36 this.route.paramMap.subscribe((params: ParamMap) => {
37 const id = +params.get('lineitemId');
38 if (id !== this.lineitemId) {
40 if (id) { this.load(); }
46 this.outlet = document.getElementById('worksheet-outlet');
50 if (!this.lineitemId) { return; }
53 'open-ils.acq', 'open-ils.acq.lineitem.retrieve',
54 this.auth.token(), this.lineitemId, {
57 flesh_cancel_reason: true,
58 flesh_li_details: true,
60 flesh_li_details_copy: true,
61 flesh_li_details_location: true,
62 flesh_li_details_receiver: true,
63 distribution_formulas: true
66 .then(li => this.lineitem = li)
67 .then(_ => this.getRemainingData())
68 .then(_ => this.populatePreview());
71 getRemainingData(): Promise<any> {
74 this.lineitem.lineitem_details().forEach(lid => {
75 lid.owning_lib(this.org.get(lid.owning_lib()));
78 return this.net.request(
80 'open-ils.circ.bre.holds.count', this.lineitem.eg_bib_id()
81 ).toPromise().then(count => this.holdCount = count);
85 populatePreview(): Promise<any> {
87 return this.printer.compileRemoteTemplate({
88 templateName: 'lineitem_worksheet',
89 printContext: 'default',
91 lineitem: this.lineitem,
92 hold_count: this.holdCount
96 this.outlet.innerHTML = response.content;
100 printWorksheet(closeTab?: boolean) {
102 if (closeTab || this.closing) {
103 const sub: any = this.printer.printJobQueued$.subscribe(
105 if (req.templateName === 'lineitem_worksheet') {
109 }, 2000); // allow for a time cushion past queueing.
116 templateName: 'lineitem_worksheet',
118 lineitem: this.lineitem,
119 hold_count: this.holdCount
121 printContext: 'default'