.
This commit is contained in:
parent
95edcbcdb7
commit
608169c2b9
@ -1,31 +1,7 @@
|
|||||||
import {
|
import { Button, Separator, Tooltip, TooltipContent, TooltipTrigger } from "@/ui";
|
||||||
Button,
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuCheckboxItem,
|
|
||||||
DropdownMenuContent,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
Popover,
|
|
||||||
PopoverContent,
|
|
||||||
PopoverTrigger,
|
|
||||||
Separator,
|
|
||||||
Tooltip,
|
|
||||||
TooltipContent,
|
|
||||||
TooltipTrigger,
|
|
||||||
} from "@/ui";
|
|
||||||
import { Table } from "@tanstack/react-table";
|
import { Table } from "@tanstack/react-table";
|
||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
import {
|
import { CirclePlusIcon, CopyPlusIcon, PackagePlusIcon, ScanIcon, Trash2Icon } from "lucide-react";
|
||||||
CalendarIcon,
|
|
||||||
CirclePlusIcon,
|
|
||||||
ClockIcon,
|
|
||||||
CopyPlusIcon,
|
|
||||||
ForwardIcon,
|
|
||||||
MoreVerticalIcon,
|
|
||||||
ReplyAllIcon,
|
|
||||||
ReplyIcon,
|
|
||||||
ScanIcon,
|
|
||||||
Trash2Icon,
|
|
||||||
} from "lucide-react";
|
|
||||||
|
|
||||||
export const QuoteItemsSortableDataTableToolbar = ({ table }: { table: Table<unknown> }) => {
|
export const QuoteItemsSortableDataTableToolbar = ({ table }: { table: Table<unknown> }) => {
|
||||||
const selectedRowsCount = table.getSelectedRowModel().rows.length;
|
const selectedRowsCount = table.getSelectedRowModel().rows.length;
|
||||||
@ -89,112 +65,24 @@ export const QuoteItemsSortableDataTableToolbar = ({ table }: { table: Table<unk
|
|||||||
<div className='flex items-center gap-2'>
|
<div className='flex items-center gap-2'>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<Button
|
<Button type='button' variant='ghost' onClick={() => table.options.meta?.appendItem()}>
|
||||||
type='button'
|
<CirclePlusIcon className='w-4 h-4 mr-2' />
|
||||||
variant='ghost'
|
<span>{t("common.append_empty_row")}</span>
|
||||||
size='icon'
|
|
||||||
onClick={() => table.options.meta?.appendItem()}
|
|
||||||
>
|
|
||||||
<CirclePlusIcon className='w-4 h-4' />
|
|
||||||
<span className='sr-only'>Añadir</span>
|
|
||||||
</Button>
|
</Button>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent>Añadir fila</TooltipContent>
|
<TooltipContent>{t("common.append_empty_row_tooltip")}</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
<Separator orientation='vertical' className='h-6 mx-1 bg-muted-foreground/30' />
|
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<Popover>
|
<TooltipTrigger asChild>
|
||||||
<PopoverTrigger asChild>
|
<Button type='button' variant='ghost' onClick={() => table.options.meta?.appendItem()}>
|
||||||
<TooltipTrigger asChild>
|
<PackagePlusIcon className='w-4 h-4 mr-2' />
|
||||||
<Button variant='ghost' size='icon'>
|
<span>{t("common.append_article")}</span>
|
||||||
<ClockIcon className='w-4 h-4' />
|
</Button>
|
||||||
<span className='sr-only'>Snooze</span>
|
</TooltipTrigger>
|
||||||
</Button>
|
<TooltipContent>{t("common.append_article_tooltip")}</TooltipContent>
|
||||||
</TooltipTrigger>
|
|
||||||
</PopoverTrigger>
|
|
||||||
<PopoverContent className='flex w-[535px] p-0'>
|
|
||||||
<div className='flex flex-col gap-2 px-2 py-4 border-r'>
|
|
||||||
<div className='px-4 text-sm font-medium'>Snooze until</div>
|
|
||||||
<div className='grid min-w-[250px] gap-1'>
|
|
||||||
<Button variant='ghost' className='justify-start font-normal'>
|
|
||||||
Later today <span className='ml-auto text-muted-foreground'></span>
|
|
||||||
</Button>
|
|
||||||
<Button variant='ghost' className='justify-start font-normal'>
|
|
||||||
Tomorrow
|
|
||||||
<span className='ml-auto text-muted-foreground'></span>
|
|
||||||
</Button>
|
|
||||||
<Button variant='ghost' className='justify-start font-normal'>
|
|
||||||
This weekend
|
|
||||||
<span className='ml-auto text-muted-foreground'></span>
|
|
||||||
</Button>
|
|
||||||
<Button variant='ghost' className='justify-start font-normal'>
|
|
||||||
Next week
|
|
||||||
<span className='ml-auto text-muted-foreground'></span>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className='p-2'>
|
|
||||||
<CalendarIcon />
|
|
||||||
</div>
|
|
||||||
</PopoverContent>
|
|
||||||
</Popover>
|
|
||||||
<TooltipContent>Snooze</TooltipContent>
|
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex items-center gap-2 ml-auto'>
|
<div className='flex items-center gap-2 ml-auto'></div>
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<Button variant='ghost' size='icon'>
|
|
||||||
<ReplyIcon className='w-4 h-4' />
|
|
||||||
<span className='sr-only'>Reply</span>
|
|
||||||
</Button>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent>Reply</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<Button variant='ghost' size='icon'>
|
|
||||||
<ReplyAllIcon className='w-4 h-4' />
|
|
||||||
<span className='sr-only'>Reply all</span>
|
|
||||||
</Button>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent>Reply all</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<Button variant='ghost' size='icon'>
|
|
||||||
<ForwardIcon className='w-4 h-4' />
|
|
||||||
<span className='sr-only'>Forward</span>
|
|
||||||
</Button>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent>Forward</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
<Separator orientation='vertical' className='h-6 mx-1 bg-muted-foreground/30' />
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button variant='ghost' size='icon'>
|
|
||||||
<MoreVerticalIcon className='w-4 h-4' />
|
|
||||||
<span className='sr-only'>Columnas</span>
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent align='end'>
|
|
||||||
{table.getAllColumns().map((column) => {
|
|
||||||
return (
|
|
||||||
<DropdownMenuCheckboxItem
|
|
||||||
key={column.id}
|
|
||||||
disabled={!column.getCanHide()}
|
|
||||||
className='capitalize'
|
|
||||||
checked={column.getIsVisible()}
|
|
||||||
onCheckedChange={(value) => column.toggleVisibility(!!value)}
|
|
||||||
>
|
|
||||||
{column.id}
|
|
||||||
</DropdownMenuCheckboxItem>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -164,15 +164,15 @@ export const QuoteDetailsCardEditor = ({
|
|||||||
const { table, row } = props;
|
const { table, row } = props;
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
label: "Duplicar",
|
label: t("common.duplicate_rows"),
|
||||||
onClick: () => table.options.meta?.duplicateItems(row.index),
|
onClick: () => table.options.meta?.duplicateItems(row.index),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Insertar fila encima",
|
label: t("common.insert_row_above"),
|
||||||
onClick: () => table.options.meta?.insertItem(row.index),
|
onClick: () => table.options.meta?.insertItem(row.index),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Insertar fila debajo",
|
label: t("common.insert_row_below"),
|
||||||
onClick: () => table.options.meta?.insertItem(row.index + 1),
|
onClick: () => table.options.meta?.insertItem(row.index + 1),
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ export const QuoteDetailsCardEditor = ({
|
|||||||
label: "-",
|
label: "-",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Eliminar",
|
label: t("common.remove_row"),
|
||||||
shortcut: "⌘⌫",
|
shortcut: "⌘⌫",
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
table.options.meta?.deleteItems(row.index);
|
table.options.meta?.deleteItems(row.index);
|
||||||
|
|||||||
@ -19,10 +19,6 @@ import { QuotePricesResume } from "./components";
|
|||||||
import { QuoteDetailsCardEditor, QuoteGeneralCardEditor } from "./components/editors";
|
import { QuoteDetailsCardEditor, QuoteGeneralCardEditor } from "./components/editors";
|
||||||
import { useQuotes } from "./hooks";
|
import { useQuotes } from "./hooks";
|
||||||
|
|
||||||
/*type QuoteDataForm = Omit<IGetQuote_Response_DTO, "items"> & {
|
|
||||||
items: IGetQuote_QuoteItem_Response_DTO;
|
|
||||||
};*/
|
|
||||||
|
|
||||||
type QuoteDataForm = IGetQuote_Response_DTO;
|
type QuoteDataForm = IGetQuote_Response_DTO;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
@ -37,15 +33,6 @@ export const QuoteEdit = () => {
|
|||||||
);
|
);
|
||||||
const [quoteLanguage, setQuoteLanguage] = useState<Language>(Language.createDefaultCode().object);
|
const [quoteLanguage, setQuoteLanguage] = useState<Language>(Language.createDefaultCode().object);
|
||||||
|
|
||||||
/*const { data: userIdentity } = useGetIdentity();
|
|
||||||
console.log(userIdentity);
|
|
||||||
|
|
||||||
const { flag } = useLocalization({
|
|
||||||
locale: userIdentity?.language ?? "es-es",
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(flag);*/
|
|
||||||
|
|
||||||
const { useOne, useUpdate } = useQuotes();
|
const { useOne, useUpdate } = useQuotes();
|
||||||
|
|
||||||
const { data, status, error: queryError } = useOne(quoteId);
|
const { data, status, error: queryError } = useOne(quoteId);
|
||||||
@ -159,106 +146,6 @@ export const QuoteEdit = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/* useEffect(() => {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
const { unsubscribe } = watch((_, { name, type }) => {
|
|
||||||
const value = getValues();
|
|
||||||
|
|
||||||
console.log(name);
|
|
||||||
|
|
||||||
if (name) {
|
|
||||||
if (name === "currency_code") {
|
|
||||||
setQuoteCurrency(
|
|
||||||
CurrencyData.createFromCode(value.currency_code ?? CurrencyData.DEFAULT_CURRENCY_CODE)
|
|
||||||
.object
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name === "lang_code") {
|
|
||||||
setQuoteLanguage(
|
|
||||||
Language.createFromCode(value.lang_code ?? Language.DEFAULT_LANGUAGE_CODE).object
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name === "items") {
|
|
||||||
console.log(">> Recalculo todas las líneas");
|
|
||||||
const { items } = value;
|
|
||||||
|
|
||||||
let quoteSubtotal = MoneyValue.create({
|
|
||||||
amount: 0,
|
|
||||||
scale: 4,
|
|
||||||
}).object;
|
|
||||||
|
|
||||||
// Recálculo líneas
|
|
||||||
items &&
|
|
||||||
items.map((item, index) => {
|
|
||||||
const itemTotals = calculateQuoteItemTotals(item);
|
|
||||||
quoteSubtotal = quoteSubtotal.add(itemTotals.totalPrice);
|
|
||||||
setValue(`items.${index}.subtotal_price`, itemTotals.subtotalPrice.toObject());
|
|
||||||
setValue(`items.${index}.total_price`, itemTotals.totalPrice.toObject());
|
|
||||||
});
|
|
||||||
|
|
||||||
// Recálculo completo
|
|
||||||
setValue("subtotal_price", quoteSubtotal.convertScale(2).toObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name.endsWith("quantity") || name.endsWith("unit_price") || name.endsWith("discount")) {
|
|
||||||
console.group(">>>>>>>>>>>>>");
|
|
||||||
|
|
||||||
const { items } = value;
|
|
||||||
|
|
||||||
const [, indexString, fieldName] = String(name).split(".");
|
|
||||||
const index = parseInt(indexString);
|
|
||||||
|
|
||||||
console.group(">> Voy a recalcular la línea ", index, items[index]);
|
|
||||||
|
|
||||||
const itemTotals_1 = calculateQuoteItemTotals(items[index]);
|
|
||||||
setValue(`items.${index}.subtotal_price`, itemTotals_1.subtotalPrice.toObject());
|
|
||||||
setValue(`items.${index}.total_price`, itemTotals_1.totalPrice.toObject());
|
|
||||||
|
|
||||||
console.log(">> Total de la línea -> ", index, itemTotals_1.subtotalPrice.toObject());
|
|
||||||
|
|
||||||
console.groupEnd();
|
|
||||||
|
|
||||||
// Recálculo completo
|
|
||||||
let quoteSubtotal = MoneyValue.create({
|
|
||||||
amount: 0,
|
|
||||||
scale: 4,
|
|
||||||
}).object;
|
|
||||||
|
|
||||||
console.group(">> Recalculo todas las líneas");
|
|
||||||
|
|
||||||
items &&
|
|
||||||
items.map((item, itemIndex) => {
|
|
||||||
const itemTotals_2 = calculateQuoteItemTotals(item);
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
">> Recalculo la linea ",
|
|
||||||
itemIndex,
|
|
||||||
itemTotals_2.subtotalPrice.toObject()
|
|
||||||
);
|
|
||||||
|
|
||||||
quoteSubtotal = quoteSubtotal.add(itemTotals_2.totalPrice);
|
|
||||||
setValue(`items.${itemIndex}.subtotal_price`, itemTotals_2.subtotalPrice.toObject());
|
|
||||||
setValue(`items.${itemIndex}.total_price`, itemTotals_2.totalPrice.toObject());
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
">> Gruardo el total en la cabecera ",
|
|
||||||
quoteSubtotal.convertScale(2).toObject()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Recálculo completo
|
|
||||||
setValue("subtotal_price", quoteSubtotal.convertScale(2).toObject());
|
|
||||||
console.groupEnd();
|
|
||||||
|
|
||||||
console.groupEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return () => unsubscribe();
|
|
||||||
}, [watch, getValues, setValue]);*/
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { unsubscribe } = watch((_, { name, type }) => {
|
const { unsubscribe } = watch((_, { name, type }) => {
|
||||||
|
|||||||
@ -95,8 +95,9 @@
|
|||||||
"subtitle": "",
|
"subtitle": "",
|
||||||
"tabs": {
|
"tabs": {
|
||||||
"all": "All",
|
"all": "All",
|
||||||
|
"emitted": "Emitted",
|
||||||
"draft": "Draft",
|
"draft": "Draft",
|
||||||
"archived": "Archive"
|
"archived": "Archived"
|
||||||
},
|
},
|
||||||
"columns": {
|
"columns": {
|
||||||
"date": "Date",
|
"date": "Date",
|
||||||
|
|||||||
@ -95,8 +95,8 @@
|
|||||||
"subtitle": "",
|
"subtitle": "",
|
||||||
"tabs": {
|
"tabs": {
|
||||||
"all": "Todas",
|
"all": "Todas",
|
||||||
"draft": "Borradores",
|
|
||||||
"emitted": "Emitidas",
|
"emitted": "Emitidas",
|
||||||
|
"draft": "Borradores",
|
||||||
"archived": "Archivadas"
|
"archived": "Archivadas"
|
||||||
},
|
},
|
||||||
"columns": {
|
"columns": {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user