Reply to topic

Check Printing Variables

philhopkins
Registered Member
Posts
8
Karma
0

Check Printing Variables

Mon Aug 12, 2019 4:13 am
I need to be able to print checks onto a 3 part check and voucher. I am working on a template but I need to print the check category on the voucher and if the transaction had a split, I need to print the split info. I have looked in the plugins code but I do not see any variables defined which would access this info. Am I missing something? If not is there anyone who could add these variables? It doesn't look very difficult for someone who knows the data structures.

I would even try if someone can point me in the proper direction, but if the data is already available just let me know how to access it.

Phil
User avatar ipwizard
KDE Developer
Posts
762
Karma
3
OS

Re: Check Printing Variables

Mon Aug 12, 2019 6:16 am
Since you already looked at the code, we can jump into it right away :)

You want to change CheckPrinting::slotPrintCheck() and add the necessary logic to it. The necessary variables to do that are all present.
it is an iterator over the selected transaction. The object it points to (KMyMoneyRegister::SelectedTransactions) contains two relevant members: the transaction and the respective split (which is part of the transaction). You can access them via (*it).transaction() and (*it).split(). Only the latter is used in the existing code AFAICT. To gain access to all splits of a transaction you use (*it).transaction().splits() which returns a const reference to QList<MyMoneySplit>, a list of all splits that make up the transaction (also the one you get via the (*it).split().

Hope that helps and gets you started. Try to keep the solution generic so that we may be able to incorporate it into the application. Patches are welcome for review via our Phabricator site.


ipwizard, proud to be a member of the KMyMoney forum since its beginning. :-D
openSuSE Leap 15.1 64bit, KF5
philhopkins
Registered Member
Posts
8
Karma
0

Re: Check Printing Variables

Mon Aug 12, 2019 8:48 pm
Thanks for the information. What you told me really helps. I will work on making the changes, which don't look too difficult. Once I get it working I will submit the as a patch. I may have a question or two as I work on it.

Phil
philhopkins
Registered Member
Posts
8
Karma
0

Re: Check Printing Variables

Thu Aug 15, 2019 5:08 pm
I am working on it but I haven't wrked with C or C++ for the last 15 years! If anyone else has any pointers they would be appreciated. I have made a litte progress but I am having to relearn how to access the data in C++.

Phil
User avatar ipwizard
KDE Developer
Posts
762
Karma
3
OS

Re: Check Printing Variables

Thu Aug 15, 2019 5:23 pm
Which data do you want to access?


ipwizard, proud to be a member of the KMyMoney forum since its beginning. :-D
openSuSE Leap 15.1 64bit, KF5
philhopkins
Registered Member
Posts
8
Karma
0

Re: Check Printing Variables

Thu Aug 15, 2019 10:16 pm
I need to access (*it).transaction().splits() or the reference QList<MyMoneySplit>. I need the information in the splits to print on the voucher when I print a check. I am reading the c++ documentation but I have forgotten so much.

Phil
philhopkins
Registered Member
Posts
8
Karma
0

Re: Check Printing Variables

Thu Aug 15, 2019 10:17 pm
Oops, Thanks in advance for any help you continue to give.

Phil
User avatar ipwizard
KDE Developer
Posts
762
Karma
3
OS

Re: Check Printing Variables

Fri Aug 16, 2019 5:52 am
You want to take a look at the MyMoneySplit object defined in kmymoney/mymoney/mymoneysplit.h. Some of the data is stored directly in this object (e.g. memo) other data is referenced by its ID (e.g. payee). To access the latter, take the ID and extract the data via the MyMoneyFile object (e.g. MyMoneyFile::instance()->payee(ID); )


ipwizard, proud to be a member of the KMyMoney forum since its beginning. :-D
openSuSE Leap 15.1 64bit, KF5
philhopkins
Registered Member
Posts
8
Karma
0

Re: Check Printing Variables

Wed Aug 21, 2019 5:05 pm
Well I got it working and yes I will submit my changes as a patch for others. I am placing the code below and if anyone wants to look at it and give me feedback I would appreciate it. I am NOT a C++ coder so I can imaging that there may be better ways to do things.

This code will make two variables available for printing SplitAccountName (the account name associated with the split) and SplitValue (the value of the split). Since I don't think there is a way to ever know the maximum number of splits associated with a transaction I have arbitrarily limited the number of splits available to 11. The check template file will have to be modified to accommodate the variables. Additionally for splits that have less than 11 splits, I have placed a space into the extra variables so that nothing will print in the unused variables if they are declared in the template file.

The following code would be inserted after line 211:
checkHTML.replace("$ACCOUNT", (*it).split().accountId());
in the file kmymoney/plugins/checkprinting/checkprinting.cpp


int NumSplits = (*it).transaction().splitCount();
std::string SplitValue;
std::string SplitAccountName;
for (int i=0; i<=10; ++i) {
std::string ii = std::to_string(i);
SplitValue = "$SPLITVALUE"+ii;
SplitAccountName = "$SPLITACCOUNTNAME"+ii;
QString qstrValue = QString::fromStdString(SplitValue);
QString qstrAccountName = QString::fromStdString(SplitAccountName);
if ( i <= NumSplits - 1 ) {
checkHTML.replace( qstrValue, MyMoneyUtils::formatMoney((*it).transaction().splits()[i].shares().abs(), currency));
checkHTML.replace( qstrAccountName, (file->account((*it).transaction().splits()[i].accountId())).name());
} else {
checkHTML.replace( qstrValue, " ");
checkHTML.replace( qstrAccountName, " ");
}
}

Thanks in advance for any comments.

Phil

 
Reply to topic

Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Invictus, Majestic-12 [Bot]