2026-04-20 06:43:09 +00:00
|
|
|
const { DataTypes } = require('sequelize');
|
|
|
|
|
const sequelize = require('../config/db');
|
|
|
|
|
|
|
|
|
|
const TenantBillingDetail = sequelize.define('TenantBillingDetail', {
|
|
|
|
|
id: {
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
primaryKey: true,
|
|
|
|
|
autoIncrement: true,
|
2026-06-11 13:45:33 +00:00
|
|
|
comment: 'ID'
|
2026-04-20 06:43:09 +00:00
|
|
|
},
|
|
|
|
|
tenantId: {
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
allowNull: false,
|
2026-06-11 13:45:33 +00:00
|
|
|
comment: 'Tenant ID'
|
2026-04-20 06:43:09 +00:00
|
|
|
},
|
2026-06-11 13:45:33 +00:00
|
|
|
billingPeriod: {
|
|
|
|
|
type: DataTypes.STRING(7),
|
2026-04-20 06:43:09 +00:00
|
|
|
allowNull: false,
|
2026-06-11 13:45:33 +00:00
|
|
|
comment: 'Billing period, format YYYY-MM'
|
2026-04-20 06:43:09 +00:00
|
|
|
},
|
2026-06-11 13:45:33 +00:00
|
|
|
planId: {
|
2026-04-20 06:43:09 +00:00
|
|
|
type: DataTypes.INTEGER,
|
2026-06-11 13:45:33 +00:00
|
|
|
allowNull: true,
|
|
|
|
|
comment: 'Subscription plan ID'
|
2026-04-20 06:43:09 +00:00
|
|
|
},
|
2026-06-11 13:45:33 +00:00
|
|
|
baseAmount: {
|
2026-04-20 06:43:09 +00:00
|
|
|
type: DataTypes.DECIMAL(10, 2),
|
2026-06-11 13:45:33 +00:00
|
|
|
allowNull: false,
|
2026-04-20 06:43:09 +00:00
|
|
|
defaultValue: 0,
|
2026-06-11 13:45:33 +00:00
|
|
|
comment: 'Base subscription amount'
|
2026-04-20 06:43:09 +00:00
|
|
|
},
|
2026-06-11 13:45:33 +00:00
|
|
|
extraAmount: {
|
2026-04-20 06:43:09 +00:00
|
|
|
type: DataTypes.DECIMAL(10, 2),
|
2026-06-11 13:45:33 +00:00
|
|
|
allowNull: false,
|
2026-04-20 06:43:09 +00:00
|
|
|
defaultValue: 0,
|
2026-06-11 13:45:33 +00:00
|
|
|
comment: 'Overage amount'
|
2026-04-20 06:43:09 +00:00
|
|
|
},
|
2026-06-11 13:45:33 +00:00
|
|
|
discountAmount: {
|
2026-04-20 06:43:09 +00:00
|
|
|
type: DataTypes.DECIMAL(10, 2),
|
2026-06-11 13:45:33 +00:00
|
|
|
allowNull: false,
|
2026-04-20 06:43:09 +00:00
|
|
|
defaultValue: 0,
|
2026-06-11 13:45:33 +00:00
|
|
|
comment: 'Discount amount'
|
2026-04-20 06:43:09 +00:00
|
|
|
},
|
|
|
|
|
totalAmount: {
|
|
|
|
|
type: DataTypes.DECIMAL(10, 2),
|
2026-06-11 13:45:33 +00:00
|
|
|
allowNull: false,
|
2026-04-20 06:43:09 +00:00
|
|
|
defaultValue: 0,
|
2026-06-11 13:45:33 +00:00
|
|
|
comment: 'Total amount'
|
2026-04-20 06:43:09 +00:00
|
|
|
},
|
|
|
|
|
status: {
|
2026-06-11 13:45:33 +00:00
|
|
|
type: DataTypes.ENUM('pending', 'paid', 'overdue'),
|
|
|
|
|
allowNull: false,
|
|
|
|
|
defaultValue: 'pending',
|
|
|
|
|
comment: 'Billing detail status'
|
2026-04-20 06:43:09 +00:00
|
|
|
},
|
2026-06-11 13:45:33 +00:00
|
|
|
paidTime: {
|
|
|
|
|
type: DataTypes.DATE,
|
2026-04-20 06:43:09 +00:00
|
|
|
allowNull: true,
|
2026-06-11 13:45:33 +00:00
|
|
|
comment: 'Paid time'
|
|
|
|
|
},
|
|
|
|
|
createTime: {
|
|
|
|
|
type: DataTypes.DATE,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
defaultValue: DataTypes.NOW,
|
|
|
|
|
comment: 'Created time'
|
|
|
|
|
},
|
|
|
|
|
updateTime: {
|
|
|
|
|
type: DataTypes.DATE,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
defaultValue: DataTypes.NOW,
|
|
|
|
|
comment: 'Updated time'
|
2026-04-20 06:43:09 +00:00
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
tableName: 'tenant_billing_details',
|
|
|
|
|
timestamps: false,
|
|
|
|
|
indexes: [
|
2026-06-11 13:45:33 +00:00
|
|
|
{ name: 'idx_tenant_period', unique: true, fields: ['tenantId', 'billingPeriod'] },
|
|
|
|
|
{ name: 'idx_tenant', fields: ['tenantId'] },
|
2026-04-20 06:43:09 +00:00
|
|
|
{ name: 'idx_status', fields: ['status'] }
|
|
|
|
|
],
|
2026-06-11 13:45:33 +00:00
|
|
|
comment: 'Tenant billing detail table'
|
2026-04-20 06:43:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = TenantBillingDetail;
|