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

let database = dbname;
let PageLength = 66;
let LeftMargin = 5;

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

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

header
	newline 4;
	print column 5, "Joe's Auto Repairs";
	print column 41, "FOR THE BEST IN AUTO SERVICE", newline;
	print column 5, "1757 El Camino Real";
	print column 48, "(415) 957-8203", newline;
	print column 5, "Bayville, CA 92304", newline 2;
end;
footer
	newline 2;
	print column 10, "FOR THE BEST IN PARTS AND SERVICE -- ";
	print "JOE'S AUTO REPAIRS", newline 2;
	print column 15, "1757 El Camino Real, Bayville, CA 92304", newline;
	print column 27, "(415) 957-8203", newline 3;
end;

for each group of job_no
	print column 30, "INVOICE", newline;
	print column 40, "Invoice No.:  83-0", job_no, newline;
	print column 40, "Invoice Date: ", "TODAY";
	newline 2;
	print column 5, "Customer:  ", name, newline;
	print column 16, address overflow into addov, newline;
	while addov != ""
		print column 16, addov overflow into addov, newline;
	end;
	newline;
	print column 5, "___________________________________________________";
	print "_________________", newline;
	print column 5, "|       |                                          ";
	print "    |           |", newline;
	print column 5, "| Date  | Job Description    Mechanic  Hours Rate  ";
	print "    |   Total   |", newline;
	print column 5, "|-------|-----------------------------------------";
	print "-----|-----------|", newline;
	print column 5, "|       |                                          ";
	print "    |           |", newline;
	let linecount = 1;
	for each record
		print column 5, "| ", worked."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;
		let linecount = linecount + 1;
		if linecount = 30
			then
			print column 5, "|       |                                         ";
			print "     |           |", newline;
			print column 5, "|       |   CONTINUED  ON NEXT PAGE               ";
			print "     |           |", newline;
			print column 5, "|       |                                         ";
			print "     |           |", newline;
			print column 5, "|_______|_________________________________________";
			print "_____|___________|", newline 3;
			newpage;
			print column 30, "INVOICE", newline;
			print column 40, "Invoice No.:  83-0", job_no, newline;
			print column 40, "Invoice Date: ", "TODAY";
			print newline, column 40, "Page ", PageNumber;
			newline 2;
			print column 5, "Customer:  ", name, newline;
			print column 16, address, newline;
			while pending do newline; end;
			newline;
			print column 5, "___________________________________________________";
			print "_________________", newline;
			print column 5, "|       |                                          ";
			print "    |           |", newline;
			print column 5, "| Date  | Job Description    Mechanic  Hours Rate  ";
			print "    |   Total   |", newline;
			print column 5, "|-------|-----------------------------------------";
			print "-----|-----------|", newline;
			print column 5, "|       |                                          ";
			print "    |           |", newline;
		end;
	end;  
	print column 5, "|       |                                         ";
	print "     |           |", newline;
	print column 5, "|-------|-----------------------------------------";
	print "-----|-----------|", newline;
	print column 5, "|       |       TOTAL FOR THIS INVOICE            ";
	print "     | ", column 64, sum of total picture "$FFF9V.99" width 7 right;
	print " |", newline;
	print column 5, "|_______|_________________________________________";
	print "_____|___________|", newline 3;
	print column 5, "Invoice due on receipt.", newline;
	print column 5, "Please make check payable to:  Joe's Auto Repairs", newline 2;
	while linecount <= 12
		do
		print newline;
		let linecount = linecount + 1;
	end;
	print column 5, " - - - - - - - - - - - - - - - - - - - - - - - - - -";
	print " - - - - - - - - -", newline 2;
	print column 5, "RETURN THIS STUB WITH YOUR PAYMENT", newline 2;
	print column 5, "Invoice No.:  83-0", job_no, column 35, "Total Amount: ";
	print sum of total picture "$FFF9V.99" width 7 right, newline;
	print column 25, "_______________", newline;
	print column 8, "AMOUNT ENCLOSED", column 25, "|$            |"; 
	print newline, column 25, "---------------", newline 2;
	print column 5, "Customer number: ", customer_no, column 35, "Date: ";
	print "TODAY", newline;
	newpage;
