1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
import "movieSchema"
import "reports"
Date d;
class BorrowerReportDetail : Detail
{
size = { 500, 22 };
font = { "Arial", 10 };
keepTogether = true;
Label movieName { this, anchor = { left = 44, top = 2, right = 0.30, bottom = 2 } };
Label dateBorrowed { this, anchor = { left = 0.5, top = 2, right = 0.20, bottom = 2 } };
bool OnCreate(void)
{
String s;
BorrowerReport report = (BorrowerReport)((ReportDestination)master).GetReport();
RowMovies row = (RowMovies)report.groupings[1].row;
s = row.name; movieName.text = s; delete s;
s = PrintString((ShortDate)row.dateBorrowed); dateBorrowed.text = s; delete s;
return true;
}
}
class BorrowerReportPageHeader : Detail
{
size = { 500, 30 };
font = { "Arial", 10, bold = true };
Label name { this, anchor = { left = 44, top = 9, right = 0.65, bottom = 2 }, text = "Movie Name" };
Label dateBorrowed { this, anchor = { left = 0.5, top = 9, right = 4, bottom = 2 }, text = "Date Borrowed" };
void OnRedraw(Surface surface)
{
int x = clientSize.w - 1, y = clientSize.h - 1;
surface.Rectangle(0, 5, x, y);
}
}
class BorrowerGroupHeader : Detail
{
size = { 500, 28 };
font = { "Arial", 10, bold = true };
keepTogether = true;
Label name { this, anchor = { left = 4, top = 7, right = 0.65, bottom = 2 } };
Label phone { this, anchor = { left = 0.4, top = 7, right = 4, bottom = 2 } };
bool OnCreate(void)
{
String s;
BorrowerReport report = (BorrowerReport)((ReportDestination)master).GetReport();
RowBorrowers row = (RowBorrowers)report.groupings[0].row;
s = row.name; name.text = s; delete s;
s = row.phoneNumber; phone.text = s; delete s;
return true;
}
void OnRedraw(Surface surface)
{
int x = clientSize.w - 1, y = clientSize.h - 1;
surface.Rectangle(0, 4, x, y - 2);
}
}
class BorrowerGroupContinuation : Detail
{
size = { 500, 28 };
font = { "Arial", 10, bold = true };
keepTogether = true;
Label name { this, anchor = { left = 4, top = 7, right = 0.65, bottom = 2 } };
bool OnCreate(void)
{
String s;
BorrowerReport report = (BorrowerReport)((ReportDestination)master).GetReport();
RowBorrowers row = (RowBorrowers)report.groupings[0].row;
s = PrintString(row.name, " (Continued)"); name.text = s; delete s;
return true;
}
void OnRedraw(Surface surface)
{
int x = clientSize.w - 1, y = clientSize.h - 1;
surface.Rectangle(0, 4, x, y - 2);
}
}
static int numMovies;
class BorrowerGroupFooter : Detail
{
size = { 500, 40 };
font = { "Arial", 10, bold = true };
keepTogether = true;
Label title { this, anchor = { left = 0.85, top = 9, right = 0.03, bottom = 2 }, text = "Total count:" };
Label total { this, anchor = { left = 0.97, top = 9, right = 9, bottom = 2 } };
bool OnCreate(void)
{
String s = PrintString(numMovies);
total.text = s;
delete s;
return true;
}
void OnRedraw(Surface surface)
{
int x = clientSize.w - 1;
surface.HLine(0, x, 5);
}
}
class BorrowerGrouping : Grouping
{
RowMovies rowMovies { };
bool ShouldSkip()
{
RowBorrowers r = (RowBorrowers)row;
Id id = r.id;
return !rowMovies.Find(dbfield("Movies", borrower), middle, nil, id);
}
}
int daysAgo;
class BorrowerReport : CommonReport
{
pageHeader = class(BorrowerReportPageHeader);
rowDetail = class(BorrowerReportDetail);
BorrowerReport()
{
groupings.size = 2;
groupings[1] = groupings[0];
groupings[0] = BorrowerGrouping { };
groupings[0].field = dbfield("Borrowers", id);
groupings[0].header = class(BorrowerGroupHeader);
groupings[0].continuation = class(BorrowerGroupContinuation);
groupings[0].footer = class(BorrowerGroupFooter);
}
bool ExecuteData(Database db)
{
DateTime now, d;
TimeStamp t;
now.GetLocalTime();
t = now;
t -= 60 * 60 * 24 * daysAgo; // Go back 90 days
d = t;
if(daysAgo)
{
static char reportTitle[256];
sprintf(reportTitle, "Movies borrowed for more than %d days", daysAgo);
title = reportTitle;
}
else
title = "Borrowed movies";
groupings[0].row = RowBorrowers { };
groupings[0].row.query = "SELECT ROWID, * FROM `Borrowers` ORDER BY `Name`;";
groupings[0].row.Select(nil);
groupings[1].row = RowMovies { };
groupings[1].row.query = "SELECT ROWID, * FROM `Movies` WHERE `Date Borrowed` < ? AND `Borrower` = ? ORDER BY `Date Borrowed`;";
groupings[1].row.SetQueryParamObject(1, Date { d.year, d.month, d.day }, class(Date));
return true;
}
void ExecuteRowData(int group)
{
if(group == 0)
{
groupings[1].row.SetQueryParam(2, (int)groupings[0].row.sysID);
numMovies = 0;
}
else if(group == 1)
numMovies++;
}
}
|