public static TimeSheetRowSet GetDLRowSet(KlonsADataSet.TIMESHEETRow[] rows) { var rowset = new TimeSheetRowSet(); foreach (var dr in rows) { switch (dr.XKind1) { case EKind1.PlanIndividualDay: rowset.Plan = dr; break; case EKind1.PlanIndividualNight: rowset.PlanNight = dr; break; case EKind1.Fact: rowset.Fact = dr; break; case EKind1.FactNight: rowset.FactNight = dr; break; case EKind1.FactOvertime: rowset.FactOvertime = dr; break; } } return(rowset); }
public void SetDLRows(TimeSheetRowSet dlrowset) { DLRows = dlrowset; }
public ErrorList SetUp(int idp, int idam) { if (SalarySheet == null) { throw new Exception("Bad init."); } var table_sar = MyData.DataSetKlons.SALARY_SHEETS; var table_sar_r = MyData.DataSetKlons.SALARY_SHEETS_R; var table_darba_laiks = MyData.DataSetKlons.TIMESHEET; var table_sh = MyData.DataSetKlons.SALARY_SHEET_TEMPL; var table_sh_r = MyData.DataSetKlons.SALARY_SHEET_TEMPL_R; var table_persons = MyData.DataSetKlons.PERSONS; var table_amati = MyData.DataSetKlons.POSITIONS; var table_dl_sar_r = MyData.DataSetKlons.TIMESHEET_LISTS_R; var error_list = new ErrorList(); string error_source; int yr = SalarySheet.YR; int mt = SalarySheet.MT; var dt1 = SalarySheet.MDT1; var dt2 = SalarySheet.MDT2; //var dv_dl_sar_r = new DataView(table_dl_sar_r); //dv_dl_sar_r.RowFilter = string.Format("Parent(FK_TIMESHEET_LISTS_R_IDS).YR = {0} AND Parent(FK_TIMESHEET_LISTS_R_IDS).MT = {1}", yr, mt); var dr_person = table_persons.FindByID(idp); var dr_amats = table_amati.FindByID(idam); if (dr_person == null) { error_list.AddError("Algas lapa", "Nav darbinieka"); return(error_list); } if (dr_amats == null) { error_list.AddError("Algas lapa", "Nav amata"); return(error_list); } if (DR_salary_sheet_r_templ == null) { error_source = string.Format("Darbinieks :{0} {1} ({2})", dr_person.FNAME, dr_person.LNAME, dr_amats.TITLE); } else { error_source = string.Format("Lapa:{0} rinda:{1}", DR_salary_sheet_r_templ.SALARY_SHEET_TEMPLRow.SNR, DR_salary_sheet_r_templ.SNR); } var drs_persons_r = dr_person.GetPERSONS_RRows().OrderBy(d => d.EDIT_DATE).ToArray(); DR_Person_r = PeriodInfo.FindNearestBefore(drs_persons_r, dt2, d => d.EDIT_DATE); if (DR_Person_r == null) { error_list.AddError(error_source, "Norādītajam periodam nav ievadīti darbinieka dati."); return(error_list); } PersonR.DateFirst = dt1; PersonR.DateLast = dt2; var drs_person_r = dr_person.GetPERSONS_RRows().OrderBy(d => d.EDIT_DATE).ToArray(); //var rete = PersonR.ReadDateListFilter(drs_person_r, d => d.EDIT_DATE); var rete = PersonR.ReadDateListAll(drs_person_r, d => d.EDIT_DATE); if (rete != PeriodInfo.ERetReadStartEndList.OK || PersonR.LinkedPeriods[0].DateFirst > dt2) { error_list.AddError(error_source, "Norādītajam periodam nav ievadīti darbinieka dati."); return(error_list); } PositionsR.DateFirst = dt1; PositionsR.DateLast = dt2; var drs_amats_r = dr_amats.GetPOSITIONS_RRows().OrderBy(d => d.EDIT_DATE).ToArray(); rete = PositionsR.ReadDateListFilter(drs_amats_r, d => d.EDIT_DATE); if (rete != PeriodInfo.ERetReadStartEndList.OK) { error_list.AddError(error_source, "Norādītajam periodam nav ievadīti amata dati."); return(error_list); } var drs_dl_sar_r = dr_person.GetTIMESHEET_LISTS_RRows() .WhereX( d => d.TIMESHEET_LISTSRow.YR == yr && d.TIMESHEET_LISTSRow.MT == mt && d.IDAM == dr_amats.ID) .ToArray(); if (drs_dl_sar_r.Length == 0) { error_list.AddError(error_source, "Norādītajam periodam nav darba laika uzskaites datu."); return(error_list); } if (drs_dl_sar_r.Length > 1) { error_list.AddError(error_source, "Darba laika uzskaites datu rindu skaits > 1."); return(error_list); } var dr_dl_sar_r = drs_dl_sar_r[0]; var dlrowset = dr_dl_sar_r.GetDLRowSet(); DLRows = dlrowset; SetDLRows(dlrowset); if (DLRows == null || DLRows.Plan == null || DLRows.Fact == null || (dr_dl_sar_r.NIGHT == 1 && (DLRows.PlanNight == null || DLRows.FactNight == null)) || (dr_dl_sar_r.OVERTIME == 1 && DLRows.FactOvertime == null)) { error_list.AddError(error_source, "Nekorekti darba laika uzskaites dati."); return(error_list); } if (Events == null) { if (!GetEventList(error_list, idp)) { return(error_list); } } if (IsRateTypeChangedDuringVacation(drs_amats_r)) { error_list.AddError(error_source, "Atvaļinājuma laikā nevar mainīt algas likmes veidu."); } var err1 = CheckVacationTimePlan(idam); if (err1 != "OK") { error_list.AddError(error_source, err1); return(error_list); } if (Row != null) { TotalPositionPay = new SalaryInfo(); TotalPositionPay.SetFromRow(Row); } return(error_list); }
public static TimeSheetRowSet GetDLRowSet(this KlonsADataSet.TIMESHEET_LISTS_RRow row) { var rowset = new TimeSheetRowSet(); var drs = row.GetTIMESHEETRows(); foreach (var dr in drs) { switch (dr.XKind1) { case EKind1.PlanIndividualDay: rowset.Plan = dr; break; case EKind1.PlanIndividualNight: rowset.PlanNight = dr; break; case EKind1.Fact: rowset.Fact = dr; break; case EKind1.FactNight: rowset.FactNight = dr; break; case EKind1.FactOvertime: rowset.FactOvertime = dr; break; } } if (row.XPlanType == EPlanType.Fixed && !row.IsIDPLNull()) { var table_darba_laiks = (row.Table.DataSet as KlonsADataSet).TIMESHEET; int yr = row.TIMESHEET_LISTSRow.YR; int mt = row.TIMESHEET_LISTSRow.MT; var drs_plan = table_darba_laiks.WhereX( d => !d.IsIDPNull() && d.IDP == row.IDPL && d.YR == yr && d.MT == mt && (d.XKind1 == EKind1.PlanGroupDay || d.XKind1 == EKind1.PlanGroupaNight) ); foreach (var dr in drs_plan) { switch (dr.XKind1) { case EKind1.PlanGroupDay: rowset.Plan = dr; break; case EKind1.PlanGroupaNight: rowset.PlanNight = dr; break; } } } return(rowset); }
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); }