Subversion Repositories SmartDukaan

Rev

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

Rev 24986 Rev 25276
Line 4... Line 4...
4
import java.io.FileInputStream;
4
import java.io.FileInputStream;
5
import java.io.FileNotFoundException;
5
import java.io.FileNotFoundException;
6
import java.time.LocalDate;
6
import java.time.LocalDate;
7
import java.time.LocalDateTime;
7
import java.time.LocalDateTime;
8
import java.util.ArrayList;
8
import java.util.ArrayList;
-
 
9
import java.util.Arrays;
9
import java.util.HashMap;
10
import java.util.HashMap;
10
import java.util.List;
11
import java.util.List;
11
import java.util.Map;
12
import java.util.Map;
12
import java.util.Set;
13
import java.util.Set;
13
import java.util.stream.Collectors;
14
import java.util.stream.Collectors;
14
 
15
 
15
import javax.servlet.http.HttpServletRequest;
16
import javax.servlet.http.HttpServletRequest;
-
 
17
import javax.transaction.Transactional;
16
 
18
 
17
import org.apache.logging.log4j.LogManager;
19
import org.apache.logging.log4j.LogManager;
18
import org.apache.logging.log4j.Logger;
20
import org.apache.logging.log4j.Logger;
19
import org.json.JSONObject;
21
import org.json.JSONObject;
20
import org.springframework.beans.factory.annotation.Autowired;
22
import org.springframework.beans.factory.annotation.Autowired;
Line 22... Line 24...
22
import org.springframework.core.io.InputStreamResource;
24
import org.springframework.core.io.InputStreamResource;
23
import org.springframework.http.HttpHeaders;
25
import org.springframework.http.HttpHeaders;
24
import org.springframework.http.HttpStatus;
26
import org.springframework.http.HttpStatus;
25
import org.springframework.http.ResponseEntity;
27
import org.springframework.http.ResponseEntity;
26
import org.springframework.stereotype.Controller;
28
import org.springframework.stereotype.Controller;
27
import org.springframework.transaction.annotation.Transactional;
-
 
28
import org.springframework.ui.Model;
29
import org.springframework.ui.Model;
29
import org.springframework.web.bind.annotation.GetMapping;
30
import org.springframework.web.bind.annotation.GetMapping;
30
import org.springframework.web.bind.annotation.PostMapping;
31
import org.springframework.web.bind.annotation.PostMapping;
31
import org.springframework.web.bind.annotation.RequestBody;
32
import org.springframework.web.bind.annotation.RequestBody;
32
import org.springframework.web.bind.annotation.RequestMapping;
33
import org.springframework.web.bind.annotation.RequestMapping;
Line 58... Line 59...
58
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
59
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
59
import com.spice.profitmandi.dao.repository.user.UserRepository;
60
import com.spice.profitmandi.dao.repository.user.UserRepository;
60
import com.spice.profitmandi.service.PartnerInvestmentService;
61
import com.spice.profitmandi.service.PartnerInvestmentService;
61
import com.spice.profitmandi.service.inventory.InventoryService;
62
import com.spice.profitmandi.service.inventory.InventoryService;
62
import com.spice.profitmandi.service.user.RetailerService;
63
import com.spice.profitmandi.service.user.RetailerService;
-
 
64
import com.spice.profitmandi.web.model.LoginDetails;
-
 
65
import com.spice.profitmandi.web.util.CookiesProcessor;
63
import com.spice.profitmandi.web.util.MVCResponseSender;
66
import com.spice.profitmandi.web.util.MVCResponseSender;
64
 
67
 
65
@Controller
68
@Controller
66
@Transactional(rollbackFor = Throwable.class)
69
@Transactional(rollbackFor = Throwable.class)
67
public class RetailerController {
70
public class RetailerController {
Line 82... Line 85...
82
 
85
 
83
	@Autowired
86
	@Autowired
84
	private DocumentRepository documentRepository;
87
	private DocumentRepository documentRepository;
85
 
88
 
86
	@Autowired
89
	@Autowired
-
 
90
	private CookiesProcessor cookiesProcessor;
-
 
91
 
-
 
92
	@Autowired
87
	@Qualifier("userUserRepository")
93
	@Qualifier("userUserRepository")
88
	private UserRepository userRepository;
94
	private UserRepository userRepository;
89
 
95
 
90
	@Autowired
96
	@Autowired
91
	private LocationRepository locationRepository;
97
	private LocationRepository locationRepository;
Line 275... Line 281...
275
	}
281
	}
