Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.91 KB | None | 0 0
  1. Public Sub AllocateBusinessToAdvisersProvidersMonthsAndMetrics()
  2.  
  3. PutSheetDataInArray WbAdviserReport, WsAggregatedData, ArrAggregatedData
  4.  
  5. FindAllAdvisers
  6.  
  7. FindAllProviders
  8.  
  9. ReDim ArrAllocatedBusiness(0 To UBound(ArrAdvisers), 0 To ColMetrics.Count, 0 To UBound(ArrProviders), 0 To 13)
  10.  
  11. PrepareAllocatedBusinessHeadings
  12.  
  13. AllocateAggregatedBusiness
  14.  
  15. End Sub
  16.  
  17. Public Sub FindAllAdvisers()
  18.  
  19. Dim arrHeadingsRow As Variant
  20.  
  21. Dim ixColumnHeading As Long
  22.  
  23. Dim arrAdviserColumn As Variant
  24.  
  25. arrHeadingsRow = RowFrom2dArray(ArrAggregatedData, 1)
  26. ixColumnHeading = IndexInArray1d(arrHeadingsRow, "Adviser")
  27. arrAdviserColumn = ColumnFrom2dArray(ArrAggregatedData, ixColumnHeading)
  28.  
  29. ArrAdvisers = ListOfUniqueValues(arrAdviserColumn, True)
  30.  
  31. End Sub
  32.  
  33. Public Sub FindAllProviders()
  34.  
  35. Dim arrHeadingsRow As Variant
  36.  
  37. Dim ixColumnPosition As Long
  38.  
  39. Dim arrProviderColumn As Variant
  40.  
  41. arrHeadingsRow = RowFrom2dArray(ArrAggregatedData, 1)
  42. ixColumnPosition = IndexInArray1d(arrHeadingsRow, "Life Co")
  43. arrProviderColumn = ColumnFrom2dArray(ArrAggregatedData, ixColumnPosition)
  44.  
  45. ArrProviders = ListOfUniqueValues(arrProviderColumn, True)
  46.  
  47. End Sub
  48.  
  49. Public Sub PrepareAllocatedBusinessHeadings()
  50.  
  51. Dim i As Long, j As Long, k As Long, l As Long
  52.  
  53. Dim LB1 As Long, UB1 As Long
  54. Dim LB2 As Long, UB2 As Long
  55. Dim LB3 As Long, UB3 As Long
  56. Dim LB4 As Long, UB4 As Long
  57.  
  58. AssignArrayBounds ArrAllocatedBusiness, LB1, UB1, LB2, UB2, LB3, UB3, LB4, UB4
  59.  
  60. For i = LB1 + 1 To UB1
  61. ArrAllocatedBusiness(i, 0, 0, 0) = ArrAdvisers(i)
  62. Next i
  63.  
  64. For i = LB1 + 1 To UB1
  65. For j = LB2 + 1 To UB2
  66. ArrAllocatedBusiness(0, j, 0, 0) = ColMetrics(j)
  67. ArrAllocatedBusiness(i, j, 0, 0) = ArrAdvisers(i) & Hyphen & ColMetrics(j)
  68. Next j
  69. Next i
  70.  
  71. For i = LB1 + 1 To UB1
  72. For j = LB2 + 1 To UB2
  73. For k = LB3 + 1 To UB3
  74. ArrAllocatedBusiness(0, 0, k, 0) = ArrProviders(k)
  75. ArrAllocatedBusiness(i, j, k, 0) = ArrAdvisers(i) & Hyphen & ColMetrics(j) & Hyphen & ArrProviders(k)
  76. Next k
  77. Next j
  78. Next i
  79.  
  80. For l = LB4 + 1 To UB4 - 1
  81. ArrAllocatedBusiness(0, 0, 0, l) = DateValue("01/" & Right("0" & Month(l), 2) & "/" & Year(Date))
  82. Next l
  83.  
  84. ArrAllocatedBusiness(0, 0, 0, UB4) = "YTD"
  85.  
  86. End Sub
  87.  
  88. Public Sub AllocateAggregatedBusiness()
  89.  
  90. Dim i As Long, j As Long, k As Long
  91.  
  92. Dim row As Long
  93.  
  94. Dim lngFirstRow As Long, lngFinalRow As Long '/ Of the AggregatedData
  95.  
  96. Dim strTypeOfBusiness As String
  97.  
  98. Dim ixAdviserColumn As Long
  99. Dim ixProviderColumn As Long
  100.  
  101. Dim ixDateSubmittedColumn As Long
  102. Dim ixInvestmentAmountColumn As Long
  103. Dim ixDateMoneyReceivedColumn As Long
  104. Dim ixMonthlyPremiumColumn As Long
  105. Dim ixSinglePremiumColumn As Long
  106. Dim ixCommissionDueColumn As Long
  107. Dim ixCommissionPaidColumn As Long
  108. Dim ixDateCommissionPaidColumn As Long
  109. Dim ixFirstMonthColumn As Long
  110.  
  111. Dim ixAdviser As Long
  112. Dim ixMetric As Long
  113. Dim ixProvider As Long
  114. Dim ixMonth As Long
  115.  
  116. Dim varSearchValue As Variant
  117.  
  118. Dim strErrorMessage As String
  119.  
  120. DetermineColumnPositions ixAdviserColumn, ixProviderColumn, ixDateSubmittedColumn, ixInvestmentAmountColumn, ixDateMoneyReceivedColumn, ixMonthlyPremiumColumn, _
  121. ixSinglePremiumColumn, ixCommissionDueColumn, ixCommissionPaidColumn, ixDateCommissionPaidColumn, ixFirstMonthColumn
  122.  
  123. AssignArrayBounds ArrAggregatedData, lngFirstRow, lngFinalRow
  124. lngFirstRow = lngFirstRow + 2
  125.  
  126. For row = lngFirstRow To lngFinalRow
  127.  
  128. strTypeOfBusiness = TypeOfBusiness(row, ixDateSubmittedColumn, ixInvestmentAmountColumn, ixDateMoneyReceivedColumn, ixMonthlyPremiumColumn, ixSinglePremiumColumn, _
  129. ixCommissionDueColumn, ixCommissionPaidColumn, ixDateCommissionPaidColumn, ixFirstMonthColumn)
  130.  
  131. Select Case strTypeOfBusiness
  132.  
  133. Case Is = ColMetrics.Item("Investment Amount")
  134. DetermineAllocatedBusinessIndexes row, ixAdviser, ixAdviserColumn, ixMetric, ixInvestmentAmountColumn, ixProvider, ixProviderColumn, ixMonth, ixDateSubmittedColumn, strTypeOfBusiness
  135. AllocateBusiness ixInvestmentAmountColumn, ixAdviser, ixMetric, ixProvider, ixMonth, row
  136.  
  137. Case Is = ColMetrics.Item("Single Premium")
  138. DetermineAllocatedBusinessIndexes row, ixAdviser, ixAdviserColumn, ixMetric, ixSinglePremiumColumn, ixProvider, ixProviderColumn, ixMonth, ixDateSubmittedColumn, strTypeOfBusiness
  139. AllocateBusiness ixSinglePremiumColumn, ixAdviser, ixMetric, ixProvider, ixMonth, row
  140.  
  141. Case Is = ColMetrics.Item("Monthly Premium")
  142. DetermineAllocatedBusinessIndexes row, ixAdviser, ixAdviserColumn, ixMetric, ixMonthlyPremiumColumn, ixProvider, ixProviderColumn, ixMonth, ixDateSubmittedColumn, strTypeOfBusiness
  143. AllocateBusiness ixMonthlyPremiumColumn, ixAdviser, ixMetric, ixProvider, ixMonth, row
  144.  
  145. Case Is = ColMetrics.Item("Invoice")
  146. DetermineAllocatedBusinessIndexes row, ixAdviser, ixAdviserColumn, ixMetric, ixCommissionDueColumn, ixProvider, ixProviderColumn, ixMonth, ixDateSubmittedColumn, strTypeOfBusiness
  147. AllocateBusiness ixCommissionDueColumn, ixAdviser, ixMetric, ixProvider, ixMonth, row
  148.  
  149. Case Is = ColMetrics.Item("Recurring")
  150. For i = 1 To 12
  151. ixMonth = i
  152. DetermineAllocatedBusinessIndexes row, ixAdviser, ixAdviserColumn, ixMetric, ixFirstMonthColumn, ixProvider, ixProviderColumn, ixMonth, ixDateSubmittedColumn, strTypeOfBusiness
  153. AllocateBusiness ixFirstMonthColumn, ixAdviser, ixMetric, ixProvider, ixMonth, row
  154. Next i
  155.  
  156. End Select
  157.  
  158. Next row
  159.  
  160. End Sub
  161.  
  162. Public Function TypeOfBusiness(ByVal row As Long, ByRef ixDateSubmittedColumn As Long, ByRef ixInvestmentAmountColumn As Long, ByRef ixDateMoneyReceivedColumn As Long, _
  163. ByRef ixMonthlyPremiumColumn As Long, ByRef ixSinglePremiumColumn As Long, ByRef ixCommissionDueColumn As Long, _
  164. ByRef ixCommissionPaidColumn As Long, ByRef ixDateCommissionPaidColumn As Long, ByRef ixFirstMonthColumn As Long) As String
  165.  
  166. Dim strBusiness As String
  167. strBusiness = ""
  168.  
  169. Dim bDateSubmittedIsPresent As Boolean
  170. Dim bSubmittedAmountIsPresent As Boolean
  171. Dim bMultipleBusinessTypesArePresent As Boolean
  172. Dim bRecurringBusinessIsPresent As Boolean
  173. Dim bCommissionIsPresent As Boolean
  174.  
  175. Dim bValuePresent As Boolean
  176.  
  177. Dim varElement As Variant
  178.  
  179. Dim i As Long
  180.  
  181. Dim arrAmountColumns As Variant
  182. arrAmountColumns = Array()
  183. ReDim arrAmountColumns(1 To 3, 1 To 2)
  184. arrAmountColumns(1, 1) = ixInvestmentAmountColumn
  185. arrAmountColumns(1, 2) = ColMetrics.Item("Investment Amount")
  186.  
  187. arrAmountColumns(2, 1) = ixSinglePremiumColumn
  188. arrAmountColumns(2, 2) = ColMetrics.Item("Single Premium")
  189.  
  190. arrAmountColumns(3, 1) = ixMonthlyPremiumColumn
  191. arrAmountColumns(3, 2) = ColMetrics.Item("Monthly Premium")
  192.  
  193. Dim LB1 As Long, UB1 As Long
  194. AssignArrayBounds arrAmountColumns, LB1, UB1
  195.  
  196.  
  197. varElement = ArrAggregatedData(row, ixDateSubmittedColumn)
  198. bDateSubmittedIsPresent = (IsDate(varElement) And Not IsEmpty(varElement))
  199.  
  200.  
  201. bSubmittedAmountIsPresent = False
  202. For i = LB1 To UB1
  203.  
  204. varElement = ArrAggregatedData(row, arrAmountColumns(i, 1))
  205. bValuePresent = (IsNumeric(varElement) And Not IsEmpty(varElement) And varElement <> 0)
  206. If bValuePresent And bSubmittedAmountIsPresent Then bMultipleBusinessTypesArePresent = True
  207. If bValuePresent And Not bSubmittedAmountIsPresent Then bSubmittedAmountIsPresent = True
  208.  
  209. If bValuePresent Then strBusiness = arrAmountColumns(i, 2)
  210.  
  211. Next i
  212.  
  213.  
  214. For i = ixFirstMonthColumn To ixFirstMonthColumn + 11
  215.  
  216. varElement = ArrAggregatedData(row, i)
  217. If (IsNumeric(varElement) And Not IsEmpty(varElement) And varElement <> 0) Then bRecurringBusinessIsPresent = True
  218.  
  219. Next i
  220. If bRecurringBusinessIsPresent Then strBusiness = ColMetrics.Item("Recurring")
  221.  
  222.  
  223. varElement = ArrAggregatedData(row, ixCommissionDueColumn)
  224. bCommissionIsPresent = (IsNumeric(varElement) And Not IsEmpty(varElement) And varElement <> 0)
  225. If Not (bSubmittedAmountIsPresent Or bRecurringBusinessIsPresent) And bCommissionIsPresent Then strBusiness = ColMetrics.Item("Invoice")
  226.  
  227. CheckErrorConditionsBusinessType row, bDateSubmittedIsPresent, bSubmittedAmountIsPresent, bMultipleBusinessTypesArePresent, bRecurringBusinessIsPresent, bCommissionIsPresent
  228.  
  229. TypeOfBusiness = strBusiness
  230.  
  231. End Function
  232.  
  233. Public Sub CheckErrorConditionsBusinessType(ByVal row As Long, ByVal bDateSubmittedIsPresent As Boolean, ByVal bSubmittedAmountIsPresent As Boolean, _
  234. ByVal bMultipleBusinessTypesArePresent As Boolean, ByVal bRecurringBusinessIsPresent As Boolean, ByVal bCommissionIsPresent As Boolean)
  235. Dim bError As Boolean
  236.  
  237. Dim strErrorMessage As String
  238.  
  239. '/ Check for: Multiple types of submitted business, submitted and recurring, submitted without date, no business at all
  240.  
  241. bError = False
  242.  
  243. If bMultipleBusinessTypesArePresent _
  244. Then
  245. bError = True
  246. strErrorMessage = strErrorMessage & "Found Multiple Types of Submitted Business on line: " & row
  247. End If
  248.  
  249. If bSubmittedAmountIsPresent And bRecurringBusinessIsPresent _
  250. Then
  251. bError = True
  252. strErrorMessage = strErrorMessage & "Found Submitted and Recurring Business on line: " & row
  253. End If
  254.  
  255. If Not (bSubmittedAmountIsPresent Or bRecurringBusinessIsPresent Or bCommissionIsPresent) _
  256. Then
  257. bError = True
  258. strErrorMessage = strErrorMessage & "Could not find any submitted or recurring business on line: " & row
  259. End If
  260.  
  261. If bSubmittedAmountIsPresent And Not bDateSubmittedIsPresent _
  262. Then
  263. bError = True
  264. strErrorMessage = strErrorMessage & "No Date Submitted for business on line: " & row
  265. End If
  266.  
  267. If bError = True Then ErrorMessage strErrorMessage
  268.  
  269. End Sub
  270.  
  271. Public Sub DetermineAllocatedBusinessIndexes(ByVal row As Long, ByRef ixAdviser As Long, ByRef ixAdviserColumn As Long, ByRef ixMetric As Long, ByRef ixMetricColumn As Long, _
  272. ByRef ixProvider As Long, ByRef ixProviderColumn As Long, ByRef ixMonth As Long, ByRef ixDateColumn As Long, ByRef strTypeOfBusiness As String)
  273. Dim i As Long
  274.  
  275. Dim varSearchValue As Variant
  276.  
  277. Dim strErrorMessage As String
  278.  
  279. Dim lngDimension As Long
  280.  
  281. Dim arrMetrics As Variant
  282. arrMetrics = Array()
  283. ReDim arrMetrics(1 To ColMetrics.Count)
  284. For i = 1 To ColMetrics.Count
  285. arrMetrics(i) = ColMetrics(i)
  286. Next i
  287.  
  288. varSearchValue = ArrAggregatedData(row, ixAdviserColumn)
  289. ixAdviser = IndexInArray1d(ArrAdvisers, varSearchValue)
  290.  
  291. varSearchValue = ColMetrics.Item(strTypeOfBusiness)
  292. ixMetric = IndexInArray1d(arrMetrics, varSearchValue)
  293.  
  294. varSearchValue = ArrAggregatedData(row, ixProviderColumn)
  295. ixProvider = IndexInArray1d(ArrProviders, varSearchValue)
  296.  
  297.  
  298. Select Case strTypeOfBusiness
  299.  
  300. Case Is <> ColMetrics.Item("Recurring")
  301. ixMonth = 0
  302. varSearchValue = ArrAggregatedData(row, ixDateColumn)
  303. ixMonth = Month(varSearchValue)
  304. If ixMonth = 0 _
  305. Then
  306. strErrorMessage = "Could not determine month of " & varSearchValue & " on row: " & row
  307. ErrorMessage strErrorMessage
  308. End If
  309.  
  310. Case Is = ColMetrics.Item("Recurring")
  311. '/ do nothing
  312.  
  313. End Select
  314.  
  315. End Sub
  316.  
  317. Public Sub AllocateBusiness(ByRef ixBusinessColumn As Long, ByRef ixAdviser As Long, ByRef ixMetric As Long, ByRef ixProvider As Long, ByRef ixMonth As Long, ByVal row As Long)
  318.  
  319. Dim i As Long, j As Long, k As Long
  320.  
  321. Dim strErrorMessage As String
  322.  
  323. Dim dblCurrentValue As Double
  324. Dim dblAdditionalValue As Double
  325. Dim dblNewValue As Double
  326.  
  327. dblCurrentValue = ArrAllocatedBusiness(ixAdviser, ixMetric, ixProvider, ixMonth)
  328.  
  329. dblAdditionalValue = ArrAggregatedData(row, ixBusinessColumn)
  330.  
  331. dblNewValue = dblCurrentValue + dblAdditionalValue
  332.  
  333. ArrAllocatedBusiness(ixAdviser, ixMetric, ixProvider, ixMonth) = dblNewValue
  334.  
  335. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement