Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
0
        public FixedAssetResponse DeleteFixedAssetConvert()
        {
            var response = new FixedAssetResponse {
                Acknowledge = AcknowledgeType.Success
            };

            using (var scope = new TransactionScope())
            {
                try
                {
                    response.Message = FixedAssetDao.DeleteFixedAssetConvert();
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        if (response.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint"))
                        {
                            response.Message = "Tài sản đã phát sinh trong chứng từ liên quan, không thể xóa!";
                        }
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }

                    #region Error
Error:
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }
                    #endregion


                    scope.Complete();
                    return(response);
                }
                catch (Exception e)
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    response.Message     = e.Message;
                    return(response);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the fixed assets.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public FixedAssetResponse GetFixedAssets(FixedAssetRequest request)
        {
            var response = new FixedAssetResponse();

            if (request.LoadOptions.Contains("FixedAssets"))
            {
                if (request.LoadOptions.Contains("IsActive") && request.LoadOptions.Length < 3)
                {
                    response.FixedAssets = FixedAssetDao.GetFixedAssetsByActive(request.IsActive);
                }
                else if (request.LoadOptions.Contains("IsActive") && request.LoadOptions.Contains("IncludingFixedAssetCurrency"))
                {
                    response.FixedAssets = FixedAssetDao.GetFixedAssetsByActive(request.IsActive);

                    foreach (FixedAssetEntity t in response.FixedAssets)
                    {
                        t.FixedAssetCurrencies = FixedAssetCurrencyDao.GetFixedAssetCurrencysByFixedAssetId(t.FixedAssetId);
                        t.FixedAssetAccessarys = FixedAssetAccessaryDao.GetFixedAssetAccessarysByFixedAssetId(t.FixedAssetId);
                    }
                }
                else
                {
                    response.FixedAssets = FixedAssetDao.GetAllFixedAssetsWithStoreProdure(request.StoreProdure);
                }
            }

            if (request.LoadOptions.Contains("FixedAsset"))
            {
                response.FixedAsset = FixedAssetDao.GetFixedAsset(request.FixedAssetId);
                if (request.LoadOptions.Contains("IncludeFixedAssetCurrency"))
                {
                    if (response.FixedAsset == null)
                    {
                        response.FixedAsset = new FixedAssetEntity();
                    }
                    response.FixedAsset.FixedAssetCurrencies = FixedAssetCurrencyDao.GetFixedAssetCurrencysByFixedAssetId(request.FixedAssetId);
                    response.FixedAsset.FixedAssetAccessarys = FixedAssetAccessaryDao.GetFixedAssetAccessarysByFixedAssetId(request.FixedAssetId);
                }

                if (request.LoadOptions.Contains("FixedAssetCode"))
                {
                    response.FixedAsset = FixedAssetDao.GetFixedAssetByCode(request.FixedAssetCode);
                    if (response.FixedAsset != null)
                    {
                        response.FixedAsset.FixedAssetCurrencies = FixedAssetCurrencyDao.GetFixedAssetCurrencysByFixedAssetId(response.FixedAsset.FixedAssetId);
                        response.FixedAsset.FixedAssetAccessarys = FixedAssetAccessaryDao.GetFixedAssetAccessarysByFixedAssetId(response.FixedAsset.FixedAssetId);
                    }
                }

                if (request.LoadOptions.Contains("RemainingQuantity"))
                {
                    response.FixedAsset = FixedAssetDao.GetFixedAssetRemainingQuantity(request.FixedAssetId);
                }

                if (request.LoadOptions.Contains("CheckFAFixedAssetIncrement"))
                {
                    response.FixedAsset = FixedAssetDao.GetFixedAssetOnFixedAssetIncrement(request.FixedAssetId);
                }

                if (request.LoadOptions.Contains("GetFADecrement"))
                {
                    response.FixedAsset = FixedAssetDao.GetFixedAssetDecrement(request.FixedAssetId, request.CurrencyCode, request.PostedDate);
                }
                if (request.LoadOptions.Contains("GetFADecrementQuantity"))
                {
                    response.FixedAsset = FixedAssetDao.GetFixedAssetDecrement(request.FixedAssetId, request.CurrencyCode, request.RefTypeId);
                }
                if (request.LoadOptions.Contains("CheckFADecrement"))
                {
                    response.FixedAsset = FixedAssetDao.GetFixedAssetDecrement(request.FixedAssetId, request.RefTypeId);
                }
                if (request.LoadOptions.Contains("CheckOpening"))
                {
                    response.FixedAsset = FixedAssetDao.GetFixedAssetOpening(request.FixedAssetId);
                }
            }

            return(response);
        }
Esempio n. 4
0
        /// <summary>
        /// Sets the fixed assets.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public FixedAssetResponse SetFixedAssets(FixedAssetRequest request)
        {
            var response = new FixedAssetResponse();

            var fixedAssetEntity = request.FixedAsset;

            if (request.Action != PersistType.Delete)
            {
                if (!fixedAssetEntity.Validate())
                {
                    foreach (var error in fixedAssetEntity.ValidationErrors)
                    {
                        response.Message += error + Environment.NewLine;
                    }
                    response.Acknowledge = AcknowledgeType.Failure;
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }
            }

            try
            {
                switch (request.Action)
                {
                case PersistType.Insert:
                    var    fixedAssetCode      = fixedAssetEntity.FixedAssetCode;
                    var    fixedAssetName      = fixedAssetEntity.FixedAssetName;
                    var    autoNumber          = AutoNumberDao.GetAutoNumberByRefType(10);
                    string lengthOfValueInsert = null;
                    for (int i = 0; i < request.Replication + 1; i++)
                    {
                        using (var scope = new TransactionScope())
                        {
                            if (i == 0)
                            {
                                fixedAssetEntity.FixedAssetCode = fixedAssetEntity.FixedAssetCode;
                            }
                            if (i != 0)
                            {
                                //fixedAssetEntity.FixedAssetCode = "0" + autoNumber.Value;
                                for (int a = 0; a < (autoNumber.LengthOfValue - autoNumber.Value.ToString(CultureInfo.InvariantCulture).Length); a++)
                                {
                                    lengthOfValueInsert += "0";
                                }
                                fixedAssetEntity.FixedAssetCode = lengthOfValueInsert + autoNumber.Value;
                                fixedAssetEntity.FixedAssetName = fixedAssetName + "(" + i + ")";
                            }
                            var fixedAssetByCode = FixedAssetDao.GetFixedAssetsByCode(fixedAssetEntity.FixedAssetCode);
                            if (fixedAssetByCode.Count != 0)
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                response.Message     = @"Mã tài sản " + fixedAssetEntity.FixedAssetCode + @" đã tồn tại !";
                                return(response);
                            }

                            if (fixedAssetEntity.FixedAssetCurrencies.Count > 1)
                            {
                                fixedAssetEntity.Quantity = 1;
                            }

                            if (fixedAssetEntity.FixedAssetCurrencies.Count == 2)
                            {
                                decimal sum1 = 0;
                                decimal sum2 = 0;
                                foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                {
                                    if (fixedAssetCurrency.CurrencyCode != "USD")
                                    {
                                        sum1 = fixedAssetCurrency.OrgPriceUSD;
                                    }
                                    else
                                    {
                                        sum2 = fixedAssetCurrency.OrgPrice;
                                    }
                                }
                                fixedAssetEntity.OrgPrice = sum1 + sum2;
                            }
                            else if (fixedAssetEntity.FixedAssetCurrencies.Count == 1)
                            {
                                foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                {
                                    if (fixedAssetCurrency.CurrencyCode != "USD")
                                    {
                                        fixedAssetEntity.OrgPrice = fixedAssetCurrency.OrgPrice;
                                    }
                                    else
                                    {
                                        fixedAssetEntity.OrgPrice = fixedAssetCurrency.OrgPrice;
                                    }
                                }
                            }
                            else
                            {
                                foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                {
                                    fixedAssetEntity.OrgPrice = fixedAssetCurrency.OrgPrice;
                                }
                            }

                            fixedAssetEntity.FixedAssetId = FixedAssetDao.InsertFixedAsset(fixedAssetEntity);
                            if (fixedAssetEntity.FixedAssetId <= 0)
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                scope.Dispose();
                                return(response);
                            }

                            if (fixedAssetEntity.FixedAssetCurrencies != null && fixedAssetEntity.FixedAssetCurrencies.Count > 0)
                            {
                                foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                {
                                    if (!fixedAssetCurrency.Validate())
                                    {
                                        foreach (string error in fixedAssetCurrency.ValidationErrors)
                                        {
                                            response.Message += error + Environment.NewLine;
                                        }
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        return(response);
                                    }
                                    fixedAssetCurrency.FixedAssetId         = fixedAssetEntity.FixedAssetId;
                                    fixedAssetCurrency.FixedAssetCurrencyId = FixedAssetCurrencyDao.InsertFixedAssetCurrency(fixedAssetCurrency);
                                    if (fixedAssetCurrency.FixedAssetCurrencyId > 0)
                                    {
                                        continue;
                                    }
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }
                            }

                            if (fixedAssetEntity.FixedAssetAccessarys != null && fixedAssetEntity.FixedAssetAccessarys.Count > 0)
                            {
                                foreach (var fixedAssetAccessary in fixedAssetEntity.FixedAssetAccessarys)
                                {
                                    if (!fixedAssetAccessary.Validate())
                                    {
                                        foreach (string error in fixedAssetAccessary.ValidationErrors)
                                        {
                                            response.Message += error + Environment.NewLine;
                                        }
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        return(response);
                                    }
                                    fixedAssetAccessary.FixedAssetId          = fixedAssetEntity.FixedAssetId;
                                    fixedAssetAccessary.FixedAssetAccessaryId = FixedAssetAccessaryDao.InsertFixedAssetAccessary(fixedAssetAccessary);
                                    if (fixedAssetAccessary.FixedAssetAccessaryId > 0)
                                    {
                                        continue;
                                    }
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }
                            }

                            autoNumber.Value += 1;
                            response.Message  = AutoNumberDao.UpdateAutoNumber(autoNumber);
                            if (response.Message != null)
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                scope.Dispose();
                                return(response);
                            }

                            scope.Complete();
                        }
                    }

                    break;

                case PersistType.Update:
                    var    fixedAssetCodeUpdate = fixedAssetEntity.FixedAssetCode;
                    var    fixedAssetNameUpdate = fixedAssetEntity.FixedAssetName;
                    var    autoNumberUpdate     = AutoNumberDao.GetAutoNumberByRefType(10);
                    string lengthOfValue        = null;
                    int    valueLocalCurency;
                    for (int i = 0; i < request.Replication + 1; i++)
                    {
                        using (var scope = new TransactionScope())
                        {
                            if (i == 0)
                            {
                                //delete FixedAssetCurrency
                                response.Message = FixedAssetCurrencyDao.DeleteFixedAssetCurrencyByFixedAssetId(fixedAssetEntity.FixedAssetId);
                                if (response.Message != null)
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }

                                if (fixedAssetEntity.FixedAssetCurrencies.Count == 2)
                                {
                                    decimal sum1 = 0;
                                    decimal sum2 = 0;
                                    foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                    {
                                        if (fixedAssetCurrency.CurrencyCode != "USD")
                                        {
                                            sum1 = fixedAssetCurrency.OrgPriceUSD;
                                        }
                                        else
                                        {
                                            sum2 = fixedAssetCurrency.OrgPrice;
                                        }
                                    }
                                    fixedAssetEntity.OrgPrice = sum1 + sum2;
                                }
                                else if (fixedAssetEntity.FixedAssetCurrencies.Count == 1)
                                {
                                    foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                    {
                                        if (fixedAssetCurrency.CurrencyCode != "USD")
                                        {
                                            fixedAssetEntity.OrgPrice = fixedAssetCurrency.OrgPrice;
                                        }
                                        else
                                        {
                                            fixedAssetEntity.OrgPrice = fixedAssetCurrency.OrgPrice;
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                    {
                                        fixedAssetEntity.OrgPrice = fixedAssetCurrency.OrgPrice;
                                    }
                                }

                                response.Message = FixedAssetAccessaryDao.DeleteFixedAssetAccessaryByFixedAssetId(fixedAssetEntity.FixedAssetId);
                                if (response.Message != null)
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }

                                response.Message = FixedAssetDao.UpdateFixedAsset(fixedAssetEntity);
                                if (response.Message != null)
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }

                                foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                {
                                    if (!fixedAssetCurrency.Validate())
                                    {
                                        foreach (var error in fixedAssetCurrency.ValidationErrors)
                                        {
                                            response.Message += error + Environment.NewLine;
                                        }
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        return(response);
                                    }
                                    fixedAssetCurrency.FixedAssetId         = fixedAssetEntity.FixedAssetId;
                                    fixedAssetCurrency.FixedAssetCurrencyId = FixedAssetCurrencyDao.InsertFixedAssetCurrency(fixedAssetCurrency);
                                    if (fixedAssetCurrency.FixedAssetCurrencyId > 0)
                                    {
                                        continue;
                                    }
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }

                                if (fixedAssetEntity.FixedAssetAccessarys != null && fixedAssetEntity.FixedAssetAccessarys.Count > 0)
                                {
                                    foreach (var fixedAssetAccessary in fixedAssetEntity.FixedAssetAccessarys)
                                    {
                                        if (!fixedAssetAccessary.Validate())
                                        {
                                            foreach (string error in fixedAssetAccessary.ValidationErrors)
                                            {
                                                response.Message += error + Environment.NewLine;
                                            }
                                            response.Acknowledge = AcknowledgeType.Failure;
                                            return(response);
                                        }
                                        fixedAssetAccessary.FixedAssetId          = fixedAssetEntity.FixedAssetId;
                                        fixedAssetAccessary.FixedAssetAccessaryId = FixedAssetAccessaryDao.InsertFixedAssetAccessary(fixedAssetAccessary);
                                        if (fixedAssetAccessary.FixedAssetAccessaryId > 0)
                                        {
                                            continue;
                                        }
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        scope.Dispose();
                                        return(response);
                                    }
                                }

                                scope.Complete();
                            }
                            if (i != 0)
                            {
                                lengthOfValue = "";
                                for (int a = 0; a < (autoNumberUpdate.LengthOfValue - autoNumberUpdate.Value.ToString(CultureInfo.InvariantCulture).Length); a++)
                                {
                                    lengthOfValue += "0";
                                }
                                fixedAssetEntity.FixedAssetCode = (autoNumberUpdate.Prefix == null ? string.Empty : autoNumberUpdate.Prefix) + lengthOfValue + autoNumberUpdate.Value + (autoNumberUpdate.Suffix == null ? string.Empty : autoNumberUpdate.Suffix);

                                fixedAssetEntity.FixedAssetName = fixedAssetNameUpdate + "(" + i + ")";
                                var fixedAssetByCode = FixedAssetDao.GetFixedAssetsByCode(fixedAssetEntity.FixedAssetCode);
                                if (fixedAssetByCode.Count != 0)
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    response.Message     = @"Mã tài sản " + fixedAssetEntity.FixedAssetCode + @" đã tồn tại !";
                                    return(response);
                                }
                                if (fixedAssetEntity.FixedAssetCurrencies.Count > 1)
                                {
                                    fixedAssetEntity.Quantity = 1;
                                }
                                if (fixedAssetEntity.FixedAssetCurrencies.Count == 2)
                                {
                                    decimal sum1 = 0;
                                    decimal sum2 = 0;
                                    foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                    {
                                        if (fixedAssetCurrency.CurrencyCode != "USD")
                                        {
                                            sum1 = fixedAssetCurrency.OrgPriceUSD;
                                        }
                                        else
                                        {
                                            sum2 = fixedAssetCurrency.OrgPrice;
                                        }
                                    }
                                    fixedAssetEntity.OrgPriceUSD = sum1 + sum2;
                                }
                                else if (fixedAssetEntity.FixedAssetCurrencies.Count == 1)
                                {
                                    foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                    {
                                        if (fixedAssetCurrency.CurrencyCode != "USD")
                                        {
                                            fixedAssetEntity.OrgPriceUSD = fixedAssetCurrency.OrgPrice;
                                        }
                                        else
                                        {
                                            fixedAssetEntity.OrgPriceUSD = fixedAssetCurrency.OrgPrice;
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                    {
                                        fixedAssetEntity.OrgPriceUSD = fixedAssetCurrency.OrgPrice;
                                    }
                                }

                                fixedAssetEntity.FixedAssetId = FixedAssetDao.InsertFixedAsset(fixedAssetEntity);
                                if (fixedAssetEntity.FixedAssetId <= 0)
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }

                                foreach (var fixedAssetCurrency in fixedAssetEntity.FixedAssetCurrencies)
                                {
                                    if (!fixedAssetCurrency.Validate())
                                    {
                                        foreach (string error in fixedAssetCurrency.ValidationErrors)
                                        {
                                            response.Message += error + Environment.NewLine;
                                        }
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        return(response);
                                    }
                                    fixedAssetCurrency.FixedAssetId         = fixedAssetEntity.FixedAssetId;
                                    fixedAssetCurrency.FixedAssetCurrencyId = FixedAssetCurrencyDao.InsertFixedAssetCurrency(fixedAssetCurrency);
                                    if (fixedAssetCurrency.FixedAssetCurrencyId > 0)
                                    {
                                        continue;
                                    }
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }

                                if (fixedAssetEntity.FixedAssetAccessarys != null && fixedAssetEntity.FixedAssetAccessarys.Count > 0)
                                {
                                    foreach (var fixedAssetAccessary in fixedAssetEntity.FixedAssetAccessarys)
                                    {
                                        if (!fixedAssetAccessary.Validate())
                                        {
                                            foreach (string error in fixedAssetAccessary.ValidationErrors)
                                            {
                                                response.Message += error + Environment.NewLine;
                                            }
                                            response.Acknowledge = AcknowledgeType.Failure;
                                            return(response);
                                        }
                                        fixedAssetAccessary.FixedAssetId          = fixedAssetEntity.FixedAssetId;
                                        fixedAssetAccessary.FixedAssetAccessaryId = FixedAssetAccessaryDao.InsertFixedAssetAccessary(fixedAssetAccessary);
                                        if (fixedAssetAccessary.FixedAssetAccessaryId > 0)
                                        {
                                            continue;
                                        }
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        scope.Dispose();
                                        return(response);
                                    }
                                }

                                //response.Message = null;
                                autoNumberUpdate.Value += 1;
                                response.Message        = AutoNumberDao.UpdateAutoNumber(autoNumberUpdate);
                                if (response.Message != null)
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }
                                scope.Complete();
                            }
                        }
                    }
                    break;

                case PersistType.Delete:
                    var accountEntityForDelete = FixedAssetDao.GetFixedAsset(request.FixedAssetId);
                    response.Message = FixedAssetDao.DeleteFixedAsset(accountEntityForDelete);
                    break;
                }
            }
            catch (Exception ex)
            {
                response.Acknowledge = AcknowledgeType.Failure;
                response.Message     = ex.Message;
                return(response);
            }

            response.FixedAssetId = fixedAssetEntity != null ? fixedAssetEntity.FixedAssetId : 0;
            response.Acknowledge  = response.Message != null ? AcknowledgeType.Failure : AcknowledgeType.Success;
            return(response);
        }
