Subversion Repositories SmartDukaan

Rev

Rev 24098 | Rev 24182 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21615 kshitij.so 1
package com.spice.profitmandi.web.controller;
2
 
23568 govind 3
import java.io.IOException;
4
import java.net.URISyntaxException;
24121 govind 5
import java.time.LocalDateTime;
23884 amit.gupta 6
import java.util.List;
23568 govind 7
 
22086 amit.gupta 8
import javax.servlet.http.HttpServletRequest;
9
 
23786 amit.gupta 10
import org.apache.logging.log4j.LogManager;
23568 govind 11
import org.apache.logging.log4j.Logger;
22481 ashik.ali 12
import org.springframework.beans.factory.annotation.Autowired;
23379 ashik.ali 13
import org.springframework.beans.factory.annotation.Value;
21615 kshitij.so 14
import org.springframework.stereotype.Controller;
22481 ashik.ali 15
import org.springframework.transaction.annotation.Transactional;
22073 ashik.ali 16
import org.springframework.ui.Model;
21615 kshitij.so 17
import org.springframework.web.bind.annotation.RequestMapping;
18
import org.springframework.web.bind.annotation.RequestMethod;
24098 tejbeer 19
import org.springframework.web.bind.annotation.RequestParam;
21615 kshitij.so 20
 
22481 ashik.ali 21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24098 tejbeer 22
import com.spice.profitmandi.dao.entity.dtr.NotificationData;
22654 ashik.ali 23
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
23884 amit.gupta 24
import com.spice.profitmandi.dao.entity.transaction.Order;
22481 ashik.ali 25
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
24098 tejbeer 26
import com.spice.profitmandi.dao.repository.dtr.NotificationPanelRepository;
23951 amit.gupta 27
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
23884 amit.gupta 28
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
23844 amit.gupta 29
import com.spice.profitmandi.service.authentication.RoleManager;
23884 amit.gupta 30
import com.spice.profitmandi.service.inventory.InventoryService;
24121 govind 31
import com.spice.profitmandi.service.slab.TargetSlabService;
23884 amit.gupta 32
import com.spice.profitmandi.service.transaction.TransactionService;
33
import com.spice.profitmandi.service.wallet.WalletService;
22481 ashik.ali 34
import com.spice.profitmandi.web.model.LoginDetails;
35
import com.spice.profitmandi.web.util.CookiesProcessor;
36
 
