Merge branch 'develop' of https://github.com/Kitzanos/GEPAFIN-BE into develop
This commit is contained in:
@@ -278,7 +278,7 @@ public class PdfDao {
|
||||
fieldValue1=Utils.formatDateString(String.valueOf(value));
|
||||
}
|
||||
if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
|
||||
fieldValue= String.valueOf(Utils.convertItalianAmountToDouble(fieldValue));
|
||||
fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
|
||||
}
|
||||
PdfPCell valueCell = new PdfPCell(new Phrase(fieldValue1, valueFont));
|
||||
valueCell.setPadding(5f); // Increase padding for better spacing
|
||||
@@ -362,7 +362,6 @@ public class PdfDao {
|
||||
PdfPCell headerCell = new PdfPCell(new Phrase(headerValue)); // Create a new PdfPCell for the header
|
||||
headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); // Center align
|
||||
headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||
headerCell.setFixedHeight(rowHeight);
|
||||
headerCell.setBackgroundColor(new BaseColor(178, 190, 181)); // Light gray background for header
|
||||
|
||||
table.addCell(headerCell); // Add the header cell to the table
|
||||
@@ -378,7 +377,7 @@ public class PdfDao {
|
||||
Object value = row.getOrDefault(key, ""); // Fetch value or use empty string if key not present
|
||||
String fieldValue= (String) value;
|
||||
if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
|
||||
fieldValue= String.valueOf(Utils.convertItalianAmountToDouble(fieldValue));
|
||||
fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
|
||||
}
|
||||
PdfPCell dataCell = new PdfPCell(new Phrase(fieldValue != null ?fieldValue: "", textFont));
|
||||
dataCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell
|
||||
@@ -498,7 +497,7 @@ public class PdfDao {
|
||||
}
|
||||
fieldValue = matchedLabels;
|
||||
}
|
||||
|
||||
|
||||
// Further processing of field value (e.g., finding labels in options)
|
||||
fieldValue = findLabelInOptions(content.getSettings(), fieldValue);
|
||||
} else {
|
||||
|
||||
@@ -416,24 +416,50 @@ public class Utils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static String convertItalianAmountToDouble(String amount) throws NumberFormatException {
|
||||
// Step 1: Remove the thousands separator and replace the decimal separator
|
||||
String normalizedAmount = amount.replace(".", "").replace(",", ".");
|
||||
// public static String convertItalianAmountToDouble(String amount) throws NumberFormatException {
|
||||
// // Step 1: Remove the thousands separator and replace the decimal separator
|
||||
// String normalizedAmount = amount.replace(".", "").replace(",", ".");
|
||||
//
|
||||
// // Step 2: Parse the string to a double
|
||||
// double value = Double.parseDouble(normalizedAmount);
|
||||
// if (value <= 0) {
|
||||
// return amount;
|
||||
// }
|
||||
// // Step 3: Format the double to 2 decimal places
|
||||
// DecimalFormat decimalFormat = new DecimalFormat("#.00");
|
||||
// return decimalFormat.format(value); // Return formatted string
|
||||
// }
|
||||
|
||||
// Step 2: Parse the string to a double
|
||||
double value = Double.parseDouble(normalizedAmount);
|
||||
if (value <= 0) {
|
||||
return amount;
|
||||
public static String convertToItalianFormat(String amount) {
|
||||
try {
|
||||
// Step 1: Sanitize and standardize the input
|
||||
String sanitizedAmount = amount.trim();
|
||||
if (sanitizedAmount.matches("\\d")) {
|
||||
return sanitizedAmount;
|
||||
}
|
||||
// Step 2: Handle Italian-style input (e.g., "37.192,00")
|
||||
if (sanitizedAmount.contains(".") && sanitizedAmount.contains(",")) {
|
||||
// Assume the period is a thousand separator and the comma is a decimal separator
|
||||
sanitizedAmount = sanitizedAmount.replace(".", "").replace(",", ".");
|
||||
} else if (sanitizedAmount.contains(",")) {
|
||||
// If the input contains only a comma, treat it as a decimal separator
|
||||
sanitizedAmount = sanitizedAmount.replace(",", ".");
|
||||
}
|
||||
// Step 3: Parse the cleaned-up string into a double
|
||||
double parsedAmount = Double.parseDouble(sanitizedAmount);
|
||||
// Step 4: Format the parsed amount to Italian format
|
||||
NumberFormat italianFormat = NumberFormat.getInstance(Locale.ITALY);
|
||||
italianFormat.setMinimumFractionDigits(2);
|
||||
italianFormat.setMaximumFractionDigits(2);
|
||||
|
||||
return italianFormat.format(parsedAmount);
|
||||
} catch (NumberFormatException e) {
|
||||
// In case of any issues with parsing, return a default or error message
|
||||
return "Invalid amount format";
|
||||
}
|
||||
// Step 3: Format the double to 2 decimal places
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.00");
|
||||
return decimalFormat.format(value); // Return formatted string
|
||||
}
|
||||
public static boolean isItalianFormattedAmount(String input) {
|
||||
// Regular expression to match Italian-style amounts (e.g., 41.003,00 or 123,45)
|
||||
if (!input.contains(",")) {
|
||||
return false; // Return false if there is no comma
|
||||
}
|
||||
String sanitizedInput = input.replace(",", "");
|
||||
|
||||
// Step 2: Check if the remaining string is a whole number
|
||||
|
||||
Reference in New Issue
Block a user