Subversion Repositories SmartDukaan

Rev

Rev 31730 | Rev 32615 | 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.common.enumuration.ActivationType;
import com.spice.profitmandi.common.enumuration.CounterSize;
import com.spice.profitmandi.common.enumuration.FofoType;
import com.spice.profitmandi.dao.entity.user.Address;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * This class basically contains store code details
 * 
 * @author ashikali
 *
 */
@Entity
@Table(name = "fofo.fofo_store")

@NamedQueries({

                @NamedQuery(name = "FofoStore.selectAllDtrUserIds", query = "select ua.userId from FofoStore fs join UserAccount ua on fs.id=ua.accountKey "
                                + "where ua.type='saholic' and fs.internal=false and fs.active=true"),

                @NamedQuery(name = "FofoStore.selectGroupByBrandWarehousePartnerSale", query = "select new com.spice.profitmandi.dao.model.BrandWisePartnerSaleModel(foi.brand, "
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then CAST(foi.quantity*foi.mop  AS integer ) else 0 end),"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then foi.quantity  else 0 end),"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :mtd  then CAST(foi.quantity*foi.mop  AS integer ) 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 CAST(foi.quantity*foi.mop  AS int) else 0 end), "
                                + "sum(case when foi.createTimestamp between  :lmtdStartDate and :lmtdEndDate 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 i.categoryId = :categoryId and fs.id in :fofoId"
                                + " group by foi.brand"),

                @NamedQuery(name = "FofoStore.selectGroupByWarehouseBrandWisePartnerSale", query = "select new com.spice.profitmandi.dao.model.WarehouseWiseBrandSaleModel("
                                + "(case when a.city in ('Noida', 'Ghaziabad')  and foi.brand = 'Vivo' then 7573 else fs.warehouseId end) AS col_0_0_,"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then CAST(foi.quantity*foi.mop  AS int) else 0 end),"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then foi.quantity  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 concat(year(foi.createTimestamp), month(foi.createTimestamp))= :mtd  then foi.quantity 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 :lmtdEndDate 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"
                                + " join com.spice.profitmandi.dao.entity.user.User u on u.id = fs.id join Address a on a.id = u.addressId"
                                + " where fo.cancelledTimestamp is null and fs.active = true"
                                + " and foi.createTimestamp >= :lmtdStartDate and foi.brand = :brand and i.categoryId = :categoryId and fs.id in :fofoId"
                                + " group by col_0_0_"),

                @NamedQuery(name = "FofoStore.selectWarehouseBrandItemSale", query = "select new com.spice.profitmandi.dao.model.WarehouseBrandWiseItemSaleModel(fs.warehouseId,i.id, i.brand, i.modelName, i.modelNumber,i.color,"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then CAST(foi.quantity*foi.mop  AS int) else 0 end),"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then foi.quantity  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 concat(year(foi.createTimestamp), month(foi.createTimestamp))= :mtd  then foi.quantity 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 :lmtdEndDate 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 and i.brand = :brand and i.categoryId = :categoryId and fs.id in :fofoId group by i.id"),

                @NamedQuery(name = "FofoStore.selectGroupByBrandAccesoriesWarehousePartnerSale", query = "select new com.spice.profitmandi.dao.model.BrandWisePartnerSaleModel(foi.brand, "
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then CAST(foi.quantity*foi.mop  AS int) else 0 end),"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then foi.quantity  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 concat(year(foi.createTimestamp), month(foi.createTimestamp))= :mtd  then foi.quantity 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 :lmtdEndDate 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 i.categoryId != :categoryId and fs.id in :fofoId"
                                + " group by foi.brand"),

                @NamedQuery(name = "FofoStore.selectGroupByWarehouseAccesoriesBrandWisePartnerSale", query = "select new com.spice.profitmandi.dao.model.WarehouseWiseBrandSaleModel(fs.warehouseId,"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then CAST(foi.quantity*foi.mop  AS int) else 0 end),"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then foi.quantity  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 concat(year(foi.createTimestamp), month(foi.createTimestamp))= :mtd  then foi.quantity 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 :lmtdEndDate 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 foi.brand = :brand and i.categoryId != :categoryId and fs.id in :fofoId"
                                + " group by fs.warehouseId"),

                @NamedQuery(name = "FofoStore.selectWarehouseAccesoriesBrandItemSale", query = "select new com.spice.profitmandi.dao.model.WarehouseBrandWiseItemSaleModel(fs.warehouseId,i.id, i.brand, i.modelName, i.modelNumber,i.color,"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then CAST(foi.quantity*foi.mop  AS int) else 0 end),"
                                + "sum(case when concat(year(foi.createTimestamp), month(foi.createTimestamp))= :lms then foi.quantity  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 concat(year(foi.createTimestamp), month(foi.createTimestamp))= :mtd  then foi.quantity 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 :lmtdEndDate 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 and i.brand = :brand and i.categoryId != :categoryId  and fs.id in :fofoId group by i.id"),

                @NamedQuery(name = "FofoStore.selectPartnerPendingIndentItem", query = "select new com.spice.profitmandi.dao.model.PartnerPendingIndentItemModel(o.retailerName,"
                                + " li.quantity, li.totalPrice)"
                                + " from FofoStore fs join Order o on fs.id = o.retailerId join  LineItem li on li.orderId = o.id "
                                + " where li.itemId = :itemId and fs.warehouseId = :warehouseId and o.status = 3"),

                @NamedQuery(name = "FofoStore.selectUnbilledActivateStockGroupByBrand", query = "select new com.spice.profitmandi.dao.model.BrandWiseUnbilledActivateStockModel(i.brand,"
                                + "  sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp)) = :almtd then 1 else 0 end),"
                                + "  sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp)) = :almtd then CAST(tl.sellingPrice  AS int) else 0 end))"
                                + " from FofoStore fs join InventoryItem ii on fs.id = ii.fofoId join ActivatedImei ai on ai.serialNumber = ii.serialNumber join Item i on i.id = ii.itemId join TagListing tl on tl.itemId = i.id"
                                + " where fs.active = true and ii.goodQuantity >= 1 and fs.id in :fofoId group by i.brand"),

                @NamedQuery(name = "FofoStore.selectUnbilledActivateStockGroupByWarehouse", query = "select new com.spice.profitmandi.dao.model.WarehouseWiseBrandUnbilledActivatedModel(fs.warehouseId,"
                                + "  sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp)) = :almtd then 1 else 0 end),"
                                + "  sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp)) = :almtd then CAST(tl.sellingPrice  AS int) else 0 end))"
                                + " from FofoStore fs join InventoryItem ii on fs.id = ii.fofoId join ActivatedImei ai on ai.serialNumber = ii.serialNumber join Item i on i.id = ii.itemId join TagListing tl on tl.itemId = i.id"
                                + " where fs.active = true and ii.goodQuantity >= 1 and i.brand = :brand and fs.id in :fofoId group by fs.warehouseId"),

                @NamedQuery(name = "FofoStore.selectWarehouseBrandItemUnbilledActivateStock", query = "select new com.spice.profitmandi.dao.model.WarehouseBrandItemUnbilledActivatedModel(fs.warehouseId,i.id, i.brand, i.modelName, i.modelNumber,i.color,"
                                + "  sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp)) = :almtd then 1 else 0 end),"
                                + "  sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp)) = :almtd then CAST(tl.sellingPrice  AS int) else 0 end))"
                                + " from FofoStore fs join InventoryItem ii on fs.id = ii.fofoId join ActivatedImei ai on ai.serialNumber = ii.serialNumber join Item i on i.id = ii.itemId join TagListing tl on tl.itemId = i.id"
                                + " where fs.active = true and ii.goodQuantity >= 1 and i.brand = :brand and fs.warehouseId in :warehouseId and fs.id in :fofoId  group by i.id"),

                @NamedQuery(name = "FofoStore.selectGroupByBrandLms", query = "select new com.spice.profitmandi.dao.model.BrandWiseModel(foi.brand, DATE_FORMAT(fo.createTimestamp, :groupParameter),sum(cast(foi.mop*foi.quantity As int)))"
                                + " 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 between :lmsStartDate and :endDate) and i.categoryId = :categoryId and fs.id in :fofoId and fs.warehouseId in :warehouseId"
                                + " group by foi.brand,DATE_FORMAT(fo.createTimestamp, :groupParameter)"), })

