| 4687 |
mandeep.dh |
1 |
package in.shop2020.inventory.service;
|
|
|
2 |
|
|
|
3 |
import java.io.ByteArrayOutputStream;
|
|
|
4 |
import java.io.File;
|
|
|
5 |
import java.io.FileOutputStream;
|
|
|
6 |
import java.io.IOException;
|
|
|
7 |
import java.text.DateFormat;
|
| 19950 |
amit.gupta |
8 |
import java.text.ParseException;
|
|
|
9 |
import java.text.SimpleDateFormat;
|
| 14082 |
manish.sha |
10 |
import java.util.Calendar;
|
| 4687 |
mandeep.dh |
11 |
import java.util.Date;
|
| 14072 |
manish.sha |
12 |
import java.util.Map;
|
| 4687 |
mandeep.dh |
13 |
|
| 19950 |
amit.gupta |
14 |
import org.apache.log4j.helpers.DateTimeDateFormat;
|
| 14072 |
manish.sha |
15 |
import org.apache.thrift.TException;
|
| 4687 |
mandeep.dh |
16 |
import org.slf4j.Logger;
|
|
|
17 |
import org.slf4j.LoggerFactory;
|
|
|
18 |
|
|
|
19 |
import com.itextpdf.text.Document;
|
|
|
20 |
import com.itextpdf.text.Element;
|
|
|
21 |
import com.itextpdf.text.Font;
|
|
|
22 |
import com.itextpdf.text.Font.FontFamily;
|
|
|
23 |
import com.itextpdf.text.FontFactory;
|
|
|
24 |
import com.itextpdf.text.Paragraph;
|
|
|
25 |
import com.itextpdf.text.Phrase;
|
|
|
26 |
import com.itextpdf.text.Rectangle;
|
|
|
27 |
import com.itextpdf.text.pdf.PdfPCell;
|
|
|
28 |
import com.itextpdf.text.pdf.PdfPTable;
|
|
|
29 |
import com.itextpdf.text.pdf.PdfWriter;
|
| 19950 |
amit.gupta |
30 |
|
|
|
31 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
|
|
32 |
import in.shop2020.model.v1.inventory.StateInfo;
|
|
|
33 |
import in.shop2020.model.v1.inventory.VatType;
|
|
|
34 |
import in.shop2020.purchase.PurchaseOrder;
|
|
|
35 |
import in.shop2020.purchase.Supplier;
|
|
|
36 |
import in.shop2020.purchase.TaxType;
|
| 14072 |
manish.sha |
37 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
38 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 19950 |
amit.gupta |
39 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 4687 |
mandeep.dh |
40 |
|
|
|
41 |
public class PdfPoSheetGenerator {
|
|
|
42 |
|
|
|
43 |
private static Logger logger = LoggerFactory
|
|
|
44 |
.getLogger(PdfPoSheetGenerator.class);
|
|
|
45 |
|
|
|
46 |
// private static final Properties properties = readProperties();
|
| 7410 |
amar.kumar |
47 |
private static final String ourAddressDelhi = "Spice Online Retail Pvt. Ltd.\nC/O,PIBCO LIMITED, Basement,Punjsons\n2,Kalkaji Industrial Area, New Delhi-110019\n";
|
| 19950 |
amit.gupta |
48 |
private static final String ourNewCompanyAddressDelhi = "New Spice Online Retail Pvt. Ltd.\nC/O,PIBCO LIMITED, Basement,Punjsons\n2,Kalkaji Industrial Area, New Delhi-110019\n";
|
| 7676 |
amar.kumar |
49 |
private static final String ourAddressBhiwandi = "Spice Online Retail Pvt. Ltd.\nC/O. FedEx Express Transportation and Supply Chain Services (India) Private Limited.\nC/O NDR WAREHOUSING, SURVEY NO.95, MUMBAI - NASIK HIGHWAY, WADAPE VILLAGE\nBHIWANDI (NR. SAI DHABA), Thane,Maharashtra -421302\n";
|
| 7410 |
amar.kumar |
50 |
private static final String ourAddressGoregaon = "Spice Online Retail Pvt. Ltd.\n93/743, Motilal Nagar-1, Goregaon(WEST),\nMotilal Nagar, Mumbai, Maharashtra-400062\n";
|
| 10877 |
manish.sha |
51 |
private static final String ourAddressBangalore = "Spice Online Retail Pvt. Ltd.\n C/O.Drive India Enterprise Solutions Limited)\n Survey No. 86, Korulur Village, Kasab Hobli\n Hoskote Taluka\n Bangalore – 560067, Karnataka\n";
|
|
|
52 |
private static final String ourAddressBangaloreSR = "Spice Online Retail Pvt. Ltd.\n Shop No. 320, Municipal 59th Cross,\n Next to Rammandir Ground,\n 3rd Block, Rajaji Nagar,\nBangalore - 560010, Karnataka\n";
|
| 12769 |
manish.sha |
53 |
private static final String ourAddressGurgaon = "Spice Online Retail Private Limited,\n SHOP NO. 10 & 11,\n OLD DELHI ROAD,OPP SECTOR-14, GURGAON-122001 Haryana\n";
|
|
|
54 |
private static final String ourAddressHyderabad = "Spice Online Retail Pvt. Ltd, Drive India Enterprise Solutions Limited, 16,17&18, Gundllapochampalli, Kompalli, Medchal Mandal, Secandrabad-500014, Dist- Hyderabad";
|
| 13051 |
manish.sha |
55 |
private static final String ourAddressGurgaonS = "Spice Online Retail Pvt Ltd. \nC/O.Drive India Enterprise Solutions Ltd, \nKhasra No.2771,Main Sheetla Mata Mandir Road \nOpposite Sec-5,Petrol Pump(Bharat Petroliam) \nNear Anmol Vatika, Gurgaon- 122001";
|
| 10877 |
manish.sha |
56 |
|
| 9925 |
amar.kumar |
57 |
private static final String amazonAddress = "Spice Online Retail Pvt. Ltd. C/O Amazon Seller Services Pvt. Ltd.,\nBuilding H Prathmesh Complex, Saravali Village,\nOpp Hotel Vatika Kalyan, Bhivandi Junction,\nBhiwandi, Maharashtra\n";
|
| 10877 |
manish.sha |
58 |
private static final String amazonAddreseBangalore = "Spice Online Retail Pvt. Ltd.\n C/O Amazon Seller Services Pvt. Ltd.\n 38 & 39, Soukya Road,\n kacherakanahalli,\n Hoskote Taluka,\n Bangalore -560067, Karnataka\n";
|
| 12752 |
manish.sha |
59 |
private static final String amazonAddressMewat = "Spice Online Retail Pvt. Ltd.\n C/O AMAZON Seller Services Pvt. Limited,\n Gokaldas Warehousing Corporation, Unit No 1,\n Village Taoru, Tehsil Taoru, Distt Mewat - 122105";
|
| 15387 |
manish.sha |
60 |
private static final String amazonAddressDelhi = "Spice Online Retail Pvt Ltd., \nC/O Amazon Seller Services Pvt. Ltd., \nA43 GF MOHAN COOPERATIVE IND, \nESTATE MAIN MATHURA ROAD, \nBADARPUR SOUTH DELHI, Delhi -110044";
|
| 12543 |
manish.sha |
61 |
private static final String flipkartAddressGgn = "Spice Online Retail Pvt. Ltd.\n C/O. Flipkart Internet Pvt. Ltd, \n KILLA NO.219/15-16 25/1 220/11 12/1 12/2 13/1/113/1/2 20 21/1 21/2/1 22/1 23/1/1,\n Bohra Kalan, PATAUDI, GURGAON - 122001, Haryana\n";
|
| 13354 |
manish.sha |
62 |
private static final String flipkartAddressDelhi = "Spice Online Retail Pvt. Ltd.\n C/O Flipkart Internet Pvt. Ltd.\n Khasra No. 435,Road No.# 04 ,Lal Dora Extension,\nMahipalpur, New Delhi- 110037\n";
|
| 13938 |
manish.sha |
63 |
private static final String snapdealAddressDelhi = "Spice Online Retail Pvt. Ltd, \nC/O. Gati Kintetsu Express Pvt Ltd.,\nPlot In Khasra No. 15/17,24, G/F, \nVillage- Samalkha, New Delhi - 110037";
|
| 7410 |
amar.kumar |
64 |
private static final String tinNoDelhi = "07250399732";
|
| 19950 |
amit.gupta |
65 |
private static final String newCompanyTinNoDelhi = "07250399733";
|
| 7410 |
amar.kumar |
66 |
private static final String tinNoMum = "27450984008";
|
| 10877 |
manish.sha |
67 |
private static final String tinNoBan = "29171183852";
|
| 12543 |
manish.sha |
68 |
private static final String tinNoFkGgn = "06681944625";
|
|
|
69 |
private static final String tinNoOurGgn = "06681944625";
|
| 12769 |
manish.sha |
70 |
private static final String tinNoOurHyd = "36601220768";
|
| 13354 |
manish.sha |
71 |
private static final String tinNoFkDelhi = "07720408834";
|
| 12543 |
manish.sha |
72 |
|
| 4687 |
mandeep.dh |
73 |
|
|
|
74 |
private static final Font helvetica8 = FontFactory.getFont(
|
|
|
75 |
FontFactory.HELVETICA, 8);
|
|
|
76 |
|
|
|
77 |
private static final Font helveticaBold8 = FontFactory.getFont(
|
|
|
78 |
FontFactory.HELVETICA_BOLD, 8);
|
|
|
79 |
private static final Font helveticaBold12 = FontFactory.getFont(
|
|
|
80 |
FontFactory.HELVETICA_BOLD, 12);
|
| 14072 |
manish.sha |
81 |
|
|
|
82 |
public static Map<Long, StateInfo> stateIdMap = null;
|
| 19950 |
amit.gupta |
83 |
public static long cutoffTime = 0;
|
| 4687 |
mandeep.dh |
84 |
|
| 14072 |
manish.sha |
85 |
static{
|
|
|
86 |
try{
|
|
|
87 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
|
|
88 |
stateIdMap = inventoryClient.getStateMaster();
|
| 19950 |
amit.gupta |
89 |
String cutOffDate = ConfigClient.getClient().get("warehouse_company_cutoff_date");
|
|
|
90 |
DateFormat df = new SimpleDateFormat("yyyy-mm-dd");
|
|
|
91 |
cutoffTime = df.parse(cutOffDate).getTime();
|
| 14072 |
manish.sha |
92 |
|
|
|
93 |
} catch(Exception e){
|
| 19950 |
amit.gupta |
94 |
logger.error("Could not initialize static block", e);
|
|
|
95 |
System.exit(0);
|
| 14072 |
manish.sha |
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
| 4687 |
mandeep.dh |
99 |
public static String generatePdfSheet(PurchaseOrder purchaseOrder,
|
|
|
100 |
Supplier supplier) throws IOException {
|
|
|
101 |
ByteArrayOutputStream baosPDF = null;
|
|
|
102 |
try {
|
| 14072 |
manish.sha |
103 |
baosPDF = new ByteArrayOutputStream();
|
| 4687 |
mandeep.dh |
104 |
|
|
|
105 |
Document document = new Document();
|
|
|
106 |
PdfWriter.getInstance(document, baosPDF);
|
|
|
107 |
document.addAuthor("shop2020");
|
|
|
108 |
document.addTitle("Purchase Order No: "
|
|
|
109 |
+ purchaseOrder.getPoNumber());
|
|
|
110 |
document.open();
|
|
|
111 |
|
|
|
112 |
PdfPTable poTable = getPoTable(purchaseOrder, supplier);
|
|
|
113 |
poTable.setSpacingAfter(10.0f);
|
|
|
114 |
poTable.setWidthPercentage(90.0f);
|
|
|
115 |
|
|
|
116 |
document.add(poTable);
|
|
|
117 |
document.close();
|
|
|
118 |
baosPDF.close();
|
|
|
119 |
} catch (Exception e) {
|
|
|
120 |
logger.error("Error while generating Invoice: ", e);
|
| 14200 |
manish.sha |
121 |
e.printStackTrace();
|
| 4687 |
mandeep.dh |
122 |
}
|
|
|
123 |
|
|
|
124 |
String tmpDir = System.getProperty("java.io.tmpdir");
|
|
|
125 |
String filename = tmpDir + "/po-" + purchaseOrder.getId() + ".pdf";
|
|
|
126 |
File f = new File(filename);
|
|
|
127 |
FileOutputStream fos = new FileOutputStream(f);
|
|
|
128 |
baosPDF.writeTo(fos);
|
|
|
129 |
return filename;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
private static PdfPTable getPoTable(PurchaseOrder purchaseOrder,
|
|
|
133 |
Supplier supplier) throws Exception {
|
|
|
134 |
PdfPTable poTable = new PdfPTable(1);
|
|
|
135 |
poTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
136 |
poTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
137 |
|
|
|
138 |
PdfPCell poTitleCell = new PdfPCell(new Phrase("Purchase Order",
|
|
|
139 |
helveticaBold12));
|
|
|
140 |
poTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
141 |
poTitleCell.setBorder(Rectangle.NO_BORDER);
|
|
|
142 |
|
| 14082 |
manish.sha |
143 |
long poValidityLimit = supplier.getPoValidityLimit();
|
|
|
144 |
Calendar cal1 = Calendar.getInstance();
|
|
|
145 |
cal1.setTimeInMillis(purchaseOrder.getCreatedAt());
|
|
|
146 |
cal1.add(Calendar.DAY_OF_MONTH, (int)poValidityLimit);
|
| 4687 |
mandeep.dh |
147 |
Date poDate = new Date(purchaseOrder.getCreatedAt());
|
| 14082 |
manish.sha |
148 |
Date poExpiryDate = new Date(cal1.getTimeInMillis());
|
|
|
149 |
|
|
|
150 |
|
| 14091 |
manish.sha |
151 |
PdfPTable poSummaryTable = new PdfPTable(new float[] { 0.3f, 0.3f, 0.4f });
|
| 4687 |
mandeep.dh |
152 |
poSummaryTable.addCell(new PdfPCell(new Phrase("PO No: "
|
|
|
153 |
+ purchaseOrder.getPoNumber())));
|
| 9416 |
amar.kumar |
154 |
poSummaryTable.addCell(new PdfPCell(new Phrase("Date: "
|
|
|
155 |
+ DateFormat.getDateInstance(DateFormat.MEDIUM).format(
|
|
|
156 |
poDate))));
|
| 14092 |
manish.sha |
157 |
poSummaryTable.addCell(new PdfPCell(new Phrase("PO Valid for delivery by: "
|
| 14082 |
manish.sha |
158 |
+ DateFormat.getDateInstance(DateFormat.MEDIUM).format(
|
|
|
159 |
poExpiryDate))));
|
| 4687 |
mandeep.dh |
160 |
poSummaryTable.setSpacingBefore(10.0f);
|
|
|
161 |
|
|
|
162 |
poTable.addCell(poTitleCell);
|
| 19950 |
amit.gupta |
163 |
poTable.addCell(getAddressCell(purchaseOrder.getWarehouseId(), purchaseOrder.getShippingWarehouseId(), purchaseOrder.getCreatedAt()));
|
| 4687 |
mandeep.dh |
164 |
poTable.addCell(poSummaryTable);
|
|
|
165 |
poTable.addCell(getSalutationTable(supplier));
|
| 14072 |
manish.sha |
166 |
poTable.addCell(getPoDetailsTable(purchaseOrder, supplier));
|
| 9591 |
amar.kumar |
167 |
poTable.addCell(getBillToTable(purchaseOrder.getWarehouseId(), purchaseOrder.getTaxType()));
|
|
|
168 |
//poTable.addCell(getCFormCell(purchaseOrder.getTaxType()));
|
| 4687 |
mandeep.dh |
169 |
|
|
|
170 |
return poTable;
|
|
|
171 |
}
|
|
|
172 |
|
| 9416 |
amar.kumar |
173 |
private static PdfPCell getCFormCell(TaxType taxType) {
|
|
|
174 |
PdfPCell cFormCell = null;
|
|
|
175 |
if(taxType == TaxType.CFORM) {
|
| 9586 |
amar.kumar |
176 |
cFormCell = new PdfPCell(new Paragraph("*To be billed on CST Against C-Form ", new Font(FontFamily.TIMES_ROMAN, 8f)));
|
| 9416 |
amar.kumar |
177 |
} else {
|
|
|
178 |
cFormCell = new PdfPCell();
|
|
|
179 |
}
|
|
|
180 |
cFormCell.setBorder(Rectangle.NO_BORDER);
|
|
|
181 |
cFormCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
182 |
return cFormCell;
|
|
|
183 |
}
|
|
|
184 |
|
| 19950 |
amit.gupta |
185 |
private static PdfPTable getAddressCell(long warehouseId, long shippingWarehouseId, long createdAt) {
|
| 7410 |
amar.kumar |
186 |
//TODO Write this code in a proper configurable way
|
|
|
187 |
String address = "";
|
|
|
188 |
String tinNo = "";
|
| 9925 |
amar.kumar |
189 |
String shippingAddress = "";
|
|
|
190 |
String shippingTinNo = "";
|
| 7410 |
amar.kumar |
191 |
if(warehouseId ==7) {
|
| 19950 |
amit.gupta |
192 |
if(createdAt < cutoffTime) {
|
|
|
193 |
address = ourAddressDelhi;
|
|
|
194 |
tinNo = tinNoDelhi;
|
|
|
195 |
} else {
|
|
|
196 |
address = ourNewCompanyAddressDelhi;
|
|
|
197 |
tinNo = newCompanyTinNoDelhi;
|
|
|
198 |
}
|
| 7410 |
amar.kumar |
199 |
} else if(warehouseId == 12) {
|
|
|
200 |
address = ourAddressGoregaon;
|
|
|
201 |
tinNo = tinNoMum;
|
|
|
202 |
} else if(warehouseId == 13) {
|
|
|
203 |
address = ourAddressBhiwandi;
|
|
|
204 |
tinNo = tinNoMum;
|
| 7466 |
amar.kumar |
205 |
} else if(warehouseId ==16) {
|
| 7464 |
amar.kumar |
206 |
address = amazonAddress;
|
|
|
207 |
tinNo = tinNoMum;
|
| 10877 |
manish.sha |
208 |
} else if(warehouseId ==1765){
|
|
|
209 |
address = ourAddressBangalore;
|
|
|
210 |
tinNo = tinNoBan;
|
|
|
211 |
} else if(warehouseId ==1768){
|
|
|
212 |
address = ourAddressBangaloreSR;
|
|
|
213 |
tinNo = tinNoBan;
|
|
|
214 |
} else if(warehouseId ==1771){
|
|
|
215 |
address = amazonAddreseBangalore;
|
|
|
216 |
tinNo = tinNoBan;
|
| 12543 |
manish.sha |
217 |
} else if(warehouseId == 2854){
|
|
|
218 |
address = flipkartAddressGgn;
|
|
|
219 |
tinNo = tinNoFkGgn;
|
|
|
220 |
} else if(warehouseId == 2857){
|
|
|
221 |
address = ourAddressGurgaon;
|
|
|
222 |
tinNo = tinNoOurGgn;
|
| 12769 |
manish.sha |
223 |
} else if(warehouseId == 3295){
|
|
|
224 |
address = amazonAddressMewat;
|
|
|
225 |
tinNo = tinNoOurGgn;
|
| 13354 |
manish.sha |
226 |
} else if(warehouseId == 3298){
|
| 12769 |
manish.sha |
227 |
address = ourAddressHyderabad;
|
|
|
228 |
tinNo = tinNoOurHyd;
|
| 13051 |
manish.sha |
229 |
} else if(warehouseId == 3931){
|
|
|
230 |
address = ourAddressGurgaonS;
|
|
|
231 |
tinNo = tinNoOurGgn;
|
| 13354 |
manish.sha |
232 |
} else if(warehouseId == 4699){
|
|
|
233 |
address = flipkartAddressDelhi;
|
|
|
234 |
tinNo = tinNoFkDelhi;
|
| 13938 |
manish.sha |
235 |
} else if(warehouseId == 5314){
|
|
|
236 |
address = snapdealAddressDelhi;
|
|
|
237 |
tinNo = tinNoFkDelhi;
|
| 15387 |
manish.sha |
238 |
} else if(warehouseId == 5623){
|
|
|
239 |
address = amazonAddressDelhi;
|
|
|
240 |
tinNo = tinNoDelhi;
|
| 12769 |
manish.sha |
241 |
}
|
| 9925 |
amar.kumar |
242 |
PdfPTable billToShipToTable = new PdfPTable(2);
|
| 7410 |
amar.kumar |
243 |
Paragraph addressParagraph = new Paragraph(address + "\nTIN NO. "
|
| 4687 |
mandeep.dh |
244 |
+ tinNo, new Font(FontFamily.TIMES_ROMAN, 8f));
|
|
|
245 |
PdfPCell addressCell = new PdfPCell();
|
| 9925 |
amar.kumar |
246 |
if(warehouseId != shippingWarehouseId) {
|
|
|
247 |
addressParagraph = new Paragraph("Bill To :\n" + address + "\n\nTIN NO. "
|
|
|
248 |
+ tinNo, new Font(FontFamily.TIMES_ROMAN, 8f));
|
|
|
249 |
}
|
| 4687 |
mandeep.dh |
250 |
addressCell.addElement(addressParagraph);
|
| 9925 |
amar.kumar |
251 |
//addressCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 4687 |
mandeep.dh |
252 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
| 9925 |
amar.kumar |
253 |
|
|
|
254 |
if(warehouseId != shippingWarehouseId) {
|
|
|
255 |
if(shippingWarehouseId ==7) {
|
|
|
256 |
shippingAddress = ourAddressDelhi;
|
|
|
257 |
shippingTinNo = tinNoDelhi;
|
|
|
258 |
} else if(shippingWarehouseId == 12) {
|
|
|
259 |
shippingAddress = ourAddressGoregaon;
|
|
|
260 |
shippingTinNo = tinNoMum;
|
|
|
261 |
} else if(shippingWarehouseId == 13) {
|
|
|
262 |
shippingAddress = ourAddressBhiwandi;
|
|
|
263 |
shippingTinNo = tinNoMum;
|
|
|
264 |
} else if(shippingWarehouseId ==16) {
|
|
|
265 |
shippingAddress = amazonAddress;
|
|
|
266 |
shippingTinNo = tinNoMum;
|
| 10877 |
manish.sha |
267 |
} else if(shippingWarehouseId ==1765){
|
|
|
268 |
shippingAddress = ourAddressBangalore;
|
|
|
269 |
shippingTinNo = tinNoBan;
|
|
|
270 |
} else if(shippingWarehouseId ==1768){
|
|
|
271 |
shippingAddress = ourAddressBangaloreSR;
|
|
|
272 |
shippingTinNo = tinNoBan;
|
|
|
273 |
} else if(shippingWarehouseId ==1771){
|
|
|
274 |
shippingAddress = amazonAddreseBangalore;
|
|
|
275 |
shippingTinNo = tinNoBan;
|
| 12543 |
manish.sha |
276 |
} else if(shippingWarehouseId == 2854){
|
|
|
277 |
shippingAddress = flipkartAddressGgn;
|
|
|
278 |
shippingTinNo = tinNoFkGgn;
|
|
|
279 |
} else if(shippingWarehouseId == 2857){
|
|
|
280 |
shippingAddress = ourAddressGurgaon;
|
|
|
281 |
shippingTinNo = tinNoOurGgn;
|
| 12729 |
manish.sha |
282 |
} else if(shippingWarehouseId == 3295){
|
|
|
283 |
shippingAddress = amazonAddressMewat;
|
|
|
284 |
shippingTinNo = tinNoOurGgn;
|
| 12769 |
manish.sha |
285 |
} else if(shippingWarehouseId == 3298){
|
|
|
286 |
shippingAddress = ourAddressHyderabad;
|
|
|
287 |
shippingTinNo = tinNoOurHyd;
|
| 13051 |
manish.sha |
288 |
} else if(shippingWarehouseId == 3931){
|
|
|
289 |
shippingAddress = ourAddressGurgaonS;
|
|
|
290 |
shippingTinNo = tinNoOurGgn;
|
| 13354 |
manish.sha |
291 |
} else if(shippingWarehouseId == 4699){
|
|
|
292 |
shippingAddress = flipkartAddressDelhi;
|
|
|
293 |
shippingTinNo = tinNoFkDelhi;
|
| 13938 |
manish.sha |
294 |
} else if(shippingWarehouseId == 5314){
|
|
|
295 |
shippingAddress = snapdealAddressDelhi;
|
|
|
296 |
shippingTinNo = tinNoFkDelhi;
|
| 15387 |
manish.sha |
297 |
} else if(shippingWarehouseId == 5623){
|
|
|
298 |
shippingAddress = amazonAddressDelhi;
|
|
|
299 |
shippingTinNo = tinNoDelhi;
|
| 9925 |
amar.kumar |
300 |
}
|
|
|
301 |
|
|
|
302 |
PdfPCell billToShipToCell = new PdfPCell();
|
|
|
303 |
billToShipToCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
304 |
billToShipToCell.setBorder(Rectangle.NO_BORDER);
|
|
|
305 |
|
|
|
306 |
PdfPCell shippingAddressCell = new PdfPCell();
|
|
|
307 |
shippingAddressCell.addElement(new Paragraph("Ship To :\n" +shippingAddress + "\nTIN NO. "
|
|
|
308 |
+ shippingTinNo, new Font(FontFamily.TIMES_ROMAN, 8f)));
|
|
|
309 |
shippingAddressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
310 |
shippingAddressCell.setBorder(Rectangle.LEFT);
|
|
|
311 |
billToShipToTable.addCell(addressCell);
|
|
|
312 |
billToShipToTable.addCell(shippingAddressCell);
|
|
|
313 |
billToShipToCell.addElement(billToShipToTable);
|
|
|
314 |
return billToShipToTable;
|
|
|
315 |
|
|
|
316 |
}
|
|
|
317 |
billToShipToTable.addCell(addressCell);
|
|
|
318 |
PdfPCell placeHolderCell = new PdfPCell();
|
|
|
319 |
placeHolderCell.setBorder(Rectangle.NO_BORDER);
|
|
|
320 |
billToShipToTable.addCell(placeHolderCell);
|
|
|
321 |
return billToShipToTable;
|
| 4687 |
mandeep.dh |
322 |
}
|
|
|
323 |
|
|
|
324 |
private static PdfPTable getSalutationTable(Supplier supplier)
|
|
|
325 |
throws Exception {
|
|
|
326 |
PdfPTable salutationTable = new PdfPTable(1);
|
|
|
327 |
salutationTable.getDefaultCell().setHorizontalAlignment(
|
|
|
328 |
Element.ALIGN_LEFT);
|
|
|
329 |
salutationTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
330 |
salutationTable.addCell(new Phrase("To", helvetica8));
|
| 8712 |
amar.kumar |
331 |
if(supplier.getName().equals("Smobility Ltd.")) {
|
|
|
332 |
salutationTable.addCell(new Phrase("Spice Retail Ltd.", helvetica8));
|
| 8713 |
amar.kumar |
333 |
} else if(supplier.getName().equals("Smobility Ltd. - Mumbai")) {
|
|
|
334 |
salutationTable.addCell(new Phrase("Spice Retail Ltd. Mumbai", helvetica8));
|
| 8712 |
amar.kumar |
335 |
} else {
|
|
|
336 |
salutationTable.addCell(new Phrase(supplier
|
|
|
337 |
.getName(), helvetica8));
|
|
|
338 |
}
|
|
|
339 |
|
| 4687 |
mandeep.dh |
340 |
salutationTable.addCell(new Paragraph(supplier
|
|
|
341 |
.getCommunicationAddress(), helvetica8));
|
|
|
342 |
salutationTable.addCell(new Phrase("Dear Sir/Madam", helveticaBold8));
|
|
|
343 |
salutationTable
|
|
|
344 |
.addCell(new Phrase(
|
|
|
345 |
"Please supply the following stocks as per the details given below:",
|
|
|
346 |
helvetica8));
|
|
|
347 |
salutationTable.addCell(new Phrase(" "));
|
|
|
348 |
return salutationTable;
|
|
|
349 |
}
|
|
|
350 |
|
| 14072 |
manish.sha |
351 |
private static PdfPTable getPoDetailsTable(PurchaseOrder purchaseOrder,Supplier supplier) throws CatalogServiceException, TException {
|
|
|
352 |
PdfPTable detailsTable = new PdfPTable(new float[] { 0.1f, 0.3f, 0.1f,
|
| 14082 |
manish.sha |
353 |
0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f });
|
| 4687 |
mandeep.dh |
354 |
detailsTable.addCell(new Phrase("Sl. No.", helveticaBold8));
|
|
|
355 |
detailsTable.addCell(new Phrase("Description", helveticaBold8));
|
|
|
356 |
detailsTable.addCell(new Phrase("Quantity", helveticaBold8));
|
| 9591 |
amar.kumar |
357 |
detailsTable.addCell(new Phrase("Mrp", helveticaBold8));
|
| 14072 |
manish.sha |
358 |
if(purchaseOrder.getTaxType()==TaxType.CFORM){
|
| 14091 |
manish.sha |
359 |
detailsTable.addCell(new Phrase("Rate Excl CST(Rs)", helveticaBold8));
|
|
|
360 |
} else {
|
|
|
361 |
detailsTable.addCell(new Phrase("Rate Excl VAT(Rs)", helveticaBold8));
|
|
|
362 |
}
|
|
|
363 |
if(purchaseOrder.getTaxType()==TaxType.CFORM){
|
| 14082 |
manish.sha |
364 |
detailsTable.addCell(new Phrase("CST%",helveticaBold8));
|
|
|
365 |
} else {
|
|
|
366 |
detailsTable.addCell(new Phrase("VAT%",helveticaBold8));
|
|
|
367 |
}
|
|
|
368 |
if(purchaseOrder.getTaxType()==TaxType.CFORM){
|
| 14072 |
manish.sha |
369 |
detailsTable.addCell(new Phrase("CST Amount",helveticaBold8));
|
|
|
370 |
} else {
|
|
|
371 |
detailsTable.addCell(new Phrase("VAT Amount",helveticaBold8));
|
|
|
372 |
}
|
| 14091 |
manish.sha |
373 |
if(purchaseOrder.getTaxType()==TaxType.CFORM){
|
|
|
374 |
detailsTable.addCell(new Phrase("Rate Incl CST(Rs)", helveticaBold8));
|
|
|
375 |
} else {
|
|
|
376 |
detailsTable.addCell(new Phrase("Rate Incl VAT(Rs)", helveticaBold8));
|
|
|
377 |
}
|
| 4687 |
mandeep.dh |
378 |
detailsTable.addCell(new Phrase("Amount (Rs)", helveticaBold8));
|
|
|
379 |
|
|
|
380 |
int slNo = 0;
|
|
|
381 |
double total = 0;
|
| 14072 |
manish.sha |
382 |
double vatFactor = 0;
|
|
|
383 |
double totalUnits = 0;
|
|
|
384 |
boolean isMRPVat = false;
|
| 14200 |
manish.sha |
385 |
CatalogClient cClient = new CatalogClient();
|
|
|
386 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = cClient.getClient();
|
| 14072 |
manish.sha |
387 |
if(stateIdMap.get(supplier.getStateId()).getVatType().equals(VatType.MRP)) {
|
|
|
388 |
isMRPVat = true;
|
|
|
389 |
}
|
| 4687 |
mandeep.dh |
390 |
for (in.shop2020.purchase.LineItem lineitem : purchaseOrder
|
|
|
391 |
.getLineitems()) {
|
|
|
392 |
slNo++;
|
|
|
393 |
detailsTable.addCell(new Phrase(slNo + "", helvetica8));
|
|
|
394 |
detailsTable.addCell(getProductNameCell(lineitem));
|
| 14092 |
manish.sha |
395 |
detailsTable.addCell(new Phrase(String.format("%.0f", lineitem.getQuantity()),
|
| 4687 |
mandeep.dh |
396 |
helvetica8));
|
| 14091 |
manish.sha |
397 |
if(lineitem.isSetMrp() && lineitem.getMrp()>0){
|
| 14092 |
manish.sha |
398 |
detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getMrp()),
|
| 14091 |
manish.sha |
399 |
helvetica8));
|
|
|
400 |
} else {
|
|
|
401 |
detailsTable.addCell(new Phrase(" ",
|
|
|
402 |
helvetica8));
|
|
|
403 |
}
|
| 14072 |
manish.sha |
404 |
if(purchaseOrder.getTaxType()==TaxType.CFORM){
|
|
|
405 |
vatFactor = 2.0;
|
|
|
406 |
} else {
|
| 14200 |
manish.sha |
407 |
if(!catalogClient.isAlive()){
|
|
|
408 |
catalogClient = cClient.getClient();
|
|
|
409 |
}
|
| 14072 |
manish.sha |
410 |
if(isMRPVat){
|
|
|
411 |
vatFactor = catalogClient.getVatPercentageForItem(lineitem.getItemId(), supplier.getStateId(), lineitem.getMrp());
|
|
|
412 |
}else{
|
|
|
413 |
vatFactor = catalogClient.getVatPercentageForItem(lineitem.getItemId(), supplier.getStateId(), lineitem.getUnitPrice());
|
|
|
414 |
}
|
|
|
415 |
}
|
| 14093 |
manish.sha |
416 |
double preVatPrice = lineitem.getUnitPrice()/(1+(vatFactor/100));
|
|
|
417 |
double taxAmount = preVatPrice * (vatFactor/100);
|
|
|
418 |
detailsTable.addCell(new Phrase(String.format("%.2f", preVatPrice),
|
| 14091 |
manish.sha |
419 |
helvetica8));
|
| 14092 |
manish.sha |
420 |
detailsTable.addCell(new Phrase(String.format("%.2f", vatFactor),
|
| 14082 |
manish.sha |
421 |
helvetica8));
|
| 14092 |
manish.sha |
422 |
detailsTable.addCell(new Phrase(String.format("%.2f", taxAmount),
|
| 14072 |
manish.sha |
423 |
helvetica8));
|
| 14092 |
manish.sha |
424 |
detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getUnitPrice()),
|
| 4687 |
mandeep.dh |
425 |
helvetica8));
|
|
|
426 |
double lineTotal = lineitem.getQuantity() * lineitem.getUnitPrice();
|
| 14072 |
manish.sha |
427 |
totalUnits += lineitem.getQuantity();
|
| 4687 |
mandeep.dh |
428 |
total += lineTotal;
|
| 14092 |
manish.sha |
429 |
detailsTable.addCell(new Phrase(String.format("%.2f", lineTotal), helvetica8));
|
| 4687 |
mandeep.dh |
430 |
}
|
| 14072 |
manish.sha |
431 |
detailsTable.addCell(getTotalCell(2));
|
| 14092 |
manish.sha |
432 |
detailsTable.addCell(new Phrase(String.format("%.0f", totalUnits), helvetica8));
|
| 14082 |
manish.sha |
433 |
detailsTable.addCell(getTotalAmountCell(6,total));
|
| 4687 |
mandeep.dh |
434 |
return detailsTable;
|
|
|
435 |
}
|
|
|
436 |
|
| 9591 |
amar.kumar |
437 |
private static PdfPTable getBillToTable(long warehouseId, TaxType taxType) {
|
| 7410 |
amar.kumar |
438 |
//TODO Write this code in a proper configurable way
|
|
|
439 |
String address = "";
|
|
|
440 |
String tinNo = "";
|
|
|
441 |
String contactPerson = "";
|
|
|
442 |
if(warehouseId ==7) {
|
|
|
443 |
address = ourAddressDelhi;
|
|
|
444 |
tinNo = tinNoDelhi;
|
| 16251 |
manish.sha |
445 |
contactPerson = "Mr. Varun Patiyal, Contact No. +91 8860488282, +91 9711178101";
|
| 7410 |
amar.kumar |
446 |
} else if(warehouseId == 12) {
|
|
|
447 |
address = ourAddressGoregaon;
|
|
|
448 |
tinNo = tinNoMum;
|
| 7421 |
amar.kumar |
449 |
contactPerson = "Mr. Avinash Sambhaji Lavange, Contact No. +91 9004049589";
|
| 7410 |
amar.kumar |
450 |
} else if(warehouseId == 13) {
|
|
|
451 |
address = ourAddressBhiwandi;
|
|
|
452 |
tinNo = tinNoMum;
|
| 12729 |
manish.sha |
453 |
contactPerson = "Mr. Vishal Tayade, Contact No. +91 9819231651";
|
| 7466 |
amar.kumar |
454 |
} else if(warehouseId ==16) {
|
|
|
455 |
address = amazonAddress;
|
|
|
456 |
tinNo = tinNoMum;
|
|
|
457 |
contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
|
| 13354 |
manish.sha |
458 |
} else if(warehouseId ==1765) {
|
| 10877 |
manish.sha |
459 |
address = ourAddressBangalore;
|
|
|
460 |
tinNo = tinNoBan;
|
| 12729 |
manish.sha |
461 |
contactPerson = "Mr. Ravi Kumar, Contact No. +91 9686392567";
|
| 10877 |
manish.sha |
462 |
}
|
|
|
463 |
else if(warehouseId ==1768) {
|
|
|
464 |
address = ourAddressBangaloreSR;
|
|
|
465 |
tinNo = tinNoBan;
|
| 12729 |
manish.sha |
466 |
contactPerson = "Mr. Ravi Kumar, Contact No. +91 9686392567";
|
| 10877 |
manish.sha |
467 |
}
|
|
|
468 |
else if(warehouseId ==1771) {
|
|
|
469 |
address = amazonAddreseBangalore;
|
|
|
470 |
tinNo = tinNoBan;
|
| 12729 |
manish.sha |
471 |
contactPerson = "Mr. Ravi Kumar, Contact No. +91 9686392567";
|
| 10877 |
manish.sha |
472 |
}
|
| 12543 |
manish.sha |
473 |
else if(warehouseId ==2854) {
|
|
|
474 |
address = flipkartAddressGgn;
|
|
|
475 |
tinNo = tinNoFkGgn;
|
|
|
476 |
contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
|
|
|
477 |
}
|
|
|
478 |
else if(warehouseId ==2857) {
|
|
|
479 |
address = ourAddressGurgaon;
|
|
|
480 |
tinNo = tinNoOurGgn;
|
|
|
481 |
contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
|
| 12729 |
manish.sha |
482 |
}
|
|
|
483 |
else if(warehouseId == 3295) {
|
|
|
484 |
address = amazonAddressMewat;
|
|
|
485 |
tinNo = tinNoOurGgn;
|
|
|
486 |
contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
|
| 12543 |
manish.sha |
487 |
}
|
| 12769 |
manish.sha |
488 |
else if(warehouseId == 3298) {
|
|
|
489 |
address = ourAddressHyderabad;
|
|
|
490 |
tinNo = tinNoOurHyd;
|
|
|
491 |
contactPerson = "Mr. Achyuta Ramaiah A, Contact No. +91 9246581582";
|
|
|
492 |
}
|
| 13051 |
manish.sha |
493 |
else if(warehouseId == 3931) {
|
|
|
494 |
address = ourAddressGurgaonS;
|
|
|
495 |
tinNo = tinNoOurGgn;
|
|
|
496 |
contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
|
|
|
497 |
}
|
| 13354 |
manish.sha |
498 |
else if(warehouseId == 4699) {
|
|
|
499 |
address = flipkartAddressDelhi;
|
|
|
500 |
tinNo = tinNoFkDelhi;
|
|
|
501 |
contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
|
|
|
502 |
}
|
| 13938 |
manish.sha |
503 |
else if(warehouseId == 5314){
|
|
|
504 |
address = snapdealAddressDelhi;
|
|
|
505 |
tinNo = tinNoFkDelhi;
|
|
|
506 |
contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
|
|
|
507 |
}
|
| 15387 |
manish.sha |
508 |
else if(warehouseId == 5623){
|
|
|
509 |
address = amazonAddressDelhi;
|
|
|
510 |
tinNo = tinNoDelhi;
|
|
|
511 |
contactPerson = "Mr. Sandeep Sachdeva, Contact No. +91 9716691287";
|
|
|
512 |
}
|
| 7410 |
amar.kumar |
513 |
|
| 4687 |
mandeep.dh |
514 |
PdfPTable billToTable = new PdfPTable(new float[] { 0.2f, 0.8f });
|
|
|
515 |
billToTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
516 |
|
| 9925 |
amar.kumar |
517 |
billToTable.addCell(new Phrase("Bill To :", helvetica8));
|
| 7410 |
amar.kumar |
518 |
billToTable.addCell(new PdfPCell(new Paragraph(address
|
| 4687 |
mandeep.dh |
519 |
+ "\nTIN NO. " + tinNo, helvetica8)));
|
|
|
520 |
|
|
|
521 |
billToTable.addCell(new Phrase("Contact Person:", helvetica8));
|
| 7410 |
amar.kumar |
522 |
billToTable.addCell(new Phrase(contactPerson, helvetica8));
|
| 4687 |
mandeep.dh |
523 |
|
|
|
524 |
billToTable.addCell(new Phrase("Taxes:", helvetica8));
|
| 9591 |
amar.kumar |
525 |
if(taxType == TaxType.CFORM) {
|
|
|
526 |
billToTable.addCell(new Phrase("Prices inclusive of all taxes (To be billed on CST Against C-Form)",
|
|
|
527 |
helvetica8));
|
|
|
528 |
} else {
|
|
|
529 |
billToTable.addCell(new Phrase("Prices inclusive of all taxes",
|
|
|
530 |
helvetica8));
|
|
|
531 |
}
|
| 4687 |
mandeep.dh |
532 |
|
|
|
533 |
return billToTable;
|
|
|
534 |
}
|
|
|
535 |
|
|
|
536 |
private static PdfPCell getProductNameCell(
|
|
|
537 |
in.shop2020.purchase.LineItem lineitem) {
|
|
|
538 |
String itemName = getItemDisplayName(lineitem);
|
|
|
539 |
PdfPCell productNameCell = new PdfPCell(
|
|
|
540 |
new Phrase(itemName, helvetica8));
|
|
|
541 |
productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
542 |
return productNameCell;
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
private static String getItemDisplayName(
|
|
|
546 |
in.shop2020.purchase.LineItem lineitem) {
|
|
|
547 |
StringBuffer itemName = new StringBuffer();
|
|
|
548 |
if (lineitem.getBrand() != null)
|
|
|
549 |
itemName.append(lineitem.getBrand() + " ");
|
|
|
550 |
if (lineitem.getModelName() != null)
|
|
|
551 |
itemName.append(lineitem.getModelName() + " ");
|
|
|
552 |
if (lineitem.getModelNumber() != null)
|
|
|
553 |
itemName.append(lineitem.getModelNumber() + " ");
|
|
|
554 |
if (lineitem.getColor() != null
|
|
|
555 |
&& !lineitem.getColor().trim().equals("NA"))
|
|
|
556 |
itemName.append("(" + lineitem.getColor() + ")");
|
|
|
557 |
|
|
|
558 |
return itemName.toString();
|
|
|
559 |
}
|
|
|
560 |
|
|
|
561 |
private static PdfPCell getTotalCell(int colspan) {
|
|
|
562 |
PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
|
|
|
563 |
totalCell.setColspan(colspan);
|
|
|
564 |
totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
565 |
return totalCell;
|
|
|
566 |
}
|
| 14072 |
manish.sha |
567 |
|
|
|
568 |
private static PdfPCell getTotalAmountCell(int colspan, double totalAmount){
|
| 14092 |
manish.sha |
569 |
PdfPCell totalCell = new PdfPCell(new Phrase(String.format("%.2f", totalAmount), helvetica8));
|
| 14072 |
manish.sha |
570 |
totalCell.setColspan(colspan);
|
| 14073 |
manish.sha |
571 |
totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| 14072 |
manish.sha |
572 |
return totalCell;
|
|
|
573 |
}
|
| 4687 |
mandeep.dh |
574 |
|
|
|
575 |
}
|