Subversion Repositories SmartDukaan

Rev

Rev 34211 | Rev 34631 | 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 com.spice.profitmandi.common.enumuration.ContentType;
23955 govind 4
import com.spice.profitmandi.common.enumuration.CounterSize;
28825 tejbeer 5
import com.spice.profitmandi.common.enumuration.FofoType;
22981 ashik.ali 6
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
30017 amit.gupta 7
import com.spice.profitmandi.common.model.*;
28024 tejbeer 8
import com.spice.profitmandi.common.util.Utils;
23330 ashik.ali 9
import com.spice.profitmandi.common.web.util.ResponseSender;
27231 tejbeer 10
import com.spice.profitmandi.dao.entity.auth.AuthUser;
30017 amit.gupta 11
import com.spice.profitmandi.dao.entity.dtr.*;
12
import com.spice.profitmandi.dao.entity.fofo.*;
34527 tejus.loha 13
import com.spice.profitmandi.dao.entity.onBoarding.LoiForm;
24159 tejbeer 14
import com.spice.profitmandi.dao.entity.user.Location;
15
import com.spice.profitmandi.dao.entity.user.Promoter;
24123 tejbeer 16
import com.spice.profitmandi.dao.entity.user.User;
27231 tejbeer 17
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
18
import com.spice.profitmandi.dao.repository.cs.CsService;
28272 tejbeer 19
import com.spice.profitmandi.dao.repository.cs.RetailerBrandsLimitService;
30017 amit.gupta 20
import com.spice.profitmandi.dao.repository.dtr.*;
27797 tejbeer 21
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeRepository;
22
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
28381 tejbeer 23
import com.spice.profitmandi.dao.repository.fofo.PincodePartnerRepository;
24123 tejbeer 24
import com.spice.profitmandi.dao.repository.user.LocationRepository;
34527 tejus.loha 25
import com.spice.profitmandi.dao.repository.user.LoiFormRepository;
24159 tejbeer 26
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
24123 tejbeer 27
import com.spice.profitmandi.dao.repository.user.UserRepository;
33990 tejus.loha 28
import com.spice.profitmandi.dao.repository.warehouse.WarehouseSupplierInvoiceRepository;
24349 amit.gupta 29
import com.spice.profitmandi.service.PartnerInvestmentService;
33814 ranu 30
import com.spice.profitmandi.service.authentication.RoleManager;
32731 ranu 31
import com.spice.profitmandi.service.catalog.BrandsService;
24159 tejbeer 32
import com.spice.profitmandi.service.inventory.InventoryService;
22981 ashik.ali 33
import com.spice.profitmandi.service.user.RetailerService;
28908 tejbeer 34
import com.spice.profitmandi.service.user.StoreTimelineTatService;
25276 amit.gupta 35
import com.spice.profitmandi.web.model.LoginDetails;
36
import com.spice.profitmandi.web.util.CookiesProcessor;
24123 tejbeer 37
import com.spice.profitmandi.web.util.MVCResponseSender;
30017 amit.gupta 38
import org.apache.logging.log4j.LogManager;
39
import org.apache.logging.log4j.Logger;
40
import org.json.JSONObject;
41
import org.springframework.beans.factory.annotation.Autowired;
42
import org.springframework.beans.factory.annotation.Qualifier;
43
import org.springframework.core.io.InputStreamResource;
44
import org.springframework.http.HttpHeaders;
45
import org.springframework.http.HttpStatus;
46
import org.springframework.http.ResponseEntity;
47
import org.springframework.stereotype.Controller;
48
import org.springframework.ui.Model;
49
import org.springframework.web.bind.annotation.*;
22981 ashik.ali 50
 
30017 amit.gupta 51
import javax.servlet.http.HttpServletRequest;
52
import javax.transaction.Transactional;
53
import java.io.File;
54
import java.io.FileInputStream;
55
import java.io.FileNotFoundException;
56
import java.time.LocalDate;
57
import java.time.LocalDateTime;
58
import java.util.*;
59
import java.util.stream.Collectors;
60
 
22981 ashik.ali 61
@Controller
25277 amit.gupta 62
@Transactional(rollbackOn = Throwable.class)
22981 ashik.ali 63
public class RetailerController {
64
 
33990 tejus.loha 65
    private static final Logger LOGGER = LogManager.getLogger(RetailerController.class);
66
    private static final List<String> CHANGE_PARTNER_CATEGORY_PERMISSIONS = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "shankar.mushra@smartdukaan.com");
67
    @Autowired
68
    PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
69
    @Autowired
70
    BrandsService brandsService;
71
    @Autowired
72
    private RetailerService retailerService;
73
    @Autowired
74
    private RetailerRepository retailerRepository;
75
    @Autowired
76
    private PincodePartnerRepository pincodePartnerRepository;
77
    @Autowired
78
    private BrandLimitRepository brandLimitRepository;
79
    @Autowired
80
    private RetailerBrandsLimitService retailerBrandsLimitService;
81
    @Autowired
82
    private RetailerBrandsLimitRepository retailerBrandsLimitRepository;
83
    @Autowired
84
    private ShopRepository shopRepository;
85
    @Autowired
86
    private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
87
    @Autowired
88
    private FofoStoreRepository fofoStoreRepository;
89
    @Autowired
90
    private DocumentRepository documentRepository;
91
    @Autowired
92
    private CookiesProcessor cookiesProcessor;
93
    @Autowired
94
    @Qualifier("userUserRepository")
95
    private UserRepository userRepository;
96
    @Autowired
97
    private AuthRepository authRepository;
98
    @Autowired
99
    private CsService csService;
100
    @Autowired
101
    private LocationRepository locationRepository;
102
    @Autowired
103
    private ResponseSender<?> responseSender;
104
    @Autowired
105
    private MVCResponseSender mvcResponseSender;
106
    @Autowired
107
    private InventoryService inventoryService;
108
    @Autowired
109
    private PromoterRepository promoterRepository;
110
    @Autowired
111
    private PartnerInvestmentService partnerInvestmentService;
112
    @Autowired
113
    private Mongo mongoClient;
114
    @Autowired
115
    private PartnerTypeChangeService partnerTypeChangeService;
116
    @Autowired
117
    private PartnerTypeChangeRepository partnerTypeChangeRepository;
118
    @Autowired
119
    private StoreTimelineTatService storeTimelineTatService;
120
    @Autowired
121
    private RoleManager roleManager;
122
    @Autowired
123
    private RetailerContactRepository retailerContactRepository;
124
    @Autowired
125
    private WarehouseSupplierInvoiceRepository warehouseSupplierInvoiceRepository;
24124 govind 126
 
33990 tejus.loha 127
    @RequestMapping(value = "/retailerDetails", method = RequestMethod.GET)
128
    public String retailerInfoByEmailIdOrMobileNumber(HttpServletRequest request,
129
                                                      @RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber,
130
                                                      Model model) throws ProfitMandiBusinessException {
131
        LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(),
132
                emailIdOrMobileNumber);
24124 govind 133
 
33990 tejus.loha 134
        Map<String, Object> map = retailerService.getByEmailIdOrMobileNumber(emailIdOrMobileNumber);
32667 raveendra. 135
 
33990 tejus.loha 136
        model.addAllAttributes(map);
28832 tejbeer 137
 
33990 tejus.loha 138
        model.addAttribute("counterSizes", CounterSize.values());
139
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
28832 tejbeer 140
 
33990 tejus.loha 141
        LOGGER.info("warehouseMap", warehouseMap);
142
        model.addAttribute("warehouses", warehouseMap);
143
        model.addAttribute("fofoTypes", FofoType.values());
144
        if (map.containsKey("retailer")) {
145
            Retailer retailer = (Retailer) map.get("retailer");
146
            User user = userRepository.selectById(retailer.getId());
147
            if (user.getLocation() != null) {
148
                Location location = locationRepository.selectById(user.getLocation());
149
                model.addAttribute("locationdetail", location);
150
                LOGGER.info("location" + location);
151
            }
152
        }
153
        return "retailer-details";
154
    }
28272 tejbeer 155
 
34527 tejus.loha 156
    @Autowired
157
    LoiFormRepository loiFormRepository;
158
 
33990 tejus.loha 159
    @RequestMapping(value = "/retailerDetails", method = RequestMethod.PUT)
160
    public String updateRetailerDetails(HttpServletRequest request,
161
                                        @RequestBody UpdateRetailerRequest updateRetailerRequest, Model model) throws ProfitMandiBusinessException {
162
        LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), updateRetailerRequest);
