Subversion Repositories SmartDukaan

Rev

Rev 28381 | Rev 28825 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
22981 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
23494 ashik.ali 3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileNotFoundException;
28710 amit.gupta 6
import java.time.Instant;
24349 amit.gupta 7
import java.time.LocalDate;
24159 tejbeer 8
import java.time.LocalDateTime;
28272 tejbeer 9
import java.util.AbstractMap;
24124 govind 10
import java.util.ArrayList;
25276 amit.gupta 11
import java.util.Arrays;
28710 amit.gupta 12
import java.util.Date;
24349 amit.gupta 13
import java.util.HashMap;
24124 govind 14
import java.util.List;
22981 ashik.ali 15
import java.util.Map;
24986 tejbeer 16
import java.util.Set;
24159 tejbeer 17
import java.util.stream.Collectors;
22981 ashik.ali 18
 
19
import javax.servlet.http.HttpServletRequest;
25276 amit.gupta 20
import javax.transaction.Transactional;
22981 ashik.ali 21
 
24159 tejbeer 22
import org.apache.logging.log4j.LogManager;
23955 govind 23
import org.apache.logging.log4j.Logger;
24159 tejbeer 24
import org.json.JSONObject;
22981 ashik.ali 25
import org.springframework.beans.factory.annotation.Autowired;
24159 tejbeer 26
import org.springframework.beans.factory.annotation.Qualifier;
23494 ashik.ali 27
import org.springframework.core.io.InputStreamResource;
28
import org.springframework.http.HttpHeaders;
29
import org.springframework.http.HttpStatus;
23330 ashik.ali 30
import org.springframework.http.ResponseEntity;
22981 ashik.ali 31
import org.springframework.stereotype.Controller;
32
import org.springframework.ui.Model;
24124 govind 33
import org.springframework.web.bind.annotation.GetMapping;
34
import org.springframework.web.bind.annotation.PostMapping;
23026 ashik.ali 35
import org.springframework.web.bind.annotation.RequestBody;
22981 ashik.ali 36
import org.springframework.web.bind.annotation.RequestMapping;
37
import org.springframework.web.bind.annotation.RequestMethod;
38
import org.springframework.web.bind.annotation.RequestParam;
39
 
23494 ashik.ali 40
import com.spice.profitmandi.common.enumuration.ContentType;
23955 govind 41
import com.spice.profitmandi.common.enumuration.CounterSize;
22981 ashik.ali 42
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24123 tejbeer 43
import com.spice.profitmandi.common.model.AddLocationModel;
24124 govind 44
import com.spice.profitmandi.common.model.CustomRetailer;
22981 ashik.ali 45
import com.spice.profitmandi.common.model.ProfitMandiConstants;
24159 tejbeer 46
import com.spice.profitmandi.common.model.PromoterDetailModel;
23026 ashik.ali 47
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
28024 tejbeer 48
import com.spice.profitmandi.common.util.Utils;
23330 ashik.ali 49
import com.spice.profitmandi.common.web.util.ResponseSender;
27231 tejbeer 50
import com.spice.profitmandi.dao.entity.auth.AuthUser;
28272 tejbeer 51
import com.spice.profitmandi.dao.entity.dtr.BrandLimit;
23494 ashik.ali 52
import com.spice.profitmandi.dao.entity.dtr.Document;
53
import com.spice.profitmandi.dao.entity.dtr.Retailer;
28024 tejbeer 54
import com.spice.profitmandi.dao.entity.dtr.RetailerBlockBrands;
28272 tejbeer 55
import com.spice.profitmandi.dao.entity.dtr.RetailerBrandsLimit;
23494 ashik.ali 56
import com.spice.profitmandi.dao.entity.dtr.Shop;
24124 govind 57
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
27797 tejbeer 58
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
59
import com.spice.profitmandi.dao.entity.fofo.PartnerTypeChange;
28381 tejbeer 60
import com.spice.profitmandi.dao.entity.fofo.PincodePartner;
24159 tejbeer 61
import com.spice.profitmandi.dao.entity.user.Location;
62
import com.spice.profitmandi.dao.entity.user.Promoter;
24123 tejbeer 63
import com.spice.profitmandi.dao.entity.user.User;
27231 tejbeer 64
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
65
import com.spice.profitmandi.dao.repository.cs.CsService;
28272 tejbeer 66
import com.spice.profitmandi.dao.repository.cs.RetailerBrandsLimitService;
67
import com.spice.profitmandi.dao.repository.dtr.BrandLimitRepository;
23494 ashik.ali 68
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
24124 govind 69
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
24159 tejbeer 70
import com.spice.profitmandi.dao.repository.dtr.Mongo;
28024 tejbeer 71
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
28272 tejbeer 72
import com.spice.profitmandi.dao.repository.dtr.RetailerBrandsLimitRepository;
23494 ashik.ali 73
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
74
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
27797 tejbeer 75
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeRepository;
76
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
28381 tejbeer 77
import com.spice.profitmandi.dao.repository.fofo.PincodePartnerRepository;
24123 tejbeer 78
import com.spice.profitmandi.dao.repository.user.LocationRepository;
24159 tejbeer 79
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
24123 tejbeer 80
import com.spice.profitmandi.dao.repository.user.UserRepository;
24349 amit.gupta 81
import com.spice.profitmandi.service.PartnerInvestmentService;
24159 tejbeer 82
import com.spice.profitmandi.service.inventory.InventoryService;
22981 ashik.ali 83
import com.spice.profitmandi.service.user.RetailerService;
25276 amit.gupta 84
import com.spice.profitmandi.web.model.LoginDetails;
85
import com.spice.profitmandi.web.util.CookiesProcessor;
24123 tejbeer 86
import com.spice.profitmandi.web.util.MVCResponseSender;
22981 ashik.ali 87
 
