Subversion Repositories SmartDukaan

Rev

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

Rev 37846 Rev 37977
Line 53... Line 53...
53
import com.spice.profitmandi.service.transaction.SDCreditService;
53
import com.spice.profitmandi.service.transaction.SDCreditService;
54
import com.spice.profitmandi.service.user.RetailerService;
54
import com.spice.profitmandi.service.user.RetailerService;
55
import com.spice.profitmandi.service.wallet.WalletService;
55
import com.spice.profitmandi.service.wallet.WalletService;
56
import com.spice.profitmandi.web.model.LoginDetails;
56
import com.spice.profitmandi.web.model.LoginDetails;
57
import com.spice.profitmandi.web.util.CookiesProcessor;
57
import com.spice.profitmandi.web.util.CookiesProcessor;
-
 
58
import com.spice.profitmandi.web.util.DishaRbmToken;
58
import com.spice.profitmandi.web.util.MVCResponseSender;
59
import com.spice.profitmandi.web.util.MVCResponseSender;
59
import in.shop2020.model.v1.order.OrderStatus;
60
import in.shop2020.model.v1.order.OrderStatus;
60
import org.apache.commons.io.output.ByteArrayOutputStream;
61
import org.apache.commons.io.output.ByteArrayOutputStream;
61
import org.apache.logging.log4j.LogManager;
62
import org.apache.logging.log4j.LogManager;
62
import org.apache.logging.log4j.Logger;
63
import org.apache.logging.log4j.Logger;
63
import org.json.JSONArray;
64
import org.json.JSONArray;
64
import org.json.JSONObject;
65
import org.json.JSONObject;
65
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.beans.factory.annotation.Autowired;
-
 
67
import org.springframework.beans.factory.annotation.Value;
66
import org.springframework.core.io.ByteArrayResource;
68
import org.springframework.core.io.ByteArrayResource;
67
import org.springframework.http.HttpHeaders;
69
import org.springframework.http.HttpHeaders;
68
import org.springframework.http.HttpStatus;
70
import org.springframework.http.HttpStatus;
69
import org.springframework.http.ResponseEntity;
71
import org.springframework.http.ResponseEntity;
70
import org.springframework.mail.javamail.JavaMailSender;
72
import org.springframework.mail.javamail.JavaMailSender;
Line 94... Line 96...
94
    @Autowired
96
    @Autowired
95
    private BillingWarehouseService billingWarehouseService;
97
    private BillingWarehouseService billingWarehouseService;
96
 
98
 
97
 
99
 
98
    private static final Logger LOGGER = LogManager.getLogger(IndentController.class);
100
    private static final Logger LOGGER = LogManager.getLogger(IndentController.class);
-
 
101
 
-
 
102
    // Key shared with chat.smartdukaan.com, only used to sign Disha passes (never sent to the page).
-
 
103
    // Set on the server only (-Ddisha.rbm.key=... in Tomcat's setenv.sh); empty = no Disha.
-
 
104
    @Value("${disha.rbm.key:}")
-
 
105
    private String dishaRbmKey;
-
 
106
    // Where Disha is served from; -Ddisha.server=http://localhost:8779 for a local test
-
 
107
    @Value("${disha.server:https://chat.smartdukaan.com}")
-
 
108
    private String dishaServer;
-
 
109
    private static final long DISHA_TOKEN_TTL_S = 4 * 60 * 60;
99
    private static final Set<Integer> defaultTags = new HashSet<Integer>(Arrays.asList(4));
110
    private static final Set<Integer> defaultTags = new HashSet<Integer>(Arrays.asList(4));
100
 
111
 
