LP#1942220: implement LI search receive and un-receive actions
authorGalen Charlton <gmc@equinoxOLI.org>
Tue, 14 Dec 2021 23:20:10 +0000 (18:20 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Tue, 14 Dec 2021 23:20:10 +0000 (18:20 -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 d348ba3..0b443b9 100644 (file)
@@ -6,6 +6,8 @@
 <eg-acq-claim-policy-dialog #claimPolicyDialog></eg-acq-claim-policy-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-alert-dialog #noActionableLIs i18n-dialogBody
   dialogBody="None of the selected line items are suitable for the action.">
     (onClick)="applyClaimPolicy($event)" [disableOnRows]="noSelectedRows">
   </eg-grid-toolbar-action>
   <eg-grid-toolbar-action label="Mark Selected Line Items as Received" i18n-label
-    (onClick)="markAsReceived($event)" [disableOnRows]="noSelectedRows">
+    (onClick)="markReceived($event)" [disableOnRows]="noSelectedRows">
   </eg-grid-toolbar-action>
   <eg-grid-toolbar-action label="Un-receive Selected Line Items" i18n-label
-    (onClick)="unReceive($event)" [disableOnRows]="noSelectedRows">
+    (onClick)="markUnReceived($event)" [disableOnRows]="noSelectedRows">
   </eg-grid-toolbar-action>
   <eg-grid-toolbar-action label="Create Invoice from Selected Line Items" i18n-label
     (onClick)="createInvoice($event)" [disableOnRows]="noSelectedRows">
index 2cb7b67..bea5ca5 100644 (file)
@@ -31,6 +31,8 @@ export class LineitemResultsComponent implements OnInit {
     @ViewChild('exportAttributesDialog') exportAttributesDialog: ExportAttributesDialogComponent;
     @ViewChild('claimPolicyDialog') claimPolicyDialog: ClaimPolicyDialogComponent;
     @ViewChild('claimPolicyAppliedString', { static: false }) claimPolicyAppliedString: StringComponent;
+    @ViewChild('lineItemsReceivedString', { static: false }) lineItemsReceivedString: StringComponent;
+    @ViewChild('lineItemsUnReceivedString', { static: false }) lineItemsUnReceivedString: StringComponent;
     @ViewChild('noActionableLIs', { static: true }) private noActionableLIs: AlertDialogComponent;
 
     noSelectedRows: (rows: IdlObject[]) => boolean;
@@ -146,4 +148,45 @@ export class LineitemResultsComponent implements OnInit {
             this.liService.doExportSingleAttributeList(ids, attr);
         });
     }
+
+    markReceived(rows: IdlObject[]) {
+        // must be on-order
+        const lis = rows.filter(l => l.state() === 'on-order');
+        if (lis.length === 0) {
+            this.noActionableLIs.open();
+            return;
+        }
+
+        const ids = rows.map(x => Number(x.id()));
+        this.net.request(
+            'open-ils.acq',
+            'open-ils.acq.lineitem.receive.batch',
+            this.auth.token(), ids
+        ).toPromise().then(resp => {
+            this.lineItemsReceivedString.current()
+            .then(str => this.toast.success(str));
+            this.lineitemResultsGrid.reload();
+        });
+    }
+
+    markUnReceived(rows: IdlObject[]) {
+        // must be received
+        const lis = rows.filter(l => l.state() === 'received');
+        if (lis.length === 0) {
+            this.noActionableLIs.open();
+            return;
+        }
+
+        const ids = rows.map(x => Number(x.id()));
+        this.net.request(
+            'open-ils.acq',
+            'open-ils.acq.lineitem.receive.rollback.batch',
+            this.auth.token(), ids
+        ).toPromise().then(resp => {
+            this.lineItemsUnReceivedString.current()
+            .then(str => this.toast.success(str));
+            this.lineitemResultsGrid.reload();
+        });
+    }
+
 }