77 lines
3.1 KiB
PHP
77 lines
3.1 KiB
PHP
<?php
|
|
$c = file_get_contents('includes/app.php');
|
|
$c = str_replace("migrated_sales_cols_", "migrated_sales_cols_v2_", $c);
|
|
|
|
// add to auto migration
|
|
$s1 = <<<S1
|
|
$stmt2 = \pdo->query("SHOW COLUMNS FROM branches LIKE 'avatar'");
|
|
if (\$stmt2->rowCount() === 0) {
|
|
\$pdo->exec("ALTER TABLE branches ADD COLUMN avatar varchar(255) DEFAULT NULL");
|
|
}
|
|
@file_put_contents(\$flagFile, '1');
|
|
S1;
|
|
|
|
$r1 = <<<R1
|
|
$stmt2 = \pdo->query("SHOW COLUMNS FROM branches LIKE 'avatar'");
|
|
if (\$stmt2->rowCount() === 0) {
|
|
\$pdo->exec("ALTER TABLE branches ADD COLUMN avatar varchar(255) DEFAULT NULL");
|
|
}
|
|
\$stmt3 = \pdo->query("SHOW COLUMNS FROM sales_orders LIKE 'customer_id'");
|
|
if (\$stmt3->rowCount() === 0) {
|
|
\$pdo->exec("ALTER TABLE sales_orders ADD COLUMN customer_id int(10) unsigned DEFAULT NULL");
|
|
}
|
|
\$stmt4 = \pdo->query("SHOW COLUMNS FROM sales_orders LIKE 'payment_status'");
|
|
if (\$stmt4->rowCount() === 0) {
|
|
\$pdo->exec("ALTER TABLE sales_orders ADD COLUMN payment_status varchar(20) NOT NULL DEFAULT 'paid'");
|
|
}
|
|
@file_put_contents(\$flagFile, '1');
|
|
R1;
|
|
|
|
$c = str_replace($s1, $r1, $c);
|
|
|
|
// add to ensure_sales_table()
|
|
$s2 = <<<S2
|
|
customer_name VARCHAR(120) DEFAULT NULL,
|
|
payment_method VARCHAR(30) NOT NULL,
|
|
S2;
|
|
|
|
$r2 = <<<R2
|
|
customer_id INT(10) UNSIGNED DEFAULT NULL,
|
|
customer_name VARCHAR(120) DEFAULT NULL,
|
|
payment_method VARCHAR(30) NOT NULL,
|
|
payment_status VARCHAR(20) NOT NULL DEFAULT 'paid',
|
|
R2;
|
|
$c = str_replace($s2, $r2, $c);
|
|
|
|
// add to create_sale
|
|
$s3 = <<<S3
|
|
(receipt_no, sale_mode, branch_code, cashier_username, cashier_name, role_name, customer_name, payment_method, items_json, item_count, subtotal, vat_amount, total_amount, status, notes, sale_date)
|
|
VALUES
|
|
(:receipt_no, :sale_mode, :branch_code, :cashier_username, :cashier_name, :role_name, :customer_name, :payment_method, :items_json, :item_count, :subtotal, :vat_amount, :total_amount, :status, :notes, NOW())
|
|
);
|
|
S3;
|
|
|
|
$r3 = <<<R3
|
|
(receipt_no, sale_mode, branch_code, cashier_username, cashier_name, role_name, customer_id, customer_name, payment_method, payment_status, items_json, item_count, subtotal, vat_amount, total_amount, status, notes, sale_date)
|
|
VALUES
|
|
(:receipt_no, :sale_mode, :branch_code, :cashier_username, :cashier_name, :role_name, :customer_id, :customer_name, :payment_method, :payment_status, :items_json, :item_count, :subtotal, :vat_amount, :total_amount, :status, :notes, NOW())
|
|
);
|
|
R3;
|
|
$c = str_replace($s3, $r3, $c);
|
|
|
|
$s4 = <<<S4
|
|
$stmt->bindValue(':customer_name', $data['customer_name']);
|
|
$stmt->bindValue(':payment_method', $data['payment_method']);
|
|
S4;
|
|
|
|
$r4 = <<<R4
|
|
$stmt->bindValue(':customer_id', $data['customer_id'] ?? null, PDO::PARAM_INT);
|
|
$stmt->bindValue(':customer_name', $data['customer_name']);
|
|
$stmt->bindValue(':payment_method', $data['payment_method']);
|
|
$stmt->bindValue(':payment_status', $data['payment_status'] ?? 'paid');
|
|
R4;
|
|
$c = str_replace($s4, $r4, $c);
|
|
|
|
file_put_contents('includes/app.php', $c);
|
|
echo "Patched includes/app.php\n";
|