| Line 4752... |
Line 4752... |
| 4752 |
// Check if an entry already exists in the FofoOpeningStock table
|
4752 |
// Check if an entry already exists in the FofoOpeningStock table
|
| 4753 |
FofoOpeningStock existingStock = fofoOpeningStockRepository.findByFofoIdAndCatalogId(fofoId, catalogId);
|
4753 |
FofoOpeningStock existingStock = fofoOpeningStockRepository.findByFofoIdAndCatalogId(fofoId, catalogId);
|
| 4754 |
|
4754 |
|
| 4755 |
|
4755 |
|
| 4756 |
if (existingStock != null) {
|
4756 |
if (existingStock != null) {
|
| 4757 |
if (partnerCurrentQty < 1 && existingStock.getOpeningDate().isBefore(LocalDate.now().minusDays(7))) {
|
4757 |
if (partnerCurrentQty < 1 && existingStock.getOpeningDate().isBefore(LocalDate.now().minusDays(5))) {
|
| 4758 |
fofoOpeningStockRepository.delete(existingStock);
|
4758 |
fofoOpeningStockRepository.delete(existingStock);
|
| 4759 |
}
|
4759 |
}
|
| 4760 |
if (existingStock.getOpeningQty() < partnerCurrentQty) {
|
4760 |
if (existingStock.getOpeningQty() < partnerCurrentQty) {
|
| 4761 |
existingStock.setOpeningQty(partnerCurrentQty);
|
4761 |
existingStock.setOpeningQty(partnerCurrentQty);
|
| 4762 |
existingStock.setCurrentQty(partnerCurrentQty);
|
4762 |
existingStock.setCurrentQty(partnerCurrentQty);
|
| Line 4764... |
Line 4764... |
| 4764 |
LOGGER.info("if condition exist {}");
|
4764 |
LOGGER.info("if condition exist {}");
|
| 4765 |
} else if (existingStock.getCurrentQty() >= existingStock.getOpeningQty()) {
|
4765 |
} else if (existingStock.getCurrentQty() >= existingStock.getOpeningQty()) {
|
| 4766 |
existingStock.setOpeningQty(existingStock.getCurrentQty());
|
4766 |
existingStock.setOpeningQty(existingStock.getCurrentQty());
|
| 4767 |
existingStock.setCurrentQty(partnerCurrentQty);
|
4767 |
existingStock.setCurrentQty(partnerCurrentQty);
|
| 4768 |
existingStock.setOpeningDate(LocalDate.now());
|
4768 |
existingStock.setOpeningDate(LocalDate.now());
|
| 4769 |
} else if (existingStock.getOpeningDate().isBefore(LocalDate.now().minusDays(7))) {
|
4769 |
} else if (existingStock.getOpeningDate().isBefore(LocalDate.now().minusDays(5))) {
|
| 4770 |
int averageQty = Math.round((existingStock.getCurrentQty() + existingStock.getOpeningQty()) / 2.0f);
|
4770 |
int averageQty = Math.round((existingStock.getCurrentQty() + existingStock.getOpeningQty()) / 2.0f);
|
| 4771 |
|
4771 |
|
| 4772 |
if (averageQty == 1 && existingStock.getOpeningQty() == 1 && existingStock.getCurrentQty() == 0) {
|
4772 |
if (averageQty == 1 && existingStock.getOpeningQty() == 1 && existingStock.getCurrentQty() == 0) {
|
| 4773 |
// Delete the existing stock entry from the table
|
4773 |
// Delete the existing stock entry from the table
|
| 4774 |
fofoOpeningStockRepository.delete(existingStock);
|
4774 |
fofoOpeningStockRepository.delete(existingStock);
|
| Line 4776... |
Line 4776... |
| 4776 |
} else {
|
4776 |
} else {
|
| 4777 |
// Update the existing stock with the new average quantity
|
4777 |
// Update the existing stock with the new average quantity
|
| 4778 |
existingStock.setOpeningQty(averageQty);
|
4778 |
existingStock.setOpeningQty(averageQty);
|
| 4779 |
existingStock.setCurrentQty(partnerCurrentQty);
|
4779 |
existingStock.setCurrentQty(partnerCurrentQty);
|
| 4780 |
existingStock.setOpeningDate(LocalDate.now());
|
4780 |
existingStock.setOpeningDate(LocalDate.now());
|
| 4781 |
LOGGER.info("Updated due to date being older than 7 days with average quantity: {}", averageQty);
|
4781 |
LOGGER.info("Updated due to date being older than 5 days with average quantity: {}", averageQty);
|
| 4782 |
}
|
4782 |
}
|
| 4783 |
} else {
|
4783 |
} else {
|
| 4784 |
existingStock.setCurrentQty(partnerCurrentQty);
|
4784 |
existingStock.setCurrentQty(partnerCurrentQty);
|
| 4785 |
}
|
4785 |
}
|
| 4786 |
} else {
|
4786 |
} else {
|
| Line 4800... |
Line 4800... |
| 4800 |
List<FofoOpeningStock> fofoOpeningStockList = fofoOpeningStockRepository.selectAllByFofoId(fofoId);
|
4800 |
List<FofoOpeningStock> fofoOpeningStockList = fofoOpeningStockRepository.selectAllByFofoId(fofoId);
|
| 4801 |
|
4801 |
|
| 4802 |
for (FofoOpeningStock fofoOpeningStock : fofoOpeningStockList) {
|
4802 |
for (FofoOpeningStock fofoOpeningStock : fofoOpeningStockList) {
|
| 4803 |
|
4803 |
|
| 4804 |
if (!partnerStockList.stream().anyMatch(partnerStock -> partnerStock.getCatalogId() == fofoOpeningStock.getCatalogId())) {
|
4804 |
if (!partnerStockList.stream().anyMatch(partnerStock -> partnerStock.getCatalogId() == fofoOpeningStock.getCatalogId())) {
|
| 4805 |
if (fofoOpeningStock.getOpeningDate().isBefore(LocalDate.now().minusDays(7))) {
|
4805 |
if (fofoOpeningStock.getOpeningDate().isBefore(LocalDate.now().minusDays(5))) {
|
| 4806 |
LOGGER.info("not match stock{}", fofoOpeningStock);
|
4806 |
LOGGER.info("not match stock{}", fofoOpeningStock);
|
| 4807 |
fofoOpeningStockRepository.delete(fofoOpeningStock);
|
4807 |
fofoOpeningStockRepository.delete(fofoOpeningStock);
|
| 4808 |
} else {
|
4808 |
} else {
|
| 4809 |
LOGGER.info("not match stock2{}", fofoOpeningStock);
|
4809 |
LOGGER.info("not match stock2{}", fofoOpeningStock);
|
| 4810 |
fofoOpeningStock.setCurrentQty(0);
|
4810 |
fofoOpeningStock.setCurrentQty(0);
|