Subversion Repositories SmartDukaan

Rev

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

Rev 24248 Rev 24263
Line 19... Line 19...
19
import org.springframework.web.bind.annotation.RequestParam;
19
import org.springframework.web.bind.annotation.RequestParam;
20
 
20
 
21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
22
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22
import com.spice.profitmandi.common.model.ProfitMandiConstants;
23
import com.spice.profitmandi.dao.entity.dtr.NotificationData;
23
import com.spice.profitmandi.dao.entity.dtr.NotificationData;
24
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
-
 
25
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
24
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
26
import com.spice.profitmandi.dao.entity.transaction.Order;
25
import com.spice.profitmandi.dao.entity.transaction.Order;
27
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
26
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
28
import com.spice.profitmandi.dao.repository.dtr.NotificationPanelRepository;
27
import com.spice.profitmandi.dao.repository.dtr.NotificationPanelRepository;
29
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
28
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
30
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
29
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
31
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
-
 
32
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
30
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
33
import com.spice.profitmandi.service.authentication.RoleManager;
31
import com.spice.profitmandi.service.authentication.RoleManager;
34
import com.spice.profitmandi.service.inventory.InventoryService;
32
import com.spice.profitmandi.service.inventory.InventoryService;
35
import com.spice.profitmandi.service.slab.TargetSlabService;
-
 
36
import com.spice.profitmandi.service.transaction.TransactionService;
33
import com.spice.profitmandi.service.transaction.TransactionService;
37
import com.spice.profitmandi.service.wallet.WalletService;
34
import com.spice.profitmandi.service.wallet.WalletService;
38
import com.spice.profitmandi.web.model.LoginDetails;
35
import com.spice.profitmandi.web.model.LoginDetails;
39
import com.spice.profitmandi.web.util.CookiesProcessor;
36
import com.spice.profitmandi.web.util.CookiesProcessor;
-
 
37
import com.spice.profitmandi.web.util.MVCResponseSender;
40
 
38
 
