cat > script <<'+-+-+-+-+-END-OF-FILE-+-+-+-+-+'
parameters
	char	dbname;
end

let database = dbname;
let PageLength = 66;

select name, customer_no, address, date, job_no, description, number,
	tenth_hours, rate from customers, worked alias DEKROW, rates, jobs where
	customers.number = jobs.customer_no and jobs.job_no = DEKROW.job_no
	and DEKROW.code = rates.code sort by job_no;

define billrate = rate * 1.5;
define total = billrate * tenth_hours / 10;

for each group of job_no
	print	sum of total, newline,
		count of total, newline,
		count of total where total != null, newline,
		average of total, newline,
		average of total where total != null, newline,
		max of total, newline,
		min of total, newline 3;
	for each record
		print "| ", DEKROW."date" picture "MM/DD", " | ";
		print description, column 34, number width 8 centre;
		print column 44, tenth_hours picture "F9.9" width 4 right;
		print column 50, billrate picture "$FF9V.99" width 6 right;
		print "/hr | ";
		print column 64, total picture "$FFF9V.99" width 7 right;
		print " |", newline;
	end;  
	print "|       |       TOTAL FOR THIS INVOICE            ";
	print "     | ", column 64, sum of total picture "$FFF9V.99" width 7 right;
	print " |", newline;
	print sum of total picture "$FFF9V.99" width 7 right, newline;
	newpage;
end;  

end;
+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 755 script
cat > stdout <<'+-+-+-+-+-END-OF-FILE-+-+-+-+-+'
30
1
1
30
30
30
30


| 02/28 | Bent Rear Fender          4       1.0  $30.00/hr |    $30.00 |
|       |       TOTAL FOR THIS INVOICE                 |        $30.00 |
 $30.00






















































97.5
3
3
32.5
32.5
75
11.25


| 02/28 | Lube and grease           6       0.5  $22.50/hr |    $11.25 |
| 02/28 | Tire repair               6       0.5  $22.50/hr |    $11.25 |
| 02/28 | Sparks & tune             6       2.5  $30.00/hr |    $75.00 |
|       |       TOTAL FOR THIS INVOICE                 |        $97.50 |
 $97.50




















































60
1
1
60
60
60
60


| 03/01 | Sparks & tune             2       2.0  $30.00/hr |    $60.00 |
|       |       TOTAL FOR THIS INVOICE                 |        $60.00 |
 $60.00






















































150
3
3
50
50
75
30


| 03/01 | Replace rear wheel        5       1.0  $30.00/hr |    $30.00 |
| 03/01 | Wheel alignment           5       1.5  $30.00/hr |    $45.00 |
| 03/01 | Bent door                 5       2.0  $37.50/hr |    $75.00 |
|       |       TOTAL FOR THIS INVOICE                 |       $150.00 |
$150.00




















































+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 644 stdout
cat > tag <<'+-+-+-+-+-END-OF-FILE-+-+-+-+-+'
test accumulators (uses aliases)
+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 644 tag
