예제 #1
0
        public Dictionary <RepGroupKey, EventRepInfo> SumGroupTotals(int k,
                                                                     List <EventRepInfo> list, List <string> keys, List <int> ids)
        {
            var    ret = new Dictionary <RepGroupKey, EventRepInfo>();
            string list_cur = null, key_cur = null;

            for (int i = 0; i < list.Count; i++)
            {
                var ev_cur = list[i];
                list_cur = ev_cur.GetSField(k);
                int pos = keys.BinarySearch(list_cur);
                if (pos >= 0 && pos < keys.Count)
                {
                    pos += 1;
                }
                if (pos < 0)
                {
                    pos = ~pos;
                }
                pos--;
                if (pos == -1)
                {
                    continue;
                }
                EventRepInfo ev_dic = null;
                while (pos >= 0)
                {
                    key_cur = keys[pos];
                    if (!list_cur.StartsWith(key_cur))
                    {
                        break;
                    }
                    var gk = new RepGroupKey(5);
                    gk.Fields[0] = key_cur;
                    if (!ret.TryGetValue(gk, out ev_dic))
                    {
                        ev_dic = new EventRepInfo();
                        ev_dic.FieldSortOrder = ev_cur.FieldSortOrder;
                        ev_dic.SetFieldId(k, ids[pos]);
                        ev_dic.SetSField(k, key_cur);
                        ev_dic.RCat1 = key_cur;
                        ev_dic.SetName1(k);
                        ev_dic.IsTotal = true;
                        ret[gk]        = ev_dic;
                    }
                    ev_dic.Add(ev_cur);

                    pos--;
                }
            }
            return(ret);
        }
