Description
Create or Update Template
Parameters
iiCompanyId | input | integer | |
icTemplateCode | input | character | TemplateCode |
iiPostingID | input | integer | |
icBusinessRelationCode | input | character | |
icDivisionCode | input | character | Sub-Account Code |
icCostCentreCode | input | character | Cost Center Code |
icProjectCode | input | character | Project Code |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/bpostingtemplate.p)
/* ============================================================================== */
/* Normalize input parameters */
/* ============================================================================== */
if iiCompanyId = 0 then assign iiCompanyId = viCompanyId.
if iiCompanyId = ? then assign iiCompanyId = viCompanyId.
/* read tempate by posting while template code is empty */
/* the template code is empty, it means the posting will */
/* not be linked any template. The original template needs to be removed. */
if (icTemplateCode = '':U or icTemplateCode = ?) and (iiPostingID <> 0 and iiPostingID <> ?) then
do:
if not can-find (first tPostingTemplate where
tPostingTemplate.Company_ID = iiCompanyId and
tPostingTemplate.Posting_ID = iiPostingID)
then do:
empty temp-table tFcDynRel.
Create tFcDynRel.
assign tFcDynRel.tcFcFrom = ""
tFcDynRel.tcFcTo = "PostingTemplate":U
tFcDynRel.tcFcRel = "for each PostingTemplate where ":U +
"PostingTemplate.Posting_ID = ":U + string(iiPostingID) + " and ":U +
"PostingTemplate.Company_ID = ":U + string(iiCompanyId)
tFcDynRel.thFcBuffer = buffer t_oPostingTemplate:handle
tFcDynRel.thFcIBuffer = buffer t_iPostingTemplate:handle.
<M-79 run StartPersistence
(output vhFcComponent (ohPersistence),
output viFcReturnSuper (oiReturnStatus)) in BPostingTemplate>
<M-83 run ReadData
(input tFcDynRel (tDynRel),
input {&TARGETPROCEDURE} (ihClass),
output oiReturnStatus (oiReturnStatus)) in persistence>
if viFcReturnSuper = -4
then oiReturnStatus = 0.
if oiReturnStatus <> 0
then return.
end.
find first tPostingTemplate where
tPostingTemplate.Company_ID = iiCompanyId and
tPostingTemplate.Posting_ID = iiPostingID no-error.
if available tPostingTemplate and tPostingTemplate.PostingTemplateCode <> icTemplateCode then
do:
assign tPostingTemplate.tc_Status = "D":U.
end.
return.
end.
/* ============================================================================== */
/* Read data from database (if needed) */
/* ============================================================================== */
if not can-find (first tPostingTemplate where
tPostingTemplate.Company_ID = iiCompanyId and
tPostingTemplate.PostingTemplateCode = icTemplateCode)
then do:
empty temp-table tFcDynRel.
Create tFcDynRel.
assign tFcDynRel.tcFcFrom = ""
tFcDynRel.tcFcTo = "PostingTemplate":U
tFcDynRel.tcFcRel = "for each PostingTemplate where ":U +
"(PostingTemplate.PostingTemplateCode = '":U + icTemplateCode + "' OR ":U +
"PostingTemplate.Posting_ID = ":U + string(iiPostingID) + ") and ":U +
"PostingTemplate.Company_ID = ":U + string(iiCompanyId)
tFcDynRel.thFcBuffer = buffer t_oPostingTemplate:handle
tFcDynRel.thFcIBuffer = buffer t_iPostingTemplate:handle.
if iiPostingID = ? or iiPostingID = 0 then
assign tFcDynRel.tcFcRel = "for each PostingTemplate where ":U +
"PostingTemplate.PostingTemplateCode = '":U + icTemplateCode + "' and ":U +
"PostingTemplate.Company_ID = ":U + string(iiCompanyId).
<M-1 run StartPersistence (output vhFcComponent (ohPersistence),
output viFcReturnSuper (oiReturnStatus)) in BPostingTemplate>
<M-2 run ReadData
(input tFcDynRel (tDynRel),
input {&TARGETPROCEDURE} (ihClass),
output oiReturnStatus (oiReturnStatus)) in persistence>
if oiReturnStatus = -4
then oiReturnStatus = 0.
if oiReturnStatus <> 0
then return.
end. /* if not can-find (first tPostingTemplate where */
find first tPostingTemplate where
tPostingTemplate.Company_ID = iiCompanyId and
tPostingTemplate.Posting_ID = iiPostingID no-error.
if available tPostingTemplate and tPostingTemplate.PostingTemplateCode <> icTemplateCode then
do:
assign tPostingTemplate.tc_Status = "D":U.
end.
find first tPostingTemplate where
tPostingTemplate.Company_ID = iiCompanyId and
tPostingTemplate.PostingTemplateCode = icTemplateCode no-error.
if available tPostingTemplate
then do:
/* Existing Posting Tempalte Code */
if tPostingTemplate.tc_Status <> "N":U and tPostingTemplate.Posting_ID = iiPostingID
then assign tPostingTemplate.tc_Status = "C":U.
end.
else do:
<M-3 run AddDetailLine (input 'PostingTemplate':U (icTable),
input '' (icParentRowid),
output oiReturnStatus (oiReturnStatus)) in BPostingTemplate>
if oiReturnStatus <> 0
then return.
end.
assign tPostingTemplate.Company_ID = iiCompanyId
tPostingTemplate.PostingTemplateBusRelCode = icBusinessRelationCode
tPostingTemplate.PostingTemplateCode = icTemplateCode
tPostingTemplate.PostingTemplateCostCtrCode = icCostCentreCode
tPostingTemplate.PostingTemplateDateLastMod = today
tPostingTemplate.PostingTemplateDivCode = icDivisionCode
tPostingTemplate.PostingTemplateProjectCode = icProjectCode
tPostingTemplate.Posting_ID = iiPostingID.