Description
This method is a submethod of ApiStdMaintainTT.
This method contains validations on input temp-tables.
Validation/Defaults:
- There can only be one CInvoice loaded at a time - There can be max two Postings (invoice/matching)
- Reason should correspond with the Postings (tcReasonAllocationStatus)
- Validate (and/or default) exchange rates
- Validations on invoice amounts
- Default the default bank information if not specified in input temp-tables
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bcinvoicejournalentry.p)
/* ===================================================================== */
/* Parameter Validation: */
/* - There can only be one CInvoice loaded at a time */
/* - There can be max two Postings */
/* - There can be just one CInvoice */
/* - Reason should correspond with the Postings (ReasonAllocationStatus) */
/* - Add call to validate (and/or default exchange rates */
/* ===================================================================== */
assign viMainTableRecordCount = 0.
for each t_sApiCinvoiceCIJE:
assign viMainTableRecordCount = viMainTableRecordCount + 1
vcReasonAllocationStatus = t_sApiCInvoiceCIJE.tcReasonAllocationStatus.
end. /* for each t_sApiCinvoiceCIJE: */
if viMainTableRecordCount = 0
then do:
assign vcMsgApi = trim(#T-7'No input record found. You must define for which records you want to create supplier invoices.':255(1253)T-7#)
oiReturnStatus = -1.
<M-1 run SetMessage (input vcMsgApi (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-3294':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
return.
end. /* if MainTableRecordCount = 0 */
if viMainTableRecordCount > 1
then do:
assign vcMsgApi = trim(#T-8'This file contains multiple Supplier Invoices. Only 1 is allowed.':255(329060724)T-8#)
oiReturnStatus = -1.
<M-2 run SetMessage (input vcMsgApi (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-3295':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
return.
end. /* if MainTableRecordCount > 0 */
assign viMainTableRecordCount = 0
viMainTableRecordCountCI = 0
viMainTableRecordCountMF = 0.
for each t_sApiCinvoicePostingCIJE:
if t_sApiCInvoicePostingCIJE.CInvoicePostingType = {&INVOICEPOSTINGTYPE-INITIAL}
then assign viMainTableRecordCountCI = viMainTableRecordCountCI + 1.
if t_sApiCInvoicePostingCIJE.CInvoicePostingType = {&INVOICEPOSTINGTYPE-ALLOCATION}
then assign viMainTableRecordCountMF = viMainTableRecordCountMF + 1.
assign viMainTableRecordCount = viMainTableRecordCount + 1.
end. /* for each t_sApiCinvoicePostingCIJE */
if viMainTableRecordCount > 2 or
viMainTableRecordCountCI > 1 or
viMainTableRecordCountMF > 1
then do:
assign vcMsgApi = trim(#T-9'Several posting records were found. You can only have one invoice and one matching posting.':255(1255)T-9#)
oiReturnStatus = -1.
<M-3 run SetMessage (input vcMsgApi (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-3296':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
return.
end. /* if viMainTableRecordCount > 2 or */
if viMainTableRecordCountMF = 1 and
(vcReasonAllocationStatus <> {&ALLOCSTATUS-ANY} and vcReasonAllocationStatus <> {&ALLOCSTATUS-ALLOC} and vcReasonAllocationStatus <> {&ALLOCSTATUS-TRANSALLOC})
then do:
assign vcMsgApi = trim(#T-12'A matching posting record was found. However, this invoice must not be defined with matching.':255(1258)T-12#)
oiReturnStatus = -1.
<M-6 run SetMessage (input vcMsgApi (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-3299':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
return.
end. /* if viMainTableRecordCountMF = 1 and */
find first t_sApiCInvoiceCIJE no-error.
if available t_sApiCInvoiceCIJE
then do:
if t_sApiCInvoiceCIJE.Company_ID = ? or
t_sApiCInvoiceCIJE.Company_ID = 0
then do:
assign t_sApiCInvoiceCIJE.Company_ID = viCompanyId.
end.
end. /* if available t_sApiCInvoiceBankCIJE */
/* Read all GL of this company */
<Q-13 run GLByGLType (all) (Read) (Cache)
(input t_sApiCInvoiceCIJE.Company_ID, (CompanyId)
input ?, (GLId)
input '':U, (GLCode)
input '':U, (GLTypeCode)
input ?, (GLIsDivisionAccount)
output dataset tqGLByGLType) in BGL >
assign viCount = 0.
for each t_sApiPostingLineCIJE :
find first tqGLByGLType where
(tqGLByGLType.tiGL_ID = t_sApiPostingLineCIJE.GL_ID or
tqGLByGLType.tcGLCode = t_sApiPostingLineCIJE.tcGLCode)
no-error.
if not available tqGLByGLType
then next.
if tqGLByGLType.tcGLTypeCode <> {&GLTYPECODE-CRED} and
tqGLByGLType.tcGLTypeCode <> {&GLTYPECODE-CROSS} and
tqGLByGLType.tcGLTypeCode <> {&GLTYPECODE-OPEN} and
tqGLByGLType.tcGLTypeCode <> {&GLTYPECODE-STAN} and
tqGLByGLType.tcGLTypeCode <> {&GLTYPECODE-VAT} and
tqGLByGLType.tcGLTypeCode <> {&GLTYPECODE-BANK} and
tqGLByGLType.tcGLTypeCode <> {&GLTYPECODE-CASH} and
tqGLByGLType.tcGLTypeCode <> {&GLTYPECODE-SYST} /* can be CIREC */
then do :
assign vcMsgApi = trim(#T-16'This type of account cannot be used.':40(55695)T-16#)
oiReturnStatus = -1.
<M-14 run SetMessage
(input vcMsgApi (icMessage),
input '':U (icArguments),
input 'tqGLByGLType.tcGLTypeCode':U (icFieldName),
input tqGLByGLType.tcGLTypeCode (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-5545':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input 'GL=':U + tqGLByGLType.tcGLCode (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
end.
if tqGLByGLType.tcGLTypeCode = {&GLTYPECODE-CRED}
then do:
if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-INVOICE} or
t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-FINANCECHARGE} or
t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-CREDITNOTE} or
t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or
t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} or
t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-PREPAYMENT} or
t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-ADJUSTMENT}
then do:
if t_sApiPostingLineCIJE.PostingLineCreditTC = 0 and
t_sApiPostingLineCIJE.PostingLineDebitTC = 0
then do:
assign oiReturnStatus = 1.
<M-62 run SetMessage
(input #T-45'You are creating an invoice with zero debit and zero credit':255(275934491)T-45# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-89227':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
end. /*IF t_sApiPostingLineCIJE.PostingLineDebitTC*/
end. /* if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-INVOICE} */
if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-INVOICE} or
t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-FINANCECHARGE}
then do:
if t_sApiPostingLineCIJE.PostingLineCreditTC < 0 or
t_sApiPostingLineCIJE.PostingLineDebitTC <> 0
then do:
assign oiReturnStatus = -1.
<M-52 run SetMessage
(input #T-5'You cannot create a supplier invoice / financial charge with a negative credit or non-zero debit':255(891118688)T-5# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-162693':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
end. /*if t_sApiPostingLineCIJE.PostingLineDebitTC <> 0 or*/
end. /*if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-CREDITNOTE}*/
if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-CREDITNOTE}
then do:
if t_sApiPostingLineCIJE.PostingLineCreditTC <> 0 or
t_sApiPostingLineCIJE.PostingLineDebitTC < 0
then do:
assign oiReturnStatus = -1.
<M-93 run SetMessage
(input #T-87'You cannot create a supplier credit note with a non-zero credit or negative debit':255(92255349)T-87# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-658611':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
end. /*if t_sApiPostingLineCIJE.PostingLineCreditTC <> 0 or*/
end. /*if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-CREDITNOTE}*/
if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then do:
if t_sApiPostingLineCIJE.PostingLineCreditTC > 0 or
t_sApiPostingLineCIJE.PostingLineDebitTC <> 0
then do:
assign oiReturnStatus = -1.
<M-58 run SetMessage
(input #T-47'You cannot create a supplier invoice correction with a positive credit or non-zero debit':255(682481717)T-47# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-330742':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
end. /*if t_sApiPostingLineCIJE.PostingLineDebitTC <> 0 or*/
end. /*if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-CREDITNOTE}*/
if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
then do:
if t_sApiPostingLineCIJE.PostingLineCreditTC <> 0 or
t_sApiPostingLineCIJE.PostingLineDebitTC > 0
then do:
assign oiReturnStatus = -1.
<M-50 run SetMessage
(input #T-55'You cannot create a supplier credit note correction with a non-zero credit or positive debit':255(298548032)T-55# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-838038':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
end. /*if t_sApiPostingLineCIJE.PostingLineDebitTC <> 0 or*/
end. /*if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-CREDITNOTE}*/
if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-PREPAYMENT} or
t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-ADJUSTMENT}
then do:
if t_sApiPostingLineCIJE.PostingLineCreditTC <> 0 and
t_sApiPostingLineCIJE.PostingLineDebitTC <> 0
then do:
assign oiReturnStatus = -1.
<M-91 run SetMessage
(input #T-63'You cannot create a prepayment/adjustment invoice with a non-zero debit and non-zero credit':255(765416669)T-63# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-353460':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
end. /*if t_sApiPostingLineCIJE.PostingLineDebitTC <> 0 or*/
end. /*if t_sApiCinvoiceCIJE.CInvoiceType = {&INVOICETYPE-CREDITNOTE}*/
assign viCount = viCount + 1.
end. /*IF tqGLByGLType.tcGLTypeCode = {&GLTYPECODE-CRED}*/
end.
if viCount <> 1
then do :
assign vcMsgApi = trim(#T-17'You must specify one supplier control account.':60(55697)T-17#)
oiReturnStatus = -1.
<M-15 run SetMessage
(input vcMsgApi (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input viCount (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-5546':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
return.
end.
/* ============================================== */
/* retrieve the creditor_id to pass to banknumber */
/* ============================================== */
if t_sApiCInvoiceCIJE.tcCreditorCode <> "":U and
t_sApiCInvoiceCIJE.tcCreditorCode <> ?
then do:
<Q-18 run CreditorPrim (all) (Read) (NoCache)
(input t_sApiCInvoiceCIJE.Company_ID, (CompanyId)
input ?, (CreditorId)
input t_sApiCInvoiceCIJE.tcCreditorCode, (CreditorCode)
output dataset tqCreditorPrim) in BCreditor >
find first tqCreditorPrim where
tqCreditorPrim.tcCreditorCode = t_sApiCInvoiceCIJE.tcCreditorCode
no-error.
if not available tqCreditorPrim
then do:
assign vcMsgApi = trim(substitute(#T-22'Supplier &1 not found.':60(999890721)T-22#, t_sApiCInvoiceCIJE.tcCreditorCode))
oiReturnStatus = -1.
<M-21 run SetMessage
(input vcMsgApi (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-9248':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
return.
end.
assign t_sApiCInvoiceCIJE.Creditor_ID = tqCreditorPrim.tiCreditor_ID.
/* ================================================= */
/* Get the default bank information if not specified */
/* ================================================ */
find first t_sApiCinvoiceBankCIJE no-error.
if not available t_sApiCinvoiceBankCIJE
then do:
<Q-19 run BankNumberForCIDefault (all) (Read) (NoCache)
(input t_sApiCInvoiceCIJE.Creditor_ID, (ParentObjectId)
input ?, (BankNumberIsDefault)
input true, (BankNumberIsActive)
input ?, (CompanyId)
output dataset tqBankNumberForCIDefault) in BBankNumber >
/* Find active defeault banknumber for current entity */
find first tqBankNumberForCIDefault where
tqBankNumberForCIDefault.tiParentObject_ID = t_sApiCInvoiceCIJE.Creditor_ID and
tqBankNumberForCIDefault.tlBankNumberIsDefault = true and
tqBankNumberForCIDefault.tlBankNumberIsActive = true and
tqBankNumberForCIDefault.tiCompany_ID = t_sApiCInvoiceCIJE.Company_ID
no-error.
/* If can not find deafault banknumber just find the active banknumber for current entity */
if not available tqBankNumberForCIDefault
then find first tqBankNumberForCIDefault where
tqBankNumberForCIDefault.tiParentObject_ID = t_sApiCInvoiceCIJE.Creditor_ID and
tqBankNumberForCIDefault.tlBankNumberIsActive = true and
tqBankNumberForCIDefault.tiCompany_ID = t_sApiCInvoiceCIJE.Company_ID
no-error.
if not available tqBankNumberForCIDefault
then find first tqBankNumberForCIDefault where
tqBankNumberForCIDefault.tiParentObject_ID = t_sApiCInvoiceCIJE.Creditor_ID and
tqBankNumberForCIDefault.tlBankNumberIsDefault = true and
tqBankNumberForCIDefault.tlBankNumberIsActive = true
no-error.
if available tqBankNumberForCIDefault
then do:
create t_sApiCInvoiceBankCIJE.
assign t_sApiCInvoiceBankCIJE.tiParentObject_ID = tqBankNumberForCIDefault.tiParentObject_ID
t_sApiCInvoiceBankCIJE.BankNumber_ID = tqBankNumberForCIDefault.tiBankNumber_ID
t_sApiCInvoiceBankCIJE.tcBankNumber = tqBankNumberForCIDefault.tcBankNumberFormatted
t_sApiCInvoiceBankCIJE.tcBankNumberExtension = tqBankNumberForCIDefault.tcBankNumberExtension
t_sApiCInvoiceBankCIJE.tcBankNumberValidation = tqBankNumberForCIDefault.tcBankNumberValidation
t_sApiCInvoiceBankCIJE.tcBankNumberSwiftCode = tqBankNumberForCIDefault.tcBankNumberSwiftCode
t_sApiCInvoiceBankCIJE.tcBusinessRelationCode = tqBankNumberForCIDefault.tcBusinessRelationCode
t_sApiCInvoiceBankCIJE.tiBankPayFormat_ID = tqBankNumberForCIDefault.tiBankPayFormat_ID
/* Assign the value to pay equal to the amount of the invoice */
t_sApiCInvoiceBankCIJE.CInvoiceBankToPayTC = if t_sApiCInvoiceCIJE.CInvoiceOriginalCreditTC <> 0 and
t_sApiCInvoiceCIJE.CInvoiceOriginalCreditTC <> ?
then t_sApiCInvoiceCIJE.CInvoiceOriginalCreditTC
else t_sApiCInvoiceCIJE.CInvoiceOriginalDebitTC
t_sApiCInvoiceBankCIJE.tc_Rowid = "X"
t_sApiCInvoiceBankCIJE.tc_ParentRowid = t_sApiCInvoiceCIJE.tc_Rowid
viSeq = 0.
<Q-20 run BankNumberPayCodeForCIDefSupp (all) (Read) (NoCache)
(input t_sApiCInvoiceBankCIJE.BankNumber_ID, (BankNumberId)
output dataset tqBankNumberPayCodeForCIDefSupp) in BBankNumber>
for each tqBankNumberPayCodeForCIDefSupp where
tqBankNumberPayCodeForCIDefSupp.tiBankNumber_ID = t_sApiCInvoiceBankCIJE.BankNumber_ID:
create t_sApiCInvoiceBankPayCodeCIJE.
assign t_sApiCInvoiceBankPayCodeCIJE.tc_ParentRowid = t_sApiCInvoiceBankCIJE.tc_Rowid
viSeq = viSeq + 1
t_sApiCInvoiceBankPayCodeCIJE.tc_Rowid = "X" + string(viSeq, "999":U)
t_sApiCInvoiceBankPayCodeCIJE.PayFormatGroup_ID = tqBankNumberPayCodeForCIDefSupp.tiPayFormatGroup_ID
t_sApiCInvoiceBankPayCodeCIJE.PayFormatCode_ID = tqBankNumberPayCodeForCIDefSupp.tiPayFormatCode_ID
t_sApiCInvoiceBankPayCodeCIJE.CInvoiceBankPayCodeValue = (if tqBankNumberPayCodeForCIDefSupp.tcBankNumberPayCodeValue <> ? and
tqBankNumberPayCodeForCIDefSupp.tcBankNumberPayCodeValue <> "":U
then tqBankNumberPayCodeForCIDefSupp.tcBankNumberPayCodeValue
else tqBankNumberPayCodeForCIDefSupp.tcPayFormatCode).
if tqBankNumberPayCodeForCIDefSupp.tcPayFormatGroupDataType = {&PAYFORMATGROUPDATATYPE-LOGICAL} and
(t_sApiCInvoiceBankPayCodeCIJE.CInvoiceBankPayCodeValue = ? or
t_sApiCInvoiceBankPayCodeCIJE.CInvoiceBankPayCodeValue = "":U)
then assign t_sApiCInvoiceBankPayCodeCIJE.CInvoiceBankPayCodeValue = "false":U.
end. /* end for each tqBankNumberPayCodeForCIDefSupp */
end. /* end available tqBankNumberForCIDefault */
end. /* end not available t_sApiCinvoiceBankCIJE */
end. /* end t_sApiCInvoiceCIJE.tcCreditorCode <> ... */
<M-56 run ApiStdMaintainTTValidateExchangeRate (output viFcReturnSuper (oiReturnStatus)) in BCInvoiceJournalEntry>
if oiReturnStatus >= 0 and viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.