Revisão | 10 (tree) |
---|---|
Hora | 2018-02-21 21:56:53 |
Autor | hirukawa_ryo |
* aoiro 0.2.3
家事按分が0円の締切仕訳が作成されてしまうバグを修正しました。
@@ -33,8 +33,9 @@ | ||
33 | 33 | /** メッセージ出力先 */ |
34 | 34 | private PrintStream out; |
35 | 35 | |
36 | - public AccountSettlement(List<AccountTitle> accountTitles) { | |
36 | + public AccountSettlement(List<AccountTitle> accountTitles, boolean isSoloproprietorship) { | |
37 | 37 | this.accountTitles = accountTitles; |
38 | + this.isSoloProprietorship = isSoloproprietorship; | |
38 | 39 | } |
39 | 40 | |
40 | 41 | public void setPrintStream(PrintStream out) { |
@@ -47,10 +48,8 @@ | ||
47 | 48 | * @param proportionalDivisions 家事按分リスト |
48 | 49 | */ |
49 | 50 | public void addClosingEntries(List<JournalEntry> journalEntries, List<ProportionalDivision> proportionalDivisions) { |
50 | - isSoloProprietorship = isSoloProprietorship(journalEntries); | |
51 | - | |
52 | 51 | if(date == null) { |
53 | - date = getClosingDate(journalEntries); | |
52 | + date = getClosingDate(journalEntries, isSoloProprietorship); | |
54 | 53 | } |
55 | 54 | if(date == null) { |
56 | 55 | throw new IllegalStateException("決算日が指定されていません。"); |
@@ -84,10 +83,14 @@ | ||
84 | 83 | } |
85 | 84 | if(debtorTotal > creditorTotal) { |
86 | 85 | double total = (debtorTotal - creditorTotal) * (1.0 - proportionalDivision.getBusinessRatio()); |
87 | - creditors.add(new Creditor(proportionalDivision.getAccountTitle(), (int)Math.floor(total))); | |
86 | + if(!(-1.0 < total && total < +1.0)) { | |
87 | + creditors.add(new Creditor(proportionalDivision.getAccountTitle(), (int)Math.floor(total))); | |
88 | + } | |
88 | 89 | } else if(creditorTotal > debtorTotal) { |
89 | 90 | double total = (creditorTotal - debtorTotal) * (1.0 - proportionalDivision.getBusinessRatio()); |
90 | - debtors.add(new Debtor(proportionalDivision.getAccountTitle(), (int)Math.floor(total))); | |
91 | + if(!(-1.0 < total && total < +1.0)) { | |
92 | + debtors.add(new Debtor(proportionalDivision.getAccountTitle(), (int)Math.floor(total))); | |
93 | + } | |
91 | 94 | } |
92 | 95 | } |
93 | 96 | if(debtors.size() > 0) { |
@@ -508,29 +511,12 @@ | ||
508 | 511 | } |
509 | 512 | } |
510 | 513 | |
511 | - /** 仕訳リストから個人事業主かどうかを判定します。 | |
512 | - * 仕訳リストに元入金が含まれていれば個人事業主と判定します。 | |
513 | - * | |
514 | - * @param journalEntries 仕訳リスト | |
515 | - * @return 仕訳リストに元入金がある場合は true、そうでなければ false を返します。 | |
516 | - */ | |
517 | - public static boolean isSoloProprietorship(List<JournalEntry> journalEntries) { | |
518 | - for(JournalEntry entry : journalEntries) { | |
519 | - for(Creditor creditor : entry.getCreditors()) { | |
520 | - if(creditor.getAccountTitle().getDisplayName().equals("元入金")) { | |
521 | - return true; | |
522 | - } | |
523 | - } | |
524 | - } | |
525 | - return false; | |
526 | - } | |
527 | - | |
528 | 514 | /** 仕訳リストから開始日を求めます。 |
529 | 515 | * |
530 | 516 | * @param journalEntries 仕訳リスト |
531 | 517 | * @return 開始日 |
532 | 518 | */ |
533 | - public static Date getOpeningDate(List<JournalEntry> journalEntries) { | |
519 | + public static Date getOpeningDate(List<JournalEntry> journalEntries, boolean isSoloProprietorship) { | |
534 | 520 | Date date = null; |
535 | 521 | |
536 | 522 | for(JournalEntry entry : journalEntries) { |
@@ -549,10 +535,10 @@ | ||
549 | 535 | * @param journalEntries 仕訳リスト |
550 | 536 | * @return 決算日 |
551 | 537 | */ |
552 | - public static Date getClosingDate(List<JournalEntry> journalEntries) { | |
538 | + public static Date getClosingDate(List<JournalEntry> journalEntries, boolean isSoloProprietorship) { | |
553 | 539 | Date date = null; |
554 | 540 | |
555 | - if(isSoloProprietorship(journalEntries)) { | |
541 | + if(isSoloProprietorship) { | |
556 | 542 | //個人事業主の場合、仕訳から年を求めて、その年の12/31を決算日とします。 |
557 | 543 | if(journalEntries.size() > 0) { |
558 | 544 | JournalEntry entry = journalEntries.get(0); |
@@ -110,7 +110,7 @@ | ||
110 | 110 | if(!skipSettlement) { |
111 | 111 | //決算 |
112 | 112 | System.out.println("決算処理を実行しています . . ."); |
113 | - AccountSettlement accountSettlement = new AccountSettlement(accountTitles); | |
113 | + AccountSettlement accountSettlement = new AccountSettlement(accountTitles, isSoloProprietorship); | |
114 | 114 | accountSettlement.setPrintStream(System.out); |
115 | 115 | accountSettlement.addClosingEntries(journalEntries, proportionalDivisions); |
116 | 116 | System.out.println(""); |
@@ -118,8 +118,8 @@ | ||
118 | 118 | |
119 | 119 | System.out.println("帳簿を作成しています . . ."); |
120 | 120 | |
121 | - GeneralJournal generalJournal = new GeneralJournal(journalEntries); | |
122 | - GeneralLedger generalLedger = new GeneralLedger(accountTitles, journalEntries); | |
121 | + GeneralJournal generalJournal = new GeneralJournal(journalEntries, isSoloProprietorship); | |
122 | + GeneralLedger generalLedger = new GeneralLedger(accountTitles, journalEntries, isSoloProprietorship); | |
123 | 123 | |
124 | 124 | generalJournal.writeTo(new File("仕訳帳.pdf")); |
125 | 125 | System.out.println(" 仕訳帳.pdf を出力しました。"); |
@@ -130,13 +130,13 @@ | ||
130 | 130 | if(!skipSettlement) { |
131 | 131 | //損益計算書 |
132 | 132 | Node<List<AccountTitle>, Amount> plRoot = accountTitlesLoader.getProfitAndLossRoot(); |
133 | - ProfitAndLoss pl = new ProfitAndLoss(plRoot, journalEntries); | |
133 | + ProfitAndLoss pl = new ProfitAndLoss(plRoot, journalEntries, isSoloProprietorship); | |
134 | 134 | pl.writeTo(new File("損益計算書.pdf")); |
135 | 135 | System.out.println(" 損益計算書.pdf を出力しました。"); |
136 | 136 | |
137 | 137 | //貸借対照表 |
138 | 138 | Node<List<AccountTitle>, Amount[]> bsRoot = accountTitlesLoader.getBalanceSheetRoot(); |
139 | - BalanceSheet bs = new BalanceSheet(bsRoot, journalEntries); | |
139 | + BalanceSheet bs = new BalanceSheet(bsRoot, journalEntries, isSoloProprietorship); | |
140 | 140 | bs.writeTo(new File("貸借対照表.pdf")); |
141 | 141 | System.out.println(" 貸借対照表.pdf を出力しました。"); |
142 | 142 |
@@ -53,12 +53,12 @@ | ||
53 | 53 | private List<String> pageData = new ArrayList<String>(); |
54 | 54 | private List<String> printData; |
55 | 55 | |
56 | - public BalanceSheet(Node<List<AccountTitle>, Amount[]> bsRoot, List<JournalEntry> journalEntries) throws IOException { | |
56 | + public BalanceSheet(Node<List<AccountTitle>, Amount[]> bsRoot, List<JournalEntry> journalEntries, boolean isSoloProprietorship) throws IOException { | |
57 | 57 | this.bsRoot = bsRoot; |
58 | 58 | this.journalEntries = journalEntries; |
59 | 59 | |
60 | - this.openingDate = AccountSettlement.getOpeningDate(journalEntries); | |
61 | - this.closingDate = AccountSettlement.getClosingDate(journalEntries); | |
60 | + this.openingDate = AccountSettlement.getOpeningDate(journalEntries, isSoloProprietorship); | |
61 | + this.closingDate = AccountSettlement.getClosingDate(journalEntries, isSoloProprietorship); | |
62 | 62 | |
63 | 63 | InputStream in = getClass().getResourceAsStream("/templates/貸借対照表.pb"); |
64 | 64 | BufferedReader r = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); |
@@ -33,7 +33,7 @@ | ||
33 | 33 | private List<String> pageData = new ArrayList<String>(); |
34 | 34 | private List<String> printData; |
35 | 35 | |
36 | - public GeneralJournal(List<JournalEntry> journalEntries) throws IOException { | |
36 | + public GeneralJournal(List<JournalEntry> journalEntries, boolean isSoloProprietorship) throws IOException { | |
37 | 37 | this.entries = journalEntries; |
38 | 38 | |
39 | 39 | InputStream in = getClass().getResourceAsStream("/templates/仕訳帳.pb"); |
@@ -44,7 +44,7 @@ | ||
44 | 44 | } |
45 | 45 | r.close(); |
46 | 46 | |
47 | - Date closing = AccountSettlement.getClosingDate(entries); | |
47 | + Date closing = AccountSettlement.getClosingDate(entries, isSoloProprietorship); | |
48 | 48 | Calendar calendar = Calendar.getInstance(); |
49 | 49 | calendar.setTime(closing); |
50 | 50 | if(calendar.get(Calendar.MONTH) == Calendar.DECEMBER && calendar.get(Calendar.DAY_OF_MONTH) == 31) { |
@@ -37,7 +37,7 @@ | ||
37 | 37 | private List<String> pageData = new ArrayList<String>(); |
38 | 38 | private List<String> printData; |
39 | 39 | |
40 | - public GeneralLedger(List<AccountTitle> accountTitles, List<JournalEntry> journalEntries) throws IOException { | |
40 | + public GeneralLedger(List<AccountTitle> accountTitles, List<JournalEntry> journalEntries, boolean isSoloProprietorship) throws IOException { | |
41 | 41 | this.accountTitles = new ArrayList<AccountTitle>(accountTitles); |
42 | 42 | this.accountTitles.add(AccountTitle.INCOME_SUMMARY); |
43 | 43 | this.accountTitles.add(AccountTitle.RETAINED_EARNINGS); |
@@ -53,7 +53,7 @@ | ||
53 | 53 | } |
54 | 54 | r.close(); |
55 | 55 | |
56 | - Date closing = AccountSettlement.getClosingDate(entries); | |
56 | + Date closing = AccountSettlement.getClosingDate(entries, isSoloProprietorship); | |
57 | 57 | Calendar calendar = Calendar.getInstance(); |
58 | 58 | calendar.setTime(closing); |
59 | 59 | if(calendar.get(Calendar.MONTH) == Calendar.DECEMBER && calendar.get(Calendar.DAY_OF_MONTH) == 31) { |
@@ -47,12 +47,12 @@ | ||
47 | 47 | private List<String> pageData = new ArrayList<String>(); |
48 | 48 | private List<String> printData; |
49 | 49 | |
50 | - public ProfitAndLoss(Node<List<AccountTitle>, Amount> plRoot, List<JournalEntry> journalEntries) throws IOException { | |
50 | + public ProfitAndLoss(Node<List<AccountTitle>, Amount> plRoot, List<JournalEntry> journalEntries, boolean isSoloProprietorship) throws IOException { | |
51 | 51 | this.plRoot = plRoot; |
52 | 52 | this.journalEntries = journalEntries; |
53 | 53 | |
54 | - this.openingDate = AccountSettlement.getOpeningDate(journalEntries); | |
55 | - this.closingDate = AccountSettlement.getClosingDate(journalEntries); | |
54 | + this.openingDate = AccountSettlement.getOpeningDate(journalEntries, isSoloProprietorship); | |
55 | + this.closingDate = AccountSettlement.getClosingDate(journalEntries, isSoloProprietorship); | |
56 | 56 | |
57 | 57 | for(JournalEntry entry : journalEntries) { |
58 | 58 | if(entry.isIncomeSummary()) { |