/// <summary>
        ///     Deletes the fAIncrementDecrement.
        /// </summary>
        /// <param name="fAIncrementDecrement">The fAIncrementDecrement.</param>
        /// <returns>
        ///     System.String.
        /// </returns>
        public string DeleteFAIncrementDecrement(FAIncrementDecrementEntity fAIncrementDecrement)
        {
            const string sql = @"uspDelete_FAIncrementDecrement";

            object[] parms = { "@RefID", fAIncrementDecrement.RefId };
            return(Db.Delete(sql, true, parms));
        }
        /// <summary>
        ///     Gets the fAIncrementDecrement by refdate and reftype.
        /// </summary>
        /// <param name="fAIncrementDecrement">The ob fAIncrementDecrement entity.</param>
        /// <returns></returns>
        public FAIncrementDecrementEntity GetFAIncrementDecrementByRefdateAndReftype(
            FAIncrementDecrementEntity fAIncrementDecrement)
        {
            const string procedures = @"uspGet_FAIncrementDecrement_ByRefdateAndReftype";

            object[] parms =
            {
                "@RefType", fAIncrementDecrement.RefType, "@RefDate", fAIncrementDecrement.RefDate, "@RefNo",
                fAIncrementDecrement.RefNo
            };
            return(Db.Read(procedures, true, Make, parms));
        }
 /// <summary>
 ///     Takes the specified s u increment decrement entity.
 /// </summary>
 /// <param name="fAIncrementDecrementEntity">The s u increment decrement entity.</param>
 /// <returns></returns>
 private static object[] Take(FAIncrementDecrementEntity fAIncrementDecrementEntity)
 {
     return(new object[]
     {
         "@RefID", fAIncrementDecrementEntity.RefId,
         "@RefType", fAIncrementDecrementEntity.RefType,
         "@RefDate", fAIncrementDecrementEntity.RefDate,
         "@PostedDate", fAIncrementDecrementEntity.PostedDate,
         "@RefNo", fAIncrementDecrementEntity.RefNo,
         "@ParalellRefNo", fAIncrementDecrementEntity.ParalellRefNo,
         "@JournalMemo", fAIncrementDecrementEntity.JournalMemo,
         "@TotalAmount", fAIncrementDecrementEntity.TotalAmount,
         "@GeneratedRefID", fAIncrementDecrementEntity.GeneratedRefId
     });
 }
        /// <summary>
        ///     Updates the fAIncrementDecrement.
        /// </summary>
        /// <param name="fAIncrementDecrement">The fAIncrementDecrement.</param>
        /// <returns>
        ///     System.String.
        /// </returns>
        public string UpdateFAIncrementDecrement(FAIncrementDecrementEntity fAIncrementDecrement)
        {
            const string sql = @"uspUpdate_FAIncrementDecrement";

            return(Db.Update(sql, true, Take(fAIncrementDecrement)));
        }
        /// <summary>
        ///     Inserts the fAIncrementDecrement.
        /// </summary>
        /// <param name="fAIncrementDecrement">The fAIncrementDecrement.</param>
        /// <returns>
        ///     System.Int32.
        /// </returns>
        public string InsertFAIncrementDecrement(FAIncrementDecrementEntity fAIncrementDecrement)
        {
            const string sql = @"uspInsert_FAIncrementDecrement";

            return(Db.Insert(sql, true, Take(fAIncrementDecrement)));
        }
コード例 #6
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);
            }
        }
コード例 #7
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);
            }
        }