88
@Controller
25277 amit.gupta 89
@Transactional(rollbackOn = Throwable.class)
22981 ashik.ali 90
public class RetailerController {
91
 
23568 govind 92
	private static final Logger LOGGER = LogManager.getLogger(RetailerController.class);
24124 govind 93
 
22981 ashik.ali 94
	@Autowired
95
	private RetailerService retailerService;
24124 govind 96
 
23330 ashik.ali 97
	@Autowired
28381 tejbeer 98
	private RetailerRepository retailerRepository;  
99
 
23494 ashik.ali 100
	@Autowired
28381 tejbeer 101
	private PincodePartnerRepository PincodePartnerRepository;
102
 
103
 
104
	@Autowired
28272 tejbeer 105
	private BrandLimitRepository brandLimitRepository;
106
 
107
	@Autowired
108
	private RetailerBrandsLimitService retailerBrandsLimitService;
109
 
110
	@Autowired
111
	private RetailerBrandsLimitRepository retailerBrandsLimitRepository;
112
 
113
	@Autowired
23494 ashik.ali 114
	private ShopRepository shopRepository;
24124 govind 115
 
23494 ashik.ali 116
	@Autowired
28024 tejbeer 117
	private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
118
 
119
	@Autowired
24124 govind 120
	private FofoStoreRepository fofoStoreRepository;
121
 
122
	@Autowired
23494 ashik.ali 123
	private DocumentRepository documentRepository;
24124 govind 124
 
23494 ashik.ali 125
	@Autowired
25276 amit.gupta 126
	private CookiesProcessor cookiesProcessor;
127
 
128
	@Autowired
24159 tejbeer 129
	@Qualifier("userUserRepository")
24123 tejbeer 130
	private UserRepository userRepository;
24124 govind 131
 
24123 tejbeer 132
	@Autowired
27231 tejbeer 133
	private AuthRepository authRepository;
134
 
135
	@Autowired
136
	private CsService csService;
137
 
138
	@Autowired
24123 tejbeer 139
	private LocationRepository locationRepository;
24124 govind 140
 
24123 tejbeer 141
	@Autowired
23330 ashik.ali 142
	private ResponseSender<?> responseSender;
24124 govind 143
 
24123 tejbeer 144
	@Autowired
145
	private MVCResponseSender mvcResponseSender;
24124 govind 146
 
24159 tejbeer 147
	@Autowired
148
	private InventoryService inventoryService;
149
 
150
	@Autowired
151
	private PromoterRepository promoterRepository;
152
 
153
	@Autowired
24349 amit.gupta 154
	private PartnerInvestmentService partnerInvestmentService;
155
 
156
	@Autowired
24159 tejbeer 157
	private Mongo mongoClient;
158
 
27797 tejbeer 159
	@Autowired
160
	private PartnerTypeChangeService partnerTypeChangeService;
161
 
162
	@Autowired
163
	private PartnerTypeChangeRepository partnerTypeChangeRepository;
164
 
23784 ashik.ali 165
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.GET)
24124 govind 166
	public String retailerInfoByEmailIdOrMobileNumber(HttpServletRequest request,
167
			@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber,
168
			Model model) throws ProfitMandiBusinessException {
169
		LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(),
170
				emailIdOrMobileNumber);
28071 tejbeer 171
 
172
		Map<String, Object> map = retailerService.getByEmailIdOrMobileNumber(emailIdOrMobileNumber);
173
 
26771 amit.gupta 174
		model.addAllAttributes(map);
28071 tejbeer 175
 
23955 govind 176
		model.addAttribute("counterSizes", CounterSize.values());
26209 tejbeer 177
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
178
		LOGGER.info("warehouseMap", warehouseMap);
179
		model.addAttribute("warehouses", warehouseMap);
26771 amit.gupta 180
		if (map.containsKey("retailer")) {
181
			Retailer retailer = (Retailer) map.get("retailer");
182
			User user = userRepository.selectById(retailer.getId());
183
			if (user.getLocation() != null) {
184
				Location location = locationRepository.selectById(user.getLocation());
185
				model.addAttribute("locationdetail", location);
186
				LOGGER.info("location" + location);
187
			}
188
		}
22981 ashik.ali 189
		return "retailer-details";
190
	}
24124 govind 191
 
23026 ashik.ali 192
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.PUT)
24124 govind 193
	public String updateRetailerDetails(HttpServletRequest request,
194
			@RequestBody UpdateRetailerRequest updateRetailerRequest, Model model) throws ProfitMandiBusinessException {
23026 ashik.ali 195
		LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), updateRetailerRequest);
196
		Map<String, Object> map = retailerService.updateRetailerDetails(updateRetailerRequest);
28071 tejbeer 197
 
23026 ashik.ali 198
		model.addAllAttributes(map);
23955 govind 199
		model.addAttribute("counterSizes", CounterSize.values());
26209 tejbeer 200
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
201
		LOGGER.info("warehouseMap", warehouseMap);
202
		model.addAttribute("warehouses", warehouseMap);
23026 ashik.ali 203
		return "retailer-details";
204
	}
22981 ashik.ali 205
 
206
	@RequestMapping(value = "/retailerInfo", method = RequestMethod.GET)
24124 govind 207
	public String retailerInfo(HttpServletRequest request) throws Exception {
22981 ashik.ali 208
		return "retailer-info";
209
	}
24124 govind 210
 
23330 ashik.ali 211
	@RequestMapping(value = "/district/all/stateName", method = RequestMethod.GET)
24124 govind 212
	public ResponseEntity<?> getAllDistrict(@RequestParam(name = "stateName") String stateName) {
23330 ashik.ali 213
		return responseSender.ok(retailerService.getAllDistrictMaster(stateName));
214
	}
24124 govind 215
 
