Commit 9c338a42 by Tuomas Riihimäki

Add placeslot entity and some utility functions

1 parent 3fd67c49
......@@ -35,6 +35,7 @@ import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.PlaceSlot;
/**
*
......@@ -115,4 +116,6 @@ public interface PlaceBeanLocal {
List<Product> getMapProducts(EventMap map);
List<PlaceSlot> getFreePlaceslots(EventUser user);
}
......@@ -64,6 +64,7 @@ import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.PlaceFacade;
import fi.codecrew.moya.facade.PlaceGroupFacade;
import fi.codecrew.moya.facade.PlaceSlotFacade;
import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
......@@ -71,6 +72,7 @@ import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
......@@ -127,6 +129,8 @@ public class PlaceBean implements PlaceBeanLocal {
private BarcodeBeanLocal barcodeBean;
@EJB
private EventMapFacade eventMapFacade;
@EJB
private PlaceSlotFacade placeSlotFacade;
@Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS)
......@@ -146,6 +150,8 @@ public class PlaceBean implements PlaceBeanLocal {
@RolesAllowed(SpecialPermission.S_USER)
@Override
/** Use place slots */
@Deprecated
public BigDecimal getTotalReservationPrice(Place newPlace)
{
return addAndCalcPrice(permbean.getCurrentUser(), newPlace);
......@@ -153,12 +159,16 @@ public class PlaceBean implements PlaceBeanLocal {
@RolesAllowed(MapPermission.S_MANAGE_OTHERS)
@Override
/** Use place slots */
@Deprecated
public BigDecimal getTotalReservationPrice(EventUser user, Place newPlace)
{
return addAndCalcPrice(user, newPlace);
}
/** Use place slots */
@Deprecated()
private BigDecimal addAndCalcPrice(EventUser user, Place newPlace) {
Set<Place> places = new HashSet<Place>();
......@@ -241,6 +251,7 @@ public class PlaceBean implements PlaceBeanLocal {
for (Timer t : ts.getTimers()) {
if (t.getInfo().equals(PLACE_RESERVE_TIMEOUTER)) {
foundTimeout = true;
break;
}
}
if (!foundTimeout) {
......@@ -689,6 +700,13 @@ public class PlaceBean implements PlaceBeanLocal {
@Override
public List<EventMap> getMaps() {
return eventMapFacade.getMaps();
@Override
public List<PlaceSlot> getFreePlaceslots(EventUser user) {
user = eventUserFacade.reload(user);
if (!permbean.isCurrentUser(user) && !permbean.hasPermission(MapPermission.MANAGE_OTHERS))
throw new EJBAccessException("User " + permbean.getCurrentUser() + "tried to fetch free places for user " + user);
return placeSlotFacade.findFreePlaces(user);
}
@Override
......
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.facade;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Root;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.Bill;
import fi.codecrew.moya.model.Bill_;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.PlaceSlot_;
@Stateless
@LocalBean
public class PlaceSlotFacade extends IntegerPkGenericFacade<Place> {
private static final Logger logger = LoggerFactory.getLogger(PlaceSlotFacade.class);
@EJB
EventBeanLocal eventBean;
public PlaceSlotFacade() {
super(Place.class);
}
/**
* Returns placeslots this user can use.
*
* @param user
* @return
*/
public List<PlaceSlot> findFreePlaceSlots(EventUser user) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<PlaceSlot> q = cb.createQuery(PlaceSlot.class);
Root<PlaceSlot> root = q.from(PlaceSlot.class);
Path<Bill> bill = root.get(PlaceSlot_.bill);
q.where(cb.(bill.get(Bill_.accountEvent))
}
// private List<PlaceSlot> getSlotsForUser(EventUser u) {
//
// CriteriaBuilder cb = getEm().getCriteriaBuilder();
// CriteriaQuery<PlaceSlot> cq = cb.createQuery(PlaceSlot.class);
//
// }
}
......@@ -53,382 +53,382 @@ import fi.codecrew.moya.utilities.BillUtils;
@Table(name = "bills", uniqueConstraints = { @UniqueConstraint(columnNames = { Bill.EVENT_ID_COLUMN, "bill_number" }) })
public class Bill extends GenericEntity {
/**
/**
*
*/
private static final long serialVersionUID = -6713643278149221869L;
public static final String EVENT_ID_COLUMN = "event_id";
@ManyToOne()
@JoinColumn(name = EVENT_ID_COLUMN, nullable = false)
private LanEvent event;
/**
* When the bill is due to be paid.
*/
// Can be calculated from SentDate + paymentTime
// @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 Date paidDate;
/**
* The bill number from which the reference number will be generated
*
* @see http://www.fkl.fi/www/page/fk_www_1293
*
*/
@Column(name = "bill_number")
private Integer billNumber;
/**
* Address where the bill should be sent;
*/
private String addr1;
private String addr2;
private String addr3;
private String addr4;
private String addr5;
@Column(nullable = false, name = "sent_time")
@Temporal(TemporalType.TIMESTAMP)
private Calendar sentDate = Calendar.getInstance();
@Column(name = "payment_time", nullable = false)
private Integer paymentTime = 0;
@Column(name = "notice_days", nullable = false)
private String noticetime = "8 vrk";
@Column(name = "their_reference", nullable = false)
private String theirReference = "";
@Column(name = "our_reference", nullable = false)
private String ourReference = "";
@Column(name = "delivery_terms", nullable = false)
private String deliveryTerms = "";
@Column(name = "delay_intrest", nullable = false)
private Integer delayIntrest = 11;
@Column(name = "expires", nullable = true)
@Temporal(TemporalType.TIMESTAMP)
private Calendar expires = null;
/**
* Notes for the event organisators about the bill.
*/
@Lob
@Column(name = "notes")
private String notes;
/**
* Bill may have multiple items on multiple rows.
*/
@OrderBy("id")
// @PrivateOwned
@OneToMany(mappedBy = "bill", cascade = CascadeType.ALL)
private List<BillLine> billLines = new ArrayList<BillLine>();
public boolean isPaid()
{
return accountEvent != null || paidDate != null;
}
/**
* When the bill is paid this AccountEvent is created and this is a
* reference to that accountAction. if this bill
*/
@JoinColumn(name = "account_event_id", referencedColumnName = "id", updatable = false)
@OneToOne
private AccountEvent accountEvent;
/**
* User who should pay this bill.
*/
@ManyToOne(optional = false)
@JoinColumn(updatable = false, name = "eventuser_id")
private EventUser user;
@SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(Bill.class);
public Integer getReferenceNumberBase() {
if (getEvent() != null && getEvent().getReferenceNumberBase() != null && getBillNumber() != null) {
return getEvent().getReferenceNumberBase() + getBillNumber();
}
return null;
}
public Integer getReferenceNumber()
{
return BillUtils.createReferenceNumber(getReferenceNumberBase());
}
/**
* 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;
}
public BigDecimal getTotalPrice() {
return this.totalPrice();
}
/**
* Commodity function to calculate the total price of the bill.
*
* @return The total sum of the bill ( unitPrice * units * vat )
*/
public BigDecimal totalVat() {
BigDecimal total = BigDecimal.ZERO;
for (BillLine line : getBillLines()) {
total = total.add(line.getLineVat());
}
return total;
}
private static final long serialVersionUID = -6713643278149221869L;
public static final String EVENT_ID_COLUMN = "event_id";
/**
* 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;
}
public Bill(LanEvent event, EventUser user, Calendar expires) {
this(event, expires);
this.setUser(user);
this.setAddr1(user.getUser().getFirstnames() + " " + user.getUser().getLastname());
this.setAddr2(user.getUser().getAddress());
this.setAddr3(user.getUser().getZip() + " " + user.getUser().getTown());
}
public Bill(LanEvent event, Calendar expires) {
this();
this.expires = expires;
this.event = event;
}
public Bill(LanEvent event, EventUser user, long expireTimeHours) {
this(event, user, Calendar.getInstance());
this.expires.setTimeInMillis((System.currentTimeMillis() + (expireTimeHours * 60 * 60 * 1000)));
}
public Bill(LanEvent event, long expireTimeHours) {
this(event, Calendar.getInstance());
this.expires.setTimeInMillis((System.currentTimeMillis() + (expireTimeHours * 60 * 60 * 1000)));
}
public Bill() {
super();
this.expires = Calendar.getInstance();
this.expires.setTimeInMillis((System.currentTimeMillis() + 1209600000)); // 2vk
}
public Calendar getDueDate() {
Calendar dueDate = Calendar.getInstance();
dueDate.setTime(this.getSentDate().getTime());
dueDate.add(Calendar.DATE, this.getPaymentTime());
return dueDate;
}
public String getNotes() {
return notes;
}
@ManyToOne()
@JoinColumn(name = EVENT_ID_COLUMN, nullable = false)
private LanEvent event;
public void setNotes(String notes) {
this.notes = notes;
}
public List<BillLine> getBillLines() {
return billLines;
}
public void setBillLines(List<BillLine> billLineList) {
this.billLines = billLineList;
}
public AccountEvent getAccountEvent() {
return accountEvent;
}
public void setAccountEvent(AccountEvent accoutEventsId) {
this.accountEvent = accoutEventsId;
}
public EventUser getUser() {
return user;
}
public void setUser(EventUser usersId) {
this.user = usersId;
}
public Integer getBillNumber() {
return billNumber;
}
public String getAddr1() {
return addr1;
}
public void setAddr1(String addr1) {
this.addr1 = addr1;
}
public String getAddr2() {
return addr2;
}
public void setAddr2(String addr2) {
this.addr2 = addr2;
}
public String getAddr3() {
return addr3;
}
public void setAddr3(String addr3) {
this.addr3 = addr3;
}
public String getAddr4() {
return addr4;
}
public void setAddr4(String addr4) {
this.addr4 = addr4;
}
public String getAddr5() {
return addr5;
}
public void setAddr5(String addr5) {
this.addr5 = addr5;
}
public String getNoticetime() {
return noticetime;
}
public void setNoticetime(String noticetime) {
this.noticetime = noticetime;
}
public String getOurReference() {
return ourReference;
}
public void setOurReference(String ourReference) {
this.ourReference = ourReference;
}
public void setTheirReference(String theirReference) {
this.theirReference = theirReference;
}
public String getTheirReference() {
return theirReference;
}
public void setDeliveryTerms(String deliveryTerms) {
this.deliveryTerms = deliveryTerms;
}
public String getDeliveryTerms() {
return deliveryTerms;
}
public void setPaymentTime(Integer paymentTime) {
this.paymentTime = paymentTime;
}
public Integer getPaymentTime() {
return paymentTime;
}
public void setDelayIntrest(Integer delayIntrest) {
this.delayIntrest = delayIntrest;
}
public Integer getDelayIntrest() {
return delayIntrest;
}
public void setBillNumber(Integer billNumber) {
this.billNumber = billNumber;
}
/**
* When the bill is due to be paid.
*/
// Can be calculated from SentDate + paymentTime
// @Column(name = "due_date")
// @Temporal(TemporalType.TIMESTAMP)
// private Calendar dueDate;
public LanEvent getEvent() {
return event;
}
/**
* When the money has appeared on the bank account.
*/
@Column(name = "paid_date")
@Temporal(TemporalType.TIMESTAMP)
private Date paidDate;
public void setEvent(LanEvent event) {
this.event = event;
}
/**
* The bill number from which the reference number will be generated
*
* @see http://www.fkl.fi/www/page/fk_www_1293
*
*/
@Column(name = "bill_number")
private Integer billNumber;
public Date getPaidDate() {
return paidDate;
}
/**
* Address where the bill should be sent;
*/
private String addr1;
private String addr2;
private String addr3;
private String addr4;
private String addr5;
@Column(nullable = false, name = "sent_time")
@Temporal(TemporalType.TIMESTAMP)
private Calendar sentDate = Calendar.getInstance();
@Column(name = "payment_time", nullable = false)
private Integer paymentTime = 0;
@Column(name = "notice_days", nullable = false)
private String noticetime = "8 vrk";
@Column(name = "their_reference", nullable = false)
private String theirReference = "";
@Column(name = "our_reference", nullable = false)
private String ourReference = "";
@Column(name = "delivery_terms", nullable = false)
private String deliveryTerms = "";
@Column(name = "delay_intrest", nullable = false)
private Integer delayIntrest = 11;
@Column(name = "expires", nullable = true)
@Temporal(TemporalType.TIMESTAMP)
private Calendar expires = null;
/**
* Notes for the event organisators about the bill.
*/
@Lob
@Column(name = "notes")
private String notes;
public void setPaidDate(Date paidDate) {
if (paidDate != null)
expires = null;
/**
* Bill may have multiple items on multiple rows.
*/
this.paidDate = paidDate;
}
@OrderBy("id")
// @PrivateOwned
@OneToMany(mappedBy = "bill", cascade = CascadeType.ALL)
private List<BillLine> billLines = new ArrayList<BillLine>();
public Date getSentDateTime()
{
Date ret = null;
if (sentDate != null)
{
ret = sentDate.getTime();
}
return ret;
}
public boolean isPaid()
{
return accountEvent != null || paidDate != null;
}
public void setSentDateTime(Date date)
{
if (date == null)
{
sentDate = null;
} else {
if (sentDate == null)
{
sentDate = Calendar.getInstance();
}
sentDate.setTime(date);
}
}
/**
* When the bill is paid this AccountEvent is created and this is a
* reference to that accountAction. if this bill
*/
@JoinColumn(name = "account_event_id", referencedColumnName = "id", updatable = false)
@OneToOne
private AccountEvent accountEvent;
public Calendar getSentDate() {
return sentDate;
}
/**
* User who should pay this bill.
*/
@ManyToOne(optional = false)
@JoinColumn(updatable = false, name = "eventuser_id")
private EventUser user;
@SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(Bill.class);
public Integer getReferenceNumberBase() {
if (getEvent() != null && getEvent().getReferenceNumberBase() != null && getBillNumber() != null) {
return getEvent().getReferenceNumberBase() + getBillNumber();
}
return null;
}
public Integer getReferenceNumber()
{
return BillUtils.createReferenceNumber(getReferenceNumberBase());
}
/**
* 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;
}
public BigDecimal getTotalPrice() {
return this.totalPrice();
}
/**
* Commodity function to calculate the total price of the bill.
*
* @return The total sum of the bill ( unitPrice * units * vat )
*/
public BigDecimal totalVat() {
BigDecimal total = BigDecimal.ZERO;
for (BillLine line : getBillLines()) {
total = total.add(line.getLineVat());
}
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;
}
public Bill(LanEvent event, EventUser user, Calendar expires) {
this(event, expires);
this.setUser(user);
this.setAddr1(user.getUser().getFirstnames() + " " + user.getUser().getLastname());
this.setAddr2(user.getUser().getAddress());
this.setAddr3(user.getUser().getZip() + " " + user.getUser().getTown());
}
public Bill(LanEvent event, Calendar expires) {
this();
this.expires = expires;
this.event = event;
}
public Bill(LanEvent event, EventUser user, long expireTimeHours) {
this(event, user, Calendar.getInstance());
this.expires.setTimeInMillis((System.currentTimeMillis() + (expireTimeHours*60*60 * 1000 )));
}
public Bill(LanEvent event, long expireTimeHours) {
this(event, Calendar.getInstance());
this.expires.setTimeInMillis((System.currentTimeMillis() + (expireTimeHours*60*60 * 1000 )));
}
public Bill() {
super();
this.expires = Calendar.getInstance();
this.expires.setTimeInMillis((System.currentTimeMillis() + 1209600000)); // 2vk
}
public Calendar getDueDate() {
Calendar dueDate = Calendar.getInstance();
dueDate.setTime(this.getSentDate().getTime());
dueDate.add(Calendar.DATE, this.getPaymentTime());
return dueDate;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public List<BillLine> getBillLines() {
return billLines;
}
public void setBillLines(List<BillLine> billLineList) {
this.billLines = billLineList;
}
public AccountEvent getAccountEvent() {
return accountEvent;
}
public void setAccountEvent(AccountEvent accoutEventsId) {
this.accountEvent = accoutEventsId;
}
public EventUser getUser() {
return user;
}
public void setUser(EventUser usersId) {
this.user = usersId;
}
public Integer getBillNumber() {
return billNumber;
}
public String getAddr1() {
return addr1;
}
public void setAddr1(String addr1) {
this.addr1 = addr1;
}
public String getAddr2() {
return addr2;
}
public void setAddr2(String addr2) {
this.addr2 = addr2;
}
public String getAddr3() {
return addr3;
}
public void setAddr3(String addr3) {
this.addr3 = addr3;
}
public String getAddr4() {
return addr4;
}
public void setAddr4(String addr4) {
this.addr4 = addr4;
}
public String getAddr5() {
return addr5;
}
public void setAddr5(String addr5) {
this.addr5 = addr5;
}
public String getNoticetime() {
return noticetime;
}
public void setNoticetime(String noticetime) {
this.noticetime = noticetime;
}
public String getOurReference() {
return ourReference;
}
public void setOurReference(String ourReference) {
this.ourReference = ourReference;
}
public void setTheirReference(String theirReference) {
this.theirReference = theirReference;
}
public String getTheirReference() {
return theirReference;
}
public void setDeliveryTerms(String deliveryTerms) {
this.deliveryTerms = deliveryTerms;
}
public String getDeliveryTerms() {
return deliveryTerms;
}
public void setPaymentTime(Integer paymentTime) {
this.paymentTime = paymentTime;
}
public Integer getPaymentTime() {
return paymentTime;
}
public void setDelayIntrest(Integer delayIntrest) {
this.delayIntrest = delayIntrest;
}
public Integer getDelayIntrest() {
return delayIntrest;
}
public void setBillNumber(Integer billNumber) {
this.billNumber = billNumber;
}
public LanEvent getEvent() {
return event;
}
public void setEvent(LanEvent event) {
this.event = event;
}
public Date getPaidDate() {
return paidDate;
}
public void setPaidDate(Date paidDate) {
if(paidDate != null)
expires = null;
this.paidDate = paidDate;
}
public Date getSentDateTime()
{
Date ret = null;
if (sentDate != null)
{
ret = sentDate.getTime();
}
return ret;
}
public void setSentDateTime(Date date)
{
if (date == null)
{
sentDate = null;
} else {
if (sentDate == null)
{
sentDate = Calendar.getInstance();
}
sentDate.setTime(date);
}
}
public Calendar getSentDate() {
return sentDate;
}
public void setSentDate(Calendar sentDate) {
this.sentDate = sentDate;
}
public void setSentDate(Calendar sentDate) {
this.sentDate = sentDate;
}
public boolean isFoodwaveBill() {
for (BillLine bl : billLines)
{
......@@ -439,41 +439,41 @@ public class Bill extends GenericEntity {
return false;
}
public boolean isFoowavePaymentOver() {
for (BillLine bl : billLines)
{
public boolean isFoowavePaymentOver() {
for (BillLine bl : billLines)
{
if (bl.getFoodwave() != null) {
if (bl.getFoodwave().isPaymentOver())
{
{
return true;
}
}
}
}
}
}
return false;
}
public Calendar getExpires() {
return expires;
}
public void setExpires(Calendar expires) {
this.expires = expires;
}
public boolean isExpired() {
if (expires == null)
return false;
return Calendar.getInstance().after(expires);
}
public void markExpired() {
if (isExpired() || isPaid())
return;
expires = Calendar.getInstance();
}
public Calendar getExpires() {
return expires;
}
public void setExpires(Calendar expires) {
this.expires = expires;
}
public boolean isExpired() {
if(isPaid() || expires == null)
return false;
return Calendar.getInstance().after(expires);
}
public void markExpired() {
if(isExpired() || isPaid())
return;
expires = Calendar.getInstance();
}
@Transient
public BigDecimal getTotalQuantity() {
......@@ -484,25 +484,25 @@ public class Bill extends GenericEntity {
continue;
total = total.add(l.getQuantity());
}
}
return total;
}
@Transient
public String getProductSummary() {
String summary = "";
for(BillLine l : getBillLines()) {
if(l == null || l.getQuantity() == null)
continue;
if(!summary.isEmpty()) {
summary += ", ";
}
summary += l.getName();
}
return summary;
}
}
......
package fi.codecrew.moya.model;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name = "place_slots")
public class PlaceSlot extends GenericEntity {
private static final long serialVersionUID = -7163361140751806941L;
@Temporal(TemporalType.TIMESTAMP)
private Date created;
@Temporal(TemporalType.TIMESTAMP)
private Date used;
@JoinColumn(nullable = false)
@ManyToOne
private Bill bill;
@JoinColumn(nullable = false)
@ManyToOne
private Product product;
@JoinColumn(nullable = true, unique = true)
@OneToOne
private Place place;
@Lob
private String description;
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getUsed() {
return used;
}
public void setUsed(Date used) {
this.used = used;
}
public Bill getBill() {
return bill;
}
public void setBill(Bill bill) {
this.bill = bill;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Place getPlace() {
return place;
}
public void setPlace(Place place) {
this.place = place;
}
}
......@@ -19,6 +19,7 @@
package fi.codecrew.moya.web.cdiview.map;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
......@@ -40,6 +41,8 @@ import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.SearchQuery;
import fi.codecrew.moya.utilities.SearchQuery.QuerySortOrder;
......@@ -117,26 +120,37 @@ public class PlaceView extends GenericCDIView {
} else if (place.isBuyable() && !place.isTaken()) {
BigDecimal balance = user.getAccountBalance();
BigDecimal price = null;
boolean canReserve = false;
// If place product is marked "PREPAID_CREDIT", places are bought from
// slots. If flag does not exist place slot is created from a bill.
if (place.getProduct().getProductFlags().contains(ProductFlag.PREPAID_CREDIT)) {
BigDecimal balance = user.getAccountBalance();
BigDecimal price = null;
if (permbean.isCurrentUser(user)) {
price = placebean.getTotalReservationPrice(place);
} else {
price = placebean.getTotalReservationPrice(user, place);
}
canReserve = (price.compareTo(balance) <= 0);
logger.debug("Balance {}, price {}", balance, price);
if (balance.compareTo(BigDecimal.ZERO) > 0) {
addFaceMessage("mapView.notEnoughCreditsToReserve");
}
if (!canReserve)
logger.debug("Did not have enought credits to reserve place! required {} , got {}", price, balance);
if (permbean.isCurrentUser(user)) {
price = placebean.getTotalReservationPrice(place);
} else {
price = placebean.getTotalReservationPrice(user, place);
List<PlaceSlot> placeslots = placebean.getFreePlaceslots(user);
canReserve = placeslots.size() > 0;
}
logger.debug("Balance {}, price {}", balance, price);
if (price.compareTo(balance) <= 0) {
if (canReserve) {
logger.debug("Place was free. Marking for user.");
if (!placebean.reservePlace(place, user)) {
this.addFaceMessage("mapView.errorWhenReservingPlace");
}
} else {
if (balance.compareTo(BigDecimal.ZERO) > 0) {
addFaceMessage("mapView.notEnoughCreditsToReserve");
}
logger.debug("Did not have enought credits to reserve place! required {} , got {}", price, balance);
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!