Пример #1
0
        private void PrepareListT(VacationCalcInfo[] vcs, string[] positions, VacationCalcInfo totalvc)
        {
            if (totalvc.Rows.Count == 0)
            {
                return;
            }

            var Rows2 = new List <VacationCalcRow>();

            Rows2.Add(new VacationCalcRow()
            {
                Caption = "Kopsummas"
            });
            Rows2.AddRange(totalvc.Rows);

            var emptyrow = new VacationCalcRow()
            {
            };

            for (int i = 0; i < vcs.Length; i++)
            {
                Rows2.Add(emptyrow);
                Rows2.Add(new VacationCalcRow()
                {
                    Caption = positions[i]
                });
                Rows2.AddRange(vcs[i].Rows);
            }
            Rows = Rows2;
        }
Пример #2
0
        public void CountVacationTime(VacationCalcRow vcr)
        {
            int   days  = 0;
            float hours = 0.0f;

            CountVacationTime(vcr.DateStart, vcr.DateEnd, out days, out hours);
            vcr.Days  = days;
            vcr.Hours = hours;
        }
Пример #3
0
        public void CalcAndAddSplit(SalarySheetRowInfo sr, VacationCalcRow v, int calcver)
        {
            var pcri = new CalcRInfo(false, calcver);

            pcri.CalcR(sr, v.DateStart, v.DateEnd);
            v.DNS  = KlonsData.RoundA(pcri.RateDNSN * v.Pay / 100.0M, 2);
            v.Cash = v.Pay - v.DNS;
            Add(v);
        }
Пример #4
0
        private VacationCalcRow AddRepRow(VacationCalcRow pvr, string ptype, string ppos)
        {
            var vr = new VacationCalcRow();

            vr.SetFrom(pvr);
            vr.Type     = ptype;
            vr.Position = ppos;
            Rows.Add(vr);
            return(vr);
        }
Пример #5
0
 public void Add(VacationCalcRow vr)
 {
     Days        += vr.Days;
     Hours       += vr.Hours;
     Pay         += vr.Pay;
     DNS         += vr.DNS;
     BeforeIINEX += vr.BeforeIINEX;
     IINEX       += vr.IINEX;
     IIN         += vr.IIN;
     Cash        += vr.Cash;
 }
Пример #6
0
        public void CalcAndAdd(SalarySheetRowInfo sr, VacationCalcRow v,
                               decimal AvPayRateDay, int calcver)
        {
            v.AvPayRate = AvPayRateDay;
            v.Pay       = KlonsData.RoundA(AvPayRateDay * (decimal)v.Days, 2);
            var pcri = new CalcRInfo(false, calcver);

            pcri.CalcR(sr, v.DateStart, v.DateEnd);
            v.DNS  = KlonsData.RoundA(pcri.RateDNSN * v.Pay / 100.0M, 2);
            v.Cash = v.Pay - v.DNS;
            Add(v);
        }
Пример #7
0
        public void CalcAndAddNextA(SalarySheetRowInfo sr, VacationCalcRow v)
        {
            Add(v);
            VacationCalcRow vcmt = null;
            int             yrmt = v.DateStart.Year * 12 + v.DateStart.Month - 1;

            if (!PerMonth.TryGetValue(yrmt, out vcmt))
            {
                vcmt           = new VacationCalcRow();
                vcmt.DateStart = v.DateStart;
                vcmt.DateEnd   = v.DateEnd;
                //vcmt.DateStart = new DateTime(v.DateStart.Year, v.DateStart.Month, 1);
                //vcmt.DateEnd = vcmt.DateStart.LastDayOfMonth();
                PerMonth[yrmt] = vcmt;
            }
            vcmt.Add(v);
        }
