Subversion Repositories SmartDukaan

Rev

Rev 7556 | Rev 7803 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2787 chandransh 1
package in.shop2020.hotspot.dashbaord.server;
2
 
3
import in.shop2020.config.ConfigException;
3044 chandransh 4
import in.shop2020.logistics.DeliveryType;
2787 chandransh 5
import in.shop2020.logistics.LogisticsServiceException;
5527 anupam.sin 6
import in.shop2020.logistics.PickUpType;
5556 rajveer 7
import in.shop2020.logistics.PickupStore;
2787 chandransh 8
import in.shop2020.logistics.Provider;
7792 anupam.sin 9
import in.shop2020.logistics.ProviderDetails;
7190 amar.kumar 10
import in.shop2020.model.v1.catalog.CatalogService;
11
import in.shop2020.model.v1.catalog.Item;
6746 rajveer 12
import in.shop2020.model.v1.inventory.BillingType;
5948 mandeep.dh 13
import in.shop2020.model.v1.inventory.InventoryServiceException;
5945 mandeep.dh 14
import in.shop2020.model.v1.inventory.Warehouse;
7528 rajveer 15
import in.shop2020.model.v1.order.AmazonOrder;
5527 anupam.sin 16
import in.shop2020.model.v1.order.Attribute;
2787 chandransh 17
import in.shop2020.model.v1.order.LineItem;
18
import in.shop2020.model.v1.order.Order;
7318 rajveer 19
import in.shop2020.model.v1.order.OrderSource;
4361 rajveer 20
import in.shop2020.model.v1.order.OrderStatus;
5527 anupam.sin 21
import in.shop2020.model.v1.order.OrderType;
7190 amar.kumar 22
import in.shop2020.thrift.clients.CatalogClient;
3132 rajveer 23
import in.shop2020.thrift.clients.LogisticsClient;
24
import in.shop2020.thrift.clients.TransactionClient;
2787 chandransh 25
import in.shop2020.thrift.clients.config.ConfigClient;
5948 mandeep.dh 26
import in.shop2020.thrift.clients.InventoryClient;
2787 chandransh 27
 
28
import java.io.ByteArrayOutputStream;
29
import java.io.File;
30
import java.io.FileOutputStream;
31
import java.io.IOException;
32
import java.text.DateFormat;
33
import java.text.DecimalFormat;
4361 rajveer 34
import java.util.ArrayList;
2787 chandransh 35
import java.util.Date;
36
import java.util.Enumeration;
37
import java.util.List;
38
import java.util.Locale;
39
import java.util.Properties;
40
import java.util.ResourceBundle;
41
 
42
import javax.servlet.ServletException;
43
import javax.servlet.ServletOutputStream;
44
import javax.servlet.http.HttpServlet;
45
import javax.servlet.http.HttpServletRequest;
46
import javax.servlet.http.HttpServletResponse;
47
 
7014 rajveer 48
import org.apache.commons.lang.StringUtils;
2787 chandransh 49
import org.apache.commons.lang.WordUtils;
50
import org.apache.thrift.TException;
51
import org.slf4j.Logger;
52
import org.slf4j.LoggerFactory;
7792 anupam.sin 53
import org.apache.thrift.transport.TTransportException;
2787 chandransh 54
 
55
import com.ibm.icu.text.RuleBasedNumberFormat;
56
 
57
import com.itextpdf.text.Document;
58
import com.itextpdf.text.Element;
59
import com.itextpdf.text.Font;
60
import com.itextpdf.text.FontFactory;
61
import com.itextpdf.text.FontFactoryImp;
62
import com.itextpdf.text.Image;
63
import com.itextpdf.text.Paragraph;
64
import com.itextpdf.text.Phrase;
65
import com.itextpdf.text.Rectangle;
66
import com.itextpdf.text.Font.FontFamily;
67
import com.itextpdf.text.pdf.BaseFont;
68
import com.itextpdf.text.pdf.PdfPCell;
69
import com.itextpdf.text.pdf.PdfPTable;
70
import com.itextpdf.text.pdf.PdfWriter;
71
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
72
 
73
@SuppressWarnings("serial")
74
public class InvoiceServlet extends HttpServlet {
7014 rajveer 75
 
76
	private static Logger logger = LoggerFactory.getLogger(InvoiceServlet.class);
77
 
78
	@Override
79
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
80
		long orderId = Long.parseLong(request.getParameter("id"));
81
		long warehouseId = Long.parseLong(request.getParameter("warehouse"));
82
		boolean withBill = false;
83
		boolean printAll = false;
84
		try {
85
			withBill = Boolean.parseBoolean(request.getParameter("withBill"));
86
		} catch(Exception e){
87
			logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
88
		}
89
		try {
90
			printAll = Boolean.parseBoolean(request.getParameter("printAll"));
91
		} catch(Exception e){
92
			logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
93
		}
94
 
95
		logger.info("Printing invoice for order id: " + orderId);
96
 
97
		InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
98
		ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, withBill, printAll, warehouseId);
99
		response.setContentType("application/pdf");
100
		response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
101
 
102
		ServletOutputStream sos;
103
		try {
104
			sos = response.getOutputStream();
105
			baos.writeTo(sos);
106
			sos.flush();
107
		} catch (IOException e) {
108
			logger.error("Encountered error while sending invoice response: ", e);
109
		}
110
	}
2787 chandransh 111
}
112
 