23494 ashik.ali 216
	@RequestMapping(value = "/retailerDocument/documentId", method = RequestMethod.GET)
24124 govind 217
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
218
			@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId,
219
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
23494 ashik.ali 220
		Document document = documentRepository.selectById(documentId);
23499 ashik.ali 221
		Retailer retailer = retailerRepository.selectById(retailerId);
24124 govind 222
 
223
		if (retailer.getDocumentId() == null) {
23494 ashik.ali 224
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
225
		}
24124 govind 226
		if (retailer.getDocumentId() != documentId) {
23494 ashik.ali 227
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
228
		}
229
		return responseSender.ok(document);
230
	}
24124 govind 231
 
23494 ashik.ali 232
	@RequestMapping(value = "/retailerDocument/download", method = RequestMethod.GET)
24124 govind 233
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request,
234
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
235
			throws ProfitMandiBusinessException {
236
 
23499 ashik.ali 237
		Retailer retailer = retailerRepository.selectById(retailerId);
24124 govind 238
 
239
		if (retailer.getDocumentId() == null) {
23494 ashik.ali 240
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
241
		}
24124 govind 242
 
23494 ashik.ali 243
		Document document = documentRepository.selectById(retailer.getDocumentId());
24124 govind 244
 
23494 ashik.ali 245
		FileInputStream file = null;
246
		try {
247
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
248
		} catch (FileNotFoundException e) {
249
			LOGGER.error("Retailer Document file not found : ", e);
250
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
251
		}
24159 tejbeer 252
		// ByteArrayOutputStream byteArrayOutputStream = new
253
		// ByteArrayOutputStream();
24124 govind 254
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
255
 
256
		final HttpHeaders headers = new HttpHeaders();
23494 ashik.ali 257
		String contentType = "";
24124 govind 258
		if (document.getContentType() == ContentType.JPEG) {
23494 ashik.ali 259
			contentType = "image/jpeg";
24124 govind 260
		} else if (document.getContentType() == ContentType.PNG) {
23494 ashik.ali 261
			contentType = "image/png";
24124 govind 262
		} else if (document.getContentType() == ContentType.PDF) {
23494 ashik.ali 263
			contentType = "application/pdf";
264
		}
24124 govind 265
		headers.set("Content-Type", contentType);
266
		headers.set("Content-disposition", "inline; filename=" + document.getName());
267
		headers.setContentLength(document.getSize());
268
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
269
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
270
 
24159 tejbeer 271
		// return
272
		// responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
23494 ashik.ali 273
	}
24124 govind 274
 
23494 ashik.ali 275
	@RequestMapping(value = "/retailerShopDocument/shopId", method = RequestMethod.GET)
24124 govind 276
	public ResponseEntity<?> retailerShopDocumentById(HttpServletRequest request,
277
			@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
278
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
23494 ashik.ali 279
		Shop shop = shopRepository.selectById(shopId);
24124 govind 280
 
281
		if (shop.getRetailerId() != retailerId) {
23494 ashik.ali 282
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
283
		}
24124 govind 284
 
285
		if (shop.getDocumentId() == null) {
23494 ashik.ali 286
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
287
		}
24124 govind 288
 
23494 ashik.ali 289
		Document document = documentRepository.selectById(shop.getDocumentId());
290
		return responseSender.ok(document);
291
	}
24124 govind 292
 
23494 ashik.ali 293
	@RequestMapping(value = "/retailerShopDocument/download", method = RequestMethod.GET)
24124 govind 294
	public ResponseEntity<?> downloadRetailerShopDocument(HttpServletRequest request,
295
			@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
296
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
297
			throws ProfitMandiBusinessException {
298
 
23494 ashik.ali 299
		Shop shop = shopRepository.selectById(shopId);
24124 govind 300
 
301
		if (shop.getRetailerId() != retailerId) {
23494 ashik.ali 302
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
303
		}
24124 govind 304
 
305
		if (shop.getDocumentId() == null) {
23494 ashik.ali 306
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
307
		}
24124 govind 308
 
23494 ashik.ali 309
		Document document = documentRepository.selectById(shop.getDocumentId());
24124 govind 310
 
23494 ashik.ali 311
		FileInputStream file = null;
312
		try {
313
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
314
		} catch (FileNotFoundException e) {
315
			LOGGER.error("Retailer Document file not found : ", e);
316
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
317
		}
24159 tejbeer 318
		// ByteArrayOutputStream byteArrayOutputStream = new
319
		// ByteArrayOutputStream();
24124 govind 320
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
321
 
322
		final HttpHeaders headers = new HttpHeaders();
23494 ashik.ali 323
		String contentType = "";
24124 govind 324
		if (document.getContentType() == ContentType.JPEG) {
23494 ashik.ali 325
			contentType = "image/jpeg";
24124 govind 326
		} else if (document.getContentType() == ContentType.PNG) {
23494 ashik.ali 327
			contentType = "image/png";
24124 govind 328
		} else if (document.getContentType() == ContentType.PDF) {
23494 ashik.ali 329
			contentType = "application/pdf";
330
		}
24124 govind 331
		headers.set("Content-Type", contentType);
332
		headers.set("Content-disposition", "inline; filename=" + document.getName());
333
		headers.setContentLength(document.getSize());
334
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
335
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
336
 
24159 tejbeer 337
		// return
338
		// responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
23494 ashik.ali 339
	}
24124 govind 340
 
341
	@GetMapping(value = "/getAllStores")
342
	public String getAllStores(HttpServletRequest request, Model model) {
343
 
25276 amit.gupta 344
		List<FofoStore> fofoStores = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive())
345
				.collect(Collectors.toList());
24349 amit.gupta 346
		Map<Integer, Boolean> investments = new HashMap<>();
24124 govind 347
 
24349 amit.gupta 348
		for (FofoStore fofoStore : fofoStores) {
349
			boolean isOk = false;
350
			if (fofoStore.getGraceDate() != null && fofoStore.getGraceDate().isAfter(LocalDate.now())) {
351
				isOk = true;
352
			} else {
353
				try {
25276 amit.gupta 354
					isOk = partnerInvestmentService.isInvestmentOk(fofoStore.getId(), 10,
355
							ProfitMandiConstants.CUTOFF_INVESTMENT);
356
					if (fofoStore.getGraceCount() > 0) {
24349 amit.gupta 357
						fofoStore.setGraceDate(null);
358
						fofoStore.setGraceCount(0);
359
						fofoStoreRepository.persist(fofoStore);
360
					}
361
				} catch (ProfitMandiBusinessException e) {
362
				}
363
			}
364
			investments.put(fofoStore.getId(), isOk);
365
		}
24124 govind 366
 
26963 amit.gupta 367
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(false);
24124 govind 368
		model.addAttribute("fofoStores", fofoStores);
24349 amit.gupta 369
		model.addAttribute("investments", investments);
24124 govind 370
		model.addAttribute("customRetailers", customRetailers);
371
 
372
		return "store";
373
 
374
	}
