GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
TransactionManager.cpp
Go to the documentation of this file.
1#line 2 "src/Eng/TransactionManager.cpp"
2
3#include "../Glb/Core.h"
4#include "../Gui/AccountRegister/Model.h"
6
9: m_prefrenceItem( GCW::Dbo::Prefrences::get() )
10{
11
12} // endManager()
13
16: m_model( _model ),
17 m_prefrenceItem( GCW::Dbo::Prefrences::get() )
18{
19
20} // endManager()
21
22auto
24newTransaction( const std::string & _accountGuid1, const std::string & _accountGuid2 )-> void
25{
26 /*!
27 ** The process begins by loading up the two accounts.
28 */
29 auto accountItem1 = GCW::Dbo::Accounts::load( _accountGuid1 );
30
31 /*
32 ** create a new transaction with two splits
33 */
34 m_transactionItem = GCW::Dbo::Transactions::add( GCW::Core::newGuid() );
35
36 /*
37 ** hook everything together
38 */
39 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
40 // transaction
41 m_transactionItem.modify()-> set_currency_guid( accountItem1-> commodity_guid() );
42 m_transactionItem.modify()-> set_enter_date( Wt::WDateTime::currentDateTime() );
43 // Split1
45 split1.modify()-> set_tx_guid ( m_transactionItem-> guid() );
46 split1.modify()-> set_account_guid ( _accountGuid1 );
47 split1.modify()-> set_reconcile_state ( GCW_RECONCILE_NO );
48 split1.modify()-> set_reconcile_date ( GCW_DEFAULT_DATE );
49 // Split2
51 split2.modify()-> set_tx_guid ( m_transactionItem-> guid() );
52 split2.modify()-> set_account_guid ( _accountGuid2 );
53 split2.modify()-> set_reconcile_state ( GCW_RECONCILE_NO );
54 split2.modify()-> set_reconcile_date ( GCW_DEFAULT_DATE );
55
56 /*
57 ** record the splits
58 */
59 m_splits.push_back( split1 );
60 m_splits.push_back( split2 );
61
62} // endnewTransaction()-> void
63
64auto
66loadTransaction( const std::string & _transactionGuid )-> void
67{
68 /*
69 ** set the transaction
70 */
71 m_transactionItem = GCW::Dbo::Transactions::load( _transactionGuid );
72
73 /*
74 ** set the splits
75 */
76 m_splits = GCW::Dbo::Splits::byTransaction( m_transactionItem-> guid() );
77
78} // endloadTransaction( const std::string & _transactionGuid )-> void
79
80auto
82deleteTransaction()-> void
83{
84
85 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
86 m_transactionItem.remove();
87 for( auto & splitItem : m_splits )
88 splitItem.remove();
89
90} // enddeleteTransaction()-> void
91
92auto
95{
96 if( !_splitItem )
97 return;
98
99 loadSplit( _splitItem-> guid() );
100
101} // endsetSplitItem( GCW::Dbo::Splits::Item::Ptr _splitItem )-> void
102
103auto
105loadSplit( const std::string & _splitGuid )-> void
106{
107 if( _splitGuid == "" )
108 return;
109
110 /*
111 ** in the words of spock: 'remember'
112 */
113 m_splitGuid = _splitGuid;
114
115 /*
116 ** get the split so we can grab the transaction
117 */
118 auto splitItem = GCW::Dbo::Splits::load( _splitGuid );
119
120 /*
121 ** set the transaction
122 */
123 loadTransaction( splitItem-> tx_guid() );
124
125} // endloadSplit( const std::string & _splitGuid )-> void
126
127auto
129otherGuid() const-> std::string
130{
131 for( auto & splitItem : m_splits )
132 if( splitItem-> guid() != m_splitGuid )
133 return splitItem-> guid();
134
135 return "";
136
137} // endotherGuid()-> std::string
138
139auto
141split( const std::string & _splitGuid ) const-> GCW::Dbo::Splits::Item::Ptr
142{
143 for( auto & splitItem : m_splits )
144 if( splitItem-> guid() == _splitGuid )
145 return splitItem;
146
148
149} // endsplit( const std::string & _splitGuid ) const-> GCW::Dbo::Splits::Item::Ptr
150
151auto
153thisSplit() const-> GCW::Dbo::Splits::Item::Ptr
154{
155 return split( m_splitGuid );
156
157} // endthisSplit() const-> GCW::Dbo::Splits::Item::Ptr
158
159auto
161thatSplit() const-> GCW::Dbo::Splits::Item::Ptr
162{
163 return split( otherGuid() );
164
165} // endthatSplit() const-> GCW::Dbo::Splits::Item::Ptr
166
167auto
169forAccountSplit( const std::string & _accountGuid ) const-> GCW::Dbo::Splits::Item::Ptr
170{
172
173 for( auto & split : m_splits )
174 if( split-> account_guid() == _accountGuid )
175 retVal = split;
176
177 return retVal;
178
179} // endforAccount( const std::string * _accountGuid ) const-> GCW::Dbo::Splits::Item::Ptr
180
181auto
183getDate() const-> Wt::WDateTime
184{
185 return m_transactionItem-> post_date_as_date();
186
187} // endgetDate() const-> Wt::WDateTime &;
188
189auto
191getDateAsString() const-> Wt::WString
192{
193 return getDate().toString( GCW_DATE_FORMAT_DISPLAY );
194
195} // endgetDate() const-> Wt::WDateTime &;
196
197auto
199setDate( const Wt::WDateTime & _value )-> void
200{
201 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
202 m_transactionItem.modify()-> set_post_date( _value );
203
204} // endsetDate( const Wt::WDateTime & _value )-> void
205
206auto
208setDate( const Wt::WDate & _value )-> void
209{
210 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
211 m_transactionItem.modify()-> set_post_date( Wt::WDateTime( _value ) );
212
213} // endsetDate( const Wt::WDateTime & _value )-> void
214
215
216
217auto
219setAction( const std::string & _value )-> void
220{
221 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
222 m_transactionItem.modify()-> set_num( _value );
223
224} // endsetAction( const std::string & _value )-> void
225
226auto
228getDescription() const-> std::string
229{
230 return m_transactionItem-> description();
231
232} // endgetDescription() const-> std::string &
233
234auto
236setDescription( const std::string & _value )-> void
237{
238 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
239 m_transactionItem.modify()-> set_description( _value );
240
241} // endsetDescription( const std::string & _value )-> void
242
243auto
245setDescription( const Wt::WString & _value )-> void
246{
247 setDescription( _value.toUTF8() );
248
249} // ensetDescription( const Wt::WString & _value )-> void
250
251auto
253getNum() const-> std::string
254{
255 return m_transactionItem-> num();
256
257} // endgetDescription() const-> std::string &
258
259auto
261setNum( const std::string & _value )-> void
262{
263 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
264 m_transactionItem.modify()-> set_num( _value );
265
266} // endsetDescription( const std::string & _value )-> void
267
268auto
270setNum( const Wt::WString & _value )-> void
271{
272 setNum( _value.toUTF8() );
273
274} // ensetDescription( const Wt::WString & _value )-> void
275
276auto
278setTransferGuid( const std::string & _value )-> void
279{
280 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
281 thatSplit().modify()-> set_account_guid( _value );
282
283} // endsetTransferGuid( const std::string & _value )-> void
284
285auto
287setReconcile( const std::string & _value )-> void
288{
289 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
290 thisSplit().modify()-> set_reconcile_state( _value );
291
292} // endsetReconcile( const std::string & _value )-> void
293
294auto
296getValue() const-> GCW_NUMERIC
297{
298 return thisSplit()-> value();
299
300} // endgetValue() const-> GCW_NUMERIC
301
302auto
304getValueAsString() const-> std::string
305{
306 return thisSplit()-> valueAsString();
307
308} // endgetValue() const-> GCW_NUMERIC
309
310auto
312setValue( GCW_NUMERIC _value )-> void
313{
314// Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
315// thisSplit().modify()-> set_value( _value );
316// thatSplit().modify()-> set_value( _value * -1 );
317
318} // endsetDebit( GCW_NUMERIC _value )-> void
319
320auto
322setValue( const std::string & _acctGuid, GCW_NUMERIC _value )-> void
323{
324 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
325 forAccountSplit( _acctGuid ).modify()-> set_value( _value );
326
327} // endsetValue( const std::string & _acctGuid, GCW_NUMERIC _value )-> void
328
329auto
331setNotes( const std::string & _acctGuid, const std::string & _value )-> void
332{
333 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
334 forAccountSplit( _acctGuid ).modify()-> set_memo( _value );
335
336} // endsetNotes( const std::string & _value )-> void
337
338
339auto
341otherSplits() const-> GCW::Dbo::Splits::Item::Vector
342{
343 return GCW::Dbo::Splits::bySplitExcept( m_splitGuid );
344
345} // endotherSplits() const-> GCW::Dbo::Splits::Item::Vector
346
347auto
349setReadOnly( bool _value )-> void
350{
351
352} // endsetReadOnly( bool _value )-> void
353
354auto
356createText( const std::string & _text ) const-> std::unique_ptr< Wt::WStandardItem >
357{
358 auto retVal = std::make_unique< Wt::WStandardItem >( _text );
359
360 retVal-> setStyleClass( "blank" );
361
362 return std::move( retVal );
363
364} // endcreateBlank() const-> std::unique_ptr< Wt::WStandardItem >
365
366auto
368createBlank() const-> std::unique_ptr< Wt::WStandardItem >
369{
370 auto retVal = std::make_unique< Wt::WStandardItem >();
371
372 retVal-> setStyleClass( "blank" );
373
374 return std::move( retVal );
375
376} // endcreateBlank() const-> std::unique_ptr< Wt::WStandardItem >
377
378auto
380createEmpty() const-> std::unique_ptr< Wt::WStandardItem >
381{
382 auto retVal = std::make_unique< Wt::WStandardItem >();
383
384 retVal-> setStyleClass( "empty" );
385
386 return std::move( retVal );
387
388} // endcreateEmpty() const-> std::unique_ptr< Wt::WStandardItem >
389
390auto
392createDate( TxItem _txItem ) const-> std::unique_ptr< Wt::WStandardItem >
393{
394 auto retVal = std::make_unique< Wt::WStandardItem >();
395
396 retVal-> setStyleClass( "date" );
397 retVal-> setFlags( Wt::ItemFlag::DeferredToolTip );
398
399 /*!
400 ** \note The post_date column (col-0) also carries with it the guid of the split
401 ** item itself, so that the originating split can be located from the table
402 ** view. The guid can be accessed by;
403 **
404 ** \code
405 ** Wt::WString splitRowGuid = Wt::asString( standardItem.data( Wt::ItemDataRole::User ) )
406 ** \endcode
407 **
408 ** \sa getSplitGuid
409 */
410// auto tip =
411// Wt::WString
412// (
413// "row: {1}\n"
414// "acg: {2}\n"
415// "spg: {3}\n"
416// )
417// .arg( m_model-> rowCount() )
418// .arg( thisSplit()-> account_guid() )
419// .arg( thisSplit()-> guid() )
420// ;
421
422 retVal-> setData( transactionItem()-> post_date_as_date(), Wt::ItemDataRole::Edit );
423 retVal-> setData( thisSplit()-> guid(), Wt::ItemDataRole::User );
424// retVal-> setToolTip( tip );
425
426 return std::move( retVal );
427
428} // endcreateDate() const-> std::unique_ptr< Wt::WStandardItem > ;
429
430auto
432createNum( TxItem _txItem ) const-> std::unique_ptr< Wt::WStandardItem >
433{
434 auto retVal = std::make_unique< Wt::WStandardItem >( _txItem-> num() );
435
436 retVal-> setStyleClass( "txnum" );
437 retVal-> setFlags( Wt::ItemFlag::DeferredToolTip );
438
439 return std::move( retVal );
440
441} // endcreateNum() const-> std::unique_ptr< Wt::WStandardItem >
442
443
444auto
446createNum( SpItem _spItem ) const-> std::unique_ptr< Wt::WStandardItem >
447{
448 auto retVal = std::make_unique< Wt::WStandardItem >( _spItem-> action() );
449
450 retVal-> setStyleClass( "spnum" );
451 retVal-> setFlags( Wt::ItemFlag::DeferredToolTip );
452
453 return std::move( retVal );
454
455} // endcreateNum() const-> std::unique_ptr< Wt::WStandardItem >
456
457
458auto
460createDescription( TxItem _txItem ) const-> std::unique_ptr< Wt::WStandardItem >
461{
462 auto retVal = std::make_unique< Wt::WStandardItem >( _txItem-> description() );
463
464 retVal-> setStyleClass( "txdesc" );
465 retVal-> setFlags( Wt::ItemFlag::DeferredToolTip );
466
467 return std::move( retVal );
468
469} // endcreateDescription() const-> std::unique_ptr< Wt::WStandardItem >
470
471
472auto
474createDescription( SpItem _spItem ) const-> std::unique_ptr< Wt::WStandardItem >
475{
476 auto retVal = std::make_unique< Wt::WStandardItem >( _spItem-> memo() );
477
478 retVal-> setStyleClass( "spdesc" );
479 retVal-> setFlags( Wt::ItemFlag::DeferredToolTip );
480
481 return std::move( retVal );
482
483} // endcreateDescription() const-> std::unique_ptr< Wt::WStandardItem >
484
485#ifdef NEVER
486auto
488createAccount( SpItem _splitItem ) const-> std::unique_ptr< Wt::WStandardItem >
489{
490 auto retVal = std::make_unique< Wt::WStandardItem >();
491 retVal-> setStyleClass( "acct" );
492 retVal-> setFlags( Wt::ItemFlag::DeferredToolTip );
493
494 /*!
495 ** The 'account' text depends on the
496 ** target account defined in the split. There are three
497 ** possibilities here;
498 **
499 ** -# no splits... this shows up as an <b>'imbalance'</b> (this is an error condition)
500 ** -# 1 split... this just shows the split account on the same single line
501 ** -# >1 split... this is more than one target account, so just indicate 'split'
502 */
503 switch( otherSplits().size() )
504 {
505 /*!
506 ** \par Imbalance
507 ** This is actually a problem... We don't have another split, and
508 ** according to 'generally accepted accounting practices' we
509 ** should! So, just plop an 'imbalance' indicator in the view.
510 ** A style-class is also applied to the item to allow the rendering
511 ** in the view to highlight this problem.
512 */
513 case 0:
514 {
515 retVal-> setText( TR("gcw.AccountRegister.account.imbalanceUSD") ); // account
516 retVal-> setStyleClass( retVal-> styleClass() + " errval" );
517 retVal-> setToolTip( TR("gcw.AccountRegister.account.imbalanceUSD.toolTip") );
518 break;
519 }
520
521 /*!
522 ** \par Normal Split
523 ** This is a straight and simple 1:1 split transaction, so we can pull
524 ** the account name from the other side of the split and pop that in
525 ** to the model directly.
526 */
527 case 1:
528 {
529 auto txSplitItem = *otherSplits().begin();
530 auto splitAccountItem = GCW::Dbo::Accounts::byGuid( txSplitItem-> account_guid() );
531
532 // yes, we have one account item
533 if( splitAccountItem )
534 {
535 retVal-> setText( GCW::Dbo::Accounts::fullName( splitAccountItem-> guid() ) );
536
537 auto tip =
539 (
540 "spa:{1}\n"
541 "txi:{2}\n"
542 )
543 .arg( splitAccountItem-> guid() )
544 .arg( txSplitItem-> guid() )
545 ;
546 retVal-> setToolTip( tip );
547 }
548
549 // no, we don't have an account item
550 else
551 {
552 /*!
553 ** \par Another Imbalance
554 ** This is another problem... We have another split, but the account
555 ** we are split-to doesn't exist. This is a problem and should not
556 ** happen and represents an error in the database. This means the
557 ** account containing this guid nolonger exists. That should never
558 ** happen.
559 */
560 retVal-> setText( TR("gcw.AccountRegister.account.imbalanceUSD") );
561 retVal-> setStyleClass( retVal-> styleClass() + " errval" );
562
563 auto toolTip =
564 Wt::WString("target guid:{1}\n{2}")
565 .arg( txSplitItem-> account_guid() )
566 .arg( TR("gcw.AccountRegister.account.invalidTarget.toolTip") )
567 .toUTF8()
568 ;
569
570 retVal-> setToolTip( toolTip );
571
572 } // endelse no account item
573
574 break;
575
576 } // endcase 1:
577
578 /*!
579 ** \par Multi-Split
580 ** When we have more than one split then we cannot display
581 ** all of the split accounts on just one line, so just pop
582 ** a message that indicates that we're in a multisplit
583 ** transaction.
584 */
585 default:
586 {
587 retVal-> setText( TR("gcw.AccountRegister.account.multisplit") ); // account
588 }
589
590 } // endswitch( transMan.otherSplits().size() )
591
592
593 return std::move( retVal );
594
595} // endcreateAccount() const-> std::unique_ptr< Wt::WStandardItem >
596#endif
597
598auto
600createAccount( SpItem _splitItem ) const-> std::unique_ptr< Wt::WStandardItem >
601{
602 auto retVal = std::make_unique< Wt::WStandardItem >();
603 retVal-> setStyleClass( "acct" );
604 retVal-> setFlags( Wt::ItemFlag::DeferredToolTip );
605
606 auto splitAccountItem = GCW::Dbo::Accounts::byGuid( _splitItem-> account_guid() );
607
608 // yes, we have one account item
609 if( splitAccountItem )
610 {
611 retVal-> setText( GCW::Dbo::Accounts::fullName( splitAccountItem-> guid() ) );
612
613 auto tip =
615 (
616 "spa:{1}\n"
617 "txi:{2}\n"
618 )
619 .arg( splitAccountItem-> guid() )
620 .arg( _splitItem-> guid() )
621 ;
622 retVal-> setToolTip( tip );
623 }
624
625 // no, we don't have an account item
626 else
627 {
628 /*!
629 ** \par Another Imbalance
630 ** This is another problem... We have another split, but the account
631 ** we are split-to doesn't exist. This is a problem and should not
632 ** happen and represents an error in the database. This means the
633 ** account containing this guid nolonger exists. That should never
634 ** happen.
635 */
636 retVal-> setText( TR("gcw.AccountRegister.account.imbalanceUSD") );
637 retVal-> setStyleClass( retVal-> styleClass() + " errval" );
638
639 auto toolTip =
640 Wt::WString("target guid:{1}\n{2}")
641 .arg( _splitItem-> account_guid() )
642 .arg( TR("gcw.AccountRegister.account.invalidTarget.toolTip") )
643 .toUTF8()
644 ;
645 retVal-> setToolTip( toolTip );
646
647 } // endelse no account item
648
649 return std::move( retVal );
650
651} // endcreateAccount() const-> std::unique_ptr< Wt::WStandardItem >
652
653auto
655createReconcile( SpItem _splitItem ) const-> std::unique_ptr< Wt::WStandardItem >
656{
657 auto retVal = std::make_unique< Wt::WStandardItem >( _splitItem-> reconcile_state() );
658
659 retVal-> setStyleClass( "rec" );
660 retVal-> setFlags( Wt::ItemFlag::DeferredToolTip );
661
662 return std::move( retVal );
663
664} // endcreateReconcile() const-> std::unique_ptr< Wt::WStandardItem >
665
666auto
668createDebit( SpItem _splitItem ) const-> std::unique_ptr< Wt::WStandardItem >
669{
670 auto retVal = std::make_unique< Wt::WStandardItem >( );
671
672 retVal-> setStyleClass( "dr" );
673 retVal-> setFlags( Wt::ItemFlag::DeferredToolTip );
674
675 /*
676 ** debits are always positive
677 */
678 if( _splitItem-> value() > 0 )
679 {
680 retVal -> setText( _splitItem-> valueAsString() );
681 }
682
683 return std::move( retVal );
684
685} // endcreateDebit() const-> std::unique_ptr< Wt::WStandardItem >
686
687auto
689createCredit( SpItem _splitItem ) const-> std::unique_ptr< Wt::WStandardItem >
690{
691 auto retVal = std::make_unique< Wt::WStandardItem >( );
692
693 retVal-> setStyleClass( "cr" );
694 retVal-> setFlags( Wt::ItemFlag::DeferredToolTip );
695
696 /*
697 ** credit are always negative
698 */
699 if( _splitItem-> value() < 0 )
700 {
701 /*
702 ** set the value and invert(true) the sign
703 */
704 retVal -> setText( _splitItem-> valueAsString( true ) );
705 }
706
707 return std::move( retVal );
708
709} // endcreateCredit() const-> std::unique_ptr< Wt::WStandardItem >
710
711auto
713createBalance() const-> std::unique_ptr< Wt::WStandardItem >
714{
715 auto retVal = std::make_unique< Wt::WStandardItem >( toString( model()-> m_balance, GCW::Cfg::decimal_format() ) );
716
717 retVal-> setStyleClass( "bal" );
718 retVal-> setFlags( Wt::ItemFlag::DeferredToolTip );
719
720 return std::move( retVal );
721
722} // endcreateBalance() const-> std::unique_ptr< Wt::WStandardItem >
723
724auto
726highlightNegativeBalance( RowItem & _row ) const-> void
727{
728 /*
729 ** if the balance is negative, highlight the row
730 */
731 if( model()-> m_balance < 0 )
732 {
733 if( prefrenceItem().accountRegisterHighlight( GCW::Dbo::Prefrences::AccountRegisterHighlight::NEGVAL_EXTRA ) )
734 {
735 for( int col = 0; col< _row.size(); col++ )
736 _row.at( col )-> setStyleClass( _row.at( col )-> styleClass() + " negval" );
737 }
738
739 if( prefrenceItem().accountRegisterHighlight( GCW::Dbo::Prefrences::AccountRegisterHighlight::NORMAL ) )
740 {
741 _row.at( _row.size()-1 )-> setStyleClass( _row.at( _row.size()-1 )-> styleClass() + " negval" );
742 }
743
744 } // endif( model()-> m_balance < 0 )
745
746
747} // endhighlightNegativeBalance() const-> void
748
749auto
751appendBasicLedger() const-> void
752{
753 RowItem row ;
754
755 row.push_back( createDate ( transactionItem() ) );
756 row.push_back( createNum ( transactionItem() ) );
757 row.push_back( createDescription ( transactionItem() ) );
758 row.push_back( createAccount ( thatSplit() ) );
759 row.push_back( createReconcile ( thisSplit() ) );
760 row.push_back( createDebit ( thisSplit() ) );
761 row.push_back( createCredit ( thisSplit() ) );
762 row.push_back( createBalance ( ) );
763
764 highlightNegativeBalance( row );
765
766 /*
767 ** set alternating row colors (row-basic-ledger: rowbl)
768 */
769 for( int col=0; col< row.size(); col++ )
770 row.at(col)-> setStyleClass( row.at(col)-> styleClass() + " rowbl" );
771
772 model()-> appendRow( std::move( row ) );
773
774} // endappendBasicLedger() const-> void
775
776auto
778appendAutosplitLedger() const-> void
779{
780} // endappendAutosplitLedger() const-> void
781
782auto
784appendTransactionJournal() const-> void
785{
786 /*
787 ** set the first line
788 */
789 {
790 RowItem row ;
791
792 row.push_back( createDate ( transactionItem() ) );
793 row.push_back( createNum ( transactionItem() ) );
794 row.push_back( createDescription ( transactionItem() ) );
795 row.push_back( createEmpty ( ) ); // account is empty on this row
796 row.push_back( createEmpty ( ) ); // reconcile is empty on this row
797 row.push_back( createDebit ( thisSplit() ) );
798 row.push_back( createCredit ( thisSplit() ) );
799 row.push_back( createBalance ( ) );
800
801 highlightNegativeBalance( row );
802
803 /*
804 ** set static row color (row-transaction-journal: rowtj)
805 */
806 for( int col=0; col< row.size(); col++ )
807 row.at(col)-> setStyleClass( row.at(col)-> styleClass() + " rowtj" );
808
809 model()-> appendRow( std::move( row ) );
810 }
811
812 /*
813 ** set another line, one for each split
814 */
815 for( auto splitItem : splits() )
816 {
817 RowItem row ;
818 row.push_back( createEmpty ( ) );
819 row.push_back( createNum ( splitItem ) );
820 row.push_back( createDescription ( splitItem ) );
821 row.push_back( createAccount ( splitItem ) );
822 row.push_back( createReconcile ( splitItem ) );
823 row.push_back( createDebit ( splitItem ) );
824 row.push_back( createCredit ( splitItem ) );
825 row.push_back( createEmpty ( ) );
826
827 for( int col=1; col< row.size(); col++ )
828 row.at(col)-> setStyleClass( row.at(col)-> styleClass() + " rowtd" );
829
830 model()-> appendRow( std::move( row ) );
831 }
832
833 if( model()-> doubleLine() )
834 {
835 RowItem row ;
836 row.push_back( createEmpty() );
837 row.push_back( createEmpty() );
838 row.push_back( createEmpty() );
839 row.push_back( createEmpty() );
840 row.push_back( createEmpty() );
841 row.push_back( createEmpty() );
842 row.push_back( createEmpty() );
843 row.push_back( createEmpty() );
844
845 model()-> appendRow( std::move( row ) );
846 }
847
848} // endappendTransactionJournal() const-> void
849
850auto
852appendGeneralJournal() const-> void
853{
854} // endappendGeneralJournal() const-> void
855
856
857
858auto
860appendRow()-> void
861{
862 /*
863 ** calculate the running balance
864 */
865 model()-> m_balance += thisSplit()-> value();
866
867 /*
868 ** build a row depending on the view mode
869 */
870 switch( model()-> viewMode() )
871 {
873 {
874 appendBasicLedger();
875 break;
876 }
877
879 {
880 appendAutosplitLedger();
881 break;
882 }
883
885 {
886 appendTransactionJournal();
887 break;
888 }
889
891 {
892 appendGeneralJournal();
893 break;
894 }
895
896 } // endswitch( model()-> viewMode() )
897
898} // endappendRow()-> void
899
900
901
static std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Definition Core.cpp:16
Wt::Dbo::ptr< Item > Ptr
Definition BaseItem.h:39
auto createBalance() const -> std::unique_ptr< Wt::WStandardItem >
auto highlightNegativeBalance(RowItem &_row) const -> void
auto createCredit(SpItem _spItem) const -> std::unique_ptr< Wt::WStandardItem >
auto setTransferGuid(const std::string &_value) -> void
Set Transfer GUID.
auto newTransaction(const std::string &_accountGuid1, const std::string &_accountGuid2) -> void
New Transaction.
auto createReconcile(SpItem _spItem) const -> std::unique_ptr< Wt::WStandardItem >
auto forAccountSplit(const std::string &_accountGuid) const -> GCW::Dbo::Splits::Item::Ptr
Load Split for Account.
auto setReconcile(const std::string &_value) -> void
auto getDateAsString() const -> Wt::WString
auto getDescription() const -> std::string
Set Description.
auto setSplitItem(GCW::Dbo::Splits::Item::Ptr _splitItem) -> void
auto createDescription(TxItem _txItem) const -> std::unique_ptr< Wt::WStandardItem >
auto thisSplit() const -> GCW::Dbo::Splits::Item::Ptr
auto getDate() const -> Wt::WDateTime
Set Date.
auto appendAutosplitLedger() const -> void
auto createDebit(SpItem _spItem) const -> std::unique_ptr< Wt::WStandardItem >
auto createBlank() const -> std::unique_ptr< Wt::WStandardItem >
auto setDescription(const std::string &_value) -> void
auto deleteTransaction() -> void
Delete Transaction.
auto getValue() const -> GCW_NUMERIC
auto appendTransactionJournal() const -> void
auto getNum() const -> std::string
Set Num.
GCW::Dbo::Splits::Item::Ptr SpItem
auto createNum(TxItem _txItem) const -> std::unique_ptr< Wt::WStandardItem >
std::vector< std::unique_ptr< Wt::WStandardItem > > RowItem
auto otherGuid() const -> std::string
Other GUID.
auto createAccount(SpItem _spItem) const -> std::unique_ptr< Wt::WStandardItem >
auto setNum(const std::string &_value) -> void
auto setDate(const Wt::WDateTime &_value) -> void
auto loadSplit(const std::string &_splitGuid) -> void
Set Split.
auto split(const std::string &_splitGuid) const -> GCW::Dbo::Splits::Item::Ptr
auto createDate(TxItem _txItem) const -> std::unique_ptr< Wt::WStandardItem >
auto setAction(const std::string &_value) -> void
Set Action.
auto setNotes(const std::string &_acctGuid, const std::string &_value) -> void
auto setReadOnly(bool _value) -> void
auto setValue(GCW_NUMERIC _value) -> void
auto appendGeneralJournal() const -> void
auto getValueAsString() const -> std::string
auto thatSplit() const -> GCW::Dbo::Splits::Item::Ptr
auto otherSplits() const -> GCW::Dbo::Splits::Item::Vector
auto createEmpty() const -> std::unique_ptr< Wt::WStandardItem >
auto createText(const std::string &_text) const -> std::unique_ptr< Wt::WStandardItem >
auto loadTransaction(const std::string &_transactionGuid) -> void
Set Transaction.
Account Register Model.
Definition Model.h:30
static constexpr const int User
static constexpr const int Edit
static WDateTime currentDateTime()
std::string toUTF8() const
WString & arg(const std::wstring &value)
#define TR(X)
Definition define.h:17
#define GCW_RECONCILE_NO
Definition gcwglobal.h:27
#define GCW_DEFAULT_DATE
Definition gcwglobal.h:26
#define GCW_DATE_FORMAT_DISPLAY
Definition gcwglobal.h:14
#define GCW_NUMERIC
Internal Numeric Type.
Definition gcwglobal.h:38
DECIMAL::decimal_format decimal_format()
Decimal Format Specifier.
Definition GnuCashew.cpp:21
auto newGuid() -> std::string
Generate new GUID string value.
Definition Core.cpp:235
auto load(const std::string &_guid) -> Item::Ptr
Load Account by GUID.
auto byGuid(const std::string &_guid) -> Item::Ptr
Load Account by GUID.
auto fullName(const std::string &_guid) -> std::string
Account Fullname via GUID.
@ NORMAL
normal handling - neg values are red
@ NEGVAL_EXTRA
extra handling - neg values are gold-background-full-line
auto byTransaction(const std::string &_txGuid) -> Item::Vector
Load Splits by Transaction.
Definition Splits.cpp:244
auto add(const std::string &_splitGuid) -> Item::Ptr
Add a single split.
Definition Splits.cpp:154
auto bySplitExcept(const std::string &_splitGuid) -> Item::Vector
Load Splits by Split.
Definition Splits.cpp:202
auto load(const std::string &_splitGuid) -> Item::Ptr
Load a single split.
Definition Splits.cpp:103
auto add(const std::string &_txGuid) -> Item::Ptr
auto load(const std::string &_txGuid) -> Item::Ptr
Load Transaction by Guid.
@ GENERAL_JOURNAL
multi-line ledger that shows all accounts and no balances
@ BASIC_LEDGER
basic one-line per transaction
@ AUTOSPLIT_LEDGER
one-line ledger that auto-opens to multi-line for each selected row
@ TRANSACTION_JOURNAL
multi-line ledger for every row
Definition App.h:18
App * app()
Definition App.cpp:75