Exemplo n.º 1
0
        public DeprecateSchedule Save(DeprecateSchedule fixedAssetSchedule)
        {
            var existDepreciationSchedule = erpNodeDBContext.DeprecateSchedules.Find(fixedAssetSchedule.Id);


            if (existDepreciationSchedule != null)
            {
                existDepreciationSchedule.FiscalYear = organization.FiscalYears.Find(existDepreciationSchedule.EndDate);

                if (existDepreciationSchedule.PostStatus == LedgerPostStatus.Posted)
                {
                    return(existDepreciationSchedule);
                }

                erpNodeDBContext.SaveChanges();
                return(existDepreciationSchedule);
            }
            else
            {
                fixedAssetSchedule.FiscalYear = organization.FiscalYears.Find(existDepreciationSchedule.EndDate);

                erpNodeDBContext.DeprecateSchedules.Add(fixedAssetSchedule);
                erpNodeDBContext.SaveChanges();

                return(fixedAssetSchedule);
            }
        }
Exemplo n.º 2
0
        public void CreateDepreciationSchedule(FixedAsset fixedAsset)
        {
            this.RemoveDepreciationSchedule(fixedAsset);

            if (fixedAsset.FixedAssetType == null)
            {
                return;
            }

            if (organization.DataItems.FirstDate > fixedAsset.EndDeprecationDate)
            {
                return;
            }


            var periodStartDate = new DateTime(Math.Max(organization.DataItems.FirstDate.Date.Ticks, fixedAsset.StartDeprecationDate.Date.Ticks));
            var currentFiscal   = organization.FiscalYears.Find(periodStartDate);
            var periodEndDate   = new DateTime(Math.Min(currentFiscal.EndDate.Date.Ticks, fixedAsset.EndDeprecationDate.Date.Ticks));

            decimal depAcc = fixedAsset.PreDepreciationValue;
            int     index  = 1;

            while (depAcc < fixedAsset.TotalDepreciationValue)
            {
                Console.WriteLine(fixedAsset.Code + "::" + currentFiscal.Name);

                DeprecateSchedule period = new DeprecateSchedule()
                {
                    Id           = Guid.NewGuid(),
                    FixedAssetId = fixedAsset.Id,
                    FixedAsset   = fixedAsset,
                    BeginDate    = periodStartDate,
                    EndDate      = periodEndDate,
                    FiscalYear   = currentFiscal,
                    No           = index++,
                };
                fixedAsset.DepreciationSchedules.Add(period);

                var expectDeprecateValue = Decimal.Round((fixedAsset.DeprecatePerYear * (decimal)period.DayCount / (decimal)period.FiscalYear.DayCount), 2);

                if (depAcc + expectDeprecateValue > fixedAsset.TotalDepreciationValue)
                {
                    expectDeprecateValue = fixedAsset.TotalDepreciationValue - depAcc;
                }

                period.DepreciationValue = expectDeprecateValue;
                depAcc += period.DepreciationValue;
                period.DepreciateAccumulation = depAcc;


                periodStartDate = currentFiscal.EndDate.AddDays(1);
                currentFiscal   = organization.FiscalYears.Find(periodStartDate);
                periodEndDate   = new DateTime(Math.Min(currentFiscal.EndDate.Ticks, fixedAsset.EndDeprecationDate.Ticks));
            }
        }
Exemplo n.º 3
0
        public bool PostLedger(DeprecateSchedule tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                return(false);
            }

            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No,
                TransactionType = transactionType
            };


            trLedger.AddDebit(tr.FixedAsset.FixedAssetType.AmortizeExpenseAccount, tr.DepreciationValue);
            trLedger.AddCredit(tr.FixedAsset.FixedAssetType.AccumulateDeprecateAcc, tr.DepreciationValue);

            if (trLedger.FinalValidate())
            {
                erpNodeDBContext.LedgerGroups.Add(trLedger);
                tr.PostStatus = LedgerPostStatus.Posted;
            }
            else
            {
                return(false);
            }

            if (SaveImmediately)
            {
                erpNodeDBContext.SaveChanges();
            }
            return(true);
        }
Exemplo n.º 4
0
 public void UnPostLedger(DeprecateSchedule fixedAssetSchedule)
 {
     organization.LedgersDal.RemoveTransaction(fixedAssetSchedule.Id);
     fixedAssetSchedule.PostStatus = LedgerPostStatus.ReadyToPost;
 }