Subversion Repositories SmartDukaan

Rev

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

Rev 30244 Rev 30323
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.ByteArrayInputStream;
-
 
4
import java.io.ByteArrayOutputStream;
-
 
5
import java.io.IOException;
-
 
6
import java.io.InputStream;
-
 
7
import java.io.InputStreamReader;
-
 
8
import java.net.URISyntaxException;
-
 
9
import java.time.LocalDate;
-
 
10
import java.time.LocalDateTime;
-
 
11
import java.time.YearMonth;
-
 
12
import java.time.format.DateTimeFormatter;
-
 
13
import java.time.temporal.ChronoUnit;
-
 
14
import java.util.ArrayList;
-
 
15
import java.util.Arrays;
-
 
16
import java.util.Collection;
-
 
17
import java.util.Comparator;
-
 
18
import java.util.HashMap;
-
 
19
import java.util.HashSet;
-
 
20
import java.util.Iterator;
-
 
21
import java.util.List;
-
 
22
import java.util.Map;
-
 
23
import java.util.Optional;
-
 
24
import java.util.Set;
-
 
25
import java.util.stream.Collectors;
-
 
26
import java.util.stream.Stream;
-
 
27
 
-
 
28
import javax.servlet.http.HttpServletRequest;
-
 
29
import javax.servlet.http.HttpServletResponse;
-
 
30
 
-
 
31
import org.apache.commons.csv.CSVFormat;
-
 
32
import org.apache.commons.csv.CSVParser;
-
 
33
import org.apache.commons.csv.CSVRecord;
-
 
34
import org.apache.commons.io.FileUtils;
-
 
35
import org.apache.commons.lang3.StringUtils;
-
 
36
import org.apache.logging.log4j.LogManager;
-
 
37
import org.apache.logging.log4j.Logger;
-
 
38
import org.apache.thrift.TException;
-
 
39
import org.json.JSONObject;
-
 
40
import org.springframework.beans.factory.annotation.Autowired;
-
 
41
import org.springframework.beans.factory.annotation.Qualifier;
-
 
42
import org.springframework.beans.factory.annotation.Value;
-
 
43
import org.springframework.core.io.ByteArrayResource;
-
 
44
import org.springframework.core.io.ClassPathResource;
-
 
45
import org.springframework.core.io.InputStreamResource;
-
 
46
import org.springframework.http.HttpHeaders;
-
 
47
import org.springframework.http.HttpStatus;
-
 
48
import org.springframework.http.MediaType;
-
 
49
import org.springframework.http.ResponseEntity;
-
 
50
import org.springframework.mail.javamail.JavaMailSender;
-
 
51
import org.springframework.stereotype.Controller;
-
 
52
import org.springframework.transaction.annotation.Transactional;
-
 
53
import org.springframework.ui.Model;
-
 
54
import org.springframework.web.bind.annotation.GetMapping;
-
 
55
import org.springframework.web.bind.annotation.PostMapping;
-
 
56
import org.springframework.web.bind.annotation.RequestBody;
-
 
57
import org.springframework.web.bind.annotation.RequestMapping;
-
 
58
import org.springframework.web.bind.annotation.RequestMethod;
-
 
59
import org.springframework.web.bind.annotation.RequestParam;
-
 
60
import org.springframework.web.bind.annotation.RequestPart;
-
 
61
import org.springframework.web.multipart.MultipartFile;
-
 
62
 
-
 
63
import com.fasterxml.jackson.databind.ObjectMapper;
3
import com.fasterxml.jackson.databind.ObjectMapper;
64
import com.google.gson.Gson;
4
import com.google.gson.Gson;
65
import com.spice.profitmandi.common.enumuration.MessageType;
5
import com.spice.profitmandi.common.enumuration.MessageType;
66
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
6
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
67
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
-
 
68
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
69
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
-
 
70
import com.spice.profitmandi.common.model.ItemFeatureDataModel;
-
 
71
import com.spice.profitmandi.common.model.NotifyItemIdModel;
-
 
72
import com.spice.profitmandi.common.model.NotifyOrderIdModel;
-
 
73
import com.spice.profitmandi.common.model.NotifyOrderModel;
-
 
74
import com.spice.profitmandi.common.model.OrderCancellationModel;
-
 