113
class InvoiceGenerationService {
114
 
7014 rajveer 115
	private static Logger logger = LoggerFactory.getLogger(InvoiceGenerationService.class);
2787 chandransh 116
 
7014 rajveer 117
	private TransactionClient tsc = null;
118
	private InventoryClient csc = null;
119
	private LogisticsClient lsc = null;
7190 amar.kumar 120
	private CatalogClient ctsc = null;
2787 chandransh 121
 
7014 rajveer 122
	private static Locale indianLocale = new Locale("en", "IN");
123
	private DecimalFormat amountFormat = new DecimalFormat("#,##0.00");
2787 chandransh 124
 
7014 rajveer 125
	private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
126
	private static final Font helvetica10 = FontFactory.getFont(FontFactory.HELVETICA, 10);
127
	private static final Font helvetica12 = FontFactory.getFont(FontFactory.HELVETICA, 12);
128
	private static final Font helvetica16 = FontFactory.getFont(FontFactory.HELVETICA, 16);
129
	private static final Font helvetica28 = FontFactory.getFont(FontFactory.HELVETICA, 28);
2787 chandransh 130
 
7014 rajveer 131
	private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
132
	private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
133
 
134
	private static final Properties properties = readProperties();
135
	private static final String ourAddress = properties.getProperty("sales_tax_address",
136
	"Spice Online Retail Pvt. Ltd.\nKhasra No. 819, Block-K\nMahipalpur, New Delhi-110037\n");
137
	private static final String tinNo = properties.getProperty("sales_tax_tin", "07250399732");
138
 
139
	private static final String delhiPincodePrefix = "11";
140
 
141
	private static Properties readProperties(){
142
		ResourceBundle resource = ResourceBundle.getBundle(InvoiceGenerationService.class.getName());
143
		Properties props = new Properties();
144
 
145
		Enumeration<String> keys = resource.getKeys();
146
		while (keys.hasMoreElements()) {
147
			String key = keys.nextElement();
148
			props.put(key, resource.getString(key));
149
		}
150
		return props;
151
	}
152
 
153
	public InvoiceGenerationService() {
154
		try {
155
			tsc = new TransactionClient();
156
			csc = new InventoryClient();
157
			lsc = new LogisticsClient();
7190 amar.kumar 158
			ctsc = new CatalogClient();
7014 rajveer 159
		} catch (Exception e) {
160
			logger.error("Error while instantiating thrift clients.", e);
161
		}
162
	}
163
 
164
	public ByteArrayOutputStream generateInvoice(long orderId, boolean withBill, boolean printAll, long warehouseId) {
165
		ByteArrayOutputStream baosPDF = null;
166
		in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
167
		in.shop2020.model.v1.inventory.InventoryService.Client iclient = csc.getClient();
168
		in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
169
 
170
 
171
		try {
172
			baosPDF = new ByteArrayOutputStream();
173
 
174
			Document document = new Document();
175
			PdfWriter.getInstance(document, baosPDF);
176
			document.addAuthor("shop2020");
177
			//document.addTitle("Invoice No: " + order.getInvoice_number());
178
			document.open();
179
 
180
			List<Order> orders = new ArrayList<Order>();
181
			if(printAll){
182
				try {
183
					List<OrderStatus> statuses = new ArrayList<OrderStatus>();
184
					statuses.add(OrderStatus.ACCEPTED);
185
					orders = tclient.getAllOrders(statuses, 0, 0, warehouseId);
186
				} catch (Exception e) {
187
					logger.error("Error while getting order information", e);
188
					return baosPDF; 
4361 rajveer 189
				}
7014 rajveer 190
			}else{
191
				orders.add(tclient.getOrder(orderId));	
192
			}
193
			boolean isFirst = true;
5387 rajveer 194
 
7014 rajveer 195
			for(Order order: orders){
196
				Warehouse warehouse = null;
197
				Provider provider = null;
198
				String destCode = null;
199
				int barcodeFontSize = 0;
200
				try {
201
					warehouse = iclient.getWarehouse(order.getWarehouse_id());
202
					long providerId = order.getLogistics_provider_id();
203
					provider = logisticsClient.getProvider(providerId);
204
					if(provider.getPickup().equals(PickUpType.SELF) || provider.getPickup().equals(PickUpType.RUNNER))
205
						destCode = provider.getPickup().toString();
206
					else
207
						destCode = logisticsClient.getDestinationCode(providerId, order.getCustomer_pincode());
2787 chandransh 208
 
7014 rajveer 209
					barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
210
				} catch (InventoryServiceException ise) {
211
					logger.error("Error while getting the warehouse information.", ise);
212
					return baosPDF;
213
				} catch (LogisticsServiceException lse) {
214
					logger.error("Error while getting the provider information.", lse);
215
					return baosPDF;
216
				} catch (ConfigException ce) {
217
					logger.error("Error while getting the fontsize for the given provider", ce);
218
					return baosPDF;
219
				} catch (TException te) {
220
					logger.error("Error while getting some essential information from the services", te);
221
					return baosPDF;
222
				}
4361 rajveer 223
 
7014 rajveer 224
				if(printAll && warehouse.getBillingType() == BillingType.OURS_EXTERNAL){
225
					if(isFirst){
226
						document.add(getFixedTextTable(16, "Spice Online Retail Pvt Ltd"));
227
						isFirst = false;
228
					}
229
					document.add(getExtraInfoTable(order, provider, 16, warehouse.getBillingType()));
230
					continue;
231
				}
2787 chandransh 232
 
7014 rajveer 233
				PdfPTable dispatchAdviceTable = getDispatchAdviceTable(order, warehouse, provider, barcodeFontSize, destCode, withBill);
234
				dispatchAdviceTable.setSpacingAfter(10.0f);
235
				dispatchAdviceTable.setWidthPercentage(90.0f);
5684 mandeep.dh 236
 
7014 rajveer 237
				document.add(dispatchAdviceTable);
238
				if(withBill){
239
					PdfPTable taxTable = getTaxCumRetailInvoiceTable(order, provider);
240
					taxTable.setSpacingBefore(5.0f);
241
					taxTable.setWidthPercentage(90.0f);
242
					document.add(new DottedLineSeparator());
243
					document.add(taxTable);
244
				}else{
245
					PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
246
					extraInfoTable.setSpacingBefore(5.0f);
247
					extraInfoTable.setWidthPercentage(90.0f);
248
					document.add(new DottedLineSeparator());
249
					document.add(extraInfoTable);
250
				}
251
				document.newPage();
252
			}
253
			document.close();
254
			baosPDF.close();
255
			// Adding facility to store the bill on the local directory. This will happen for only for Mahipalpur warehouse.
256
			if(withBill && !printAll){
7079 rajveer 257
				String strOrderId = StringUtils.repeat("0", 10-String.valueOf(orderId).length()) + orderId;  
7014 rajveer 258
				String dirPath = "/SaholicInvoices" + File.separator + strOrderId.substring(0, 2) + File.separator + strOrderId.substring(2, 4) + File.separator + strOrderId.substring(4, 6);
259
				String filename = dirPath + File.separator + orderId + ".pdf";
260
				File dirFile = new File(dirPath);
261
				if(!dirFile.exists()){
262
					dirFile.mkdirs();
263
				}
264
				File f = new File(filename);
265
				FileOutputStream fos = new FileOutputStream(f);
266
				baosPDF.writeTo(fos);
267
			}
268
		} catch (Exception e) {
269
			logger.error("Error while generating Invoice: ", e);
270
		}
271
		return baosPDF;
272
	}
3065 chandransh 273
 
7014 rajveer 274
	private PdfPTable getDispatchAdviceTable(Order order, Warehouse warehouse, Provider provider, float barcodeFontSize, String destCode, boolean withBill){
275
		Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
2787 chandransh 276
 
7014 rajveer 277
		PdfPTable table = new PdfPTable(1);
278
		table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
2787 chandransh 279
 
7014 rajveer 280
		PdfPTable logoTable = new PdfPTable(2);
7318 rajveer 281
		addLogoTable(logoTable, order);
282
 
7014 rajveer 283
		PdfPCell titleCell = getTitleCell();
284
		PdfPTable customerTable = getCustomerAddressTable(order, destCode, false, helvetica12, false);
285
		PdfPTable providerInfoTable = getProviderTable(order, provider, barCodeFont);
2787 chandransh 286
 
7014 rajveer 287
		PdfPTable dispatchTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
288
		dispatchTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
289
		dispatchTable.addCell(customerTable);
290
		dispatchTable.addCell(new Phrase(" "));
291
		dispatchTable.addCell(providerInfoTable);
2787 chandransh 292
 
7014 rajveer 293
		Warehouse shippingLocation = CatalogUtils.getWarehouse(warehouse.getShippingWarehouseId());
294
		PdfPTable invoiceTable = getTopInvoiceTable(order, shippingLocation.getTinNumber());
295
		PdfPCell addressCell = getAddressCell(shippingLocation.getLocation() +
296
				"\nPIN " + warehouse.getPincode() + "\n\n");
2787 chandransh 297
 
7014 rajveer 298
		PdfPTable chargesTable = new PdfPTable(1);
299
		chargesTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
300
		chargesTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
301
		if(order.isLogisticsCod()){
7318 rajveer 302
			chargesTable.addCell(new Phrase("AMOUNT TO BE COLLECTED : Rs " + (order.getTotal_amount()-order.getGvAmount()-order.getAdvanceAmount()), helveticaBold12));
7014 rajveer 303
			chargesTable.addCell(new Phrase("RTO ADDRESS:DEL/HPW/111116"));
304
		} else {
305
			chargesTable.addCell(new Phrase("Do not pay any extra charges to the Courier."));  
306
		}
2787 chandransh 307
 
7014 rajveer 308
		PdfPTable addressAndNoteTable = new PdfPTable(new float[]{0.3f, 0.7f});
309
		addressAndNoteTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
310
		addressAndNoteTable.addCell(addressCell);
311
		addressAndNoteTable.addCell(chargesTable);
2787 chandransh 312
 
7014 rajveer 313
		table.addCell(logoTable);
314
		table.addCell(titleCell);
315
		table.addCell(dispatchTable);
316
		table.addCell(invoiceTable);
317
		table.addCell(new Phrase("If undelivered, return to:", helvetica10));
318
		table.addCell(addressAndNoteTable);
319
		return table;
320
	}
2787 chandransh 321
 
7318 rajveer 322
	private void addLogoTable(PdfPTable logoTable, Order order) {
323
		logoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
324
		logoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
325
		logoTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM);
326
 
327
		PdfPCell logoCell;
328
		String logoPath;
329
 
7556 rajveer 330
		if(order.getSource() == OrderSource.STORE.getValue()){
331
			logoCell = new PdfPCell(new Phrase(""));
332
 
333
			logoCell.setBorder(Rectangle.NO_BORDER);
334
			logoCell.setHorizontalAlignment(Element.ALIGN_LEFT);
335
 
336
			logoTable.addCell(logoCell);
337
		}else{
7318 rajveer 338
			logoPath = InvoiceGenerationService.class.getResource("/logo.jpg").getPath();
339
 
340
			try {
341
				logoCell = new PdfPCell(Image.getInstance(logoPath), false);
342
			} catch (Exception e) {
343
				//Too Many exceptions to catch here: BadElementException, MalformedURLException and IOException
344
				logger.warn("Couldn't load the Saholic logo: ", e);
345
				logoCell = new PdfPCell(new Phrase("Saholic Logo"));
346
			}
347
			logoCell.setBorder(Rectangle.NO_BORDER);
348
			logoCell.setHorizontalAlignment(Element.ALIGN_LEFT);
349
 
350
			logoTable.addCell(logoCell);
351
 
352
		}
353
	}
