Пример #1
0
void postGLTransactionsToExternal::sPost()
{
  if ( QMessageBox::critical( this, tr("Create New ICDIST File?"),
                              tr( "Creating a new Export File will delete the previous Export File.\n"
                                  "You should make sure that the previous Export Files have been imported into RW2000 before Proceeding.\n\n"
                                  "Are you sure that you want to Create a New Export File?" ),
                                  "&Yes", "&No", QString::null, 0, 1  ) != 0 )
    return;

  QFile distFile(_metrics->value("AccountingSystemExportPath") + "/ICDIST00.EXP");
  if (distFile.open(QIODevice::WriteOnly))
  {
    QString sql( "SELECT accnt_profit, accnt_number, accnt_sub,"
                 "       LPAD(SUBSTR(TEXT(gltrans_journalnumber), 1, 4), 4, '0') AS journalnumber,"
                 "       TO_CHAR(gltrans_date, 'YYYYMMDD') AS distdate,"
                 "       usr_initials,"
                 "       TRUNC((SUM(gltrans_amount) * 100), 0) AS amount "
                 "FROM accnt, usr, gltrans "
                 "WHERE ( (gltrans_accnt_id=accnt_id)"
                 " AND (NOT gltrans_exported)"
                 " AND (usr_username=CURRENT_USER)"
                 " AND (gltrans_date BETWEEN :startDate AND :endDate)" );

    if (_sourceModule->currentText() != tr("All"))
      sql += " AND (gltrans_source=:source)";

    sql += ") "
           "GROUP BY accnt_profit, accnt_number, accnt_sub, journalnumber,"
           "         distdate, usr_initials "
           "HAVING (SUM(gltrans_amount) <> 0);";

    q.prepare(sql);
    q.bindValue(":startDate", _dates->startDate());
    q.bindValue(":endDate", _dates->endDate());
    q.bindValue(":source", _sourceModule->currentText());
    q.exec();
    if (q.first())
    {
      QTextStream textStream(&distFile);
      QString     format;

      do
      {
        textStream << "8";                                                                                           //  IC-DIST-TYP (MISC-COSTS-APPLIED)
        if (_metrics->value("AccountingSystem") == "RealWorld91")
        {
          if (_metrics->value("GLProfitSize").toInt() == 0)
            textStream << "00000000";                                                                                //  IC-DIST-PFT-CTR-1
          else
          {
            format = "%0" + QString("%1").arg(_metrics->value("GLProfitSize").toInt()) + "d";
      
            textStream << QString().sprintf(format, q.value("accnt_profit").toInt());                               //  IC-DIST-PFT-CTR-1
            textStream << QString().fill('0', (8 - _metrics->value("GLProfitSize").toInt()));                        //  Filler '0's
          }

          textStream << "00000000";                                                                                  //  IC-DIST-PFT-CTR-2
        }

        format = "%0" + QString("%1").arg(_metrics->value("GLMainSize").toInt()) + "d";
        
        textStream << QString().sprintf(format, q.value("accnt_number").toInt());                                   //  IC-DIST-MAIN-ACCT-NO
        textStream << QString().fill('0', (8 - _metrics->value("GLMainSize").toInt()));                              //  Filler '0's

        if (_metrics->value("GLSubaccountSize").toInt() == 0)
          textStream << "00000000";                                                                                  //  IC-DIST-SUB-ACCT-NO
        else
        {
          format = "%0" + QString("%1").arg(_metrics->value("GLSubaccountSize").toInt()) + "d";
        
          textStream << QString().sprintf(format, q.value("accnt_sub").toInt());                                    //  IC-DIST-SUB-ACCT-NO
          textStream << QString().fill('0', (8 - _metrics->value("GLSubaccountSize").toInt()));                      //  Filler '0's
        }

        textStream << q.value("distdate").toString();                                                               //  IC-DIST-TRX-DAT
        textStream << "IC";                                                                                          //  Journal Code
        textStream << q.value("journalnumber").toString();                                                          //  IC-DIST-JRNL-NO

        if (q.value("usr_initials").toString().length())
          textStream << q.value("usr_initials").toString().leftJustify(3, ' ', TRUE);                               //  IC-DIST-USER-ID
        else
          textStream << "OMG";                                                                                       //  IC-DIST-USER-ID

        textStream << "N";                                                                                           //  IC-DIST-CORR-FLG

        if (q.value("amount").toInt() < 0)
          textStream << QString().sprintf("%014d+", abs(q.value("amount").toInt()));                                //  IC-DIST-AMT
        else
          textStream << QString().sprintf("%014d-", q.value("amount").toInt());                                     //  IC-DIST-AMT

        textStream << "N";                                                                                           //  IC-DIST-POST-TO-GL-FLG

        textStream << "\n";                                                                                          //  EOL
      }
      while (q.next());
    }

    distFile.close();
  }
  else
  {
    QMessageBox::critical( this, tr("Cannot Open Distribution File"),
                           tr( "The G/L Distribution Export file cannot be opened.  Please contact your Systems Adminstrator\n\n"
                               "G/L Transactions were NOT exported." ) );
    return;
  }

  if ( QMessageBox::information( this, tr("Mark Distributions as Posted"),
                                 tr( "A new ICDIST file has been generated in the RealWorld directory.\n"
                                     "You should now use the RealWorld icfu/icutil tool to import this file.\n"
                                     "After you have successfully imported the ICDIST file click the 'Post' button\n"
                                     "to mark these transactions as distributed.\n"
                                     "If, for any reason, you were unable to post the ICDIST file click on the\n"
                                     "'Do Not Post' button and re-export G/L Transactions to re-create the IDDIST file.\n" ),
                                     tr("&Post"), tr("Do &Not Post"), QString::null, 0, 1) == 0)
  {
    q.prepare( "UPDATE gltrans "
               "SET gltrans_exported=TRUE "
               "WHERE ( (NOT gltrans_exported)"
               " AND (gltrans_date BETWEEN :startDate AND :endDate) );" );
    q.bindValue(":startDate", _dates->startDate());
    q.bindValue(":endDate", _dates->endDate());
    q.exec();
  }

  accept();
}
Пример #2
0
/** vertex file: see SINGLE format.
*  distribution file: see above.
*/
void BayesGraphSave::operator()( const Graph& graph,
                                 const std::string vertexFileName,
                                 const std::string distFileName ) const {

  std::ofstream distFile(distFileName.c_str()), vertexFile(vertexFileName.c_str());
  vertex_iterator vi, vi_end;
  Label2Index label2Index;
  vertexFile << ID << GRAPH_SEPARATOR << LATENT << GRAPH_SEPARATOR
             << LEVEL << GRAPH_SEPARATOR << CARDINALITY << GRAPH_SEPARATOR << "label" << "\n";  // writes header
 BOOST_LOG_TRIVIAL(trace) << "saving vertices...\n";
  for ( boost::tie(vi, vi_end) = boost::vertices(graph); vi != vi_end; ++vi ) {
    int vertex = *vi;
    vertexFile << graph[vertex].index << GRAPH_SEPARATOR
               << !(graph[vertex].is_leaf()) << GRAPH_SEPARATOR
               << graph[vertex].level << GRAPH_SEPARATOR
               << graph[vertex].variable.cardinality() << GRAPH_SEPARATOR
               << graph[vertex].getLabel() << std::endl;
    label2Index[graph[vertex].getLabel()] = graph[vertex].index;
  }
  vertexFile.close();
  BOOST_LOG_TRIVIAL(trace) << "saving joint distribution...\n";

  for ( boost::tie(vi, vi_end) = boost::vertices(graph); vi != vi_end; ++vi ) {
    const Node& node = graph[*vi];
    if ( !node.is_leaf() ) {
      auto latentVar = node.variable;
      // plJointDistribution distribution = node.jointDistribution;
      // plVariablesConjunction all_variables = distribution.get_variables(); // all variables (latent variable and its children)
      plVariablesConjunction childVars = node.get_children_variables(); // child childVars
      // for (size_t i = 1; i <  all_variables.size(); ++i)
      //   childVars ^=  all_variables[i]; // initializes child conjunction.
      // plSymbol latentVar =  all_variables[0]; // latent variable
      distFile << node.index << GRAPH_SEPARATOR <<  childVars.size() << std::endl;

      // plComputableObjectList objLists = distribution.get_computable_object_list();
      // plComputableObject probTableZ = objLists.get_distribution_over(latentVar); // distribution table for the latent variable
      auto probTableZ = node.marginalDist; int val;

      for ( val = 0; val < latentVar.cardinality() - 1 ; ++val ) {
        distFile << std::fixed << std::setprecision(30)
                 << probTableZ->compute( plValues().add(latentVar, val) )
                 << GRAPH_SEPARATOR; // P(latentVar = val)
      }

      distFile << std::fixed << std::setprecision(15)
               << probTableZ->compute( plValues().add(latentVar, val) )
               << std::endl; // writes last probability value

      for ( size_t i = 0; i < childVars.size(); ++i ) {

        plSymbol varX = childVars[ i ]; // retrieves the child variable
        distFile << label2Index[varX.name()] << std::endl; // writes child variable's id.
        auto distTableXZ = node.cndChildrenDists.at(i);  //objLists.get_distribution_over(varX); // conditional distribution P(X_i | Z)
        // plDistributionTable& distTableXZ =
        //     static_cast<plDistributionTable&>( compTableXZ ); // casting P(X_i | Z) to derived class

        for ( val = 0; val < latentVar.cardinality(); ++val ) {
          int childVal;
          for ( childVal = 0; childVal < varX.cardinality() - 1; ++childVal ) { // for each value x of the child variable            
            distFile << std::fixed << std::setprecision(15)
                     << distTableXZ->compute( plValues().add(latentVar, val).add(varX, childVal) )
                     << GRAPH_SEPARATOR; // p(X_i = childVal | Z = val)
          }
          distFile << std::fixed << std::setprecision(15)
                   << distTableXZ->compute( plValues().add(latentVar, val).add(varX, childVal) ) << std::endl;
       }
      }
      distFile << std::endl; // breaks the line, moves to the next latent variable.
    }
  }

  distFile.close();
}