@zaamx/netme-pos 0.0.10 → 0.0.11
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.
|
@@ -311,24 +311,24 @@ const CreateOperatorModal = () => {
|
|
|
311
311
|
] }) }) })
|
|
312
312
|
] });
|
|
313
313
|
};
|
|
314
|
-
const columnHelper = ui.createDataTableColumnHelper();
|
|
315
|
-
const useColumns = () => {
|
|
314
|
+
const columnHelper$1 = ui.createDataTableColumnHelper();
|
|
315
|
+
const useColumns$1 = () => {
|
|
316
316
|
return react.useMemo(
|
|
317
317
|
() => [
|
|
318
|
-
columnHelper.accessor("first_name", {
|
|
318
|
+
columnHelper$1.accessor("first_name", {
|
|
319
319
|
header: "First Name"
|
|
320
320
|
}),
|
|
321
|
-
columnHelper.accessor("last_name", {
|
|
321
|
+
columnHelper$1.accessor("last_name", {
|
|
322
322
|
header: "Last Name"
|
|
323
323
|
}),
|
|
324
|
-
columnHelper.accessor("email", {
|
|
324
|
+
columnHelper$1.accessor("email", {
|
|
325
325
|
header: "Email"
|
|
326
326
|
}),
|
|
327
|
-
columnHelper.accessor("created_at", {
|
|
327
|
+
columnHelper$1.accessor("created_at", {
|
|
328
328
|
header: "Date Added",
|
|
329
329
|
cell: ({ getValue }) => new Date(getValue()).toLocaleDateString()
|
|
330
330
|
}),
|
|
331
|
-
columnHelper.display({
|
|
331
|
+
columnHelper$1.display({
|
|
332
332
|
id: "actions",
|
|
333
333
|
cell: ({ row }) => /* @__PURE__ */ jsxRuntime.jsx(OperatorActions, { operator: row.original })
|
|
334
334
|
})
|
|
@@ -355,7 +355,7 @@ const OperatorTable = () => {
|
|
|
355
355
|
queryKey: ["operators", limit, offset, searchValue],
|
|
356
356
|
placeholderData: (previousData) => previousData
|
|
357
357
|
});
|
|
358
|
-
const columns = useColumns();
|
|
358
|
+
const columns = useColumns$1();
|
|
359
359
|
const table = ui.useDataTable({
|
|
360
360
|
data: (data == null ? void 0 : data.operators) || [],
|
|
361
361
|
columns,
|
|
@@ -386,10 +386,499 @@ const OperatorsPage = () => {
|
|
|
386
386
|
/* @__PURE__ */ jsxRuntime.jsx(OperatorTable, {})
|
|
387
387
|
] });
|
|
388
388
|
};
|
|
389
|
-
const config = adminSdk.defineRouteConfig({
|
|
389
|
+
const config$1 = adminSdk.defineRouteConfig({
|
|
390
390
|
label: "Operators",
|
|
391
391
|
icon: icons.Users
|
|
392
392
|
});
|
|
393
|
+
const STATUS_OPTIONS = [
|
|
394
|
+
"pending",
|
|
395
|
+
"paid",
|
|
396
|
+
"approved",
|
|
397
|
+
"rejected",
|
|
398
|
+
"canceled"
|
|
399
|
+
];
|
|
400
|
+
const toForm = (po) => ({
|
|
401
|
+
payment_method: po.payment_method ?? "",
|
|
402
|
+
amount: po.amount != null ? String(po.amount) : "",
|
|
403
|
+
status: po.status ?? "",
|
|
404
|
+
concept: po.concept ?? "",
|
|
405
|
+
reference_code: po.reference_code ?? "",
|
|
406
|
+
institution: po.institution ?? "",
|
|
407
|
+
depositor_name: po.depositor_name ?? "",
|
|
408
|
+
terminal_reference: po.terminal_reference ?? "",
|
|
409
|
+
ticket_amount: po.ticket_amount != null ? String(po.ticket_amount) : "",
|
|
410
|
+
authorizer: po.authorizer ?? "",
|
|
411
|
+
receipt_file: po.receipt_file ?? ""
|
|
412
|
+
});
|
|
413
|
+
const EditPaymentOptionDrawer = ({
|
|
414
|
+
paymentOption,
|
|
415
|
+
open,
|
|
416
|
+
setOpen
|
|
417
|
+
}) => {
|
|
418
|
+
const [formData, setFormData] = react.useState(toForm(paymentOption));
|
|
419
|
+
const queryClient = reactQuery.useQueryClient();
|
|
420
|
+
react.useEffect(() => {
|
|
421
|
+
if (open) {
|
|
422
|
+
setFormData(toForm(paymentOption));
|
|
423
|
+
}
|
|
424
|
+
}, [open, paymentOption]);
|
|
425
|
+
const update = (key, value) => setFormData((prev) => ({ ...prev, [key]: value }));
|
|
426
|
+
const updateMutation = reactQuery.useMutation({
|
|
427
|
+
mutationFn: () => {
|
|
428
|
+
const payload = {
|
|
429
|
+
payment_method: formData.payment_method,
|
|
430
|
+
status: formData.status,
|
|
431
|
+
concept: formData.concept,
|
|
432
|
+
reference_code: formData.reference_code,
|
|
433
|
+
institution: formData.institution,
|
|
434
|
+
depositor_name: formData.depositor_name,
|
|
435
|
+
terminal_reference: formData.terminal_reference,
|
|
436
|
+
authorizer: formData.authorizer,
|
|
437
|
+
receipt_file: formData.receipt_file
|
|
438
|
+
};
|
|
439
|
+
if (formData.amount.trim() !== "") {
|
|
440
|
+
payload.amount = Number(formData.amount);
|
|
441
|
+
}
|
|
442
|
+
if (formData.ticket_amount.trim() !== "") {
|
|
443
|
+
payload.ticket_amount = Number(formData.ticket_amount);
|
|
444
|
+
}
|
|
445
|
+
return sdk.client.fetch(
|
|
446
|
+
`/admin/payment-options/${paymentOption.id}`,
|
|
447
|
+
{
|
|
448
|
+
method: "POST",
|
|
449
|
+
body: payload
|
|
450
|
+
}
|
|
451
|
+
);
|
|
452
|
+
},
|
|
453
|
+
onSuccess: () => {
|
|
454
|
+
queryClient.invalidateQueries({ queryKey: ["payment-options"] });
|
|
455
|
+
ui.toast.success("Nota de pago actualizada");
|
|
456
|
+
setOpen(false);
|
|
457
|
+
},
|
|
458
|
+
onError: (error) => {
|
|
459
|
+
ui.toast.error(error.message || "No se pudo actualizar la nota de pago");
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
const statusOptions = STATUS_OPTIONS.includes(formData.status) || !formData.status ? STATUS_OPTIONS : [formData.status, ...STATUS_OPTIONS];
|
|
463
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Drawer, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Content, { children: [
|
|
464
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Title, { children: "Editar nota de pago" }) }),
|
|
465
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Body, { className: "flex-1 overflow-auto p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
|
|
466
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
467
|
+
paymentOption.order_display_id ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", leading: "compact", className: "text-ui-fg-subtle", children: [
|
|
468
|
+
"Orden #",
|
|
469
|
+
paymentOption.order_display_id
|
|
470
|
+
] }) : null,
|
|
471
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", leading: "compact", className: "text-ui-fg-subtle", children: [
|
|
472
|
+
"Pago: ",
|
|
473
|
+
paymentOption.payment_id
|
|
474
|
+
] })
|
|
475
|
+
] }),
|
|
476
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
477
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Método de pago" }),
|
|
478
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
479
|
+
ui.Input,
|
|
480
|
+
{
|
|
481
|
+
value: formData.payment_method,
|
|
482
|
+
onChange: (e) => update("payment_method", e.target.value)
|
|
483
|
+
}
|
|
484
|
+
)
|
|
485
|
+
] }),
|
|
486
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
487
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
488
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Monto" }),
|
|
489
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
490
|
+
ui.Input,
|
|
491
|
+
{
|
|
492
|
+
type: "number",
|
|
493
|
+
step: "0.01",
|
|
494
|
+
value: formData.amount,
|
|
495
|
+
onChange: (e) => update("amount", e.target.value)
|
|
496
|
+
}
|
|
497
|
+
)
|
|
498
|
+
] }),
|
|
499
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
500
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Estatus" }),
|
|
501
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
502
|
+
ui.Select,
|
|
503
|
+
{
|
|
504
|
+
value: formData.status,
|
|
505
|
+
onValueChange: (value) => update("status", value),
|
|
506
|
+
children: [
|
|
507
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Seleccionar estatus" }) }),
|
|
508
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: statusOptions.map((s) => /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: s, children: s }, s)) })
|
|
509
|
+
]
|
|
510
|
+
}
|
|
511
|
+
)
|
|
512
|
+
] })
|
|
513
|
+
] }),
|
|
514
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
515
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Concepto" }),
|
|
516
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
517
|
+
ui.Input,
|
|
518
|
+
{
|
|
519
|
+
value: formData.concept,
|
|
520
|
+
onChange: (e) => update("concept", e.target.value)
|
|
521
|
+
}
|
|
522
|
+
)
|
|
523
|
+
] }),
|
|
524
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
525
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Folio / Referencia" }),
|
|
526
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
527
|
+
ui.Input,
|
|
528
|
+
{
|
|
529
|
+
value: formData.reference_code,
|
|
530
|
+
onChange: (e) => update("reference_code", e.target.value)
|
|
531
|
+
}
|
|
532
|
+
)
|
|
533
|
+
] }),
|
|
534
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
535
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Institución" }),
|
|
536
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
537
|
+
ui.Input,
|
|
538
|
+
{
|
|
539
|
+
value: formData.institution,
|
|
540
|
+
onChange: (e) => update("institution", e.target.value)
|
|
541
|
+
}
|
|
542
|
+
)
|
|
543
|
+
] }),
|
|
544
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
545
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Nombre del depositante" }),
|
|
546
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
547
|
+
ui.Input,
|
|
548
|
+
{
|
|
549
|
+
value: formData.depositor_name,
|
|
550
|
+
onChange: (e) => update("depositor_name", e.target.value)
|
|
551
|
+
}
|
|
552
|
+
)
|
|
553
|
+
] }),
|
|
554
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
555
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
556
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Referencia de terminal" }),
|
|
557
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
558
|
+
ui.Input,
|
|
559
|
+
{
|
|
560
|
+
value: formData.terminal_reference,
|
|
561
|
+
onChange: (e) => update("terminal_reference", e.target.value)
|
|
562
|
+
}
|
|
563
|
+
)
|
|
564
|
+
] }),
|
|
565
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
566
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Monto del ticket" }),
|
|
567
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
568
|
+
ui.Input,
|
|
569
|
+
{
|
|
570
|
+
type: "number",
|
|
571
|
+
step: "0.01",
|
|
572
|
+
value: formData.ticket_amount,
|
|
573
|
+
onChange: (e) => update("ticket_amount", e.target.value)
|
|
574
|
+
}
|
|
575
|
+
)
|
|
576
|
+
] })
|
|
577
|
+
] }),
|
|
578
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
579
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Autorizó" }),
|
|
580
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
581
|
+
ui.Input,
|
|
582
|
+
{
|
|
583
|
+
value: formData.authorizer,
|
|
584
|
+
onChange: (e) => update("authorizer", e.target.value)
|
|
585
|
+
}
|
|
586
|
+
)
|
|
587
|
+
] }),
|
|
588
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
589
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Comprobante (URL)" }),
|
|
590
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
591
|
+
ui.Input,
|
|
592
|
+
{
|
|
593
|
+
value: formData.receipt_file,
|
|
594
|
+
onChange: (e) => update("receipt_file", e.target.value)
|
|
595
|
+
}
|
|
596
|
+
),
|
|
597
|
+
formData.receipt_file && /* @__PURE__ */ jsxRuntime.jsx(
|
|
598
|
+
"a",
|
|
599
|
+
{
|
|
600
|
+
href: formData.receipt_file,
|
|
601
|
+
target: "_blank",
|
|
602
|
+
rel: "noreferrer",
|
|
603
|
+
className: "text-ui-fg-interactive text-xs",
|
|
604
|
+
children: "Ver comprobante"
|
|
605
|
+
}
|
|
606
|
+
)
|
|
607
|
+
] })
|
|
608
|
+
] }) }),
|
|
609
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
610
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
611
|
+
ui.Button,
|
|
612
|
+
{
|
|
613
|
+
size: "small",
|
|
614
|
+
variant: "secondary",
|
|
615
|
+
disabled: updateMutation.isPending,
|
|
616
|
+
children: "Cancelar"
|
|
617
|
+
}
|
|
618
|
+
) }),
|
|
619
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
620
|
+
ui.Button,
|
|
621
|
+
{
|
|
622
|
+
size: "small",
|
|
623
|
+
onClick: () => updateMutation.mutate(),
|
|
624
|
+
isLoading: updateMutation.isPending,
|
|
625
|
+
children: "Guardar"
|
|
626
|
+
}
|
|
627
|
+
)
|
|
628
|
+
] }) })
|
|
629
|
+
] }) });
|
|
630
|
+
};
|
|
631
|
+
const DeletePaymentOptionModal = ({
|
|
632
|
+
paymentOption,
|
|
633
|
+
open,
|
|
634
|
+
setOpen
|
|
635
|
+
}) => {
|
|
636
|
+
const queryClient = reactQuery.useQueryClient();
|
|
637
|
+
const deleteMutation = reactQuery.useMutation({
|
|
638
|
+
mutationFn: () => sdk.client.fetch(`/admin/payment-options/${paymentOption.id}`, {
|
|
639
|
+
method: "DELETE"
|
|
640
|
+
}),
|
|
641
|
+
onSuccess: () => {
|
|
642
|
+
queryClient.invalidateQueries({ queryKey: ["payment-options"] });
|
|
643
|
+
ui.toast.success("Nota de pago eliminada");
|
|
644
|
+
setOpen(false);
|
|
645
|
+
},
|
|
646
|
+
onError: (error) => {
|
|
647
|
+
ui.toast.error(error.message || "No se pudo eliminar la nota de pago");
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
const label = paymentOption.reference_code || paymentOption.concept || paymentOption.payment_method || paymentOption.id;
|
|
651
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Prompt, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Content, { children: [
|
|
652
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Header, { children: [
|
|
653
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Title, { children: "Eliminar nota de pago" }),
|
|
654
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Description, { children: [
|
|
655
|
+
'¿Seguro que deseas eliminar la nota de pago "',
|
|
656
|
+
label,
|
|
657
|
+
'"? Esta acción no se puede deshacer.'
|
|
658
|
+
] })
|
|
659
|
+
] }),
|
|
660
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Footer, { children: [
|
|
661
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Cancel, { children: "Cancelar" }),
|
|
662
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
663
|
+
ui.Prompt.Action,
|
|
664
|
+
{
|
|
665
|
+
onClick: () => deleteMutation.mutate(),
|
|
666
|
+
disabled: deleteMutation.isPending,
|
|
667
|
+
children: "Eliminar"
|
|
668
|
+
}
|
|
669
|
+
)
|
|
670
|
+
] })
|
|
671
|
+
] }) });
|
|
672
|
+
};
|
|
673
|
+
const PaymentOptionActions = ({
|
|
674
|
+
paymentOption
|
|
675
|
+
}) => {
|
|
676
|
+
const [editOpen, setEditOpen] = react.useState(false);
|
|
677
|
+
const [deleteOpen, setDeleteOpen] = react.useState(false);
|
|
678
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
679
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
680
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", variant: "transparent", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisHorizontal, {}) }) }),
|
|
681
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
682
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
683
|
+
ui.DropdownMenu.Item,
|
|
684
|
+
{
|
|
685
|
+
onClick: () => setEditOpen(true),
|
|
686
|
+
className: "gap-x-2",
|
|
687
|
+
children: [
|
|
688
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, { className: "text-ui-fg-subtle" }),
|
|
689
|
+
"Editar"
|
|
690
|
+
]
|
|
691
|
+
}
|
|
692
|
+
),
|
|
693
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
694
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
695
|
+
ui.DropdownMenu.Item,
|
|
696
|
+
{
|
|
697
|
+
onClick: () => setDeleteOpen(true),
|
|
698
|
+
className: "gap-x-2",
|
|
699
|
+
children: [
|
|
700
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
701
|
+
"Eliminar"
|
|
702
|
+
]
|
|
703
|
+
}
|
|
704
|
+
)
|
|
705
|
+
] })
|
|
706
|
+
] }),
|
|
707
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
708
|
+
EditPaymentOptionDrawer,
|
|
709
|
+
{
|
|
710
|
+
paymentOption,
|
|
711
|
+
open: editOpen,
|
|
712
|
+
setOpen: setEditOpen
|
|
713
|
+
}
|
|
714
|
+
),
|
|
715
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
716
|
+
DeletePaymentOptionModal,
|
|
717
|
+
{
|
|
718
|
+
paymentOption,
|
|
719
|
+
open: deleteOpen,
|
|
720
|
+
setOpen: setDeleteOpen
|
|
721
|
+
}
|
|
722
|
+
)
|
|
723
|
+
] });
|
|
724
|
+
};
|
|
725
|
+
const columnHelper = ui.createDataTableColumnHelper();
|
|
726
|
+
const formatAmount = (value) => {
|
|
727
|
+
const n = Number(value ?? 0);
|
|
728
|
+
return n.toLocaleString("es-MX", {
|
|
729
|
+
minimumFractionDigits: 2,
|
|
730
|
+
maximumFractionDigits: 2
|
|
731
|
+
});
|
|
732
|
+
};
|
|
733
|
+
const statusColor = (status) => {
|
|
734
|
+
switch ((status || "").toLowerCase()) {
|
|
735
|
+
case "paid":
|
|
736
|
+
case "pagado":
|
|
737
|
+
case "approved":
|
|
738
|
+
case "aprobado":
|
|
739
|
+
case "completed":
|
|
740
|
+
return "green";
|
|
741
|
+
case "pending":
|
|
742
|
+
case "pendiente":
|
|
743
|
+
case "in_progress":
|
|
744
|
+
return "orange";
|
|
745
|
+
case "rejected":
|
|
746
|
+
case "rechazado":
|
|
747
|
+
case "failed":
|
|
748
|
+
case "canceled":
|
|
749
|
+
case "cancelled":
|
|
750
|
+
case "cancelado":
|
|
751
|
+
return "red";
|
|
752
|
+
default:
|
|
753
|
+
return "grey";
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
const useColumns = () => {
|
|
757
|
+
return react.useMemo(
|
|
758
|
+
() => [
|
|
759
|
+
columnHelper.accessor("order_display_id", {
|
|
760
|
+
header: "Orden",
|
|
761
|
+
cell: ({ row }) => {
|
|
762
|
+
const displayId = row.original.order_display_id;
|
|
763
|
+
const orderId = row.original.order_id;
|
|
764
|
+
if (!displayId) {
|
|
765
|
+
return "—";
|
|
766
|
+
}
|
|
767
|
+
if (!orderId) {
|
|
768
|
+
return `#${displayId}`;
|
|
769
|
+
}
|
|
770
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
771
|
+
"a",
|
|
772
|
+
{
|
|
773
|
+
href: `/app/orders/${orderId}`,
|
|
774
|
+
className: "text-ui-fg-interactive hover:underline",
|
|
775
|
+
onClick: (e) => e.stopPropagation(),
|
|
776
|
+
children: [
|
|
777
|
+
"#",
|
|
778
|
+
displayId
|
|
779
|
+
]
|
|
780
|
+
}
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
}),
|
|
784
|
+
columnHelper.accessor("reference_code", {
|
|
785
|
+
header: "Folio / Referencia",
|
|
786
|
+
cell: ({ getValue }) => getValue() || "—"
|
|
787
|
+
}),
|
|
788
|
+
columnHelper.accessor("payment_method", {
|
|
789
|
+
header: "Método",
|
|
790
|
+
cell: ({ getValue }) => getValue() || "—"
|
|
791
|
+
}),
|
|
792
|
+
columnHelper.accessor("amount", {
|
|
793
|
+
header: "Monto",
|
|
794
|
+
cell: ({ getValue }) => formatAmount(getValue())
|
|
795
|
+
}),
|
|
796
|
+
columnHelper.accessor("status", {
|
|
797
|
+
header: "Estatus",
|
|
798
|
+
cell: ({ getValue }) => {
|
|
799
|
+
const status = getValue();
|
|
800
|
+
if (!status) {
|
|
801
|
+
return "—";
|
|
802
|
+
}
|
|
803
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", color: statusColor(status), children: status });
|
|
804
|
+
}
|
|
805
|
+
}),
|
|
806
|
+
columnHelper.accessor("concept", {
|
|
807
|
+
header: "Concepto",
|
|
808
|
+
cell: ({ getValue }) => getValue() || "—"
|
|
809
|
+
}),
|
|
810
|
+
columnHelper.accessor("created_at", {
|
|
811
|
+
header: "Fecha",
|
|
812
|
+
cell: ({ getValue }) => new Date(getValue()).toLocaleString()
|
|
813
|
+
}),
|
|
814
|
+
columnHelper.display({
|
|
815
|
+
id: "actions",
|
|
816
|
+
cell: ({ row }) => /* @__PURE__ */ jsxRuntime.jsx(PaymentOptionActions, { paymentOption: row.original })
|
|
817
|
+
})
|
|
818
|
+
],
|
|
819
|
+
[]
|
|
820
|
+
);
|
|
821
|
+
};
|
|
822
|
+
const PaymentOptionTable = () => {
|
|
823
|
+
const [searchValue, setSearchValue] = react.useState("");
|
|
824
|
+
const [pagination, setPagination] = react.useState({
|
|
825
|
+
pageIndex: 0,
|
|
826
|
+
pageSize: 15
|
|
827
|
+
});
|
|
828
|
+
const limit = pagination.pageSize;
|
|
829
|
+
const offset = pagination.pageIndex * limit;
|
|
830
|
+
const { data, isLoading } = reactQuery.useQuery({
|
|
831
|
+
queryFn: () => sdk.client.fetch("/admin/payment-options", {
|
|
832
|
+
query: {
|
|
833
|
+
limit,
|
|
834
|
+
offset,
|
|
835
|
+
q: searchValue || void 0
|
|
836
|
+
}
|
|
837
|
+
}),
|
|
838
|
+
queryKey: ["payment-options", limit, offset, searchValue],
|
|
839
|
+
placeholderData: (previousData) => previousData
|
|
840
|
+
});
|
|
841
|
+
const columns = useColumns();
|
|
842
|
+
const table = ui.useDataTable({
|
|
843
|
+
data: (data == null ? void 0 : data.payment_options) || [],
|
|
844
|
+
columns,
|
|
845
|
+
getRowId: (row) => row.id,
|
|
846
|
+
rowCount: (data == null ? void 0 : data.count) || 0,
|
|
847
|
+
isLoading,
|
|
848
|
+
search: {
|
|
849
|
+
state: searchValue,
|
|
850
|
+
onSearchChange: setSearchValue
|
|
851
|
+
},
|
|
852
|
+
pagination: {
|
|
853
|
+
state: pagination,
|
|
854
|
+
onPaginationChange: setPagination
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.DataTable, { instance: table, children: [
|
|
858
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DataTable.Toolbar, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center justify-between gap-x-2", children: [
|
|
859
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
860
|
+
(data == null ? void 0 : data.count) ?? 0,
|
|
861
|
+
" notas"
|
|
862
|
+
] }),
|
|
863
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DataTable.Search, { placeholder: "Buscar por orden, folio, concepto, método..." })
|
|
864
|
+
] }) }),
|
|
865
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DataTable.Table, {}),
|
|
866
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DataTable.Pagination, {})
|
|
867
|
+
] });
|
|
868
|
+
};
|
|
869
|
+
const PaymentOptionsPage = () => {
|
|
870
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "flex flex-col items-stretch overflow-hidden p-0", children: [
|
|
871
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between border-b border-ui-border-base px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
872
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Notas de pago (POS)" }),
|
|
873
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Revisa, edita o elimina las notas de pago registradas desde el POS." })
|
|
874
|
+
] }) }),
|
|
875
|
+
/* @__PURE__ */ jsxRuntime.jsx(PaymentOptionTable, {})
|
|
876
|
+
] });
|
|
877
|
+
};
|
|
878
|
+
const config = adminSdk.defineRouteConfig({
|
|
879
|
+
label: "Notas de pago",
|
|
880
|
+
icon: icons.CurrencyDollar
|
|
881
|
+
});
|
|
393
882
|
const i18nTranslations0 = {};
|
|
394
883
|
const widgetModule = { widgets: [] };
|
|
395
884
|
const routeModule = {
|
|
@@ -397,15 +886,27 @@ const routeModule = {
|
|
|
397
886
|
{
|
|
398
887
|
Component: OperatorsPage,
|
|
399
888
|
path: "/operators"
|
|
889
|
+
},
|
|
890
|
+
{
|
|
891
|
+
Component: PaymentOptionsPage,
|
|
892
|
+
path: "/payment-options"
|
|
400
893
|
}
|
|
401
894
|
]
|
|
402
895
|
};
|
|
403
896
|
const menuItemModule = {
|
|
404
897
|
menuItems: [
|
|
898
|
+
{
|
|
899
|
+
label: config$1.label,
|
|
900
|
+
icon: config$1.icon,
|
|
901
|
+
path: "/operators",
|
|
902
|
+
nested: void 0,
|
|
903
|
+
rank: void 0,
|
|
904
|
+
translationNs: void 0
|
|
905
|
+
},
|
|
405
906
|
{
|
|
406
907
|
label: config.label,
|
|
407
908
|
icon: config.icon,
|
|
408
|
-
path: "/
|
|
909
|
+
path: "/payment-options",
|
|
409
910
|
nested: void 0,
|
|
410
911
|
rank: void 0,
|
|
411
912
|
translationNs: void 0
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { defineRouteConfig } from "@medusajs/admin-sdk";
|
|
3
|
-
import { EllipsisHorizontal, PencilSquare, Trash, Users } from "@medusajs/icons";
|
|
4
|
-
import { toast, Drawer, Label, Input, Text, Button, Prompt, DropdownMenu, IconButton, FocusModal, createDataTableColumnHelper, useDataTable, DataTable, Container, Heading } from "@medusajs/ui";
|
|
5
|
-
import { useState, useMemo } from "react";
|
|
3
|
+
import { EllipsisHorizontal, PencilSquare, Trash, Users, CurrencyDollar } from "@medusajs/icons";
|
|
4
|
+
import { toast, Drawer, Label, Input, Text, Button, Prompt, DropdownMenu, IconButton, FocusModal, createDataTableColumnHelper, useDataTable, DataTable, Container, Heading, Select, Badge } from "@medusajs/ui";
|
|
5
|
+
import { useState, useMemo, useEffect } from "react";
|
|
6
6
|
import { useQueryClient, useMutation, useQuery } from "@tanstack/react-query";
|
|
7
7
|
import Medusa from "@medusajs/js-sdk";
|
|
8
8
|
const sdk = new Medusa({
|
|
@@ -308,24 +308,24 @@ const CreateOperatorModal = () => {
|
|
|
308
308
|
] }) }) })
|
|
309
309
|
] });
|
|
310
310
|
};
|
|
311
|
-
const columnHelper = createDataTableColumnHelper();
|
|
312
|
-
const useColumns = () => {
|
|
311
|
+
const columnHelper$1 = createDataTableColumnHelper();
|
|
312
|
+
const useColumns$1 = () => {
|
|
313
313
|
return useMemo(
|
|
314
314
|
() => [
|
|
315
|
-
columnHelper.accessor("first_name", {
|
|
315
|
+
columnHelper$1.accessor("first_name", {
|
|
316
316
|
header: "First Name"
|
|
317
317
|
}),
|
|
318
|
-
columnHelper.accessor("last_name", {
|
|
318
|
+
columnHelper$1.accessor("last_name", {
|
|
319
319
|
header: "Last Name"
|
|
320
320
|
}),
|
|
321
|
-
columnHelper.accessor("email", {
|
|
321
|
+
columnHelper$1.accessor("email", {
|
|
322
322
|
header: "Email"
|
|
323
323
|
}),
|
|
324
|
-
columnHelper.accessor("created_at", {
|
|
324
|
+
columnHelper$1.accessor("created_at", {
|
|
325
325
|
header: "Date Added",
|
|
326
326
|
cell: ({ getValue }) => new Date(getValue()).toLocaleDateString()
|
|
327
327
|
}),
|
|
328
|
-
columnHelper.display({
|
|
328
|
+
columnHelper$1.display({
|
|
329
329
|
id: "actions",
|
|
330
330
|
cell: ({ row }) => /* @__PURE__ */ jsx(OperatorActions, { operator: row.original })
|
|
331
331
|
})
|
|
@@ -352,7 +352,7 @@ const OperatorTable = () => {
|
|
|
352
352
|
queryKey: ["operators", limit, offset, searchValue],
|
|
353
353
|
placeholderData: (previousData) => previousData
|
|
354
354
|
});
|
|
355
|
-
const columns = useColumns();
|
|
355
|
+
const columns = useColumns$1();
|
|
356
356
|
const table = useDataTable({
|
|
357
357
|
data: (data == null ? void 0 : data.operators) || [],
|
|
358
358
|
columns,
|
|
@@ -383,10 +383,499 @@ const OperatorsPage = () => {
|
|
|
383
383
|
/* @__PURE__ */ jsx(OperatorTable, {})
|
|
384
384
|
] });
|
|
385
385
|
};
|
|
386
|
-
const config = defineRouteConfig({
|
|
386
|
+
const config$1 = defineRouteConfig({
|
|
387
387
|
label: "Operators",
|
|
388
388
|
icon: Users
|
|
389
389
|
});
|
|
390
|
+
const STATUS_OPTIONS = [
|
|
391
|
+
"pending",
|
|
392
|
+
"paid",
|
|
393
|
+
"approved",
|
|
394
|
+
"rejected",
|
|
395
|
+
"canceled"
|
|
396
|
+
];
|
|
397
|
+
const toForm = (po) => ({
|
|
398
|
+
payment_method: po.payment_method ?? "",
|
|
399
|
+
amount: po.amount != null ? String(po.amount) : "",
|
|
400
|
+
status: po.status ?? "",
|
|
401
|
+
concept: po.concept ?? "",
|
|
402
|
+
reference_code: po.reference_code ?? "",
|
|
403
|
+
institution: po.institution ?? "",
|
|
404
|
+
depositor_name: po.depositor_name ?? "",
|
|
405
|
+
terminal_reference: po.terminal_reference ?? "",
|
|
406
|
+
ticket_amount: po.ticket_amount != null ? String(po.ticket_amount) : "",
|
|
407
|
+
authorizer: po.authorizer ?? "",
|
|
408
|
+
receipt_file: po.receipt_file ?? ""
|
|
409
|
+
});
|
|
410
|
+
const EditPaymentOptionDrawer = ({
|
|
411
|
+
paymentOption,
|
|
412
|
+
open,
|
|
413
|
+
setOpen
|
|
414
|
+
}) => {
|
|
415
|
+
const [formData, setFormData] = useState(toForm(paymentOption));
|
|
416
|
+
const queryClient = useQueryClient();
|
|
417
|
+
useEffect(() => {
|
|
418
|
+
if (open) {
|
|
419
|
+
setFormData(toForm(paymentOption));
|
|
420
|
+
}
|
|
421
|
+
}, [open, paymentOption]);
|
|
422
|
+
const update = (key, value) => setFormData((prev) => ({ ...prev, [key]: value }));
|
|
423
|
+
const updateMutation = useMutation({
|
|
424
|
+
mutationFn: () => {
|
|
425
|
+
const payload = {
|
|
426
|
+
payment_method: formData.payment_method,
|
|
427
|
+
status: formData.status,
|
|
428
|
+
concept: formData.concept,
|
|
429
|
+
reference_code: formData.reference_code,
|
|
430
|
+
institution: formData.institution,
|
|
431
|
+
depositor_name: formData.depositor_name,
|
|
432
|
+
terminal_reference: formData.terminal_reference,
|
|
433
|
+
authorizer: formData.authorizer,
|
|
434
|
+
receipt_file: formData.receipt_file
|
|
435
|
+
};
|
|
436
|
+
if (formData.amount.trim() !== "") {
|
|
437
|
+
payload.amount = Number(formData.amount);
|
|
438
|
+
}
|
|
439
|
+
if (formData.ticket_amount.trim() !== "") {
|
|
440
|
+
payload.ticket_amount = Number(formData.ticket_amount);
|
|
441
|
+
}
|
|
442
|
+
return sdk.client.fetch(
|
|
443
|
+
`/admin/payment-options/${paymentOption.id}`,
|
|
444
|
+
{
|
|
445
|
+
method: "POST",
|
|
446
|
+
body: payload
|
|
447
|
+
}
|
|
448
|
+
);
|
|
449
|
+
},
|
|
450
|
+
onSuccess: () => {
|
|
451
|
+
queryClient.invalidateQueries({ queryKey: ["payment-options"] });
|
|
452
|
+
toast.success("Nota de pago actualizada");
|
|
453
|
+
setOpen(false);
|
|
454
|
+
},
|
|
455
|
+
onError: (error) => {
|
|
456
|
+
toast.error(error.message || "No se pudo actualizar la nota de pago");
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
const statusOptions = STATUS_OPTIONS.includes(formData.status) || !formData.status ? STATUS_OPTIONS : [formData.status, ...STATUS_OPTIONS];
|
|
460
|
+
return /* @__PURE__ */ jsx(Drawer, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(Drawer.Content, { children: [
|
|
461
|
+
/* @__PURE__ */ jsx(Drawer.Header, { children: /* @__PURE__ */ jsx(Drawer.Title, { children: "Editar nota de pago" }) }),
|
|
462
|
+
/* @__PURE__ */ jsx(Drawer.Body, { className: "flex-1 overflow-auto p-4", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
|
|
463
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
464
|
+
paymentOption.order_display_id ? /* @__PURE__ */ jsxs(Text, { size: "small", leading: "compact", className: "text-ui-fg-subtle", children: [
|
|
465
|
+
"Orden #",
|
|
466
|
+
paymentOption.order_display_id
|
|
467
|
+
] }) : null,
|
|
468
|
+
/* @__PURE__ */ jsxs(Text, { size: "small", leading: "compact", className: "text-ui-fg-subtle", children: [
|
|
469
|
+
"Pago: ",
|
|
470
|
+
paymentOption.payment_id
|
|
471
|
+
] })
|
|
472
|
+
] }),
|
|
473
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
474
|
+
/* @__PURE__ */ jsx(Label, { children: "Método de pago" }),
|
|
475
|
+
/* @__PURE__ */ jsx(
|
|
476
|
+
Input,
|
|
477
|
+
{
|
|
478
|
+
value: formData.payment_method,
|
|
479
|
+
onChange: (e) => update("payment_method", e.target.value)
|
|
480
|
+
}
|
|
481
|
+
)
|
|
482
|
+
] }),
|
|
483
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
484
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
485
|
+
/* @__PURE__ */ jsx(Label, { children: "Monto" }),
|
|
486
|
+
/* @__PURE__ */ jsx(
|
|
487
|
+
Input,
|
|
488
|
+
{
|
|
489
|
+
type: "number",
|
|
490
|
+
step: "0.01",
|
|
491
|
+
value: formData.amount,
|
|
492
|
+
onChange: (e) => update("amount", e.target.value)
|
|
493
|
+
}
|
|
494
|
+
)
|
|
495
|
+
] }),
|
|
496
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
497
|
+
/* @__PURE__ */ jsx(Label, { children: "Estatus" }),
|
|
498
|
+
/* @__PURE__ */ jsxs(
|
|
499
|
+
Select,
|
|
500
|
+
{
|
|
501
|
+
value: formData.status,
|
|
502
|
+
onValueChange: (value) => update("status", value),
|
|
503
|
+
children: [
|
|
504
|
+
/* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Seleccionar estatus" }) }),
|
|
505
|
+
/* @__PURE__ */ jsx(Select.Content, { children: statusOptions.map((s) => /* @__PURE__ */ jsx(Select.Item, { value: s, children: s }, s)) })
|
|
506
|
+
]
|
|
507
|
+
}
|
|
508
|
+
)
|
|
509
|
+
] })
|
|
510
|
+
] }),
|
|
511
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
512
|
+
/* @__PURE__ */ jsx(Label, { children: "Concepto" }),
|
|
513
|
+
/* @__PURE__ */ jsx(
|
|
514
|
+
Input,
|
|
515
|
+
{
|
|
516
|
+
value: formData.concept,
|
|
517
|
+
onChange: (e) => update("concept", e.target.value)
|
|
518
|
+
}
|
|
519
|
+
)
|
|
520
|
+
] }),
|
|
521
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
522
|
+
/* @__PURE__ */ jsx(Label, { children: "Folio / Referencia" }),
|
|
523
|
+
/* @__PURE__ */ jsx(
|
|
524
|
+
Input,
|
|
525
|
+
{
|
|
526
|
+
value: formData.reference_code,
|
|
527
|
+
onChange: (e) => update("reference_code", e.target.value)
|
|
528
|
+
}
|
|
529
|
+
)
|
|
530
|
+
] }),
|
|
531
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
532
|
+
/* @__PURE__ */ jsx(Label, { children: "Institución" }),
|
|
533
|
+
/* @__PURE__ */ jsx(
|
|
534
|
+
Input,
|
|
535
|
+
{
|
|
536
|
+
value: formData.institution,
|
|
537
|
+
onChange: (e) => update("institution", e.target.value)
|
|
538
|
+
}
|
|
539
|
+
)
|
|
540
|
+
] }),
|
|
541
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
542
|
+
/* @__PURE__ */ jsx(Label, { children: "Nombre del depositante" }),
|
|
543
|
+
/* @__PURE__ */ jsx(
|
|
544
|
+
Input,
|
|
545
|
+
{
|
|
546
|
+
value: formData.depositor_name,
|
|
547
|
+
onChange: (e) => update("depositor_name", e.target.value)
|
|
548
|
+
}
|
|
549
|
+
)
|
|
550
|
+
] }),
|
|
551
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
552
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
553
|
+
/* @__PURE__ */ jsx(Label, { children: "Referencia de terminal" }),
|
|
554
|
+
/* @__PURE__ */ jsx(
|
|
555
|
+
Input,
|
|
556
|
+
{
|
|
557
|
+
value: formData.terminal_reference,
|
|
558
|
+
onChange: (e) => update("terminal_reference", e.target.value)
|
|
559
|
+
}
|
|
560
|
+
)
|
|
561
|
+
] }),
|
|
562
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
563
|
+
/* @__PURE__ */ jsx(Label, { children: "Monto del ticket" }),
|
|
564
|
+
/* @__PURE__ */ jsx(
|
|
565
|
+
Input,
|
|
566
|
+
{
|
|
567
|
+
type: "number",
|
|
568
|
+
step: "0.01",
|
|
569
|
+
value: formData.ticket_amount,
|
|
570
|
+
onChange: (e) => update("ticket_amount", e.target.value)
|
|
571
|
+
}
|
|
572
|
+
)
|
|
573
|
+
] })
|
|
574
|
+
] }),
|
|
575
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
576
|
+
/* @__PURE__ */ jsx(Label, { children: "Autorizó" }),
|
|
577
|
+
/* @__PURE__ */ jsx(
|
|
578
|
+
Input,
|
|
579
|
+
{
|
|
580
|
+
value: formData.authorizer,
|
|
581
|
+
onChange: (e) => update("authorizer", e.target.value)
|
|
582
|
+
}
|
|
583
|
+
)
|
|
584
|
+
] }),
|
|
585
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
586
|
+
/* @__PURE__ */ jsx(Label, { children: "Comprobante (URL)" }),
|
|
587
|
+
/* @__PURE__ */ jsx(
|
|
588
|
+
Input,
|
|
589
|
+
{
|
|
590
|
+
value: formData.receipt_file,
|
|
591
|
+
onChange: (e) => update("receipt_file", e.target.value)
|
|
592
|
+
}
|
|
593
|
+
),
|
|
594
|
+
formData.receipt_file && /* @__PURE__ */ jsx(
|
|
595
|
+
"a",
|
|
596
|
+
{
|
|
597
|
+
href: formData.receipt_file,
|
|
598
|
+
target: "_blank",
|
|
599
|
+
rel: "noreferrer",
|
|
600
|
+
className: "text-ui-fg-interactive text-xs",
|
|
601
|
+
children: "Ver comprobante"
|
|
602
|
+
}
|
|
603
|
+
)
|
|
604
|
+
] })
|
|
605
|
+
] }) }),
|
|
606
|
+
/* @__PURE__ */ jsx(Drawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
607
|
+
/* @__PURE__ */ jsx(Drawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
608
|
+
Button,
|
|
609
|
+
{
|
|
610
|
+
size: "small",
|
|
611
|
+
variant: "secondary",
|
|
612
|
+
disabled: updateMutation.isPending,
|
|
613
|
+
children: "Cancelar"
|
|
614
|
+
}
|
|
615
|
+
) }),
|
|
616
|
+
/* @__PURE__ */ jsx(
|
|
617
|
+
Button,
|
|
618
|
+
{
|
|
619
|
+
size: "small",
|
|
620
|
+
onClick: () => updateMutation.mutate(),
|
|
621
|
+
isLoading: updateMutation.isPending,
|
|
622
|
+
children: "Guardar"
|
|
623
|
+
}
|
|
624
|
+
)
|
|
625
|
+
] }) })
|
|
626
|
+
] }) });
|
|
627
|
+
};
|
|
628
|
+
const DeletePaymentOptionModal = ({
|
|
629
|
+
paymentOption,
|
|
630
|
+
open,
|
|
631
|
+
setOpen
|
|
632
|
+
}) => {
|
|
633
|
+
const queryClient = useQueryClient();
|
|
634
|
+
const deleteMutation = useMutation({
|
|
635
|
+
mutationFn: () => sdk.client.fetch(`/admin/payment-options/${paymentOption.id}`, {
|
|
636
|
+
method: "DELETE"
|
|
637
|
+
}),
|
|
638
|
+
onSuccess: () => {
|
|
639
|
+
queryClient.invalidateQueries({ queryKey: ["payment-options"] });
|
|
640
|
+
toast.success("Nota de pago eliminada");
|
|
641
|
+
setOpen(false);
|
|
642
|
+
},
|
|
643
|
+
onError: (error) => {
|
|
644
|
+
toast.error(error.message || "No se pudo eliminar la nota de pago");
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
const label = paymentOption.reference_code || paymentOption.concept || paymentOption.payment_method || paymentOption.id;
|
|
648
|
+
return /* @__PURE__ */ jsx(Prompt, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(Prompt.Content, { children: [
|
|
649
|
+
/* @__PURE__ */ jsxs(Prompt.Header, { children: [
|
|
650
|
+
/* @__PURE__ */ jsx(Prompt.Title, { children: "Eliminar nota de pago" }),
|
|
651
|
+
/* @__PURE__ */ jsxs(Prompt.Description, { children: [
|
|
652
|
+
'¿Seguro que deseas eliminar la nota de pago "',
|
|
653
|
+
label,
|
|
654
|
+
'"? Esta acción no se puede deshacer.'
|
|
655
|
+
] })
|
|
656
|
+
] }),
|
|
657
|
+
/* @__PURE__ */ jsxs(Prompt.Footer, { children: [
|
|
658
|
+
/* @__PURE__ */ jsx(Prompt.Cancel, { children: "Cancelar" }),
|
|
659
|
+
/* @__PURE__ */ jsx(
|
|
660
|
+
Prompt.Action,
|
|
661
|
+
{
|
|
662
|
+
onClick: () => deleteMutation.mutate(),
|
|
663
|
+
disabled: deleteMutation.isPending,
|
|
664
|
+
children: "Eliminar"
|
|
665
|
+
}
|
|
666
|
+
)
|
|
667
|
+
] })
|
|
668
|
+
] }) });
|
|
669
|
+
};
|
|
670
|
+
const PaymentOptionActions = ({
|
|
671
|
+
paymentOption
|
|
672
|
+
}) => {
|
|
673
|
+
const [editOpen, setEditOpen] = useState(false);
|
|
674
|
+
const [deleteOpen, setDeleteOpen] = useState(false);
|
|
675
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
676
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
677
|
+
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { size: "small", variant: "transparent", children: /* @__PURE__ */ jsx(EllipsisHorizontal, {}) }) }),
|
|
678
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
679
|
+
/* @__PURE__ */ jsxs(
|
|
680
|
+
DropdownMenu.Item,
|
|
681
|
+
{
|
|
682
|
+
onClick: () => setEditOpen(true),
|
|
683
|
+
className: "gap-x-2",
|
|
684
|
+
children: [
|
|
685
|
+
/* @__PURE__ */ jsx(PencilSquare, { className: "text-ui-fg-subtle" }),
|
|
686
|
+
"Editar"
|
|
687
|
+
]
|
|
688
|
+
}
|
|
689
|
+
),
|
|
690
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
691
|
+
/* @__PURE__ */ jsxs(
|
|
692
|
+
DropdownMenu.Item,
|
|
693
|
+
{
|
|
694
|
+
onClick: () => setDeleteOpen(true),
|
|
695
|
+
className: "gap-x-2",
|
|
696
|
+
children: [
|
|
697
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
698
|
+
"Eliminar"
|
|
699
|
+
]
|
|
700
|
+
}
|
|
701
|
+
)
|
|
702
|
+
] })
|
|
703
|
+
] }),
|
|
704
|
+
/* @__PURE__ */ jsx(
|
|
705
|
+
EditPaymentOptionDrawer,
|
|
706
|
+
{
|
|
707
|
+
paymentOption,
|
|
708
|
+
open: editOpen,
|
|
709
|
+
setOpen: setEditOpen
|
|
710
|
+
}
|
|
711
|
+
),
|
|
712
|
+
/* @__PURE__ */ jsx(
|
|
713
|
+
DeletePaymentOptionModal,
|
|
714
|
+
{
|
|
715
|
+
paymentOption,
|
|
716
|
+
open: deleteOpen,
|
|
717
|
+
setOpen: setDeleteOpen
|
|
718
|
+
}
|
|
719
|
+
)
|
|
720
|
+
] });
|
|
721
|
+
};
|
|
722
|
+
const columnHelper = createDataTableColumnHelper();
|
|
723
|
+
const formatAmount = (value) => {
|
|
724
|
+
const n = Number(value ?? 0);
|
|
725
|
+
return n.toLocaleString("es-MX", {
|
|
726
|
+
minimumFractionDigits: 2,
|
|
727
|
+
maximumFractionDigits: 2
|
|
728
|
+
});
|
|
729
|
+
};
|
|
730
|
+
const statusColor = (status) => {
|
|
731
|
+
switch ((status || "").toLowerCase()) {
|
|
732
|
+
case "paid":
|
|
733
|
+
case "pagado":
|
|
734
|
+
case "approved":
|
|
735
|
+
case "aprobado":
|
|
736
|
+
case "completed":
|
|
737
|
+
return "green";
|
|
738
|
+
case "pending":
|
|
739
|
+
case "pendiente":
|
|
740
|
+
case "in_progress":
|
|
741
|
+
return "orange";
|
|
742
|
+
case "rejected":
|
|
743
|
+
case "rechazado":
|
|
744
|
+
case "failed":
|
|
745
|
+
case "canceled":
|
|
746
|
+
case "cancelled":
|
|
747
|
+
case "cancelado":
|
|
748
|
+
return "red";
|
|
749
|
+
default:
|
|
750
|
+
return "grey";
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
const useColumns = () => {
|
|
754
|
+
return useMemo(
|
|
755
|
+
() => [
|
|
756
|
+
columnHelper.accessor("order_display_id", {
|
|
757
|
+
header: "Orden",
|
|
758
|
+
cell: ({ row }) => {
|
|
759
|
+
const displayId = row.original.order_display_id;
|
|
760
|
+
const orderId = row.original.order_id;
|
|
761
|
+
if (!displayId) {
|
|
762
|
+
return "—";
|
|
763
|
+
}
|
|
764
|
+
if (!orderId) {
|
|
765
|
+
return `#${displayId}`;
|
|
766
|
+
}
|
|
767
|
+
return /* @__PURE__ */ jsxs(
|
|
768
|
+
"a",
|
|
769
|
+
{
|
|
770
|
+
href: `/app/orders/${orderId}`,
|
|
771
|
+
className: "text-ui-fg-interactive hover:underline",
|
|
772
|
+
onClick: (e) => e.stopPropagation(),
|
|
773
|
+
children: [
|
|
774
|
+
"#",
|
|
775
|
+
displayId
|
|
776
|
+
]
|
|
777
|
+
}
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
}),
|
|
781
|
+
columnHelper.accessor("reference_code", {
|
|
782
|
+
header: "Folio / Referencia",
|
|
783
|
+
cell: ({ getValue }) => getValue() || "—"
|
|
784
|
+
}),
|
|
785
|
+
columnHelper.accessor("payment_method", {
|
|
786
|
+
header: "Método",
|
|
787
|
+
cell: ({ getValue }) => getValue() || "—"
|
|
788
|
+
}),
|
|
789
|
+
columnHelper.accessor("amount", {
|
|
790
|
+
header: "Monto",
|
|
791
|
+
cell: ({ getValue }) => formatAmount(getValue())
|
|
792
|
+
}),
|
|
793
|
+
columnHelper.accessor("status", {
|
|
794
|
+
header: "Estatus",
|
|
795
|
+
cell: ({ getValue }) => {
|
|
796
|
+
const status = getValue();
|
|
797
|
+
if (!status) {
|
|
798
|
+
return "—";
|
|
799
|
+
}
|
|
800
|
+
return /* @__PURE__ */ jsx(Badge, { size: "2xsmall", color: statusColor(status), children: status });
|
|
801
|
+
}
|
|
802
|
+
}),
|
|
803
|
+
columnHelper.accessor("concept", {
|
|
804
|
+
header: "Concepto",
|
|
805
|
+
cell: ({ getValue }) => getValue() || "—"
|
|
806
|
+
}),
|
|
807
|
+
columnHelper.accessor("created_at", {
|
|
808
|
+
header: "Fecha",
|
|
809
|
+
cell: ({ getValue }) => new Date(getValue()).toLocaleString()
|
|
810
|
+
}),
|
|
811
|
+
columnHelper.display({
|
|
812
|
+
id: "actions",
|
|
813
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(PaymentOptionActions, { paymentOption: row.original })
|
|
814
|
+
})
|
|
815
|
+
],
|
|
816
|
+
[]
|
|
817
|
+
);
|
|
818
|
+
};
|
|
819
|
+
const PaymentOptionTable = () => {
|
|
820
|
+
const [searchValue, setSearchValue] = useState("");
|
|
821
|
+
const [pagination, setPagination] = useState({
|
|
822
|
+
pageIndex: 0,
|
|
823
|
+
pageSize: 15
|
|
824
|
+
});
|
|
825
|
+
const limit = pagination.pageSize;
|
|
826
|
+
const offset = pagination.pageIndex * limit;
|
|
827
|
+
const { data, isLoading } = useQuery({
|
|
828
|
+
queryFn: () => sdk.client.fetch("/admin/payment-options", {
|
|
829
|
+
query: {
|
|
830
|
+
limit,
|
|
831
|
+
offset,
|
|
832
|
+
q: searchValue || void 0
|
|
833
|
+
}
|
|
834
|
+
}),
|
|
835
|
+
queryKey: ["payment-options", limit, offset, searchValue],
|
|
836
|
+
placeholderData: (previousData) => previousData
|
|
837
|
+
});
|
|
838
|
+
const columns = useColumns();
|
|
839
|
+
const table = useDataTable({
|
|
840
|
+
data: (data == null ? void 0 : data.payment_options) || [],
|
|
841
|
+
columns,
|
|
842
|
+
getRowId: (row) => row.id,
|
|
843
|
+
rowCount: (data == null ? void 0 : data.count) || 0,
|
|
844
|
+
isLoading,
|
|
845
|
+
search: {
|
|
846
|
+
state: searchValue,
|
|
847
|
+
onSearchChange: setSearchValue
|
|
848
|
+
},
|
|
849
|
+
pagination: {
|
|
850
|
+
state: pagination,
|
|
851
|
+
onPaginationChange: setPagination
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
return /* @__PURE__ */ jsxs(DataTable, { instance: table, children: [
|
|
855
|
+
/* @__PURE__ */ jsx(DataTable.Toolbar, { children: /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center justify-between gap-x-2", children: [
|
|
856
|
+
/* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
857
|
+
(data == null ? void 0 : data.count) ?? 0,
|
|
858
|
+
" notas"
|
|
859
|
+
] }),
|
|
860
|
+
/* @__PURE__ */ jsx(DataTable.Search, { placeholder: "Buscar por orden, folio, concepto, método..." })
|
|
861
|
+
] }) }),
|
|
862
|
+
/* @__PURE__ */ jsx(DataTable.Table, {}),
|
|
863
|
+
/* @__PURE__ */ jsx(DataTable.Pagination, {})
|
|
864
|
+
] });
|
|
865
|
+
};
|
|
866
|
+
const PaymentOptionsPage = () => {
|
|
867
|
+
return /* @__PURE__ */ jsxs(Container, { className: "flex flex-col items-stretch overflow-hidden p-0", children: [
|
|
868
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center justify-between border-b border-ui-border-base px-6 py-4", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
869
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: "Notas de pago (POS)" }),
|
|
870
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Revisa, edita o elimina las notas de pago registradas desde el POS." })
|
|
871
|
+
] }) }),
|
|
872
|
+
/* @__PURE__ */ jsx(PaymentOptionTable, {})
|
|
873
|
+
] });
|
|
874
|
+
};
|
|
875
|
+
const config = defineRouteConfig({
|
|
876
|
+
label: "Notas de pago",
|
|
877
|
+
icon: CurrencyDollar
|
|
878
|
+
});
|
|
390
879
|
const i18nTranslations0 = {};
|
|
391
880
|
const widgetModule = { widgets: [] };
|
|
392
881
|
const routeModule = {
|
|
@@ -394,15 +883,27 @@ const routeModule = {
|
|
|
394
883
|
{
|
|
395
884
|
Component: OperatorsPage,
|
|
396
885
|
path: "/operators"
|
|
886
|
+
},
|
|
887
|
+
{
|
|
888
|
+
Component: PaymentOptionsPage,
|
|
889
|
+
path: "/payment-options"
|
|
397
890
|
}
|
|
398
891
|
]
|
|
399
892
|
};
|
|
400
893
|
const menuItemModule = {
|
|
401
894
|
menuItems: [
|
|
895
|
+
{
|
|
896
|
+
label: config$1.label,
|
|
897
|
+
icon: config$1.icon,
|
|
898
|
+
path: "/operators",
|
|
899
|
+
nested: void 0,
|
|
900
|
+
rank: void 0,
|
|
901
|
+
translationNs: void 0
|
|
902
|
+
},
|
|
402
903
|
{
|
|
403
904
|
label: config.label,
|
|
404
905
|
icon: config.icon,
|
|
405
|
-
path: "/
|
|
906
|
+
path: "/payment-options",
|
|
406
907
|
nested: void 0,
|
|
407
908
|
rank: void 0,
|
|
408
909
|
translationNs: void 0
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GET = GET;
|
|
4
|
+
exports.POST = POST;
|
|
5
|
+
exports.DELETE = DELETE;
|
|
6
|
+
const zod_1 = require("@medusajs/framework/zod");
|
|
7
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
8
|
+
const payment_options_1 = require("../../../../modules/payment-options");
|
|
9
|
+
const UpdatePaymentOptionSchema = zod_1.z.object({
|
|
10
|
+
payment_method: zod_1.z.string().optional(),
|
|
11
|
+
amount: zod_1.z.coerce.number().optional(),
|
|
12
|
+
status: zod_1.z.string().optional(),
|
|
13
|
+
institution: zod_1.z.string().optional(),
|
|
14
|
+
receipt_file: zod_1.z.string().optional(),
|
|
15
|
+
concept: zod_1.z.string().optional(),
|
|
16
|
+
reference_code: zod_1.z.string().optional(),
|
|
17
|
+
depositor_name: zod_1.z.string().optional(),
|
|
18
|
+
terminal_reference: zod_1.z.string().optional(),
|
|
19
|
+
ticket_amount: zod_1.z.coerce.number().optional(),
|
|
20
|
+
authorizer: zod_1.z.string().optional(),
|
|
21
|
+
});
|
|
22
|
+
async function GET(req, res) {
|
|
23
|
+
const { id } = req.params;
|
|
24
|
+
const service = req.scope.resolve(payment_options_1.PAYMENT_OPTION_MODULE);
|
|
25
|
+
try {
|
|
26
|
+
const payment_option = await service.retrievePaymentOption(id);
|
|
27
|
+
res.json({ payment_option });
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
res.status(404).json({ message: "Payment option not found." });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function POST(req, res) {
|
|
34
|
+
const { id } = req.params;
|
|
35
|
+
const service = req.scope.resolve(payment_options_1.PAYMENT_OPTION_MODULE);
|
|
36
|
+
const validated = UpdatePaymentOptionSchema.parse(req.body);
|
|
37
|
+
try {
|
|
38
|
+
const payment_option = await service.updatePaymentOptions({
|
|
39
|
+
id,
|
|
40
|
+
...validated,
|
|
41
|
+
});
|
|
42
|
+
res.json({ payment_option });
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
res.status(404).json({ message: error.message });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function DELETE(req, res) {
|
|
49
|
+
const { id } = req.params;
|
|
50
|
+
const service = req.scope.resolve(payment_options_1.PAYMENT_OPTION_MODULE);
|
|
51
|
+
const link = req.scope.resolve(utils_1.ContainerRegistrationKeys.LINK);
|
|
52
|
+
// Load first so we know the linked payment for cleanup.
|
|
53
|
+
const existing = await service.retrievePaymentOption(id).catch(() => null);
|
|
54
|
+
if (!existing) {
|
|
55
|
+
res.status(404).json({ message: "Payment option not found." });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// Best-effort: drop the payment <-> payment_option link if it exists.
|
|
59
|
+
if (existing.payment_id) {
|
|
60
|
+
await link
|
|
61
|
+
.dismiss({
|
|
62
|
+
[utils_1.Modules.PAYMENT]: { payment_id: existing.payment_id },
|
|
63
|
+
[payment_options_1.PAYMENT_OPTION_MODULE]: { payment_option_id: id },
|
|
64
|
+
})
|
|
65
|
+
.catch(() => { });
|
|
66
|
+
}
|
|
67
|
+
await service.deletePaymentOptions(id);
|
|
68
|
+
res.json({ id, object: "payment_option", deleted: true });
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvYXBpL2FkbWluL3BheW1lbnQtb3B0aW9ucy9baWRdL3JvdXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBMkJBLGtCQVVDO0FBRUQsb0JBZUM7QUFFRCx3QkF5QkM7QUF6RUQsaURBQTJDO0FBQzNDLHFEQUE4RTtBQUU5RSx5RUFBMkU7QUFFM0UsTUFBTSx5QkFBeUIsR0FBRyxPQUFDLENBQUMsTUFBTSxDQUFDO0lBQ3pDLGNBQWMsRUFBRSxPQUFDLENBQUMsTUFBTSxFQUFFLENBQUMsUUFBUSxFQUFFO0lBQ3JDLE1BQU0sRUFBRSxPQUFDLENBQUMsTUFBTSxDQUFDLE1BQU0sRUFBRSxDQUFDLFFBQVEsRUFBRTtJQUNwQyxNQUFNLEVBQUUsT0FBQyxDQUFDLE1BQU0sRUFBRSxDQUFDLFFBQVEsRUFBRTtJQUM3QixXQUFXLEVBQUUsT0FBQyxDQUFDLE1BQU0sRUFBRSxDQUFDLFFBQVEsRUFBRTtJQUNsQyxZQUFZLEVBQUUsT0FBQyxDQUFDLE1BQU0sRUFBRSxDQUFDLFFBQVEsRUFBRTtJQUNuQyxPQUFPLEVBQUUsT0FBQyxDQUFDLE1BQU0sRUFBRSxDQUFDLFFBQVEsRUFBRTtJQUM5QixjQUFjLEVBQUUsT0FBQyxDQUFDLE1BQU0sRUFBRSxDQUFDLFFBQVEsRUFBRTtJQUNyQyxjQUFjLEVBQUUsT0FBQyxDQU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QUUsQ0FBQztRQUNkLEdBQUcsQ0FBQyxNQUFNLENBQUMsR0FBRyxDQUFDLENBQUMsSUFBSSxDQUFDLEVBQUUsT0FBTyxFQUFFLDJCQUEyQixFQUFFLENBQUMsQ0FBQTtRQUM5RCxPQUFNO0lBQ1IsQ0FBQztJQUVELHNFQUFzRTtJQUN0RSxJQUFJLFFBQVEsQ0FBQyxVQUFVLEVBQUUsQ0FBQztRQUN4QixNQUFNLElBQUk7YUFDUCxPQUFPLENBQUM7WUFDUCxDQUFDLGVBQU8sQ0FBQyxPQUFPLENBQUMsRUFBRSxFQUFFLFVBQVUsRUFBRSxRQUFRLENBQUMsVUFBVSxFQUFFO1lBQ3RELENBQUMsdUNBQXFCLENBQUMsRUFBRSxFQUFFLGlCQUFpQixFQUFFLEVBQUUsRUFBRTtTQUNuRCxDQUFDO2FBQ0QsS0FBSyxDQUFDLEdBQUcsRUFBRSxHQUFFLENBQUMsQ0FBQyxDQUFBO0lBQ3BCLENBQUM7SUFFRCxNQUFNLE9BQU8sQ0FBQyxvQkFBb0IsQ0FBQyxFQUFFLENBQUMsQ0FBQTtJQUV0QyxHQUFHLENBQUMsSUFBSSxDQUFDLEVBQUUsRUFBRSxFQUFFLE1BQU0sRUFBRSxnQkFBZ0IsRUFBRSxPQUFPLEVBQUUsSUFBSSxFQUFFLENBQUMsQ0FBQTtBQUMzRCxDQUFDIn0=
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GET = GET;
|
|
4
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
5
|
+
const payment_options_1 = require("../../../modules/payment-options");
|
|
6
|
+
async function GET(req, res) {
|
|
7
|
+
const service = req.scope.resolve(payment_options_1.PAYMENT_OPTION_MODULE);
|
|
8
|
+
const query = req.scope.resolve(utils_1.ContainerRegistrationKeys.QUERY);
|
|
9
|
+
const { limit: limitRaw, offset: offsetRaw, q, status, payment_method, } = req.query;
|
|
10
|
+
const limit = limitRaw ? parseInt(limitRaw, 10) : 15;
|
|
11
|
+
const offset = offsetRaw ? parseInt(offsetRaw, 10) : 0;
|
|
12
|
+
const term = q?.trim();
|
|
13
|
+
const filters = {};
|
|
14
|
+
if (status) {
|
|
15
|
+
filters.status = status;
|
|
16
|
+
}
|
|
17
|
+
if (payment_method) {
|
|
18
|
+
filters.payment_method = payment_method;
|
|
19
|
+
}
|
|
20
|
+
if (term) {
|
|
21
|
+
const like = `%${term}%`;
|
|
22
|
+
const or = [
|
|
23
|
+
{ reference_code: { $ilike: like } },
|
|
24
|
+
{ concept: { $ilike: like } },
|
|
25
|
+
{ depositor_name: { $ilike: like } },
|
|
26
|
+
{ payment_method: { $ilike: like } },
|
|
27
|
+
{ authorizer: { $ilike: like } },
|
|
28
|
+
{ institution: { $ilike: like } },
|
|
29
|
+
{ payment_id: { $ilike: like } },
|
|
30
|
+
];
|
|
31
|
+
// If the term is a pure number, treat it as an order display id and match
|
|
32
|
+
// the payment options linked to that order's payment(s).
|
|
33
|
+
if (/^\d+$/.test(term)) {
|
|
34
|
+
const { data: orders } = await query.graph({
|
|
35
|
+
entity: "order",
|
|
36
|
+
filters: { display_id: parseInt(term, 10) },
|
|
37
|
+
fields: ["id", "payment_collections.payments.id"],
|
|
38
|
+
});
|
|
39
|
+
const paymentIds = orders.flatMap((o) => (o.payment_collections ?? []).flatMap((pc) => (pc.payments ?? []).map((p) => p?.id).filter(Boolean)));
|
|
40
|
+
if (paymentIds.length) {
|
|
41
|
+
or.push({ payment_id: { $in: paymentIds } });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
filters.$or = or;
|
|
45
|
+
}
|
|
46
|
+
const [payment_options, count] = await service.listAndCountPaymentOptions(filters, {
|
|
47
|
+
skip: offset,
|
|
48
|
+
take: limit,
|
|
49
|
+
order: { created_at: "DESC" },
|
|
50
|
+
});
|
|
51
|
+
// Enrich the page with the linked order's display id.
|
|
52
|
+
const paymentIds = [
|
|
53
|
+
...new Set(payment_options.map((po) => po.payment_id).filter(Boolean)),
|
|
54
|
+
];
|
|
55
|
+
let orderByPaymentId = {};
|
|
56
|
+
if (paymentIds.length) {
|
|
57
|
+
const { data: payments } = await query.graph({
|
|
58
|
+
entity: "payment",
|
|
59
|
+
filters: { id: paymentIds },
|
|
60
|
+
fields: [
|
|
61
|
+
"id",
|
|
62
|
+
"payment_collection.order.id",
|
|
63
|
+
"payment_collection.order.display_id",
|
|
64
|
+
],
|
|
65
|
+
});
|
|
66
|
+
orderByPaymentId = payments.reduce((acc, p) => {
|
|
67
|
+
const order = p?.payment_collection?.order;
|
|
68
|
+
if (order) {
|
|
69
|
+
acc[p.id] = { id: order.id, display_id: order.display_id };
|
|
70
|
+
}
|
|
71
|
+
return acc;
|
|
72
|
+
}, {});
|
|
73
|
+
}
|
|
74
|
+
const enriched = payment_options.map((po) => {
|
|
75
|
+
const order = po.payment_id ? orderByPaymentId[po.payment_id] : undefined;
|
|
76
|
+
return {
|
|
77
|
+
...po,
|
|
78
|
+
order_id: order?.id ?? null,
|
|
79
|
+
order_display_id: order?.display_id ?? null,
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
res.json({ payment_options: enriched, count, limit, offset });
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvYXBpL2FkbWluL3BheW1lbnQtb3B0aW9ucy9yb3V0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQWdCQSxrQkEwR0M7QUE5R0QscURBQXFFO0FBRXJFLHNFQUF3RTtBQUVqRSxLQUFLLFVBQVUsR0FBRyxDQUFDLEdBQWtCLEVBQUUsR0FBbUI7SUFDL0QsTUFBTSxPQUFPLEdBQUcsR0FBRyxDQUFDLEtBQUssQ0FBQyxP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