@zauru-sdk/services 1.0.49 → 1.0.52
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/dist/cjs/common.js +235 -0
- package/dist/cjs/index.js +50 -0
- package/dist/cjs/sessions/sessions.js +18 -0
- package/dist/cjs/sessions/upstash.js +59 -0
- package/dist/cjs/zauru/httpGraphQL.js +42 -0
- package/dist/cjs/zauru/httpOauth.js +42 -0
- package/dist/cjs/zauru/httpZauru.js +42 -0
- package/dist/cjs/zauru/zauru-agencies.js +27 -0
- package/dist/cjs/zauru/zauru-automatic-numbers.js +28 -0
- package/dist/cjs/zauru/zauru-bookings.js +90 -0
- package/dist/cjs/zauru/zauru-bundles.js +104 -0
- package/dist/cjs/zauru/zauru-cases.js +30 -0
- package/dist/cjs/zauru/zauru-consolidated.js +81 -0
- package/dist/cjs/zauru/zauru-currencies.js +27 -0
- package/dist/cjs/zauru/zauru-deliveries.js +53 -0
- package/dist/cjs/zauru/zauru-discharges.js +55 -0
- package/dist/cjs/zauru/zauru-employees.js +30 -0
- package/dist/cjs/zauru/zauru-forms.js +363 -0
- package/dist/cjs/zauru/zauru-invoices.js +104 -0
- package/dist/cjs/zauru/zauru-items.js +293 -0
- package/dist/cjs/zauru/zauru-lote-record.js +33 -0
- package/dist/cjs/zauru/zauru-lotes.js +312 -0
- package/dist/cjs/zauru/zauru-motivos-rechazo.js +57 -0
- package/dist/cjs/zauru/zauru-payees.js +247 -0
- package/dist/cjs/zauru/zauru-payment-terms.js +75 -0
- package/dist/cjs/zauru/zauru-price-lists.js +49 -0
- package/dist/cjs/zauru/zauru-profiles.js +80 -0
- package/dist/cjs/zauru/zauru-purchase-orders.js +438 -0
- package/dist/cjs/zauru/zauru-receptions.js +104 -0
- package/dist/cjs/zauru/zauru-shipments.js +62 -0
- package/dist/cjs/zauru/zauru-suggested-prices.js +94 -0
- package/dist/cjs/zauru/zauru-tags.js +20 -0
- package/dist/cjs/zauru/zauru-templates.js +22 -0
- package/dist/cjs/zauru/zauru-variables.js +56 -0
- package/dist/cjs/zauru/zauru-web-app-tables.js +167 -0
- package/package.json +12 -9
- package/CHANGELOG.md +0 -232
- package/src/common.ts +0 -343
- package/src/index.ts +0 -37
- package/src/sessions/sessions.ts +0 -17
- package/src/sessions/upstash.ts +0 -55
- package/src/zauru/httpGraphQL.ts +0 -55
- package/src/zauru/httpOauth.ts +0 -55
- package/src/zauru/httpZauru.ts +0 -56
- package/src/zauru/zauru-agencies.ts +0 -32
- package/src/zauru/zauru-automatic-numbers.ts +0 -35
- package/src/zauru/zauru-bookings.ts +0 -134
- package/src/zauru/zauru-bundles.ts +0 -157
- package/src/zauru/zauru-cases.ts +0 -44
- package/src/zauru/zauru-consolidated.ts +0 -129
- package/src/zauru/zauru-currencies.ts +0 -39
- package/src/zauru/zauru-deliveries.ts +0 -70
- package/src/zauru/zauru-discharges.ts +0 -90
- package/src/zauru/zauru-employees.ts +0 -43
- package/src/zauru/zauru-forms.ts +0 -618
- package/src/zauru/zauru-invoices.ts +0 -142
- package/src/zauru/zauru-items.ts +0 -481
- package/src/zauru/zauru-lote-record.ts +0 -77
- package/src/zauru/zauru-lotes.ts +0 -484
- package/src/zauru/zauru-motivos-rechazo.ts +0 -121
- package/src/zauru/zauru-payees.ts +0 -402
- package/src/zauru/zauru-payment-terms.ts +0 -126
- package/src/zauru/zauru-price-lists.ts +0 -68
- package/src/zauru/zauru-profiles.ts +0 -106
- package/src/zauru/zauru-purchase-orders.ts +0 -701
- package/src/zauru/zauru-receptions.ts +0 -148
- package/src/zauru/zauru-shipments.ts +0 -88
- package/src/zauru/zauru-suggested-prices.ts +0 -137
- package/src/zauru/zauru-tags.ts +0 -22
- package/src/zauru/zauru-templates.ts +0 -24
- package/src/zauru/zauru-variables.ts +0 -67
- package/src/zauru/zauru-web-app-tables.ts +0 -256
- package/tsconfig.json +0 -24
- /package/dist/{common.js → esm/common.js} +0 -0
- /package/dist/{index.js → esm/index.js} +0 -0
- /package/dist/{sessions → esm/sessions}/sessions.js +0 -0
- /package/dist/{sessions → esm/sessions}/upstash.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpGraphQL.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpOauth.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpZauru.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-agencies.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-automatic-numbers.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-bookings.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-bundles.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-cases.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-consolidated.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-currencies.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-deliveries.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-discharges.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-employees.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-forms.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-invoices.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-items.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-lote-record.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-lotes.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-motivos-rechazo.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-payees.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-payment-terms.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-price-lists.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-profiles.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-purchase-orders.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-receptions.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-shipments.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-suggested-prices.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-tags.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-templates.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-variables.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-web-app-tables.js +0 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPurchasesOrderByIdNumber = exports.deletePurchaseOrder = exports.getGraphQLPurchaseOrderBetweenDates = exports.getPurchaseOrder = exports.getLast100Receptions = exports.updateReceivedPurchaseOrder = exports.updatePurchaseOrder = exports.enablePurchase = exports.getPurchase = exports.getPurchasesList = exports.getPurchasesListDataTables = exports.getNewPurchaseOrderInfo = exports.receivePurchaseOrder = exports.receiveLotPurchaseOrder = exports.createNewAuthorizedPurchaseOrder = exports.createNewPurchaseOrder = exports.markAsReceivePartialPurchaseOrder = exports.markAsReceivePurchaseOrder = void 0;
|
|
7
|
+
const common_1 = require("@zauru-sdk/common");
|
|
8
|
+
const zauru_receptions_js_1 = require("./zauru-receptions.js");
|
|
9
|
+
const httpZauru_js_1 = __importDefault(require("./httpZauru.js"));
|
|
10
|
+
const common_js_1 = require("../common.js");
|
|
11
|
+
const httpGraphQL_js_1 = __importDefault(require("./httpGraphQL.js"));
|
|
12
|
+
const graphql_1 = require("@zauru-sdk/graphql");
|
|
13
|
+
/**
|
|
14
|
+
* markAsReceivePurchaseOrder
|
|
15
|
+
* Esta función sólo se utiliza cuando se van a marcar como recibida toda la órden de compra, se recibe todo lo que se envío
|
|
16
|
+
* si se quiere recibir parcialmente, utilizar el endpoint de /receptions
|
|
17
|
+
* @param headers
|
|
18
|
+
* @param body
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
const markAsReceivePurchaseOrder = (headers, body) => {
|
|
22
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
23
|
+
const sendBody = { ...body };
|
|
24
|
+
if (sendBody.fechaVencimiento) {
|
|
25
|
+
await (0, exports.receiveLotPurchaseOrder)(headers, sendBody);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
await (0, exports.receivePurchaseOrder)(headers, sendBody);
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.markAsReceivePurchaseOrder = markAsReceivePurchaseOrder;
|
|
34
|
+
/**
|
|
35
|
+
* markAsReceivePartialPurchaseOrder
|
|
36
|
+
* @param headers
|
|
37
|
+
* @param body
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
const markAsReceivePartialPurchaseOrder = (headers, session, body) => {
|
|
41
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
42
|
+
const sendBody = { ...body };
|
|
43
|
+
if (sendBody.fechaVencimiento) {
|
|
44
|
+
await (0, zauru_receptions_js_1.createNewLotPurchaseOrderReception)(headers, session, sendBody);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
await (0, zauru_receptions_js_1.createNewPurchaseOrderReception)(headers, session, body);
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
exports.markAsReceivePartialPurchaseOrder = markAsReceivePartialPurchaseOrder;
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param headers
|
|
56
|
+
* @param body
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
const createNewPurchaseOrder = (headers, body) => {
|
|
60
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
61
|
+
let sendBody = {
|
|
62
|
+
...body,
|
|
63
|
+
purchase_order_details_attributes: (0, common_1.arrayToObject)(body?.purchase_order_details),
|
|
64
|
+
tag_ids: [
|
|
65
|
+
"",
|
|
66
|
+
...(body?.taggings?.map((x) => x.tag_id?.toString()) ?? []),
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
delete headers["Content-type"];
|
|
70
|
+
delete sendBody.__rvfInternalFormId;
|
|
71
|
+
delete sendBody.taggings;
|
|
72
|
+
delete sendBody.purchase_order_details;
|
|
73
|
+
if (!(sendBody?.pdf instanceof File) || sendBody.pdf?.size <= 0) {
|
|
74
|
+
delete sendBody.pdf;
|
|
75
|
+
}
|
|
76
|
+
sendBody = (0, common_1.convertToFormData)({
|
|
77
|
+
purchase_order: sendBody,
|
|
78
|
+
});
|
|
79
|
+
const response = await httpZauru_js_1.default.post(`/purchases/purchase_orders.json`, sendBody, { headers });
|
|
80
|
+
return response.data;
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
exports.createNewPurchaseOrder = createNewPurchaseOrder;
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* @param headers
|
|
87
|
+
* @param body
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
const createNewAuthorizedPurchaseOrder = (headers, body, withReceive = true) => {
|
|
91
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
92
|
+
const sendBody = {
|
|
93
|
+
...body,
|
|
94
|
+
purchase_order_details_attributes: (0, common_1.arrayToObject)(body?.purchase_order_details),
|
|
95
|
+
};
|
|
96
|
+
const response = await httpZauru_js_1.default.post(`/purchases/purchase_orders.json`, { purchase_order: sendBody }, { headers });
|
|
97
|
+
await httpZauru_js_1.default.get(`/purchases/purchase_orders/${response.data.id}/authorize.json`, { headers });
|
|
98
|
+
if (withReceive) {
|
|
99
|
+
if (sendBody.fechaVencimiento) {
|
|
100
|
+
await (0, exports.receiveLotPurchaseOrder)(headers, response.data);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
await (0, exports.receivePurchaseOrder)(headers, response.data);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return response.data;
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
exports.createNewAuthorizedPurchaseOrder = createNewAuthorizedPurchaseOrder;
|
|
110
|
+
/**
|
|
111
|
+
* receiveLotPurchaseOrder
|
|
112
|
+
* @param headers
|
|
113
|
+
* @param body
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
const receiveLotPurchaseOrder = (headers, body) => {
|
|
117
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
118
|
+
const sendBody = {
|
|
119
|
+
agency_id: body.agency_id,
|
|
120
|
+
delivery_date: body.issue_date,
|
|
121
|
+
id: body.id,
|
|
122
|
+
needs_transit: false,
|
|
123
|
+
purchase_order_details_attributes: (0, common_1.arrayToObject)(body.purchase_order_details?.map((x) => {
|
|
124
|
+
const newDetail = {
|
|
125
|
+
id: x.id,
|
|
126
|
+
booked_quantity: x.booked_quantity,
|
|
127
|
+
item_id: x.item_id,
|
|
128
|
+
lot_delivered_quantity: [x.delivered_quantity],
|
|
129
|
+
lot_name: [body.id_number],
|
|
130
|
+
lot_expire: [body.fechaVencimiento],
|
|
131
|
+
};
|
|
132
|
+
return newDetail;
|
|
133
|
+
})),
|
|
134
|
+
};
|
|
135
|
+
await httpZauru_js_1.default.patch(`/purchases/purchase_orders/${body.id}/receive_action`, { purchase_order: sendBody }, { headers });
|
|
136
|
+
return true;
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
exports.receiveLotPurchaseOrder = receiveLotPurchaseOrder;
|
|
140
|
+
/**
|
|
141
|
+
* receivePurchaseOrder
|
|
142
|
+
* @param headers
|
|
143
|
+
* @param body
|
|
144
|
+
* @returns
|
|
145
|
+
*/
|
|
146
|
+
const receivePurchaseOrder = (headers, body) => {
|
|
147
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
148
|
+
const sendBody = {
|
|
149
|
+
agency_id: body.agency_id,
|
|
150
|
+
delivery_date: body.issue_date,
|
|
151
|
+
id: body.id,
|
|
152
|
+
needs_transit: false,
|
|
153
|
+
purchase_order_details_attributes: (0, common_1.arrayToObject)(body.purchase_order_details?.map((x) => {
|
|
154
|
+
const newDetail = {
|
|
155
|
+
id: x.id,
|
|
156
|
+
delivered_quantity: x.delivered_quantity,
|
|
157
|
+
booked_quantity: x.booked_quantity,
|
|
158
|
+
item_id: x.item_id,
|
|
159
|
+
};
|
|
160
|
+
return newDetail;
|
|
161
|
+
})),
|
|
162
|
+
};
|
|
163
|
+
await httpZauru_js_1.default.patch(`/purchases/purchase_orders/${body.id}/receive_action`, { purchase_order: sendBody }, { headers });
|
|
164
|
+
return true;
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
exports.receivePurchaseOrder = receivePurchaseOrder;
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* @param headers
|
|
171
|
+
* @returns
|
|
172
|
+
*/
|
|
173
|
+
const getNewPurchaseOrderInfo = (headers) => {
|
|
174
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
175
|
+
const response = await httpZauru_js_1.default.get("/purchases/purchase_orders/new.json", { headers });
|
|
176
|
+
const purchasersList = [];
|
|
177
|
+
response.data?.purchasers?.forEach((purchaser) => {
|
|
178
|
+
if (purchaser?.id) {
|
|
179
|
+
purchasersList.push({
|
|
180
|
+
value: purchaser?.id,
|
|
181
|
+
label: purchaser?.name,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
return { ...response.data, purchasersList };
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
exports.getNewPurchaseOrderInfo = getNewPurchaseOrderInfo;
|
|
189
|
+
/**
|
|
190
|
+
* getPurchasesListDataTables Function for get all zauru orden-compras
|
|
191
|
+
* @param headers
|
|
192
|
+
* @returns
|
|
193
|
+
*/
|
|
194
|
+
const getPurchasesListDataTables = (headers, body) => {
|
|
195
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
196
|
+
const response = await httpZauru_js_1.default.post(`/purchases/purchase_orders/datatables.json`, body, { headers });
|
|
197
|
+
return response.data;
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
exports.getPurchasesListDataTables = getPurchasesListDataTables;
|
|
201
|
+
/**
|
|
202
|
+
* getPurchasesList Function for get all zauru orden-compras
|
|
203
|
+
* @param headers
|
|
204
|
+
* @param params
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
207
|
+
const getPurchasesList = (headers, session, params = {}, config) => {
|
|
208
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
209
|
+
//Si quiere obtener los de producción, obtengo primero su agencia producción
|
|
210
|
+
if (config?.fromProduction) {
|
|
211
|
+
const { production_agency_id: temp_production_agency_id } = await (0, common_js_1.getVariablesByName)(headers, session, ["production_agency_id"]);
|
|
212
|
+
const hashProductionAgencyId = JSON.parse(temp_production_agency_id ?? "{}");
|
|
213
|
+
const production_agency_id = hashProductionAgencyId[session.get("agency_id")];
|
|
214
|
+
params.agency_id = production_agency_id;
|
|
215
|
+
}
|
|
216
|
+
const response = await httpZauru_js_1.default.get(`/purchases/purchase_orders/export.json`, {
|
|
217
|
+
headers,
|
|
218
|
+
params,
|
|
219
|
+
});
|
|
220
|
+
return response.data;
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
exports.getPurchasesList = getPurchasesList;
|
|
224
|
+
/**
|
|
225
|
+
* getPurchase Function for get an especific purchase order
|
|
226
|
+
* @param headers
|
|
227
|
+
* @returns
|
|
228
|
+
*/
|
|
229
|
+
const getPurchase = (headers, purchase_order_id) => {
|
|
230
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
231
|
+
const response = await (0, httpZauru_js_1.default)(`/purchases/purchase_orders/${purchase_order_id}.json`, { method: "GET", headers });
|
|
232
|
+
const baskets_memo = (0, common_1.getBasketsSchema)(response.data.memo);
|
|
233
|
+
const baskets_memo_quantity = baskets_memo
|
|
234
|
+
.map((basket) => basket.total)
|
|
235
|
+
.reduce(common_1.reduceAdd, 0);
|
|
236
|
+
return {
|
|
237
|
+
...response.data,
|
|
238
|
+
baskets_memo,
|
|
239
|
+
baskets_memo_quantity,
|
|
240
|
+
};
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
exports.getPurchase = getPurchase;
|
|
244
|
+
/**
|
|
245
|
+
* enablePurchase Enable a purchase order
|
|
246
|
+
* @param headers
|
|
247
|
+
* @param purchase_order_id
|
|
248
|
+
* @param reception_id
|
|
249
|
+
* @returns
|
|
250
|
+
*/
|
|
251
|
+
const enablePurchase = (headers, purchase_order_id, reception_id) => {
|
|
252
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
253
|
+
const response = await httpZauru_js_1.default.get(`/purchases/receptions/${reception_id}/rebound.json?purchase_order_id=${purchase_order_id}`, { headers });
|
|
254
|
+
return response.data;
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
exports.enablePurchase = enablePurchase;
|
|
258
|
+
/**
|
|
259
|
+
* updatePurchaseOrder
|
|
260
|
+
* @param headers
|
|
261
|
+
* @param body
|
|
262
|
+
* @param purchase_order_id
|
|
263
|
+
* @returns
|
|
264
|
+
*/
|
|
265
|
+
const updatePurchaseOrder = (headers, body, purchase_order_id) => {
|
|
266
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
267
|
+
const response = await httpZauru_js_1.default.patch(`/purchases/purchase_orders/${purchase_order_id}.json`, body, { headers });
|
|
268
|
+
return response.data;
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
exports.updatePurchaseOrder = updatePurchaseOrder;
|
|
272
|
+
/**
|
|
273
|
+
* updatePurchaseOrder
|
|
274
|
+
* @param headers
|
|
275
|
+
* @param body
|
|
276
|
+
* @param purchase_order_id
|
|
277
|
+
* @returns
|
|
278
|
+
*/
|
|
279
|
+
const updateReceivedPurchaseOrder = (headers, body, purchase_order_id) => {
|
|
280
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
281
|
+
const response = await httpZauru_js_1.default.patch(`/purchases/purchase_orders/${purchase_order_id}/update_received.json`, body, { headers });
|
|
282
|
+
return response.data;
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
exports.updateReceivedPurchaseOrder = updateReceivedPurchaseOrder;
|
|
286
|
+
/**
|
|
287
|
+
* getLast100Receptions
|
|
288
|
+
* @param headers
|
|
289
|
+
* @returns
|
|
290
|
+
*/
|
|
291
|
+
const getLast100Receptions = (session, agency_id) => {
|
|
292
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
293
|
+
const headers = await (0, common_js_1.getGraphQLAPIHeaders)(session);
|
|
294
|
+
const response = await httpGraphQL_js_1.default.post("", {
|
|
295
|
+
query: graphql_1.getLast100ReceptionsStringQuery,
|
|
296
|
+
variables: {
|
|
297
|
+
agencyId: agency_id ?? session.get("agency_id"),
|
|
298
|
+
},
|
|
299
|
+
}, { headers });
|
|
300
|
+
if (response.data.errors) {
|
|
301
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
302
|
+
}
|
|
303
|
+
return response.data?.data?.purchase_orders;
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
exports.getLast100Receptions = getLast100Receptions;
|
|
307
|
+
/**
|
|
308
|
+
* getPurchaseOrder
|
|
309
|
+
* @param headers
|
|
310
|
+
* @returns
|
|
311
|
+
*/
|
|
312
|
+
const getPurchaseOrder = (session, poId, config = {
|
|
313
|
+
withLotStocksToMyAgency: false,
|
|
314
|
+
}) => {
|
|
315
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
316
|
+
const headers = await (0, common_js_1.getGraphQLAPIHeaders)(session);
|
|
317
|
+
const response = await httpGraphQL_js_1.default.post("", {
|
|
318
|
+
query: (0, graphql_1.getPurchaseOrderStringQuery)({
|
|
319
|
+
withLotStocks: config.withLotStocksToMyAgency,
|
|
320
|
+
}),
|
|
321
|
+
variables: {
|
|
322
|
+
id: poId,
|
|
323
|
+
},
|
|
324
|
+
}, { headers });
|
|
325
|
+
if (response.data.errors) {
|
|
326
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
327
|
+
}
|
|
328
|
+
const tempResponse = response.data?.data?.purchase_orders[0];
|
|
329
|
+
if (config.withLotStocksToMyAgency) {
|
|
330
|
+
tempResponse.lots[0].lot_stocks = tempResponse.lots[0].lot_stocks.filter((x) => x.agency_id === Number(session.get("agency_id")));
|
|
331
|
+
}
|
|
332
|
+
return tempResponse;
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
exports.getPurchaseOrder = getPurchaseOrder;
|
|
336
|
+
/**
|
|
337
|
+
* getPurchaseOrder
|
|
338
|
+
* @param headers
|
|
339
|
+
* @returns
|
|
340
|
+
*/
|
|
341
|
+
const getGraphQLPurchaseOrderBetweenDates = (session, dates, config = {
|
|
342
|
+
agencyFilter: true,
|
|
343
|
+
consolidateIdFilter: false,
|
|
344
|
+
useProductionAgencyId: false,
|
|
345
|
+
withShipmentToMyAgency: false,
|
|
346
|
+
withLotStocksToMyAgency: false,
|
|
347
|
+
}) => {
|
|
348
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
349
|
+
const headers = await (0, common_js_1.getGraphQLAPIHeaders)(session);
|
|
350
|
+
let agency_id = config.agencyId;
|
|
351
|
+
if (config.useProductionAgencyId) {
|
|
352
|
+
const { production_agency_id /**{5693: 5696} */ } = await (0, common_js_1.getVariablesByName)(headers, session, ["production_agency_id"]);
|
|
353
|
+
const hashAgencyId = JSON.parse(production_agency_id ?? "{}");
|
|
354
|
+
agency_id = hashAgencyId[session.get("agency_id")];
|
|
355
|
+
}
|
|
356
|
+
const query = (0, graphql_1.getPurchaseOrdersBetweenDatesStringQuery)({
|
|
357
|
+
agencyFilter: config.agencyFilter,
|
|
358
|
+
consolidateIdFilter: config.consolidateIdFilter,
|
|
359
|
+
lotItemIdExclusion: config.lotItemIdExclusion,
|
|
360
|
+
poDetailTagId: config.poDetailTagId,
|
|
361
|
+
withLotStocks: config.withLotStocksToMyAgency,
|
|
362
|
+
//itemId: config.itemId,
|
|
363
|
+
//payeeCategoryId: config.payeeCategoryId,
|
|
364
|
+
});
|
|
365
|
+
const variables = {
|
|
366
|
+
...(config.agencyFilter
|
|
367
|
+
? { agencyId: agency_id ?? session.get("agency_id") }
|
|
368
|
+
: {}),
|
|
369
|
+
...(config.lotItemIdExclusion
|
|
370
|
+
? { lotItemIdExclusion: config.lotItemIdExclusion }
|
|
371
|
+
: {}),
|
|
372
|
+
...(config.poDetailTagId ? { poDetailTagId: config.poDetailTagId } : {}),
|
|
373
|
+
startDate: (0, common_1.formatDateToUTC)(dates.startDate),
|
|
374
|
+
endDate: (0, common_1.formatDateToUTC)(dates.endDate),
|
|
375
|
+
};
|
|
376
|
+
const response = await httpGraphQL_js_1.default.post("", {
|
|
377
|
+
query,
|
|
378
|
+
variables,
|
|
379
|
+
}, { headers });
|
|
380
|
+
if (response.data.errors) {
|
|
381
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
382
|
+
}
|
|
383
|
+
//============ Aplicación de filtros
|
|
384
|
+
let responseData = [];
|
|
385
|
+
if (config.withShipmentToMyAgency) {
|
|
386
|
+
responseData = response.data?.data?.purchase_orders.filter((x) => x.shipment_purchase_orders.some((y) => y.shipment.agency_to_id?.toString() == session.get("agency_id")));
|
|
387
|
+
}
|
|
388
|
+
if (config.withLotStocksToMyAgency) {
|
|
389
|
+
responseData = responseData.map((x) => {
|
|
390
|
+
x.lots = x.lots.map((y) => {
|
|
391
|
+
y.lot_stocks = y.lot_stocks.filter((z) => z.agency_id == session.get("agency_id"));
|
|
392
|
+
return y;
|
|
393
|
+
});
|
|
394
|
+
return x;
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
return responseData;
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
exports.getGraphQLPurchaseOrderBetweenDates = getGraphQLPurchaseOrderBetweenDates;
|
|
401
|
+
/**
|
|
402
|
+
* deletePurchaseOrder
|
|
403
|
+
* @param headers
|
|
404
|
+
* @param id
|
|
405
|
+
* @returns
|
|
406
|
+
*/
|
|
407
|
+
const deletePurchaseOrder = (headers, id) => {
|
|
408
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
409
|
+
await httpZauru_js_1.default.delete(`/purchases/purchase_orders/${id}.json?destroy=true`, { headers });
|
|
410
|
+
return true;
|
|
411
|
+
});
|
|
412
|
+
};
|
|
413
|
+
exports.deletePurchaseOrder = deletePurchaseOrder;
|
|
414
|
+
/**
|
|
415
|
+
* getPurchaseOrderByIdNumber
|
|
416
|
+
* @param session
|
|
417
|
+
* @param idNumber
|
|
418
|
+
* @returns
|
|
419
|
+
*/
|
|
420
|
+
const getPurchasesOrderByIdNumber = (session, id_number) => {
|
|
421
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
422
|
+
const headers = await (0, common_js_1.getGraphQLAPIHeaders)(session);
|
|
423
|
+
const response = await httpGraphQL_js_1.default.post("", {
|
|
424
|
+
query: graphql_1.getPurchaseOrderByIdNumberStringQuery,
|
|
425
|
+
variables: {
|
|
426
|
+
id_number,
|
|
427
|
+
},
|
|
428
|
+
}, { headers });
|
|
429
|
+
if (response.data.errors) {
|
|
430
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
431
|
+
}
|
|
432
|
+
if (!response?.data?.data.purchase_orders) {
|
|
433
|
+
return [];
|
|
434
|
+
}
|
|
435
|
+
return response.data?.data?.purchase_orders;
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
exports.getPurchasesOrderByIdNumber = getPurchasesOrderByIdNumber;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createNewLotPurchaseOrderReception = exports.createNewPurchaseOrderReception = exports.deleteReception = exports.createNewReception = void 0;
|
|
7
|
+
const common_1 = require("@zauru-sdk/common");
|
|
8
|
+
const httpZauru_js_1 = __importDefault(require("./httpZauru.js"));
|
|
9
|
+
/**
|
|
10
|
+
* createNewReception
|
|
11
|
+
* @param headers
|
|
12
|
+
* @param body
|
|
13
|
+
* @param purchase_order_id
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
async function createNewReception(headers, body, purchase_order_id) {
|
|
17
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
18
|
+
const response = await (0, httpZauru_js_1.default)(`/purchases/purchase_orders/${purchase_order_id}/receptions.json`, { method: "POST", headers, data: body });
|
|
19
|
+
return response.data;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.createNewReception = createNewReception;
|
|
23
|
+
/**
|
|
24
|
+
* deleteReception
|
|
25
|
+
* @param headers
|
|
26
|
+
* @param id
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
async function deleteReception(headers, receptionId, poId) {
|
|
30
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
31
|
+
await httpZauru_js_1.default.get(`/purchases/receptions/${receptionId}/rebound.json?purchase_order_id=${poId}`, {
|
|
32
|
+
headers,
|
|
33
|
+
});
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.deleteReception = deleteReception;
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param headers
|
|
41
|
+
* @param poId
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
async function createNewPurchaseOrderReception(headers, session, body) {
|
|
45
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
46
|
+
const sendBody = {
|
|
47
|
+
reception: {
|
|
48
|
+
memo: "LABORATORIO - Recibido parcialmente desde WebApp",
|
|
49
|
+
purchase_order_id: body.id,
|
|
50
|
+
needs_transit: false,
|
|
51
|
+
agency_id: session.get("agency_id"),
|
|
52
|
+
entity_id: session.get("selectedEntity"),
|
|
53
|
+
received_at: (0, common_1.getDatePickerCurrentDate)(),
|
|
54
|
+
invoice_number: "",
|
|
55
|
+
reception_details_attributes: (0, common_1.arrayToObject)(body?.purchase_order_details?.map((x) => {
|
|
56
|
+
return {
|
|
57
|
+
item_id: x.item_id,
|
|
58
|
+
purchase_order_detail_id: x.id,
|
|
59
|
+
quantity: x.delivered_quantity,
|
|
60
|
+
};
|
|
61
|
+
})),
|
|
62
|
+
},
|
|
63
|
+
purchase_order_id: body.id,
|
|
64
|
+
};
|
|
65
|
+
await httpZauru_js_1.default.post(`/purchases/purchase_orders/${body.id}/receptions.json`, sendBody, {
|
|
66
|
+
headers,
|
|
67
|
+
});
|
|
68
|
+
return true;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
exports.createNewPurchaseOrderReception = createNewPurchaseOrderReception;
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @param headers
|
|
75
|
+
* @param poId
|
|
76
|
+
* @returns
|
|
77
|
+
*/
|
|
78
|
+
async function createNewLotPurchaseOrderReception(headers, session, body) {
|
|
79
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
80
|
+
const sendBody = {
|
|
81
|
+
memo: "LABORATORIO - Recibido parcialmente desde WebApp",
|
|
82
|
+
purchase_order_id: body.id,
|
|
83
|
+
needs_transit: false,
|
|
84
|
+
received_at: (0, common_1.getDatePickerCurrentDate)(),
|
|
85
|
+
invoice_number: "",
|
|
86
|
+
agency_id: session.get("agency_id"),
|
|
87
|
+
entity_id: session.get("selectedEntity"),
|
|
88
|
+
reception_details_attributes: (0, common_1.arrayToObject)(body?.purchase_order_details?.map((x) => {
|
|
89
|
+
return {
|
|
90
|
+
item_id: x.item_id,
|
|
91
|
+
purchase_order_detail_id: x.id,
|
|
92
|
+
lot_delivered_quantity: [x.delivered_quantity],
|
|
93
|
+
lot_name: [body.id_number],
|
|
94
|
+
lot_expire: [body.fechaVencimiento],
|
|
95
|
+
};
|
|
96
|
+
})),
|
|
97
|
+
};
|
|
98
|
+
await httpZauru_js_1.default.post(`/purchases/purchase_orders/${body.id}/receptions.json`, { reception: sendBody, purchase_order_id: body.id }, {
|
|
99
|
+
headers,
|
|
100
|
+
});
|
|
101
|
+
return true;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
exports.createNewLotPurchaseOrderReception = createNewLotPurchaseOrderReception;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deleteShipment_booking = exports.receiveShipment_booking = exports.getShipmentsByToAgencyLast100Id_booking = void 0;
|
|
7
|
+
const common_1 = require("@zauru-sdk/common");
|
|
8
|
+
const common_js_1 = require("../common.js");
|
|
9
|
+
const httpGraphQL_js_1 = __importDefault(require("./httpGraphQL.js"));
|
|
10
|
+
const graphql_1 = require("@zauru-sdk/graphql");
|
|
11
|
+
const httpZauru_js_1 = __importDefault(require("./httpZauru.js"));
|
|
12
|
+
/**
|
|
13
|
+
* getShipmentsByToAgencyLast100Id_booking
|
|
14
|
+
*/
|
|
15
|
+
async function getShipmentsByToAgencyLast100Id_booking(session, agency_to_id) {
|
|
16
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
17
|
+
const headers = await (0, common_js_1.getGraphQLAPIHeaders)(session);
|
|
18
|
+
const response = await httpGraphQL_js_1.default.post("", {
|
|
19
|
+
query: graphql_1.getShipmentsByToAgencyLast100StringQuery,
|
|
20
|
+
variables: {
|
|
21
|
+
agency_to_id,
|
|
22
|
+
},
|
|
23
|
+
}, { headers });
|
|
24
|
+
if (response.data.errors) {
|
|
25
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
26
|
+
}
|
|
27
|
+
const registers = response?.data?.data?.shipments;
|
|
28
|
+
return registers;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.getShipmentsByToAgencyLast100Id_booking = getShipmentsByToAgencyLast100Id_booking;
|
|
32
|
+
/**
|
|
33
|
+
* receiveShipment_booking
|
|
34
|
+
* @param headers
|
|
35
|
+
* @param id
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
async function receiveShipment_booking(headers, id) {
|
|
39
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
40
|
+
const response = await httpZauru_js_1.default.get(`/inventories/bookings/${id}/deliver.json`, { headers });
|
|
41
|
+
if (!response.data) {
|
|
42
|
+
throw new Error("Sin respuesta de: /inventories/bookings/id/deliver.json");
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.receiveShipment_booking = receiveShipment_booking;
|
|
48
|
+
/**
|
|
49
|
+
* deleteShipment_booking
|
|
50
|
+
* @param headers
|
|
51
|
+
* @param id
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
async function deleteShipment_booking(headers, id) {
|
|
55
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
56
|
+
await httpZauru_js_1.default.delete(`/inventories/bookings/${id}.json`, {
|
|
57
|
+
headers,
|
|
58
|
+
});
|
|
59
|
+
return true;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.deleteShipment_booking = deleteShipment_booking;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deleteSuggestedPrice = exports.createSuggestedPrice = exports.getSuggestedPrices = exports.getSuggestedPricesExportJSON = void 0;
|
|
7
|
+
const common_1 = require("@zauru-sdk/common");
|
|
8
|
+
const httpZauru_js_1 = __importDefault(require("./httpZauru.js"));
|
|
9
|
+
const common_js_1 = require("../common.js");
|
|
10
|
+
const httpGraphQL_js_1 = __importDefault(require("./httpGraphQL.js"));
|
|
11
|
+
const graphql_1 = require("@zauru-sdk/graphql");
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param headers
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
const getSuggestedPricesExportJSON = async (headers) => {
|
|
18
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
19
|
+
const response = await httpZauru_js_1.default.get(`/sales/suggested_prices/export.json`, {
|
|
20
|
+
headers,
|
|
21
|
+
});
|
|
22
|
+
return response.data;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.getSuggestedPricesExportJSON = getSuggestedPricesExportJSON;
|
|
26
|
+
/**
|
|
27
|
+
* getSuggestedPrices
|
|
28
|
+
* @param session
|
|
29
|
+
* @param id
|
|
30
|
+
*/
|
|
31
|
+
async function getSuggestedPrices(session, config) {
|
|
32
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
33
|
+
const { notNullPriceList = false, withItems = false, withItemCategories = false, onlyCurrent = false, } = config;
|
|
34
|
+
const headers = await (0, common_js_1.getGraphQLAPIHeaders)(session);
|
|
35
|
+
const response = await httpGraphQL_js_1.default.post("", {
|
|
36
|
+
query: (0, graphql_1.getSuggestedPricesStringQuery)({
|
|
37
|
+
notNullPriceList,
|
|
38
|
+
withItems,
|
|
39
|
+
withItemCategories,
|
|
40
|
+
onlyCurrent,
|
|
41
|
+
}),
|
|
42
|
+
}, { headers });
|
|
43
|
+
if (response.data.errors) {
|
|
44
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
45
|
+
}
|
|
46
|
+
return response?.data?.data?.suggested_prices ?? [];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.getSuggestedPrices = getSuggestedPrices;
|
|
50
|
+
/**
|
|
51
|
+
* createSuggestedPrice
|
|
52
|
+
* @param headers
|
|
53
|
+
* @param body
|
|
54
|
+
*/
|
|
55
|
+
async function createSuggestedPrice(headers, body) {
|
|
56
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
57
|
+
const response = await httpZauru_js_1.default.post(`/sales/suggested_prices.json`, { suggested_price: body }, { headers });
|
|
58
|
+
return response.data;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.createSuggestedPrice = createSuggestedPrice;
|
|
62
|
+
//No existe actualizar
|
|
63
|
+
// /**
|
|
64
|
+
// * updateSuggestedPrice
|
|
65
|
+
// * @param headers
|
|
66
|
+
// * @param body
|
|
67
|
+
// */
|
|
68
|
+
// export async function updateSuggestedPrice(
|
|
69
|
+
// headers: any,
|
|
70
|
+
// body: Partial<SuggestedPriceGraphQL>
|
|
71
|
+
// ): Promise<AxiosUtilsResponse<SuggestedPriceGraphQL>> {
|
|
72
|
+
// return handlePossibleAxiosErrors(async () => {
|
|
73
|
+
// const response = await httpZauru.patch<SuggestedPriceGraphQL>(
|
|
74
|
+
// `/sales/suggested_prices.json`,
|
|
75
|
+
// { suggested_price: body },
|
|
76
|
+
// { headers }
|
|
77
|
+
// );
|
|
78
|
+
// return response.data;
|
|
79
|
+
// });
|
|
80
|
+
// }
|
|
81
|
+
/**
|
|
82
|
+
* deleteSuggestedPrice
|
|
83
|
+
* @param headers
|
|
84
|
+
* @param body
|
|
85
|
+
*/
|
|
86
|
+
async function deleteSuggestedPrice(headers, id) {
|
|
87
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
88
|
+
await httpZauru_js_1.default.delete(`/sales/suggested_prices/${id}?destroy=true`, {
|
|
89
|
+
headers,
|
|
90
|
+
});
|
|
91
|
+
return true;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports.deleteSuggestedPrice = deleteSuggestedPrice;
|