170 lines
2.2 KiB
JavaScript
170 lines
2.2 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 journal_lines = sequelize.define(
|
|
'journal_lines',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
debit_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
credit_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
journal_lines.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.journal_lines.belongsTo(db.journal_entries, {
|
|
as: 'journal_entry',
|
|
foreignKey: {
|
|
name: 'journal_entryId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.journal_lines.belongsTo(db.gl_accounts, {
|
|
as: 'gl_account',
|
|
foreignKey: {
|
|
name: 'gl_accountId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.journal_lines.belongsTo(db.items, {
|
|
as: 'item',
|
|
foreignKey: {
|
|
name: 'itemId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.journal_lines.belongsTo(db.production_orders, {
|
|
as: 'production_order',
|
|
foreignKey: {
|
|
name: 'production_orderId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.journal_lines.belongsTo(db.suppliers, {
|
|
as: 'supplier',
|
|
foreignKey: {
|
|
name: 'supplierId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.journal_lines.belongsTo(db.customers, {
|
|
as: 'customer',
|
|
foreignKey: {
|
|
name: 'customerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.journal_lines.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.journal_lines.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return journal_lines;
|
|
};
|
|
|
|
|