/// <summary>
        /// Initializes the fixed asset ledgers.
        /// </summary>
        /// <param name="fAArmortizationEntity">The f a armortization entity.</param>
        /// <returns></returns>
        private static IEnumerable <FixedAssetLedgerEntity> InitFixedAssetLedgers(FAArmortizationEntity fAArmortizationEntity)
        {
            var fixedAssetLedgers = new List <FixedAssetLedgerEntity>();

            foreach (var fAArmortizationDetail in fAArmortizationEntity.FAArmortizationDetails)
            {
                var fixedAssetLedger = new FixedAssetLedgerEntity
                {
                    RefId                            = fAArmortizationEntity.RefId,
                    RefTypeId                        = fAArmortizationEntity.RefTypeId,
                    RefNo                            = fAArmortizationEntity.RefNo,
                    RefDate                          = fAArmortizationEntity.RefDate,
                    PostedDate                       = fAArmortizationEntity.PostedDate,
                    FixedAssetId                     = fAArmortizationDetail.FixedAssetId,
                    DepartmentId                     = fAArmortizationDetail.DepartmentId,
                    CurrencyCode                     = fAArmortizationDetail.CurrencyCode,
                    OrgPriceAccount                  = "",
                    OrgPriceDebitAmount              = 0,
                    OrgPriceCreditAmount             = 0,
                    OrgPriceDebitAmountExchange      = 0,
                    OrgPriceCreditAmountExchange     = 0,
                    DepreciationAccount              = "",
                    DepreciationDebitAmount          = 0,
                    DepreciationCreditAmount         = 0,
                    DepreciationDebitAmountExchange  = 0,
                    DepreciationCreditAmountExchange = 0,
                    BudgetSourceAccount              = "",
                    BudgetSourcelDebitAmount         = 0,
                    BudgetSourceCreditAmount         = 0,
                    BudgetSourcelDebitAmountExchange = 0,
                    BudgetSourceCreditAmountExchange = 0,
                    JournalMemo                      = fAArmortizationEntity.JournalMemo,
                    Description                      = fAArmortizationDetail.Description,
                    Quantity                         = fAArmortizationDetail.Quantity
                };
                if (fixedAssetLedgers.Count == 0 || (from item in fixedAssetLedgers
                                                     where (item.FixedAssetId == fAArmortizationDetail.FixedAssetId)
                                                     select item).FirstOrDefault() == null)
                {
                    fixedAssetLedger = AddFixedAssetLedgerEntity(fAArmortizationDetail, fixedAssetLedger);
                    fixedAssetLedgers.Add(fixedAssetLedger);
                }
                else
                {
                    fixedAssetLedger = (from item in fixedAssetLedgers
                                        where (item.FixedAssetId == fAArmortizationDetail.FixedAssetId)
                                        select item).First();
                    fixedAssetLedgers.Remove(fixedAssetLedger);
                    fixedAssetLedgers.Add(AddFixedAssetLedgerEntity(fAArmortizationDetail, fixedAssetLedger));
                }
            }
            return(fixedAssetLedgers);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Takes the specified fixed asset ledger.
 /// </summary>
 /// <param name="fixedAssetLedger">The fixed asset ledger.</param>
 /// <returns></returns>
 private static object[] Take(FixedAssetLedgerEntity fixedAssetLedger)
 {
     return(new object[]
     {
         "@FixedAssetLedgerID", fixedAssetLedger.FixedAssetLedgerId,
         "@RefID", fixedAssetLedger.RefId,
         "@RefType", fixedAssetLedger.RefType,
         "@RefNo", fixedAssetLedger.RefNo,
         "@RefDate", fixedAssetLedger.RefDate,
         "@PostedDate", fixedAssetLedger.PostedDate,
         "@FixedAssetID", fixedAssetLedger.FixedAssetId,
         "@DepartmentID", fixedAssetLedger.DepartmentId,
         "@LifeTime", fixedAssetLedger.LifeTime,
         "@AnnualDepreciationRate", fixedAssetLedger.AnnualDepreciationRate,
         "@AnnualDepreciationAmount", fixedAssetLedger.AnnualDepreciationAmount,
         "@OrgPriceAccount", fixedAssetLedger.OrgPriceAccount,
         "@OrgPriceDebitAmount", fixedAssetLedger.OrgPriceDebitAmount,
         "@OrgPriceCreditAmount", fixedAssetLedger.OrgPriceCreditAmount,
         "@DepreciationAccount", fixedAssetLedger.DepreciationAccount,
         "@DepreciationDebitAmount", fixedAssetLedger.DepreciationDebitAmount,
         "@DepreciationCreditAmount", fixedAssetLedger.DepreciationCreditAmount,
         "@CapitalAccount", fixedAssetLedger.CapitalAccount,
         "@CapitalDebitAmount", fixedAssetLedger.CapitalDebitAmount,
         "@CapitalCreditAmount", fixedAssetLedger.CapitalCreditAmount,
         "@JournalMemo", fixedAssetLedger.JournalMemo,
         "@Description", fixedAssetLedger.Description,
         "@RemainingLifeTime", fixedAssetLedger.RemainingLifeTime,
         "@EndYear", fixedAssetLedger.EndYear,
         "@FARefOrder", fixedAssetLedger.FARefOrder,
         "@FixedAssetOrder", fixedAssetLedger.FixedAssetOrder,
         "@Quantity", fixedAssetLedger.Quantity,
         "@DifferenceQuantity", fixedAssetLedger.DifferenceQuantity,
         "@FixedAssetCode", fixedAssetLedger.FixedAssetCode,
         "@FixedAssetName", fixedAssetLedger.FixedAssetName,
         "@DevaluationPeriod", fixedAssetLedger.DevaluationPeriod,
         "@DevaluationRate", fixedAssetLedger.DevaluationRate,
         "@PeriodDevaluationAmount", fixedAssetLedger.PeriodDevaluationAmount,
         "@DevaluationDebitAmount", fixedAssetLedger.DevaluationDebitAmount,
         "@DevaluationCreditAmount", fixedAssetLedger.DevaluationCreditAmount,
         "@RemainingDevaluationLifeTime", fixedAssetLedger.RemainingDevaluationLifeTime,
         "@EndDevaluationDate", fixedAssetLedger.EndDevaluationDate,
         "@DevaluationAmount", fixedAssetLedger.DevaluationAmount,
         "@DecreaseReasonID", fixedAssetLedger.DecreaseReasonId,
     });
 }
 /// <summary>
 /// Takes the specified fixed asset ledger.
 /// </summary>
 /// <param name="fixedAssetLedger">The fixed asset ledger.</param>
 /// <returns></returns>
 private static object[] Take(FixedAssetLedgerEntity fixedAssetLedger)
 {
     return(new object[]
     {
         "@FixedAssetLedgerID", fixedAssetLedger.FixedAssetLedgerId,
         "@RefID", fixedAssetLedger.RefId,
         "@RefTypeID", fixedAssetLedger.RefTypeId,
         "@RefNo", fixedAssetLedger.RefNo,
         "@RefDate", fixedAssetLedger.RefDate,
         "@PostedDate", fixedAssetLedger.PostedDate,
         "@FixedAssetID", fixedAssetLedger.FixedAssetId,
         "@DepartmentID", fixedAssetLedger.DepartmentId,
         "@LifeTime", fixedAssetLedger.LifeTime,
         "@CurrencyCode", fixedAssetLedger.CurrencyCode,
         "@AnnualDepreciationRate", fixedAssetLedger.AnnualDepreciationRate,
         "@AnnualDepreciationAmount", fixedAssetLedger.AnnualDepreciationAmount,
         "@ExchangeRate", fixedAssetLedger.ExchangeRate,
         "@OrgPriceAccount", fixedAssetLedger.OrgPriceAccount,
         "@OrgPriceDebitAmount", fixedAssetLedger.OrgPriceDebitAmount,
         "@OrgPriceCreditAmount", fixedAssetLedger.OrgPriceCreditAmount,
         "@OrgPriceDebitAmountExchange", fixedAssetLedger.OrgPriceDebitAmountExchange,
         "@OrgPriceCreditAmountExchange", fixedAssetLedger.OrgPriceCreditAmountExchange,
         "@DepreciationAccount", fixedAssetLedger.DepreciationAccount,
         "@DepreciationDebitAmount", fixedAssetLedger.DepreciationDebitAmount,
         "@DepreciationCreditAmount", fixedAssetLedger.DepreciationCreditAmount,
         "@DepreciationDebitAmountExchange", fixedAssetLedger.DepreciationDebitAmountExchange,
         "@DepreciationCreditAmountExchange", fixedAssetLedger.DepreciationCreditAmountExchange,
         "@BudgetSourceAccount", fixedAssetLedger.BudgetSourceAccount,
         "@BudgetSourcelDebitAmount", fixedAssetLedger.BudgetSourcelDebitAmount,
         "@BudgetSourceCreditAmount", fixedAssetLedger.BudgetSourceCreditAmount,
         "@BudgetSourcelDebitAmountExchange", fixedAssetLedger.BudgetSourcelDebitAmountExchange,
         "@BudgetSourceCreditAmountExchange", fixedAssetLedger.BudgetSourceCreditAmountExchange,
         "@JournalMemo", fixedAssetLedger.JournalMemo,
         "@Description", fixedAssetLedger.Description,
         "Quantity", fixedAssetLedger.Quantity
     });
 }
 /// <summary>
 /// Adds the fixed asset ledger entity.
 /// </summary>
 /// <param name="fAArmortizationDetail">The f a armortization detail.</param>
 /// <param name="fixedAssetLedger">The fixed asset ledger.</param>
 /// <returns></returns>
 private static FixedAssetLedgerEntity AddFixedAssetLedgerEntity(FAArmortizationDetailEntity fAArmortizationDetail, FixedAssetLedgerEntity fixedAssetLedger)
 {
     if (fAArmortizationDetail.AccountNumber.Contains("366"))
     {
         fixedAssetLedger.BudgetSourceAccount = fAArmortizationDetail.AccountNumber;
         fixedAssetLedger.ExchangeRate        = (decimal)fAArmortizationDetail.ExchangeRate;
         if (fAArmortizationDetail.CurrencyCode.Equals("USD"))
         {
             fixedAssetLedger.BudgetSourcelDebitAmount         += fAArmortizationDetail.AmountOC;
             fixedAssetLedger.BudgetSourcelDebitAmountExchange += fAArmortizationDetail.AmountOC;
         }
         else
         {
             fixedAssetLedger.BudgetSourcelDebitAmount         += fAArmortizationDetail.AmountOC;
             fixedAssetLedger.BudgetSourcelDebitAmountExchange += fAArmortizationDetail.AmountExchange;
         }
     }
     //if (fAArmortizationDetail.CorrespondingAccountNumber.Contains("2141") || fAArmortizationDetail.CorrespondingAccountNumber.Contains("2143"))
     if (fAArmortizationDetail.CorrespondingAccountNumber.Contains("2141") || fAArmortizationDetail.CorrespondingAccountNumber.Contains("2142")) // thông tư mới lấy đầu 2141 và 2142
     {
         fixedAssetLedger.DepreciationAccount = fAArmortizationDetail.CorrespondingAccountNumber;
         if (fAArmortizationDetail.CurrencyCode.Equals("USD"))
         {
             fixedAssetLedger.DepreciationCreditAmount         += fAArmortizationDetail.AmountOC;
             fixedAssetLedger.DepreciationCreditAmountExchange += fAArmortizationDetail.AmountOC;
         }
         else
         {
             fixedAssetLedger.DepreciationCreditAmount         += fAArmortizationDetail.AmountOC;
             fixedAssetLedger.DepreciationCreditAmountExchange += fAArmortizationDetail.AmountExchange;
         }
     }
     return(fixedAssetLedger);
 }
        /// <summary>
        /// Updates the opening account entry.
        /// </summary>
        /// <param name="openingFixedAssetEntryDetails">The opening account entry details.</param>
        /// <returns>OpeningAccountEntryReponse.</returns>
        public OpeningFixedAssetResponse UpdateOpeningFixedAssetEntry(
            IList <OpeningFixedAssetEntryEntity> openingFixedAssetEntryDetails)
        {
            var openingFixedAssetEntryResponse = new OpeningFixedAssetResponse {
                Acknowledge = AcknowledgeType.Success
            };

            using (var scope = new TransactionScope())
            {
                if (openingFixedAssetEntryDetails != null)
                {
                    //openingFixedAssetEntryResponse.Message = OpeningFixedAssetEntryDao.de(openingFixedAssetEntryDetails.First().RefId);
                    var fixedAssetEntity =
                        FixedAssetDao.GetFixedAssetById(openingFixedAssetEntryDetails.First().FixedAssetId);

                    //.Delete OpeningFixedEntry by FixedAssetId
                    AutoMapper(DeleteOpeningFixedAssetEntry(openingFixedAssetEntryDetails.First().FixedAssetId),
                               openingFixedAssetEntryResponse);
                    string  account              = "";
                    decimal orgAmount            = 0;
                    decimal orgAmountOC          = 0;
                    decimal depreciationAmount   = 0;
                    decimal depreciationAmountOC = 0;
                    decimal devaluationAmount    = 0;
                    var     generalLedgerEntity  = new List <FixedAssetLedgerEntity>();
                    //Xóa số dư đầu kỳ tài sản cố định trong bảng General Ledger

                    GeneralLedgerDao.DeleteGeneralLedger(openingFixedAssetEntryDetails.First().FixedAssetId);

                    //AnhNT: Xóa theo cách mới (phù hợp với kiểu lưu mới)
                    AutoMapper(
                        DeleteOriginalLedgerByReftypeRefNo(openingFixedAssetEntryDetails.First().RefType.ToString(),
                                                           openingFixedAssetEntryDetails.First().FixedAssetCode), openingFixedAssetEntryResponse);
                    //AnhNT: Xóa theo cách cũ (dành cho DB của khách hàng đang hoạt động)
                    AutoMapper(DeleteOriginalLedger(openingFixedAssetEntryDetails.First().FixedAssetId),
                               openingFixedAssetEntryResponse);

                    foreach (var openingFixedAssetEntry in openingFixedAssetEntryDetails)
                    {
                        if (string.IsNullOrEmpty(openingFixedAssetEntry.RefId))
                        {
                            openingFixedAssetEntry.RefId = Guid.NewGuid().ToString();
                        }
                        else
                        {
                            //openingFixedAssetEntry.RefId = Guid.NewGuid().ToString();
                            var fixedAssetLedger =
                                FixedAssetLedgerDao.GetFixedAssetLedgerByFixedAssetId(openingFixedAssetEntry.FixedAssetId,
                                                                                      openingFixedAssetEntry.RefType);

                            if (fixedAssetLedger != null)
                            {
                                AutoMapper(DeleteFixAssetLedger(fixedAssetLedger.RefId, openingFixedAssetEntry.RefType),
                                           openingFixedAssetEntryResponse);
                            }

                            //AutoMapper(DeleteGeneralLedger(openingFixedAssetEntry.RefId), openingFixedAssetEntryResponse);
                            //AutoMapper(DeleteOriginalLedger(openingFixedAssetEntry.RefId), openingFixedAssetEntryResponse);
                            //AutoMapper(DeleteOriginalLedger(openingFixedAssetEntry.RefId), openingFixedAssetEntryResponse);
                            //if (!string.IsNullOrEmpty(openingFixedAssetEntryResponse.Message))
                            //    goto Error;

                            AutoMapper(DeleteFixAssetLedger(openingFixedAssetEntry.RefId, openingFixedAssetEntry.RefType),
                                       openingFixedAssetEntryResponse);
                            if (!string.IsNullOrEmpty(openingFixedAssetEntryResponse.Message))
                            {
                                goto Error;
                            }


                            if (!openingFixedAssetEntry.Validate())
                            {
                                foreach (string error in openingFixedAssetEntry.ValidationErrors)
                                {
                                    openingFixedAssetEntryResponse.Message += error + Environment.NewLine;
                                }

                                openingFixedAssetEntryResponse.Acknowledge = AcknowledgeType.Failure;
                                return(openingFixedAssetEntryResponse);
                            }

                            openingFixedAssetEntryResponse.Message =
                                OpeningFixedAssetEntryDao.InsertOpeningFixedAssetEntry(openingFixedAssetEntry);
                            if (!string.IsNullOrEmpty(openingFixedAssetEntryResponse.Message))
                            {
                                openingFixedAssetEntryResponse.Acknowledge = AcknowledgeType.Failure;
                                return(openingFixedAssetEntryResponse);
                            }

                            #region Insert FixAsset Ledger

                            if (openingFixedAssetEntry.OrgPriceAccount != null)
                            {
                                if (account != openingFixedAssetEntry.FixedAssetId)
                                {
                                    orgAmount          = openingFixedAssetEntryDetails.Sum(c => c.OrgPriceDebitAmount);
                                    depreciationAmount = openingFixedAssetEntryDetails.Sum(c => c.DepreciationCreditAmount);
                                    devaluationAmount  = openingFixedAssetEntryDetails.Sum(c => c.DevaluationCreditAmount);
                                    var creditAccount = openingFixedAssetEntryDetails
                                                        .Where(c => c.DepreciationAccount != null).ToList();
                                    var orgAccount          = openingFixedAssetEntryDetails.First().OrgPriceAccount;
                                    var depreciationAccount = creditAccount.First().DepreciationAccount;

                                    var voucher = new FixedAssetLedgerEntity
                                    {
                                        FixedAssetLedgerId = Guid.NewGuid().ToString(),
                                        RefId                    = openingFixedAssetEntry.FixedAssetId,
                                        RefType                  = openingFixedAssetEntry.RefType,
                                        RefNo                    = "OPN",
                                        RefDate                  = openingFixedAssetEntry.PostedDate,
                                        PostedDate               = openingFixedAssetEntry.PostedDate,
                                        FixedAssetId             = openingFixedAssetEntry.FixedAssetId,
                                        DepartmentId             = openingFixedAssetEntry.DepartmentId,
                                        LifeTime                 = fixedAssetEntity.LifeTime,
                                        AnnualDepreciationRate   = fixedAssetEntity.DepreciationRate,
                                        AnnualDepreciationAmount = fixedAssetEntity.PeriodDepreciationAmount,
                                        OrgPriceAccount          = orgAccount,
                                        OrgPriceDebitAmount      = orgAmount,
                                        OrgPriceCreditAmount     = 0,
                                        DepreciationAccount      = depreciationAccount,
                                        DepreciationDebitAmount  = 0,
                                        DepreciationCreditAmount = depreciationAmount, //openingFixedAssetEntry.DepreciationCreditAmount, //depreciationAmount,
                                        CapitalAccount           = null,
                                        CapitalDebitAmount       = 0,
                                        CapitalCreditAmount      = 0,
                                        JournalMemo              = @"Dư đầu kỳ tài sản " + fixedAssetEntity.FixedAssetCode,
                                        Description              = @"Dư đầu kỳ tài sản " + fixedAssetEntity.FixedAssetCode,
                                        RemainingLifeTime        = fixedAssetEntity.RemainingLifeTime,
                                        EndYear                  = fixedAssetEntity.EndYear,
                                        DevaluationDebitAmount   = 0,
                                        DevaluationCreditAmount  = devaluationAmount, //openingFixedAssetEntry.DevaluationCreditAmount,
                                        DevaluationAmount        = fixedAssetEntity.DevaluationAmount,
                                        DevaluationPeriod        = fixedAssetEntity.DevaluationPeriod,
                                        EndDevaluationDate       =
                                            fixedAssetEntity.EndDevaluationDate == new DateTime(0001, 01, 01)
                                                ? fixedAssetEntity.DevaluationDate.AddMonths(
                                                (int)fixedAssetEntity.DevaluationLifeTime)
                                                : fixedAssetEntity.EndDevaluationDate,
                                        PeriodDevaluationAmount = fixedAssetEntity.PeriodDevaluationAmount,
                                        Quantity = fixedAssetEntity.Quantity,
                                    };
                                    account = openingFixedAssetEntry.FixedAssetId;
                                    generalLedgerEntity.Add(voucher);
                                }
                            }

                            #region Insert OriginalLedger

                            if (!string.IsNullOrEmpty(openingFixedAssetEntryResponse.Message))
                            {
                                goto Error;
                            }
                            AutoMapper(InsertOriginalLedger(openingFixedAssetEntry), openingFixedAssetEntryResponse);
                            if (!string.IsNullOrEmpty(openingFixedAssetEntryResponse.Message))
                            {
                                openingFixedAssetEntryResponse.Acknowledge = AcknowledgeType.Failure;
                                return(openingFixedAssetEntryResponse);
                            }

                            #endregion
                        }

                        #endregion

                        #region Insert General Ledger

                        AutoMapper(InsertGeneralLedger(openingFixedAssetEntry), openingFixedAssetEntryResponse);
                        if (!string.IsNullOrEmpty(openingFixedAssetEntryResponse.Message))
                        {
                            openingFixedAssetEntryResponse.Acknowledge = AcknowledgeType.Failure;
                            return(openingFixedAssetEntryResponse);
                        }

                        #endregion
                    }

                    #region Insert FixAsset Ledger

                    foreach (var item in generalLedgerEntity)
                    {
                        var voucher = new FixedAssetLedgerEntity
                        {
                            FixedAssetLedgerId = item.FixedAssetLedgerId,
                            RefId                    = item.RefId,
                            RefType                  = item.RefType,
                            RefNo                    = item.RefNo,
                            RefDate                  = item.PostedDate,
                            PostedDate               = item.PostedDate,
                            FixedAssetId             = item.FixedAssetId,
                            DepartmentId             = item.DepartmentId,
                            LifeTime                 = item.LifeTime,
                            AnnualDepreciationRate   = item.AnnualDepreciationRate,
                            AnnualDepreciationAmount = item.AnnualDepreciationAmount,
                            OrgPriceAccount          = item.OrgPriceAccount,
                            OrgPriceDebitAmount      = item.OrgPriceDebitAmount,
                            OrgPriceCreditAmount     = item.OrgPriceCreditAmount,
                            DepreciationAccount      = item.DepreciationAccount,
                            DepreciationDebitAmount  = item.DepreciationDebitAmount,
                            DepreciationCreditAmount = item.DepreciationCreditAmount,
                            CapitalAccount           = item.CapitalAccount,
                            CapitalDebitAmount       = item.CapitalDebitAmount,
                            CapitalCreditAmount      = item.CapitalCreditAmount,
                            JournalMemo              = item.JournalMemo,
                            Description              = item.Description,
                            RemainingLifeTime        = item.RemainingLifeTime,
                            EndYear                  = item.EndYear,
                            DevaluationDebitAmount   = item.DevaluationDebitAmount,
                            DevaluationCreditAmount  = item.DevaluationCreditAmount,
                            DevaluationAmount        = item.DevaluationAmount,
                            DevaluationPeriod        = item.DevaluationPeriod,
                            EndDevaluationDate       = item.EndDevaluationDate,
                            PeriodDevaluationAmount  = item.PeriodDevaluationAmount,
                            Quantity                 = item.Quantity
                        };

                        openingFixedAssetEntryResponse.Message = FixedAssetLedgerDao.InsertFixedAssetLedger(voucher);
                        if (!string.IsNullOrEmpty(openingFixedAssetEntryResponse.Message))
                        {
                            openingFixedAssetEntryResponse.Acknowledge = AcknowledgeType.Failure;
                            return(openingFixedAssetEntryResponse);
                        }
                    }

                    #endregion

Error:
                    if (!string.IsNullOrEmpty(openingFixedAssetEntryResponse.Message))
                    {
                        openingFixedAssetEntryResponse.RefId       = openingFixedAssetEntryDetails.First().RefId;
                        openingFixedAssetEntryResponse.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(openingFixedAssetEntryResponse);
                    }
                    openingFixedAssetEntryResponse.RefId = openingFixedAssetEntryDetails.First().RefId;
                }
                scope.Complete();
            }
            return(openingFixedAssetEntryResponse);
        }
        /// <summary>
        /// Inserts the fixed asset ledger.
        /// </summary>
        /// <param name="fixedAssetLedger">The fixed asset ledger.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public int InsertFixedAssetLedger(FixedAssetLedgerEntity fixedAssetLedger)
        {
            const string sql = @"uspInsert_FixedAssetLedger";

            return(Db.Insert(sql, true, Take(fixedAssetLedger)));
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Updates the ba deposit.
        /// </summary>
        /// <param name="fAIncrementDecrementEntity">The b a deposit entity.</param>
        /// <returns></returns>
        public FAIncrementDecrementResponse UpdateFAIncrementDecrement(FAIncrementDecrementEntity fAIncrementDecrementEntity, bool isconvertDB)
        {
            var response = new FAIncrementDecrementResponse {
                Acknowledge = AcknowledgeType.Success
            };

            if (fAIncrementDecrementEntity != null && !fAIncrementDecrementEntity.Validate())
            {
                foreach (var error in fAIncrementDecrementEntity.ValidationErrors)
                {
                    response.Message += error + Environment.NewLine;
                }
                response.Acknowledge = AcknowledgeType.Failure;
                return(response);
            }

            using (var scope = new TransactionScope())
            {
                if (fAIncrementDecrementEntity != null)
                {
                    #region Master
                    var pUInvoiceByRefNo = FAIncrementDecrementDao.GetFAIncrementDecrementByRefNo(fAIncrementDecrementEntity.RefNo, fAIncrementDecrementEntity.PostedDate);
                    if (pUInvoiceByRefNo != null && !pUInvoiceByRefNo.RefId.Equals(fAIncrementDecrementEntity.RefId) && pUInvoiceByRefNo.PostedDate.Year == fAIncrementDecrementEntity.PostedDate.Year)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        response.Message     = string.Format("Số chứng từ \'{0}\' đã tồn tại!", fAIncrementDecrementEntity.RefNo);
                        return(response);
                    }
                    if (!isconvertDB)//Nếu là insert từ chứng từ
                    {
                        if (string.IsNullOrEmpty(fAIncrementDecrementEntity.RefId))
                        {
                            fAIncrementDecrementEntity.RefId = Guid.NewGuid().ToString();
                            response.Message =
                                FAIncrementDecrementDao.InsertFAIncrementDecrement(fAIncrementDecrementEntity);
                        }
                        else
                        {
                            // Xóa detail
                            response.Message =
                                FAIncrementDecrementDetailDao.DeleteFAIncrementDecrementDetailByRefId(
                                    fAIncrementDecrementEntity.RefId);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                goto Error;
                            }

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

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

                            AutoMapper(
                                DeleteFixAssetLedger(fAIncrementDecrementEntity.RefId,
                                                     fAIncrementDecrementEntity.RefType), response);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                goto Error;
                            }

                            response.Message =
                                FAIncrementDecrementDao.UpdateFAIncrementDecrement(fAIncrementDecrementEntity);
                        }
                    }
                    else//Nếu sử dụng chức năng convertDB
                    {
                        if (string.IsNullOrEmpty(fAIncrementDecrementEntity.RefId))
                        {
                            fAIncrementDecrementEntity.RefId = Guid.NewGuid().ToString();
                        }
                        response.Message =
                            FAIncrementDecrementDao.InsertFAIncrementDecrement(fAIncrementDecrementEntity);
                    }
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        goto Error;
                    }
                    #endregion

                    #region Detail
                    //Tạo biến để xác định tài sản đã có không insert vào FixedAssetLedger entity thành dòng mới
                    var fixedAssetId = "";
                    if (fAIncrementDecrementEntity.FAIncrementDecrementDetails != null && fAIncrementDecrementEntity.FAIncrementDecrementDetails.Count > 0)
                    {
                        foreach (FAIncrementDecrementDetailEntity entity in fAIncrementDecrementEntity.FAIncrementDecrementDetails)
                        {
                            entity.RefDetailId = Guid.NewGuid().ToString();
                            entity.RefId       = fAIncrementDecrementEntity.RefId;
                            response.Message   = FAIncrementDecrementDetailDao.InsertFAIncrementDecrementDetail(entity);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                goto Error;
                            }

                            #region General Ledger
                            AutoMapper(InsertGeneralLedger(entity, fAIncrementDecrementEntity), response);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                goto Error;
                            }
                            #endregion

                            #region Original Ledger
                            AutoMapper(InsertOriginalLedger(entity, fAIncrementDecrementEntity), response);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                goto Error;
                            }
                            #endregion

                            //#region FixedAsset Ledger
                            //AutoMapper(InsertFixAssetLedger(entity, fAIncrementDecrementEntity), pUInvoiceResponse);
                            //if (!string.IsNullOrEmpty(pUInvoiceResponse.Message))
                            //    goto Error;
                            //#endregion

                            #region Insert FixedAssetLedger
                            // insert bang GeneralLedger
                            //1 tài sản lưu thành 1 dòng, số tiền = tổng số tiền của các dòng cùng tài sản
                            if (entity.FixedAssetId != null)
                            {
                                var totalAmount = (from f in fAIncrementDecrementEntity.FAIncrementDecrementDetails where f.FixedAssetId == entity.FixedAssetId select f).ToList();
                                if (fixedAssetId != entity.FixedAssetId)
                                {
                                    //get fixedAssetInfo
                                    var fixedAssetEntity = FixedAssetDao.GetFixedAssetById(entity.FixedAssetId);

                                    var fixedAssetLedgerEntity = new FixedAssetLedgerEntity
                                    {
                                        FixedAssetLedgerId = Guid.NewGuid().ToString(),
                                        RefId                    = fAIncrementDecrementEntity.RefId,
                                        RefType                  = fAIncrementDecrementEntity.RefType,
                                        RefNo                    = fAIncrementDecrementEntity.RefNo,
                                        RefDate                  = fAIncrementDecrementEntity.RefDate,
                                        PostedDate               = fAIncrementDecrementEntity.PostedDate,
                                        FixedAssetId             = entity.FixedAssetId,
                                        DepartmentId             = entity.DepartmentId,
                                        LifeTime                 = fixedAssetEntity.LifeTime,
                                        AnnualDepreciationRate   = fixedAssetEntity.DepreciationRate,
                                        AnnualDepreciationAmount = fixedAssetEntity.PeriodDepreciationAmount,
                                        OrgPriceAccount          = null,
                                        OrgPriceDebitAmount      = entity.DebitAccount.StartsWith("211") || entity.DebitAccount.StartsWith("213") ? totalAmount.Select(c => c.Amount).Sum() : 0,
                                        OrgPriceCreditAmount     = entity.DebitAccount.StartsWith("211") || entity.DebitAccount.StartsWith("213") ? 0 : totalAmount.Select(c => c.Amount).Sum(),
                                        DepreciationAccount      = null,
                                        DepreciationDebitAmount  = entity.DebitAccount.StartsWith("214") ? entity.Amount * (100 - fixedAssetEntity.UsingRatio) / 100 : 0,
                                        DepreciationCreditAmount = entity.CreditAccount.StartsWith("214") ? entity.Amount * (100 - fixedAssetEntity.UsingRatio) / 100 : 0,
                                        CapitalAccount           = fixedAssetEntity.CapitalAccount,
                                        CapitalDebitAmount       = 0,
                                        CapitalCreditAmount      = 0,
                                        Quantity                 = (decimal)entity.Quantity,// fixedAssetEntity.Quantity,
                                        JournalMemo              = fAIncrementDecrementEntity.JournalMemo,
                                        Description              = entity.Description,
                                        RemainingLifeTime        = fixedAssetEntity.RemainingLifeTime,
                                        EndYear                  = fixedAssetEntity.EndYear,
                                        DevaluationAmount        = fixedAssetEntity.DevaluationAmount,
                                        DevaluationPeriod        = fixedAssetEntity.DevaluationPeriod,
                                        DevaluationDebitAmount   = entity.DebitAccount.StartsWith("214") ? entity.Amount * fixedAssetEntity.UsingRatio / 100 : 0,
                                        DevaluationCreditAmount  = entity.CreditAccount.StartsWith("214") ? entity.Amount * fixedAssetEntity.UsingRatio / 100 : 0,
                                        EndDevaluationDate       = fixedAssetEntity.EndDevaluationDate == new DateTime(0001, 01, 01) ? fixedAssetEntity.DevaluationDate.AddMonths((int)fixedAssetEntity.DevaluationLifeTime) : fixedAssetEntity.EndDevaluationDate,
                                        PeriodDevaluationAmount  = fixedAssetEntity.PeriodDevaluationAmount,
                                    };

                                    response.Message = FixedAssetLedgerDao.InsertFixedAssetLedger(fixedAssetLedgerEntity);
                                    if (!string.IsNullOrEmpty(response.Message))
                                    {
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        return(response);
                                    }
                                    fixedAssetId = entity.FixedAssetId;
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion

                    #region Error
Error:
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }
                    response.RefId = fAIncrementDecrementEntity.RefId;
                    scope.Complete();
                    #endregion
                }
                return(response);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Inserts the ba deposit.
        /// </summary>
        /// <param name="fAIncrementDecrementEntity">The b a deposit entity.</param>
        /// <returns></returns>
        public FAIncrementDecrementResponse InsertFAIncrementDecrement(
            FAIncrementDecrementEntity fAIncrementDecrementEntity)
        {
            var response = new FAIncrementDecrementResponse {
                Acknowledge = AcknowledgeType.Success
            };

            try
            {
                if (!fAIncrementDecrementEntity.Validate())
                {
                    foreach (var error in fAIncrementDecrementEntity.ValidationErrors)
                    {
                        response.Message += error + Environment.NewLine;
                    }
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }
                using (var scope = new TransactionScope())
                {
                    var fAIncrementDecrementByRefNo =
                        FAIncrementDecrementDao.GetFAIncrementDecrementByRefNo(fAIncrementDecrementEntity.RefNo, fAIncrementDecrementEntity.PostedDate);
                    if (fAIncrementDecrementByRefNo != null && fAIncrementDecrementByRefNo.PostedDate.Year == fAIncrementDecrementEntity.PostedDate.Year)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        response.Message     = "Mã chứng từ đã tồn tại!";
                        return(response);
                    }
                    fAIncrementDecrementEntity.RefId = Guid.NewGuid().ToString();
                    response.Message = FAIncrementDecrementDao.InsertFAIncrementDecrement(fAIncrementDecrementEntity);
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        return(response);
                    }

                    #region insert FAIncrementDecrementDetails

                    //Tạo biến để xác định tài sản đã có không insert vào FixedAssetLedger entity thành dòng mới
                    var fixedAssetId = "";
                    if (fAIncrementDecrementEntity.FAIncrementDecrementDetails != null)
                    {
                        foreach (var fAIncrementDecrementDetailEntity in fAIncrementDecrementEntity.FAIncrementDecrementDetails)
                        {
                            fAIncrementDecrementDetailEntity.RefDetailId = Guid.NewGuid().ToString();
                            fAIncrementDecrementDetailEntity.RefId       = fAIncrementDecrementEntity.RefId;
                            response.Message =
                                FAIncrementDecrementDetailDao.InsertFAIncrementDecrementDetail(fAIncrementDecrementDetailEntity);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                return(response);
                            }

                            #region insert bang GeneralLedger

                            if (fAIncrementDecrementDetailEntity.DebitAccount != null && fAIncrementDecrementDetailEntity.CreditAccount != null)
                            {
                                var generalLedgerEntity = new GeneralLedgerEntity
                                {
                                    RefType                    = fAIncrementDecrementEntity.RefType,
                                    RefNo                      = fAIncrementDecrementEntity.RefNo,
                                    ProjectId                  = fAIncrementDecrementDetailEntity.ProjectId,
                                    BudgetSourceId             = fAIncrementDecrementDetailEntity.BudgetSourceId,
                                    Description                = fAIncrementDecrementDetailEntity.Description,
                                    RefDetailId                = fAIncrementDecrementDetailEntity.RefDetailId,
                                    ExchangeRate               = 1,
                                    BudgetSubKindItemCode      = fAIncrementDecrementDetailEntity.BudgetSubKindItemCode,
                                    CurrencyCode               = "VND",
                                    BudgetKindItemCode         = fAIncrementDecrementDetailEntity.BudgetKindItemCode,
                                    RefId                      = fAIncrementDecrementEntity.RefId,
                                    PostedDate                 = fAIncrementDecrementEntity.PostedDate,
                                    BudgetItemCode             = fAIncrementDecrementDetailEntity.BudgetItemCode,
                                    ListItemId                 = fAIncrementDecrementDetailEntity.ListItemId,
                                    BudgetSubItemCode          = fAIncrementDecrementDetailEntity.BudgetSubItemCode,
                                    BudgetDetailItemCode       = fAIncrementDecrementDetailEntity.BudgetDetailItemCode,
                                    AccountNumber              = fAIncrementDecrementDetailEntity.DebitAccount,
                                    CorrespondingAccountNumber = fAIncrementDecrementDetailEntity.CreditAccount,
                                    DebitAmount                =
                                        fAIncrementDecrementDetailEntity.DebitAccount == null
                                            ? 0
                                            : fAIncrementDecrementDetailEntity.Amount,
                                    DebitAmountOC =
                                        fAIncrementDecrementDetailEntity.DebitAccount == null
                                            ? 0
                                            : fAIncrementDecrementDetailEntity.Amount,
                                    CreditAmount       = 0,
                                    CreditAmountOC     = 0,
                                    FundStructureId    = fAIncrementDecrementDetailEntity.FundStructureId,
                                    GeneralLedgerId    = Guid.NewGuid().ToString(),
                                    JournalMemo        = fAIncrementDecrementEntity.JournalMemo,
                                    RefDate            = fAIncrementDecrementEntity.RefDate,
                                    SortOrder          = fAIncrementDecrementDetailEntity.SortOrder,
                                    AccountingObjectId = fAIncrementDecrementDetailEntity.AccountingObjectId,
                                };
                                response.Message = GeneralLedgerDao.InsertGeneralLedger(generalLedgerEntity);
                                if (!string.IsNullOrEmpty(response.Message))
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    return(response);
                                }
                                generalLedgerEntity.GeneralLedgerId            = Guid.NewGuid().ToString();
                                generalLedgerEntity.AccountNumber              = fAIncrementDecrementDetailEntity.CreditAccount;
                                generalLedgerEntity.CorrespondingAccountNumber = fAIncrementDecrementDetailEntity.DebitAccount;
                                generalLedgerEntity.DebitAmount    = 0;
                                generalLedgerEntity.DebitAmountOC  = 0;
                                generalLedgerEntity.CreditAmount   = fAIncrementDecrementDetailEntity.Amount;
                                generalLedgerEntity.CreditAmountOC = fAIncrementDecrementDetailEntity.Amount;
                                response.Message = GeneralLedgerDao.InsertGeneralLedger(generalLedgerEntity);
                                if (!string.IsNullOrEmpty(response.Message))
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    return(response);
                                }
                            }
                            else
                            {
                                var generalLedgerEntity = new GeneralLedgerEntity
                                {
                                    RefType               = fAIncrementDecrementEntity.RefType,
                                    RefNo                 = fAIncrementDecrementEntity.RefNo,
                                    ProjectId             = fAIncrementDecrementDetailEntity.ProjectId,
                                    BudgetSourceId        = fAIncrementDecrementDetailEntity.BudgetSourceId,
                                    Description           = fAIncrementDecrementDetailEntity.Description,
                                    RefDetailId           = fAIncrementDecrementDetailEntity.RefDetailId,
                                    ExchangeRate          = 1,
                                    BudgetSubKindItemCode = fAIncrementDecrementDetailEntity.BudgetSubKindItemCode,
                                    CurrencyCode          = "VND",
                                    BudgetKindItemCode    = fAIncrementDecrementDetailEntity.BudgetKindItemCode,
                                    RefId                 = fAIncrementDecrementEntity.RefId,
                                    PostedDate            = fAIncrementDecrementEntity.PostedDate,
                                    BudgetItemCode        = fAIncrementDecrementDetailEntity.BudgetItemCode,
                                    ListItemId            = fAIncrementDecrementDetailEntity.ListItemId,
                                    BudgetSubItemCode     = fAIncrementDecrementDetailEntity.BudgetSubItemCode,
                                    BudgetDetailItemCode  = fAIncrementDecrementDetailEntity.BudgetDetailItemCode,
                                    AccountNumber         = fAIncrementDecrementDetailEntity.DebitAccount ?? fAIncrementDecrementDetailEntity.CreditAccount,
                                    DebitAmount           =
                                        fAIncrementDecrementDetailEntity.DebitAccount == null
                                            ? 0
                                            : fAIncrementDecrementDetailEntity.Amount,
                                    DebitAmountOC =
                                        fAIncrementDecrementDetailEntity.DebitAccount == null
                                            ? 0
                                            : fAIncrementDecrementDetailEntity.Amount,
                                    CreditAmount    = 0,
                                    CreditAmountOC  = 0,
                                    FundStructureId = fAIncrementDecrementDetailEntity.FundStructureId,
                                    GeneralLedgerId = Guid.NewGuid().ToString(),
                                    JournalMemo     = fAIncrementDecrementEntity.JournalMemo,
                                    RefDate         = fAIncrementDecrementEntity.RefDate,
                                    SortOrder       = fAIncrementDecrementDetailEntity.SortOrder
                                };
                                response.Message = GeneralLedgerDao.InsertGeneralLedger(generalLedgerEntity);
                                if (!string.IsNullOrEmpty(response.Message))
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    return(response);
                                }
                            }

                            #endregion

                            #region Insert FixedAssetLedger
                            // insert bang GeneralLedger
                            //1 tài sản lưu thành 1 dòng, số tiền = tổng số tiền của các dòng cùng tài sản
                            if (fAIncrementDecrementDetailEntity.FixedAssetId != null)
                            {
                                var totalAmount = (from f in fAIncrementDecrementEntity.FAIncrementDecrementDetails where f.FixedAssetId == fAIncrementDecrementDetailEntity.FixedAssetId select f).ToList();
                                if (fixedAssetId != fAIncrementDecrementDetailEntity.FixedAssetId)
                                {
                                    //get fixedAssetInfo
                                    var fixedAssetEntity = FixedAssetDao.GetFixedAssetById(fAIncrementDecrementDetailEntity.FixedAssetId);

                                    var fixedAssetLedgerEntity = new FixedAssetLedgerEntity
                                    {
                                        FixedAssetLedgerId = Guid.NewGuid().ToString(),
                                        RefId                    = fAIncrementDecrementEntity.RefId,
                                        RefType                  = fAIncrementDecrementEntity.RefType,
                                        RefNo                    = fAIncrementDecrementEntity.RefNo,
                                        RefDate                  = fAIncrementDecrementEntity.RefDate,
                                        PostedDate               = fAIncrementDecrementEntity.PostedDate,
                                        FixedAssetId             = fAIncrementDecrementDetailEntity.FixedAssetId,
                                        DepartmentId             = fAIncrementDecrementDetailEntity.DepartmentId,
                                        LifeTime                 = fixedAssetEntity.LifeTime,
                                        AnnualDepreciationRate   = fixedAssetEntity.DepreciationRate,
                                        AnnualDepreciationAmount = fixedAssetEntity.PeriodDepreciationAmount,
                                        OrgPriceAccount          = null,
                                        OrgPriceDebitAmount      = fAIncrementDecrementDetailEntity.DebitAccount.StartsWith("211") || fAIncrementDecrementDetailEntity.DebitAccount.StartsWith("213") ? totalAmount.Select(c => c.Amount).Sum() : 0,
                                        OrgPriceCreditAmount     = fAIncrementDecrementDetailEntity.DebitAccount.StartsWith("211") || fAIncrementDecrementDetailEntity.DebitAccount.StartsWith("213") ? 0 : totalAmount.Select(c => c.Amount).Sum(),
                                        DepreciationAccount      = null,
                                        DepreciationDebitAmount  = fAIncrementDecrementDetailEntity.DebitAccount.StartsWith("214") ? fixedAssetEntity.AccumDepreciationAmount + fixedAssetEntity.AccumDevaluationAmount : 0,
                                        DepreciationCreditAmount = fAIncrementDecrementDetailEntity.DebitAccount.StartsWith("214") ? 0 : fixedAssetEntity.AccumDepreciationAmount + fixedAssetEntity.AccumDevaluationAmount,
                                        CapitalAccount           = fixedAssetEntity.CapitalAccount,
                                        CapitalDebitAmount       = 0,
                                        CapitalCreditAmount      = 0,
                                        Quantity                 = (decimal)fAIncrementDecrementDetailEntity.Quantity,// fixedAssetEntity.Quantity,
                                        //Quantity = fixedAssetEntity.Quantity,
                                        JournalMemo             = fAIncrementDecrementEntity.JournalMemo,
                                        Description             = fAIncrementDecrementDetailEntity.Description,
                                        RemainingLifeTime       = fixedAssetEntity.RemainingLifeTime,
                                        EndYear                 = fixedAssetEntity.EndYear,
                                        DevaluationAmount       = fixedAssetEntity.DevaluationAmount,
                                        DevaluationPeriod       = fixedAssetEntity.DevaluationPeriod,
                                        EndDevaluationDate      = fixedAssetEntity.EndDevaluationDate == new DateTime(0001, 01, 01) ? fixedAssetEntity.DevaluationDate.AddMonths((int)fixedAssetEntity.DevaluationLifeTime) : fixedAssetEntity.EndDevaluationDate,
                                        PeriodDevaluationAmount = fixedAssetEntity.PeriodDevaluationAmount
                                    };

                                    response.Message = FixedAssetLedgerDao.InsertFixedAssetLedger(fixedAssetLedgerEntity);
                                    if (!string.IsNullOrEmpty(response.Message))
                                    {
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        return(response);
                                    }
                                    fixedAssetId = fAIncrementDecrementDetailEntity.FixedAssetId;
                                }
                            }
                            #endregion

                            #region Insert OriginalGeneralLedger
                            var originalGeneralLedgerEntity = new OriginalGeneralLedgerEntity
                            {
                                OriginalGeneralLedgerId = Guid.NewGuid().ToString(),
                                RefType               = fAIncrementDecrementEntity.RefType,
                                RefId                 = fAIncrementDecrementEntity.RefId,
                                JournalMemo           = fAIncrementDecrementEntity.JournalMemo,
                                RefDate               = fAIncrementDecrementEntity.RefDate,
                                RefNo                 = fAIncrementDecrementEntity.RefNo,
                                RefDetailId           = fAIncrementDecrementDetailEntity.RefDetailId,
                                OrgRefDate            = null,
                                OrgRefNo              = null,
                                AccountingObjectId    = fAIncrementDecrementDetailEntity.AccountingObjectId,
                                ActivityId            = fAIncrementDecrementDetailEntity.ActivityId,
                                Amount                = fAIncrementDecrementDetailEntity.Amount,
                                AmountOC              = fAIncrementDecrementDetailEntity.Amount,
                                Approved              = true,
                                BankId                = null,
                                BudgetChapterCode     = fAIncrementDecrementDetailEntity.BudgetChapterCode,
                                BudgetDetailItemCode  = fAIncrementDecrementDetailEntity.BudgetDetailItemCode,
                                BudgetItemCode        = fAIncrementDecrementDetailEntity.BudgetItemCode,
                                BudgetKindItemCode    = fAIncrementDecrementDetailEntity.BudgetKindItemCode,
                                BudgetSourceId        = fAIncrementDecrementDetailEntity.BudgetSourceId,
                                BudgetSubItemCode     = fAIncrementDecrementDetailEntity.BudgetSubItemCode,
                                BudgetSubKindItemCode = fAIncrementDecrementDetailEntity.BudgetSubKindItemCode,
                                CashWithDrawTypeId    = fAIncrementDecrementDetailEntity.CashWithDrawTypeId,
                                CreditAccount         = fAIncrementDecrementDetailEntity.CreditAccount,
                                DebitAccount          = fAIncrementDecrementDetailEntity.DebitAccount,
                                Description           = fAIncrementDecrementDetailEntity.Description,
                                FundStructureId       = fAIncrementDecrementDetailEntity.FundStructureId,
                                ProjectActivityId     = fAIncrementDecrementDetailEntity.ProjectActivityId,
                                MethodDistributeId    = fAIncrementDecrementDetailEntity.MethodDistributeId,
                                ProjectId             = fAIncrementDecrementDetailEntity.ProjectId,
                                ToBankId              = null,
                                SortOrder             = fAIncrementDecrementDetailEntity.SortOrder,
                                PostedDate            = fAIncrementDecrementEntity.PostedDate,

                                // Không có Currency trong db : mặc định VNĐ và 1
                                CurrencyCode = "VND",
                                ExchangeRate = 1,
                            };
                            response.Message = OriginalGeneralLedgerDao.InsertOriginalGeneralLedger(originalGeneralLedgerEntity);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                return(response);
                            }

                            #endregion
                        }
                    }

                    #endregion

                    scope.Complete();
                }
                response.RefId = fAIncrementDecrementEntity.RefId;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(response);
            }
        }