Subversion Repositories SmartDukaan

Rev

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

package com.spice.profitmandi.service;

import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.dao.entity.inventory.SalesTargets;
import com.spice.profitmandi.dao.model.*;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public interface RbmTargetService {

    List<WarehouseRbmTargetModel> getWarehouseWiseRbmMonthlyTarget();

    List<MTDAchievedTargetModel> getDateWiseAchievedTargetOfRbm(LocalDate startDate, LocalDate endDate);

    List<WarehouseMobileStockByMovementModel> getWarehouseMobileStockByMovement();

    List<SoldCatalogsReportModel> getCatalogSoldReport(LocalDate startDate, LocalDate endDate);

    int getWorkingDaysCount(LocalDate startDate);

    List<TodayAchievedMovementModel> getMovementWiseAchievementByDate(LocalDate startDate, LocalDate endDate);

    List<RbmBrandSoldModel> getBrandsSoldByRbm(int authId, int warehouseId, LocalDate startDate, LocalDate endDate);

    List<RbmBrandPartnerCountModel> getBrandPartnerCountByRbm(int authId, int warehouseId, LocalDate startDate, LocalDate endDate);

    List<WarehouseBuyingByMovementModel> getWarehouseBuyingByMovement(int warehouseId, LocalDate startDate, LocalDate endDate);

    /**
     * Opening stock value per movement class for a warehouse at the start of a period.
     * Used by the RBM DRR drill-down "Warehouse Flow" table to contextualise the
     * period's buying/selling ratio against stock that already existed before the
     * period.
     *
     * @param warehouseId warehouse whose opening we want
     * @param asOfDate    the period start; everything received before this date
     *                    and everything sold before this date contribute
     */
    List<WarehouseOpeningByMovementModel> getWarehouseOpeningByMovement(int warehouseId, LocalDate asOfDate);

    /**
     * Daily writer for Sales-hierarchy targets (mirrors {@link #setMovementWiseRbmTargets}).
     * Reads today's persisted RBM snapshots from inventory.rbm_targets, rolls them up per
     * (sales_auth_id × warehouse_id) for every active Sales person whose downline contains
     * at least one RBM, and inserts one row per (sales, warehouse) into inventory.sales_targets.
     * Intended to run once daily via the cron flag {@code pushSalesTargets},
     * chained after {@code pushRbmTargets}.
     */
    void setSalesTargets();

    /**
     * Same as {@link #setSalesTargets()} but for a specific date — reads that
     * day's persisted RBM snapshots and writes Sales snapshots stamped to that
     * day. Useful for backfilling missed cron runs or seeding local/staging
     * data without needing today's RBM snapshot.
     */
    void setSalesTargetsForDate(LocalDate date);

    List<SalesTargets> getSalesTargetsByDates(LocalDate startDate, LocalDate endDate);

    /**
     * Historical snapshot writer for Sales-hierarchy achievement (mirrors
     * {@link #setMovementWiseRbmAchievement}). Rolls up today's live order
     * ACH into one row per (Sales person × warehouse) and persists to
     * {@code inventory.sales_achievements} for later reconciliation.
     * The DRR dashboard reads ACH LIVE from orders — this table is audit only.
     */
    void setSalesAchievements();

    /**
     * Dated variant of {@link #setSalesAchievements()} for backfill.
     */
    void setSalesAchievementsForDate(LocalDate date);

    /**
     * Per-(auth × warehouse) live achievement for a specific Sales-hierarchy role
     * (category 4, escalation L1..L6) in a date range. Direct query — no RBM roll-up.
     */
    List<SalesHierarchyAchievedByMovementModel> getSalesAchievementByRole(
            int categoryId, String escalationType, LocalDate startDate, LocalDate endDate);

    /**
     * Monthly target per (auth × warehouse) for a specific Sales-hierarchy role,
     * looked up for the month of {@code refDate}. Sum of
     * {@code fofo.monthly_target.purchase} across each Sales person's assigned partners.
     */
    List<SalesHierarchyMonthlyTargetModel> getSalesMonthlyTargetByRole(
            int categoryId, String escalationType, LocalDate refDate);

    /**
     * Distinct-partner rolled-up ACH per warehouse for a set of Sales-hierarchy
     * auth_ids (RSM/NSM's downline). Dedupes partners across positions so overlapping
     * assignments don't double-count.
     */
    List<com.spice.profitmandi.dao.model.SalesDownlineAchievedByMovementModel>
    getSalesDownlineAchievement(java.util.Collection<Integer> authIds, LocalDate startDate, LocalDate endDate);

    /**
     * Distinct-partner rolled-up monthly target per warehouse for a set of
     * Sales-hierarchy auth_ids. Same dedup guarantee as
     * {@link #getSalesDownlineAchievement}.
     */
    List<com.spice.profitmandi.dao.model.SalesDownlineMonthlyTargetModel>
    getSalesDownlineMonthlyTarget(java.util.Collection<Integer> authIds, LocalDate refDate);

    /**
     * Brand × movement-status sold by a set of Sales-hierarchy auth_ids in one
     * warehouse × date range. Works for both single-person views (pass one
     * authId) and RSM/NSM roll-ups (pass self + full downline). Dedupes
     * partners via SELECT DISTINCT.
     */
    List<com.spice.profitmandi.dao.model.SalesHierarchyBrandSoldModel>
    getSalesBrandsSold(java.util.Collection<Integer> authIds, int warehouseId, LocalDate startDate, LocalDate endDate);

    /**
     * Distinct partner count per brand for the same Sales-hierarchy auth_ids
     * set. Used for the "N partners" badge in the drill-down brand mix.
     */
    List<com.spice.profitmandi.dao.model.SalesHierarchyBrandPartnerCountModel>
    getSalesBrandPartnerCount(java.util.Collection<Integer> authIds, int warehouseId, LocalDate startDate, LocalDate endDate);

    List<RbmTargetAndAchievementsModel> getRbmTargetsAndAchievemnts(LocalDate startDate, LocalDate endDate);

    List<RbmArrViewModel> getRbmTodayArr(LocalDate todayDate) throws Exception;

    List<RbmArrViewModel> getRbmTodayArr() throws Exception;

    void setMovementWiseRbmTargets();

    void setMovementWiseRbmAchievement();

    List<Sold15daysOldAgingModel> getAgingSale(LocalDate startDate, LocalDate endDate);

    List<Our15DaysOldAgingStock> our15DaysAgingStock();

    List<WarehouseAgingStockModel> getWarehouseWiseAgingStock();

    List<RbmBilledFofoIdsModel> getDateWiseBilledFofoIdByRbm(LocalDate startDate, LocalDate endDate);

    List<RbmWeeklyBillingModel> getWeeklyBillingDataForMonth(LocalDate monthStart, LocalDate monthEnd);

    double calculateFofoIdTodayTarget(int fofoId, double secondryMtd, LocalDate date);

    long getRemainingDaysInMonth(LocalDate date);

    List<RbmCallTargetModel> getRbmCallTargetModels() throws Exception;

    List<RbmCallTargetModel> getRbmCallTargetModels(LocalDate queryDate) throws Exception;

    List<OutOfSequenceDetailModel> getOutOfSequenceDetails(int authId);

    List<CalledPartnerDetailModel> getCalledPartnerDetails(int authId) throws ProfitMandiBusinessException;

    List<CalledPartnerDetailModel> getCalledPartnerDetails(int authId, LocalDate date) throws ProfitMandiBusinessException;

    List<List<String>> getRbmCallTargetRawDataByAuthId(int authId) throws Exception;

    List<List<String>> getAllCallDataByDate(LocalDate date) throws Exception;

    List<List<String>> getAllRbmCallTargetRawData() throws Exception;
}