| Line 1... |
Line 1... |
| 1 |
package in.shop2020.inventory.service;
|
1 |
package in.shop2020.inventory.service;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.inventory.controllers.PurchaseOrderController;
|
- |
|
| 4 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
3 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
| 5 |
import in.shop2020.model.v1.inventory.StateInfo;
|
4 |
import in.shop2020.model.v1.inventory.StateInfo;
|
| 6 |
import in.shop2020.model.v1.inventory.VatType;
|
5 |
import in.shop2020.model.v1.inventory.VatType;
|
| 7 |
import in.shop2020.model.v1.inventory.Warehouse;
|
- |
|
| 8 |
import in.shop2020.purchase.PurchaseOrder;
|
6 |
import in.shop2020.purchase.PurchaseOrder;
|
| 9 |
import in.shop2020.purchase.Supplier;
|
7 |
import in.shop2020.purchase.Supplier;
|
| 10 |
import in.shop2020.purchase.TaxType;
|
8 |
import in.shop2020.purchase.TaxType;
|
| 11 |
|
9 |
|
| 12 |
import java.io.ByteArrayOutputStream;
|
10 |
import java.io.ByteArrayOutputStream;
|
| 13 |
import java.io.File;
|
11 |
import java.io.File;
|
| 14 |
import java.io.FileOutputStream;
|
12 |
import java.io.FileOutputStream;
|
| 15 |
import java.io.IOException;
|
13 |
import java.io.IOException;
|
| 16 |
import java.math.BigDecimal;
|
14 |
import java.math.BigDecimal;
|
| 17 |
import java.text.DateFormat;
|
15 |
import java.text.DateFormat;
|
| - |
|
16 |
import java.util.Calendar;
|
| 18 |
import java.util.Date;
|
17 |
import java.util.Date;
|
| 19 |
import java.util.Map;
|
18 |
import java.util.Map;
|
| 20 |
|
19 |
|
| 21 |
import org.apache.thrift.TException;
|
20 |
import org.apache.thrift.TException;
|
| 22 |
import org.apache.thrift.transport.TTransportException;
|
21 |
import org.apache.thrift.transport.TTransportException;
|
| Line 32... |
Line 31... |
| 32 |
import com.itextpdf.text.Phrase;
|
31 |
import com.itextpdf.text.Phrase;
|
| 33 |
import com.itextpdf.text.Rectangle;
|
32 |
import com.itextpdf.text.Rectangle;
|
| 34 |
import com.itextpdf.text.pdf.PdfPCell;
|
33 |
import com.itextpdf.text.pdf.PdfPCell;
|
| 35 |
import com.itextpdf.text.pdf.PdfPTable;
|
34 |
import com.itextpdf.text.pdf.PdfPTable;
|
| 36 |
import com.itextpdf.text.pdf.PdfWriter;
|
35 |
import com.itextpdf.text.pdf.PdfWriter;
|
| 37 |
import in.shop2020.purchase.PurchaseService.Client;
|
- |
|
| 38 |
import in.shop2020.thrift.clients.CatalogClient;
|
36 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 39 |
import in.shop2020.thrift.clients.InventoryClient;
|
37 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 40 |
import in.shop2020.thrift.clients.PurchaseClient;
|
- |
|
| 41 |
|
38 |
|
| 42 |
public class PdfPoSheetGenerator {
|
39 |
public class PdfPoSheetGenerator {
|
| 43 |
|
40 |
|
| 44 |
private static Logger logger = LoggerFactory
|
41 |
private static Logger logger = LoggerFactory
|
| 45 |
.getLogger(PdfPoSheetGenerator.class);
|
42 |
.getLogger(PdfPoSheetGenerator.class);
|
| Line 130... |
Line 127... |
| 130 |
PdfPCell poTitleCell = new PdfPCell(new Phrase("Purchase Order",
|
127 |
PdfPCell poTitleCell = new PdfPCell(new Phrase("Purchase Order",
|
| 131 |
helveticaBold12));
|
128 |
helveticaBold12));
|
| 132 |
poTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
129 |
poTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 133 |
poTitleCell.setBorder(Rectangle.NO_BORDER);
|
130 |
poTitleCell.setBorder(Rectangle.NO_BORDER);
|
| 134 |
|
131 |
|
| - |
|
132 |
long poValidityLimit = supplier.getPoValidityLimit();
|
| - |
|
133 |
Calendar cal1 = Calendar.getInstance();
|
| - |
|
134 |
cal1.setTimeInMillis(purchaseOrder.getCreatedAt());
|
| - |
|
135 |
cal1.add(Calendar.DAY_OF_MONTH, (int)poValidityLimit);
|
| 135 |
Date poDate = new Date(purchaseOrder.getCreatedAt());
|
136 |
Date poDate = new Date(purchaseOrder.getCreatedAt());
|
| - |
|
137 |
Date poExpiryDate = new Date(cal1.getTimeInMillis());
|
| - |
|
138 |
|
| - |
|
139 |
|
| 136 |
PdfPTable poSummaryTable = new PdfPTable(new float[] { 0.5f, 0.5f });
|
140 |
PdfPTable poSummaryTable = new PdfPTable(new float[] { 0.35f, 0.3f, 0.35f });
|
| 137 |
poSummaryTable.addCell(new PdfPCell(new Phrase("PO No: "
|
141 |
poSummaryTable.addCell(new PdfPCell(new Phrase("PO No: "
|
| 138 |
+ purchaseOrder.getPoNumber())));
|
142 |
+ purchaseOrder.getPoNumber())));
|
| 139 |
poSummaryTable.addCell(new PdfPCell(new Phrase("Date: "
|
143 |
poSummaryTable.addCell(new PdfPCell(new Phrase("Date: "
|
| 140 |
+ DateFormat.getDateInstance(DateFormat.MEDIUM).format(
|
144 |
+ DateFormat.getDateInstance(DateFormat.MEDIUM).format(
|
| 141 |
poDate))));
|
145 |
poDate))));
|
| - |
|
146 |
poSummaryTable.addCell(new PdfPCell(new Phrase("Expiry Date: "
|
| - |
|
147 |
+ DateFormat.getDateInstance(DateFormat.MEDIUM).format(
|
| - |
|
148 |
poExpiryDate))));
|
| 142 |
poSummaryTable.setSpacingBefore(10.0f);
|
149 |
poSummaryTable.setSpacingBefore(10.0f);
|
| 143 |
|
150 |
|
| 144 |
poTable.addCell(poTitleCell);
|
151 |
poTable.addCell(poTitleCell);
|
| 145 |
poTable.addCell(getAddressCell(purchaseOrder.getWarehouseId(), purchaseOrder.getShippingWarehouseId()));
|
152 |
poTable.addCell(getAddressCell(purchaseOrder.getWarehouseId(), purchaseOrder.getShippingWarehouseId()));
|
| 146 |
poTable.addCell(poSummaryTable);
|
153 |
poTable.addCell(poSummaryTable);
|
| Line 319... |
Line 326... |
| 319 |
return salutationTable;
|
326 |
return salutationTable;
|
| 320 |
}
|
327 |
}
|
| 321 |
|
328 |
|
| 322 |
private static PdfPTable getPoDetailsTable(PurchaseOrder purchaseOrder,Supplier supplier) throws CatalogServiceException, TException {
|
329 |
private static PdfPTable getPoDetailsTable(PurchaseOrder purchaseOrder,Supplier supplier) throws CatalogServiceException, TException {
|
| 323 |
PdfPTable detailsTable = new PdfPTable(new float[] { 0.1f, 0.3f, 0.1f,
|
330 |
PdfPTable detailsTable = new PdfPTable(new float[] { 0.1f, 0.3f, 0.1f,
|
| 324 |
0.1f, 0.1f, 0.1f, 0.15f, 0.15f });
|
331 |
0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f });
|
| 325 |
detailsTable.addCell(new Phrase("Sl. No.", helveticaBold8));
|
332 |
detailsTable.addCell(new Phrase("Sl. No.", helveticaBold8));
|
| 326 |
detailsTable.addCell(new Phrase("Description", helveticaBold8));
|
333 |
detailsTable.addCell(new Phrase("Description", helveticaBold8));
|
| 327 |
detailsTable.addCell(new Phrase("Quantity", helveticaBold8));
|
334 |
detailsTable.addCell(new Phrase("Quantity", helveticaBold8));
|
| 328 |
detailsTable.addCell(new Phrase("Mrp", helveticaBold8));
|
335 |
detailsTable.addCell(new Phrase("Mrp", helveticaBold8));
|
| 329 |
if(purchaseOrder.getTaxType()==TaxType.CFORM){
|
336 |
if(purchaseOrder.getTaxType()==TaxType.CFORM){
|
| - |
|
337 |
detailsTable.addCell(new Phrase("CST%",helveticaBold8));
|
| - |
|
338 |
} else {
|
| - |
|
339 |
detailsTable.addCell(new Phrase("VAT%",helveticaBold8));
|
| - |
|
340 |
}
|
| - |
|
341 |
if(purchaseOrder.getTaxType()==TaxType.CFORM){
|
| 330 |
detailsTable.addCell(new Phrase("CST Amount",helveticaBold8));
|
342 |
detailsTable.addCell(new Phrase("CST Amount",helveticaBold8));
|
| 331 |
} else {
|
343 |
} else {
|
| 332 |
detailsTable.addCell(new Phrase("VAT Amount",helveticaBold8));
|
344 |
detailsTable.addCell(new Phrase("VAT Amount",helveticaBold8));
|
| 333 |
}
|
345 |
}
|
| 334 |
detailsTable.addCell(new Phrase("Rate Excl. (Rs)", helveticaBold8));
|
346 |
detailsTable.addCell(new Phrase("Rate Excl. (Rs)", helveticaBold8));
|
| Line 361... |
Line 373... |
| 361 |
}else{
|
373 |
}else{
|
| 362 |
vatFactor = catalogClient.getVatPercentageForItem(lineitem.getItemId(), supplier.getStateId(), lineitem.getUnitPrice());
|
374 |
vatFactor = catalogClient.getVatPercentageForItem(lineitem.getItemId(), supplier.getStateId(), lineitem.getUnitPrice());
|
| 363 |
}
|
375 |
}
|
| 364 |
}
|
376 |
}
|
| 365 |
double taxAmount = (lineitem.getUnitPrice() * vatFactor)/100;
|
377 |
double taxAmount = (lineitem.getUnitPrice() * vatFactor)/100;
|
| - |
|
378 |
detailsTable.addCell(new Phrase(vatFactor + "",
|
| - |
|
379 |
helvetica8));
|
| 366 |
detailsTable.addCell(new Phrase(taxAmount + "",
|
380 |
detailsTable.addCell(new Phrase(taxAmount + "",
|
| 367 |
helvetica8));
|
381 |
helvetica8));
|
| 368 |
detailsTable.addCell(new Phrase((lineitem.getUnitPrice()-taxAmount) + "",
|
382 |
detailsTable.addCell(new Phrase((lineitem.getUnitPrice()-taxAmount) + "",
|
| 369 |
helvetica8));
|
383 |
helvetica8));
|
| 370 |
detailsTable.addCell(new Phrase(lineitem.getUnitPrice() + "",
|
384 |
detailsTable.addCell(new Phrase(lineitem.getUnitPrice() + "",
|
| Line 374... |
Line 388... |
| 374 |
total += lineTotal;
|
388 |
total += lineTotal;
|
| 375 |
detailsTable.addCell(new Phrase("" + lineTotal, helvetica8));
|
389 |
detailsTable.addCell(new Phrase("" + lineTotal, helvetica8));
|
| 376 |
}
|
390 |
}
|
| 377 |
detailsTable.addCell(getTotalCell(2));
|
391 |
detailsTable.addCell(getTotalCell(2));
|
| 378 |
detailsTable.addCell(new Phrase(BigDecimal.valueOf(totalUnits).toPlainString(), helvetica8));
|
392 |
detailsTable.addCell(new Phrase(BigDecimal.valueOf(totalUnits).toPlainString(), helvetica8));
|
| 379 |
detailsTable.addCell(getTotalAmountCell(5,total));
|
393 |
detailsTable.addCell(getTotalAmountCell(6,total));
|
| 380 |
return detailsTable;
|
394 |
return detailsTable;
|
| 381 |
}
|
395 |
}
|
| 382 |
|
396 |
|
| 383 |
private static PdfPTable getBillToTable(long warehouseId, TaxType taxType) {
|
397 |
private static PdfPTable getBillToTable(long warehouseId, TaxType taxType) {
|
| 384 |
//TODO Write this code in a proper configurable way
|
398 |
//TODO Write this code in a proper configurable way
|