project BLF > class BNumber > method GetNumber
Description
Claim a number from a sequence.
Sequence is increased by one.
If the claimed number is not committed when housekeeping is run, it is released again.
Parameters
iiCompanyId | input | integer | |
iiNumbrYear | input | integer | NumbrYear |
icNumbrType | input | character | NumbrType |
oiNumber | output | integer | the new number for a certain journal |
iiInstanceId | input | integer | |
icClassName | input | character | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
QadFitnesse
program code (program1/bnumber.p)
if iiCompanyId = 0
or iiCompanyId = ?
then assign iiCompanyId = viCompanyId.
if iiCompanyId = 0
or iiCompanyId = ?
or iiNumbrYear = 0
or iiNumbrYear = ?
or icNumbrType = ""
or icNumbrType = ?
then return.
/* ================================================================= */
/* Look for a type 'RELEASED' record (5 attempts) */
/* ================================================================= */
do viRetries = 1 to 5:
oiReturnStatus = 0.
/* ========================================= */
/* Get the first RELEASED number from the db */
/* ========================================= */
<M-51 run GetFirstNumber
(input iiCompanyId (iiCompanyId),
input iiNumbrYear (iiNumbrYear),
input icNumbrType (icNumbrType),
input {&NUMBERSTATUS-RELEASED} (icNumbrStatus),
output vilFirstNumbr (oiNumbr),
output vllFirstNumbrIsActive (olNumbrIsActive),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
/* ======================================================= */
/* Create new numbers-queue when no released one was found */
/* ======================================================= */
if vilFirstNumbr = ?
then do:
if transaction
then do:
/* When a (automatic) transaction is active, create released records in a separate thread */
vhFcComponent = ?.
<M-62 run MainBlock () in XML>
<M-84 run ReadXMLNodeValue
(input search('server.xml') (icXMLFile),
input 'serverConfiguration' (icStartTag),
input 'ENVAPPSERVERURL' (icNodeTag),
output vcURL (ocNodeValue),
output viFcReturnSuper (oiReturnStatus)) in XML>
run gipr_DeleteProcedure in vhFcComponent.
delete procedure vhFcComponent.
if vcURL = ? then vcURL = "".
if vcURL <> ""
then do:
create server vhSvr.
vhSvr:connect ("-URL " + vcURL, "", "", "") no-error.
if not vhSvr:connected() then vcURL = "".
end.
end.
if vcURL = ""
then do:
<M-87 run ApiPrepareReleasedNumbers
(input iiCompanyId (iiCompanyId),
input iiNumbrYear (iiNumbrYear),
input icNumbrType (icNumbrType),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
end.
else do:
run api/bnumber/apipreparereleasednumbers.p on vhSvr
(input "",
input "",
input "",
input viSessionID,
input iiCompanyId,
input iiNumbrYear,
input icNumbrType,
output dataset tFcMessages append,
output viFcReturnSuper).
vhSvr:disconnect().
end.
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
next.
end. /* if vilFirstNumbr = ? */
/* ======================================================= */
/* Chech if the number-sequence is still active */
/* ======================================================= */
if vllFirstNumbrIsActive <> true
then do:
assign oiReturnStatus = -3
vcNumberMsg = trim(substitute(#T-47'This sequence ($1) has been deactivated.':255(310601826)T-47#,string(iiNumbrYear) + '/':U + icNumbrType)).
<M-8 run SetMessage
(input vcNumberMsg (icMessage),
input '':U (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'D':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-125':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
return.
end. /* if vllFirstNumbrIsActive <> true */
/* ==================================================================================================== */
/* Actions on maximal voucher number: */
/* Due to the limitation that a voucher should only be 9 digits long following actions should be taken: */
/* 1. Raise error when returned number would be more than 9 digits (BNumberP:GetNumber) */
/* 2. Raise warning when returned number or manually updated number is higher than 999.000.000 */
/* ==================================================================================================== */
if vilFirstNumbr <> ?
then if vilFirstNumbr > 999999999
then do:
assign oiReturnStatus = -3
vcNumberMsg = trim(substitute(#T-26'Unable to retrieve the next number for this sequence (&1) because the next number (&2) is longer than 9 digits.':255(753545979)T-26#,trim(string(iiNumbrYear)) + '/':U + trim(icNumbrType),string(vilFirstNumbr))).
<M-7 run SetMessage
(input vcNumberMsg (icMessage),
input '':U (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'blf-493831':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
Return.
end. /* if vilFirstNumbr > 999999999 */
else if vilFirstNumbr > 999900000
then do:
assign oiReturnStatus = +1
vcNumberMsg = trim(substitute(#T-68'Warning: the next number (&2) for this sequence (&1) is approaching the maximum of 9 digits.':255(167815287)T-68#,trim(string(iiNumbrYear)) + '/':U + trim(icNumbrType),string(vilFirstNumbr))).
<M-24 run SetMessage
(input vcNumberMsg (icMessage),
input '':U (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'W':U (icType),
input 4 (iiSeverity),
input '' (icRowid),
input 'blf-598416':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
end. /* if vilFirstNumbr > 999900000 */
/* ======================================== */
/* Write the nex number into the db */
/* ======================================== */
assign vcWhere = "for each Numbr where Numbr.Company_ID = ":U + string(iiCompanyId)
+ " and Numbr.NumbrYear = ":U + string(iiNumbrYear)
+ " and Numbr.NumbrType = '":U + icNumbrType
+ "' and Numbr.Numbr = ":U + string(vilFirstNumbr)
+ " and Numbr.NumbrStatus = '":U + {&NUMBERSTATUS-RELEASED} + "'":U.
<M-9 run StartPersistence
(output vhFcComponent (ohPersistence),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
/* Save date and time in UTC */
session:timezone = 0.
<M-11 run WriteDirect
(input 'Numbr':U (icTableName),
input vcWhere (icPrepare),
input 'NumbrStatus,LastModifiedDate,LastModifiedTime,LastModifiedUser':U (icFieldList),
input 'c,t,i,c' (icFieldListDataTypes),
input {&NUMBERSTATUS-CLAIMED} + chr(2) + string(today) + chr(2) + string(time) + chr(2) + vcUserLogin (icAbsolute),
input '' (icIncremental),
input {&TARGETPROCEDURE} (ihClass),
input vcUserLogin (icUserLogin),
output viFcReturnSuper (oiReturnStatus)) in persistence>
session:timezone = viTimeOffset.
if viFcReturnSuper >= 0
then do:
oiNumber = vilFirstNumbr.
<M-18 run StartPersistence
(output vhFcComponent (ohPersistence),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
<M-19 run AddNumber
(input iiInstanceId (iiInstanceId),
input icClassName (icClassName),
input string(iiCompanyId) + ',' + string(iiNumbrYear) + ',' + icNumbrType + ',' + string(oiNumber) (icNumberData)) in persistence>
return.
end. /* if viFcReturnSuper >= 0 */
end. /* do viRetries = 1 to 5: */
/* retries exceeded */
oiReturnStatus = -3.
<M-5 run SetMessage
(input #T-13'Failed to retrieve next number for sequence $1.':255(134314538)T-13# (icMessage),
input string(iiNumbrYear) + '/' + icNumbrType (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'D' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'blf-314877':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
finally:
if vhSvr <> ?
then do:
delete object vhSvr.
vhSvr = ?.
end.
end finally.