375
 
27797 tejbeer 376
	@GetMapping(value = "/getPartnerCategory")
377
	public String getPartnerCategory(HttpServletRequest request, @RequestParam int fofoId, Model model) {
378
 
379
		PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
380
		List<PartnerType> partnerTypes = partnerType.nextPartnerTypes();
381
		LOGGER.info("partnerType" + partnerTypes);
382
		model.addAttribute("partnerTypes", partnerTypes);
383
		model.addAttribute("fofoId", fofoId);
384
		return "partner-category";
385
	}
386
 
387
	@PostMapping(value = "/updatePartnerCategory")
388
	public String updatePartnerCategory(HttpServletRequest request, @RequestParam(name = "fofoId") int fofoId,
389
			@RequestParam(name = "partnerType") PartnerType partnerType, Model model) throws Exception {
390
 
391
		PartnerTypeChange ptc = new PartnerTypeChange();
392
		ptc.setFofoId(fofoId);
393
		ptc.setPartnerType(partnerType);
394
		ptc.setCreateTimestamp(LocalDate.now().atStartOfDay().plusDays(1));
395
		partnerTypeChangeRepository.persist(ptc);
396
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
397
 
398
		return "response";
399
	}
400
 
24349 amit.gupta 401
	@GetMapping(value = "/partners")
402
	public String getStoreName(HttpServletRequest request, Model model, @RequestParam String query) throws Exception {
403
		model.addAttribute("response", mvcResponseSender
26963 amit.gupta 404
				.createResponseString(retailerService.getFofoRetailers(false).values().stream().filter(x -> {
24349 amit.gupta 405
					return x.getDisplayName().toLowerCase().matches(".*?" + query.toLowerCase() + ".*?");
406
				}).collect(Collectors.toList())));
407
		return "response";
408
	}
409
 
24124 govind 410
	@PostMapping(value = "/deactivateStore")
411
	public String deActivateStore(HttpServletRequest request,
412
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
413
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
25276 amit.gupta 414
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
27231 tejbeer 415
		if (!Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "amit.gupta@smartdukaan.com")
26131 tejbeer 416
				.contains(loginDetails.getEmailId())) {
417
			throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
418
					"You are not authorise to deactivate retailer");
25276 amit.gupta 419
		}
24843 govind 420
		fofoStore.setActive(false);
421
		fofoStoreRepository.persist(fofoStore);
24124 govind 422
		LOGGER.info("inserted into InActiveFofoStore successfully");
423
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
424
		return "response";
425
	}
28710 amit.gupta 426
 
427
 
428
	@PostMapping(value = "/activateStoreForever")
429
	public String activateStoreForever(HttpServletRequest request,
430
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
431
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
432
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
433
		if (!Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "amit.gupta@smartdukaan.com","manish.tiwari@smartdukaan.com")
434
				.contains(loginDetails.getEmailId())) {
435
			throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
436
					"You are not authorise to activate retailer");
437
		}
438
		fofoStore.setActive(true);
439
		fofoStoreRepository.persist(fofoStore);
440
		LOGGER.info("inserted into ActiveFofoStore successfully");
441
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
442
		return "response";
443
	}
444
 
445
	@PostMapping(value = "/activateStoreTemporary")
446
	public String activateStoreTemporary(HttpServletRequest request,
447
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId,
448
			@RequestParam(name = "days", required = true ) int days,Model model) throws Exception {
449
 
450
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
451
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
452
		if (!Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "amit.gupta@smartdukaan.com","manish.tiwari@smartdukaan.com")
453
				.contains(loginDetails.getEmailId())) {
454
			throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
455
					"You are not authorise to deactivate retailer");
456
		}
457
 
458
		LocalDateTime currentDate =LocalDate.now().atStartOfDay();
459
 
460
		LocalDateTime EndDate = currentDate.plusDays(days);
461
		fofoStore.setActiveTimeStamp(EndDate);
462
 
463
		LOGGER.info("EndDate"+EndDate);
464
		LOGGER.info("getActiveTimeStamp"+fofoStore.getActiveTimeStamp());
465
 
466
		if( currentDate.isBefore(fofoStore.getActiveTimeStamp()))
467
		{
468
 
469
		fofoStore.setActive(true);
470
		fofoStoreRepository.persist(fofoStore);
471
		LOGGER.info("inserted into InActiveFofoStore successfully");
472
 
473
		}
474
 
475
 
476
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
477
		return "response";
478
	}
479
 
480
 
25276 amit.gupta 481
 
482
	@GetMapping(value = "/getAllInactiveStores")
