|
Home Up OE Scripts Net Zero?
| |
 | How to use these scripts:
These scripts can't just be copied onto your notepad
and pasted into their objects' events. One objective of these
tutorials is to publish scripts that require some consideration as
they are grafted into your application. If you approach this
methodically you can learn by quick success rather than repeated
failures.
Before you touch the keyboard make sure you've got handy:
 | Your plan, which shows all the datawindows
& other objects referred to by the scripts
|
 | A table definition report for each table
referenced in the scripts by SQL statements
|
 | A printout of the definition for each DataWindow
referenced in one of the datawindow controls' methods:
GetItemNumber, GetItemString, or SetItem
|
 | A printout of the scripts below
|
Make sure that the object's referenced in the
scripts correspond exactly to the names of the objects in your
Windows.
Go through the script and find any reference to your
tables or columns -- adjust the script so that it refers to _your_
database and not the one on the desk where the scripts were made.
Wherever the script refers to a DataWindow's column
object via the DataWindow Control check the DataWindow's definition
and make sure that the script has the correct spelling for the column
object that is displayed.
As each script is copied into the appropriate
event (which may not be the default for the object) right click
on the script and choose Compile from the popup menu. Since you
can't close the object without having all its scripts compile its a
good idea to check each before you move on.
|
|
 | Add these to the Global Variables for your application: integer CurrentOrderId, CurrentEntityId, CurrentInOut
|
 | At open of w_orderentry //Connect
with
the SQLCA database engine
CONNECT USING SQLCA;
IF SQLCA.SQLCODE <> 0 and SQLCA.SQLCODE <> -1 THEN
MessageBox("SQLCODE ->" + STRING(SQLCA.SQLCODE) +
"<-",SQLCA.SQLERRTEXT)
HALT
END IF
//Set the Transaction Object for 'The Order' datawindow control
//and 'An Order' that gets required fields at the top
dwc_the_order.SetTransObject(SQLCA)
dwc_anorder.SetTransObject(SQLCA)
//Get dwc_anorder ready for the user to enter data
dwc_anorder.InsertRow(0)
dwc_anorder.SetItem(1,"acctg_date",Today())
dwc_anorder.SetFocus()
//Get helpful text to the user
st_helper.Text = "Fill out the Order's header information at the top of the form.
Click 'Enter Details' or press [Enter] when you're done."
|
 |
At Close of w_orderentry
DISCONNECT USING SQLCA;
|
 | At clicked of cb_go2details //Set