public class FofoStore implements Serializable {

        private static final long serialVersionUID = 1L;

        public FofoStore() {
        }

        @Id
        @Column(name = "id", unique = true, updatable = false)
        private int id;

        @Column(name = "code", unique = true)
        private String code;

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

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

        @Column(name = "counter_size")
        @Enumerated(EnumType.STRING)
        private CounterSize counterSize = CounterSize.TEN_LAC;

        @Column(name = "counter_potential")
        private float counterPotential;

        @Column(name = "warehouse_id")
        private int warehouseId;

        @Column(name = "minimum_investment")
        private float minimumInvestment;

        @Column(name = "grace_date")
        private LocalDate graceDate;

        @Column(name = "investment_ok")
        private boolean investmentOk;

        @Column
        private boolean active = true;

        @Column
        private String pan;

        @Transient
        private Address userAddress;

        @Column(name = "internal")
        private boolean internal;

        @Column(name = "bags_last_credited")
        private LocalDateTime bagsLastCredited;

        @Column(name = "fofo_type")
        @Enumerated(EnumType.STRING)
        private FofoType fofoType;

        @Column(name = "activation_type")
        @Enumerated(EnumType.STRING)
        private ActivationType activationType = ActivationType.BILLING_PENDING;

        @Column(name = "active_timestamp")
        private LocalDateTime activeTimeStamp;

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

