GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
PaymentWidget.cpp
Go to the documentation of this file.
1#line 2 "src/Gui/BillPay/PaymentWidget.cpp"
2
3#include <Wt/WVBoxLayout.h>
4
5#include "../../Eng/TransactionManager.h"
6#include "../../Glb/Core.h"
7#include "BillPay.h"
8
10PaymentWidget( const std::string & _bpGuid )
11: Wt::WContainerWidget(),
12 m_bpGuid( _bpGuid )
13{
14 addStyleClass( "PaymentWidget" );
15
16 /*
17 ** use a layout.
18 */
19 auto lw = setLayout( std::make_unique< Wt::WVBoxLayout >() );
20
21 /*
22 ** This is a complex widget, with a header area with a
23 ** handful of fields, and some controls and whatnot.
24 */
25 auto templtMain =
26 lw->
27 addWidget( std::make_unique< Wt::WTemplate >( TR("gcw_gui.billpay.paymentwidget.form.main") ) );
28
29 /*
30 ** insert the table
31 */
33 m_table-> addStyleClass( "MakePaymentTable" );
34
35 /*
36 ** add the first row of widgets
37 */
38 m_date = table()-> elementAt( 0, 0 )-> addNew< Wt::WDateEdit >( );
39 m_num = table()-> elementAt( 0, 1 )-> addNew< Wt::WLineEdit >( );
40 m_desc = table()-> elementAt( 0, 2 )-> addNew< Wt::WLineEdit >( );
41 m_acct = table()-> elementAt( 0, 3 )-> addNew< AccountRegister::SuggestionEdit >( );
42 m_recon = table()-> elementAt( 0, 4 )-> addNew< Wt::WLineEdit >( );
43// m_debit = table()-> elementAt( 0, 5 )-> addNew< Wt::WLineEdit >( );
44 m_credit = table()-> elementAt( 0, 6 )-> addNew< Wt::WLineEdit >( );
45
46#ifdef INCLUDE_TABLE_WITH_MULTIPLE_INPUT_ROWS
47 /*
48 ** add the edit widget to the tableWidgets vector set
49 */
50 auto _addElement = [&]( size_t _row, size_t _col, const char * styleClass, Wt::WFormWidget * _element )
51 {
53
54 if( m_tableWidgets.size() <= _row )
55 m_tableWidgets.resize( _row + 1 );
56
57 if( m_tableWidgets[_row].size() <= _col )
58 m_tableWidgets[_row].resize( _col + 1 );
59
61 };
62
63 /*
64 ** add a LineEdit to the table
65 */
66 auto _addLineEdit = [&]( size_t _row, size_t _col, const char * _styleClass )
67 {
68 auto element = table()-> elementAt( _row, _col )-> addNew< Wt::WLineEdit >();
70 };
71
72 /*
73 ** add the AccountSeggestionEdit to the table
74 */
75 auto _addAcctEdit = [&]( size_t _row, size_t _col, const char * _styleClass )
76 {
77 auto element = table()-> elementAt( _row, _col )-> addNew< AccountSuggestionEdit >();
79 };
80
81 /*
82 ** build the table
83 */
84 for( int row=1; row<= 3; row++ )
85 {
86 _addLineEdit( row, 1, "num" );
87 _addLineEdit( row, 2, "desc" );
88 _addAcctEdit( row, 3, "acct" );
89 _addLineEdit( row, 4, "recon" );
90 _addLineEdit( row, 5, "debit" );
91 _addLineEdit( row, 6, "credit" );
92 }
93#endif
94
95 /*
96 ** apply styling
97 */
98 m_date -> setFormat( GCW_DATE_FORMAT_DISPLAY );
99 m_date -> addStyleClass( "date" );
100 m_num -> addStyleClass( "num" );
101 m_desc -> addStyleClass( "desc" );
102 m_acct -> addStyleClass( "acct" );
103 m_recon -> addStyleClass( "recon" );
104// m_debit -> addStyleClass( "debit" );
105 m_credit -> addStyleClass( "credit" );
106
107 m_date -> setPlaceholderText( TR("gcw.billPay.pht.date" ) );
108 m_num -> setPlaceholderText( TR("gcw.billPay.pht.num" ) );
109 m_desc -> setPlaceholderText( TR("gcw.billPay.pht.desc" ) );
110 m_acct -> setPlaceholderText( TR("gcw.billPay.pht.acct" ) );
111 m_recon -> setPlaceholderText( TR("gcw.billPay.pht.recon" ) );
112// m_debit -> setPlaceholderText( TR("gcw.billPay.pht.debit" ) );
113 m_credit -> setPlaceholderText( TR("gcw.billPay.pht.credit") );
114
115// m_trans1 -> setToolTip( TR("gcw.billPay.toolTip.trans" ) );
116// m_date1 -> setToolTip( TR("gcw.billPay.toolTip.date" ) );
117// m_memo1 -> setToolTip( TR("gcw.billPay.toolTip.memo" ) );
118// m_confirm -> setToolTip( TR("gcw.billPay.toolTip.confirm" ) );
119
121 m_confirm-> setPlaceholderText( TR("gcw.billPay.pht.confirm") );
122
123 /*
124 ** get all the data loaded
125 */
126 loadData();
127
128} // endPaymentWidget( const std::string & _bpGuid )
129
130auto
133{
134 GCW_NUMERIC retVal(0);
135
136 /*
137 ** this adds the two values together using GAAP...
138 ** the debit is 'added' and the credit is 'subtracted'
139 ** from the value
140 **
141 */
142// GCW_NUMERIC dVal( m_debit -> valueText().toUTF8() );
143 GCW_NUMERIC cVal( m_credit-> valueText().toUTF8() );
144
145 retVal = /* dVal - */ cVal;
146
147 return retVal;
148
149} // endvalue()-> GCW_NUMERIC
150
151auto
154{
155 auto splitItems = GCW::Dbo::Splits::byAccount( GCW::Gui::BillPay::bpItem( bpGuid() ).accountGuid() );
156 for( auto si = splitItems.rbegin(); si != splitItems.rend(); si++ )
157 {
158 auto splitItem = *si;
159 auto txItem = GCW::Dbo::Transactions::byGuid( splitItem-> tx_guid() );
160
161 if( txItem-> num() == "bp" )
162 return txItem;
163
164 } // endfor( ..all splits in reverse.. )
165
167
168} // endlastTx()-> GCW::Dbo::Transactions::Item::Ptr
169
170auto
173{
174 auto bpItem = GCW::Gui::BillPay::bpItem( bpGuid() );
175
176 if( auto txItem = lastTx() )
177 {
178 for( auto splitItem: GCW::Dbo::Splits::byTransaction( txItem-> guid() ) )
179 {
180 if( splitItem-> account_guid() != bpItem.accountGuid() )
181 return splitItem ;
182
183 } // endfor( ..all splits.. )
184
185 } // endif( auto txItem = lastTx() )
186
188
189} // endlastSplit()-> GCW::Dbo::Splits::Item::Ptr
190
191auto
193loadData()-> void
194{
195 /*
196 ** be safe
197 */
198 if( m_bpGuid == "" )
199 return;
200
201 auto bpItem = GCW::Gui::BillPay::bpItem( bpGuid() );
202
203 auto desc = bpItem.nickname();
204 if( bpItem.last4() != "" )
205 desc += " (" + bpItem.last4() + ")";
206
207 m_date -> setValueText( GCW::Core::currentDateTimeDisplayString() );
208 m_recon -> setValueText( "n" );
209 m_num -> setValueText( "bp" );
210 m_desc -> setValueText( desc );
211
212 if( auto splitItem = lastSplit() )
213 m_acct-> setValueText( GCW::Dbo::Accounts::fullName( splitItem-> account_guid() ) );
214
215} // endloadData()-> void
216
217auto
219saveData()-> bool
220{
221 /*
222 ** make sure the account is assigned
223 */
224 if( m_acct-> valueText() == "" )
225 {
226 Wt::WMessageBox::show( TR("gcw.billPay.lbl.billPay"), TR("gcw.billPay.save.needaccount"), Wt::StandardButton::Ok );
227 return false;
228 }
229
230 /*
231 ** make sure there is a (+) positive value
232 */
233 if( value() < 1 )
234 {
235 Wt::WMessageBox::show( TR("gcw.billPay.lbl.billPay"), TR("gcw.billPay.save.positive"), Wt::StandardButton::Ok );
236 return false;
237 }
238
239 /*
240 ** load up some stuff so we can work
241 */
242 auto bpItem = GCW::Gui::BillPay::bpItem( m_bpGuid );
243 auto acctItem = GCW::Dbo::Accounts::byFullName( m_acct-> valueText() );
244
245#ifdef NEVER
246 std::cout << __FILE__ << ":" << __LINE__
247 << " " << bpItem.accountFullName()
248 << " " << bpItem.accountGuid()
249 << " " << bpItem.nickname()
250 << std::endl;
251
252 std::cout << __FILE__ << ":" << __LINE__
253 << " vt:" << m_acct-> valueText()
254 << " id:" << acctItem-> guid()
255 << " ds:" << acctItem-> description()
256 << std::endl;
257#endif
258
259 /*
260 ** now build up a new transaction
261 **
262 ** BUGBUG: note, this procedure will save 'm_confirm' which is the confirmation notes
263 ** to the split item memo field. This can cause gnucash to improperly display
264 ** the value of that memo field if that value that was set there is multi-line
265 ** (ie; contains carriage return codes in the line string) If the value is
266 ** multi-line, it is able to store properly in the sql database, but the display
267 ** in gnucash does not expand to show the multiple lines, instead it shows
268 ** everything on one line with 'line-return' indicators in it. It is editable,
269 ** but I don't know the long-term impact of storing data like this that gnucash
270 ** might have to deal with.
271 */
273 transMan.newTransaction( bpItem.accountGuid(), acctItem-> guid() );
274 transMan.setDescription( m_desc-> valueText() );
275 transMan.setDate ( m_date-> date() );
276 transMan.setValue ( acctItem-> guid() , -value() );
277 transMan.setValue ( bpItem.accountGuid(), value() );
278 transMan.setNotes ( bpItem.accountGuid(), m_confirm-> valueText().toUTF8() );
279 transMan.setNum ( m_num-> valueText().toUTF8() );
280
281 /*
282 ** good save
283 */
284 return true;
285
286} // endsaveData()-> bool
287
288auto
290paymentDate() const-> std::string
291{
292 return m_date-> valueText().toUTF8();
293
294} // endpaymentDate() const-> std::string
295
296
298PaymentWidgetDialog( const std::string & _bpGuid )
299{
300 rejectWhenEscapePressed( true );
301 setClosable( true );
302
303 addStyleClass( "PaymentWidgetDialog" );
304 setWindowTitle( TR( "gcw.billPay.dialog.title" ) );
305
306 m_editWidget = contents()-> addNew< PaymentWidget >( _bpGuid );
307
308 auto pbSave = titleBar()-> addNew< Wt::WPushButton >( TR( "gcw.billPay.lbl.save" ) );
309 auto pbCancel = titleBar()-> addNew< Wt::WPushButton >( TR( "gcw.billPay.lbl.cancel" ) );
310
311 pbSave -> setStyleClass( "btn-xs" );
312 pbCancel -> setStyleClass( "btn-xs" );
313
314 pbSave -> clicked().connect( this, &PaymentWidgetDialog::saveData );
315 pbCancel -> clicked().connect( this, &Wt::WDialog::reject );
316
317} // endPaymentWidgetDialog( const std::string & _bpGuid )
318
319auto
321saveData()-> void
322{
323 if( m_editWidget-> saveData() )
324 accept();
325
326} // endsaveData()-> void
327
328
329auto
331paymentDate() const-> std::string
332{
333 return m_editWidget-> paymentDate();
334
335} // endpaymentDate() const-> std::string
336
337
Wt::Dbo::ptr< Item > Ptr
Definition BaseItem.h:39
Wt::Dbo::ptr< Item > Ptr
auto newTransaction(const std::string &_accountGuid1, const std::string &_accountGuid2) -> void
New Transaction.
auto setDescription(const std::string &_value) -> void
auto setNum(const std::string &_value) -> void
auto setDate(const Wt::WDateTime &_value) -> void
auto setNotes(const std::string &_acctGuid, const std::string &_value) -> void
auto setValue(GCW_NUMERIC _value) -> void
PaymentWidgetDialog(const std::string &_bpGuid)
auto paymentDate() const -> std::string
auto lastSplit() -> GCW::Dbo::Splits::Item::Ptr
Last Split.
std::vector< std::vector< Wt::WFormWidget * > > m_tableWidgets
auto table() -> Wt::WTable *
AccountRegister::SuggestionEdit * m_acct
auto value() -> GCW_NUMERIC
Value.
PaymentWidget(const std::string &_bpGuid)
auto paymentDate() const -> std::string
auto lastTx() -> GCW::Dbo::Transactions::Item::Ptr
Last Transaction.
Widget * addNew(Args &&...args)
void setLayout(std::unique_ptr< WLayout > layout)
virtual void addWidget(std::unique_ptr< WWidget > widget)
virtual void reject()
virtual WString styleClass() const override
virtual void addStyleClass(const WString &styleClass, bool force=false) override
#define TR(X)
Definition define.h:17
#define GCW_DATE_FORMAT_DISPLAY
Definition gcwglobal.h:14
#define GCW_NUMERIC
Internal Numeric Type.
Definition gcwglobal.h:38
auto currentDateTimeDisplayString() -> std::string
Definition Core.cpp:287
auto byFullName(const std::string &_fullName) -> Item::Ptr
Load Account by 'full name' with ':' account separator.
auto fullName(const std::string &_guid) -> std::string
Account Fullname via GUID.
auto byTransaction(const std::string &_txGuid) -> Item::Vector
Load Splits by Transaction.
Definition Splits.cpp:244
auto byAccount(const std::string &_accountGuid) -> Item::Vector
Load Splits by Account.
Definition Splits.cpp:165
auto byGuid(const std::string &_txGuid) -> Item::Ptr
auto bpItem(const std::string &_guid) -> GCW::Gui::BillPay::Item
Bill Pay Item.
Definition BillPay.cpp:33