Subversion Repositories SmartDukaan

Rev

Rev 27738 | Rev 27884 | 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.fofo;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.spice.profitmandi.dao.convertor.LocalDateTimeAttributeConverter;

@Entity
@Table(name = "fofo.fofo_order", schema = "fofo")

@NamedQueries({

                @NamedQuery(name = "FofoOrder.SelectItemWiseTertiary", query = "select new com.spice.profitmandi.dao.model.ItemWiseTertiaryModel(foi.brand,"
                                + "foi.modelName, foi.modelNumber, foi.color, foi.quantity, foi.mop)"
                                + " from FofoOrder fo join FofoOrderItem foi on fo.id = foi.orderId where fo.cancelledTimestamp is null and fo.fofoId = :fofoId"
                                + " and fo.createTimestamp between :startDate and :endDate"),

                @NamedQuery(name = "FofoOrder.selectGroupByBrandPartnerTertiary", query = "select new com.spice.profitmandi.dao.model.BrandWiseTertiaryModel(foi.brand, "
                                + "sum(case when foi.createTimestamp >= :today then CAST(foi.quantity*foi.mop  AS int) else 0 end),"
                                + "sum(case when foi.createTimestamp >= :threedays  and foi.createTimestamp < :endDate  then CAST(foi.quantity*foi.mop  AS int) else 0 end),"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :mtd  then CAST(foi.quantity*foi.mop  AS int) else 0 end),"
                                + "sum(case when foi.createTimestamp between  :lmtdStartDate and :lmtdEndDate  then CAST(foi.quantity*foi.mop  AS int) else 0 end),"
                                + "sum(case when foi.createTimestamp between  :lmtdStartDate and :lmsEndDate  then CAST(foi.quantity*foi.mop  AS int) else 0 end),"
                                + "sum(case when foi.createTimestamp >= :today then foi.quantity else 0 end),"
                                + "sum(case when foi.createTimestamp >= :threedays and foi.createTimestamp < :endDate then foi.quantity else 0 end),"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :mtd  then foi.quantity else 0 end), "
                                + "sum(case when foi.createTimestamp between  :lmtdStartDate and :lmtdEndDate then foi.quantity else 0 end),"
                                + "sum(case when foi.createTimestamp between  :lmtdStartDate and :lmsEndDate  then foi.quantity else 0 end)"
                                + "     )"
                                + " from FofoStore fs join FofoOrder fo on fs.id = fo.fofoId join FofoOrderItem foi on foi.orderId = fo.id  join Item i on i.id = foi.itemId "
                                + "  where fo.cancelledTimestamp is null and fs.active = true "
                                + " and foi.createTimestamp >= :lmtdStartDate and fs.warehouseId in :warehouseId"
                                + " group by foi.brand "),

                @NamedQuery(name = "FofoOrder.selectItemPartnerTertiaryByBrand", query = "select new com.spice.profitmandi.dao.model.BrandItemWiseTertiaryModel(foi.brand, i.modelName,"
                                + " i.modelNumber, i.color, foi.quantity*foi.mop, foi.quantity)"
                                + " from FofoStore fs join FofoOrder fo on fs.id = fo.fofoId join FofoOrderItem foi on foi.orderId = fo.id  join "
                                + " Item i on i.id = foi.itemId where fo.cancelledTimestamp is null and fs.active = true "
                                + " and foi.createTimestamp >= :startDate and foi.createTimestamp < :endDate and fs.warehouseId in :warehouseId and foi.brand in :brand order by foi.itemId desc"),

                @NamedQuery(name = "FofoOrder.selectTodayItemPartnerTertiaryByBrand", query = "select new com.spice.profitmandi.dao.model.BrandItemWiseTertiaryModel(foi.brand, i.modelName,"
                                + " i.modelNumber, i.color, foi.quantity*foi.mop, foi.quantity)"
                                + " from FofoStore fs join FofoOrder fo on fs.id = fo.fofoId join FofoOrderItem foi on foi.orderId = fo.id  join "
                                + " Item i on i.id = foi.itemId where fo.cancelledTimestamp is null and fs.active = true "
                                + " and foi.createTimestamp >= :startDate and fs.warehouseId in :warehouseId and foi.brand in :brand order by foi.itemId desc"),

})
public class FofoOrder implements Serializable {

        private static final long serialVersionUID = 1L;

        @Id
        @Column(name = "id")
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private int id;

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

        @Column(name = "customer_id")
        private int customerId;

        @Column(name = "customer_address_id")
        private int customerAddressId;

        @Column(name = "customer_gst_number")
        private String customerGstNumber;

        @Column(name = "total_amount")
        private float totalAmount;

        @Column(name = "invoice_number", length = 50)
        private String invoiceNumber;

        @Column(name = "cashback")
        private float cashback;

        @Convert(converter = LocalDateTimeAttributeConverter.class)
        @Column(name = "create_timestamp")
        private LocalDateTime createTimestamp = LocalDateTime.now();

        @Convert(converter = LocalDateTimeAttributeConverter.class)
        @Column(name = "cancelled_timestamp")
        private LocalDateTime cancelledTimestamp;

        // @Convert(converter = LocalDateTimeAttributeConverter.class)
        // @Column(name = "billing_timestamp")
        @Transient
        private LocalDateTime billingTimestamp;

        @Transient
        private FofoOrderItem orderItem;

        @Transient
        private LocalDate dateOfBirth;

        public LocalDate getDateOfBirth() {
                return dateOfBirth;
        }