Пример #8
0
 public void SetFrom(VacationCalcRow vr)
 {
     IsTotal     = vr.IsTotal;
     Position    = vr.Position;
     this.Type   = vr.Type;
     Caption     = vr.Caption;
     DateStart   = vr.DateStart;
     DateEnd     = vr.DateEnd;
     Days        = vr.Days;
     Hours       = vr.Hours;
     AvPayRate   = vr.AvPayRate;
     Pay         = vr.Pay;
     DNS         = vr.DNS;
     BeforeIINEX = vr.BeforeIINEX;
     IINEX       = vr.IINEX;
     IIN         = vr.IIN;
     Cash        = vr.Cash;
 }
Пример #9
0
        public void CalcAndAddNext(SalarySheetRowInfo sr, VacationCalcRow v,
                                   decimal AvPayRateDay)
        {
            v.AvPayRate = AvPayRateDay;
            v.Pay       = KlonsData.RoundA(AvPayRateDay * (decimal)v.Days, 2);
            Add(v);
            VacationCalcRow vcmt = null;
            int             yrmt = v.DateStart.Year * 12 + v.DateStart.Month - 1;

            if (!PerMonth.TryGetValue(yrmt, out vcmt))
            {
                vcmt           = new VacationCalcRow();
                vcmt.DateStart = v.DateStart;
                vcmt.DateEnd   = v.DateEnd;
                //vcmt.DateStart = new DateTime(v.DateStart.Year, v.DateStart.Month, 1);
                //vcmt.DateEnd = vcmt.DateStart.LastDayOfMonth();
                PerMonth[yrmt] = vcmt;
            }
            vcmt.Add(v);
        }
Пример #10
0
        public void SumTotals(VacationCalcInfo[] vcs, VacationCalcInfo totalvc)
        {
            VcrPrevCurrent  = new VacationCalcRow("A: izmaksāts iepriekš");
            VcrCurrent      = new VacationCalcRow("B: šajā periodā");
            VcrNext         = new VacationNextCalcRow("C: aprēķināts avansā");
            VcrCompensation = new VacationCalcRow("D: kompensācija");

            foreach (var vc in vcs)
            {
                VcrPrevCurrent.Add(vc.VcrPrevCurrent);
                VcrCurrent.Add(vc.VcrCurrent);
                VcrCompensation.Add(vc.VcrCompensation);
                VcrNext.Add(vc.VcrNext);
            }

            VcrPrevCurrent.Days  = totalvc.VcrPrevCurrent.Days;
            VcrCurrent.Days      = totalvc.VcrCurrent.Days;
            VcrCompensation.Days = totalvc.VcrCompensation.Days;
            VcrNext.Days         = totalvc.VcrNext.Days;
        }
Пример #11
0
        private void PrepareListB(SalarySheetRowInfo sr, VacationCalcInfo totalvc)
        {
            if (totalvc.Rows.Count == 0)
            {
                return;
            }
            var rows2 = new List <VacationCalcRow>();
            var r1    = new VacationCalcRow();

            r1.Caption = "Kopā";
            rows2.Add(r1);
            rows2.AddRange(totalvc.Rows);

            rows2.Add(new VacationCalcRow());

            r1         = new VacationCalcRow();
            r1.Caption = sr.GetPositionTitle();
            rows2.Add(r1);
            rows2.AddRange(Rows);
            Rows = rows2;
        }
Пример #12
0
        private void EnsureExactSum(VacationCalcRow v, VacationCalcInfo[] vx,
                                    Func <VacationCalcInfo, VacationCalcRow> fgetx,
                                    Func <VacationCalcRow, decimal> fget, Action <VacationCalcRow, decimal> fset)
        {
            VacationCalcRow v0 = null;
            decimal         s  = fget(v);

            foreach (var vi in vx)
            {
                var     vj = fgetx(vi);
                decimal d  = fget(vj);
                s -= d;
                if (v0 == null && d != 0.0M)
                {
                    v0 = vj;
                }
            }
            if (v0 != null)
            {
                fset(v0, fget(v0) + s);
            }
        }
