Subversion Repositories SmartDukaan

Rev

Rev 20073 | Rev 21854 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 20073 Rev 21844
Line 1... Line 1...
1
package in.shop2020.inventory.service;
1
package in.shop2020.inventory.service;
2
 
2
 
-
 
3
import in.shop2020.model.v1.catalog.CatalogServiceException;
-
 
4
import in.shop2020.model.v1.catalog.GstRate;
-
 
5
import in.shop2020.model.v1.catalog.StateGstRates;
-
 
6
import in.shop2020.model.v1.inventory.StateInfo;
-
 
7
import in.shop2020.model.v1.order.BuyerInfo;
-
 
8
import in.shop2020.model.v1.order.WarehouseAddress;
-
 
9
import in.shop2020.purchase.PurchaseOrder;
-
 
10
import in.shop2020.purchase.Supplier;
-
 
11
import in.shop2020.purchase.TaxType;
-
 
12
import in.shop2020.thrift.clients.CatalogClient;
-
 
13
import in.shop2020.thrift.clients.InventoryClient;
-
 
14
import in.shop2020.thrift.clients.TransactionClient;
-
 
15
 
3
import java.io.ByteArrayOutputStream;
16
import java.io.ByteArrayOutputStream;
4
import java.io.File;
17
import java.io.File;
5
import java.io.FileOutputStream;
18
import java.io.FileOutputStream;
6
import java.io.IOException;
19
import java.io.IOException;
7
import java.text.DateFormat;
20
import java.text.DateFormat;
-
 
21
import java.text.MessageFormat;
8
import java.util.Calendar;
22
import java.util.Calendar;
9
import java.util.Date;
23
import java.util.Date;
10
import java.util.Map;
24
import java.util.Map;
11
 
25
 
-
 
26
import org.apache.commons.lang.StringUtils;
12
import org.apache.thrift.TException;
27
import org.apache.thrift.TException;
13
import org.slf4j.Logger;
28
import org.slf4j.Logger;
14
import org.slf4j.LoggerFactory;
29
import org.slf4j.LoggerFactory;
15
 
30
 
16
import com.itextpdf.text.Document;
31
import com.itextpdf.text.Document;
Line 23... Line 38...
23
import com.itextpdf.text.Rectangle;
38
import com.itextpdf.text.Rectangle;
24
import com.itextpdf.text.pdf.PdfPCell;
39
import com.itextpdf.text.pdf.PdfPCell;
25
import com.itextpdf.text.pdf.PdfPTable;
40
import com.itextpdf.text.pdf.PdfPTable;
26
import com.itextpdf.text.pdf.PdfWriter;
41
import com.itextpdf.text.pdf.PdfWriter;
27
 
42
 
28
import in.shop2020.model.v1.catalog.CatalogServiceException;
-
 
29
import in.shop2020.model.v1.inventory.StateInfo;
-
 
30
import in.shop2020.model.v1.inventory.VatType;
-
 
31
import in.shop2020.model.v1.order.BuyerInfo;
-
 
32
import in.shop2020.model.v1.order.WarehouseAddress;
-
 
33
import in.shop2020.purchase.PurchaseOrder;
-
 
34
import in.shop2020.purchase.Supplier;
-
 
35
import in.shop2020.purchase.TaxType;
-
 
36
import in.shop2020.thrift.clients.CatalogClient;
-
 
37
import in.shop2020.thrift.clients.InventoryClient;
-
 
38
import in.shop2020.thrift.clients.TransactionClient;
-
 
39
 
-
 
