Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Advanced Reports Dr. Peter Wayne. 2 Here is the set we will use for the report.

Similar presentations


Presentation on theme: "1 Advanced Reports Dr. Peter Wayne. 2 Here is the set we will use for the report."— Presentation transcript:

1 1 Advanced Reports Dr. Peter Wayne

2 2 Here is the set we will use for the report.

3 3 There is a 1:many link on the 'transactionid' field.

4 4 Always begin your report with the Quick Report Genie.

5 5

6 6

7 7

8 8 We will group by the linking field of the parent table.

9 9 Add fields from the child table

10 10 Grouping

11 11 Ordering

12 12 Remove spurious summations

13 13 Take advantage of formatting help

14 14

15 15 Move parent table fields from the Detail section to the Group section. Move child table fields to the left in the Detail section. Shorten all the lines created by the genie and make the report 8.5" wide. You now should have a report that looks like the one in the next slide. Save the report under a name, before any accident makes you lose all your work!

16 16

17 17

18 18 Now, let's add parameters to the report. We'll ask the user for 6a beginning date 6an ending date 6whether to include all transactions, or only reconciled transactions (status="R") We'll ask for these parameters in the OnPrintInit event of the report.

19 19

20 20 Use the Xbasic script genie to help write the event script.

21 21 The genie has an option to create an Xdialog box.

22 22 The Xbasic genie helps us create the xdialog.

23 23 Here, I choose ls_begin_date as the variable name. I specify that it is of type "Date", that its width is 12, and I will use a calendar control to enter the date.

24 24 End date is similar. A 3rd variable, "ls_include", specifies whether to include all transactions or just reconciled ones, and uses radio buttons for input.

25 25 Pressing "Define radio buttons" brings up this dialog:

26 26 And then we enter a title for the Xdialog box.

27 27 This is important -- specify that the variables in this script are shared.

28 28

29 29 Insert generated code into code editor and modify it. In my case, remove the extra quotation marks added by the genie around the default for ls_include in the line, ls_include=""all transactions""

30 30 The xdialog returns 4 values: 1) varC_result contains "OK" or "Cancel" 2) ls_start_date, ls_end_date, and ls_include are all shared variables. If the user presses "Cancel", we want to abort the printing. A5v5's OnPrintInit will abort printing if a cancel() is issued. So let's add a few lines to the end of the Xdialog:

31 31

32 32 Now we use the variables from our Xdialog to create a filter that can be used in the Detail, Records specification of the report. Add these lines of code: dim shared flter as c flter="between(date,{"+dtoc(ls_begin_date)+"},{"+\ dtoc(ls_end_date)+"})" if ls_include="only reconciled transactions" then flter=flter+".and. status='R'" end Add flter to the variables for the report:

33 33

34 34 Flter is defined as a session-level variable.

35 35 Place the flter variable in the Report's Detail Properties section.

36 36 Make eval(flter) the filter expression for the Detail section's Records property. Change "Base report on current selection of records" to "None" in Additional Record Order and Filter Criteria.

37 37 We generate a very respectable xdialog when the report is previewed:

38 38

39 39 Since we made the different ls_xxx variables shared variables, we can put them on the report for a more professional appearance: Here I have added them to the form's variable definition.

40 40 Putting the variables on the report makes the report self- documenting.

41 41 The subpayee in the child is often the same as the payee in the parent record. We can use a conditional object to suppress the superfluous display of the subpayee field. Here I have put a conditional object around the subpayee field.

42 42 The first condition is Payee=Mycheckdetail->Subpayee

43 43 The default condition is to show the subpayee, but if the subpayee is the same as the payee, then the field is suppressed. A similar choice is made with the subamount field:

44 44 Notice that repetition of the subpayee and subpayment is now suppressed.

45 45 Make one report do the work of two with a conditional object. We'll create an Account Summary report to summarize transactions by account. Since the account field is part of the detail record, we first need to create a set in which the detail items are primary. Create a 1:1 link from mycheckdetail to checkbook:

46 46 Then create a Quick Report with Grouping by the Account field in Mycheckdetail:

47 47 Add a session-level logical variable, show_detail, to the report definition:

48 48 Place a conditional object around the entire set of fields in the Detail section of the report.

