diff --git a/packages/core/graphql/src/lib/documents/ordering/create-order-invoice.gql b/packages/core/graphql/src/lib/documents/ordering/create-order-invoice.gql new file mode 100644 index 00000000..9420b856 --- /dev/null +++ b/packages/core/graphql/src/lib/documents/ordering/create-order-invoice.gql @@ -0,0 +1,19 @@ +mutation OrderingInvoiceCreate( + $input: IIoRestorecommerceOrderOrderingInvoiceRequestList! +) { + ordering { + order { + CreateInvoice(input: $input) { + details { + items { + payload { + id + invoiceNumber + paymentState + } + } + } + } + } + } +} diff --git a/packages/core/state/src/lib/+state/order/order.actions.ts b/packages/core/state/src/lib/+state/order/order.actions.ts index 03c2f35c..73dd4efb 100644 --- a/packages/core/state/src/lib/+state/order/order.actions.ts +++ b/packages/core/state/src/lib/+state/order/order.actions.ts @@ -85,3 +85,8 @@ export const orderRemoveFail = createAction( '[ORDER] Order remove fail', props<{ error: string }>() ); + +export const orderCreateInvoiceRequest = createAction( + '[ORDER] Create an invoice request', + props<{ payload: string }>() +); diff --git a/packages/core/state/src/lib/+state/order/order.facade.ts b/packages/core/state/src/lib/+state/order/order.facade.ts index 17f13b3e..f0697eed 100644 --- a/packages/core/state/src/lib/+state/order/order.facade.ts +++ b/packages/core/state/src/lib/+state/order/order.facade.ts @@ -37,5 +37,12 @@ export class OrderFacade { remove = (payload: { id: string }) => this.store.dispatch(orderActions.orderRemoveRequest({ payload })); + createOrderInvoice = (payload: string) => + this.store.dispatch( + orderActions.orderCreateInvoiceRequest({ + payload, + }) + ); + constructor(private readonly store: Store) {} } diff --git a/packages/core/state/src/lib/services/ordering/order.service.ts b/packages/core/state/src/lib/services/ordering/order.service.ts index 888c19c3..a741e8ac 100644 --- a/packages/core/state/src/lib/services/ordering/order.service.ts +++ b/packages/core/state/src/lib/services/ordering/order.service.ts @@ -7,6 +7,9 @@ import { IIoRestorecommerceOrderOrderList, IIoRestorecommerceResourcebaseDeleteRequest, IIoRestorecommerceResourcebaseReadRequest, + OrderingInvoiceCreateGQL, + OrderingInvoiceCreateMutation, + IIoRestorecommerceOrderOrderingInvoiceRequestList, OrderingOrderDeleteMutateGQL, OrderingOrderDeleteMutateMutation, OrderingOrderMutateGQL, @@ -22,7 +25,8 @@ export class OrderService { constructor( private readonly orderingOrderReadGQL: OrderingOrderReadGQL, private readonly orderingOrderMutateGQL: OrderingOrderMutateGQL, - private readonly orderingOrderDeleteMutateGQL: OrderingOrderDeleteMutateGQL + private readonly orderingOrderDeleteMutateGQL: OrderingOrderDeleteMutateGQL, + private readonly orderingInvoiceCreateGQL: OrderingInvoiceCreateGQL ) {} read( @@ -48,4 +52,24 @@ export class OrderService { input: payload, }); } + + createOrderInvoice( + payload: string + ): Observable> { + const orderInvoiceInput: IIoRestorecommerceOrderOrderingInvoiceRequestList = + {}; + orderInvoiceInput.items = [ + { + sections: [ + { + orderId: payload, + }, + ], + }, + ]; + + return this.orderingInvoiceCreateGQL.mutate({ + input: orderInvoiceInput, + }); + } } diff --git a/packages/modules/order/src/lib/components/template/order-template.component.ts b/packages/modules/order/src/lib/components/template/order-template.component.ts index 37566578..98dcb2bf 100644 --- a/packages/modules/order/src/lib/components/template/order-template.component.ts +++ b/packages/modules/order/src/lib/components/template/order-template.component.ts @@ -105,6 +105,10 @@ export class OrderTemplateComponent implements OnInit, OnDestroy { '[Log] ~ file: order-template.component.ts:107 ~ OrderTemplateComponent ~ tap ~ console: triggerCreateInvoice --->', id ); + + console.log('*** Action for creating an invoice for this', id); + + this.orderFacade.createOrderInvoice(id); }) );