Subversion Repositories SmartDukaan

Rev

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

Rev 23380 Rev 23509
Line 1... Line 1...
1
package com.spice.profitmandi.common.util;
1
package com.spice.profitmandi.common.util;
2
 
2
 
3
 
-
 
4
import java.io.OutputStream;
3
import java.io.OutputStream;
5
import java.util.List;
4
import java.util.List;
6
import java.util.Locale;
5
import java.util.Locale;
7
import java.util.Set;
6
import java.util.Set;
8
 
7
 
Line 23... Line 22...
23
import com.itextpdf.text.pdf.PdfWriter;
22
import com.itextpdf.text.pdf.PdfWriter;
24
import com.spice.profitmandi.common.model.CustomCustomer;
23
import com.spice.profitmandi.common.model.CustomCustomer;
25
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
24
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
26
import com.spice.profitmandi.common.model.CustomOrderItem;
25
import com.spice.profitmandi.common.model.CustomOrderItem;
27
import com.spice.profitmandi.common.model.CustomRetailer;
26
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
27
import com.spice.profitmandi.common.model.DebitNotePdfModel;
28
import com.spice.profitmandi.common.model.PdfModel;
28
import com.spice.profitmandi.common.model.PdfModel;
29
 
29
 
30
public class PdfUtils {
30
public class PdfUtils {
31
	
31
 
32
	private static final Font FONT_TITLE = new Font(Font.FontFamily.HELVETICA  , 18, Font.BOLD);
32
	private static final Font FONT_TITLE = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
33
	private static Font FONT_NORMAL = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL);
33
	private static Font FONT_NORMAL = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL);
34
	private static Font FONT_BOLD = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
34
	private static Font FONT_BOLD = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
-
 
35
	// private static Font fontTableHeader = new
35
	//private static Font fontTableHeader = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD);
36
	// Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD);
36
	private static final String INVOICE_TITLE = "TAX INVOICE";
37
	private static final String INVOICE_TITLE = "TAX INVOICE";
37
	
38
 
38
	private static float[] igstWidthsWithDiscount = new float[]{.3f, 2.6f, 0.7f, .4f, 0.7f, 0.5f, .7f, .6f, 0.6f, 0.9f};
39
	private static float[] igstWidthsWithDiscount = new float[] { .3f, 2.6f, 0.7f, .4f, 0.7f, 0.5f, .7f, .6f, 0.6f,
-
 
40
			0.9f };
39
	private static float[] stateWidthsWithDiscount = new float[]{.2f, 2.1f, 0.7f, .3f, 0.6f, 0.4f, .7f, .5f, .6f, .5f, .6f, .8f};
41
	private static float[] stateWidthsWithDiscount = new float[] { .2f, 2.1f, 0.7f, .3f, 0.6f, 0.4f, .7f, .5f, .6f, .5f,
-
 
42
			.6f, .8f };
40
	
43
 
41
	private static final Locale indianLocale = Locale.getDefault();
44
	private static final Locale indianLocale = Locale.getDefault();
42
	
45
 
43
	private static final Logger LOGGER = LoggerFactory.getLogger(PdfUtils.class);
46
	private static final Logger LOGGER = LoggerFactory.getLogger(PdfUtils.class);
44
	
47
 
45
	public static void generateAndWrite(PdfModel pdfModel, OutputStream outputStream){
48
	public static void generateAndWrite(PdfModel pdfModel, OutputStream outputStream) {
46
		Document document = new Document();
49
		Document document = new Document();
47
		document.setMargins(0, 0, 25, 0);
50
		document.setMargins(0, 0, 25, 0);
48
        try {
51
		try {
49
	        	CustomCustomer customer = pdfModel.getCustomer();
52
			CustomCustomer customer = pdfModel.getCustomer();
50
	        	CustomRetailer retailer = pdfModel.getRetailer();
53
			CustomRetailer retailer = pdfModel.getRetailer();
51
	        	boolean stateGst = false;
54
			boolean stateGst = false;
52
	        	String customerAddressStateCode = "", retailerAddressStateCode = "";
55
			String customerAddressStateCode = "", retailerAddressStateCode = "";
53
        	if(customer.getAddress().getState().equals(retailer.getAddress().getState())){
56
			if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
54
        		stateGst = true;
57
				stateGst = true;
55
        		customerAddressStateCode = Utils.getStateCode(customer.getAddress().getState());
58
				customerAddressStateCode = Utils.getStateCode(customer.getAddress().getState());
56
        	}else{
59
			} else {
57
        		customerAddressStateCode = Utils.getStateCode(customer.getAddress().getState());
60
				customerAddressStateCode = Utils.getStateCode(customer.getAddress().getState());
58
        		retailerAddressStateCode = Utils.getStateCode(retailer.getAddress().getState());
61
				retailerAddressStateCode = Utils.getStateCode(retailer.getAddress().getState());
59
        	}
62
			}
60
        	Set<CustomOrderItem> orderItems = pdfModel.getOrderItems();
63
			Set<CustomOrderItem> orderItems = pdfModel.getOrderItems();
61
        	
64
 
62
            PdfWriter.getInstance(document,outputStream);
65
			PdfWriter.getInstance(document, outputStream);
63
 
66
 
64
            document.open();
67
			document.open();
65
            document.addTitle(pdfModel.getTitle());
68
			document.addTitle(pdfModel.getTitle());
66
            document.addAuthor(pdfModel.getAuther());
69
			document.addAuthor(pdfModel.getAuther());
67
            
70
 
68
            Paragraph paragraphTitle = new Paragraph(INVOICE_TITLE, FONT_TITLE);
71
			Paragraph paragraphTitle = new Paragraph(INVOICE_TITLE, FONT_TITLE);
69
            paragraphTitle.setAlignment(Element.ALIGN_CENTER);
72
			paragraphTitle.setAlignment(Element.ALIGN_CENTER);
70
            
73
 
71
            PdfPCell blankCell = new PdfPCell();
74
			PdfPCell blankCell = new PdfPCell();
72
            blankCell.setBorder(Rectangle.NO_BORDER);
75
			blankCell.setBorder(Rectangle.NO_BORDER);
73
            PdfPTable tableCustomerRetailer = new PdfPTable(3);
76
			PdfPTable tableCustomerRetailer = new PdfPTable(3);
74
            tableCustomerRetailer.setWidthPercentage(90);
77
			tableCustomerRetailer.setWidthPercentage(90);
75
            tableCustomerRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
78
			tableCustomerRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
76
            PdfPCell columnCustomerInfo = new PdfPCell();
79
			PdfPCell columnCustomerInfo = new PdfPCell();
77
            columnCustomerInfo.addElement(new Paragraph("Customer Details", FONT_BOLD));
80
			columnCustomerInfo.addElement(new Paragraph("Customer Details", FONT_BOLD));
78
            columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getFirstName() + " " + customer.getLastName()), FONT_NORMAL));