49 49 Check "Object can shrink" in the properties for the conditional object: The condition is "var->show_detail=.f."

50 50 Check "Shrink contents of band" in the properties for the entire Detail section:

51 51 Define an Xdialog box for the reports OnPrintInit event to ask whether to show detail records:

52 52 The report initializes with this dialog box:

53 53 Here is the report with details checked

54 54 And here is the same report without details shown:

55 55 Sometimes an intermediate table is required to generate a desired report Example: A calendar-type report:

56 56 The on-call schedule is entered into a simple flat table:

57 57 dim docslist as c docslist=<<%a% M O P F %a% dim docs[4] as c docs.initialize(docslist) dim t as p ' empty the on call schedule table t=table.open("on call schedule",file_rw_exclusive) t.zap(.t.) The On-call schedule is initially filled from a single script. First, we initialize an array of the 4 on-call doctors:

58 58 dim dy as d dim week as n dim i as n dim j as n dy={1/1/2002} j=1 week=1 The script continues by initializing the week and setting the date to the new year

59 59 for i=1 to 366 t.enter_begin() t.date=dy t.Day_of_week=cdow(dy) t.On_call_doctor=docs[j] t.Week=week t.enter_end(.t.) dy=dy+1 if dow(dy)>1.and. dow(dy)<7 then ' it's not a Sat or Sun, so on-call doctor changes j=if(j<4,j+1,1) end if if dow(dy)=1 then week=week+1 end if next i The table is filled with the day, the day of the week, the on-call doctor, and the week number

60 60 It is difficult to generate an acceptable calendar report from the On Call Schedule.dbf. It is easier to generate a calendar report from a poorly normalized table whose structure imitates the structure of weeks and months:

61 61 This structure lends itself more naturally to the desired report format:

62 62 The scratch table is filled from the working table through an Xbasic script: t=table.open("on call schedule",file_ro_shared) ' read from t2=table.open("oncallcalendar",file_rw_exclusive) ' write to t2.zap(.t.) t2.close() t2=table.open("oncallcalendar",file_rw_shared) 'it is empty now t.fetch_first() ' read from on call schedule.dbf thisyear=year(t.date) while thisyear<2004 for thismonth=1 to 12 firstofmonth=ctod(alltrim(str(thismonth))+"/1/"+alltrim(str(thisyear))) ' continued next slide

63 63 fltr="between(date,\ {"+dtoc(firstofmonth)+"},{"+dtoc(end_of_month(firstofmonth))+"})" query.filter=fltr query.options="M" query.order="date" ix=t.query_create() t.fetch_first() mnth=month(t.date) ' continued next slide The rest of the script is reproduced on these next slides so that you can study it later, if you wish.

64 64 while.not. t.fetch_eof() t2.enter_begin() dayofweek=dow(t.date) if dayofweek>1 then for i=1 to dayofweek*2-2 fld=t2.field_get(i) fld.blank_put() next i t2.month_year=cmonth(t.date)+", "+cyear(t.date) end if for i=dayofweek to 7 fld=t2.field_get(dow(t.date)*2-1) fld.value_put(t.on_call_doctor) fld=t2.field_get(dow(t.date)*2) fld.value_put(t.date) if t.holiday=.t. then

65 65 pos=atc("_",fld.name_get()) fldname=left(fld.name_get(),pos)+"Hol" fld=t2.field_get(dow(t.date)*3) eval("t2."+fldname)=.t. end if t2.month=mnth+12*(thisyear-2001) t2.month_year=cmonth(t.date)+", "+cyear(t.date) t.fetch_next() next i t2.enter_end(.t.) end while ix.drop() next thismonth thisyear=thisyear+1 end while t2.close() t.close() ' end of script

66 66 To summarize: I needed a way to create and then calendrically display the on-call schedule. It was simplest to create the schedule in a single flat-file table and then to use Xbasic to copy the dates and the associated on-call doctor to another table, suitable for generating the calendar report. The report groups by months. Every field on the report is a calculated field. The details of this report (and the scripts) are not important-- what is important is the concept of moving your data from the data entry table into a scratch table to make the reporting simpler.


Download ppt "1 Advanced Reports Dr. Peter Wayne. 2 Here is the set we will use for the report."

Similar presentations


Ads by Google