1 import {Component, Input, ViewChild, TemplateRef, OnInit} from '@angular/core';
2 import {DialogComponent} from '@eg/share/dialog/dialog.component';
3 import {NgForm} from '@angular/forms';
4 import {IdlService, IdlObject} from '@eg/core/idl.service';
5 import {EventService} from '@eg/core/event.service';
6 import {NetService} from '@eg/core/net.service';
7 import {AuthService} from '@eg/core/auth.service';
8 import {PcrudService} from '@eg/core/pcrud.service';
9 import {GridDataSource} from '@eg/share/grid/grid';
10 import {Pager} from '@eg/share/util/pager';
11 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
12 import {StringComponent} from '@eg/share/string/string.component';
13 import {ToastService} from '@eg/share/toast/toast.service';
14 import {PermService} from '@eg/core/perm.service';
15 import {OrgService} from '@eg/core/org.service';
16 import {Observable} from 'rxjs';
17 import {map} from 'rxjs/operators';
18 import {ProgressInlineComponent} from '@eg/share/dialog/progress-inline.component';
19 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
22 selector: 'eg-fund-rollover-dialog',
23 templateUrl: './fund-rollover-dialog.component.html'
26 export class FundRolloverDialogComponent
27 extends DialogComponent implements OnInit {
31 @Input() contextOrgId: number;
33 @ViewChild('successString', { static: true }) successString: StringComponent;
34 @ViewChild('updateFailedString', { static: false }) updateFailedString: StringComponent;
35 @ViewChild('rolloverProgress', { static: true })
36 private rolloverProgress: ProgressInlineComponent;
38 includeDescendants = false;
40 showEncumbOnly = false;
41 limitToEncumbrances = false;
43 contextOrg: IdlObject;
46 years: ComboboxEntry[];
50 amount_rolled: number;
53 private idl: IdlService,
54 private evt: EventService,
55 private net: NetService,
56 private auth: AuthService,
57 private pcrud: PcrudService,
58 private perm: PermService,
59 private toast: ToastService,
60 private org: OrgService,
61 private modal: NgbModal
67 this.onOpen$.subscribe(() => this._initDialog());
68 this.doneLoading = true;
71 private _initDialog() {
72 this.contextOrg = this.org.get(this.contextOrgId);
73 this.includeDescendants = false;
74 this.doCloseout = false;
75 this.limitToEncumbrances = false;
76 this.showResults = false;
83 'open-ils.acq.fund.org.years.retrieve',
86 { limit_perm: 'VIEW_FUND' }
89 this.years = years.map(y => {
90 if (maxYear < y) { maxYear = y; }
91 return { id: y, label: y };
96 this.showEncumbOnly = false;
97 this.org.settings('acq.fund.allow_rollover_without_money', this.contextOrgId).then((ous) => {
98 this.showEncumbOnly = ous['acq.fund.allow_rollover_without_money'];
103 this.isProcessing = true;
105 const rolloverResponses: any = [];
107 let method = 'open-ils.acq.fiscal_rollover';
108 if (this.doCloseout) {
109 method += '.combined';
111 method += '.propagate';
113 if (this.dryRun) { method += '.dry_run'; }
116 this.amount_rolled = 0;
124 this.includeDescendants,
125 { encumb_only : this.limitToEncumbrances }
128 rolloverResponses.push(r.fund);
130 this.amount_rolled += Number(r.rollover_amount);
134 this.isProcessing = false;
135 this.showResults = true;
137 this.successString.current()
138 .then(str => this.toast.success(str));
140 // note that we're intentionally not closing the dialog
141 // so that user can view the results