| 2787 |
chandransh |
1 |
package in.shop2020.hotspot.dashbaord.server;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.config.ConfigException;
|
| 3044 |
chandransh |
4 |
import in.shop2020.logistics.DeliveryType;
|
| 2787 |
chandransh |
5 |
import in.shop2020.logistics.LogisticsServiceException;
|
| 5527 |
anupam.sin |
6 |
import in.shop2020.logistics.PickUpType;
|
| 5556 |
rajveer |
7 |
import in.shop2020.logistics.PickupStore;
|
| 2787 |
chandransh |
8 |
import in.shop2020.logistics.Provider;
|
| 7792 |
anupam.sin |
9 |
import in.shop2020.logistics.ProviderDetails;
|
| 7190 |
amar.kumar |
10 |
import in.shop2020.model.v1.catalog.CatalogService;
|
|
|
11 |
import in.shop2020.model.v1.catalog.Item;
|
| 6746 |
rajveer |
12 |
import in.shop2020.model.v1.inventory.BillingType;
|
| 5948 |
mandeep.dh |
13 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
| 5945 |
mandeep.dh |
14 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| 7528 |
rajveer |
15 |
import in.shop2020.model.v1.order.AmazonOrder;
|
| 5527 |
anupam.sin |
16 |
import in.shop2020.model.v1.order.Attribute;
|
| 2787 |
chandransh |
17 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
18 |
import in.shop2020.model.v1.order.Order;
|
| 7318 |
rajveer |
19 |
import in.shop2020.model.v1.order.OrderSource;
|
| 4361 |
rajveer |
20 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 5527 |
anupam.sin |
21 |
import in.shop2020.model.v1.order.OrderType;
|
| 7190 |
amar.kumar |
22 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 3132 |
rajveer |
23 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
24 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 2787 |
chandransh |
25 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 5948 |
mandeep.dh |
26 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 2787 |
chandransh |
27 |
|
|
|
28 |
import java.io.ByteArrayOutputStream;
|
|
|
29 |
import java.io.File;
|
|
|
30 |
import java.io.FileOutputStream;
|
|
|
31 |
import java.io.IOException;
|
|
|
32 |
import java.text.DateFormat;
|
|
|
33 |
import java.text.DecimalFormat;
|
| 4361 |
rajveer |
34 |
import java.util.ArrayList;
|
| 2787 |
chandransh |
35 |
import java.util.Date;
|
|
|
36 |
import java.util.Enumeration;
|
|
|
37 |
import java.util.List;
|
|
|
38 |
import java.util.Locale;
|
|
|
39 |
import java.util.Properties;
|
|
|
40 |
import java.util.ResourceBundle;
|
|
|
41 |
|
|
|
42 |
import javax.servlet.ServletException;
|
|
|
43 |
import javax.servlet.ServletOutputStream;
|
|
|
44 |
import javax.servlet.http.HttpServlet;
|
|
|
45 |
import javax.servlet.http.HttpServletRequest;
|
|
|
46 |
import javax.servlet.http.HttpServletResponse;
|
|
|
47 |
|
| 7014 |
rajveer |
48 |
import org.apache.commons.lang.StringUtils;
|
| 2787 |
chandransh |
49 |
import org.apache.commons.lang.WordUtils;
|
|
|
50 |
import org.apache.thrift.TException;
|
|
|
51 |
import org.slf4j.Logger;
|
|
|
52 |
import org.slf4j.LoggerFactory;
|
| 7792 |
anupam.sin |
53 |
import org.apache.thrift.transport.TTransportException;
|
| 2787 |
chandransh |
54 |
|
|
|
55 |
import com.ibm.icu.text.RuleBasedNumberFormat;
|
|
|
56 |
|
|
|
57 |
import com.itextpdf.text.Document;
|
|
|
58 |
import com.itextpdf.text.Element;
|
|
|
59 |
import com.itextpdf.text.Font;
|
|
|
60 |
import com.itextpdf.text.FontFactory;
|
|
|
61 |
import com.itextpdf.text.FontFactoryImp;
|
|
|
62 |
import com.itextpdf.text.Image;
|
|
|
63 |
import com.itextpdf.text.Paragraph;
|
|
|
64 |
import com.itextpdf.text.Phrase;
|
|
|
65 |
import com.itextpdf.text.Rectangle;
|
|
|
66 |
import com.itextpdf.text.Font.FontFamily;
|
|
|
67 |
import com.itextpdf.text.pdf.BaseFont;
|
|
|
68 |
import com.itextpdf.text.pdf.PdfPCell;
|
|
|
69 |
import com.itextpdf.text.pdf.PdfPTable;
|
|
|
70 |
import com.itextpdf.text.pdf.PdfWriter;
|
|
|
71 |
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
|
|
|
72 |
|
|
|
73 |
@SuppressWarnings("serial")
|
|
|
74 |
public class InvoiceServlet extends HttpServlet {
|
| 7014 |
rajveer |
75 |
|
|
|
76 |
private static Logger logger = LoggerFactory.getLogger(InvoiceServlet.class);
|
|
|
77 |
|
|
|
78 |
@Override
|
|
|
79 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
80 |
long orderId = Long.parseLong(request.getParameter("id"));
|
|
|
81 |
long warehouseId = Long.parseLong(request.getParameter("warehouse"));
|
|
|
82 |
boolean withBill = false;
|
|
|
83 |
boolean printAll = false;
|
|
|
84 |
try {
|
|
|
85 |
withBill = Boolean.parseBoolean(request.getParameter("withBill"));
|
|
|
86 |
} catch(Exception e){
|
|
|
87 |
logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
|
|
|
88 |
}
|
|
|
89 |
try {
|
|
|
90 |
printAll = Boolean.parseBoolean(request.getParameter("printAll"));
|
|
|
91 |
} catch(Exception e){
|
|
|
92 |
logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
logger.info("Printing invoice for order id: " + orderId);
|
|
|
96 |
|
|
|
97 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
|
|
98 |
ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, withBill, printAll, warehouseId);
|
|
|
99 |
response.setContentType("application/pdf");
|
|
|
100 |
response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
|
|
|
101 |
|
|
|
102 |
ServletOutputStream sos;
|
|
|
103 |
try {
|
|
|
104 |
sos = response.getOutputStream();
|
|
|
105 |
baos.writeTo(sos);
|
|
|
106 |
sos.flush();
|
|
|
107 |
} catch (IOException e) {
|
|
|
108 |
logger.error("Encountered error while sending invoice response: ", e);
|
|
|
109 |
}
|
|
|
110 |
}
|
| 2787 |
chandransh |
111 |
}
|
|
|
112 |
|
|
|
113 |
class InvoiceGenerationService {
|
|
|
114 |
|
| 7014 |
rajveer |
115 |
private static Logger logger = LoggerFactory.getLogger(InvoiceGenerationService.class);
|
| 2787 |
chandransh |
116 |
|
| 7014 |
rajveer |
117 |
private TransactionClient tsc = null;
|
|
|
118 |
private InventoryClient csc = null;
|
|
|
119 |
private LogisticsClient lsc = null;
|
| 7190 |
amar.kumar |
120 |
private CatalogClient ctsc = null;
|
| 2787 |
chandransh |
121 |
|
| 7014 |
rajveer |
122 |
private static Locale indianLocale = new Locale("en", "IN");
|
|
|
123 |
private DecimalFormat amountFormat = new DecimalFormat("#,##0.00");
|
| 2787 |
chandransh |
124 |
|
| 7994 |
manish.sha |
125 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
126 |
private static final Font helvetica6 = FontFactory.getFont(FontFactory.HELVETICA, 6);
|
| 7995 |
manish.sha |
127 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
128 |
private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
|
|
129 |
private static final Font helvetica10 = FontFactory.getFont(FontFactory.HELVETICA, 10);
|
|
|
130 |
private static final Font helvetica12 = FontFactory.getFont(FontFactory.HELVETICA, 12);
|
|
|
131 |
private static final Font helvetica16 = FontFactory.getFont(FontFactory.HELVETICA, 16);
|
|
|
132 |
private static final Font helvetica28 = FontFactory.getFont(FontFactory.HELVETICA, 28);
|
| 2787 |
chandransh |
133 |
|
| 7014 |
rajveer |
134 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
|
|
135 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
|
|
136 |
|
|
|
137 |
private static final Properties properties = readProperties();
|
|
|
138 |
private static final String ourAddress = properties.getProperty("sales_tax_address",
|
|
|
139 |
"Spice Online Retail Pvt. Ltd.\nKhasra No. 819, Block-K\nMahipalpur, New Delhi-110037\n");
|
|
|
140 |
private static final String tinNo = properties.getProperty("sales_tax_tin", "07250399732");
|
|
|
141 |
|
|
|
142 |
private static final String delhiPincodePrefix = "11";
|
|
|
143 |
|
|
|
144 |
private static Properties readProperties(){
|
|
|
145 |
ResourceBundle resource = ResourceBundle.getBundle(InvoiceGenerationService.class.getName());
|
|
|
146 |
Properties props = new Properties();
|
|
|
147 |
|
|
|
148 |
Enumeration<String> keys = resource.getKeys();
|
|
|
149 |
while (keys.hasMoreElements()) {
|
|
|
150 |
String key = keys.nextElement();
|
|
|
151 |
props.put(key, resource.getString(key));
|
|
|
152 |
}
|
|
|
153 |
return props;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
public InvoiceGenerationService() {
|
|
|
157 |
try {
|
|
|
158 |
tsc = new TransactionClient();
|
|
|
159 |
csc = new InventoryClient();
|
|
|
160 |
lsc = new LogisticsClient();
|
| 7190 |
amar.kumar |
161 |
ctsc = new CatalogClient();
|
| 7014 |
rajveer |
162 |
} catch (Exception e) {
|
|
|
163 |
logger.error("Error while instantiating thrift clients.", e);
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
public ByteArrayOutputStream generateInvoice(long orderId, boolean withBill, boolean printAll, long warehouseId) {
|
|
|
168 |
ByteArrayOutputStream baosPDF = null;
|
|
|
169 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
170 |
in.shop2020.model.v1.inventory.InventoryService.Client iclient = csc.getClient();
|
|
|
171 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
try {
|
|
|
175 |
baosPDF = new ByteArrayOutputStream();
|
|
|
176 |
|
|
|
177 |
Document document = new Document();
|
|
|
178 |
PdfWriter.getInstance(document, baosPDF);
|
|
|
179 |
document.addAuthor("shop2020");
|
|
|
180 |
//document.addTitle("Invoice No: " + order.getInvoice_number());
|
|
|
181 |
document.open();
|
|
|
182 |
|
|
|
183 |
List<Order> orders = new ArrayList<Order>();
|
|
|
184 |
if(printAll){
|
|
|
185 |
try {
|
|
|
186 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
|
|
187 |
statuses.add(OrderStatus.ACCEPTED);
|
|
|
188 |
orders = tclient.getAllOrders(statuses, 0, 0, warehouseId);
|
|
|
189 |
} catch (Exception e) {
|
|
|
190 |
logger.error("Error while getting order information", e);
|
|
|
191 |
return baosPDF;
|
| 4361 |
rajveer |
192 |
}
|
| 7014 |
rajveer |
193 |
}else{
|
|
|
194 |
orders.add(tclient.getOrder(orderId));
|
|
|
195 |
}
|
|
|
196 |
boolean isFirst = true;
|
| 5387 |
rajveer |
197 |
|
| 7014 |
rajveer |
198 |
for(Order order: orders){
|
|
|
199 |
Warehouse warehouse = null;
|
|
|
200 |
Provider provider = null;
|
|
|
201 |
String destCode = null;
|
|
|
202 |
int barcodeFontSize = 0;
|
|
|
203 |
try {
|
|
|
204 |
warehouse = iclient.getWarehouse(order.getWarehouse_id());
|
|
|
205 |
long providerId = order.getLogistics_provider_id();
|
|
|
206 |
provider = logisticsClient.getProvider(providerId);
|
|
|
207 |
if(provider.getPickup().equals(PickUpType.SELF) || provider.getPickup().equals(PickUpType.RUNNER))
|
|
|
208 |
destCode = provider.getPickup().toString();
|
|
|
209 |
else
|
|
|
210 |
destCode = logisticsClient.getDestinationCode(providerId, order.getCustomer_pincode());
|
| 2787 |
chandransh |
211 |
|
| 7014 |
rajveer |
212 |
barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
|
|
|
213 |
} catch (InventoryServiceException ise) {
|
|
|
214 |
logger.error("Error while getting the warehouse information.", ise);
|
|
|
215 |
return baosPDF;
|
|
|
216 |
} catch (LogisticsServiceException lse) {
|
|
|
217 |
logger.error("Error while getting the provider information.", lse);
|
|
|
218 |
return baosPDF;
|
|
|
219 |
} catch (ConfigException ce) {
|
|
|
220 |
logger.error("Error while getting the fontsize for the given provider", ce);
|
|
|
221 |
return baosPDF;
|
|
|
222 |
} catch (TException te) {
|
|
|
223 |
logger.error("Error while getting some essential information from the services", te);
|
|
|
224 |
return baosPDF;
|
|
|
225 |
}
|
| 4361 |
rajveer |
226 |
|
| 7014 |
rajveer |
227 |
if(printAll && warehouse.getBillingType() == BillingType.OURS_EXTERNAL){
|
|
|
228 |
if(isFirst){
|
|
|
229 |
document.add(getFixedTextTable(16, "Spice Online Retail Pvt Ltd"));
|
|
|
230 |
isFirst = false;
|
|
|
231 |
}
|
|
|
232 |
document.add(getExtraInfoTable(order, provider, 16, warehouse.getBillingType()));
|
|
|
233 |
continue;
|
|
|
234 |
}
|
| 2787 |
chandransh |
235 |
|
| 7014 |
rajveer |
236 |
PdfPTable dispatchAdviceTable = getDispatchAdviceTable(order, warehouse, provider, barcodeFontSize, destCode, withBill);
|
|
|
237 |
dispatchAdviceTable.setSpacingAfter(10.0f);
|
|
|
238 |
dispatchAdviceTable.setWidthPercentage(90.0f);
|
| 5684 |
mandeep.dh |
239 |
|
| 7014 |
rajveer |
240 |
document.add(dispatchAdviceTable);
|
|
|
241 |
if(withBill){
|
|
|
242 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(order, provider);
|
|
|
243 |
taxTable.setSpacingBefore(5.0f);
|
|
|
244 |
taxTable.setWidthPercentage(90.0f);
|
|
|
245 |
document.add(new DottedLineSeparator());
|
|
|
246 |
document.add(taxTable);
|
|
|
247 |
}else{
|
|
|
248 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
|
|
249 |
extraInfoTable.setSpacingBefore(5.0f);
|
|
|
250 |
extraInfoTable.setWidthPercentage(90.0f);
|
|
|
251 |
document.add(new DottedLineSeparator());
|
|
|
252 |
document.add(extraInfoTable);
|
|
|
253 |
}
|
|
|
254 |
document.newPage();
|
|
|
255 |
}
|
|
|
256 |
document.close();
|
|
|
257 |
baosPDF.close();
|
|
|
258 |
// Adding facility to store the bill on the local directory. This will happen for only for Mahipalpur warehouse.
|
|
|
259 |
if(withBill && !printAll){
|
| 7079 |
rajveer |
260 |
String strOrderId = StringUtils.repeat("0", 10-String.valueOf(orderId).length()) + orderId;
|
| 7014 |
rajveer |
261 |
String dirPath = "/SaholicInvoices" + File.separator + strOrderId.substring(0, 2) + File.separator + strOrderId.substring(2, 4) + File.separator + strOrderId.substring(4, 6);
|
|
|
262 |
String filename = dirPath + File.separator + orderId + ".pdf";
|
|
|
263 |
File dirFile = new File(dirPath);
|
|
|
264 |
if(!dirFile.exists()){
|
|
|
265 |
dirFile.mkdirs();
|
|
|
266 |
}
|
|
|
267 |
File f = new File(filename);
|
|
|
268 |
FileOutputStream fos = new FileOutputStream(f);
|
|
|
269 |
baosPDF.writeTo(fos);
|
|
|
270 |
}
|
|
|
271 |
} catch (Exception e) {
|
|
|
272 |
logger.error("Error while generating Invoice: ", e);
|
|
|
273 |
}
|
|
|
274 |
return baosPDF;
|
|
|
275 |
}
|
| 3065 |
chandransh |
276 |
|
| 7014 |
rajveer |
277 |
private PdfPTable getDispatchAdviceTable(Order order, Warehouse warehouse, Provider provider, float barcodeFontSize, String destCode, boolean withBill){
|
|
|
278 |
Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
|
| 2787 |
chandransh |
279 |
|
| 7014 |
rajveer |
280 |
PdfPTable table = new PdfPTable(1);
|
|
|
281 |
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 2787 |
chandransh |
282 |
|
| 7014 |
rajveer |
283 |
PdfPTable logoTable = new PdfPTable(2);
|
| 7318 |
rajveer |
284 |
addLogoTable(logoTable, order);
|
|
|
285 |
|
| 7014 |
rajveer |
286 |
PdfPCell titleCell = getTitleCell();
|
|
|
287 |
PdfPTable customerTable = getCustomerAddressTable(order, destCode, false, helvetica12, false);
|
|
|
288 |
PdfPTable providerInfoTable = getProviderTable(order, provider, barCodeFont);
|
| 2787 |
chandransh |
289 |
|
| 7014 |
rajveer |
290 |
PdfPTable dispatchTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
|
|
291 |
dispatchTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
292 |
dispatchTable.addCell(customerTable);
|
|
|
293 |
dispatchTable.addCell(new Phrase(" "));
|
|
|
294 |
dispatchTable.addCell(providerInfoTable);
|
| 2787 |
chandransh |
295 |
|
| 7014 |
rajveer |
296 |
Warehouse shippingLocation = CatalogUtils.getWarehouse(warehouse.getShippingWarehouseId());
|
|
|
297 |
PdfPTable invoiceTable = getTopInvoiceTable(order, shippingLocation.getTinNumber());
|
|
|
298 |
PdfPCell addressCell = getAddressCell(shippingLocation.getLocation() +
|
|
|
299 |
"\nPIN " + warehouse.getPincode() + "\n\n");
|
| 2787 |
chandransh |
300 |
|
| 7014 |
rajveer |
301 |
PdfPTable chargesTable = new PdfPTable(1);
|
|
|
302 |
chargesTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
303 |
chargesTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
304 |
if(order.isLogisticsCod()){
|
| 7318 |
rajveer |
305 |
chargesTable.addCell(new Phrase("AMOUNT TO BE COLLECTED : Rs " + (order.getTotal_amount()-order.getGvAmount()-order.getAdvanceAmount()), helveticaBold12));
|
| 7014 |
rajveer |
306 |
chargesTable.addCell(new Phrase("RTO ADDRESS:DEL/HPW/111116"));
|
| 7994 |
manish.sha |
307 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
308 |
if(order.getLogistics_provider_id()==7L){
|
|
|
309 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
310 |
String fedexCodReturnBarcode = "";
|
|
|
311 |
try {
|
|
|
312 |
fedexCodReturnBarcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_COD_Return_BarCode");
|
|
|
313 |
} catch (TException e1) {
|
|
|
314 |
logger.error("Error while getting the provider information.", e1);
|
|
|
315 |
}
|
|
|
316 |
PdfPCell formIdCell= new PdfPCell(new Paragraph("COD Return Form id-0325", helvetica6));
|
|
|
317 |
formIdCell.setPaddingTop(5.0f);
|
|
|
318 |
formIdCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
319 |
formIdCell.setBorder(Rectangle.NO_BORDER);
|
|
|
320 |
PdfPCell awbNumberCell= new PdfPCell(new Paragraph("*" + fedexCodReturnBarcode + "*", barCodeFont));
|
|
|
321 |
awbNumberCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
322 |
awbNumberCell.setBorder(Rectangle.NO_BORDER);
|
|
|
323 |
chargesTable.addCell(new Phrase("PRIORITY OVERNIGHT ", helvetica8));
|
|
|
324 |
chargesTable.addCell(formIdCell);
|
|
|
325 |
chargesTable.addCell(awbNumberCell);
|
|
|
326 |
}
|
|
|
327 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
328 |
} else {
|
|
|
329 |
chargesTable.addCell(new Phrase("Do not pay any extra charges to the Courier."));
|
|
|
330 |
}
|
| 2787 |
chandransh |
331 |
|
| 7014 |
rajveer |
332 |
PdfPTable addressAndNoteTable = new PdfPTable(new float[]{0.3f, 0.7f});
|
|
|
333 |
addressAndNoteTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
334 |
addressAndNoteTable.addCell(addressCell);
|
|
|
335 |
addressAndNoteTable.addCell(chargesTable);
|
| 2787 |
chandransh |
336 |
|
| 7014 |
rajveer |
337 |
table.addCell(logoTable);
|
|
|
338 |
table.addCell(titleCell);
|
|
|
339 |
table.addCell(dispatchTable);
|
|
|
340 |
table.addCell(invoiceTable);
|
|
|
341 |
table.addCell(new Phrase("If undelivered, return to:", helvetica10));
|
|
|
342 |
table.addCell(addressAndNoteTable);
|
|
|
343 |
return table;
|
|
|
344 |
}
|
| 2787 |
chandransh |
345 |
|
| 7318 |
rajveer |
346 |
private void addLogoTable(PdfPTable logoTable, Order order) {
|
|
|
347 |
logoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
348 |
logoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
349 |
logoTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM);
|
|
|
350 |
|
|
|
351 |
PdfPCell logoCell;
|
|
|
352 |
String logoPath;
|
|
|
353 |
|
| 7556 |
rajveer |
354 |
if(order.getSource() == OrderSource.STORE.getValue()){
|
|
|
355 |
logoCell = new PdfPCell(new Phrase(""));
|
|
|
356 |
|
|
|
357 |
logoCell.setBorder(Rectangle.NO_BORDER);
|
|
|
358 |
logoCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
359 |
|
|
|
360 |
logoTable.addCell(logoCell);
|
|
|
361 |
}else{
|
| 7318 |
rajveer |
362 |
logoPath = InvoiceGenerationService.class.getResource("/logo.jpg").getPath();
|
|
|
363 |
|
|
|
364 |
try {
|
|
|
365 |
logoCell = new PdfPCell(Image.getInstance(logoPath), false);
|
|
|
366 |
} catch (Exception e) {
|
|
|
367 |
//Too Many exceptions to catch here: BadElementException, MalformedURLException and IOException
|
|
|
368 |
logger.warn("Couldn't load the Saholic logo: ", e);
|
|
|
369 |
logoCell = new PdfPCell(new Phrase("Saholic Logo"));
|
|
|
370 |
}
|
|
|
371 |
logoCell.setBorder(Rectangle.NO_BORDER);
|
|
|
372 |
logoCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
373 |
|
|
|
374 |
logoTable.addCell(logoCell);
|
|
|
375 |
|
|
|
376 |
}
|
|
|
377 |
}
|
|
|
378 |
|
| 7014 |
rajveer |
379 |
private Font getBarCodeFont(Provider provider, float barcodeFontSize) {
|
|
|
380 |
String fontPath = InvoiceGenerationService.class.getResource("/" + provider.getName().toLowerCase() + "/barcode.TTF").getPath();
|
|
|
381 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
382 |
ttfFontFactory.register(fontPath, "barcode");
|
|
|
383 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
|
|
384 |
return barCodeFont;
|
|
|
385 |
}
|
| 2787 |
chandransh |
386 |
|
| 7014 |
rajveer |
387 |
private PdfPCell getTitleCell() {
|
|
|
388 |
PdfPCell titleCell = new PdfPCell(new Phrase("Dispatch Advice", helveticaBold12));
|
|
|
389 |
titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
390 |
titleCell.setBorder(Rectangle.NO_BORDER);
|
|
|
391 |
return titleCell;
|
|
|
392 |
}
|
| 2787 |
chandransh |
393 |
|
| 7014 |
rajveer |
394 |
private PdfPTable getProviderTable(Order order, Provider provider, Font barCodeFont) {
|
|
|
395 |
PdfPTable providerInfoTable = new PdfPTable(1);
|
|
|
396 |
providerInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 7318 |
rajveer |
397 |
if(order.isLogisticsCod()){
|
|
|
398 |
PdfPCell deliveryTypeCell = new PdfPCell(new Phrase("COD ", helvetica28));
|
|
|
399 |
deliveryTypeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
400 |
deliveryTypeCell.setBorder(Rectangle.NO_BORDER);
|
|
|
401 |
providerInfoTable.addCell(deliveryTypeCell);
|
|
|
402 |
}
|
| 7994 |
manish.sha |
403 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
404 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
405 |
String fedexPackageBarcode = "";
|
|
|
406 |
try {
|
|
|
407 |
fedexPackageBarcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_Package_BarCode");
|
|
|
408 |
} catch (TException e1) {
|
|
|
409 |
logger.error("Error while getting the provider information.", e1);
|
|
|
410 |
}
|
|
|
411 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7318 |
rajveer |
412 |
|
|
|
413 |
|
|
|
414 |
|
| 7014 |
rajveer |
415 |
PdfPCell providerNameCell = new PdfPCell(new Phrase(provider.getName(), helveticaBold12));
|
|
|
416 |
providerNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
417 |
providerNameCell.setBorder(Rectangle.NO_BORDER);
|
| 7994 |
manish.sha |
418 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
419 |
PdfPCell formIdCell= null;
|
|
|
420 |
if(order.getLogistics_provider_id()==7L){
|
|
|
421 |
if(order.isCod()){
|
|
|
422 |
formIdCell = new PdfPCell(new Paragraph("Form id-0305", helvetica6));
|
|
|
423 |
}
|
|
|
424 |
else{
|
|
|
425 |
formIdCell = new PdfPCell(new Paragraph("Form id-0467", helvetica6));
|
|
|
426 |
}
|
|
|
427 |
}
|
|
|
428 |
formIdCell.setPaddingTop(20.0f);
|
|
|
429 |
formIdCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
430 |
formIdCell.setBorder(Rectangle.NO_BORDER);
|
|
|
431 |
|
|
|
432 |
PdfPCell awbNumberCell= null;
|
|
|
433 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
434 |
awbNumberCell = new PdfPCell(new Paragraph("*" + order.getAirwaybill_no() + "*", barCodeFont));
|
|
|
435 |
}
|
|
|
436 |
else{
|
|
|
437 |
awbNumberCell = new PdfPCell(new Paragraph("*" + fedexPackageBarcode + "*", barCodeFont));
|
|
|
438 |
}
|
| 8010 |
manish.sha |
439 |
awbNumberCell.setPaddingBottom(5.0f);
|
| 7014 |
rajveer |
440 |
awbNumberCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
441 |
awbNumberCell.setBorder(Rectangle.NO_BORDER);
|
|
|
442 |
|
|
|
443 |
providerInfoTable.addCell(providerNameCell);
|
| 7994 |
manish.sha |
444 |
providerInfoTable.addCell(formIdCell);
|
|
|
445 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
446 |
providerInfoTable.addCell(awbNumberCell);
|
| 7792 |
anupam.sin |
447 |
|
|
|
448 |
Warehouse warehouse = null;
|
|
|
449 |
try{
|
|
|
450 |
InventoryClient isc = new InventoryClient();
|
| 7804 |
amar.kumar |
451 |
warehouse = isc.getClient().getWarehouse(order.getWarehouse_id());
|
| 7803 |
amar.kumar |
452 |
} catch(Exception e) {
|
| 7792 |
anupam.sin |
453 |
logger.error("Unable to get warehouse for id : " + order.getWarehouse_id(), e);
|
| 7805 |
amar.kumar |
454 |
//TODO throw e;
|
| 7792 |
anupam.sin |
455 |
}
|
|
|
456 |
String accountNo = "";
|
|
|
457 |
DeliveryType dt = DeliveryType.PREPAID;
|
|
|
458 |
if (order.isLogisticsCod()) {
|
|
|
459 |
dt = DeliveryType.COD;
|
|
|
460 |
}
|
| 7994 |
manish.sha |
461 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
462 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
463 |
for (ProviderDetails detail : provider.getDetails()) {
|
|
|
464 |
if(in.shop2020.model.v1.inventory.WarehouseLocation.findByValue((int) detail.getLogisticLocation()) == warehouse.getLogisticsLocation() && detail.getDeliveryType() == dt) {
|
|
|
465 |
providerInfoTable.addCell(new Phrase("Account No : " + detail.getAccountNo(), helvetica8));
|
|
|
466 |
}
|
|
|
467 |
}
|
| 7792 |
anupam.sin |
468 |
}
|
| 7994 |
manish.sha |
469 |
else{
|
|
|
470 |
providerInfoTable.addCell(new Phrase("STANDARD OVERNIGHT ", helvetica8));
|
|
|
471 |
}
|
|
|
472 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
473 |
Date awbDate;
|
|
|
474 |
if(order.getBilling_timestamp() == 0){
|
|
|
475 |
awbDate = new Date();
|
|
|
476 |
}else{
|
|
|
477 |
awbDate = new Date(order.getBilling_timestamp());
|
|
|
478 |
}
|
|
|
479 |
providerInfoTable.addCell(new Phrase("AWB Date : " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(awbDate), helvetica8));
|
|
|
480 |
providerInfoTable.addCell(new Phrase("Weight : " + order.getTotal_weight() + " Kg", helvetica8));
|
| 7994 |
manish.sha |
481 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
482 |
if(order.getLogistics_provider_id()==7L){
|
|
|
483 |
providerInfoTable.addCell(new Phrase("Bill T/C Sender "+ "Bill D/T Sender", helvetica8));
|
|
|
484 |
}
|
|
|
485 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
486 |
return providerInfoTable;
|
|
|
487 |
}
|
|
|
488 |
|
|
|
489 |
private PdfPTable getTopInvoiceTable(Order order, String tinNo){
|
|
|
490 |
PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.2f, 0.3f, 0.1f, 0.1f, 0.1f});
|
|
|
491 |
invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
492 |
|
|
|
493 |
invoiceTable.addCell(getInvoiceTableHeader(6));
|
|
|
494 |
|
|
|
495 |
invoiceTable.addCell(new Phrase("Order No", helvetica8));
|
|
|
496 |
invoiceTable.addCell(new Phrase("Paymode", helvetica8));
|
|
|
497 |
invoiceTable.addCell(new Phrase("Product Name", helvetica8));
|
|
|
498 |
invoiceTable.addCell(new Phrase("Quantity", helvetica8));
|
|
|
499 |
invoiceTable.addCell(new Phrase("Rate", helvetica8));
|
|
|
500 |
invoiceTable.addCell(new Phrase("Amount", helvetica8));
|
|
|
501 |
populateTopInvoiceTable(order, invoiceTable);
|
|
|
502 |
|
|
|
503 |
|
|
|
504 |
if(order.getInsurer() > 0) {
|
|
|
505 |
invoiceTable.addCell(getInsuranceCell(4));
|
|
|
506 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
|
|
507 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
|
|
508 |
}
|
|
|
509 |
|
| 7318 |
rajveer |
510 |
if(order.getSource() == OrderSource.STORE.getValue()) {
|
|
|
511 |
invoiceTable.addCell(getAdvanceAmountCell(4));
|
|
|
512 |
invoiceTable.addCell(getPriceCell(order.getAdvanceAmount()));
|
|
|
513 |
invoiceTable.addCell(getPriceCell(order.getAdvanceAmount()));
|
|
|
514 |
}
|
|
|
515 |
|
| 7014 |
rajveer |
516 |
invoiceTable.addCell(getTotalCell(4));
|
|
|
517 |
invoiceTable.addCell(getRupeesCell());
|
| 7318 |
rajveer |
518 |
invoiceTable.addCell(getTotalAmountCell(order.getTotal_amount()-order.getGvAmount()-order.getAdvanceAmount()));
|
| 7014 |
rajveer |
519 |
|
|
|
520 |
PdfPCell tinCell = new PdfPCell(new Phrase("TIN NO. " + tinNo, helvetica8));
|
|
|
521 |
tinCell.setColspan(6);
|
|
|
522 |
tinCell.setPadding(2);
|
|
|
523 |
invoiceTable.addCell(tinCell);
|
|
|
524 |
|
|
|
525 |
return invoiceTable;
|
|
|
526 |
}
|
|
|
527 |
|
|
|
528 |
private void populateTopInvoiceTable(Order order, PdfPTable invoiceTable) {
|
|
|
529 |
List<LineItem> lineitems = order.getLineitems();
|
|
|
530 |
for (LineItem lineitem : lineitems) {
|
|
|
531 |
invoiceTable.addCell(new Phrase(order.getId() + "", helvetica8));
|
|
|
532 |
if(order.getPickupStoreId() > 0 && order.isCod() == true)
|
|
|
533 |
invoiceTable.addCell(new Phrase("In-Store", helvetica8));
|
|
|
534 |
else if (order.isCod())
|
|
|
535 |
invoiceTable.addCell(new Phrase("COD", helvetica8));
|
|
|
536 |
else
|
|
|
537 |
invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
|
| 7318 |
rajveer |
538 |
|
| 7190 |
amar.kumar |
539 |
invoiceTable.addCell(getProductNameCell(lineitem, false, order.getFreebieItemId()));
|
| 2787 |
chandransh |
540 |
|
| 7014 |
rajveer |
541 |
invoiceTable.addCell(new Phrase(lineitem.getQuantity() + "", helvetica8));
|
| 2787 |
chandransh |
542 |
|
| 7014 |
rajveer |
543 |
invoiceTable.addCell(getPriceCell(lineitem.getUnit_price()-order.getGvAmount()));
|
|
|
544 |
|
|
|
545 |
invoiceTable.addCell(getPriceCell(lineitem.getTotal_price()-order.getGvAmount()));
|
|
|
546 |
}
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
private PdfPCell getAddressCell(String address) {
|
|
|
550 |
Paragraph addressParagraph = new Paragraph(address, new Font(FontFamily.TIMES_ROMAN, 8f));
|
|
|
551 |
PdfPCell addressCell = new PdfPCell();
|
|
|
552 |
addressCell.addElement(addressParagraph);
|
|
|
553 |
addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
554 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
|
|
555 |
return addressCell;
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
private PdfPTable getTaxCumRetailInvoiceTable(Order order, Provider provider){
|
|
|
559 |
PdfPTable taxTable = new PdfPTable(1);
|
|
|
560 |
Phrase phrase = null;
|
|
|
561 |
taxTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
562 |
taxTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
563 |
|
| 7318 |
rajveer |
564 |
// PdfPTable logoTable = new PdfPTable(2);
|
|
|
565 |
// addLogoTable(logoTable, order);
|
|
|
566 |
|
| 7014 |
rajveer |
567 |
if (order.getOrderType().equals(OrderType.B2B)) {
|
|
|
568 |
phrase = new Phrase("TAX INVOICE", helveticaBold12);
|
|
|
569 |
} else {
|
|
|
570 |
phrase = new Phrase("RETAIL INVOICE", helveticaBold12);
|
|
|
571 |
}
|
|
|
572 |
PdfPCell retailInvoiceTitleCell = new PdfPCell(phrase);
|
|
|
573 |
retailInvoiceTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
574 |
retailInvoiceTitleCell.setBorder(Rectangle.NO_BORDER);
|
|
|
575 |
|
|
|
576 |
Paragraph sorlAddress = new Paragraph(ourAddress + "TIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f, Element.ALIGN_CENTER));
|
|
|
577 |
PdfPCell sorlAddressCell = new PdfPCell(sorlAddress);
|
|
|
578 |
sorlAddressCell.addElement(sorlAddress);
|
|
|
579 |
sorlAddressCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
580 |
|
|
|
581 |
PdfPTable customerAddress = getCustomerAddressTable(order, null, true, helvetica8, true);
|
|
|
582 |
PdfPTable orderDetails = getOrderDetails(order, provider);
|
|
|
583 |
|
|
|
584 |
PdfPTable addrAndOrderDetailsTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
|
|
585 |
addrAndOrderDetailsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
586 |
addrAndOrderDetailsTable.addCell(customerAddress);
|
|
|
587 |
addrAndOrderDetailsTable.addCell(new Phrase(" "));
|
|
|
588 |
addrAndOrderDetailsTable.addCell(orderDetails);
|
|
|
589 |
|
|
|
590 |
boolean isVAT = order.getCustomer_pincode().startsWith(delhiPincodePrefix);
|
|
|
591 |
PdfPTable invoiceTable = getBottomInvoiceTable(order, isVAT);
|
|
|
592 |
|
|
|
593 |
PdfPCell disclaimerCell = new PdfPCell(new Phrase("Goods once sold will not be taken back.\nAll disputes subject to Delhi Jurisdiction.\nThis is a Computer generated Invoice.", helvetica8));
|
|
|
594 |
disclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
595 |
disclaimerCell.setBorder(Rectangle.NO_BORDER);
|
| 7318 |
rajveer |
596 |
|
|
|
597 |
//taxTable.addCell(logoTable);
|
| 7014 |
rajveer |
598 |
taxTable.addCell(retailInvoiceTitleCell);
|
|
|
599 |
taxTable.addCell(sorlAddress);
|
|
|
600 |
taxTable.addCell(addrAndOrderDetailsTable);
|
|
|
601 |
taxTable.addCell(invoiceTable);
|
|
|
602 |
taxTable.addCell(disclaimerCell);
|
|
|
603 |
|
|
|
604 |
return taxTable;
|
|
|
605 |
}
|
|
|
606 |
|
|
|
607 |
private PdfPTable getCustomerAddressTable(Order order, String destCode, boolean showPaymentMode, Font font, boolean forInvoce){
|
|
|
608 |
PdfPTable customerTable = new PdfPTable(1);
|
|
|
609 |
customerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
610 |
if(forInvoce || order.getPickupStoreId() == 0){
|
|
|
611 |
customerTable.addCell(new Phrase(order.getCustomer_name(), font));
|
|
|
612 |
customerTable.addCell(new Phrase(order.getCustomer_address1(), font));
|
|
|
613 |
customerTable.addCell(new Phrase(order.getCustomer_address2(), font));
|
|
|
614 |
customerTable.addCell(new Phrase(order.getCustomer_city() + "," + order.getCustomer_state(), font));
|
| 7994 |
manish.sha |
615 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
616 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
617 |
if(destCode != null)
|
|
|
618 |
customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + destCode, helvetica16));
|
|
|
619 |
else
|
|
|
620 |
customerTable.addCell(new Phrase(order.getCustomer_pincode(), font));
|
|
|
621 |
}
|
|
|
622 |
else{
|
|
|
623 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
624 |
String fedexLocationcode = "";
|
|
|
625 |
try {
|
|
|
626 |
fedexLocationcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_Location_Code");
|
|
|
627 |
} catch (TException e1) {
|
|
|
628 |
logger.error("Error while getting the provider information.", e1);
|
|
|
629 |
}
|
|
|
630 |
customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + fedexLocationcode, helvetica16));
|
|
|
631 |
}
|
|
|
632 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
633 |
customerTable.addCell(new Phrase("Phone :" + order.getCustomer_mobilenumber(), font));
|
|
|
634 |
}else{
|
|
|
635 |
try {
|
| 5556 |
rajveer |
636 |
in.shop2020.logistics.LogisticsService.Client lclient = (new LogisticsClient()).getClient();
|
| 7014 |
rajveer |
637 |
PickupStore store = lclient.getPickupStore(order.getPickupStoreId());
|
|
|
638 |
customerTable.addCell(new Phrase(order.getCustomer_name() + " \nc/o " + store.getName(), font));
|
|
|
639 |
customerTable.addCell(new Phrase(store.getLine1(), font));
|
|
|
640 |
customerTable.addCell(new Phrase(store.getLine2(), font));
|
|
|
641 |
customerTable.addCell(new Phrase(store.getCity() + "," + store.getState(), font));
|
|
|
642 |
if(destCode != null)
|
|
|
643 |
customerTable.addCell(new Phrase(store.getPin() + " - " + destCode, helvetica16));
|
|
|
644 |
else
|
|
|
645 |
customerTable.addCell(new Phrase(store.getPin(), font));
|
|
|
646 |
customerTable.addCell(new Phrase("Phone :" + store.getPhone(), font));
|
| 5556 |
rajveer |
647 |
} catch (TException e) {
|
|
|
648 |
// TODO Auto-generated catch block
|
|
|
649 |
e.printStackTrace();
|
|
|
650 |
}
|
| 5527 |
anupam.sin |
651 |
|
| 7014 |
rajveer |
652 |
}
|
|
|
653 |
|
|
|
654 |
if(order.getOrderType().equals(OrderType.B2B)) {
|
|
|
655 |
String tin = null;
|
|
|
656 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
657 |
List<Attribute> attributes;
|
|
|
658 |
try {
|
|
|
659 |
attributes = tclient.getAllAttributesForOrderId(order.getId());
|
|
|
660 |
|
|
|
661 |
for(Attribute attribute : attributes) {
|
|
|
662 |
if(attribute.getName().equals("tinNumber")) {
|
|
|
663 |
tin = attribute.getValue();
|
|
|
664 |
}
|
|
|
665 |
}
|
|
|
666 |
if (tin != null) {
|
|
|
667 |
customerTable.addCell(new Phrase("TIN :" + tin, font));
|
|
|
668 |
}
|
|
|
669 |
|
|
|
670 |
} catch (Exception e) {
|
|
|
671 |
logger.error("Error while getting order attributes", e);
|
|
|
672 |
}
|
|
|
673 |
}
|
|
|
674 |
/*
|
| 2787 |
chandransh |
675 |
if(showPaymentMode){
|
|
|
676 |
customerTable.addCell(new Phrase(" ", font));
|
|
|
677 |
customerTable.addCell(new Phrase("Payment Mode: Prepaid", font));
|
| 5856 |
anupam.sin |
678 |
}*/
|
| 7014 |
rajveer |
679 |
return customerTable;
|
|
|
680 |
}
|
| 2787 |
chandransh |
681 |
|
| 7014 |
rajveer |
682 |
private PdfPTable getOrderDetails(Order order, Provider provider){
|
|
|
683 |
PdfPTable orderTable = new PdfPTable(new float[]{0.4f, 0.6f});
|
|
|
684 |
orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 2787 |
chandransh |
685 |
|
| 7014 |
rajveer |
686 |
orderTable.addCell(new Phrase("Invoice No:", helvetica8));
|
|
|
687 |
orderTable.addCell(new Phrase(order.getInvoice_number(), helvetica8));
|
| 2787 |
chandransh |
688 |
|
| 7014 |
rajveer |
689 |
orderTable.addCell(new Phrase("Date:", helvetica8));
|
|
|
690 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
|
| 2787 |
chandransh |
691 |
|
| 7014 |
rajveer |
692 |
orderTable.addCell(new Phrase("Order ID:", helvetica8));
|
|
|
693 |
orderTable.addCell(new Phrase("" + order.getId(), helvetica8));
|
| 2787 |
chandransh |
694 |
|
| 7528 |
rajveer |
695 |
if(order.getSource() == OrderSource.AMAZON.getValue()){
|
|
|
696 |
AmazonOrder aorder = null;
|
|
|
697 |
try {
|
|
|
698 |
aorder = tsc.getClient().getAmazonOrder(order.getId());
|
|
|
699 |
} catch (TException e) {
|
|
|
700 |
logger.error("Error while getting amazon order", e);
|
|
|
701 |
}
|
|
|
702 |
orderTable.addCell(new Phrase("Amazon Order ID:", helvetica8));
|
|
|
703 |
orderTable.addCell(new Phrase(aorder.getAmazonOrderCode(), helvetica8));
|
|
|
704 |
}
|
|
|
705 |
|
| 7014 |
rajveer |
706 |
orderTable.addCell(new Phrase("Order Date:", helvetica8));
|
|
|
707 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getCreated_timestamp())), helvetica8));
|
| 2787 |
chandransh |
708 |
|
| 7014 |
rajveer |
709 |
orderTable.addCell(new Phrase("Courier:", helvetica8));
|
|
|
710 |
orderTable.addCell(new Phrase(provider.getName(), helvetica8));
|
| 2787 |
chandransh |
711 |
|
| 7014 |
rajveer |
712 |
orderTable.addCell(new Phrase("AWB No:", helvetica8));
|
|
|
713 |
orderTable.addCell(new Phrase(order.getAirwaybill_no(), helvetica8));
|
| 2787 |
chandransh |
714 |
|
| 7014 |
rajveer |
715 |
orderTable.addCell(new Phrase("AWB Date:", helvetica8));
|
|
|
716 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
|
| 2787 |
chandransh |
717 |
|
| 7014 |
rajveer |
718 |
return orderTable;
|
|
|
719 |
}
|
| 2787 |
chandransh |
720 |
|
| 7014 |
rajveer |
721 |
private PdfPTable getBottomInvoiceTable(Order order, boolean isVAT){
|
|
|
722 |
PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.5f, 0.1f, 0.1f, 0.1f});
|
|
|
723 |
invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 2787 |
chandransh |
724 |
|
| 7014 |
rajveer |
725 |
invoiceTable.addCell(getInvoiceTableHeader(5));
|
| 4262 |
rajveer |
726 |
|
| 7014 |
rajveer |
727 |
invoiceTable.addCell(new Phrase("Sl. No.", helveticaBold8));
|
|
|
728 |
invoiceTable.addCell(new Phrase("Description", helveticaBold8));
|
|
|
729 |
invoiceTable.addCell(new Phrase("Quantity", helveticaBold8));
|
|
|
730 |
invoiceTable.addCell(new Phrase("Rate (Rs)", helveticaBold8));
|
|
|
731 |
invoiceTable.addCell(new Phrase("Amount (Rs)", helveticaBold8));
|
|
|
732 |
LineItem lineItem = order.getLineitems().get(0);
|
|
|
733 |
double orderAmount = order.getTotal_amount();
|
|
|
734 |
double rate = lineItem.getVatRate();
|
| 7057 |
amar.kumar |
735 |
double salesTax = (rate * (orderAmount - order.getInsuranceAmount()))/(100 + rate);
|
| 6750 |
rajveer |
736 |
|
| 7014 |
rajveer |
737 |
populateBottomInvoiceTable(order, invoiceTable, rate);
|
| 6750 |
rajveer |
738 |
|
| 7014 |
rajveer |
739 |
PdfPCell salesTaxCell = getPriceCell(salesTax);
|
|
|
740 |
|
|
|
741 |
invoiceTable.addCell(getVATLabelCell(isVAT));
|
|
|
742 |
invoiceTable.addCell(new Phrase(rate + "%", helvetica8));
|
|
|
743 |
invoiceTable.addCell(salesTaxCell);
|
|
|
744 |
|
|
|
745 |
if(order.getInsurer() > 0) {
|
|
|
746 |
invoiceTable.addCell(getInsuranceCell(3));
|
|
|
747 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
|
|
748 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
|
|
749 |
}
|
|
|
750 |
|
|
|
751 |
invoiceTable.addCell(getEmptyCell(5));
|
|
|
752 |
|
|
|
753 |
invoiceTable.addCell(getTotalCell(3));
|
|
|
754 |
invoiceTable.addCell(getRupeesCell());
|
|
|
755 |
invoiceTable.addCell(getTotalAmountCell(orderAmount));
|
|
|
756 |
|
|
|
757 |
invoiceTable.addCell(new Phrase("Amount in Words:", helvetica8));
|
|
|
758 |
invoiceTable.addCell(getAmountInWordsCell(orderAmount));
|
|
|
759 |
|
|
|
760 |
invoiceTable.addCell(getEOECell(5));
|
|
|
761 |
|
|
|
762 |
return invoiceTable;
|
|
|
763 |
}
|
|
|
764 |
|
|
|
765 |
private PdfPCell getInvoiceTableHeader(int colspan) {
|
|
|
766 |
PdfPCell invoiceTableHeader = new PdfPCell(new Phrase("Order Details:", helveticaBold12));
|
|
|
767 |
invoiceTableHeader.setBorder(Rectangle.NO_BORDER);
|
|
|
768 |
invoiceTableHeader.setColspan(colspan);
|
|
|
769 |
invoiceTableHeader.setPaddingTop(10);
|
|
|
770 |
return invoiceTableHeader;
|
|
|
771 |
}
|
|
|
772 |
|
|
|
773 |
private void populateBottomInvoiceTable(Order order, PdfPTable invoiceTable, double rate) {
|
|
|
774 |
for (LineItem lineitem : order.getLineitems()) {
|
|
|
775 |
invoiceTable.addCell(new Phrase("" + order.getId() , helvetica8));
|
|
|
776 |
|
| 7190 |
amar.kumar |
777 |
invoiceTable.addCell(getProductNameCell(lineitem, true, order.getFreebieItemId()));
|
| 7014 |
rajveer |
778 |
|
|
|
779 |
invoiceTable.addCell(new Phrase("" + lineitem.getQuantity(), helvetica8));
|
|
|
780 |
|
|
|
781 |
double itemPrice = lineitem.getUnit_price();
|
|
|
782 |
double showPrice = (100 * itemPrice)/(100 + rate);
|
|
|
783 |
invoiceTable.addCell(getPriceCell(showPrice)); //Unit Price Cell
|
|
|
784 |
|
|
|
785 |
double totalPrice = lineitem.getTotal_price();
|
|
|
786 |
showPrice = (100 * totalPrice)/(100 + rate);
|
|
|
787 |
invoiceTable.addCell(getPriceCell(showPrice)); //Total Price Cell
|
|
|
788 |
}
|
|
|
789 |
}
|
|
|
790 |
|
| 7190 |
amar.kumar |
791 |
private PdfPCell getProductNameCell(LineItem lineitem, boolean appendIMEI, Long freebieItemId) {
|
| 7014 |
rajveer |
792 |
String itemName = getItemDisplayName(lineitem, appendIMEI);
|
| 7190 |
amar.kumar |
793 |
if(freebieItemId!=null && freebieItemId!=0){
|
|
|
794 |
try {
|
|
|
795 |
CatalogService.Client catalogClient = ctsc.getClient();
|
|
|
796 |
Item item = catalogClient.getItem(freebieItemId);
|
|
|
797 |
itemName = itemName + "\n(Free Item: " + item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + ")";
|
|
|
798 |
} catch(Exception tex) {
|
|
|
799 |
logger.error("Not able to get Freebie Item Details for ItemId:" + freebieItemId, tex);
|
|
|
800 |
}
|
|
|
801 |
}
|
| 7014 |
rajveer |
802 |
PdfPCell productNameCell = new PdfPCell(new Phrase(itemName, helvetica8));
|
|
|
803 |
productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
804 |
return productNameCell;
|
|
|
805 |
}
|
|
|
806 |
|
|
|
807 |
private PdfPCell getPriceCell(double price) {
|
|
|
808 |
PdfPCell totalPriceCell = new PdfPCell(new Phrase(amountFormat.format(price), helvetica8));
|
|
|
809 |
totalPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
810 |
return totalPriceCell;
|
|
|
811 |
}
|
|
|
812 |
|
|
|
813 |
private PdfPCell getVATLabelCell(boolean isVAT) {
|
|
|
814 |
PdfPCell vatCell = null;
|
|
|
815 |
if(isVAT){
|
|
|
816 |
vatCell = new PdfPCell(new Phrase("VAT", helveticaBold8));
|
|
|
817 |
} else {
|
|
|
818 |
vatCell = new PdfPCell(new Phrase("CST", helveticaBold8));
|
|
|
819 |
}
|
|
|
820 |
vatCell.setColspan(3);
|
|
|
821 |
vatCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
822 |
return vatCell;
|
|
|
823 |
}
|
|
|
824 |
|
| 7318 |
rajveer |
825 |
private PdfPCell getAdvanceAmountCell(int colspan) {
|
|
|
826 |
PdfPCell insuranceCell = null;
|
|
|
827 |
insuranceCell = new PdfPCell(new Phrase("Advance Amount Received", helvetica8));
|
|
|
828 |
insuranceCell.setColspan(colspan);
|
|
|
829 |
insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
830 |
return insuranceCell;
|
|
|
831 |
}
|
|
|
832 |
|
| 7014 |
rajveer |
833 |
private PdfPCell getInsuranceCell(int colspan) {
|
|
|
834 |
PdfPCell insuranceCell = null;
|
|
|
835 |
insuranceCell = new PdfPCell(new Phrase("1 Year WorldWide Theft Insurance", helvetica8));
|
|
|
836 |
insuranceCell.setColspan(colspan);
|
|
|
837 |
insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
838 |
return insuranceCell;
|
|
|
839 |
}
|
|
|
840 |
|
|
|
841 |
private PdfPCell getEmptyCell(int colspan) {
|
|
|
842 |
PdfPCell emptyCell = new PdfPCell(new Phrase(" ", helvetica8));
|
|
|
843 |
emptyCell.setColspan(colspan);
|
|
|
844 |
return emptyCell;
|
|
|
845 |
}
|
|
|
846 |
|
|
|
847 |
private PdfPCell getTotalCell(int colspan) {
|
|
|
848 |
PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
|
|
|
849 |
totalCell.setColspan(colspan);
|
|
|
850 |
totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
851 |
return totalCell;
|
|
|
852 |
}
|
|
|
853 |
|
|
|
854 |
private PdfPCell getRupeesCell() {
|
|
|
855 |
PdfPCell rupeesCell = new PdfPCell(new Phrase("Rs.", helveticaBold8));
|
|
|
856 |
rupeesCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
857 |
return rupeesCell;
|
|
|
858 |
}
|
|
|
859 |
|
|
|
860 |
private PdfPCell getTotalAmountCell(double orderAmount) {
|
|
|
861 |
PdfPCell totalAmountCell = new PdfPCell(new Phrase(amountFormat.format(orderAmount), helveticaBold8));
|
|
|
862 |
totalAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
863 |
return totalAmountCell;
|
|
|
864 |
}
|
|
|
865 |
|
|
|
866 |
/**
|
|
|
867 |
* This method uses ICU4J libraries to convert the given amount into words
|
|
|
868 |
* of Indian locale.
|
|
|
869 |
*
|
|
|
870 |
* @param orderAmount
|
|
|
871 |
* The amount to convert.
|
|
|
872 |
* @return the string representation of the given amount.
|
|
|
873 |
*/
|
|
|
874 |
private PdfPCell getAmountInWordsCell(double orderAmount) {
|
|
|
875 |
RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
|
|
|
876 |
StringBuilder amountInWords = new StringBuilder("Rs. ");
|
|
|
877 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)orderAmount)));
|
|
|
878 |
amountInWords.append(" and ");
|
|
|
879 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)(orderAmount*100)%100)));
|
|
|
880 |
amountInWords.append(" paise");
|
|
|
881 |
|
|
|
882 |
PdfPCell amountInWordsCell= new PdfPCell(new Phrase(amountInWords.toString(), helveticaBold8));
|
|
|
883 |
amountInWordsCell.setColspan(4);
|
|
|
884 |
return amountInWordsCell;
|
|
|
885 |
}
|
|
|
886 |
|
|
|
887 |
/**
|
|
|
888 |
* Returns the item name to be displayed in the invoice table.
|
|
|
889 |
*
|
|
|
890 |
* @param lineitem
|
|
|
891 |
* The line item whose name has to be displayed
|
|
|
892 |
* @param appendIMEI
|
|
|
893 |
* Whether to attach the IMEI No. to the item name
|
|
|
894 |
* @return The name to be displayed for the given line item.
|
|
|
895 |
*/
|
|
|
896 |
private String getItemDisplayName(LineItem lineitem, boolean appendIMEI){
|
|
|
897 |
StringBuffer itemName = new StringBuffer();
|
|
|
898 |
if(lineitem.getBrand()!= null)
|
|
|
899 |
itemName.append(lineitem.getBrand() + " ");
|
|
|
900 |
if(lineitem.getModel_name() != null)
|
|
|
901 |
itemName.append(lineitem.getModel_name() + " ");
|
|
|
902 |
if(lineitem.getModel_number() != null )
|
|
|
903 |
itemName.append(lineitem.getModel_number() + " ");
|
|
|
904 |
if(lineitem.getColor() != null && !lineitem.getColor().trim().equals("NA"))
|
|
|
905 |
itemName.append("("+lineitem.getColor()+")");
|
|
|
906 |
if(appendIMEI && lineitem.isSetSerial_number()){
|
|
|
907 |
itemName.append("\nIMEI No. " + lineitem.getSerial_number());
|
|
|
908 |
}
|
|
|
909 |
|
|
|
910 |
return itemName.toString();
|
|
|
911 |
}
|
|
|
912 |
|
|
|
913 |
/**
|
|
|
914 |
*
|
|
|
915 |
* @param colspan
|
|
|
916 |
* @return a PdfPCell containing the E&OE text and spanning the given
|
|
|
917 |
* no. of columns
|
|
|
918 |
*/
|
|
|
919 |
private PdfPCell getEOECell(int colspan) {
|
|
|
920 |
PdfPCell eoeCell = new PdfPCell(new Phrase("E & O.E", helvetica8));
|
|
|
921 |
eoeCell.setColspan(colspan);
|
|
|
922 |
eoeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
923 |
return eoeCell;
|
|
|
924 |
}
|
|
|
925 |
|
|
|
926 |
private PdfPTable getExtraInfoTable(Order order, Provider provider, float barcodeFontSize, BillingType billingType){
|
|
|
927 |
PdfPTable extraInfoTable = new PdfPTable(1);
|
|
|
928 |
extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
929 |
extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
930 |
|
|
|
931 |
String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
932 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
933 |
ttfFontFactory.register(fontPath, "barcode");
|
|
|
934 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
|
|
935 |
|
|
|
936 |
PdfPCell extraInfoCell;
|
|
|
937 |
if(billingType == BillingType.EXTERNAL){
|
|
|
938 |
extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "* *" + order.getCustomer_name() + "* *" + order.getTotal_amount() + "*", barCodeFont));
|
|
|
939 |
}else{
|
|
|
940 |
extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "* *" + order.getLineitems().get(0).getTransfer_price() + "*", barCodeFont));
|
|
|
941 |
}
|
|
|
942 |
|
|
|
943 |
extraInfoCell.setPaddingTop(20.0f);
|
|
|
944 |
extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
945 |
extraInfoCell.setBorder(Rectangle.NO_BORDER);
|
|
|
946 |
|
|
|
947 |
extraInfoTable.addCell(extraInfoCell);
|
|
|
948 |
|
|
|
949 |
|
|
|
950 |
return extraInfoTable;
|
|
|
951 |
}
|
|
|
952 |
|
|
|
953 |
private PdfPTable getFixedTextTable(float barcodeFontSize, String printText){
|
|
|
954 |
PdfPTable extraInfoTable = new PdfPTable(1);
|
|
|
955 |
extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
956 |
extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
957 |
|
|
|
958 |
String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
959 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
960 |
ttfFontFactory.register(fontPath, "barcode");
|
|
|
961 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
|
|
962 |
|
|
|
963 |
PdfPCell extraInfoCell = new PdfPCell(new Paragraph( "*" + printText + "*", barCodeFont));
|
|
|
964 |
|
|
|
965 |
extraInfoCell.setPaddingTop(20.0f);
|
|
|
966 |
extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
967 |
extraInfoCell.setBorder(Rectangle.NO_BORDER);
|
|
|
968 |
|
|
|
969 |
extraInfoTable.addCell(extraInfoCell);
|
|
|
970 |
|
|
|
971 |
return extraInfoTable;
|
|
|
972 |
}
|
|
|
973 |
|
|
|
974 |
public static void main(String[] args) throws IOException {
|
|
|
975 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
| 7318 |
rajveer |
976 |
long orderId = 356324;
|
|
|
977 |
ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, true, false, 1);
|
| 7014 |
rajveer |
978 |
String userHome = System.getProperty("user.home");
|
|
|
979 |
File f = new File(userHome + "/invoice-" + orderId + ".pdf");
|
|
|
980 |
FileOutputStream fos = new FileOutputStream(f);
|
|
|
981 |
baos.writeTo(fos);
|
|
|
982 |
System.out.println("Invoice generated.");
|
|
|
983 |
}
|
| 2787 |
chandransh |
984 |
}
|