354
 
7014 rajveer 355
	private Font getBarCodeFont(Provider provider, float barcodeFontSize) {
356
		String fontPath = InvoiceGenerationService.class.getResource("/" + provider.getName().toLowerCase() + "/barcode.TTF").getPath();
357
		FontFactoryImp ttfFontFactory = new FontFactoryImp();
358
		ttfFontFactory.register(fontPath, "barcode");
359
		Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
360
		return barCodeFont;
361
	}
2787 chandransh 362
 
7014 rajveer 363
	private PdfPCell getTitleCell() {
364
		PdfPCell titleCell = new PdfPCell(new Phrase("Dispatch Advice", helveticaBold12));
365
		titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
366
		titleCell.setBorder(Rectangle.NO_BORDER);
367
		return titleCell;
368
	}
2787 chandransh 369
 
7014 rajveer 370
	private PdfPTable getProviderTable(Order order, Provider provider, Font barCodeFont) {
371
		PdfPTable providerInfoTable = new PdfPTable(1);
372
		providerInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
7318 rajveer 373
		if(order.isLogisticsCod()){
374
			PdfPCell deliveryTypeCell = new PdfPCell(new Phrase("COD   ", helvetica28));
375
			deliveryTypeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
376
			deliveryTypeCell.setBorder(Rectangle.NO_BORDER);
377
			providerInfoTable.addCell(deliveryTypeCell);
378
		}
379
 
380
 
381
 
382
 
7014 rajveer 383
		PdfPCell providerNameCell = new PdfPCell(new Phrase(provider.getName(), helveticaBold12));
384
		providerNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
385
		providerNameCell.setBorder(Rectangle.NO_BORDER);
386
 
387
		PdfPCell awbNumberCell = new PdfPCell(new Paragraph("*" + order.getAirwaybill_no() + "*", barCodeFont));
388
		awbNumberCell.setPaddingTop(20.0f);
389
		awbNumberCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
390
		awbNumberCell.setBorder(Rectangle.NO_BORDER);
391
 
392
		providerInfoTable.addCell(providerNameCell);
393
		providerInfoTable.addCell(awbNumberCell);
7792 anupam.sin 394
 
395
		Warehouse warehouse = null;
396
		try{
397
    		InventoryClient isc = new InventoryClient();
398
    		Warehouse warehouse = isc.getClient().getWarehouse(order.getWarehouse_id());
399
		catch(Exception e) {
400
		    logger.error("Unable to get warehouse for id : " + order.getWarehouse_id(), e);
401
		    throw e;
402
		}
403
		String accountNo = "";
404
		DeliveryType dt =  DeliveryType.PREPAID;
405
        if (order.isLogisticsCod()) {
406
            dt = DeliveryType.COD;
407
        }
408
        for (ProviderDetails detail : provider.getDetails()) {
409
            if(in.shop2020.model.v1.inventory.WarehouseLocation.findByValue((int) detail.getLogisticLocation()) == warehouse.getLogisticsLocation() && detail.getDeliveryType() == dt) {
410
                providerInfoTable.addCell(new Phrase("Account No : " + detail.getAccountNo(), helvetica8));
411
            }
412
        }
413
 
7014 rajveer 414
		Date awbDate;
415
		if(order.getBilling_timestamp() == 0){
416
			awbDate = new Date();
417
		}else{
418
			awbDate = new Date(order.getBilling_timestamp());
419
		}
420
		providerInfoTable.addCell(new Phrase("AWB Date   : " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(awbDate), helvetica8));
421
		providerInfoTable.addCell(new Phrase("Weight         : " + order.getTotal_weight() + " Kg", helvetica8));
422
		return providerInfoTable;
423
	}
424
 
425
	private PdfPTable getTopInvoiceTable(Order order, String tinNo){
426
		PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.2f, 0.3f, 0.1f, 0.1f, 0.1f});
