Subversion Repositories SmartDukaan

Rev

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

Rev 28969 Rev 28979
Line 405... Line 405...
405
 
405
 
406
	@Override
406
	@Override
407
	public void processSchemeIn(int purchaseId, int retailerId) throws ProfitMandiBusinessException {
407
	public void processSchemeIn(int purchaseId, int retailerId) throws ProfitMandiBusinessException {
408
		LOGGER.info("Trying to process SchemeIn with purchaseId [{}] and retailerId [{}]", purchaseId, retailerId);
408
		LOGGER.info("Trying to process SchemeIn with purchaseId [{}] and retailerId [{}]", purchaseId, retailerId);
409
		Purchase purchase = purchaseRepository.selectByIdAndFofoId(purchaseId, retailerId);
409
		Purchase purchase = purchaseRepository.selectByIdAndFofoId(purchaseId, retailerId);
-
 
410
		//TODO - SCHEME
410
		PartnerType partnerType = partnerTypeChangeService.getTypeOnMonth(retailerId, YearMonth.from(purchase.getCreateTimestamp()));
411
		//PartnerType partnerType = partnerTypeChangeService.getTypeOnMonth(retailerId, YearMonth.from(purchase.getCreateTimestamp()));
-
 
412
		PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId, purchase.getCreateTimestamp().toLocalDate());
-
 
413
		
411
		List<Scheme> schemes = schemeRepository.selectActiveAll(SchemeType.IN, partnerType,
414
		List<Scheme> schemes = schemeRepository.selectActiveAll(SchemeType.IN, partnerType,
412
				purchase.getCreateTimestamp(), false);
415
				purchase.getCreateTimestamp(), false);
413
		float totalCashback = 0;
416
		float totalCashback = 0;
414
		if (schemes.isEmpty()) {
417
		if (schemes.isEmpty()) {
415
			return;
418
			return;
Line 475... Line 478...
475
	}
478
	}
476
 
479
 
477
	private float createSchemeInOut(Scheme scheme, InventoryItem inventoryItem) {
480
	private float createSchemeInOut(Scheme scheme, InventoryItem inventoryItem) {
478
		List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAll(inventoryItem.getId());
481
		List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAll(inventoryItem.getId());
479
		float amountToCredit = 0;
482
		float amountToCredit = 0;
480
		if (schemeInOuts.stream().filter(x -> x.getRolledBackTimestamp() == null).collect(Collectors.toList())
483
		if (schemeInOuts.stream().filter(x -> x.getRolledBackTimestamp() == null && x.getSchemeId()==scheme.getId()).collect(Collectors.toList())
481
				.size() == 0) {
484
				.size() == 0) {
482
			SchemeInOut schemeInOut = new SchemeInOut();
485
			SchemeInOut schemeInOut = new SchemeInOut();
483
			amountToCredit = this.getAmount(inventoryItem, scheme);
486
			amountToCredit = this.getAmount(inventoryItem, scheme);
484
			schemeInOut.setSchemeId(scheme.getId());
487
			schemeInOut.setSchemeId(scheme.getId());
485
			schemeInOut.setInventoryItemId(inventoryItem.getId());
488
			schemeInOut.setInventoryItemId(inventoryItem.getId());
Line 562... Line 565...
562
	@Override
565
	@Override
563
	public void processSchemeOut(int fofoOrderId, int retailerId) throws ProfitMandiBusinessException {
566
	public void processSchemeOut(int fofoOrderId, int retailerId) throws ProfitMandiBusinessException {
564
		FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(retailerId, fofoOrderId);
567
		FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(retailerId, fofoOrderId);
565
		//Process only if order is not cancelled
568
		//Process only if order is not cancelled
566
		if(fofoOrder.getCancelledTimestamp()==null) {
569
		if(fofoOrder.getCancelledTimestamp()==null) {
567
			//PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId,
570
			PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId, fofoOrder.getCreateTimestamp().toLocalDate());
568
			//		fofoOrder.getCreateTimestamp().toLocalDate());
-
 
569
			
571
			//TODO - SCHEME
570
			PartnerType partnerType = partnerTypeChangeService.getTypeOnMonth(retailerId, YearMonth.from(fofoOrder.getCreateTimestamp()));
572
			//PartnerType partnerType = partnerTypeChangeService.getTypeOnMonth(retailerId, YearMonth.from(fofoOrder.getCreateTimestamp()));
571
			
573
			
572
			List<ScanRecord> scanRecords = scanRecordRepository.selectAllByOrderId(fofoOrderId);
574
			List<ScanRecord> scanRecords = scanRecordRepository.selectAllByOrderId(fofoOrderId);
573
			Set<Integer> inventoryItemIds = scanRecords.stream().map(x -> x.getInventoryItemId())
575
			Set<Integer> inventoryItemIds = scanRecords.stream().map(x -> x.getInventoryItemId())
574
					.collect(Collectors.toSet());
576
					.collect(Collectors.toSet());
575
			Set<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIds).stream()
577
			Set<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIds).stream()