OPEN DATABASE "db";

SET SYNTAX = "1";

SET DATE = "%d.%m.%y";

FIELD lineitems.delivdate DISPLAY AS DATE("%d%m%y");
FIELD orderno    DISPLAY AS (10);
FIELD qty        DISPLAY AS DOUBLE(6, 0);
FIELD price      DISPLAY AS MONEY(8, 2);

FIELD status = orderstat
               VALUES ARE ( 0 = "OPEN",
                            5 = "IN PROCESSING",
                            6 = "RELEASED TO AB",
                            7 = "AB PRINTED",
                            8 = "RELEASED TO LS",
                            9 = "RELEASED TO RG",
                           10 = "INVOICE PRINTED",
                           12 = "ACCOUNTING NOTIF.",
                           13 = "TRANSACTION COMPL.")
               DISPLAY AS LEFT(18);

FIELD icnt = IF (itemcount= "1", 10,
                    IF (itemcount= "2", 100,
                       IF (itemcount= "3", 1000, 1)))
                  DISPLAY AS INT(4);

FIELD amount = (qty * price / icnt)
                DISPLAY AS MONEY(10, 2);

CREATE VIEW temp AS SELECT *
   FROM customers, orders, lineitems, parts
   WHERE customers.custno = orders.custno
     AND orders.orderid = lineitems.orderid
     AND lineitems.itemno = parts.partno;

REPORT
   SELECT
      custno, matchcode, name1, name2,
      delivdate, orderno, ordertype, status,
      itemno, descripa, descripb,
      qty, price, icnt, amount
   FROM temp
   WHERE ordertype = "VK"
   ORDER BY 1, 5, 6
CALCULATE
   SUM(15) BREAK ON (1) PAGE,
   SUM(15) BREAK ON REPORT
USING "man34.frm";
