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