21615 kshitij.so 37
@Controller
22481 ashik.ali 38
@Transactional(rollbackFor = Throwable.class)
21615 kshitij.so 39
public class DashboardController {
23923 amit.gupta 40
 
23379 ashik.ali 41
	@Value("${web.api.host}")
42
	private String webApiHost;
23923 amit.gupta 43
 
24072 amit.gupta 44
	@Value("${web.api.scheme}")
45
	private String webApiScheme;
46
 
24078 amit.gupta 47
	@Value("${web.api.root}")
48
	private String webApiRoot;
49
 
23379 ashik.ali 50
	@Value("${web.api.port}")
51
	private int webApiPort;
21615 kshitij.so 52
 
24077 amit.gupta 53
 
22481 ashik.ali 54
	@Autowired
22927 ashik.ali 55
	private CookiesProcessor cookiesProcessor;
23923 amit.gupta 56
 
23568 govind 57
	@Autowired
23786 amit.gupta 58
	private RoleManager roleManager;
23923 amit.gupta 59
 
23838 ashik.ali 60
	@Autowired
61
	private FofoStoreRepository fofoStoreRepository;
23884 amit.gupta 62
 
63
	@Autowired
64
	private WalletService walletService;
23923 amit.gupta 65
 
23884 amit.gupta 66
	@Autowired
67
	private InventoryService inventoryService;
24121 govind 68
 
69
	@Autowired
70
	private TargetSlabService targetSlabService;
23923 amit.gupta 71
 
23884 amit.gupta 72
	@Autowired
73
	private OrderRepository orderRepository;
23951 amit.gupta 74
 
75
	@Autowired
76
	private PurchaseReturnItemRepository purchaseReturnItemRepository;
24098 tejbeer 77
 
23923 amit.gupta 78
	/*
79
	 * @Autowired private ScanRepository scanRepository;
80
	 */
81
 
23884 amit.gupta 82
	@Autowired
83
	private TransactionService transactionService;
24098 tejbeer 84
 
85
	@Autowired
86
	private NotificationPanelRepository notificationPanelRepository;
23923 amit.gupta 87
 
23568 govind 88
	private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
23923 amit.gupta 89
 
21615 kshitij.so 90
	@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
24098 tejbeer 91
	public String dashboard(HttpServletRequest request,@RequestParam(name = "offset", defaultValue = "0") int offset,
92
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
23923 amit.gupta 93
			throws ProfitMandiBusinessException, URISyntaxException, IOException {
94
		// LOGGER.info("scanRepository.selectScansByInventoryItemId(1)",
95
		// scanRepository.selectScansByInventoryItemId(1));
23884 amit.gupta 96
		LOGGER.info("In Dashboard");
22927 ashik.ali 97
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23923 amit.gupta 98
 
22481 ashik.ali 99
		FofoStore fofoStore = null;
100
		try {
22927 ashik.ali 101
			fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
22481 ashik.ali 102
		} catch (ProfitMandiBusinessException e) {
22927 ashik.ali 103
			LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
22481 ashik.ali 104
		}
23884 amit.gupta 105
 
23923 amit.gupta 106
		float walletAmount = 0;
107
		float inStockAmount = 0;
108
		float unbilledStockAmount = 0;
109
		float grnPendingStockAmount = 0;
110
		float shortPercentage = 100;
111
		float totalInvestedAmount = 0;
23936 tejbeer 112
		float minimumInvestment = 0;
23951 amit.gupta 113
		float returnedStockInTransit=0;
24121 govind 114
		double sale=0;
23923 amit.gupta 115
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
116
			model.addAttribute("showAlert", false);
117
		} else if (roleManager.isPartner(loginDetails.getRoleIds())) {
118
			walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
119
			inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
24121 govind 120
			sale=targetSlabService.getSaleValueforFoFoId(loginDetails.getFofoId(), LocalDateTime.of(LocalDateTime.now().getYear(), LocalDateTime.now().getMonthValue(),01, 00, 00), LocalDateTime.now()).get(loginDetails.getFofoId());
121
 
23884 amit.gupta 122
			List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
23923 amit.gupta 123
			for (Order unBilledOrder : unbilledOrders) {
23884 amit.gupta 124
				unbilledStockAmount += unBilledOrder.getTotalAmount();
125
			}
126
 
23904 amit.gupta 127
			List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(loginDetails.getFofoId());
23923 amit.gupta 128
			for (Order grnPendingOrder : grnPendingOrders) {
23884 amit.gupta 129
				grnPendingStockAmount += grnPendingOrder.getTotalAmount();
130
			}
23923 amit.gupta 131
			totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
132
			shortPercentage = ((fofoStore.getMinimumInvestment() - totalInvestedAmount)
133
					/ fofoStore.getMinimumInvestment()) * 100;
23944 amit.gupta 134
			model.addAttribute("showAlert", shortPercentage > 10);
23936 tejbeer 135
			minimumInvestment = fofoStore.getMinimumInvestment();
23951 amit.gupta 136
 
137
			//debitNoteRepository.se
23884 amit.gupta 138
		}
24121 govind 139
		model.addAttribute("sale", sale);
23923 amit.gupta 140
		model.addAttribute("walletAmount", walletAmount);
141
		model.addAttribute("inStockAmount", inStockAmount);
142
		model.addAttribute("unbilledStockAmount", unbilledStockAmount);
143
		model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);
144
		model.addAttribute("shortPercentage", shortPercentage);
145
		model.addAttribute("totalInvestedAmount", totalInvestedAmount);
23936 tejbeer 146
		model.addAttribute("minimumInvestmentAmount", minimumInvestment);
23951 amit.gupta 147
		model.addAttribute("returnedStockInTransit", returnedStockInTransit);
23923 amit.gupta 148
 
23848 ashik.ali 149
		model.addAttribute("fofoStore", fofoStore);
23918 amit.gupta 150
		model.addAttribute("walletAmount");
22086 amit.gupta 151
		model.addAttribute("appContextPath", request.getContextPath());
23796 amit.gupta 152
		model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
23379 ashik.ali 153
		model.addAttribute("webApiHost", webApiHost);
154
		model.addAttribute("webApiPort", webApiPort);
24072 amit.gupta 155
		model.addAttribute("webApiScheme", webApiScheme);
24077 amit.gupta 156
		model.addAttribute("webApiRoot", webApiRoot);
24098 tejbeer 157
 
158
		List<NotificationData> notificationData = null;
159
		long size = 0;
160
 
161
		notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
162
		size = notificationPanelRepository.selectAllCount();
163
		LOGGER.info("notification_data {}", notificationData);
164
 
165
		LOGGER.info("notification_data {}",size);
166
 
167
 
168
		if (!notificationData.isEmpty()) {
169
 
170
			model.addAttribute("notificationData",notificationData);
171
			LOGGER.info("notificationdata", notificationData);
172
			model.addAttribute("start", offset + 1);
173
			model.addAttribute("size", size);
174
			model.addAttribute("url", "/getPaginatedNotificationData");
175
 
176
			LOGGER.info("start {}",offset+1);
177
			LOGGER.info("SIZE {}",size);
178
 
179
 
180
 
181
			if (notificationData.size() < limit) {
182
				model.addAttribute("end", offset + notificationData.size());
183
				LOGGER.info("SIZE2 {}", offset + notificationData.size());
184
			} else {
185
				model.addAttribute("end", offset + limit);
186
 
187
				LOGGER.info("end {}",size);
188
 
189
 
190
			}
191
 
192
 
193
		} else {
194
 
195
			model.addAttribute("notificationData", notificationData);
196
			model.addAttribute("size", size);
197
			LOGGER.info("sizeOriginal {}",size);
198
 
199
		}
23923 amit.gupta 200
		// LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
201
		// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
21615 kshitij.so 202
		return "dashboard";
203
	}