81
			columnCustomerInfo.addElement(new Paragraph(
79
            columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getLine1()) + ", " + StringUtils.capitalize(customer.getAddress().getLine2()), FONT_NORMAL));
82
					StringUtils.capitalize(customer.getFirstName() + " " + customer.getLastName()), FONT_NORMAL));
80
            columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getCity()) + ", " + StringUtils.capitalize(customer.getAddress().getState()) + "(" + customerAddressStateCode + ")" + "\n" + customer.getAddress().getPinCode(), FONT_NORMAL));
83
			columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getLine1()) + ", "
81
            columnCustomerInfo.addElement(new Paragraph("Mobile - " + customer.getMobileNumber(), FONT_NORMAL));
84
					+ StringUtils.capitalize(customer.getAddress().getLine2()), FONT_NORMAL));
82
            if(customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
85
			columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getCity()) + ", "
83
            		columnCustomerInfo.addElement(new Paragraph("GST Number - " + customer.getGstNumber(), FONT_NORMAL));
86
					+ StringUtils.capitalize(customer.getAddress().getState()) + "(" + customerAddressStateCode + ")"
84
            }
87
					+ "\n" + customer.getAddress().getPinCode(), FONT_NORMAL));
85
            columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
88
			columnCustomerInfo.addElement(new Paragraph("Mobile - " + customer.getMobileNumber(), FONT_NORMAL));
86
            PdfPCell columnRetailerInfo = new PdfPCell();
89
			if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
87
            columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_BOLD));
90
				columnCustomerInfo.addElement(new Paragraph("GST Number - " + customer.getGstNumber(), FONT_NORMAL));
88
            columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getLine1()) + ", " + StringUtils.capitalize(retailer.getAddress().getLine2()) + ", " + StringUtils.capitalize(retailer.getAddress().getCity()) + "-" + retailer.getAddress().getPinCode() + ", " + retailer.getAddress().getState() + "(" + (stateGst? customerAddressStateCode : retailerAddressStateCode) + ")", FONT_BOLD));
91
			}
89
            columnRetailerInfo.addElement(new Paragraph("Contact No.- "+retailer.getAddress().getPhoneNumber(), FONT_BOLD));
92
			columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
90
            columnRetailerInfo.addElement(new Paragraph("GST NO. " + retailer.getGstNumber(), FONT_BOLD));
93
			PdfPCell columnRetailerInfo = new PdfPCell();
91
            columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
94
			columnRetailerInfo
92
            
95
					.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_BOLD));
93
            PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
96
			columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getLine1()) + ", "
94
            tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
97
					+ StringUtils.capitalize(retailer.getAddress().getLine2()) + ", "
95
            
98
					+ StringUtils.capitalize(retailer.getAddress().getCity()) + "-" + retailer.getAddress().getPinCode()
96
            PdfPTable tableInvoiceDate = new PdfPTable(2);
99
					+ ", " + retailer.getAddress().getState() + "("
97
            tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
100
					+ (stateGst ? customerAddressStateCode : retailerAddressStateCode) + ")", FONT_BOLD));
98
            
101
			columnRetailerInfo
99
            PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice No:", FONT_NORMAL));
102
					.addElement(new Paragraph("Contact No.- " + retailer.getAddress().getPhoneNumber(), FONT_BOLD));
