Example #1
0
        private PeriodInfo FillGaps2(PeriodInfo pi, UntMinData um0)
        {
            var ret = new PeriodInfo();

            ret.DateFirst = pi.DateFirst;
            ret.DateLast  = pi.DateLast;
            if (pi.LinkedPeriods.Count == 0)
            {
                var um1 = um0.Copy();
                um1.Dt1 = pi.DateFirst;
                um1.Dt2 = pi.DateLast;
                var pi2 = new PeriodInfo();
                pi2.DateFirst = pi.DateFirst;
                pi2.DateLast  = pi.DateLast;
                pi2.Item1     = um1;
                pi.LinkedPeriods.Add(pi2);
                return(ret);
            }
            foreach (var pic in pi.LinkedPeriods)
            {
                var pi_prev = ret.LinkedPeriods.LastOrDefault();
                if (pi_prev == null && pic.DateFirst > pi.DateFirst)
                {
                    var um1 = um0.Copy();
                    um1.Dt1 = pi.DateFirst;
                    um1.Dt2 = pic.DateFirst.AddDays(-1);
                    var pi2 = new PeriodInfo();
                    pi2.DateFirst = um1.Dt1;
                    pi2.DateLast  = um1.Dt2;
                    pi2.Item1     = um1;
                    ret.LinkedPeriods.Add(pi2);
                }
                if (pi_prev != null && pic.DateFirst > pi_prev.DateLast.AddDays(1))
                {
                    var um1 = um0.Copy();
                    um1.Dt1 = pi_prev.DateLast.AddDays(1);
                    um1.Dt2 = pic.DateFirst.AddDays(-1);
                    var pi2 = new PeriodInfo();
                    pi2.DateFirst = um1.Dt1;
                    pi2.DateLast  = um1.Dt2;
                    pi2.Item1     = um1;
                    ret.LinkedPeriods.Add(pi2);
                }
                ret.LinkedPeriods.Add(pic);
            }
            var pi_last = ret.LinkedPeriods.LastOrDefault();

            if (pi_last != null && pi_last.DateLast < pi.DateLast)
            {
                var um1 = um0.Copy();
                um1.Dt1 = pi_last.DateLast.AddDays(1);
                um1.Dt2 = pi.DateLast;
                var pi2 = new PeriodInfo();
                pi2.DateFirst = um1.Dt1;
                pi2.DateLast  = um1.Dt2;
                pi2.Item1     = um1;
                ret.LinkedPeriods.Add(pi2);
            }
            return(ret);
        }
Example #2
0
 public PeriodInfo(PeriodInfo pi)
 {
     Item1     = pi.Item1;
     Item2     = pi.Item2;
     DateFirst = pi.DateFirst;
     DateLast  = pi.DateLast;
     PeriodId  = pi.PeriodId;
     EEventId  = pi.EEventId;
 }
Example #3
0
        private PeriodInfo GetUntMinFromDB(KlonsADataSet.PERSONSRow drpr, DateTime dt1, DateTime dt2)
        {
            var um0 = new UntMinData();

            um0.Dt1 = dt1;
            um0.Dt2 = dt2;
            var ret = new PeriodInfo();

            ret.DateFirst = dt1;
            ret.DateLast  = dt2;
            var ret2 = new PeriodInfo();

            ret2.DateFirst = dt1;
            ret2.DateLast  = dt2;
            ret2.Item1     = um0;
            ret.LinkedPeriods.Add(ret2);

            var pi = new PeriodInfo();

            pi.DateFirst = dt1;
            pi.DateLast  = dt2;
            var drs = drpr.GetUNTAXED_MINRows()
                      .OrderBy(d => d.ONDATE)
                      .ToArray();

            if (drs.Length == 0)
            {
                return(ret);
            }
            var rt = pi.ReadDateListFilter(drs, d => d.ONDATE);

            if (rt != PeriodInfo.ERetReadStartEndList.OK ||
                pi.LinkedPeriods.Count == 0)
            {
                return(ret);
            }

            ret.LinkedPeriods.Clear();
            foreach (var pi2 in pi.LinkedPeriods)
            {
                var dr_untmin = (pi2.Item1 as KlonsADataSet.UNTAXED_MINRow);
                var um1       = new UntMinData();
                um1.Dt1         = pi2.DateFirst;
                um1.Dt2         = pi2.DateLast;
                um1.UntMin      = dr_untmin.UNTAXED_MIN;
                um1.IINRateType = dr_untmin.IIN_RATE_TYPE;
                var pi_out = new PeriodInfo();
                pi_out.DateFirst = um1.Dt1;
                pi_out.DateLast  = um1.Dt2;
                pi_out.Item1     = um1;
                ret.LinkedPeriods.Add(pi_out);
            }
            return(ret);
        }
