예제 #1
0
        public string DeleteFixedAsset(FixedAssetEntity fixedAsset)
        {
            const string sql = @"uspDelete_FixedAsset";

            object[] parms = { "@FixedAssetID", fixedAsset.FixedAssetId };
            return(Db.Delete(sql, true, parms));
        }
예제 #2
0
        /// <summary>
        /// Inserts the fixed asset.
        /// </summary>
        /// <param name="fixedAssetEntity">The fixed asset entity.</param>
        /// <returns></returns>
        public FixedAssetResponse InsertFixedAsset(FixedAssetEntity fixedAssetEntity)
        {
            var response = new FixedAssetResponse {
                Acknowledge = AcknowledgeType.Success
            };

            using (var scope = new TransactionScope())
            {
                try
                {
                    if (!fixedAssetEntity.Validate())
                    {
                        foreach (string error in fixedAssetEntity.ValidationErrors)
                        {
                            response.Message += error + Environment.NewLine;
                        }
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }
                    fixedAssetEntity.FixedAssetId   = Guid.NewGuid().ToString();
                    fixedAssetEntity.FixedAssetCode = fixedAssetEntity.FixedAssetCode.Trim();
                    var fixedAssetCheck = FixedAssetDao.GetFixedAssetByCode(fixedAssetEntity.FixedAssetCode);
                    if (fixedAssetCheck != null)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        response.Message     = "Mã tài sản cố định đã tồn tại";
                        scope.Dispose();
                        return(response);
                    }
                    response.Message = FixedAssetDao.InsertFixedAsset(fixedAssetEntity);
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        return(response);
                    }
                    foreach (var fixedAssetDetailAccessory in fixedAssetEntity.FixedAssetDetailAccessories)
                    {
                        fixedAssetDetailAccessory.FixedAssetId = fixedAssetEntity.FixedAssetId;
                        FixedAssetDetailAccessoryDao.InsertFixedAssetDetailAccessory(fixedAssetDetailAccessory);
                    }
                    response.FixedAssetId = fixedAssetEntity.FixedAssetId;
                    scope.Complete();
                    return(response);
                }
                catch (Exception ex)
                {
                    response.Message = ex.Message;
                    scope.Dispose();
                    return(response);
                }
            }
        }
예제 #3
0
 internal static FixedAssetModel FromDataTransferObject(FixedAssetEntity entity)
 {
     return(entity == null ? null : AutoMapper.Mapper.Map <FixedAssetEntity, FixedAssetModel>(entity));
 }
