make a bunch of adjustments

This commit is contained in:
Trowbridge 2019-03-05 16:18:02 -05:00
parent 85c3269bcc
commit ba99264fb6
4 changed files with 162 additions and 122 deletions

248
fpvt.frm
View File

@ -16,6 +16,8 @@ Attribute VB_Exposed = False
Public mod_adjust As Boolean
Private month() As Variant
Private mload() As Variant
Private adjust As Object
Option Explicit
Private Sub cbCancel_Click()
@ -28,14 +30,6 @@ Private Sub cbCancel_Click()
End Sub
Private Sub cbOK_Click()
'MsgBox (handler.scenario)
End Sub
Private Sub chbPlug_Change()
opvolume.Enabled = Not chbPlug.value
@ -44,6 +38,16 @@ Private Sub chbPlug_Change()
End Sub
Private Sub butAdjust_Click()
MsgBox ("adjustment posted")
Me.Hide
End Sub
Private Sub butCancel_Click()
Me.Hide
End Sub
Private Sub lbMonth_Change()
Dim i As Long
@ -85,110 +89,74 @@ Private Sub lbMonth_Change()
End Sub
Private Sub ListBox1_Click()
End Sub
Private Sub opmprice_Click()
Private Sub opEditPrice_Click()
opPlugVol.Enabled = False
opPlugPrice.Enabled = False
opPlugVol.Visible = False
opPlugPrice.Visible = False
opPlugPrice.value = True
opPlugVol.value = False
tbMFVal = Format(CDbl(tbmPAVal.value) + CDbl(tbMBaseVal.value) + CDbl(tbMAVal.value), "#,###")
tbMFVol = Format((CDbl(tbMPAVol.value) + CDbl(tbMBaseVol.value)), "#,###")
tbMFPrice = Format(CDbl(tbMFVal.value) / CDbl(tbMFVol.value), "#.000")
tbFcPrice.Enabled = True
tbFcPrice.BackColor = &H80000018
tbFcVal.Enabled = False
tbFcVal.BackColor = &H80000005
tbFcVol.Enabled = False
tbFcVol.BackColor = &H80000005
End Sub
Private Sub opmvol_Click()
Dim pchange As Double
'---------calculate percent change----------------------------------------------------------------------
pchange = 1 + CDbl(tbMAVal.value) / (CDbl(tbmPAVal.value) + CDbl(tbMBaseVal.value))
'---------add the adjustments together to get the new forecast------------------------------------------
tbMFVal = Format(CDbl(tbmPAVal.value) + CDbl(tbMBaseVal.value) + CDbl(tbMAVal.value), "#,###")
tbMFVol = Format((CDbl(tbMPAVol.value) + CDbl(tbMBaseVol.value)) * pchange, "#,###")
tbMFPrice = Format(CDbl(tbMFVal.value) / CDbl(tbMFVol.value), "#.000")
End Sub
Private Sub opprice_Click()
tbFcVal = Format(CDbl(tbPadjVal.value) + CDbl(tbBaseVal.value) + CDbl(tbAdjVal.value), "#,###")
tbFcVol = Format((CDbl(tbPadjVol.value) + CDbl(tbBaseVol.value)), "#,###")
tbFcPrice = Format(CDbl(tbFcVal.value) / CDbl(tbFcVol.value), "#.000")
Private Sub opEditSales_Click()
opPlugVol.Enabled = True
opPlugPrice.Enabled = True
opPlugVol.Visible = True
opPlugPrice.Visible = True
tbFcPrice.Enabled = False
tbFcPrice.BackColor = &H80000005
tbFcVal.Enabled = True
tbFcVal.BackColor = &H80000018
tbFcVol.Enabled = False
tbFcVol.BackColor = &H80000005
End Sub
Private Sub opvolume_Click()
Dim pchange As Double
'---------calculate percent change----------------------------------------------------------------------
pchange = 1 + CDbl(tbAdjVal.value) / (CDbl(tbPadjVal.value) + CDbl(tbBaseVal.value))
'---------add the adjustments together to get the new forecast------------------------------------------
tbFcVal = Format(CDbl(tbPadjVal.value) + CDbl(tbBaseVal.value) + CDbl(tbAdjVal.value), "#,###")
tbFcVol = Format((CDbl(tbPadjVol.value) + CDbl(tbBaseVol.value)) * pchange, "#,###")
tbFcPrice = Format(CDbl(tbFcVal.value) / CDbl(tbFcVol.value), "#.000")
Private Sub opEditVol_Click()
opPlugVol.Enabled = False
opPlugPrice.Enabled = False
opPlugPrice.value = False
opPlugVol.value = True
opPlugVol.Enabled = False
opPlugPrice.Enabled = False
opPlugVol.Visible = False
opPlugPrice.Visible = False
tbFcPrice.Enabled = False
tbFcPrice.BackColor = &H80000005
tbFcVal.Enabled = False
tbFcVal.BackColor = &H80000005
tbFcVol.Enabled = True
tbFcVol.BackColor = &H80000018
End Sub
Private Sub tbAdjVal_Change()
Dim pchange As Double
If IsNumeric(tbAdjVal.value) Then
'---------calculate percent change----------------------------------------------------------------------
pchange = 1 + CDbl(tbAdjVal.value) / (CDbl(tbPadjVal.value) + CDbl(tbBaseVal.value))
'---------add the adjustments together to get the new forecast------------------------------------------
tbFcVal = Format(CDbl(tbPadjVal.value) + CDbl(tbBaseVal.value) + CDbl(tbAdjVal.value), "#,###")
'---------if volume adjustment method is selected, scale the volume up----------------------------------
If opvolume Then
tbFcVol = Format((CDbl(tbPadjVol.value) + CDbl(tbBaseVol.value)) * pchange, "#,###")
Else
tbFcVol = Format((CDbl(tbPadjVol.value) + CDbl(tbBaseVol.value)), "#,###")
End If
tbFcPrice = Format(CDbl(tbFcVal.value) / CDbl(tbFcVol.value), "#.000")
Else
tbFcVal = Format(CDbl(tbPadjVal.value) + CDbl(tbBaseVal.value), "#,###")
tbFcVol = Format((CDbl(tbPadjVol.value) + CDbl(tbBaseVol.value)), "#,###")
tbFcPrice = Format(CDbl(tbFcVal.value) / CDbl(tbFcVol.value), "#.000")
End If
Private Sub opPlugPrice_Click()
calc_val
End Sub
Private Sub tbAdjVol_Change()
If IsNumeric(tbAdjVol.value) Then
tbFcVol = Format(CDbl(tbAdjVol.value) + CDbl(tbBaseVol.value), "#,###")
Else
tbFcVol = Format(CDbl(tbBaseVol.value), "#,###")
End If
Private Sub opPlugVol_Click()
calc_val
End Sub
Private Sub tbMAVal_Change()
Private Sub tbFcPrice_Change()
If opEditPrice Then calc_price
End Sub
Dim pchange As Double
If IsNumeric(tbMAVal.value) Then
'---------calculate percent change----------------------------------------------------------------------
pchange = 1 + CDbl(tbMAVal.value) / (CDbl(tbMAVal.value) + CDbl(tbMBaseVal.value))
'---------add the adjustments together to get the new forecast------------------------------------------
tbMFVal = Format(CDbl(tbmPAVal.value) + CDbl(tbMBaseVal.value) + CDbl(tbMAVal.value), "#,###")
'---------if volume adjustment method is selected, scale the volume up----------------------------------
If opmvol Then
tbMFVol = Format((CDbl(tbMPAVol.value) + CDbl(tbMBaseVol.value)) * pchange, "#,###")
Else
tbMFVol = Format((CDbl(tbMPAVol.value) + CDbl(tbMBaseVol.value)), "#,###")
End If
tbMFPrice = Format(CDbl(tbMFVal.value) / CDbl(tbMFVol.value), "#.000")
Else
tbMFVal = Format(CDbl(tbmPAVal.value) + CDbl(tbMBaseVal.value), "#,###")
tbMFVol = Format((CDbl(tbMPAVol.value) + CDbl(tbMBaseVol.value)), "#,###")
tbMFPrice = Format(CDbl(tbMFVal.value) / CDbl(tbMFVol.value), "#.000")
End If
Private Sub tbFcVal_Change()
If opEditSales Then calc_val
End Sub
Private Sub tbFcVol_Change()
If opEditVol Then calc_vol
End Sub
Private Sub UserForm_Activate()
@ -232,7 +200,7 @@ Private Sub UserForm_Activate()
Next i
fpvt.tbFcVol.value = Format(CDbl(fpvt.tbBaseVol.value) + CDbl(fpvt.tbPadjVol.value), "#,###")
fpvt.tbFcVal.value = Format(CDbl(fpvt.tbBaseVal.value) + CDbl(fpvt.tbPadjVal.value), "#,###")
fpvt.tbFcVal.value = Format(CDbl(fpvt.tbBaseVal.value) + CDbl(fpvt.tbPadjVal.value), "#")
fpvt.tbFcPrice.value = Format(CDbl(fpvt.tbFcVal.value) / CDbl(fpvt.tbFcVol.value), "#.000")
'---------------------------------------populate monthly-------------------------------------------------------
@ -293,3 +261,87 @@ Function co_num(ByRef one As Variant, ByRef two As Variant) As Variant
End Function
Sub calc_val()
Dim pchange As Double
If IsNumeric(tbFcVal.value) Then
'calculate percent change
pchange = CDbl(tbFcVal.value) / (CDbl(tbPadjVal.value) + CDbl(tbBaseVal.value))
'plug the adjustment required
tbAdjVal = Format(CDbl(tbFcVal.value) - CDbl(tbBaseVal.value) - CDbl(tbPadjVal.value), "#,###")
'---------if volume adjustment method is selected, scale the volume up----------------------------------
If opPlugVol Then
tbFcVol = Format((CDbl(tbPadjVol.value) + CDbl(tbBaseVol.value)) * pchange, "#,###")
Else
tbFcVol = Format((CDbl(tbPadjVol.value) + CDbl(tbBaseVol.value)), "#,###")
End If
tbFcPrice = Format(CDbl(tbFcVal.value) / CDbl(tbFcVol.value), "#.000")
tbAdjVol = Format(tbFcVol - (CDbl(tbBaseVol) + CDbl(tbPadjVol)), "#,###")
tbAdjPrice = Format(CDbl(tbFcVal.value) / CDbl(tbFcVol.value) - ((CDbl(tbBaseVal.value) + CDbl(tbPadjVal.value)) / (CDbl(tbBaseVol.value) + CDbl(tbPadjVol.value))), "#.000")
Else
'tbFcVal = Format(CDbl(tbPadjVal.value) + CDbl(tbBaseVal.value), "#,###")
tbAdjVol = Format((CDbl(tbFcVol.value) - CDbl(tbBaseVol.value) - CDbl(tbPadjVol.value)), "#,###")
tbAdjPrice = 0
'tbAdjPrice = Format(CDbl(tbFcVal.value) / CDbl(tbFcVol.value) - ((tbBaseVal + tbPadjVal) / (tbBaseVol + tbPadjVol)), "#.000")
End If
'build json
Set adjust = JsonConverter.ParseJson("{""scneario"":" & scenario & "}")
adjust("type") = "increment"
If opPlugVol Then
adjust("vp") = "v"
Else
adjust("vp") = "p"
End If
adjust("amount") = tbAdjVal
adjust("stamp") = Format(Date + time, "yyyy-mm-dd hh:mm:ss")
adjust("user") = Application.UserName
'print json
tbJSON = JsonConverter.ConvertToJson(adjust)
End Sub
Sub calc_vol()
Dim pchange As Double
If IsNumeric(tbFcVol.value) And tbFcVol <> 0 Then
'price should already have been re-calculated to base + prior at this point
tbFcVal = Format(CDbl(tbFcPrice.value) * CDbl(tbFcVol.value))
'calculate percent change
'pchange = CDbl(tbFcVal.value) / (CDbl(tbPadjVal.value) + CDbl(tbBaseVal.value))
'plug the adjustment required
tbAdjVal = Format(CDbl(tbFcVal.value) - CDbl(tbBaseVal.value) - CDbl(tbPadjVal.value), "#,###")
tbAdjVol = Format(tbFcVol - (CDbl(tbBaseVol) + CDbl(tbPadjVol)), "#,###")
tbAdjPrice = Format(CDbl(tbFcVal.value) / CDbl(tbFcVol.value) - ((CDbl(tbBaseVal.value) + CDbl(tbPadjVal.value)) / (CDbl(tbBaseVol.value) + CDbl(tbPadjVol.value))), "#.000")
Else
tbFcVal = 0
tbAdjVal = Format(CDbl(tbFcVal.value) - CDbl(tbBaseVal.value) - CDbl(tbPadjVal.value), "#,###")
tbAdjPrice = Format((tbBaseVal + tbPadjVal) / (tbBaseVol + tbPadjVol), "#.000")
tbAdjVol = Format(-CDbl(tbBaseVol.value) - CDbl(tbPadjVol.value), "#,###")
End If
tbFcVal = Format(tbFcVal, "#,###")
End Sub
Sub calc_price()
If IsNumeric(tbFcPrice.value) And tbFcPrice.value <> 0 Then
tbFcVal = Format(CDbl(tbFcPrice.value) * CDbl(tbFcVol.value), "#,###")
tbAdjVal = Format(CDbl(tbFcVal.value) - CDbl(tbBaseVal.value) - CDbl(tbPadjVal.value), "#,###")
tbAdjPrice = Format(CDbl(tbFcVal.value) / CDbl(tbFcVol.value) - ((CDbl(tbBaseVal.value) + CDbl(tbPadjVal.value)) / (CDbl(tbBaseVol.value) + CDbl(tbPadjVol.value))), "#.000")
Else
tbFcVal = 0
tbAdjVal = Format(CDbl(tbFcVal.value) - CDbl(tbBaseVal.value) - CDbl(tbPadjVal.value), "#,###")
End If
End Sub

BIN
fpvt.frx

Binary file not shown.

View File

@ -1,3 +1,4 @@
Attribute VB_Name = "handler"
Option Explicit
Public sql As String
@ -31,32 +32,10 @@ Sub load_fpvt()
Exit For
End If
Next i
If showprice Then
fpvt.opvolume.Visible = False
fpvt.opprice.Visible = False
fpvt.tbAdjPrice.BackColor = &H80000005
fpvt.tbAdjVol.BackColor = &H80000005
fpvt.tbAdjVal.BackColor = &H80000004
fpvt.tbAdjVal.Enabled = False
fpvt.tbAdjPrice.Enabled = True
fpvt.tbAdjVol.Enabled = True
Else
fpvt.opvolume.Visible = True
fpvt.opprice.Visible = True
fpvt.tbAdjPrice.BackColor = &H80000003
fpvt.tbAdjVol.BackColor = &H80000003
fpvt.tbAdjVal.BackColor = &H80000005
fpvt.tbAdjVal.Enabled = True
fpvt.tbAdjPrice.Enabled = False
fpvt.tbAdjVol.Enabled = False
End If
fpvt.Show
End Sub

View File

@ -1,3 +1,12 @@
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Sheet3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)