@codemind.ec/medusa-plugin-invoice 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -315,31 +315,42 @@ const config = adminSdk.defineRouteConfig({
315
315
  label: "Plantillas PDF",
316
316
  icon: icons.DocumentText
317
317
  });
318
- const NewCompanyPage = () => {
318
+ const EditCompanyPage = () => {
319
+ const { id } = reactRouterDom.useParams();
319
320
  const navigate = reactRouterDom.useNavigate();
320
- const form = reactHookForm.useForm({
321
- defaultValues: {
322
- company_name: "",
323
- company_ruc: "",
324
- company_address: "",
325
- company_phone: "",
326
- company_email: "",
327
- company_logo: "",
328
- notes: "",
329
- admin_notification_email: "",
330
- is_default: false
331
- }
321
+ const queryClient = reactQuery.useQueryClient();
322
+ const { data, isLoading } = reactQuery.useQuery({
323
+ queryFn: () => sdk.client.fetch(`/admin/invoice-config/${id}`),
324
+ queryKey: ["invoice-config", id],
325
+ enabled: !!id
332
326
  });
333
- const createMutation = reactQuery.useMutation({
334
- mutationFn: (payload) => sdk.client.fetch("/admin/invoice-config", {
327
+ const config2 = data == null ? void 0 : data.invoice_config;
328
+ const getDefaults = react.useCallback(() => ({
329
+ company_name: (config2 == null ? void 0 : config2.company_name) || "",
330
+ company_ruc: (config2 == null ? void 0 : config2.company_ruc) || "",
331
+ company_address: (config2 == null ? void 0 : config2.company_address) || "",
332
+ company_phone: (config2 == null ? void 0 : config2.company_phone) || "",
333
+ company_email: (config2 == null ? void 0 : config2.company_email) || "",
334
+ company_logo: (config2 == null ? void 0 : config2.company_logo) || "",
335
+ notes: (config2 == null ? void 0 : config2.notes) || "",
336
+ admin_notification_email: (config2 == null ? void 0 : config2.admin_notification_email) || "",
337
+ is_default: (config2 == null ? void 0 : config2.is_default) || false
338
+ }), [config2]);
339
+ const form = reactHookForm.useForm({ defaultValues: getDefaults() });
340
+ react.useEffect(() => {
341
+ form.reset(getDefaults());
342
+ }, [getDefaults]);
343
+ const saveMutation = reactQuery.useMutation({
344
+ mutationFn: (payload) => sdk.client.fetch(`/admin/invoice-config/${id}`, {
335
345
  method: "POST",
336
346
  body: payload
337
347
  }),
338
348
  onSuccess: () => {
339
- ui.toast.success("Empresa creada exitosamente");
340
- navigate("/invoice-config/companies");
349
+ queryClient.invalidateQueries({ queryKey: ["invoice-config", id] });
350
+ queryClient.invalidateQueries({ queryKey: ["invoice-configs"] });
351
+ ui.toast.success("Empresa actualizada");
341
352
  },
342
- onError: () => ui.toast.error("Error al crear la empresa")
353
+ onError: () => ui.toast.error("Error al guardar")
343
354
  });
344
355
  const uploadLogo = async (event) => {
345
356
  var _a;
@@ -352,10 +363,16 @@ const NewCompanyPage = () => {
352
363
  ui.toast.error("Error al subir el logo.");
353
364
  }
354
365
  };
355
- const handleSubmit = form.handleSubmit((data) => createMutation.mutate(data));
366
+ const handleSubmit = form.handleSubmit((data2) => saveMutation.mutate(data2));
367
+ if (isLoading) {
368
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center py-10", children: "Cargando..." }) });
369
+ }
370
+ if (!config2) {
371
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center py-10", children: "Empresa no encontrada" }) });
372
+ }
356
373
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
357
374
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
358
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Nueva Empresa" }),
375
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Editar Empresa" }),
359
376
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/invoice-config/companies"), children: "← Volver" })
360
377
  ] }),
361
378
  /* @__PURE__ */ jsxRuntime.jsx(reactHookForm.FormProvider, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, className: "flex flex-col gap-4 p-6 max-w-2xl", children: [
@@ -378,7 +395,7 @@ const NewCompanyPage = () => {
378
395
  name: "company_name",
379
396
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
380
397
  /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", children: "Nombre de la Empresa *" }),
381
- /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, placeholder: "Mi Empresa S.A.S." })
398
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field })
382
399
  ] })
383
400
  }
384
401
  ),
@@ -400,7 +417,7 @@ const NewCompanyPage = () => {
400
417
  name: "company_address",
401
418
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
402
419
  /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", children: "Dirección" }),
403
- /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field, placeholder: "Av. Principal 123, Quito" })
420
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field })
404
421
  ] })
405
422
  }
406
423
  ),
@@ -412,7 +429,7 @@ const NewCompanyPage = () => {
412
429
  name: "company_phone",
413
430
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
414
431
  /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", children: "Teléfono" }),
415
- /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, placeholder: "+593 99 123 4567" })
432
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field })
416
433
  ] })
417
434
  }
418
435
  ),
@@ -423,7 +440,7 @@ const NewCompanyPage = () => {
423
440
  name: "company_email",
424
441
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
425
442
  /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", children: "Email de la Empresa" }),
426
- /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, placeholder: "info@empresa.com" })
443
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field })
427
444
  ] })
428
445
  }
429
446
  )
@@ -435,7 +452,7 @@ const NewCompanyPage = () => {
435
452
  name: "notes",
436
453
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
437
454
  /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", children: "Notas" }),
438
- /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field, placeholder: "Notas internas o pie de página del documento" })
455
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field })
439
456
  ] })
440
457
  }
441
458
  ),
@@ -473,47 +490,36 @@ const NewCompanyPage = () => {
473
490
  ),
474
491
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2 pt-2", children: [
475
492
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/invoice-config/companies"), children: "Cancelar" }),
476
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { type: "submit", isLoading: createMutation.isPending, children: "Crear Empresa" })
493
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { type: "submit", isLoading: saveMutation.isPending, children: "Guardar Cambios" })
477
494
  ] })
478
495
  ] }) })
479
496
  ] });
480
497
  };
481
- const EditCompanyPage = () => {
482
- const { id } = reactRouterDom.useParams();
498
+ const NewCompanyPage = () => {
483
499
  const navigate = reactRouterDom.useNavigate();
484
- const queryClient = reactQuery.useQueryClient();
485
- const { data, isLoading } = reactQuery.useQuery({
486
- queryFn: () => sdk.client.fetch(`/admin/invoice-config/${id}`),
487
- queryKey: ["invoice-config", id],
488
- enabled: !!id
500
+ const form = reactHookForm.useForm({
501
+ defaultValues: {
502
+ company_name: "",
503
+ company_ruc: "",
504
+ company_address: "",
505
+ company_phone: "",
506
+ company_email: "",
507
+ company_logo: "",
508
+ notes: "",
509
+ admin_notification_email: "",
510
+ is_default: false
511
+ }
489
512
  });
490
- const config2 = data == null ? void 0 : data.invoice_config;
491
- const getDefaults = react.useCallback(() => ({
492
- company_name: (config2 == null ? void 0 : config2.company_name) || "",
493
- company_ruc: (config2 == null ? void 0 : config2.company_ruc) || "",
494
- company_address: (config2 == null ? void 0 : config2.company_address) || "",
495
- company_phone: (config2 == null ? void 0 : config2.company_phone) || "",
496
- company_email: (config2 == null ? void 0 : config2.company_email) || "",
497
- company_logo: (config2 == null ? void 0 : config2.company_logo) || "",
498
- notes: (config2 == null ? void 0 : config2.notes) || "",
499
- admin_notification_email: (config2 == null ? void 0 : config2.admin_notification_email) || "",
500
- is_default: (config2 == null ? void 0 : config2.is_default) || false
501
- }), [config2]);
502
- const form = reactHookForm.useForm({ defaultValues: getDefaults() });
503
- react.useEffect(() => {
504
- form.reset(getDefaults());
505
- }, [getDefaults]);
506
- const saveMutation = reactQuery.useMutation({
507
- mutationFn: (payload) => sdk.client.fetch(`/admin/invoice-config/${id}`, {
513
+ const createMutation = reactQuery.useMutation({
514
+ mutationFn: (payload) => sdk.client.fetch("/admin/invoice-config", {
508
515
  method: "POST",
509
516
  body: payload
510
517
  }),
511
518
  onSuccess: () => {
512
- queryClient.invalidateQueries({ queryKey: ["invoice-config", id] });
513
- queryClient.invalidateQueries({ queryKey: ["invoice-configs"] });
514
- ui.toast.success("Empresa actualizada");
519
+ ui.toast.success("Empresa creada exitosamente");
520
+ navigate("/invoice-config/companies");
515
521
  },
516
- onError: () => ui.toast.error("Error al guardar")
522
+ onError: () => ui.toast.error("Error al crear la empresa")
517
523
  });
518
524
  const uploadLogo = async (event) => {
519
525
  var _a;
@@ -526,16 +532,10 @@ const EditCompanyPage = () => {
526
532
  ui.toast.error("Error al subir el logo.");
527
533
  }
528
534
  };
529
- const handleSubmit = form.handleSubmit((data2) => saveMutation.mutate(data2));
530
- if (isLoading) {
531
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center py-10", children: "Cargando..." }) });
532
- }
533
- if (!config2) {
534
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center py-10", children: "Empresa no encontrada" }) });
535
- }
535
+ const handleSubmit = form.handleSubmit((data) => createMutation.mutate(data));
536
536
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
537
537
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
538
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Editar Empresa" }),
538
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Nueva Empresa" }),
539
539
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/invoice-config/companies"), children: "← Volver" })
540
540
  ] }),
541
541
  /* @__PURE__ */ jsxRuntime.jsx(reactHookForm.FormProvider, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, className: "flex flex-col gap-4 p-6 max-w-2xl", children: [
@@ -558,7 +558,7 @@ const EditCompanyPage = () => {
558
558
  name: "company_name",
559
559
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
560
560
  /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", children: "Nombre de la Empresa *" }),
561
- /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field })
561
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, placeholder: "Mi Empresa S.A.S." })
562
562
  ] })
563
563
  }
