Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
4687 mandeep.dh 1
package in.shop2020.inventory.service;
2
 
3
import java.io.ByteArrayOutputStream;
4
import java.io.File;
5
import java.io.FileOutputStream;
6
import java.io.IOException;
7
import java.text.DateFormat;
21844 amit.gupta 8
import java.text.MessageFormat;
14082 manish.sha 9
import java.util.Calendar;
4687 mandeep.dh 10
import java.util.Date;
24012 amit.gupta 11
import java.util.List;
14072 manish.sha 12
import java.util.Map;
4687 mandeep.dh 13
 
21844 amit.gupta 14
import org.apache.commons.lang.StringUtils;
14072 manish.sha 15
import org.apache.thrift.TException;
4687 mandeep.dh 16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18
 
19
import com.itextpdf.text.Document;
20
import com.itextpdf.text.Element;
21
import com.itextpdf.text.Font;
22
import com.itextpdf.text.Font.FontFamily;
23
import com.itextpdf.text.FontFactory;
24
import com.itextpdf.text.Paragraph;
25
import com.itextpdf.text.Phrase;
26
import com.itextpdf.text.Rectangle;
27
import com.itextpdf.text.pdf.PdfPCell;
28
import com.itextpdf.text.pdf.PdfPTable;
29
import com.itextpdf.text.pdf.PdfWriter;
19950 amit.gupta 30
 
24012 amit.gupta 31
import in.shop2020.model.v1.catalog.CatalogServiceException;
32
import in.shop2020.model.v1.inventory.InventoryService;
33
import in.shop2020.model.v1.inventory.StateInfo;
34
import in.shop2020.model.v1.inventory.VendorItemMapping;
35
import in.shop2020.model.v1.order.BuyerInfo;
36
import in.shop2020.model.v1.order.WarehouseAddress;
37
import in.shop2020.purchase.PurchaseOrder;
38
import in.shop2020.purchase.Supplier;
39
import in.shop2020.purchase.TaxType;
40
import in.shop2020.thrift.clients.CatalogClient;
41
import in.shop2020.thrift.clients.InventoryClient;
42
import in.shop2020.thrift.clients.TransactionClient;
43
 