101
    private final List<OrderStatus> partnerPendingOrderList = Arrays.asList(OrderStatus.ACCEPTED,
112
    private final List<OrderStatus> partnerPendingOrderList = Arrays.asList(OrderStatus.ACCEPTED,
102
            OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH,
113
            OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH,
103
            OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.SHIPPED_TO_LOGST,
114
            OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.SHIPPED_TO_LOGST,
Line 1604... Line 1615...
1604
        List<String> brands = ProfitMandiConstants.BRANDS;
1615
        List<String> brands = ProfitMandiConstants.BRANDS;
1605
 
1616
 
1606
        AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1617
        AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1607
        Set<Integer> fofoIds = csService1.getAuthFofoIds(email, true);
1618
        Set<Integer> fofoIds = csService1.getAuthFofoIds(email, true);
1608
 
1619
 
-
 
1620
        // Disha widget for RBMs only; a failed lookup hides Disha instead of breaking the page
-
 
1621
        boolean isRBM = false;
-
 
1622
        try {
-
 
1623
            isRBM = authUser != null && positionRepository.selectPositionByAuthId(authUser.getId()).stream()
-
 
1624
                    .anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
-
 
1625
        } catch (Exception e) {
-
 
1626
            LOGGER.warn("Disha: could not check RBM position for {}", email, e);
-
 
1627
        }
-
 
1628
        String dishaKey = dishaRbmKey == null ? "" : dishaRbmKey.trim();
-
 
1629
        // Ira's way for now (Tanay, 2026-10-30): Disha is on this page for any logged-in staff member,
-
 
1630
        // named by the login email; Disha's own server lets in only a @smartdukaan.com login with
-
 
1631
        // partners assigned to it (the position check above was false for an RBM login, so it is
-
 
1632
        // logged, not used). With the key set (-Ddisha.rbm.key) the page also carries signed
-
 
1633
        // per-store passes, which Disha prefers.
-
 
1634
        if (!isRBM) LOGGER.info("Disha: {} has no RBM position; Disha's server decides by partners", email);
-
 
1635
        boolean dishaOn = authUser != null;
-
 
1636
        model.addAttribute("authEmail", email);
-
 
1637
        model.addAttribute("dishaOn", dishaOn);
-
 
1638
        model.addAttribute("dishaServer", dishaServer.trim().replaceAll("/+$", ""));
-
 
1639
 
1609
        Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
1640
        Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
1610
 
1641
 
1611
        Map<Integer, Map<String, Double>> fofoIdBrandAmountMap = new HashMap<>();
1642
        Map<Integer, Map<String, Double>> fofoIdBrandAmountMap = new HashMap<>();
1612
        Map<Integer, Map<String, Double>> fofoIdBrandQtyMap = new HashMap<>();
1643
        Map<Integer, Map<String, Double>> fofoIdBrandQtyMap = new HashMap<>();
1613
 
1644
 
Line 1820... Line 1851...
1820
        }
1851
        }
1821
 
1852
 
1822
 
1853
 
1823
        //Only L3 and above can change the activationType
1854
        //Only L3 and above can change the activationType
1824
 
1855
 
-
 
1856
        // Disha passes: one per store on the page plus a list-only one, all expiring together
-
 
1857
        String dishaListToken = "";
-
 
1858
        Map<String, String> dishaTokens = new HashMap<>();
-
 
1859
        if (dishaOn && !dishaKey.isEmpty()) {
-
 
1860
            long dishaExpiresAt = System.currentTimeMillis() / 1000L + DISHA_TOKEN_TTL_S;
-
 
1861
            dishaListToken = DishaRbmToken.mint(dishaKey, "", email, dishaExpiresAt);
-
 
1862
            for (CustomRetailer cr : customRetailers.values()) {
-
 
1863
                if (cr == null || cr.getCode() == null || cr.getCode().trim().isEmpty()) {
-
 
1864
                    continue;
-
 
1865
                }
-
 
1866
                dishaTokens.put(cr.getCode(), DishaRbmToken.mint(dishaKey, cr.getCode(), email, dishaExpiresAt));
-
 
1867
            }
-
 
1868
        }
-
 
1869
        model.addAttribute("dishaListToken", dishaListToken);
-
 
1870
        model.addAttribute("dishaTokensJson", new JSONObject(dishaTokens).toString());
-
 
1871
 
1825
        model.addAttribute("customRetailers", customRetailers);
1872
        model.addAttribute("customRetailers", customRetailers);
1826
        model.addAttribute("totalDueMap", totalDueMap);
1873
        model.addAttribute("totalDueMap", totalDueMap);
1827
        model.addAttribute("fofoMTDSaleMap", fofoMTDSaleMap);
1874
        model.addAttribute("fofoMTDSaleMap", fofoMTDSaleMap);
1828
        model.addAttribute("fofoIdMonthlyTargetMap", fofoIdMonthlyTargetMap);
1875
        model.addAttribute("fofoIdMonthlyTargetMap", fofoIdMonthlyTargetMap);
1829
        model.addAttribute("currentMonthTillDateRetailerPOValueMap", currentMonthTillDateRetailerPOValueMap);
1876
        model.addAttribute("currentMonthTillDateRetailerPOValueMap", currentMonthTillDateRetailerPOValueMap);