| Revision | 120 (tree) |
|---|---|
| Time | 2023-03-04 11:37:28 |
| Author | |
aoiro 1.1.2
次年度の元入金に繰り越す勘定科目の金額がすべて0円の場合は、先頭の勘定科目1つを次年度の元入金として繰り越すようにしました。これによって、現金 0 / 元入金 0 が次年度にも繰り越されるようになりました。従来は次年度は 元入金 0 / 元入金 0 となっていました。
| @@ -810,6 +810,7 @@ | ||
| 810 | 810 | Collections.sort(list, (o1, o2) -> { |
| 811 | 811 | return accountTitles.indexOf(o1.getKey()) - accountTitles.indexOf(o2.getKey()); |
| 812 | 812 | }); |
| 813 | + Entry<AccountTitle, Amount> reserved = null; | |
| 813 | 814 | for(Entry<AccountTitle, Amount> e : list) { |
| 814 | 815 | AccountTitle accountTitle = e.getKey(); |
| 815 | 816 | Amount amount = e.getValue(); |
| @@ -823,6 +824,9 @@ | ||
| 823 | 824 | } |
| 824 | 825 | if(accountTitle.getType() == AccountType.Assets) { |
| 825 | 826 | if(amount.getValue() == 0) { |
| 827 | + if(reserved == null) { | |
| 828 | + reserved = e; | |
| 829 | + } | |
| 826 | 830 | continue; |
| 827 | 831 | } else if(amount.getValue() > 0) { |
| 828 | 832 | debtors.add(e); |
| @@ -833,6 +837,9 @@ | ||
| 833 | 837 | } |
| 834 | 838 | } else if(accountTitle.getType() == AccountType.Liabilities || accountTitle.getType() == AccountType.Equity) { |
| 835 | 839 | if(amount.getValue() == 0) { |
| 840 | + if(reserved == null) { | |
| 841 | + reserved = e; | |
| 842 | + } | |
| 836 | 843 | continue; |
| 837 | 844 | } else if(amount.getValue() > 0) { |
| 838 | 845 | creditors.add(e); |
| @@ -844,7 +851,19 @@ | ||
| 844 | 851 | } |
| 845 | 852 | } |
| 846 | 853 | AccountTitle capital = AccountTitle.getByDisplayName(new HashSet<>(accountTitles), "元入金"); |
| 847 | - if(capital != null) { | |
| 854 | + // 期末残高 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 | + // 借方・貸方の勘定差異を元入金勘定で埋めます。 | |
| 848 | 867 | Map.Entry<AccountTitle, Amount> e = Map.entry(capital, new Amount(Creditor.class, (debtorsTotal - creditorsTotal))); |
| 849 | 868 | if(debtorsTotal >= creditorsTotal) { |
| 850 | 869 | creditors.add(e); |