LP1952931 Receiving...
authorBill Erickson <berickxx@gmail.com>
Wed, 2 Feb 2022 20:50:02 +0000 (15:50 -0500)
committerBill Erickson <berickxx@gmail.com>
Wed, 2 Feb 2022 20:50:02 +0000 (15:50 -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 ec72062..993a605 100644 (file)
@@ -120,8 +120,19 @@ across different vendors to match a container code.
           <li class="list-group-item">
             <eg-progress-inline min="0" max="0" #progress></eg-progress-inline>
           </li>
+          <li class="list-group-item" *ngFor="let li of receiveResponse.lineitems">
+            {{li.lids.length}} item(s) received for line item
+            <a target="_blank" fragment="{{li.id}}" 
+              routerLink="/staff/acq/po/{{li.po}}">#{{li.id}}</a>.
+          </li>
         </ul>
       </div>
+      <div class="card-footer d-flex">
+        <div class="flex-1"></div>
+        <button (click)="clearReceiving()" class="btn btn-outline-dark" i18n>
+          Close
+        </button>
+      </div>
     </div>
   </div>
 </div>
index aea6f16..916c714 100644 (file)
@@ -13,6 +13,13 @@ import {GridDataSource, GridColumn, GridCellTextGenerator} from '@eg/share/grid/
 import {GridComponent} from '@eg/share/grid/grid.component';
 import {ProgressInlineComponent} from '@eg/share/dialog/progress-inline.component';
 
+interface ReceiveResponse {
+    progress: number;
+    lineitems: any[];
+    complete: boolean;
+    po: number;
+}
+
 @Component({
   templateUrl: 'receive.component.html'
 })
@@ -26,6 +33,7 @@ export class AsnReceiveComponent implements OnInit {
     container: IdlObject;
     entries: IdlObject[] = [];
     containers: IdlObject[] = [];
+    receiveResponse: ReceiveResponse;
 
     @ViewChild('grid') private grid: GridComponent;
     @ViewChild('progress') private progress: ProgressInlineComponent;
@@ -71,6 +79,7 @@ export class AsnReceiveComponent implements OnInit {
     }
 
     findContainer() {
+        this.receiving = false;
         this.container = null;
         this.containers = [];
         this.entries = [];
@@ -145,8 +154,15 @@ export class AsnReceiveComponent implements OnInit {
         this.receiving = true;
         this.dryRun = dryRun;
 
+        this.receiveResponse = {
+            progress: 0,
+            lineitems: [],
+            complete: false,
+            po: null
+        };
+
         setTimeout(() => // Allow time to render
-            this.progress.update({value: 0, max: this.entries.length}));
+            this.progress.update({value: 0, max: this.affectedItemsCount()}));
 
         let method = 'open-ils.acq.shipment_notification.receive_items';
         if (dryRun) { method += '.dry_run'; }
@@ -155,7 +171,9 @@ export class AsnReceiveComponent implements OnInit {
             method, this.auth.token(), this.container.id())
         .subscribe(
             resp => {
+                this.progress.update({value: resp.progress});
                 console.debug("ASN Receive returned", resp);
+                this.receiveResponse = resp;
             },
             err => {},
             () => {
@@ -163,5 +181,10 @@ export class AsnReceiveComponent implements OnInit {
             }
         );
     }
+
+    clearReceiving() {
+        this.receiving = false;
+        this.findContainer();
+    }
 }
 
index f03eb5f..7a2b792 100644 (file)
@@ -4350,8 +4350,8 @@ sub asn_receive_items {
     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 $mgr = OpenILS::Application::Acq::BatchManager->new(
+        editor => $e, conn => $client, throttle => 1);
 
     my $asn = $e->retrieve_acq_shipment_notification([$asn_id, 
         {flesh => 1, flesh_fields => {acqsn => ['provider', 'entries']}}
@@ -4360,10 +4360,28 @@ sub asn_receive_items {
     return $e->die_event unless 
         $e->allowed('MANAGE_SHIPMENT_NOTIFICATION', $asn->provider->owner);
 
-    for my $entry (@{$asn->entries}) {
+    my $resp = {
+        lineitems => [],
+        progress => 0,
+    };
+
+    my @entries = sort {$a->lineitem cmp $b->lineitem} @{$asn->entries};
+
+    for my $entry (@entries) {
+
+        my $li = $e->retrieve_acq_lineitem($entry->lineitem)
+            or return $e->die_event;
+
+        my $li_resp = {
+            id => $entry->lineitem, 
+            po => $li->purchase_order, 
+            lids => []
+        };
 
-        my $lid_ids = $e->search_acq_lineitem_detail([   
-            {   lineitem => $entry->lineitem, 
+        push(@{$resp->{lineitems}}, $li_resp);
+            
+        my $lid_ids = $e->search_acq_lineitem_detail(
+            [{  lineitem => $entry->lineitem, 
                 recv_time => undef,
                 cancel_reason => undef # TODO delayed?
             }, {   
@@ -4381,7 +4399,18 @@ sub asn_receive_items {
 
         for my $li_id (@$lid_ids) {
             return $e->die_event unless receive_lineitem_detail($mgr, $li_id);
-            $mgr->respond;
+
+            my $lid = $e->retrieve_acq_lineitem_detail($li_id);
+
+            my $note = $lid->note ? $lid->note . "\n" : '';
+            $note .= "Received via shipment notification #$asn_id";
+            $lid->note($note);
+
+            $e->update_acq_lineitem_detail($lid) or return $e->die_event;
+
+            push(@{$li_resp->{lids}}, $li_id);
+            $resp->{progress}++;
+            $client->respond($resp);
         }
     }
 
@@ -4391,7 +4420,8 @@ sub asn_receive_items {
         $e->commit;
     }
 
-    $mgr->respond_complete;
+    $resp->{complete} = 1;
+    $client->respond_complete($resp);
 
     undef;
 }