/// <summary>
 /// Adds the account balance for credit.
 /// </summary>
 /// <param name="openingAccountEntryEntity">The opening account entry entity.</param>
 /// <param name="openingAccountEntryDetailEntityy">The opening account entry detail entityy.</param>
 /// <returns></returns>
 public AccountBalanceEntity AddAccountBalanceForCredit(OpeningAccountEntryEntity openingAccountEntryEntity,
                                                        OpeningAccountEntryDetailEntity openingAccountEntryDetailEntityy)
 {
     //credit account
     return(new AccountBalanceEntity
     {
         BalanceDate = openingAccountEntryEntity.PostedDate,
         CurrencyCode = openingAccountEntryDetailEntityy.CurrencyCode,
         ExchangeRate = (decimal)openingAccountEntryDetailEntityy.ExchangeRate,
         AccountNumber = openingAccountEntryEntity.AccountCode,
         MovementCreditAmountOC = openingAccountEntryDetailEntityy.CreditAmountOC,
         MovementCreditAmountExchange = openingAccountEntryDetailEntityy.CreditAmountExchange,
         BudgetSourceCode = openingAccountEntryDetailEntityy.BudgetSourceCode,
         BudgetItemCode = openingAccountEntryDetailEntityy.BudgetItemCode,
         CustomerId = openingAccountEntryDetailEntityy.CustomerId,
         VendorId = openingAccountEntryDetailEntityy.VendorId,
         EmployeeId = openingAccountEntryDetailEntityy.EmployeeId,
         AccountingObjectId = openingAccountEntryDetailEntityy.AccountingObjectId,
         MergerFundId = openingAccountEntryDetailEntityy.MergerFundId,
         BankId = openingAccountEntryDetailEntityy.BankId,
         ProjectId = openingAccountEntryDetailEntityy.ProjectId,
         //InventoryItemId = openingAccountEntryDetailEntityy.InventoryItemId,
         MovementDebitAmountOC = 0,
         MovementDebitAmountExchange = 0
     });
 }
