Subversion Repositories SmartDukaan

Rev

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

Rev 25067 Rev 25140
Line 30... Line 30...
30
import org.springframework.beans.factory.annotation.Qualifier;
30
import org.springframework.beans.factory.annotation.Qualifier;
31
import org.springframework.beans.factory.annotation.Value;
31
import org.springframework.beans.factory.annotation.Value;
32
import org.springframework.core.io.InputStreamResource;
32
import org.springframework.core.io.InputStreamResource;
33
import org.springframework.http.HttpHeaders;
33
import org.springframework.http.HttpHeaders;
34
import org.springframework.http.HttpStatus;
34
import org.springframework.http.HttpStatus;
-
 
35
import org.springframework.http.MediaType;
35
import org.springframework.http.ResponseEntity;
36
import org.springframework.http.ResponseEntity;
36
import org.springframework.mail.javamail.JavaMailSender;
37
import org.springframework.mail.javamail.JavaMailSender;
37
import org.springframework.mail.javamail.MimeMessageHelper;
38
import org.springframework.mail.javamail.MimeMessageHelper;
38
import org.springframework.stereotype.Controller;
39
import org.springframework.stereotype.Controller;
39
import org.springframework.transaction.annotation.Transactional;
40
import org.springframework.transaction.annotation.Transactional;
Line 42... Line 43...
42
import org.springframework.web.bind.annotation.RequestMapping;
43
import org.springframework.web.bind.annotation.RequestMapping;
43
import org.springframework.web.bind.annotation.RequestMethod;
44
import org.springframework.web.bind.annotation.RequestMethod;
44
import org.springframework.web.bind.annotation.RequestParam;
45
import org.springframework.web.bind.annotation.RequestParam;
45
 
46
 
46
import com.google.gson.Gson;
47
import com.google.gson.Gson;
-
 
48
import com.spice.profitmandi.common.enumuration.SearchType;
47
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
49
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
48
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
50
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
49
import com.spice.profitmandi.common.model.CustomRetailer;
51
import com.spice.profitmandi.common.model.CustomRetailer;
50
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
52
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
51
import com.spice.profitmandi.common.model.ItemFeatureDataModel;
53
import com.spice.profitmandi.common.model.ItemFeatureDataModel;
52
import com.spice.profitmandi.common.model.NotifyItemIdModel;
54
import com.spice.profitmandi.common.model.NotifyItemIdModel;
53
import com.spice.profitmandi.common.model.NotifyOrderIdModel;
55
import com.spice.profitmandi.common.model.NotifyOrderIdModel;
54
import com.spice.profitmandi.common.model.NotifyOrderModel;
56
import com.spice.profitmandi.common.model.NotifyOrderModel;
-
 
57
import com.spice.profitmandi.common.model.PdfModel;
55
import com.spice.profitmandi.common.model.ProfitMandiConstants;
58
import com.spice.profitmandi.common.model.ProfitMandiConstants;
56
import com.spice.profitmandi.common.util.ExcelUtils;
59
import com.spice.profitmandi.common.util.ExcelUtils;
-
 
60
import com.spice.profitmandi.common.util.PdfUtils;
57
import com.spice.profitmandi.common.util.Utils;
61
import com.spice.profitmandi.common.util.Utils;
58
import com.spice.profitmandi.dao.entity.catalog.Item;
62
import com.spice.profitmandi.dao.entity.catalog.Item;
59
import com.spice.profitmandi.dao.entity.catalog.TagListing;
63
import com.spice.profitmandi.dao.entity.catalog.TagListing;
60
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
64
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
61
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
65
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
-
 
66
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
62
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
67
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
63
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
68
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
64
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
69
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
65
import com.spice.profitmandi.dao.entity.transaction.NotifyColorChange;
70
import com.spice.profitmandi.dao.entity.transaction.NotifyColorChange;
66
import com.spice.profitmandi.dao.entity.transaction.NotifyItem;
71
import com.spice.profitmandi.dao.entity.transaction.NotifyItem;
Line 306... Line 311...
306
				limit, purchaseReference, searchType);
311
				limit, purchaseReference, searchType);
307
		model.addAllAttributes(map);
312
		model.addAllAttributes(map);
308
		return "grn-history";
313
		return "grn-history";
309
	}
314
	}
310
 
315
 
-
 
316
	@RequestMapping(value = "/downloadPurchaseInvoices")
-
 
