Subversion Repositories SmartDukaan

Rev

Rev 24121 | Rev 24203 | 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
 
23884 amit.gupta 121
			List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
23923 amit.gupta 122
			for (Order unBilledOrder : unbilledOrders) {
23884 amit.gupta 123
				unbilledStockAmount += unBilledOrder.getTotalAmount();
124
			}
125
 
23904 amit.gupta 126
			List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(loginDetails.getFofoId());
23923 amit.gupta 127
			for (Order grnPendingOrder : grnPendingOrders) {
23884 amit.gupta 128
				grnPendingStockAmount += grnPendingOrder.getTotalAmount();
129
			}
23923 amit.gupta 130
			totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
131
			shortPercentage = ((fofoStore.getMinimumInvestment() - totalInvestedAmount)
132
					/ fofoStore.getMinimumInvestment()) * 100;
23944 amit.gupta 133
			model.addAttribute("showAlert", shortPercentage > 10);
23936 tejbeer 134
			minimumInvestment = fofoStore.getMinimumInvestment();
23951 amit.gupta 135
 
136
			//debitNoteRepository.se
23884 amit.gupta 137
		}
24121 govind 138
		model.addAttribute("sale", sale);
23923 amit.gupta 139
		model.addAttribute("walletAmount", walletAmount);
140
		model.addAttribute("inStockAmount", inStockAmount);
141
		model.addAttribute("unbilledStockAmount", unbilledStockAmount);
142
		model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);
143
		model.addAttribute("shortPercentage", shortPercentage);
144
		model.addAttribute("totalInvestedAmount", totalInvestedAmount);
23936 tejbeer 145
		model.addAttribute("minimumInvestmentAmount", minimumInvestment);
23951 amit.gupta 146
		model.addAttribute("returnedStockInTransit", returnedStockInTransit);
23923 amit.gupta 147
 
23848 ashik.ali 148
		model.addAttribute("fofoStore", fofoStore);
23918 amit.gupta 149
		model.addAttribute("walletAmount");
22086 amit.gupta 150
		model.addAttribute("appContextPath", request.getContextPath());
23796 amit.gupta 151
		model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
23379 ashik.ali 152
		model.addAttribute("webApiHost", webApiHost);
153
		model.addAttribute("webApiPort", webApiPort);
24072 amit.gupta 154
		model.addAttribute("webApiScheme", webApiScheme);
24077 amit.gupta 155
		model.addAttribute("webApiRoot", webApiRoot);
24098 tejbeer 156
 
157
		List<NotificationData> notificationData = null;
158
		long size = 0;
159
 
160
		notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
161
		size = notificationPanelRepository.selectAllCount();
162
		LOGGER.info("notification_data {}", notificationData);
163
 
164
		LOGGER.info("notification_data {}",size);
165
 
166
 
167
		if (!notificationData.isEmpty()) {
168
 
169
			model.addAttribute("notificationData",notificationData);
170
			LOGGER.info("notificationdata", notificationData);
171
			model.addAttribute("start", offset + 1);
172
			model.addAttribute("size", size);
173
			model.addAttribute("url", "/getPaginatedNotificationData");
174
 
175
			LOGGER.info("start {}",offset+1);
176
			LOGGER.info("SIZE {}",size);
177
 
178
 
179
 
180
			if (notificationData.size() < limit) {
181
				model.addAttribute("end", offset + notificationData.size());
182
				LOGGER.info("SIZE2 {}", offset + notificationData.size());
183
			} else {
184
				model.addAttribute("end", offset + limit);
185
 
186
				LOGGER.info("end {}",size);
187
 
188
 
189
			}
190
 
191
 
192
		} else {
193
 
194
			model.addAttribute("notificationData", notificationData);
195
			model.addAttribute("size", size);
196
			LOGGER.info("sizeOriginal {}",size);
197
 
198
		}
23923 amit.gupta 199
		// LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
200
		// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
21615 kshitij.so 201
		return "dashboard";
202
	}
23923 amit.gupta 203
 
24098 tejbeer 204
 
205
	@RequestMapping(value = "/getPaginatedNotificationData", method = RequestMethod.GET)
206
	public String getPaginatedNotificationData(HttpServletRequest request,
207
			@RequestParam(name = "offset", defaultValue = "0") int offset,
208
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
209
		List<NotificationData> notificationData = null;
210
 
211
		notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
212
 
213
		LOGGER.info("notification_data {}", notificationData);
214
 
215
 
216
		if (!notificationData.isEmpty()) {
217
 
218
			model.addAttribute("notificationData",notificationData);
219
			model.addAttribute("url", "/getPaginatedNotificationData");
220
 
221
		} else {
222
			model.addAttribute("notificationData", notificationData);
223
 
224
		}
225
 
226
		return "dashboard-paginated";
227
	}
22354 ashik.ali 228
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
23923 amit.gupta 229
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
22354 ashik.ali 230
		model.addAttribute("appContextPath", request.getContextPath());
231
		return "contact-us";
232
	}
23923 amit.gupta 233
 
234
	/*
235
	 * private List<PaymentOption> getPaymentOptions(int fofoId){ List<Integer>
236
	 * paymentOptionIds =
237
	 * fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
238
	 * if(paymentOptionIds.isEmpty()){ return new ArrayList<>(); } return
239
	 * paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds)); }
240
	 */
241
 
21615 kshitij.so 242
}