private void OnChangeZanzonWariai(models.db.Row row) { long zanzonKakaku = (long)Math.Ceiling(row.GetLong("syutoku_kakaku", 0) * row.GetDouble("zanzon_wariai", 0) / 100); row.Table.SetColumnValue(row, "zanzon_kakaku", zanzonKakaku); }
// 償却 public static bool CreateGenkaSyoukyakuMeisai(models.Context context, int koteiShisanId) { models.db.Row koteiShisanRow = context.KaikeiDatabase.MTKoteiShisan.GetRowById(koteiShisanId); if (koteiShisanRow == null) { return(false); } DateTime?syutokubi = koteiShisanRow.GetDate("syutoku_nenngappi"); long syutokuKakaku = koteiShisanRow.GetLong("syutoku_kakaku", -1); long taiyouNensuu = koteiShisanRow.GetLong("taiyou_nennsuu", -1); double syoukyakuritsu = koteiShisanRow.GetDouble("syoukyaku_ritsu", -1); double zanzonWariai = koteiShisanRow.GetDouble("zanzon_wariai", -1); if (syutokubi == null || syutokuKakaku < 0 || taiyouNensuu < 0 || syoukyakuritsu < 0 || zanzonWariai < 0) { return(false); } long zanzonKagaku = (long)Math.Round(syutokuKakaku * zanzonWariai / 100); DateTime gensyoubi = helper.Converter.DateTimeToNenndoKimatsubi(syutokubi.Value); long ruikeiSyoukyakuhi = 0; long ruikeiShiyouTsukisuu = 0; long kaisuu = 1; while (ruikeiShiyouTsukisuu < taiyouNensuu * 12) { long shiyouTsukisuu; if (ruikeiShiyouTsukisuu == 0) { shiyouTsukisuu = syutokubi.Value.Month >= 4 ? 15 - syutokubi.Value.Month : 3 - syutokubi.Value.Month; if (context.Setting.GetInt("kounyuutsuki_syoukyaku", 0) != 0) { shiyouTsukisuu++; } if (shiyouTsukisuu == 0) { gensyoubi = gensyoubi.AddYears(1); shiyouTsukisuu = 12; } } else if (taiyouNensuu * 12 - ruikeiShiyouTsukisuu < 12) { shiyouTsukisuu = taiyouNensuu * 12 - ruikeiShiyouTsukisuu; } else { shiyouTsukisuu = 12; } long syoukyakuhi = TeigakuhouGenkaSyoukyakuhi(syutokuKakaku, zanzonWariai, shiyouTsukisuu, syoukyakuritsu); long kisyuTyouboKagaku = syutokuKakaku - ruikeiSyoukyakuhi; ruikeiShiyouTsukisuu += shiyouTsukisuu; if (kisyuTyouboKagaku - syoukyakuhi < zanzonKagaku) // 償却残額が残存価額を下回る { syoukyakuhi = kisyuTyouboKagaku - zanzonKagaku; ruikeiSyoukyakuhi += syoukyakuhi; insertMeisaiRow(context, koteiShisanId, kaisuu, shiyouTsukisuu, syoukyakuhi, gensyoubi, kisyuTyouboKagaku, ruikeiSyoukyakuhi); break; } if (ruikeiShiyouTsukisuu == taiyouNensuu * 12 && // 最終年 kisyuTyouboKagaku - syoukyakuhi != zanzonKagaku) // 残存価額の調整が必要 { if (shiyouTsukisuu == 12) // 年跨ぎ { ruikeiSyoukyakuhi += syoukyakuhi; insertMeisaiRow(context, koteiShisanId, kaisuu, shiyouTsukisuu, syoukyakuhi, gensyoubi, kisyuTyouboKagaku, ruikeiSyoukyakuhi); shiyouTsukisuu = 1; kaisuu++; gensyoubi = gensyoubi.AddYears(1); kisyuTyouboKagaku = kisyuTyouboKagaku - syoukyakuhi; syoukyakuhi = kisyuTyouboKagaku - zanzonKagaku; ruikeiSyoukyakuhi += syoukyakuhi; insertMeisaiRow(context, koteiShisanId, kaisuu, shiyouTsukisuu, syoukyakuhi, gensyoubi, kisyuTyouboKagaku, ruikeiSyoukyakuhi); } else { shiyouTsukisuu += 1; syoukyakuhi = kisyuTyouboKagaku - zanzonKagaku; ruikeiSyoukyakuhi += syoukyakuhi; insertMeisaiRow(context, koteiShisanId, kaisuu, shiyouTsukisuu, syoukyakuhi, gensyoubi, kisyuTyouboKagaku, ruikeiSyoukyakuhi); } } else { ruikeiSyoukyakuhi += syoukyakuhi; insertMeisaiRow(context, koteiShisanId, kaisuu, shiyouTsukisuu, syoukyakuhi, gensyoubi, kisyuTyouboKagaku, ruikeiSyoukyakuhi); } kaisuu++; gensyoubi = gensyoubi.AddYears(1); } return(true); }