WIP Line Calculations
This commit is contained in:
17
.vscode/launch.json
vendored
Normal file
17
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug Main Process",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
|
||||
"windows": {
|
||||
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
|
||||
},
|
||||
"args": ["."],
|
||||
"outputCapture": "std"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
const { DBFFile } = require("dbffile");
|
||||
const path = require("path");
|
||||
const _ = require("lodash");
|
||||
const log = require("electron-log");
|
||||
|
||||
async function DecodeEstimate(filePath) {
|
||||
const parsedFilePath = path.parse(filePath);
|
||||
@@ -8,7 +9,6 @@ async function DecodeEstimate(filePath) {
|
||||
parsedFilePath.dir,
|
||||
parsedFilePath.name
|
||||
);
|
||||
console.log("DecodeEstimate -> extensionlessFilePath", extensionlessFilePath);
|
||||
const ret = {
|
||||
...(await DecodeAd1File(extensionlessFilePath)),
|
||||
...(await DecodeVehFile(extensionlessFilePath)),
|
||||
@@ -16,7 +16,10 @@ async function DecodeEstimate(filePath) {
|
||||
...(await DecodeLinFile(extensionlessFilePath)),
|
||||
};
|
||||
|
||||
if (ret.V_MILEAGE > 20000) return ret;
|
||||
if (ret.V_MILEAGE > 20000)
|
||||
return _.transform(ret, function (result, val, key) {
|
||||
result[key.toLowerCase()] = val;
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -181,7 +184,6 @@ async function DecodeTtlFile(extensionlessFilePath) {
|
||||
async function DecodeLinFile(extensionlessFilePath) {
|
||||
let dbf = await DBFFile.open(`${extensionlessFilePath}.LIN`);
|
||||
let records = await dbf.readRecords();
|
||||
|
||||
let joblines = records.map((record) =>
|
||||
_.transform(
|
||||
_.pick(record, [
|
||||
@@ -233,6 +235,7 @@ async function DecodeLinFile(extensionlessFilePath) {
|
||||
]),
|
||||
function (result, val, key) {
|
||||
//Required because unq_seq gets pulled as a numeric instaed of a string.
|
||||
console.log("key", key);
|
||||
if (key === "UNQ_SEQ") {
|
||||
return (result[key.toLowerCase()] = val.toString());
|
||||
}
|
||||
@@ -241,22 +244,28 @@ async function DecodeLinFile(extensionlessFilePath) {
|
||||
)
|
||||
);
|
||||
|
||||
//Perform required RPS Validations.
|
||||
//Update DB Prices.
|
||||
const massagedJobLines = joblines
|
||||
const m = joblines
|
||||
.filter(
|
||||
(jobline) =>
|
||||
jobline.PART_TYPE &&
|
||||
!jobline.db_ref.startsWith("900") &&
|
||||
(jobline.part_type && jobline.part_type.toUpperCase()) !== "PAG" &&
|
||||
jobline.glass_flag === false
|
||||
)
|
||||
.map((jobline) => {
|
||||
//
|
||||
console.log("Massagejobline", jobline);
|
||||
if (
|
||||
(jobline.db_price === null || jobline.db_price === 0) &&
|
||||
!!jobline.act_price &&
|
||||
jobline.act_price > 0
|
||||
) {
|
||||
console.log(1, jobline.line_desc, jobline.db_price, jobline.act_price);
|
||||
log.info(
|
||||
"DB Price null/lower than act price",
|
||||
jobline.line_desc,
|
||||
jobline.db_price,
|
||||
jobline.act_price
|
||||
);
|
||||
jobline.db_price = jobline.act_price;
|
||||
}
|
||||
|
||||
@@ -265,14 +274,22 @@ async function DecodeLinFile(extensionlessFilePath) {
|
||||
jobline.act_price &&
|
||||
jobline.act_price > jobline.db_price
|
||||
) {
|
||||
log.info(
|
||||
"Act price higher than existing db price",
|
||||
jobline.line_desc,
|
||||
jobline.db_price,
|
||||
jobline.act_price
|
||||
);
|
||||
console.log(2, jobline.line_desc, jobline.db_price, jobline.act_price);
|
||||
jobline.db_price = jobline.act_price;
|
||||
}
|
||||
|
||||
delete jobline.glass_flag;
|
||||
console.log(jobline);
|
||||
return jobline;
|
||||
});
|
||||
|
||||
return { joblines: { data: massagedJobLines } };
|
||||
return { joblines: { data: joblines } };
|
||||
}
|
||||
|
||||
exports.DecodeEstimate = DecodeEstimate;
|
||||
|
||||
@@ -106,14 +106,11 @@ async function HandleNewFile(path) {
|
||||
const b = BrowserWindow.getAllWindows()[0];
|
||||
b.webContents.send(ipcTypes.default.estimate.toRenderer.estimateDecodeStart);
|
||||
const newJob = await DecodeEstimate(path);
|
||||
const newJobLow = _.transform(newJob, function (result, val, key) {
|
||||
result[key.toLowerCase()] = val;
|
||||
});
|
||||
|
||||
if (newJobLow && newJob) {
|
||||
if (newJob && newJob) {
|
||||
b.webContents.send(
|
||||
ipcTypes.default.estimate.toRenderer.estimateDecodeSuccess,
|
||||
newJobLow
|
||||
newJob
|
||||
);
|
||||
|
||||
NewNotification({
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: ALTER TABLE "public"."joblines" DROP COLUMN "price_diff";
|
||||
type: run_sql
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: ALTER TABLE "public"."joblines" ADD COLUMN "price_diff" numeric NULL;
|
||||
type: run_sql
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: ALTER TABLE "public"."joblines" DROP COLUMN "price_diff_pc";
|
||||
type: run_sql
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: ALTER TABLE "public"."joblines" ADD COLUMN "price_diff_pc" numeric NULL;
|
||||
type: run_sql
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
20
hasura/migrations/1602875306082_run_sql_migration/up.yaml
Normal file
20
hasura/migrations/1602875306082_run_sql_migration/up.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: |-
|
||||
CREATE OR REPLACE FUNCTION public.calculate_job_line()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
DECLARE
|
||||
_new record;
|
||||
BEGIN
|
||||
_new := NEW;
|
||||
_new."price_diff" = _new."db_price" - _new."act_price";
|
||||
_new."price_diff_pc" = (_new."db_price" - _new."act_price") / _new."db_price";
|
||||
_new."updated_at" = NOW();
|
||||
RETURN _new;
|
||||
END;
|
||||
$function$
|
||||
;
|
||||
type: run_sql
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -0,0 +1,9 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: "CREATE OR REPLACE FUNCTION public.calculate_job_line()\n RETURNS trigger\n
|
||||
LANGUAGE plpgsql\nAS $function$\nDECLARE\n _new record;\nBEGIN\n _new := NEW;\n
|
||||
_new.\"price_diff\" = _new.\"db_price\" - _new.\"act_price\";\n\nif _new.\"db_price\"
|
||||
> 0 then \n_new.\"price_diff_pc\" = (_new.\"db_price\" - _new.\"act_price\")
|
||||
/ _new.\"db_price\";\n\nend if;\n\n RETURN _new;\nEND;\n$function$\n;"
|
||||
type: run_sql
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -0,0 +1,9 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: |-
|
||||
create trigger calculate_updated_job_line before
|
||||
update
|
||||
on
|
||||
public.joblines for each row execute procedure calculate_job_line();
|
||||
type: run_sql
|
||||
@@ -0,0 +1,37 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: drop_insert_permission
|
||||
- args:
|
||||
permission:
|
||||
backend_only: false
|
||||
check:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
columns:
|
||||
- act_price
|
||||
- created_at
|
||||
- db_price
|
||||
- db_ref
|
||||
- id
|
||||
- jobid
|
||||
- line_desc
|
||||
- line_ind
|
||||
- line_no
|
||||
- oem_partno
|
||||
- part_qty
|
||||
- part_type
|
||||
- unq_seq
|
||||
- updated_at
|
||||
set: {}
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: create_insert_permission
|
||||
@@ -0,0 +1,39 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: drop_insert_permission
|
||||
- args:
|
||||
permission:
|
||||
backend_only: false
|
||||
check:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
columns:
|
||||
- act_price
|
||||
- created_at
|
||||
- db_price
|
||||
- db_ref
|
||||
- id
|
||||
- jobid
|
||||
- line_desc
|
||||
- line_ind
|
||||
- line_no
|
||||
- oem_partno
|
||||
- part_qty
|
||||
- part_type
|
||||
- price_diff
|
||||
- price_diff_pc
|
||||
- unq_seq
|
||||
- updated_at
|
||||
set: {}
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: create_insert_permission
|
||||
@@ -0,0 +1,37 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
columns:
|
||||
- act_price
|
||||
- created_at
|
||||
- db_price
|
||||
- db_ref
|
||||
- id
|
||||
- jobid
|
||||
- line_desc
|
||||
- line_ind
|
||||
- line_no
|
||||
- oem_partno
|
||||
- part_qty
|
||||
- part_type
|
||||
- unq_seq
|
||||
- updated_at
|
||||
computed_fields: []
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -0,0 +1,39 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
columns:
|
||||
- act_price
|
||||
- created_at
|
||||
- db_price
|
||||
- db_ref
|
||||
- id
|
||||
- jobid
|
||||
- line_desc
|
||||
- line_ind
|
||||
- line_no
|
||||
- oem_partno
|
||||
- part_qty
|
||||
- part_type
|
||||
- price_diff
|
||||
- price_diff_pc
|
||||
- unq_seq
|
||||
- updated_at
|
||||
computed_fields: []
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -0,0 +1,36 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: drop_update_permission
|
||||
- args:
|
||||
permission:
|
||||
columns:
|
||||
- act_price
|
||||
- created_at
|
||||
- db_price
|
||||
- db_ref
|
||||
- id
|
||||
- jobid
|
||||
- line_desc
|
||||
- line_ind
|
||||
- line_no
|
||||
- oem_partno
|
||||
- part_qty
|
||||
- part_type
|
||||
- unq_seq
|
||||
- updated_at
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
set: {}
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: create_update_permission
|
||||
@@ -0,0 +1,38 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: drop_update_permission
|
||||
- args:
|
||||
permission:
|
||||
columns:
|
||||
- act_price
|
||||
- created_at
|
||||
- db_price
|
||||
- db_ref
|
||||
- id
|
||||
- jobid
|
||||
- line_desc
|
||||
- line_ind
|
||||
- line_no
|
||||
- oem_partno
|
||||
- part_qty
|
||||
- part_type
|
||||
- price_diff
|
||||
- price_diff_pc
|
||||
- unq_seq
|
||||
- updated_at
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
set: {}
|
||||
role: user
|
||||
table:
|
||||
name: joblines
|
||||
schema: public
|
||||
type: create_update_permission
|
||||
@@ -81,6 +81,8 @@ tables:
|
||||
- oem_partno
|
||||
- part_qty
|
||||
- part_type
|
||||
- price_diff
|
||||
- price_diff_pc
|
||||
- unq_seq
|
||||
- updated_at
|
||||
backend_only: false
|
||||
@@ -100,6 +102,8 @@ tables:
|
||||
- oem_partno
|
||||
- part_qty
|
||||
- part_type
|
||||
- price_diff
|
||||
- price_diff_pc
|
||||
- unq_seq
|
||||
- updated_at
|
||||
filter:
|
||||
@@ -125,6 +129,8 @@ tables:
|
||||
- oem_partno
|
||||
- part_qty
|
||||
- part_type
|
||||
- price_diff
|
||||
- price_diff_pc
|
||||
- unq_seq
|
||||
- updated_at
|
||||
filter:
|
||||
|
||||
@@ -80,6 +80,8 @@ export const QUERY_JOB_BY_PK = gql`
|
||||
part_qty
|
||||
part_type
|
||||
unq_seq
|
||||
price_diff
|
||||
price_diff_pc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user