100
            invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
103
			columnRetailerInfo.addElement(new Paragraph("GST NO. " + retailer.getGstNumber(), FONT_BOLD));
101
            
104
			columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
102
            PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
105
 
103
            invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
106
			PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
104
            
107
			tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
105
            PdfPCell dateKey = new PdfPCell(new Paragraph("Date:", FONT_NORMAL));
108
 
106
            dateKey.setBorder(Rectangle.NO_BORDER);
109
			PdfPTable tableInvoiceDate = new PdfPTable(2);
107
 
110
			tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
108
            PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
111
 
109
            dateValue.setBorder(Rectangle.NO_BORDER);
112
			PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice No:", FONT_NORMAL));
110
            tableInvoiceDate.addCell(invoiceNumberKey);
113
			invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
111
            //tableInvoiceDate.addCell(blankCell);
114
 
112
            tableInvoiceDate.addCell(invoiceNumberValue);
115
			PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
113
            tableInvoiceDate.addCell(dateKey);
116
			invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
114
            //tableInvoiceDate.addCell(blankCell);
117
 
115
            tableInvoiceDate.addCell(dateValue);
118
			PdfPCell dateKey = new PdfPCell(new Paragraph("Date:", FONT_NORMAL));
116
            tableInvoiceDateRetailer.addCell(tableInvoiceDate);
119
			dateKey.setBorder(Rectangle.NO_BORDER);
117
            tableInvoiceDateRetailer.addCell(columnRetailerInfo);
120
 
118
            
121
			PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
119
            tableCustomerRetailer.addCell(columnCustomerInfo);
122
			dateValue.setBorder(Rectangle.NO_BORDER);
120
            tableCustomerRetailer.addCell(blankCell);
123
			tableInvoiceDate.addCell(invoiceNumberKey);
121
            tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
124
			// tableInvoiceDate.addCell(blankCell);
122
            
125
			tableInvoiceDate.addCell(invoiceNumberValue);
123
            PdfPTable orders = null;
126
			tableInvoiceDate.addCell(dateKey);
124
            if(stateGst){
127
			// tableInvoiceDate.addCell(blankCell);
125
            	orders = new PdfPTable(stateWidthsWithDiscount.length);
128
			tableInvoiceDate.addCell(dateValue);
126
            	orders.setWidths(stateWidthsWithDiscount);
129
			tableInvoiceDateRetailer.addCell(tableInvoiceDate);
127
            }else{
130
			tableInvoiceDateRetailer.addCell(columnRetailerInfo);
128
            	orders = new PdfPTable(igstWidthsWithDiscount.length);
131
 
129
            	orders.setWidths(igstWidthsWithDiscount);
132
			tableCustomerRetailer.addCell(columnCustomerInfo);
130
            }
133
			tableCustomerRetailer.addCell(blankCell);
131
            orders.setWidthPercentage(90);
134
			tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
132
            orders.addCell(new Paragraph("Sl", FONT_BOLD));
135
 
133
            orders.addCell(new Paragraph("Description", FONT_BOLD));
136
			PdfPTable orders = null;
134
            orders.addCell(new Paragraph("HSN", FONT_BOLD));
137
			if (stateGst) {
135
            orders.addCell(new Paragraph("Qty", FONT_BOLD));
138
				orders = new PdfPTable(stateWidthsWithDiscount.length);
136
            orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
139
				orders.setWidths(stateWidthsWithDiscount);
137
            orders.addCell(new Paragraph("Disc.", FONT_BOLD));
140
			} else {
138
            orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
141
				orders = new PdfPTable(igstWidthsWithDiscount.length);
139
            if(!stateGst){
142
				orders.setWidths(igstWidthsWithDiscount);
140
            	orders.addCell(new Paragraph("IGST\n%", FONT_BOLD));
143
			}
141
                orders.addCell(new Paragraph("IGST", FONT_BOLD));
144
			orders.setWidthPercentage(90);
142
                //orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1});
145
			orders.addCell(new Paragraph("Sl", FONT_BOLD));
143
                //total 8f
146
			orders.addCell(new Paragraph("Description", FONT_BOLD));
144
            }else{
147
			orders.addCell(new Paragraph("HSN", FONT_BOLD));
145
            	orders.addCell(new Paragraph("CGST %", FONT_BOLD));
148
			orders.addCell(new Paragraph("Qty", FONT_BOLD));
146
                orders.addCell(new Paragraph("CGST", FONT_BOLD));
149
			orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
147
                orders.addCell(new Paragraph("SGST %", FONT_BOLD));
150
			orders.addCell(new Paragraph("Disc.", FONT_BOLD));
148
                orders.addCell(new Paragraph("SGST", FONT_BOLD));
151
			orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
149
                //orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1, 1, 1});
152
			if (!stateGst) {
150
                //total 8f
153
				orders.addCell(new Paragraph("IGST\n%", FONT_BOLD));
151
            }
154
				orders.addCell(new Paragraph("IGST", FONT_BOLD));
152
            orders.addCell(new Paragraph("Total", FONT_BOLD));
155
				// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1});
153
            
156
				// total 8f
154
            //orders.addCell(new Paragraph("Item Total (Rs)", FONT_BOLD));
157
			} else {
155
            
158
				orders.addCell(new Paragraph("CGST %", FONT_BOLD));
156
            orders.setHeaderRows(1);
159
				orders.addCell(new Paragraph("CGST", FONT_BOLD));
157
            //orders.setSkipFirstHeader(true);
160
				orders.addCell(new Paragraph("SGST %", FONT_BOLD));
158
            
161
				orders.addCell(new Paragraph("SGST", FONT_BOLD));
159
            float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
162
				// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1, 1, 1});
160
            int index = 1;
163
				// total 8f
161
        	for(CustomOrderItem orderItem : orderItems){
164
			}
162
            	orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
165
			orders.addCell(new Paragraph("Total", FONT_BOLD));
163
            	orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
166
 
164
            	orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
167
			// orders.addCell(new Paragraph("Item Total (Rs)", FONT_BOLD));
165
            	orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
168
 
166
            	orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
169
			orders.setHeaderRows(1);
167
            	orders.addCell(new Paragraph(String.format("%.2f", orderItem.getDiscount()), FONT_NORMAL));
170
			// orders.setSkipFirstHeader(true);
168
            	orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
171
 
169
            	if(!stateGst){
172
			float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
170
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
173
			int index = 1;
171
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
174
			for (CustomOrderItem orderItem : orderItems) {
172
            		igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
175
				orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
173
            	}else{
176
				orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
174
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
177
				orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
175
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstAmount()), FONT_NORMAL));
178
				orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
