| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
3 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 4 |
import com.spice.profitmandi.dao.entity.fofo.MonthlyTarget;
|
4 |
import com.spice.profitmandi.dao.entity.fofo.MonthlyTarget;
|
| 5 |
import com.spice.profitmandi.dao.entity.inventory.RbmAchievements;
|
5 |
import com.spice.profitmandi.dao.entity.inventory.RbmAchievements;
|
| 6 |
import com.spice.profitmandi.dao.entity.inventory.RbmTargets;
|
6 |
import com.spice.profitmandi.dao.entity.inventory.RbmTargets;
|
| - |
|
7 |
import com.spice.profitmandi.dao.entity.logistics.PublicHolidays;
|
| 7 |
import com.spice.profitmandi.dao.model.*;
|
8 |
import com.spice.profitmandi.dao.model.*;
|
| 8 |
import com.spice.profitmandi.dao.repository.catalog.RbmAchievementsRepository;
|
9 |
import com.spice.profitmandi.dao.repository.catalog.RbmAchievementsRepository;
|
| 9 |
import com.spice.profitmandi.dao.repository.catalog.RbmTargetsRepository;
|
10 |
import com.spice.profitmandi.dao.repository.catalog.RbmTargetsRepository;
|
| 10 |
import com.spice.profitmandi.dao.repository.fofo.MonthlyTargetRepository;
|
11 |
import com.spice.profitmandi.dao.repository.fofo.MonthlyTargetRepository;
|
| - |
|
12 |
import com.spice.profitmandi.dao.repository.logistics.PublicHolidaysRepository;
|
| 11 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
13 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 12 |
import org.apache.logging.log4j.LogManager;
|
14 |
import org.apache.logging.log4j.LogManager;
|
| 13 |
import org.apache.logging.log4j.Logger;
|
15 |
import org.apache.logging.log4j.Logger;
|
| 14 |
import org.hibernate.Session;
|
16 |
import org.hibernate.Session;
|
| 15 |
import org.hibernate.SessionFactory;
|
17 |
import org.hibernate.SessionFactory;
|
| 16 |
import org.hibernate.query.NativeQuery;
|
18 |
import org.hibernate.query.NativeQuery;
|
| 17 |
import org.springframework.beans.factory.annotation.Autowired;
|
19 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 18 |
import org.springframework.stereotype.Component;
|
20 |
import org.springframework.stereotype.Component;
|
| 19 |
|
21 |
|
| 20 |
import javax.persistence.TypedQuery;
|
22 |
import javax.persistence.TypedQuery;
|
| 21 |
import java.time.LocalDate;
|
- |
|
| 22 |
import java.time.LocalDateTime;
|
- |
|
| 23 |
import java.time.LocalTime;
|
23 |
import java.time.*;
|
| 24 |
import java.time.YearMonth;
|
24 |
import java.time.temporal.ChronoUnit;
|
| 25 |
import java.util.ArrayList;
|
25 |
import java.util.ArrayList;
|
| 26 |
import java.util.List;
|
26 |
import java.util.List;
|
| 27 |
import java.util.Map;
|
27 |
import java.util.Map;
|
| 28 |
import java.util.Optional;
|
28 |
import java.util.Optional;
|
| 29 |
import java.util.stream.Collectors;
|
29 |
import java.util.stream.Collectors;
|
| Line 42... |
Line 42... |
| 42 |
RbmAchievementsRepository rbmAchievementsRepository;
|
42 |
RbmAchievementsRepository rbmAchievementsRepository;
|
| 43 |
|
43 |
|
| 44 |
@Autowired
|
44 |
@Autowired
|
| 45 |
MonthlyTargetRepository monthlyTargetRepository;
|
45 |
MonthlyTargetRepository monthlyTargetRepository;
|
| 46 |
|
46 |
|
| - |
|
47 |
@Autowired
|
| - |
|
48 |
PublicHolidaysRepository publicHolidaysRepository;
|
| - |
|
49 |
|
| 47 |
@Override
|
50 |
@Override
|
| 48 |
public List<WarehouseRbmTargetModel> getWarehouseWiseRbmMonthlyTarget() {
|
51 |
public List<WarehouseRbmTargetModel> getWarehouseWiseRbmMonthlyTarget() {
|
| 49 |
Session session = sessionFactory.getCurrentSession();
|
52 |
Session session = sessionFactory.getCurrentSession();
|
| 50 |
final TypedQuery<WarehouseRbmTargetModel> typedQuerySimilar = session.createNamedQuery("RbmTarget.getWarehouseWiseMonthlyTarget", WarehouseRbmTargetModel.class);
|
53 |
final TypedQuery<WarehouseRbmTargetModel> typedQuerySimilar = session.createNamedQuery("RbmTarget.getWarehouseWiseMonthlyTarget", WarehouseRbmTargetModel.class);
|
| 51 |
|
54 |
|
| Line 463... |
Line 466... |
| 463 |
// Log or handle as needed
|
466 |
// Log or handle as needed
|
| 464 |
return 0; // or -1 or some fallback
|
467 |
return 0; // or -1 or some fallback
|
| 465 |
}
|
468 |
}
|
| 466 |
|
469 |
|
| 467 |
double remainingTarget = monthlyTarget.getPurchaseTarget() - secondryMtd;
|
470 |
double remainingTarget = monthlyTarget.getPurchaseTarget() - secondryMtd;
|
| 468 |
double remainingWorkingDays = getWorkingDaysCount(date) - 1;
|
471 |
// double remainingWorkingDays = getWorkingDaysCount(date);
|
| - |
|
472 |
double remainingWorkingDays = (double) getRemainingDaysInMonth(date);
|
| 469 |
|
473 |
|
| 470 |
|
474 |
|
| 471 |
|
475 |
|
| 472 |
if (remainingWorkingDays == 0) return remainingTarget; // Last day
|
476 |
if (remainingWorkingDays == 0) return remainingTarget; // Last day
|
| 473 |
LOGGER.info("remainingWorkingDays {}", remainingWorkingDays);
|
477 |
LOGGER.info("remainingWorkingDays {}", remainingWorkingDays);
|
| 474 |
LOGGER.info("remainingTarget {}", remainingTarget);
|
478 |
LOGGER.info("remainingTarget {}", remainingTarget);
|
| 475 |
|
479 |
|
| 476 |
return (int) Math.ceil(remainingTarget / remainingWorkingDays);
|
480 |
return (int) Math.ceil(remainingTarget / remainingWorkingDays);
|
| 477 |
}
|
481 |
}
|
| 478 |
|
482 |
|
| - |
|
483 |
@Override
|
| - |
|
484 |
public long getRemainingDaysInMonth(LocalDate date) {
|
| - |
|
485 |
LocalDate lastDayOfMonth = YearMonth.from(date).atEndOfMonth();
|
| - |
|
486 |
|
| - |
|
487 |
long totalDays = ChronoUnit.DAYS.between(date, lastDayOfMonth) + 1;
|
| - |
|
488 |
|
| - |
|
489 |
// Count Sundays manually
|
| - |
|
490 |
long sundayCount = 0;
|
| - |
|
491 |
LocalDate current = date;
|
| - |
|
492 |
while (!current.isAfter(lastDayOfMonth)) {
|
| - |
|
493 |
if (current.getDayOfWeek() == DayOfWeek.SUNDAY) {
|
| - |
|
494 |
sundayCount++;
|
| - |
|
495 |
}
|
| - |
|
496 |
current = current.plusDays(1);
|
| - |
|
497 |
}
|
| - |
|
498 |
|
| - |
|
499 |
// Public holidays in the range
|
| - |
|
500 |
long publicHolidays = publicHolidaysRepository
|
| - |
|
501 |
.selectAllBetweenDates(date, lastDayOfMonth)
|
| - |
|
502 |
.size();
|
| - |
|
503 |
|
| - |
|
504 |
long remainingDays = totalDays - sundayCount - publicHolidays;
|
| - |
|
505 |
|
| - |
|
506 |
LOGGER.info("remainingDays {}", remainingDays);
|
| - |
|
507 |
LOGGER.info("totalDays {}", totalDays);
|
| - |
|
508 |
LOGGER.info("sundays {}", sundayCount);
|
| - |
|
509 |
LOGGER.info("publicHolidays {}", publicHolidays);
|
| - |
|
510 |
|
| - |
|
511 |
return remainingDays;
|
| - |
|
512 |
}
|
| - |
|
513 |
|
| 479 |
|
514 |
|
| 480 |
|
515 |
|
| 481 |
}
|
516 |
}
|