project QadFinancials > class BPaymentSelection > method APITransferPayments

Description

This method used to generate the bank dirver file for the first time


Parameters


tPaySelRefinputtemp-table
tCCollectionPaySeloutputtemp-table
tPaySelHistoryRefoutputtemp-table
icTransferFilePathinputcharacterTransferFilePath
ilIsIndividualInvoicesinputlogical
ilClearDatainputlogical
iiBankGL_IDinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bpaymentselection.p)

/* Change - WouAnt - 3 06 2005 : The field Individual Invoices should not be selected from 
Transfer activity. This indicator indicates if Grouping is allowed or not - and according to us 
it is always allowed and is depending on Creditor setting */
assign ilIsIndividualInvoices = NO. 

assign vcActivityCode = {&PAYMENTSELECTIONACTIVITY-EXECUTE}.

empty temp-table tCDocumentPaySel.
empty temp-table tCDocumentInvoiceXRefPaySel.

/* Where the references would not be complette in the ascii, these can be listed in remittance print 
   - every format to handle in specific way - but through the tExportReferences table */
empty temp-table tExportReferences.

assign vlIsDuplicate    = false.

/* first clear the instance, otherwise problems when you execute it twice */
if ilClearData
then do:
    <M-17 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
    if oiReturnStatus < 0 then return.
end.

for each tPaySelRef:
    find first tPaySel where 
               tPaySel.PaySel_ID = tPaySelRef.PaySel_ID 
               no-error.
    if not available tPaySel
    then do:
        if vcList = "":U
        then vcList = string (tPaySelRef.PaySel_ID).
        else if lookup (string(tPaySelRef.PaySel_ID),vcList,chr(4)) = 0
             then vcList = vcList + chr(4) + string (tPaySelRef.PaySel_ID).
    end.
end.    
if vcList = "" 
then do:
   <M-24 run SetMessage
      (input  #T-29'Invalid selection Code Entered':255(786893276)T-29# (icMessage), 
       input  '' (icArguments), 
       input  '' (icFieldName), 
       input  '' (icFieldValue), 
       input  '':U (icType), 
       input  2 (iiSeverity), 
       input  '' (icRowid), 
       input  'qadfin-269952':U (icFcMsgNumber), 
       input  '' (icFcExplanation), 
       input  '' (icFcIdentification), 
       input  '' (icFcContext), 
       output oiReturnStatus (oiReturnStatus)) in BPaymentSelection>
end.    

