Accueil › Documentation › Installation · origen_billing

Installation · origen_billing

1. Base de données

Exécute le SQL suivant dans ta base de données avant de démarrer la ressource pour la première fois.

sql
CREATE TABLE IF NOT EXISTS `origen_billing_jobs` (
    `id`                    INT           NOT NULL AUTO_INCREMENT,
    `job_name`              VARCHAR(50)   NOT NULL,
    `label`                 VARCHAR(100)  NOT NULL DEFAULT '',
    `society_account`       VARCHAR(100)  NOT NULL DEFAULT '',
    `can_invoice`           TINYINT(1)    NOT NULL DEFAULT 1,
    `commission`            DECIMAL(5,2)  NOT NULL DEFAULT 0.00,
    `society_loss`          DECIMAL(5,2)  NOT NULL DEFAULT 0.00,
    `active`                TINYINT(1)    NOT NULL DEFAULT 1,
    `autopay_enabled`       TINYINT(1)    NOT NULL DEFAULT 0,
    `autopay_mode`          ENUM('immediate','delayed') NOT NULL DEFAULT 'immediate',
    `autopay_delay_hours`   INT           NOT NULL DEFAULT 0,
    `created_at`            TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at`            TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uq_job_name` (`job_name`),
    KEY `idx_job_active` (`active`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
CREATE TABLE IF NOT EXISTS `origen_billing_products` (
    `id`          INT           NOT NULL AUTO_INCREMENT,
    `job_name`    VARCHAR(50)   NOT NULL,
    `name`        VARCHAR(100)  NOT NULL,
    `description` VARCHAR(255)  NOT NULL DEFAULT '',
    `price`       DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    `active`      TINYINT(1)    NOT NULL DEFAULT 1,
    `created_at`  TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    KEY `idx_product_job`    (`job_name`),
    KEY `idx_product_active` (`active`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
CREATE TABLE IF NOT EXISTS `origen_billing_invoice_items` (
    `id`          INT           NOT NULL AUTO_INCREMENT,
    `invoice_id`  INT           NOT NULL,
    `product_id`  INT           DEFAULT NULL,
    `name`        VARCHAR(100)  NOT NULL,
    `price`       DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    `quantity`    INT           NOT NULL DEFAULT 1,
    `subtotal`    DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    PRIMARY KEY (`id`),
    KEY `idx_item_invoice` (`invoice_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
CREATE TABLE IF NOT EXISTS `origen_billing_invoices` (
    `id`                   INT           NOT NULL AUTO_INCREMENT,
    `target_identifier`    VARCHAR(100)  NOT NULL,
    `target_name`          VARCHAR(100)  NOT NULL DEFAULT '',
    `author_identifier`    VARCHAR(100)  NOT NULL,
    `author_name`          VARCHAR(100)  NOT NULL DEFAULT '',
    `job_name`             VARCHAR(50)   NOT NULL,
    `company_label`        VARCHAR(100)  NOT NULL DEFAULT '',
    `society_account`      VARCHAR(100)  NOT NULL,
    `amount`               DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    `description`          VARCHAR(255)  NOT NULL DEFAULT '',
    `notes`                TEXT          DEFAULT NULL,
    `status`               ENUM('pending','paid','cancelled') NOT NULL DEFAULT 'pending',
    `commission_percent`   DECIMAL(5,2)  NOT NULL DEFAULT 0.00,
    `society_loss_percent` DECIMAL(5,2)  NOT NULL DEFAULT 0.00,
    `net_amount`           DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    `commission_amount`    DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    `society_amount`       DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    `commission_status`    ENUM('none','pending','delivered') NOT NULL DEFAULT 'none',
    `commission_paid_at`   TIMESTAMP     NULL DEFAULT NULL,
    `paid_at`              TIMESTAMP     NULL DEFAULT NULL,
    `cancelled_by`         VARCHAR(100)  NULL DEFAULT NULL,
    `context_data`         TEXT          NULL DEFAULT NULL,
    `autopay_enabled`      TINYINT(1)    NOT NULL DEFAULT 0,
    `autopay_mode`         ENUM('immediate','delayed') NOT NULL DEFAULT 'immediate',
    `autopay_delay_hours`  INT           NOT NULL DEFAULT 0,
    `autopay_state`        ENUM('none','scheduled','retrying','retry_on_login','done') NOT NULL DEFAULT 'none',
    `autopay_attempts`     INT           NOT NULL DEFAULT 0,
    `autopay_next_try_at`  TIMESTAMP     NULL DEFAULT NULL,
    `autopay_last_error`   VARCHAR(64)   NULL DEFAULT NULL,
    `created_at`           TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    KEY `idx_target`     (`target_identifier`),
    KEY `idx_author`     (`author_identifier`),
    KEY `idx_job`        (`job_name`),
    KEY `idx_status`     (`status`),
    KEY `idx_commission` (`commission_status`),
    KEY `idx_autopay`    (`autopay_state`, `autopay_next_try_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

2. server.cfg

Ajoute la ressource après ses dépendances :

cfg
ensure ox_lib
ensure oxmysql
ensure origen_billing

3. Chargement initial des métiers

Les métiers listés dans Config.AuthorizedJobs (dans config.lua) sont uniquement des données initiales. Ils sont insérés dans la base de données au premier démarrage de la ressource, si le métier n’existe pas déjà.

Après le premier démarrage, toute la gestion des métiers se fait depuis le panneau d’administration en jeu (/billingadmin). Les modifications de Config.AuthorizedJobs n’écraseront pas les enregistrements existants dans la base de données.

Pour réinitialiser un métier à ses valeurs initiales, supprime sa ligne dans origen_billing_jobs et redémarre la ressource.


4. Webhooks Discord (facultatif)

Ouvre svconfig.lua et mets enabled = true avec les URL de tes webhooks :

lua
return {
    enabled = true,
    webhooks = {
        ['invoice-created']   = 'https://discord.com/api/webhooks/...',
        ['invoice-paid']      = 'https://discord.com/api/webhooks/...',
        ['invoice-cancelled'] = 'https://discord.com/api/webhooks/...',
        ['commission-paid']   = 'https://discord.com/api/webhooks/...',
    },
}