Subversion Repositories SmartDukaan

Rev

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