Subversion Repositories SmartDukaan

Rev

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

Rev 28980 Rev 29585
Line 4... Line 4...
4
import java.io.ByteArrayOutputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.InputStream;
5
import java.io.InputStream;
6
import java.time.LocalDate;
6
import java.time.LocalDate;
7
import java.time.LocalDateTime;
7
import java.time.LocalDateTime;
8
import java.time.LocalTime;
8
import java.time.LocalTime;
9
import java.time.YearMonth;
9
import java.time.Month;
10
import java.util.ArrayList;
10
import java.util.ArrayList;
11
import java.util.Arrays;
11
import java.util.Arrays;
12
import java.util.HashMap;
12
import java.util.HashMap;
13
import java.util.HashSet;
13
import java.util.HashSet;
14
import java.util.List;
14
import java.util.List;
Line 33... Line 33...
33
import org.springframework.web.bind.annotation.RequestMapping;
33
import org.springframework.web.bind.annotation.RequestMapping;
34
import org.springframework.web.bind.annotation.RequestMethod;
34
import org.springframework.web.bind.annotation.RequestMethod;
35
import org.springframework.web.bind.annotation.RequestParam;
35
import org.springframework.web.bind.annotation.RequestParam;
36
 
36
 
37
import com.spice.profitmandi.common.enumuration.DateTimePattern;
37
import com.spice.profitmandi.common.enumuration.DateTimePattern;
-
 
38
import com.spice.profitmandi.common.enumuration.ReporticoProject;
38
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
39
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
40
import com.spice.profitmandi.common.model.CustomRetailer;
39
import com.spice.profitmandi.common.model.MapWrapper;
41
import com.spice.profitmandi.common.model.MapWrapper;
40
import com.spice.profitmandi.common.model.ProfitMandiConstants;
42
import com.spice.profitmandi.common.model.ProfitMandiConstants;
41
import com.spice.profitmandi.common.model.SchemeItems;
43
import com.spice.profitmandi.common.model.SchemeItems;
42
import com.spice.profitmandi.common.model.SchemeModel;
44
import com.spice.profitmandi.common.model.SchemeModel;
-
 
45
import com.spice.profitmandi.common.services.ReporticoService;
43
import com.spice.profitmandi.common.util.ExcelUtils;
46
import com.spice.profitmandi.common.util.ExcelUtils;
-
 
47
import com.spice.profitmandi.common.util.FileUtil;
44
import com.spice.profitmandi.common.util.FormattingUtils;
48
import com.spice.profitmandi.common.util.FormattingUtils;
45
import com.spice.profitmandi.common.util.StringUtils;
49
import com.spice.profitmandi.common.util.StringUtils;
46
import com.spice.profitmandi.common.util.Utils;
50
import com.spice.profitmandi.common.util.Utils;
47
import com.spice.profitmandi.common.web.util.ResponseSender;
51
import com.spice.profitmandi.common.web.util.ResponseSender;
-
 
52
import com.spice.profitmandi.dao.entity.catalog.EvaluateSchemeInvestmentPayoutModel;
48
import com.spice.profitmandi.dao.entity.catalog.Item;
53
import com.spice.profitmandi.dao.entity.catalog.Item;
49
import com.spice.profitmandi.dao.entity.catalog.Scheme;
54
import com.spice.profitmandi.dao.entity.catalog.Scheme;
50
import com.spice.profitmandi.dao.entity.catalog.TagListing;
55
import com.spice.profitmandi.dao.entity.catalog.TagListing;
51
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
56
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
52
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
57
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
-
 
58
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
53
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
59
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
54
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
60
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
55
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
61
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
56
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
62
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
57
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
63
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
58
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
64
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
59
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
65
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
60
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
66
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
61
import com.spice.profitmandi.dao.model.CreateOfferRequest;
67
import com.spice.profitmandi.dao.model.CreateOfferRequest;
62
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
68
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
63
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
69
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
64
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
70
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
65
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
71
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
66
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
72
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
67
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
73
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
68
import com.spice.profitmandi.dao.repository.dtr.Mongo;
74
import com.spice.profitmandi.dao.repository.dtr.Mongo;
69
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
75
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
-
 
