diff --git a/modules/customer-invoices/src/web/components/editor/items/item-row.tsx b/modules/customer-invoices/src/web/components/editor/items/item-row.tsx new file mode 100644 index 00000000..327e9384 --- /dev/null +++ b/modules/customer-invoices/src/web/components/editor/items/item-row.tsx @@ -0,0 +1,230 @@ +import { Button, Checkbox, TableCell, TableRow, Tooltip, TooltipContent, TooltipTrigger } from "@repo/shadcn-ui/components"; +import { ArrowDownIcon, ArrowUpIcon, CopyIcon, Trash2Icon } from "lucide-react"; +import { useEffect } from 'react'; +import { Controller, useFormContext } from "react-hook-form"; +import { useCalcInvoiceItemTotals } from '../../../hooks'; +import { useTranslation } from '../../../i18n'; +import { CustomerInvoiceItemFormData } from '../../../schemas'; +import { CustomerInvoiceTaxesMultiSelect } from '../../customer-invoice-taxes-multi-select'; +import { AmountDTOInputField } from './amount-dto-input-field'; +import { HoverCardTotalsSummary } from './hover-card-total-summary'; +import { PercentageDTOInputField } from './percentage-dto-input-field'; +import { QuantityDTOInputField } from './quantity-dto-input-field'; + +export type ItemRowProps = { + + item: CustomerInvoiceItemFormData; + rowIndex: number; + isSelected: boolean; + isFirst: boolean; + isLast: boolean; + readOnly: boolean; + onToggleSelect: () => void; + onDuplicate: () => void; + onMoveUp: () => void; + onMoveDown: () => void; + onRemove: () => void; +} + + +export const ItemRow = ({ item, + rowIndex, + isSelected, + isFirst, + isLast, + readOnly, + onToggleSelect, + onDuplicate, + onMoveUp, + onMoveDown, + onRemove, }: ItemRowProps) => { + const { t } = useTranslation(); + + const { control, setValue } = useFormContext(); + const totals = useCalcInvoiceItemTotals(item); + + console.log(totals); + + // sincroniza el total con el form + useEffect(() => { + if (totals?.totalDTO) { + setValue?.(`items.${rowIndex}.total_amount`, totals.totalDTO); + } + }, [totals.totalDTO, control, rowIndex]); + + + return ( + + {/* selección */} + +
+ +
+
+ + {/* # */} + + + {rowIndex + 1} + + + + {/* description */} + + ( +