예제 #2
0
        public void MakeGroupReport()
        {
            ReportRows = new List <EventRepInfo>();
            var table_items = MyData.DataSetKlons.ITEMS;
            var drs_items   = table_items.WhereNotDeleted();

            GroupingDict = new Dictionary <RepGroupKey, EventRepInfo>();
            int[] groupingorder = new[] { GroupOrderCat1, GroupOrderCatD, GroupOrderCatT,
                                          GroupOrderDep, GroupOrderPlace };
            int[] groupingorderA = GetBackSortOrder(groupingorder);
            bool  ShowDescr      = groupingorderA[1] == -1;

            var DT1x = DT1.FirstDayOfMonth().AddDays(-1);

            foreach (var dr_item in drs_items)
            {
                var it = new ItemInfo();
                it.SetFromRow(dr_item);
                if (it.Events.Count == 0)
                {
                    continue;
                }
                if (it.Events[0].Dt > DT2)
                {
                    continue;
                }
                if (it.Events.Count > 1)
                {
                    var ev = it.Events[it.Events.Count - 1];
                    if (ev.XEvent == EEvent.likvid && ev.Dt < DT1)
                    {
                        continue;
                    }
                }

                var rt = it.CheckItem();
                if (rt != "OK")
                {
                    continue;
                }
                var rev1 = new EventRepInfo()
                {
                    Dt        = DT1x,
                    LastInDay = true,
                    XEvent    = EEvent.apr
                };
                var rev2 = new EventRepInfo()
                {
                    Dt        = DT2,
                    LastInDay = true,
                    XEvent    = EEvent.apr
                };
                it.Events2 = new List <EventInfo>();
                it.Events2.Add(rev1);

                for (int i = 1; i < it.Events.Count; i++)
                {
                    var ev = it.Events[i];
                    if (ev.XEvent != EEvent.rekat)
                    {
                        continue;
                    }
                    var ev_pr = it.Events[i - 1];
                    if (ev.Dt < DT1 || ev.Dt > DT2)
                    {
                        continue;
                    }
                    if (!IsGroupingKeyChanged(ev_pr, ev))
                    {
                        continue;
                    }

                    var ev_new = new EventRepInfo();
                    ev_new.Dt        = ev.Dt;
                    ev_new.LastInDay = false;
                    it.Events2.Add(ev_new);
                }

                it.Events2.Add(rev2);
                rt = it.FullCalc();
                if (rt != "OK")
                {
                    continue;
                }

                if (it.Events2.Count > 2)
                {
                    for (int i = 1; i < it.Events2.Count - 1; i++)
                    {
                        var evr  = it.Events2[i] as EventRepInfo;
                        var evrn = it.Events2[i + 1] as EventRepInfo;

                        evr.ValueRecat      = -evr.Value1;
                        evr.DeprecRecat     = -evr.Deprec1;
                        evr.TaxValRecatCalc = -evr.TaxValLeft0;

                        evrn.ValueRecat      = evr.Value1;
                        evrn.DeprecRecat     = evr.Deprec1;
                        evrn.TaxValRecatCalc = evr.TaxValLeft0;

                        evr.Value0     = 0.0M;
                        evr.Value1     = 0.0M;
                        evr.Deprec0    = 0.0M;
                        evr.Deprec1    = 0.0M;
                        evr.ValueLeft0 = 0.0M;
                        evr.ValueLeft1 = 0.0M;

                        evr.TaxVal      = 0.0M;
                        evr.TaxValLeft1 = 0.0M;
                        evr.TaxValLeft0 = 0.0M;
                        evr.TaxDeprec   = 0.0M;
                    }
                }

                for (int i = 0; i < it.Events2.Count; i++)
                {
                    var evr = it.Events2[i] as EventRepInfo;
                    evr.TaxValC = evr.TaxValNewCalc + evr.TaxValAddCalc
                                  + evr.TaxValRecatCalc - evr.TaxValExcludeCalc;
                }


                rev1.Value1      = 0.0M;
                rev1.Deprec1     = 0.0M;
                rev1.ValueLeft1  = 0.0M;
                rev1.ValueC      = 0.0M;
                rev1.DeprecC     = 0.0M;
                rev1.TaxVal      = 0.0M;
                rev1.TaxValC     = 0.0M;
                rev1.TaxValLeft1 = 0.0M;
                rev1.TaxDeprec   = 0.0M;

                rev1.ValueNew            = 0.0M;
                rev1.ValueAdd            = 0.0M;
                rev1.ValueRevalue        = 0.0M;
                rev1.ValueExclude        = 0.0M;
                rev1.DeprecNew           = 0.0M;
                rev1.DeprecAdd           = 0.0M;
                rev1.DeprecRevalue       = 0.0M;
                rev1.DeprecExclude       = 0.0M;
                rev1.DeprecCalc          = 0.0M;
                rev1.TaxValNewCalc       = 0.0M;
                rev1.TaxValAddCalc       = 0.0M;
                rev1.TaxValExcludeCalc   = 0.0M;
                rev1.TaxDeprecCalc       = 0.0M;
                rev1.TaxValLeftAtEndCalc = 0.0M;

                rev2.Value0      = 0.0M;
                rev2.Deprec0     = 0.0M;
                rev2.ValueLeft0  = 0.0M;
                rev2.TaxVal      = 0.0M;
                rev2.TaxValLeft0 = 0.0M;
                rev2.TaxDeprec   = 0.0M;

                rev2.ValueNew      += rev2.ValueAdd;
                rev2.ValueAdd       = 0.0M;
                rev2.DeprecRevalue += rev2.DeprecNew + rev2.DeprecAdd;
                rev2.DeprecNew      = 0.0M;
                rev2.DeprecAdd      = 0.0M;

                if (rev2.State == EState.OK || rev2.State == EState.NotUsed)
                {
                    rev2.CountAtEnd = 1;
                }

                foreach (var ev in it.Events2)
                {
                    if (ev.Cat1 == 0 && ev.CatD == 0 && ev.CatT == 0 &&
                        ev.Department == 0 && ev.Place == 0)
                    {
                        continue;
                    }

                    var evr = ev as EventRepInfo;
                    evr.FieldSortOrder = groupingorder;

                    evr.SetSFields();
                    if (DoFilter && !FilterEvent(evr))
                    {
                        continue;
                    }
                    evr.SetSFieldsIgnore();
                    evr.SetRFields();

                    var gk = new RepGroupKey()
                    {
                        GroupingOrder = groupingorder,
                        Fields        = new[] { evr.SCat1, evr.SCatD, evr.SCatT, evr.SDepartment,
                                                evr.SPlace }
                    };

                    EventRepInfo evr_dic = null;
                    if (!GroupingDict.TryGetValue(gk, out evr_dic))
                    {
                        evr_dic = new EventRepInfo()
                        {
                            Cat1       = evr.Cat1,
                            CatD       = evr.CatD,
                            CatT       = evr.CatT,
                            Department = evr.Department,
                            Place      = evr.Place,

                            SCat1       = evr.SCat1,
                            SCatD       = evr.SCatD,
                            SCatT       = evr.SCatT,
                            SDepartment = evr.SDepartment,
                            SPlace      = evr.SPlace,

                            RCat1 = evr.RCat1,
                            RCat2 = evr.RCat2,
                            RCat3 = evr.RCat3,
                            RCat4 = evr.RCat4,
                            RCat5 = evr.RCat5,

                            FieldSortOrder = groupingorder
                        };

                        if (ShowDescr)
                        {
                            evr_dic.SetName1(groupingorderA[0]);
                        }

                        GroupingDict[gk] = evr_dic;
                    }
                    evr_dic.Add(evr);
                }
            }

            var evs = GroupingDict
                      .Where(d => FilterGroupingKey(d.Key))
                      .OrderBy(d => d.Key)
                      .Select(d => d.Value);

            ReportRows.AddRange(evs);

            if (!AddTotals)
            {
                return;
            }

            int firstGroupField = groupingorderA[0];
            var sum             = SumTotals(ReportRows, firstGroupField);

            if (ReportRows.Count > 0 && (GroupOrderCat1 == 0 ||
                                         GroupOrderDep == 0 || GroupOrderDep == 0))
            {
                List <string> keys = null;
                List <int>    ids  = null;
                GetTotalsKeys(firstGroupField, out keys, out ids);
                if (keys.Count > 0)
                {
                    var dic_totals = SumGroupTotals(firstGroupField, ReportRows, keys, ids);
                    foreach (var kv in dic_totals)
                    {
                        kv.Key.GroupingOrder = groupingorder;
                        GroupingDict[kv.Key] = kv.Value;
                    }

                    var evs2 = GroupingDict
                               .Where(d => FilterGroupingKey(d.Key))
                               .OrderBy(d => d.Key)
                               .Select(d => d.Value)
                               .ToArray();

                    ReportRows.Clear();
                    ReportRows.AddRange(evs);
                }
            }
            ReportRows.Add(sum);
        }