Subversion Repositories SmartDukaan

Rev

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

Rev 37636 Rev 37658
Line 12... Line 12...
12
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
12
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
13
import com.spice.profitmandi.common.model.CustomRetailer;
13
import com.spice.profitmandi.common.model.CustomRetailer;
14
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
14
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
15
import com.spice.profitmandi.common.model.InvoicePdfModel;
15
import com.spice.profitmandi.common.model.InvoicePdfModel;
16
import com.spice.profitmandi.common.model.ProfitMandiConstants;
16
import com.spice.profitmandi.common.model.ProfitMandiConstants;
17
import com.spice.profitmandi.common.services.mandii.*;
-
 
18
import com.spice.profitmandi.common.util.FileUtil;
17
import com.spice.profitmandi.common.util.FileUtil;
19
import com.spice.profitmandi.common.util.FormattingUtils;
18
import com.spice.profitmandi.common.util.FormattingUtils;
20
import com.spice.profitmandi.common.util.Utils;
19
import com.spice.profitmandi.common.util.Utils;
21
import com.spice.profitmandi.dao.cart.CartService;
20
import com.spice.profitmandi.dao.cart.CartService;
22
import com.spice.profitmandi.dao.entity.catalog.Item;
21
import com.spice.profitmandi.dao.entity.catalog.Item;
Line 1861... Line 1860...
1861
    public void createOffers(FileInputStream stream) throws Exception {
1860
    public void createOffers(FileInputStream stream) throws Exception {
1862
        offerService.createOffers(stream);
1861
        offerService.createOffers(stream);
1863
    }
1862
    }
1864
 
1863
 
1865
    @Autowired
1864
    @Autowired
1866
    MandiiService mandiiService;
-
 
1867
 
-
 
1868
    @Autowired
-
 
1869
    FofoKycRepository fofoKycRepository;
1865
    FofoKycRepository fofoKycRepository;
1870
 
1866
 
1871
    @Autowired
1867
    @Autowired
1872
    PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
1868
    PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
1873
 
1869
 
Line 1875... Line 1871...
1875
    DocumentRepository documentRepository;
1871
    DocumentRepository documentRepository;
1876
 
1872
 
1877
    @Autowired
1873
    @Autowired
1878
    com.spice.profitmandi.dao.repository.dtr.UserRepository dtrUserRepository;
1874
    com.spice.profitmandi.dao.repository.dtr.UserRepository dtrUserRepository;
1879
 
1875
 
1880
    public void mandiiUser(String firstName, String lastName, String pan, String dob, String aadhaar, String gender,
-
 
1881
                           String father) throws Exception {
-
 
1882
        FofoStore fs = fofoStoreRepository.selectByPan(pan);
-
 
1883
        CustomRetailer cr = retailerService.getFofoRetailer(fs.getId());
-
 
1884
        com.spice.profitmandi.dao.entity.dtr.User dtrUser = dtrUserRepository.selectByEmailId(cr.getEmail());
-
 
1885
        MandiiUser mandiiUser = mandiiService.getUser(dtrUser.getFirstName(), dtrUser.getLastName(), father,
-
 
1886
                Gender.valueOf(gender), cr.getEmail(), pan, cr.getMobileNumber(), LocalDate.parse(dob),
-
 
1887
                cr.getAddress().getLine1() + " " + cr.getAddress().getLine2(), cr.getAddress().getCity(),
-
 
1888
                cr.getAddress().getState(), cr.getAddress().getPinCode());
-
 
1889
        mandiiUser.setFatherName(father);
-
 
1890
        if (StringUtils.isNotEmpty(firstName)) {
-
 
1891
            mandiiUser.setFirstName(firstName);
-
 
1892
            mandiiUser.setLastName(lastName);
-
 
1893
        }
-
 
1894
        if (StringUtils.isNotEmpty(father)) {
-
 
1895
            mandiiUser.setFatherName(father);
-
 
1896
        }
-
 
1897
        if (StringUtils.isNotEmpty(aadhaar)) {
-
 
1898
            mandiiUser.setAadharNumber(aadhaar);
-
 
1899
        }
-
 
1900
        mandiiUser.setGender(Gender.valueOf(gender));
-
 
1901
        mandiiService.createAccount(cr.getBusinessName(), mandiiUser);
-
 
1902
    }
-
 
1903
 
-
 
1904
    @Autowired
-
 
1905
    CreditAccountRepository creditAccountRepository;
-
 
1906
 
-
 
1907
    public void mandiiUsers() throws Exception {
-
 
1908
        List<CreditAccount> creditAccounts = creditAccountRepository.selectAll();
-
 
1909
        List<Integer> fofoIds = creditAccounts.stream().filter(x -> x.getGateway().equals(Gateway.MANDII) && (x.getCreditStatus().equals(CreditStatus.UNKNOWN) || x.getCreditStatus().equals(CreditStatus.TO_BE_EVALUATED))).map(x -> x.getFofoId()).collect(Collectors.toList());
-
 
1910
        List<FofoStore> fsList = fofoStoreRepository.selectByRetailerIds(fofoIds);
-
 
1911
        for (FofoStore store : fsList) {
-
 
1912
            this.mandiiUsers(store.getPan());
-
 
1913
        }
-
 
1914
 
-
 
1915
    }
-
 
1916
 
-
 
1917
    public void mandiiUsers(String pan) throws Exception {
-
 
1918
        FofoStore fs = fofoStoreRepository.selectByPan(pan);
-
 
1919
 
-
 
1920
        PartnerOnBoardingPanel pob = partnerOnBoardingPanelRepository.selectByCode(fs.getCode());
-
 
1921
        List<FofoKyc> fofoKycs = fofoKycRepository.selectByPartnerOnBoardingId(pob.getId());
-
 
1922
        CustomRetailer cr = retailerService.getFofoRetailer(fs.getId());
-
 
1923
        com.spice.profitmandi.dao.entity.dtr.User dtrUser = dtrUserRepository.selectByEmailId(cr.getEmail());
-
 
1924
        boolean ca = false;
-
 
1925
        for (FofoKyc fk : fofoKycs) {
-
 
1926
 
-
 
1927
            MandiiUser mandiiUser = mandiiService.getUser(fk.getFirstName(), fk.getLastName(), fk.getFatherName(),
-
 
1928
                    fk.getGender(), fk.getEmail(), pan, fk.getMobile(), fk.getDob(),
-
 
1929
                    fk.getAddress1() + " " + fk.getAddress2() + " " + fk.getAddress3(), fk.getCity(), fk.getState(),
-
 
1930
                    fk.getPincode());
-
 
1931
 
-
 
1932
            LOGGER.info("mandiiUser" + mandiiUser);
-
 
1933
 
-
 
1934
            ca = mandiiService.createAccount(cr.getBusinessName(), mandiiUser);
-
 
1935
 
-
 
1936
            Document panDoc = documentRepository.selectById(fk.getPanDoc());
-
 
1937
            File fPan = new File(panDoc.getPath() + panDoc.getName());
-
 
1938
            String encodeString = encodeFileToBase64Binary(fPan);
-
 
1939
 
-
 
1940
            mandiiService.documentUpload(pan, fk.getMobile(), "PROPRIETOR_PAN", encodeString, null);
-
 
1941
 
-
 
1942
            Document adhaarF = documentRepository.selectById(fk.getPoaFront());
-
 
1943
            File adharf = new File(adhaarF.getPath() + adhaarF.getName());
-
 
1944
            String adhaarFEncodstring = encodeFileToBase64Binary(adharf);
-
 
1945
            mandiiService.documentUpload(pan, fk.getMobile(), "AADHAAR", adhaarFEncodstring, "FRONT");
-
 
1946
 
-
 
1947
            Document adhaarB = documentRepository.selectById(fk.getPoaBack());
-
 
1948
            File adharb = new File(adhaarB.getPath() + adhaarF.getName());
-
 
1949
            String adhaarBEncodstring = encodeFileToBase64Binary(adharb);
-
 
1950
            mandiiService.documentUpload(pan, fk.getMobile(), "AADHAAR", adhaarBEncodstring, "BACK");
-
 
1951
 
-
 
1952
            if (ca == true) {
-
 
1953
                AccountStatusResponseOut accountStatusResponseOut = mandiiService.getStatus(fs.getPan());
-
 
1954
                this.setCreditAccount(fs.getId(), accountStatusResponseOut);
-
 
1955
            }
-
 
1956
 
-
 
1957
        }
-
 
1958
 
-
 
1959
    }
