From ba99264fb636689c6b237a033de535265c73e763 Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Tue, 5 Mar 2019 16:18:02 -0500 Subject: [PATCH] make a bunch of adjustments --- fpvt.frm | 248 +++++++++++++++++++++++++++++++--------------------- fpvt.frx | Bin 23576 -> 24600 bytes handler.bas | 27 +----- pivot.bas | 9 ++ 4 files changed, 162 insertions(+), 122 deletions(-) diff --git a/fpvt.frm b/fpvt.frm index 6377a73..3fc3b4e 100644 --- a/fpvt.frm +++ b/fpvt.frm @@ -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 + + diff --git a/fpvt.frx b/fpvt.frx index 7cf124adad2957b810e53ecc4d3a5519cc6d7562..28fe3e35eb65faf92bed44dbeac4d8588c0035bc 100644 GIT binary patch delta 3815 zcmZvfdr;KZ702)0-QV(XcLiNwc}Q5^Zx)1QfiMys?ZlCO?{9xRg8pVc zzjN%4Y}ingik0ly}U;n~kU^r||O$~3WDMQb&A zTuo1Cnxtv*(3EC?ZfbRbr$@=89hPpO!vKAyZ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e(8H0elMx z<8MQL2YeU20=@?>f=l34AZ#utB>j13-mcfsc^&)+TmwG_!e|cir{HJc=inFMIuN>F zLB0Wg4Stgt6Nlx_h>;R;R@aM^41GzqC@&Et; diff --git a/handler.bas b/handler.bas index b6cfdc7..8736e9e 100644 --- a/handler.bas +++ b/handler.bas @@ -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 diff --git a/pivot.bas b/pivot.bas index 9d0472e..52b1906 100644 --- a/pivot.bas +++ b/pivot.bas @@ -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)