1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

会計ソフトの作成 19 月次試算表のテスト

Posted at

月次試算表を特定の年月について再現できるようになったので、利用しているアプリが算出する月次試算表と、作成中のアプリで、どの締日でも同じデータが取得できるのかをテストします。

作成中のアプリのロジックに100%の信頼があれば、こんなことは不要ですけども、ロジックで説明しても理解を得られない方もいるでしょうし、自分自身が100%の信頼とか持ち得ていません。

最初は、作成中アプリ側で月次試算表をテキスト化して出力、それと使用中アプリの出力する試算表汎用データが同一であることを、ファイル単位で比較する何らかのスクリプトを考えていたのですが、全く逆に、使用中ソフトが作成する月次試算表の汎用データをDBに入れちゃって、それと作成中アプリの月次試算表で同じ数値が並んでいるのかを調べる方が、結局は楽だし、そのデータは会計の特質から将来キャッシュとして利用できるはずと判断しました。計算の結果を先にDBに入れてしまうのは本末転倒の気もしますが、過去の蓄積されたデータを何か別なものに移すのであれば、慎重さは大事だろうと思います。

CREATE TABLE wkkaikei."xxx月次試算" (                                                       id integer NOT NULL,
    "年月" integer NOT NULL,
    "科目コード" integer NOT NULL,
    "科目名" text NOT NULL,
    "前残" integer NOT NULL,
    "借方金額" integer NOT NULL,
    "貸方金額" integer NOT NULL,
    "残高" integer NOT NULL,
    "備考" text --予備的な列
);

CREATE SEQUENCE wkkaikei."xxx月次試算_id_seq"
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE wkkaikei."xxx月次試算_id_seq" OWNED BY wkkaikei."xxx月次試算".id;
ALTER TABLE ONLY wkkaikei."xxx月次試算" ALTER COLUMN id SET DEFAULT nextval('wkkaikei."xxx月次試算_id_seq"'::regclass);
ALTER TABLE ONLY wkkaikei."xxx月次試算"
    ADD CONSTRAINT "xxx月次試算_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY wkkaikei."xxx月次試算"
    ADD CONSTRAINT "uxxx月次試算" UNIQUE ("年月", "科目コード");

それでテスト側の書き換え

public function test_get_trial_balance_by_month(): void
{
 //ありえない締日のテスト
 $response = KaikeiWorkModel::getTrialBalanceByMonth('2100/12/31');
 $this->assertFalse($response);

 //会計年度2020年から2024年のテスト
 $arr = DB::select("
select distinct replace(締日::text,'-','/') as 締日,締日 as fname
rom kaikei.work_仕訳_明細_増減
where 年度>= 2020 and 年度<=2024 order by 締日"); 

 foreach ($arr as $key => $val) {                                                             
   $response = KaikeiWorkModel::getTrialBalanceByMonth((string) $val->締日);
   $this->assertTrue(is_array($response));
   if (is_array($response)) {
   foreach ($response as $key => $val) {

     $年月 = substr(str_replace('-', '', substr($val->締日, 0, 7)), 2, 4); 

     $sql = 'select * from wkkaikei.xxx月次試算 where 年月= ? and 科目コード = ? ';
     $chkar = DB::select($sql, [$年月, $val->科目コード]); 

     //両者の比較                                                                             
     if ($chkar[0]->前残 != $val->前残) {
      dump($chkar[0], $val);
     }
    if ($chkar[0]->借方金額 != $val->借方) {
     dump($chkar[0], $val);
    }
    if ($chkar[0]->貸方金額 != $val->貸方) {
     dump($chkar[0], $val);
    }
   if ($chkar[0]->残高 != $val->残高) {
    dump($chkar[0], $val);
   }

 }

 }
 }
 }

このテスト結果、特定の決算仕訳時のみ出現する科目について、両者で不一致となることがわかりました。
そのため、$sqlstring_month の当該箇所の書き換え

case m.要素コード
when '5' then
 case m.科目貸借
  when '貸方' then to_int(前損益累計) - to_int(借方) + to_int(貸方) 
   else to_int(前損益累計) + to_int(借方) - to_int(貸方) 
 end 
 when '2' then
  case m.科目貸借
   when '借方' then to_int(前損益累計) + to_int(借方) - to_int(貸方)
   else          -(to_int(前損益累計) + to_int(借方) - to_int(貸方) ) 
  end 
  else to_int(残高) end as 残高,

この修正を加えて再度テストで全て同一となりました。
貸借、仕訳、勘定科目の組み合わせ8通りの中、科目貸借が通常と逆の場合が鬼門であることがわかります。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?