GnuCashew ~ GnuCash Enabled Web
GCW
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 "../../Dbo/Transactions/Manager.h"
6 #include "../../Glb/Core.h"
7 #include "../AccountSuggestionEdit.h"
8 #include "BillPay.h"
9 
11 PaymentWidget( const std::string & _bpGuid )
12 : Wt::WContainerWidget(),
13  m_bpGuid( _bpGuid )
14 {
15  addStyleClass( "PaymentWidget" );
16 
17  /*
18  ** use a layout.
19  */
20  auto lw = setLayout( std::make_unique< Wt::WVBoxLayout >() );
21 
22  /*
23  ** This is a complex widget, with a header area with a
24  ** handful of fields, and some controls and whatnot.
25  */
26  auto templtMain =
27  lw->
28  addWidget( std::make_unique< Wt::WTemplate >( TR("gcw_gui.billpay.paymentwidget.form.main") ) );
29 
30  /*
31  ** insert the table
32  */
33  m_table = templtMain-> bindNew< Wt::WTable >( "table" );
34  m_table-> addStyleClass( "MakePaymentTable" );
35 
36  /*
37  ** add the first row of widgets
38  */
39  m_date = table()-> elementAt( 0, 0 )-> addNew< Wt::WDateEdit >( );
40  m_num = table()-> elementAt( 0, 1 )-> addNew< Wt::WLineEdit >( );
41  m_desc = table()-> elementAt( 0, 2 )-> addNew< Wt::WLineEdit >( );
42  auto acct = table()-> elementAt( 0, 3 )-> addNew< AccountSuggestionEdit >( );
43  m_recon = table()-> elementAt( 0, 4 )-> addNew< Wt::WLineEdit >( );
44  m_debit = table()-> elementAt( 0, 5 )-> addNew< Wt::WLineEdit >( );
45  m_credit = table()-> elementAt( 0, 6 )-> addNew< Wt::WLineEdit >( );
46 
47 #ifdef INCLUDE_TABLE_WITH_MULTIPLE_INPUT_ROWS
48  /*
49  ** add the edit widget to the tableWidgets vector set
50  */
51  auto _addElement = [&]( size_t _row, size_t _col, const char * styleClass, Wt::WFormWidget * _element )
52  {
53  _element-> addStyleClass( styleClass );
54 
55  if( m_tableWidgets.size() <= _row )
56  m_tableWidgets.resize( _row + 1 );
57 
58  if( m_tableWidgets[_row].size() <= _col )
59  m_tableWidgets[_row].resize( _col + 1 );
60 
61  m_tableWidgets[_row][_col] = _element;
62  };
63 
64  /*
65  ** add a LineEdit to the table
66  */
67  auto _addLineEdit = [&]( size_t _row, size_t _col, const char * _styleClass )
68  {
69  auto element = table()-> elementAt( _row, _col )-> addNew< Wt::WLineEdit >();
70  _addElement( _row, _col, _styleClass, element );
71  };
72 
73  /*
74  ** add the AccountSeggestionEdit to the table
75  */
76  auto _addAcctEdit = [&]( size_t _row, size_t _col, const char * _styleClass )
77  {
78  auto element = table()-> elementAt( _row, _col )-> addNew< AccountSuggestionEdit >();
79  _addElement( _row, _col, _styleClass, element );
80  };
81 
82  /*
83  ** build the table
84  */
85  for( int row=1; row<= 3; row++ )
86  {
87  _addLineEdit( row, 1, "num" );
88  _addLineEdit( row, 2, "desc" );
89  _addAcctEdit( row, 3, "acct" );
90  _addLineEdit( row, 4, "recon" );
91  _addLineEdit( row, 5, "debit" );
92  _addLineEdit( row, 6, "credit" );
93  }
94 #endif
95 
96  /*
97  ** apply styling
98  */
99  m_date -> addStyleClass ( "date" );
100  m_num -> addStyleClass ( "num" );
101  m_desc -> addStyleClass ( "desc" );
102  acct -> addStyleClass ( "acct" );
103  m_recon -> addStyleClass ( "recon" );
104  m_debit -> addStyleClass ( "debit" );
105  m_credit -> addStyleClass ( "credit" );
106 
107  m_date -> setPlaceholderText ( "Date" );
108  m_num -> setPlaceholderText ( "Num" );
109  m_desc -> setPlaceholderText ( "Description" );
110  m_recon -> setPlaceholderText ( "R" );
111  m_debit -> setPlaceholderText ( "Debit" );
112  m_credit -> setPlaceholderText ( "Credit" );
113 
114 // m_trans1 -> setToolTip( TR("gcw.billPay.toolTip.trans" ) );
115 // m_date1 -> setToolTip( TR("gcw.billPay.toolTip.date" ) );
116 // m_memo1 -> setToolTip( TR("gcw.billPay.toolTip.memo" ) );
117 // m_confirm -> setToolTip( TR("gcw.billPay.toolTip.confirm" ) );
118 
119  m_confirm = templtMain-> bindNew< Wt::WTextArea >( "confirm" );
120  m_confirm-> setPlaceholderText( "Confirmation" );
121 
122  /*
123  ** get all the data loaded
124  */
125  loadData();
126 
127 } // endPaymentWidget( const std::string & _bpGuid )
128 
129 auto
131 loadData()-> void
132 {
133  /*
134  ** be safe
135  */
136  if( m_bpGuid == "" )
137  return;
138 
139  auto bpItem = GCW::Gui::BillPay::bpItem( bpGuid() );
140 
141  std::cout << __FILE__ << ":" << __LINE__ << " bpItem:" << bpItem.guid() << std::endl;
142  std::cout << __FILE__ << ":" << __LINE__ << " account:" << bpItem.accountGuid() << std::endl;
143 
144  GCW::Dbo::Transactions::Manager transactionManager;
145 
146  m_date-> setValueText( GCW::Core::currentDateTimeDisplayString() );
147 
148 } // endloadData()-> void
149 
150 auto
152 saveData()-> void
153 {
154  /*
155  ** load the bpItem
156  */
157  auto bpItem = GCW::Gui::BillPay::bpItem( m_bpGuid );
158 
159  std::cout << __FILE__ << ":" << __LINE__
160  << " " << bpItem.accountFullName()
161  << " " << bpItem.nickname()
162  << std::endl;
163 
164 #ifdef NEVER
165  Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
166  bpItem.set_accountGuid ( m_account -> valueGuid() );
167  bpItem.set_dueDay ( m_dueDay -> valueText() );
168  bpItem.set_minimum ( m_minimum -> valueText() );
169  bpItem.set_budget ( m_budget -> valueText() );
170  bpItem.set_nickname ( m_nickname -> valueText() );
171  bpItem.set_group ( m_group -> valueText() );
172  bpItem.set_limit ( m_limit -> valueText() );
173  bpItem.set_actual ( m_actual -> valueText() );
174  bpItem.set_url ( m_url -> valueText() );
175  bpItem.set_ap ( m_ap -> valueText() );
176  bpItem.set_isActive ( m_isActive -> valueText() );
177  bpItem.set_isVisible ( m_isVisible -> valueText() );
178  bpItem.set_autoPay ( m_autoPay -> valueText() );
179  bpItem.set_payNow ( m_payNow -> valueText() );
180  bpItem.set_last4 ( m_last4 -> valueText() );
181  bpItem.set_note ( m_note -> valueText() );
182 
183  int i = 1;
184  for( auto cb : m_cbx )
185  bpItem.set_cb( i++, cb-> valueText() );
186 
187 #endif
188 
189 } // endsaveData()-> void
190 
192 PaymentWidgetDialog( const std::string & _bpGuid )
193 {
194  rejectWhenEscapePressed( true );
195  setClosable( true );
196 
197  addStyleClass( "PaymentWidgetDialog" );
198  setWindowTitle( TR( "gcw.billPay.dialog.title" ) );
199 
200  auto editWidget = contents()-> addNew< PaymentWidget >( _bpGuid );
201 
202  auto pbSave = titleBar()-> addNew< Wt::WPushButton >( TR( "gcw.billPay.label.save" ) );
203  auto pbCancel = titleBar()-> addNew< Wt::WPushButton >( TR( "gcw.billPay.label.cancel" ) );
204 
205  pbSave -> setStyleClass( "btn-xs" );
206  pbCancel -> setStyleClass( "btn-xs" );
207 
208  pbSave -> clicked().connect( [this,editWidget](){ editWidget-> saveData(); accept(); } );
209  pbCancel -> clicked().connect( this, &Wt::WDialog::reject );
210 
211 } // endPaymentWidgetDialog( const std::string & _bpGuid )
212 
213 
214 
Transaction Manager.
Definition: Manager.h:30
PaymentWidgetDialog(const std::string &_bpGuid)
std::vector< std::vector< Wt::WFormWidget * > > m_tableWidgets
Definition: PaymentWidget.h:62
auto table() -> Wt::WTable *
Definition: PaymentWidget.h:50
PaymentWidget(const std::string &_bpGuid)
#define TR(X)
Definition: define.h:17
auto currentDateTimeDisplayString() -> std::string
Definition: Core.cpp:287
auto bpItem(const std::string &_guid) -> GCW::Gui::BillPay::Item
Bill Pay Item.
Definition: BillPay.cpp:19
App * app()
Definition: App.cpp:67
Definition: GncLock.h:6