41
@Controller
39
@Controller
42
@Transactional(rollbackFor = Throwable.class)
40
@Transactional(rollbackFor = Throwable.class)
43
public class DashboardController {
41
public class DashboardController {
44
 
42
 
45
	@Value("${web.api.host}")
43
	@Value("${web.api.host}")
46
	private String webApiHost;
44
	private String webApiHost;
47
 
45
 
48
	@Value("${web.api.scheme}")
46
	@Value("${web.api.scheme}")
49
	private String webApiScheme;
47
	private String webApiScheme;
50
	
48
 
51
	@Value("${web.api.root}")
49
	@Value("${web.api.root}")
52
	private String webApiRoot;
50
	private String webApiRoot;
53
 
51
 
54
	@Value("${web.api.port}")
52
	@Value("${web.api.port}")
55
	private int webApiPort;
53
	private int webApiPort;
56
 
54
 
57
 
-
 
58
	@Autowired
55
	@Autowired
59
	private CookiesProcessor cookiesProcessor;
56
	private CookiesProcessor cookiesProcessor;
60
 
57
 
61
	@Autowired
58
	@Autowired
62
	private RoleManager roleManager;
59
	private RoleManager roleManager;
Line 67... Line 64...
67
	@Autowired
64
	@Autowired
68
	private WalletService walletService;
65
	private WalletService walletService;
69
 
66
 
70
	@Autowired
67
	@Autowired
71
	private InventoryService inventoryService;
68
	private InventoryService inventoryService;
72
	
-
 
73
 
69
 
74
	@Autowired
70
	@Autowired
75
	private OrderRepository orderRepository;
71
	private OrderRepository orderRepository;
76
	
72
 
77
	@Autowired
73
	@Autowired
78
	private FofoOrderRepository fofoOrderRepository;
74
	private FofoOrderRepository fofoOrderRepository;
79
	
75
 
80
	/*
76
	/*
81
	 * @Autowired private ScanRepository scanRepository;
77
	 * @Autowired private ScanRepository scanRepository;
82
	 */
78
	 */
83
 
79
 
84
	@Autowired
80
	@Autowired
85
	private TransactionService transactionService;
81
	private TransactionService transactionService;
-
 
82
 
-
 
83
	@Autowired
-
 
84
	private MVCResponseSender mvcResponseSender;
86
	
85
 
87
	@Autowired
86
	@Autowired
88
	private NotificationPanelRepository notificationPanelRepository;
87
	private NotificationPanelRepository notificationPanelRepository;
89
 
88
 
90
	@Autowired
89
	@Autowired
91
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
90
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
Line 114... Line 113...
114
		float grnPendingStockAmount = 0;
113
		float grnPendingStockAmount = 0;
115
		float shortPercentage = 100;
114
		float shortPercentage = 100;
116
		float totalInvestedAmount = 0;
115
		float totalInvestedAmount = 0;
117
		float minimumInvestment = 0;
116
		float minimumInvestment = 0;
118
		float returnedStockInTransit = 0;
117
		float returnedStockInTransit = 0;
119
		double sale=0;
118
		double sale = 0;
120
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
119
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
121
			model.addAttribute("showAlert", false);
120
			model.addAttribute("showAlert", false);
122
			model.addAttribute("sale",sale);
121
			model.addAttribute("sale", sale);
-
 
122
			List<NotificationData> notificationData = null;
-
 
123
			long size = 0;
-
 
124
 
-
 
125
			notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
-
 
126
			size = notificationPanelRepository.selectAllCount();
-
 
127
			LOGGER.info("notification_data {}", notificationData);
-
 
128
 
-
 
129
			LOGGER.info("notification_data {}", size);
-
 
130
 
-
 
131
			if (!notificationData.isEmpty()) {
-
 
132
 
-
 
133
				model.addAttribute("notificationData", notificationData);
-
 
134
				LOGGER.info("notificationdata", notificationData);
-
 
135
				model.addAttribute("start", offset + 1);
-
 
136
				model.addAttribute("size", size);
-
 
137
				model.addAttribute("url", "/getPaginatedNotificationData");
-
 
138
 
-
 
139
				LOGGER.info("start {}", offset + 1);
-
 
140
				LOGGER.info("SIZE {}", size);
-
 
141
 
-
 
142
				if (notificationData.size() < limit) {
-
 
143
					model.addAttribute("end", offset + notificationData.size());
-
 
144
					LOGGER.info("SIZE2 {}", offset + notificationData.size());
-
 
145
				} else {
-
 
146
					model.addAttribute("end", offset + limit);
-
 
147
 
-
 
148
					LOGGER.info("end {}", size);
-
 
149
 
-
 
150
				}
-
 
151
 
-
 
152
			} else {
-
 
153
 
-
 
154
				model.addAttribute("notificationData", notificationData);
-
 
155
				model.addAttribute("size", size);
-
 
156
				LOGGER.info("sizeOriginal {}", size);
-
 
157
 
-
 
158
			}
123
		} else if (roleManager.isPartner(loginDetails.getRoleIds())) {
159
		} else if (roleManager.isPartner(loginDetails.getRoleIds())) {
124
			walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
160
			walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
125
			inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
161
			inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
-
 
162
			sale = fofoOrderRepository.selectTotalSaleSumByFofoIdBrtweenDate(loginDetails.getFofoId(),
126
			sale=fofoOrderRepository.selectTotalSaleSumByFofoIdBrtweenDate(loginDetails.getFofoId(), LocalDateTime.of(LocalDateTime.now().getYear(), LocalDateTime.now().getMonth(),01, 00, 00), LocalDateTime.now());
163
					LocalDateTime.of(LocalDateTime.now().getYear(), LocalDateTime.now().getMonth(), 01, 00, 00),
-
 
164
					LocalDateTime.now());
127
	
165
 
128
			List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
166
			List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
129
			for (Order unBilledOrder : unbilledOrders) {
167
			for (Order unBilledOrder : unbilledOrders) {
130
				unbilledStockAmount += unBilledOrder.getTotalAmount();
168
				unbilledStockAmount += unBilledOrder.getTotalAmount();
131
			}
169
			}
132
 
170
 
Line 137... Line 175...
137
			totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
175
			totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
138
			shortPercentage = ((fofoStore.getMinimumInvestment() - totalInvestedAmount)
176
			shortPercentage = ((fofoStore.getMinimumInvestment() - totalInvestedAmount)
139
					/ fofoStore.getMinimumInvestment()) * 100;
177
					/ fofoStore.getMinimumInvestment()) * 100;
140
			model.addAttribute("showAlert", shortPercentage > 10);
178
			model.addAttribute("showAlert", shortPercentage > 10);
141
			minimumInvestment = fofoStore.getMinimumInvestment();
179
			minimumInvestment = fofoStore.getMinimumInvestment();
142
			
180
 
143
			//debitNoteRepository.se
181
			// debitNoteRepository.se
-
 
182
			List<NotificationData> notificationData = null;
-
 
183
			long size = 0;
-
 
184
 
-
 
185
			notificationData = notificationPanelRepository.selectAllNotificationDataByActiveFlag(offset, limit, true);
-
 
186
			size = notificationPanelRepository.selectCountByActiveFlag(true);
-
 
187
			LOGGER.info("notification_data {}", notificationData);
-
 
188
 
-
 
189
			LOGGER.info("notification_data {}", size);
-
 
190
 
-
 
191
			if (!notificationData.isEmpty()) {
-
 
192
 
-
 
193
				model.addAttribute("notificationData", notificationData);
-
 
194
				LOGGER.info("notificationdata", notificationData);
-
 
195
				model.addAttribute("start", offset + 1);
-
 
196
				model.addAttribute("size", size);
-
 
197
				model.addAttribute("url", "/getPaginatedNotificationData");
-
 
198
 
-
 
199
				LOGGER.info("start {}", offset + 1);
-
 
200
				LOGGER.info("SIZE {}", size);
-
 
201
 
-
 
202
				if (notificationData.size() < limit) {
-
 
203
					model.addAttribute("end", offset + notificationData.size());
-
 
204
					LOGGER.info("SIZE2 {}", offset + notificationData.size());
-
 
205
				} else {
-
 
206
					model.addAttribute("end", offset + limit);
-
 
207
 
-
 
208
					LOGGER.info("end {}", size);
-
 
209
 
-
 
210
				}
-
 
211
 
-
 
212
			} else {
-
 
213
 
-
 
214
				model.addAttribute("notificationData", notificationData);
-
 
215
				model.addAttribute("size", size);
-
 
216
				LOGGER.info("sizeOriginal {}", size);
-
 
217
 
-
 
218
			}
144
		}
219
		}
