Subversion Repositories SmartDukaan

Rev

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