Compare commits
	
		
			3 Commits
		
	
	
		
			12c17b0be6
			...
			86225ea7e5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 86225ea7e5 | ||
|  | fde6c97964 | ||
|  | 81174b5d57 | 
| @ -382,15 +382,15 @@ End Function | |||||||
| 
 | 
 | ||||||
| Public Function ARRAYp_MakeInteger(ParamArray items()) As Integer() | Public Function ARRAYp_MakeInteger(ParamArray items()) As Integer() | ||||||
| 
 | 
 | ||||||
|     Dim x() As Integer |     Dim X() As Integer | ||||||
|     Dim i As Integer |     Dim i As Integer | ||||||
|     ReDim x(UBound(items)) |     ReDim X(UBound(items)) | ||||||
| 
 | 
 | ||||||
|     For i = 0 To UBound(items()) |     For i = 0 To UBound(items()) | ||||||
|         x(i) = items(i) |         X(i) = items(i) | ||||||
|     Next i |     Next i | ||||||
| 
 | 
 | ||||||
|     ARRAYp_MakeInteger = x |     ARRAYp_MakeInteger = X | ||||||
| 
 | 
 | ||||||
| End Function | End Function | ||||||
| 
 | 
 | ||||||
| @ -604,15 +604,17 @@ Sub frmListBoxHeader(ByRef hdr As MSForms.listbox, ByRef det As MSForms.listbox, | |||||||
|     'lbHEAD.ZOrder (0) |     'lbHEAD.ZOrder (0) | ||||||
|     hdr.SpecialEffect = fmSpecialEffectFlat |     hdr.SpecialEffect = fmSpecialEffectFlat | ||||||
|     'hdr.BackColor = RGB(200, 200, 200) |     'hdr.BackColor = RGB(200, 200, 200) | ||||||
|     hdr.Height = 10 |     'hdr.Height = 15 | ||||||
| 
 | 
 | ||||||
|     ' align header to body (should be done last!) |     ' align header to body (should be done last!) | ||||||
|     hdr.width = det.width |     hdr.width = det.width | ||||||
|     hdr.Left = det.Left |     hdr.Left = det.Left | ||||||
|     hdr.Top = det.Top - (hdr.Height - 1) |     hdr.Top = det.Top - (hdr.Height + 3) | ||||||
| 
 | 
 | ||||||
| End Sub | End Sub | ||||||
| 
 | 
 | ||||||
| 
 | Public Function IntersectsWith(Range1 As Range, Range2 As Range) As Boolean | ||||||
|  |     IntersectsWith = Not Application.Intersect(Range1, Range2) Is Nothing | ||||||
|  | End Function | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,10 +1,10 @@ | |||||||
| VERSION 5.00 | VERSION 5.00 | ||||||
| Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} build  | Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} build  | ||||||
|    Caption         =   "UserForm1" |    Caption         =   "Change the Mix" | ||||||
|    ClientHeight    =   3015 |    ClientHeight    =   1590 | ||||||
|    ClientLeft      =   120 |    ClientLeft      =   120 | ||||||
|    ClientTop       =   465 |    ClientTop       =   465 | ||||||
|    ClientWidth     =   8100 |    ClientWidth     =   10725 | ||||||
|    OleObjectBlob   =   "build.frx":0000 |    OleObjectBlob   =   "build.frx":0000 | ||||||
|    StartUpPosition =   1  'CenterOwner |    StartUpPosition =   1  'CenterOwner | ||||||
| End | End | ||||||
| @ -13,61 +13,27 @@ 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 part As String |  | ||||||
| Public bill As String |  | ||||||
| Public ship As String |  | ||||||
| Public useval As Boolean |  | ||||||
| Option Explicit | Option Explicit | ||||||
| 
 | 
 | ||||||
| Private Sub cbBill_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) | Public useval As Boolean | ||||||
|     Select Case KeyCode | 
 | ||||||
|         Case 13 | Private Sub cmdCancel_Click() | ||||||
|             useval = True |     useval = False | ||||||
|             Me.Hide |     Me.Hide | ||||||
|         Case 27 |  | ||||||
|             useval = False |  | ||||||
|             Me.Hide |  | ||||||
|     End Select |  | ||||||
| End Sub | End Sub | ||||||
| 
 | 
 | ||||||
| 
 | Private Sub cmdOK_Click() | ||||||
| Private Sub cbPart_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) |     useval = True | ||||||
| 
 |     Me.Hide | ||||||
|     Select Case KeyCode |  | ||||||
|         Case 13 |  | ||||||
|             useval = True |  | ||||||
|             Me.Hide |  | ||||||
|         Case 27 |  | ||||||
|             useval = False |  | ||||||
|             Me.Hide |  | ||||||
|     End Select |  | ||||||
| 
 |  | ||||||
| End Sub | End Sub | ||||||
| 
 | 
 | ||||||
| 
 | Public Sub Initialize(part As String, billTo As String, shipTo As String) | ||||||
| Private Sub cbShip_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) |     cbPart.list = shSupportingData.ListObjects("ITEM").DataBodyRange.Value | ||||||
|     Select Case KeyCode |     cbPart.Value = part | ||||||
|         Case 13 |     cbBill.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.Value | ||||||
|             useval = True |     cbBill.Value = billTo | ||||||
|             Me.Hide |     cbShip.list = shSupportingData.ListObjects("CUSTOMER").DataBodyRange.Value | ||||||
|         Case 27 |     cbShip.Value = shipTo | ||||||
|             useval = False |  | ||||||
|             Me.Hide |  | ||||||
|     End Select |  | ||||||
| End Sub |  | ||||||
| 
 |  | ||||||
| Private Sub UserForm_Activate() |  | ||||||
|      |      | ||||||
|     useval = False |     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 | End Sub | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								VBA/build.frx
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								VBA/build.frx
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -1,7 +1,7 @@ | |||||||
| VERSION 5.00 | VERSION 5.00 | ||||||
| Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} changes  | Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} changes  | ||||||
|    Caption         =   "History" |    Caption         =   "History" | ||||||
|    ClientHeight    =   7785 |    ClientHeight    =   7815 | ||||||
|    ClientLeft      =   120 |    ClientLeft      =   120 | ||||||
|    ClientTop       =   465 |    ClientTop       =   465 | ||||||
|    ClientWidth     =   16710 |    ClientWidth     =   16710 | ||||||
| @ -13,93 +13,40 @@ 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 | ||||||
| Private x As Variant | Private X As Variant | ||||||
| 
 | 
 | ||||||
| Private Sub cbCancel_Click() | Private Sub cbCancel_Click() | ||||||
| 
 |  | ||||||
|     Me.Hide |     Me.Hide | ||||||
| 
 |  | ||||||
| End Sub | End Sub | ||||||
| 
 | 
 | ||||||
| Private Sub cbUndo_Click() | Private Sub cbUndo_Click() | ||||||
| 
 |  | ||||||
|      |  | ||||||
|     Call Me.delete_selected |     Call Me.delete_selected | ||||||
| 
 |  | ||||||
| End Sub | End Sub | ||||||
| 
 | 
 | ||||||
| Private Sub lbHist_Change() | Private Sub lbHist_Change() | ||||||
| 
 |  | ||||||
|     Dim i As Integer |     Dim i As Integer | ||||||
| 
 | 
 | ||||||
|     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 | ||||||
| 
 |  | ||||||
| End Sub | 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() | Private Sub UserForm_Activate() | ||||||
| 
 |  | ||||||
