Ejemplo n.º 1
0
        public static void GetIINDeductionsForPerson(CalcRRow2 wt, KlonsADataSet.PERSONS_RRow drpr,
                                                     KlonsADataSet.RATESRow drl, DateTime dt1, DateTime dt2, int calcver)
        {
            wt.ExUntaxedMinimum    = 0.0M;
            wt.ExDependants        = 0.0M;
            wt.ExInvalidity        = 0.0M;
            wt.ExRetaliation       = 0.0M;
            wt.ExNationalMovements = 0.0M;

            if (!string.IsNullOrEmpty(drpr.TAXDOC_NO))
            {
                wt.ExDependants = drl.APGAD * (decimal)drpr.APGAD_SK;

                if (drpr.INVALID == 1 || drpr.INVALID == 2)
                {
                    wt.ExInvalidity = drl.INVALID_12;
                }
                else if (drpr.INVALID == 3)
                {
                    wt.ExInvalidity = drl.INVALID_3;
                }

                if (drpr.PRET == 1)
                {
                    wt.ExNationalMovements = drl.PRET;
                }

                if (drpr.REPRES == 1)
                {
                    wt.ExRetaliation = drl.REPR;
                }

                if (drpr.PENSIONER == 1 || drpr.PENSIONER_SP == 1)
                {
                    wt.ExUntaxedMinimum = 0.0M;
                }
                else
                {
                    if (dt1 < ProgressiveIINStartDate)
                    {
                        wt.ExUntaxedMinimum = drl.NEPLIEK_MIN;
                    }
                    else
                    {
                        if (calcver == KlonsData.VersionRef(0))
                        {
                            wt.ExUntaxedMinimum = GetIINUntaxedMinimum(drpr.PERSONSRow, dt1);
                        }
                        else
                        {
                            wt.ExUntaxedMinimum = GetIINUntaxedMinimum2(drpr.PERSONSRow, dt1, dt2);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void CalcIIN()
        {
            decimal pay1 =
                SI._AMOUNT_BEFORE_SN -
                SI._PLUS_NOSAI +
                SI._PLUS_AUTHORS_FEES;

            decimal payAfterSAI =
                SI._AMOUNT_BEFORE_SN -
                SI._DNSN_AMOUNT +
                SI._PLUS_NOSAI +
                SI._PLUS_AUTHORS_FEES -
                SI._MINUS_BEFORE_IIN;

            decimal iinexempts = SI.SumIINExemptsAll();

            if (!CalcR.UseProgresiveIINRate)
            {
                iinexempts            = Math.Min(iinexempts, payAfterSAI);
                SI._AMOUNT_BEFORE_IIN = payAfterSAI - iinexempts;
                SI._IIN_AMOUNT        = KlonsData.RoundA(SI._AMOUNT_BEFORE_IIN * SI._RATE_IIN / 100.0M, 2);
            }
            else if (CalcR.HasTaxDoc)
            {
                if (pay1 <= CalcR.IINMargin)
                {
                    iinexempts            = Math.Min(iinexempts, payAfterSAI);
                    SI._AMOUNT_BEFORE_IIN = payAfterSAI - iinexempts;
                    SI._IIN_AMOUNT        = KlonsData.RoundA(SI._AMOUNT_BEFORE_IIN * SI._RATE_IIN / 100.0M, 2);
                }
                else
                {
                    decimal amountbeforeiin =
                        CalcR.IINMargin -
                        SI._DNSN_AMOUNT -
                        SI._MINUS_BEFORE_IIN -
                        iinexempts;

                    decimal iin = amountbeforeiin * SI._RATE_IIN / 100.0M;

                    decimal amountbeforeiin2 =
                        pay1 -
                        CalcR.IINMargin;

                    iin += amountbeforeiin2 * SI._RATE_IIN2 / 100.0M;

                    if (iin < 0.0M)
                    {
                        iinexempts += KlonsData.RoundA(iin / (SI._RATE_IIN / 100.0M), 2);
                        iin         = 0.0M;
                    }

                    SI._IIN_AMOUNT = KlonsData.RoundA(iin, 2);
                }
            }
            else
            {
                if (SI._CALC_VER < KlonsData.VersionRef(2))
                {
                    iinexempts            = 0.0M;
                    SI._AMOUNT_BEFORE_IIN = payAfterSAI - iinexempts;
                    decimal iin =
                        (SI._AMOUNT_BEFORE_IIN + SI._DNSN_AMOUNT) * SI._RATE_IIN2 / 100.0M -
                        SI._DNSN_AMOUNT * SI._RATE_IIN / 100.0M;
                    SI._IIN_AMOUNT = KlonsData.RoundA(iin, 2);
                }
                else
                {
                    SI._AMOUNT_BEFORE_IIN = payAfterSAI - iinexempts;
                    decimal iin =
                        (SI._AMOUNT_BEFORE_IIN + SI._DNSN_AMOUNT) * SI._RATE_IIN2 / 100.0M -
                        SI._DNSN_AMOUNT * SI._RATE_IIN / 100.0M;
                    if (iin < 0.0M)
                    {
                        iin        = 0.0M;
                        iinexempts = payAfterSAI + SI._DNSN_AMOUNT - SI._DNSN_AMOUNT * SI._RATE_IIN / SI._RATE_IIN2;
                        iinexempts = KlonsData.RoundA(iinexempts, 2);
                    }
                    SI._IIN_AMOUNT = KlonsData.RoundA(iin, 2);
                }
            }

            SI._AMOUNT_BEFORE_IIN = payAfterSAI - iinexempts;

            CalcR.ExDivided.ApplyTo0(SI);
            CalcR.CorrectIINExempts(iinexempts);
            CalcR.ExCorrect.ApplyTo(SI);
            CalcR.SaveStateForFinal(CalcR.ExCorrect);
            CalcR.AddToListT();
            CalcR.PrepareList();
        }
Ejemplo n.º 3
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);
        }