Example #4
0
        private List <UntMinData> GetUntMinChanges(PeriodInfo pi_merged, PeriodInfo pi_db)
        {
            var ret            = new List <UntMinData>();
            var merged_db_copy = pi_merged.LinkedPeriods
                                 .Select(x => x.Item1 as UntMinData)
                                 .Select(x => x.Copy());
            var list_merged_var = new List <UntMinData>(merged_db_copy);

            var add_update = new Action <UntMinData>((UntMinData update) =>
            {
                var fpi_db = pi_db.LinkedPeriods
                             .Where(x => x.DateFirst <= update.Dt1 && x.DateLast >= update.Dt1)
                             .FirstOrDefault()
                             ?.Item1 as UntMinData;
                if (fpi_db == null)
                {
                    return;
                }
                list_merged_var
                .Where(x =>
                       x.Dt1 > update.Dt2 &&
                       x.Dt1 >= fpi_db.Dt1 &&
                       x.Dt2 <= fpi_db.Dt2)
                .ForEach(x =>
                {
                    x.UntMin      = update.UntMin;
                    x.IINRateType = update.IINRateType;
                });
            });

            for (int i = 0; i < pi_merged.LinkedPeriods.Count; i++)
            {
                var pi2      = pi_merged.LinkedPeriods[i];
                var um_dbvar = list_merged_var[i];
                var um_db    = pi2.Item1 as UntMinData;
                var um_egrm  = pi2.Item2 as UntMinData;
                //if (um1.UntMin == um2.UntMin && um1.IINRateType == um2.IINRateType) continue;
                if (um_dbvar.UntMin == um_egrm.UntMin &&
                    um_dbvar.IINRateType == um_egrm.IINRateType)
                {
                    continue;
                }
                var umrt = new UntMinData()
                {
                    Dt1         = um_db.Dt1,
                    Dt2         = um_db.Dt2,
                    UntMin      = um_egrm.UntMin,
                    IINRateType = um_egrm.IINRateType
                };
                ret.Add(umrt);
                add_update(umrt);
            }
            return(ret);
        }
Example #5
0
        public void GetPersonRow(int idp)
        {
            var table_persons = MyData.DataSetKlons.PERSONS;
            var dt1           = SalarySheet.MDT1;
            var dt2           = SalarySheet.MDT2;

            var dr_person     = table_persons.FindByID(idp);
            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);
        }
Example #6
0
        public string GetLikmes()
        {
            var drs_likmes = MyData.DataSetKlons.RATES.OrderBy(d => d.ONDATE).ToArray();

            DR_Likmes = PeriodInfo.FindNearestBefore(drs_likmes,
                                                     MDT1, d => d.ONDATE);

            if (DR_Likmes == null)
            {
                return("Likmes nav definētas.");
            }

            return("OK");
        }
Example #7
0
 public bool ContainsList(PeriodInfo pi)
 {
     if (pi.LinkedPeriods.Count == 0)
     {
         return(true);
     }
     foreach (var p in pi.LinkedPeriods)
     {
         if (!ContainsThis(p))
         {
             return(false);
         }
     }
     return(true);
 }
Example #8
0
 public bool ListContainsThis(PeriodInfo pi)
 {
     if (LinkedPeriods.Count == 0)
     {
         return(false);
     }
     foreach (var p in LinkedPeriods)
     {
         if (p.ContainsThis(pi))
         {
             return(true);
         }
     }
     return(false);
 }
Example #9
0
        private PeriodInfo GetIINRateFromEgrm(nm_e_gramatinasGigv egrm, DateTime dt1, DateTime dt2)
        {
            var um0 = new UntMinData();

            um0.Dt1 = dt1;
            um0.Dt2 = dt2;
            var ret = new PeriodInfo();

            ret.DateFirst = dt1;
            ret.DateLast  = dt2;
            var ret2 = new PeriodInfo();

            ret2.DateFirst = dt1;
            ret2.DateLast  = dt2;
            ret2.Item1     = um0;
            ret.LinkedPeriods.Add(ret2);

            var egrm_iinlikme = egrm?.pazime_progr_iin_likmes?.pazime_progr_iin_likme;

            if (egrm_iinlikme == null)
            {
                return(ret);
            }
            var ret3 = new UntMinData()
            {
                Dt1         = egrm_iinlikme.datums_no,
                Dt2         = egrm_iinlikme.datums_lidzSpecified && egrm_iinlikme.datums_lidz != null ? egrm_iinlikme.datums_lidz.Value : dt2,
                IINRateType = 1
            };

            if (ret3.Dt1 < dt1)
            {
                ret3.Dt1 = dt1;
            }
            if (ret3.Dt2 > dt2)
            {
                ret3.Dt2 = dt2;
            }
            if (ret3.Dt1 > dt2 || ret3.Dt2 < dt1 || ret3.Dt2 < ret3.Dt1)
            {
                return(ret);
            }
            ret2.DateFirst = ret3.Dt1;
            ret2.DateLast  = ret3.Dt2;
            ret2.Item1     = ret3;
            return(ret);
        }
Example #10
0
        public ERetReadStartEndList ReadDateListAll <TItem>(TItem[] items,
                                                            Func <TItem, DateTime> getItemDate)
        {
            LinkedPeriods.Clear();

            if (items.Length == 0)
            {
                return(ERetReadStartEndList.EmptyList);
            }
            DateTime   dt1, dt2;
            PeriodInfo new_per;

            dt1 = DateTime.MinValue;

            for (int i = 0; i < items.Length; i++)
            {
                TItem it1 = items[i];

                dt2 = getItemDate(it1);
                if (dt1 >= dt2)
                {
                    return(ERetReadStartEndList.BadDates);
                }

                new_per = new PeriodInfo()
                {
                    Item1     = it1,
                    DateFirst = dt2
                };
                LinkedPeriods.Add(new_per);

                dt1 = dt2;
            }

            if (LinkedPeriods.Count == 0)
            {
                return(ERetReadStartEndList.BadDates);
            }

            for (int i = 0; i < LinkedPeriods.Count - 1; i++)
            {
                LinkedPeriods[i].DateLast = LinkedPeriods[i + 1].DateFirst.AddDays(-1);
            }

            return(ERetReadStartEndList.OK);
        }
