Get pounds to update for each forecast adjustment.

Lots of cleanup here too, removing large swaths of code that are no
longer needed. Many improvements the Excel workbook, which is kept in
Teams, not git. These changes may or may not have had accompanying VBA
changes.
This commit is contained in:
PhilRunninger 2023-04-27 16:54:37 -04:00
parent fde6c97964
commit 86225ea7e5
21 changed files with 1056 additions and 859 deletions

View File

@ -28,12 +28,12 @@ Private Sub cmdOK_Click()
End Sub End Sub
Public Sub Initialize(part As String, billTo As String, shipTo As String) Public Sub Initialize(part As String, billTo As String, shipTo As String)
cbPart.list = shSupportingData.ListObjects("ITEM").DataBodyRange.value cbPart.list = shSupportingData.ListObjects("ITEM").DataBodyRange.Value
cbPart.value = part cbPart.Value = part
cbBill.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.value cbBill.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.Value
cbBill.value = billTo cbBill.Value = billTo
cbShip.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.value cbShip.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.Value
cbShip.value = shipTo cbShip.Value = shipTo
useval = False useval = False
End Sub End Sub

Binary file not shown.

View File

@ -28,7 +28,7 @@ Private Sub lbHist_Change()
For i = 0 To Me.lbHist.ListCount - 1 For i = 0 To Me.lbHist.ListCount - 1
If Me.lbHist.Selected(i) Then If Me.lbHist.Selected(i) Then
Me.tbPrint.value = X(i, 7) Me.tbPrint.Value = X(i, 7)
Exit Sub Exit Sub
End If End If
Next i Next i
@ -43,20 +43,6 @@ Private Sub UserForm_Activate()
Exit Sub Exit Sub
End If 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") Call Utils.frmListBoxHeader(Me.lbHEAD, Me.lbHist, "Modifier", "Owner", "When", "Tag", "Comment", "Sales", "id")
End Sub End Sub
@ -74,7 +60,7 @@ Sub delete_selected()
If Me.lbHist.Selected(i) Then 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 If fail Then
MsgBox ("undo did not work") MsgBox ("Undo did not work.")
Exit Sub Exit Sub
End If End If
End If End If

Binary file not shown.

View File

