fix: enhance pricing component formatting and update sorting logic in PrezzarioTable
This commit is contained in:
parent
f979fd9721
commit
19d273ff49
6 changed files with 38 additions and 24 deletions
|
|
@ -172,7 +172,11 @@ export const PricingComponent = ({
|
|||
className="xs:text-3xl text-2xl font-semibold sm:text-6xl"
|
||||
data-role="amount"
|
||||
>
|
||||
<AnimatedNumber value={secondPayment} format={customFormat} />
|
||||
<AnimatedNumber
|
||||
value={secondPayment}
|
||||
format={customFormat}
|
||||
precision={secondPayment % 1 === 0 ? 0 : 2}
|
||||
/>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ export const PrezzarioTable = ({
|
|||
pinnedFiltri={pinnedFiltri}
|
||||
searchColumn={searchFiltro}
|
||||
columns_titles={columns_titles}
|
||||
defaultSort={[{ desc: false, id: "categoria" }]}
|
||||
defaultSort={[{ desc: false, id: "id" }]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import {
|
|||
SelectValue,
|
||||
} from "~/components/ui/select";
|
||||
import { useEffect } from "react";
|
||||
import { DevTool } from "@hookform/devtools";
|
||||
|
||||
type FormPrezzoProps = {
|
||||
initialValues: Prezziario | null;
|
||||
|
|
@ -130,6 +131,7 @@ export const FormPrezzo = ({
|
|||
return (
|
||||
<>
|
||||
<Form {...form}>
|
||||
<DevTool control={form.control} />
|
||||
<form
|
||||
onSubmit={form.handleSubmit(onSubmit)}
|
||||
className="space-y-4 px-0.5"
|
||||
|
|
@ -237,10 +239,11 @@ export const FormPrezzo = ({
|
|||
<Input
|
||||
{...field}
|
||||
type="number"
|
||||
step={0.01}
|
||||
id="prezzo"
|
||||
value={Number(field.value) / 100}
|
||||
onChange={(v) => {
|
||||
field.onChange(parseInt(v.target.value) * 100);
|
||||
field.onChange(parseFloat(v.target.value) * 100);
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
|
|
|
|||
|
|
@ -9,12 +9,13 @@ import {
|
|||
createTRPCRouter,
|
||||
publicProcedure,
|
||||
} from "~/server/api/trpc";
|
||||
import { getPrezziarioByIdHandler } from "~/server/controllers/prezziario.controller";
|
||||
|
||||
import { db } from "~/server/db";
|
||||
import {
|
||||
addPrezziario,
|
||||
deletePrezziario,
|
||||
getPrezziario,
|
||||
getPrezziarioByIdHandler,
|
||||
getPrezziarioByTipologia,
|
||||
getPrezziarioConsulenza,
|
||||
updatePrezziario,
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
import type { PrezziarioIdprezziario } from "~/schemas/public/Prezziario";
|
||||
import type { Querier } from "~/server/db";
|
||||
|
||||
export const getPrezziarioByIdHandler = async ({
|
||||
db,
|
||||
input,
|
||||
}: {
|
||||
db: Querier;
|
||||
input: {
|
||||
idprezziario: PrezziarioIdprezziario;
|
||||
};
|
||||
}) => {
|
||||
return await db
|
||||
.selectFrom("prezziario")
|
||||
.selectAll()
|
||||
.where("prezziario.idprezziario", "=", input.idprezziario)
|
||||
.executeTakeFirst();
|
||||
};
|
||||
|
|
@ -7,6 +7,7 @@ import type {
|
|||
import { db, type Querier } from "~/server/db";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import TipologiaPosizioneEnum from "~/schemas/public/TipologiaPosizioneEnum";
|
||||
import { sql } from "kysely";
|
||||
|
||||
export const getPrezziario = async () => {
|
||||
try {
|
||||
|
|
@ -14,7 +15,7 @@ export const getPrezziario = async () => {
|
|||
.selectFrom("prezziario")
|
||||
.selectAll()
|
||||
.where("isActive", "=", true)
|
||||
.orderBy("prezzo_cent", "asc")
|
||||
.orderBy("idprezziario", "asc")
|
||||
.execute();
|
||||
} catch (error) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -24,6 +25,22 @@ export const getPrezziario = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
export const getPrezziarioByIdHandler = async ({
|
||||
db,
|
||||
input,
|
||||
}: {
|
||||
db: Querier;
|
||||
input: {
|
||||
idprezziario: PrezziarioIdprezziario;
|
||||
};
|
||||
}) => {
|
||||
return await db
|
||||
.selectFrom("prezziario")
|
||||
.selectAll()
|
||||
.where("prezziario.idprezziario", "=", input.idprezziario)
|
||||
.executeTakeFirst();
|
||||
};
|
||||
|
||||
export const addPrezziario = async ({
|
||||
db,
|
||||
input,
|
||||
|
|
@ -139,7 +156,14 @@ export const getPrezziarioByTipologia = async ({
|
|||
} else if (tipologia == TipologiaPosizioneEnum.Stabile) {
|
||||
qry2 = qry2.where("isStabile", "=", true);
|
||||
}
|
||||
const saldi = await qry2.orderBy("prezzo_cent", "asc").execute();
|
||||
// query with order by numeric part of idprezziario, handling '+' at the end
|
||||
const saldi = await qry2
|
||||
.orderBy(
|
||||
sql`CAST(REGEXP_REPLACE(idprezziario, '[^0-9]+', '', 'g') AS INTEGER),
|
||||
CASE WHEN idprezziario LIKE '%+%' THEN 1 ELSE 0 END`,
|
||||
)
|
||||
.execute();
|
||||
//const saldi = await qry2.orderBy("prezzo_cent", "asc").execute();
|
||||
|
||||
if (!saldi) {
|
||||
throw new TRPCError({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue