tOpenBalanceCI | input-output | temp-table | dfasd |
iiBJournalEntryId | input | integer | Instance of BJournalEntry |
iiPostingId | input | integer | Posting ID |
icPONbrInv | input | character | |
ocNewRecordInfo | output | character | New Record Information : rowid, cinvoice_id, rowid, cinvoice_id, ...... |
oiReturnStatus | output | integer | Return status of the method. |
empty temp-table tDefaultSafsCI. assign vlStartCreditorByCreditor = false vlStartReasonByIdCode = false vlStartAddrByAddrBusRelType = false vlStartCompanyPropByBusinessRel = false vlStartReasonByInitialStatus = false vlStartBankNrPayCodeForCIDef = false vlStartSupplierForDaybookSet = false vlStartPOAccountingControl = false. /* replace unknown value */ if iiBJournalEntryId = ? then assign iiBJournalEntryId = 0. if iiPostingId = ? then assign iiPostingId = 0. /* validate input parameters */ <M-1 run CreateCInvoicesValidate (input-output tOpenBalanceCI (tOpenBalanceCI), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then return. CREATEBLOCK : DO : for each tOpenBalanceCI where tOpenBalanceCI.tcCreditorCode <> "":U no-lock: /* create the invoice */ <M-2 run AddDetailLine (input 'CInvoice':U (icTable), input '':U (icParentRowid), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. find first tFcRowidConvert where tFcRowidConvert.tcFcNewRowid = string(rowid(tOpenBalanceCI)) no-error. if available tFcRowidConvert then assign tFcRowidConvert.tcFcNewRowid = tCInvoice.tc_Rowid. assign tCInvoice.Company_ID = tOpenBalanceCI.tiCompanyId tCInvoice.CInvoiceHoldAmountTC = tOpenBalanceCI.tdInvoiceHoldAmountTC tCInvoice.CInvoicePostingPeriod = tOpenBalanceCI.tiPeriodPeriod tCInvoice.CInvoicePostingYear = tOpenBalanceCI.tiPeriodYear tCInvoice.tcCreditorCode = tOpenBalanceCI.tcCreditorCode tCInvoice.tcDivisionCode = tOpenBalanceCI.tcDivisionCode tCInvoice.tcJournalCode = tOpenBalanceCI.tcJournalCode tCInvoice.CInvoicePostingDate = tOpenBalanceCI.ttPostingDate tCInvoice.CInvoiceType = tOpenBalanceCI.tcInvoiceType tCInvoice.CInvoiceDate = tOpenBalanceCI.ttInvoiceDate tCInvoice.CInvoiceTaxPointDate = tOpenBalanceCI.ttInvoiceTaxPointDate tCInvoice.CInvoiceReference = tOpenBalanceCI.tcInvoiceReference tCInvoice.CInvoiceDescription = tOpenBalanceCI.tcInvoiceDescription tCInvoice.tcCurrencyCode = tOpenBalanceCI.tcTCCurrencyCode tCInvoice.tcProjectCode = tOpenBalanceCI.tcProjectCode tCInvoice.tcCostCentreCode = tOpenBalanceCI.tcCostCentreCode tCInvoice.tcNormalPaymentConditionCode = tOpenBalanceCI.tcNormalPaymentConditionCode tCInvoice.CInvoiceExchangeRate = tOpenBalanceCI.tdExchangeRateTCLC tCInvoice.CinvoiceRateScale = if (tOpenBalanceCI.tdExchangeRateScale = 0 or tOpenBalanceCI.tdExchangeRateScale = ?) then 1 else tOpenBalanceCI.tdExchangeRateScale tCInvoice.CInvoiceCCRate = tOpenBalanceCI.tdExchangeRateTCCC tCInvoice.CInvoiceCCScale = if (tOpenBalanceCI.tdCCExchangeRateScale = 0 or tOpenBalanceCI.tdExchangeRateScale = ?)then 1 else tOpenBalanceCI.tdCCExchangeRateScale tCInvoice.tcReasonCode = tOpenBalanceCI.tcReasonCode tCInvoice.CInvoiceTSMNumber = tOpenBalanceCI.tcInvoiceTSMNumber tCInvoice.CInvoiceDueDate = tOpenBalanceCI.ttInvoiceDueDate tCInvoice.CInvoiceDiscountDueDate = tOpenBalanceCI.ttInvoiceDiscountDueDate tCInvoice.CInvoiceCIText = tOpenBalanceCI.tcPostingText tCInvoice.CInvoiceIsOpen = true tCInvoice.CInvoiceIsERS = tOpenBalanceCI.tlInvoiceIsERS tCInvoice.CInvoiceBatchNumber = tOpenBalanceCI.tcInvoiceBatchNumber tCInvoice.CInvoiceIsSelected = false ocNewRecordInfo = if tOpenBalanceCI.tcKey <> "":U then tOpenBalanceCI.tcKey + ",":U + string(tCInvoice.CInvoice_ID) else "":U tOpenBalanceCI.tiInvoiceId = tCInvoice.CInvoice_ID tCInvoice.tcRoleName = tOpenBalanceCI.tcRoleName tCInvoice.CInvoiceCommentNote = tOpenBalanceCI.tcInvoiceCommentNote tCInvoice.CInvoiceDayBookSetCode = tOpenBalanceCI.tcDayBookSetCode tCInvoice.tcBLWIGroupCode = tOpenBalanceCI.tcBLWIGroupCode. if tCInvoice.CInvoiceType <> {&INVOICETYPE-PREPAYMENT} then do: if icPONbrInv <> ? and icPONbrInv <> "":U then do: <Q-40 run PurchaseOrderByDomainNbrVend (all) (Read) (NoCache) (input vcDomainCode, (DomainCode) input icPONbrInv, (PONbr) input ?, (POVendor) input ?, (POCurrency) input ?, (POType) output dataset tqPurchaseOrderByDomainNbrVend) in BMfgPO> find tqPurchaseOrderByDomainNbrVend where tqPurchaseOrderByDomainNbrVend.tcpo_domain = vcDomainCode and tqPurchaseOrderByDomainNbrVend.tcpo_nbr = icPONbrInv no-error. if available tqPurchaseOrderByDomainNbrVend then do: assign tCInvoice.CInvoiceSiteCode = tqPurchaseOrderByDomainNbrVend.tcpo_site tCInvoice.CInvoiceDayBookSetCode = tqPurchaseOrderByDomainNbrVend.tcpo_daybookset. end. if tCInvoice.CInvoiceDayBookSetCode = "":U or tCInvoice.CInvoiceDayBookSetCode = ? then do: <M-39 run CreateCInvoicesDayBookSetCode (input-output vlStartSupplierForDaybookSet (blStartSupplierForDaybookSet), input-output vlStartPOAccountingControl (blStartPOAccountingControl), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. end. /* If (tCInvoice.CInvoiceDayBookSetCode = "":U or */ end. /* if icPONbrInv <> ? or */ else do: <M-97 run CreateCInvoicesDayBookSetCode (input-output vlStartSupplierForDaybookSet (blStartSupplierForDaybookSet), input-output vlStartPOAccountingControl (blStartPOAccountingControl), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. end. /* else do: */ end. /* if tCInvoice.CInvoiceType <> {&INVOICETYPE-PREPAYMENT} */ if tOpenBalanceCI.tcPostingType = {&POSTINGTYPE-DEBIT} then assign tCInvoice.CInvoiceOriginalDebitTC = tOpenBalanceCI.tdInvoiceAmountTC tCInvoice.CInvoiceOriginalDebitLC = tOpenBalanceCI.tdInvoiceAmountLC tCInvoice.CInvoiceOriginalDebitCC = tOpenBalanceCI.tdInvoiceAmountCC tCInvoice.tdCInvoiceOriginalTC = tOpenBalanceCI.tdInvoiceAmountTC tCInvoice.tdCInvoiceOriginalLC = tOpenBalanceCI.tdInvoiceAmountLC. else assign tCInvoice.CInvoiceOriginalCreditTC = tOpenBalanceCI.tdInvoiceAmountTC tCInvoice.CInvoiceOriginalCreditLC = tOpenBalanceCI.tdInvoiceAmountLC tCInvoice.CInvoiceOriginalCreditCC = tOpenBalanceCI.tdInvoiceAmountCC tCInvoice.tdCInvoiceOriginalTC = tOpenBalanceCI.tdInvoiceAmountTC tCInvoice.tdCInvoiceOriginalLC = tOpenBalanceCI.tdInvoiceAmountLC. if not vlStartCreditorByCreditor then do: <Q-29 run CreditorByCreditor (Start) in BCreditor > assign vlStartCreditorByCreditor = true. end. /* end not vlStartCreditorByCreditor */ <Q-4 run CreditorByCreditor (first) (Read) (Cache) (input ?, (CreditorId) input tOpenBalanceCI.tiCompanyId, (CompanyId) input tOpenBalanceCI.tcCreditorCode, (CreditorCode) input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType) output dataset tqCreditorByCreditor) in BCreditor > find first tqCreditorByCreditor no-error. if not available tqCreditorByCreditor then do: assign oiReturnStatus = -1. <M-5 run SetMessage (input trim(#T-12'The supplier is not defined in the system.':255(1134)T-12#) (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input '':U (icRowid), input 'QADFIN-670':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> leave CREATEBLOCK. end. /* end not available tqCreditorByCreditor */ assign tCInvoice.Creditor_ID = tqCreditorByCreditor.tiCreditor_ID tCInvoice.tcPurchaseTypeCode = tqCreditorByCreditor.tcPurchaseTypeCode tCInvoice.tcBLWIGroupCode = tqCreditorByCreditor.tcBLWIGroupCode. /*Use the Credit Term per domain*/ if tCInvoice.CInvoiceType = {&INVOICETYPE-PREPAYMENT} and (tCInvoice.tcNormalPaymentConditionCode = "":U or tCInvoice.tcNormalPaymentConditionCode = ?) then do: <Q-55 run DomainCreditTermByDomain (first) (Read) (NoCache) (input viDomainID, (Domain_ID) output dataset tqDomainCreditTermByDomain) in BDomainProperty> find first tqDomainCreditTermByDomain no-error. if available(tqDomainCreditTermByDomain) and tqDomainCreditTermByDomain.tcPrePaymentConditionCode <> ? and tqDomainCreditTermByDomain.tcPrePaymentConditionCode <> '':U and tqDomainCreditTermByDomain.tlPrePaymentConditionIsActive = true then tCInvoice.tcNormalPaymentConditionCode = tqDomainCreditTermByDomain.tcPrePaymentConditionCode. else tCInvoice.tcNormalPaymentConditionCode = "":U. if tCInvoice.tcNormalPaymentConditionCode = "":U or tCInvoice.tcNormalPaymentConditionCode = ? then do: assign tCInvoice.tcNormalPaymentConditionCode = tqCreditorByCreditor.tcNormalPaymentConditionCode. /*if the paymentconditioncode is stage, get first normal paymentcondition*/ if tqCreditorByCreditor.tcNormalPaymentConditionPayType = {&PAYMENTCONDITIONPAYMENTTYPE-STAGED} then do: <Q-66 run PaymentConditionByProperties (all) (Read) (NoCache) (input ?, (PaymentCondition_ID) input ?, (PaymentConditionCode) input true, (PaymentConditionIsActive) input {&PAYMENTCONDITIONPAYMENTTYPE-NORMAL}, (PaymentConditionPaymentType) input ?, (PaymentConditionPdDiscType) input 0, (PaymentConditionPercentage) output dataset tqPaymentConditionByProperties) in BPaymentCondition> find first tqPaymentConditionByProperties no-error. if available tqPaymentConditionByProperties then assign tCInvoice.tcNormalPaymentConditionCode = tqPaymentConditionByProperties.tcPaymentConditionCode. end. /*tqCreditorByCreditor.tcNormalPaymentConditionPayType = {&PAYMENTCONDITIONPAYMENTTYPE-STAGED} */ end. end. /* end tCInvoice.CInvoiceType = {&INVOICETYPE-PREPAYMENT} */ /* default reason of creditor if not yet filled and linked cinvoiceislockpayment and cinvoiceisinvoiceapproved */ if tCInvoice.tcReasonCode = "":U then assign tCInvoice.Reason_ID = if tqCreditorByCreditor.tiReason_ID = ? then 0 else tqCreditorByCreditor.tiReason_ID tCInvoice.tcReasonCode = if tqCreditorByCreditor.tcReasonCode = ? then "":U else tqCreditorByCreditor.tcReasonCode vlReasonFromCreditor = true. else assign vlReasonFromCreditor = false. /* all defaulting based on the reason code */ <M-24 run CreateCInvoicesReason (input-output vlStartReasonByIdCode (blStartReasonByIdCode), input-output vlStartReasonByInitialStatus (blStartReasonByInitialStatus), input vlReasonFromCreditor (ilIsReasonFromCreditor), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or viFcReturnSuper > 0 and oiReturnStatus = 0 then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. <M-44 run CreateCInvoicesDet (output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. /* default own vat number, transaction end country */ if not vlStartCompanyPropByBusinessRel then do: <Q-31 run CompanyPropertyByBusinessRel (Start) in BCompanyProperty > assign vlStartCompanyPropByBusinessRel = true. end. /* end not vlStartCompanyPropByBusinessRel */ <Q-7 run CompanyPropertyByBusinessRel (first) (Read) (Cache) (input tOpenBalanceCI.tiCompanyId, (CompanyId) input ?, (AddressType) output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty > find first tqCompanyPropertyByBusinessRel no-error. if available tqCompanyPropertyByBusinessRel then assign tCInvoice.CInvoiceOwnVatNumber = tqCompanyPropertyByBusinessRel.tcAddressTaxIDState tCInvoice.tcOwnVatNumberCountryCode = tqCompanyPropertyByBusinessRel.tcAddressCountryCode. /* creditor vat number, transaction start */ if not vlStartAddrByAddrBusRelType then do: <Q-33 run AddressByAddressBusRelType (Start) in BBusinessRelation > assign vlStartAddrByAddrBusRelType = true. end. /* end not vlStartAddrByAddrBusRelType */ <Q-8 run AddressByAddressBusRelType (all) (Read) (Cache) (input ?, (AddressTypeId) input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode) input tqCreditorByCreditor.tiBusinessRelation_ID, (BusinessRelationId) input tqCreditorByCreditor.tcBusinessRelationCode, (BusinessRelationCode) input ?, (AddressId) output dataset tqAddressByAddressBusRelType) in BBusinessRelation > find first tqAddressByAddressBusRelType no-error. if available tqAddressByAddressBusRelType then assign tCInvoice.CInvoiceCreditorVatNumber = tqAddressByAddressBusRelType.tcAddressTaxIDState tCInvoice.tcCredVatNumberCountryCode = tqAddressByAddressBusRelType.tcCountryCode. /* Create CInvoiceBank */ if (tOpenBalanceCI.tiBankNumber_ID <> ? and tOpenBalanceCI.tiBankNumber_ID <> 0) or (tOpenBalanceCI.tcBankNumber <> ? and tOpenBalanceCI.tcBankNumber <> "":U) then do: <M-14 run AddDetailLine (input 'CInvoiceBank':U (icTable), input tCInvoice.tc_rowid (icParentRowid), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. assign tCInvoiceBank.CInvoice_ID = tCInvoice.CInvoice_ID tCInvoiceBank.BankNumber_ID = tOpenBalanceCI.tiBankNumber_ID tCInvoiceBank.tcBankNumber = tOpenBalanceCI.tcBankNumber tCInvoiceBank.CInvoiceBankToPayTC = tOpenBalanceCI.tdInvoiceAmountTC tCInvoiceBank.tcBankNumberExtension = tOpenBalanceCI.tcBankNumberExtension tCInvoiceBank.tiParentObject_ID = tCInvoice.Creditor_ID. end. /* end tOpenBalanceCI.tiBankNumber_ID <> ? and ... */ else do: <Q-22 run BankNumberForCIDefault (all) (Read) (NoCache) (input tCInvoice.Creditor_ID, (ParentObjectId) input ?, (BankNumberIsDefault) input true, (BankNumberIsActive) input ?, (CompanyId) output dataset tqBankNumberForCIDefault) in BBankNumber> /* Find active and default bank number for current activity */ find first tqBankNumberForCIDefault where tqBankNumberForCIDefault.tiParentObject_ID = tCInvoice.Creditor_ID and tqBankNumberForCIDefault.tlBankNumberIsActive = true and tqBankNumberForCIDefault.tlBankNumberIsDefault = true and tqBankNumberForCIDefault.tiCompany_ID = tOpenBalanceCI.tiCompanyId no-error. /* Find active bank number for the current entity */ if not available tqBankNumberForCIDefault then find first tqBankNumberForCIDefault where tqBankNumberForCIDefault.tiParentObject_ID = tCInvoice.Creditor_ID and tqBankNumberForCIDefault.tlBankNumberIsActive = true and tqBankNumberForCIDefault.tiCompany_ID = tOpenBalanceCI.tiCompanyId no-error. /* just find the first active bank number */ if not available tqBankNumberForCIDefault then find first tqBankNumberForCIDefault where tqBankNumberForCIDefault.tiParentObject_ID = tCInvoice.Creditor_ID and tqBankNumberForCIDefault.tlBankNumberIsDefault = true and tqBankNumberForCIDefault.tlBankNumberIsActive = true no-error. if available tqBankNumberForCIDefault then do: <M-16 run AddDetailLine (input 'CInvoiceBank':U (icTable), input tCInvoice.tc_rowid (icParentRowid), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. assign tCInvoiceBank.CInvoice_ID = tCInvoice.CInvoice_ID tCInvoiceBank.BankNumber_ID = tqBankNumberForCIDefault.tiBankNumber_ID tCInvoiceBank.tcBankNumber = tqBankNumberForCIDefault.tcBankNumber tCInvoiceBank.CInvoiceBankToPayTC = tOpenBalanceCI.tdInvoiceAmountTC tCInvoiceBank.tcBankNumberExtension = tqBankNumberForCIDefault.tcBankNumberExtension tCInvoiceBank.tiBankPayFormat_ID = tqBankNumberForCIDefault.tiBankPayFormat_ID tCInvoiceBank.tiParentObject_ID = tqBankNumberForCIDefault.tiParentObject_ID. end. /* end if available */ end. /* else tOpenBalanceCI.tcCreditorCode <> '' */ if can-find(first tCInvoiceBank) and tCInvoiceBank.BankNumber_ID <> 0 and tCInvoiceBank.BankNumber_ID <> ? and tCInvoiceBank.CInvoiceBank_ID <> 0 and tCInvoiceBank.CInvoiceBank_ID <> ? then do: if not vlStartBankNrPayCodeForCIDef then do: <Q-37 run BankNumberPayCodeForCIDefSupp (Start) in BBankNumber> assign vlStartBankNrPayCodeForCIDef = true. end. /* end not vlStartBankNrPayCodeForCIDef */ <Q-19 run BankNumberPayCodeForCIDefSupp (all) (Read) (Cache) (input tCInvoiceBank.BankNumber_ID, (BankNumberId) output dataset tqBankNumberPayCodeForCIDefSupp) in BBankNumber> for each tqBankNumberPayCodeForCIDefSupp where tqBankNumberPayCodeForCIDefSupp.tiBankNumber_ID = tCInvoiceBank.BankNumber_ID: <M-20 run AddDetailLine (input 'CInvoiceBankPayCode':U (icTable), input tCInvoiceBank.tc_Rowid (icParentRowid), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or oiReturnStatus = 0 then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. assign tCInvoiceBankPayCode.CInvoiceBank_ID = tCInvoiceBank.CInvoiceBank_ID tCInvoiceBankPayCode.PayFormatCode_ID = tqBankNumberPayCodeForCIDefSupp.tiPayFormatCode_ID tCInvoiceBankPayCode.PayFormatGroup_ID = tqBankNumberPayCodeForCIDefSupp.tiPayFormatGroup_ID tCInvoiceBankPayCode.CInvoiceBankPayCodeValue = (if tqBankNumberPayCodeForCIDefSupp.tcBankNumberPayCodeValue <> ? and tqBankNumberPayCodeForCIDefSupp.tcBankNumberPayCodeValue <> "":U then tqBankNumberPayCodeForCIDefSupp.tcBankNumberPayCodeValue else tqBankNumberPayCodeForCIDefSupp.tcPayFormatCode) tCInvoiceBankPayCode.tcPayFormatGroupCode = tqBankNumberPayCodeForCIDefSupp.tcPayFormatGroupCode tCInvoiceBankPayCode.tcPayFormatGroupDescription = tqBankNumberPayCodeForCIDefSupp.tcPayFormatGroupDescription tCInvoiceBankPayCode.tlPayFormatGroupIsMandatory = tqBankNumberPayCodeForCIDefSupp.tlPayFormatGroupIsMandatory tCInvoiceBankPayCode.tcPayFormatGroupInputOption = tqBankNumberPayCodeForCIDefSupp.tcPayFormatGroupInputOption tCInvoiceBankPayCode.tcPayFormatGroupDataType = tqBankNumberPayCodeForCIDefSupp.tcPayFormatGroupDataType. if tCInvoiceBankPayCode.tcPayFormatGroupDataType = {&PAYFORMATGROUPDATATYPE-LOGICAL} and (tCInvoiceBankPayCode.CInvoiceBankPayCodeValue = ? or tCInvoiceBankPayCode.CInvoiceBankPayCodeValue = "":U) then assign tCInvoiceBankPayCode.CInvoiceBankPayCodeValue = "false":U. end. /* end for each tqBankNumberPayCodeForCIDefSupp ... */ end. /* end can-find(first tCInvoiceBank) and ... */ /* VAT currency rate - VAT currency itself is defaulted in IntialValues */ <M-13 run GetVatExchangeRate (input tCInvoice.Company_ID (iiCompanyID), input tCInvoice.tcCurrencyCode (icCInvoiceCurrencyCode), input tCInvoice.tcVatCurrencyCode (icOwnVatCurrencyCode), input tCInvoice.CInvoiceExchangeRate (idCInvoiceExchangeRate), input tCInvoice.CinvoiceRateScale (idCInvoiceRateScale), input tCInvoice.CInvoiceCurrency_ID (iiCInvoiceCurrencyId), input tCInvoice.VatCurrency_ID (iiOwnVatCurrencyId), input tCInvoice.CInvoiceTaxPointDate (itTaxPointDate), output tCInvoice.CInvoiceVatExchangeRate (odVatExchangeRate), output tCInvoice.CInvoiceVatRateScale (odVatRateScale), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. /* If field tOpenBalanceCI.tcBLWIGroupCode is set to SKIPGTMCALLFORNONTAXOPENBAL and the invoice is non-taxable */ /* then we just look for the non-taxable VAT of the domain and create CInvoiceVat ourself */ /* else we call DefaultValuesTax that will create all required data after calling GTM */ /* This was implemented to increase the performance for opening-balances (as they are always non-taxable) */ if tOpenBalanceCI.tcBLWIGroupCode = {&SKIPGTMCALLFORNONTAXOPENBAL} and tCInvoice.CInvoiceIsTaxable = false and tCInvoice.Company_ID <> 0 and tCInvoice.Company_ID <> ? then do : /* Find the domain of the invoice */ if tCInvoice.Company_ID = viCompanyID then assign vcDomainCodeOfCInvoice = vcDomainCode. else do : <Q-86 run CompanyByCompanyIdCode (all) (Read) (Cache) (input tCInvoice.Company_ID, (CompanyId) input ?, (CompanyCode) output dataset tqCompanyByCompanyIdCode) in BCompany> Find tqCompanyByCompanyIdCode where tqCompanyByCompanyIdCode.tiCompany_ID = tCInvoice.Company_ID no-lock no-error. if not available tqCompanyByCompanyIdCode then do : assign vcMessage = trim(substitute(#T-746'Unable to find the Domain based upon the ID of the Company (&1) of the Invoice':250(211246318)T-746#,tCInvoice.Company_ID)) oiReturnStatus = -1. <M-48 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-813459':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> leave CREATEBLOCK. end. /* if not available tqCompanyByCompanyIdCode */ assign vcDomainCodeOfCInvoice = tqCompanyByCompanyIdCode.tcDomainCode. end. /* Not if tCInvoice.Company_ID = viCompanyID */ /* Remove any taxes that were already on the invoice */ for each tCInvoiceVat where tCInvoiceVat.tc_ParentRowid = tCInvoice.tc_Rowid : if tCInvoiceVat.tc_Status = "N":U then delete tCInvoiceVat. else assign tCInvoiceVat.tc_Status = "D":U. end. /* for each tCInvoiceVat where */ /* Query the non-taxable VAT of the domain used for output */ <Q-56 run VATPrim (all) (Read) (Cache) (input ?, (VatId) input '00000000':U, (VatCode) input ?, (DomainId) input vcDomainCode, (DomainCode) input {&VATINOUT-INPUT}, (VatInOut) output dataset tqVATPrim) in BVAT> for first tqVATPrim where tqVATPrim.tcVatCode = "00000000":U and tqVATPrim.tcVatInOut = {&VATINOUT-INPUT} and tqVATPrim.tcDomainCode = vcDomainCode no-lock : /* Create a tCInvoiceVat with all default values */ <M-46 run AddDetailLine (input 'CInvoiceVat':U (icTable), input tCInvoice.tc_Rowid (icParentRowid), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. assign tCInvoiceVat.tcVatCode = tqVATPrim.tcVatCode tCInvoiceVat.tcDomainCode = tqVATPrim.tcDomainCode tCInvoiceVat.tcVatInOut = tqVATPrim.tcVatInOut tCInvoiceVat.tcNormalTaxGLCode = "":U tCInvoiceVat.tcNormalTaxDivisionCode = "":U tCInvoiceVat.tcAbsRetTaxGLCode = "":U tCInvoiceVat.tcAbsRetTaxDivisionCode = "":U tCInvoiceVat.CInvoiceVatIsTaxable = tCInvoice.CInvoiceIsTaxable tCInvoiceVat.CInvoiceVatSequence = 1 tCInvoiceVat.CInvoiceVatUILinkedRowID = "0":U tCInvoiceVat.CInvoiceVatVatBaseDebitLC = 0 tCInvoiceVat.CInvoiceVatVatBaseDebitTC = 0 tCInvoiceVat.CInvoiceVatVatBaseCreditLC = 0 tCInvoiceVat.CInvoiceVatVatBaseCreditTC = 0 tCInvoiceVat.CInvoiceVatVatBaseDebitCC = 0 tCInvoiceVat.CInvoiceVatVatBaseCreditCC = 0 tCInvoiceVat.CInvoiceVatNTBaseDebitTC = 0 tCInvoiceVat.CInvoiceVatNTBaseCreditTC = 0 tCInvoiceVat.CInvoiceVatVatDebitTC = 0 tCInvoiceVat.CInvoiceVatVatDebitLC = 0 tCInvoiceVat.CInvoiceVatVatCreditTC = 0 tCInvoiceVat.CInvoiceVatVatCreditLC = 0 tCInvoiceVat.CInvoiceVatIsUpdAllow = false tCInvoiceVat.CInvoiceVatIsAbsRet = false tCInvoiceVat.CInvoiceVatIsAccrRcpUs = false tCInvoiceVat.CInvoiceVatIsRevCharge = false tCInvoiceVat.CInvoiceVatTaxTrType = {&VATTAXTRANSACTIONTYPE-APVOUCHER} tCInvoiceVat.TxtyTaxType = {&VATTAXTYPE-NONTAX} tCInvoiceVat.TxenvTaxEnv = "":U tCInvoiceVat.TxclTaxCls = "":U tCInvoiceVat.TxuTaxUsage = "":U. end. /* for first tqVATPrim where */ end. /* if tOpenBalanceCI.tcBLWIGroupCode = {&SKIPGTMCALLFORNONTAXOPENBAL} and */ else do : <M-17 run DefaultValuesTax (input tCInvoice.tc_Rowid (icCInvoiceRowid), input tCInvoice.CInvoice_ID (iiCInvoiceId), input tCInvoice.tcCurrencyCode (icCurrencyCode), input tCInvoice.CInvoiceVoucher (icDocumentReference), input tCInvoice.CInvoiceTaxPointDate (itTaxPointDate), input tqCreditorByCreditor.tcTxzTaxZone (icShipFromTaxZone), input tCInvoice.tcShipToTaxZone (icShipToTaxZone), input tqCreditorByCreditor.tcTxclTaxCls (icTxclTaxClass), input tqCreditorByCreditor.tcTxuTaxUsage (icTxuTaxUsage), input if tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICE} then tCInvoice.CInvoiceOriginalCreditTC else if tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTE} then tCInvoice.CInvoiceOriginalDebitTC else 0 (idInvoiceAmountTC), input tCInvoice.CInvoiceExchangeRate (idExchangeRate), input tCInvoice.CInvoiceRateScale (idExchangeRateScale), input tCInvoice.tcNormalPaymentConditionCode (icPaymentConditionCode), input tCInvoice.CInvoicePostingDate (itPostingDate), input false (ilTaxable), input tCInvoice.CInvoiceIsWHT (ilCreditorIsWht), input tCInvoice.CInvoiceType (icInvoiceType), input ? (ilShipToAddressIsTaxInCity), input tCInvoice.CInvoiceVatExchangeRate (idVatExchangeRate), input tCInvoice.CInvoiceVatRateScale (idVatRateScale), input tCInvoice.CInvoiceIsLogisticMatching (ilIsLogisticMatching), output vcDummy (ocTxenvTaxEnv), input tCInvoice.CInvoiceIsTaxExcluded (ilCInvoiceIsTaxExcluded), input tCInvoice.CInvoiceDate (itCInvoiceDate), input tCInvoice.CInvoiceCCRate (idCCExchangeRate), input tCInvoice.CInvoiceCCScale (idCCExchangeRateScale), input tCInvoice.tiShipToAddressId (iiShipToAddressID), input tqCreditorByCreditor.tiAddress_ID (iiShipFromAddressID), input tCInvoice.tcCreditorCode (icCreditorCode), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. end. /* Not if tOpenBalanceCI.tcBLWIGroupCode = {&SKIPGTMCALLFORNONTAXOPENBAL} and */ /* Update payment details of the invoice including staged payment */ <M-51 run CreateCInvoicesPayment (output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or viFcReturnSuper > 0 and oiReturnStatus = 0 then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. /* ci posting */ if tCInvoice.CInvoiceIsInitialStatus <> true then do: <M-79 run CreateCInvoicesGLAccount (input tCInvoice.tcControlGLCode (icGLCode), input ? (iiDivisionId), input-output tCInvoice.tcDivisionCode (bcDivisionCode), input ? (iiCostCentreId), input-output tCInvoice.tcCostCentreCode (bcCostCentreCode), input ? (iiProjectId), input-output tCInvoice.tcProjectCode (bcProjectCode), input tCInvoice.CInvoiceType (icCInvoiceType), input tqCreditorByCreditor.tiInvControlGLProfile_ID (iiInvControlGLProfileId), input tqCreditorByCreditor.tiCnControlGLProfile_ID (iiCnControlGLProfileId), input tqCreditorByCreditor.tiPrePayControlGLProfile_ID (iiPrePayControlGLProfileId), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. /* i don't use it but i have to give it as input parameter so i make it empty first */ assign viRepeatingPostingID = iiPostingId. /* to make sure that in case iiPostingId = 0, it stays 0 after the first run */ <M-11 run CreateCIPosting (input tCInvoice.CInvoice_ID (iiCInvoiceId), input tOpenBalanceCI.tiPeriodYear (iiPeriodYear), input tOpenBalanceCI.tiPeriodPeriod (iiPeriodPeriod), input tOpenBalanceCI.ttPostingDate (itPostingDate), input tqCreditorByCreditor.tiCreditor_ID (iiCreditorId), input tOpenBalanceCI.tcCreditorCode (icCreditorCode), input tOpenBalanceCI.tcInvoiceType (icCInvoiceType), input if tOpenBalanceCI.tcTransferAccountDivisionCode = '':U then tOpenBalanceCI.tcDivisionCode else tOpenBalanceCI.tcTransferAccountDivisionCode (icDivisionCode), input tOpenBalanceCI.tcJournalCode (icJournalCode), input tOpenBalanceCI.tiInvoiceVoucher (iiVoucher), input tOpenBalanceCI.ttInvoiceTaxPointDate (itTaxPointDate), input tOpenBalanceCI.tcInvoiceReference (icReference), input tOpenBalanceCI.tcInvoiceDescription (icDescription), input tOpenBalanceCI.tdInvoiceAmountTC (idInvoiceAmountTC), input tOpenBalanceCI.tdInvoiceAmountLC (idInvoiceAmountLC), input tOpenBalanceCI.tdInvoiceAmountCC (idInvoiceAmountCC), input tOpenBalanceCI.tcTCCurrencyCode (icCurrencyCode), input tOpenBalanceCI.tdExchangeRateTCLC (idExchangeRate), input (if tOpenBalanceCI.tdExchangeRateScale = 0 then 1 else tOpenBalanceCI.tdExchangeRateScale) (idExchangeRateScale), input tOpenBalanceCI.tcPostingText (icCIText), input tOpenBalanceCI.tcPostingType (icPostingType), input tOpenBalanceCI.tcTransferAccountGLCode (icGlCode), input if tOpenBalanceCI.tcTransferAccountCostCentreCode = '':U then tOpenBalanceCI.tcCostCentreCode else tOpenBalanceCI.tcTransferAccountCostCentreCode (icCostCentreCode), input if tOpenBalanceCI.tcTransferAccountProjectCode = '':U then tOpenBalanceCI.tcProjectCode else tOpenBalanceCI.tcTransferAccountProjectCode (icProjectCode), input tOpenBalanceCI.tlOnlyControlAccount (ilOnlyControlAccount), input '':U (icShipToCountryCode), input '':U (icTxclTaxCls), input '':U (icTxuTaxUsage), input '':U (icTxenvTaxEnv), input '':U (icPaymentCondition), input ? (ilIsTaxInCityFromShipTo), input '':U (icPoNbr), input ? (ilIsTaxable), input tCInvoice.tcCostCentreCode (icControlCostCentreCode), input tCInvoice.tcProjectCode (icControlProjectCode), input 0 (iiShipFromAddressId), input 0 (iiShipToAddressId), input false (ilIsLogisticMatching), input true (ilGetDefaultSafs), input tqCreditorByCreditor.tcBusinessRelationCode (icBusinessRelationCode), input tqCreditorByCreditor.tiPrePayControlGLProfile_ID (iiPrePayControlGLProfileId), input tqCreditorByCreditor.tiInvControlGLProfile_ID (iiInvControlGLProfileId), input tqCreditorByCreditor.tiCnControlGLProfile_ID (iiCnControlGLProfileId), input tCInvoice.tc_Rowid (icCInvoiceRowid), input if tqCreditorByCreditor.tlBusinessRelationIsInterco then tqCreditorByCreditor.tcBusinessRelationICCode else '':U (icBusinessRelationInterCoCode), input tqCreditorByCreditor.tcCountryCode (icShipFromCountryCode), input tqCreditorByCreditor.tlCountryIsEUCountry (ilShipFromCountryIsEUCountry), input tqCreditorByCreditor.tcTxzTaxZone (icCreditorTaxZone), input tCInvoice.CInvoiceIsTaxExcluded (ilCInvoiceIsTaxExcluded), input ? (ilIsInitialStatus), input-output tCInvoiceVat (tApiCInvoiceVat), input tDefaultSafsCI (tDefaultSafsCI), input yes (ilHandleCommunicationWithJE), input-output iiBJournalEntryId (biBJournalEntryId), input-output viRepeatingPostingID (biPostingId), input tOpenBalanceCI.tdExchangeRateTCCC (idExchangeRateCC), input tOpenBalanceCI.tdCCExchangeRateScale (idExchangeRateScaleCC), input tOpenBalanceCI.ttInvoiceDate (itInvoiceDate), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. end. /* of if tCInvoice.CInvoiceIsInitialStatus <> true */ /* /* XXS LBO 5.8.2004 */ if tCInvoice.CInvoiceType = {&INVOICETYPE-PREPAYMENT} then assign tCInvoice.CInvoiceAllocationStatus = {&ALLOCSTATUS-ALLOC} tCInvoice.CInvoiceIsLockPayment = false tCInvoice.CInvoiceIsInitialStatus = false tCInvoice.CInvoiceIsInvoiceApproved = true tCInvoice.tcReasonAllocationStatus = {&ALLOCSTATUS-NOALLOC}. /* XXE LBO 5.8.2004 */ */ /* Tackle the withholding taxes WHT: for every invoice - meaning each tOpenBalanceCI - there can only be a single WHT via this method although the normal UI of the CI support multiple WHTs to be specified per invoice */ /* This was a limitation to reduce the impact of extending the current SupplierOpeningBalance function for WHT - agreeed upon by BA's (IMH) */ if tOpenBalanceCI.tcVatCode <> "":U and tOpenBalanceCI.tcVatCode <> ? and ((tOpenBalanceCI.tdWHTFeeCreditTC <> 0 and tOpenBalanceCI.tdWHTFeeCreditTC <> ?) or (tOpenBalanceCI.tdWHTFeeDebitTC <> 0 and tOpenBalanceCI.tdWHTFeeDebitTC <> ?) or (tOpenBalanceCI.tdWHTExpenseCreditTC <> 0 and tOpenBalanceCI.tdWHTExpenseCreditTC <> ?) or (tOpenBalanceCI.tdWHTExpenseDebitTC <> 0 and tOpenBalanceCI.tdWHTExpenseDebitTC <> ?) ) then do : /* Create a CInvoiceWHT record */ <M-91 run AddDetailLine (input 'CInvoiceWHT':U (icTable), input tCInvoice.tc_rowid (icParentRowid), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. /* Copy the input into the new CInvoiceWHT record */ assign tCInvoiceWHT.tcVatCode = tOpenBalanceCI.tcVatCode tCInvoiceWHT.CInvoiceWHTFeeDebitTC = tOpenBalanceCI.tdWHTFeeDebitTC tCInvoiceWHT.CInvoiceWHTFeeCreditTC = tOpenBalanceCI.tdWHTFeeCreditTC tCInvoiceWHT.CInvoiceWHTExpenseDebitTC = tOpenBalanceCI.tdWHTExpenseDebitTC tCInvoiceWHT.CInvoiceWHTExpenseCreditTC = tOpenBalanceCI.tdWHTExpenseCreditTC. /* Default and copy the Domain and In-out of the WHT-code */ assign tCInvoiceWHT.tcVatInOut = (if tOpenBalanceCI.tcVatInOut <> "":U and tOpenBalanceCI.tcVatInOut <> ? then tOpenBalanceCI.tcVatInOut else {&VATINOUT-INPUT}) tCInvoiceWHT.tcDomainCode = (if tOpenBalanceCI.tcDomainCode <> "":U and tOpenBalanceCI.tcDomainCode <> ? then tOpenBalanceCI.tcDomainCode else vcDomainCode). /* Call the defaulting method that will fill in all WHT details based upon the VatCode (=WHTCode) and the Fee or Expense */ /* Note that some of the output parameters of this call will need to be chnaged when merging in FT293 with the Brasil-WHT into the trunk */ <M-61 run DefaultValuesWHTCode (input tCInvoice.tc_Rowid (icCInvoiceRowId), input tCInvoice.CInvoiceType (icCInvoiceType), input tCInvoiceWHT.tcVatCode (icWHTCode), input-output tCInvoiceWHT.CInvoiceWHTFeeDebitTC (bdCInvoiceWHTFeesDebitTC), input-output tCInvoiceWHT.CInvoiceWHTFeeCreditTC (bdCInvoiceWHTFeesCreditTC), input tCInvoice.tcCurrencyCode (icCInvoiceCurrencyCode), input tCInvoice.CInvoiceCurrency_ID (iiCInvoiceCurrencyId), input tCInvoice.CInvoiceExchangeRate (idCInvoiceExchangeRate), input tCInvoice.CInvoiceRateScale (idCInvoiceExchangeRateScale), input tCInvoice.CInvoicePostingDate (itCInvoicePostingDate), input tCInvoice.CInvoiceDate (itCInvoiceDate), output tCInvoiceWHT.CInvoiceWHTTaxType (ocTx2TaxType), output tCInvoiceWHT.tcVatDescription (ocTx2Desc), output tCInvoiceWHT.CInvoiceWHTTaxPct (odTx2TaxPct), output tCInvoiceWHT.CInvoiceWHTBaseTaxPct (odWHTBasePercentage), output tCInvoiceWHT.tcGLCode (ocWHTAcct), output tCInvoiceWHT.tcDivisionCode (ocWHTSubAcct), output tCInvoiceWHT.CInvoiceWHTTaxFeeDebitTC (odCInvoiceWHTTaxableFeesDebitTC), output tCInvoiceWHT.CInvoiceWHTTaxFeeCreditTC (odCInvoiceWHTTaxableFeesCreditTC), output tCInvoiceWHT.CInvoiceWHTTaxFeeDebitLC (odCInvoiceWHTTaxableFeesDebitLC), output tCInvoiceWHT.CInvoiceWHTTaxFeeCreditLC (odCInvoiceWHTTaxableFeesCreditLC), output tCInvoiceWHT.CInvoiceWHTTaxFeeDebitCC (odCInvoiceWHTTaxableFeesDebitCC), output tCInvoiceWHT.CInvoiceWHTTaxFeeCreditCC (odCInvoiceWHTTaxableFeesCreditCC), output tCInvoiceWHT.CInvoiceWHTAmtDebitTC (odCInvoiceWHTAmountDebitTC), output tCInvoiceWHT.CInvoiceWHTAmtCreditTC (odCInvoiceWHTAmountCreditTC), output tCInvoiceWHT.CInvoiceWHTAmtDebitLC (odCInvoiceWHTAmountDebitLC), output tCInvoiceWHT.CInvoiceWHTAmtCreditLC (odCInvoiceWHTAmountCreditLC), output tCInvoiceWHT.CInvoiceWHTAmtDebitCC (odCInvoiceWHTAmountDebitCC), output tCInvoiceWHT.CInvoiceWHTAmtCreditCC (odCInvoiceWHTAmountCreditCC), output tCInvoiceWHT.CInvoiceWHTIsUpdAllow (olWHTIsUpdAllow), output viFcReturnSuper (oiReturnStatus)) in BCInvoice> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave CREATEBLOCK. end. /* if tOpenBalanceCI.tcVatCode <> "":U and */ end. /* end for each tOpenBalanceCI */ END. /* end CREATEBLOCK */ if vlStartCreditorByCreditor then do: <Q-26 run CreditorByCreditor (Stop) in BCreditor > end. /* end vlStartCreditorByCreditor */ if vlStartReasonByIdCode then do: <Q-28 run ReasonByIdCode (Stop) in BReason > end. /* end vlStartReasonByIdCode */ if vlStartReasonByInitialStatus then do: <Q-30 run ReasonByInitialStatus (Stop) in BReason > end. /* end vlStartReasonByInitialStatus */ if vlStartCompanyPropByBusinessRel then do: <Q-32 run CompanyPropertyByBusinessRel (Stop) in BCompanyProperty > end. /* end vlStartCompanyPropByBusinessRel */ if vlStartAddrByAddrBusRelType then do: <Q-34 run AddressByAddressBusRelType (Stop) in BBusinessRelation > end. /* end vlStartAddrByAddrBusRelType */ if vlStartBankNrPayCodeForCIDef then do: <Q-38 run BankNumberPayCodeForCIDefSupp (Stop) in BBankNumber> end. /* end vlStartBankNrPayCodeForCIDef */ if vlStartSupplierForDaybookSet then do: <Q-49 run SupplierForDaybookSetSite (Stop) in BMfgSupplier > end. /* end vlStartSupplierForDaybookSet */