76
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
70
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
77
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
71
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
78
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
72
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
79
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
73
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
80
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
74
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
81
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
75
import com.spice.profitmandi.service.authentication.RoleManager;
82
import com.spice.profitmandi.service.authentication.RoleManager;
76
import com.spice.profitmandi.service.inventory.InventoryService;
83
import com.spice.profitmandi.service.inventory.InventoryService;
77
import com.spice.profitmandi.service.offers.OfferService;
84
import com.spice.profitmandi.service.offers.OfferService;
78
import com.spice.profitmandi.service.scheme.SchemeService;
85
import com.spice.profitmandi.service.scheme.SchemeService;
79
import com.spice.profitmandi.service.user.RetailerService;
86
import com.spice.profitmandi.service.user.RetailerService;
-
 
87
import com.spice.profitmandi.service.wallet.WalletService;
80
import com.spice.profitmandi.web.model.LoginDetails;
88
import com.spice.profitmandi.web.model.LoginDetails;
81
import com.spice.profitmandi.web.util.CookiesProcessor;
89
import com.spice.profitmandi.web.util.CookiesProcessor;
82
import com.spice.profitmandi.web.util.MVCResponseSender;
90
import com.spice.profitmandi.web.util.MVCResponseSender;
83
 
91
 
-
 
92
import in.shop2020.model.v1.order.WalletReferenceType;
-
 
93
 
84
@Controller
94
@Controller
85
@Transactional(rollbackOn = Throwable.class)
95
@Transactional(rollbackOn = Throwable.class)
86
public class SchemeController {
96
public class SchemeController {
87
 
97
 
88
	private static final Logger LOGGER = LogManager.getLogger(SchemeController.class);
98
	private static final Logger LOGGER = LogManager.getLogger(SchemeController.class);
Line 96... Line 106...
96
	@Autowired
106
	@Autowired
97
	private StateGstRateRepository stateGstRateRepository;
107
	private StateGstRateRepository stateGstRateRepository;
98
 
108
 
99
	@Autowired
109
	@Autowired
100
	private ItemRepository itemRepository;
110
	private ItemRepository itemRepository;
-
 
111
	
-
 
112
	
-
 
113
	@Autowired
-
 
114
	private ReporticoService reporticoService;
101
 
115
 
102
	@Autowired
116
	@Autowired
103
	private SchemeRepository schemeRepository;
117
	private SchemeRepository schemeRepository;
104
 
118
 
105
	@Autowired
119
	@Autowired
Line 130... Line 144...
130
	@Autowired
144
	@Autowired
131
	private RetailerService retailerService;
145
	private RetailerService retailerService;
132
 
146
 
133
	@Autowired
147
	@Autowired
134
	private Mongo mongoClient;
148
	private Mongo mongoClient;
-
 
149
	
-
 
150
	@Autowired
-
 
151
	WalletService walletService;
-
 
152
 
-
 
153
	@Autowired
-
 
154
	PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
-
 
155
 
135
 
156
 
136
	@Autowired
157
	@Autowired
137
	private PartnerTypeChangeService partnerTypeChangeService;
158
	private PartnerTypeChangeService partnerTypeChangeService;
138
 
159
 
139
	@Autowired
160
	@Autowired
Line 148... Line 169...
148
	@Autowired
169
	@Autowired
149
	SchemeInOutRepository schemeInOutRepository;
170
	SchemeInOutRepository schemeInOutRepository;
150
 
171
 
151
	@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
172
	@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
152
	public String createScheme(HttpServletRequest request, Model model) {
173
	public String createScheme(HttpServletRequest request, Model model) {
-
 
174
		
-
 
175
		LocalDate currentdate = LocalDate.now();
-
 
176
		Month month = currentdate.getMonth().minus(1);
-
 
177
		model.addAttribute("month", month);
-
 
178
		
153
		// Map<Integer, String> itemIdItemDescriptionMap =
179
		// Map<Integer, String> itemIdItemDescriptionMap =
154
		// inventoryService.getAllItemIdItemDescriptionMap();
180
		// inventoryService.getAllItemIdItemDescriptionMap();
155
		// model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
181
		// model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
156
		Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
182
		Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
157
		brands.addAll(inventoryService.getAllTagListingBrands(14206));
183
		brands.addAll(inventoryService.getAllTagListingBrands(14206));
158
		model.addAttribute("brands", brands);
184
		model.addAttribute("brands", brands);
159
		model.addAttribute("retailerTypes", PartnerType.values());
185
		model.addAttribute("retailerTypes", PartnerType.values());
160
		return "create-scheme";
186
		return "create-scheme";
161
	}
187
	}
-
 
188
	
-
 
189
	
162
 
190
 
163
	@RequestMapping(value = "/getTagListingItemsByBrand", method = RequestMethod.POST)
191
	@RequestMapping(value = "/getTagListingItemsByBrand", method = RequestMethod.POST)
164
	public String getTagListingItemsByBrand(HttpServletRequest request, @RequestBody List<String> brands, Model model) {
192
	public String getTagListingItemsByBrand(HttpServletRequest request, @RequestBody List<String> brands, Model model) {
165
		Map<Integer, String> itemIdItemDescriptionMap = new HashMap<>();
193
		Map<Integer, String> itemIdItemDescriptionMap = new HashMap<>();
166
		LOGGER.info("brands" + brands);
194
		LOGGER.info("brands" + brands);
Line 182... Line 210...
182
		if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
210
		if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
183
			throw new ProfitMandiBusinessException("User", loginDetails.getEmailId(), "Unauthorised access");
211
			throw new ProfitMandiBusinessException("User", loginDetails.getEmailId(), "Unauthorised access");
184
		}
212
		}
185
		return "update-schemes-page";
213
		return "update-schemes-page";
186
	}
214
	}
