json_build should accomodate new part schema

This commit is contained in:
Trowbridge 2019-03-21 02:29:36 -04:00
parent 5a87acc876
commit c9fff3e27e
2 changed files with 93 additions and 43 deletions

View File

@ -427,6 +427,8 @@ Sub month_tosheet(ByRef pkg() As Variant, ByRef basket() As Variant)
Call x.SHTp_DumpVar(basket, "_month", 1, 21, False, False, True) Call x.SHTp_DumpVar(basket, "_month", 1, 21, False, False, True)
Call x.SHTp_DumpVar(basket, "_month", 1, 26, False, False, True) Call x.SHTp_DumpVar(basket, "_month", 1, 26, False, False, True)
Sheets("config").Cells(5, 2) = 0 Sheets("config").Cells(5, 2) = 0
Sheets("config").Cells(6, 2) = 0
Sheets("config").Cells(7, 2) = 0
months.load_sheet months.load_sheet

View File

@ -26,6 +26,7 @@ Private scenario() As Variant
Private orig As Range Private orig As Range
Private basket_touch As Range Private basket_touch As Range
Private showbasket As Boolean Private showbasket As Boolean
Private np As Object 'json dedicated to new part scenario
Private Sub Worksheet_Change(ByVal target As Range) Private Sub Worksheet_Change(ByVal target As Range)
@ -119,10 +120,10 @@ Sub mvp_set()
Else Else
sales(i, 4) = sales(i, 5) - (sales(i, 2) + sales(i, 3)) sales(i, 4) = sales(i, 5) - (sales(i, 2) + sales(i, 3))
End If End If
Call Me.build_json(i)
Next i Next i
Me.crunch_array Me.crunch_array
Me.build_json
Me.set_sheet Me.set_sheet
@ -144,10 +145,10 @@ Sub mvp_adj()
Else Else
sales(i, 4) = sales(i, 5) - (sales(i, 2) + sales(i, 3)) sales(i, 4) = sales(i, 5) - (sales(i, 2) + sales(i, 3))
End If End If
Call Me.build_json(i)
Next i Next i
Me.crunch_array Me.crunch_array
Me.build_json
Me.set_sheet Me.set_sheet
@ -199,10 +200,10 @@ On Error GoTo errh
Exit Sub Exit Sub
End Select End Select
End If End If
Call Me.build_json(i)
Next i Next i
Me.crunch_array Me.crunch_array
Me.build_json
Me.set_sheet Me.set_sheet
errh: errh:
@ -255,10 +256,10 @@ Sub ms_adj()
Exit Sub Exit Sub
End Select End Select
End If End If
Call Me.build_json(i)
Next i Next i
Me.crunch_array Me.crunch_array
Me.build_json
Me.set_sheet Me.set_sheet
@ -296,9 +297,14 @@ Sub set_sheet()
Call x.SHTp_DumpVar(x.SHTp_get_block(Worksheets("_month").Range("R1")), "month", 6, 20, False, False, False) Call x.SHTp_DumpVar(x.SHTp_get_block(Worksheets("_month").Range("R1")), "month", 6, 20, False, False, False)
'Sheets("month").Range("B32:Q5000").ClearContents 'Sheets("month").Range("B32:Q5000").ClearContents
For i = 1 To 12 If Me.newpart Then
Sheets("_month").Cells(i + 1, 16) = JsonConverter.ConvertToJson(adjust(i)) Sheets("_month").Range("P2:P13").ClearContents
Next i Sheets("_month").Cells(2, 16) = JsonConverter.ConvertToJson(np)
Else
For i = 1 To 12
Sheets("_month").Cells(i + 1, 16) = JsonConverter.ConvertToJson(adjust(i))
Next i
End If
dumping = False dumping = False
@ -454,10 +460,14 @@ Sub format_number(ByRef target As Range)
End Sub End Sub
Sub build_json(ByVal pos As Integer) Sub build_json()
Dim i As Long Dim i As Long
Dim j As Long Dim j As Long
Dim pos As Long
Dim o As Object
Dim m As Object
Dim list As Object
ReDim handler.basis(100) ReDim handler.basis(100)
i = 2 i = 2
@ -468,45 +478,72 @@ Sub build_json(ByVal pos As Integer)
i = i + 1 i = i + 1
Loop Loop
ReDim Preserve handler.basis(j - 1) ReDim Preserve handler.basis(j - 1)
'if something is changing ReDim adjust(12)
If Round(units(pos, 4), 2) <> 0 Or (Round(price(pos, 4), 8) <> 0 And Round(units(pos, 5), 2) <> 0) Then
Set adjust(pos) = JsonConverter.ParseJson(JsonConverter.ConvertToJson(basejson)) If Me.newpart Then
'if there is no existing volume on the target month but units are being added Set np = JsonConverter.ParseJson(JsonConverter.ConvertToJson(basejson))
If units(pos, 2) + units(pos, 3) = 0 And units(pos, 4) <> 0 Then np("stamp") = Format(DateTime.Now, "yyyy-MM-dd hh:mm:ss")
'add month np("user") = Application.UserName
If Round(price(pos, 5), 8) <> Round(tprice(1, 2) + tprice(1, 3), 8) Then np("scenario")("version") = "b20"
'if the target price is diferent from the average and a month is being added np("scenario")("iter") = handler.basis
adjust(pos)("type") = "addmonth_vp" np("source") = "adj"
Else Set m = JsonConverter.ParseJson("{}")
'if the target price is the same as average and a month is being added End If
adjust(pos)("type") = "addmonth_v"
For pos = 1 To 12
If Me.newpart Then
If sales(pos, 5) <> 0 Then
Set o = JsonConverter.ParseJson("{}")
o("amount") = sales(pos, 5)
o("qty") = units(pos, 5)
Set m(Worksheets("month").Cells(5 + pos, 1).value) = JsonConverter.ParseJson(JsonConverter.ConvertToJson(o))
End If End If
adjust(pos)("month") = Worksheets("month").Cells(5 + pos, 1)
adjust(pos)("qty") = units(pos, 4)
adjust(pos)("amount") = sales(pos, 4)
Else Else
'scale the existing volume(price) on the target month 'if something is changing
If Round(price(pos, 4), 8) <> 0 Then If Round(units(pos, 4), 2) <> 0 Or (Round(price(pos, 4), 8) <> 0 And Round(units(pos, 5), 2) <> 0) Then
If Round(units(pos, 4), 2) <> 0 Then Set adjust(pos) = JsonConverter.ParseJson(JsonConverter.ConvertToJson(basejson))
adjust(pos)("type") = "scale_vp" 'if there is no existing volume on the target month but units are being added
If units(pos, 2) + units(pos, 3) = 0 And units(pos, 4) <> 0 Then
'add month
If Round(price(pos, 5), 8) <> Round(tprice(1, 2) + tprice(1, 3), 8) Then
'if the target price is diferent from the average and a month is being added
adjust(pos)("type") = "addmonth_vp"
Else
'if the target price is the same as average and a month is being added
adjust(pos)("type") = "addmonth_v"
End If
adjust(pos)("month") = Worksheets("month").Cells(5 + pos, 1)
adjust(pos)("qty") = units(pos, 4)
adjust(pos)("amount") = sales(pos, 4)
Else Else
adjust(pos)("type") = "scale_p" 'scale the existing volume(price) on the target month
If Round(price(pos, 4), 8) <> 0 Then
If Round(units(pos, 4), 2) <> 0 Then
adjust(pos)("type") = "scale_vp"
Else
adjust(pos)("type") = "scale_p"
End If
Else
'if the target price is the same as average and a month is being added
adjust(pos)("type") = "scale_v"
End If
adjust(pos)("qty") = units(pos, 4)
adjust(pos)("amount") = sales(pos, 4)
'------------add this in to only scale a particular month--------------------
adjust(pos)("scenario")("order_month") = Worksheets("month").Cells(5 + pos, 1)
End If End If
Else adjust(pos)("stamp") = Format(DateTime.Now, "yyyy-MM-dd hh:mm:ss")
'if the target price is the same as average and a month is being added adjust(pos)("user") = Application.UserName
adjust(pos)("type") = "scale_v" adjust(pos)("scenario")("version") = "b20"
adjust(pos)("scenario")("iter") = handler.basis
adjust(pos)("source") = "adj"
End If End If
adjust(pos)("qty") = units(pos, 4)
adjust(pos)("amount") = sales(pos, 4)
'------------add this in to only scale a particular month--------------------
adjust(pos)("scenario")("order_month") = Worksheets("month").Cells(5 + pos, 1)
End If End If
adjust(pos)("stamp") = Format(DateTime.Now, "yyyy-MM-dd hh:mm:ss") Next pos
adjust(pos)("user") = Application.UserName
adjust(pos)("scenario")("version") = "b20" If Me.newpart Then
adjust(pos)("scenario")("iter") = handler.basis Set np("months") = JsonConverter.ParseJson(JsonConverter.ConvertToJson(m))
adjust(pos)("source") = "adj"
End If End If
End Sub End Sub
@ -573,7 +610,6 @@ Sub reset()
End Sub End Sub
Sub switch_basket() Sub switch_basket()
Attribute switch_basket.VB_ProcData.VB_Invoke_Func = " \n14"
If Sheets("config").Cells(6, 2) = 1 Then If Sheets("config").Cells(6, 2) = 1 Then
@ -864,10 +900,22 @@ Sub new_part()
price(i, 1) = 0 price(i, 1) = 0
price(i, 2) = 0 price(i, 2) = 0
price(i, 3) = 0 price(i, 3) = 0
Call Me.build_json(i)
Next i Next i
Call Me.crunch_array Call Me.crunch_array
Call Me.build_json
Call Me.set_sheet Call Me.set_sheet
dumping = False dumping = False
End Sub End Sub
Function newpart() As Boolean
If Worksheets("config").Cells(7, 2) = 1 Then
newpart = True
Else
newpart = False
End If
End Function