<M-11 run DataLoad
   (input  '':U (icRowids), 
    input  vcList (icPkeys), 
    input  '':U (icObjectIds), 
    input  '' (icFreeform), 
    input  no (ilKeepPrevious), 
    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>       
if viFcReturnSuper <> 0
then do:
    <M-12 run SetMessage
       (input  #T-46'The data could not be loaded. The system was unable to modify the payment selection.':100(2965)t-46# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  '':U (icType), 
        input  2 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-1075':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
    
    assign oiReturnStatus = -1.
    return.
end.

/* Set the Status to Transferred */
for each tPaySel:
    assign tPaySel.PaySelStatus = {&PAYMENTSELECTIONSTATUS-TRANSFERRED}
           tPaySel.tc_Status    = (if tPaySel.tc_Status = "":U
                                   then "C":U
                                   else tPaySel.tc_Status).
end. /* for each */

/* Validate all payment selections have the same bankaccount */
if iiBankGL_ID = ? or iiBankGL_ID = 0
then do:
    find first tPaySel no-error.
    if available tPaySel
    then assign iiBankGL_ID = tPaySel.GL_ID.           
    
    if iiBankGL_ID <> 0 and iiBankGL_ID <> ?
    then do:
        find first tPaySel where
                   tPaySel.tc_Status <> '':U and
                   tPaySel.GL_ID     <> iiBankGL_ID
                   no-error.
        if available tPaySel
        then do:
            <M-43 run SetMessage
               (input  #T-47'Payment selections with multiple bank accounts were found.':100(2966)t-47# (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'D':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QADFIN-2518':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
            assign oiReturnStatus = - 1.
            return.                     
        end.           
    end.
end.

/* Execution Date check */
find first tPaySel where
           tPaySel.tc_Status <> '':U no-error.
if available tPaySel
then do:
    if can-find (tPaySel where
                 tPaySel.tc_Status  <> '':U and
                 tPaySel.tc_Rowid   <> tPaySel.tc_Rowid and
                 tPaySel.PaySelDate <> tPaysel.PayselDate)
    then do:
        <M-45 run SetMessage (input  #T-48'Payment selections with multiple execution dates were found.':100(2967)t-48# (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'D':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-2676':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
        assign oiReturnStatus = - 1.
        return.                     
    end.               
end.

/* No recreation of CCollection or CDocument records */
empty temp-table tCDocumentInfoForCollection.
empty temp-table tCCollectionPaySel.
empty temp-table tUpdateCDocumentColl.

assign viCDocXrefSequence = 0.
/* check with query calls because it's run from execute, and everything is done on register */
/* go to document for this paysel_id, then go to collection and then do everything */

<Q-72 run CDocumentByPaySelId (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input tPaySel.PaySel_ID, (PaySelId)
    output dataset tqCDocumentByPaySelId) in BCDocument >

for each tPaySel,
    each tPaySelLine where
         tPaySelLine.tc_ParentRowid = tPaySel.tc_Rowid:
        
    /* ------------------------------------------ */
    /* Open Amounts - Necessary for Validations   */
    /* We cannot check open balances of linked    */
    /* OI because they can differ from the moment */
    /* of registration                            */
    /* ------------------------------------------ */
    assign tPaySelLine.tdOpenInvoiceAmountTC = tPaySelLine.PaySelLineAmountTC.     

   
    for each tqCDocumentByPaySelId where tqCDocumentByPaySelId.tiPaySelLine_ID = tPaySelLine.PaySelLine_ID:
        find first tCDocumentInfoForCollection where
                   tCDocumentInfoForCollection.tiCDocument_ID      = tqCDocumentByPaySelId.tiCDocument_ID and
                   tCDocumentInfoForCollection.tcPayFormatTypeCode = tPaySelLine.PayFormatTypeCode
                   no-error.
        if not available tCDocumentInfoForCollection
        then do:
            create tCDocumentInfoForCollection.
            assign tCDocumentInfoForCollection.tiCDocument_ID      = tqCDocumentByPaySelId.tiCDocument_ID
                   tCDocumentInfoForCollection.tcPayFormatTypeCode = tPaySelLine.PayFormatTypeCode
                   tCDocumentInfoForCollection.tiOldColl_Id        = tqCDocumentByPaySelId.tiCCollection_ID
                   tCDocumentInfoForCollection.tcGLCode            = tqCDocumentByPaySelId.tcGLCode
                   tCDocumentInfoForCollection.tiGLId              = tqCDocumentByPaySelId.tiGL_ID
                   tCDocumentInfoForCollection.ttPaySelDate        = tPaySel.PaySelDate
                   /* the bc amount is the correct one */
                   tCDocumentInfoForCollection.tdCreditAmountTC    = tqCDocumentByPaySelId.tdCDocumentOriginalCreditBC
                   tCDocumentInfoForCollection.tdCreditAmountLC    = tqCDocumentByPaySelId.tdCDocumentOriginalCreditLC
                   tCDocumentInfoForCollection.tdCreditAmountCC    = tqCDocumentByPaySelId.tdCDocumentOriginalCreditCC
                   tCDocumentInfoForCollection.tiPaySelLineId      = tqCDocumentByPaySelId.tiPaySelLine_ID
                   tCDocumentInfoForCollection.tiPaySel_ID         = tPaySel.PaySel_ID.
        end.

        create tCDocumentInvoiceXRefPaySel.
        assign viCDocXrefSequence                                      = viCDocXrefSequence + 1
               tCDocumentInvoiceXrefPaySel.PaySelLine_ID               = tPaySelLine.PaySelLine_ID
               tCDocumentInvoiceXRefPaySel.CDocument_ID                = tqCDocumentByPaySelId.tiCDocument_ID
               tCDocumentInvoiceXrefPaySel.CDocumentInvoiceXrefAlloTC  = if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR}
                                                                         then tPaySelLine.PaySelLineAmountTC + tPaySelLine.PaySelLineDiscountTC
                                                                         else if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR}
                                                                              then -(tPaySelLine.PaySelLineAmountTC + tPaySelLine.PaySelLineDiscountTC)
                                                                              else abs(tPaySelLine.PaySelLineAmountTC) + abs(tPaySelLine.PaySelLineDiscountTC)
               tCDocumentInvoiceXrefPaySel.CDocumentInvoiceXrefDiscTC  = if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR}
                                                                         then tPaySelLine.PaySelLineDiscountTC
                                                                         else if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR}
                                                                              then -(tPaySelLine.PaySelLineDiscountTC)
                                                                              else abs(tPaySelLine.PaySelLineDiscountTC)
               tCDocumentInvoiceXRefPaySel.CInvoice_ID                 = tPaySelLine.PaySelLineParentObject_ID
               tCDocumentInvoiceXrefPaySel.tc_Rowid                    = string(viCDocXrefSequence)
               tCDocumentInvoiceXrefPaySel.tc_Status                   = 'N':U.
    end.
