🎉 Driving School is released. Read more →
Paid Scripts
Company Manager
Integrations
rcore_hotel

rcore_hotel integration

Set your Config.billingType = 4

-- 1 = esx_billing
-- 2 = okokbilling
-- 3 = okokbilling v2
local billingType = Config.billingType
 
 
--Open database function if you have any more edits
--If true remove player from hotel room
function checkInvoices(identifier, cb)
    if billingType == 2 or billingType == 3 then
        MySQL.Async.fetchAll(
            'SELECT * FROM `okokbilling` WHERE `receiver_identifier` = @identifier AND `paid_date` IS NULL', {
                ['@identifier'] = identifier,
            }, function(data)
                if data[1] ~= nil then
                    cb(data)
                else
                    cb({})
                end
            end)
    end
    if billingType == 1 then
        MySQL.Async.fetchAll(
            'SELECT * FROM `billing` WHERE `identifier`=@identifier AND `sender`=@identifier AND `paid_date` IS NULL', {
                ['@identifier'] = identifier,
            }, function(data)
                if data[1] ~= nil then
                    cb(data)
                else
                    cb({})
                end
            end)
    end
    if billingType == 4 then
        MySQL.Async.fetchAll('SELECT * FROM `billings` WHERE `identifier` = @identifier AND `status` = "unpaid"', {
            ['@identifier'] = identifier,
        }, function(data)
            if data[1] ~= nil then
                cb(data)
            else
                cb({})
            end
        end)
    end
end
 
--Create bill in invoices
function createBill(identifier, amount, room, extra, cb)
    if billingType == 3 then
        local xPlayer = ESX.GetPlayerFromIdentifier(identifier)
        if not xPlayer then
            local result = MySQL.Sync.fetchAll("SELECT * FROM users WHERE identifier=@identifier LIMIT 1", {
                ["@identifier"] = identifier,
            })
 
            if next(result) == nil then
                print('Cant create invoice for ' .. identifier .. ' because he is not in the database')
                cb({})
                return
            end
 
            result = result[1]
 
            TriggerEvent("okokBilling:CreateCustomInvoiceOffline", identifier, result.firstname .. " " .. result
                .lastname, amount, string.format('%s - %s', _U('hotel_room_invoice'), room.door.name), "hotel bill",
                Config.PayoutSociety, Config.PayoutSociety)
 
            cb({})
        else
            TriggerEvent("okokBilling:CreateCustomInvoice", xPlayer.source, amount,
                string.format('%s - %s', _U('hotel_room_invoice'), room.door.name), "hotel bill", Config.PayoutSociety,
                Config.PayoutSociety)
            cb({})
        end
    end
    if billingType == 2 then
        local result = MySQL.Sync.fetchAll("SELECT * FROM users WHERE identifier=@identifier LIMIT 1", {
            ["@identifier"] = identifier,
        })
 
        result = result[1]
 
 
        MySQL.Async.insert(
            'INSERT INTO okokBilling (receiver_identifier, receiver_name, author_identifier, author_name, society, society_name, item, invoice_value, status, notes, sent_date, limit_pay_date) VALUES (@receiver_identifier, @receiver_name, @author_identifier, @author_name, @society, @society_name, @item, @invoice_value, @status, @notes, CURRENT_TIMESTAMP(), DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL @limit_pay_date DAY))',
            {
                ['@receiver_identifier'] = identifier,
                ['@receiver_name'] = result.firstname .. " " .. result.lastname,
                ['@author_identifier'] = identifier,
                ['@author_name'] = result.firstname .. " " .. result.lastname,
                ['@society'] = Config.PayoutSociety,
                ['@society_name'] = Config.PayoutSociety,
                ['@item'] = "none",
                ['@invoice_value'] = amount,
                ['@status'] = "unpaid",
                ['@notes'] = string.format('%s - %s', _U('hotel_room_invoice'), room.door.name),
                ['@limit_pay_date'] = 7
            }, function(data)
                cb(data)
            end)
    end
    if billingType == 1 then
        MySQL.Async.execute(
            'INSERT INTO `billing` (`identifier`, `sender`, `target_type`, `target`, `label`, `amount`, `extra`) VALUES (@identifier,@identifier,@targetType,@target,@label,@amount,@extra)',
            {
                ['@identifier'] = identifier,
                ['@targetType'] = 'society',
                ['@target'] = Config.PayoutSociety,
                ['@label'] = string.format('%s - %s', _U('hotel_room_invoice'), room.door.name),
                ['@amount'] = tonumber(amount),
                ['@extra'] = json.encode(extra)
            }, function(data)
                cb(data)
            end)
    end
    if billingType == 4 then
        local from = {
            label = Config.PayoutSociety,
            job = Config.PayoutSociety,
            identifier = Config.PayoutSociety,
        }
        TriggerEvent('bill:createBill', identifier, tonumber(amount),
            string.format('%s - %s', _U('hotel_room_invoice'), room.door.name), from)
    end
end
 
--Delete bill
function deleteHotelRoom(room, identifier, hotel, cb)
    MySQL.Async.execute('DELETE FROM `hotels_rooms` WHERE hotel=@hotel AND doorName=@doorName AND owner=@owner LIMIT 1',
        {
            ['@doorName'] = room.name,
            ['@owner'] = identifier,
            ['@hotel'] = hotel.name or hotel
        }, function(changes)
            cb(changes and changes > 0)
        end)
end
Last updated on