427
		invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
428
 
429
		invoiceTable.addCell(getInvoiceTableHeader(6));
430
 
431
		invoiceTable.addCell(new Phrase("Order No", helvetica8));
432
		invoiceTable.addCell(new Phrase("Paymode", helvetica8));
433
		invoiceTable.addCell(new Phrase("Product Name", helvetica8));
434
		invoiceTable.addCell(new Phrase("Quantity", helvetica8));
435
		invoiceTable.addCell(new Phrase("Rate", helvetica8));
436
		invoiceTable.addCell(new Phrase("Amount", helvetica8));
437
		populateTopInvoiceTable(order, invoiceTable);
438
 
439
 
440
		if(order.getInsurer() > 0) {
441
			invoiceTable.addCell(getInsuranceCell(4));
442
			invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
443
			invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
444
		}
445
 
7318 rajveer 446
		if(order.getSource() == OrderSource.STORE.getValue()) {
447
			invoiceTable.addCell(getAdvanceAmountCell(4));
448
			invoiceTable.addCell(getPriceCell(order.getAdvanceAmount()));
449
			invoiceTable.addCell(getPriceCell(order.getAdvanceAmount()));
450
		}
451
 
7014 rajveer 452
		invoiceTable.addCell(getTotalCell(4));      
