diff --git a/kmymoney/plugins/printcheck/check_all_fields.html b/kmymoney/plugins/printcheck/check_all_fields.html index c029a6c55..4f7163f43 100644 --- a/kmymoney/plugins/printcheck/check_all_fields.html +++ b/kmymoney/plugins/printcheck/check_all_fields.html @@ -1,47 +1,49 @@ + +
data about the owner
$OWNER_NAME $OWNER_NAME
$OWNER_ADDRESS $OWNER_ADDRESS
$OWNER_CITY $OWNER_CITY
$OWNER_STATE $OWNER_STATE
data about the account institution
$INSTITUTION_NAME $INSTITUTION_NAME
$INSTITUTION_STREET $INSTITUTION_STREET
$INSTITUTION_TELEPHONE $INSTITUTION_TELEPHONE
$INSTITUTION_TOWN $INSTITUTION_TOWN
$INSTITUTION_CITY $INSTITUTION_CITY
$INSTITUTION_POSTCODE $INSTITUTION_POSTCODE
$INSTITUTION_MANAGER $INSTITUTION_MANAGER
data about the account
$ACCOUNT_NAME $ACCOUNT_NAME
$ACCOUNT_NUMBER $ACCOUNT_NUMBER
$ACCOUNT_FULL_IBAN $ACCOUNT_FULL_IBAN
$ACCOUNT_IBAN_WITHOUT_COUNTRY $ACCOUNT_IBAN_WITHOUT_COUNTRY
data about the payee
$PAYEE_NAME $PAYEE_NAME
$PAYEE_ADDRESS $PAYEE_ADDRESS
$PAYEE_CITY $PAYEE_CITY
$PAYEE_POSTCODE $PAYEE_POSTCODE
$PAYEE_STATE $PAYEE_STATE
$PAYEE_NOTES $PAYEE_NOTES
data about the transaction
$DATE $DATE
$CHECK_NUMBER $CHECK_NUMBER
$AMOUNT_STRING $AMOUNT_STRING
$AMOUNT_DECIMAL $AMOUNT_DECIMAL
$AMOUNT_DECIMAL_WITHOUT_CURRENCY $AMOUNT_DECIMAL_WITHOUT_CURRENCY
$MEMO $MEMO
$MEMO1 $MEMO1
$MEMO2 $MEMO2
diff --git a/kmymoney/plugins/printcheck/printcheck.cpp b/kmymoney/plugins/printcheck/printcheck.cpp index 2710e6d4b..1f2b882e6 100644 --- a/kmymoney/plugins/printcheck/printcheck.cpp +++ b/kmymoney/plugins/printcheck/printcheck.cpp @@ -1,220 +1,226 @@ /*************************************************************************** * Copyright 2009 Cristian Onet onet.cristian@gmail.com * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see * ***************************************************************************/ #include "printcheck.h" // KDE includes #include #include #include #include #include #include #include #include // KMyMoney includes #include "mymoneyfile.h" #include "pluginloader.h" #include "numbertowords.h" #include "pluginsettings.h" K_PLUGIN_FACTORY(PrintCheckFactory, registerPlugin();) K_EXPORT_PLUGIN(PrintCheckFactory("kmm_printcheck")) struct KMMPrintCheckPlugin::Private { KAction* m_action; QString m_checkTemplateHTML; QStringList m_printedTransactionIdList; KMyMoneyRegister::SelectedTransactions m_transactions; }; KMMPrintCheckPlugin::KMMPrintCheckPlugin(QObject *parent, const QVariantList&) : KMyMoneyPlugin::Plugin(parent, "Print check"/*must be the same as X-KDE-PluginInfo-Name*/) { // Tell the host application to load my GUI component setComponentData(PrintCheckFactory::componentData()); setXMLFile("kmm_printcheck.rc"); // For ease announce that we have been loaded. qDebug("KMyMoney printcheck plugin loaded"); d = new Private; // Create the actions of this plugin QString actionName = i18n("Print check"); d->m_action = actionCollection()->addAction("transaction_printcheck", this, SLOT(slotPrintCheck())); d->m_action->setText(actionName); // wait until a transaction is selected before enableing the action d->m_action->setEnabled(false); d->m_printedTransactionIdList = PluginSettings::printedChecks(); readCheckTemplate(); connect(KMyMoneyPlugin::PluginLoader::instance(), SIGNAL(plug(KPluginInfo*)), this, SLOT(slotPlug(KPluginInfo*))); connect(KMyMoneyPlugin::PluginLoader::instance(), SIGNAL(unplug(KPluginInfo*)), this, SLOT(slotUnplug(KPluginInfo*))); connect(KMyMoneyPlugin::PluginLoader::instance(), SIGNAL(configChanged(Plugin*)), this, SLOT(slotUpdateConfig())); } KMMPrintCheckPlugin::~KMMPrintCheckPlugin() { delete d; } void KMMPrintCheckPlugin::readCheckTemplate() { QString checkTemplateHTMLPath = KGlobal::dirs()->findResource("appdata", "check_template.html"); if (PluginSettings::checkTemplateFile().isEmpty()) { PluginSettings::setCheckTemplateFile(checkTemplateHTMLPath); PluginSettings::self()->writeConfig(); } QFile checkTemplateHTMLFile(PluginSettings::checkTemplateFile()); checkTemplateHTMLFile.open(QIODevice::ReadOnly); QTextStream stream(&checkTemplateHTMLFile); d->m_checkTemplateHTML = stream.readAll(); checkTemplateHTMLFile.close(); } bool KMMPrintCheckPlugin::canBePrinted(const KMyMoneyRegister::SelectedTransaction & selectedTransaction) const { MyMoneyFile* file = MyMoneyFile::instance(); bool isACheck = file->account(selectedTransaction.split().accountId()).accountType() == MyMoneyAccount::Checkings && selectedTransaction.split().shares().isNegative(); return isACheck && d->m_printedTransactionIdList.contains(selectedTransaction.transaction().id()) == 0; } void KMMPrintCheckPlugin::markAsPrinted(const KMyMoneyRegister::SelectedTransaction & selectedTransaction) { d->m_printedTransactionIdList.append(selectedTransaction.transaction().id()); } void KMMPrintCheckPlugin::slotPrintCheck() { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneyMoneyToWordsConverter converter; KHTMLPart *htmlPart = new KHTMLPart(static_cast(0)); KMyMoneyRegister::SelectedTransactions::const_iterator it; for (it = d->m_transactions.constBegin(); it != d->m_transactions.constEnd(); ++it) { if (!canBePrinted(*it)) continue; // skip this check since it was already printed QString checkHTML = d->m_checkTemplateHTML; MyMoneySecurity currency = file->currency(file->account((*it).split().accountId()).currencyId()); MyMoneyInstitution institution = file->institution(file->account((*it).split().accountId()).institutionId()); MyMoneyAccount account = file->account((*it).split().accountId()); MyMoneyPayee payee = file->payee((*it).split().payeeId()); // replace the predefined tokens // data about the user checkHTML.replace("$OWNER_NAME", file->user().name()); checkHTML.replace("$OWNER_ADDRESS", file->user().address()); checkHTML.replace("$OWNER_CITY", file->user().city()); checkHTML.replace("$OWNER_STATE", file->user().state()); // data about the account institution checkHTML.replace("$INSTITUTION_NAME", institution.name()); checkHTML.replace("$INSTITUTION_STREET", institution.street()); checkHTML.replace("$INSTITUTION_TELEPHONE", institution.telephone()); checkHTML.replace("$INSTITUTION_TOWN", institution.town()); checkHTML.replace("$INSTITUTION_CITY", institution.city()); checkHTML.replace("$INSTITUTION_POSTCODE", institution.postcode()); checkHTML.replace("$INSTITUTION_MANAGER", institution.manager()); // data about the account checkHTML.replace("$ACCOUNT_NAME", account.name()); checkHTML.replace("$ACCOUNT_NUMBER", account.number()); checkHTML.replace("$ACCOUNT_FULL_IBAN", account.value("iban")); checkHTML.replace("$ACCOUNT_IBAN_WITHOUT_COUNTRY", account.value("iban").mid(2)); // data about the payee checkHTML.replace("$PAYEE_NAME", payee.name()); checkHTML.replace("$PAYEE_ADDRESS", payee.address()); checkHTML.replace("$PAYEE_CITY", payee.city()); checkHTML.replace("$PAYEE_POSTCODE", payee.postcode()); checkHTML.replace("$PAYEE_STATE", payee.state()); checkHTML.replace("$PAYEE_NOTES", payee.notes()); // data about the transaction checkHTML.replace("$DATE", KGlobal::locale()->formatDate((*it).transaction().postDate(), KLocale::LongDate)); checkHTML.replace("$CHECK_NUMBER", (*it).split().number()); checkHTML.replace("$AMOUNT_DECIMAL_WITHOUT_CURRENCY", (*it).split().value().abs().formatMoney(account.fraction(currency))); checkHTML.replace("$AMOUNT_STRING", converter.convert((*it).split().value().abs())); checkHTML.replace("$AMOUNT_DECIMAL", MyMoneyUtils::formatMoney((*it).split().value().abs(), currency)); - checkHTML.replace("$MEMO", (*it).split().memo()); + QString memo = (*it).split().memo(); + QStringList lines = memo.split("\n"); + if (lines.size() >= 1) + checkHTML.replace("$MEMO1", lines.at(0)); + if (lines.size() > 1) + checkHTML.replace("$MEMO2", lines.at(1)); + checkHTML.replace("$MEMO", memo); // print the check htmlPart->begin(); htmlPart->write(checkHTML); htmlPart->end(); htmlPart->view()->print(); // mark the transaction as printed markAsPrinted(*it); } PluginSettings::setPrintedChecks(d->m_printedTransactionIdList); } void KMMPrintCheckPlugin::slotTransactionsSelected(const KMyMoneyRegister::SelectedTransactions& transactions) { d->m_transactions = transactions; bool actionEnabled = false; // enable/disable the action depending if there are transactions selected or not // and whether they can be printed or not KMyMoneyRegister::SelectedTransactions::const_iterator it; for (it = d->m_transactions.constBegin(); it != d->m_transactions.constEnd(); ++it) { if (canBePrinted(*it)) { actionEnabled = true; break; } } d->m_action->setEnabled(actionEnabled); } // the plugin loader plugs in a plugin void KMMPrintCheckPlugin::slotPlug(KPluginInfo *info) { if (info->pluginName() == objectName()) { connect(viewInterface(), SIGNAL(transactionsSelected(KMyMoneyRegister::SelectedTransactions)), this, SLOT(slotTransactionsSelected(KMyMoneyRegister::SelectedTransactions))); } } // the plugin loader unplugs a plugin void KMMPrintCheckPlugin::slotUnplug(KPluginInfo *info) { if (info->pluginName() == objectName()) { disconnect(viewInterface(), SIGNAL(transactionsSelected(KMyMoneyRegister::SelectedTransactions)), this, SLOT(slotTransactionsSelected(KMyMoneyRegister::SelectedTransactions))); } } // the plugin's configurations has changed void KMMPrintCheckPlugin::slotUpdateConfig() { PluginSettings::self()->readConfig(); // re-read the data because the configuration has changed readCheckTemplate(); d->m_printedTransactionIdList = PluginSettings::printedChecks(); } diff --git a/kmymoney/plugins/printcheck/sepa.html b/kmymoney/plugins/printcheck/sepa.html index 4d938627b..d053bddfc 100644 --- a/kmymoney/plugins/printcheck/sepa.html +++ b/kmymoney/plugins/printcheck/sepa.html @@ -1,90 +1,91 @@ printing template for sepa bank transfer form .top { position:absolute; /* adjust according to printer border */ left:-0.5cm; top:-1.2cm; /* white-space: nowrap; */ font-size: 12pt; font-stretch: extra-expanded; font-family: monospace; white-space: pre; letter-spacing: 0.15cm; } .payee { position:absolute; left:0.9cm; top:2.45cm; } .iban { position:absolute; left:0.9cm; top:3.3cm; } .bic { position:absolute; left:0.9cm; top:4.2cm; } .amount { position:absolute; left:8.3cm; top:5.0cm; } -.memo { +.memo1 { position:absolute; left:0.9cm; top:5.9cm; } .memo2 { position:absolute; left:0.9cm; - top:6.7cm; + top:6.75cm; } .owner { position:absolute; left:0.9cm; top:7.6cm; } .accountiban { position:absolute; left:0.9cm; top:8.5cm; } .accountibanwoco { position:absolute; left:1.8cm; top:8.5cm; }
$PAYEE_NAME
$PAYEE_NOTES
$AMOUNT_DECIMAL_WITHOUT_CURRENCY
-
$MEMO
+
$MEMO1
+
$MEMO2
$OWNER_NAME
$ACCOUNT_IBAN_WITHOUT_COUNTRY