Subversion Repositories SmartDukaan

Rev

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

Rev 30380 Rev 30381
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.common.model.InvoicePdfModel;
-
 
5
import com.spice.profitmandi.common.model.ProfitMandiConstants;
4
import com.spice.profitmandi.common.model.ProfitMandiConstants;
6
import com.spice.profitmandi.common.util.PdfUtils;
-
 
7
import com.spice.profitmandi.common.web.client.RestClient;
5
import com.spice.profitmandi.common.web.client.RestClient;
8
import com.spice.profitmandi.dao.entity.transaction.Order;
6
import com.spice.profitmandi.dao.entity.transaction.Order;
9
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
7
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
10
import com.spice.profitmandi.service.authentication.RoleManager;
8
import com.spice.profitmandi.service.authentication.RoleManager;
11
import com.spice.profitmandi.service.inventory.PurchaseService;
9
import com.spice.profitmandi.service.inventory.PurchaseService;
Line 29... Line 27...
29
import org.springframework.web.bind.annotation.RequestMapping;
27
import org.springframework.web.bind.annotation.RequestMapping;
30
import org.springframework.web.bind.annotation.RequestMethod;
28
import org.springframework.web.bind.annotation.RequestMethod;
31
import org.springframework.web.bind.annotation.RequestParam;
29
import org.springframework.web.bind.annotation.RequestParam;
32
 
30
 
33
import javax.servlet.http.HttpServletRequest;
31
import javax.servlet.http.HttpServletRequest;
34
import java.io.ByteArrayInputStream;
-
 
35
import java.io.ByteArrayOutputStream;
32
import java.io.ByteArrayOutputStream;
36
import java.io.File;
33
import java.io.File;
37
import java.io.InputStream;
-
 
38
import java.time.LocalDateTime;
34
import java.time.LocalDateTime;
39
import java.util.*;
35
import java.util.*;
40
import java.util.zip.ZipEntry;
36
import java.util.zip.ZipEntry;
41
import java.util.zip.ZipOutputStream;
37
import java.util.zip.ZipOutputStream;
42
 
38
 
Line 107... Line 103...
107
				final HttpHeaders headers = new HttpHeaders();
103
				final HttpHeaders headers = new HttpHeaders();
108
				headers.setContentType(MediaType.APPLICATION_PDF);
104
				headers.setContentType(MediaType.APPLICATION_PDF);
109
				headers.set("Content-Type", "application/pdf");
105
				headers.set("Content-Type", "application/pdf");
110
				headers.set("Content-disposition", "inline; filename=" + invoiceNumber + ".pdf");
106
				headers.set("Content-disposition", "inline; filename=" + invoiceNumber + ".pdf");
111
 
107
 
112
				if (!invoiceNumber.equals("NSDLHR14541")) {
108
				if (false) {
113
					InvoicePdfModel invoicePdfModel = invoiceService.getInvoicePdfModel(orders);
109
					/*InvoicePdfModel invoicePdfModel = invoiceService.getInvoicePdfModel(orders);
114
 
110
 
115
					ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
111
					ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
116
					List<InvoicePdfModel> pdfModels = new ArrayList<>();
112
					List<InvoicePdfModel> pdfModels = new ArrayList<>();
117
					pdfModels.add(invoicePdfModel);
113
					pdfModels.add(invoicePdfModel);
118
					PdfUtils.generateAndWrite(pdfModels, byteArrayOutputStream);
114
					PdfUtils.generateAndWrite(pdfModels, byteArrayOutputStream);
119
					final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
115
					final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
120
					final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
116
					final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
121
					LOGGER.info("Before stream - {}", pdfModels);
117
					LOGGER.info("Before stream - {}", pdfModels);
122
					return new ResponseEntity<>(inputStreamResource, headers, HttpStatus.OK);
118
					return new ResponseEntity<>(inputStreamResource, headers, HttpStatus.OK);*/
123
				} else {
119
				} else {
124
					Map<String, String> headersMap = new HashMap<>();
120
					Map<String, String> headersMap = new HashMap<>();
125
					headersMap.put("Authorization", "Basic " + Base64.getEncoder().encodeToString("sd:smart@123".getBytes()));
121
					headersMap.put("Authorization", "Basic " + Base64.getEncoder().encodeToString("sd:smart@123".getBytes()));
126
					if (invoiceNumbers.size() == 1) {
122
					if (invoiceNumbers.size() == 1) {
127
						String invoicePath = this.getInvoicePath(orders.get(0));
123
						String invoicePath = this.getInvoicePath(orders.get(0));