| Line 34... |
Line 34... |
| 34 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
34 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 35 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
35 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 36 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
36 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 37 |
import com.spice.profitmandi.dao.repository.catalog.RetailerSchemeRepository;
|
37 |
import com.spice.profitmandi.dao.repository.catalog.RetailerSchemeRepository;
|
| 38 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
38 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| - |
|
39 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 39 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
40 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 40 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
41 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
| 41 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
42 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 42 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
43 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 43 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
44 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| Line 70... |
Line 71... |
| 70 |
@Autowired
|
71 |
@Autowired
|
| 71 |
private RoleManager roleManager;
|
72 |
private RoleManager roleManager;
|
| 72 |
|
73 |
|
| 73 |
@Autowired
|
74 |
@Autowired
|
| 74 |
private RetailerRepository retailerRepository;
|
75 |
private RetailerRepository retailerRepository;
|
| - |
|
76 |
|
| - |
|
77 |
@Autowired
|
| - |
|
78 |
private TagListingRepository tagListingRepository;
|
| 75 |
|
79 |
|
| 76 |
@Autowired
|
80 |
@Autowired
|
| 77 |
private RetailerSchemeRepository retailerSchemeRepository;
|
81 |
private RetailerSchemeRepository retailerSchemeRepository;
|
| 78 |
|
82 |
|
| 79 |
@Autowired
|
83 |
@Autowired
|
| Line 684... |
Line 688... |
| 684 |
}
|
688 |
}
|
| 685 |
|
689 |
|
| 686 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) {
|
690 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) {
|
| 687 |
float amount = 0;
|
691 |
float amount = 0;
|
| 688 |
float totalTaxRate = inventoryItem.getIgstRate() + inventoryItem.getSgstRate() + inventoryItem.getCgstRate();
|
692 |
float totalTaxRate = inventoryItem.getIgstRate() + inventoryItem.getSgstRate() + inventoryItem.getCgstRate();
|
| 689 |
float taxableSellingPrice = (inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount())
|
- |
|
| 690 |
/ (1 + totalTaxRate / 100);
|
- |
|
| 691 |
|
- |
|
| 692 |
if (scheme.getAmountType() == AmountType.PERCENTAGE) {
|
693 |
if (scheme.getAmountType() == AmountType.PERCENTAGE) {
|
| - |
|
694 |
if(scheme.getType().equals(SchemeType.IN)) {
|
| - |
|
695 |
amount = inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount();
|
| - |
|
696 |
} else {
|
| - |
|
697 |
try {
|
| - |
|
698 |
amount = tagListingRepository.selectByItemId(inventoryItem.getItemId()).getSellingPrice();
|
| - |
|
699 |
} catch(Exception e) {
|
| - |
|
700 |
LOGGER.info("Could not find tag Listing entry in {}", inventoryItem.getItemId());
|
| - |
|
701 |
e.printStackTrace();
|
| - |
|
702 |
}
|
| - |
|
703 |
}
|
| - |
|
704 |
float taxableSellingPrice = amount / (1 + totalTaxRate / 100);
|
| 693 |
amount = taxableSellingPrice * scheme.getAmount() / 100;
|
705 |
amount = taxableSellingPrice * scheme.getAmount() / 100;
|
| 694 |
} else {
|
706 |
} else {
|
| 695 |
amount = scheme.getAmount();
|
707 |
amount = scheme.getAmount();
|
| 696 |
}
|
708 |
}
|
| 697 |
return amount;
|
709 |
return amount;
|
| Line 869... |
Line 881... |
| 869 |
}
|
881 |
}
|
| 870 |
|
882 |
|
| 871 |
@Override
|
883 |
@Override
|
| 872 |
public void reverseSchemes(List<InventoryItem> inventoryItems, int reversalReference, String reversalReason)
|
884 |
public void reverseSchemes(List<InventoryItem> inventoryItems, int reversalReference, String reversalReason)
|
| 873 |
throws Exception {
|
885 |
throws Exception {
|
| 874 |
float amountToRollback = 0;
|
- |
|
| 875 |
float amountToCredit = 0;
|
886 |
float amountToCredit = 0;
|
| - |
|
887 |
float amountToDebit = 0;
|
| 876 |
Map<Integer, InventoryItem> inventoryItemsMap = inventoryItems.stream()
|
888 |
Map<Integer, InventoryItem> inventoryItemsMap = inventoryItems.stream()
|
| 877 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
889 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 878 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(inventoryItemsMap.keySet());
|
890 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(inventoryItemsMap.keySet());
|
| 879 |
List<Integer> schemeIds = schemeInOuts.stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
|
891 |
List<Integer> schemeIds = schemeInOuts.stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
|
| 880 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIds, 0, schemeIds.size()).stream()
|
892 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIds, 0, schemeIds.size()).stream()
|
| 881 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
893 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 882 |
for (SchemeInOut schemeInOut : schemeInOuts) {
|
894 |
for (SchemeInOut schemeInOut : schemeInOuts) {
|
| 883 |
InventoryItem ii = inventoryItemsMap.get(schemeInOut.getInventoryItemId());
|
895 |
InventoryItem ii = inventoryItemsMap.get(schemeInOut.getInventoryItemId());
|
| 884 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
896 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
| 885 |
if (scheme.getAmountType().equals(AmountType.FIXED))
|
897 |
if (scheme.getAmountType().equals(AmountType.FIXED)) {
|
| 886 |
continue;
|
898 |
continue;
|
| - |
|
899 |
}
|
| 887 |
if(schemeInOut.getRolledBackTimestamp() == null) {
|
900 |
if(schemeInOut.getRolledBackTimestamp() == null) {
|
| 888 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
901 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
| 889 |
schemeInOutRepository.persist(schemeInOut);
|
902 |
schemeInOutRepository.persist(schemeInOut);
|
| 890 |
|
- |
|
| - |
|
903 |
float newAmount = getAmount(ii, scheme);
|
| - |
|
904 |
if(schemeInOut.getAmount() - newAmount >= 0.01f) {
|
| 891 |
SchemeInOut sioNew = new SchemeInOut();
|
905 |
SchemeInOut sioNew = new SchemeInOut();
|
| 892 |
sioNew.setAmount(getAmount(ii, scheme));
|
906 |
sioNew.setAmount(newAmount);
|
| 893 |
sioNew.setInventoryItemId(schemeInOut.getInventoryItemId());
|
907 |
sioNew.setInventoryItemId(schemeInOut.getInventoryItemId());
|
| 894 |
sioNew.setSchemeId(schemeInOut.getSchemeId());
|
908 |
sioNew.setSchemeId(schemeInOut.getSchemeId());
|
| 895 |
schemeInOutRepository.persist(sioNew);
|
909 |
schemeInOutRepository.persist(sioNew);
|
| 896 |
amountToRollback += schemeInOut.getAmount();
|
910 |
amountToCredit += sioNew.getAmount();
|
| 897 |
amountToCredit += sioNew.getAmount();
|
911 |
amountToDebit += schemeInOut.getAmount();
|
| - |
|
912 |
}
|
| - |
|
913 |
|
| 898 |
}
|
914 |
}
|
| 899 |
}
|
915 |
}
|
| 900 |
if (amountToRollback > 0 && amountToCredit > 0) {
|
- |
|
| 901 |
int fofoId = inventoryItems.get(0).getFofoId();
|
916 |
int fofoId = inventoryItems.get(0).getFofoId();
|
| - |
|
917 |
if (amountToDebit > 0) {
|
| 902 |
walletService.addAmountToWallet(fofoId, reversalReference, WalletReferenceType.PRICE_DROP, reversalReason,
|
918 |
walletService.addAmountToWallet(fofoId, reversalReference, WalletReferenceType.PRICE_DROP, reversalReason,
|
| 903 |
amountToRollback);
|
919 |
-amountToDebit);
|
| - |
|
920 |
}
|
| - |
|
921 |
if (amountToCredit > 0) {
|
| - |
|
922 |
walletService.addAmountToWallet(fofoId, reversalReference, WalletReferenceType.PRICE_DROP, reversalReason,
|
| - |
|
923 |
amountToCredit);
|
| 904 |
}
|
924 |
}
|
| 905 |
}
|
925 |
}
|
| 906 |
|
926 |
|
| 907 |
}
|
927 |
}
|