FreeDebks
1.0.3
Main Page
Related Pages
Classes
Files
File List
All
Classes
Files
Functions
Variables
Friends
Pages
src
data
FdItemJournal.cpp
Go to the documentation of this file.
1
// --------------------------------------------------------------------
2
// Copyright © 2011-2013 Mathieu Schopfer
3
//
4
// This file is part of FreeDebks.
5
//
6
// FreeDebks is free software: you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation, either version 3 of the License, or
9
// (at your option) any later version.
10
//
11
// FreeDebks is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
15
//
16
// You should have received a copy of the GNU General Public License
17
// along with FreeDebks. If not, see <http://www.gnu.org/licenses/>.
18
// --------------------------------------------------------------------
19
20
#include "FdItemJournal.hpp"
21
#include "FdItemCoa.hpp"
22
#include "FdModelCoa.hpp"
23
#include "../gui/FdSubWindow.hpp"
24
25
FdItemJournal::FdItemJournal
(QDate date, QString
object
, QString label, FdItemCoa_p debit, FdItemCoa_p credit,
double
amount) :
26
mDate(date), mObject(object), mLabel(label), mDebit(debit), mCredit(credit), mAmount(amount)
27
{
28
}
29
33
FdItemJournal_p
FdItemJournal::pointer
(
FdSubWindow
*subwindow, QDomElement &entry)
34
{
35
return
FdItemJournal_p(
new
FdItemJournal
(QDate().fromString(entry.attribute(
"Date"
),
"yyyy.MM.dd"
),
36
entry.attribute(
"Object"
),
37
entry.attribute(
"Label"
),
38
subwindow->
coa
()->
itemById
(entry.attribute(
"Debit"
)),
39
subwindow->
coa
()->
itemById
(entry.attribute(
"Credit"
)),
40
entry.attribute(
"Amount"
).toDouble()));
41
}
42
43
QDate
FdItemJournal::date
()
const
44
{
45
return
mDate
;
46
}
47
48
QString
FdItemJournal::object
()
const
49
{
50
return
mObject
;
51
}
52
53
QString
FdItemJournal::label
()
const
54
{
55
return
mLabel
;
56
}
57
58
FdItemCoa_p
FdItemJournal::debit
()
const
59
{
60
return
mDebit
;
61
}
62
63
FdItemCoa_p
FdItemJournal::credit
()
const
64
{
65
return
mCredit
;
66
}
67
68
double
FdItemJournal::amount
()
const
69
{
70
return
mAmount
;
71
}
72
73
void
FdItemJournal::setDate
(QDate date)
74
{
75
mDate
=
date
;
76
}
77
78
void
FdItemJournal::setObject
(QString
object
)
79
{
80
mObject
=
object
;
81
}
82
83
void
FdItemJournal::setLabel
(QString label)
84
{
85
mLabel
=
label
;
86
}
87
88
void
FdItemJournal::setDebit
(FdItemCoa_p account)
89
{
90
mDebit
= account;
91
}
92
93
void
FdItemJournal::setCredit
(FdItemCoa_p account)
94
{
95
mCredit
= account;
96
}
97
98
void
FdItemJournal::setAmount
(
double
amount)
99
{
100
mAmount
=
amount
;
101
}
102
103
107
bool
FdItemJournal::isEmpty
()
const
108
{
109
if
(
mLabel
==
""
&&
mDebit
.isNull() &&
mCredit
.isNull() &&
mAmount
== 0)
110
return
true
;
111
112
return
false
;
113
}
114
118
bool
FdItemJournal::isValid
()
const
119
{
120
if
(
mAmount
!= 0 && (
mDebit
.isNull() ||
mCredit
.isNull()))
121
return
false
;
122
123
return
true
;
124
}
125
129
bool
FdItemJournal::breakDown
()
const
130
{
131
if
(!
isValid
())
132
return
false
;
133
if
(
mAmount
)
134
{
135
mDebit
->debited(
mAmount
);
136
mCredit
->credited(
mAmount
);
137
}
138
return
true
;
139
}
140
141
QDomElement
FdItemJournal::toXml
(QDomDocument &document)
const
142
{
143
QDomElement entry = document.createElement(
"Entry"
);
144
entry.setAttribute(
"Date"
,
mDate
.toString(
"yyyy.MM.dd"
));
145
entry.setAttribute(
"Object"
,
mObject
);
146
entry.setAttribute(
"Label"
,
mLabel
);
147
if
(!
mDebit
.isNull())
148
entry.setAttribute(
"Debit"
,
mDebit
->id());
149
if
(!
mCredit
.isNull())
150
entry.setAttribute(
"Credit"
,
mCredit
->id());
151
entry.setAttribute(
"Amount"
, QString::number(
mAmount
,
'f'
, 2));
152
153
return
entry;
154
}
Generated on Sat Aug 24 2013 21:18:03 for FreeDebks by
1.8.1.2