483
	public String getInactiveStores(HttpServletRequest request, Model model) {
484
		List<FofoStore> inActiveFofoStores = fofoStoreRepository.selectInActiveStore();
485
		Map<Integer, CustomRetailer> customRetailers = retailerService
486
				.getFofoRetailers(inActiveFofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
24680 govind 487
		model.addAttribute("inActiveFofoStores", inActiveFofoStores);
488
		model.addAttribute("customRetailers", customRetailers);
489
		return "inactive-stores";
490
	}
25276 amit.gupta 491
 
492
	// Extend billing for 2 days
24349 amit.gupta 493
	@PostMapping(value = "/extendBilling")
494
	public String extendBilling(HttpServletRequest request,
495
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
496
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
25276 amit.gupta 497
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
27231 tejbeer 498
		if (Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "prakash.rai@smartdukaan.com",
499
				"amit.gupta@smartdukaan.com").contains(loginDetails.getEmailId())) {
25276 amit.gupta 500
			fofoStore.setGraceDate(LocalDate.now().plusDays(2));
501
			fofoStore.setGraceCount(fofoStore.getGraceCount() + 1);
502
			fofoStoreRepository.persist(fofoStore);
503
			model.addAttribute("response", mvcResponseSender.createResponseString(fofoStore.getGraceCount()));
504
		} else {
26131 tejbeer 505
			throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
506
					"You are not authorise to extend billing");
25276 amit.gupta 507
		}
24349 amit.gupta 508
		return "response";
25276 amit.gupta 509
 
24124 govind 510
	}
511
 
24159 tejbeer 512
	@RequestMapping(value = "/getPromoterInfo", method = RequestMethod.GET)
513
	public String getPromoterInfo(HttpServletRequest request,
514
			@RequestParam(name = "offset", defaultValue = "0") int offset,
27489 tejbeer 515
			@RequestParam(name = "limit", defaultValue = "10") int limit,
516
			@RequestParam(name = "fofoId", required = false, defaultValue = "0") int fofoId, Model model)
517
			throws Exception {
24159 tejbeer 518
		LOGGER.info("requested url : " + request.getRequestURL().toString());
519
		List<Promoter> promoterInfo = null;
520
 
521
		long size = 0;
27489 tejbeer 522
 
24159 tejbeer 523
		List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
524
				.collect(Collectors.toList());
525
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
526
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
24986 tejbeer 527
		Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
528
		brands.add("Airtel");
529
		brands.add("Vodafone");
530
		brands.add("Idea");
25276 amit.gupta 531
		LOGGER.info("brands" + brands);
24159 tejbeer 532
		model.addAttribute("customRetailers", customRetailers);
25276 amit.gupta 533
		model.addAttribute("brands", brands);
24159 tejbeer 534
 
27489 tejbeer 535
		if (fofoId != 0) {
536
			promoterInfo = promoterRepository.selectAllPromoterByFofoId(fofoId, offset, limit);
24159 tejbeer 537
 
27489 tejbeer 538
			size = promoterRepository.selectPromoterCount(fofoId);
539
 
540
		} else {
541
			promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
542
 
543
			size = promoterRepository.selectAllCount();
544
 
545
		}
24159 tejbeer 546
		if (!promoterInfo.isEmpty()) {
547
			List<Integer> partnerIds = new ArrayList<>();
548
 
549
			for (Promoter promoterdetail : promoterInfo) {
550
				partnerIds.add(promoterdetail.getRetailerId());
551
			}
552
			Map<Integer, CustomRetailer> partnersMap = null;
24349 amit.gupta 553
			if (!partnerIds.equals(null)) {
24159 tejbeer 554
				LOGGER.info("partnerIds" + partnerIds);
24349 amit.gupta 555
				partnersMap = retailerService.getFofoRetailers(partnerIds);
24159 tejbeer 556
			}
24349 amit.gupta 557
 
24159 tejbeer 558
			LOGGER.info("partnerIds" + partnersMap);
559
			model.addAttribute("promoterInfo", promoterInfo);
560
			model.addAttribute("partnersMap", partnersMap);
561
			model.addAttribute("start", offset + 1);
562
			model.addAttribute("size", size);
563
			model.addAttribute("url", "/getPaginatedPromoterInfo");
564
 
565
			if (promoterInfo.size() < limit) {
566
				model.addAttribute("end", offset + promoterInfo.size());
567
			} else {
568
				model.addAttribute("end", offset + limit);
569
			}
570
		} else {
571
			model.addAttribute("promoterInfo", promoterInfo);
572
			model.addAttribute("size", size);
573
		}
574
		return "promoter-info";
575
 
576
	}
24349 amit.gupta 577
 
24159 tejbeer 578
	@RequestMapping(value = "/getPaginatedPromoterInfo", method = RequestMethod.GET)
579
	public String getPaginatedPromoterInfo(HttpServletRequest request,
580
			@RequestParam(name = "offset", defaultValue = "0") int offset,
27489 tejbeer 581
			@RequestParam(name = "limit", defaultValue = "10") int limit,
582
			@RequestParam(name = "fofoId", required = false, defaultValue = "0") int fofoId, Model model)
