backbone_pos/application/service/
pos_receipt.rs1use uuid::Uuid;
11
12use super::pos_write_service::{PosError, PosWriteService, Receipt, ReceiptLine, ReceiptTender};
13
14impl PosWriteService {
15 pub async fn receipt(&self, pos_invoice_id: Uuid) -> Result<Receipt, PosError> {
20 let hdr = self.invoices
22 .fetch_receipt_header(&self.rpool(), pos_invoice_id).await?
23 .ok_or(PosError::InvoiceNotFound(pos_invoice_id))?;
24
25 let line_rows = self.items.fetch_receipt_lines(&self.rpool(), pos_invoice_id).await?;
26 let lines = line_rows.into_iter().map(|r| {
27 let desc = r.description.unwrap_or_else(|| r.item_id.to_string());
28 ReceiptLine {
29 description: desc, course: r.course, quantity: r.quantity, unit_price: r.unit_price,
30 discount_amount: r.discount_amount, net_amount: r.net_amount,
31 }
32 }).collect();
33
34 let tender_rows = self.payments.fetch_receipt_tenders(&self.rpool(), pos_invoice_id).await?;
35 let tenders = tender_rows.into_iter().map(|r| ReceiptTender { method: r.method, amount: r.amount }).collect();
36
37 Ok(Receipt {
38 pos_invoice_id,
39 receipt_number: hdr.receipt_number,
40 register_name: hdr.register_name,
41 posting_at: hdr.posting_at,
42 currency: hdr.currency,
43 status: hdr.status,
44 is_invoiced: hdr.is_invoiced,
45 lines,
46 net_total: hdr.net_total,
47 tax_rate: hdr.tax_rate,
48 tax_total: hdr.tax_total,
49 rounding_adjustment: hdr.rounding_adjustment,
50 grand_total: hdr.rounded_total,
52 tenders,
53 paid_total: hdr.paid_total,
54 change_due: hdr.change_due,
55 })
56 }
57}