Example #11
0
        public static decimal GetIINUntaxedMinimum2(KlonsADataSet.PERSONSRow drpr,
                                                    DateTime dt1, DateTime dt2)
        {
            var pi = new PeriodInfo();

            pi.DateFirst = dt1;
            pi.DateLast  = dt2;
            var drs = drpr.GetUNTAXED_MINRows()
                      .OrderBy(d => d.ONDATE)
                      .ToArray();

            if (drs.Length == 0)
            {
                return(0.0M);
            }
            var rt = pi.ReadDateListFilter(drs, d => d.ONDATE);

            if (rt != PeriodInfo.ERetReadStartEndList.OK ||
                pi.LinkedPeriods.Count == 0)
            {
                return(0.0M);
            }

            decimal daysinmonth = dt1.DaysInMonth();

            decimal sum    = 0.0M;
            decimal daysct = 0.0M;

            foreach (var pi2 in pi.LinkedPeriods)
            {
                daysct = (decimal)((pi2.DateLast - pi2.DateFirst).TotalDays + 1);
                decimal rate = (pi2.Item1 as KlonsADataSet.UNTAXED_MINRow).UNTAXED_MIN;
                sum += rate * daysct / daysinmonth;
            }
            daysct = (decimal)((dt2 - dt1).TotalDays + 1);
            sum    = sum / daysct * daysinmonth;
            return(sum);
        }
Example #12
0
        //for sequancing some value form Item1
        //func f must return value A if PI1.A != PI2.A, or SkipValue if PI1.A == PI2.A
        public PeriodInfo FilterValueListWithDates(Func <PeriodInfo, PeriodInfo, object> f)
        {
            var retpi = new PeriodInfo(this);

            retpi.DateFirst = DateFirst;
            retpi.DateLast  = DateLast;
            if (LinkedPeriods.Count == 0)
            {
                return(retpi);
            }

            var pi1 = LinkedPeriods[0];
            var npi = new PeriodInfo(pi1);

            retpi.LinkedPeriods.Add(npi);

            if (LinkedPeriods.Count == 1)
            {
                return(retpi);
            }

            for (int i = 1; i < LinkedPeriods.Count; i++)
            {
                var pi2 = LinkedPeriods[i];
                var val = f(pi1, pi2);
                if (object.ReferenceEquals(val, SkipValue))
                {
                    npi.DateLast = pi2.DateLast;
                    continue;
                }
                pi1 = pi2;
                npi = new PeriodInfo(pi1);
                retpi.LinkedPeriods.Add(npi);
            }

            return(retpi);
        }
Example #13
0
        public PeriodInfo FilterThisWithList(PeriodInfo pif)
        {
            var retpi = new PeriodInfo(this);

            foreach (var pf in pif.LinkedPeriods)
            {
                if (DateFirst > pf.DateLast || DateLast < pf.DateFirst)
                {
                    continue;
                }
                var npi = new PeriodInfo(this);
                if (npi.DateFirst < pf.DateFirst)
                {
                    npi.DateFirst = pf.DateFirst;
                }
                if (npi.DateLast > pf.DateLast)
                {
                    npi.DateLast = pf.DateLast;
                }
                retpi.LinkedPeriods.Add(npi);
            }

            return(retpi);
        }
Example #14
0
        public bool GetPersonRow(ErrorList err, int idp, SalarySheetInfo sh)
        {
            var table_persons = MyData.DataSetKlons.PERSONS;

            IDP = idp;
            var dr_person = table_persons.FindByID(idp);

            if (dr_person == null)
            {
                var es = string.Format("{0} ({1}-{2})",
                                       IDP,
                                       sh.CalendarMonth.Year,
                                       sh.CalendarMonth.Month);
                err.AddError(es, "Nav darbinieka");
                return(false);
            }

            var drs_persons_r = dr_person.GetPERSONS_RRows().OrderBy(d => d.EDIT_DATE).ToArray();

            var dt2 = sh.MDT2;

            DR_Person_r = PeriodInfo.FindNearestBefore(drs_persons_r,
                                                       dt2, d => d.EDIT_DATE);

            if (DR_Person_r == null)
            {
                var es = string.Format("{0} {1} ({2}-{3})",
                                       dr_person.FNAME,
                                       dr_person.LNAME,
                                       sh.CalendarMonth.Year,
                                       sh.CalendarMonth.Month);
                err.AddError(es, "Norādītajam periodam nav ievadīti darbinieka dati.");
                return(false);
            }
            return(true);
        }