34527 tejus.loha 163
        if (!updateRetailerRequest.getFofoType().equals(FofoType.INTERNAL)) {
164
            LoiForm loiForm = null;
165
            loiForm = loiFormRepository.selectByEmailOrMobile(updateRetailerRequest.getUserMobileNumber());
166
            if (loiForm == null) {
167
                loiForm = loiFormRepository.selectByEqualsKeyValue("gstNo", updateRetailerRequest.getGstNumber());
168
                if (loiForm == null) {
169
                    throw new ProfitMandiBusinessException("Loi Not Available of this User", "Message - ", "Please fill the LOI_FORM and try again");
170
                }
171
            }
172
 
173
        }
33990 tejus.loha 174
        Map<String, Object> map = retailerService.updateRetailerDetails(updateRetailerRequest);
175
        //retailerService.up
28272 tejbeer 176
 
33990 tejus.loha 177
        model.addAllAttributes(map);
178
        model.addAttribute("counterSizes", CounterSize.values());
179
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
180
        LOGGER.info("warehouseMap", warehouseMap);
181
        model.addAttribute("warehouses", warehouseMap);
182
        model.addAttribute("fofoTypes", FofoType.values());
183
        return "retailer-details";
184
    }
28272 tejbeer 185
 
33990 tejus.loha 186
    @RequestMapping(value = "/retailer/update-email", method = RequestMethod.POST)
187
    public String updateRetailerEmail(@RequestParam("newEmail") String newEmail, @RequestParam("fofoID") int fofoID) throws ProfitMandiBusinessException {
188
        retailerService.updateRetailerEmail(fofoID, newEmail);
189
        return "retailer-details";
190
    }
24124 govind 191
 
33990 tejus.loha 192
    @RequestMapping(value = "/retailerInfo", method = RequestMethod.GET)
193
    public String retailerInfo(HttpServletRequest request) throws Exception {
194
        return "retailer-info";
195
    }
28024 tejbeer 196
 
33990 tejus.loha 197
    @RequestMapping(value = "/district/all/stateName", method = RequestMethod.GET)
198
    public ResponseEntity<?> getAllDistrict(@RequestParam(name = "stateName") String stateName) {
199
        return responseSender.ok(retailerService.getAllDistrictMaster(stateName));
200
    }
24124 govind 201
 
33990 tejus.loha 202
    @RequestMapping(value = "/retailerDocument/documentId", method = RequestMethod.GET)
203
    public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
204
                                                  @RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId,
205
                                                  @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
206
        Document document = documentRepository.selectById(documentId);
207
        Retailer retailer = retailerRepository.selectById(retailerId);
24124 govind 208
 
33990 tejus.loha 209
        if (retailer.getDocumentId() == null) {
210
            throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
211
        }
212
        if (retailer.getDocumentId() != documentId) {
213
            throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
214
        }
215
        return responseSender.ok(document);
216
    }
25276 amit.gupta 217
 
33990 tejus.loha 218
    @RequestMapping(value = "/retailerDocument/download", method = RequestMethod.GET)
219
    public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request,
220
                                                      @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
221
            throws ProfitMandiBusinessException {
24124 govind 222
 
33990 tejus.loha 223
        Retailer retailer = retailerRepository.selectById(retailerId);
27231 tejbeer 224
 
33990 tejus.loha 225
        if (retailer.getDocumentId() == null) {
226
            throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
227
        }
27231 tejbeer 228
 
33990 tejus.loha 229
        Document document = documentRepository.selectById(retailer.getDocumentId());
24124 govind 230
 
33990 tejus.loha 231
        FileInputStream file = null;
232
        try {
233
            file = new FileInputStream(document.getPath() + File.separator + document.getName());
234
        } catch (FileNotFoundException e) {
235
            LOGGER.error("Retailer Document file not found : ", e);
236
            throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
237
        }
238
        // ByteArrayOutputStream byteArrayOutputStream = new
239
        // ByteArrayOutputStream();
240
        // ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
24124 govind 241
 
33990 tejus.loha 242
        final HttpHeaders headers = new HttpHeaders();
243
        String contentType = "";
244
        if (document.getContentType() == ContentType.JPEG) {
245
            contentType = "image/jpeg";
246
        } else if (document.getContentType() == ContentType.PNG) {
247
            contentType = "image/png";
248
        } else if (document.getContentType() == ContentType.PDF) {
249
            contentType = "application/pdf";
250
        }
251
        headers.set("Content-Type", contentType);
252
        headers.set("Content-disposition", "inline; filename=" + document.getName());
253
        headers.setContentLength(document.getSize());
254
        final InputStreamResource inputStreamResource = new InputStreamResource(file);
255
        return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
24124 govind 256
 
33990 tejus.loha 257
        // return
258
        // responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
259
    }
24159 tejbeer 260
 
33990 tejus.loha 261
    @RequestMapping(value = "/retailerShopDocument/shopId", method = RequestMethod.GET)
262
    public ResponseEntity<?> retailerShopDocumentById(HttpServletRequest request,
263
                                                      @RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
264
                                                      @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
265
        Shop shop = shopRepository.selectById(shopId);
24159 tejbeer 266
 
33990 tejus.loha 267
        if (shop.getRetailerId() != retailerId) {
268
            throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
269
        }
24349 amit.gupta 270
 
33990 tejus.loha 271
        if (shop.getDocumentId() == null) {
272
            throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
273
        }
24159 tejbeer 274
 
33990 tejus.loha 275
        Document document = documentRepository.selectById(shop.getDocumentId());
276
        return responseSender.ok(document);
277
    }
27797 tejbeer 278
 
33990 tejus.loha 279
    @RequestMapping(value = "/retailerShopDocument/download", method = RequestMethod.GET)
