void KMoneyThingHomeView::doHTML()
{
  KLocale *locale = new KLocale("KMoneyThing");  

  khtmlPart->begin();
  khtmlPart->write("<html>");
  khtmlPart->write("<head><style type='text/css'>th, tr { text-align: left; padding-right: 1em }</style></head>");
  khtmlPart->write("<body><h1>");
  khtmlPart->write(i18n("Welcome to KMoneyThing") + " pre0.1");
  khtmlPart->write("</h1><hr><p>");
  khtmlPart->write(i18n("This application is still under development, and is not yet suitable for general use."));
  khtmlPart->write("</p>");
  khtmlPart->write("<h2>" + i18n("Summary") + "</h2>");
  khtmlPart->write("<table>");
  khtmlPart->write("<tr><th>" + i18n("Account") + "</th><th>" + i18n("Balance") + "</th></tr>");
  // TODO: International accounts
  // TODO: Adding up balances with suport for internationalisation
  for (Q_UINT32 i = 0; i < mCurrentFile->accounts(); i++)
  {
    locale->setCountry(mCurrentFile->getAccount(i)->locale());
    QString accountName = mCurrentFile->getAccount(i)->name();
    QString accountBalance = locale->formatMoney(mCurrentFile->getAccount(i)->balance());
    khtmlPart->write(QString("<tr><td>%1</td><td>%2</td></tr>").arg(accountName).arg(accountBalance));
  }
  locale->setCountry(mCurrentFile->locale());
  QString totalBalance = locale->formatMoney(0.0);
  khtmlPart->write("<tr><th>" + i18n("Total:") + "</th><th>" + totalBalance + "</th></tr>");
  khtmlPart->write("</table>");
  khtmlPart->write("</body></html>");
  khtmlPart->end();
  
  delete locale;
}
예제 #2
0
파일: kraftview_ro.cpp 프로젝트: KDE/kraft
void KraftViewRO::setup( DocGuardedPtr doc )
{
    KraftViewBase::setup( doc );

    if ( !doc ) return;

    KLocale *locale = doc->locale();
    if ( !locale ) locale = KGlobal::locale();

    // do stuff like open a template and render values into it.
    KStandardDirs stdDirs;
    QString templFileName = QString( "kraftdoc_ro.trml" );
    QString findFile = "kraft/reports/" + templFileName;

    QString tmplFile = stdDirs.findResource( "data", findFile );


    QByteArray kraftHome = qgetenv("KRAFT_HOME");

    if( !kraftHome.isEmpty() ) {
        QString file = QString( "%1/reports/kraftdoc_ro.trml").arg(QString::fromLocal8Bit(kraftHome));
        QFileInfo fi(file);
        if( fi.exists() && fi.isReadable() ) {
            tmplFile = file;
        }
    }
    if( tmplFile.isEmpty() ) {
        kDebug() << "Could not find template to render ro view of document.";
        return;
    }


    TextTemplate tmpl( tmplFile );
    if( !tmpl.open() ) {
        return;
    }
    tmpl.setValue( DOC_RO_TAG( "HEADLINE" ), doc->docType() + " " + doc->ident() );
    tmpl.setValue( DOC_RO_TAG( "DATE" ), locale->formatDate( doc->date(), KLocale::ShortDate ) );
    tmpl.setValue( DOC_RO_TAG( "DOC_TYPE" ),  doc->docType() );
    QString address = doc->address();
    address.replace( '\n', "<br/>" );
    tmpl.setValue( DOC_RO_TAG( "ADDRESS" ), address );
    tmpl.setValue( DOC_RO_TAG( "DOCNO" ), doc->ident() );
    tmpl.setValue( DOC_RO_TAG( "PRETEXT" ), doc->preText() );
    tmpl.setValue( DOC_RO_TAG( "POSTTEXT" ), doc->postText() );
    tmpl.setValue( DOC_RO_TAG( "SALUT" ), doc->salut() );
    tmpl.setValue( DOC_RO_TAG( "GOODBYE" ), doc->goodbye() );


    DocPositionList positions = doc->positions();

    // check the tax settings: If all items have the same settings, its not individual.
    bool individualTax = false;
    int ttype = -1;
    foreach( DocPositionBase *dp, positions  ) {
        if( ttype == -1 ) {
            ttype = dp->taxType();
        } else {
            if( ttype != dp->taxType() ) { // different from previous one?
                individualTax = true;
                break;
            }
        }
    }

    int pos = 1;
    int taxFreeCnt = 0;
    int reducedTaxCnt = 0;
    int fullTaxCnt = 0;

    QString docType = doc->docType();
    DocType dt(docType);

    foreach( DocPositionBase *dpb, positions ) {
        DocPosition *dp = static_cast<DocPosition*>(dpb);
        tmpl.createDictionary( "ITEMS" );

        tmpl.setValue( "ITEMS", "NUMBER", QString::number( pos++ ) );
        tmpl.setValue( "ITEMS", "TEXT", dp->text() );
        tmpl.setValue( "ITEMS", "AMOUNT", locale->formatNumber( dp->amount() ) );
        tmpl.setValue( "ITEMS", "UNIT", dp->unit().einheit( dp->amount() ) );
        double singlePrice = dp->unitPrice().toDouble();

        if( dt.pricesVisible() ) {
            tmpl.createSubDictionary("ITEMS", "PRICE_DISPLAY");
            tmpl.setValue( "PRICE_DISPLAY", "SINGLE_PRICE", locale->formatMoney( singlePrice ) );
            QString style( "positive" );
            if ( singlePrice < 0 ) {
                style = "negative";
            }

            tmpl.setValue( "PRICE_DISPLAY", "PRICE_STYLE", style );

            tmpl.setValue( "PRICE_DISPLAY", "PRICE", locale->formatMoney( dp->overallPrice().toDouble() ) );
        }
#if 0
        QString taxType;
        if( individualTax ) {
            if( dp->taxType() == 1 ) {
                taxFreeCnt++;
                taxType = "TAX_FREE";
            } else if( dp->taxType() == 2 ) {
                taxType = "REDUCED_TAX";
                reducedTaxCnt++;
            } else {
                // ATTENTION: Default for all non known tax types is full tax.
                fullTaxCnt++;
                taxType = "FULL_TAX";
            }
        }
#endif
    }