| Line 5... |
Line 5... |
| 5 |
import java.util.HashMap;
|
5 |
import java.util.HashMap;
|
| 6 |
import java.util.HashSet;
|
6 |
import java.util.HashSet;
|
| 7 |
import java.util.List;
|
7 |
import java.util.List;
|
| 8 |
import java.util.Map;
|
8 |
import java.util.Map;
|
| 9 |
import java.util.Set;
|
9 |
import java.util.Set;
|
| - |
|
10 |
import java.util.stream.Collectors;
|
| 10 |
|
11 |
|
| 11 |
import org.apache.logging.log4j.LogManager;
|
12 |
import org.apache.logging.log4j.LogManager;
|
| 12 |
import org.apache.logging.log4j.Logger;
|
13 |
import org.apache.logging.log4j.Logger;
|
| 13 |
import org.springframework.beans.factory.annotation.Autowired;
|
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 14 |
import org.springframework.beans.factory.annotation.Qualifier;
|
15 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 15 |
import org.springframework.stereotype.Component;
|
16 |
import org.springframework.stereotype.Component;
|
| 16 |
|
17 |
|
| 17 |
import com.spice.profitmandi.common.enumuration.DateTimePattern;
|
- |
|
| 18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 19 |
import com.spice.profitmandi.common.model.CreateSchemeRequest;
|
19 |
import com.spice.profitmandi.common.model.CreateSchemeRequest;
|
| 20 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
20 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21 |
import com.spice.profitmandi.common.model.SchemeModel;
|
21 |
import com.spice.profitmandi.common.model.SchemeModel;
|
| 22 |
import com.spice.profitmandi.common.util.StringUtils;
|
22 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 23 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
23 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 24 |
import com.spice.profitmandi.dao.entity.catalog.RetailerScheme;
|
24 |
import com.spice.profitmandi.dao.entity.catalog.RetailerScheme;
|
| 25 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
25 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 26 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
- |
|
| 27 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
26 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
| 28 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
27 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 29 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
28 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 30 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
29 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 31 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
30 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| Line 35... |
Line 34... |
| 35 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
34 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 36 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
35 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 37 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
36 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 38 |
import com.spice.profitmandi.dao.repository.catalog.RetailerSchemeRepository;
|
37 |
import com.spice.profitmandi.dao.repository.catalog.RetailerSchemeRepository;
|
| 39 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
38 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 40 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
- |
|
| 41 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
39 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| - |
|
40 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 42 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
41 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
| 43 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
42 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 44 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
43 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 45 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
44 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 46 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
45 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| Line 675... |
Line 674... |
| 675 |
}
|
674 |
}
|
| 676 |
|
675 |
|
| 677 |
private float createSchemeInOut(Scheme scheme, InventoryItem inventoryItem) {
|
676 |
private float createSchemeInOut(Scheme scheme, InventoryItem inventoryItem) {
|
| 678 |
SchemeInOut schemeInOut = schemeInOutRepository.selectByScheme(scheme.getId(), inventoryItem.getId());
|
677 |
SchemeInOut schemeInOut = schemeInOutRepository.selectByScheme(scheme.getId(), inventoryItem.getId());
|
| 679 |
float amount = 0;
|
678 |
float amount = 0;
|
| 680 |
if (schemeInOut == null) {
|
679 |
if (schemeInOut == null || schemeInOut.getRolledBackTimestamp() != null) {
|
| 681 |
schemeInOut = new SchemeInOut();
|
680 |
schemeInOut = new SchemeInOut();
|
| 682 |
amount = this.getAmount(inventoryItem, scheme);
|
681 |
amount = this.getAmount(inventoryItem, scheme);
|
| 683 |
schemeInOut.setSchemeId(scheme.getId());
|
682 |
schemeInOut.setSchemeId(scheme.getId());
|
| 684 |
schemeInOut.setInventoryItemId(inventoryItem.getId());
|
683 |
schemeInOut.setInventoryItemId(inventoryItem.getId());
|
| 685 |
schemeInOut.setAmount(amount);
|
684 |
schemeInOut.setAmount(amount);
|
| Line 689... |
Line 688... |
| 689 |
}
|
688 |
}
|
| 690 |
|
689 |
|
| 691 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) {
|
690 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) {
|
| 692 |
float amount = 0;
|
691 |
float amount = 0;
|
| 693 |
float totalTaxRate = inventoryItem.getIgstRate() + inventoryItem.getSgstRate() + inventoryItem.getCgstRate();
|
692 |
float totalTaxRate = inventoryItem.getIgstRate() + inventoryItem.getSgstRate() + inventoryItem.getCgstRate();
|
| 694 |
float taxableSellingPrice = inventoryItem.getUnitPrice() / (1 + totalTaxRate / 100);
|
693 |
float taxableSellingPrice = (inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount())
|
| - |
|
694 |
/ (1 + totalTaxRate / 100);
|
| 695 |
|
695 |
|
| 696 |
if (scheme.getAmountType() == AmountType.PERCENTAGE) {
|
696 |
if (scheme.getAmountType() == AmountType.PERCENTAGE) {
|
| 697 |
amount = taxableSellingPrice * scheme.getAmount() / 100;
|
697 |
amount = taxableSellingPrice * scheme.getAmount() / 100;
|
| 698 |
} else {
|
698 |
} else {
|
| 699 |
amount = scheme.getAmount();
|
699 |
amount = scheme.getAmount();
|
| Line 868... |
Line 868... |
| 868 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
868 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
| 869 |
}
|
869 |
}
|
| 870 |
return schemes;
|
870 |
return schemes;
|
| 871 |
}
|
871 |
}
|
| 872 |
|
872 |
|
| - |
|
873 |
@Override
|
| - |
|
874 |
public void reverseSchemes(List<InventoryItem> inventoryItems, int reversalReference, String reversalReason)
|
| - |
|
875 |
throws Exception {
|
| - |
|
876 |
float amountToRollback = 0;
|
| - |
|
877 |
float amountToCredit = 0;
|
| - |
|
878 |
Map<Integer, InventoryItem> inventoryItemsMap = inventoryItems.stream()
|
| - |
|
879 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| - |
|
880 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(inventoryItemsMap.keySet());
|
| - |
|
881 |
List<Integer> schemeIds = schemeInOuts.stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
|
| - |
|
882 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIds, 0, schemeIds.size()).stream()
|
| - |
|
883 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| - |
|
884 |
for (SchemeInOut schemeInOut : schemeInOuts) {
|
| - |
|
885 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
| - |
|
886 |
if(scheme.getAmountType().equals(AmountType.FIXED)) continue;
|
| - |
|
887 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
| - |
|
888 |
schemeInOutRepository.persist(schemeInOut);
|
| - |
|
889 |
SchemeInOut sioNew = new SchemeInOut();
|
| - |
|
890 |
sioNew.setAmount(getAmount(inventoryItemsMap.get(schemeInOut.getInventoryItemId()),
|
| - |
|
891 |
scheme));
|
| - |
|
892 |
sioNew.setInventoryItemId(schemeInOut.getInventoryItemId());
|
| - |
|
893 |
sioNew.setSchemeId(schemeInOut.getSchemeId());
|
| - |
|
894 |
schemeInOutRepository.persist(sioNew);
|
| - |
|
895 |
amountToRollback += schemeInOut.getAmount();
|
| - |
|
896 |
amountToCredit += sioNew.getAmount();
|
| - |
|
897 |
}
|
| - |
|
898 |
if (amountToRollback > 0 && amountToCredit > 0) {
|
| - |
|
899 |
int fofoId = inventoryItems.get(0).getFofoId();
|
| - |
|
900 |
walletService.rollbackAmountFromWallet(fofoId, amountToRollback, reversalReference,
|
| - |
|
901 |
WalletReferenceType.SCHEME_IN, reversalReason);
|
| - |
|
902 |
walletService.addAmountToWallet(fofoId, reversalReference, WalletReferenceType.SCHEME_IN, reversalReason,
|
| - |
|
903 |
amountToCredit);
|
| - |
|
904 |
}
|
| - |
|
905 |
}
|
| - |
|
906 |
|
| 873 |
}
|
907 |
}
|