From 693bd8b898d0c4f1305ba0f385f900db4ae74d00 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Tue, 5 Aug 2025 15:24:24 +0200 Subject: [PATCH] Update billing_server.lua --- .../[tools]/nordi_billing/billing_server.lua | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/resources/[tools]/nordi_billing/billing_server.lua b/resources/[tools]/nordi_billing/billing_server.lua index e5851351a..49b8a2fc9 100644 --- a/resources/[tools]/nordi_billing/billing_server.lua +++ b/resources/[tools]/nordi_billing/billing_server.lua @@ -316,22 +316,39 @@ end -- Create the necessary database tables if they don't exist MySQL.ready(function() - MySQL.query.await([[ - CREATE TABLE IF NOT EXISTS billing_accounts ( - id INT AUTO_INCREMENT PRIMARY KEY, - bill_id INT, - bill_description VARCHAR(255), - sender_id VARCHAR(50), - receiver_id VARCHAR(50), - account_id VARCHAR(50), - amount DECIMAL(10,2), - created_at DATETIME, - paid TINYINT DEFAULT 0, - declined TINYINT DEFAULT 0, - paid_at DATETIME - ) - ]]) + -- First check if the billing_accounts table exists + local tableExists = MySQL.query.await("SHOW TABLES LIKE 'billing_accounts'") + if #tableExists > 0 then + -- Table exists, check if the declined column exists + local columnExists = MySQL.query.await("SHOW COLUMNS FROM billing_accounts LIKE 'declined'") + + if #columnExists == 0 then + -- Add the declined column if it doesn't exist + MySQL.query.await("ALTER TABLE billing_accounts ADD COLUMN declined TINYINT DEFAULT 0") + print("^2[nordi_billing] Added 'declined' column to billing_accounts table^7") + end + else + -- Create the table with all required columns + MySQL.query.await([[ + CREATE TABLE IF NOT EXISTS billing_accounts ( + id INT AUTO_INCREMENT PRIMARY KEY, + bill_id INT, + bill_description VARCHAR(255), + sender_id VARCHAR(50), + receiver_id VARCHAR(50), + account_id VARCHAR(50), + amount DECIMAL(10,2), + created_at DATETIME, + paid TINYINT DEFAULT 0, + declined TINYINT DEFAULT 0, + paid_at DATETIME + ) + ]]) + print("^2[nordi_billing] Created billing_accounts table^7") + end + + -- Create offline_payments table if it doesn't exist MySQL.query.await([[ CREATE TABLE IF NOT EXISTS offline_payments ( id INT AUTO_INCREMENT PRIMARY KEY, @@ -342,7 +359,10 @@ MySQL.ready(function() processed TINYINT DEFAULT 0 ) ]]) -end) + print("^2[nordi_billing] Database tables initialized^7") +end) -- Added closing parenthesis here + + -- Handle offline payments when a player logs in RegisterNetEvent('QBCore:Server:PlayerLoaded', function()