import { query } from "../../sqlServer/prodSqlServer.js";
import { customerInvNoHold } from "../../sqlServer/querys/dataMart/customerInventoryQuerys.js";

export const getCurrentCustomerInv = async (data: any | null) => {
    //console.log(data.customer[0]);

    let updatedQuery = customerInvNoHold;

    if (data.customer) {
        //console.log(data.customer);
        updatedQuery = customerInvNoHold.replaceAll(
            "--and IdAdressen",
            `and IdAdressen = ${data.customer[0]}`
        );
    }

    if (data.whseToInclude) {
        updatedQuery = updatedQuery.replaceAll(
            "--and x.IdWarenlager in (14,15)",
            `and x.IdWarenlager in (${data.whseToInclude[0]})`
        );
    }
    try {
        const inventory: any = await query(
            updatedQuery,
            "Get active inventory"
        );

        return {
            success: true,
            message: "All customer inventory minus holds",
            data: inventory.data,
        };
    } catch (error) {
        return {
            success: false,
            message: "There was an error getting the inventory",
            data: error,
        };
    }
};