Exemplo n.º 2
0
 /// <summary>
 /// Takes the specified opening account entry.
 /// </summary>
 /// <param name="openingAccountEntry">The opening account entry.</param>
 /// <returns></returns>
 private static object[] Take(OpeningAccountEntryEntity openingAccountEntry)
 {
     return(new object[]
     {
         @"RefID", openingAccountEntry.RefId,
         @"RefTypeID", openingAccountEntry.RefTypeId,
         @"PostedDate", openingAccountEntry.PostedDate,
         @"AccountCode", openingAccountEntry.AccountCode,
         @"TotalAccountBeginningDebitAmountOC", openingAccountEntry.TotalAccountBeginningDebitAmountOC,
         @"TotalAccountBeginningCreditAmountOC", openingAccountEntry.TotalAccountBeginningCreditAmountOC,
         @"TotalDebitAmountOC", openingAccountEntry.TotalDebitAmountOC,
         @"TotalCreditAmountOC", openingAccountEntry.TotalCreditAmountOC,
         @"TotalAccountBeginningDebitAmountExchange", openingAccountEntry.TotalAccountBeginningDebitAmountExchange,
         @"TotalAccountBeginningCreditAmountExchange", openingAccountEntry.TotalAccountBeginningCreditAmountExchange,
         @"TotalDebitAmountExchange", openingAccountEntry.TotalDebitAmountExchange,
         @"TotalCreditAmountExchange", openingAccountEntry.TotalCreditAmountExchange
     });
 }
 /// <summary>
 /// Takes the specified opening account entry.
 /// </summary>
 /// <param name="openingAccountEntryEntity">The opening account entry.</param>
 /// <returns></returns>
 private static object[] Take(OpeningAccountEntryEntity openingAccountEntryEntity)
 {
     return(new object[]
     {
         "@RefID", openingAccountEntryEntity.RefId,
         "@RefType", openingAccountEntryEntity.RefType,
         "@PostedDate", openingAccountEntryEntity.PostedDate,
         "@CurrencyID", openingAccountEntryEntity.CurrencyId,
         "@ExchangeRate", openingAccountEntryEntity.ExchangeRate,
         "@AccountNumber", openingAccountEntryEntity.AccountNumber,
         "@AccBeginningDebitAmountOC", openingAccountEntryEntity.AccBeginningDebitAmountOC,
         "@AccBeginningDebitAmount", openingAccountEntryEntity.AccBeginningDebitAmount,
         "@AccBeginningCreditAmountOC", openingAccountEntryEntity.AccBeginningCreditAmountOC,
         "@AccBeginningCreditAmount", openingAccountEntryEntity.AccBeginningCreditAmount,
         "@DebitAmountOC", openingAccountEntryEntity.DebitAmountOC,
         "@DebitAmount", openingAccountEntryEntity.DebitAmount,
         "@CreditAmountOC", openingAccountEntryEntity.CreditAmountOC,
         "@CreditAmount", openingAccountEntryEntity.CreditAmount,
         "@BudgetSourceId", openingAccountEntryEntity.BudgetSourceId,
         "@BudgetChapterCode", openingAccountEntryEntity.BudgetChapterCode,
         "@BudgetKindItemCode", openingAccountEntryEntity.BudgetKindItemCode,
         "@BudgetSubKindItemCode", openingAccountEntryEntity.BudgetSubKindItemCode,
         "@BudgetItemCode", openingAccountEntryEntity.BudgetItemCode,
         "@BudgetSubItemCode", openingAccountEntryEntity.BudgetSubItemCode,
         "@MethodDistributeId", openingAccountEntryEntity.MethodDistributeId,
         "@CashWithdrawTypeId", openingAccountEntryEntity.CashWithdrawTypeId,
         "@AccountingObjectId", openingAccountEntryEntity.AccountingObjectId,
         "@ActivityId", openingAccountEntryEntity.ActivityId,
         "@ProjectId", openingAccountEntryEntity.ProjectId,
         "@TaskId", openingAccountEntryEntity.TaskId,
         "@BankId", openingAccountEntryEntity.BankId,
         "@Approved", openingAccountEntryEntity.Approved,
         "@SortOrder", openingAccountEntryEntity.SortOrder,
         "@BudgetDetailItemCode", openingAccountEntryEntity.BudgetDetailItemCode,
         "@ProjectActivityId", openingAccountEntryEntity.ProjectActivityId,
         "@ApprovedDate", openingAccountEntryEntity.ApprovedDate,
         "@FundStructureId", openingAccountEntryEntity.FundStructureId,
         "@ProjectActivityEAID", openingAccountEntryEntity.ProjectActivityEAID,
         "@BudgetProvideCode", openingAccountEntryEntity.BudgetProvideCode,
         "@BudgetExpenseID", openingAccountEntryEntity.BudgetExpenseId,
         "@ContractID", openingAccountEntryEntity.ContractId,
         "@CapitalPlanID", openingAccountEntryEntity.CapitalPlanId,
     });
 }
        /// <summary>
        /// Updates the account balance.
        /// </summary>
        /// <param name="openingAccountEntryEntity">The opening account entry entity.</param>
        /// <param name="balanceSide">The balance side.</param>
        /// <returns></returns>
        public string UpdateAccountBalance(OpeningAccountEntryEntity openingAccountEntryEntity, int balanceSide)
        {
            var openingAccountEntryDetails = OpeningAccountEntryDetailDao.GetOpeningAccountEntryDetailsByRefId(openingAccountEntryEntity.RefId);

            foreach (var openingAccountEntryDetail in openingAccountEntryDetails)
            {
                string message;
                switch (balanceSide)
                {
                case 0:
                    var accountBalanceForDebit     = AddAccountBalanceForDebit(openingAccountEntryEntity, openingAccountEntryDetail);
                    var accountBalanceForDebitExit = AccountBalanceDao.GetExitsAccountBalance(accountBalanceForDebit);
                    if (accountBalanceForDebitExit != null)
                    {
                        message = UpdateAccountBalance(accountBalanceForDebitExit, accountBalanceForDebit.MovementDebitAmountOC,
                                                       accountBalanceForDebit.MovementDebitAmountExchange, false, 1);
                        if (message != null)
                        {
                            return(message);
                        }
                    }
                    break;

                case 1:
                    var accountBalanceForCredit     = AddAccountBalanceForCredit(openingAccountEntryEntity, openingAccountEntryDetail);
                    var accountBalanceForCreditExit = AccountBalanceDao.GetExitsAccountBalance(accountBalanceForCredit);
                    if (accountBalanceForCreditExit != null)
                    {
                        message = UpdateAccountBalance(accountBalanceForCreditExit, accountBalanceForCredit.MovementCreditAmountOC,
                                                       accountBalanceForCredit.MovementCreditAmountExchange, false, 2);
                        if (message != null)
                        {
                            return(message);
                        }
                    }
                    break;

                case 2:
                    break;
                }
            }
            return(null);
        }
        /// <summary>
        /// Inserts the account balance.
        /// </summary>
        /// <param name="openingAccountEntryEntity">The opening account entry entity.</param>
        /// <param name="openingAccountEntryDetailEntity">The opening account entry detail entity.</param>
        /// <param name="balanceSide">The balance side.</param>
        public void InsertAccountBalance(OpeningAccountEntryEntity openingAccountEntryEntity, OpeningAccountEntryDetailEntity openingAccountEntryDetailEntity,
                                         int balanceSide)
        {
            //check balance side

            switch (balanceSide)
            {
            case 0:     //ben no
                var accountBalanceForDebit     = AddAccountBalanceForDebit(openingAccountEntryEntity, openingAccountEntryDetailEntity);
                var accountBalanceForDebitExit = AccountBalanceDao.GetExitsAccountBalance(accountBalanceForDebit);
                if (accountBalanceForDebitExit != null)
                {
                    UpdateAccountBalance(accountBalanceForDebitExit, accountBalanceForDebit.MovementDebitAmountOC,
                                         accountBalanceForDebit.MovementDebitAmountExchange, true, 1);
                }
                else
                {
                    AccountBalanceDao.InsertAccountBalance(accountBalanceForDebit);
                }
                break;

            case 1:     //ben co
                var accountBalanceForCredit     = AddAccountBalanceForCredit(openingAccountEntryEntity, openingAccountEntryDetailEntity);
                var accountBalanceForCreditExit = AccountBalanceDao.GetExitsAccountBalance(accountBalanceForCredit);
                if (accountBalanceForCreditExit != null)
                {
                    UpdateAccountBalance(accountBalanceForCreditExit, accountBalanceForCredit.MovementCreditAmountOC,
                                         accountBalanceForCredit.MovementCreditAmountExchange, true, 2);
                }
                else
                {
                    AccountBalanceDao.InsertAccountBalance(accountBalanceForCredit);
                }
                break;

            case 2:
                if (openingAccountEntryDetailEntity.DebitAmountOC == 0)
                {
                    accountBalanceForCredit     = AddAccountBalanceForCredit(openingAccountEntryEntity, openingAccountEntryDetailEntity);
                    accountBalanceForCreditExit = AccountBalanceDao.GetExitsAccountBalance(accountBalanceForCredit);
                    if (accountBalanceForCreditExit != null)
                    {
                        UpdateAccountBalance(accountBalanceForCreditExit, accountBalanceForCredit.MovementCreditAmountOC,
                                             accountBalanceForCredit.MovementCreditAmountExchange, true, 2);
                    }
                    else
                    {
                        AccountBalanceDao.InsertAccountBalance(accountBalanceForCredit);
                    }
                }
                else
                {
                    accountBalanceForDebit     = AddAccountBalanceForDebit(openingAccountEntryEntity, openingAccountEntryDetailEntity);
                    accountBalanceForDebitExit = AccountBalanceDao.GetExitsAccountBalance(accountBalanceForDebit);
                    if (accountBalanceForDebitExit != null)
                    {
                        UpdateAccountBalance(accountBalanceForDebitExit, accountBalanceForDebit.MovementDebitAmountOC,
                                             accountBalanceForDebit.MovementDebitAmountExchange, true, 1);
                    }
                    else
                    {
                        AccountBalanceDao.InsertAccountBalance(accountBalanceForDebit);
                    }
                }
                break;     //luong tinh
            }
        }
        /// <summary>
        /// Adds the journal entry account.
        /// </summary>
        /// <param name="openingAccountEntryEntity">The opening account entry entity.</param>
        /// <param name="openingAccountEntryDetailEntity">The opening account entry detail entity.</param>
        /// <param name="balanceSide">The balance side.</param>
        /// <returns></returns>
        public JournalEntryAccountEntity AddJournalEntryAccount(OpeningAccountEntryEntity openingAccountEntryEntity,
                                                                OpeningAccountEntryDetailEntity openingAccountEntryDetailEntity, int balanceSide)
        {
            decimal amountOC;
            decimal amountExchange;
            int     journalType;

            switch (balanceSide)
            {
            case 0:
                amountOC       = openingAccountEntryDetailEntity.DebitAmountOC;
                amountExchange = openingAccountEntryDetailEntity.DebitAmountExchange;
                journalType    = 1;
                break;

            case 1:
                amountOC       = openingAccountEntryDetailEntity.CreditAmountOC * (-1);
                amountExchange = openingAccountEntryDetailEntity.CreditAmountExchange * (-1);
                journalType    = 2;
                break;

            default:
                if (openingAccountEntryDetailEntity.DebitAmountOC > openingAccountEntryDetailEntity.CreditAmountOC)
                {
                    amountOC       = Math.Abs(openingAccountEntryDetailEntity.DebitAmountOC - openingAccountEntryDetailEntity.CreditAmountOC);
                    amountExchange = Math.Abs(openingAccountEntryDetailEntity.DebitAmountExchange - openingAccountEntryDetailEntity.CreditAmountExchange);
                    journalType    = 1;
                }
                else
                {
                    amountOC       = openingAccountEntryDetailEntity.DebitAmountOC - openingAccountEntryDetailEntity.CreditAmountOC;
                    amountExchange = openingAccountEntryDetailEntity.DebitAmountExchange - openingAccountEntryDetailEntity.CreditAmountExchange;
                    journalType    = 2;
                }
                break;
            }
            return(new JournalEntryAccountEntity
            {
                RefId = openingAccountEntryEntity.RefId,
                RefTypeId = openingAccountEntryEntity.RefTypeId,
                RefNo = "OPN",
                RefDate = openingAccountEntryEntity.PostedDate,
                PostedDate = openingAccountEntryEntity.PostedDate,
                JournalMemo = null,
                CurrencyCode = openingAccountEntryDetailEntity.CurrencyCode,
                ExchangeRate = (decimal)openingAccountEntryDetailEntity.ExchangeRate,
                BankAccount = null,
                RefDetailId = openingAccountEntryDetailEntity.RefDetailId,
                AccountNumber = openingAccountEntryEntity.AccountCode,
                CorrespondingAccountNumber = null,
                AmountOc = amountOC,
                BankId = openingAccountEntryDetailEntity.BankId,
                Description = null,
                JournalType = journalType,
                AmountExchange = amountExchange,
                BudgetSourceCode = openingAccountEntryDetailEntity.BudgetSourceCode,
                BudgetItemCode = openingAccountEntryDetailEntity.BudgetItemCode,
                AccountingObjectId = openingAccountEntryDetailEntity.AccountingObjectId,
                EmployeeId = openingAccountEntryDetailEntity.EmployeeId,
                CustomerId = openingAccountEntryDetailEntity.CustomerId,
                VendorId = openingAccountEntryDetailEntity.VendorId,
                MergerFundId = openingAccountEntryDetailEntity.MergerFundId,
                VoucherTypeId = null,
                ProjectId = openingAccountEntryDetailEntity.ProjectId
            });
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sets the opening account entries.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public OpeningInventoryEntryResponse SetOpeningInventoryEntries(OpeningInventoryEntryRequest request)
        {
            OpeningInventoryEntryEntity inventoryEntryEntity = new OpeningInventoryEntryEntity();
            var    response                = new OpeningInventoryEntryResponse();
            string accountNumber           = "";
            var    openingInventoryEntries = request.OpeningInventoryEntries;

            //var auditingLog = new AudittingLogEntity { ComponentName = "SO DU DAU KY CCDC", EventAction = (int)request.Action };
            if (request.Action != PersistType.Delete)
            {
                foreach (var openingInventoryEntryEntity in openingInventoryEntries)
                {
                    inventoryEntryEntity = openingInventoryEntryEntity;
                    accountNumber        = openingInventoryEntryEntity.AccountNumber;
                    if (!openingInventoryEntryEntity.Validate())
                    {
                        foreach (var error in openingInventoryEntryEntity.ValidationErrors)
                        {
                            response.Message += error + Environment.NewLine;
                        }
                        response.Acknowledge = AcknowledgeType.Failure;
                        return(response);
                    }
                }
            }
            try
            {
                switch (request.Action)
                {
                case PersistType.Insert:
                    break;

                case PersistType.Update:
                    using (var scope = new TransactionScope())
                    {
                        if (openingInventoryEntries[0].RefTypeId != 8888)
                        {
                            response.Message =
                                JournalEntryAccountDao.DeleteJournalEntryAccountByPostedDateAndRefType(
                                    openingInventoryEntries[0].PostedDate, openingInventoryEntries[0].RefTypeId);
                            if (response.Message != null)
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                scope.Dispose();
                                return(response);
                            }



                            //  var dtPostedDate = openingInventoryEntries[0].PostedDate;
                            //Delete trong bảng JourentryAccount

                            //insert or update master openingAccountEntry
                            var account = AccountDao.GetAccountByAccountCode(accountNumber);
                            var openingAccountEntryForUpdate = OpeningAccountEntryDao.GetOpeningAccountEntryEntityByAccountCode(account.AccountCode);
                            #region
                            if (openingAccountEntryForUpdate != null)
                            {
                                openingAccountEntryForUpdate.TotalAccountBeginningDebitAmountOC  = 0;
                                openingAccountEntryForUpdate.TotalAccountBeginningCreditAmountOC = 0;
                                openingAccountEntryForUpdate.TotalDebitAmountOC  = 0;
                                openingAccountEntryForUpdate.TotalCreditAmountOC = 0;
                                openingAccountEntryForUpdate.TotalAccountBeginningDebitAmountExchange  = 0;
                                openingAccountEntryForUpdate.TotalAccountBeginningCreditAmountExchange = 0;
                                openingAccountEntryForUpdate.TotalDebitAmountExchange  = 0;
                                openingAccountEntryForUpdate.TotalCreditAmountExchange = 0;

                                foreach (var openingInventoryEntryEntity in openingInventoryEntries)//var openingAccountEntryDetailEntity in openingAccountEntry.OpeningAccountEntryDetails)
                                {
                                    openingAccountEntryForUpdate.TotalDebitAmountOC       += openingInventoryEntryEntity.AmountOc;
                                    openingAccountEntryForUpdate.TotalDebitAmountExchange += openingInventoryEntryEntity.AmountExchange;
                                }
                                response.Message = OpeningAccountEntryDao.UpdateOpeningAccountEntry(openingAccountEntryForUpdate);
                                if (response.Message != null)
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }
                                //    openingAccountEntry.RefId = openingAccountEntryForUpdate.RefId;
                            }
                            else
                            {
                                OpeningAccountEntryEntity openingAccountEntry = new OpeningAccountEntryEntity()
                                {
                                    AccountCode = accountNumber,
                                    AccountId   = inventoryEntryEntity.AccountId,
                                    AccountName = inventoryEntryEntity.AccountName,
                                    ParentId    = inventoryEntryEntity.ParentId,
                                    PostedDate  = inventoryEntryEntity.PostedDate,
                                    RefId       = 0,
                                    RefNo       = inventoryEntryEntity.RefNo,
                                    RefTypeId   = 700,
                                };
                                foreach (var openingInventoryEntryEntity in openingInventoryEntries)//var openingAccountEntryDetailEntity in openingAccountEntry.OpeningAccountEntryDetails)
                                {
                                    openingAccountEntry.TotalDebitAmountOC       += openingInventoryEntryEntity.AmountOc;
                                    openingAccountEntry.TotalDebitAmountExchange += openingInventoryEntryEntity.AmountExchange;
                                }
                                openingAccountEntry.RefId = OpeningAccountEntryDao.InsertOpeningAccountEntry(openingAccountEntry);
                                if (openingAccountEntry.RefId == 0)
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }
                            }
                            #endregion


                            //Xoa het
                            foreach (var openingInventoryEntryEntity in openingInventoryEntries)
                            {
                                var openingInventoryEntryForUpdate = OpeningInventoryEntryDao.GetOpeningInventoryEntryEntityByAccountCodeForMaster(openingInventoryEntryEntity.AccountNumber);
                                if (openingInventoryEntryForUpdate != null)
                                {
                                    response.Message = OpeningInventoryEntryDao.DeleteOpeningInventoryEntryByAccountCode(openingInventoryEntryForUpdate);
                                    response.Message = JournalEntryAccountDao.DeleteJournalEntryAccount(openingInventoryEntryForUpdate.RefId, openingInventoryEntryForUpdate.RefTypeId);
                                }
                            }

                            foreach (var openingInventoryEntryEntity in openingInventoryEntries)
                            {
                                //insert or update master
                                var openingInventoryEntryForUpdate =
                                    OpeningInventoryEntryDao.GetOpeningInventoryEntryEntityByAccountCodeForMaster(
                                        openingInventoryEntryEntity.AccountNumber);
                                if (openingInventoryEntryForUpdate != null)
                                {
                                    openingInventoryEntryEntity.RefId =
                                        OpeningInventoryEntryDao.InsertOpeningInventoryEntry(
                                            openingInventoryEntryEntity);
                                    if (openingInventoryEntryEntity.RefId == 0)
                                    {
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        scope.Dispose();
                                        return(response);
                                    }
                                }
                                else
                                {
                                    openingInventoryEntryEntity.RefId =
                                        OpeningInventoryEntryDao.InsertOpeningInventoryEntry(
                                            openingInventoryEntryEntity);
                                    if (openingInventoryEntryEntity.RefId == 0)
                                    {
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        scope.Dispose();
                                        return(response);
                                    }
                                }
                                response.RefId = openingInventoryEntryEntity.RefId;

                                //insert JournalEntryAccount
                                var journalEntryAccount = AddJournalEntryAccount(openingInventoryEntryEntity);
                                if (!journalEntryAccount.Validate())
                                {
                                    foreach (var error in journalEntryAccount.ValidationErrors)
                                    {
                                        response.Message += error + Environment.NewLine;
                                    }
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    return(response);
                                }
                                journalEntryAccount.RefId =
                                    JournalEntryAccountDao.InsertJournalEntryAccount(journalEntryAccount);
                                if (journalEntryAccount.RefId != 0)
                                {
                                    continue;
                                }
                                else
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }

                                //}
                                //insert log
                                //auditingLog.Reference = "Cập nhật CT số dư đầu kỳ cho tài khoản vật tư";
                                //auditingLog.Amount = 0;
                                //AudittingLogDao.InsertAudittingLog(auditingLog);
                            }
                        }
                        else
                        {
                            //insert or update master openingAccountEntry
                            var account = AccountDao.GetAccountByAccountCode(accountNumber);
                            var openingAccountEntryForUpdate = OpeningAccountEntryDao.GetOpeningAccountEntryEntityByAccountCode(account.AccountCode);
                            if (openingAccountEntryForUpdate != null)
                            {
                                openingAccountEntryForUpdate.TotalAccountBeginningDebitAmountOC  = 0;
                                openingAccountEntryForUpdate.TotalAccountBeginningCreditAmountOC = 0;
                                openingAccountEntryForUpdate.TotalDebitAmountOC  = 0;
                                openingAccountEntryForUpdate.TotalCreditAmountOC = 0;
                                openingAccountEntryForUpdate.TotalAccountBeginningDebitAmountExchange  = 0;
                                openingAccountEntryForUpdate.TotalAccountBeginningCreditAmountExchange = 0;
                                openingAccountEntryForUpdate.TotalDebitAmountExchange  = 0;
                                openingAccountEntryForUpdate.TotalCreditAmountExchange = 0;
                                response.Message = OpeningAccountEntryDao.UpdateOpeningAccountEntry(openingAccountEntryForUpdate);
                                if (response.Message != null)
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }
                                else
                                {
                                    response.RefId = 1;    //Success SaveData
                                }
                                //    openingAccountEntry.RefId = openingAccountEntryForUpdate.RefId;
                            }
                            else
                            {
                                OpeningAccountEntryEntity openingAccountEntry = new OpeningAccountEntryEntity()
                                {
                                    AccountCode = accountNumber,
                                    AccountId   = inventoryEntryEntity.AccountId,
                                    AccountName = inventoryEntryEntity.AccountName,
                                    ParentId    = inventoryEntryEntity.ParentId,
                                    PostedDate  = inventoryEntryEntity.PostedDate,
                                    RefId       = 0,
                                    RefNo       = inventoryEntryEntity.RefNo,
                                    RefTypeId   = 700,
                                };
                                openingAccountEntry.RefId = OpeningAccountEntryDao.InsertOpeningAccountEntry(openingAccountEntry);
                                if (openingAccountEntry.RefId == 0)
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }
                            }

                            //Xoa het
                            foreach (var openingInventoryEntryEntity in openingInventoryEntries)
                            {
                                var openingInventoryEntryForUpdate = OpeningInventoryEntryDao.GetOpeningInventoryEntryEntityByAccountCodeForMaster(openingInventoryEntryEntity.AccountNumber);
                                if (openingInventoryEntryForUpdate != null)
                                {
                                    response.Message = OpeningInventoryEntryDao.DeleteOpeningInventoryEntryByAccountCode(openingInventoryEntryForUpdate);
                                    response.Message = JournalEntryAccountDao.DeleteJournalEntryAccountByAcountNumber(openingInventoryEntryEntity.AccountNumber, 701);
                                    if (response.Message != null)
                                    {
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        scope.Dispose();
                                        return(response);
                                    }
                                    else
                                    {
                                        response.RefId = 1;    //Success SaveData
                                    }
                                }
                                else
                                {
                                    response.RefId = 1;    //Success SaveData
                                }
                            }
                        }
                        scope.Complete();
                    }
                    break;

                default:
                    using (var scope = new TransactionScope())
                    {
                        //insert log
                        //auditingLog.Reference = "Xóa CT số dư đầu kỳ cho tài khoản vật tư";
                        //auditingLog.Amount = 0;
                        //AudittingLogDao.InsertAudittingLog(auditingLog);

                        scope.Complete();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                response.Acknowledge = AcknowledgeType.Failure;
                response.Message     = ex.Message;
                return(response);
            }

            //   response.RefId = openingAccountEntry.RefId;
            response.Acknowledge = response.Message != null ? AcknowledgeType.Failure : AcknowledgeType.Success;
            return(response);
        }
        /// <summary>
        /// Sets the opening account entry details.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public OpeningAccountEntryDetailResponse SetOpeningAccountEntryDetails(OpeningAccountEntryDetailRequest request)
        {
            var response = new OpeningAccountEntryDetailResponse();

            var openingAccountEntryDetails = request.OpeningAccountEntryDetails;

            //var auditingLog = new AudittingLogEntity { ComponentName = "SO DU DAU KY TSCD", EventAction = (int)request.Action };
            try
            {
                if (request.Action == PersistType.Insert)
                {
                    if (openingAccountEntryDetails != null && openingAccountEntryDetails.Count > 0)
                    {
                        var openingAccountEntry = new OpeningAccountEntryEntity();
                        using (var scope = new TransactionScope())
                        {
                            //insert detail
                            foreach (var openingAccountEntryDetailEntity in openingAccountEntryDetails)
                            {
                                openingAccountEntry.AccountCode = openingAccountEntryDetailEntity.AccountCode;
                                openingAccountEntry.PostedDate  = openingAccountEntryDetailEntity.PostedDate;
                                openingAccountEntry.RefTypeId   = openingAccountEntryDetailEntity.RefTypeId;
                                openingAccountEntry.TotalAccountBeginningDebitAmountOC  += openingAccountEntryDetailEntity.AccountBeginningDebitAmountOC;
                                openingAccountEntry.TotalAccountBeginningCreditAmountOC += openingAccountEntryDetailEntity.AccountBeginningCreditAmountOC;
                                openingAccountEntry.TotalDebitAmountOC  += openingAccountEntryDetailEntity.DebitAmountOC;
                                openingAccountEntry.TotalCreditAmountOC += openingAccountEntryDetailEntity.CreditAmountOC;
                                openingAccountEntry.TotalAccountBeginningDebitAmountExchange  += openingAccountEntryDetailEntity.AccountBeginningDebitAmountExchange;
                                openingAccountEntry.TotalAccountBeginningCreditAmountExchange += openingAccountEntryDetailEntity.AccountBeginningCreditAmountExchange;
                                openingAccountEntry.TotalDebitAmountExchange  += openingAccountEntryDetailEntity.DebitAmountExchange;
                                openingAccountEntry.TotalCreditAmountExchange += openingAccountEntryDetailEntity.CreditAmountExchange;

                                openingAccountEntryDetailEntity.RefDetailId = OpeningAccountEntryDetailDao.InsertOpeningAccountEntryDetail(openingAccountEntryDetailEntity);
                                if (openingAccountEntryDetailEntity.RefDetailId == 0)
                                {
                                    response.Acknowledge = AcknowledgeType.Failure;
                                    scope.Dispose();
                                    return(response);
                                }
                            }

                            //insert master
                            openingAccountEntry.RefId = OpeningAccountEntryDao.InsertOpeningAccountEntry(openingAccountEntry);
                            if (openingAccountEntry.RefId == 0)
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                scope.Dispose();
                                return(response);
                            }

                            //insert log
                            //auditingLog.Reference = "Thêm mới CT số dư đầu kỳ cho tài khoản ";
                            //auditingLog.Amount = 0;
                            //AudittingLogDao.InsertAudittingLog(auditingLog);

                            scope.Complete();
                        }
                    }
                }
                else if (request.Action == PersistType.Update)
                {
                    if (openingAccountEntryDetails != null && openingAccountEntryDetails.Count > 0)
                    {
                        using (var scope = new TransactionScope())
                        {
                            response.Message = OpeningAccountEntryDetailDao.DeleteOpeningAccountEntryDetailByAccountCode(openingAccountEntryDetails[0].AccountCode);
                            if (response.Message != null)
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                scope.Dispose();
                                return(response);
                            }
                            foreach (var openingAccountEntryDetailEntity in openingAccountEntryDetails)
                            {
                                openingAccountEntryDetailEntity.RefDetailId = OpeningAccountEntryDetailDao.InsertOpeningAccountEntryDetail(openingAccountEntryDetailEntity);
                            }

                            //insert log
                            //auditingLog.Reference = "Cập nhật CT số dư đầu kỳ cho tài khoản";
                            //auditingLog.Amount = 0;
                            //AudittingLogDao.InsertAudittingLog(auditingLog);

                            scope.Complete();
                        }
                    }
                }
                else
                {
                    using (var scope = new TransactionScope())
                    {
                        //insert log
                        //auditingLog.Reference = "Xóa CT số dư đầu kỳ cho tài khoản ";
                        //auditingLog.Amount = 0;
                        //AudittingLogDao.InsertAudittingLog(auditingLog);

                        scope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                response.Acknowledge = AcknowledgeType.Failure;
                response.Message     = ex.Message;
                return(response);
            }

            response.RefId       = 1;
            response.Acknowledge = response.Message != null ? AcknowledgeType.Failure : AcknowledgeType.Success;
            return(response);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Updates the opening account entry.
        /// </summary>
        /// <param name="openingAccountEntryEntity">The opening account entry entity.</param>
        /// <returns></returns>
        public string UpdateOpeningAccountEntry(OpeningAccountEntryEntity openingAccountEntryEntity)
        {
            const string sql = @"uspUpdate_OpeningAccountEntry";

            return(Db.Update(sql, true, Take(openingAccountEntryEntity)));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Inserts the opening account entry.
        /// </summary>
        /// <param name="openingAccountEntryEntity">The opening account entry entity.</param>
        /// <returns></returns>
        public long InsertOpeningAccountEntry(OpeningAccountEntryEntity openingAccountEntryEntity)
        {
            const string sql = @"uspInsert_OpeningAccountEntry";

            return(Db.Insert(sql, true, Take(openingAccountEntryEntity)));
        }
        /// <summary>
        /// Inserts the opening account entry.
        /// </summary>
        /// <param name="openingAccountEntryEntity">The opening account entry entity.</param>
        /// <returns></returns>
        public string InsertOpeningAccountEntry(OpeningAccountEntryEntity openingAccountEntryEntity)
        {
            const string procedures = @"uspInsert_OpeningAccountEntry";

            return(Db.Insert(procedures, true, Take(openingAccountEntryEntity)));
        }
        public IList <OpeningAccountEntryEntity> GetOpeningAccountEntrys(string connectionString, List <CurrencyEntity> currency)
        {
            List <OpeningAccountEntryEntity> buentity = new List <OpeningAccountEntryEntity>();

            using (var context = new MISAEntity(connectionString))
            {
                //var querry = context.OpeningAccountEntries.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.OpeningAccountEntries.ToList();
                //var fixedasset = context.FixedAssets.ToList();
                //var inventoryitems = context.InventoryItems.ToList();
                // var stocks = context.Stocks.ToList();
                foreach (var result in resultcontext)
                {
                    var newresult = new OpeningAccountEntryEntity();
                    newresult.RefId                      = result.RefID.ToString();
                    newresult.RefType                    = ConvRefType.ConvRefType(result.RefType);
                    newresult.PostedDate                 = result.PostedDate ?? DateTime.Now;
                    newresult.CurrencyId                 = currency == null || string.IsNullOrEmpty(result.CurrencyID) ? null : currency.FirstOrDefault(c => c.CurrencyCode == result.CurrencyID).CurrencyId;
                    newresult.ExchangeRate               = result.ExchangeRate ?? 0;
                    newresult.AccountNumber              = result.AccountNumber;
                    newresult.AccBeginningDebitAmountOC  = result.AccBeginningDebitAmountOC;
                    newresult.AccBeginningDebitAmount    = result.AccBeginningDebitAmount;
                    newresult.AccBeginningCreditAmountOC = result.AccBeginningCreditAmountOC;
                    newresult.AccBeginningCreditAmount   = result.AccBeginningCreditAmount;
                    newresult.DebitAmountOC              = result.DebitAmountOC;
                    newresult.DebitAmount                = result.DebitAmount;
                    newresult.CreditAmountOC             = result.CreditAmountOC;
                    newresult.CreditAmount               = result.CreditAmount;
                    newresult.BudgetSourceId             = result.BudgetSource == null ? null : result.BudgetSource.BudgetSourceID.ToString();
                    newresult.BudgetChapterCode          = result.BudgetChapterCode;
                    newresult.BudgetKindItemCode         = result.BudgetKindItemCode;
                    newresult.BudgetSubKindItemCode      = result.BudgetSubKindItemCode;
                    newresult.BudgetItemCode             = result.BudgetItemCode;
                    newresult.BudgetSubItemCode          = result.BudgetSubItemCode;
                    newresult.MethodDistributeId         = result.MethodDistributeID ?? 0;
                    newresult.CashWithdrawTypeId         = ConvertCash.ConvertCash(result.CashWithdrawTypeID);
                    newresult.AccountingObjectId         = result.AccountingObject == null ? null : result.AccountingObject.AccountingObjectID.ToString();
                    newresult.ActivityId                 = result.Activity == null ? null : result.Activity.ActivityID.ToString();
                    newresult.ProjectId                  = result.Project == null ? null : result.Project.ProjectID.ToString();
                    newresult.TaskId                     = result.TaskID.ToString();
                    //newresult.BankId = result.ba;
                    newresult.Approved             = result.Approved ?? true;
                    newresult.SortOrder            = result.SortOrder ?? 0;
                    newresult.BudgetDetailItemCode = result.BudgetDetailItemCode;
                    newresult.ProjectActivityId    = result.Project1 == null ? null : result.Project1.ProjectID.ToString();
                    newresult.ApprovedDate         = result.ApprovedDate ?? DateTime.Now;
                    newresult.FundStructureId      = result.FundStructure == null ? null : result.FundStructure.FundStructureID.ToString();
                    newresult.ProjectActivityEAID  = result.Project1 == null ? null : result.Project1.ProjectID.ToString();
                    newresult.BudgetProvideCode    = result.BudgetProvidence == null ? null : result.BudgetProvidence.BudgetProvideCode;
                    //newresult.BudgetExpenseId = result.BudgetExpense;
                    buentity.Add(newresult);
                }
            }
            return(buentity);
        }