579 lines
11 KiB
JavaScript
579 lines
11 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const HumanResources = db.human_resources;
|
|
|
|
const Inventory = db.inventory;
|
|
|
|
const Machinery = db.machinery;
|
|
|
|
const Phones = db.phones;
|
|
|
|
const QualityControl = db.quality_control;
|
|
|
|
const RawMaterials = db.raw_materials;
|
|
|
|
const Sales = db.sales;
|
|
|
|
const Suppliers = db.suppliers;
|
|
|
|
const WorkOrders = db.work_orders;
|
|
|
|
const HumanResourcesData = [
|
|
{
|
|
employee_name: 'John Doe',
|
|
|
|
role: 'Production Manager',
|
|
|
|
payroll: 75000,
|
|
},
|
|
|
|
{
|
|
employee_name: 'Jane Smith',
|
|
|
|
role: 'Inventory Controller',
|
|
|
|
payroll: 65000,
|
|
},
|
|
|
|
{
|
|
employee_name: 'Alice Brown',
|
|
|
|
role: 'Quality Inspector',
|
|
|
|
payroll: 60000,
|
|
},
|
|
|
|
{
|
|
employee_name: 'Bob White',
|
|
|
|
role: 'Sales Representative',
|
|
|
|
payroll: 55000,
|
|
},
|
|
];
|
|
|
|
const InventoryData = [
|
|
{
|
|
product_name: 'Smartphone Model A',
|
|
|
|
quantity: 150,
|
|
|
|
price: 299.99,
|
|
},
|
|
|
|
{
|
|
product_name: 'Smartphone Model B',
|
|
|
|
quantity: 200,
|
|
|
|
price: 399.99,
|
|
},
|
|
|
|
{
|
|
product_name: 'Smartphone Model C',
|
|
|
|
quantity: 100,
|
|
|
|
price: 499.99,
|
|
},
|
|
|
|
{
|
|
product_name: 'Smartphone Model D',
|
|
|
|
quantity: 250,
|
|
|
|
price: 199.99,
|
|
},
|
|
];
|
|
|
|
const MachineryData = [
|
|
{
|
|
machine_name: 'CNC Machine',
|
|
|
|
maintenance_schedule: new Date('2023-11-15T10:00:00Z'),
|
|
|
|
status: 'Operational',
|
|
},
|
|
|
|
{
|
|
machine_name: 'Injection Molder',
|
|
|
|
maintenance_schedule: new Date('2023-11-20T14:00:00Z'),
|
|
|
|
status: 'Under Maintenance',
|
|
},
|
|
|
|
{
|
|
machine_name: 'Glass Cutter',
|
|
|
|
maintenance_schedule: new Date('2023-11-25T09:00:00Z'),
|
|
|
|
status: 'Operational',
|
|
},
|
|
|
|
{
|
|
machine_name: 'Wire Extruder',
|
|
|
|
maintenance_schedule: new Date('2023-11-30T11:00:00Z'),
|
|
|
|
status: 'Operational',
|
|
},
|
|
];
|
|
|
|
const PhonesData = [
|
|
{
|
|
imei: '123456789012345',
|
|
|
|
model: 'Model X',
|
|
|
|
price: 699.99,
|
|
|
|
memory: '128GB',
|
|
|
|
color: 'Black',
|
|
|
|
box_condition: 'New',
|
|
|
|
battery_health: '100%',
|
|
},
|
|
|
|
{
|
|
imei: '234567890123456',
|
|
|
|
model: 'Model Y',
|
|
|
|
price: 799.99,
|
|
|
|
memory: '256GB',
|
|
|
|
color: 'White',
|
|
|
|
box_condition: 'New',
|
|
|
|
battery_health: '100%',
|
|
},
|
|
|
|
{
|
|
imei: '345678901234567',
|
|
|
|
model: 'Model Z',
|
|
|
|
price: 899.99,
|
|
|
|
memory: '512GB',
|
|
|
|
color: 'Blue',
|
|
|
|
box_condition: 'New',
|
|
|
|
battery_health: '100%',
|
|
},
|
|
|
|
{
|
|
imei: '456789012345678',
|
|
|
|
model: 'Model A',
|
|
|
|
price: 499.99,
|
|
|
|
memory: '64GB',
|
|
|
|
color: 'Red',
|
|
|
|
box_condition: 'New',
|
|
|
|
battery_health: '100%',
|
|
},
|
|
];
|
|
|
|
const QualityControlData = [
|
|
{
|
|
check_point: 'Initial Inspection',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
passed: true,
|
|
},
|
|
|
|
{
|
|
check_point: 'Mid-Production Check',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
passed: false,
|
|
},
|
|
|
|
{
|
|
check_point: 'Final Inspection',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
passed: true,
|
|
},
|
|
|
|
{
|
|
check_point: 'Random Sampling',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
passed: true,
|
|
},
|
|
];
|
|
|
|
const RawMaterialsData = [
|
|
{
|
|
name: 'Steel Sheets',
|
|
|
|
quantity: 5000,
|
|
|
|
reorder_level: 1000,
|
|
},
|
|
|
|
{
|
|
name: 'Aluminum Rods',
|
|
|
|
quantity: 3000,
|
|
|
|
reorder_level: 500,
|
|
},
|
|
|
|
{
|
|
name: 'Copper Wires',
|
|
|
|
quantity: 2000,
|
|
|
|
reorder_level: 300,
|
|
},
|
|
|
|
{
|
|
name: 'Plastic Pellets',
|
|
|
|
quantity: 10000,
|
|
|
|
reorder_level: 2000,
|
|
},
|
|
];
|
|
|
|
const SalesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
sale_date: new Date('2023-11-01T10:00:00Z'),
|
|
|
|
total_price: 699.99,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
sale_date: new Date('2023-11-02T11:00:00Z'),
|
|
|
|
total_price: 799.99,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
sale_date: new Date('2023-11-03T12:00:00Z'),
|
|
|
|
total_price: 899.99,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
sale_date: new Date('2023-11-04T13:00:00Z'),
|
|
|
|
total_price: 499.99,
|
|
},
|
|
];
|
|
|
|
const SuppliersData = [
|
|
{
|
|
supplier_name: 'Global Metals Inc.',
|
|
|
|
contract_terms: 'Annual',
|
|
|
|
delivery_schedule: new Date('2023-12-01T08:00:00Z'),
|
|
},
|
|
|
|
{
|
|
supplier_name: 'Plastics Co.',
|
|
|
|
contract_terms: 'Quarterly',
|
|
|
|
delivery_schedule: new Date('2023-12-10T08:00:00Z'),
|
|
},
|
|
|
|
{
|
|
supplier_name: 'Glassworks Ltd.',
|
|
|
|
contract_terms: 'Monthly',
|
|
|
|
delivery_schedule: new Date('2023-12-15T08:00:00Z'),
|
|
},
|
|
|
|
{
|
|
supplier_name: 'Wire Solutions',
|
|
|
|
contract_terms: 'Bi-Annual',
|
|
|
|
delivery_schedule: new Date('2023-12-20T08:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const WorkOrdersData = [
|
|
{
|
|
order_number: 'WO-001',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
order_number: 'WO-002',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
order_number: 'WO-003',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
order_number: 'WO-004',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateQualityControlWithWork_order() {
|
|
const relatedWork_order0 = await WorkOrders.findOne({
|
|
offset: Math.floor(Math.random() * (await WorkOrders.count())),
|
|
});
|
|
const QualityControl0 = await QualityControl.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (QualityControl0?.setWork_order) {
|
|
await QualityControl0.setWork_order(relatedWork_order0);
|
|
}
|
|
|
|
const relatedWork_order1 = await WorkOrders.findOne({
|
|
offset: Math.floor(Math.random() * (await WorkOrders.count())),
|
|
});
|
|
const QualityControl1 = await QualityControl.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (QualityControl1?.setWork_order) {
|
|
await QualityControl1.setWork_order(relatedWork_order1);
|
|
}
|
|
|
|
const relatedWork_order2 = await WorkOrders.findOne({
|
|
offset: Math.floor(Math.random() * (await WorkOrders.count())),
|
|
});
|
|
const QualityControl2 = await QualityControl.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (QualityControl2?.setWork_order) {
|
|
await QualityControl2.setWork_order(relatedWork_order2);
|
|
}
|
|
|
|
const relatedWork_order3 = await WorkOrders.findOne({
|
|
offset: Math.floor(Math.random() * (await WorkOrders.count())),
|
|
});
|
|
const QualityControl3 = await QualityControl.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (QualityControl3?.setWork_order) {
|
|
await QualityControl3.setWork_order(relatedWork_order3);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithPhone() {
|
|
const relatedPhone0 = await Phones.findOne({
|
|
offset: Math.floor(Math.random() * (await Phones.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setPhone) {
|
|
await Sale0.setPhone(relatedPhone0);
|
|
}
|
|
|
|
const relatedPhone1 = await Phones.findOne({
|
|
offset: Math.floor(Math.random() * (await Phones.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setPhone) {
|
|
await Sale1.setPhone(relatedPhone1);
|
|
}
|
|
|
|
const relatedPhone2 = await Phones.findOne({
|
|
offset: Math.floor(Math.random() * (await Phones.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setPhone) {
|
|
await Sale2.setPhone(relatedPhone2);
|
|
}
|
|
|
|
const relatedPhone3 = await Phones.findOne({
|
|
offset: Math.floor(Math.random() * (await Phones.count())),
|
|
});
|
|
const Sale3 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Sale3?.setPhone) {
|
|
await Sale3.setPhone(relatedPhone3);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithSales_person() {
|
|
const relatedSales_person0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setSales_person) {
|
|
await Sale0.setSales_person(relatedSales_person0);
|
|
}
|
|
|
|
const relatedSales_person1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setSales_person) {
|
|
await Sale1.setSales_person(relatedSales_person1);
|
|
}
|
|
|
|
const relatedSales_person2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setSales_person) {
|
|
await Sale2.setSales_person(relatedSales_person2);
|
|
}
|
|
|
|
const relatedSales_person3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Sale3 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Sale3?.setSales_person) {
|
|
await Sale3.setSales_person(relatedSales_person3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await HumanResources.bulkCreate(HumanResourcesData);
|
|
|
|
await Inventory.bulkCreate(InventoryData);
|
|
|
|
await Machinery.bulkCreate(MachineryData);
|
|
|
|
await Phones.bulkCreate(PhonesData);
|
|
|
|
await QualityControl.bulkCreate(QualityControlData);
|
|
|
|
await RawMaterials.bulkCreate(RawMaterialsData);
|
|
|
|
await Sales.bulkCreate(SalesData);
|
|
|
|
await Suppliers.bulkCreate(SuppliersData);
|
|
|
|
await WorkOrders.bulkCreate(WorkOrdersData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateQualityControlWithWork_order(),
|
|
|
|
await associateSaleWithPhone(),
|
|
|
|
await associateSaleWithSales_person(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('human_resources', null, {});
|
|
|
|
await queryInterface.bulkDelete('inventory', null, {});
|
|
|
|
await queryInterface.bulkDelete('machinery', null, {});
|
|
|
|
await queryInterface.bulkDelete('phones', null, {});
|
|
|
|
await queryInterface.bulkDelete('quality_control', null, {});
|
|
|
|
await queryInterface.bulkDelete('raw_materials', null, {});
|
|
|
|
await queryInterface.bulkDelete('sales', null, {});
|
|
|
|
await queryInterface.bulkDelete('suppliers', null, {});
|
|
|
|
await queryInterface.bulkDelete('work_orders', null, {});
|
|
},
|
|
};
|