-
 
215
	
-
 
216
	
-
 
217
	@RequestMapping(value = "/payMonthlyInvestment", method = RequestMethod.POST)
-
 
218
	public void payMonthlyInvestment(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
-
 
219
		
-
 
220
		LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
-
 
221
		LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
-
 
222
		int referenceId = Integer.parseInt(FormattingUtils.getYearMonth(startOfPreviousMonth.atStartOfDay()));
-
 
223
		LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
-
 
224
		List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
-
 
225
				.selectAll(startOfPreviousMonth, lastOfPreviousMonth);
-
 
226
		Map<Integer, Long> investmentMaintainedDaysMap = partnerDailyInvestments.stream()
-
 
227
				.filter(x -> x.getShortPercentage() <= 10)
-
 
228
				.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
-
 
229
		LOGGER.info("investmentMaintainedDaysMap {}", investmentMaintainedDaysMap);
-
 
230
		List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAllPending(SchemeType.INVESTMENT,
-
 
231
				startOfPreviousMonth.atStartOfDay(), firstDateOfCurrentMonth.atStartOfDay());
-
 
232
		
-
 
233
		if(schemeInOuts.isEmpty()) 
-
 
234
		{
-
 
235
			throw new ProfitMandiBusinessException("Investment Payout", "",
-
 
236
					"No data Found");
-
 
237
		}
-
 
238
		
-
 
239
		Map<Integer, List<SchemeInOut>> inventoryItemIdSchemeMap = schemeInOuts.stream()
-
 
240
				.collect(Collectors.groupingBy(x -> x.getInventoryItemId()));
-
 
241
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIdSchemeMap.keySet());
-
 