@ -13,24 +13,13 @@ Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False Attribute VB_Exposed = False
Public mod_adjust As Boolean Option Explicit
Private month() As Variant Private month() As Variant
Private mload() As Variant
Private adjust As Object Private adjust As Object
Private nomonth As Boolean
Private mline As Integer
Private clear_lb As Boolean
Private load_tb As Boolean Private load_tb As Boolean
Private set_Price As Boolean Private set_Price As Boolean
Private sp As Object Private sp As Object
Private basket() As Variant
Private cust() As Variant
Private vSwap() As Variant
Private swapline As Integer
Private set_swapalt As Boolean
Private return_swap As Boolean
Private jswap As Object
Private cswap As Object
Private bVol As Double Private bVol As Double
Private bVal As Double Private bVal As Double
@ -45,21 +34,6 @@ Private fVol As Double
Private fVal As Double Private fVal As Double
Private fPrc As Double Private fPrc As Double
Private bVolm As Double
Private bValm As Double
Private bPrcm As Double
Private pVolm As Double
Private pValm As Double
Private pPrcm As Double
Private aVolm As Double
Private aValm As Double
Private aPrcm As Double
Private fVolm As Double
Private fValm As Double
Private fPrcm As Double
Option Explicit
'===================================================================================================== '=====================================================================================================
' Developers' backdoor to enter or exit debug mode: Ctrl-RightClick on the "Selected Scenario" ' Developers' backdoor to enter or exit debug mode: Ctrl-RightClick on the "Selected Scenario"
' label at the top of the form. Debug Mode shows the Pending Changes tab in the form, as well ' label at the top of the form. Debug Mode shows the Pending Changes tab in the form, as well
@ -74,40 +48,20 @@ End Sub
Private Sub butAdjust_Click() Private Sub butAdjust_Click()
Dim fail As Boolean Dim fail As Boolean
Dim doc As String Dim msg As String
If tbAPI.text = "" Then If tbAPI.text = "" Then msg = "No adjustments provided."
MsgBox ("No adjustments provided") If cbTAG.text = "" Then msg = "No tag was selected."
If tbAPI.text = "" Then msg = "No adjustements are ready."
If msg <> "" Then
MsgBox msg, vbOKOnly Or vbExclamation
Exit Sub Exit Sub
End If End If
If cbTAG.text = "" Then Call handler.request_adjust(tbAPI.text, fail)
MsgBox ("no tag was selected")
Exit Sub
End If
Select Case fpvt.mp.SelectedItem.Name
Case "pageSWAP"
doc = tbAPI.text
If doc = "" Then
MsgBox ("no part swap setup")
Exit Sub
End If
Case "pAnn"
doc = tbAPI.text
If doc = "" Then
MsgBox ("no adjustements are ready")
Exit Sub
End If
Case Else
doc = tbAPI.text
'MsgBox ("not on an adjustable tab")
'Exit Sub
End Select
Call handler.request_adjust(doc, fail)
If fail Then If fail Then
MsgBox ("adjustment was not made due to error") MsgBox "Adjustment was not made due to error.", vbOKOnly Or vbExclamation
Exit Sub Exit Sub
End If End If
@ -123,28 +77,11 @@ Private Sub butCancel_Click()
Me.Hide Me.Hide
End Sub End Sub
Private Sub butMAdjust_Click()
Dim i As Integer
Dim fail As Boolean
For i = 1 To 12
If month(i, 10) <> "" Then
Call handler.request_adjust(CStr(month(i, 10)), fail)
End If
Next i
Me.Hide
End Sub
Private Sub butMCancel_Click()
Me.Hide
End Sub
Private Sub cbGoSheet_Click() Private Sub cbGoSheet_Click()
shMonthView.Range("MonthComment").value = "" shMonthView.Range("MonthComment").Value = ""
shMonthView.Range("MonthTag").value = "" shMonthView.Range("MonthTag").Value = ""
shMonthView.Range("QtyPctChange").value = 0 shMonthView.Range("QtyPctChange").Value = 0
shMonthView.Range("PricePctChange").value = 0 shMonthView.Range("PricePctChange").Value = 0
shMonthView.Visible = xlSheetVisible shMonthView.Visible = xlSheetVisible
shMonthView.Select shMonthView.Select
Me.Hide Me.Hide
@ -154,137 +91,15 @@ Private Sub cbTAG_Change()
Dim j As Object Dim j As Object
If tbAPI.text = "" Then tbAPI.text = "{}" If tbAPI.text = "" Then tbAPI.text = "{}"
Set j = JsonConverter.ParseJson(tbAPI.text) Set j = JsonConverter.ParseJson(tbAPI.text)
j("tag") = cbTAG.value j("tag") = cbTAG.Value
tbAPI.text = JsonConverter.ConvertToJson(j) tbAPI.text = JsonConverter.ConvertToJson(j)
End Sub End Sub
Private Sub lbMonth_Change()
If clear_lb Or load_tb Then Exit Sub
Dim i As Long
For i = 0 To 13
If lbMonth.Selected(i) Then
mline = i
If i <> 0 And i <> 13 Then
Me.load_var
Me.load_mbox
Else
load_tb = True
tbMBaseVal.value = ""
tbMBaseVol.value = ""
tbMBasePrice.value = ""
tbmPAVal.value = ""
tbMPAVol.value = ""
tbMPAPrice.value = ""
tbMFVal.value = ""
tbMFVol.value = ""
tbMFPrice.value = ""
tbMAVal.value = ""
tbMAVol.value = ""
tbMAPrice.value = ""
load_tb = False
End If
Exit For
End If
Next i
End Sub
Private Sub cbPLIST_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode <> 13 Then Exit Sub
Dim i As Long
If set_swapalt Then Exit Sub
Dim vtable() As Variant
Dim ptable As String
Dim rx As Object
Set rx = CreateObject("vbscript.regexp")
rx.Global = True
rx.Pattern = " - .*"
For i = 0 To Me.lbSWAP.ListCount - 1
If Me.lbSWAP.Selected(i) Then
vSwap(swapline, 2) = rx.Replace(cbPLIST.value, "")
return_swap = True
lbSWAP.list = vSwap
return_swap = False
End If
Next i
vtable = Utils.ARRAYp_TransposeVar(vSwap)
vtable = Utils.ARRAYp_zerobased_addheader(vtable, "original", "sales", "replace", "fit")
vtable = Utils.ARRAYp_TransposeVar(vtable)
ptable = Utils.json_from_table_zb(vtable, "rows", True, False)
Set jswap("swap") = JsonConverter.ParseJson(ptable)
jswap("scenario")("version") = handler.plan
jswap("scenario")("iter") = handler.basis
jswap("stamp") = Format(Date + time, "yyyy-mm-dd hh:mm:ss")
jswap("user") = Application.UserName
jswap("source") = "adj"
jswap("message") = tbCOM.text
jswap("tag") = cbTAG.text
jswap("type") = "swap"
tbAPI.text = JsonConverter.ConvertToJson(jswap)
End Sub
Private Sub dbGETSWAP_Click()
Dim doc As String
Dim j As Object
Dim fail As Boolean
Dim l() As Variant
Dim ptable As String
Dim vtable() As Variant
Set j = JsonConverter.ParseJson("{""scenario"":" & handler.scenario & "}")
'Set j = JsonConverter.ParseJson(doc)
j("new_mold") = pickSWAP.text
doc = JsonConverter.ConvertToJson(j)
vSwap = handler.get_swap_fit(doc, fail)
lbSWAP.list = vSwap
'Call x.frmListBoxHeader(lbSWAPH, lbSWAP, "Original", "Sales", "Replacement", "Fit")
cbPLIST.list = shSupportingData.ListObjects("ITEM").DataBodyRange.value
'---------build change-------------
Set jswap = j
vtable = Utils.ARRAYp_TransposeVar(vSwap)
vtable = Utils.ARRAYp_zerobased_addheader(vtable, "original", "sales", "replace", "fit")
vtable = Utils.ARRAYp_TransposeVar(vtable)
ptable = Utils.json_from_table_zb(vtable, "rows", True, False)
Set jswap("swap") = JsonConverter.ParseJson(ptable)
jswap("scenario")("version") = handler.plan
jswap("scenario")("iter") = handler.basis
jswap("stamp") = Format(Date + time, "yyyy-mm-dd hh:mm:ss")
jswap("user") = Application.UserName
jswap("source") = "adj"
jswap("message") = tbCOM.text
jswap("tag") = cbTAG.text
jswap("type") = "swap"
tbAPI.text = JsonConverter.ConvertToJson(jswap)
End Sub
Private Sub lbSWAP_Change()
Dim i As Long
If return_swap Then Exit Sub
For i = 0 To Me.lbSWAP.ListCount - 1
If Me.lbSWAP.Selected(i) Then
set_swapalt = True
cbPLIST.value = vSwap(i, 2)
set_swapalt = False
swapline = i
End If
Next i
End Sub
Private Sub opEditPrice_Click() Private Sub opEditPrice_Click()
opPlugVol.Visible = False opPlugVol.Visible = False
opPlugPrice.Visible = False opPlugPrice.Visible = False
opPlugPrice.value = True opPlugPrice.Value = True
opPlugVol.value = False opPlugVol.Value = False
tbFcPrice.Enabled = True tbFcPrice.Enabled = True
tbFcPrice.BackColor = &H80000018 tbFcPrice.BackColor = &H80000018
@ -320,36 +135,6 @@ Private Sub opEditSales_Click()
tbpd.Enabled = True tbpd.Enabled = True
End Sub End Sub
Private Sub opEditPriceM_Click()
opmvol.Enabled = False
opmprice.Enabled = False
opmvol.Visible = False
opmprice.Visible = False
opmprice.value = True
opmvol.value = True
tbMFPrice.Enabled = True
tbMFPrice.BackColor = &H80000018
tbMFVal.Enabled = False
tbMFVal.BackColor = &H80000005
tbMFVol.Enabled = True
tbMFVol.BackColor = &H80000018
End Sub
Private Sub opEditSalesM_Click()
opmvol.Enabled = True
opmprice.Enabled = True
opmvol.Visible = True
opmprice.Visible = True
tbMFPrice.Enabled = False
tbMFPrice.BackColor = &H80000005
tbMFVal.Enabled = True
tbMFVal.BackColor = &H80000018
tbMFVol.Enabled = False
tbMFVol.BackColor = &H80000005
End Sub
Private Sub opPlugPrice_Click() Private Sub opPlugPrice_Click()
calc_val calc_val
End Sub End Sub
@ -359,15 +144,15 @@ Private Sub opPlugVol_Click()
End Sub End Sub
Private Sub sbpd_Change() Private Sub sbpd_Change()
tbpd.value = sbpd.value tbpd.Value = sbpd.Value
End Sub End Sub
Private Sub sbpp_Change() Private Sub sbpp_Change()
tbpp.value = sbpp.value tbpp.Value = sbpp.Value
End Sub End Sub
Private Sub sbpv_Change() Private Sub sbpv_Change()
tbpv.value = sbpv.value tbpv.Value = sbpv.Value
End Sub End Sub
Private Sub tbCOM_Change() Private Sub tbCOM_Change()
@ -394,75 +179,41 @@ Private Sub tbFcVol_Change()
If opEditPrice Then calc_price If opEditPrice Then calc_price
End Sub End Sub
'--------------------------------monthly buttons--------------------------------------
Private Sub opmPrice_Click()
calc_mval
End Sub
Private Sub opmVol_Click()
calc_mval
End Sub
Private Sub tbmfPrice_Change()
If mline = 0 Then Exit Sub
If clear_lb Or load_tb Then Exit Sub
set_Price = True
If opEditPriceM Then calc_mprice
set_Price = False
End Sub
Private Sub tbMFVal_Change()
If mline = 0 Then Exit Sub
If clear_lb Or load_tb Then Exit Sub
If opEditSalesM Then calc_mval
End Sub
Private Sub tbmfVol_Change()
If mline = 0 Then Exit Sub
If clear_lb Or load_tb Then Exit Sub
If opEditPriceM Then calc_mprice
End Sub
Private Sub tbpd_Change() Private Sub tbpd_Change()
If load_tb Then Exit Sub If load_tb Then Exit Sub
If Not VBA.IsNumeric(tbpd.value) Then If Not VBA.IsNumeric(tbpd.Value) Then
tbpd = "0" tbpd = "0"
End If End If
tbFcVal = (bVal + pVal) * (1 + tbpd.value / 100) tbFcVal = (bVal + pVal) * (1 + tbpd.Value / 100)
End Sub End Sub
Private Sub tbpp_Change() Private Sub tbpp_Change()
If load_tb Then Exit Sub If load_tb Then Exit Sub
If Not VBA.IsNumeric(tbpd.value) Then If Not VBA.IsNumeric(tbpd.Value) Then
tbpd = "0" tbpd = "0"
End If End If
tbFcPrice = (bPrc + pPrc) * (1 + tbpp.value / 100) tbFcPrice = (bPrc + pPrc) * (1 + tbpp.Value / 100)
Me.load_mbox_ann Me.load_mbox_ann
End Sub End Sub
Private Sub tbpv_Change() Private Sub tbpv_Change()
If load_tb Then Exit Sub If load_tb Then Exit Sub
If Not VBA.IsNumeric(tbpv.value) Then If Not VBA.IsNumeric(tbpv.Value) Then
tbpd = "0" tbpd = "0"
End If End If
tbFcVol = (bVol + pVol) * (1 + tbpv.value / 100) tbFcVol = (bVol + pVol) * (1 + tbpv.Value / 100)
End Sub End Sub
Private Sub UserForm_Activate() Private Sub UserForm_Activate()
Dim i As Long Me.Caption = "Forecast Adjust " & shConfig.Range("version").Value & " Loading..."
Dim j As Long
Dim k As Long
Dim ok As Boolean
Me.Caption = "Forecast Adjust " & shConfig.Range("version").value & " Loading..."
Me.mp.Visible = False Me.mp.Visible = False
Me.fraExit.Visible = False Me.fraExit.Visible = False
Dim ok As Boolean
Set sp = handler.scenario_package("{""scenario"":" & scenario & "}", ok) Set sp = handler.scenario_package("{""scenario"":" & scenario & "}", ok)
Call Utils.frmListBoxHeader(Me.lbSHDR, Me.lbSDET, "Field", "Selection") Call Utils.frmListBoxHeader(Me.lbSHDR, Me.lbSDET, "Field", "Selection")
Me.Caption = "Forecast Adjust " & shConfig.Range("version").value Me.Caption = "Forecast Adjust " & shConfig.Range("version").Value
If Not ok Then If Not ok Then
fpvt.Hide fpvt.Hide
@ -471,7 +222,6 @@ Private Sub UserForm_Activate()
End If End If
'---show existing adjustment if there is one---- '---show existing adjustment if there is one----
fpvt.mod_adjust = False
pVol = 0 pVol = 0
pVal = 0 pVal = 0
pPrc = 0 pPrc = 0
@ -484,14 +234,16 @@ Private Sub UserForm_Activate()
fVal = 0 fVal = 0
fVol = 0 fVol = 0
fPrc = 0 fPrc = 0
Me.tbAPI.value = "" Me.tbAPI.Value = ""
If IsNull(sp("package")("totals")) Then If IsNull(sp("package")("totals")) Then
MsgBox "An unexpected error has occurred when retrieving the scenario.", vbOKOnly Or vbExclamation, "Error"
fpvt.Hide fpvt.Hide
Application.StatusBar = False Application.StatusBar = False
Exit Sub Exit Sub
End If End If
Dim i As Long
For i = 1 To sp("package")("totals").Count For i = 1 To sp("package")("totals").Count
Select Case sp("package")("totals")(i)("order_season") Select Case sp("package")("totals")(i)("order_season")
Case 2024 Case 2024
@ -534,7 +286,6 @@ Private Sub UserForm_Activate()
'---------------------------------------populate monthly------------------------------------------------------- '---------------------------------------populate monthly-------------------------------------------------------
k = 0
'--parse json into variant array for loading-- '--parse json into variant array for loading--
ReDim month(sp("package")("mpvt").Count + 1, 10) ReDim month(sp("package")("mpvt").Count + 1, 10)
@ -555,81 +306,28 @@ Private Sub UserForm_Activate()
End If End If
Next i Next i
month(0, 0) = "month"
month(13, 0) = "total"
month(0, 1) = "2023 qty"
month(0, 2) = "2024 base qty"
month(0, 3) = "2024 adj qty"
month(0, 4) = "2024 qty"
month(0, 5) = "2023 val"
month(0, 6) = "2024 base val"
month(0, 7) = "2024 adj val"
month(0, 8) = "2024 val"
Me.crunch_array Me.crunch_array
ReDim basket(sp("package")("basket").Count, 3) ReDim basket(sp("package")("basket").Count, 3)
' basket(0, 0) = "order_season"
' basket(0, 1) = "order_month"
' basket(0, 2) = "version"
' basket(0, 3) = "iter"
' basket(0, 4) = "part_descr"
' basket(0, 5) = "bill_cust_descr"
' basket(0, 6) = "ship_cust_descr"
' basket(0, 7) = "units"
' basket(0, 8) = "value_usd"
basket(0, 0) = "part_descr" basket(0, 0) = "part_descr"
basket(0, 1) = "bill_cust_descr" basket(0, 1) = "bill_cust_descr"
basket(0, 2) = "ship_cust_descr" basket(0, 2) = "ship_cust_descr"
basket(0, 3) = "mix" basket(0, 3) = "mix"
For i = 1 To UBound(basket, 1) For i = 1 To UBound(basket, 1)
'basket(i, 0) = sp("package")("base")(i)("order_season")
'basket(i, 1) = sp("package")("base")(i)("order_month")
'basket(i, 2) = sp("package")("base")(i)("version")
'basket(i, 3) = sp("package")("base")(i)("iter")
'basket(i, 4) = sp("package")("base")(i)("part_descr")
'basket(i, 5) = sp("package")("base")(i)("bill_cust_descr")
'basket(i, 6) = sp("package")("base")(i)("ship_cust_descr")
'basket(i, 7) = sp("package")("base")(i)("units")
'basket(i, 8) = sp("package")("base")(i)("value_usd")
basket(i, 0) = sp("package")("basket")(i)("part_descr") basket(i, 0) = sp("package")("basket")(i)("part_descr")
basket(i, 1) = sp("package")("basket")(i)("bill_cust_descr") basket(i, 1) = sp("package")("basket")(i)("bill_cust_descr")
basket(i, 2) = sp("package")("basket")(i)("ship_cust_descr") basket(i, 2) = sp("package")("basket")(i)("ship_cust_descr")
basket(i, 3) = sp("package")("basket")(i)("mix") basket(i, 3) = sp("package")("basket")(i)("mix")
Next i Next i
'---------------get list of customers----------------------------
ReDim cust(sp("package")("customers").Count - 1, 3)
For i = 0 To UBound(cust, 1)
cust(i, 0) = sp("package")("customers")(i + 1)("bill_cust_descr")
cust(i, 1) = ""
cust(i, 2) = sp("package")("customers")(i + 1)("ship_cust_descr")
cust(i, 3) = ""
Next i
Call Utils.frmListBoxHeader(lbCUSTH, lbCUST, "Bill-To", "Replace", "Ship-To", "Replace")
'-------------load tags------------------------------- '-------------load tags-------------------------------
cbTAG.list = shConfig.ListObjects("TAGS").DataBodyRange.value cbTAG.list = shConfig.ListObjects("TAGS").DataBodyRange.Value
'----------reset spinner buttons---------------------- '----------reset spinner buttons----------------------
sbpv.value = 0 sbpv.Value = 0
sbpp.value = 0 sbpp.Value = 0
sbpd.value = 0 sbpd.Value = 0
'--------reset swap tab-------------------------------
lbSWAP.clear
pickSWAP.value = ""
pickSWAP.text = Mid(sp("package")("basket")(1)("part_descr"), 1, 8)
pickSWAP.list = shSupportingData.ListObjects("MOLD").DataBodyRange.value
cbBT.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.value
cbST.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.value
lbCUST.list = cust
Call Utils.frmListBoxHeader(Me.lbSWAPH, Me.lbSWAP, "Original", "Sales", "Replacement", "Fit")
Call handler.month_tosheet(month, basket) Call handler.month_tosheet(month, basket)
Application.StatusBar = False Application.StatusBar = False
@ -670,75 +368,6 @@ Sub crunch_array()
mload(i, 3) = Format(month(i, 5), "#,###") mload(i, 3) = Format(month(i, 5), "#,###")
mload(i, 4) = Format(month(i, 8), "#,###") mload(i, 4) = Format(month(i, 8), "#,###")
Next i Next i
'mline = 0
clear_lb = True
lbMonth.clear
lbMonth.list = mload
clear_lb = False
End Sub
Private Sub lbCUST_Change()
Dim i As Long
Dim X() As Variant
X = lbCUST.list
For i = 0 To UBound(X, 1)
If lbCUST.Selected(i) Then Exit For
Next i
cbBT.text = X(i, 0)
cbST.text = X(i, 2)
End Sub
Private Sub cbBT_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode <> 13 Then Exit Sub
Dim i As Long
Dim X() As Variant
X = lbCUST.list
For i = 0 To UBound(X, 1)
If lbCUST.Selected(i) Then X(i, 1) = Me.rev_cust(cbBT.text)
Next i
lbCUST.list = X
Call Me.build_cust_swap
End Sub
Private Sub cbST_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode <> 13 Then Exit Sub
Dim i As Long
Dim X() As Variant
X = lbCUST.list
For i = 0 To UBound(X, 1)
If lbCUST.Selected(i) Then X(i, 3) = Me.rev_cust(cbST.text)
Next i
lbCUST.list = X
Call Me.build_cust_swap
End Sub
Sub build_cust_swap()
Dim vtable() As Variant
Dim ptable As String
vtable = lbCUST.list
vtable = Utils.ARRAYp_TransposeVar(vtable)
vtable = Utils.ARRAYp_zerobased_addheader(vtable, "bill", "bill_r", "ship", "ship_r")
vtable = Utils.ARRAYp_TransposeVar(vtable)
ptable = Utils.json_from_table_zb(vtable, "rows", True, False)
Set cswap = JsonConverter.ParseJson("{""scenario"":" & handler.scenario & "}")
cswap("scenario")("version") = handler.plan
cswap("scenario")("iter") = handler.basis
cswap("stamp") = Format(Date + time, "yyyy-mm-dd hh:mm:ss")
cswap("user") = Application.UserName
cswap("source") = "adj"
cswap("message") = tbCOM.text
cswap("tag") = cbTAG.text
cswap("type") = "cust_swap"
Set cswap("swap") = JsonConverter.ParseJson(ptable)
tbAPI.text = JsonConverter.ConvertToJson(cswap)
End Sub End Sub
Public Function rev_cust(cust As String) As String Public Function rev_cust(cust As String) As String
@ -755,61 +384,6 @@ Public Function rev_cust(cust As String) As String
End Function End Function
Sub load_var()
'base
bVolm = co_num(month(mline, 2), 0)
bValm = co_num(month(mline, 6), 0)
'prior adjust
pVolm = co_num(month(mline, 3), 0)
pValm = co_num(month(mline, 7), 0)
'current forecast
fVolm = co_num(month(mline, 4), 0)
fValm = co_num(month(mline, 8), 0)
'adjustment
aVolm = fVolm - (bVolm + pVolm)
aValm = fValm - (bValm + pValm)
If month(mline, 9) = "addmonth" Then
nomonth = True
bPrcm = month(13, 6) / month(13, 2)
fPrcm = month(13, 8) / month(13, 4)
Else
'prices
If bVolm <> 0 Then bPrcm = bValm / bVolm
If (bVolm + pVolm) <> 0 Then pPrcm = (pValm + bValm) / (bVolm + pVolm) - bPrcm
If fVolm <> 0 Then fPrcm = fValm / fVolm
aPrcm = fPrcm - (bPrcm + pPrcm)
End If
End Sub
Sub load_mbox()
load_tb = True
tbMBaseVol = Format(bVolm, "#,###")
tbMBaseVal = Format(bValm, "#,###")
tbMBasePrice = Format(bPrcm, "0.00000")
tbMPAVol = Format(pVolm, "#,###")
tbmPAVal = Format(pValm, "#,###")
tbMPAPrice = Format(pPrcm, "0.00000")
tbMFVol = Format(fVolm, "#,###")
tbMFVal = Format(fValm, "#,###")
If Not set_Price Then tbMFPrice = Format(fPrcm, "0.#####")
tbMAVol = Format(aVolm, "#,###")
tbMAVal = Format(aValm, "#,###")
tbMAPrice = Format(aPrcm, "0.00000")
load_tb = False
End Sub
Sub load_mbox_ann() Sub load_mbox_ann()
load_tb = True load_tb = True
@ -833,23 +407,6 @@ Sub load_mbox_ann()
load_tb = False load_tb = False
End Sub End Sub
Sub load_array()
'base
month(mline, 2) = bVolm
month(mline, 6) = bValm
'prior adjust
month(mline, 3) = pVolm
month(mline, 7) = pValm
'current forecast
month(mline, 4) = fVolm
month(mline, 8) = fValm
Me.crunch_array
End Sub
Function co_num(ByRef one As Variant, ByRef two As Variant) As Variant Function co_num(ByRef one As Variant, ByRef two As Variant) As Variant
If Not IsNumeric(one) Or IsNull(one) Then If Not IsNumeric(one) Or IsNull(one) Then
@ -864,9 +421,9 @@ Sub calc_val()
Dim pchange As Double Dim pchange As Double
If IsNumeric(tbFcVal.value) Then If IsNumeric(tbFcVal.Value) Then
'get textbox value 'get textbox value
fVal = tbFcVal.value fVal = tbFcVal.Value
'do calculations 'do calculations
aVal = fVal - bVal - pVal aVal = fVal - bVal - pVal
@ -875,7 +432,7 @@ Sub calc_val()
If (Round(pVal, 2) + Round(bVal, 2)) = 0 Then If (Round(pVal, 2) + Round(bVal, 2)) = 0 Then
pchange = 0 pchange = 0
If co_num(pVal, bVal) = 0 Then If co_num(pVal, bVal) = 0 Then
MsgBox ("zero times any number is zero, cannot scale to get to the target") MsgBox "Zero times any number is zero. Cannot scale to get to the target."
Else Else
fVol = fVal / (co_num(bVal, pVal) / co_num(bVol, pVol)) fVol = fVal / (co_num(bVal, pVal) / co_num(bVol, pVol))
End If End If
@ -932,15 +489,8 @@ Sub calc_val()
End Sub End Sub
Sub calc_price() Sub calc_price()
fVol = co_num(tbFcVol.Value, 0)
'If IsNumeric(tbFcPrice.value) And tbFcPrice.value <> 0 And IsNumeric(tbFcVol.value) And tbFcVol.value <> 0 Then fPrc = co_num(tbFcPrice.Value, 0)
'If IsNumeric(tbFcPrice.value) And IsNumeric(tbFcVol.value) And tbFcVol.value <> 0 Then
'If IsNumeric(tbFcPrice.value) And IsNumeric(tbFcVol.value) Then
'capture currently changed item
fVol = co_num(tbFcVol.value, 0)
fPrc = co_num(tbFcPrice.value, 0)
'calc 'calc
fVal = fPrc * fVol fVal = fPrc * fVol
aVal = fVal - bVal - pVal aVal = fVal - bVal - pVal
@ -989,163 +539,6 @@ Sub calc_price()
tbAPI = JsonConverter.ConvertToJson(adjust) tbAPI = JsonConverter.ConvertToJson(adjust)
End Sub End Sub
Sub calc_mval()
Dim pchange As Double
Dim j As Object
If IsNumeric(tbMFVal.value) Then
'get textbox value
fValm = tbMFVal.value
'do calculations
aValm = fValm - bValm - pValm
'---------if volume adjustment method is selected, scale the volume up----------------------------------
If nomonth Then
fVolm = fValm / bPrcm
fPrcm = bPrcm
Else
If opmvol Then
pchange = fValm / (pValm + bValm)
fVolm = (pVolm + bVolm) * pchange
Else
fVolm = pVolm + bVolm
End If
End If
If fVolm = 0 Then
fPrcm = 0
Else
fPrcm = fValm / fVolm
End If
aVolm = fVolm - (bVolm + pVolm)
aPrcm = fPrcm - (bPrcm + pPrcm)
Else
aVolm = fVolm - bVolm - pVolm
aPrcm = 0
End If
tbMFVal = Format(tbMFVal, "#,###")
'build json
Set j = JsonConverter.ParseJson("{""scenario"":" & scenario & "}")
j("scenario")("version") = handler.plan
j("scenario")("iter") = handler.basis
j("stamp") = Format(Date + time, "yyyy-mm-dd hh:mm:ss")
j("user") = Application.UserName
j("source") = "adj"
If opEditSalesM Then
If opmvol Then
If nomonth Then
j("type") = "addmonth_v"
j("month") = month(mline, 0)
Else
j("type") = "scale_v"
j("scenario")("order_month") = month(mline, 0)
End If
j("amount") = aValm
Else
If nomonth Then
j("type") = "addmonth_p"
j("month") = month(mline, 0)
Else
j("type") = "scale_p"
j("scenario")("order_month") = month(mline, 0)
End If
j("amount") = aValm
End If
Else
If nomonth Then
j("type") = "addmonth_vp"
j("month") = month(mline, 0)
Else
j("type") = "scale_vp"
j("scenario")("order_month") = month(mline, 0)
End If
j("qty") = aVolm
j("amount") = aValm
End If
month(mline, 10) = JsonConverter.ConvertToJson(j)
tbAPI = JsonConverter.ConvertToJson(j)
Me.load_mbox
Me.load_array
End Sub
Sub calc_mprice()
Dim j As Object
If IsNumeric(tbMFPrice.value) And tbMFPrice.value <> 0 And IsNumeric(tbMFVol.value) And tbMFVol.value <> 0 Then
'capture currently changed item
fVolm = tbMFVol.value
fPrcm = tbMFPrice.value
'calc
fValm = fPrcm * fVolm
aValm = fValm - bValm - pValm
aVolm = fVolm - (bVolm + pVolm)
If nomonth Then
aPrcm = fValm / fVolm - bPrcm
Else
aPrcm = fValm / fVolm - ((bValm + pValm) / (bVolm + pVolm))
End If
Else
fValm = 0
aValm = fValm - bValm - pValm
End If
'build json
Set j = JsonConverter.ParseJson("{""scenario"":" & scenario & "}")
j("scenario")("version") = handler.plan
j("scenario")("iter") = handler.basis
j("stamp") = Format(Date + time, "yyyy-mm-dd hh:mm:ss")
j("user") = Application.UserName
j("source") = "adj"
If opEditSalesM Then
If opmvol Then
If nomonth Then
j("type") = "addmonth_v"
j("month") = month(mline, 0)
Else
j("type") = "scale_v"
j("scenario")("order_month") = month(mline, 0)
End If
j("amount") = aValm
Else
If nomonth Then
'this scenario should be prevented
j("type") = "addmonth_v"
j("month") = month(mline, 0)
Else
j("type") = "scale_p"
j("scenario")("order_month") = month(mline, 0)
End If
j("amount") = aValm
End If
Else
If nomonth Then
j("type") = "addmonth_vp"
j("month") = month(mline, 0)
Else
If aVolm = 0 Then
j("type") = "scale_p"
Else
j("type") = "scale_vp"
End If
j("scenario")("order_month") = month(mline, 0)
End If
j("qty") = aVolm
j("amount") = aValm
End If
month(mline, 10) = JsonConverter.ConvertToJson(j)
tbAPI = JsonConverter.ConvertToJson(j)
If clear_lb Then MsgBox ("clear")
Me.load_mbox
Me.load_array
End Sub
Function iter_def(ByVal iter As String) As String Function iter_def(ByVal iter As String) As String
Dim i As Integer Dim i As Integer
@ -1169,3 +562,4 @@ Function iter_def(ByVal iter As String) As String
End Function End Function

