add forecast notes
This commit is contained in:
parent
26ad456d52
commit
1df3ff1adb
4
api.ts
4
api.ts
@ -76,8 +76,8 @@ router.post('/sales_walk/flag_cust', async (ctx) => {
|
||||
if (ctx.request.hasBody) {
|
||||
const body = JSON.parse(bodyText);
|
||||
console.log("Body JSON:", body);
|
||||
const { bill_cust, ship_cust, bucket, attainment, notes } = body; // Destructure the needed values from the JSON
|
||||
const result = await client.queryObject({args: [bill_cust, ship_cust, bucket, attainment, notes], text: query} );
|
||||
const { bill_cust, ship_cust, bucket, attainment, notes , fcnotes} = body; // Destructure the needed values from the JSON
|
||||
const result = await client.queryObject({args: [bill_cust, ship_cust, bucket, attainment, notes, fcnotes], text: query} );
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
|
@ -1,18 +1,19 @@
|
||||
SELECT
|
||||
sw.bill_dba,
|
||||
sw.ship_dba,
|
||||
sw.dsm,
|
||||
sw.budget_2024,
|
||||
sw.shipments_2023,
|
||||
sw.shipments_2024,
|
||||
sw.open_orders_2024,
|
||||
sw.quotes,
|
||||
--(shipments_2024 + open_orders_2024) - shipments_2023 yoy_delta,
|
||||
(shipments_2024 + open_orders_2024) - budget_2024 yoy_delta,
|
||||
sw.flag,
|
||||
sw.bucket,
|
||||
sw.attainment,
|
||||
sw.notes
|
||||
sw.bill_dba "Bill-To",
|
||||
sw.ship_dba "Ship-To",
|
||||
sw.dsm "DSM",
|
||||
sw.budget_2024 "2024 Budget",
|
||||
sw.shipments_2023 "2023 Shipments",
|
||||
sw.shipments_2024 "2024 Shipments",
|
||||
sw.open_orders_2024 "Open Orders",
|
||||
sw.quotes "Quotes",
|
||||
(shipments_2024 + open_orders_2024) - budget_2024 "Budget Delta",
|
||||
(shipments_2024 + open_orders_2024) - shipments_2023 "YoY Delta",
|
||||
sw.flag "Flag",
|
||||
sw.bucket "Bucket",
|
||||
sw.attainment "'25 Fcst vs '24 Bdgt - %",
|
||||
sw.notes "YoY Notes",
|
||||
sw.fcnotes "'25 Forecast Notes"
|
||||
FROM
|
||||
rlarp.sales_walk_r1 sw
|
||||
WHERE
|
||||
|
@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS rlarp.walk_r1 (
|
||||
,bucket text
|
||||
,attainment numeric
|
||||
,notes text
|
||||
,fcnotes text
|
||||
,PRIMARY KEY (bill_cust, ship_cust)
|
||||
);
|
||||
|
||||
@ -90,11 +91,11 @@ GROUP BY
|
||||
COALESCE(act.bill_dba,TRIM(bgt.bill_dba)) bill_dba
|
||||
,COALESCE(act.ship_dba,TRIM(bgt.ship_dba)) ship_dba
|
||||
,COALESCE(act.dsm ,TRIM(bgt.dsm )) dsm
|
||||
,SUM(COALESCE(bgt.pounds ,0)) "Budget 2024"
|
||||
,SUM(COALESCE(act."Actual 2023",0)) "Actual 2023"
|
||||
,SUM(COALESCE(act."Actual 2024",0)) "Actual 2024"
|
||||
,SUM(COALESCE(act."Open Ord" ,0)) "Open Ord"
|
||||
,SUM(COALESCE(act."Quotes" ,0)) "Quotes"
|
||||
,COALESCE(SUM(bgt.pounds ),0) "Budget 2024"
|
||||
,COALESCE(SUM(act."Actual 2023"),0) "Actual 2023"
|
||||
,COALESCE(SUM(act."Actual 2024"),0) "Actual 2024"
|
||||
,COALESCE(SUM(act."Open Ord" ),0) "Open Ord"
|
||||
,COALESCE(SUM(act."Quotes" ),0) "Quotes"
|
||||
FROM
|
||||
act
|
||||
FULL OUTER JOIN bgt ON
|
||||
@ -124,7 +125,7 @@ SELECT
|
||||
,"Quotes" quotes
|
||||
,CASE WHEN "Actual 2023" > 0
|
||||
THEN CASE
|
||||
WHEN "Actual 2024" = 0 AND "Open Ord" = 0 AND "Quotes" = 0 THEN 'No Activity'
|
||||
WHEN "Actual 2024" = 0 AND "Open Ord" = 0 AND "Quotes" = 0 THEN 'Not Quoted'
|
||||
WHEN "Actual 2024" = 0 AND "Open Ord" = 0 AND "Quotes" > 0 THEN 'Quoted Only'
|
||||
WHEN ("Actual 2024" + "Open Ord") < "Actual 2023" THEN 'Reduced'
|
||||
WHEN ("Actual 2024" + "Open Ord") >= "Actual 2023" THEN 'Increased'
|
||||
@ -133,11 +134,13 @@ SELECT
|
||||
CASE
|
||||
WHEN "Actual 2024" = 0 AND "Open Ord" = 0 AND "Quotes" > 0 THEN 'Incremental Quoted'
|
||||
WHEN "Actual 2024" > 0 OR "Open Ord" > 0 THEN 'Incremental Won'
|
||||
WHEN "Actual 2024" = 0 AND "Open Ord" = 0 AND "Quotes" = 0 THEN 'Not Quoted'
|
||||
END
|
||||
END flag
|
||||
,COALESCE(w.bucket,a.bucket,'None') bucket
|
||||
,COALESCE(w.attainment,0) attainment
|
||||
,COALESCE(w.notes,a.notes,'-') notes
|
||||
,COALESCE(w.fcnotes,'-') fcnotes
|
||||
FROM
|
||||
rlarp.sales_walk_r1_agg agg
|
||||
LEFT OUTER JOIN rlarp.walk a ON
|
||||
@ -255,9 +258,9 @@ SELECT
|
||||
,"Open Ord" open_orders_2024
|
||||
,"Quotes" quotes
|
||||
,"Budget 2024" * COALESCE(w.attainment,0) available_to_win
|
||||
,CASE WHEN "Actual 2023" > 0
|
||||
,CASE WHEN COALESCE("Actual 2023",0) > 0
|
||||
THEN CASE
|
||||
WHEN "Actual 2024" = 0 AND "Open Ord" = 0 AND "Quotes" = 0 THEN 'No Activity'
|
||||
WHEN "Actual 2024" = 0 AND "Open Ord" = 0 AND "Quotes" = 0 THEN 'Not Quoted'
|
||||
WHEN "Actual 2024" = 0 AND "Open Ord" = 0 AND "Quotes" > 0 THEN 'Quoted Only'
|
||||
WHEN ("Actual 2024" + "Open Ord") < "Actual 2023" THEN 'Reduced'
|
||||
WHEN ("Actual 2024" + "Open Ord") >= "Actual 2023" THEN 'Increased'
|
||||
@ -266,12 +269,15 @@ SELECT
|
||||
CASE
|
||||
WHEN "Actual 2024" = 0 AND "Open Ord" = 0 AND "Quotes" > 0 THEN 'Incremental Quoted'
|
||||
WHEN "Actual 2024" > 0 OR "Open Ord" > 0 THEN 'Incremental Won'
|
||||
WHEN "Actual 2024" = 0 AND "Open Ord" = 0 AND "Quotes" = 0 THEN 'Not Quoted'
|
||||
ELSE 'Not Quoted'
|
||||
END
|
||||
END flag
|
||||
,COALESCE(w.bucket,a.bucket,'None') bucket
|
||||
,COALESCE(w.attainment,0) attainment
|
||||
,COALESCE(w.notes,a.notes,'-') notes
|
||||
,sw.flag flag_cust
|
||||
,COALESCE(w.fcnotes,'-') fcnotes
|
||||
,COALESCE(sw.flag,'Not Quoted') flag_cust
|
||||
FROM
|
||||
rlarp.sales_walk_r1_seg_agg agg
|
||||
LEFT OUTER JOIN rlarp.walk a ON
|
||||
|
@ -1,13 +1,14 @@
|
||||
MERGE INTO
|
||||
rlarp.walk_r1 w
|
||||
USING
|
||||
( SELECT $1 bill_cust, $2 ship_cust, $3 bucket, $4 attainment, $5 notes) as i ON
|
||||
( SELECT $1 bill_cust, $2 ship_cust, $3 bucket, $4 attainment, $5 notes, $6 fcnotes) as i ON
|
||||
i.ship_cust = w.ship_cust
|
||||
AND i.bill_cust = w.bill_cust
|
||||
WHEN MATCHED THEN UPDATE SET
|
||||
bucket = i.bucket
|
||||
,attainment = i.attainment::numeric
|
||||
,notes = i.notes
|
||||
,fcnotes = i.fcnotes
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (bill_cust, ship_cust, bucket, attainment, notes)
|
||||
VALUES (bill_cust,i.ship_cust, i.bucket, i.attainment::numeric, i.notes )
|
||||
INSERT (bill_cust, ship_cust, bucket, attainment, notes, fcnotes)
|
||||
VALUES (bill_cust,i.ship_cust, i.bucket, i.attainment::numeric, i.notes , i.fcnotes)
|
||||
|
Loading…
Reference in New Issue
Block a user