Subversion Repositories SmartDukaan

Rev

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

Rev 22025 Rev 22068
Line 7... Line 7...
7
import java.util.Locale;
7
import java.util.Locale;
8
import java.util.Set;
8
import java.util.Set;
9
 
9
 
10
import org.slf4j.Logger;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
11
import org.slf4j.LoggerFactory;
-
 
12
import org.springframework.util.StringUtils;
12
 
13
 
13
import com.ibm.icu.text.RuleBasedNumberFormat;
14
import com.ibm.icu.text.RuleBasedNumberFormat;
14
import com.itextpdf.text.Chunk;
15
import com.itextpdf.text.Chunk;
15
import com.itextpdf.text.Document;
16
import com.itextpdf.text.Document;
16
import com.itextpdf.text.DocumentException;
17
import com.itextpdf.text.DocumentException;
Line 69... Line 70...
69
            blankCell.setBorder(Rectangle.NO_BORDER);
70
            blankCell.setBorder(Rectangle.NO_BORDER);
70
            PdfPTable tableCustomerRetailer = new PdfPTable(3);
71
            PdfPTable tableCustomerRetailer = new PdfPTable(3);
71
            tableCustomerRetailer.setWidthPercentage(90);
72
            tableCustomerRetailer.setWidthPercentage(90);
72
            tableCustomerRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
73
            tableCustomerRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
73
            PdfPCell columnCustomerInfo = new PdfPCell();
74
            PdfPCell columnCustomerInfo = new PdfPCell();
74
            columnCustomerInfo.addElement(new Paragraph(customer.getName(), FONT_NORMAL));
75
            columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getName()), FONT_NORMAL));
75
            columnCustomerInfo.addElement(new Paragraph(customer.getAddress().getLine1() + ", " + customer.getAddress().getLine2(), FONT_NORMAL));
76
            columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getLine1()) + ", " + StringUtils.capitalize(customer.getAddress().getLine2()), FONT_NORMAL));
76
            columnCustomerInfo.addElement(new Paragraph(customer.getAddress().getCity() + ", " + customer.getAddress().getState() + "(" + customerAddressStateCode + ")" + "\n" + customer.getAddress().getPinCode(), FONT_NORMAL));
77
            columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getCity()) + ", " + StringUtils.capitalize(customer.getAddress().getState()) + "(" + customerAddressStateCode + ")" + "\n" + customer.getAddress().getPinCode(), FONT_NORMAL));
77
            columnCustomerInfo.addElement(new Paragraph(customer.getMobileNumber(), FONT_NORMAL));
78
            columnCustomerInfo.addElement(new Paragraph(customer.getMobileNumber(), FONT_NORMAL));
78
            columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
79
            columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
79
            PdfPCell columnRetailerInfo = new PdfPCell();
80
            PdfPCell columnRetailerInfo = new PdfPCell();
80
            //columnRetailerInfo.addElement(new Paragraph("Invoice No:"));
81
            //columnRetailerInfo.addElement(new Paragraph("Invoice No:"));
81
            columnRetailerInfo.addElement(new Paragraph(retailer.getBusinessName(), FONT_BOLD));
82
            columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getBusinessName()), FONT_BOLD));
82
           // columnRetailerInfo.addElement(new Paragraph("Plot No. 485, Udyog Vihar Phase V, Gurgoan-122016", FONT_BOLD));
83
           // columnRetailerInfo.addElement(new Paragraph("Plot No. 485, Udyog Vihar Phase V, Gurgoan-122016", FONT_BOLD));
83
            columnRetailerInfo.addElement(new Paragraph(retailer.getAddress().getLine1() + ", " + retailer.getAddress().getLine2() + ", " + retailer.getAddress().getCity() + "-" + retailer.getAddress().getPinCode() + ", " + retailer.getAddress().getState() + "(" + (gstWithInState? customerAddressStateCode : retailerAddressStateCode) + ")", FONT_BOLD));
84
            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() + "(" + (gstWithInState? customerAddressStateCode : retailerAddressStateCode) + ")", FONT_BOLD));
84
            columnRetailerInfo.addElement(new Paragraph("Contact No.- "+retailer.getMobileNumber(), FONT_BOLD));
85
            columnRetailerInfo.addElement(new Paragraph("Contact No.- "+retailer.getMobileNumber(), FONT_BOLD));
85
            columnRetailerInfo.addElement(new Paragraph("TIN NO. " + retailer.getTinNumber(), FONT_BOLD));
