Subversion Repositories SmartDukaan

Rev

Rev 35365 | Rev 35426 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Objects;


@NamedQueries({
        @NamedQuery(name = "Catalog.findOtherORNullCategoryAndInStock", query = "select i.catalogItemId "
                + " from WarehouseInventoryItem wi "
                + " join Item i on i.id = wi.itemId"
                + " left join CategorisedCatalog cc on cc.catalogId = i.catalogItemId and cc.endDate is null "
                + " where ((cc.status is null OR cc.status = 'OTHER' OR cc.status = 'SLOWMOVING')) and i.categoryId in (10006,10009,10010) and i.brand= :brand group by i.catalogItemId having sum(wi.currentQuantity) > 0"),

        @NamedQuery(name = "Catalog.findOtherORNullCategoryAndPartnerInStock", query = "select i.catalogItemId "
                + " from CurrentInventorySnapshot cis "
                + " join Item i on i.id = cis.itemId"
                + " left join CategorisedCatalog cc on cc.catalogId = i.catalogItemId and cc.endDate is null "
                + " where  ((cc.status is null OR cc.status = 'OTHER' OR cc.status = 'SLOWMOVING')) and i.categoryId in (10006,10009,10010) and i.brand= :brand and cis.fofoId = :fofoId group by i.catalogItemId having sum(cis.availability) > 0"),

        @NamedQuery(name = "Catalog.findAllWithEOLWithOutStock", query = "select i.catalogItemId "
                + " from Item i "
                + " left join  WarehouseInventoryItem wi on i.id = wi.itemId"
                + " left join CategorisedCatalog cc on cc.catalogId = i.catalogItemId and cc.endDate is null "
                + " where ((cc.status is null OR cc.status = 'OTHER' OR cc.status = 'SLOWMOVING')) and i.categoryId in (10006,10009,10010) and wi.lastScanType not in (:scanTypes) group by i.catalogItemId having (sum(wi.currentQuantity) = 0 OR sum(wi.currentQuantity) IS NULL)"),

})

@Entity
@Table(name = "catalog.catalog")
public class Catalog {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", columnDefinition = "int(11)")
    private int id;

    @Column(name="brand_id")
    private int brandId;

    @Column
    private String brand;

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

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

    @Column(name = "category_id")
    private int categoryId;

    @Column(name="created_by")
    private String createdBy;

    @Column
    private LocalDateTime created;

    public int getId() {
        return id;
    }

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

    public int getBrandId() {
        return brandId;
    }

    public void setBrandId(int brandId) {
        this.brandId = brandId;
    }

    public String getBrand() {
        return brand;
    }

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

    public String getModelNumber() {
        return modelNumber;
    }

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

    public String getModelName() {
        return modelName;
    }

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

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public LocalDateTime getCreated() {
        return created;
    }

    public void setCreated(LocalDateTime created) {
        this.created = created;
    }

    public int getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(int categoryId) {
        this.categoryId = categoryId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Catalog catalog = (Catalog) o;
        return id == catalog.id && brandId == catalog.brandId && categoryId == catalog.categoryId && Objects.equals(brand, catalog.brand) && Objects.equals(modelNumber, catalog.modelNumber) && Objects.equals(modelName, catalog.modelName) && Objects.equals(createdBy, catalog.createdBy) && Objects.equals(created, catalog.created);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, brandId, brand, modelNumber, modelName, categoryId, createdBy, created);
    }

    public String getDescription() {
        StringBuilder itemString = new StringBuilder();
        if (this.getBrand() != null && !this.getBrand().isEmpty()) {
            itemString.append(this.getBrand().trim());
        }
        itemString.append(" ");
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
            itemString.append(this.getModelName().trim());
        }
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
            itemString.append(" ");
            itemString.append(this.getModelNumber().trim());
        }

        return itemString.toString().replaceAll("\\s+", " ").trim();
    }

    public String getDescriptionNoBrand() {
        StringBuilder itemString = new StringBuilder();
        itemString.append(" ");
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
            itemString.append(this.getModelName().trim());
        }
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
            itemString.append(" ");
            itemString.append(this.getModelNumber().trim());
        }

        return itemString.toString().replaceAll("\\s+", " ").trim();
    }

    @Override
    public String toString() {
        return "Catalog{" +
                "id=" + id +
                ", brandId=" + brandId +
                ", brand='" + brand + '\'' +
                ", modelNumber='" + modelNumber + '\'' +
                ", modelName='" + modelName + '\'' +
                ", categoryId=" + categoryId +
                ", createdBy='" + createdBy + '\'' +
                ", created=" + created +
                '}';
    }

}