• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

b1f6c1c4 / ProfessionalAccounting / 307

25 Sep 2023 04:48AM UTC coverage: 56.975% (-1.3%) from 58.254%
307

push

appveyor

b1f6c1c4
raw subtotal more controllable

5947 of 10438 relevant lines covered (56.97%)

125.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.79
/AccountingServer.Entities/Util/SubtotalPreprocessor.cs
1
/* Copyright (C) 2020-2023 b1f6c1c4
2
 *
3
 * This file is part of ProfessionalAccounting.
4
 *
5
 * ProfessionalAccounting is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU Affero General Public License as
7
 * published by the Free Software Foundation, version 3.
8
 *
9
 * ProfessionalAccounting is distributed in the hope that it will be useful, but
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
12
 * for more details.
13
 *
14
 * You should have received a copy of the GNU Affero General Public License
15
 * along with ProfessionalAccounting.  If not, see
16
 * <https://www.gnu.org/licenses/>.
17
 */
18

19
using System;
20
using System.Linq;
21

22
namespace AccountingServer.Entities.Util;
23

24
public static class SubtotalPreprocessor
25
{
26
    public static SubtotalLevel PreprocessVoucher(this ISubtotal query)
27
    {
32✔
28
        if (query.GatherType != GatheringType.VoucherCount)
32✔
29
            throw new InvalidOperationException("记账凭证分类汇总只能计数");
×
30
        if (query.EquivalentDate.HasValue)
32✔
31
            throw new InvalidOperationException("记账凭证分类汇总不能等值");
×
32

33
        var level = query.Levels.Aggregate(SubtotalLevel.None, static (total, l) => total | l);
26✔
34
        if (query.AggrType != AggregationType.None)
32✔
35
            level |= query.AggrInterval;
5✔
36

37
        if (level.HasFlag(SubtotalLevel.User))
32✔
38
            throw new InvalidOperationException("记账凭证不能按用户分类汇总");
1✔
39
        if (level.HasFlag(SubtotalLevel.Currency))
31✔
40
            throw new InvalidOperationException("记账凭证不能按币种分类汇总");
1✔
41
        if (level.HasFlag(SubtotalLevel.Title))
30✔
42
            throw new InvalidOperationException("记账凭证不能按一级科目分类汇总");
1✔
43
        if (level.HasFlag(SubtotalLevel.SubTitle))
29✔
44
            throw new InvalidOperationException("记账凭证不能按二级科目分类汇总");
1✔
45
        if (level.HasFlag(SubtotalLevel.Content))
28✔
46
            throw new InvalidOperationException("记账凭证不能按内容分类汇总");
1✔
47
        if (level.HasFlag(SubtotalLevel.Remark))
27✔
48
            throw new InvalidOperationException("记账凭证不能按备注分类汇总");
1✔
49
        if (level.HasFlag(SubtotalLevel.Value))
26✔
50
            throw new InvalidOperationException("记账凭证不能按金额分类汇总");
×
51

52
        return level;
26✔
53
    }
26✔
54

55
    public static SubtotalLevel PreprocessDetail(this ISubtotal query)
56
    {
92✔
57
        var level = query.Levels.Aggregate(SubtotalLevel.None, static (total, l) => total | l);
75✔
58
        if (query.AggrType != AggregationType.None)
92✔
59
            level |= query.AggrInterval;
4✔
60
        if (query.EquivalentDate.HasValue)
92✔
61
            level |= SubtotalLevel.Currency;
×
62

63
        return level;
92✔
64
    }
92✔
65

66
    public static bool ShouldAvoidZero(this ISubtotal query)
67
        => query.AggrType != AggregationType.ChangedDay &&
92✔
68
            query.Levels.LastOrDefault().HasFlag(SubtotalLevel.NonZero);
69

70
    public static DateTime? Project(this DateTime? dt, SubtotalLevel level)
71
    {
×
72
        if (!dt.HasValue)
×
73
            return null;
×
74
        if (!level.HasFlag(SubtotalLevel.Day))
×
75
            return null;
×
76
        if (!level.HasFlag(SubtotalLevel.Week))
×
77
            return dt;
×
78
        if (level.HasFlag(SubtotalLevel.Year))
×
79
            return new(dt!.Value.Year, 1, 1);
×
80
        if (level.HasFlag(SubtotalLevel.Quarter))
×
81
            return new(dt!.Value.Year, (dt!.Value.Month + 2) / 3 * 3, 1);
×
82
        if (level.HasFlag(SubtotalLevel.Month))
×
83
            return new(dt!.Value.Year, dt!.Value.Month, 1);
×
84
        // if (level.HasFlag(SubtotalLevel.Week))
85
        return dt.Value.DayOfWeek switch
×
86
            {
87
                DayOfWeek.Monday => dt.Value.AddDays(-0),
×
88
                DayOfWeek.Tuesday => dt.Value.AddDays(-1),
×
89
                DayOfWeek.Wednesday => dt.Value.AddDays(-2),
×
90
                DayOfWeek.Thursday => dt.Value.AddDays(-3),
×
91
                DayOfWeek.Friday => dt.Value.AddDays(-4),
×
92
                DayOfWeek.Saturday => dt.Value.AddDays(-5),
×
93
                DayOfWeek.Sunday => dt.Value.AddDays(-6),
×
94
                _ => throw new ArgumentOutOfRangeException(),
×
95
            };
96
    }
×
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc