</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>
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'
export class AsnReceiveComponent implements OnInit {
barcode = '';
+ receiving = false;
+ dryRun = true;
// Technically possible for one container code to match across providers.
container: IdlObject;
containers: IdlObject[] = [];
@ViewChild('grid') private grid: GridComponent;
+ @ViewChild('progress') private progress: ProgressInlineComponent;
+
gridDataSource: GridDataSource = new GridDataSource();
constructor(
private router: Router,
private ngLocation: Location,
private pcrud: PcrudService,
+ private net: NetService,
+ private auth: AuthService,
private li: LineitemService
) {}
.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;
+ }
+ );
}
}
}
+__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;