diff --git a/src/modules/core/components/form/FormFieldSelect.tsx b/src/modules/core/components/form/FormFieldSelect.tsx index 8e9ae193..35a3d933 100644 --- a/src/modules/core/components/form/FormFieldSelect.tsx +++ b/src/modules/core/components/form/FormFieldSelect.tsx @@ -36,7 +36,7 @@ export const FormFieldSelect = ({ control={control} name={name} render={({ field }: any) => ( - + {label}
+ IconProps & React.RefAttributes | any >; name: string; } diff --git a/src/modules/payments/components/TablesPendingPayments.tsx b/src/modules/payments/components/TablesPendingPayments.tsx index 4c451400..60463549 100644 --- a/src/modules/payments/components/TablesPendingPayments.tsx +++ b/src/modules/payments/components/TablesPendingPayments.tsx @@ -1,4 +1,4 @@ -import { Label, Separator } from "@/components"; +import { FormLabel, Label, Separator } from "@/components"; import { ErrorLoading, Loading } from "@/modules/core/components"; import { RootState, useAppDispatch, useAppSelector } from "@/redux/store"; import { useEffect } from "react"; @@ -10,15 +10,23 @@ import { DataTableForm } from "@/modules/core/components/table/DataTableForm"; import { toast } from "sonner"; import { columnsPaymentsPendingHarvestActions } from "./columns/ColumnsTablePaymentsPendingHarvest"; import { columnsPaymentsPendingWorkActions } from "./columns/ColumnsTablePaymentsPendingWork"; -import { columnsPaymentsToPayActions } from "./columns/ColumnsTablePaymentsToPay"; +import { + columnsPaymentsToPayActions, + columnsPaymentsToPayActionsView, +} from "./columns/ColumnsTablePaymentsToPay"; import { UseFormReturn } from "react-hook-form"; interface Props { employeeId: string; form: UseFormReturn; + readOnly?: boolean; } -export const TablesPendingPayments = ({ employeeId, form }: Props) => { +export const TablesPendingPayments = ({ + employeeId, + form, + readOnly = false, +}: Props) => { const { data, isLoading, isError } = useGetEmployeePendingPayments(employeeId); @@ -59,29 +67,37 @@ export const TablesPendingPayments = ({ employeeId, form }: Props) => { return ( <> - + {!readOnly && ( + <> + + + + + )} - - - - - - - + {!readOnly && ( + <> + + + + + )} { > diff --git a/src/modules/payments/components/columns/ActionsTablePaymentsToPayView.tsx b/src/modules/payments/components/columns/ActionsTablePaymentsToPayView.tsx new file mode 100644 index 00000000..1f6086f0 --- /dev/null +++ b/src/modules/payments/components/columns/ActionsTablePaymentsToPayView.tsx @@ -0,0 +1,30 @@ +import { ActionsTable } from "@/modules/core/components"; +import { ItemCopyIdRecord } from "@/modules/core/components/table/actions/ItemCopyIdRecord"; +import { ItemNavigate } from "@/modules/core/components/table/actions/ItemNavigate"; +import { Link } from "lucide-react"; +import { useState } from "react"; + +export const ActionsTablePaymentsToPayView = ({ record }: any) => { + const [openDropDownMenu, setOpenDropDownMenu] = useState(false); + + console.log({ record }); + + return ( + + + + + ); +}; diff --git a/src/modules/payments/components/columns/ColumnsTablePaymentsPendingHarvest.tsx b/src/modules/payments/components/columns/ColumnsTablePaymentsPendingHarvest.tsx index d1a3931a..058662ec 100644 --- a/src/modules/payments/components/columns/ColumnsTablePaymentsPendingHarvest.tsx +++ b/src/modules/payments/components/columns/ColumnsTablePaymentsPendingHarvest.tsx @@ -125,6 +125,7 @@ export const columnsPaymentsPendingHarvestActions = [ value_pay, payment_is_pending, type: "harvest", + harvest: { id: harvestDetail?.harvest?.id }, }) ); dispatch(calculateTotal()); diff --git a/src/modules/payments/components/columns/ColumnsTablePaymentsPendingWork.tsx b/src/modules/payments/components/columns/ColumnsTablePaymentsPendingWork.tsx index b478663a..bce0f6c0 100644 --- a/src/modules/payments/components/columns/ColumnsTablePaymentsPendingWork.tsx +++ b/src/modules/payments/components/columns/ColumnsTablePaymentsPendingWork.tsx @@ -108,6 +108,7 @@ export const columnsPaymentsPendingWorkActions = [ value_pay, payment_is_pending, type: "work", + work: { id: workDetail?.work?.id }, }) ); dispatch(calculateTotal()); diff --git a/src/modules/payments/components/columns/ColumnsTablePaymentsToPay.tsx b/src/modules/payments/components/columns/ColumnsTablePaymentsToPay.tsx index 4ca90ead..98b3c498 100644 --- a/src/modules/payments/components/columns/ColumnsTablePaymentsToPay.tsx +++ b/src/modules/payments/components/columns/ColumnsTablePaymentsToPay.tsx @@ -13,6 +13,7 @@ import { FormatMoneyValue } from "@/modules/core/helpers/FormatMoneyValue"; import { PaymentPending } from "../../interfaces/PaymentPending"; import { calculateTotal, removeRecordToPay } from "../../utils/paymentSlice"; import { ActionsTablePaymentsToPay } from "./ActionsTablePaymentsToPay"; +import { ActionsTablePaymentsToPayView } from "./ActionsTablePaymentsToPayView"; export const columnsPaymentsToPay: ColumnDef[] = [ { @@ -79,9 +80,9 @@ export const columnsPaymentsToPay: ColumnDef[] = [ cell: ({ row }) => { const value = row.getValue("type"); return value === "harvest" ? ( - Harvest + Cosecha ) : ( - Work + Trabajo ); }, header: ({ column }: any) => { @@ -109,8 +110,18 @@ export const columnsPaymentsToPayActions = [ const dispatch = useAppDispatch(); const handleDelete = () => { + const { date, ...rest } = record; + + const data = { + ...rest, + [rest.type === "harvest" ? "harvest" : "work"]: { + id: rest[rest.type === "harvest" ? "harvest" : "work"].id, + date, + }, + }; + + dispatch(removeRecordToPay({ ...data })); dispatch(calculateTotal()); - dispatch(removeRecordToPay({ ...record })); toast.success(`Se ha eliminado el registro`); }; @@ -121,7 +132,22 @@ export const columnsPaymentsToPayActions = [ }, ]; +export const columnsPaymentsToPayActionsView = [ + ...columnsPaymentsToPay, + { + id: "actions", + cell: ({ row }: any) => { + const record = row.original; + + console.log({ record }); + + return ; + }, + }, +]; + export default { columnsPaymentsToPay, columnsPaymentsToPayActions, + columnsPaymentsToPayActionsView, }; diff --git a/src/modules/payments/components/forms/FormPayment.tsx b/src/modules/payments/components/forms/FormPayment.tsx index 18eb6a80..bda5b9e8 100644 --- a/src/modules/payments/components/forms/FormPayment.tsx +++ b/src/modules/payments/components/forms/FormPayment.tsx @@ -1,14 +1,14 @@ -import { Badge, Button, Form, Label, Separator } from "@/components"; +import { Alert, Badge, Button, Form, Separator } from "@/components"; +import { AlertDescription, AlertTitle } from "@/components/ui/alert"; import { ButtonsForm } from "@/modules/core/components/ButtonsForm"; import { FormFieldCalendar } from "@/modules/core/components/form/FormFieldCalendar"; import { FormFieldCommand } from "@/modules/core/components/form/FormFieldCommand"; -import { FormFieldDataTable } from "@/modules/core/components/form/FormFieldDataTable"; import { FormFieldInput } from "@/modules/core/components/form/FormFieldInput"; import { FormFieldSelect } from "@/modules/core/components/form/FormFieldSelect"; -import { DataTableForm } from "@/modules/core/components/table/DataTableForm"; import { FormatMoneyValue } from "@/modules/core/helpers/FormatMoneyValue"; import { FormProps } from "@/modules/core/interfaces/FormProps"; import { useAppDispatch } from "@/redux/store"; +import { ExclamationTriangleIcon } from "@radix-ui/react-icons"; import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import { toast } from "sonner"; @@ -20,7 +20,6 @@ import { calculateTotal, resetAll, } from "../../utils/paymentSlice"; -import { columnsPaymentsToPay } from "../columns/ColumnsTablePaymentsToPay"; import { TablesPendingPayments } from "../TablesPendingPayments"; export const FormPayment = ({ @@ -42,8 +41,6 @@ export const FormPayment = ({ const dispatch = useAppDispatch(); useEffect(() => { - // dispatch(resetDataEmployee()); - // dispatch(resetPaymentsToPay()); if (defaultValues) { const { payments_harvest = [], @@ -52,14 +49,10 @@ export const FormPayment = ({ } = defaultValues; const data = { ...rest, - // categories: { - // harvests: payments_harvest, - // works: payments_work, - // }, }; - // console.log(data); - formPayment.reset(data); + formPayment.reset(data); + dispatch(resetAll()); dispatch( addRecordsToPay( defaultValues.payments_harvest.map((item: any) => { @@ -69,6 +62,7 @@ export const FormPayment = ({ payment_is_pending: item?.harvests_detail?.payment_is_pending, type: "harvest", date: item?.harvests_detail?.harvest?.date, + harvest: { id: item?.harvests_detail?.harvest?.id }, }; }) ) @@ -82,11 +76,13 @@ export const FormPayment = ({ payment_is_pending: item?.works_detail?.payment_is_pending, type: "work", date: item?.works_detail?.work?.date, + work: { id: item?.works_detail?.work?.id }, }; }) ) ); dispatch(calculateTotal()); + setEmployeeId(defaultValues.employee.id); } }, []); @@ -136,8 +132,6 @@ export const FormPayment = ({ return [...employees]; }; - // Table components - return (
{/* Tablas */} - + {!readOnly && ( + + )} {/* TODO: Mejorar estilo de los badges */} {employeeId.length <= 0 ? ( - + + + Aviso + + Debes seleccionar un empleado para que se muestren los pagos + pendientes. + + ) : ( - + )} {/* Fin Tablas */} - {defaultValues && ( - - - - )} -