40
public class PdfPoSheetGenerator {
43
public class PdfPoSheetGenerator {
41
 
44
 
42
    private static Logger logger = LoggerFactory
-
 
43
            .getLogger(PdfPoSheetGenerator.class);
45
	private static Logger logger = LoggerFactory.getLogger(PdfPoSheetGenerator.class);
44
 
46
 
45
    // private static final Properties properties = readProperties();
-
 
46
    private static final String ourAddressDelhi = "Spice Online Retail Pvt. Ltd.\nC/O,PIBCO LIMITED, Basement,Punjsons\n2,Kalkaji Industrial Area, New Delhi-110019\n";
-
 
47
    private static final String ourAddressBhiwandi = "Spice Online Retail Pvt. Ltd.\nC/O. FedEx Express Transportation and Supply Chain Services (India) Private Limited.\nC/O NDR WAREHOUSING, SURVEY NO.95, MUMBAI - NASIK HIGHWAY, WADAPE VILLAGE\nBHIWANDI (NR. SAI DHABA), Thane,Maharashtra -421302\n";                   
-
 
48
    private static final String ourAddressGoregaon = "Spice Online Retail Pvt. Ltd.\n93/743, Motilal Nagar-1, Goregaon(WEST),\nMotilal Nagar, Mumbai, Maharashtra-400062\n";
-
 
49
    private static final String ourAddressBangalore = "Spice Online Retail Pvt. Ltd.\n C/O.Drive India Enterprise Solutions Limited)\n Survey No. 86, Korulur Village, Kasab Hobli\n Hoskote Taluka\n Bangalore – 560067, Karnataka\n";
-
 
50
    private static final String ourAddressBangaloreSR = "Spice Online Retail Pvt. Ltd.\n Shop No. 320, Municipal 59th Cross,\n Next to Rammandir Ground,\n 3rd Block, Rajaji Nagar,\nBangalore - 560010, Karnataka\n";
-
 
51
    private static final String ourAddressGurgaon = "Spice Online Retail Private Limited,\n SHOP NO. 10 & 11,\n OLD DELHI ROAD,OPP SECTOR-14, GURGAON-122001 Haryana\n";
-
 
52
    private static final String ourAddressHyderabad = "Spice Online Retail Pvt. Ltd, Drive India Enterprise Solutions Limited, 16,17&18, Gundllapochampalli, Kompalli, Medchal Mandal, Secandrabad-500014, Dist- Hyderabad";
-
 
53
    private static final String ourAddressGurgaonS = "Spice Online Retail Pvt Ltd. \nC/O.Drive India Enterprise Solutions Ltd, \nKhasra No.2771,Main Sheetla Mata Mandir Road \nOpposite Sec-5,Petrol Pump(Bharat Petroliam) \nNear Anmol Vatika, Gurgaon- 122001";
47
	private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
54
    
-
 
55
    private static final String amazonAddress = "Spice Online Retail Pvt. Ltd. C/O Amazon Seller Services  Pvt. Ltd.,\nBuilding H Prathmesh Complex, Saravali Village,\nOpp Hotel Vatika Kalyan, Bhivandi Junction,\nBhiwandi, Maharashtra\n";
-
 
56
    private static final String amazonAddreseBangalore = "Spice Online Retail Pvt. Ltd.\n C/O Amazon Seller Services Pvt. Ltd.\n 38 & 39, Soukya Road,\n kacherakanahalli,\n Hoskote Taluka,\n Bangalore  -560067, Karnataka\n";
-
 
57
    private static final String amazonAddressMewat = "Spice Online Retail Pvt. Ltd.\n C/O AMAZON Seller Services Pvt. Limited,\n  Gokaldas Warehousing Corporation,  Unit No 1,\n Village Taoru,  Tehsil Taoru, Distt Mewat - 122105";
-
 
58
    private static final String amazonAddressDelhi = "Spice Online Retail Pvt Ltd., \nC/O Amazon Seller Services Pvt. Ltd., \nA43 GF MOHAN COOPERATIVE IND,  \nESTATE MAIN MATHURA ROAD,  \nBADARPUR SOUTH DELHI, Delhi -110044"; 
-
 
59
    private static final String flipkartAddressGgn = "Spice Online Retail Pvt. Ltd.\n C/O. Flipkart Internet Pvt. Ltd, \n KILLA NO.219/15-16 25/1 220/11 12/1 12/2 13/1/113/1/2 20 21/1 21/2/1 22/1 23/1/1,\n Bohra Kalan, PATAUDI, GURGAON - 122001, Haryana\n";
-
 
60
    private static final String flipkartAddressDelhi = "Spice Online Retail Pvt. Ltd.\n C/O Flipkart Internet Pvt. Ltd.\n Khasra No. 435,Road No.# 04 ,Lal Dora Extension,\nMahipalpur, New Delhi- 110037\n";
-
 
61
    private static final String snapdealAddressDelhi = "Spice Online Retail Pvt. Ltd, \nC/O. Gati Kintetsu Express Pvt Ltd.,\nPlot In Khasra No. 15/17,24, G/F, \nVillage- Samalkha, New Delhi - 110037";
-
 
62
    private static final String tinNoDelhi = "07250399732";
-
 
63
    private static final String tinNoMum = "27450984008";
-
 
64
    private static final String tinNoBan = "29171183852";
-
 
65
    private static final String tinNoFkGgn = "06681944625";
-
 
66
    private static final String tinNoOurGgn = "06681944625";
-
 
67
    private static final String tinNoOurHyd = "36601220768";
-
 
68
    private static final String tinNoFkDelhi = "07720408834";
-
 
69
    
-
 
70
 
-
 
71
    private static final Font helvetica8 = FontFactory.getFont(
-
 
72
            FontFactory.HELVETICA, 8);
-
 
73
 
-
 
74
    private static final Font helveticaBold8 = FontFactory.getFont(
-
 
75
            FontFactory.HELVETICA_BOLD, 8);
-
 
76
    private static final Font helveticaBold12 = FontFactory.getFont(
-
 
77
            FontFactory.HELVETICA_BOLD, 12);
-
 
78
    
-
 
79
    public static Map<Long, StateInfo> stateIdMap = null; 
-
 
80
 
48
 
-
 
49
	private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
-
 
50
	private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
-
 
51
 
-
 
52
	public static Map<Long, StateInfo> stateIdMap = null;
-
 
53
 
-
 
54
	static String CONTACT_FORMAT = "Mr. {0}, Contact No. +91 {1}";
-
 
55
 
81
	static{
56
	static {
82
		try{
57
		try {
83
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
58
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
84
			stateIdMap = inventoryClient.getStateMaster();
59
			stateIdMap = inventoryClient.getStateMaster();
85
			
60
 
86
		} catch(Exception e){
61
		} catch (Exception e) {
87
			logger.error("Unable to get State Info Map", e);
62
			logger.error("Unable to get State Info Map", e);
88
		}
63
		}
89
	}
64
	}
90
 
65
 
91
    public static String generatePdfSheet(PurchaseOrder purchaseOrder,
66
	public static String generatePdfSheet(PurchaseOrder purchaseOrder, Supplier supplier) throws IOException {
92
            Supplier supplier) throws IOException {
-
 
93
        ByteArrayOutputStream baosPDF = null;
67
		ByteArrayOutputStream baosPDF = null;
94
        try {
68
		try {
-
 
69
			in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
-
 
70
			BuyerInfo binfo = tClient.getBuyerByWarehouse(purchaseOrder.getWarehouseId());
95
        	baosPDF = new ByteArrayOutputStream();
71
			baosPDF = new ByteArrayOutputStream();
96
 
72
 
97
            Document document = new Document();
73
			Document document = new Document();
98
            PdfWriter.getInstance(document, baosPDF);
74
			PdfWriter.getInstance(document, baosPDF);
99
            document.addAuthor("shop2020");
75
			document.addAuthor("shop2020");
100
            document.addTitle("Purchase Order No: "
-
 
101
                    + purchaseOrder.getPoNumber());
76
			document.addTitle("Purchase Order No: " + purchaseOrder.getPoNumber());
102
            document.open();
77
			document.open();
103
 
78
 
104
            PdfPTable poTable = getPoTable(purchaseOrder, supplier);
79
			PdfPTable poTable = getPoTable(purchaseOrder, supplier, binfo);
105
            poTable.setSpacingAfter(10.0f);
80
			poTable.setSpacingAfter(10.0f);
106
            poTable.setWidthPercentage(90.0f);
81
			poTable.setWidthPercentage(100.0f);
107
 
82
 
108
            document.add(poTable);
83
			document.add(poTable);
109
            document.close();
84
			document.close();
110
            baosPDF.close();
85
			baosPDF.close();
111
        } catch (Exception e) {
86
		} catch (Exception e) {
112
            logger.error("Error while generating Invoice: ", e);
87
			logger.error("Error while generating Invoice: ", e);
113
            e.printStackTrace();
88
			e.printStackTrace();
114
        }
-
 
115
 
-
 
116
        String tmpDir = System.getProperty("java.io.tmpdir");
-
 
117
        String filename = tmpDir + "/po-" + purchaseOrder.getId() + ".pdf";
-
 
118
        File f = new File(filename);
-
 
119
        FileOutputStream fos = new FileOutputStream(f);
-
 
120
        baosPDF.writeTo(fos);
-
 
121
        return filename;
-
 
122
    }
-
 
123
 
-
 
124
    private static PdfPTable getPoTable(PurchaseOrder purchaseOrder,
-
 
125
            Supplier supplier) throws Exception {
-
 
126
        PdfPTable poTable = new PdfPTable(1);
-
 
127
        poTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
-
 
128
        poTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
-
 
129
 
-
 
130
        PdfPCell poTitleCell = new PdfPCell(new Phrase("Purchase Order",
-
 
131
                helveticaBold12));
-
 
132
        poTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
-
 
133
        poTitleCell.setBorder(Rectangle.NO_BORDER);
-
 
134
 
-
 
135
        long poValidityLimit = supplier.getPoValidityLimit();
-
 
136
        Calendar cal1 = Calendar.getInstance();
-
 
137
        cal1.setTimeInMillis(purchaseOrder.getCreatedAt());
-
 
138
        cal1.add(Calendar.DAY_OF_MONTH, (int)poValidityLimit);
-
 
139
        Date poDate = new Date(purchaseOrder.getCreatedAt());
-
 
140
        Date poExpiryDate = new Date(cal1.getTimeInMillis());
-
 
141
        
-
 
142
        
-
 
143
        PdfPTable poSummaryTable = new PdfPTable(new float[] { 0.3f, 0.3f, 0.4f });
-
 
144
        poSummaryTable.addCell(new PdfPCell(new Phrase("PO No: "
-
 
145
                + purchaseOrder.getPoNumber())));
-
 
146
        poSummaryTable.addCell(new PdfPCell(new Phrase("Date: "
-
 
147
        		+ DateFormat.getDateInstance(DateFormat.MEDIUM).format(
-
 
148
        				poDate))));
-
 
149
        poSummaryTable.addCell(new PdfPCell(new Phrase("PO Valid for delivery by: "
-
 
150
        		+ DateFormat.getDateInstance(DateFormat.MEDIUM).format(
-
 
151
        				poExpiryDate))));
-
 
152
        poSummaryTable.setSpacingBefore(10.0f);
-
 
153
 
-
 
154
        poTable.addCell(poTitleCell);
-
 
155
        poTable.addCell(getAddressCell(purchaseOrder));
-
 
156
        poTable.addCell(poSummaryTable);
-
 
157
        poTable.addCell(getSalutationTable(supplier));
-
 
158
        poTable.addCell(getPoDetailsTable(purchaseOrder, supplier));
-
 
159
        poTable.addCell(getBillToTable(purchaseOrder));
-
 
160
        //poTable.addCell(getCFormCell(purchaseOrder.getTaxType()));
-
 
161
 
-
 
162
        return poTable;
-
 
163
    }
-
 
164
 
-
 
165
    /*private static PdfPCell getCFormCell(TaxType taxType) {
-
 
166
    	PdfPCell cFormCell = null;
-
 
167
		if(taxType == TaxType.CFORM) {
-
 
168
			cFormCell = new PdfPCell(new Paragraph("*To be billed on CST Against C-Form ", new Font(FontFamily.TIMES_ROMAN, 8f)));
-
 
169
		} else {
-
 
170
			cFormCell = new PdfPCell();
-
 
171
		}
89
		}
-
 
90
 
-
 
91
		String tmpDir = System.getProperty("java.io.tmpdir");
-
 
92
		String filename = tmpDir + "/po-" + purchaseOrder.getId() + ".pdf";
-
 
93
		File f = new File(filename);
-
 
94
		FileOutputStream fos = new FileOutputStream(f);
-
 
95
		baosPDF.writeTo(fos);
-
 
96
		return filename;
-
 
97
	}
-
 
98
 
-
 
99
	private static PdfPTable getPoTable(PurchaseOrder purchaseOrder, Supplier supplier, BuyerInfo binfo) throws Exception {
-
 
100
		PdfPTable poTable = new PdfPTable(1);
172
		cFormCell.setBorder(Rectangle.NO_BORDER);
101
		poTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
-
 
102
		poTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
-
 
103
 
-
 
104
		PdfPCell poTitleCell = new PdfPCell(new Phrase("Purchase Order", helveticaBold12));
173
		cFormCell.setHorizontalAlignment(Element.ALIGN_LEFT);
105
		poTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
-
 
106
		poTitleCell.setBorder(Rectangle.NO_BORDER);
-
 
107
 
-
 
108
		long poValidityLimit = supplier.getPoValidityLimit();
-
 
109
		Calendar cal1 = Calendar.getInstance();
-
 
110
		cal1.setTimeInMillis(purchaseOrder.getCreatedAt());
-
 
111
		cal1.add(Calendar.DAY_OF_MONTH, (int) poValidityLimit);
-
 
112
		Date poDate = new Date(purchaseOrder.getCreatedAt());
-
 
113
		Date poExpiryDate = new Date(cal1.getTimeInMillis());
-
 
114
 
-
 
115
		PdfPTable poSummaryTable = new PdfPTable(new float[] { 0.3f, 0.3f, 0.4f });
-
 
116
		poSummaryTable.addCell(new PdfPCell(new Phrase("PO No: " + purchaseOrder.getPoNumber())));
-
 
117
		poSummaryTable.addCell(new PdfPCell(new Phrase("Date: " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(poDate))));
-
 
118
		poSummaryTable.addCell(new PdfPCell(new Phrase("PO Valid for delivery by: "
-
 
119
				+ DateFormat.getDateInstance(DateFormat.MEDIUM).format(poExpiryDate))));
-
 
120
		poSummaryTable.setSpacingBefore(10.0f);
-
 
121
 
-
 
122
		poTable.addCell(poTitleCell);
-
 
123
		poTable.addCell(getAddressCell(purchaseOrder, binfo));
-
 
124
		poTable.addCell(poSummaryTable);
-
 
125
		poTable.addCell(getSalutationTable(supplier));
-
 
126
		poTable.addCell(getPoDetailsTable(purchaseOrder, supplier, binfo));
-
 
127
		poTable.addCell(getBillToTable(purchaseOrder));
-
 
128
		// poTable.addCell(getCFormCell(purchaseOrder.getTaxType()));
-
 
129
 
174
		return cFormCell;
130
		return poTable;
-
 
131
	}
-
 
132
 
-
 
133
	/*
-
 
134
	 * private static PdfPCell getCFormCell(TaxType taxType) { PdfPCell
-
 
135
	 * cFormCell = null; if(taxType == TaxType.CFORM) { cFormCell = new
-
 
136
	 * PdfPCell(new Paragraph("*To be billed on CST Against C-Form ", new
-
 
137
	 * Font(FontFamily.TIMES_ROMAN, 8f))); } else { cFormCell = new PdfPCell();
-
 
138
	 * } cFormCell.setBorder(Rectangle.NO_BORDER);
-
 
139
	 * cFormCell.setHorizontalAlignment(Element.ALIGN_LEFT); return cFormCell; }
175
	}*/
140
	 */
176
 
141
 
177
	private static PdfPTable getAddressCell(PurchaseOrder purchaseOrder) {
142
	private static PdfPTable getAddressCell(PurchaseOrder purchaseOrder, BuyerInfo binfo) {
178
    	//TODO Write this code in a proper configurable way
143
		// TODO Write this code in a proper configurable way
179
		BuyerInfo binfo = null;
-
 
180
    	String address = "";
144
		String address = "";
181
    	String tinNo = "";
145
		String tinNo = "";
182
    	String shippingAddress = "";
146
		String shippingAddress = "";
183
    	try {
147
		try {
184
	    	in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
148
			in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
185
			binfo = tClient.getBuyerByWarehouse(purchaseOrder.getWarehouseId());
-
 
186
			WarehouseAddress addr = tClient.getWarehouseAddress(purchaseOrder.getWarehouseAddressId());
149
			WarehouseAddress addr = tClient.getWarehouseAddress(purchaseOrder.getWarehouseAddressId());
187
			tinNo = binfo.getTin();
150
			tinNo = binfo.getTin();
188
			address = binfo.getOrganisationName() + "\n" + addr.getAddress() + "\n" + "-" + addr.getPin();
151
			address = binfo.getOrganisationName() + "\n" + addr.getAddress() + "\n" + "-" + addr.getPin();
189
    	} catch (Exception e) {
152
		} catch (Exception e) {
190
    		logger.error("This should not happen", e);
153
			logger.error("This should not happen", e);
191
    	}
154
		}
192
		
155
 
193
    	
-
 
194
    	
-
 
195
    	PdfPTable billToShipToTable  = new PdfPTable(2);
156
		PdfPTable billToShipToTable = new PdfPTable(2);
196
        Paragraph addressParagraph = new Paragraph(address + "\nTIN NO. "
157
		Paragraph addressParagraph = new Paragraph(address, new Font(FontFamily.TIMES_ROMAN, 8f));
197
                + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f));
-
 
198
        PdfPCell addressCell = new PdfPCell();
158
		PdfPCell addressCell = new PdfPCell();
199
        if(purchaseOrder.getWarehouseId() != purchaseOrder.getShippingWarehouseId()) {
159
		if (purchaseOrder.getWarehouseId() != purchaseOrder.getShippingWarehouseId()) {
200
           	addressParagraph = new Paragraph("Bill To :\n" + address + "\n\nTIN NO. "
160
			addressParagraph = new Paragraph("Bill To :\n" + address + "\n\nTIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f));
201
                    + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f));
-
 
202
        }
161
		}
203
        addressCell.addElement(addressParagraph);
162
		addressCell.addElement(addressParagraph);
204
        //addressCell.setHorizontalAlignment(Element.ALIGN_CENTER);
163
		// addressCell.setHorizontalAlignment(Element.ALIGN_CENTER);
205
        addressCell.setBorder(Rectangle.NO_BORDER);
164
		addressCell.setBorder(Rectangle.NO_BORDER);
206
        
165
 
207
        if(purchaseOrder.getWarehouseId() != purchaseOrder.getShippingWarehouseId()) {
166
		if (purchaseOrder.getWarehouseId() != purchaseOrder.getShippingWarehouseId()) {
208
        	try {
167
			try {
209
    	    	in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
168
				in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
210
    			WarehouseAddress addr = tClient.getWarehouseAddress(purchaseOrder.getShippingWarehouseAddressId());
169
				WarehouseAddress addr = tClient.getWarehouseAddress(purchaseOrder.getShippingWarehouseAddressId());
211
    			address = binfo.getOrganisationName() + "\n" + addr.getAddress() + "\n" + "-" + addr.getPin();
170
				address = binfo.getOrganisationName() + "\n" + addr.getAddress() + "\n" + "-" + addr.getPin();
212
        	} catch (Exception e) {
171
			} catch (Exception e) {
213
        		logger.error("This should not happen", e);
172
				logger.error("This should not happen", e);
214
        	}
-
 
215
/*			if(shippingWarehouseId ==7) {
-
 
216
				shippingAddress = ourAddressDelhi;
-
 
217
				shippingTinNo = tinNoDelhi;
-
 
218
	    	} else if(shippingWarehouseId == 12) {
-
 
219
	    		shippingAddress = ourAddressGoregaon;
-
 
220
	    		shippingTinNo = tinNoMum;
-
 
221
	    	} else if(shippingWarehouseId == 13) {
-
 
222
	    		shippingAddress = ourAddressBhiwandi;
-
 
223
	    		shippingTinNo = tinNoMum;
-
 
224
	    	} else if(shippingWarehouseId ==16) {
-
 
225
	    		shippingAddress = amazonAddress;
-
 
226
	    		shippingTinNo = tinNoMum;
-
 
227
	    	} else if(shippingWarehouseId ==1765){
-
 
228
	    		shippingAddress = ourAddressBangalore;
-
 
229
	    		shippingTinNo = tinNoBan;
-
 
230
	    	} else if(shippingWarehouseId ==1768){
-
 
231
	    		shippingAddress = ourAddressBangaloreSR;
-
 
232
	    		shippingTinNo = tinNoBan;
-
 
233
	    	} else if(shippingWarehouseId ==1771){
-
 
234
	    		shippingAddress = amazonAddreseBangalore;
-
 
235
	    		shippingTinNo = tinNoBan;
-
 
236
	    	} else if(shippingWarehouseId == 2854){
-
 
237
	    		shippingAddress = flipkartAddressGgn;
-
 
238
	    		shippingTinNo = tinNoFkGgn;
-
 
239
	    	} else if(shippingWarehouseId == 2857){
-
 
240
	    		shippingAddress = ourAddressGurgaon;
-
 
241
	    		shippingTinNo = tinNoOurGgn;
-
 
242
	    	} else if(shippingWarehouseId == 3295){
-
 
243
	    		shippingAddress = amazonAddressMewat;
-
 
244
	    		shippingTinNo = tinNoOurGgn;
-
 
245
	    	} else if(shippingWarehouseId == 3298){
-
 
246
	    		shippingAddress = ourAddressHyderabad;
-
 
247
	    		shippingTinNo = tinNoOurHyd;
-
 
248
	    	} else if(shippingWarehouseId == 3931){
-
 
249
	    		shippingAddress = ourAddressGurgaonS;
-
 
250
	    		shippingTinNo = tinNoOurGgn;
-
 
251
	    	} else if(shippingWarehouseId == 4699){
-
 
252
	    		shippingAddress = flipkartAddressDelhi;
-
 
253
	    		shippingTinNo = tinNoFkDelhi;
-
 
254
	    	} else if(shippingWarehouseId == 5314){
-
 
255
	    		shippingAddress = snapdealAddressDelhi;
-
 
256
	    		shippingTinNo = tinNoFkDelhi;
-
 
257
	    	} else if(shippingWarehouseId == 5623){
-
 
258
	    		shippingAddress = amazonAddressDelhi;
-
 
259
	    		shippingTinNo = tinNoDelhi;
-
 
260
	    	}*/
-
 
261
			
173
			}
262
			PdfPCell billToShipToCell = new PdfPCell();
174
			PdfPCell billToShipToCell = new PdfPCell();
263
			billToShipToCell.setHorizontalAlignment(Element.ALIGN_LEFT);
175
			billToShipToCell.setHorizontalAlignment(Element.ALIGN_LEFT);
264
			billToShipToCell.setBorder(Rectangle.NO_BORDER);
176
			billToShipToCell.setBorder(Rectangle.NO_BORDER);
265
			
177
 
266
			PdfPCell shippingAddressCell = new PdfPCell();
178
			PdfPCell shippingAddressCell = new PdfPCell();
267
			shippingAddressCell.addElement(new Paragraph("Ship To :\n" +shippingAddress + "\nTIN NO. "
179
			shippingAddressCell.addElement(new Paragraph("Ship To :\n" + shippingAddress + "\nTIN NO. " + tinNo, new Font(
268
	                + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f)));
180
					FontFamily.TIMES_ROMAN, 8f)));
269
			shippingAddressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
181
			shippingAddressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
270
	        shippingAddressCell.setBorder(Rectangle.LEFT);
182
			shippingAddressCell.setBorder(Rectangle.LEFT);
271
	        billToShipToTable.addCell(addressCell);
183
			billToShipToTable.addCell(addressCell);
272
	        billToShipToTable.addCell(shippingAddressCell);
184
			billToShipToTable.addCell(shippingAddressCell);
273
	        billToShipToCell.addElement(billToShipToTable);
185
			billToShipToCell.addElement(billToShipToTable);
274
	        return billToShipToTable;
186
			return billToShipToTable;
275
			
187
 
276
    	}
188
		}
277
        billToShipToTable.addCell(addressCell);
189
		billToShipToTable.addCell(addressCell);
278
        PdfPCell placeHolderCell = new PdfPCell();
190
		PdfPCell placeHolderCell = new PdfPCell();
279
        placeHolderCell.setBorder(Rectangle.NO_BORDER);
191
		placeHolderCell.setBorder(Rectangle.NO_BORDER);
280
        billToShipToTable.addCell(placeHolderCell);
192
		billToShipToTable.addCell(placeHolderCell);
281
        return billToShipToTable;
193
		return billToShipToTable;
282
    }
194
	}
283
 
195
 
284
    private static PdfPTable getSalutationTable(Supplier supplier)
196
	private static PdfPTable getSalutationTable(Supplier supplier) throws Exception {
285
            throws Exception {
197
		PdfPTable salutationTable = new PdfPTable(1);
286
        PdfPTable salutationTable = new PdfPTable(1);
198
		salutationTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
287
        salutationTable.getDefaultCell().setHorizontalAlignment(
199
		salutationTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
288
                Element.ALIGN_LEFT);
200
		salutationTable.addCell(new Phrase("To", helvetica8));
289
        salutationTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
201
		if (supplier.getName().equals("Smobility Ltd.")) {
290
        salutationTable.addCell(new Phrase("To", helvetica8));
202
			salutationTable.addCell(new Phrase("Spice Retail Ltd.", helvetica8));
291
        if(supplier.getName().equals("Smobility Ltd.")) {
203
		} else if (supplier.getName().equals("Smobility Ltd. - Mumbai")) {
292
        	salutationTable.addCell(new Phrase("Spice Retail Ltd.", helvetica8));
204
			salutationTable.addCell(new Phrase("Spice Retail Ltd. Mumbai", helvetica8));
293
        } else if(supplier.getName().equals("Smobility Ltd. - Mumbai")) {
205
		} else {
294
        	salutationTable.addCell(new Phrase("Spice Retail Ltd. Mumbai", helvetica8));
206
			salutationTable.addCell(new Phrase(supplier.getName(), helvetica8));
295
        } else {
207
		}
296
        	salutationTable.addCell(new Phrase(supplier
208
 
297
                    .getName(), helvetica8));
209
		salutationTable.addCell(new Paragraph(supplier.getCommunicationAddress(), helvetica8));
298
        }
210
		salutationTable.addCell(new Phrase("Dear Sir/Madam", helveticaBold8));
299
        
211
		salutationTable.addCell(new Phrase("Please supply the following stocks as per the details given below:", helvetica8));
300
        salutationTable.addCell(new Paragraph(supplier
212
		salutationTable.addCell(new Phrase(" "));
301
                .getCommunicationAddress(), helvetica8));
213
		return salutationTable;
302
        salutationTable.addCell(new Phrase("Dear Sir/Madam", helveticaBold8));
214
	}
303
        salutationTable
215
 
304
                .addCell(new Phrase(
216
	private static PdfPTable getPoDetailsTable(PurchaseOrder purchaseOrder, Supplier supplier, BuyerInfo binfo)
305
                        "Please supply the following stocks as per the details given below:",
217
			throws CatalogServiceException, TException {
306
                        helvetica8));
218
		float[] widths;
307
        salutationTable.addCell(new Phrase(" "));
219
		TaxType taxType = TaxType.SGST;
308
        return salutationTable;
220
		if(taxType.equals(TaxType.SGST)){
309
    }
221
			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 };
310
 
222
		} else {
311
    private static PdfPTable getPoDetailsTable(PurchaseOrder purchaseOrder,Supplier supplier) throws CatalogServiceException, TException {
223
			widths = new float[] { 0.1f, 0.27f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.08f, 0.1f };
312
        PdfPTable detailsTable = new PdfPTable(new float[] { 0.1f, 0.3f, 0.1f,
224
		}
313
                0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f });
225
		PdfPTable detailsTable = new PdfPTable(widths);
314
        detailsTable.addCell(new Phrase("Sl. No.", helveticaBold8));
226
		
315
        detailsTable.addCell(new Phrase("Description", helveticaBold8));
227
		PdfPCell slNoCell = getHeaderCell("Sl. No");
316
        detailsTable.addCell(new Phrase("Quantity", helveticaBold8));
228
		detailsTable.addCell(slNoCell);
317
        detailsTable.addCell(new Phrase("Mrp", helveticaBold8));
229
		
318
        if(purchaseOrder.getTaxType()==TaxType.CFORM){
230
		PdfPCell description = getHeaderCell("Description");
319
        	detailsTable.addCell(new Phrase("Rate Excl CST(Rs)", helveticaBold8));
231
		detailsTable.addCell(description);
320
        	detailsTable.addCell(new Phrase("CST%",helveticaBold8));
232
 
321
        	detailsTable.addCell(new Phrase("CST Amount",helveticaBold8));
233
		
322
        	detailsTable.addCell(new Phrase("Rate Incl CST(Rs)", helveticaBold8));
234
		PdfPCell hsnCodeCell = getHeaderCell("HSN Code");
323
        } else {
235
		detailsTable.addCell(hsnCodeCell);
324
        	detailsTable.addCell(new Phrase("Rate Excl VAT(Rs)", helveticaBold8));
236
		
325
        	detailsTable.addCell(new Phrase("VAT%",helveticaBold8));
237
		PdfPCell qtyCell = getHeaderCell("Qty");
326
        	detailsTable.addCell(new Phrase("VAT Amount",helveticaBold8));
238
		detailsTable.addCell(qtyCell);
327
        	detailsTable.addCell(new Phrase("Rate Incl VAT(Rs)", helveticaBold8));
239
 
328
        }
240
		PdfPCell rateCell = getHeaderCell("Rate");
329
        detailsTable.addCell(new Phrase("Amount (Rs)", helveticaBold8));
241
		detailsTable.addCell(rateCell);
330
 
242
		
331
        int slNo = 0;
243
		PdfPCell totalCell = getHeaderCell("Total Value");
332
        double total = 0;
244
		detailsTable.addCell(totalCell);
333
        double vatFactor = 0;
245
		
334
        double totalUnits = 0;
246
		PdfPCell taxableAmontCell = getHeaderCell("Taxable Value");
335
        boolean isMRPVat = false;
247
		taxableAmontCell.setRowspan(2);
336
        CatalogClient cClient = new CatalogClient();
248
		detailsTable.addCell(taxableAmontCell);
337
        in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = cClient.getClient();
249
		
338
        if(stateIdMap.get(supplier.getStateId()).getVatType().equals(VatType.MRP)) {
250
		
339
			isMRPVat = true;
251
		if(taxType.equals(TaxType.SGST)) {
340
		}
252
			PdfPCell cell1 = new PdfPCell(new Phrase("CGST", helveticaBold8));
341
        for (in.shop2020.purchase.LineItem lineitem : purchaseOrder
253
			cell1.setColspan(2);
342
                .getLineitems()) {
254
			cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
343
            slNo++;
255
			detailsTable.addCell(cell1);
344
            detailsTable.addCell(new Phrase(slNo + "", helvetica8));
256
 
345
            detailsTable.addCell(getProductNameCell(lineitem));
257
			PdfPCell cell2 = new PdfPCell(new Phrase("SGST", helveticaBold8));
346
            detailsTable.addCell(new Phrase(String.format("%.0f", lineitem.getQuantity()),
258
			cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
347
                    helvetica8));
259
			cell2.setColspan(2);
348
            if(lineitem.isSetMrp() && lineitem.getMrp()>0){
260
			detailsTable.addCell(cell2);
349
	            detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getMrp()),
261
		} else {
350
	                    helvetica8));
262
			PdfPCell cell3 = new PdfPCell(new Phrase("IGST", helveticaBold8));
351
            } else {
263
			cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
352
            	detailsTable.addCell(new Phrase(" ",
264
			cell3.setRowspan(2);
353
	                    helvetica8));
265
		}
354
            }
266
		
355
            if(purchaseOrder.getTaxType()==TaxType.CFORM){
267
		if(taxType.equals(TaxType.SGST)) {
356
            	vatFactor = 2.0;
268
			detailsTable.addCell(new Phrase("Rate(%)", helveticaBold8));
357
            } else {
269
			detailsTable.addCell(new Phrase("Amount", helveticaBold8));
358
            	if(!catalogClient.isAlive()){
270
			detailsTable.addCell(new Phrase("Rate(%)", helveticaBold8));
359
            		catalogClient = cClient.getClient();
271
			detailsTable.addCell(new Phrase("Amount", helveticaBold8));
360
            	}
272
		}else {
361
            	if(isMRPVat){
273
			detailsTable.addCell(new Phrase("Rate(%)", helveticaBold8));
362
            		vatFactor = catalogClient.getVatPercentageForItem(lineitem.getItemId(), supplier.getStateId(), lineitem.getMrp());
274
			detailsTable.addCell(new Phrase("Amount", helveticaBold8));
363
            	}else{
275
		}
364
            		vatFactor = catalogClient.getVatPercentageForItem(lineitem.getItemId(), supplier.getStateId(), lineitem.getUnitPrice());
276
		
365
            	}
277
		int slNo = 0;
366
            }
278
		double total = 0;
367
            double preVatPrice = lineitem.getUnitPrice()/(1+(vatFactor/100));
279
		double vatFactor = 0;
368
            double taxAmount = preVatPrice * (vatFactor/100);
280
		double totalUnits = 0;
369
            detailsTable.addCell(new Phrase(String.format("%.2f", preVatPrice), helvetica8));
281
		String stateCode = null;
370
            detailsTable.addCell(new Phrase(String.format("%.2f", vatFactor), helvetica8));
282
		CatalogClient cClient = new CatalogClient();
371
            detailsTable.addCell(new Phrase(String.format("%.2f", taxAmount), helvetica8));
283
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = cClient.getClient();
372
            detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getUnitPrice()), helvetica8));
