Subversion Repositories SmartDukaan

Rev

Rev 12653 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
12653 manish.sha 1
package in.shop2020.support.controllers;
2
 
3
 
4
import java.awt.image.BufferedImage;
5
import java.io.BufferedReader;
6
import java.io.ByteArrayOutputStream;
7
import java.io.File;
8
import java.io.FileOutputStream;
9
import java.io.FileReader;
10
import java.io.IOException;
11
import java.io.OutputStream;
12
import java.text.DateFormat;
13
import java.text.DecimalFormat;
14
import java.util.ArrayList;
15
import java.util.Date;
16
import java.util.HashMap;
17
import java.util.List;
18
import java.util.Locale;
19
import java.util.Map;
20
 
21
import in.shop2020.config.ConfigException;
22
import in.shop2020.logistics.DeliveryType;
23
import in.shop2020.logistics.LogisticsServiceException;
24
import in.shop2020.logistics.PickUpType;
25
import in.shop2020.logistics.PickupStore;
26
import in.shop2020.logistics.Provider;
27
import in.shop2020.logistics.ProviderDetails;
28
import in.shop2020.model.v1.catalog.CatalogService;
29
import in.shop2020.model.v1.catalog.Item;
30
import in.shop2020.model.v1.catalog.ItemType;
31
import in.shop2020.model.v1.inventory.BillingType;
32
import in.shop2020.model.v1.inventory.InventoryService;
33
import in.shop2020.model.v1.inventory.InventoryServiceException;
34
import in.shop2020.model.v1.inventory.Warehouse;
35
import in.shop2020.model.v1.order.AmazonOrder;
36
import in.shop2020.model.v1.order.Attribute;
37
import in.shop2020.model.v1.order.EbayOrder;
38
import in.shop2020.model.v1.order.FlipkartOrder;
39
import in.shop2020.model.v1.order.LineItem;
40
import in.shop2020.model.v1.order.OrderSource;
41
import in.shop2020.model.v1.order.OrderStatus;
42
import in.shop2020.model.v1.order.OrderType;
43
import in.shop2020.model.v1.order.ProductCondition;
44
import in.shop2020.model.v1.order.SnapdealOrder;
45
import in.shop2020.model.v1.order.TaxType;
46
import in.shop2020.model.v1.order.TransactionService;
47
import in.shop2020.support.utils.ReportsUtils;
48
import in.shop2020.thrift.clients.CatalogClient;
49
import in.shop2020.thrift.clients.InventoryClient;
50
import in.shop2020.thrift.clients.LogisticsClient;
51
import in.shop2020.thrift.clients.TransactionClient;
52
import in.shop2020.thrift.clients.config.ConfigClient;
53
import in.shop2020.model.v1.order.Order;
54
 
55
import javax.servlet.ServletOutputStream;
56
import javax.servlet.http.HttpServletRequest;
57
import javax.servlet.http.HttpServletResponse;
58
import javax.servlet.http.HttpSession;
59
 
60
import org.apache.commons.io.FileUtils;
61
import org.apache.commons.lang.StringUtils;
62
import org.apache.commons.lang.WordUtils;
63
import org.apache.struts2.interceptor.ServletRequestAware;
64
import org.apache.struts2.interceptor.ServletResponseAware;
65
import org.apache.struts2.interceptor.SessionAware;
66
import org.apache.thrift.TException;
67
import org.apache.thrift.transport.TTransportException;
68
import org.krysalis.barcode4j.impl.code128.Code128Bean;
69
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
70
import org.krysalis.barcode4j.tools.UnitConv;
71
import org.slf4j.Logger;
72
import org.slf4j.LoggerFactory;
73
 
74
import com.ibm.icu.text.RuleBasedNumberFormat;
75
import com.itextpdf.text.Document;
76
import com.itextpdf.text.Element;
77
import com.itextpdf.text.Font;
78
import com.itextpdf.text.FontFactory;
79
import com.itextpdf.text.FontFactoryImp;
80
import com.itextpdf.text.Image;
81
import com.itextpdf.text.Paragraph;
82
import com.itextpdf.text.Phrase;
83
import com.itextpdf.text.Rectangle;
84
import com.itextpdf.text.Font.FontFamily;
85
import com.itextpdf.text.pdf.BaseFont;
86
import com.itextpdf.text.pdf.PdfPCell;
87
import com.itextpdf.text.pdf.PdfPTable;
88
import com.itextpdf.text.pdf.PdfWriter;
89
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
90
import com.opensymphony.xwork2.ActionSupport;
91
@SuppressWarnings("serial")
92
public class BulkOrderBillingController extends ActionSupport implements ServletResponseAware, ServletRequestAware{
93
 
94
	private HttpServletRequest request;
95
	private HttpSession session;
96
	protected HttpServletResponse response;
97
 
98
	private File bulkBillingFile;
99
	private String errorMsg="";
100
	private String successMsg="";
101
	private String fileNameVal;
102
	private String orderIds;
103
 
104
	private String oneOrderId;
105
 
106
	private long singleTransactionId = 0l;
107
	private long singleUserId = 0l;
108
 
109
	private Map<Long, List<String>> orderImeiListMap = new HashMap<Long, List<String>>(); 
110
 
111
	private static Logger logger = LoggerFactory.getLogger(BulkOrderBillingController.class);
112
 
113
 
114
	@Override
115
	public void setServletRequest(HttpServletRequest request) {
116
		// TODO Auto-generated method stub
117
		this.request = request;
118
		this.session = request.getSession();	
119
	}
120
 
121
	public void setServletResponse(HttpServletResponse response) {
122
		this.response = response;
123
	}
124
 
125
	public String index() {
126
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))
127
			return "authfail";
128
		return "bulk-order-billing";
129
	}
130
 