242
		Map<Integer, List<Integer>> retailerInventoryItemIdMap = inventoryItems.stream().collect(
-
 
243
				Collectors.groupingBy(x -> x.getFofoId(), Collectors.mapping(x -> x.getId(), Collectors.toList())));
-
 
244
		System.out.println("Fofo Id\tInvestment Maintained Days\tEligible payout");
-
 
245
		for (Map.Entry<Integer, List<Integer>> retailerEntry : retailerInventoryItemIdMap.entrySet()) {
-
 
246
			int fofoId = retailerEntry.getKey();
-
 
247
			long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
-
 
248
					: investmentMaintainedDaysMap.get(fofoId);
-
 
249
 
-
 
250
			List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
-
 
251
					.flatMap(List::stream).filter(x -> x.getRolledBackTimestamp() == null).collect(Collectors.toList());
-
 
252
			float totalAmount = 0;
-
 
253
			for(SchemeInOut sio : schemeInouts) {
-
 
254
				
-
 
255
				if (investmentMaintainedDays < 8) {
-
 
256
					sio.setStatus(SchemePayoutStatus.REJECTED);
-
 
257
					//sio.setRolledBackTimestamp(LocalDateTime.now());
-
 
258
					sio.setStatusDescription("Investment maintained for " + investmentMaintainedDays + "(< 8) days");
-
 
259
				} else if (investmentMaintainedDays < 12) {
-
 
260
					sio.setStatus(SchemePayoutStatus.CREDITED);
-
 
261
					sio.setAmount(sio.getAmount()/2);
-
 
262
					sio.setCreditTimestamp(LocalDateTime.now());
-
 
263
					sio.setStatusDescription("Investment maintained for " + investmentMaintainedDays + "(< 12) days");
-
 
264
					totalAmount += sio.getAmount();
-
 
265
				} else {
-
 
266
					sio.setStatus(SchemePayoutStatus.CREDITED);
-
 
267
					sio.setCreditTimestamp(LocalDateTime.now());
-
 
268
					totalAmount += sio.getAmount();
-
 
269
				}
-
 
270
			}
-
 
271
			if(totalAmount > 0) {
-
 
272
				String description = "Investment margin paid for " + FormattingUtils.formatYearMonth(startOfPreviousMonth.atStartOfDay());
-
 
273
				if(investmentMaintainedDays < 12) {
-
 
274
					description += ", as maintained for " + investmentMaintainedDays  + "(< 12) days";
-
 
275
				}
-
 
276
				walletService.addAmountToWallet(fofoId,referenceId, WalletReferenceType.INVESTMENT_PAYOUT,  description, totalAmount, lastOfPreviousMonth.atTime(LocalTime.MAX));
-
 
277
			}
-
 
278
			System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
-
 
279
		}
-
 
280
		
-
 
281
		
-
 
282
	}
-
 
283
	
-
 
284
	@RequestMapping(value = "/evaluateActualInvestmentPayout", method = RequestMethod.GET)
-
 
285
   public ResponseEntity<?> evaluateActualInvestmentPayout(HttpServletRequest request,Model model) throws Exception {
-
 
286
		
-
 
287
		List<List<?>> rows = new ArrayList<>();
-
 
288
		LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
-
 
289
		LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
-
 
290
		LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
-
 
291
		List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
-
 
292
				.selectAll(startOfPreviousMonth, lastOfPreviousMonth);
-
 
293
		Map<Integer, Long> investmentMaintainedDaysMap = partnerDailyInvestments.stream()
-
 
294
				.filter(x -> x.getShortPercentage() <= 10)
-
 
295
				.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
-
 
296
		LOGGER.info("investmentMaintainedDaysMap {}", investmentMaintainedDaysMap);
-
 
297
		List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAllPending(SchemeType.INVESTMENT,
-
 
298
				startOfPreviousMonth.atStartOfDay(), firstDateOfCurrentMonth.atStartOfDay());
-
 
299
		Map<Integer, List<SchemeInOut>> inventoryItemIdSchemeMap = schemeInOuts.stream()
-
 
300
				.collect(Collectors.groupingBy(x -> x.getInventoryItemId()));
-
 
301
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIdSchemeMap.keySet());
-
 
