1#line 2 "src/Gui/AccountRegister/Model.cpp"
5#include "../Glb/gcwglobal.h"
6#include "../Dbo/SessionGnuCash.h"
7#include "../Dbo/Splits/Splits.h"
8#include "../Dbo/Prefrences.h"
9#include "../Dbo/Vars/Vars.h"
10#include "../Glb/Core.h"
11#include "../Eng/TransactionManager.h"
16:
Wt::WStandardItemModel( 0, 8 )
37 std::cout << __FILE__ <<
":" << __LINE__ <<
" model<signal>.dataChanged()"
39 <<
"\n r1:" << _index1.
row()
40 <<
" c1:" << _index1.
column()
42 <<
"\n r2:" << _index2.
row()
43 <<
" c2:" << _index2.
column()
53 std::cout << __FILE__ <<
":" << __LINE__ <<
" model<signal>.itemChanged()"
54 <<
"\n r:" << _item-> row()
55 <<
" c:" << _item-> column()
69 m_accountGuid = _accountGuid;
78 m_viewMode = _viewMode;
87 m_doubleLine = _doubleLine;
108 if( getSplitGuid( _index ) ==
"" )
116 if(
split-> isReconciled() )
134 if( getSplitGuid( _index ) ==
"" )
173 if( !_index.isValid() )
180 if( getSplitGuid( _index ) ==
"" )
209 isReadOnly( index( _row, 0 ) );
227 index( _index.row(), column )
333 auto debit = getDebit( _index );
334 auto credit = getCredit( _index );
335 retVal = debit - credit;
368 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << __FUNCTION__ <<
"(): "
369 <<
"\n row:" << _index.row()
370 <<
"\n col:" << _index.column()
371 <<
"\n gui:" << getSplitGuid( _index )
386 auto splitGuid = getSplitGuid( _index );
387 if( splitGuid ==
"" )
393 transMan.
newTransaction( m_accountGuid, getTransferGuid( _index ) );
409 switch( _index.column() )
413 transMan.
setDate( getDate( _index ) );
419 transMan.
setAction( getAction( _index ) );
443 transMan.
setValue( getValue( _index ) );
449 transMan.
setValue( getValue( _index ) );
456 transMan.
setNotes( getNotes( _index ) );
483 auto _valuesMatch = [](
const Wt::cpp17::any & _any1,
const Wt::cpp17::any & _any2 )
488 if( _any1.type() == _any2.type() )
491 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << __FUNCTION__
494 <<
"\n " << _any1.type().name()
495 <<
"\n " << _any1.type().hash_code()
499 if(
typeid(std::string) == _any1.type() )
501 auto v1 = Wt::cpp17::any_cast< std::string >( _any1 );
502 auto v2 = Wt::cpp17::any_cast< std::string >( _any2 );
509 auto v1 = Wt::cpp17::any_cast< Wt::WString >( _any1 );
510 auto v2 = Wt::cpp17::any_cast< Wt::WString >( _any2 );
515 if(
typeid(
int) == _any1.type() )
517 auto v1 = Wt::cpp17::any_cast< int >( _any1 );
518 auto v2 = Wt::cpp17::any_cast< int >( _any2 );
525 auto v1 = Wt::cpp17::any_cast< Wt::WDate >( _any1 );
526 auto v2 = Wt::cpp17::any_cast< Wt::WDate >( _any2 );
533 auto v1 = Wt::cpp17::any_cast< Wt::WDateTime >( _any1 );
534 auto v2 = Wt::cpp17::any_cast< Wt::WDateTime >( _any2 );
540 std::cout << __FILE__ <<
":" << __LINE__
541 <<
" unhandled type " << _any1.type().name()
557 if( !_valuesMatch( _index.data( _role ), _value ) )
561 <<
"\n row:" << _index.row()
562 <<
"\n col:" << _index.column()
606 const auto start = std::chrono::system_clock::now();
616 if( m_accountGuid ==
"" )
622 layoutAboutToBeChanged().emit();
649 std::cout << __FILE__ <<
":" << __LINE__
650 <<
" guid:" << registerAccountItem-> guid()
651 <<
" name:" << registerAccountItem-> name()
652 <<
" dbcr:" <<
static_cast<int>( registerAccountItem-> accountDrCr() )
653 <<
" type:" <<
static_cast<int>( registerAccountItem-> accountType() )
654 <<
" typn:" << registerAccountItem-> accountTypeName()
676 m_splitCount = splitItems.size();
689 for(
auto splitItem : splitItems )
697 bool readOnly =
true;
743 auto post_date = _addColumn( columns,
"" );
754 appendRow( std::move( columns ) ) ;
775 if( registerAccountItem )
776 accountDef = registerAccountItem-> accountDef();
783 setHeaderData( col++,
TR(
"gcw.AccountRegister.column.date" ) );
784 setHeaderData( col++,
TR(
"gcw.AccountRegister.column.num" ) );
785 setHeaderData( col++,
TR(
"gcw.AccountRegister.column.memo" ) );
786 setHeaderData( col++,
TR(
"gcw.AccountRegister.column." + accountDef.
colAccount ) );
787 setHeaderData( col++,
TR(
"gcw.AccountRegister.column.reconcile" ) );
788 setHeaderData( col++,
TR(
"gcw.AccountRegister.column." + accountDef.
colDr ) );
789 setHeaderData( col++,
TR(
"gcw.AccountRegister.column." + accountDef.
colCr ) );
790 setHeaderData( col++,
TR(
"gcw.AccountRegister.column.balance" ) );
795 layoutChanged().emit();
800 std::cout << __FILE__ <<
":" << __LINE__
801 <<
" " << std::chrono::duration_cast< std::chrono::milliseconds >
802 ( std::chrono::system_clock::now() - start ).count()
803 <<
"mS load time for"
804 <<
" " << splitCount() <<
" items"
826 std::set< std::string > retVal;
827 for(
int row=0; row< rowCount(); row++ )
static std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
auto setTransferGuid(const std::string &_value) -> void
Set Transfer GUID.
auto newTransaction(const std::string &_accountGuid1, const std::string &_accountGuid2) -> void
New Transaction.
auto setReconcile(const std::string &_value) -> void
auto setSplitItem(GCW::Dbo::Splits::Item::Ptr _splitItem) -> void
auto transactionItem() const -> GCW::Dbo::Transactions::Item::Ptr
Transaction Item.
auto setDescription(const std::string &_value) -> void
auto setDate(const Wt::WDateTime &_value) -> void
auto loadSplit(const std::string &_splitGuid) -> void
Set Split.
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 isDeletable(const Wt::WModelIndex &_index) -> bool
Is Read Only.
auto getDate(const Wt::WModelIndex &_index) -> Wt::WDateTime
Get Date from the index.
auto setViewMode(ViewMode _viewMode) -> void
auto getValue(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get Value (positive or negative)
auto getReconcile(const Wt::WModelIndex &_index) -> std::string
Get Reconciliation.
auto isReadOnly() -> bool
auto setStyleClass(int _row, const std::string &_class) -> void
auto setAccountGuid(const std::string &_accountGuid) -> void
auto getDebit(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get Debit value.
auto getAction(const Wt::WModelIndex &_index) -> std::string
Get Action.
auto getCredit(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get Credit value.
auto getString(const Wt::WModelIndex &_index, int column) -> std::string
auto getNumeric(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get numeric value.
auto splitCount() -> int
Split Count.
auto getSplitGuid(const Wt::WModelIndex &_index) -> std::string
Get GUID from row.
auto removeStyleClass(int _row, const std::string &_class) -> void
auto refreshFromDisk() -> void
Refresh From Disk.
auto getDescription(const Wt::WModelIndex &_index) -> std::string
Get Description.
auto getTransferGuid(const Wt::WModelIndex &_index) -> std::string
Get Transfer Account GUID.
auto setDoubleLine(bool _doubleLine) -> void
auto isJumpable(const Wt::WModelIndex &_index) -> bool
Is Jumpable.
std::vector< std::unique_ptr< Wt::WStandardItem > > RowItem
auto setData(const Wt::WModelIndex &_index, const Wt::cpp17::any &_value, Wt::ItemDataRole _role) -> bool
auto saveToDisk() -> void
auto makeRow(const std::string &_splitGuid) -> RowItem
auto suggestionsFromColumn(int _column) const -> std::set< std::string >
Column Suggestions.
auto getTransferText(const Wt::WModelIndex &_index) -> std::string
Get Transfer Account Text.
static constexpr const int User
static constexpr const int Edit
static constexpr const int Display
virtual Signal< WModelIndex, WModelIndex > & dataChanged()
virtual bool setData(const WModelIndex &index, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit)
virtual cpp17::any data(const WModelIndex &index, ItemDataRole role=ItemDataRole::Display) const=0
void setTime(const WTime &time)
static WDateTime fromString(const WString &s)
static WDateTime currentDateTime()
cpp17::any data(ItemDataRole role=ItemDataRole::Display) const
Signal< WStandardItem * > & itemChanged()
std::string toUTF8() const
#define GCW_DATE_DEFAULT_TIME
Default Time.
#define GCW_DATE_FORMAT_DISPLAY
#define GCW_RECONCILE_YES
#define GCW_NUMERIC
Internal Numeric Type.
WString asString(const cpp17::any &v, const WString &formatString=WString())
const std::vector< AccountDef_t > s_accountDefs
auto byFullName(const std::string &_fullName) -> Item::Ptr
Load Account by 'full name' with ':' account separator.
auto byGuid(const std::string &_guid) -> Item::Ptr
Load Account by GUID.
auto get() -> GCW::Dbo::Prefrences::Item
auto byAccount(const std::string &_accountGuid) -> Item::Vector
Load Splits by Account.
auto byGuid(const std::string &_splitGuid) -> Item::Ptr
Load a single split.
constexpr int asInt(Col col) noexcept
std::string colAccount
a printable 'label' for the 'account' column in the registers
std::string colDr
a printable 'label' for the 'debit' column in the registers
std::string colCr
a printable 'label' for the 'credit' column in the registers