4687 mandeep.dh 44
public class PdfPoSheetGenerator {
45
 
21844 amit.gupta 46
	private static Logger logger = LoggerFactory.getLogger(PdfPoSheetGenerator.class);
4687 mandeep.dh 47
 
21844 amit.gupta 48
	private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
4687 mandeep.dh 49
 
21844 amit.gupta 50
	private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
51
	private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
4687 mandeep.dh 52
 
21844 amit.gupta 53
	public static Map<Long, StateInfo> stateIdMap = null;
24012 amit.gupta 54
	public static InventoryService.Client inventoryClient = null;
4687 mandeep.dh 55
 
21844 amit.gupta 56
	static String CONTACT_FORMAT = "Mr. {0}, Contact No. +91 {1}";
57
 
58
	static {
59
		try {
24012 amit.gupta 60
			inventoryClient = new InventoryClient().getClient();
14072 manish.sha 61
			stateIdMap = inventoryClient.getStateMaster();
21844 amit.gupta 62
 
63
		} catch (Exception e) {
20025 amit.gupta 64
			logger.error("Unable to get State Info Map", e);
14072 manish.sha 65
		}
66
	}
67
 
21844 amit.gupta 68
	public static String generatePdfSheet(PurchaseOrder purchaseOrder, Supplier supplier) throws IOException {
69
		ByteArrayOutputStream baosPDF = null;
70
		try {
71
			in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
72
			BuyerInfo binfo = tClient.getBuyerByWarehouse(purchaseOrder.getWarehouseId());
73
			baosPDF = new ByteArrayOutputStream();
4687 mandeep.dh 74
 
21844 amit.gupta 75
			Document document = new Document();
76
			PdfWriter.getInstance(document, baosPDF);
77
			document.addAuthor("shop2020");
78
			document.addTitle("Purchase Order No: " + purchaseOrder.getPoNumber());
79
			document.open();
4687 mandeep.dh 80
 
21844 amit.gupta 81
			PdfPTable poTable = getPoTable(purchaseOrder, supplier, binfo);
82
			poTable.setSpacingAfter(10.0f);
83
			poTable.setWidthPercentage(100.0f);
4687 mandeep.dh 84
 
21844 amit.gupta 85
			document.add(poTable);
86
			document.close();
87
			baosPDF.close();
88
		} catch (Exception e) {
89
			logger.error("Error while generating Invoice: ", e);
90
			e.printStackTrace();
91
		}
4687 mandeep.dh 92
 
21844 amit.gupta 93
		String tmpDir = System.getProperty("java.io.tmpdir");
94
		String filename = tmpDir + "/po-" + purchaseOrder.getId() + ".pdf";
95
		File f = new File(filename);
96
		FileOutputStream fos = new FileOutputStream(f);
97
		baosPDF.writeTo(fos);
98
		return filename;
99
	}
4687 mandeep.dh 100
 
21844 amit.gupta 101
	private static PdfPTable getPoTable(PurchaseOrder purchaseOrder, Supplier supplier, BuyerInfo binfo) throws Exception {
102
		PdfPTable poTable = new PdfPTable(1);
103
		poTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
104
		poTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
4687 mandeep.dh 105
 
21844 amit.gupta 106
		PdfPCell poTitleCell = new PdfPCell(new Phrase("Purchase Order", helveticaBold12));
107
		poTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
108
		poTitleCell.setBorder(Rectangle.NO_BORDER);
4687 mandeep.dh 109
 
21844 amit.gupta 110
		long poValidityLimit = supplier.getPoValidityLimit();
111
		Calendar cal1 = Calendar.getInstance();
112
		cal1.setTimeInMillis(purchaseOrder.getCreatedAt());
113
		cal1.add(Calendar.DAY_OF_MONTH, (int) poValidityLimit);
114
		Date poDate = new Date(purchaseOrder.getCreatedAt());
115
		Date poExpiryDate = new Date(cal1.getTimeInMillis());
4687 mandeep.dh 116
 
21844 amit.gupta 117
		PdfPTable poSummaryTable = new PdfPTable(new float[] { 0.3f, 0.3f, 0.4f });
118
		poSummaryTable.addCell(new PdfPCell(new Phrase("PO No: " + purchaseOrder.getPoNumber())));
119
		poSummaryTable.addCell(new PdfPCell(new Phrase("Date: " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(poDate))));
120
		poSummaryTable.addCell(new PdfPCell(new Phrase("PO Valid for delivery by: "
121
				+ DateFormat.getDateInstance(DateFormat.MEDIUM).format(poExpiryDate))));
122
		poSummaryTable.setSpacingBefore(10.0f);
4687 mandeep.dh 123
 
21844 amit.gupta 124
		poTable.addCell(poTitleCell);
125
		poTable.addCell(getAddressCell(purchaseOrder, binfo));
126
		poTable.addCell(poSummaryTable);
127
		poTable.addCell(getSalutationTable(supplier));
128
		poTable.addCell(getPoDetailsTable(purchaseOrder, supplier, binfo));
129
		poTable.addCell(getBillToTable(purchaseOrder));
130
		// poTable.addCell(getCFormCell(purchaseOrder.getTaxType()));
23081 amit.gupta 131
 
132
		if(supplier.isSetTnc()) {
133
			poTable.addCell(getTncTable(supplier.getTnc()));
134
		}
4687 mandeep.dh 135
 
21844 amit.gupta 136
		return poTable;
137
	}
9416 amar.kumar 138
 
21844 amit.gupta 139
	/*
140
	 * private static PdfPCell getCFormCell(TaxType taxType) { PdfPCell
141
	 * cFormCell = null; if(taxType == TaxType.CFORM) { cFormCell = new
142
	 * PdfPCell(new Paragraph("*To be billed on CST Against C-Form ", new
143
	 * Font(FontFamily.TIMES_ROMAN, 8f))); } else { cFormCell = new PdfPCell();
144
	 * } cFormCell.setBorder(Rectangle.NO_BORDER);
145
	 * cFormCell.setHorizontalAlignment(Element.ALIGN_LEFT); return cFormCell; }
146
	 */
147
 
148
	private static PdfPTable getAddressCell(PurchaseOrder purchaseOrder, BuyerInfo binfo) {
149
		// TODO Write this code in a proper configurable way
150
		String address = "";
151
		String tinNo = "";
152
		String shippingAddress = "";
153
		try {
154
			in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
20073 amit.gupta 155
			WarehouseAddress addr = tClient.getWarehouseAddress(purchaseOrder.getWarehouseAddressId());
20025 amit.gupta 156
			tinNo = binfo.getTin();
157
			address = binfo.getOrganisationName() + "\n" + addr.getAddress() + "\n" + "-" + addr.getPin();
21844 amit.gupta 158
		} catch (Exception e) {
159
			logger.error("This should not happen", e);
160
		}
161
 
162
		PdfPTable billToShipToTable = new PdfPTable(2);
163
		Paragraph addressParagraph = new Paragraph(address, new Font(FontFamily.TIMES_ROMAN, 8f));
164
		PdfPCell addressCell = new PdfPCell();
165
		if (purchaseOrder.getWarehouseId() != purchaseOrder.getShippingWarehouseId()) {
166
			addressParagraph = new Paragraph("Bill To :\n" + address + "\n\nTIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f));
167
		}
168
		addressCell.addElement(addressParagraph);
169
		// addressCell.setHorizontalAlignment(Element.ALIGN_CENTER);
170
		addressCell.setBorder(Rectangle.NO_BORDER);
171
 
172
		if (purchaseOrder.getWarehouseId() != purchaseOrder.getShippingWarehouseId()) {
173
			try {
174
				in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
175
				WarehouseAddress addr = tClient.getWarehouseAddress(purchaseOrder.getShippingWarehouseAddressId());
176
				address = binfo.getOrganisationName() + "\n" + addr.getAddress() + "\n" + "-" + addr.getPin();
177
			} catch (Exception e) {
178
				logger.error("This should not happen", e);
179
			}
9925 amar.kumar 180
			PdfPCell billToShipToCell = new PdfPCell();
181
			billToShipToCell.setHorizontalAlignment(Element.ALIGN_LEFT);
182
			billToShipToCell.setBorder(Rectangle.NO_BORDER);
21844 amit.gupta 183
 
9925 amar.kumar 184
			PdfPCell shippingAddressCell = new PdfPCell();
21844 amit.gupta 185
			shippingAddressCell.addElement(new Paragraph("Ship To :\n" + shippingAddress + "\nTIN NO. " + tinNo, new Font(
186
					FontFamily.TIMES_ROMAN, 8f)));
9925 amar.kumar 187
			shippingAddressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
21844 amit.gupta 188
			shippingAddressCell.setBorder(Rectangle.LEFT);
189
			billToShipToTable.addCell(addressCell);
190
			billToShipToTable.addCell(shippingAddressCell);
191
			billToShipToCell.addElement(billToShipToTable);
192
			return billToShipToTable;
4687 mandeep.dh 193
 
21844 amit.gupta 194
		}
195
		billToShipToTable.addCell(addressCell);
196
		PdfPCell placeHolderCell = new PdfPCell();
197
		placeHolderCell.setBorder(Rectangle.NO_BORDER);
198
		billToShipToTable.addCell(placeHolderCell);
199
		return billToShipToTable;
200
	}
4687 mandeep.dh 201
 
21844 amit.gupta 202
	private static PdfPTable getSalutationTable(Supplier supplier) throws Exception {
203
		PdfPTable salutationTable = new PdfPTable(1);
204
		salutationTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
205
		salutationTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
206
		salutationTable.addCell(new Phrase("To", helvetica8));
207
		if (supplier.getName().equals("Smobility Ltd.")) {
208
			salutationTable.addCell(new Phrase("Spice Retail Ltd.", helvetica8));
209
		} else if (supplier.getName().equals("Smobility Ltd. - Mumbai")) {
210
			salutationTable.addCell(new Phrase("Spice Retail Ltd. Mumbai", helvetica8));
211
		} else {
212
			salutationTable.addCell(new Phrase(supplier.getName(), helvetica8));
213
		}
4687 mandeep.dh 214
 
21844 amit.gupta 215
		salutationTable.addCell(new Paragraph(supplier.getCommunicationAddress(), helvetica8));
216
		salutationTable.addCell(new Phrase("Dear Sir/Madam", helveticaBold8));
217
		salutationTable.addCell(new Phrase("Please supply the following stocks as per the details given below:", helvetica8));
218
		salutationTable.addCell(new Phrase(" "));
219
		return salutationTable;
220
	}
221
 
222
	private static PdfPTable getPoDetailsTable(PurchaseOrder purchaseOrder, Supplier supplier, BuyerInfo binfo)
223
			throws CatalogServiceException, TException {
224
		float[] widths;
21854 amit.gupta 225
		TaxType taxType = purchaseOrder.getTaxType();
21844 amit.gupta 226
		if(taxType.equals(TaxType.SGST)){
227
			widths = new float[] { 0.05f, 0.25f, 0.09f, 0.1f, 0.09f, 0.09f, 0.09f, 0.07f, 0.1f, 0.07f, 0.1f };
228
		} else {
229
			widths = new float[] { 0.1f, 0.27f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.08f, 0.1f };
14072 manish.sha 230
		}
21844 amit.gupta 231
		PdfPTable detailsTable = new PdfPTable(widths);
232
 
233
		PdfPCell slNoCell = getHeaderCell("Sl. No");
234
		detailsTable.addCell(slNoCell);
235
 
236
		PdfPCell description = getHeaderCell("Description");
237
		detailsTable.addCell(description);
4687 mandeep.dh 238
 
21844 amit.gupta 239
 
240
		PdfPCell hsnCodeCell = getHeaderCell("HSN Code");
241
		detailsTable.addCell(hsnCodeCell);
242
 
243
		PdfPCell qtyCell = getHeaderCell("Qty");
244
		detailsTable.addCell(qtyCell);
245
 
246
		PdfPCell rateCell = getHeaderCell("Rate");
247
		detailsTable.addCell(rateCell);
248
 
249
		PdfPCell totalCell = getHeaderCell("Total Value");
250
		detailsTable.addCell(totalCell);
251
 
252
		PdfPCell taxableAmontCell = getHeaderCell("Taxable Value");
253
		taxableAmontCell.setRowspan(2);
254
		detailsTable.addCell(taxableAmontCell);
255
 
256
 
257
		if(taxType.equals(TaxType.SGST)) {
258
			PdfPCell cell1 = new PdfPCell(new Phrase("CGST", helveticaBold8));
259
			cell1.setColspan(2);
260
			cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
261
			detailsTable.addCell(cell1);
262
 
263
			PdfPCell cell2 = new PdfPCell(new Phrase("SGST", helveticaBold8));
264
			cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
265
			cell2.setColspan(2);
266
			detailsTable.addCell(cell2);
267
		} else {
268
			PdfPCell cell3 = new PdfPCell(new Phrase("IGST", helveticaBold8));
269
			cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
270
			cell3.setRowspan(2);
21854 amit.gupta 271
			detailsTable.addCell(cell3);
21844 amit.gupta 272
		}
273
 
274
		if(taxType.equals(TaxType.SGST)) {
275
			detailsTable.addCell(new Phrase("Rate(%)", helveticaBold8));
276
			detailsTable.addCell(new Phrase("Amount", helveticaBold8));
277
			detailsTable.addCell(new Phrase("Rate(%)", helveticaBold8));
278
			detailsTable.addCell(new Phrase("Amount", helveticaBold8));
279
		}else {
280
			detailsTable.addCell(new Phrase("Rate(%)", helveticaBold8));
281
			detailsTable.addCell(new Phrase("Amount", helveticaBold8));
282
		}
283
 
284
		int slNo = 0;
285
		double total = 0;
286
		double vatFactor = 0;
287
		double totalUnits = 0;
288
		String stateCode = null;
289
		CatalogClient cClient = new CatalogClient();
290
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = cClient.getClient();
291
		for (in.shop2020.purchase.LineItem lineitem : purchaseOrder.getLineitems()) {
292
			slNo++;
293
			detailsTable.addCell(new Phrase(slNo + "", helvetica8));
24012 amit.gupta 294
			detailsTable.addCell(getProductNameCell(lineitem, purchaseOrder.getSupplierId()));
21844 amit.gupta 295
			detailsTable.addCell(new Phrase(lineitem.getHsnCode(), helvetica8));
296
			detailsTable.addCell(new Phrase(String.format("%d Units", (int)lineitem.getQuantity()), helvetica8));
297
			detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getUnitPrice()), helvetica8));
298
 
299
			double totalAmount = lineitem.getUnitPrice()*lineitem.getQuantity();
300
			detailsTable.addCell(new Phrase(String.format("%.2f", totalAmount), helvetica8));
301
 
302
			double totalTaxRate = lineitem.getIgstRate() + lineitem.getSgstRate() + lineitem.getCgstRate();
303
			double taxableAmount = totalAmount / (1 + (totalTaxRate / 100));
304
			detailsTable.addCell(new Phrase(String.format("%.2f", taxableAmount), helvetica8));
305
 
306
			if(purchaseOrder.getTaxType().equals(TaxType.SGST)) {
307
				double cgstAmount = taxableAmount * (lineitem.getCgstRate() / 100);
308
				detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getCgstRate()), helvetica8));