284
		for (in.shop2020.purchase.LineItem lineitem : purchaseOrder.getLineitems()) {
373
            double lineTotal = lineitem.getQuantity() * lineitem.getUnitPrice();
285
			slNo++;
374
            totalUnits += lineitem.getQuantity();
286
			detailsTable.addCell(new Phrase(slNo + "", helvetica8));
375
            total += lineTotal;
287
			detailsTable.addCell(getProductNameCell(lineitem));
376
            detailsTable.addCell(new Phrase(String.format("%.2f", lineTotal), helvetica8));
288
			detailsTable.addCell(new Phrase(lineitem.getHsnCode(), helvetica8));
377
        }
289
			detailsTable.addCell(new Phrase(String.format("%d Units", (int)lineitem.getQuantity()), helvetica8));
378
        detailsTable.addCell(getTotalCell(2));
290
			detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getUnitPrice()), helvetica8));
379
        detailsTable.addCell(new Phrase(String.format("%.0f", totalUnits), helvetica8));
291
 
380
        detailsTable.addCell(getTotalAmountCell(6,total));
292
			double totalAmount = lineitem.getUnitPrice()*lineitem.getQuantity();
381
        return detailsTable;
293
			detailsTable.addCell(new Phrase(String.format("%.2f", totalAmount), helvetica8));
