Description
This method accepts APMatching_ID and create a copy of this AP matching.
Parameters
iiOriginalAPMId | input | integer | |
ilClearData | input | logical | |
ilRemoveOriginalAPM | input | logical | |
ocNewAPMRowid | output | character | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bapmatching.p)
/* =================================================================================================== */
/* Method : CopyIntoNew */
/* Desc : This method create a copy of the AP matching with the input APMatchingId */
/* --------------------------------------------------------------------------------------------------- */
/* Params: (I) iiOriginalAPMId ID of AP matching to be copied */
/* (I) ilClearData Flag to determine clear data of the instance or not */
/* (I) ilRemoveOriginalAPM Flag to determine remove original AP matching or not */
/* (O) ocNewAPMRowid Row ID of the copy of AP Matching */
/* (O) oiReturnStatus Return status */
/* =================================================================================================== */
assign oiReturnStatus = -98.
/* =================================================================================================== */
/* Normalize input parameters */
/* =================================================================================================== */
if iiOriginalAPMId = 0 then assign iiOriginalAPMId = ?.
/* =================================================================================================== */
/* Validate input parameters */
/* =================================================================================================== */
if iiOriginalAPMId = ?
then do:
assign vcMessage = trim(#T-1'Invalid AP matching ID provided.':255(69560)T-1#)
vcContext = "iiOriginalAPMId = ?":U
oiReturnStatus = -1.
<M-2 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8157':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
return.
end. /* if iiOriginalAPMId = ? */
/* =================================================================================================== */
/* Clear the intance data otherwise it causes issues when executed multiple times */
/* =================================================================================================== */
if ilClearData = true
then do:
<M-3 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end. /* if ilClearData = true */
/* =================================================================================================== */
/* Load the original AP matching if it not existing in the instance */
/* =================================================================================================== */
find first tAPMatching where
tAPMatching.APMatching_ID = iiOriginalAPMId
no-error.
if not available tAPMatching
then do:
<M-5 run DataLoad
(input '':U (icRowids),
input string(iiOriginalAPMId) (icPkeys),
input '':U (icObjectIds),
input '':U (icFreeform),
input not ilClearData (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
assign vcMessage = trim(substitute(#T-4'Data could not be loaded: unable to load the AP matching with ID (&1)':255(69561)T-4#,iiOriginalAPMId)).
<M-6 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'S':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8158':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
return.
end. /* if viFcReturnSuper < 0 */
end. /* if viFcReturnSuper <> 0 */
end. /* if not available tAPMatching */
/* =================================================================================================== */
/* Create APMatching APMatchingLn APMatchingLn APMatchingLnTax APMatchingLnRevTax */
/* =================================================================================================== */
find first bAPMatching where
bAPMatching.APMatching_ID = iiOriginalAPMId
no-error.
<M-7 run AddDetailLine
(input 'APMatching':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
/* assign viOriginalPostingYear = tCInvoice.CInvoicePostingYear. */
buffer-copy bAPMatching
except bAPMatching.APMatching_ID
bAPMatching.Posting_ID
bAPMatching.CirecPostingLine_ID
bAPMatching.tc_ParentRowId
bAPMatching.LastModifiedDate
bAPMatching.LastModifiedTime
bAPMatching.LastModifiedUser
bAPMatching.tc_RowId
bAPMatching.tc_Status
to tAPMatching.
assign ocNewAPMRowid = tAPMatching.tc_Rowid.
for each bAPMatchingLn where
bAPMatchingLn.tc_ParentRowid = bAPMatching.tc_Rowid:
<M-8 run AddDetailLine
(input 'APMatchingLn':U (icTable),
input tAPMatching.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
buffer-copy bAPMatchingLn
except bAPMatchingLn.APMatching_ID
bAPMatchingLn.APMatchingLn_ID
bAPMatchingLn.PvoPostingLine_ID
bAPMatchingLn.VarRatePostingLine_ID
bAPMatchingLn.VarUsagePostingLine_ID
bAPMatchingLn.VarExchRatePostingLine_ID
bAPMatchingLn.NewExpensePostingLine_ID
bAPMatchingLn.RevExpensePostingLine_ID
bAPMatchingLn.tc_ParentRowId
bAPMatchingLn.tc_RowId
bAPMatchingLn.tc_Status
to tAPMatchingLn.
assign tAPMatchingLn.APMatching_ID = tAPMatching.APMatching_ID.
for each bAPMatchingLnTax where
bAPMatchingLnTax.tc_ParentRowId = bAPMatchingLn.tc_RowId:
<M-9 run AddDetailLine
(input 'APMatchingLnTax':U (icTable),
input tAPMatchingLn.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
buffer-copy bAPMatchingLnTax
except bAPMatchingLnTax.APMatching_ID
bAPMatchingLnTax.APMatchingLn_ID
bAPMatchingLnTax.APMatchingLnTax_ID
bAPMatchingLnTax.APRatePostingLine_ID
bAPMatchingLnTax.PPVPostingLine_ID
bAPMatchingLnTax.tc_ParentRowId
bAPMatchingLnTax.tc_RowId
bAPMatchingLnTax.tc_Status
to tAPMatchingLnTax.
assign tAPMatchingLnTax.APMatching_ID = tAPMatching.APMatching_ID
tAPMatchingLnTax.APMatchingLn_ID = tAPMatchingLn.APMatchingLn_ID.
end. /* for each bAPMatchingLnTax */
for each bAPMatchingLnWHT where
bAPMatchingLnWHT.tc_ParentRowId = bAPMatchingLn.tc_RowId:
<M-91 run AddDetailLine
(input 'APMatchingLnWHT':U (icTable),
input tAPMatchingLn.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
buffer-copy bAPMatchingLnWHT
except bAPMatchingLnWHT.APMatching_ID
bAPMatchingLnWHT.APMatchingLn_ID
bAPMatchingLnWHT.APMatchingLnWHT_ID
bAPMatchingLnWHT.tc_ParentRowId
bAPMatchingLnWHT.tc_RowId
bAPMatchingLnWHT.tc_Status
to tAPMatchingLnTax.
assign tAPMatchingLnWHT.APMatching_ID = tAPMatching.APMatching_ID
tAPMatchingLnWHT.APMatchingLn_ID = tAPMatchingLn.APMatchingLn_ID.
end. /* for each bAPMatchingLnWHT */
/* No APMatchongLnRevTax record should be copied as they are created during AdditionalUpdates */
end. /* for each bAPMatchingLn */
/* ========================================================================================= */
/* Remove the original receiver matching from instance */
/* ========================================================================================= */
if ilRemoveOriginalAPM
then do:
for each tAPMatching where
tAPMatching.APMatching_ID = iiOriginalAPMId:
for each tAPMatchingLn where
tAPMatchingLn.tc_ParentRowid = tAPMatching.tc_Rowid:
for each tAPMatchingLnTax where
tAPMatchingLnTax.tc_ParentRowid = tAPMatchingLn.tc_Rowid:
delete tAPMatchingLnTax.
end. /* for each tAPMatchingLnTax where */
for each tAPMatchingLnWHT where
tAPMatchingLnWHT.tc_ParentRowid = tAPMatchingLn.tc_Rowid:
delete tAPMatchingLnWHT.
end. /* for each tAPMatchingLnWHT where */
for each tAPMatchingLnRevTax where
tAPMatchingLnRevTax.tc_ParentRowid = tAPMatchingLn.tc_Rowid:
delete tAPMatchingLnRevTax.
end. /* for each tAPMatchingLnRevTax where */
delete tAPMatchingLn.
end. /* for each tAPMatchingLn where */
delete tAPMatching.
end. /* for each tAPMatching where */
end. /* if ilRemoveOriginalAPM */
/* =================================================================================================== */
/* Return */
/* =================================================================================================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.