use crate::domain::models::{Merchant, OrderRecord}; pub struct BillingService; impl BillingService { pub fn generate_invoice_html(order: &OrderRecord, merchant: &Merchant) -> String { let subtotal = order.price_inr; let total_tax = order.cgst + order.sgst + order.igst; let grand_total = subtotal + total_tax + order.delivery_fee; format!( r#" Invoice - {tx_id}
{brand_name}
INVOICE
#{tx_id}
Date: {date}
Sold By
{brand_name}
{merchant_addr}
Ship To
{buyer_name}
{buyer_email}
{buyer_addr}
Item Description Amount
Product Purchase ({link_id}) ₹{subtotal:.2}
Subtotal ₹{subtotal:.2}
Tax (GST) ₹{total_tax:.2}
Shipping ₹{shipping:.2}
{discount_row}
Grand Total ₹{total:.2}
"#, brand_name = merchant.brand_name, tx_id = order.transaction_id, date = order .created_at .map(|t| t.format("%d %b %Y").to_string()) .unwrap_or_else(|| "N/A".to_string()), merchant_addr = merchant.business_address.as_deref().unwrap_or("N/A"), buyer_name = order.buyer_name, buyer_email = order.buyer_email, buyer_addr = order.delivery_address.as_deref().unwrap_or("N/A"), link_id = order.link_id, subtotal = subtotal, total_tax = total_tax, shipping = order.delivery_fee, total = grand_total, discount_row = if order.discount_amount > 0.0 { format!( r#"
Discount-₹{:.2}
"#, order.discount_amount ) } else { String::new() } ) } }