382
    }
294
 
383
 
295
			double totalTaxRate = lineitem.getIgstRate() + lineitem.getSgstRate() + lineitem.getCgstRate();
384
    private static PdfPTable getBillToTable(PurchaseOrder po) {
296
			double taxableAmount = totalAmount / (1 + (totalTaxRate / 100));
385
    	//TODO Write this code in a proper configurable way
297
			detailsTable.addCell(new Phrase(String.format("%.2f", taxableAmount), helvetica8));
386
    	String address = "";
298
 
387
    	String tinNo = "";
299
			if(purchaseOrder.getTaxType().equals(TaxType.SGST)) {
388
    	String contactPerson = "";
300
				double cgstAmount = taxableAmount * (lineitem.getCgstRate() / 100);
389
    	BuyerInfo binfo = new BuyerInfo();
301
				detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getCgstRate()), helvetica8));
390
    	try {
302
				detailsTable.addCell(new Phrase(String.format("%.2f", cgstAmount), helvetica8));
391
	    	in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
303
 
-
 
304
				double sgstAmount = taxableAmount * (lineitem.getSgstRate() / 100);
-
 
305
				detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getSgstRate()), helvetica8));
-
 
306
				detailsTable.addCell(new Phrase(String.format("%.2f", sgstAmount), helvetica8));