280
    public ResponseEntity<?> downloadRetailerShopDocument(HttpServletRequest request,
281
                                                          @RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
282
                                                          @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
283
            throws ProfitMandiBusinessException {
27797 tejbeer 284
 
33990 tejus.loha 285
        Shop shop = shopRepository.selectById(shopId);
28908 tejbeer 286
 
33990 tejus.loha 287
        if (shop.getRetailerId() != retailerId) {
288
            throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
289
        }
28908 tejbeer 290
 
33990 tejus.loha 291
        if (shop.getDocumentId() == null) {
292
            throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
293
        }
33814 ranu 294
 
33990 tejus.loha 295
        Document document = documentRepository.selectById(shop.getDocumentId());
33814 ranu 296
 
33990 tejus.loha 297
        FileInputStream file = null;
298
        try {
299
            file = new FileInputStream(document.getPath() + File.separator + document.getName());
300
        } catch (FileNotFoundException e) {
301
            LOGGER.error("Retailer Document file not found : ", e);
302
            throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
303
        }
304
        // ByteArrayOutputStream byteArrayOutputStream = new
305
        // ByteArrayOutputStream();
306
        // ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
28071 tejbeer 307
 
33990 tejus.loha 308
        final HttpHeaders headers = new HttpHeaders();
309
        String contentType = "";
310
        if (document.getContentType() == ContentType.JPEG) {
311
            contentType = "image/jpeg";
312
        } else if (document.getContentType() == ContentType.PNG) {
313
            contentType = "image/png";
314
        } else if (document.getContentType() == ContentType.PDF) {
315
            contentType = "application/pdf";
316
        }
317
        headers.set("Content-Type", contentType);
318
        headers.set("Content-disposition", "inline; filename=" + document.getName());
319
        headers.setContentLength(document.getSize());
320
        final InputStreamResource inputStreamResource = new InputStreamResource(file);
321
        return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
28071 tejbeer 322
 
33990 tejus.loha 323
        // return
324
        // responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
325
    }
28071 tejbeer 326
 
33990 tejus.loha 327
    @GetMapping(value = "/getstore")
33247 ranu 328
    public String getstore(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
30017 amit.gupta 329
 
33990 tejus.loha 330
        List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
331
                .collect(Collectors.toList());
30426 tejbeer 332
 
33990 tejus.loha 333
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
30426 tejbeer 334
 
33990 tejus.loha 335
        Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = fofoIds.stream().map(x -> customRetailerMap.get(x))
336
                .filter(x -> x != null).collect(Collectors.toList()).stream()
337
                .collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
30426 tejbeer 338
 
33990 tejus.loha 339
        //LOGGER.info("fofoIds" + fofoIds);
340
        model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
341
        //LOGGER.info("fofoIdsAndCustomRetailer" + fofoIdsAndCustomRetailer);
342
        model.addAttribute("fofoIds", fofoIds);
24124 govind 343
 
33990 tejus.loha 344
        return "store";
29267 manish 345
 
33990 tejus.loha 346
    }
30017 amit.gupta 347
 
33990 tejus.loha 348
    @RequestMapping(value = "/getPartnerinfo")
349
    public String getPartnerinfo(HttpServletRequest request, @RequestBody SelectStorePartnerInfo selectStorePartnerInfo,
350
                                 Model model) throws ProfitMandiBusinessException {
351
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
352
        //LOGGER.info("selectStorePartnerInfo" + selectStorePartnerInfo.getUserIds());
353
        List<FofoStore> fofoStores = fofoStoreRepository.selectByRetailerIds(selectStorePartnerInfo.getUserIds());
354
        //LOGGER.info("fofoStoresInfo" + fofoStores);
355
        Map<Integer, Boolean> investments = new HashMap<>();
32207 amit.gupta 356
 
33990 tejus.loha 357
        for (FofoStore fofoStore : fofoStores) {
358
            boolean isOk = false;
359
            if (fofoStore.getGraceDate() != null && fofoStore.getGraceDate().isAfter(LocalDate.now())) {
360
                isOk = true;
361
            } else {
362
                try {
363
                    isOk = partnerInvestmentService.isInvestmentOk(fofoStore.getId(), ProfitMandiConstants.MIN_INVESTMENT_PERCENTAGE,
364
                            ProfitMandiConstants.CUTOFF_INVESTMENT);
365
                    if (fofoStore.getGraceCount() > 0) {
366
                        fofoStore.setGraceDate(null);
367
                        fofoStore.setGraceCount(0);
368
                    }
369
                } catch (ProfitMandiBusinessException e) {
370
                }
371
            }
372
            investments.put(fofoStore.getId(), isOk);
373
        }
29267 manish 374
 
33990 tejus.loha 375
        Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(false);
376
        model.addAttribute("fofoStores", fofoStores);
377
        model.addAttribute("investments", investments);
378
        model.addAttribute("customRetailers", customRetailers);
379
        boolean canChangeCategory = CHANGE_PARTNER_CATEGORY_PERMISSIONS.contains(loginDetails.getEmailId());
380
        model.addAttribute("canChangeCategory", canChangeCategory);
29267 manish 381
 
33990 tejus.loha 382
        return "store-investment";
29267 manish 383
 
33990 tejus.loha 384
    }
29267 manish 385
 
33990 tejus.loha 386
    @GetMapping(value = "/getAllStores")
387
    public String getAllStores(HttpServletRequest request, Model model) throws Exception {
30017 amit.gupta 388
 
33990 tejus.loha 389
        List<FofoStore> fofoStores = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive())
390
                .collect(Collectors.toList());
391
        Map<Integer, Boolean> investments = new HashMap<>();
24124 govind 392
 
33990 tejus.loha 393
        for (FofoStore fofoStore : fofoStores) {
394
            boolean isOk = false;
395
            if (fofoStore.getGraceDate() != null && fofoStore.getGraceDate().isAfter(LocalDate.now())) {
396
                isOk = true;
397
            } else {
398
                try {
399
                    isOk = partnerInvestmentService.isInvestmentOk(fofoStore.getId(), ProfitMandiConstants.MIN_INVESTMENT_PERCENTAGE,
400
                            ProfitMandiConstants.CUTOFF_INVESTMENT);
401
                    if (fofoStore.getGraceCount() > 0) {
402
                        fofoStore.setGraceDate(null);
403
                        fofoStore.setGraceCount(0);
404
                    }
405
                } catch (ProfitMandiBusinessException e) {
406
                }
407
            }
408
            investments.put(fofoStore.getId(), isOk);
409
        }
24124 govind 410
 
33990 tejus.loha 411
        Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(false);
412
        model.addAttribute("fofoStores", fofoStores);
413
        model.addAttribute("investments", investments);
414
        model.addAttribute("customRetailers", customRetailers);
24124 govind 415
 
33990 tejus.loha 416
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
417
        boolean canChangeCategory = CHANGE_PARTNER_CATEGORY_PERMISSIONS.contains(loginDetails.getEmailId());
418
        model.addAttribute("canChangeCategory", canChangeCategory);
24124 govind 419
 
33990 tejus.loha 420
        return "store-investment";
32207 amit.gupta 421
 
33990 tejus.loha 422
    }
24124 govind 423
 
33990 tejus.loha 424
    @GetMapping(value = "/getPartnerCategory")
33247 ranu 425
    public String getPartnerCategory(HttpServletRequest request, @RequestParam int fofoId, Model model) throws ProfitMandiBusinessException {
27797 tejbeer 426
 
33990 tejus.loha 427
        PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
428
        List<PartnerType> partnerTypes = partnerType.nextPartnerTypes();
429
        LOGGER.info("partnerType" + partnerTypes);
430
        model.addAttribute("partnerTypes", partnerTypes);
431
        model.addAttribute("fofoId", fofoId);
432
        return "partner-category";
433
    }
27797 tejbeer 434
 
33990 tejus.loha 435
    @PostMapping(value = "/updatePartnerCategory")
436
    public String updatePartnerCategory(HttpServletRequest request, @RequestParam(name = "fofoId") int fofoId,
437
                                        @RequestParam(name = "partnerType") PartnerType partnerType, Model model) throws Exception {
27797 tejbeer 438
 
33990 tejus.loha 439
        PartnerTypeChange ptc = new PartnerTypeChange();
440
        ptc.setFofoId(fofoId);
441
        ptc.setPartnerType(partnerType);
442
        ptc.setCreateTimestamp(LocalDate.now().atStartOfDay().plusDays(1));
443
        partnerTypeChangeRepository.persist(ptc);
444
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
27797 tejbeer 445
 
33990 tejus.loha 446
        return "response";
447
    }
27797 tejbeer 448
 
33990 tejus.loha 449
    @GetMapping(value = "/partners")
450
    public String getStoreName(HttpServletRequest request, Model model, @RequestParam String query) throws Exception {
451
        model.addAttribute("response1",
452
                mvcResponseSender.createResponseString(retailerService.getFofoRetailers(false).values().stream()
453
                        .filter(x -> x.getDisplayName().toLowerCase().matches(".*?" + query.toLowerCase() + ".*?"))
454
                        .collect(Collectors.toList())));
455
        return "response";
456
    }
24349 amit.gupta 457
 
33990 tejus.loha 458
    @PostMapping(value = "/deactivateStore")
459
    public String deActivateStore(HttpServletRequest request,
460
                                  @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
461
        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
462
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
463
        if (!Arrays
464
                .asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "amit.gupta@smartdukaan.com",
34211 vikas.jang 465
                        "rahul.katyal@smartdukaan.com", "vikas.jangra@smartdukaan.com", "sm@smartdukaan.com")
33990 tejus.loha 466
                .contains(loginDetails.getEmailId())) {
467
            throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
468
                    "You are not authorise to deactivate retailer");
469
        }
470
        fofoStore.setActive(false);
471
        LOGGER.info("inserted into InActiveFofoStore successfully");
472
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
473
        return "response";
474
    }
28825 tejbeer 475
 
33990 tejus.loha 476
    @PostMapping(value = "/activateStoreForever")
477
    public String activateStoreForever(HttpServletRequest request,
478
                                       @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
479
        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
480
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
481
        if (!Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "amit.gupta@smartdukaan.com",
482
                "rahul.katyal@smartdukaan.com", "sm@smartdukaan.com").contains(loginDetails.getEmailId())) {
483
            throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
484
                    "You are not authorise to activate retailer");
485
        }
486
        fofoStore.setActive(true);
487
        LOGGER.info("inserted into ActiveFofoStore successfully");
488
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
489
        return "response";
490
    }
28825 tejbeer 491
 
33990 tejus.loha 492
    @PostMapping(value = "/activateStoreTemporary")
493
    public String activateStoreTemporary(HttpServletRequest request,
494
                                         @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId,
495
                                         @RequestParam(name = "days", required = true) int days, Model model) throws Exception {
28825 tejbeer 496
 
33990 tejus.loha 497
        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
498
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
499
        if (!Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "amit.gupta@smartdukaan.com",
500
                "rahul.katyal@smartdukaan.com", "sm@smartdukaan.com").contains(loginDetails.getEmailId())) {
501
            throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
502
                    "You are not authorise to deactivate retailer");
503
        }
28825 tejbeer 504
 
33990 tejus.loha 505
        LocalDateTime currentDate = LocalDate.now().atStartOfDay();
28825 tejbeer 506
 
33990 tejus.loha 507
        LocalDateTime EndDate = currentDate.plusDays(days);
508
        fofoStore.setActiveTimeStamp(EndDate);
28825 tejbeer 509
 
33990 tejus.loha 510
        LOGGER.info("EndDate" + EndDate);
511
        LOGGER.info("getActiveTimeStamp" + fofoStore.getActiveTimeStamp());
28825 tejbeer 512
 
33990 tejus.loha 513
        if (currentDate.isBefore(fofoStore.getActiveTimeStamp())) {
514
            fofoStore.setActive(true);
515
            LOGGER.info("inserted into InActiveFofoStore successfully");
516
        }
28825 tejbeer 517
 
33990 tejus.loha 518
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
519
        return "response";
520
    }
25276 amit.gupta 521
 
33990 tejus.loha 522
    @GetMapping(value = "/getAllInactiveStores")