예제 #4
0
 private object[] Take(FixedAssetEntity fixedAsset)
 {
     return(new object[]
     {
         "@FixedAssetID", fixedAsset.FixedAssetId,
         "@FixedAssetCode", fixedAsset.FixedAssetCode,
         "@FixedAssetName", fixedAsset.FixedAssetName,
         "@FixedAssetForeignName", fixedAsset.FixedAssetForeignName,
         "@FixedAssetCategoryID", fixedAsset.FixedAssetCategoryId,
         "@State", fixedAsset.State,
         "@Description", fixedAsset.Description,
         "@ProductionYear", fixedAsset.ProductionYear,
         "@MadeIn", fixedAsset.MadeIn,
         "@PurchasedDate", fixedAsset.PurchasedDate,
         "@UsedDate", fixedAsset.UsedDate,
         "@DepreciationDate", fixedAsset.DepreciationDate,
         "@IncrementDate", fixedAsset.IncrementDate,
         "@DisposedDate", fixedAsset.DisposedDate,
         "@Unit", fixedAsset.Unit,
         "@SerialNumber", fixedAsset.SerialNumber,
         "@Accessories", fixedAsset.Accessories,
         "@Quantity", fixedAsset.Quantity,
         "@UnitPrice", fixedAsset.UnitPrice,
         "@OrgPrice", fixedAsset.OrgPrice,
         "@AccumDepreciationAmount", fixedAsset.AccumDepreciationAmount,
         "@RemainingAmount", fixedAsset.RemainingAmount,
         "@CurrencyCode", fixedAsset.CurrencyCode,
         "@ExchangeRate", fixedAsset.ExchangeRate,
         "@UnitPriceUSD", fixedAsset.UnitPriceUSD,
         "@OrgPriceUSD", fixedAsset.OrgPriceUSD,
         "@AccumDepreciationAmountUSD", fixedAsset.AccumDepreciationAmountUSD,
         "@RemainingAmountUSD", fixedAsset.RemainingAmountUSD,
         "@AnnualDepreciationAmount", fixedAsset.AnnualDepreciationAmount,
         "@AnnualDepreciationAmountUSD", fixedAsset.AnnualDepreciationAmountUSD,
         "@LifeTime", fixedAsset.LifeTime,
         "@DepreciationRate", fixedAsset.DepreciationRate,
         "@OrgPriceAccountCode", fixedAsset.OrgPriceAccountCode,
         "@DepreciationAccountCode", fixedAsset.DepreciationAccountCode,
         "@CapitalAccountCode", fixedAsset.CapitalAccountCode,
         "@DepartmentID", fixedAsset.DepartmentId,
         "@EmployeeID", fixedAsset.EmployeeId,
         "@IsActive", fixedAsset.IsActive,
         "@NumberOfFloor", fixedAsset.NumberOfFloor,
         "@AreaOfBuilding", fixedAsset.AreaOfBuilding,
         "@AreaOfFloor", fixedAsset.AreaOfFloor,
         "@WorkingArea", fixedAsset.WorkingArea,
         "@AdministrationArea", fixedAsset.AdministrationArea,
         "@HousingArea", fixedAsset.HousingArea,
         "@VacancyArea", fixedAsset.VacancyArea,
         "@OccupiedArea", fixedAsset.OccupiedArea,
         "@LeasingArea", fixedAsset.LeasingArea,
         "@GuestHouseArea", fixedAsset.GuestHouseArea,
         "@OtherArea", fixedAsset.OtherArea,
         "@NumberOfSeat", fixedAsset.NumberOfSeat,
         "@ControlPlate", fixedAsset.ControlPlate,
         "@IsStateManagement", fixedAsset.IsStateManagement,
         "@IsBussiness", fixedAsset.IsBussiness,
         "@Address", fixedAsset.Address,
         "@BudgetSourceCode", fixedAsset.BudgetSourceCode,
         "@ManagementCar", fixedAsset.ManagementCar,
         "@Brand", fixedAsset.Brand,
         "@IsEstimateEmployee", fixedAsset.IsEstimateEmployee,
         "@ArmortizationAccount", fixedAsset.ArmortizationAccount,
         "@BudgetItemCode", fixedAsset.BudgetItemCode,
         "@DateSuspension", fixedAsset.DateSuspension,
         "@ReasonSuspension", fixedAsset.ReasonSuspension
     });
 }
예제 #5
0
        public string UpdateFixedAsset(FixedAssetEntity fixedAsset)
        {
            const string sql = "uspUpdate_FixedAsset";

            return(Db.Update(sql, true, Take(fixedAsset)));
        }
예제 #6
0
        public int InsertFixedAsset(FixedAssetEntity fixedAsset)
        {
            const string sql = "uspInsert_FixedAsset";

            return(Db.Insert(sql, true, Take(fixedAsset)));
        }