145
		model.addAttribute("walletAmount", walletAmount);
220
		model.addAttribute("walletAmount", walletAmount);
146
		model.addAttribute("inStockAmount", inStockAmount);
221
		model.addAttribute("inStockAmount", inStockAmount);
147
		model.addAttribute("unbilledStockAmount", unbilledStockAmount);
222
		model.addAttribute("unbilledStockAmount", unbilledStockAmount);
148
		model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);
223
		model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);
Line 160... Line 235...
160
		model.addAttribute("webApiScheme", webApiScheme);
235
		model.addAttribute("webApiScheme", webApiScheme);
161
		model.addAttribute("webApiRoot", webApiRoot);
236
		model.addAttribute("webApiRoot", webApiRoot);
162
		model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
237
		model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
163
		model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
238
		model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
164
		model.addAttribute("sale", sale);
239
		model.addAttribute("sale", sale);
165
		
-
 
166
		List<NotificationData> notificationData = null;
-
 
167
		long size = 0;
-
 
168
	
-
 
169
		notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
-
 
170
		size = notificationPanelRepository.selectAllCount();
-
 
171
		LOGGER.info("notification_data {}", notificationData);
-
 
172
		
-
 
173
		LOGGER.info("notification_data {}",size);
-
 
174
		
-
 
