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