project QadFinancials > class BDInvoice > method CreateDInvoiceMovementsCrossCyExt
Description
CreateDInvoiceMovementsCrossCyExt; sub -mehtod of CreateDInvoiceMovementsCrossCy (submehtod of CreateDInvoiceMovements) that is called to create a QCrossCompany-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 |
iiDInvoiceID | input | integer | MovementDInvoiceID |
iiDInvoiceCompanyID | input | integer | DInvoiceCompanyID; company of the Debtor Invoice |
iiDDocumentInvoiceXrefID | input | integer | |
idMovementDiscountAmountTC | input | decimal | MovementDiscountAmountTC |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bdinvoice.p)
/* ======================================================================= */
/* Get the DI and the current Cy; errors are already checked by the caller */
/* ======================================================================= */
<Q-38 run DInvoiceByDebtStatusCurr (all) (Read) (NoCache)
(input ?, (CompanyId)
input iiDInvoiceID, (DInvoiceId)
input ?, (DebtorId)
input ?, (SkipRowId)
input ?, (DebtorCode)
input ?, (CurrencyCode)
input ?, (DInvoiceIsOpen)
input ?, (DInvoiceType)
input ?, (CurrencyId)
input ?, (DInvoiceIsSelected)
input ?, (DInvoiceBalanceDebitTC)
output dataset tqDInvoiceByDebtStatusCurr) in BDInvoice >
find first tqDInvoiceByDebtStatusCurr where
tqDInvoiceByDebtStatusCurr.tiDInvoice_ID = iiDInvoiceID
no-lock no-error.
/* Fill in the vcLogicalIDCInvoice */
assign vcLogicalIDDInvoice = ''.
if available tqDInvoiceByDebtStatusCurr
then assign vcLogicalIDDInvoice = tqDInvoiceByDebtStatusCurr.tcCompanyCode + "/" +
string (tqDInvoiceByDebtStatusCurr.tiPeriodYear ) + "/" +
tqDInvoiceByDebtStatusCurr.tcJournalCode + "/" +
string (tqDInvoiceByDebtStatusCurr.tiDInvoiceVoucher).
/* ===================================================== */
/* Get the domain fo the company of the invoice */
/* ===================================================== */
<Q-29 run CompanyByDomainActive (all) (Read) (Cache)
(input tqDInvoiceByDebtStatusCurr.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. The system could not find cross-company account information for the domain (&1 / &2) linked to the invoice.':255(59445)T-20#,tqDomainForInterCompany.tcDomainCode,tqDomainForInterCompany.tiDomain_ID)) + chr(10) +
trim(substitute(#T-21'Customer invoice: '&1'.':255(49403)T-21#, string(tqDInvoiceByDebtStatusCurr.tcJournalCode) + "/":U + string(tqDInvoiceByDebtStatusCurr.tiPeriodYear) + "/":U + string(tqDInvoiceByDebtStatusCurr.tiDInvoiceVoucher, "999999999":U))) + chr(10) +
trim(substitute(#T-22'Entity of the invoice: '&1'.':255(59446)T-22#,string(iiDInvoiceCompanyID)))
oiReturnStatus = -3.
<M-11 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-1089':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end. /* if not available tqDomainForInterCompany */
assign vcMessage = "":U.
if tqDomainForInterCompany.tcIntercoARGLCode = "":U and
tqDomainForInterCompany.tcIntercoARGLCode = ?
then assign vcMessage = vcMessage + chr(10) + trim(substitute(#T-31'AR cross-company accounts are not defined for the domain (&1).':255(59436)T-31#,vcDomainCode)).
if tqDomainForInterCompany.tlIntercoARGLIsIntercoAccount <> true
then assign vcMessage = vcMessage + chr(10) + trim(#T-32'The GL account must be an intercompany account.':255(997)T-32#).
if tqDomainForInterCompany.tlIntercoARGLIsCostCentreAccount and
(tqDomainForInterCompany.tiIntercoARCostCentreProfile_ID = 0 or
tqDomainForInterCompany.tiIntercoARCostCentreProfile_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.tlIntercoARGLIsProjectAccount and
(tqDomainForInterCompany.tiIntercoARProjectProfile_ID = 0 or
tqDomainForInterCompany.tiIntercoARProjectProfile_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.tlIntercoARGLIsDivisionAccount and
(tqDomainForInterCompany.tiIntercoARDivisionProfile_ID = 0 or
tqDomainForInterCompany.tiIntercoARDivisionProfile_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' in domain '&1' is defined incorrectly.':255(59447)T-27#,tqCompanyByDomainActive.tcDomainCode,tqDomainForInterCompany.tcIntercoARGLCode)) + chr(10) +
trim(substitute(#T-28'Customer invoice: '&1'.':255(49403)T-28#, string(tqDInvoiceByDebtStatusCurr.tcJournalCode) + "/":U + string(tqDInvoiceByDebtStatusCurr.tiPeriodYear) + "/":U + string(tqDInvoiceByDebtStatusCurr.tiDInvoiceVoucher, "999999999":U))) + chr(10) +
substring(vcMessage,2,-1,"CHARACTER":U)
oiReturnStatus = -3.
<M-12 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-1090':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
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 tNewQCrossCyPostingDI.
assign tNewQCrossCyPostingDI.Company_ID = tqDInvoiceByDebtStatusCurr.tiCompany_ID
tNewQCrossCyPostingDI.DInvoice_ID = tqDInvoiceByDebtStatusCurr.tiDInvoice_ID
tNewQCrossCyPostingDI.Currency_ID = tqDInvoiceByDebtStatusCurr.tiDInvoiceCurrency_ID
tNewQCrossCyPostingDI.CrossCompanyGL_ID = tqDomainForInterCompany.tiIntercoARGL_ID
tNewQCrossCyPostingDI.CrossCompanyGLIsCredit = (if idMovementAmountCreditTC <> 0 and idMovementAmountCreditTC <> ? then false else true)
tNewQCrossCyPostingDI.OriginatorCompany_ID = viCompanyId
tNewQCrossCyPostingDI.OriginatorPosting_ID = iiOriginatorPostingID
tNewQCrossCyPostingDI.OriginatorPostingLine_ID = iiOriginatorPostingLineId
tNewQCrossCyPostingDI.OriginatorJournal_ID = tqDInvoiceByDebtStatusCurr.tiJournal_ID
tNewQCrossCyPostingDI.QCrossCyPostingAmountTC = (if idMovementAmountCreditTC <> 0 and idMovementAmountCreditTC <> ? then idMovementAmountCreditTC else idMovementAmountDebitTC)
tNewQCrossCyPostingDI.tc_Rowid = string(tNewQCrossCyPostingDI.OriginatorPostingLine_ID) + "-":U + string(tNewQCrossCyPostingDI.QCrossCyPostingAmountTC) + "-":U + STRING(TIME,"HH:MM:SS":U)
tNewQCrossCyPostingDI.QCrossCyPostingInfo = vcLogicalIDDInvoice
tNewQCrossCyPostingDI.DDocumentInvoiceXref_ID = iiDDocumentInvoiceXrefID
tNewQCrossCyPostingDI.QCrossCyPostingDiscAmountTC =idMovementDiscountAmountTC .
/* ====================================================================================================== */
/* Extend vcListDInvoiceIDsForQCrossCy; Comma-separated list of DInvoiceIDs for the DInvoices wherefor a */
/* tNewCrossCyPostingTable-record is created in method CreateDInvoiceMovement (and the submethods of it). */
/* Based on this list, PreSave-method will update the DInvoiceIsSelected-flag for these DInvoices (that */
/* are not loaded into the business-instance). */
/* Extend vcListDIPostingLinesForQCrossCy; Comma-separated list of PostingLineIDs for the DInvoices */
/* wherefor a tNewCrossCyPostingDI-record is created in method CreateDInvoiceMovement (and the */
/* submethods of it). Based on this list, 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 CreateDInvoiceMovement and used further on in StopExternalInstances */
/* ====================================================================================================== */
assign vcListDInvoiceIDsForQCrossCy =
if vcListDInvoiceIDsForQCrossCy <> "":U and
vcListDInvoiceIDsForQCrossCy <> ?
then vcListDInvoiceIDsForQCrossCy + ",":U + string(tNewQCrossCyPostingDI.DInvoice_ID)
else string(tNewQCrossCyPostingDI.DInvoice_ID)
vcListDIPostingLinesForQCrossCy =
if vcListDIPostingLinesForQCrossCy <> "":U and
vcListDIPostingLinesForQCrossCy <> ?
then vcListDIPostingLinesForQCrossCy + ",":U + string(tNewQCrossCyPostingDI.OriginatorPostingLine_ID)
else string(tNewQCrossCyPostingDI.OriginatorPostingLine_ID).