Subversion Repositories SmartDukaan

Rev

Rev 37648 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37648 Rev 37669
Line 299... Line 299...
299
    @SuppressWarnings("unchecked")
299
    @SuppressWarnings("unchecked")
300
    @Override
300
    @Override
301
    @Transactional(rollbackFor = Throwable.class)
301
    @Transactional(rollbackFor = Throwable.class)
302
    public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest) throws
302
    public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest) throws
303
            ProfitMandiBusinessException {
303
            ProfitMandiBusinessException {
-
 
304
        this.validateGstNumbers(updateRetailerRequest);
-
 
305
 
304
        Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
306
        Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
305
        User dtrUser = (User) map.get("user");
307
        User dtrUser = (User) map.get("user");
306
 
308
 
307
        if (updateRetailerRequest.isFofo()) {
309
        if (updateRetailerRequest.isFofo()) {
308
            Retailer resolvedRetailer = (Retailer) map.get("retailer");
310
            Retailer resolvedRetailer = (Retailer) map.get("retailer");
Line 420... Line 422...
420
        } catch (ProfitMandiBusinessException e) {
422
        } catch (ProfitMandiBusinessException e) {
421
            return null;
423
            return null;
422
        }
424
        }
423
    }
425
    }
424
 
426
 
-
 
427
    /**
-
 
428
     * The onboarding screen carries the partner's GSTIN in two boxes that both read "GST NUMBER":
-
 
429
     * the retailer one (dtr.retailer.number) and the store one (fofo_store.gst_number, which is
-
 
430
     * what billing reads and what goes to NIC as the recipient). Neither was validated, so
-
 
431
     * DLSH1660 was saved with the LOI's pincode (110095) in the store box while the retailer box
-
 
432
     * held the real 07CMEPR1110C1ZO - an invoice NIC would refuse.
-
 
433
     * <p>
-
 
434
     * Both are normalised and checked here, before any write, and must agree when both are
-
 
435
     * present: across 1,800 partners on record they already do, bar the one that caused this.
-
 
436
     */
-
 
437
    private void validateGstNumbers(UpdateRetailerRequest updateRetailerRequest)
-
 
438
            throws ProfitMandiBusinessException {
-
 
439
        String storeGstin = StringUtils.normalizeGstNumber(updateRetailerRequest.getGstNumber());
-
 
440
        String retailerGstin = StringUtils.normalizeGstNumber(updateRetailerRequest.getNumber());
-
 
441
 
-
 
442
        if (!StringUtils.isValidGstNumber(storeGstin)) {
-
 
443
            throw new ProfitMandiBusinessException("gstNumber", storeGstin, "RTLR_1020");
-
 
444
        }
-
 
445
        if (!StringUtils.isValidGstNumber(retailerGstin)) {
-
 
446
            throw new ProfitMandiBusinessException("number", retailerGstin, "RTLR_1020");
-
 
447
        }
-
 
448
        if (isNotBlank(storeGstin) && isNotBlank(retailerGstin) && !storeGstin.equals(retailerGstin)) {
-
 
449
            throw new ProfitMandiBusinessException("gstNumber", storeGstin + " / " + retailerGstin, "RTLR_1021");
-
 
450
        }
-
 
451
 
-
 
452
        // Persist what was validated, so the same registration is never stored two ways.
-
 
453
        updateRetailerRequest.setGstNumber(storeGstin);
-
 
454
        updateRetailerRequest.setNumber(retailerGstin);
-
 
455
    }
-
 
456
 
-
 
457
    private static boolean isNotBlank(String value) {
-
 
458
        return value != null && !value.isEmpty();
-
 
459
    }
-
 
460
 
425
    private void guardAgainstDuplicatePartnerChain(UpdateRetailerRequest updateRetailerRequest)
461
    private void guardAgainstDuplicatePartnerChain(UpdateRetailerRequest updateRetailerRequest)
426
            throws ProfitMandiBusinessException {
462
            throws ProfitMandiBusinessException {
427
        User byMobile = null;
463
        User byMobile = null;
428
        try {
464
        try {
429
            byMobile = userRepository.selectByMobileNumber(updateRetailerRequest.getUserMobileNumber());
465
            byMobile = userRepository.selectByMobileNumber(updateRetailerRequest.getUserMobileNumber());