564
564
  ),
@@ -580,7 +580,7 @@ const EditCompanyPage = () => {
580
580
  name: "company_address",
581
581
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
582
582
  /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", children: "Dirección" }),
583
- /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field })
583
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field, placeholder: "Av. Principal 123, Quito" })
584
584
  ] })
585
585
  }
586
586
  ),
@@ -592,7 +592,7 @@ const EditCompanyPage = () => {
592
592
  name: "company_phone",
593
593
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
594
594
  /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", children: "Teléfono" }),
595
- /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field })
595
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, placeholder: "+593 99 123 4567" })
596
596
  ] })
597
597
  }
598
598
  ),
@@ -603,7 +603,7 @@ const EditCompanyPage = () => {
603
603
  name: "company_email",
604
604
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
605
605
  /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", children: "Email de la Empresa" }),
606
- /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field })
606
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, placeholder: "info@empresa.com" })
607
607
  ] })
608
608
  }
609
609
  )
@@ -615,7 +615,7 @@ const EditCompanyPage = () => {
615
615
  name: "notes",
616
616
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
617
617
  /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", children: "Notas" }),
618
- /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field })
618
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field, placeholder: "Notas internas o pie de página del documento" })
619
619
  ] })
620
620
  }
621
621
  ),
@@ -653,23 +653,114 @@ const EditCompanyPage = () => {
653
653
  ),
654
654
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2 pt-2", children: [
655
655
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/invoice-config/companies"), children: "Cancelar" }),
656
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { type: "submit", isLoading: saveMutation.isPending, children: "Guardar Cambios" })
656
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { type: "submit", isLoading: createMutation.isPending, children: "Crear Empresa" })
657
657
  ] })
658
658
  ] }) })
659
659
  ] });
660
660
  };
