
const db = require('../models');
const FileDBApi = require('./file');
const crypto = require('crypto');
const Utils = require('../utils');



const Sequelize = db.Sequelize;
const Op = Sequelize.Op;

module.exports = class Payroll_itemsDBApi {
    

    
    static async create(data, options) {
        const currentUser = (options && options.currentUser) || { id: null };
        const transaction = (options && options.transaction) || undefined;

        const payroll_items = await db.payroll_items.create(
            {
                id: data.id || undefined,
        
        workdays: data.workdays
        ||
        null
            ,
            
        sick_days: data.sick_days
        ||
        null
            ,
            
        leave_days: data.leave_days
        ||
        null
            ,
            
        absent_days: data.absent_days
        ||
        null
            ,
            
        late_count: data.late_count
        ||
        null
            ,
            
        late_minutes_total: data.late_minutes_total
        ||
        null
            ,
            
        base_salary_monthly: data.base_salary_monthly
        ||
        null
            ,
            
        daily_rate: data.daily_rate
        ||
        null
            ,
            
        base_salary_total: data.base_salary_total
        ||
        null
            ,
            
        meal_transport_total: data.meal_transport_total
        ||
        null
            ,
            
        position_allowance_total: data.position_allowance_total
        ||
        null
            ,
            
        kpi_score: data.kpi_score
        ||
        null
            ,
            
        kpi_allowance_total: data.kpi_allowance_total
        ||
        null
            ,
            
        overtime_hours_total: data.overtime_hours_total
        ||
        null
            ,
            
        overtime_rate: data.overtime_rate
        ||
        null
            ,
            
        overtime_total: data.overtime_total
        ||
        null
            ,
            
        revenue_bonus_total: data.revenue_bonus_total
        ||
        null
            ,
            
        service_charge_total: data.service_charge_total
        ||
        null
            ,
            
        deduction_total: data.deduction_total
        ||
        null
            ,
            
        take_home_pay: data.take_home_pay
        ||
        null
            ,
            
        status: data.status
        ||
        null
            ,
            
        adjustment_notes: data.adjustment_notes
        ||
        null
            ,
            
            importHash: data.importHash || null,
            createdById: currentUser.id,
            updatedById: currentUser.id,
    },
        { transaction },
    );

        
        await payroll_items.setPayroll_period( data.payroll_period || null, {
            transaction,
        });
        
        await payroll_items.setEmployee( data.employee || null, {
            transaction,
        });
        
        await payroll_items.setOutlet( data.outlet || null, {
            transaction,
        });
        
        await payroll_items.setOrganizations( data.organizations || null, {
            transaction,
        });
        

        

        

        return payroll_items;
    }
    

    static async bulkImport(data, options) {
        const currentUser = (options && options.currentUser) || { id: null };
        const transaction = (options && options.transaction) || undefined;

        // Prepare data - wrapping individual data transformations in a map() method
        const payroll_itemsData = data.map((item, index) => ({
                id: item.id || undefined,
                
                workdays: item.workdays
            ||
            null
            ,
            
                sick_days: item.sick_days
            ||
            null
            ,
            
                leave_days: item.leave_days
            ||
            null
            ,
            
                absent_days: item.absent_days
            ||
            null
            ,
            
                late_count: item.late_count
            ||
            null
            ,
            
                late_minutes_total: item.late_minutes_total
            ||
            null
            ,
            
                base_salary_monthly: item.base_salary_monthly
            ||
            null
            ,
            
                daily_rate: item.daily_rate
            ||
            null
            ,
            
                base_salary_total: item.base_salary_total
            ||
            null
            ,
            
                meal_transport_total: item.meal_transport_total
            ||
            null
            ,
            
                position_allowance_total: item.position_allowance_total
            ||
            null
            ,
            
                kpi_score: item.kpi_score
            ||
            null
            ,
            
                kpi_allowance_total: item.kpi_allowance_total
            ||
            null
            ,
            
                overtime_hours_total: item.overtime_hours_total
            ||
            null
            ,
            
                overtime_rate: item.overtime_rate
            ||
            null
            ,
            
                overtime_total: item.overtime_total
            ||
            null
            ,
            
                revenue_bonus_total: item.revenue_bonus_total
            ||
            null
            ,
            
                service_charge_total: item.service_charge_total
            ||
            null
            ,
            
                deduction_total: item.deduction_total
            ||
            null
            ,
            
                take_home_pay: item.take_home_pay
            ||
            null
            ,
            
                status: item.status
            ||
            null
            ,
            
                adjustment_notes: item.adjustment_notes
            ||
            null
            ,
            
            importHash: item.importHash || null,
            createdById: currentUser.id,
            updatedById: currentUser.id,
            createdAt: new Date(Date.now() + index * 1000),
    }));

        // Bulk create items
        const payroll_items = await db.payroll_items.bulkCreate(payroll_itemsData, { transaction });

        // For each item created, replace relation files
        

        return payroll_items;
    }

    static async update(id, data,  options) {
        const currentUser = (options && options.currentUser) || {id: null};
        const transaction = (options && options.transaction) || undefined;
        const globalAccess = currentUser.app_role?.globalAccess;

        const payroll_items = await db.payroll_items.findByPk(id, {}, {transaction});


        

        const updatePayload = {};
        
        if (data.workdays !== undefined) updatePayload.workdays = data.workdays;
        
        
        if (data.sick_days !== undefined) updatePayload.sick_days = data.sick_days;
        
        
        if (data.leave_days !== undefined) updatePayload.leave_days = data.leave_days;
        
        
        if (data.absent_days !== undefined) updatePayload.absent_days = data.absent_days;
        
        
        if (data.late_count !== undefined) updatePayload.late_count = data.late_count;
        
        
        if (data.late_minutes_total !== undefined) updatePayload.late_minutes_total = data.late_minutes_total;
        
        
        if (data.base_salary_monthly !== undefined) updatePayload.base_salary_monthly = data.base_salary_monthly;
        
        
        if (data.daily_rate !== undefined) updatePayload.daily_rate = data.daily_rate;
        
        
        if (data.base_salary_total !== undefined) updatePayload.base_salary_total = data.base_salary_total;
        
        
        if (data.meal_transport_total !== undefined) updatePayload.meal_transport_total = data.meal_transport_total;
        
        
        if (data.position_allowance_total !== undefined) updatePayload.position_allowance_total = data.position_allowance_total;
        
        
        if (data.kpi_score !== undefined) updatePayload.kpi_score = data.kpi_score;
        
        
        if (data.kpi_allowance_total !== undefined) updatePayload.kpi_allowance_total = data.kpi_allowance_total;
        
        
        if (data.overtime_hours_total !== undefined) updatePayload.overtime_hours_total = data.overtime_hours_total;
        
        
        if (data.overtime_rate !== undefined) updatePayload.overtime_rate = data.overtime_rate;
        
        
        if (data.overtime_total !== undefined) updatePayload.overtime_total = data.overtime_total;
        
        
        if (data.revenue_bonus_total !== undefined) updatePayload.revenue_bonus_total = data.revenue_bonus_total;
        
        
        if (data.service_charge_total !== undefined) updatePayload.service_charge_total = data.service_charge_total;
        
        
        if (data.deduction_total !== undefined) updatePayload.deduction_total = data.deduction_total;
        
        
        if (data.take_home_pay !== undefined) updatePayload.take_home_pay = data.take_home_pay;
        
        
        if (data.status !== undefined) updatePayload.status = data.status;
        
        
        if (data.adjustment_notes !== undefined) updatePayload.adjustment_notes = data.adjustment_notes;
        
        
        updatePayload.updatedById = currentUser.id;

        await payroll_items.update(updatePayload, {transaction});

        
        
        if (data.payroll_period !== undefined) {
            await payroll_items.setPayroll_period(
              
              data.payroll_period,
              
              { transaction }
            );
        }
        
        if (data.employee !== undefined) {
            await payroll_items.setEmployee(
              
              data.employee,
              
              { transaction }
            );
        }
        
        if (data.outlet !== undefined) {
            await payroll_items.setOutlet(
              
              data.outlet,
              
              { transaction }
            );
        }
        
        if (data.organizations !== undefined) {
            await payroll_items.setOrganizations(
              
              data.organizations,
              
              { transaction }
            );
        }
        

        
        

        

        return payroll_items;
    }

    static async deleteByIds(ids, options) {
        const currentUser = (options && options.currentUser) || { id: null };
        const transaction = (options && options.transaction) || undefined;

        const payroll_items = await db.payroll_items.findAll({
            where: {
                id: {
                    [Op.in]: ids,
                },
            },
            transaction,
        });

        await db.sequelize.transaction(async (transaction) => {
            for (const record of payroll_items) {
                await record.update(
                    {deletedBy: currentUser.id},
                    {transaction}
                );
            }
            for (const record of payroll_items) {
                await record.destroy({transaction});
            }
        });


        return payroll_items;
    }

    static async remove(id, options) {
        const currentUser = (options && options.currentUser) || {id: null};
        const transaction = (options && options.transaction) || undefined;

        const payroll_items = await db.payroll_items.findByPk(id, options);

        await payroll_items.update({
            deletedBy: currentUser.id
        }, {
            transaction,
        });

        await payroll_items.destroy({
            transaction
        });

        return payroll_items;
    }

    static async findBy(where, options) {
        const transaction = (options && options.transaction) || undefined;

        const payroll_items = await db.payroll_items.findOne(
            { where },
            { transaction },
        );

        if (!payroll_items) {
            return payroll_items;
        }

        const output = payroll_items.get({plain: true});

        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        output.payroll_adjustments_payroll_item = await payroll_items.getPayroll_adjustments_payroll_item({
            transaction
        });
        
        
        output.payslips_payroll_item = await payroll_items.getPayslips_payroll_item({
            transaction
        });
        
        
        
        
        
        output.payroll_period = await payroll_items.getPayroll_period({
            transaction
        });
        
        
        output.employee = await payroll_items.getEmployee({
            transaction
        });
        
        
        output.outlet = await payroll_items.getOutlet({
            transaction
        });
        
        
        output.organizations = await payroll_items.getOrganizations({
            transaction
        });
        
        

        return output;
    }

    static async findAll(
          filter,
           globalAccess,  options
        ) {
        const limit = filter.limit || 0;
        let offset = 0;
        let where = {};
        const currentPage = +filter.page;

        
        const user = (options && options.currentUser) || null;
        const userOrganizations = (user && user.organizations?.id) || null;
        

        
        if (userOrganizations) {
            if (options?.currentUser?.organizationsId) {
                where.organizationsId = options.currentUser.organizationsId;
            }
        }
        

        offset = currentPage * limit;

        const orderBy = null;

    const transaction = (options && options.transaction) || undefined;

    let include = [

      {
        model: db.payroll_periods,
        as: 'payroll_period',
        
        where: filter.payroll_period ? {
          [Op.or]: [
            { id: { [Op.in]: filter.payroll_period.split('|').map(term => Utils.uuid(term)) } },
            {
              name: {
                [Op.or]: filter.payroll_period.split('|').map(term => ({ [Op.iLike]: `%${term}%` }))
              }
            },
          ]
        } : {},
        
      },

      {
        model: db.employees,
        as: 'employee',
        
        where: filter.employee ? {
          [Op.or]: [
            { id: { [Op.in]: filter.employee.split('|').map(term => Utils.uuid(term)) } },
            {
              full_name: {
                [Op.or]: filter.employee.split('|').map(term => ({ [Op.iLike]: `%${term}%` }))
              }
            },
          ]
        } : {},
        
      },

      {
        model: db.outlets,
        as: 'outlet',
        
        where: filter.outlet ? {
          [Op.or]: [
            { id: { [Op.in]: filter.outlet.split('|').map(term => Utils.uuid(term)) } },
            {
              name: {
                [Op.or]: filter.outlet.split('|').map(term => ({ [Op.iLike]: `%${term}%` }))
              }
            },
          ]
        } : {},
        
      },

      {
        model: db.organizations,
        as: 'organizations',
        
      },



    ];

        if (filter) {
            if (filter.id) {
                where = {
                    ...where,
                    ['id']: Utils.uuid(filter.id),
                };
            }

            
            if (filter.adjustment_notes) {
                where = {
                    ...where,
                    [Op.and]: Utils.ilike(
                        'payroll_items',
                        'adjustment_notes',
                        filter.adjustment_notes,
                    ),
                };
            }
            

            
            

            
            if (filter.workdaysRange) {
                const [start, end] = filter.workdaysRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    workdays: {
                    ...where.workdays,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    workdays: {
                    ...where.workdays,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.sick_daysRange) {
                const [start, end] = filter.sick_daysRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    sick_days: {
                    ...where.sick_days,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    sick_days: {
                    ...where.sick_days,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.leave_daysRange) {
                const [start, end] = filter.leave_daysRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    leave_days: {
                    ...where.leave_days,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    leave_days: {
                    ...where.leave_days,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.absent_daysRange) {
                const [start, end] = filter.absent_daysRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    absent_days: {
                    ...where.absent_days,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    absent_days: {
                    ...where.absent_days,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.late_countRange) {
                const [start, end] = filter.late_countRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    late_count: {
                    ...where.late_count,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    late_count: {
                    ...where.late_count,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.late_minutes_totalRange) {
                const [start, end] = filter.late_minutes_totalRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    late_minutes_total: {
                    ...where.late_minutes_total,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    late_minutes_total: {
                    ...where.late_minutes_total,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.base_salary_monthlyRange) {
                const [start, end] = filter.base_salary_monthlyRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    base_salary_monthly: {
                    ...where.base_salary_monthly,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    base_salary_monthly: {
                    ...where.base_salary_monthly,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.daily_rateRange) {
                const [start, end] = filter.daily_rateRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    daily_rate: {
                    ...where.daily_rate,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    daily_rate: {
                    ...where.daily_rate,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.base_salary_totalRange) {
                const [start, end] = filter.base_salary_totalRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    base_salary_total: {
                    ...where.base_salary_total,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    base_salary_total: {
                    ...where.base_salary_total,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.meal_transport_totalRange) {
                const [start, end] = filter.meal_transport_totalRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    meal_transport_total: {
                    ...where.meal_transport_total,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    meal_transport_total: {
                    ...where.meal_transport_total,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.position_allowance_totalRange) {
                const [start, end] = filter.position_allowance_totalRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    position_allowance_total: {
                    ...where.position_allowance_total,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    position_allowance_total: {
                    ...where.position_allowance_total,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.kpi_scoreRange) {
                const [start, end] = filter.kpi_scoreRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    kpi_score: {
                    ...where.kpi_score,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    kpi_score: {
                    ...where.kpi_score,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.kpi_allowance_totalRange) {
                const [start, end] = filter.kpi_allowance_totalRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    kpi_allowance_total: {
                    ...where.kpi_allowance_total,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    kpi_allowance_total: {
                    ...where.kpi_allowance_total,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.overtime_hours_totalRange) {
                const [start, end] = filter.overtime_hours_totalRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    overtime_hours_total: {
                    ...where.overtime_hours_total,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    overtime_hours_total: {
                    ...where.overtime_hours_total,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.overtime_rateRange) {
                const [start, end] = filter.overtime_rateRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    overtime_rate: {
                    ...where.overtime_rate,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    overtime_rate: {
                    ...where.overtime_rate,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.overtime_totalRange) {
                const [start, end] = filter.overtime_totalRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    overtime_total: {
                    ...where.overtime_total,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    overtime_total: {
                    ...where.overtime_total,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.revenue_bonus_totalRange) {
                const [start, end] = filter.revenue_bonus_totalRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    revenue_bonus_total: {
                    ...where.revenue_bonus_total,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    revenue_bonus_total: {
                    ...where.revenue_bonus_total,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.service_charge_totalRange) {
                const [start, end] = filter.service_charge_totalRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    service_charge_total: {
                    ...where.service_charge_total,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    service_charge_total: {
                    ...where.service_charge_total,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.deduction_totalRange) {
                const [start, end] = filter.deduction_totalRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    deduction_total: {
                    ...where.deduction_total,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    deduction_total: {
                    ...where.deduction_total,
                            [Op.lte]: end,
                    },
                };
                }
            }
            
            if (filter.take_home_payRange) {
                const [start, end] = filter.take_home_payRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                    take_home_pay: {
                    ...where.take_home_pay,
                            [Op.gte]: start,
                    },
                };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                    take_home_pay: {
                    ...where.take_home_pay,
                            [Op.lte]: end,
                    },
                };
                }
            }
            

            if (filter.active !== undefined) {
                where = {
                    ...where,
                    active: filter.active === true || filter.active === 'true'
                };
            }

            
            if (filter.status) {
                where = {
                    ...where,
                status: filter.status,
            };
            }
            


      

      

      

      
      if (filter.organizations) {
        const listItems = filter.organizations.split('|').map(item => {
          return  Utils.uuid(item)
        });

        where = {
          ...where,
          organizationsId: {[Op.or]: listItems}
        };
      }
      



            if (filter.createdAtRange) {
                const [start, end] = filter.createdAtRange;

                if (start !== undefined && start !== null && start !== '') {
                    where = {
                        ...where,
                        ['createdAt']: {
                            ...where.createdAt,
                            [Op.gte]: start,
                        },
                    };
                }

                if (end !== undefined && end !== null && end !== '') {
                    where = {
                        ...where,
                        ['createdAt']: {
                            ...where.createdAt,
                            [Op.lte]: end,
                        },
                    };
                }
            }
        }
        

        
        if (globalAccess) {
            delete where.organizationsId;
        }
        

        const queryOptions = {
            where,
            include,
            distinct: true,
            order: filter.field && filter.sort
                ? [[filter.field, filter.sort]]
                : [['createdAt', 'desc']],
            transaction: options?.transaction,
            logging: console.log
        };

        if (!options?.countOnly) {
            queryOptions.limit = limit ? Number(limit) : undefined;
            queryOptions.offset = offset ? Number(offset) : undefined;
        }

        try {
            const { rows, count } = await db.payroll_items.findAndCountAll(queryOptions);

            return {
                rows: options?.countOnly ? [] : rows,
                count: count
            };
        } catch (error) {
            console.error('Error executing query:', error);
            throw error;
        }
    }

    static async findAllAutocomplete(query, limit, offset,  globalAccess, organizationId,) {
        let where = {};
        
        
        if (!globalAccess && organizationId) {
            where.organizationId = organizationId;
        }
        

        if (query) {
            where = {
                [Op.or]: [
                    { ['id']: Utils.uuid(query) },
                    Utils.ilike(
                        'payroll_items',
                        'adjustment_notes',
                        query,
                    ),
                ],
            };
        }

        const records = await db.payroll_items.findAll({
            attributes: [ 'id', 'adjustment_notes' ],
            where,
            limit: limit ? Number(limit) : undefined,
            offset: offset ? Number(offset) : undefined,
            orderBy: [['adjustment_notes', 'ASC']],
        });

        return records.map((record) => ({
            id: record.id,
            label: record.adjustment_notes,
        }));
    }

    
};