end;  

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




    Joe's Auto Repairs                  FOR THE BEST IN AUTO SERVICE
    1757 El Camino Real                        (415) 957-8203
    Bayville, CA 92304

                             INVOICE
                                       Invoice No.:  83-0349
                                       Invoice Date: TODAY

    Customer:  Mr. B. Wilson
               14 valley View Drive,
               Bayville, CA 92308

    ____________________________________________________________________
    |       |                                              |           |
    | Date  | Job Description    Mechanic  Hours Rate      |   Total   |
    |-------|----------------------------------------------|-----------|
    |       |                                              |           |
    | 02/28 | Bent Rear Fender      4       1.0  $30.00/hr |    $30.00 |
    |       |                                              |           |
    |-------|----------------------------------------------|-----------|
    |       |       TOTAL FOR THIS INVOICE                 |    $30.00 |
    |_______|______________________________________________|___________|


    Invoice due on receipt.
    Please make check payable to:  Joe's Auto Repairs












     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    RETURN THIS STUB WITH YOUR PAYMENT

    Invoice No.:  83-0349         Total Amount:  $30.00
                        _______________
       AMOUNT ENCLOSED  |$            |
                        ---------------

    Customer number: 4            Date: TODAY








         FOR THE BEST IN PARTS AND SERVICE -- JOE'S AUTO REPAIRS

              1757 El Camino Real, Bayville, CA 92304
                          (415) 957-8203






    Joe's Auto Repairs                  FOR THE BEST IN AUTO SERVICE
    1757 El Camino Real                        (415) 957-8203
    Bayville, CA 92304

                             INVOICE
                                       Invoice No.:  83-0352
                                       Invoice Date: TODAY

    Customer:  Mrs. H. Watson
               82 Oak St.,
               Bayville, CA 92308

    ____________________________________________________________________
    |       |                                              |           |
    | Date  | Job Description    Mechanic  Hours Rate      |   Total   |
    |-------|----------------------------------------------|-----------|
    |       |                                              |           |
    | 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 |
    |_______|______________________________________________|___________|


    Invoice due on receipt.
    Please make check payable to:  Joe's Auto Repairs










     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    RETURN THIS STUB WITH YOUR PAYMENT

    Invoice No.:  83-0352         Total Amount:  $97.50
                        _______________
       AMOUNT ENCLOSED  |$            |
                        ---------------

    Customer number: 6            Date: TODAY








         FOR THE BEST IN PARTS AND SERVICE -- JOE'S AUTO REPAIRS

              1757 El Camino Real, Bayville, CA 92304
                          (415) 957-8203






    Joe's Auto Repairs                  FOR THE BEST IN AUTO SERVICE
    1757 El Camino Real                        (415) 957-8203
    Bayville, CA 92304

                             INVOICE
                                       Invoice No.:  83-0381
                                       Invoice Date: TODAY

    Customer:  Mrs. B. Hooper
               32 Ridge Rd.,
               Bayville, CA 92308

    ____________________________________________________________________
    |       |                                              |           |
    | Date  | Job Description    Mechanic  Hours Rate      |   Total   |
    |-------|----------------------------------------------|-----------|
    |       |                                              |           |
    | 03/01 | Sparks & tune         2       2.0  $30.00/hr |    $60.00 |
    |       |                                              |           |
    |-------|----------------------------------------------|-----------|
    |       |       TOTAL FOR THIS INVOICE                 |    $60.00 |
    |_______|______________________________________________|___________|


    Invoice due on receipt.
    Please make check payable to:  Joe's Auto Repairs












     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    RETURN THIS STUB WITH YOUR PAYMENT

    Invoice No.:  83-0381         Total Amount:  $60.00
                        _______________
       AMOUNT ENCLOSED  |$            |
                        ---------------

    Customer number: 2            Date: TODAY








         FOR THE BEST IN PARTS AND SERVICE -- JOE'S AUTO REPAIRS

              1757 El Camino Real, Bayville, CA 92304
                          (415) 957-8203






    Joe's Auto Repairs                  FOR THE BEST IN AUTO SERVICE
    1757 El Camino Real                        (415) 957-8203
    Bayville, CA 92304

                             INVOICE
                                       Invoice No.:  83-0387
                                       Invoice Date: TODAY

    Customer:  Miss C. Marshall
               12  Ridge Way,
               Gull Point, CA 92309

    ____________________________________________________________________
    |       |                                              |           |
    | Date  | Job Description    Mechanic  Hours Rate      |   Total   |
    |-------|----------------------------------------------|-----------|
    |       |                                              |           |
    | 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 |
    |_______|______________________________________________|___________|


    Invoice due on receipt.
    Please make check payable to:  Joe's Auto Repairs










     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    RETURN THIS STUB WITH YOUR PAYMENT

    Invoice No.:  83-0387         Total Amount: $150.00
                        _______________
       AMOUNT ENCLOSED  |$            |
                        ---------------

    Customer number: 5            Date: TODAY








         FOR THE BEST IN PARTS AND SERVICE -- JOE'S AUTO REPAIRS

              1757 El Camino Real, Bayville, CA 92304
                          (415) 957-8203


+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 644 stdout
cat > tag <<'+-+-+-+-+-END-OF-FILE-+-+-+-+-+'
A complex report using one level of grouping; produces invoices.
+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 644 tag