453
		invoiceTable.addCell(getRupeesCell());
7318 rajveer 454
		invoiceTable.addCell(getTotalAmountCell(order.getTotal_amount()-order.getGvAmount()-order.getAdvanceAmount()));
7014 rajveer 455
 
456
		PdfPCell tinCell = new PdfPCell(new Phrase("TIN NO. " + tinNo, helvetica8));
457
		tinCell.setColspan(6);
458
		tinCell.setPadding(2);
459
		invoiceTable.addCell(tinCell);
460
 
461
		return invoiceTable;
462
	}
463
 
464
	private void populateTopInvoiceTable(Order order, PdfPTable invoiceTable) {
465
		List<LineItem> lineitems = order.getLineitems();
466
		for (LineItem lineitem : lineitems) {
467
			invoiceTable.addCell(new Phrase(order.getId() + "", helvetica8));
468
			if(order.getPickupStoreId() > 0 && order.isCod() == true)
469
				invoiceTable.addCell(new Phrase("In-Store", helvetica8));
470
			else if (order.isCod())
471
				invoiceTable.addCell(new Phrase("COD", helvetica8));
472
			else
473
				invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
7318 rajveer 474
 
7190 amar.kumar 475
			invoiceTable.addCell(getProductNameCell(lineitem, false, order.getFreebieItemId()));
2787 chandransh 476
 
7014 rajveer 477
			invoiceTable.addCell(new Phrase(lineitem.getQuantity() + "", helvetica8));
2787 chandransh 478
 
7014 rajveer 479
			invoiceTable.addCell(getPriceCell(lineitem.getUnit_price()-order.getGvAmount()));
480
 
481
			invoiceTable.addCell(getPriceCell(lineitem.getTotal_price()-order.getGvAmount()));
482
		}
483
	}
484
 
485
	private PdfPCell getAddressCell(String address) {
486
		Paragraph addressParagraph = new Paragraph(address, new Font(FontFamily.TIMES_ROMAN, 8f));
487
		PdfPCell addressCell = new PdfPCell();
488
		addressCell.addElement(addressParagraph);
489
		addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
490
		addressCell.setBorder(Rectangle.NO_BORDER);
491
		return addressCell;
492
	}
493
 
494
	private PdfPTable getTaxCumRetailInvoiceTable(Order order, Provider provider){
495
		PdfPTable taxTable = new PdfPTable(1);
496
		Phrase phrase = null;
497
		taxTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
498
		taxTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
499
 
7318 rajveer 500
//		PdfPTable logoTable = new PdfPTable(2);
501
//		addLogoTable(logoTable, order);
502
 
7014 rajveer 503
		if (order.getOrderType().equals(OrderType.B2B)) {
504
			phrase = new Phrase("TAX INVOICE", helveticaBold12);
505
		} else {
506
			phrase = new Phrase("RETAIL INVOICE", helveticaBold12);
507
		}
508
		PdfPCell retailInvoiceTitleCell = new PdfPCell(phrase);
509
		retailInvoiceTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
510
		retailInvoiceTitleCell.setBorder(Rectangle.NO_BORDER);
511
 
512
		Paragraph sorlAddress = new Paragraph(ourAddress + "TIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f, Element.ALIGN_CENTER));
513
		PdfPCell sorlAddressCell = new PdfPCell(sorlAddress);
514
		sorlAddressCell.addElement(sorlAddress);
515
		sorlAddressCell.setHorizontalAlignment(Element.ALIGN_CENTER);
516
 
517
		PdfPTable customerAddress = getCustomerAddressTable(order, null, true, helvetica8, true);
518
		PdfPTable orderDetails = getOrderDetails(order, provider);
519
 
520
		PdfPTable addrAndOrderDetailsTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
521
		addrAndOrderDetailsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
522
		addrAndOrderDetailsTable.addCell(customerAddress);
523
		addrAndOrderDetailsTable.addCell(new Phrase(" "));
524
		addrAndOrderDetailsTable.addCell(orderDetails);
525
 
526
		boolean isVAT = order.getCustomer_pincode().startsWith(delhiPincodePrefix);
527
		PdfPTable invoiceTable = getBottomInvoiceTable(order, isVAT);
528
 
529
		PdfPCell disclaimerCell = new PdfPCell(new Phrase("Goods once sold will not be taken back.\nAll disputes subject to Delhi Jurisdiction.\nThis is a Computer generated Invoice.", helvetica8));
530
		disclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
531
		disclaimerCell.setBorder(Rectangle.NO_BORDER);
7318 rajveer 532
 
533
		//taxTable.addCell(logoTable);
7014 rajveer 534
		taxTable.addCell(retailInvoiceTitleCell);
535
		taxTable.addCell(sorlAddress);
536
		taxTable.addCell(addrAndOrderDetailsTable);
537
		taxTable.addCell(invoiceTable);
538
		taxTable.addCell(disclaimerCell);
539
 
540
		return taxTable;
541
	}
542
 
543
	private PdfPTable getCustomerAddressTable(Order order, String destCode, boolean showPaymentMode, Font font, boolean forInvoce){
544
		PdfPTable customerTable = new PdfPTable(1);
545
		customerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
546
		if(forInvoce || order.getPickupStoreId() == 0){
547
			customerTable.addCell(new Phrase(order.getCustomer_name(), font));
548
			customerTable.addCell(new Phrase(order.getCustomer_address1(), font));
549
			customerTable.addCell(new Phrase(order.getCustomer_address2(), font));
550
			customerTable.addCell(new Phrase(order.getCustomer_city() + "," + order.getCustomer_state(), font));
551
			if(destCode != null)
552
				customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + destCode, helvetica16));
553
			else
554
				customerTable.addCell(new Phrase(order.getCustomer_pincode(), font));
555
			customerTable.addCell(new Phrase("Phone :" + order.getCustomer_mobilenumber(), font));
556
		}else{
557
			try {
5556 rajveer 558
				in.shop2020.logistics.LogisticsService.Client lclient = (new LogisticsClient()).getClient();
7014 rajveer 559
				PickupStore store = lclient.getPickupStore(order.getPickupStoreId());
560
				customerTable.addCell(new Phrase(order.getCustomer_name() + " \nc/o " + store.getName(), font));
561
				customerTable.addCell(new Phrase(store.getLine1(), font));
562
				customerTable.addCell(new Phrase(store.getLine2(), font));
563
				customerTable.addCell(new Phrase(store.getCity() + "," + store.getState(), font));
564
				if(destCode != null)
565
					customerTable.addCell(new Phrase(store.getPin() + " - " + destCode, helvetica16));
566
				else
567
					customerTable.addCell(new Phrase(store.getPin(), font));
568
				customerTable.addCell(new Phrase("Phone :" + store.getPhone(), font));
5556 rajveer 569
			} catch (TException e) {
570
				// TODO Auto-generated catch block
571
				e.printStackTrace();
572
			}
5527 anupam.sin 573
 
7014 rajveer 574
		}