-
 
307
			} else {
-
 
308
				double igstAmount = taxableAmount * (lineitem.getIgstRate() / 100);
-
 
309
				detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getIgstRate()), helvetica8));
-
 
310
				detailsTable.addCell(new Phrase(String.format("%.2f", igstAmount), helvetica8));
-
 
311
			}
-
 
312
 
-
 
313
			totalUnits += lineitem.getQuantity();
-
 
314
			total += totalAmount;
-
 
315
		}
-
 
316
		detailsTable.addCell(getTotalCell(2));
-
 
317
		detailsTable.addCell(new Phrase(String.format("%.0f", totalUnits), helvetica8));
-
 
318
		detailsTable.addCell(getTotalAmountCell(6, total));
-
 
319
		return detailsTable;
-
 
320
	}
-
 
321
 
-
 
322
	private static PdfPCell getHeaderCell(String headerName) {
-
 
323
		PdfPCell cell = new PdfPCell(new Phrase(headerName, helveticaBold8));
-
 
324
		cell.setRowspan(2);
-
 
325
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
-
 
326
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
-
 
327
		return cell;
-
 
328
	}
-
 
329
	
-
 
330
	private static PdfPTable getBillToTable(PurchaseOrder po) {
-
 
331
		// TODO Write this code in a proper configurable way
-
 
332
		String address = "";
-
 
333
		String gstin = "";
-
 
334
		String contactPerson = "Neeraj Gupta";
-
 
335
		String contactNumber = "9873802000";
-
 
336
		BuyerInfo binfo = new BuyerInfo();
-
 
337
		try {
-
 
338
			in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
392
			binfo = tClient.getBuyerByWarehouse(po.getWarehouseId());
339
			binfo = tClient.getBuyerByWarehouse(po.getWarehouseId());
-
 
340
			gstin = binfo.getGstin();
393
			WarehouseAddress addr = tClient.getWarehouseAddress(po.getWarehouseAddressId());
341
			WarehouseAddress addr = tClient.getWarehouseAddress(po.getWarehouseAddressId());
394
			tinNo = binfo.getTin();
-
 
395
			address = binfo.getOrganisationName() + "\n" + addr.getAddress() + "\n" + "-" + addr.getPin();
342
			address = binfo.getOrganisationName() + "\n" + addr.getAddress() + "\n" + "-" + addr.getPin();
396
    	} catch (Exception e) {
-
 
397
    		logger.error("This should not happen", e);
-
 
398
    	}
-
 
399
    	if(po.getWarehouseId()==7) {
-
 
400
    		contactPerson = "Mr. Varun Patiyal, Contact No. +91 8860488282, +91 9711178101";
-
 
401
    	} else if(po.getWarehouseId() == 12) {
-
 
402
    		contactPerson = "Mr. Avinash Sambhaji Lavange, Contact No. +91 9004049589";
-
 
403
    	} else if(po.getWarehouseId() == 13) {
-
 
404
    		contactPerson = "Mr. Vishal Tayade, Contact No. +91 9819231651";
343
			if (StringUtils.isNotBlank(addr.getContact_person())) {
405
    	} else if(po.getWarehouseId() ==16) {
-
 
406
    		contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
-
 
407
    	} else if(po.getWarehouseId() ==1765) {
-
 
408
    		contactPerson = "Mr. Ravi Kumar, Contact No. +91 9686392567";
344
				contactPerson = addr.getContact_person();
409
    	}
345
			}
410
    	else if(po.getWarehouseId() ==1768) {
-
 
411
    		contactPerson = "Mr. Ravi Kumar, Contact No. +91 9686392567";
346
			if (StringUtils.isNotBlank(addr.getContact_number())) {
412
    	}
-
 
413
    	else if(po.getWarehouseId() ==1771) {
-
 
414
    		contactPerson = "Mr. Ravi Kumar, Contact No. +91 9686392567";
347
				contactNumber = addr.getContact_number();
415
    	}
348
			}
416
    	else if(po.getWarehouseId() ==2854) {
-
 
417
    		contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
-
 
418
    	} 
-
 
419
    	else if(po.getWarehouseId() ==2857) {
349
		} catch (Exception e) {
420
    		contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
-
 
421
    	} 
-
 
422
    	else if(po.getWarehouseId() == 3295) {
-
 
423
    		contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
-
 
424
    	}
-
 
425
    	else if(po.getWarehouseId() == 3298) {
350
			logger.error("This should not happen", e);
426
    		contactPerson = "Mr. Achyuta Ramaiah A, Contact No. +91 9246581582";
-
 
427
    	}
351
		}
