local ss = analiz.libs.serv
 

-- ver1.0: doc:F:\p\FINNIOVA_PRJs\V5\finnova_examples\v4\doc\ Integration_CF_in_Finnova_en_V1.0.docx
-- verX    doc:F:\p\FINNIOVA_PRJs\V5\finnova_examples\v2\doc\ Integration_CF_in_Finnova_en.docx
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
if analiz.mix==nil then analiz.mix={} end
if analiz.mix.finnova==nil then analiz.mix.finnova={} end
if analiz.mix.finnova.serv==nil then analiz.mix.finnova.serv={} end

local finn_serv =analiz.mix.finnova.serv

local mt_serv={}

local function dlog(function_name,msg)
  if 1==1 then return end
  ss.l(function_name..":"..msg)
end
-- ----------------------------------------------------------------------------
local function extractCode(line)
 if line:len()<4 then dlog("extractCode","line is empty") return nil end
 if line:sub(1,1)~=":" then dlog("extractCode","first is not :") return nil end
 local last = 3
 local last_max = 5
 while last<=last_max do
   if line:sub(last,last)==":" then
    return line:sub(2,last-1),last+1
  end
  last = last+1
 end
dlog("extractCode","not found code")
 return nil
end
-- ----------------------------------------------------------------------------
local function parseLine(i,lines)
   local l = lines[i]
   if l=="" then return i+1 end
   local code, r = extractCode(l)

dlog("parseLine",l.." code:"..ss.def(code,"nil").." next:"..ss.def(r,"nil"))
   if code==nil then return i+1 end
   local text = l:sub(r,l:len())
dlog("parseLine","first text:"..text) 
   
   i=i+1
   local count=1
   while i<=#lines do
     l = lines[i]
     local code_n, r = extractCode(l)
     if code_n~=nil then return i,code,text end
     local num = "/"..ss.IntToStr(count)
--     ss.l("check.num:"..num .." string :"..l)
     local vv = l:find(num)
--     ss.l("find:"..ss.def(v,"nul")) 
     if vv==1 then  l = l:sub(num:len()+1,l:len()) end
     text=text.."\n"..l
     i=i+1        
     count=count+1
   end
  return i,code,text 
end

function ParseMT_X(xml_str,prop)
 if xml_str:find("\r")~=nil then 
  xml_str=ss.ReplaceValue(xml_str,"\r","")
 end
 local lines = ss.mysplit(xml_str,"\n")
