Description
Create the posting header record.
Executed by UI when the user press the >> button in bank state line form
Parameters
iiPeriodId | input | integer | Period ID |
iiPeriodYear | input | integer | Period Year |
iiPeriodPeriod | input | integer | Period Period |
iiJournalId | input | integer | Journal ID |
icJournalCode | input | character | Daybook Code |
oiVoucher | output | integer | Voucher |
itBankStateLinePostingDate | input | date | posting date |
itBankStateLineValueDate | input | date | Value Date |
icBankStateLineDescription | input | character | Description |
iiGLId | input | integer | GL id |
icGLCode | input | character | GL code |
biBJournalEntryId | input-output | integer | Instance of Journal Entry |
biPostingId | input-output | integer | Posting ID |
ocRowId | output | character | Row ID of posting, necessary to create posting lines |
icParentRowId | input | character | Parent Row ID |
icRowId | input | character | Row ID |
icBankStateNumber | input | character | Bank State Number |
iiBankStateYear | input | integer | Year of bank statement |
icBankImpLineRef | input | character | Bank Importing Reference |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bbankentry.p)
/* ====================== */
/* replace unknown values */
/* ====================== */
if iiPeriodId = ? then assign iiPeriodId = 0.
if iiPeriodYear = ? then assign iiPeriodYear = 0.
if iiPeriodPeriod = ? then assign iiPeriodPeriod = 0.
if iiJournalId = ? then assign iiJournalId = 0.
if icJournalCode = ? then assign icJournalCode = "":U.
if icBankStateLineDescription = ? then assign icBankStateLineDescription = "":U.
if iiGLId = ? then assign iiGLId = 0.
if icGLCode = ? then assign icGLCode = "":U.
if icBankStateNumber = ? then assign icBankStateNumber = "":U.
if iiBankStateYear = ? then assign iiBankStateYear = 0.
if biBJournalEntryId = ? then assign biBJournalEntryId = 0.
if biPostingId = ? then assign biPostingId = 0.
assign viBJournalEntryBEID = biBJournalEntryId
viBankPostingYear = 0
vcBankPostingJournalCode = "":U
viBankPostingVoucher = 0.
/* ==================================================== */
/* if there was already a posting header record for it, */
/* don't do a thing here */
/* ==================================================== */
if biPostingId <> 0
then return.
/* ========================= */
/* validate input Period */
/* ========================= */
if iiPeriodId = 0 and iiPeriodYear = 0 and iiPeriodPeriod = 0
then do:
assign vcMessage = trim(#T-24'You must enter the GL period.':150(337)T-24#)
oiReturnStatus = -1.
<M-1 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-719':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
end.
/* ========================= */
/* validate input Journal */
/* ========================= */
if iiJournalId = 0 and icJournalCode = "":U
then do:
assign vcMessage = trim(#T-25'You must enter the daybook.':150(338)T-25#)
oiReturnStatus = -1.
<M-22 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-2186':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
end.
/* ========================= */
/* validate input GL */
/* ========================= */
if iiGLId = 0 and icGLCode = "":U
then do:
assign vcMessage = trim(#T-26'You must enter the GL account.':150(339)T-26#)
oiReturnStatus = -1.
<M-23 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-2187':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
end.
if itBankStateLinePostingDate = ?
then do:
assign vcMessage = trim(#T-27'You must enter the posting date.':150(340)T-27#)
oiReturnStatus = -1.
<M-8 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-723':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
end.
/* In case one of the 4 previuos messages appeared, return */
if oiReturnStatus = -1
then return.
/* ======================================================= */
/* get the period year and period if only the id is filled */
/* ======================================================= */
if (iiPeriodId <> 0 and iiPeriodYear = 0 and iiPeriodPeriod = 0)
then do:
<Q-2 run PeriodPrim (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input iiPeriodId, (PeriodId)
input ?, (PeriodYear)
input ?, (PeriodPeriod)
output dataset tqPeriodPrim) in BPeriod >
find first tqPeriodPrim no-error.
if not available tqPeriodPrim
then do:
assign vcMessage = trim(#T-28'The specified GL period is not defined in the system.':150(341)T-28#)
oiReturnStatus = -1.
<M-3 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-720':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
return.
end.
assign iiPeriodId = tqPeriodPrim.tiPeriod_ID.
end.
/* ========================================== */
/* get the glcode if only the gl id is filled */
/* ========================================== */
if iiGLId <> 0 and icGLCode = "":U
then do:
<Q-4 run GLPrim (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input ?, (GLCode)
input iiGLId, (GLId)
output dataset tqGLPrim) in BGL >
find first tqGLPrim no-error.
if not available tqGLPrim
then do:
assign vcMessage = trim(#T-29'The specified GL account is not defined in the system.':150(342)T-29#)
oiReturnStatus = -1.
<M-5 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-721':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
return.
end.
assign icGLCode = tqGLPrim.tcGLCode.
end.
<Q-18 run GetGLIDBasedOnGLCode (all) (Read) (NoCache)
(input viCompanyId, (CompanyID)
input icGLCode, (GLCode)
output dataset tqGLIDBasedOnGLCode) in BGL >
find first tqGLIDBasedOnGLCode no-error.
if not available tqGLIDBasedOnGLCode
then do:
assign vcMessage = trim(#T-30'The specified GL account is not defined in the system.':150(342)T-30#)
oiReturnStatus = -1.
<M-19 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-792':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
return.
end.
/* ===================================================== */
/* get the journal code if only the journal ID is filled */
/* ===================================================== */
if iiJournalId <> 0 and icJournalCode = "":U
then do:
<Q-6 run JournalPrim (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input ?, (JournalCode)
input iiJournalId, (JournalID)
output dataset tqJournalPrim) in BJournal >
find first tqJournalPrim no-error.
if not available tqJournalPrim
then do:
assign vcMessage = trim(#T-31'The specified daybook is not defined in the system.':150(343)T-31#)
oiReturnStatus = -1.
<M-7 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-722':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
return.
end.
end.
/* ================================ */
/* start the journal entry instance */
/* ================================ */
if viBJournalEntryBEID = 0 or viBJournalEntryBEID = ?
then do:
<I-14 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "True"
&CLASS = "BJournalEntry"}>
assign vlBJEIsStartedFromBE = true.
end.
else do:
<I-15 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
end.
assign biBJournalEntryId = viBJournalEntryBEID.
/* when you set the vlPostingMustBeBalanced on false, then you can create */
/* posting lines in journal entry that are not in balance */
/* and before you write the date you can set it back to true */
<M-20 run SetPublicData
(input 'vlPostingMustBeBalanced':U (icDataList),
input 'false':U (icValueList),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
/* ========================= */
/* add posting header record */
/* ========================= */
<M-12 run AddPostingHeader
(input viCompanyId (iiCompanyId),
input iiPeriodYear (iiPeriodYear),
input iiPeriodPeriod (iiPeriodPeriod),
input icJournalCode (icJournalCode),
input '' (icReportingJournalCode),
input ? (iiVoucher),
input itBankStateLinePostingDate (itPostingDate),
input itBankStateLineValueDate (itValueDate),
input icBankStateLineDescription (icPostingText),
input tqGLIDBasedOnGLCode.tcBusinessRelationCode (icPostingBusinessRelationText),
input '':U (icPostingInvoiceReferenceText),
input icBankStateLineDescription (icPostingParentText),
input ? (iiBPeriodId),
input ? (icPostingOriginAddressCode),
input string(iiBankStateYear, '9999':U) + '/':U + trim(icJournalCode) (icPostingOriginDocument),
input ? (icPostingOriginDocumentType),
input '':U (icBatchNumber),
input icBankImpLineRef (icBankImpLineRef),
output biPostingId (oiPostingId),
output ocRowId (ocRowid),
output oiVoucher (oiPostingVoucher),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-17 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
assign vcMessage = trim(substitute(#T-32'An error occurred when creating the posting header: &1.':200(344)T-32#, string(viFcReturnSuper))).
<M-16 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-757':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
return.
end.
/* ================================================================================= *
* If the user tries to make a banking entry for very small amount in Foreign *
* currency, then LC amount can lead to 0 amount *
* ================================================================================= */
<M-68 run SetPostingIsZeroValueAllowed
(input ocRowId (icPostingRowId),
input ? (iiPostingId),
input true (ilPostingIsZeroValueAllowed),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-90 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
return.
end.
/* ========================================================================================================= */
/* Normally we would here close BJournalEntry but we will not do it for performance */
/* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it. */
/* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the */
/* appserver that is executed after each call to the appserver */
/* ========================================================================================================= */
assign viBankPostingYear = iiPeriodYear
vcBankPostingJournalCode = icJournalCode
viBankPostingVoucher = oiVoucher.
find first tBankStateLine where
tBankStateLine.tc_RowId = icRowId and
tBankStateLine.tc_ParentRowid = icParentRowId
no-error.
if available tBankStateLine
then assign tBankStateLine.tiPostingPeriodYear = viBankPostingYear
tBankStateLine.tcPostingJournalCode = vcBankPostingJournalCode
tBankStateLine.tiPostingVoucher = viBankPostingVoucher.