Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Riina Antikainen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit eab4f333
authored
Mar 21, 2010
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added comments to database classes
1 parent
2126e11a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
14 deletions
code/LanBortalDatabase/src/fi/insomnia/bortal/model/Bill.java
code/LanBortalDatabase/src/fi/insomnia/bortal/model/BillLine.java
code/LanBortalDatabase/src/fi/insomnia/bortal/model/CardTemplate.java
code/LanBortalDatabase/src/fi/insomnia/bortal/model/Bill.java
View file @
eab4f33
...
...
@@ -4,6 +4,7 @@
*/
package
fi
.
insomnia
.
bortal
.
model
;
import
java.math.BigDecimal
;
import
java.util.Calendar
;
import
java.util.List
;
...
...
@@ -24,8 +25,9 @@ import javax.persistence.TemporalType;
import
javax.persistence.Version
;
/**
*
*
* The system can send bills to the users.
* When user pays bill a AccountEvent row is created for product whose price is +1
* and Bills paidDate is changed to not null.
*/
@Entity
@Table
(
name
=
"bills"
)
...
...
@@ -40,40 +42,94 @@ public class Bill implements EventChildInterface {
private
static
final
long
serialVersionUID
=
1L
;
@EmbeddedId
private
EventPk
id
;
;
private
EventPk
id
;
/**
* When the bill is due to be paid.
*/
@Column
(
name
=
"due_date"
)
@Temporal
(
TemporalType
.
TIMESTAMP
)
private
Calendar
dueDate
;
/**
* When the money has appeared on the bank account.
*/
@Column
(
name
=
"paid_date"
)
@Temporal
(
TemporalType
.
TIMESTAMP
)
private
Calendar
paidDate
;
/**
* Reference number of the bill.
* @See http://www.fkl.fi/www/page/fk_www_1293
*/
@Column
(
name
=
"reference_number"
)
private
String
referenceNumber
;
/**
* Notes for the event organisators about the bill.
*/
@Lob
@Column
(
name
=
"notes"
)
private
String
notes
;
/**
* Bill may have multiple items on multiple rows.
*/
@OneToMany
(
mappedBy
=
"bill"
)
private
List
<
BillLine
>
billLines
;
/**
* When the bill is paid this AccountEvent is created and this is a reference
* to that accountAction.
*/
@JoinColumns
({
@JoinColumn
(
name
=
"account_event_id"
,
referencedColumnName
=
"entity_id"
,
nullable
=
false
,
updatable
=
false
,
insertable
=
false
),
@JoinColumn
(
name
=
"account_event_event_id"
,
referencedColumnName
=
"events_pk_id"
,
nullable
=
false
,
updatable
=
false
,
insertable
=
false
)
})
@JoinColumn
(
name
=
"account_event_id"
,
referencedColumnName
=
"entity_id"
,
updatable
=
false
,
insertable
=
false
),
@JoinColumn
(
name
=
"account_event_event_id"
,
referencedColumnName
=
"events_pk_id"
,
updatable
=
false
,
insertable
=
false
)
})
@OneToOne
private
AccountEvent
accountEvent
;
/**
* User who should pay this bill.
*/
@JoinColumn
(
name
=
"users_id"
,
referencedColumnName
=
"users_id"
,
nullable
=
false
)
@ManyToOne
(
optional
=
false
)
private
User
user
;
/**
* Which event the bill is assigned to.
*/
@ManyToOne
@JoinColumn
(
name
=
"events_id"
,
referencedColumnName
=
"events_id"
)
private
Event
event
;
/**
* Commodity function to calculate the total price of the bill.
* @return The total sum of the bill ( unitPrice * units * vat )
*/
public
BigDecimal
totalPrice
()
{
BigDecimal
total
=
BigDecimal
.
ZERO
;
for
(
BillLine
line:
getBillLines
())
{
total
=
total
.
add
(
line
.
getLinePrice
());
}
return
total
;
}
/**
* Commodity function to return the vatless price of the bill
* @return The total VAT-less sum of the bill ( unitPrice * units )
*/
public
BigDecimal
totalPriceVatless
()
{
BigDecimal
total
=
BigDecimal
.
ZERO
;
for
(
BillLine
line:
getBillLines
())
{
total
=
total
.
add
(
line
.
getLinePriceVatless
());
}
return
total
;
}
@Override
public
EventPk
getId
()
{
return
id
;
...
...
code/LanBortalDatabase/src/fi/insomnia/bortal/model/BillLine.java
View file @
eab4f33
...
...
@@ -23,35 +23,50 @@ import javax.persistence.Version;
*/
@Entity
@Table
(
name
=
"bill_lines"
)
@NamedQueries
(
{
@NamedQueries
({
@NamedQuery
(
name
=
"BillLine.findAll"
,
query
=
"SELECT b FROM BillLine b"
),
@NamedQuery
(
name
=
"BillLine.findByProduct"
,
query
=
"SELECT b FROM BillLine b WHERE b.name = :name"
),
@NamedQuery
(
name
=
"BillLine.findByUnits"
,
query
=
"SELECT b FROM BillLine b WHERE b.units = :units"
),
@NamedQuery
(
name
=
"BillLine.findByUnitPrice"
,
query
=
"SELECT b FROM BillLine b WHERE b.unitPrice = :unitPrice"
),
@NamedQuery
(
name
=
"BillLine.findByVat"
,
query
=
"SELECT b FROM BillLine b WHERE b.vat = :vat"
)
})
public
class
BillLine
implements
EventChildInterface
{
public
class
BillLine
implements
EventChildInterface
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
BigDecimal
DEFAULT_VAT
=
BigDecimal
.
ZERO
;
@EmbeddedId
private
EventPk
id
;
/**
* Product name shown on the bill
*/
@Column
(
name
=
"name"
,
nullable
=
false
)
private
String
name
;
/**
* How many units the of the product has been purchased eg. 14 (Entrance
* tickets), 1.5 (l) eh.. something..
*/
@Column
(
name
=
"units"
,
nullable
=
false
,
precision
=
24
,
scale
=
4
)
private
BigDecimal
units
;
private
BigDecimal
units
=
BigDecimal
.
ZERO
;
/**
* How much one(1) unit of this product costs
*
*/
@Column
(
name
=
"unit_price"
,
nullable
=
false
,
precision
=
24
,
scale
=
4
)
private
BigDecimal
unitPrice
;
private
BigDecimal
unitPrice
=
BigDecimal
.
ZERO
;
/**
* How much VAT this product contains ( 0, 0.22 ) etc
*/
@Column
(
name
=
"vat"
,
nullable
=
false
,
precision
=
3
,
scale
=
2
)
private
BigDecimal
vat
=
DEFAULT_VAT
;
/**
* Which bill this bill line belongs to
*/
@JoinColumns
({
@JoinColumn
(
name
=
"bills_id"
,
referencedColumnName
=
"entity_id"
,
nullable
=
false
,
updatable
=
false
,
insertable
=
false
),
@JoinColumn
(
name
=
"bills_event_id"
,
referencedColumnName
=
"events_pk_id"
,
nullable
=
false
,
updatable
=
false
,
insertable
=
false
)
})
@JoinColumn
(
name
=
"bills_event_id"
,
referencedColumnName
=
"events_pk_id"
,
nullable
=
false
,
updatable
=
false
,
insertable
=
false
)
})
@ManyToOne
private
Bill
bill
;
...
...
@@ -59,6 +74,25 @@ public class BillLine implements EventChildInterface{
@Column
(
nullable
=
false
)
private
int
jpaVersionField
;
/**
* Calculate the total price for the items on this line
* @return
*/
public
BigDecimal
getLinePrice
()
{
BigDecimal
vatMultiplicand
=
BigDecimal
.
ONE
.
add
(
getVat
());
return
getLinePriceVatless
().
multiply
(
vatMultiplicand
);
}
/**
* Calculate the total VAT-less price for the items on this lin
* @return
*/
public
BigDecimal
getLinePriceVatless
()
{
return
getUnitPrice
().
multiply
(
getUnits
());
}
public
BillLine
()
{
}
...
...
@@ -75,6 +109,8 @@ public class BillLine implements EventChildInterface{
this
.
setVat
(
vat
);
}
public
String
getName
()
{
return
name
;
}
...
...
code/LanBortalDatabase/src/fi/insomnia/bortal/model/CardTemplate.java
View file @
eab4f33
...
...
@@ -20,13 +20,12 @@ import javax.persistence.Table;
import
javax.persistence.Version
;
/**
*
*
ID-card templates for the event.
*/
@Entity
@Table
(
name
=
"card_templates"
)
@NamedQueries
(
{
@NamedQuery
(
name
=
"CardTemplate.findAll"
,
query
=
"SELECT c FROM CardTemplate c"
),
@NamedQuery
(
name
=
"CardTemplate.findByName"
,
query
=
"SELECT c FROM CardTemplate c WHERE c.name = :name"
)
})
public
class
CardTemplate
implements
EventChildInterface
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment