Subversion Repositories SmartDukaan

Rev

Rev 29910 | Rev 29980 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 29910 Rev 29929
Line 1... Line 1...
1
 
1
 
2
package com.spice.profitmandi.common.util;
2
package com.spice.profitmandi.common.util;
3
 
3
 
4
import java.text.DecimalFormat;
-
 
5
import java.text.NumberFormat;
4
import java.text.NumberFormat;
6
import java.time.LocalDateTime;
5
import java.time.LocalDateTime;
7
import java.time.format.DateTimeFormatter;
6
import java.time.format.DateTimeFormatter;
8
import java.util.Locale;
7
import java.util.Locale;
9
 
8
 
10
public class FormattingUtils {
9
public class FormattingUtils {
11
 
10
 
12
	private static Locale indianLocale = new Locale("en", "IN");
11
	private static final NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(new Locale("en", "IN"));
13
	private static DecimalFormat f = new DecimalFormat("##.00");
12
	private static final NumberFormat numberFormatter = NumberFormat.getNumberInstance(new Locale("en", "IN"));
14
	private NumberFormat currencyFormat;
-
 
15
	private static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
13
	private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
16
	private static DateTimeFormatter dateMonthFormatter = DateTimeFormatter.ofPattern("MMM-dd");
14
	private static final DateTimeFormatter dateMonthFormatter = DateTimeFormatter.ofPattern("MMM-dd");
17
	private static DateTimeFormatter reporticoFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
15
	private static final DateTimeFormatter reporticoFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
18
	private static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
16
	private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
19
	private static DateTimeFormatter ymFormatter = DateTimeFormatter.ofPattern("yyyyMM");
17
	private static final DateTimeFormatter ymFormatter = DateTimeFormatter.ofPattern("yyyyMM");
20
	private static DateTimeFormatter monYYYYFormatter = DateTimeFormatter.ofPattern("MMM, yyyy");
18
	private static final DateTimeFormatter monYYYYFormatter = DateTimeFormatter.ofPattern("MMM, yyyy");
21
	
19
 
22
	public static String getYearMonth(LocalDateTime dateTime) {
20
	public static String getYearMonth(LocalDateTime dateTime) {
23
		return dateTime.format(ymFormatter);
21
		return dateTime.format(ymFormatter);
24
	}
22
	}
25
	
23
 
26
	
24
 
27
	public static String formatYearMonth(LocalDateTime dateTime) {
25
	public static String formatYearMonth(LocalDateTime dateTime) {
28
		return dateTime.format(monYYYYFormatter);
26
		return dateTime.format(monYYYYFormatter);
29
	}
27
	}
30
	
28
 
31
	public FormattingUtils(){
-
 
32
		currencyFormat = NumberFormat.getNumberInstance(indianLocale);
-
 
33
		currencyFormat.setMaximumFractionDigits(2);
-
 
34
		currencyFormat.setMinimumFractionDigits(2);
-
 
35
		currencyFormat.setMinimumIntegerDigits(1);
-
 
36
	}
-
 
37
	
-
 
38
	public FormattingUtils(int maximumFractionDigits){
-
 
39
		currencyFormat = NumberFormat.getNumberInstance(indianLocale);
-
 
40
		currencyFormat.setMaximumFractionDigits(maximumFractionDigits);
-
 
41
		currencyFormat.setMinimumIntegerDigits(1);
-
 
42
	}
-
 
43
	
-
 
44
	public String formatPrice(double amount){
29
	public static String formatDecimal(double number) {
45
		return currencyFormat.format(amount);
30
		return numberFormatter.format(number).replace("\\.00", "");
46
	}
31
	}
-
 
32
 
-
 
33
	public static String formatDecimal(int number) {
-
 
34
		return numberFormatter.format(number).replace("\\.00", "");
47
	
35
	}
-
 
36
 
-
 
37
	public static String formatDecimal(long number) {
-
 
38
		return numberFormatter.format(number).replace("\\.00", "");
-
 
39
	}
-
 
40
 
-
 
41
	public static String formatDecimal(float number) {
-
 
42
		return numberFormatter.format(number).replace("\\.00", "");
-
 
43
	}
-
 
44
/*
-
 
45
	public String formatDecimal(double amount){
-
 
46
		return numberFormatter.format(amount).replace("\\.00", "");
-
 
47
	}*/
-
 
48
 
48
	public static String format(LocalDateTime localDateTime){
49
	public static String format(LocalDateTime localDateTime) {
49
		return localDateTime.format(dateTimeFormatter);
50
		return localDateTime.format(dateTimeFormatter);
50
	}
51
	}
51
	
52
 
52
	public static String formatDecimalTwoDigits(double number) {
53
	public String formatPrice(double amount) {
53
		return f.format(number);
54
		return currencyFormatter.format(amount).replace("\\.00", "");
54
	}
55
	}
-
 
56
 
-
 
57
	public String formatPrice(float amount) {
-
 
58
		return currencyFormatter.format(amount).replace("\\.00", "");
-
 
59
	}
-
 
60
 
-
 
61
	public String formatPrice(int amount) {
-
 
62
		return currencyFormatter.format(amount).replace("\\.00", "");
-
 
63
	}
-
 
64
 
-
 
65
	public String formatPrice(long amount) {
-
 
66
		return currencyFormatter.format(amount).replace("\\.00", "");
-
 
67
	}
-
 
68
 
55
	public static String formatDate(LocalDateTime dateTime) {
69
	public static String formatDate(LocalDateTime dateTime) {
56
		return dateTime.format(dateFormatter);
70
		return dateTime.format(dateFormatter);
57
	}
71
	}
-
 
72
 
58
	public static String formatDateMonth(LocalDateTime dateTime) {
73
	public static String formatDateMonth(LocalDateTime dateTime) {
59
		return dateTime.format(dateMonthFormatter);
74
		return dateTime.format(dateMonthFormatter);
60
	}
75
	}
61
	
76
 
62
	public static String formatReporitcoDate(LocalDateTime dateTime) {
77
	public static String formatReporitcoDate(LocalDateTime dateTime) {
63
		if(dateTime==null) return "-";
78
		if (dateTime == null) return "-";
64
		return dateTime.format(reporticoFormatter);
79
		return dateTime.format(reporticoFormatter);
65
	}
80
	}
66
 
-
 
67
	public static String formatShortHand(long value) {
-
 
68
		String finalval = null;
-
 
69
 
-
 
70
		if (value >= 100000 && value < 10000000) {
-
 
71
			long reminder = value / 100000;
-
 
72
			long quitonent = value % 100000;
-
 
73
			finalval = reminder + "." + quitonent;
-
 
74
			String secondval = String.valueOf(quitonent);
-
 
75
			if (secondval.length() >= 2) {
-
 
76
				secondval = secondval.substring(0, 2);
-
 
77
				finalval = reminder + "." + secondval;
-
 
78
			}
-
 
79
			return String.valueOf(finalval) + " Lacs";
-
 
80
		} else if (value >= 1000 && value < 100000) {
-
 
81
			long reminder = value / 1000;
-
 
82
			long quitonent = value % 1000;
-
 
83
			finalval = reminder + "." + quitonent;
-
 
84
			String secondval = String.valueOf(quitonent);
-
 
85
			if (secondval.length() >= 2) {
-
 
86
				secondval = secondval.substring(0, 2);
-
 
87
				finalval = reminder + "." + secondval;
-
 
88
			}
-
 
89
			return String.valueOf(finalval) + " K";
-
 
90
		} else if (value >= 10000000 && value < 1000000000) {
-
 
91
			long reminder = value / 10000000;
-
 
92
			long quitonent = value % 10000000;
-
 
93
			finalval = reminder + "." + quitonent;
-
 
94
			String secondval = String.valueOf(quitonent);
-
 
95
			if (secondval.length() >= 2) {
-
 
96
				secondval = secondval.substring(0, 2);
-
 
97
				finalval = reminder + "." + secondval;
-
 
98
			}
-
 
99
			return String.valueOf(finalval) + " Cr";
-
 
100
		}
-
 
101
		return String.valueOf(finalval);
-
 
102
 
-
 
103
	}
-
 
104
}
81
}