33247 ranu 523
    public String getInactiveStores(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
33990 tejus.loha 524
        List<FofoStore> inActiveFofoStores = fofoStoreRepository.selectInActiveStore();
30426 tejbeer 525
 
33990 tejus.loha 526
        LOGGER.info("inActiveFofoStores {}", inActiveFofoStores);
527
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
30426 tejbeer 528
 
33990 tejus.loha 529
        List<Integer> fofoIds = inActiveFofoStores.stream().map(x -> x.getId()).collect(Collectors.toList());
30431 tejbeer 530
 
33990 tejus.loha 531
        Map<Integer, CustomRetailer> customRetailers = fofoIds.stream().map(x -> customRetailerMap.get(x))
532
                .filter(x -> x != null).collect(Collectors.toList()).stream()
533
                .collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
534
        LOGGER.info("customRetailers {}", customRetailers);
30426 tejbeer 535
 
33990 tejus.loha 536
        model.addAttribute("inActiveFofoStores", inActiveFofoStores);
537
        model.addAttribute("customRetailers", customRetailers);
538
        return "inactive-stores";
539
    }
25276 amit.gupta 540
 
33990 tejus.loha 541
    // Extend billing for 2 days
542
    @PostMapping(value = "/extendBilling")
543
    public String extendBilling(HttpServletRequest request,
544
                                @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
545
        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
546
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
547
        if (Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "amit.gupta@smartdukaan.com",
548
                "rahul.katyal@smartdukaan.com", "sm@smartdukaan.com", "mohit.gulati@smartdukaan.com", "chiranjib.sarkar@smartdukaan.com").contains(loginDetails.getEmailId())) {
549
            fofoStore.setGraceDate(LocalDate.now().plusDays(2));
550
            fofoStore.setGraceCount(fofoStore.getGraceCount() + 1);
551
            model.addAttribute("response1", mvcResponseSender.createResponseString(fofoStore.getGraceCount()));
552
        } else {
553
            throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
554
                    "You are not authorise to extend billing");
555
        }
556
        return "response";
25276 amit.gupta 557
 
33990 tejus.loha 558
    }
24124 govind 559
 
33990 tejus.loha 560
    @RequestMapping(value = "/getPromoterInfo", method = RequestMethod.GET)
32887 shampa 561
 
33990 tejus.loha 562
    public String getShowPromoterInfo(HttpServletRequest request,
563
                                      @RequestParam(name = "offset", defaultValue = "0") int offset,
564
                                      @RequestParam(name = "limit", defaultValue = "10") int limit,
565
                                      @RequestParam(name = "fofoId", required = false, defaultValue = "0") int fofoId, Model model)
566
            throws Exception {
567
        //LOGGER.info("requested url : " + request.getRequestURL().toString());
568
        List<Promoter> promoterInfo = null;
569
        long size = 0;
24159 tejbeer 570
 
33990 tejus.loha 571
        List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
572
                .collect(Collectors.toList());
32887 shampa 573
 
33990 tejus.loha 574
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
32887 shampa 575
 
33990 tejus.loha 576
        Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> customRetailerMap.get(x))
577
                .filter(x -> x != null).collect(Collectors.toList()).stream()
578
                .collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
579
        String customRetailers = JSONObject.valueToString(customRetailersMap.values());
580
        Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
581
        brands.add("Airtel");
582
        brands.add("Vodafone");
583
        brands.add("Idea");
584
        LOGGER.info("brands" + brands);
585
        model.addAttribute("customRetailers", customRetailers);
586
        model.addAttribute("brands", brands);
32887 shampa 587
 
33990 tejus.loha 588
        if (fofoId != 0) {
589
            promoterInfo = promoterRepository.selectAllPromoterByFofoIdStatus(fofoId, offset, limit, true);
32887 shampa 590
 
33990 tejus.loha 591
            //size = promoterRepository.selectPromoterCount(fofoId);
592
            size = promoterInfo.size();
593
        } else {
594
            //rkb
595
            promoterInfo = promoterRepository.selectAllPromoterStatus(offset, limit, true);
32887 shampa 596
 
33990 tejus.loha 597
            //size = promoterRepository.selectAllCount();
598
            size = promoterInfo.size();
599
        }
600
        if (!promoterInfo.isEmpty()) {
601
            Set<Integer> partnerIds = new HashSet<>();
32887 shampa 602
 
33990 tejus.loha 603
            for (Promoter promoterdetail : promoterInfo) {
604
                partnerIds.add(promoterdetail.getRetailerId());
605
            }
606
            Map<Integer, CustomRetailer> partnersMap = null;
607
            if (!partnerIds.equals(null)) {
608
                LOGGER.info("partnerIds" + partnerIds);
32887 shampa 609
 
33990 tejus.loha 610
                partnersMap = partnerIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null)
611
                        .collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
32887 shampa 612
 
33990 tejus.loha 613
            }
32887 shampa 614
 
33990 tejus.loha 615
            LOGGER.info("partnerIds" + partnersMap);
616
            model.addAttribute("promoterInfo", promoterInfo);
617
            model.addAttribute("partnersMap", partnersMap);
618
            model.addAttribute("start", offset + 1);
619
            model.addAttribute("size", size);
620
            model.addAttribute("url", "/getPaginatedPromoterInfo");
32887 shampa 621
 
33990 tejus.loha 622
            if (promoterInfo.size() < limit) {
623
                model.addAttribute("end", offset + promoterInfo.size());
624
            } else {
625
                model.addAttribute("end", offset + limit);
626
            }
627
        } else {
628
            model.addAttribute("promoterInfo", promoterInfo);
629
            model.addAttribute("size", size);
630
        }
631
        return "promoter-info";
32887 shampa 632
 
33990 tejus.loha 633
    }
32887 shampa 634
 
33990 tejus.loha 635
    @RequestMapping(value = "/getPromoterInactive", method = RequestMethod.GET)
32887 shampa 636
 
33990 tejus.loha 637
    public String getShowPromoterInactiveInfo(HttpServletRequest request,
638
                                              @RequestParam(name = "offset", defaultValue = "0") int offset,
639
                                              @RequestParam(name = "limit", defaultValue = "10") int limit,
640
                                              @RequestParam(name = "fofoId", required = false, defaultValue = "0") int fofoId, Model model)
641
            throws Exception {
642
        //LOGGER.info("requested url : " + request.getRequestURL().toString());
643
        List<Promoter> promoterInfo = null;
644
        long size = 0;
32887 shampa 645
 
33990 tejus.loha 646
        List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
647
                .collect(Collectors.toList());
32887 shampa 648
 
33990 tejus.loha 649
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
27489 tejbeer 650
 
33990 tejus.loha 651
        Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> customRetailerMap.get(x))
652
                .filter(x -> x != null).collect(Collectors.toList()).stream()
653
                .collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
654
        String customRetailers = JSONObject.valueToString(customRetailersMap.values());
655
        Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
656
        brands.add("Airtel");
657
        brands.add("Vodafone");
658
        brands.add("Idea");
659
        LOGGER.info("brands" + brands);
660
        model.addAttribute("customRetailers", customRetailers);
661
        model.addAttribute("brands", brands);
30426 tejbeer 662
 
33990 tejus.loha 663
        if (fofoId != 0) {
664
            promoterInfo = promoterRepository.selectAllPromoterByFofoIdStatus(fofoId, offset, limit, false);
30426 tejbeer 665
 
33990 tejus.loha 666
            //size = promoterRepository.selectPromoterCount(fofoId);
667
            size = promoterInfo.size();
24159 tejbeer 668
 
33990 tejus.loha 669
        } else {
670
            //rkb
671
            promoterInfo = promoterRepository.selectAllPromoterStatus(offset, limit, false);
24159 tejbeer 672
 
33990 tejus.loha 673
            //size = promoterRepository.selectAllCount();
674
            size = promoterInfo.size();
27489 tejbeer 675
 
33990 tejus.loha 676
        }
677
        if (!promoterInfo.isEmpty()) {
678
            Set<Integer> partnerIds = new HashSet<>();
27489 tejbeer 679
 
33990 tejus.loha 680
            for (Promoter promoterdetail : promoterInfo) {
681
                partnerIds.add(promoterdetail.getRetailerId());
682
            }
683
            Map<Integer, CustomRetailer> partnersMap = null;
684
            if (!partnerIds.equals(null)) {
685
                LOGGER.info("partnerIds" + partnerIds);
27489 tejbeer 686
 
33990 tejus.loha 687
                partnersMap = partnerIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null)
688
                        .collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
24159 tejbeer 689
 
33990 tejus.loha 690
            }
30426 tejbeer 691
 
33990 tejus.loha 692
            LOGGER.info("partnerIds" + partnersMap);
693
            model.addAttribute("promoterInfo", promoterInfo);
694
            model.addAttribute("partnersMap", partnersMap);