175
 
-
 
176
		if (!notificationData.isEmpty()) {
-
 
177
 
-
 
178
			model.addAttribute("notificationData",notificationData);
-
 
179
			LOGGER.info("notificationdata", notificationData);
-
 
180
			model.addAttribute("start", offset + 1);
-
 
181
			model.addAttribute("size", size);
-
 
182
			model.addAttribute("url", "/getPaginatedNotificationData");
-
 
183
			
-
 
184
			LOGGER.info("start {}",offset+1);
-
 
185
			LOGGER.info("SIZE {}",size);
-
 
186
		
-
 
187
			
-
 
188
 
-
 
189
			if (notificationData.size() < limit) {
-
 
190
				model.addAttribute("end", offset + notificationData.size());
-
 
191
				LOGGER.info("SIZE2 {}", offset + notificationData.size());
-
 
192
			} else {
-
 
193
				model.addAttribute("end", offset + limit);
-
 
194
				
-
 
195
				LOGGER.info("end {}",size);
-
 
196
				
-
 
197
				
-
 
198
			}
-
 
199
 
-
 
200
		
-
 
201
		} else {
-
 
202
 
240
 
203
			model.addAttribute("notificationData", notificationData);
-
 
204
			model.addAttribute("size", size);
-
 
205
			LOGGER.info("sizeOriginal {}",size);
-
 
206
 
-
 
207
		}
-
 
208
		// LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
241
		// LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
209
		// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
242
		// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
210
		return "dashboard";
243
		return "dashboard";
211
	}
244
	}
212
 
245
 
213
	//This method is currently hardcoded to faciliate watches sold as gift.
246
	// This method is currently hardcoded to faciliate watches sold as gift.
214
	private boolean hasGift(int fofoId) {
247
	private boolean hasGift(int fofoId) {
215
		try {
248
		try {
216
			return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId).getAvailability() > 0;
249
			return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
-
 
250
					.getAvailability() > 0;
217
		} catch (ProfitMandiBusinessException e) {
251
		} catch (ProfitMandiBusinessException e) {
218
			return false;
252
			return false;
219
		}
253
		}
220
	}
254
	}
-
 
255
 
221
	@RequestMapping(value = "/getPaginatedNotificationData", method = RequestMethod.GET)
256
	@RequestMapping(value = "/getPaginatedNotificationData", method = RequestMethod.GET)
222
	public String getPaginatedNotificationData(HttpServletRequest request,
257
	public String getPaginatedNotificationData(HttpServletRequest request,
223
			@RequestParam(name = "offset", defaultValue = "0") int offset,
258
			@RequestParam(name = "offset", defaultValue = "0") int offset,
224
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
259
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
225
		List<NotificationData> notificationData = null;
-
 
226
		
-
 
227
		notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
260
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
228
 
261
 
-
 
262
		FofoStore fofoStore = null;
-
 
263
		try {
-
 
264
			fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
-
 
265
		} catch (ProfitMandiBusinessException e) {
229
		LOGGER.info("notification_data {}", notificationData);
266
			LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
230
		
267
		}
-
 
268
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
-
 
269
			List<NotificationData> notificationData = null;
231
 
270
 
232
		if (!notificationData.isEmpty()) {
271
			notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
233
 
272
 
234
			model.addAttribute("notificationData",notificationData);
273
			LOGGER.info("notification_data {}", notificationData);
235
			model.addAttribute("url", "/getPaginatedNotificationData");
-
 
236
 
274
 
-
 
275
			if (!notificationData.isEmpty()) {
-
 
276
 
-
 
277
				model.addAttribute("notificationData", notificationData);
-
 
278
				model.addAttribute("url", "/getPaginatedNotificationData");
-
 
279
 
237
		} else {
280
			} else {
238
			model.addAttribute("notificationData", notificationData);
281
				model.addAttribute("notificationData", notificationData);
-
 
282
 
-
 
283
			}
-
 
284
		} else if (roleManager.isPartner(loginDetails.getRoleIds())) {
-
 
285
 
-
 
286
			List<NotificationData> notificationData = null;
239
 
287
 
-
 
288
			notificationData = notificationPanelRepository.selectAllNotificationDataByActiveFlag(offset, limit, true);
-
 
289
			LOGGER.info("notification_data {}", notificationData);
-
 
290
 
-
 
291
			if (!notificationData.isEmpty()) {
-
 
292
 
-
 
293
				model.addAttribute("notificationData", notificationData);
-
 
294
				model.addAttribute("url", "/getPaginatedNotificationData");
-
 
295
 
-
 
296
			} else {
-
 
297
				model.addAttribute("notificationData", notificationData);
-
 
298
 
-
 
299
			}
240
		}
300
		}
241
 
301
 
242
		return "dashboard-paginated";
302
		return "dashboard-paginated";
243
	}