Binary file not shown.

View File

@ -217,7 +217,7 @@ Function request_adjust(doc As String, ByRef fail As Boolean) As Object
'json("stamp") = Format(Now, "yyyy-mm-dd hh:mm:ss") 'json("stamp") = Format(Now, "yyyy-mm-dd hh:mm:ss")
'doc = JsonConverter.ConvertToJson(doc) 'doc = JsonConverter.ConvertToJson(doc)
server = shConfig.Range("server").value server = shConfig.Range("server").Value
With req With req
.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
@ -255,12 +255,12 @@ Function request_adjust(doc As String, ByRef fail As Boolean) As Object
Set json = JsonConverter.ParseJson(wr) Set json = JsonConverter.ParseJson(wr)
If IsNull(json("x")) Then If IsNull(json("x")) Then
MsgBox ("no adjustment was made") MsgBox ("No adjustment was made.")
fail = False fail = False
Exit Function Exit Function
End If End If
ReDim res(json("x").Count - 1, 33) ReDim res(json("x").Count - 1, 34)
For i = 0 To UBound(res, 1) For i = 0 To UBound(res, 1)
res(i, 0) = json("x")(i + 1)("bill_cust_descr") res(i, 0) = json("x")(i + 1)("bill_cust_descr")
@ -297,6 +297,7 @@ Function request_adjust(doc As String, ByRef fail As Boolean) As Object
res(i, 31) = json("x")(i + 1)("logid") res(i, 31) = json("x")(i + 1)("logid")
res(i, 32) = json("x")(i + 1)("tag") res(i, 32) = json("x")(i + 1)("tag")
res(i, 33) = json("x")(i + 1)("comment") res(i, 33) = json("x")(i + 1)("comment")
res(i, 34) = json("x")(i + 1)("pounds")
Next i Next i
Set json = Nothing Set json = Nothing
@ -331,7 +332,7 @@ Sub load_config()
Dim i As Integer Dim i As Integer
'----server to use--------------------------------------------------------- '----server to use---------------------------------------------------------
handler.server = shConfig.Range("server").value handler.server = shConfig.Range("server").Value
'---basis----------------------------------------------------------------- '---basis-----------------------------------------------------------------
With shConfig.ListObjects("BASIS") With shConfig.ListObjects("BASIS")
For i = 1 To .DataBodyRange.Rows.Count For i = 1 To .DataBodyRange.Rows.Count
@ -354,7 +355,7 @@ Sub load_config()
Next Next
End With End With
'---plan version-------------------------------------------------------------- '---plan version--------------------------------------------------------------
handler.plan = shConfig.Range("budget").value handler.plan = shConfig.Range("budget").Value
End Sub End Sub
@ -369,7 +370,7 @@ Sub month_tosheet(ByRef pkg() As Variant, ByRef basket() As Variant)
Set j = JsonConverter.ParseJson("{""scenario"":" & scenario & "}") Set j = JsonConverter.ParseJson("{""scenario"":" & scenario & "}")
.Cells(1, 16) = JsonConverter.ConvertToJson(j) .Cells(1, 16) = JsonConverter.ConvertToJson(j)
For i = 0 To 12 For i = 1 To 12
'------------volume------------------- '------------volume-------------------
.Cells(i + 1, 1) = co_num(pkg(i, 1), 0) .Cells(i + 1, 1) = co_num(pkg(i, 1), 0)
.Cells(i + 1, 2) = co_num(pkg(i, 2), 0) .Cells(i + 1, 2) = co_num(pkg(i, 2), 0)
@ -454,9 +455,9 @@ Sub month_tosheet(ByRef pkg() As Variant, ByRef basket() As Variant)
.Range("U1:AC100000").ClearContents .Range("U1:AC100000").ClearContents
Call Utils.SHTp_DumpVar(basket, .Name, 1, 21, False, False, True) Call Utils.SHTp_DumpVar(basket, .Name, 1, 21, False, False, True)
Call Utils.SHTp_DumpVar(basket, .Name, 1, 26, False, False, True) Call Utils.SHTp_DumpVar(basket, .Name, 1, 26, False, False, True)
shConfig.Range("rebuild").value = 0 shConfig.Range("rebuild").Value = 0
shConfig.Range("show_basket").value = 0 shConfig.Range("show_basket").Value = 0
shConfig.Range("new_part").value = 0 shConfig.Range("new_part").Value = 0
shMonthView.LoadSheet shMonthView.LoadSheet
@ -489,7 +490,7 @@ Function list_changes(doc As String, ByRef fail As Boolean) As Variant()
Exit Function Exit Function
End If End If
server = shConfig.Range("server").value server = shConfig.Range("server").Value
With req With req
.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
@ -503,7 +504,7 @@ Function list_changes(doc As String, ByRef fail As Boolean) As Variant()
Set json = JsonConverter.ParseJson(wr) Set json = JsonConverter.ParseJson(wr)
If IsNull(json("x")) Then If IsNull(json("x")) Then
MsgBox ("no history") MsgBox ("No history.")
fail = True fail = True
Exit Function Exit Function
End If End If
@ -563,7 +564,7 @@ Function undo_changes(ByVal logid As Integer, ByRef fail As Boolean) As Variant(
Next i Next i
If j = 0 Then 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 fail = True
Exit Function Exit Function
End If End If
@ -602,7 +603,7 @@ Function get_swap_fit(doc As String, ByRef fail As Boolean) As Variant()
Exit Function Exit Function
End If End If
server = shConfig.Range("server").value server = shConfig.Range("server").Value
With req With req
.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
@ -616,7 +617,7 @@ Function get_swap_fit(doc As String, ByRef fail As Boolean) As Variant()
Set json = JsonConverter.ParseJson(wr) Set json = JsonConverter.ParseJson(wr)
If IsNull(json("x")) Then If IsNull(json("x")) Then
MsgBox ("no history") MsgBox ("No history.")
fail = True fail = True
Exit Function Exit Function
End If End If

View File

@ -21,10 +21,10 @@ End Sub
Private Sub cbOK_Click() Private Sub cbOK_Click()
Application.StatusBar = "Retrieving data for " & cbDSM.value & "....." Application.StatusBar = "Retrieving data for " & cbDSM.Value & "....."
openf.Caption = "retrieving data......" openf.Caption = "Retrieving data......"
Call handler.pg_main_workset(cbDSM.value) Call handler.pg_main_workset(cbDSM.Value)
shOrders.PivotTables("ptOrders").PivotCache.Refresh shOrders.PivotTables("ptOrders").PivotCache.Refresh
Application.StatusBar = False Application.StatusBar = False
openf.Hide openf.Hide
@ -33,8 +33,8 @@ End Sub
Private Sub UserForm_Activate() Private Sub UserForm_Activate()
handler.server = shConfig.Range("server").value handler.server = shConfig.Range("server").Value
cbDSM.list = shSupportingData.ListObjects("DSM").DataBodyRange.value cbDSM.list = shSupportingData.ListObjects("DSM").DataBodyRange.Value
End Sub End Sub

Binary file not shown.

View File

@ -29,7 +29,7 @@ End Sub
Private Sub UserForm_Activate() Private Sub UserForm_Activate()
useval = False useval = False
cbPart.list = shSupportingData.ListObjects("ITEM").DataBodyRange.value cbPart.list = shSupportingData.ListObjects("ITEM").DataBodyRange.Value
End Sub End Sub

Binary file not shown.

View File

@ -10,7 +10,9 @@ Attribute VB_Exposed = True
Option Explicit Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range) Private Sub Worksheet_Change(ByVal Target As Range)
If shConfig.Range("debug_mode").value Then If Intersect(Target, shConfig.Range("debug_mode")) Is Nothing Then Exit Sub
If shConfig.Range("debug_mode").Value Then
shConfig.Visible = xlSheetVisible shConfig.Visible = xlSheetVisible
shData.Visible = xlSheetVisible shData.Visible = xlSheetVisible
shMonthView.Visible = xlSheetVisible shMonthView.Visible = xlSheetVisible

