Compare commits

..

No commits in common. "dev" and "master" have entirely different histories.
dev ... master

25 changed files with 1979 additions and 1806 deletions

View File

@ -382,15 +382,15 @@ End Function
Public Function ARRAYp_MakeInteger(ParamArray items()) As Integer()
Dim X() As Integer
Dim x() As Integer
Dim i As Integer
ReDim X(UBound(items))
ReDim x(UBound(items))
For i = 0 To UBound(items())
X(i) = items(i)
x(i) = items(i)
Next i
ARRAYp_MakeInteger = X
ARRAYp_MakeInteger = x
End Function
@ -604,17 +604,15 @@ Sub frmListBoxHeader(ByRef hdr As MSForms.listbox, ByRef det As MSForms.listbox,
'lbHEAD.ZOrder (0)
hdr.SpecialEffect = fmSpecialEffectFlat
'hdr.BackColor = RGB(200, 200, 200)
'hdr.Height = 15
hdr.Height = 10
' align header to body (should be done last!)
hdr.width = det.width
hdr.Left = det.Left
hdr.Top = det.Top - (hdr.Height + 3)
hdr.Top = det.Top - (hdr.Height - 1)
End Sub
Public Function IntersectsWith(Range1 As Range, Range2 As Range) As Boolean
IntersectsWith = Not Application.Intersect(Range1, Range2) Is Nothing
End Function

View File

@ -1,10 +1,10 @@
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} build
Caption = "Change the Mix"
ClientHeight = 1590
Caption = "UserForm1"
ClientHeight = 3015
ClientLeft = 120
ClientTop = 465
ClientWidth = 10725
ClientWidth = 8100
OleObjectBlob = "build.frx":0000
StartUpPosition = 1 'CenterOwner
End
@ -13,27 +13,61 @@ Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public part As String
Public bill As String
Public ship As String
Public useval As Boolean
Option Explicit
Public useval As Boolean
Private Sub cmdCancel_Click()
useval = False
Me.Hide
Private Sub cbBill_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 13
useval = True
Me.Hide
Case 27
useval = False
Me.Hide
End Select
End Sub
Private Sub cmdOK_Click()
useval = True
Me.Hide
Private Sub cbPart_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 13
useval = True
Me.Hide
Case 27
useval = False
Me.Hide
End Select
End Sub
Public Sub Initialize(part As String, billTo As String, shipTo As String)
cbPart.list = shSupportingData.ListObjects("ITEM").DataBodyRange.Value
cbPart.Value = part
cbBill.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.Value
cbBill.Value = billTo
cbShip.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.Value
cbShip.Value = shipTo
Private Sub cbShip_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 13
useval = True
Me.Hide
Case 27
useval = False
Me.Hide
End Select
End Sub
Private Sub UserForm_Activate()
useval = False
cbPart.value = part
cbBill.value = bill
cbShip.value = ship
cbPart.list = shSupportingData.ListObjects("ITEM").DataBodyRange.value
cbBill.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.value
cbShip.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.value
End Sub

Binary file not shown.

View File

