Subversion Repositories SmartDukaan

Rev

Rev 30958 | 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.convertor.LocalDateTimeAttributeConverter;

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

/**
 * This class basically contains details
 *
 * @author ashikali
 */

/**
 * @author amit
 *
 */
@Entity
@Table(name = "transaction.price_drop")

@NamedQueries(value = {
                @NamedQuery(name = "PriceDrop.selectBrandPendingPriceDropByYearMonth", query = "select new com.spice.profitmandi.dao.model.PriceDropYearMonthModel(i.brand, "
                                + "   DATE_FORMAT(pd.affectedOn, '%m-%Y'),sum(cast(pd.amount As  integer )) ) from PriceDrop pd join  PriceDropIMEI pdi  on"
                                + " (pd.id = pdi.priceDropId) join InventoryItem it  on (pdi.imei = it.serialNumber and pdi.partnerId=it.fofoId)"
                                + " join Item i on i.id = it.itemId where pdi.status ='PENDING' and pdi.partnerId = :fofoId and "
                                + " pd.amount > 0 and pd.affectedOn >= :startDate group by i.brand, DATE_FORMAT(pd.affectedOn, '%m-%Y')"),

                @NamedQuery(name = "PriceDrop.selectSixMonthBrandPriceDropByYearMonth", query = "select new com.spice.profitmandi.dao.model.PriceDropBrandModel(i.brand, "
                                + " sum(cast(pd.amount As integer )) ) from PriceDrop pd join  PriceDropIMEI pdi  on"
                                + " (pd.id = pdi.priceDropId) join InventoryItem it on (pdi.imei = it.serialNumber and pdi.partnerId=it.fofoId)"
                                + " join Item i on i.id = it.itemId where pdi.status ='PENDING' and pdi.partnerId = :fofoId and "
                                + " pd.amount > 0 and pd.affectedOn >= :startDate and pd.affectedOn <= :endDate group by i.brand"),


                @NamedQuery(name = "PriceDrop.selectBrandPendingPriceDropWithDetailsByYearMonth", query = "select new com.spice.profitmandi.dao.model.PriceDropWithDetailsByYearMonthModel(i.brand, "
                                + "  i.modelName,i.modelNumber,cast(pd.amount As integer ),pdi.imei ) from PriceDrop pd join  PriceDropIMEI pdi  on"
                                + " (pd.id = pdi.priceDropId) join InventoryItem it  on (pdi.imei = it.serialNumber and pdi.partnerId=it.fofoId)"
                                + " join Item i on i.id = it.itemId where pdi.status ='PENDING' and pdi.partnerId = :fofoId and "
                                + " pd.amount > 0  and i.brand = :brand and DATE_FORMAT(pd.affectedOn, '%m-%Y') = :yearMonthValue"),

                @NamedQuery(name = "PriceDrop.selectBrandPendingPriceDropWithDetailsAndSixMonth", query = "select new com.spice.profitmandi.dao.model.PriceDropWithDetailsByYearMonthModel(i.brand, "
                                + "  i.modelName,i.modelNumber,cast(pd.amount As integer ),pdi.imei ) from PriceDrop pd join  PriceDropIMEI pdi  on"
                                + " (pd.id = pdi.priceDropId) join InventoryItem it  on (pdi.imei = it.serialNumber and pdi.partnerId=it.fofoId)"
                                + " join Item i on i.id = it.itemId where pdi.status ='PENDING' and pdi.partnerId = :fofoId and "
                                + " pd.amount > 0  and i.brand = :brand and pd.affectedOn >= :startDate and pd.affectedOn <= :endDate"),


})
public class PriceDrop implements Serializable {

        private static final long serialVersionUID = 1L;

        public PriceDrop() {
        }

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

        @Column(name = "catalog_id")
        private int catalogItemId;

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

        @Column(name = "new_dp")
        private float newDp;

        @Column(name = "old_dp")
        private float oldDp;

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

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

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

        @Transient
        private String description;

        public String getDescription() {
                return description;
        }

        public void setDescription(String description) {
                this.description = description;
        }

        public float getMop() {
                return mop;
        }

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

        public float getNewDp() {
                return newDp;
        }

        public void setNewDp(float newDp) {
                this.newDp = newDp;
        }

        public float getOldDp() {
                return oldDp;
        }

        public void setOldDp(float oldDp) {
                this.oldDp = oldDp;
        }