Esempio n. 5
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);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Deletes the fixed asset.
        /// </summary>
        /// <param name="fixedAssetId">The fixed asset identifier.</param>
        /// <param name="systemDate">The system date.</param>
        /// <returns></returns>
        public FixedAssetResponse DeleteFixedAsset(string fixedAssetId, DateTime systemDate)
        {
            var response = new FixedAssetResponse {
                Acknowledge = AcknowledgeType.Success
            };

            using (var scope = new TransactionScope())
            {
                try
                {
                    var fixedAssetEntity = FixedAssetDao.GetFixedAssetById(fixedAssetId);

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

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

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

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

                        response.Message = OpeningFixedAssetEntryDao.DeleteOpeningFixedAssetEntry(fixedAssetEntity.RefId);
                        if (!string.IsNullOrEmpty(response.Message))
                        {
                            goto Error;
                        }
                    }

                    response.Message = FixedAssetDao.DeleteFixedAsset(fixedAssetEntity);
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        if (response.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint"))
                        {
                            response.Message = "Tài sản đã phát sinh trong chứng từ liên quan, không thể xóa!";
                        }
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }

                    response.Message = FixedAssetDao.DeleteFixedAssetActivity(fixedAssetEntity);

                    #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 e)
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    response.Message     = e.Message;
                    return(response);
                }
            }
        }