24159 tejbeer 583
			throws ProfitMandiBusinessException {
584
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
585
		List<Promoter> promoterInfo = null;
27489 tejbeer 586
		if (fofoId != 0) {
587
			promoterInfo = promoterRepository.selectAllPromoterByFofoId(fofoId, offset, limit);
588
		} else {
589
			promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
590
		}
24159 tejbeer 591
		LOGGER.info("promoterInfo" + promoterInfo);
592
		if (!promoterInfo.isEmpty()) {
593
			List<Integer> partnerIds = new ArrayList<>();
594
 
595
			for (Promoter promoterdetail : promoterInfo) {
596
				partnerIds.add(promoterdetail.getRetailerId());
597
			}
598
			Map<Integer, CustomRetailer> partnersMap = null;
24349 amit.gupta 599
			if (!partnerIds.equals(null)) {
24159 tejbeer 600
				LOGGER.info("partnerIds" + partnerIds);
24349 amit.gupta 601
				partnersMap = retailerService.getFofoRetailers(partnerIds);
24159 tejbeer 602
			}
24349 amit.gupta 603
 
24159 tejbeer 604
			LOGGER.info("partnerIds" + partnersMap);
605
			model.addAttribute("promoterInfo", promoterInfo);
606
			model.addAttribute("partnersMap", partnersMap);
607
			model.addAttribute("url", "/getPaginatedPromoterInfo");
608
		} else {
609
			model.addAttribute("promoterInfo", promoterInfo);
610
 
611
		}
612
 
613
		return "promoter-info-paginated";
614
	}
615
 
616
	@RequestMapping(value = "/createPromoter", method = RequestMethod.POST)
617
	public String createPromoter(HttpServletRequest request, @RequestBody PromoterDetailModel promoterdetailModel,
618
			Model model) throws Exception {
619
		LOGGER.info("requested url : " + request.getRequestURL().toString());
620
		LOGGER.info("requested url : " + promoterdetailModel);
26131 tejbeer 621
		Promoter promoter = promoterRepository.selectById(promoterdetailModel.getId());
622
		if (promoter == null) {
623
			promoter = new Promoter();
24159 tejbeer 624
			promoter.setBrand(promoterdetailModel.getBrand());
625
			promoter.setRetailerId(promoterdetailModel.getRetailerId());
626
			promoter.setCreatedTimestamp(LocalDateTime.now());
26131 tejbeer 627
 
24159 tejbeer 628
		}
27489 tejbeer 629
		promoter.setName(promoterdetailModel.getName());
630
		promoter.setEmail(promoterdetailModel.getEmail());
631
		promoter.setMobile(promoterdetailModel.getMobile());
632
		promoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
633
		promoter.setStatus(promoterdetailModel.isStatus());
634
		LOGGER.info("sdport" + promoterdetailModel.isStatus());
635
		promoterRepository.persist(promoter);
24159 tejbeer 636
 
637
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
638
 
639
		return "response";
640
 
641
	}
642
 
643
	@RequestMapping(value = "/removePromoterfromPartnerStore", method = RequestMethod.POST)
644
	public String removePromoterfromPartnerStore(HttpServletRequest request,
645
			@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
646
 
647
		Promoter promoter = promoterRepository.selectById(id);
648
 
26131 tejbeer 649
		promoter.setStatus(false);
24159 tejbeer 650
		promoterRepository.persist(promoter);
651
 
652
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
653
 
654
		return "response";
655
	}
656
 
657
	@RequestMapping(value = "/addLocation", method = RequestMethod.POST)
658
	public String addLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel, Model model)
659
			throws Exception {
660
 
661
		Location location = new Location();
662
		location.setName(addLocationModel.getName());
663
		location.setLine1(addLocationModel.getLine1());
664
		location.setLine2(addLocationModel.getLine2());
665
		location.setCity(addLocationModel.getCity());
666
		location.setState(addLocationModel.getState());
667
		location.setPin(addLocationModel.getPin());
668
 
669
		LOGGER.info("PostLocation" + location);
670
		locationRepository.persist(location);
671
 
672
		User user = userRepository.selectById(addLocationModel.getUserId());
673
		user.setLocation(location.getId());
674
		userRepository.persist(user);
675
 
676
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
677
		return "response";
678
 
679
	}
680
 
681
	@RequestMapping(value = "/updateLocation", method = RequestMethod.POST)
682
	public String updateLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel,
683
			Model model) throws Exception {
684
 
685
		Location userlocation = locationRepository.selectById(addLocationModel.getUserId());
686
 
687
		userlocation.setName(addLocationModel.getName());
688
		userlocation.setCity(addLocationModel.getCity());
689
		userlocation.setLine1(addLocationModel.getLine1());
690
		userlocation.setLine2(addLocationModel.getLine2());
691
		userlocation.setPin(addLocationModel.getPin());
692
		userlocation.setState(addLocationModel.getState());
693
 
694
		locationRepository.persist(userlocation);
695
 
696
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
697
		return "response";
698
 
699
	}
700
 
27231 tejbeer 701
	@RequestMapping(value = "/getPartnerReadonlyInfo")
702
	public String getPartnerReadonlyInfo(HttpServletRequest request, Model model) throws Exception {
703
 
704
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
705
		AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
706
 
707
		Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
708
 
709
		List<Integer> fofoIds = pp.get(authUser.getId());
710
 
711
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
712
 
713
		model.addAttribute("customRetailersMap", customRetailersMap);
27243 tejbeer 714
 
27231 tejbeer 715
		return "partner-readonly-info";
716
 
717
	}
718
 
28071 tejbeer 719
	@RequestMapping(value = "/getBlockBrandMapping")
720
	public String getBlockBrandMapping(HttpServletRequest request, Model model) throws Exception {
721
 
722
		int fofoId = Utils.SYSTEM_PARTNER_ID;
723
		Set<String> brands = null;
724
 
725
		brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
726
				.collect(Collectors.toSet());
727
 
728
		LOGGER.info("brands" + brands);
729
		model.addAttribute("brands", brands);
730
 
731
		return "block-brand-mapping";
732
 
733
	}
734
 
735
	@RequestMapping(value = "/getBlockBrand")