86
            columnRetailerInfo.addElement(new Paragraph("TIN NO. " + retailer.getTinNumber(), FONT_BOLD));
86
            columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
87
            columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
87
            PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
88
            PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
88
            tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
89
            tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
Line 110... Line 111...
110
            tableCustomerRetailer.addCell(columnCustomerInfo);
111
            tableCustomerRetailer.addCell(columnCustomerInfo);
111
            tableCustomerRetailer.addCell(blankCell);
112
            tableCustomerRetailer.addCell(blankCell);
112
            tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
113
            tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
113
            
114
            
114
            PdfPTable orders = null;
115
            PdfPTable orders = null;
115
            if(gstWithInState){
116
            if(!gstWithInState){
116
            	orders = new PdfPTable(8);
117
            	orders = new PdfPTable(8);
117
            }else{
118
            }else{
118
            	orders = new PdfPTable(10);
119
            	orders = new PdfPTable(10);
119
            }
120
            }
120
            orders.setWidthPercentage(90);
121
            orders.setWidthPercentage(90);
Line 140... Line 141...
140
            orders.addCell(new Paragraph("Description", FONT_BOLD));
141
            orders.addCell(new Paragraph("Description", FONT_BOLD));
141
            orders.addCell(new Paragraph("HSN Code", FONT_BOLD));
142
            orders.addCell(new Paragraph("HSN Code", FONT_BOLD));
142
            orders.addCell(new Paragraph("Qty", FONT_BOLD));
143
            orders.addCell(new Paragraph("Qty", FONT_BOLD));
143
            orders.addCell(new Paragraph("Rate (Rs)", FONT_BOLD));
144
            orders.addCell(new Paragraph("Rate (Rs)", FONT_BOLD));
144
            orders.addCell(new Paragraph("Amount (Rs)", FONT_BOLD));
145
            orders.addCell(new Paragraph("Amount (Rs)", FONT_BOLD));
