113 lines
3.9 KiB
JavaScript
113 lines
3.9 KiB
JavaScript
module.exports = (sequelize, DataTypes) => {
|
|
const SubmissionProduct = sequelize.define("submission_products", {
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
autoIncrement: true,
|
|
primaryKey: true,
|
|
},
|
|
submission_id: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
},
|
|
product_id: DataTypes.INTEGER,
|
|
unit_id: DataTypes.INTEGER,
|
|
annual_installed_capacity: DataTypes.STRING(100),
|
|
|
|
// --- Previous Periods ---
|
|
previous_quantity_period_one: { type: DataTypes.STRING(100), allowNull: true },
|
|
previous_quantity_period_two: { type: DataTypes.STRING(100), allowNull: true },
|
|
previous_quantity_period_three: { type: DataTypes.STRING(100), allowNull: true },
|
|
|
|
previous_cost_period_one: { type: DataTypes.STRING(100), allowNull: true },
|
|
previous_cost_period_two: { type: DataTypes.STRING(100), allowNull: true },
|
|
previous_cost_period_three: { type: DataTypes.STRING(100), allowNull: true },
|
|
|
|
// --- Current Periods ---
|
|
current_quantity_period_one: { type: DataTypes.STRING(100), allowNull: true },
|
|
current_quantity_period_two: { type: DataTypes.STRING(100), allowNull: true },
|
|
current_quantity_period_three: { type: DataTypes.STRING(100), allowNull: true },
|
|
|
|
current_cost_period_one: { type: DataTypes.STRING(100), allowNull: true },
|
|
current_cost_period_two: { type: DataTypes.STRING(100), allowNull: true },
|
|
current_cost_period_three: { type: DataTypes.STRING(100), allowNull: true },
|
|
|
|
// --- Forecast Periods ---
|
|
forecast_quantity_period_one: { type: DataTypes.STRING(100), allowNull: true },
|
|
forecast_quantity_period_two: { type: DataTypes.STRING(100), allowNull: true },
|
|
forecast_quantity_period_three: { type: DataTypes.STRING(100), allowNull: true },
|
|
|
|
forecast_cost_period_one: { type: DataTypes.STRING(100), allowNull: true },
|
|
forecast_cost_period_two: { type: DataTypes.STRING(100), allowNull: true },
|
|
forecast_cost_period_three: { type: DataTypes.STRING(100), allowNull: true },
|
|
|
|
previous_quantity: DataTypes.STRING(100),
|
|
previous_cost: DataTypes.STRING(100),
|
|
current_quantity: DataTypes.STRING(100),
|
|
current_cost: DataTypes.STRING(100),
|
|
forecast_quantity: DataTypes.STRING(100),
|
|
forecast_cost: DataTypes.STRING(100),
|
|
variation_reason_master_id: DataTypes.INTEGER,
|
|
other_variation_reason: DataTypes.STRING(255),
|
|
zero_target_reason_master_id: DataTypes.INTEGER,
|
|
other_zero_target_reason: DataTypes.STRING(255),
|
|
remarks: DataTypes.STRING(255),
|
|
created_by: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
},
|
|
updated_by: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
},
|
|
is_active: {
|
|
type: DataTypes.BOOLEAN,
|
|
defaultValue: true,
|
|
},
|
|
created_at: {
|
|
type: DataTypes.DATE,
|
|
defaultValue: DataTypes.NOW,
|
|
},
|
|
updated_at: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true,
|
|
},
|
|
}, {
|
|
tableName: "submission_products",
|
|
timestamps: false,
|
|
});
|
|
|
|
|
|
|
|
SubmissionProduct.associate = (models) => {
|
|
|
|
SubmissionProduct.belongsTo(models.Submission, {
|
|
foreignKey: "submission_id",
|
|
as: "submission",
|
|
});
|
|
|
|
SubmissionProduct.belongsTo(models.Product, {
|
|
foreignKey: "product_id",
|
|
as: "product",
|
|
});
|
|
|
|
SubmissionProduct.belongsTo(models.UnitMaster, {
|
|
foreignKey: "unit_id",
|
|
as: "unit",
|
|
});
|
|
|
|
SubmissionProduct.belongsTo(models.VariationReasonMaster, {
|
|
foreignKey: "variation_reason_master_id",
|
|
as: "variation_reason",
|
|
});
|
|
|
|
SubmissionProduct.belongsTo(models.ZeroTargetReasonMaster, {
|
|
foreignKey: "zero_target_reason_master_id",
|
|
as: "zero_target_reason",
|
|
});
|
|
|
|
|
|
};
|
|
|
|
return SubmissionProduct;
|
|
};
|
|
|