diff --git a/fix_showreceipt.php b/fix_showreceipt.php deleted file mode 100644 index 2b239cf..0000000 --- a/fix_showreceipt.php +++ /dev/null @@ -1,26 +0,0 @@ -"; - const rca = document.getElementById('receiptCompanyAddress'); - if(rca) rca.innerHTML = data.outlet_address ? data.outlet_address.replace(/\n/g, '
') : ""; - - // Update labels for Purchase vs Sale -JS; - -$replace = <<<'JS' - const rcn = document.getElementById('receiptCompanyName'); - if(rcn) rcn.textContent = data.outlet_name || ""; - const rca = document.getElementById('receiptCompanyAddress'); - if(rca) { - rca.textContent = data.outlet_address || "".replace(//gi, '\n'); - rca.style.whiteSpace = 'pre-line'; - } - - // Update labels for Purchase vs Sale -JS; - -$content = str_replace($search, $replace, $content); -file_put_contents('index.php', $content); diff --git a/index.php b/index.php index ad7964f..409580f 100644 --- a/index.php +++ b/index.php @@ -6985,7 +6985,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; const total = subtotal - discountAmount - loyaltyRedeemed; const companyName = outletName || ""; const companyPhone = outletPhone || ""; - const companyAddress = outletAddress ? outletAddress.replace(/\n/g, '
') : ""; + const companyAddress = outletAddress ? outletAddress.replace(/\n/g, '
') : (typeof companySettings !== 'undefined' ? (companySettings.company_address || '').replace(/\n/g, '
') : ''); const companyVat = ""; const companyLogo = ""; @@ -11895,7 +11895,7 @@ document.addEventListener('DOMContentLoaded', function() { if(rcn) rcn.textContent = data.outlet_name || ""; const rca = document.getElementById('receiptCompanyAddress'); if(rca) { - rca.textContent = data.outlet_address || "".replace(//gi, '\n'); + rca.textContent = data.outlet_address || (typeof companySettings !== 'undefined' ? companySettings.company_address : '') || ''; rca.style.whiteSpace = 'pre-line'; } @@ -14694,7 +14694,7 @@ document.addEventListener('DOMContentLoaded', function() { if (!data) return; // Reuse view logic document.getElementById('printCompanyName').textContent = data.outlet_name || ""; - document.getElementById('printCompanyAddress').textContent = data.outlet_address || "".replace(//gi, '\n'); + document.getElementById('printCompanyAddress').textContent = data.outlet_address || (typeof companySettings !== 'undefined' ? companySettings.company_address : '') || ''; document.getElementById('printCompanyAddress').style.whiteSpace = 'pre-line'; const cPhone = data.outlet_phone || ""; if (cPhone) { @@ -14836,7 +14836,7 @@ document.addEventListener('DOMContentLoaded', function() { const companyName = inv.outlet_name || ""; const companyPhone = inv.outlet_phone || ""; - const companyAddress = inv.outlet_address ? inv.outlet_address.replace(/\n/g, '
') : ""; + const companyAddress = inv.outlet_address ? inv.outlet_address.replace(/\n/g, '
') : (typeof companySettings !== 'undefined' ? (companySettings.company_address || '').replace(/\n/g, '
') : ''); const companyVat = ""; const companyLogo = ""; diff --git a/patch_cashflow.php b/patch_cashflow.php deleted file mode 100644 index e9f98d4..0000000 --- a/patch_cashflow.php +++ /dev/null @@ -1,60 +0,0 @@ -query(" - SELECT m.sort_col, m.label, - ( - SELECT COALESCE(SUM(amount), 0) FROM payments WHERE DATE_FORMAT(payment_date, \'%Y-%m\') = m.sort_col - ) + ( - SELECT COALESCE(SUM(amount), 0) FROM pos_payments WHERE DATE_FORMAT(created_at, \'%Y-%m\') = m.sort_col - ) as income, - ( - SELECT COALESCE(SUM(amount), 0) FROM expenses WHERE DATE_FORMAT(expense_date, \'%Y-%m\') = m.sort_col - ) + ( - SELECT COALESCE(SUM(amount), 0) FROM purchase_payments WHERE DATE_FORMAT(payment_date, \'%Y-%m\') = m.sort_col - ) + ( - SELECT COALESCE(SUM(net_salary), 0) FROM hr_payroll WHERE DATE_FORMAT(payment_date, \'%Y-%m\') = m.sort_col - ) as expense - FROM ( - SELECT DISTINCT DATE_FORMAT(dt, \'%Y-%m\') as sort_col, DATE_FORMAT(dt, \'%M %Y\') as label - FROM ( - SELECT payment_date as dt FROM payments - UNION SELECT created_at as dt FROM pos_payments - UNION SELECT expense_date as dt FROM expenses - UNION SELECT payment_date as dt FROM purchase_payments - ) dates - ) m - ORDER BY m.sort_col DESC LIMIT 6 - ")->fetchAll(PDO::FETCH_ASSOC);'; - -$repl_cf = ' // Cash Flow Data (Income vs Expense - last 6 months) - $data[\'cash_flow\'] = db()->query(" - SELECT m.sort_col, m.label, - ( - SELECT COALESCE(SUM(amount), 0) FROM payments WHERE DATE_FORMAT(payment_date, \'%Y-%m\') = m.sort_col $out_and - ) + ( - SELECT COALESCE(SUM(amount), 0) FROM pos_payments WHERE DATE_FORMAT(created_at, \'%Y-%m\') = m.sort_col $out_and - ) as income, - ( - SELECT COALESCE(SUM(amount), 0) FROM expenses WHERE DATE_FORMAT(expense_date, \'%Y-%m\') = m.sort_col $out_and - ) + ( - SELECT COALESCE(SUM(amount), 0) FROM purchase_payments WHERE DATE_FORMAT(payment_date, \'%Y-%m\') = m.sort_col $out_and - ) + ( - SELECT COALESCE(SUM(net_salary), 0) FROM hr_payroll WHERE DATE_FORMAT(payment_date, \'%Y-%m\') = m.sort_col $out_and - ) as expense - FROM ( - SELECT DISTINCT DATE_FORMAT(dt, \'%Y-%m\') as sort_col, DATE_FORMAT(dt, \'%M %Y\') as label - FROM ( - SELECT payment_date as dt FROM payments $out_w - UNION SELECT created_at as dt FROM pos_payments $out_w - UNION SELECT expense_date as dt FROM expenses $out_w - UNION SELECT payment_date as dt FROM purchase_payments $out_w - ) dates - ) m - ORDER BY m.sort_col DESC LIMIT 6 - ")->fetchAll(PDO::FETCH_ASSOC);'; - -$c = str_replace($find_cf, $repl_cf, $c); -file_put_contents('index.php', $c); -echo "Cash flow patched\n"; diff --git a/patch_dashboard.php b/patch_dashboard.php deleted file mode 100644 index 721f84f..0000000 --- a/patch_dashboard.php +++ /dev/null @@ -1,81 +0,0 @@ -query("SELECT * FROM customers ORDER BY id DESC LIMIT 5")->fetchAll(); - $data[\'stats\'] = [ - \'total_customers\' => db()->query("SELECT COUNT(*) FROM customers")->fetchColumn(), - \'total_items\' => db()->query("SELECT COUNT(*) FROM stock_items")->fetchColumn(), - \'total_sales\' => (db()->query("SELECT SUM(total_with_vat) FROM invoices")->fetchColumn() ?: 0) + (db()->query("SELECT SUM(net_amount) FROM pos_transactions WHERE status = \'completed\'")->fetchColumn() ?: 0), - \'total_received\' => (db()->query("SELECT SUM(amount) FROM payments")->fetchColumn() ?: 0) + (db()->query("SELECT SUM(amount) FROM pos_payments")->fetchColumn() ?: 0), - \'total_purchases\' => db()->query("SELECT SUM(total_with_vat) FROM purchases")->fetchColumn() ?: 0, - \'total_paid\' => db()->query("SELECT SUM(amount) FROM purchase_payments")->fetchColumn() ?: 0, - \'expired_items\' => db()->query("SELECT COUNT(*) FROM stock_items WHERE expiry_date IS NOT NULL AND expiry_date <= CURDATE()")->fetchColumn(), - \'near_expiry_items\' => db()->query("SELECT COUNT(*) FROM stock_items WHERE expiry_date IS NOT NULL AND expiry_date > CURDATE() AND expiry_date <= DATE_ADD(CURDATE(), INTERVAL 30 DAY)")->fetchColumn(), - \'low_stock_items_count\' => db()->query("SELECT COUNT(*) FROM stock_items WHERE stock_quantity <= min_stock_level")->fetchColumn(), - ];'; - -$repl_dashboard = ' if (can(\'dashboard_view\')) { - $out_w = isset($_SESSION[\'outlet_id\']) ? "WHERE outlet_id = " . (int)$_SESSION[\'outlet_id\'] : "WHERE 1=1"; - $out_and = isset($_SESSION[\'outlet_id\']) ? "AND outlet_id = " . (int)$_SESSION[\'outlet_id\'] : ""; - - $data[\'customers\'] = db()->query("SELECT * FROM customers $out_w ORDER BY id DESC LIMIT 5")->fetchAll(); - $data[\'stats\'] = [ - \'total_customers\' => db()->query("SELECT COUNT(*) FROM customers $out_w")->fetchColumn(), - \'total_items\' => db()->query("SELECT COUNT(*) FROM stock_items $out_w")->fetchColumn(), - \'total_sales\' => (db()->query("SELECT SUM(total_with_vat) FROM invoices $out_w")->fetchColumn() ?: 0) + (db()->query("SELECT SUM(net_amount) FROM pos_transactions WHERE status = \'completed\' $out_and")->fetchColumn() ?: 0), - \'total_received\' => (db()->query("SELECT SUM(amount) FROM payments $out_w")->fetchColumn() ?: 0) + (db()->query("SELECT SUM(amount) FROM pos_payments WHERE 1=1 $out_and")->fetchColumn() ?: 0), - \'total_purchases\' => db()->query("SELECT SUM(total_with_vat) FROM purchases $out_w")->fetchColumn() ?: 0, - \'total_paid\' => db()->query("SELECT SUM(amount) FROM purchase_payments $out_w")->fetchColumn() ?: 0, - \'expired_items\' => db()->query("SELECT COUNT(*) FROM stock_items WHERE expiry_date IS NOT NULL AND expiry_date <= CURDATE() $out_and")->fetchColumn(), - \'near_expiry_items\' => db()->query("SELECT COUNT(*) FROM stock_items WHERE expiry_date IS NOT NULL AND expiry_date > CURDATE() AND expiry_date <= DATE_ADD(CURDATE(), INTERVAL 30 DAY) $out_and")->fetchColumn(), - \'low_stock_items_count\' => db()->query("SELECT COUNT(*) FROM stock_items WHERE stock_quantity <= min_stock_level $out_and")->fetchColumn(), - ];'; - -$c = str_replace($find_dashboard, $repl_dashboard, $c); - -// Also replace the queries for Cash Flow and Charts -$find_charts = ' $data[\'monthly_sales\'] = db()->query(" - SELECT label, SUM(tot) as total FROM ( - SELECT DATE_FORMAT(invoice_date, \'%M %Y\') as label, total_with_vat as tot, DATE_FORMAT(invoice_date, \'%Y-%m\') as sort_col FROM invoices - UNION ALL - SELECT DATE_FORMAT(created_at, \'%M %Y\') as label, net_amount as tot, DATE_FORMAT(created_at, \'%Y-%m\') as sort_col FROM pos_transactions WHERE status = \'completed\' - ) t - GROUP BY label, sort_col - ORDER BY sort_col ASC LIMIT 12 - ")->fetchAll(PDO::FETCH_ASSOC); - - $data[\'yearly_sales\'] = db()->query(" - SELECT label, SUM(tot) as total FROM ( - SELECT YEAR(invoice_date) as label, total_with_vat as tot FROM invoices - UNION ALL - SELECT YEAR(created_at) as label, net_amount as tot FROM pos_transactions WHERE status = \'completed\' - ) t - GROUP BY label - ORDER BY label ASC LIMIT 5 - ")->fetchAll(PDO::FETCH_ASSOC);'; - -$repl_charts = ' $data[\'monthly_sales\'] = db()->query(" - SELECT label, SUM(tot) as total FROM ( - SELECT DATE_FORMAT(invoice_date, \'%M %Y\') as label, total_with_vat as tot, DATE_FORMAT(invoice_date, \'%Y-%m\') as sort_col FROM invoices $out_w - UNION ALL - SELECT DATE_FORMAT(created_at, \'%M %Y\') as label, net_amount as tot, DATE_FORMAT(created_at, \'%Y-%m\') as sort_col FROM pos_transactions WHERE status = \'completed\' $out_and - ) t - GROUP BY label, sort_col - ORDER BY sort_col ASC LIMIT 12 - ")->fetchAll(PDO::FETCH_ASSOC); - - $data[\'yearly_sales\'] = db()->query(" - SELECT label, SUM(tot) as total FROM ( - SELECT YEAR(invoice_date) as label, total_with_vat as tot FROM invoices $out_w - UNION ALL - SELECT YEAR(created_at) as label, net_amount as tot FROM pos_transactions WHERE status = \'completed\' $out_and - ) t - GROUP BY label - ORDER BY label ASC LIMIT 5 - ")->fetchAll(PDO::FETCH_ASSOC);'; - -$c = str_replace($find_charts, $repl_charts, $c); - -file_put_contents('index.php', $c); -echo "Dashboard Patched\n"; diff --git a/patch_expenses.php b/patch_expenses.php deleted file mode 100644 index 5c98db2..0000000 --- a/patch_expenses.php +++ /dev/null @@ -1,9 +0,0 @@ -${companySettings.company_name || 'Your Company'} -

- ${companySettings.company_address || ''}
- Phone: ${companySettings.company_phone || ''} | Email: ${companySettings.company_email || ''} - ${companySettings.tax_number ? `
TRN: ${companySettings.tax_number}` : ''} -

-JS; - -$replace = <<<'JS' -

${data.outlet_name || companySettings.company_name || 'Your Company'}

-

- ${data.outlet_address ? data.outlet_address.replace(/\n/g, '
') : (companySettings.company_address || '').replace(/\n/g, '
')}
- Phone: ${data.outlet_phone || companySettings.company_phone || ''} | Email: ${companySettings.company_email || ''} - ${companySettings.tax_number ? `
TRN: ${companySettings.tax_number}` : ''} -

-JS; - -$content = str_replace($search, $replace, $content); -file_put_contents('index.php', $content); diff --git a/patch_others.php b/patch_others.php deleted file mode 100644 index c468f2c..0000000 --- a/patch_others.php +++ /dev/null @@ -1,25 +0,0 @@ -prepare\(\"INSERT INTO users \(username, password, email, phone, group_id\) VALUES \(\?, \?, \?, \?, \?\)\"\);.*?\\\$stmt->execute\(\[\\\$username, password_hash\(\\\$password, PASSWORD_DEFAULT\), \\\$email, \\\$phone, \\\$group_id\]\);/s", - "\$group_id = (int)(\$_POST['group_id'] ?? 0) ?: null;\n \$outlet_id = !empty(\$_POST['outlet_id']) ? (int)\$_POST['outlet_id'] : null;\n \$stmt = \$db->prepare(\"INSERT INTO users (username, password, email, phone, group_id, outlet_id) VALUES (?, ?, ?, ?, ?, ?)\");\n \$stmt->execute([\$username, password_hash(\$password, PASSWORD_DEFAULT), \$email, \$phone, \$group_id, \$outlet_id]);", - $content -); - -// 3. Fix Edit User POST -$content = preg_replace( - "/\\\$group_id = \(int\)\(\\\$_POST\['group_id'\] \?\? 0\) \?\: null;.*?if \(\!empty\(\\\$password\)\) \{.*?\\\$stmt = \\\$db->prepare\(\"UPDATE users SET username=\?, password=\?, email=\?, phone=\?, group_id=\? WHERE id=\?\"\);.*?\\\$stmt->execute\(\[\\\$username, password_hash\(\\\$password, PASSWORD_DEFAULT\), \\\$email, \\\$phone, \\\$group_id, \\\$id\]\);.*?\} else \{.*?\\\$stmt = \\\$db->prepare\(\"UPDATE users SET username=\?, email=\?, phone=\?, group_id=\? WHERE id=\?\"\);.*?\\\$stmt->execute\(\[\\\$username, \\\$email, \\\$phone, \\\$group_id, \\\$id\]\);.*?\}/s", - "\$group_id = (int)(\$_POST['group_id'] ?? 0) ?: null;\n \$outlet_id = !empty(\$_POST['outlet_id']) ? (int)\$_POST['outlet_id'] : null;\n if (!empty(\$password)) {\n \$stmt = \$db->prepare(\"UPDATE users SET username=?, password=?, email=?, phone=?, group_id=?, outlet_id=? WHERE id=?\");\n \$stmt->execute([\$username, password_hash(\$password, PASSWORD_DEFAULT), \$email, \$phone, \$group_id, \$outlet_id, \$id]);\n } else {\n \$stmt = \$db->prepare(\"UPDATE users SET username=?, email=?, phone=?, group_id=?, outlet_id=? WHERE id=?\");\n \$stmt->execute([\$username, \$email, \$phone, \$group_id, \$outlet_id, \$id]);\n }", - $content -); - -file_put_contents('index.php', $content); -echo "Patched auth & post logic\n"; diff --git a/patch_payment.php b/patch_payment.php deleted file mode 100644 index 5fb2a7a..0000000 --- a/patch_payment.php +++ /dev/null @@ -1,23 +0,0 @@ -prepare("SELECT p.*, i.customer_id, c.name as customer_name, - o.name as outlet_name, o.address as outlet_address, o.phone as outlet_phone - FROM payments p - JOIN invoices i ON p.invoice_id = i.id - LEFT JOIN customers c ON i.customer_id = c.id - LEFT JOIN outlets o ON i.outlet_id = o.id - WHERE p.id = ?"); -SQL; -$replace = <<<'SQL' - $stmt = db()->prepare("SELECT p.*, i.customer_id, i.id as inv_id, c.name as customer_name, - o.name as outlet_name, o.address as outlet_address, o.phone as outlet_phone - FROM payments p - JOIN invoices i ON p.invoice_id = i.id - LEFT JOIN customers c ON i.customer_id = c.id - LEFT JOIN outlets o ON i.outlet_id = o.id - WHERE p.id = ?"); -SQL; - -$content = str_replace($search, $replace, $content); -file_put_contents('index.php', $content); diff --git a/patch_posreceipt.php b/patch_posreceipt.php deleted file mode 100644 index 1dcd85b..0000000 --- a/patch_posreceipt.php +++ /dev/null @@ -1,37 +0,0 @@ -"; - const companyPhone = ""; - const companyVat = ""; - const companyLogo = ""; - - container.innerHTML = ` -
-
- ${companyLogo ? `Logo` : ''} -
${companyName}
- ${companyPhone ? `
هاتف / Tel: ${companyPhone}
` : ''} - ${companyVat ? `
الرقم الضريبي / VAT No: ${companyVat}
` : ''} -JS; - -$replace = <<<'JS' - const companyName = outletName || ""; - const companyPhone = outletPhone || ""; - const companyAddress = outletAddress ? outletAddress.replace(/\n/g, '
') : ""; - const companyVat = ""; - const companyLogo = ""; - - container.innerHTML = ` -
-
- ${companyLogo ? `Logo` : ''} -
${companyName}
- ${companyAddress ? `
${companyAddress}
` : ''} - ${companyPhone ? `
هاتف / Tel: ${companyPhone}
` : ''} - ${companyVat ? `
الرقم الضريبي / VAT No: ${companyVat}
` : ''} -JS; - -$content = str_replace($search, $replace, $content); -file_put_contents('index.php', $content); diff --git a/patch_qrcode.php b/patch_qrcode.php deleted file mode 100644 index 64cc16c..0000000 --- a/patch_qrcode.php +++ /dev/null @@ -1,17 +0,0 @@ -; - const vatNo = ; - const qrData = `Seller: ${companyName}\nVAT: ${vatNo}\nInvoice: INV-${data.id.toString().padStart(5, '0')}\nDate: ${data.invoice_date}\nTotal: ${grandTotalValue.toFixed(3)}`; -JS; - -$replace = <<<'JS' - const companyName = data.outlet_name || ; - const vatNo = ; - const qrData = `Seller: ${companyName}\nVAT: ${vatNo}\nInvoice: INV-${data.id.toString().padStart(5, '0')}\nDate: ${data.invoice_date}\nTotal: ${grandTotalValue.toFixed(3)}`; -JS; - -$content = str_replace($search, $replace, $content); -file_put_contents('index.php', $content); diff --git a/patch_quotations.php b/patch_quotations.php deleted file mode 100644 index 07f2c40..0000000 --- a/patch_quotations.php +++ /dev/null @@ -1,40 +0,0 @@ -prepare("SELECT q.*, c.name as customer_name - FROM quotations q - JOIN customers c ON q.customer_id = c.id - WHERE $whereSql -SQL; - -$replace_q = <<<'SQL' - $stmt = db()->prepare("SELECT q.*, c.name as customer_name, o.name as outlet_name, o.address as outlet_address, o.phone as outlet_phone - FROM quotations q - JOIN customers c ON q.customer_id = c.id - LEFT JOIN outlets o ON q.outlet_id = o.id - WHERE $whereSql -SQL; - -$content = str_replace($search_q, $replace_q, $content); - -// LPOs query update -$search_l = <<<'SQL' - $stmt = db()->prepare("SELECT q.*, s.name as supplier_name - FROM lpos q - JOIN suppliers s ON q.supplier_id = s.id - WHERE $whereSql -SQL; - -$replace_l = <<<'SQL' - $stmt = db()->prepare("SELECT q.*, s.name as supplier_name, o.name as outlet_name, o.address as outlet_address, o.phone as outlet_phone - FROM lpos q - JOIN suppliers s ON q.supplier_id = s.id - LEFT JOIN outlets o ON q.outlet_id = o.id - WHERE $whereSql -SQL; - -$content = str_replace($search_l, $replace_l, $content); - -file_put_contents('index.php', $content); diff --git a/patch_receipt.php b/patch_receipt.php deleted file mode 100644 index 034d128..0000000 --- a/patch_receipt.php +++ /dev/null @@ -1,15 +0,0 @@ - -

-HTML; - -$replace = <<<'HTML' -

-

-HTML; - -$content = str_replace($search, $replace, $content); -file_put_contents('index.php', $content); diff --git a/patch_showreceipt.php b/patch_showreceipt.php deleted file mode 100644 index ab79f6c..0000000 --- a/patch_showreceipt.php +++ /dev/null @@ -1,22 +0,0 @@ -"; - const rca = document.getElementById('receiptCompanyAddress'); - if(rca) rca.innerHTML = data.outlet_address ? data.outlet_address.replace(/\n/g, '
') : ""; - - // Update labels for Purchase vs Sale -JS; - -$content = str_replace($search, $replace, $content); -file_put_contents('index.php', $content); diff --git a/patch_users.php b/patch_users.php deleted file mode 100644 index 4b3de37..0000000 --- a/patch_users.php +++ /dev/null @@ -1,46 +0,0 @@ -prepare("INSERT INTO users (username, password, email, phone, group_id) VALUES (?, ?, ?, ?, ?)"); - try { - $stmt->execute([$username, $hashed_password, $email, $phone, $group_id]);'; - -$repl_add = ' $outlet_id = !empty($_POST[\'outlet_id\']) ? (int)$_POST[\'outlet_id\'] : null; - $stmt = db()->prepare("INSERT INTO users (username, password, email, phone, group_id, outlet_id) VALUES (?, ?, ?, ?, ?, ?)"); - try { - $stmt->execute([$username, $hashed_password, $email, $phone, $group_id, $outlet_id]);'; - -$c = str_replace($find_add, $repl_add, $c); - -// Fix Edit User -$find_edit = ' if ($password) { - $hashed_password = password_hash($password, PASSWORD_DEFAULT); - $stmt = db()->prepare("UPDATE users SET username = ?, password = ?, email = ?, phone = ?, group_id = ? WHERE id = ?"); - $stmt->execute([$username, $hashed_password, $email, $phone, $group_id, $id]); - } else { - $stmt = db()->prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ? WHERE id = ?"); - $stmt->execute([$username, $email, $phone, $group_id, $id]); - }'; - -$repl_edit = ' $outlet_id = !empty($_POST[\'outlet_id\']) ? (int)$_POST[\'outlet_id\'] : null; - if ($password) { - $hashed_password = password_hash($password, PASSWORD_DEFAULT); - $stmt = db()->prepare("UPDATE users SET username = ?, password = ?, email = ?, phone = ?, group_id = ?, outlet_id = ? WHERE id = ?"); - $stmt->execute([$username, $hashed_password, $email, $phone, $group_id, $outlet_id, $id]); - } else { - $stmt = db()->prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, outlet_id = ? WHERE id = ?"); - $stmt->execute([$username, $email, $phone, $group_id, $outlet_id, $id]); - }'; - -$c = str_replace($find_edit, $repl_edit, $c); - -// Fix login session -$c = str_replace( - "\$_SESSION['user_role_name'] = \$u['role_name'];", - "\$_SESSION['user_role_name'] = \$u['role_name'];\n \$_SESSION['outlet_id'] = \$u['outlet_id'];", - $c -); - -file_put_contents('index.php', $c); -echo "Patched users.php\n"; diff --git a/patch_users_1.php b/patch_users_1.php deleted file mode 100644 index 1729f50..0000000 --- a/patch_users_1.php +++ /dev/null @@ -1,99 +0,0 @@ -query("SELECT * FROM outlets WHERE status = 'active'")->fetchAll(PDO::FETCH_ASSOC); - \$cur_out = \$_SESSION['outlet_id'] ?? 0; - \$cur_name = 'All Outlets'; - foreach (\$outlets as \$o) { if (\$o['id'] == \$cur_out) \$cur_name = \$o['name']; } - ?> - - -EOD; - -$new_nav = << 1): - if (\$is_admin) { - \$outlets = db()->query("SELECT * FROM outlets WHERE status = 'active'")->fetchAll(PDO::FETCH_ASSOC); - } else { - \$in_clause = implode(',', array_map('intval', \$assigned_outlets_arr)); - \$outlets = db()->query("SELECT * FROM outlets WHERE status = 'active' AND id IN (\$in_clause)")->fetchAll(PDO::FETCH_ASSOC); - } - \$cur_out = \$_SESSION['outlet_id'] ?? 0; - \$cur_name = \$is_admin ? 'All Outlets' : (count(\$outlets) > 0 ? \$outlets[0]['name'] : 'Select Outlet'); - foreach (\$outlets as \$o) { if (\$o['id'] == \$cur_out) \$cur_name = \$o['name']; } - ?> - - -EOD; - -$content = str_replace($old_nav, $new_nav, $content); - -file_put_contents($file, $content); -echo "Patch 1 applied.\n"; diff --git a/patch_users_2.php b/patch_users_2.php deleted file mode 100644 index 0ef75fc..0000000 --- a/patch_users_2.php +++ /dev/null @@ -1,44 +0,0 @@ -prepare("INSERT INTO users (username, password, email, phone, group_id, outlet_id) VALUES (?, ?, ?, ?, ?, ?)"); - try { - \$stmt->execute([\$username, \$hashed_password, \$email, \$phone, \$group_id, \$outlet_id]); -EOD; - -$new_add = <<prepare("INSERT INTO users (username, password, email, phone, group_id, outlet_id, assigned_outlets) VALUES (?, ?, ?, ?, ?, ?, ?)"); - try { - \$stmt->execute([\$username, \$hashed_password, \$email, \$phone, \$group_id, \$outlet_id, \$assigned_outlets]); -EOD; -$content = str_replace($old_add, $new_add, $content); - -// edit_user backend -$old_edit = <<prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ?, outlet_id = ? WHERE id = ?"); - \$stmt->execute([\$username, \$email, \$phone, \$group_id, \$status, \$outlet_id, \$id]); -EOD; - -$new_edit = <<prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ?, outlet_id = ?, assigned_outlets = ? WHERE id = ?"); - \$stmt->execute([\$username, \$email, \$phone, \$group_id, \$status, \$outlet_id, \$assigned_outlets, \$id]); -EOD; -$content = str_replace($old_edit, $new_edit, $content); - -file_put_contents($file, $content); -echo "Patch 2 applied.\n"; diff --git a/patch_users_3.php b/patch_users_3.php deleted file mode 100644 index 0b0c05e..0000000 --- a/patch_users_3.php +++ /dev/null @@ -1,64 +0,0 @@ - - - -
-EOD; - -$new_add_ui = << - - -
Hold Ctrl/Cmd to select multiple outlets.
-
-EOD; - -$content = str_replace($old_add_ui, $new_add_ui, $content); - -// edit_user form -$old_edit_ui = << - - -
-EOD; - -$new_edit_ui = << - - -
Hold Ctrl/Cmd to select multiple outlets.
-
-EOD; - -$content = str_replace($old_edit_ui, $new_edit_ui, $content); - -file_put_contents($file, $content); -echo "Patch 3 applied.\n"; diff --git a/patch_users_4.php b/patch_users_4.php deleted file mode 100644 index 724466a..0000000 --- a/patch_users_4.php +++ /dev/null @@ -1,45 +0,0 @@ - - - - -EOD; - -$new_action = << - - - - -
- - -
- - -EOD; - -$content = str_replace($old_action, $new_action, $content); -file_put_contents($file, $content); -echo "Patch 4 applied.\n"; diff --git a/patch_users_5.php b/patch_users_5.php deleted file mode 100644 index 9f9750c..0000000 --- a/patch_users_5.php +++ /dev/null @@ -1,43 +0,0 @@ - - - -EOD; - -$new_display = << - Global / All Outlets'; - } else { - foreach ((\$data["outlets"] ?? []) as \$out) { - if (in_array(\$out["id"], \$assigned)) { - echo '' . htmlspecialchars(\$out["name"]) . ''; - } - } - } - ?> - -EOD; - -$content = str_replace($old_display, $new_display, $content); -file_put_contents($file, $content); -echo "Patch 5 applied.\n"; diff --git a/patch_users_6.php b/patch_users_6.php deleted file mode 100644 index 9b12e14..0000000 --- a/patch_users_6.php +++ /dev/null @@ -1,44 +0,0 @@ -prepare("INSERT INTO users (username, password, email, phone, group_id, outlet_id, assigned_outlets) VALUES (?, ?, ?, ?, ?, ?, ?)"); -EOD; - -$new_add = <<prepare("INSERT INTO users (username, password, email, phone, group_id, outlet_id, assigned_outlets) VALUES (?, ?, ?, ?, ?, ?, ?)"); -EOD; -$content = str_replace($old_add, $new_add, $content); - -// edit_user -$old_edit = <<prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ?, outlet_id = ?, assigned_outlets = ? WHERE id = ?"); -EOD; - -$new_edit = <<prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ?, outlet_id = ?, assigned_outlets = ? WHERE id = ?"); -EOD; -$content = str_replace($old_edit, $new_edit, $content); - -file_put_contents($file, $content); -echo "Patch 6 applied.\n"; diff --git a/patch_users_edit_post.php b/patch_users_edit_post.php deleted file mode 100644 index 6b3b5d1..0000000 --- a/patch_users_edit_post.php +++ /dev/null @@ -1,17 +0,0 @@ -prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ? WHERE id = ?"); - $stmt->execute([$username, $email, $phone, $group_id, $status, $id]);'; - -$repl_edit_post = '$status = $_POST[\'status\'] ?? \'active\'; - $outlet_id = !empty($_POST[\'outlet_id\']) ? (int)$_POST[\'outlet_id\'] : null; - if ($id && $username) { - $stmt = db()->prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ?, outlet_id = ? WHERE id = ?"); - $stmt->execute([$username, $email, $phone, $group_id, $status, $outlet_id, $id]);'; - -$c = str_replace($find_edit_post, $repl_edit_post, $c); -file_put_contents('index.php', $c); -echo "Edit Post Patched\n"; diff --git a/patch_users_edit_ui.php b/patch_users_edit_ui.php deleted file mode 100644 index ab9448e..0000000 --- a/patch_users_edit_ui.php +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - '; - -$repl_group_edit = $find_group_edit . ' -
- - -
'; - -$c = str_replace($find_group_edit, $repl_group_edit, $c); - -// Also we need to make sure 'status' was updated in Edit User POST! -// Looking at the previous edit_user patch, I didn't add status. I will add status now since the UI has it! -// Actually, earlier the backend code didn't update `status`? -// Let me just replace the file contents. - -file_put_contents('index.php', $c); -echo "UI Edit Patched\n"; diff --git a/patch_users_ui.php b/patch_users_ui.php deleted file mode 100644 index bf504f5..0000000 --- a/patch_users_ui.php +++ /dev/null @@ -1,34 +0,0 @@ -query(\"SELECT id, name FROM role_groups ORDER BY name ASC\")->fetchAll();\n break;\n case 'backups':", - "\$data['role_groups'] = db()->query(\"SELECT id, name FROM role_groups ORDER BY name ASC\")->fetchAll();\n \$data['outlets'] = db()->query(\"SELECT id, name FROM outlets ORDER BY name ASC\")->fetchAll();\n break;\n case 'backups':", - $c -); - -// Add Outlet field to Add User -$find_group_add = ' - '; - -$repl_group_add = $find_group_add . ' -
- - -
'; - -$c = str_replace($find_group_add, $repl_group_add, $c); - -file_put_contents('index.php', $c); -echo "UI Patched\n"; diff --git a/patch_viewquot.php b/patch_viewquot.php deleted file mode 100644 index 0d5801a..0000000 --- a/patch_viewquot.php +++ /dev/null @@ -1,19 +0,0 @@ -'); - const companyVat = companySettings.vat_number ? `

VAT: ${companySettings.vat_number}

` : ''; - const companyPhone = companySettings.company_phone ? `

Tel: ${companySettings.company_phone}

` : ''; -JS; - -$replace = <<<'JS' - const companyName = data.outlet_name || companySettings.company_name || 'Accounting System'; - const companyAddress = data.outlet_address ? data.outlet_address.replace(/\n/g, '
') : (companySettings.company_address || '').replace(/\n/g, '
'); - const companyVat = companySettings.vat_number ? `

VAT: ${companySettings.vat_number}

` : ''; - const companyPhone = data.outlet_phone ? `

Tel: ${data.outlet_phone}

` : (companySettings.company_phone ? `

Tel: ${companySettings.company_phone}

` : ''); -JS; - -$content = str_replace($search, $replace, $content); -file_put_contents('index.php', $content); diff --git a/post_debug.log b/post_debug.log index 26a2c7e..42681fe 100644 --- a/post_debug.log +++ b/post_debug.log @@ -18,3 +18,6 @@ 2026-02-26 03:09:24 - POST: {"action":"translate","text":"LAMING RED KIDNEY BEANS 425","target":"ar"} 2026-02-26 03:09:34 - POST: {"id":"62","name_en":"LAMING RED KIDNEY BEANS 425","name_ar":"\u0641\u0627\u0635\u0648\u0644\u064a\u0627\u0621 \u062d\u0645\u0631\u0627\u0621 \u0644\u0627\u0645\u064a\u0646\u062c 425","sku":"000023071605","category_id":"2","unit_id":"1","supplier_id":"5","sale_price":"0.25","purchase_price":"0.2","stock_quantity":"0","min_stock_level":"0","vat_rate":"0.00","expiry_date":"","promotion_start":"","promotion_end":"","promotion_percent":"0","edit_item":""} 2026-02-26 03:11:08 - POST: {"action":"save_pos_transaction","customer_id":"","payments":"[{\"method\":\"cash\",\"amount\":1.7}]","total_amount":"1.7000000000000002","tax_amount":"0","discount_code_id":"","discount_amount":"0","loyalty_redeemed":"0","items":"[{\"id\":48,\"qty\":1,\"price\":1.3,\"vat_rate\":0,\"vat_amount\":0},{\"id\":17,\"qty\":1,\"price\":0.4,\"vat_rate\":0,\"vat_amount\":0}]"} +2026-02-26 05:17:43 - POST: {"action":"save_theme","theme":"forest"} +2026-02-26 05:17:47 - POST: {"action":"save_theme","theme":"default"} +2026-02-26 05:47:24 - POST: {"action":"save_pos_transaction","customer_id":"","payments":"[{\"method\":\"cash\",\"amount\":2.6}]","total_amount":"2.6","tax_amount":"0","discount_code_id":"","discount_amount":"0","loyalty_redeemed":"0","items":"[{\"id\":19,\"qty\":1,\"price\":1.2,\"vat_rate\":0,\"vat_amount\":0},{\"id\":12,\"qty\":1,\"price\":1.2,\"vat_rate\":0,\"vat_amount\":0},{\"id\":13,\"qty\":1,\"price\":0.2,\"vat_rate\":0,\"vat_amount\":0}]"} diff --git a/update_payment.php b/update_payment.php deleted file mode 100644 index ea1de35..0000000 --- a/update_payment.php +++ /dev/null @@ -1,21 +0,0 @@ -prepare("SELECT p.*, i.customer_id, c.name as customer_name - FROM payments p - JOIN invoices i ON p.invoice_id = i.id - JOIN customers c ON i.customer_id = c.id - WHERE p.id = ?"); -SQL; -$replace = <<<'SQL' - $stmt = db()->prepare("SELECT p.*, i.customer_id, i.type as inv_type, i.id as inv_id, c.name as customer_name, - o.name as outlet_name, o.address as outlet_address, o.phone as outlet_phone - FROM payments p - JOIN invoices i ON p.invoice_id = i.id - LEFT JOIN customers c ON i.customer_id = c.id - LEFT JOIN outlets o ON i.outlet_id = o.id - WHERE p.id = ?"); -SQL; - -$content = str_replace($search, $replace, $content); -file_put_contents('index.php', $content); // oops wait, file_put_contents