예제 #7
0
        /// <summary>
        /// Updates the fixed asset.
        /// </summary>
        /// <param name="fixedAssetEntity">The fixed asset entity.</param>
        /// <returns></returns>
        public FixedAssetResponse UpdateFixedAsset(FixedAssetEntity fixedAssetEntity, DateTime systemDate)
        {
            var response = new FixedAssetResponse {
                Acknowledge = AcknowledgeType.Success
            };

            using (var scope = new TransactionScope())
            {
                try
                {
                    if (!fixedAssetEntity.Validate())
                    {
                        foreach (string error in fixedAssetEntity.ValidationErrors)
                        {
                            response.Message += error + Environment.NewLine;
                        }
                        response.Acknowledge = AcknowledgeType.Failure;
                        return(response);
                    }
                    fixedAssetEntity.FixedAssetCode = fixedAssetEntity.FixedAssetCode.Trim();
                    var fixedAssetCheck = FixedAssetDao.GetFixedAssetByCode(fixedAssetEntity.FixedAssetCode);
                    if (fixedAssetCheck != null && fixedAssetCheck.FixedAssetId != fixedAssetEntity.FixedAssetId)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        response.Message     = "Mã tài sản cố định đã tồn tại";
                        scope.Dispose();
                        return(response);
                    }

                    #region AnhNT: Xóa dư đầu kỳ nếu sửa ngày < dbstartdate
                    //=========================================================================
                    var fixedAssetEntity2 = FixedAssetDao.GetFixedAssetById(fixedAssetEntity.FixedAssetId);

                    if (fixedAssetEntity2 != null && !string.IsNullOrEmpty(fixedAssetEntity2.RefId) && fixedAssetEntity2.PurchasedDate < systemDate)
                    {
                        AutoMapper(DeleteGeneralLedger(fixedAssetEntity2.RefId), response);
                        if (!string.IsNullOrEmpty(response.Message))
                        {
                            goto Error;
                        }

                        AutoMapper(DeleteOriginalLedger(fixedAssetEntity2.RefId), response);
                        if (!string.IsNullOrEmpty(response.Message))
                        {
                            goto Error;
                        }

                        AutoMapper(DeleteOpeningFixedAssetEntry(fixedAssetEntity2.FixedAssetId), response);
                        if (!string.IsNullOrEmpty(response.Message))
                        {
                            goto Error;
                        }

                        if (fixedAssetEntity2.RefType == 603)
                        {
                            AutoMapper(DeleteFixAssetLedger603(fixedAssetEntity2.FixedAssetId, fixedAssetEntity2.RefType),
                                       response);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                goto Error;
                            }
                            //Xóa ts dư đầu kỳ
                            AutoMapper(DeleteGeneralLedger(fixedAssetEntity.FixedAssetId), response);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                goto Error;
                            }
                        }
                        else
                        {
                            AutoMapper(DeleteFixAssetLedger(fixedAssetEntity2.RefId, fixedAssetEntity2.RefType),
                                       response);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                goto Error;
                            }
                        }

                        response.Message = OpeningFixedAssetEntryDao.DeleteOpeningFixedAssetEntry(fixedAssetEntity2.RefId);
                        if (!string.IsNullOrEmpty(response.Message))
                        {
                            goto Error;
                        }
                    }
                    //=========================================================================
                    #endregion

                    response.Message = FixedAssetDao.UpdateFixedAsset(fixedAssetEntity);
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }
                    FixedAssetDetailAccessoryDao.DeleteFixedAssetDetailAccessoryByFixedAssetId(fixedAssetEntity.FixedAssetId);
                    foreach (var fixedAssetDetailAccessory in fixedAssetEntity.FixedAssetDetailAccessories)
                    {
                        fixedAssetDetailAccessory.FixedAssetId = fixedAssetEntity.FixedAssetId;
                        FixedAssetDetailAccessoryDao.InsertFixedAssetDetailAccessory(fixedAssetDetailAccessory);
                    }
                    #region Error
