GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
EditWidget.cpp
Go to the documentation of this file.
1#line 2 "src/Gui/BillPay/EditWidget.cpp"
2
3#include <Wt/WMenuItem.h>
4#include <Wt/WVBoxLayout.h>
5#include <Wt/WMessageBox.h>
6
7#include "../../Eng/AccountComboModel.h"
8#include "../../Glb/Core.h"
9#include "BillPay.h"
10
12EditWidget( const std::string & _bpGuid )
13: Wt::WContainerWidget(),
14 m_bpGuid( _bpGuid )
15{
16 addStyleClass( "EditWidget" );
17
18 /*
19 ** use a layout.
20 */
21 auto lw = setLayout( std::make_unique< Wt::WVBoxLayout >() );
22
23 /*
24 ** This is a complex widget, with a header area with a
25 ** handful of fields, then a tab widget with a couple
26 ** pages.
27 */
28 auto templtMain =
29 lw->
31 (
32 std::make_unique< Wt::WTemplate >( TR("gcw_gui.billpay.editwidget.form.main") )
33 );
34
35 /*
36 ** add all the widgets
37 */
38 m_pbSave = templtMain-> bindNew< Wt::WPushButton >( "save" , TR("gcw.billPay.lbl.save") );
39 m_pbCancel = templtMain-> bindNew< Wt::WPushButton >( "cancel" , TR("gcw.billPay.lbl.cancel") );
40 m_pbDelete = templtMain-> bindNew< Wt::WPushButton >( "delete" , TR("gcw.billPay.lbl.delete") );
41 m_pbProcess = templtMain-> bindNew< Wt::WPushButton >( "process" , TR("gcw.billPay.lbl.process") );
50 m_ap = templtMain-> bindNew< Wt::WCheckBox >( "ap" , TR("gcw.billPay.lbl.ap") );
51 m_isActive = templtMain-> bindNew< Wt::WCheckBox >( "isActive" , TR("gcw.billPay.lbl.isActive") );
52 m_isVisible = templtMain-> bindNew< Wt::WCheckBox >( "isVisible" , TR("gcw.billPay.lbl.isVisible") );
53 m_autoPay = templtMain-> bindNew< Wt::WCheckBox >( "autoPay" , TR("gcw.billPay.lbl.autoPay") );
54 m_payNow = templtMain-> bindNew< Wt::WCheckBox >( "payNow" , TR("gcw.billPay.lbl.payNow") );
55
56 m_pbSave -> setStyleClass( "btn-xs" );
57 m_pbCancel -> setStyleClass( "btn-xs" );
58 m_pbDelete -> setStyleClass( "btn-xs" );
59 m_pbProcess -> setStyleClass( "btn-xs" );
60
61 m_account -> setToolTip( TR("gcw.billPay.ttp.account" ) );
62 m_dueDay -> setToolTip( TR("gcw.billPay.ttp.dueDay" ) );
63 m_minimum -> setToolTip( TR("gcw.billPay.ttp.minimum" ) );
64 m_budget -> setToolTip( TR("gcw.billPay.ttp.budget" ) );
65 m_nickname -> setToolTip( TR("gcw.billPay.ttp.nickname" ) );
66 m_group -> setToolTip( TR("gcw.billPay.ttp.group" ) );
67 m_limit -> setToolTip( TR("gcw.billPay.ttp.limit" ) );
68 m_actual -> setToolTip( TR("gcw.billPay.ttp.actual" ) );
69 m_ap -> setToolTip( TR("gcw.billPay.ttp.ap" ) );
70 m_isActive -> setToolTip( TR("gcw.billPay.ttp.isActive" ) );
71 m_isVisible -> setToolTip( TR("gcw.billPay.ttp.isVisible" ) );
72 m_autoPay -> setToolTip( TR("gcw.billPay.ttp.autoPay" ) );
73 m_payNow -> setToolTip( TR("gcw.billPay.ttp.payNow" ) );
74
75 m_dueDay -> setRange( 1, 31 );
76 m_group -> setRange( 0, 30 );
77 m_group -> setSingleStep( 5 );
78
79 templtMain-> bindString( "accountLabel" , TR("gcw.billPay.lbl.account" ) );
80 templtMain-> bindString( "dueDayLabel" , TR("gcw.billPay.lbl.dueDay" ) );
81 templtMain-> bindString( "minimumLabel" , TR("gcw.billPay.lbl.minimum" ) );
82 templtMain-> bindString( "budgetLabel" , TR("gcw.billPay.lbl.budget" ) );
83 templtMain-> bindString( "nicknameLabel" , TR("gcw.billPay.lbl.nickname" ) );
84 templtMain-> bindString( "groupLabel" , TR("gcw.billPay.lbl.group" ) );
85 templtMain-> bindString( "limitLabel" , TR("gcw.billPay.lbl.limit" ) );
86 templtMain-> bindString( "actualLabel" , TR("gcw.billPay.lbl.actual" ) );
87
88 /*
89 ** this is the tab widget. It takes up the remaining bottom space
90 ** on the form.
91 */
92 m_tabWidget = lw-> addWidget( std::make_unique< Wt::WTabWidget >(), 1 );
93
94 /*
95 ** This is the payment template. It will get added to
96 ** the first page of the tab widget.
97 */
99 {
100 auto u_ = std::make_unique< Wt::WTemplate >( TR( "gcw_gui.billpayeditor.form.tab1" ) );
101 templtPayment = u_.get();
102 m_tabWidget-> addTab( std::move( u_ ), TR("gcw.billPay.tabName.payment") );
103
104 for( int cb = 0; cb < 12; cb++ )
105 {
106 auto cbx = std::make_unique< Wt::WCheckBox >( toString( cb+1 ) );
107 cbx-> setTristate( true );
108 cbx-> setPartialStateSelectable( true );
109
110 m_cbx.push_back( cbx.get() );
111
112 templtPayment-> bindWidget( "cb" + toString( cb+1 ), std::move( cbx ) );
113 }
114
115 auto pbgo = templtPayment-> bindNew< Wt::WPushButton >( "go", TR("gcw.billPay.lbl.go") );
116 pbgo-> setStyleClass( "btn-xs" );
117
121// m_note = templtPayment-> bindNew< Wt::WTextEdit >( "note" );
122 m_label = templtPayment-> bindNew< Wt::WLabel >( "image", "image" );
123 m_label-> setMinimumSize( "160px", "160px" );
124 m_label-> resize( "160px", "160px" );
125
126 m_note-> setRows( 10 );
127// m_note-> resize( Wt::WLength::Auto, Wt::WLength( 200 ) );
128
129 auto pbClear = templtPayment-> bindNew< Wt::WPushButton >( "clear", TR("gcw.billPay.lbl.clear") );
130 pbClear-> setStyleClass( "btn-xs" );
131 pbClear-> setToolTip( TR("gcw.billPay.ttp.clear") );
132 pbClear->
133 clicked().connect( [&]()
134 {
135 for( auto cb : m_cbx )
136 cb-> setValueText( "no" );
137 });
138
139 } // endWt::WTemplate * templtPayment;
140
141 /*
142 ** This is the history widget. It contains
143 ** a registry table for this widget. It gets added to
144 ** the second page of the tab widget.
145 **
146 */
148 {
149 /*
150 ** This does a better job of honoring the layout, but we still have
151 ** to set the widget height.
152 **
153 */
154 auto w_ = std::make_unique< GCW::Gui::AccountRegister::Widget >();
155 m_register = w_.get();
156 m_register-> setReadOnly( true );
157 auto tab = m_tabWidget-> addTab( std::move( w_ ), TR("gcw.billPay.tabName.history") );
158// tab-> contents()-> setMaximumSize( Wt::WLength::Auto, "300px" );
159
160 } // endWt::WTemplate * templtHistory;
161
162 m_pbSave -> clicked().connect( [&](){ saveData(); });
163 m_pbCancel -> clicked().connect( [&](){ m_canceled.emit(); });
164 m_pbDelete -> clicked().connect( [&](){ m_deleted.emit(); });
165 m_pbProcess -> clicked().connect( [&](){ processPayment(); });
166
167 /*
168 ** get all the data loaded
169 */
170 loadData();
171
172} // endEditWidget( const std::string & _accountGuid )
173
174auto
176loadData()-> void
177{
178 /*
179 ** beware of safety
180 */
181 if( m_bpGuid == "" )
182 return;
183
184 m_pbProcess -> setDisabled( false );
185 m_pbDelete -> setDisabled( false );
186
187 /*
188 ** Get the item that carries the bill-pay info
189 */
190 auto bpItem = GCW::Gui::BillPay::bpItem( m_bpGuid );
191
192 /*
193 ** format the 'name' to be something readable
194 */
195 auto fullName = GCW::Dbo::Accounts::fullName( bpItem.accountGuid() );
196
197 /*
198 ** If the account-name has been assigned, then don't allow it to
199 ** be re-assigned.
200 */
201 if( fullName != "" )
202 m_account -> setDisabled( true );
203
204 /*
205 ** populate the form
206 */
207 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
208 m_account -> setValueText( fullName );
209 m_dueDay -> setValueText( bpItem.dueDay () );
210 m_minimum -> setValueText( bpItem.minimum () );
211 m_budget -> setValueText( bpItem.budget () );
212 m_nickname -> setValueText( bpItem.nickname () );
213 m_group -> setValueText( bpItem.group () );
214 m_limit -> setValueText( bpItem.limit () );
215 m_actual -> setValueText( bpItem.actual () );
216 m_url -> setValueText( bpItem.url () );
217 m_ap -> setValueText( bpItem.ap () );
218 m_isActive -> setValueText( bpItem.isActive () );
219 m_isVisible -> setValueText( bpItem.isVisible () );
220 m_autoPay -> setValueText( bpItem.autoPay () );
221 m_payNow -> setValueText( bpItem.payNow () );
222 m_last4 -> setValueText( bpItem.last4 () );
223 m_note -> setValueText( bpItem.note () );
224
225 int i = 1;
226 for( auto cb : m_cbx )
227 cb-> setValueText( bpItem.cb( i++ ) );
228
229 m_register -> setAccountGuid( bpItem.accountGuid() );
230
231} // endloadData()-> void
232
233auto
235accountIsDuplicated()-> bool
236{
237 auto accountGuid = m_account-> valueGuid();
238
240
241 for( auto & itm : items )
242 {
243 Item item(itm);
244
245 /*
246 ** if the account is the same but the bpItem is different
247 ** then this must be a duplicate. The accountGuid and
248 ** bpItemGuid must match in order for this to not be a
249 ** duplicate. When they match, it means we're saving
250 ** the same (correct) bp item.
251 */
252 if( item.accountGuid() == accountGuid
253 && item.guid() != m_bpGuid
254 )
255 return true;
256 }
257
258 return false;
259
260} // endduplicateAccount()-> bool
261
262auto
264saveData()-> void
265{
266 /*
267 ** This needs to be set before we can save
268 */
269 if( m_account-> valueText() == "" )
270 {
271 Wt::WMessageBox::show( TR("gcw.billPay.lbl.billPay"), TR("gcw.billPay.save.needaccount"), Wt::StandardButton::Ok );
272 return;
273 }
274
275#ifdef DUPLICATES_ARE_ALLOWED_SINCE_INTERNET_EXPENSES_ARE_PAID_TO_FRONTIER_AND_HOSTGATOR_AND_SO_ON_SO_THERE_CAN_BE_MULTIPLE_INTERNET_BILLS
276 /*
277 ** If the account is already in a bill-pay, then disallow
278 ** another duplicate
279 */
280 if( accountIsDuplicated() )
281 {
282 Wt::WMessageBox::show( TR("gcw.billPay.lbl.billPay"), TR("gcw.billPay.save.duplicate"), Wt::StandardButton::Ok );
283 return;
284 }
285#endif
286
287 /*
288 ** little bit of housekeeping before we begin
289 */
290 if( m_bpGuid == "" )
291 m_bpGuid = GCW::Core::newGuid();
292
293 /*
294 ** load the bpItem, if we had to create a new guid above,
295 ** then we'll end up with a 'new' bpItem.
296 **
297 */
298 auto bpItem = GCW::Gui::BillPay::bpItem( m_bpGuid );
299
300 /*
301 ** save everything
302 */
303 Wt::Dbo::Transaction t ( GCW::app() -> gnucashew_session() );
304 bpItem.set_accountGuid ( m_account -> valueGuid() );
305 bpItem.set_dueDay ( m_dueDay -> valueText() );
306 bpItem.set_minimum ( m_minimum -> valueText() );
307 bpItem.set_budget ( m_budget -> valueText() );
308 bpItem.set_nickname ( m_nickname -> valueText() );
309 bpItem.set_group ( m_group -> valueText() );
310 bpItem.set_limit ( m_limit -> valueText() );
311 bpItem.set_actual ( m_actual -> valueText() );
312 bpItem.set_url ( m_url -> valueText() );
313 bpItem.set_ap ( m_ap -> valueText() );
314 bpItem.set_isActive ( m_isActive -> valueText() );
315 bpItem.set_isVisible ( m_isVisible -> valueText() );
316 bpItem.set_autoPay ( m_autoPay -> valueText() );
317 bpItem.set_payNow ( m_payNow -> valueText() );
318 bpItem.set_last4 ( m_last4 -> valueText() );
319 bpItem.set_note ( m_note -> valueText() );
320
321 int i = 1;
322 for( auto cb : m_cbx )
323 bpItem.set_cb( i++, cb-> valueText() );
324
325 m_saved.emit();
326
327} // endsaveData()-> void
328
329
330
331static std::unique_ptr< GCW::Gui::BillPay::PaymentWidgetDialog > dialog;
332auto
334processPayment()-> void
335{
336 dialog = std::make_unique< GCW::Gui::BillPay::PaymentWidgetDialog >( m_bpGuid );
337 dialog-> show();
338 dialog->
339 finished().connect( [&]()
340 {
341 m_lastPaymentDate = dialog-> paymentDate();
342 dialog.reset( nullptr );
343 });
344
345} // endprocessPayment()-> void
346
347
348
350EditWidgetDialog( const std::string & _bpGuid )
351{
352 addStyleClass( "EditWidgetDialog" );
353 setWindowTitle( "Bill Pay Account" );
354
355 setClosable( true );
356 rejectWhenEscapePressed( true );
357
358 auto editWidget = contents()-> addNew< EditWidget >( _bpGuid );
359
360 editWidget-> saved ().connect( [&](){ accept(); });
361 editWidget-> canceled ().connect( [&](){ reject(); });
362
363} // endEditWidgetDialog( const std::string & _accountGuid )
364
365
#define GCW_GUI_BILLPAY_ITEM_CFY
Definition BillPay.h:40
static std::unique_ptr< GCW::Gui::BillPay::PaymentWidgetDialog > dialog
EditWidgetDialog(const std::string &_bpGuid)
Wt::WPushButton * m_pbDelete
Definition EditWidget.h:64
Wt::WPushButton * m_pbSave
Definition EditWidget.h:62
Wt::WPushButton * m_pbProcess
Definition EditWidget.h:65
std::vector< Wt::WCheckBox * > m_cbx
Definition EditWidget.h:86
Wt::WTabWidget * m_tabWidget
Definition EditWidget.h:85
GCW::Gui::AccountComboBox * m_account
Definition EditWidget.h:66
Wt::WCheckBox * m_isVisible
Definition EditWidget.h:77
Wt::WPushButton * m_pbCancel
Definition EditWidget.h:63
EditWidget(const std::string &_bpGuid)
GCW::Gui::AccountRegister::Widget * m_register
Definition EditWidget.h:61
auto guid() const -> std::string
Item GUID.
auto accountGuid() const -> std::string
Account GUID.
void emit(A... args) const
Widget * addNew(Args &&...args)
void setLayout(std::unique_ptr< WLayout > layout)
virtual void addWidget(std::unique_ptr< WWidget > widget)
EventSignal< WMouseEvent > & clicked()
virtual void resize(const WLength &width, const WLength &height) override
virtual void setStyleClass(const WString &styleClass) override
virtual void setMinimumSize(const WLength &width, const WLength &height) override
virtual void addStyleClass(const WString &styleClass, bool force=false) override
virtual void setToolTip(const WString &text, TextFormat textFormat=TextFormat::Plain) override
#define TR(X)
Definition define.h:17
auto newGuid() -> std::string
Generate new GUID string value.
Definition Core.cpp:235
auto fullName(const std::string &_guid) -> std::string
Account Fullname via GUID.
auto getByCfy(const std::string &_cfyValue) -> GCW::Dbo::Vars::Item::Vector
Definition Vars.cpp:75
auto bpItem(const std::string &_guid) -> GCW::Gui::BillPay::Item
Bill Pay Item.
Definition BillPay.cpp:33
auto toString(int _value) -> std::string
Convert Integer to String.
Definition BillPay.cpp:55
App * app()
Definition App.cpp:75