Rate Calculation
function test() {
let unlocode_data = {
hongkong: "HKHKG",
shangai: "CNSHA",
longbeach: "USLGB",
};
const db_data = _.get(payload, "generated.get_sheet_data.data.values");
const ext_data = _.get(payload, "generated.mapping.result.extracted_data.0");
const container_type = _.get(ext_data, "container_details.0.container_size");
const container_count = _.get(
ext_data,
"container_details.0.container_count"
);
let origin_loc = _.get(ext_data, "origin.location")
.replace(/\s/g, "")
.toLowerCase();
let dest_loc = _.get(ext_data, "destination.location")
.replace(/\s/g, "")
.toLowerCase();
const origin_code = unlocode_data[origin_loc];
const dest_code = unlocode_data[dest_loc];
let total_charge = 0;
let freight_charge = 0;
let charge = 0;
db_data.map((item) => {
if (
item[0] === container_type &&
item[2] === origin_code &&
item[3] === dest_code
) {
if (item[5] === "Freight") {
freight_charge = Number(item[6].replace("$", "").replace(/,/g, ""));
} else {
charge = Number(item[6].replace("$", "").replace(/,/g, ""));
}
total_charge = freight_charge + charge;
}
});
return {
type: container_type,
origin: _.get(ext_data, "origin.location"),
destination: _.get(ext_data, "destination.location"),
pol: origin_code,
pod: dest_code,
freight: freight_charge,
fuel: charge,
total_container: container_count,
total: total_charge * container_count,
description: `Quotation for ${container_count} ${container_type} from ${origin_code}(${_.get(
ext_data,
"origin.location"
)}) to ${dest_code}(${_.get(
ext_data,
"destination.location"
)}). Your total charge is ${total_charge * container_count}`,
};
}