309
				detailsTable.addCell(new Phrase(String.format("%.2f", cgstAmount), helvetica8));
310
 
311
				double sgstAmount = taxableAmount * (lineitem.getSgstRate() / 100);
312
				detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getSgstRate()), helvetica8));
313
				detailsTable.addCell(new Phrase(String.format("%.2f", sgstAmount), helvetica8));
314
			} else {
315
				double igstAmount = taxableAmount * (lineitem.getIgstRate() / 100);
316
				detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getIgstRate()), helvetica8));
317
				detailsTable.addCell(new Phrase(String.format("%.2f", igstAmount), helvetica8));
318
			}
319
 
320
			totalUnits += lineitem.getQuantity();
321
			total += totalAmount;
322
		}
23828 amit.gupta 323
		if(purchaseOrder.getTaxType().equals(TaxType.SGST)) {
324
 
325
			detailsTable.addCell(getTotalCell(3));
326
			detailsTable.addCell(new Phrase(String.format("%.0f", totalUnits), helvetica8));
327
			detailsTable.addCell(getTotalAmountCell(7, total));
328
		} else {
329
			detailsTable.addCell(getTotalCell(2));
330
			detailsTable.addCell(new Phrase(String.format("%.0f", totalUnits), helvetica8));
331
			detailsTable.addCell(getTotalAmountCell(6, total));
332
		}