428
    	else if(po.getWarehouseId() == 3931) {
-
 
429
    		contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
-
 
430
    	}
-
 
431
    	else if(po.getWarehouseId() == 4699) {
-
 
432
    		contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
-
 
433
    	}
-
 
434
    	else if(po.getWarehouseId() == 5314){
-
 
435
    		contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
-
 
436
    	}
-
 
437
    	else if(po.getWarehouseId() == 5623){
-
 
438
    		contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
-
 
439
    	}
-
 
440
 
352
 
-
 
353
		contactPerson = MessageFormat.format(CONTACT_FORMAT, contactPerson, contactNumber);
441
        PdfPTable billToTable = new PdfPTable(new float[] { 0.2f, 0.8f });
354
		PdfPTable billToTable = new PdfPTable(new float[] { 0.2f, 0.8f });
442
        billToTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
355
		billToTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
443
 
356
 
444
        billToTable.addCell(new Phrase("Bill To :", helvetica8));
357
		billToTable.addCell(new Phrase("Bill To :", helvetica8));
445
        billToTable.addCell(new PdfPCell(new Paragraph(address
358
		billToTable.addCell(new PdfPCell(new Paragraph(address 
-
 
359
				+ "\n\nPlace of Supply - " 
-
 
360
				+ MessageFormat.format("{0}({1})", stateIdMap.get(binfo.getStateId()).getStateName(),stateIdMap.get(binfo.getStateId()).getStateCode())
446
                + "\nTIN NO. " + tinNo, helvetica8)));
361
				+ "\nGST NO. " + gstin, helvetica8)));