-
 
1960
 
-
 
1961
    private void setCreditAccount(int fofoId, AccountStatusResponseOut accountStatusResponseOut) {
-
 
1962
 
-
 
1963
        CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(fofoId, Gateway.MANDII);
-
 
1964
 
-
 
1965
        if (creditAccount == null) {
-
 
1966
            creditAccount = new CreditAccount();
-
 
1967
            creditAccount.setFofoId(fofoId);
-
 
1968
            creditAccount.setGateway(Gateway.MANDII);
-
 
1969
        }
-
 
1970
 
-
 
1971
        if (accountStatusResponseOut == null) {
-
 
1972
            creditAccount.setCreditStatus(CreditStatus.UNKNOWN);
-
 
1973
            creditAccount.setDescription("User company not found");
-
 
1974
 
-
 
1975
        } else {
-
 
1976
            if (accountStatusResponseOut.getSanctionLimit() != null) {
-
 
1977
                creditAccount.setSanctionedAmount(accountStatusResponseOut.getSanctionLimit().floatValue());
-
 
1978
            } else {
-
 
1979
                creditAccount.setSanctionedAmount(0);
-
 
1980
            }
-
 
1981
 
-
 
1982
            creditAccount.setInterestRate(accountStatusResponseOut.getRateOfInterest());
-
 
1983
            if (accountStatusResponseOut.getBalanceAmount() != null) {
-
 
1984
                creditAccount.setAvailableAmount(accountStatusResponseOut.getBalanceAmount().floatValue());
-
 
1985
            } else {
-
 
1986
                creditAccount.setAvailableAmount(0);
-
 
1987
            }
-
 
1988
 
-
 
1989
            if (accountStatusResponseOut.getCurrentStage() != null) {
-
 
1990
                creditAccount.setDescription(accountStatusResponseOut.getCurrentStage().toString());
-
 
1991
            }
-
 
1992
            if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.SANCTION_AVAILABLE)) {
-
 
1993
                creditAccount.setCreditStatus(CreditStatus.SANCTIONED);
-
 
1994
            } else if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.IN_ELIGIBLE)) {
-
 
1995
                creditAccount.setCreditStatus(CreditStatus.INELIGIBLE);
-
 
1996
            } else {
-
 
1997
 
-
 
1998
                creditAccount.setCreditStatus(CreditStatus.TO_BE_EVALUATED);
-
 
1999
            }
-
 
2000
        }
-
 
2001
 
-
 
2002
        creditAccount.setUpdatedOn(LocalDateTime.now());
-
 
2003
        creditAccountRepository.persist(creditAccount);
-
 
2004
    }
-
 
2005
 
-
 
2006
    private static String encodeFileToBase64Binary(File file) throws Exception {
-
 
2007
        FileInputStream fileInputStreamReader = new FileInputStream(file);
-
 
2008
        byte[] bytes = new byte[(int) file.length()];
-
 
2009
        fileInputStreamReader.read(bytes);
-
 
2010
        return new String(Base64.getEncoder().encodeToString(bytes));
-
 
2011
    }
-
 
2012
 
-
 
2013
    public void testIrnLive(String invoiceNumber) throws Exception {
1876
    public void testIrnLive(String invoiceNumber) throws Exception {
2014
        List<Order> orders = orderRepository.selectByInvoiceNumber(invoiceNumber);
1877
        List<Order> orders = orderRepository.selectByInvoiceNumber(invoiceNumber);
2015
        InvoicePdfModel invoicePdfModel = invoiceService.getInvoicePdfModel(orders);
1878
        InvoicePdfModel invoicePdfModel = invoiceService.getInvoicePdfModel(orders);
2016
        gstProService.getEInvoice(orders, invoicePdfModel);
1879
        gstProService.getEInvoice(orders, invoicePdfModel);
2017
    }
1880
    }