75
import com.spice.profitmandi.common.model.PdfModel;
7
import com.spice.profitmandi.common.model.*;
76
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
77
import com.spice.profitmandi.common.model.SendNotificationModel;
-
 
78
import com.spice.profitmandi.common.util.ExcelUtils;
8
import com.spice.profitmandi.common.util.ExcelUtils;
79
import com.spice.profitmandi.common.util.PdfUtils;
9
import com.spice.profitmandi.common.util.PdfUtils;
80
import com.spice.profitmandi.common.util.Utils;
10
import com.spice.profitmandi.common.util.Utils;
81
import com.spice.profitmandi.common.util.Utils.Attachment;
11
import com.spice.profitmandi.common.util.Utils.Attachment;
82
import com.spice.profitmandi.dao.entity.auth.AuthUser;
12
import com.spice.profitmandi.dao.entity.auth.AuthUser;
83
import com.spice.profitmandi.dao.entity.catalog.FocusedModelByPassRequest;
-
 
84
import com.spice.profitmandi.dao.entity.catalog.HighDemandItem;
-
 
85
import com.spice.profitmandi.dao.entity.catalog.Item;
13
import com.spice.profitmandi.dao.entity.catalog.*;
86
import com.spice.profitmandi.dao.entity.catalog.TagListing;
-
 
87
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
-
 
88
import com.spice.profitmandi.dao.entity.cs.Position;
14
import com.spice.profitmandi.dao.entity.cs.Position;
89
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
15
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
90
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
-
 
91
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
16
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
92
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
17
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
93
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
18
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
94
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
-
 
95
import com.spice.profitmandi.dao.entity.transaction.NotifyCancel;
-
 
96
import com.spice.profitmandi.dao.entity.transaction.NotifyColorChange;
-
 
97
import com.spice.profitmandi.dao.entity.transaction.NotifyMessage;
-
 
98
import com.spice.profitmandi.dao.entity.transaction.NotifyOrder;
-
 
99
import com.spice.profitmandi.dao.entity.transaction.Order;
19
import com.spice.profitmandi.dao.entity.transaction.*;
100
import com.spice.profitmandi.dao.enumuration.catalog.ByPassRequestStatus;
20
import com.spice.profitmandi.dao.enumuration.catalog.ByPassRequestStatus;
101
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
21
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
102
import com.spice.profitmandi.dao.model.BrandItemWiseTertiaryModel;
-
 
103
import com.spice.profitmandi.dao.model.BrandRegionModel;
-
 
104
import com.spice.profitmandi.dao.model.BrandWiseTertiaryModel;
-
 
105
import com.spice.profitmandi.dao.model.ContentPojo;
22
import com.spice.profitmandi.dao.model.*;
106
import com.spice.profitmandi.dao.model.OpenPoItemModel;
-
 
107
import com.spice.profitmandi.dao.model.OpenPoModel;
-
 
108
import com.spice.profitmandi.dao.model.OurPurchaseItemModel;
-
 
109
import com.spice.profitmandi.dao.model.OurPurchaseModel;
-
 
110
import com.spice.profitmandi.dao.model.SecondaeryOrderDateRange;
-
 
111
import com.spice.profitmandi.dao.model.SecondaryOrderBillingModel;
-
 
112
import com.spice.profitmandi.dao.model.SecondaryOrderItemBillingModel;
-
 
113
import com.spice.profitmandi.dao.model.SecondaryWarehouseWiseOrderBilllingModel;
-
 
114
import com.spice.profitmandi.dao.model.Specification;
-
 
115
import com.spice.profitmandi.dao.model.SpecificationGroup;
-
 
116
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
23
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
117
import com.spice.profitmandi.dao.repository.catalog.FocusedModelByPassRepository;
-
 
118
import com.spice.profitmandi.dao.repository.catalog.HighDemandItemsRepository;
-
 
119
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
24
import com.spice.profitmandi.dao.repository.catalog.*;
120
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
-
 
121
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
-
 
122
import com.spice.profitmandi.dao.repository.cs.CsService;
25
import com.spice.profitmandi.dao.repository.cs.CsService;
123
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
26
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
124
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
27
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
125
import com.spice.profitmandi.dao.repository.dtr.Mongo;
28
import com.spice.profitmandi.dao.repository.dtr.Mongo;
126
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
29
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
127
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
30
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
128
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
-
 
