Subversion Repositories SmartDukaan

Rev

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

Rev 20985 Rev 21854
Line 1... Line 1...
1
package in.shop2020.hotspot.dashbaord.server;
1
package in.shop2020.hotspot.dashbaord.server;
2
 
2
 
-
 
3
import in.shop2020.config.ConfigException;
-
 
4
import in.shop2020.logistics.BluedartAttributes;
-
 
5
import in.shop2020.logistics.DeliveryType;
-
 
6
import in.shop2020.logistics.LogisticsServiceException;
-
 
7
import in.shop2020.logistics.PickUpType;
-
 
8
import in.shop2020.logistics.PickupStore;
-
 
9
import in.shop2020.logistics.Provider;
-
 
10
import in.shop2020.logistics.ProviderDetails;
-
 
11
import in.shop2020.model.v1.catalog.CatalogService;
-
 
12
import in.shop2020.model.v1.catalog.CatalogServiceException;
-
 
13
import in.shop2020.model.v1.catalog.Item;
-
 
14
import in.shop2020.model.v1.inventory.BillingType;
-
 
15
import in.shop2020.model.v1.inventory.InventoryServiceException;
-
 
16
import in.shop2020.model.v1.inventory.Warehouse;
-
 
17
import in.shop2020.model.v1.order.AmazonOrder;
-
 
18
import in.shop2020.model.v1.order.Attribute;
-
 
19
import in.shop2020.model.v1.order.EbayOrder;
-
 
20
import in.shop2020.model.v1.order.FlipkartOrder;
-
 
21
import in.shop2020.model.v1.order.HsOrder;
-
 
22
import in.shop2020.model.v1.order.LineItem;
-
 
23
import in.shop2020.model.v1.order.Order;
-
 
24
import in.shop2020.model.v1.order.OrderSource;
-
 
25
import in.shop2020.model.v1.order.OrderStatus;
-
 
26
import in.shop2020.model.v1.order.OrderType;
-
 
27
import in.shop2020.model.v1.order.ProductCondition;
-
 
28
import in.shop2020.model.v1.order.SellerInfo;
-
 
29
import in.shop2020.model.v1.order.ShipmentLogisticsCostDetail;
-
 
30
import in.shop2020.model.v1.order.SnapdealOrder;
-
 
31
import in.shop2020.model.v1.order.TransactionService;
-
 
32
import in.shop2020.model.v1.order.WarehouseAddress;
-
 
33
import in.shop2020.model.v1.user.Address;
-
 
34
import in.shop2020.thrift.clients.CatalogClient;
-
 
35
import in.shop2020.thrift.clients.InventoryClient;
-
 
36
import in.shop2020.thrift.clients.LogisticsClient;
-
 
37
import in.shop2020.thrift.clients.TransactionClient;
-
 
38
import in.shop2020.thrift.clients.UserClient;
-
 
39
import in.shop2020.thrift.clients.config.ConfigClient;
-
 
40
 
3
import java.awt.image.BufferedImage;
41
import java.awt.image.BufferedImage;
4
import java.io.ByteArrayOutputStream;
42
import java.io.ByteArrayOutputStream;
5
import java.io.File;
43
import java.io.File;
6
import java.io.FileOutputStream;
44
import java.io.FileOutputStream;
7
import java.io.IOException;
45
import java.io.IOException;
8
import java.io.OutputStream;
46
import java.io.OutputStream;
9
import java.text.DateFormat;
47
import java.text.DateFormat;
10
import java.text.DecimalFormat;
48
import java.text.DecimalFormat;
11
import java.util.ArrayList;
49
import java.util.ArrayList;
-
 
50
import java.util.Calendar;
12
import java.util.Date;
51
import java.util.Date;
13
import java.util.HashMap;
52
import java.util.HashMap;
14
import java.util.List;
53
import java.util.List;
15
import java.util.Locale;
54
import java.util.Locale;
16
import java.util.Map;
55
import java.util.Map;
Line 45... Line 84...
45
import com.itextpdf.text.pdf.PdfPCell;
84
import com.itextpdf.text.pdf.PdfPCell;
46
import com.itextpdf.text.pdf.PdfPTable;
85
import com.itextpdf.text.pdf.PdfPTable;
47
import com.itextpdf.text.pdf.PdfWriter;
86
import com.itextpdf.text.pdf.PdfWriter;
48
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
87
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
49
 
88
 
50
import in.shop2020.config.ConfigException;
-
 
51
import in.shop2020.logistics.BluedartAttributes;
-
 
52
import in.shop2020.logistics.DeliveryType;
-
 
53
import in.shop2020.logistics.LogisticsServiceException;
-
 
54
import in.shop2020.logistics.PickUpType;
-
 
55
import in.shop2020.logistics.PickupStore;
-
 
56
import in.shop2020.logistics.Provider;
-
 
57
import in.shop2020.logistics.ProviderDetails;
-
 
58
import in.shop2020.model.v1.catalog.CatalogService;
-
 
59
import in.shop2020.model.v1.catalog.CatalogServiceException;
-
 
60
import in.shop2020.model.v1.catalog.Item;
-
 
61
import in.shop2020.model.v1.inventory.BillingType;
-
 
62
import in.shop2020.model.v1.inventory.InventoryServiceException;
-
 