Example #15
0
        //not filtered
        public ERetReadStartEndList ReadStartEndList <TItem>(TItem[] items,
                                                             Func <TItem, bool> isStartItem, Func <TItem, DateTime> getItemDate)
        {
            if (items.Length == 0)
            {
                return(ERetReadStartEndList.OK);
            }
            int      k = 0;
            DateTime dt1, dt2;

            dt1 = DateTime.MinValue;
            while (k < items.Length)
            {
                TItem      it1 = items[k];
                TItem      it2 = default(TItem);
                PeriodInfo new_per;

                if (!isStartItem(it1))
                {
                    return(ERetReadStartEndList.BadStart);
                }
                dt2 = getItemDate(it1);
                if (dt1 > dt2)
                {
                    return(ERetReadStartEndList.BadDates);
                }
                dt1 = dt2;
                if (k == items.Length - 1)
                {
                    new_per = new PeriodInfo()
                    {
                        Item1     = it1,
                        DateFirst = dt1
                    };
                    LinkedPeriods.Add(new_per);
                    return(ERetReadStartEndList.OK);
                }

                it2 = items[k + 1];
                if (isStartItem(it2))
                {
                    return(ERetReadStartEndList.BadEnd);
                }
                dt2 = getItemDate(it2);
                if (dt1 > dt2)
                {
                    return(ERetReadStartEndList.BadDates);
                }

                new_per = new PeriodInfo()
                {
                    Item1     = it1,
                    Item2     = it2,
                    DateFirst = dt1,
                    DateLast  = dt2
                };
                dt1 = dt2;
                LinkedPeriods.Add(new_per);

                k += 2;
            }
            return(ERetReadStartEndList.OK);
        }
Example #16
0
        private PeriodInfo GetUntMinFromEgrm(nm_e_gramatinasGigv egrm, DateTime dt1, DateTime dt2)
        {
            var um0 = new UntMinData();

            um0.Dt1 = dt1;
            um0.Dt2 = dt2;
            var ret = new PeriodInfo();

            ret.DateFirst = dt1;
            ret.DateLast  = dt2;
            var ret2 = new PeriodInfo();

            ret2.DateFirst = dt1;
            ret2.DateLast  = dt2;
            ret2.Item1     = um0;
            ret.LinkedPeriods.Add(ret2);

            if (egrm.prognozetie_mnm == null || egrm.prognozetie_mnm.Length == 0)
            {
                return(ret);
            }

            var pi = new PeriodInfo();

            pi.DateFirst = dt1;
            pi.DateLast  = dt2;
            var ums1 = egrm.prognozetie_mnm
                       .OrderBy(d => d.datums_no)
                       .Where(d => d.datums_no <= dt2)
                       .Select(d =>
            {
                var rt = new UntMinData()
                {
                    Dt1    = d.datums_no,
                    Dt2    = d.datums_lidzSpecified && d.datums_lidz != null ? d.datums_lidz.Value : dt2,
                    UntMin = (decimal)d.summa
                };
                if (rt.Dt1 < dt1)
                {
                    rt.Dt1 = dt1;
                }
                if (rt.Dt2 > dt2)
                {
                    rt.Dt2 = dt2;
                }
                return(rt);
            })
                       .Where(d => d.Dt2 >= d.Dt1 && d.Dt2 >= dt1)
                       .ToList();

            if (ums1.Count == 0)
            {
                return(ret);
            }

            var ums2 = ums1
                       .Select(d => new PeriodInfo()
            {
                DateFirst = d.Dt1,
                DateLast  = d.Dt2,
                Item1     = d
            })
                       .ToList();

            ret.LinkedPeriods.Clear();
            ret.LinkedPeriods.AddRange(ums2);

            return(ret);
        }
Example #17
0
        // filtered with DateFirst, DateLast
        public ERetReadStartEndList ReadDateListFilter <TItem>(TItem[] items,
                                                               Func <TItem, DateTime> getItemDate)
        {
            LinkedPeriods.Clear();

            if (items.Length == 0)
            {
                return(ERetReadStartEndList.EmptyList);
            }
            DateTime dt1, dt2;

            dt1 = DateTime.MinValue;
            TItem      itd = default(TItem);
            TItem      it0 = itd;
            PeriodInfo new_per;

            for (int i = 0; i < items.Length; i++)
            {
                TItem it1 = items[i];

                dt2 = getItemDate(it1);
                if (dt1 >= dt2)
                {
                    return(ERetReadStartEndList.BadDates);
                }

                if (dt2 <= this.DateFirst)
                {
                    it0 = it1;
                    dt1 = dt2;
                    continue;
                }

                if (dt2 > this.DateFirst && dt1 <= this.DateFirst &&
                    !object.ReferenceEquals(it0, itd))
                {
                    new_per = new PeriodInfo()
                    {
                        Item1     = it0,
                        DateFirst = this.DateFirst
                    };
                    LinkedPeriods.Add(new_per);
                }

                if (dt2 > this.DateLast)
                {
                    break;
                }

                new_per = new PeriodInfo()
                {
                    Item1     = it1,
                    DateFirst = dt2
                };
                LinkedPeriods.Add(new_per);

                dt1 = dt2;
            }


            if (LinkedPeriods.Count == 0)
            {
                if (!object.ReferenceEquals(it0, itd))
                {
                    new_per = new PeriodInfo()
                    {
                        Item1     = it0,
                        DateFirst = this.DateFirst,
                        DateLast  = this.DateLast
                    };
                    LinkedPeriods.Add(new_per);
                }
                else
                {
                    return(ERetReadStartEndList.BadDates);
                }
            }

            for (int i = 0; i < LinkedPeriods.Count - 1; i++)
            {
                LinkedPeriods[i].DateLast = LinkedPeriods[i + 1].DateFirst.AddDays(-1);
            }

            LinkedPeriods[LinkedPeriods.Count - 1].DateLast = this.DateLast;

            return(ERetReadStartEndList.OK);
        }