695
            model.addAttribute("start", offset + 1);
696
            model.addAttribute("size", size);
697
            model.addAttribute("url", "/getPaginatedPromoterInactiveInfo");
30426 tejbeer 698
 
33990 tejus.loha 699
            if (promoterInfo.size() < limit) {
700
                model.addAttribute("end", offset + promoterInfo.size());
701
            } else {
702
                model.addAttribute("end", offset + limit);
703
            }
704
        } else {
705
            model.addAttribute("promoterInfo", promoterInfo);
706
            model.addAttribute("size", size);
707
        }
708
        return "promoter-inactive";
24349 amit.gupta 709
 
33990 tejus.loha 710
    }
24159 tejbeer 711
 
33990 tejus.loha 712
    @RequestMapping(value = "/getPaginatedPromoterInfo", method = RequestMethod.GET)
713
    public String getPaginatedPromoterInfo(HttpServletRequest request,
714
                                           @RequestParam(name = "offset", defaultValue = "0") int offset,
715
                                           @RequestParam(name = "limit", defaultValue = "10") int limit,
716
                                           @RequestParam(name = "fofoId", required = false, defaultValue = "0") int fofoId, Model model)
717
            throws ProfitMandiBusinessException {
718
        LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
719
        List<Promoter> promoterInfo = null;
720
        if (fofoId != 0) {
721
            promoterInfo = promoterRepository.selectAllPromoterByFofoIdStatus(fofoId, offset, limit, true);
722
        } else {
723
            promoterInfo = promoterRepository.selectAllPromoterStatus(offset, limit, true);
724
        }
725
        LOGGER.info("promoterInfo" + promoterInfo);
726
        if (!promoterInfo.isEmpty()) {
727
            Set<Integer> partnerIds = new HashSet<>();
24159 tejbeer 728
 
33990 tejus.loha 729
            for (Promoter promoterdetail : promoterInfo) {
730
                partnerIds.add(promoterdetail.getRetailerId());
731
            }
732
            Map<Integer, CustomRetailer> partnersMap = null;
733
            if (!partnerIds.equals(null)) {
734
                LOGGER.info("partnerIds" + partnerIds);
24349 amit.gupta 735
 
33990 tejus.loha 736
                Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
32887 shampa 737
 
33990 tejus.loha 738
                partnersMap = partnerIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null)
739
                        .collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
24159 tejbeer 740
 
33990 tejus.loha 741
            }
30426 tejbeer 742
 
33990 tejus.loha 743
            LOGGER.info("partnerIds" + partnersMap);
744
            model.addAttribute("promoterInfo", promoterInfo);
745
            model.addAttribute("partnersMap", partnersMap);
746
            model.addAttribute("url", "/getPaginatedPromoterInfo");
747
        } else {
748
            model.addAttribute("promoterInfo", promoterInfo);
30426 tejbeer 749
 
33990 tejus.loha 750
        }
30426 tejbeer 751
 
33990 tejus.loha 752
        return "promoter-info-paginated";
753
    }
24349 amit.gupta 754
 
33990 tejus.loha 755
    @RequestMapping(value = "/getPaginatedPromoterInactiveInfo", method = RequestMethod.GET)
756
    public String getPaginatedPromoterInactiveInfo(HttpServletRequest request,
757
                                                   @RequestParam(name = "offset", defaultValue = "0") int offset,
758
                                                   @RequestParam(name = "limit", defaultValue = "10") int limit,
759
                                                   @RequestParam(name = "fofoId", required = false, defaultValue = "0") int fofoId, Model model)
760
            throws ProfitMandiBusinessException {
761
        LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
762
        List<Promoter> promoterInfo = null;
763
        if (fofoId != 0) {
764
            promoterInfo = promoterRepository.selectAllPromoterByFofoIdStatus(fofoId, offset, limit, false);
765
        } else {
766
            promoterInfo = promoterRepository.selectAllPromoterStatus(offset, limit, false);
767
        }
768
        LOGGER.info("promoterInfo" + promoterInfo);
769
        if (!promoterInfo.isEmpty()) {
770
            Set<Integer> partnerIds = new HashSet<>();
24159 tejbeer 771
 
33990 tejus.loha 772
            for (Promoter promoterdetail : promoterInfo) {
773
                partnerIds.add(promoterdetail.getRetailerId());
774
            }
775
            Map<Integer, CustomRetailer> partnersMap = null;
776
            if (!partnerIds.equals(null)) {
777
                LOGGER.info("partnerIds" + partnerIds);
24159 tejbeer 778
 
33990 tejus.loha 779
                Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
24159 tejbeer 780
 
33990 tejus.loha 781
                partnersMap = partnerIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null)
782
                        .collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
32887 shampa 783
 
33990 tejus.loha 784
            }
32887 shampa 785
 
33990 tejus.loha 786
            LOGGER.info("partnerIds" + partnersMap);
787
            model.addAttribute("promoterInfo", promoterInfo);
788
            model.addAttribute("partnersMap", partnersMap);
789
            model.addAttribute("url", "/getPaginatedPromoterInactiveInfo");
790
        } else {
791
            model.addAttribute("promoterInfo", promoterInfo);
32887 shampa 792
 
33990 tejus.loha 793
        }
32887 shampa 794
 
33990 tejus.loha 795
        return "promoter-inactive-info-paginated";
796
    }
32887 shampa 797
 
33990 tejus.loha 798
    @RequestMapping(value = "/createPromoter", method = RequestMethod.POST)
799
    public String createPromoter(HttpServletRequest request, @RequestBody PromoterDetailModel promoterdetailModel,
800
                                 Model model) throws Exception {
801
        LOGGER.info("requested url : " + request.getRequestURL().toString());
802
        LOGGER.info("requested url : " + promoterdetailModel);
803
        Promoter promoter = promoterRepository.selectById(promoterdetailModel.getId());
804
        if (promoter == null) {
805
            promoter = new Promoter();
806
            promoter.setBrand(promoterdetailModel.getBrand());
807
            promoter.setRetailerId(promoterdetailModel.getRetailerId());
808
            promoter.setCreatedTimestamp(LocalDateTime.now());
809
            promoter.setEmail(promoterdetailModel.getEmail());
810
            promoter.setName(promoterdetailModel.getName());
811
            promoter.setMobile(promoterdetailModel.getMobile());
812
            promoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
813
            promoter.setStatus(promoterdetailModel.isStatus());
814
            promoterRepository.persist(promoter);
32887 shampa 815
 
33990 tejus.loha 816
            List<Promoter> promoters = promoterRepository.selectAllByRetailer(promoterdetailModel.getRetailerId());
817
            if (!promoters.isEmpty()) {
818
                FofoStore fs = fofoStoreRepository.selectByRetailerId(promoterdetailModel.getRetailerId());
819
                PartnerOnBoardingPanel pobp = partnerOnBoardingPanelRepository.selectByCode(fs.getCode());
820
                if (pobp != null) {
821
                    storeTimelineTatService.promoterComplete(pobp.getId());
822
                }
823
            }
32887 shampa 824
 
33990 tejus.loha 825
        } else {
826
            promoter.setEmail(promoterdetailModel.getEmail());
827
            promoter.setName(promoterdetailModel.getName());
828
            promoter.setMobile(promoterdetailModel.getMobile());
829
            promoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
830
            promoter.setStatus(promoterdetailModel.isStatus());
831
        }
832
        LOGGER.info("sdport" + promoterdetailModel.isStatus());
26131 tejbeer 833
 
33990 tejus.loha 834
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
28908 tejbeer 835
 
33990 tejus.loha 836
        return "response";
24159 tejbeer 837
 
33990 tejus.loha 838
    }
24159 tejbeer 839
 
33990 tejus.loha 840
    @RequestMapping(value = "/setPromoterInActive", method = RequestMethod.POST)
841
    public String PromoterInActive(HttpServletRequest request, @RequestParam(name = "id", required = true, defaultValue = "0") int id, Model model) throws Exception {
24159 tejbeer 842
 
33990 tejus.loha 843
        Promoter promoter = promoterRepository.selectById(id);
24159 tejbeer 844
 
33990 tejus.loha 845
        promoter.setStatus(false);
32887 shampa 846
 
33990 tejus.loha 847
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
32887 shampa 848
 
33990 tejus.loha 849
        return "response";
850
    }
32887 shampa 851
 
33990 tejus.loha 852
    @RequestMapping(value = "/removePromoterfromPartnerStore", method = RequestMethod.POST)
853
    public String removePromoterfromPartnerStore(HttpServletRequest request,
854
                                                 @RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
32887 shampa 855
 
33990 tejus.loha 856
        Promoter promoter = promoterRepository.selectById(id);
857
        promoter.setStatus(false);
858
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
32887 shampa 859
 
33990 tejus.loha 860
        return "response";
861
    }
24159 tejbeer 862
 
