LP#1942220: implement add selected to PO action from LI search user/gmcharlt/ang-acq-4-wip
authorGalen Charlton <gmc@equinoxOLI.org>
Thu, 16 Dec 2021 00:39:19 +0000 (19:39 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Thu, 16 Dec 2021 00:39:19 +0000 (19:39 -0500)
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/acq/lineitem/add-to-po-dialog.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/lineitem/add-to-po-dialog.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/lineitem/lineitem.module.ts
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

diff --git a/Open-ILS/src/eg2/src/app/staff/acq/lineitem/add-to-po-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/acq/lineitem/add-to-po-dialog.component.html
new file mode 100644 (file)
index 0000000..9567e2e
--- /dev/null
@@ -0,0 +1,32 @@
+<ng-template #dialogContent>
+  <form class="form-validated">
+    <div class="modal-header bg-info">
+      <h3 class="modal-title" i18n>Add Line Items to Purchase order</h3>
+      <button type="button" class="close"
+        i18n-aria-label aria-label="Close" (click)="close()">
+        <span aria-hidden="true">&times;</span>
+      </button>
+    </div>
+    <div class="modal-body">
+      <h4 i18n *ngIf="liIds && liIds.length">Line Item(s) selected:
+        <span *ngFor="let id of liIds; last as isLast">
+          {{id}}<span *ngIf="!isLast">,</span>
+        </span>
+      </h4>
+      <h4 i18n>Please select a PO and click "Add to Purchase Order" to add the line items,
+        or "Exit Dialog" to exit without adding the line items to a PO.</h4>
+      <eg-combobox domId="acq-add-to-po-dialog" name="acq-add-to-po-dialog" 
+        [asyncSupportsEmptyTermClick]="true"
+        idlClass="acqpo" [idlQueryAnd]="{state: ['new', 'pending']}"
+        idlIncludeLibraryInLabel="ordering_agency"
+        [(ngModel)]="po"></eg-combobox>
+    </div>
+    <div class="modal-footer">
+      <button type="button" class="btn btn-success" [disabled]="!po" 
+        (click)="close(po.id)" i18n>Add to Purchase Order</button>
+      <button type="button" class="btn btn-warning"
+        (click)="close()" i18n>Exit Dialog</button>
+    </div>
+  </form>
+</ng-template>
+
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/lineitem/add-to-po-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/lineitem/add-to-po-dialog.component.ts
new file mode 100644 (file)
index 0000000..5e8739d
--- /dev/null
@@ -0,0 +1,18 @@
+import {Component, Input, ViewChild, TemplateRef, OnInit} from '@angular/core';
+import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
+import {DialogComponent} from '@eg/share/dialog/dialog.component';
+import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
+
+@Component({
+  selector: 'eg-acq-add-to-po-dialog',
+  templateUrl: './add-to-po-dialog.component.html'
+})
+
+export class AddToPoDialogComponent extends DialogComponent {
+    @Input() ids: number[];
+    po: ComboboxEntry;
+    constructor(private modal: NgbModal) { super(modal); }
+}
+
+
index 06ddf9c..bec333b 100644 (file)
@@ -18,6 +18,7 @@ import {LineitemHistoryComponent} from './history.component';
 import {BriefRecordComponent} from './brief-record.component';
 import {CreateAssetsComponent} from './create-assets.component';
 import {CancelDialogComponent} from './cancel-dialog.component';
+import {AddToPoDialogComponent} from './add-to-po-dialog.component';
 import {DeleteLineitemsDialogComponent} from './delete-lineitems-dialog.component';
 import {AddCopiesDialogComponent} from './add-copies-dialog.component';
 import {LinkInvoiceDialogComponent} from './link-invoice-dialog.component';
@@ -38,6 +39,7 @@ import {AcqCommonModule} from '../acq-common.module';
     LineitemCopyAttrsComponent,
     LineitemHistoryComponent,
     CancelDialogComponent,
+    AddToPoDialogComponent,
     DeleteLineitemsDialogComponent,
     AddCopiesDialogComponent,
     LinkInvoiceDialogComponent,
@@ -50,6 +52,7 @@ import {AcqCommonModule} from '../acq-common.module';
   exports: [
     LineitemListComponent,
     CancelDialogComponent,
+    AddToPoDialogComponent,
     DeleteLineitemsDialogComponent,
     AddCopiesDialogComponent,
     LinkInvoiceDialogComponent,
index ade7c80..bf9cd85 100644 (file)
@@ -5,6 +5,7 @@
 <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-acq-add-to-po-dialog #addToPoDialog></eg-acq-add-to-po-dialog>
 <eg-acq-delete-lineitems-dialog #deleteLineitemsDialog></eg-acq-delete-lineitems-dialog>
 <eg-acq-link-invoice-dialog #linkInvoiceDialog></eg-acq-link-invoice-dialog>
 
@@ -14,6 +15,7 @@
 <eg-string #lineItemsCancelledString i18n-text text="Line Item(s) Canceled"></eg-string>
 <eg-string #lineItemsDeletedString i18n-text text="Line Item(s) Deleted"></eg-string>
 <eg-string #lineItemsUpdatedString i18n-text text="Line Item(s) Updated"></eg-string>
+<eg-string #lineItemsAddedToPoString i18n-text text="Line Item(s) Added to Purchase Order"></eg-string>
 
 <eg-alert-dialog #noActionableLIs i18n-dialogBody
   dialogBody="None of the selected line items are suitable for the action.">
index 8240717..913d352 100644 (file)
@@ -18,6 +18,7 @@ import {AlertDialogComponent} from '@eg/share/dialog/alert.component';
 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
 import {ClaimPolicyDialogComponent} from '../lineitem/claim-policy-dialog.component';
 import {CancelDialogComponent} from '../lineitem/cancel-dialog.component';
+import {AddToPoDialogComponent} from '../lineitem/add-to-po-dialog.component';
 import {DeleteLineitemsDialogComponent} from '../lineitem/delete-lineitems-dialog.component';
 import {LinkInvoiceDialogComponent} from '../lineitem/link-invoice-dialog.component';
 
@@ -35,12 +36,14 @@ export class LineitemResultsComponent implements OnInit {
     @ViewChild('exportAttributesDialog') exportAttributesDialog: ExportAttributesDialogComponent;
     @ViewChild('claimPolicyDialog') claimPolicyDialog: ClaimPolicyDialogComponent;
     @ViewChild('cancelDialog') cancelDialog: CancelDialogComponent;
+    @ViewChild('addToPoDialog') addToPoDialog: AddToPoDialogComponent;
     @ViewChild('deleteLineitemsDialog') deleteLineitemsDialog: DeleteLineitemsDialogComponent;
     @ViewChild('linkInvoiceDialog') linkInvoiceDialog: LinkInvoiceDialogComponent;
     @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('lineItemsAddedToPoString', { static: false }) lineItemsAddedToPoString: StringComponent;
     @ViewChild('lineItemsDeletedString', { static: false }) lineItemsDeletedString: StringComponent;
     @ViewChild('lineItemsUpdatedString', { static: false }) lineItemsUpdatedString: StringComponent;
     @ViewChild('noActionableLIs', { static: true }) private noActionableLIs: AlertDialogComponent;
@@ -101,6 +104,33 @@ export class LineitemResultsComponent implements OnInit {
                     '/lineitem/' + row.id() + '/worksheet', '_blank');
     }
 
+    addSelectedToPurchaseOrder(rows: IdlObject[]) {
+        // must not be already attached to a PO
+        // and be in a pre-order state
+        const lis = rows.filter(
+            l => !l.purchase_order() &&
+            ['new', 'selector-ready', 'order-ready', 'approved'].includes(l.state())
+        );
+        if (lis.length === 0) {
+            this.noActionableLIs.open();
+            return;
+        }
+        const ids = lis.map(x => Number(x.id()));
+
+        this.addToPoDialog.ids = ids;
+        this.addToPoDialog.open().subscribe(poId => {
+            this.net.request('open-ils.acq',
+                'open-ils.acq.purchase_order.add_lineitem',
+                this.auth.token(), poId, ids
+            ).toPromise().then(resp => {
+                window.open('/eg2/staff/acq/po/' + poId, '_blank');
+                this.lineItemsAddedToPoString.current()
+                .then(str => this.toast.success(str));
+                this.lineitemResultsGrid.reload();
+            });
+        });
+    }
+
     applyClaimPolicy(rows: IdlObject[]) {
         // must be attached to a PO; while this is not
         // strictly necessary, seems to make sense that