mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
Merged in feature/HIMA-1005-order-confirmation-is-not-showing (pull request #1056)
[HIMA-1005] fixed issue with orders that were not shown in the ISA, this happened for orders with items that were split in multiple items because one supplier could not provide all the amount of the items, some of the split items were missing the promotio
This commit is contained in:
@@ -64,7 +64,7 @@ export class SharedSelectors {
|
||||
return {
|
||||
processId: currentProcessId,
|
||||
customer: detailsCustomer,
|
||||
breadcrumbs: currentBreadcrumbs ? currentBreadcrumbs.breadcrumbs : null,
|
||||
breadcrumbs: currentBreadcrumbs ? currentBreadcrumbs.breadcrumbs : null
|
||||
};
|
||||
}
|
||||
|
||||
@@ -287,14 +287,14 @@ export class SharedSelectors {
|
||||
deliveryPrice: cartEntry.deliveryPrice,
|
||||
downloadPrice: cartEntry.downloadPrice,
|
||||
deliveryDate: cartEntry.deliveryDate,
|
||||
pickUpDate: cartEntry.pickUpDate,
|
||||
pickUpDate: cartEntry.pickUpDate
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
cart: cartData,
|
||||
customer: currentCustomer,
|
||||
promotionPoints: promotionPoints,
|
||||
promotionPoints: promotionPoints
|
||||
};
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ export class SharedSelectors {
|
||||
|
||||
return {
|
||||
processId,
|
||||
customers,
|
||||
customers
|
||||
};
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ export class SharedSelectors {
|
||||
const currentProducts = products.products[currentProcessId];
|
||||
|
||||
return {
|
||||
itemsDTO: currentProducts ? currentProducts : null,
|
||||
itemsDTO: currentProducts ? currentProducts : null
|
||||
};
|
||||
}
|
||||
|
||||
@@ -428,78 +428,84 @@ export class SharedSelectors {
|
||||
const currentProcess = process.processes[processId];
|
||||
|
||||
if (currentProcess) {
|
||||
// get all data
|
||||
const cartData: OrderItem[] = [];
|
||||
const orders = currentProcess.finishedOrder;
|
||||
const orderIds: string[] = [];
|
||||
let totalSum = 0;
|
||||
let totalQuantity = 0;
|
||||
let promotionPoints = 0;
|
||||
let targetBranchName = '';
|
||||
let targetBranchAddress = '';
|
||||
try {
|
||||
// get all data
|
||||
const cartData: OrderItem[] = [];
|
||||
const orders = currentProcess.finishedOrder;
|
||||
const orderIds: string[] = [];
|
||||
let totalSum = 0;
|
||||
let totalQuantity = 0;
|
||||
let promotionPoints = 0;
|
||||
let targetBranchName = '';
|
||||
let targetBranchAddress = '';
|
||||
|
||||
if (orders && orders.displayOrder) {
|
||||
orders.displayOrder.forEach((order: DisplayOrderDTO) => {
|
||||
orderIds.push(order.orderNumber);
|
||||
order.items.forEach((item: DisplayOrderItemDTO) => {
|
||||
if (order.orderType === DeliveryType['Branch']) {
|
||||
targetBranchName = order.targetBranch.name;
|
||||
// tslint:disable-next-line: max-line-length
|
||||
targetBranchAddress = `${undefinedToEmptyStringOrValue(order.targetBranch.address.street)} ${undefinedToEmptyStringOrValue(
|
||||
order.targetBranch.address.streetNumber
|
||||
)}, ${undefinedToEmptyStringOrValue(order.targetBranch.address.zipCode)} ${undefinedToEmptyStringOrValue(
|
||||
order.targetBranch.address.city
|
||||
)}`;
|
||||
}
|
||||
if (orders && orders.displayOrder) {
|
||||
orders.displayOrder.forEach((order: DisplayOrderDTO) => {
|
||||
orderIds.push(order.orderNumber);
|
||||
order.items.forEach((item: DisplayOrderItemDTO) => {
|
||||
if (order.orderType === DeliveryType['Branch']) {
|
||||
targetBranchName = order.targetBranch.name;
|
||||
// tslint:disable-next-line: max-line-length
|
||||
targetBranchAddress = `${undefinedToEmptyStringOrValue(order.targetBranch.address.street)} ${undefinedToEmptyStringOrValue(
|
||||
order.targetBranch.address.streetNumber
|
||||
)}, ${undefinedToEmptyStringOrValue(order.targetBranch.address.zipCode)} ${undefinedToEmptyStringOrValue(
|
||||
order.targetBranch.address.city
|
||||
)}`;
|
||||
}
|
||||
|
||||
totalSum += item.price.value.value * item.quantity;
|
||||
totalQuantity += item.quantity;
|
||||
promotionPoints += item.quantity * item.promotion.points;
|
||||
const isDownload = item.product.format === 'EB' || item.product.format === 'DL';
|
||||
const orderItem: OrderItem = {
|
||||
id: +item.product.catalogProductNumber,
|
||||
orderId: order.id,
|
||||
orderNumber: order.orderNumber,
|
||||
orderType: order.orderType,
|
||||
book: item.product,
|
||||
quantity: item.quantity,
|
||||
currency: item.price.value.currency,
|
||||
price: item.price.value.value,
|
||||
imgUrl: item.product.ean,
|
||||
isTakeNow: item.subsetItems[0].supplierLabel === 'F' ? true : false,
|
||||
isDownload: isDownload,
|
||||
orderDate: item.orderDate,
|
||||
targetBranchName: targetBranchName,
|
||||
targetBranchAddress: targetBranchAddress,
|
||||
};
|
||||
totalSum += item.price.value.value * item.quantity;
|
||||
totalQuantity += item.quantity;
|
||||
if (item.promotion) {
|
||||
promotionPoints += item.quantity * item.promotion.points;
|
||||
}
|
||||
const isDownload = item.product.format === 'EB' || item.product.format === 'DL';
|
||||
const orderItem: OrderItem = {
|
||||
id: +item.product.catalogProductNumber,
|
||||
orderId: order.id,
|
||||
orderNumber: order.orderNumber,
|
||||
orderType: order.orderType,
|
||||
book: item.product,
|
||||
quantity: item.quantity,
|
||||
currency: item.price.value.currency,
|
||||
price: item.price.value.value,
|
||||
imgUrl: item.product.ean,
|
||||
isTakeNow: item.subsetItems[0].supplierLabel === 'F' ? true : false,
|
||||
isDownload: isDownload,
|
||||
orderDate: item.orderDate,
|
||||
targetBranchName: targetBranchName,
|
||||
targetBranchAddress: targetBranchAddress
|
||||
};
|
||||
|
||||
if (order.orderType === DeliveryType['ShippingAddress']) {
|
||||
orderItem.deliveryDate = item.subsetItems[0].estimatedShippingDate;
|
||||
}
|
||||
if (order.orderType === DeliveryType['ShippingAddress']) {
|
||||
orderItem.deliveryDate = item.subsetItems[0].estimatedShippingDate;
|
||||
}
|
||||
|
||||
if (order.orderType === DeliveryType['Branch']) {
|
||||
orderItem.pickUpDate = item.subsetItems[0].estimatedShippingDate;
|
||||
}
|
||||
if (order.orderType === DeliveryType['Branch']) {
|
||||
orderItem.pickUpDate = item.subsetItems[0].estimatedShippingDate;
|
||||
}
|
||||
|
||||
cartData.push(orderItem);
|
||||
cartData.push(orderItem);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const takeNowItems = cartData.filter((item: OrderItem) => item.isTakeNow);
|
||||
const pickUpItems = cartData.filter((item: OrderItem) => !item.isTakeNow && item.orderType === DeliveryType['Branch']);
|
||||
const takeNowItems = cartData.filter((item: OrderItem) => item.isTakeNow);
|
||||
const pickUpItems = cartData.filter((item: OrderItem) => !item.isTakeNow && item.orderType === DeliveryType['Branch']);
|
||||
|
||||
// Prepare object for components
|
||||
return {
|
||||
cart: cartData,
|
||||
failedItemIds: orders.failedItemIds,
|
||||
totalSum: totalSum,
|
||||
totalQuantity: totalQuantity,
|
||||
cartId: currentProcess.cartId,
|
||||
orderIds: orderIds,
|
||||
isTakeNowOnly: takeNowItems && cartData && takeNowItems.length === cartData.length ? true : false,
|
||||
isPickUpOnly: pickUpItems && cartData && pickUpItems.length === cartData.length ? true : false,
|
||||
promotionPoints: promotionPoints,
|
||||
};
|
||||
// Prepare object for components
|
||||
return {
|
||||
cart: cartData,
|
||||
failedItemIds: orders.failedItemIds,
|
||||
totalSum: totalSum,
|
||||
totalQuantity: totalQuantity,
|
||||
cartId: currentProcess.cartId,
|
||||
orderIds: orderIds,
|
||||
isTakeNowOnly: takeNowItems && cartData && takeNowItems.length === cartData.length ? true : false,
|
||||
isPickUpOnly: pickUpItems && cartData && pickUpItems.length === cartData.length ? true : false,
|
||||
promotionPoints: promotionPoints
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,7 +546,7 @@ export class SharedSelectors {
|
||||
} else {
|
||||
return <FilterItem>{ ...item, selected: false };
|
||||
}
|
||||
}),
|
||||
})
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -572,10 +572,11 @@ export class ProcessState {
|
||||
const recentArticles = state.recentArticles;
|
||||
const currentProcessId = this.store.selectSnapshot(AppState.getCurrentProcessId);
|
||||
const process = { ...currentProcesses[currentProcessId], finishedOrder: order };
|
||||
ctx.setState(this.updateProcess(process));
|
||||
|
||||
let processes = { ...currentProcesses };
|
||||
const processes = { ...currentProcesses };
|
||||
processes[process.id] = process;
|
||||
console.log(processes);
|
||||
ctx.patchState({ processes: processes });
|
||||
|
||||
this.syncApiState(currentProcessId, processes, recentArticles);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,38 +3,16 @@ import { Select, Store } from '@ngxs/store';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { User, Address } from '../../../../core/models/user.model';
|
||||
import { BookData } from '../../../../core/models/book-data.model';
|
||||
import {
|
||||
takeUntil,
|
||||
take,
|
||||
filter,
|
||||
tap,
|
||||
distinctUntilChanged
|
||||
} from 'rxjs/operators';
|
||||
import { takeUntil, take, filter, tap, distinctUntilChanged } from 'rxjs/operators';
|
||||
import { SharedSelectors } from '../../../../core/store/selectors/shared.selectors';
|
||||
import {
|
||||
PopBreadcrumbsBeforeCurrent,
|
||||
UpdateCurrentBreadcrumbName
|
||||
} from '../../../../core/store/actions/breadcrumb.actions';
|
||||
import {
|
||||
DeleteCart,
|
||||
SetCartToProcess
|
||||
} from '../../../../core/store/actions/cart.actions';
|
||||
import {
|
||||
ResetProcess,
|
||||
EmptyFinishedOrders
|
||||
} from '../../../../core/store/actions/process.actions';
|
||||
import {
|
||||
shrinkTitleAnimation,
|
||||
shrinkSecondaryAnimation,
|
||||
shrinkMainCard
|
||||
} from '../cart-confirmation/shrink.animation';
|
||||
import { PopBreadcrumbsBeforeCurrent, UpdateCurrentBreadcrumbName } from '../../../../core/store/actions/breadcrumb.actions';
|
||||
import { DeleteCart, SetCartToProcess } from '../../../../core/store/actions/cart.actions';
|
||||
import { ResetProcess, EmptyFinishedOrders } from '../../../../core/store/actions/process.actions';
|
||||
import { shrinkTitleAnimation, shrinkSecondaryAnimation, shrinkMainCard } from '../cart-confirmation/shrink.animation';
|
||||
import { OrderItem } from '../../../../core/models/order-item';
|
||||
import { ProcessCartConfirmed } from '../../../../core/models/process-cart-confirmed.model';
|
||||
import { PrinterService } from '../../../../core/services/printer.service';
|
||||
import {
|
||||
isArrayOfMinLengthDefined,
|
||||
undefinedToEmptyStringOrValue
|
||||
} from '../../../../core/utils/app.utils';
|
||||
import { isArrayOfMinLengthDefined, undefinedToEmptyStringOrValue } from '../../../../core/utils/app.utils';
|
||||
import { PrinterSelectionComponent } from '../../../../components/printer-selection/printer-selection.component';
|
||||
import { DeliveryType } from '../../../../core/models/delivery-option.model';
|
||||
import { isNullOrUndefined } from 'util';
|
||||
@@ -57,9 +35,7 @@ export interface OrderData {
|
||||
animations: [shrinkTitleAnimation, shrinkSecondaryAnimation, shrinkMainCard]
|
||||
})
|
||||
export class CartConfirmationComponent implements OnInit, OnDestroy {
|
||||
@Select(SharedSelectors.getConfirmedCart) cartData$: Observable<
|
||||
ProcessCartConfirmed
|
||||
>;
|
||||
@Select(SharedSelectors.getConfirmedCart) cartData$: Observable<ProcessCartConfirmed>;
|
||||
@Select(SharedSelectors.getFinishedOrderCustomer) customer$: Observable<User>;
|
||||
@ViewChild('printModal') printModal: PrinterSelectionComponent;
|
||||
|
||||
@@ -110,14 +86,9 @@ export class CartConfirmationComponent implements OnInit, OnDestroy {
|
||||
.pipe(
|
||||
takeUntil(this.destroy$),
|
||||
filter(data => isArrayOfMinLengthDefined(data, 'cart', 0)),
|
||||
distinctUntilChanged(
|
||||
(prev, curr) =>
|
||||
prev && curr && JSON.stringify(prev) === JSON.stringify(curr)
|
||||
)
|
||||
distinctUntilChanged((prev, curr) => prev && curr && JSON.stringify(prev) === JSON.stringify(curr))
|
||||
)
|
||||
.subscribe((processCart: ProcessCartConfirmed) =>
|
||||
this.processOrder(processCart)
|
||||
);
|
||||
.subscribe((processCart: ProcessCartConfirmed) => this.processOrder(processCart));
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
@@ -126,16 +97,12 @@ export class CartConfirmationComponent implements OnInit, OnDestroy {
|
||||
|
||||
expand() {
|
||||
this.expanded = !this.expanded;
|
||||
this.store.dispatch(
|
||||
new UpdateCurrentBreadcrumbName(
|
||||
this.expanded ? this.title : 'Empfehlungen',
|
||||
'shoppingCart'
|
||||
)
|
||||
);
|
||||
this.store.dispatch(new UpdateCurrentBreadcrumbName(this.expanded ? this.title : 'Empfehlungen', 'shoppingCart'));
|
||||
}
|
||||
|
||||
private processOrder(processCart: ProcessCartConfirmed) {
|
||||
this.orders = [];
|
||||
console.log(processCart);
|
||||
if (processCart) {
|
||||
this.failedItemsIds = processCart.failedItemIds;
|
||||
this.isPickUpOnly = processCart.isPickUpOnly;
|
||||
@@ -147,22 +114,15 @@ export class CartConfirmationComponent implements OnInit, OnDestroy {
|
||||
this.booksTotalSum = processCart.totalSum;
|
||||
|
||||
this.orderIds.forEach((orderNumber: string) => {
|
||||
const order = this.booksFromOrder.find(
|
||||
(itemInOrder: OrderItem) => itemInOrder.orderNumber === orderNumber
|
||||
);
|
||||
const order = this.booksFromOrder.find((itemInOrder: OrderItem) => itemInOrder.orderNumber === orderNumber);
|
||||
|
||||
const isDownload =
|
||||
order.book.format === 'EB' || order.book.format === 'DL';
|
||||
const isDownload = order.book.format === 'EB' || order.book.format === 'DL';
|
||||
this.orders.push({
|
||||
orderId: order.orderId,
|
||||
orderNumber: order.orderNumber,
|
||||
isDelivery:
|
||||
order.orderType === DeliveryType['ShippingAddress'] && !isDownload,
|
||||
isDownload:
|
||||
order.orderType === DeliveryType['Download'] || isDownload,
|
||||
items: this.booksFromOrder.filter(
|
||||
(itemInOrder: OrderItem) => itemInOrder.orderNumber === orderNumber
|
||||
),
|
||||
isDelivery: order.orderType === DeliveryType['ShippingAddress'] && !isDownload,
|
||||
isDownload: order.orderType === DeliveryType['Download'] || isDownload,
|
||||
items: this.booksFromOrder.filter((itemInOrder: OrderItem) => itemInOrder.orderNumber === orderNumber),
|
||||
orderDate: order.orderDate,
|
||||
targetBranchName: order.targetBranchName,
|
||||
targetBranchAddress: order.targetBranchAddress
|
||||
@@ -201,13 +161,11 @@ export class CartConfirmationComponent implements OnInit, OnDestroy {
|
||||
|
||||
if (this.isAddressSet(customer.delivery_addres)) {
|
||||
// tslint:disable-next-line: max-line-length
|
||||
delAddress = `${undefinedToEmptyStringOrValue(
|
||||
customer.delivery_addres.street
|
||||
)} ${undefinedToEmptyStringOrValue(
|
||||
delAddress = `${undefinedToEmptyStringOrValue(customer.delivery_addres.street)} ${undefinedToEmptyStringOrValue(
|
||||
customer.delivery_addres.streetNo + ''
|
||||
)}, ${undefinedToEmptyStringOrValue(
|
||||
customer.delivery_addres.zip + ''
|
||||
)} ${undefinedToEmptyStringOrValue(customer.delivery_addres.city)}`;
|
||||
)}, ${undefinedToEmptyStringOrValue(customer.delivery_addres.zip + '')} ${undefinedToEmptyStringOrValue(
|
||||
customer.delivery_addres.city
|
||||
)}`;
|
||||
}
|
||||
|
||||
delAddress = delAddress ? delAddress : '';
|
||||
@@ -229,10 +187,7 @@ export class CartConfirmationComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
async print(printer: string) {
|
||||
const printResponse = await this.printer.printOrder(
|
||||
[this.printOrderId],
|
||||
printer
|
||||
);
|
||||
const printResponse = await this.printer.printOrder([this.printOrderId], printer);
|
||||
|
||||
if (!printResponse.error) {
|
||||
this.printModal.closeModal();
|
||||
|
||||
@@ -25,6 +25,7 @@ import { SharedSelectors } from '../../../../core/store/selectors/shared.selecto
|
||||
import { SearchDropdownComponent } from '@libs/ui/lib/search-dropdown';
|
||||
import { AddBranchesIfNotLoaded } from 'apps/sales/src/app/core/store/actions/branch.actions';
|
||||
import { allowedAvailabilityStatusCodes } from 'apps/sales/src/app/core/utils/product.util';
|
||||
import { ViewRef_ } from '@angular/core/src/view';
|
||||
|
||||
@Component({
|
||||
selector: 'app-checkout',
|
||||
@@ -489,7 +490,7 @@ export class ProductCheckoutComponent implements OnInit, OnDestroy {
|
||||
if (allowedAvailabilityStatusCodes(preferedAv.status)) {
|
||||
preferredQty = preferedAv.qty;
|
||||
}
|
||||
this.cdrf.detectChanges();
|
||||
this.detectChanges();
|
||||
}
|
||||
if (preferredQty) {
|
||||
return preferredQty;
|
||||
@@ -516,7 +517,7 @@ export class ProductCheckoutComponent implements OnInit, OnDestroy {
|
||||
if (allowedAvailabilityStatusCodes(preferedAv.status)) {
|
||||
preferredQty = preferedAv.qty;
|
||||
}
|
||||
this.cdrf.detectChanges();
|
||||
this.detectChanges();
|
||||
}
|
||||
if (preferredQty) {
|
||||
return preferredQty;
|
||||
@@ -626,4 +627,12 @@ export class ProductCheckoutComponent implements OnInit, OnDestroy {
|
||||
ngOnDestroy() {
|
||||
this.destroy$.next();
|
||||
}
|
||||
|
||||
detectChanges() {
|
||||
setTimeout(() => {
|
||||
if (this.cdrf !== null && this.cdrf !== undefined && !(this.cdrf as ViewRef_).destroyed) {
|
||||
this.cdrf.detectChanges();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user