コード例 #1
0
        public void CalculateProcessedDepreciation(DepreciationPlanList depreciationPlanList,
                                                   MyDataSet myDataSet)
        {
            foreach (DepreciationPlan depreciationPlan in depreciationPlanList.DepreciationPlans)
            {
                foreach (Asset asset in myDataSet.AssetList)
                {
                    DepreciationType depreciationType = myDataSet.DepreciationTypes[asset.DepreciationTypeId];
                    if (myDataSet.DepreciationCharges.ContainsKey(depreciationPlan.Year.ToString() + depreciationPlan.Month.ToString("00") + asset.Id.ToString()))
                    {
                        DepreciationCharge depreciationCharge = myDataSet.DepreciationCharges[depreciationPlan.Year.ToString() + depreciationPlan.Month.ToString("00") + asset.Id.ToString()];

                        DepreciationItem depr = new DepreciationItem();
                        depr.AssetName          = asset.AssetName;
                        depr.CurrentCharge      = depreciationCharge.CurrentCharge;
                        depr.CumulativelyCharge = depreciationCharge.CumulativelyCharge;
                        depr.RemainingAmount    = depreciationCharge.RemainingAmount;
                        depreciationPlan.Depreciacions.Add(depr);

                        depreciationPlan.CurrentCharge      += depreciationCharge.CurrentCharge;
                        depreciationPlan.CumulativelyCharge += depreciationCharge.CumulativelyCharge;
                        depreciationPlan.RemainingAmount    += depreciationCharge.RemainingAmount;

                        depreciationPlanList.TotalCurrentCharge += depreciationCharge.CurrentCharge;
                    }
                }
                if (depreciationPlan.CumulativelyCharge != 0)
                {
                    depreciationPlanList.TotalCumulativelyCharge = depreciationPlan.CumulativelyCharge;
                    depreciationPlanList.TotalRemainingAmount    = depreciationPlan.RemainingAmount;
                }
            }
        }
コード例 #2
0
        public void CalculatePlanForAssets(DepreciationPlanList depreciationPlanList,
                                           MyDataSet myDataSet,
                                           bool posting)
        {
            foreach (DepreciationPlan depreciationPlan in depreciationPlanList.DepreciationPlans)
            {
                foreach (Asset asset in myDataSet.AssetList)
                {
                    if (DataManipulation.CanProcessDepretiatin(asset.StartUsingDate, new DateTime(depreciationPlan.Year, depreciationPlan.Month, 1)))
                    {
                        DepreciationType depreciationType = myDataSet.DepreciationTypes[asset.DepreciationTypeId];
                        AssetType        assetType        = myDataSet.AssetTypes.Where(at => at.Id == asset.AssetTypeId).FirstOrDefault();
                        decimal          depreciation     = 0;
                        if (assetType.LowValueAsset)
                        {
                            depreciation = asset.InitialValue;
                        }
                        else
                        {
                            depreciation = decimal.Round(asset.InitialValue * ((depreciationType.DepreciationRate / 100) / 12), 2);
                        }

                        if (!myDataSet.DepreciationCharges.ContainsKey(depreciationPlan.Year.ToString() + depreciationPlan.Month.ToString("00") + asset.Id.ToString()) && depreciation != 0)
                        {
                            if (asset.AmortisedValue + depreciation > asset.InitialValue)
                            {
                                depreciation = asset.InitialValue - asset.AmortisedValue;
                            }
                            asset.AmortisedValue += depreciation;
                            //Księgowanie umożenia
                            if (posting && asset.AmortisedValue <= asset.InitialValue && asset.IsUsed && !asset.Depreciated && depreciation != 0)
                            {
                                DepreciationCharge depreciationCharge = new DepreciationCharge();
                                depreciationCharge.Month              = depreciationPlan.Month;
                                depreciationCharge.Year               = depreciationPlan.Year;
                                depreciationCharge.AssetId            = asset.Id;
                                depreciationCharge.CurrentCharge      = depreciation;
                                depreciationCharge.RemainingAmount    = asset.InitialValue - asset.AmortisedValue;
                                depreciationCharge.CumulativelyCharge = asset.AmortisedValue;
                                depreciationCharge.No = db.T_DepreciationCharges.Where(dc => dc.AssetId == asset.Id).ToList().Count + 1;
                                db.T_DepreciationCharges.Add(depreciationCharge);

                                Asset assetForModfy = db.T_Assets.Find(asset.Id);
                                assetForModfy.AmortisedValue += depreciation;
                                if (assetForModfy.AmortisedValue == assetForModfy.InitialValue)
                                {
                                    assetForModfy.Depreciated = true;
                                }

                                db.SaveChanges();
                            }
                        }
                        DepreciationItem depr = new DepreciationItem();
                        depr.AssetName     = asset.AssetName;
                        depr.CurrentCharge = depreciation;
                        if (depreciation != 0)
                        {
                            depreciationPlan.Depreciacions.Add(depr);
                        }
                        depreciationPlan.CurrentCharge          += depreciation;
                        depreciationPlanList.TotalCurrentCharge += depreciation;
                    }
                }
            }
        }