176
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstRate()), FONT_NORMAL));
179
				orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
177
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstAmount()), FONT_NORMAL));
180
				orders.addCell(new Paragraph(String.format("%.2f", orderItem.getDiscount()), FONT_NORMAL));
178
            		cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
181
				orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
179
            		sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
182
				if (!stateGst) {
180
            	}
183
					orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
181
            	orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
184
					orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
182
            	//orders.addCell(new Paragraph(String.format("%.2f", orderItem.getItemTotal()), FONT_NORMAL));
185
					igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
183
            }
186
				} else {
184
        	
187
					orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
185
        	for(CustomInsurancePolicy insurancePolicy : pdfModel.getInsurancePolicies()){
188
					orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstAmount()), FONT_NORMAL));
186
        		orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
189
					orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstRate()), FONT_NORMAL));
187
            	orders.addCell(new Paragraph(insurancePolicy.getDescription(), FONT_NORMAL));
190
					orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstAmount()), FONT_NORMAL));
188
            	orders.addCell(new Paragraph(insurancePolicy.getHsnCode(), FONT_NORMAL));
191
					cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
189
            	orders.addCell(new Paragraph("1", FONT_NORMAL));
192
					sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
190
            	orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
193
				}
191
            	orders.addCell(new Paragraph("-", FONT_NORMAL));
194
				orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
192
            	orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
195
				// orders.addCell(new Paragraph(String.format("%.2f",
193
            	if(!stateGst){
196
				// orderItem.getItemTotal()), FONT_NORMAL));
194
            		orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getIgstRate()), FONT_NORMAL));
197
			}
195
            		orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getIgstAmount()), FONT_NORMAL));
198
 
196
            		igstTotalAmount = igstTotalAmount + insurancePolicy.getIgstAmount();
199
			for (CustomInsurancePolicy insurancePolicy : pdfModel.getInsurancePolicies()) {
197
            	}else{
200
				orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
198
            		orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getCgstRate()), FONT_NORMAL));
201
				orders.addCell(new Paragraph(insurancePolicy.getDescription(), FONT_NORMAL));
199
            		orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getCgstAmount()), FONT_NORMAL));
202
				orders.addCell(new Paragraph(insurancePolicy.getHsnCode(), FONT_NORMAL));
200
            		orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getSgstRate()), FONT_NORMAL));
203
				orders.addCell(new Paragraph("1", FONT_NORMAL));
201
            		orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getSgstAmount()), FONT_NORMAL));
204
				orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
202
            		cgstTotalAmount = cgstTotalAmount + insurancePolicy.getCgstAmount();
205
				orders.addCell(new Paragraph("-", FONT_NORMAL));
203
            		sgstTotalAmount = sgstTotalAmount + insurancePolicy.getSgstAmount();
206
				orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
204
            	}
207
				if (!stateGst) {
205
            	orders.addCell(new Paragraph(String.format("%.0f", insurancePolicy.getNetAmount()), FONT_NORMAL));
208
					orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getIgstRate()), FONT_NORMAL));
206
        	}
209
					orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getIgstAmount()), FONT_NORMAL));
207
 
210
					igstTotalAmount = igstTotalAmount + insurancePolicy.getIgstAmount();
208
        	document.add(paragraphTitle);
211
				} else {
209
            document.add(Chunk.NEWLINE);
212
					orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getCgstRate()), FONT_NORMAL));
210
            document.add(Chunk.NEWLINE);
213
					orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getCgstAmount()), FONT_NORMAL));
211
            document.add(tableCustomerRetailer);
214
					orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getSgstRate()), FONT_NORMAL));
212
            
215
					orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getSgstAmount()), FONT_NORMAL));
213
            document.add(Chunk.NEWLINE);
216
					cgstTotalAmount = cgstTotalAmount + insurancePolicy.getCgstAmount();
214
            document.add(orders);
217
					sgstTotalAmount = sgstTotalAmount + insurancePolicy.getSgstAmount();
215
            
218
				}
216
            PdfPTable grandTotalTable = new PdfPTable(3);
219
				orders.addCell(new Paragraph(String.format("%.0f", insurancePolicy.getNetAmount()), FONT_NORMAL));
217
            if(stateGst){
220
			}
218
            	grandTotalTable.setWidths(new float[]{6.6f, .6f, .8f});
221
 
219
            }else{
222
			document.add(paragraphTitle);
220
            	grandTotalTable.setWidths(new float[]{6.5f, .6f, .9f});
223
			document.add(Chunk.NEWLINE);
221
            }
224
			document.add(Chunk.NEWLINE);
222
            grandTotalTable.setWidthPercentage(90);
225
			document.add(tableCustomerRetailer);
223
            
226
 
224
            Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
227
			document.add(Chunk.NEWLINE);
225
            grandTotalParagraph.setIndentationRight(20);
228
			document.add(orders);
226
            grandTotalTable.addCell(grandTotalParagraph);
229
 
227
            Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
230
			PdfPTable grandTotalTable = new PdfPTable(3);
228
            grandTotalTable.addCell(rsParagraph);
231
			if (stateGst) {
229
            Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
232
				grandTotalTable.setWidths(new float[] { 6.6f, .6f, .8f });
230
            grandTotalTable.addCell(amountParagraph);
233
			} else {
231
            
234
				grandTotalTable.setWidths(new float[] { 6.5f, .6f, .9f });
232
            
235
			}
233
            document.add(grandTotalTable);
236
			grandTotalTable.setWidthPercentage(90);
234
            
237
 
235
            PdfPTable amountInWordsTable = new PdfPTable(3);
238
			Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
236
            if(!stateGst){
239
			grandTotalParagraph.setIndentationRight(20);
237
            	amountInWordsTable.setWidths(new float[]{2, 5.1f, 0.9f});
240
			grandTotalTable.addCell(grandTotalParagraph);
238
            }else{
241
			Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
239
            	amountInWordsTable.setWidths(new float[]{2, 5.2f, 0.8f});
242
			grandTotalTable.addCell(rsParagraph);
240
            }
243
			Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
241
            amountInWordsTable.setWidthPercentage(90);
244
			grandTotalTable.addCell(amountParagraph);
242
            amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
245
 
243
            
246
			document.add(grandTotalTable);
244
            String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
247
 
245
           	amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
248
			PdfPTable amountInWordsTable = new PdfPTable(3);
246
            amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
249
			if (!stateGst) {
247
            document.add(amountInWordsTable);            
250
				amountInWordsTable.setWidths(new float[] { 2, 5.1f, 0.9f });
248
            
251
			} else {
249
            StringBuffer sb = new StringBuffer();
252
				amountInWordsTable.setWidths(new float[] { 2, 5.2f, 0.8f });
250
            List<String> tncs = pdfModel.getTncs();
253
			}
251
            for (String tnc: tncs){
254
			amountInWordsTable.setWidthPercentage(90);
252
            	sb.append(tnc).append("\n");
255
			amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
253
            }
256
 
254
            
257
			String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
255
            Paragraph warningParagraph = new Paragraph(sb.toString(), FONT_NORMAL);
258
			amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
256
            warningParagraph.setIndentationLeft(40);
259
			amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
257
            document.add(Chunk.NEWLINE);
260
			document.add(amountInWordsTable);
258
            document.add(warningParagraph);
261
 
259
            
262
			StringBuffer sb = new StringBuffer();
260
            document.close(); // no need to close PDFwriter?
263
			List<String> tncs = pdfModel.getTncs();
261
 
264
			for (String tnc : tncs) {
262
        } catch (DocumentException e) {
265
				sb.append(tnc).append("\n");
263
            LOGGER.error("Unable to write data to pdf file : ", e);
266
			}
264
        } catch (Exception e) {
267
 
-
 
268
			Paragraph warningParagraph = new Paragraph(sb.toString(), FONT_NORMAL);
-
 
269
			warningParagraph.setIndentationLeft(40);
-
 
270
			document.add(Chunk.NEWLINE);
-
 
271
			document.add(warningParagraph);
-
 
272
 
-
 
273
			document.close(); // no need to close PDFwriter?
-
 
274
 
-
 
275
		} catch (DocumentException e) {
-
 
276
			LOGGER.error("Unable to write data to pdf file : ", e);
-
 
277
		} catch (Exception e) {
265
			// TODO Auto-generated catch block
278
			// TODO Auto-generated catch block
266
			e.printStackTrace();
279
			e.printStackTrace();
267
		}
280
		}
268
	}
281
	}
-
 