33990 tejus.loha 863
    @RequestMapping(value = "/activePromoterfromPartnerStore", method = RequestMethod.POST)
864
    public String activePromoterfromPartnerStore(HttpServletRequest request,
865
                                                 @RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
24159 tejbeer 866
 
33990 tejus.loha 867
        Promoter promoter = promoterRepository.selectById(id);
868
        promoter.setStatus(true);
869
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
32887 shampa 870
 
33990 tejus.loha 871
        return "response";
872
    }
24159 tejbeer 873
 
33990 tejus.loha 874
    @RequestMapping(value = "/addLocation", method = RequestMethod.POST)
875
    public String addLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel, Model model)
876
            throws Exception {
24159 tejbeer 877
 
33990 tejus.loha 878
        Location location = new Location();
879
        location.setName(addLocationModel.getName());
880
        location.setLine1(addLocationModel.getLine1());
881
        location.setLine2(addLocationModel.getLine2());
882
        location.setCity(addLocationModel.getCity());
883
        location.setState(addLocationModel.getState());
884
        location.setPin(addLocationModel.getPin());
24159 tejbeer 885
 
33990 tejus.loha 886
        LOGGER.info("PostLocation" + location);
887
        locationRepository.persist(location);
24159 tejbeer 888
 
33990 tejus.loha 889
        User user = userRepository.selectById(addLocationModel.getUserId());
890
        user.setLocation(location.getId());
891
        userRepository.persist(user);
24159 tejbeer 892
 
33990 tejus.loha 893
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
894
        return "response";
24159 tejbeer 895
 
33990 tejus.loha 896
    }
24159 tejbeer 897
 
33990 tejus.loha 898
    @RequestMapping(value = "/updateLocation", method = RequestMethod.POST)
899
    public String updateLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel,
900
                                 Model model) throws Exception {
24159 tejbeer 901
 
33990 tejus.loha 902
        Location userlocation = locationRepository.selectById(addLocationModel.getUserId());
24159 tejbeer 903
 
33990 tejus.loha 904
        userlocation.setName(addLocationModel.getName());
905
        userlocation.setCity(addLocationModel.getCity());
906
        userlocation.setLine1(addLocationModel.getLine1());
907
        userlocation.setLine2(addLocationModel.getLine2());
908
        userlocation.setPin(addLocationModel.getPin());
909
        userlocation.setState(addLocationModel.getState());
24159 tejbeer 910
 
33990 tejus.loha 911
        locationRepository.persist(userlocation);
24159 tejbeer 912
 
33990 tejus.loha 913
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
914
        return "response";
24159 tejbeer 915
 
33990 tejus.loha 916
    }
24159 tejbeer 917
 
33990 tejus.loha 918
    @RequestMapping(value = "/getPartnerReadonlyInfo")
919
    public String getPartnerReadonlyInfo(HttpServletRequest request, Model model) throws Exception {
24159 tejbeer 920
 
33990 tejus.loha 921
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
922
        AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
27231 tejbeer 923
 
33990 tejus.loha 924
        Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
27231 tejbeer 925
 
33990 tejus.loha 926
        Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
27231 tejbeer 927
 
33990 tejus.loha 928
        Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
929
            try {
930
                return retailerService.getFofoRetailer(x);
931
            } catch (ProfitMandiBusinessException e) {
932
                // TODO Auto-generated catch block
933
                return null;
934
            }
935
        }).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
27231 tejbeer 936
 
33990 tejus.loha 937
        model.addAttribute("customRetailersMap", customRetailersMap);
27231 tejbeer 938
 
33990 tejus.loha 939
        return "partner-readonly-info";
27243 tejbeer 940
 
33990 tejus.loha 941
    }
27231 tejbeer 942
 
33990 tejus.loha 943
    @RequestMapping(value = "/getBlockBrandMapping")
944
    public String getBlockBrandMapping(HttpServletRequest request, Model model) throws Exception {
27231 tejbeer 945
 
33990 tejus.loha 946
        int fofoId = Utils.SYSTEM_PARTNER_ID;
947
        Set<String> brands = null;
28071 tejbeer 948
 
33990 tejus.loha 949
        brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
950
                .collect(Collectors.toSet());
28071 tejbeer 951
 
33990 tejus.loha 952
        LOGGER.info("brands" + brands);
953
        model.addAttribute("brands", brands);
28071 tejbeer 954
 
33990 tejus.loha 955
        return "block-brand-mapping";
28071 tejbeer 956
 
33990 tejus.loha 957
    }
28071 tejbeer 958
 
33990 tejus.loha 959
    @RequestMapping(value = "/getBlockBrand")
960
    public String getBlockBrand(HttpServletRequest request,
961
                                @RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
962
            throws Exception {
28071 tejbeer 963
 
33990 tejus.loha 964
        List<RetailerBlockBrands> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByBrands(brand);
28071 tejbeer 965
 
33990 tejus.loha 966
        List<Integer> blockBrandPartners = retailerBlockBrands.stream().map(x -> x.getFofoId())
967
                .collect(Collectors.toList());
968
        Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
28071 tejbeer 969
 
33990 tejus.loha 970
        LOGGER.info("retailerBlockBrands" + retailerBlockBrands);
971
        model.addAttribute("blockBrandPartners", blockBrandPartners);
972
        model.addAttribute("retailerBlockBrands", retailerBlockBrands);
973
        model.addAttribute("customRetailers", customRetailers);
28272 tejbeer 974
 
33990 tejus.loha 975
        return "retailer-block-brand";
28071 tejbeer 976
 
33990 tejus.loha 977
    }
28071 tejbeer 978
 
33990 tejus.loha 979
    @RequestMapping(value = "/getRetailerBlockBrandMappping", method = RequestMethod.POST)
980
    public String getBlockBrandMappping(HttpServletRequest request,
981
                                        @RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
982
                                        @RequestParam(name = "fofoIds", required = true, defaultValue = "0") List<Integer> fofoIds, Model model)
983
            throws Exception {
984
        List<RetailerBlockBrands> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByBrands(brand);
985
        if (!retailerBlockBrands.isEmpty()) {
986
            retailerBlockBrandsRepository.deleteAllbyBrands(brand);
987
        }
28071 tejbeer 988
 
33990 tejus.loha 989
        for (int id : fofoIds) {
990
            RetailerBlockBrands retailerBlockBrand = new RetailerBlockBrands();
991
            retailerBlockBrand.setFofoId(id);
992
            retailerBlockBrand.setBlockBrands(brand);
993
            retailerBlockBrandsRepository.persist(retailerBlockBrand);
28071 tejbeer 994
 
33990 tejus.loha 995
        }
996
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
28071 tejbeer 997
 
33990 tejus.loha 998
        return "response";
999
    }
28071 tejbeer 1000
 
33990 tejus.loha 1001
    @RequestMapping(value = "/getBrandslimit", method = RequestMethod.GET)
1002
    public String getBrandslimit(HttpServletRequest request, Model model) throws Exception {
28071 tejbeer 1003
 
33990 tejus.loha 1004
        int fofoId = Utils.SYSTEM_PARTNER_ID;
32731 ranu 1005
 
33990 tejus.loha 1006
        List<String> brands = brandsService.getBrandsToDisplay(3).stream().map(x -> x.getName()).collect(Collectors.toList());
1007
        model.addAttribute("brands", brands);
28272 tejbeer 1008
 
33990 tejus.loha 1009
        return "brands-limit";
28272 tejbeer 1010
 
33990 tejus.loha 1011
    }
28272 tejbeer 1012
 
33990 tejus.loha 1013
    @RequestMapping(value = "/setUpdateLimit", method = RequestMethod.POST)
1014
    public String getUpdateLimit(HttpServletRequest request,
1015
                                 @RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
1016
                                 @RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
1017
                                 @RequestParam(name = "limit", required = true, defaultValue = "0") float limit,
1018
                                 @RequestParam(name = "minStockLimit", required = true, defaultValue = "0") float minStockLimit,
1019
                                 @RequestParam(name = "preLimit", required = true, defaultValue = "0") float preLimit,
1020
                                 @RequestParam(name = "preStockLimit", required = true, defaultValue = "0") float preStockLimit, Model model)
1021
            throws Exception {
28272 tejbeer 1022
 
33990 tejus.loha 1023
        CustomRetailer cr = retailerService.getFofoRetailer(fofoId);
28272 tejbeer 1024
 
33990 tejus.loha 1025
        Map.Entry<Integer, CustomRetailer> customRetailers = new AbstractMap.SimpleEntry(cr.getPartnerId(), cr);
28272 tejbeer 1026
 
33990 tejus.loha 1027
        // Map<Integer, CustomRetailer> customRetailers =
1028
        // retailerService.getFofoRetailers(true);
28277 tejbeer 1029
 
33990 tejus.loha 1030
        RetailerBrandsLimit retailerBrands = retailerBrandsLimitRepository.selectLimitByBrandAndFofoId(fofoId, brand);
28277 tejbeer 1031
 
33990 tejus.loha 1032
        if (retailerBrands == null) {
1033
            retailerBrands = new RetailerBrandsLimit();
1034
            retailerBrands.setMinStockLimit(minStockLimit);
1035
            retailerBrands.setBrandLimit(limit);
1036
            retailerBrands.setIsUpdate(1);
1037
            retailerBrands.setCreatedTimestamp(LocalDateTime.now());
1038
            retailerBrands.setPartnerId(fofoId);
1039
            retailerBrands.setBrandName(brand);
1040
            retailerBrands.setUpdatedTimestamp(LocalDateTime.now());
1041
            retailerBrandsLimitRepository.persist(retailerBrands);
1042
        } else {
1043
            retailerBrands.setMinStockLimit(minStockLimit);
1044
            retailerBrands.setBrandLimit(limit);
1045
            retailerBrands.setIsUpdate(1);
1046
            retailerBrands.setUpdatedTimestamp(LocalDateTime.now());
1047
            retailerBrandsLimitRepository.persist(retailerBrands);
30028 manish 1048
 
33990 tejus.loha 1049
        }
1050
        retailerBrands = retailerBrandsLimitRepository.selectLimitByBrandAndFofoId(fofoId, brand);
28277 tejbeer 1051
 
33990 tejus.loha 1052
        Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = new HashMap<>();
28272 tejbeer 1053
 
33990 tejus.loha 1054
        retailerBrandsLimitMap.put(retailerBrands.getPartnerId(), retailerBrands);
28272 tejbeer 1055
 
33990 tejus.loha 1056
        BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brand);
28272 tejbeer 1057
 
33990 tejus.loha 1058
        model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
1059
        model.addAttribute("brandLimit", brandLimit);
1060
        model.addAttribute("customRetailers", customRetailers);
28272 tejbeer 1061
 
33990 tejus.loha 1062
        model.addAttribute("brand", brand);
1063
        return "brands-limit-row-mapping";
28272 tejbeer 1064
 
33990 tejus.loha 1065
    }
