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