131
	public String create(){
132
 
133
		File fileToCreate = null;
134
		List<Long> orderIdList = new ArrayList<Long>();
135
		Map<Long, Order> ordersMap = new HashMap<Long, Order>();
136
		Map<Long, Map<Long, String>> orderItemsMap = new HashMap<Long, Map<Long, String>>();
137
		Map<Long, Boolean> billingLeftOrderIdMap = new HashMap<Long, Boolean>();
138
		Map<Long, Integer> orderBillingTypeMap = new HashMap<Long, Integer>();
139
		TransactionClient txnClient = null;
140
		CatalogClient catalogClient = null;
141
		InventoryClient inventoryClient = null;
142
		try {
143
			txnClient = new TransactionClient();
144
			catalogClient = new CatalogClient();
145
			inventoryClient = new InventoryClient();
146
		} catch (TTransportException e1) {
147
			// TODO Auto-generated catch block
148
			e1.printStackTrace();
149
		}
150
 
151
		if(bulkBillingFile!=null & fileNameVal !=null && !fileNameVal.isEmpty()){
152
			logger.info("File Name "+bulkBillingFile.getName());
153
			System.out.println("File Name "+bulkBillingFile.getName());
154
 
155
			logger.info("File Name Value "+fileNameVal);
156
			System.out.println("File Name Value "+fileNameVal);
157
			String fileName = fileNameVal;
158
 
159
			try {
160
				if(!fileName.substring(fileName.lastIndexOf(".")+1).equalsIgnoreCase("txt")){
161
					throw new Exception("Not Again! File is not in expected TXT Format");
162
				}
163
				fileToCreate = new File("/tmp/", fileName);
164
 
165
				FileUtils.copyFile(this.bulkBillingFile, fileToCreate);
166
			} catch (Exception e) {
167
				logger.error("Hurray!! Error while writing file used to the local file system", e);
168
				errorMsg = e.getMessage();
169
				return "bulk-order-billing";
170
			}
171
 
172
		}
173
		else {
174
			errorMsg = errorMsg + "<br>Folk, No File Uploaded or file name is blank";
175
		}
176
		if(fileToCreate==null){
177
			errorMsg = errorMsg +" <br> No File to read";
178
			return "bulk-order-billing";
179
		}
180
 
181
		if(orderIds==null || orderIds.trim().isEmpty() || orderIds.trim().length()==0){
182
			errorMsg = errorMsg +" <br> Order Ids ";
183
		} else {
184
			if(orderIds.contains(",")){
185
				for(String s: orderIds.split(",")){
186
					orderIdList.add(Long.parseLong(s.trim()));
187
				}
188
			}else{
189
				orderIdList.add(Long.parseLong(orderIds.trim()));
190
			}
191
		}
192
 
193
		TransactionService.Client tClient = txnClient.getClient();
194
		InventoryService.Client iClient = inventoryClient.getClient();
195
 
196
		try{
197
			List<Order> ordersList = tClient.getOrderList(orderIdList);
198
			if(ordersList!=null && ordersList.size()>0){
199
				long transactionId = ordersList.get(0).getTransactionId();
200
				if(ordersList.size()>1){
201
					for (Order order: ordersList){
202
						if(transactionId== order.getTransactionId()){
203
							List<Attribute> attrList = new ArrayList<Attribute>();
204
							Attribute attr1 = new Attribute();
205
							attr1.setName("Single Invoice");
206
							attr1.setValue("true");
207
							attrList.add(attr1);
208
 
209
							ordersMap.put(order.getId(), order);
210
 
211
							if(!tClient.isAlive()){
212
								tClient = txnClient.getClient();
213
							}
214
							tClient.setOrderAttributes(order.getId(), attrList);
215
 
216
							if(!iClient.isAlive()){
217
								iClient = inventoryClient.getClient();
218
							}
219
 
220
							orderBillingTypeMap.put(order.getId(), iClient.getWarehouse(order.getWarehouse_id()).getBillingType().getValue());
221
							singleTransactionId = transactionId;
222
							singleUserId = order.getCustomer_id();
223
						} else {
224
							billingLeftOrderIdMap.put(order.getId(), Boolean.TRUE);
225
						}
226
					}
227
				} else {
228
					ordersMap.put(ordersList.get(0).getId(), ordersList.get(0));
229
 
230
					List<Attribute> attrList = new ArrayList<Attribute>();
231
					Attribute attr1 = new Attribute();
232
					attr1.setName("Single Invoice");
233
					attr1.setValue("true");
234
					attrList.add(attr1);
235
 
236
					if(!tClient.isAlive()){
237
						tClient = txnClient.getClient();
238
					}
239
					tClient.setOrderAttributes(ordersList.get(0).getId(), attrList);
240
 
241
					if(!iClient.isAlive()){
242
						iClient = inventoryClient.getClient();
243
					}
244
					singleTransactionId = transactionId;
245
					singleUserId = ordersList.get(0).getCustomer_id();
246
					orderBillingTypeMap.put(ordersList.get(0).getId(), iClient.getWarehouse(ordersList.get(0).getWarehouse_id()).getBillingType().getValue());
247
				}
248
			} else {
249
				return "bulk-order-billing";
250
			}
251
 
252
		} catch(Exception e){
253
			e.printStackTrace();
254
		}
255
 
256
		CatalogService.Client cClient = catalogClient.getClient();
257
 
258
 
259
		try{
260
			if(ordersMap!=null && ordersMap.size()>0){
261
				for(Long orderId: ordersMap.keySet()){
262
					Order order = ordersMap.get(orderId);
263
					LineItem lineItem = order.getLineitems().get(0);
264
					if(!cClient.isAlive()){
265
						cClient = catalogClient.getClient();
266
					}
267
					Item orderItem = cClient.getItem(lineItem.getItem_id());
268
					Map<Long, String> itemTypeMap = new HashMap<Long, String>();
269
					if(orderItem.getType()==ItemType.NON_SERIALIZED){
270
						itemTypeMap.put(orderItem.getId(), "NON_SERIALIZED");
271
					} else {
272
						itemTypeMap.put(orderItem.getId(), "SERIALIZED");
273
					}
274
					orderItemsMap.put(orderId, itemTypeMap);
275
				}
276
			}
277
		} catch(Exception e){
278
			e.printStackTrace();
279
		}
280
 
281
		Map<Long,List<String>> serialNumbersMap = new HashMap<Long, List<String>>();
282
		Map<Long,List<String>> itemNumbersMap = new HashMap<Long, List<String>>();
283
		Map<Long,Long> freebieWarehouseIdMap = new HashMap<Long,Long>();
284
		if(fileToCreate.isFile()){
285
			try{
286
				BufferedReader br = new BufferedReader(new FileReader(fileToCreate));
287
				long line = 1;
288
				String strLine;
289
				String[] values;
290
 
291
 
292
				while((strLine = br.readLine())!=null){
293
					if(line==1){
294
						values = strLine.split("\t");						
295
						if(values.length !=4){
296
							errorMsg = errorMsg + " File contains Inappropriate Content ";
297
							addActionError(errorMsg);
298
							return create();
299
						}
300
						line++;
301
						continue;
302
					}
303
					values = strLine.split("\t");
304
					logger.info("Row No "+line);
305
					System.out.print("Row No "+line);
306
					for(String s : values){
307
						logger.info(s);
308
						System.out.print(s);
309
					}
310
					if(!tClient.isAlive()){
311
						tClient = txnClient.getClient();
312
					}
313
 
12728 manish.sha 314
					if(values[0]=="")
315
						continue;
316
 
12653 manish.sha 317
					long ordId= Long.parseLong(values[0]);
318
					if(billingLeftOrderIdMap.containsKey(ordId)){
319
						line++;
320
						continue;
321
					}
322
 
323
					List<String> serialNumbers = null;
324
					List<String> itemNumbers = null;
325
					Order order = ordersMap.get(ordId);
326
					if(order.isSetFreebieItemId()){
327
						if(!freebieWarehouseIdMap.containsKey(ordId)){
328
							freebieWarehouseIdMap.put(ordId, Long.parseLong(values[3]));
329
						}
330
					} else{
331
						if(!freebieWarehouseIdMap.containsKey(ordId)){
332
							freebieWarehouseIdMap.put(ordId, 0l);
333
						}
334
					}
335
					if("SERIALIZED".equalsIgnoreCase(orderItemsMap.get(order.getId()).get(order.getLineitems().get(0).getItem_id()))){
336
						if(serialNumbersMap.containsKey(ordId)){
337
							serialNumbers = serialNumbersMap.get(ordId);
338
							serialNumbers.add(values[2]);
339
							serialNumbersMap.put(ordId, serialNumbers);
340
						}else{
341
							serialNumbers = new ArrayList<String>();
342
							serialNumbers.add(values[2]);
343
							serialNumbersMap.put(ordId, serialNumbers);
344
						}
345
						if(itemNumbersMap.containsKey(ordId)){
346
							itemNumbers = itemNumbersMap.get(ordId);
347
							itemNumbers.add(values[1]);
348
							itemNumbersMap.put(ordId, itemNumbers);
349
						}else{
350
							itemNumbers = new ArrayList<String>();
351
							itemNumbers.add(values[1]);
352
							itemNumbersMap.put(ordId, itemNumbers);
353
						}
354
 
355
					} else {
356
						if(itemNumbersMap.containsKey(ordId)){
357
							itemNumbers = itemNumbersMap.get(ordId);
358
							itemNumbers.add(values[1]);
359
							itemNumbersMap.put(ordId, itemNumbers);
360
						}else{
361
							itemNumbers = new ArrayList<String>();
362
							itemNumbers.add(values[1]);
363
							itemNumbersMap.put(ordId, itemNumbers);
364
						}
365
					}
366
					/*try{
367
						tClient.addBillingDetails(order.getId(), null, serialNumbers, itemNumbers, Long.parseLong(values[3]), "mp-mmx-admin", (long)(Math.random()*Math.pow(10.0, 7)), orderBillingTypeMap.get(order.getId()), order.getFulfilmentWarehouseId(), false);
368
					} catch(Exception e1){
369
						if(serialNumbers.size()>0){
370
							if(orderImeiListMap.containsKey(order.getId())){
371
								List<String> imeiList = orderImeiListMap.get(order.getId());
372
								imeiList.addAll(serialNumbers);
373
								orderImeiListMap.put(order.getId(), imeiList);
374
							}
375
							else{
376
								orderImeiListMap.put(order.getId(), serialNumbers);
377
							}
378
						}
379
 
380
						if(itemNumbers.size()>0 && serialNumbers.size()==0){
381
							if(orderImeiListMap.containsKey(order.getId())){
382
								List<String> imeiList = orderImeiListMap.get(order.getId());
383
								imeiList.addAll(itemNumbers);
384
								orderImeiListMap.put(order.getId(), imeiList);
385
							}
386
							else{
387
								orderImeiListMap.put(order.getId(), itemNumbers);
388
							}
389
						}
390
						line++;
391
						continue;
392
 
393
					}*/
394
 
395
					line++;
396
				}
397
 
398
				/*if(orderImeiListMap!=null && orderImeiListMap.size()>0){
399
					for(Long orderId : orderImeiListMap.keySet()){
400
						errorMsg = errorMsg + "<br> Error Occured for Order Id: "+ orderId ; 
401
						for(String imei : orderImeiListMap.get(orderId)){
402
							errorMsg = errorMsg + " Imei :" + imei +" ";
403
						}
404
					}
405
				}*/
406
 
407
				for(Order order: ordersMap.values()){
408
					try{
409
						if("SERIALIZED".equalsIgnoreCase(orderItemsMap.get(order.getId()).get(order.getLineitems().get(0).getItem_id()))){
410
							tClient.addBillingDetails(order.getId(), null, serialNumbersMap.get(order.getId()), itemNumbersMap.get(order.getId()), freebieWarehouseIdMap.get(order.getId()), "mp-mmx-admin", (long)(Math.random()*Math.pow(10.0, 7)), orderBillingTypeMap.get(order.getId()), order.getFulfilmentWarehouseId(), false);
411
						}else{
412
							tClient.addBillingDetails(order.getId(), null, new ArrayList<String>(), itemNumbersMap.get(order.getId()), freebieWarehouseIdMap.get(order.getId()), "mp-mmx-admin", (long)(Math.random()*Math.pow(10.0, 7)), orderBillingTypeMap.get(order.getId()), order.getFulfilmentWarehouseId(), false);
413
						}
414
 
415
					} catch(Exception e1){
416
						errorMsg = errorMsg+ "<br>" + "Order Id :" +order.getId()+ " Got Some Error while billing";
417
						logger.error("Order Id :" +order.getId()+ " Got Some Error while billing", e1);
418
						continue;
419
					}
420
				}
421
 
422
				if(billingLeftOrderIdMap!=null && billingLeftOrderIdMap.size()>0){
423
					errorMsg = errorMsg+ "<br>" + "These orders have been left because does not have same transaction id ";
424
					for(Long orderId : billingLeftOrderIdMap.keySet()){
425
						errorMsg = errorMsg+ orderId+ " ";
426
					}
427
				}
428
 
429
 
430
 
431
 
432
			} catch(Exception e){
433
				logger.error(errorMsg, e);
434
			}
435
		}
436
 
437
		if(singleTransactionId>0 && singleUserId>0){
438
			try{
439
				if(!tClient.isAlive()){
440
					tClient = txnClient.getClient();
441
				}
442
				tClient.addInvoiceDetailsToOrders(singleTransactionId, singleUserId);
443
			} catch(Exception e){
444
				errorMsg = errorMsg + "<br>Error while generating invoice number for transaction";
445
				logger.error(errorMsg, e);
446
			}
447
		}
448
 
449
		successMsg="All Orders have been billed sucessfully and also Invoice Number genrated";
450
		return "bulk-order-billing";
451
	}
