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, 26, False, False, True)
Sheets("config").Cells(5, 2) = 0
Sheets("config").Cells(6, 2) = 0
Sheets("config").Cells(7, 2) = 0
months.load_sheet

View File

@ -26,6 +26,7 @@ Private scenario() As Variant
Private orig As Range
Private basket_touch As Range
Private showbasket As Boolean
Private np As Object 'json dedicated to new part scenario
Private Sub Worksheet_Change(ByVal target As Range)
@ -119,10 +120,10 @@ Sub mvp_set()
Else
sales(i, 4) = sales(i, 5) - (sales(i, 2) + sales(i, 3))
End If
Call Me.build_json(i)
Next i
Me.crunch_array
Me.build_json
Me.set_sheet
@ -144,10 +145,10 @@ Sub mvp_adj()
Else
sales(i, 4) = sales(i, 5) - (sales(i, 2) + sales(i, 3))
End If
Call Me.build_json(i)
Next i
Me.crunch_array
Me.build_json
Me.set_sheet
@ -199,10 +200,10 @@ On Error GoTo errh
Exit Sub
End Select
End If
Call Me.build_json(i)
Next i
Me.crunch_array
Me.build_json
Me.set_sheet
errh:
@ -255,10 +256,10 @@ Sub ms_adj()
Exit Sub
End Select
End If
Call Me.build_json(i)
Next i
Me.crunch_array
Me.build_json
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)
'Sheets("month").Range("B32:Q5000").ClearContents
If Me.newpart Then
Sheets("_month").Range("P2:P13").ClearContents
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
@ -454,10 +460,14 @@ Sub format_number(ByRef target As Range)
End Sub
Sub build_json(ByVal pos As Integer)
Sub build_json()
Dim i 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)
i = 2
@ -469,6 +479,27 @@ Sub build_json(ByVal pos As Integer)
Loop
ReDim Preserve handler.basis(j - 1)
ReDim adjust(12)
If Me.newpart Then
Set np = JsonConverter.ParseJson(JsonConverter.ConvertToJson(basejson))
np("stamp") = Format(DateTime.Now, "yyyy-MM-dd hh:mm:ss")
np("user") = Application.UserName
np("scenario")("version") = "b20"
np("scenario")("iter") = handler.basis
np("source") = "adj"
Set m = JsonConverter.ParseJson("{}")
End If
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
Else
'if something is changing
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))
@ -508,6 +539,12 @@ Sub build_json(ByVal pos As Integer)
adjust(pos)("scenario")("iter") = handler.basis
adjust(pos)("source") = "adj"
End If
End If
Next pos
If Me.newpart Then
Set np("months") = JsonConverter.ParseJson(JsonConverter.ConvertToJson(m))
End If
End Sub
@ -573,7 +610,6 @@ Sub reset()
End Sub
Sub switch_basket()
Attribute switch_basket.VB_ProcData.VB_Invoke_Func = " \n14"
If Sheets("config").Cells(6, 2) = 1 Then
@ -864,10 +900,22 @@ Sub new_part()
price(i, 1) = 0
price(i, 2) = 0
price(i, 3) = 0
Call Me.build_json(i)
Next i
Call Me.crunch_array
Call Me.build_json
Call Me.set_sheet
dumping = False
End Sub
Function newpart() As Boolean
If Worksheets("config").Cells(7, 2) = 1 Then
newpart = True
Else
newpart = False
End If
End Function