Update: 2026-05-15 04:41:45
This commit is contained in:
@@ -21,9 +21,15 @@ use PhpOffice\PhpSpreadsheet\Style\Fill;
|
|||||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Color;
|
use PhpOffice\PhpSpreadsheet\Style\Color;
|
||||||
|
|
||||||
|
// Enable error reporting for debugging
|
||||||
|
ini_set('display_errors', '1');
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
// Autoload PhpSpreadsheet
|
// Autoload PhpSpreadsheet
|
||||||
require_once ROOT_PATH . '/vendor/autoload.php';
|
require_once ROOT_PATH . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
// Auth: Support both Bearer header and ?token= query param (for download links)
|
// Auth: Support both Bearer header and ?token= query param (for download links)
|
||||||
$token = $_GET['token'] ?? null;
|
$token = $_GET['token'] ?? null;
|
||||||
if (!$token) {
|
if (!$token) {
|
||||||
@@ -392,3 +398,10 @@ $writer->save('php://output');
|
|||||||
$spreadsheet->disconnectWorksheets();
|
$spreadsheet->disconnectWorksheets();
|
||||||
unset($spreadsheet);
|
unset($spreadsheet);
|
||||||
exit;
|
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());
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,20 +5,20 @@
|
|||||||
|
|
||||||
-- Add tax_amount column (calculated from tax_rate × line_total)
|
-- Add tax_amount column (calculated from tax_rate × line_total)
|
||||||
ALTER TABLE invoice_lines
|
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
|
-- Add discount_amount column
|
||||||
ALTER TABLE invoice_lines
|
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)
|
-- Add net_total column (subtotal + tax - discount)
|
||||||
ALTER TABLE invoice_lines
|
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
|
-- Add tax_category for classification
|
||||||
-- standard = 16%, zero_rated = 0%, exempt = no tax, special = variable rate
|
-- standard = 16%, zero_rated = 0%, exempt = no tax, special = variable rate
|
||||||
ALTER TABLE invoice_lines
|
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
|
-- Backfill existing data: calculate tax_amount from line_total * tax_rate
|
||||||
UPDATE invoice_lines
|
UPDATE invoice_lines
|
||||||
|
|||||||
@@ -17,8 +17,16 @@ try {
|
|||||||
echo "<ul>";
|
echo "<ul>";
|
||||||
foreach ($queries as $query) {
|
foreach ($queries as $query) {
|
||||||
if (empty($query)) continue;
|
if (empty($query)) continue;
|
||||||
|
try {
|
||||||
$db->exec($query);
|
$db->exec($query);
|
||||||
echo "<li>✅ Executed: <pre>" . htmlspecialchars(substr($query, 0, 50)) . "...</pre></li>";
|
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 "</ul>";
|
||||||
echo "<h2>Migration completed successfully!</h2>";
|
echo "<h2>Migration completed successfully!</h2>";
|
||||||
|
|||||||
Reference in New Issue
Block a user