Subversion Repositories SmartDukaan

Rev

Rev 35119 | Rev 35152 | 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 com.spice.profitmandi.dao.convertor.LocalDateTimeAttributeConverter;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Set;

@Entity
@Table(name = "fofo.fofo_order_item", uniqueConstraints = {
                @UniqueConstraint(name = "UK_ORDER_ID_AND_ITEM_ID", columnNames = { "order_id", "item_id" }) })

@NamedQueries({
                @NamedQuery(name = "FofoOrderItem.selectPartnerMonthlySale", query = "select new com.spice.profitmandi.dao.model.PartnerMonthlySaleModel(fo.fofoId, "
                                + " DATE_FORMAT(foi.createTimestamp, '%m-%Y'),sum(CAST(foi.quantity*foi.mop  AS int))) from  FofoOrder fo join FofoOrderItem foi on "
                                + " fo.id = foi.orderId  where fo.fofoId in :fofoIds and fo.cancelledTimestamp is null "
                                + " and foi.createTimestamp >= :startDate"
                                + " group by fo.fofoId,DATE_FORMAT(foi.createTimestamp, '%m-%Y')"),
                @NamedQuery(
                                name = "FofoOrderItem.selectPartnerBrandItemMonthlySale",
                                query = "select new com.spice.profitmandi.dao.model.BrandItemWisePartnerSaleModel( " +
                                                "foi.brand, " +
                                                "foi.modelName, " +
                                                "foi.modelNumber, " +
                                                "sum(foi.quantity)) " +
                                                "from FofoOrder fo " +
                                                "join FofoOrderItem foi on fo.id = foi.orderId " +
                                                "join Catalog ca on ca.modelNumber = foi.modelNumber " +
                                                "where fo.fofoId in :fofoIds " +
                                                "and foi.brand =:brand " +
                                                "and fo.cancelledTimestamp is null " +
                                                "and foi.createTimestamp >= :startDate " +
                                                "and foi.createTimestamp < :endDate " +
                                                "and ca.categoryId =  10006 " +
                                                "group by foi.brand, foi.modelName, foi.modelNumber,ca.categoryId, fo.fofoId,DATE_FORMAT(foi.createTimestamp, '%m-%Y')"
                ),
        @NamedQuery(
                name = "FofoOrderItem.selectBrandItemsByRegionAndDate",
                query = "select new com.spice.profitmandi.dao.model.EligibleRewardItemsModel(" +
                        "o.fofoId, pr.regionId, o.id, li.serialNumber, oi.brand, oi.dp, oi.quantity, i.catalogItemId) " +
                        "from ActivatedImei ai " +
                        "join FofoLineItem li on li.serialNumber = ai.serialNumber " +
                        "join FofoOrderItem oi on oi.id = li.fofoOrderItemId " +
                        "join FofoOrder o on o.id = oi.orderId " +
                        "join Item i on i.id = oi.itemId " +
                        "join PartnerRegion pr on pr.fofoId = o.fofoId " +
                        "where pr.regionId = :regionId " +
                        "and i.brand = :brand " +
                        "and ai.activationTimestamp between :orderStartDate and :orderEndDate " +
                        "and not exists (select 1 from SaleRewardHistory srh where srh.imeis = ai.serialNumber) " +
                        "group by li.serialNumber"
                ),

                @NamedQuery(
                                name = "LineItem.selectPartnerBrandItemMonthlySecondarySale",
                                query = "select new com.spice.profitmandi.dao.model.BrandItemWisePartnerSaleModel( " +
                                                "i.brand, " +
                                                "i.modelName, " +
                                                "i.modelNumber, " +
                                                "sum(l.quantity)) " +
                                                "from Order o " +
                                                "join LineItem l on o.id = l.orderId " +
                                                "join Item i on i.id = l.itemId " +
                                                "join Catalog  ca on ca.modelNumber=i.modelNumber " +
                                                "where i.brand =:brand " +
                                                "and o.retailerId = :fofoIds " +
                                                "and o.billingTimestamp >= :startDate " +
                                                "and o.billingTimestamp < :endDate " +
                                                "and ca.categoryId =  10006 " +
                                                "group by i.brand, i.modelName, i.modelNumber, DATE_FORMAT(o.billingTimestamp, '%m-%Y')"
                ),
})
public class FofoOrderItem implements Serializable {

        private static final long serialVersionUID = 1L;

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

