Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Antti Väyrynen
/
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 48abfe98
authored
Apr 12, 2014
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add possibility to enter product count as a number in user shop.
1 parent
fe44ba6d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
50 deletions
code/MoyaWeb/WebContent/resources/cditools/products/shop.xhtml
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/shop/ProductShopView.java
code/MoyaWeb/src/fi/codecrew/moya/web/helper/ProductShopItemHelper.java
code/MoyaWeb/src/fi/codecrew/moya/web/helpers/ProductShopItem.java
code/MoyaWeb/WebContent/resources/cditools/products/shop.xhtml
View file @
48abfe9
...
@@ -40,13 +40,13 @@
...
@@ -40,13 +40,13 @@
<h:commandButton
action=
"#{productShopView.addMinusOne}"
value=
"#{i18n['productshop.minusOne']}"
>
<h:commandButton
action=
"#{productShopView.addMinusOne}"
value=
"#{i18n['productshop.minusOne']}"
>
<f:ajax
render=
"@form"
/>
<f:ajax
render=
"@form"
/>
</h:commandButton>
</h:commandButton>
<h:outputText
id=
"cartcount"
escape=
"false"
value=
" #{cart.count} "
>
<p:inputText
size=
"2"
id=
"cartcount"
escape=
"false"
value=
"#{cart.count}"
>
<f:ajax
render=
"@form"
listener=
"#{productShopView.countChangeListener}"
/>
<f:convertNumber
maxIntegerDigits=
"2"
minFractionDigits=
"0"
/>
<f:convertNumber
maxIntegerDigits=
"2"
minFractionDigits=
"0"
/>
</
h:out
putText>
</
p:in
putText>
<h:commandButton
action=
"#{productShopView.addOne}"
value=
"#{i18n['productshop.plusOne']}"
>
<h:commandButton
action=
"#{productShopView.addOne}"
value=
"#{i18n['productshop.plusOne']}"
>
<f:ajax
render=
"@form"
/>
<f:ajax
render=
"@form"
/>
</h:commandButton>
</h:commandButton>
</p:column>
</p:column>
<p:column
rendered=
"#{productShopView.hasLimits}"
>
<p:column
rendered=
"#{productShopView.hasLimits}"
>
<f:facet
name=
"header"
>
<f:facet
name=
"header"
>
...
@@ -57,7 +57,7 @@
...
@@ -57,7 +57,7 @@
</h:outputText>
</h:outputText>
</p:column>
</p:column>
<p:column>
<p:column>
<h:dataTable
border=
"0"
var=
"disc"
value=
"#{cart.discounts}"
>
<h:dataTable
styleClass=
"noborderTable"
border=
"0"
var=
"disc"
value=
"#{cart.discounts}"
>
<p:column>
<p:column>
<h:outputText
value=
"#{disc.shortdesc}"
/>
<h:outputText
value=
"#{disc.shortdesc}"
/>
</p:column>
</p:column>
...
...
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/shop/ProductShopView.java
View file @
48abfe9
...
@@ -9,6 +9,7 @@ import java.util.Map;
...
@@ -9,6 +9,7 @@ import java.util.Map;
import
javax.ejb.EJB
;
import
javax.ejb.EJB
;
import
javax.enterprise.context.ConversationScoped
;
import
javax.enterprise.context.ConversationScoped
;
import
javax.faces.event.AjaxBehaviorEvent
;
import
javax.faces.model.ListDataModel
;
import
javax.faces.model.ListDataModel
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
javax.inject.Named
;
import
javax.inject.Named
;
...
@@ -54,8 +55,6 @@ public class ProductShopView extends GenericCDIView {
...
@@ -54,8 +55,6 @@ public class ProductShopView extends GenericCDIView {
@EJB
@EJB
private
transient
EventBeanLocal
eventbean
;
private
transient
EventBeanLocal
eventbean
;
public
void
cashChanged
()
public
void
cashChanged
()
{
{
payInstant
=
false
;
payInstant
=
false
;
...
@@ -81,10 +80,10 @@ public class ProductShopView extends GenericCDIView {
...
@@ -81,10 +80,10 @@ public class ProductShopView extends GenericCDIView {
@Inject
@Inject
private
BillEditView
billEditView
;
private
BillEditView
billEditView
;
@Inject
@Inject
private
ProductShopItemHelper
psiHelper
;
private
ProductShopItemHelper
psiHelper
;
public
ProductShopItemHelper
getPsiHelper
()
{
public
ProductShopItemHelper
getPsiHelper
()
{
return
psiHelper
;
return
psiHelper
;
}
}
...
@@ -164,9 +163,17 @@ public class ProductShopView extends GenericCDIView {
...
@@ -164,9 +163,17 @@ public class ProductShopView extends GenericCDIView {
}
}
}
}
public
void
countChangeListener
(
AjaxBehaviorEvent
e
)
{
ProductShopItem
item
=
shoppingcart
.
getRowData
();
logger
.
info
(
"Count change from event {}, src {}, from item {}"
,
e
,
e
.
getSource
(),
item
.
getCount
());
psiHelper
.
setProductShopItemCount
(
item
,
item
.
getCount
());
updateCartLimits
(
item
);
}
public
String
add
(
Integer
count
)
{
public
String
add
(
Integer
count
)
{
ProductShopItem
item
=
shoppingcart
.
getRowData
();
ProductShopItem
item
=
shoppingcart
.
getRowData
();
psiHelper
.
setProductShopItemCount
(
item
,
item
.
getCount
().
add
(
BigDecimal
.
valueOf
(
count
)));
psiHelper
.
setProductShopItemCount
(
item
,
item
.
getCount
().
add
(
BigDecimal
.
valueOf
(
count
)));
updateCartLimits
(
item
);
updateCartLimits
(
item
);
...
@@ -223,15 +230,15 @@ public class ProductShopView extends GenericCDIView {
...
@@ -223,15 +230,15 @@ public class ProductShopView extends GenericCDIView {
if
(
l
!=
null
)
{
if
(
l
!=
null
)
{
hasLimits
=
true
;
hasLimits
=
true
;
}
}
psiHelper
.
updateProductShopItemLimit
(
n
,
l
);
psiHelper
.
updateProductShopItemLimit
(
n
,
l
);
}
}
}
}
public
String
removeBought
()
{
public
String
removeBought
()
{
ProductShopItem
row
=
boughtItems
.
getRowData
();
ProductShopItem
row
=
boughtItems
.
getRowData
();
psiHelper
.
setProductShopItemCount
(
row
,
row
.
getCount
().
subtract
(
BigDecimal
.
ONE
));
psiHelper
.
setProductShopItemCount
(
row
,
row
.
getCount
().
subtract
(
BigDecimal
.
ONE
));
updateCartLimits
(
row
);
updateCartLimits
(
row
);
return
null
;
return
null
;
...
@@ -428,8 +435,8 @@ public class ProductShopView extends GenericCDIView {
...
@@ -428,8 +435,8 @@ public class ProductShopView extends GenericCDIView {
public
String
readCode
()
{
public
String
readCode
()
{
ReaderEvent
event
=
readerView
.
getReaderEvent
();
ReaderEvent
event
=
readerView
.
getReaderEvent
();
if
(
event
==
null
)
{
if
(
event
==
null
)
{
return
null
;
return
null
;
}
}
...
...
code/MoyaWeb/src/fi/codecrew/moya/web/helper/ProductShopItemHelper.java
View file @
48abfe9
...
@@ -17,49 +17,44 @@ import fi.codecrew.moya.web.helpers.ProductShopItem;
...
@@ -17,49 +17,44 @@ import fi.codecrew.moya.web.helpers.ProductShopItem;
@ConversationScoped
@ConversationScoped
public
class
ProductShopItemHelper
extends
GenericCDIView
{
public
class
ProductShopItemHelper
extends
GenericCDIView
{
/**
/**
*
*
*/
*/
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
@EJB
@EJB
private
DiscountBeanLocal
discountBean
;
private
DiscountBeanLocal
discountBean
;
public
void
setProductShopItemCount
(
ProductShopItem
item
,
BigDecimal
count
)
{
public
void
setProductShopItemCount
(
ProductShopItem
item
,
BigDecimal
count
)
{
if
(
count
==
null
||
count
.
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
{
if
(
count
==
null
||
count
.
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
count
=
BigDecimal
.
ZERO
;
{
}
count
=
BigDecimal
.
ZERO
;
item
.
setCount
(
count
);
}
item
.
setInternalCount
(
count
);
item
.
setInternalPrice
(
item
.
getProduct
().
getPrice
().
abs
().
multiply
(
count
));
item
.
setInternalPrice
(
item
.
getProduct
().
getPrice
().
abs
().
multiply
(
count
));
item
.
setInternalDiscounts
(
discountBean
.
getActiveDiscountsByProduct
(
item
.
getProduct
(),
count
,
Calendar
.
getInstance
(),
item
.
getUser
()));
item
.
setInternalDiscounts
(
discountBean
.
getActiveDiscountsByProduct
(
item
.
getProduct
(),
count
,
Calendar
.
getInstance
(),
item
.
getUser
())
);
item
.
setInternalDiscountValues
(
new
HashMap
<
Integer
,
BigDecimal
>());
item
.
setInternalDiscountValues
(
new
HashMap
<
Integer
,
BigDecimal
>());
for
(
Discount
d
:
item
.
getDiscounts
())
{
for
(
Discount
d
:
item
.
getDiscounts
())
BigDecimal
newprice
=
item
.
getPrice
().
multiply
(
d
.
getPercentage
());
{
item
.
getInternalDiscountValues
().
put
(
d
.
getId
(),
item
.
getPrice
().
subtract
(
newprice
));
BigDecimal
newprice
=
item
.
getPrice
().
multiply
(
d
.
getPercentage
());
item
.
setInternalPrice
(
newprice
);
item
.
getInternalDiscountValues
().
put
(
d
.
getId
(),
item
.
getPrice
().
subtract
(
newprice
));
}
item
.
setInternalPrice
(
newprice
);
}
}
}
public
boolean
updateProductShopItemLimit
(
ProductShopItem
item
,
BigDecimal
limitValue
)
{
public
boolean
updateProductShopItemLimit
(
ProductShopItem
item
,
BigDecimal
limitValue
)
{
if
(
limitValue
!=
null
&&
limitValue
.
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
if
(
limitValue
!=
null
&&
limitValue
.
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
{
{
this
.
setProductShopItemCount
(
item
,
item
.
getCount
().
add
(
limitValue
));
this
.
setProductShopItemCount
(
item
,
item
.
getCount
().
add
(
limitValue
));
if
(
item
.
getCount
().
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
{
if
(
item
.
getCount
().
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
{
this
.
setProductShopItemCount
(
item
,
BigDecimal
.
ZERO
);
this
.
setProductShopItemCount
(
item
,
BigDecimal
.
ZERO
);
}
}
item
.
setLimit
(
BigDecimal
.
ZERO
);
item
.
setLimit
(
BigDecimal
.
ZERO
);
return
true
;
return
true
;
...
@@ -68,5 +63,4 @@ public class ProductShopItemHelper extends GenericCDIView {
...
@@ -68,5 +63,4 @@ public class ProductShopItemHelper extends GenericCDIView {
return
false
;
return
false
;
}
}
}
}
code/MoyaWeb/src/fi/codecrew/moya/web/helpers/ProductShopItem.java
View file @
48abfe9
...
@@ -47,7 +47,7 @@ public class ProductShopItem {
...
@@ -47,7 +47,7 @@ public class ProductShopItem {
this
.
user
=
user
;
this
.
user
=
user
;
this
.
product
=
prod
;
this
.
product
=
prod
;
id
=
this
.
product
.
getId
();
id
=
this
.
product
.
getId
();
set
Internal
Count
(
BigDecimal
.
ZERO
);
setCount
(
BigDecimal
.
ZERO
);
setInternalPrice
(
BigDecimal
.
ZERO
);
setInternalPrice
(
BigDecimal
.
ZERO
);
}
}
...
@@ -85,21 +85,26 @@ public class ProductShopItem {
...
@@ -85,21 +85,26 @@ public class ProductShopItem {
* DO NOT USE THIS.
* DO NOT USE THIS.
*
*
* Use ProductShopIteHelper.setProductShopItemCount instead.
* Use ProductShopIteHelper.setProductShopItemCount instead.
*
* p.s. This still needs to exist because we want to set count from jsf, but
* this value needs to be updated with
* ProductShopIteHelper.setProductShopItemCount
*
* @param count
* @param count
*/
*/
public
void
set
Internal
Count
(
BigDecimal
count
)
{
public
void
setCount
(
BigDecimal
count
)
{
this
.
count
=
count
;
this
.
count
=
count
;
}
}
public
void
setInternalPrice
(
BigDecimal
price
)
{
public
void
setInternalPrice
(
BigDecimal
price
)
{
this
.
price
=
price
;
this
.
price
=
price
;
}
}
public
List
<
Discount
>
getDiscounts
()
public
List
<
Discount
>
getDiscounts
()
{
{
return
discounts
;
return
discounts
;
}
}
public
void
setInternalDiscounts
(
List
<
Discount
>
discounts
)
{
public
void
setInternalDiscounts
(
List
<
Discount
>
discounts
)
{
this
.
discounts
=
discounts
;
this
.
discounts
=
discounts
;
}
}
...
@@ -109,7 +114,6 @@ public class ProductShopItem {
...
@@ -109,7 +114,6 @@ public class ProductShopItem {
return
discountValues
.
get
(
discId
);
return
discountValues
.
get
(
discId
);
}
}
public
BigDecimal
getPrice
()
public
BigDecimal
getPrice
()
{
{
return
price
;
return
price
;
...
@@ -145,11 +149,11 @@ public class ProductShopItem {
...
@@ -145,11 +149,11 @@ public class ProductShopItem {
public
void
setUser
(
EventUser
user
)
{
public
void
setUser
(
EventUser
user
)
{
this
.
user
=
user
;
this
.
user
=
user
;
}
}
public
Map
<
Integer
,
BigDecimal
>
getInternalDiscountValues
()
{
public
Map
<
Integer
,
BigDecimal
>
getInternalDiscountValues
()
{
return
discountValues
;
return
discountValues
;
}
}
public
void
setInternalDiscountValues
(
Map
<
Integer
,
BigDecimal
>
discountValues
)
{
public
void
setInternalDiscountValues
(
Map
<
Integer
,
BigDecimal
>
discountValues
)
{
this
.
discountValues
=
discountValues
;
this
.
discountValues
=
discountValues
;
}
}
...
...
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