Subversion Repositories SmartDukaan

Rev

Rev 35360 | Rev 35391 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.dao.service;

import com.spice.profitmandi.common.model.ProfitMandiConstants;
import com.spice.profitmandi.common.util.Utils;
import com.spice.profitmandi.dao.entity.auth.AuthUser;
import com.spice.profitmandi.dao.entity.fofo.TrialForm;
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
import com.spice.profitmandi.dao.repository.cs.CsService;
import com.spice.profitmandi.dao.service.loiForm.LoiFormServiceImpl;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class TrialServiceImpl implements TrialService {

    private static final Logger LOGGER = LogManager.getLogger(LoiFormServiceImpl.class);

    @Autowired
    JavaMailSender mailSender;

    @Autowired
    AuthRepository authRepository;

    @Autowired
    CsService csService;

    @Override
    public void sentMailForTrialUser(TrialForm trialForm) throws Exception {
        String body =
                "Dear Team,<br><br>" +
                        "A new partner has registered via the SmartDukaan Partners App. Please review the details below and initiate the verification process immediately.<br><br>" +
                        "<strong>Applicant Name:</strong> " + trialForm.getFirstName() + " " + trialForm.getLastName() + "<br>" +
                        "<strong>Business Name:</strong> " + trialForm.getBusinessName() + "<br>" +
                        "<strong>Mobile:</strong> " + trialForm.getMobile() + "<br>" +
                        "<strong>Email:</strong> " + trialForm.getEmail() + "<br>" +
                        "<strong>GST Number:</strong> " + trialForm.getGstNumber() + "<br><br>" +
                        "<strong>Address:</strong><br>" +
                        trialForm.getAddressLine1() + "<br>" +
                        (trialForm.getAddressLine2() != null ? trialForm.getAddressLine2() + "<br>" : "") +
                        trialForm.getCity() + ", " + trialForm.getState() + " - " + trialForm.getPincode() + "<br><br>" +
                        "<strong>Required Actions:</strong><br>" +
                        "• Verify Details: Validate KYC documents and basic business information.<br>" +
                        "• Assess Potential: Check the location feasibility and estimated sales potential.<br>" +
                        "• Assign Territory: Assign the appropriate Area Sales Manager (ASM) and Business Manager (BM) in the system.<br><br>" +
                        "Regards,<br>SmartDukaan Team";

        String[] emailTo = {"kamini.sharma@smartdukaan.com"};
//        String[] emailTo = {"aman.gupta@smartdukaan.com"};
        String[] cc = {"vaibhav.tandon@smartdukaan.com"};
        LOGGER.info("RegistrationBody - " + body);
        Utils.sendMailWithAttachments(mailSender, emailTo, cc, "New Trial Registration: " + trialForm.getBusinessName(), body);


    }

    public void sentMailForTrialUserToSales(TrialForm trialForm) throws Exception {
        String body =
                "<strong>Sales Team Action:</strong><br>" +
                        "A new verified partner lead has been assigned to your territory. They have successfully passed the initial verification stage.<br><br>" +
                        "<strong>Lead Information:</strong><br>" +
                        "<strong>Applicant Name:</strong> " + trialForm.getFirstName() + " " + trialForm.getLastName() + "<br>" +
                        "<strong>Business Name:</strong> " + trialForm.getBusinessName() + "<br>" +
                        "<strong>Mobile:</strong> " + trialForm.getMobile() + "<br>" +
                        "<strong>Email:</strong> " + trialForm.getEmail() + "<br>" +
                        "<strong>GST Number:</strong> " + trialForm.getGstNumber() + "<br><br>" +
                        "<strong>Address:</strong><br>" +
                        trialForm.getAddressLine1() + "<br>" +
                        (trialForm.getAddressLine2() != null ? trialForm.getAddressLine2() + "<br>" : "") +
                        trialForm.getCity() + ", " + trialForm.getState() + " - " + trialForm.getPincode() + "<br><br>" +
                        "<strong>Strategic Objective:</strong> The partner has expressed initial interest. Your goal is to move them beyond trial onboarding.<br><br>" +
                        "<strong>Next Steps:</strong><br>" +
                        "• Contact Immediately: Call or visit the store within the next 24 hours.<br>" +
                        "• The Pitch: Explain the SmartDukaan ecosystem and pitch the Full Franchise Partner Model. Emphasize the long-term higher margins, income boost, brand access, tech support, and branding benefits over the trial version.<br>" +
                        "• Update Status: Log your interaction and the partner's interest level in the app immediately after the meeting.<br><br>" +
                        "Good Luck,<br>" +
                        "Regards,<br>SmartDukaan Team";

        List<AuthUser> salesAuthUserList = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, Arrays.asList(EscalationType.L3, EscalationType.L4, EscalationType.L5));
        List<String> salesEmailList = new ArrayList<>();
        for (AuthUser authUser : salesAuthUserList) {
            if (authUser.getEmailId() != null && !authUser.getEmailId().trim().isEmpty()) {
                salesEmailList.add(authUser.getEmailId());
            }
        }
        AuthUser bmAuthUser = authRepository.selectById(trialForm.getBmId());
        AuthUser asmAuthUser = authRepository.selectById(trialForm.getAsmId());

        String[] emailTo = new String[]{bmAuthUser.getEmailId()};
        List<String> ccList = new ArrayList<>(salesEmailList);
        ccList.add(asmAuthUser.getEmailId());
        String[] cc = ccList.stream()
                .filter(email -> !email.trim().isEmpty())
                .toArray(String[]::new);
        LOGGER.info("RegistrationBody - " + body);
        LOGGER.info("cc list - " + Arrays.toString(cc));
        Utils.sendMailWithAttachments(mailSender, emailTo, cc, "NEW LEAD ASSIGNED: " + trialForm.getBusinessName() + "- Call/Visit ASAP", body);


    }

    public void sentMailForStoreCodeCreation(TrialForm trialForm) throws Exception {
        String body =
                "The trial user has been verified.<br><br>" +
                        "Please create Store Code for: <strong>" + trialForm.getBusinessName() + "</strong><br>" +
                        "Mobile Number: <strong>" + trialForm.getMobile() + "</strong><br><br>" +
                        "Regards,<br>SmartDukaan Team";

        String[] emailTo = {"gaurav.sharma@smartdukaan.com"};
        LOGGER.info("RegistrationBody - " + body);
        String[] cc = {"devkinandan.lal@smartdukaan.com"};
        LOGGER.info("cc list - " + Arrays.toString(cc));
        Utils.sendMailWithAttachments(mailSender, emailTo, cc, "Store Code Creation Required for trial user" + trialForm.getBusinessName(), body);


    }
}