129
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
31
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
130
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
32
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
131
import com.spice.profitmandi.dao.repository.fofo.LiveDemoBillingRespository;
33
import com.spice.profitmandi.dao.repository.fofo.LiveDemoBillingRespository;
132
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
-
 
133
import com.spice.profitmandi.dao.repository.inventory.NotifyStatus;
34
import com.spice.profitmandi.dao.repository.inventory.NotifyStatus;
134
import com.spice.profitmandi.dao.repository.transaction.NotifyCancelOrderRepository;
-
 
135
import com.spice.profitmandi.dao.repository.transaction.NotifyColorChangeRepository;
-
 
136
import com.spice.profitmandi.dao.repository.transaction.NotifyItemRepository;
-
 
137
import com.spice.profitmandi.dao.repository.transaction.NotifyMessageRepository;
-
 
138
import com.spice.profitmandi.dao.repository.transaction.NotifyOrderRespository;
-
 
139
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
35
import com.spice.profitmandi.dao.repository.transaction.*;
140
import com.spice.profitmandi.dao.repository.warehouse.WarehousePurchaseOrderRepository;
36
import com.spice.profitmandi.dao.repository.warehouse.WarehousePurchaseOrderRepository;
141
import com.spice.profitmandi.dao.repository.warehouse.WarehouseScanRepository;
37
import com.spice.profitmandi.dao.repository.warehouse.WarehouseScanRepository;
142
import com.spice.profitmandi.service.NotificationService;
38
import com.spice.profitmandi.service.NotificationService;
143
import com.spice.profitmandi.service.inventory.InventoryService;
39
import com.spice.profitmandi.service.inventory.InventoryService;
144
import com.spice.profitmandi.service.order.OrderService;
40
import com.spice.profitmandi.service.order.OrderService;
145
import com.spice.profitmandi.service.user.RetailerService;
41
import com.spice.profitmandi.service.user.RetailerService;
146
import com.spice.profitmandi.web.model.LoginDetails;
42
import com.spice.profitmandi.web.model.LoginDetails;
147
import com.spice.profitmandi.web.util.CookiesProcessor;
43
import com.spice.profitmandi.web.util.CookiesProcessor;
148
import com.spice.profitmandi.web.util.MVCResponseSender;
44
import com.spice.profitmandi.web.util.MVCResponseSender;
149
 
-
 
150
import in.shop2020.model.v1.order.OrderStatus;
45
import in.shop2020.model.v1.order.OrderStatus;
151
import in.shop2020.model.v1.order.TransactionServiceException;
46
import in.shop2020.model.v1.order.TransactionServiceException;
-
 
47
import org.apache.commons.csv.CSVFormat;
-
 
48
import org.apache.commons.csv.CSVParser;
-
 
49
import org.apache.commons.csv.CSVRecord;
-
 
50
import org.apache.commons.io.FileUtils;
-
 
51
import org.apache.commons.lang3.StringUtils;
-
 
52
import org.apache.logging.log4j.LogManager;
-
 
53
import org.apache.logging.log4j.Logger;
-
 
54
import org.apache.thrift.TException;
-
 
55
import org.json.JSONObject;
-
 
56
import org.springframework.beans.factory.annotation.Autowired;
-
 
57
import org.springframework.beans.factory.annotation.Qualifier;
-
 
58
import org.springframework.beans.factory.annotation.Value;
-
 
59
import org.springframework.core.io.ByteArrayResource;
-
 
60
import org.springframework.core.io.ClassPathResource;
-
 
61
import org.springframework.core.io.InputStreamResource;
-
 
62
import org.springframework.http.HttpHeaders;
-
 
63
import org.springframework.http.HttpStatus;
-
 
64
import org.springframework.http.MediaType;
-
 
65
import org.springframework.http.ResponseEntity;
-
 
66
import org.springframework.mail.javamail.JavaMailSender;
-
 
67
import org.springframework.stereotype.Controller;
-
 
68
import org.springframework.transaction.annotation.Transactional;
-
 
69
import org.springframework.ui.Model;
-
 
70
import org.springframework.web.bind.annotation.*;
-
 
71
import org.springframework.web.multipart.MultipartFile;
-
 