|     Dim fail As Boolean |     Dim fail As Boolean | ||||||
|      |      | ||||||
|     'x = handler.list_changes("{""user"":""" & Application.UserName & """}", fail) |     X = handler.list_changes("{""scenario"":{""quota_rep_descr"":""" & shData.Cells(2, 5) & """}}", fail) | ||||||
|     x = handler.list_changes("{""scenario"":{""quota_rep_descr"":""" & shData.Cells(2, 5) & """}}", fail) |  | ||||||
|     If fail Then |     If fail Then | ||||||
|         Me.Hide |         Me.Hide | ||||||
|         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") | ||||||
|      |  | ||||||
|      |  | ||||||
|     ' 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 | End Sub | ||||||
| 
 | 
 | ||||||
| Sub delete_selected() | Sub delete_selected() | ||||||
| 
 |  | ||||||
|     Dim logid As Integer |     Dim logid As Integer | ||||||
|     Dim i As Integer |     Dim i As Integer | ||||||
|     Dim fail As Boolean |     Dim fail As Boolean | ||||||
| @ -109,12 +56,11 @@ Sub delete_selected() | |||||||
|         Exit Sub |         Exit Sub | ||||||
|     End If |     End If | ||||||
|      |      | ||||||
|      |  | ||||||
|     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 | ||||||
|             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 | ||||||
| @ -124,5 +70,4 @@ Sub delete_selected() | |||||||
|      |      | ||||||
|     Me.lbHist.clear |     Me.lbHist.clear | ||||||
|     Me.Hide |     Me.Hide | ||||||
| 
 |  | ||||||
| End Sub | End Sub | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								VBA/changes.frx
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								VBA/changes.frx
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										999
									
								
								VBA/fpvt.frm
									
									
									
									
									
								
							
							
						
						
									
										999
									
								
								VBA/fpvt.frm
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								VBA/fpvt.frx
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								VBA/fpvt.frx
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -98,7 +98,13 @@ Sub pg_main_workset(rep As String) | |||||||
|         Exit Sub |         Exit Sub | ||||||
|     End If |     End If | ||||||
|     Set json = JsonConverter.ParseJson(wr) |     Set json = JsonConverter.ParseJson(wr) | ||||||
|     ReDim res(json("x").Count, 33) |      | ||||||
|  |     If IsNull(json("x")) Then | ||||||
|  |         MsgBox "No data found for " & rep & "." | ||||||
|  |         Exit Sub | ||||||
|  |     End If | ||||||
|  |      | ||||||
|  |     ReDim res(json("x").Count, 34) | ||||||
|      |      | ||||||
|     For i = 1 To UBound(res, 1) |     For i = 1 To UBound(res, 1) | ||||||
|         res(i, 0) = json("x")(i)("bill_cust_descr") |         res(i, 0) = json("x")(i)("bill_cust_descr") | ||||||
| @ -135,6 +141,7 @@ Sub pg_main_workset(rep As String) | |||||||
|         res(i, 31) = json("x")(i)("logid") |         res(i, 31) = json("x")(i)("logid") | ||||||
|         res(i, 32) = json("x")(i)("tag") |         res(i, 32) = json("x")(i)("tag") | ||||||
|         res(i, 33) = json("x")(i)("comment") |         res(i, 33) = json("x")(i)("comment") | ||||||
|  |         res(i, 34) = json("x")(i)("pounds") | ||||||
|     Next i |     Next i | ||||||
|      |      | ||||||
|     res(0, 0) = "bill_cust_descr" |     res(0, 0) = "bill_cust_descr" | ||||||
| @ -171,6 +178,7 @@ Sub pg_main_workset(rep As String) | |||||||
|     res(0, 31) = "logid" |     res(0, 31) = "logid" | ||||||
|     res(0, 32) = "tag" |     res(0, 32) = "tag" | ||||||
|     res(0, 33) = "comment" |     res(0, 33) = "comment" | ||||||
|  |     res(0, 34) = "pounds" | ||||||
|      |      | ||||||
|     Set json = Nothing |     Set json = Nothing | ||||||
| 
 | 
 | ||||||
| @ -209,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.Cells(1, 2) |     server = shConfig.Range("server").Value | ||||||
|      |      | ||||||
|     With req |     With req | ||||||
|         .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All |         .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All | ||||||
| @ -247,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") | ||||||
| @ -289,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 | ||||||
| @ -322,41 +331,31 @@ End Function | |||||||
| Sub load_config() | Sub load_config() | ||||||
| 
 | 
 | ||||||
|     Dim i As Integer |     Dim i As Integer | ||||||
|     Dim j As Integer |  | ||||||
|     '----server to use--------------------------------------------------------- |     '----server to use--------------------------------------------------------- | ||||||
|     handler.server = shConfig.Cells(1, 2) |     handler.server = shConfig.Range("server").Value | ||||||
|     '---basis----------------------------------------------------------------- |     '---basis----------------------------------------------------------------- | ||||||
|     ReDim handler.basis(100) |     With shConfig.ListObjects("BASIS") | ||||||
|     i = 2 |         For i = 1 To .DataBodyRange.Rows.Count | ||||||
|     j = 0 |             ReDim Preserve handler.basis(i - 1) | ||||||
|     Do While shConfig.Cells(2, i) <> "" |             handler.basis(i - 1) = .DataBodyRange(i, 1) | ||||||
|         handler.basis(j) = shConfig.Cells(2, i) |         Next | ||||||
|         j = j + 1 |     End With | ||||||
|         i = i + 1 |  | ||||||
|     Loop |  | ||||||
|     ReDim Preserve handler.basis(j - 1) |  | ||||||
|     '---baseline----------------------------------------------------------------- |     '---baseline----------------------------------------------------------------- | ||||||
|     ReDim handler.baseline(100) |     With shConfig.ListObjects("BASELINE") | ||||||
|     i = 2 |         For i = 1 To .DataBodyRange.Rows.Count | ||||||
|     j = 0 |             ReDim Preserve handler.baseline(i - 1) | ||||||
|     Do While shConfig.Cells(3, i) <> "" |             handler.baseline(i - 1) = .DataBodyRange(i, 1) | ||||||
|         handler.baseline(j) = shConfig.Cells(3, i) |         Next | ||||||
|         j = j + 1 |     End With | ||||||
|         i = i + 1 |  | ||||||
|     Loop |  | ||||||
|     ReDim Preserve handler.baseline(j - 1) |  | ||||||
|     '---adjustments----------------------------------------------------------------- |     '---adjustments----------------------------------------------------------------- | ||||||
|     ReDim handler.adjust(100) |     With shConfig.ListObjects("ADJUST") | ||||||
|     i = 2 |         For i = 1 To .DataBodyRange.Rows.Count | ||||||
|     j = 0 |             ReDim Preserve handler.adjust(i - 1) | ||||||
|     Do While shConfig.Cells(4, i) <> "" |             handler.adjust(i - 1) = .DataBodyRange(i, 1) | ||||||
|         handler.adjust(j) = shConfig.Cells(4, i) |         Next | ||||||
|         j = j + 1 |     End With | ||||||
|         i = i + 1 |  | ||||||
|     Loop |  | ||||||
|     ReDim Preserve handler.adjust(j - 1) |  | ||||||
|     '---plan version-------------------------------------------------------------- |     '---plan version-------------------------------------------------------------- | ||||||
|     handler.plan = shConfig.Cells(9, 2) |     handler.plan = shConfig.Range("budget").Value | ||||||
|      |      | ||||||
| End Sub | End Sub | ||||||
| 
 | 
 | ||||||
| @ -371,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) | ||||||
| @ -456,11 +455,11 @@ 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.Cells(5, 2) = 0 |         shConfig.Range("rebuild").Value = 0 | ||||||
|         shConfig.Cells(6, 2) = 0 |         shConfig.Range("show_basket").Value = 0 | ||||||
|         shConfig.Cells(7, 2) = 0 |         shConfig.Range("new_part").Value = 0 | ||||||
|          |          | ||||||
|         shMonthView.load_sheet |         shMonthView.LoadSheet | ||||||
|      |      | ||||||
|     End With |     End With | ||||||
|          |          | ||||||
| @ -491,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.Cells(1, 2) |     server = shConfig.Range("server").Value | ||||||
|      |      | ||||||
|     With req |     With req | ||||||
|         .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All |         .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All | ||||||
| @ -505,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 | ||||||
| @ -565,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 | ||||||
| @ -604,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.Cells(1, 2) |     server = shConfig.Range("server").Value | ||||||
|      |      | ||||||
|     With req |     With req | ||||||
|         .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All |         .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All | ||||||
| @ -618,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 | ||||||
|  | |||||||
| @ -1,10 +1,10 @@ | |||||||
| VERSION 5.00 | VERSION 5.00 | ||||||
| Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} openf  | Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} openf  | ||||||
|    Caption         =   "Open a Forecast" |    Caption         =   "Open a Forecast" | ||||||
|    ClientHeight    =   2025 |    ClientHeight    =   1365 | ||||||
|    ClientLeft      =   120 |    ClientLeft      =   120 | ||||||
|    ClientTop       =   465 |    ClientTop       =   465 | ||||||
|    ClientWidth     =   3825 |    ClientWidth     =   6825 | ||||||
|    OleObjectBlob   =   "openf.frx":0000 |    OleObjectBlob   =   "openf.frx":0000 | ||||||
|    StartUpPosition =   1  'CenterOwner |    StartUpPosition =   1  'CenterOwner | ||||||
| End | End | ||||||
| @ -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,11 +33,8 @@ End Sub | |||||||
| 
 | 
 | ||||||
| Private Sub UserForm_Activate() | Private Sub UserForm_Activate() | ||||||
| 
 | 
 | ||||||
|     'handler.server = "http://192.168.1.69:3000" |     handler.server = shConfig.Range("server").Value | ||||||
|     handler.server = shConfig.Cells(1, 2) |     cbDSM.list = shSupportingData.ListObjects("DSM").DataBodyRange.Value | ||||||
|      |  | ||||||
|     openf.Caption = "Select a DSM" |  | ||||||
|     cbDSM.list = shSupportingData.ListObjects("DSM").DataBodyRange.value |  | ||||||
| 
 | 
 | ||||||
| End Sub | End Sub | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								VBA/openf.frx
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								VBA/openf.frx
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										33
									
								
								VBA/part.frm
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								VBA/part.frm
									
									
									
									
									
								
							| @ -1,10 +1,10 @@ | |||||||
| VERSION 5.00 | VERSION 5.00 | ||||||
| Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} part  | Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} part  | ||||||
|    Caption         =   "Part Picker" |    Caption         =   "Part Picker" | ||||||
|    ClientHeight    =   1080 |    ClientHeight    =   1335 | ||||||
|    ClientLeft      =   120 |    ClientLeft      =   120 | ||||||
|    ClientTop       =   465 |    ClientTop       =   465 | ||||||
|    ClientWidth     =   8100 |    ClientWidth     =   9285.001 | ||||||
|    OleObjectBlob   =   "part.frx":0000 |    OleObjectBlob   =   "part.frx":0000 | ||||||
|    StartUpPosition =   1  'CenterOwner |    StartUpPosition =   1  'CenterOwner | ||||||
| End | End | ||||||
| @ -13,34 +13,23 @@ 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 part As String |  | ||||||
| Public bill As String |  | ||||||
| Public ship As String |  | ||||||
| Public useval As Boolean |  | ||||||
| Option Explicit | Option Explicit | ||||||
| 
 | 
 | ||||||
|  | Public useval As Boolean | ||||||
| 
 | 
 | ||||||
| Private Sub cbPart_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) | Private Sub cmdCancel_Click() | ||||||
| 
 |     useval = False | ||||||
|     Select Case KeyCode |     Me.Hide | ||||||
|         Case 13 |  | ||||||
|             useval = True |  | ||||||
|             Me.Hide |  | ||||||
|         Case 27 |  | ||||||
|             useval = False |  | ||||||
|             Me.Hide |  | ||||||
|     End Select |  | ||||||
| 
 |  | ||||||
| End Sub | End Sub | ||||||
| 
 | 
 | ||||||
| 
 | Private Sub cmdOK_Click() | ||||||
|  |     useval = True | ||||||
|  |     Me.Hide | ||||||
|  | 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 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								VBA/part.frx
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								VBA/part.frx
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -7,3 +7,25 @@ Attribute VB_GlobalNameSpace = False | |||||||
| Attribute VB_Creatable = False | Attribute VB_Creatable = False | ||||||
| Attribute VB_PredeclaredId = True | Attribute VB_PredeclaredId = True | ||||||
| Attribute VB_Exposed = 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 | ||||||
|  | 
 | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								VBA/shHelp.cls
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								VBA/shHelp.cls
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | |||||||
|  | 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 | ||||||
|  | 
 | ||||||
							
								
								
									
										1050
									
								
								VBA/shMonthView.cls
									
									
									
									
									
								
							
							
						
						
									
										1050
									
								
								VBA/shMonthView.cls
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										148
									
								
								VBA/shWalk.cls
									
									
									
									
									
								
							
							
						
						
									
										148
									
								
								VBA/shWalk.cls
									
									
									
									
									
								
							| @ -7,108 +7,108 @@ Attribute VB_GlobalNameSpace = False | |||||||
| Attribute VB_Creatable = False | Attribute VB_Creatable = False | ||||||
| Attribute VB_PredeclaredId = True | Attribute VB_PredeclaredId = True | ||||||
| Attribute VB_Exposed = True | Attribute VB_Exposed = True | ||||||
| ' Option Explicit | 'Option Explicit | ||||||
| ' | ' | ||||||
| ' Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) | 'Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) | ||||||
| '     Dim pt As PivotTable | '    Dim pt As PivotTable | ||||||
| '     Set pt = ActiveSheet.PivotTables("ptWalk") | '    Set pt = ActiveSheet.PivotTables("ptWalk") | ||||||
| '     Dim intersec As Range | '    Dim intersec As Range | ||||||
| '     Set intersec = Intersect(Target, pt.DataBodyRange) | '    Set intersec = Intersect(Target, pt.DataBodyRange) | ||||||
| ' | ' | ||||||
| '     If intersec Is Nothing Then | '    If intersec Is Nothing Then | ||||||
| '         Exit Sub | '        Exit Sub | ||||||
| '     ElseIf intersec.address <> Target.address Then | '    ElseIf intersec.address <> Target.address Then | ||||||
| '         Exit Sub | '        Exit Sub | ||||||
| '     End If | '    End If | ||||||
| ' | ' | ||||||
| '     Cancel = True | '    Cancel = True | ||||||
| ' | ' | ||||||
| '     Dim i As Long | '    Dim i As Long | ||||||
| '     Dim j As Long | '    Dim j As Long | ||||||
| '     Dim k As Long | '    Dim k As Long | ||||||
| ' | ' | ||||||
| '     Dim ri As PivotItemList | '    Dim ri As PivotItemList | ||||||
| '     Dim ci As PivotItemList | '    Dim ci As PivotItemList | ||||||
| '     Dim df As Object | '    Dim df As Object | ||||||
| '     Dim rd As Object | '    Dim rd As Object | ||||||
| '     Dim cd As Object | '    Dim cd As Object | ||||||
| '     Dim dd As Object | '    Dim dd As Object | ||||||
| ' | ' | ||||||
| '     Dim pf As PivotField | '    Dim pf As PivotField | ||||||
| '     Dim pi As PivotItem | '    Dim pi As PivotItem | ||||||
| ' | ' | ||||||
| '     Set ri = Target.Cells.PivotCell.RowItems | '    Set ri = Target.Cells.PivotCell.RowItems | ||||||
| '     Set ci = Target.Cells.PivotCell.ColumnItems | '    Set ci = Target.Cells.PivotCell.ColumnItems | ||||||
| '     Set df = Target.Cells.PivotCell.DataField | '    Set df = Target.Cells.PivotCell.DataField | ||||||
| ' | ' | ||||||
| '     Set rd = Target.Cells.PivotTable.RowFields | '    Set rd = Target.Cells.PivotTable.RowFields | ||||||
| '     Set cd = Target.Cells.PivotTable.ColumnFields | '    Set cd = Target.Cells.PivotTable.ColumnFields | ||||||
| ' | ' | ||||||
| '     ReDim handler.sc(ri.Count, 1) | '    ReDim handler.sc(ri.Count, 1) | ||||||
| ' | ' | ||||||
| '     handler.sql = "" | '    handler.sql = "" | ||||||
| '     handler.jsql = "" | '    handler.jsql = "" | ||||||
| ' | ' | ||||||
| '     For i = 1 To ri.Count | '    For i = 1 To ri.Count | ||||||
| '         If i <> 1 Then handler.sql = handler.sql & vbCrLf & "AND " | '        If i <> 1 Then handler.sql = handler.sql & vbCrLf & "AND " | ||||||
| '         If i <> 1 Then handler.jsql = handler.jsql & vbCrLf & "," | '        If i <> 1 Then handler.jsql = handler.jsql & vbCrLf & "," | ||||||
| '         handler.sql = handler.sql & rd(piv_pos(rd, i)).Name & " = '" & escape_sql(ri(i).Name) & "'" | '        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) & """" | '        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, 0) = rd(piv_pos(rd, i)).Name | ||||||
| '         handler.sc(i - 1, 1) = ri(i).Name | '        handler.sc(i - 1, 1) = ri(i).Name | ||||||
| '     Next i | '    Next i | ||||||
| ' | ' | ||||||
| '     scenario = "{" & handler.jsql & "}" | '    scenario = "{" & handler.jsql & "}" | ||||||
| ' | ' | ||||||
| '     Call handler.load_config | '    Call handler.load_config | ||||||
| '     Call handler.load_fpvt | '    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 | '    For i = 1 To list.Count | ||||||
| '         If list(i).Position = target_pos Then | '        If list(i).Position = target_pos Then | ||||||
| '             piv_pos = i | '            piv_pos = i | ||||||
| '             Exit Function | '            Exit Function | ||||||
| '         End If | '        End If | ||||||
| '     Next i | '    Next i | ||||||
| '     'should not get to this point | '    '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 | '    For i = 1 To pt.PivotFields.Count | ||||||
| '         If pt.PivotFields(i).Name = field_name Then | '        If pt.PivotFields(i).Name = field_name Then | ||||||
| '             piv_fld_index = i | '            piv_fld_index = i | ||||||
| '             Exit Function | '            Exit Function | ||||||
| '         End If | '        End If | ||||||
| '     Next i | '    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, "'", "''") | ||||||
| '     text = Replace(text, """", "\""") | '    text = Replace(text, """", "\""") | ||||||
| '     If text = "(blank)" Then text = "" | '    If text = "(blank)" Then text = "" | ||||||
| '     escape_json = 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, "'", "''") | ||||||
| '     text = Replace(text, """", """""") | '    text = Replace(text, """", """""") | ||||||
| '     If text = "(blank)" Then text = "" | '    If text = "(blank)" Then text = "" | ||||||
| '     escape_sql = text | '    escape_sql = text | ||||||
| ' | ' | ||||||
| ' End Function | 'End Function | ||||||
| ' | ' | ||||||
| ' | ' | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										795
									
								
								build/build_baseline_from_FAnalysis.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										795
									
								
								build/build_baseline_from_FAnalysis.sql
									
									
									
									
									
										Normal 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 | ||||||
|  |         -- | ||||||
|  | */ | ||||||
							
								
								
									
										32
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								index.js
									
									
									
									
									
								
							| @ -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 }; | ||||||
| } | } | ||||||
|  | |||||||
| @ -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 | ||||||
|  | |||||||
| @ -1,91 +1,92 @@ | |||||||
| WITH rows AS ( | WITH rows AS ( | ||||||
| SELECT | SELECT | ||||||
|     ---------customer info----------------- |     ---------customer info----------------- | ||||||
|     bill_cust_descr |     bill_cust_descr | ||||||
|     ,billto_group |     ,billto_group | ||||||
|     ,ship_cust_descr |     ,ship_cust_descr | ||||||
|     ,shipto_group |     ,shipto_group | ||||||
|     ,quota_rep_descr |     ,quota_rep_descr | ||||||
|     ,director |     ,director | ||||||
|     ,segm |     ,segm | ||||||
|     ,substance |     ,substance | ||||||
|     ,chan |     ,chan | ||||||
|     ,chansub |     ,chansub | ||||||
|     ---------product info------------------ |     ---------product info------------------ | ||||||
|     ,majg_descr |     ,majg_descr | ||||||
|     ,ming_descr |     ,ming_descr | ||||||
|     ,majs_descr |     ,majs_descr | ||||||
|     ,mins_descr |     ,mins_descr | ||||||
|     --,brand |     --,brand | ||||||
|     --,part_family |     --,part_family | ||||||
|     ,part_group |     ,part_group | ||||||
|     ,branding |     ,branding | ||||||
|     --,color |     --,color | ||||||
|     ,part_descr |     ,part_descr | ||||||
|     ---------dates------------------------- |     ---------dates------------------------- | ||||||
|     ,order_season |     ,order_season | ||||||
|     ,order_month |     ,order_month | ||||||
|     ,ship_season |     ,ship_season | ||||||
|     ,ship_month |     ,ship_month | ||||||
|     ,request_season |     ,request_season | ||||||
|     ,request_month |     ,request_month | ||||||
|     ,promo |     ,promo | ||||||
|     --------values------------------------- |     --------values------------------------- | ||||||
|     ,sum(value_loc) value_loc |     ,sum(value_loc) value_loc | ||||||
|     ,sum(value_usd) value_usd |     ,sum(value_usd) value_usd | ||||||
|     ,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 | ||||||
|     ,version |     ,sum(pounds) pounds | ||||||
|     ,iter |     ,version | ||||||
|     ,logid |     ,iter | ||||||
|     ,tag |     ,logid | ||||||
|     ,comment |     ,tag | ||||||
| FROM |     ,comment | ||||||
|     rlarp.osm_pool | FROM | ||||||
| WHERE |     rlarp.osm_pool | ||||||
|     quota_rep_descr = 'rep_replace' | WHERE | ||||||
| GROUP BY |     quota_rep_descr = 'rep_replace' | ||||||
|         ---------customer info----------------- | GROUP BY | ||||||
|     bill_cust_descr |         ---------customer info----------------- | ||||||
|     ,billto_group |     bill_cust_descr | ||||||
|     ,ship_cust_descr |     ,billto_group | ||||||
|     ,shipto_group |     ,ship_cust_descr | ||||||
|     ,quota_rep_descr |     ,shipto_group | ||||||
|     ,director |     ,quota_rep_descr | ||||||
|     ,segm |     ,director | ||||||
|     ,substance |     ,segm | ||||||
|     ,chan |     ,substance | ||||||
|     ,chansub |     ,chan | ||||||
|     ---------product info------------------ |     ,chansub | ||||||
|     ,majg_descr |     ---------product info------------------ | ||||||
|     ,ming_descr |     ,majg_descr | ||||||
|     ,majs_descr |     ,ming_descr | ||||||
|     ,mins_descr |     ,majs_descr | ||||||
|     --,brand |     ,mins_descr | ||||||
|     --,part_family |     --,brand | ||||||
|     ,part_group |     --,part_family | ||||||
|     ,branding |     ,part_group | ||||||
|     --,color |     ,branding | ||||||
|     ,part_descr |     --,color | ||||||
|     ---------dates------------------------- |     ,part_descr | ||||||
|     ,order_season |     ---------dates------------------------- | ||||||
|     ,order_month |     ,order_season | ||||||
|     ,ship_season |     ,order_month | ||||||
|     ,ship_month |     ,ship_season | ||||||
|     ,request_season |     ,ship_month | ||||||
|     ,request_month |     ,request_season | ||||||
|     ,promo |     ,request_month | ||||||
|     ,version |     ,promo | ||||||
|     ,iter |     ,version | ||||||
|     ,logid |     ,iter | ||||||
|     ,tag |     ,logid | ||||||
|     ,comment |     ,tag | ||||||
|     ,substance |     ,comment | ||||||
| ORDER BY |     ,substance | ||||||
|     logid ASC | ORDER BY | ||||||
| ) |     logid ASC | ||||||
| SELECT | ) | ||||||
|     json_agg(row_to_json(rows)) x | SELECT | ||||||
| FROM |     json_agg(row_to_json(rows)) x | ||||||
|     rows | FROM | ||||||
|  |     rows | ||||||
|  | |||||||
| @ -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 | ||||||
| @ -354,11 +355,11 @@ FROM | |||||||
|     LEFT OUTER JOIN rlarp.repc r ON |     LEFT OUTER JOIN rlarp.repc r ON | ||||||
|              r.rcode =  CASE WHEN i.ming = 'B52' THEN 'PW' ELSE |              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 |                             --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),'') <> ''  |                             CASE WHEN COALESCE(seg.segm,'') = 'Retail' AND  COALESCE((SELECT currep FROM lgpgm.usrcust where cucust = bc.bvcust),'') <> '' | ||||||
|                                 THEN  |                                 THEN | ||||||
|                                     (SELECT currep FROM lgpgm.usrcust where cucust = bc.bvcust) |                                     (SELECT currep FROM lgpgm.usrcust where cucust = bc.bvcust) | ||||||
|                                 --default logic |                                 --default logic | ||||||
|                                 ELSE  |                                 ELSE | ||||||
|                                     CASE SUBSTR(bc.bvclas,2,3) |                                     CASE SUBSTR(bc.bvclas,2,3) | ||||||
|                                         WHEN 'DIS' THEN sc.bvsalm |                                         WHEN 'DIS' THEN sc.bvsalm | ||||||
|                                         ELSE bc.bvsalm |                                         ELSE bc.bvsalm | ||||||
| @ -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 | ||||||
|  | |||||||
| @ -1,19 +1,19 @@ | |||||||
| WITH  | WITH | ||||||
| target AS (select target_increment incr) | target AS (select target_increment incr) | ||||||
| ,basemix AS ( | ,basemix AS ( | ||||||
|     SELECT |     SELECT | ||||||
|         fspr |         fspr | ||||||
|         ,plnt          ---master data  |         ,plnt          ---master data | ||||||
|         ,promo          --history date mix |         ,promo          --history date mix | ||||||
|         ,terms |         ,terms | ||||||
|         ,bill_cust_descr          --history cust mix |         ,bill_cust_descr          --history cust mix | ||||||
|         ,ship_cust_descr          --history cust mix |         ,ship_cust_descr          --history cust mix | ||||||
|         ,dsm |         ,dsm | ||||||
|         ,quota_rep_descr          --master data  |         ,quota_rep_descr          --master data | ||||||
|         ,director |         ,director | ||||||
|         ,billto_group          --master data  |         ,billto_group          --master data | ||||||
|         ,shipto_group |         ,shipto_group | ||||||
|         ,chan          --master data  |         ,chan          --master data | ||||||
|         ,chansub |         ,chansub | ||||||
|         ,chan_retail |         ,chan_retail | ||||||
|         ,part |         ,part | ||||||
| @ -26,18 +26,19 @@ target AS (select target_increment incr) | |||||||
|         ,mins_descr |         ,mins_descr | ||||||
|         ,segm |         ,segm | ||||||
|         ,substance |         ,substance | ||||||
|         ,fs_line          --master data  |         ,fs_line          --master data | ||||||
|         ,r_currency          --history cust mix |         ,r_currency          --history cust mix | ||||||
|         ,r_rate          --master data  |         ,r_rate          --master data | ||||||
|         ,c_currency          --master data  |         ,c_currency          --master data | ||||||
|         ,c_rate          --master data  |         ,c_rate          --master data | ||||||
|         ,sum(coalesce(units,0)) units          --history value |         ,sum(coalesce(units,0)) units          --history value | ||||||
|         ,sum(coalesce(value_loc,0)) value_loc          --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_loc,0)) cost_loc          --history part mix | ||||||
|         ,sum(coalesce(cost_usd,0)) cost_usd |         ,sum(coalesce(cost_usd,0)) cost_usd | ||||||
|         ,calc_status          --0  |         ,sum(coalesce(pounds,0)) pounds | ||||||
|         ,flag          --0  |         ,calc_status          --0 | ||||||
|  |         ,flag          --0 | ||||||
|         ,order_date          --history date mix |         ,order_date          --history date mix | ||||||
|         ,order_month |         ,order_month | ||||||
|         ,order_season |         ,order_season | ||||||
| @ -56,18 +57,18 @@ target AS (select target_increment incr) | |||||||
|         AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments |         AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments | ||||||
|         AND order_date <= ship_date |         AND order_date <= ship_date | ||||||
|     GROUP BY |     GROUP BY | ||||||
|                 fspr |         fspr | ||||||
|         ,plnt          ---master data  |         ,plnt          ---master data | ||||||
|         ,promo          --history date mix |         ,promo          --history date mix | ||||||
|         ,terms |         ,terms | ||||||
|         ,bill_cust_descr          --history cust mix |         ,bill_cust_descr          --history cust mix | ||||||
|         ,ship_cust_descr          --history cust mix |         ,ship_cust_descr          --history cust mix | ||||||
|         ,dsm |         ,dsm | ||||||
|         ,quota_rep_descr          --master data  |         ,quota_rep_descr          --master data | ||||||
|         ,director |         ,director | ||||||
|         ,billto_group          --master data  |         ,billto_group          --master data | ||||||
|         ,shipto_group |         ,shipto_group | ||||||
|         ,chan          --master data  |         ,chan          --master data | ||||||
|         ,chansub |         ,chansub | ||||||
|         ,chan_retail |         ,chan_retail | ||||||
|         ,part |         ,part | ||||||
| @ -80,13 +81,13 @@ target AS (select target_increment incr) | |||||||
|         ,mins_descr |         ,mins_descr | ||||||
|         ,segm |         ,segm | ||||||
|         ,substance |         ,substance | ||||||
|         ,fs_line          --master data  |         ,fs_line          --master data | ||||||
|         ,r_currency          --history cust mix |         ,r_currency          --history cust mix | ||||||
|         ,r_rate          --master data  |         ,r_rate          --master data | ||||||
|         ,c_currency          --master data  |         ,c_currency          --master data | ||||||
|         ,c_rate          --master data  |         ,c_rate          --master data | ||||||
|         ,calc_status          --0  |         ,calc_status          --0 | ||||||
|         ,flag          --0  |         ,flag          --0 | ||||||
|         ,order_date          --history date mix |         ,order_date          --history date mix | ||||||
|         ,order_month |         ,order_month | ||||||
|         ,order_season |         ,order_season | ||||||
| @ -104,7 +105,7 @@ target AS (select target_increment incr) | |||||||
|         ,CASE WHEN (SELECT sum(value_loc * r_rate) FROM basemix) = 0 THEN |         ,CASE WHEN (SELECT sum(value_loc * r_rate) FROM basemix) = 0 THEN | ||||||
|             0 |             0 | ||||||
|         ELSE |         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 |         END factor | ||||||
|         ,CASE WHEN (SELECT sum(value_loc * r_rate) FROM basemix) = 0 THEN |         ,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 |             CASE WHEN ((SELECT incr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM basemix)) <> 0 THEN | ||||||
| @ -123,17 +124,17 @@ target AS (select target_increment incr) | |||||||
| ,final AS ( | ,final AS ( | ||||||
|     SELECT |     SELECT | ||||||
|         fspr |         fspr | ||||||
|         ,plnt          ---master data  |         ,plnt          ---master data | ||||||
|         ,promo          --history date mix |         ,promo          --history date mix | ||||||
|         ,terms |         ,terms | ||||||
|         ,bill_cust_descr          --history cust mix |         ,bill_cust_descr          --history cust mix | ||||||
|         ,ship_cust_descr          --history cust mix |         ,ship_cust_descr          --history cust mix | ||||||
|         ,dsm |         ,dsm | ||||||
|         ,quota_rep_descr          --master data  |         ,quota_rep_descr          --master data | ||||||
|         ,director |         ,director | ||||||
|         ,billto_group          --master data  |         ,billto_group          --master data | ||||||
|         ,shipto_group |         ,shipto_group | ||||||
|         ,chan          --master data  |         ,chan          --master data | ||||||
|         ,chansub |         ,chansub | ||||||
|         ,chan_retail |         ,chan_retail | ||||||
|         ,part |         ,part | ||||||
| @ -146,18 +147,18 @@ target AS (select target_increment incr) | |||||||
|         ,mins_descr |         ,mins_descr | ||||||
|         ,segm |         ,segm | ||||||
|         ,substance |         ,substance | ||||||
|         ,fs_line          --master data  |         ,fs_line          --master data | ||||||
|         ,r_currency          --history cust mix |         ,r_currency          --history cust mix | ||||||
|         ,r_rate          --master data  |         ,r_rate          --master data | ||||||
|         ,c_currency          --master data  |         ,c_currency          --master data | ||||||
|         ,c_rate          --master data  |         ,c_rate          --master data | ||||||
|         ,0::numeric units |         ,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/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 |         ,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_loc | ||||||
|         ,0::numeric cost_usd |         ,0::numeric cost_usd | ||||||
|         ,calc_status          --0  |         ,calc_status          --0 | ||||||
|         ,flag          --0  |         ,flag          --0 | ||||||
|         ,order_date          --history date mix |         ,order_date          --history date mix | ||||||
|         ,order_month |         ,order_month | ||||||
|         ,order_season |         ,order_season | ||||||
| @ -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 | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| WITH  | WITH | ||||||
| target AS (select incr_qty qincr) | target AS (select incr_qty qincr) | ||||||
| ,testv AS ( | ,testv AS ( | ||||||
|     SELECT |     SELECT | ||||||
| @ -39,17 +39,17 @@ target AS (select incr_qty qincr) | |||||||
| ,basemix AS ( | ,basemix AS ( | ||||||
|     SELECT |     SELECT | ||||||
|         fspr |         fspr | ||||||
|         ,plnt          ---master data  |         ,plnt          ---master data | ||||||
|         ,promo          --history date mix |         ,promo          --history date mix | ||||||
|         ,terms |         ,terms | ||||||
|         ,bill_cust_descr          --history cust mix |         ,bill_cust_descr          --history cust mix | ||||||
|         ,ship_cust_descr          --history cust mix |         ,ship_cust_descr          --history cust mix | ||||||
|         ,dsm |         ,dsm | ||||||
|         ,quota_rep_descr          --master data  |         ,quota_rep_descr          --master data | ||||||
|         ,director |         ,director | ||||||
|         ,billto_group          --master data  |         ,billto_group          --master data | ||||||
|         ,shipto_group |         ,shipto_group | ||||||
|         ,chan          --master data  |         ,chan          --master data | ||||||
|         ,chansub |         ,chansub | ||||||
|         ,chan_retail |         ,chan_retail | ||||||
|         ,part |         ,part | ||||||
| @ -62,18 +62,19 @@ target AS (select incr_qty qincr) | |||||||
|         ,mins_descr |         ,mins_descr | ||||||
|         ,segm |         ,segm | ||||||
|         ,substance |         ,substance | ||||||
|         ,fs_line          --master data  |         ,fs_line          --master data | ||||||
|         ,r_currency          --history cust mix |         ,r_currency          --history cust mix | ||||||
|         ,r_rate          --master data  |         ,r_rate          --master data | ||||||
|         ,c_currency          --master data  |         ,c_currency          --master data | ||||||
|         ,c_rate          --master data  |         ,c_rate          --master data | ||||||
|         ,sum(coalesce(units,0)) units          --history value |         ,sum(coalesce(units,0)) units          --history value | ||||||
|         ,sum(coalesce(value_loc,0)) value_loc          --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_loc,0)) cost_loc          --history part mix | ||||||
|         ,sum(coalesce(cost_usd,0)) cost_usd |         ,sum(coalesce(cost_usd,0)) cost_usd | ||||||
|         ,calc_status          --0  |         ,sum(coalesce(pounds,0)) pounds | ||||||
|         ,flag          --0  |         ,calc_status          --0 | ||||||
|  |         ,flag          --0 | ||||||
|         ,order_date          --history date mix |         ,order_date          --history date mix | ||||||
|         ,order_month |         ,order_month | ||||||
|         ,order_season |         ,order_season | ||||||
| @ -89,7 +90,7 @@ target AS (select incr_qty qincr) | |||||||
|         -----------------scenario---------------------------- |         -----------------scenario---------------------------- | ||||||
|         where_clause |         where_clause | ||||||
|         -----------------additional params------------------- |         -----------------additional params------------------- | ||||||
|         AND CASE (SELECT flag FROM flagv)  |         AND CASE (SELECT flag FROM flagv) | ||||||
|                 WHEN 'scale all' THEN true |                 WHEN 'scale all' THEN true | ||||||
|                 WHEN 'scale copy' THEN iter IN ('copy','plan','diff') |                 WHEN 'scale copy' THEN iter IN ('copy','plan','diff') | ||||||
|                 WHEN 'scale new part' THEN module = 'new basket' |                 WHEN 'scale new part' THEN module = 'new basket' | ||||||
| @ -98,17 +99,17 @@ target AS (select incr_qty qincr) | |||||||
|         AND order_date <= ship_date |         AND order_date <= ship_date | ||||||
|     GROUP BY |     GROUP BY | ||||||
|         fspr |         fspr | ||||||
|         ,plnt          ---master data  |         ,plnt          ---master data | ||||||
|         ,promo          --history date mix |         ,promo          --history date mix | ||||||
|         ,terms |         ,terms | ||||||
|         ,bill_cust_descr          --history cust mix |         ,bill_cust_descr          --history cust mix | ||||||
|         ,ship_cust_descr          --history cust mix |         ,ship_cust_descr          --history cust mix | ||||||
|         ,dsm |         ,dsm | ||||||
|         ,quota_rep_descr          --master data  |         ,quota_rep_descr          --master data | ||||||
|         ,director |         ,director | ||||||
|         ,billto_group          --master data  |         ,billto_group          --master data | ||||||
|         ,shipto_group |         ,shipto_group | ||||||
|         ,chan          --master data  |         ,chan          --master data | ||||||
|         ,chansub |         ,chansub | ||||||
|         ,chan_retail |         ,chan_retail | ||||||
|         ,part |         ,part | ||||||
| @ -121,13 +122,13 @@ target AS (select incr_qty qincr) | |||||||
|         ,mins_descr |         ,mins_descr | ||||||
|         ,segm |         ,segm | ||||||
|         ,substance |         ,substance | ||||||
|         ,fs_line          --master data  |         ,fs_line          --master data | ||||||
|         ,r_currency          --history cust mix |         ,r_currency          --history cust mix | ||||||
|         ,r_rate          --master data  |         ,r_rate          --master data | ||||||
|         ,c_currency          --master data  |         ,c_currency          --master data | ||||||
|         ,c_rate          --master data  |         ,c_rate          --master data | ||||||
|         ,calc_status          --0  |         ,calc_status          --0 | ||||||
|         ,flag          --0  |         ,flag          --0 | ||||||
|         ,order_date          --history date mix |         ,order_date          --history date mix | ||||||
|         ,order_month |         ,order_month | ||||||
|         ,order_season |         ,order_season | ||||||
| @ -152,17 +153,17 @@ target AS (select incr_qty qincr) | |||||||
| ,final AS ( | ,final AS ( | ||||||
|     SELECT |     SELECT | ||||||
|         fspr |         fspr | ||||||
|         ,plnt          ---master data  |         ,plnt          ---master data | ||||||
|         ,promo          --history date mix |         ,promo          --history date mix | ||||||
|         ,terms |         ,terms | ||||||
|         ,bill_cust_descr          --history cust mix |         ,bill_cust_descr          --history cust mix | ||||||
|         ,ship_cust_descr          --history cust mix |         ,ship_cust_descr          --history cust mix | ||||||
|         ,dsm |         ,dsm | ||||||
|         ,quota_rep_descr          --master data  |         ,quota_rep_descr          --master data | ||||||
|         ,director |         ,director | ||||||
|         ,billto_group          --master data  |         ,billto_group          --master data | ||||||
|         ,shipto_group |         ,shipto_group | ||||||
|         ,chan          --master data  |         ,chan          --master data | ||||||
|         ,chansub |         ,chansub | ||||||
|         ,chan_retail |         ,chan_retail | ||||||
|         ,part |         ,part | ||||||
| @ -175,18 +176,18 @@ target AS (select incr_qty qincr) | |||||||
|         ,mins_descr |         ,mins_descr | ||||||
|         ,segm |         ,segm | ||||||
|         ,substance |         ,substance | ||||||
|         ,fs_line          --master data  |         ,fs_line          --master data | ||||||
|         ,r_currency          --history cust mix |         ,r_currency          --history cust mix | ||||||
|         ,r_rate          --master data  |         ,r_rate          --master data | ||||||
|         ,c_currency          --master data  |         ,c_currency          --master data | ||||||
|         ,c_rate          --master data  |         ,c_rate          --master data | ||||||
|         ,round(units*s.factor    ,2) units |         ,round(units*s.factor    ,2) units | ||||||
|         ,round(value_loc*s.factor,2) value_loc |         ,round(value_loc*s.factor,2) value_loc | ||||||
|         ,round(value_usd*s.factor,2) value_usd |         ,round(value_usd*s.factor,2) value_usd | ||||||
|         ,round(cost_loc*s.factor ,2) cost_loc |         ,round(cost_loc*s.factor ,2) cost_loc | ||||||
|         ,round(cost_usd*s.factor ,2) cost_usd |         ,round(cost_usd*s.factor ,2) cost_usd | ||||||
|         ,calc_status          --0  |         ,calc_status          --0 | ||||||
|         ,flag          --0  |         ,flag          --0 | ||||||
|         ,order_date          --history date mix |         ,order_date          --history date mix | ||||||
|         ,order_month |         ,order_month | ||||||
|         ,order_season |         ,order_season | ||||||
| @ -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 | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| WITH  | WITH | ||||||
| target AS (select target_vol vincr, target_prc pincr) | target AS (select target_vol vincr, target_prc pincr) | ||||||
| ,testv AS ( | ,testv AS ( | ||||||
|     SELECT |     SELECT | ||||||
| @ -39,17 +39,17 @@ target AS (select target_vol vincr, target_prc pincr) | |||||||
| ,basemix AS ( | ,basemix AS ( | ||||||
|     SELECT |     SELECT | ||||||
|         fspr |         fspr | ||||||
|         ,plnt          ---master data  |         ,plnt          ---master data | ||||||
|         ,promo          --history date mix |         ,promo          --history date mix | ||||||
|         ,terms |         ,terms | ||||||
|         ,bill_cust_descr          --history cust mix |         ,bill_cust_descr          --history cust mix | ||||||
|         ,ship_cust_descr          --history cust mix |         ,ship_cust_descr          --history cust mix | ||||||
|         ,dsm |         ,dsm | ||||||
|         ,quota_rep_descr          --master data  |         ,quota_rep_descr          --master data | ||||||
|         ,director |         ,director | ||||||
|         ,billto_group          --master data  |         ,billto_group          --master data | ||||||
|         ,shipto_group |         ,shipto_group | ||||||
|         ,chan          --master data  |         ,chan          --master data | ||||||
|         ,chansub |         ,chansub | ||||||
|         ,chan_retail |         ,chan_retail | ||||||
|         ,part |         ,part | ||||||
| @ -62,18 +62,19 @@ target AS (select target_vol vincr, target_prc pincr) | |||||||
|         ,mins_descr |         ,mins_descr | ||||||
|         ,segm |         ,segm | ||||||
|         ,substance |         ,substance | ||||||
|         ,fs_line          --master data  |         ,fs_line          --master data | ||||||
|         ,r_currency          --history cust mix |         ,r_currency          --history cust mix | ||||||
|         ,r_rate          --master data  |         ,r_rate          --master data | ||||||
|         ,c_currency          --master data  |         ,c_currency          --master data | ||||||
|         ,c_rate          --master data  |         ,c_rate          --master data | ||||||
|         ,sum(coalesce(units,0)) units          --history value |         ,sum(coalesce(units,0)) units          --history value | ||||||
|         ,sum(coalesce(value_loc,0)) value_loc          --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_loc,0)) cost_loc          --history part mix | ||||||
|         ,sum(coalesce(cost_usd,0)) cost_usd |         ,sum(coalesce(cost_usd,0)) cost_usd | ||||||
|         ,calc_status          --0  |         ,sum(coalesce(pounds,0)) pounds | ||||||
|         ,flag          --0  |         ,calc_status          --0 | ||||||
|  |         ,flag          --0 | ||||||
|         ,order_date          --history date mix |         ,order_date          --history date mix | ||||||
|         ,order_month |         ,order_month | ||||||
|         ,order_season |         ,order_season | ||||||
| @ -89,7 +90,7 @@ target AS (select target_vol vincr, target_prc pincr) | |||||||
|         -----------------scenario---------------------------- |         -----------------scenario---------------------------- | ||||||
|         where_clause |         where_clause | ||||||
|         -----------------additional params------------------- |         -----------------additional params------------------- | ||||||
|         AND CASE (SELECT flag FROM flagv)  |         AND CASE (SELECT flag FROM flagv) | ||||||
|                 WHEN 'scale all' THEN true |                 WHEN 'scale all' THEN true | ||||||
|                 WHEN 'scale copy' THEN iter IN ('plan','diff','copy') |                 WHEN 'scale copy' THEN iter IN ('plan','diff','copy') | ||||||
|                 WHEN 'scale new part' THEN module = 'new basket' |                 WHEN 'scale new part' THEN module = 'new basket' | ||||||
| @ -97,18 +98,18 @@ target AS (select target_vol vincr, target_prc pincr) | |||||||
|         AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments |         AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments | ||||||
|         AND order_date <= ship_date |         AND order_date <= ship_date | ||||||
|     GROUP BY |     GROUP BY | ||||||
|                 fspr |         fspr | ||||||
|         ,plnt          ---master data  |         ,plnt          ---master data | ||||||
|         ,promo          --history date mix |         ,promo          --history date mix | ||||||
|         ,terms |         ,terms | ||||||
|         ,bill_cust_descr          --history cust mix |         ,bill_cust_descr          --history cust mix | ||||||
|         ,ship_cust_descr          --history cust mix |         ,ship_cust_descr          --history cust mix | ||||||
|         ,dsm |         ,dsm | ||||||
|         ,quota_rep_descr          --master data  |         ,quota_rep_descr          --master data | ||||||
|         ,director |         ,director | ||||||
|         ,billto_group          --master data  |         ,billto_group          --master data | ||||||
|         ,shipto_group |         ,shipto_group | ||||||
|         ,chan          --master data  |         ,chan          --master data | ||||||
|         ,chansub |         ,chansub | ||||||
|         ,chan_retail |         ,chan_retail | ||||||
|         ,part |         ,part | ||||||
| @ -121,13 +122,13 @@ target AS (select target_vol vincr, target_prc pincr) | |||||||
|         ,mins_descr |         ,mins_descr | ||||||
|         ,segm |         ,segm | ||||||
|         ,substance |         ,substance | ||||||
|         ,fs_line          --master data  |         ,fs_line          --master data | ||||||
|         ,r_currency          --history cust mix |         ,r_currency          --history cust mix | ||||||
|         ,r_rate          --master data  |         ,r_rate          --master data | ||||||
|         ,c_currency          --master data  |         ,c_currency          --master data | ||||||
|         ,c_rate          --master data  |         ,c_rate          --master data | ||||||
|         ,calc_status          --0  |         ,calc_status          --0 | ||||||
|         ,flag          --0  |         ,flag          --0 | ||||||
|         ,order_date          --history date mix |         ,order_date          --history date mix | ||||||
|         ,order_month |         ,order_month | ||||||
|         ,order_season |         ,order_season | ||||||
| @ -151,17 +152,17 @@ target AS (select target_vol vincr, target_prc pincr) | |||||||
| ,volume AS ( | ,volume AS ( | ||||||
|     SELECT |     SELECT | ||||||
|         fspr |         fspr | ||||||
|         ,plnt          ---master data  |         ,plnt          ---master data | ||||||
|         ,promo          --history date mix |         ,promo          --history date mix | ||||||
|         ,terms |         ,terms | ||||||
|         ,bill_cust_descr          --history cust mix |         ,bill_cust_descr          --history cust mix | ||||||
|         ,ship_cust_descr          --history cust mix |         ,ship_cust_descr          --history cust mix | ||||||
|         ,dsm |         ,dsm | ||||||
|         ,quota_rep_descr          --master data  |         ,quota_rep_descr          --master data | ||||||
|         ,director |         ,director | ||||||
|         ,billto_group          --master data  |         ,billto_group          --master data | ||||||
|         ,shipto_group |         ,shipto_group | ||||||
|         ,chan          --master data  |         ,chan          --master data | ||||||
|         ,chansub |         ,chansub | ||||||
|         ,chan_retail |         ,chan_retail | ||||||
|         ,part |         ,part | ||||||
| @ -174,18 +175,18 @@ target AS (select target_vol vincr, target_prc pincr) | |||||||
|         ,mins_descr |         ,mins_descr | ||||||
|         ,segm |         ,segm | ||||||
|         ,substance |         ,substance | ||||||
|         ,fs_line          --master data  |         ,fs_line          --master data | ||||||
|         ,r_currency          --history cust mix |         ,r_currency          --history cust mix | ||||||
|         ,r_rate          --master data  |         ,r_rate          --master data | ||||||
|         ,c_currency          --master data  |         ,c_currency          --master data | ||||||
|         ,c_rate          --master data  |         ,c_rate          --master data | ||||||
|         ,round(units*s.factor    ,2) units |         ,round(units*s.factor    ,2) units | ||||||
|         ,round(value_loc*s.factor,2) value_loc |         ,round(value_loc*s.factor,2) value_loc | ||||||
|         ,round(value_usd*s.factor,2) value_usd |         ,round(value_usd*s.factor,2) value_usd | ||||||
|         ,round(cost_loc*s.factor ,2) cost_loc |         ,round(cost_loc*s.factor ,2) cost_loc | ||||||
|         ,round(cost_usd*s.factor ,2) cost_usd |         ,round(cost_usd*s.factor ,2) cost_usd | ||||||
|         ,calc_status          --0  |         ,calc_status          --0 | ||||||
|         ,flag          --0  |         ,flag          --0 | ||||||
|         ,order_date          --history date mix |         ,order_date          --history date mix | ||||||
|         ,order_month |         ,order_month | ||||||
|         ,order_season |         ,order_season | ||||||
| @ -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 | ||||||
| @ -232,17 +234,17 @@ FROM | |||||||
| ,pricing AS ( | ,pricing AS ( | ||||||
|     SELECT |     SELECT | ||||||
|         fspr |         fspr | ||||||
|         ,plnt          ---master data  |         ,plnt          ---master data | ||||||
|         ,promo          --history date mix |         ,promo          --history date mix | ||||||
|         ,terms |         ,terms | ||||||
|         ,bill_cust_descr          --history cust mix |         ,bill_cust_descr          --history cust mix | ||||||
|         ,ship_cust_descr          --history cust mix |         ,ship_cust_descr          --history cust mix | ||||||
|         ,dsm |         ,dsm | ||||||
|         ,quota_rep_descr          --master data  |         ,quota_rep_descr          --master data | ||||||
|         ,director |         ,director | ||||||
|         ,billto_group          --master data  |         ,billto_group          --master data | ||||||
|         ,shipto_group |         ,shipto_group | ||||||
|         ,chan          --master data  |         ,chan          --master data | ||||||
|         ,chansub |         ,chansub | ||||||
|         ,chan_retail |         ,chan_retail | ||||||
|         ,part |         ,part | ||||||
| @ -255,18 +257,18 @@ FROM | |||||||
|         ,mins_descr |         ,mins_descr | ||||||
|         ,segm |         ,segm | ||||||
|         ,substance |         ,substance | ||||||
|         ,fs_line          --master data  |         ,fs_line          --master data | ||||||
|         ,r_currency          --history cust mix |         ,r_currency          --history cust mix | ||||||
|         ,r_rate          --master data  |         ,r_rate          --master data | ||||||
|         ,c_currency          --master data  |         ,c_currency          --master data | ||||||
|         ,c_rate          --master data  |         ,c_rate          --master data | ||||||
|         ,0::numeric units |         ,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/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 |         ,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_loc | ||||||
|         ,0::numeric cost_usd |         ,0::numeric cost_usd | ||||||
|         ,calc_status          --0  |         ,calc_status          --0 | ||||||
|         ,flag          --0  |         ,flag          --0 | ||||||
|         ,order_date          --history date mix |         ,order_date          --history date mix | ||||||
|         ,order_month |         ,order_month | ||||||
|         ,order_season |         ,order_season | ||||||
| @ -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 | ||||||
|  | |||||||
| @ -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 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user