Subversion Repositories SmartDukaan

Rev

Rev 676 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 676 Rev 734
Line 1... Line 1...
1
package in.shop2020.support.services;
1
package in.shop2020.support.services;
2
 
2
 
3
 
-
 
4
import in.shop2020.logistics.LogisticsServiceException;
3
import in.shop2020.logistics.LogisticsServiceException;
5
import in.shop2020.logistics.Provider;
4
import in.shop2020.logistics.Provider;
6
import in.shop2020.model.v1.catalog.InventoryService.Client;
5
import in.shop2020.model.v1.catalog.InventoryService.Client;
7
import in.shop2020.model.v1.catalog.InventoryServiceException;
6
import in.shop2020.model.v1.catalog.InventoryServiceException;
8
import in.shop2020.model.v1.catalog.Warehouse;
7
import in.shop2020.model.v1.catalog.Warehouse;
Line 10... Line 9...
10
import in.shop2020.model.v1.order.Order;
9
import in.shop2020.model.v1.order.Order;
11
import in.shop2020.model.v1.order.TransactionServiceException;
10
import in.shop2020.model.v1.order.TransactionServiceException;
12
import in.shop2020.thrift.clients.CatalogServiceClient;
11
import in.shop2020.thrift.clients.CatalogServiceClient;
13
import in.shop2020.thrift.clients.LogisticsServiceClient;
12
import in.shop2020.thrift.clients.LogisticsServiceClient;
14
import in.shop2020.thrift.clients.TransactionServiceClient;
13
import in.shop2020.thrift.clients.TransactionServiceClient;
15
 
-
 
16
 
14
 
17
import java.io.ByteArrayOutputStream;
15
import java.io.ByteArrayOutputStream;
18
import java.io.File;
16
import java.io.File;
19
import java.io.FileNotFoundException;
-
 
20
import java.io.FileOutputStream;
17
import java.io.FileOutputStream;
21
import java.io.IOException;
18
import java.io.IOException;
22
import java.io.OutputStream;
-
 
23
import java.net.URL;
-
 
24
import java.text.DateFormat;
19
import java.text.DateFormat;
-
 
20
import java.text.DecimalFormat;
25
import java.util.Date;
21
import java.util.Date;
26
import java.util.List;
22
import java.util.List;
27
 
23
 
28
import org.apache.thrift.TException;
24
import org.apache.thrift.TException;
29
 
25
 
30
import com.itextpdf.text.BaseColor;
-
 
31
import com.itextpdf.text.Document;
26
import com.itextpdf.text.Document;
32
import com.itextpdf.text.Element;
27
import com.itextpdf.text.Element;
33
import com.itextpdf.text.Font;
28
import com.itextpdf.text.Font;
34
import com.itextpdf.text.Font.FontFamily;
29
import com.itextpdf.text.Font.FontFamily;
35
import com.itextpdf.text.FontFactory;
30
import com.itextpdf.text.FontFactory;
Line 40... Line 35...
40
import com.itextpdf.text.Rectangle;
35
import com.itextpdf.text.Rectangle;
41
import com.itextpdf.text.pdf.BaseFont;
36
import com.itextpdf.text.pdf.BaseFont;
42
import com.itextpdf.text.pdf.PdfPCell;
37
import com.itextpdf.text.pdf.PdfPCell;
43
import com.itextpdf.text.pdf.PdfPTable;
38
import com.itextpdf.text.pdf.PdfPTable;
44
import com.itextpdf.text.pdf.PdfWriter;
39
import com.itextpdf.text.pdf.PdfWriter;
45
import com.itextpdf.text.pdf.draw.LineSeparator;
-
 
46
 
-
 
47
 
40
 