28277 tejbeer 1066
 
33990 tejus.loha 1067
    @RequestMapping(value = "/getRetailerBrandslimitMapping", method = RequestMethod.GET)
1068
    public String getRetailerBrandslimit(HttpServletRequest request,
1069
                                         @RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
1070
            throws Exception {
28272 tejbeer 1071
 
33990 tejus.loha 1072
        Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
1073
        List<RetailerBrandsLimit> retailerBrandsLimit = retailerBrandsLimitRepository.setAllLimitByBrand(brand);
1074
        Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = retailerBrandsLimit.stream()
1075
                .collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
28272 tejbeer 1076
 
33990 tejus.loha 1077
        model.addAttribute("customRetailers", customRetailers);
1078
        model.addAttribute("brand", brand);
1079
        model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
28272 tejbeer 1080
 
33990 tejus.loha 1081
        BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brand);
28272 tejbeer 1082
 
33990 tejus.loha 1083
        model.addAttribute("brandLimit", brandLimit);
28272 tejbeer 1084
 
33990 tejus.loha 1085
        return "brands-limit-mapping";
28272 tejbeer 1086
 
33990 tejus.loha 1087
    }
28272 tejbeer 1088
 
33990 tejus.loha 1089
    @RequestMapping(value = "/setBrandWiseLimit", method = RequestMethod.POST)
1090
    public String brandwiseLimit(HttpServletRequest request,
1091
                                 @RequestParam(name = "brands", required = true, defaultValue = "") String brands,
1092
                                 @RequestParam(name = "limit", required = true, defaultValue = "") float limit, Model model)
1093
            throws Exception {
28272 tejbeer 1094
 
33990 tejus.loha 1095
        LOGGER.info("limit" + limit);
30426 tejbeer 1096
 
33990 tejus.loha 1097
        BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brands);
28272 tejbeer 1098
 
33990 tejus.loha 1099
        List<RetailerBrandsLimit> retailerBrandsLimit = retailerBrandsLimitRepository.setAllLimitByBrand(brands);
28272 tejbeer 1100
 
33990 tejus.loha 1101
        Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = retailerBrandsLimit.stream()
1102
                .collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
28272 tejbeer 1103
 
33990 tejus.loha 1104
        Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
28272 tejbeer 1105
 
33990 tejus.loha 1106
        if (brandLimit == null) {
28272 tejbeer 1107
 
33990 tejus.loha 1108
            brandLimit = new BrandLimit();
1109
            brandLimit.setBrandLimit(limit);
1110
            brandLimit.setBrandName(brands);
1111
            brandLimit.setCreatedTimestamp(LocalDateTime.now());
1112
            brandLimit.setUpdatedTimestamp(LocalDateTime.now());
1113
            brandLimitRepository.persist(brandLimit);
28272 tejbeer 1114
 
33990 tejus.loha 1115
        } else {
1116
            brandLimit.setBrandLimit(limit);
28272 tejbeer 1117
 
33990 tejus.loha 1118
            brandLimit.setUpdatedTimestamp(LocalDateTime.now());
1119
            brandLimitRepository.persist(brandLimit);
28272 tejbeer 1120
 
33990 tejus.loha 1121
        }
1122
        brandLimit = brandLimitRepository.setLimitByBrands(brands);
30028 manish 1123
 
33990 tejus.loha 1124
        LOGGER.info("brandLimit" + brandLimit);
1125
        model.addAttribute("brand", brands);
1126
        model.addAttribute("brandLimit", brandLimit);
1127
        model.addAttribute("customRetailers", customRetailers);
1128
        model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
1129
        return "brands-limit-mapping";
28272 tejbeer 1130
 
33990 tejus.loha 1131
    }
28272 tejbeer 1132
 
33990 tejus.loha 1133
    @RequestMapping(value = "/setBrandWiseStockLimit", method = RequestMethod.POST)
1134
    public String setBrandWiseStockLimit(HttpServletRequest request,
1135
                                         @RequestParam(name = "brands", required = true, defaultValue = "") String brands,
1136
                                         @RequestParam(name = "stockLimit", required = true, defaultValue = "") float stockLimit, Model model)
1137
            throws Exception {
28272 tejbeer 1138
 
33990 tejus.loha 1139
        LOGGER.info("limit" + stockLimit);
28272 tejbeer 1140
 
33990 tejus.loha 1141
        BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brands);
28825 tejbeer 1142
 
33990 tejus.loha 1143
        List<RetailerBrandsLimit> retailerBrandsLimit = retailerBrandsLimitRepository.setAllLimitByBrand(brands);
30028 manish 1144
 
33990 tejus.loha 1145
        Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = retailerBrandsLimit.stream()
1146
                .collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
30028 manish 1147
 
33990 tejus.loha 1148
        Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
30028 manish 1149
 
33990 tejus.loha 1150
        if (brandLimit == null) {
30028 manish 1151
 
33990 tejus.loha 1152
            brandLimit = new BrandLimit();
1153
            brandLimit.setBrandLimit(0);
1154
            brandLimit.setBrandName(brands);
1155
            brandLimit.setStockLimit(stockLimit);
1156
            brandLimit.setCreatedTimestamp(LocalDateTime.now());
1157
            brandLimit.setUpdatedTimestamp(LocalDateTime.now());
1158
            brandLimitRepository.persist(brandLimit);
30028 manish 1159
 
33990 tejus.loha 1160
        } else {
1161
            brandLimit.setStockLimit(stockLimit);
30028 manish 1162
 
33990 tejus.loha 1163
            brandLimit.setUpdatedTimestamp(LocalDateTime.now());
1164
            brandLimitRepository.persist(brandLimit);
30028 manish 1165
 
33990 tejus.loha 1166
        }
1167
        brandLimit = brandLimitRepository.setLimitByBrands(brands);
30028 manish 1168
 
33990 tejus.loha 1169
        model.addAttribute("brand", brands);
1170
        model.addAttribute("brandLimit", brandLimit);
1171
        model.addAttribute("customRetailers", customRetailers);
1172
        model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
1173
        return "brands-limit-mapping";
30028 manish 1174
 
33990 tejus.loha 1175
    }
30028 manish 1176
 
33990 tejus.loha 1177
    @RequestMapping(value = "/setPartnerPincode", method = RequestMethod.POST)
1178
    public String setPartnerPincode(HttpServletRequest request,
1179
                                    @RequestParam(name = "pincode", required = true, defaultValue = "") String pincode,
1180
                                    @RequestParam(name = "fofoId", required = true, defaultValue = "") int fofoId, Model model)