instance variable CurrentInOut, Debit/Credit, based on the order's type
//for easy access in later scripts
if dwc_anorder.GetItemString(1,"type") = "I" then
CurrentInOut = -1
else
CurrentInOut = 1
end if
//Set invisible field to this value for easy Update to the database
dwc_anorder.SetItem(1,"in_out",CurrentInOut)
//Try updating the database and relate if any fields are missing
dwc_anorder.Update()
if SQLCA.SQLCode <> 0 then
messagebox("Update Error","Please complete all the
fields in the Order's header before choosing 'Enter Details'")
dwc_anorder.SetFocus()
return
end if
//If we got to here then set the other instance variables to use in other scripts
CurrentOrderId = dwc_anorder.GetItemNumber(1,"order_id")
CurrentEntityId = dwc_anorder.GetItemNumber(1,"entity_id")
//The user if done with the Order's header so disable it and the
//'enter details' button
cb_go2details.Enabled = false
dwc_anorder.Enabled = false
//Enable controls needed next
dwc_adetail.Enabled = true
cb_detail_ok.Enabled = true
//Set transaction object and setup dwc_adetail for entering details
dwc_adetail.SetTransObject(SQLCA)
dwc_adetail.InsertRow(0)
dwc_adetail.SetFocus()
//Show helpful text
st_helper.Text = "Enter each Good or Service, the quantity, and amount for each.
Choose 'Detail OK' to add it to the order. Choose 'Tender' (alt-T) when all details have
been added to the order."
|
 | At itemchanged of dwc_adetail real Cost,
Price, EstabAmount
integer GSId
string FieldName
//Get the field that just changed into String form from the DataWindow Object
//for easy use in next logic
FieldName = string(dwo.name)
//gs_id is the only field we're interested in for the time being
if FieldName = "gs_id" then
//Construct the SQL to get back Cost & Price so non-zero amount
will default
//for the user
GSId = integer(data)
SELECT "cost", "price"
INTO :Cost, :Price
FROM "goods_and_services"
WHERE "id" = :GSId;
if SQLCA.SQLCode <> 0 then
messagebox("SQLError",string(SQLCA.SQLCode) + " " + SQLCA.SQLErrText)
return
end if
//Choose Price or Cost depending on whether the order brings
goods/services in or out
//of the enterprise
if CurrentInOut = -1 then
EstabAmount = Price
else
EstabAmount = Cost
end if
dwc_adetail.SetItem(1,"each",EstabAmount)
end if
|
 | At clicked of cb_detail_ok integer GSId,
Qty, ExchangeLDet, LDetCost, LDetPrice
real Each, Cost, Price, ExchangeAmount
//Load data from the DWC into local variables of easy use in next logic
GSId = dwc_adetail.GetItemNumber(1,"gs_id")
Qty = dwc_adetail.GetItemNumber(1,"qty")
Each = dwc_adetail.GetItemNumber(1,"each")
//If a field has been left null deliver error message and set focus back
//on the DWC
if isnull(GSId) or isnull(Qty) or isnull(Each) then
messagebox("Detail not OK","Please fill in all three
fields before choosing 'Detail OK.'")
dwc_adetail.SetFocus()
return
end if
//Get Cost/Price and ledger detail code for them. Later step will override a user-entered
//amount if zero is not in the database
SELECT "cost", "ldetcost", "price", "ldetprice"
INTO :Cost, :LDetCost, :Price, :LDetPrice
FROM "goods_and_services"
WHERE "id" = :GSId;
if SQLCA.SQLCode <> 0 then
messagebox("SQL Error",SQLCA.SQLErrText)
halt
end if
//Make Qty into Debit/Credit & choose appropriate amount for the qty
//exchanged on this detail
Qty = Qty * CurrentInOut
if CurrentInOut = -1 then
ExchangeAmount = Price
ExchangeLDet = LDetPrice
else
ExchangeLDet = LDetCost
ExchangeAmount = Cost
end if
if ExchangeAmount = 0 then ExchangeAmount = Each
//Update the database with the new detail
INSERT INTO "detail"
("order_id", "gs_id", "qty", "each",
"ldet_id", "deliver_to")
VALUES
(:CurrentOrderId, :GSId, :Qty, :ExchangeAmount, :ExchangeLDet, :CurrentEntityId);
if SQLCA.SQLCode <> 0 then
messagebox("Error at INSERT",SQLCA.SQLErrText)
halt
else
//Commit each detail line -- will help for real-time update of
//QOH, etc for 'real' multi-user application
COMMIT USING SQLCA;
//Setup the retrieval arugment for dwc_the_order & reset it so that
it
//will show all details
dwc_the_order.Retrieve(CurrentOrderId)
//Enable the Tender button since there has been at least one non-tender
//detail posted
cb_tender.Enabled = true
//Reset dwc_adetail to clear last data from the control & make it
ready
//for the next
dwc_adetail.Reset()
dwc_adetail.InsertRow(0)
dwc_adetail.SetFocus()
end if
//Give helpful text
st_helper.Text = "Enter more details as needed. Choose 'Tender' (alt-T) when you're
done..."
|
 | At clicked of cb_tender real OrderTotal
integer Ready, TenderQty, TenderGSId, TenderLDetId
//Select all details with the CurrentOrderId, sum their extensions for
//use to calculate Tender due for the order
SELECT SUM("qty" * "each")
INTO :OrderTotal
FROM "detail"
WHERE "order_id" = :CurrentOrderId;
//See if the user is really ready to Tender and be done with this order
Ready = messagebox("Tender","If you answer Yes " + string(-1 *
OrderTotal,"$#0.00") + " will be tendered. Are you ready to tender this
order?", Question!, YesNo!, 2)
if Ready = 2 then
//User answered No so setup and return for another detail
dwc_adetail.Reset()
dwc_adetail.InsertRow(0)
dwc_adetail.SetFocus()
return
else
//Yes user is ready, so setup appropriate tender for this enterprise
//Invoice(-1) gets Receivables, PO(1) gets Payables
TenderQty = -1 * CurrentInOut
If CurrentInOut = -1 then
TenderGSId = 6
TenderLDetId = 1010
else
TenderGsId = 9
TenderLDetId = 2000
end if
//Make OrderTotal a positive
amount, TenderQty show CrDr
OrderTotal = abs(OrderTotal)
//insert the tender detail into the database
INSERT INTO "detail"
("order_id", "gs_id",
"qty", "each", "ldet_id", "deliver_to")
VALUES
(:CurrentOrderId, :TenderGSId, :TenderQty,
:OrderTotal, :TenderLDetId, :CurrentEntityId)
USING SQLCA;
if SQLCA.SQLCode = 0 then
COMMIT USING SQLCA;
close(parent)
else
messagebox("Insert failed",
SQLCA.SQLErrText)
halt
end if
end if
|
|