48
public class InvoiceGenerationService {
41
public class InvoiceGenerationService {
49
	private static TransactionServiceClient tsc = null;
42
	private TransactionServiceClient tsc = null;
50
	private static CatalogServiceClient csc = null;
43
	private CatalogServiceClient csc = null;
51
	private static LogisticsServiceClient lsc = null;
44
	private LogisticsServiceClient lsc = null;
-
 
45
	private DecimalFormat amountFormat = new DecimalFormat("#,##0.00");
52
	
46
	
53
	static {
47
	public InvoiceGenerationService() {
54
	 	try {
48
		try {
55
			tsc = new TransactionServiceClient();
49
			tsc = new TransactionServiceClient();
56
			csc = new CatalogServiceClient();
50
			csc = new CatalogServiceClient();
57
			lsc = new LogisticsServiceClient();
51
			lsc = new LogisticsServiceClient();
58
		} catch (Exception e) {
52
		} catch (Exception e) {
59
			// TODO Auto-generated catch block
-
 
60
			e.printStackTrace();
53
			e.printStackTrace();
61
		}
54
		}
62
	}
55
	}
63
	
56
 
64
	public static ByteArrayOutputStream generateInvoice(long orderId){
57
	public ByteArrayOutputStream generateInvoice(long orderId) {
65
		
-
 
66
		ByteArrayOutputStream baosPDF = null;
58
		ByteArrayOutputStream baosPDF = null;
67
		in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
59
		in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
68
		Client iclient = csc.getClient();
60
		Client iclient = csc.getClient();
69
		in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
61
		in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
70
		 
62
 
71
		Order order = null;
63
		Order order = null;
72
		Warehouse warehouse = null;
64
		Warehouse warehouse = null;
73
		Provider provider = null;
65
		Provider provider = null;
-
 
66
		String destCode = null;
74
		try {
67
		try {
75
			order = tclient.getOrder(orderId);
68
			order = tclient.getOrder(orderId);
76
			warehouse = iclient.getWarehouse(order.getWarehouse_id());
69
			warehouse = iclient.getWarehouse(order.getWarehouse_id());
-
 
70
			long providerId = order.getLogistics_provider_id();
77
			provider = logisticsClient.getProvider(order.getLogistics_provider_id());
71
			provider = logisticsClient.getProvider(providerId);
-
 
72
			destCode = logisticsClient.getDestinationCode(providerId, order.getCustomer_pincode());
78
		} catch (TransactionServiceException e1) {
73
		} catch (TransactionServiceException e1) {
79
			e1.printStackTrace();
74
			e1.printStackTrace();
80
			return baosPDF;
75
			return baosPDF;
81
		} catch (TException e1) {
76
		} catch (TException e1) {
82
			e1.printStackTrace();
77
			e1.printStackTrace();
Line 86... Line 81...
86
			return baosPDF;
81
			return baosPDF;
87
		} catch (LogisticsServiceException e) {
82
		} catch (LogisticsServiceException e) {
88
			e.printStackTrace();
83
			e.printStackTrace();
89
			return baosPDF;
84
			return baosPDF;
90
		}
85
		}
91
		 
86
 
92
		
87
		try {
93
	     try {
88
			baosPDF = new ByteArrayOutputStream();
94
	//             OutputStream file = new FileOutputStream(new File("/home/rajveer/Test.pdf"));
89
 
95
	     baosPDF = new ByteArrayOutputStream();
90
			String fontPath = InvoiceGenerationService.class.getResource("/" + provider.getName().toLowerCase() + "/barcode.TTF").getPath();
96
	     
91
			FontFactoryImp ttfFontFactory = new FontFactoryImp();
97
	     String fontPath = InvoiceGenerationService.class.getResource("/C39TXME.TTF").getPath();
92
			ttfFontFactory.register(fontPath, "barcode");
98
	     FontFactoryImp ttfFontFactory = new FontFactoryImp();
93
			Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, 32);
99
	     ttfFontFactory.register(fontPath, "barcode");
94
			Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
100
	     Font barCode = ttfFontFactory.getFont("barcode", 30);
95
			Font helvetica10 = FontFactory.getFont(FontFactory.HELVETICA, 10);
101
	     Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
96
			Font helvetica12 = FontFactory.getFont(FontFactory.HELVETICA, 12);
102
	     Document document = new Document();
97
			Font helvetica16 = FontFactory.getFont(FontFactory.HELVETICA, 16);
103
	     PdfWriter.getInstance(document, baosPDF);
98
			
104
	     document.addAuthor("shop2020");
99
			Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
105
	     document.addTitle("Invoice No: " + order.getInvoice_number());
100
			Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
106
	     document.open();
101
			Document document = new Document();
107
	     PdfPTable table = new PdfPTable(1);
102
			PdfWriter.getInstance(document, baosPDF);
108
	     table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
103
			document.addAuthor("shop2020");
109
	     
104
			document.addTitle("Invoice No: " + order.getInvoice_number());
110
	     String logoPath = InvoiceGenerationService.class.getResource("/logo.png").getPath();
105
			document.open();
111
	     PdfPCell logoCell = new PdfPCell(Image.getInstance(logoPath), false);
106
			PdfPTable table = new PdfPTable(1);
112
	     logoCell.setBorder(Rectangle.NO_BORDER);
107
			table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
113
	     
108
 
114
	     String addressString =  warehouse.getLocation() + "\nPIN " + warehouse.getPincode()+ "\n\n";
109
			String logoPath = InvoiceGenerationService.class.getResource("/logo.jpg").getPath();
115
	     Paragraph addressParagraph = new Paragraph(addressString, new Font(FontFamily.TIMES_ROMAN,8f));
110
			PdfPCell logoCell = new PdfPCell(Image.getInstance(logoPath), false);
116
	     PdfPCell addressCell = new PdfPCell();
111
			logoCell.setBorder(Rectangle.NO_BORDER);
117
	     addressCell.addElement(addressParagraph);
112
 
118
	     addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
113
			String addressString = warehouse.getLocation() + "\nPIN " + warehouse.getPincode() + "\n\n";
119
	     addressCell.setBorder(Rectangle.NO_BORDER);
114
			Paragraph addressParagraph = new Paragraph(addressString, new Font(FontFamily.TIMES_ROMAN, 8f));
120
	     
115
			PdfPCell addressCell = new PdfPCell();
121
	     PdfPCell titleCell = new PdfPCell(new Phrase("Dispatch Advice", FontFactory.getFont(FontFactory.HELVETICA, 20)));
116
			addressCell.addElement(addressParagraph);
122
	     titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
117
			addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
123
	     titleCell.setBorder(Rectangle.NO_BORDER);
118
			addressCell.setBorder(Rectangle.NO_BORDER);
124
	     
119
 
125
	     PdfPTable providerInfoTable = new PdfPTable(2);
120
			PdfPCell titleCell = new PdfPCell(new Phrase("Dispatch Advice",	helveticaBold12));
126
	     providerInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
121
			titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
127
	     PdfPCell providerNameCell = new PdfPCell(new Phrase("Courier Name:"  + provider.getName(), helvetica8));
122
			titleCell.setBorder(Rectangle.NO_BORDER);
128
	     providerNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
123
 
129
	     providerNameCell.setColspan(2);
124
			PdfPTable providerInfoTable = new PdfPTable(2);
130
	     providerNameCell.setBorder(Rectangle.NO_BORDER);
125
			providerInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
131
	     
126
			PdfPCell providerNameCell = new PdfPCell(new Phrase(provider.getName(), helveticaBold12));
132
	     PdfPCell awbNumberCell = new PdfPCell(new Paragraph(order.getAirwaybill_no()+"", barCode));
127
			providerNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
133
	     awbNumberCell.setPaddingBottom(10.0f);
128
			providerNameCell.setColspan(2);
134
	     awbNumberCell.setRowspan(2);
129
			providerNameCell.setBorder(Rectangle.NO_BORDER);
135
	     awbNumberCell.setBorder(Rectangle.NO_BORDER);
130
 
136
	     
131
			PdfPCell awbNumberCell = new PdfPCell(new Paragraph("*" + order.getAirwaybill_no() + "*", barCodeFont));
137
	     providerInfoTable.addCell(providerNameCell);
132
			awbNumberCell.setPaddingTop(20.0f);
138
	     providerInfoTable.addCell(awbNumberCell);
133
			awbNumberCell.setPaddingBottom(10.0f);
139
	     providerInfoTable.addCell(new Phrase("Account No :" + provider.getAccountNo(), helvetica8));
134
			awbNumberCell.setRowspan(3);
140
	     providerInfoTable.addCell(new Phrase("AWB Date   :" + DateFormat.getDateInstance(DateFormat.SHORT).format(new Date()), helvetica8));
135
			awbNumberCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
141
	     
136
			awbNumberCell.setBorder(Rectangle.NO_BORDER);
142
	     
137
 
143
	     PdfPTable customerTable = new PdfPTable(new float[]{1f, 0.2f, 3f});
138
			providerInfoTable.addCell(providerNameCell);
144
	     customerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
139
			providerInfoTable.addCell(awbNumberCell);
145
	     customerTable.addCell(new Phrase("Name", helvetica8));
140
			providerInfoTable.addCell(new Phrase("Account No : " + provider.getAccountNo(), helvetica8));
146
	     customerTable.addCell(new Phrase(":", helvetica8));
141
			providerInfoTable.addCell(new Phrase("AWB Date   : " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()), helvetica8));
147
	     customerTable.addCell(new Phrase(order.getCustomer_name(), helvetica8));
142
			providerInfoTable.addCell(new Phrase("Weight         : " + order.getTotal_weight()/1000.0 + " Kg", helvetica8));
148
	     
143
			
149
	     customerTable.addCell(new Phrase("Address", helvetica8));
144
			PdfPTable customerTable = new PdfPTable(1);
150
	     customerTable.addCell(new Phrase(":", helvetica8));
145
			customerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
151
	     customerTable.addCell(new Phrase(order.getCustomer_address(), helvetica8));
146
			
152
	     
147
			PdfPTable nameTable = new PdfPTable(2);
153
	     customerTable.addCell(new Phrase("City", helvetica8));
148
			nameTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
154
	     customerTable.addCell(new Phrase(":", helvetica8));
149
			nameTable.addCell(new Phrase(order.getCustomer_name(), helvetica12));
155
	     customerTable.addCell(new Phrase(order.getCustomer_city(), helvetica8));
150
			
156
	     
151
			PdfPCell phoneCell = new PdfPCell(new Phrase("Phone :" + order.getCustomer_mobilenumber(), helvetica12));
157
	     customerTable.addCell(new Phrase("State", helvetica8));
152
			phoneCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
158
	     customerTable.addCell(new Phrase(":", helvetica8));
153
			phoneCell.setBorder(Rectangle.NO_BORDER);
159
	     customerTable.addCell(new Phrase(order.getCustomer_state(), helvetica8));
154
			nameTable.addCell(phoneCell);
160
	     
155
			
161
	     customerTable.addCell(new Phrase("PIN", helvetica8));
156
			PdfPCell nameCell = new PdfPCell(nameTable);
162
	     customerTable.addCell(new Phrase(":", helvetica8));
157
			nameCell.setBorder(Rectangle.NO_BORDER);
163
	     customerTable.addCell(new Phrase(order.getCustomer_pincode(), helvetica8));
158
			customerTable.addCell(nameCell);
164
	     
159
			
165
	     customerTable.addCell(new Phrase("Phone", helvetica8));
160
			customerTable.addCell(new Phrase(order.getCustomer_address1(), helvetica12));
166
	     customerTable.addCell(new Phrase(":", helvetica8));
161
			customerTable.addCell(new Phrase(order.getCustomer_address2(), helvetica12));
167
	     customerTable.addCell(new Phrase(order.getCustomer_mobilenumber()+"", helvetica8));
162
			customerTable.addCell(new Phrase(order.getCustomer_city() + "," + order.getCustomer_state(), helvetica12));
168
	     
163
			customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + destCode, helvetica16));
169
	     PdfPTable invoiceTable = new PdfPTable(6);
164
 
170
	     invoiceTable.setSpacingAfter(20);
165
			PdfPTable invoiceTable = new PdfPTable(6);
171
	     invoiceTable.setSpacingBefore(20);
166
			invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
172
	     
167
			//invoiceTable.setSpacingAfter(20);
173
	     PdfPCell invoiceTableHeader = new PdfPCell(new Phrase("Order Details:", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8)));
168
			//invoiceTable.setSpacingBefore(20);
174
	     invoiceTableHeader.setBorder(Rectangle.NO_BORDER);
169
 
175
	     invoiceTableHeader.setColspan(6);
170
			PdfPCell invoiceTableHeader = new PdfPCell(new Phrase("Order Details:", helveticaBold12));
176
	     invoiceTable.addCell(invoiceTableHeader);
171
			invoiceTableHeader.setBorder(Rectangle.NO_BORDER);
177
	     
172
			invoiceTableHeader.setColspan(6);
178
	     invoiceTable.addCell(new Phrase("Order No", helvetica8));
173
			invoiceTableHeader.setPaddingTop(10);
179
	     invoiceTable.addCell(new Phrase("Paymode", helvetica8));
174
			invoiceTable.addCell(invoiceTableHeader);
180
	     invoiceTable.addCell(new Phrase("Product Name", helvetica8));
175
 
181
	     invoiceTable.addCell(new Phrase("Quantity", helvetica8));
176
			invoiceTable.addCell(new Phrase("Order No", helvetica8));
182
	     invoiceTable.addCell(new Phrase("Rate", helvetica8));
177
			invoiceTable.addCell(new Phrase("Paymode", helvetica8));
183
	     invoiceTable.addCell(new Phrase("Amount", helvetica8));
178
			invoiceTable.addCell(new Phrase("Product Name", helvetica8));
184
	     List<LineItem> lineitems = order.getLineitems();
179
			invoiceTable.addCell(new Phrase("Quantity", helvetica8));
185
	     double totalitems = 0;
180
			invoiceTable.addCell(new Phrase("Rate", helvetica8));
186
	     for(LineItem lineitem: lineitems){
181
			invoiceTable.addCell(new Phrase("Amount", helvetica8));
187
	    	 invoiceTable.addCell(new Phrase(orderId + "", helvetica8));
182
			List<LineItem> lineitems = order.getLineitems();
188
	    	 invoiceTable.addCell(new Phrase("EXP", helvetica8));
183
			double totalitems = 0;
189
	    	 invoiceTable.addCell(new Phrase(lineitem.getBrand() + " " + lineitem.getModel_number() + " " + lineitem.getModel_name() + " " + lineitem.getColor(), helvetica8));
184
			for (LineItem lineitem : lineitems) {
190
		     invoiceTable.addCell(new Phrase(lineitem.getQuantity()+"", helvetica8));
185
				invoiceTable.addCell(new Phrase(orderId + "", helvetica8));
191
		     invoiceTable.addCell(new Phrase(lineitem.getUnit_price()+"", helvetica8));
186
				invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
192
		     invoiceTable.addCell(new Phrase(lineitem.getTotal_price()+"", helvetica8));
187
				
193
		     totalitems = totalitems + lineitem.getQuantity();
188
				PdfPCell productNameCell = new PdfPCell(new Phrase(lineitem.getBrand() + " "
194
	     }
189
						+ lineitem.getModel_number() + " "
195
	     PdfPCell totalCell = new PdfPCell(new Phrase("Total", helvetica8));
190
						+ lineitem.getModel_name() + " " + lineitem.getColor(),
196
	     totalCell.setColspan(4);
191
						helvetica8));
197
    	 invoiceTable.addCell(totalCell);
192
				productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
198
	     invoiceTable.addCell(new Phrase(totalitems+"", helvetica8));
193
				invoiceTable.addCell(productNameCell);
199
	     invoiceTable.addCell(new Phrase(order.getTotal_amount()+"", helvetica8));
194
				
200
	     
195
				invoiceTable.addCell(new Phrase(lineitem.getQuantity() + "", helvetica8));
201
	     PdfPCell cstCell = new PdfPCell(new Phrase("CST No: " , helvetica8));
196
				
202
	     PdfPCell tinCell = new PdfPCell(new Phrase("TIN No: " + warehouse.getTinNumber(), helvetica8));
197
				PdfPCell unitPriceCell = new PdfPCell(new Phrase(amountFormat.format(lineitem.getUnit_price()), helvetica8));
203
	     cstCell.setColspan(3);
198
				unitPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
204
	     tinCell.setColspan(3);
199
				invoiceTable.addCell(unitPriceCell);
205
	     cstCell.setBorderWidthRight(0);
200
				
206
	     tinCell.setBorderWidthLeft(0);
201
				PdfPCell totalPriceCell = new PdfPCell(new Phrase(amountFormat.format(lineitem.getTotal_price()), helvetica8));
207
	     invoiceTable.addCell(cstCell);
202
				totalPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
208
	     invoiceTable.addCell(tinCell);
203
				invoiceTable.addCell(totalPriceCell);
209
	     
204
				totalitems = totalitems + lineitem.getQuantity();
210
	     table.addCell(logoCell);
205
			}
211
	     table.addCell(addressCell);
206
			PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
212
	     table.addCell(titleCell);
207
			totalCell.setColspan(4);
213
	     table.addCell(providerInfoTable);
208
			invoiceTable.addCell(totalCell);
214
	     table.addCell(customerTable);
209
			
215
	     table.addCell(invoiceTable);
210
			PdfPCell rupeesCell = new PdfPCell(new Phrase("Rs.", helveticaBold8));
216
	     table.addCell(new Phrase("If Undelivered:", helvetica8));
211
			rupeesCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
217
	     table.addCell(new Phrase("Return to:", helvetica8));
212
			invoiceTable.addCell(rupeesCell);
218
	     table.addCell(addressCell);
213
			
219
	     
214
			PdfPCell totalAmountCell = new PdfPCell(new Phrase(amountFormat.format(order.getTotal_amount()) + "", helveticaBold8));
220
	     table.addCell(new Phrase("Do not pay any extra charges to the Courier."));
215
			totalAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
221
	     
216
			invoiceTable.addCell(totalAmountCell);
222
	     table.setWidthPercentage(90.0f);
217
 
223
	     
218
			PdfPCell tinCell = new PdfPCell(new Phrase("TIN No: " + warehouse.getTinNumber(), helvetica8));
224
	     document.add(table);  
219
			tinCell.setColspan(6);
225
	     document.close();
220
			tinCell.setPadding(2);
226
	     baosPDF.close();
221
			invoiceTable.addCell(tinCell);
227
	     } catch (Exception e) {
222
 
228
	    	 e.printStackTrace();
223
			table.addCell(logoCell);
229
	     }
