Using the Form Designer, you can create a dashboard to show the top five customers for the last 12 months, and their sales totals, with links to lists of the invoices. This tutorial requires the IN Module.
Property |
Value |
Alignment |
taCentre |
ParentColor |
True |
Transparent |
True |
Next, you can write MaxBasic code to add the figures to the labels.
Dim PeriodToUse as Number, StartPeriod as Number, EndPeriod as Number
PeriodToUse = CurrentPeriod("AR")
StartPeriod = AddPeriod(PeriodToUse, -12,True)
EndPeriod = AddPeriod(PeriodToUse, -1,True)
This sets the PeriodToUse to the current AR Period, the StartPeriod to 12 periods prior to the PeriodToUse, and EndPeriod to 1 period before PeriodToUse.
Sub RefreshTopCustomers
SQLCUST = "SELECT INHEAD.CustomerCode " & _
" ,Sum(Case When INHEAD.PeriodID Between :StartPeriod AND :EndPeriod Then INHEAD.ExclusiveAmount Else 0 End) as Sales " & _
"FROM INHEAD INNER JOIN ARCUST ON ARCUST.CustomerCode=INHEAD.CustomerCode " & _
"WHERE (INHEAD.PeriodID Between :StartPeriod and :EndPeriod " & _
" AND INHEAD.DocumentClass IN ( 'I' , 'C' ) " & _
" AND INHEAD.PostStatus IN ( 'U' , 'P' )) " & _
"GROUP BY INHEAD.CustomerCode " & _
"ORDER BY Sales DESC "
tblCustomers = ExecuteSQL(SQLCUST, StartPeriod, EndPeriod)
Counter = 0
tblCustomers.First
Do Until tblCustomers.EOF or (Counter >= 5)
If Counter = 0 Then
LinkTopCust1.caption = tblCustomers.CustomerCode
lblCust1.caption = CHR(10) & " $" & FormatNumber(tblCustomers.Sales, ",0.00")
End If
If Counter = 1 Then
LinkTopCust2.caption = tblCustomers.CustomerCode
lblCust2.caption = CHR(10) & " $" & FormatNumber(tblCustomers.Sales, ",0.00")
End If
If Counter = 2 Then
LinkTopCust3.caption = tblCustomers.CustomerCode
lblCust3.caption = CHR(10) & " $" & FormatNumber(tblCustomers.Sales, ",0.00")
End If
If Counter = 3 Then
LinkTopCust4.caption = tblCustomers.CustomerCode
lblCust4.caption = CHR(10) & " $" & FormatNumber(tblCustomers.Sales, ",0.00")
End If
If Counter = 4 Then
LinkTopCust5.caption = tblCustomers.CustomerCode
lblCust5.caption = CHR(10) & " $" & FormatNumber(tblCustomers.Sales, ",0.00")
End If
Counter = Counter + 1
tblCustomers.Next
Loop
End Sub
Sub OnCreate
RefreshTopCustomers
End Sub
(Ctrl+S).(Ctrl+R) to test the form.Next, you can link the Link Labels to lists of invoices.
Sub ONLinkTopCust1
SQLTopCUST = "SELECT INHEAD.CustomerCode as Customer " & _
" ,INHead.DocumentID as DocID " & _
" ,INHead.DocumentNo as DocNo " & _
" ,INHead.DocumentType as DocType " & _
" ,INHead.DocumentClass as DocClass " & _
" ,INHead.DocumentDate as DocDate " & _
" ,INHead.ExclusiveAmount " & _
" ,INHead.ExclusiveCost " & _
"FROM INHEAD INNER JOIN ARCUST ON ARCUST.CustomerCode=INHEAD.CustomerCode " & _
"WHERE (INHEAD.PeriodID Between :StartPeriod and :EndPeriod " & _
" AND INHEAD.DocumentClass IN ( 'I' , 'C' ) " & _
" AND INHEAD.PostStatus IN ( 'U' , 'P' ) " & _
" AND INHEAD.CustomerCode = :CUST ) " & _
"ORDER BY DocID DESC "
tblTopCust = ExecuteSQL(SQLTopCUST, StartPeriod, EndPeriod, LINKTOPCUST1.caption)
tblTopCust.Fields.Item("Customer").Visible = False
tblTopCust.Fields.Item(6).Total = True
tblTopCust.Fields.Item(7).Total= True
Report = CreateReport(tblTopCust, "Invoices and Credits For " & tblTopCust.Customer & CHR(10) & " From " & (PeriodName(StartPeriod) & " To " & (PeriodName(EndPeriod))))
Report.Destination = "Screen"
Report.Run
Handled = True
End Sub
(Ctrl+S).(Ctrl+R) to test the form. When you click on the Link Labels you will see the relevant list of Invoices.