リビジョン | 67 (tree) |
---|---|
日時 | 2020-10-16 12:02:30 |
作者 | ![]() |
* aoiro 0.7.2
BalanceSheet 仕訳が存在しない場合 closingDate が null となり例外がスローされる問題を修正しました。(コンソール版では事前に仕訳件数のチェックがおこなわれるため発生しませんでした。)
BalanceSheet createOpeningJournalEntries メソッドの名前を createNextOpeningJournalEntries に変更しました。
次年度の開始仕訳.yml の作成ロジックをアトミックに変更しました。
@@ -204,8 +204,8 @@ | ||
204 | 204 | System.out.println(""); |
205 | 205 | System.out.println("繰越処理を実行しています . . ."); |
206 | 206 | |
207 | - //開始仕訳 | |
208 | - bs.createOpeningJournalEntries(outputDir.resolve("次年度の開始仕訳.yml")); | |
207 | + //次年度の開始仕訳 | |
208 | + bs.createNextOpeningJournalEntries(outputDir.resolve("次年度の開始仕訳.yml")); | |
209 | 209 | System.out.println(" 次年度の開始仕訳.yml を出力しました。"); |
210 | 210 | } |
211 | 211 |
@@ -9,6 +9,8 @@ | ||
9 | 9 | import java.nio.charset.StandardCharsets; |
10 | 10 | import java.nio.file.Files; |
11 | 11 | import java.nio.file.Path; |
12 | +import java.nio.file.StandardCopyOption; | |
13 | +import java.nio.file.StandardOpenOption; | |
12 | 14 | import java.text.NumberFormat; |
13 | 15 | import java.time.LocalDate; |
14 | 16 | import java.time.chrono.JapaneseChronology; |
@@ -777,7 +779,7 @@ | ||
777 | 779 | * @return 次期開始仕訳のYAML文字列 |
778 | 780 | * @throws IOException |
779 | 781 | */ |
780 | - public String createOpeningJournalEntries(Path path) throws IOException { | |
782 | + public String createNextOpeningJournalEntries(Path path) throws IOException { | |
781 | 783 | List<Entry<AccountTitle, Amount>> debtors = new ArrayList<>(); |
782 | 784 | long debtorsTotal = 0; |
783 | 785 | List<Entry<AccountTitle, Amount>> creditors = new ArrayList<>(); |
@@ -784,7 +786,10 @@ | ||
784 | 786 | long creditorsTotal = 0; |
785 | 787 | |
786 | 788 | StringBuilder sb = new StringBuilder(); |
787 | - String nextOpeningDate = DateTimeFormatter.ISO_LOCAL_DATE.format(this.closingDate.plusDays(1)); | |
789 | + String nextOpeningDate = null; | |
790 | + if(this.closingDate != null) { | |
791 | + nextOpeningDate = DateTimeFormatter.ISO_LOCAL_DATE.format(this.closingDate.plusDays(1)); | |
792 | + } | |
788 | 793 | |
789 | 794 | if(isSoloProprietorship) { |
790 | 795 | //個人事業主の場合は、事業主貸(資産)、事業主借(負債)、所得金額(資本)が次期の元入金に加算されます。 |
@@ -946,9 +951,25 @@ | ||
946 | 951 | |
947 | 952 | String s = sb.toString(); |
948 | 953 | |
949 | - if(path != null) { | |
950 | - try(Writer writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { | |
951 | - writer.write(s); | |
954 | + if(path != null && Files.isDirectory(path.getParent())) { | |
955 | + Path tmpFile = null; | |
956 | + try { | |
957 | + Path dir = path.getParent(); | |
958 | + // 会計年度フォルダーが存在する場合のみ次年度の開始仕訳を作成します。 | |
959 | + tmpFile = dir.resolve("次年度の開始仕訳.tmp"); | |
960 | + Files.writeString(tmpFile, s, StandardCharsets.UTF_8, | |
961 | + StandardOpenOption.CREATE, | |
962 | + StandardOpenOption.TRUNCATE_EXISTING, | |
963 | + StandardOpenOption.WRITE, | |
964 | + StandardOpenOption.SYNC); | |
965 | + | |
966 | + Files.move(tmpFile, path, | |
967 | + StandardCopyOption.REPLACE_EXISTING, | |
968 | + StandardCopyOption.ATOMIC_MOVE); | |
969 | + } finally { | |
970 | + if(tmpFile != null) { | |
971 | + try { Files.deleteIfExists(tmpFile); } catch(Exception ignore) {} | |
972 | + } | |
952 | 973 | } |
953 | 974 | } |
954 | 975 |