🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 02:16
This commit is contained in:
@@ -25,8 +25,8 @@ final class Request
|
||||
$this->queryParams = $_GET;
|
||||
$this->files = $_FILES;
|
||||
|
||||
$contentType = $this->getHeader('Content-Type');
|
||||
if ($contentType && str_contains($contentType, 'application/json')) {
|
||||
$contentType = $this->getHeader('Content-Type') ?? $_SERVER['CONTENT_TYPE'] ?? '';
|
||||
if ($contentType && str_contains(strtolower($contentType), 'application/json')) {
|
||||
$this->body = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
} else {
|
||||
$this->body = $_POST;
|
||||
|
||||
@@ -16,6 +16,15 @@ final class InvoiceController
|
||||
private readonly FileStorageService $storage
|
||||
) {}
|
||||
|
||||
public function list(Request $request): void
|
||||
{
|
||||
$invoices = $this->invoiceModel->findByTenant($request->tenantId);
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'data' => $invoices
|
||||
]);
|
||||
}
|
||||
|
||||
public function upload(Request $request): void
|
||||
{
|
||||
$files = $request->getFiles();
|
||||
|
||||
@@ -10,6 +10,13 @@ final class InvoiceModel extends BaseModel
|
||||
{
|
||||
protected string $table = 'invoices';
|
||||
|
||||
public function findByTenant(string $tenantId): array
|
||||
{
|
||||
$stmt = $this->db()->prepare("SELECT * FROM {$this->table} WHERE tenant_id = ? AND deleted_at IS NULL ORDER BY created_at DESC");
|
||||
$stmt->execute([$tenantId]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
public function findByStatus(string $status, ?string $tenantId = null): array
|
||||
{
|
||||
$sql = "SELECT * FROM {$this->table} WHERE status = ? AND deleted_at IS NULL";
|
||||
|
||||
@@ -455,10 +455,13 @@
|
||||
modals.innerHTML = `
|
||||
<div class="fixed inset-0 bg-black/60 backdrop-blur-sm z-[100] flex items-center justify-center" id="invoice-modal">
|
||||
<div class="glass-panel p-8 rounded-3xl w-full max-w-md border border-white/10 shadow-2xl">
|
||||
<h3 class="text-2xl font-bold mb-6">رفع فاتورة (JSON/XML)</h3>
|
||||
<form id="upload-invoice-form" class="space-y-4">
|
||||
<h3 class="text-2xl font-bold mb-6">رفع فاتورة للتدقيق</h3>
|
||||
<form id="upload-invoice-form" class="space-y-4" enctype="multipart/form-data">
|
||||
<input type="text" id="inv-comp-id" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none" placeholder="معرف الشركة (Company ID)" required>
|
||||
<textarea id="inv-payload" rows="6" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none font-mono text-sm" placeholder='{"Invoice": {...}}' required></textarea>
|
||||
<div class="p-4 border-2 border-dashed border-white/20 rounded-xl bg-black/10 text-center">
|
||||
<p class="text-sm text-slate-400 mb-2">اختر ملف الفاتورة (JSON/XML/PDF)</p>
|
||||
<input type="file" id="inv-file" class="text-sm w-full" required>
|
||||
</div>
|
||||
<div class="flex gap-3 mt-6">
|
||||
<button type="button" onclick="document.getElementById('invoice-modal').remove()" class="flex-1 py-3 bg-white/5 hover:bg-white/10 rounded-xl transition">إلغاء</button>
|
||||
<button type="submit" class="flex-1 py-3 bg-primary hover:bg-primary-dark text-white font-bold rounded-xl shadow-lg transition">تحقق ورفع</button>
|
||||
@@ -471,14 +474,18 @@
|
||||
document.getElementById('upload-invoice-form').onsubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
const companyId = document.getElementById('inv-comp-id').value; // Keep as string (UUID)
|
||||
const payload = JSON.parse(document.getElementById('inv-payload').value);
|
||||
const companyId = document.getElementById('inv-comp-id').value;
|
||||
const fileInput = document.getElementById('inv-file');
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('company_id', companyId);
|
||||
formData.append('invoice', fileInput.files[0]);
|
||||
|
||||
const btn = e.target.querySelector('button[type="submit"]');
|
||||
btn.textContent = 'جاري التحقق...';
|
||||
btn.disabled = true;
|
||||
|
||||
await API.post('/invoices/upload', { company_id: companyId, payload });
|
||||
await API.upload('/invoices/upload', formData);
|
||||
document.getElementById('invoice-modal').remove();
|
||||
renderInvoices();
|
||||
} catch(err) {
|
||||
|
||||
Reference in New Issue
Block a user