282
 
-
 
283
	public static void generateAndWriteDebitNote(List<DebitNotePdfModel> debitNotePdfModels,
-
 
284
			OutputStream outputStream) {
-
 
285
		Document document = new Document();
-
 
286
		document.setMargins(0, 0, 25, 0);
-
 
287
		try {
-
 
288
			for (DebitNotePdfModel debitNotePdfModel : debitNotePdfModels) {
-
 
289
 
-
 
290
				PdfModel pdfModel = debitNotePdfModel.getPdfModel();
-
 
291
				CustomCustomer customer = pdfModel.getCustomer();
-
 
292
				CustomRetailer retailer = pdfModel.getRetailer();
-
 
293
				boolean stateGst = false;
-
 
294
				String customerAddressStateCode = "", retailerAddressStateCode = "";
-
 
295
				if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
-
 
296
					stateGst = true;
-
 
297
					customerAddressStateCode = Utils.getStateCode(customer.getAddress().getState());
-
 
298
				} else {
-
 
299
					customerAddressStateCode = Utils.getStateCode(customer.getAddress().getState());
-
 
300
					retailerAddressStateCode = Utils.getStateCode(retailer.getAddress().getState());
-
 
301
				}
-
 
302
				Set<CustomOrderItem> orderItems = pdfModel.getOrderItems();
-
 
303
 
-
 
304
				PdfWriter.getInstance(document, outputStream);
-
 
305
 
-
 
306
				document.open();
-
 
307
				document.addTitle(pdfModel.getTitle());
-
 
308
				document.addAuthor(pdfModel.getAuther());
-
 
309
 
-
 
310
				Paragraph paragraphTitle = new Paragraph(INVOICE_TITLE, FONT_TITLE);
-
 
311
				paragraphTitle.setAlignment(Element.ALIGN_CENTER);
-
 
312
 
-
 
313
				PdfPCell blankCell = new PdfPCell();
-
 
314
				blankCell.setBorder(Rectangle.NO_BORDER);
-
 
315
				PdfPTable tableCustomerRetailer = new PdfPTable(3);
-
 
316
				tableCustomerRetailer.setWidthPercentage(90);
-
 
317
				tableCustomerRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
-
 
318
				PdfPCell columnCustomerInfo = new PdfPCell();
-
 
319
				columnCustomerInfo.addElement(new Paragraph("Customer Details", FONT_BOLD));
-
 
320
				columnCustomerInfo.addElement(new Paragraph(
-
 
321
						StringUtils.capitalize(customer.getFirstName() + " " + customer.getLastName()), FONT_NORMAL));
-
 
322
				columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getLine1())
-
 
323
						+ ", " + StringUtils.capitalize(customer.getAddress().getLine2()), FONT_NORMAL));
-
 
324
				columnCustomerInfo.addElement(new Paragraph(
-
 
325
						StringUtils.capitalize(customer.getAddress().getCity()) + ", "
-
 
326
								+ StringUtils.capitalize(customer.getAddress().getState()) + "("
-
 
327
								+ customerAddressStateCode + ")" + "\n" + customer.getAddress().getPinCode(),
-
 
328
						FONT_NORMAL));
-
 
329
				columnCustomerInfo.addElement(new Paragraph("Mobile - " + customer.getMobileNumber(), FONT_NORMAL));
-
 
330
				if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
-
 
331
					columnCustomerInfo
-
 
332
							.addElement(new Paragraph("GST Number - " + customer.getGstNumber(), FONT_NORMAL));
-
 
333
				}
-
 
334
				columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
-
 
335
				PdfPCell columnRetailerInfo = new PdfPCell();
-
 
336
				columnRetailerInfo
-
 
337
						.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_BOLD));
-
 
338
				columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getLine1())
-
 
339
						+ ", " + StringUtils.capitalize(retailer.getAddress().getLine2()) + ", "
-
 
340
						+ StringUtils.capitalize(retailer.getAddress().getCity()) + "-"
-
 
341
						+ retailer.getAddress().getPinCode() + ", " + retailer.getAddress().getState() + "("
-
 
342
						+ (stateGst ? customerAddressStateCode : retailerAddressStateCode) + ")", FONT_BOLD));
-
 
343
				columnRetailerInfo
-
 
344
						.addElement(new Paragraph("Contact No.- " + retailer.getAddress().getPhoneNumber(), FONT_BOLD));
-
 
345
				columnRetailerInfo.addElement(new Paragraph("GST NO. " + retailer.getGstNumber(), FONT_BOLD));
-
 
346
				columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
-
 
347
 
-
 
348
				PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
-
 
349
				tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
-
 
350
 
-
 
351
				PdfPTable tableInvoiceDate = new PdfPTable(2);
-
 
352
				tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
-
 
353
 
-
 
354
				PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice No:", FONT_NORMAL));
-
 
355
				invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
-
 
356
 
-
 
357
				PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
-
 
358
				invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
-
 
359
 
-
 
360
				PdfPCell dateKey = new PdfPCell(new Paragraph("Date:", FONT_NORMAL));
-
 
