|
|
|
|
@@ -152,6 +152,31 @@ public class PdfDao {
|
|
|
|
|
// Create value cell with rounded corners
|
|
|
|
|
PdfPTable valueTable = new PdfPTable(1);
|
|
|
|
|
valueTable.setWidthPercentage(100);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object finalValue = value;
|
|
|
|
|
List<Object> criteriaObject = (List<Object>) contentResponseBean.getSettings().stream()
|
|
|
|
|
.filter(setting -> GepafinConstant.CRITERIA_TABLE_COLUMNS.equals(setting.getName()))
|
|
|
|
|
.findFirst()
|
|
|
|
|
.map(setting -> {
|
|
|
|
|
try {
|
|
|
|
|
// Assuming setting.getValue() contains the JSON string or object
|
|
|
|
|
return PdfUtils.extractRows(finalValue);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException("Error extracting rows from setting value", e);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.orElse(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update value if criteriaObject is not null
|
|
|
|
|
if (criteriaObject != null) {
|
|
|
|
|
value = criteriaObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update value if criteriaObject is not null
|
|
|
|
|
|
|
|
|
|
if (value instanceof List<?>) {
|
|
|
|
|
// Further check if the list contains Strings
|
|
|
|
|
List<?> list = (List<?>) value;
|
|
|
|
|
@@ -181,11 +206,10 @@ public class PdfDao {
|
|
|
|
|
document.add(valueTable);
|
|
|
|
|
}
|
|
|
|
|
else if (!list.isEmpty() && list.get(0) instanceof Map<?, ?>) {
|
|
|
|
|
Object object = value;
|
|
|
|
|
String stringvalue = Utils.convertToString(object);
|
|
|
|
|
List<Map<String, Object>> fieldValueList = Utils.convertJsonStringIntoJsonList(stringvalue);
|
|
|
|
|
|
|
|
|
|
document = createPdfTable(fieldValueList, document, contentResponseBean);
|
|
|
|
|
Object object = value;
|
|
|
|
|
String stringvalue = Utils.convertToString(object);
|
|
|
|
|
List<Map<String, Object>> fieldValueList = Utils.convertJsonStringIntoJsonList(stringvalue);
|
|
|
|
|
document = createPdfTable(fieldValueList, document, contentResponseBean);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
@@ -231,27 +255,29 @@ public class PdfDao {
|
|
|
|
|
document.add(valueTable);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
String fieldValue1= (String) value;
|
|
|
|
|
if(Utils.isValidDateString(fieldValue1)){
|
|
|
|
|
fieldValue1=Utils.formatDateString(String.valueOf(value));
|
|
|
|
|
}
|
|
|
|
|
if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
|
|
|
|
|
fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
|
|
|
|
|
}
|
|
|
|
|
if (value instanceof String) {
|
|
|
|
|
String fieldValue1 = (String) value;
|
|
|
|
|
if (Utils.isValidDateString(fieldValue1)) {
|
|
|
|
|
fieldValue1 = Utils.formatDateString(String.valueOf(value));
|
|
|
|
|
}
|
|
|
|
|
if(contentResponseBean.getName().equals("numberinput") && Boolean.TRUE.equals(Utils.isNumeric(fieldValue))){
|
|
|
|
|
fieldValue1=Utils.convertToItalianFormat(fieldValue);
|
|
|
|
|
}
|
|
|
|
|
// PdfPCell valueCell = new PdfPCell(new Phrase(fieldValue1, valueFont));
|
|
|
|
|
PdfPCell valueCell = PdfUtils.htmlToPdfPCell(fieldValue1, valueFont);
|
|
|
|
|
valueCell.setMinimumHeight(30f); // Set a fixed height for the cell
|
|
|
|
|
valueCell.setPaddingLeft(10f); // Adjust left padding as needed
|
|
|
|
|
valueCell.setPaddingTop(0f); // Remove padding from top to allow vertical centering
|
|
|
|
|
valueCell.setPaddingBottom(6f);
|
|
|
|
|
valueCell.setPaddingLeft(leftMargin); // Increase left margin for value
|
|
|
|
|
valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell
|
|
|
|
|
valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
|
|
valueCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
|
|
valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners
|
|
|
|
|
valueTable.addCell(valueCell);
|
|
|
|
|
document.add(valueTable);
|
|
|
|
|
}
|
|
|
|
|
PdfPCell valueCell = PdfUtils.htmlToPdfPCell(fieldValue1, valueFont);
|
|
|
|
|
valueCell.setMinimumHeight(30f); // Set a fixed height for the cell
|
|
|
|
|
valueCell.setPaddingLeft(10f); // Adjust left padding as needed
|
|
|
|
|
valueCell.setPaddingTop(0f); // Remove padding from top to allow vertical centering
|
|
|
|
|
valueCell.setPaddingBottom(6f);
|
|
|
|
|
valueCell.setPaddingLeft(leftMargin); // Increase left margin for value
|
|
|
|
|
valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell
|
|
|
|
|
valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
|
|
valueCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
|
|
|
|
valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners
|
|
|
|
|
valueTable.addCell(valueCell);
|
|
|
|
|
document.add(valueTable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
document.add(new Paragraph("\n")); // Add line break after each value
|
|
|
|
|
@@ -264,11 +290,12 @@ public class PdfDao {
|
|
|
|
|
Map<String, Boolean> formulaEnabledMap = new HashMap<>();
|
|
|
|
|
Map<String, String> formulaTypeMap = new HashMap<>();
|
|
|
|
|
Map<String, String> fieldTypeMap = new HashMap<>();
|
|
|
|
|
Map<String, String> totalMap = new HashMap<>();
|
|
|
|
|
Font lightGrayFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new BaseColor(110, 110, 110)); // Light gray
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contentResponseBean.getSettings().stream()
|
|
|
|
|
.filter(setting -> "table_columns".equals(setting.getName())) // Check for "table_columns"
|
|
|
|
|
.filter(setting -> "table_columns".equals(setting.getName()) || "criteria_table_columns".equals(setting.getName())) // Check for "table_columns"
|
|
|
|
|
.map(SettingResponseBean::getValue)
|
|
|
|
|
.filter(Objects::nonNull) // Ensure value is not null
|
|
|
|
|
.filter(settingValue -> settingValue instanceof Map) // Ensure value is a Map
|
|
|
|
|
@@ -283,7 +310,7 @@ public class PdfDao {
|
|
|
|
|
Boolean isFormulaEnabled = (Boolean) fieldData.get("enableFormula");
|
|
|
|
|
String formulaType = (String) fieldData.get("lastRowFormula");
|
|
|
|
|
String fieldType = (String) fieldData.get("fieldtype"); // Get the field type (e.g., numeric)
|
|
|
|
|
|
|
|
|
|
String total= (String) fieldData.get("lastRowText");
|
|
|
|
|
if (fieldName != null && fieldDataValue != null) {
|
|
|
|
|
stateFieldMap.put(fieldName, fieldDataValue);
|
|
|
|
|
}
|
|
|
|
|
@@ -297,6 +324,9 @@ public class PdfDao {
|
|
|
|
|
if (fieldType != null) {
|
|
|
|
|
fieldTypeMap.put(fieldName, fieldType); // Store the fieldType in the map
|
|
|
|
|
}
|
|
|
|
|
if(total!=null){
|
|
|
|
|
totalMap.put(fieldName,total);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
PdfPTable table = new PdfPTable(stateFieldMap.size()); // Number of columns equals the number of map entries
|
|
|
|
|
@@ -342,12 +372,15 @@ public class PdfDao {
|
|
|
|
|
Object value = row.getOrDefault(key, ""); // Fetch value or use empty string if key not present
|
|
|
|
|
// String fieldValue= (String) value;
|
|
|
|
|
String fieldValue = value != null ? value.toString() : "";
|
|
|
|
|
if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
|
|
|
|
|
fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
|
|
|
|
|
}
|
|
|
|
|
// if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
|
|
|
|
|
//// fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
|
|
|
|
|
// }
|
|
|
|
|
if (Boolean.TRUE.equals(formulaEnabledMap.get(key)) && Boolean.TRUE.equals(GepafinConstant.NUMERIC.equalsIgnoreCase(fieldTypeMap.get(key)))) {
|
|
|
|
|
calculateValue(key, fieldValue, formulaTypeMap, columnSums);
|
|
|
|
|
}
|
|
|
|
|
if(Boolean.TRUE.equals(Utils.isNumeric(fieldValue))){
|
|
|
|
|
fieldValue=Utils.convertToItalianFormat(fieldValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PdfPCell dataCell = PdfUtils.htmlToPdfPCell(fieldValue != null ? fieldValue : "", textFont);
|
|
|
|
|
dataCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell
|
|
|
|
|
@@ -397,14 +430,19 @@ public class PdfDao {
|
|
|
|
|
table.addCell(emptyCell);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
PdfPCell emptyCell = new PdfPCell(new Phrase(""));
|
|
|
|
|
String total=null;
|
|
|
|
|
if (totalMap.containsKey(key)) {
|
|
|
|
|
total=totalMap.getOrDefault(key, "");
|
|
|
|
|
}
|
|
|
|
|
PdfPCell emptyCell = new PdfPCell(new Phrase(total,lightGrayFont));
|
|
|
|
|
emptyCell.setPaddingTop(8f);
|
|
|
|
|
emptyCell.setPaddingLeft(8f);
|
|
|
|
|
emptyCell.setBackgroundColor(new BaseColor(239, 243, 248));
|
|
|
|
|
table.addCell(emptyCell);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add the last table to the document
|
|
|
|
|
document.add(table);
|
|
|
|
|
|
|
|
|
|
@@ -415,7 +453,7 @@ public class PdfDao {
|
|
|
|
|
try {
|
|
|
|
|
if (Boolean.FALSE.equals(StringUtils.isEmpty(fieldValue))) {
|
|
|
|
|
// Use Locale.ITALY to parse the number with the Italian format (comma as decimal separator)
|
|
|
|
|
NumberFormat format = NumberFormat.getInstance(Locale.ITALY);
|
|
|
|
|
NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
|
|
|
|
|
Number number = format.parse(fieldValue); // Parse the fieldValue as a number
|
|
|
|
|
double numericValue = number.doubleValue(); // Convert the parsed number to double
|
|
|
|
|
|
|
|
|
|
|