View File

@ -30,7 +30,7 @@ Public Sub MPP_Down() ' Handler for down-triangle on price percent change.
If newpart Then Exit Sub If newpart Then Exit Sub
With shMonthView.Range("PricePctChange") With shMonthView.Range("PricePctChange")
.value = WorksheetFunction.Max(-0.1, .value - 0.01) .Value = WorksheetFunction.Max(-0.1, .Value - 0.01)
End With End With
MPP_Change MPP_Change
End Sub End Sub
@ -39,7 +39,7 @@ Public Sub MPP_Up() ' Handler for up-triangle on price percent change.
If newpart Then Exit Sub If newpart Then Exit Sub
With shMonthView.Range("PricePctChange") With shMonthView.Range("PricePctChange")
.value = WorksheetFunction.Min(0.1, .value + 0.01) .Value = WorksheetFunction.Min(0.1, .Value + 0.01)
End With End With
MPP_Change MPP_Change
End Sub End Sub
@ -70,7 +70,7 @@ Public Sub MPV_Down() ' Handler for down-triangle on qty percent change.
If newpart Then Exit Sub If newpart Then Exit Sub
With shMonthView.Range("QtyPctChange") With shMonthView.Range("QtyPctChange")
.value = WorksheetFunction.Max(-0.1, .value - 0.01) .Value = WorksheetFunction.Max(-0.1, .Value - 0.01)
End With End With
MPV_Change MPV_Change
End Sub End Sub
@ -79,7 +79,7 @@ Public Sub MPV_Up() ' Handler for up-triangle on qty percent change.
If newpart Then Exit Sub If newpart Then Exit Sub
With shMonthView.Range("QtyPctChange") With shMonthView.Range("QtyPctChange")
.value = WorksheetFunction.Min(0.1, .value + 0.01) .Value = WorksheetFunction.Min(0.1, .Value + 0.01)
End With End With
MPV_Change MPV_Change
End Sub End Sub
@ -106,6 +106,10 @@ Private Sub MPV_Change()
Application.ScreenUpdating = True Application.ScreenUpdating = True
End Sub End Sub
Public Sub ToggleVolumePrice()
shMonthView.Range("MonthAdjustVolume").Value = (shMonthView.Range("MonthAdjustVolume").Value <> True)
shMonthView.Range("MonthAdjustPrice").Value = Not shMonthView.Range("MonthAdjustVolume").Value
End Sub
Private Sub Worksheet_Change(ByVal Target As Range) Private Sub Worksheet_Change(ByVal Target As Range)
'---this needs checked prior to busy check because % increase spinners are flagged as dumps '---this needs checked prior to busy check because % increase spinners are flagged as dumps
@ -121,7 +125,7 @@ Private Sub Worksheet_Change(ByVal Target As Range)
IntersectsWith(Target, Range("sales"))) And _ IntersectsWith(Target, Range("sales"))) And _
Target.Columns.Count > 1 _ Target.Columns.Count > 1 _
Then Then
MsgBox ("you can only change one column at a time - your change will be undone") MsgBox "You can only change one column at a time. Your change will be undone."
busy = True busy = True
Application.Undo Application.Undo
busy = False busy = False
@ -135,7 +139,7 @@ Private Sub Worksheet_Change(ByVal Target As Range)
If IntersectsWith(Target, Range("SalesNewAdj")) Then Call Me.ms_adj If IntersectsWith(Target, Range("SalesNewAdj")) Then Call Me.ms_adj
If IntersectsWith(Target, Range("SalesFinal")) Then Call Me.ms_set If IntersectsWith(Target, Range("SalesFinal")) Then Call Me.ms_set
If IntersectsWith(Target, Range("basket")) And shConfig.Range("show_basket").value = 1 Then If IntersectsWith(Target, Range("basket")) And shConfig.Range("show_basket").Value = 1 Then
If RemoveEmptyBasketLines Then ' Lines were removed If RemoveEmptyBasketLines Then ' Lines were removed
GetEditBasket shMonthView.Range("basket").Resize(1, 1) ' Don't "touch" the mix column, so as to rescale all rows proportionally to 100% total. GetEditBasket shMonthView.Range("basket").Resize(1, 1) ' Don't "touch" the mix column, so as to rescale all rows proportionally to 100% total.
Else Else
@ -145,7 +149,7 @@ Private Sub Worksheet_Change(ByVal Target As Range)
End Sub End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If IntersectsWith(Target, Union(Range("basket_new_item"), Range("basket"))) And shConfig.Range("show_basket").value = 1 Then If IntersectsWith(Target, Union(Range("basket_new_item"), Range("basket"))) And shConfig.Range("show_basket").Value = 1 Then
Cancel = True Cancel = True
Call Me.basket_pick(Target) Call Me.basket_pick(Target)
Target.Select Target.Select
@ -154,7 +158,7 @@ End Sub
Sub picker_shortcut() Sub picker_shortcut()
If IntersectsWith(Selection, Range("basket")) And shConfig.Range("show_basket").value = 1 Then If IntersectsWith(Selection, Range("basket")) And shConfig.Range("show_basket").Value = 1 Then
Call Me.basket_pick(Selection) Call Me.basket_pick(Selection)
End If End If
@ -417,7 +421,7 @@ Private Sub BuildJson()
Set np("scenario")("iter") = JsonConverter.ParseJson("[""copy""]") Set np("scenario")("iter") = JsonConverter.ParseJson("[""copy""]")
np("source") = "adj" np("source") = "adj"
np("type") = "new_basket" np("type") = "new_basket"
np("tag") = shMonthView.Range("MonthTag").value np("tag") = shMonthView.Range("MonthTag").Value
Set m = JsonConverter.ParseJson("{}") Set m = JsonConverter.ParseJson("{}")
End If End If
@ -427,7 +431,7 @@ Private Sub BuildJson()
Set o = JsonConverter.ParseJson("{}") Set o = JsonConverter.ParseJson("{}")
o("amount") = sales(pos, 5) o("amount") = sales(pos, 5)
o("qty") = units(pos, 5) o("qty") = units(pos, 5)
Set m(shMonthView.Range("OrderMonths").Cells(pos, 1).value) = JsonConverter.ParseJson(JsonConverter.ConvertToJson(o)) Set m(shMonthView.Range("OrderMonths").Cells(pos, 1).Value) = JsonConverter.ParseJson(JsonConverter.ConvertToJson(o))
End If End If
Else Else
'if something is changing 'if something is changing
@ -475,10 +479,10 @@ Private Sub BuildJson()
If Me.newpart Then If Me.newpart Then
Set np("months") = JsonConverter.ParseJson(JsonConverter.ConvertToJson(m)) Set np("months") = JsonConverter.ParseJson(JsonConverter.ConvertToJson(m))
np("newpart") = shMonthView.Range("basket").Cells(1, 1).value np("newpart") = shMonthView.Range("basket").Cells(1, 1).Value
'get the basket from the sheet 'get the basket from the sheet
Dim basket() As Variant Dim basket() As Variant
basket = shMonthUpdate.Range("U1").CurrentRegion.value basket = shMonthUpdate.Range("U1").CurrentRegion.Value
Set m = JsonConverter.ParseJson(Utils.json_from_table(basket, "basket", False)) Set m = JsonConverter.ParseJson(Utils.json_from_table(basket, "basket", False))
If UBound(basket, 1) <= 2 Then If UBound(basket, 1) <= 2 Then
Set np("basket") = JsonConverter.ParseJson("[" & Utils.json_from_table(basket, "basket", False) & "]") Set np("basket") = JsonConverter.ParseJson("[" & Utils.json_from_table(basket, "basket", False) & "]")
@ -559,13 +563,13 @@ Sub reset()
End Sub End Sub
Sub switch_basket() Sub switch_basket()
shConfig.Range("show_basket").value = 1 - shConfig.Range("show_basket").value shConfig.Range("show_basket").Value = 1 - shConfig.Range("show_basket").Value
Call Me.print_basket Call Me.print_basket
End Sub End Sub
Sub print_basket() Sub print_basket()
If shConfig.Range("show_basket").value = 0 Then If shConfig.Range("show_basket").Value = 0 Then
busy = True busy = True
shMonthView.Range("basket").ClearContents shMonthView.Range("basket").ClearContents
busy = False busy = False
@ -580,10 +584,10 @@ Sub print_basket()
shMonthView.Range("basket").ClearContents shMonthView.Range("basket").ClearContents
For i = 2 To UBound(basket, 1) For i = 2 To UBound(basket, 1)
shMonthView.Range("basket").Resize(1, 1).Offset(i - 2, 0).value = basket(i, 1) shMonthView.Range("basket").Resize(1, 1).Offset(i - 2, 0).Value = basket(i, 1)
shMonthView.Range("basket").Resize(1, 1).Offset(i - 2, 4).value = basket(i, 2) shMonthView.Range("basket").Resize(1, 1).Offset(i - 2, 4).Value = basket(i, 2)
shMonthView.Range("basket").Resize(1, 1).Offset(i - 2, 10).value = basket(i, 3) shMonthView.Range("basket").Resize(1, 1).Offset(i - 2, 10).Value = basket(i, 3)
shMonthView.Range("basket").Resize(1, 1).Offset(i - 2, 15).value = basket(i, 4) shMonthView.Range("basket").Resize(1, 1).Offset(i - 2, 15).Value = basket(i, 4)
Next i Next i
busy = False busy = False
@ -600,9 +604,9 @@ Sub basket_pick(ByRef Target As Range)
If build.useval Then If build.useval Then
busy = True busy = True
.Cells(Target.row + i, 2) = build.cbPart.value .Cells(Target.row + i, 2) = build.cbPart.Value
.Cells(Target.row + i, 6) = rev_cust(build.cbBill.value) .Cells(Target.row + i, 6) = rev_cust(build.cbBill.Value)
.Cells(Target.row + i, 12) = rev_cust(build.cbShip.value) .Cells(Target.row + i, 12) = rev_cust(build.cbShip.Value)
busy = False busy = False
GetEditBasket Selection GetEditBasket Selection
@ -715,7 +719,7 @@ Sub post_adjust()
If WorksheetFunction.CountA(shMonthUpdate.Range("P2:P13")) = 0 Then msg = "Make sure at least one month has Final values for Volume, Price, and Sales." If WorksheetFunction.CountA(shMonthUpdate.Range("P2:P13")) = 0 Then msg = "Make sure at least one month has Final values for Volume, Price, and Sales."
End If End If
If IsEmpty(shMonthView.Range("MonthTag").value) Then msg = "You need to specify a tag for this update." If IsEmpty(shMonthView.Range("MonthTag").Value) Then msg = "You need to specify a tag for this update."
If msg <> "" Then If msg <> "" Then
MsgBox msg, vbOKOnly Or vbExclamation MsgBox msg, vbOKOnly Or vbExclamation
@ -728,8 +732,8 @@ Sub post_adjust()
If Me.newpart Then If Me.newpart Then
Set adjust = JsonConverter.ParseJson(shMonthUpdate.Cells(2, 16)) Set adjust = JsonConverter.ParseJson(shMonthUpdate.Cells(2, 16))
adjust("message") = shMonthView.Range("MonthComment").value adjust("message") = shMonthView.Range("MonthComment").Value
adjust("tag") = shMonthView.Range("MonthTag").value adjust("tag") = shMonthView.Range("MonthTag").Value
jdoc = JsonConverter.ConvertToJson(adjust) jdoc = JsonConverter.ConvertToJson(adjust)
Call handler.request_adjust(jdoc, fail) Call handler.request_adjust(jdoc, fail)
If fail Then Exit Sub If fail Then Exit Sub
@ -737,8 +741,8 @@ Sub post_adjust()
For i = 2 To 13 For i = 2 To 13
If shMonthUpdate.Cells(i, 16) <> "" Then If shMonthUpdate.Cells(i, 16) <> "" Then
Set adjust = JsonConverter.ParseJson(shMonthUpdate.Cells(i, 16)) Set adjust = JsonConverter.ParseJson(shMonthUpdate.Cells(i, 16))
adjust("message") = shMonthView.Range("MonthComment").value adjust("message") = shMonthView.Range("MonthComment").Value
adjust("tag") = shMonthView.Range("MonthTag").value adjust("tag") = shMonthView.Range("MonthTag").Value
jdoc = JsonConverter.ConvertToJson(adjust) jdoc = JsonConverter.ConvertToJson(adjust)
Call handler.request_adjust(jdoc, fail) Call handler.request_adjust(jdoc, fail)
If fail Then Exit Sub If fail Then Exit Sub
@ -752,7 +756,7 @@ End Sub
Sub build_new() Sub build_new()
shConfig.Range("rebuild").value = 1 shConfig.Range("rebuild").Value = 1
Dim i As Long Dim i As Long
Dim j As Long Dim j As Long
Dim basket() As Variant Dim basket() As Variant
@ -800,7 +804,7 @@ Sub new_part()
cust = Utils.SHTp_Get(shMonthUpdate.Name, 1, 27, True) cust = Utils.SHTp_Get(shMonthUpdate.Name, 1, 27, True)
If Not Utils.TBLp_Aggregate(cust, True, True, True, Array(0, 1), Array("S", "S"), Array(2)) Then If Not Utils.TBLp_Aggregate(cust, True, True, True, Array(0, 1), Array("S", "S"), Array(2)) Then
MsgBox ("error building customer mix") MsgBox ("Error building customer mix.")
End If End If
'--------inquire for new part to join with cust mix-------------------------------------------- '--------inquire for new part to join with cust mix--------------------------------------------
@ -816,14 +820,14 @@ Sub new_part()
With shMonthView.Range("basket") With shMonthView.Range("basket")
.ClearContents .ClearContents
For i = 1 To UBound(cust, 2) For i = 1 To UBound(cust, 2)
.Cells(i, 1) = part.cbPart.value .Cells(i, 1) = part.cbPart.Value
.Cells(i, 5) = cust(0, i) .Cells(i, 5) = cust(0, i)
.Cells(i, 11) = cust(1, i) .Cells(i, 11) = cust(1, i)
.Cells(i, 16) = CDbl(cust(2, i)) .Cells(i, 16) = CDbl(cust(2, i))
Next i Next i
End With End With
shConfig.Range("new_part").value = 1 shConfig.Range("new_part").Value = 1
'------copy revised basket to _month storage--------------------------------------------------- '------copy revised basket to _month storage---------------------------------------------------
@ -886,18 +890,18 @@ Sub new_part()
'force basket to show to demonstrate the part was changed 'force basket to show to demonstrate the part was changed
shConfig.Range("show_basket").value = 1 shConfig.Range("show_basket").Value = 1
Call Me.print_basket Call Me.print_basket
busy = False busy = False
End Sub End Sub
Function newpart() As Boolean Function newpart() As Boolean
newpart = shConfig.Range("new_part").value = 1 newpart = shConfig.Range("new_part").Value = 1
End Function End Function
Private Sub Worksheet_Deactivate() Private Sub Worksheet_Deactivate()
Forecasting.shMonthView.Visible = IIf(shConfig.Range("debug_mode").value, xlSheetVisible, xlSheetHidden) Forecasting.shMonthView.Visible = IIf(shConfig.Range("debug_mode").Value, xlSheetVisible, xlSheetHidden)
End Sub End Sub

