project QadFinancials > class BCInvoice > method CreateCInvoiceMovementsCrossCyExt
Description
CreateCInvoiceMovementsCrossCyExt; sub -mehtod of CreateCInvoiceMovementsCrossCy (submehtod of CreateCInvoiceMovements) that is called to create a QCroosCompany-record that will be picked up later on by a daemon.
Parameters
iiOriginatorPostingID | input | integer | OriginatorPostingID |
iiOriginatorPostingLineId | input | integer | OriginatorPostingLineId |
idMovementAmountCreditTC | input | decimal | MovementAmountCreditTC |
idMovementAmountDebitTC | input | decimal | MovementAmountDebitTC |
idMovementAmountCreditLC | input | decimal | |
idMovementAmountDebitLC | input | decimal | |
idMovementAmountCreditCC | input | decimal | |
idMovementAmountDebitCC | input | decimal | |
iiCInvoiceID | input | integer | MovementCInvoiceID |
iiCInvoiceCompanyID | input | integer | CInvoiceCompanyID; company of the cinvoice |
iiCDocumentInvoiceXrefID | input | integer | ID of the Supplier payment allocation records which triggers the Supplier invoice movement. |
ilMovementIsAboutWHT | input | logical | |
itPaymentDate | input | date | Date of the Payment in case the movement is related to a payment |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program7/bcinvoice.p)
/* ======================================================================= */
/* Get the CI and the current Cy; errors are already checked by the caller */
/* ======================================================================= */
<Q-36 run CInvoiceByCyIDYearJrnlVchr (all) (Read) (Cache)
(input ?, (CompanyId)
input iiCInvoiceID, (CInvoiceId)
input ?, (PeriodYear)
input ?, (JournalId)
input ?, (JournalCode)
input ?, (Voucher)
output dataset tqCInvoiceByCyIDYearJrnlVchr) in BCInvoice>
assign vcLogicalIDCInvoice = ''.
vlPaySelUnconfirm = ?.
<I-65 {bFcOpenInstance
&CLASS = "Session"}>
<M-63 run GetLogicalValue
(input 'PaySelUnconfirm':U (icName),
output vlPaySelUnconfirm (olValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
/* Fill in the vcLogicalIDCInvoice */
find first tqCInvoiceByCyIDYearJrnlVchr where
tqCInvoiceByCyIDYearJrnlVchr.tiCInvoice_ID = iiCInvoiceID
no-lock no-error.
if available tqCInvoiceByCyIDYearJrnlVchr
then assign vcLogicalIDCInvoice = tqCInvoiceByCyIDYearJrnlVchr.tcCompanyCode + "/" +
string (tqCInvoiceByCyIDYearJrnlVchr.tiCInvoicePostingYear) + "/" +
tqCInvoiceByCyIDYearJrnlVchr.tcJournalCode + "/" +
string (tqCInvoiceByCyIDYearJrnlVchr.tiCInvoiceVoucher).
/* ==================================================================== */
/* Store the unconfirm indicator of supplier payment selection. */
/* This indicator will be used by a different session (Cross Cy Daemon) */
/* ==================================================================== */
if vlPaySelUnconfirm = true and available tqCInvoiceByCyIDYearJrnlVchr
then assign vcLogicalIDCInvoice = vcLogicalIDCInvoice + "/" +
'#SIPAYSELUC#':U.
/* ==================================================================== */
/* Store the Bounced indicator of supplier payment. */
/* This indicator will be used by a different session (Cross Cy Daemon) */
/* ==================================================================== */
if tMovement.tlIsUndoPayment = true and
vlPaySelUnconfirm <> true and
available tqCInvoiceByCyIDYearJrnlVchr
then assign vcLogicalIDCInvoice = vcLogicalIDCInvoice + "/" +
'#SIBOUNCED#':U.
/* ==================================================================== */
/* Store the Bounced indicator of supplier open item adjustment. */
/* This indicator will be used by a different session (Cross Cy Daemon) */
/* ==================================================================== */
if tMovement.tlIsDelTaxAtPartialPayment = false and available tqCInvoiceByCyIDYearJrnlVchr
then assign vcLogicalIDCInvoice = vcLogicalIDCInvoice + "/" +
'#SIADJ#':U.
/* ===================================================== */
/* Get the domain fo the company of the invoice */
/* ===================================================== */
<Q-29 run CompanyByDomainActive (all) (Read) (Cache)
(input tqCInvoiceByCyIDYearJrnlVchr.tiCompany_ID, (CompanyId)
input ?, (DomainId)
input ?, (CompanyIsActive)
output dataset tqCompanyByDomainActive) in BCompany>
find first tqCompanyByDomainActive no-lock no-error.
/* ============================================================================================ */
/* Get a GL that will be used for the posting in the current company with following properties; */
/* Get the A/R G/L account that is specified in the domain of the current company */
/* - GL.GLType should be CrossCompany */
/* - GL.GLSystemType should be empty */
/* - GL.GLIsIntercompany should be true */
/* ============================================================================================ */
<Q-30 run DomainForInterCompany (all) (Read) (Cache)
(input tqCompanyByDomainActive.tiDomain_ID, (DomainID)
input ?, (DomainCode)
input ?, (CompanyID)
output dataset tqDomainForInterCompany) in BDomain>
find first tqDomainForInterCompany no-lock no-error.
if not available tqDomainForInterCompany
then do :
assign vcMessage = trim(substitute(#T-20'A cross-company error occurred. No cross-company account information is defined for the domain (&1 / &2) linked to the invoice':255(662255080)T-20#,tqDomainForInterCompany.tcDomainCode,tqDomainForInterCompany.tiDomain_ID)) + chr(10) +
trim(substitute(#T-21'Supplier invoice: &1.':255(995)T-21#,string(tqCInvoiceByCyIDYearJrnlVchr.tcJournalCode) + "/":U + string(tqCInvoiceByCyIDYearJrnlVchr.tiPeriodYear) + "/":U + string(tqCInvoiceByCyIDYearJrnlVchr.tiCInvoiceVoucher,"999999999":U))) + chr(10) +
trim(substitute(#T-22'Entity of the invoice &1.':250(453606997)T-22#,string(iiCInvoiceCompanyID)))
oiReturnStatus = -3.
<M-5 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tqCInvoiceByCyIDYearJrnlVchr.tc_rowid (icRowid),
input 'QADFIN-856':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
return.
end. /* if not available tqDomainForInterCompany */
assign vcMessage = "":U.
if tqDomainForInterCompany.tcIntercoAPGLCode = "":U and
tqDomainForInterCompany.tcIntercoAPGLCode = ?
then assign vcMessage = vcMessage + chr(10) + trim(substitute(#T-31'No AP cross-company control account was defined for domain (&1).':255(59435)T-31#,tqCompanyByDomainActive.tcDomainCode)).
if tqDomainForInterCompany.tlIntercoAPGLIsIntercoAccount <> true
then assign vcMessage = vcMessage + chr(10) + trim(#T-32'The GL account must be an intercompany account.':255(997)T-32#).
if tqDomainForInterCompany.tlIntercoAPGLIsCostCentreAccount and
(tqDomainForInterCompany.tiIntercoAPCostCentreProfile_ID = 0 or
tqDomainForInterCompany.tiIntercoAPCostCentreProfile_ID = ?)
then assign vcMessage = vcMessage + chr(10) + trim(#T-33'No cost center was specified, and the GL account is defined with cost center analysis. A default cost center is mandatory for automatic postings.':255(998)T-33#).
if tqDomainForInterCompany.tlIntercoAPGLIsProjectAccount and
(tqDomainForInterCompany.tiIntercoAPProjectProfile_ID = 0 or
tqDomainForInterCompany.tiIntercoAPProjectProfile_ID = ?)
then assign vcMessage = vcMessage + chr(10) + trim(#T-34'No project was specified, and the GL account is defined with project analysis. A default project is mandatory for automatic postings.':255(999)T-34#).
if tqDomainForInterCompany.tlIntercoAPGLIsDivisionAccount and
(tqDomainForInterCompany.tiIntercoAPDivisionProfile_ID = 0 or
tqDomainForInterCompany.tiIntercoAPDivisionProfile_ID = ?)
then assign vcMessage = vcMessage + chr(10) + trim(#T-35'No sub-account was specified, and the GL account is defined with sub-account analysis. A default sub-account is mandatory for automatic postings.':255(1000)T-35#).
if vcMessage <> "":U and LENGTH(vcMessage,"CHARACTER":U) > 1
then do :
assign vcMessage = trim(substitute(#T-27'A cross-company error occurred. GL account &2 is incorrectly defined in domain &1.':255(680860200)T-27#,tqCompanyByDomainActive.tcDomainCode,tqDomainForInterCompany.tcIntercoAPGLCode)) + chr(10) +
trim(substitute(#T-28'Supplier invoice: &1.':255(995)T-28#,string(tqCInvoiceByCyIDYearJrnlVchr.tcJournalCode) + "/":U + string(tqCInvoiceByCyIDYearJrnlVchr.tiPeriodYear) + "/":U + string(tqCInvoiceByCyIDYearJrnlVchr.tiCInvoiceVoucher,"999999999":U))) + chr(10) +
substring(vcMessage,2,-1,"CHARACTER":U)
oiReturnStatus = -3.
<M-6 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tqCInvoiceByCyIDYearJrnlVchr.tc_rowid (icRowid),
input 'QADFIN-857':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
return.
end. /* if vcMessage <> "":U and LENGTH(vcMessage,"CHARACTER":U) > 1 */
/* =========================================================================== */
/* Create a Q-CrossCompany posting that will be picked up later-on by a daemon */
/* =========================================================================== */
create tNewQCrossCyPostingTable.
assign tNewQCrossCyPostingTable.Company_ID = tqCInvoiceByCyIDYearJrnlVchr.tiCompany_ID
tNewQCrossCyPostingTable.CInvoice_ID = tqCInvoiceByCyIDYearJrnlVchr.tiCInvoice_ID
tNewQCrossCyPostingTable.Currency_ID = tqCInvoiceByCyIDYearJrnlVchr.tiCInvoiceCurrency_ID
tNewQCrossCyPostingTable.CrossCompanyGL_ID = tqDomainForInterCompany.tiIntercoAPGL_ID
tNewQCrossCyPostingTable.CrossCompanyGLIsCredit = (if idMovementAmountCreditTC <> 0 and idMovementAmountCreditTC <> ? then false else true)
tNewQCrossCyPostingTable.OriginatorCompany_ID = viCompanyId
tNewQCrossCyPostingTable.OriginatorPosting_ID = iiOriginatorPostingID
tNewQCrossCyPostingTable.OriginatorPostingLine_ID = iiOriginatorPostingLineId
tNewQCrossCyPostingTable.OriginatorJournal_ID = tqCInvoiceByCyIDYearJrnlVchr.tiJournal_ID
tNewQCrossCyPostingTable.QCrossCyPostingAmountTC = (if idMovementAmountCreditTC <> 0 and idMovementAmountCreditTC <> ? then idMovementAmountCreditTC else idMovementAmountDebitTC)
tNewQCrossCyPostingTable.QCrossCyPostingAmountLC = (if idMovementAmountCreditLC <> 0 and idMovementAmountCreditLC <> ? then idMovementAmountCreditLC else idMovementAmountDebitLC)
tNewQCrossCyPostingTable.QCrossCyPostingAmountCC = (if idMovementAmountCreditCC <> 0 and idMovementAmountCreditCC <> ? then idMovementAmountCreditCC else idMovementAmountDebitCC)
tNewQCrossCyPostingTable.tc_Rowid = string(tNewQCrossCyPostingTable.OriginatorPostingLine_ID) + "-":U + string(tNewQCrossCyPostingTable.QCrossCyPostingAmountTC) + "-":U + STRING(TIME,"HH:MM:SS":U)
tNewQCrossCyPostingTable.QCrossCyPostingInfo = vcLogicalIDCInvoice
tNewQCrossCyPostingTable.QCrossCyPostingIsWHT = ilMovementIsAboutWHT
tNewQCrossCyPostingTable.QCrossCyPostingPaymentDate = itPaymentDate.
/* ============================================================================ *
* Create instructions for the Cross company daemon to also update staged *
* payments *
* Stages should be updated only when *
* - payment has stages which are created *
* - for payment created in Paid status - two movements for one allocation *
* can be created (one normal and second for applying of WHT *
* ============================================================================ */
if can-find(first tCInvoiceStageUpdates where
tCInvoiceStageUpdates.tiCInvoice_ID = tNewQCrossCyPostingTable.CInvoice_ID and
tCInvoiceStageUpdates.tc_Status <> "":U ) and
not can-find(first tNewQCrossCyPostingTable where
tNewQCrossCyPostingTable.CInvoice_ID = tNewQCrossCyPostingTable.CInvoice_ID and
tNewQCrossCyPostingTable.CDocumentInvoiceXref_ID <> ? and
tNewQCrossCyPostingTable.CDocumentInvoiceXref_ID <> 0)
then assign tNewQCrossCyPostingTable.CDocumentInvoiceXref_ID = iiCDocumentInvoiceXrefID.
/* ============================================================================================================= */
/* Create instance-dep temp-table tCInvoiceIDsForQCrossCompany to store CInvoiceIDs for the CInvoices wherefor a */
/* tNewCrossCyPostingTable-record is created in method CreateCInvoiceMovement (and the submethods of it). */
/* Based on this temp-table, PreSave-method will update the CInvoiceIsSelected-flag for these CInvoices (that */
/* are not loaded into the business-instance). */
/* Create inst-dep temp-table tPostingLinesForQCrossCy to store PostingLineIDs for the CInvoices */
/* wherefor a tNewCrossCyPostingTable-record is created in method CreateCInvoiceMovement (and the */
/* submethods of it). Based on this temp-table, method StopExternalInstances will mark these PostingLines as */
/* deleted in the BPostingInstance. This has to be defined as instance-independant because it gets filled */
/* and emptied in CreateCInvoiceMovement and used further on in StopExternalInstances */
/* ============================================================================================================= */
if tNewQCrossCyPostingTable.CInvoice_ID <> 0 and
tNewQCrossCyPostingTable.CInvoice_ID <> ?
then do:
if not can-find(first tCInvoiceIDsForQCrossCompany where
tCInvoiceIDsForQCrossCompany.tiCInvoiceID = tNewQCrossCyPostingTable.CInvoice_ID)
then do:
create tCInvoiceIDsForQCrossCompany.
assign tCInvoiceIDsForQCrossCompany.tiCInvoiceID = tNewQCrossCyPostingTable.CInvoice_ID.
end.
end. /* if tNewQCrossCyPostingTable.CInvoice_ID <> 0 and */
if tNewQCrossCyPostingTable.OriginatorPostingLine_ID <> 0 and
tNewQCrossCyPostingTable.OriginatorPostingLine_ID <> ?
then do:
if not can-find(first tPostingLinesForQCrossCompany where
tPostingLinesForQCrossCompany.tiPostingLineID = tNewQCrossCyPostingTable.OriginatorPostingLine_ID)
then do:
create tPostingLinesForQCrossCompany.
assign tPostingLinesForQCrossCompany.tiPostingLineID = tNewQCrossCyPostingTable.OriginatorPostingLine_ID.
end.
end. /* if tNewQCrossCyPostingTable.OriginatorPostingLine_ID <> 0 and */