Fix AI mime-type and enable invoice actions
This commit is contained in:
@@ -67,12 +67,19 @@ export class GeminiExtractorService {
|
||||
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([
|
||||
prompt,
|
||||
{
|
||||
inlineData: {
|
||||
data: fileData.toString('base64'),
|
||||
mimeType: 'image/jpeg', // Adjusted based on file extension in prod
|
||||
mimeType: mimeType,
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -200,23 +200,42 @@ export const InvoicesPage = () => {
|
||||
</div>
|
||||
</td>
|
||||
<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 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 className="px-6 py-4"><StatusBadge status={inv.status} /></td>
|
||||
<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">
|
||||
<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" />
|
||||
</button>
|
||||
{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" />
|
||||
</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" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user