38630-vm/backend/src/db/models/quote_items.js
2026-02-19 23:45:10 +00:00

176 lines
2.0 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 quote_items = sequelize.define(
'quote_items',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
item_description_ar: {
type: DataTypes.TEXT,
},
quantity: {
type: DataTypes.DECIMAL,
},
unit: {
type: DataTypes.ENUM,
values: [
"sqm",
"piece",
"ml",
"set",
"job"
],
},
unit_price: {
type: DataTypes.DECIMAL,
},
discount_amount: {
type: DataTypes.DECIMAL,
},
tax_amount: {
type: DataTypes.DECIMAL,
},
line_total: {
type: DataTypes.DECIMAL,
},
sort_order: {
type: DataTypes.INTEGER,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
quote_items.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.quote_items.belongsTo(db.lead_requests, {
as: 'lead_request',
foreignKey: {
name: 'lead_requestId',
},
constraints: false,
});
db.quote_items.belongsTo(db.stone_variants, {
as: 'stone_variant',
foreignKey: {
name: 'stone_variantId',
},
constraints: false,
});
db.quote_items.belongsTo(db.users, {
as: 'createdBy',
});
db.quote_items.belongsTo(db.users, {
as: 'updatedBy',
});
};
return quote_items;
};