63
import in.shop2020.model.v1.inventory.Warehouse;
-
 
64
import in.shop2020.model.v1.order.AmazonOrder;
-
 
65
import in.shop2020.model.v1.order.Attribute;
-
 
66
import in.shop2020.model.v1.order.EbayOrder;
-
 
67
import in.shop2020.model.v1.order.FlipkartOrder;
-
 
68
import in.shop2020.model.v1.order.HsOrder;
-
 
69
import in.shop2020.model.v1.order.LineItem;
-
 
70
import in.shop2020.model.v1.order.Order;
-
 
71
import in.shop2020.model.v1.order.OrderSource;
-
 
72
import in.shop2020.model.v1.order.OrderStatus;
-
 
73
import in.shop2020.model.v1.order.OrderType;
-
 
74
import in.shop2020.model.v1.order.ProductCondition;
-
 
75
import in.shop2020.model.v1.order.SellerInfo;
-
 
76
import in.shop2020.model.v1.order.ShipmentLogisticsCostDetail;
-
 
77
import in.shop2020.model.v1.order.SnapdealOrder;
-
 
78
import in.shop2020.model.v1.order.WarehouseAddress;
-
 
79
import in.shop2020.model.v1.user.Address;
-
 
80
import in.shop2020.thrift.clients.CatalogClient;
-
 
81
import in.shop2020.thrift.clients.InventoryClient;
-
 
82
import in.shop2020.thrift.clients.LogisticsClient;
-
 
83
import in.shop2020.thrift.clients.TransactionClient;
-
 
84
import in.shop2020.thrift.clients.UserClient;
-
 
85
import in.shop2020.thrift.clients.config.ConfigClient;
-
 
86
 
-
 
87
@SuppressWarnings("serial")
89
@SuppressWarnings("serial")
88
public class InvoiceServlet extends HttpServlet {
90
public class InvoiceServlet extends HttpServlet {
89
 
91
 
90
	private static Logger logger = LoggerFactory.getLogger(InvoiceServlet.class);
92
	private static Logger logger = LoggerFactory.getLogger(InvoiceServlet.class);
-
 
93
	private static long july2017Timestamp;
-
 
94
	static {
-
 
95
		Calendar july2017 = Calendar.getInstance();
-
 
96
		july2017.set(2017, Calendar.JULY, 1);
-
 
97
		july2017Timestamp = july2017.getTimeInMillis();
91
	
98
	}
92
	@Override
99
	@Override
93
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
100
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
94
		long orderId = Long.parseLong(request.getParameter("id"));
101
		long orderId = Long.parseLong(request.getParameter("id"));
95
		String logisticsTxnId  = request.getParameter("logisticsTxnId");
102
		String logisticsTxnId  = request.getParameter("logisticsTxnId");
-
 
103
		Order o = null;
-
 
104
		try {
-
 
105
			in.shop2020.model.v1.order.TransactionService.Client tclient = new TransactionClient().getClient();
-
 
106
			o = tclient.getOrder(orderId);
-
 
107
		} catch (Exception e) {
-
 
108
			logger.warn("Seems problem with transaction service", e);
-
 
109
			return;
-
 
110
		}
-
 
111
		
96
		long warehouseId = Long.parseLong(request.getParameter("warehouse"));
112
		long warehouseId = Long.parseLong(request.getParameter("warehouse"));
97
		boolean withBill = false;
113
		boolean withBill = false;
98
		boolean printAll = false;
114
		boolean printAll = false;
99
		try {
115
		try {
100
			withBill = Boolean.parseBoolean(request.getParameter("withBill"));
116
			withBill = Boolean.parseBoolean(request.getParameter("withBill"));
Line 112... Line 128...
112
		}else{
128
		}else{
113
			logger.info("Printing invoice for order id: " + orderId);
129
			logger.info("Printing invoice for order id: " + orderId);
114
		}
130
		}
115
		
131
		
116
		ByteArrayOutputStream baos = null;
132
		ByteArrayOutputStream baos = null;
-
 
133
		//For invoices older than july 17
-
 
134
		if(o.getBilling_timestamp() < july2017Timestamp) {
-
 
135
			InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
-
 
136
			baos = invoiceGenerationService.generateInvoice(orderId, withBill, printAll, warehouseId);
117
	
137
		} else { //For GST
118
		InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
138
			GSTInvoiceGenerationService invoiceGenerationService = new GSTInvoiceGenerationService();
119
		baos = invoiceGenerationService.generateInvoice(orderId, withBill, printAll, warehouseId);
139
			baos = invoiceGenerationService.generateInvoice(orderId, withBill, printAll, warehouseId);
-
 
140
			
120
 
141
		}
121
		response.setContentType("application/pdf");
142
		response.setContentType("application/pdf");
122
		if(logisticsTxnId!=null && !logisticsTxnId.isEmpty()){
143
		if(logisticsTxnId!=null && !logisticsTxnId.isEmpty()){
123
			response.setHeader("Content-disposition", "inline; filename=invoice-"+logisticsTxnId+".pdf" );
144
			response.setHeader("Content-disposition", "inline; filename=invoice-"+logisticsTxnId+".pdf" );
124
		} else {
145
		} else {
125
			response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
146
			response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );