Subversion Repositories SmartDukaan

Rev

Rev 34619 | Rev 34936 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34619 Rev 34813
Line 17... Line 17...
17
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
17
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
18
import com.spice.profitmandi.dao.enumuration.dtr.RetailerType;
18
import com.spice.profitmandi.dao.enumuration.dtr.RetailerType;
19
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
19
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
20
import com.spice.profitmandi.dao.enumuration.fofo.PaymentOptionType;
20
import com.spice.profitmandi.dao.enumuration.fofo.PaymentOptionType;
21
import com.spice.profitmandi.dao.enumuration.transaction.PartnerVerificationApprovalStatus;
21
import com.spice.profitmandi.dao.enumuration.transaction.PartnerVerificationApprovalStatus;
-
 
22
import com.spice.profitmandi.dao.model.LastMonthCreditedIncomeModel;
22
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
23
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
23
import com.spice.profitmandi.dao.repository.dtr.*;
24
import com.spice.profitmandi.dao.repository.dtr.*;
24
import com.spice.profitmandi.dao.repository.fofo.FofoPartnerPaymentOptionRepository;
-
 
25
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
25
import com.spice.profitmandi.dao.repository.fofo.*;
26
import com.spice.profitmandi.dao.repository.fofo.PincodePartnerRepository;
-
 
27
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
26
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
28
import com.spice.profitmandi.dao.repository.user.*;
27
import com.spice.profitmandi.dao.repository.user.*;
29
import com.spice.profitmandi.service.PostOfficeService;
28
import com.spice.profitmandi.service.PostOfficeService;
30
import in.shop2020.model.v1.user.CartStatus;
29
import in.shop2020.model.v1.user.CartStatus;
31
import org.apache.logging.log4j.LogManager;
30
import org.apache.logging.log4j.LogManager;
Line 34... Line 33...
34
import org.springframework.beans.factory.annotation.Qualifier;
33
import org.springframework.beans.factory.annotation.Qualifier;
35
import org.springframework.cache.annotation.Cacheable;
34
import org.springframework.cache.annotation.Cacheable;
36
import org.springframework.stereotype.Component;
35
import org.springframework.stereotype.Component;
37
 
36
 
38
import java.nio.charset.StandardCharsets;
37
import java.nio.charset.StandardCharsets;
-
 
38
import java.time.LocalDate;
39
import java.time.LocalDateTime;
39
import java.time.LocalDateTime;
-
 
40
import java.time.YearMonth;
-
 
41
import java.time.format.DateTimeFormatter;
40
import java.util.*;
42
import java.util.*;
41
import java.util.function.Function;
43
import java.util.function.Function;
42
import java.util.stream.Collectors;
44
import java.util.stream.Collectors;
43
import java.util.stream.Stream;
45
import java.util.stream.Stream;
44
 
46
 
Line 133... Line 135...
133
    private PartnerOnboardingVerificationRepository partnerOnboardingVerificationRepository;
135
    private PartnerOnboardingVerificationRepository partnerOnboardingVerificationRepository;
134
 
136
 
135
    @Autowired
137
    @Autowired
136
    private PincodePartnerRepository pincodePartnerRepository;
138
    private PincodePartnerRepository pincodePartnerRepository;
137
 
139
 
-
 
140
    @Autowired
-
 
141
    SchemeInOutRepository schemeInOutRepository;
-
 
142
 
-
 
143
    @Autowired
-
 
144
    OfferPayoutRepository offerPayoutRepository;
-
 
145
 
-
 
146
    @Autowired
-
 
147
    PartnerTypeChangeService partnerTypeChangeService;
-
 
148
 
138
    @Override
149
    @Override
139
    public Map<String, Object> getByEmailIdOrMobileNumber(String emailIdOrMobileNumber) throws ProfitMandiBusinessException {
150
    public Map<String, Object> getByEmailIdOrMobileNumber(String emailIdOrMobileNumber) throws ProfitMandiBusinessException {
140
        User user = null;
151
        User user = null;
141
        int fofoId = Utils.SYSTEM_PARTNER_ID;
152
        int fofoId = Utils.SYSTEM_PARTNER_ID;
142
 
153
 
Line 1340... Line 1351...
1340
 
1351
 
1341
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1352
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1342
        return this.getFofoRetailers(storeIds);
1353
        return this.getFofoRetailers(storeIds);
1343
    }
1354
    }
