Published Date : 2021年2月21日17:31

パート3: 給与所得者の所得税と住民税を計算するAndroidアプリ
Part 3: Android App Calculates Income and Resident Taxes for Salaried Workers


This blog has an English translation


ニコニコ動画にアップした動画のまとめ記事です。

This is a summary blog post about a video I uploaded to NicoNico.

細かい部分は動画を参考にしてください。

Please refer to the video for details.


目次

Table of Contents




① 動画の説明
① Video Description



警告:

今回説明する給与所得者の所得税及び住民税を計算するツールは、あくまで簡易的なお遊び用のツールです。

正確な数値、計算方法は各自で調べて下さい。

このツールは大雑把に大体の見積りを計算して楽しむ為のツールです。

決して従業員の年末調整や個人の確定申告等に使用しないでください。

さらに、税金の計算方法は変更される場合があり、控除についても同様です。

また、控除や税金の計算方法が間違っている可能性もありますので、

あまり信用せずに、各自で調べてから実験してみてください。

このツールを使って何かしらの損害が発生したとしても、私は一切の責任を負いません。

Warning:

​The tool I'm going to show you for calculating income and residence taxes for salaried workers is just a simple tool for playing.

​Please check the exact number and calculation method by yourself.

​This tool is used to calculate rough estimates and enjoy them.

​Do not use for year-end adjustment of employees or for individual tax return.

In addition, the method of calculating taxes and deductions may change.

Also, there is a possibility that the deduction and tax calculation methods are incorrect.

Don't trust it too much, and test it yourself.

​I will not be liable for any damage caused by using this tool.

前回の続きです。

Continued from last time.


Responsive image

社会保険料の計算結果を表示する箇所の説明テキストです。

Text describing where to display the calculation result of the social insurance premium.

グリッドレイアウトを8行一列に設定して配置します。

Sets grid layout to 8 rows and 1 columns.

結果表示のプレイスホルダーテキストを表示します。

Displays the placeholder text for the result display.

IDを使ってビジビリティを操作して計算結果が出たら非表示にします。

Manipulate visibility using ID and hide it when the result comes out.

結果表示用のグリッドレイアウトの一行目は健康保険料の月額を表示させます。

The first line of the grid layout for results displays the monthly health insurance premium.

二行目は厚生年金保険料の月額の計算結果を表示させます。

The second line displays the calculation result of the monthly amount of welfare pension premiums

三行目は雇用保険料の月額の計算結果を表示させます。

The third line displays the calculation result of the monthly employment insurance premium.

四行目は健康保険料の年額の計算結果を表示させます。

The fourth line displays the calculation result of the annual amount of health insurance premiums.

五行目は厚生年金保険料の年額の計算結果を表示させます。

The fifth line displays the calculation result of the annual amount of employees' pension premiums.

六行目は雇用保険料の年額の計算結果を表示させます。

The sixth line displays the calculation result of the annual amount of the employment insurance premium.

七行目は全ての社会保険料を合わせた額の12か月分の計算結果を表示させます。

The seventh line displays the calculation results for 12 months of the total amount of social insurance premiums.

八行目は社会保険料の総額の一か月分の計算結果を表示させます。

The eighth line displays the calculation results for one month of the total amount of social insurance premiums.

これで社会保険料の計算結果を表示するレイアウトの準備が整いました。

You are now ready to view the results of the social insurance calculation.

メインアクティビティのJavaファイルを開いてください。

Open the Java file for the main activity.

スピナーの変数を用意します。

Prepare the spinner variable.

スピナー型として変数を宣言すればライブラリは自動でインポートされます。

Declaring a variable as type spinner will automatically import the library.

スピナーの為のアレイアダプターの変数を用意します。

Prepare the array adapter variable for the spinner.

スピナーで選択された値を入れる変数です。

A variable that stores the value selected by the spinner.

宣言した変数をオンクリエイトメソッド内で初期化していきます。

The declared variable is initialized in the onCreate method.

月額の給与を選択する為に必要な一連の作業を別のメソッドととしてまとめましょう。

Let's make the set of tasks required to select a monthly salary in a separate method.

月額の給与の範囲における社会保険料の一覧をCSVファイルにして、そのファイルを読み込み整理するクラスファイルを作成する必要があります。