72
 
-
 
73
import javax.servlet.http.HttpServletRequest;
-
 
74
import javax.servlet.http.HttpServletResponse;
-
 
75
import java.io.*;
-
 
76
import java.net.URISyntaxException;
-
 
77
import java.time.LocalDate;
-
 
78
import java.time.LocalDateTime;
-
 
79
import java.time.YearMonth;
-
 
80
import java.time.format.DateTimeFormatter;
-
 
81
import java.time.temporal.ChronoUnit;
-
 
82
import java.util.*;
-
 
83
import java.util.stream.Collectors;
-
 
84
import java.util.stream.Stream;
152
 
85
 
153
@Controller
86
@Controller
154
@Transactional(rollbackFor = Throwable.class)
87
@Transactional(rollbackFor = Throwable.class)
155
public class InventoryController {
88
public class InventoryController {
156
 
89
 
Line 490... Line 423...
490
 
423
 
491
		final HttpHeaders headers = new HttpHeaders();
424
		final HttpHeaders headers = new HttpHeaders();
492
		headers.setContentType(MediaType.APPLICATION_PDF);
425
		headers.setContentType(MediaType.APPLICATION_PDF);
493
		headers.set("Content-disposition", "inline; filename=invoices.pdf");
426
		headers.set("Content-disposition", "inline; filename=invoices.pdf");
494
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
427
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
495
		List<PdfModel> pdfModels = new ArrayList<>();
428
		List<InvoicePdfModel> pdfModels = new ArrayList<>();
496
		/*
429
		/*
497
		 * for (FofoOrder fofoOrder : fofoOrders) { try {
430
		 * for (FofoOrder fofoOrder : fofoOrders) { try {
498
		 * pdfModels.add(orderService.getInvoicePdfModel(fofoOrder.getId())); } catch
431
		 * pdfModels.add(orderService.getInvoicePdfModel(fofoOrder.getId())); } catch
499
		 * (Exception e) {
432
		 * (Exception e) {
500
		 * LOGGER.info("could not create invoice for {}, invoice number {}",
433
		 * LOGGER.info("could not create invoice for {}, invoice number {}",
Line 570... Line 503...
570
	public ResponseEntity<?> downloadInvoices(HttpServletRequest request, @RequestParam String serialNumber,
503
	public ResponseEntity<?> downloadInvoices(HttpServletRequest request, @RequestParam String serialNumber,
571
			Model model) throws ProfitMandiBusinessException {
504
			Model model) throws ProfitMandiBusinessException {
572
		byte[] bytes = null;
505
		byte[] bytes = null;
573
		if (!imeis.contains(serialNumber)) {
506
		if (!imeis.contains(serialNumber)) {
574
 
507
 
575
			PdfModel pdfModel = orderService.getDummyPdfModel(serialNumber);
508
			InvoicePdfModel pdfModel = orderService.getDummyPdfModel(serialNumber);
576
			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
509
			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
577
			PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
510
			PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
578
			bytes = byteArrayOutputStream.toByteArray();
511
			bytes = byteArrayOutputStream.toByteArray();
579
		} else {
512
		} else {
580
			ClassPathResource resource = new ClassPathResource("/META-INF/" + serialNumber + ".pdf");
513
			ClassPathResource resource = new ClassPathResource("/META-INF/" + serialNumber + ".pdf");
Line 598... Line 531...
598
			Model model) throws Exception {
531
			Model model) throws Exception {
599
		byte[] bytes = null;
532
		byte[] bytes = null;
600
		List<Attachment> attachments = new ArrayList<>();
533
		List<Attachment> attachments = new ArrayList<>();
601
		for (String serialNumber : serialNumbers) {
534
		for (String serialNumber : serialNumbers) {
602
			if (!imeis.contains(serialNumber)) {
535
			if (!imeis.contains(serialNumber)) {
603
				PdfModel pdfModel = null;
536
				InvoicePdfModel pdfModel = null;
604
				try {
537
				try {
605
					pdfModel = orderService.getDummyPdfModel(serialNumber);
538
					pdfModel = orderService.getDummyPdfModel(serialNumber);
606
				} catch (Exception e) {
539
				} catch (Exception e) {
607
					continue;
540
					continue;
608
				}
541
				}