Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

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

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * Daily target snapshot for one Sales-hierarchy person (ASM / CM / DM / BM /
 * RSM / NSM) at one warehouse, split by movement class — mirrors
 * {@link RbmTargets} but rolled up to a manager. Written each day by the
 * cron chain: {@code pushRbmTargets} → {@code pushSalesTargets}. The Sales
 * daily target is the sum of persisted RBM daily targets for the RBMs in
 * that manager's downline for the same warehouse.
 *
 * <p>Table DDL (run once against the target DB):
 * <pre>
 * CREATE TABLE inventory.sales_targets (
 *   id                 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
 *   sales_auth_id      INT NOT NULL,
 *   sales_name         VARCHAR(128),
 *   role               VARCHAR(8),
 *   warehouse_id       INT NOT NULL,
 *   hid_target         FLOAT DEFAULT 0,
 *   fastmoving_target  FLOAT DEFAULT 0,
 *   running_target     FLOAT DEFAULT 0,
 *   slowmoving_target  FLOAT DEFAULT 0,
 *   other_target       FLOAT DEFAULT 0,
 *   create_timestamp   DATETIME NOT NULL,
 *   KEY idx_sales_created (sales_auth_id, create_timestamp),
 *   KEY idx_created (create_timestamp)
 * );
 * </pre>
 */
@Entity
@Table(name = "inventory.sales_targets")
public class SalesTargets {

    @Id
    @Column(name = "id", unique = true, updatable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "sales_auth_id")
    private int salesAuthId;

    @Column(name = "sales_name")
    private String salesName;

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

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

    @Column(name = "hid_target")
    private float hidTarget;

    @Column(name = "fastmoving_target")
    private float fastMovingTarget;

    @Column(name = "running_target")
    private float runningTarget;

    @Column(name = "slowmoving_target")
    private float slowMovingTarget;

    @Column(name = "other_target")
    private float otherTarget;

    @Column(name = "create_timestamp")
    private LocalDateTime createTimestamp;

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

    public int getSalesAuthId() { return salesAuthId; }
    public void setSalesAuthId(int salesAuthId) { this.salesAuthId = salesAuthId; }

    public String getSalesName() { return salesName; }
    public void setSalesName(String salesName) { this.salesName = salesName; }

    public String getRole() { return role; }
    public void setRole(String role) { this.role = role; }

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

    public float getHidTarget() { return hidTarget; }
    public void setHidTarget(float hidTarget) { this.hidTarget = hidTarget; }

    public float getFastMovingTarget() { return fastMovingTarget; }
    public void setFastMovingTarget(float fastMovingTarget) { this.fastMovingTarget = fastMovingTarget; }

    public float getRunningTarget() { return runningTarget; }
    public void setRunningTarget(float runningTarget) { this.runningTarget = runningTarget; }

    public float getSlowMovingTarget() { return slowMovingTarget; }
    public void setSlowMovingTarget(float slowMovingTarget) { this.slowMovingTarget = slowMovingTarget; }

    public float getOtherTarget() { return otherTarget; }
    public void setOtherTarget(float otherTarget) { this.otherTarget = otherTarget; }

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

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SalesTargets that = (SalesTargets) o;
        return id == that.id && salesAuthId == that.salesAuthId && warehouseId == that.warehouseId
                && Float.compare(hidTarget, that.hidTarget) == 0
                && Float.compare(fastMovingTarget, that.fastMovingTarget) == 0
                && Float.compare(runningTarget, that.runningTarget) == 0
                && Float.compare(slowMovingTarget, that.slowMovingTarget) == 0
                && Float.compare(otherTarget, that.otherTarget) == 0
                && Objects.equals(salesName, that.salesName) && Objects.equals(role, that.role)
                && Objects.equals(createTimestamp, that.createTimestamp);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, salesAuthId, salesName, role, warehouseId, hidTarget, fastMovingTarget,
                runningTarget, slowMovingTarget, otherTarget, createTimestamp);
    }

    @Override
    public String toString() {
        return "SalesTargets{id=" + id + ", salesAuthId=" + salesAuthId + ", role='" + role
                + "', warehouseId=" + warehouseId + ", hid=" + hidTarget + ", fast=" + fastMovingTarget
                + ", run=" + runningTarget + ", slow=" + slowMovingTarget + ", other=" + otherTarget
                + ", ts=" + createTimestamp + "}";
    }
}