276
 
282
 
277
	@GetMapping(value = "/getAllStores")
283
	@GetMapping(value = "/getAllStores")
278
	public String getAllStores(HttpServletRequest request, Model model) {
284
	public String getAllStores(HttpServletRequest request, Model model) {
279
 
285
 
280
		List<FofoStore> fofoStores = fofoStoreRepository.selectAll().stream().filter(x->x.isActive()).collect(Collectors.toList());
286
		List<FofoStore> fofoStores = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive())
-
 
287
				.collect(Collectors.toList());
281
		Map<Integer, Boolean> investments = new HashMap<>();
288
		Map<Integer, Boolean> investments = new HashMap<>();
282
 
289
 
283
		for (FofoStore fofoStore : fofoStores) {
290
		for (FofoStore fofoStore : fofoStores) {
284
			boolean isOk = false;
291
			boolean isOk = false;
285
			if (fofoStore.getGraceDate() != null && fofoStore.getGraceDate().isAfter(LocalDate.now())) {
292
			if (fofoStore.getGraceDate() != null && fofoStore.getGraceDate().isAfter(LocalDate.now())) {
286
				isOk = true;
293
				isOk = true;
287
			} else {
294
			} else {
288
				try {
295
				try {
289
					isOk = partnerInvestmentService.isInvestmentOk(fofoStore.getId(), 10, 30);
296
					isOk = partnerInvestmentService.isInvestmentOk(fofoStore.getId(), 10,
-
 
297
							ProfitMandiConstants.CUTOFF_INVESTMENT);
290
					if(fofoStore.getGraceCount() > 0) {
298
					if (fofoStore.getGraceCount() > 0) {
291
						fofoStore.setGraceDate(null);
299
						fofoStore.setGraceDate(null);
292
						fofoStore.setGraceCount(0);
300
						fofoStore.setGraceCount(0);
293
						fofoStoreRepository.persist(fofoStore);
301
						fofoStoreRepository.persist(fofoStore);
294
					}
302
					}
295
				} catch (ProfitMandiBusinessException e) {
303
				} catch (ProfitMandiBusinessException e) {
Line 318... Line 326...
318
 
326
 
319
	@PostMapping(value = "/deactivateStore")
327
	@PostMapping(value = "/deactivateStore")
320
	public String deActivateStore(HttpServletRequest request,
328
	public String deActivateStore(HttpServletRequest request,
321
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
329
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
322
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
330
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
331
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
332
		if (!Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com").contains(loginDetails.getEmailId())) {
-
 
333
			throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access", "You are not authorise to deactivate retailer");
323
 
334
		}
324
		fofoStore.setActive(false);
335
		fofoStore.setActive(false);
325
		fofoStoreRepository.persist(fofoStore);
336
		fofoStoreRepository.persist(fofoStore);
326
		LOGGER.info("inserted into InActiveFofoStore successfully");
337
		LOGGER.info("inserted into InActiveFofoStore successfully");
327
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
338
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
328
 
339
 
329
		return "response";
340
		return "response";
330
 
341
 
331
	}
342
	}
-
 
343
 
332
	@GetMapping(value="/getAllInactiveStores")
344
	@GetMapping(value = "/getAllInactiveStores")
333
	public String getInactiveStores(HttpServletRequest request,Model model)
345
	public String getInactiveStores(HttpServletRequest request, Model model) {
334
	{
-
 
335
		List<FofoStore> inActiveFofoStores=fofoStoreRepository.selectInActiveStore();
346
		List<FofoStore> inActiveFofoStores = fofoStoreRepository.selectInActiveStore();
-
 
347
		Map<Integer, CustomRetailer> customRetailers = retailerService
336
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(inActiveFofoStores.stream().map(x->x.getId()).collect(Collectors.toList()));
348
				.getFofoRetailers(inActiveFofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
337
		model.addAttribute("inActiveFofoStores", inActiveFofoStores);
349
		model.addAttribute("inActiveFofoStores", inActiveFofoStores);
338
		model.addAttribute("customRetailers", customRetailers);
350
		model.addAttribute("customRetailers", customRetailers);
339
		return "inactive-stores";
351
		return "inactive-stores";
340
	}
352
	}
341
	
353
 
342
	//Extend billing for 2 days
354
	// Extend billing for 2 days
343
	@PostMapping(value = "/extendBilling")
355
	@PostMapping(value = "/extendBilling")
344
	public String extendBilling(HttpServletRequest request,
356
	public String extendBilling(HttpServletRequest request,
345
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
357
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
346
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
358
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
359
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
360
		if (Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com").contains(loginDetails.getEmailId())) {
347
		fofoStore.setGraceDate(LocalDate.now().plusDays(2));
361
			fofoStore.setGraceDate(LocalDate.now().plusDays(2));
348
		fofoStore.setGraceCount(fofoStore.getGraceCount() + 1);
362
			fofoStore.setGraceCount(fofoStore.getGraceCount() + 1);
349
		fofoStoreRepository.persist(fofoStore);
363
			fofoStoreRepository.persist(fofoStore);
350
		model.addAttribute("response", mvcResponseSender.createResponseString(fofoStore.getGraceCount()));
364
			model.addAttribute("response", mvcResponseSender.createResponseString(fofoStore.getGraceCount()));
-
 
365
		} else {
-
 
366
			throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access", "You are not authorise to extend billing");
-
 
367
		}
351
		return "response";
368
		return "response";
352
		
369
 
353
	}
370
	}
354
 
371
 
355
	@RequestMapping(value = "/getPromoterInfo", method = RequestMethod.GET)
372
	@RequestMapping(value = "/getPromoterInfo", method = RequestMethod.GET)
356
	public String getPromoterInfo(HttpServletRequest request,
373
	public String getPromoterInfo(HttpServletRequest request,
357
			@RequestParam(name = "offset", defaultValue = "0") int offset,
374
			@RequestParam(name = "offset", defaultValue = "0") int offset,
Line 366... Line 383...
366
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
383
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
367
		Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
384
		Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
368
		brands.add("Airtel");
385
		brands.add("Airtel");
369
		brands.add("Vodafone");
386
		brands.add("Vodafone");
370
		brands.add("Idea");
387
		brands.add("Idea");
371
		LOGGER.info("brands"+brands); 
388
		LOGGER.info("brands" + brands);
372
		model.addAttribute("customRetailers", customRetailers);
389
		model.addAttribute("customRetailers", customRetailers);
373
		model.addAttribute("brands",brands );
390
		model.addAttribute("brands", brands);
374
		promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
391
		promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
375
 
392
 
376
		size = promoterRepository.selectAllCount();
393
		size = promoterRepository.selectAllCount();
377
 
394
 
378
		LOGGER.info("promoterInfo" + promoterInfo);
395
		LOGGER.info("promoterInfo" + promoterInfo);
Line 459... Line 476...
459
			promoterRepository.persist(promoter);
476
			promoterRepository.persist(promoter);
460
		} else {
477
		} else {
461
			Promoter updatePromoter = promoterRepository.selectById(promoterdetailModel.getId());
478
			Promoter updatePromoter = promoterRepository.selectById(promoterdetailModel.getId());
462
			updatePromoter.setRetailerId(promoterdetailModel.getRetailerId());
479
			updatePromoter.setRetailerId(promoterdetailModel.getRetailerId());
463
			updatePromoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
480
			updatePromoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
464
			LOGGER.info("sdport"+ promoterdetailModel.isSdPortalAccess());
481
			LOGGER.info("sdport" + promoterdetailModel.isSdPortalAccess());
465
			LOGGER.info("sdport"  + updatePromoter);
482
			LOGGER.info("sdport" + updatePromoter);
466
			promoterRepository.persist(updatePromoter);
483
			promoterRepository.persist(updatePromoter);
467
			
484
 
468
		}
485
		}
469
 
486
 
470
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
487
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
471
 
488
 
472
		return "response";
489
		return "response";