38471-vm/patch_inserts.php
2026-02-25 09:58:14 +00:00

69 lines
3.8 KiB
PHP

<?php
$content = file_get_contents('index.php');
$patterns = [
// Invoices (POS)
[
'INSERT INTO invoices (transaction_no, customer_id, invoice_date, payment_type, total_amount, vat_amount, total_with_vat, paid_amount, status, register_session_id, is_pos, discount_amount, loyalty_points_redeemed, created_by)',
'INSERT INTO invoices (outlet_id, transaction_no, customer_id, invoice_date, payment_type, total_amount, vat_amount, total_with_vat, paid_amount, status, register_session_id, is_pos, discount_amount, loyalty_points_redeemed, created_by)',
'?, ?, ?, ?, ?, ?, ?, ?, ?, \'paid\', ?, 1, ?, ?, ?',
'".(int)($_SESSION["outlet_id"] ?? 1).", ?, ?, ?, ?, ?, ?, ?, ?, \'paid\', ?, 1, ?, ?, ?'
],
// Quotations
[
'INSERT INTO quotations (customer_id, quotation_date, valid_until, status, total_amount, vat_amount, total_with_vat)',
'INSERT INTO quotations (outlet_id, customer_id, quotation_date, valid_until, status, total_amount, vat_amount, total_with_vat)',
'?, ?, ?, ?, ?, ?, ?',
'".(int)($_SESSION["outlet_id"] ?? 1).", ?, ?, ?, ?, ?, ?, ?'
],
// Lpos
[
'INSERT INTO lpos (supplier_id, lpo_date, delivery_date, status, total_amount, vat_amount, total_with_vat, terms_conditions)',
'INSERT INTO lpos (outlet_id, supplier_id, lpo_date, delivery_date, status, total_amount, vat_amount, total_with_vat, terms_conditions)',
'?, ?, ?, \'pending\', ?, ?, ?, ?',
'".(int)($_SESSION["outlet_id"] ?? 1).", ?, ?, ?, \'pending\', ?, ?, ?, ?'
],
// Invoices (General)
[
'INSERT INTO invoices (customer_id, invoice_date, status, payment_type, total_amount, vat_amount, total_with_vat, paid_amount)',
'INSERT INTO invoices (outlet_id, customer_id, invoice_date, status, payment_type, total_amount, vat_amount, total_with_vat, paid_amount)',
'?, ?, \'unpaid\', \'credit\', ?, ?, ?, 0',
'".(int)($_SESSION["outlet_id"] ?? 1).", ?, ?, \'unpaid\', \'credit\', ?, ?, ?, 0'
],
// Purchases (General)
[
'INSERT INTO purchases (supplier_id, invoice_date, status, payment_type, total_amount, vat_amount, total_with_vat, paid_amount)',
'INSERT INTO purchases (outlet_id, supplier_id, invoice_date, status, payment_type, total_amount, vat_amount, total_with_vat, paid_amount)',
'?, ?, \'unpaid\', \'credit\', ?, ?, ?, 0',
'".(int)($_SESSION["outlet_id"] ?? 1).", ?, ?, \'unpaid\', \'credit\', ?, ?, ?, 0'
],
// Expenses
[
'INSERT INTO expenses (category_id, amount, expense_date, reference_no, description)',
'INSERT INTO expenses (outlet_id, category_id, amount, expense_date, reference_no, description)',
'(int)$_POST[\'category_id\'], $amt, $date, $_POST[\'reference_no\'] ?? \'\', $desc',
'".(int)($_SESSION["outlet_id"] ?? 1).", (int)$_POST[\'category_id\'], $amt, $date, $_POST[\'reference_no\'] ?? \'\', $desc'
],
// Users
[
'INSERT INTO users (username, password, email, phone, group_id)',
'INSERT INTO users (outlet_id, username, password, email, phone, group_id)',
'?, ?, ?, ?, ?',
'".(int)($_SESSION["outlet_id"] ?? 1).", ?, ?, ?, ?, ?'
]
];
foreach ($patterns as $p) {
if (strpos($content, $p[0]) !== false) {
$content = str_replace($p[0], $p[1], $content);
$content = str_replace($p[2], $p[3], $content);
echo "Patched " . explode(' ', $p[0])[2] . "\n";
}
}
// Don't forget invoice_items insertion
$p1 = 'INSERT INTO invoice_items (invoice_id, item_id, quantity, unit_price, vat_amount, total_price) VALUES (?, ?, ?, ?, ?, ?)';
$p2 = 'INSERT INTO invoice_items (invoice_id, item_id, quantity, unit_price, vat_amount, total_price) VALUES (?, ?, ?, ?, ?, ?)';
// Actually wait, invoice_items doesn't have outlet_id... No wait, does it?
file_put_contents('index.php', $content);