You need to create a CSV file of the list of social insurance premiums in the monthly salary range and create a class file to read and organize the file.

では[app]で右クリックをして、画面の指示通りにアセッツフォルダを作成してください。

Right-click in [app] and create the assets folder as instructed on the screen.

作成したアセッツフォルダに前回動画シリーズで使用した月額の給与の範囲における社会保険料の一覧のCSVファイルをコピペします。

Copy and paste the CSV file of the list of social insurance premiums in the monthly salary range used in the previous my video series into the created assets folder.

tableOfPremium.csv
月額円以上,月額円未満,健保介無全額,健保介無折半額,健保介有全額,健保介有折半額,厚生一般全額,厚生一般折半額
0,63000,5724.6,2862.3,6762.8,3381.4,16104,8052
63000,73000,6711.6,3355.8,7928.8,3964.4,16104,8052
73000,83000,7698.6,3849.3,9094.8,4547.4,16104,8052
83000,93000,8685.6,4342.8,10260.8,5130.4,16104,8052
93000,101000,9672.6,4836.3,11426.8,5713.4,17934,8967
101000,107000,10264.8,5132.4,12126.4,6063.2,19032,9516
107000,114000,10857,5428.5,12826,6413,20130,10065
114000,122000,11646.6,5823.3,13758.8,6879.4,21594,10797
122000,130000,12436.2,6218.1,14691.6,7345.8,23058,11529
130000,138000,13225.8,6612.9,15624.4,7812.2,24522,12261
138000,146000,14015.4,7007.7,16557.2,8278.6,25986,12993
146000,155000,14805,7402.5,17490,8745,27450,13725
155000,165000,15792,7896,18656,9328,29280,14640
165000,175000,16779,8389.5,19822,9911,31110,15555
175000,185000,17766,8883,20988,10494,32940,16470
185000,195000,18753,9376.5,22154,11077,34770,17385
195000,210000,19740,9870,23320,11660,36600,18300
210000,230000,21714,10857,25652,12826,40260,20130
230000,250000,23688,11844,27984,13992,43920,21960
250000,270000,25662,12831,30316,15158,47580,23790
270000,290000,27636,13818,32648,16324,51240,25620
290000,310000,29610,14805,34980,17490,54900,27450
310000,330000,31584,15792,37312,18656,58560,29280
330000,350000,33558,16779,39644,19822,62220,31110
350000,370000,35532,17766,41976,20988,65880,32940
370000,395000,37506,18753,44308,22154,69540,34770
395000,425000,40467,20233.5,47806,23903,75030,37515
425000,455000,43428,21714,51304,25652,80520,40260
455000,485000,46389,23194.5,54802,27401,86010,43005
485000,515000,49350,24675,58300,29150,91500,45750
515000,545000,52311,26155.5,61798,30899,96990,48495
545000,575000,55272,27636,65296,32648,102480,51240
575000,605000,58233,29116.5,68794,34397,107970,53985
605000,635000,61194,30597,72292,36146,113460,56730
635000,665000,64155,32077.5,75790,37895,118950,59475
665000,695000,67116,33558,79288,39644,118950,59475
695000,730000,70077,35038.5,82786,41393,118950,59475
730000,770000,74025,37012.5,87450,43725,118950,59475
770000,810000,77973,38986.5,92114,46057,118950,59475
810000,855000,81921,40960.5,96778,48389,118950,59475
855000,905000,86856,43428,102608,51304,118950,59475
905000,955000,91791,45895.5,108438,54219,118950,59475
955000,1005000,96726,48363,114268,57134,118950,59475
1005000,1055000,101661,50830.5,120098,60049,118950,59475
1055000,1115000,107583,53791.5,127094,63547,118950,59475
1115000,1175000,113505,56752.5,134090,67045,118950,59475
1175000,1235000,119427,59713.5,141086,70543,118950,59475
1235000,1295000,125349,62674.5,148082,74041,118950,59475
1295000,1355000,131271,65635.5,155078,77539,118950,59475
1355000,0,137193,68596.5,162074,81037,118950,59475

では次にメインのパッケージ上で右クリックして、画面の指示通りにJavaクラスファイルを作成してください。

Then right-click on the main package and follow the on-screen instructions to create the Java class file.