        public void setDateOfBirth(LocalDate dateOfBirth) {
                this.dateOfBirth = dateOfBirth;
        }

        public FofoOrderItem getOrderItem() {
                return orderItem;
        }

        public void setOrderItem(FofoOrderItem orderItem) {
                this.orderItem = orderItem;
        }

        public LocalDateTime getCancelledTimestamp() {
                return cancelledTimestamp;
        }

        public void setCancelledTimestamp(LocalDateTime cancelledTimestamp) {
                this.cancelledTimestamp = cancelledTimestamp;
        }

        public int getId() {
                return id;
        }

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

        public int getFofoId() {
                return fofoId;
        }

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

        public int getCustomerId() {
                return customerId;
        }

        public void setCustomerId(int customerId) {
                this.customerId = customerId;
        }

        public int getCustomerAddressId() {
                return customerAddressId;
        }

        public void setCustomerAddressId(int customerAddressId) {
                this.customerAddressId = customerAddressId;
        }

        public String getCustomerGstNumber() {
                return customerGstNumber;
        }

        public void setCustomerGstNumber(String customerGstNumber) {
                this.customerGstNumber = customerGstNumber;
        }

        public float getTotalAmount() {
                return totalAmount;
        }

        public void setTotalAmount(float totalAmount) {
                this.totalAmount = totalAmount;
        }

        public String getInvoiceNumber() {
                return invoiceNumber;
        }

        public void setInvoiceNumber(String invoiceNumber) {
                this.invoiceNumber = invoiceNumber;
        }

        public float getCashback() {
                return cashback;
        }

        public void setCashback(float cashback) {
                this.cashback = cashback;
        }

        public LocalDateTime getCreateTimestamp() {
                return createTimestamp;
        }

        public void setCreateTimestamp(LocalDateTime createTimestamp) {
                this.createTimestamp = createTimestamp;
        }

        public String getFormattedDate() {
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
                return this.createTimestamp.format(formatter);
        }

        @Override
        public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + ((billingTimestamp == null) ? 0 : billingTimestamp.hashCode());
                result = prime * result + ((cancelledTimestamp == null) ? 0 : cancelledTimestamp.hashCode());
                result = prime * result + Float.floatToIntBits(cashback);
                result = prime * result + ((createTimestamp == null) ? 0 : createTimestamp.hashCode());
                result = prime * result + customerAddressId;
                result = prime * result + ((customerGstNumber == null) ? 0 : customerGstNumber.hashCode());
                result = prime * result + customerId;
                result = prime * result + ((dateOfBirth == null) ? 0 : dateOfBirth.hashCode());
                result = prime * result + fofoId;
                result = prime * result + id;
                result = prime * result + ((invoiceNumber == null) ? 0 : invoiceNumber.hashCode());
                result = prime * result + ((orderItem == null) ? 0 : orderItem.hashCode());
                result = prime * result + Float.floatToIntBits(totalAmount);
                return result;
        }

        @Override
        public boolean equals(Object obj) {
                if (this == obj)
                        return true;
                if (obj == null)
                        return false;
                if (getClass() != obj.getClass())
                        return false;
                FofoOrder other = (FofoOrder) obj;
                if (billingTimestamp == null) {
                        if (other.billingTimestamp != null)
                                return false;
                } else if (!billingTimestamp.equals(other.billingTimestamp))
                        return false;
                if (cancelledTimestamp == null) {
                        if (other.cancelledTimestamp != null)
                                return false;
                } else if (!cancelledTimestamp.equals(other.cancelledTimestamp))
                        return false;
                if (Float.floatToIntBits(cashback) != Float.floatToIntBits(other.cashback))
                        return false;
                if (createTimestamp == null) {
                        if (other.createTimestamp != null)
                                return false;
                } else if (!createTimestamp.equals(other.createTimestamp))
                        return false;
                if (customerAddressId != other.customerAddressId)
                        return false;
                if (customerGstNumber == null) {
                        if (other.customerGstNumber != null)
                                return false;
                } else if (!customerGstNumber.equals(other.customerGstNumber))
                        return false;
                if (customerId != other.customerId)
                        return false;
                if (dateOfBirth == null) {
                        if (other.dateOfBirth != null)
                                return false;
                } else if (!dateOfBirth.equals(other.dateOfBirth))
                        return false;
                if (fofoId != other.fofoId)
                        return false;
                if (id != other.id)
                        return false;
                if (invoiceNumber == null) {
                        if (other.invoiceNumber != null)
                                return false;
                } else if (!invoiceNumber.equals(other.invoiceNumber))
                        return false;
                if (orderItem == null) {
                        if (other.orderItem != null)
                                return false;
                } else if (!orderItem.equals(other.orderItem))
                        return false;
                if (Float.floatToIntBits(totalAmount) != Float.floatToIntBits(other.totalAmount))
                        return false;
                return true;
        }

        @Override
        public String toString() {
                return "FofoOrder [id=" + id + ", fofoId=" + fofoId + ", customerId=" + customerId + ", customerAddressId="
                                + customerAddressId + ", customerGstNumber=" + customerGstNumber + ", totalAmount=" + totalAmount
                                + ", invoiceNumber=" + invoiceNumber + ", cashback=" + cashback + ", createTimestamp=" + createTimestamp
                                + ", cancelledTimestamp=" + cancelledTimestamp + ", billingTimestamp=" + billingTimestamp
                                + ", orderItem=" + orderItem + ", dateOfBirth=" + dateOfBirth + "]";
        }

}