Subversion Repositories SmartDukaan

Rev

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