mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
@@ -5,34 +5,31 @@ import {
|
||||
BranchDTO,
|
||||
OLAAvailabilityDTO,
|
||||
StoreCheckoutBranchService,
|
||||
StoreCheckoutService,
|
||||
StoreCheckoutSupplierService,
|
||||
SupplierDTO,
|
||||
} from '@swagger/checkout';
|
||||
import { combineLatest, Observable, of } from 'rxjs';
|
||||
import {
|
||||
AvailabilityRequestDTO,
|
||||
AvailabilityService as SwaggerAvailabilityService,
|
||||
AvailabilityService,
|
||||
AvailabilityDTO as SwaggerAvailabilityDTO,
|
||||
AvailabilityType,
|
||||
} from '@swagger/availability';
|
||||
import { AvailabilityDTO as CatAvailabilityDTO } from '@swagger/cat';
|
||||
import { map, shareReplay, switchMap, withLatestFrom, mergeMap, timeout } from 'rxjs/operators';
|
||||
import { isArray, memorize } from '@utils/common';
|
||||
import { LogisticianService, OrderService } from '@swagger/oms';
|
||||
import { LogisticianDTO, LogisticianService } from '@swagger/oms';
|
||||
import { ResponseArgsOfIEnumerableOfStockInfoDTO, StockDTO, StockInfoDTO, StockService } from '@swagger/remi';
|
||||
import { ItemData } from './defs/item-data.model';
|
||||
import { PriceDTO } from '@swagger/availability';
|
||||
import { AvailabilityByBranchDTO } from './defs/availability-by-branch-dto.model';
|
||||
import { AvailabilityByBranchDTO, ItemData } from './defs';
|
||||
import { Availability } from './defs/availability';
|
||||
|
||||
@Injectable()
|
||||
export class DomainAvailabilityService {
|
||||
constructor(
|
||||
private swaggerAvailabilityService: SwaggerAvailabilityService,
|
||||
private storeCheckoutService: StoreCheckoutService,
|
||||
private orderService: OrderService,
|
||||
private logisticanService: LogisticianService,
|
||||
private _stock: StockService,
|
||||
private _availabilityService: AvailabilityService,
|
||||
private _logisticanService: LogisticianService,
|
||||
private _stockService: StockService,
|
||||
private _supplierService: StoreCheckoutSupplierService,
|
||||
private _branchService: StoreCheckoutBranchService
|
||||
) {}
|
||||
@@ -63,7 +60,7 @@ export class DomainAvailabilityService {
|
||||
|
||||
@memorize()
|
||||
getCurrentStock(): Observable<StockDTO> {
|
||||
return this._stock.StockCurrentStock().pipe(
|
||||
return this._stockService.StockCurrentStock().pipe(
|
||||
map((response) => response.result),
|
||||
shareReplay()
|
||||
);
|
||||
@@ -71,7 +68,7 @@ export class DomainAvailabilityService {
|
||||
|
||||
@memorize()
|
||||
getCurrentBranch(): Observable<BranchDTO> {
|
||||
return this._stock.StockCurrentBranch().pipe(
|
||||
return this._stockService.StockCurrentBranch().pipe(
|
||||
map((response) => ({
|
||||
id: response.result.id,
|
||||
name: response.result.name,
|
||||
@@ -94,8 +91,8 @@ export class DomainAvailabilityService {
|
||||
}
|
||||
|
||||
@memorize({})
|
||||
getLogisticians() {
|
||||
return this.logisticanService.LogisticianGetLogisticians({}).pipe(
|
||||
getLogisticians(): Observable<LogisticianDTO> {
|
||||
return this._logisticanService.LogisticianGetLogisticians({}).pipe(
|
||||
map((response) => response.result?.find((l) => l.logisticianNumber === '2470')),
|
||||
shareReplay()
|
||||
);
|
||||
@@ -112,7 +109,7 @@ export class DomainAvailabilityService {
|
||||
price: PriceDTO;
|
||||
quantity: number;
|
||||
}): Observable<AvailabilityByBranchDTO[]> {
|
||||
return this._stock.StockStockRequest({ stockRequest: { branchIds, itemId } }).pipe(
|
||||
return this._stockService.StockStockRequest({ stockRequest: { branchIds, itemId } }).pipe(
|
||||
map((response) => response.result),
|
||||
withLatestFrom(this.getTakeAwaySupplier()),
|
||||
map(([result, supplier]) => {
|
||||
@@ -138,7 +135,7 @@ export class DomainAvailabilityService {
|
||||
return this.getCurrentStock().pipe(
|
||||
switchMap((s) =>
|
||||
combineLatest([
|
||||
this._stock.StockInStock({ articleIds: [item.itemId], stockId: s.id }),
|
||||
this._stockService.StockInStock({ articleIds: [item.itemId], stockId: s.id }),
|
||||
this.getTakeAwaySupplier(),
|
||||
this.getCurrentBranch(),
|
||||
])
|
||||
@@ -164,7 +161,7 @@ export class DomainAvailabilityService {
|
||||
quantity: number;
|
||||
}): Observable<AvailabilityDTO> {
|
||||
return combineLatest([
|
||||
this._stock.StockStockRequest({ stockRequest: { branchIds: [branch.id], itemId } }),
|
||||
this._stockService.StockStockRequest({ stockRequest: { branchIds: [branch.id], itemId } }),
|
||||
this.getTakeAwaySupplier(),
|
||||
]).pipe(
|
||||
map(([response, supplier]) => {
|
||||
@@ -184,7 +181,7 @@ export class DomainAvailabilityService {
|
||||
quantity: number;
|
||||
}): Observable<AvailabilityDTO> {
|
||||
return this.getCurrentStock().pipe(
|
||||
switchMap((s) => this._stock.StockInStockByEAN({ eans, stockId: s.id })),
|
||||
switchMap((s) => this._stockService.StockInStockByEAN({ eans, stockId: s.id })),
|
||||
withLatestFrom(this.getTakeAwaySupplier(), this.getCurrentBranch()),
|
||||
map(([response, supplier, branch]) => {
|
||||
return this._mapToTakeAwayAvailability({ response, supplier, branch, quantity, price });
|
||||
@@ -196,7 +193,7 @@ export class DomainAvailabilityService {
|
||||
getTakeAwayAvailabilitiesByEans({ eans }: { eans: string[] }): Observable<StockInfoDTO[]> {
|
||||
const eansFiltered = Array.from(new Set(eans));
|
||||
return this.getCurrentStock().pipe(
|
||||
switchMap((s) => this._stock.StockInStockByEAN({ eans: eansFiltered, stockId: s.id })),
|
||||
switchMap((s) => this._stockService.StockInStockByEAN({ eans: eansFiltered, stockId: s.id })),
|
||||
withLatestFrom(this.getTakeAwaySupplier(), this.getCurrentBranch()),
|
||||
map((response) => response[0].result),
|
||||
shareReplay()
|
||||
@@ -204,8 +201,16 @@ export class DomainAvailabilityService {
|
||||
}
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getPickUpAvailability({ item, branch, quantity }: { item: ItemData; quantity: number; branch: BranchDTO }): Observable<AvailabilityDTO> {
|
||||
return this.swaggerAvailabilityService
|
||||
getPickUpAvailability({
|
||||
item,
|
||||
branch,
|
||||
quantity,
|
||||
}: {
|
||||
item: ItemData;
|
||||
quantity: number;
|
||||
branch: BranchDTO;
|
||||
}): Observable<Availability<AvailabilityDTO, SwaggerAvailabilityDTO>> {
|
||||
return this._availabilityService
|
||||
.AvailabilityStoreAvailability([
|
||||
{
|
||||
qty: quantity,
|
||||
@@ -223,7 +228,7 @@ export class DomainAvailabilityService {
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getDeliveryAvailability({ item, quantity }: { item: ItemData; quantity: number }): Observable<AvailabilityDTO> {
|
||||
return this.swaggerAvailabilityService
|
||||
return this._availabilityService
|
||||
.AvailabilityShippingAvailability([
|
||||
{
|
||||
ean: item?.ean,
|
||||
@@ -241,7 +246,7 @@ export class DomainAvailabilityService {
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getDigDeliveryAvailability({ item, quantity }: { item: ItemData; quantity: number }): Observable<AvailabilityDTO> {
|
||||
return this.swaggerAvailabilityService
|
||||
return this._availabilityService
|
||||
.AvailabilityShippingAvailability([
|
||||
{
|
||||
qty: quantity,
|
||||
@@ -286,7 +291,9 @@ export class DomainAvailabilityService {
|
||||
timeout(5000),
|
||||
mergeMap((branch) =>
|
||||
this.getPickUpAvailability({ item, quantity, branch }).pipe(
|
||||
mergeMap((availability) => logistician$.pipe(map((logistician) => ({ ...availability, logistician: { id: logistician.id } })))),
|
||||
mergeMap((availability) =>
|
||||
logistician$.pipe(map((logistician) => ({ ...availability[0], logistician: { id: logistician.id } })))
|
||||
),
|
||||
shareReplay()
|
||||
)
|
||||
)
|
||||
@@ -295,7 +302,7 @@ export class DomainAvailabilityService {
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getDownloadAvailability({ item }: { item: ItemData }): Observable<AvailabilityDTO> {
|
||||
return this.swaggerAvailabilityService
|
||||
return this._availabilityService
|
||||
.AvailabilityShippingAvailability([
|
||||
{
|
||||
ean: item?.ean,
|
||||
@@ -330,11 +337,11 @@ export class DomainAvailabilityService {
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getTakeAwayAvailabilities(items: { id: number; price: PriceDTO }[], branchId: number) {
|
||||
return this._stock.StockGetStocksByBranch({ branchId }).pipe(
|
||||
return this._stockService.StockGetStocksByBranch({ branchId }).pipe(
|
||||
map((req) => req.result?.find((_) => true)?.id),
|
||||
switchMap((stockId) =>
|
||||
stockId
|
||||
? this._stock.StockInStock({ articleIds: items.map((i) => i.id), stockId })
|
||||
? this._stockService.StockInStock({ articleIds: items.map((i) => i.id), stockId })
|
||||
: of({ result: [] } as ResponseArgsOfIEnumerableOfStockInfoDTO)
|
||||
),
|
||||
timeout(20000),
|
||||
@@ -355,7 +362,7 @@ export class DomainAvailabilityService {
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getPickUpAvailabilities(payload: AvailabilityRequestDTO[], preferred?: boolean) {
|
||||
return this.swaggerAvailabilityService.AvailabilityStoreAvailability(payload).pipe(
|
||||
return this._availabilityService.AvailabilityStoreAvailability(payload).pipe(
|
||||
timeout(20000),
|
||||
map((response) => (preferred ? this._mapToPickUpAvailability(response.result) : response.result))
|
||||
);
|
||||
@@ -363,7 +370,7 @@ export class DomainAvailabilityService {
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getDeliveryAvailabilities(payload: AvailabilityRequestDTO[]) {
|
||||
return this.swaggerAvailabilityService.AvailabilityShippingAvailability(payload).pipe(
|
||||
return this._availabilityService.AvailabilityShippingAvailability(payload).pipe(
|
||||
timeout(20000),
|
||||
map((response) => this._mapToShippingAvailability(response.result))
|
||||
);
|
||||
@@ -371,7 +378,7 @@ export class DomainAvailabilityService {
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getDigDeliveryAvailabilities(payload: AvailabilityRequestDTO[]) {
|
||||
return this.swaggerAvailabilityService.AvailabilityShippingAvailability(payload).pipe(
|
||||
return this._availabilityService.AvailabilityShippingAvailability(payload).pipe(
|
||||
timeout(20000),
|
||||
map((response) => this._mapToShippingAvailability(response.result))
|
||||
);
|
||||
@@ -492,26 +499,29 @@ export class DomainAvailabilityService {
|
||||
return availability;
|
||||
}
|
||||
|
||||
private _mapToPickUpAvailability(availabilities: SwaggerAvailabilityDTO[]) {
|
||||
private _mapToPickUpAvailability(availabilities: SwaggerAvailabilityDTO[]): Availability<AvailabilityDTO, SwaggerAvailabilityDTO>[] {
|
||||
if (isArray(availabilities)) {
|
||||
const preferred = availabilities.filter((f) => f.preferred === 1);
|
||||
const totalAvailable = availabilities.reduce((sum, av) => sum + (av?.qty || 0), 0);
|
||||
|
||||
return preferred.map((p) => {
|
||||
return {
|
||||
availabilityType: p?.status,
|
||||
ssc: p?.ssc,
|
||||
sscText: p?.sscText,
|
||||
supplier: { id: p?.supplierId },
|
||||
isPrebooked: p?.isPrebooked,
|
||||
estimatedShippingDate: p?.requestStatusCode === '32' ? p?.altAt : p?.at,
|
||||
price: p?.price,
|
||||
inStock: totalAvailable,
|
||||
supplierProductNumber: p?.supplierProductNumber,
|
||||
supplierInfo: p?.requestStatusCode,
|
||||
lastRequest: p?.requested,
|
||||
itemId: p.itemId,
|
||||
};
|
||||
return [
|
||||
{
|
||||
availabilityType: p?.status,
|
||||
ssc: p?.ssc,
|
||||
sscText: p?.sscText,
|
||||
supplier: { id: p?.supplierId },
|
||||
isPrebooked: p?.isPrebooked,
|
||||
estimatedShippingDate: p?.requestStatusCode === '32' ? p?.altAt : p?.at,
|
||||
price: p?.price,
|
||||
inStock: totalAvailable,
|
||||
supplierProductNumber: p?.supplierProductNumber,
|
||||
supplierInfo: p?.requestStatusCode,
|
||||
lastRequest: p?.requested,
|
||||
itemId: p.itemId,
|
||||
},
|
||||
p,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
1
apps/domain/availability/src/lib/defs/availability.ts
Normal file
1
apps/domain/availability/src/lib/defs/availability.ts
Normal file
@@ -0,0 +1 @@
|
||||
export type Availability<T, S> = [T, S];
|
||||
@@ -1,3 +1,3 @@
|
||||
// start:ng42.barrel
|
||||
export * from './item-data.model';
|
||||
// end:ng42.barrel
|
||||
export * from './availability-by-branch-dto';
|
||||
export * from './availability';
|
||||
export * from './item-data';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { AvailabilityByBranchDTO } from 'apps/domain/availability/src/lib/defs/availability-by-branch-dto.model';
|
||||
import { AvailabilityByBranchDTO } from '@domain/availability';
|
||||
|
||||
@Pipe({
|
||||
name: 'inStock',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { AvailabilityByBranchDTO } from 'apps/domain/availability/src/lib/defs/availability-by-branch-dto.model';
|
||||
import { AvailabilityByBranchDTO } from '@domain/availability';
|
||||
|
||||
@Pipe({
|
||||
name: 'stockInfo',
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
<div class="availability-icons">
|
||||
<div class="fetching xsmall" *ngIf="store.fetchingTakeAwayAvailability$ | async; else showAvailabilityTakeAwayIcon"></div>
|
||||
<ng-template #showAvailabilityTakeAwayIcon>
|
||||
<ui-icon *ngIf="store.isTakeAwayAvailabilityAvailable$ | async" icon="shopping_bag" size="18px"></ui-icon>
|
||||
<ui-icon *ngIf="store.isTakeAwayAvailabilityAvailable$ | async" icon="shopping_bag" size="18px"> </ui-icon>
|
||||
</ng-template>
|
||||
|
||||
<div class="fetching xsmall" *ngIf="store.fetchingPickUpAvailability$ | async; else showAvailabilityPickUpIcon"></div>
|
||||
@@ -104,7 +104,7 @@
|
||||
*ngIf="store.fetchingDeliveryB2BAvailability$ | async; else showAvailabilityDeliveryB2BIcon"
|
||||
></div>
|
||||
<ng-template #showAvailabilityDeliveryB2BIcon>
|
||||
<ui-icon *ngIf="showDeliveryB2BTruck$ | async" class="truck_b2b" icon="truck_b2b" size="40px"></ui-icon>
|
||||
<ui-icon *ngIf="showDeliveryB2BTruck$ | async" class="truck_b2b" icon="truck_b2b" size="40px"> </ui-icon>
|
||||
</ng-template>
|
||||
|
||||
<span *ngIf="store.isDownload$ | async" class="download-icon">
|
||||
|
||||
@@ -6,6 +6,7 @@ import { DomainAvailabilityService, ItemData } from '@domain/availability';
|
||||
import { DomainCatalogService } from '@domain/catalog';
|
||||
import { ComponentStore, tapResponse } from '@ngrx/component-store';
|
||||
import { ItemDTO, ResponseArgsOfItemDTO } from '@swagger/cat';
|
||||
import { AvailabilityDTO } from '@swagger/checkout';
|
||||
import { UiErrorModalComponent, UiModalService } from '@ui/modal';
|
||||
import { combineLatest, Observable, of } from 'rxjs';
|
||||
import { catchError, filter, first, map, shareReplay, switchMap, tap } from 'rxjs/operators';
|
||||
@@ -113,11 +114,22 @@ export class ArticleDetailsStore extends ComponentStore<ArticleDetailsState> {
|
||||
|
||||
//#region Abholung
|
||||
readonly fetchingPickUpAvailability$ = this.select((s) => s.fetchingPickUpAvailability);
|
||||
readonly pickUpAvailability$ = combineLatest([this.itemData$, this.branch$, this.isDownload$]).pipe(
|
||||
readonly pickUpAvailability$: Observable<AvailabilityDTO> = combineLatest([this.itemData$, this.branch$, this.isDownload$]).pipe(
|
||||
tap(() => this.patchState({ fetchingPickUpAvailability: true, fetchingPickUpAvailabilityError: undefined })),
|
||||
switchMap(([item, branch, isDownload]) =>
|
||||
!!item && !!branch && !isDownload
|
||||
? this.domainAvailabilityService.getPickUpAvailability({ item, branch, quantity: 1 }).pipe(
|
||||
map((av) => {
|
||||
if (av[1].availableFor) {
|
||||
if ((av[1].availableFor & 2) === 2) {
|
||||
return av[0];
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
return av[0];
|
||||
}
|
||||
}),
|
||||
catchError((err) => {
|
||||
console.error('getPickUpAvailability failed.', err);
|
||||
this.patchState({ fetchingPickUpAvailabilityError: 'Fehler beim laden der Abholung.' });
|
||||
@@ -235,11 +247,16 @@ export class ArticleDetailsStore extends ComponentStore<ArticleDetailsState> {
|
||||
]).pipe(
|
||||
map(([item, isDownload, pickupAvailability, deliveryDigAvailability, downloadAvailability]) => {
|
||||
const availability = isDownload ? downloadAvailability : pickupAvailability || deliveryDigAvailability;
|
||||
return item?.catalogAvailability?.supplier === 'S' && !isDownload
|
||||
? `${item?.catalogAvailability?.ssc} - ${item?.catalogAvailability?.sscText}`
|
||||
: availability?.ssc || availability?.sscText
|
||||
? `${availability?.ssc} - ${availability?.sscText}`
|
||||
: 'Keine Lieferanten vorhanden';
|
||||
|
||||
if (item?.catalogAvailability?.supplier === 'S' && !isDownload) {
|
||||
return [item?.catalogAvailability?.ssc, item?.catalogAvailability?.sscText].filter((f) => !!f).join(' - ');
|
||||
}
|
||||
|
||||
if (availability?.ssc || availability?.sscText) {
|
||||
return [availability?.ssc, availability?.sscText].filter((f) => !!f).join(' - ');
|
||||
}
|
||||
|
||||
return 'Keine Lieferanten vorhanden';
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -251,6 +251,7 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy {
|
||||
catalogProductNumber: String(item?.id),
|
||||
...item?.product,
|
||||
},
|
||||
itemType: item.type,
|
||||
promotion: { points: item?.promoPoints },
|
||||
};
|
||||
|
||||
|
||||
@@ -305,6 +305,7 @@ export class CheckoutDummyStore extends ComponentStore<CheckoutDummyState> {
|
||||
destination: {
|
||||
data: { target: 1, targetBranch: { id: branch.id } },
|
||||
},
|
||||
itemType: this.item.type,
|
||||
};
|
||||
|
||||
if (update) {
|
||||
|
||||
@@ -526,9 +526,17 @@ export class CheckoutReviewComponent extends ComponentStore<CheckoutReviewCompon
|
||||
availabilities['download'] = downloadAvailability;
|
||||
}
|
||||
|
||||
if (pickupAvailability && this.availabilityService.isAvailable({ availability: pickupAvailability })) {
|
||||
availableOptions.push('pick-up');
|
||||
availabilities['pick-up'] = pickupAvailability;
|
||||
if (pickupAvailability && this.availabilityService.isAvailable({ availability: pickupAvailability[0] })) {
|
||||
if (pickupAvailability[1].availableFor) {
|
||||
if ((pickupAvailability[1].availableFor & 2) === 2) {
|
||||
availableOptions.push('pick-up');
|
||||
availabilities['pick-up'] = pickupAvailability[0];
|
||||
}
|
||||
} else {
|
||||
availableOptions.push('pick-up');
|
||||
availabilities['pick-up'] = pickupAvailability[0];
|
||||
}
|
||||
|
||||
if (!customerFeatures?.webshop && this.availabilityService.isAvailable({ availability: b2bAvailability })) {
|
||||
availableOptions.push('b2b-delivery');
|
||||
availabilities['b2b-delivery'] = b2bAvailability;
|
||||
@@ -648,6 +656,7 @@ export class CheckoutReviewComponent extends ComponentStore<CheckoutReviewCompon
|
||||
},
|
||||
quantity,
|
||||
})
|
||||
.pipe(map((av) => av[0]))
|
||||
.toPromise();
|
||||
break;
|
||||
case 'Versand':
|
||||
|
||||
@@ -45,7 +45,8 @@
|
||||
<div class="item-date" *ngIf="orderType === 'Abholung'">Abholung ab {{ item?.availability?.estimatedShippingDate | date }}</div>
|
||||
<div class="item-date" *ngIf="orderType === 'Versand' || orderType === 'B2B-Versand' || orderType === 'DIG-Versand'">
|
||||
<ng-container *ngIf="item?.availability?.estimatedDelivery; else estimatedShippingDate">
|
||||
Zustellung zwischen {{ (item?.availability?.estimatedDelivery?.start | date: 'EEE, dd.MM.')?.replace('.', '') }} und
|
||||
Zustellung zwischen {{ (item?.availability?.estimatedDelivery?.start | date: 'EEE, dd.MM.')?.replace('.', '') }}
|
||||
und
|
||||
{{ (item?.availability?.estimatedDelivery?.stop | date: 'EEE, dd.MM.')?.replace('.', '') }}
|
||||
</ng-container>
|
||||
<ng-template #estimatedShippingDate> Versand {{ item?.availability?.estimatedShippingDate | date }} </ng-template>
|
||||
@@ -90,7 +91,7 @@
|
||||
<button
|
||||
[disabled]="(loadingOnQuantityChangeById$ | async) === item?.id || (loadingOnItemChangeById$ | async) === item?.id"
|
||||
(click)="onChangeItem()"
|
||||
*ngIf="(isDummy$ | async) || (hasOrderType$ | async)"
|
||||
*ngIf="canEdit$ | async"
|
||||
>
|
||||
<ui-spinner [show]="(loadingOnItemChangeById$ | async) === item?.id">
|
||||
Ändern
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ApplicationService } from '@core/application';
|
||||
import { DomainAvailabilityService } from '@domain/availability';
|
||||
import { DomainCheckoutService } from '@domain/checkout';
|
||||
import { ComponentStore } from '@ngrx/component-store';
|
||||
import { ShoppingCartItemDTO } from '@swagger/checkout';
|
||||
import { ItemType, ShoppingCartItemDTO } from '@swagger/checkout';
|
||||
import { combineLatest } from 'rxjs';
|
||||
import { filter, first, map, shareReplay, switchMap } from 'rxjs/operators';
|
||||
|
||||
@@ -83,6 +83,15 @@ export class ShoppingCartItemComponent extends ComponentStore<ShoppingCartItemCo
|
||||
shareReplay()
|
||||
);
|
||||
|
||||
canEdit$ = combineLatest([this.isDummy$, this.hasOrderType$, this.item$]).pipe(
|
||||
map(([isDummy, hasOrderType, item]) => {
|
||||
if (item.itemType === (66560 as ItemType)) {
|
||||
return false;
|
||||
}
|
||||
return isDummy || hasOrderType;
|
||||
})
|
||||
);
|
||||
|
||||
quantityRange$ = combineLatest([this.orderType$, this.item$]).pipe(
|
||||
map(([orderType, item]) => (orderType === 'Rücklage' ? item.availability?.inStock : 999))
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<form *ngIf="control" [formGroup]="control">
|
||||
<ui-form-control label="MwSt" variant="default">
|
||||
<ui-form-control label="MwSt" variant="default" *ngIf="!hideVat">
|
||||
<ui-select formControlName="vat">
|
||||
<ui-select-option *ngFor="let vat of vats$ | async" [label]="vat.name + '%'" [value]="vat.vatType"></ui-select-option>
|
||||
<ui-select-option *ngFor="let vat of vats$ | async" [label]="vat.name + '%'" [value]="vat.vatType"> </ui-select-option>
|
||||
</ui-select>
|
||||
</ui-form-control>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, OnInit, Output } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { DomainOmsService } from '@domain/oms';
|
||||
import { VATDTO } from '@swagger/oms';
|
||||
@@ -25,6 +25,9 @@ export class PurchasingOptionsModalPriceInputComponent implements OnInit {
|
||||
|
||||
private _subscriptions = new Subscription();
|
||||
|
||||
@Input()
|
||||
hideVat = false;
|
||||
|
||||
constructor(private _omsService: DomainOmsService, private _fb: FormBuilder) {}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -35,7 +38,7 @@ export class PurchasingOptionsModalPriceInputComponent implements OnInit {
|
||||
const fb = this._fb;
|
||||
this.control = fb.group({
|
||||
price: fb.control(undefined, [Validators.required, Validators.pattern(/^\d+([\,]\d{1,2})?$/), Validators.max(99999)]),
|
||||
vat: fb.control(undefined, [Validators.required]),
|
||||
vat: fb.control(0, [Validators.required]),
|
||||
});
|
||||
|
||||
this._subscriptions.add(
|
||||
|
||||
@@ -83,9 +83,11 @@
|
||||
</div>
|
||||
<div class="custom-price" *ngIf="showCustomPrice$ | async">
|
||||
<page-purchasing-options-modal-price-input
|
||||
[hideVat]="item.type === 66560"
|
||||
(priceChanged)="changeCustomPrice($event)"
|
||||
(vatChanged)="changeCustomVat($event)"
|
||||
></page-purchasing-options-modal-price-input>
|
||||
>
|
||||
</page-purchasing-options-modal-price-input>
|
||||
</div>
|
||||
<hr />
|
||||
<div class="summary-row" *ngIf="quantity$ | async; let quantity">
|
||||
|
||||
@@ -55,10 +55,23 @@ export class PurchasingOptionsModalComponent {
|
||||
);
|
||||
|
||||
readonly customPriceInvalid$ = combineLatest([
|
||||
this.item$,
|
||||
this.showCustomPrice$,
|
||||
this.purchasingOptionsModalStore.selectCustomPrice,
|
||||
this.purchasingOptionsModalStore.selectCustomVat,
|
||||
]).pipe(map(([showCustomPrice, customPrice, customVat]) => showCustomPrice && (!customPrice || !customVat)));
|
||||
]).pipe(
|
||||
map(([item, showCustomPrice, customPrice, customVat]) => {
|
||||
if (!showCustomPrice) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((item.type as any) === 66560) {
|
||||
return !customPrice;
|
||||
}
|
||||
|
||||
return !customPrice || !customVat;
|
||||
})
|
||||
);
|
||||
|
||||
readonly showTakeAwayButton$ = combineLatest([
|
||||
this.option$,
|
||||
@@ -238,7 +251,7 @@ export class PurchasingOptionsModalComponent {
|
||||
const shoppingCartItem = await this.purchasingOptionsModalStore.selectShoppingCartItem.pipe(first()).toPromise();
|
||||
const canAdd = await this.canAdd$.pipe(first()).toPromise();
|
||||
const customPrice = await this.purchasingOptionsModalStore.selectCustomPrice.pipe(first()).toPromise();
|
||||
const customVat = await this.purchasingOptionsModalStore.selectCustomVat.pipe(first()).toPromise();
|
||||
const customVat = (await this.purchasingOptionsModalStore.selectCustomVat.pipe(first()).toPromise()) ?? 0;
|
||||
const customer = await this.checkoutService.getCustomer({ processId }).pipe(first()).toPromise();
|
||||
|
||||
if (canAdd || navigate === 'add-customer-data') {
|
||||
@@ -250,6 +263,7 @@ export class PurchasingOptionsModalComponent {
|
||||
...item.product,
|
||||
},
|
||||
promotion: { points: item.promoPoints },
|
||||
itemType: item.type,
|
||||
};
|
||||
|
||||
newItem.product.catalogProductNumber = String(item.id);
|
||||
|
||||
@@ -376,11 +376,25 @@ export class PurchasingOptionsModalStore extends ComponentStore<PurchasingOption
|
||||
break;
|
||||
case 'pick-up':
|
||||
if (!isNullOrUndefined(branch)) {
|
||||
availability$ = this.availabilityService.getPickUpAvailability({
|
||||
item: { itemId: item.id, ean: item.product.ean, price: item.catalogAvailability.price },
|
||||
quantity,
|
||||
branch,
|
||||
});
|
||||
availability$ = this.availabilityService
|
||||
.getPickUpAvailability({
|
||||
item: { itemId: item.id, ean: item.product.ean, price: item.catalogAvailability.price },
|
||||
quantity,
|
||||
branch,
|
||||
})
|
||||
.pipe(
|
||||
map((av) => {
|
||||
if (av[1].availableFor) {
|
||||
if ((av[1].availableFor & 2) === 2) {
|
||||
return av[0];
|
||||
} else {
|
||||
undefined;
|
||||
}
|
||||
} else {
|
||||
return av[0];
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'delivery':
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
/* tslint:disable */
|
||||
import { AvailabilityDTO } from './availability-dto';
|
||||
import { EntityDTOContainerOfDestinationDTO } from './entity-dtocontainer-of-destination-dto';
|
||||
import { ItemType } from './item-type';
|
||||
import { ProductDTO } from './product-dto';
|
||||
import { PromotionDTO } from './promotion-dto';
|
||||
import { Price } from './price';
|
||||
export interface AddToShoppingCartDTO {
|
||||
availability?: AvailabilityDTO;
|
||||
destination?: EntityDTOContainerOfDestinationDTO;
|
||||
itemType?: ItemType;
|
||||
product?: ProductDTO;
|
||||
promotion?: PromotionDTO;
|
||||
quantity: number;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
/* tslint:disable */
|
||||
export type ItemType = 0 | 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096 | 8192 | 16384 | 32768;
|
||||
export type ItemType = 0 | 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096 | 8192 | 16384 | 32768 | 65536;
|
||||
@@ -4,6 +4,7 @@ import { EntityDTOContainerOfShoppingCartItemDTO } from './entity-dtocontainer-o
|
||||
import { AvailabilityDTO } from './availability-dto';
|
||||
import { UrlDTO } from './url-dto';
|
||||
import { EntityDTOContainerOfDestinationDTO } from './entity-dtocontainer-of-destination-dto';
|
||||
import { ItemType } from './item-type';
|
||||
import { OrderItemType } from './order-item-type';
|
||||
import { ProductDTO } from './product-dto';
|
||||
import { PromotionDTO } from './promotion-dto';
|
||||
@@ -22,6 +23,7 @@ export interface ShoppingCartItemDTO extends EntityDTOBaseOfShoppingCartItemDTOA
|
||||
destination?: EntityDTOContainerOfDestinationDTO;
|
||||
estimatedShippingDate?: string;
|
||||
features?: {[key: string]: string};
|
||||
itemType?: ItemType;
|
||||
lastAvailabilityRequest?: string;
|
||||
orderItemType?: OrderItemType;
|
||||
parent?: EntityDTOContainerOfShoppingCartItemDTO;
|
||||
|
||||
Reference in New Issue
Block a user