setfeg.0003.script 4.81 KB
Newer Older
wangguangchao committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
void getFepEntries(Argument<Boolean> argfirstcall)
{
  //! Get entries from fee pool
  //! ArgFirstCall is true if it is the first call with a access to pool as roles are set
  // FEPinp contains the information about the fees from pool
  // 1. Read the pool records from FEP
  int cnt = 0;
  argfirstcall.value = false;
  IStream sqlStm = new StreamImpl();
  IStream cacsql = new StreamImpl();
  String id = NULLSTR;
  IStream inrStm = new StreamImpl();
  int sqlStmCnt = 0;
  String sql = NULLSTR;
  String sepWrn = NULLSTR;
  IStream sepStm = new StreamImpl();
  int stmCnt = 0;
  IStream ptyInrStm = new StreamImpl();
  String ptynam = NULLSTR;
  String ptyextkey = NULLSTR;
  if( Platform.streamCount( $\setmod\roldsc.getValue() ) > 0 )
  {
    Platform.streamClear( sqlStm );
    setFepSql( sqlStm );
    if( ! Platform.isEmpty( sqlStm ) )
    {
      // read Sql from cache (not from FEPINP as it has to be reread in case of pickup)
      Platform.streamClear( cacsql );
      Platform.cacheRead( cacsql, "SEFMOD", "FEPSQL" );
      if( Platform.errorCode() == tdCacheNotFound )
      {
        argfirstcall.value = true;
      }
      else
      {
        Platform.reraise();
        if( Platform.compareTo( Platform.toString( sqlStm ) ,  Platform.toString( cacsql ) ) == 0 )
        {
          if(1==1) return;
        }
      }
      Platform.cacheWrite( sqlStm, "SEFMOD", "FEPSQL" );
      // remove old pool entries from cache (if any)
44 45 46
      Argument<Integer> cntBox = new Argument<>("",0);
      Platform.cacheRead( cntBox, "SETFEG", "FEPCNT" );
      cnt = cntBox.value;
wangguangchao committed
47 48 49 50 51 52 53 54
      if( Platform.errorCode() != tdCacheNotFound )
      {
        Platform.reraise();
        if( cnt > 0 )
        {
          for(int  i = 1;i <= cnt;i++)
          {
            id = "";
55 56 57
            Argument<String> idBox= new Argument<>("","");
            Platform.cacheRead( idBox, "SETFEG", "FEPIDS", i );
            id = idBox.value;
wangguangchao committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
            if( Platform.errorCode() != tdCacheNotFound )
            {
              Platform.cacheDelete( "SETFEG", "FEEVAL", id );
              Platform.cacheDelete( "SETFEG", "FEPIDS", i );
              Platform.reraise();
            }
          }
        }
      }
      cnt = 0;
      Platform.streamClear( inrStm );
      sqlStmCnt = Platform.streamCount( sqlStm );
      for(int  sqlCnt = 1;sqlCnt <= sqlStmCnt;sqlCnt++)
      {
        sql = Platform.getLine( sqlStm, sqlCnt );
        Platform.dbExecuteSql( "select inr from fep " + Platform.sdbEtyGenSql( $wrkfep, sql ) );
        Platform.dbFetchStream( inrStm );
        Platform.dbCloseCursor();
      }
      sepWrn = "";
      if( ! Platform.isEmpty( $\setmod\sep\inr ) && Platform.isEmpty( $\setmod\tmpnotfnlflg ) )
      {
        Platform.streamClear( sepStm );
        Platform.dbExecuteSQL( "select inr from fep where sepinr = ? and dontrninr = ' ' and rpltrninr = ' ' ", $\setmod\sep\inr.getValue() );
        Platform.dbFetchStream( sepStm );
        Platform.dbCloseCursor();
        stmCnt = Platform.streamCount( sepStm );
        for(int  i = 1;i <= stmCnt;i++)
        {
          if( Platform.streamSearch( inrStm, Platform.getLine( sepStm, i ) ) == 0 )
          {
            Platform.streamInsert( inrStm, 0, Platform.getLine( sepStm, i ) );
            sepWrn = #CT000305;
          }
        }
        $\trnmod\mtabut\syswrn.sysWarningSet( SYSWRNTypeWarning, sepWrn, "SETFEGBOGSEPWRN" );
      }
      Platform.streamClear( ptyInrStm );
      fillPtyInrStmForFep( ptyInrStm );
      stmCnt = Platform.streamCount( inrStm );
      for(int  idx = 1;idx <= stmCnt;idx++)
      {
        Platform.sdbRead( $wrkfep, Platform.getLine( inrStm, idx ) );
        if( Platform.streamSearch( ptyInrStm, $wrkfep\ptyinr ) > 0 )
        {
          cnt = cnt + 1;
          Platform.cacheWrite( $wrkfep\inr.getValue(), "SETFEG", "FEPIDS", cnt );
          Platform.cacheWrite( cnt, "SETFEG", "FEPIDS", $wrkfep\inr.getValue() );
          setOneFepInp();
        }
        else
        {
          Platform.dbExecuteSQL( "SELECT NAM,EXTKEY FROM PTY WHERE INR = ?", $wrkfep\ptyinr.getValue() );
          ptynam = "";
          ptyextkey = "";
113 114 115 116 117
          Argument<String> ptynamBox = new Argument<>();
          Argument<String> ptyextkeyBox = new Argument<>();
          Platform.dbFetchFields( "NAM", ptynamBox, "EXTKEY", ptyextkeyBox );
          ptynam = ptynamBox.value;
          ptyextkey = ptyextkeyBox.value;
wangguangchao committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
          if( Platform.errorCode() != tdOdbcNotFound )
          {
            Platform.reraise();
          }
          Platform.dbCloseCursor();
          $\trnmod\mtabut\syswrn.sysWarningSet( SYSWRNTypeWarning, Platform.getText( #CT000010, $wrkfep\feecod.getValue(), ptyextkey, ptynam ), "FEPWRN-" + $wrkfep\inr.getValue() );
        }
      }
      if( Platform.errorCode() != tdOdbcNotFound )
      {
        Platform.reraise();
      }
      Platform.cacheWrite( cnt, "SETFEG", "FEPCNT" );
    }
  }

}