Subversion Repositories SmartDukaan

Rev

Rev 34212 | Rev 34498 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.dao.entity.transaction;

import com.spice.profitmandi.dao.model.DailyStatementModel;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "transaction.loan")
@NamedQueries({
                @NamedQuery(name = "Loan.getLoansCountWithFofoID", query = "select new com.spice.profitmandi.dao.model.LoanCountByFofoIdModel(" +
                                " cast(fofoId as int), count(id))" +
                                " from Loan " +
                                " where fofoId in (:fofoIds) " +
                                " group by fofoId "),

                @NamedQuery(name = "Loan.findBlockedLoans", query = "SELECT l FROM Loan l WHERE l.freeDays > 364"),

                @NamedQuery(name= "Loan.getDueLoansByFofoId", query = "SELECT new com.spice.profitmandi.dao.model.loan.TotalLoanAmountDueModel(ls.id, l.pendingAmount, SUM(ls.amount)) " +
                                "FROM Loan l JOIN LoanStatement ls on ls.loanId=l.id " +
                                "WHERE l.fofoId = :fofoId AND l.pendingAmount > 0 " +
                                "GROUP BY ls.loanId")
})

public class Loan {

        @Id
        @Column(name = "id", unique = true, updatable = false)
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private int id;

        @Column(name = "fofo_id")
        private int fofoId;

        @Column(name = "interest_rate")
        private BigDecimal interestRate;

        @Column(name = "intial_amount")
        private BigDecimal intialAmount;

        @Column(name = "pending_amount")
        private BigDecimal pendingAmount;

        @Column(name = "created_on")
        private LocalDateTime createdOn;

        @Column(name = "settled_on")
        private LocalDateTime settledOn;

        @Column(name = "due_date")
        private LocalDateTime dueDate;

        @Column(name = "interest_accured")
        private BigDecimal interestAccrued;

        @Column(name = "interest_paid")
        private BigDecimal interestPaid;

        @Column(name = "free_days")
        private int freeDays;

        @Transient
        private boolean loanStatus;

        @Transient
        private BigDecimal totalPending;

        public long getDays() {
                return ChronoUnit.DAYS.between(this.getCreatedOn().toLocalDate(), LocalDateTime.now()) + 1;
        }

        public boolean isDue() {
                return this.getSettledOn()==null && !this.getDueDate().toLocalDate().isBefore(LocalDate.now());
        }

        public boolean isOverdue() {
                return this.getSettledOn()==null && this.getDueDate().toLocalDate().isBefore(LocalDate.now()) &&
                                !this.getDueDate().plusDays(15).toLocalDate().isBefore(LocalDate.now());
        }

        public boolean isDefault() {
                return this.getSettledOn()==null && this.getDueDate().plusDays(15).toLocalDate().isBefore(LocalDate.now());
        }

        @Transient
        private List<DailyStatementModel> dailyStatementModel;

        public int getId() {
                return id;
        }

        public void setId(int id) {
                this.id = id;
        }

        public BigDecimal getTotalPending() {
                return totalPending;
        }

        public void setTotalPending(BigDecimal totalPending) {
                this.totalPending = totalPending;
        }

        public int getFofoId() {
                return fofoId;
        }

        public void setFofoId(int fofoId) {
                this.fofoId = fofoId;
        }

        public BigDecimal getInterestRate() {
                return interestRate;
        }

        public void setInterestRate(BigDecimal interestRate) {
                this.interestRate = interestRate;
        }

        public BigDecimal getIntialAmount() {
                return intialAmount;
        }

        public void setIntialAmount(BigDecimal intialAmount) {
                this.intialAmount = intialAmount;
        }

        public BigDecimal getPendingAmount() {
                return pendingAmount;
        }

        public void setPendingAmount(BigDecimal pendingAmount) {
                this.pendingAmount = pendingAmount;
        }

        public LocalDateTime getCreatedOn() {
                return createdOn;
        }

        public void setCreatedOn(LocalDateTime createdOn) {
                this.createdOn = createdOn;
        }

        public LocalDateTime getDueDate() {
                return dueDate;
        }

        public void setDueDate(LocalDateTime dueDate) {
                this.dueDate = dueDate;
        }

        public BigDecimal getInterestAccrued() {
                return interestAccrued;
        }

        public void setInterestAccrued(BigDecimal interestAccrued) {
                this.interestAccrued = interestAccrued;
        }

        public BigDecimal getInterestPaid() {
                return interestPaid;
        }

        public void setInterestPaid(BigDecimal interestPaid) {
                this.interestPaid = interestPaid;
        }

        public int getFreeDays() {
                return freeDays;
        }

        public void setFreeDays(int freeDays) {
                this.freeDays = freeDays;
        }

        public List<DailyStatementModel> getDailyStatementModel() {
                return dailyStatementModel;
        }

        public void setDailyStatementModel(List<DailyStatementModel> dailyStatementModel) {
                this.dailyStatementModel = dailyStatementModel;
        }

        public boolean isLimit() {
                return this.getFreeDays() >= 365;
        }

        @Override
        public String toString() {
                return "Loan{" +
                                "id=" + id +
                                ", fofoId=" + fofoId +
                                ", interestRate=" + interestRate +
                                ", intialAmount=" + intialAmount +
                                ", pendingAmount=" + pendingAmount +
                                ", createdOn=" + createdOn +
                                ", settledOn=" + settledOn +
                                ", dueDate=" + dueDate +
                                ", interestAccrued=" + interestAccrued +
                                ", interestPaid=" + interestPaid +
                                ", freeDays=" + freeDays +
                                ", loanStatus=" + loanStatus +
                                ", totalPending=" + totalPending +
                                ", dailyStatementModel=" + dailyStatementModel +
                                '}';
        }

        @Override
        public boolean equals(Object o) {
                if (this == o) return true;
                if (o == null || getClass() != o.getClass()) return false;
                Loan loan = (Loan) o;
                return id == loan.id && fofoId == loan.fofoId && freeDays == loan.freeDays && loanStatus == loan.loanStatus && Objects.equals(interestRate, loan.interestRate) && Objects.equals(intialAmount, loan.intialAmount) && Objects.equals(pendingAmount, loan.pendingAmount) && Objects.equals(createdOn, loan.createdOn) && Objects.equals(settledOn, loan.settledOn) && Objects.equals(dueDate, loan.dueDate) && Objects.equals(interestAccrued, loan.interestAccrued) && Objects.equals(interestPaid, loan.interestPaid) && Objects.equals(totalPending, loan.totalPending) && Objects.equals(dailyStatementModel, loan.dailyStatementModel);
        }

        @Override
        public int hashCode() {
                return Objects.hash(id, fofoId, interestRate, intialAmount, pendingAmount, createdOn, settledOn, dueDate, interestAccrued, interestPaid, freeDays, loanStatus, totalPending, dailyStatementModel);
        }

        public LocalDateTime getSettledOn() {
                return settledOn;
        }

        public void setSettledOn(LocalDateTime settledOn) {
                this.settledOn = settledOn;
        }

        public boolean isLoanStatus() {
                return loanStatus;
        }

        public void setLoanStatus(boolean loanStatus) {
                this.loanStatus = loanStatus;
        }

}