Error:
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }
                    #endregion
                    response.FixedAssetId = fixedAssetEntity.FixedAssetId;
                    scope.Complete();
                    return(response);
                }
                catch (Exception ex)
                {
                    response.Message = ex.Message;
                    scope.Dispose();
                    return(response);
                }
            }
        }
 /// <summary>
 /// Takes the specified fixed asset.
 /// </summary>
 /// <param name="fixedAssetEntity">The fixed asset.</param>
 /// <returns></returns>
 private object[] Take(FixedAssetEntity fixedAssetEntity)
 {
     return(new object[]
     {
         "@FixedAssetID", fixedAssetEntity.FixedAssetId,
         "@FixedAssetCategoryID", fixedAssetEntity.FixedAssetCategoryId,
         "@DepartmentID", fixedAssetEntity.DepartmentId,
         "@FixedAssetCode", fixedAssetEntity.FixedAssetCode,
         "@FixedAssetName", fixedAssetEntity.FixedAssetName,
         "@Quantity", fixedAssetEntity.Quantity,
         "@Description", fixedAssetEntity.Description,
         "@ProductionYear", fixedAssetEntity.ProductionYear,
         "@MadeIn", fixedAssetEntity.MadeIn,
         "@SerialNumber", fixedAssetEntity.SerialNumber,
         "@Accessories", fixedAssetEntity.Accessories,
         "@VendorID", fixedAssetEntity.VendorId,
         "@GuaranteeDuration", fixedAssetEntity.GuaranteeDuration,
         "@IsSecondHand", fixedAssetEntity.IsSecondHand,
         "@LastState", fixedAssetEntity.LastState,
         "@DisposedDate", fixedAssetEntity.DisposedDate,
         "@DisposedAmount", fixedAssetEntity.DisposedAmount,
         "@DisposedReason", fixedAssetEntity.DisposedReason,
         "@PurchasedDate", fixedAssetEntity.PurchasedDate,
         "@UsedDate", fixedAssetEntity.UsedDate,
         "@DepreciationDate", fixedAssetEntity.DepreciationDate,
         "@IncrementDate", fixedAssetEntity.IncrementDate,
         "@OrgPrice", fixedAssetEntity.OrgPrice,
         "@DepreciationValueCaculated", fixedAssetEntity.DepreciationValueCaculated,
         "@AccumDepreciationAmount", fixedAssetEntity.AccumDepreciationAmount,
         "@LifeTime", fixedAssetEntity.LifeTime,
         "@DepreciationRate", fixedAssetEntity.DepreciationRate,
         "@PeriodDepreciationAmount", fixedAssetEntity.PeriodDepreciationAmount,
         "@RemainingAmount", fixedAssetEntity.RemainingAmount,
         "@RemainingLifeTime", fixedAssetEntity.RemainingLifeTime,
         "@EndYear", fixedAssetEntity.EndYear,
         "@OrgPriceAccount", fixedAssetEntity.OrgPriceAccount,
         "@CapitalAccount", fixedAssetEntity.CapitalAccount,
         "@BudgetChapterCode", fixedAssetEntity.BudgetChapterCode,
         "@BudgetKindItemCode", fixedAssetEntity.BudgetKindItemCode,
         "@BudgetSubKindItemCode", fixedAssetEntity.BudgetSubKindItemCode,
         "@BudgetItemCode", fixedAssetEntity.BudgetItemCode,
         "@BudgetSubItemCode", fixedAssetEntity.BudgetSubItemCode,
         "@CreditDepreciationAccount", fixedAssetEntity.CreditDepreciationAccount,
         "@DebitDepreciationAccount", fixedAssetEntity.DebitDepreciationAccount,
         "@IsFixedAssetTransfer", fixedAssetEntity.IsFixedAssetTransfer,
         "@DepreciationTimeCaculated", fixedAssetEntity.DepreciationTimeCaculated,
         "@Unit", fixedAssetEntity.Unit,
         "@Source", fixedAssetEntity.Source,
         "@IsActive", fixedAssetEntity.IsActive,
         "@RevenueAccount", fixedAssetEntity.RevenueAccount,
         "@UsingRatio", fixedAssetEntity.UsingRatio,
         "@DevaluationDate", fixedAssetEntity.DevaluationDate,
         "@DevaluationPeriod", fixedAssetEntity.DevaluationPeriod,
         "@DevaluationRate", fixedAssetEntity.DevaluationRate,
         "@DevaluationLifeTime", fixedAssetEntity.DevaluationLifeTime,
         "@DevaluationCreditAccount", fixedAssetEntity.DevaluationCreditAccount,
         "@DevaluationDebitAccount", fixedAssetEntity.DevaluationDebitAccount,
         "@AccumDevaluationAmount", fixedAssetEntity.AccumDevaluationAmount,
         "@EndDevaluationDate", fixedAssetEntity.EndDevaluationDate,
         "@PeriodDevaluationAmount", fixedAssetEntity.PeriodDevaluationAmount,
         "@DevaluationAmount", fixedAssetEntity.DevaluationAmount,
         "@FundStructureId", fixedAssetEntity.FundStructureId
     });
 }
        public List <FixedAssetEntity> GetFixedAsset(string connectionString)
        {
            List <FixedAssetEntity> listAccount = new List <FixedAssetEntity>();

            using (var context = new MISAEntity(connectionString))
            {
                var department = context.Departments.ToList();
                var categories = context.FixedAssets.ToList();
                foreach (var result in categories)
                {
                    var fixedAsset = new FixedAssetEntity();
                    fixedAsset.FixedAssetId         = result.FixedAssetID.ToString();
                    fixedAsset.FixedAssetCategoryId = result.FixedAssetCategoryID.ToString();
                    fixedAsset.DepartmentId         = result.Department == null?"": result.Department.DepartmentID.ToString();
                    fixedAsset.FixedAssetCode       = result.FixedAssetCode;
                    fixedAsset.FixedAssetName       = result.FixedAssetName;
                    fixedAsset.Quantity             = result.Quantity ?? 0;
                    fixedAsset.Description          = result.Description;
                    fixedAsset.ProductionYear       = result.ProductionYear ?? 0;
                    fixedAsset.MadeIn       = result.MadeIn;
                    fixedAsset.SerialNumber = result.SerialNumber;
                    fixedAsset.Accessories  = result.Accessories;
                    //fixedAsset.VendorId = result.ven;
                    fixedAsset.GuaranteeDuration          = result.GuaranteeDuration;
                    fixedAsset.IsSecondHand               = result.IsSecondHand;
                    fixedAsset.LastState                  = result.LastState ?? 0;
                    fixedAsset.DisposedDate               = result.DisposedDate ?? DateTime.Now;
                    fixedAsset.DisposedAmount             = result.DisposedAmount;
                    fixedAsset.DisposedReason             = result.DisposedReason;
                    fixedAsset.PurchasedDate              = result.PurchasedDate ?? DateTime.Now;
                    fixedAsset.UsedDate                   = result.UsedDate ?? DateTime.Now;
                    fixedAsset.DepreciationDate           = result.DepreciationDate ?? DateTime.Now;
                    fixedAsset.IncrementDate              = result.IncrementDate ?? DateTime.Now;
                    fixedAsset.OrgPrice                   = result.OrgPrice;
                    fixedAsset.DepreciationValueCaculated = result.DepreciationValueCaculated;
                    fixedAsset.AccumDepreciationAmount    = result.AccumDepreciationAmount;
                    fixedAsset.LifeTime                   = decimal.ToInt32(result.LifeTime);
                    fixedAsset.DepreciationRate           = result.DepreciationRate;
                    fixedAsset.PeriodDepreciationAmount   = result.PeriodDepreciationAmount;
                    fixedAsset.RemainingAmount            = result.RemainingAmount;
                    fixedAsset.RemainingLifeTime          = result.RemainingLifeTime ?? 0;
                    fixedAsset.EndYear                   = result.EndYear ?? 0;
                    fixedAsset.OrgPriceAccount           = result.OrgPriceAccount;
                    fixedAsset.CapitalAccount            = result.CapitalAccount;
                    fixedAsset.BudgetChapterCode         = result.BudgetChapterCode;
                    fixedAsset.BudgetKindItemCode        = result.BudgetKindItemCode;
                    fixedAsset.BudgetSubKindItemCode     = result.BudgetSubKindItemCode;
                    fixedAsset.BudgetItemCode            = result.BudgetItemCode;
                    fixedAsset.BudgetSubItemCode         = result.BudgetSubItemCode;
                    fixedAsset.CreditDepreciationAccount = result.DepreciationAccount;
                    fixedAsset.DebitDepreciationAccount  = result.DebitDepreciationAccount;
                    fixedAsset.IsFixedAssetTransfer      = result.IsFixedAssetTransfer;
                    fixedAsset.DepreciationTimeCaculated = result.DepreciationTimeCaculated;
                    fixedAsset.Unit = result.Unit;
                    // fixedAsset.RevenueAccount = result.re;
                    fixedAsset.Source                  = result.Source;
                    fixedAsset.DevaluationDate         = result.DevaluationDate ?? DateTime.Now;
                    fixedAsset.DevaluationAmount       = result.DevaluationAmount;
                    fixedAsset.DevaluationPeriod       = result.DevaluationPeriod;
                    fixedAsset.DevaluationLifeTime     = result.DevaluationLifeTime;
                    fixedAsset.DevaluationRate         = result.DevaluationRate;
                    fixedAsset.PeriodDevaluationAmount = result.PeriodDevaluationAmount;
                    fixedAsset.AccumDevaluationAmount  = result.AccumDevaluationAmount;
                    //fixedAsset.re = result.RemainingDevaluationLifeTime;
                    fixedAsset.EndDevaluationDate       = result.EndDevaluationDate ?? DateTime.Now;
                    fixedAsset.DevaluationDebitAccount  = result.DevaluationDebitAccount;
                    fixedAsset.DevaluationCreditAccount = result.DevaluationCreditAccount;
                    //fixedAsset.ProductionRate = result.ProductionRate;
                    fixedAsset.IsActive = true;
                    //fixedAsset.UsingRatio = result.UsingRatio;
                    fixedAsset.FixedAssetDetailAccessories = new List <FixedAssetDetailAccessoryEntity>();
                    fixedAsset.FixedAssetVoucherAttachs    = new List <FixedAssetVoucherAttachEntity>();

                    listAccount.Add(fixedAsset);
                }
            }

            return(listAccount);
        }