Example #18
0
        private PeriodInfo MergeUntMinData(PeriodInfo pi_db, PeriodInfo pi_egrm)
        {
            var um0 = new UntMinData();

            um0.Dt1 = pi_db.DateFirst;
            um0.Dt2 = pi_db.DateLast;
            var ret = new PeriodInfo();

            ret.DateFirst = pi_db.DateFirst;
            ret.DateLast  = pi_db.DateLast;
            var ret2 = new PeriodInfo();

            ret2.DateFirst = pi_db.DateFirst;
            ret2.DateLast  = pi_db.DateLast;
            ret2.Item1     = um0;
            ret2.Item2     = um0;
            ret.LinkedPeriods.Add(ret2);

            var dts1 = pi_db.LinkedPeriods.Select(d => d.DateFirst);
            var dts2 = pi_db.LinkedPeriods.Select(d => d.DateLast.AddDays(1));
            var dts3 = pi_egrm.LinkedPeriods.Select(d => d.DateFirst);
            var dts4 = pi_egrm.LinkedPeriods.Select(d => d.DateLast.AddDays(1));
            var dts  = dts1
                       .Union(dts2)
                       .Union(dts3)
                       .Union(dts4)
                       .OrderBy(d => d)
                       .ToList();

            if (dts.Count < 2)
            {
                return(ret);
            }

            ret.LinkedPeriods.Clear();

            for (int i = 0; i <= dts.Count - 2; i++)
            {
                var adt1   = dts[i];
                var adt2   = dts[i + 1].AddDays(-1);
                var pi_out = new PeriodInfo();
                pi_out.DateFirst = adt1;
                pi_out.DateLast  = adt2;
                var fpi_db   = pi_db.FilterListWithDates(adt1, adt2);
                var fpi_egrm = pi_egrm.FilterListWithDates(adt1, adt2);

                var umout1 = new UntMinData();
                umout1.Dt1 = adt1;
                umout1.Dt2 = adt2;
                var umout2 = new UntMinData();
                umout2.Dt1   = adt1;
                umout2.Dt2   = adt2;
                pi_out.Item1 = umout1;
                pi_out.Item2 = umout2;

                if (fpi_db.LinkedPeriods.Count == 1)
                {
                    umout1.UntMin      = (fpi_db.LinkedPeriods[0].Item1 as UntMinData).UntMin;
                    umout1.IINRateType = (fpi_db.LinkedPeriods[0].Item1 as UntMinData).IINRateType;
                }
                if (fpi_egrm.LinkedPeriods.Count == 1)
                {
                    umout2.UntMin      = (fpi_egrm.LinkedPeriods[0].Item1 as UntMinData).UntMin;
                    umout2.IINRateType = (fpi_egrm.LinkedPeriods[0].Item1 as UntMinData).IINRateType;
                }

                ret.LinkedPeriods.Add(pi_out);
            }

            return(ret);
        }
Example #19
0
        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);
        }
Example #20
0
 public bool ContainsThis(PeriodInfo pi)
 {
     return(!(DateFirst > pi.DateLast || DateLast < pi.DateFirst));
 }
Example #21
0
        public ErrorList SetUpT(int idp)
        {
            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_persons = MyData.DataSetKlons.PERSONS;

            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 dr_person = table_persons.FindByID(idp);

            if (dr_person == null)
            {
                error_list.AddError("Algas lapa", "Nav darbinieka");
                return(error_list);
            }

            error_source = string.Format("Darbinieks :{0} {1})",
                                         dr_person.FNAME,
                                         dr_person.LNAME);

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

            if (Events == null)
            {
                if (!GetEventList(error_list, idp))
                {
                    return(error_list);
                }
            }

            if (Row != null)
            {
                TotalPositionPay = new SalaryInfo();
                TotalPositionPay.SetFromRow(Row);
            }

            return(error_list);
        }