452
 
453
	public void downloadInvoice(){
454
		TransactionClient txnClient = null;
455
		try{
456
			txnClient = new TransactionClient();
457
			TransactionService.Client tClient = txnClient.getClient();
458
			Order singleOrder = null;
459
			if(oneOrderId!=null && StringUtils.isNumeric(oneOrderId)){
460
				singleOrder = tClient.getOrder(Long.parseLong(oneOrderId));
461
				if(singleOrder.getSource()!=OrderSource.WEBSITE.getValue()){
462
					errorMsg = "Order source is not Website. Can't Bill using this functionality";
463
					return;
464
				}
465
				if(!singleOrder.isSetInvoice_number()){
466
					errorMsg = "Order has not been billed. Can't generate invoice";
467
					return;
468
				}
469
			}
470
			ByteArrayOutputStream baos = null;
471
 
472
			InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
473
			baos = invoiceGenerationService.generateInvoice(singleOrder.getTransactionId(), singleOrder.getCustomer_id(), true, false);
474
 
475
			logger.info("After this piece of code");
476
			response.setContentType("application/pdf");
477
			response.setHeader("Content-disposition", "inline; filename=invoice-"+singleOrder.getTransactionId()+".pdf" );
478
 
479
			ServletOutputStream sos = response.getOutputStream();
480
			sos.write(baos.toByteArray());
481
			sos.flush();
482
		}
483
		catch(Exception e){
484
			logger.error("Unablke to stream",e);
485
			e.printStackTrace();
486
		}
487
 
488
	}
489
 
490
	public File getBulkBillingFile() {
491
		return bulkBillingFile;
492
	}
493
 
494
	public void setBulkBillingFile(File bulkBillingFile) {
495
		this.bulkBillingFile = bulkBillingFile;
496
	}
497
 
498
	public String getErrorMsg() {
499
		return errorMsg;
500
	}
501
 
502
	public void setErrorMsg(String errorMsg) {
503
		this.errorMsg = errorMsg;
504
	}
505
 
506
	public String getSuccessMsg() {
507
		return successMsg;
508
	}
509
 
510
	public void setSuccessMsg(String successMsg) {
511
		this.successMsg = successMsg;
512
	}
513
 
514
	public String getFileNameVal() {
515
		return fileNameVal;
516
	}
517
 
518
	public void setFileNameVal(String fileNameVal) {
519
		this.fileNameVal = fileNameVal;
520
	}
521
 
522
	public String getOrderIds() {
523
		return orderIds;
524
	}
525
 
526
	public void setOrderIds(String orderIds) {
527
		this.orderIds = orderIds;
528
	}
529
 
530
	public static Warehouse getWarehouse(long warehouseId) {
531
		try{
532
			InventoryClient catalogServiceClient = new InventoryClient();
533
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
534
			return catalogClient.getWarehouse(warehouseId);
535
		}catch(Exception e){
536
			e.printStackTrace();
537
		}
538
		return null;
539
	}
540
 
541
	public String getOneOrderId() {
542
		return oneOrderId;
543
	}
544
 
545
	public void setOneOrderId(String oneOrderId) {
546
		this.oneOrderId = oneOrderId;
547
	}
548
}
549
 
550
 
