Subversion Repositories SmartDukaan

Rev

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

Rev 23512 Rev 23527
Line 5... Line 5...
5
import java.util.HashMap;
5
import java.util.HashMap;
6
import java.util.HashSet;
6
import java.util.HashSet;
7
import java.util.List;
7
import java.util.List;
8
import java.util.Map;
8
import java.util.Map;
9
import java.util.Set;
9
import java.util.Set;
10
import java.util.stream.Collectors;
-
 
11
 
10
 
12
import org.slf4j.Logger;
11
import org.slf4j.Logger;
13
import org.slf4j.LoggerFactory;
12
import org.slf4j.LoggerFactory;
14
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.stereotype.Component;
14
import org.springframework.stereotype.Component;
Line 29... Line 28...
29
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
28
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
30
import com.spice.profitmandi.dao.entity.fofo.Purchase;
29
import com.spice.profitmandi.dao.entity.fofo.Purchase;
31
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
30
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
32
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
31
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
33
import com.spice.profitmandi.dao.entity.transaction.Order;
32
import com.spice.profitmandi.dao.entity.transaction.Order;
34
import com.spice.profitmandi.dao.enumuration.catalog.SchemeAmountType;
33
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
35
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
34
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
36
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
35
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
37
import com.spice.profitmandi.dao.repository.catalog.RetailerSchemeRepository;
36
import com.spice.profitmandi.dao.repository.catalog.RetailerSchemeRepository;
38
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
37
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
39
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
38
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
Line 140... Line 139...
140
		if (createSchemeRequest.getAmount() <= 0) {
139
		if (createSchemeRequest.getAmount() <= 0) {
141
			throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(),
140
			throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(),
142
					"SCHM_VE_1001");
141
					"SCHM_VE_1001");
143
		}
142
		}
144
 
143
 
145
		if (SchemeAmountType.valueOf(createSchemeRequest.getAmountType()) == SchemeAmountType.PERCENTAGE
144
		if (AmountType.valueOf(createSchemeRequest.getAmountType()) == AmountType.PERCENTAGE
146
				&& createSchemeRequest.getAmount() > 100) {
145
				&& createSchemeRequest.getAmount() > 100) {
147
			throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(),
146
			throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(),
148
					"SCHM_VE_1002");
147
					"SCHM_VE_1002");
149
		}
148
		}
150
 
149
 
Line 164... Line 163...
164
	private Scheme toScheme(int creatorId, CreateSchemeRequest createSchemeRequest) {
163
	private Scheme toScheme(int creatorId, CreateSchemeRequest createSchemeRequest) {
165
		Scheme scheme = new Scheme();
164
		Scheme scheme = new Scheme();
166
		scheme.setName(createSchemeRequest.getName());
165
		scheme.setName(createSchemeRequest.getName());
167
		scheme.setDescription(createSchemeRequest.getDescription());
166
		scheme.setDescription(createSchemeRequest.getDescription());
168
		scheme.setType(SchemeType.valueOf(createSchemeRequest.getType()));
167
		scheme.setType(SchemeType.valueOf(createSchemeRequest.getType()));
169
		scheme.setAmountType(SchemeAmountType.valueOf(createSchemeRequest.getAmountType()));
168
		scheme.setAmountType(AmountType.valueOf(createSchemeRequest.getAmountType()));
170
		scheme.setAmount(createSchemeRequest.getAmount());
169
		scheme.setAmount(createSchemeRequest.getAmount());
171
		scheme.setStartDateTime(StringUtils.toDateTime(createSchemeRequest.getStartDateTimeString(),
170
		scheme.setStartDateTime(StringUtils.toDateTime(createSchemeRequest.getStartDateTimeString(),
172
				DateTimePattern.DD_MM_YYYY_T_HH_MM_SS));
171
				DateTimePattern.DD_MM_YYYY_T_HH_MM_SS));
173
		scheme.setEndDateTime(StringUtils.toDateTime(createSchemeRequest.getEndDateTimeString(),
172
		scheme.setEndDateTime(StringUtils.toDateTime(createSchemeRequest.getEndDateTimeString(),
174
				DateTimePattern.DD_MM_YYYY_T_HH_MM_SS));
173
				DateTimePattern.DD_MM_YYYY_T_HH_MM_SS));
Line 677... Line 676...
677
	private float getAmount(InventoryItem inventoryItem, Scheme scheme) {
676
	private float getAmount(InventoryItem inventoryItem, Scheme scheme) {
678
		float amount = 0;
677
		float amount = 0;
679
		float totalTaxRate = inventoryItem.getIgstRate() + inventoryItem.getSgstRate() + inventoryItem.getCgstRate();
678
		float totalTaxRate = inventoryItem.getIgstRate() + inventoryItem.getSgstRate() + inventoryItem.getCgstRate();
680
		float taxableSellingPrice = inventoryItem.getUnitPrice() / (1 + totalTaxRate / 100);
679
		float taxableSellingPrice = inventoryItem.getUnitPrice() / (1 + totalTaxRate / 100);
681
 
680
 
682
		if (scheme.getAmountType() == SchemeAmountType.PERCENTAGE) {
681
		if (scheme.getAmountType() == AmountType.PERCENTAGE) {
683
			amount = taxableSellingPrice * scheme.getAmount() / 100;
682
			amount = taxableSellingPrice * scheme.getAmount() / 100;
684
		} else {
683
		} else {
685
			amount = scheme.getAmount();
684
			amount = scheme.getAmount();
686
		}
685
		}
687
		return amount;
686
		return amount;
Line 816... Line 815...
816
	public void rollbackSchemes(List<InventoryItem> inventoryItems, int rollbackReference, String rollbackReason) {
815
	public void rollbackSchemes(List<InventoryItem> inventoryItems, int rollbackReference, String rollbackReason) {
817
		Set<Integer> inventoryItemIdSet = new HashSet<>(inventoryItems.stream().map(x->x.getId()).collect(Collectors.toList()));
816
		Set<Integer> inventoryItemIdSet = new HashSet<>(inventoryItems.stream().map(x->x.getId()).collect(Collectors.toList()));
818
		float amountToRollback = 0;
817
		float amountToRollback = 0;
819
		List<SchemeInOut> schemes = schemeInOutRepository.selectByInventoryItemIds(inventoryItemIdSet);
818
		List<SchemeInOut> schemes = schemeInOutRepository.selectByInventoryItemIds(inventoryItemIdSet);
820
		for(SchemeInOut schemeInOut: schemes) {
819
		for(SchemeInOut schemeInOut: schemes) {
821
			schemeInOut.setRolled_back_timestamp(LocalDateTime.now());
820
			schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
822
			schemeInOutRepository.persist(schemeInOut);
821
			schemeInOutRepository.persist(schemeInOut);
823
			amountToRollback += schemeInOut.getAmount();
822
			amountToRollback += schemeInOut.getAmount();
824
		}
823
		}
825
		walletService.rollbackAmountFromWallet(inventoryItems.get(0).getFofoId(), amountToRollback, rollbackReference, WalletReferenceType.SCHEME_IN, rollbackReason);
824
		walletService.rollbackAmountFromWallet(inventoryItems.get(0).getFofoId(), amountToRollback, rollbackReference, WalletReferenceType.SCHEME_IN, rollbackReason);
826
	}
825
	}