Subversion Repositories SmartDukaan

Rev

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

Rev 23511 Rev 23512
Line 711... Line 711...
711
	public void processSchemeOut(int fofoOrderId, int retailerId) throws ProfitMandiBusinessException {
711
	public void processSchemeOut(int fofoOrderId, int retailerId) throws ProfitMandiBusinessException {
712
		FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(retailerId, fofoOrderId);
712
		FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(retailerId, fofoOrderId);
713
		List<Scheme> schemes = schemeRepository.selectActiveAll(SchemeType.OUT, LocalDateTime.now());
713
		List<Scheme> schemes = schemeRepository.selectActiveAll(SchemeType.OUT, LocalDateTime.now());
714
		LOGGER.info("Active Schemes {}", schemes);
714
		LOGGER.info("Active Schemes {}", schemes);
715
		float totalCashback = 0;
715
		float totalCashback = 0;
-
 
716
		int count = 0;
716
		if (schemes.isEmpty()) {
717
		if (schemes.isEmpty()) {
717
			return;
718
			return;
718
		}
719
		}
719
 
720
 
720
		List<FofoOrderItem> fofoOrderItems = orderService.getByOrderId(fofoOrderId);
721
		List<FofoOrderItem> fofoOrderItems = orderService.getByOrderId(fofoOrderId);
Line 757... Line 758...
757
				.entrySet()) {
758
				.entrySet()) {
758
			for (FofoLineItem fofoLineItem : allFofoOrderItemSchemesEntry.getKey().getFofoLineItems()) {
759
			for (FofoLineItem fofoLineItem : allFofoOrderItemSchemesEntry.getKey().getFofoLineItems()) {
759
				for (Scheme scheme : allFofoOrderItemSchemesEntry.getValue()) {
760
				for (Scheme scheme : allFofoOrderItemSchemesEntry.getValue()) {
760
					float cashback = this.createSchemeInOut(scheme,
761
					float cashback = this.createSchemeInOut(scheme,
761
							inventoryItemIdInventoryItemMap.get(fofoLineItem.getInventoryItemId()));
762
							inventoryItemIdInventoryItemMap.get(fofoLineItem.getInventoryItemId()));
-
 
763
					if(cashback > 0) {
762
					totalCashback = totalCashback + cashback;
764
						totalCashback = totalCashback + cashback;
-
 
765
						count += 1;
-
 
766
					}
763
				}
767
				}
764
			}
768
			}
765
		}
769
		}
766
 
770
 
767
		Set<Integer> schemeIds = this.fofoLineItemSchemesMapToSchemeIds(notAllFofoOrderItemSchemesMap);
771
		Set<Integer> schemeIds = this.fofoLineItemSchemesMapToSchemeIds(notAllFofoOrderItemSchemesMap);
Line 775... Line 779...
775
					for (Scheme scheme : notAllFofoOrderItemSchemesEntry.getValue()) {
779
					for (Scheme scheme : notAllFofoOrderItemSchemesEntry.getValue()) {
776
						if (foundSchemeIds.contains(scheme.getId())) {
780
						if (foundSchemeIds.contains(scheme.getId())) {
777
							float cashback = this.createSchemeInOut(scheme,
781
							float cashback = this.createSchemeInOut(scheme,
778
									inventoryItemIdInventoryItemMap.get(fofoLineItem.getInventoryItemId()));
782
									inventoryItemIdInventoryItemMap.get(fofoLineItem.getInventoryItemId()));
779
							totalCashback = totalCashback + cashback;
783
							totalCashback = totalCashback + cashback;
-
 
784
							if(cashback > 0) {
-
 
785
								totalCashback = totalCashback + cashback;
-
 
786
								count += 1;
-
 
787
							}
780
						}
788
						}
781
					}
789
					}
782
				}
790
				}
783
			}
791
			}
784
		}
792
		}
785
		if (totalCashback > 0) {
793
		if (totalCashback > 0) {
786
			walletService.addAmountToWallet(retailerId, fofoOrderId, WalletReferenceType.SCHEME_OUT,
794
			walletService.addAmountToWallet(retailerId, fofoOrderId, WalletReferenceType.SCHEME_OUT,
787
					"Added for SCHEME_OUT", totalCashback);
795
					"Sales margin for invoice number " + fofoOrder.getInvoiceNumber() + ". Total " + count + " pc(s)", totalCashback);
788
			fofoOrder.setCashback(totalCashback);
796
			fofoOrder.setCashback(totalCashback);
789
			fofoOrderRepository.persist(fofoOrder);
797
			fofoOrderRepository.persist(fofoOrder);
790
		}
798
		}
791
	}
799
	}
792
 
800