145
            if(gstWithInState){
146
            if(!gstWithInState){
146
            	orders.addCell(new Paragraph("IGST Rate%", FONT_BOLD));
147
            	orders.addCell(new Paragraph("IGST Rate%", FONT_BOLD));
147
                orders.addCell(new Paragraph("IGST Amount", FONT_BOLD));
148
                orders.addCell(new Paragraph("IGST Amount", FONT_BOLD));
148
                //orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1});
149
                //orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1});
149
                orders.setWidths(new float[]{.7f, 3, 1.2f, .7f, 1.1f, 1.1f, .9f, .9f});
150
                orders.setWidths(new float[]{.7f, 3, 1.2f, .7f, 1.1f, 1.1f, .9f, .9f});
150
            }else{
151
            }else{
Line 168... Line 169...
168
            	orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
169
            	orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
169
            	orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
170
            	orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
170
            	orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
171
            	orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
171
            	orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
172
            	orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
172
            	orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
173
            	orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
173
            	if(gstWithInState){
174
            	if(!gstWithInState){
174
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
175
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
175
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
176
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
176
            		igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
177
            		igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
177
            	}else{
178
            	}else{
178
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
179
            		orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
Line 203... Line 204...
203
            
204
            
204
            
205
            
205
            
206
            
206
            
207
            
207
            PdfPTable gstTotalTable = null;
208
            PdfPTable gstTotalTable = null;
208
            if(gstWithInState){
209
            if(!gstWithInState){
209
            	gstTotalTable = new PdfPTable(3);
210
            	gstTotalTable = new PdfPTable(3);
210
            	gstTotalTable.setWidths(new float[]{8, .9f, .9f});
211
            	gstTotalTable.setWidths(new float[]{8, .9f, .9f});
211
            }else{
212
            }else{
212
            	gstTotalTable = new PdfPTable(5);
213
            	gstTotalTable = new PdfPTable(5);
213
            	gstTotalTable.setWidths(new float[]{8, .9f, .9f, .9f, .9f});
214
            	gstTotalTable.setWidths(new float[]{8, .9f, .9f, .9f, .9f});
Line 219... Line 220...
219
            //PdfPCell grandTotalCell = new PdfPCell(new Paragraph("Grand total", fontBold));
220
            //PdfPCell grandTotalCell = new PdfPCell(new Paragraph("Grand total", fontBold));
220
            //grandTotalCell.setVerticalAlignment(Element.ALIGN_RIGHT);
221
            //grandTotalCell.setVerticalAlignment(Element.ALIGN_RIGHT);
221
            Paragraph gstTotalParagraph = new Paragraph("Gst Total", FONT_BOLD);
222
            Paragraph gstTotalParagraph = new Paragraph("Gst Total", FONT_BOLD);
222
            gstTotalParagraph.setIndentationRight(20);
223
            gstTotalParagraph.setIndentationRight(20);
223
            gstTotalTable.addCell(gstTotalParagraph);
224
            gstTotalTable.addCell(gstTotalParagraph);
224
            if(gstWithInState){
225
            if(!gstWithInState){
225
            	gstTotalTable.addCell(new Paragraph("IGST", FONT_BOLD));
226
            	gstTotalTable.addCell(new Paragraph("IGST", FONT_BOLD));
226
            	gstTotalTable.addCell(new Paragraph(String.format("%.2f", igstTotalAmount), FONT_BOLD));
227
            	gstTotalTable.addCell(new Paragraph(String.format("%.2f", igstTotalAmount), FONT_BOLD));
227
            }else{
228
            }else{
228
            	gstTotalTable.addCell(new Paragraph("CGST", FONT_BOLD));
229
            	gstTotalTable.addCell(new Paragraph("CGST", FONT_BOLD));
229
            	gstTotalTable.addCell(new Paragraph(String.format("%.2f", cgstTotalAmount), FONT_BOLD));
230
            	gstTotalTable.addCell(new Paragraph(String.format("%.2f", cgstTotalAmount), FONT_BOLD));
Line 233... Line 234...
233
            
234
            
234
            //grandTotalCell.setColspan(6);
235
            //grandTotalCell.setColspan(6);
235
            document.add(gstTotalTable);
236
            document.add(gstTotalTable);
236
            
237
            
237
            PdfPTable grandTotalTable = new PdfPTable(3);
238
            PdfPTable grandTotalTable = new PdfPTable(3);
238
            if(gstWithInState){
239
            if(!gstWithInState){
239
            	grandTotalTable.setWidths(new float[]{8, .9f, .9f});
240
            	grandTotalTable.setWidths(new float[]{8, .9f, .9f});
240
            }else{
241
            }else{
241
            	grandTotalTable.setWidths(new float[]{10, .9f, .9f});
242
            	grandTotalTable.setWidths(new float[]{10, .9f, .9f});
242
            }
243
            }
243
            grandTotalTable.setWidthPercentage(90);
244
            grandTotalTable.setWidthPercentage(90);
Line 252... Line 253...
252
            
253
            
253
            
254
            
254
            document.add(grandTotalTable);
255
            document.add(grandTotalTable);
255
            
256
            
256
            PdfPTable amountInWordsTable = new PdfPTable(3);
257
            PdfPTable amountInWordsTable = new PdfPTable(3);
257
            if(gstWithInState){
258
            if(!gstWithInState){
258
            	amountInWordsTable.setWidths(new float[]{2, 5, 2.7f});
259
            	amountInWordsTable.setWidths(new float[]{2, 5, 2.7f});
259
            }else{
260
            }else{
260
            	amountInWordsTable.setWidths(new float[]{2, 7, 2.7f});
261
            	amountInWordsTable.setWidths(new float[]{2, 7, 2.7f});
261
            }
262
            }
262
            amountInWordsTable.setWidthPercentage(90);
263
            amountInWordsTable.setWidthPercentage(90);
Line 294... Line 295...
294
			// TODO Auto-generated catch block
295
			// TODO Auto-generated catch block
295
			e.printStackTrace();
296
			e.printStackTrace();
296
		}
297
		}
297
	}
298
	}
298
	
299
	
299
	@SuppressWarnings("deprecation")
-
 
300
	private static String toAmountInWords(float amount){
300
	private static String toAmountInWords(float amount){
301
		RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
301
		RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
302
       	StringBuilder amountInWords = new StringBuilder("Rs. ");
302
       	StringBuilder amountInWords = new StringBuilder("Rs. ");
303
        amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)amount)));
303
        amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int)amount)));
304
       	amountInWords.append(" and ");
304
       	amountInWords.append(" and ");
305
        amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)(amount*100)%100)));
305
        amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int)(amount*100)%100)));
306
       	amountInWords.append(" paise");
306
       	amountInWords.append(" paise");
307
       	return amountInWords.toString();
307
       	return amountInWords.toString();
308
	}
308
	}
309
}
309
}