end. /* for each tPaySel, */




/* old collections must be updated */
for each tCDocumentInfoForCollection where
         tCDocumentInfoForCollection.tiOldColl_Id <> 0 and
         tCDocumentInfoForCollection.tiOldColl_Id <> ? 
    break by tCDocumentInfoForCollection.tiOldColl_Id:
    
    if first-of(tCDocumentInfoForCollection.tiOldColl_Id)
    then do:
        find first tCCollectionPaySel where
                   tCCollectionPaySel.CCollection_ID = tCDocumentInfoForCollection.tiOldColl_Id
                   no-error.
        if not available tCCollectionPaySel
        then do:
            create tCCollectionPaySel.
            assign viSeq                                       = viSeq + 1
                   tCCollectionPaySel.Company_ID               = viCompanyId
                   tCCollectionPaySel.CCollection_ID           = tCDocumentInfoForCollection.tiOldColl_Id
                   tCCollectionPaySel.GL_ID                    = tCDocumentInfoForCollection.tiGLId
                   tCCollectionPaySel.tcGLCode                 = tCDocumentInfoForCollection.tcGLCode
                   tCCollectionPaySel.tiPaySel_ID              = tCDocumentInfoForCollection.tiPaySel_ID
                   tCCollectionPaySel.tcPayFormatType          = tCDocumentInfoForCollection.tcPayFormatTypeCode
                   tCCollectionPaySel.CCollectionRequestedDate = tCDocumentInfoForCollection.ttPaySelDate 
                   tCCollectionPaySel.tc_Status                = "D":U /* not really delete just a signal to identify from the update from Cdoucment */
                   tCCollectionPaySel.tc_Rowid                 = string(viSeq)
                   tCCollectionPaySel.CCollectionIsExecuted    = true
                   tCCollectionPaySel.CCollectionIsAutomatic   = true.
        end.
    end.
end.