302
		Map<Integer, List<Integer>> retailerInventoryItemIdMap = inventoryItems.stream().collect(
-
 
303
				Collectors.groupingBy(x -> x.getFofoId(), Collectors.mapping(x -> x.getId(), Collectors.toList())));
-
 
304
		System.out.println("Fofo Id\tInvestment Maintained Days\tEligible payout");
-
 
305
		for (Map.Entry<Integer, List<Integer>> retailerEntry : retailerInventoryItemIdMap.entrySet()) {
-
 
306
			int fofoId = retailerEntry.getKey();
-
 
307
			List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
-
 
308
					.flatMap(List::stream).collect(Collectors.toList());
-
 
309
			double totalAmount = schemeInouts.stream().filter(x -> x.getRolledBackTimestamp() == null)
-
 
310
					.collect(Collectors.summingDouble(x -> x.getAmount()));
-
 
311
			long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
-
 
312
					: investmentMaintainedDaysMap.get(fofoId);
-
 
313
			if (investmentMaintainedDays < 8) {
-
 
314
				totalAmount = 0;
-
 
315
			} else if (investmentMaintainedDays < 12) {
-
 
316
				totalAmount = totalAmount / 2;
-
 
317
			}
-
 
318
			System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
-
 
319
			CustomRetailer customRetailer= retailerService.getFofoRetailer(fofoId);
-
 
320
			
-
 
321
			 rows.add(Arrays.asList(fofoId,customRetailer.getBusinessName(),customRetailer.getCode(),investmentMaintainedDays,totalAmount));
-
 
322
		}
-
 
323
	
-
 
324
		
-
 
325
				org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
-
 
326
				.getCSVByteStream(Arrays.asList("fofoId","Name", "Code", "investmentMaintainedDays","totalAmount"), rows);
-
 
327
 
-
 
328
		final HttpHeaders headers = new HttpHeaders();
-
 
329
		headers.set("Content-Type", "text/csv");
-
 
330
		headers.set("Content-disposition", "inline; filename=investmentMaintainedDays.csv");
-
 
331
		headers.setContentLength(baos.toByteArray().length);
-
 
332
 
-
 
333
		final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
-
 
334
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
-
 
335
	
-
 
336
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
-
 
337
		
-
 
338
	}
-
 
339
	
-
 
340
	@RequestMapping(value = "/processInvestmentDryRun", method = RequestMethod.GET)
-
 