736
	public String getBlockBrand(HttpServletRequest request,
737
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
738
			throws Exception {
739
 
740
		List<RetailerBlockBrands> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByBrands(brand);
741
 
742
		List<Integer> blockBrandPartners = retailerBlockBrands.stream().map(x -> x.getFofoId())
743
				.collect(Collectors.toList());
744
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
28272 tejbeer 745
 
28071 tejbeer 746
		LOGGER.info("retailerBlockBrands" + retailerBlockBrands);
747
		model.addAttribute("blockBrandPartners", blockBrandPartners);
748
		model.addAttribute("retailerBlockBrands", retailerBlockBrands);
749
		model.addAttribute("customRetailers", customRetailers);
750
 
751
		return "retailer-block-brand";
752
 
753
	}
754
 
755
	@RequestMapping(value = "/getRetailerBlockBrandMappping", method = RequestMethod.POST)
756
	public String getBlockBrandMappping(HttpServletRequest request,
757
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
758
			@RequestParam(name = "fofoIds", required = true, defaultValue = "0") List<Integer> fofoIds, Model model)
759
			throws Exception {
760
		List<RetailerBlockBrands> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByBrands(brand);
761
		if (!retailerBlockBrands.isEmpty()) {
762
			retailerBlockBrandsRepository.deleteAllbyBrands(brand);
763
		}
764
 
765
		for (int id : fofoIds) {
766
			RetailerBlockBrands retailerBlockBrand = new RetailerBlockBrands();
767
			retailerBlockBrand.setFofoId(id);
768
			retailerBlockBrand.setBlockBrands(brand);
769
			retailerBlockBrandsRepository.persist(retailerBlockBrand);
770
 
771
		}
772
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
773
 
774
		return "response";
775
	}
776
 
28272 tejbeer 777
	@RequestMapping(value = "/getBrandslimit", method = RequestMethod.GET)
778
	public String getBrandslimit(HttpServletRequest request, Model model) throws Exception {
779
 
780
		int fofoId = Utils.SYSTEM_PARTNER_ID;
781
		Set<String> brands = null;
782
 
783
		brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
784
				.collect(Collectors.toSet());
785
 
786
		model.addAttribute("brands", brands);
787
 
788
		return "brands-limit";
789
 
790
	}
791
 
792
	@RequestMapping(value = "/setUpdateLimit", method = RequestMethod.POST)
793
	public String getUpdateLimit(HttpServletRequest request,
794
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
795
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
796
			@RequestParam(name = "limit", required = true, defaultValue = "0") float limit, Model model)
797
			throws Exception {
798
 
799
		CustomRetailer cr = retailerService.getFofoRetailer(fofoId);
28277 tejbeer 800
 
801
		Map.Entry<Integer, CustomRetailer> customRetailers = new AbstractMap.SimpleEntry(cr.getPartnerId(), cr);
802
 
803
		// Map<Integer, CustomRetailer> customRetailers =
804
		// retailerService.getFofoRetailers(true);
805
		LOGGER.info("customRetailers" + customRetailers);
28272 tejbeer 806
		RetailerBrandsLimit retailerBrands = retailerBrandsLimitRepository.selectLimitByBrandAndFofoId(fofoId, brand);
28277 tejbeer 807
 
28272 tejbeer 808
		if (retailerBrands == null) {
809
			retailerBrands = new RetailerBrandsLimit();
810
			retailerBrands.setBrandLimit(limit);
811
			retailerBrands.setIsUpdate(1);
812
			retailerBrands.setCreatedTimestamp(LocalDateTime.now());
813
			retailerBrands.setPartnerId(fofoId);
814
			retailerBrands.setBrandName(brand);
815
			retailerBrands.setUpdatedTimestamp(LocalDateTime.now());
816
			retailerBrandsLimitRepository.persist(retailerBrands);
817
 
818
		}
819
 
820
		else {
821
			retailerBrands.setBrandLimit(limit);
822
			retailerBrands.setIsUpdate(1);
823
			retailerBrands.setUpdatedTimestamp(LocalDateTime.now());
824
			retailerBrandsLimitRepository.persist(retailerBrands);
825
 
826
		}
827
		retailerBrands = retailerBrandsLimitRepository.selectLimitByBrandAndFofoId(fofoId, brand);
828
 
829
		Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = new HashMap<>();
830
 
831
		retailerBrandsLimitMap.put(retailerBrands.getPartnerId(), retailerBrands);
832
 
833
		BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brand);
834
 
835
		model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
836
		model.addAttribute("brandLimit", brandLimit);
837
		model.addAttribute("customRetailers", customRetailers);
28277 tejbeer 838
 
839
		model.addAttribute("brand", brand);
28272 tejbeer 840
		return "brands-limit-row-mapping";
841
 
842
	}
843
 
844
	@RequestMapping(value = "/getRetailerBrandslimitMapping", method = RequestMethod.GET)
845
	public String getRetailerBrandslimit(HttpServletRequest request,
846
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
847
			throws Exception {
848
 
849
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
28283 tejbeer 850
		List<RetailerBrandsLimit> retailerBrandsLimit = retailerBrandsLimitRepository.setAllLimitByBrands(brand);
851
		Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = retailerBrandsLimit.stream()
852
				.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
28272 tejbeer 853
 
854
		model.addAttribute("customRetailers", customRetailers);
855
		model.addAttribute("brand", brand);
28283 tejbeer 856
		model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
28272 tejbeer 857
 
858
		BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brand);
859
 
860
		model.addAttribute("brandLimit", brandLimit);
861
 
862
		return "brands-limit-mapping";
863
 
864
	}
865
 
866
	@RequestMapping(value = "/setBrandWiseLimit", method = RequestMethod.POST)
867
	public String brandwiseLimit(HttpServletRequest request,
868
			@RequestParam(name = "brands", required = true, defaultValue = "") String brands,
869
			@RequestParam(name = "limit", required = true, defaultValue = "") float limit, Model model)
870
			throws Exception {
871
 
872
		LOGGER.info("limit" + limit);
873
 
874
		BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brands);
875
 
