Parameters
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/tconvertinstalnetxml.p)
define buffer btNETDBTableRef for tNETDBTableRef.
/* Fill the data for the export here */
for each tNETDBTableRef where
tNETDBTableRef.trParentRowid = ?:
find t_oCInvoice where
t_oCInvoice.tc_Rowid = string(tNETDBTableRef.trChildRowid) no-error.
if not available t_oCInvoice
then do:
<M-46 run SetMessageInLog
(input #T-48'Creditor-Invoice integration: No input record record was found.You have to define for which records creditor invoices must be created.':255(999890624)T-48# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
/* Company ID */
if t_oCInvoice.Company_ID = ? or t_oCInvoice.Company_ID = 0
then do:
<M-63 run SetMessageInLog
(input #T-63'Invalid Company Code':200(999890625)T-63# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
/* Creditor */
if vcEANSupplier = '':U or vcEANSupplier = '?':U or vcEANSupplier = ?
then do:
<M-55 run SetMessageInLog
(input #T-55'Invalid Supplier GLN':200(999890626)T-55# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
else do:
/* Currency Code - already filled from import */
if t_oCInvoice.tcCurrencyCode <> '':U and
t_oCInvoice.tcCurrencyCode <> ? and
t_oCInvoice.tcCurrencyCode <> '?':U
then do:
<Q-59 run CurrencyPrim (all) (Read) (NoCache)
(input t_oCInvoice.tcCurrencyCode, (CurrencyCode)
input ?, (Currency_ID)
output dataset tqCurrencyPrim) in BCurrency >
find first tqCurrencyPrim no-error.
if available tqCurrencyPrim
then assign t_oCInvoice.CInvoiceCurrency_ID = tqCurrencyPrim.tiCurrency_ID.
else do:
<M-60 run SetMessageInLog
(input #T-65'Invalid currency code.':200(16214)T-65# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
end.
else do:
<M-75 run SetMessageInLog
(input #T-76'Invalid currency code.':200(16214)T-76# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
<Q-56 run BusinessRelationByEANCode (all) (Read) (NoCache)
(input vcEANSupplier, (EANCode)
output dataset tqBusinessRelationByEANCode) in BBusinessRelation >
find tqBusinessRelationByEANCode no-error.
if available tqBusinessRelationByEANCode
then do:
<Q-57 run CreditorByBusinessRelation (all) (Read) (NoCache)
(input t_oCInvoice.Company_ID, (CompanyId)
input ?, (CreditorCode)
input tqBusinessRelationByEANCode.tiBusinessRelation_ID, (BusinessRelationId)
output dataset tqCreditorByBusinessRelation) in BCreditor >
find tqCreditorByBusinessRelation where
tqCreditorByBusinessRelation.tcCurrencyCode = t_oCInvoice.tcCurrencyCode
no-error.
if not available tqCreditorByBusinessRelation
then do:
<M-58 run SetMessageInLog
(input #T-56'Invalid Creditor Code':200(999890630)T-56# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
assign t_oCInvoice.tcCreditorCode = tqCreditorByBusinessRelation.tcCreditorCode.
end.
end.
assign vhFcComponent = ?
t_oCInvoice.CInvoice_ID = <M-28 GetNextValue (input 'ObjectNumber':U (icSequence)) in persistence>.
/* PeriodYear + PeriodPeriod */
<Q-2 run PeriodByStartEndDate (first) (Read) (NoCache)
(input viCompanyLoadedId, (CompanyId)
input today, (Date)
output dataset tqPeriodByStartEndDate) in BPeriod >
find first tqPeriodByStartEndDate no-error.
if available tqPeriodByStartEndDate
then assign t_oCInvoice.Period_ID = tqPeriodByStartEndDate.tiPeriod_ID
t_oCInvoice.CInvoicePostingYear = tqPeriodByStartEndDate.tiPeriodYear
t_oCInvoice.CInvoicePostingPeriod = tqPeriodByStartEndDate.tiPeriodPeriod.
/* Creditor */
if t_oCInvoice.tcCreditorCode = "":U or t_oCInvoice.tcCreditorCode = ? or t_oCInvoice.tcCreditorCode = "?":U
then do:
<M-29 run SetMessageInLog
(input #T-49'Invalid Creditor Code':200(999890630)T-49# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
<Q-9 run CreditorByCreditor (all) (Read) (NoCache)
(input ?, (CreditorId)
input t_oCInvoice.Company_ID, (CompanyId)
input t_oCInvoice.tcCreditorCode, (CreditorCode)
input ?, (AddressType)
output dataset tqCreditorByCreditor) in BCreditor >
find first tqCreditorByCreditor no-error.
if available tqCreditorByCreditor
then do:
assign t_oCInvoice.Creditor_ID = tqCreditorByCreditor.tiCreditor_ID
viGLProfileId = if t_oCInvoice.CInvoiceType = {&INVOICETYPE-INVOICE} then tqCreditorByCreditor.tiInvControlGLProfile_ID else if t_oCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTE} then tqCreditorByCreditor.tiCnControlGLProfile_ID else ?.
if viGLProfileId <> ? and viGLProfileId <> 0
then do:
<Q-5 run ProfileLinkByGL (all) (Read) (NoCache)
(input viGLProfileId, (GlProfileId)
input viCompanyId, (CompanyId)
output dataset tqProfileLinkByGL) in BProfile >
end.
/* Division Code */
find first tqProfileLinkByGL no-error.
if available tqProfileLinkByGL and
tqProfileLinkByGL.tlGLIsDivisionAccount and
tqCreditorByCreditor.tiDivisionProfile_ID <> ? and tqCreditorByCreditor.tiDivisionProfile_ID <> 0
then do:
<Q-6 run GetDivisionFromProfile (all) (Read) (NoCache)
(input t_oCInvoice.Company_ID, (CompanyId)
input tqCreditorByCreditor.tiDivisionProfile_ID, (DivisionProfileId)
output dataset tqDivisionFromProfile) in BProfile >
find first tqDivisionFromProfile no-error.
if available tqDivisionFromProfile
then assign t_oCInvoice.tcDivisionCode = tqDivisionFromProfile.tcDivisionCode
t_oCInvoice.Division_ID = tqDivisionFromProfile.tiDivision_ID.
end.
end.
else do:
<M-33 run SetMessageInLog
(input #T-44'Invalid creditor code':200(999890628)T-44# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
/* Journal Code */
assign viJournalProfileId = if t_oCInvoice.CInvoiceType = {&INVOICETYPE-INVOICE} then tqCreditorByCreditor.tiInvControlGLProfile_ID else if t_oCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTE} then tqCreditorByCreditor.tiCnControlGLProfile_ID else ?.
if viJournalProfileId <> ? and viJournalProfileId <> 0
then do:
<Q-8 run JournalForProfile (all) (Read) (NoCache)
(input viJournalProfileId, (JournalProfileId)
input t_oCInvoice.Company_ID, (CompanyId)
input ?, (JournalControl)
output dataset tqJournalForProfile) in BProfile >
end.
find first tqJournalForProfile where
tqJournalForProfile.tiProfile_ID = viJournalProfileId
no-error.
if available tqJournalForProfile
then assign t_oCInvoice.Journal_ID = tqJournalForProfile.tiJournal_ID
t_oCInvoice.tcJournalCode = tqJournalForProfile.tcJournalCode.
else do:
<M-35 run SetMessageInLog
(input #T-37'Invalid Journal Code':200(999890627)T-37# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
/* Reason Code */
if available tqCreditorByCreditor
then assign t_oCInvoice.Reason_ID = tqCreditorByCreditor.tiReason_ID
t_oCInvoice.tcReasonCode = tqCreditorByCreditor.tcReasonCode.
/* Reason Allocation Status */
assign t_oCInvoice.tcReasonAllocationStatus = {&ALLOCSTATUS-NOALLOC}.
/* BLWI Group Code */
if available tqCreditorByCreditor
then assign t_oCInvoice.BLWIGroup_ID = tqCreditorByCreditor.tiBLWIGroup_ID
t_oCInvoice.tcBLWIGroupCode = tqCreditorByCreditor.tcBLWIGroupCode.
/* Own Country Code */
/* Own Business Relation Code */
/* Own VAT Number Identity */
<Q-11 run CompanyPropertyByBusinessRel (all) (Read) (NoCache)
(input t_oCInvoice.Company_ID, (CompanyId)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty >
find first tqCompanyPropertyByBusinessRel no-error.
if available tqCompanyPropertyByBusinessRel
then assign t_oCInvoice.CInvoiceOwnVatNumber = tqCompanyPropertyByBusinessRel.tcAddressTaxIDState
t_oCInvoice.tcOwnVatNumberCountryCode = tqCompanyPropertyByBusinessRel.tcAddressCountryCode
t_oCInvoice.tcTransactionEndCountryCode = tqCompanyPropertyByBusinessRel.tcAddressCountryCode
t_oCInvoice.TransactionEndCountry_ID = tqCompanyPropertyByBusinessRel.tiIdentityCountry_ID.
else do:
<M-38 run SetMessageInLog
(input #T-45'Invalid company property':200(999890629)T-45# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
/* Local Currency Code */
if t_oCInvoice.Company_ID <> ? and t_oCInvoice.Company_ID <> 0
then do:
<Q-15 run CompanyPropertyForAllData (all) (Read) (NoCache)
(input t_oCInvoice.Company_ID, (CompanyId)
output dataset tqCompanyPropertyForAllData) in BCompanyProperty >
find first tqCompanyPropertyForAllData no-error.
if available tqCompanyPropertyForAllData
then assign t_oCInvoice.tcLocalCurrencyCode = tqCompanyPropertyForAllData.tcCurrencyCode.
end.
/* CA Journal Code */
/* CA Voucher */
assign t_oCInvoice.tcCAJournalCode = '':U
t_oCInvoice.tiCAVoucher = 0.
/* MF Journal Code */
assign t_oCInvoice.tcMFJournalCode = '':U.
/* Posting Date */
/* Type - input file */
/* Voucher - TODO - in case filled in the input file - take it, otherwise getnumber */
/* Date - input file */
/* Tax Point Date */
/* Reference - input file */
/* Description */
assign t_oCInvoice.CInvoicePostingDate = today
t_oCInvoice.CInvoiceTaxPointDate = t_oCInvoice.CInvoiceDate
t_oCInvoice.tcCInvoiceReference1 = '':U
t_oCInvoice.CInvoiceDescription = '':U.
/* Linked CInvoice Voucher */
/* Linked Journal Code */
/* Linked Period Year */
assign t_oCInvoice.LinkedCInvoice_ID = 0
t_oCInvoice.tiLinkedCInvoiceVoucher = 0
t_oCInvoice.tcLinkedJournalCode = '':U
t_oCInvoice.tiLinkedPeriodYear = 0.
/* Is Open */
/* Is Selected */
/* Allocation Status */
assign t_oCInvoice.CInvoiceIsOpen = true
t_oCInvoice.CInvoiceIsSelected = false
t_oCInvoice.CInvoiceAllocationStatus = {&ALLOCSTATUS-NOALLOC}.
/* CInvoice Is Lock Payment */
/* CInvoice Is Invoice Approved */
if t_oCInvoice.tcReasonCode <> ? and t_oCInvoice.tcReasonCode <> "?":U and t_oCInvoice.tcReasonCode <> "":U
then do:
<Q-16 run ReasonByIdCode (all) (Read) (NoCache)
(input t_oCInvoice.Reason_ID, (ReasonId)
input t_oCInvoice.tcReasonCode, (ReasonCode)
output dataset tqReasonByIdCode) in BReason >
find first tqReasonByIdCode no-error.
if available tqReasonByIdCode
then assign t_oCInvoice.CInvoiceIsLockPayment = tqReasonByIdCode.tlReasonIsLockPayment
t_oCInvoice.CInvoiceIsInvoiceApproved = tqReasonByIdCode.tlReasonIsInvoiceApproved.
end.
/* Contact */
/* TSM Number */
assign t_oCInvoice.CInvoiceContact = '':U
t_oCInvoice.CInvoiceTSMNumber = '':U.
/* Normal Payment Condition */
/* Discount Payment Condition */
if available tqCreditorByCreditor
then assign t_oCInvoice.NormalPaymentCondition_ID = tqCreditorByCreditor.tiNormalPaymentCondition_ID
t_oCInvoice.tcNormalPaymentConditionCode = tqCreditorByCreditor.tcNormalPaymentConditionCode
t_oCInvoice.tcNormalPaymentConditionType = tqCreditorByCreditor.tcNormalPaymentConditionPayType.
/* t_oCInvoice.DiscPaymentCondition_ID = tqCreditorByCreditor.tiDiscPaymentCondition_ID
t_oCInvoice.tcDiscountPaymentConditionCode = tqCreditorByCreditor.tcDiscountPaymentConditionCode. */
/* Due Date */
/* Discount Due Date */
if t_oCInvoice.tcNormalPaymentConditionCode <> '':U and t_oCInvoice.tcNormalPaymentConditionCode <> ? and t_oCInvoice.tcNormalPaymentConditionCode <> "?":U
then do:
<Q-17 run PaymentConditionByIdCode (all) (Read) (NoCache)
(input t_oCInvoice.NormalPaymentCondition_ID, (PaymentConditionId)
input t_oCInvoice.tcNormalPaymentConditionCode, (PaymentConditionCode)
output dataset tqPaymentConditionByIdCode) in BPaymentCondition >
find first tqPaymentConditionByIdCode no-error.
if available tqPaymentConditionByIdCode
then do:
assign vhFcComponent = ?.
<M-71 run CalculateDueDiscountDate
(input tqPaymentConditionByIdCode.tiPaymentCondition_ID (iiPaymentConditionID),
input tqPaymentConditionByIdCode.tcPaymentConditionCode (icPaymentConditionCode),
input t_oCInvoice.CInvoiceDate (itInvoiceDate),
output t_oCInvoice.CInvoiceDueDate (otDueDate),
output t_oCInvoice.CInvoiceDiscountDueDate (otDiscountDate),
output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
end.
end.
else do:
<M-50 run SetMessageInLog
(input #T-50'Invalid normal payment condition':200(999890631)T-50# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
/* CI Text */
/* MF Text */
assign t_oCInvoice.CInvoiceCIText = '':U
t_oCInvoice.CInvoiceMFText = '':U.
/* Closing Date */
/* Is Logistic Matching */
/* Creditor Payment Means */
assign t_oCInvoice.CInvoiceClosingDate = ?
t_oCInvoice.CInvoiceCirecClosingDate = ?
t_oCInvoice.CInvoiceIsLogisticMatching = false.
/*BKW*
if available tqCreditorByCreditor
then assign t_oCInvoice.tcCreditorPaymentMeans = tqCreditorByCreditor.tcCreditorPaymentMeans.
*BKW*/
/* t_oCInvoice.tcPaymentMeansTranslated */
/* call submethod in order to split the code */
assign vcRole = '':U.
<M-27 run SetOutputDataSub (output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
if viFcReturnSuper < 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
/* Cons.Curr */
<Q-23 run SystemPropertyByAll (all) (Read) (NoCache)
(output dataset tqSystemPropertyByAll) in BSystemProperty >
find first tqSystemPropertyByAll no-error.
if available tqSystemPropertyByAll
then do:
<Q-26 run CurrencyByCode (all) (Read) (NoCache)
(input tqSystemPropertyByAll.tcCurrencyCode, (CurrencyCode)
output dataset tqCurrencyByCode) in BCurrency >
find first tqCurrencyByCode no-error.
if available tqCurrencyByCode
then do:
assign vhFcComponent = ?.
<M-25 run APIGetExchangeRate (input ? (iiFromCurrencyId),
input t_oCInvoice.tcCurrencyCode (icFromCurrencyCode),
input ? (iiToCurrencyId),
input tqCurrencyByCode.tcCurrencyCode (icToCurrencyCode),
input ? (iiExchangeRateTypeId),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input t_oCInvoice.CInvoiceDate (itValidityDate),
output vdExchangeRate (odMultiplyExchangeRate),
output vdExchangeRateScale (odExchangeRateScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BExchangeRate>
/* Original Debit CC */
/* Original Credit CC */
/* Balance Debit CC */
/* Balance Credit CC */
/* VAT Base Debit CC */
/* VAT Base Credit CC */
/* VAT Debit CC */
/* VAT Credit CC */
assign vhFcComponent = ?
t_oCInvoice.CInvoiceOriginalDebitCC = <M-65 RoundAmount
(input t_oCInvoice.CInvoiceOriginalDebitTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input tqCurrencyByCode.tiCurrency_ID (iiCurrencyID),
input tqCurrencyByCode.tcCurrencyCode (icCurrencyCode)) in business>
t_oCInvoice.CInvoiceOriginalCreditCC = <M-72 RoundAmount
(input t_oCInvoice.CInvoiceOriginalCreditTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input tqCurrencyByCode.tiCurrency_ID (iiCurrencyID),
input tqCurrencyByCode.tcCurrencyCode (icCurrencyCode)) in business>
t_oCInvoice.CInvoiceBalanceDebitCC = t_oCInvoice.CInvoiceOriginalDebitCC
t_oCInvoice.CInvoiceBalanceCreditCC = t_oCInvoice.CInvoiceOriginalCreditCC
t_oCInvoice.CInvoiceVATBaseDebitCC = <M-67 RoundAmount
(input t_oCInvoice.CInvoiceVATBaseDebitTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input tqCurrencyByCode.tiCurrency_ID (iiCurrencyID),
input tqCurrencyByCode.tcCurrencyCode (icCurrencyCode)) in business>
t_oCInvoice.CInvoiceVATBaseCreditCC = <M-68 RoundAmount
(input t_oCInvoice.CInvoiceVATBaseCreditTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input tqCurrencyByCode.tiCurrency_ID (iiCurrencyID),
input tqCurrencyByCode.tcCurrencyCode (icCurrencyCode)) in business>
t_oCInvoice.CInvoiceVATDebitCC = <M-69 RoundAmount
(input t_oCInvoice.CInvoiceVATDebitTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input tqCurrencyByCode.tiCurrency_ID (iiCurrencyID),
input tqCurrencyByCode.tcCurrencyCode (icCurrencyCode)) in business>
t_oCInvoice.CInvoiceVATCreditCC = <M-70 RoundAmount
(input t_oCInvoice.CInvoiceVATCreditTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input tqCurrencyByCode.tiCurrency_ID (iiCurrencyID),
input tqCurrencyByCode.tcCurrencyCode (icCurrencyCode)) in business>
vlSysPropertyIsSpecCIApprove = tqSystemPropertyByAll.tlSysPropertyIsSpecCIApprove.
end.
end.
else assign vlSysPropertyIsSpecCIApprove = false.
/* Role */
if vlSysPropertyIsSpecCIApprove = true
then do:
<Q-52 run RoleByNameId (all) (Read) (NoCache)
(input ?, (RoleID)
input vcRole, (RoleName)
output dataset tqRoleByNameId) in BRole >
find first tqRoleByNameId no-error.
if available tqRoleByNameId
then assign t_oCInvoice.Role_ID = tqRoleByNameId.tiRole_ID
t_oCInvoice.tcRoleName = tqRoleByNameId.tcRoleName.
else do:
<M-53 run SetMessageInLog
(input #T-54'Invalid Role':200(999890632)T-54# (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
end.
else assign t_oCInvoice.Role_ID = ?
t_oCInvoice.tcRoleName = '':U.
/* Original Amount TC */
/* Original Amount LC */
/* Balance LC */
/* Balance CC */
assign t_oCInvoice.tdCInvoiceOriginalTC = t_oCInvoice.CInvoiceOriginalDebitTC - t_oCInvoice.CInvoiceOriginalCreditTC
t_oCInvoice.tdCInvoiceOriginalLC = t_oCInvoice.CInvoiceOriginalDebitLC - t_oCInvoice.CInvoiceOriginalCreditLC
t_oCInvoice.CInvoiceBalanceLC = t_oCInvoice.CInvoiceBalanceDebitLC - t_oCInvoice.CInvoiceBalanceCreditLC
t_oCInvoice.CInvoiceBalanceCC = t_oCInvoice.CInvoiceBalanceDebitCC - t_oCInvoice.CInvoiceBalanceCreditCC
t_oCInvoice.tdCInvoiceVatBaseTC = t_oCInvoice.CInvoiceVatBaseDebitTC - t_oCInvoice.CInvoiceVatBaseCreditTC
t_oCInvoice.tdCInvoiceVatBaseLC = t_oCInvoice.CInvoiceVatBaseDebitLC - t_oCInvoice.CInvoiceVatBaseCreditLC.
t_oCInvoice.CInvoiceIsVatDelay = false. /* TODO in ucs nothing */
/* Total Amount TC */
/* Total Amount LC */
assign t_oCInvoice.tdTotalAmountDebitTC = t_oCInvoice.CInvoiceVatBaseDebitTC + t_oCInvoice.CInvoiceVatDebitTC
t_oCInvoice.tdTotalAmountCreditTC = t_oCInvoice.CInvoiceVatBaseCreditTC + t_oCInvoice.CInvoiceVatCreditTC.
end.