月額の給与の範囲とヘッダー、その月額の給与の範囲における社会保険料をそれぞれ格納するリスト型変数を用意していきます。

We will prepare a list variable to store the monthly salary range and header, and the social insurance premium within the monthly salary range.

変数を用意した後に画面上で右クリックして画面の指示に従ってその変数のゲッターを作成してください。

After preparing the variables, right-click on the screen and follow the instructions on the screen to create getters for them.

ではCSVファイルを読み込んで整理するメソッドを作成していきましょう。

Let's create a method to load and organize CSV files.

CSVファイルの読み込みにおけるバッファードリーダーの詳しい説明は前回の動画シリーズを参考にしてください。

Refer to my previous video series for a detailed explanation of the buffered reader for reading CSV files.

AssetManager assetManager = context.getResources().getAssets();
try {
    InputStream inputStream = assetManager.open("tableOfPremium.csv");
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    BufferedReader bufferReader = new BufferedReader(inputStreamReader);


    ............................................................................

このあたりの処理も前回の動画シリーズの時とほぼ同じです。

These processes are almost identical to my previous video series.

一つ違うのは月額の給与の範囲をそのまま選択可能にしている事で、ユーザーからの入力された値を基に計算する方法と違ってシンプルになっています。

One difference is that you can choose the range of monthly salary as it is, which is simpler than calculating based on user input.

これでCSVファイルを扱うクラスファイルの準備が整ったのでメインアクティビティのJavaファイルに戻り、クリエイトアダプターメソッドの作成の続きを開始しましょう。

Now that we have a class file to work with the CSV file, let's return to the main activity Java file and continue creating the Create Adapter method.

CSVドライバーを使ってリストアダプターに月額の給与の範囲を加えていきます。

Use the CSV driver to add the monthly salary range to the list adapter.

レイアウトのIDからスピナーのインスタンスを作成します。

Creates instances of the spinners from the layout IDs.

デフォルトでリストの18番目の値をセットします。この値は各自で好きなように設定してください。

Set the 18th value in the list by default. Set this value as you like.

ではチェックボックスがチェックされた時の処理をメソッドにして記述していきましょう。

Now let's write a method that takes care of what happens when the checkbox is checked.

チェックボックスがチェックされたかどうかを判定するブーリアン型変数とチェックボックスのインスタンスを作成します。

Creates a boolean variable to determine if the checkbox is checked. Creates instances of check boxes.

スウィッチ文の中でチェックボックスのID毎に行う処理を分けます。

Separate processing for each check box ID in the switch statement.

片方がチェックされた時はもう片方のチェックボックスのチェックを外すようにすれば、二つのチェックボックスが同時にチェックされることはありません。

If one check box is checked, the other check box is unchecked so that the two check boxes are not checked at the same time.

では次に社会保険料の計算ボタンが押された時の処理を書いてきましょう。

Next, let's write down the process when the social insurance premium calculation button is pressed.

計算結果の表示に必要な変数を用意して、プレイスホルダー用のテキストビューのインスタンスを作成します。

Prepare the variables necessary to display the calculation results. Creates an instance of the text view for the place holder.

チェックボックスとスピナーで選択された値を基にCSVドライバーから社会保険料を取得します。

Gets the social insurance premium from the CSV driver based on the value selected by the check box and spinner.

社会保険料の表示をしてプレイスホルダーを画面から見えなくしたいので、ビジビリティをインビジブルに設定します。

I want to hide the place holder from the screen by showing the social insurance premium, so I set the visibility to Invisible.

では実際に社会保険料を画面に表示させるメソッドを作成しましょう。

Then, let's create a method to actually display the social insurance premium on the screen.

チェックボックスがチェックされていない時にボタンが押された時の処理もelse文の中に記述しましょう。

Also describe in the else statement what happens when a button is pressed when the checkbox is not checked.

一先ず作成されていないメソッドの行をコメントアウトして途中経過のアプリの動作を確認してみましょう。

First of all, let's comment out the lines of the methods that have not been created and see how the application works.


Responsive image


Responsive image

きちんと動作されている事を確認してください。

Make sure it works properly.

パート4へ続く。

Continue to Part 4.



以上です。お疲れ様です。

That's all. Thank you for your hard work.