Update: 2026-05-15 04:41:45

This commit is contained in:
Hamza-Ayed
2026-05-15 04:41:45 +03:00
parent 2f1ecca593
commit 698d0df01e
3 changed files with 27 additions and 6 deletions

View File

@@ -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());
}

View File

@@ -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

View File

@@ -17,8 +17,16 @@ try {
echo "<ul>";
foreach ($queries as $query) {
if (empty($query)) continue;
$db->exec($query);
echo "<li>✅ Executed: <pre>" . htmlspecialchars(substr($query, 0, 50)) . "...</pre></li>";
try {
$db->exec($query);
echo "<li>✅ Executed: <pre>" . htmlspecialchars(substr($query, 0, 70)) . "...</pre></li>";
} catch (\Exception $innerE) {
if (str_contains($innerE->getMessage(), 'Duplicate column name')) {
echo "<li> تخطي (العمود موجود مسبقاً): <pre>" . htmlspecialchars(substr($query, 0, 70)) . "...</pre></li>";
} else {
throw $innerE;
}
}
}
echo "</ul>";
echo "<h2>Migration completed successfully!</h2>";