Description
Replicate Payment Conditions to MFG/PRO Credit Terms.
Parameters
tCopyPaymentCondition | input | temp-table | |
icDomainCode | input | character | If DomainCode is filled, we only need to replicate this payment condition to this domaincode (for new domains only). If DomainCode is left blank, we need to replicate this to all domains (for changes to payment conditions) |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bmfgcreditterms.p)
/* ====================== */
/* Check input parameters */
/* ====================== */
if not can-find(first tCopyPaymentCondition)
then return.
/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus = -98
viLocalReturnStatus = 0
vcListCtMstr = '':U.
CONVERTBLOCK:
DO:
/* ======================================================= */
/* Retrieve domains depending on icDomainCode (all or one) */
/* ======================================================= */
<Q-19 run DomainsPrim (all) (Read) (NoCache)
(input 0, (DomainID)
input icDomainCode, (DomainCode)
output dataset tqDomainsPrim) in BDomain >
/* ===================================== */
/* Check which records need to be loaded */
/* ===================================== */
for each tCopyPaymentCondition:
for each tqDomainsPrim:
/* ============================================================ */
/* Create a list of all tct_mstr records that need to be loaded */
/* ============================================================ */
<Q-20 assign vlFcQueryRecordsAvailable = CtMstrByDomainCode (NoCache)
(input tCopyPaymentCondition.PaymentConditionCode, (Code)
input tqDomainsPrim.tcDomainCode, (Domain)) in BMfgCreditTerms >
if vlFcQueryRecordsAvailable = true
then assign vcListCtMstr = vcListCtMstr +
(if vcListCtMstr = '':U
then '':U
else chr(4)) +
tqDomainsPrim.tcDomainCode +
chr(2) +
tCopyPaymentCondition.PaymentConditionCode.
end. /* for each tDomainsPrim: */
end. /* for each tCopyPaymentCondition */
/* ========================= */
/* Load the tct_mstr records */
/* ========================= */
if vcListCtMstr <> "":U and
vcListCtMstr <> ?
then do :
<M-4 run DataLoad
(input '':U (icRowids),
input vcListCtMstr (icPkeys),
input '':U (icObjectIds),
input '':U (icFreeform),
input false (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BMfgCreditTerms>
if viFcReturnSuper <> 0
then do:
assign viLocalReturnStatus = viFcReturnSuper.
leave CONVERTBLOCK.
end. /* if viFcReturnSuper <> 0 */
end. /* if vcListCtMstr <> "":U and */
/* ================================================= */
/* Convert table tPaymentCondition to table tct_mstr */
/* ================================================= */
for each tCopyPaymentCondition:
for each tqDomainsPrim:
/* ================================================================ */
/* Create or update tct_mstr records based on tCopyPaymentCondition */
/* ================================================================ */
find tct_mstr where
tct_mstr.ct_code = tCopyPaymentCondition.PaymentConditionCode and
tct_mstr.ct_domain = tqDomainsPrim.tcDomainCode
no-error.
if not available tct_mstr
then do:
if tCopyPaymentCondition.tc_Status = "D"
then next.
<M-8 run AddDetailLine
(input 'ct_mstr':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BMfgCreditTerms>
if viFcReturnSuper <> 0
then do:
assign viLocalReturnStatus = viFcReturnSuper.
leave CONVERTBLOCK.
end. /* if viFcReturnSuper <> 0 */
assign tct_mstr.oid_ct_mstr = <M-9 GetNextOidValue () in BMfgCreditTerms> no-error.
if error-status:error
then do:
assign vcMessage = trim(#T-16'Cannot retrieve an oid-value while replicating credit terms.':255(69623)t-16#) + chr(10) +
trim(substitute(#T-17'Credit Term: &1.':255(69624)T-17#, trim(tCopyPaymentCondition.PaymentConditionCode)))
viLocalReturnStatus = -1.
if ERROR-STATUS:NUM-MESSAGES > 0
then assign vcMessage = vcMessage + chr(10) +
trim(substitute(#T-18'Detailed info: &1 (&2).':255(466)T-18#,ERROR-STATUS:GET-MESSAGE(1),string(ERROR-STATUS:GET-NUMBER(1)))).
<M-10 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8201':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgCreditTerms>
leave CONVERTBLOCK.
end.
end. /* if not available tct_mstr */
else assign tct_mstr.tc_Status = "C":U.
assign tct_mstr.ct_code = tCopyPaymentCondition.PaymentConditionCode
tct_mstr.ct_domain = tqDomainsPrim.tcDomainCode
tct_mstr.ct_desc = tCopyPaymentCondition.PaymentConditionDescript
tct_mstr.ct_min_days = tCopyPaymentCondition.PaymentConditionDueDays
tct_mstr.ct_base_date = tCopyPaymentCondition.PaymentConditionBaseDate
tct_mstr.ct_base_days = tCopyPaymentCondition.PaymentConditionBaseDays
tct_mstr.ct_grace_days = tCopyPaymentCondition.PaymentConditionGraceDay
tct_mstr.ct_disc_pct = tCopyPaymentCondition.PaymentConditionPercentage
tct_mstr.ct_terms_int = tCopyPaymentCondition.PaymentConditionTermsInt
tct_mstr.ct_late_int = tCopyPaymentCondition.PaymentConditionLateInt
tct_mstr.ct_mod_date = today
tct_mstr.ct_userid = vcUserLogin
tct_mstr.ct_dating = (if tCopyPaymentCondition.PaymentConditionPaymentTyp = {&PAYMENTCONDITIONPAYMENTTYPE-STAGED}
then true
else false)
tct_mstr.ct_disc_days = (if tCopyPaymentCondition.PaymentConditionPdDiscType = {&PAYMENTCONDITIONPERIODTYPE-MONTHS}
then ((tCopyPaymentCondition.PaymentConditionDayMthDisc * 30) + tCopyPaymentCondition.PaymentConditionSupDayDisc)
else if tCopyPaymentCondition.PaymentConditionPdDiscType = {&PAYMENTCONDITIONPERIODTYPE-DAYS}
then (tCopyPaymentCondition.PaymentConditionDayMthDisc + tCopyPaymentCondition.PaymentConditionSupDayDisc)
else if tCopyPaymentCondition.PaymentConditionPdDiscType = {&PAYMENTCONDITIONPERIODTYPE-FORTNIGHT}
then ((tCopyPaymentCondition.PaymentConditionDayMthDisc * 15) + tCopyPaymentCondition.PaymentConditionSupDayDisc)
else if tCopyPaymentCondition.PaymentConditionPdDiscType = {&PAYMENTCONDITIONPERIODTYPE-WEEK}
then ((tCopyPaymentCondition.PaymentConditionDayMthDisc * 7) + tCopyPaymentCondition.PaymentConditionSupDayDisc)
else 0)
tct_mstr.ct_from_inv = (if tCopyPaymentCondition.PaymentConditionPdDiscType = {&PAYMENTCONDITIONPERIODTYPE-DAYS}
then 1
else if tCopyPaymentCondition.PaymentConditionPdDiscType = {&PAYMENTCONDITIONPERIODTYPE-MONTHS}
then 2
else if tCopyPaymentCondition.PaymentConditionPdDiscType = {&PAYMENTCONDITIONPERIODTYPE-FORTNIGHT}
then 3
else if tCopyPaymentCondition.PaymentConditionPdDiscType = {&PAYMENTCONDITIONPERIODTYPE-WEEK}
then 4
else tct_mstr.ct_from_inv)
tct_mstr.ct_due_days = (if tCopyPaymentCondition.PaymentConditionPeriodType = {&PAYMENTCONDITIONPERIODTYPE-MONTHS}
then ((tCopyPaymentCondition.PaymentConditionDaysMonths * 30) + tCopyPaymentCondition.PaymentConditionSupplDays)
else if tCopyPaymentCondition.PaymentConditionPeriodType = {&PAYMENTCONDITIONPERIODTYPE-DAYS}
then tCopyPaymentCondition.PaymentConditionDaysMonths + tCopyPaymentCondition.PaymentConditionSupplDays
else if tCopyPaymentCondition.PaymentConditionPeriodType = {&PAYMENTCONDITIONPERIODTYPE-FORTNIGHT}
then ((tCopyPaymentCondition.PaymentConditionDaysMonths * 15) + tCopyPaymentCondition.PaymentConditionSupplDays)
else if tCopyPaymentCondition.PaymentConditionPeriodType = {&PAYMENTCONDITIONPERIODTYPE-WEEK}
then ((tCopyPaymentCondition.PaymentConditionDaysMonths * 7) + tCopyPaymentCondition.PaymentConditionSupplDays)
else 0)
tct_mstr.ct_due_inv = (if tCopyPaymentCondition.PaymentConditionPeriodType = {&PAYMENTCONDITIONPERIODTYPE-DAYS}
then 1
else if tCopyPaymentCondition.PaymentConditionPeriodType = {&PAYMENTCONDITIONPERIODTYPE-MONTHS}
then 2
else if tCopyPaymentCondition.PaymentConditionPeriodType = {&PAYMENTCONDITIONPERIODTYPE-FORTNIGHT}
then 3
else if tCopyPaymentCondition.PaymentConditionPeriodType = {&PAYMENTCONDITIONPERIODTYPE-WEEK}
then 4
else tct_mstr.ct_from_inv)
tct_mstr.ct_mtd_disc = (if tCopyPaymentCondition.PaymentConditionPdDiscType = {&PAYMENTCONDITIONPERIODTYPE-MONTHS}
then true
else false)
tct_mstr.ct_mtd_due = (if tCopyPaymentCondition.PaymentConditionPeriodType = {&PAYMENTCONDITIONPERIODTYPE-MONTHS}
then true
else false)
tct_mstr.tc_Status = (if tCopyPaymentCondition.tc_Status = "D":U
then tCopyPaymentCondition.tc_Status
else tct_mstr.tc_Status).
end. /* for each tqDomainsPrim: */
end. /* for each tCopyPaymentCondition */
end. /* CONVERTBLOCK */
VALIDATEBLOCK:
DO:
if viLocalReturnStatus < 0
then leave VALIDATEBLOCK.
/* ========== */
/* ValidateBC */
/* ========== */
<M-12 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BMfgCreditTerms>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave VALIDATEBLOCK.
/* ================== */
/* Additional Updates */
/* ================== */
<M-13 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BMfgCreditTerms>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave VALIDATEBLOCK.
/* ======== */
/* DataSave */
/* ======== */
<M-14 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BMfgCreditTerms>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave VALIDATEBLOCK.
end. /* VALIDATEBLOCK */
/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus = viLocalReturnStatus.
Sample code: how to call this method through RPCRequestService (QXtend Inbound)
define temp-table ttContext no-undo
field propertyQualifier as character
field propertyName as character
field propertyValue as character
index entityContext is primary unique
propertyQualifier
propertyName
index propertyQualifier
propertyQualifier.
define dataset dsContext for ttContext.
define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.
/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
ttContext.propertyValue = "BMfgCreditTerms".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiReplicateFromFinancials".
create ttContext.
assign ttContext.propertyName = "applicationId"
ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
ttContext.propertyValue = "".
/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bmfgcreditterms.apireplicatefromfinancials.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icDomainCode = <parameter value>.
vhParameter = vhInputDS:get-buffer-handle("tCopyPaymentCondition").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").
if not vhServer:connected()
then do:
message "Could not connect AppServer" view-as alert-box error title "Error".
return.
end.
/* Run */
assign vhContextDS = dataset dsContext:handle.
run program/rpcrequestservice.p on vhServer
(input-output dataset-handle vhContextDS by-reference,
output dataset-handle vhExceptionDS,
input dataset-handle vhInputDS by-reference,
input-output dataset-handle vhInputOutputDS by-reference,
output dataset-handle vhOutputDS).
/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).
if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).
/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.
if valid-handle(vhInputDS)
then delete object vhInputDS.
if valid-handle(vhOutputDS)
then delete object vhOutputDS.
if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.