317
	public ResponseEntity<?> downloadPurchaseInvoices(HttpServletRequest request,
-
 
318
			@RequestParam(required = false) LocalDateTime startTime,
-
 
319
			@RequestParam(required = false) LocalDateTime endTime,
-
 
320
			@RequestParam(name = "offset", defaultValue = "0") int offset,
-
 
321
			@RequestParam(name = "limit", defaultValue = "10") int limit,
-
 
322
			@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
-
 
323
			@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
-
 
324
			throws ProfitMandiBusinessException {
-
 
325
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
326
		Map<String, Object> map = inventoryService.getGrnHistory(loginDetails.getFofoId(), startTime, endTime, offset,
-
 
327
				limit, purchaseReference, searchType);
-
 
328
 
-
 
329
		List<FofoOrder> fofoOrders = (List<FofoOrder>) map.get("saleHistories");
-
 
330
 
-
 
331
		if (fofoOrders.size() == 0) {
-
 
332
			throw new ProfitMandiBusinessException("Search criteria", "", "No orders found for criteria");
-
 
333
		}
-
 
334
 
-
 
335
		final HttpHeaders headers = new HttpHeaders();
-
 
336
		headers.setContentType(MediaType.APPLICATION_PDF);
-
 
337
		headers.set("Content-disposition", "inline; filename=invoices.pdf");
-
 
338
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-
 
339
		List<PdfModel> pdfModels = new ArrayList<>();
-
 
340
		/*for (FofoOrder fofoOrder : fofoOrders) {
-
 
341
			try {
-
 
342
				pdfModels.add(orderService.getInvoicePdfModel(fofoOrder.getId()));
-
 
343
			} catch (Exception e) {
-
 
344
				LOGGER.info("could not create invoice for {}, invoice number {}", fofoOrder.getId(),
-
 
345
						fofoOrder.getInvoiceNumber());
-
 
346
			}
-
 
347
		}*/
-
 
348
		PdfUtils.generateAndWrite(pdfModels, byteArrayOutputStream);
-
 
349
		headers.setContentLength(byteArrayOutputStream.toByteArray().length);
-
 
350
		final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
-
 
351
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
-
 
352
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
-
 
353
	}
-
 
354
 
311
	@RequestMapping(value = "/getPaginatedGrnHistory")
355
	@RequestMapping(value = "/getPaginatedGrnHistory")
312
	public String getPaginatedGrnHistory(HttpServletRequest request,
356
	public String getPaginatedGrnHistory(HttpServletRequest request,
313
			@RequestParam(required = false) LocalDateTime startTime,
357
			@RequestParam(required = false) LocalDateTime startTime,
314
			@RequestParam(required = false) LocalDateTime endTime,
358
			@RequestParam(required = false) LocalDateTime endTime,
315
			@RequestParam(name = "offset", defaultValue = "0") int offset,
359
			@RequestParam(name = "offset", defaultValue = "0") int offset,
Line 610... Line 654...
610
 
654
 
611
	@RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
655
	@RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
612
	public String cancelOrder(HttpServletRequest request, @RequestParam int orderId, @RequestParam String reason,
656
	public String cancelOrder(HttpServletRequest request, @RequestParam int orderId, @RequestParam String reason,
613
			@RequestParam OrderStatus orderStatus, Model model) throws Exception {
657
			@RequestParam OrderStatus orderStatus, Model model) throws Exception {
614
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
658
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
615
		//User userInfo = saholicUserRepository.selectById(loginDetails.getFofoId());
659
		// User userInfo = saholicUserRepository.selectById(loginDetails.getFofoId());
616
		LOGGER.info("status" + orderStatus);
660
		LOGGER.info("status" + orderStatus);
617
		try {
661
		try {
618
			Order order = orderRepository.selectById(orderId);
662
			Order order = orderRepository.selectById(orderId);
619
			orderRepository.refundOrder(orderId, loginDetails.getEmailId(), reason, orderStatus);
663
			orderRepository.refundOrder(orderId, loginDetails.getEmailId(), reason, orderStatus);
620
			
664
			
Line 631... Line 675...
631
	private void sendCancellationNotificationToPartner(Order order, String reason) throws Exception {
675
	private void sendCancellationNotificationToPartner(Order order, String reason) throws Exception {
632
		Item item = itemRepository.selectById(order.getLineItem().getItemId());
676
		Item item = itemRepository.selectById(order.getLineItem().getItemId());
633
		NotificationCampaigns notification = new NotificationCampaigns();
677
		NotificationCampaigns notification = new NotificationCampaigns();
634
		notification.setName("Order Cancellation");
678
		notification.setName("Order Cancellation");
635
 
679
 
636
		notification.setTitle(String.format("Order %s %d(Pcs) cancelled", item.getItemDescription(), order.getLineItem().getQuantity()));
680
		notification.setTitle(String.format("Order %s %d(Pcs) cancelled", item.getItemDescription(),
-
 
681
				order.getLineItem().getQuantity()));
637
		
682
 
638
		notification.setMessage(reason);
683
		notification.setMessage(reason);
639
		notification.setType("url");
684
		notification.setType("url");
640
		notification.setUrl("http://app.profitmandi.com/pages/home/notifications");
685
		notification.setUrl("http://app.profitmandi.com/pages/home/notifications");
641
 
686
 
642
		notification.setSql("SELECT distinct d1.user_id from devices d1 left join devices d2 on"
687
		notification.setSql("SELECT distinct d1.user_id from devices d1 left join devices d2 on"
Line 647... Line 692...
647
		notification.setStatus("active");
692
		notification.setStatus("active");
648
		notification.setSmsprocessed(0);
693
		notification.setSmsprocessed(0);
649
		notification.setNotification_processed(0);
694
		notification.setNotification_processed(0);
650
		notification.setNotification_type("GENERAL_NOTIFICATION");
695
		notification.setNotification_type("GENERAL_NOTIFICATION");
651
		mongoClient.persistNotificationCmpInfo(notification);
696
		mongoClient.persistNotificationCmpInfo(notification);
652
		
697
 
653
	}
698
	}
654
 
699
 
655
	@RequestMapping(value = "/getNotifyItemColor", method = RequestMethod.GET)
700
	@RequestMapping(value = "/getNotifyItemColor", method = RequestMethod.GET)
656
	public String getNotifyItemColor(HttpServletRequest request, @RequestParam int catalogItemId,
701
	public String getNotifyItemColor(HttpServletRequest request, @RequestParam int catalogItemId,
657
			@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
702
			@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
Line 704... Line 749...
704
		notifytimestamp.setCreated(LocalDateTime.now());
749
		notifytimestamp.setCreated(LocalDateTime.now());
705
		notifyColorChangeRepository.persist(notifytimestamp);
750
		notifyColorChangeRepository.persist(notifytimestamp);
706
		NotifyMessage notifyMessage = new NotifyMessage();
751
		NotifyMessage notifyMessage = new NotifyMessage();
707
		notifyMessage.setNotifyId(notifytimestamp.getId());
752
		notifyMessage.setNotifyId(notifytimestamp.getId());
708
		notifyMessage.setNotifyMessages(notifyOrderModel.getMessage());
753
		notifyMessage.setNotifyMessages(notifyOrderModel.getMessage());
709
        notifyMessageRepository.persist(notifyMessage);
754
		notifyMessageRepository.persist(notifyMessage);
710
		for (NotifyItemIdModel itemid : notifyOrderModel.getItemIds()) {
755
		for (NotifyItemIdModel itemid : notifyOrderModel.getItemIds()) {
711
 
756
 
712
			notifyItem = new com.spice.profitmandi.dao.entity.transaction.NotifyItem();
757
			notifyItem = new com.spice.profitmandi.dao.entity.transaction.NotifyItem();
713
			notifyItem.setItemId(itemid.getItemId());
758
			notifyItem.setItemId(itemid.getItemId());
714
			notifyItem.setResponseTime(itemid.getResponseTime());
759
			notifyItem.setResponseTime(itemid.getResponseTime());
Line 742... Line 787...
742
 
787
 
743
		LOGGER.info("orderIds" + orderIds);
788
		LOGGER.info("orderIds" + orderIds);
744
		List<Order> orders = orderRepository.selectByOrderIds(orderIds);
789
		List<Order> orders = orderRepository.selectByOrderIds(orderIds);
745
		for (Order order : orders) {
790
		for (Order order : orders) {
746
			LOGGER.info("order" + order.getId());
791
			LOGGER.info("order" + order.getId());
747
			
-
 
748
			 NotifyMessage message = notifyMessageRepository.selectByNotifyId(notifytimestamp.getId());
-
 
749
 
792
 
-
 
793
			NotifyMessage message = notifyMessageRepository.selectByNotifyId(notifytimestamp.getId());
-
 
794
 
750
			//LOGGER.info("message112" + message.getNotifyMessages());
795
			// LOGGER.info("message112" + message.getNotifyMessages());
751
                      
-
 
-
 
796
 
752
			NotificationCampaigns notification = new NotificationCampaigns();
797
			NotificationCampaigns notification = new NotificationCampaigns();
753
			notification.setName("Notify Partner");
798
			notification.setName("Notify Partner");
754
 
799
 
755
			notification.setTitle("Notify Partner");
800
			notification.setTitle("Notify Partner");
756
 
801