@deenruv/wfirma-plugin 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +45 -0
- package/dist/plugin-server/api/wfirma-admin.resolver.d.ts +13 -0
- package/dist/plugin-server/api/wfirma-admin.resolver.js +40 -0
- package/dist/plugin-server/constants.d.ts +12 -0
- package/dist/plugin-server/constants.js +31 -0
- package/dist/plugin-server/extensions/wfirma.extension.d.ts +1 -0
- package/dist/plugin-server/extensions/wfirma.extension.js +19 -0
- package/dist/plugin-server/helpers/fetch-wfirma-api.d.ts +3 -0
- package/dist/plugin-server/helpers/fetch-wfirma-api.js +75 -0
- package/dist/plugin-server/helpers/types.d.ts +349 -0
- package/dist/plugin-server/helpers/types.js +2 -0
- package/dist/plugin-server/index.d.ts +7 -0
- package/dist/plugin-server/index.js +56 -0
- package/dist/plugin-server/services/wfirma.service.d.ts +15 -0
- package/dist/plugin-server/services/wfirma.service.js +246 -0
- package/dist/plugin-server/types.d.ts +7 -0
- package/dist/plugin-server/types.js +2 -0
- package/dist/plugin-server/ui/components/ProformaInvoiceActionButton.ts +48 -0
- package/dist/plugin-server/ui/components/RecipeInvoiceActionButton.ts +48 -0
- package/dist/plugin-server/ui/graphql/mutations.ts +14 -0
- package/dist/plugin-server/ui/graphql/queries.ts +7 -0
- package/dist/plugin-server/ui/graphql/scalars.ts +15 -0
- package/dist/plugin-server/ui/graphql/selectors.ts +0 -0
- package/dist/plugin-server/ui/providers.ts +13 -0
- package/dist/plugin-server/ui/routes.ts +1 -0
- package/dist/plugin-server/ui/styles/overwrite.css +0 -0
- package/dist/plugin-server/ui/zeus/const.ts +4767 -0
- package/dist/plugin-server/ui/zeus/index.ts +21694 -0
- package/dist/plugin-server/ui/zeus/typedDocumentNode.ts +27 -0
- package/dist/plugin-server/zeus/const.d.ts +6 -0
- package/dist/plugin-server/zeus/const.js +3698 -0
- package/dist/plugin-server/zeus/index.d.ts +18878 -0
- package/dist/plugin-server/zeus/index.js +1094 -0
- package/dist/plugin-server/zeus/typedDocumentNode.d.ts +3 -0
- package/dist/plugin-server/zeus/typedDocumentNode.js +13 -0
- package/dist/plugin-ui/components/WFirmaButtons.d.ts +2 -0
- package/dist/plugin-ui/components/WFirmaButtons.js +66 -0
- package/dist/plugin-ui/graphql/mutations.d.ts +10 -0
- package/dist/plugin-ui/graphql/mutations.js +10 -0
- package/dist/plugin-ui/graphql/queries.d.ts +1 -0
- package/dist/plugin-ui/graphql/queries.js +4 -0
- package/dist/plugin-ui/graphql/scalars.d.ts +13 -0
- package/dist/plugin-ui/graphql/scalars.js +14 -0
- package/dist/plugin-ui/graphql/selectors.d.ts +0 -0
- package/dist/plugin-ui/graphql/selectors.js +1 -0
- package/dist/plugin-ui/index.d.ts +1 -0
- package/dist/plugin-ui/index.js +14 -0
- package/dist/plugin-ui/locales/en/index.d.ts +5 -0
- package/dist/plugin-ui/locales/en/index.js +2 -0
- package/dist/plugin-ui/locales/en/wfirma.json +4 -0
- package/dist/plugin-ui/locales/pl/index.d.ts +5 -0
- package/dist/plugin-ui/locales/pl/index.js +2 -0
- package/dist/plugin-ui/locales/pl/wfirma.json +4 -0
- package/dist/plugin-ui/translation-ns.d.ts +1 -0
- package/dist/plugin-ui/translation-ns.js +1 -0
- package/dist/plugin-ui/tsconfig.json +18 -0
- package/dist/plugin-ui/zeus/const.d.ts +6 -0
- package/dist/plugin-ui/zeus/const.js +3695 -0
- package/dist/plugin-ui/zeus/index.d.ts +18878 -0
- package/dist/plugin-ui/zeus/index.js +1086 -0
- package/dist/plugin-ui/zeus/typedDocumentNode.d.ts +3 -0
- package/dist/plugin-ui/zeus/typedDocumentNode.js +9 -0
- package/package.json +52 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RequestContext, OrderService, ShippingMethodService } from "@deenruv/core";
|
|
2
|
+
import { WFirmaPluginConfig } from "../types";
|
|
3
|
+
import { GraphQLTypes, ResolverInputTypes } from "../zeus";
|
|
4
|
+
export declare class WFirmaService {
|
|
5
|
+
private orderService;
|
|
6
|
+
private shippingMethodService;
|
|
7
|
+
private plugin_config;
|
|
8
|
+
constructor(orderService: OrderService, shippingMethodService: ShippingMethodService, plugin_config: WFirmaPluginConfig);
|
|
9
|
+
private client;
|
|
10
|
+
createInvoice(ctx: RequestContext, input: ResolverInputTypes["SendInvoiceToWFirmaInput"]): Promise<GraphQLTypes["WFirmaResponse"] | null>;
|
|
11
|
+
private saveInvoiceDataOnOrder;
|
|
12
|
+
private findContractor;
|
|
13
|
+
private addContractor;
|
|
14
|
+
private getOrderDataForInvoice;
|
|
15
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.WFirmaService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const core_1 = require("@deenruv/core");
|
|
18
|
+
const fetch_wfirma_api_1 = require("../helpers/fetch-wfirma-api");
|
|
19
|
+
const constants_1 = require("../constants");
|
|
20
|
+
let WFirmaService = class WFirmaService {
|
|
21
|
+
constructor(orderService, shippingMethodService, plugin_config) {
|
|
22
|
+
var _a;
|
|
23
|
+
this.orderService = orderService;
|
|
24
|
+
this.shippingMethodService = shippingMethodService;
|
|
25
|
+
this.plugin_config = plugin_config;
|
|
26
|
+
this.client = ((_a = this.plugin_config) === null || _a === void 0 ? void 0 : _a.authorization)
|
|
27
|
+
? (0, fetch_wfirma_api_1.fetchWFirmaAPI)(this.plugin_config.authorization)
|
|
28
|
+
: null;
|
|
29
|
+
}
|
|
30
|
+
async createInvoice(ctx, input) {
|
|
31
|
+
var _a, _b, _c, _d, _e, _f;
|
|
32
|
+
const { orderID, invoiceType } = input;
|
|
33
|
+
if (!this.client) {
|
|
34
|
+
console.error("WFirma authorization is not set");
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const orderData = await this.getOrderDataForInvoice(ctx, orderID);
|
|
38
|
+
if (!orderData)
|
|
39
|
+
return null;
|
|
40
|
+
let contractorID = null;
|
|
41
|
+
contractorID = orderData.contractor.email
|
|
42
|
+
? await this.findContractor(orderData.contractor.email, (_a = orderData.contractor.street) !== null && _a !== void 0 ? _a : "")
|
|
43
|
+
: null;
|
|
44
|
+
if (!contractorID) {
|
|
45
|
+
contractorID = await this.addContractor(orderData.contractor);
|
|
46
|
+
}
|
|
47
|
+
if (!contractorID)
|
|
48
|
+
return null;
|
|
49
|
+
const addInvoiceInput = {
|
|
50
|
+
invoices: [
|
|
51
|
+
{
|
|
52
|
+
invoice: {
|
|
53
|
+
type: invoiceType,
|
|
54
|
+
type_of_sale: "WSTO_EE",
|
|
55
|
+
contractor: { id: contractorID },
|
|
56
|
+
invoicecontents: orderData.invoicecontents,
|
|
57
|
+
price_type: invoiceType === "proforma" ? "brutto" : "netto",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
const addInvoiceResponse = await this.client("add-invoice", addInvoiceInput);
|
|
63
|
+
if (!((_d = (_c = (_b = addInvoiceResponse === null || addInvoiceResponse === void 0 ? void 0 : addInvoiceResponse.invoices) === null || _b === void 0 ? void 0 : _b["0"]) === null || _c === void 0 ? void 0 : _c.invoice) === null || _d === void 0 ? void 0 : _d.id))
|
|
64
|
+
return null;
|
|
65
|
+
const saveResponse = await this.saveInvoiceDataOnOrder(ctx, orderID, input, (_f = (_e = addInvoiceResponse === null || addInvoiceResponse === void 0 ? void 0 : addInvoiceResponse.invoices) === null || _e === void 0 ? void 0 : _e["0"]) === null || _f === void 0 ? void 0 : _f.invoice);
|
|
66
|
+
return saveResponse ? { __typename: "WFirmaResponse", url: "" } : null;
|
|
67
|
+
}
|
|
68
|
+
async saveInvoiceDataOnOrder(ctx, orderID, input, invoiceData) {
|
|
69
|
+
const response = await this.orderService.updateCustomFields(ctx, orderID, {
|
|
70
|
+
wfirmaInvoiceId: invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.id,
|
|
71
|
+
});
|
|
72
|
+
if (invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.fullnumber) {
|
|
73
|
+
await this.orderService.addNoteToOrder(ctx, {
|
|
74
|
+
id: orderID,
|
|
75
|
+
note: `[WFirma] Typ faktury: ${input.invoiceType}, numer faktury: ${invoiceData.fullnumber}`,
|
|
76
|
+
isPublic: false,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return response;
|
|
80
|
+
}
|
|
81
|
+
async findContractor(email, street) {
|
|
82
|
+
var _a, _b, _c;
|
|
83
|
+
if (this.client === null) {
|
|
84
|
+
console.error("WFirma authorization is not set");
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const contractorRequestInput = {
|
|
88
|
+
contractors: {
|
|
89
|
+
parameters: {
|
|
90
|
+
limit: 5,
|
|
91
|
+
page: 1,
|
|
92
|
+
fields: [{ field: "id" }, { field: "email" }],
|
|
93
|
+
conditions: [
|
|
94
|
+
{
|
|
95
|
+
condition: {
|
|
96
|
+
field: "email",
|
|
97
|
+
operator: "eq",
|
|
98
|
+
value: email,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
condition: {
|
|
103
|
+
field: "street",
|
|
104
|
+
operator: "eq",
|
|
105
|
+
value: street,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
const response = await this.client("find-contractor", contractorRequestInput);
|
|
113
|
+
return (_c = (_b = (_a = response === null || response === void 0 ? void 0 : response.contractors) === null || _a === void 0 ? void 0 : _a["0"]) === null || _b === void 0 ? void 0 : _b.contractor) === null || _c === void 0 ? void 0 : _c.id;
|
|
114
|
+
}
|
|
115
|
+
async addContractor(contractor) {
|
|
116
|
+
var _a, _b, _c;
|
|
117
|
+
if (this.client === null) {
|
|
118
|
+
console.error("WFirma authorization is not set");
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const addContractorInput = {
|
|
122
|
+
contractors: [
|
|
123
|
+
{
|
|
124
|
+
contractor: contractor,
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
};
|
|
128
|
+
const response = await this.client("add-contractor", addContractorInput);
|
|
129
|
+
return (_c = (_b = (_a = response === null || response === void 0 ? void 0 : response.contractors) === null || _a === void 0 ? void 0 : _a["0"]) === null || _b === void 0 ? void 0 : _b.contractor) === null || _c === void 0 ? void 0 : _c.id;
|
|
130
|
+
}
|
|
131
|
+
async getOrderDataForInvoice(ctx, orderID) {
|
|
132
|
+
var _a, _b, _c, _d, _e;
|
|
133
|
+
try {
|
|
134
|
+
const order = await this.orderService.findOne(ctx, orderID, [
|
|
135
|
+
"customer",
|
|
136
|
+
"lines",
|
|
137
|
+
"lines.productVariant",
|
|
138
|
+
"shippingLines",
|
|
139
|
+
"shippingLines.shippingMethod",
|
|
140
|
+
"customer.addresses",
|
|
141
|
+
"sellerOrders.customer",
|
|
142
|
+
]);
|
|
143
|
+
if (!order)
|
|
144
|
+
throw new Error("Order not found");
|
|
145
|
+
if (!order.customer)
|
|
146
|
+
throw new Error("Order has no customer");
|
|
147
|
+
if (!order.shippingAddress ||
|
|
148
|
+
!order.shippingAddress.city ||
|
|
149
|
+
!order.shippingAddress.postalCode) {
|
|
150
|
+
throw new Error("Order has no shipping address");
|
|
151
|
+
}
|
|
152
|
+
let nip = null;
|
|
153
|
+
let companyName = null;
|
|
154
|
+
const orderBillingAddress = order.billingAddress;
|
|
155
|
+
const orderBillingAddressCustomFields = orderBillingAddress === null || orderBillingAddress === void 0 ? void 0 : orderBillingAddress.customFields;
|
|
156
|
+
if (orderBillingAddressCustomFields) {
|
|
157
|
+
nip = orderBillingAddressCustomFields === null || orderBillingAddressCustomFields === void 0 ? void 0 : orderBillingAddressCustomFields.companyTaxId;
|
|
158
|
+
companyName = orderBillingAddressCustomFields === null || orderBillingAddressCustomFields === void 0 ? void 0 : orderBillingAddressCustomFields.companyName;
|
|
159
|
+
}
|
|
160
|
+
if (!nip) {
|
|
161
|
+
const customAddressData = (_a = order.customer.addresses.find((address) => address.streetLine1 === (orderBillingAddress === null || orderBillingAddress === void 0 ? void 0 : orderBillingAddress.streetLine1))) === null || _a === void 0 ? void 0 : _a.customFields;
|
|
162
|
+
if (customAddressData) {
|
|
163
|
+
nip = customAddressData === null || customAddressData === void 0 ? void 0 : customAddressData.companyTaxId;
|
|
164
|
+
companyName = customAddressData === null || customAddressData === void 0 ? void 0 : customAddressData.companyName;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const contractor = Object.assign({ name: companyName
|
|
168
|
+
? companyName
|
|
169
|
+
: order.customer.firstName + " " + order.customer.lastName, street: ((_c = (_b = order.billingAddress) === null || _b === void 0 ? void 0 : _b.streetLine1) !== null && _c !== void 0 ? _c : "") +
|
|
170
|
+
" " +
|
|
171
|
+
((_e = (_d = order.billingAddress) === null || _d === void 0 ? void 0 : _d.streetLine2) !== null && _e !== void 0 ? _e : ""), city: order.billingAddress.city, zip: order.billingAddress.postalCode, phone: order.customer.phoneNumber, email: order.customer.emailAddress }, (nip ? { tax_id_type: "nip", nip } : {}));
|
|
172
|
+
const totalProductsQuantity = order.lines.reduce((acc, line) => {
|
|
173
|
+
return acc + line.quantity;
|
|
174
|
+
}, 0);
|
|
175
|
+
const distributedOderDiscount = order.discounts.reduce((acc, discount) => {
|
|
176
|
+
if (discount.type === "DISTRIBUTED_ORDER_PROMOTION") {
|
|
177
|
+
return acc - discount.amountWithTax / 100 / totalProductsQuantity;
|
|
178
|
+
}
|
|
179
|
+
return acc;
|
|
180
|
+
}, 0);
|
|
181
|
+
const lineItemsDistributedDiscountArray = order.lines.map((line) => {
|
|
182
|
+
const basePrice = (line.discountedLinePriceWithTax != line.linePriceWithTax
|
|
183
|
+
? line.discountedLinePriceWithTax
|
|
184
|
+
: line.linePriceWithTax) /
|
|
185
|
+
100 /
|
|
186
|
+
line.quantity;
|
|
187
|
+
const price = basePrice - distributedOderDiscount > 0
|
|
188
|
+
? basePrice - distributedOderDiscount
|
|
189
|
+
: 0;
|
|
190
|
+
const excessDiscount = basePrice - distributedOderDiscount > 0
|
|
191
|
+
? 0
|
|
192
|
+
: distributedOderDiscount - basePrice;
|
|
193
|
+
return { price, excessDiscount };
|
|
194
|
+
});
|
|
195
|
+
let totalExcessDiscount = lineItemsDistributedDiscountArray.reduce((acc, { excessDiscount }) => acc + excessDiscount, 0);
|
|
196
|
+
const invoicecontents = order.lines.map((line, index) => {
|
|
197
|
+
let priceValue = lineItemsDistributedDiscountArray[index].price;
|
|
198
|
+
if (totalExcessDiscount > 0) {
|
|
199
|
+
priceValue =
|
|
200
|
+
totalExcessDiscount > priceValue
|
|
201
|
+
? 0
|
|
202
|
+
: priceValue - totalExcessDiscount;
|
|
203
|
+
totalExcessDiscount -=
|
|
204
|
+
lineItemsDistributedDiscountArray[index].price;
|
|
205
|
+
}
|
|
206
|
+
const price = `${priceValue}`;
|
|
207
|
+
return {
|
|
208
|
+
invoicecontent: {
|
|
209
|
+
name: line.productVariant.name,
|
|
210
|
+
count: `${line.quantity}`,
|
|
211
|
+
unit_count: `${line.quantity}`,
|
|
212
|
+
price,
|
|
213
|
+
unit: `szt.`,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
const shipping = order.shippingWithTax / 100;
|
|
218
|
+
if (shipping !== 0) {
|
|
219
|
+
const shippingLine = order.shippingLines[0];
|
|
220
|
+
const shippingMethod = await this.shippingMethodService.findOne(ctx, shippingLine.shippingMethod.id);
|
|
221
|
+
const shippingcontent = {
|
|
222
|
+
invoicecontent: {
|
|
223
|
+
name: (shippingMethod === null || shippingMethod === void 0 ? void 0 : shippingMethod.name) || "Shipping",
|
|
224
|
+
count: "1",
|
|
225
|
+
unit_count: "1",
|
|
226
|
+
price: `${shipping}`,
|
|
227
|
+
unit: `szt.`,
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
invoicecontents.push(shippingcontent);
|
|
231
|
+
}
|
|
232
|
+
return { contractor, invoicecontents };
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
console.error("error on get data order data for invoice", error);
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
exports.WFirmaService = WFirmaService;
|
|
241
|
+
exports.WFirmaService = WFirmaService = __decorate([
|
|
242
|
+
(0, common_1.Injectable)(),
|
|
243
|
+
__param(2, (0, common_1.Inject)(constants_1.PLUGIN_INIT_OPTIONS)),
|
|
244
|
+
__metadata("design:paramtypes", [core_1.OrderService,
|
|
245
|
+
core_1.ShippingMethodService, Object])
|
|
246
|
+
], WFirmaService);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { addActionBarItem } from "@deenruv/admin-ui/core";
|
|
2
|
+
import { switchMap, map } from "rxjs";
|
|
3
|
+
import gql from "graphql-tag";
|
|
4
|
+
import { MUTATIONS } from "../graphql/mutations";
|
|
5
|
+
|
|
6
|
+
export const ProformaInvoiceActionButton = addActionBarItem({
|
|
7
|
+
id: "wystaw-proforme",
|
|
8
|
+
buttonStyle: "solid",
|
|
9
|
+
buttonColor: "success",
|
|
10
|
+
icon: "printer",
|
|
11
|
+
locationId: "order-detail",
|
|
12
|
+
label: "Wystaw proformę",
|
|
13
|
+
buttonState: ({ route, dataService, notificationService, injector }) => {
|
|
14
|
+
return route.data.pipe(
|
|
15
|
+
switchMap((data) => data.detail.entity),
|
|
16
|
+
map((order: any) => {
|
|
17
|
+
if (
|
|
18
|
+
order?.state === "PaymentSettled" ||
|
|
19
|
+
order?.state === "InRealization" ||
|
|
20
|
+
order?.state === "PartiallyShipped" ||
|
|
21
|
+
order?.state === "Shipped" ||
|
|
22
|
+
order?.state === "PartiallyDelivered" ||
|
|
23
|
+
order?.state === "Delivered"
|
|
24
|
+
) {
|
|
25
|
+
return { disabled: false, visible: true };
|
|
26
|
+
}
|
|
27
|
+
return { disabled: false, visible: false };
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
onClick: async (x, { route, dataService, notificationService, injector }) => {
|
|
32
|
+
const orderID = route.snapshot.params.id;
|
|
33
|
+
const response = await dataService
|
|
34
|
+
.mutate(MUTATIONS["SEND_INVOICE"], {
|
|
35
|
+
input: { orderID, invoiceType: "proforma" },
|
|
36
|
+
})
|
|
37
|
+
.toPromise();
|
|
38
|
+
|
|
39
|
+
if (response?.sendInvoiceToWFirma) {
|
|
40
|
+
const url = "https://wfirma.pl/invoices/index/proforma";
|
|
41
|
+
//@ts-expect-error vendure specific :)
|
|
42
|
+
window.open(url, "_blank");
|
|
43
|
+
notificationService.success("Proforma została wygenerowana");
|
|
44
|
+
} else {
|
|
45
|
+
notificationService.error("Wystąpił błąd podczas generowania proformy");
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { addActionBarItem } from "@deenruv/admin-ui/core";
|
|
2
|
+
import { switchMap, map } from "rxjs";
|
|
3
|
+
import gql from "graphql-tag";
|
|
4
|
+
import { MUTATIONS } from "../graphql/mutations";
|
|
5
|
+
|
|
6
|
+
export const RecipeInvoiceActionButton = addActionBarItem({
|
|
7
|
+
id: "wystaw-paragon",
|
|
8
|
+
buttonStyle: "solid",
|
|
9
|
+
buttonColor: "success",
|
|
10
|
+
icon: "printer",
|
|
11
|
+
locationId: "order-detail",
|
|
12
|
+
label: "Wystaw paragon",
|
|
13
|
+
buttonState: ({ route, dataService, notificationService, injector }) => {
|
|
14
|
+
return route.data.pipe(
|
|
15
|
+
switchMap((data) => data.detail.entity),
|
|
16
|
+
map((order: any) => {
|
|
17
|
+
if (
|
|
18
|
+
order?.state === "PaymentSettled" ||
|
|
19
|
+
order?.state === "InRealization" ||
|
|
20
|
+
order?.state === "PartiallyShipped" ||
|
|
21
|
+
order?.state === "Shipped" ||
|
|
22
|
+
order?.state === "PartiallyDelivered" ||
|
|
23
|
+
order?.state === "Delivered"
|
|
24
|
+
) {
|
|
25
|
+
return { disabled: false, visible: true };
|
|
26
|
+
}
|
|
27
|
+
return { disabled: false, visible: false };
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
onClick: async (x, { route, dataService, notificationService, injector }) => {
|
|
32
|
+
const orderID = route.snapshot.params.id;
|
|
33
|
+
const response = await dataService
|
|
34
|
+
.mutate(MUTATIONS["SEND_INVOICE"], {
|
|
35
|
+
input: { orderID, invoiceType: "receipt_fiscal_normal" },
|
|
36
|
+
})
|
|
37
|
+
.toPromise();
|
|
38
|
+
|
|
39
|
+
if (response?.sendInvoiceToWFirma) {
|
|
40
|
+
const url = "https://wfirma.pl/invoices/index/all";
|
|
41
|
+
//@ts-expect-error vendure specific :)
|
|
42
|
+
window.open(url, "_blank");
|
|
43
|
+
notificationService.success("Paragon został wygenerowany");
|
|
44
|
+
} else {
|
|
45
|
+
notificationService.error("Wystąpił błąd podczas generowania paragonu");
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { $ } from "../zeus";
|
|
2
|
+
import { typedGql } from "../zeus/typedDocumentNode";
|
|
3
|
+
import { scalars } from "./scalars";
|
|
4
|
+
|
|
5
|
+
const mutation = typedGql("mutation", { scalars });
|
|
6
|
+
|
|
7
|
+
const SEND_INVOICE = mutation({
|
|
8
|
+
sendInvoiceToWFirma: [
|
|
9
|
+
{ input: $("input", "SendInvoiceToWFirmaInput!") },
|
|
10
|
+
{ url: true },
|
|
11
|
+
],
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const MUTATIONS = { SEND_INVOICE };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ZeusScalars } from "../zeus";
|
|
2
|
+
|
|
3
|
+
export const scalars = ZeusScalars({
|
|
4
|
+
DateTime: {
|
|
5
|
+
decode: (e: unknown) => new Date(e as string).toISOString(),
|
|
6
|
+
encode: (e: unknown) => (e as Date).toISOString(),
|
|
7
|
+
},
|
|
8
|
+
JSON: {
|
|
9
|
+
decode: (e: unknown) => JSON.parse(e as string),
|
|
10
|
+
encode: (e: unknown) => JSON.stringify(e),
|
|
11
|
+
},
|
|
12
|
+
Money: {
|
|
13
|
+
decode: (e) => e as number,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { registerReactCustomDetailComponent } from "@deenruv/admin-ui/react";
|
|
2
|
+
import { ProformaInvoiceActionButton } from "./components/ProformaInvoiceActionButton";
|
|
3
|
+
import { RecipeInvoiceActionButton } from "./components/RecipeInvoiceActionButton";
|
|
4
|
+
// import { OrderDetailWFirma } from "./components/OrderDetailWFirma";
|
|
5
|
+
|
|
6
|
+
export default [
|
|
7
|
+
ProformaInvoiceActionButton,
|
|
8
|
+
RecipeInvoiceActionButton,
|
|
9
|
+
// registerReactCustomDetailComponent({
|
|
10
|
+
// component: OrderDetailWFirma,
|
|
11
|
+
// locationId: "order-detail",
|
|
12
|
+
// }),
|
|
13
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default [];
|
|
File without changes
|