Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
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");
        }