| Line 40... |
Line 40... |
| 40 |
|
40 |
|
| 41 |
@Autowired
|
41 |
@Autowired
|
| 42 |
private ItemRepository itemRepository;
|
42 |
private ItemRepository itemRepository;
|
| 43 |
|
43 |
|
| 44 |
@Autowired
|
44 |
@Autowired
|
| 45 |
private UserAccountRepository userAccountRepository;
|
- |
|
| 46 |
|
- |
|
| 47 |
@Autowired
|
- |
|
| 48 |
private TransactionService transactionService;
|
- |
|
| 49 |
|
- |
|
| 50 |
@Autowired
|
- |
|
| 51 |
private CommonPaymentService commonPaymentService;
|
- |
|
| 52 |
|
- |
|
| 53 |
@Autowired
|
- |
|
| 54 |
private CartService cartService;
|
45 |
private BidService bidService;
|
| 55 |
|
46 |
|
| 56 |
@Autowired
|
47 |
@Autowired
|
| 57 |
SaholicCISTableRepository saholicCISTableRepository;
|
48 |
SaholicCISTableRepository saholicCISTableRepository;
|
| 58 |
|
49 |
|
| 59 |
@Autowired
|
50 |
@Autowired
|
| Line 76... |
Line 67... |
| 76 |
List<Item> items = itemRepository.selectAllByCatalogItemId(liquidation.getCatalogId());
|
67 |
List<Item> items = itemRepository.selectAllByCatalogItemId(liquidation.getCatalogId());
|
| 77 |
if (items.size() > 0) {
|
68 |
if (items.size() > 0) {
|
| 78 |
long remainingQty = 0;
|
69 |
long remainingQty = 0;
|
| 79 |
for (Item item : items) {
|
70 |
for (Item item : items) {
|
| 80 |
List<SaholicCISTable> saholicCISTable = saholicCISTableRepository.selectAllByItemId(item.getId());
|
71 |
List<SaholicCISTable> saholicCISTable = saholicCISTableRepository.selectAllByItemId(item.getId());
|
| 81 |
remainingQty += saholicCISTable.stream().filter(x -> x.getNetAvailability() > 0).count();
|
72 |
remainingQty += saholicCISTable.stream().mapToInt(SaholicCISTable::getAvailability).sum();
|
| 82 |
}
|
73 |
}
|
| 83 |
List<Bid> bids = bidRepository.selectAllBidByLiquidationIdAndStatus(liquidation.getId(), Arrays.asList(ProfitMandiConstants.BID_ENUM.PENDING, ProfitMandiConstants.BID_ENUM.PROCESSING));
|
74 |
List<Bid> bids = bidRepository.selectAllBidByLiquidationIdAndStatus(liquidation.getId(), Arrays.asList(ProfitMandiConstants.BID_ENUM.PENDING, ProfitMandiConstants.BID_ENUM.PROCESSING));
|
| 84 |
|
75 |
|
| 85 |
for (Bid bid : bids) {
|
76 |
for (Bid bid : bids) {
|
| 86 |
if (remainingQty >= bid.getQuantity()) {
|
77 |
if (remainingQty >= bid.getQuantity()) {
|
| 87 |
List<BulkOrderModel> bulkOrderModels = new ArrayList<>();
|
78 |
List<BulkOrderModel> bulkOrderModels = new ArrayList<>();
|
| 88 |
BulkOrderModel bulkOrderModel = new BulkOrderModel();
|
79 |
BulkOrderModel bulkOrderModel = new BulkOrderModel();
|
| - |
|
80 |
bulkOrderModel.setRowIndex(bid.getId());
|
| 89 |
bulkOrderModel.setFofoId(bid.getFofoId());
|
81 |
bulkOrderModel.setFofoId(bid.getFofoId());
|
| 90 |
bulkOrderModel.setItemId(items.get(0).getId());
|
82 |
bulkOrderModel.setItemId(items.get(0).getId());
|
| 91 |
bulkOrderModel.setQuantity(bid.getQuantity());
|
83 |
bulkOrderModel.setQuantity(bid.getQuantity());
|
| 92 |
bulkOrderModel.setDescription(items.get(0).getItemDescription());
|
84 |
bulkOrderModel.setDescription(items.get(0).getItemDescription());
|
| 93 |
bulkOrderModel.setItemPrice(bid.getBiddingAmount());
|
85 |
bulkOrderModel.setItemPrice(bid.getBiddingAmount());
|
| 94 |
|
86 |
|
| 95 |
bulkOrderModels.add(bulkOrderModel);
|
87 |
bulkOrderModels.add(bulkOrderModel);
|
| 96 |
|
88 |
|
| 97 |
bulkOrderService.generatePurchaseOrder(bulkOrderModels, bid.getFofoId(), ProfitMandiConstants.PO_TYPE.AUTO);
|
89 |
bulkOrderService.generatePurchaseOrder(bulkOrderModels, bid.getFofoId(), ProfitMandiConstants.PO_TYPE.AUTO, type);
|
| 98 |
remainingQty -= bid.getQuantity();
|
90 |
remainingQty -= bid.getQuantity();
|
| - |
|
91 |
} else {
|
| 99 |
//this.generatePurchaseOrder(liquidation, bid, item, remainingQty, type);
|
92 |
bidService.cancelYesterdayProcessBid(bid.getId());
|
| 100 |
}
|
93 |
}
|
| 101 |
}
|
94 |
}
|
| 102 |
liquidation.setQuantity((int) remainingQty);
|
95 |
liquidation.setQuantity((int) remainingQty);
|
| 103 |
liquidation.setStatus(ProfitMandiConstants.LIQUIDATION_ENUM.CLOSED);
|
96 |
liquidation.setStatus(ProfitMandiConstants.LIQUIDATION_ENUM.CLOSED);
|
| 104 |
}
|
97 |
}
|
| 105 |
}
|
98 |
}
|
| 106 |
}
|
99 |
}
|
| 107 |
}
|
100 |
}
|
| 108 |
|
- |
|
| 109 |
public void generatePurchaseOrder(Liquidation liquidation, Bid bid, Item item, long remainingQty, ProfitMandiConstants.BID_CRON_ENUM type) throws Exception {
|
- |
|
| 110 |
UserCart uc = userAccountRepository.getUserCart(bid.getFofoId());
|
- |
|
| 111 |
double walletAmount = walletService.getWalletAmount(uc.getUserId());
|
- |
|
| 112 |
double orderAmount = (bid.getBiddingAmount() * bid.getQuantity());
|
- |
|
| 113 |
|
- |
|
| 114 |
if (walletAmount >= orderAmount) {
|
- |
|
| 115 |
List<CartItem> cartItems = new ArrayList<>();
|
- |
|
| 116 |
CartItem cartItem = new CartItem();
|
- |
|
| 117 |
cartItem.setItemId(item.getId());
|
- |
|
| 118 |
cartItem.setQuantity(bid.getQuantity());
|
- |
|
| 119 |
cartItem.setSellingPrice(bid.getBiddingAmount());
|
- |
|
| 120 |
cartItems.add(cartItem);
|
- |
|
| 121 |
cartService.addItemsToCart(uc.getCartId(), cartItems);
|
- |
|
| 122 |
liquidation.setQuantity((int) remainingQty - bid.getQuantity());
|
- |
|
| 123 |
bid.setStatus(ProfitMandiConstants.BID_ENUM.CLOSED);
|
- |
|
| 124 |
int transactionId = transactionService.createTransaction(uc, orderAmount, 0);
|
- |
|
| 125 |
commonPaymentService.payThroughWallet(transactionId);
|
- |
|
| 126 |
} else {
|
- |
|
| 127 |
if (remainingQty <= bid.getQuantity() || (type.equals(ProfitMandiConstants.BID_CRON_ENUM.YESTERDAY))){
|
- |
|
| 128 |
bid.setStatus(ProfitMandiConstants.BID_ENUM.CANCELLED);
|
- |
|
| 129 |
} else {
|
- |
|
| 130 |
bid.setStatus(ProfitMandiConstants.BID_ENUM.PROCESSING);
|
- |
|
| 131 |
liquidation.setQuantity((int) remainingQty - bid.getQuantity());
|
- |
|
| 132 |
bulkOrderService.notifyPartnerRBM(walletAmount, orderAmount, bid.getFofoId());
|
- |
|
| 133 |
}
|
- |
|
| 134 |
}
|
- |
|
| 135 |
}
|
- |
|
| 136 |
|
- |
|
| 137 |
|
- |
|
| 138 |
}
|
101 |
}
|