661
+ const NewTemplatePage = () => {
662
+ const navigate = reactRouterDom.useNavigate();
663
+ const [name, setName] = react.useState("");
664
+ const [slug, setSlug] = react.useState("");
665
+ const [type, setType] = react.useState("order_invoice");
666
+ const createMutation = reactQuery.useMutation({
667
+ mutationFn: (payload) => sdk.client.fetch("/admin/invoice-templates", {
668
+ method: "POST",
669
+ body: payload
670
+ }),
671
+ onSuccess: (data) => {
672
+ ui.toast.success("Plantilla creada");
673
+ navigate(`/invoice-config/invoice-templates/${data.invoice_template.id}`);
674
+ },
675
+ onError: () => {
676
+ ui.toast.error("Error al crear la plantilla");
677
+ }
678
+ });
679
+ const handleCreate = () => {
680
+ if (!name || !slug) {
681
+ ui.toast.error("Nombre y slug son requeridos");
682
+ return;
683
+ }
684
+ createMutation.mutate({
685
+ name,
686
+ slug,
687
+ type,
688
+ html_content: getDefaultHtml(type)
689
+ });
690
+ };
691
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
692
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", style: { marginBottom: 24 }, children: "Nueva Plantilla" }),
693
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 16, maxWidth: 500 }, children: [
694
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
695
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "name", children: "Nombre" }),
696
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { id: "name", value: name, onChange: (e) => setName(e.target.value), placeholder: "Ej: Mi Comprobante" })
697
+ ] }),
698
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
699
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "slug", children: "Slug (identificador único)" }),
700
+ /* @__PURE__ */ jsxRuntime.jsx(
701
+ ui.Input,
702
+ {
703
+ id: "slug",
704
+ value: slug,
705
+ onChange: (e) => setSlug(e.target.value.toLowerCase().replace(/[^a-z0-9_]/g, "_")),
706
+ placeholder: "Ej: my_custom_invoice"
707
+ }
708
+ )
709
+ ] }),
710
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
711
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "type", children: "Tipo de documento" }),
712
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { value: type, onValueChange: setType, children: [
713
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Seleccionar tipo" }) }),
714
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
715
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "order_invoice", children: "Comprobante de Pedido" }),
716
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "quote_proforma", children: "Cotización Proforma" })
717
+ ] })
718
+ ] })
719
+ ] }),
720
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 8, marginTop: 16 }, children: [
721
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/invoice-config/invoice-templates"), children: "Cancelar" }),
722
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: handleCreate, isLoading: createMutation.isPending, children: "Crear Plantilla" })
723
+ ] })
724
+ ] })
725
+ ] });
726
+ };
727
+ function getDefaultHtml(type) {
728
+ if (type === "quote_proforma") {
729
+ return `<!DOCTYPE html>
730
+ <html>
731
+ <head><style>body { font-family: Helvetica, sans-serif; }</style></head>
732
+ <body>
733
+ <h1>COTIZACIÓN {{quote_number}}</h1>
734
+ <p>Fecha: {{date_str}}</p>
735
+ <p>Servicio: {{service_name}}</p>
736
+ <!-- Personaliza tu plantilla aquí -->
737
+ </body>
738
+ </html>`;
739
+ }
740
+ return `<!DOCTYPE html>
741
+ <html>
742
+ <head><style>body { font-family: Helvetica, sans-serif; }</style></head>
743
+ <body>
744
+ <h1>COMPROBANTE {{invoice_id}}</h1>
745
+ <p>Fecha: {{invoice_date}}</p>
746
+ <p>Empresa: {{company_name}}</p>
747
+ <!-- Personaliza tu plantilla aquí -->
748
+ </body>
749
+ </html>`;
750
+ }
751
+ const COMPANY_VARIABLES = [
752
+ { name: "company_name" },
753
+ { name: "company_ruc" },
754
+ { name: "company_address" },
755
+ { name: "company_phone" },
756
+ { name: "company_email" },
757
+ { name: "company_logo_base64" }
758
+ ];
661
759
  const ORDER_INVOICE_CATEGORIES = [
662
760
  {
663
761
  label: "Empresa",
664
762
  icon: "🏢",
665
- variables: [
666
- { name: "company_name" },
667
- { name: "company_ruc" },
668
- { name: "company_address" },
669
- { name: "company_phone" },
670
- { name: "company_email" },
671
- { name: "company_logo_base64" }
672
- ]
763
+ variables: COMPANY_VARIABLES
673
764
  },
674
765
  {
675
766
  label: "Documento",
@@ -727,10 +818,7 @@ const QUOTE_PROFORMA_CATEGORIES = [
727
818
  {
728
819
  label: "Empresa",
729
820
  icon: "🏢",
730
- variables: [
731
- { name: "company_name" },
732
- { name: "company_website" }
733
- ]
821
+ variables: [...COMPANY_VARIABLES, { name: "company_website" }]
734
822
  },
735
823
  {
736
824
  label: "Documento",
@@ -822,6 +910,11 @@ const SAMPLE_DATA = {
822
910
  },
823
911
  quote_proforma: {
824
912
  company_name: "Mi Empresa",
913
+ company_ruc: "1234567890001",
914
+ company_address: "Av. Principal 123, Quito",
915
+ company_phone: "+593 99 123 4567",
916
+ company_email: "info@miempresa.com",
917
+ company_logo_base64: PLACEHOLDER_LOGO_BASE64,
825
918
  company_website: "www.miempresa.com",
826
919
  quote_number: "QP-2025-0001",
827
920
  date_str: "19/06/2025",
@@ -1060,96 +1153,6 @@ const TemplateEditorPage = () => {
1060
1153
  ] })
1061
1154
  ] });
1062
1155
  };
