feat: update Receipt data structure to remove items and include packName, discount, and amount

This commit is contained in:
Marco Pedone 2026-03-08 01:22:03 +01:00
parent 0e936140f2
commit 2aa5ccea1d
2 changed files with 25 additions and 40 deletions

View file

@ -71,21 +71,18 @@ export function ReceiptGenerator({
);
}
interface Item {
description: string;
price: number;
discount: number;
}
export interface PurchaseData {
export type PurchaseData = {
ordineId: OrdiniOrdineId;
date: Date;
clienteNome: string;
clienteIndirizzo: string;
paymentMethod: string;
items: Item[];
}
packName: string;
sconto: number;
amount_cent: number;
};
interface ReceiptProps {
data: PurchaseData;
@ -97,10 +94,6 @@ function Receipt({ data }: ReceiptProps) {
const companyAddress =
"Via Beata Giovanna 1\nBassano del Grappa (VI) 36061\nItalia";
const total = data.items.reduce(
(acc, item) => acc + item.price * (1 - item.discount),
0,
);
const note =
"La presente è non costituisce ricevuta o fattura fiscale ai sensi dell'Art.21, DPR 633/72.\nSeguirà fattura elettronica direttamente al tuo indirizzo di posta.";
const footer =
@ -158,28 +151,22 @@ function Receipt({ data }: ReceiptProps) {
<thead>
<tr className="border-b">
<th className="py-2 text-left">Descrizione</th>
<th className="py-2 text-right">Prezzo</th>
<th className="py-2 text-right">Sconto</th>
<th className="py-2 text-right">Sconto applicato</th>
<th className="py-2 text-right">Importo</th>
</tr>
</thead>
<tbody>
{data.items.map((item) => (
<tr className="border-b" key={item.description}>
<td className="py-2">{item.description}</td>
<td className="py-2 text-right">
{formatCurrency(item.price)}
</td>
<td className="py-2 text-right">
{item.discount > 0
? `-${(item.discount * 100).toFixed(0)}%`
: ""}
</td>
<td className="py-2 text-right">
{formatCurrency(item.price * (1 - item.discount))}
</td>
</tr>
))}
<tr className="border-b">
<td className="py-2">{data.packName}</td>
<td className="py-2 text-right">
{data.sconto > 0 && `${data.sconto}%`}
</td>
<td className="py-2 text-right">
{formatCurrency(data.amount_cent / 100)}
</td>
</tr>
</tbody>
</table>
</div>
@ -187,11 +174,11 @@ function Receipt({ data }: ReceiptProps) {
<div className="w-64">
<div className="mt-1 flex justify-between pt-2 font-bold">
<span>Totale:</span>
<span>{formatCurrency(total)}</span>
<span>{formatCurrency(data.amount_cent / 100)}</span>
</div>
<div className="flex justify-between py-1">
<span>di cui IVA (22%):</span>
<span>{formatCurrency(total * 0.22)}</span>
<span>{formatCurrency((data.amount_cent / 100) * 0.22)}</span>
</div>
</div>
</div>

View file

@ -1552,13 +1552,11 @@ export const getOrdineRicevutaData = async ({
clienteIndirizzo: `${anagrafica.via_residenza} ${anagrafica.civico_residenza}\n${anagrafica.comune_residenza} (${anagrafica.provincia_residenza}) ${anagrafica.cap_residenza}\n${anagrafica.nazione_residenza}`,
clienteNome: anagrafica.username,
date: data.created_at,
items: [
{
description: data.nome_it,
discount: data.sconto / 100, // Convert percentage to decimal
price: data.amount_cent / 100, // Convert cents to euros
},
],
packName: data.nome_it,
sconto: data.sconto,
amount_cent: data.amount_cent,
ordineId: data.ordine_id,
paymentMethod: data.paymentmethod,
} as PurchaseData;