361
				dateKey.setBorder(Rectangle.NO_BORDER);
-
 
362
 
-
 
363
				PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
-
 
364
				dateValue.setBorder(Rectangle.NO_BORDER);
-
 
365
				tableInvoiceDate.addCell(invoiceNumberKey);
-
 
366
				// tableInvoiceDate.addCell(blankCell);
-
 
367
				tableInvoiceDate.addCell(invoiceNumberValue);
-
 
368
				tableInvoiceDate.addCell(dateKey);
-
 
369
				// tableInvoiceDate.addCell(blankCell);
-
 
370
				tableInvoiceDate.addCell(dateValue);
-
 
371
				tableInvoiceDateRetailer.addCell(tableInvoiceDate);
-
 
372
				tableInvoiceDateRetailer.addCell(columnRetailerInfo);
-
 
373
 
-
 
374
				tableCustomerRetailer.addCell(columnCustomerInfo);
-
 
375
				tableCustomerRetailer.addCell(blankCell);
-
 
376
				tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
-
 
377
 
-
 
378
				PdfPTable orders = null;
-
 
379
				if (stateGst) {
-
 
380
					orders = new PdfPTable(stateWidthsWithDiscount.length);
-
 
381
					orders.setWidths(stateWidthsWithDiscount);
-
 
382
				} else {
-
 
383
					orders = new PdfPTable(igstWidthsWithDiscount.length);
-
 
384
					orders.setWidths(igstWidthsWithDiscount);
-
 
385
				}
-
 
386
				orders.setWidthPercentage(90);
-
 
387
				orders.addCell(new Paragraph("Sl", FONT_BOLD));
-
 
388
				orders.addCell(new Paragraph("Description", FONT_BOLD));
-
 
389
				orders.addCell(new Paragraph("HSN", FONT_BOLD));
-
 
390
				orders.addCell(new Paragraph("Qty", FONT_BOLD));
-
 
391
				orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
-
 
392
				orders.addCell(new Paragraph("Disc.", FONT_BOLD));
-
 
393
				orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
-
 
394
				if (!stateGst) {
-
 
395
					orders.addCell(new Paragraph("IGST\n%", FONT_BOLD));
-
 
396
					orders.addCell(new Paragraph("IGST", FONT_BOLD));
-
 
397
					// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1});
-
 
398
					// total 8f
-
 
399
				} else {
-
 
400
					orders.addCell(new Paragraph("CGST %", FONT_BOLD));
-
 
401
					orders.addCell(new Paragraph("CGST", FONT_BOLD));
-
 
402
					orders.addCell(new Paragraph("SGST %", FONT_BOLD));
-
 
403
					orders.addCell(new Paragraph("SGST", FONT_BOLD));
-
 
404
					// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1, 1,
-
 
405
					// 1});
-
 
406
					// total 8f
-
 
407
				}
-
 
408
				orders.addCell(new Paragraph("Total", FONT_BOLD));
-
 
409
 
-
 
410
				// orders.addCell(new Paragraph("Item Total (Rs)", FONT_BOLD));
-
 
411
 
-
 
412
				orders.setHeaderRows(1);
-
 
413
				// orders.setSkipFirstHeader(true);
-
 
414
 
-
 
415
				float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
-
 
416
				int index = 1;
-
 
417
				for (CustomOrderItem orderItem : orderItems) {
-
 
418
					orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
-
 
419
					orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
-
 
420
					orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
-
 
421
					orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
-
 
422
					orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
-
 
423
					orders.addCell(new Paragraph(String.format("%.2f", orderItem.getDiscount()), FONT_NORMAL));
-
 
424
					orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
-
 
425
					if (!stateGst) {
-
 
426
						orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
-
 
427
						orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
-
 
428
						igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
-
 
429
					} else {
-
 
430
						orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
-
 
431
						orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstAmount()), FONT_NORMAL));
-
 
432
						orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstRate()), FONT_NORMAL));
-
 
433
						orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstAmount()), FONT_NORMAL));
-
 
434
						cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
-
 
435
						sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
-
 
436
					}
-
 
437
					orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
-
 
438
					// orders.addCell(new Paragraph(String.format("%.2f",
-
 
439
					// orderItem.getItemTotal()), FONT_NORMAL));
-
 
440
				}
-
 
441
 
-
 