447
 
362
 
448
        billToTable.addCell(new Phrase("Contact Person:", helvetica8));
363
		billToTable.addCell(new Phrase("Contact Person:", helvetica8));
449
        billToTable.addCell(new Phrase(contactPerson, helvetica8));
364
		billToTable.addCell(new Phrase(contactPerson, helvetica8));
450
 
365
 
451
        billToTable.addCell(new Phrase("Taxes:", helvetica8));
366
		billToTable.addCell(new Phrase("Taxes:", helvetica8));
452
        if(po.getTaxType() == TaxType.CFORM) {
367
		if (po.getTaxType() == TaxType.CFORM) {
453
        	billToTable.addCell(new Phrase("Prices inclusive of all taxes (To be billed on CST Against C-Form)",
368
			billToTable.addCell(new Phrase("Prices inclusive of all taxes (To be billed on CST Against C-Form)", helvetica8));
454
        			helvetica8));
-
 
455
        } else {
369
		} else {
456
        	billToTable.addCell(new Phrase("Prices inclusive of all taxes",
370
			billToTable.addCell(new Phrase("Prices inclusive of all taxes", helvetica8));
457
        			helvetica8));
-
 
458
        }
371
		}
459
 
372
 
460
        return billToTable;
373
		return billToTable;
461
    }
