@codemind.ec/medusa-plugin-invoice 1.0.3 → 1.0.4
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.
|
@@ -4,11 +4,11 @@ const adminSdk = require("@medusajs/admin-sdk");
|
|
|
4
4
|
const ui = require("@medusajs/ui");
|
|
5
5
|
const Medusa = require("@medusajs/js-sdk");
|
|
6
6
|
const react = require("react");
|
|
7
|
-
const icons = require("@medusajs/icons");
|
|
8
7
|
const reactQuery = require("@tanstack/react-query");
|
|
9
|
-
const reactRouterDom = require("react-router-dom");
|
|
10
8
|
const reactHookForm = require("react-hook-form");
|
|
11
9
|
const zod = require("@medusajs/framework/zod");
|
|
10
|
+
const reactRouterDom = require("react-router-dom");
|
|
11
|
+
const icons = require("@medusajs/icons");
|
|
12
12
|
const CodeMirror = require("@uiw/react-codemirror");
|
|
13
13
|
const langHtml = require("@codemirror/lang-html");
|
|
14
14
|
const themeOneDark = require("@codemirror/theme-one-dark");
|
|
@@ -72,82 +72,6 @@ const OrderInvoiceWidget = ({ data: order }) => {
|
|
|
72
72
|
adminSdk.defineWidgetConfig({
|
|
73
73
|
zone: "order.details.side.before"
|
|
74
74
|
});
|
|
75
|
-
const TYPE_LABELS = {
|
|
76
|
-
order_invoice: "Comprobante de Pedido",
|
|
77
|
-
quote_proforma: "Cotización Proforma"
|
|
78
|
-
};
|
|
79
|
-
const InvoiceTemplatesPage = () => {
|
|
80
|
-
const navigate = reactRouterDom.useNavigate();
|
|
81
|
-
const queryClient = reactQuery.useQueryClient();
|
|
82
|
-
const { data, isLoading } = reactQuery.useQuery({
|
|
83
|
-
queryFn: () => sdk.client.fetch("/admin/invoice-templates"),
|
|
84
|
-
queryKey: ["invoice-templates"]
|
|
85
|
-
});
|
|
86
|
-
const deleteMutation = reactQuery.useMutation({
|
|
87
|
-
mutationFn: (id) => sdk.client.fetch(`/admin/invoice-templates/${id}`, { method: "DELETE" }),
|
|
88
|
-
onSuccess: () => {
|
|
89
|
-
queryClient.invalidateQueries({ queryKey: ["invoice-templates"] });
|
|
90
|
-
ui.toast.success("Plantilla eliminada");
|
|
91
|
-
},
|
|
92
|
-
onError: () => {
|
|
93
|
-
ui.toast.error("No se pudo eliminar la plantilla");
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
const templates = (data == null ? void 0 : data.invoice_templates) ?? [];
|
|
97
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
|
|
98
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 24 }, children: [
|
|
99
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Plantillas de Documentos" }),
|
|
100
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 8 }, children: [
|
|
101
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/invoice-config"), children: "Configuración" }),
|
|
102
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: () => navigate("/invoice-templates/new"), children: "+ Nueva Plantilla" })
|
|
103
|
-
] })
|
|
104
|
-
] }),
|
|
105
|
-
isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", padding: 40 }, children: "Cargando..." }) : templates.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", padding: 40, color: "#6c757d" }, children: "No hay plantillas. Se crearán automáticamente al reiniciar el servidor." }) : /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { children: [
|
|
106
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
107
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Nombre" }),
|
|
108
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Slug" }),
|
|
109
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Tipo" }),
|
|
110
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Estado" }),
|
|
111
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Actualizado" }),
|
|
112
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { style: { textAlign: "right" }, children: "Acciones" })
|
|
113
|
-
] }) }),
|
|
114
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Body, { children: templates.map((tpl) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
115
|
-
ui.Table.Row,
|
|
116
|
-
{
|
|
117
|
-
onClick: () => navigate(`/invoice-templates/${tpl.id}`),
|
|
118
|
-
style: { cursor: "pointer" },
|
|
119
|
-
children: [
|
|
120
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: tpl.name }),
|
|
121
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx("code", { style: { fontSize: 12 }, children: tpl.slug }) }),
|
|
122
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: TYPE_LABELS[tpl.type] ?? tpl.type }),
|
|
123
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: tpl.is_default ? /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: "blue", children: "Por defecto" }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: "grey", children: "Personalizada" }) }),
|
|
124
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: new Date(tpl.updated_at).toLocaleDateString("es-ES") }),
|
|
125
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { style: { textAlign: "right" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
126
|
-
ui.Button,
|
|
127
|
-
{
|
|
128
|
-
variant: "danger",
|
|
129
|
-
size: "small",
|
|
130
|
-
disabled: tpl.is_default,
|
|
131
|
-
onClick: (e) => {
|
|
132
|
-
e.stopPropagation();
|
|
133
|
-
if (confirm("¿Eliminar esta plantilla?")) {
|
|
134
|
-
deleteMutation.mutate(tpl.id);
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
children: "Eliminar"
|
|
138
|
-
}
|
|
139
|
-
) })
|
|
140
|
-
]
|
|
141
|
-
},
|
|
142
|
-
tpl.id
|
|
143
|
-
)) })
|
|
144
|
-
] })
|
|
145
|
-
] });
|
|
146
|
-
};
|
|
147
|
-
const config$1 = adminSdk.defineRouteConfig({
|
|
148
|
-
label: "Plantillas PDF",
|
|
149
|
-
icon: icons.DocumentText
|
|
150
|
-
});
|
|
151
75
|
zod.z.object({
|
|
152
76
|
company_name: zod.z.string().optional(),
|
|
153
77
|
company_ruc: zod.z.string().optional(),
|
|
@@ -341,9 +265,85 @@ const InvoiceConfigPage = () => {
|
|
|
341
265
|
) })
|
|
342
266
|
] });
|
|
343
267
|
};
|
|
344
|
-
const config = adminSdk.defineRouteConfig({
|
|
268
|
+
const config$1 = adminSdk.defineRouteConfig({
|
|
345
269
|
label: "Comprobante de Pedido"
|
|
346
270
|
});
|
|
271
|
+
const TYPE_LABELS = {
|
|
272
|
+
order_invoice: "Comprobante de Pedido",
|
|
273
|
+
quote_proforma: "Cotización Proforma"
|
|
274
|
+
};
|
|
275
|
+
const InvoiceTemplatesPage = () => {
|
|
276
|
+
const navigate = reactRouterDom.useNavigate();
|
|
277
|
+
const queryClient = reactQuery.useQueryClient();
|
|
278
|
+
const { data, isLoading } = reactQuery.useQuery({
|
|
279
|
+
queryFn: () => sdk.client.fetch("/admin/invoice-templates"),
|
|
280
|
+
queryKey: ["invoice-templates"]
|
|
281
|
+
});
|
|
282
|
+
const deleteMutation = reactQuery.useMutation({
|
|
283
|
+
mutationFn: (id) => sdk.client.fetch(`/admin/invoice-templates/${id}`, { method: "DELETE" }),
|
|
284
|
+
onSuccess: () => {
|
|
285
|
+
queryClient.invalidateQueries({ queryKey: ["invoice-templates"] });
|
|
286
|
+
ui.toast.success("Plantilla eliminada");
|
|
287
|
+
},
|
|
288
|
+
onError: () => {
|
|
289
|
+
ui.toast.error("No se pudo eliminar la plantilla");
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
const templates = (data == null ? void 0 : data.invoice_templates) ?? [];
|
|
293
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
|
|
294
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 24 }, children: [
|
|
295
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Plantillas de Documentos" }),
|
|
296
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 8 }, children: [
|
|
297
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/invoice-config"), children: "Configuración" }),
|
|
298
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: () => navigate("/invoice-templates/new"), children: "+ Nueva Plantilla" })
|
|
299
|
+
] })
|
|
300
|
+
] }),
|
|
301
|
+
isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", padding: 40 }, children: "Cargando..." }) : templates.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", padding: 40, color: "#6c757d" }, children: "No hay plantillas. Se crearán automáticamente al reiniciar el servidor." }) : /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { children: [
|
|
302
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
303
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Nombre" }),
|
|
304
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Slug" }),
|
|
305
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Tipo" }),
|
|
306
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Estado" }),
|
|
307
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Actualizado" }),
|
|
308
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { style: { textAlign: "right" }, children: "Acciones" })
|
|
309
|
+
] }) }),
|
|
310
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Body, { children: templates.map((tpl) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
311
|
+
ui.Table.Row,
|
|
312
|
+
{
|
|
313
|
+
onClick: () => navigate(`/invoice-templates/${tpl.id}`),
|
|
314
|
+
style: { cursor: "pointer" },
|
|
315
|
+
children: [
|
|
316
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: tpl.name }),
|
|
317
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx("code", { style: { fontSize: 12 }, children: tpl.slug }) }),
|
|
318
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: TYPE_LABELS[tpl.type] ?? tpl.type }),
|
|
319
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: tpl.is_default ? /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: "blue", children: "Por defecto" }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: "grey", children: "Personalizada" }) }),
|
|
320
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: new Date(tpl.updated_at).toLocaleDateString("es-ES") }),
|
|
321
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { style: { textAlign: "right" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
322
|
+
ui.Button,
|
|
323
|
+
{
|
|
324
|
+
variant: "danger",
|
|
325
|
+
size: "small",
|
|
326
|
+
disabled: tpl.is_default,
|
|
327
|
+
onClick: (e) => {
|
|
328
|
+
e.stopPropagation();
|
|
329
|
+
if (confirm("¿Eliminar esta plantilla?")) {
|
|
330
|
+
deleteMutation.mutate(tpl.id);
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
children: "Eliminar"
|
|
334
|
+
}
|
|
335
|
+
) })
|
|
336
|
+
]
|
|
337
|
+
},
|
|
338
|
+
tpl.id
|
|
339
|
+
)) })
|
|
340
|
+
] })
|
|
341
|
+
] });
|
|
342
|
+
};
|
|
343
|
+
const config = adminSdk.defineRouteConfig({
|
|
344
|
+
label: "Plantillas PDF",
|
|
345
|
+
icon: icons.DocumentText
|
|
346
|
+
});
|
|
347
347
|
const NewTemplatePage = () => {
|
|
348
348
|
const navigate = reactRouterDom.useNavigate();
|
|
349
349
|
const [name, setName] = react.useState("");
|
|
@@ -743,14 +743,14 @@ const widgetModule = { widgets: [
|
|
|
743
743
|
] };
|
|
744
744
|
const routeModule = {
|
|
745
745
|
routes: [
|
|
746
|
-
{
|
|
747
|
-
Component: InvoiceTemplatesPage,
|
|
748
|
-
path: "/invoice-templates"
|
|
749
|
-
},
|
|
750
746
|
{
|
|
751
747
|
Component: InvoiceConfigPage,
|
|
752
748
|
path: "/invoice-config"
|
|
753
749
|
},
|
|
750
|
+
{
|
|
751
|
+
Component: InvoiceTemplatesPage,
|
|
752
|
+
path: "/invoice-templates"
|
|
753
|
+
},
|
|
754
754
|
{
|
|
755
755
|
Component: NewTemplatePage,
|
|
756
756
|
path: "/invoice-templates/new"
|
|
@@ -764,7 +764,7 @@ const routeModule = {
|
|
|
764
764
|
const menuItemModule = {
|
|
765
765
|
menuItems: [
|
|
766
766
|
{
|
|
767
|
-
label: config.label,
|
|
767
|
+
label: config$1.label,
|
|
768
768
|
icon: void 0,
|
|
769
769
|
path: "/invoice-config",
|
|
770
770
|
nested: void 0,
|
|
@@ -772,8 +772,8 @@ const menuItemModule = {
|
|
|
772
772
|
translationNs: void 0
|
|
773
773
|
},
|
|
774
774
|
{
|
|
775
|
-
label: config
|
|
776
|
-
icon: config
|
|
775
|
+
label: config.label,
|
|
776
|
+
icon: config.icon,
|
|
777
777
|
path: "/invoice-templates",
|
|
778
778
|
nested: void 0,
|
|
779
779
|
rank: void 0,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
|
|
3
|
-
import { Container, Heading, Text, Button, toast,
|
|
3
|
+
import { Container, Heading, Text, Button, toast, Label, Input, Textarea, Table, Badge, Select } from "@medusajs/ui";
|
|
4
4
|
import Medusa from "@medusajs/js-sdk";
|
|
5
5
|
import { useState, useCallback, useEffect, useRef, useMemo } from "react";
|
|
6
|
-
import {
|
|
7
|
-
import { useQueryClient, useQuery, useMutation } from "@tanstack/react-query";
|
|
8
|
-
import { useNavigate, useParams } from "react-router-dom";
|
|
6
|
+
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
9
7
|
import { useForm, FormProvider, Controller } from "react-hook-form";
|
|
10
8
|
import { z } from "@medusajs/framework/zod";
|
|
9
|
+
import { useNavigate, useParams } from "react-router-dom";
|
|
10
|
+
import { DocumentText } from "@medusajs/icons";
|
|
11
11
|
import CodeMirror from "@uiw/react-codemirror";
|
|
12
12
|
import { html } from "@codemirror/lang-html";
|
|
13
13
|
import { oneDark } from "@codemirror/theme-one-dark";
|
|
@@ -67,82 +67,6 @@ const OrderInvoiceWidget = ({ data: order }) => {
|
|
|
67
67
|
defineWidgetConfig({
|
|
68
68
|
zone: "order.details.side.before"
|
|
69
69
|
});
|
|
70
|
-
const TYPE_LABELS = {
|
|
71
|
-
order_invoice: "Comprobante de Pedido",
|
|
72
|
-
quote_proforma: "Cotización Proforma"
|
|
73
|
-
};
|
|
74
|
-
const InvoiceTemplatesPage = () => {
|
|
75
|
-
const navigate = useNavigate();
|
|
76
|
-
const queryClient = useQueryClient();
|
|
77
|
-
const { data, isLoading } = useQuery({
|
|
78
|
-
queryFn: () => sdk.client.fetch("/admin/invoice-templates"),
|
|
79
|
-
queryKey: ["invoice-templates"]
|
|
80
|
-
});
|
|
81
|
-
const deleteMutation = useMutation({
|
|
82
|
-
mutationFn: (id) => sdk.client.fetch(`/admin/invoice-templates/${id}`, { method: "DELETE" }),
|
|
83
|
-
onSuccess: () => {
|
|
84
|
-
queryClient.invalidateQueries({ queryKey: ["invoice-templates"] });
|
|
85
|
-
toast.success("Plantilla eliminada");
|
|
86
|
-
},
|
|
87
|
-
onError: () => {
|
|
88
|
-
toast.error("No se pudo eliminar la plantilla");
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
const templates = (data == null ? void 0 : data.invoice_templates) ?? [];
|
|
92
|
-
return /* @__PURE__ */ jsxs(Container, { children: [
|
|
93
|
-
/* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 24 }, children: [
|
|
94
|
-
/* @__PURE__ */ jsx(Heading, { level: "h1", children: "Plantillas de Documentos" }),
|
|
95
|
-
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 8 }, children: [
|
|
96
|
-
/* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/invoice-config"), children: "Configuración" }),
|
|
97
|
-
/* @__PURE__ */ jsx(Button, { onClick: () => navigate("/invoice-templates/new"), children: "+ Nueva Plantilla" })
|
|
98
|
-
] })
|
|
99
|
-
] }),
|
|
100
|
-
isLoading ? /* @__PURE__ */ jsx("div", { style: { textAlign: "center", padding: 40 }, children: "Cargando..." }) : templates.length === 0 ? /* @__PURE__ */ jsx("div", { style: { textAlign: "center", padding: 40, color: "#6c757d" }, children: "No hay plantillas. Se crearán automáticamente al reiniciar el servidor." }) : /* @__PURE__ */ jsxs(Table, { children: [
|
|
101
|
-
/* @__PURE__ */ jsx(Table.Header, { children: /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
102
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Nombre" }),
|
|
103
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Slug" }),
|
|
104
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Tipo" }),
|
|
105
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Estado" }),
|
|
106
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Actualizado" }),
|
|
107
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { style: { textAlign: "right" }, children: "Acciones" })
|
|
108
|
-
] }) }),
|
|
109
|
-
/* @__PURE__ */ jsx(Table.Body, { children: templates.map((tpl) => /* @__PURE__ */ jsxs(
|
|
110
|
-
Table.Row,
|
|
111
|
-
{
|
|
112
|
-
onClick: () => navigate(`/invoice-templates/${tpl.id}`),
|
|
113
|
-
style: { cursor: "pointer" },
|
|
114
|
-
children: [
|
|
115
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: tpl.name }),
|
|
116
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx("code", { style: { fontSize: 12 }, children: tpl.slug }) }),
|
|
117
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: TYPE_LABELS[tpl.type] ?? tpl.type }),
|
|
118
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: tpl.is_default ? /* @__PURE__ */ jsx(Badge, { color: "blue", children: "Por defecto" }) : /* @__PURE__ */ jsx(Badge, { color: "grey", children: "Personalizada" }) }),
|
|
119
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: new Date(tpl.updated_at).toLocaleDateString("es-ES") }),
|
|
120
|
-
/* @__PURE__ */ jsx(Table.Cell, { style: { textAlign: "right" }, children: /* @__PURE__ */ jsx(
|
|
121
|
-
Button,
|
|
122
|
-
{
|
|
123
|
-
variant: "danger",
|
|
124
|
-
size: "small",
|
|
125
|
-
disabled: tpl.is_default,
|
|
126
|
-
onClick: (e) => {
|
|
127
|
-
e.stopPropagation();
|
|
128
|
-
if (confirm("¿Eliminar esta plantilla?")) {
|
|
129
|
-
deleteMutation.mutate(tpl.id);
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
children: "Eliminar"
|
|
133
|
-
}
|
|
134
|
-
) })
|
|
135
|
-
]
|
|
136
|
-
},
|
|
137
|
-
tpl.id
|
|
138
|
-
)) })
|
|
139
|
-
] })
|
|
140
|
-
] });
|
|
141
|
-
};
|
|
142
|
-
const config$1 = defineRouteConfig({
|
|
143
|
-
label: "Plantillas PDF",
|
|
144
|
-
icon: DocumentText
|
|
145
|
-
});
|
|
146
70
|
z.object({
|
|
147
71
|
company_name: z.string().optional(),
|
|
148
72
|
company_ruc: z.string().optional(),
|
|
@@ -336,9 +260,85 @@ const InvoiceConfigPage = () => {
|
|
|
336
260
|
) })
|
|
337
261
|
] });
|
|
338
262
|
};
|
|
339
|
-
const config = defineRouteConfig({
|
|
263
|
+
const config$1 = defineRouteConfig({
|
|
340
264
|
label: "Comprobante de Pedido"
|
|
341
265
|
});
|
|
266
|
+
const TYPE_LABELS = {
|
|
267
|
+
order_invoice: "Comprobante de Pedido",
|
|
268
|
+
quote_proforma: "Cotización Proforma"
|
|
269
|
+
};
|
|
270
|
+
const InvoiceTemplatesPage = () => {
|
|
271
|
+
const navigate = useNavigate();
|
|
272
|
+
const queryClient = useQueryClient();
|
|
273
|
+
const { data, isLoading } = useQuery({
|
|
274
|
+
queryFn: () => sdk.client.fetch("/admin/invoice-templates"),
|
|
275
|
+
queryKey: ["invoice-templates"]
|
|
276
|
+
});
|
|
277
|
+
const deleteMutation = useMutation({
|
|
278
|
+
mutationFn: (id) => sdk.client.fetch(`/admin/invoice-templates/${id}`, { method: "DELETE" }),
|
|
279
|
+
onSuccess: () => {
|
|
280
|
+
queryClient.invalidateQueries({ queryKey: ["invoice-templates"] });
|
|
281
|
+
toast.success("Plantilla eliminada");
|
|
282
|
+
},
|
|
283
|
+
onError: () => {
|
|
284
|
+
toast.error("No se pudo eliminar la plantilla");
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
const templates = (data == null ? void 0 : data.invoice_templates) ?? [];
|
|
288
|
+
return /* @__PURE__ */ jsxs(Container, { children: [
|
|
289
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 24 }, children: [
|
|
290
|
+
/* @__PURE__ */ jsx(Heading, { level: "h1", children: "Plantillas de Documentos" }),
|
|
291
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 8 }, children: [
|
|
292
|
+
/* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/invoice-config"), children: "Configuración" }),
|
|
293
|
+
/* @__PURE__ */ jsx(Button, { onClick: () => navigate("/invoice-templates/new"), children: "+ Nueva Plantilla" })
|
|
294
|
+
] })
|
|
295
|
+
] }),
|
|
296
|
+
isLoading ? /* @__PURE__ */ jsx("div", { style: { textAlign: "center", padding: 40 }, children: "Cargando..." }) : templates.length === 0 ? /* @__PURE__ */ jsx("div", { style: { textAlign: "center", padding: 40, color: "#6c757d" }, children: "No hay plantillas. Se crearán automáticamente al reiniciar el servidor." }) : /* @__PURE__ */ jsxs(Table, { children: [
|
|
297
|
+
/* @__PURE__ */ jsx(Table.Header, { children: /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
298
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Nombre" }),
|
|
299
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Slug" }),
|
|
300
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Tipo" }),
|
|
301
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Estado" }),
|
|
302
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Actualizado" }),
|
|
303
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { style: { textAlign: "right" }, children: "Acciones" })
|
|
304
|
+
] }) }),
|
|
305
|
+
/* @__PURE__ */ jsx(Table.Body, { children: templates.map((tpl) => /* @__PURE__ */ jsxs(
|
|
306
|
+
Table.Row,
|
|
307
|
+
{
|
|
308
|
+
onClick: () => navigate(`/invoice-templates/${tpl.id}`),
|
|
309
|
+
style: { cursor: "pointer" },
|
|
310
|
+
children: [
|
|
311
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: tpl.name }),
|
|
312
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx("code", { style: { fontSize: 12 }, children: tpl.slug }) }),
|
|
313
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: TYPE_LABELS[tpl.type] ?? tpl.type }),
|
|
314
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: tpl.is_default ? /* @__PURE__ */ jsx(Badge, { color: "blue", children: "Por defecto" }) : /* @__PURE__ */ jsx(Badge, { color: "grey", children: "Personalizada" }) }),
|
|
315
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: new Date(tpl.updated_at).toLocaleDateString("es-ES") }),
|
|
316
|
+
/* @__PURE__ */ jsx(Table.Cell, { style: { textAlign: "right" }, children: /* @__PURE__ */ jsx(
|
|
317
|
+
Button,
|
|
318
|
+
{
|
|
319
|
+
variant: "danger",
|
|
320
|
+
size: "small",
|
|
321
|
+
disabled: tpl.is_default,
|
|
322
|
+
onClick: (e) => {
|
|
323
|
+
e.stopPropagation();
|
|
324
|
+
if (confirm("¿Eliminar esta plantilla?")) {
|
|
325
|
+
deleteMutation.mutate(tpl.id);
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
children: "Eliminar"
|
|
329
|
+
}
|
|
330
|
+
) })
|
|
331
|
+
]
|
|
332
|
+
},
|
|
333
|
+
tpl.id
|
|
334
|
+
)) })
|
|
335
|
+
] })
|
|
336
|
+
] });
|
|
337
|
+
};
|
|
338
|
+
const config = defineRouteConfig({
|
|
339
|
+
label: "Plantillas PDF",
|
|
340
|
+
icon: DocumentText
|
|
341
|
+
});
|
|
342
342
|
const NewTemplatePage = () => {
|
|
343
343
|
const navigate = useNavigate();
|
|
344
344
|
const [name, setName] = useState("");
|
|
@@ -738,14 +738,14 @@ const widgetModule = { widgets: [
|
|
|
738
738
|
] };
|
|
739
739
|
const routeModule = {
|
|
740
740
|
routes: [
|
|
741
|
-
{
|
|
742
|
-
Component: InvoiceTemplatesPage,
|
|
743
|
-
path: "/invoice-templates"
|
|
744
|
-
},
|
|
745
741
|
{
|
|
746
742
|
Component: InvoiceConfigPage,
|
|
747
743
|
path: "/invoice-config"
|
|
748
744
|
},
|
|
745
|
+
{
|
|
746
|
+
Component: InvoiceTemplatesPage,
|
|
747
|
+
path: "/invoice-templates"
|
|
748
|
+
},
|
|
749
749
|
{
|
|
750
750
|
Component: NewTemplatePage,
|
|
751
751
|
path: "/invoice-templates/new"
|
|
@@ -759,7 +759,7 @@ const routeModule = {
|
|
|
759
759
|
const menuItemModule = {
|
|
760
760
|
menuItems: [
|
|
761
761
|
{
|
|
762
|
-
label: config.label,
|
|
762
|
+
label: config$1.label,
|
|
763
763
|
icon: void 0,
|
|
764
764
|
path: "/invoice-config",
|
|
765
765
|
nested: void 0,
|
|
@@ -767,8 +767,8 @@ const menuItemModule = {
|
|
|
767
767
|
translationNs: void 0
|
|
768
768
|
},
|
|
769
769
|
{
|
|
770
|
-
label: config
|
|
771
|
-
icon: config
|
|
770
|
+
label: config.label,
|
|
771
|
+
icon: config.icon,
|
|
772
772
|
path: "/invoice-templates",
|
|
773
773
|
nested: void 0,
|
|
774
774
|
rank: void 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemind.ec/medusa-plugin-invoice",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Invoice & quotation PDF widget for Medusa v2 admin — download order receipts and manage company billing config.",
|
|
5
5
|
"author": "Kollor <dev@codemind.ec> (https://codemind.ec)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,8 +44,6 @@
|
|
|
44
44
|
"prepublishOnly": "medusa plugin:build"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@codemirror/lang-html": "^6.4.11",
|
|
48
|
-
"@codemirror/theme-one-dark": "^6.1.3",
|
|
49
47
|
"@medusajs/admin-sdk": "2.13.3",
|
|
50
48
|
"@medusajs/admin-shared": "2.13.3",
|
|
51
49
|
"@medusajs/cli": "2.13.3",
|
|
@@ -62,7 +60,6 @@
|
|
|
62
60
|
"@types/pdfmake": "^0.2.11",
|
|
63
61
|
"@types/react": "^18.3.3",
|
|
64
62
|
"@types/react-dom": "^18.3.0",
|
|
65
|
-
"@uiw/react-codemirror": "^4.25.8",
|
|
66
63
|
"handlebars": "^4.7.8",
|
|
67
64
|
"prop-types": "^15.8.1",
|
|
68
65
|
"react": "^18.3.1",
|
|
@@ -73,6 +70,9 @@
|
|
|
73
70
|
"vite": "^5.4.14"
|
|
74
71
|
},
|
|
75
72
|
"dependencies": {
|
|
73
|
+
"@codemirror/lang-html": "^6.4.11",
|
|
74
|
+
"@codemirror/theme-one-dark": "^6.1.3",
|
|
75
|
+
"@uiw/react-codemirror": "^4.25.8",
|
|
76
76
|
"axios": "^1.7.7",
|
|
77
77
|
"html-to-pdfmake": "^2.5.33",
|
|
78
78
|
"jsdom": "^29.0.1",
|