From 698d0df01efc10c4c6dc4455b578044ee6cb33a4 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Fri, 15 May 2026 04:41:45 +0300 Subject: [PATCH] Update: 2026-05-15 04:41:45 --- app/modules_app/invoices/export_excel.php | 13 +++++++++++++ database/migrations/008_invoice_lines_enhance.sql | 8 ++++---- public/migrate_008.php | 12 ++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/modules_app/invoices/export_excel.php b/app/modules_app/invoices/export_excel.php index 20330e8..fa1bd0c 100644 --- a/app/modules_app/invoices/export_excel.php +++ b/app/modules_app/invoices/export_excel.php @@ -21,9 +21,15 @@ use PhpOffice\PhpSpreadsheet\Style\Fill; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Style\Color; +// Enable error reporting for debugging +ini_set('display_errors', '1'); +error_reporting(E_ALL); + // Autoload PhpSpreadsheet require_once ROOT_PATH . '/vendor/autoload.php'; +try { + // Auth: Support both Bearer header and ?token= query param (for download links) $token = $_GET['token'] ?? null; if (!$token) { @@ -392,3 +398,10 @@ $writer->save('php://output'); $spreadsheet->disconnectWorksheets(); unset($spreadsheet); exit; + +} catch (\Exception $e) { + if (ob_get_length()) ob_end_clean(); + header('Content-Type: text/plain; charset=utf-8'); + file_put_contents(STORAGE_PATH . '/logs/export_errors.log', "[" . date('Y-m-d H:i:s') . "] " . $e->getMessage() . "\n" . $e->getTraceAsString(), FILE_APPEND); + die("خطأ في التصدير: " . $e->getMessage()); +} diff --git a/database/migrations/008_invoice_lines_enhance.sql b/database/migrations/008_invoice_lines_enhance.sql index e99448c..d5e138b 100644 --- a/database/migrations/008_invoice_lines_enhance.sql +++ b/database/migrations/008_invoice_lines_enhance.sql @@ -5,20 +5,20 @@ -- Add tax_amount column (calculated from tax_rate × line_total) ALTER TABLE invoice_lines - ADD COLUMN IF NOT EXISTS tax_amount DECIMAL(12,3) DEFAULT 0 AFTER tax_rate; + ADD COLUMN tax_amount DECIMAL(12,3) DEFAULT 0 AFTER tax_rate; -- Add discount_amount column ALTER TABLE invoice_lines - ADD COLUMN IF NOT EXISTS discount_amount DECIMAL(12,3) DEFAULT 0 AFTER tax_amount; + ADD COLUMN discount_amount DECIMAL(12,3) DEFAULT 0 AFTER tax_amount; -- Add net_total column (subtotal + tax - discount) ALTER TABLE invoice_lines - ADD COLUMN IF NOT EXISTS net_total DECIMAL(12,3) DEFAULT 0 AFTER discount_amount; + ADD COLUMN net_total DECIMAL(12,3) DEFAULT 0 AFTER discount_amount; -- Add tax_category for classification -- standard = 16%, zero_rated = 0%, exempt = no tax, special = variable rate ALTER TABLE invoice_lines - ADD COLUMN IF NOT EXISTS tax_category VARCHAR(20) DEFAULT 'standard' AFTER net_total; + ADD COLUMN tax_category VARCHAR(20) DEFAULT 'standard' AFTER net_total; -- Backfill existing data: calculate tax_amount from line_total * tax_rate UPDATE invoice_lines diff --git a/public/migrate_008.php b/public/migrate_008.php index cd802ed..a90864a 100644 --- a/public/migrate_008.php +++ b/public/migrate_008.php @@ -17,8 +17,16 @@ try { echo ""; echo "

Migration completed successfully!

";