1344
 
1355
 
-
 
1356
    @Override
-
 
1357
    public Map<String, Object> computeIncomeMap(int fofoId, int yearMonth) {
-
 
1358
        LocalDateTime startOfMonth = LocalDate.now().minusMonths(yearMonth).withDayOfMonth(1).atStartOfDay();
-
 
1359
        LocalDateTime endOfMonth = startOfMonth.plusMonths(1);
-
 
1360
        YearMonth monthYear = YearMonth.now();
-
 
1361
 
-
 
1362
 
-
 
1363
        // 3) Fetch brand-wise data (same as original)
-
 
1364
        List<LastMonthCreditedIncomeModel> lastMonthPendingIncomeModels = schemeInOutRepository
-
 
1365
                .selectLastMonthPendingIncomeByFofoId(fofoId, startOfMonth, endOfMonth);
-
 
1366
 
-
 
1367
        List<LastMonthCreditedIncomeModel> lastMonthPurchaseInMargins = schemeInOutRepository
-
 
1368
                .selectLastMonthPurchaseInMarginByFofoId(fofoId, startOfMonth, endOfMonth);
-
 
1369
 
-
 
1370
        List<LastMonthCreditedIncomeModel> lastMonthFrontEndIncomes = schemeInOutRepository
-
 
1371
                .selectFrontIncomeByBrand(fofoId, startOfMonth, endOfMonth);
-
 
1372
 
-
 
1373
        List<LastMonthCreditedIncomeModel> lastMonthSaleMargins = schemeInOutRepository
-
 
1374
                .selectLastMonthCreditedIncomeByFofoId(fofoId, startOfMonth, endOfMonth);
-
 
1375
 
-
 
1376
        List<OfferPayoutImeiIncomeModel> offerPayoutImeiIncomeModels = offerPayoutRepository
-
 
1377
                .getTotalPayoutsByPartnerPeriod(
-
 
1378
                        YearMonth.of(startOfMonth.getYear(), startOfMonth.getMonth()),
-
 
1379
                        fofoId, null, null);
-
 
1380
 
-
 
1381
        // 4) Convert to maps for brand-wise access
-
 
1382
        Map<String, LastMonthCreditedIncomeModel> lastMonthPendingIncomeMap =
-
 
1383
                lastMonthPendingIncomeModels.stream()
-
 
1384
                        .collect(Collectors.toMap(x -> x.getBrand(), x -> x));
-
 
1385
 
-
 
1386
        Map<String, LastMonthCreditedIncomeModel> lastMonthPurchaseInMarginMap =
-
 
1387
                lastMonthPurchaseInMargins.stream()
-
 
1388
                        .collect(Collectors.toMap(x -> x.getBrand(), x -> x));
-
 
1389
 
-
 
1390
        Map<String, LastMonthCreditedIncomeModel> lastMonthFrontEndIncomeMap =
-
 
1391
                lastMonthFrontEndIncomes.stream()
-
 
1392
                        .collect(Collectors.toMap(x -> x.getBrand(), x -> x));
-
 
1393
 
-
 
1394
        Map<String, LastMonthCreditedIncomeModel> lastMonthSaleMarginMap =
-
 
1395
                lastMonthSaleMargins.stream()
-
 
1396
                        .collect(Collectors.toMap(x -> x.getBrand(), x -> x));
-
 
1397
 
-
 
1398
        Map<String, Double> additionalPurchasePayout = offerPayoutImeiIncomeModels.stream()
-
 
1399
                .collect(Collectors.groupingBy(OfferPayoutImeiIncomeModel::getBrand,
-
 
1400
                        Collectors.summingDouble(OfferPayoutImeiIncomeModel::getPurchasePayout)));
-
 
1401
 
-
 
1402
        Map<String, Double> additionSalePayout = offerPayoutImeiIncomeModels.stream()
-
 
1403
                .collect(Collectors.groupingBy(OfferPayoutImeiIncomeModel::getBrand,
-
 
1404
                        Collectors.summingDouble(OfferPayoutImeiIncomeModel::getSalePayout)));
-
 
1405
 
-
 
1406
        // 5) Get all unique brands
-
 
1407
        Set<String> brandSet = new HashSet<>();
-
 
1408
        brandSet.addAll(lastMonthPurchaseInMarginMap.keySet());
-
 
1409
        brandSet.addAll(lastMonthSaleMarginMap.keySet());
-
 
1410
        brandSet.addAll(lastMonthPendingIncomeMap.keySet());
-
 
1411
        brandSet.addAll(additionalPurchasePayout.keySet());
-
 
1412
        brandSet.addAll(additionSalePayout.keySet());
-
 
1413
        brandSet.addAll(lastMonthFrontEndIncomeMap.keySet());
-
 
1414
 
-
 
1415
        // 6) Calculate total amount per brand (same logic as original)
-
 
1416
        Map<String, Float> totalAmountMap = new HashMap<>();
-
 
1417
        brandSet.forEach(brand -> {
-
 
1418
            float total =
-
 
1419
                    (lastMonthSaleMarginMap.get(brand) == null ? 0 : lastMonthSaleMarginMap.get(brand).getAmount()) +
-
 
1420
                            (lastMonthPurchaseInMarginMap.get(brand) == null ? 0 : lastMonthPurchaseInMarginMap.get(brand).getAmount()) +
-
 
1421
                            (lastMonthPendingIncomeMap.get(brand) == null ? 0 : lastMonthPendingIncomeMap.get(brand).getAmount()) +
-
 
1422
                            (additionalPurchasePayout.get(brand) == null ? 0 : additionalPurchasePayout.get(brand).floatValue()) +
-
 
1423
                            (additionSalePayout.get(brand) == null ? 0 : additionSalePayout.get(brand).floatValue()) +
-
 
1424
                            (lastMonthFrontEndIncomeMap.get(brand) == null ? 0 : lastMonthFrontEndIncomeMap.get(brand).getAmount());
-
 
1425
            totalAmountMap.put(brand, total);
-
 
1426
        });
-
 
1427
 
-
 
1428
        // 7) Calculate aggregated totals
-
 
1429
        float totalIncome = totalAmountMap.values().stream()
-
 
1430
                .reduce(0f, Float::sum);
-
 
1431
 
-
 
1432
        float pendingIncome = lastMonthPendingIncomeMap.values().stream()
-
 
1433
                .map(LastMonthCreditedIncomeModel::getAmount)
-
 
1434
                .reduce(0f, Float::sum);
-
 
1435
 
-
 
1436
        float creditedIncome = totalIncome - pendingIncome;
-
 
1437
 
-
 
1438
        // 8) Build month labels
-
 
1439
        Map<Integer, String> monthValueMap = new HashMap<>();
-
 
1440
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("MMM''uu");
-
 
1441
        for (int i = 0; i <= 5; i++) {
-
 
1442
            LocalDateTime m = LocalDateTime.now()
-
 
1443
                    .withDayOfMonth(1)
-
 
1444
                    .minusMonths(i);
-
 
1445
            monthValueMap.put(i, m.format(fmt));
-
 
1446
        }
-
 
1447
 
-
 
1448
        // 9) Assemble result with all brand-wise data
-
 
1449
        Map<String, Object> result = new HashMap<>();
-
 
1450
        result.put("totalIncome", totalIncome);
-
 
1451
        result.put("creditedIncome", creditedIncome);
-
 
1452
        result.put("pendingIncome", pendingIncome);
-
 
1453
        result.put("monthIndex", yearMonth);
-
 
1454
        result.put("monthValueMap", monthValueMap);
-
 
1455
 
-
 
1456
        // Include brand-wise data for detailed analysis
-
 
1457
        result.put("brandSet", brandSet);
-
 
1458
        result.put("totalAmountMap", totalAmountMap);
-
 
1459
        result.put("lastMonthPurchaseInMarginMap", lastMonthPurchaseInMarginMap);
-
 
1460
        result.put("lastMonthSaleMarginMap", lastMonthSaleMarginMap);
-
 
1461
        result.put("lastMonthPendingIncomeMap", lastMonthPendingIncomeMap);
-
 
1462
        result.put("additionalPurchasePayoutMap", additionalPurchasePayout);
-
 
1463
        result.put("additionalSalePayoutMap", additionSalePayout);
-
 
1464
        result.put("lastMonthFrontEndIncomeMap", lastMonthFrontEndIncomeMap);
-
 
1465
 
-
 
1466
        return result;
-
 
1467
    }
-
 
1468
 
1345
}
1469
}