GnuCashew ~ GnuCash Enabled Web
GCW
AccountRegisterModel.h
Go to the documentation of this file.
1 #line 2 "src/Eng/AccountRegisterModel.h"
2 
3 #ifndef __ENG_ACCOUNTREGISTERMODEL_H___
4 #define __ENG_ACCOUNTREGISTERMODEL_H___
5 
6 #include <Wt/WStandardItemModel.h>
7 
8 #include "../GnuCashew.h"
9 
10 namespace GCW {
11  namespace Eng {
12 
13 /*!
14 ** \brief Account Register Model
15 **
16 ** This model is used to present account details to the
17 ** 'editor register' (the spreadsheet-looing book-like-looking
18 ** thing that the user posts transactions through.
19 **
20 */
22 : public Wt::WStandardItemModel
23 {
24  using RowItem = std::vector< std::unique_ptr< Wt::WStandardItem > >;
25  using ColItem = Wt::WStandardItem *;
26 
27  public:
28 
29  enum class ViewMode
30  {
31  /// basic one-line per transaction
33 
34  /// one-line ledger that auto-opens to multi-line for each selected row
36 
37  /// self explanatory
39  };
40 
41  /*!
42  ** \brief ctor
43  **
44  ** This opens the model associated with a specific account.
45  **
46  */
47  AccountRegisterModel( const std::string & _accountGuid = "", bool _editable = true );
48 
49  auto setAccountGuid( const std::string & _accountGuid )-> void ;
50  auto refreshFromDisk()-> void ;
51  auto saveToDisk()-> void ;
52 
53  auto viewMode() const-> ViewMode { return m_viewMode; }
54  auto setViewMode( ViewMode _viewMode )-> void;
55  auto doubleLine() const-> bool { return m_doubleLine; }
56  auto setDoubleLine( bool _doubleLine )-> void;
57 
58  /*!
59  ** \brief Is Read Only
60  **
61  ** This returns .true. if the item can be deleted.
62  **
63  */
64  auto isDeletable( const Wt::WModelIndex & _index )-> bool ;
65 
66  auto isEditable( int _row )-> bool ;
67  auto isEditable( const Wt::WModelIndex & _index )-> bool ;
68 
69  /*!
70  ** \brief Get GUID from row
71  **
72  ** This will retrieve the GUID value from the row.
73  **
74  */
75  auto getSplitGuid( const Wt::WModelIndex & _index )-> std::string ;
76  auto getSplitGuid( int _row )-> std::string ;
77 
78  /*!
79  ** \brief Get Date from the index
80  **
81  ** This pulls the 'date' column out and returns it as a WDateTime
82  ** value.
83  **
84  ** \note This will 'force' the 'time' component to be equal to
85  ** the default time of '10:59:00', since the 'date' column
86  ** does not support a time component... this seems to be
87  ** consistent with GnuCash.
88  **
89  */
90  auto getDate( const Wt::WModelIndex & _index )-> Wt::WDateTime;
91 
92  /*!
93  ** \brief Get Action
94  **
95  */
96  auto getAction( const Wt::WModelIndex & _index )-> std::string;
97 
98  /*!
99  ** \brief Get Description
100  **
101  */
102  auto getDescription( const Wt::WModelIndex & _index )-> std::string;
103 
104  /*!
105  ** \brief Get Transfer Account Text
106  **
107  */
108  auto getTransferText( const Wt::WModelIndex & _index )-> std::string;
109 
110  /*!
111  ** \brief Get Transfer Account GUID
112  **
113  */
114  auto getTransferGuid( const Wt::WModelIndex & _index )-> std::string;
115 
116  /*!
117  ** \brief Get Reconciliation
118  **
119  */
120  auto getReconcile( const Wt::WModelIndex & _index )-> std::string;
121 
122  /*!
123  ** \brief Get numeric value
124  **
125  ** This returns the numeric value of the line. This is suitable
126  ** for querying either the debit or credit column values (and is really
127  ** intended for internal use). The 'value' is pulled from the Display
128  ** value of the index and converted to a GCW_NUMERIC value.
129  **
130  */
131  auto getNumeric( const Wt::WModelIndex & _index )-> GCW_NUMERIC;
132 
133  /*!
134  ** \brief Get Debit value
135  **
136  */
137  auto getDebit( const Wt::WModelIndex & _index )-> GCW_NUMERIC;
138 
139  /*!
140  ** \brief Get Credit value
141  **
142  */
143  auto getCredit( const Wt::WModelIndex & _index )-> GCW_NUMERIC;
144 
145  /*!
146  ** \brief Get Value (positive or negative)
147  **
148  ** The value that gets stored in the back-end database is either positive
149  ** for debit, and negative for credit. This function will read-out the
150  ** debit and credit columns in the register display and figure out if
151  ** the returned value should be returned positive or negative corrected.
152  **
153  ** This function always positive for debit, and negative for credit values.
154  **
155  */
156  auto getValue( const Wt::WModelIndex & _index )-> GCW_NUMERIC;
157 
158  /*!
159  ** \brief
160  **
161  **
162  **
163  */
164  auto getBalance ( const Wt::WModelIndex & _index )-> GCW_NUMERIC ;
165 
166  auto present () const-> GCW_NUMERIC { return m_present; }
167  auto future () const-> GCW_NUMERIC { return m_future; }
168  auto cleared () const-> GCW_NUMERIC { return m_cleared; }
169  auto reconciled () const-> GCW_NUMERIC { return m_reconciled; }
170  auto projected () const-> GCW_NUMERIC { return m_projected; }
171 
172  auto makeRow( const std::string & _splitGuid )-> RowItem ;
173 
174  /*!
175  ** \brief Column Suggestions
176  **
177  ** This produces a unique-set of items that represent all the text-values
178  ** for that particular column. This is used to produce a suggestion-box
179  ** for the register.
180  **
181  */
182  auto suggestionsFromColumn( int _column ) const-> std::set< std::string > ;
183 
184  auto setData( const Wt::WModelIndex & _index, const Wt::cpp17::any & _value, Wt::ItemDataRole _role )-> bool ;
185 
186  auto goneDirty()-> Wt::Signal< Wt::WModelIndex > & { return m_goneDirty; }
187 /*
188 
189  these are additional values that need to be available
190 
191 balance
192  balance limit
193  balance (Period)
194  balance usd
195  cleared
196  cleared usd
197  fiture minimum
198  future minimum usa
199  last num
200  last reconcile date
201  opening balance
202  present
203  present usd
204  reconciled reconciled usd
205  total total period
206  total usd
207 */
208 
209  private:
210 
211  auto getString( const Wt::WModelIndex & _index, int column )-> std::string;
212 
213  auto saveToDisk( const Wt::WModelIndex & _index )-> void ;
214 
215 #ifdef NEVER
216  template <typename T>
217  bool matchValue( const Wt::cpp17::any & _any1, const Wt::cpp17::any & _any2 )
218  {
219  auto v1 = Wt::cpp17::any_cast< T >( _any1 );
220  auto v2 = Wt::cpp17::any_cast< T >( _any2 );
221  return v1 == v2;
222  }
223 #endif
224 
225  /*
226  ** Send a signal when a index is being updated
227  ** because it was dirty.
228  **
229  */
230  Wt::Signal< Wt::WModelIndex > m_goneDirty;
231 
232  /*
233  ** keep track of rows as they go dirty.
234  **
235  */
236 // std::set< int > m_dirtyRows;
237 
238  /*!
239  ** \brief Editable Indicator
240  **
241  ** The model can be either R/W (read-write) or R/O (read-only).
242  **
243  */
244  bool m_editable = false;
245 
247  bool m_doubleLine = false;
248 
249  /*!
250  ** \brief Account GUID
251  **
252  ** The model is associated with a single account.
253  **
254  */
255  std::string m_accountGuid;
256 
257  /*
258  ** Keep track of the last date entered for pre-populating
259  ** the next row.
260  **
261  */
262  std::string m_lastDate;
263 
269 
270 }; // endclass AccountRegisterModel
271 
272  } // namespace Eng {
273 } // endnamespace GCW {
274 
275 #endif // #ifndef __ENG_ACCOUNTREGISTERMODEL_H___
276 
277 
278 
auto getCredit(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get Credit value.
Wt::Signal< Wt::WModelIndex > m_goneDirty
auto getBalance(const Wt::WModelIndex &_index) -> GCW_NUMERIC
auto getDescription(const Wt::WModelIndex &_index) -> std::string
Get Description.
AccountRegisterModel(const std::string &_accountGuid="", bool _editable=true)
ctor
auto makeRow(const std::string &_splitGuid) -> RowItem
auto getTransferText(const Wt::WModelIndex &_index) -> std::string
Get Transfer Account Text.
auto setAccountGuid(const std::string &_accountGuid) -> void
auto reconciled() const -> GCW_NUMERIC
auto setDoubleLine(bool _doubleLine) -> void
auto getValue(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get Value (positive or negative)
auto goneDirty() -> Wt::Signal< Wt::WModelIndex > &
auto suggestionsFromColumn(int _column) const -> std::set< std::string >
Column Suggestions.
auto setData(const Wt::WModelIndex &_index, const Wt::cpp17::any &_value, Wt::ItemDataRole _role) -> bool
auto setViewMode(ViewMode _viewMode) -> void
auto getReconcile(const Wt::WModelIndex &_index) -> std::string
Get Reconciliation.
auto getDate(const Wt::WModelIndex &_index) -> Wt::WDateTime
Get Date from the index.
std::string m_accountGuid
Account GUID.
auto getString(const Wt::WModelIndex &_index, int column) -> std::string
auto isDeletable(const Wt::WModelIndex &_index) -> bool
Is Read Only.
auto future() const -> GCW_NUMERIC
auto getSplitGuid(const Wt::WModelIndex &_index) -> std::string
Get GUID from row.
auto getTransferGuid(const Wt::WModelIndex &_index) -> std::string
Get Transfer Account GUID.
auto refreshFromDisk() -> void
Refresh From Disk.
std::vector< std::unique_ptr< Wt::WStandardItem > > RowItem
auto getAction(const Wt::WModelIndex &_index) -> std::string
Get Action.
bool m_editable
Editable Indicator.
auto cleared() const -> GCW_NUMERIC
auto getDebit(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get Debit value.
@ BASIC_LEDGER
basic one-line per transaction
@ AUTOSPLIT_LEDGER
one-line ledger that auto-opens to multi-line for each selected row
auto getNumeric(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get numeric value.
auto present() const -> GCW_NUMERIC
auto viewMode() const -> ViewMode
auto projected() const -> GCW_NUMERIC
#define GCW_NUMERIC
Internal Numeric Type.
Definition: gcwglobal.h:37
Definition: App.h:17