38852-vm/backend/src/db/models/financial_statements.js
2026-02-28 20:55:43 +00:00

212 lines
2.4 KiB
JavaScript

const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');
module.exports = function(sequelize, DataTypes) {
const financial_statements = sequelize.define(
'financial_statements',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
statement_type: {
type: DataTypes.ENUM,
values: [
"income",
"balance_sheet",
"cash_flow"
],
},
period_type: {
type: DataTypes.ENUM,
values: [
"annual",
"quarterly",
"ttm"
],
},
period_start_at: {
type: DataTypes.DATE,
},
period_end_at: {
type: DataTypes.DATE,
},
reported_at: {
type: DataTypes.DATE,
},
revenue: {
type: DataTypes.DECIMAL,
},
gross_profit: {
type: DataTypes.DECIMAL,
},
operating_income: {
type: DataTypes.DECIMAL,
},
net_income: {
type: DataTypes.DECIMAL,
},
ebitda: {
type: DataTypes.DECIMAL,
},
total_assets: {
type: DataTypes.DECIMAL,
},
total_liabilities: {
type: DataTypes.DECIMAL,
},
total_equity: {
type: DataTypes.DECIMAL,
},
operating_cash_flow: {
type: DataTypes.DECIMAL,
},
free_cash_flow: {
type: DataTypes.DECIMAL,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
financial_statements.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.financial_statements.belongsTo(db.assets, {
as: 'asset',
foreignKey: {
name: 'assetId',
},
constraints: false,
});
db.financial_statements.belongsTo(db.users, {
as: 'createdBy',
});
db.financial_statements.belongsTo(db.users, {
as: 'updatedBy',
});
};
return financial_statements;
};