if can-find(first tCCollectionPaySel)
then do:
    if viBCCollectionPaySelID = 0 or viBCCollectionPaySelID = ?
    then do:
        <I-27 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BCCollection"}>
        assign vlBCCollIsStartedFromPaySel = true.
    end.
    else do:
        <I-28 {bFcOpenInstance
            &CLASS           = "BCCollection"}>
    end.
     <M-29 run UpdateCCollection
        (input-output tCCollectionPaySel (tCCollectionsToUpdate), 
         input  false (ilClearData), 
         input  true (ilUpdateFromPaySel), 
         input  false (ilResetPaySelId), 
         output viFcReturnSuper (oiReturnStatus)) in BCCollection>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then do:
        <I-50 {bFcCloseInstance
            &CLASS           = "BCCollection"}> 
        <M-54 run StopExternalInstances
           (output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
        return.
    end.

    if vlBCCollIsStartedFromPaySel
    then do:
        <M-37 run ValidateBCAndAdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BCCollection>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then do:
            <I-51 {bFcCloseInstance
            &CLASS           = "BCCollection"}> 
            <M-55 run StopExternalInstances
               (output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
            return.
        end.
    end.

    /* ========================================================================================================= */
    /* Normally we would here close BCCollection but we will not do it for performance                           */
    /* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it.     */
    /* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the  */
    /* appserver that is executed after each call to the appserver                                               */
    /* ========================================================================================================= */
                        
    for each tCCollectionPaySel where
             tCCollectionPaySel.tc_Status <> "D":U:
        for each tCDocumentInfoForCollection where
                 tCDocumentInfoForCollection.tcPayFormatTypeCode = tCCollectionPaySel.tcPayFormatType :
            create tUpdateCDocumentColl.
            assign tUpdateCDocumentColl.tiCDocumentId      = tCDocumentInfoForCollection.tiCDocument_ID
                   tUpdateCDocumentColl.tiNewCCollectionId = tCCollectionPaySel.CCollection_ID.
        end.
    end.
end.

/* Generate Ascii */
<M-23 run GenerateASCII (input  iiBankGL_ID (iiBankGL_ID), 
                 input  ilIsIndividualInvoices (ilisIndividualInvoices), 
                 input  false (ilisRepetitiveTransfer), 
                 output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0 
then do:
    /* let's remove the files if the action was not completted ok */
    for each tCCollectionPaySel where
             tCCollectionPaySel.tc_Status <> '':U
             break by tCCollectionPaySel.tcOutputFileName:
        if first-of(tCCollectionPaySel.tcOutputFileName) and
           search(tCCollectionPaySel.tcOutputFileName) <> ?
        then os-delete value(tCCollectionPaySel.tcOutputFileName).
    end.
    return.
end.
    
<M-15 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0 
then do:
    /* let's remove the files if the action was not completted ok */
    for each tCCollectionPaySel where
             tCCollectionPaySel.tc_Status <> '':U
             break by tCCollectionPaySel.tcOutputFileName:
        if first-of(tCCollectionPaySel.tcOutputFileName) and
           search(tCCollectionPaySel.tcOutputFileName) <> ?
        then os-delete value(tCCollectionPaySel.tcOutputFileName).
    end.
    return.
end.


<M-16 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0 
then do:
    /* let's remove the files if the action was not completted ok */
    for each tCCollectionPaySel where
             tCCollectionPaySel.tc_Status <> '':U
             break by tCCollectionPaySel.tcOutputFileName:
        if first-of(tCCollectionPaySel.tcOutputFileName) and
           search(tCCollectionPaySel.tcOutputFileName) <> ?
        then os-delete value(tCCollectionPaySel.tcOutputFileName).
    end.
    return.
end.


<M-57 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0 
then do:
    /* let's remove the files if the action was not completted ok */
    for each tCCollectionPaySel where
             tCCollectionPaySel.tc_Status <> '':U
             break by tCCollectionPaySel.tcOutputFileName:
        if first-of(tCCollectionPaySel.tcOutputFileName) and
           search(tCCollectionPaySel.tcOutputFileName) <> ?
        then os-delete value(tCCollectionPaySel.tcOutputFileName).
    end.
    return.
end.

for each tPaySelHistory:
    create tPaySelHistoryRef.
    buffer-copy tPaySelHistory to tPaySelHistoryRef.
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 = "BPaymentSelection".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "APITransferPayments".
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/bpaymentselection.apitransferpayments.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icTransferFilePath = <parameter value>
       vhParameter::ilIsIndividualInvoices = <parameter value>
       vhParameter::ilClearData = <parameter value>
       vhParameter::iiBankGL_ID = <parameter value>.

vhParameter = vhInputDS:get-buffer-handle("tPaySelRef").
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.