json_build should accomodate new part schema
This commit is contained in:
parent
5a87acc876
commit
c9fff3e27e
@ -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
|
||||
|
||||
|
132
months.cls
132
months.cls
@ -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
|
||||
|
||||
For i = 1 To 12
|
||||
Sheets("_month").Cells(i + 1, 16) = JsonConverter.ConvertToJson(adjust(i))
|
||||
Next i
|
||||
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,44 +479,71 @@ Sub build_json(ByVal pos As Integer)
|
||||
Loop
|
||||
ReDim Preserve handler.basis(j - 1)
|
||||
|
||||
'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))
|
||||
'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"
|
||||
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
|
||||
adjust(pos)("month") = Worksheets("month").Cells(5 + pos, 1)
|
||||
adjust(pos)("qty") = units(pos, 4)
|
||||
adjust(pos)("amount") = sales(pos, 4)
|
||||
Else
|
||||
'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"
|
||||
'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))
|
||||
'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
|
||||
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
|
||||
Else
|
||||
'if the target price is the same as average and a month is being added
|
||||
adjust(pos)("type") = "scale_v"
|
||||
adjust(pos)("stamp") = Format(DateTime.Now, "yyyy-MM-dd hh:mm:ss")
|
||||
adjust(pos)("user") = Application.UserName
|
||||
adjust(pos)("scenario")("version") = "b20"
|
||||
adjust(pos)("scenario")("iter") = handler.basis
|
||||
adjust(pos)("source") = "adj"
|
||||
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
|
||||
adjust(pos)("stamp") = Format(DateTime.Now, "yyyy-MM-dd hh:mm:ss")
|
||||
adjust(pos)("user") = Application.UserName
|
||||
adjust(pos)("scenario")("version") = "b20"
|
||||
adjust(pos)("scenario")("iter") = handler.basis
|
||||
adjust(pos)("source") = "adj"
|
||||
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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user