コード例 #8
0
        public List <FAIncrementDecrementEntity> GetFAIncrementDecrements(string connectionString)
        {
            List <FAIncrementDecrementEntity> buentity = new List <FAIncrementDecrementEntity>();

            using (var context = new MISAEntity(connectionString))
            {
                var querry   = context.FAIncrementDecrementDetails.ToList();
                var projects = context.Projects.ToList();
                //var currencys = context.CCies.ToList();
                var budgetsource = context.BudgetSources.ToList();
                var listitems    = context.ListItems.ToList();
                //var funds = context.Funds.ToList();
                var fundstructures = context.FundStructures.ToList();
                //var budgetproviders = context.BudgetProvidences.ToList();
                var accountingobject = context.AccountingObjects.ToList();
                var projectexpenses  = context.ProjectExpenses.ToList();
                var activity         = context.Activities.ToList();
                //var tasks = context.Tasks.ToList();
                //var topics = context.Topics.ToList();
                //banks = context.BankInfoes.ToList();
                var department    = context.Departments.ToList();
                var resultcontext = context.FAIncrementDecrements.ToList();
                var fixedasset    = context.FixedAssets.ToList();
                //Get CAReceipts
                var resultcontext2           = context.CAReceipts.Where(x => x.RefType == 103).ToList();
                var resultcontext2Fixedasset = context.CAReceiptDetailFixedAssets.ToList();
                //Get BADeposits
                var resultcontext3           = context.BADeposits.Where(x => x.RefType == 155).ToList();
                var resultcontext3Fixedasset = context.BADepositDetailFixedAssets.ToList();
                //Get SAInvoices
                var resultcontext4           = context.SAInvoices.Where(x => x.RefType == 256).ToList();
                var resultcontext4Fixedasset = context.SAInvoiceDetailFixedAssets.ToList();
                //var inventoryitems = context.InventoryItems.ToList();
                //var stocks = context.Stocks.ToList();
                #region Detail
                foreach (var result in resultcontext)
                {
                    var newresult = new FAIncrementDecrementEntity();
                    newresult.RefId          = result.RefID.ToString();
                    newresult.RefType        = ConvRefType.ConvRefType(result.RefType);
                    newresult.RefDate        = result.RefDate;
                    newresult.PostedDate     = result.PostedDate;
                    newresult.RefNo          = result.RefNo;
                    newresult.ParalellRefNo  = result.ParalellRefNo;
                    newresult.JournalMemo    = result.JournalMemo;
                    newresult.TotalAmount    = result.TotalAmount;
                    newresult.GeneratedRefId = result.GeneratedRefID.ToString();
                    newresult.FAIncrementDecrementDetails = result.FAIncrementDecrementDetails.Count <= 0 ? null : FAIncrementDecrementDetails(result.FAIncrementDecrementDetails.ToList(), result.RefID.ToString());
                    buentity.Add(newresult);
                }
                #endregion

                #region CAReceipts
                foreach (var result in resultcontext2)
                {
                    var newresult = new FAIncrementDecrementEntity();
                    newresult.RefId         = result.RefID.ToString();
                    newresult.RefType       = ConvRefType.ConvRefType(result.RefType);
                    newresult.RefDate       = result.RefDate;
                    newresult.PostedDate    = result.PostedDate;
                    newresult.RefNo         = result.RefNo;
                    newresult.ParalellRefNo = result.ParalellRefNo;
                    newresult.JournalMemo   = result.JournalMemo;
                    newresult.TotalAmount   = result.TotalAmount;
                    //newresult.GeneratedRefId = result.GeneratedRefID.ToString();
                    newresult.FAIncrementDecrementDetails = resultcontext2Fixedasset.Count <= 0 ? null : FAIncrementDecrementDetailsFromCAReceipt(resultcontext2Fixedasset, result.RefID.ToString());
                    buentity.Add(newresult);
                }
                #endregion

                #region BADeposits
                foreach (var result in resultcontext3)
                {
                    var newresult = new FAIncrementDecrementEntity();
                    newresult.RefId         = result.RefID.ToString();
                    newresult.RefType       = ConvRefType.ConvRefType(result.RefType);
                    newresult.RefDate       = result.RefDate;
                    newresult.PostedDate    = result.PostedDate;
                    newresult.RefNo         = result.RefNo;
                    newresult.ParalellRefNo = result.ParalellRefNo;
                    newresult.JournalMemo   = result.JournalMemo;
                    newresult.TotalAmount   = result.TotalAmount;
                    //newresult.GeneratedRefId = result.GeneratedRefID.ToString();
                    newresult.FAIncrementDecrementDetails = resultcontext3Fixedasset.Count <= 0 ? null : FAIncrementDecrementDetailsFromBADeposits(resultcontext3Fixedasset, result.RefID.ToString());
                    buentity.Add(newresult);
                }
                #endregion

                #region SAInvoices
                foreach (var result in resultcontext4)
                {
                    var newresult = new FAIncrementDecrementEntity();
                    newresult.RefId         = result.RefID.ToString();
                    newresult.RefType       = ConvRefType.ConvRefType(result.RefType);
                    newresult.RefDate       = result.RefDate;
                    newresult.PostedDate    = result.PostedDate;
                    newresult.RefNo         = result.RefNo;
                    newresult.ParalellRefNo = result.ParalellRefNo;
                    newresult.JournalMemo   = result.JournalMemo;
                    newresult.TotalAmount   = result.TotalAmount;
                    //newresult.GeneratedRefId = result.GeneratedRefID.ToString();
                    newresult.FAIncrementDecrementDetails = resultcontext4Fixedasset.Count <= 0 ? null : FAIncrementDecrementDetailsFromSAInvoices(resultcontext4Fixedasset, result.RefID.ToString());
                    buentity.Add(newresult);
                }
                #endregion
            }
            return(buentity);
        }