551
class InvoiceGenerationService {
552
 
553
	private static Logger logger = LoggerFactory.getLogger(InvoiceGenerationService.class);
554
 
555
	private TransactionClient tsc = null;
556
	private InventoryClient csc = null;
557
	private LogisticsClient lsc = null;
558
	private CatalogClient ctsc = null;
559
 
560
	private static Locale indianLocale = new Locale("en", "IN");
561
	private DecimalFormat amountFormat = new DecimalFormat("#,##0.00");
562
 
563
	//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
564
	private static final Font helvetica6 = FontFactory.getFont(FontFactory.HELVETICA, 6);
565
	//End:-Added By Manish Sharma for FedEx Integration  - Shipment Creation on 21-Aug-2013
566
	private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
567
	/*private static final Font helvetica10 = FontFactory.getFont(FontFactory.HELVETICA, 10);
568
	private static final Font helvetica12 = FontFactory.getFont(FontFactory.HELVETICA, 12);*/
569
	private static final Font helvetica16 = FontFactory.getFont(FontFactory.HELVETICA, 16);
570
	//private static final Font helvetica22 = FontFactory.getFont(FontFactory.HELVETICA, 22);
571
 
572
	private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
573
	private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
574
 
575
	private static final String delhiPincodePrefix = "11";
576
	private static final String[] maharashtraPincodePrefix = {"40", "41", "42", "43", "44"};
577
 
578
	public InvoiceGenerationService() {
579
		try {
580
			tsc = new TransactionClient();
581
			csc = new InventoryClient();
582
			lsc = new LogisticsClient();
583
			ctsc = new CatalogClient();
584
		} catch (Exception e) {
585
			logger.error("Error while instantiating thrift clients.", e);
586
		}
587
	}
588
 
589
	public ByteArrayOutputStream generateInvoice(long transactionId, long customerId, boolean withBill, boolean printAll) {
590
		ByteArrayOutputStream baosPDF = null;
591
		in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
592
 
593
 
594
		try {
595
			baosPDF = new ByteArrayOutputStream();
596
 
597
			Document document = new Document();
598
			PdfWriter.getInstance(document, baosPDF);
599
			document.addAuthor("shop2020");
600
			//document.addTitle("Invoice No: " + order.getInvoice_number());
601
			document.open();
602
 
603
			List<Order> orders = new ArrayList<Order>();
604
 
605
			if(!tclient.isAlive()){
606
				tclient = tsc.getClient();
607
			}
608
 
609
			List<Order> ordersByTransaction = tclient.getOrdersForTransaction(transactionId, customerId);
610
			for(Order order: ordersByTransaction){
611
				if(order.isSetInvoice_number()){
612
					orders.add(order);
613
				}
614
			}
615
 
616
 
617
 
618
			PdfPTable taxTable = getTaxCumRetailInvoiceTable(orders);
619
			taxTable.setWidthPercentage(90.0f);
620
			taxTable.setSpacingAfter(5.0f);
621
 
622
 
623
			PdfPTable orderItemsDetailTable = new PdfPTable(1);
624
			orderItemsDetailTable.setWidthPercentage(90.0f);
625
			orderItemsDetailTable.setSpacingBefore(5.0f);
626
			orderItemsDetailTable.addCell(new Phrase("Order Reference Ids :", helveticaBold8));
627
			StringBuffer sbOrders = new StringBuffer();
628
 
629
			for(Order o1 : orders){
630
				sbOrders.append(o1.getId()+",");
631
			}
632
 
633
 
634
			String orderIds = sbOrders.toString();
635
			orderIds = orderIds.substring(0, orderIds.length()-1);
636
 
637
			orderItemsDetailTable.addCell(new Phrase(orderIds.toString(), helvetica8));
638
			orderItemsDetailTable.addCell(new Phrase("IMEI Details :", helveticaBold8));
639
 
640
			StringBuffer sbImeis = new StringBuffer();
641
 
642
			for(Order o1 : orders){
643
				sbImeis.append(o1.getLineitems().get(0).getSerial_number()+",");
644
			}
645
 
646
			String imeis = sbImeis.toString();
647
			imeis = imeis.substring(0, imeis.length()-1);
648
 
649
			orderItemsDetailTable.addCell(new Phrase(imeis, helvetica8));
650
 
651
 
652
 
653
 
654
			document.add(taxTable);
655
			document.add(new DottedLineSeparator());
656
			document.add(orderItemsDetailTable);
657
 
658
 
659
 
660
			document.close();
661
			baosPDF.close();
662
			// Adding facility to store the bill on the local directory. This will happen for only for Mahipalpur warehouse.
663
			if(withBill && !printAll){
664
				/*String strOrderId = StringUtils.repeat("0", 10-String.valueOf(transactionId).length()) + transactionId;  
665
				String dirPath = "/SaholicInvoices" + File.separator + strOrderId.substring(0, 2) + File.separator + strOrderId.substring(2, 4) + File.separator + strOrderId.substring(4, 6);
666
				String filename = dirPath + File.separator + transactionId + ".pdf";*/
667
				String  filename = "/tmp/"+"invoice-"+transactionId+".pdf";
668
				/*File dirFile = new File(dirPath);
669
				if(!dirFile.exists()){
670
					dirFile.mkdirs();
671
				}*/
672
				File f = new File(filename);
673
				FileOutputStream fos = new FileOutputStream(f);
674
				baosPDF.writeTo(fos);
675
			}
676
		} catch (Exception e) {
677
			logger.error("Error while generating Invoice: ", e);
678
		}
679
		return baosPDF;
680
	}
681
 
682
 
683
 
684
	private void addLogoTable(PdfPTable logoTable,Order order) {
685
		logoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
686
		logoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
687
		logoTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM);
688
 
689
		PdfPCell logoCell;
690
		String logoPath;
691
 
692
		if(order.getSource() == OrderSource.STORE.getValue()){
693
			logoCell = new PdfPCell(new Phrase(""));
694
 
695
		}else{
696
			logoPath = InvoiceGenerationService.class.getResource("/logo.jpg").getPath();
697
 
698
			try {
699
				logoCell = new PdfPCell(Image.getInstance(logoPath), false);
700
			} catch (Exception e) {
701
				//Too Many exceptions to catch here: BadElementException, MalformedURLException and IOException
702
				logger.warn("Couldn't load the Saholic logo: ", e);
703
				logoCell = new PdfPCell(new Phrase("Saholic Logo"));
704
			}
705
 
706
		}
707
		logoCell.setBorder(Rectangle.NO_BORDER);
708
		logoCell.setHorizontalAlignment(Element.ALIGN_LEFT);
709
		logoTable.addCell(logoCell);
710
		logoTable.addCell(" ");
711
 
712
	}
713
 
714
	/*private Font getBarCodeFont(Provider provider, float barcodeFontSize) {
715
		String fontPath = InvoiceGenerationService.class.getResource("/" + provider.getName().toLowerCase() + "/barcode.TTF").getPath();
716
		FontFactoryImp ttfFontFactory = new FontFactoryImp();
717
		ttfFontFactory.register(fontPath, "barcode");
718
		Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
719
		return barCodeFont;
720
	}*/
721
 
722
	/*private PdfPCell getTitleCell() {
723
		PdfPCell titleCell = new PdfPCell(new Phrase("Dispatch Advice", helveticaBold12));
724
		titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
725
		titleCell.setBorder(Rectangle.NO_BORDER);
726
		return titleCell;
727
	}*/
728
 
729
	/*private PdfPTable getProviderTable(Order order, Provider provider, Font barCodeFont) {
730
		PdfPTable providerInfoTable = new PdfPTable(1);
731
		providerInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
732
		if(order.isLogisticsCod()){
733
			PdfPCell deliveryTypeCell = new PdfPCell(new Phrase("COD   ", helvetica22));
734
			deliveryTypeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
735
			deliveryTypeCell.setBorder(Rectangle.NO_BORDER);
736
			providerInfoTable.addCell(deliveryTypeCell);
737
		}
738
 
739
 
740
		PdfPCell providerNameCell = new PdfPCell(new Phrase(provider.getName(), helveticaBold12));
741
		providerNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
742
		providerNameCell.setBorder(Rectangle.NO_BORDER);
743
		PdfPCell formIdCell= null;
744
		if(order.getLogistics_provider_id()==7L){
745
			if(order.isCod()){
746
				formIdCell = new PdfPCell(new Paragraph(order.getAirwaybill_no()+" Form id-0305", helvetica6));
747
			}
748
			else{
749
				formIdCell = new PdfPCell(new Paragraph(order.getAirwaybill_no()+" Form id-0467", helvetica6));
750
			}
751
			formIdCell.setPaddingTop(1.0f);
752
			formIdCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
753
			formIdCell.setBorder(Rectangle.NO_BORDER);
754
		}
755
 
756
 
757
		PdfPCell awbNumberCell= null;
758
		String fedexPackageBarcode = "";
759
		if(order.getLogistics_provider_id()!=7L){
760
			awbNumberCell = new PdfPCell(new Paragraph("*" + order.getAirwaybill_no() + "*", barCodeFont));
761
			awbNumberCell.setPaddingTop(20.0f);
762
		}
763
		else{
764
			in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
765
			try {
766
				fedexPackageBarcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_Package_BarCode");
767
			} catch (TException e1) {
768
				logger.error("Error while getting the provider information.", e1);
769
			}
770
			awbNumberCell = new PdfPCell(new Paragraph(" ", helvetica6));
771
		}
772
		awbNumberCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
773
		awbNumberCell.setBorder(Rectangle.NO_BORDER);
774
 
775
		providerInfoTable.addCell(providerNameCell);
776
		if(formIdCell != null){
777
			providerInfoTable.addCell(formIdCell);
778
		}
779
		//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
780
		if(order.getLogistics_provider_id()==7L){
781
			generateBarcode(fedexPackageBarcode, "fedex_"+order.getId());
782
 
783
			Image barcodeImage=null;
784
			try {
785
				barcodeImage = Image.getInstance("/tmp/"+"fedex_"+order.getId()+".png");
786
			} catch (Exception e) {
787
				logger.error("Exception during getting Barcode Image for Fedex : ", e);
788
			}
789
			providerInfoTable.addCell(barcodeImage);
790
		}
791
		providerInfoTable.addCell(awbNumberCell);
792
 
793
		Warehouse warehouse = null;
794
		try{
795
    		InventoryClient isc = new InventoryClient();
796
    		warehouse = isc.getClient().getWarehouse(order.getWarehouse_id());
797
		} catch(Exception e) {
798
		    logger.error("Unable to get warehouse for id : " + order.getWarehouse_id(), e);
799
		    //TODO throw e;
800
		}
801
		DeliveryType dt =  DeliveryType.PREPAID;
802
        if (order.isLogisticsCod()) {
803
            dt = DeliveryType.COD;
804
        }
805
        //Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
806
        if(order.getLogistics_provider_id()!=7L){
807
	        for (ProviderDetails detail : provider.getDetails()) {
808
	            if(in.shop2020.model.v1.inventory.WarehouseLocation.findByValue((int) detail.getLogisticLocation()) == warehouse.getLogisticsLocation() && detail.getDeliveryType() == dt) {
809
	                providerInfoTable.addCell(new Phrase("Account No : " + detail.getAccountNo(), helvetica8));
810
	            }
811
	        }
812
        }
813
        else{
814
        	providerInfoTable.addCell(new Phrase("STANDARD OVERNIGHT ", helvetica8));
815
        }
816
        //End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
817
		Date awbDate;
818
		if(order.getBilling_timestamp() == 0){
819
			awbDate = new Date();
820
		}else{
821
			awbDate = new Date(order.getBilling_timestamp());
822
		}
823
		if(order.getLogistics_provider_id()!=7L){
824
			providerInfoTable.addCell(new Phrase("AWB Date   : " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(awbDate), helvetica8));
825
		}
826
		providerInfoTable.addCell(new Phrase("Weight         : " + order.getTotal_weight() + " Kg", helvetica8));
827
		if(order.getSource() == OrderSource.EBAY.getValue()){
828
			EbayOrder ebayOrder = null;
829
			try {
830
				ebayOrder = tsc.getClient().getEbayOrderByOrderId(order.getId());
831
			} catch (TException e) {
832
				logger.error("Error while getting ebay order", e);
833
			}
834
			providerInfoTable.addCell(new Phrase("PaisaPayId            : " + ebayOrder.getPaisaPayId(), helvetica8));
835
			providerInfoTable.addCell(new Phrase("Sales Rec Number: " + ebayOrder.getSalesRecordNumber(), helvetica8));
836
		}
837
		//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
838
		if(order.getLogistics_provider_id()==7L){
839
			providerInfoTable.addCell(new Phrase("Bill T/C Sender      "+ "Bill D/T Sender", helvetica8));
840
		}
841
		//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
842
		return providerInfoTable;
843
	}*/
