Commit c819151b by Tuomas Riihimäki

Add a source of payment to bills

Att the moment we do not have a way to distinguish betweeb cahsh, admin, and
paytrail/checkout payments. This mergerequest adds the functionality.
1 parent 03676fde
Pipeline #161 passed
in 0 seconds
...@@ -50,7 +50,7 @@ public interface BillBeanLocal { ...@@ -50,7 +50,7 @@ public interface BillBeanLocal {
Collection<BillSummary> getBillLineSummary(); 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); void getPdfBillStream(Bill bill, OutputStream ostream);
......
...@@ -237,9 +237,9 @@ public class BillBean implements BillBeanLocal { ...@@ -237,9 +237,9 @@ public class BillBean implements BillBeanLocal {
@Override @Override
@RolesAllowed({ BillPermission.S_WRITE_ALL }) @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 @Override
...@@ -276,7 +276,7 @@ public class BillBean implements BillBeanLocal { ...@@ -276,7 +276,7 @@ public class BillBean implements BillBeanLocal {
// we will mark them immediately as paid. // we will mark them immediately as paid.
if (bill.getTotalPrice().compareTo(BigDecimal.ZERO) == 0 if (bill.getTotalPrice().compareTo(BigDecimal.ZERO) == 0
&& eventbean.getPropertyBoolean(LanEventPropertyKey.ALLOW_FREE_BILLS)) { && 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; return bill;
......
...@@ -52,7 +52,7 @@ public class BillPBean { ...@@ -52,7 +52,7 @@ public class BillPBean {
private static final Logger logger = LoggerFactory.getLogger(BillPBean.class); private static final Logger logger = LoggerFactory.getLogger(BillPBean.class);
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) @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); bill = billFacade.reload(bill);
if (bill.getAccountEvent() != null || bill.getPaidDate() != null) { if (bill.getAccountEvent() != null || bill.getPaidDate() != null) {
...@@ -87,13 +87,14 @@ public class BillPBean { ...@@ -87,13 +87,14 @@ public class BillPBean {
} }
bill.setPaidDate(when.getTime()); bill.setPaidDate(when.getTime());
bill.setPaymentSource(paymentSource);
return bill; 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(); EventUser user = bill.getUser();
......
...@@ -640,6 +640,9 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -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)" "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() { public BootstrapBean() {
......
...@@ -380,7 +380,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -380,7 +380,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
if (bill.getAccountEvent() == null if (bill.getAccountEvent() == null
&& bill.getPaidDate() == null) { && bill.getPaidDate() == null) {
logger.info("Trying to mark bill {} paid", bill); 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); 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 { } else {
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Bill already marked paid: ", bill, " status ", status, " stamp ", stamp, " payment ", payment); 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 { ...@@ -135,7 +135,7 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
} else if (bill.getAccountEvent() == null } else if (bill.getAccountEvent() == null
&& bill.getPaidDate() == null && bill.getPaidDate() == null
&& (SvmReturnType.NOTIFICATION.equals(type) || SvmReturnType.SUCCESS.equals(type))) { && (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); logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Validated order number ", orderNumber, " bill ", bill == null ? "null" : bill.toString(), " with authcode: ", authcode);
ret = true; ret = true;
......
...@@ -25,20 +25,7 @@ import java.util.Calendar; ...@@ -25,20 +25,7 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType; import javax.persistence.*;
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 org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -54,6 +41,16 @@ import fi.codecrew.moya.utilities.BillUtils; ...@@ -54,6 +41,16 @@ import fi.codecrew.moya.utilities.BillUtils;
@Table(name = "bills", uniqueConstraints = { @UniqueConstraint(columnNames = { Bill.EVENT_ID_COLUMN, "bill_number" }) }) @Table(name = "bills", uniqueConstraints = { @UniqueConstraint(columnNames = { Bill.EVENT_ID_COLUMN, "bill_number" }) })
public class Bill extends GenericEntity { 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> * <p>
* With how many decimals we want to calculate prices, discounts, etc. If we * With how many decimals we want to calculate prices, discounts, etc. If we
...@@ -176,6 +173,11 @@ public class Bill extends GenericEntity { ...@@ -176,6 +173,11 @@ public class Bill extends GenericEntity {
@JoinColumn(updatable = false, name = "eventuser_id") @JoinColumn(updatable = false, name = "eventuser_id")
private EventUser user; private EventUser user;
@Column(nullable=false, name = "payment_source")
@Enumerated(EnumType.STRING)
private BillPaymentSource paymentSource = BillPaymentSource.UNKNOWN;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(Bill.class); private static final Logger logger = LoggerFactory.getLogger(Bill.class);
...@@ -504,4 +506,12 @@ public class Bill extends GenericEntity { ...@@ -504,4 +506,12 @@ public class Bill extends GenericEntity {
return summary; return summary;
} }
public BillPaymentSource getPaymentSource() {
return paymentSource;
}
public void setPaymentSource(BillPaymentSource paymentSource) {
this.paymentSource = paymentSource;
}
} }
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
<h:outputLabel for="paidDate" value="#{i18n['bill.paidDate']}:" /> <h:outputLabel for="paidDate" value="#{i18n['bill.paidDate']}:" />
<p:calendar id="paidDate" value="#{billEditView.bill.paidDate}" pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" /> <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:outputLabel for="billnr" value="#{i18n['bill.billNumber']}:" />
<h:inputText id="billnr" value="#{billEditView.bill.billNumber}" /> <h:inputText id="billnr" value="#{billEditView.bill.billNumber}" />
......
...@@ -145,7 +145,7 @@ public class BillEditView extends GenericCDIView { ...@@ -145,7 +145,7 @@ public class BillEditView extends GenericCDIView {
public void buyWithCredits() { public void buyWithCredits() {
try { try {
bill = billbean.markPaid(bill, Calendar.getInstance(), true); bill = billbean.markPaid(bill, Calendar.getInstance(), true, Bill.BillPaymentSource.ADMIN);
} catch (BillException e) { } catch (BillException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
// TODO: error handling // TODO: error handling
......
...@@ -151,7 +151,7 @@ public class BillListView extends GenericCDIView { ...@@ -151,7 +151,7 @@ public class BillListView extends GenericCDIView {
try { try {
Bill bill = lazyBillList.getRowData(); Bill bill = lazyBillList.getRowData();
billbean.markPaid(bill, Calendar.getInstance(), false); billbean.markPaid(bill, Calendar.getInstance(), false, Bill.BillPaymentSource.ADMIN);
} catch (BillException x) { } catch (BillException x) {
throw new RuntimeException(x); throw new RuntimeException(x);
} }
......
...@@ -172,7 +172,7 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -172,7 +172,7 @@ public class FoodWaveFoodView extends GenericCDIView {
Bill b = createBillFromShoppingcart(); Bill b = createBillFromShoppingcart();
try { try {
billBean.markPaid(b, Calendar.getInstance(), true); billBean.markPaid(b, Calendar.getInstance(), true, Bill.BillPaymentSource.CREDITS);
} catch (BillException e) { } catch (BillException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -186,7 +186,7 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -186,7 +186,7 @@ public class FoodWaveFoodView extends GenericCDIView {
Bill b = createBillFromShoppingcart(); Bill b = createBillFromShoppingcart();
try { try {
billBean.markPaid(b, Calendar.getInstance(), false); billBean.markPaid(b, Calendar.getInstance(), false, Bill.BillPaymentSource.CASH);
} catch (BillException e) { } catch (BillException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
...@@ -265,7 +265,7 @@ public class FoodWaveView extends GenericCDIView { ...@@ -265,7 +265,7 @@ public class FoodWaveView extends GenericCDIView {
Bill b = bills.getRowData(); Bill b = bills.getRowData();
try { try {
b = billbean.markPaid(b, Calendar.getInstance(), false); b = billbean.markPaid(b, Calendar.getInstance(), false, Bill.BillPaymentSource.CASH);
} catch (BillException e) { } catch (BillException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -288,7 +288,7 @@ public class FoodWaveView extends GenericCDIView { ...@@ -288,7 +288,7 @@ public class FoodWaveView extends GenericCDIView {
Bill b = bills.getRowData(); Bill b = bills.getRowData();
try { try {
b = billbean.markPaid(b, Calendar.getInstance(), true); b = billbean.markPaid(b, Calendar.getInstance(), true, Bill.BillPaymentSource.CREDITS);
} catch (BillException e) { } catch (BillException e) {
throw new RuntimeException(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!