Subversion Repositories SmartDukaan

Rev

Rev 24203 | Rev 24263 | 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;
24248 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;
24203 amit.gupta 22
import com.spice.profitmandi.common.model.ProfitMandiConstants;
24098 tejbeer 23
import com.spice.profitmandi.dao.entity.dtr.NotificationData;
24203 amit.gupta 24
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
22654 ashik.ali 25
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
23884 amit.gupta 26
import com.spice.profitmandi.dao.entity.transaction.Order;
22481 ashik.ali 27
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
24098 tejbeer 28
import com.spice.profitmandi.dao.repository.dtr.NotificationPanelRepository;
24203 amit.gupta 29
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
24248 govind 30
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
23951 amit.gupta 31
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
23884 amit.gupta 32
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
23844 amit.gupta 33
import com.spice.profitmandi.service.authentication.RoleManager;
23884 amit.gupta 34
import com.spice.profitmandi.service.inventory.InventoryService;
24121 govind 35
import com.spice.profitmandi.service.slab.TargetSlabService;
23884 amit.gupta 36
import com.spice.profitmandi.service.transaction.TransactionService;
37
import com.spice.profitmandi.service.wallet.WalletService;
22481 ashik.ali 38
import com.spice.profitmandi.web.model.LoginDetails;
39
import com.spice.profitmandi.web.util.CookiesProcessor;
40
 
21615 kshitij.so 41
@Controller
22481 ashik.ali 42
@Transactional(rollbackFor = Throwable.class)
21615 kshitij.so 43
public class DashboardController {
23923 amit.gupta 44
 
23379 ashik.ali 45
	@Value("${web.api.host}")
46
	private String webApiHost;
23923 amit.gupta 47
 
24072 amit.gupta 48
	@Value("${web.api.scheme}")
49
	private String webApiScheme;
50
 
24078 amit.gupta 51
	@Value("${web.api.root}")
52
	private String webApiRoot;
53
 
23379 ashik.ali 54
	@Value("${web.api.port}")
55
	private int webApiPort;
21615 kshitij.so 56
 
24077 amit.gupta 57
 
22481 ashik.ali 58
	@Autowired
22927 ashik.ali 59
	private CookiesProcessor cookiesProcessor;
23923 amit.gupta 60
 
23568 govind 61
	@Autowired
23786 amit.gupta 62
	private RoleManager roleManager;
23923 amit.gupta 63
 
23838 ashik.ali 64
	@Autowired
65
	private FofoStoreRepository fofoStoreRepository;
23884 amit.gupta 66
 
67
	@Autowired
68
	private WalletService walletService;
23923 amit.gupta 69
 
23884 amit.gupta 70
	@Autowired
71
	private InventoryService inventoryService;
24121 govind 72
 
23923 amit.gupta 73
 
23884 amit.gupta 74
	@Autowired
75
	private OrderRepository orderRepository;
23951 amit.gupta 76
 
77
	@Autowired
24248 govind 78
	private FofoOrderRepository fofoOrderRepository;
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;
24248 govind 118
		float returnedStockInTransit = 0;
24121 govind 119
		double sale=0;
23923 amit.gupta 120
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
121
			model.addAttribute("showAlert", false);
24248 govind 122
			model.addAttribute("sale",sale);
23923 amit.gupta 123
		} else if (roleManager.isPartner(loginDetails.getRoleIds())) {
124
			walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
125
			inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
24248 govind 126
			sale=fofoOrderRepository.selectTotalSaleSumByFofoIdBrtweenDate(loginDetails.getFofoId(), LocalDateTime.of(LocalDateTime.now().getYear(), LocalDateTime.now().getMonth(),01, 00, 00), LocalDateTime.now());
127
 
23884 amit.gupta 128
			List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
23923 amit.gupta 129
			for (Order unBilledOrder : unbilledOrders) {
23884 amit.gupta 130
				unbilledStockAmount += unBilledOrder.getTotalAmount();
131
			}
132
 
23904 amit.gupta 133
			List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(loginDetails.getFofoId());
23923 amit.gupta 134
			for (Order grnPendingOrder : grnPendingOrders) {
23884 amit.gupta 135
				grnPendingStockAmount += grnPendingOrder.getTotalAmount();
136
			}
23923 amit.gupta 137
			totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
138
			shortPercentage = ((fofoStore.getMinimumInvestment() - totalInvestedAmount)
139
					/ fofoStore.getMinimumInvestment()) * 100;
23944 amit.gupta 140
			model.addAttribute("showAlert", shortPercentage > 10);
23936 tejbeer 141
			minimumInvestment = fofoStore.getMinimumInvestment();
23951 amit.gupta 142
 
143
			//debitNoteRepository.se
23884 amit.gupta 144
		}
