project QadFinancials > class BDInvoice > method StdMaintainTTWithIntPost
Description
create a di posting for the dinvoice records, WITHOUT ValidateBC, AddUpd and DataSave
Parameters
| icAction | input | character | |
| bcLstPrimKey | input-output | character | |
| bcLstRowId | input-output | character | |
| bcLstReturn | input-output | character | |
| olSaveAsDraft | output | logical | SaveAsDraft |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program7/bdinvoice.p)
/* Set default return status */
/* Empty used temp-tables */
assign oiReturnStatus = -98.
empty temp-table tDIOpenBalance.
/* Initialise: Validate the value for the Company */
/* Replace unknown values */
assign vlWarningsFound = false.
if tApiDInvoice.Company_ID <> 0 and tApiDInvoice.Company_ID <> ? and tApiDInvoice.Company_ID <> viCompanyId
then do:
assign vcMessage = trim(substitute(#T-73'The entity of the customer invoice (&1) must match the current entity (&2).':255(14472)T-73#, string(tApiDInvoice.Company_ID),string(viCompanyId)))
oiReturnStatus = -1
bcLstReturn = bcLstReturn + chr(4) + string(-1)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U
vlSaveAsDraft = false.
<M-56 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-7172':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
Return.
end. /* if tApiDInvoice.Company_ID <> 0 and */
assign tDInvoice.Company_ID = viCompanyId.
if tApiDInvoice.Debtor_ID = ? then assign tApiDInvoice.Debtor_ID = 0.
if tApiDInvoice.tcDebtorCode = ? then assign tApiDInvoice.tcDebtorCode = "":U.
if tApiDInvoice.DInvoiceType = ? then assign tApiDInvoice.DInvoiceType = "":U.
/* Create tOpenBalance record that will be used for a call to a submethod */
create tDIOpenBalance.
assign tDIOpenBalance.tiCompanyId = tApiDInvoice.Company_ID
tDIOpenBalance.tcAction = icAction
tDIOpenBalance.tcDebtorCode = tApiDInvoice.tcDebtorCode
tDIOpenBalance.tcInvoiceType = tApiDInvoice.DInvoiceType
tDIOpenBalance.tiPeriodYear = tApiDInvoice.DInvoicePostingYear
tDIOpenBalance.tiPeriodPeriod = tApiDInvoice.DInvoicePostingPeriod
tDIOpenBalance.tcJournalCode = tApiDInvoice.tcJournalCode
tDIOpenBalance.tiInvoiceVoucher = tApiDInvoice.DInvoiceVoucher
tDIOpenBalance.ttInvoiceDate = tApiDInvoice.DInvoiceDate
tDIOpenBalance.ttPostingDate = tApiDInvoice.DInvoicePostingDate
tDIOpenBalance.tcPostingType = if tApiDInvoice.DInvoiceOriginalDebitTC <> 0 and tApiDInvoice.DInvoiceOriginalDebitTC <> ? then {&POSTINGTYPE-DEBIT} else {&POSTINGTYPE-CREDIT}
tDIOpenBalance.tcPostingText = trim(#T-71'Customer Invoice Import':150(49401)T-71#)
tDIOpenBalance.tdInvoiceAmountTC = if tApiDInvoice.DInvoiceOriginalDebitTC <> 0 and tApiDInvoice.DInvoiceOriginalDebitTC <> ? then tApiDInvoice.DInvoiceOriginalDebitTC else tApiDInvoice.DInvoiceOriginalCreditTC
tDIOpenBalance.tdInvoiceAmountLC = if tApiDInvoice.DInvoiceOriginalDebitLC <> 0 and tApiDInvoice.DInvoiceOriginalDebitLC <> ? then tApiDInvoice.DInvoiceOriginalDebitLC else tApiDInvoice.DInvoiceOriginalCreditLC
tDIOpenBalance.tdExchangeRateTCLC = tApiDInvoice.DInvoiceExchangeRate
tDIOpenBalance.tdExchangeRateScale = tApiDInvoice.DInvoiceRateScale
tDIOpenBalance.tcTCCurrencyCode = tApiDInvoice.tcCurrencyCode
tDIOpenBalance.ttInvoiceTaxPointDate = tApiDInvoice.DInvoicePostingDate
tDIOpenBalance.tcProjectCode = tApiDInvoice.tcProjectCode
tDIOpenBalance.tcReasonCode = tApiDInvoice.tcReasonCode
tDIOpenBalance.tcCostCentreCode = tApiDInvoice.tcCostCentreCode
tDIOpenBalance.tcInvoiceReference = trim(tDIOpenBalance.tcPostingText) + " (":U + trim(string(today)) + " - ":U + trim(string(tDIOpenBalance.tdInvoiceAmountTC)) + ")":U
tDIOpenBalance.tcInvoiceDescription = tDIOpenBalance.tcInvoiceReference
tDIOpenBalance.tcNormalPaymentConditionCode = tApiDInvoice.tcNormalPaymentConditionCode
tDIOpenBalance.tcKey = "KEY":U.
/* Get the Code of the current company (used te retrieve the VAT-defaults */
Assign
vcShipFromTaxZone = tApiDInvoice.tcShipFromTaxZone
vcShipFromCountryCode = tApiDInvoice.tcShipFromCountryCode
viShipFromAddressID = tApiDInvoice.ShipFromAddress_ID
vlShipFromIsEUCountry = tApiDInvoice.tlShipFromCountryIsEUCountry.
<Q-63 run CompanyPropertyByBusinessRel (first) (Read) (NoCache)
(input tDIOpenBalance.tiCompanyId, (CompanyId)
input ?, (AddressType)
output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty >
find first tqCompanyPropertyByBusinessRel no-error.
if available tqCompanyPropertyByBusinessRel
then do:
<Q-53 run VatNumberByIdBusRelCntryVat (first) (Read) (NoCache)
(input ?, (BusinessRelationId)
input ?, (IdentityCountryId)
input ?, (IdentityCountryCode)
input tqCompanyPropertyByBusinessRel.tcVatNumberIdentity, (VatNumberIdentity)
input tqCompanyPropertyByBusinessRel.tiVatNumber_ID, (VatNumberId)
input ?, (VatNumberIsActive)
output dataset tqVatNumberByIdBusRelCntryVat) in BBusinessRelation >
find first tqVatNumberByIdBusRelCntryVat no-error.
assign vcCompanyAVRCode = if available tqVatNumberByIdBusRelCntryVat then tqVatNumberByIdBusRelCntryVat.tcBusinessRelationAVRCode else "":U
vcShipFromTaxZone = tqCompanyPropertyByBusinessRel.tcTxzTaxZone when vcShipFromTaxZone = "":U or vcShipFromTaxZone = ?
vcShipFromCountryCode = tqCompanyPropertyByBusinessRel.tcAddressCountryCode when vcShipFromCountryCode = "":U or vcShipFromCountryCode = ?
viShipFromAddressID = tqCompanyPropertyByBusinessRel.tiAddress_ID when viShipFromAddressID = 0 or viShipFromAddressID = ?
vlShipFromIsEUCountry = tqCompanyPropertyByBusinessRel.tlIdentityIsEUCountry when vlShipFromIsEUCountry = ?.
end. /* if available tqCompanyPropertyByBusinessRel */
/* Get some values from the debtor */
assign vcShipToCountryCode = tApiDInvoice.tcShipToCountryCode.
if tApiDInvoice.Company_ID <> 0 and tApiDInvoice.Company_ID <> ? and
tApiDInvoice.tcDebtorCode <> "":U and tApiDInvoice.tcDebtorCode <> ?
then do:
<Q-58 run DebtorByDebtor (first) (Read) (NoCache)
(input tApiDInvoice.Company_ID, (CompanyId)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
input tApiDInvoice.Debtor_ID, (DebtorId)
input ?, (DebtorCode)
output dataset tqDebtorByDebtor) in BDebtor >
find first tqDebtorByDebtor no-error.
if available tqDebtorByDebtor
then do:
assign tDIOpenBalance.tcBusinessRelationCode = tqDebtorByDebtor.tcBusinessRelationCode
vcVatDeliveryType = tqDebtorByDebtor.tcVatDeliveryType
vcVatPercentageLevel = tqDebtorByDebtor.tcVatPercentageLevel
vcTxclTaxClass = tqDebtorByDebtor.tcTxclTaxCls
vcTxuTaxUsage = tqDebtorByDebtor.tcTxuTaxUsage
vcDebtorCode = tqDebtorByDebtor.tcDebtorCode
vlAddressIsTaxInCity = tqDebtorByDebtor.tlAddressIsTaxInCity
vcShipToTaxZone = tqDebtorByDebtor.tcAddressTxzTaxZone
viShipToAddressID = tqDebtorByDebtor.tiAddress_ID
vcShipToCountryCode = tqDebtorByDebtor.tcCountryCode when vcShipToCountryCode = "":U or vcShipToCountryCode = ?
vlShipToIsEUCountry = tqDebtorByDebtor.tlCountryIsEUCountry
vcDebtorTaxZone = tqDebtorByDebtor.tcTxzTaxZone.
/* Get AVRCode */
<Q-59 run AddressByAddressBusRelType (all) (Read) (NoCache)
(input ?, (AddressTypeId)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
input tqDebtorByDebtor.tiBusinessRelation_ID, (BusinessRelationId)
input tqDebtorByDebtor.tcBusinessRelationCode, (BusinessRelationCode)
input ?, (AddressId)
output dataset tqAddressByAddressBusRelType) in BBusinessRelation >
find first tqAddressByAddressBusRelType no-error.
if available tqAddressByAddressBusRelType
then assign vcDebtorAVRCode = tqAddressByAddressBusRelType.tcBusinessRelationAVRCode.
/* Get division */
if tqDebtorByDebtor.tiDivisionProfile_ID <> ? and tqDebtorByDebtor.tiDivisionProfile_ID <> 0
then do:
<Q-60 run GetDivisionFromProfile (all) (Read) (NoCache)
(input tApiDInvoice.Company_ID, (CompanyId)
input tqDebtorByDebtor.tiDivisionProfile_ID, (DivisionProfileId)
output dataset tqDivisionFromProfile) in BProfile >
find first tqDivisionFromProfile no-error.
if available tqDivisionFromProfile
then assign tDIOpenBalance.tcDivisionCode = tqDivisionFromProfile.tcDivisionCode.
end. /* if tqDebtorByDebtor.tiDivisionProfile_ID <> ? and tqDebtorByDebtor.tiDivisionProfile_ID <> 0 */
/* Get the Payment-conditions from the Debtor */
if tApiDInvoice.tcNormalPaymentConditionCode = "":U or tApiDInvoice.tcNormalPaymentConditionCode = ?
then assign tDIOpenBalance.tcNormalPaymentConditionCode = (if tDIOpenBalance.tcNormalPaymentConditionCode = "":U or tDIOpenBalance.tcNormalPaymentConditionCode = ? then tqDebtorByDebtor.tcNormalPaymentConditionCode else tDIOpenBalance.tcNormalPaymentConditionCode).
/* Get the bank information if the debtor uses directdebit payment instruments */
assign vhFcComponent = ?.
<M-57 run GetParentBankData
(input viCompanyID (iiCompanyID),
input ? (icCreditorCode),
input tqDebtorByDebtor.tcDebtorCode (icDebtorCode),
input {&PAYFORMATPAYINSTRUMENT-DIRECTDEBIT} (icPaymentInstrument),
output tDIOpenBalance.tiBankNumber_ID (oiBankNumberID),
output tDIOpenBalance.tcBankNumber (ocBankNumber),
output tDIOpenBalance.tcBankNumberExtension (ocBankNumberExtension),
input ? (icOwnBankNumber),
input ? (icGLCode),
output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end. /* if oiReturnStatus < 0 */
else assign vlWarningsFound = true.
end. /* if viFcReturnSuper <> 0 */
end. /* if available tqDebtorByDebtor */
end. /* if tApiDInvoice.Company_ID <> 0 */
/* Calculate due dates */
<M-48 run ApiStdMaintainTTWithIntPostDates
(output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end. /* if oiReturnStatus < 0 */
else assign vlWarningsFound = true.
end. /* if viFcReturnSuper <> 0 */
/* Call a submethod that will create the debtor invoices */
/* Result: DInvoice, DInvoicePosting and DInvoiceMovement records created */
<M-50 run CreateDInvoices
(input-output tDIOpenBalance (tDIOpenBalance),
input 0 (iiBJournalEntryId),
input 0 (iiPostingId),
output vcListNewInvoices (ocNewRecordInfo),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end. /* if oiReturnStatus < 0 */
else assign vlWarningsFound = true.
end. /* if viFcReturnSuper <> 0 */
/* Search the debtor invoice that you have just created */
assign viListNewInvoices = integer(entry(2,vcListNewInvoices)) no-error.
if error-status:error = false
then find first tDInvoice where
tDInvoice.DInvoice_ID = viListNewInvoices
no-error.
if error-status:error = true or
not available tDInvoice
then do:
assign vcMessage = trim(substitute(#T-69'A customer invoice integration error ocurred. The call to method '&1' (method that initiates the invoice) returned unexpected information.':255(14496)T-69#, "CreateDInvoices":U)) + chr(10) +
trim(substitute(#T-70'Data returned: &1.':255(14497)T-70#,viListNewInvoices))
oiReturnStatus = -1
bcLstReturn = bcLstReturn + chr(4) + string(-1)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U
vlSaveAsDraft = false.
if error-status:error = true and
error-status:num-messages >= 1
then assign vcMessage = vcMessage + chr(10) + ERROR-STATUS:GET-MESSAGE(1).
<M-67 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-7173':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
Return.
end. /* if error-status:error = true or */
/* Copy all data into the new cinvoice */
/* Before continuing, we copy the primary-key-fields of the main table to the input parameters */
/* This is just to hold it there so it can be assigned to ocPrimKey if the save succeeds. This */
/* is done because tDInvoice is no longer available after the save. We use ocRowid in stead */
assign vcDInvoiceRowId = tDInvoice.tc_Rowid
vcCommitNumber = vcCommitNumber + ",":U + tDInvoice.tc_Rowid
tDInvoice.tcReasonCode = tApiDInvoice.tcReasonCode
tApiDInvoice.DInvoice_ID = tDInvoice.DInvoice_ID.
<Q-64 run CurrencyByCode (all) (Read) (NoCache)
(input tDInvoice.tcCurrencyCode, (CurrencyCode)
output dataset tqCurrencyByCode) in BCurrency >
find first tqCurrencyByCode no-error.
/* Call a submethod that will create the DInvoiceVat record */
<M-61 run DefaultValuesTax
(input tDInvoice.DInvoice_ID (iiDinvoiceId),
input tDInvoice.tcCurrencyCode (icCurrencyCode),
input tDInvoice.DInvoiceVoucher (icDocumentReference),
input tDInvoice.DInvoiceTaxPointDate (itTaxPointDate),
input vcShipFromTaxZone (icShipFromTaxZone),
input vcShipToTaxZone (icShipToTaxZone),
input tDInvoice.tcDebtorCode (icDebtorCode),
input vcTxclTaxClass (icTxclTaxClass),
input vcTxuTaxUsage (icTxuTaxUsage),
input if tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} then tDInvoice.DInvoiceOriginalDebitTC else if tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTE} then tDInvoice.DInvoiceOriginalCreditTC else 0 (idInvoiceAmountTC),
input tDInvoice.DInvoiceExchangeRate (idExchangeRate),
input tDInvoice.DInvoiceRateScale (idExchangeRateScale),
input tDInvoice.tcNormalPaymentConditionCode (icPaymentConditionCode),
input tDInvoice.DInvoicePostingDate (itPostingDate),
input tDInvoice.DInvoiceIsTaxable (ilTaxable),
input tDInvoice.DInvoiceIsTaxExcluded (ilDInvoiceIsTaxExcluded),
input tDInvoice.DInvoiceType (icInvoiceType),
input ? (ilShipToAddressIsTaxInCity),
input tDInvoice.DInvoiceVatExchangeRate (idVatExchangeRate),
input tDInvoice.DInvoiceVatRateScale (idVatRateScale),
input tDInvoice.DInvoiceCCRate (idCCExchangeRate),
input tDInvoice.DInvoiceCCScale (idCCExchangeRateScale),
input viShipToAddressID (iiShipToAddressID),
input viShipFromAddressID (iiShipFromAddressID),
output vcTaxEnv (ocTxenvTaxEnv),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign vcMessage = trim(substitute(#T-74'An error (&1) occurred when saving the tax details of the new customer invoices. See other messages for further details.':255(1802)T-74#,string(viFcReturnSuper)))
olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
<M-68 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-7174':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end. /* if oiReturnStatus < 0 */
else assign vlWarningsFound = true.
end. /* if viFcReturnSuper <> 0 */
/* Call a submethod that will create the PostingVat records */
find first tDInvoicePosting where
tDInvoicePosting.DInvoice_ID = tDInvoice.DInvoice_ID
no-error.
if available tdinvoiceposting and
(tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTE})
then do:
empty temp-table tDIAccount.
assign vcPostingTcRowid = "":U
vdAmountTC = if tdinvoice.dinvoicetype = {&INVOICETYPE-INVOICE} or tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then tDInvoice.DInvoiceOriginalDebitTC else if tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTE} or tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} then tDInvoice.DInvoiceOriginalCreditTC else 0
vdAmountLC = if tdinvoice.dinvoicetype = {&INVOICETYPE-INVOICE} or tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then tDInvoice.DInvoiceOriginalDebitLC else if tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTE} or tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} then tDInvoice.DInvoiceOriginalCreditLC else 0
vdAmountCC = if tdinvoice.dinvoicetype = {&INVOICETYPE-INVOICE} or tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then tDInvoice.DInvoiceOriginalDebitCC else if tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTE} or tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} then tDInvoice.DInvoiceOriginalCreditCC else 0
vdDebitAmountTC = if tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then 0 else vdAmountTC
vdCreditAmountTC = if tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then vdAmountTC else 0.
if viBJournalEntryDIID <> 0
then do:
if valid-handle(vhBJournalEntryDIInst) = false
then do:
<I-62 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
end. /* if valid-handle(vhBJournalEntryDIInst) = false */
<M-49 run PassRowIdBasedOnPostingIdInInstance
(input tDInvoicePosting.Posting_ID (iiPostingId),
output vcPostingTcRowid (ocPostingRowId),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
end. /* if viBJournalEntryDIID <> 0 */
assign viControlGLProfileId = if tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then tqDebtorByDebtor.tiInvControlGLProfile_ID else tqDebtorByDebtor.tiCnControlGLProfile_ID .
<Q-66 run ProfileLinkByGL (all) (Read) (NoCache)
(input viControlGLProfileId, (GlProfileId)
input viCompanyId, (CompanyId)
output dataset tqProfileLinkByGL) in BProfile >
find first tqProfileLinkByGL no-error.
<M-65 run CreateDIPostingTax
(input vcPostingTcRowid (icRowId),
input tDInvoicePosting.Posting_ID (iiPostingId),
input tDInvoice.DInvoiceTaxPointDate (itTaxPointDate),
input tDInvoice.DInvoiceDIText (icDIText),
input tDInvoice.tcCurrencyCode (icCurrencyCode),
input tDInvoice.DInvoiceCurrency_ID (iiCurrencyId),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType),
input tDInvoice.DInvoiceExchangeRate (idExchangeRate),
input tDInvoice.DInvoiceRateScale (idExchangeRateScale),
input vdDebitAmountTC (idVatFullDebitTC),
input vdCreditAmountTC (idVatFullCreditTC),
input (if tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} then {&POSTINGTYPE-DEBIT} else if tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTE} then {&POSTINGTYPE-CREDIT} else '':U) (icDInvoiceType),
input tDInvoice.tcDivisionCode (icDivisionCode),
input tDInvoice.tcVatCurrencyCode (icVatCurrencyCode),
input tDInvoice.VatCurrency_ID (iiVatCurrencyId),
input tDInvoice.DInvoiceVatExchangeRate (idVatExchangeRate),
input tDInvoice.DInvoiceVatRateScale (idVatExchangeRateScale),
input vcShipFromCountryCode (icShipFromCountryCode),
input vcShipToCountryCode (icShipToCountryCode),
input vlShipFromIsEUCountry (ilShipFromCountryIsEUCountry),
input vlShipToIsEUCountry (ilShipToCountryIsEUCountry),
input vcTxclTaxClass (icTxclTaxCls),
input vcTxuTaxUsage (icTxuTaxUsage),
input vcShipFromTaxZone (icShipFromTaxZone),
input vcShipToTaxZone (icShipToTxzTaxZone),
input ? (icTxenvTaxEnv),
input tDInvoice.DInvoiceVoucher (iiVoucher),
input tDInvoice.tcNormalPaymentConditionCode (icPaymentCondition),
input vlIsCompanyTaxInCity (ilIsTaxInCityFromShipTo),
input if available tqProfileLinkByGL then tqprofileLinkByGL.tcGLCode else ? (icControlGLCode),
input tDInvoice.Debtor_ID (iiMasterId),
input tDInvoice.DInvoice_ID (iiTransactionId),
input tDInvoice.DInvoiceIsTaxable (ilIsTaxable),
input tDInvoice.tcCostCentreCode (icCostCentreCode),
input tDInvoice.tcProjectCode (icProjectCode),
input ? (iiShipFromAddressId),
input ? (iiShipToAddressId),
input '' (icSoldToDebtorCode),
input 0 (idInvoiceAmountTC),
input ? (icShipFromTaxIDFeder),
input ? (icShipFromTaxIDState),
input ? (icShipFromTaxIDMisc1),
input ? (icShipFromTaxIDMisc2),
input ? (icShipFromTaxIDMisc3),
input ? (iiShipFromTaxDeclaration),
input ? (icShipToTaxIDFeder),
input ? (icShipToTaxIDState),
input ? (icShipToTaxIDMisc1),
input ? (icShipToTaxIDMisc2),
input ? (icShipToTaxIDMisc3),
input ? (iiShipToTaxDeclaration),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign vcMessage = trim(substitute(#T-72'An error (&1) occurred when saving the tax details of the new customer invoices. See other messages for further details.':255(1802)T-72#,string(viFcReturnSuper)))
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U
vlSaveAsDraft = icAction <> {&DAEMONACTION-SAVE}.
<M-51 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-7171':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
Return.
end. /* if oiReturnStatus < 0 */
else assign vlWarningsFound = true.
end. /* if viFcReturnSuper <> 0 */
end. /* if available tdinvoiceposting and */
/* This is where it ends if only SaveAsDraft is needed */
if vlSaveAsDraft
then do:
assign oiReturnStatus = -1
bcLstReturn = bcLstReturn + chr(4) + "-1":U
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
Return.
end. /* if vlSaveAsDraft */
/* Indicate that everything was saved correctly */
/* Set return status = OK */
assign bcLstReturn = bcLstReturn + chr(4) + (if vlWarningsFound = true then "1":U else "0":U)
bcLstPrimKey = bcLstPrimKey + chr(4) + string(tApiDInvoice.DInvoice_ID)
bcLstRowid = bcLstRowid + chr(4) + vcDInvoiceRowId
oiReturnStatus = (if vlWarningsFound = true then 1 else 0).