1063
- const NewTemplatePage = () => {
1064
- const navigate = reactRouterDom.useNavigate();
1065
- const [name, setName] = react.useState("");
1066
- const [slug, setSlug] = react.useState("");
1067
- const [type, setType] = react.useState("order_invoice");
1068
- const createMutation = reactQuery.useMutation({
1069
- mutationFn: (payload) => sdk.client.fetch("/admin/invoice-templates", {
1070
- method: "POST",
1071
- body: payload
1072
- }),
1073
- onSuccess: (data) => {
1074
- ui.toast.success("Plantilla creada");
1075
- navigate(`/invoice-config/invoice-templates/${data.invoice_template.id}`);
1076
- },
1077
- onError: () => {
1078
- ui.toast.error("Error al crear la plantilla");
1079
- }
1080
- });
1081
- const handleCreate = () => {
1082
- if (!name || !slug) {
1083
- ui.toast.error("Nombre y slug son requeridos");
1084
- return;
1085
- }
1086
- createMutation.mutate({
1087
- name,
1088
- slug,
1089
- type,
1090
- html_content: getDefaultHtml(type)
1091
- });
1092
- };
1093
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
1094
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", style: { marginBottom: 24 }, children: "Nueva Plantilla" }),
1095
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 16, maxWidth: 500 }, children: [
1096
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1097
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "name", children: "Nombre" }),
1098
- /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { id: "name", value: name, onChange: (e) => setName(e.target.value), placeholder: "Ej: Mi Comprobante" })
1099
- ] }),
1100
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1101
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "slug", children: "Slug (identificador único)" }),
1102
- /* @__PURE__ */ jsxRuntime.jsx(
1103
- ui.Input,
1104
- {
1105
- id: "slug",
1106
- value: slug,
1107
- onChange: (e) => setSlug(e.target.value.toLowerCase().replace(/[^a-z0-9_]/g, "_")),
1108
- placeholder: "Ej: my_custom_invoice"
1109
- }
1110
- )
1111
- ] }),
1112
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1113
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "type", children: "Tipo de documento" }),
1114
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { value: type, onValueChange: setType, children: [
1115
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Seleccionar tipo" }) }),
1116
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
1117
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "order_invoice", children: "Comprobante de Pedido" }),
1118
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "quote_proforma", children: "Cotización Proforma" })
1119
- ] })
1120
- ] })
1121
- ] }),
1122
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 8, marginTop: 16 }, children: [
1123
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/invoice-config/invoice-templates"), children: "Cancelar" }),
1124
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: handleCreate, isLoading: createMutation.isPending, children: "Crear Plantilla" })
1125
- ] })
1126
- ] })
1127
- ] });
1128
- };
1129
- function getDefaultHtml(type) {
1130
- if (type === "quote_proforma") {
1131
- return `<!DOCTYPE html>
1132
- <html>
1133
- <head><style>body { font-family: Helvetica, sans-serif; }</style></head>
1134
- <body>
1135
- <h1>COTIZACIÓN {{quote_number}}</h1>
1136
- <p>Fecha: {{date_str}}</p>
1137
- <p>Servicio: {{service_name}}</p>
1138
- <!-- Personaliza tu plantilla aquí -->
1139
- </body>
1140
- </html>`;
1141
- }
1142
- return `<!DOCTYPE html>
1143
- <html>
1144
- <head><style>body { font-family: Helvetica, sans-serif; }</style></head>
1145
- <body>
1146
- <h1>COMPROBANTE {{invoice_id}}</h1>
1147
- <p>Fecha: {{invoice_date}}</p>
1148
- <p>Empresa: {{company_name}}</p>
1149
- <!-- Personaliza tu plantilla aquí -->
1150
- </body>
1151
- </html>`;
1152
- }
1153
1156
  const i18nTranslations0 = {};
1154
1157
  const widgetModule = { widgets: [
1155
1158
  {
@@ -1171,21 +1174,21 @@ const routeModule = {
1171
1174
  Component: InvoiceTemplatesPage,
1172
1175
  path: "/invoice-config/invoice-templates"
1173
1176
  },
1174
- {
1175
- Component: NewCompanyPage,
1176
- path: "/invoice-config/companies/new"
1177
- },
1178
1177
  {
1179
1178
  Component: EditCompanyPage,
1180
1179
  path: "/invoice-config/companies/:id"
1181
1180
  },
1182
1181
  {
1183
- Component: TemplateEditorPage,
1184
- path: "/invoice-config/invoice-templates/:id"
1182
+ Component: NewCompanyPage,
1183
+ path: "/invoice-config/companies/new"
1185
1184
  },
1186
1185
  {
1187
1186
  Component: NewTemplatePage,
1188
1187
  path: "/invoice-config/invoice-templates/new"
1188
+ },
1189
+ {
1190
+ Component: TemplateEditorPage,
1191
+ path: "/invoice-config/invoice-templates/:id"
1189
1192
  }
1190
1193
  ]
1191
1194
  };