Subversion Repositories SmartDukaan

Rev

Rev 24266 | Rev 24645 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24266 Rev 24641
Line 7... Line 7...
7
import java.util.Collections;
7
import java.util.Collections;
8
import java.util.HashMap;
8
import java.util.HashMap;
9
import java.util.HashSet;
9
import java.util.HashSet;
10
import java.util.List;
10
import java.util.List;
11
import java.util.Map;
11
import java.util.Map;
-
 
12
import java.util.stream.Collectors;
12
 
13
 
13
import org.apache.commons.lang.StringUtils;
14
import org.apache.commons.lang.StringUtils;
14
import org.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.Logger;
16
import org.apache.logging.log4j.Logger;
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.beans.factory.annotation.Autowired;
Line 188... Line 189...
188
	}
189
	}
189
 
190
 
190
	public void cancelOrder(List<String> invoiceNumbers) throws Exception {
191
	public void cancelOrder(List<String> invoiceNumbers) throws Exception {
191
		orderService.cancelOrder(invoiceNumbers);
192
		orderService.cancelOrder(invoiceNumbers);
192
	}
193
	}
-
 
194
	
-
 
195
	
-
 
196
	public void migratePurchase() {
-
 
197
		List<Purchase> purchases = purchaseRepository.selectPurchaseAllPurchasesLessThanZero();
-
 
198
		for(Purchase purchase : purchases) {
-
 
199
			List<InventoryItem> inventoryItems =  inventoryItemRepository.selectByPurchaseId(purchase.getId());
-
 
200
			List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(purchase.getPurchaseReference(), purchase.getFofoId());
-
 
201
			Map<Integer, Integer> ourSaleItemQtyMap = orders.stream().collect(Collectors.groupingBy(x->x.getLineItem().getItemId(), 
-
 
202
					Collectors.summingInt(x->x.getLineItem().getQuantity())));
-
 
203
			Map<Integer, Integer> theirPurchaseItemQtyMap = inventoryItems.stream().collect(Collectors.groupingBy(InventoryItem::getItemId, 
-
 
204
					Collectors.summingInt(InventoryItem::getInitialQuantity)));
-
 
205
			for (Map.Entry<Integer, Integer> partnerPurchaseEntry : theirPurchaseItemQtyMap.entrySet()) {
-
 
206
				int ourSale = ourSaleItemQtyMap.get(partnerPurchaseEntry.getKey());
-
 
207
				if(partnerPurchaseEntry.getValue() - ourSale > 0) {
-
 
208
					int quantityToReduce = partnerPurchaseEntry.getValue() - ourSale;
-
 
209
					for(InventoryItem ii : inventoryItems) {
-
 
210
						if(ii.getGoodQuantity() >= quantityToReduce && ii.getInitialQuantity() > quantityToReduce) {
-
 
211
							LOGGER.info("Invoice {} item {} can be reduced to {}", purchase.getPurchaseReference(), ii.getItemId(), ii.getGoodQuantity() - quantityToReduce);
-
 
212
						}
-
 
213
					}
-
 
214
				}
-
 
215
			}
-
 
216
		}
-
 
217
	}
193
}
218
}
194
219