import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid';
import {AcqSearchService, AcqSearchTerm, AcqSearch} from './acq-search.service';
import {LineitemService} from '../lineitem/lineitem.service';
+import {ToastService} from '@eg/share/toast/toast.service';
import {ExportAttributesDialogComponent} from '../lineitem/export-attributes-dialog.component';
import {AcqSearchFormComponent} from './acq-search-form.component';
+import {StringComponent} from '@eg/share/string/string.component';
import {AlertDialogComponent} from '@eg/share/dialog/alert.component';
+import {ClaimPolicyDialogComponent} from '../lineitem/claim-policy-dialog.component';
@Component({
selector: 'eg-lineitem-results',
@ViewChild('acqSearchForm', { static: true}) acqSearchForm: AcqSearchFormComponent;
@ViewChild('acqSearchLineitemsGrid', { static: true }) lineitemResultsGrid: GridComponent;
@ViewChild('exportAttributesDialog') exportAttributesDialog: ExportAttributesDialogComponent;
+ @ViewChild('claimPolicyDialog') claimPolicyDialog: ClaimPolicyDialogComponent;
+ @ViewChild('claimPolicyAppliedString', { static: false }) claimPolicyAppliedString: StringComponent;
@ViewChild('noActionableLIs', { static: true }) private noActionableLIs: AlertDialogComponent;
noSelectedRows: (rows: IdlObject[]) => boolean;
private route: ActivatedRoute,
private net: NetService,
private auth: AuthService,
+ private toast: ToastService,
private liService: LineitemService,
private acqSearch: AcqSearchService) {
}
'/lineitem/' + row.id() + '/worksheet', '_blank');
}
+ applyClaimPolicy(rows: IdlObject[]) {
+ // must be attached to a PO; while this is not
+ // strictly necessary, seems to make sense that
+ // a claim policy is relevant only once you know
+ // who the vendor is
+ const lis = rows.filter(l => l.purchase_order());
+ if (lis.length === 0) {
+ this.noActionableLIs.open();
+ return;
+ }
+ const ids = lis.map(x => Number(x.id()));
+
+ this.claimPolicyDialog.ids = ids;
+ this.claimPolicyDialog.open().subscribe(claimPolicy => {
+ if (!claimPolicy) { return; }
+
+ const lisToUpdate: IdlObject[] = [];
+ this.liService.getFleshedLineitems(ids, { fromCache: true }).subscribe(
+ liStruct => {
+ liStruct.lineitem.claim_policy(claimPolicy);
+ lisToUpdate.push(liStruct.lineitem);
+ },
+ err => { },
+ () => {
+ this.net.request(
+ 'open-ils.acq',
+ 'open-ils.acq.lineitem.update',
+ this.auth.token(), lisToUpdate
+ ).toPromise().then(resp => {
+ this.claimPolicyAppliedString.current()
+ .then(str => this.toast.success(str));
+ });
+ }
+ );
+ });
+ }
+
createPurchaseOrder(rows: IdlObject[]) {
+ // must not be already attached to a PO
const lis = rows.filter(l => !l.purchase_order());
if (lis.length === 0) {
this.noActionableLIs.open();