23923 amit.gupta 145
		model.addAttribute("walletAmount", walletAmount);
146
		model.addAttribute("inStockAmount", inStockAmount);
147
		model.addAttribute("unbilledStockAmount", unbilledStockAmount);
148
		model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);
149
		model.addAttribute("shortPercentage", shortPercentage);
150
		model.addAttribute("totalInvestedAmount", totalInvestedAmount);
23936 tejbeer 151
		model.addAttribute("minimumInvestmentAmount", minimumInvestment);
23951 amit.gupta 152
		model.addAttribute("returnedStockInTransit", returnedStockInTransit);
23923 amit.gupta 153
 
23848 ashik.ali 154
		model.addAttribute("fofoStore", fofoStore);
23918 amit.gupta 155
		model.addAttribute("walletAmount");
22086 amit.gupta 156
		model.addAttribute("appContextPath", request.getContextPath());
23796 amit.gupta 157
		model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
23379 ashik.ali 158
		model.addAttribute("webApiHost", webApiHost);
159
		model.addAttribute("webApiPort", webApiPort);
24072 amit.gupta 160
		model.addAttribute("webApiScheme", webApiScheme);
24077 amit.gupta 161
		model.addAttribute("webApiRoot", webApiRoot);
24203 amit.gupta 162
		model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
163
		model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
24248 govind 164
		model.addAttribute("sale", sale);
24098 tejbeer 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
 
203
			model.addAttribute("notificationData", notificationData);
204
			model.addAttribute("size", size);
205
			LOGGER.info("sizeOriginal {}",size);
206
 
207
		}
23923 amit.gupta 208
		// LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
209
		// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
21615 kshitij.so 210
		return "dashboard";
211
	}
23923 amit.gupta 212
 
24203 amit.gupta 213
	//This method is currently hardcoded to faciliate watches sold as gift.
214
	private boolean hasGift(int fofoId) {
215
		try {
216
			return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId).getAvailability() > 0;
217
		} catch (ProfitMandiBusinessException e) {
218
			return false;
219
		}
220
	}
24098 tejbeer 221
	@RequestMapping(value = "/getPaginatedNotificationData", method = RequestMethod.GET)
222
	public String getPaginatedNotificationData(HttpServletRequest request,
223
			@RequestParam(name = "offset", defaultValue = "0") int offset,
224
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
225
		List<NotificationData> notificationData = null;
226
 
227
		notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
228
 
229
		LOGGER.info("notification_data {}", notificationData);
230
 
231
 
232
		if (!notificationData.isEmpty()) {
233
 
234
			model.addAttribute("notificationData",notificationData);
235
			model.addAttribute("url", "/getPaginatedNotificationData");
236
 
237
		} else {
238
			model.addAttribute("notificationData", notificationData);
239
 
240
		}
241
 
242
		return "dashboard-paginated";
243
	}
22354 ashik.ali 244
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
23923 amit.gupta 245
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
22354 ashik.ali 246
		model.addAttribute("appContextPath", request.getContextPath());
247
		return "contact-us";
248
	}
23923 amit.gupta 249
 
250
	/*
251
	 * private List<PaymentOption> getPaymentOptions(int fofoId){ List<Integer>
252
	 * paymentOptionIds =
253
	 * fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
254
	 * if(paymentOptionIds.isEmpty()){ return new ArrayList<>(); } return
255
	 * paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds)); }
256
	 */
257
 
21615 kshitij.so 258
}