Subversion Repositories SmartDukaan

Rev

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