VERSION 5.00 Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmMain Caption = "Main" ClientHeight = 9255.001 ClientLeft = 120 ClientTop = 465 ClientWidth = 8655.001 OleObjectBlob = "frmMain.frx":0000 StartUpPosition = 1 'CenterOwner End Attribute VB_Name = "frmMain" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim monthly_commission As Variant Dim montyly_commission_TA As Variant Dim montyly_commission_TB As Variant Dim quartely_commission_TA As Variant Dim quartely_commission_TB As Variant Dim monthly_top_5_comission_name As Variant Dim monthly_top_5_comission_value As Variant Dim monthly_total As Variant Dim monthly_total_TA As Variant Dim monthly_total_TB As Variant Dim month_selected As Integer Dim sales_selected As String Dim sales_data_loaded As Boolean Dim calc_result_empty As Boolean Dim pivot_result Dim get_team_monthly_sale Dim teams_month_total_sale, team_a_month_total_sale, team_b_month_total_sale Dim best_selling_result Dim month_best_agent Dim team_a_best_name, team_a_best_value, team_a_best_commission Dim team_b_best_name, team_b_best_value, team_b_best_commission Dim apanalysis_calc_result As Variant Dim apanalysis_sales_calc_result As Variant Dim agent_name_selected As String Dim str_month_selected As String Dim name_and_month As String Dim case_persistency_pivot As Variant Dim agent_month_new_case, agent_month_collapsed_case, agent_quarter_new_case, agent_quarter_collapsed_case, agent_month_case_persistency, agent_quarter_case_persistency Dim agent_monthly_sale As Variant Dim monthly_total_sell, month_total_commission Function validateAgentSalesFile(workfile_xls_filename As String) As Boolean Dim validation_result As Boolean validation_result = True Set agent_sales_workbook = Workbooks.Open(workfile_xls_filename) Set agent_sales_worksheet = agent_sales_workbook.Worksheets(1) If (agent_sales_worksheet.Cells(1, 1) <> "Sales No.") Then validation_result = False End If If (agent_sales_worksheet.Cells(1, 2) <> "Date") Then validation_result = False End If If (agent_sales_worksheet.Cells(1, 3) <> "Agent Name") Then validation_result = False End If agent_sales_workbook.Close validateAgentSalesFile = validation_result End Function Function validateAgentWorkingPerformanceFile(workfile_xls_filename As String) As Boolean Dim validation_result As Boolean validation_result = True Set agent_working_performance_workbook = Workbooks.Open(workfile_xls_filename) Set agent_working_performance_worksheet = agent_working_performance_workbook.Worksheets(1) If (agent_working_performance_worksheet.Cells(1, 1) <> "Date") Then validation_result = False End If If (agent_working_performance_worksheet.Cells(1, 2) <> "Name") Then validation_result = False End If If (agent_working_performance_worksheet.Cells(1, 3) <> "Team") Then validation_result = False End If agent_working_performance_workbook.Close savechanges:=False validateAgentWorkingPerformanceFile = True End Function Function validateProductSalesFile(workfile_xls_filename As String) As Boolean Dim validation_result As Boolean validation_result = True Set product_sales_workbook = Workbooks.Open(workfile_xls_filename) Set product_sales_worksheet = product_sales_workbook.Worksheets(1) If (product_sales_worksheet.Cells(1, 1) <> "Sales No.") Then validation_result = False End If If (product_sales_worksheet.Cells(1, 2) <> "Date") Then validation_result = False End If If (product_sales_worksheet.Cells(1, 3) <> "Product Category") Then validation_result = False End If product_sales_workbook.Close validateProductSalesFile = True End Function Private Sub cmbMonthSelect_Change() If (cmbMonthSelect.Value <> "") Then str_month_selected = Common.ConvLetterMonthToIntMonth(cmbMonthSelect.Value) If (calc_result_empty = False) Then name_and_month = agent_name_selected & "," & str_month_selected frmMain.UpdateScreen End If End If End Sub Sub UpdateScreen() ' team details Dim team_a_agent_name, team_b_agent_name As String team_a_agent_name = team_a_best_name(str_month_selected) team_b_agent_name = team_b_best_name(str_month_selected) lblTotalSales.Caption = "Total Sales: " & " " & Format(teams_month_total_sale(str_month_selected), "0.00") lblMonthlyCommissionTA.Caption = "Team A: " & "$" & Format(team_a_month_total_sale(str_month_selected), "0.00") lblMonthlyCommissionTB.Caption = "Team B: " & "$" & Format(team_b_month_total_sale(str_month_selected), "0.00") lblTaTopSeller.Caption = team_a_agent_name lblTbTopSeller.Caption = team_b_agent_name 'commission lblTaTopSellingUnit.Caption = Format(team_a_best_commission(str_month_selected), "0.00") lblTbTopSellingUnit.Caption = Format(team_b_best_commission(str_month_selected), "0.00") lblTaTopMonthlySales.Caption = Format(team_a_best_value(str_month_selected), "0.00") lblTbTopMonthlySales.Caption = Format(team_b_best_value(str_month_selected), "0.00") lblTaCasePersistency.Caption = Format(agent_month_case_persistency(team_a_agent_name & "," & str_month_selected), "0.00%") lblTbCasePersistency.Caption = Format(agent_month_case_persistency(team_b_agent_name & "," & str_month_selected), "0.00%") StatusTa.BackColor = Var.STATUS_COLOR_GREEN If (agent_month_case_persistency(team_a_agent_name & "," & str_month_selected) < 0.66) Then StatusTa.BackColor = Var.STATUS_COLOR_YELLOW End If If (agent_month_case_persistency(team_a_agent_name & "," & str_month_selected) < 0.33) Then StatusTa.BackColor = Var.STATUS_COLOR_RED End If StatusTb.BackColor = Var.STATUS_COLOR_GREEN If (agent_month_case_persistency(team_b_agent_name & "," & str_month_selected) < 0.66) Then StatusTb.BackColor = Var.STATUS_COLOR_YELLOW End If If (agent_month_case_persistency(team_b_agent_name & "," & str_month_selected) < 0.33) Then StatusTb.BackColor = Var.STATUS_COLOR_RED End If ' agent details Common.initAccountFromAccountSheet lblAgentName.Caption = agent_name_selected lblAgentAge.Caption = Common.LookupAge(agent_name_selected) lblAgentTeam.Caption = Common.LookupTeam(agent_name_selected) lblCasePersistency.Caption = Format(agent_month_case_persistency(name_and_month), "0.00") lblCollpasedCase.Caption = agent_month_collapsed_case(name_and_month) lblNewCase.Caption = agent_month_new_case(name_and_month) lblTotalComission.Caption = month_total_commission(name_and_month) lblTotalSale.Caption = Format(monthly_total_sell(name_and_month), "0.00") ' check if path found ' handle throw error If (Dir(Application.ActiveWorkbook.Path & "\images\" & agent_name_selected & ".jpg") = "") Then Msgbox "Sorry but the path for staff profile image not found" Else Image1.Picture = LoadPicture(Application.ActiveWorkbook.Path & "\images\" & agent_name_selected & ".jpg") End If End Sub Private Sub cmbAgentSelect_Change() If (cmbAgentSelect.Value <> "") Then agent_name_selected = cmbAgentSelect.Value If (calc_result_empty = False) Then 'monthly_commission_per_agent name_and_month = agent_name_selected & "," & str_month_selected frmMain.UpdateScreen End If End If End Sub Private Sub cmdBrowseAgentSalesFileBtn_Click() Dim validate_result As Boolean Var.agentSalesFilePath = Application.GetOpenFilename(FileFilter:="Excel files (*.xlsx*), *.xlsx*", Title:="Choose an Excel file to open", MultiSelect:=False) Debug.Print CStr(Var.agentSalesFilePath) If CStr(Var.agentSalesFilePath) = CStr(False) Then ' User did not select a file MsgBox "no file selected" Else ' User selected a file txtBrowseAgentSalesFilePath.Value = Var.agentSalesFilePath validate_result = validateAgentSalesFile(Var.agentSalesFilePath) If (validate_result = False) Then MsgBox "sorry but wrong agent sales file selected" Var.agentSalesFilePath = "" txtBrowseAgentSalesFilePath.Text = "" Else Debug.Print "agent sales file validation OK" Var.agent_sales_file_OK = True End If End If End Sub Sub UpdateSelectReportTabStatus() Dim result As Boolean result = False If (Var.agent_sales_file_OK = True) Then If (Var.agent_working_performance_OK = True) Then If (Var.product_sales_OK = True) Then MultiPage1.Pages(1).Enabled = True MultiPage1.Pages(2).Enabled = True End If End If End If End Sub Private Sub cmdBrowseAgentWorkingPerformanceBtn_Click() Dim validate_result As Boolean Var.agentWorkingPerformancePath = Application.GetOpenFilename(FileFilter:="Excel files (*.xlsx*), *.xlsx*", Title:="Choose an Excel file to open", MultiSelect:=False) Debug.Print CStr(Var.agentWorkingPerformancePath) If CStr(Var.agentWorkingPerformancePath) = CStr(False) Then ' User did not select a file MsgBox "no file selected" Else ' User selected a file txtBrowseAgentWorkingPerformancePath.Value = Var.agentWorkingPerformancePath validate_result = validateAgentWorkingPerformanceFile(Var.agentWorkingPerformancePath) If (validate_result = False) Then MsgBox "sorry but wrong agent sales file selected" Var.agentWorkingPerformancePath = "" txtBrowseAgentWorkingPerformancePath.Text = "" Else Debug.Print "agent sales file validation OK" Var.agent_working_performance_OK = True End If End If End Sub Private Sub cmdBrowseProductSalesBtn_Click() Dim validate_result As Boolean Var.productSalesPath = Application.GetOpenFilename(FileFilter:="Excel files (*.xlsx*), *.xlsx*", Title:="Choose an Excel file to open", MultiSelect:=False) If CStr(Var.productSalesPath) = CStr(False) Then ' User did not select a file MsgBox "no file selected" Else ' User selected a file txtBrowseProductSalesPath.Value = Var.productSalesPath validate_result = validateProductSalesFile(Var.productSalesPath) If (validate_result = False) Then MsgBox "sorry but wrong agent sales file selected" Var.productSalesPath = "" txtBrowseProductSalesPath.Text = "" Else Debug.Print "agent sales file validation OK" Var.product_sales_OK = True End If End If End Sub Private Sub cmdCalculate_Click() Dim sPath As String Var.AgentSalesMeta = ReadAgentSalesWorkbook.Run(Var.agentSalesFilePath) Var.ProductSalesMeta = ReadProductSalesWorkbook.Run(Var.productSalesPath) Var.AgentWorkingPerformanceMeta = ReadAgentWorkingPerfWorkbook.Run(Var.agentWorkingPerformancePath) Var.CombinedSalesMeta = Array(Var.AgentSalesMeta, Var.ProductSalesMeta, Var.AgentWorkingPerformanceMeta) calc_result_empty = False case_persistency_pivot = awp_xlsx_case_persistency_pivot.OpenFile(Var.agentWorkingPerformancePath) Set agent_month_new_case = case_persistency_pivot(0) Set agent_month_collapsed_case = case_persistency_pivot(1) Set agent_quarter_new_case = case_persistency_pivot(2) Set agent_quarter_collapsed_case = case_persistency_pivot(3) Set agent_month_case_persistency = case_persistency_pivot(4) Set agent_quarter_case_persistency = case_persistency_pivot(5) agent_monthly_sale = as_xlsx_get_agent_monthly_sale.OpenFile(Var.agentSalesFilePath) Set monthly_total_sell = agent_monthly_sale(0) Set month_total_commission = agent_monthly_sale(1) month_best_agent = as_xlsx_get_month_best_agent.OpenFile(Var.agentSalesFilePath) 'Set monthly_total_sell = month_best_agent(0) Set team_a_best_name = month_best_agent(1) Set team_a_best_value = month_best_agent(2) Set team_a_best_commission = month_best_agent(3) Set team_b_best_name = month_best_agent(4) Set team_b_best_value = month_best_agent(5) Set team_b_best_commission = month_best_agent(6) month_best_agent = as_xlsx_get_team_monthly_sale.OpenFile(Var.agentSalesFilePath) Set teams_month_total_sale = month_best_agent(0) Set team_a_month_total_sale = month_best_agent(1) Set team_b_month_total_sale = month_best_agent(2) agent_name_selected = "Alex" str_month_selected = "1" name_and_month = "Alex,1" frmMain.UpdateScreen ' APAnalysis_WriteTable calc_result, file_path, wb cmbMonthSelect.Enabled = True optTeamEnable.Enabled = True optAgentEnable.Enabled = True framePressToStart.Visible = False frameTeamDetails.Visible = True ' wb.Save ' wb.Close Debug.Print "done" End Sub Private Sub cmdLogout_Click() frmMain.Hide frmLogin.Show End Sub Private Sub cmdGenTextRpt_Click() Debug.Print "GenTextReport start" Common.GenTextReport Debug.Print "GenTextReport end" End Sub Private Sub cmdTest_Click() End Sub Private Sub CommandButton11_Click() End End Sub Function createNewXlsx(file_path As String) Dim wb As Workbook Set wb = Workbooks.Add wb.SaveAs file_path wb.Close End Function Private Sub UserForm_Initialize() calc_result_empty = True Config.init 'txtOutputRptDirectory.Text = Var.output_report_directory frmMain.cmbGenRptType.AddItem "01 Text Report" frmMain.cmbGenRptType.AddItem "02 Chart Report" frmMain.cmbMonthSelect.AddItem "Jan" frmMain.cmbMonthSelect.AddItem "Feb" frmMain.cmbMonthSelect.AddItem "Mar" frmMain.cmbMonthSelect.AddItem "Apr" frmMain.cmbMonthSelect.AddItem "May" frmMain.cmbMonthSelect.AddItem "Jun" frmMain.cmbMonthSelect.AddItem "Jul" frmMain.cmbMonthSelect.AddItem "Aug" frmMain.cmbMonthSelect.AddItem "Sep" frmMain.cmbMonthSelect.AddItem "Oct" frmMain.cmbMonthSelect.AddItem "Nov" frmMain.cmbMonthSelect.AddItem "Dec" cmbMonthSelect.Value = "Jan" frmMain.cmbAgentSelect.AddItem "Alex" frmMain.cmbAgentSelect.AddItem "Ben" frmMain.cmbAgentSelect.AddItem "Candy" frmMain.cmbAgentSelect.AddItem "Danny" frmMain.cmbAgentSelect.AddItem "Eason" frmMain.cmbAgentSelect.AddItem "Filex" frmMain.cmbAgentSelect.AddItem "Gary" frmMain.cmbAgentSelect.AddItem "Henry" frmMain.cmbAgentSelect.AddItem "Irene" frmMain.cmbAgentSelect.AddItem "Jenny" sales_selected = "Alex" cmbAgentSelect.Text = "" cmbAgentSelect.Value = sales_selected cmbGenRptType.Text = "" cmbGenRptType.Value = "01 Text Report" framePressToStart.Visible = True framePressToStart.Top = 75 framePressToStart.Left = 10 framePressToStart.Height = 283 framePressToStart.Width = 388 frameAgentDetails.Visible = False frameAgentDetails.Top = framePressToStart.Top frameAgentDetails.Left = framePressToStart.Left frameAgentDetails.Height = framePressToStart.Height frameAgentDetails.Width = framePressToStart.Width frameTeamDetails.Visible = False frameTeamDetails.Top = framePressToStart.Top frameTeamDetails.Left = framePressToStart.Left frameTeamDetails.Height = framePressToStart.Height frameTeamDetails.Width = framePressToStart.Width ' align frame in tab 2 frmChartRpt.Top = frmTextReport.Top frmChartRpt.Left = frmTextReport.Left frmChartRpt.Height = frmTextReport.Height frmChartRpt.Width = frmTextReport.Width Var.STATUS_COLOR_GREEN = RGB(0, 128, 0) Var.STATUS_COLOR_YELLOW = RGB(255, 255, 0) Var.STATUS_COLOR_RED = RGB(255, 0, 0) End Sub Private Sub txtOutputRptDirectory_Change() Var.output_report_directory = txtOutputRptDirectory.Text End Sub Private Sub cmdGenReport_Click() If (frmMain.cmbGenRptType.Value = "01 Text Report") Then Common.GenTextReport End If If (frmMain.cmbGenRptType.Value = "02 Chart Report") Then Common.GenChartReport End If End Sub Private Sub optAgentEnable_Click() If (optAgentEnable.Value) Then cmbAgentSelect.Enabled = True frameAgentDetails.Visible = True frameTeamDetails.Visible = False End If End Sub Private Sub optTeamEnable_Click() If (optTeamEnable.Value) Then cmbAgentSelect.Enabled = False frameTeamDetails.Visible = True frameAgentDetails.Visible = False End If End Sub Private Sub cmbGenRptType_Change() If (cmbGenRptType.Value = "01 Text Report") Then frmTextReport.Visible = True frmChartRpt.Visible = False End If If (cmbGenRptType.Value = "02 Chart Report") Then frmChartRpt.Visible = True frmTextReport.Visible = False End If End Sub Private Sub cmdNext_Click() UpdateSelectReportTabStatus End Sub