LP1952931 Receiving...
authorBill Erickson <berickxx@gmail.com>
Wed, 2 Feb 2022 18:04:34 +0000 (13:04 -0500)
committerBill Erickson <berickxx@gmail.com>
Wed, 2 Feb 2022 18:04:34 +0000 (13:04 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.html
Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm

index 68d4005..ec72062 100644 (file)
@@ -111,9 +111,27 @@ across different vendors to match a container code.
   </a>
 </ng-template>
 
-<eg-grid *ngIf="container" #grid [dataSource]="gridDataSource" 
+<div class="row" *ngIf="receiving">
+  <div class="col-lg-6 offset-lg-3">
+    <div class="card">
+      <div class="card-header" i18n>Receiving Items <span *ngIf="dryRun"> (Dry Run)</span></div>
+      <div class="card-body">
+        <ul class="list-group list-group-flush">
+          <li class="list-group-item">
+            <eg-progress-inline min="0" max="0" #progress></eg-progress-inline>
+          </li>
+        </ul>
+      </div>
+    </div>
+  </div>
+</div>
+
+<eg-grid *ngIf="container && !receiving" #grid [dataSource]="gridDataSource" 
   pageSize="50" (onRowActivate)="openLi($event)">
 
+  <eg-grid-toolbar-button i18n-label label="Receive All Items (Dry Run)"
+    (onClick)="receiveAllItems(true)"></eg-grid-toolbar-button> 
+
   <eg-grid-toolbar-button i18n-label label="Receive All Items"
     (onClick)="receiveAllItems()"></eg-grid-toolbar-button> 
 
index 0f5ad15..aea6f16 100644 (file)
@@ -5,10 +5,13 @@ import {Observable, Observer, of, from} from 'rxjs';
 import {tap} from 'rxjs/operators';
 import {IdlObject} from '@eg/core/idl.service';
 import {PcrudService} from '@eg/core/pcrud.service';
+import {NetService} from '@eg/core/net.service';
+import {AuthService} from '@eg/core/auth.service';
 import {LineitemService} from '../lineitem/lineitem.service';
 import {Pager} from '@eg/share/util/pager';
 import {GridDataSource, GridColumn, GridCellTextGenerator} from '@eg/share/grid/grid';
 import {GridComponent} from '@eg/share/grid/grid.component';
+import {ProgressInlineComponent} from '@eg/share/dialog/progress-inline.component';
 
 @Component({
   templateUrl: 'receive.component.html'
@@ -16,6 +19,8 @@ import {GridComponent} from '@eg/share/grid/grid.component';
 export class AsnReceiveComponent implements OnInit {
 
     barcode = '';
+    receiving = false;
+    dryRun = true;
 
     // Technically possible for one container code to match across providers.
     container: IdlObject;
@@ -23,6 +28,8 @@ export class AsnReceiveComponent implements OnInit {
     containers: IdlObject[] = [];
 
     @ViewChild('grid') private grid: GridComponent;
+    @ViewChild('progress') private progress: ProgressInlineComponent;
+
     gridDataSource: GridDataSource = new GridDataSource();
 
     constructor(
@@ -30,6 +37,8 @@ export class AsnReceiveComponent implements OnInit {
         private router: Router,
         private ngLocation: Location,
         private pcrud: PcrudService,
+        private net: NetService,
+        private auth: AuthService,
         private li: LineitemService
     ) {}
 
@@ -132,8 +141,27 @@ export class AsnReceiveComponent implements OnInit {
             .reduce((pv, cv) => pv + (cv || 0));
     }
 
-    receiveAllItems() {
-        alert('TODO');
+    receiveAllItems(dryRun?: boolean) {
+        this.receiving = true;
+        this.dryRun = dryRun;
+
+        setTimeout(() => // Allow time to render
+            this.progress.update({value: 0, max: this.entries.length}));
+
+        let method = 'open-ils.acq.shipment_notification.receive_items';
+        if (dryRun) { method += '.dry_run'; }
+
+        this.net.request('open-ils.acq',
+            method, this.auth.token(), this.container.id())
+        .subscribe(
+            resp => {
+                console.debug("ASN Receive returned", resp);
+            },
+            err => {},
+            () => {
+                // this.receiving = false;
+            }
+        );
     }
 }
 
index 62cd372..f03eb5f 100644 (file)
@@ -4321,5 +4321,81 @@ sub li_existing_copies {
 }
 
 
+__PACKAGE__->register_method(
+    method => 'asn_receive_items',
+    api_name => 'open-ils.acq.shipment_notification.receive_items',
+    max_bundle_count => 1,
+    signature => {
+        desc => q/
+            Mark items from a shipment notification as received.
+        /,
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => 'Shipment Notification ID', type => 'number'}
+        ],
+        return => {desc => q/Stream of status updates, event on error/}
+    }
+);
+
+__PACKAGE__->register_method(
+    method => 'asn_receive_items',
+    api_name => 'open-ils.acq.shipment_notification.receive_items.dry_run',
+    max_bundle_count => 1,
+    signature => q/dry_run variant of open-ils.acq.shipment_notification.receive_items/
+);
+
+sub asn_receive_items {
+    my ($self, $client, $auth, $asn_id) = @_;
+
+    my $e = new_editor(xact => 1, authtoken => $auth);
+    return $e->die_event unless $e->checkauth;
+
+    my $mgr = 
+        OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $client);
+
+    my $asn = $e->retrieve_acq_shipment_notification([$asn_id, 
+        {flesh => 1, flesh_fields => {acqsn => ['provider', 'entries']}}
+    ]) || return $e->die_event;
+
+    return $e->die_event unless 
+        $e->allowed('MANAGE_SHIPMENT_NOTIFICATION', $asn->provider->owner);
+
+    for my $entry (@{$asn->entries}) {
+
+        my $lid_ids = $e->search_acq_lineitem_detail([   
+            {   lineitem => $entry->lineitem, 
+                recv_time => undef,
+                cancel_reason => undef # TODO delayed?
+            }, {   
+                limit => $entry->item_count,
+                order_by => {acqlid => 'id'}
+            }],
+            {idlist => 1}
+        );
+
+        if (scalar(@$lid_ids) < $entry->item_count) {
+            $logger->warn(sprintf(
+                "ASN $asn_id entry %d found %d receivable items, but wanted %d",
+                $entry->id, scalar(@$lid_ids), $entry->item_count));
+        }
+
+        for my $li_id (@$lid_ids) {
+            return $e->die_event unless receive_lineitem_detail($mgr, $li_id);
+            $mgr->respond;
+        }
+    }
+
+    if ($self->api_name =~ /dry_run/) {
+        $e->rollback;
+    } else {
+        $e->commit;
+    }
+
+    $mgr->respond_complete;
+
+    undef;
+}
+
+
 1;