





















const db = require('../models');
const Users = db.users;






const Customers = db.customers;

const Vehicles = db.vehicles;

const PayTypes = db.pay_types;

const EmployeePayTypes = db.employee_pay_types;

const ChemicalProducts = db.chemical_products;

const JobLogs = db.job_logs;

const JobChemicalUsages = db.job_chemical_usages;

const PayrollRuns = db.payroll_runs;

const PayrollLineItems = db.payroll_line_items;







const CustomersData = [
    
    {
    
        
        
            
                "name": "Ada Lovelace",
            
        
    
        
        
            
                "contact_name": "Ada Lovelace",
            
        
    
        
        
            
                "phone": "Alan Turing",
            
        
    
        
        
            
                "email": "Grace Hopper",
            
        
    
        
        
            
                "address_line1": "Marie Curie",
            
        
    
        
        
            
                "address_line2": "Marie Curie",
            
        
    
        
        
            
                "city": "Grace Hopper",
            
        
    
        
        
            
                "state": "Ada Lovelace",
            
        
    
        
        
            
                "postal_code": "Marie Curie",
            
        
    
        
        
            
                "notes": "Alan Turing",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Ada Lovelace",
            
        
    
        
        
            
                "contact_name": "Grace Hopper",
            
        
    
        
        
            
                "phone": "Grace Hopper",
            
        
    
        
        
            
                "email": "Alan Turing",
            
        
    
        
        
            
                "address_line1": "Ada Lovelace",
            
        
    
        
        
            
                "address_line2": "Grace Hopper",
            
        
    
        
        
            
                "city": "Grace Hopper",
            
        
    
        
        
            
                "state": "Ada Lovelace",
            
        
    
        
        
            
                "postal_code": "Alan Turing",
            
        
    
        
        
            
                "notes": "Grace Hopper",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Ada Lovelace",
            
        
    
        
        
            
                "contact_name": "Alan Turing",
            
        
    
        
        
            
                "phone": "Alan Turing",
            
        
    
        
        
            
                "email": "Marie Curie",
            
        
    
        
        
            
                "address_line1": "Ada Lovelace",
            
        
    
        
        
            
                "address_line2": "Grace Hopper",
            
        
    
        
        
            
                "city": "Alan Turing",
            
        
    
        
        
            
                "state": "Alan Turing",
            
        
    
        
        
            
                "postal_code": "Grace Hopper",
            
        
    
        
        
            
                "notes": "Ada Lovelace",
            
        
    
    },
    
];



const VehiclesData = [
    
    {
    
        
        
            
                "name": "Ada Lovelace",
            
        
    
        
        
            
                "vehicle_number": "Grace Hopper",
            
        
    
        
        
            
                "license_plate": "Ada Lovelace",
            
        
    
        
        
            
                "vin": "Grace Hopper",
            
        
    
        
        
            
                "active": false,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Marie Curie",
            
        
    
        
        
            
                "vehicle_number": "Alan Turing",
            
        
    
        
        
            
                "license_plate": "Alan Turing",
            
        
    
        
        
            
                "vin": "Alan Turing",
            
        
    
        
        
            
                "active": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Alan Turing",
            
        
    
        
        
            
                "vehicle_number": "Alan Turing",
            
        
    
        
        
            
                "license_plate": "Grace Hopper",
            
        
    
        
        
            
                "vin": "Alan Turing",
            
        
    
        
        
            
                "active": false,
            
        
    
    },
    
];



const PayTypesData = [
    
    {
    
        
        
            
                "name": "Ada Lovelace",
            
        
    
        
        
            
                "pay_method": "hourly",
            
        
    
        
        
            
                "hourly_rate": 4.7,
            
        
    
        
        
            
                "commission_rate": 1.55,
            
        
    
        
        
            
                "active": true,
            
        
    
        
        
            
                "description": "Alan Turing",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Marie Curie",
            
        
    
        
        
            
                "pay_method": "hourly",
            
        
    
        
        
            
                "hourly_rate": 7.14,
            
        
    
        
        
            
                "commission_rate": 9.85,
            
        
    
        
        
            
                "active": false,
            
        
    
        
        
            
                "description": "Marie Curie",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Alan Turing",
            
        
    
        
        
            
                "pay_method": "hourly",
            
        
    
        
        
            
                "hourly_rate": 1.9,
            
        
    
        
        
            
                "commission_rate": 0.07,
            
        
    
        
        
            
                "active": true,
            
        
    
        
        
            
                "description": "Marie Curie",
            
        
    
    },
    
];



const EmployeePayTypesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "active": true,
            
        
    
        
        
            
                "effective_start": new Date(Date.now()),
            
        
    
        
        
            
                "effective_end": new Date(Date.now()),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "active": true,
            
        
    
        
        
            
                "effective_start": new Date(Date.now()),
            
        
    
        
        
            
                "effective_end": new Date(Date.now()),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "active": false,
            
        
    
        
        
            
                "effective_start": new Date(Date.now()),
            
        
    
        
        
            
                "effective_end": new Date(Date.now()),
            
        
    
    },
    
];



const ChemicalProductsData = [
    
    {
    
        
        
            
                "name": "Ada Lovelace",
            
        
    
        
        
            
                "unit": "Marie Curie",
            
        
    
        
        
            
                "active": false,
            
        
    
        
        
            
                "notes": "Marie Curie",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Ada Lovelace",
            
        
    
        
        
            
                "unit": "Ada Lovelace",
            
        
    
        
        
            
                "active": true,
            
        
    
        
        
            
                "notes": "Alan Turing",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Ada Lovelace",
            
        
    
        
        
            
                "unit": "Marie Curie",
            
        
    
        
        
            
                "active": false,
            
        
    
        
        
            
                "notes": "Marie Curie",
            
        
    
    },
    
];



const JobLogsData = [
    
    {
    
        
        
            
                "work_date": new Date(Date.now()),
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "hours_conducted": 6.05,
            
        
    
        
        
            
                "client_paid": 4.35,
            
        
    
        
        
            
                "workers_comp_class": "ground",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "odometer_start": 7,
            
        
    
        
        
            
                "odometer_end": 3,
            
        
    
        
        
            
                "job_address": "Marie Curie",
            
        
    
        
        
            
                "status": "approved",
            
        
    
        
        
            
                "notes_to_admin": "Grace Hopper",
            
        
    
    },
    
    {
    
        
        
            
                "work_date": new Date(Date.now()),
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "hours_conducted": 5.37,
            
        
    
        
        
            
                "client_paid": 6.48,
            
        
    
        
        
            
                "workers_comp_class": "ladder",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "odometer_start": 6,
            
        
    
        
        
            
                "odometer_end": 6,
            
        
    
        
        
            
                "job_address": "Alan Turing",
            
        
    
        
        
            
                "status": "needs_correction",
            
        
    
        
        
            
                "notes_to_admin": "Alan Turing",
            
        
    
    },
    
    {
    
        
        
            
                "work_date": new Date(Date.now()),
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "hours_conducted": 2.84,
            
        
    
        
        
            
                "client_paid": 2.49,
            
        
    
        
        
            
                "workers_comp_class": "ground",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "odometer_start": 7,
            
        
    
        
        
            
                "odometer_end": 1,
            
        
    
        
        
            
                "job_address": "Grace Hopper",
            
        
    
        
        
            
                "status": "approved",
            
        
    
        
        
            
                "notes_to_admin": "Alan Turing",
            
        
    
    },
    
];



const JobChemicalUsagesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "quantity_used": 2.31,
            
        
    
        
        
            
                "notes": "Ada Lovelace",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "quantity_used": 1.65,
            
        
    
        
        
            
                "notes": "Alan Turing",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "quantity_used": 6.77,
            
        
    
        
        
            
                "notes": "Grace Hopper",
            
        
    
    },
    
];



const PayrollRunsData = [
    
    {
    
        
        
            
                "name": "Alan Turing",
            
        
    
        
        
            
                "period_start": new Date(Date.now()),
            
        
    
        
        
            
                "period_end": new Date(Date.now()),
            
        
    
        
        
            
                "run_date": new Date(Date.now()),
            
        
    
        
        
            
                "status": "finalized",
            
        
    
        
        
            
                "notes": "Grace Hopper",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Grace Hopper",
            
        
    
        
        
            
                "period_start": new Date(Date.now()),
            
        
    
        
        
            
                "period_end": new Date(Date.now()),
            
        
    
        
        
            
                "run_date": new Date(Date.now()),
            
        
    
        
        
            
                "status": "exported",
            
        
    
        
        
            
                "notes": "Marie Curie",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Ada Lovelace",
            
        
    
        
        
            
                "period_start": new Date(Date.now()),
            
        
    
        
        
            
                "period_end": new Date(Date.now()),
            
        
    
        
        
            
                "run_date": new Date(Date.now()),
            
        
    
        
        
            
                "status": "finalized",
            
        
    
        
        
            
                "notes": "Ada Lovelace",
            
        
    
    },
    
];



const PayrollLineItemsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "total_hours": 7.01,
            
        
    
        
        
            
                "gross_pay": 5.59,
            
        
    
        
        
            
                "total_commission_base": 6.85,
            
        
    
        
        
            
                "total_client_paid": 6.78,
            
        
    
        
        
            
                "summary": "Ada Lovelace",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "total_hours": 9.8,
            
        
    
        
        
            
                "gross_pay": 0.63,
            
        
    
        
        
            
                "total_commission_base": 7.24,
            
        
    
        
        
            
                "total_client_paid": 8.44,
            
        
    
        
        
            
                "summary": "Alan Turing",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "total_hours": 4.42,
            
        
    
        
        
            
                "gross_pay": 1.61,
            
        
    
        
        
            
                "total_commission_base": 9.35,
            
        
    
        
        
            
                "total_client_paid": 1.46,
            
        
    
        
        
            
                "summary": "Ada Lovelace",
            
        
    
    },
    
];




    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            // Similar logic for "relation_many"
        
    

    
    
    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateEmployeePayTypeWithEmployee() {
            
                const relatedEmployee0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const EmployeePayType0 = await EmployeePayTypes.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (EmployeePayType0?.setEmployee)
                {
                    await
                    EmployeePayType0.
                    setEmployee(relatedEmployee0);
                }
            
                const relatedEmployee1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const EmployeePayType1 = await EmployeePayTypes.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (EmployeePayType1?.setEmployee)
                {
                    await
                    EmployeePayType1.
                    setEmployee(relatedEmployee1);
                }
            
                const relatedEmployee2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const EmployeePayType2 = await EmployeePayTypes.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (EmployeePayType2?.setEmployee)
                {
                    await
                    EmployeePayType2.
                    setEmployee(relatedEmployee2);
                }
            
        }
        
    
        
            
            async function associateEmployeePayTypeWithPay_type() {
            
                const relatedPay_type0 = await PayTypes.findOne({
                    offset: Math.floor(Math.random() * (await PayTypes.count())),
                });
                const EmployeePayType0 = await EmployeePayTypes.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (EmployeePayType0?.setPay_type)
                {
                    await
                    EmployeePayType0.
                    setPay_type(relatedPay_type0);
                }
            
                const relatedPay_type1 = await PayTypes.findOne({
                    offset: Math.floor(Math.random() * (await PayTypes.count())),
                });
                const EmployeePayType1 = await EmployeePayTypes.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (EmployeePayType1?.setPay_type)
                {
                    await
                    EmployeePayType1.
                    setPay_type(relatedPay_type1);
                }
            
                const relatedPay_type2 = await PayTypes.findOne({
                    offset: Math.floor(Math.random() * (await PayTypes.count())),
                });
                const EmployeePayType2 = await EmployeePayTypes.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (EmployeePayType2?.setPay_type)
                {
                    await
                    EmployeePayType2.
                    setPay_type(relatedPay_type2);
                }
            
        }
        
    
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    
        
    

    
    
    
        
    
        
            
            async function associateJobLogWithEmployee() {
            
                const relatedEmployee0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const JobLog0 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (JobLog0?.setEmployee)
                {
                    await
                    JobLog0.
                    setEmployee(relatedEmployee0);
                }
            
                const relatedEmployee1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const JobLog1 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (JobLog1?.setEmployee)
                {
                    await
                    JobLog1.
                    setEmployee(relatedEmployee1);
                }
            
                const relatedEmployee2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const JobLog2 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (JobLog2?.setEmployee)
                {
                    await
                    JobLog2.
                    setEmployee(relatedEmployee2);
                }
            
        }
        
    
        
            
            async function associateJobLogWithCustomer() {
            
                const relatedCustomer0 = await Customers.findOne({
                    offset: Math.floor(Math.random() * (await Customers.count())),
                });
                const JobLog0 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (JobLog0?.setCustomer)
                {
                    await
                    JobLog0.
                    setCustomer(relatedCustomer0);
                }
            
                const relatedCustomer1 = await Customers.findOne({
                    offset: Math.floor(Math.random() * (await Customers.count())),
                });
                const JobLog1 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (JobLog1?.setCustomer)
                {
                    await
                    JobLog1.
                    setCustomer(relatedCustomer1);
                }
            
                const relatedCustomer2 = await Customers.findOne({
                    offset: Math.floor(Math.random() * (await Customers.count())),
                });
                const JobLog2 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (JobLog2?.setCustomer)
                {
                    await
                    JobLog2.
                    setCustomer(relatedCustomer2);
                }
            
        }
        
    
        
    
        
    
        
    
        
            
            async function associateJobLogWithPay_type() {
            
                const relatedPay_type0 = await PayTypes.findOne({
                    offset: Math.floor(Math.random() * (await PayTypes.count())),
                });
                const JobLog0 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (JobLog0?.setPay_type)
                {
                    await
                    JobLog0.
                    setPay_type(relatedPay_type0);
                }
            
                const relatedPay_type1 = await PayTypes.findOne({
                    offset: Math.floor(Math.random() * (await PayTypes.count())),
                });
                const JobLog1 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (JobLog1?.setPay_type)
                {
                    await
                    JobLog1.
                    setPay_type(relatedPay_type1);
                }
            
                const relatedPay_type2 = await PayTypes.findOne({
                    offset: Math.floor(Math.random() * (await PayTypes.count())),
                });
                const JobLog2 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (JobLog2?.setPay_type)
                {
                    await
                    JobLog2.
                    setPay_type(relatedPay_type2);
                }
            
        }
        
    
        
            
            async function associateJobLogWithVehicle() {
            
                const relatedVehicle0 = await Vehicles.findOne({
                    offset: Math.floor(Math.random() * (await Vehicles.count())),
                });
                const JobLog0 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (JobLog0?.setVehicle)
                {
                    await
                    JobLog0.
                    setVehicle(relatedVehicle0);
                }
            
                const relatedVehicle1 = await Vehicles.findOne({
                    offset: Math.floor(Math.random() * (await Vehicles.count())),
                });
                const JobLog1 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (JobLog1?.setVehicle)
                {
                    await
                    JobLog1.
                    setVehicle(relatedVehicle1);
                }
            
                const relatedVehicle2 = await Vehicles.findOne({
                    offset: Math.floor(Math.random() * (await Vehicles.count())),
                });
                const JobLog2 = await JobLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (JobLog2?.setVehicle)
                {
                    await
                    JobLog2.
                    setVehicle(relatedVehicle2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateJobChemicalUsageWithJob_log() {
            
                const relatedJob_log0 = await JobLogs.findOne({
                    offset: Math.floor(Math.random() * (await JobLogs.count())),
                });
                const JobChemicalUsage0 = await JobChemicalUsages.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (JobChemicalUsage0?.setJob_log)
                {
                    await
                    JobChemicalUsage0.
                    setJob_log(relatedJob_log0);
                }
            
                const relatedJob_log1 = await JobLogs.findOne({
                    offset: Math.floor(Math.random() * (await JobLogs.count())),
                });
                const JobChemicalUsage1 = await JobChemicalUsages.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (JobChemicalUsage1?.setJob_log)
                {
                    await
                    JobChemicalUsage1.
                    setJob_log(relatedJob_log1);
                }
            
                const relatedJob_log2 = await JobLogs.findOne({
                    offset: Math.floor(Math.random() * (await JobLogs.count())),
                });
                const JobChemicalUsage2 = await JobChemicalUsages.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (JobChemicalUsage2?.setJob_log)
                {
                    await
                    JobChemicalUsage2.
                    setJob_log(relatedJob_log2);
                }
            
        }
        
    
        
            
            async function associateJobChemicalUsageWithChemical_product() {
            
                const relatedChemical_product0 = await ChemicalProducts.findOne({
                    offset: Math.floor(Math.random() * (await ChemicalProducts.count())),
                });
                const JobChemicalUsage0 = await JobChemicalUsages.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (JobChemicalUsage0?.setChemical_product)
                {
                    await
                    JobChemicalUsage0.
                    setChemical_product(relatedChemical_product0);
                }
            
                const relatedChemical_product1 = await ChemicalProducts.findOne({
                    offset: Math.floor(Math.random() * (await ChemicalProducts.count())),
                });
                const JobChemicalUsage1 = await JobChemicalUsages.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (JobChemicalUsage1?.setChemical_product)
                {
                    await
                    JobChemicalUsage1.
                    setChemical_product(relatedChemical_product1);
                }
            
                const relatedChemical_product2 = await ChemicalProducts.findOne({
                    offset: Math.floor(Math.random() * (await ChemicalProducts.count())),
                });
                const JobChemicalUsage2 = await JobChemicalUsages.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (JobChemicalUsage2?.setChemical_product)
                {
                    await
                    JobChemicalUsage2.
                    setChemical_product(relatedChemical_product2);
                }
            
        }
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associatePayrollLineItemWithPayroll_run() {
            
                const relatedPayroll_run0 = await PayrollRuns.findOne({
                    offset: Math.floor(Math.random() * (await PayrollRuns.count())),
                });
                const PayrollLineItem0 = await PayrollLineItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (PayrollLineItem0?.setPayroll_run)
                {
                    await
                    PayrollLineItem0.
                    setPayroll_run(relatedPayroll_run0);
                }
            
                const relatedPayroll_run1 = await PayrollRuns.findOne({
                    offset: Math.floor(Math.random() * (await PayrollRuns.count())),
                });
                const PayrollLineItem1 = await PayrollLineItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (PayrollLineItem1?.setPayroll_run)
                {
                    await
                    PayrollLineItem1.
                    setPayroll_run(relatedPayroll_run1);
                }
            
                const relatedPayroll_run2 = await PayrollRuns.findOne({
                    offset: Math.floor(Math.random() * (await PayrollRuns.count())),
                });
                const PayrollLineItem2 = await PayrollLineItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (PayrollLineItem2?.setPayroll_run)
                {
                    await
                    PayrollLineItem2.
                    setPayroll_run(relatedPayroll_run2);
                }
            
        }
        
    
        
            
            async function associatePayrollLineItemWithEmployee() {
            
                const relatedEmployee0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const PayrollLineItem0 = await PayrollLineItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (PayrollLineItem0?.setEmployee)
                {
                    await
                    PayrollLineItem0.
                    setEmployee(relatedEmployee0);
                }
            
                const relatedEmployee1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const PayrollLineItem1 = await PayrollLineItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (PayrollLineItem1?.setEmployee)
                {
                    await
                    PayrollLineItem1.
                    setEmployee(relatedEmployee1);
                }
            
                const relatedEmployee2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const PayrollLineItem2 = await PayrollLineItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (PayrollLineItem2?.setEmployee)
                {
                    await
                    PayrollLineItem2.
                    setEmployee(relatedEmployee2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    


module.exports = {
    up: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
                
                await Customers.bulkCreate(CustomersData);
                
            
            
                
                await Vehicles.bulkCreate(VehiclesData);
                
            
            
                
                await PayTypes.bulkCreate(PayTypesData);
                
            
            
                
                await EmployeePayTypes.bulkCreate(EmployeePayTypesData);
                
            
            
                
                await ChemicalProducts.bulkCreate(ChemicalProductsData);
                
            
            
                
                await JobLogs.bulkCreate(JobLogsData);
                
            
            
                
                await JobChemicalUsages.bulkCreate(JobChemicalUsagesData);
                
            
            
                
                await PayrollRuns.bulkCreate(PayrollRunsData);
                
            
            
                
                await PayrollLineItems.bulkCreate(PayrollLineItemsData);
                
            
            await Promise.all([
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        // Similar logic for "relation_many"
                    
                
            
                
                
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateEmployeePayTypeWithEmployee(),
                    
                
                    
                        
                        await associateEmployeePayTypeWithPay_type(),
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                        
                        await associateJobLogWithEmployee(),
                    
                
                    
                        
                        await associateJobLogWithCustomer(),
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateJobLogWithPay_type(),
                    
                
                    
                        
                        await associateJobLogWithVehicle(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateJobChemicalUsageWithJob_log(),
                    
                
                    
                        
                        await associateJobChemicalUsageWithChemical_product(),
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associatePayrollLineItemWithPayroll_run(),
                    
                
                    
                        
                        await associatePayrollLineItemWithEmployee(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            ]);
        
    },

    down: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
            await queryInterface.bulkDelete('customers', null, {});
            
            
            await queryInterface.bulkDelete('vehicles', null, {});
            
            
            await queryInterface.bulkDelete('pay_types', null, {});
            
            
            await queryInterface.bulkDelete('employee_pay_types', null, {});
            
            
            await queryInterface.bulkDelete('chemical_products', null, {});
            
            
            await queryInterface.bulkDelete('job_logs', null, {});
            
            
            await queryInterface.bulkDelete('job_chemical_usages', null, {});
            
            
            await queryInterface.bulkDelete('payroll_runs', null, {});
            
            
            await queryInterface.bulkDelete('payroll_line_items', null, {});
            
        
    },
};