Files
MBS/TEST/MultipleDialogs/MultiMasterDetail/OrderInput.4gl
T

187 lines
5.8 KiB
Plaintext

# Property of Four Js*
# (c) Copyright Four Js 1995, 2019. All Rights Reserved.
# * Trademark of Four Js Development Tools Europe Ltd
# in the United States and elsewhere
#
# Four Js and its suppliers do not warrant or guarantee that these
# samples are accurate and suitable for your purposes. Their inclusion is
# purely for information purposes only.
IMPORT FGL MsgBox
GLOBALS "Globals.4gl"
DEFINE items DYNAMIC ARRAY OF RECORD
item_line INTEGER,
item_name VARCHAR(50),
item_quant DECIMAL(8,2),
item_price MONEY(10,2),
item_total MONEY(15,2),
item_id INTEGER
END RECORD
CONSTANT mytitle = "Orders"
FUNCTION ord_input(mode, cust_id, cust_name, ord_id)
DEFINE mode CHAR(1)
DEFINE cust_id INTEGER
DEFINE cust_name VARCHAR(50)
DEFINE ord_id INTEGER
DEFINE i, id, s,r INTEGER
DEFINE name STRING
DEFINE price DECIMAL(10,2)
DEFINE touched,reorder INT
OPEN WINDOW w_ord WITH FORM "Orders"
CALL items.clear()
IF mode == 'M' THEN
-- Simulate database fetch
LET ordrec.ord_id = ord_id
LET ordrec.ord_daddr = "5, Market Street"
LET ordrec.ord_crea = TODAY - ord_id
LET ordrec.ord_deliv = ordrec.ord_crea + 3
LET ordrec.ord_valid = "n"
-- Some item lines...
LET i=0
LET items[i:=i+1].item_line = i
LET items[1].item_id = 2
LET items[i].item_name = "Oranges (1Kg)"
LET items[i].item_quant = 2
LET items[i].item_price = 4.65
LET items[i].item_total = items[i].item_quant * items[i].item_price
LET items[i:=i+1].item_line = i
LET items[1].item_id = 1
LET items[i].item_name = "Apples (1Kg)"
LET items[i].item_quant = 3
LET items[i].item_price = 3.45
LET items[i].item_total = items[i].item_quant * items[i].item_price
LET ordrec.ord_amount = 0
FOR i=1 TO items.getLength()
LET ordrec.ord_amount = ordrec.ord_amount + items[i].item_total
END FOR
END IF
DIALOG ATTRIBUTES(FIELD ORDER FORM, UNBUFFERED)
INPUT BY NAME ordrec.* ATTRIBUTE(WITHOUT DEFAULTS=(mode=='M'))
END INPUT
INPUT ARRAY items FROM itemlist.* ATTRIBUTE(WITHOUT DEFAULTS)
BEFORE INSERT
CALL orditem_reorder(DIALOG)
AFTER INSERT
LET reorder=1
AFTER DELETE
LET reorder=1
AFTER ROW
IF FIELD_TOUCHED(itemlist.*) THEN
LET touched=TRUE
END IF
IF reorder THEN
CALL orditem_reorder(DIALOG)
LET reorder=0
END IF
ON CHANGE item_quant
CALL orditem_total(DIALOG, arr_curr())
ON ACTION zoom_item
LET r=DIALOG.getCurrentRow("itemlist")
CALL select_item(DIALOG.getFieldBuffer("item_name")) RETURNING s, id, name, price
IF s==0 THEN
LET items[r].item_id = id
LET items[r].item_name = name
LET items[r].item_price = price
CALL orditem_total(DIALOG, r)
CALL DIALOG.setFieldTouched("item_name",TRUE)
END IF
END INPUT
BEFORE DIALOG
DISPLAY BY NAME cust_id, cust_name
--init some items in the new record after the defaults have been filled in
IF mode='A' THEN
LET ordrec.ord_deliv = TODAY+1
END IF
ON ACTION accept
ACCEPT DIALOG
ON ACTION cancel
IF touched OR FIELD_TOUCHED(ordrec.*) OR
FIELD_TOUCHED(itemlist.*) THEN
IF NOT mbox_yn(mytitle,"Close window without saving input?","question") THEN
CONTINUE DIALOG
END IF
END IF
EXIT DIALOG
AFTER DIALOG
-- Save data in database.
DISPLAY "save data"
END DIALOG
CLOSE WINDOW w_ord
END FUNCTION
FUNCTION orditem_reorder(d)
DEFINE d ui.Dialog
DEFINE i INTEGER
FOR i=1 TO d.getArrayLength("itemlist")
LET items[i].item_line = i
END FOR
END FUNCTION
FUNCTION orditem_total(d, r)
DEFINE d ui.Dialog
DEFINE r, i INTEGER
LET items[r].item_total = items[r].item_quant * items[r].item_price
LET ordrec.ord_amount = 0
FOR i=1 TO d.getArrayLength("itemlist")
LET ordrec.ord_amount = ordrec.ord_amount + items[i].item_total
END FOR
END FUNCTION
FUNCTION select_item(filter)
DEFINE filter STRING
DEFINE i INTEGER
DEFINE itemarr DYNAMIC ARRAY OF RECORD
item_id INTEGER,
item_name VARCHAR(50),
item_price MONEY(10,2)
END RECORD
OPEN WINDOW w_item WITH FORM "ItemList"
LET i = 0
LET itemarr[i:=i+1].item_id = i LET itemarr[i].item_name = "Apples (1Kg)" LET itemarr[i].item_price = 4.25
LET itemarr[i:=i+1].item_id = i LET itemarr[i].item_name = "Oranges (1Kg)" LET itemarr[i].item_price = 5.35
LET itemarr[i:=i+1].item_id = i LET itemarr[i].item_name = "Lemons (1Kg)" LET itemarr[i].item_price = 4.95
LET itemarr[i:=i+1].item_id = i LET itemarr[i].item_name = "Melons (unit)" LET itemarr[i].item_price = 1.55
LET itemarr[i:=i+1].item_id = i LET itemarr[i].item_name = "Peanuts (1Kg)" LET itemarr[i].item_price = 2.25
DISPLAY ARRAY itemarr TO sr.*
AFTER DISPLAY
IF NOT int_flag THEN
LET i = arr_curr()
ELSE
LET int_flag = FALSE
LET i = -1
END IF
END DISPLAY
CLOSE WINDOW w_item
IF i > 0 THEN
RETURN 0, itemarr[i].item_id, itemarr[i].item_name, itemarr[i].item_price
ELSE
RETURN -1, NULL, NULL, NULL
END IF
END FUNCTION