LP#1942220: implement LI search action cancel
authorGalen Charlton <gmc@equinoxOLI.org>
Tue, 14 Dec 2021 23:30:39 +0000 (18:30 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Tue, 14 Dec 2021 23:30:39 +0000 (18:30 -0500)
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts

index 0b443b9..6baf6ab 100644 (file)
@@ -4,10 +4,12 @@
 
 <eg-acq-export-attributes-dialog #exportAttributesDialog></eg-acq-export-attributes-dialog>
 <eg-acq-claim-policy-dialog #claimPolicyDialog></eg-acq-claim-policy-dialog>
+<eg-acq-cancel-dialog #cancelDialog></eg-acq-cancel-dialog>
 
 <eg-string #claimPolicyAppliedString i18n-text text="Claim Policy Applied to Selected Line Item(s)"></eg-string>
 <eg-string #lineItemsReceivedString i18n-text text="Line Item(s) Received"></eg-string>
 <eg-string #lineItemsUnReceivedString i18n-text text="Line Item(s) Un-Received"></eg-string>
+<eg-string #lineItemsCancelledString i18n-text text="Line Item(s) Canceled"></eg-string>
 
 <eg-alert-dialog #noActionableLIs i18n-dialogBody
   dialogBody="None of the selected line items are suitable for the action.">
index bea5ca5..35b43b4 100644 (file)
@@ -16,6 +16,7 @@ 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';
+import {CancelDialogComponent} from '../lineitem/cancel-dialog.component';
 
 @Component({
   selector: 'eg-lineitem-results',
@@ -30,9 +31,11 @@ export class LineitemResultsComponent implements OnInit {
     @ViewChild('acqSearchLineitemsGrid', { static: true }) lineitemResultsGrid: GridComponent;
     @ViewChild('exportAttributesDialog') exportAttributesDialog: ExportAttributesDialogComponent;
     @ViewChild('claimPolicyDialog') claimPolicyDialog: ClaimPolicyDialogComponent;
+    @ViewChild('cancelDialog') cancelDialog: CancelDialogComponent;
     @ViewChild('claimPolicyAppliedString', { static: false }) claimPolicyAppliedString: StringComponent;
     @ViewChild('lineItemsReceivedString', { static: false }) lineItemsReceivedString: StringComponent;
     @ViewChild('lineItemsUnReceivedString', { static: false }) lineItemsUnReceivedString: StringComponent;
+    @ViewChild('lineItemsCancelledString', { static: false }) lineItemsCancelledString: StringComponent;
     @ViewChild('noActionableLIs', { static: true }) private noActionableLIs: AlertDialogComponent;
 
     noSelectedRows: (rows: IdlObject[]) => boolean;
@@ -126,6 +129,31 @@ export class LineitemResultsComponent implements OnInit {
         });
     }
 
+    cancelLineitems(rows: IdlObject[]) {
+        // must be attached to a PO and have a state of
+        // either 'on-order' or 'cancelled'
+        const lis = rows.filter(l =>
+            l.purchase_order() && ['on-order', 'cancelled'].includes(l.state())
+        );
+        if (lis.length === 0) {
+            this.noActionableLIs.open();
+            return;
+        }
+        const ids = lis.map(x => Number(x.id()));
+        this.cancelDialog.open().subscribe(reason => {
+            if (!reason) { return; }
+
+            this.net.request('open-ils.acq',
+                'open-ils.acq.lineitem.cancel.batch',
+                this.auth.token(), ids, reason
+            ).toPromise().then(resp => {
+                this.lineItemsCancelledString.current()
+                .then(str => this.toast.success(str));
+                this.lineitemResultsGrid.reload();
+            });
+        });
+    }
+
     createPurchaseOrder(rows: IdlObject[]) {
         // must not be already attached to a PO
         const lis = rows.filter(l => !l.purchase_order());