575
 
576
		if(order.getOrderType().equals(OrderType.B2B)) {
577
			String tin = null;
578
			in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
579
			List<Attribute> attributes;
580
			try {
581
				attributes = tclient.getAllAttributesForOrderId(order.getId());
582
 
583
				for(Attribute attribute : attributes) {
584
					if(attribute.getName().equals("tinNumber")) {
585
						tin = attribute.getValue();
586
					}
587
				}
588
				if (tin != null) {
589
					customerTable.addCell(new Phrase("TIN :" + tin, font));
590
				}
591
 
592
			} catch (Exception e) {
593
				logger.error("Error while getting order attributes", e);
594
			}
595
		}
596
		/*
2787 chandransh 597
        if(showPaymentMode){
598
            customerTable.addCell(new Phrase(" ", font));
599
            customerTable.addCell(new Phrase("Payment Mode: Prepaid", font));
5856 anupam.sin 600
        }*/
7014 rajveer 601
		return customerTable;
602
	}
2787 chandransh 603
 
7014 rajveer 604
	private PdfPTable getOrderDetails(Order order, Provider provider){
605
		PdfPTable orderTable = new PdfPTable(new float[]{0.4f, 0.6f});
606
		orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
2787 chandransh 607
 
7014 rajveer 608
		orderTable.addCell(new Phrase("Invoice No:", helvetica8));
609
		orderTable.addCell(new Phrase(order.getInvoice_number(), helvetica8));
2787 chandransh 610
 
7014 rajveer 611
		orderTable.addCell(new Phrase("Date:", helvetica8));
612
		orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
2787 chandransh 613
 
7014 rajveer 614
		orderTable.addCell(new Phrase("Order ID:", helvetica8));
615
		orderTable.addCell(new Phrase("" + order.getId(), helvetica8));
2787 chandransh 616
 
7528 rajveer 617
		if(order.getSource() == OrderSource.AMAZON.getValue()){
618
			AmazonOrder aorder = null;
619
			try {
620
				aorder = tsc.getClient().getAmazonOrder(order.getId());
621
			} catch (TException e) {
622
				logger.error("Error while getting amazon order", e);
623
			}
624
			orderTable.addCell(new Phrase("Amazon Order ID:", helvetica8));
625
			orderTable.addCell(new Phrase(aorder.getAmazonOrderCode(), helvetica8));
626
		}
627
 
7014 rajveer 628
		orderTable.addCell(new Phrase("Order Date:", helvetica8));
629
		orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getCreated_timestamp())), helvetica8));
2787 chandransh 630
 
7014 rajveer 631
		orderTable.addCell(new Phrase("Courier:", helvetica8));
632
		orderTable.addCell(new Phrase(provider.getName(), helvetica8));
2787 chandransh 633
 
7014 rajveer 634
		orderTable.addCell(new Phrase("AWB No:", helvetica8));
635
		orderTable.addCell(new Phrase(order.getAirwaybill_no(), helvetica8));
2787 chandransh 636
 
7014 rajveer 637
		orderTable.addCell(new Phrase("AWB Date:", helvetica8));
638
		orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
2787 chandransh 639
 
7014 rajveer 640
		return orderTable;
641
	}
2787 chandransh 642
 
7014 rajveer 643
	private PdfPTable getBottomInvoiceTable(Order order, boolean isVAT){
644
		PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.5f, 0.1f, 0.1f, 0.1f});
645
		invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
2787 chandransh 646
 
7014 rajveer 647
		invoiceTable.addCell(getInvoiceTableHeader(5));
4262 rajveer 648
 
7014 rajveer 649
		invoiceTable.addCell(new Phrase("Sl. No.", helveticaBold8));
650
		invoiceTable.addCell(new Phrase("Description", helveticaBold8));
651
		invoiceTable.addCell(new Phrase("Quantity", helveticaBold8));
652
		invoiceTable.addCell(new Phrase("Rate (Rs)", helveticaBold8));
653
		invoiceTable.addCell(new Phrase("Amount (Rs)", helveticaBold8));
654
		LineItem lineItem = order.getLineitems().get(0);
