Commit inicial: fuentes MBS ERP (Genero 6) + .gitignore + docs/SETUP_PC_MBS.md

This commit is contained in:
2026-08-18 20:59:52 -04:00
commit 454973e269
5978 changed files with 2664094 additions and 0 deletions
+138
View File
@@ -0,0 +1,138 @@
#
# FOURJS_START_COPYRIGHT(U,2011)
# Property of Four Js*
# (c) Copyright Four Js 2011, 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.
# FOURJS_END_COPYRIGHT
#
IMPORT XML
IMPORT COM
GLOBALS "Types.4gl"
DEFINE ret INTEGER
DEFINE port STRING
DEFINE now DATETIME HOUR TO FRACTION
&define display_status(status) \
IF NOT screen THEN \
DISPLAY status \
ELSE \
DISPLAY status TO MSG \
MENU ON idle 1 EXIT MENU ON ACTION close EXIT PROGRAM END MENU \
END IF
MAIN
DEFER INTERRUPT
LET screen = false
#
# Check arguments
#
IF num_args() = 2 and arg_val(1) = "-W" THEN
LET serverURL = arg_val(2)
CALL CreateShoppingCartService(true)
EXIT PROGRAM
ELSE
IF num_args() = 2 and arg_val(1) = "-S" THEN
LET screen = true
CALL fgl_setenv("FGLAPPSERVER",arg_val(2))
CLOSE WINDOW SCREEN
OPEN WINDOW w WITH FORM "Server" ATTRIBUTES(TEXT = "ShoppingCart service", STYLE="naked")
display_status("ShoppingCart service startup")
ELSE
IF num_args() <> 0 THEN
CALL exitHelp()
EXIT PROGRAM
END IF
END IF
END IF
display_status("Initializing Shopping Cart service...")
CALL InitGoods()
CALL CreateShoppingCartService(false)
display_status("... done")
display_status("Starting Shopping Cart service")
CALL com.WebServiceEngine.Start()
display_status("... Shopping Cart service started")
IF screen THEN
MENU
ON IDLE 1
LET now = CURRENT
DISPLAY now||": Waiting..." TO MSG
LET ret = com.WebServiceEngine.ProcessServices(1)
CASE ret
WHEN 0
DISPLAY "Request processed." TO msg
WHEN -1
DISPLAY "No request..." TO msg
WHEN -2
DISPLAY "Disconnected from application server." TO msg
EXIT PROGRAM # The Application server has closed the connection
WHEN -3
DISPLAY "Client Connection lost." TO msg
WHEN -4
DISPLAY "Server interrupted with Ctrl-C." TO msg
WHEN -9
DISPLAY "Unsupported operation." TO msg
WHEN -10
DISPLAY "Internal server error." TO msg
OTHERWISE
DISPLAY "Unexpected server error " || status || "." TO msg
EXIT MENU
END CASE
ON ACTION close
EXIT PROGRAM
END MENU
ELSE
WHILE TRUE
LET now = CURRENT
display_status(now||": Waiting...")
LET ret = com.WebServiceEngine.ProcessServices(-1)
CASE ret
WHEN 0
display_status("... Request processed.")
WHEN -2
DISPLAY "Disconnected from application server."
EXIT PROGRAM # The Application server has closed the connection
WHEN -3
DISPLAY "Client Connection lost."
WHEN -4
DISPLAY "Server interrupted with Ctrl-C."
WHEN -9
DISPLAY "Unsupported operation."
WHEN -10
DISPLAY "Internal server error."
OTHERWISE
DISPLAY "Unexpected server error " || status || "."
EXIT WHILE
END CASE
IF int_flag<>0 THEN
LET int_flag=0
EXIT WHILE
END IF
END WHILE
DISPLAY "Shopping Cart service stopped"
END IF
END MAIN
FUNCTION exitHelp()
DISPLAY "Usage: "
DISPLAY " ", arg_val(0)
DISPLAY " Start the server on port defined by FGLAPPSERVER"
DISPLAY " ", arg_val(0), " -W serverurl"
DISPLAY " Generate the WSDL file for the given url"
DISPLAY " ", arg_val(0), " -S port"
DISPLAY " Start service in graphical mode and on given port"
EXIT PROGRAM
END FUNCTION
@@ -0,0 +1,36 @@
--
-- FOURJS_START_COPYRIGHT(U,2011)
-- Property of Four Js*
-- (c) Copyright Four Js 2011, 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.
-- FOURJS_END_COPYRIGHT
--
SCHEMA FORMONLY
LAYOUT
GROUP ( TEXT = "Status")
GRID
{
[msg ]
[ ]
[ ]
}
END
END
END -- layout
ATTRIBUTES
TEXTEDIT msg=formonly.msg, NOENTRY, STRETCH=X,SCROLLBARS=NONE,TITLE="Message",COLOR=RED;
END
@@ -0,0 +1,310 @@
#
# FOURJS_START_COPYRIGHT(U,2011)
# Property of Four Js*
# (c) Copyright Four Js 2011, 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.
# FOURJS_END_COPYRIGHT
#
IMPORT XML
IMPORT COM
IMPORT SECURITY
GLOBALS "Types.4gl"
PRIVATE DEFINE GoodsInStock DYNAMIC ARRAY OF Good
PRIVATE DEFINE Sessions DYNAMIC ARRAY OF ShoppingCart
#
# Initialize the list of goods
#
#
FUNCTION InitGoods()
CALL GoodsInStock.appendElement()
LET GoodsInStock[1].serial = 101
LET GoodsInStock[1].desc = "Air conditioners"
LET GoodsInStock[1].UnitPrice = 1000.0
CALL GoodsInStock.appendElement()
LET GoodsInStock[2].serial = 102
LET GoodsInStock[2].desc = "Flower decorations"
LET GoodsInStock[2].UnitPrice = 4.99
CALL GoodsInStock.appendElement()
LET GoodsInStock[3].serial = 103
LET GoodsInStock[3].desc = "Gloves"
LET GoodsInStock[3].UnitPrice = 14.99
CALL GoodsInStock.appendElement()
LET GoodsInStock[4].SERIAL = 104
LET GoodsInStock[4].desc = "Guitar"
LET GoodsInStock[4].UnitPrice = 355.59
CALL GoodsInStock.appendElement()
LET GoodsInStock[5].SERIAL = 105
LET GoodsInStock[5].desc = "Hammer"
LET GoodsInStock[5].UnitPrice = 12.99
CALL GoodsInStock.appendElement()
LET GoodsInStock[6].SERIAL = 106
LET GoodsInStock[6].desc = "Milk"
LET GoodsInStock[6].UnitPrice = 2.99
CALL GoodsInStock.appendElement()
LET GoodsInStock[7].SERIAL = 107
LET GoodsInStock[7].desc = "Mirror"
LET GoodsInStock[7].UnitPrice = 29.99
CALL GoodsInStock.appendElement()
LET GoodsInStock[8].SERIAL = 108
LET GoodsInStock[8].desc = "Mug"
LET GoodsInStock[8].UnitPrice = 7.99
CALL GoodsInStock.appendElement()
LET GoodsInStock[9].SERIAL = 109
LET GoodsInStock[9].desc = "Ball"
LET GoodsInStock[9].UnitPrice = 3.99
CALL GoodsInStock.appendElement()
LET GoodsInStock[10].SERIAL = 110
LET GoodsInStock[10].desc = "Pencils"
LET GoodsInStock[10].UnitPrice = 11.99
CALL GoodsInStock.appendElement()
LET GoodsInStock[11].SERIAL = 111
LET GoodsInStock[11].desc = "Watch"
LET GoodsInStock[11].UnitPrice = 109.49
CALL GoodsInStock.appendElement()
LET GoodsInStock[12].SERIAL = 112
LET GoodsInStock[12].desc = "Postcard"
LET GoodsInStock[12].UnitPrice = 0.79
CALL GoodsInStock.appendElement()
LET GoodsInStock[13].SERIAL = 113
LET GoodsInStock[13].desc = "School bag"
LET GoodsInStock[13].UnitPrice = 24.99
END FUNCTION
#
# Returns the list of goods
#
FUNCTION GetGoodsList()
RETURN GoodsInStock
END FUNCTION
#
# Creates a new shopping cart
# and returns an identifier
#
FUNCTION MgrGetSessionId(login)
DEFINE login STRING
DEFINE ind INTEGER
FOR ind = 1 TO Sessions.getLength()
IF Sessions[ind].cust.login == login THEN
RETURN Sessions[ind].cust.id
END IF
END FOR
RETURN MgrCreateNewSession(login)
END FUNCTION
#
# Creates a new session
# and returns the identifier
#
PRIVATE FUNCTION MgrCreateNewSession(login)
DEFINE login STRING
DEFINE ind STRING
CALL Sessions.appendElement()
LET ind = Sessions.getLength()
LET Sessions[ind].cust.login = login
LET Sessions[ind].cust.id = security.RandomGenerator.CreateUUIDString()
LET Sessions[ind].cust.DATE = CURRENT
RETURN Sessions[ind].cust.id
END FUNCTION
#
# Scans all sessions and remove them if expiration date is reached
# Session lifetime is 10 minutes
#
FUNCTION MgrRemoveExpiredSessions()
DEFINE ind INTEGER
DEFINE id STRING
FOR ind = 1 TO Sessions.getLength()
IF CURRENT > Sessions[ind].cust.DATE + INTERVAL (10) MINUTE TO MINUTE THEN
LET id = Sessions[ind].cust.id
CALL Sessions.deleteElement(ind)
DISPLAY " Sessions "||id||" has expired"
END IF
END FOR
END FUNCTION
#
# Adds given good to given session
# return TRUE if added, FALSE otherwise
#
FUNCTION MgrAddGoodToCart(id,serial)
DEFINE id STRING
DEFINE SERIAL INTEGER
DEFINE ind INTEGER
FOR ind = 1 TO Sessions.getLength()
IF Sessions[ind].cust.id = id THEN
CALL AddGoods(Sessions[ind].goods,serial)
RETURN TRUE
END IF
END FOR
RETURN FALSE
END FUNCTION
PRIVATE FUNCTION AddGoods(goods,serial)
DEFINE goods DYNAMIC ARRAY OF GoodValue
DEFINE SERIAL INTEGER
DEFINE ind INTEGER
FOR ind = 1 TO goods.getLength()
IF goods[ind].SERIAL = SERIAL THEN
LET goods[ind].Qte = goods[ind].Qte + 1
RETURN
END IF
END FOR
# New Good
CALL goods.appendElement()
LET ind = goods.getLength()
LET goods[ind].SERIAL = SERIAL
LET goods[ind].DESC = RetrieveGoodDescription(serial)
LET goods[ind].Qte = 1
END FUNCTION
#
# Removes given good from given session
# return TRUE if removed, FALSE otherwise
#
FUNCTION MgrRemoveGoodFromCart(id,serial)
DEFINE id STRING
DEFINE SERIAL INTEGER
DEFINE ind INTEGER
FOR ind = 1 TO Sessions.getLength()
IF Sessions[ind].cust.id = id THEN
CALL RemoveGoods(Sessions[ind].goods,serial)
RETURN TRUE
END IF
END FOR
RETURN FALSE
END FUNCTION
PRIVATE FUNCTION RemoveGoods(goods,serial)
DEFINE goods DYNAMIC ARRAY OF GoodValue
DEFINE SERIAL INTEGER
DEFINE ind INTEGER
FOR ind = 1 TO goods.getLength()
IF goods[ind].SERIAL = SERIAL THEN
LET goods[ind].Qte = goods[ind].Qte - 1
IF goods[ind].Qte == 0 THEN
CALL goods.deleteElement(ind)
END IF
EXIT FOR
END IF
END FOR
END FUNCTION
#
# Returns the list of goods in shopping cart
#
FUNCTION MgrGetGoodsInCart(id)
DEFINE id STRING
DEFINE ind INTEGER
FOR ind = 1 TO Sessions.getLength()
IF Sessions[ind].cust.id = id THEN
RETURN TRUE,Sessions[ind].goods
END IF
END FOR
RETURN FALSE,NULL
END FUNCTION
#
# Removes the session of given id
# Note: session is closed
#
FUNCTION MgrDiscardShoppingCart(id)
DEFINE id STRING
DEFINE ind INTEGER
FOR ind = 1 TO Sessions.getLength()
IF Sessions[ind].cust.id = id THEN
CALL Sessions[ind].goods.clear()
RETURN
END IF
END FOR
END FUNCTION
#
# Order the cart and returns the
# total price
# Note: session is closed
#
FUNCTION MgrOrderCart(id)
DEFINE id STRING
DEFINE ind INTEGER
DEFINE TOTAL FLOAT
FOR ind = 1 TO Sessions.getLength()
IF Sessions[ind].cust.id = id THEN
LET TOTAL = ComputePrice(Sessions[ind].goods)
CALL Sessions.deleteElement(ind)
RETURN TRUE, total
END IF
END FOR
RETURN FALSE,0
END FUNCTION
#
# Returns the UnitPrice of a good
#
PRIVATE FUNCTION RetrieveGoodUnitPrice(serial)
DEFINE SERIAL INTEGER
DEFINE ind INTEGER
FOR ind = 1 TO GoodsInStock.getLength()
IF GoodsInStock[ind].SERIAL = SERIAL THEN
RETURN GoodsInStock[ind].UnitPrice
END IF
END FOR
RETURN 0
END FUNCTION
#
# Returns the Description of a good
#
PRIVATE FUNCTION RetrieveGoodDescription(serial)
DEFINE SERIAL INTEGER
DEFINE ind INTEGER
FOR ind = 1 TO GoodsInStock.getLength()
IF GoodsInStock[ind].SERIAL = SERIAL THEN
RETURN GoodsInStock[ind].DESC
END IF
END FOR
RETURN 0
END FUNCTION
#
# Computes the total price of all goods
#
PRIVATE FUNCTION ComputePrice(goods)
DEFINE goods DYNAMIC ARRAY OF GoodValue
DEFINE ind INTEGER
DEFINE TOTAL FLOAT
DEFINE unit FLOAT
LET TOTAL = 0
FOR ind = 1 TO goods.getLength()
LET unit = RetrieveGoodUnitPrice(goods[ind].SERIAL)
LET TOTAL = TOTAL + unit * goods[ind].Qte
END FOR
RETURN TOTAL
END FUNCTION
File diff suppressed because one or more lines are too long
@@ -0,0 +1,224 @@
#
# FOURJS_START_COPYRIGHT(U,2011)
# Property of Four Js*
# (c) Copyright Four Js 2011, 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.
# FOURJS_END_COPYRIGHT
#
IMPORT XML
IMPORT COM
GLOBALS "Types.4gl"
#
# GetShoppingCart parameters
#
DEFINE getcart_in RECORD
login STRING
END RECORD
DEFINE getcart_out RECORD
list DYNAMIC ARRAY OF Good
END RECORD
#
# AddToCart parameters
#
DEFINE addtocart_in RECORD
SERIAL INTEGER
END RECORD
#
# RemoveFromCart parameters
#
DEFINE removefromcart_in RECORD
SERIAL INTEGER
END RECORD
#
# GetGoodsInCart parameters
#
DEFINE getgoodsincart_out RECORD
goods DYNAMIC ARRAY OF GoodValue
END RECORD
#
# OrderCart parameters
#
DEFINE ordercart_out RECORD
totalPrice FLOAT
END RECORD
#
# The state variable exchanged as HTTP cookie
#
DEFINE state STRING
#
# Fault returned in case of error
#
DEFINE BadSession RECORD ATTRIBUTE (XMLName="BadSessionError")
msg STRING
END RECORD
&define display_status(status) \
IF NOT screen THEN \
DISPLAY status \
ELSE \
DISPLAY status TO MSG \
MENU ON idle 1 EXIT MENU ON ACTION close EXIT PROGRAM END MENU \
END IF
#
# Returns a new shopping with the list of goods
#
FUNCTION CreateShoppingCartService(generateWSDL)
DEFINE generateWSDL boolean
DEFINE serv com.WebService
DEFINE op com.WebOperation
DEFINE ret INTEGER
# Create ShoppingCart service
LET serv = com.WebService.CreateStatefulWebService("ShoppingCart","http://tempuri.org",state)
CALL serv.setFeature("Soap1.2",TRUE)
#
# Create BadSession Fault
#
CALL serv.createFault(BadSession,FALSE)
# Create GetShoppingCart operation
# will initiate a new session
LET op = com.WebOperation.CreateDOCStyle("GetShoppingCart","GetShoppingCart",getcart_in,getcart_out)
CALL op.initiateSession(true)
CALL serv.publishOperation(op,NULL)
# Create AddToCart operations
# requires a session to be initated before
LET op = com.WebOperation.CreateDOCStyle("AddToCart","AddToCart",addtocart_in,NULL)
CALL op.addFault(BadSession,NULL)
CALL serv.publishOperation(op,NULL)
# Create RemoveFromCart operations
LET op = com.WebOperation.CreateDOCStyle("RemoveFromCart","RemoveFromCart",removefromcart_in,NULL)
CALL op.addFault(BadSession,NULL)
CALL serv.publishOperation(op,NULL)
# Create GetGoodsInCart operations
LET op = com.WebOperation.CreateDOCStyle("GetGoodsInCart","GetGoodsInCart",NULL,getgoodsincart_out)
CALL op.addFault(BadSession,NULL)
CALL serv.publishOperation(op,NULL)
# Create DiscardCart operations
LET op = com.WebOperation.CreateDOCStyle("DiscardCart","DiscardCart",NULL,NULL)
CALL op.addFault(BadSession,NULL)
CALL serv.publishOperation(op,NULL)
# Create OrderCart operations
LET op = com.WebOperation.CreateDOCStyle("OrderCart","OrderCart",NULL,ordercart_out)
CALL op.addFault(BadSession,NULL)
CALL serv.publishOperation(op,NULL)
IF generateWSDL THEN
#
# Generate WSDL
#
LET ret = serv.saveWSDL(serverURL)
IF ret=0 THEN
DISPLAY "WSDL saved"
ELSE
DISPLAY "ERROR: Unable to save WSDL"
END IF
ELSE
#
# Register service
#
CALL com.WebServiceEngine.RegisterService(serv)
display_status("ShoppingCart Service registered")
END IF
END FUNCTION
#
# Returns a new shopping cart or a previous one not yet released
#
FUNCTION GetShoppingCart()
DEFINE ind INTEGER
DEFINE tmp DYNAMIC ARRAY OF Good
LET state = MgrGetSessionId(getcart_in.login)
LET tmp = GetGoodsList()
FOR ind = 1 TO tmp.getLength()
CALL getcart_out.list.appendElement()
LET getcart_out.list[ind].* = tmp[ind].*
END FOR
END FUNCTION
#
# Adds given goods to the cart
# throw BadSession if there is no session
#
FUNCTION AddToCart()
IF NOT MgrAddGoodToCart(state,addtocart_in.SERIAL) THEN
LET BadSession.msg = "Cannot add to cart"
CALL com.WebServiceEngine.SetFaultDetail(BadSession)
END IF
END FUNCTION
#
# Removes from cart
#
FUNCTION RemoveFromCart()
IF NOT MgrRemoveGoodFromCart(state,removefromcart_in.SERIAL) THEN
LET BadSession.msg = "Cannot remove from cart"
CALL com.WebServiceEngine.SetFaultDetail(BadSession)
END IF
END FUNCTION
#
# GetGoodsInCart
#
FUNCTION GetGoodsInCart()
DEFINE ok BOOLEAN
DEFINE tmp DYNAMIC ARRAY OF GoodValue
DEFINE ind INTEGER
CALL MgrGetGoodsInCart(state) RETURNING ok, tmp
IF NOT OK THEN
LET BadSession.msg = "Cannot return goods"
CALL com.WebServiceEngine.SetFaultDetail(BadSession)
ELSE
FOR ind =1 TO tmp.getLength()
LET getgoodsincart_out.goods[ind].* = tmp[ind].*
END FOR
END IF
END FUNCTION
#
# Discard cart
# release the cart
#
FUNCTION DiscardCart()
CALL MgrDiscardShoppingCart(state)
END FUNCTION
#
# Order cart
# release the cart
#
FUNCTION OrderCart()
DEFINE ok BOOLEAN
CALL MgrOrderCart(state) RETURNING ok,ordercart_out.totalPrice
IF NOT ok THEN
LET BadSession.msg = "Cannot order cart"
CALL com.WebServiceEngine.SetFaultDetail(BadSession)
END IF
END FUNCTION
+41
View File
@@ -0,0 +1,41 @@
#
# FOURJS_START_COPYRIGHT(U,2011)
# Property of Four Js*
# (c) Copyright Four Js 2011, 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.
# FOURJS_END_COPYRIGHT
#
GLOBALS
TYPE Good RECORD
SERIAL INTEGER, # Goods serial number
DESC STRING, # Goods description
UnitPrice FLOAT # Goods unit price
END RECORD
TYPE Customer RECORD
login STRING, # Customer login
id STRING, # Customer identify
DATE DATETIME HOUR TO MINUTE # Customer creation date
END RECORD
TYPE GoodValue RECORD
SERIAL INTEGER,
DESC STRING,
Qte INTEGER
END RECORD
TYPE ShoppingCart RECORD
cust Customer,
goods DYNAMIC ARRAY OF GoodValue
END RECORD
DEFINE serverURL STRING
DEFINE screen BOOLEAN
END GLOBALS
+19
View File
@@ -0,0 +1,19 @@
@rem
@rem FOURJS_START_COPYRIGHT(U,2011)
@rem Property of Four Js*
@rem (c) Copyright Four Js 2011, 2019. All Rights Reserved.
@rem * Trademark of Four Js Development Tools Europe Ltd
@rem in the United States and elsewhere
@rem
@rem Four Js and its suppliers do not warrant or guarantee that these samples
@rem are accurate and suitable for your purposes. Their inclusion is purely for
@rem information purposes only.
@rem FOURJS_END_COPYRIGHT
@rem
fglcomp Server.4gl
fglcomp SessionManagement.4gl
fglcomp ShoppingCartService.4gl
fglcomp Types.4gl
fglform Server.per
call fgllink -o ShoppingCartServer.42r ShoppingCartService.42m Server.42m SessionManagement.42m Types.42m
+15
View File
@@ -0,0 +1,15 @@
@rem
@rem FOURJS_START_COPYRIGHT(U,2011)
@rem Property of Four Js*
@rem (c) Copyright Four Js 2011, 2019. All Rights Reserved.
@rem * Trademark of Four Js Development Tools Europe Ltd
@rem in the United States and elsewhere
@rem
@rem Four Js and its suppliers do not warrant or guarantee that these samples
@rem are accurate and suitable for your purposes. Their inclusion is purely for
@rem information purposes only.
@rem FOURJS_END_COPYRIGHT
@rem
SET FGLAPPSERVER=8090
fglrun ShoppingCartServer.42r