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