Example #22
0
        public void CrossWith(PeriodInfo pic, out PeriodInfo pi1, out PeriodInfo pi2)
        {
            if (LinkedPeriods.Count == 0 || pic.LinkedPeriods.Count == 0 ||
                LinkedPeriods[0].DateFirst != pic.LinkedPeriods[0].DateFirst ||
                LinkedPeriods[LinkedPeriods.Count - 1].DateLast != pic.LinkedPeriods[pic.LinkedPeriods.Count - 1].DateLast)
            {
                throw new ArgumentException("Bad lists.");
            }

            pi1 = new PeriodInfo(this);
            pi2 = new PeriodInfo(pic);
            int        k1 = -1, k2 = -1;
            PeriodInfo kpi1 = null;
            PeriodInfo kpi2 = null;

            kpi1 = pi1.LinkedPeriods[0];
            kpi2 = pi1.LinkedPeriods[0];
            var kdt11 = kpi1.DateFirst;
            var kdt21 = kpi2.DateFirst;

            DateTime   kdt12, kdt22;
            PeriodInfo npi1, npi2;

            bool eo1 = false, eo2 = false;

            if (kdt11 < kdt21)
            {
                while (true)
                {
                    kdt12 = kpi1.DateLast;
                    if (kdt12 < kdt21)
                    {
                        npi1 = new PeriodInfo(kpi1);
                        pi1.LinkedPeriods.Add(npi1);
                        pi2.LinkedPeriods.Add(null);
                        k1++;
                        eo1 = k1 == LinkedPeriods.Count;
                        if (eo1)
                        {
                            break;
                        }
                        kpi1 = LinkedPeriods[k1];
                    }
                    else
                    {
                        npi1          = new PeriodInfo(kpi1);
                        npi1.DateLast = kdt21.AddDays(-1);
                        pi1.LinkedPeriods.Add(npi1);
                        pi2.LinkedPeriods.Add(null);
                        kdt12 = kdt21;
                        break;
                    }
                }
            }
            else if (kdt21 < kdt11)
            {
                while (true)
                {
                    kdt22 = kpi2.DateLast;
                    if (kdt22 < kdt11)
                    {
                        npi2 = new PeriodInfo(kpi2);
                        pi1.LinkedPeriods.Add(null);
                        pi2.LinkedPeriods.Add(npi2);
                        k2++;
                        eo2 = k2 == pic.LinkedPeriods.Count;
                        if (eo2)
                        {
                            break;
                        }
                        kpi2 = pic.LinkedPeriods[k2];
                    }
                    else
                    {
                        npi2          = new PeriodInfo(kpi2);
                        npi2.DateLast = kdt11.AddDays(-1);
                        pi1.LinkedPeriods.Add(null);
                        pi2.LinkedPeriods.Add(npi2);
                        kdt22 = kdt11;
                        break;
                    }
                }
            }

            while (true)
            {
                kdt12 = kpi1.DateLast;
                kdt22 = kpi2.DateLast;

                if (kdt12 < kdt22)
                {
                    npi1 = new PeriodInfo(kpi1)
                    {
                        DateFirst = kdt11,
                        DateLast  = kdt12
                    };
                    npi2 = new PeriodInfo(kpi2)
                    {
                        DateFirst = kdt21,
                        DateLast  = kdt12
                    };
                    pi1.LinkedPeriods.Add(npi1);
                    pi2.LinkedPeriods.Add(npi2);
                    kdt21 = kdt12.AddDays(1);
                    k1++;
                    eo1 = k1 == LinkedPeriods.Count;
                    if (eo1)
                    {
                        break;
                    }
                    kpi1  = LinkedPeriods[k1];
                    kdt11 = kpi1.DateFirst;
                    continue;
                }

                if (kdt12 > kdt22)
                {
                    npi1 = new PeriodInfo(kpi1)
                    {
                        DateFirst = kdt11,
                        DateLast  = kdt22
                    };
                    npi2 = new PeriodInfo(kpi2)
                    {
                        DateFirst = kdt21,
                        DateLast  = kdt22
                    };
                    pi1.LinkedPeriods.Add(npi1);
                    pi2.LinkedPeriods.Add(npi2);
                    kdt11 = kdt22.AddDays(1);
                    k2++;
                    eo2 = k2 == pic.LinkedPeriods.Count;
                    if (eo2)
                    {
                        break;
                    }
                    kpi2  = pic.LinkedPeriods[k2];
                    kdt21 = kpi2.DateFirst;
                    continue;
                }

                if (kdt12 == kdt22)
                {
                    npi1 = new PeriodInfo(kpi1)
                    {
                        DateFirst = kdt11,
                        DateLast  = kdt12
                    };
                    npi2 = new PeriodInfo(kpi2)
                    {
                        DateFirst = kdt21,
                        DateLast  = kdt22
                    };
                    pi1.LinkedPeriods.Add(npi1);
                    pi2.LinkedPeriods.Add(npi2);
                    kdt11 = kdt22.AddDays(1);
                    kdt21 = kdt11;
                    k1++;
                    k2++;
                    eo1 = k1 == LinkedPeriods.Count;
                    eo2 = k2 == pic.LinkedPeriods.Count;
                    if (eo1 || eo2)
                    {
                        break;
                    }
                    kpi1  = LinkedPeriods[k1];
                    kpi2  = pic.LinkedPeriods[k2];
                    kdt11 = kpi1.DateFirst;
                    kdt21 = kpi2.DateFirst;
                    continue;
                }
            }

            if (eo1 && eo2)
            {
                return;
            }

            if (eo1)
            {
                while (true)
                {
                    npi2 = new PeriodInfo(kpi2)
                    {
                        DateFirst = kdt21
                    };
                    pi1.LinkedPeriods.Add(null);
                    pi2.LinkedPeriods.Add(npi2);
                    k2++;
                    eo2 = k2 == pic.LinkedPeriods.Count;
                    if (eo2)
                    {
                        return;
                    }

                    kpi2  = pic.LinkedPeriods[k2];
                    kdt21 = kpi2.DateFirst;
                }
            }

            if (eo2)
            {
                while (true)
                {
                    npi1 = new PeriodInfo(kpi1)
                    {
                        DateFirst = kdt11
                    };
                    pi1.LinkedPeriods.Add(npi1);
                    pi2.LinkedPeriods.Add(null);
                    k1++;
                    eo1 = k1 == LinkedPeriods.Count;
                    if (eo1)
                    {
                        return;
                    }
                    kpi1  = LinkedPeriods[k1];
                    kdt11 = kpi1.DateFirst;
                }
            }
        }
