Commit b8f16f85 by Tuukka Kivilahti

Merge branch 'payment-source' into 'master'

Add a source of payment to bills

See merge request !426
2 parents 7fb40872 c819151b
......@@ -50,7 +50,7 @@ public interface BillBeanLocal {
Collection<BillSummary> getBillLineSummary();
Bill markPaid(Bill bill, Calendar when, boolean useCredits) throws BillException;
Bill markPaid(Bill bill, Calendar when, boolean useCredits, Bill.BillPaymentSource paymentSource) throws BillException;
void getPdfBillStream(Bill bill, OutputStream ostream);
......
......@@ -237,9 +237,9 @@ public class BillBean implements BillBeanLocal {
@Override
@RolesAllowed({ BillPermission.S_WRITE_ALL })
public Bill markPaid(Bill bill, Calendar when, boolean useCredits) throws BillException {
public Bill markPaid(Bill bill, Calendar when, boolean useCredits, Bill.BillPaymentSource paymentSource) throws BillException {
return billpbean.markPaid(bill, when, useCredits);
return billpbean.markPaid(bill, when, useCredits, paymentSource);
}
@Override
......@@ -276,7 +276,7 @@ public class BillBean implements BillBeanLocal {
// we will mark them immediately as paid.
if (bill.getTotalPrice().compareTo(BigDecimal.ZERO) == 0
&& eventbean.getPropertyBoolean(LanEventPropertyKey.ALLOW_FREE_BILLS)) {
bill = billpbean.markPaid(bill, Calendar.getInstance(), false);
bill = billpbean.markPaid(bill, Calendar.getInstance(), false, Bill.BillPaymentSource.UNKNOWN);
}
return bill;
......
......@@ -52,7 +52,7 @@ public class BillPBean {
private static final Logger logger = LoggerFactory.getLogger(BillPBean.class);
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private Bill markPaidSafeTransaction(Bill bill, Calendar when, boolean useCredits) throws BillException {
private Bill markPaidSafeTransaction(Bill bill, Calendar when, boolean useCredits, Bill.BillPaymentSource paymentSource) throws BillException {
bill = billFacade.reload(bill);
if (bill.getAccountEvent() != null || bill.getPaidDate() != null) {
......@@ -87,13 +87,14 @@ public class BillPBean {
}
bill.setPaidDate(when.getTime());
bill.setPaymentSource(paymentSource);
return bill;
}
public Bill markPaid(Bill bill, Calendar when, boolean useCredits) throws BillException {
public Bill markPaid(Bill bill, Calendar when, boolean useCredits, Bill.BillPaymentSource paymentSource) throws BillException {
bill = markPaidSafeTransaction(bill, when, useCredits);
bill = markPaidSafeTransaction(bill, when, useCredits, paymentSource);
EventUser user = bill.getUser();
......
......@@ -640,6 +640,9 @@ public class BootstrapBean implements BootstrapBeanLocal {
"ALTER TABLE event_role_features ADD CONSTRAINT FK_event_role_features_role_id FOREIGN KEY (role_id) REFERENCES roles (id)"
});
dbUpdates.add(new String[]{
"ALTER TABLE bills ADD COLUMN payment_source TEXT NOT NULL default 'UNKNOWN'",
});
}
public BootstrapBean() {
......
......@@ -380,7 +380,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
if (bill.getAccountEvent() == null
&& bill.getPaidDate() == null) {
logger.info("Trying to mark bill {} paid", bill);
billpbean.markPaid(bill, Calendar.getInstance(), false);
billpbean.markPaid(bill, Calendar.getInstance(), false, Bill.BillPaymentSource.CHECKOUT);
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Marking bill paid from checkout. Received bill status ", statusInt, " for bill ", bill, " stamp ", stamp, " payment: ", payment, " reference ", reference);
} else {
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Bill already marked paid: ", bill, " status ", status, " stamp ", stamp, " payment ", payment);
......
......@@ -135,7 +135,7 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
} else if (bill.getAccountEvent() == null
&& bill.getPaidDate() == null
&& (SvmReturnType.NOTIFICATION.equals(type) || SvmReturnType.SUCCESS.equals(type))) {
billpbean.markPaid(bill, Calendar.getInstance(), false);
billpbean.markPaid(bill, Calendar.getInstance(), false, Bill.BillPaymentSource.PAYTRAIL);
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Validated order number ", orderNumber, " bill ", bill == null ? "null" : bill.toString(), " with authcode: ", authcode);
ret = true;
......
......@@ -25,20 +25,7 @@ import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.persistence.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -54,6 +41,16 @@ import fi.codecrew.moya.utilities.BillUtils;
@Table(name = "bills", uniqueConstraints = { @UniqueConstraint(columnNames = { Bill.EVENT_ID_COLUMN, "bill_number" }) })
public class Bill extends GenericEntity {
public enum BillPaymentSource{
UNKNOWN,
PAYTRAIL,
CHECKOUT,
// expected to be paid by cash
CASH,
// Marked paid by admin ui
ADMIN,
CREDITS,
}
/**
* <p>
* With how many decimals we want to calculate prices, discounts, etc. If we
......@@ -176,6 +173,11 @@ public class Bill extends GenericEntity {
@JoinColumn(updatable = false, name = "eventuser_id")
private EventUser user;
@Column(nullable=false, name = "payment_source")
@Enumerated(EnumType.STRING)
private BillPaymentSource paymentSource = BillPaymentSource.UNKNOWN;
@SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(Bill.class);
......@@ -504,4 +506,12 @@ public class Bill extends GenericEntity {
return summary;
}
public BillPaymentSource getPaymentSource() {
return paymentSource;
}
public void setPaymentSource(BillPaymentSource paymentSource) {
this.paymentSource = paymentSource;
}
}
......@@ -29,6 +29,9 @@
<h:outputLabel for="paidDate" value="#{i18n['bill.paidDate']}:" />
<p:calendar id="paidDate" value="#{billEditView.bill.paidDate}" pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
<h:outputLabel for="paymentSource" value="#{i18n['bill.paymentSource']}:" />
<h:outputText id="paymentSource" value="#{billEditView.bill.paymentSource}" />
<h:outputLabel for="billnr" value="#{i18n['bill.billNumber']}:" />
<h:inputText id="billnr" value="#{billEditView.bill.billNumber}" />
......
......@@ -145,7 +145,7 @@ public class BillEditView extends GenericCDIView {
public void buyWithCredits() {
try {
bill = billbean.markPaid(bill, Calendar.getInstance(), true);
bill = billbean.markPaid(bill, Calendar.getInstance(), true, Bill.BillPaymentSource.ADMIN);
} catch (BillException e) {
throw new RuntimeException(e);
// TODO: error handling
......
......@@ -151,7 +151,7 @@ public class BillListView extends GenericCDIView {
try {
Bill bill = lazyBillList.getRowData();
billbean.markPaid(bill, Calendar.getInstance(), false);
billbean.markPaid(bill, Calendar.getInstance(), false, Bill.BillPaymentSource.ADMIN);
} catch (BillException x) {
throw new RuntimeException(x);
}
......
......@@ -172,7 +172,7 @@ public class FoodWaveFoodView extends GenericCDIView {
Bill b = createBillFromShoppingcart();
try {
billBean.markPaid(b, Calendar.getInstance(), true);
billBean.markPaid(b, Calendar.getInstance(), true, Bill.BillPaymentSource.CREDITS);
} catch (BillException e) {
throw new RuntimeException(e);
}
......@@ -186,7 +186,7 @@ public class FoodWaveFoodView extends GenericCDIView {
Bill b = createBillFromShoppingcart();
try {
billBean.markPaid(b, Calendar.getInstance(), false);
billBean.markPaid(b, Calendar.getInstance(), false, Bill.BillPaymentSource.CASH);
} catch (BillException e) {
throw new RuntimeException(e);
}
......
......@@ -265,7 +265,7 @@ public class FoodWaveView extends GenericCDIView {
Bill b = bills.getRowData();
try {
b = billbean.markPaid(b, Calendar.getInstance(), false);
b = billbean.markPaid(b, Calendar.getInstance(), false, Bill.BillPaymentSource.CASH);
} catch (BillException e) {
throw new RuntimeException(e);
}
......@@ -288,7 +288,7 @@ public class FoodWaveView extends GenericCDIView {
Bill b = bills.getRowData();
try {
b = billbean.markPaid(b, Calendar.getInstance(), true);
b = billbean.markPaid(b, Calendar.getInstance(), true, Bill.BillPaymentSource.CREDITS);
} catch (BillException e) {
throw new RuntimeException(e);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!