View File

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

View File

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

View File

@ -339,6 +339,7 @@ SELECT
,COALESCE(log.doc->>'tag','') "tag" ,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment" ,log.doc->>'message' "comment"
,log.doc->>'type' module ,log.doc->>'type' module
,round(b.units * i.nwht * CASE i.nwun WHEN 'KG' THEN 2.2046 ELSE 1 END, 2) pounds
FROM FROM
basemix b basemix b
CROSS JOIN log CROSS JOIN log
@ -435,6 +436,7 @@ FROM
,sum(cost_loc) cost_loc ,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd ,sum(cost_usd) cost_usd
,sum(units) units ,sum(units) units
,sum(pounds) pounds
FROM FROM
ins ins
GROUP BY GROUP BY

View File

@ -36,6 +36,7 @@ target AS (select target_increment incr)
,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_loc,0)) cost_loc --history part mix
,sum(coalesce(cost_usd,0)) cost_usd ,sum(coalesce(cost_usd,0)) cost_usd
,sum(coalesce(pounds,0)) pounds
,calc_status --0 ,calc_status --0
,flag --0 ,flag --0
,order_date --history date mix ,order_date --history date mix
@ -173,6 +174,7 @@ target AS (select target_increment incr)
,COALESCE(log.doc->>'tag','') "tag" ,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment" ,log.doc->>'message' "comment"
,log.doc->>'type' module ,log.doc->>'type' module
,0::numeric pounds
FROM FROM
basemix b basemix b
CROSS JOIN scale s CROSS JOIN scale s
@ -227,6 +229,7 @@ target AS (select target_increment incr)
,sum(cost_loc) cost_loc ,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd ,sum(cost_usd) cost_usd
,sum(units) units ,sum(units) units
,sum(pounds) pounds
FROM FROM
ins ins
GROUP BY GROUP BY