844
 
845
	/*private PdfPTable getTopInvoiceTable(Order order, String tinNo){
846
		PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.2f, 0.3f, 0.1f, 0.1f, 0.1f});
847
		invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
848
 
849
		invoiceTable.addCell(getInvoiceTableHeader(6));
850
 
851
		invoiceTable.addCell(new Phrase("Order No", helvetica8));
852
		invoiceTable.addCell(new Phrase("Paymode", helvetica8));
853
		invoiceTable.addCell(new Phrase("Product Name", helvetica8));
854
		invoiceTable.addCell(new Phrase("Quantity", helvetica8));
855
		invoiceTable.addCell(new Phrase("Rate", helvetica8));
856
		invoiceTable.addCell(new Phrase("Amount", helvetica8));
857
		populateTopInvoiceTable(order, invoiceTable);
858
 
859
 
860
		if(order.getInsurer() > 0) {
861
			invoiceTable.addCell(getInsuranceCell(4));
862
			invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
863
			invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
864
		}
865
 
866
		if(order.getSource() == OrderSource.STORE.getValue()) {
867
			invoiceTable.addCell(getAdvanceAmountCell(4));
868
			invoiceTable.addCell(getPriceCell(order.getAdvanceAmount()));
869
			invoiceTable.addCell(getPriceCell(order.getAdvanceAmount()));
870
		}
871
 
872
		invoiceTable.addCell(getTotalCell(4));      
873
		invoiceTable.addCell(getRupeesCell());
874
		invoiceTable.addCell(getTotalAmountCell(order.getTotal_amount()-order.getGvAmount()-order.getAdvanceAmount()));
875
 
876
		PdfPCell tinCell = new PdfPCell(new Phrase("TIN NO. " + tinNo, helvetica8));
877
		tinCell.setColspan(6);
878
		tinCell.setPadding(2);
879
		invoiceTable.addCell(tinCell);
880
 
881
		return invoiceTable;
882
	}*/
883
 
884
	/*private void populateTopInvoiceTable(Order order, PdfPTable invoiceTable) {
885
		List<LineItem> lineitems = order.getLineitems();
886
		for (LineItem lineitem : lineitems) {
887
			invoiceTable.addCell(new Phrase(order.getId() + "", helvetica8));
888
			if(order.getPickupStoreId() > 0 && order.isCod() == true)
889
				invoiceTable.addCell(new Phrase("In-Store", helvetica8));
890
			else if (order.isCod())
891
				invoiceTable.addCell(new Phrase("COD", helvetica8));
892
			else
893
				invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
894
 
895
			invoiceTable.addCell(getProductNameCell(lineitem, false, order.getFreebieItemId()));
896
 
897
			invoiceTable.addCell(new Phrase(lineitem.getQuantity() + "", helvetica8));
898
 
899
			invoiceTable.addCell(getPriceCell(lineitem.getUnit_price()-order.getGvAmount()));
900
 
901
			invoiceTable.addCell(getPriceCell(lineitem.getTotal_price()-order.getGvAmount()));
902
		}
903
	}*/
904
 
905
	/*private PdfPCell getAddressCell(String address) {
906
		Paragraph addressParagraph = new Paragraph(address, new Font(FontFamily.TIMES_ROMAN, 8f));
907
		PdfPCell addressCell = new PdfPCell();
908
		addressCell.addElement(addressParagraph);
909
		addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
910
		addressCell.setBorder(Rectangle.NO_BORDER);
911
		return addressCell;
912
	}*/
913
 
914
	private PdfPTable getTaxCumRetailInvoiceTable(List<Order> orders){
915
		in.shop2020.model.v1.inventory.InventoryService.Client iclient = csc.getClient();
916
 
917
		String ourAddress = "";
918
		String tinNo = "";
919
 
920
		Order order = null;
921
		for(Order ord: orders){
922
			Warehouse warehouse = null;
923
			Warehouse shippingLocation = null;
924
			order =ord;
925
			try {
926
				warehouse = iclient.getWarehouse(order.getWarehouse_id());
927
				shippingLocation = BulkOrderBillingController.getWarehouse(warehouse.getShippingWarehouseId());
928
				ourAddress = shippingLocation.getLocation() + "-" + shippingLocation.getPincode();
929
				tinNo = shippingLocation.getTinNumber();
930
			} catch (InventoryServiceException ise) {
931
				logger.error("Error while getting the warehouse information.", ise);
932
				return null;
933
			} catch (TException te) {
934
				logger.error("Error while getting some essential information from the services", te);
935
				return null;
936
			}
937
			break;
938
		}
939
 
940
		PdfPTable taxTable = new PdfPTable(1);
941
		Phrase phrase = null;
942
		taxTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
943
		taxTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
944
 
945
		PdfPTable logoTitleAndOurAddressTable = new PdfPTable(new float[]{0.4f, 0.3f, 0.3f});
946
		logoTitleAndOurAddressTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
947
		logoTitleAndOurAddressTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
948
 
949
 
950
		PdfPTable logoTable = new PdfPTable(2);
951
		addLogoTable(logoTable,order); 
952
 
953
		if (order.getOrderType().equals(OrderType.B2B)) {
954
			phrase = new Phrase("TAX INVOICE", helveticaBold12);
955
		} else {
956
			phrase = new Phrase("RETAIL INVOICE", helveticaBold12);
957
		}
958
		PdfPCell retailInvoiceTitleCell = new PdfPCell(phrase);
959
		retailInvoiceTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
960
		retailInvoiceTitleCell.setBorder(Rectangle.NO_BORDER);
961
 
962
		Paragraph sorlAddress = new Paragraph(ourAddress + "\n Contact No.- 0120-2479977" + "\nTIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f, Element.ALIGN_CENTER));
963
		PdfPCell sorlAddressCell = new PdfPCell(sorlAddress);
964
		sorlAddressCell.addElement(sorlAddress);
965
		sorlAddressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
966
 
967
		PdfPTable customerAddress = getCustomerAddressTable(order, null, true, helvetica8, true);
968
		PdfPTable orderDetails = getOrderDetails(order);
969
 
970
		PdfPTable addrAndOrderDetailsTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
971
		addrAndOrderDetailsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
972
		addrAndOrderDetailsTable.addCell(customerAddress);
973
		addrAndOrderDetailsTable.addCell(new Phrase(" "));
974
		addrAndOrderDetailsTable.addCell(orderDetails);
975
 
976
		boolean isVAT = isVatApplicable(order);
977
		PdfPTable invoiceTable = getBottomInvoiceTable(orders, isVAT);
978
 
979
		PdfPTable regAddAndDisCellTable = new PdfPTable(2);
980
 
981
		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));
982
		disclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
983
		disclaimerCell.setBorder(Rectangle.NO_BORDER);
984
 
985
		PdfPCell regAddressCell = new PdfPCell(new Phrase(" SPICE ONLINE RETAIL PRIVATE LIMITED\n Regd. Add. 60-D, STREET NO. C-5, SAINIK FARMS,NEW DELHI-110062\n CIN: U74140DL2008PTC183856 Tel. No. 0120-2479977 E-mail. help@saholic.com Website. www.saholic.com", helvetica6));
