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 { export type PurchaseData = {
description: string;
price: number;
discount: number;
}
export interface PurchaseData {
ordineId: OrdiniOrdineId; ordineId: OrdiniOrdineId;
date: Date; date: Date;
clienteNome: string; clienteNome: string;
clienteIndirizzo: string; clienteIndirizzo: string;
paymentMethod: string; paymentMethod: string;
items: Item[]; packName: string;
} sconto: number;
amount_cent: number;
};
interface ReceiptProps { interface ReceiptProps {
data: PurchaseData; data: PurchaseData;
@ -97,10 +94,6 @@ function Receipt({ data }: ReceiptProps) {
const companyAddress = const companyAddress =
"Via Beata Giovanna 1\nBassano del Grappa (VI) 36061\nItalia"; "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 = 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."; "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 = const footer =
@ -158,28 +151,22 @@ function Receipt({ data }: ReceiptProps) {
<thead> <thead>
<tr className="border-b"> <tr className="border-b">
<th className="py-2 text-left">Descrizione</th> <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> <th className="py-2 text-right">Importo</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{data.items.map((item) => ( <tr className="border-b">
<tr className="border-b" key={item.description}> <td className="py-2">{data.packName}</td>
<td className="py-2">{item.description}</td>
<td className="py-2 text-right"> <td className="py-2 text-right">
{formatCurrency(item.price)} {data.sconto > 0 && `${data.sconto}%`}
</td> </td>
<td className="py-2 text-right"> <td className="py-2 text-right">
{item.discount > 0 {formatCurrency(data.amount_cent / 100)}
? `-${(item.discount * 100).toFixed(0)}%` </td>
: ""} </tr>
</td>
<td className="py-2 text-right">
{formatCurrency(item.price * (1 - item.discount))}
</td>
</tr>
))}
</tbody> </tbody>
</table> </table>
</div> </div>
@ -187,11 +174,11 @@ function Receipt({ data }: ReceiptProps) {
<div className="w-64"> <div className="w-64">
<div className="mt-1 flex justify-between pt-2 font-bold"> <div className="mt-1 flex justify-between pt-2 font-bold">
<span>Totale:</span> <span>Totale:</span>
<span>{formatCurrency(total)}</span> <span>{formatCurrency(data.amount_cent / 100)}</span>
</div> </div>
<div className="flex justify-between py-1"> <div className="flex justify-between py-1">
<span>di cui IVA (22%):</span> <span>di cui IVA (22%):</span>
<span>{formatCurrency(total * 0.22)}</span> <span>{formatCurrency((data.amount_cent / 100) * 0.22)}</span>
</div> </div>
</div> </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}`, clienteIndirizzo: `${anagrafica.via_residenza} ${anagrafica.civico_residenza}\n${anagrafica.comune_residenza} (${anagrafica.provincia_residenza}) ${anagrafica.cap_residenza}\n${anagrafica.nazione_residenza}`,
clienteNome: anagrafica.username, clienteNome: anagrafica.username,
date: data.created_at, date: data.created_at,
items: [
{ packName: data.nome_it,
description: data.nome_it, sconto: data.sconto,
discount: data.sconto / 100, // Convert percentage to decimal amount_cent: data.amount_cent,
price: data.amount_cent / 100, // Convert cents to euros
},
],
ordineId: data.ordine_id, ordineId: data.ordine_id,
paymentMethod: data.paymentmethod, paymentMethod: data.paymentmethod,
} as PurchaseData; } as PurchaseData;