Example #23
0
        public static string GetVacDaysNotUsed(KlonsADataSet.PERSONSRow dr_person, DateTime dt, RepRowVacDays rrvd)
        {
            rrvd.Clear();

            if (dr_person == null)
            {
                throw new ArgumentException();
            }
            int idp = dr_person.ID;

            rrvd.IDP  = idp;
            rrvd.Name = dr_person.ZNAME;

            var drs_events = dr_person.GetEVENTSRows();

            var drsn_hirefire = drs_events
                                .Where(d =>
                                       (d.IDN == (int)EEventId.Pieņemts ||
                                        d.IDN == (int)EEventId.Atlaists) &&
                                       d.DATE1 <= dt)
                                .OrderBy(d => d.DATE1).ToArray();

            if (drsn_hirefire.Length == 0)
            {
                return("OK");
            }

            var pi_hirefire = new PeriodInfo();

            var rt1 = pi_hirefire.ReadStartEndList(drsn_hirefire,
                                                   isStartItem: it => it.IDN == (int)EEventId.Pieņemts,
                                                   getItemDate: it => it.DATE1);

            switch (rt1)
            {
            case PeriodInfo.ERetReadStartEndList.BadDates:
                return("Pieņemts/atlaists notikumiem ir nekorekti datumi.");

            case PeriodInfo.ERetReadStartEndList.BadStart:
            case PeriodInfo.ERetReadStartEndList.BadEnd:
                return("Pieņemts/atlaists notikumiem ir nekorekta secība.");
            }

            var pi_last = pi_hirefire.LinkedPeriods[pi_hirefire.LinkedPeriods.Count - 1];

            if (pi_last.DateLast < dt)
            {
                return("OK");
            }

            if (pi_last.DateLast == dt)
            {
                var dr_last_ev = drsn_hirefire[drsn_hirefire.Length - 1];
                if (dr_last_ev.EventCode == EEventId.Atlaists)
                {
                    rrvd.Compansated = dr_last_ev.DAYS;
                }
            }

            if (pi_hirefire.LinkedPeriods.Count == 1)
            {
                rrvd.ToUse = dr_person.VACATION_DAYS;
            }

            var dt1 = pi_last.DateFirst;
            var dt2 = pi_last.DateLast;

            if (dt2 > dt)
            {
                dt2 = dt;
            }
            int days_in_work = (dt2 - dt1).Days + 1;

            rrvd.ToUse += (float)Math.Round((float)days_in_work * 28f / 365f, 2);

            var drsn_vac = drs_events
                           .Where(d =>
                                  d.IDP == idp &&
                                  d.IDN == 101 &&
                                  d.DATE1 <= pi_last.DateLast &&
                                  d.DATE2 >= pi_last.DateFirst)
                           .OrderBy(d => d.DATE1).ToArray();

            var pi_vac = new PeriodInfo();

            var rt2 = pi_vac.ReadPeriodList(drsn_vac,
                                            getItemDate1: it => it.DATE1,
                                            getItemDate2: it => it.DATE2);

            switch (rt2)
            {
            case PeriodInfo.ERetReadPeriodList.BadDates:
                return("Atvaļinājuma notikumam beigu datums \nir mazāks par sākuma datumu.");

            case PeriodInfo.ERetReadPeriodList.PeriodsOverlap:
                return("Atvaļinājuma notikumai pārklājas");
            }


            foreach (var dr_vac in drsn_vac)
            {
                rrvd.Used += dr_vac.DAYS;
            }
            rrvd.Used = (float)Math.Round(rrvd.Used, 2);

            rrvd.NotUsed = rrvd.ToUse - rrvd.Used - rrvd.Compansated;
            rrvd.NotUsed = (float)Math.Round(rrvd.NotUsed, 2);

            return("OK");
        }