Пример #13
0
        public PayFx CalcAll(SalarySheetRowInfo sr, VacationCalcRow v, int calcver)
        {
            var cri = new CalcRInfo(false, calcver);

            cri.CalcR(sr, v.DateStart, v.DateEnd);
            var pfx = new PayFx(cri);

            if (cri.UseProgresiveIINRate)
            {
                pfx.IinEx = 0.0M;
            }
            else
            {
                pfx.IinEx = cri.ExMax2.SumIINExempts();
            }
            pfx.Pay = v.Pay;
            pfx.CalcAllAndRound();
            v.DNS   = pfx.DNS;
            v.IINEX = pfx.UsedIinEx;
            v.IIN   = pfx.IIN;
            v.Cash  = pfx.Cash;
            return(pfx);
        }
Пример #14
0
        public void CalcAll(SalarySheetRowInfo sr, VacationCalcInfo[] vcs, int calcver)
        {
            Days  = 0.0f;
            Hours = 0.0f;
            Pay   = 0.0M;
            DNS   = 0.0M;
            IINEX = 0.0M;
            IIN   = 0.0M;
            Cash  = 0.0M;

            foreach (var v in PerMonth)
            {
                CalcAll(sr, v.Value, calcver);
                Add(v.Value);
            }

            if (vcs == null)
            {
                return;
            }


            var pfx = new PayFx();

            pfx.Pay       = Pay;
            pfx.DNS       = DNS;
            pfx.UsedIinEx = IINEX;
            pfx.IIN       = IIN;
            pfx.Cash      = Cash;

            var vcrms = new VacationCalcRow[vcs.Length];
            var pfxs  = new PayFx[vcs.Length];

            for (int i = 0; i < vcs.Length; i++)
            {
                var vci = vcs[i];
                if (vci == null)
                {
                    continue;
                }
                var vcri = vci.VcrCompensation;
                vcrms[i] = vcri;
                var pfx1 = new PayFx();
                pfx1.Pay = vcri.Pay;
                pfxs[i]  = pfx1;
            }

            PayFx.SplitAndRound(pfx, pfxs);

            for (int i = 0; i < vcs.Length; i++)
            {
                var vci = vcs[i];
                if (vci == null)
                {
                    continue;
                }
                var vcrm = vcrms[i];
                var pfx1 = pfxs[i];
                vcrm.DNS   = pfx1.DNS;
                vcrm.IINEX = pfx1.UsedIinEx;
                vcrm.IIN   = pfx1.IIN;
                vcrm.Cash  = pfx1.Cash;
            }
        }