442
				for (CustomInsurancePolicy insurancePolicy : pdfModel.getInsurancePolicies()) {
-
 
443
					orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
-
 
444
					orders.addCell(new Paragraph(insurancePolicy.getDescription(), FONT_NORMAL));
-
 
445
					orders.addCell(new Paragraph(insurancePolicy.getHsnCode(), FONT_NORMAL));
-
 
446
					orders.addCell(new Paragraph("1", FONT_NORMAL));
-
 
447
					orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
-
 
448
					orders.addCell(new Paragraph("-", FONT_NORMAL));
-
 
449
					orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
-
 
450
					if (!stateGst) {
-
 
451
						orders.addCell(
-
 
452
								new Paragraph(String.format("%.2f", insurancePolicy.getIgstRate()), FONT_NORMAL));
-
 
453
						orders.addCell(
-
 
454
								new Paragraph(String.format("%.2f", insurancePolicy.getIgstAmount()), FONT_NORMAL));
-
 
455
						igstTotalAmount = igstTotalAmount + insurancePolicy.getIgstAmount();
-
 
456
					} else {
-
 
457
						orders.addCell(
-
 
458
								new Paragraph(String.format("%.2f", insurancePolicy.getCgstRate()), FONT_NORMAL));
-
 
459
						orders.addCell(
-
 
460
								new Paragraph(String.format("%.2f", insurancePolicy.getCgstAmount()), FONT_NORMAL));
-
 
461
						orders.addCell(
-
 
462
								new Paragraph(String.format("%.2f", insurancePolicy.getSgstRate()), FONT_NORMAL));
-
 
463
						orders.addCell(
-
 
464
								new Paragraph(String.format("%.2f", insurancePolicy.getSgstAmount()), FONT_NORMAL));
-
 
465
						cgstTotalAmount = cgstTotalAmount + insurancePolicy.getCgstAmount();
-
 
466
						sgstTotalAmount = sgstTotalAmount + insurancePolicy.getSgstAmount();
-
 
467
					}
-
 
468
					orders.addCell(new Paragraph(String.format("%.0f", insurancePolicy.getNetAmount()), FONT_NORMAL));
-
 
469
				}
-
 
470
 
-
 
471
				document.add(paragraphTitle);
-
 
472
				document.add(Chunk.NEWLINE);
-
 
473
				document.add(Chunk.NEWLINE);
-
 
474
				document.add(tableCustomerRetailer);
-
 
475
 
-
 
476
				document.add(Chunk.NEWLINE);
-
 
477
				document.add(orders);
-
 
478
 
-
 
479
				PdfPTable grandTotalTable = new PdfPTable(3);
-
 
480
				if (stateGst) {
-
 
481
					grandTotalTable.setWidths(new float[] { 6.6f, .6f, .8f });
-
 
482
				} else {
-
 
483
					grandTotalTable.setWidths(new float[] { 6.5f, .6f, .9f });
-
 
484
				}
-
 
485
				grandTotalTable.setWidthPercentage(90);
-
 
486
 
-
 
487
				Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
-
 
488
				grandTotalParagraph.setIndentationRight(20);
-
 
489
				grandTotalTable.addCell(grandTotalParagraph);
-
 
490
				Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
-
 
491
				grandTotalTable.addCell(rsParagraph);
-
 
492
				Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
-
 
493
				grandTotalTable.addCell(amountParagraph);
-
 
494
 
-
 
495
				document.add(grandTotalTable);
-
 
496
 
-
 
497
				PdfPTable amountInWordsTable = new PdfPTable(3);
-
 
498
				if (!stateGst) {
-
 
499
					amountInWordsTable.setWidths(new float[] { 2, 5.1f, 0.9f });
-
 
500
				} else {
-
 
501
					amountInWordsTable.setWidths(new float[] { 2, 5.2f, 0.8f });
-
 
502
				}
-
 
503
				amountInWordsTable.setWidthPercentage(90);
-
 
504
				amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
-
 
505
 
-
 
506
				String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
-
 
507
				amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
-
 
508
				amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
-
 
509
				document.add(amountInWordsTable);
-
 
510
 
-
 
511
				StringBuffer sb = new StringBuffer();
-
 
512
				List<String> tncs = pdfModel.getTncs();
-
 
513
				for (String tnc : tncs) {
-
 
514
					sb.append(tnc).append("\n");
-
 
515
				}
-
 
516
 
-
 
517
				Paragraph warningParagraph = new Paragraph(sb.toString(), FONT_NORMAL);
-
 
518
				warningParagraph.setIndentationLeft(40);
-
 
519
				document.add(Chunk.NEWLINE);
-
 
520
				document.add(warningParagraph);
-
 
521
				document.newPage();
-
 
522
			}
-
 
523
			document.close(); // no need to close PDFwriter?
-
 
524
		} catch (DocumentException e) {
-
 
525
			LOGGER.error("Unable to write data to pdf file : ", e);
-
 
526
		} catch (Exception e) {
-
 
527
			// TODO Auto-generated catch block
-
 
528
			e.printStackTrace();
-
 
529
		}
269
	
530
	}
-
 
531
 
270
	private static String toAmountInWords(float amount){
532
	private static String toAmountInWords(float amount) {
271
		RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
533
		RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale,
-
 
534
				RuleBasedNumberFormat.SPELLOUT);
272
       	StringBuilder amountInWords = new StringBuilder("Rs. ");
535
		StringBuilder amountInWords = new StringBuilder("Rs. ");
273
        amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int)amount)));
536
		amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int) amount)));
274
       	amountInWords.append(" and ");
537
		amountInWords.append(" and ");
275
        amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int)(amount*100)%100)));
538
		amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int) (amount * 100) % 100)));
276
       	amountInWords.append(" paise");
539
		amountInWords.append(" paise");
277
       	return amountInWords.toString();
540
		return amountInWords.toString();
278
	}
541
	}
279
}
542
}