private string GetKaikeiKubunNameOfTyuukiRow(models.db.Row tyuukiRow)
 {
     return(db.MTKaikeiKubun.GetFirst("name", "where id=" + tyuukiRow.GetLong("kaikei_kubun", -1)) as string);
 }
Example #2
0
        // 償却
        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);
        }
Example #3
0
        private void AddMototyouReport(DataDynamics.ActiveReports.ActiveReport parentReport, int kanjouKamokuId, int parentKamokuId, bool isHojoKamoku)
        {
            models.query.KanjouMototyou mototyou = new models.query.KanjouMototyou(context.KaikeiDatabase);
            mototyou.Calc(
                popup.StartDate.Value,
                popup.EndDate.Value,
                kanjouKamokuId,
                popup.TargetKaikeiKubun,
                renumberDenpyouBangou: false,
                isHojoKamoku: isHojoKamoku);

            int    kaikeiKubun = popup.TargetKaikeiKubun;
            string houjinMei   = context.KaikeiDatabase.MTKaikeiKubun.GetRowFromCache(context.KaikeiDatabase.MTKaikeiKubun.RootNodeId).GetStr("name") as string;
            string shisetsuMei = "";

            if (kaikeiKubun != -1 && kaikeiKubun != context.KaikeiDatabase.MTKaikeiKubun.RootNodeId)
            {
                shisetsuMei = context.KaikeiDatabase.MTKaikeiKubun.GetRowFromCache(kaikeiKubun).GetStr("name") as string;
            }
            models.db.Row kanjouKamokuRow = context.KaikeiDatabase.MTKanjouKamoku.GetFirstRow("where id=" + kanjouKamokuId);
            string        kamokuMei       = kanjouKamokuRow.GetStr("kamoku", "");

            DataDynamics.ActiveReports.ActiveReport report = null;
            if (popup.RenzokuKeishikiChecked)
            {
                report = new views.reports.KanjouMototyou2();
                if (isHojoKamoku == false)
                {
                    (report as views.reports.KanjouMototyou2).SetHeader(houjinMei, shisetsuMei, kamokuMei, "", isHojoMototyou: false);
                }
                else
                {
                    models.db.Row parentKanjouKamokuRow = context.KaikeiDatabase.MTKanjouKamoku.GetFirstRow("where id=" + parentKamokuId);
                    string        parentKamokuMei       = parentKanjouKamokuRow.GetStr("kamoku", "");
                    (report as views.reports.KanjouMototyou2).SetHeader(houjinMei, shisetsuMei, parentKamokuMei, kamokuMei, isHojoMototyou: true);
                }
            }
            else
            {
                report = new views.reports.KanjouMototyou();
                (report as views.reports.KanjouMototyou).SetHeader(houjinMei, shisetsuMei, kamokuMei);
            }

            bool printReport = false;

            if (mototyou.MototyouRows.Count > 0)
            {
                report.DataSource = mototyou.MototyouRows;
                printReport       = true;
            }
            else if (mototyou.ZengetsuKurikoshiGaku != 0)
            {
                // 伝票がない場合、前期繰越の額を印刷する。
                List <models.query.KanjouMototyou.MototyouRow> rows = new List <models.query.KanjouMototyou.MototyouRow>();
                int taisyakuKubunId = (int)kanjouKamokuRow.GetLong("taisyaku_kubun_id", -1);

                long karikataKingaku  = 0;
                long kashikataKingaku = 0;

                switch ((models.constants.MTTaisyakuKubun)taisyakuKubunId)
                {
                case models.constants.MTTaisyakuKubun.KariPlus:
                case models.constants.MTTaisyakuKubun.KariMinus:
                    karikataKingaku = mototyou.ZengetsuKurikoshiGaku;
                    break;

                case models.constants.MTTaisyakuKubun.KashiPlus:
                case models.constants.MTTaisyakuKubun.KashiMinus:
                    kashikataKingaku = mototyou.ZengetsuKurikoshiGaku;
                    break;
                }

                var row = new models.query.KanjouMototyou.MototyouRow(
                    -1,
                    "",
                    -1,
                    DateTime.Now,
                    "",
                    "",
                    karikataKingaku,
                    kashikataKingaku,
                    mototyou.ZengetsuKurikoshiGaku,
                    null,
                    false,
                    mototyou.ZengetsuKurikoshiGaku
                    );
                rows.Add(row);

                if (popup.RenzokuKeishikiChecked)
                {
                    (report as views.reports.KanjouMototyou2).ZenkiKurikoshiOnly = true;
                }
                else
                {
                    (report as views.reports.KanjouMototyou).ZenkiKurikoshiOnly = true;
                }
                report.DataSource = rows;

                printReport = true;
            }

            if (printReport)
            {
                report.Run();
                parentReport.Document.Pages.AddRange(report.Document.Pages.GetRange(0, report.Document.Pages.Count));
            }
        }
Example #4
0
        private void CalcButtonClicked()
        {
            if (form.StartDate == null || form.EndDate == null)
            {
                helper.MsgBox.Err(KaikeiSystemBody.Properties.Resources.MsgInvalidDate);
                return;
            }

            form.ClearGrid();

            balanceSheet.Calc(form.StartDate.Value, form.EndDate.Value, form.KaikeiKubun, hideInnerKaikeiKubunKamoku: true);

            int year = helper.Converter.GetNenndo(form.StartDate.Value);

            foreach (var row in balanceSheet.AllKamokuSummary())
            {
                int           kamokuId       = row.Id;
                models.db.Row kamokuKubunRow = Context.KaikeiDatabase.MTKamokuKubun.GetRowFromCache(kamokuId);
                models.db.Row daikubunRow    = Context.KaikeiDatabase.MTKamokuKubun.GetRowFromCache((int)kamokuKubunRow.GetLong("parent_id", -1));
                string        daikubunStr    = daikubunRow != null?daikubunRow.GetStr("name", "") : "";

                if (row.TaisyakuKamokuKubunId == (int)models.constants.MTKamokuKubun.Shisan)
                {
                    form.AddShisanGridRow(
                        daikubunStr,
                        kamokuKubunRow.GetStr("name", ""),
                        row.CurrentSumAmount,
                        row.LastSumAmount,
                        row.Sai
                        );
                }
                if (row.TaisyakuKamokuKubunId == (int)models.constants.MTKamokuKubun.Husai)
                {
                    form.AddHusaiGridRow(
                        daikubunStr,
                        kamokuKubunRow.GetStr("name", ""),
                        row.CurrentSumAmount,
                        row.LastSumAmount,
                        row.Sai
                        );
                }
                if (row.TaisyakuKamokuKubunId == (int)models.constants.MTKamokuKubun.Junshisan)
                {
                    form.AddJunshisanGridRow(
                        daikubunStr,
                        kamokuKubunRow.GetStr("name", ""),
                        row.CurrentSumAmount,
                        row.LastSumAmount,
                        row.Sai
                        );
                }
            }

            foreach (models.query.BalanceSheet.SummaryItem item in Enum.GetValues(typeof(models.query.BalanceSheet.SummaryItem)))
            {
                models.query.BalanceSheet.BalanceSheetRow row = balanceSheet.GetSummaryItem(item);
                form.SetSummaryItem(item, row.CurrentSumAmount, row.LastSumAmount, row.Sai);
            }

            helper.MsgBox.Info(KaikeiSystemBody.Properties.Resources.MsgSucceeded);
        }