| 810 |
Collections.sort(list, (o1, o2) -> { |
Collections.sort(list, (o1, o2) -> { |
| 811 |
return accountTitles.indexOf(o1.getKey()) - accountTitles.indexOf(o2.getKey()); |
return accountTitles.indexOf(o1.getKey()) - accountTitles.indexOf(o2.getKey()); |
| 812 |
}); |
}); |
| 813 |
|
Entry<AccountTitle, Amount> reserved = null; |
| 814 |
for(Entry<AccountTitle, Amount> e : list) { |
for(Entry<AccountTitle, Amount> e : list) { |
| 815 |
AccountTitle accountTitle = e.getKey(); |
AccountTitle accountTitle = e.getKey(); |
| 816 |
Amount amount = e.getValue(); |
Amount amount = e.getValue(); |
| 824 |
} |
} |
| 825 |
if(accountTitle.getType() == AccountType.Assets) { |
if(accountTitle.getType() == AccountType.Assets) { |
| 826 |
if(amount.getValue() == 0) { |
if(amount.getValue() == 0) { |
| 827 |
|
if(reserved == null) { |
| 828 |
|
reserved = e; |
| 829 |
|
} |
| 830 |
continue; |
continue; |
| 831 |
} else if(amount.getValue() > 0) { |
} else if(amount.getValue() > 0) { |
| 832 |
debtors.add(e); |
debtors.add(e); |
| 837 |
} |
} |
| 838 |
} else if(accountTitle.getType() == AccountType.Liabilities || accountTitle.getType() == AccountType.Equity) { |
} else if(accountTitle.getType() == AccountType.Liabilities || accountTitle.getType() == AccountType.Equity) { |
| 839 |
if(amount.getValue() == 0) { |
if(amount.getValue() == 0) { |
| 840 |
|
if(reserved == null) { |
| 841 |
|
reserved = e; |
| 842 |
|
} |
| 843 |
continue; |
continue; |
| 844 |
} else if(amount.getValue() > 0) { |
} else if(amount.getValue() > 0) { |
| 845 |
creditors.add(e); |
creditors.add(e); |
| 851 |
} |
} |
| 852 |
} |
} |
| 853 |
AccountTitle capital = AccountTitle.getByDisplayName(new HashSet<>(accountTitles), "元入金"); |
AccountTitle capital = AccountTitle.getByDisplayName(new HashSet<>(accountTitles), "元入金"); |
| 854 |
if(capital != null) { |
// 期末残高 0 の勘定科目は翌期の元入金に繰り越しませんが、 |
| 855 |
|
// 繰り越す勘定科目が 1つもない場合は先頭の勘定科目を翌期の元入金として繰り越します。 |
| 856 |
|
if(creditors.size() == 0 && debtors.size() == 0 && reserved != null && capital != null) { |
| 857 |
|
Map.Entry<AccountTitle, Amount> e = Map.entry(capital, new Amount(Creditor.class, 0)); |
| 858 |
|
if(reserved.getKey().getType().getNormalBalance() == Debtor.class) { |
| 859 |
|
debtors.add(reserved); |
| 860 |
|
creditors.add(e); |
| 861 |
|
} else { |
| 862 |
|
debtors.add(e); |
| 863 |
|
creditors.add(reserved); |
| 864 |
|
} |
| 865 |
|
} else if(capital != null) { |
| 866 |
|
// 借方・貸方の勘定差異を元入金勘定で埋めます。 |
| 867 |
Map.Entry<AccountTitle, Amount> e = Map.entry(capital, new Amount(Creditor.class, (debtorsTotal - creditorsTotal))); |
Map.Entry<AccountTitle, Amount> e = Map.entry(capital, new Amount(Creditor.class, (debtorsTotal - creditorsTotal))); |
| 868 |
if(debtorsTotal >= creditorsTotal) { |
if(debtorsTotal >= creditorsTotal) { |
| 869 |
creditors.add(e); |
creditors.add(e); |