986
		regAddressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
987
		regAddressCell.setBorder(Rectangle.NO_BORDER);
988
		/*SPICE ONLINE RETAIL PRIVATE LIMITED
989
		Regd. Add. 60-D, STREET NO. C-5, SAINIK FARMS,NEW DELHI-110062
990
		CIN: U74140DL2008PTC183856
991
		Tel. No. 0120-2479977
992
		E-mail. help@saholic.com
993
		Website. www.saholic.com*/
994
 
995
 
996
		logoTitleAndOurAddressTable.addCell(logoTable);
997
		logoTitleAndOurAddressTable.addCell(retailInvoiceTitleCell);
998
		logoTitleAndOurAddressTable.addCell(sorlAddress);
999
 
1000
		regAddAndDisCellTable.addCell(disclaimerCell);
1001
		regAddAndDisCellTable.addCell(regAddressCell);
1002
 
1003
		taxTable.addCell(logoTitleAndOurAddressTable);
1004
		taxTable.addCell(addrAndOrderDetailsTable);
1005
		taxTable.addCell(invoiceTable);
1006
		taxTable.addCell(regAddAndDisCellTable);
1007
 
1008
		if(order.getProductCondition().equals(ProductCondition.BAD)){
1009
			PdfPCell badSaleDisclaimerCell = new PdfPCell(new Phrase(" Item(s) above are sold on as is where is basis. They " +
1010
					"may be in dead/defective/damaged/refurbished/incomplete/open condition. These " +
1011
					"are not returnable, exchangeable or refundable under any circumstances. No " +
1012
					"warranty is assured on these items." ,
1013
					new Font(FontFamily.TIMES_ROMAN, 8f)));
1014
			badSaleDisclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
1015
			badSaleDisclaimerCell.setBorder(Rectangle.NO_BORDER);
1016
			taxTable.addCell(badSaleDisclaimerCell);
1017
		}
1018
		return taxTable;
1019
	}
1020
 
1021
	private boolean isVatApplicable(Order order) {
1022
		if(order.getWarehouse_id() == 7) {
1023
			if(order.getCustomer_pincode().startsWith(delhiPincodePrefix)) {
1024
				return true;
1025
			} else {
1026
				return false;
1027
			}
1028
		} else {
1029
			for(int i=0; i< maharashtraPincodePrefix.length; i++) {
1030
				if(order.getCustomer_pincode().startsWith(maharashtraPincodePrefix[i])) {
1031
					return true;
1032
				}
1033
			}
1034
			return false;
1035
		}
1036
	}
1037
 
1038
	/*private PdfPTable getFlipkartBarCodes(Order order) {
1039
		PdfPTable flipkartTable = new PdfPTable(3);
1040
 
1041
		PdfPCell spacerCell = new PdfPCell();
1042
		spacerCell.setBorder(Rectangle.NO_BORDER);
1043
		spacerCell.setColspan(3);
1044
		spacerCell.setPaddingTop(330.0f);
1045
 
1046
		String flipkartCodeFontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
1047
		FontFactoryImp ttfFontFactory = new FontFactoryImp();
1048
		ttfFontFactory.register(flipkartCodeFontPath, "barcode");
1049
		Font flipkartBarCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, 20);
1050
 
1051
		String serialNumber = "0000000000";
1052
		if(order.getLineitems().get(0).getSerial_number()!=null && !order.getLineitems().get(0).getSerial_number().isEmpty()) {
1053
			serialNumber = order.getLineitems().get(0).getSerial_number();
1054
		} else if(order.getLineitems().get(0).getItem_number()!=null && !order.getLineitems().get(0).getItem_number().isEmpty()) {
1055
			serialNumber = order.getLineitems().get(0).getItem_number();
1056
		}
1057
 
1058
		PdfPCell serialNumberBarCodeCell = new PdfPCell(new Paragraph("*" +  serialNumber + "*", flipkartBarCodeFont));
1059
		serialNumberBarCodeCell.setBorder(Rectangle.TOP);
1060
		serialNumberBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
1061
		serialNumberBarCodeCell.setPaddingTop(11.0f);
1062
 
1063
 
1064
		PdfPCell invoiceNumberBarCodeCell = new PdfPCell(new Paragraph("*" +  order.getInvoice_number() + "*", flipkartBarCodeFont));
1065
		invoiceNumberBarCodeCell.setBorder(Rectangle.TOP);
1066
		invoiceNumberBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
1067
		invoiceNumberBarCodeCell.setPaddingTop(11.0f);
1068
 
1069
		double rate = order.getLineitems().get(0).getVatRate();
1070
		double salesTax = (rate * order.getTotal_amount())/(100 + rate);
1071
		PdfPCell vatAmtBarCodeCell = new PdfPCell(new Paragraph("*" +  amountFormat.format(salesTax) + "*", flipkartBarCodeFont));
1072
		vatAmtBarCodeCell.setBorder(Rectangle.TOP);
1073
		vatAmtBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
1074
		vatAmtBarCodeCell.setPaddingTop(11.0f);
1075
 
1076
		flipkartTable.addCell(spacerCell);
1077
		flipkartTable.addCell(serialNumberBarCodeCell);
1078
		flipkartTable.addCell(invoiceNumberBarCodeCell);
1079
		flipkartTable.addCell(vatAmtBarCodeCell);
1080
 
1081
		return flipkartTable;
1082
 
1083
	}*/
1084
 
1085
	private PdfPTable getCustomerAddressTable(Order order, String destCode, boolean showPaymentMode, Font font, boolean forInvoce){
1086
		PdfPTable customerTable = new PdfPTable(1);
1087
		customerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
1088
		if(forInvoce || order.getPickupStoreId() == 0){
1089
			customerTable.addCell(new Phrase(order.getCustomer_name(), font));
1090
			customerTable.addCell(new Phrase(order.getCustomer_address1(), font));
1091
			customerTable.addCell(new Phrase(order.getCustomer_address2(), font));
1092
			customerTable.addCell(new Phrase(order.getCustomer_city() + "," + order.getCustomer_state(), font));
1093
			//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
1094
			in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
1095
			if(order.getLogistics_provider_id()!=7L){
1096
				if(destCode != null)
1097
					customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + destCode, helvetica16));
1098
				else
1099
					customerTable.addCell(new Phrase(order.getCustomer_pincode(), font));
1100
			}
1101
			else{
1102
				String fedexLocationcode = "";
1103
				try {
1104
					fedexLocationcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_Location_Code");
1105
				} catch (TException e1) {
1106
					logger.error("Error while getting the provider information.", e1);
1107
				}
1108
				customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + fedexLocationcode, helvetica16));
1109
			}
1110
			//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
1111
			if(order.getCustomer_mobilenumber()!=null && !order.getCustomer_mobilenumber().isEmpty()) {
1112
				customerTable.addCell(new Phrase("Phone : " + (order.getCustomer_mobilenumber()== null ? "" : order.getCustomer_mobilenumber()), font));
1113
			}
1114
 
1115
		}else{
1116
			try {
1117
				in.shop2020.logistics.LogisticsService.Client lclient = (new LogisticsClient()).getClient();
1118
				PickupStore store = lclient.getPickupStore(order.getPickupStoreId());
1119
				customerTable.addCell(new Phrase(order.getCustomer_name() + " \nc/o " + store.getName(), font));
1120
				customerTable.addCell(new Phrase(store.getLine1(), font));
1121
				customerTable.addCell(new Phrase(store.getLine2(), font));
1122
				customerTable.addCell(new Phrase(store.getCity() + "," + store.getState(), font));
1123
				if(destCode != null)
1124
					customerTable.addCell(new Phrase(store.getPin() + " - " + destCode, helvetica16));
1125
				else
1126
					customerTable.addCell(new Phrase(store.getPin(), font));
1127
				customerTable.addCell(new Phrase("Phone :" + store.getPhone(), font));
1128
 
1129
 
1130
			} catch (TException e) {
1131
				// TODO Auto-generated catch block
1132
				e.printStackTrace();
1133
			}
1134
 
1135
		}
1136
 
1137
		if(order.getOrderType().equals(OrderType.B2B)) {
1138
			String tin = null;
1139
			in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
1140
			List<Attribute> attributes;
1141
			try {
1142
				attributes = tclient.getAllAttributesForOrderId(order.getId());
1143
 
1144
				for(Attribute attribute : attributes) {
1145
					if(attribute.getName().equals("tinNumber")) {
1146
						tin = attribute.getValue();
1147
					}
1148
				}
1149
				if (tin != null) {
1150
					customerTable.addCell(new Phrase("TIN :" + tin, font));
1151
				}
1152
 
1153
			} catch (Exception e) {
1154
				logger.error("Error while getting order attributes", e);
1155
			}
1156
		}