21844 amit.gupta 333
		return detailsTable;
334
	}
335
 
336
	private static PdfPCell getHeaderCell(String headerName) {
337
		PdfPCell cell = new PdfPCell(new Phrase(headerName, helveticaBold8));
338
		cell.setRowspan(2);
339
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
340
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
341
		return cell;
342
	}
23081 amit.gupta 343
	private static PdfPTable getTncTable(String tnc) {
344
		PdfPTable tncTable = new PdfPTable(new float[] { 1f });
345
		tncTable.addCell(new Phrase("Terms & Conditions", helveticaBold8));
346
		tncTable.addCell(new Phrase(tnc, helvetica8));
347
		return tncTable;
348
	}
21844 amit.gupta 349
	private static PdfPTable getBillToTable(PurchaseOrder po) {
350
		// TODO Write this code in a proper configurable way
351
		String address = "";
352
		String gstin = "";
353
		String contactPerson = "Neeraj Gupta";
354
		String contactNumber = "9873802000";
355
		BuyerInfo binfo = new BuyerInfo();
356
		try {
357
			in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
20067 amit.gupta 358
			binfo = tClient.getBuyerByWarehouse(po.getWarehouseId());
21844 amit.gupta 359
			gstin = binfo.getGstin();
20067 amit.gupta 360
			WarehouseAddress addr = tClient.getWarehouseAddress(po.getWarehouseAddressId());
361
			address = binfo.getOrganisationName() + "\n" + addr.getAddress() + "\n" + "-" + addr.getPin();
21844 amit.gupta 362
			if (StringUtils.isNotBlank(addr.getContact_person())) {
363
				contactPerson = addr.getContact_person();
364
			}
365
			if (StringUtils.isNotBlank(addr.getContact_number())) {
366
				contactNumber = addr.getContact_number();
367
			}
368
		} catch (Exception e) {
369
			logger.error("This should not happen", e);
370
		}
7410 amar.kumar 371
 
21844 amit.gupta 372
		contactPerson = MessageFormat.format(CONTACT_FORMAT, contactPerson, contactNumber);
373
		PdfPTable billToTable = new PdfPTable(new float[] { 0.2f, 0.8f });
374
		billToTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
4687 mandeep.dh 375
 
21844 amit.gupta 376
		billToTable.addCell(new Phrase("Bill To :", helvetica8));
377
		billToTable.addCell(new PdfPCell(new Paragraph(address 
378
				+ "\n\nPlace of Supply - " 
379
				+ MessageFormat.format("{0}({1})", stateIdMap.get(binfo.getStateId()).getStateName(),stateIdMap.get(binfo.getStateId()).getStateCode())
380
				+ "\nGST NO. " + gstin, helvetica8)));
4687 mandeep.dh 381
 
21844 amit.gupta 382
		billToTable.addCell(new Phrase("Contact Person:", helvetica8));
383
		billToTable.addCell(new Phrase(contactPerson, helvetica8));
4687 mandeep.dh 384
 
21844 amit.gupta 385
		billToTable.addCell(new Phrase("Taxes:", helvetica8));
386
		if (po.getTaxType() == TaxType.CFORM) {
387
			billToTable.addCell(new Phrase("Prices inclusive of all taxes (To be billed on CST Against C-Form)", helvetica8));
388
		} else {
389
			billToTable.addCell(new Phrase("Prices inclusive of all taxes", helvetica8));
390
		}
4687 mandeep.dh 391
 
21844 amit.gupta 392
		return billToTable;
393
	}
