Subversion Repositories SmartDukaan

Rev

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