1157
		/*
1158
        if(showPaymentMode){
1159
            customerTable.addCell(new Phrase(" ", font));
1160
            customerTable.addCell(new Phrase("Payment Mode: Prepaid", font));
1161
        }*/
1162
		return customerTable;
1163
	}
1164
 
1165
	private PdfPTable getOrderDetails(Order order){
1166
		PdfPTable orderTable = new PdfPTable(new float[]{0.4f, 0.6f});
1167
		orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
1168
 
1169
		orderTable.addCell(new Phrase("Invoice No:", helvetica8));
1170
		orderTable.addCell(new Phrase(order.getInvoice_number(), helvetica8));
1171
 
1172
		orderTable.addCell(new Phrase("Date:", helvetica8));
1173
		orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
1174
 
1175
		try {
1176
			String poRefVal = tsc.getClient().getOrderAttributeValue(order.getId(), "poRefNumber");
1177
			if(poRefVal!=null && poRefVal.length()>0){
1178
				orderTable.addCell(new Phrase("PO Ref:", helvetica8));
1179
				orderTable.addCell(new Phrase(poRefVal, helvetica8));
1180
			}
1181
 
1182
		} catch (TException e) {
1183
			logger.error("Error while getting amazon order", e);
1184
		}
1185
 
1186
		orderTable.addCell(new Phrase("Tax Type:", helvetica8));
1187
 
1188
		if(order.getTaxType().equals(TaxType.CFORM)) {
1189
			orderTable.addCell(new Phrase("CST Against CForm", helvetica8));
1190
		} else {
1191
 
1192
			if(isVatApplicable(order)){
1193
				orderTable.addCell(new Phrase("VAT", helvetica8));
1194
			} else {
1195
				orderTable.addCell(new Phrase("CST", helvetica8));
1196
			}
1197
			orderTable.addCell(getVATLabelCell(isVatApplicable(order)));
1198
		}
1199
		return orderTable;
1200
	}
1201
 
1202
	private PdfPTable getBottomInvoiceTable(List<Order> orders, boolean isVAT){
1203
		PdfPTable invoiceTable = new PdfPTable(new float[]{0.1f, 0.3f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f});
1204
		invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
1205
 
1206
		invoiceTable.addCell(getInvoiceTableHeader(8));
1207
 
1208
		invoiceTable.addCell(new Phrase("Sl. No.", helveticaBold8));
1209
		invoiceTable.addCell(new Phrase("Description", helveticaBold8));
1210
		invoiceTable.addCell(new Phrase("Quantity", helveticaBold8));
1211
		invoiceTable.addCell(new Phrase("Rate (Rs)", helveticaBold8));
1212
		invoiceTable.addCell(new Phrase("Amount (Rs)", helveticaBold8));
1213
		invoiceTable.addCell(new Phrase("Tax Rate%", helveticaBold8));
1214
		invoiceTable.addCell(new Phrase("Tax (Rs)", helveticaBold8));
1215
		invoiceTable.addCell(new Phrase("Item Total (Rs)", helveticaBold8));
1216
 
1217
		double totalOrdersAmount = 0.0;
1218
		int i=1;
1219
		for(Order order :orders){
1220
			LineItem lineItem = order.getLineitems().get(0);
1221
			double orderAmount = order.getTotal_amount();
1222
			double rate = lineItem.getVatRate();
1223
			double salesTax = (rate * (orderAmount - order.getInsuranceAmount()))/(100 + rate);
1224
 
1225
			invoiceTable.addCell(new Phrase(i+"", helveticaBold8));
1226
			invoiceTable.addCell(getProductNameCell(lineItem, false, order.getFreebieItemId()));
1227
			invoiceTable.addCell(new Phrase("" + lineItem.getQuantity(), helvetica8));
1228
 
1229
 
1230
			//populateBottomInvoiceTable(order, invoiceTable, rate);
1231
 
1232
			double itemPrice = lineItem.getUnit_price();
1233
			double showPrice = (100 * itemPrice)/(100 + rate);
1234
			invoiceTable.addCell(getPriceCell(showPrice));
1235
 
1236
			double totalPrice = lineItem.getTotal_price();
1237
			showPrice = (100 * totalPrice)/(100 + rate);
1238
			invoiceTable.addCell(getPriceCell(showPrice));
1239
 
1240
			PdfPCell salesTaxCell = getPriceCell(salesTax);
1241
 
1242
 
1243
			invoiceTable.addCell(new Phrase(rate + "%", helvetica8));
1244
			invoiceTable.addCell(salesTaxCell);
1245
			invoiceTable.addCell(getTotalAmountCell(orderAmount));
1246
 
1247
			totalOrdersAmount = totalOrdersAmount+ orderAmount;
1248
			i++;
1249
		}
1250
 
1251
 
1252
		invoiceTable.addCell(getEmptyCell(8));
1253
 
1254
		invoiceTable.addCell(getTotalCell(6));
1255
		invoiceTable.addCell(getRupeesCell());
1256
		invoiceTable.addCell(getTotalAmountCell(totalOrdersAmount));
1257
 
1258
		invoiceTable.addCell(new Phrase("Amount in Words:", helveticaBold8));
1259
		invoiceTable.addCell(getAmountInWordsCell(totalOrdersAmount));
1260
 
1261
		invoiceTable.addCell(getEOECell(8));
1262
 
1263
		return invoiceTable;
1264
	}
1265
 
1266
	private PdfPCell getInvoiceTableHeader(int colspan) {
1267
		PdfPCell invoiceTableHeader = new PdfPCell(new Phrase("Order Item Details:", helveticaBold12));
1268
		invoiceTableHeader.setBorder(Rectangle.NO_BORDER);
1269
		invoiceTableHeader.setColspan(colspan);
1270
		invoiceTableHeader.setPaddingTop(1);
1271
		return invoiceTableHeader;
1272
	}
1273
 
1274
	/*private void populateBottomInvoiceTable(Order order, PdfPTable invoiceTable, double rate) {
1275
		for (LineItem lineitem : order.getLineitems()) {
1276
			invoiceTable.addCell(new Phrase("" + order.getId() , helvetica8));
1277
 
1278
			invoiceTable.addCell(getProductNameCell(lineitem, false, order.getFreebieItemId()));
1279
 
1280
			invoiceTable.addCell(new Phrase("" + lineitem.getQuantity(), helvetica8));
1281
 
1282
			double itemPrice = lineitem.getUnit_price();
1283
			double showPrice = (100 * itemPrice)/(100 + rate);
1284
			invoiceTable.addCell(getPriceCell(showPrice)); //Unit Price Cell
1285
 
1286
			double totalPrice = lineitem.getTotal_price();
1287
			showPrice = (100 * totalPrice)/(100 + rate);
1288
			invoiceTable.addCell(getPriceCell(showPrice));  //Total Price Cell
1289
		}
1290
	}*/
1291
 
1292
	private PdfPCell getProductNameCell(LineItem lineitem, boolean appendIMEI, Long freebieItemId) {
1293
		String itemName = getItemDisplayName(lineitem, appendIMEI);
1294
		if(freebieItemId!=null && freebieItemId!=0){
1295
			try {
1296
				CatalogService.Client catalogClient = ctsc.getClient();
1297
				Item item = catalogClient.getItem(freebieItemId);
1298
				itemName = itemName + "\n(Free Item: " + item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + ")";
1299
			} catch(Exception tex) {
1300
				logger.error("Not able to get Freebie Item Details for ItemId:" + freebieItemId, tex);
1301
			}
1302
		}
1303
		PdfPCell productNameCell = new PdfPCell(new Phrase(itemName, helvetica8));
1304
		productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
1305
		return productNameCell;
1306
	}
1307
 
1308
	private PdfPCell getPriceCell(double price) {
1309
		PdfPCell totalPriceCell = new PdfPCell(new Phrase(amountFormat.format(price), helvetica8));
1310
		totalPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
1311
		return totalPriceCell;
1312
	}
1313
 
1314
	private PdfPCell getVATLabelCell(boolean isVAT) {
1315
		PdfPCell vatCell = null;
1316
		if(isVAT){
1317
			vatCell = new PdfPCell(new Phrase("VAT", helveticaBold8));
1318
		} else {
1319
			vatCell = new PdfPCell(new Phrase("CST", helveticaBold8));
1320
		}
1321
		vatCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
1322
		return vatCell;
1323
	}