        public int getTarget() {
                return target;
        }

        public void setTarget(int target) {
                this.target = target;
        }

        public ActivationType getActivationType() {
                return activationType;
        }

        public float getCounterPotential() {
                return counterPotential;
        }

        public void setCounterPotential(float counterPotential) {
                this.counterPotential = counterPotential;
        }

        public void setActivationType(ActivationType activationType) {
                this.activationType = activationType;
        }

        public LocalDateTime getBagsLastCredited() {
                return bagsLastCredited;
        }

        public void setBagsLastCredited(LocalDateTime bagsLastCredited) {
                this.bagsLastCredited = bagsLastCredited;
        }

        public boolean isInternal() {
                return internal;
        }

        public void setInternal(boolean internal) {
                this.internal = internal;
        }

        public int getWarehouseId() {
                return warehouseId;
        }

        public void setWarehouseId(int warehouseId) {
                this.warehouseId = warehouseId;
        }

        public boolean isInvestmentOk() {
                return investmentOk;
        }

        public void setInvestmentOk(boolean investmentOk) {
                this.investmentOk = investmentOk;
        }

        @Column(name = "grace_count")
        private int graceCount;

        public String getPan() {
                return pan;
        }

        public void setPan(String pan) {
                this.pan = pan;
        }

        public int getGraceCount() {
                return graceCount;
        }

        public boolean isActive() {
                return active;
        }

        public void setActive(boolean active) {
                this.active = active;
        }

        public void setGraceCount(int graceCount) {
                this.graceCount = graceCount;
        }

        public LocalDate getGraceDate() {
                return graceDate;
        }

        public void setGraceDate(LocalDate graceDate) {
                this.graceDate = graceDate;
        }

        public float getMinimumInvestment() {
                return minimumInvestment;
        }

        public void setMinimumInvestment(float minimumInvestment) {
                this.minimumInvestment = minimumInvestment;
        }

        /*
         * public int getCreditCycle() { return creditCycle; } public void
         * setCreditCycle(int creditCycle) { this.creditCycle = creditCycle; }
         */
        public CounterSize getCounterSize() {
                return counterSize;
        }

        public void setCounterSize(CounterSize counterSize) {
                this.counterSize = counterSize;
        }

        public int getId() {
                return id;
        }

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

        public String getCode() {
                return code;
        }

        public void setCode(String code) {
                this.code = code;
        }

        public String getLatitude() {
                return latitude;
        }

        public void setLatitude(String latitude) {
                this.latitude = latitude;
        }

        public String getLongitude() {
                return longitude;
        }

        public void setLongitude(String longitude) {
                this.longitude = longitude;
        }

        public Address getUserAddress() {
                return userAddress;
        }

        public void setUserAddress(Address userAddress) {
                this.userAddress = userAddress;
        }

        public LocalDateTime getActiveTimeStamp() {
                return activeTimeStamp;
        }

        public void setActiveTimeStamp(LocalDateTime activeTimeStamp) {
                this.activeTimeStamp = activeTimeStamp;
        }

        public FofoType getFofoType() {
                return fofoType;
        }

        public void setFofoType(FofoType fofoType) {
                this.fofoType = fofoType;
        }

