252 lines
3.3 KiB
JavaScript
252 lines
3.3 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 vendor_contracts = sequelize.define(
|
|
'vendor_contracts',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"draft",
|
|
|
|
|
|
"sent",
|
|
|
|
|
|
"signed",
|
|
|
|
|
|
"active",
|
|
|
|
|
|
"completed",
|
|
|
|
|
|
"cancelled"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
start_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
end_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
amount_planned: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
amount_actual: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
deposit_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
deposit_due_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
final_payment_due_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
payment_status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"unpaid",
|
|
|
|
|
|
"partial",
|
|
|
|
|
|
"paid",
|
|
|
|
|
|
"refunded"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
scope_of_work: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
vendor_contracts.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.vendor_contracts.hasMany(db.schedule_items, {
|
|
as: 'schedule_items_vendor_contract',
|
|
foreignKey: {
|
|
name: 'vendor_contractId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.vendor_contracts.hasMany(db.budget_items, {
|
|
as: 'budget_items_vendor_contract',
|
|
foreignKey: {
|
|
name: 'vendor_contractId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.vendor_contracts.hasMany(db.payments, {
|
|
as: 'payments_vendor_contract',
|
|
foreignKey: {
|
|
name: 'vendor_contractId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.vendor_contracts.belongsTo(db.events, {
|
|
as: 'event',
|
|
foreignKey: {
|
|
name: 'eventId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.vendor_contracts.belongsTo(db.vendors, {
|
|
as: 'vendor',
|
|
foreignKey: {
|
|
name: 'vendorId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.vendor_contracts.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.vendor_contracts.hasMany(db.file, {
|
|
as: 'contract_files',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.vendor_contracts.getTableName(),
|
|
belongsToColumn: 'contract_files',
|
|
},
|
|
});
|
|
|
|
|
|
db.vendor_contracts.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.vendor_contracts.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return vendor_contracts;
|
|
};
|
|
|
|
|