1181
            throws Exception {
30028 manish 1182
 
33990 tejus.loha 1183
        if (!pincode.equals("")) {
1184
            PincodePartner pinPartner = new PincodePartner();
1185
            pinPartner.setFofoId(fofoId);
1186
            pinPartner.setPincode(pincode);
1187
            pincodePartnerRepository.perist(pinPartner);
1188
        }
30028 manish 1189
 
33990 tejus.loha 1190
        List<PincodePartner> partnerPincodeList = pincodePartnerRepository.selectByPartnerId(fofoId);
30028 manish 1191
 
33990 tejus.loha 1192
        LOGGER.info("partnerPincodeList" + partnerPincodeList);
30028 manish 1193
 
33990 tejus.loha 1194
        model.addAttribute("partnerPincodeList", partnerPincodeList);
1195
        return "pincode-partner-index";
28272 tejbeer 1196
 
33990 tejus.loha 1197
    }
28381 tejbeer 1198
 
33990 tejus.loha 1199
    @RequestMapping(value = "/removePartnerPincode", method = RequestMethod.POST)
1200
    public String removePartnerPincode(HttpServletRequest request, @RequestParam int id,
1201
                                       @RequestParam(name = "fofoId", required = true, defaultValue = "") int fofoId, Model model)
1202
            throws Exception {
28825 tejbeer 1203
 
33990 tejus.loha 1204
        pincodePartnerRepository.delete(id);
28825 tejbeer 1205
 
33990 tejus.loha 1206
        List<PincodePartner> partnerPincodeList = pincodePartnerRepository.selectByPartnerId(fofoId);
28381 tejbeer 1207
 
33990 tejus.loha 1208
        LOGGER.info("partnerPincodeList" + partnerPincodeList);
28825 tejbeer 1209
 
33990 tejus.loha 1210
        model.addAttribute("partnerPincodeList", partnerPincodeList);
28381 tejbeer 1211
 
33990 tejus.loha 1212
        return "pincode-partner-index";
28381 tejbeer 1213
 
33990 tejus.loha 1214
    }
28825 tejbeer 1215
 
33990 tejus.loha 1216
    @RequestMapping(value = "/removeSearchPincode", method = RequestMethod.POST)
1217
    public String removeSearchPincode(HttpServletRequest request, @RequestParam int id,
1218
                                      @RequestParam(name = "pin", required = true, defaultValue = "") String pin,
1219
                                      @RequestParam(name = "fofoId", required = true, defaultValue = "") int fofoId, Model model)
1220
            throws Exception {
28825 tejbeer 1221
 
33990 tejus.loha 1222
        pincodePartnerRepository.delete(id);
28825 tejbeer 1223
 
33990 tejus.loha 1224
        List<PincodePartner> partnerPincodeList = pincodePartnerRepository.selectPartnersByPincode(pin);
28381 tejbeer 1225
 
33990 tejus.loha 1226
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
28825 tejbeer 1227
 
33990 tejus.loha 1228
        model.addAttribute("customRetailerMap", customRetailerMap);
28381 tejbeer 1229
 
33990 tejus.loha 1230
        model.addAttribute("partnerPincodeList", partnerPincodeList);
28381 tejbeer 1231
 
33990 tejus.loha 1232
        return "search-pincode-partner";
28381 tejbeer 1233
 
33990 tejus.loha 1234
    }
28825 tejbeer 1235
 
33990 tejus.loha 1236
    @RequestMapping(value = "/searchPincodePartner", method = RequestMethod.GET)
1237
    public String searchPincodePartner(HttpServletRequest request,
1238
                                       @RequestParam(name = "pincode", required = true, defaultValue = "") String pincode, Model model)
1239
            throws Exception {
28825 tejbeer 1240
 
33990 tejus.loha 1241
        List<PincodePartner> partnerPincodeList = pincodePartnerRepository.selectPartnersByPincode(pincode);
28825 tejbeer 1242
 
33990 tejus.loha 1243
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
28381 tejbeer 1244
 
33990 tejus.loha 1245
        model.addAttribute("customRetailerMap", customRetailerMap);
28825 tejbeer 1246
 
33990 tejus.loha 1247
        model.addAttribute("partnerPincodeList", partnerPincodeList);
28381 tejbeer 1248
 
33990 tejus.loha 1249
        return "search-pincode-partner";
28825 tejbeer 1250
 
33990 tejus.loha 1251
    }
28381 tejbeer 1252
 
33990 tejus.loha 1253
    @RequestMapping(value = "/showPartnerPincode", method = RequestMethod.GET)
1254
    public String showPartnerPincode(HttpServletRequest request,
1255
                                     @RequestParam(name = "partnerId", required = true, defaultValue = "") int partnerId, Model model)
1256
            throws Exception {
28825 tejbeer 1257
 
33990 tejus.loha 1258
        List<PincodePartner> partnerPincodeList = pincodePartnerRepository.selectByPartnerId(partnerId);
28825 tejbeer 1259
 
33990 tejus.loha 1260
        model.addAttribute("partnerPincodeList", partnerPincodeList);
28825 tejbeer 1261
 
33990 tejus.loha 1262
        return "pincode-partner-index";
28825 tejbeer 1263
 
33990 tejus.loha 1264
    }
28381 tejbeer 1265
 
33990 tejus.loha 1266
    @RequestMapping(value = "/getAllPartnerPincode", method = RequestMethod.GET)
1267
    public String getAllPartnerPincode(HttpServletRequest request, Model model) throws Exception {
1268
        return "add-partner-pincode";
1269
    }
28825 tejbeer 1270
 
33990 tejus.loha 1271
    @RequestMapping(value = "/alternateRetailerContacts", method = RequestMethod.GET)
1272
    public String alternateRetailerContacts(HttpServletRequest request, Model model) throws Exception {
1273
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1274
        boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
28825 tejbeer 1275
 
33990 tejus.loha 1276
        model.addAttribute("isAdmin", isAdmin);
1277
        return "retailer-contacts";
1278
    }
28825 tejbeer 1279
 
33990 tejus.loha 1280
    @RequestMapping(value = "/retailer-contact-list", method = RequestMethod.GET)
1281
    public String getRetailerContactList(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId)
1282
            throws Exception {
28825 tejbeer 1283
 
33990 tejus.loha 1284
        List<RetailerContact> retailerContacts = retailerContactRepository.selectAllByRetailerId(fofoId);
32629 amit.gupta 1285
 
33990 tejus.loha 1286
        model.addAttribute("retailerContacts", retailerContacts);
32667 raveendra. 1287
 
33990 tejus.loha 1288
        return "retailer-contact-list";
33814 ranu 1289
 
33990 tejus.loha 1290
    }
33814 ranu 1291
 
33990 tejus.loha 1292
    @RequestMapping(value = "/add-retailer-contact-list", method = RequestMethod.GET)
1293
    public String updateRetailerContactList(HttpServletRequest request, Model model,
1294
                                            @RequestParam(defaultValue = "0") int fofoId,
1295
                                            @RequestParam String contactName,
1296
                                            @RequestParam String contactNumber) throws Exception {
1297
        RetailerContact retailerContact = new RetailerContact();
1298
        retailerContact.setFofoId(fofoId);
1299
        retailerContact.setName(contactName);
1300
        retailerContact.setMobile(contactNumber);
1301
        retailerContact.setActive(true);
1302
        retailerContact.setCreatedAt(LocalDateTime.now());
1303
        retailerContactRepository.persist(retailerContact);
33814 ranu 1304
 
33990 tejus.loha 1305
        List<RetailerContact> retailerContacts = retailerContactRepository.selectAllByRetailerId(fofoId);
33814 ranu 1306
 
33990 tejus.loha 1307
        model.addAttribute("retailerContacts", retailerContacts);
33814 ranu 1308
 
33990 tejus.loha 1309
        return "retailer-contact-list";
33814 ranu 1310
 
33990 tejus.loha 1311
    }
33814 ranu 1312
 
33990 tejus.loha 1313
    @RequestMapping(value = "/update-contact-status", method = RequestMethod.GET)
1314
    public String updateRetailerContactStatus(HttpServletRequest request, Model model,
1315
                                              @RequestParam(defaultValue = "0") int fofoId,
1316
                                              @RequestParam(defaultValue = "0") int contactId,
1317
                                              @RequestParam boolean active) throws Exception {
33814 ranu 1318
 
33990 tejus.loha 1319
        RetailerContact retailerContact = retailerContactRepository.selectById(contactId);
1320
        retailerContact.setActive(active);
33814 ranu 1321
 
33990 tejus.loha 1322
        List<RetailerContact> retailerContacts = retailerContactRepository.selectAllByRetailerId(fofoId);
33814 ranu 1323
 
33990 tejus.loha 1324
        model.addAttribute("retailerContacts", retailerContacts);
33814 ranu 1325
 
33990 tejus.loha 1326
        return "retailer-contact-list";
33814 ranu 1327
 
33990 tejus.loha 1328
    }
33814 ranu 1329
 
1330
 
28272 tejbeer 1331
}