| 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;
|
| 8182 |
amar.kumar |
17 |
import in.shop2020.model.v1.order.EbayOrder;
|
| 2787 |
chandransh |
18 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
19 |
import in.shop2020.model.v1.order.Order;
|
| 7318 |
rajveer |
20 |
import in.shop2020.model.v1.order.OrderSource;
|
| 4361 |
rajveer |
21 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 5527 |
anupam.sin |
22 |
import in.shop2020.model.v1.order.OrderType;
|
| 10310 |
amar.kumar |
23 |
import in.shop2020.model.v1.order.ProductCondition;
|
| 8488 |
amar.kumar |
24 |
import in.shop2020.model.v1.order.SnapdealOrder;
|
| 8996 |
amar.kumar |
25 |
import in.shop2020.model.v1.order.FlipkartOrder;
|
| 9432 |
amar.kumar |
26 |
import in.shop2020.model.v1.order.TaxType;
|
| 7190 |
amar.kumar |
27 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 3132 |
rajveer |
28 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
29 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 2787 |
chandransh |
30 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 5948 |
mandeep.dh |
31 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 2787 |
chandransh |
32 |
|
| 8067 |
manish.sha |
33 |
import java.awt.image.BufferedImage;
|
| 2787 |
chandransh |
34 |
import java.io.ByteArrayOutputStream;
|
|
|
35 |
import java.io.File;
|
|
|
36 |
import java.io.FileOutputStream;
|
|
|
37 |
import java.io.IOException;
|
| 8067 |
manish.sha |
38 |
import java.io.OutputStream;
|
| 2787 |
chandransh |
39 |
import java.text.DateFormat;
|
|
|
40 |
import java.text.DecimalFormat;
|
| 4361 |
rajveer |
41 |
import java.util.ArrayList;
|
| 2787 |
chandransh |
42 |
import java.util.Date;
|
|
|
43 |
import java.util.List;
|
|
|
44 |
import java.util.Locale;
|
|
|
45 |
|
|
|
46 |
import javax.servlet.ServletException;
|
|
|
47 |
import javax.servlet.ServletOutputStream;
|
|
|
48 |
import javax.servlet.http.HttpServlet;
|
|
|
49 |
import javax.servlet.http.HttpServletRequest;
|
|
|
50 |
import javax.servlet.http.HttpServletResponse;
|
|
|
51 |
|
| 7014 |
rajveer |
52 |
import org.apache.commons.lang.StringUtils;
|
| 2787 |
chandransh |
53 |
import org.apache.commons.lang.WordUtils;
|
|
|
54 |
import org.apache.thrift.TException;
|
| 8067 |
manish.sha |
55 |
import org.krysalis.barcode4j.impl.code128.Code128Bean;
|
|
|
56 |
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
|
|
|
57 |
import org.krysalis.barcode4j.tools.UnitConv;
|
| 2787 |
chandransh |
58 |
import org.slf4j.Logger;
|
|
|
59 |
import org.slf4j.LoggerFactory;
|
|
|
60 |
|
|
|
61 |
import com.ibm.icu.text.RuleBasedNumberFormat;
|
|
|
62 |
|
|
|
63 |
import com.itextpdf.text.Document;
|
|
|
64 |
import com.itextpdf.text.Element;
|
|
|
65 |
import com.itextpdf.text.Font;
|
|
|
66 |
import com.itextpdf.text.FontFactory;
|
|
|
67 |
import com.itextpdf.text.FontFactoryImp;
|
|
|
68 |
import com.itextpdf.text.Image;
|
|
|
69 |
import com.itextpdf.text.Paragraph;
|
|
|
70 |
import com.itextpdf.text.Phrase;
|
|
|
71 |
import com.itextpdf.text.Rectangle;
|
|
|
72 |
import com.itextpdf.text.Font.FontFamily;
|
| 8034 |
manish.sha |
73 |
import com.itextpdf.text.pdf.Barcode128;
|
| 2787 |
chandransh |
74 |
import com.itextpdf.text.pdf.BaseFont;
|
| 8037 |
manish.sha |
75 |
import com.itextpdf.text.pdf.PdfContentByte;
|
| 2787 |
chandransh |
76 |
import com.itextpdf.text.pdf.PdfPCell;
|
|
|
77 |
import com.itextpdf.text.pdf.PdfPTable;
|
|
|
78 |
import com.itextpdf.text.pdf.PdfWriter;
|
|
|
79 |
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
|
|
|
80 |
|
|
|
81 |
@SuppressWarnings("serial")
|
|
|
82 |
public class InvoiceServlet extends HttpServlet {
|
| 7014 |
rajveer |
83 |
|
|
|
84 |
private static Logger logger = LoggerFactory.getLogger(InvoiceServlet.class);
|
|
|
85 |
|
|
|
86 |
@Override
|
|
|
87 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
88 |
long orderId = Long.parseLong(request.getParameter("id"));
|
|
|
89 |
long warehouseId = Long.parseLong(request.getParameter("warehouse"));
|
|
|
90 |
boolean withBill = false;
|
|
|
91 |
boolean printAll = false;
|
|
|
92 |
try {
|
|
|
93 |
withBill = Boolean.parseBoolean(request.getParameter("withBill"));
|
|
|
94 |
} catch(Exception e){
|
|
|
95 |
logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
|
|
|
96 |
}
|
|
|
97 |
try {
|
|
|
98 |
printAll = Boolean.parseBoolean(request.getParameter("printAll"));
|
|
|
99 |
} catch(Exception e){
|
|
|
100 |
logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
logger.info("Printing invoice for order id: " + orderId);
|
| 8182 |
amar.kumar |
104 |
|
| 8194 |
amar.kumar |
105 |
ByteArrayOutputStream baos = null;
|
| 8182 |
amar.kumar |
106 |
|
|
|
107 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
|
|
108 |
baos = invoiceGenerationService.generateInvoice(orderId, withBill, printAll, warehouseId);
|
| 7014 |
rajveer |
109 |
|
|
|
110 |
response.setContentType("application/pdf");
|
|
|
111 |
response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
|
|
|
112 |
|
|
|
113 |
ServletOutputStream sos;
|
|
|
114 |
try {
|
|
|
115 |
sos = response.getOutputStream();
|
|
|
116 |
baos.writeTo(sos);
|
|
|
117 |
sos.flush();
|
|
|
118 |
} catch (IOException e) {
|
|
|
119 |
logger.error("Encountered error while sending invoice response: ", e);
|
|
|
120 |
}
|
|
|
121 |
}
|
| 2787 |
chandransh |
122 |
}
|
|
|
123 |
|
|
|
124 |
class InvoiceGenerationService {
|
|
|
125 |
|
| 7014 |
rajveer |
126 |
private static Logger logger = LoggerFactory.getLogger(InvoiceGenerationService.class);
|
| 2787 |
chandransh |
127 |
|
| 7014 |
rajveer |
128 |
private TransactionClient tsc = null;
|
|
|
129 |
private InventoryClient csc = null;
|
|
|
130 |
private LogisticsClient lsc = null;
|
| 7190 |
amar.kumar |
131 |
private CatalogClient ctsc = null;
|
| 2787 |
chandransh |
132 |
|
| 7014 |
rajveer |
133 |
private static Locale indianLocale = new Locale("en", "IN");
|
|
|
134 |
private DecimalFormat amountFormat = new DecimalFormat("#,##0.00");
|
| 2787 |
chandransh |
135 |
|
| 7994 |
manish.sha |
136 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
137 |
private static final Font helvetica6 = FontFactory.getFont(FontFactory.HELVETICA, 6);
|
| 7995 |
manish.sha |
138 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
139 |
private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
|
|
140 |
private static final Font helvetica10 = FontFactory.getFont(FontFactory.HELVETICA, 10);
|
|
|
141 |
private static final Font helvetica12 = FontFactory.getFont(FontFactory.HELVETICA, 12);
|
|
|
142 |
private static final Font helvetica16 = FontFactory.getFont(FontFactory.HELVETICA, 16);
|
| 8551 |
manish.sha |
143 |
private static final Font helvetica22 = FontFactory.getFont(FontFactory.HELVETICA, 22);
|
| 2787 |
chandransh |
144 |
|
| 7014 |
rajveer |
145 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
|
|
146 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
|
|
147 |
|
|
|
148 |
private static final String delhiPincodePrefix = "11";
|
| 9319 |
amar.kumar |
149 |
private static final String[] maharashtraPincodePrefix = {"40", "41", "42", "43", "44"};
|
| 12809 |
manish.sha |
150 |
private static final String[] telanganaPincodes = {"500001","500002","500003","500004","500005","500006","500007","500008","500009","500010","500011","500012","500013","500014","500015","500016","500017","500018","500019","500020","500021","500022","500023","500024","500025","500026","500027","500028","500029","500030","500031","500032","500033","500034","500035","500036","500037","500038","500039","500040","500041","500042","500043","500044","500045","500046","500047","500048","500049","500050","500051","500052","500053","500054","500055","500056","500057","500058","500059","500060","500061","500062","500063","500064","500065","500066","500067","500068","500069","500070","500071","500072","500073","500074","500075","500076","500077","500078","500079","500080","500081","500082","500083","500084","500085","500086","500087","500088","500089","500090","500091","500092","500093","500094","500095","500096","500097","500098","500178","500409","501218","501301","501401","501510","501511","501512","502307","502319","517501","517502","517503","517505","517507","520001","520002","520003","520004","520005","520006","520007","520008","520009","520010","520011","520012","520013","520014","520015","521108","521225","522001","522002","522003","522004","522005","522006","522007","522019","522509","530001","530002","530003","530004","530005","530007","530008","530009","530010","530010","530011","530012","530013","530014","530015","530016","530017","530018","530020","530021","530022","530023","530024","530026","530027","530028","530029","530032","530035","530040","530041","530043","530044","530045","530046","531001","533101","533103","533104","533105"};
|
| 7014 |
rajveer |
151 |
|
|
|
152 |
public InvoiceGenerationService() {
|
|
|
153 |
try {
|
|
|
154 |
tsc = new TransactionClient();
|
|
|
155 |
csc = new InventoryClient();
|
|
|
156 |
lsc = new LogisticsClient();
|
| 7190 |
amar.kumar |
157 |
ctsc = new CatalogClient();
|
| 7014 |
rajveer |
158 |
} catch (Exception e) {
|
|
|
159 |
logger.error("Error while instantiating thrift clients.", e);
|
|
|
160 |
}
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
public ByteArrayOutputStream generateInvoice(long orderId, boolean withBill, boolean printAll, long warehouseId) {
|
|
|
164 |
ByteArrayOutputStream baosPDF = null;
|
|
|
165 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
166 |
in.shop2020.model.v1.inventory.InventoryService.Client iclient = csc.getClient();
|
|
|
167 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
try {
|
|
|
171 |
baosPDF = new ByteArrayOutputStream();
|
|
|
172 |
|
|
|
173 |
Document document = new Document();
|
| 8039 |
manish.sha |
174 |
PdfWriter.getInstance(document, baosPDF);
|
| 7014 |
rajveer |
175 |
document.addAuthor("shop2020");
|
|
|
176 |
//document.addTitle("Invoice No: " + order.getInvoice_number());
|
|
|
177 |
document.open();
|
|
|
178 |
|
|
|
179 |
List<Order> orders = new ArrayList<Order>();
|
|
|
180 |
if(printAll){
|
|
|
181 |
try {
|
|
|
182 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
|
|
183 |
statuses.add(OrderStatus.ACCEPTED);
|
|
|
184 |
orders = tclient.getAllOrders(statuses, 0, 0, warehouseId);
|
|
|
185 |
} catch (Exception e) {
|
|
|
186 |
logger.error("Error while getting order information", e);
|
|
|
187 |
return baosPDF;
|
| 4361 |
rajveer |
188 |
}
|
| 7014 |
rajveer |
189 |
}else{
|
|
|
190 |
orders.add(tclient.getOrder(orderId));
|
|
|
191 |
}
|
|
|
192 |
boolean isFirst = true;
|
| 5387 |
rajveer |
193 |
|
| 7014 |
rajveer |
194 |
for(Order order: orders){
|
|
|
195 |
Warehouse warehouse = null;
|
|
|
196 |
Provider provider = null;
|
|
|
197 |
String destCode = null;
|
| 8011 |
rajveer |
198 |
Warehouse shippingLocation = null;
|
| 7014 |
rajveer |
199 |
int barcodeFontSize = 0;
|
|
|
200 |
try {
|
|
|
201 |
warehouse = iclient.getWarehouse(order.getWarehouse_id());
|
|
|
202 |
long providerId = order.getLogistics_provider_id();
|
|
|
203 |
provider = logisticsClient.getProvider(providerId);
|
|
|
204 |
if(provider.getPickup().equals(PickUpType.SELF) || provider.getPickup().equals(PickUpType.RUNNER))
|
|
|
205 |
destCode = provider.getPickup().toString();
|
|
|
206 |
else
|
|
|
207 |
destCode = logisticsClient.getDestinationCode(providerId, order.getCustomer_pincode());
|
| 2787 |
chandransh |
208 |
|
| 7014 |
rajveer |
209 |
barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
|
| 8011 |
rajveer |
210 |
shippingLocation = CatalogUtils.getWarehouse(warehouse.getShippingWarehouseId());
|
| 7014 |
rajveer |
211 |
} catch (InventoryServiceException ise) {
|
|
|
212 |
logger.error("Error while getting the warehouse information.", ise);
|
|
|
213 |
return baosPDF;
|
|
|
214 |
} catch (LogisticsServiceException lse) {
|
|
|
215 |
logger.error("Error while getting the provider information.", lse);
|
|
|
216 |
return baosPDF;
|
|
|
217 |
} catch (ConfigException ce) {
|
|
|
218 |
logger.error("Error while getting the fontsize for the given provider", ce);
|
|
|
219 |
return baosPDF;
|
|
|
220 |
} catch (TException te) {
|
|
|
221 |
logger.error("Error while getting some essential information from the services", te);
|
|
|
222 |
return baosPDF;
|
|
|
223 |
}
|
| 4361 |
rajveer |
224 |
|
| 7014 |
rajveer |
225 |
if(printAll && warehouse.getBillingType() == BillingType.OURS_EXTERNAL){
|
|
|
226 |
if(isFirst){
|
|
|
227 |
document.add(getFixedTextTable(16, "Spice Online Retail Pvt Ltd"));
|
|
|
228 |
isFirst = false;
|
|
|
229 |
}
|
|
|
230 |
document.add(getExtraInfoTable(order, provider, 16, warehouse.getBillingType()));
|
|
|
231 |
continue;
|
|
|
232 |
}
|
| 8182 |
amar.kumar |
233 |
|
|
|
234 |
PdfPTable dispatchAdviceTable = null;
|
| 8488 |
amar.kumar |
235 |
|
|
|
236 |
if (new Long(order.getSource()).intValue() == OrderSource.SNAPDEAL.getValue()) {
|
|
|
237 |
dispatchAdviceTable = new PdfPTable(1);
|
| 8998 |
amar.kumar |
238 |
} else if(new Long(order.getSource()).intValue() == OrderSource.FLIPKART.getValue()) {
|
| 8996 |
amar.kumar |
239 |
dispatchAdviceTable = new PdfPTable(1);
|
|
|
240 |
} else if ((new Long(order.getSource()).intValue() == OrderSource.EBAY.getValue()) && (order.getLogistics_provider_id()>7)) {
|
| 8225 |
amar.kumar |
241 |
if(order.getWarehouse_id() == 7 || order.getWarehouse_id() == 5 || order.getWarehouse_id() == 9) {
|
|
|
242 |
dispatchAdviceTable = new PdfPTable(1);
|
| 8303 |
amar.kumar |
243 |
} else {
|
|
|
244 |
if (order.getAirwaybill_no()== null || order.getAirwaybill_no().equals("null") || order.getAirwaybill_no().isEmpty()) {
|
|
|
245 |
dispatchAdviceTable = new PdfPTable(1);
|
|
|
246 |
} else {
|
|
|
247 |
EbayInvoiceGenerationService invoiceGenerationService = new EbayInvoiceGenerationService();
|
|
|
248 |
dispatchAdviceTable = invoiceGenerationService.getDispatchAdviceTable(orderId, warehouseId);
|
|
|
249 |
}
|
| 8225 |
amar.kumar |
250 |
}
|
| 8182 |
amar.kumar |
251 |
} else {
|
|
|
252 |
dispatchAdviceTable = getDispatchAdviceTable(order, warehouse, provider, barcodeFontSize, destCode, withBill, shippingLocation);
|
|
|
253 |
}
|
| 7014 |
rajveer |
254 |
dispatchAdviceTable.setSpacingAfter(10.0f);
|
|
|
255 |
dispatchAdviceTable.setWidthPercentage(90.0f);
|
|
|
256 |
document.add(dispatchAdviceTable);
|
| 8182 |
amar.kumar |
257 |
//TODO fix this logic
|
|
|
258 |
if ((new Long(order.getSource()).intValue() == OrderSource.EBAY.getValue()) && (order.getLogistics_provider_id()>7)) {
|
| 8303 |
amar.kumar |
259 |
if (order.getAirwaybill_no()== null || order.getAirwaybill_no().equals("null") || order.getAirwaybill_no().isEmpty()
|
|
|
260 |
|| order.getWarehouse_id() == 7 || order.getWarehouse_id() == 5 || order.getWarehouse_id() == 9) {
|
|
|
261 |
if(withBill){
|
|
|
262 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(order, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , shippingLocation.getTinNumber());
|
|
|
263 |
taxTable.setSpacingBefore(5.0f);
|
|
|
264 |
taxTable.setWidthPercentage(90.0f);
|
|
|
265 |
document.add(new DottedLineSeparator());
|
|
|
266 |
document.add(taxTable);
|
|
|
267 |
}else{
|
|
|
268 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
|
|
269 |
extraInfoTable.setSpacingBefore(5.0f);
|
|
|
270 |
extraInfoTable.setWidthPercentage(90.0f);
|
|
|
271 |
document.add(new DottedLineSeparator());
|
|
|
272 |
document.add(extraInfoTable);
|
|
|
273 |
}
|
|
|
274 |
} else {
|
|
|
275 |
document.newPage();
|
|
|
276 |
}
|
| 8488 |
amar.kumar |
277 |
} else if (new Long(order.getSource()).intValue() == OrderSource.SNAPDEAL.getValue()) {
|
|
|
278 |
if(withBill){
|
|
|
279 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(order, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , shippingLocation.getTinNumber());
|
|
|
280 |
taxTable.setSpacingBefore(5.0f);
|
|
|
281 |
taxTable.setWidthPercentage(90.0f);
|
|
|
282 |
document.add(new DottedLineSeparator());
|
|
|
283 |
document.add(taxTable);
|
|
|
284 |
}else{
|
|
|
285 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
|
|
286 |
extraInfoTable.setSpacingBefore(5.0f);
|
|
|
287 |
extraInfoTable.setWidthPercentage(90.0f);
|
|
|
288 |
document.add(new DottedLineSeparator());
|
|
|
289 |
document.add(extraInfoTable);
|
|
|
290 |
}
|
| 8182 |
amar.kumar |
291 |
}
|
| 7014 |
rajveer |
292 |
if(withBill){
|
| 8016 |
rajveer |
293 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(order, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , shippingLocation.getTinNumber());
|
| 7014 |
rajveer |
294 |
taxTable.setSpacingBefore(5.0f);
|
|
|
295 |
taxTable.setWidthPercentage(90.0f);
|
|
|
296 |
document.add(new DottedLineSeparator());
|
|
|
297 |
document.add(taxTable);
|
| 9009 |
amar.kumar |
298 |
if(order.getSource() == OrderSource.FLIPKART.getValue()) {
|
| 9043 |
amar.kumar |
299 |
//document.add(new DottedLineSeparator());
|
| 9009 |
amar.kumar |
300 |
document.add(getFlipkartBarCodes(order));
|
|
|
301 |
}
|
|
|
302 |
|
| 7014 |
rajveer |
303 |
}else{
|
|
|
304 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
|
|
305 |
extraInfoTable.setSpacingBefore(5.0f);
|
|
|
306 |
extraInfoTable.setWidthPercentage(90.0f);
|
|
|
307 |
document.add(new DottedLineSeparator());
|
|
|
308 |
document.add(extraInfoTable);
|
|
|
309 |
}
|
|
|
310 |
document.newPage();
|
|
|
311 |
}
|
|
|
312 |
document.close();
|
|
|
313 |
baosPDF.close();
|
|
|
314 |
// Adding facility to store the bill on the local directory. This will happen for only for Mahipalpur warehouse.
|
|
|
315 |
if(withBill && !printAll){
|
| 7079 |
rajveer |
316 |
String strOrderId = StringUtils.repeat("0", 10-String.valueOf(orderId).length()) + orderId;
|
| 7014 |
rajveer |
317 |
String dirPath = "/SaholicInvoices" + File.separator + strOrderId.substring(0, 2) + File.separator + strOrderId.substring(2, 4) + File.separator + strOrderId.substring(4, 6);
|
|
|
318 |
String filename = dirPath + File.separator + orderId + ".pdf";
|
|
|
319 |
File dirFile = new File(dirPath);
|
|
|
320 |
if(!dirFile.exists()){
|
|
|
321 |
dirFile.mkdirs();
|
|
|
322 |
}
|
|
|
323 |
File f = new File(filename);
|
|
|
324 |
FileOutputStream fos = new FileOutputStream(f);
|
|
|
325 |
baosPDF.writeTo(fos);
|
|
|
326 |
}
|
|
|
327 |
} catch (Exception e) {
|
|
|
328 |
logger.error("Error while generating Invoice: ", e);
|
|
|
329 |
}
|
|
|
330 |
return baosPDF;
|
|
|
331 |
}
|
| 3065 |
chandransh |
332 |
|
| 8039 |
manish.sha |
333 |
private PdfPTable getDispatchAdviceTable(Order order, Warehouse warehouse, Provider provider, float barcodeFontSize, String destCode, boolean withBill, Warehouse shippingLocation){
|
| 7014 |
rajveer |
334 |
Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
|
| 2787 |
chandransh |
335 |
|
| 7014 |
rajveer |
336 |
PdfPTable table = new PdfPTable(1);
|
|
|
337 |
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 8106 |
manish.sha |
338 |
|
|
|
339 |
PdfPTable titleBarTable = new PdfPTable(new float[]{0.4f, 0.4f, 0.2f});
|
| 8107 |
manish.sha |
340 |
titleBarTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 8106 |
manish.sha |
341 |
|
| 8103 |
manish.sha |
342 |
PdfPTable logoTable = new PdfPTable(2);
|
|
|
343 |
addLogoTable(logoTable,order);
|
| 7318 |
rajveer |
344 |
|
| 7014 |
rajveer |
345 |
PdfPCell titleCell = getTitleCell();
|
|
|
346 |
PdfPTable customerTable = getCustomerAddressTable(order, destCode, false, helvetica12, false);
|
| 8039 |
manish.sha |
347 |
PdfPTable providerInfoTable = getProviderTable(order, provider, barCodeFont);
|
| 2787 |
chandransh |
348 |
|
| 7014 |
rajveer |
349 |
PdfPTable dispatchTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
|
|
350 |
dispatchTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
351 |
dispatchTable.addCell(customerTable);
|
|
|
352 |
dispatchTable.addCell(new Phrase(" "));
|
|
|
353 |
dispatchTable.addCell(providerInfoTable);
|
| 2787 |
chandransh |
354 |
|
| 7014 |
rajveer |
355 |
PdfPTable invoiceTable = getTopInvoiceTable(order, shippingLocation.getTinNumber());
|
| 8110 |
manish.sha |
356 |
PdfPTable addressTable = new PdfPTable(1);
|
|
|
357 |
addressTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
358 |
addressTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
359 |
|
| 7014 |
rajveer |
360 |
PdfPCell addressCell = getAddressCell(shippingLocation.getLocation() +
|
| 8169 |
manish.sha |
361 |
" - " + shippingLocation.getPincode() + "\nContact No.- 0120-2479977" + "\n\n");
|
| 2787 |
chandransh |
362 |
|
| 7014 |
rajveer |
363 |
PdfPTable chargesTable = new PdfPTable(1);
|
|
|
364 |
chargesTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
365 |
chargesTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
366 |
if(order.isLogisticsCod()){
|
| 7318 |
rajveer |
367 |
chargesTable.addCell(new Phrase("AMOUNT TO BE COLLECTED : Rs " + (order.getTotal_amount()-order.getGvAmount()-order.getAdvanceAmount()), helveticaBold12));
|
| 7014 |
rajveer |
368 |
chargesTable.addCell(new Phrase("RTO ADDRESS:DEL/HPW/111116"));
|
| 7994 |
manish.sha |
369 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
370 |
if(order.getLogistics_provider_id()==7L){
|
|
|
371 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
372 |
String fedexCodReturnBarcode = "";
|
| 8080 |
manish.sha |
373 |
String fedexCodReturnTrackingId = "";
|
| 7994 |
manish.sha |
374 |
try {
|
|
|
375 |
fedexCodReturnBarcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_COD_Return_BarCode");
|
| 8080 |
manish.sha |
376 |
fedexCodReturnTrackingId = tclient.getOrderAttributeValue(order.getId(), "FedEx_COD_Return_Tracking_No");
|
| 7994 |
manish.sha |
377 |
} catch (TException e1) {
|
|
|
378 |
logger.error("Error while getting the provider information.", e1);
|
|
|
379 |
}
|
| 8080 |
manish.sha |
380 |
PdfPCell formIdCell= new PdfPCell(new Paragraph("COD Return "+fedexCodReturnTrackingId+" Form id-0325", helvetica6));
|
| 8104 |
manish.sha |
381 |
formIdCell.setPaddingTop(2.0f);
|
| 7994 |
manish.sha |
382 |
formIdCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
383 |
formIdCell.setBorder(Rectangle.NO_BORDER);
|
|
|
384 |
chargesTable.addCell(new Phrase("PRIORITY OVERNIGHT ", helvetica8));
|
|
|
385 |
chargesTable.addCell(formIdCell);
|
| 8035 |
manish.sha |
386 |
|
| 8067 |
manish.sha |
387 |
generateBarcode(fedexCodReturnBarcode, "fedex_codr_"+order.getId());
|
| 8037 |
manish.sha |
388 |
|
| 8067 |
manish.sha |
389 |
Image barcodeImage=null;
|
|
|
390 |
try {
|
|
|
391 |
barcodeImage = Image.getInstance("/tmp/"+"fedex_codr_"+order.getId()+".png");
|
|
|
392 |
} catch (Exception e) {
|
|
|
393 |
logger.error("Exception during getting Barcode Image for Fedex : ", e);
|
|
|
394 |
}
|
|
|
395 |
|
| 8173 |
manish.sha |
396 |
PdfPTable codReturnTable = new PdfPTable(new float[]{0.6f,0.4f});
|
|
|
397 |
codReturnTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
398 |
codReturnTable.addCell(barcodeImage);
|
|
|
399 |
codReturnTable.addCell(new Phrase(" "));
|
|
|
400 |
chargesTable.addCell(codReturnTable);
|
|
|
401 |
|
| 7994 |
manish.sha |
402 |
}
|
|
|
403 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
404 |
} else {
|
|
|
405 |
chargesTable.addCell(new Phrase("Do not pay any extra charges to the Courier."));
|
|
|
406 |
}
|
| 8080 |
manish.sha |
407 |
|
|
|
408 |
if(order.getLogistics_provider_id()==7L){
|
|
|
409 |
chargesTable.addCell(new Phrase("Term and Condition:- Subject to the Conditions of Carriage which " +
|
|
|
410 |
"limits the liability of FedEx for loss, delay or damage to the consignment." +
|
|
|
411 |
" Visit http://www.fedex.com/in/domestic/services/terms to view the conitions of Carriage" ,
|
| 8082 |
manish.sha |
412 |
new Font(FontFamily.TIMES_ROMAN, 8f)));
|
| 8080 |
manish.sha |
413 |
}
|
| 10310 |
amar.kumar |
414 |
|
| 8110 |
manish.sha |
415 |
addressTable.addCell(new Phrase("If undelivered, return to:", helvetica10));
|
|
|
416 |
addressTable.addCell(addressCell);
|
|
|
417 |
|
| 7014 |
rajveer |
418 |
PdfPTable addressAndNoteTable = new PdfPTable(new float[]{0.3f, 0.7f});
|
|
|
419 |
addressAndNoteTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 8110 |
manish.sha |
420 |
addressAndNoteTable.addCell(addressTable);
|
| 7014 |
rajveer |
421 |
addressAndNoteTable.addCell(chargesTable);
|
| 2787 |
chandransh |
422 |
|
| 8106 |
manish.sha |
423 |
titleBarTable.addCell(logoTable);
|
|
|
424 |
titleBarTable.addCell(titleCell);
|
|
|
425 |
titleBarTable.addCell(" ");
|
|
|
426 |
|
|
|
427 |
table.addCell(titleBarTable);
|
| 7014 |
rajveer |
428 |
table.addCell(dispatchTable);
|
|
|
429 |
table.addCell(invoiceTable);
|
|
|
430 |
table.addCell(addressAndNoteTable);
|
|
|
431 |
return table;
|
|
|
432 |
}
|
| 2787 |
chandransh |
433 |
|
| 8103 |
manish.sha |
434 |
private void addLogoTable(PdfPTable logoTable,Order order) {
|
| 7318 |
rajveer |
435 |
logoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
436 |
logoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
437 |
logoTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM);
|
| 8096 |
manish.sha |
438 |
|
| 7318 |
rajveer |
439 |
PdfPCell logoCell;
|
|
|
440 |
String logoPath;
|
| 8102 |
manish.sha |
441 |
|
| 7556 |
rajveer |
442 |
if(order.getSource() == OrderSource.STORE.getValue()){
|
|
|
443 |
logoCell = new PdfPCell(new Phrase(""));
|
|
|
444 |
|
|
|
445 |
}else{
|
| 8102 |
manish.sha |
446 |
logoPath = InvoiceGenerationService.class.getResource("/logo.jpg").getPath();
|
| 8094 |
manish.sha |
447 |
|
| 7318 |
rajveer |
448 |
try {
|
|
|
449 |
logoCell = new PdfPCell(Image.getInstance(logoPath), false);
|
|
|
450 |
} catch (Exception e) {
|
|
|
451 |
//Too Many exceptions to catch here: BadElementException, MalformedURLException and IOException
|
|
|
452 |
logger.warn("Couldn't load the Saholic logo: ", e);
|
|
|
453 |
logoCell = new PdfPCell(new Phrase("Saholic Logo"));
|
|
|
454 |
}
|
|
|
455 |
|
|
|
456 |
}
|
| 8090 |
manish.sha |
457 |
logoCell.setBorder(Rectangle.NO_BORDER);
|
|
|
458 |
logoCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 8102 |
manish.sha |
459 |
logoTable.addCell(logoCell);
|
|
|
460 |
logoTable.addCell(" ");
|
| 8103 |
manish.sha |
461 |
|
| 7318 |
rajveer |
462 |
}
|
|
|
463 |
|
| 7014 |
rajveer |
464 |
private Font getBarCodeFont(Provider provider, float barcodeFontSize) {
|
|
|
465 |
String fontPath = InvoiceGenerationService.class.getResource("/" + provider.getName().toLowerCase() + "/barcode.TTF").getPath();
|
|
|
466 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
467 |
ttfFontFactory.register(fontPath, "barcode");
|
|
|
468 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
|
|
469 |
return barCodeFont;
|
|
|
470 |
}
|
| 2787 |
chandransh |
471 |
|
| 7014 |
rajveer |
472 |
private PdfPCell getTitleCell() {
|
|
|
473 |
PdfPCell titleCell = new PdfPCell(new Phrase("Dispatch Advice", helveticaBold12));
|
|
|
474 |
titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
475 |
titleCell.setBorder(Rectangle.NO_BORDER);
|
|
|
476 |
return titleCell;
|
|
|
477 |
}
|
| 2787 |
chandransh |
478 |
|
| 8039 |
manish.sha |
479 |
private PdfPTable getProviderTable(Order order, Provider provider, Font barCodeFont) {
|
| 7014 |
rajveer |
480 |
PdfPTable providerInfoTable = new PdfPTable(1);
|
|
|
481 |
providerInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 7318 |
rajveer |
482 |
if(order.isLogisticsCod()){
|
| 8551 |
manish.sha |
483 |
PdfPCell deliveryTypeCell = new PdfPCell(new Phrase("COD ", helvetica22));
|
| 7318 |
rajveer |
484 |
deliveryTypeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
485 |
deliveryTypeCell.setBorder(Rectangle.NO_BORDER);
|
|
|
486 |
providerInfoTable.addCell(deliveryTypeCell);
|
|
|
487 |
}
|
|
|
488 |
|
| 8035 |
manish.sha |
489 |
|
| 7014 |
rajveer |
490 |
PdfPCell providerNameCell = new PdfPCell(new Phrase(provider.getName(), helveticaBold12));
|
|
|
491 |
providerNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
492 |
providerNameCell.setBorder(Rectangle.NO_BORDER);
|
| 7994 |
manish.sha |
493 |
PdfPCell formIdCell= null;
|
|
|
494 |
if(order.getLogistics_provider_id()==7L){
|
|
|
495 |
if(order.isCod()){
|
| 8034 |
manish.sha |
496 |
formIdCell = new PdfPCell(new Paragraph(order.getAirwaybill_no()+" Form id-0305", helvetica6));
|
| 7994 |
manish.sha |
497 |
}
|
|
|
498 |
else{
|
| 8034 |
manish.sha |
499 |
formIdCell = new PdfPCell(new Paragraph(order.getAirwaybill_no()+" Form id-0467", helvetica6));
|
| 7994 |
manish.sha |
500 |
}
|
| 8551 |
manish.sha |
501 |
formIdCell.setPaddingTop(1.0f);
|
| 8015 |
rajveer |
502 |
formIdCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
503 |
formIdCell.setBorder(Rectangle.NO_BORDER);
|
| 7994 |
manish.sha |
504 |
}
|
| 8015 |
rajveer |
505 |
|
| 7994 |
manish.sha |
506 |
|
|
|
507 |
PdfPCell awbNumberCell= null;
|
| 8034 |
manish.sha |
508 |
String fedexPackageBarcode = "";
|
| 7994 |
manish.sha |
509 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
510 |
awbNumberCell = new PdfPCell(new Paragraph("*" + order.getAirwaybill_no() + "*", barCodeFont));
|
| 8017 |
manish.sha |
511 |
awbNumberCell.setPaddingTop(20.0f);
|
| 7994 |
manish.sha |
512 |
}
|
|
|
513 |
else{
|
| 8013 |
rajveer |
514 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
515 |
try {
|
|
|
516 |
fedexPackageBarcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_Package_BarCode");
|
|
|
517 |
} catch (TException e1) {
|
|
|
518 |
logger.error("Error while getting the provider information.", e1);
|
|
|
519 |
}
|
| 8174 |
manish.sha |
520 |
awbNumberCell = new PdfPCell(new Paragraph(" ", helvetica6));
|
|
|
521 |
}
|
|
|
522 |
awbNumberCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
523 |
awbNumberCell.setBorder(Rectangle.NO_BORDER);
|
|
|
524 |
|
|
|
525 |
providerInfoTable.addCell(providerNameCell);
|
|
|
526 |
if(formIdCell != null){
|
|
|
527 |
providerInfoTable.addCell(formIdCell);
|
|
|
528 |
}
|
|
|
529 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
530 |
if(order.getLogistics_provider_id()==7L){
|
| 8169 |
manish.sha |
531 |
generateBarcode(fedexPackageBarcode, "fedex_"+order.getId());
|
|
|
532 |
|
|
|
533 |
Image barcodeImage=null;
|
|
|
534 |
try {
|
|
|
535 |
barcodeImage = Image.getInstance("/tmp/"+"fedex_"+order.getId()+".png");
|
|
|
536 |
} catch (Exception e) {
|
|
|
537 |
logger.error("Exception during getting Barcode Image for Fedex : ", e);
|
|
|
538 |
}
|
| 8174 |
manish.sha |
539 |
providerInfoTable.addCell(barcodeImage);
|
| 7994 |
manish.sha |
540 |
}
|
| 8174 |
manish.sha |
541 |
providerInfoTable.addCell(awbNumberCell);
|
| 7014 |
rajveer |
542 |
|
| 7792 |
anupam.sin |
543 |
Warehouse warehouse = null;
|
|
|
544 |
try{
|
|
|
545 |
InventoryClient isc = new InventoryClient();
|
| 7804 |
amar.kumar |
546 |
warehouse = isc.getClient().getWarehouse(order.getWarehouse_id());
|
| 7803 |
amar.kumar |
547 |
} catch(Exception e) {
|
| 7792 |
anupam.sin |
548 |
logger.error("Unable to get warehouse for id : " + order.getWarehouse_id(), e);
|
| 7805 |
amar.kumar |
549 |
//TODO throw e;
|
| 7792 |
anupam.sin |
550 |
}
|
|
|
551 |
DeliveryType dt = DeliveryType.PREPAID;
|
|
|
552 |
if (order.isLogisticsCod()) {
|
|
|
553 |
dt = DeliveryType.COD;
|
|
|
554 |
}
|
| 7994 |
manish.sha |
555 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
556 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
557 |
for (ProviderDetails detail : provider.getDetails()) {
|
|
|
558 |
if(in.shop2020.model.v1.inventory.WarehouseLocation.findByValue((int) detail.getLogisticLocation()) == warehouse.getLogisticsLocation() && detail.getDeliveryType() == dt) {
|
|
|
559 |
providerInfoTable.addCell(new Phrase("Account No : " + detail.getAccountNo(), helvetica8));
|
|
|
560 |
}
|
|
|
561 |
}
|
| 7792 |
anupam.sin |
562 |
}
|
| 7994 |
manish.sha |
563 |
else{
|
|
|
564 |
providerInfoTable.addCell(new Phrase("STANDARD OVERNIGHT ", helvetica8));
|
|
|
565 |
}
|
|
|
566 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
567 |
Date awbDate;
|
|
|
568 |
if(order.getBilling_timestamp() == 0){
|
|
|
569 |
awbDate = new Date();
|
|
|
570 |
}else{
|
|
|
571 |
awbDate = new Date(order.getBilling_timestamp());
|
|
|
572 |
}
|
| 8106 |
manish.sha |
573 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
574 |
providerInfoTable.addCell(new Phrase("AWB Date : " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(awbDate), helvetica8));
|
|
|
575 |
}
|
| 7014 |
rajveer |
576 |
providerInfoTable.addCell(new Phrase("Weight : " + order.getTotal_weight() + " Kg", helvetica8));
|
| 8182 |
amar.kumar |
577 |
if(order.getSource() == OrderSource.EBAY.getValue()){
|
|
|
578 |
EbayOrder ebayOrder = null;
|
|
|
579 |
try {
|
|
|
580 |
ebayOrder = tsc.getClient().getEbayOrderByOrderId(order.getId());
|
|
|
581 |
} catch (TException e) {
|
|
|
582 |
logger.error("Error while getting ebay order", e);
|
|
|
583 |
}
|
|
|
584 |
providerInfoTable.addCell(new Phrase("PaisaPayId : " + ebayOrder.getPaisaPayId(), helvetica8));
|
|
|
585 |
providerInfoTable.addCell(new Phrase("Sales Rec Number: " + ebayOrder.getSalesRecordNumber(), helvetica8));
|
|
|
586 |
}
|
| 7994 |
manish.sha |
587 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
588 |
if(order.getLogistics_provider_id()==7L){
|
|
|
589 |
providerInfoTable.addCell(new Phrase("Bill T/C Sender "+ "Bill D/T Sender", helvetica8));
|
|
|
590 |
}
|
|
|
591 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
592 |
return providerInfoTable;
|
|
|
593 |
}
|
|
|
594 |
|
|
|
595 |
private PdfPTable getTopInvoiceTable(Order order, String tinNo){
|
|
|
596 |
PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.2f, 0.3f, 0.1f, 0.1f, 0.1f});
|
|
|
597 |
invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
598 |
|
|
|
599 |
invoiceTable.addCell(getInvoiceTableHeader(6));
|
|
|
600 |
|
|
|
601 |
invoiceTable.addCell(new Phrase("Order No", helvetica8));
|
|
|
602 |
invoiceTable.addCell(new Phrase("Paymode", helvetica8));
|
|
|
603 |
invoiceTable.addCell(new Phrase("Product Name", helvetica8));
|
|
|
604 |
invoiceTable.addCell(new Phrase("Quantity", helvetica8));
|
|
|
605 |
invoiceTable.addCell(new Phrase("Rate", helvetica8));
|
|
|
606 |
invoiceTable.addCell(new Phrase("Amount", helvetica8));
|
|
|
607 |
populateTopInvoiceTable(order, invoiceTable);
|
|
|
608 |
|
|
|
609 |
|
|
|
610 |
if(order.getInsurer() > 0) {
|
|
|
611 |
invoiceTable.addCell(getInsuranceCell(4));
|
|
|
612 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
|
|
613 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
|
|
614 |
}
|
|
|
615 |
|
| 7318 |
rajveer |
616 |
if(order.getSource() == OrderSource.STORE.getValue()) {
|
|
|
617 |
invoiceTable.addCell(getAdvanceAmountCell(4));
|
|
|
618 |
invoiceTable.addCell(getPriceCell(order.getAdvanceAmount()));
|
|
|
619 |
invoiceTable.addCell(getPriceCell(order.getAdvanceAmount()));
|
|
|
620 |
}
|
|
|
621 |
|
| 7014 |
rajveer |
622 |
invoiceTable.addCell(getTotalCell(4));
|
|
|
623 |
invoiceTable.addCell(getRupeesCell());
|
| 7318 |
rajveer |
624 |
invoiceTable.addCell(getTotalAmountCell(order.getTotal_amount()-order.getGvAmount()-order.getAdvanceAmount()));
|
| 7014 |
rajveer |
625 |
|
|
|
626 |
PdfPCell tinCell = new PdfPCell(new Phrase("TIN NO. " + tinNo, helvetica8));
|
|
|
627 |
tinCell.setColspan(6);
|
|
|
628 |
tinCell.setPadding(2);
|
|
|
629 |
invoiceTable.addCell(tinCell);
|
|
|
630 |
|
|
|
631 |
return invoiceTable;
|
|
|
632 |
}
|
|
|
633 |
|
|
|
634 |
private void populateTopInvoiceTable(Order order, PdfPTable invoiceTable) {
|
|
|
635 |
List<LineItem> lineitems = order.getLineitems();
|
|
|
636 |
for (LineItem lineitem : lineitems) {
|
|
|
637 |
invoiceTable.addCell(new Phrase(order.getId() + "", helvetica8));
|
|
|
638 |
if(order.getPickupStoreId() > 0 && order.isCod() == true)
|
|
|
639 |
invoiceTable.addCell(new Phrase("In-Store", helvetica8));
|
|
|
640 |
else if (order.isCod())
|
|
|
641 |
invoiceTable.addCell(new Phrase("COD", helvetica8));
|
|
|
642 |
else
|
|
|
643 |
invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
|
| 7318 |
rajveer |
644 |
|
| 7190 |
amar.kumar |
645 |
invoiceTable.addCell(getProductNameCell(lineitem, false, order.getFreebieItemId()));
|
| 2787 |
chandransh |
646 |
|
| 7014 |
rajveer |
647 |
invoiceTable.addCell(new Phrase(lineitem.getQuantity() + "", helvetica8));
|
| 2787 |
chandransh |
648 |
|
| 7014 |
rajveer |
649 |
invoiceTable.addCell(getPriceCell(lineitem.getUnit_price()-order.getGvAmount()));
|
|
|
650 |
|
|
|
651 |
invoiceTable.addCell(getPriceCell(lineitem.getTotal_price()-order.getGvAmount()));
|
|
|
652 |
}
|
|
|
653 |
}
|
|
|
654 |
|
|
|
655 |
private PdfPCell getAddressCell(String address) {
|
|
|
656 |
Paragraph addressParagraph = new Paragraph(address, new Font(FontFamily.TIMES_ROMAN, 8f));
|
|
|
657 |
PdfPCell addressCell = new PdfPCell();
|
|
|
658 |
addressCell.addElement(addressParagraph);
|
|
|
659 |
addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
660 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
|
|
661 |
return addressCell;
|
|
|
662 |
}
|
|
|
663 |
|
| 8011 |
rajveer |
664 |
private PdfPTable getTaxCumRetailInvoiceTable(Order order, Provider provider, String ourAddress, String tinNo){
|
| 7014 |
rajveer |
665 |
PdfPTable taxTable = new PdfPTable(1);
|
|
|
666 |
Phrase phrase = null;
|
|
|
667 |
taxTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
668 |
taxTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 8104 |
manish.sha |
669 |
|
| 8110 |
manish.sha |
670 |
PdfPTable logoTitleAndOurAddressTable = new PdfPTable(new float[]{0.4f, 0.3f, 0.3f});
|
| 8107 |
manish.sha |
671 |
logoTitleAndOurAddressTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 8112 |
manish.sha |
672 |
logoTitleAndOurAddressTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 8107 |
manish.sha |
673 |
|
| 8110 |
manish.sha |
674 |
|
| 8103 |
manish.sha |
675 |
PdfPTable logoTable = new PdfPTable(2);
|
|
|
676 |
addLogoTable(logoTable,order);
|
| 7318 |
rajveer |
677 |
|
| 7014 |
rajveer |
678 |
if (order.getOrderType().equals(OrderType.B2B)) {
|
|
|
679 |
phrase = new Phrase("TAX INVOICE", helveticaBold12);
|
|
|
680 |
} else {
|
|
|
681 |
phrase = new Phrase("RETAIL INVOICE", helveticaBold12);
|
|
|
682 |
}
|
|
|
683 |
PdfPCell retailInvoiceTitleCell = new PdfPCell(phrase);
|
|
|
684 |
retailInvoiceTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
685 |
retailInvoiceTitleCell.setBorder(Rectangle.NO_BORDER);
|
|
|
686 |
|
| 8169 |
manish.sha |
687 |
Paragraph sorlAddress = new Paragraph(ourAddress + "\n Contact No.- 0120-2479977" + "\nTIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f, Element.ALIGN_CENTER));
|
| 7014 |
rajveer |
688 |
PdfPCell sorlAddressCell = new PdfPCell(sorlAddress);
|
|
|
689 |
sorlAddressCell.addElement(sorlAddress);
|
| 8110 |
manish.sha |
690 |
sorlAddressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 7014 |
rajveer |
691 |
|
|
|
692 |
PdfPTable customerAddress = getCustomerAddressTable(order, null, true, helvetica8, true);
|
|
|
693 |
PdfPTable orderDetails = getOrderDetails(order, provider);
|
|
|
694 |
|
|
|
695 |
PdfPTable addrAndOrderDetailsTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
|
|
696 |
addrAndOrderDetailsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
697 |
addrAndOrderDetailsTable.addCell(customerAddress);
|
|
|
698 |
addrAndOrderDetailsTable.addCell(new Phrase(" "));
|
|
|
699 |
addrAndOrderDetailsTable.addCell(orderDetails);
|
|
|
700 |
|
| 9319 |
amar.kumar |
701 |
boolean isVAT = isVatApplicable(order);
|
| 7014 |
rajveer |
702 |
PdfPTable invoiceTable = getBottomInvoiceTable(order, isVAT);
|
|
|
703 |
|
| 10607 |
manish.sha |
704 |
PdfPTable regAddAndDisCellTable = new PdfPTable(2);
|
|
|
705 |
|
| 7014 |
rajveer |
706 |
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));
|
|
|
707 |
disclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
708 |
disclaimerCell.setBorder(Rectangle.NO_BORDER);
|
| 7318 |
rajveer |
709 |
|
| 10609 |
manish.sha |
710 |
PdfPCell regAddressCell = new PdfPCell(new Phrase(" SPICE ONLINE RETAIL PRIVATE LIMITED\n Regd. Add. 60-D, STREET NO. C-5, SAINIK FARMS,NEW DELHI-110062\n CIN: U74140DL2008PTC183856 Tel. No. 0120-2479977 E-mail. help@saholic.com Website. www.saholic.com", helvetica6));
|
| 10607 |
manish.sha |
711 |
regAddressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
712 |
regAddressCell.setBorder(Rectangle.NO_BORDER);
|
|
|
713 |
/*SPICE ONLINE RETAIL PRIVATE LIMITED
|
|
|
714 |
Regd. Add. 60-D, STREET NO. C-5, SAINIK FARMS,NEW DELHI-110062
|
|
|
715 |
CIN: U74140DL2008PTC183856
|
|
|
716 |
Tel. No. 0120-2479977
|
|
|
717 |
E-mail. help@saholic.com
|
|
|
718 |
Website. www.saholic.com*/
|
| 9014 |
amar.kumar |
719 |
PdfPCell powerTextCell = new PdfPCell(new Phrase("Powered By Flipkart", helvetica8));
|
|
|
720 |
powerTextCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
721 |
powerTextCell.setBorder(Rectangle.NO_BORDER);
|
|
|
722 |
powerTextCell.setPaddingBottom(30.0f);
|
| 8104 |
manish.sha |
723 |
|
|
|
724 |
logoTitleAndOurAddressTable.addCell(logoTable);
|
| 8110 |
manish.sha |
725 |
logoTitleAndOurAddressTable.addCell(retailInvoiceTitleCell);
|
|
|
726 |
logoTitleAndOurAddressTable.addCell(sorlAddress);
|
| 8104 |
manish.sha |
727 |
|
| 10607 |
manish.sha |
728 |
regAddAndDisCellTable.addCell(disclaimerCell);
|
|
|
729 |
regAddAndDisCellTable.addCell(regAddressCell);
|
|
|
730 |
|
| 8104 |
manish.sha |
731 |
taxTable.addCell(logoTitleAndOurAddressTable);
|
| 7014 |
rajveer |
732 |
taxTable.addCell(addrAndOrderDetailsTable);
|
|
|
733 |
taxTable.addCell(invoiceTable);
|
| 10608 |
manish.sha |
734 |
taxTable.addCell(regAddAndDisCellTable);
|
| 9014 |
amar.kumar |
735 |
if(order.getSource() == OrderSource.FLIPKART.getValue()) {
|
|
|
736 |
taxTable.addCell(powerTextCell);
|
|
|
737 |
|
|
|
738 |
}
|
| 10320 |
amar.kumar |
739 |
if(order.getProductCondition().equals(ProductCondition.BAD)){
|
| 10328 |
amar.kumar |
740 |
PdfPCell badSaleDisclaimerCell = new PdfPCell(new Phrase(" Item(s) above are sold on as is where is basis. They " +
|
| 10320 |
amar.kumar |
741 |
"may be in dead/defective/damaged/refurbished/incomplete/open condition. These " +
|
|
|
742 |
"are not returnable, exchangeable or refundable under any circumstances. No " +
|
|
|
743 |
"warranty is assured on these items." ,
|
| 10329 |
amar.kumar |
744 |
new Font(FontFamily.TIMES_ROMAN, 8f)));
|
| 10328 |
amar.kumar |
745 |
badSaleDisclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
746 |
badSaleDisclaimerCell.setBorder(Rectangle.NO_BORDER);
|
|
|
747 |
taxTable.addCell(badSaleDisclaimerCell);
|
| 10320 |
amar.kumar |
748 |
}
|
| 7014 |
rajveer |
749 |
return taxTable;
|
|
|
750 |
}
|
| 9009 |
amar.kumar |
751 |
|
| 9319 |
amar.kumar |
752 |
private boolean isVatApplicable(Order order) {
|
|
|
753 |
if(order.getWarehouse_id() == 7) {
|
|
|
754 |
if(order.getCustomer_pincode().startsWith(delhiPincodePrefix)) {
|
|
|
755 |
return true;
|
|
|
756 |
} else {
|
|
|
757 |
return false;
|
|
|
758 |
}
|
| 12809 |
manish.sha |
759 |
} else if(order.getWarehouse_id() == 3298){
|
|
|
760 |
for(int i=0; i< telanganaPincodes.length; i++) {
|
|
|
761 |
if(order.getCustomer_pincode().trim().equalsIgnoreCase(telanganaPincodes[i])) {
|
|
|
762 |
return true;
|
|
|
763 |
}
|
|
|
764 |
}
|
|
|
765 |
return false;
|
|
|
766 |
}
|
|
|
767 |
else {
|
| 9319 |
amar.kumar |
768 |
for(int i=0; i< maharashtraPincodePrefix.length; i++) {
|
|
|
769 |
if(order.getCustomer_pincode().startsWith(maharashtraPincodePrefix[i])) {
|
|
|
770 |
return true;
|
|
|
771 |
}
|
|
|
772 |
}
|
|
|
773 |
return false;
|
|
|
774 |
}
|
|
|
775 |
}
|
|
|
776 |
|
| 9037 |
amar.kumar |
777 |
private PdfPTable getFlipkartBarCodes(Order order) {
|
|
|
778 |
PdfPTable flipkartTable = new PdfPTable(3);
|
|
|
779 |
|
|
|
780 |
PdfPCell spacerCell = new PdfPCell();
|
| 9040 |
amar.kumar |
781 |
spacerCell.setBorder(Rectangle.NO_BORDER);
|
| 9037 |
amar.kumar |
782 |
spacerCell.setColspan(3);
|
| 9099 |
amar.kumar |
783 |
spacerCell.setPaddingTop(330.0f);
|
| 9037 |
amar.kumar |
784 |
|
|
|
785 |
String flipkartCodeFontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
786 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
787 |
ttfFontFactory.register(flipkartCodeFontPath, "barcode");
|
|
|
788 |
Font flipkartBarCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, 20);
|
|
|
789 |
|
| 9040 |
amar.kumar |
790 |
String serialNumber = "0000000000";
|
| 9511 |
manish.sha |
791 |
if(order.getLineitems().get(0).getSerial_number()!=null && !order.getLineitems().get(0).getSerial_number().isEmpty()) {
|
| 9040 |
amar.kumar |
792 |
serialNumber = order.getLineitems().get(0).getSerial_number();
|
| 9511 |
manish.sha |
793 |
} else if(order.getLineitems().get(0).getItem_number()!=null && !order.getLineitems().get(0).getItem_number().isEmpty()) {
|
| 9040 |
amar.kumar |
794 |
serialNumber = order.getLineitems().get(0).getItem_number();
|
|
|
795 |
}
|
|
|
796 |
|
|
|
797 |
PdfPCell serialNumberBarCodeCell = new PdfPCell(new Paragraph("*" + serialNumber + "*", flipkartBarCodeFont));
|
| 9037 |
amar.kumar |
798 |
serialNumberBarCodeCell.setBorder(Rectangle.TOP);
|
| 9044 |
amar.kumar |
799 |
serialNumberBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 9037 |
amar.kumar |
800 |
serialNumberBarCodeCell.setPaddingTop(11.0f);
|
|
|
801 |
|
|
|
802 |
|
|
|
803 |
PdfPCell invoiceNumberBarCodeCell = new PdfPCell(new Paragraph("*" + order.getInvoice_number() + "*", flipkartBarCodeFont));
|
|
|
804 |
invoiceNumberBarCodeCell.setBorder(Rectangle.TOP);
|
| 9044 |
amar.kumar |
805 |
invoiceNumberBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 9037 |
amar.kumar |
806 |
invoiceNumberBarCodeCell.setPaddingTop(11.0f);
|
|
|
807 |
|
|
|
808 |
double rate = order.getLineitems().get(0).getVatRate();
|
|
|
809 |
double salesTax = (rate * order.getTotal_amount())/(100 + rate);
|
| 9040 |
amar.kumar |
810 |
PdfPCell vatAmtBarCodeCell = new PdfPCell(new Paragraph("*" + amountFormat.format(salesTax) + "*", flipkartBarCodeFont));
|
| 9037 |
amar.kumar |
811 |
vatAmtBarCodeCell.setBorder(Rectangle.TOP);
|
| 9044 |
amar.kumar |
812 |
vatAmtBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 9037 |
amar.kumar |
813 |
vatAmtBarCodeCell.setPaddingTop(11.0f);
|
|
|
814 |
|
|
|
815 |
flipkartTable.addCell(spacerCell);
|
|
|
816 |
flipkartTable.addCell(serialNumberBarCodeCell);
|
|
|
817 |
flipkartTable.addCell(invoiceNumberBarCodeCell);
|
|
|
818 |
flipkartTable.addCell(vatAmtBarCodeCell);
|
|
|
819 |
|
|
|
820 |
return flipkartTable;
|
|
|
821 |
|
| 9009 |
amar.kumar |
822 |
}
|
|
|
823 |
|
| 7014 |
rajveer |
824 |
private PdfPTable getCustomerAddressTable(Order order, String destCode, boolean showPaymentMode, Font font, boolean forInvoce){
|
|
|
825 |
PdfPTable customerTable = new PdfPTable(1);
|
|
|
826 |
customerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
827 |
if(forInvoce || order.getPickupStoreId() == 0){
|
|
|
828 |
customerTable.addCell(new Phrase(order.getCustomer_name(), font));
|
|
|
829 |
customerTable.addCell(new Phrase(order.getCustomer_address1(), font));
|
|
|
830 |
customerTable.addCell(new Phrase(order.getCustomer_address2(), font));
|
|
|
831 |
customerTable.addCell(new Phrase(order.getCustomer_city() + "," + order.getCustomer_state(), font));
|
| 7994 |
manish.sha |
832 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
833 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
834 |
if(destCode != null)
|
|
|
835 |
customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + destCode, helvetica16));
|
|
|
836 |
else
|
|
|
837 |
customerTable.addCell(new Phrase(order.getCustomer_pincode(), font));
|
|
|
838 |
}
|
|
|
839 |
else{
|
|
|
840 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
841 |
String fedexLocationcode = "";
|
|
|
842 |
try {
|
|
|
843 |
fedexLocationcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_Location_Code");
|
|
|
844 |
} catch (TException e1) {
|
|
|
845 |
logger.error("Error while getting the provider information.", e1);
|
|
|
846 |
}
|
|
|
847 |
customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + fedexLocationcode, helvetica16));
|
|
|
848 |
}
|
|
|
849 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 9100 |
amar.kumar |
850 |
if(order.getCustomer_mobilenumber()!=null && !order.getCustomer_mobilenumber().isEmpty()) {
|
|
|
851 |
customerTable.addCell(new Phrase("Phone : " + (order.getCustomer_mobilenumber()== null ? "" : order.getCustomer_mobilenumber()), font));
|
|
|
852 |
}
|
| 7014 |
rajveer |
853 |
}else{
|
|
|
854 |
try {
|
| 5556 |
rajveer |
855 |
in.shop2020.logistics.LogisticsService.Client lclient = (new LogisticsClient()).getClient();
|
| 7014 |
rajveer |
856 |
PickupStore store = lclient.getPickupStore(order.getPickupStoreId());
|
|
|
857 |
customerTable.addCell(new Phrase(order.getCustomer_name() + " \nc/o " + store.getName(), font));
|
|
|
858 |
customerTable.addCell(new Phrase(store.getLine1(), font));
|
|
|
859 |
customerTable.addCell(new Phrase(store.getLine2(), font));
|
|
|
860 |
customerTable.addCell(new Phrase(store.getCity() + "," + store.getState(), font));
|
|
|
861 |
if(destCode != null)
|
|
|
862 |
customerTable.addCell(new Phrase(store.getPin() + " - " + destCode, helvetica16));
|
|
|
863 |
else
|
|
|
864 |
customerTable.addCell(new Phrase(store.getPin(), font));
|
|
|
865 |
customerTable.addCell(new Phrase("Phone :" + store.getPhone(), font));
|
| 5556 |
rajveer |
866 |
} catch (TException e) {
|
|
|
867 |
// TODO Auto-generated catch block
|
|
|
868 |
e.printStackTrace();
|
|
|
869 |
}
|
| 5527 |
anupam.sin |
870 |
|
| 7014 |
rajveer |
871 |
}
|
|
|
872 |
|
|
|
873 |
if(order.getOrderType().equals(OrderType.B2B)) {
|
|
|
874 |
String tin = null;
|
|
|
875 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
876 |
List<Attribute> attributes;
|
|
|
877 |
try {
|
|
|
878 |
attributes = tclient.getAllAttributesForOrderId(order.getId());
|
|
|
879 |
|
|
|
880 |
for(Attribute attribute : attributes) {
|
|
|
881 |
if(attribute.getName().equals("tinNumber")) {
|
|
|
882 |
tin = attribute.getValue();
|
|
|
883 |
}
|
|
|
884 |
}
|
|
|
885 |
if (tin != null) {
|
|
|
886 |
customerTable.addCell(new Phrase("TIN :" + tin, font));
|
|
|
887 |
}
|
|
|
888 |
|
|
|
889 |
} catch (Exception e) {
|
|
|
890 |
logger.error("Error while getting order attributes", e);
|
|
|
891 |
}
|
|
|
892 |
}
|
|
|
893 |
/*
|
| 2787 |
chandransh |
894 |
if(showPaymentMode){
|
|
|
895 |
customerTable.addCell(new Phrase(" ", font));
|
|
|
896 |
customerTable.addCell(new Phrase("Payment Mode: Prepaid", font));
|
| 5856 |
anupam.sin |
897 |
}*/
|
| 7014 |
rajveer |
898 |
return customerTable;
|
|
|
899 |
}
|
| 2787 |
chandransh |
900 |
|
| 7014 |
rajveer |
901 |
private PdfPTable getOrderDetails(Order order, Provider provider){
|
|
|
902 |
PdfPTable orderTable = new PdfPTable(new float[]{0.4f, 0.6f});
|
|
|
903 |
orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 2787 |
chandransh |
904 |
|
| 7014 |
rajveer |
905 |
orderTable.addCell(new Phrase("Invoice No:", helvetica8));
|
|
|
906 |
orderTable.addCell(new Phrase(order.getInvoice_number(), helvetica8));
|
| 2787 |
chandransh |
907 |
|
| 7014 |
rajveer |
908 |
orderTable.addCell(new Phrase("Date:", helvetica8));
|
|
|
909 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
|
| 2787 |
chandransh |
910 |
|
| 7014 |
rajveer |
911 |
orderTable.addCell(new Phrase("Order ID:", helvetica8));
|
|
|
912 |
orderTable.addCell(new Phrase("" + order.getId(), helvetica8));
|
| 2787 |
chandransh |
913 |
|
| 12590 |
amit.gupta |
914 |
if(order.getSource() == OrderSource.AMAZON.getValue() || order.getSource() == OrderSource.JUNGLEE.getValue()){
|
| 7528 |
rajveer |
915 |
AmazonOrder aorder = null;
|
|
|
916 |
try {
|
|
|
917 |
aorder = tsc.getClient().getAmazonOrder(order.getId());
|
|
|
918 |
} catch (TException e) {
|
|
|
919 |
logger.error("Error while getting amazon order", e);
|
|
|
920 |
}
|
| 12590 |
amit.gupta |
921 |
if(order.getSource() == OrderSource.JUNGLEE.getValue()){
|
|
|
922 |
orderTable.addCell(new Phrase("Junglee Order ID:", helvetica8));
|
|
|
923 |
}else {
|
|
|
924 |
orderTable.addCell(new Phrase("Amazon Order ID:", helvetica8));
|
|
|
925 |
}
|
| 7528 |
rajveer |
926 |
orderTable.addCell(new Phrase(aorder.getAmazonOrderCode(), helvetica8));
|
| 8182 |
amar.kumar |
927 |
} else if(order.getSource() == OrderSource.EBAY.getValue()){
|
|
|
928 |
EbayOrder ebayOrder = null;
|
|
|
929 |
try {
|
|
|
930 |
ebayOrder = tsc.getClient().getEbayOrderByOrderId(order.getId());
|
|
|
931 |
} catch (TException e) {
|
|
|
932 |
logger.error("Error while getting ebay order", e);
|
|
|
933 |
}
|
|
|
934 |
orderTable.addCell(new Phrase("PaisaPayId:", helvetica8));
|
|
|
935 |
orderTable.addCell(new Phrase(ebayOrder.getPaisaPayId(), helvetica8));
|
|
|
936 |
orderTable.addCell(new Phrase("Sales Rec Number:", helvetica8));
|
|
|
937 |
orderTable.addCell(new Phrase(new Long(ebayOrder.getSalesRecordNumber()).toString(), helvetica8));
|
| 8488 |
amar.kumar |
938 |
} else if(order.getSource() == OrderSource.SNAPDEAL.getValue()){
|
|
|
939 |
SnapdealOrder snapdealOrder = null;
|
|
|
940 |
try {
|
| 11424 |
kshitij.so |
941 |
snapdealOrder = tsc.getClient().getSnapdealOrder(order.getId(), null, null).get(0);
|
| 8488 |
amar.kumar |
942 |
} catch (TException e) {
|
|
|
943 |
logger.error("Error while getting snapdeal order", e);
|
|
|
944 |
}
|
|
|
945 |
orderTable.addCell(new Phrase("Snapdeal OrderId:", helvetica8));
|
|
|
946 |
orderTable.addCell(new Phrase(new Long(snapdealOrder.getSubOrderId()).toString(), helvetica8));
|
| 8828 |
amar.kumar |
947 |
|
|
|
948 |
String refernceCodeFontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
949 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
950 |
ttfFontFactory.register(refernceCodeFontPath, "barcode");
|
| 8876 |
amar.kumar |
951 |
Font referenceCodeBarCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, 20);
|
| 8828 |
amar.kumar |
952 |
|
| 8874 |
amar.kumar |
953 |
PdfPCell snapdealReferenceBarCodeCell = new PdfPCell(new Paragraph("*" + snapdealOrder.getReferenceCode() + "*", referenceCodeBarCodeFont));
|
| 8828 |
amar.kumar |
954 |
snapdealReferenceBarCodeCell.setBorder(Rectangle.NO_BORDER);
|
| 8876 |
amar.kumar |
955 |
snapdealReferenceBarCodeCell.setPaddingTop(9.0f);
|
|
|
956 |
snapdealReferenceBarCodeCell.setColspan(2);
|
| 9042 |
amar.kumar |
957 |
snapdealReferenceBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 8876 |
amar.kumar |
958 |
//orderTable.addCell(new Phrase("Snapdeal ReferenceCode:", helvetica8));
|
| 8828 |
amar.kumar |
959 |
orderTable.addCell(snapdealReferenceBarCodeCell);
|
|
|
960 |
//orderTable.addCell(new Phrase(snapdealOrder.getReferenceCode(), helvetica8));
|
| 7528 |
rajveer |
961 |
}
|
| 8989 |
vikram.rag |
962 |
else if(order.getSource() == OrderSource.FLIPKART.getValue()){
|
|
|
963 |
FlipkartOrder flipkartOrder = null;
|
|
|
964 |
try {
|
|
|
965 |
flipkartOrder = tsc.getClient().getFlipkartOrder(order.getId());
|
|
|
966 |
} catch (TException e) {
|
| 8996 |
amar.kumar |
967 |
logger.error("Error while getting flipkart order", e);
|
| 8989 |
vikram.rag |
968 |
}
|
|
|
969 |
orderTable.addCell(new Phrase("Flipkart OrderId:", helvetica8));
|
|
|
970 |
orderTable.addCell(new Phrase(flipkartOrder.getFlipkartOrderId(), helvetica8));
|
| 9037 |
amar.kumar |
971 |
|
|
|
972 |
//orderTable.addCell(new Phrase("Flipkart OrderItemId:", helvetica8));
|
|
|
973 |
String flipkartBarCodeFontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
974 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
975 |
ttfFontFactory.register(flipkartBarCodeFontPath, "barcode");
|
| 9043 |
amar.kumar |
976 |
Font flipkartBarCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, 18);
|
| 9037 |
amar.kumar |
977 |
|
| 9043 |
amar.kumar |
978 |
orderTable.addCell(new Phrase("Flipkart OrderItemId:", helvetica8));
|
| 9037 |
amar.kumar |
979 |
PdfPCell flipkartOrderItemIdBarCodeCell = new PdfPCell(new Paragraph("*" + new Long(flipkartOrder.getFlipkartSubOrderId()).toString() + "*", flipkartBarCodeFont));
|
|
|
980 |
flipkartOrderItemIdBarCodeCell.setBorder(Rectangle.NO_BORDER);
|
|
|
981 |
flipkartOrderItemIdBarCodeCell.setPaddingTop(9.0f);
|
| 9043 |
amar.kumar |
982 |
//flipkartOrderItemIdBarCodeCell.setColspan(2);
|
|
|
983 |
//flipkartOrderItemIdBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 9037 |
amar.kumar |
984 |
orderTable.addCell(flipkartOrderItemIdBarCodeCell);
|
|
|
985 |
//orderTable.addCell(new Phrase("Flipkart OrderItemId:", helvetica8));
|
|
|
986 |
//orderTable.addCell(new Phrase(new Long(flipkartOrder.getFlipkartSubOrderId()).toString(), helvetica8));
|
| 8989 |
vikram.rag |
987 |
}
|
|
|
988 |
|
|
|
989 |
|
| 7014 |
rajveer |
990 |
orderTable.addCell(new Phrase("Order Date:", helvetica8));
|
|
|
991 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getCreated_timestamp())), helvetica8));
|
| 2787 |
chandransh |
992 |
|
| 7014 |
rajveer |
993 |
orderTable.addCell(new Phrase("Courier:", helvetica8));
|
|
|
994 |
orderTable.addCell(new Phrase(provider.getName(), helvetica8));
|
| 2787 |
chandransh |
995 |
|
| 9038 |
amar.kumar |
996 |
if(order.getAirwaybill_no()!=null && !order.getAirwaybill_no().isEmpty()) {
|
|
|
997 |
orderTable.addCell(new Phrase("AWB No:", helvetica8));
|
|
|
998 |
orderTable.addCell(new Phrase(order.getAirwaybill_no(), helvetica8));
|
|
|
999 |
}
|
| 2787 |
chandransh |
1000 |
|
| 7014 |
rajveer |
1001 |
orderTable.addCell(new Phrase("AWB Date:", helvetica8));
|
|
|
1002 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
|
| 2787 |
chandransh |
1003 |
|
| 7014 |
rajveer |
1004 |
return orderTable;
|
|
|
1005 |
}
|
| 2787 |
chandransh |
1006 |
|
| 7014 |
rajveer |
1007 |
private PdfPTable getBottomInvoiceTable(Order order, boolean isVAT){
|
|
|
1008 |
PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.5f, 0.1f, 0.1f, 0.1f});
|
|
|
1009 |
invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 2787 |
chandransh |
1010 |
|
| 7014 |
rajveer |
1011 |
invoiceTable.addCell(getInvoiceTableHeader(5));
|
| 4262 |
rajveer |
1012 |
|
| 7014 |
rajveer |
1013 |
invoiceTable.addCell(new Phrase("Sl. No.", helveticaBold8));
|
|
|
1014 |
invoiceTable.addCell(new Phrase("Description", helveticaBold8));
|
|
|
1015 |
invoiceTable.addCell(new Phrase("Quantity", helveticaBold8));
|
|
|
1016 |
invoiceTable.addCell(new Phrase("Rate (Rs)", helveticaBold8));
|
|
|
1017 |
invoiceTable.addCell(new Phrase("Amount (Rs)", helveticaBold8));
|
|
|
1018 |
LineItem lineItem = order.getLineitems().get(0);
|
|
|
1019 |
double orderAmount = order.getTotal_amount();
|
|
|
1020 |
double rate = lineItem.getVatRate();
|
| 7057 |
amar.kumar |
1021 |
double salesTax = (rate * (orderAmount - order.getInsuranceAmount()))/(100 + rate);
|
| 6750 |
rajveer |
1022 |
|
| 7014 |
rajveer |
1023 |
populateBottomInvoiceTable(order, invoiceTable, rate);
|
| 6750 |
rajveer |
1024 |
|
| 7014 |
rajveer |
1025 |
PdfPCell salesTaxCell = getPriceCell(salesTax);
|
| 9432 |
amar.kumar |
1026 |
|
| 9588 |
amar.kumar |
1027 |
if(order.getTaxType().equals(TaxType.CFORM)) {
|
| 9432 |
amar.kumar |
1028 |
invoiceTable.addCell(getCFORMLabelCell());
|
|
|
1029 |
} else {
|
|
|
1030 |
invoiceTable.addCell(getVATLabelCell(isVAT));
|
|
|
1031 |
}
|
| 7014 |
rajveer |
1032 |
invoiceTable.addCell(new Phrase(rate + "%", helvetica8));
|
|
|
1033 |
invoiceTable.addCell(salesTaxCell);
|
|
|
1034 |
|
|
|
1035 |
if(order.getInsurer() > 0) {
|
|
|
1036 |
invoiceTable.addCell(getInsuranceCell(3));
|
|
|
1037 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
|
|
1038 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
|
|
1039 |
}
|
|
|
1040 |
|
|
|
1041 |
invoiceTable.addCell(getEmptyCell(5));
|
|
|
1042 |
|
|
|
1043 |
invoiceTable.addCell(getTotalCell(3));
|
|
|
1044 |
invoiceTable.addCell(getRupeesCell());
|
|
|
1045 |
invoiceTable.addCell(getTotalAmountCell(orderAmount));
|
|
|
1046 |
|
|
|
1047 |
invoiceTable.addCell(new Phrase("Amount in Words:", helvetica8));
|
|
|
1048 |
invoiceTable.addCell(getAmountInWordsCell(orderAmount));
|
|
|
1049 |
|
|
|
1050 |
invoiceTable.addCell(getEOECell(5));
|
|
|
1051 |
|
|
|
1052 |
return invoiceTable;
|
|
|
1053 |
}
|
|
|
1054 |
|
|
|
1055 |
private PdfPCell getInvoiceTableHeader(int colspan) {
|
|
|
1056 |
PdfPCell invoiceTableHeader = new PdfPCell(new Phrase("Order Details:", helveticaBold12));
|
|
|
1057 |
invoiceTableHeader.setBorder(Rectangle.NO_BORDER);
|
|
|
1058 |
invoiceTableHeader.setColspan(colspan);
|
| 8551 |
manish.sha |
1059 |
invoiceTableHeader.setPaddingTop(1);
|
| 7014 |
rajveer |
1060 |
return invoiceTableHeader;
|
|
|
1061 |
}
|
|
|
1062 |
|
|
|
1063 |
private void populateBottomInvoiceTable(Order order, PdfPTable invoiceTable, double rate) {
|
|
|
1064 |
for (LineItem lineitem : order.getLineitems()) {
|
|
|
1065 |
invoiceTable.addCell(new Phrase("" + order.getId() , helvetica8));
|
|
|
1066 |
|
| 7190 |
amar.kumar |
1067 |
invoiceTable.addCell(getProductNameCell(lineitem, true, order.getFreebieItemId()));
|
| 7014 |
rajveer |
1068 |
|
|
|
1069 |
invoiceTable.addCell(new Phrase("" + lineitem.getQuantity(), helvetica8));
|
|
|
1070 |
|
|
|
1071 |
double itemPrice = lineitem.getUnit_price();
|
|
|
1072 |
double showPrice = (100 * itemPrice)/(100 + rate);
|
|
|
1073 |
invoiceTable.addCell(getPriceCell(showPrice)); //Unit Price Cell
|
|
|
1074 |
|
|
|
1075 |
double totalPrice = lineitem.getTotal_price();
|
|
|
1076 |
showPrice = (100 * totalPrice)/(100 + rate);
|
|
|
1077 |
invoiceTable.addCell(getPriceCell(showPrice)); //Total Price Cell
|
|
|
1078 |
}
|
|
|
1079 |
}
|
|
|
1080 |
|
| 7190 |
amar.kumar |
1081 |
private PdfPCell getProductNameCell(LineItem lineitem, boolean appendIMEI, Long freebieItemId) {
|
| 7014 |
rajveer |
1082 |
String itemName = getItemDisplayName(lineitem, appendIMEI);
|
| 7190 |
amar.kumar |
1083 |
if(freebieItemId!=null && freebieItemId!=0){
|
|
|
1084 |
try {
|
|
|
1085 |
CatalogService.Client catalogClient = ctsc.getClient();
|
|
|
1086 |
Item item = catalogClient.getItem(freebieItemId);
|
|
|
1087 |
itemName = itemName + "\n(Free Item: " + item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + ")";
|
|
|
1088 |
} catch(Exception tex) {
|
|
|
1089 |
logger.error("Not able to get Freebie Item Details for ItemId:" + freebieItemId, tex);
|
|
|
1090 |
}
|
|
|
1091 |
}
|
| 7014 |
rajveer |
1092 |
PdfPCell productNameCell = new PdfPCell(new Phrase(itemName, helvetica8));
|
|
|
1093 |
productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
1094 |
return productNameCell;
|
|
|
1095 |
}
|
|
|
1096 |
|
|
|
1097 |
private PdfPCell getPriceCell(double price) {
|
|
|
1098 |
PdfPCell totalPriceCell = new PdfPCell(new Phrase(amountFormat.format(price), helvetica8));
|
|
|
1099 |
totalPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1100 |
return totalPriceCell;
|
|
|
1101 |
}
|
|
|
1102 |
|
|
|
1103 |
private PdfPCell getVATLabelCell(boolean isVAT) {
|
|
|
1104 |
PdfPCell vatCell = null;
|
|
|
1105 |
if(isVAT){
|
|
|
1106 |
vatCell = new PdfPCell(new Phrase("VAT", helveticaBold8));
|
|
|
1107 |
} else {
|
|
|
1108 |
vatCell = new PdfPCell(new Phrase("CST", helveticaBold8));
|
|
|
1109 |
}
|
|
|
1110 |
vatCell.setColspan(3);
|
|
|
1111 |
vatCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1112 |
return vatCell;
|
|
|
1113 |
}
|
|
|
1114 |
|
| 9432 |
amar.kumar |
1115 |
private PdfPCell getCFORMLabelCell() {
|
|
|
1116 |
PdfPCell cFormCell = null;
|
|
|
1117 |
cFormCell = new PdfPCell(new Phrase("CST Against CForm", helveticaBold8));
|
|
|
1118 |
cFormCell.setColspan(3);
|
|
|
1119 |
cFormCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1120 |
return cFormCell;
|
|
|
1121 |
}
|
|
|
1122 |
|
| 7318 |
rajveer |
1123 |
private PdfPCell getAdvanceAmountCell(int colspan) {
|
|
|
1124 |
PdfPCell insuranceCell = null;
|
|
|
1125 |
insuranceCell = new PdfPCell(new Phrase("Advance Amount Received", helvetica8));
|
|
|
1126 |
insuranceCell.setColspan(colspan);
|
|
|
1127 |
insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1128 |
return insuranceCell;
|
|
|
1129 |
}
|
|
|
1130 |
|
| 7014 |
rajveer |
1131 |
private PdfPCell getInsuranceCell(int colspan) {
|
|
|
1132 |
PdfPCell insuranceCell = null;
|
|
|
1133 |
insuranceCell = new PdfPCell(new Phrase("1 Year WorldWide Theft Insurance", helvetica8));
|
|
|
1134 |
insuranceCell.setColspan(colspan);
|
|
|
1135 |
insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1136 |
return insuranceCell;
|
|
|
1137 |
}
|
|
|
1138 |
|
|
|
1139 |
private PdfPCell getEmptyCell(int colspan) {
|
|
|
1140 |
PdfPCell emptyCell = new PdfPCell(new Phrase(" ", helvetica8));
|
|
|
1141 |
emptyCell.setColspan(colspan);
|
|
|
1142 |
return emptyCell;
|
|
|
1143 |
}
|
|
|
1144 |
|
|
|
1145 |
private PdfPCell getTotalCell(int colspan) {
|
|
|
1146 |
PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
|
|
|
1147 |
totalCell.setColspan(colspan);
|
|
|
1148 |
totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1149 |
return totalCell;
|
|
|
1150 |
}
|
|
|
1151 |
|
|
|
1152 |
private PdfPCell getRupeesCell() {
|
|
|
1153 |
PdfPCell rupeesCell = new PdfPCell(new Phrase("Rs.", helveticaBold8));
|
|
|
1154 |
rupeesCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1155 |
return rupeesCell;
|
|
|
1156 |
}
|
|
|
1157 |
|
|
|
1158 |
private PdfPCell getTotalAmountCell(double orderAmount) {
|
|
|
1159 |
PdfPCell totalAmountCell = new PdfPCell(new Phrase(amountFormat.format(orderAmount), helveticaBold8));
|
|
|
1160 |
totalAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1161 |
return totalAmountCell;
|
|
|
1162 |
}
|
|
|
1163 |
|
|
|
1164 |
/**
|
|
|
1165 |
* This method uses ICU4J libraries to convert the given amount into words
|
|
|
1166 |
* of Indian locale.
|
|
|
1167 |
*
|
|
|
1168 |
* @param orderAmount
|
|
|
1169 |
* The amount to convert.
|
|
|
1170 |
* @return the string representation of the given amount.
|
|
|
1171 |
*/
|
|
|
1172 |
private PdfPCell getAmountInWordsCell(double orderAmount) {
|
|
|
1173 |
RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
|
|
|
1174 |
StringBuilder amountInWords = new StringBuilder("Rs. ");
|
|
|
1175 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)orderAmount)));
|
|
|
1176 |
amountInWords.append(" and ");
|
|
|
1177 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)(orderAmount*100)%100)));
|
|
|
1178 |
amountInWords.append(" paise");
|
|
|
1179 |
|
|
|
1180 |
PdfPCell amountInWordsCell= new PdfPCell(new Phrase(amountInWords.toString(), helveticaBold8));
|
|
|
1181 |
amountInWordsCell.setColspan(4);
|
|
|
1182 |
return amountInWordsCell;
|
|
|
1183 |
}
|
|
|
1184 |
|
|
|
1185 |
/**
|
|
|
1186 |
* Returns the item name to be displayed in the invoice table.
|
|
|
1187 |
*
|
|
|
1188 |
* @param lineitem
|
|
|
1189 |
* The line item whose name has to be displayed
|
|
|
1190 |
* @param appendIMEI
|
|
|
1191 |
* Whether to attach the IMEI No. to the item name
|
|
|
1192 |
* @return The name to be displayed for the given line item.
|
|
|
1193 |
*/
|
|
|
1194 |
private String getItemDisplayName(LineItem lineitem, boolean appendIMEI){
|
|
|
1195 |
StringBuffer itemName = new StringBuffer();
|
|
|
1196 |
if(lineitem.getBrand()!= null)
|
|
|
1197 |
itemName.append(lineitem.getBrand() + " ");
|
|
|
1198 |
if(lineitem.getModel_name() != null)
|
|
|
1199 |
itemName.append(lineitem.getModel_name() + " ");
|
|
|
1200 |
if(lineitem.getModel_number() != null )
|
|
|
1201 |
itemName.append(lineitem.getModel_number() + " ");
|
|
|
1202 |
if(lineitem.getColor() != null && !lineitem.getColor().trim().equals("NA"))
|
|
|
1203 |
itemName.append("("+lineitem.getColor()+")");
|
|
|
1204 |
if(appendIMEI && lineitem.isSetSerial_number()){
|
|
|
1205 |
itemName.append("\nIMEI No. " + lineitem.getSerial_number());
|
|
|
1206 |
}
|
|
|
1207 |
|
|
|
1208 |
return itemName.toString();
|
|
|
1209 |
}
|
|
|
1210 |
|
|
|
1211 |
/**
|
|
|
1212 |
*
|
|
|
1213 |
* @param colspan
|
|
|
1214 |
* @return a PdfPCell containing the E&OE text and spanning the given
|
|
|
1215 |
* no. of columns
|
|
|
1216 |
*/
|
|
|
1217 |
private PdfPCell getEOECell(int colspan) {
|
|
|
1218 |
PdfPCell eoeCell = new PdfPCell(new Phrase("E & O.E", helvetica8));
|
|
|
1219 |
eoeCell.setColspan(colspan);
|
|
|
1220 |
eoeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1221 |
return eoeCell;
|
|
|
1222 |
}
|
|
|
1223 |
|
|
|
1224 |
private PdfPTable getExtraInfoTable(Order order, Provider provider, float barcodeFontSize, BillingType billingType){
|
|
|
1225 |
PdfPTable extraInfoTable = new PdfPTable(1);
|
|
|
1226 |
extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
1227 |
extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
1228 |
|
|
|
1229 |
String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
1230 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
1231 |
ttfFontFactory.register(fontPath, "barcode");
|
|
|
1232 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
|
|
1233 |
|
|
|
1234 |
PdfPCell extraInfoCell;
|
|
|
1235 |
if(billingType == BillingType.EXTERNAL){
|
|
|
1236 |
extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "* *" + order.getCustomer_name() + "* *" + order.getTotal_amount() + "*", barCodeFont));
|
|
|
1237 |
}else{
|
|
|
1238 |
extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "* *" + order.getLineitems().get(0).getTransfer_price() + "*", barCodeFont));
|
|
|
1239 |
}
|
|
|
1240 |
|
|
|
1241 |
extraInfoCell.setPaddingTop(20.0f);
|
|
|
1242 |
extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
1243 |
extraInfoCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1244 |
|
|
|
1245 |
extraInfoTable.addCell(extraInfoCell);
|
|
|
1246 |
|
|
|
1247 |
|
|
|
1248 |
return extraInfoTable;
|
|
|
1249 |
}
|
|
|
1250 |
|
|
|
1251 |
private PdfPTable getFixedTextTable(float barcodeFontSize, String printText){
|
|
|
1252 |
PdfPTable extraInfoTable = new PdfPTable(1);
|
|
|
1253 |
extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
1254 |
extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
1255 |
|
|
|
1256 |
String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
1257 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
1258 |
ttfFontFactory.register(fontPath, "barcode");
|
|
|
1259 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
|
|
1260 |
|
|
|
1261 |
PdfPCell extraInfoCell = new PdfPCell(new Paragraph( "*" + printText + "*", barCodeFont));
|
|
|
1262 |
|
|
|
1263 |
extraInfoCell.setPaddingTop(20.0f);
|
|
|
1264 |
extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
1265 |
extraInfoCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1266 |
|
|
|
1267 |
extraInfoTable.addCell(extraInfoCell);
|
|
|
1268 |
|
|
|
1269 |
return extraInfoTable;
|
|
|
1270 |
}
|
| 8067 |
manish.sha |
1271 |
|
|
|
1272 |
private void generateBarcode(String barcodeString, String fileName){
|
|
|
1273 |
Code128Bean bean = new Code128Bean();
|
| 7014 |
rajveer |
1274 |
|
| 8067 |
manish.sha |
1275 |
final int dpi = 60;
|
|
|
1276 |
|
|
|
1277 |
//Configure the barcode generator
|
|
|
1278 |
bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar
|
|
|
1279 |
//width exactly one pixel
|
|
|
1280 |
bean.setFontSize(bean.getFontSize()+1.0f);
|
|
|
1281 |
bean.doQuietZone(false);
|
|
|
1282 |
|
|
|
1283 |
try {
|
|
|
1284 |
File outputFile = new File("/tmp/"+fileName+".png");
|
|
|
1285 |
OutputStream out = new FileOutputStream(outputFile);
|
|
|
1286 |
|
|
|
1287 |
//Set up the canvas provider for monochrome PNG output
|
|
|
1288 |
BitmapCanvasProvider canvas = new BitmapCanvasProvider(
|
|
|
1289 |
out, "image/x-png", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
|
|
|
1290 |
|
|
|
1291 |
//Generate the barcode
|
|
|
1292 |
bean.generateBarcode(canvas, barcodeString);
|
|
|
1293 |
|
|
|
1294 |
//Signal end of generation
|
|
|
1295 |
canvas.finish();
|
|
|
1296 |
out.close();
|
|
|
1297 |
|
|
|
1298 |
}
|
|
|
1299 |
catch(Exception e){
|
|
|
1300 |
logger.error("Exception during generating Barcode : ", e);
|
|
|
1301 |
}
|
|
|
1302 |
}
|
|
|
1303 |
|
| 7014 |
rajveer |
1304 |
public static void main(String[] args) throws IOException {
|
|
|
1305 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
| 7318 |
rajveer |
1306 |
long orderId = 356324;
|
|
|
1307 |
ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, true, false, 1);
|
| 7014 |
rajveer |
1308 |
String userHome = System.getProperty("user.home");
|
|
|
1309 |
File f = new File(userHome + "/invoice-" + orderId + ".pdf");
|
|
|
1310 |
FileOutputStream fos = new FileOutputStream(f);
|
|
|
1311 |
baos.writeTo(fos);
|
|
|
1312 |
System.out.println("Invoice generated.");
|
|
|
1313 |
}
|
| 2787 |
chandransh |
1314 |
}
|