Example #24
0
        public virtual string AnalizeDLEvents(int idp)
        {
            IsOK = false;

            var table_persons = KlonsData.St.DataSetKlons.PERSONS;
            var dr_person     = table_persons.FindByID(idp);

            if (dr_person == null)
            {
                throw new ArgumentException("No person.");
            }

            HireFire  = new PeriodInfo();
            Positions = new Dictionary <int, PeriodInfo>();
            Vacations = new PeriodInfo();
            SickDays  = new PeriodInfo();

            var drs_events = dr_person.GetEVENTSRows();

            //
            // atlaists / pieņemts
            //
            var drsn_hirefire = drs_events.Where(d =>
            {
                return
                (Utils.IN(d.IDN, (int)EEventId.Pieņemts, (int)EEventId.Atlaists));
            }).OrderBy(d => d.DATE1).ToArray();

            if (drsn_hirefire.Length == 0)
            {
                return("OK");
            }

            var pi_hirefire = new PeriodInfo();

            var rt1 = pi_hirefire.ReadStartEndList(drsn_hirefire,
                                                   isStartItem: it => it.IDN == (int)EEventId.Pieņemts,
                                                   getItemDate: it => it.DATE1);

            switch (rt1)
            {
            case PeriodInfo.ERetReadStartEndList.BadDates:
                return("Pieņemts/atlaists notikumiem ir nekorekti datumi.");

            case PeriodInfo.ERetReadStartEndList.BadStart:
            case PeriodInfo.ERetReadStartEndList.BadEnd:
                return("Pieņemts/atlaists notikumiem ir nekorekta secība.");
            }

            //
            // amati
            //
            var drsn_position = drs_events.Where(d =>
            {
                return
                (d.IDP == idp &&
                 Utils.IN(d.IDN, (int)EEventId.Piešķirts_amats, (int)EEventId.Atbrīvots_no_amata));
            }).OrderBy(d => d.DATE1).ToArray();

            var dic_pos    = Utils.BreakListInGroups(drsn_position, d => d.IDA);
            var dic_pos_pi = new Dictionary <int, PeriodInfo>();

            foreach (var kv in dic_pos)
            {
                var pi = new PeriodInfo();
                dic_pos_pi[kv.Key] = pi;
                rt1 = pi.ReadStartEndList(kv.Value.ToArray(),
                                          isStartItem: it => it.IDN == (int)EEventId.Piešķirts_amats,
                                          getItemDate: it => it.DATE1);

                switch (rt1)
                {
                case PeriodInfo.ERetReadStartEndList.BadDates:
                    return("Piešķirts/atņemts amats notikumiem ir nekorekti datumi.");

                case PeriodInfo.ERetReadStartEndList.BadStart:
                case PeriodInfo.ERetReadStartEndList.BadEnd:
                    return("Piešķirts/atņemts amats notikumiem ir nekorekta secība.");
                }

                if (!pi_hirefire.ListContainsList(pi))
                {
                    return("Piešķirts/atņemts amats notikums atlaistam darbiniekam.");
                }
            }

            //
            //  atvaļinājumi
            //
            var drsn_vac = drs_events.Where(d =>
            {
                return(d.IDP == idp &&
                       d.IDN >= 100 &&
                       d.IDN < 200);
            }).OrderBy(d => d.DATE1).ToArray();

            var pi_vac = new PeriodInfo();

            var rt2 = pi_vac.ReadPeriodList(drsn_vac,
                                            getItemDate1: it => it.DATE1,
                                            getItemDate2: it => it.DATE2);

            switch (rt2)
            {
            case PeriodInfo.ERetReadPeriodList.BadDates:
                return("Atvaļinājuma notikumam beigu datums \nir mazāks par sākuma datumu.");

            case PeriodInfo.ERetReadPeriodList.PeriodsOverlap:
                return("Atvaļinājuma notikumai pārklājas");
            }

            foreach (var pi in pi_vac.LinkedPeriods)
            {
                pi.PeriodId = EPeriodId.Atvaļinājums;
                var dr_notikumi_r = pi.Item1 as KlonsADataSet.EVENTSRow;
                pi.EEventId = (EEventId)dr_notikumi_r.IDN;
            }

            //
            //  slimo
            //
            var pi_sick = new PeriodInfo();

            var drsn_sick = drs_events.Where(d =>
            {
                return(d.IDP == idp &&
                       d.IDN >= 200 &&
                       d.IDN < 300);
            }).OrderBy(d => d.DATE1).ToArray();

            rt2 = pi_sick.ReadPeriodList(drsn_sick,
                                         getItemDate1: it => it.DATE1,
                                         getItemDate2: it => it.DATE2);

            switch (rt2)
            {
            case PeriodInfo.ERetReadPeriodList.BadDates:
                return("Slimības notikumam beigu datums \nir mazāks par sākuma datumu.");

            case PeriodInfo.ERetReadPeriodList.PeriodsOverlap:
                return("Slimības notikumai pārklājas");
            }

            foreach (var pi in pi_sick.LinkedPeriods)
            {
                pi.PeriodId = EPeriodId.Slimo;
                var dr_notikumi_r = pi.Item1 as KlonsADataSet.EVENTSRow;
                pi.EEventId = (EEventId)dr_notikumi_r.IDN;
            }

            //
            //  check
            //

            if (!pi_hirefire.ListContainsList(pi_vac))
            {
                return("Atvaļinājuma notikums atlaistam darbiniekam.");
            }

            if (!pi_hirefire.ListContainsList(pi_sick))
            {
                return("Slimības notikums atlaistam darbiniekam.");
            }

            //if (pi_vac.ListContainsList(pi_sick))
            //    return "Slimības notikums pārklājas ar atvaļinājumu.";

            if (pi_hirefire.LinkedPeriods.Count > 0 &&
                dic_pos_pi.Count == 0)
            {
                return("Darbiniekam nav piešķirts amats");
            }

            if (pi_hirefire.LinkedPeriods.Count > 0)
            {
                int  ct    = pi_hirefire.LinkedPeriods.Count;
                var  dt2   = pi_hirefire.LinkedPeriods[ct - 1].DateLast;
                bool posok = false;
                if (dt2 == DateTime.MaxValue)
                {
                    foreach (var pi in dic_pos_pi.Values)
                    {
                        int ct1 = pi.LinkedPeriods.Count;
                        if (ct1 == 0)
                        {
                            continue;
                        }
                        if (pi.LinkedPeriods[ct1 - 1].DateLast == DateTime.MaxValue)
                        {
                            posok = true;
                            break;
                        }
                    }
                    if (!posok)
                    {
                        return("Darbiniekam nav amata.");
                    }
                }
                else
                {
                    foreach (var pi in dic_pos_pi.Values)
                    {
                        int ct1 = pi.LinkedPeriods.Count;
                        if (ct1 == 0)
                        {
                            continue;
                        }
                        var dt3 = pi.LinkedPeriods[ct1 - 1].DateLast;
                        if (dt3 == DateTime.MaxValue)
                        {
                            return("Darbinieks nav atbrīvots no amata.");
                        }
                        if (dt3 == dt2)
                        {
                            posok = true;
                            break;
                        }
                    }
                    if (!posok)
                    {
                        return("Darbiniekam nav amata.");
                    }
                }
            }

            HireFire  = pi_hirefire;
            Positions = dic_pos_pi;
            Vacations = pi_vac;
            SickDays  = pi_sick;

            IsOK = true;
            return("OK");
        }
Example #25
0
 public PeriodInfo FilterWithList(PeriodInfo pif)
 {
     return(FilterWithList(pif.LinkedPeriods));
 }
Example #26
0
 public DatesFromTo(PeriodInfo pi)
 {
     DateFrom = pi.DateFirst;
     DateTo   = pi.DateLast;
 }