245 lines
3.5 KiB
JavaScript
245 lines
3.5 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 vat_declarations = sequelize.define(
|
|
'vat_declarations',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"draft",
|
|
|
|
|
|
"generated",
|
|
|
|
|
|
"reviewed",
|
|
|
|
|
|
"submitted",
|
|
|
|
|
|
"accepted",
|
|
|
|
|
|
"rejected",
|
|
|
|
|
|
"amended"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
total_sales_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
taxable_sales_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
output_vat_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
total_purchases_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
input_vat_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
vat_payable_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
generated_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
reviewed_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
vat_declarations.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.vat_declarations.belongsTo(db.merchants, {
|
|
as: 'merchant',
|
|
foreignKey: {
|
|
name: 'merchantId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.vat_declarations.belongsTo(db.tax_periods, {
|
|
as: 'tax_period',
|
|
foreignKey: {
|
|
name: 'tax_periodId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.vat_declarations.belongsTo(db.users, {
|
|
as: 'generated_by',
|
|
foreignKey: {
|
|
name: 'generated_byId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.vat_declarations.belongsTo(db.users, {
|
|
as: 'reviewed_by',
|
|
foreignKey: {
|
|
name: 'reviewed_byId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.vat_declarations.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.vat_declarations.hasMany(db.file, {
|
|
as: 'pdf_file',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.vat_declarations.getTableName(),
|
|
belongsToColumn: 'pdf_file',
|
|
},
|
|
});
|
|
|
|
db.vat_declarations.hasMany(db.file, {
|
|
as: 'excel_file',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.vat_declarations.getTableName(),
|
|
belongsToColumn: 'excel_file',
|
|
},
|
|
});
|
|
|
|
db.vat_declarations.hasMany(db.file, {
|
|
as: 'revenue_office_export_file',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.vat_declarations.getTableName(),
|
|
belongsToColumn: 'revenue_office_export_file',
|
|
},
|
|
});
|
|
|
|
|
|
db.vat_declarations.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.vat_declarations.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return vat_declarations;
|
|
};
|
|
|
|
|