mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
feat: add Print Receipt button to completed transactions
Add a 'Print Receipt' option for completed credit purchase transactions in the AI provider config dialog. Clicking it opens a print-friendly receipt with Soapbox Technology, LLC business details (soapbox.pub, [email protected]) in a standard receipt layout showing payment ID, date, method, credits, processing fee, and total charged. Follows the existing window.open() print pattern used by gift card QR code printing. Adds i18n translations for all 6 supported languages.
This commit is contained in:
1 parent
c285dbcd05
commit
c229f40da8
7 files changed
+287
-6
No files matched your search
@@ -895,6 +895,228 @@ export function AIProviderConfigDialog({
|
||||
}
|
||||
};
|
||||
|
||||
const handlePrintReceipt = (payment: Payment) => {
|
||||
const receiptDate = new Date((payment.completed_at ?? payment.created_at) * 1000);
|
||||
const formattedDate = new Intl.DateTimeFormat('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
}).format(receiptDate);
|
||||
const formattedTime = new Intl.DateTimeFormat('en-US', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(receiptDate);
|
||||
|
||||
const paymentMethodDisplay = payment.method === 'stripe' ? t('creditCard') : t('lightning');
|
||||
const statusDisplay = payment.status.charAt(0).toUpperCase() + payment.status.slice(1);
|
||||
|
||||
const printWindow = window.open('', '_blank');
|
||||
if (!printWindow) {
|
||||
toast({
|
||||
title: t('printFailed'),
|
||||
description: t('failedToOpenPrintWindow'),
|
||||
variant: 'destructive',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const printHTML = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>${t('receipt')} - ${payment.id}</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
padding: 40px 20px;
|
||||
background: white;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.receipt {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
border: 1px solid #e0e0e0;
|
||||
padding: 48px 40px;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
padding-bottom: 28px;
|
||||
border-bottom: 2px solid #000;
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
|
||||
.company-name {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.5px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.company-detail {
|
||||
font-size: 13px;
|
||||
color: #555;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.company-detail a {
|
||||
color: #555;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.receipt-title {
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 2px;
|
||||
text-transform: uppercase;
|
||||
color: #333;
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
|
||||
.details-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 140px 1fr;
|
||||
gap: 8px 16px;
|
||||
margin-bottom: 28px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.details-grid dt {
|
||||
color: #666;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.details-grid dd {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.divider {
|
||||
border: none;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
margin: 0 0 28px 0;
|
||||
}
|
||||
|
||||
.line-items {
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
|
||||
.line-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 6px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.line-item-label {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.line-item-value {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.line-item-total {
|
||||
border-top: 1px solid #000;
|
||||
margin-top: 8px;
|
||||
padding-top: 10px;
|
||||
font-weight: 700;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
text-align: center;
|
||||
padding-top: 28px;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.footer p {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
@media print {
|
||||
body {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.receipt {
|
||||
border: none;
|
||||
padding: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="receipt">
|
||||
<div class="header">
|
||||
<div class="company-name">Soapbox Technology, LLC</div>
|
||||
<div class="company-detail">
|
||||
<a href="https://soapbox.pub">soapbox.pub</a><br />
|
||||
[email protected]
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="receipt-title">${t('receipt')}</div>
|
||||
|
||||
<dl class="details-grid">
|
||||
<dt>${t('receiptNumber')}</dt>
|
||||
<dd>${payment.id}</dd>
|
||||
<dt>${t('date')}</dt>
|
||||
<dd>${formattedDate} ${formattedTime}</dd>
|
||||
<dt>${t('status')}</dt>
|
||||
<dd>${statusDisplay}</dd>
|
||||
<dt>${t('paymentMethodLabel')}</dt>
|
||||
<dd>${paymentMethodDisplay}</dd>
|
||||
${payment.description ? `<dt>${t('description')}</dt><dd>${payment.description}</dd>` : ''}
|
||||
</dl>
|
||||
|
||||
<hr class="divider" />
|
||||
|
||||
<div class="line-items">
|
||||
<div class="line-item">
|
||||
<span class="line-item-label">${t('credits')}</span>
|
||||
<span class="line-item-value">${formatCurrency(payment.amount)}</span>
|
||||
</div>
|
||||
${payment.fee > 0 ? `
|
||||
<div class="line-item">
|
||||
<span class="line-item-label">${t('processingFee')}</span>
|
||||
<span class="line-item-value">${formatCurrency(payment.fee)}</span>
|
||||
</div>
|
||||
` : ''}
|
||||
<div class="line-item line-item-total">
|
||||
<span class="line-item-label">${t('totalCharged')}</span>
|
||||
<span class="line-item-value">${formatCurrency(payment.total)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<p>${t('thankYouForPurchase')}</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
printWindow.document.write(printHTML);
|
||||
printWindow.document.close();
|
||||
|
||||
printWindow.onload = () => {
|
||||
setTimeout(() => {
|
||||
printWindow.print();
|
||||
}, 250);
|
||||
};
|
||||
};
|
||||
|
||||
const handleDownloadCSV = () => {
|
||||
if (!giftcards || giftcards.length === 0) return;
|
||||
|
||||
@@ -1307,6 +1529,17 @@ export function AIProviderConfigDialog({
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{payment.status === 'completed' && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => handlePrintReceipt(payment)}
|
||||
className="h-6 px-2 text-xs"
|
||||
>
|
||||
<Printer className="h-3 w-3 mr-1" />
|
||||
{t('printReceipt')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
+9
-1
@@ -573,5 +573,13 @@
|
||||
"failedToDuplicateProject": "Failed to duplicate project",
|
||||
"newProjectName": "New Project Name",
|
||||
"duplicateProjectDescription": "Create a copy of this project with a new name",
|
||||
"resume": "Resume"
|
||||
"resume": "Resume",
|
||||
"printReceipt": "Print Receipt",
|
||||
"receipt": "Receipt",
|
||||
"receiptNumber": "Receipt #",
|
||||
"date": "Date",
|
||||
"status": "Status",
|
||||
"paymentMethodLabel": "Payment Method",
|
||||
"totalCharged": "Total Charged",
|
||||
"thankYouForPurchase": "Thank you for your purchase!"
|
||||
}
|
||||
+9
-1
@@ -487,5 +487,13 @@
|
||||
"failedToDuplicateProject": "An kasa kwafin aikin",
|
||||
"newProjectName": "Sunan Sabon Aikin",
|
||||
"duplicateProjectDescription": "Ƙirƙiri kwafin wannan aikin da sabon suna",
|
||||
"resume": "Ci gaba"
|
||||
"resume": "Ci gaba",
|
||||
"printReceipt": "Buga Rasidi",
|
||||
"receipt": "Rasidi",
|
||||
"receiptNumber": "Rasidi #",
|
||||
"date": "Kwanan wata",
|
||||
"status": "Matsayi",
|
||||
"paymentMethodLabel": "Hanyar Biyan Kuɗi",
|
||||
"totalCharged": "Jimlar da aka Caji",
|
||||
"thankYouForPurchase": "Mun gode da sayan ku!"
|
||||
}
|
||||
+9
-1
@@ -484,5 +484,13 @@
|
||||
"failedToDuplicateProject": "Ọ dara ada imepụta ọrụ",
|
||||
"newProjectName": "Aha Ọrụ Ọhụrụ",
|
||||
"duplicateProjectDescription": "Mepụta oyiri nke ọrụ a na aha ọhụrụ",
|
||||
"resume": "Gaa n'ihu"
|
||||
"resume": "Gaa n'ihu",
|
||||
"printReceipt": "Bipụta Risịịtị",
|
||||
"receipt": "Risịịtị",
|
||||
"receiptNumber": "Risịịtị #",
|
||||
"date": "Ụbọchị",
|
||||
"status": "Ọnọdụ",
|
||||
"paymentMethodLabel": "Ụzọ Ịkwụ Ụgwọ",
|
||||
"totalCharged": "Nchịkọta Ego a Gbara",
|
||||
"thankYouForPurchase": "Daalụ maka ịzụta gị!"
|
||||
}
|
||||
+9
-1
@@ -496,5 +496,13 @@
|
||||
"failedToDuplicateProject": "Falha ao duplicar projeto",
|
||||
"newProjectName": "Nome do Novo Projeto",
|
||||
"duplicateProjectDescription": "Criar uma cópia deste projeto com um novo nome",
|
||||
"resume": "Retomar"
|
||||
"resume": "Retomar",
|
||||
"printReceipt": "Imprimir Recibo",
|
||||
"receipt": "Recibo",
|
||||
"receiptNumber": "Recibo Nº",
|
||||
"date": "Data",
|
||||
"status": "Status",
|
||||
"paymentMethodLabel": "Método de Pagamento",
|
||||
"totalCharged": "Total Cobrado",
|
||||
"thankYouForPurchase": "Obrigado pela sua compra!"
|
||||
}
|
||||
+9
-1
@@ -484,5 +484,13 @@
|
||||
"failedToDuplicateProject": "O kuna lati ṣe ẹda iṣẹ akanṣe",
|
||||
"newProjectName": "Orukọ Iṣẹ Akanṣe Tuntun",
|
||||
"duplicateProjectDescription": "Ṣẹda ẹda ti iṣẹ akanṣe yii pẹlu orukọ tuntun",
|
||||
"resume": "Tẹsiwaju"
|
||||
"resume": "Tẹsiwaju",
|
||||
"printReceipt": "Tẹ Ìwé Ẹ̀rí",
|
||||
"receipt": "Ìwé Ẹ̀rí",
|
||||
"receiptNumber": "Ìwé Ẹ̀rí #",
|
||||
"date": "Ọjọ́",
|
||||
"status": "Ipò",
|
||||
"paymentMethodLabel": "Ọ̀nà Ìsanwó",
|
||||
"totalCharged": "Àpapọ̀ tí a gba",
|
||||
"thankYouForPurchase": "A dúpẹ́ fún rírà rẹ!"
|
||||
}
|
||||
+9
-1
@@ -496,5 +496,13 @@
|
||||
"failedToDuplicateProject": "复制项目失败",
|
||||
"newProjectName": "新项目名称",
|
||||
"duplicateProjectDescription": "使用新名称创建此项目的副本",
|
||||
"resume": "继续"
|
||||
"resume": "继续",
|
||||
"printReceipt": "打印收据",
|
||||
"receipt": "收据",
|
||||
"receiptNumber": "收据编号",
|
||||
"date": "日期",
|
||||
"status": "状态",
|
||||
"paymentMethodLabel": "支付方式",
|
||||
"totalCharged": "总收费",
|
||||
"thankYouForPurchase": "感谢您的购买!"
|
||||
}
|
||||
Reference in new issue
Block a user