| Line 31... |
Line 31... |
| 31 |
import java.io.IOException;
|
31 |
import java.io.IOException;
|
| 32 |
import java.text.DateFormat;
|
32 |
import java.text.DateFormat;
|
| 33 |
import java.text.DecimalFormat;
|
33 |
import java.text.DecimalFormat;
|
| 34 |
import java.util.ArrayList;
|
34 |
import java.util.ArrayList;
|
| 35 |
import java.util.Date;
|
35 |
import java.util.Date;
|
| 36 |
import java.util.Enumeration;
|
- |
|
| 37 |
import java.util.List;
|
36 |
import java.util.List;
|
| 38 |
import java.util.Locale;
|
37 |
import java.util.Locale;
|
| 39 |
import java.util.Properties;
|
- |
|
| 40 |
import java.util.ResourceBundle;
|
- |
|
| 41 |
|
38 |
|
| 42 |
import javax.servlet.ServletException;
|
39 |
import javax.servlet.ServletException;
|
| 43 |
import javax.servlet.ServletOutputStream;
|
40 |
import javax.servlet.ServletOutputStream;
|
| 44 |
import javax.servlet.http.HttpServlet;
|
41 |
import javax.servlet.http.HttpServlet;
|
| 45 |
import javax.servlet.http.HttpServletRequest;
|
42 |
import javax.servlet.http.HttpServletRequest;
|
| Line 48... |
Line 45... |
| 48 |
import org.apache.commons.lang.StringUtils;
|
45 |
import org.apache.commons.lang.StringUtils;
|
| 49 |
import org.apache.commons.lang.WordUtils;
|
46 |
import org.apache.commons.lang.WordUtils;
|
| 50 |
import org.apache.thrift.TException;
|
47 |
import org.apache.thrift.TException;
|
| 51 |
import org.slf4j.Logger;
|
48 |
import org.slf4j.Logger;
|
| 52 |
import org.slf4j.LoggerFactory;
|
49 |
import org.slf4j.LoggerFactory;
|
| 53 |
import org.apache.thrift.transport.TTransportException;
|
- |
|
| 54 |
|
50 |
|
| 55 |
import com.ibm.icu.text.RuleBasedNumberFormat;
|
51 |
import com.ibm.icu.text.RuleBasedNumberFormat;
|
| 56 |
|
52 |
|
| 57 |
import com.itextpdf.text.Document;
|
53 |
import com.itextpdf.text.Document;
|
| 58 |
import com.itextpdf.text.Element;
|
54 |
import com.itextpdf.text.Element;
|
| Line 132... |
Line 128... |
| 132 |
private static final Font helvetica28 = FontFactory.getFont(FontFactory.HELVETICA, 28);
|
128 |
private static final Font helvetica28 = FontFactory.getFont(FontFactory.HELVETICA, 28);
|
| 133 |
|
129 |
|
| 134 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
130 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
| 135 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
131 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
| 136 |
|
132 |
|
| 137 |
private static final Properties properties = readProperties();
|
- |
|
| 138 |
private static final String ourAddress = properties.getProperty("sales_tax_address",
|
- |
|
| 139 |
"Spice Online Retail Pvt. Ltd.\nKhasra No. 819, Block-K\nMahipalpur, New Delhi-110037\n");
|
- |
|
| 140 |
private static final String tinNo = properties.getProperty("sales_tax_tin", "07250399732");
|
- |
|
| 141 |
|
- |
|
| 142 |
private static final String delhiPincodePrefix = "11";
|
133 |
private static final String delhiPincodePrefix = "11";
|
| 143 |
|
134 |
|
| 144 |
private static Properties readProperties(){
|
- |
|
| 145 |
ResourceBundle resource = ResourceBundle.getBundle(InvoiceGenerationService.class.getName());
|
- |
|
| 146 |
Properties props = new Properties();
|
- |
|
| 147 |
|
- |
|
| 148 |
Enumeration<String> keys = resource.getKeys();
|
- |
|
| 149 |
while (keys.hasMoreElements()) {
|
- |
|
| 150 |
String key = keys.nextElement();
|
- |
|
| 151 |
props.put(key, resource.getString(key));
|
- |
|
| 152 |
}
|
- |
|
| 153 |
return props;
|
- |
|
| 154 |
}
|
- |
|
| 155 |
|
- |
|
| 156 |
public InvoiceGenerationService() {
|
135 |
public InvoiceGenerationService() {
|
| 157 |
try {
|
136 |
try {
|
| 158 |
tsc = new TransactionClient();
|
137 |
tsc = new TransactionClient();
|
| 159 |
csc = new InventoryClient();
|
138 |
csc = new InventoryClient();
|
| 160 |
lsc = new LogisticsClient();
|
139 |
lsc = new LogisticsClient();
|
| Line 197... |
Line 176... |
| 197 |
|
176 |
|
| 198 |
for(Order order: orders){
|
177 |
for(Order order: orders){
|
| 199 |
Warehouse warehouse = null;
|
178 |
Warehouse warehouse = null;
|
| 200 |
Provider provider = null;
|
179 |
Provider provider = null;
|
| 201 |
String destCode = null;
|
180 |
String destCode = null;
|
| - |
|
181 |
Warehouse shippingLocation = null;
|
| 202 |
int barcodeFontSize = 0;
|
182 |
int barcodeFontSize = 0;
|
| 203 |
try {
|
183 |
try {
|
| 204 |
warehouse = iclient.getWarehouse(order.getWarehouse_id());
|
184 |
warehouse = iclient.getWarehouse(order.getWarehouse_id());
|
| 205 |
long providerId = order.getLogistics_provider_id();
|
185 |
long providerId = order.getLogistics_provider_id();
|
| 206 |
provider = logisticsClient.getProvider(providerId);
|
186 |
provider = logisticsClient.getProvider(providerId);
|
| Line 208... |
Line 188... |
| 208 |
destCode = provider.getPickup().toString();
|
188 |
destCode = provider.getPickup().toString();
|
| 209 |
else
|
189 |
else
|
| 210 |
destCode = logisticsClient.getDestinationCode(providerId, order.getCustomer_pincode());
|
190 |
destCode = logisticsClient.getDestinationCode(providerId, order.getCustomer_pincode());
|
| 211 |
|
191 |
|
| 212 |
barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
|
192 |
barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
|
| - |
|
193 |
shippingLocation = CatalogUtils.getWarehouse(warehouse.getShippingWarehouseId());
|
| 213 |
} catch (InventoryServiceException ise) {
|
194 |
} catch (InventoryServiceException ise) {
|
| 214 |
logger.error("Error while getting the warehouse information.", ise);
|
195 |
logger.error("Error while getting the warehouse information.", ise);
|
| 215 |
return baosPDF;
|
196 |
return baosPDF;
|
| 216 |
} catch (LogisticsServiceException lse) {
|
197 |
} catch (LogisticsServiceException lse) {
|
| 217 |
logger.error("Error while getting the provider information.", lse);
|
198 |
logger.error("Error while getting the provider information.", lse);
|
| Line 231... |
Line 212... |
| 231 |
}
|
212 |
}
|
| 232 |
document.add(getExtraInfoTable(order, provider, 16, warehouse.getBillingType()));
|
213 |
document.add(getExtraInfoTable(order, provider, 16, warehouse.getBillingType()));
|
| 233 |
continue;
|
214 |
continue;
|
| 234 |
}
|
215 |
}
|
| 235 |
|
216 |
|
| 236 |
PdfPTable dispatchAdviceTable = getDispatchAdviceTable(order, warehouse, provider, barcodeFontSize, destCode, withBill);
|
217 |
PdfPTable dispatchAdviceTable = getDispatchAdviceTable(order, warehouse, provider, barcodeFontSize, destCode, withBill, shippingLocation);
|
| 237 |
dispatchAdviceTable.setSpacingAfter(10.0f);
|
218 |
dispatchAdviceTable.setSpacingAfter(10.0f);
|
| 238 |
dispatchAdviceTable.setWidthPercentage(90.0f);
|
219 |
dispatchAdviceTable.setWidthPercentage(90.0f);
|
| 239 |
|
220 |
|
| 240 |
document.add(dispatchAdviceTable);
|
221 |
document.add(dispatchAdviceTable);
|
| 241 |
if(withBill){
|
222 |
if(withBill){
|
| 242 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(order, provider);
|
223 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(order, provider, shippingLocation.getLocation(), shippingLocation.getPincode());
|
| 243 |
taxTable.setSpacingBefore(5.0f);
|
224 |
taxTable.setSpacingBefore(5.0f);
|
| 244 |
taxTable.setWidthPercentage(90.0f);
|
225 |
taxTable.setWidthPercentage(90.0f);
|
| 245 |
document.add(new DottedLineSeparator());
|
226 |
document.add(new DottedLineSeparator());
|
| 246 |
document.add(taxTable);
|
227 |
document.add(taxTable);
|
| 247 |
}else{
|
228 |
}else{
|
| Line 272... |
Line 253... |
| 272 |
logger.error("Error while generating Invoice: ", e);
|
253 |
logger.error("Error while generating Invoice: ", e);
|
| 273 |
}
|
254 |
}
|
| 274 |
return baosPDF;
|
255 |
return baosPDF;
|
| 275 |
}
|
256 |
}
|
| 276 |
|
257 |
|
| 277 |
private PdfPTable getDispatchAdviceTable(Order order, Warehouse warehouse, Provider provider, float barcodeFontSize, String destCode, boolean withBill){
|
258 |
private PdfPTable getDispatchAdviceTable(Order order, Warehouse warehouse, Provider provider, float barcodeFontSize, String destCode, boolean withBill, Warehouse shippingLocation){
|
| 278 |
Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
|
259 |
Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
|
| 279 |
|
260 |
|
| 280 |
PdfPTable table = new PdfPTable(1);
|
261 |
PdfPTable table = new PdfPTable(1);
|
| 281 |
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
262 |
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 282 |
|
263 |
|
| Line 291... |
Line 272... |
| 291 |
dispatchTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
272 |
dispatchTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 292 |
dispatchTable.addCell(customerTable);
|
273 |
dispatchTable.addCell(customerTable);
|
| 293 |
dispatchTable.addCell(new Phrase(" "));
|
274 |
dispatchTable.addCell(new Phrase(" "));
|
| 294 |
dispatchTable.addCell(providerInfoTable);
|
275 |
dispatchTable.addCell(providerInfoTable);
|
| 295 |
|
276 |
|
| 296 |
Warehouse shippingLocation = CatalogUtils.getWarehouse(warehouse.getShippingWarehouseId());
|
- |
|
| 297 |
PdfPTable invoiceTable = getTopInvoiceTable(order, shippingLocation.getTinNumber());
|
277 |
PdfPTable invoiceTable = getTopInvoiceTable(order, shippingLocation.getTinNumber());
|
| 298 |
PdfPCell addressCell = getAddressCell(shippingLocation.getLocation() +
|
278 |
PdfPCell addressCell = getAddressCell(shippingLocation.getLocation() +
|
| 299 |
"\nPIN " + warehouse.getPincode() + "\n\n");
|
279 |
"\nPIN " + warehouse.getPincode() + "\n\n");
|
| 300 |
|
280 |
|
| 301 |
PdfPTable chargesTable = new PdfPTable(1);
|
281 |
PdfPTable chargesTable = new PdfPTable(1);
|
| Line 451... |
Line 431... |
| 451 |
warehouse = isc.getClient().getWarehouse(order.getWarehouse_id());
|
431 |
warehouse = isc.getClient().getWarehouse(order.getWarehouse_id());
|
| 452 |
} catch(Exception e) {
|
432 |
} catch(Exception e) {
|
| 453 |
logger.error("Unable to get warehouse for id : " + order.getWarehouse_id(), e);
|
433 |
logger.error("Unable to get warehouse for id : " + order.getWarehouse_id(), e);
|
| 454 |
//TODO throw e;
|
434 |
//TODO throw e;
|
| 455 |
}
|
435 |
}
|
| 456 |
String accountNo = "";
|
- |
|
| 457 |
DeliveryType dt = DeliveryType.PREPAID;
|
436 |
DeliveryType dt = DeliveryType.PREPAID;
|
| 458 |
if (order.isLogisticsCod()) {
|
437 |
if (order.isLogisticsCod()) {
|
| 459 |
dt = DeliveryType.COD;
|
438 |
dt = DeliveryType.COD;
|
| 460 |
}
|
439 |
}
|
| 461 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
440 |
//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
|
| Line 553... |
Line 532... |
| 553 |
addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
532 |
addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 554 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
533 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
| 555 |
return addressCell;
|
534 |
return addressCell;
|
| 556 |
}
|
535 |
}
|
| 557 |
|
536 |
|
| 558 |
private PdfPTable getTaxCumRetailInvoiceTable(Order order, Provider provider){
|
537 |
private PdfPTable getTaxCumRetailInvoiceTable(Order order, Provider provider, String ourAddress, String tinNo){
|
| 559 |
PdfPTable taxTable = new PdfPTable(1);
|
538 |
PdfPTable taxTable = new PdfPTable(1);
|
| 560 |
Phrase phrase = null;
|
539 |
Phrase phrase = null;
|
| 561 |
taxTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
540 |
taxTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 562 |
taxTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
541 |
taxTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 563 |
|
542 |
|