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