+
+ ${order.restaurant?.name || "رسید سفارش"}
+ سفارش شماره ${formatFaNumber(order.orderNumber)}
+ ${formatOptionalDate(order.createdAt, {
+ year: "numeric",
+ month: "2-digit",
+ day: "2-digit",
+ hour: "2-digit",
+ minute: "2-digit",
+ })}
+
+
+
+
+
+ مشتری${getCustomerName(order)}
+ موبایل${order.user?.phone || "-"}
+ روش تحویل${order.deliveryMethod?.description || "-"}
+ روش پرداخت${order.paymentMethod?.description || "-"}
+ ${
+ customerAddress
+ ? `آدرس مشتری${customerAddress}
`
+ : ""
+ }
+
+
+
+
+
+
+
+
+
+ جمع آیتمها${formatPrice(order.subTotal)}
+ ${
+ order.itemsDiscount > 0
+ ? `تخفیف آیتمها${formatPrice(order.itemsDiscount)}
`
+ : ""
+ }
+ ${
+ order.couponDiscount > 0
+ ? `تخفیف کوپن${formatPrice(order.couponDiscount)}
`
+ : ""
+ }
+ هزینه ارسال${formatPrice(order.deliveryFee)}
+ ${
+ order.tax > 0
+ ? `مالیات${formatPrice(order.tax)}
`
+ : ""
+ }
+
+ مبلغ کل${formatPrice(order.total)}
+
+
+ ${
+ order.description
+ ? `توضیحات:
${order.description}
`
+ : ""
+ }
+
+ `;
+};
+
+export const printOrderReceipt = (order: Order): void => {
+ const html = buildOrderReceiptHtml(order);
+ printHtmlDocument({
+ title: `سفارش ${order.orderNumber}`,
+ html,
+ widthMm: 80,
+ styles: baseReceiptStyles,
+ });
+};
diff --git a/src/shared/print/printHtmlDocument.ts b/src/shared/print/printHtmlDocument.ts
new file mode 100644
index 0000000..a27b5c5
--- /dev/null
+++ b/src/shared/print/printHtmlDocument.ts
@@ -0,0 +1,77 @@
+type PrintHtmlDocumentParams = {
+ title: string;
+ html: string;
+ widthMm?: number;
+ styles?: string;
+};
+
+const defaultStyles = `
+ * { box-sizing: border-box; }
+ html, body {
+ margin: 0;
+ padding: 0;
+ background: #fff;
+ color: #111;
+ font-family: Tahoma, Arial, sans-serif;
+ direction: rtl;
+ }
+ @page {
+ size: 80mm auto;
+ margin: 4mm;
+ }
+ .receipt {
+ width: 100%;
+ }
+`;
+
+export const printHtmlDocument = ({
+ title,
+ html,
+ widthMm = 80,
+ styles,
+}: PrintHtmlDocumentParams): void => {
+ if (typeof window === "undefined") return;
+
+ const printWindow = window.open("", "_blank");
+ if (!printWindow) return;
+
+ const safeTitle = title.replace(//g, ">");
+ const pageStyles = styles ?? defaultStyles.replace("80mm", `${widthMm}mm`);
+
+ const pageHtml = `
+
+
+
+