View File

@ -72,6 +72,7 @@ target AS (select incr_qty qincr)
,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_loc,0)) cost_loc --history part mix
,sum(coalesce(cost_usd,0)) cost_usd ,sum(coalesce(cost_usd,0)) cost_usd
,sum(coalesce(pounds,0)) pounds
,calc_status --0 ,calc_status --0
,flag --0 ,flag --0
,order_date --history date mix ,order_date --history date mix
@ -202,6 +203,7 @@ target AS (select incr_qty qincr)
,COALESCE(log.doc->>'tag','') "tag" ,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment" ,log.doc->>'message' "comment"
,log.doc->>'type' module ,log.doc->>'type' module
,round(pounds*s.factor, 2) pounds
FROM FROM
basemix b basemix b
CROSS JOIN scale s CROSS JOIN scale s
@ -254,6 +256,7 @@ FROM
,sum(cost_loc) cost_loc ,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd ,sum(cost_usd) cost_usd
,sum(units) units ,sum(units) units
,sum(pounds) pounds
FROM FROM
ins ins
GROUP BY GROUP BY

View File

@ -72,6 +72,7 @@ target AS (select target_vol vincr, target_prc pincr)
,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_loc,0)) cost_loc --history part mix
,sum(coalesce(cost_usd,0)) cost_usd ,sum(coalesce(cost_usd,0)) cost_usd
,sum(coalesce(pounds,0)) pounds
,calc_status --0 ,calc_status --0
,flag --0 ,flag --0
,order_date --history date mix ,order_date --history date mix
@ -201,6 +202,7 @@ target AS (select target_vol vincr, target_prc pincr)
,COALESCE(log.doc->>'tag','') "tag" ,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment" ,log.doc->>'message' "comment"
,log.doc->>'type' module ,log.doc->>'type' module
,round(pounds*s.factor, 2) pounds
FROM FROM
basemix b basemix b
CROSS JOIN vscale s CROSS JOIN vscale s
@ -282,6 +284,7 @@ FROM
,COALESCE(log.doc->>'tag','') "tag" ,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment" ,log.doc->>'message' "comment"
,log.doc->>'type' module ,log.doc->>'type' module
,0::numeric pounds
FROM FROM
volume b volume b
CROSS JOIN pscale s CROSS JOIN pscale s
@ -336,6 +339,7 @@ FROM
,sum(cost_loc) cost_loc ,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd ,sum(cost_usd) cost_usd
,sum(units) units ,sum(units) units
,sum(pounds) pounds
FROM FROM
ins ins
GROUP BY GROUP BY

View File

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