Ejemplo n.º 1
0
        // nolietojums konkrētam mēnesiem tiek rēķināts pirmajam mēneša notikumam
        // -- pirms šajā mēnesī tiek mainīta PL vērtība
        // => nolietojumu rēķina sākot ar nākamā mēneša pirmo datumu
        public string FullCalc()
        {
            if (Events.Count == 0)
            {
                return("OK");
            }

            int     lastMt = 0, curMt = 0;
            int     lastTaxDeprecYr = 0, curTaxDeprecYr = 0;
            decimal deprecMt, deprecPeriod;

            EEvent curState  = EEvent.nenoteikts;
            EEvent nextState = EEvent.nenoteikts;
            EEvent curEvent  = EEvent.nenoteikts;

            EventInfo curEventInfo  = Events[0];
            EventInfo curEventInfo2 = null;

            DateReg   = curEventInfo.Dt;
            DateStart = curEventInfo.Dt.FirstDayOfMonth();
            DateEnd   = DateTime.MaxValue;

            if (Events.Count > 1 && Events[Events.Count - 1].XEvent == EEvent.likvid)
            {
                DateLiq = Events[Events.Count - 1].Dt;
                DateEnd = DateLiq.LastDayOfMonth();
            }

            FirstYear  = DateStart.Year;
            FirstMonth = DateStart.Month;

            int i1 = 0, i2 = 0, k;

            for (i2 = 0; i2 < Events2.Count; i2++)
            {
                k = DateDiffInMonths(curEventInfo.Dt, Events2[i2].Dt);
                if (k >= 0)
                {
                    break;
                }
                Events2[i2].State = EState.OldDate;
            }

            InUse = false;
            State = EState.OK;

            while (i1 < Events.Count || i2 < Events2.Count)
            {
                if (i1 < Events.Count)
                {
                    if (i2 >= Events2.Count)
                    {
                        curEventInfo = Events[i1];
                        i1++;
                    }
                    else
                    {
                        curEventInfo  = Events[i1];
                        curEventInfo2 = Events2[i2];
                        if (curEventInfo2.LastInDay)
                        {
                            if (curEventInfo2.Dt < curEventInfo.Dt)
                            {
                                curEventInfo = curEventInfo2;
                                i2++;
                            }
                            else
                            {
                                i1++;
                            }
                        }
                        else
                        {
                            if (curEventInfo2.Dt <= curEventInfo.Dt)
                            {
                                curEventInfo = curEventInfo2;
                                i2++;
                            }
                            else
                            {
                                i1++;
                            }
                        }
                    }
                }
                else
                {
                    curEventInfo = Events2[i2];
                    i2++;
                }



                curEvent       = curEventInfo.XEvent;
                nextState      = curEvent;
                curMt          = DateDiffInMonths(DateStart, curEventInfo.Dt);
                curTaxDeprecYr = curEventInfo.Dt.Year;

                if (lastTaxDeprecYr == 0)
                {
                    lastTaxDeprecYr = curTaxDeprecYr;
                    if (curEventInfo.XEvent == EEvent.pienuzsk && curEventInfo.Dt.IsLastOfYear())
                    {
                        lastTaxDeprecYr++;
                    }
                }

                if ((curEventInfo.XEvent == EEvent.apr || curEventInfo.XEvent == EEvent.noliet) &&
                    curEventInfo.LastInDay &&
                    curEventInfo.Dt.IsLastOfYear())
                {
                    curTaxDeprecYr++;
                }

                Value0      = Value1;
                Deprec0     = Deprec1;
                ValueLeft0  = ValueLeft1;
                TaxValLeft0 = TaxValLeft1;

                // finanšu nolietojums
                if (curMt > lastMt)
                {
                    if (InUse)
                    {
                        deprecMt = RateDMt;
                    }
                    else
                    {
                        deprecMt = 0.0M;
                    }

                    if (deprecMt > 0.0M)
                    {
                        MtUsed += curMt - lastMt;
                    }

                    deprecPeriod = (curMt - lastMt) * deprecMt;
                    if (deprecPeriod > (Value0 - Deprec0))
                    {
                        deprecPeriod = Value0 - Deprec0;
                    }

                    DeprecCalcThisMt = deprecPeriod;

                    Deprec1    += deprecPeriod;
                    ValueLeft1 -= deprecPeriod;
                    DeprecCalc += deprecPeriod;

                    Deprec0    = Deprec1;
                    ValueLeft0 = ValueLeft1;

                    lastMt = curMt;
                }
                else
                {
                    DeprecCalcThisMt = 0;
                }


                // nolietojums nodokļiem
                if (curTaxDeprecYr > lastTaxDeprecYr && TaxRate != 0.0f)
                {
                    var r         = (decimal)Math.Pow((1.0f - TaxRate), curTaxDeprecYr - lastTaxDeprecYr);
                    var taxDeprec = TaxValLeft1 * (1.0M - r);
                    taxDeprec       = Math.Round(taxDeprec, 2);
                    TaxDeprecCalc  += taxDeprec;
                    TaxDeprec      += taxDeprec;
                    TaxValLeft1    -= taxDeprec;
                    lastTaxDeprecYr = curTaxDeprecYr;

                    if (TaxEach == 1 && TaxValLeft1 <= 71.14M)
                    {
                        TaxDeprecCalc += TaxValLeft1;
                        TaxDeprec     += TaxValLeft1;
                        TaxValLeft1    = 0.0M;
                    }
                }


                if (curEventInfo.XEvent == EEvent.noliet ||
                    curEventInfo.XEvent == EEvent.apr)
                {
                    curEventInfo.State      = State;
                    curEventInfo.Cat1       = Cat1;
                    curEventInfo.CatD       = CatD;
                    curEventInfo.CatT       = CatT;
                    curEventInfo.Place      = Place;
                    curEventInfo.Department = Department;

                    curEventInfo.Value0           = Value0;
                    curEventInfo.Value1           = Value1;
                    curEventInfo.Deprec0          = Deprec0;
                    curEventInfo.Deprec1          = Deprec1;
                    curEventInfo.ValueLeft0       = Value0 - Deprec0;
                    curEventInfo.ValueLeft1       = Value1 - Deprec1;
                    curEventInfo.SellValue        = SellValue;
                    curEventInfo.RateD            = RateD;
                    curEventInfo.RateDMt          = RateDMt;
                    curEventInfo.DeprecCalc       = DeprecCalc;
                    curEventInfo.ValueLeft0       = Value0 - Deprec0;
                    curEventInfo.DeprecCalcThisMt = DeprecCalcThisMt;
                    curEventInfo.MtTotal          = MtTotal;
                    curEventInfo.MtUsed           = MtUsed;

                    curEventInfo.TaxVal          = TaxVal;
                    curEventInfo.TaxValLeft0     = TaxValLeft0;
                    curEventInfo.TaxValLeft1     = TaxValLeft1;
                    curEventInfo.TaxDeprec       = TaxDeprec;
                    curEventInfo.TaxDeprecCalc   = TaxDeprecCalc;
                    curEventInfo.TaxRate         = TaxRate;
                    curEventInfo.TaxEach         = TaxEach;
                    curEventInfo.TaxValLeftAtEnd = TaxValLeftAtEnd;

                    if (curEventInfo.XEvent == EEvent.apr)
                    {
                        curEventInfo.ValueNew            = ValueNew;
                        curEventInfo.DeprecNew           = DeprecNew;
                        curEventInfo.ValueAdd            = ValueAdd;
                        curEventInfo.DeprecAdd           = DeprecAdd;
                        curEventInfo.ValueRevalue        = ValueRevalue;
                        curEventInfo.DeprecRevalue       = DeprecRevalue;
                        curEventInfo.ValueRecat          = ValueRecat;
                        curEventInfo.DeprecRecat         = DeprecRecat;
                        curEventInfo.ValueExclude        = ValueExclude;
                        curEventInfo.DeprecExclude       = DeprecExclude;
                        curEventInfo.TaxValNewCalc       = TaxValNewCalc;
                        curEventInfo.TaxValAddCalc       = TaxValAddCalc;
                        curEventInfo.TaxValRecatCalc     = TaxValRecatCalc;
                        curEventInfo.TaxValExcludeCalc   = TaxValExcludeCalc;
                        curEventInfo.TaxValLeftAtEndCalc = TaxValLeftAtEndCalc;

                        ValueNew     = 0.0M;
                        ValueAdd     = 0.0M;
                        ValueRevalue = 0.0M;
                        ValueRecat   = 0.0M;
                        ValueExclude = 0.0M;

                        DeprecNew     = 0.0M;
                        DeprecAdd     = 0.0M;
                        DeprecRevalue = 0.0M;
                        DeprecRecat   = 0.0M;
                        DeprecExclude = 0.0M;

                        DeprecCalc          = 0.0M;
                        TaxValNewCalc       = 0.0M;
                        TaxValAddCalc       = 0.0M;
                        TaxValRecatCalc     = 0.0M;
                        TaxValExcludeCalc   = 0.0M;
                        TaxDeprecCalc       = 0.0M;
                        TaxValLeftAtEndCalc = 0.0M;
                    }
                }
                else
                {
                    // izmētājam ValueC, DeprecC
                    if (curEventInfo.XEvent.IsIn(EEvent.ieg, EEvent.eks, EEvent.izv, EEvent.iegeks,
                                                 EEvent.kapit))
                    {
                        curEventInfo.TaxValC = curEventInfo.ValueC - curEventInfo.DeprecC;
                    }
                    else if (curEventInfo.XEvent == EEvent.likvid)
                    {
                        curEventInfo.TaxValC = curEventInfo.ValueC - curEventInfo.DeprecC;
                    }
                    else if (curEventInfo.XEvent != EEvent.pienuzsk)
                    {
                        curEventInfo.TaxValC = 0.0M;
                    }

                    if (curEventInfo.XEvent.IsIn(EEvent.ieg, EEvent.eks, EEvent.izv, EEvent.iegeks))
                    {
                        curEventInfo.ValueNew  = curEventInfo.ValueC;
                        curEventInfo.DeprecNew = curEventInfo.DeprecC;
                        ValueNew      += curEventInfo.ValueC;
                        DeprecNew     += curEventInfo.DeprecC;
                        StartingValue += curEventInfo.ValueC - curEventInfo.DeprecC;
                        curEventInfo.TaxValNewCalc = curEventInfo.TaxValC;
                        TaxValNewCalc += curEventInfo.TaxValC;
                    }
                    else if (curEventInfo.XEvent == EEvent.kapit)
                    {
                        curEventInfo.ValueAdd  = curEventInfo.ValueC;
                        curEventInfo.DeprecAdd = curEventInfo.DeprecC;
                        ValueAdd  += curEventInfo.ValueC;
                        DeprecAdd += curEventInfo.DeprecC;
                        curEventInfo.TaxValAddCalc = curEventInfo.TaxValC;
                        TaxValAddCalc += curEventInfo.TaxValC;
                    }
                    else if (curEventInfo.XEvent == EEvent.parvert)
                    {
                        curEventInfo.ValueRevalue  = curEventInfo.ValueC;
                        curEventInfo.DeprecRevalue = curEventInfo.DeprecC;
                        ValueRevalue  += curEventInfo.ValueC;
                        DeprecRevalue += curEventInfo.DeprecC;
                    }
                    else if (curEventInfo.XEvent == EEvent.likvid)
                    {
                        curEventInfo.ValueExclude  = curEventInfo.ValueC;
                        curEventInfo.DeprecExclude = curEventInfo.DeprecC;
                        ValueExclude  += curEventInfo.ValueC;
                        DeprecExclude += curEventInfo.DeprecC;
                        curEventInfo.TaxValExcludeCalc = -curEventInfo.TaxValC;
                        TaxValExcludeCalc -= curEventInfo.TaxValC;
                    }

                    Value1      += curEventInfo.ValueC;
                    Deprec1     += curEventInfo.DeprecC;
                    TaxVal      += curEventInfo.TaxValC;
                    TaxValLeft1 += curEventInfo.TaxValC;

                    // nolietojums nodokļiem
                    if (curEventInfo.XEvent == EEvent.likvid)
                    {
                        //TaxValLeft1 ir jau koriģēts ar TaxValC
                        TaxValLeftAtEnd     = TaxValLeft1;
                        TaxValLeftAtEndCalc = TaxValLeft1;
                        if (TaxEach == 1)
                        {
                            TaxDeprecCalc  += TaxValLeft1;
                            TaxDeprec      += TaxValLeft1;
                            TaxValLeft1     = 0.0M;
                            lastTaxDeprecYr = curTaxDeprecYr + 1;
                        }
                    }

                    // ItemInfo => EventInfo
                    if (curEventInfo.XEvent != EEvent.pienuzsk || curEventInfo.InitFields)
                    {
                        curEventInfo.Value0      = Value0;
                        curEventInfo.Deprec0     = Deprec0;
                        curEventInfo.Value1      = Value1;
                        curEventInfo.Deprec1     = Deprec1;
                        curEventInfo.TaxVal      = TaxVal;
                        curEventInfo.TaxValLeft0 = TaxValLeft0;
                        curEventInfo.TaxValLeft1 = TaxValLeft1;
                    }

                    curEventInfo.DeprecCalc       = DeprecCalc;
                    curEventInfo.ValueLeft0       = Value0 - Deprec0;
                    curEventInfo.ValueLeft1       = Value1 - Deprec1;
                    curEventInfo.DeprecCalcThisMt = DeprecCalcThisMt;
                    curEventInfo.MtUsed           = MtUsed;
                    curEventInfo.TaxDeprec        = TaxVal - TaxValLeft1;
                    curEventInfo.TaxDeprecCalc    = TaxDeprecCalc;

                    if (Events.Count > 0 && Events[0] != curEventInfo)
                    {
                        curEventInfo.State = State;

                        if (curEventInfo.InitFields)
                        {
                            curEventInfo.Cat1       = Cat1;
                            curEventInfo.CatD       = CatD;
                            curEventInfo.CatT       = CatT;
                            curEventInfo.Place      = Place;
                            curEventInfo.Department = Department;
                            curEventInfo.SellValue  = SellValue;
                            curEventInfo.MtTotal    = MtTotal;
                        }
                        else
                        {
                            var editablefields = SomeDataDefs.GetEditableFields(curEventInfo.XEvent);
                            if (!editablefields.HasFlag(EChColInd.cat1))
                            {
                                curEventInfo.Cat1 = Cat1;
                            }
                            if (!editablefields.HasFlag(EChColInd.cat1))
                            {
                                curEventInfo.Cat1 = Cat1;
                            }
                            if (!editablefields.HasFlag(EChColInd.catd))
                            {
                                curEventInfo.CatD = CatD;
                            }
                            if (!editablefields.HasFlag(EChColInd.catt))
                            {
                                curEventInfo.CatT = CatT;
                            }
                            if (!editablefields.HasFlag(EChColInd.place))
                            {
                                curEventInfo.Place = Place;
                            }
                            if (!editablefields.HasFlag(EChColInd.department))
                            {
                                curEventInfo.Department = Department;
                            }
                            if (!editablefields.HasFlag(EChColInd.sellvalue))
                            {
                                curEventInfo.SellValue = SellValue;
                            }
                            if (!editablefields.HasFlag(EChColInd.mttotal))
                            {
                                curEventInfo.MtTotal = MtTotal;
                            }
                        }
                    }

                    curEventInfo.RecalcA();

                    // EventInfo => ItemInfo
                    Cat1       = curEventInfo.Cat1;
                    CatD       = curEventInfo.CatD;
                    CatT       = curEventInfo.CatT;
                    Place      = curEventInfo.Place;
                    Department = curEventInfo.Department;

                    ValueLeft0 = Value0 - Deprec0;
                    ValueLeft1 = Value1 - Deprec1;
                    SellValue  = curEventInfo.SellValue;

                    MtTotal = curEventInfo.MtTotal;

                    RateD   = curEventInfo.RateD;
                    TaxRate = curEventInfo.TaxRate;
                    RateDMt = curEventInfo.RateDMt;

                    TaxEach = curEventInfo.TaxEach;

                    curState = curEventInfo.XEvent;



                    if (curState.IsIn(EEvent.ieg, EEvent.izv))
                    {
                        InUse = false;
                        State = EState.NotUsed;
                    }
                    else if (curState.IsIn(EEvent.eks, EEvent.iegeks))
                    {
                        InUse = true;
                        State = EState.OK;
                    }
                    else if (curState == EEvent.rekat)
                    {
                    }
                    else if (curState == EEvent.kapit)
                    {
                    }
                    else if (curState == EEvent.parvert)
                    {
                    }
                    else if (curState == EEvent.nelieto)
                    {
                        InUse = false;
                        State = EState.NotUsed;
                    }
                    else if (curState == EEvent.lieto)
                    {
                        InUse = true;
                        State = EState.OK;
                    }
                    else if (curState == EEvent.likvid)
                    {
                        InUse       = false;
                        DateLiq     = curEventInfo.Dt;
                        State       = EState.Liquidated;
                        EndingValue = Value0 - Deprec0;
                    }
                }
            }
            return("OK");
        }
