mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
This commit is contained in:
@@ -34,6 +34,7 @@ export class ShelfOrderDetailsCardComponent {
|
||||
|
||||
get actions(): KeyValueDTOOfStringAndString[] {
|
||||
if (this.orderDetails) {
|
||||
console.log({ actions: this.orderDetails.actions });
|
||||
return this.orderDetails.actions;
|
||||
}
|
||||
|
||||
|
||||
@@ -282,30 +282,6 @@ export class ShelfOrderDetailsComponent {
|
||||
items.forEach((item) => this.selectOrderItem(item, false));
|
||||
}
|
||||
|
||||
async determineSupplier(
|
||||
items: (OrderItemListItemDTO & {
|
||||
receipts?: ReceiptDTO[];
|
||||
})[]
|
||||
) {
|
||||
const orderItemId = items.find((item) => item.orderId);
|
||||
const orderId = orderItemId && orderItemId.orderId;
|
||||
|
||||
if (!orderId) {
|
||||
return;
|
||||
}
|
||||
const compartmentCodeItem = items.find((item) => item.compartmentCode);
|
||||
const orderNumberItem = items.find((item) => item.orderNumber);
|
||||
|
||||
const compartmentCode =
|
||||
compartmentCodeItem && compartmentCodeItem.compartmentCode;
|
||||
const orderNumber = orderNumberItem && orderNumberItem.orderNumber;
|
||||
|
||||
this.detailsFacade.determineSupplier(orderId, {
|
||||
compartmentCode,
|
||||
orderNumber,
|
||||
});
|
||||
}
|
||||
|
||||
shouldNavigateOnPartialPickUp(
|
||||
items: (OrderItemListItemDTO & {
|
||||
receipts?: ReceiptDTO[];
|
||||
@@ -320,6 +296,16 @@ export class ShelfOrderDetailsComponent {
|
||||
return shouldNavigate;
|
||||
}
|
||||
|
||||
navigateAfterSupplierDetermined(
|
||||
updatedItems: (OrderItemListItemDTO & {
|
||||
receipts?: ReceiptDTO[];
|
||||
})[]
|
||||
) {
|
||||
if (updatedItems && updatedItems[0]) {
|
||||
this.shelfNavigationService.navigateToDetails({ ...updatedItems[0] });
|
||||
}
|
||||
}
|
||||
|
||||
navigateAfterActionCompleted(
|
||||
items: (OrderItemListItemDTO & {
|
||||
receipts?: ReceiptDTO[];
|
||||
@@ -360,8 +346,9 @@ export class ShelfOrderDetailsComponent {
|
||||
let navigate = true;
|
||||
let items = await this.orderItems$.pipe(first()).toPromise();
|
||||
let results: ResponseArgsOfValueTupleOfOrderItemSubsetDTOAndOrderItemSubsetDTO[];
|
||||
|
||||
console.log({ action });
|
||||
let currentReceipts: ReceiptDTO[] = this.orderDetailsService.getReceipts(
|
||||
items
|
||||
);
|
||||
|
||||
// Early Exit for Partial Pickups
|
||||
if (this.actionHandlerService.isPartialPickup(action)) {
|
||||
@@ -377,27 +364,61 @@ export class ShelfOrderDetailsComponent {
|
||||
);
|
||||
}
|
||||
|
||||
// Step 0 [Determine if Supplier set]
|
||||
if (this.actionHandlerService.shouldDetermineSupplier(action)) {
|
||||
this.determineSupplier(items);
|
||||
const actionsToTake = this.actionHandlerService.getActions(action);
|
||||
|
||||
for (const a of actionsToTake) {
|
||||
try {
|
||||
const {
|
||||
results: newResults,
|
||||
receipts: newReceipts,
|
||||
} = await this.executeAction(a, items, currentReceipts);
|
||||
|
||||
if (newResults) {
|
||||
results = newResults;
|
||||
}
|
||||
|
||||
if (Array.isArray(newReceipts)) {
|
||||
currentReceipts = Array.from(
|
||||
new Set([...(currentReceipts || []), ...(newReceipts || [])])
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(
|
||||
`Fehler beim Aktualisieren des Postens ${
|
||||
err.message ? '(Meldung ' + err.message + ')' : ''
|
||||
})`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 1 [Set Status]
|
||||
if (this.actionHandlerService.shouldSetStatus(action)) {
|
||||
const targetStatus = this.actionHandlerService.getNewProcessingStatus(
|
||||
action
|
||||
);
|
||||
results = await this.orderDetailsService.setProcessingStatus(
|
||||
items,
|
||||
targetStatus,
|
||||
this.processingStatusChangeData
|
||||
);
|
||||
this.resetPartialPickup();
|
||||
if (navigate) {
|
||||
this.navigateAfterActionCompleted(items, results);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2 [Create Note ]
|
||||
async executeAction(
|
||||
command: string,
|
||||
items: (OrderItemListItemDTO & {
|
||||
receipts?: ReceiptDTO[];
|
||||
})[],
|
||||
latestReceipts: ReceiptDTO[]
|
||||
) {
|
||||
let results: ResponseArgsOfValueTupleOfOrderItemSubsetDTOAndOrderItemSubsetDTO[];
|
||||
let receipts: ReceiptDTO[];
|
||||
if (this.actionHandlerService.shouldCreateShippingNote(action)) {
|
||||
|
||||
if (this.actionHandlerService.shouldDetermineSupplier(command)) {
|
||||
const updatedItems = await this.orderDetailsService.setDetermineSupplier(
|
||||
items
|
||||
);
|
||||
this.navigateAfterSupplierDetermined(updatedItems);
|
||||
}
|
||||
|
||||
if (this.actionHandlerService.getActionIsStatusChange(command)) {
|
||||
results = await this.setStatus(command, items);
|
||||
}
|
||||
|
||||
if (this.actionHandlerService.shouldCreateShippingNote(command)) {
|
||||
receipts = await this.shippingNoteService.create(
|
||||
this.shippingNoteService.getSubsetIdsForWhichToCreateShippingNotes(
|
||||
items
|
||||
@@ -406,17 +427,11 @@ export class ShelfOrderDetailsComponent {
|
||||
);
|
||||
}
|
||||
|
||||
// Step 3 [Print Note]
|
||||
if (this.actionHandlerService.shouldPrintShippingNote(action)) {
|
||||
const existingReceipts = this.orderDetailsService.getReceipts(items);
|
||||
await this.shippingNoteService.print(
|
||||
[...existingReceipts, ...(receipts || [])],
|
||||
this.printData
|
||||
);
|
||||
if (this.actionHandlerService.shouldPrintShippingNote(command)) {
|
||||
await this.shippingNoteService.print(latestReceipts, this.printData);
|
||||
}
|
||||
|
||||
// Step 4 [Print Abholfachetikett]
|
||||
if (this.actionHandlerService.shouldPrintAbholfachetikett(action)) {
|
||||
if (this.actionHandlerService.shouldPrintAbholfachetikett(command)) {
|
||||
await this.abholfachEtikettService.print(
|
||||
this.abholfachEtikettService.orderSubsetIdsForWhichToPrintAbholfachEtikett(
|
||||
items
|
||||
@@ -425,8 +440,25 @@ export class ShelfOrderDetailsComponent {
|
||||
);
|
||||
}
|
||||
|
||||
if (navigate) {
|
||||
this.navigateAfterActionCompleted(items, results);
|
||||
}
|
||||
return { results, receipts };
|
||||
}
|
||||
|
||||
private async setStatus(
|
||||
command: string,
|
||||
items: (OrderItemListItemDTO & {
|
||||
receipts?: ReceiptDTO[];
|
||||
})[]
|
||||
) {
|
||||
const targetStatus = this.actionHandlerService.getNewProcessingStatus(
|
||||
command
|
||||
);
|
||||
const results = await this.orderDetailsService.setProcessingStatus(
|
||||
items,
|
||||
targetStatus,
|
||||
this.processingStatusChangeData
|
||||
);
|
||||
this.resetPartialPickup();
|
||||
|
||||
return results.filter((result) => !!result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,14 @@ export class ShelfActionHandlerService {
|
||||
return action.command.split('|').filter((step) => step !== '|');
|
||||
}
|
||||
|
||||
public getNewProcessingStatus(action: KeyValueDTOOfStringAndString): number {
|
||||
const commands = this.getActions(action);
|
||||
public getActionIsStatusChange(command: string) {
|
||||
const match = actionCommands[command];
|
||||
|
||||
const targetStatus = commands.find((command) => !!actionCommands[command]);
|
||||
return actionCommands[targetStatus];
|
||||
return typeof match === 'number';
|
||||
}
|
||||
|
||||
public getNewProcessingStatus(command: string): number {
|
||||
return actionCommands[command];
|
||||
}
|
||||
|
||||
public isPartialPickup(action: KeyValueDTOOfStringAndString): boolean {
|
||||
@@ -36,38 +39,19 @@ export class ShelfActionHandlerService {
|
||||
return action.command.includes('ARRIVED');
|
||||
}
|
||||
|
||||
public shouldSetStatus(action: KeyValueDTOOfStringAndString): boolean {
|
||||
const commands = this.getActions(action);
|
||||
const match = commands.find((command) => !!actionCommands[command]);
|
||||
|
||||
if (!match || this.shouldDetermineSupplier(action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
public shouldCreateShippingNote(command: string): boolean {
|
||||
return command === additionalCommands.CREATE_SHIPPINGNOTE;
|
||||
}
|
||||
|
||||
public shouldCreateShippingNote(
|
||||
action: KeyValueDTOOfStringAndString
|
||||
): boolean {
|
||||
return action.command.includes(additionalCommands.CREATE_SHIPPINGNOTE);
|
||||
public shouldDetermineSupplier(command: string): boolean {
|
||||
return command === additionalCommands.ORDER_AT_SUPPLIER;
|
||||
}
|
||||
|
||||
public shouldDetermineSupplier(
|
||||
action: KeyValueDTOOfStringAndString
|
||||
): boolean {
|
||||
return action.command.includes(additionalCommands.ORDER_AT_SUPPLIER);
|
||||
public shouldPrintShippingNote(command: string): boolean {
|
||||
return command === additionalCommands.PRINT_SHIPPINGNOTE;
|
||||
}
|
||||
|
||||
public shouldPrintShippingNote(
|
||||
action: KeyValueDTOOfStringAndString
|
||||
): boolean {
|
||||
return action.command.includes(additionalCommands.PRINT_SHIPPINGNOTE);
|
||||
}
|
||||
|
||||
public shouldPrintAbholfachetikett(
|
||||
action: KeyValueDTOOfStringAndString
|
||||
): boolean {
|
||||
return action.command.includes(additionalCommands.PRINT_COMPARTMENTLABEL);
|
||||
public shouldPrintAbholfachetikett(command: string): boolean {
|
||||
return command.includes(additionalCommands.PRINT_COMPARTMENTLABEL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ import { Injectable } from '@angular/core';
|
||||
import { DetailsFacade } from '@shelf-store/details';
|
||||
import {
|
||||
KeyValueDTOOfStringAndString,
|
||||
OrderCheckoutService,
|
||||
OrderItemListItemDTO,
|
||||
ReceiptDTO,
|
||||
ResponseArgsOfValueTupleOfOrderItemSubsetDTOAndOrderItemSubsetDTO,
|
||||
StatusValues,
|
||||
} from '@swagger/oms';
|
||||
import { Observable } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { filter, map, switchMap, take, tap } from 'rxjs/operators';
|
||||
import { OrderDetailsCardInput } from '../components/order-details-card';
|
||||
import { ProcessingStatusNameMap } from '../constants';
|
||||
import { ShelfActionHandlerService } from './shelf-action-handler.service';
|
||||
@@ -17,7 +18,8 @@ import { ShelfActionHandlerService } from './shelf-action-handler.service';
|
||||
export class ShelfOrderDetailsService {
|
||||
constructor(
|
||||
private actionHandlerService: ShelfActionHandlerService,
|
||||
private detailsFacade: DetailsFacade
|
||||
private detailsFacade: DetailsFacade,
|
||||
private orderCheckoutService: OrderCheckoutService
|
||||
) {}
|
||||
|
||||
public orderDetailsCardFromOrderItems$(
|
||||
@@ -119,7 +121,11 @@ export class ShelfOrderDetailsService {
|
||||
}
|
||||
|
||||
details.actions.some((action) =>
|
||||
this.actionHandlerService.shouldPrintShippingNote(action)
|
||||
this.actionHandlerService
|
||||
.getActions(action)
|
||||
.some((command) =>
|
||||
this.actionHandlerService.shouldPrintShippingNote(command)
|
||||
)
|
||||
);
|
||||
})
|
||||
);
|
||||
@@ -156,6 +162,10 @@ export class ShelfOrderDetailsService {
|
||||
results = await this.setReorder(items);
|
||||
break;
|
||||
|
||||
case 268435456:
|
||||
results = await this.setSupplier(items);
|
||||
break;
|
||||
|
||||
default:
|
||||
results = await this.setStatus(items, status);
|
||||
break;
|
||||
@@ -224,4 +234,55 @@ export class ShelfOrderDetailsService {
|
||||
);
|
||||
return this.detailsFacade.changeStatus(payloads);
|
||||
}
|
||||
|
||||
setSupplier(
|
||||
items: (OrderItemListItemDTO & {
|
||||
receipts?: ReceiptDTO[];
|
||||
})[]
|
||||
) {
|
||||
return this.setStatus(items, 268435456);
|
||||
}
|
||||
|
||||
async setDetermineSupplier(
|
||||
items: (OrderItemListItemDTO & {
|
||||
receipts?: ReceiptDTO[];
|
||||
})[]
|
||||
) {
|
||||
const orderItemId = items.find((item) => item.orderId);
|
||||
const orderId = orderItemId && orderItemId.orderId;
|
||||
|
||||
if (!orderId) {
|
||||
return;
|
||||
}
|
||||
const compartmentCodeItem = items.find((item) => item.compartmentCode);
|
||||
const orderNumberItem = items.find((item) => item.orderNumber);
|
||||
|
||||
const compartmentCode =
|
||||
compartmentCodeItem && compartmentCodeItem.compartmentCode;
|
||||
const orderNumber = orderNumberItem && orderNumberItem.orderNumber;
|
||||
|
||||
if (compartmentCode || orderNumber) {
|
||||
const result = await this.orderCheckoutService
|
||||
.OrderCheckoutOrderAtSupplierResponse(orderId)
|
||||
.pipe(
|
||||
tap((response) =>
|
||||
this.detailsFacade.setDeterminedSupplier(
|
||||
response,
|
||||
compartmentCodeItem || orderNumberItem
|
||||
)
|
||||
),
|
||||
map((response) => response.body && response.body.result),
|
||||
switchMap((data) =>
|
||||
this.detailsFacade.getOrderItemsByOrderNumber$(data.orderNumber)
|
||||
),
|
||||
filter(
|
||||
(itms) => Array.isArray(itms) && itms[0].processingStatus !== 1
|
||||
),
|
||||
take(1)
|
||||
)
|
||||
.toPromise();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import {
|
||||
OrderService,
|
||||
OrderItemProcessingStatusValue,
|
||||
ReceiptDTO,
|
||||
StrictHttpResponse,
|
||||
ResponseArgsOfSupplierOrderResult,
|
||||
} from '@swagger/oms';
|
||||
import { Observable, concat } from 'rxjs';
|
||||
import * as actions from './details.actions';
|
||||
@@ -324,4 +326,14 @@ export class DetailsFacade {
|
||||
|
||||
return this.patchOrderItemSubsets(payload);
|
||||
}
|
||||
|
||||
setDeterminedSupplier(
|
||||
response: StrictHttpResponse<ResponseArgsOfSupplierOrderResult>,
|
||||
item: {
|
||||
compartmentCode?: string;
|
||||
orderNumber?: string;
|
||||
}
|
||||
): void {
|
||||
this.store.dispatch(actions.determineSupplierDone({ response, item }));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user