655
		double orderAmount = order.getTotal_amount();
656
		double rate = lineItem.getVatRate();
7057 amar.kumar 657
		double salesTax = (rate * (orderAmount - order.getInsuranceAmount()))/(100 + rate);
6750 rajveer 658
 
7014 rajveer 659
		populateBottomInvoiceTable(order, invoiceTable, rate);
6750 rajveer 660
 
7014 rajveer 661
		PdfPCell salesTaxCell = getPriceCell(salesTax);
662
 
663
		invoiceTable.addCell(getVATLabelCell(isVAT));
664
		invoiceTable.addCell(new Phrase(rate + "%", helvetica8));
665
		invoiceTable.addCell(salesTaxCell);
666
 
667
		if(order.getInsurer() > 0) {
668
			invoiceTable.addCell(getInsuranceCell(3));
669
			invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
670
			invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
671
		}
672
 
673
		invoiceTable.addCell(getEmptyCell(5));
674
 
675
		invoiceTable.addCell(getTotalCell(3));
676
		invoiceTable.addCell(getRupeesCell());
677
		invoiceTable.addCell(getTotalAmountCell(orderAmount));
678
 
679
		invoiceTable.addCell(new Phrase("Amount in Words:", helvetica8));
680
		invoiceTable.addCell(getAmountInWordsCell(orderAmount));
681
 
682
		invoiceTable.addCell(getEOECell(5));
683
 
684
		return invoiceTable;
685
	}
686
 
687
	private PdfPCell getInvoiceTableHeader(int colspan) {
688
		PdfPCell invoiceTableHeader = new PdfPCell(new Phrase("Order Details:", helveticaBold12));
689
		invoiceTableHeader.setBorder(Rectangle.NO_BORDER);
690
		invoiceTableHeader.setColspan(colspan);
691
		invoiceTableHeader.setPaddingTop(10);
692
		return invoiceTableHeader;
693
	}
694
 
695
	private void populateBottomInvoiceTable(Order order, PdfPTable invoiceTable, double rate) {
696
		for (LineItem lineitem : order.getLineitems()) {
697
			invoiceTable.addCell(new Phrase("" + order.getId() , helvetica8));
698
 
7190 amar.kumar 699
			invoiceTable.addCell(getProductNameCell(lineitem, true, order.getFreebieItemId()));
7014 rajveer 700
 
701
			invoiceTable.addCell(new Phrase("" + lineitem.getQuantity(), helvetica8));
702
 
703
			double itemPrice = lineitem.getUnit_price();
704
			double showPrice = (100 * itemPrice)/(100 + rate);
705
			invoiceTable.addCell(getPriceCell(showPrice)); //Unit Price Cell
706
 
707
			double totalPrice = lineitem.getTotal_price();
708
			showPrice = (100 * totalPrice)/(100 + rate);
709
			invoiceTable.addCell(getPriceCell(showPrice));  //Total Price Cell
710
		}
711
	}
712
 
7190 amar.kumar 713
	private PdfPCell getProductNameCell(LineItem lineitem, boolean appendIMEI, Long freebieItemId) {
7014 rajveer 714
		String itemName = getItemDisplayName(lineitem, appendIMEI);
7190 amar.kumar 715
		if(freebieItemId!=null && freebieItemId!=0){
716
			try {
717
				CatalogService.Client catalogClient = ctsc.getClient();
718
				Item item = catalogClient.getItem(freebieItemId);
719
				itemName = itemName + "\n(Free Item: " + item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + ")";
720
			} catch(Exception tex) {
721
				logger.error("Not able to get Freebie Item Details for ItemId:" + freebieItemId, tex);
722
			}
723
		}
7014 rajveer 724
		PdfPCell productNameCell = new PdfPCell(new Phrase(itemName, helvetica8));
725
		productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
726
		return productNameCell;
727
	}
728
 
729
	private PdfPCell getPriceCell(double price) {
730
		PdfPCell totalPriceCell = new PdfPCell(new Phrase(amountFormat.format(price), helvetica8));
731
		totalPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
732
		return totalPriceCell;
733
	}
734
 
735
	private PdfPCell getVATLabelCell(boolean isVAT) {
736
		PdfPCell vatCell = null;
737
		if(isVAT){
738
			vatCell = new PdfPCell(new Phrase("VAT", helveticaBold8));
739
		} else {
740
			vatCell = new PdfPCell(new Phrase("CST", helveticaBold8));
741
		}
742
		vatCell.setColspan(3);
743
		vatCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
744
		return vatCell;
745
	}
746
 
7318 rajveer 747
	private PdfPCell getAdvanceAmountCell(int colspan) {
748
		PdfPCell insuranceCell = null;
749
		insuranceCell = new PdfPCell(new Phrase("Advance Amount Received", helvetica8));
750
		insuranceCell.setColspan(colspan);
751
		insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
752
		return insuranceCell;
753
	}
754
 
7014 rajveer 755
	private PdfPCell getInsuranceCell(int colspan) {
756
		PdfPCell insuranceCell = null;
757
		insuranceCell = new PdfPCell(new Phrase("1 Year WorldWide Theft Insurance", helvetica8));
758
		insuranceCell.setColspan(colspan);
759
		insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
760
		return insuranceCell;
761
	}
762
 
763
	private PdfPCell getEmptyCell(int colspan) {
764
		PdfPCell emptyCell = new PdfPCell(new Phrase(" ", helvetica8));
765
		emptyCell.setColspan(colspan);
766
		return emptyCell;
767
	}
768
 
