| Line 35... |
Line 35... |
| 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.dtr.RetailerRepository;
|
39 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 40 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
- |
|
| 41 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
40 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
| 42 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
41 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 43 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
42 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 44 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
43 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 45 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
44 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| Line 103... |
Line 102... |
| 103 |
private OrderRepository orderRepository;
|
102 |
private OrderRepository orderRepository;
|
| 104 |
|
103 |
|
| 105 |
@Autowired
|
104 |
@Autowired
|
| 106 |
private FofoOrderRepository fofoOrderRepository;
|
105 |
private FofoOrderRepository fofoOrderRepository;
|
| 107 |
|
106 |
|
| 108 |
@Autowired
|
- |
|
| 109 |
private RoleRepository roleRepository;
|
- |
|
| 110 |
|
- |
|
| 111 |
@Override
|
107 |
@Override
|
| 112 |
public void saveScheme(int creatorId, CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException {
|
108 |
public void saveScheme(int creatorId, CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException {
|
| 113 |
|
109 |
|
| 114 |
this.validateCreateSchemeRequest(createSchemeRequest);
|
110 |
this.validateCreateSchemeRequest(createSchemeRequest);
|
| 115 |
|
111 |
|
| Line 157... |
Line 153... |
| 157 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(),
|
153 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(),
|
| 158 |
"SCHM_VE_1002");
|
154 |
"SCHM_VE_1002");
|
| 159 |
}
|
155 |
}
|
| 160 |
|
156 |
|
| 161 |
if (createSchemeRequest.getStartDate() == null) {
|
157 |
if (createSchemeRequest.getStartDate() == null) {
|
| 162 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.START_DATE,
|
158 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.START_DATE, createSchemeRequest.getStartDate(),
|
| 163 |
createSchemeRequest.getStartDate(), "SCHM_VE_1003");
|
159 |
"SCHM_VE_1003");
|
| 164 |
}
|
160 |
}
|
| 165 |
if (createSchemeRequest.getEndDate() == null) {
|
161 |
if (createSchemeRequest.getEndDate() == null) {
|
| 166 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.END_DATE,
|
162 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.END_DATE, createSchemeRequest.getEndDate(),
|
| 167 |
createSchemeRequest.getEndDate(), "SCHM_VE_1004");
|
163 |
"SCHM_VE_1004");
|
| 168 |
}
|
164 |
}
|
| 169 |
}
|
165 |
}
|
| 170 |
|
166 |
|
| 171 |
private Scheme toScheme(int creatorId, CreateSchemeRequest createSchemeRequest) {
|
167 |
private Scheme toScheme(int creatorId, CreateSchemeRequest createSchemeRequest) {
|
| 172 |
Scheme scheme = new Scheme();
|
168 |
Scheme scheme = new Scheme();
|
| Line 218... |
Line 214... |
| 218 |
}
|
214 |
}
|
| 219 |
List<Integer> itemIds = schemeItemRepository.selectItemIdsBySchemeId(scheme.getId());
|
215 |
List<Integer> itemIds = schemeItemRepository.selectItemIdsBySchemeId(scheme.getId());
|
| 220 |
if (itemIds.size() > 0) {
|
216 |
if (itemIds.size() > 0) {
|
| 221 |
List<Item> items = itemRepository.selectByIds(new HashSet<>(itemIds));
|
217 |
List<Item> items = itemRepository.selectByIds(new HashSet<>(itemIds));
|
| 222 |
scheme.setItemStringMap(this.toItemStringMap(items));
|
218 |
scheme.setItemStringMap(this.toItemStringMap(items));
|
| 223 |
}
|
219 |
}
|
| 224 |
return scheme;
|
220 |
return scheme;
|
| 225 |
}
|
221 |
}
|
| 226 |
|
222 |
|
| 227 |
public Map<Integer, String> toItemStringMap(List<Item> items) {
|
223 |
public Map<Integer, String> toItemStringMap(List<Item> items) {
|
| 228 |
Map<Integer, String> itemMap = new HashMap<>();
|
224 |
Map<Integer, String> itemMap = new HashMap<>();
|
| Line 819... |
Line 815... |
| 819 |
throws Exception {
|
815 |
throws Exception {
|
| 820 |
Set<Integer> inventoryItemIdSet = new HashSet<>(inventoryItemIds);
|
816 |
Set<Integer> inventoryItemIdSet = new HashSet<>(inventoryItemIds);
|
| 821 |
float amountToRollback = 0;
|
817 |
float amountToRollback = 0;
|
| 822 |
List<SchemeInOut> schemes = schemeInOutRepository.selectByInventoryItemIds(inventoryItemIdSet);
|
818 |
List<SchemeInOut> schemes = schemeInOutRepository.selectByInventoryItemIds(inventoryItemIdSet);
|
| 823 |
for (SchemeInOut schemeInOut : schemes) {
|
819 |
for (SchemeInOut schemeInOut : schemes) {
|
| - |
|
820 |
if (schemeInOut.getRolledBackTimestamp() == null) {
|
| 824 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
821 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
| 825 |
schemeInOutRepository.persist(schemeInOut);
|
822 |
schemeInOutRepository.persist(schemeInOut);
|
| 826 |
amountToRollback += schemeInOut.getAmount();
|
823 |
amountToRollback += schemeInOut.getAmount();
|
| - |
|
824 |
}
|
| 827 |
}
|
825 |
}
|
| 828 |
if (schemes.size() > 0) {
|
826 |
if (amountToRollback > 0) {
|
| 829 |
int inventoryItemId = inventoryItemIds.get(0);
|
827 |
int inventoryItemId = inventoryItemIds.get(0);
|
| 830 |
Integer fofoId = inventoryItemRepository.selectById(inventoryItemId).getFofoId();
|
828 |
Integer fofoId = inventoryItemRepository.selectById(inventoryItemId).getFofoId();
|
| 831 |
walletService.rollbackAmountFromWallet(fofoId, amountToRollback, rollbackReference,
|
829 |
walletService.rollbackAmountFromWallet(fofoId, amountToRollback, rollbackReference,
|
| 832 |
WalletReferenceType.SCHEME_IN, rollbackReason);
|
830 |
WalletReferenceType.SCHEME_IN, rollbackReason);
|
| 833 |
}
|
831 |
}
|
| Line 882... |
Line 880... |
| 882 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIds, 0, schemeIds.size()).stream()
|
880 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIds, 0, schemeIds.size()).stream()
|
| 883 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
881 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 884 |
for (SchemeInOut schemeInOut : schemeInOuts) {
|
882 |
for (SchemeInOut schemeInOut : schemeInOuts) {
|
| 885 |
InventoryItem ii = inventoryItemsMap.get(schemeInOut.getInventoryItemId());
|
883 |
InventoryItem ii = inventoryItemsMap.get(schemeInOut.getInventoryItemId());
|
| 886 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
884 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
| 887 |
if(scheme.getAmountType().equals(AmountType.FIXED)) continue;
|
885 |
if (scheme.getAmountType().equals(AmountType.FIXED))
|
| - |
|
886 |
continue;
|
| - |
|
887 |
|
| 888 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
888 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
| 889 |
schemeInOutRepository.persist(schemeInOut);
|
889 |
schemeInOutRepository.persist(schemeInOut);
|
| - |
|
890 |
|
| 890 |
SchemeInOut sioNew = new SchemeInOut();
|
891 |
SchemeInOut sioNew = new SchemeInOut();
|
| 891 |
sioNew.setAmount(getAmount(ii,scheme));
|
892 |
sioNew.setAmount(getAmount(ii, scheme));
|
| 892 |
sioNew.setInventoryItemId(schemeInOut.getInventoryItemId());
|
893 |
sioNew.setInventoryItemId(schemeInOut.getInventoryItemId());
|
| 893 |
sioNew.setSchemeId(schemeInOut.getSchemeId());
|
894 |
sioNew.setSchemeId(schemeInOut.getSchemeId());
|
| 894 |
schemeInOutRepository.persist(sioNew);
|
895 |
schemeInOutRepository.persist(sioNew);
|
| 895 |
amountToRollback += schemeInOut.getAmount();
|
896 |
amountToRollback += schemeInOut.getAmount();
|
| 896 |
amountToCredit += sioNew.getAmount();
|
897 |
amountToCredit += sioNew.getAmount();
|
| 897 |
}
|
898 |
}
|
| 898 |
if (amountToRollback > 0 && amountToCredit > 0) {
|
899 |
if (amountToRollback > 0 && amountToCredit > 0) {
|
| 899 |
int fofoId = inventoryItems.get(0).getFofoId();
|
900 |
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,
|
901 |
walletService.addAmountToWallet(fofoId, reversalReference, WalletReferenceType.PRICE_DROP, reversalReason,
|
| 903 |
amountToCredit);
|
902 |
amountToRollback);
|
| 904 |
}
|
903 |
}
|
| 905 |
}
|
904 |
}
|
| 906 |
|
905 |
|
| 907 |
}
|
906 |
}
|