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 df16c9aa
authored
Feb 15, 2014
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
discount by role
1 parent
bb1a5f46
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
52 additions
and
20 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/ProductBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/ProductPBean.java
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/ProductBeanLocal.java
code/MoyaDatabase/src/fi/codecrew/moya/model/Bill.java
code/MoyaDatabase/src/fi/codecrew/moya/model/Product.java
code/MoyaWeb/WebContent/resources/cditools/products/manageDiscount.xhtml
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/shop/FoodWaveFoodView.java
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/shop/ProductShopView.java
code/MoyaWeb/src/fi/codecrew/moya/web/helpers/ProductShopItem.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
View file @
df16c9a
...
@@ -151,7 +151,7 @@ public class PlaceBean implements PlaceBeanLocal {
...
@@ -151,7 +151,7 @@ public class PlaceBean implements PlaceBeanLocal {
for
(
Entry
<
Product
,
Integer
>
entry
:
mockmap
.
entrySet
())
{
for
(
Entry
<
Product
,
Integer
>
entry
:
mockmap
.
entrySet
())
{
logger
.
debug
(
"Adding to price {} of {}"
,
entry
.
getValue
(),
entry
.
getKey
().
getName
());
logger
.
debug
(
"Adding to price {} of {}"
,
entry
.
getValue
(),
entry
.
getKey
().
getName
());
if
(
entry
.
getKey
()
!=
null
)
{
if
(
entry
.
getKey
()
!=
null
)
{
total
=
total
.
add
(
productBean
.
calculateTotal
(
entry
.
getKey
(),
new
BigDecimal
(
entry
.
getValue
()),
now
));
total
=
total
.
add
(
productBean
.
calculateTotal
(
entry
.
getKey
(),
new
BigDecimal
(
entry
.
getValue
()),
now
,
user
));
}
}
}
}
return
total
;
return
total
;
...
...
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/ProductBean.java
View file @
df16c9a
...
@@ -285,12 +285,12 @@ public class ProductBean implements ProductBeanLocal {
...
@@ -285,12 +285,12 @@ public class ProductBean implements ProductBeanLocal {
}
}
@Override
@Override
public
BigDecimal
calculateTotal
(
Product
product
,
BigDecimal
quantity
,
Calendar
date
)
{
public
BigDecimal
calculateTotal
(
Product
product
,
BigDecimal
quantity
,
Calendar
date
,
EventUser
user
)
{
if
(
product
==
null
||
quantity
==
null
)
{
if
(
product
==
null
||
quantity
==
null
)
{
throw
new
RuntimeException
(
"Some parameter is null!"
);
throw
new
RuntimeException
(
"Some parameter is null!"
);
}
}
BigDecimal
total
=
product
.
getPrice
();
BigDecimal
total
=
product
.
getPrice
();
for
(
Discount
d
:
product
.
getActiveDiscounts
(
quantity
,
date
))
{
for
(
Discount
d
:
product
.
getActiveDiscounts
(
quantity
,
date
,
user
))
{
total
=
total
.
multiply
(
d
.
getPercentage
());
total
=
total
.
multiply
(
d
.
getPercentage
());
}
}
return
total
.
setScale
(
2
,
RoundingMode
.
HALF_UP
).
multiply
(
quantity
);
return
total
.
setScale
(
2
,
RoundingMode
.
HALF_UP
).
multiply
(
quantity
);
...
...
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/ProductPBean.java
View file @
df16c9a
...
@@ -73,7 +73,7 @@ public class ProductPBean {
...
@@ -73,7 +73,7 @@ public class ProductPBean {
}
}
BigDecimal
unitPrice
=
product
.
getPrice
().
negate
();
BigDecimal
unitPrice
=
product
.
getPrice
().
negate
();
List
<
Discount
>
discounts
=
product
.
getActiveDiscounts
(
quantity
,
date
);
List
<
Discount
>
discounts
=
product
.
getActiveDiscounts
(
quantity
,
date
,
user
);
for
(
Discount
d
:
discounts
)
{
for
(
Discount
d
:
discounts
)
{
unitPrice
=
unitPrice
.
multiply
(
d
.
getPercentage
());
unitPrice
=
unitPrice
.
multiply
(
d
.
getPercentage
());
}
}
...
...
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/ProductBeanLocal.java
View file @
df16c9a
...
@@ -47,7 +47,7 @@ public interface ProductBeanLocal {
...
@@ -47,7 +47,7 @@ public interface ProductBeanLocal {
Discount
save
(
Discount
discount
);
Discount
save
(
Discount
discount
);
BigDecimal
calculateTotal
(
Product
product
,
BigDecimal
quantity
,
Calendar
date
);
BigDecimal
calculateTotal
(
Product
product
,
BigDecimal
quantity
,
Calendar
date
,
EventUser
user
);
HashMap
<
Integer
,
BigDecimal
>
getProductLimit
(
Map
<
Integer
,
BigDecimal
>
prodCounts
,
EventUser
user
);
HashMap
<
Integer
,
BigDecimal
>
getProductLimit
(
Map
<
Integer
,
BigDecimal
>
prodCounts
,
EventUser
user
);
...
...
code/MoyaDatabase/src/fi/codecrew/moya/model/Bill.java
View file @
df16c9a
...
@@ -364,7 +364,7 @@ public class Bill extends GenericEntity {
...
@@ -364,7 +364,7 @@ public class Bill extends GenericEntity {
}
}
this
.
getBillLines
().
add
(
new
BillLine
(
this
,
product
,
count
,
foodwave
));
this
.
getBillLines
().
add
(
new
BillLine
(
this
,
product
,
count
,
foodwave
));
for
(
Discount
disc
:
product
.
getActiveDiscounts
(
count
,
sentDate
))
{
for
(
Discount
disc
:
product
.
getActiveDiscounts
(
count
,
sentDate
,
this
.
getUser
()
))
{
this
.
getBillLines
().
add
(
new
BillLine
(
this
,
product
,
disc
,
count
));
this
.
getBillLines
().
add
(
new
BillLine
(
this
,
product
,
disc
,
count
));
}
}
}
}
...
...
code/MoyaDatabase/src/fi/codecrew/moya/model/Product.java
View file @
df16c9a
...
@@ -163,15 +163,28 @@ public class Product extends GenericEntity {
...
@@ -163,15 +163,28 @@ public class Product extends GenericEntity {
}
}
// TODO: alennukset lasketaan täällä. HUOMHUOM!!
// TODO: alennukset lasketaan täällä. HUOMHUOM!!
public
List
<
Discount
>
getActiveDiscounts
(
BigDecimal
quantity
,
Calendar
time
)
{
// Oikea paikka ois joku kaunis bean, mutta ehkä enskerralla voin
// refactoroida
// tai si sitäseuraavalla -TKjne
public
List
<
Discount
>
getActiveDiscounts
(
BigDecimal
quantity
,
Calendar
time
,
EventUser
user
)
{
ArrayList
<
Discount
>
ret
=
new
ArrayList
<
Discount
>();
ArrayList
<
Discount
>
ret
=
new
ArrayList
<
Discount
>();
for
(
Discount
d
:
getDiscounts
())
{
for
(
Discount
d
:
getDiscounts
())
{
if
(
d
.
isActive
()
&&
if
(
d
.
isActive
()
&&
(
d
.
getValidTo
()
==
null
||
d
.
getValidTo
().
after
(
time
))
&&
(
d
.
getValidTo
()
==
null
||
d
.
getValidTo
().
after
(
time
))
&&
(
d
.
getValidFrom
()
==
null
||
d
.
getValidFrom
().
before
(
time
))
&&
(
d
.
getValidFrom
()
==
null
||
d
.
getValidFrom
().
before
(
time
))
&&
quantity
.
compareTo
(
d
.
getAmountMax
())
<=
0
&&
(
d
.
getAmountMax
().
compareTo
(
BigDecimal
.
ZERO
)
==
0
||
quantity
.
compareTo
(
d
.
getAmountMax
())
<=
0
)
&&
quantity
.
compareTo
(
d
.
getAmountMin
())
>=
0
)
{
(
d
.
getAmountMin
().
compareTo
(
BigDecimal
.
ZERO
)
==
0
||
quantity
.
compareTo
(
d
.
getAmountMin
())
>=
0
))
{
ret
.
add
(
d
);
// plaah, there is role, must do magic
if
(
d
.
getRole
()
!=
null
)
{
for
(
Role
role
:
user
.
getRoles
())
{
if
(
d
.
getRole
().
equals
(
role
))
{
ret
.
add
(
d
);
}
}
}
else
{
ret
.
add
(
d
);
}
}
}
}
}
return
ret
;
return
ret
;
...
...
code/MoyaWeb/WebContent/resources/cditools/products/manageDiscount.xhtml
View file @
df16c9a
...
@@ -31,6 +31,12 @@
...
@@ -31,6 +31,12 @@
<h:inputText
id=
"code"
value=
"#{productView.discount.code}"
/>
<h:inputText
id=
"code"
value=
"#{productView.discount.code}"
/>
<h:message
for=
"code"
/>
<h:message
for=
"code"
/>
<h:outputLabel
for=
"role"
value=
"#{i18n['discount.role']}:"
/>
<h:selectOneMenu
id=
"role"
value=
"#{productView.discount.role}"
converter=
"#{roleConverter}"
>
<f:selectItems
var=
"role"
itemLabel=
"#{role.name}"
value=
"#{roleDataView.rolesWithEmpty}"
/>
</h:selectOneMenu>
<h:message
for=
"role"
/>
<h:outputLabel
for=
"amountMin"
value=
"#{i18n['discount.amountMin']}:"
/>
<h:outputLabel
for=
"amountMin"
value=
"#{i18n['discount.amountMin']}:"
/>
<h:inputText
id=
"amountMin"
value=
"#{productView.discount.amountMin}"
required=
"true"
/>
<h:inputText
id=
"amountMin"
value=
"#{productView.discount.amountMin}"
required=
"true"
/>
<h:message
for=
"amountMin"
/>
<h:message
for=
"amountMin"
/>
...
@@ -54,6 +60,8 @@
...
@@ -54,6 +60,8 @@
<h:outputLabel
for=
"active"
value=
"#{i18n['discount.active']}"
/>
<h:outputLabel
for=
"active"
value=
"#{i18n['discount.active']}"
/>
<h:selectBooleanCheckbox
id=
"active"
value=
"#{productView.discount.active}"
/>
<h:selectBooleanCheckbox
id=
"active"
value=
"#{productView.discount.active}"
/>
<h:message
for=
"active"
/>
<h:message
for=
"active"
/>
</h:panelGrid>
</h:panelGrid>
...
...
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/shop/FoodWaveFoodView.java
View file @
df16c9a
...
@@ -66,7 +66,7 @@ public class FoodWaveFoodView extends GenericCDIView {
...
@@ -66,7 +66,7 @@ public class FoodWaveFoodView extends GenericCDIView {
foodWave
=
foodWaveBean
.
findFoodwave
(
getFoodwaveid
());
foodWave
=
foodWaveBean
.
findFoodwave
(
getFoodwaveid
());
logger
.
debug
(
"Foodwave {}"
,
foodWave
);
logger
.
debug
(
"Foodwave {}"
,
foodWave
);
shoppingcart
=
new
ListDataModel
<
ProductShopItem
>(
ProductShopItem
.
productGTList
(
foodWave
.
getTemplate
().
getProducts
()));
shoppingcart
=
new
ListDataModel
<
ProductShopItem
>(
ProductShopItem
.
productGTList
(
foodWave
.
getTemplate
().
getProducts
()
,
userview
.
getUser
()
));
this
.
beginConversation
();
this
.
beginConversation
();
}
}
...
...
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/shop/ProductShopView.java
View file @
df16c9a
...
@@ -94,7 +94,7 @@ public class ProductShopView extends GenericCDIView {
...
@@ -94,7 +94,7 @@ public class ProductShopView extends GenericCDIView {
public
void
initBillView
()
{
public
void
initBillView
()
{
if
(
requirePermissions
(
ShopPermission
.
LIST_USERPRODUCTS
)
if
(
requirePermissions
(
ShopPermission
.
LIST_USERPRODUCTS
)
&&
shoppingcart
==
null
)
{
&&
shoppingcart
==
null
)
{
shoppingcart
=
new
ListDataModel
<
ProductShopItem
>(
ProductShopItem
.
productList
(
productBean
.
listUserShoppableProducts
()));
shoppingcart
=
new
ListDataModel
<
ProductShopItem
>(
ProductShopItem
.
productList
(
productBean
.
listUserShoppableProducts
()
,
user
));
updateCartLimits
(
null
);
updateCartLimits
(
null
);
logger
.
debug
(
"Initialized billing shoppingcart to {}"
,
shoppingcart
);
logger
.
debug
(
"Initialized billing shoppingcart to {}"
,
shoppingcart
);
this
.
beginConversation
();
this
.
beginConversation
();
...
@@ -137,7 +137,7 @@ public class ProductShopView extends GenericCDIView {
...
@@ -137,7 +137,7 @@ public class ProductShopView extends GenericCDIView {
public
void
initShopView
()
{
public
void
initShopView
()
{
if
(
requirePermissions
(
ShopPermission
.
SHOP_TO_OTHERS
)
&&
shoppingcart
==
null
)
{
if
(
requirePermissions
(
ShopPermission
.
SHOP_TO_OTHERS
)
&&
shoppingcart
==
null
)
{
shoppingcart
=
new
ListDataModel
<
ProductShopItem
>(
ProductShopItem
.
productGTList
(
productBean
.
findForStaffshop
()));
shoppingcart
=
new
ListDataModel
<
ProductShopItem
>(
ProductShopItem
.
productGTList
(
productBean
.
findForStaffshop
()
,
user
));
updateCartLimits
(
null
);
updateCartLimits
(
null
);
LanEventProperty
cashdefault
=
eventbean
.
getProperty
(
LanEventPropertyKey
.
SHOP_DEFAULT_CASH
);
LanEventProperty
cashdefault
=
eventbean
.
getProperty
(
LanEventPropertyKey
.
SHOP_DEFAULT_CASH
);
...
...
code/MoyaWeb/src/fi/codecrew/moya/web/helpers/ProductShopItem.java
View file @
df16c9a
...
@@ -11,6 +11,7 @@ import org.slf4j.Logger;
...
@@ -11,6 +11,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
fi.codecrew.moya.model.Discount
;
import
fi.codecrew.moya.model.Discount
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.Product
;
import
fi.codecrew.moya.model.Product
;
public
class
ProductShopItem
{
public
class
ProductShopItem
{
...
@@ -23,6 +24,8 @@ public class ProductShopItem {
...
@@ -23,6 +24,8 @@ public class ProductShopItem {
private
Map
<
Integer
,
BigDecimal
>
discountValues
;
private
Map
<
Integer
,
BigDecimal
>
discountValues
;
private
BigDecimal
price
;
private
BigDecimal
price
;
private
BigDecimal
limit
;
private
BigDecimal
limit
;
private
EventUser
user
;
public
BigDecimal
getCreditPrice
()
public
BigDecimal
getCreditPrice
()
{
{
...
@@ -42,12 +45,12 @@ public class ProductShopItem {
...
@@ -42,12 +45,12 @@ public class ProductShopItem {
return
BigDecimal
.
ZERO
;
return
BigDecimal
.
ZERO
;
}
}
public
ProductShopItem
(
Product
prod
)
{
public
ProductShopItem
(
Product
prod
,
EventUser
user
)
{
super
();
super
();
this
.
user
=
user
;
this
.
product
=
prod
;
this
.
product
=
prod
;
id
=
this
.
product
.
getId
();
id
=
this
.
product
.
getId
();
setCount
(
BigDecimal
.
ZERO
);
setCount
(
BigDecimal
.
ZERO
);
}
}
/**
/**
...
@@ -56,21 +59,21 @@ public class ProductShopItem {
...
@@ -56,21 +59,21 @@ public class ProductShopItem {
* @param findForStaffshop
* @param findForStaffshop
* @return
* @return
*/
*/
public
static
List
<
ProductShopItem
>
productGTList
(
List
<
Product
>
products
)
{
public
static
List
<
ProductShopItem
>
productGTList
(
List
<
Product
>
products
,
EventUser
user
)
{
List
<
ProductShopItem
>
ret
=
new
ArrayList
<
ProductShopItem
>();
List
<
ProductShopItem
>
ret
=
new
ArrayList
<
ProductShopItem
>();
for
(
Product
prod
:
products
)
{
for
(
Product
prod
:
products
)
{
if
(
prod
.
getPrice
().
compareTo
(
BigDecimal
.
ZERO
)
>=
0
)
{
if
(
prod
.
getPrice
().
compareTo
(
BigDecimal
.
ZERO
)
>=
0
)
{
ret
.
add
(
new
ProductShopItem
(
prod
));
ret
.
add
(
new
ProductShopItem
(
prod
,
user
));
}
}
}
}
return
ret
;
return
ret
;
}
}
public
static
List
<
ProductShopItem
>
productList
(
List
<
Product
>
products
)
{
public
static
List
<
ProductShopItem
>
productList
(
List
<
Product
>
products
,
EventUser
user
)
{
List
<
ProductShopItem
>
ret
=
new
ArrayList
<
ProductShopItem
>();
List
<
ProductShopItem
>
ret
=
new
ArrayList
<
ProductShopItem
>();
for
(
Product
prod
:
products
)
{
for
(
Product
prod
:
products
)
{
ret
.
add
(
new
ProductShopItem
(
prod
));
ret
.
add
(
new
ProductShopItem
(
prod
,
user
));
}
}
return
ret
;
return
ret
;
...
@@ -89,7 +92,7 @@ public class ProductShopItem {
...
@@ -89,7 +92,7 @@ public class ProductShopItem {
this
.
count
=
count
;
this
.
count
=
count
;
price
=
product
.
getPrice
().
abs
().
multiply
(
count
);
price
=
product
.
getPrice
().
abs
().
multiply
(
count
);
discounts
=
product
.
getActiveDiscounts
(
count
,
Calendar
.
getInstance
());
discounts
=
product
.
getActiveDiscounts
(
count
,
Calendar
.
getInstance
()
,
user
);
discountValues
=
new
HashMap
<
Integer
,
BigDecimal
>();
discountValues
=
new
HashMap
<
Integer
,
BigDecimal
>();
for
(
Discount
d
:
discounts
)
for
(
Discount
d
:
discounts
)
{
{
...
@@ -153,4 +156,12 @@ public class ProductShopItem {
...
@@ -153,4 +156,12 @@ public class ProductShopItem {
limit
=
limitValue
;
limit
=
limitValue
;
return
false
;
return
false
;
}
}
public
EventUser
getUser
()
{
return
user
;
}
public
void
setUser
(
EventUser
user
)
{
this
.
user
=
user
;
}
}
}
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