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