| 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;
|
| 18875 |
manish.sha |
11 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
| 7190 |
amar.kumar |
12 |
import in.shop2020.model.v1.catalog.Item;
|
| 6746 |
rajveer |
13 |
import in.shop2020.model.v1.inventory.BillingType;
|
| 5948 |
mandeep.dh |
14 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
| 5945 |
mandeep.dh |
15 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| 7528 |
rajveer |
16 |
import in.shop2020.model.v1.order.AmazonOrder;
|
| 5527 |
anupam.sin |
17 |
import in.shop2020.model.v1.order.Attribute;
|
| 8182 |
amar.kumar |
18 |
import in.shop2020.model.v1.order.EbayOrder;
|
| 13691 |
manish.sha |
19 |
import in.shop2020.model.v1.order.HsOrder;
|
| 2787 |
chandransh |
20 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
21 |
import in.shop2020.model.v1.order.Order;
|
| 7318 |
rajveer |
22 |
import in.shop2020.model.v1.order.OrderSource;
|
| 4361 |
rajveer |
23 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 5527 |
anupam.sin |
24 |
import in.shop2020.model.v1.order.OrderType;
|
| 10310 |
amar.kumar |
25 |
import in.shop2020.model.v1.order.ProductCondition;
|
| 8488 |
amar.kumar |
26 |
import in.shop2020.model.v1.order.SnapdealOrder;
|
| 8996 |
amar.kumar |
27 |
import in.shop2020.model.v1.order.FlipkartOrder;
|
| 9432 |
amar.kumar |
28 |
import in.shop2020.model.v1.order.TaxType;
|
| 18530 |
manish.sha |
29 |
import in.shop2020.model.v1.user.Address;
|
| 7190 |
amar.kumar |
30 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 3132 |
rajveer |
31 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
32 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 2787 |
chandransh |
33 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 5948 |
mandeep.dh |
34 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 18530 |
manish.sha |
35 |
import in.shop2020.thrift.clients.UserClient;
|
| 2787 |
chandransh |
36 |
|
| 8067 |
manish.sha |
37 |
import java.awt.image.BufferedImage;
|
| 2787 |
chandransh |
38 |
import java.io.ByteArrayOutputStream;
|
|
|
39 |
import java.io.File;
|
|
|
40 |
import java.io.FileOutputStream;
|
|
|
41 |
import java.io.IOException;
|
| 8067 |
manish.sha |
42 |
import java.io.OutputStream;
|
| 2787 |
chandransh |
43 |
import java.text.DateFormat;
|
|
|
44 |
import java.text.DecimalFormat;
|
| 4361 |
rajveer |
45 |
import java.util.ArrayList;
|
| 2787 |
chandransh |
46 |
import java.util.Date;
|
| 13276 |
manish.sha |
47 |
import java.util.HashMap;
|
| 2787 |
chandransh |
48 |
import java.util.List;
|
|
|
49 |
import java.util.Locale;
|
| 13276 |
manish.sha |
50 |
import java.util.Map;
|
| 2787 |
chandransh |
51 |
|
|
|
52 |
import javax.servlet.ServletException;
|
|
|
53 |
import javax.servlet.ServletOutputStream;
|
|
|
54 |
import javax.servlet.http.HttpServlet;
|
|
|
55 |
import javax.servlet.http.HttpServletRequest;
|
|
|
56 |
import javax.servlet.http.HttpServletResponse;
|
|
|
57 |
|
| 7014 |
rajveer |
58 |
import org.apache.commons.lang.StringUtils;
|
| 2787 |
chandransh |
59 |
import org.apache.commons.lang.WordUtils;
|
|
|
60 |
import org.apache.thrift.TException;
|
| 8067 |
manish.sha |
61 |
import org.krysalis.barcode4j.impl.code128.Code128Bean;
|
|
|
62 |
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
|
|
|
63 |
import org.krysalis.barcode4j.tools.UnitConv;
|
| 2787 |
chandransh |
64 |
import org.slf4j.Logger;
|
|
|
65 |
import org.slf4j.LoggerFactory;
|
|
|
66 |
|
|
|
67 |
import com.ibm.icu.text.RuleBasedNumberFormat;
|
|
|
68 |
|
|
|
69 |
import com.itextpdf.text.Document;
|
|
|
70 |
import com.itextpdf.text.Element;
|
|
|
71 |
import com.itextpdf.text.Font;
|
|
|
72 |
import com.itextpdf.text.FontFactory;
|
|
|
73 |
import com.itextpdf.text.FontFactoryImp;
|
|
|
74 |
import com.itextpdf.text.Image;
|
| 18875 |
manish.sha |
75 |
import com.itextpdf.text.PageSize;
|
| 2787 |
chandransh |
76 |
import com.itextpdf.text.Paragraph;
|
|
|
77 |
import com.itextpdf.text.Phrase;
|
|
|
78 |
import com.itextpdf.text.Rectangle;
|
|
|
79 |
import com.itextpdf.text.Font.FontFamily;
|
| 8034 |
manish.sha |
80 |
import com.itextpdf.text.pdf.Barcode128;
|
| 2787 |
chandransh |
81 |
import com.itextpdf.text.pdf.BaseFont;
|
| 8037 |
manish.sha |
82 |
import com.itextpdf.text.pdf.PdfContentByte;
|
| 2787 |
chandransh |
83 |
import com.itextpdf.text.pdf.PdfPCell;
|
|
|
84 |
import com.itextpdf.text.pdf.PdfPTable;
|
|
|
85 |
import com.itextpdf.text.pdf.PdfWriter;
|
|
|
86 |
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
|
|
|
87 |
|
|
|
88 |
@SuppressWarnings("serial")
|
|
|
89 |
public class InvoiceServlet extends HttpServlet {
|
| 7014 |
rajveer |
90 |
|
|
|
91 |
private static Logger logger = LoggerFactory.getLogger(InvoiceServlet.class);
|
|
|
92 |
|
|
|
93 |
@Override
|
|
|
94 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
95 |
long orderId = Long.parseLong(request.getParameter("id"));
|
| 13276 |
manish.sha |
96 |
String logisticsTxnId = request.getParameter("logisticsTxnId");
|
| 7014 |
rajveer |
97 |
long warehouseId = Long.parseLong(request.getParameter("warehouse"));
|
|
|
98 |
boolean withBill = false;
|
|
|
99 |
boolean printAll = false;
|
|
|
100 |
try {
|
|
|
101 |
withBill = Boolean.parseBoolean(request.getParameter("withBill"));
|
|
|
102 |
} catch(Exception e){
|
|
|
103 |
logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
|
|
|
104 |
}
|
|
|
105 |
try {
|
|
|
106 |
printAll = Boolean.parseBoolean(request.getParameter("printAll"));
|
|
|
107 |
} catch(Exception e){
|
|
|
108 |
logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
|
|
|
109 |
}
|
|
|
110 |
|
| 13276 |
manish.sha |
111 |
if(logisticsTxnId!=null && !logisticsTxnId.isEmpty()){
|
|
|
112 |
logger.info("Printing invoice for master order id: " + logisticsTxnId);
|
|
|
113 |
}else{
|
|
|
114 |
logger.info("Printing invoice for order id: " + orderId);
|
|
|
115 |
}
|
| 8182 |
amar.kumar |
116 |
|
| 8194 |
amar.kumar |
117 |
ByteArrayOutputStream baos = null;
|
| 8182 |
amar.kumar |
118 |
|
|
|
119 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
|
|
120 |
baos = invoiceGenerationService.generateInvoice(orderId, withBill, printAll, warehouseId);
|
| 7014 |
rajveer |
121 |
|
|
|
122 |
response.setContentType("application/pdf");
|
| 13276 |
manish.sha |
123 |
if(logisticsTxnId!=null && !logisticsTxnId.isEmpty()){
|
|
|
124 |
response.setHeader("Content-disposition", "inline; filename=invoice-"+logisticsTxnId+".pdf" );
|
|
|
125 |
} else {
|
|
|
126 |
response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
|
|
|
127 |
}
|
| 7014 |
rajveer |
128 |
|
|
|
129 |
ServletOutputStream sos;
|
|
|
130 |
try {
|
|
|
131 |
sos = response.getOutputStream();
|
|
|
132 |
baos.writeTo(sos);
|
|
|
133 |
sos.flush();
|
|
|
134 |
} catch (IOException e) {
|
|
|
135 |
logger.error("Encountered error while sending invoice response: ", e);
|
|
|
136 |
}
|
|
|
137 |
}
|
| 2787 |
chandransh |
138 |
}
|
|
|
139 |
|
|
|
140 |
class InvoiceGenerationService {
|
|
|
141 |
|
| 7014 |
rajveer |
142 |
private static Logger logger = LoggerFactory.getLogger(InvoiceGenerationService.class);
|
| 2787 |
chandransh |
143 |
|
| 7014 |
rajveer |
144 |
private TransactionClient tsc = null;
|
|
|
145 |
private InventoryClient csc = null;
|
|
|
146 |
private LogisticsClient lsc = null;
|
| 7190 |
amar.kumar |
147 |
private CatalogClient ctsc = null;
|
| 18530 |
manish.sha |
148 |
private UserClient usc = null;
|
| 2787 |
chandransh |
149 |
|
| 7014 |
rajveer |
150 |
private static Locale indianLocale = new Locale("en", "IN");
|
|
|
151 |
private DecimalFormat amountFormat = new DecimalFormat("#,##0.00");
|
| 2787 |
chandransh |
152 |
|
| 7994 |
manish.sha |
153 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
154 |
private static final Font helvetica6 = FontFactory.getFont(FontFactory.HELVETICA, 6);
|
| 7995 |
manish.sha |
155 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
156 |
private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
|
|
157 |
private static final Font helvetica10 = FontFactory.getFont(FontFactory.HELVETICA, 10);
|
|
|
158 |
private static final Font helvetica12 = FontFactory.getFont(FontFactory.HELVETICA, 12);
|
|
|
159 |
private static final Font helvetica16 = FontFactory.getFont(FontFactory.HELVETICA, 16);
|
| 8551 |
manish.sha |
160 |
private static final Font helvetica22 = FontFactory.getFont(FontFactory.HELVETICA, 22);
|
| 2787 |
chandransh |
161 |
|
| 7014 |
rajveer |
162 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
|
|
163 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
|
|
164 |
|
|
|
165 |
private static final String delhiPincodePrefix = "11";
|
| 9319 |
amar.kumar |
166 |
private static final String[] maharashtraPincodePrefix = {"40", "41", "42", "43", "44"};
|
| 16196 |
manish.sha |
167 |
private static final String[] karnatakaPincodePrefix = {"56", "57", "58", "59"};
|
| 12809 |
manish.sha |
168 |
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"};
|
| 18657 |
manish.sha |
169 |
private Address billingAddress;
|
| 7014 |
rajveer |
170 |
|
|
|
171 |
public InvoiceGenerationService() {
|
|
|
172 |
try {
|
|
|
173 |
tsc = new TransactionClient();
|
|
|
174 |
csc = new InventoryClient();
|
|
|
175 |
lsc = new LogisticsClient();
|
| 7190 |
amar.kumar |
176 |
ctsc = new CatalogClient();
|
| 18530 |
manish.sha |
177 |
usc = new UserClient();
|
| 7014 |
rajveer |
178 |
} catch (Exception e) {
|
|
|
179 |
logger.error("Error while instantiating thrift clients.", e);
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
public ByteArrayOutputStream generateInvoice(long orderId, boolean withBill, boolean printAll, long warehouseId) {
|
|
|
184 |
ByteArrayOutputStream baosPDF = null;
|
|
|
185 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
186 |
in.shop2020.model.v1.inventory.InventoryService.Client iclient = csc.getClient();
|
|
|
187 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
|
| 18875 |
manish.sha |
188 |
|
| 7014 |
rajveer |
189 |
try {
|
|
|
190 |
baosPDF = new ByteArrayOutputStream();
|
|
|
191 |
|
|
|
192 |
Document document = new Document();
|
| 8039 |
manish.sha |
193 |
PdfWriter.getInstance(document, baosPDF);
|
| 7014 |
rajveer |
194 |
document.addAuthor("shop2020");
|
|
|
195 |
//document.addTitle("Invoice No: " + order.getInvoice_number());
|
|
|
196 |
document.open();
|
| 13276 |
manish.sha |
197 |
//document.bo
|
| 7014 |
rajveer |
198 |
|
|
|
199 |
List<Order> orders = new ArrayList<Order>();
|
| 13276 |
manish.sha |
200 |
Map<String, List<Order>> logisticsTxnIdOrdersMap = new HashMap<String, List<Order>>();
|
| 7014 |
rajveer |
201 |
if(printAll){
|
|
|
202 |
try {
|
|
|
203 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
|
|
204 |
statuses.add(OrderStatus.ACCEPTED);
|
| 13276 |
manish.sha |
205 |
if(!tclient.isAlive()){
|
|
|
206 |
tclient = tsc.getClient();
|
|
|
207 |
}
|
| 7014 |
rajveer |
208 |
orders = tclient.getAllOrders(statuses, 0, 0, warehouseId);
|
| 13276 |
manish.sha |
209 |
for(Order o:orders){
|
|
|
210 |
if(o.isSetLogisticsTransactionId()){
|
|
|
211 |
if(logisticsTxnIdOrdersMap.containsKey(o.getLogisticsTransactionId())){
|
|
|
212 |
List<Order> groupOrdersList = logisticsTxnIdOrdersMap.get(o.getLogisticsTransactionId());
|
|
|
213 |
groupOrdersList.add(o);
|
|
|
214 |
logisticsTxnIdOrdersMap.put(o.getLogisticsTransactionId(), groupOrdersList);
|
|
|
215 |
}else {
|
|
|
216 |
List<Order> groupOrdersList = new ArrayList<Order>();
|
|
|
217 |
groupOrdersList.add(o);
|
|
|
218 |
logisticsTxnIdOrdersMap.put(o.getLogisticsTransactionId(), groupOrdersList);
|
|
|
219 |
}
|
|
|
220 |
}
|
|
|
221 |
}
|
| 7014 |
rajveer |
222 |
} catch (Exception e) {
|
|
|
223 |
logger.error("Error while getting order information", e);
|
|
|
224 |
return baosPDF;
|
| 4361 |
rajveer |
225 |
}
|
| 7014 |
rajveer |
226 |
}else{
|
| 13276 |
manish.sha |
227 |
if(!tclient.isAlive()){
|
|
|
228 |
tclient = tsc.getClient();
|
|
|
229 |
}
|
|
|
230 |
orders.add(tclient.getOrder(orderId));
|
|
|
231 |
Order o = orders.get(0);
|
|
|
232 |
if(o.isSetLogisticsTransactionId()){
|
|
|
233 |
List<Order> groupOrdersList = tclient.getGroupOrdersByLogisticsTxnId(o.getLogisticsTransactionId());
|
|
|
234 |
logisticsTxnIdOrdersMap.put(o.getLogisticsTransactionId(), groupOrdersList);
|
|
|
235 |
}
|
| 7014 |
rajveer |
236 |
}
|
|
|
237 |
boolean isFirst = true;
|
| 13276 |
manish.sha |
238 |
if(logisticsTxnIdOrdersMap!=null && logisticsTxnIdOrdersMap.size()>0){
|
|
|
239 |
for(String logisticsTxnId : logisticsTxnIdOrdersMap.keySet()){
|
|
|
240 |
List<Order> ordersList = logisticsTxnIdOrdersMap.get(logisticsTxnId);
|
|
|
241 |
Order singleOrder = ordersList.get(0);
|
|
|
242 |
Warehouse warehouse = null;
|
|
|
243 |
Provider provider = null;
|
|
|
244 |
String destCode = null;
|
|
|
245 |
Warehouse shippingLocation = null;
|
|
|
246 |
int barcodeFontSize = 0;
|
|
|
247 |
String invoiceFormat = null;
|
|
|
248 |
try {
|
|
|
249 |
warehouse = iclient.getWarehouse(singleOrder.getWarehouse_id());
|
|
|
250 |
long providerId = singleOrder.getLogistics_provider_id();
|
|
|
251 |
provider = logisticsClient.getProvider(providerId);
|
|
|
252 |
if(provider.getPickup().equals(PickUpType.SELF) || provider.getPickup().equals(PickUpType.RUNNER))
|
|
|
253 |
destCode = provider.getPickup().toString();
|
|
|
254 |
else
|
|
|
255 |
destCode = logisticsClient.getDestinationCode(providerId, singleOrder.getCustomer_pincode());
|
| 5387 |
rajveer |
256 |
|
| 13276 |
manish.sha |
257 |
barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
|
|
|
258 |
shippingLocation = CatalogUtils.getWarehouse(warehouse.getShippingWarehouseId());
|
|
|
259 |
invoiceFormat = tclient.getInvoiceFormatLogisticsTxnId(singleOrder.getTransactionId(), Long.parseLong(logisticsTxnId.split("-")[1]));
|
|
|
260 |
} catch (InventoryServiceException ise) {
|
|
|
261 |
logger.error("Error while getting the warehouse information.", ise);
|
|
|
262 |
return baosPDF;
|
|
|
263 |
} catch (LogisticsServiceException lse) {
|
|
|
264 |
logger.error("Error while getting the provider information.", lse);
|
|
|
265 |
return baosPDF;
|
|
|
266 |
} catch (ConfigException ce) {
|
|
|
267 |
logger.error("Error while getting the fontsize for the given provider", ce);
|
|
|
268 |
return baosPDF;
|
|
|
269 |
} catch (TException te) {
|
|
|
270 |
logger.error("Error while getting some essential information from the services", te);
|
|
|
271 |
return baosPDF;
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
if(printAll && warehouse.getBillingType() == BillingType.OURS_EXTERNAL){
|
|
|
275 |
for(Order order : ordersList){
|
|
|
276 |
if(isFirst){
|
|
|
277 |
document.add(getFixedTextTable(16, "Spice Online Retail Pvt Ltd"));
|
|
|
278 |
isFirst = false;
|
|
|
279 |
}
|
|
|
280 |
document.add(getExtraInfoTable(order, provider, 16, warehouse.getBillingType()));
|
|
|
281 |
continue;
|
|
|
282 |
}
|
|
|
283 |
}
|
|
|
284 |
PdfPTable dispatchAdviceTable = null;
|
|
|
285 |
Order order = ordersList.get(0);
|
|
|
286 |
if(ordersList.size()==1){
|
|
|
287 |
if (new Long(order.getSource()).intValue() == OrderSource.SNAPDEAL.getValue()) {
|
|
|
288 |
dispatchAdviceTable = new PdfPTable(1);
|
|
|
289 |
} else if(new Long(order.getSource()).intValue() == OrderSource.FLIPKART.getValue()) {
|
|
|
290 |
dispatchAdviceTable = new PdfPTable(1);
|
| 13691 |
manish.sha |
291 |
} else if(new Long(order.getSource()).intValue() == OrderSource.HOMESHOP18.getValue()) {
|
|
|
292 |
dispatchAdviceTable = new PdfPTable(1);
|
| 13276 |
manish.sha |
293 |
} else if ((new Long(order.getSource()).intValue() == OrderSource.EBAY.getValue()) && (order.getLogistics_provider_id()>7)) {
|
|
|
294 |
if(order.getWarehouse_id() == 7 || order.getWarehouse_id() == 5 || order.getWarehouse_id() == 9) {
|
|
|
295 |
dispatchAdviceTable = new PdfPTable(1);
|
|
|
296 |
} else {
|
|
|
297 |
if (order.getAirwaybill_no()== null || order.getAirwaybill_no().equals("null") || order.getAirwaybill_no().isEmpty()) {
|
|
|
298 |
dispatchAdviceTable = new PdfPTable(1);
|
|
|
299 |
} else {
|
|
|
300 |
EbayInvoiceGenerationService invoiceGenerationService = new EbayInvoiceGenerationService();
|
|
|
301 |
dispatchAdviceTable = invoiceGenerationService.getDispatchAdviceTable(orderId, warehouseId);
|
|
|
302 |
}
|
|
|
303 |
}
|
|
|
304 |
}
|
|
|
305 |
else {
|
|
|
306 |
dispatchAdviceTable = getDispatchAdviceTable(ordersList, warehouse, provider, barcodeFontSize, destCode, withBill, shippingLocation, invoiceFormat);
|
|
|
307 |
}
|
|
|
308 |
} else {
|
|
|
309 |
dispatchAdviceTable = getDispatchAdviceTable(ordersList, warehouse, provider, barcodeFontSize, destCode, withBill, shippingLocation, invoiceFormat);
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
dispatchAdviceTable.setSpacingAfter(10.0f);
|
|
|
313 |
dispatchAdviceTable.setWidthPercentage(90.0f);
|
|
|
314 |
document.add(dispatchAdviceTable);
|
|
|
315 |
if("Bulk".equalsIgnoreCase(invoiceFormat)){
|
| 13321 |
manish.sha |
316 |
if(ordersList.size()>3 || (order.getLogistics_provider_id()==7 && order.isLogisticsCod())){
|
| 13320 |
manish.sha |
317 |
document.newPage();
|
|
|
318 |
}
|
| 13276 |
manish.sha |
319 |
}
|
|
|
320 |
|
|
|
321 |
if ((new Long(order.getSource()).intValue() == OrderSource.EBAY.getValue()) && (order.getLogistics_provider_id()>7) &&(ordersList.size()==1)) {
|
|
|
322 |
if (order.getAirwaybill_no()== null || order.getAirwaybill_no().equals("null") || order.getAirwaybill_no().isEmpty()
|
|
|
323 |
|| order.getWarehouse_id() == 7 || order.getWarehouse_id() == 5 || order.getWarehouse_id() == 9) {
|
|
|
324 |
if(withBill){
|
|
|
325 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , shippingLocation.getTinNumber(), invoiceFormat);
|
|
|
326 |
taxTable.setSpacingBefore(5.0f);
|
|
|
327 |
taxTable.setWidthPercentage(90.0f);
|
|
|
328 |
document.add(new DottedLineSeparator());
|
|
|
329 |
document.add(taxTable);
|
|
|
330 |
}else{
|
|
|
331 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
|
|
332 |
extraInfoTable.setSpacingBefore(5.0f);
|
|
|
333 |
extraInfoTable.setWidthPercentage(90.0f);
|
|
|
334 |
document.add(new DottedLineSeparator());
|
|
|
335 |
document.add(extraInfoTable);
|
|
|
336 |
}
|
|
|
337 |
} else {
|
|
|
338 |
document.newPage();
|
|
|
339 |
}
|
|
|
340 |
} else if (new Long(order.getSource()).intValue() == OrderSource.SNAPDEAL.getValue() &&(ordersList.size()==1)) {
|
|
|
341 |
if(withBill){
|
|
|
342 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , shippingLocation.getTinNumber(), invoiceFormat);
|
|
|
343 |
taxTable.setSpacingBefore(5.0f);
|
|
|
344 |
taxTable.setWidthPercentage(90.0f);
|
|
|
345 |
document.add(new DottedLineSeparator());
|
|
|
346 |
document.add(taxTable);
|
|
|
347 |
}else{
|
|
|
348 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
|
|
349 |
extraInfoTable.setSpacingBefore(5.0f);
|
|
|
350 |
extraInfoTable.setWidthPercentage(90.0f);
|
|
|
351 |
document.add(new DottedLineSeparator());
|
|
|
352 |
document.add(extraInfoTable);
|
|
|
353 |
}
|
|
|
354 |
}
|
|
|
355 |
if(withBill){
|
|
|
356 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , shippingLocation.getTinNumber(), invoiceFormat);
|
|
|
357 |
taxTable.setSpacingBefore(5.0f);
|
|
|
358 |
taxTable.setWidthPercentage(90.0f);
|
|
|
359 |
document.add(new DottedLineSeparator());
|
|
|
360 |
document.add(taxTable);
|
|
|
361 |
if(order.getSource() == OrderSource.FLIPKART.getValue()) {
|
|
|
362 |
//document.add(new DottedLineSeparator());
|
|
|
363 |
document.add(getFlipkartBarCodes(order));
|
|
|
364 |
}
|
| 2787 |
chandransh |
365 |
|
| 13276 |
manish.sha |
366 |
}else{
|
|
|
367 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
|
|
368 |
extraInfoTable.setSpacingBefore(5.0f);
|
|
|
369 |
extraInfoTable.setWidthPercentage(90.0f);
|
|
|
370 |
document.add(new DottedLineSeparator());
|
|
|
371 |
document.add(extraInfoTable);
|
|
|
372 |
}
|
| 13316 |
manish.sha |
373 |
|
|
|
374 |
if("Bulk".equalsIgnoreCase(invoiceFormat)){
|
|
|
375 |
PdfPTable orderItemsDetailTable = new PdfPTable(1);
|
|
|
376 |
orderItemsDetailTable.setWidthPercentage(90.0f);
|
|
|
377 |
orderItemsDetailTable.setSpacingBefore(5.0f);
|
|
|
378 |
orderItemsDetailTable.addCell(new Phrase("SubOrder Ids :", helveticaBold8));
|
|
|
379 |
StringBuffer sbOrders = new StringBuffer();
|
|
|
380 |
|
| 13318 |
manish.sha |
381 |
for(Order o1 : ordersList){
|
| 13316 |
manish.sha |
382 |
sbOrders.append(o1.getId()+",");
|
|
|
383 |
}
|
|
|
384 |
|
|
|
385 |
|
|
|
386 |
String orderIds = sbOrders.toString();
|
|
|
387 |
orderIds = orderIds.substring(0, orderIds.length()-1);
|
| 13319 |
manish.sha |
388 |
|
| 13316 |
manish.sha |
389 |
StringBuffer sbImeis = new StringBuffer();
|
|
|
390 |
|
| 13317 |
manish.sha |
391 |
for(Order o1 : ordersList){
|
| 13316 |
manish.sha |
392 |
if(o1.getLineitems().get(0).getSerial_number()!=null){
|
|
|
393 |
sbImeis.append(o1.getLineitems().get(0).getSerial_number()+",");
|
|
|
394 |
}
|
|
|
395 |
}
|
|
|
396 |
|
| 13319 |
manish.sha |
397 |
orderItemsDetailTable.addCell(new Phrase(orderIds.toString(), helvetica8));
|
| 13316 |
manish.sha |
398 |
|
| 13319 |
manish.sha |
399 |
if(sbImeis.length()>0){
|
|
|
400 |
orderItemsDetailTable.addCell(new Phrase("IMEI Details :", helveticaBold8));
|
|
|
401 |
logger.info("Imeis List:- " + sbImeis);
|
|
|
402 |
String imeis = sbImeis.toString();
|
| 13490 |
manish.sha |
403 |
if(imeis.endsWith(","))
|
|
|
404 |
imeis = imeis.substring(0, imeis.length()-1);
|
| 13319 |
manish.sha |
405 |
logger.info("Final Imeis List:- " + sbImeis);
|
|
|
406 |
|
|
|
407 |
orderItemsDetailTable.addCell(new Phrase(imeis, helvetica8));
|
|
|
408 |
}
|
|
|
409 |
|
| 13316 |
manish.sha |
410 |
document.add(orderItemsDetailTable);
|
|
|
411 |
}
|
| 18779 |
manish.sha |
412 |
PdfPTable billingAddressTable = getCustomerAddressTable(order, null, true, helvetica8, true, true);
|
| 18778 |
manish.sha |
413 |
if(billingAddress!=null){
|
|
|
414 |
billingAddressTable.setWidthPercentage(90.0f);
|
|
|
415 |
billingAddressTable.setSpacingBefore(5.0f);
|
|
|
416 |
billingAddressTable.addCell(new Phrase("Billing Address :", helveticaBold8));
|
|
|
417 |
billingAddressTable.addCell(new Phrase(billingAddress.getName() +" "+billingAddress.getLine1()
|
|
|
418 |
+billingAddress.getLine2() +" "+billingAddress.getCity() + "," + billingAddress.getState()
|
|
|
419 |
+" -"+billingAddress.getPin(), helvetica8));
|
|
|
420 |
document.add(billingAddressTable);
|
|
|
421 |
}
|
| 13316 |
manish.sha |
422 |
|
| 13276 |
manish.sha |
423 |
document.newPage();
|
| 7014 |
rajveer |
424 |
}
|
| 13276 |
manish.sha |
425 |
} else {
|
|
|
426 |
for(Order singleOrder : orders){
|
|
|
427 |
List<Order> ordersList = new ArrayList<Order>();
|
|
|
428 |
ordersList.add(singleOrder);
|
|
|
429 |
Warehouse warehouse = null;
|
|
|
430 |
Provider provider = null;
|
|
|
431 |
String destCode = null;
|
|
|
432 |
Warehouse shippingLocation = null;
|
|
|
433 |
int barcodeFontSize = 0;
|
|
|
434 |
String invoiceFormat = "Individual";
|
|
|
435 |
try {
|
|
|
436 |
warehouse = iclient.getWarehouse(singleOrder.getWarehouse_id());
|
|
|
437 |
long providerId = singleOrder.getLogistics_provider_id();
|
|
|
438 |
provider = logisticsClient.getProvider(providerId);
|
|
|
439 |
if(provider.getPickup().equals(PickUpType.SELF) || provider.getPickup().equals(PickUpType.RUNNER))
|
|
|
440 |
destCode = provider.getPickup().toString();
|
|
|
441 |
else
|
|
|
442 |
destCode = logisticsClient.getDestinationCode(providerId, singleOrder.getCustomer_pincode());
|
| 4361 |
rajveer |
443 |
|
| 13276 |
manish.sha |
444 |
barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
|
|
|
445 |
shippingLocation = CatalogUtils.getWarehouse(warehouse.getShippingWarehouseId());
|
|
|
446 |
} catch (InventoryServiceException ise) {
|
|
|
447 |
logger.error("Error while getting the warehouse information.", ise);
|
|
|
448 |
return baosPDF;
|
|
|
449 |
} catch (LogisticsServiceException lse) {
|
|
|
450 |
logger.error("Error while getting the provider information.", lse);
|
|
|
451 |
return baosPDF;
|
|
|
452 |
} catch (ConfigException ce) {
|
|
|
453 |
logger.error("Error while getting the fontsize for the given provider", ce);
|
|
|
454 |
return baosPDF;
|
|
|
455 |
} catch (TException te) {
|
|
|
456 |
logger.error("Error while getting some essential information from the services", te);
|
|
|
457 |
return baosPDF;
|
| 7014 |
rajveer |
458 |
}
|
| 13276 |
manish.sha |
459 |
|
|
|
460 |
if(printAll && warehouse.getBillingType() == BillingType.OURS_EXTERNAL){
|
|
|
461 |
for(Order order : ordersList){
|
|
|
462 |
if(isFirst){
|
|
|
463 |
document.add(getFixedTextTable(16, "Spice Online Retail Pvt Ltd"));
|
|
|
464 |
isFirst = false;
|
|
|
465 |
}
|
|
|
466 |
document.add(getExtraInfoTable(order, provider, 16, warehouse.getBillingType()));
|
|
|
467 |
continue;
|
|
|
468 |
}
|
|
|
469 |
}
|
|
|
470 |
PdfPTable dispatchAdviceTable = null;
|
|
|
471 |
Order order = ordersList.get(0);
|
|
|
472 |
if(ordersList.size()==1){
|
|
|
473 |
if (new Long(order.getSource()).intValue() == OrderSource.SNAPDEAL.getValue()) {
|
| 8303 |
amar.kumar |
474 |
dispatchAdviceTable = new PdfPTable(1);
|
| 13276 |
manish.sha |
475 |
} else if(new Long(order.getSource()).intValue() == OrderSource.FLIPKART.getValue()) {
|
|
|
476 |
dispatchAdviceTable = new PdfPTable(1);
|
| 13705 |
manish.sha |
477 |
} else if(new Long(order.getSource()).intValue() == OrderSource.HOMESHOP18.getValue()) {
|
|
|
478 |
dispatchAdviceTable = new PdfPTable(1);
|
| 13276 |
manish.sha |
479 |
} else if ((new Long(order.getSource()).intValue() == OrderSource.EBAY.getValue()) && (order.getLogistics_provider_id()>7)) {
|
|
|
480 |
if(order.getWarehouse_id() == 7 || order.getWarehouse_id() == 5 || order.getWarehouse_id() == 9) {
|
|
|
481 |
dispatchAdviceTable = new PdfPTable(1);
|
|
|
482 |
} else {
|
|
|
483 |
if (order.getAirwaybill_no()== null || order.getAirwaybill_no().equals("null") || order.getAirwaybill_no().isEmpty()) {
|
|
|
484 |
dispatchAdviceTable = new PdfPTable(1);
|
|
|
485 |
} else {
|
|
|
486 |
EbayInvoiceGenerationService invoiceGenerationService = new EbayInvoiceGenerationService();
|
|
|
487 |
dispatchAdviceTable = invoiceGenerationService.getDispatchAdviceTable(orderId, warehouseId);
|
|
|
488 |
}
|
|
|
489 |
}
|
|
|
490 |
}
|
|
|
491 |
else {
|
|
|
492 |
dispatchAdviceTable = getDispatchAdviceTable(ordersList, warehouse, provider, barcodeFontSize, destCode, withBill, shippingLocation, invoiceFormat);
|
|
|
493 |
}
|
|
|
494 |
} else {
|
|
|
495 |
dispatchAdviceTable = getDispatchAdviceTable(ordersList, warehouse, provider, barcodeFontSize, destCode, withBill, shippingLocation, invoiceFormat);
|
|
|
496 |
}
|
|
|
497 |
|
|
|
498 |
dispatchAdviceTable.setSpacingAfter(10.0f);
|
|
|
499 |
dispatchAdviceTable.setWidthPercentage(90.0f);
|
|
|
500 |
document.add(dispatchAdviceTable);
|
|
|
501 |
if("Bulk".equalsIgnoreCase(invoiceFormat)){
|
| 13320 |
manish.sha |
502 |
if(ordersList.size()>1){
|
|
|
503 |
document.newPage();
|
|
|
504 |
}
|
| 13276 |
manish.sha |
505 |
}
|
|
|
506 |
|
|
|
507 |
if ((new Long(order.getSource()).intValue() == OrderSource.EBAY.getValue()) && (order.getLogistics_provider_id()>7) &&(ordersList.size()==1)) {
|
|
|
508 |
if (order.getAirwaybill_no()== null || order.getAirwaybill_no().equals("null") || order.getAirwaybill_no().isEmpty()
|
|
|
509 |
|| order.getWarehouse_id() == 7 || order.getWarehouse_id() == 5 || order.getWarehouse_id() == 9) {
|
|
|
510 |
if(withBill){
|
|
|
511 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , shippingLocation.getTinNumber(), invoiceFormat);
|
|
|
512 |
taxTable.setSpacingBefore(5.0f);
|
|
|
513 |
taxTable.setWidthPercentage(90.0f);
|
|
|
514 |
document.add(new DottedLineSeparator());
|
|
|
515 |
document.add(taxTable);
|
|
|
516 |
}else{
|
|
|
517 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
|
|
518 |
extraInfoTable.setSpacingBefore(5.0f);
|
|
|
519 |
extraInfoTable.setWidthPercentage(90.0f);
|
|
|
520 |
document.add(new DottedLineSeparator());
|
|
|
521 |
document.add(extraInfoTable);
|
|
|
522 |
}
|
| 8303 |
amar.kumar |
523 |
} else {
|
| 13276 |
manish.sha |
524 |
document.newPage();
|
| 8303 |
amar.kumar |
525 |
}
|
| 13276 |
manish.sha |
526 |
} else if (new Long(order.getSource()).intValue() == OrderSource.SNAPDEAL.getValue() &&(ordersList.size()==1)) {
|
| 8303 |
amar.kumar |
527 |
if(withBill){
|
| 13276 |
manish.sha |
528 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , shippingLocation.getTinNumber(), invoiceFormat);
|
| 8303 |
amar.kumar |
529 |
taxTable.setSpacingBefore(5.0f);
|
|
|
530 |
taxTable.setWidthPercentage(90.0f);
|
|
|
531 |
document.add(new DottedLineSeparator());
|
|
|
532 |
document.add(taxTable);
|
|
|
533 |
}else{
|
|
|
534 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
|
|
535 |
extraInfoTable.setSpacingBefore(5.0f);
|
|
|
536 |
extraInfoTable.setWidthPercentage(90.0f);
|
|
|
537 |
document.add(new DottedLineSeparator());
|
|
|
538 |
document.add(extraInfoTable);
|
|
|
539 |
}
|
|
|
540 |
}
|
| 8488 |
amar.kumar |
541 |
if(withBill){
|
| 13276 |
manish.sha |
542 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , shippingLocation.getTinNumber(), invoiceFormat);
|
| 8488 |
amar.kumar |
543 |
taxTable.setSpacingBefore(5.0f);
|
|
|
544 |
taxTable.setWidthPercentage(90.0f);
|
|
|
545 |
document.add(new DottedLineSeparator());
|
|
|
546 |
document.add(taxTable);
|
| 13276 |
manish.sha |
547 |
if(order.getSource() == OrderSource.FLIPKART.getValue()) {
|
|
|
548 |
//document.add(new DottedLineSeparator());
|
|
|
549 |
document.add(getFlipkartBarCodes(order));
|
|
|
550 |
}
|
|
|
551 |
|
| 8488 |
amar.kumar |
552 |
}else{
|
|
|
553 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
|
|
554 |
extraInfoTable.setSpacingBefore(5.0f);
|
|
|
555 |
extraInfoTable.setWidthPercentage(90.0f);
|
|
|
556 |
document.add(new DottedLineSeparator());
|
|
|
557 |
document.add(extraInfoTable);
|
|
|
558 |
}
|
| 13276 |
manish.sha |
559 |
|
|
|
560 |
if("Bulk".equalsIgnoreCase(invoiceFormat)){
|
|
|
561 |
PdfPTable orderItemsDetailTable = new PdfPTable(1);
|
|
|
562 |
orderItemsDetailTable.setWidthPercentage(90.0f);
|
|
|
563 |
orderItemsDetailTable.setSpacingBefore(5.0f);
|
| 13313 |
manish.sha |
564 |
orderItemsDetailTable.addCell(new Phrase("SubOrder Ids :", helveticaBold8));
|
| 13276 |
manish.sha |
565 |
StringBuffer sbOrders = new StringBuffer();
|
|
|
566 |
|
|
|
567 |
for(Order o1 : orders){
|
|
|
568 |
sbOrders.append(o1.getId()+",");
|
|
|
569 |
}
|
|
|
570 |
|
|
|
571 |
|
|
|
572 |
String orderIds = sbOrders.toString();
|
|
|
573 |
orderIds = orderIds.substring(0, orderIds.length()-1);
|
|
|
574 |
|
|
|
575 |
orderItemsDetailTable.addCell(new Phrase(orderIds.toString(), helvetica8));
|
| 13319 |
manish.sha |
576 |
|
| 13276 |
manish.sha |
577 |
|
|
|
578 |
StringBuffer sbImeis = new StringBuffer();
|
|
|
579 |
|
|
|
580 |
for(Order o1 : orders){
|
|
|
581 |
if(o1.getLineitems().get(0).getSerial_number()!=null){
|
|
|
582 |
sbImeis.append(o1.getLineitems().get(0).getSerial_number()+",");
|
|
|
583 |
}
|
|
|
584 |
}
|
|
|
585 |
|
| 13319 |
manish.sha |
586 |
if(sbImeis.length()>0){
|
|
|
587 |
orderItemsDetailTable.addCell(new Phrase("IMEI Details :", helveticaBold8));
|
|
|
588 |
|
|
|
589 |
logger.info("Imeis List:- " + sbImeis);
|
|
|
590 |
String imeis = sbImeis.toString();
|
|
|
591 |
imeis = imeis.substring(0, imeis.length()-2);
|
|
|
592 |
logger.info("Final Imeis List:- " + sbImeis);
|
|
|
593 |
|
|
|
594 |
orderItemsDetailTable.addCell(new Phrase(imeis, helvetica8));
|
|
|
595 |
}
|
|
|
596 |
|
| 13276 |
manish.sha |
597 |
document.add(orderItemsDetailTable);
|
| 9009 |
amar.kumar |
598 |
}
|
| 18779 |
manish.sha |
599 |
PdfPTable billingAddressTable = getCustomerAddressTable(order, null, true, helvetica8, true, true);
|
| 18769 |
manish.sha |
600 |
if(billingAddress!=null){
|
|
|
601 |
billingAddressTable.setWidthPercentage(90.0f);
|
|
|
602 |
billingAddressTable.setSpacingBefore(5.0f);
|
|
|
603 |
billingAddressTable.addCell(new Phrase("Billing Address :", helveticaBold8));
|
|
|
604 |
billingAddressTable.addCell(new Phrase(billingAddress.getName() +" "+billingAddress.getLine1()
|
|
|
605 |
+billingAddress.getLine2() +" "+billingAddress.getCity() + "," + billingAddress.getState()
|
|
|
606 |
+" -"+billingAddress.getPin(), helvetica8));
|
|
|
607 |
document.add(billingAddressTable);
|
|
|
608 |
}
|
|
|
609 |
|
| 13276 |
manish.sha |
610 |
document.newPage();
|
| 7014 |
rajveer |
611 |
}
|
|
|
612 |
}
|
| 13276 |
manish.sha |
613 |
|
| 18875 |
manish.sha |
614 |
|
|
|
615 |
if(logisticsTxnIdOrdersMap!=null && logisticsTxnIdOrdersMap.size()>0){
|
|
|
616 |
for(String logisticsTxnId : logisticsTxnIdOrdersMap.keySet()){
|
| 18878 |
manish.sha |
617 |
document.setPageSize(PageSize.A4.rotate());
|
|
|
618 |
document.left(50f);
|
|
|
619 |
document.top(75f);
|
| 18875 |
manish.sha |
620 |
document.newPage();
|
|
|
621 |
List<Order> ordersList = logisticsTxnIdOrdersMap.get(logisticsTxnId);
|
|
|
622 |
PdfPTable headerTable = new PdfPTable(1);
|
|
|
623 |
headerTable.addCell(getInvoiceTableHeader(0,ordersList.get(0).getLogisticsTransactionId()));
|
|
|
624 |
PdfPTable packagingTable = getPackagingInfoTable(ordersList);
|
| 18876 |
manish.sha |
625 |
PdfPTable signTable = new PdfPTable(new float[]{0.1f, 0.8f, 0.1f});
|
|
|
626 |
signTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
627 |
signTable.setSplitLate(false);
|
|
|
628 |
signTable.setSpacingBefore(10.0f);
|
|
|
629 |
signTable.addCell(new Phrase("Biller",helveticaBold8));
|
|
|
630 |
signTable.addCell(new Phrase("",helveticaBold8));
|
|
|
631 |
signTable.addCell(new Phrase("Packer",helveticaBold8));
|
| 18875 |
manish.sha |
632 |
document.add(headerTable);
|
|
|
633 |
document.add(packagingTable);
|
| 18876 |
manish.sha |
634 |
document.add(signTable);
|
| 18875 |
manish.sha |
635 |
}
|
|
|
636 |
|
|
|
637 |
}
|
|
|
638 |
|
| 7014 |
rajveer |
639 |
document.close();
|
|
|
640 |
baosPDF.close();
|
|
|
641 |
// Adding facility to store the bill on the local directory. This will happen for only for Mahipalpur warehouse.
|
|
|
642 |
if(withBill && !printAll){
|
| 7079 |
rajveer |
643 |
String strOrderId = StringUtils.repeat("0", 10-String.valueOf(orderId).length()) + orderId;
|
| 7014 |
rajveer |
644 |
String dirPath = "/SaholicInvoices" + File.separator + strOrderId.substring(0, 2) + File.separator + strOrderId.substring(2, 4) + File.separator + strOrderId.substring(4, 6);
|
|
|
645 |
String filename = dirPath + File.separator + orderId + ".pdf";
|
|
|
646 |
File dirFile = new File(dirPath);
|
|
|
647 |
if(!dirFile.exists()){
|
|
|
648 |
dirFile.mkdirs();
|
|
|
649 |
}
|
|
|
650 |
File f = new File(filename);
|
|
|
651 |
FileOutputStream fos = new FileOutputStream(f);
|
|
|
652 |
baosPDF.writeTo(fos);
|
|
|
653 |
}
|
|
|
654 |
} catch (Exception e) {
|
|
|
655 |
logger.error("Error while generating Invoice: ", e);
|
|
|
656 |
}
|
|
|
657 |
return baosPDF;
|
|
|
658 |
}
|
| 18875 |
manish.sha |
659 |
|
|
|
660 |
|
|
|
661 |
private PdfPTable getPackagingInfoTable(List<Order> orderList) throws CatalogServiceException, TException{
|
|
|
662 |
PdfPTable packagingTable = new PdfPTable(new float[]{0.05f, 0.1f, 0.1f, 0.2f, 0.3f, 0.05f, 0.05f, 0.05f, 0.05f});
|
| 18876 |
manish.sha |
663 |
packagingTable.setSplitLate(false);
|
| 18875 |
manish.sha |
664 |
packagingTable.addCell(new Phrase("Item Id", helveticaBold8));
|
|
|
665 |
packagingTable.addCell(new Phrase("BIN Id", helveticaBold8));
|
|
|
666 |
packagingTable.addCell(new Phrase("Sub Order Id", helveticaBold8));
|
|
|
667 |
packagingTable.addCell(new Phrase("Item Description", helveticaBold8));
|
|
|
668 |
packagingTable.addCell(new Phrase("Serial Numbers", helveticaBold8));
|
|
|
669 |
packagingTable.addCell(new Phrase("Pack Size", helveticaBold8));
|
|
|
670 |
packagingTable.addCell(new Phrase("Quantity", helveticaBold8));
|
|
|
671 |
packagingTable.addCell(new Phrase("Total Pieces", helveticaBold8));
|
|
|
672 |
packagingTable.addCell(new Phrase("Unit Price", helveticaBold8));
|
|
|
673 |
|
|
|
674 |
Map<Long, Item> itemMap = new HashMap<Long, Item>();
|
|
|
675 |
|
|
|
676 |
CatalogService.Client catalogClient = ctsc.getClient();
|
|
|
677 |
for(Order order:orderList){
|
|
|
678 |
if(!itemMap.containsKey(order.getLineitems().get(0).getItem_id())){
|
|
|
679 |
itemMap.put(order.getLineitems().get(0).getItem_id(), catalogClient.getItem(order.getLineitems().get(0).getItem_id()));
|
|
|
680 |
}
|
|
|
681 |
}
|
|
|
682 |
|
|
|
683 |
for(Order order:orderList){
|
|
|
684 |
packagingTable.addCell(new Phrase(order.getLineitems().get(0).getItem_id()+"", helvetica8));
|
|
|
685 |
packagingTable.addCell(new Phrase("", helveticaBold8));
|
|
|
686 |
packagingTable.addCell(new Phrase(order.getId()+"", helvetica8));
|
|
|
687 |
packagingTable.addCell(new Phrase(getItemDisplayName(order.getLineitems().get(0), false), helvetica8));
|
|
|
688 |
if(order.getLineitems().get(0).isSetSerial_number()){
|
|
|
689 |
packagingTable.addCell(new Phrase(order.getLineitems().get(0).getSerial_number(), helvetica8));
|
|
|
690 |
}else{
|
|
|
691 |
packagingTable.addCell(new Phrase("", helvetica8));
|
|
|
692 |
}
|
|
|
693 |
packagingTable.addCell(new Phrase(itemMap.get(order.getLineitems().get(0).getItem_id()).getPackQuantity()+"", helvetica8));
|
|
|
694 |
packagingTable.addCell(new Phrase(order.getLineitems().get(0).getQuantity()+"", helvetica8));
|
|
|
695 |
packagingTable.addCell(new Phrase((order.getLineitems().get(0).getQuantity()*itemMap.get(order.getLineitems().get(0).getItem_id()).getPackQuantity())+"", helvetica8));
|
|
|
696 |
packagingTable.addCell(new Phrase(order.getLineitems().get(0).getUnit_price()+"", helvetica8));
|
|
|
697 |
}
|
|
|
698 |
return packagingTable;
|
|
|
699 |
}
|
| 3065 |
chandransh |
700 |
|
| 13276 |
manish.sha |
701 |
private PdfPTable getDispatchAdviceTable(List<Order> orderList, Warehouse warehouse, Provider provider, float barcodeFontSize, String destCode, boolean withBill, Warehouse shippingLocation, String invoiceFormat){
|
|
|
702 |
Order order = orderList.get(0);
|
| 7014 |
rajveer |
703 |
Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
|
| 13276 |
manish.sha |
704 |
|
|
|
705 |
double totalAmount = 0.0;
|
|
|
706 |
double totalWeight = 0.0;
|
|
|
707 |
|
|
|
708 |
for (Order o: orderList){
|
| 17470 |
manish.sha |
709 |
totalAmount = totalAmount + o.getTotal_amount() +o.getShippingCost()-o.getGvAmount()-o.getAdvanceAmount();
|
| 13276 |
manish.sha |
710 |
totalWeight = totalWeight + o.getTotal_weight();
|
|
|
711 |
}
|
| 2787 |
chandransh |
712 |
|
| 7014 |
rajveer |
713 |
PdfPTable table = new PdfPTable(1);
|
| 18847 |
manish.sha |
714 |
table.setSplitLate(false);
|
| 7014 |
rajveer |
715 |
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 8106 |
manish.sha |
716 |
|
|
|
717 |
PdfPTable titleBarTable = new PdfPTable(new float[]{0.4f, 0.4f, 0.2f});
|
| 8107 |
manish.sha |
718 |
titleBarTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 8106 |
manish.sha |
719 |
|
| 8103 |
manish.sha |
720 |
PdfPTable logoTable = new PdfPTable(2);
|
|
|
721 |
addLogoTable(logoTable,order);
|
| 7318 |
rajveer |
722 |
|
| 7014 |
rajveer |
723 |
PdfPCell titleCell = getTitleCell();
|
| 18530 |
manish.sha |
724 |
PdfPTable customerTable = getCustomerAddressTable(order, destCode, false, helvetica12, false, false);
|
| 13276 |
manish.sha |
725 |
PdfPTable providerInfoTable = getProviderTable(order, provider, barCodeFont, totalWeight);
|
| 2787 |
chandransh |
726 |
|
| 7014 |
rajveer |
727 |
PdfPTable dispatchTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
|
|
728 |
dispatchTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
729 |
dispatchTable.addCell(customerTable);
|
|
|
730 |
dispatchTable.addCell(new Phrase(" "));
|
|
|
731 |
dispatchTable.addCell(providerInfoTable);
|
| 2787 |
chandransh |
732 |
|
| 13276 |
manish.sha |
733 |
PdfPTable invoiceTable = getTopInvoiceTable(orderList, shippingLocation.getTinNumber(), invoiceFormat);
|
| 8110 |
manish.sha |
734 |
PdfPTable addressTable = new PdfPTable(1);
|
|
|
735 |
addressTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
736 |
addressTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
737 |
|
| 7014 |
rajveer |
738 |
PdfPCell addressCell = getAddressCell(shippingLocation.getLocation() +
|
| 17203 |
manish.sha |
739 |
" - " + shippingLocation.getPincode() + "\nContact No.- +91-9811247808" + "\n\n");
|
| 2787 |
chandransh |
740 |
|
| 7014 |
rajveer |
741 |
PdfPTable chargesTable = new PdfPTable(1);
|
|
|
742 |
chargesTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
743 |
chargesTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
744 |
if(order.isLogisticsCod()){
|
| 13276 |
manish.sha |
745 |
chargesTable.addCell(new Phrase("AMOUNT TO BE COLLECTED : Rs " + (totalAmount), helveticaBold12));
|
| 7014 |
rajveer |
746 |
chargesTable.addCell(new Phrase("RTO ADDRESS:DEL/HPW/111116"));
|
| 7994 |
manish.sha |
747 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
748 |
if(order.getLogistics_provider_id()==7L){
|
|
|
749 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
750 |
String fedexCodReturnBarcode = "";
|
| 8080 |
manish.sha |
751 |
String fedexCodReturnTrackingId = "";
|
| 7994 |
manish.sha |
752 |
try {
|
|
|
753 |
fedexCodReturnBarcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_COD_Return_BarCode");
|
| 8080 |
manish.sha |
754 |
fedexCodReturnTrackingId = tclient.getOrderAttributeValue(order.getId(), "FedEx_COD_Return_Tracking_No");
|
| 7994 |
manish.sha |
755 |
} catch (TException e1) {
|
|
|
756 |
logger.error("Error while getting the provider information.", e1);
|
|
|
757 |
}
|
| 8080 |
manish.sha |
758 |
PdfPCell formIdCell= new PdfPCell(new Paragraph("COD Return "+fedexCodReturnTrackingId+" Form id-0325", helvetica6));
|
| 8104 |
manish.sha |
759 |
formIdCell.setPaddingTop(2.0f);
|
| 7994 |
manish.sha |
760 |
formIdCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
761 |
formIdCell.setBorder(Rectangle.NO_BORDER);
|
|
|
762 |
chargesTable.addCell(new Phrase("PRIORITY OVERNIGHT ", helvetica8));
|
|
|
763 |
chargesTable.addCell(formIdCell);
|
| 8035 |
manish.sha |
764 |
|
| 8067 |
manish.sha |
765 |
generateBarcode(fedexCodReturnBarcode, "fedex_codr_"+order.getId());
|
| 8037 |
manish.sha |
766 |
|
| 8067 |
manish.sha |
767 |
Image barcodeImage=null;
|
|
|
768 |
try {
|
|
|
769 |
barcodeImage = Image.getInstance("/tmp/"+"fedex_codr_"+order.getId()+".png");
|
|
|
770 |
} catch (Exception e) {
|
|
|
771 |
logger.error("Exception during getting Barcode Image for Fedex : ", e);
|
|
|
772 |
}
|
|
|
773 |
|
| 8173 |
manish.sha |
774 |
PdfPTable codReturnTable = new PdfPTable(new float[]{0.6f,0.4f});
|
|
|
775 |
codReturnTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
776 |
codReturnTable.addCell(barcodeImage);
|
|
|
777 |
codReturnTable.addCell(new Phrase(" "));
|
|
|
778 |
chargesTable.addCell(codReturnTable);
|
|
|
779 |
|
| 7994 |
manish.sha |
780 |
}
|
|
|
781 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
782 |
} else {
|
|
|
783 |
chargesTable.addCell(new Phrase("Do not pay any extra charges to the Courier."));
|
|
|
784 |
}
|
| 8080 |
manish.sha |
785 |
|
|
|
786 |
if(order.getLogistics_provider_id()==7L){
|
|
|
787 |
chargesTable.addCell(new Phrase("Term and Condition:- Subject to the Conditions of Carriage which " +
|
|
|
788 |
"limits the liability of FedEx for loss, delay or damage to the consignment." +
|
|
|
789 |
" Visit http://www.fedex.com/in/domestic/services/terms to view the conitions of Carriage" ,
|
| 8082 |
manish.sha |
790 |
new Font(FontFamily.TIMES_ROMAN, 8f)));
|
| 8080 |
manish.sha |
791 |
}
|
| 10310 |
amar.kumar |
792 |
|
| 8110 |
manish.sha |
793 |
addressTable.addCell(new Phrase("If undelivered, return to:", helvetica10));
|
|
|
794 |
addressTable.addCell(addressCell);
|
|
|
795 |
|
| 7014 |
rajveer |
796 |
PdfPTable addressAndNoteTable = new PdfPTable(new float[]{0.3f, 0.7f});
|
|
|
797 |
addressAndNoteTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 8110 |
manish.sha |
798 |
addressAndNoteTable.addCell(addressTable);
|
| 7014 |
rajveer |
799 |
addressAndNoteTable.addCell(chargesTable);
|
| 2787 |
chandransh |
800 |
|
| 8106 |
manish.sha |
801 |
titleBarTable.addCell(logoTable);
|
|
|
802 |
titleBarTable.addCell(titleCell);
|
|
|
803 |
titleBarTable.addCell(" ");
|
|
|
804 |
|
|
|
805 |
table.addCell(titleBarTable);
|
| 7014 |
rajveer |
806 |
table.addCell(dispatchTable);
|
|
|
807 |
table.addCell(invoiceTable);
|
|
|
808 |
table.addCell(addressAndNoteTable);
|
|
|
809 |
return table;
|
|
|
810 |
}
|
| 2787 |
chandransh |
811 |
|
| 8103 |
manish.sha |
812 |
private void addLogoTable(PdfPTable logoTable,Order order) {
|
| 7318 |
rajveer |
813 |
logoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
814 |
logoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
815 |
logoTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM);
|
| 8096 |
manish.sha |
816 |
|
| 7318 |
rajveer |
817 |
PdfPCell logoCell;
|
|
|
818 |
String logoPath;
|
| 8102 |
manish.sha |
819 |
|
| 7556 |
rajveer |
820 |
if(order.getSource() == OrderSource.STORE.getValue()){
|
|
|
821 |
logoCell = new PdfPCell(new Phrase(""));
|
|
|
822 |
|
|
|
823 |
}else{
|
| 8102 |
manish.sha |
824 |
logoPath = InvoiceGenerationService.class.getResource("/logo.jpg").getPath();
|
| 8094 |
manish.sha |
825 |
|
| 7318 |
rajveer |
826 |
try {
|
|
|
827 |
logoCell = new PdfPCell(Image.getInstance(logoPath), false);
|
|
|
828 |
} catch (Exception e) {
|
|
|
829 |
//Too Many exceptions to catch here: BadElementException, MalformedURLException and IOException
|
|
|
830 |
logger.warn("Couldn't load the Saholic logo: ", e);
|
|
|
831 |
logoCell = new PdfPCell(new Phrase("Saholic Logo"));
|
|
|
832 |
}
|
|
|
833 |
|
|
|
834 |
}
|
| 8090 |
manish.sha |
835 |
logoCell.setBorder(Rectangle.NO_BORDER);
|
|
|
836 |
logoCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 8102 |
manish.sha |
837 |
logoTable.addCell(logoCell);
|
|
|
838 |
logoTable.addCell(" ");
|
| 8103 |
manish.sha |
839 |
|
| 7318 |
rajveer |
840 |
}
|
|
|
841 |
|
| 7014 |
rajveer |
842 |
private Font getBarCodeFont(Provider provider, float barcodeFontSize) {
|
|
|
843 |
String fontPath = InvoiceGenerationService.class.getResource("/" + provider.getName().toLowerCase() + "/barcode.TTF").getPath();
|
|
|
844 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
845 |
ttfFontFactory.register(fontPath, "barcode");
|
|
|
846 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
|
|
847 |
return barCodeFont;
|
|
|
848 |
}
|
| 2787 |
chandransh |
849 |
|
| 7014 |
rajveer |
850 |
private PdfPCell getTitleCell() {
|
|
|
851 |
PdfPCell titleCell = new PdfPCell(new Phrase("Dispatch Advice", helveticaBold12));
|
|
|
852 |
titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
853 |
titleCell.setBorder(Rectangle.NO_BORDER);
|
|
|
854 |
return titleCell;
|
|
|
855 |
}
|
| 2787 |
chandransh |
856 |
|
| 13276 |
manish.sha |
857 |
private PdfPTable getProviderTable(Order order, Provider provider, Font barCodeFont, double totalWeight) {
|
| 7014 |
rajveer |
858 |
PdfPTable providerInfoTable = new PdfPTable(1);
|
|
|
859 |
providerInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 7318 |
rajveer |
860 |
if(order.isLogisticsCod()){
|
| 8551 |
manish.sha |
861 |
PdfPCell deliveryTypeCell = new PdfPCell(new Phrase("COD ", helvetica22));
|
| 7318 |
rajveer |
862 |
deliveryTypeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
863 |
deliveryTypeCell.setBorder(Rectangle.NO_BORDER);
|
|
|
864 |
providerInfoTable.addCell(deliveryTypeCell);
|
|
|
865 |
}
|
|
|
866 |
|
| 8035 |
manish.sha |
867 |
|
| 7014 |
rajveer |
868 |
PdfPCell providerNameCell = new PdfPCell(new Phrase(provider.getName(), helveticaBold12));
|
|
|
869 |
providerNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
870 |
providerNameCell.setBorder(Rectangle.NO_BORDER);
|
| 7994 |
manish.sha |
871 |
PdfPCell formIdCell= null;
|
|
|
872 |
if(order.getLogistics_provider_id()==7L){
|
|
|
873 |
if(order.isCod()){
|
| 8034 |
manish.sha |
874 |
formIdCell = new PdfPCell(new Paragraph(order.getAirwaybill_no()+" Form id-0305", helvetica6));
|
| 7994 |
manish.sha |
875 |
}
|
|
|
876 |
else{
|
| 8034 |
manish.sha |
877 |
formIdCell = new PdfPCell(new Paragraph(order.getAirwaybill_no()+" Form id-0467", helvetica6));
|
| 7994 |
manish.sha |
878 |
}
|
| 8551 |
manish.sha |
879 |
formIdCell.setPaddingTop(1.0f);
|
| 8015 |
rajveer |
880 |
formIdCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
881 |
formIdCell.setBorder(Rectangle.NO_BORDER);
|
| 7994 |
manish.sha |
882 |
}
|
| 8015 |
rajveer |
883 |
|
| 7994 |
manish.sha |
884 |
|
|
|
885 |
PdfPCell awbNumberCell= null;
|
| 8034 |
manish.sha |
886 |
String fedexPackageBarcode = "";
|
| 7994 |
manish.sha |
887 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
888 |
awbNumberCell = new PdfPCell(new Paragraph("*" + order.getAirwaybill_no() + "*", barCodeFont));
|
| 8017 |
manish.sha |
889 |
awbNumberCell.setPaddingTop(20.0f);
|
| 7994 |
manish.sha |
890 |
}
|
|
|
891 |
else{
|
| 8013 |
rajveer |
892 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
893 |
try {
|
|
|
894 |
fedexPackageBarcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_Package_BarCode");
|
|
|
895 |
} catch (TException e1) {
|
|
|
896 |
logger.error("Error while getting the provider information.", e1);
|
|
|
897 |
}
|
| 8174 |
manish.sha |
898 |
awbNumberCell = new PdfPCell(new Paragraph(" ", helvetica6));
|
|
|
899 |
}
|
|
|
900 |
awbNumberCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
901 |
awbNumberCell.setBorder(Rectangle.NO_BORDER);
|
|
|
902 |
|
|
|
903 |
providerInfoTable.addCell(providerNameCell);
|
|
|
904 |
if(formIdCell != null){
|
|
|
905 |
providerInfoTable.addCell(formIdCell);
|
|
|
906 |
}
|
|
|
907 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
908 |
if(order.getLogistics_provider_id()==7L){
|
| 8169 |
manish.sha |
909 |
generateBarcode(fedexPackageBarcode, "fedex_"+order.getId());
|
|
|
910 |
|
|
|
911 |
Image barcodeImage=null;
|
|
|
912 |
try {
|
|
|
913 |
barcodeImage = Image.getInstance("/tmp/"+"fedex_"+order.getId()+".png");
|
|
|
914 |
} catch (Exception e) {
|
|
|
915 |
logger.error("Exception during getting Barcode Image for Fedex : ", e);
|
|
|
916 |
}
|
| 8174 |
manish.sha |
917 |
providerInfoTable.addCell(barcodeImage);
|
| 7994 |
manish.sha |
918 |
}
|
| 8174 |
manish.sha |
919 |
providerInfoTable.addCell(awbNumberCell);
|
| 7014 |
rajveer |
920 |
|
| 7792 |
anupam.sin |
921 |
Warehouse warehouse = null;
|
|
|
922 |
try{
|
|
|
923 |
InventoryClient isc = new InventoryClient();
|
| 7804 |
amar.kumar |
924 |
warehouse = isc.getClient().getWarehouse(order.getWarehouse_id());
|
| 7803 |
amar.kumar |
925 |
} catch(Exception e) {
|
| 7792 |
anupam.sin |
926 |
logger.error("Unable to get warehouse for id : " + order.getWarehouse_id(), e);
|
| 7805 |
amar.kumar |
927 |
//TODO throw e;
|
| 7792 |
anupam.sin |
928 |
}
|
|
|
929 |
DeliveryType dt = DeliveryType.PREPAID;
|
|
|
930 |
if (order.isLogisticsCod()) {
|
|
|
931 |
dt = DeliveryType.COD;
|
|
|
932 |
}
|
| 7994 |
manish.sha |
933 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
934 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
935 |
for (ProviderDetails detail : provider.getDetails()) {
|
|
|
936 |
if(in.shop2020.model.v1.inventory.WarehouseLocation.findByValue((int) detail.getLogisticLocation()) == warehouse.getLogisticsLocation() && detail.getDeliveryType() == dt) {
|
|
|
937 |
providerInfoTable.addCell(new Phrase("Account No : " + detail.getAccountNo(), helvetica8));
|
|
|
938 |
}
|
|
|
939 |
}
|
| 7792 |
anupam.sin |
940 |
}
|
| 7994 |
manish.sha |
941 |
else{
|
|
|
942 |
providerInfoTable.addCell(new Phrase("STANDARD OVERNIGHT ", helvetica8));
|
|
|
943 |
}
|
|
|
944 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
945 |
Date awbDate;
|
|
|
946 |
if(order.getBilling_timestamp() == 0){
|
|
|
947 |
awbDate = new Date();
|
|
|
948 |
}else{
|
|
|
949 |
awbDate = new Date(order.getBilling_timestamp());
|
|
|
950 |
}
|
| 8106 |
manish.sha |
951 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
952 |
providerInfoTable.addCell(new Phrase("AWB Date : " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(awbDate), helvetica8));
|
|
|
953 |
}
|
| 13322 |
manish.sha |
954 |
providerInfoTable.addCell(new Phrase("Weight : " + totalWeight + " Kg", helvetica8));
|
| 8182 |
amar.kumar |
955 |
if(order.getSource() == OrderSource.EBAY.getValue()){
|
|
|
956 |
EbayOrder ebayOrder = null;
|
|
|
957 |
try {
|
|
|
958 |
ebayOrder = tsc.getClient().getEbayOrderByOrderId(order.getId());
|
|
|
959 |
} catch (TException e) {
|
|
|
960 |
logger.error("Error while getting ebay order", e);
|
|
|
961 |
}
|
|
|
962 |
providerInfoTable.addCell(new Phrase("PaisaPayId : " + ebayOrder.getPaisaPayId(), helvetica8));
|
|
|
963 |
providerInfoTable.addCell(new Phrase("Sales Rec Number: " + ebayOrder.getSalesRecordNumber(), helvetica8));
|
|
|
964 |
}
|
| 7994 |
manish.sha |
965 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
966 |
if(order.getLogistics_provider_id()==7L){
|
|
|
967 |
providerInfoTable.addCell(new Phrase("Bill T/C Sender "+ "Bill D/T Sender", helvetica8));
|
|
|
968 |
}
|
|
|
969 |
//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| 7014 |
rajveer |
970 |
return providerInfoTable;
|
|
|
971 |
}
|
|
|
972 |
|
| 13276 |
manish.sha |
973 |
private PdfPTable getTopInvoiceTable(List<Order> orderList, String tinNo, String invoiceFormat){
|
| 7014 |
rajveer |
974 |
PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.2f, 0.3f, 0.1f, 0.1f, 0.1f});
|
|
|
975 |
invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
976 |
|
| 13276 |
manish.sha |
977 |
invoiceTable.addCell(getInvoiceTableHeader(6,orderList.get(0).getLogisticsTransactionId()));
|
|
|
978 |
if("Bulk".equalsIgnoreCase(invoiceFormat)){
|
|
|
979 |
invoiceTable.addCell(new Phrase("Sr No", helvetica8));
|
|
|
980 |
}else{
|
|
|
981 |
invoiceTable.addCell(new Phrase("Order No", helvetica8));
|
|
|
982 |
}
|
| 7014 |
rajveer |
983 |
invoiceTable.addCell(new Phrase("Paymode", helvetica8));
|
|
|
984 |
invoiceTable.addCell(new Phrase("Product Name", helvetica8));
|
|
|
985 |
invoiceTable.addCell(new Phrase("Quantity", helvetica8));
|
|
|
986 |
invoiceTable.addCell(new Phrase("Rate", helvetica8));
|
|
|
987 |
invoiceTable.addCell(new Phrase("Amount", helvetica8));
|
| 13276 |
manish.sha |
988 |
double totalAmount = 0.0;
|
| 17470 |
manish.sha |
989 |
double totalShippingCost = 0.0;
|
| 13276 |
manish.sha |
990 |
double insuranceAmount = 0.0;
|
|
|
991 |
double advanceAmount = 0.0;
|
|
|
992 |
|
|
|
993 |
|
|
|
994 |
if("Bulk".equalsIgnoreCase(invoiceFormat)){
|
|
|
995 |
Map<Long, String> itemNamesMap= new HashMap<Long, String>();
|
|
|
996 |
Map<Long, Double> itemQuantityMap = new HashMap<Long, Double>();
|
|
|
997 |
Map<Long, Double> itemRateMap = new HashMap<Long, Double>();
|
|
|
998 |
Map<Long, Double> itemTotalAmtMap = new HashMap<Long, Double>();
|
|
|
999 |
String paymentMode = "";
|
|
|
1000 |
for(Order order : orderList){
|
|
|
1001 |
LineItem lineitem = order.getLineitems().get(0);
|
| 13496 |
manish.sha |
1002 |
totalAmount = totalAmount + order.getTotal_amount()-order.getAdvanceAmount();
|
| 17470 |
manish.sha |
1003 |
totalShippingCost = totalShippingCost + order.getShippingCost();
|
| 13276 |
manish.sha |
1004 |
if(order.getInsurer() > 0) {
|
|
|
1005 |
insuranceAmount =insuranceAmount + order.getInsuranceAmount();
|
|
|
1006 |
}
|
|
|
1007 |
if(order.getSource() == OrderSource.STORE.getValue()) {
|
|
|
1008 |
advanceAmount = advanceAmount + order.getAdvanceAmount();
|
|
|
1009 |
}
|
|
|
1010 |
if(!itemNamesMap.containsKey(lineitem.getItem_id())){
|
|
|
1011 |
itemNamesMap.put(lineitem.getItem_id(), getItemDisplayName(lineitem, false));
|
|
|
1012 |
}
|
|
|
1013 |
if(!itemRateMap.containsKey(lineitem.getItem_id())){
|
|
|
1014 |
itemRateMap.put(lineitem.getItem_id(), lineitem.getUnit_price());
|
|
|
1015 |
}
|
|
|
1016 |
if(itemQuantityMap.containsKey(lineitem.getItem_id())){
|
|
|
1017 |
double currentQuantity = itemQuantityMap.get(lineitem.getItem_id()) +lineitem.getQuantity();
|
|
|
1018 |
itemQuantityMap.put(lineitem.getItem_id(), currentQuantity);
|
|
|
1019 |
}else{
|
|
|
1020 |
itemQuantityMap.put(lineitem.getItem_id(), lineitem.getQuantity());
|
|
|
1021 |
}
|
|
|
1022 |
|
|
|
1023 |
if(itemTotalAmtMap.containsKey(lineitem.getItem_id())){
|
| 13492 |
manish.sha |
1024 |
double totalItemAmount = itemTotalAmtMap.get(lineitem.getItem_id()) + (order.getTotal_amount()-order.getAdvanceAmount()-order.getInsuranceAmount());
|
| 13276 |
manish.sha |
1025 |
itemTotalAmtMap.put(lineitem.getItem_id(), totalItemAmount);
|
|
|
1026 |
}else{
|
| 13492 |
manish.sha |
1027 |
itemTotalAmtMap.put(lineitem.getItem_id(), (order.getTotal_amount()-order.getAdvanceAmount()-order.getInsuranceAmount()));
|
| 13276 |
manish.sha |
1028 |
}
|
|
|
1029 |
if(paymentMode==null || paymentMode.isEmpty()){
|
|
|
1030 |
if(order.getPickupStoreId() > 0 && order.isCod() == true)
|
|
|
1031 |
paymentMode = "In-Store";
|
|
|
1032 |
else if (order.isCod())
|
|
|
1033 |
paymentMode = "COD";
|
|
|
1034 |
else
|
|
|
1035 |
paymentMode = "Prepaid";
|
|
|
1036 |
}
|
|
|
1037 |
}
|
|
|
1038 |
|
|
|
1039 |
int serialNo = 0;
|
|
|
1040 |
for(Long itemId : itemNamesMap.keySet()){
|
|
|
1041 |
serialNo ++;
|
|
|
1042 |
invoiceTable.addCell(new Phrase(serialNo+ "", helvetica8));
|
|
|
1043 |
invoiceTable.addCell(new Phrase(paymentMode, helvetica8));
|
|
|
1044 |
invoiceTable.addCell(new Phrase(itemNamesMap.get(itemId), helvetica8));
|
|
|
1045 |
invoiceTable.addCell(new Phrase(itemQuantityMap.get(itemId)+"", helvetica8));
|
|
|
1046 |
invoiceTable.addCell(new Phrase(itemRateMap.get(itemId)+"", helvetica8));
|
|
|
1047 |
invoiceTable.addCell(new Phrase(itemTotalAmtMap.get(itemId)+"", helvetica8));
|
|
|
1048 |
}
|
|
|
1049 |
|
|
|
1050 |
if(insuranceAmount>0){
|
|
|
1051 |
invoiceTable.addCell(getInsuranceCell(4));
|
|
|
1052 |
invoiceTable.addCell(getPriceCell(insuranceAmount));
|
|
|
1053 |
invoiceTable.addCell(getPriceCell(insuranceAmount));
|
|
|
1054 |
}
|
|
|
1055 |
if(advanceAmount>0){
|
|
|
1056 |
invoiceTable.addCell(getAdvanceAmountCell(4));
|
|
|
1057 |
invoiceTable.addCell(getPriceCell(advanceAmount));
|
|
|
1058 |
invoiceTable.addCell(getPriceCell(advanceAmount));
|
|
|
1059 |
}
|
|
|
1060 |
}else{
|
|
|
1061 |
for(Order order : orderList){
|
|
|
1062 |
populateTopInvoiceTable(order, invoiceTable);
|
|
|
1063 |
if(order.getInsurer() > 0) {
|
|
|
1064 |
invoiceTable.addCell(getInsuranceCell(4));
|
|
|
1065 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
|
|
1066 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
|
|
1067 |
}
|
| 7014 |
rajveer |
1068 |
|
| 13276 |
manish.sha |
1069 |
if(order.getSource() == OrderSource.STORE.getValue()) {
|
|
|
1070 |
invoiceTable.addCell(getAdvanceAmountCell(4));
|
|
|
1071 |
invoiceTable.addCell(getPriceCell(order.getAdvanceAmount()));
|
|
|
1072 |
invoiceTable.addCell(getPriceCell(order.getAdvanceAmount()));
|
|
|
1073 |
}
|
| 13494 |
manish.sha |
1074 |
totalAmount = totalAmount + order.getTotal_amount()-order.getAdvanceAmount();
|
| 17470 |
manish.sha |
1075 |
totalShippingCost = totalShippingCost + order.getShippingCost();
|
| 13276 |
manish.sha |
1076 |
}
|
| 7014 |
rajveer |
1077 |
}
|
| 17470 |
manish.sha |
1078 |
if(totalShippingCost>0){
|
|
|
1079 |
invoiceTable.addCell(getShippingCostCell(4));
|
| 17501 |
manish.sha |
1080 |
invoiceTable.addCell(getRupeesCell(false));
|
|
|
1081 |
invoiceTable.addCell(getPriceCell(totalShippingCost));
|
| 17470 |
manish.sha |
1082 |
}
|
| 7014 |
rajveer |
1083 |
invoiceTable.addCell(getTotalCell(4));
|
| 17501 |
manish.sha |
1084 |
invoiceTable.addCell(getRupeesCell(true));
|
| 17470 |
manish.sha |
1085 |
invoiceTable.addCell(getTotalAmountCell(totalAmount+totalShippingCost));
|
| 13276 |
manish.sha |
1086 |
|
| 7014 |
rajveer |
1087 |
|
|
|
1088 |
PdfPCell tinCell = new PdfPCell(new Phrase("TIN NO. " + tinNo, helvetica8));
|
|
|
1089 |
tinCell.setColspan(6);
|
|
|
1090 |
tinCell.setPadding(2);
|
|
|
1091 |
invoiceTable.addCell(tinCell);
|
|
|
1092 |
|
|
|
1093 |
return invoiceTable;
|
|
|
1094 |
}
|
|
|
1095 |
|
|
|
1096 |
private void populateTopInvoiceTable(Order order, PdfPTable invoiceTable) {
|
|
|
1097 |
List<LineItem> lineitems = order.getLineitems();
|
|
|
1098 |
for (LineItem lineitem : lineitems) {
|
|
|
1099 |
invoiceTable.addCell(new Phrase(order.getId() + "", helvetica8));
|
|
|
1100 |
if(order.getPickupStoreId() > 0 && order.isCod() == true)
|
|
|
1101 |
invoiceTable.addCell(new Phrase("In-Store", helvetica8));
|
|
|
1102 |
else if (order.isCod())
|
|
|
1103 |
invoiceTable.addCell(new Phrase("COD", helvetica8));
|
|
|
1104 |
else
|
|
|
1105 |
invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
|
| 7318 |
rajveer |
1106 |
|
| 7190 |
amar.kumar |
1107 |
invoiceTable.addCell(getProductNameCell(lineitem, false, order.getFreebieItemId()));
|
| 2787 |
chandransh |
1108 |
|
| 7014 |
rajveer |
1109 |
invoiceTable.addCell(new Phrase(lineitem.getQuantity() + "", helvetica8));
|
| 2787 |
chandransh |
1110 |
|
| 7014 |
rajveer |
1111 |
invoiceTable.addCell(getPriceCell(lineitem.getUnit_price()-order.getGvAmount()));
|
|
|
1112 |
|
|
|
1113 |
invoiceTable.addCell(getPriceCell(lineitem.getTotal_price()-order.getGvAmount()));
|
|
|
1114 |
}
|
|
|
1115 |
}
|
|
|
1116 |
|
|
|
1117 |
private PdfPCell getAddressCell(String address) {
|
|
|
1118 |
Paragraph addressParagraph = new Paragraph(address, new Font(FontFamily.TIMES_ROMAN, 8f));
|
|
|
1119 |
PdfPCell addressCell = new PdfPCell();
|
|
|
1120 |
addressCell.addElement(addressParagraph);
|
|
|
1121 |
addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
1122 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1123 |
return addressCell;
|
|
|
1124 |
}
|
|
|
1125 |
|
| 13276 |
manish.sha |
1126 |
private PdfPTable getTaxCumRetailInvoiceTable(List<Order> orderList, Provider provider, String ourAddress, String tinNo, String invoiceFormat){
|
|
|
1127 |
Order order = orderList.get(0);
|
| 7014 |
rajveer |
1128 |
PdfPTable taxTable = new PdfPTable(1);
|
|
|
1129 |
Phrase phrase = null;
|
| 18847 |
manish.sha |
1130 |
taxTable.setSplitLate(false);
|
| 7014 |
rajveer |
1131 |
taxTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
1132 |
taxTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 8104 |
manish.sha |
1133 |
|
| 8110 |
manish.sha |
1134 |
PdfPTable logoTitleAndOurAddressTable = new PdfPTable(new float[]{0.4f, 0.3f, 0.3f});
|
| 8107 |
manish.sha |
1135 |
logoTitleAndOurAddressTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 8112 |
manish.sha |
1136 |
logoTitleAndOurAddressTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 8107 |
manish.sha |
1137 |
|
| 8110 |
manish.sha |
1138 |
|
| 8103 |
manish.sha |
1139 |
PdfPTable logoTable = new PdfPTable(2);
|
|
|
1140 |
addLogoTable(logoTable,order);
|
| 7318 |
rajveer |
1141 |
|
| 7014 |
rajveer |
1142 |
|
| 17203 |
manish.sha |
1143 |
Paragraph sorlAddress = new Paragraph(ourAddress + "\n Contact No.- +91-9811247808" + "\nTIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f, Element.ALIGN_CENTER));
|
| 7014 |
rajveer |
1144 |
PdfPCell sorlAddressCell = new PdfPCell(sorlAddress);
|
|
|
1145 |
sorlAddressCell.addElement(sorlAddress);
|
| 8110 |
manish.sha |
1146 |
sorlAddressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 7014 |
rajveer |
1147 |
|
| 18769 |
manish.sha |
1148 |
PdfPTable customerAddress = getCustomerAddressTable(order, null, true, helvetica8, true, false);
|
| 18657 |
manish.sha |
1149 |
if (order.getOrderType().equals(OrderType.B2B)) {
|
|
|
1150 |
if(billingAddress!=null){
|
|
|
1151 |
if(order.getCustomer_state().trim().equalsIgnoreCase(billingAddress.getState())){
|
|
|
1152 |
phrase = new Phrase("TAX INVOICE", helveticaBold12);
|
|
|
1153 |
}else{
|
|
|
1154 |
phrase = new Phrase("RETAIL INVOICE", helveticaBold12);
|
|
|
1155 |
}
|
|
|
1156 |
}else{
|
|
|
1157 |
phrase = new Phrase("TAX INVOICE", helveticaBold12);
|
|
|
1158 |
}
|
|
|
1159 |
} else {
|
|
|
1160 |
phrase = new Phrase("RETAIL INVOICE", helveticaBold12);
|
|
|
1161 |
}
|
| 18693 |
manish.sha |
1162 |
|
|
|
1163 |
PdfPCell retailInvoiceTitleCell = new PdfPCell(phrase);
|
|
|
1164 |
retailInvoiceTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
1165 |
retailInvoiceTitleCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1166 |
|
| 7014 |
rajveer |
1167 |
PdfPTable orderDetails = getOrderDetails(order, provider);
|
|
|
1168 |
|
|
|
1169 |
PdfPTable addrAndOrderDetailsTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
|
|
1170 |
addrAndOrderDetailsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
1171 |
addrAndOrderDetailsTable.addCell(customerAddress);
|
|
|
1172 |
addrAndOrderDetailsTable.addCell(new Phrase(" "));
|
|
|
1173 |
addrAndOrderDetailsTable.addCell(orderDetails);
|
|
|
1174 |
|
| 9319 |
amar.kumar |
1175 |
boolean isVAT = isVatApplicable(order);
|
| 13276 |
manish.sha |
1176 |
PdfPTable invoiceTable = getBottomInvoiceTable(orderList, isVAT, invoiceFormat);
|
| 7014 |
rajveer |
1177 |
|
| 10607 |
manish.sha |
1178 |
PdfPTable regAddAndDisCellTable = new PdfPTable(2);
|
|
|
1179 |
|
| 7014 |
rajveer |
1180 |
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));
|
|
|
1181 |
disclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
1182 |
disclaimerCell.setBorder(Rectangle.NO_BORDER);
|
| 7318 |
rajveer |
1183 |
|
| 17203 |
manish.sha |
1184 |
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. +91-9811247808 E-mail. help@saholic.com Website. www.saholic.com", helvetica6));
|
| 10607 |
manish.sha |
1185 |
regAddressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
1186 |
regAddressCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1187 |
/*SPICE ONLINE RETAIL PRIVATE LIMITED
|
|
|
1188 |
Regd. Add. 60-D, STREET NO. C-5, SAINIK FARMS,NEW DELHI-110062
|
|
|
1189 |
CIN: U74140DL2008PTC183856
|
|
|
1190 |
Tel. No. 0120-2479977
|
|
|
1191 |
E-mail. help@saholic.com
|
|
|
1192 |
Website. www.saholic.com*/
|
| 9014 |
amar.kumar |
1193 |
PdfPCell powerTextCell = new PdfPCell(new Phrase("Powered By Flipkart", helvetica8));
|
|
|
1194 |
powerTextCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
1195 |
powerTextCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1196 |
powerTextCell.setPaddingBottom(30.0f);
|
| 8104 |
manish.sha |
1197 |
|
|
|
1198 |
logoTitleAndOurAddressTable.addCell(logoTable);
|
| 8110 |
manish.sha |
1199 |
logoTitleAndOurAddressTable.addCell(retailInvoiceTitleCell);
|
|
|
1200 |
logoTitleAndOurAddressTable.addCell(sorlAddress);
|
| 8104 |
manish.sha |
1201 |
|
| 10607 |
manish.sha |
1202 |
regAddAndDisCellTable.addCell(disclaimerCell);
|
|
|
1203 |
regAddAndDisCellTable.addCell(regAddressCell);
|
|
|
1204 |
|
| 8104 |
manish.sha |
1205 |
taxTable.addCell(logoTitleAndOurAddressTable);
|
| 7014 |
rajveer |
1206 |
taxTable.addCell(addrAndOrderDetailsTable);
|
|
|
1207 |
taxTable.addCell(invoiceTable);
|
| 10608 |
manish.sha |
1208 |
taxTable.addCell(regAddAndDisCellTable);
|
| 9014 |
amar.kumar |
1209 |
if(order.getSource() == OrderSource.FLIPKART.getValue()) {
|
|
|
1210 |
taxTable.addCell(powerTextCell);
|
|
|
1211 |
|
|
|
1212 |
}
|
| 10320 |
amar.kumar |
1213 |
if(order.getProductCondition().equals(ProductCondition.BAD)){
|
| 10328 |
amar.kumar |
1214 |
PdfPCell badSaleDisclaimerCell = new PdfPCell(new Phrase(" Item(s) above are sold on as is where is basis. They " +
|
| 10320 |
amar.kumar |
1215 |
"may be in dead/defective/damaged/refurbished/incomplete/open condition. These " +
|
|
|
1216 |
"are not returnable, exchangeable or refundable under any circumstances. No " +
|
|
|
1217 |
"warranty is assured on these items." ,
|
| 10329 |
amar.kumar |
1218 |
new Font(FontFamily.TIMES_ROMAN, 8f)));
|
| 10328 |
amar.kumar |
1219 |
badSaleDisclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
1220 |
badSaleDisclaimerCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1221 |
taxTable.addCell(badSaleDisclaimerCell);
|
| 10320 |
amar.kumar |
1222 |
}
|
| 7014 |
rajveer |
1223 |
return taxTable;
|
|
|
1224 |
}
|
| 9009 |
amar.kumar |
1225 |
|
| 9319 |
amar.kumar |
1226 |
private boolean isVatApplicable(Order order) {
|
|
|
1227 |
if(order.getWarehouse_id() == 7) {
|
|
|
1228 |
if(order.getCustomer_pincode().startsWith(delhiPincodePrefix)) {
|
|
|
1229 |
return true;
|
|
|
1230 |
} else {
|
|
|
1231 |
return false;
|
|
|
1232 |
}
|
| 12809 |
manish.sha |
1233 |
} else if(order.getWarehouse_id() == 3298){
|
|
|
1234 |
for(int i=0; i< telanganaPincodes.length; i++) {
|
|
|
1235 |
if(order.getCustomer_pincode().trim().equalsIgnoreCase(telanganaPincodes[i])) {
|
|
|
1236 |
return true;
|
|
|
1237 |
}
|
|
|
1238 |
}
|
|
|
1239 |
return false;
|
| 16196 |
manish.sha |
1240 |
} else if(order.getWarehouse_id() == 1765 || order.getWarehouse_id() == 1768){
|
|
|
1241 |
for(int i=0; i< karnatakaPincodePrefix.length; i++) {
|
|
|
1242 |
if(order.getCustomer_pincode().startsWith(karnatakaPincodePrefix[i])) {
|
|
|
1243 |
return true;
|
|
|
1244 |
}
|
|
|
1245 |
}
|
|
|
1246 |
return false;
|
| 12809 |
manish.sha |
1247 |
}
|
|
|
1248 |
else {
|
| 9319 |
amar.kumar |
1249 |
for(int i=0; i< maharashtraPincodePrefix.length; i++) {
|
|
|
1250 |
if(order.getCustomer_pincode().startsWith(maharashtraPincodePrefix[i])) {
|
|
|
1251 |
return true;
|
|
|
1252 |
}
|
|
|
1253 |
}
|
|
|
1254 |
return false;
|
|
|
1255 |
}
|
|
|
1256 |
}
|
|
|
1257 |
|
| 9037 |
amar.kumar |
1258 |
private PdfPTable getFlipkartBarCodes(Order order) {
|
|
|
1259 |
PdfPTable flipkartTable = new PdfPTable(3);
|
|
|
1260 |
|
|
|
1261 |
PdfPCell spacerCell = new PdfPCell();
|
| 9040 |
amar.kumar |
1262 |
spacerCell.setBorder(Rectangle.NO_BORDER);
|
| 9037 |
amar.kumar |
1263 |
spacerCell.setColspan(3);
|
| 9099 |
amar.kumar |
1264 |
spacerCell.setPaddingTop(330.0f);
|
| 9037 |
amar.kumar |
1265 |
|
|
|
1266 |
String flipkartCodeFontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
1267 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
1268 |
ttfFontFactory.register(flipkartCodeFontPath, "barcode");
|
|
|
1269 |
Font flipkartBarCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, 20);
|
|
|
1270 |
|
| 9040 |
amar.kumar |
1271 |
String serialNumber = "0000000000";
|
| 9511 |
manish.sha |
1272 |
if(order.getLineitems().get(0).getSerial_number()!=null && !order.getLineitems().get(0).getSerial_number().isEmpty()) {
|
| 9040 |
amar.kumar |
1273 |
serialNumber = order.getLineitems().get(0).getSerial_number();
|
| 9511 |
manish.sha |
1274 |
} else if(order.getLineitems().get(0).getItem_number()!=null && !order.getLineitems().get(0).getItem_number().isEmpty()) {
|
| 9040 |
amar.kumar |
1275 |
serialNumber = order.getLineitems().get(0).getItem_number();
|
|
|
1276 |
}
|
|
|
1277 |
|
|
|
1278 |
PdfPCell serialNumberBarCodeCell = new PdfPCell(new Paragraph("*" + serialNumber + "*", flipkartBarCodeFont));
|
| 9037 |
amar.kumar |
1279 |
serialNumberBarCodeCell.setBorder(Rectangle.TOP);
|
| 9044 |
amar.kumar |
1280 |
serialNumberBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 9037 |
amar.kumar |
1281 |
serialNumberBarCodeCell.setPaddingTop(11.0f);
|
|
|
1282 |
|
|
|
1283 |
|
|
|
1284 |
PdfPCell invoiceNumberBarCodeCell = new PdfPCell(new Paragraph("*" + order.getInvoice_number() + "*", flipkartBarCodeFont));
|
|
|
1285 |
invoiceNumberBarCodeCell.setBorder(Rectangle.TOP);
|
| 9044 |
amar.kumar |
1286 |
invoiceNumberBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 9037 |
amar.kumar |
1287 |
invoiceNumberBarCodeCell.setPaddingTop(11.0f);
|
|
|
1288 |
|
|
|
1289 |
double rate = order.getLineitems().get(0).getVatRate();
|
|
|
1290 |
double salesTax = (rate * order.getTotal_amount())/(100 + rate);
|
| 9040 |
amar.kumar |
1291 |
PdfPCell vatAmtBarCodeCell = new PdfPCell(new Paragraph("*" + amountFormat.format(salesTax) + "*", flipkartBarCodeFont));
|
| 9037 |
amar.kumar |
1292 |
vatAmtBarCodeCell.setBorder(Rectangle.TOP);
|
| 9044 |
amar.kumar |
1293 |
vatAmtBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 9037 |
amar.kumar |
1294 |
vatAmtBarCodeCell.setPaddingTop(11.0f);
|
|
|
1295 |
|
|
|
1296 |
flipkartTable.addCell(spacerCell);
|
|
|
1297 |
flipkartTable.addCell(serialNumberBarCodeCell);
|
|
|
1298 |
flipkartTable.addCell(invoiceNumberBarCodeCell);
|
|
|
1299 |
flipkartTable.addCell(vatAmtBarCodeCell);
|
|
|
1300 |
|
|
|
1301 |
return flipkartTable;
|
|
|
1302 |
|
| 9009 |
amar.kumar |
1303 |
}
|
| 18657 |
manish.sha |
1304 |
|
|
|
1305 |
private void setBillingAddress(long userId, in.shop2020.model.v1.user.UserContextService.Client userClient) throws TException{
|
|
|
1306 |
billingAddress = userClient.getBillingAddressForUser(userId);
|
|
|
1307 |
}
|
| 9009 |
amar.kumar |
1308 |
|
| 18530 |
manish.sha |
1309 |
private PdfPTable getCustomerAddressTable(Order order, String destCode, boolean showPaymentMode, Font font, boolean forInvoce, boolean billingAdd){
|
| 7014 |
rajveer |
1310 |
PdfPTable customerTable = new PdfPTable(1);
|
|
|
1311 |
if(forInvoce || order.getPickupStoreId() == 0){
|
| 18530 |
manish.sha |
1312 |
in.shop2020.model.v1.user.UserContextService.Client userClient = usc.getClient();
|
|
|
1313 |
try {
|
|
|
1314 |
if(billingAdd && userClient.isPrivateDealUser(order.getCustomer_id())){
|
| 18657 |
manish.sha |
1315 |
setBillingAddress(order.getCustomer_id(), userClient);
|
|
|
1316 |
if(billingAddress!=null){
|
| 18769 |
manish.sha |
1317 |
return customerTable;
|
|
|
1318 |
/*
|
| 18657 |
manish.sha |
1319 |
customerTable.addCell(new Phrase(billingAddress.getName(), font));
|
|
|
1320 |
customerTable.addCell(new Phrase(billingAddress.getLine1(), font));
|
|
|
1321 |
customerTable.addCell(new Phrase(billingAddress.getLine2(), font));
|
|
|
1322 |
customerTable.addCell(new Phrase(billingAddress.getCity() + "," + billingAddress.getState(), font));
|
|
|
1323 |
customerTable.addCell(new Phrase(billingAddress.getPin(), font));
|
|
|
1324 |
customerTable.addCell(new Phrase("Phone : " + (billingAddress.getPhone()== null ? "" : billingAddress.getPhone()), font));
|
| 18769 |
manish.sha |
1325 |
*/
|
| 18657 |
manish.sha |
1326 |
}else{
|
|
|
1327 |
customerTable.addCell(new Phrase(order.getCustomer_name(), font));
|
|
|
1328 |
if(order.getSource() == OrderSource.HOMESHOP18.getValue()){
|
|
|
1329 |
HsOrder hsOrder = null;
|
|
|
1330 |
try {
|
|
|
1331 |
hsOrder = tsc.getClient().getHomeShopOrder(order.getId(), null, null).get(0);
|
|
|
1332 |
}catch (TException e) {
|
|
|
1333 |
logger.error("Error while getting homeshop18 order", e);
|
|
|
1334 |
}
|
|
|
1335 |
String hsShippingName = hsOrder.getShippingName();
|
|
|
1336 |
if(hsShippingName!=null && !hsShippingName.isEmpty()){
|
|
|
1337 |
customerTable.addCell(new Phrase("Shipped To: "+hsShippingName, font));
|
|
|
1338 |
}
|
|
|
1339 |
}
|
|
|
1340 |
customerTable.addCell(new Phrase(order.getCustomer_address1(), font));
|
|
|
1341 |
customerTable.addCell(new Phrase(order.getCustomer_address2(), font));
|
|
|
1342 |
customerTable.addCell(new Phrase(order.getCustomer_city() + "," + order.getCustomer_state(), font));
|
|
|
1343 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
1344 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
1345 |
if(destCode != null)
|
|
|
1346 |
customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + destCode, helvetica16));
|
|
|
1347 |
else
|
|
|
1348 |
customerTable.addCell(new Phrase(order.getCustomer_pincode(), font));
|
|
|
1349 |
}
|
|
|
1350 |
else{
|
|
|
1351 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
1352 |
String fedexLocationcode = "";
|
|
|
1353 |
try {
|
|
|
1354 |
fedexLocationcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_Location_Code");
|
|
|
1355 |
} catch (TException e1) {
|
|
|
1356 |
logger.error("Error while getting the provider information.", e1);
|
|
|
1357 |
}
|
|
|
1358 |
customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + fedexLocationcode, helvetica16));
|
|
|
1359 |
}
|
|
|
1360 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
1361 |
if(order.getCustomer_mobilenumber()!=null && !order.getCustomer_mobilenumber().isEmpty()) {
|
|
|
1362 |
customerTable.addCell(new Phrase("Phone : " + (order.getCustomer_mobilenumber()== null ? "" : order.getCustomer_mobilenumber()), font));
|
|
|
1363 |
}
|
|
|
1364 |
}
|
| 18530 |
manish.sha |
1365 |
}else{
|
| 18769 |
manish.sha |
1366 |
customerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 18530 |
manish.sha |
1367 |
customerTable.addCell(new Phrase(order.getCustomer_name(), font));
|
|
|
1368 |
if(order.getSource() == OrderSource.HOMESHOP18.getValue()){
|
|
|
1369 |
HsOrder hsOrder = null;
|
|
|
1370 |
try {
|
|
|
1371 |
hsOrder = tsc.getClient().getHomeShopOrder(order.getId(), null, null).get(0);
|
|
|
1372 |
}catch (TException e) {
|
|
|
1373 |
logger.error("Error while getting homeshop18 order", e);
|
|
|
1374 |
}
|
|
|
1375 |
String hsShippingName = hsOrder.getShippingName();
|
|
|
1376 |
if(hsShippingName!=null && !hsShippingName.isEmpty()){
|
|
|
1377 |
customerTable.addCell(new Phrase("Shipped To: "+hsShippingName, font));
|
|
|
1378 |
}
|
|
|
1379 |
}
|
|
|
1380 |
customerTable.addCell(new Phrase(order.getCustomer_address1(), font));
|
|
|
1381 |
customerTable.addCell(new Phrase(order.getCustomer_address2(), font));
|
|
|
1382 |
customerTable.addCell(new Phrase(order.getCustomer_city() + "," + order.getCustomer_state(), font));
|
|
|
1383 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
1384 |
if(order.getLogistics_provider_id()!=7L){
|
|
|
1385 |
if(destCode != null)
|
|
|
1386 |
customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + destCode, helvetica16));
|
|
|
1387 |
else
|
|
|
1388 |
customerTable.addCell(new Phrase(order.getCustomer_pincode(), font));
|
|
|
1389 |
}
|
|
|
1390 |
else{
|
|
|
1391 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
1392 |
String fedexLocationcode = "";
|
|
|
1393 |
try {
|
|
|
1394 |
fedexLocationcode = tclient.getOrderAttributeValue(order.getId(), "FedEx_Location_Code");
|
|
|
1395 |
} catch (TException e1) {
|
|
|
1396 |
logger.error("Error while getting the provider information.", e1);
|
|
|
1397 |
}
|
|
|
1398 |
customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + fedexLocationcode, helvetica16));
|
|
|
1399 |
}
|
|
|
1400 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
|
|
1401 |
if(order.getCustomer_mobilenumber()!=null && !order.getCustomer_mobilenumber().isEmpty()) {
|
|
|
1402 |
customerTable.addCell(new Phrase("Phone : " + (order.getCustomer_mobilenumber()== null ? "" : order.getCustomer_mobilenumber()), font));
|
|
|
1403 |
}
|
| 13734 |
manish.sha |
1404 |
}
|
| 18530 |
manish.sha |
1405 |
} catch (TException e2) {
|
|
|
1406 |
e2.printStackTrace();
|
| 13734 |
manish.sha |
1407 |
}
|
| 18530 |
manish.sha |
1408 |
|
| 7014 |
rajveer |
1409 |
}else{
|
| 18769 |
manish.sha |
1410 |
customerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 7014 |
rajveer |
1411 |
try {
|
| 5556 |
rajveer |
1412 |
in.shop2020.logistics.LogisticsService.Client lclient = (new LogisticsClient()).getClient();
|
| 7014 |
rajveer |
1413 |
PickupStore store = lclient.getPickupStore(order.getPickupStoreId());
|
|
|
1414 |
customerTable.addCell(new Phrase(order.getCustomer_name() + " \nc/o " + store.getName(), font));
|
|
|
1415 |
customerTable.addCell(new Phrase(store.getLine1(), font));
|
|
|
1416 |
customerTable.addCell(new Phrase(store.getLine2(), font));
|
|
|
1417 |
customerTable.addCell(new Phrase(store.getCity() + "," + store.getState(), font));
|
|
|
1418 |
if(destCode != null)
|
|
|
1419 |
customerTable.addCell(new Phrase(store.getPin() + " - " + destCode, helvetica16));
|
|
|
1420 |
else
|
|
|
1421 |
customerTable.addCell(new Phrase(store.getPin(), font));
|
|
|
1422 |
customerTable.addCell(new Phrase("Phone :" + store.getPhone(), font));
|
| 5556 |
rajveer |
1423 |
} catch (TException e) {
|
|
|
1424 |
// TODO Auto-generated catch block
|
|
|
1425 |
e.printStackTrace();
|
|
|
1426 |
}
|
| 5527 |
anupam.sin |
1427 |
|
| 7014 |
rajveer |
1428 |
}
|
|
|
1429 |
|
|
|
1430 |
if(order.getOrderType().equals(OrderType.B2B)) {
|
|
|
1431 |
String tin = null;
|
|
|
1432 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
|
|
1433 |
List<Attribute> attributes;
|
|
|
1434 |
try {
|
|
|
1435 |
attributes = tclient.getAllAttributesForOrderId(order.getId());
|
|
|
1436 |
|
|
|
1437 |
for(Attribute attribute : attributes) {
|
|
|
1438 |
if(attribute.getName().equals("tinNumber")) {
|
|
|
1439 |
tin = attribute.getValue();
|
|
|
1440 |
}
|
|
|
1441 |
}
|
|
|
1442 |
if (tin != null) {
|
|
|
1443 |
customerTable.addCell(new Phrase("TIN :" + tin, font));
|
|
|
1444 |
}
|
|
|
1445 |
|
|
|
1446 |
} catch (Exception e) {
|
|
|
1447 |
logger.error("Error while getting order attributes", e);
|
|
|
1448 |
}
|
|
|
1449 |
}
|
|
|
1450 |
/*
|
| 2787 |
chandransh |
1451 |
if(showPaymentMode){
|
|
|
1452 |
customerTable.addCell(new Phrase(" ", font));
|
|
|
1453 |
customerTable.addCell(new Phrase("Payment Mode: Prepaid", font));
|
| 5856 |
anupam.sin |
1454 |
}*/
|
| 7014 |
rajveer |
1455 |
return customerTable;
|
|
|
1456 |
}
|
| 2787 |
chandransh |
1457 |
|
| 7014 |
rajveer |
1458 |
private PdfPTable getOrderDetails(Order order, Provider provider){
|
|
|
1459 |
PdfPTable orderTable = new PdfPTable(new float[]{0.4f, 0.6f});
|
|
|
1460 |
orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 2787 |
chandransh |
1461 |
|
| 7014 |
rajveer |
1462 |
orderTable.addCell(new Phrase("Invoice No:", helvetica8));
|
|
|
1463 |
orderTable.addCell(new Phrase(order.getInvoice_number(), helvetica8));
|
| 2787 |
chandransh |
1464 |
|
| 7014 |
rajveer |
1465 |
orderTable.addCell(new Phrase("Date:", helvetica8));
|
|
|
1466 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
|
| 2787 |
chandransh |
1467 |
|
| 13691 |
manish.sha |
1468 |
String hsCourierName = "";
|
| 12590 |
amit.gupta |
1469 |
if(order.getSource() == OrderSource.AMAZON.getValue() || order.getSource() == OrderSource.JUNGLEE.getValue()){
|
| 7528 |
rajveer |
1470 |
AmazonOrder aorder = null;
|
|
|
1471 |
try {
|
|
|
1472 |
aorder = tsc.getClient().getAmazonOrder(order.getId());
|
|
|
1473 |
} catch (TException e) {
|
|
|
1474 |
logger.error("Error while getting amazon order", e);
|
|
|
1475 |
}
|
| 12590 |
amit.gupta |
1476 |
if(order.getSource() == OrderSource.JUNGLEE.getValue()){
|
|
|
1477 |
orderTable.addCell(new Phrase("Junglee Order ID:", helvetica8));
|
|
|
1478 |
}else {
|
|
|
1479 |
orderTable.addCell(new Phrase("Amazon Order ID:", helvetica8));
|
|
|
1480 |
}
|
| 7528 |
rajveer |
1481 |
orderTable.addCell(new Phrase(aorder.getAmazonOrderCode(), helvetica8));
|
| 13691 |
manish.sha |
1482 |
} else if(order.getSource() == OrderSource.HOMESHOP18.getValue()){
|
|
|
1483 |
HsOrder hsOrder = null;
|
|
|
1484 |
try {
|
| 13706 |
manish.sha |
1485 |
hsOrder = tsc.getClient().getHomeShopOrder(order.getId(), null, null).get(0);
|
| 13691 |
manish.sha |
1486 |
}catch (TException e) {
|
|
|
1487 |
logger.error("Error while getting homeshop18 order", e);
|
|
|
1488 |
}
|
|
|
1489 |
hsCourierName = hsOrder.getCourierName();
|
|
|
1490 |
orderTable.addCell(new Phrase("HomeShop18 Order No:", helvetica8));
|
|
|
1491 |
orderTable.addCell(new Phrase(hsOrder.getHsOrderNo(), helvetica8));
|
|
|
1492 |
orderTable.addCell(new Phrase("HomeShop18 Sub Order No:", helvetica8));
|
|
|
1493 |
orderTable.addCell(new Phrase(hsOrder.getHsSubOrderNo(), helvetica8));
|
|
|
1494 |
|
| 8182 |
amar.kumar |
1495 |
} else if(order.getSource() == OrderSource.EBAY.getValue()){
|
|
|
1496 |
EbayOrder ebayOrder = null;
|
|
|
1497 |
try {
|
|
|
1498 |
ebayOrder = tsc.getClient().getEbayOrderByOrderId(order.getId());
|
|
|
1499 |
} catch (TException e) {
|
|
|
1500 |
logger.error("Error while getting ebay order", e);
|
|
|
1501 |
}
|
|
|
1502 |
orderTable.addCell(new Phrase("PaisaPayId:", helvetica8));
|
|
|
1503 |
orderTable.addCell(new Phrase(ebayOrder.getPaisaPayId(), helvetica8));
|
|
|
1504 |
orderTable.addCell(new Phrase("Sales Rec Number:", helvetica8));
|
|
|
1505 |
orderTable.addCell(new Phrase(new Long(ebayOrder.getSalesRecordNumber()).toString(), helvetica8));
|
| 8488 |
amar.kumar |
1506 |
} else if(order.getSource() == OrderSource.SNAPDEAL.getValue()){
|
|
|
1507 |
SnapdealOrder snapdealOrder = null;
|
|
|
1508 |
try {
|
| 11424 |
kshitij.so |
1509 |
snapdealOrder = tsc.getClient().getSnapdealOrder(order.getId(), null, null).get(0);
|
| 8488 |
amar.kumar |
1510 |
} catch (TException e) {
|
|
|
1511 |
logger.error("Error while getting snapdeal order", e);
|
|
|
1512 |
}
|
|
|
1513 |
orderTable.addCell(new Phrase("Snapdeal OrderId:", helvetica8));
|
|
|
1514 |
orderTable.addCell(new Phrase(new Long(snapdealOrder.getSubOrderId()).toString(), helvetica8));
|
| 8828 |
amar.kumar |
1515 |
|
|
|
1516 |
String refernceCodeFontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
1517 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
1518 |
ttfFontFactory.register(refernceCodeFontPath, "barcode");
|
| 8876 |
amar.kumar |
1519 |
Font referenceCodeBarCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, 20);
|
| 8828 |
amar.kumar |
1520 |
|
| 8874 |
amar.kumar |
1521 |
PdfPCell snapdealReferenceBarCodeCell = new PdfPCell(new Paragraph("*" + snapdealOrder.getReferenceCode() + "*", referenceCodeBarCodeFont));
|
| 8828 |
amar.kumar |
1522 |
snapdealReferenceBarCodeCell.setBorder(Rectangle.NO_BORDER);
|
| 8876 |
amar.kumar |
1523 |
snapdealReferenceBarCodeCell.setPaddingTop(9.0f);
|
|
|
1524 |
snapdealReferenceBarCodeCell.setColspan(2);
|
| 9042 |
amar.kumar |
1525 |
snapdealReferenceBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 8876 |
amar.kumar |
1526 |
//orderTable.addCell(new Phrase("Snapdeal ReferenceCode:", helvetica8));
|
| 8828 |
amar.kumar |
1527 |
orderTable.addCell(snapdealReferenceBarCodeCell);
|
|
|
1528 |
//orderTable.addCell(new Phrase(snapdealOrder.getReferenceCode(), helvetica8));
|
| 7528 |
rajveer |
1529 |
}
|
| 8989 |
vikram.rag |
1530 |
else if(order.getSource() == OrderSource.FLIPKART.getValue()){
|
|
|
1531 |
FlipkartOrder flipkartOrder = null;
|
|
|
1532 |
try {
|
|
|
1533 |
flipkartOrder = tsc.getClient().getFlipkartOrder(order.getId());
|
|
|
1534 |
} catch (TException e) {
|
| 8996 |
amar.kumar |
1535 |
logger.error("Error while getting flipkart order", e);
|
| 8989 |
vikram.rag |
1536 |
}
|
|
|
1537 |
orderTable.addCell(new Phrase("Flipkart OrderId:", helvetica8));
|
|
|
1538 |
orderTable.addCell(new Phrase(flipkartOrder.getFlipkartOrderId(), helvetica8));
|
| 9037 |
amar.kumar |
1539 |
|
|
|
1540 |
//orderTable.addCell(new Phrase("Flipkart OrderItemId:", helvetica8));
|
|
|
1541 |
String flipkartBarCodeFontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
1542 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
1543 |
ttfFontFactory.register(flipkartBarCodeFontPath, "barcode");
|
| 9043 |
amar.kumar |
1544 |
Font flipkartBarCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, 18);
|
| 9037 |
amar.kumar |
1545 |
|
| 9043 |
amar.kumar |
1546 |
orderTable.addCell(new Phrase("Flipkart OrderItemId:", helvetica8));
|
| 9037 |
amar.kumar |
1547 |
PdfPCell flipkartOrderItemIdBarCodeCell = new PdfPCell(new Paragraph("*" + new Long(flipkartOrder.getFlipkartSubOrderId()).toString() + "*", flipkartBarCodeFont));
|
|
|
1548 |
flipkartOrderItemIdBarCodeCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1549 |
flipkartOrderItemIdBarCodeCell.setPaddingTop(9.0f);
|
| 9043 |
amar.kumar |
1550 |
//flipkartOrderItemIdBarCodeCell.setColspan(2);
|
|
|
1551 |
//flipkartOrderItemIdBarCodeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 9037 |
amar.kumar |
1552 |
orderTable.addCell(flipkartOrderItemIdBarCodeCell);
|
|
|
1553 |
//orderTable.addCell(new Phrase("Flipkart OrderItemId:", helvetica8));
|
|
|
1554 |
//orderTable.addCell(new Phrase(new Long(flipkartOrder.getFlipkartSubOrderId()).toString(), helvetica8));
|
| 8989 |
vikram.rag |
1555 |
}
|
|
|
1556 |
|
|
|
1557 |
|
| 7014 |
rajveer |
1558 |
orderTable.addCell(new Phrase("Order Date:", helvetica8));
|
|
|
1559 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getCreated_timestamp())), helvetica8));
|
| 13276 |
manish.sha |
1560 |
|
|
|
1561 |
if(OrderType.B2B==order.getOrderType()){
|
|
|
1562 |
try {
|
|
|
1563 |
String poRefVal = tsc.getClient().getOrderAttributeValue(order.getId(), "poRefNumber");
|
|
|
1564 |
if(poRefVal!=null && poRefVal.length()>0){
|
|
|
1565 |
orderTable.addCell(new Phrase("PO Ref:", helvetica8));
|
|
|
1566 |
orderTable.addCell(new Phrase(poRefVal, helvetica8));
|
|
|
1567 |
}
|
|
|
1568 |
|
|
|
1569 |
} catch (TException e) {
|
|
|
1570 |
logger.error("Error while getting amazon order", e);
|
|
|
1571 |
}
|
|
|
1572 |
}
|
| 2787 |
chandransh |
1573 |
|
| 7014 |
rajveer |
1574 |
orderTable.addCell(new Phrase("Courier:", helvetica8));
|
| 13691 |
manish.sha |
1575 |
if(order.getSource() == OrderSource.HOMESHOP18.getValue()){
|
|
|
1576 |
orderTable.addCell(new Phrase(hsCourierName, helvetica8));
|
|
|
1577 |
} else{
|
|
|
1578 |
orderTable.addCell(new Phrase(provider.getName(), helvetica8));
|
|
|
1579 |
}
|
| 2787 |
chandransh |
1580 |
|
| 9038 |
amar.kumar |
1581 |
if(order.getAirwaybill_no()!=null && !order.getAirwaybill_no().isEmpty()) {
|
|
|
1582 |
orderTable.addCell(new Phrase("AWB No:", helvetica8));
|
|
|
1583 |
orderTable.addCell(new Phrase(order.getAirwaybill_no(), helvetica8));
|
|
|
1584 |
}
|
| 2787 |
chandransh |
1585 |
|
| 7014 |
rajveer |
1586 |
orderTable.addCell(new Phrase("AWB Date:", helvetica8));
|
|
|
1587 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
|
| 2787 |
chandransh |
1588 |
|
| 7014 |
rajveer |
1589 |
return orderTable;
|
|
|
1590 |
}
|
| 2787 |
chandransh |
1591 |
|
| 13276 |
manish.sha |
1592 |
private PdfPTable getBottomInvoiceTable(List<Order> orderList,boolean isVAT, String invoiceFormat){
|
|
|
1593 |
PdfPTable invoiceTable = new PdfPTable(new float[]{0.1f, 0.3f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f});
|
| 7014 |
rajveer |
1594 |
invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 2787 |
chandransh |
1595 |
|
| 13284 |
manish.sha |
1596 |
invoiceTable.addCell(getInvoiceTableHeader(8,orderList.get(0).getLogisticsTransactionId()));
|
| 4262 |
rajveer |
1597 |
|
| 13276 |
manish.sha |
1598 |
if("Bulk".equalsIgnoreCase(invoiceFormat)){
|
|
|
1599 |
invoiceTable.addCell(new Phrase("Sr No", helveticaBold8));
|
|
|
1600 |
}else{
|
|
|
1601 |
invoiceTable.addCell(new Phrase("Order No", helveticaBold8));
|
|
|
1602 |
}
|
| 7014 |
rajveer |
1603 |
invoiceTable.addCell(new Phrase("Description", helveticaBold8));
|
|
|
1604 |
invoiceTable.addCell(new Phrase("Quantity", helveticaBold8));
|
|
|
1605 |
invoiceTable.addCell(new Phrase("Rate (Rs)", helveticaBold8));
|
|
|
1606 |
invoiceTable.addCell(new Phrase("Amount (Rs)", helveticaBold8));
|
| 13276 |
manish.sha |
1607 |
invoiceTable.addCell(new Phrase("Tax Rate%", helveticaBold8));
|
|
|
1608 |
invoiceTable.addCell(new Phrase("Tax (Rs)", helveticaBold8));
|
|
|
1609 |
invoiceTable.addCell(new Phrase("Item Total (Rs)", helveticaBold8));;
|
|
|
1610 |
double totalAmount = 0.0;
|
|
|
1611 |
double insuranceAmount = 0.0;
|
| 17470 |
manish.sha |
1612 |
double totalShippingCost = 0.0;
|
| 13276 |
manish.sha |
1613 |
int i=1;
|
|
|
1614 |
if("Bulk".equalsIgnoreCase(invoiceFormat)){
|
|
|
1615 |
Map<Long, String> itemNamesMap= new HashMap<Long, String>();
|
|
|
1616 |
Map<Long, Double> itemQuantityMap = new HashMap<Long, Double>();
|
|
|
1617 |
Map<Long, Double> itemRateMap = new HashMap<Long, Double>();
|
|
|
1618 |
Map<Long, Double> itemTotalAmtMap = new HashMap<Long, Double>();
|
|
|
1619 |
Map<Long, Double> itemTaxPercentageMap = new HashMap<Long, Double>();
|
|
|
1620 |
Map<Long, Double> itemTaxValueMap = new HashMap<Long, Double>();
|
|
|
1621 |
|
|
|
1622 |
for(Order order : orderList){
|
|
|
1623 |
LineItem lineitem = order.getLineitems().get(0);
|
|
|
1624 |
|
|
|
1625 |
double orderAmount = order.getTotal_amount();
|
|
|
1626 |
double rate = lineitem.getVatRate();
|
|
|
1627 |
double salesTax = (rate * (orderAmount - order.getInsuranceAmount()))/(100 + rate);
|
|
|
1628 |
totalAmount = totalAmount + orderAmount;
|
| 17470 |
manish.sha |
1629 |
totalShippingCost = totalShippingCost + order.getShippingCost();
|
| 13276 |
manish.sha |
1630 |
double itemPrice = lineitem.getUnit_price();
|
|
|
1631 |
double showPrice = (100 * itemPrice)/(100 + rate);
|
|
|
1632 |
double totalPrice = lineitem.getTotal_price();
|
|
|
1633 |
double showTotalPrice = (100 * totalPrice)/(100 + rate);
|
|
|
1634 |
|
|
|
1635 |
if(order.getInsurer() > 0) {
|
|
|
1636 |
insuranceAmount =insuranceAmount + order.getInsuranceAmount();
|
|
|
1637 |
}
|
|
|
1638 |
|
|
|
1639 |
if(!itemNamesMap.containsKey(lineitem.getItem_id())){
|
|
|
1640 |
itemNamesMap.put(lineitem.getItem_id(), getItemDisplayName(lineitem, false));
|
|
|
1641 |
}
|
|
|
1642 |
if(itemQuantityMap.containsKey(lineitem.getItem_id())){
|
|
|
1643 |
double quantity = itemQuantityMap.get(lineitem.getItem_id()) + lineitem.getQuantity();
|
|
|
1644 |
itemQuantityMap.put(lineitem.getItem_id(), quantity);
|
|
|
1645 |
} else {
|
|
|
1646 |
itemQuantityMap.put(lineitem.getItem_id(),lineitem.getQuantity());
|
|
|
1647 |
}
|
|
|
1648 |
if(!itemRateMap.containsKey(lineitem.getItem_id())){
|
|
|
1649 |
itemRateMap.put(lineitem.getItem_id(), showPrice);
|
|
|
1650 |
}
|
|
|
1651 |
if(!itemTaxPercentageMap.containsKey(lineitem.getItem_id())){
|
|
|
1652 |
itemTaxPercentageMap.put(lineitem.getItem_id(), rate);
|
|
|
1653 |
}
|
|
|
1654 |
if(itemTaxValueMap.containsKey(lineitem.getItem_id())){
|
|
|
1655 |
double taxValue = itemTaxValueMap.get(lineitem.getItem_id()) + salesTax;
|
|
|
1656 |
itemTaxValueMap.put(lineitem.getItem_id(), taxValue);
|
|
|
1657 |
}else{
|
|
|
1658 |
itemTaxValueMap.put(lineitem.getItem_id(), salesTax);
|
|
|
1659 |
}
|
|
|
1660 |
if(itemTotalAmtMap.containsKey(lineitem.getItem_id())){
|
|
|
1661 |
double totalItemAmount = itemTotalAmtMap.get(lineitem.getItem_id()) + showTotalPrice;
|
|
|
1662 |
itemTotalAmtMap.put(lineitem.getItem_id(), totalItemAmount);
|
|
|
1663 |
}else{
|
|
|
1664 |
itemTotalAmtMap.put(lineitem.getItem_id(), showTotalPrice);
|
|
|
1665 |
}
|
|
|
1666 |
}
|
|
|
1667 |
|
|
|
1668 |
for(Long itemId : itemNamesMap.keySet()){
|
|
|
1669 |
invoiceTable.addCell(new Phrase(i+"", helveticaBold8));
|
|
|
1670 |
invoiceTable.addCell(new Phrase(itemNamesMap.get(itemId),helvetica8));
|
|
|
1671 |
invoiceTable.addCell(new Phrase(itemQuantityMap.get(itemId)+"",helvetica8));
|
| 13285 |
manish.sha |
1672 |
invoiceTable.addCell(getPriceCell(itemRateMap.get(itemId)));
|
|
|
1673 |
invoiceTable.addCell(getPriceCell(itemTotalAmtMap.get(itemId)));
|
|
|
1674 |
invoiceTable.addCell(new Phrase(itemTaxPercentageMap.get(itemId)+"%",helvetica8));
|
|
|
1675 |
invoiceTable.addCell(getPriceCell(itemTaxValueMap.get(itemId)));
|
|
|
1676 |
invoiceTable.addCell(getPriceCell(itemTotalAmtMap.get(itemId)+itemTaxValueMap.get(itemId)));
|
| 13313 |
manish.sha |
1677 |
i++;
|
| 13276 |
manish.sha |
1678 |
}
|
|
|
1679 |
}
|
|
|
1680 |
else{
|
| 9432 |
amar.kumar |
1681 |
|
| 13276 |
manish.sha |
1682 |
for(Order order :orderList){
|
|
|
1683 |
LineItem lineItem = order.getLineitems().get(0);
|
|
|
1684 |
double orderAmount = order.getTotal_amount();
|
|
|
1685 |
double rate = lineItem.getVatRate();
|
|
|
1686 |
double salesTax = (rate * (orderAmount - order.getInsuranceAmount()))/(100 + rate);
|
|
|
1687 |
|
|
|
1688 |
invoiceTable.addCell(new Phrase(order.getId()+"", helveticaBold8));
|
|
|
1689 |
invoiceTable.addCell(getProductNameCell(lineItem, true, order.getFreebieItemId()));
|
|
|
1690 |
invoiceTable.addCell(new Phrase("" + lineItem.getQuantity(), helvetica8));
|
|
|
1691 |
|
|
|
1692 |
|
|
|
1693 |
//populateBottomInvoiceTable(order, invoiceTable, rate);
|
|
|
1694 |
|
|
|
1695 |
double itemPrice = lineItem.getUnit_price();
|
|
|
1696 |
double showPrice = (100 * itemPrice)/(100 + rate);
|
|
|
1697 |
invoiceTable.addCell(getPriceCell(showPrice));
|
|
|
1698 |
|
|
|
1699 |
double totalPrice = lineItem.getTotal_price();
|
|
|
1700 |
showPrice = (100 * totalPrice)/(100 + rate);
|
|
|
1701 |
invoiceTable.addCell(getPriceCell(showPrice));
|
|
|
1702 |
|
|
|
1703 |
PdfPCell salesTaxCell = getPriceCell(salesTax);
|
|
|
1704 |
|
|
|
1705 |
|
|
|
1706 |
invoiceTable.addCell(new Phrase(rate + "%", helvetica8));
|
|
|
1707 |
invoiceTable.addCell(salesTaxCell);
|
|
|
1708 |
invoiceTable.addCell(getTotalAmountCell(orderAmount));
|
|
|
1709 |
|
|
|
1710 |
if(order.getInsurer() > 0) {
|
|
|
1711 |
insuranceAmount =insuranceAmount + order.getInsuranceAmount();
|
|
|
1712 |
}
|
|
|
1713 |
totalAmount = totalAmount+ orderAmount;
|
| 17470 |
manish.sha |
1714 |
totalShippingCost = totalShippingCost + order.getShippingCost();
|
| 13276 |
manish.sha |
1715 |
i++;
|
|
|
1716 |
}
|
| 9432 |
amar.kumar |
1717 |
}
|
| 7014 |
rajveer |
1718 |
|
| 13276 |
manish.sha |
1719 |
if(insuranceAmount>0){
|
|
|
1720 |
invoiceTable.addCell(getInsuranceCell(7));
|
|
|
1721 |
invoiceTable.addCell(getPriceCell(insuranceAmount));
|
| 7014 |
rajveer |
1722 |
}
|
| 17470 |
manish.sha |
1723 |
if(totalShippingCost>0){
|
| 17501 |
manish.sha |
1724 |
invoiceTable.addCell(getShippingCostCell(6));
|
|
|
1725 |
invoiceTable.addCell(getRupeesCell(false));
|
|
|
1726 |
invoiceTable.addCell(getPriceCell(totalShippingCost));
|
| 17470 |
manish.sha |
1727 |
}
|
| 13276 |
manish.sha |
1728 |
invoiceTable.addCell(getTotalCell(6));
|
| 17501 |
manish.sha |
1729 |
invoiceTable.addCell(getRupeesCell(true));
|
| 17470 |
manish.sha |
1730 |
invoiceTable.addCell(getTotalAmountCell(totalAmount+totalShippingCost));
|
| 7014 |
rajveer |
1731 |
|
| 13276 |
manish.sha |
1732 |
invoiceTable.addCell(new Phrase("Amount in Words:", helveticaBold8));
|
| 17470 |
manish.sha |
1733 |
invoiceTable.addCell(getAmountInWordsCell(totalAmount+totalShippingCost));
|
| 7014 |
rajveer |
1734 |
|
| 13276 |
manish.sha |
1735 |
invoiceTable.addCell(getEOECell(8));
|
| 7014 |
rajveer |
1736 |
|
|
|
1737 |
return invoiceTable;
|
|
|
1738 |
}
|
|
|
1739 |
|
| 13276 |
manish.sha |
1740 |
private PdfPCell getInvoiceTableHeader(int colspan, String masterOrderId) {
|
|
|
1741 |
PdfPTable invoiceHeaderTable = new PdfPTable(2);
|
|
|
1742 |
PdfPCell masterOrderIdCell = new PdfPCell(new Phrase("Master Order Id- "+masterOrderId, helvetica10));
|
| 13320 |
manish.sha |
1743 |
if(masterOrderId!=null && !masterOrderId.isEmpty()){
|
|
|
1744 |
masterOrderIdCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1745 |
masterOrderIdCell.setPaddingTop(1);
|
|
|
1746 |
}
|
| 13281 |
manish.sha |
1747 |
PdfPCell invoiceTableHeader = new PdfPCell(new Phrase("Order Details:", helveticaBold12));
|
| 7014 |
rajveer |
1748 |
invoiceTableHeader.setBorder(Rectangle.NO_BORDER);
|
| 8551 |
manish.sha |
1749 |
invoiceTableHeader.setPaddingTop(1);
|
| 13276 |
manish.sha |
1750 |
invoiceHeaderTable.addCell(invoiceTableHeader);
|
| 13320 |
manish.sha |
1751 |
if(masterOrderId!=null && !masterOrderId.isEmpty()){
|
|
|
1752 |
invoiceHeaderTable.addCell(masterOrderIdCell);
|
|
|
1753 |
}else{
|
|
|
1754 |
masterOrderIdCell = new PdfPCell(new Phrase(" ", helvetica10));
|
|
|
1755 |
invoiceHeaderTable.addCell(masterOrderIdCell);
|
|
|
1756 |
}
|
| 13283 |
manish.sha |
1757 |
PdfPCell headerCell = new PdfPCell(invoiceHeaderTable);
|
|
|
1758 |
headerCell.setColspan(colspan);
|
|
|
1759 |
return headerCell;
|
| 7014 |
rajveer |
1760 |
}
|
|
|
1761 |
|
| 13276 |
manish.sha |
1762 |
/*private void populateBottomInvoiceTable(List<Order> orderList, PdfPTable invoiceTable) {
|
| 7014 |
rajveer |
1763 |
for (LineItem lineitem : order.getLineitems()) {
|
|
|
1764 |
invoiceTable.addCell(new Phrase("" + order.getId() , helvetica8));
|
|
|
1765 |
|
| 7190 |
amar.kumar |
1766 |
invoiceTable.addCell(getProductNameCell(lineitem, true, order.getFreebieItemId()));
|
| 7014 |
rajveer |
1767 |
|
|
|
1768 |
invoiceTable.addCell(new Phrase("" + lineitem.getQuantity(), helvetica8));
|
|
|
1769 |
|
|
|
1770 |
double itemPrice = lineitem.getUnit_price();
|
|
|
1771 |
double showPrice = (100 * itemPrice)/(100 + rate);
|
|
|
1772 |
invoiceTable.addCell(getPriceCell(showPrice)); //Unit Price Cell
|
|
|
1773 |
|
|
|
1774 |
double totalPrice = lineitem.getTotal_price();
|
|
|
1775 |
showPrice = (100 * totalPrice)/(100 + rate);
|
|
|
1776 |
invoiceTable.addCell(getPriceCell(showPrice)); //Total Price Cell
|
|
|
1777 |
}
|
| 13276 |
manish.sha |
1778 |
}*/
|
| 7014 |
rajveer |
1779 |
|
| 7190 |
amar.kumar |
1780 |
private PdfPCell getProductNameCell(LineItem lineitem, boolean appendIMEI, Long freebieItemId) {
|
| 7014 |
rajveer |
1781 |
String itemName = getItemDisplayName(lineitem, appendIMEI);
|
| 7190 |
amar.kumar |
1782 |
if(freebieItemId!=null && freebieItemId!=0){
|
|
|
1783 |
try {
|
|
|
1784 |
CatalogService.Client catalogClient = ctsc.getClient();
|
|
|
1785 |
Item item = catalogClient.getItem(freebieItemId);
|
|
|
1786 |
itemName = itemName + "\n(Free Item: " + item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + ")";
|
|
|
1787 |
} catch(Exception tex) {
|
|
|
1788 |
logger.error("Not able to get Freebie Item Details for ItemId:" + freebieItemId, tex);
|
|
|
1789 |
}
|
|
|
1790 |
}
|
| 7014 |
rajveer |
1791 |
PdfPCell productNameCell = new PdfPCell(new Phrase(itemName, helvetica8));
|
|
|
1792 |
productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
1793 |
return productNameCell;
|
|
|
1794 |
}
|
|
|
1795 |
|
|
|
1796 |
private PdfPCell getPriceCell(double price) {
|
|
|
1797 |
PdfPCell totalPriceCell = new PdfPCell(new Phrase(amountFormat.format(price), helvetica8));
|
|
|
1798 |
totalPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1799 |
return totalPriceCell;
|
|
|
1800 |
}
|
|
|
1801 |
|
|
|
1802 |
private PdfPCell getVATLabelCell(boolean isVAT) {
|
|
|
1803 |
PdfPCell vatCell = null;
|
|
|
1804 |
if(isVAT){
|
|
|
1805 |
vatCell = new PdfPCell(new Phrase("VAT", helveticaBold8));
|
|
|
1806 |
} else {
|
|
|
1807 |
vatCell = new PdfPCell(new Phrase("CST", helveticaBold8));
|
|
|
1808 |
}
|
|
|
1809 |
vatCell.setColspan(3);
|
|
|
1810 |
vatCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1811 |
return vatCell;
|
|
|
1812 |
}
|
|
|
1813 |
|
| 9432 |
amar.kumar |
1814 |
private PdfPCell getCFORMLabelCell() {
|
|
|
1815 |
PdfPCell cFormCell = null;
|
|
|
1816 |
cFormCell = new PdfPCell(new Phrase("CST Against CForm", helveticaBold8));
|
|
|
1817 |
cFormCell.setColspan(3);
|
|
|
1818 |
cFormCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1819 |
return cFormCell;
|
|
|
1820 |
}
|
|
|
1821 |
|
| 7318 |
rajveer |
1822 |
private PdfPCell getAdvanceAmountCell(int colspan) {
|
|
|
1823 |
PdfPCell insuranceCell = null;
|
|
|
1824 |
insuranceCell = new PdfPCell(new Phrase("Advance Amount Received", helvetica8));
|
|
|
1825 |
insuranceCell.setColspan(colspan);
|
|
|
1826 |
insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1827 |
return insuranceCell;
|
|
|
1828 |
}
|
|
|
1829 |
|
| 7014 |
rajveer |
1830 |
private PdfPCell getInsuranceCell(int colspan) {
|
|
|
1831 |
PdfPCell insuranceCell = null;
|
| 13276 |
manish.sha |
1832 |
insuranceCell = new PdfPCell(new Phrase("1 Year WorldWide Theft Insurance. T&C Apply", helvetica8));
|
| 7014 |
rajveer |
1833 |
insuranceCell.setColspan(colspan);
|
|
|
1834 |
insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1835 |
return insuranceCell;
|
|
|
1836 |
}
|
|
|
1837 |
|
|
|
1838 |
private PdfPCell getEmptyCell(int colspan) {
|
|
|
1839 |
PdfPCell emptyCell = new PdfPCell(new Phrase(" ", helvetica8));
|
|
|
1840 |
emptyCell.setColspan(colspan);
|
|
|
1841 |
return emptyCell;
|
|
|
1842 |
}
|
| 17470 |
manish.sha |
1843 |
|
|
|
1844 |
private PdfPCell getShippingCostCell(int colspan) {
|
|
|
1845 |
PdfPCell shippingCostCell = new PdfPCell(new Phrase("Shipping Charges", helvetica8));
|
|
|
1846 |
shippingCostCell.setColspan(colspan);
|
| 17501 |
manish.sha |
1847 |
shippingCostCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| 17470 |
manish.sha |
1848 |
return shippingCostCell;
|
|
|
1849 |
}
|
|
|
1850 |
|
|
|
1851 |
private PdfPCell getCodChargesCell(int colspan) {
|
|
|
1852 |
PdfPCell codChargesCell = new PdfPCell(new Phrase("COD Charges", helvetica8));
|
|
|
1853 |
codChargesCell.setColspan(colspan);
|
|
|
1854 |
return codChargesCell;
|
|
|
1855 |
}
|
| 7014 |
rajveer |
1856 |
|
|
|
1857 |
private PdfPCell getTotalCell(int colspan) {
|
| 13276 |
manish.sha |
1858 |
PdfPCell totalCell = new PdfPCell(new Phrase("Grand Total", helveticaBold8));
|
| 7014 |
rajveer |
1859 |
totalCell.setColspan(colspan);
|
|
|
1860 |
totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1861 |
return totalCell;
|
|
|
1862 |
}
|
|
|
1863 |
|
| 17501 |
manish.sha |
1864 |
private PdfPCell getRupeesCell(boolean useBold) {
|
|
|
1865 |
PdfPCell rupeesCell;
|
|
|
1866 |
if(useBold)
|
|
|
1867 |
rupeesCell= new PdfPCell(new Phrase("Rs.", helveticaBold8));
|
|
|
1868 |
else
|
|
|
1869 |
rupeesCell= new PdfPCell(new Phrase("Rs.", helvetica8));
|
| 7014 |
rajveer |
1870 |
rupeesCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1871 |
return rupeesCell;
|
|
|
1872 |
}
|
|
|
1873 |
|
|
|
1874 |
private PdfPCell getTotalAmountCell(double orderAmount) {
|
|
|
1875 |
PdfPCell totalAmountCell = new PdfPCell(new Phrase(amountFormat.format(orderAmount), helveticaBold8));
|
|
|
1876 |
totalAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1877 |
return totalAmountCell;
|
|
|
1878 |
}
|
|
|
1879 |
|
|
|
1880 |
/**
|
|
|
1881 |
* This method uses ICU4J libraries to convert the given amount into words
|
|
|
1882 |
* of Indian locale.
|
|
|
1883 |
*
|
|
|
1884 |
* @param orderAmount
|
|
|
1885 |
* The amount to convert.
|
|
|
1886 |
* @return the string representation of the given amount.
|
|
|
1887 |
*/
|
|
|
1888 |
private PdfPCell getAmountInWordsCell(double orderAmount) {
|
|
|
1889 |
RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
|
|
|
1890 |
StringBuilder amountInWords = new StringBuilder("Rs. ");
|
|
|
1891 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)orderAmount)));
|
|
|
1892 |
amountInWords.append(" and ");
|
|
|
1893 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)(orderAmount*100)%100)));
|
|
|
1894 |
amountInWords.append(" paise");
|
|
|
1895 |
|
|
|
1896 |
PdfPCell amountInWordsCell= new PdfPCell(new Phrase(amountInWords.toString(), helveticaBold8));
|
|
|
1897 |
amountInWordsCell.setColspan(4);
|
|
|
1898 |
return amountInWordsCell;
|
|
|
1899 |
}
|
|
|
1900 |
|
|
|
1901 |
/**
|
|
|
1902 |
* Returns the item name to be displayed in the invoice table.
|
|
|
1903 |
*
|
|
|
1904 |
* @param lineitem
|
|
|
1905 |
* The line item whose name has to be displayed
|
|
|
1906 |
* @param appendIMEI
|
|
|
1907 |
* Whether to attach the IMEI No. to the item name
|
|
|
1908 |
* @return The name to be displayed for the given line item.
|
|
|
1909 |
*/
|
|
|
1910 |
private String getItemDisplayName(LineItem lineitem, boolean appendIMEI){
|
|
|
1911 |
StringBuffer itemName = new StringBuffer();
|
|
|
1912 |
if(lineitem.getBrand()!= null)
|
|
|
1913 |
itemName.append(lineitem.getBrand() + " ");
|
|
|
1914 |
if(lineitem.getModel_name() != null)
|
|
|
1915 |
itemName.append(lineitem.getModel_name() + " ");
|
|
|
1916 |
if(lineitem.getModel_number() != null )
|
|
|
1917 |
itemName.append(lineitem.getModel_number() + " ");
|
|
|
1918 |
if(lineitem.getColor() != null && !lineitem.getColor().trim().equals("NA"))
|
|
|
1919 |
itemName.append("("+lineitem.getColor()+")");
|
| 13320 |
manish.sha |
1920 |
if(appendIMEI && lineitem.isSetSerial_number() && !lineitem.getSerial_number().isEmpty()){
|
| 7014 |
rajveer |
1921 |
itemName.append("\nIMEI No. " + lineitem.getSerial_number());
|
|
|
1922 |
}
|
|
|
1923 |
|
|
|
1924 |
return itemName.toString();
|
|
|
1925 |
}
|
|
|
1926 |
|
|
|
1927 |
/**
|
|
|
1928 |
*
|
|
|
1929 |
* @param colspan
|
|
|
1930 |
* @return a PdfPCell containing the E&OE text and spanning the given
|
|
|
1931 |
* no. of columns
|
|
|
1932 |
*/
|
|
|
1933 |
private PdfPCell getEOECell(int colspan) {
|
|
|
1934 |
PdfPCell eoeCell = new PdfPCell(new Phrase("E & O.E", helvetica8));
|
|
|
1935 |
eoeCell.setColspan(colspan);
|
|
|
1936 |
eoeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
1937 |
return eoeCell;
|
|
|
1938 |
}
|
|
|
1939 |
|
|
|
1940 |
private PdfPTable getExtraInfoTable(Order order, Provider provider, float barcodeFontSize, BillingType billingType){
|
|
|
1941 |
PdfPTable extraInfoTable = new PdfPTable(1);
|
|
|
1942 |
extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
1943 |
extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
1944 |
|
|
|
1945 |
String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
1946 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
1947 |
ttfFontFactory.register(fontPath, "barcode");
|
|
|
1948 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
|
|
1949 |
|
|
|
1950 |
PdfPCell extraInfoCell;
|
|
|
1951 |
if(billingType == BillingType.EXTERNAL){
|
|
|
1952 |
extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "* *" + order.getCustomer_name() + "* *" + order.getTotal_amount() + "*", barCodeFont));
|
|
|
1953 |
}else{
|
|
|
1954 |
extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "* *" + order.getLineitems().get(0).getTransfer_price() + "*", barCodeFont));
|
|
|
1955 |
}
|
|
|
1956 |
|
|
|
1957 |
extraInfoCell.setPaddingTop(20.0f);
|
|
|
1958 |
extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
1959 |
extraInfoCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1960 |
|
|
|
1961 |
extraInfoTable.addCell(extraInfoCell);
|
|
|
1962 |
|
|
|
1963 |
|
|
|
1964 |
return extraInfoTable;
|
|
|
1965 |
}
|
|
|
1966 |
|
|
|
1967 |
private PdfPTable getFixedTextTable(float barcodeFontSize, String printText){
|
|
|
1968 |
PdfPTable extraInfoTable = new PdfPTable(1);
|
|
|
1969 |
extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
1970 |
extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
1971 |
|
|
|
1972 |
String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
|
|
1973 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
|
|
1974 |
ttfFontFactory.register(fontPath, "barcode");
|
|
|
1975 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
|
|
1976 |
|
|
|
1977 |
PdfPCell extraInfoCell = new PdfPCell(new Paragraph( "*" + printText + "*", barCodeFont));
|
|
|
1978 |
|
|
|
1979 |
extraInfoCell.setPaddingTop(20.0f);
|
|
|
1980 |
extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
1981 |
extraInfoCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1982 |
|
|
|
1983 |
extraInfoTable.addCell(extraInfoCell);
|
|
|
1984 |
|
|
|
1985 |
return extraInfoTable;
|
|
|
1986 |
}
|
| 8067 |
manish.sha |
1987 |
|
|
|
1988 |
private void generateBarcode(String barcodeString, String fileName){
|
|
|
1989 |
Code128Bean bean = new Code128Bean();
|
| 7014 |
rajveer |
1990 |
|
| 8067 |
manish.sha |
1991 |
final int dpi = 60;
|
|
|
1992 |
|
|
|
1993 |
//Configure the barcode generator
|
|
|
1994 |
bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar
|
|
|
1995 |
//width exactly one pixel
|
|
|
1996 |
bean.setFontSize(bean.getFontSize()+1.0f);
|
|
|
1997 |
bean.doQuietZone(false);
|
|
|
1998 |
|
|
|
1999 |
try {
|
|
|
2000 |
File outputFile = new File("/tmp/"+fileName+".png");
|
|
|
2001 |
OutputStream out = new FileOutputStream(outputFile);
|
|
|
2002 |
|
|
|
2003 |
//Set up the canvas provider for monochrome PNG output
|
|
|
2004 |
BitmapCanvasProvider canvas = new BitmapCanvasProvider(
|
|
|
2005 |
out, "image/x-png", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
|
|
|
2006 |
|
|
|
2007 |
//Generate the barcode
|
|
|
2008 |
bean.generateBarcode(canvas, barcodeString);
|
|
|
2009 |
|
|
|
2010 |
//Signal end of generation
|
|
|
2011 |
canvas.finish();
|
|
|
2012 |
out.close();
|
|
|
2013 |
|
|
|
2014 |
}
|
|
|
2015 |
catch(Exception e){
|
|
|
2016 |
logger.error("Exception during generating Barcode : ", e);
|
|
|
2017 |
}
|
|
|
2018 |
}
|
|
|
2019 |
|
| 7014 |
rajveer |
2020 |
public static void main(String[] args) throws IOException {
|
|
|
2021 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
| 7318 |
rajveer |
2022 |
long orderId = 356324;
|
|
|
2023 |
ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, true, false, 1);
|
| 7014 |
rajveer |
2024 |
String userHome = System.getProperty("user.home");
|
|
|
2025 |
File f = new File(userHome + "/invoice-" + orderId + ".pdf");
|
|
|
2026 |
FileOutputStream fos = new FileOutputStream(f);
|
|
|
2027 |
baos.writeTo(fos);
|
|
|
2028 |
System.out.println("Invoice generated.");
|
|
|
2029 |
}
|
| 2787 |
chandransh |
2030 |
}
|