303
	}
-
 
304
 
244
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
305
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
245
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
306
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
246
		model.addAttribute("appContextPath", request.getContextPath());
307
		model.addAttribute("appContextPath", request.getContextPath());
247
		return "contact-us";
308
		return "contact-us";
248
	}
309
	}
249
 
310
 
250
	/*
311
	/*
251
	 * private List<PaymentOption> getPaymentOptions(int fofoId){ List<Integer>
312
	 * private List<PaymentOption> getPaymentOptions(int fofoId){ List<Integer>
252
	 * paymentOptionIds =
313
	 * paymentOptionIds =
253
	 * fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
314
	 * fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId)
254
	 * if(paymentOptionIds.isEmpty()){ return new ArrayList<>(); } return
315
	 * ; if(paymentOptionIds.isEmpty()){ return new ArrayList<>(); } return
255
	 * paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds)); }
316
	 * paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds)); }
256
	 */
317
	 */
257
 
318
 
-
 
319
	@RequestMapping(value = "/inactiveNotificationData", method = RequestMethod.POST)
-
 
320
	public String inactiveNotificationData(HttpServletRequest request,
-
 
321
			@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
-
 
322
 
-
 
323
		NotificationData notificationData = notificationPanelRepository.selectById(id);
-
 
324
		if (notificationData != null) {
-
 
325
 
-
 
326
			notificationData.setActive(false);
-
 
327
			LOGGER.info("notification" + notificationData);
-
 
328
			notificationPanelRepository.persist(notificationData);
-
 
329
 
-
 
330
			model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
331
		} else {
-
 
332
			model.addAttribute("response", mvcResponseSender.createResponseString(false));
-
 
333
 
-
 
334
		}
-
 
335
		return "response";
-
 
336
	}
-
 
337
 
-
 
338
	@RequestMapping(value = "/activeNotificationData", method = RequestMethod.POST)
-
 
339
	public String activeNotificationData(HttpServletRequest request,
-
 
340
			@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
-
 
341
 
-
 
342
		NotificationData notificationData = notificationPanelRepository.selectById(id);
-
 
343
		if (notificationData != null) {
-
 
344
 
-
 
345
			notificationData.setActive(true);
-
 
346
			notificationData.setCreated_timestamp(LocalDateTime.now());
-
 
347
			LOGGER.info("notification" + notificationData);
-
 
348
			notificationPanelRepository.persist(notificationData);
-
 
349
 
-
 
350
			model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
351
		} else {
-
 
352
			model.addAttribute("response", mvcResponseSender.createResponseString(false));
-
 
353
 
-
 
354
		}
-
 
355
		return "response";
-
 
356
	}
-
 
357
 
258
}
358
}