| Line 212... |
Line 212... |
| 212 |
|
212 |
|
| 213 |
public void migratePurchase() throws Exception {
|
213 |
public void migratePurchase() throws Exception {
|
| 214 |
List<Purchase> purchases = purchaseRepository.selectPurchaseAllPurchasesLessThanZero();
|
214 |
List<Purchase> purchases = purchaseRepository.selectPurchaseAllPurchasesLessThanZero();
|
| 215 |
System.out.printf("Total Purchases count is %s", purchases.size());
|
215 |
System.out.printf("Total Purchases count is %s", purchases.size());
|
| 216 |
for (Purchase purchase : purchases) {
|
216 |
for (Purchase purchase : purchases) {
|
| 217 |
System.out.printf("Got purchase id %d\n", purchase.getId());
|
- |
|
| 218 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchase.getId());
|
217 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchase.getId());
|
| 219 |
Map<Integer, List<InventoryItem>> itemIdInventoryMap = inventoryItems.stream()
|
218 |
Map<Integer, List<InventoryItem>> itemIdInventoryMap = inventoryItems.stream()
|
| 220 |
.collect(Collectors.groupingBy(InventoryItem::getItemId));
|
219 |
.collect(Collectors.groupingBy(InventoryItem::getItemId));
|
| 221 |
List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(purchase.getPurchaseReference(),
|
220 |
List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(purchase.getPurchaseReference(),
|
| 222 |
purchase.getFofoId());
|
221 |
purchase.getFofoId());
|
| Line 246... |
Line 245... |
| 246 |
if (scanRecord.getType().equals(ScanType.PURCHASE)) {
|
245 |
if (scanRecord.getType().equals(ScanType.PURCHASE)) {
|
| 247 |
CurrentInventorySnapshot cis = currentInventorySnapshotRepository
|
246 |
CurrentInventorySnapshot cis = currentInventorySnapshotRepository
|
| 248 |
.selectByItemIdAndFofoId(itemQtyEntry.getKey(), purchase.getFofoId());
|
247 |
.selectByItemIdAndFofoId(itemQtyEntry.getKey(), purchase.getFofoId());
|
| 249 |
if (cis.getAvailability() - quantityToReduce >= 0) {
|
248 |
if (cis.getAvailability() - quantityToReduce >= 0) {
|
| 250 |
scanRecord.setQuantity(scanRecord.getQuantity() - quantityToReduce);
|
249 |
scanRecord.setQuantity(scanRecord.getQuantity() - quantityToReduce);
|
| - |
|
250 |
ii.setInitialQuantity(ii.getInitialQuantity() - quantityToReduce);
|
| 251 |
genericRepository.delete(ii);
|
251 |
ii.setGoodQuantity(ii.getGoodQuantity() - quantityToReduce);
|
| 252 |
cis.setAvailability(cis.getAvailability() - quantityToReduce);
|
252 |
cis.setAvailability(cis.getAvailability() - quantityToReduce);
|
| 253 |
purchase.setUnfullfilledNonSerializedQuantity(
|
253 |
purchase.setUnfullfilledNonSerializedQuantity(
|
| 254 |
purchase.getUnfullfilledNonSerializedQuantity() + quantityToReduce);
|
254 |
purchase.getUnfullfilledNonSerializedQuantity() + quantityToReduce);
|
| 255 |
LOGGER.info("Rectified {}, {}, {}, {}, {}, {}, {}",
|
255 |
LOGGER.info("Rectified {}, {}, {}, {}, {}, {}, {}",
|
| 256 |
purchase.getPurchaseReference(), ii.getId(), ii.getItemId(),
|
256 |
purchase.getPurchaseReference(), ii.getId(), ii.getItemId(),
|