project QadFinancials > class BCurrency > method ApiSynchronise

Description

System Procedure ApiSynchronise to synchronise the Currencies database-records.


Parameters


olUpdatesDoneoutputlogicalThis output parameter will return true if a db-update was done within the method.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BSystem.ApiSynchroniseCustom2


program code (program9/bcurrency.p)

/* ======================== */
    /* Set default ReturnStatus */
    /* Clear the instance       */
    /* ======================== */
    assign oiReturnStatus = -98.
    <M-11 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BCurrency>
    if viFcReturnSuper <> 0 
    then do :
        assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0 then return.
    end. /* if viFcReturnSuper <> 0 */

    /* ================================= */
    /* Read once all existing currencies */
    /* ================================= */
    <Q-16 run CurrencyPrim (all) (Read) (NoCache)
          (input ?, (CurrencyCode)
           input ?, (Currency_ID)
           output dataset tqCurrencyPrim) in BCurrency >

    /* ======================================================================================== */
    /* Create new, inactive currencies for all not-yet existing ISO-currencies (Except for EUR) */
    /* ======================================================================================== */
    /* Note: this information comes from following site: www.thefinancials.com ; http://www.thefinancials.com/vortex/CurrencyFormatsTable.html */
    assign vcISOCurrencies = "Afghanistan Afghani,AFA,0,Albania Lek,ALL,2,Algerian Dinar,DZD,2,Angola New Kwanza,AON,0,Argentina Peso,ARS,2,Armenia Dram,AMD,2,Aruban Florin,AWG,2,Australian Dollar,AUD,2,Austrian Schilling,ATS,2,Azerbaijani Manat,AZM,2,Bahamian Dollar,BSD,2,Bahraini Dinar,BHD,3,Bangladesh Taka,BDT,2,Barbados Dollar,BBD,2,Belarussian Rouble,BYR,0,Belgium Franc,BEF,0,Belize Dollar,BZD,2,Bermudian Dollar,BMD,2,Bhutan Ngultrum,BTN,2,Bolivian Boliviano,BOB,2,Bosnian Convertible Mark,BAM,2,Botswana Pula,BWP,2,Brazilian Real,BRL,2,British Sterling,GBP,2,Brunei Dollar,BND,2,Bulgaria Lev,BGL,2,Burundi Franc,BIF,0,Cambodia Riel,KHR,2,Canadian Dollar,CAD,2,Cayman Islands Dollar,KYD,2,CFP Franc,XPF,0,Chilean Peso,CLP,0,Chinese Renminbi Yuan,CNY,2,Colombian Peso,COP,2,Comorian Franc,KMF,0,Congo - Dem. Rep. Franc,CDF,2,Costa Rican Colon,CRC,2,Croatia Kuna,HRK,2,Cuban Peso,CUP,2,Cypriot Pound,CYP,2,Czech Koruna,CZK,2,Danish Krone,DKK,2,Deutsche Mark,DEM,2,Djibouti Franc,DJF,0,Dominican Republic Peso,DOP,2,Dutch Guilder,NLG,2,East Caribbean Dollar,XCD,2,Ecuador Sucre,ECS,0,Egyptian Pound,EGP,2,El Salvadorian Colón,SVC,0,Eritrea - Nakfa,ERN,0,Escudo Caboverdiano,CVE,0,Estonia Kroon,EEK,2,Ethiopia Birr,ETB,0,Euro,EUR,2,Falkland Pound,FKP,0,Fiji Dollar,FJD,0,Finnish Markka,FIM,2,French Franc,FRF,2,Gambia Dalasi,GMD,0,Georgia - Lari,GEL,0,Ghana Cedi,GHC,2,Gibraltar Pound,GIP,2,Greek Drachma,GRD,2,Guatemala Quetzal,GTQ,0,Guyana Dollar,GYD,0,Haiti Gourde,HTG,0,Honduras Lempira,HNL,2,Hong Kong Dollar,HKD,2,Hungary Forint,HUF,0,Icelandic Króna,ISK,2,Indian Rupee,INR,2,Indonesia Rupiah,IDR,0,Iranian Riyal,IRR,2,Iraqi Dinar,IQD,3,Irish Punt,IEP,2,Israel Shekel,ILS,2,Italian Lira,ITL,0,Jamaican Dollar,JMD,2,Japanese Yen,JPY,0,Jordanian Dinar,JOD,3,Kazakhstan Tenge,KZT,0,Kenyan Shilling,KES,2,Kuwaiti Dinar,KWD,3,Kyrgyzstan - Som,KGS,0,Laos Kip,LAK,0,Latvia Lat,LVL,2,Lebanese Pound,LBP,0,Lesotho Maloti,LSL,0,Liberian Dollar,LRD,0,Libyan Dinar,LYD,0,Lithuania Litas,LTL,2,Luxembourg Franc,LUF,0,Macao Pataca,MOP,0,Macedonian Denar,MKD,2,Malagasy Franc,MGF,0,Malawian Kwacha,MWK,2,Malaysian Ringgit,MYR,2,Maldives Rufiyaa,MVR,0,Maltese Lira,MTL,2,Mauritania Ouguiya,MRO,0,Mauritius Rupee,MUR,0,Mexican Peso,MXN,2,Moldovian Leu,MDL,0,Mongolia Tugrik,MNT,0,Moroccan Dirham,MAD,0,Mozambique Metical,MZM,2,Myanmar Kyat,MMK,0,Namibian Dollar,NAD,0,Nepalese Rupee,NPR,2,New Zealand Dollar,NZD,2,Nicaragua Córdoba,NIO,0,Nigeria Naira,NGN,0,North Korean Won,KPW,0,Norwegian Krone,NOK,2,Pakistani Rupee,PKR,2,Panama Balboa,PAB,0,Papua New Guinea Kina,PGK,0,Paraguay Guarani,PYG,0,Peru New Sol,PEN,2,Philippine Peso,PHP,2,Poland New Zloty,PLN,2,Portuguese Escudo,PTE,0,Qatari Riyal,QAR,0,Riyal Omani,OMR,3,Romanian Leu,ROL,2,Russian Federation Ruble,RUB,2,Rwanda Franc,RWF,0,S. African Rand Commerc.,SAC,0,Saudi Riyal,SAR,2,Serbian Dinar,CSD,0,Seychelles Rupee,SCR,0,Sierra Leone Leone,SLL,0,Singapore Dollar,SGD,2,Slovak Koruna,SKK,2,Slovenia Tolar,SIT,2,Solomon Islands Dollar,SBD,0,Somali Shilling,SOS,0,South African Rand,ZAR,2,South Korean Won,KRW,0,Spanish Peseta,ESP,0,Sri Lankan Rupee,LKR,0,St Helena Pound,SHP,0,Sudanese Dinars,SDD,0,Sudanese Pound,SDP,0,Surinam Guilder,SRG,0,Swaziland Lilangeni,SZL,0,Swedish Krona,SEK,2,Swiss Franc,CHF,2,Syrian Pound,SYP,0,Taiwanese NT Dollar,TWD,0,Tajikistan - Ruble,TJR,0,Tanzanian Shilling,TZS,2,Thailand Baht,THB,2,Tongan Pa'anga,TOP,2,Tunisia Tunisian Dinar,TND,3,Turkish Lira,TRL,0,Turkish New Lira,TRY,0,Turkmenistan - Manat,TMM,0,UAE Dirham,AED,2,Ugandian Shilling,UGX,0,Ukraine Hryvna,UAH,2,Uruguayan Peso,UYU,2,US Dollar,USD,2,Uzbekistani Sum,UZS,0,Vanuatu Vatu,VUV,0,Venezuela Bolivar,VEB,2,Vietnam Dong,VND,0,Western Samoa Tala,WST,0,Yemen Riyal,YER,0,Zambian Kwacha,ZMK,0,Zimbabwe Dollar,ZWD,2":U.
    
    /* WouAnt - Let's make only EUR and USD */
    /* Note: since we need to define the corresponding rounding method, 
     *       the third entry for the currency should denote rounding method code
     */
    assign vcISOCurrencies = "Euro,EUR,2,US Dollar,USD,2":U.
    /* WouAnt - Let's make only EUR and USD */
    
    if num-entries(vcISOCurrencies) modulo 3 <> 0
    then do :
        assign vcMessage      = trim(#T-18'Internal error on the synchronization of ISO currencies. The list of currencies must contain the description, the code, and the number of decimals.':255(1591)t-18#) + chr(10) + 
                                trim(substitute(#T-19'List of ISO currencies: &1':255(1592)T-19#,vcISOCurrencies))
               oiReturnStatus = -3.
        <M-12 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-2913':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BCurrency> 
        Return.
    end. /* if num-entries(vcISOCurrencies) modulo 3 <> 0 */

    do viISOCounter = num-entries(vcISOCurrencies) to 1 by -3 :
   
        assign vcCurrencyCode        = entry(viISOCounter - 1,vcISOCurrencies)
               vcCurrencyDescription = substring(entry(viISOCounter - 2,vcISOCurrencies),1,40,"CHARACTER":U)               
               no-error.

        if error-status:error
        then do :
            assign vcMessage      = trim(#T-20'Internal error on the synchronization of ISO currencies. Cannot extract the correct information from the list of ISO currencies.':255(1593)t-20#) + chr(10) + 
                                    trim(substitute(#T-21'Currency code: &1.':255(1594)T-21#,vcCurrencyCode)) + chr(10) + 
                                    trim(substitute(#T-22'Currency description: &1.':255(1595)T-22#,vcCurrencyDescription)) + chr(10) + 
                                    trim(substitute(#T-23'Number of decimals: &1.':255(1596)T-23#,viCurrencyNumDec)) + chr(10) + 
                                    (if ERROR-STATUS:NUM-MESSAGES > 0
                                     then trim(substitute(#T-24'Error message: &1':255(1597)T-24#,ERROR-STATUS:GET-MESSAGE(1))) + chr(10)  
                                     else "":U) + 
                                    trim(substitute(#T-25'List of ISO currencies: &1':255(1592)T-25#,vcISOCurrencies))
                   oiReturnStatus = -3.
            <M-13 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-2914':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BCurrency> 
            Return. 
        end. /* if error-status:error */
        
        if can-find (tqCurrencyPrim where
                     tqCurrencyPrim.tcCurrencyCode = vcCurrencyCode)
        then next.               
              
        <M-14 run AddDetailLine (input  'Currency':U (icTable), 
                         input  '':U (icParentRowid), 
                         output viFcReturnSuper (oiReturnStatus)) in BCurrency>
        if viFcReturnSuper <> 0 
        then do :
            assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0 then return.
        end. /* if viFcReturnSuper <> 0 */
        
        assign tCurrency.CurrencyCode               = vcCurrencyCode
               tCurrency.CurrencyDescription        = vcCurrencyDescription
               tCurrency.CurrencyIsActive           = (vcCurrencyCode = 'EUR':U or vcCurrencyCode = 'USD':U).
               
        <Q-26 run RoundingMethodPrim (all) (Read) (NoCache)
           (input ?, (RoundingMethodID)
            input entry(viISOCounter,vcISOCurrencies), (RoundingMethodCode)
            output dataset tqRoundingMethodPrim) in BRoundingMethod > 
            
        for first tqRoundingMethodPrim:
           assign tCurrency.RoundingMethod_ID    = tqRoundingMethodPrim.tiRoundingMethod_ID
                  tCurrency.tcRoundingMethodCode = tqRoundingMethodPrim.tcRoundingMethodCode
                  vhFcComponent = ?.

           <M-27 run CalculateNumberOfDecimals
              (input  tqRoundingMethodPrim.tdRoundingMethodUnit (idRoundingMethodUnit), 
               output tCurrency.CurrencyNumberOfDecimals (odNumberOfDecimals), 
               output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>                                                          
        end.
                
    end. /* do viISOCounter = num-entries(vcISOCurrencies) to 1 by -3 */
 
    /* ============================ */
    /* Return in case of no actions */
    /* ============================ */
    if not can-find (first tCurrency where 
                           tCurrency.tc_Status <> "":U)
    then do :
        assign oiReturnStatus = 0.
        Return.
    end. /* if not can-find (first tCurrency where */   

    /* ==================================== */
    /* Validate, AdditionalUpdates and Save */
    /* ==================================== */
    <M-7 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BCurrency>
    if viFcReturnSuper <> 0 
    then do :
        assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0 then return.
    end. /* if viFcReturnSuper <> 0 */
    <M-8 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BCurrency>
    if viFcReturnSuper <> 0 
    then do :
        assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0 then return.
    end. /* if viFcReturnSuper <> 0 */
    <M-9 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BCurrency>
    if viFcReturnSuper <> 0 
    then do :
        assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0 then return.
    end. /* if viFcReturnSuper <> 0 */

    /* ==================================== */
    /* Indacte that changes have been done  */
    /* ==================================== */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.
    assign olUpdatesDone = true.


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