project QadFinancials > class BDebtor > method ApiLoadDebtor


Parameters


tApiDebtoroutputtemp-table
tApiDebtorSafDefaultoutputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program9/bdebtor.p)

empty temp-table tApiDebtor.
empty temp-table tApiDebtorSafDefault.
empty temp-table tDebtorIndex.

<Q-5 run DebtorPrim (Start) in BDebtor >
<Q-9 run BLWIGroupPrim (Start) in BBLWIGroup >
<Q-12 run BusinessRelationByIdCode (Start) in BBusinessRelation >
<Q-15 run ProfilePrim (Start) in BProfile >
<Q-18 run CurrencyPrim (Start) in BCurrency >
<Q-20 run DebtorCreditRatingPrim (Start) in BDebtorCreditRating >
<Q-24 run DebtorTypePrim (Start) in BDebtorType >
<Q-30 run PaymentConditionByIdCode (Start) in BPaymentCondition >
<Q-33 run PaymentGroupPrim (Start) in BPaymentGroup >
<Q-40 run ReasonPrim (Start) in BReason >

<Q-1 run DebtorByCompany (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input ?, (DebtorID)
    output dataset tqDebtorByCompany) in BDebtor >

for each tqDebtorByCompany:
    create tApiDebtor.

    <M-2 run BufferCopy
       (input  buffer tqDebtorByCompany:handle (ihFrom), 
        input  buffer tApiDebtor:handle (ihTo), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>

    assign tApiDebtor.tcBillToDebtorCode           = <M-7 ApiLoadDebtorCalcDebtorCode  (input  tApiDebtor.BillToDebtor_ID (iiDebtorId)) in BDebtor>
           tApiDebtor.tcBLWIGroupCode              = <M-8 ApiLoadDebtorCalcBLWIGroupCode
                                                        (input  tApiDebtor.BLWIGroup_ID (iiBLWIGroupId)) in BDebtor>
           tApiDebtor.tcCnControlGLProfileCode     = <M-14 ApiLoadDebtorCalcProfileCode
                                                        (input  tApiDebtor.CnControlGLProfile_ID (iiProfileId)) in BDebtor>
           tApiDebtor.tcCurrencyCode               = <M-17 ApiLoadDebtorCalcCurrencyCode
                                                        (input  tApiDebtor.Currency_ID (iiCurrencyId)) in BDebtor>
           tApiDebtor.tcDebtorCreditRatingCode     = <M-22 ApiLoadDebtorCalcDebtorCreditRatingCode
                                                        (input  tApiDebtor.DebtorCreditRating_ID (iiDebtorCreditRatingId)) in BDebtor>
           tApiDebtor.tcDebtorTypeCode             = <M-23 ApiLoadDebtorCalcDebtorTypeCode
                                                        (input  tApiDebtor.DebtorType_ID (iiDebtorTypeId)) in BDebtor>
           tApiDebtor.tcDivisionProfileCode        = <M-26 ApiLoadDebtorCalcProfileCode
                                                        (input  tApiDebtor.DivisionProfile_ID (iiProfileId)) in BDebtor>
           tApiDebtor.tcFinanceChgProfileCode      = <M-27 ApiLoadDebtorCalcProfileCode
                                                        (input  tApiDebtor.FinChgGLProfile_ID (iiProfileId)) in BDebtor>
           tApiDebtor.tcInvControlGLProfileCode    = <M-28 ApiLoadDebtorCalcProfileCode
                                                        (input  tApiDebtor.InvControlGLProfile_ID (iiProfileId)) in BDebtor>
           tApiDebtor.tcPaymentGroupCode           = <M-32 ApiLoadDebtorCalcPaymentGroupCode
                                                        (input  tApiDebtor.PaymentGroup_ID (iiPaymentGroupID)) in BDebtor>
           tApiDebtor.tcBillScheduleCode           = <M-96 ApiLoadDebtorCalcBillScheduleCode  
                                                        (input  tApiDebtor.BillSchedule_ID (iiBillScheduleID)) in BDebtor>
           tApiDebtor.tcEmployeeCode               = <M-97 ApiLoadDebtorCalcEmployeeCode  
                                                        (input  tApiDebtor.Employee_ID (iiEmployeeID)) in BDebtor>
           tApiDebtor.tcDeductionCtrlGLProfileCode = <M-61 ApiLoadDebtorCalcProfileCode  
                                                        (input  tApiDebtor.DeductionCtrlGLProfile_ID (iiProfileId)) in BDebtor>
           tApiDebtor.tcPrepayControlGLProfileCode = <M-38 ApiLoadDebtorCalcProfileCode
                                                        (input  tApiDebtor.PrePayControlGLProfile_ID (iiProfileId)) in BDebtor>
           tApiDebtor.tcReasonCode                 = <M-39 ApiLoadDebtorCalcReasonCode
                                                        (input  tApiDebtor.Reason_ID (iiReasonId)) in BDebtor>
           tApiDebtor.tcSalesAccountGLProfileCode  = <M-42 ApiLoadDebtorCalcProfileCode
                                                        (input  tApiDebtor.SalesAccountGLProfile_ID (iiProfileId)) in BDebtor>
           tApiDebtor.tc_ParentRowid               = "":U
           tApiDebtor.tc_Status                    = "":U.

    if tApiDebtor.BusinessRelation_ID = ? or
       tApiDebtor.BusinessRelation_ID = 0
    then assign tApiDebtor.tcBusinessRelationCode      = "":U
                tApiDebtor.tcBusinessRelationName1     = "":U
                tApiDebtor.tlBusinessRelationIsInterco = false.
    else do:
        <Q-11 run BusinessRelationByIdCode (all) (Read) (Cache)
           (input tApiDebtor.BusinessRelation_ID, (BusinessRelationId)
            input ?, (BusinessRelationCode)
            output dataset tqBusinessRelationByIdCode) in BBusinessRelation >

        find first tqBusinessRelationByIdCode where
                   tqBusinessRelationByIdCode.tiBusinessRelation_ID = tApiDebtor.BusinessRelation_ID
                   no-error.

        assign tApiDebtor.tcBusinessRelationCode      = if available tqBusinessRelationByIdCode
                                                        then tqBusinessRelationByIdCode.tcBusinessRelationCode
                                                        else "":U
               tApiDebtor.tcBusinessRelationName1     = if available tqBusinessRelationByIdCode
                                                        then tqBusinessRelationByIdCode.tcBusinessRelationName1
                                                        else "":U
               tApiDebtor.tlBusinessRelationIsInterco = if available tqBusinessRelationByIdCode
                                                        then tqBusinessRelationByIdCode.tlBusinessRelationIsInterco
                                                        else false.
    end.

    if tApiDebtor.NormalPaymentCondition_ID = ? or
       tApiDebtor.NormalPaymentCondition_ID = 0
    then assign tApiDebtor.tcNormalPaymentConditionCode = "":U
                tApiDebtor.tcNormalPaymentConditionType = "":U.
    else do:
        <Q-29 run PaymentConditionByIdCode (all) (Read) (Cache)
           (input tApiDebtor.NormalPaymentCondition_ID, (PaymentConditionId)
            input ?, (PaymentConditionCode)
            output dataset tqPaymentConditionByIdCode) in BPaymentCondition >

        find first tqPaymentConditionByIdCode where
                   tqPaymentConditionByIdCode.tiPaymentCondition_ID = tApiDebtor.NormalPaymentCondition_ID
                   no-error.

        assign tApiDebtor.tcNormalPaymentConditionCode = if available tqPaymentConditionByIdCode
                                                         then tqPaymentConditionByIdCode.tcPaymentConditionCode
                                                         else "":U
               tApiDebtor.tcNormalPaymentConditionType = if available tqPaymentConditionByIdCode
                                                         then tqPaymentConditionByIdCode.tcPaymentConditionPaymentTyp
                                                         else "":U.
    end.

    /* =================================================================================== */
    /* Hold a similar record in table DebtorIndex; this table contains the tc_rowid and    */
    /* Debtor_ID with and index on DebtorID. This is needed because we will perform        */
    /* several finds later on to get the tc_rowid of the Debtor                            */
    /* =================================================================================== */
    create tDebtorIndex.

    assign tDebtorIndex.tiDebtorID = tqDebtorByCompany.tiDebtor_ID
           tDebtorIndex.tcRowID    = tqDebtorByCompany.tc_Rowid.
end.

<Q-41 run ReasonPrim (Stop) in BReason >
<Q-34 run PaymentGroupPrim (Stop) in BPaymentGroup >
<Q-31 run PaymentConditionByIdCode (Stop) in BPaymentCondition >
<Q-25 run DebtorTypePrim (Stop) in BDebtorType >
<Q-21 run DebtorCreditRatingPrim (Stop) in BDebtorCreditRating >
<Q-19 run CurrencyPrim (Stop) in BCurrency >
<Q-16 run ProfilePrim (Stop) in BProfile >
<Q-13 run BusinessRelationByIdCode (Stop) in BBusinessRelation >
<Q-10 run BLWIGroupPrim (Stop) in BBLWIGroup >
<Q-6 run DebtorPrim (Stop) in BDebtor >

<Q-3 run DebtorSafDefaultByDebtorSafDef (all) (Read) (NoCache)
   (input ?, (DebtorSafDefaultID)
    output dataset tqDebtorSafDefaultByDebtorSafDef) in BDebtor >

for each tqDebtorSafDefaultByDebtorSafDef,
    first tDebtorIndex where
          tDebtorIndex.tiDebtorID = tqDebtorSafDefaultByDebtorSafDef.tiDebtor_ID:
    create tApiDebtorSafDefault.

    <M-4 run BufferCopy
       (input  buffer tqDebtorSafDefaultByDebtorSafDef:handle (ihFrom), 
        input  buffer tApiDebtorSafDefault:handle (ihTo), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>

    assign tApiDebtorSafDefault.tc_ParentRowid = tDebtorIndex.tcRowID
           tApiDebtorSafDefault.tc_Rowid       = entry(1, tqDebtorSafDefaultByDebtorSafDef.tc_rowid)
           tApiDebtorSafDefault.tc_Status      = "":U.
end.


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 = "BDebtor".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiLoadDebtor".
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 = "".

/* 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.