| Line 48... |
Line 48... |
| 48 |
import java.util.stream.Collectors;
|
48 |
import java.util.stream.Collectors;
|
| 49 |
import java.util.stream.LongStream;
|
49 |
import java.util.stream.LongStream;
|
| 50 |
|
50 |
|
| 51 |
@Component
|
51 |
@Component
|
| 52 |
public class AdminUser {
|
52 |
public class AdminUser {
|
| 53 |
@Autowired
|
53 |
@Autowired
|
| 54 |
private Gson gson;
|
54 |
private Gson gson;
|
| 55 |
|
55 |
|
| 56 |
@Autowired
|
56 |
@Autowired
|
| 57 |
private OrderRepository orderRepository;
|
57 |
private OrderRepository orderRepository;
|
| 58 |
|
58 |
|
| 59 |
@Autowired
|
59 |
@Autowired
|
| 60 |
TicketRepository ticketRepository;
|
60 |
TicketRepository ticketRepository;
|
| 61 |
|
61 |
|
| 62 |
@Autowired
|
62 |
@Autowired
|
| 63 |
private ChartService chartService;
|
63 |
private ChartService chartService;
|
| 64 |
|
64 |
|
| 65 |
@Autowired
|
65 |
@Autowired
|
| 66 |
RetailerService retailerService;
|
66 |
RetailerService retailerService;
|
| 67 |
|
67 |
|
| 68 |
@Autowired
|
68 |
@Autowired
|
| 69 |
AuthRepository authRepository;
|
69 |
AuthRepository authRepository;
|
| 70 |
|
70 |
|
| 71 |
@Autowired
|
71 |
@Autowired
|
| 72 |
FofoStoreRepository fofoStoreRepository;
|
72 |
FofoStoreRepository fofoStoreRepository;
|
| 73 |
|
73 |
|
| 74 |
@Autowired
|
74 |
@Autowired
|
| 75 |
CsService1 csService1;
|
75 |
CsService1 csService1;
|
| 76 |
|
76 |
|
| 77 |
@Autowired
|
77 |
@Autowired
|
| 78 |
CsService csService;
|
78 |
CsService csService;
|
| 79 |
|
79 |
|
| 80 |
@Autowired
|
80 |
@Autowired
|
| 81 |
private MenuRepository menuRepository;
|
81 |
private MenuRepository menuRepository;
|
| 82 |
|
82 |
|
| 83 |
@Autowired
|
83 |
@Autowired
|
| 84 |
private PositionRepository positionRepository;
|
84 |
private PositionRepository positionRepository;
|
| 85 |
|
85 |
|
| 86 |
@Autowired
|
86 |
@Autowired
|
| 87 |
private MenuCategoryRepository menuCategoryRepository;
|
87 |
private MenuCategoryRepository menuCategoryRepository;
|
| 88 |
|
88 |
|
| 89 |
@Autowired
|
89 |
@Autowired
|
| 90 |
private SaholicInventoryCISRepository saholicInventoryCISRepository;
|
90 |
private SaholicInventoryCISRepository saholicInventoryCISRepository;
|
| 91 |
|
91 |
|
| 92 |
@Autowired
|
92 |
@Autowired
|
| 93 |
private ReporticoCacheTableRepository reporticoCacheTableRepository;
|
93 |
private ReporticoCacheTableRepository reporticoCacheTableRepository;
|
| 94 |
|
94 |
|
| 95 |
@Autowired
|
95 |
@Autowired
|
| 96 |
private ActivatedImeiRepository activatedImeiRepository;
|
96 |
private ActivatedImeiRepository activatedImeiRepository;
|
| 97 |
|
97 |
|
| 98 |
@Autowired
|
98 |
@Autowired
|
| 99 |
private PartnerStatsService partnerStatsService;
|
99 |
private PartnerStatsService partnerStatsService;
|
| 100 |
@Autowired
|
100 |
@Autowired
|
| 101 |
private SDCreditService sdCreditService;
|
101 |
private SDCreditService sdCreditService;
|
| 102 |
|
102 |
|
| 103 |
List<String> colorList = Arrays.asList("mediumseagreen", "dodgerblue", "darkblue", "gold", "#eb0029", "coral",
|
103 |
List<String> colorList = Arrays.asList("mediumseagreen", "dodgerblue", "darkblue", "gold", "#eb0029", "coral",
|
| 104 |
"#63C5DA", "red", "deeppink", "midnightblue", "cornsilk");
|
104 |
"#63C5DA", "red", "deeppink", "midnightblue", "cornsilk");
|
| 105 |
|
105 |
|
| 106 |
List<String> borderList = Arrays.asList("lawngreen", "lightblue", "#0000cd", "#f7e98e", "#eb0029", "lightcoral",
|
106 |
List<String> borderList = Arrays.asList("lawngreen", "lightblue", "#0000cd", "#f7e98e", "#eb0029", "lightcoral",
|
| 107 |
"#0000cd", "lightsalmon", "pink", "#0000cd", "cornsilk");
|
107 |
"#0000cd", "lightsalmon", "pink", "#0000cd", "cornsilk");
|
| 108 |
|
108 |
|
| 109 |
List<String> brands = Arrays.asList("Oppo", "Vivo", "Samsung", "Realme", "OnePlus", "Xiaomi", "Tecno", "Itel",
|
109 |
List<String> brands = Arrays.asList("Oppo", "Vivo", "Samsung", "Realme", "OnePlus", "Xiaomi", "Tecno", "Itel",
|
| 110 |
"Lava", "Nokia");
|
110 |
"Lava", "Nokia");
|
| 111 |
|
111 |
|
| 112 |
private static final Logger LOGGER = LogManager.getLogger(AdminUser.class);
|
112 |
private static final Logger LOGGER = LogManager.getLogger(AdminUser.class);
|
| 113 |
|
113 |
|
| 114 |
public ChartModel getBrandWiseLmp(List<Integer> warehouseIds, List<Integer> fofoIds, LocalDate startDate,
|
114 |
public ChartModel getBrandWiseLmp(List<Integer> warehouseIds, List<Integer> fofoIds, LocalDate startDate,
|
| 115 |
LocalDate endDate, String filterType) {
|
115 |
LocalDate endDate, String filterType) {
|
| 116 |
LOGGER.info("params" + warehouseIds + fofoIds + startDate);
|
116 |
LOGGER.info("params" + warehouseIds + fofoIds + startDate);
|
| 117 |
|
117 |
|
| 118 |
List<BrandWiseModel> brandWiseLms = orderRepository.selectGroupByBrandLmp(fofoIds, warehouseIds, startDate,
|
118 |
List<BrandWiseModel> brandWiseLms = orderRepository.selectGroupByBrandLmp(fofoIds, warehouseIds, startDate,
|
| 119 |
endDate, filterType);
|
119 |
endDate, filterType);
|
| 120 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
120 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
| 121 |
ChartModel cm = null;
|
121 |
ChartModel cm = null;
|
| 122 |
|
122 |
|
| 123 |
if (filterType.equals("dateWise")) {
|
123 |
if (filterType.equals("dateWise")) {
|
| 124 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
124 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
| 125 |
|
125 |
|
| 126 |
Map<String, Map<LocalDate, Double>> brandDateValue = new HashMap<>();
|
126 |
Map<String, Map<LocalDate, Double>> brandDateValue = new HashMap<>();
|
| 127 |
for (BrandWiseModel bwl : brandWiseLms) {
|
127 |
for (BrandWiseModel bwl : brandWiseLms) {
|
| 128 |
if (!brandDateValue.containsKey(bwl.getBrand())) {
|
128 |
if (!brandDateValue.containsKey(bwl.getBrand())) {
|
| 129 |
brandDateValue.put(bwl.getBrand(), new HashMap<>());
|
129 |
brandDateValue.put(bwl.getBrand(), new HashMap<>());
|
| 130 |
}
|
130 |
}
|
| 131 |
Map<LocalDate, Double> dateWiseSalesMap = brandDateValue.get(bwl.getBrand());
|
131 |
Map<LocalDate, Double> dateWiseSalesMap = brandDateValue.get(bwl.getBrand());
|
| 132 |
dateWiseSalesMap.put(LocalDate.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
|
132 |
dateWiseSalesMap.put(LocalDate.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
|
| 133 |
}
|
133 |
}
|
| 134 |
|
134 |
|
| 135 |
long days = startDate.until(endDate, ChronoUnit.DAYS);
|
135 |
long days = startDate.until(endDate, ChronoUnit.DAYS);
|
| 136 |
List<LocalDate> allDatesBetween = LongStream.range(0, days).mapToObj(x -> startDate.plusDays(x))
|
136 |
List<LocalDate> allDatesBetween = LongStream.range(0, days).mapToObj(x -> startDate.plusDays(x))
|
| 137 |
.collect(Collectors.toList());
|
137 |
.collect(Collectors.toList());
|
| 138 |
LOGGER.info("All dates between {}", allDatesBetween);
|
138 |
LOGGER.info("All dates between {}", allDatesBetween);
|
| 139 |
|
139 |
|
| 140 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
140 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
| 141 |
|
141 |
|
| 142 |
for (String brand : brands) {
|
142 |
for (String brand : brands) {
|
| 143 |
if (!brandDateValue.containsKey(brand)) {
|
143 |
if (!brandDateValue.containsKey(brand)) {
|
| 144 |
brandDateValue.put(brand, new HashMap<>());
|
144 |
brandDateValue.put(brand, new HashMap<>());
|
| 145 |
}
|
145 |
}
|
| 146 |
Map<LocalDate, Double> dateWiseBrand = brandDateValue.get(brand);
|
146 |
Map<LocalDate, Double> dateWiseBrand = brandDateValue.get(brand);
|
| 147 |
for (LocalDate date : allDatesBetween) {
|
147 |
for (LocalDate date : allDatesBetween) {
|
| 148 |
if (dateWiseBrand.get(date) == null) {
|
148 |
if (dateWiseBrand.get(date) == null) {
|
| 149 |
dateWiseBrand.put(date, 0.0);
|
149 |
dateWiseBrand.put(date, 0.0);
|
| 150 |
}
|
150 |
}
|
| 151 |
}
|
151 |
}
|
| 152 |
|
152 |
|
| 153 |
Map<LocalDate, Double> sortedMonthBrandValue = new TreeMap<>(dateWiseBrand);
|
153 |
Map<LocalDate, Double> sortedMonthBrandValue = new TreeMap<>(dateWiseBrand);
|
| 154 |
sortedBrandValue.put(brand, new ArrayList<>(sortedMonthBrandValue.values()));
|
154 |
sortedBrandValue.put(brand, new ArrayList<>(sortedMonthBrandValue.values()));
|
| 155 |
LOGGER.info("Sorted Brandwise values count {}", sortedMonthBrandValue.size());
|
155 |
LOGGER.info("Sorted Brandwise values count {}", sortedMonthBrandValue.size());
|
| 156 |
}
|
156 |
}
|
| 157 |
|
157 |
|
| 158 |
LOGGER.info("brandMonthValueCount {}", brandDateValue.size());
|
158 |
LOGGER.info("brandMonthValueCount {}", brandDateValue.size());
|
| 159 |
|
159 |
|
| 160 |
LOGGER.info("sortedBrandValueCount {}", sortedBrandValue.size());
|
160 |
LOGGER.info("sortedBrandValueCount {}", sortedBrandValue.size());
|
| 161 |
cm = chartService.createChartWithLabels(
|
161 |
cm = chartService.createChartWithLabels(
|
| 162 |
allDatesBetween.stream().map(x -> x.format((DateTimeFormatter.ofPattern("dd MMM''uu"))))
|
162 |
allDatesBetween.stream().map(x -> x.format((DateTimeFormatter.ofPattern("dd MMM''uu"))))
|
| 163 |
.collect(Collectors.toCollection(LinkedHashSet::new)),
|
163 |
.collect(Collectors.toCollection(LinkedHashSet::new)),
|
| 164 |
sortedBrandValue, colorList, borderList, "Brand Wise Date Wise Purchase");
|
164 |
sortedBrandValue, colorList, borderList, "Brand Wise Date Wise Purchase");
|
| 165 |
|
165 |
|
| 166 |
} else {
|
166 |
} else {
|
| 167 |
|
167 |
|
| 168 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
|
168 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
|
| 169 |
|
169 |
|
| 170 |
Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
|
170 |
Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
|
| 171 |
for (BrandWiseModel bwl : brandWiseLms) {
|
171 |
for (BrandWiseModel bwl : brandWiseLms) {
|
| 172 |
Map<YearMonth, Double> yearMonthValue = new HashMap<>();
|
172 |
Map<YearMonth, Double> yearMonthValue = new HashMap<>();
|
| 173 |
if (brandMonthValue.containsKey(bwl.getBrand())) {
|
173 |
if (brandMonthValue.containsKey(bwl.getBrand())) {
|
| 174 |
yearMonthValue = brandMonthValue.get(bwl.getBrand());
|
174 |
yearMonthValue = brandMonthValue.get(bwl.getBrand());
|
| 175 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
175 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
| 176 |
(double) bwl.getAmount());
|
176 |
(double) bwl.getAmount());
|
| 177 |
} else {
|
177 |
} else {
|
| 178 |
|
178 |
|
| 179 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
179 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
| 180 |
(double) bwl.getAmount());
|
180 |
(double) bwl.getAmount());
|
| 181 |
|
181 |
|
| 182 |
}
|
182 |
}
|
| 183 |
brandMonthValue.put(bwl.getBrand(), yearMonthValue);
|
183 |
brandMonthValue.put(bwl.getBrand(), yearMonthValue);
|
| 184 |
|
184 |
|
| 185 |
}
|
185 |
}
|
| 186 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
186 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 187 |
|
187 |
|
| 188 |
Period age = Period.between(startDate, endDate);
|
188 |
Period age = Period.between(startDate, endDate);
|
| 189 |
int months = age.getMonths();
|
189 |
int months = age.getMonths();
|
| 190 |
LOGGER.info("months" + months);
|
190 |
LOGGER.info("months" + months);
|
| 191 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
191 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
| 192 |
LOGGER.info("brandMonthValue" + brandMonthValue);
|
192 |
LOGGER.info("brandMonthValue" + brandMonthValue);
|
| 193 |
|
193 |
|
| 194 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
194 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
| 195 |
|
195 |
|
| 196 |
for (String brand : brands) {
|
196 |
for (String brand : brands) {
|
| 197 |
Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
|
197 |
Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
|
| 198 |
for (int i = months; i >= 0; i--) {
|
198 |
for (int i = months; i >= 0; i--) {
|
| 199 |
|
199 |
|
| 200 |
LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
|
200 |
LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
|
| 201 |
|
201 |
|
| 202 |
if (yearMonthValue != null) {
|
202 |
if (yearMonthValue != null) {
|
| 203 |
if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
|
203 |
if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
|
| 204 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
204 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
| 205 |
}
|
205 |
}
|
| 206 |
|
206 |
|
| 207 |
} else {
|
207 |
} else {
|
| 208 |
yearMonthValue = new HashMap<>();
|
208 |
yearMonthValue = new HashMap<>();
|
| 209 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
209 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
| 210 |
}
|
210 |
}
|
| 211 |
}
|
211 |
}
|
| 212 |
|
212 |
|
| 213 |
Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
|
213 |
Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
|
| 214 |
|
214 |
|
| 215 |
brandMonthValue.put(brand, sortedMonthBrandValue);
|
215 |
brandMonthValue.put(brand, sortedMonthBrandValue);
|
| 216 |
|
216 |
|
| 217 |
sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
|
217 |
sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
|
| 218 |
|
218 |
|
| 219 |
}
|
219 |
}
|
| 220 |
|
220 |
|
| 221 |
cm = chartService.createChart(months, sortedBrandValue, colorList, borderList,
|
221 |
cm = chartService.createChart(months, sortedBrandValue, colorList, borderList,
|
| 222 |
"Brand Wise Monthly Purchase");
|
222 |
"Brand Wise Monthly Purchase");
|
| 223 |
|
223 |
|
| 224 |
}
|
224 |
}
|
| 225 |
|
225 |
|
| 226 |
return cm;
|
226 |
return cm;
|
| 227 |
}
|
227 |
}
|
| 228 |
|
228 |
|
| 229 |
public ChartInvestmentModel getAllStatePartnerType(Map<Integer, PartnerDetailModel> fofoIdAndallValues)
|
229 |
public ChartInvestmentModel getAllStatePartnerType(Map<Integer, PartnerDetailModel> fofoIdAndallValues)
|
| 230 |
throws ProfitMandiBusinessException {
|
230 |
throws ProfitMandiBusinessException {
|
| 231 |
|
231 |
|
| 232 |
Map<String, Float> partnerTypeCount = new HashMap<>();
|
232 |
Map<String, Float> partnerTypeCount = new HashMap<>();
|
| 233 |
|
233 |
|
| 234 |
List<PartnerType> partnerTypes = Arrays.asList(PartnerType.values());
|
234 |
List<PartnerType> partnerTypes = Arrays.asList(PartnerType.values());
|
| 235 |
|
235 |
|
| 236 |
for (PartnerType partnerType : partnerTypes) {
|
236 |
for (PartnerType partnerType : partnerTypes) {
|
| 237 |
|
237 |
|
| 238 |
float count = fofoIdAndallValues.entrySet().stream()
|
238 |
float count = fofoIdAndallValues.entrySet().stream()
|
| 239 |
.filter(x -> x.getValue().getPartnerType().equals(partnerType)).count();
|
239 |
.filter(x -> x.getValue().getPartnerType().equals(partnerType)).count();
|
| 240 |
|
240 |
|
| 241 |
partnerTypeCount.put(partnerType.toString(), count);
|
241 |
partnerTypeCount.put(partnerType.toString(), count);
|
| 242 |
|
242 |
|
| 243 |
}
|
243 |
}
|
| 244 |
|
244 |
|
| 245 |
ChartInvestmentModel cm = new ChartInvestmentModel();
|
245 |
ChartInvestmentModel cm = new ChartInvestmentModel();
|
| 246 |
|
246 |
|
| 247 |
HashSet<String> labels = new HashSet<String>();
|
247 |
HashSet<String> labels = new HashSet<String>();
|
| 248 |
labels.addAll(partnerTypes.stream().skip(1).map(x -> x.toString()).collect(Collectors.toList()));
|
248 |
labels.addAll(partnerTypes.stream().skip(1).map(x -> x.toString()).collect(Collectors.toList()));
|
| 249 |
List<String> labelList = new ArrayList<>(labels);
|
249 |
List<String> labelList = new ArrayList<>(labels);
|
| 250 |
|
250 |
|
| 251 |
List<String> backgroundColor = new ArrayList<>();
|
251 |
List<String> backgroundColor = new ArrayList<>();
|
| 252 |
|
252 |
|
| 253 |
List<Float> values = new ArrayList<>();
|
253 |
List<Float> values = new ArrayList<>();
|
| 254 |
|
254 |
|
| 255 |
for (String label : labelList) {
|
255 |
for (String label : labelList) {
|
| 256 |
values.add(partnerTypeCount.get(label));
|
256 |
values.add(partnerTypeCount.get(label));
|
| 257 |
if (label.equals("BRONZE")) {
|
257 |
if (label.equals("BRONZE")) {
|
| 258 |
backgroundColor.add("#CD7F32");
|
258 |
backgroundColor.add("#CD7F32");
|
| 259 |
}
|
259 |
}
|
| 260 |
if (label.equals("SILVER")) {
|
260 |
if (label.equals("SILVER")) {
|
| 261 |
backgroundColor.add("silver");
|
261 |
backgroundColor.add("silver");
|
| 262 |
}
|
262 |
}
|
| 263 |
if (label.equals("GOLD")) {
|
263 |
if (label.equals("GOLD")) {
|
| 264 |
backgroundColor.add("#FFD700");
|
264 |
backgroundColor.add("#FFD700");
|
| 265 |
}
|
265 |
}
|
| 266 |
if (label.equals("DIAMOND")) {
|
266 |
if (label.equals("DIAMOND")) {
|
| 267 |
backgroundColor.add("#B9F2FF");
|
267 |
backgroundColor.add("#B9F2FF");
|
| 268 |
}
|
268 |
}
|
| 269 |
|
269 |
|
| 270 |
if (label.equals("PLATINUM")) {
|
270 |
if (label.equals("PLATINUM")) {
|
| 271 |
backgroundColor.add("#800080");
|
271 |
backgroundColor.add("#800080");
|
| 272 |
}
|
272 |
}
|
| 273 |
if (label.equals("NEW")) {
|
273 |
if (label.equals("NEW")) {
|
| 274 |
backgroundColor.add("green");
|
274 |
backgroundColor.add("green");
|
| 275 |
}
|
275 |
}
|
| 276 |
|
276 |
|
| 277 |
}
|
277 |
}
|
| 278 |
|
278 |
|
| 279 |
LOGGER.info("valuesPartnerType" + values);
|
279 |
LOGGER.info("valuesPartnerType" + values);
|
| 280 |
LOGGER.info("partnerTypeCount" + partnerTypeCount);
|
280 |
LOGGER.info("partnerTypeCount" + partnerTypeCount);
|
| 281 |
|
281 |
|
| 282 |
Data data = new Data();
|
282 |
Data data = new Data();
|
| 283 |
data.setData(values);
|
283 |
data.setData(values);
|
| 284 |
data.setBackgroundColor(backgroundColor);
|
284 |
data.setBackgroundColor(backgroundColor);
|
| 285 |
data.setLabel("DataSet 1");
|
285 |
data.setLabel("DataSet 1");
|
| 286 |
|
286 |
|
| 287 |
PieLables label = new PieLables();
|
287 |
PieLables label = new PieLables();
|
| 288 |
label.setFontColor("black");
|
288 |
label.setFontColor("black");
|
| 289 |
label.setFontSize(22);
|
289 |
label.setFontSize(22);
|
| 290 |
|
290 |
|
| 291 |
Legend legend = new Legend();
|
291 |
Legend legend = new Legend();
|
| 292 |
legend.setLabels(label);
|
292 |
legend.setLabels(label);
|
| 293 |
legend.setPosition("left");
|
293 |
legend.setPosition("left");
|
| 294 |
|
294 |
|
| 295 |
List<Data> dataList = new ArrayList<>();
|
295 |
List<Data> dataList = new ArrayList<>();
|
| 296 |
dataList.add(data);
|
296 |
dataList.add(data);
|
| 297 |
|
297 |
|
| 298 |
DataInvestmentModel datasets = new DataInvestmentModel();
|
298 |
DataInvestmentModel datasets = new DataInvestmentModel();
|
| 299 |
datasets.setDatasets(dataList);
|
299 |
datasets.setDatasets(dataList);
|
| 300 |
datasets.setLabels(labels);
|
300 |
datasets.setLabels(labels);
|
| 301 |
|
301 |
|
| 302 |
OptionModel om = new OptionModel();
|
302 |
OptionModel om = new OptionModel();
|
| 303 |
om.setLegend(legend);
|
303 |
om.setLegend(legend);
|
| 304 |
cm.setType("pie");
|
304 |
cm.setType("pie");
|
| 305 |
cm.setData(datasets);
|
305 |
cm.setData(datasets);
|
| 306 |
cm.setOptions(om);
|
306 |
cm.setOptions(om);
|
| 307 |
|
307 |
|
| 308 |
return cm;
|
308 |
return cm;
|
| 309 |
}
|
309 |
}
|
| 310 |
|
310 |
|
| 311 |
public Map<String, Object> getFilter(int warehouseId, String email, LocalDateTime date, LocalDateTime endDate)
|
311 |
public Map<String, Object> getFilter(int warehouseId, String email, LocalDateTime date, LocalDateTime endDate)
|
| 312 |
throws ProfitMandiBusinessException {
|
312 |
throws ProfitMandiBusinessException {
|
| 313 |
Map<String, Object> map = new HashMap<>();
|
313 |
Map<String, Object> map = new HashMap<>();
|
| 314 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
314 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 315 |
Map<Integer, CustomRetailer> crm = null;
|
315 |
Map<Integer, CustomRetailer> crm = null;
|
| 316 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
316 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
| 317 |
|
317 |
|
| 318 |
Set<Integer> fofoIds = csService1.getAuthFofoIds(email, true);
|
318 |
Set<Integer> fofoIds = csService1.getAuthFofoIds(email, true);
|
| 319 |
|
319 |
|
| 320 |
if (warehouseId != 0) {
|
320 |
if (warehouseId != 0) {
|
| 321 |
|
321 |
|
| 322 |
fofoIds = fofoStoreRepository.selectPartnerByfofoIdAndWarehouse(new ArrayList<>(fofoIds), warehouseId)
|
322 |
fofoIds = fofoStoreRepository.selectPartnerByfofoIdAndWarehouse(new ArrayList<>(fofoIds), warehouseId)
|
| 323 |
.stream().map(x -> x).collect(Collectors.toSet());
|
323 |
.stream().map(x -> x).collect(Collectors.toSet());
|
| 324 |
|
324 |
|
| 325 |
}
|
325 |
}
|
| 326 |
|
326 |
|
| 327 |
if (fofoIds != null) {
|
327 |
if (fofoIds != null) {
|
| 328 |
|
328 |
|
| 329 |
crm = fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null)
|
329 |
crm = fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null)
|
| 330 |
.collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
330 |
.collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 331 |
|
331 |
|
| 332 |
}
|
332 |
}
|
| 333 |
|
333 |
|
| 334 |
map.put("date", date);
|
334 |
map.put("date", date);
|
| 335 |
map.put("endDate", endDate);
|
335 |
map.put("endDate", endDate);
|
| 336 |
map.put("customRetailersMap", crm);
|
336 |
map.put("customRetailersMap", crm);
|
| 337 |
map.put("fofoIds", fofoIds);
|
337 |
map.put("fofoIds", fofoIds);
|
| 338 |
map.put("warehouseMap", warehouseMap);
|
338 |
map.put("warehouseMap", warehouseMap);
|
| 339 |
|
339 |
|
| 340 |
return map;
|
340 |
return map;
|
| 341 |
|
341 |
|
| 342 |
}
|
342 |
}
|
| 343 |
|
343 |
|
| 344 |
public ChartModel getBrandWiseLms(List<Integer> warehouseIds, List<Integer> fofoIds, LocalDate startDate,
|
344 |
public ChartModel getBrandWiseLms(List<Integer> warehouseIds, List<Integer> fofoIds, LocalDate startDate,
|
| 345 |
LocalDate endDate, String filterType) {
|
345 |
LocalDate endDate, String filterType) {
|
| 346 |
LOGGER.info("params" + warehouseIds + fofoIds + startDate);
|
346 |
//LOGGER.info("params" + warehouseIds + fofoIds + startDate);
|
| 347 |
|
347 |
|
| 348 |
List<BrandWiseModel> brandWiseLms = fofoStoreRepository.selectGroupByBrandLms(fofoIds, warehouseIds, startDate,
|
348 |
List<BrandWiseModel> brandWiseLms = fofoStoreRepository.selectGroupByBrandLms(fofoIds, warehouseIds, startDate,
|
| 349 |
endDate, filterType);
|
349 |
endDate, filterType);
|
| 350 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
350 |
//LOGGER.info("brandWiseLms" + brandWiseLms);
|
| 351 |
|
351 |
|
| 352 |
ChartModel cm = null;
|
352 |
ChartModel cm = null;
|
| 353 |
|
353 |
|
| 354 |
if (filterType.equals("dateWise")) {
|
354 |
if (filterType.equals("dateWise")) {
|
| 355 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
355 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
| 356 |
|
356 |
|
| 357 |
Map<String, Map<LocalDate, Double>> brandDateValue = new HashMap<>();
|
357 |
Map<String, Map<LocalDate, Double>> brandDateValue = new HashMap<>();
|
| 358 |
for (BrandWiseModel bwl : brandWiseLms) {
|
358 |
for (BrandWiseModel bwl : brandWiseLms) {
|
| 359 |
if (!brandDateValue.containsKey(bwl.getBrand())) {
|
359 |
if (!brandDateValue.containsKey(bwl.getBrand())) {
|
| 360 |
brandDateValue.put(bwl.getBrand(), new HashMap<>());
|
360 |
brandDateValue.put(bwl.getBrand(), new HashMap<>());
|
| 361 |
}
|
361 |
}
|
| 362 |
Map<LocalDate, Double> dateWiseSalesMap = brandDateValue.get(bwl.getBrand());
|
362 |
Map<LocalDate, Double> dateWiseSalesMap = brandDateValue.get(bwl.getBrand());
|
| 363 |
dateWiseSalesMap.put(LocalDate.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
|
363 |
dateWiseSalesMap.put(LocalDate.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
|
| 364 |
}
|
364 |
}
|
| 365 |
|
365 |
|
| 366 |
long days = startDate.until(endDate, ChronoUnit.DAYS);
|
366 |
long days = startDate.until(endDate, ChronoUnit.DAYS);
|
| 367 |
List<LocalDate> allDatesBetween = LongStream.range(0, days).mapToObj(x -> startDate.plusDays(x))
|
367 |
List<LocalDate> allDatesBetween = LongStream.range(0, days).mapToObj(x -> startDate.plusDays(x))
|
| 368 |
.collect(Collectors.toList());
|
368 |
.collect(Collectors.toList());
|
| 369 |
LOGGER.info("All dates between {}", allDatesBetween);
|
369 |
//LOGGER.info("All dates between {}", allDatesBetween);
|
| 370 |
|
370 |
|
| 371 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
371 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
| 372 |
|
372 |
|
| 373 |
for (String brand : brands) {
|
373 |
for (String brand : brands) {
|
| 374 |
if (!brandDateValue.containsKey(brand)) {
|
374 |
if (!brandDateValue.containsKey(brand)) {
|
| 375 |
brandDateValue.put(brand, new HashMap<>());
|
375 |
brandDateValue.put(brand, new HashMap<>());
|
| 376 |
}
|
376 |
}
|
| 377 |
Map<LocalDate, Double> dateWiseBrand = brandDateValue.get(brand);
|
377 |
Map<LocalDate, Double> dateWiseBrand = brandDateValue.get(brand);
|
| 378 |
for (LocalDate date : allDatesBetween) {
|
378 |
for (LocalDate date : allDatesBetween) {
|
| 379 |
if (dateWiseBrand.get(date) == null) {
|
379 |
if (dateWiseBrand.get(date) == null) {
|
| 380 |
dateWiseBrand.put(date, 0.0);
|
380 |
dateWiseBrand.put(date, 0.0);
|
| 381 |
}
|
381 |
}
|
| 382 |
}
|
382 |
}
|
| 383 |
|
383 |
|
| 384 |
Map<LocalDate, Double> sortedMonthBrandValue = new TreeMap<>(dateWiseBrand);
|
384 |
Map<LocalDate, Double> sortedMonthBrandValue = new TreeMap<>(dateWiseBrand);
|
| 385 |
sortedBrandValue.put(brand, new ArrayList<>(sortedMonthBrandValue.values()));
|
385 |
sortedBrandValue.put(brand, new ArrayList<>(sortedMonthBrandValue.values()));
|
| 386 |
LOGGER.info("Sorted Brandwise values count {}", sortedMonthBrandValue.size());
|
386 |
LOGGER.info("Sorted Brandwise values count {}", sortedMonthBrandValue.size());
|
| 387 |
}
|
387 |
}
|
| 388 |
|
388 |
|
| 389 |
LOGGER.info("brandMonthValueCount {}", brandDateValue.size());
|
389 |
LOGGER.info("brandMonthValueCount {}", brandDateValue.size());
|
| 390 |
|
390 |
|
| 391 |
LOGGER.info("sortedBrandValueCount {}", sortedBrandValue.size());
|
391 |
LOGGER.info("sortedBrandValueCount {}", sortedBrandValue.size());
|
| 392 |
cm = chartService.createChartWithLabels(
|
392 |
cm = chartService.createChartWithLabels(
|
| 393 |
allDatesBetween.stream().map(x -> x.format((DateTimeFormatter.ofPattern("dd MMM''uu"))))
|
393 |
allDatesBetween.stream().map(x -> x.format((DateTimeFormatter.ofPattern("dd MMM''uu"))))
|
| 394 |
.collect(Collectors.toCollection(LinkedHashSet::new)),
|
394 |
.collect(Collectors.toCollection(LinkedHashSet::new)),
|
| 395 |
sortedBrandValue, colorList, borderList, "Brand Wise Date Wise Sale");
|
395 |
sortedBrandValue, colorList, borderList, "Brand Wise Date Wise Sale");
|
| 396 |
|
396 |
|
| 397 |
} else {
|
397 |
} else {
|
| 398 |
|
398 |
|
| 399 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
|
399 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
|
| 400 |
|
400 |
|
| 401 |
Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
|
401 |
Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
|
| 402 |
for (BrandWiseModel bwl : brandWiseLms) {
|
402 |
for (BrandWiseModel bwl : brandWiseLms) {
|
| 403 |
Map<YearMonth, Double> yearMonthValue = new HashMap<>();
|
403 |
Map<YearMonth, Double> yearMonthValue = new HashMap<>();
|
| 404 |
if (brandMonthValue.containsKey(bwl.getBrand())) {
|
404 |
if (brandMonthValue.containsKey(bwl.getBrand())) {
|
| 405 |
yearMonthValue = brandMonthValue.get(bwl.getBrand());
|
405 |
yearMonthValue = brandMonthValue.get(bwl.getBrand());
|
| 406 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
406 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
| 407 |
(double) bwl.getAmount());
|
407 |
(double) bwl.getAmount());
|
| 408 |
} else {
|
408 |
} else {
|
| 409 |
|
409 |
|
| 410 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
410 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
| 411 |
(double) bwl.getAmount());
|
411 |
(double) bwl.getAmount());
|
| 412 |
|
412 |
|
| 413 |
}
|
413 |
}
|
| 414 |
brandMonthValue.put(bwl.getBrand(), yearMonthValue);
|
414 |
brandMonthValue.put(bwl.getBrand(), yearMonthValue);
|
| 415 |
|
415 |
|
| 416 |
}
|
416 |
}
|
| 417 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
417 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 418 |
|
418 |
|
| 419 |
Period age = Period.between(startDate, endDate);
|
419 |
Period age = Period.between(startDate, endDate);
|
| 420 |
int months = age.getMonths();
|
420 |
int months = age.getMonths();
|
| 421 |
LOGGER.info("months" + months);
|
421 |
//LOGGER.info("months" + months);
|
| 422 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
422 |
//LOGGER.info("brandWiseLms" + brandWiseLms);
|
| 423 |
LOGGER.info("brandMonthValue" + brandMonthValue);
|
423 |
//LOGGER.info("brandMonthValue" + brandMonthValue);
|
| 424 |
|
424 |
|
| 425 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
425 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
| 426 |
|
426 |
|
| 427 |
for (String brand : brands) {
|
427 |
for (String brand : brands) {
|
| 428 |
Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
|
428 |
Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
|
| 429 |
for (int i = months; i >= 0; i--) {
|
429 |
for (int i = months; i >= 0; i--) {
|
| 430 |
|
430 |
|
| 431 |
LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
|
431 |
LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
|
| 432 |
|
432 |
|
| 433 |
if (yearMonthValue != null) {
|
433 |
if (yearMonthValue != null) {
|
| 434 |
if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
|
434 |
if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
|
| 435 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
435 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
| 436 |
}
|
436 |
}
|
| 437 |
|
437 |
|
| 438 |
} else {
|
438 |
} else {
|
| 439 |
yearMonthValue = new HashMap<>();
|
439 |
yearMonthValue = new HashMap<>();
|
| 440 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
440 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
| 441 |
}
|
441 |
}
|
| 442 |
}
|
442 |
}
|
| 443 |
|
443 |
|
| 444 |
Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
|
444 |
Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
|
| 445 |
|
445 |
|
| 446 |
brandMonthValue.put(brand, sortedMonthBrandValue);
|
446 |
brandMonthValue.put(brand, sortedMonthBrandValue);
|
| 447 |
|
447 |
|
| 448 |
sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
|
448 |
sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
|
| 449 |
|
449 |
|
| 450 |
}
|
450 |
}
|
| 451 |
|
451 |
|
| 452 |
cm = chartService.createChart(months, sortedBrandValue, colorList, borderList, "Brand Wise Monthly Sale");
|
452 |
cm = chartService.createChart(months, sortedBrandValue, colorList, borderList, "Brand Wise Monthly Sale");
|
| 453 |
}
|
453 |
}
|
| 454 |
|
454 |
|
| 455 |
return cm;
|
455 |
return cm;
|
| 456 |
}
|
456 |
}
|
| 457 |
|
457 |
|
| 458 |
public String adminPanel(int fofoId, String email, Model model) throws Exception {
|
458 |
public String adminPanel(int fofoId, String email, Model model) throws Exception {
|
| 459 |
List<Menu> menus = null;
|
459 |
List<Menu> menus = null;
|
| 460 |
try {
|
460 |
try {
|
| 461 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
461 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
| 462 |
List<Position> positions = positionRepository.selectAll(authUser.getId());
|
462 |
List<Position> positions = positionRepository.selectAll(authUser.getId());
|
| 463 |
Map<Integer, PartnerDetailModel> warehousePartnerDetailMap = null;
|
463 |
Map<Integer, PartnerDetailModel> warehousePartnerDetailMap = null;
|
| 464 |
|
464 |
|
| 465 |
Map<Integer, WarehouseWiseStockModel> warehouseStockMap = new HashMap<>();
|
465 |
Map<Integer, WarehouseWiseStockModel> warehouseStockMap = new HashMap<>();
|
| 466 |
LinkedHashMap<Integer, WarehouseWiseStockModel> warehouseStockSortedMap = new LinkedHashMap<>();
|
466 |
LinkedHashMap<Integer, WarehouseWiseStockModel> warehouseStockSortedMap = new LinkedHashMap<>();
|
| 467 |
|
467 |
|
| 468 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
468 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
| 469 |
Map<Integer, String> wm = new LinkedHashMap<>();
|
469 |
Map<Integer, String> wm = new LinkedHashMap<>();
|
| 470 |
|
470 |
|
| 471 |
Map<AuthUser, Long> authUserTicketCount = null;
|
471 |
Map<AuthUser, Long> authUserTicketCount = null;
|
| 472 |
LoanSummary loanSummary= sdCreditService.getLoanSummary();
|
472 |
LoanSummary loanSummary = sdCreditService.getLoanSummary();
|
| 473 |
model.addAttribute("loanSummary",loanSummary);
|
473 |
model.addAttribute("loanSummary", loanSummary);
|
| 474 |
|
474 |
|
| 475 |
|
475 |
|
| 476 |
for (Map.Entry<Integer, String> entry : warehouseMap.entrySet()) {
|
476 |
for (Map.Entry<Integer, String> entry : warehouseMap.entrySet()) {
|
| 477 |
wm.put(entry.getKey(), entry.getValue());
|
477 |
wm.put(entry.getKey(), entry.getValue());
|
| 478 |
}
|
478 |
}
|
| 479 |
|
479 |
|
| 480 |
wm.put(0, "Total Values");
|
480 |
wm.put(0, "Total Values");
|
| 481 |
long stockValue = 0;
|
481 |
long stockValue = 0;
|
| 482 |
long stockQty = 0;
|
482 |
long stockQty = 0;
|
| 483 |
long pendingIndent = 0;
|
483 |
long pendingIndent = 0;
|
| 484 |
long tertiary = 0;
|
484 |
long tertiary = 0;
|
| 485 |
|
485 |
|
| 486 |
Set<Integer> fofoIds = csService1.getAuthFofoIds(email, true);
|
486 |
Set<Integer> fofoIds = csService1.getAuthFofoIds(email, true);
|
| 487 |
|
487 |
|
| 488 |
if (fofoIds != null && fofoIds.size() > 0) {
|
488 |
if (fofoIds != null && fofoIds.size() > 0) {
|
| 489 |
Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
|
489 |
Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
|
| 490 |
.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream()
|
490 |
.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream()
|
| 491 |
.collect(Collectors.groupingBy(FofoStore::getWarehouseId,
|
491 |
.collect(Collectors.groupingBy(FofoStore::getWarehouseId,
|
| 492 |
Collectors.mapping(FofoStore::getId, Collectors.toList())));
|
492 |
Collectors.mapping(FofoStore::getId, Collectors.toList())));
|
| 493 |
// warehouseStock
|
493 |
// warehouseStock
|
| 494 |
List<WarehouseWiseStockModel> warehouseStocks = saholicInventoryCISRepository
|
494 |
List<WarehouseWiseStockModel> warehouseStocks = saholicInventoryCISRepository
|
| 495 |
.selectGroupByWarehouse(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
|
495 |
.selectGroupByWarehouse(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
|
| 496 |
|
496 |
|
| 497 |
warehouseStockMap = warehouseStocks.stream().collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
|
497 |
warehouseStockMap = warehouseStocks.stream().collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
|
| 498 |
|
498 |
|
| 499 |
if (!warehouseStockMap.isEmpty()) {
|
499 |
if (!warehouseStockMap.isEmpty()) {
|
| 500 |
for (Entry<Integer, WarehouseWiseStockModel> warehouseStock : warehouseStockMap.entrySet()) {
|
500 |
for (Entry<Integer, WarehouseWiseStockModel> warehouseStock : warehouseStockMap.entrySet()) {
|
| 501 |
stockValue += warehouseStock.getValue().getStockValue();
|
501 |
stockValue += warehouseStock.getValue().getStockValue();
|
| 502 |
stockQty += warehouseStock.getValue().getStockQty();
|
502 |
stockQty += warehouseStock.getValue().getStockQty();
|
| 503 |
pendingIndent += warehouseStock.getValue().getPendingIndent();
|
503 |
pendingIndent += warehouseStock.getValue().getPendingIndent();
|
| 504 |
tertiary += warehouseStock.getValue().getTertiary();
|
504 |
tertiary += warehouseStock.getValue().getTertiary();
|
| 505 |
}
|
505 |
}
|
| 506 |
WarehouseWiseStockModel ws = new WarehouseWiseStockModel();
|
506 |
WarehouseWiseStockModel ws = new WarehouseWiseStockModel();
|
| 507 |
ws.setStockQty(stockQty);
|
507 |
ws.setStockQty(stockQty);
|
| 508 |
ws.setStockValue(stockValue);
|
508 |
ws.setStockValue(stockValue);
|
| 509 |
ws.setPendingIndent(pendingIndent);
|
509 |
ws.setPendingIndent(pendingIndent);
|
| 510 |
ws.setTertiary(tertiary);
|
510 |
ws.setTertiary(tertiary);
|
| 511 |
ws.setWarehouseId(0);
|
511 |
ws.setWarehouseId(0);
|
| 512 |
warehouseStockMap.put(0, ws);
|
512 |
warehouseStockMap.put(0, ws);
|
| 513 |
|
513 |
|
| 514 |
}
|
514 |
}
|
| 515 |
|
515 |
|
| 516 |
warehouseStockMap.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.reverseOrder()))
|
516 |
warehouseStockMap.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.reverseOrder()))
|
| 517 |
.forEachOrdered(x -> warehouseStockSortedMap.put(x.getKey(), x.getValue()));
|
517 |
.forEachOrdered(x -> warehouseStockSortedMap.put(x.getKey(), x.getValue()));
|
| 518 |
|
518 |
|
| 519 |
ReporticoCacheTable rctSaholic = reporticoCacheTableRepository.selectByTableName("SaholicInventoryCIS");
|
519 |
ReporticoCacheTable rctSaholic = reporticoCacheTableRepository.selectByTableName("SaholicInventoryCIS");
|
| 520 |
model.addAttribute("reporticoDate", rctSaholic);
|
520 |
model.addAttribute("reporticoDate", rctSaholic);
|
| 521 |
|
521 |
|
| 522 |
// warehouseStock
|
522 |
// warehouseStock
|
| 523 |
warehousePartnerDetailMap = this.getWarehousePartnerDetail(warehouseIdFofoIdMap);
|
523 |
warehousePartnerDetailMap = this.getWarehousePartnerDetail(warehouseIdFofoIdMap);
|
| 524 |
|
524 |
|
| 525 |
ReporticoCacheTable rctPartneStat = reporticoCacheTableRepository.selectByTableName("partnerStat");
|
525 |
ReporticoCacheTable rctPartneStat = reporticoCacheTableRepository.selectByTableName("partnerStat");
|
| 526 |
|
526 |
|
| 527 |
Set<CustomRetailer> positionRetailers = fofoIds.stream()
|
527 |
Set<CustomRetailer> positionRetailers = fofoIds.stream()
|
| 528 |
.map(x -> retailerService.getAllFofoRetailers().get(x)).filter(x -> x != null)
|
528 |
.map(x -> retailerService.getAllFofoRetailers().get(x)).filter(x -> x != null)
|
| 529 |
.collect(Collectors.toSet());
|
529 |
.collect(Collectors.toSet());
|
| 530 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
530 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
| 531 |
model.addAttribute("reporticoProjectMap", ReporticoProject.salesReporticoProjectMap);
|
531 |
model.addAttribute("reporticoProjectMap", ReporticoProject.salesReporticoProjectMap);
|
| 532 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
532 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
| 533 |
model.addAttribute("rctPartneStat", rctPartneStat);
|
533 |
model.addAttribute("rctPartneStat", rctPartneStat);
|
| 534 |
} else {
|
534 |
} else {
|
| 535 |
List<Position> warehousePositions = positions.stream()
|
535 |
List<Position> warehousePositions = positions.stream()
|
| 536 |
.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE)
|
536 |
.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE)
|
| 537 |
.collect(Collectors.toList());
|
537 |
.collect(Collectors.toList());
|
| 538 |
if (warehousePositions.size() > 0) {
|
538 |
if (warehousePositions.size() > 0) {
|
| 539 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
539 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
| 540 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
540 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
| 541 |
positionRetailers.addAll(customRetailers);
|
541 |
positionRetailers.addAll(customRetailers);
|
| 542 |
});
|
542 |
});
|
| 543 |
model.addAttribute("reporticoProjectMap", ReporticoProject.warehouseReporticoMap);
|
543 |
model.addAttribute("reporticoProjectMap", ReporticoProject.warehouseReporticoMap);
|
| 544 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
544 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
| 545 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
545 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
| 546 |
}
|
546 |
}
|
| 547 |
List<Position> categoryPositions = positions.stream()
|
547 |
List<Position> categoryPositions = positions.stream()
|
| 548 |
.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_CATEGORY)
|
548 |
.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_CATEGORY)
|
| 549 |
.collect(Collectors.toList());
|
549 |
.collect(Collectors.toList());
|
| 550 |
if (categoryPositions.size() > 0) {
|
550 |
if (categoryPositions.size() > 0) {
|
| 551 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
551 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
| 552 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
552 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
| 553 |
positionRetailers.addAll(customRetailers);
|
553 |
positionRetailers.addAll(customRetailers);
|
| 554 |
});
|
554 |
});
|
| 555 |
model.addAttribute("reporticoProjectMap", ReporticoProject.warehouseReporticoMap);
|
555 |
model.addAttribute("reporticoProjectMap", ReporticoProject.warehouseReporticoMap);
|
| 556 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
556 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
| 557 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
557 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
| 558 |
}
|
558 |
}
|
| 559 |
}
|
559 |
}
|
| 560 |
|
560 |
|
| 561 |
if (positions.size() > 0) {
|
561 |
if (positions.size() > 0) {
|
| 562 |
if (positions.stream()
|
562 |
if (positions.stream()
|
| 563 |
.filter(x -> x.getEscalationType().equals(EscalationType.L3)
|
563 |
.filter(x -> x.getEscalationType().equals(EscalationType.L3)
|
| 564 |
|| x.getEscalationType().equals(EscalationType.L4)
|
564 |
|| x.getEscalationType().equals(EscalationType.L4)
|
| 565 |
|| x.getEscalationType().equals(EscalationType.L5))
|
565 |
|| x.getEscalationType().equals(EscalationType.L5))
|
| 566 |
.count() > 0) {
|
566 |
.count() > 0) {
|
| 567 |
authUserTicketCount = ticketRepository.selectAllAuthUserTicketCount(Optional.of(false));
|
567 |
authUserTicketCount = ticketRepository.selectAllAuthUserTicketCount(Optional.of(false));
|
| 568 |
}
|
568 |
}
|
| 569 |
}
|
569 |
}
|
| 570 |
|
570 |
|
| 571 |
if (Arrays.asList("amit.gupta@smartdukaan.com", "ranu.rajput@smartdukaan.com",
|
571 |
if (Arrays.asList("amit.gupta@smartdukaan.com", "ranu.rajput@smartdukaan.com",
|
| 572 |
"shampa.banerjee@smartdukaan.com", "tejus.lohani@smartdukaan.com").contains(email)) {
|
572 |
"shampa.banerjee@smartdukaan.com", "tejus.lohani@smartdukaan.com").contains(email)) {
|
| 573 |
menus = menuRepository.selectAllBySequence();
|
573 |
menus = menuRepository.selectAllBySequence();
|
| 574 |
} else if (positions.size() > 0) {
|
574 |
} else if (positions.size() > 0) {
|
| 575 |
if (positions.stream().filter(x -> x.getEscalationType().equals(EscalationType.L5)).count() > 0) {
|
575 |
if (positions.stream().filter(x -> x.getEscalationType().equals(EscalationType.L5)).count() > 0) {
|
| 576 |
menus = menuRepository.selectAllBySequence();
|
576 |
menus = menuRepository.selectAllBySequence();
|
| 577 |
} else {
|
577 |
} else {
|
| 578 |
List<Integer> menuIds = menuCategoryRepository.selectAllByPositions(positions).stream()
|
578 |
List<Integer> menuIds = menuCategoryRepository.selectAllByPositions(positions).stream()
|
| 579 |
.map(x -> x.getMenuId()).collect(Collectors.toList());
|
579 |
.map(x -> x.getMenuId()).collect(Collectors.toList());
|
| 580 |
if (menuIds.size() > 0) {
|
580 |
if (menuIds.size() > 0) {
|
| 581 |
menus = menuRepository.selectAllByIds(menuIds);
|
581 |
menus = menuRepository.selectAllByIds(menuIds);
|
| 582 |
}
|
582 |
}
|
| 583 |
}
|
583 |
}
|
| 584 |
}
|
584 |
}
|
| 585 |
|
585 |
|
| 586 |
model.addAttribute("authId", authUser.getId());
|
586 |
model.addAttribute("authId", authUser.getId());
|
| 587 |
|
587 |
|
| 588 |
model.addAttribute("warehousePartnerDetailMap", warehousePartnerDetailMap);
|
588 |
model.addAttribute("warehousePartnerDetailMap", warehousePartnerDetailMap);
|
| 589 |
model.addAttribute("warehouseMap", wm);
|
589 |
model.addAttribute("warehouseMap", wm);
|
| 590 |
model.addAttribute("authUserTicketCount", authUserTicketCount);
|
590 |
model.addAttribute("authUserTicketCount", authUserTicketCount);
|
| 591 |
model.addAttribute("warehouseStockMap", warehouseStockSortedMap);
|
591 |
model.addAttribute("warehouseStockMap", warehouseStockSortedMap);
|
| 592 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
592 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 593 |
|
593 |
|
| 594 |
model.addAttribute("date", curDate.withDayOfMonth(1).minusMonths(6).toLocalDate());
|
594 |
model.addAttribute("date", curDate.withDayOfMonth(1).minusMonths(6).toLocalDate());
|
| 595 |
|
595 |
|
| 596 |
} catch (ProfitMandiBusinessException e) {
|
596 |
} catch (ProfitMandiBusinessException e) {
|
| 597 |
}
|
597 |
}
|
| 598 |
List<Menu> menuList = (menus != null) ? this.prepareMenu(menus) : new ArrayList<>();
|
598 |
List<Menu> menuList = (menus != null) ? this.prepareMenu(menus) : new ArrayList<>();
|
| 599 |
LOGGER.info("menu" + menuList);
|
599 |
LOGGER.info("menu" + menuList);
|
| 600 |
model.addAttribute("menu", menuList);
|
600 |
model.addAttribute("menu", menuList);
|
| 601 |
return "admin";
|
601 |
return "admin";
|
| 602 |
}
|
602 |
}
|
| 603 |
|
603 |
|
| 604 |
private List<Menu> prepareMenu(List<Menu> menus) {
|
604 |
private List<Menu> prepareMenu(List<Menu> menus) {
|
| 605 |
List<Menu> returnMenu = new ArrayList<>();
|
605 |
List<Menu> returnMenu = new ArrayList<>();
|
| 606 |
Map<Menu, List<Menu>> subMenuMap = new HashMap<>();
|
606 |
Map<Menu, List<Menu>> subMenuMap = new HashMap<>();
|
| 607 |
for (Menu menu : menus) {
|
607 |
for (Menu menu : menus) {
|
| 608 |
if (menu.get_parent() == null) {
|
608 |
if (menu.get_parent() == null) {
|
| 609 |
if (!subMenuMap.containsKey(menu)) {
|
609 |
if (!subMenuMap.containsKey(menu)) {
|
| 610 |
subMenuMap.put(menu, new ArrayList<>());
|
610 |
subMenuMap.put(menu, new ArrayList<>());
|
| 611 |
}
|
611 |
}
|
| 612 |
} else {
|
612 |
} else {
|
| 613 |
Menu parentMenu = menu.get_parent();
|
613 |
Menu parentMenu = menu.get_parent();
|
| 614 |
if (!subMenuMap.containsKey(parentMenu)) {
|
614 |
if (!subMenuMap.containsKey(parentMenu)) {
|
| 615 |
subMenuMap.put(parentMenu, new ArrayList<>());
|
615 |
subMenuMap.put(parentMenu, new ArrayList<>());
|
| 616 |
}
|
616 |
}
|
| 617 |
subMenuMap.get(parentMenu).add(menu);
|
617 |
subMenuMap.get(parentMenu).add(menu);
|
| 618 |
}
|
618 |
}
|
| 619 |
}
|
619 |
}
|
| 620 |
subMenuMap.entrySet().stream().forEach(entry -> {
|
620 |
subMenuMap.entrySet().stream().forEach(entry -> {
|
| 621 |
entry.getKey().setSubMenus(entry.getValue());
|
621 |
entry.getKey().setSubMenus(entry.getValue());
|
| 622 |
returnMenu.add(entry.getKey());
|
622 |
returnMenu.add(entry.getKey());
|
| 623 |
});
|
623 |
});
|
| 624 |
return returnMenu;
|
624 |
return returnMenu;
|
| 625 |
}
|
625 |
}
|
| 626 |
|
626 |
|
| 627 |
public Map<Integer, PartnerDetailModel> getWarehousePartnerDetail(Map<Integer, List<Integer>> warehousePartnerMap)
|
627 |
public Map<Integer, PartnerDetailModel> getWarehousePartnerDetail(Map<Integer, List<Integer>> warehousePartnerMap)
|
| 628 |
throws Exception {
|
628 |
throws Exception {
|
| 629 |
|
629 |
|
| 630 |
Map<Integer, PartnerDetailModel> warehouseIdAndallValues = new LinkedHashMap<>();
|
630 |
Map<Integer, PartnerDetailModel> warehouseIdAndallValues = new LinkedHashMap<>();
|
| 631 |
// Map<Integer, List<FofoStore>> warehousePartnerMap =
|
631 |
// Map<Integer, List<FofoStore>> warehousePartnerMap =
|
| 632 |
// fofoStoreRepository.getWarehousePartnerMap();
|
632 |
// fofoStoreRepository.getWarehousePartnerMap();
|
| 633 |
Map<Integer, PartnerDetailModel> partnerStats = this.getPartnersStatDataFromFile();
|
633 |
Map<Integer, PartnerDetailModel> partnerStats = this.getPartnersStatDataFromFile();
|
| 634 |
List<Integer> allfofoIds = new ArrayList<>();
|
634 |
List<Integer> allfofoIds = new ArrayList<>();
|
| 635 |
if (partnerStats != null) {
|
635 |
if (partnerStats != null) {
|
| 636 |
for (Entry<Integer, List<Integer>> warehouse : warehousePartnerMap.entrySet()) {
|
636 |
for (Entry<Integer, List<Integer>> warehouse : warehousePartnerMap.entrySet()) {
|
| 637 |
List<Integer> fofoIds = warehouse.getValue().stream().collect(Collectors.toList());
|
637 |
List<Integer> fofoIds = warehouse.getValue().stream().collect(Collectors.toList());
|
| 638 |
allfofoIds.addAll(fofoIds);
|
638 |
allfofoIds.addAll(fofoIds);
|
| 639 |
List<PartnerDetailModel> partnerDetails = fofoIds.stream().map(x -> partnerStats.get(x))
|
639 |
List<PartnerDetailModel> partnerDetails = fofoIds.stream().map(x -> partnerStats.get(x))
|
| 640 |
.collect(Collectors.toList());
|
640 |
.collect(Collectors.toList());
|
| 641 |
if (partnerDetails != null && !partnerDetails.isEmpty()) {
|
641 |
if (partnerDetails != null && !partnerDetails.isEmpty()) {
|
| 642 |
PartnerDetailModel partnerDetailModel = partnerStatsService.getAggregateStats(partnerDetails);
|
642 |
PartnerDetailModel partnerDetailModel = partnerStatsService.getAggregateStats(partnerDetails);
|
| 643 |
warehouseIdAndallValues.put(warehouse.getKey(), partnerDetailModel);
|
643 |
warehouseIdAndallValues.put(warehouse.getKey(), partnerDetailModel);
|
| 644 |
}
|
644 |
}
|
| 645 |
|
645 |
|
| 646 |
}
|
646 |
}
|
| 647 |
List<PartnerDetailModel> allPartnerDetails = allfofoIds.stream().map(x -> partnerStats.get(x))
|
647 |
List<PartnerDetailModel> allPartnerDetails = allfofoIds.stream().map(x -> partnerStats.get(x))
|
| 648 |
.collect(Collectors.toList());
|
648 |
.collect(Collectors.toList());
|
| 649 |
LOGGER.info("allPartnerDetails" + allPartnerDetails);
|
649 |
LOGGER.info("allPartnerDetails" + allPartnerDetails);
|
| 650 |
PartnerDetailModel partnerDetailModel = partnerStatsService
|
650 |
PartnerDetailModel partnerDetailModel = partnerStatsService
|
| 651 |
.getAggregateStats(new ArrayList<>(allPartnerDetails));
|
651 |
.getAggregateStats(new ArrayList<>(allPartnerDetails));
|
| 652 |
warehouseIdAndallValues.put(0, partnerDetailModel);
|
652 |
warehouseIdAndallValues.put(0, partnerDetailModel);
|
| 653 |
}
|
653 |
}
|
| 654 |
return warehouseIdAndallValues;
|
654 |
return warehouseIdAndallValues;
|
| 655 |
}
|
655 |
}
|
| 656 |
|
656 |
|
| 657 |
public Map<Integer, PartnerDetailModel> getPartnersStatDataFromFile() throws Exception {
|
657 |
public Map<Integer, PartnerDetailModel> getPartnersStatDataFromFile() throws Exception {
|
| 658 |
ObjectInputStream objectinputstream = null;
|
658 |
ObjectInputStream objectinputstream = null;
|
| 659 |
Map<Integer, PartnerDetailModel> partnerStat = null;
|
659 |
Map<Integer, PartnerDetailModel> partnerStat = null;
|
| 660 |
try {
|
660 |
try {
|
| 661 |
FileInputStream streamIn = new FileInputStream("/tmp/partnerStat.tmp");
|
661 |
FileInputStream streamIn = new FileInputStream("/tmp/partnerStat.tmp");
|
| 662 |
objectinputstream = new ObjectInputStream(streamIn);
|
662 |
objectinputstream = new ObjectInputStream(streamIn);
|
| 663 |
partnerStat = (Map<Integer, PartnerDetailModel>) objectinputstream.readObject();
|
663 |
partnerStat = (Map<Integer, PartnerDetailModel>) objectinputstream.readObject();
|
| 664 |
|
664 |
|
| 665 |
LOGGER.info("partnerStat" + partnerStat);
|
665 |
objectinputstream.close();
|
| 666 |
objectinputstream.close();
|
666 |
|
| 667 |
|
667 |
} catch (Exception e) {
|
| 668 |
} catch (Exception e) {
|
668 |
LOGGER.info("exceptionddd" + e);
|
| 669 |
LOGGER.info("exceptionddd" + e);
|
669 |
|
| 670 |
|
670 |
e.printStackTrace();
|
| 671 |
e.printStackTrace();
|
671 |
|
| 672 |
|
672 |
} finally {
|
| 673 |
} finally {
|
673 |
if (objectinputstream != null) {
|
| 674 |
if (objectinputstream != null) {
|
674 |
objectinputstream.close();
|
| 675 |
objectinputstream.close();
|
675 |
}
|
| 676 |
LOGGER.info("clofddd" + partnerStat);
|
676 |
}
|
| 677 |
|
677 |
return partnerStat;
|
| 678 |
}
|
678 |
|
| 679 |
}
|
679 |
}
|
| 680 |
return partnerStat;
|
680 |
|
| 681 |
|
681 |
private String getWarehouses(Set<CustomRetailer> positionRetailers) {
|
| 682 |
}
|
682 |
Map<Integer, String> warehouses = new HashMap<>();
|
| 683 |
|
683 |
positionRetailers.stream().forEach(x -> {
|
| 684 |
private String getWarehouses(Set<CustomRetailer> positionRetailers) {
|
684 |
if (x.getWarehouseId() != 0) {
|
| 685 |
Map<Integer, String> warehouses = new HashMap<>();
|
685 |
warehouses.put(x.getWarehouseId(), ProfitMandiConstants.WAREHOUSE_MAP.get(x.getWarehouseId()));
|
| 686 |
positionRetailers.stream().forEach(x -> {
|
686 |
}
|
| 687 |
if (x.getWarehouseId() != 0) {
|
687 |
});
|
| 688 |
warehouses.put(x.getWarehouseId(), ProfitMandiConstants.WAREHOUSE_MAP.get(x.getWarehouseId()));
|
688 |
return gson.toJson(warehouses);
|
| 689 |
}
|
- |
|
| 690 |
});
|
- |
|
| 691 |
return gson.toJson(warehouses);
|
- |
|
| 692 |
|
689 |
|
| 693 |
}
|
690 |
}
|
| 694 |
|
691 |
|
| 695 |
|
692 |
|
| 696 |
}
|
693 |
}
|