23923 amit.gupta 204
 
24098 tejbeer 205
 
206
	@RequestMapping(value = "/getPaginatedNotificationData", method = RequestMethod.GET)
207
	public String getPaginatedNotificationData(HttpServletRequest request,
208
			@RequestParam(name = "offset", defaultValue = "0") int offset,
209
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
210
		List<NotificationData> notificationData = null;
211
 
212
		notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
213
 
214
		LOGGER.info("notification_data {}", notificationData);
215
 
216
 
217
		if (!notificationData.isEmpty()) {
218
 
219
			model.addAttribute("notificationData",notificationData);
220
			model.addAttribute("url", "/getPaginatedNotificationData");
221
 
222
		} else {
223
			model.addAttribute("notificationData", notificationData);
224
 
225
		}
226
 
227
		return "dashboard-paginated";
228
	}
22354 ashik.ali 229
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
23923 amit.gupta 230
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
22354 ashik.ali 231
		model.addAttribute("appContextPath", request.getContextPath());
232
		return "contact-us";
233
	}
23923 amit.gupta 234
 
235
	/*
236
	 * private List<PaymentOption> getPaymentOptions(int fofoId){ List<Integer>
237
	 * paymentOptionIds =
238
	 * fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
239
	 * if(paymentOptionIds.isEmpty()){ return new ArrayList<>(); } return
240
	 * paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds)); }
241
	 */
242
 
21615 kshitij.so 243
}