import { format } from "date-fns-tz";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { query } from "../../sqlServer/prodSqlServer.js";
import { financeAudit } from "../../sqlServer/querys/dataMart/financeAudit.js";

export const getfinanceAudit = async (date: any) => {
    let inventoryAudit: any = [];

    const { data, error } = (await tryCatch(
        query(financeAudit.replace("[date]", date), "inventory audit")
    )) as any;

    //console.log(data);

    if (error) {
        return [];
    }

    inventoryAudit = data.data.map((i: any) => {
        return { ...i, bookinDate: format(i.bookinDate, "MM/dd/yyyy") };
    });

    return inventoryAudit;
};