Ejemplo n.º 2
0
        public string CheckItem()
        {
            if (Events.Count == 0)
            {
                return("OK");
            }

            decimal value  = 0.0M;
            decimal deprec = 0.0M;
            decimal TaxVal = 0.0M;

            DateTime dateStart = Events[0].Dt.FirstDayOfMonth();
            DateTime dateEnd   = Events[Events.Count - 1].Dt.LastDayOfMonth();

            EEvent curState  = EEvent.nenoteikts;
            EEvent nextState = EEvent.nenoteikts;
            EEvent curEvent  = EEvent.nenoteikts;

            for (int i = 0; i < Events.Count; i++)
            {
                var curEventInfo = Events[i];
                curEvent  = curEventInfo.XEvent;
                nextState = curEvent;

                value  += curEventInfo.ValueC;
                deprec += curEventInfo.DeprecC;
                TaxVal += curEventInfo.TaxVal;

                var evstr       = curState.ToMyString();
                var badeverrstr = "Nekorekts notikums [" + evstr + "]";

                if (curEvent == EEvent.noliet || curEvent == EEvent.apr)
                {
                    if (curState == EEvent.nenoteikts)
                    {
                        return(badeverrstr);
                    }
                    continue;
                }

                switch (curState)
                {
                case EEvent.nenoteikts:
                    if (curEvent.IsIn(EEvent.iegeks, EEvent.pienuzsk))
                    {
                        nextState = EEvent.eks;
                    }
                    else if (!curEvent.IsIn(EEvent.ieg, EEvent.izv))
                    {
                        return(badeverrstr);
                    }
                    break;

                case EEvent.ieg:
                    if (!curEvent.IsIn(EEvent.eks, EEvent.izv))
                    {
                        return(badeverrstr);
                    }
                    break;

                case EEvent.izv:
                    if (!curEvent.IsIn(EEvent.eks, EEvent.izv))
                    {
                        return(badeverrstr);
                    }
                    break;

                case EEvent.eks:
                    if (curEvent.IsIn(EEvent.kapit, EEvent.rekat, EEvent.parvert, EEvent.vieta))
                    {
                        nextState = EEvent.eks;
                    }
                    else if (!curEvent.IsIn(EEvent.nelieto, EEvent.likvid))
                    {
                        return(badeverrstr);
                    }
                    break;

                case EEvent.nelieto:
                    if (curEvent == EEvent.lieto)
                    {
                        nextState = EEvent.eks;
                    }
                    else if (curEvent.IsIn(EEvent.kapit, EEvent.rekat, EEvent.parvert, EEvent.vieta))
                    {
                        nextState = EEvent.nelieto;
                    }
                    else if (!curEvent.IsIn(EEvent.likvid))
                    {
                        return(badeverrstr);
                    }
                    break;

                case EEvent.likvid:
                    return("Nekorekts notikums pēc pamatlīdzekļa likvidācijas.");
                }

                curState = nextState;

                switch (curState)
                {
                case EEvent.pienuzsk:
                case EEvent.ieg:
                case EEvent.izv:
                case EEvent.nelieto:
                case EEvent.eks:
                    if (value < 0.0M)
                    {
                        return("Pamatlīdzeklim ir negatīva vērtība.");
                    }
                    if (deprec < 0.0M)
                    {
                        return("Pamatlīdzekļa uzkrātais nolietojums ir negatīvs.");
                    }
                    if (value < deprec)
                    {
                        return("Pamatlīdzekļa nolietojums ir lielāks par vērtību.");
                    }
                    break;
                }
            }

            return("OK");
        }