Fix AI mime-type and enable invoice actions

This commit is contained in:
Hamza-Ayed
2026-04-18 02:17:56 +03:00
parent 9f5b202bb2
commit 066df077b1
2 changed files with 32 additions and 6 deletions

View File

@@ -67,12 +67,19 @@ export class GeminiExtractorService {
Pay close attention to Jordanian Tax Rules (subtotal - discount + tax = grand_total). Pay close attention to Jordanian Tax Rules (subtotal - discount + tax = grand_total).
`; `;
// Detect MIME type based on extension
const ext = path.extname(filePath).toLowerCase();
let mimeType = 'image/jpeg';
if (ext === '.pdf') mimeType = 'application/pdf';
else if (ext === '.png') mimeType = 'image/png';
else if (ext === '.webp') mimeType = 'image/webp';
const result = await this.model.generateContent([ const result = await this.model.generateContent([
prompt, prompt,
{ {
inlineData: { inlineData: {
data: fileData.toString('base64'), data: fileData.toString('base64'),
mimeType: 'image/jpeg', // Adjusted based on file extension in prod mimeType: mimeType,
}, },
}, },
]); ]);

View File

@@ -200,23 +200,42 @@ export const InvoicesPage = () => {
</div> </div>
</td> </td>
<td className="px-6 py-4 text-slate-500 text-sm"> <td className="px-6 py-4 text-slate-500 text-sm">
{inv.issue_date ? new Date(inv.issue_date).toLocaleDateString('ar-JO') : '---'} {inv.invoice_date ? new Date(inv.invoice_date).toLocaleDateString('ar-JO') : '---'}
</td> </td>
<td className="px-6 py-4 font-mono font-bold text-slate-800 text-left"> <td className="px-6 py-4 font-mono font-bold text-slate-800 text-left">
{Number(inv.total_amount).toLocaleString('en-US', { minimumFractionDigits: 3 })} {Number(inv.grand_total).toLocaleString('en-US', { minimumFractionDigits: 3 })}
</td> </td>
<td className="px-6 py-4"><StatusBadge status={inv.status} /></td> <td className="px-6 py-4"><StatusBadge status={inv.status} /></td>
<td className="px-6 py-4 text-center"> <td className="px-6 py-4 text-center">
<div className="flex items-center justify-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity"> <div className="flex items-center justify-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
<button className="p-2 text-slate-400 hover:text-primary-600 hover:bg-primary-50 rounded-lg transition-all"> <button
onClick={(e) => { e.stopPropagation(); console.log('View Invoice', inv.id); }}
className="p-2 text-slate-400 hover:text-primary-600 hover:bg-primary-50 rounded-lg transition-all"
>
<Eye className="w-4 h-4" /> <Eye className="w-4 h-4" />
</button> </button>
{inv.status === 'validated' && ( {inv.status === 'validated' && (
<button className="p-2 text-emerald-500 hover:text-emerald-600 hover:bg-emerald-50 rounded-lg transition-all" title="إرسال لجو فوترة"> <button
onClick={async (e) => {
e.stopPropagation();
try {
await apiClient.post(`/invoices/${inv.id}/submit`);
alert('تم الإرسال لجو فوترة بنجاح');
fetchData();
} catch (err) {
alert('فشل الإرسال');
}
}}
className="p-2 text-emerald-500 hover:text-emerald-600 hover:bg-emerald-50 rounded-lg transition-all"
title="إرسال لجو فوترة"
>
<Send className="w-4 h-4" /> <Send className="w-4 h-4" />
</button> </button>
)} )}
<button className="p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-lg transition-all"> <button
onClick={(e) => { e.stopPropagation(); }}
className="p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-lg transition-all"
>
<MoreVertical className="w-4 h-4" /> <MoreVertical className="w-4 h-4" />
</button> </button>
</div> </div>