-- ss.tprint(lines)
 local i = 1 
 local cache = {}
 while i<=#lines do
   i,code,item = parseLine(i,lines)
   if code~=nil then 
      local c = cache[code]
      if c== nil then c= {} cache[code]=c end
      c[#c+1]=item
   end
 end
 return cache
end

-- ---------------------------------------------------------------------
-- ---------------------------------------------------------------------
-- ---------------------------------------------------------------------
local function removeSlashWord_(val)
  local new_val= RemoveSlashWord(val)
--  ss.l("removeSlashWord_.r:"..new_val)
  if new_val:sub(1,1)=="\n" then ss.l("!!!!")new_val=new_val:sub(2) end
--  ss.l("removeSlashWord_.2:"..new_val)

  return new_val
end
local function parse_FirstAndOther_v2(val)
  if val=="" or val==nil then return "","" end
  -- ao: remove word start with /
--ss.l("parse_FirstAndOther_v2.before:"..val)
  val = removeSlashWord_(val)
--ss.l("parse_FirstAndOther_v2.other:"..val)
  local f = val:find("\n")
  if f==nil then return val,"" end
  return val:sub(1,f-1),val:sub(f+1)
end


local function parse_FirstAndOther_(val)
  if val=="" or val==nil then return "","" end
  local f = val:find("\n")
  if f==nil then return val,"" end
  return val:sub(1,f-1),val:sub(f+1)
end

-- Check that `val` contains something useful.
local function checkvalidNameOrAdress_(val)
  local function check(v)
   if v==nil then return false end
   if v=="" then return false end
   return ""
  end

  local is_name = check(val.lastname)
  local is_addr = check(val.address)
  return is_addr or is_name
end

local function get_(cache,code,def_value)
  local i = cache[code]
  if i==nil then return def_value end
  return i[1]
end


local bic_parser =nil
local function ExtractSwiftCode_(o, cache,ii, doc_writer)
    if doc_writer ~= nil then
        doc_writer:write(ii.pattern,ii.name, "ExtractBic("..ii.pattern..")")
    end
    if bic_parser==nil  then 
     bic_parser=CreateBicParser()
    end
    local val  = get_(cache, ii.pattern, "")
    ss.l("ExtractSwiftCode_.val:"..val..". pattern:"..ii.pattern)
    if val~="" then 
      ss.l("!!!======================.parse.start")
      local words ={}
      bic_parser:parse_mt_item_(words,val)
     ss.l("words:")
  ss.tprint(words)
      local bics,bic_iso2_codes,emessage = bic_parser:extract_bics_(words)
      ss.l("!!!======================.parse.end:"..(#bics))
      emessage = ss.def(emessage,"")
      if emessage~="" then ss.l("ExtractBic_.bic_parser.emessage:"..emessage) end

      if #bics>0 then 
       val=bics[1]
     else 
      ss.l("bic not found")
      end
    end

   o[ii.name]=val
end

local function ExtractNameXD(o,cache,name,pattern,doc_writer)
  if doc_writer~=nil then 
     doc_writer:write(pattern,name..".lastname","ExtractNameXD().lastname")
     doc_writer:write(pattern,name..".address","ExtractNameXD().address")
  end

ss.l("ExtractNameXD:"..name.." pattern:"..pattern)
  local x={}
   x.lastname,x.address = parse_FirstAndOther_(get_(cache,pattern,""))
  if checkvalidNameOrAdress_(x) then o[name] = x end
end


local digits_={}
do 
    for i=0,9 do
     digits_[ss.IntToStr(i)]= true
   end
ss.tprint(digits_)
end


local function isDigit_(ch)
  if digits_[ch]==true then return true end
  return false
end
local function  isSym_(text)
 local p = text:find("%a")
ss.l(ss.def(type(p),"nil"))
 return p~=nil
end


 function checkFormat_account_old(val)
 local len = val:len()
 if len<3 then ss.l("len")return false end
-- local = val:gmatch("%a%a%d+") --AAXXXXXX (a - char,X - digital)
 for i=1,len do
   local ch = val:sub(i,i)
   if i>2 then
     if not (isDigit_(ch)) then ss.l("non di:"..i..":"..ch)return false end
   elseif not (isSym_(ch)) then ss.l("non sym:"..i..":"..ch)return false
   end
 end
 return true
end


-- new ver: 15.06.2022
-- from ao:-check only first 2 sym
-- https://ru.wikipedia.org/wiki/IBAN
 function checkFormat_account_(val)
 local len = val:len()
 if len<3 then ss.l("len")return false end

 for i=1,2 do -- check first 2 sym
   local ch = val:sub(i,i)
   if not (isSym_(ch)) then ss.l("non sym:"..i..":"..ch)return false   end
 end
 return true
end


local function alter_swift_code(o,cache,doc_writer)
 ss.l("alter_swift_code.start")
  if ss.def(o.swift_code,"")~="" then ss.l("swift_code exits") return end
  local account = ss.def(o.account,"")
  if not(checkFormat_account_(account)) then ss.l("account no account:"..account) return end
  o.swift_code = "NON:"..account:sub(1,2)
  ss.l("swift_code:"..o.swift_code)
end


local function ExtractName52D(o,cache,doc_writer)
  if doc_writer~=nil then 
     doc_writer:write("52D","name52D.lastname","ExtractName52D().lastname")
     doc_writer:write("52D","name52D.address","ExtractName52D().address")
  end

  local name52D={}
   name52D.lastname,name52D.address = parse_FirstAndOther_(get_(cache,"52D",""))
  if checkvalidNameOrAdress_(name52D) then o.name52D = name52D end
end


local function ExtractName52D_new(o,cache,doc_writer)
  if doc_writer~=nil then 
     doc_writer:write("52D","name52D.lastname","ExtractName52D_new().lastname")
     doc_writer:write("52D","name52D.address","ExtractName52D_new().address")
  end

  local name52D={}
   local val = get_(cache,"52D","")
   name52D.lastname,name52D.address = parse_FirstAndOther_v2(val)
  if checkvalidNameOrAdress_(name52D) then o.name52D = name52D end
  ss.l("ExtractName52D_new:"..val)
  ss.tprint(name52D)
end


local function ExtractName57D(o,cache,doc_writer)
  if doc_writer~=nil then 
     doc_writer:write("57D","name57D.lastname","ExtractName57D().lastname")
     doc_writer:write("57D","name57D.address","ExtractName57D().address")
  end

  local name57D={}
   _,name57D.address = parse_FirstAndOther_(get_(cache,"57D",""))
  if checkvalidNameOrAdress_(name57D) then o.name57D = name57D end
end

-- ----------------------------------------------------------------------------
local function ExtractAmount(o,cache,doc_writer)
-- ----------------------------------------
 local function parse_(val)
   local p ={}
   if val==nil then p.valid=false return p end
   val = val[1]
   if val==nil then p.valid=false return p end

   local d = val:find("%d")
   if d==nil then p.valid=false return p end
   p.valid = true

   p.currency = val:sub(1,d-1)
   p.amount = val:sub(d,val:len())
   if p.amount:find(",")~=nil then p.amount = p.amount:gsub(",",".") end
   return p
 end



-- ----------------------------------------
 local function Parse33b_(val)
   return  parse_(val)
 end
-- ----------------------------------------
 local function Parse32a_(val)
   local p ={}
   if val==nil then p.valid=false return p end
   if #val==0 then p.valid=false return p end
local cur = val[1]
   cur = cur:sub(7,cur:len()) --remove date
--  ss.l("'"..val.."'")
   if val=="" then p.valid=false return p end --???
   return parse_({cur})
 end

 if doc_writer~=nil then 
    doc_writer:write("33B,32A","amount","ExtractAmount().amount","-1")
    doc_writer:write("33B,32A","currency","ExtractAmount().currency","UNDEF")
 end

-- ----------------------------------------
  local p33b = Parse33b_(cache["33B"])
  if p33b.valid then
    o.amount = p33b.amount
    o.currency = p33b.currency
    return 
  end

  local p32a = Parse32a_(cache["32A"])
  if p32a.valid then
    o.amount = p32a.amount
    o.currency = p32a.currency
    return 
  end
  ss.l("amount.Info:33B:"..ss.toJson_sort(cache["33B"]))
  ss.l("amount.Info:32A:"..ss.toJson_sort(cache["32A"]))

  o.amount = "-1"
  o.currency = "UNDEF"
end

function all_trim(s)
   if s==nil then ss.l("all_trim:nill!!") s="" end
   return s:match( "^%s*(.-)%s*$" )
end

local function parse_std_impl_(cache,codes)
   local line59 =""
  for i = 1,#codes do
    line59 = get_(cache,codes[i],"")
   if line59~="" then break end
  end

   if line59=="" then return "","","" end

  local l1 = line59
local s = line59:find("\n")
local account =""
   if s==nil then account=all_trim(line59)
             else account=all_trim(line59:sub(2,s-1))
   end

   if line59:sub(1,1)=="/" then 
      if s==nil then return "","",account end
      l1= line59:sub(s+1,line59:len())
   end

   local f = l1:find("\n")
   if f==nil then return l1,"",account end

   local lastname = l1:sub(1,f-1)
   local address = l1:sub(f+1,l1:len())
   if address:find("\n")~=nil then 
      address = ss.ReplaceValue(address,"\n"," ")
   end
   return lastname,address,account
end

local function parse_std_(cache,codes)
  local lastname,address,account =  parse_std_impl_(cache,codes)
--  ss.l("parse_std_")
--  ss.l("codes[1]"..codes[1])
--  ss.l("lastname:"..lastname)
  return lastname,address,account
end

local function get_doc(ii)
  if ii.from_obj==nil then return ii.from end
  return ii.from_obj.."."..ii.from
end

local function  load_item(o,cache,ii,profile_info)

   local ttype=ss.def(ii.ttype,"std")
  local doc_writer = profile_info.profile_full.advanced_.xml_doc_writer


   if ttype=="std" then 
      if doc_writer~=nil then
        doc_writer:write(ii.pattern,ii.name)
      end
      o[ii.name]=get_(cache,ii.pattern,"") 
   elseif ttype=="ExtractAmount" then
      ExtractAmount(o,cache,doc_writer) 
   elseif ttype=="alias" then
      if doc_writer~=nil then
        doc_writer:write("",ii.name,get_doc(ii),"")
      end

      if ii.from_obj==nil then 
        o[ii.name]=o[ii.from]
      else
       local l=o[ii.from_obj]
       if l==nil then ss.l("failed.mtParser.loaditem.not found ii.from_obj:"..ii.from_obj) l={} end
        o[ii.name]=l[ii.from]
     end
   elseif ttype=="const" then
      if doc_writer~=nil then
        local value = ss.def(ii.value_,"<nil>")
        if type(value)=="boolean" then 
           if value then value="true" else value="false" end
        end
        doc_writer:write("",ii.name," ='"..value.."'",value)
      end
      o[ii.name]=ii.value_
   elseif ttype=="alter_swift_code" then
      alter_swift_code(o,cache,doc_writer)
   elseif ttype == "ExtractSwiftCode" then
        ExtractSwiftCode_(o, cache, ii,doc_writer)
   elseif ttype=="ExtractName52D" then
      ExtractName52D(o,cache,doc_writer)
   elseif ttype=="ExtractName52D_new" then
      ExtractName52D_new(o,cache,doc_writer)
   elseif ttype=="ExtractName57D" then
      ExtractName57D(o,cache,doc_writer)
   elseif ttype=="ExtractNameXD" then
      ExtractNameXD(o,cache,ii.name,ii.pattern,doc_writer)
   elseif ttype=="use_config" then
      mt_serv.add_from_std_config(o,cache,ii.name,{profile_full={advanced_={xml_doc_writer=doc_writer}}})
   elseif ttype=="parse_std" then
     local lastname,address,account = parse_std_(cache,ii.pattern)
     local function a_(obj,ii,propname,val,doc_obj)  
          local name = ii[propname]
          if  name=="_no_" then return end  
          obj[name]=val 
          if doc_obj==nil then return end
          if doc_obj.writer==nil then return end
          local full_name=name
          if doc_obj.objname~=nil then full_name=doc_obj.objname.."."..name end
           doc_obj.writer:write(ii.pattern,full_name,"","")
          end

      local doc_obj={
       writer =doc_writer,
       objname=ii.objname
      }
     if ii.objname~=nil then
       local oo={}
       a_(oo,ii,"lastname",lastname,doc_obj)
       a_(oo,ii,"address",address,doc_obj)
       a_(oo,ii,"account",account,doc_obj)
       o[ii.objname]=oo
     else
       a_(o,ii,"lastname",lastname,doc_obj)
       a_(o,ii,"address",address,doc_obj)
       a_(o,ii,"account",account,doc_obj)
     end
   else
       ss.l("failed.ttype")
       ss.tprint(ii)
       ss.l("tracestack:")
       ss.l(debug.traceback())	
       ss.e("sleep sec 15")
       ss.e("abort 1")
   end
end

local function  add_from_std_config(o,cache,ttype,profile_info)
  if profile_info==nil then
   ss.l("add_from_std_config:profile_info is NULL")
        profile_info={profile_full={advanced_={}}}
  end
        
  if profile_info.profile_full==nil then   ss.l("failed:add_from_std_config:profile_info.profile_full.advanced_ is NULL")   ss.tprint(profile_info)   ss.l(debug.traceback()) end
  if profile_info.profile_full.advanced_==nil then ss.l("failed:add_from_std_config:profile_info.profile_full.advanced_ is NULL") ss.tprint(profile_info) ss.l(debug.traceback())end

  local ttype_real = ttype
  local ttype_profile = profile_info.profile_full.advanced_["PARSE_"..ttype]

  if ttype_profile~=nil then 
    ss.l("ttype_profile:"..ttype_profile)
    ttype_real = ttype_profile
  end
  local cfg = finn_serv.parser_config[ttype_real]
  if cfg==nil then
    ss.l("failed. not found ttype:"..ttype_real)
    ss.l(debug.traceback())	
    ss.l("_________________")
    ss.tprint(cache)
    ss.l("_________________")
     return 
  end
  if cfg.meta.base~=nil then 
    -- The configuration can extend another one (for example, MT202cov extends MT103).
    add_from_std_config(o,cache,cfg.meta.base,{profile_full={advanced_={xml_doc_writer=profile_info.profile_full.advanced_.xml_doc_writer}}})
  end
  for i=1,#cfg.items do
   local ii = cfg.items[i]
     load_item(o,cache,ii,profile_info)
--   o[ii.name]=get_(cache,ii.pattern,"") 
  end
--   o.ordering_customer=get_(cache,"50A","") 
--   o.sending_institution=get_(cache,"51A","") 
--   o.beneficiary_customer=get_(cache,"59A","") 
end
mt_serv.add_from_std_config = add_from_std_config
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------

function CreateMTParser()
 local p = {}

 function p:ParseMT(o,xml_str,prop,sub_type,profile_info)
-- ss.l("MTParser:ParseMT")
-- ss.tprint(profile_info)

  if profile_info==nil then 
   ss.l("warning:profile_info is NULL,type:"..prop)
   ss.l("tracestack:")
   ss.l(debug.traceback())	
   profile_info={profile_full={advanced_={}}}
  end

  local cache = ParseMT_X(xml_str,prop)
  ss.l("_______________________________________________")

--  ss.tprint(cache)

-- doc ver - reference to the description of the algorithm
-- description of variants(doc ver)  on top of the script



  if prop=="mt103" then return self:ParseMT103(o,cache,"ver1.0:incomming",profile_info)

  elseif prop=="mt110" then return self:ParseMT110(o,cache,"ver1.0:outgoing",profile_info)

  elseif prop=="mt101" then return self:ParseMT101(o,cache,"ver1.0:incomming",profile_info)


  elseif prop=="mt200"    then return self:ParseMT200(o,cache,"ver1.0:incomming",profile_info) 
  elseif prop=="mt202"    then return self:ParseMT202(o,cache,"ver1.0:incomming",profile_info) 
  elseif prop=="mt202cov" then return self:ParseMT202cov(o,cache,"ver1.0:incomming",profile_info)
  else
   if prop=="mt540" or 
     prop=="mt542" or
     prop== "mt586" or
     prop== "mt599" or
     prop== "mt940" then 
     return self:ParseMTstub(o,cache,"ver1.0:incomming",prop,profile_info)
     else
       o.error_message = "failed. unknown document type:"..ss.def(prop,"<nil>")
     end
  end

 end




-- ---------------------------------
 function p:ParseMT101(o,cache,doc_ver_id,profile_info)
--[[move to transactionParserConfig.lua  
   ExtractAmount(o,cache) --For now, we are using this option for everyone.
   o.swift_code = get_(cache,"52A","") --19.12.2018
   o.lastname,o.address = parse_std_(cache,{"50H","50F"})
   o.swift_code_dbtr = o.swift_code
   o.swift_code_cdtr = ""
--]]
   o.doc_ver_id = doc_ver_id
   add_from_std_config(o,cache,"mt101",profile_info)

 end

 function p:ParseMT103(o,cache,doc_ver_id,profile_info)
--[[move to transactionParserConfig.lua  
--   ExtractAmount(o,cache) 

--   o.lastname,o.address = parse_std_(cache,{"50K","50F"})

-- begin 11.12.2018 // see:Fwd: FW: Paremtrierungen / Einstellungen
-- This is still experimental code, as it's unclear what to do with these fields and where to place them.


--   o.swift_code = get_(cache,"52A","") --19.12.2018
--   o.bank_name = get_(cache,"52D","")
--   o.account   =  get_(cache,"57A","")

--   o.swift_code_dbtr = o.swift_code
--   o.swift_code_cdtr=""

--   add_from_std_config(o,cache,"mt103")
--   o.ordering_customer=get_(cache,"50A","") 
--   o.sending_institution=get_(cache,"51A","") 
--   o.beneficiary_customer=get_(cache,"59A","") 
         
--   local cdtr  = {}
--   cdtr.lastname, cdtr.address =parse_std_(cache,{"59","59F"})
--   o.cdtr = cdtr
--   o.remittance= get_(cache,"70","")
--   o.remittance2= get_(cache,"72","")

--Ordering Institution	52D lastname(first line),address(other)
--  ExtractName52D(o,cache)
--Account with Institution	57D firstline – ignore, addres (other)
--  ExtractName57D(o,cache)
--]]
   add_from_std_config(o,cache,"mt103",profile_info)
--local valandsum  =  get_(cache,"33B","") -- ao:Split the currency and amount.
   o.doc_ver_id = doc_ver_id
 end


 function p:ParseMT110(o,cache,doc_ver_id,profile_info)
--[[move to transactionParserConfig.lua  
  ExtractAmount(o,cache) 
   o.lastname,o.address = parse_std_(cache,{"59","59F"})
   o.swift_code = get_(cache,"52A","") --19.12.2018
   o.bank_name = get_(cache,"52D","")
   o.account   =  get_(cache,"57A","")
   o.doc_ver_id = doc_ver_id

   o.swift_code_cdtr = o.swift_code
   o.swift_code_dbtr  = ""
--]]
   add_from_std_config(o,cache,"mt110",profile_info)
 end

 function p:ParseMT200(o,cache,doc_ver_id,profile_info)
--[[move to transactionParserConfig.lua  
  ExtractAmount(o,cache) 
--there is no specific description
--   o.lastname = parse_std_(cache,{"57A","56A"})
   o.lastname = parse_std_(cache,{"00"})
   o.isbot = true
--   o.skip_processing_message = "skip processing MT200"
   o.swift_code_cdtr = ""
   o.swift_code_dbtr  = ""
--]]
   o.doc_ver_id = "no doc info"
   add_from_std_config(o,cache,"mt200",profile_info)
 end

--[[
 function p:ParseMT202_bak(o,cache,doc_ver_id)
  ExtractAmount(o,cache) 
  o.swift_code = get_(cache,"52A","") --19.12.2018
  o.bank_name = get_(cache,"52D","")
  o.account   =  get_(cache,"57A","")

  o.skip_processing = true
  o.skip_processing_message = "skip processing MT202"

   o.swift_code_dbtr   = o.swift_code
   o.swift_code_cdtr  = ""

--   o.lastname,o.address = parse_std_(cache,{"58D","72"})
   o.doc_ver_id = doc_ver_id
 end
--]]
 function p:ParseMT202(o,cache,doc_ver_id,profile_info)
--[[move to transactionParserConfig.lua  
--  ExtractAmount(o,cache) 
--  o.swift_code = get_(cache,"52A","") --19.12.2018
--  o.bank_name = get_(cache,"52D","")
--  o.account   =  get_(cache,"57A","")

--  o.skip_processing = true
--  o.skip_processing_message = "skip processing MT202"
               
--   o.swift_code_dbtr   = o.swift_code
--   o.swift_code_cdtr  = ""

--   o.swift_code_cdtr  = get_(cache,"58A","")--24.05.2019

--   o.remittance= get_(cache,"72","")
--   ss.l("zz2zzz")
--   ExtractName52D(o,cache)
--   o.lastname,o.address = parse_std_(cache,{"58D"})--incore
--]]
   add_from_std_config(o,cache,"mt202",profile_info)

   o.doc_ver_id = doc_ver_id
 end




 function p:ParseMTstub(o,cache,doc_ver_id,prop,profile_info)
--  o.skip_processing = true
  o.lastname = "test"
  o.address="praga"
  o.skip_processing = true --11.04.2019
  o.skip_processing_message = "skip processing :"..prop
  o.doc_ver_id = "no doc info"
  add_from_std_config(o,cache,prop,profile_info)
 end
--[[                            
 function p:ParseMT202cov_bak(o,cache,doc_ver_id)--before 24/05/2019
  ExtractAmount(o,cache) 
 
   o.swift_code = get_(cache,"52A","") --19.12.2018
   o.bank_name = get_(cache,"52D","")
   o.account   =  get_(cache,"57A","")

  o.skip_processing = true
  o.skip_processing_message = "skip processing MT202cov"
--   o.lastname,o.address = parse_std_(cache,{"58","72","59","59F"})
--   o.remittance = get_(cache,"70","")
   o.doc_ver_id = doc_ver_id

   o.swift_code_dbtr   = o.swift_code
   o.swift_code_cdtr  = ""

 end
--]]
 function p:ParseMT202cov(o,cache,doc_ver_id,profile_info)

--  self:ParseMT103(o,cache,doc_ver_id)--mt202  It is similar to MT103, so we extract it using the template.
--  ExtractAmount(o,cache) 
--  o.swift_code = get_(cache,"52A","") --19.12.2018
--  o.bank_name = get_(cache,"52D","")
--  o.account   =  get_(cache,"57A","")

--  o.skip_processing = true
--  o.skip_processing_message = "skip processing MT202"
       
--alias   o.swift_code_dbtr   = o.swift_code
--   o.swift_code_cdtr  = ""
--   o.swift_code_cdtr  = get_(cache,"58A","")--?? 24.05.2019

--MT103 is already being extracted.   o.remittance= get_(cache,"72","")
   ss.l("zz2zzz")

--   ExtractName52D(o,cache)

--   o.lastname,o.address = parse_std_(cache,{"58D"})--incore

   --
   add_from_std_config(o,cache,"mt202cov",profile_info)

   o.doc_ver_id = doc_ver_id
 end


 return p
end




