|
|
@@ -22,7 +22,8 @@ import {
|
|
|
ServerConfigService,
|
|
|
SortOrder,
|
|
|
} from '@vendure/admin-ui/core';
|
|
|
-import { summate } from '@vendure/common/lib/shared-utils';
|
|
|
+import { pick } from '@vendure/common/lib/pick';
|
|
|
+import { assertNever, summate } from '@vendure/common/lib/shared-utils';
|
|
|
import { EMPTY, merge, Observable, of, Subject } from 'rxjs';
|
|
|
import { map, mapTo, startWith, switchMap, take } from 'rxjs/operators';
|
|
|
|
|
|
@@ -205,6 +206,25 @@ export class OrderDetailComponent
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ transitionPaymentState({ payment, state }: { payment: OrderDetail.Payments; state: string }) {
|
|
|
+ this.dataService.order
|
|
|
+ .transitionPaymentToState(payment.id, state)
|
|
|
+ .subscribe(({ transitionPaymentToState }) => {
|
|
|
+ switch (transitionPaymentToState.__typename) {
|
|
|
+ case 'Payment':
|
|
|
+ this.notificationService.success(_('order.transitioned-payment-to-state-success'), {
|
|
|
+ state,
|
|
|
+ });
|
|
|
+ this.dataService.order.getOrder(this.id).single$.subscribe();
|
|
|
+ this.fetchHistory.next();
|
|
|
+ break;
|
|
|
+ case 'PaymentStateTransitionError':
|
|
|
+ this.notificationService.error(transitionPaymentToState.message);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
canAddFulfillment(order: OrderDetail.Fragment): boolean {
|
|
|
const allItemsFulfilled = order.lines
|
|
|
.reduce((items, line) => [...items, ...line.items], [] as OrderLineFragment['items'])
|
|
|
@@ -212,6 +232,7 @@ export class OrderDetailComponent
|
|
|
return (
|
|
|
!allItemsFulfilled &&
|
|
|
!this.hasUnsettledModifications(order) &&
|
|
|
+ this.outstandingPaymentAmount(order) === 0 &&
|
|
|
(order.nextStates.includes('Shipped') ||
|
|
|
order.nextStates.includes('PartiallyShipped') ||
|
|
|
order.nextStates.includes('Delivered'))
|
|
|
@@ -229,12 +250,20 @@ export class OrderDetailComponent
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ outstandingPaymentAmount(order: OrderDetailFragment): number {
|
|
|
+ const paymentIsValid = (p: OrderDetail.Payments): boolean =>
|
|
|
+ p.state !== 'Cancelled' && p.state !== 'Declined' && p.state !== 'Error';
|
|
|
+ const validPayments = order.payments?.filter(paymentIsValid).map(p => pick(p, ['amount'])) ?? [];
|
|
|
+ const amountCovered = summate(validPayments, 'amount');
|
|
|
+ return order.totalWithTax - amountCovered;
|
|
|
+ }
|
|
|
+
|
|
|
addManualPayment(order: OrderDetailFragment) {
|
|
|
this.modalService
|
|
|
.fromComponent(AddManualPaymentDialogComponent, {
|
|
|
closable: true,
|
|
|
locals: {
|
|
|
- outstandingAmount: this.getOutstandingModificationAmount(order),
|
|
|
+ outstandingAmount: this.outstandingPaymentAmount(order),
|
|
|
currencyCode: order.currencyCode,
|
|
|
},
|
|
|
})
|