1324
 
1325
	private PdfPCell getCFORMLabelCell() {
1326
		PdfPCell cFormCell = null;
1327
		cFormCell = new PdfPCell(new Phrase("CST Against CForm", helveticaBold8));
1328
		cFormCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
1329
		return cFormCell;
1330
	}
1331
 
1332
	/*private PdfPCell getAdvanceAmountCell(int colspan) {
1333
		PdfPCell insuranceCell = null;
1334
		insuranceCell = new PdfPCell(new Phrase("Advance Amount Received", helvetica8));
1335
		insuranceCell.setColspan(colspan);
1336
		insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
1337
		return insuranceCell;
1338
	}*/
1339
 
1340
	/*private PdfPCell getInsuranceCell(int colspan) {
1341
		PdfPCell insuranceCell = null;
1342
		insuranceCell = new PdfPCell(new Phrase("1 Year WorldWide Theft Insurance", helvetica8));
1343
		insuranceCell.setColspan(colspan);
1344
		insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
1345
		return insuranceCell;
1346
	}*/
1347
 
1348
	private PdfPCell getEmptyCell(int colspan) {
1349
		PdfPCell emptyCell = new PdfPCell(new Phrase(" ", helvetica8));
1350
		emptyCell.setColspan(colspan);
1351
		return emptyCell;
1352
	}
1353
 
1354
	private PdfPCell getTotalCell(int colspan) {
1355
		PdfPCell totalCell = new PdfPCell(new Phrase("Grand Total", helveticaBold8));
1356
		totalCell.setColspan(colspan);
1357
		totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
1358
		return totalCell;
1359
	}
1360
 
1361
	private PdfPCell getRupeesCell() {
1362
		PdfPCell rupeesCell = new PdfPCell(new Phrase("Rs.", helveticaBold8));
1363
		rupeesCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
1364
		return rupeesCell;
1365
	}
1366
 
1367
	private PdfPCell getTotalAmountCell(double orderAmount) {
1368
		PdfPCell totalAmountCell = new PdfPCell(new Phrase(amountFormat.format(orderAmount), helveticaBold8));
1369
		totalAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
1370
		return totalAmountCell;
1371
	}
1372
 
1373
	/**
1374
	 * This method uses ICU4J libraries to convert the given amount into words
1375
	 * of Indian locale.
1376
	 * 
1377
	 * @param orderAmount
1378
	 *            The amount to convert.
1379
	 * @return the string representation of the given amount.
1380
	 */
1381
	private PdfPCell getAmountInWordsCell(double orderAmount) {
1382
		RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
1383
		StringBuilder amountInWords = new StringBuilder("Rs. ");
1384
		amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)orderAmount)));
1385
		amountInWords.append(" and ");
1386
		amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)(orderAmount*100)%100)));
1387
		amountInWords.append(" paise");
1388
 
1389
		PdfPCell amountInWordsCell= new PdfPCell(new Phrase(amountInWords.toString(), helveticaBold8));
1390
		amountInWordsCell.setColspan(4);
1391
		return amountInWordsCell;
1392
	}
1393
 
1394
	/**
1395
	 * Returns the item name to be displayed in the invoice table.
1396
	 * 
1397
	 * @param lineitem
1398
	 *            The line item whose name has to be displayed
1399
	 * @param appendIMEI
1400
	 *            Whether to attach the IMEI No. to the item name
1401
	 * @return The name to be displayed for the given line item.
1402
	 */
1403
	private String getItemDisplayName(LineItem lineitem, boolean appendIMEI){
1404
		StringBuffer itemName = new StringBuffer();
1405
		if(lineitem.getBrand()!= null)
1406
			itemName.append(lineitem.getBrand() + " ");
1407
		if(lineitem.getModel_name() != null)
1408
			itemName.append(lineitem.getModel_name() + " ");
1409
		if(lineitem.getModel_number() != null )
1410
			itemName.append(lineitem.getModel_number() + " ");
1411
		if(lineitem.getColor() != null && !lineitem.getColor().trim().equals("NA"))
1412
			itemName.append("("+lineitem.getColor()+")");
1413
		if(appendIMEI && lineitem.isSetSerial_number()){
1414
			itemName.append("\nIMEI No. " + lineitem.getSerial_number());
1415
		}
1416
 
1417
		return itemName.toString();
1418
	}
1419
 
1420
	/**
1421
	 * 
1422
	 * @param colspan
1423
	 * @return a PdfPCell containing the E&amp;OE text and spanning the given
1424
	 *         no. of columns
1425
	 */
1426
	private PdfPCell getEOECell(int colspan) {
1427
		PdfPCell eoeCell = new PdfPCell(new Phrase("E & O.E", helvetica8));
1428
		eoeCell.setColspan(colspan);
1429
		eoeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
1430
		return eoeCell;
1431
	}
1432
 
1433
	/*private PdfPTable getExtraInfoTable(Order order, Provider provider, float barcodeFontSize, BillingType billingType){
1434
		PdfPTable extraInfoTable = new PdfPTable(1);
1435
		extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
1436
		extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
1437
 
1438
		String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
1439
		FontFactoryImp ttfFontFactory = new FontFactoryImp();
1440
		ttfFontFactory.register(fontPath, "barcode");
1441
		Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
1442
 
1443
		PdfPCell extraInfoCell;
1444
		if(billingType == BillingType.EXTERNAL){
1445
			extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "*        *" + order.getCustomer_name() + "*        *"  + order.getTotal_amount() + "*", barCodeFont));
1446
		}else{
1447
			extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "*        *" + order.getLineitems().get(0).getTransfer_price() + "*", barCodeFont));	
1448
		}
1449
 
1450
		extraInfoCell.setPaddingTop(20.0f);
1451
		extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
1452
		extraInfoCell.setBorder(Rectangle.NO_BORDER);
1453
 
1454
		extraInfoTable.addCell(extraInfoCell);
1455
 
1456
 
1457
		return extraInfoTable;
1458
	}*/
1459
 
1460
	/*private PdfPTable getFixedTextTable(float barcodeFontSize, String printText){
1461
		PdfPTable extraInfoTable = new PdfPTable(1);
1462
		extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
1463
		extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
1464
 
1465
		String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
1466
		FontFactoryImp ttfFontFactory = new FontFactoryImp();
1467
		ttfFontFactory.register(fontPath, "barcode");
1468
		Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
1469
 
1470
		PdfPCell extraInfoCell = new PdfPCell(new Paragraph( "*" + printText + "*", barCodeFont));
1471
 
1472
		extraInfoCell.setPaddingTop(20.0f);
1473
		extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
1474
		extraInfoCell.setBorder(Rectangle.NO_BORDER);
1475
 
1476
		extraInfoTable.addCell(extraInfoCell);
1477
 
1478
		return extraInfoTable;
1479
	}*/
1480
 
1481
	/*private void generateBarcode(String barcodeString, String fileName){
1482
		Code128Bean bean = new Code128Bean();
1483
 
1484
		final int dpi = 60;
1485
 
1486
		//Configure the barcode generator
1487
		bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar 
1488
		                                                 //width exactly one pixel
1489
		bean.setFontSize(bean.getFontSize()+1.0f);
1490
		bean.doQuietZone(false);
1491
 
1492
		try {
1493
			File outputFile = new File("/tmp/"+fileName+".png");
1494
			OutputStream out = new FileOutputStream(outputFile);
1495
 
1496
		    //Set up the canvas provider for monochrome PNG output 
1497
		    BitmapCanvasProvider canvas = new BitmapCanvasProvider(
1498
		            out, "image/x-png", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
1499
 
1500
		    //Generate the barcode
1501
		    bean.generateBarcode(canvas, barcodeString);
1502
 
1503
		    //Signal end of generation
1504
		    canvas.finish();
1505
		    out.close();
1506
 
1507
		} 
1508
		catch(Exception e){
1509
			logger.error("Exception during generating Barcode : ", e);
1510
		}
1511
	}*/
1512
 
1513
	/*public static void main(String[] args) throws IOException {
1514
		InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
1515
		long orderId = 356324;
1516
		ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, true, false, 1);
1517
		String userHome = System.getProperty("user.home");
1518
		File f = new File(userHome + "/invoice-" + orderId + ".pdf");
1519
		FileOutputStream fos = new FileOutputStream(f);
1520
		baos.writeTo(fos);
1521
		System.out.println("Invoice generated.");
1522
	}*/
1523
}