@ -1,7 +1,7 @@
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} changes
Caption = "History"
ClientHeight = 7815
ClientHeight = 7785
ClientLeft = 120
ClientTop = 465
ClientWidth = 16710
@ -13,40 +13,93 @@ Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private X As Variant
Private x As Variant
Private Sub cbCancel_Click()
Me.Hide
End Sub
Private Sub cbUndo_Click()
Call Me.delete_selected
End Sub
Private Sub lbHist_Change()
Dim i As Integer
For i = 0 To Me.lbHist.ListCount - 1
If Me.lbHist.Selected(i) Then
Me.tbPrint.Value = X(i, 7)
Me.tbPrint.value = x(i, 7)
Exit Sub
End If
Next i
End Sub
Private Sub lbHist_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 46
Call Me.delete_selected
Case 27
Call Me.Hide
End Select
End Sub
Private Sub UserForm_Activate()
Dim fail As Boolean
X = handler.list_changes("{""scenario"":{""quota_rep_descr"":""" & shData.Cells(2, 5) & """}}", fail)
'x = handler.list_changes("{""user"":""" & Application.UserName & """}", fail)
x = handler.list_changes("{""scenario"":{""quota_rep_descr"":""" & shData.Cells(2, 5) & """}}", fail)
If fail Then
Me.Hide
Exit Sub
End If
Me.lbHist.list = X
Me.lbHist.list = x
lbHEAD.ColumnCount = lbHist.ColumnCount
lbHEAD.ColumnWidths = lbHist.ColumnWidths
' add header elements
lbHEAD.clear
lbHEAD.AddItem
lbHEAD.list(0, 0) = "Modifier"
lbHEAD.list(0, 1) = "Owner"
lbHEAD.list(0, 2) = "When"
lbHEAD.list(0, 3) = "Tag"
lbHEAD.list(0, 4) = "Comment"
lbHEAD.list(0, 5) = "Sales"
lbHEAD.list(0, 6) = "id"
Call Utils.frmListBoxHeader(Me.lbHEAD, Me.lbHist, "Modifier", "Owner", "When", "Tag", "Comment", "Sales", "id")
' make it pretty
'body.ZOrder (1)
'lbHEAD.ZOrder (0)
'lbHEAD.SpecialEffect = fmSpecialEffectFlat
'lbHEAD.BackColor = RGB(200, 200, 200)
'lbHEAD.Height = 10
' align header to body (should be done last!)
'lbHEAD.width = lbHist.width
'lbHEAD.Left = lbHist.Left
'lbHEAD.Top = lbHist.Top - (lbHEAD.Height - 1)
End Sub
Sub delete_selected()
Dim logid As Integer
Dim i As Integer
Dim fail As Boolean
@ -56,11 +109,12 @@ Sub delete_selected()
Exit Sub
End If
For i = 0 To Me.lbHist.ListCount - 1
If Me.lbHist.Selected(i) Then
Call handler.undo_changes(X(i, 6), fail)
Call handler.undo_changes(x(i, 6), fail)
If fail Then
MsgBox ("Undo did not work.")
MsgBox ("undo did not work")
Exit Sub
End If
End If
@ -70,4 +124,5 @@ Sub delete_selected()
Me.lbHist.clear
Me.Hide
End Sub

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -98,13 +98,7 @@ Sub pg_main_workset(rep As String)
Exit Sub
End If
Set json = JsonConverter.ParseJson(wr)
If IsNull(json("x")) Then
MsgBox "No data found for " & rep & "."
Exit Sub
End If
ReDim res(json("x").Count, 34)
ReDim res(json("x").Count, 33)
For i = 1 To UBound(res, 1)
res(i, 0) = json("x")(i)("bill_cust_descr")
@ -141,7 +135,6 @@ Sub pg_main_workset(rep As String)
res(i, 31) = json("x")(i)("logid")
res(i, 32) = json("x")(i)("tag")
res(i, 33) = json("x")(i)("comment")
res(i, 34) = json("x")(i)("pounds")
Next i
res(0, 0) = "bill_cust_descr"
@ -178,7 +171,6 @@ Sub pg_main_workset(rep As String)
res(0, 31) = "logid"
res(0, 32) = "tag"
res(0, 33) = "comment"
res(0, 34) = "pounds"
Set json = Nothing
@ -217,7 +209,7 @@ Function request_adjust(doc As String, ByRef fail As Boolean) As Object
'json("stamp") = Format(Now, "yyyy-mm-dd hh:mm:ss")
'doc = JsonConverter.ConvertToJson(doc)
server = shConfig.Range("server").Value
server = shConfig.Cells(1, 2)
With req
.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
@ -255,12 +247,12 @@ Function request_adjust(doc As String, ByRef fail As Boolean) As Object
Set json = JsonConverter.ParseJson(wr)
If IsNull(json("x")) Then
MsgBox ("No adjustment was made.")
MsgBox ("no adjustment was made")
fail = False
Exit Function
End If
ReDim res(json("x").Count - 1, 34)
ReDim res(json("x").Count - 1, 33)
For i = 0 To UBound(res, 1)
res(i, 0) = json("x")(i + 1)("bill_cust_descr")
@ -297,7 +289,6 @@ Function request_adjust(doc As String, ByRef fail As Boolean) As Object
res(i, 31) = json("x")(i + 1)("logid")
res(i, 32) = json("x")(i + 1)("tag")
res(i, 33) = json("x")(i + 1)("comment")
res(i, 34) = json("x")(i + 1)("pounds")
Next i
Set json = Nothing
@ -331,31 +322,41 @@ End Function
Sub load_config()
Dim i As Integer
Dim j As Integer
'----server to use---------------------------------------------------------
handler.server = shConfig.Range("server").Value
handler.server = shConfig.Cells(1, 2)
'---basis-----------------------------------------------------------------
With shConfig.ListObjects("BASIS")
For i = 1 To .DataBodyRange.Rows.Count
ReDim Preserve handler.basis(i - 1)
handler.basis(i - 1) = .DataBodyRange(i, 1)
Next
End With
ReDim handler.basis(100)
i = 2
j = 0
Do While shConfig.Cells(2, i) <> ""
handler.basis(j) = shConfig.Cells(2, i)
j = j + 1
i = i + 1
Loop
ReDim Preserve handler.basis(j - 1)
'---baseline-----------------------------------------------------------------
With shConfig.ListObjects("BASELINE")
For i = 1 To .DataBodyRange.Rows.Count
ReDim Preserve handler.baseline(i - 1)
handler.baseline(i - 1) = .DataBodyRange(i, 1)
Next
End With
ReDim handler.baseline(100)
i = 2
j = 0
Do While shConfig.Cells(3, i) <> ""
handler.baseline(j) = shConfig.Cells(3, i)
j = j + 1
i = i + 1
Loop
ReDim Preserve handler.baseline(j - 1)
'---adjustments-----------------------------------------------------------------
With shConfig.ListObjects("ADJUST")
For i = 1 To .DataBodyRange.Rows.Count
ReDim Preserve handler.adjust(i - 1)
handler.adjust(i - 1) = .DataBodyRange(i, 1)
Next
End With
ReDim handler.adjust(100)
i = 2
j = 0
Do While shConfig.Cells(4, i) <> ""
handler.adjust(j) = shConfig.Cells(4, i)
j = j + 1
i = i + 1
Loop
ReDim Preserve handler.adjust(j - 1)
'---plan version--------------------------------------------------------------
handler.plan = shConfig.Range("budget").Value
handler.plan = shConfig.Cells(9, 2)
End Sub
@ -370,7 +371,7 @@ Sub month_tosheet(ByRef pkg() As Variant, ByRef basket() As Variant)
Set j = JsonConverter.ParseJson("{""scenario"":" & scenario & "}")
.Cells(1, 16) = JsonConverter.ConvertToJson(j)
For i = 1 To 12
For i = 0 To 12
'------------volume-------------------
.Cells(i + 1, 1) = co_num(pkg(i, 1), 0)
.Cells(i + 1, 2) = co_num(pkg(i, 2), 0)
@ -455,11 +456,11 @@ Sub month_tosheet(ByRef pkg() As Variant, ByRef basket() As Variant)
.Range("U1:AC100000").ClearContents
Call Utils.SHTp_DumpVar(basket, .Name, 1, 21, False, False, True)
Call Utils.SHTp_DumpVar(basket, .Name, 1, 26, False, False, True)
shConfig.Range("rebuild").Value = 0
shConfig.Range("show_basket").Value = 0
shConfig.Range("new_part").Value = 0
shConfig.Cells(5, 2) = 0
shConfig.Cells(6, 2) = 0
shConfig.Cells(7, 2) = 0
shMonthView.LoadSheet
shMonthView.load_sheet
End With
@ -490,7 +491,7 @@ Function list_changes(doc As String, ByRef fail As Boolean) As Variant()
Exit Function
End If
server = shConfig.Range("server").Value
server = shConfig.Cells(1, 2)
With req
.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
@ -504,7 +505,7 @@ Function list_changes(doc As String, ByRef fail As Boolean) As Variant()
Set json = JsonConverter.ParseJson(wr)
If IsNull(json("x")) Then
MsgBox ("No history.")
MsgBox ("no history")
fail = True
Exit Function
End If
@ -564,7 +565,7 @@ Function undo_changes(ByVal logid As Integer, ByRef fail As Boolean) As Variant(
Next i
If j = 0 Then
MsgBox ("Current data set is not tracking changes. Cannot isolate change locally.")
MsgBox ("current data set is not tracking changes, cannot isolate change locally")
fail = True
Exit Function
End If
@ -603,7 +604,7 @@ Function get_swap_fit(doc As String, ByRef fail As Boolean) As Variant()
Exit Function
End If
server = shConfig.Range("server").Value
server = shConfig.Cells(1, 2)
With req
.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
@ -617,7 +618,7 @@ Function get_swap_fit(doc As String, ByRef fail As Boolean) As Variant()
Set json = JsonConverter.ParseJson(wr)
If IsNull(json("x")) Then
MsgBox ("No history.")
MsgBox ("no history")
fail = True
Exit Function
End If

View File

@ -1,10 +1,10 @@
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} openf
Caption = "Open a Forecast"
ClientHeight = 1365
ClientHeight = 2025
ClientLeft = 120
ClientTop = 465
ClientWidth = 6825
ClientWidth = 3825
OleObjectBlob = "openf.frx":0000
StartUpPosition = 1 'CenterOwner
End
@ -21,10 +21,10 @@ End Sub
Private Sub cbOK_Click()
Application.StatusBar = "Retrieving data for " & cbDSM.Value & "....."
Application.StatusBar = "Retrieving data for " & cbDSM.value & "....."
openf.Caption = "Retrieving data......"
Call handler.pg_main_workset(cbDSM.Value)
openf.Caption = "retrieving data......"
Call handler.pg_main_workset(cbDSM.value)
shOrders.PivotTables("ptOrders").PivotCache.Refresh
Application.StatusBar = False
openf.Hide
@ -33,8 +33,11 @@ End Sub
Private Sub UserForm_Activate()
handler.server = shConfig.Range("server").Value
cbDSM.list = shSupportingData.ListObjects("DSM").DataBodyRange.Value
'handler.server = "http://192.168.1.69:3000"
handler.server = shConfig.Cells(1, 2)
openf.Caption = "Select a DSM"
cbDSM.list = shSupportingData.ListObjects("DSM").DataBodyRange.value
End Sub

Binary file not shown.

View File

@ -1,10 +1,10 @@
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} part
Caption = "Part Picker"
ClientHeight = 1335
ClientHeight = 1080
ClientLeft = 120
ClientTop = 465
ClientWidth = 9285.001
ClientWidth = 8100
OleObjectBlob = "part.frx":0000
StartUpPosition = 1 'CenterOwner
End
@ -13,23 +13,34 @@ Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public part As String
Public bill As String
Public ship As String
Public useval As Boolean
Option Explicit
Public useval As Boolean
Private Sub cmdCancel_Click()
useval = False
Me.Hide
Private Sub cbPart_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 13
useval = True
Me.Hide
Case 27
useval = False
Me.Hide
End Select
End Sub
Private Sub cmdOK_Click()
useval = True
Me.Hide
End Sub
Private Sub UserForm_Activate()
useval = False
cbPart.list = shSupportingData.ListObjects("ITEM").DataBodyRange.Value
cbPart.list = shSupportingData.ListObjects("ITEM").DataBodyRange.value
End Sub

Binary file not shown.

View File

@ -7,25 +7,3 @@ Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, shConfig.Range("debug_mode")) Is Nothing Then Exit Sub
If shConfig.Range("debug_mode").Value Then
shConfig.Visible = xlSheetVisible
shData.Visible = xlSheetVisible
shMonthView.Visible = xlSheetVisible
shMonthUpdate.Visible = xlSheetVisible
shSupportingData.Visible = xlSheetVisible
shWalk.Visible = xlSheetVisible
Else
shConfig.Visible = xlSheetVeryHidden
shData.Visible = xlSheetHidden
shMonthView.Visible = xlSheetHidden
shMonthUpdate.Visible = xlSheetVeryHidden
shSupportingData.Visible = xlSheetVeryHidden
shWalk.Visible = xlSheetVeryHidden
End If
End Sub

View File

@ -1,11 +0,0 @@
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "shHelp"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
Option Explicit

File diff suppressed because it is too large Load Diff

View File

@ -7,108 +7,108 @@ Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
'Option Explicit
' Option Explicit
'
'Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
' Dim pt As PivotTable
' Set pt = ActiveSheet.PivotTables("ptWalk")
' Dim intersec As Range
' Set intersec = Intersect(Target, pt.DataBodyRange)
' Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
' Dim pt As PivotTable
' Set pt = ActiveSheet.PivotTables("ptWalk")
' Dim intersec As Range
' Set intersec = Intersect(Target, pt.DataBodyRange)
'
' If intersec Is Nothing Then
' Exit Sub
' ElseIf intersec.address <> Target.address Then
' Exit Sub
' End If
' If intersec Is Nothing Then
' Exit Sub
' ElseIf intersec.address <> Target.address Then
' Exit Sub
' End If
'
' Cancel = True
' Cancel = True
'
' Dim i As Long
' Dim j As Long
' Dim k As Long
' Dim i As Long
' Dim j As Long
' Dim k As Long
'
' Dim ri As PivotItemList
' Dim ci As PivotItemList
' Dim df As Object
' Dim rd As Object
' Dim cd As Object
' Dim dd As Object
' Dim ri As PivotItemList
' Dim ci As PivotItemList
' Dim df As Object
' Dim rd As Object
' Dim cd As Object
' Dim dd As Object
'
' Dim pf As PivotField
' Dim pi As PivotItem
' Dim pf As PivotField
' Dim pi As PivotItem
'
' Set ri = Target.Cells.PivotCell.RowItems
' Set ci = Target.Cells.PivotCell.ColumnItems
' Set df = Target.Cells.PivotCell.DataField
' Set ri = Target.Cells.PivotCell.RowItems
' Set ci = Target.Cells.PivotCell.ColumnItems
' Set df = Target.Cells.PivotCell.DataField
'
' Set rd = Target.Cells.PivotTable.RowFields
' Set cd = Target.Cells.PivotTable.ColumnFields
' Set rd = Target.Cells.PivotTable.RowFields
' Set cd = Target.Cells.PivotTable.ColumnFields
'
' ReDim handler.sc(ri.Count, 1)
' ReDim handler.sc(ri.Count, 1)
'
' handler.sql = ""
' handler.jsql = ""
' handler.sql = ""
' handler.jsql = ""
'
' For i = 1 To ri.Count
' If i <> 1 Then handler.sql = handler.sql & vbCrLf & "AND "
' If i <> 1 Then handler.jsql = handler.jsql & vbCrLf & ","
' handler.sql = handler.sql & rd(piv_pos(rd, i)).Name & " = '" & escape_sql(ri(i).Name) & "'"
' jsql = jsql & """" & rd(piv_pos(rd, i)).Name & """:""" & escape_json(ri(i).Name) & """"
' handler.sc(i - 1, 0) = rd(piv_pos(rd, i)).Name
' handler.sc(i - 1, 1) = ri(i).Name
' Next i
' For i = 1 To ri.Count
' If i <> 1 Then handler.sql = handler.sql & vbCrLf & "AND "
' If i <> 1 Then handler.jsql = handler.jsql & vbCrLf & ","
' handler.sql = handler.sql & rd(piv_pos(rd, i)).Name & " = '" & escape_sql(ri(i).Name) & "'"
' jsql = jsql & """" & rd(piv_pos(rd, i)).Name & """:""" & escape_json(ri(i).Name) & """"
' handler.sc(i - 1, 0) = rd(piv_pos(rd, i)).Name
' handler.sc(i - 1, 1) = ri(i).Name
' Next i
'
' scenario = "{" & handler.jsql & "}"
' scenario = "{" & handler.jsql & "}"
'
' Call handler.load_config
' Call handler.load_fpvt
' Call handler.load_config
' Call handler.load_fpvt
'
'End Sub
' End Sub
'
'Function piv_pos(list As Object, target_pos As Long) As Long
' Function piv_pos(list As Object, target_pos As Long) As Long
'
' Dim i As Long
' Dim i As Long
'
' For i = 1 To list.Count
' If list(i).Position = target_pos Then
' piv_pos = i
' Exit Function
' End If
' Next i
' 'should not get to this point
' For i = 1 To list.Count
' If list(i).Position = target_pos Then
' piv_pos = i
' Exit Function
' End If
' Next i
' 'should not get to this point
'
'End Function
' End Function
'
'Function piv_fld_index(field_name As String, ByRef pt As PivotTable) As Integer
' Function piv_fld_index(field_name As String, ByRef pt As PivotTable) As Integer
'
' Dim i As Integer
' Dim i As Integer
'
' For i = 1 To pt.PivotFields.Count
' If pt.PivotFields(i).Name = field_name Then
' piv_fld_index = i
' Exit Function
' End If
' Next i
' For i = 1 To pt.PivotFields.Count
' If pt.PivotFields(i).Name = field_name Then
' piv_fld_index = i
' Exit Function
' End If
' Next i
'
'End Function
' End Function
'
'Function escape_json(ByVal text As String) As String
' Function escape_json(ByVal text As String) As String
'
' text = Replace(text, "'", "''")
' text = Replace(text, """", "\""")
' If text = "(blank)" Then text = ""
' escape_json = text
' text = Replace(text, "'", "''")
' text = Replace(text, """", "\""")
' If text = "(blank)" Then text = ""
' escape_json = text
'
'End Function
' End Function
'
'Function escape_sql(ByVal text As String) As String
' Function escape_sql(ByVal text As String) As String
'
' text = Replace(text, "'", "''")
' text = Replace(text, """", """""")
' If text = "(blank)" Then text = ""
' escape_sql = text
' text = Replace(text, "'", "''")
' text = Replace(text, """", """""")
' If text = "(blank)" Then text = ""
' escape_sql = text
'
'End Function
' End Function
'
'

View File

@ -1,795 +0,0 @@
-- Connection: usmidsql01.FAnalysis
/*
*******************************************************************************************************************************************
** Phil Runninger, 4/27/2023 *************************************************************************************************************
**
** Here is how you use this script. This procedure is only temporary, as the entire
** system will be rewritten for the 2025 season.
**
** 1. In SSMS...
** a. Turn on the option: Query Results, Sql Server, Results to Grid, Include column headers....
** b. Connect to usmidsql01.
** c. Run this script in the FAnalysis database.
** d. Right-click in the results grid, and choose Save Results As...
** 2. In a proper text editor, aka Neovim, remove all instances of NULL from the exported file, leaving nothing between the commas.
** 3. In DBeaver,
** a. Log into usmidsap01
** b. Navigate to the ubm.rlarp.osm_pool table
** c. Right-click, and choose Import Data.
** d. Follow the self-explanatory steps in the wizard. Make sure to choose the option to empty the table first.
** e. Verify the import worked correctly.
** f. Run the following statements to finish setting up the system.
** DELETE FROM rlarp.osm_log WHERE id > 1;
** ALTER SEQUENCE rlarp.osm_log_id_seq RESTART 1;
**
*******************************************************************************************************************************************
*******************************************************************************************************************************************
Baseline Data New Method:
Forecasting on Orders Basis
1 -- Pull 2023 Sales & Volumes + 2023 Promised Sales & Volumes
2 - Backout 2024 Open Orders --
3 -- Sum 1 and 2, Group By ShiptoGroup, Partgroup
4 - Pull 2019 Orders Group By ShipToGroup, Partgroup, OrderMonth
5 - Map 3 (total) to 4 (by order month)
ShipTo and Partgroup in both
* Shipto and Partgroup does not exist in 2019 --> Subtract from 2023 Ship 90
Exists in 2019, does not exists in 2023 -- > Ignore
On the Orders Worksheet
Show 2019 Orders as Reference
Rollup - As part of process.
*/
----------------------------------------------------------------------
--BASE DATA VALUES RECAST WITH Last Price Paid instead of Spot Price
---------------------------------------------------------------------
SELECT * INTO #BASE_DATA
FROM
( SELECT
[Bill-To] AS bill_cust_descr
,[Bill-To Group] AS billto_group
,[Ship-To] AS ship_cust_descr
,[Ship-To Group] AS shipto_group
,CASE WHEN [Quota Rep] LIKE '[0-9][0-9][0-9][0-9][0-9] -%' THEN LEFT([Quota Rep],5) ELSE NULL END AS [dsm]
,CASE WHEN [Quota Rep] LIKE '[0-9][0-9][0-9][0-9][0-9] -%' THEN SUBSTRING(RTRIM([Quota Rep]), 9, LEN([Quota Rep])-8) ELSE LTRIM(RTRIM([Quota Rep])) END AS [quota_rep_descr]
,[Director] AS [director]
,[Segment] AS [segm]
,CASE WHEN [Major Group] LIKE '610%' THEN 'Fiber' ELSE 'Plastic' END [substance]
,[Channel] AS [chan]
,[Channel Sub] AS [chansub]
,[Channel - Retail] AS [chan_retail]
,[Part Code] AS [part]
,[Part Group Descr] AS [part_descr]
,[Part Group] AS [part_group]
,[Branding Flag] AS [branding]
,LEFT([Major Group],5) + ' ' + [Major Group] AS [majg_descr]
,LEFT([Minor Group],5) + ' ' + [Minor Group] AS [ming_descr]
,LEFT([Major Sales Group],5) + ' ' + [Major Sales Group] AS [majs_descr]
,LEFT([Minor Sales Group],5) + ' ' + [Minor Sales Group] AS [mins_descr]
,[Order Date] AS [order_date]
,[Order Season] AS [order_season]
,[Order Month] AS [order_month]
,[Ship Date] AS [ship_date]
,[Ship Season] AS [ship_season]
,[Ship Month] AS [ship_month]
,[Request Date] AS [request_date]
,[Request Season] AS [request_season]
,[Request Month] AS [request_month]
,[Promo Code] AS [promo]
,[Financial Statement Line] as [fs_line]
,[Inventory Currency] as [r_currency]
,[Order Currency] as [c_currency]
,PRICE.LPP_loc * BASE.Units AS [value_loc]
,PRICE.LPP_USD * BASE.Units AS [value_usd]
,[Standard Cost Local - Historic] AS [cost_loc]
,[Std Cost USD - Historic] AS [cost_usd]
,[Units] AS [units]
,[Pounds] AS [pounds]
,'b24' AS [version]
,'copy' AS [iter]
,1 AS [logid]
,'baseline' AS [tag]
,'don''t undo' AS [comment]
,[Promise Month] AS [Promise Month]
,[Data Source] AS [Data Source]
,[Order Status] AS [Order Status]
,[Promise Season] AS [Promise Season]
FROM [FAnalysis].[RLARP].[osm_stack_pretty_wSTATUS] AS BASE
LEFT OUTER JOIN
(
SELECT shipto_group, [part_descr], /*[Order Number], */ [price_loc] AS [LPP_loc], [price_USD] AS [LPP_USD]
FROM
( SELECT
ROW_NUMBER() OVER (PARTITION BY [Ship-To Group], [Part Code Descr] ORDER BY [Order Date] DESC, [Order Number] DESC) AS LPP_RANK
-- ,[Order Date] AS [Order Date]
-- ,[Order Number] AS [Order Number]
,[Ship-To Group] AS shipto_group
,[Part Code Descr] AS [part_descr]
-- ,[value local] AS [value_loc]
-- ,[value usd] AS [value_usd]
-- ,[Units] AS [units]
,[Value Local] / NULLIF([Units],0) AS [price_loc]
,[Value USD] / NULLIF([Units],0) AS [price_USD]
FROM [FAnalysis].[RLARP].[osm_stack_pretty_wSTATUS]
WHERE
(
([Data Source] = 'Actual' AND [Order Status] = 'Open - Current' AND [Promise Season] >= 2023) OR
([Data Source] = 'Actual' AND [Ship Season] = 2023)
) AND
[Ship-To] IS NOT NULL AND
[Ship-To Group] IS NOT NULL AND
[Order Date] IS NOT NULL
--ORDER BY [shipto_group], [part_descr], LPP_RANK ASC
) AS LPP_RESULT
WHERE LPP_RESULT.LPP_RANK = 1
) PRICE
ON BASE.[Ship-To Group] = PRICE.shipto_group AND
BASE.[Part Code Descr] = PRICE.part_descr
WHERE
(
(BASE.[Data Source] = 'Actual' AND BASE.[Order Status] = 'Open - Current' AND BASE.[Promise Season] >= 2023) OR
(BASE.[Data Source] = 'Actual' AND BASE.[Ship Season] = 2023)
) AND
BASE.[Ship-To] IS NOT NULL AND
BASE.[Ship-To Group] IS NOT NULL
) AS A
CREATE CLUSTERED INDEX IDX_CBASE_DATA_STG ON #BASE_DATA(shipto_group)
CREATE INDEX IDX_CFYBASE_DATA_PG ON #BASE_DATA(part_group)
/* Backout orders that already have been placed for FY2024 from the Order Forecast Baseline */
UPDATE #BASE_DATA SET
[value_loc] = -1 * [value_loc]
,[value_usd] = -1 * [value_usd]
,[cost_loc] = -1 * [cost_loc]
,[cost_usd] = -1 * [cost_usd]
,[units] = -1 * [Units]
,[pounds] = -1 * [Pounds]
WHERE [Data Source] = 'Actual' AND [Order Status] = 'Open - Current' AND [Promise Season] > 2023
----------------------------------------------------------------------------------------------------
--CREATE TEMP TABLES: * Shipto and Partgroup does not exist in 2019 --> Subtract from 2023 Ship 90
--SELECT #BASE_DATA. FROM #BASE_DATA
----------------------------------------------------------------------------------------------------
SELECT * INTO #FY2023 FROM
( SELECT
[shipto_group]
,[part_group]
,[ship_month]
,[value_loc]
,[value_usd]
,[cost_loc]
,[cost_usd]
,[units]
,[pounds]
,[Promise Month]
,CASE
WHEN A.ship_month IS NULL THEN
CASE
WHEN CAST(LEFT(A.[Promise Month],2) AS INT) - 3 < 1 THEN CAST(LEFT(A.[Promise Month],2) AS INT) + 9
ELSE CAST(LEFT(A.[Promise Month],2) AS INT) - 3
END --2023 Promised, Not Shipped
ELSE
CASE
WHEN CAST(LEFT(A.ship_month,2) AS INT) - 3 < 1 THEN CAST(LEFT(A.ship_month,2) AS INT) + 9
ELSE CAST(LEFT(A.ship_month,2) AS INT) - 3
END
END AS order_month_idx
FROM
( SELECT
shipto_group
,[part_group]
,[ship_month]
,SUM([value_loc]) AS [value_loc]
,SUM([value_usd]) AS [value_usd]
,SUM([cost_loc]) AS [cost_loc]
,SUM([cost_usd]) AS [cost_usd]
,SUM([units]) AS [units]
,SUM([pounds]) AS [pounds]
,MAX([Promise Month]) AS [Promise Month]
FROM #BASE_DATA
WHERE
(
([Data Source] = 'Actual' AND [ship_season] = 2023) OR
([Data Source] = 'Actual' AND [Order Status] = 'Open - Current' AND [Promise Season] = 2023)
) AND
[shipto_group] IS NOT NULL AND
[part_group] <> ''
GROUP BY [shipto_group], [part_group], [ship_month]
) AS A
) AS FY23
CREATE CLUSTERED INDEX IDX_CFY2023_STG ON #FY2023(shipto_group)
CREATE INDEX IDX_CFY2023_PG ON #FY2023(part_group)
SELECT * INTO #FY2019 FROM
( SELECT
[Ship-To Group] AS shipto_group
,[Part Group] AS [part_group]
,MAX([Order Month]) AS [order_month]
FROM [FAnalysis].[RLARP].[osm_stack_pretty_wSTATUS]
WHERE
[Data Source] = 'Actual' AND
[Order Season] = 2019 AND
[Ship-To Group] IS NOT NULL AND
[part group] <> ''
GROUP BY [Ship-To Group], [Part Group]
) AS FY19
CREATE CLUSTERED INDEX IDX_CFY2019_STG ON #FY2019(shipto_group)
CREATE INDEX IDX_CFY2019_PG ON #FY2019(part_group)
------------------------
-- BEGIN MASTER QUERY
-------------------------
SELECT
CASE
WHEN DETAIL.[ship_season] IS NULL THEN CAST(DETAIL.[promise_season] % 100 AS varchar) + LEFT(DETAIL.[promise_month], 2)
ELSE CAST(DETAIL.[ship_season] % 100 AS varchar) + LEFT(DETAIL.[ship_month], 2)
END AS [fspr]
,NULL as [plnt]
,DETAIL.[promo]
,NULL as [terms]
,DETAIL.bill_cust_descr
,DETAIL.ship_cust_descr
,DETAIL.[dsm]
,DETAIL.[quota_rep_descr]
,DETAIL.[director]
,DETAIL.billto_group
,DETAIL.shipto_group
,DETAIL.[chan]
,DETAIL.[chansub]
,DETAIL.[chan_retail]
,DETAIL.[part]
,DETAIL.[part_descr]
,DETAIL.[part_group]
,DETAIL.[branding]
,DETAIL.[majg_descr]
,DETAIL.[ming_descr]
,DETAIL.[majs_descr]
,DETAIL.[mins_descr]
,DETAIL.[segm]
,DETAIL.[substance]
,DETAIL.[fs_line]
,DETAIL.[r_currency]
,DETAIL.[value_usd]/nullif(DETAIL.[value_loc],0) as [r_rate]
,DETAIL.[c_currency]
,DETAIL.[cost_usd]/nullif(DETAIL.[cost_loc],0) as [c_rate]
,ROUND(DETAIL.[Units] * MAPPED.Distribution_Factor,0) AS [units]
,DETAIL.[value_loc] * MAPPED.Distribution_Factor AS [value_loc]
,DETAIL.[value_usd] * MAPPED.Distribution_Factor AS [value_usd]
,DETAIL.[cost_loc] * MAPPED.Distribution_Factor AS [cost_loc]
,DETAIL.[cost_usd] * MAPPED.Distribution_Factor AS [cost_usd]
,'CLOSED' as [calc_status]
,'SHIPMENT' as [flag]
,DETAIL.[order_date]
,MAPPED.[order_month]
,2024 AS [order_season]
,DETAIL.[request_date]
,DETAIL.[request_month]
,DETAIL.[request_season]
,DETAIL.[ship_date]
,DETAIL.[ship_month]
,DETAIL.[ship_season]
,[version]
,'copy' AS [iter] -- {'copy'--> baseline data, 'actuals' --> reference data}
,[logid]
,[tag]
,[comment]
,'build_pool' as [module]
,DETAIL.[Pounds] * MAPPED.Distribution_Factor AS [pounds]
FROM
( SELECT
FY23_SALES.shipto_group
,FY23_SALES.part_group
,FY19_ORDERS.order_month AS order_month
,FY23_SALES.value_loc * FY19_ORDERS.Distribution_Factor AS value_loc
,FY23_SALES.value_usd * FY19_ORDERS.Distribution_Factor AS value_usd
,FY23_SALES.cost_loc * FY19_ORDERS.Distribution_Factor AS cost_loc
,FY23_SALES.cost_usd * FY19_ORDERS.Distribution_Factor AS cost_usd
,FY23_SALES.units * FY19_ORDERS.Distribution_Factor AS units
,FY23_SALES.pounds * FY19_ORDERS.Distribution_Factor AS pounds
,FY19_ORDERS.Distribution_Factor AS Distribution_Factor
FROM
( SELECT
shipto_group
,[part_group]
,SUM([value_loc]) AS [value_loc]
,SUM([value_usd]) AS [value_usd]
,SUM([cost_loc]) AS [cost_loc]
,SUM([cost_usd]) AS [cost_usd]
,SUM([units]) AS [units]
,SUM([pounds]) AS [pounds]
FROM
( SELECT /* SHIPPED IN 2023 */
bill_cust_descr
,billto_group
,ship_cust_descr
,[shipto_group]
,[quota_rep_descr]
,[director]
,[segm]
,[substance]
,[chan]
,[chansub]
,[part_descr]
,[part_group]
,[branding]
,[majg_descr]
,[ming_descr]
,[majs_descr]
,[mins_descr]
,[order_season]
,[order_month]
,[ship_date]
,[ship_season]
,[ship_month]
,[request_season]
,[request_month]
,[promo]
,[value_loc]
,[value_usd]
,[cost_loc]
,[cost_usd]
,[units]
,[pounds]
,[version]
,[iter]
,[logid]
,[tag]
,[comment]
FROM #BASE_DATA
WHERE [Data Source] = 'Actual' AND [ship_season] = 2023
UNION ALL
SELECT /* OPEN Promised 2023*/
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,[quota_rep_descr]
,[director]
,[segm]
,[substance]
,[chan]
,[chansub]
,[part_descr]
,[part_group]
,[branding]
,[majg_descr]
,[ming_descr]
,[majs_descr]
,[mins_descr]
,[order_season]
,[order_month]
,[ship_date]
,[ship_season]
,[ship_month]
,[request_season]
,[request_month]
,[promo]
,[value_loc]
,[value_usd]
,[cost_loc]
,[cost_usd]
,[units]
,[pounds]
,[version]
,[iter]
,[logid]
,[tag]
,[comment]
FROM #BASE_DATA
WHERE [Data Source] = 'Actual' AND [Order Status] = 'Open - Current' AND [Promise Season] = 2023
UNION ALL
SELECT /* OPEN 2024 AND LATER */
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,[quota_rep_descr]
,[director]
,[segm]
,[substance]
,[chan]
,[chansub]
,[part_descr]
,[part_group]
,[branding]
,[majg_descr]
,[ming_descr]
,[majs_descr]
,[mins_descr]
,[order_season]
,[order_month]
,[ship_date]
,[ship_season]
,[ship_month]
,[request_season]
,[request_month]
,[promo]
,[value_loc] AS [value_loc] /* These values are negative in #BASE_DATA to backout order that already have been placed for FY2024 */
,[value_usd] AS [value_usd]
,[cost_loc] AS [cost_loc]
,[cost_usd] AS [cost_usd]
,[Units] AS [units]
,[Pounds] AS [pounds]
,[version]
,[iter]
,[logid]
,[tag]
,[comment]
FROM #BASE_DATA
WHERE [Data Source] = 'Actual' AND [Order Status] = 'Open - Current' AND [Promise Season] > 2023
) AS A
WHERE part_group <>'' AND shipto_group IS NOT NULL
GROUP BY A.shipto_group, A.part_group
) AS FY23_SALES
LEFT OUTER JOIN
( SELECT * /* 4 - Pull 2019 Orders Group By ShipToGroup, Partgroup, OrderMonth Distribution */
FROM
( SELECT
[shipto_group]
,[part_group]
,[order_month]
,SUM([value_loc]) AS [value_loc]
,SUM([value_usd]) AS [value_usd]
,SUM([cost_loc]) AS [cost_loc]
,SUM([cost_usd]) AS [cost_usd]
,SUM([units]) AS [units]
,SUM([pounds]) AS [pounds]
,SUM([Distribution_Factor]) AS [Distribution_Factor]
FROM
( SELECT /* 2019 Orders*/
CASE
WHEN SUM([units]) OVER (Partition by [Ship-To Group], [Part Group]) <> 0 THEN [units] / SUM([units]) OVER (Partition by [Ship-To Group], [Part Group])
ELSE NULL
END AS [Distribution_Factor]
,[Bill-To] AS bill_cust_descr
,[Bill-To Group] AS billto_group
,[Ship-To] AS ship_cust_descr
,[Ship-To Group] AS shipto_group
,CASE WHEN Right(Left([Quota Rep], 7), 1) = '-' THEN RIGHT(LTRIM(RTRIM([Quota Rep])), Len([Quota Rep]) - 7) ELSE LTRIM(RTRIM([Quota Rep])) END AS [quota_rep_descr]
,[Director] AS [director]
,[Segment] AS [segm]
,CASE WHEN [Major Group] LIKE '610%' THEN 'Fiber' ELSE 'Plastic' END [substance]
,[Channel] AS [chan]
,[Channel Sub] AS [chansub]
,[Part Group Descr] AS [part_descr]
,[Part Group] AS [part_group]
,[Branding Flag] AS [branding]
,LEFT([Major Group],5) + ' ' + [Major Group] AS [majg_descr]
,LEFT([Minor Group],5) + ' ' + [Minor Group] AS [ming_descr]
,LEFT([Major Sales Group],5) + ' ' + [Major Sales Group] AS [majs_descr]
,LEFT([Minor Sales Group],5) + ' ' + [Minor Sales Group] AS [mins_descr]
,[Order Season] AS [order_season]
,[Order Month] AS [order_month]
,[Ship Season] AS [ship_season]
,[Ship Month] AS [ship_month]
,[Request Season] AS [request_season]
,[Request Month] AS [request_month]
,[Promo Code] AS [promo]
,[value local] AS [value_loc]
,[value usd] AS [value_usd]
,[Standard Cost Local - Historic] AS [cost_loc]
,[Std Cost USD - Historic] AS [cost_usd]
,[Units] AS [units]
,[Pounds] AS [pounds]
,'b24' AS [version]
,'copy' AS [iter]
,1 AS [logid]
,'baseline' AS [tag]
,'don''t undo' AS [comment]
FROM [FAnalysis].[RLARP].[osm_stack_pretty_wSTATUS]
WHERE [Data Source] = 'Actual' AND [Order Season] = 2019
) AS B
GROUP BY B.shipto_group, B.part_group, B.order_month
) AS C
--ORDER BY shipto_group, part_group, order_month
) AS FY19_ORDERS
ON FY23_SALES.shipto_group = FY19_ORDERS.shipto_group AND FY23_SALES.part_group = FY19_ORDERS.part_group
WHERE FY19_ORDERS.Order_month is NOT NULL
--ORDER BY part_group ASC, order_month ASC
UNION ALL
SELECT
C.shipto_group
,C.part_group
,D.order_month
,C.value_loc AS value_loc
,C.value_usd AS value_usd
,C.cost_loc AS cost_loc
,C.cost_usd AS cost_usd
,C.units AS units
,C.pounds AS pounds
--,1 AS Distribution_Factor
--,CASE WHEN SUM(C.[units]) OVER (Partition by [C.shipto_group], [C.part_group]) <> 0 THEN C.[units] / SUM(C.[units]) OVER (Partition by [C.shipto_group], [C.part_group]) ELSE NULL END AS [Distribution_Factor]
,C.Distribution_Factor AS Distribution_Factor
FROM
( SELECT
A.shipto_group
,A.part_group
,A.order_month_idx
,A.value_loc AS value_loc
,A.value_usd AS value_usd
,A.cost_loc AS cost_loc
,A.cost_usd AS cost_usd
,A.units AS units
,A.pounds AS pounds
,CASE
WHEN SUM(A.[units]) OVER (Partition by A.[shipto_group], A.[part_group]) <> 0 THEN A.[units] / SUM(A.[units]) OVER (Partition by A.[shipto_group], A.[part_group])
ELSE NULL
END AS [Distribution_Factor]
FROM #FY2023 A
LEFT OUTER JOIN #FY2019 B
ON A.shipto_group = B.shipto_group AND A.part_group = B.part_group
WHERE
b.[order_month] IS NULL AND
A.shipto_group IS NOT NULL
) AS C
INNER JOIN
( SELECT DISTINCT CAST(Left([order_month],2) AS INT) AS [order_month_idx], [order_month]
FROM #FY2019
) AS D ON C.order_month_idx = D.Order_month_idx
) AS MAPPED
INNER JOIN
( SELECT
MAX([bill_cust_descr]) AS bill_cust_descr
,MAX([billto_group]) AS billto_group
,MAX([ship_cust_descr]) AS ship_cust_descr
,shipto_group
,MAX([dsm]) AS dsm
,MAX([quota_rep_descr]) AS quota_rep_descr
,MAX([director]) AS [director]
,MAX([segm]) AS [segm]
,MAX([substance]) AS [substance]
,MAX([chan]) AS [chan]
,MAX([chansub]) AS [chansub]
,MAX([chan_retail]) AS [chan_retail]
,MAX([part]) AS [part]
,[part_descr]
,[part_group]
,MAX([branding]) AS [branding]
,MAX([majg_descr]) AS [majg_descr]
,MAX([ming_descr]) AS [ming_descr]
,MAX([majs_descr]) AS [majs_descr]
,MAX([mins_descr]) AS [mins_descr]
,MAX([order_date]) AS [order_date]
,MAX([order_season]) AS [order_season]
,MAX([order_month]) AS [order_month]
,MAX([ship_date]) AS [ship_date]
,MAX([ship_season]) AS [ship_season]
,MAX([ship_month]) AS [ship_month]
,MAX([request_date]) AS [request_date]
,MAX([request_season]) AS [request_season]
,MAX([request_month]) AS [request_month]
,MAX([promo]) AS [promo]
,MAX([fs_line]) as [fs_line]
,MAX([r_currency]) as [r_currency]
,MAX([c_currency]) as [c_currency]
,SUM([value_loc]) AS [value_loc]
,SUM([value_usd]) AS [value_usd]
,SUM([cost_loc]) AS [cost_loc]
,SUM([cost_usd]) AS [cost_usd]
,SUM([units]) AS [units]
,SUM([pounds]) AS [pounds]
,MAX([version]) AS [version]
,MAX([iter]) AS [iter]
,MAX([logid]) AS [logid]
,MAX([tag]) AS [tag]
,MAX([comment]) AS [comment]
,MAX([Promise Month]) AS [promise_month]
,MAX([Data Source]) AS [Data Source]
,MAX([Order Status])AS [Order Status]
,MAX([Promise Season]) AS [promise_season]
FROM #BASE_DATA
GROUP BY shipto_group, /*[part],*/ [part_descr], [part_group]
) AS DETAIL
ON MAPPED.shipto_group = DETAIL.shipto_group AND MAPPED.part_group = DETAIL.part_group
-- ORDER BY shipto_group, part_group, order_season, order_month
--
UNION ALL
--
-- 2019 ORDERS & 2022 ORDERS for Reference --
SELECT
CASE
WHEN [Ship Season] IS NULL THEN CAST([Promise Season] % 100 AS varchar) + LEFT([Promise Month], 2)
ELSE CAST([Ship Season] % 100 AS varchar) + LEFT([Ship Month], 2)
END AS [fspr]
,NULL as [plnt]
,[Promo Code] AS [promo]
,NULL as [terms]
,[Bill-To] AS bill_cust_descr
,[Ship-To] AS ship_cust_descr
,CASE WHEN [Quota Rep] LIKE '[0-9][0-9][0-9][0-9][0-9] -%' THEN LEFT([Quota Rep],5) ELSE NULL END AS [dsm]
,CASE WHEN [Quota Rep] LIKE '[0-9][0-9][0-9][0-9][0-9] -%' THEN SUBSTRING(RTRIM([Quota Rep]), 9, LEN([Quota Rep])-8) ELSE LTRIM(RTRIM([Quota Rep])) END AS [quota_rep_descr]
,[Director] AS [director]
,[Bill-To Group] AS billto_group
,[Ship-To Group] AS shipto_group
,[Channel] AS [chan]
,[Channel Sub] AS [chansub]
,[Channel - Retail] AS [chan_retail]
,[Part Code] AS [part]
,[Part Group Descr] AS [part_descr]
,[Part Group] AS [part_group]
,[Branding Flag] AS [branding]
,LEFT([Major Group],5) + ' ' + [Major Group] AS [majg_descr]
,LEFT([Minor Group],5) + ' ' + [Minor Group] AS [ming_descr]
,LEFT([Major Sales Group],5) + ' ' + [Major Sales Group] AS [majs_descr]
,LEFT([Minor Sales Group],5) + ' ' + [Minor Sales Group] AS [mins_descr]
,[Segment] AS [segm]
,CASE WHEN [Major Group] LIKE '610%' THEN 'Fiber' ELSE 'Plastic' END [substance]
,[Financial Statement Line] as [fs_line]
,[Inventory Currency] as [r_currency]
,[Value USD]/nullif([Value Local],0) as [r_rate]
,[Order Currency] as [c_currency]
,[Std Cost USD - Current]/nullif([Std Cost Local - Current],0) as [c_rate]
,[Units] AS [units]
,[value local] AS [value_loc]
,[value usd] AS [value_usd]
,[Standard Cost Local - Historic] AS [cost_loc]
,[Std Cost USD - Historic] AS [cost_usd]
,'CLOSED' as [calc_status]
,'SHIPMENT' as [flag]
,[Order Date] AS [order_date]
,[Order Month] AS [order_month]
,[Order Season] AS [order_season]
,[Request Date] AS [request_date]
,[Request Month] AS [request_month]
,[Request Season] AS [request_season]
,[Ship Date] AS [ship_date]
,[Ship Month] AS [ship_month]
,[Ship Season] AS [ship_season]
,'b24' AS [version]
,'actuals' AS [iter]
,1 AS [logid]
,'baseline' AS [tag]
,'don''t undo' AS [comment]
,'build_pool' as [module]
,[Pounds] AS [pounds]
FROM [FAnalysis].[RLARP].[osm_stack_pretty_wSTATUS]
WHERE ([Data Source] = 'Actual' AND [Order Season] IN(2019,2022)) AND [Ship-To Group] IS NOT NULL AND [part group] <> '' --jps04/25/2023 Included 2022 Data for refernece per users request
--
UNION ALL
--
-- OPEN ORDERS GOING INTO THE BEGINNING OF 2024 SEASON --
-- THESE WERE BACKED OUT OF THE 2024 BASELINE --
SELECT
CASE
WHEN [Ship Season] IS NULL THEN CAST([Promise Season] % 100 AS varchar) + LEFT([Promise Month], 2)
ELSE CAST([Ship Season] % 100 AS varchar) + LEFT([Ship Month], 2)
END AS [fspr]
,NULL as [plnt]
,[Promo Code] AS [promo]
,NULL as [terms]
,[Bill-To] AS bill_cust_descr
,[Ship-To] AS ship_cust_descr
,CASE WHEN [Quota Rep] LIKE '[0-9][0-9][0-9][0-9][0-9] -%' THEN LEFT([Quota Rep],5) ELSE NULL END AS [dsm]
,CASE WHEN [Quota Rep] LIKE '[0-9][0-9][0-9][0-9][0-9] -%' THEN SUBSTRING(RTRIM([Quota Rep]), 9, LEN([Quota Rep])-8) ELSE LTRIM(RTRIM([Quota Rep])) END AS [quota_rep_descr]
,[Director] AS [director]
,[Bill-To Group] AS billto_group
,[Ship-To Group] AS shipto_group
,[Channel] AS [chan]
,[Channel Sub] AS [chansub]
,[Channel - Retail] AS [chan_retail]
,[Part Code] AS [part]
,[Part Group Descr] AS [part_descr]
,[Part Group] AS [part_group]
,[Branding Flag] AS [branding]
,LEFT([Major Group],5) + ' ' + [Major Group] AS [majg_descr]
,LEFT([Minor Group],5) + ' ' + [Minor Group] AS [ming_descr]
,LEFT([Major Sales Group],5) + ' ' + [Major Sales Group] AS [majs_descr]
,LEFT([Minor Sales Group],5) + ' ' + [Minor Sales Group] AS [mins_descr]
,[Segment] AS [segm]
,CASE WHEN [Major Group] LIKE '610%' THEN 'Fiber' ELSE 'Plastic' END [substance]
,[Financial Statement Line] as [fs_line]
,[Inventory Currency] as [r_currency]
,[Value USD]/nullif([Value Local],0) as [r_rate]
,[Order Currency] as [c_currency]
,[Std Cost USD - Current]/nullif([Std Cost Local - Current],0) as [c_rate]
,[Units] AS [units]
,[value local] AS [value_loc]
,[value usd] AS [value_usd]
,[Standard Cost Local - Historic] AS [cost_loc]
,[Std Cost USD - Historic] AS [cost_usd]
,'BACKORDER' as [calc_status]
,'REMAINDER' as [flag]
,[Order Date] AS [order_date]
,[Order Month] AS [order_month]
,'2024' AS [order_season] --jps04/25/2023 Changed order season to 2024 so these show up under 2024 in pivot table
,[Request Date] AS [request_date]
,[Request Month] AS [request_month]
,[Request Season] AS [request_season]
,[Ship Date] AS [ship_date]
,[Ship Month] AS [ship_month]
,[Ship Season] AS [ship_season]
,'b24' AS [version]
,'actuals' AS [iter]
,1 AS [logid]
,'open-orders' AS [tag] --jps04/25/2023 Change to 'Open-orders' to stinguish these records from the 2024 baseline records
,'don''t undo' AS [comment]
,'build_pool' as [module]
,[Pounds] AS [pounds]
FROM [FAnalysis].[RLARP].[osm_stack_pretty_wSTATUS]
WHERE [Data Source] = 'Actual' AND [Order Status] = 'Open - Current' AND [Promise Season] > 2023
--- CLEANUP --
DROP TABLE #FY2019
DROP TABLE #FY2023
DROP TABLE #BASE_DATA
/*
/* OUTPUTS FOR DEBUG AND VALIDATION*/
-- Select * FROM #BASE_DATA
-- ORDER BY shipto_group, part_group
--
-- Select * FROM #FY2019
-- ORDER BY shipto_group, part_group
--
-- SELECT
-- [shipto_group]
-- ,[part_group]
-- ,[order_month]
-- ,SUM([value_loc]) AS [value_loc]
-- ,SUM([value_usd]) AS [value_usd]
-- ,SUM([cost_loc]) AS [cost_loc]
-- ,SUM([cost_usd]) AS [cost_usd]
-- ,SUM([units]) AS [units]
-- ,SUM([pounds]) AS [pounds]
-- ,SUM([Distribution_Factor]) AS [Distribution_Factor]
-- FROM(
-- Select /* 2019 Orders*/
-- CASE WHEN SUM([units]) OVER (Partition by [Ship-To Group], [Part Group]) <> 0 THEN [units] / SUM([units]) OVER (Partition by [Ship-To Group], [Part Group]) ELSE NULL END AS [Distribution_Factor]
-- ,[Bill-To] AS bill_cust_descr
-- ,[Bill-To Group] AS billto_group
-- ,[Ship-To] AS ship_cust_descr
-- ,[Ship-To Group] AS shipto_group
-- ,CASE WHEN Right(Left([Quota Rep], 7), 1) = '-' THEN RIGHT(LTRIM(RTRIM([Quota Rep])), Len([Quota Rep]) - 7) ELSE LTRIM(RTRIM([Quota Rep])) END AS [quota_rep_descr]
-- ,[Director] AS [director]
-- ,[Segment] AS [segm]
-- ,CASE WHEN [Major Group] LIKE '610%' THEN 'Fiber' ELSE 'Plastic' END [substance]
-- ,[Channel] AS [chan]
-- ,[Channel Sub] AS [chansub]
-- ,[Part Group Descr] AS [part_descr]
-- ,[Part Group] AS [part_group]
-- ,[Branding Flag] AS [branding]
-- ,LEFT([Major Group],5) + ' ' + [Major Group] AS [majg_descr]
-- ,LEFT([Minor Group],5) + ' ' + [Minor Group] AS [ming_descr]
-- ,LEFT([Major Sales Group],5) + ' ' + [Major Sales Group] AS [majs_descr]
-- ,LEFT([Minor Sales Group],5) + ' ' + [Minor Sales Group] AS [mins_descr]
-- ,[Order Season] AS [order_season]
-- ,[Order Month] AS [order_month]
-- ,[Ship Season] AS [ship_season]
-- ,[Ship Month] AS [ship_month]
-- ,[Request Season] AS [request_season]
-- ,[Request Month] AS [request_month]
-- ,[Promo Code] AS [promo]
-- ,[value local] AS [value_loc]
-- ,[value usd] AS [value_usd]
-- ,[Standard Cost Local - Historic] AS [cost_loc]
-- ,[Std Cost USD - Historic] AS [cost_usd]
-- ,[Units] AS [units]
-- ,[Pounds] AS [pounds]
-- ,'b24' AS [version]
-- ,'actuals' AS [iter]
-- ,1 AS [logid]
-- ,'baseline' AS [tag]
-- ,'don''t undo' AS [comment]
-- FROM [FAnalysis].[RLARP].[osm_stack_pretty_wSTATUS]
-- WHERE [Data Source] = 'Actual' AND [Order Season] = 2019
-- ) AS B
-- GROUP BY B.shipto_group, B.part_group, B.order_month
-- ORDER BY shipto_group, part_group, order_month
--
*/

View File

@ -77,7 +77,7 @@ server.get('/get_pool', bodyParser.json(), function(req, res) {
var path = './route_sql/get_pool.sql';
var callback = function(arg) {
sql = arg;
console.log(new Date().toISOString() + " GET (pool) file: " + path + "-._.".repeat(20));
console.log(new Date().toISOString() + "-------------------------get pool:----------------------------");
console.log(req.body.quota_rep);
sql = sql.replace("rep_replace", req.body.quota_rep);
console.log(sql);
@ -124,7 +124,7 @@ server.get('/scenario_package', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + " GET (scenario package) file: " + path + "-._.".repeat(20))
console.log(new Date().toISOString() + "-------------------------get scenario:------------------------------")
console.log(req.body);
//parse the where clause into the main sql statement
sql = sql.replace(new RegExp("where_clause", 'g'), w)
@ -163,7 +163,7 @@ server.get('/swap_fit', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + "get swap fit: " + path + "-._.".repeat(20))
console.log(new Date().toISOString() + "-------------------------get swap fit:------------------------------")
console.log(req.body);
//parse the where clause into the main sql statement
sql = sql.replace(new RegExp("where_clause", 'g'), w);
@ -203,7 +203,7 @@ server.post('/swap', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + "post swap: " + path + "-._.".repeat(20))
console.log(new Date().toISOString() + "-------------------------post swap:------------------------------")
console.log(req.body);
//parse the where clause into the main sql statement
sql = sql.replace(new RegExp("where_clause", 'g'), w);
@ -246,7 +246,7 @@ server.post('/cust_swap', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + " POST (cust swap) file: " + path + "-._.".repeat(20))
console.log(new Date().toISOString() + "-------------------------cust swap:------------------------------")
console.log(req.body);
//parse the where clause into the main sql statement
sql = sql.replace(new RegExp("where_clause", 'g'), w);
@ -282,7 +282,7 @@ server.get('/list_changes', bodyParser.json(), function(req, res) {
var callback = function(arg) {
sql = arg;
console.log(new Date().toISOString() + "GET (list changes) file: " + path + "-._.".repeat(20))
console.log(new Date().toISOString() + "-------------------------list changes:------------------------------")
console.log(req.body);
//parse the where clause into the main sql statement
sql = sql.replace(new RegExp("replace_user", 'g'), req.body.scenario.quota_rep_descr)
@ -313,7 +313,7 @@ server.get('/undo_change', bodyParser.json(), function(req, res) {
var callback = function(arg) {
sql = arg;
console.log(new Date().toISOString() + " GET (undo change) file: " + path + "-._.".repeat(20))
console.log(new Date().toISOString() + "-------------------------undo change:------------------------------")
console.log(req.body);
//parse the where clause into the main sql statement
sql = sql.replace(new RegExp("replace_id", 'g'), JSON.stringify(req.body.logid))
@ -352,7 +352,7 @@ server.post('/addmonth_v', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + " POST (add month volume) file: " + path + "-._.".repeat(20));
console.log(new Date().toISOString() + "-----------------------------add month volume:---------------------------------");
req.body.stamp = new Date().toISOString()
console.log(req.body);
//console.log(args);
@ -386,7 +386,7 @@ server.post('/addmonth_vp', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + " POST (add month volume and price) file: " + path + "-._.".repeat(20));
console.log(new Date().toISOString() + "------------------add month volume and price:-------------------");
req.body.stamp = new Date().toISOString()
console.log(req.body);
//console.log(args);
@ -429,7 +429,7 @@ server.post('/scale_v', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + " POST (scale volume) file: " + path + "-._.".repeat(20));
console.log(new Date().toISOString() + "-----------------------scale volume:------------------------------");
req.body.stamp = new Date().toISOString()
console.log(req.body);
//console.log(args);
@ -470,7 +470,7 @@ server.post('/scale_p', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + " POST (scale price) file: " + path + "-._.".repeat(20));
console.log(new Date().toISOString() + "--------------------scale price:-------------------");
req.body.stamp = new Date().toISOString()
console.log(req.body);
//console.log(args);
@ -511,7 +511,7 @@ server.post('/scale_vp', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + " POST (scale volume & price) file: " + path + "-._.".repeat(20));
console.log(new Date().toISOString() + "--------------------scale volume & price:-------------------");
req.body.stamp = new Date().toISOString()
console.log(req.body);
//console.log(args);
@ -553,7 +553,7 @@ server.post('/scale_vp_sales', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + " POST (scale volume & price sales) file: " + path + "-._.".repeat(20));
console.log(new Date().toISOString() + "--------------------scale volume & price sales:-------------------");
req.body.stamp = new Date().toISOString()
console.log(req.body);
//console.log(args);
@ -595,7 +595,7 @@ server.post('/new_part', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + " POST (new part) file: " + path + "-._.".repeat(20));
console.log(new Date().toISOString() + "--------------------new part:-------------------");
req.body.stamp = new Date().toISOString()
console.log(req.body);
//console.log(args);
@ -639,7 +639,7 @@ server.post('/new_basket', bodyParser.json(), function(req, res) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + " POST (new basket) file: " + path + "-._.".repeat(20));
console.log(new Date().toISOString() + "--------------------new basket:-------------------");
req.body.stamp = new Date().toISOString()
console.log(req.body);
//console.log(args);
@ -696,7 +696,7 @@ function build_where(req, c, w, d, args) {
if (req.body.stamp) {
w = w +
`
AND order_date >= least('` + req.body.stamp + "'::date,'2022-06-01')";
AND order_date >= least('` + req.body.stamp + "'::date,'2021-06-01')";
}
return { c, w, d };
}

View File

@ -224,7 +224,6 @@ SELECT
,sum(coalesce(o.value_usd,0)) value_usd
,sum(coalesce(o.cost_loc,0)) cost_loc
,sum(coalesce(o.cost_usd,0)) cost_usd
,sum(coalesce(o.pounds,0)) pounds
,o.calc_status
,o.flag
FROM
@ -339,7 +338,6 @@ SELECT
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
,round(b.pounds*s.factor*m.momix, 2) pounds
FROM
basemix b
CROSS JOIN vscale s
@ -430,7 +428,6 @@ SELECT
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
,0::numeric pounds
FROM
volume b
CROSS JOIN pscale p
@ -484,7 +481,6 @@ FROM
,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd
,sum(units) units
,sum(pounds) pounds
FROM
ins
GROUP BY

View File

@ -1,92 +1,91 @@
WITH rows AS (
SELECT
---------customer info-----------------
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director
,segm
,substance
,chan
,chansub
---------product info------------------
,majg_descr
,ming_descr
,majs_descr
,mins_descr
--,brand
--,part_family
,part_group
,branding
--,color
,part_descr
---------dates-------------------------
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
--------values-------------------------
,sum(value_loc) value_loc
,sum(value_usd) value_usd
,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd
,sum(units) units
,sum(pounds) pounds
,version
,iter
,logid
,tag
,comment
FROM
rlarp.osm_pool
WHERE
quota_rep_descr = 'rep_replace'
GROUP BY
---------customer info-----------------
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director
,segm
,substance
,chan
,chansub
---------product info------------------
,majg_descr
,ming_descr
,majs_descr
,mins_descr
--,brand
--,part_family
,part_group
,branding
--,color
,part_descr
---------dates-------------------------
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
,logid
,tag
,comment
,substance
ORDER BY
logid ASC
)
SELECT
json_agg(row_to_json(rows)) x
FROM
rows
WITH rows AS (
SELECT
---------customer info-----------------
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director
,segm
,substance
,chan
,chansub
---------product info------------------
,majg_descr
,ming_descr
,majs_descr
,mins_descr
--,brand
--,part_family
,part_group
,branding
--,color
,part_descr
---------dates-------------------------
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
--------values-------------------------
,sum(value_loc) value_loc
,sum(value_usd) value_usd
,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd
,sum(units) units
,version
,iter
,logid
,tag
,comment
FROM
rlarp.osm_pool
WHERE
quota_rep_descr = 'rep_replace'
GROUP BY
---------customer info-----------------
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director
,segm
,substance
,chan
,chansub
---------product info------------------
,majg_descr
,ming_descr
,majs_descr
,mins_descr
--,brand
--,part_family
,part_group
,branding
--,color
,part_descr
---------dates-------------------------
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
,logid
,tag
,comment
,substance
ORDER BY
logid ASC
)
SELECT
json_agg(row_to_json(rows)) x
FROM
rows

View File

@ -339,7 +339,6 @@ SELECT
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
,round(b.units * i.nwht * CASE i.nwun WHEN 'KG' THEN 2.2046 ELSE 1 END, 2) pounds
FROM
basemix b
CROSS JOIN log
@ -355,11 +354,11 @@ FROM
LEFT OUTER JOIN rlarp.repc r ON
r.rcode = CASE WHEN i.ming = 'B52' THEN 'PW' ELSE
--if the gl expense code is 1RE use the retail rep assigned to the bill-to customer if available
CASE WHEN COALESCE(seg.segm,'') = 'Retail' AND COALESCE((SELECT currep FROM lgpgm.usrcust where cucust = bc.bvcust),'') <> ''
THEN
CASE WHEN COALESCE(seg.segm,'') = 'Retail' AND COALESCE((SELECT currep FROM lgpgm.usrcust where cucust = bc.bvcust),'') <> ''
THEN
(SELECT currep FROM lgpgm.usrcust where cucust = bc.bvcust)
--default logic
ELSE
ELSE
CASE SUBSTR(bc.bvclas,2,3)
WHEN 'DIS' THEN sc.bvsalm
ELSE bc.bvsalm
@ -436,7 +435,6 @@ FROM
,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd
,sum(units) units
,sum(pounds) pounds
FROM
ins
GROUP BY

View File

@ -1,19 +1,19 @@
WITH
WITH
target AS (select target_increment incr)
,basemix AS (
SELECT
fspr
,plnt ---master data
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,quota_rep_descr --master data
,director
,billto_group --master data
,billto_group --master data
,shipto_group
,chan --master data
,chan --master data
,chansub
,chan_retail
,part
@ -26,19 +26,18 @@ target AS (select target_increment incr)
,mins_descr
,segm
,substance
,fs_line --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,r_rate --master data
,c_currency --master data
,c_rate --master data
,sum(coalesce(units,0)) units --history value
,sum(coalesce(value_loc,0)) value_loc --history value
,sum(coalesce(value_usd,0)) value_usd --0
,sum(coalesce(value_usd,0)) value_usd --0
,sum(coalesce(cost_loc,0)) cost_loc --history part mix
,sum(coalesce(cost_usd,0)) cost_usd
,sum(coalesce(pounds,0)) pounds
,calc_status --0
,flag --0
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
@ -57,18 +56,18 @@ target AS (select target_increment incr)
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND order_date <= ship_date
GROUP BY
fspr
,plnt ---master data
fspr
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,quota_rep_descr --master data
,director
,billto_group --master data
,billto_group --master data
,shipto_group
,chan --master data
,chan --master data
,chansub
,chan_retail
,part
@ -81,13 +80,13 @@ target AS (select target_increment incr)
,mins_descr
,segm
,substance
,fs_line --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,calc_status --0
,flag --0
,r_rate --master data
,c_currency --master data
,c_rate --master data
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
@ -105,7 +104,7 @@ target AS (select target_increment incr)
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM basemix) = 0 THEN
0
ELSE
(SELECT incr::numeric FROM target)/(SELECT sum(value_loc * r_rate) FROM basemix)
(SELECT incr::numeric FROM target)/(SELECT sum(value_loc * r_rate) FROM basemix)
END factor
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM basemix) = 0 THEN
CASE WHEN ((SELECT incr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM basemix)) <> 0 THEN
@ -124,17 +123,17 @@ target AS (select target_increment incr)
,final AS (
SELECT
fspr
,plnt ---master data
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,quota_rep_descr --master data
,director
,billto_group --master data
,billto_group --master data
,shipto_group
,chan --master data
,chan --master data
,chansub
,chan_retail
,part
@ -147,18 +146,18 @@ target AS (select target_increment incr)
,mins_descr
,segm
,substance
,fs_line --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,r_rate --master data
,c_currency --master data
,c_rate --master data
,0::numeric units
,round((CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric,2) value_loc
,round((CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_usd*s.factor END)::numeric ,2) value_usd
,0::numeric cost_loc
,0::numeric cost_usd
,calc_status --0
,flag --0
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
@ -174,7 +173,6 @@ target AS (select target_increment incr)
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
,0::numeric pounds
FROM
basemix b
CROSS JOIN scale s
@ -229,7 +227,6 @@ target AS (select target_increment incr)
,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd
,sum(units) units
,sum(pounds) pounds
FROM
ins
GROUP BY

View File

@ -1,4 +1,4 @@
WITH
WITH
target AS (select incr_qty qincr)
,testv AS (
SELECT
@ -39,17 +39,17 @@ target AS (select incr_qty qincr)
,basemix AS (
SELECT
fspr
,plnt ---master data
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,quota_rep_descr --master data
,director
,billto_group --master data
,billto_group --master data
,shipto_group
,chan --master data
,chan --master data
,chansub
,chan_retail
,part
@ -62,19 +62,18 @@ target AS (select incr_qty qincr)
,mins_descr
,segm
,substance
,fs_line --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,r_rate --master data
,c_currency --master data
,c_rate --master data
,sum(coalesce(units,0)) units --history value
,sum(coalesce(value_loc,0)) value_loc --history value
,sum(coalesce(value_usd,0)) value_usd --0
,sum(coalesce(value_usd,0)) value_usd --0
,sum(coalesce(cost_loc,0)) cost_loc --history part mix
,sum(coalesce(cost_usd,0)) cost_usd
,sum(coalesce(pounds,0)) pounds
,calc_status --0
,flag --0
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
@ -90,7 +89,7 @@ target AS (select incr_qty qincr)
-----------------scenario----------------------------
where_clause
-----------------additional params-------------------
AND CASE (SELECT flag FROM flagv)
AND CASE (SELECT flag FROM flagv)
WHEN 'scale all' THEN true
WHEN 'scale copy' THEN iter IN ('copy','plan','diff')
WHEN 'scale new part' THEN module = 'new basket'
@ -99,17 +98,17 @@ target AS (select incr_qty qincr)
AND order_date <= ship_date
GROUP BY
fspr
,plnt ---master data
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,quota_rep_descr --master data
,director
,billto_group --master data
,billto_group --master data
,shipto_group
,chan --master data
,chan --master data
,chansub
,chan_retail
,part
@ -122,13 +121,13 @@ target AS (select incr_qty qincr)
,mins_descr
,segm
,substance
,fs_line --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,calc_status --0
,flag --0
,r_rate --master data
,c_currency --master data
,c_rate --master data
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
@ -153,17 +152,17 @@ target AS (select incr_qty qincr)
,final AS (
SELECT
fspr
,plnt ---master data
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,quota_rep_descr --master data
,director
,billto_group --master data
,billto_group --master data
,shipto_group
,chan --master data
,chan --master data
,chansub
,chan_retail
,part
@ -176,18 +175,18 @@ target AS (select incr_qty qincr)
,mins_descr
,segm
,substance
,fs_line --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,r_rate --master data
,c_currency --master data
,c_rate --master data
,round(units*s.factor ,2) units
,round(value_loc*s.factor,2) value_loc
,round(value_usd*s.factor,2) value_usd
,round(cost_loc*s.factor ,2) cost_loc
,round(cost_usd*s.factor ,2) cost_usd
,calc_status --0
,flag --0
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
@ -203,7 +202,6 @@ target AS (select incr_qty qincr)
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
,round(pounds*s.factor, 2) pounds
FROM
basemix b
CROSS JOIN scale s
@ -256,7 +254,6 @@ FROM
,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd
,sum(units) units
,sum(pounds) pounds
FROM
ins
GROUP BY

View File

@ -1,4 +1,4 @@
WITH
WITH
target AS (select target_vol vincr, target_prc pincr)
,testv AS (
SELECT
@ -39,17 +39,17 @@ target AS (select target_vol vincr, target_prc pincr)
,basemix AS (
SELECT
fspr
,plnt ---master data
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,quota_rep_descr --master data
,director
,billto_group --master data
,billto_group --master data
,shipto_group
,chan --master data
,chan --master data
,chansub
,chan_retail
,part
@ -62,19 +62,18 @@ target AS (select target_vol vincr, target_prc pincr)
,mins_descr
,segm
,substance
,fs_line --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,r_rate --master data
,c_currency --master data
,c_rate --master data
,sum(coalesce(units,0)) units --history value
,sum(coalesce(value_loc,0)) value_loc --history value
,sum(coalesce(value_usd,0)) value_usd --0
,sum(coalesce(value_usd,0)) value_usd --0
,sum(coalesce(cost_loc,0)) cost_loc --history part mix
,sum(coalesce(cost_usd,0)) cost_usd
,sum(coalesce(pounds,0)) pounds
,calc_status --0
,flag --0
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
@ -90,7 +89,7 @@ target AS (select target_vol vincr, target_prc pincr)
-----------------scenario----------------------------
where_clause
-----------------additional params-------------------
AND CASE (SELECT flag FROM flagv)
AND CASE (SELECT flag FROM flagv)
WHEN 'scale all' THEN true
WHEN 'scale copy' THEN iter IN ('plan','diff','copy')
WHEN 'scale new part' THEN module = 'new basket'
@ -98,18 +97,18 @@ target AS (select target_vol vincr, target_prc pincr)
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND order_date <= ship_date
GROUP BY
fspr
,plnt ---master data
fspr
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,quota_rep_descr --master data
,director
,billto_group --master data
,billto_group --master data
,shipto_group
,chan --master data
,chan --master data
,chansub
,chan_retail
,part
@ -122,13 +121,13 @@ target AS (select target_vol vincr, target_prc pincr)
,mins_descr
,segm
,substance
,fs_line --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,calc_status --0
,flag --0
,r_rate --master data
,c_currency --master data
,c_rate --master data
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
@ -152,17 +151,17 @@ target AS (select target_vol vincr, target_prc pincr)
,volume AS (
SELECT
fspr
,plnt ---master data
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,quota_rep_descr --master data
,director
,billto_group --master data
,billto_group --master data
,shipto_group
,chan --master data
,chan --master data
,chansub
,chan_retail
,part
@ -175,18 +174,18 @@ target AS (select target_vol vincr, target_prc pincr)
,mins_descr
,segm
,substance
,fs_line --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,r_rate --master data
,c_currency --master data
,c_rate --master data
,round(units*s.factor ,2) units
,round(value_loc*s.factor,2) value_loc
,round(value_usd*s.factor,2) value_usd
,round(cost_loc*s.factor ,2) cost_loc
,round(cost_usd*s.factor ,2) cost_usd
,calc_status --0
,flag --0
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
@ -202,7 +201,6 @@ target AS (select target_vol vincr, target_prc pincr)
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
,round(pounds*s.factor, 2) pounds
FROM
basemix b
CROSS JOIN vscale s
@ -234,17 +232,17 @@ FROM
,pricing AS (
SELECT
fspr
,plnt ---master data
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,quota_rep_descr --master data
,director
,billto_group --master data
,billto_group --master data
,shipto_group
,chan --master data
,chan --master data
,chansub
,chan_retail
,part
@ -257,18 +255,18 @@ FROM
,mins_descr
,segm
,substance
,fs_line --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,r_rate --master data
,c_currency --master data
,c_rate --master data
,0::numeric units
,round((CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric,2) value_loc
,round((CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_usd*s.factor END)::numeric ,2) value_usd
,0::numeric cost_loc
,0::numeric cost_usd
,calc_status --0
,flag --0
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
@ -284,7 +282,6 @@ FROM
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
,0::numeric pounds
FROM
volume b
CROSS JOIN pscale s
@ -339,7 +336,6 @@ FROM
,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd
,sum(units) units
,sum(pounds) pounds
FROM
ins
GROUP BY

View File

@ -36,6 +36,7 @@ FROM
rlarp.osm_pool
WHERE
where_clause
--quota_rep_descr = 'MATTHEW STAAL'
AND order_season IN (2023,2024)
GROUP BY
order_season