        @Column(name = "order_id")
        private int orderId;

        @Column(name = "pending_order_item_id")
        private int pendingOrderItemId;

        @Column(name = "item_id")
        private int itemId;

        @Column(name = "quantity")
        private int quantity;

        @Column(name = "selling_price")
        private float sellingPrice;

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

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

        @Column(name = "igst_rate")
        private float igstRate;

        @Column(name = "cgst_rate")
        private float cgstRate;

        @Column(name = "sgst_rate")
        private float sgstRate;

        @Column(name = "hsn_code")
        private String hsnCode;

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

        @Column(name = "brand")
        private String brand;

        @Column(name = "model_name")
        private String modelName;

        @Column(name = "model_number")
        private String modelNumber;

        @Column(name = "color")
        private String color;

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

        @Transient
        private boolean doa;

        @Transient
        private String itemName;

        public boolean isDoa() {
                return doa;
        }

        public String getItemName() {
                return itemName;
        }

        public void setItemName(String itemName) {
                this.itemName = itemName;
        }

        public void setDoa(boolean doa) {
                this.doa = doa;
        }

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

        @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
        @JoinColumn(name = "fofo_order_item_id", insertable = false, updatable = false, nullable = false)
        private Set<FofoLineItem> fofoLineItems;

        public int getId() {
                return id;
        }

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

        public int getOrderId() {
                return orderId;
        }

        public void setOrderId(int orderId) {
                this.orderId = orderId;
        }

        public int getPendingOrderItemId() {
                return pendingOrderItemId;
        }

        public void setPendingOrderItemId(int pendingOrderItemId) {
                this.pendingOrderItemId = pendingOrderItemId;
        }

        public int getItemId() {
                return itemId;
        }

        public void setItemId(int itemId) {
                this.itemId = itemId;
        }

        public int getQuantity() {
                return quantity;
        }

        public void setQuantity(int quantity) {
                this.quantity = quantity;
        }

        public float getSellingPrice() {
                return sellingPrice;
        }

        public void setSellingPrice(float sellingPrice) {
                this.sellingPrice = sellingPrice;
        }

        public float getCost() {
                return cost;
        }

        public void setCost(float cost) {
                this.cost = cost;
        }

        public float getMop() {
                return mop;
        }

        public void setMop(float mop) {
                this.mop = mop;
        }

        public float getIgstRate() {
                return igstRate;
        }

        public void setIgstRate(float igstRate) {
                this.igstRate = igstRate;
        }

        public float getCgstRate() {
                return cgstRate;
        }

        public void setCgstRate(float cgstRate) {
                this.cgstRate = cgstRate;
        }

        public float getSgstRate() {
                return sgstRate;
        }

        public void setSgstRate(float sgstRate) {
                this.sgstRate = sgstRate;
        }

        public String getHsnCode() {
                return hsnCode;
        }

        public void setHsnCode(String hsnCode) {
                this.hsnCode = hsnCode;
        }

        public float getDp() {
                return dp;
        }

        public void setDp(float dp) {
                this.dp = dp;
        }

        public String getBrand() {
                return brand;
        }

        public void setBrand(String brand) {
                this.brand = brand;
        }

        public String getModelName() {
                return modelName;
        }

        public void setModelName(String modelName) {
                this.modelName = modelName;
        }

        public String getModelNumber() {
                return modelNumber;
        }

        public void setModelNumber(String modelNumber) {
                this.modelNumber = modelNumber;
        }

        public String getColor() {
                return color;
        }

        public void setColor(String color) {
                this.color = color;
        }

        public float getDiscount() {
                return discount;
        }

        public void setDiscount(float discount) {
                this.discount = discount;
        }

        public LocalDateTime getCreateTimestamp() {
                return createTimestamp;
        }

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

        public Set<FofoLineItem> getFofoLineItems() {
                return fofoLineItems;
        }

        public void setFofoLineItems(Set<FofoLineItem> fofoLineItems) {
                this.fofoLineItems = fofoLineItems;
        }