Пример #15
0
        public ErrorList CalcVacationDays2(SalarySheetRowInfo srs, VacationCalcInfo[] vcs, int calcver)
        {
            var error_list = new ErrorList();

            if (vcs != null && srs != srs?.SalarySheetRowSet?.TotalRow)
            {
                throw new ArgumentException("Bad call.");
            }

            var dt1  = srs.SalarySheet.DT1;
            var dt2  = srs.SalarySheet.DT2;
            var mdt1 = srs.SalarySheet.MDT1;
            var mdt2 = srs.SalarySheet.MDT2;

            var ps = srs.Events.Vacations.LinkedPeriods.Where(
                d =>
            {
                if (!SomeDataDefs.IsEventPaidVacation(d.EEventId))
                {
                    return(false);
                }

                var dr_not = (d.Item1 as KlonsADataSet.EVENTSRow);
                if (dr_not.IsDATE3Null())
                {
                    return(false);
                }

                return((d.DateFirst <= dt2 && d.DateLast >= dt1) ||
                       (dr_not.DATE3 >= dt1 && dr_not.DATE3 <= dt2));
            }).ToArray();


            // kompensācija atlaižot
            var fire_evs = srs.Events.HireFire.LinkedPeriods
                           .Where(d => d.DateLast >= dt1 && d.DateLast <= dt2)
                           .ToArray();

            if (ps.Length == 0 && fire_evs.Length == 0)
            {
                return(error_list);
            }

            var ps_cur = ps.Where(
                d =>
                d.DateFirst <= dt2 && d.DateLast >= dt1
                ).ToArray();

            var ps_next = ps.Where(
                d =>
            {
                var dr_not = (d.Item1 as KlonsADataSet.EVENTSRow);
                if (dr_not.IsDATE3Null())
                {
                    return(false);
                }
                return((d.DateLast > dt2) &&
                       (dr_not.DATE3 >= dt1 && dr_not.DATE3 <= dt2));
            }).ToArray();

            var ps_prev = ps_cur.Where(
                d =>
            {
                var dr_not = (d.Item1 as KlonsADataSet.EVENTSRow);
                if (dr_not.IsDATE3Null())
                {
                    return(false);
                }
                return(dr_not.DATE3 < dt1);
            }).ToArray();



            SalaryInfo prevsi = srs.GetPrevRow();

            if (prevsi != null)
            {
                VcrPrev.Pay = prevsi._VACATION_PAY_NEXT;
                VcrPrev.DNS = prevsi._VACATION_DNS_NEXT;
                VcrPrev.IIN = prevsi._VACATION_IIN_NEXT;
                AdvancePrev = prevsi._VACATION_ADVANCE_NEXT;

                if (vcs != null)
                {
                    for (int i = 0; i < vcs.Length; i++)
                    {
                        var vci = vcs[i];
                        if (vci == null)
                        {
                            continue;
                        }
                        var sr      = srs.SalarySheetRowSet.LinkedRows[i];
                        var prevsi2 = sr.GetPrevRow();
                        if (prevsi2 == null)
                        {
                            continue;
                        }
                        vci.VcrPrev.Pay = prevsi._VACATION_PAY_NEXT;
                        vci.VcrPrev.DNS = prevsi._VACATION_DNS_NEXT;
                        vci.VcrPrev.IIN = prevsi._VACATION_IIN_NEXT;
                        vci.AdvancePrev = prevsi._VACATION_ADVANCE_NEXT;
                    }
                }
            }

            error_list += GetAvPayCalc(srs);
            if (error_list.HasErrors)
            {
                return(error_list);
            }

            float               caldays   = 0;
            VacationCalcRow     vt        = new VacationCalcRow();
            VacationCalcRow     v         = new VacationCalcRow();
            TimeSheetRowSetList dlrowsetT = null;
            TimeSheetRowSet     dlrowset  = null;
            decimal             r         = 0.0M;

            decimal _AvPayRate = AvPayRateDay;

            if (IsAggregatedTimeRate(srs))
            {
                _AvPayRate = AvPayRateCalendarDay;
            }
            vt.AvPayRate = _AvPayRate;

            caldays = 0;
            foreach (var pi in ps_prev)
            {
                vt.DateStart = pi.DateFirst;
                vt.DateEnd   = pi.DateLast;
                if (vt.DateStart < dt1)
                {
                    vt.DateStart = dt1;
                }
                if (vt.DateEnd > dt2)
                {
                    vt.DateEnd = dt2;
                }

                if (dlrowsetT == null)
                {
                    dlrowsetT = srs.GetDLRowSetList();
                }
                dlrowsetT.CountVacationTime(vt);
                caldays += (vt.DateEnd - vt.DateStart).Days + 1;
                VcrPrevCurrent.CalcAndAdd(srs, vt, _AvPayRate, CalcVer);

                if (PreparingReport)
                {
                    AddRepRow(vt, "A", "Kopā");
                }

                if (vcs != null)
                {
                    v.DateStart = vt.DateStart;
                    v.DateEnd   = vt.DateEnd;

                    int ct = vcs.Where(d => d != null).Count();

                    for (int i = 0; i < vcs.Length; i++)
                    {
                        var vci = vcs[i];
                        if (vci == null)
                        {
                            continue;
                        }
                        var sr = srs.SalarySheetRowSet.LinkedRows[i];
                        dlrowset = dlrowsetT[i];
                        dlrowset.CountVacationTime(v);

                        if (vt.Hours == 0.0f)
                        {
                            r = 1.0M / (decimal)ct;
                        }
                        else
                        {
                            r = (decimal)(v.Hours / vt.Hours);
                        }

                        v.Pay = KlonsData.RoundA(vt.Pay * r, 2);
                        vci.VcrPrevCurrent.CalcAndAddSplit(sr, v, CalcVer);

                        if (PreparingReport)
                        {
                            vci.AddRepRow(vt, "A", sr.GetPositionTitle());
                        }
                    }
                }
            }

            caldays = 0;
            foreach (var pi in ps_cur)
            {
                vt.DateStart = pi.DateFirst;
                vt.DateEnd   = pi.DateLast;
                if (vt.DateStart < dt1)
                {
                    vt.DateStart = dt1;
                }
                if (vt.DateEnd > dt2)
                {
                    vt.DateEnd = dt2;
                }

                if (dlrowsetT == null)
                {
                    dlrowsetT = srs.GetDLRowSetList();
                }
                dlrowsetT.CountVacationTime(vt);
                caldays += (vt.DateEnd - vt.DateStart).Days + 1;
                VcrCurrent.CalcAndAdd(srs, vt, _AvPayRate, CalcVer);

                if (PreparingReport)
                {
                    AddRepRow(vt, "B", "Kopā");
                }

                if (vcs != null)
                {
                    v.DateStart = vt.DateStart;
                    v.DateEnd   = vt.DateEnd;

                    int ct = vcs.Where(d => d != null).Count();

                    for (int i = 0; i < vcs.Length; i++)
                    {
                        var vci = vcs[i];
                        if (vci == null)
                        {
                            continue;
                        }
                        var sr = srs.SalarySheetRowSet.LinkedRows[i];

                        dlrowset = dlrowsetT[i];
                        dlrowset.CountVacationTime(v);

                        if (vt.Hours == 0.0f)
                        {
                            r = 1.0M / (decimal)ct;
                        }
                        else
                        {
                            r = (decimal)(v.Hours / vt.Hours);
                        }

                        v.Pay = KlonsData.RoundA(vt.Pay * r, 2);
                    }

                    Utils.MakeExactSum(vt.Pay, vcs,
                                       d => d.VcrCurrent.Pay,
                                       (d, val) => d.VcrCurrent.Pay = val);

                    for (int i = 0; i < vcs.Length; i++)
                    {
                        var vci = vcs[i];
                        if (vci == null)
                        {
                            continue;
                        }
                        var sr = srs.SalarySheetRowSet.LinkedRows[i];
                        vci.VcrCurrent.CalcAndAddSplit(sr, v, CalcVer);
                        if (PreparingReport)
                        {
                            vci.AddRepRow(vt, "B", sr.GetPositionTitle());
                        }
                    }
                }
            }

            foreach (var pi in ps_next)
            {
                vt.DateStart = dt2.AddDays(1);
                vt.DateEnd   = pi.DateLast;
                if (vt.DateStart < pi.DateFirst)
                {
                    vt.DateStart = pi.DateFirst;
                }
                var dtpe = vt.DateStart.LastDayOfMonth();
                if (vt.DateEnd > dtpe)
                {
                    vt.DateEnd = dtpe;
                }

                while (true)
                {
                    int addmt = Utils.MonthDiff(dt1, vt.DateStart);

                    var nextdlrowsetT = srs.GetDLRowSetList(addmt);
                    if (nextdlrowsetT.Count == 0)
                    {
                        break;
                    }

                    nextdlrowsetT.CountVacationTime(vt);
                    caldays += (vt.DateEnd - vt.DateStart).Days + 1;
                    VcrNext.CalcAndAddNext(srs, vt, _AvPayRate);

                    if (PreparingReport)
                    {
                        AddRepRow(vt, "C", "Kopā");
                    }


                    if (vcs != null)
                    {
                        v.DateStart = vt.DateStart;
                        v.DateEnd   = vt.DateEnd;

                        int ct = vcs.Where(d => d != null).Count();

                        for (int i = 0; i < vcs.Length; i++)
                        {
                            var vci = vcs[i];
                            if (vci == null)
                            {
                                continue;
                            }
                            var sr = srs.SalarySheetRowSet.LinkedRows[i];

                            var nextdlrowset = nextdlrowsetT[i];
                            if (nextdlrowset == null)
                            {
                                //error_list.AddPersonError(srs.DR_Person_r.ID, )
                            }
                            nextdlrowset.CountVacationTime(v);

                            if (vt.Hours == 0.0f)
                            {
                                r = 1.0M / (decimal)ct;
                            }
                            else
                            {
                                r = (decimal)(v.Hours / vt.Hours);
                            }

                            v.Pay = KlonsData.RoundA(vt.Pay * r, 2);
                        }

                        Utils.MakeExactSum(vt.Pay, vcs,
                                           d => d.VcrNext.Pay,
                                           (d, val) => d.VcrNext.Pay = val);

                        for (int i = 0; i < vcs.Length; i++)
                        {
                            var vci = vcs[i];
                            if (vci == null)
                            {
                                continue;
                            }
                            var sr = srs.SalarySheetRowSet.LinkedRows[i];
                            vci.VcrNext.CalcAndAddNextA(sr, v);
                            if (PreparingReport)
                            {
                                vci.AddRepRow(vt, "C", sr.GetPositionTitle());
                            }
                        }
                    }

                    if (vt.DateEnd == pi.DateLast)
                    {
                        break;
                    }
                    vt.DateStart = dtpe.AddDays(1);
                    vt.DateEnd   = pi.DateLast;
                    dtpe         = dtpe.AddDays(1).LastDayOfMonth();
                    if (vt.DateEnd > dtpe)
                    {
                        vt.DateEnd = dtpe;
                    }
                }
            }

            // kompensācija atlaižot
            vt.Days = 0;
            foreach (var fe in fire_evs)
            {
                var dr_ev = fe.Item2 as KlonsADataSet.EVENTSRow;
                if (dr_ev == null)
                {
                    continue;
                }
                if (calcver == KlonsData.VersionRef(0))
                {
                    vt.Days += dr_ev.DAYS;
                }
                else
                {
                    vt.Days += dr_ev.DAYS2;
                }
            }
            if (vt.Days > 0)
            {
                error_list += GetAvPayCalc(srs);
                if (error_list.HasErrors)
                {
                    return(error_list);
                }

                vt.DateStart = srs.SalarySheet.DT1;
                vt.DateEnd   = srs.SalarySheet.DT2;
                caldays      = vt.Days;
                vt.Hours     = 0.0f;

                VcrCompensation.CalcAndAdd(srs, vt, AvPayRateCalendarDay, CalcVer);

                if (PreparingReport)
                {
                    AddRepRow(vt, "D", "Kopā");
                }

                if (vcs != null)
                {
                    v.DateStart = vt.DateStart;
                    v.DateEnd   = vt.DateEnd;
                    v.Days      = vt.Days;
                    v.Hours     = 0.0f;

                    int ct = vcs.Where(d => d != null).Count();

                    for (int i = 0; i < vcs.Length; i++)
                    {
                        var vci = vcs[i];
                        if (vci == null)
                        {
                            continue;
                        }
                        var sr = srs.SalarySheetRowSet.LinkedRows[i];

                        r     = 1.0M / (decimal)ct;
                        v.Pay = KlonsData.RoundA(vt.Pay * r, 2);
                    }

                    Utils.MakeExactSum(vt.Pay, vcs,
                                       d => d.VcrCompensation.Pay,
                                       (d, val) => d.VcrCompensation.Pay = val);

                    for (int i = 0; i < vcs.Length; i++)
                    {
                        var vci = vcs[i];
                        if (vci == null)
                        {
                            continue;
                        }
                        var sr = srs.SalarySheetRowSet.LinkedRows[i];
                        vci.VcrCompensation.CalcAndAddSplit(sr, v, CalcVer);
                        if (PreparingReport)
                        {
                            vci.AddRepRow(vt, "D", sr.GetPositionTitle());
                        }
                    }
                }
            }

            VcrNext.CalcAll(srs, vcs, CalcVer);

            if (PreparingReport)
            {
                PrepareRows();
            }
            return(error_list);
        }