374
	}
462
 
375
 
463
    private static PdfPCell getProductNameCell(
-
 
464
            in.shop2020.purchase.LineItem lineitem) {
376
	private static PdfPCell getProductNameCell(in.shop2020.purchase.LineItem lineitem) {
465
        String itemName = getItemDisplayName(lineitem);
377
		String itemName = getItemDisplayName(lineitem);
466
        PdfPCell productNameCell = new PdfPCell(
-
 
467
                new Phrase(itemName, helvetica8));
378
		PdfPCell productNameCell = new PdfPCell(new Phrase(itemName, helvetica8));
468
        productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
379
		productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
469
        return productNameCell;
380
		return productNameCell;
470
    }
381
	}
471
 
382
 
472
    private static String getItemDisplayName(
-
 
473
            in.shop2020.purchase.LineItem lineitem) {
383
	private static String getItemDisplayName(in.shop2020.purchase.LineItem lineitem) {
474
        StringBuffer itemName = new StringBuffer();
384
		StringBuffer itemName = new StringBuffer();
475
        if (lineitem.getBrand() != null)
385
		if (lineitem.getBrand() != null)
476
            itemName.append(lineitem.getBrand() + " ");
386
			itemName.append(lineitem.getBrand() + " ");
477
        if (lineitem.getModelName() != null)
387
		if (lineitem.getModelName() != null)
478
            itemName.append(lineitem.getModelName() + " ");
388
			itemName.append(lineitem.getModelName() + " ");
479
        if (lineitem.getModelNumber() != null)
389
		if (lineitem.getModelNumber() != null)
480
            itemName.append(lineitem.getModelNumber() + " ");
390
			itemName.append(lineitem.getModelNumber() + " ");
481
        if (lineitem.getColor() != null
-
 
482
                && !lineitem.getColor().trim().equals("NA"))
391
		if (lineitem.getColor() != null && !lineitem.getColor().trim().equals("NA"))
483
            itemName.append("(" + lineitem.getColor() + ")");
392
			itemName.append("(" + lineitem.getColor() + ")");
484
 
393
 
485
        return itemName.toString();
394
		return itemName.toString();
486
    }
395
	}
487
 
396
 
488
    private static PdfPCell getTotalCell(int colspan) {
397
	private static PdfPCell getTotalCell(int colspan) {
489
        PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
398
		PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
490
        totalCell.setColspan(colspan);
399
		totalCell.setColspan(colspan);
491
        totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
400
		totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
492
        return totalCell;
401
		return totalCell;
493
    }
402
	}
494
    
403
 
495
    private static PdfPCell getTotalAmountCell(int colspan, double totalAmount){
404
	private static PdfPCell getTotalAmountCell(int colspan, double totalAmount) {
496
    	PdfPCell totalCell = new PdfPCell(new Phrase(String.format("%.2f", totalAmount), helvetica8));
405
		PdfPCell totalCell = new PdfPCell(new Phrase(String.format("%.2f", totalAmount), helvetica8));
497
        totalCell.setColspan(colspan);
406
		totalCell.setColspan(colspan);
498
        totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
407
		totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
499
        return totalCell; 
408
		return totalCell;
500
    }
409
	}
501
 
410
 
502
}
411
}