341
	   public ResponseEntity<?> processInvestmentDryRun(HttpServletRequest request,Model model) throws Exception {
-
 
342
			
-
 
343
		LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
-
 
344
		LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
-
 
345
		LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
-
 
346
		List<List<?>> rows = new ArrayList<>();
-
 
347
		
-
 
348
			Map<String, String> params = new HashMap<>();
-
 
349
			
-
 
350
			params.put("MANUAL_datesBetween_FROMDATE",firstDateOfCurrentMonth.toString());
-
 
351
			params.put("MANUAL_datesBetween_TODATE",firstDateOfCurrentMonth.plusDays(9).toString());
-
 
352
			
-
 
353
			params.put("type","INVESTMENT");
-
 
354
			
-
 
355
			List<EvaluateSchemeInvestmentPayoutModel> evaluateSchemeInvestmentPayouts = reporticoService.getReports(EvaluateSchemeInvestmentPayoutModel.class,
-
 
356
					ReporticoProject.FOCO, "schemepayout.xml", params);
-
 
357
			LOGGER.info("reportResponse {}", evaluateSchemeInvestmentPayouts);
-
 
358
			
-
 
359
			
-
 
360
			
-
 
361
			int referenceId = Integer.parseInt(FormattingUtils.getYearMonth(startOfPreviousMonth.atStartOfDay()));
-
 
362
		  List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
-
 
363
					.selectAll(startOfPreviousMonth, lastOfPreviousMonth);
-
 
364
			Map<Integer, Long> investmentMaintainedDaysMap = partnerDailyInvestments.stream()
-
 
365
					.filter(x -> x.getShortPercentage() <= 10)
-
 
366
					.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
-
 
367
			
-
 
368
			for (EvaluateSchemeInvestmentPayoutModel esip : evaluateSchemeInvestmentPayouts) {
-
 
369
 
-
 
370
				long investmentMaintainedDays = investmentMaintainedDaysMap.get(esip.getFofoId()) == null ? 0
-
 
371
						: investmentMaintainedDaysMap.get(esip.getFofoId());
-
 
372
				
-
 
373
				esip.setInvestmentDays(investmentMaintainedDays);
-
 
374
				
-
 
375
				float processAmount = esip.getPaidAmount()/2;
-
 
376
				
-
 
377
				esip.setProcessAmount(processAmount);
-
 
378
				
-
 
379
				rows.add(Arrays.asList(esip.getCode(),esip.getStoreName(),esip.getFofoId(),esip.getItemId(),esip.getBrand(),esip.getModelName(),esip.getModelNumber(),
-
 
380
						esip.getColor(),esip.getSchemeInDp(),esip.getSchemeOutDp(),esip.getSchemeId(),
-
 
381
						esip.getName(),esip.getType(),esip.getPartnerType(),esip.getAmountType(),esip.getAmount(),esip.getPurchaseInvoice(),esip.getSaleInovoice(),
-
 
382
						esip.getPaidAmount(),esip.getCreateTimestamp(),esip.getRolledBackTimestamp(),esip.getSerialNumber(),esip.getInRef(),esip.getOutRef()
-
 
383
						,esip.getBusinessDate(),esip.getStatus(),esip.getDescription(),esip.getProcessAmount(),esip.getInvestmentDays()));
-
 
384
			}
-
 
385
			
-
 
386
		
-
 
387
			
-
 
388
			
-
 
389
		
-
 
390
 
-
 
391
			org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
-
 
392
					.getCSVByteStream(Arrays.asList("Code","Store Name","Fofo Id","Item Id","Brand","Model Name",
-
 
393
							"Model Number","Color","Scheme In Dp","Scheme Out Dp","Scheme Id",
-
 
394
							"Name","Type","Partner Type","Amount Type","Amount","Purchase Invoice","Sale Inovoice",
-
 
395
							"Paid Amount","Create Timestamp","Rolled Back Timestamp",
-
 
396
							"Serial Number","In Ref","Out Ref","Business Date","Status","Description","Process Amount","Investment Days"), rows);
-
 
397
 
-
 
398
			final HttpHeaders headers = new HttpHeaders();
-
 
399
			headers.set("Content-Type", "text/csv");
-
 
400
			headers.set("Content-disposition", "inline; filename=schemePayout.csv");
-
 
401
			headers.setContentLength(baos.toByteArray().length);
-
 
402
 
-
 
403
			final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
-
 
404
			final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
-
 
405
		
-
 
406
			return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
-
 
407
	
-
 
408
		}
187
 
409
 
188
	@RequestMapping(value = "/schemes/update", method = RequestMethod.POST)
410
	@RequestMapping(value = "/schemes/update", method = RequestMethod.POST)
189
	public String updateShcemes(HttpServletRequest request, @RequestBody SchemeItems schemeItems, Model model)
411
	public String updateShcemes(HttpServletRequest request, @RequestBody SchemeItems schemeItems, Model model)
190
			throws Exception {
412
			throws Exception {
191
		for (int schemeId : schemeItems.getSchemeIds()) {
413
		for (int schemeId : schemeItems.getSchemeIds()) {