4687 mandeep.dh 394
 
24012 amit.gupta 395
	private static PdfPCell getProductNameCell(in.shop2020.purchase.LineItem lineitem, long supplierId) {
396
		String itemName = getItemDisplayName(lineitem, supplierId);
21844 amit.gupta 397
		PdfPCell productNameCell = new PdfPCell(new Phrase(itemName, helvetica8));
398
		productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
399
		return productNameCell;
400
	}
4687 mandeep.dh 401
 
24012 amit.gupta 402
	private static String getItemDisplayName(in.shop2020.purchase.LineItem lineitem, long supplierId) {
21844 amit.gupta 403
		StringBuffer itemName = new StringBuffer();
404
		if (lineitem.getBrand() != null)
405
			itemName.append(lineitem.getBrand() + " ");
406
		if (lineitem.getModelName() != null)
407
			itemName.append(lineitem.getModelName() + " ");
408
		if (lineitem.getModelNumber() != null)
409
			itemName.append(lineitem.getModelNumber() + " ");
410
		if (lineitem.getColor() != null && !lineitem.getColor().trim().equals("NA"))
24012 amit.gupta 411
			itemName.append("-" + lineitem.getColor());
412
		if(lineitem.getBrand()=="Samsung") {
413
			List<VendorItemMapping> vims = getVendorItemMapping(lineitem.getItemId());
414
			if(vims != null && vims.size() > 0) {
415
				for(VendorItemMapping vim : vims) {
416
					if(vim.getVendorId() == supplierId) {
417
						itemName.append("(" + vim.getItemKey() + ")");
418
					}
419
				}
420
			}
421
		}
21844 amit.gupta 422
		return itemName.toString();
423
	}
24012 amit.gupta 424
 
425
	private static List<VendorItemMapping> getVendorItemMapping(long itemId) {
426
		try {
427
 
428
			return inventoryClient.getVendorItemMappings(itemId);
429
		}catch (Exception e) {
430
			try {
431
				inventoryClient =  new InventoryClient().getClient();
432
				return inventoryClient.getVendorItemMappings(itemId);
433
			} catch(Exception e1) {
434
				e1.printStackTrace();
435
			}
436
		}
437
		return null;
438
	}
4687 mandeep.dh 439
 
21844 amit.gupta 440
	private static PdfPCell getTotalCell(int colspan) {
441
		PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
442
		totalCell.setColspan(colspan);
443
		totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
444
		return totalCell;
445
	}
4687 mandeep.dh 446
 
21844 amit.gupta 447
	private static PdfPCell getTotalAmountCell(int colspan, double totalAmount) {
448
		PdfPCell totalCell = new PdfPCell(new Phrase(String.format("%.2f", totalAmount), helvetica8));
449
		totalCell.setColspan(colspan);
450
		totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
451
		return totalCell;
452
	}
453
 
4687 mandeep.dh 454
}