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); }