        @Override
        public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + ((brand == null) ? 0 : brand.hashCode());
                result = prime * result + Float.floatToIntBits(cgstRate);
                result = prime * result + ((color == null) ? 0 : color.hashCode());
                result = prime * result + Float.floatToIntBits(cost);
                result = prime * result + ((createTimestamp == null) ? 0 : createTimestamp.hashCode());
                result = prime * result + Float.floatToIntBits(discount);
                result = prime * result + (doa ? 1231 : 1237);
                result = prime * result + Float.floatToIntBits(dp);
                result = prime * result + ((fofoLineItems == null) ? 0 : fofoLineItems.hashCode());
                result = prime * result + ((hsnCode == null) ? 0 : hsnCode.hashCode());
                result = prime * result + id;
                result = prime * result + Float.floatToIntBits(igstRate);
                result = prime * result + itemId;
                result = prime * result + ((itemName == null) ? 0 : itemName.hashCode());
                result = prime * result + ((modelName == null) ? 0 : modelName.hashCode());
                result = prime * result + ((modelNumber == null) ? 0 : modelNumber.hashCode());
                result = prime * result + Float.floatToIntBits(mop);
                result = prime * result + orderId;
                result = prime * result + quantity;
                result = prime * result + Float.floatToIntBits(sellingPrice);
                result = prime * result + Float.floatToIntBits(sgstRate);
                return result;
        }

        @Override
        public boolean equals(Object obj) {
                if (this == obj)
                        return true;
                if (obj == null)
                        return false;
                if (getClass() != obj.getClass())
                        return false;
                FofoOrderItem other = (FofoOrderItem) obj;
                if (brand == null) {
                        if (other.brand != null)
                                return false;
                } else if (!brand.equals(other.brand))
                        return false;
                if (Float.floatToIntBits(cgstRate) != Float.floatToIntBits(other.cgstRate))
                        return false;
                if (color == null) {
                        if (other.color != null)
                                return false;
                } else if (!color.equals(other.color))
                        return false;
                if (Float.floatToIntBits(cost) != Float.floatToIntBits(other.cost))
                        return false;
                if (createTimestamp == null) {
                        if (other.createTimestamp != null)
                                return false;
                } else if (!createTimestamp.equals(other.createTimestamp))
                        return false;
                if (Float.floatToIntBits(discount) != Float.floatToIntBits(other.discount))
                        return false;
                if (doa != other.doa)
                        return false;
                if (Float.floatToIntBits(dp) != Float.floatToIntBits(other.dp))
                        return false;
                if (fofoLineItems == null) {
                        if (other.fofoLineItems != null)
                                return false;
                } else if (!fofoLineItems.equals(other.fofoLineItems))
                        return false;
                if (hsnCode == null) {
                        if (other.hsnCode != null)
                                return false;
                } else if (!hsnCode.equals(other.hsnCode))
                        return false;
                if (id != other.id)
                        return false;
                if (Float.floatToIntBits(igstRate) != Float.floatToIntBits(other.igstRate))
                        return false;
                if (itemId != other.itemId)
                        return false;
                if (itemName == null) {
                        if (other.itemName != null)
                                return false;
                } else if (!itemName.equals(other.itemName))
                        return false;
                if (modelName == null) {
                        if (other.modelName != null)
                                return false;
                } else if (!modelName.equals(other.modelName))
                        return false;
                if (modelNumber == null) {
                        if (other.modelNumber != null)
                                return false;
                } else if (!modelNumber.equals(other.modelNumber))
                        return false;
                if (Float.floatToIntBits(mop) != Float.floatToIntBits(other.mop))
                        return false;
                if (orderId != other.orderId)
                        return false;
                if (quantity != other.quantity)
                        return false;
                if (Float.floatToIntBits(sellingPrice) != Float.floatToIntBits(other.sellingPrice))
                        return false;
                if (Float.floatToIntBits(sgstRate) != Float.floatToIntBits(other.sgstRate))
                        return false;
                return true;
        }

        @Override
        public String toString() {
                return "FofoOrderItem [id=" + id + ", orderId=" + orderId + ", itemId=" + itemId + ", quantity=" + quantity
                                + ", sellingPrice=" + sellingPrice + ", cost=" + cost + ", mop=" + mop + ", igstRate=" + igstRate
                                + ", cgstRate=" + cgstRate + ", sgstRate=" + sgstRate + ", hsnCode=" + hsnCode + ", dp=" + dp
                                + ", brand=" + brand + ", modelName=" + modelName + ", modelNumber=" + modelNumber + ", color=" + color
                                + ", discount=" + discount + ", doa=" + doa + ", itemName=" + itemName + ", createTimestamp="
                                + createTimestamp + ", fofoLineItems=" + fofoLineItems + "]";
        }

}