        @Override
        public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + ((activationType == null) ? 0 : activationType.hashCode());
                result = prime * result + (active ? 1231 : 1237);
                result = prime * result + ((activeTimeStamp == null) ? 0 : activeTimeStamp.hashCode());
                result = prime * result + ((bagsLastCredited == null) ? 0 : bagsLastCredited.hashCode());
                result = prime * result + ((code == null) ? 0 : code.hashCode());
                result = prime * result + Float.floatToIntBits(counterPotential);
                result = prime * result + ((counterSize == null) ? 0 : counterSize.hashCode());
                result = prime * result + ((fofoType == null) ? 0 : fofoType.hashCode());
                result = prime * result + graceCount;
                result = prime * result + ((graceDate == null) ? 0 : graceDate.hashCode());
                result = prime * result + id;
                result = prime * result + (internal ? 1231 : 1237);
                result = prime * result + (investmentOk ? 1231 : 1237);
                result = prime * result + ((latitude == null) ? 0 : latitude.hashCode());
                result = prime * result + ((longitude == null) ? 0 : longitude.hashCode());
                result = prime * result + Float.floatToIntBits(minimumInvestment);
                result = prime * result + ((pan == null) ? 0 : pan.hashCode());
                result = prime * result + ((userAddress == null) ? 0 : userAddress.hashCode());
                result = prime * result + warehouseId;
                return result;
        }

        @Override
        public boolean equals(Object obj) {
                if (this == obj)
                        return true;
                if (obj == null)
                        return false;
                if (getClass() != obj.getClass())
                        return false;
                FofoStore other = (FofoStore) obj;
                if (activationType != other.activationType)
                        return false;
                if (active != other.active)
                        return false;
                if (activeTimeStamp == null) {
                        if (other.activeTimeStamp != null)
                                return false;
                } else if (!activeTimeStamp.equals(other.activeTimeStamp))
                        return false;
                if (bagsLastCredited == null) {
                        if (other.bagsLastCredited != null)
                                return false;
                } else if (!bagsLastCredited.equals(other.bagsLastCredited))
                        return false;
                if (code == null) {
                        if (other.code != null)
                                return false;
                } else if (!code.equals(other.code))
                        return false;
                if (Float.floatToIntBits(counterPotential) != Float.floatToIntBits(other.counterPotential))
                        return false;
                if (counterSize != other.counterSize)
                        return false;
                if (fofoType != other.fofoType)
                        return false;
                if (graceCount != other.graceCount)
                        return false;
                if (graceDate == null) {
                        if (other.graceDate != null)
                                return false;
                } else if (!graceDate.equals(other.graceDate))
                        return false;
                if (id != other.id)
                        return false;
                if (internal != other.internal)
                        return false;
                if (investmentOk != other.investmentOk)
                        return false;
                if (latitude == null) {
                        if (other.latitude != null)
                                return false;
                } else if (!latitude.equals(other.latitude))
                        return false;
                if (longitude == null) {
                        if (other.longitude != null)
                                return false;
                } else if (!longitude.equals(other.longitude))
                        return false;
                if (Float.floatToIntBits(minimumInvestment) != Float.floatToIntBits(other.minimumInvestment))
                        return false;
                if (pan == null) {
                        if (other.pan != null)
                                return false;
                } else if (!pan.equals(other.pan))
                        return false;
                if (userAddress == null) {
                        if (other.userAddress != null)
                                return false;
                } else if (!userAddress.equals(other.userAddress))
                        return false;
                if (warehouseId != other.warehouseId)
                        return false;
                return true;
        }

        @Override
        public String toString() {
                return "FofoStore [id=" + id + ", code=" + code + ", latitude=" + latitude + ", longitude=" + longitude
                                + ", counterSize=" + counterSize + ", counterPotential=" + counterPotential + ", warehouseId="
                                + warehouseId + ", minimumInvestment=" + minimumInvestment + ", graceDate=" + graceDate
                                + ", investmentOk=" + investmentOk + ", active=" + active + ", pan=" + pan + ", userAddress="
                                + userAddress + ", internal=" + internal + ", bagsLastCredited=" + bagsLastCredited + ", fofoType="
                                + fofoType + ", activationType=" + activationType + ", activeTimeStamp=" + activeTimeStamp
                                + ", graceCount=" + graceCount + "]";
        }

}