project QadFinancials > class BCInvoice > method ApiStdMaintainTTWithExtPost
Description
This method is a submethod of ApiStdMaintainTT.
This method copies the table, makes no ci/mf posting
Parameters
icAction | input | character | This parameter defines what should happen with the input data : -SAVE: Save the data if there were no errors, -SAVESTORE : Save the data if there were no errors. If there were errors, save as draft. -STORE : Save the data as draft -VALIDATE : Validate the input data, but do no save the data. |
bcLstReturn | input-output | character | Char 4 separated list with the return status of the newly created main-table records. Zero means not errors occurred. |
bcLstPrimKey | input-output | character | Character 4 separated list with the primary keys of the newly created main-table records. The fields of the primary key are separated with Character 2. |
bcLstRowId | input-output | character | Char 4 separated list with the temporarely rowids (negative for new ones) of the newly created main-table records. |
olSaveAsDraft | output | logical | Save As Draft |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bcinvoice.p)
assign oiReturnStatus = -98.
TRY: do:
/* Initialise and Create new instance */
/* Validate the value for the Company */
assign vlWarningsFound = false.
<M-14 run DataNew (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
if viFcReturnSuper >= 0 then do:
<M-56 run SetRowidConvert
(input tApiCInvoice.tc_Rowid (icOldRowid),
input tCInvoice.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end.
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
else if viFcReturnSuper < 0 then leave TRY.
if tApiCInvoice.Company_ID <> 0 and
tApiCInvoice.Company_ID <> ? and
tApiCInvoice.Company_ID <> viCompanyId
then do :
assign oiReturnStatus = -1
bcLstReturn = bcLstReturn + chr(4) + string(-1)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U
vlSaveAsDraft = false.
<M-46 run SetMessage
(input trim(subst(#T-55'The entity of the supplier invoice (&1) should match the current entity (&2).':255(999890427)T-55#, string(tApiCInvoice.Company_ID),string(viCompanyId))) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tCInvoice.tc_Rowid (icRowid),
input 'QADFIN-3287':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
Return.
end.
assign tCInvoice.Company_ID = viCompanyId.
/* 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 tCInvoice is no longer available after the save. We use ocRowid in stead */
buffer-copy tApiCInvoice
except CInvoice_ID
company_ID
CInvoiceRegistrationNr
tc_rowid
tc_ParentRowid
tc_status
to tCInvoice.
assign tApiCInvoice.CInvoice_ID = tCInvoice.CInvoice_ID
vcRowId = tCInvoice.tc_Rowid
tCInvoice.tcLocalCurrencyCode = vcCompanyLC
tCInvoice.tdCInvoiceOriginalTC = if tCInvoice.CInvoiceType <> {&INVOICETYPE-INVOICE} and tCInvoice.CInvoiceType <> {&INVOICETYPE-INVOICECORRECTION}
then tCInvoice.CInvoiceOriginalDebitTC
else tCInvoice.CInvoiceOriginalCreditTC
tCInvoice.tdCInvoiceOriginalLC = if tCInvoice.CInvoiceType <> {&INVOICETYPE-INVOICE} and tCInvoice.CInvoiceType <> {&INVOICETYPE-INVOICECORRECTION}
then tCInvoice.CInvoiceOriginalDebitLC
else tCInvoice.CInvoiceOriginalCreditLC
tCInvoice.tdTotalAmountDebitTC = tCInvoice.CInvoiceVatBaseDebitTC
+ tCInvoice.CInvoiceVatDebitTC
tCInvoice.tdTotalAmountCreditTC = tCInvoice.CInvoiceVatBaseCreditTC
+ tCInvoice.CInvoiceVatCreditTC.
/* Default unfilled values */
if tApiCInvoice.CInvoiceIsLockPayment = ?
then do:
<Q-45 run ReasonByIdCode (all) (Read) (NoCache)
(input ?, (ReasonId)
input tCInvoice.tcReasonCode, (ReasonCode)
output dataset tqReasonByIdCode) in BReason >
find first tqReasonByIdCode where
tqReasonByIdCode.tcReasonCode = tCInvoice.tcReasonCode
no-lock no-error.
if available tqReasonByIdCode
then assign tCInvoice.CInvoiceIsLockPayment = tqReasonByIdCode.tlReasonIsLockPayment
tCInvoice.CInvoiceIsLogisticMatching = tqReasonByIdCode.tlReasonIsLogisticMatching.
end.
assign tCInvoice.CInvoiceIsOpen = (tCInvoice.CInvoiceBalanceTC <> 0 or tCInvoice.CInvoiceBalanceLC <> 0 or tCInvoice.CInvoiceBalanceCC <> 0)
tCInvoice.CInvoiceIsSelected = false.
/* Add the Stage details */
for each tApiCInvoiceStage where
tApiCInvoiceStage.tc_ParentRowid = tApiCInvoice.tc_Rowid
by tApiCInvoiceStage.tc_Rowid :
<M-24 run AddDetailLine
(input 'CInvoiceStage':U (icTable),
input tCInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
if viFcReturnSuper >= 0 then do:
<M-57 run SetRowidConvert
(input tApiCInvoiceStage.tc_Rowid (icOldRowid),
input tCInvoiceStage.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end.
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
else if viFcReturnSuper < 0 then leave TRY.
buffer-copy tApiCInvoiceStage
except tApiCInvoiceStage.CInvoiceStage_ID
tApiCInvoiceStage.CInvoice_ID
tApiCInvoiceStage.tc_ParentRowid
tApiCInvoiceStage.tc_Rowid
tApiCInvoiceStage.tc_Status
to tCInvoiceStage.
end.
/* Add the VAT details */
assign viFirstCInvoiceVatId = 0.
for each tApiCInvoiceVat where
tApiCInvoiceVat.tc_ParentRowid = tApiCInvoice.tc_Rowid
by tApiCInvoiceVat.tc_Rowid :
if tApiCInvoiceVat.CInvoiceVatVatBaseCreditTC = ? then assign tApiCInvoiceVat.CInvoiceVatVatBaseCreditTC = 0.
if tApiCInvoiceVat.CInvoiceVatVatBaseDebitTC = ? then assign tApiCInvoiceVat.CInvoiceVatVatBaseDebitTC = 0.
if tApiCInvoiceVat.CInvoiceVatVatCreditTC = ? then assign tApiCInvoiceVat.CInvoiceVatVatCreditTC = 0.
if tApiCInvoiceVat.CInvoiceVatVatDebitTC = ? then assign tApiCInvoiceVat.CInvoiceVatVatDebitTC = 0.
<M-25 run AddDetailLine
(input 'CInvoiceVat':U (icTable),
input tCInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
if viFcReturnSuper >= 0 then do:
<M-58 run SetRowidConvert
(input tApiCInvoiceVat.tc_Rowid (icOldRowid),
input tCInvoiceVat.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end.
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
else if viFcReturnSuper < 0 then leave TRY.
buffer-copy tApiCInvoiceVat
except CInvoiceVat_ID CInvoice_ID tc_rowid tc_ParentRowid tc_status
to tCInvoiceVat.
if viFirstCInvoiceVatId = 0
then assign viFirstCInvoiceVatId = tCInvoiceVat.CInvoiceVat_ID.
end.
/* Add the WHT details */
for each tApiCInvoiceWHT where
tApiCInvoiceWHT.tc_ParentRowid = tApiCInvoice.tc_Rowid
by tApiCInvoiceWHT.tc_Rowid :
<M-47 run AddDetailLine
(input 'CInvoiceWHT':U (icTable),
input tCInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
if viFcReturnSuper >= 0 then do:
<M-2 run SetRowidConvert
(input tApiCInvoiceWHT.tc_Rowid (icOldRowid),
input tCInvoiceWHT.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end.
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
else if viFcReturnSuper < 0 then leave TRY.
buffer-copy tApiCInvoiceWHT
except CInvoiceWHT_ID CInvoice_ID tc_rowid tc_ParentRowid tc_status
to tCInvoiceWHT.
assign tCInvoiceWHT.CInvoiceVat_ID = viFirstCInvoiceVatId.
/******************************************************************/
/* Fill any necessary wht fields which have not been filled only */
/* if the fees fields are already filled. This section of code is */
/* primarily needed for xml integration */
/******************************************************************/
for each tCInvoiceWHT where
tCInvoiceWHT.tc_ParentRowid = tCInvoice.tc_Rowid and
tCInvoiceWHT.tc_Status = "N":U and
((tCInvoiceWHT.CInvoiceWHTFeeCreditTC <> 0 and
tCInvoiceWHT.CInvoiceWHTFeeDebitTC = 0) or
(tCInvoiceWHT.CInvoiceWHTFeeCreditTC = 0 and
tCInvoiceWHT.CInvoiceWHTFeeDebitTC <> 0)):
if (tCInvoiceWHT.CInvoiceWHTTaxType = "":U or
tCInvoiceWHT.CInvoiceWHTTaxType = ?) or
(tCInvoiceWHT.tcVatDescription = "":U or
tCInvoiceWHT.tcVatDescription = ?) or
(tCInvoiceWHT.CInvoiceWhtTaxPct = 0 or
tCInvoiceWHT.CInvoiceWhtTaxPct = ?) or
(tCInvoiceWHT.tcGLCode = "":U or
tCInvoiceWHT.tcGLCode = ?)
then do:
if tCInvoiceWHT.tcVatCode <> "":U and
tCInvoiceWHT.tcVatCode <> ?
then do:
<M-91 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 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end. /* if t_sCInvoiceWHT.tcVatCode <> "":U */
else do:
assign vcMessage = trim(#T-66'You must specify a tax code':80(601485617)T-66#)
oiReturnStatus = -1.
<M-1 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'WHTCode':U (icFieldName),
input tCInvoiceWHT.tcVatCode (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'qadfin-149393':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
return.
end. /* else if t_sCInvoiceWHT.tcVatCode <> "":U */
end. /* if t_sCInvoiceWHT.CInvoiceWHTTaxType = "":U */
if ((tCInvoiceWHT.CInvoiceWHTTaxFeeDebitTC = 0 or
tCInvoiceWHT.CInvoiceWHTTaxFeeDebitTC = ?) and
(tCInvoiceWHT.CInvoiceWHTFeeDebitTC <> 0 and
tCInvoiceWHT.CInvoiceWHTFeeDebitTC <> ?)) or
((tCInvoiceWHT.CInvoiceWHTTaxFeeCreditTC = 0 or
tCInvoiceWHT.CInvoiceWHTTaxFeeCreditTC = ?) and
(tCInvoiceWHT.CInvoiceWHTFeeCreditTC <> 0 and
tCInvoiceWHT.CInvoiceWHTFeeCreditTC <> ?))
then do:
<M-38 run DefaultValuesWHTFees
(input tCInvoice.tc_Rowid (icCInvoiceRowId),
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 tCInvoiceWHT.CInvoiceWHTBaseTaxPct (idWHTBasePercentage),
input tCInvoiceWHT.CInvoiceWHTTaxPct (idTxTaxPct),
input tCInvoice.CInvoicePostingDate (itCInvoicePostingDate),
input tCInvoice.CInvoiceDate (itCInvoiceDate),
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 viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end. /* if ((tCInvoiceWHT.CInvoiceWHTTaxFeeDebitTC = 0 or */
end.
end.
/* Add the CI-PO details */
for each tApiCInvoicePO where
tApiCInvoicePO.tc_ParentRowid = tApiCInvoice.tc_Rowid
by tApiCInvoicePO.tc_Rowid:
<M-26 run AddDetailLine
(input 'CInvoicePO':U (icTable),
input tCInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
if viFcReturnSuper >= 0 then do:
<M-59 run SetRowidConvert
(input tApiCInvoicePO.tc_Rowid (icOldRowid),
input tCInvoicePO.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end.
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
else if viFcReturnSuper < 0 then leave TRY.
buffer-copy tApiCInvoicePO
except tApiCInvoicePO.CInvoicePO_ID
tApiCInvoicePO.CInvoice_ID
tApiCInvoicePO.tc_ParentRowid
tApiCInvoicePO.tc_Rowid
tApiCInvoicePO.tc_Status
to tCInvoicePO.
end.
/* Add the CI-Bank details */
assign vlStartedQueryPayCodeGroupByID = false.
for each tApiCInvoiceBank where
tApiCInvoiceBank.tc_ParentRowid = tApiCInvoice.tc_Rowid
by tApiCInvoiceBank.tc_Rowid :
<M-27 run AddDetailLine
(input 'CInvoiceBank':U (icTable),
input tCInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
if viFcReturnSuper >= 0 then do:
<M-60 run SetRowidConvert
(input tApiCInvoiceBank.tc_Rowid (icOldRowid),
input tCInvoiceBank.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end.
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
else if viFcReturnSuper < 0 then leave TRY.
buffer-copy tApiCInvoiceBank
except tApiCInvoiceBank.CInvoiceBank_ID
tApiCInvoiceBank.CInvoice_ID
tApiCInvoiceBank.tc_ParentRowid
tApiCInvoiceBank.tc_Rowid
tApiCInvoiceBank.tc_Status
to tCInvoiceBank.
/* Add the CI-BankCode details */
for each tApiCInvoiceBankPayCode where
tApiCInvoiceBankPayCode.tc_ParentRowid = tApiCInvoiceBank.tc_Rowid
by tApiCInvoiceBankPayCode.tc_Rowid :
<M-52 run AddDetailLine
(input 'CInvoiceBankPayCode':U (icTable),
input tCInvoiceBank.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
if viFcReturnSuper >= 0 then do:
<M-61 run SetRowidConvert
(input tApiCInvoiceBankPayCode.tc_Rowid (icOldRowid),
input tCInvoiceBankPayCode.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end.
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
else if viFcReturnSuper < 0 then leave TRY.
buffer-copy tApiCInvoiceBankPayCode
except tApiCInvoiceBankPayCode.CInvoiceBankPayCode_ID
tApiCInvoiceBankPayCode.CInvoiceBank_ID
tApiCInvoiceBankPayCode.PayFormatCode_ID
tApiCInvoiceBankPayCode.PayFormatGroup_ID
tApiCInvoiceBankPayCode.tc_ParentRowid
tApiCInvoiceBankPayCode.tc_Rowid
tApiCInvoiceBankPayCode.tc_Status
to tCInvoiceBankPayCode.
/* have to set the PayFormatGroupID - not set as a related business field */
if (vlStartedQueryPayCodeGroupByID <> true)
then do:
<Q-67 run PayFormatGroupForID (Start) in BPaymentFormat >
assign vlStartedQueryPayCodeGroupByID = true.
end. /* if vlStartedQueryPayCodeGroupByID */
<Q-65 run PayFormatGroupForID (all) (Read) (NoCache)
(input tApiCInvoiceBank.tcPayFormatTypeCode, (PayFormatTypeCode)
input tApiCInvoiceBankPayCode.tcPayFormatGroupCode, (PayFormatGroupCode)
output dataset tqPayFormatGroupForID) in BPaymentFormat >
find first tqPayFormatGroupForID where
tqPayFormatGroupForID.tcPayFormatGroupCode = tApiCInvoiceBankPayCode.tcPayFormatGroupCode and
tqPayFormatGroupForID.tcPayFormatTypeCode = tApiCInvoiceBank.tcPayFormatTypeCode
no-lock no-error.
if available tqPayFormatGroupForID
then assign tCInvoiceBankPayCode.PayFormatGroup_ID = tqPayFormatGroupForID.tiPayFormatGroup_ID.
else do:
assign oiReturnStatus = -1
vcMessage = trim(substitute(#T-71'The payment attribute (tcpayFormatGroupCode) with name &1 is not defined for the payment format &2.':255(73463996)T-71# , tApiCInvoiceBankPayCode.tcPayFormatGroupCode, tApiCInvoiceBank.tcPayFormatTypeCode))
olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(-1)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
<M-70 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-9693':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
return.
end.
end.
end.
if (vlStartedQueryPayCodeGroupByID = true)
then do:
<Q-69 run PayFormatGroupForID (Stop) in BPaymentFormat >
end. /* if vlStartedQueryPayCodeGroupByID */
/* Add CInvoicePosting details (ControlAccount) */
<Q-19 run CreditorByCreditorCodeID (all) (Read) (NoCache)
(input tCInvoice.Creditor_ID, (CreditorId)
input tCInvoice.Company_ID, (CompanyId)
input if tcinvoice.creditor_id = 0 then tCInvoice.tcCreditorCode else '':U, (CreditorCode)
output dataset tqCreditorByCreditorCodeID) in BCreditor >
find first tqCreditorByCreditorCodeID no-error.
if available tqCreditorByCreditorCodeID
then do:
assign viControlGLProfileId = if tCInvoice.CInvoiceType = {&INVOICETYPE-PREPAYMENT}
then tqCreditorByCreditorCodeID.tiPrePayControlGLProfile_ID
else if tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICE} or tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then tqCreditorByCreditorCodeID.tiInvControlGLProfile_ID
else tqCreditorByCreditorCodeID.tiCnControlGLProfile_ID.
<Q-5 run ProfileLinkByGL (all) (Read) (NoCache)
(input viControlGLProfileId, (GlProfileId)
input viCompanyId, (CompanyId)
output dataset tqProfileLinkByGL) in BProfile >
find first tqProfileLinkByGl no-error.
if available tqProfileLinkByGl
then assign vcControlGLCode = tqProfileLinkByGL.tcGLCode.
assign tCInvoice.tcControlGLCode = vcControlGLCode.
end.
find first tApiCInvoicePosting where
tApiCInvoicePosting.tc_ParentRowid = tApiCInvoice.tc_Rowid and
tApiCInvoicePosting.CInvoicePostingType = {&INVOICEPOSTINGTYPE-INITIAL}
no-error.
if available tApiCInvoicePosting
then do:
<M-28 run AddDetailLine
(input 'CInvoicePosting':U (icTable),
input tCInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
if viFcReturnSuper >= 0 then do:
<M-62 run SetRowidConvert
(input tApiCInvoicePosting.tc_Rowid (icOldRowid),
input tCInvoicePosting.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end.
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
else if viFcReturnSuper < 0 then leave TRY.
buffer-copy tApiCInvoicePosting
except CInvoicePosting_ID CInvoice_ID tc_rowid tc_ParentRowid tc_status
to tCInvoicePosting.
/* fill in the CInvoice voucher, search in instance */
<M-7 run GetPostingInfoByPostingId
(input tCInvoicePosting.Posting_ID (iiPostingId),
input vcControlGLCode (icGLCode),
output viDummy (oiPostingPeriodYear),
output vcDummy (ocPostingJournalCode),
output tCInvoice.CInvoiceVoucher (oiPostingVoucher),
output viDummy (oiPostingPeriodPeriod),
output viControlPostingLineId (oiPostingLineId),
output vdControlPostingDebitTC (odPostingLineDebitTC),
output vdControlPostingCreditTC (odPostingLineCreditTC),
output vdControlPostingDebitLC (odPostingLineDebitLC),
output vdControlPostingCreditLC (odPostingLineCreditLC),
output vdControlPostingDebitCC (odPostingLineDebitCC),
output vdControlPostingCreditCC (odPostingLineCreditCC),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
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.
else assign vlWarningsFound = true.
end.
/* Create a new CInvoiceMovement and copy all data */
assign vlControlPostingError = false.
if viControlPostingLineId <> ? and viControlPostingLineId <> 0
then do:
<M-22 run AddDetailLine
(input 'CInvoiceMovement':U (icTable),
input tCInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper < 0
then assign vlControlPostingError = true.
assign tCInvoiceMovement.CInvoiceMovementType = {&MOVEMENTTYPE-INITIAL}
tCInvoiceMovement.PostingLine_ID = viControlPostingLineId.
end.
else assign vlControlPostingError = true.
/* posting must be on control account, and on right side */
if vlControlPostingError = true
then do:
assign oiReturnStatus = -1
vcMessage = trim(substitute(#T-51'The posting must be on control account (&1): for &2 or &3 on &4, for &5 or &6 on &7.':255(13948)T-51# , vcControlGLCode, {&INVOICETYPE-INVOICE-TR}, {&INVOICETYPE-INVOICECORRECTION-TR}, {&CREDITDEBITABBREVIATION-DEBIT-TR}, {&INVOICETYPE-CREDITNOTE-TR}, {&INVOICETYPE-CREDITNOTECORRECTION-TR}, {&CREDITDEBITABBREVIATION-CREDIT-TR}))
olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(-1)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
<M-23 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-2481':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
return.
end.
/* Validate CInvoiceOriginalAmount with ControlPosting */
if tCInvoice.CInvoiceOriginalCreditTC <> vdControlPostingCreditTC or
tCInvoice.CInvoiceOriginalCreditLC <> vdControlPostingCreditLC or
tCInvoice.CInvoiceOriginalCreditCC <> vdControlPostingCreditCC or
tCInvoice.CInvoiceOriginalDebitTC <> vdControlPostingDebitTC or
tCInvoice.CInvoiceOriginalDebitLC <> vdControlPostingDebitLC or
tCInvoice.CInvoiceOriginalDebitCC <> vdControlPostingDebitCC
then do:
assign oiReturnStatus = -1
vcMessage = trim(substitute(#T-6'The posting amount on control account (&1) must be same as supplier invoice original amount.':255(245797264)T-6#, vcControlGLCode))
olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(-1)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
<M-42 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-57714':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
return.
end. /* if tCInvoice.CInvoiceOriginalCreditTC <> vdControlPostingCreditTC or */
/* ================================================== */
/* Write the posting-id in the tCInvoiceVat record */
/* ================================================== */
for each tCInvoiceVat where
tCInvoiceVat.tc_ParentRowid = tCInvoice.tc_Rowid and
tCInvoiceVat.tc_Status <> "D":U
no-lock:
<M-92 run GetPostingVatID
(input tCInvoiceVat.tcDomainCode (icDomainCode),
input tCInvoiceVat.TxclTaxCls (icTxclTaxCls),
input tCInvoiceVat.TxenvTaxEnv (icTxenvTaxEnv),
input tCInvoiceVat.TxuTaxUsage (icTxuTaxUsage),
input tCInvoiceVat.tcVatCode (icVatCode),
input tCInvoiceVat.tcVatInOut (icVatInOut),
input tCInvoicePosting.Posting_ID (iiPostingID),
output tCInvoiceVat.PostingVat_ID (oiPostingVatID),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
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.
else assign vlWarningsFound = true.
end. /* if viFcReturnSuper <> 0 */
end. /* for each tCInvoiceVat */
end.
/* Add CInvoicePosting details (CIRECAccount) */
<Q-29 run GLByGLSystemType (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input {&GLSYSTEMTYPE-CIREC}, (GLSystemTypeCode)
input {&GLTYPECODE-SYST}, (GlTypeCode)
input ?, (GlIsDivisionAccount)
output dataset tqGLByGLSystemType) in BGL >
find first tqGLByGLSystemType no-error.
if available tqGLByGLSystemType
then assign vcCirecGLCode = tqGLByGLSystemType.tcGLCode.
find first tApiCInvoicePosting where
tApiCInvoicePosting.tc_ParentRowid = tApiCInvoice.tc_Rowid and
tApiCInvoicePosting.CInvoicePostingType = {&INVOICEPOSTINGTYPE-ALLOCATION}
no-error.
if available tApiCInvoicePosting
then do:
<M-30 run AddDetailLine
(input 'CInvoicePosting':U (icTable),
input tCInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
if viFcReturnSuper >= 0 then do:
<M-63 run SetRowidConvert
(input tApiCInvoicePosting.tc_Rowid (icOldRowid),
input tCInvoicePosting.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end.
if viFcReturnSuper > 0 then assign vlWarningsFound = true.
else if viFcReturnSuper < 0 then leave TRY.
buffer-copy tApiCInvoicePosting
except CInvoicePosting_ID CInvoice_ID tc_rowid tc_ParentRowid tc_status
to tCInvoicePosting.
/* fill in the CInvoice voucher, search in instance */
<M-31 run GetPostingInfoByPostingId
(input tCInvoicePosting.Posting_ID (iiPostingId),
input vcCirecGLCode (icGLCode),
output viDummy (oiPostingPeriodYear),
output vcDummy (ocPostingJournalCode),
output viDummy (oiPostingVoucher),
output viDummy (oiPostingPeriodPeriod),
output viCIRECPostingLineID (oiPostingLineId),
output vdCIRECPostingDebitTC (odPostingLineDebitTC),
output vdCIRECPostingCreditTC (odPostingLineCreditTC),
output vdCIRECPostingDebitLC (odPostingLineDebitLC),
output vdCIRECPostingCreditLC (odPostingLineCreditLC),
output vdCIRECPostingDebitCC (odPostingLineDebitCC),
output vdCIRECPostingCreditCC (odPostingLineCreditCC),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
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.
else assign vlWarningsFound = true.
end.
assign vlControlPostingError = false.
if viCIRECPostingLineId <> ? and viCIRECPostingLineId <> 0
then do:
if (tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICE} or tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICECORRECTION}) and vdCIRECPostingCreditLC = 0
then assign vlControlPostingError = false.
if (tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTE} or tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}) and vdCIRECPostingDebitLC = 0
then assign vlControlPostingError = false.
end.
else assign vlControlPostingError = true.
/* posting must be on CIREC account, and on right side */
if vlControlPostingError = true
then do:
assign oiReturnStatus = -1
vcMessage = trim(substitute(#T-50'The posting must be to an unmatched invoices account (&1): for &2 or &3 on &4, for &5 or &6 on &7.':255(13949)T-50# , vcCIRECGLCode, {&INVOICETYPE-INVOICE-TR}, {&INVOICETYPE-INVOICECORRECTION-TR}, {&CREDITDEBITABBREVIATION-DEBIT-TR}, {&INVOICETYPE-CREDITNOTE-TR}, {&INVOICETYPE-CREDITNOTECORRECTION-TR}, {&CREDITDEBITABBREVIATION-CREDIT-TR}))
olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(-1)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
<M-33 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-2486':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
return.
end.
end.
/* 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.
/* Add method which can be implemented to set some defaults */
<M-90 run ApiStdMaintainTTDefaulting (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
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.
else assign vlWarningsFound = true.
end.
/* Validate the data and performa AddUpd */
<M-16 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
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.
else assign vlWarningsFound = true.
end.
<M-17 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
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.
else assign vlWarningsFound = true.
end.
/* Save the data */
if icAction <> {&DAEMONACTION-VALIDATE}
then do:
if vlReturnDatasetCI
then do:
<M-53 run GetXmlRepresentationDataset
(input '' (icObjectRowId),
input false (ilHeaderOnly),
input 0 (iiPriority),
output vhTempDS by-reference (ozXMLDataset),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
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.
else assign vlWarningsFound = true.
end.
/* Make a deep-copy of the dataset to prevent any further updates in the class tables from being reflected into the published dataset. */
vhDatasetToReturnCI:copy-dataset (vhTempDS, true, false, false, "", false, "").
delete object vhTempDS no-error.
/* Get the KeyField indications */
assign vcTableName = "".
<M-54 run GetKeyFields
(input-output vcTableName (bcTableName),
output vcPrimKeyCI (ocPrimaryKey),
output vcDummy (ocAlternateKey),
output vcDummy (ocObjectID),
output vcDummy (ocObjectStatus),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
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 vlReturnDatasetCI */
<M-18 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
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 icAction <> {&DAEMONACTION-VALIDATE} */
/* 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(tApiCInvoice.CInvoice_ID)
bcLstRowid = bcLstRowid + chr(4) + vcRowID
oiReturnStatus = (if vlWarningsFound = true then 1 else 0).
return.
end. /* TRY */
assign
oiReturnStatus = viFcReturnSuper
olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(oiReturnStatus)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.