769
	private PdfPCell getTotalCell(int colspan) {
770
		PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
771
		totalCell.setColspan(colspan);
772
		totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
773
		return totalCell;
774
	}
775
 
776
	private PdfPCell getRupeesCell() {
777
		PdfPCell rupeesCell = new PdfPCell(new Phrase("Rs.", helveticaBold8));
778
		rupeesCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
779
		return rupeesCell;
780
	}
781
 
782
	private PdfPCell getTotalAmountCell(double orderAmount) {
783
		PdfPCell totalAmountCell = new PdfPCell(new Phrase(amountFormat.format(orderAmount), helveticaBold8));
784
		totalAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
785
		return totalAmountCell;
786
	}
787
 
788
	/**
789
	 * This method uses ICU4J libraries to convert the given amount into words
790
	 * of Indian locale.
791
	 * 
792
	 * @param orderAmount
793
	 *            The amount to convert.
794
	 * @return the string representation of the given amount.
795
	 */
796
	private PdfPCell getAmountInWordsCell(double orderAmount) {
797
		RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
798
		StringBuilder amountInWords = new StringBuilder("Rs. ");
799
		amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)orderAmount)));
800
		amountInWords.append(" and ");
801
		amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)(orderAmount*100)%100)));
802
		amountInWords.append(" paise");
803
 
804
		PdfPCell amountInWordsCell= new PdfPCell(new Phrase(amountInWords.toString(), helveticaBold8));
805
		amountInWordsCell.setColspan(4);
806
		return amountInWordsCell;
807
	}
808
 
809
	/**
810
	 * Returns the item name to be displayed in the invoice table.
811
	 * 
812
	 * @param lineitem
813
	 *            The line item whose name has to be displayed
814
	 * @param appendIMEI
815
	 *            Whether to attach the IMEI No. to the item name
816
	 * @return The name to be displayed for the given line item.
817
	 */
818
	private String getItemDisplayName(LineItem lineitem, boolean appendIMEI){
819
		StringBuffer itemName = new StringBuffer();
820
		if(lineitem.getBrand()!= null)
821
			itemName.append(lineitem.getBrand() + " ");
822
		if(lineitem.getModel_name() != null)
823
			itemName.append(lineitem.getModel_name() + " ");
824
		if(lineitem.getModel_number() != null )
825
			itemName.append(lineitem.getModel_number() + " ");
826
		if(lineitem.getColor() != null && !lineitem.getColor().trim().equals("NA"))
827
			itemName.append("("+lineitem.getColor()+")");
828
		if(appendIMEI && lineitem.isSetSerial_number()){
829
			itemName.append("\nIMEI No. " + lineitem.getSerial_number());
830
		}
831
 
832
		return itemName.toString();
833
	}
834
 
835
	/**
836
	 * 
837
	 * @param colspan
838
	 * @return a PdfPCell containing the E&amp;OE text and spanning the given
839
	 *         no. of columns
840
	 */
841
	private PdfPCell getEOECell(int colspan) {
842
		PdfPCell eoeCell = new PdfPCell(new Phrase("E & O.E", helvetica8));
843
		eoeCell.setColspan(colspan);
844
		eoeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
845
		return eoeCell;
846
	}
847
 
848
	private PdfPTable getExtraInfoTable(Order order, Provider provider, float barcodeFontSize, BillingType billingType){
849
		PdfPTable extraInfoTable = new PdfPTable(1);
850
		extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
851
		extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
852
 
853
		String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
854
		FontFactoryImp ttfFontFactory = new FontFactoryImp();
855
		ttfFontFactory.register(fontPath, "barcode");
856
		Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
857
 
858
		PdfPCell extraInfoCell;
859
		if(billingType == BillingType.EXTERNAL){
860
			extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "*        *" + order.getCustomer_name() + "*        *"  + order.getTotal_amount() + "*", barCodeFont));
861
		}else{
862
			extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "*        *" + order.getLineitems().get(0).getTransfer_price() + "*", barCodeFont));	
863
		}
864
 
865
		extraInfoCell.setPaddingTop(20.0f);
866
		extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
867
		extraInfoCell.setBorder(Rectangle.NO_BORDER);
868
 
869
		extraInfoTable.addCell(extraInfoCell);
870
 
871
 
872
		return extraInfoTable;
873
	}
874
 
875
	private PdfPTable getFixedTextTable(float barcodeFontSize, String printText){
876
		PdfPTable extraInfoTable = new PdfPTable(1);
877
		extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
878
		extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
879
 
880
		String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
881
		FontFactoryImp ttfFontFactory = new FontFactoryImp();
882
		ttfFontFactory.register(fontPath, "barcode");
883
		Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
884
 
885
		PdfPCell extraInfoCell = new PdfPCell(new Paragraph( "*" + printText + "*", barCodeFont));
886
 
887
		extraInfoCell.setPaddingTop(20.0f);
888
		extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
889
		extraInfoCell.setBorder(Rectangle.NO_BORDER);
890
 
891
		extraInfoTable.addCell(extraInfoCell);
892
 
893
		return extraInfoTable;
894
	}
895
 
896
	public static void main(String[] args) throws IOException {
897
		InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
7318 rajveer 898
		long orderId = 356324;
899
		ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, true, false, 1);
7014 rajveer 900
		String userHome = System.getProperty("user.home");
901
		File f = new File(userHome + "/invoice-" + orderId + ".pdf");
902
		FileOutputStream fos = new FileOutputStream(f);
903
		baos.writeTo(fos);
904
		System.out.println("Invoice generated.");
905
	}
2787 chandransh 906
}