        public float getTp() {
                return tp;
        }

        public void setTp(float tp) {
                this.tp = tp;
        }

        public float getNlc() {
                return nlc;
        }

        public void setNlc(float nlc) {
                this.nlc = nlc;
        }


        @Column(name = "credit_note_number")
        private String creditNoteNumber;

        @Convert(converter = LocalDateTimeAttributeConverter.class)
        @Column(name = "process_timestamp")
        private LocalDateTime processTimestamp;

        @Convert(converter = LocalDateTimeAttributeConverter.class)
        @Column(name = "complete_timestamp")
        private LocalDateTime completeTimestamp;

        @Column(name = "price_drop_in")
        private float priceDropIn;

        @Column(name = "partner_payout")
        private float partnerPayout;

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

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

        @Convert(converter = LocalDateTimeAttributeConverter.class)
        @Column(name = "credit_note_date")
        private LocalDateTime creditNoteDate;

        public int getId() {
                return id;
        }

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

        public float getPriceDropIn() {
                return priceDropIn;
        }

        public void setPriceDropIn(float priceDropIn) {
                this.priceDropIn = priceDropIn;
        }

        public int getCatalogItemId() {
                return catalogItemId;
        }

        public void setCatalogItemId(int catalogItemId) {
                this.catalogItemId = catalogItemId;
        }

        @Override
        public String toString() {
                return "PriceDrop [id=" + id + ", catalogItemId=" + catalogItemId + ", amount=" + amount + ", newDp=" + newDp
                                + ", oldDp=" + oldDp + ", mop=" + mop + ", tp=" + tp + ", nlc=" + nlc + ", description=" + description
                                + ", creditNoteNumber=" + creditNoteNumber + ", processTimestamp=" + processTimestamp
                                + ", completeTimestamp=" + completeTimestamp + ", priceDropIn=" + priceDropIn + ", partnerPayout="
                                + partnerPayout + ", createdOn=" + createdOn + ", affectedOn=" + affectedOn + ", creditNoteDate="
                                + creditNoteDate + "]";
        }

        public float getAmount() {
                return amount;
        }

        public void setAmount(float amount) {
                this.amount = amount;
        }

        public LocalDateTime getProcessTimestamp() {
                return processTimestamp;
        }

        public void setProcessTimestamp(LocalDateTime processTimestamp) {
                this.processTimestamp = processTimestamp;
        }

        public String getCreditNoteNumber() {
                return creditNoteNumber;
        }

        public void setCreditNoteNumber(String creditNoteNumber) {
                this.creditNoteNumber = creditNoteNumber;
        }

        public LocalDateTime getCreatedOn() {
                return createdOn;
        }

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

        public LocalDateTime getAffectedOn() {
                return affectedOn;
        }

        public void setAffectedOn(LocalDateTime affectedOn) {
                this.affectedOn = affectedOn;
        }

        public LocalDateTime getCreditNoteDate() {
                return creditNoteDate;
        }

        public void setCreditNoteDate(LocalDateTime creditNoteDate) {
                this.creditNoteDate = creditNoteDate;
        }

        public float getPartnerPayout() {
                return partnerPayout;
        }

        public float getDropAmount() {
                return oldDp - newDp;
        }

        public float getAutoPartnerPayout(LocalDateTime creditDate) {
                if (creditDate.toLocalDate().isAfter(LocalDate.of(2022, 9, 15))) {
                        return this.getDropAmount();
                } else {
                        if (this.getPartnerPayout() == 0) {
                                return this.getDropAmount() / 1.18f;
                        } else {
                                return this.getPartnerPayout();
                        }
                }
        }

        public void setPartnerPayout(float partnerPayout) {
                this.partnerPayout = partnerPayout;
        }

        public String getDate(LocalDateTime ldt) {
                DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
                String s = dtf.format(ldt);
                return s;
        }

        public LocalDateTime getCompleteTimestamp() {
                return completeTimestamp;
        }

        public void setCompleteTimestamp(LocalDateTime completeTimestamp) {
                this.completeTimestamp = completeTimestamp;
        }

        @Override
        public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + id;
                return result;
        }

        @Override
        public boolean equals(Object obj) {
                if (this == obj)
                        return true;
                if (obj == null)
                        return false;
                if (getClass() != obj.getClass())
                        return false;
                PriceDrop other = (PriceDrop) obj;
                if (id != other.id)
                        return false;
                return true;
        }

}