876
		List<RetailerBrandsLimit> retailerBrandsLimit = retailerBrandsLimitRepository.setAllLimitByBrands(brands);
877
 
878
		Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = retailerBrandsLimit.stream()
879
				.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
880
 
881
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
882
 
883
		if (brandLimit == null) {
884
 
885
			brandLimit = new BrandLimit();
886
			brandLimit.setBrandLimit(limit);
887
			brandLimit.setBrandName(brands);
888
			brandLimit.setCreatedTimestamp(LocalDateTime.now());
889
			brandLimit.setUpdatedTimestamp(LocalDateTime.now());
890
			brandLimitRepository.persist(brandLimit);
891
 
892
		}
893
 
894
		else {
895
			brandLimit.setBrandLimit(limit);
896
 
897
			brandLimit.setUpdatedTimestamp(LocalDateTime.now());
898
			brandLimitRepository.persist(brandLimit);
899
 
900
		}
901
		brandLimit = brandLimitRepository.setLimitByBrands(brands);
902
 
903
		LOGGER.info("brandLimit" + brandLimit);
28277 tejbeer 904
		model.addAttribute("brand", brands);
28272 tejbeer 905
		model.addAttribute("brandLimit", brandLimit);
906
		model.addAttribute("customRetailers", customRetailers);
907
		model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
908
		return "brands-limit-mapping";
909
 
910
	}
28381 tejbeer 911
 
912
 
913
 
914
 
915
	@RequestMapping(value = "/setPartnerPincode", method = RequestMethod.POST)
916
	public String setPartnerPincode(HttpServletRequest request,
917
			@RequestParam(name = "pincode", required = true, defaultValue = "") String pincode,
918
			@RequestParam(name = "fofoId", required = true, defaultValue = "") int fofoId,Model model) throws Exception {
28272 tejbeer 919
 
28381 tejbeer 920
		if(!pincode.equals("")) {
921
	    PincodePartner pinPartner = new PincodePartner();	
922
		pinPartner.setFofoId(fofoId);
923
		pinPartner.setPincode(pincode);
924
		PincodePartnerRepository.perist(pinPartner);
925
		}
926
 
927
	List<PincodePartner> partnerPincodeList=	PincodePartnerRepository.selectByPartnerId(fofoId);
928
 
929
	LOGGER.info("partnerPincodeList" +partnerPincodeList);
930
 
931
	model.addAttribute("partnerPincodeList", partnerPincodeList);
932
		return "pincode-partner-index";
933
 
934
	}
935
 
936
 
937
	@RequestMapping(value = "/removePartnerPincode", method = RequestMethod.POST)
938
	public String removePartnerPincode(HttpServletRequest request,
939
			@RequestParam int id,
940
			@RequestParam(name = "fofoId", required = true, defaultValue = "") int fofoId,Model model) throws Exception {
941
 
942
 
943
	PincodePartnerRepository.delete(id);
944
 
945
	List<PincodePartner> partnerPincodeList=	PincodePartnerRepository.selectByPartnerId(fofoId);
946
 
947
	LOGGER.info("partnerPincodeList" +partnerPincodeList);
948
 
949
	model.addAttribute("partnerPincodeList", partnerPincodeList);
950
 
951
		return "pincode-partner-index";
952
 
953
	}
954
 
955
	@RequestMapping(value = "/removeSearchPincode", method = RequestMethod.POST)
956
	public String removeSearchPincode(HttpServletRequest request,@RequestParam int id,
957
			@RequestParam(name = "pin", required = true, defaultValue = "") String pin,
958
			@RequestParam(name = "fofoId", required = true, defaultValue = "") int fofoId,Model model) throws Exception {
959
 
960
 
961
	PincodePartnerRepository.delete(id);
962
 
963
	List<PincodePartner> partnerPincodeList=	PincodePartnerRepository.selectPartnersByPincode(pin);
964
 
965
	Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
966
 
967
 
968
	model.addAttribute("customRetailerMap", customRetailerMap);
969
 
970
	model.addAttribute("partnerPincodeList", partnerPincodeList);
971
 
972
 
973
		return "search-pincode-partner";
974
 
975
	}
976
 
977
	@RequestMapping(value = "/searchPincodePartner", method = RequestMethod.GET)
978
	public String searchPincodePartner(HttpServletRequest request,
979
			@RequestParam(name = "pincode", required = true, defaultValue = "") String pincode,Model model) throws Exception {
980
 
981
		List<PincodePartner> partnerPincodeList=	PincodePartnerRepository.selectPartnersByPincode(pincode);
982
 
983
		Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
984
 
985
 
986
		model.addAttribute("customRetailerMap", customRetailerMap);
987
 
988
		model.addAttribute("partnerPincodeList", partnerPincodeList);
989
 
990
		return "search-pincode-partner";
991
 
992
 
993
	}
994
 
995
	@RequestMapping(value = "/showPartnerPincode", method = RequestMethod.GET)
996
	public String showPartnerPincode(HttpServletRequest request,
997
			@RequestParam(name = "partnerId", required = true, defaultValue = "") int partnerId,Model model) throws Exception {
998
 
999
		List<PincodePartner> partnerPincodeList=	PincodePartnerRepository.selectByPartnerId(partnerId);
1000
 
1001
 
1002
		model.addAttribute("partnerPincodeList", partnerPincodeList);
1003
 
1004
		return "pincode-partner-index";
1005
 
1006
 
1007
	}
1008
 
1009
 
1010
	@RequestMapping(value = "/getAllPartnerPincode", method = RequestMethod.GET)
1011
	public String getAllPartnerPincode(HttpServletRequest request,
1012
			Model model) throws Exception {
1013
 
1014
 
1015
 
1016
		return "add-partner-pincode";
1017
 
1018
 
1019
	}
28272 tejbeer 1020
}