224
			table.addCell(titleCell);
230
	     return baosPDF;
225
			table.addCell(providerInfoTable);
231
	 }
226
			table.addCell(customerTable);
232
	
227
			table.addCell(invoiceTable);
-
 
228
			table.addCell(new Phrase("If undelivered, return to:", helvetica10));
-
 
229
			table.addCell(addressCell);
-
 
230
 
-
 
231
			table.addCell(new Phrase("Do not pay any extra charges to the Courier."));
-
 
232
 
-
 
233
			table.setWidthPercentage(90.0f);
-
 
234
 
-
 
235
			document.add(table);
-
 
236
			document.close();
-
 
237
			baosPDF.close();
-
 
238
		} catch (Exception e) {
-
 
239
			e.printStackTrace();
-
 
240
		}
-
 
241
		return baosPDF;
-
 
242
	}
-
 
243
 
233
	public static void main(String[] args) throws IOException {
244
	public static void main(String[] args) throws IOException {
-
 
245
		InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
234
		ByteArrayOutputStream baos = InvoiceGenerationService.generateInvoice(1);
246
		ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(13);
235
		File f = new File("/home/rajveer/Desktop/one.pdf");
247
		File f = new File("/home/ashish/Downloads/invoice-13.pdf");
236
		FileOutputStream fos = new FileOutputStream(f);
248
		FileOutputStream fos = new FileOutputStream(f);
237
		baos.writeTo(fos);
249
		baos.writeTo(fos);
238
	}
250
	}
239
}
251
}