192 lines
2.5 KiB
JavaScript
192 lines
2.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 stay_folios = sequelize.define(
|
|
'stay_folios',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
folio_number: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"open",
|
|
|
|
|
|
"closed",
|
|
|
|
|
|
"void"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
balance_due: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
total_charges: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
total_payments: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
stay_folios.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.stay_folios.hasMany(db.folio_items, {
|
|
as: 'folio_items_stay_folio',
|
|
foreignKey: {
|
|
name: 'stay_folioId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.stay_folios.hasMany(db.payments, {
|
|
as: 'payments_stay_folio',
|
|
foreignKey: {
|
|
name: 'stay_folioId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.stay_folios.hasMany(db.invoices, {
|
|
as: 'invoices_stay_folio',
|
|
foreignKey: {
|
|
name: 'stay_folioId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.stay_folios.belongsTo(db.hotels, {
|
|
as: 'hotel',
|
|
foreignKey: {
|
|
name: 'hotelId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.stay_folios.belongsTo(db.reservations, {
|
|
as: 'reservation',
|
|
foreignKey: {
|
|
name: 'reservationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.stay_folios.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.stay_folios.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.stay_folios.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return stay_folios;
|
|
};
|
|
|
|
|