Example #1
0
        public string DeleteOpeningInventoryEntryByAccountCode(OpeningInventoryEntryEntity openingAccountEntryEntity)
        {
            const string sql = @"uspDelet_OpeningInventoryEntryByAccountNumber";

            object[] parms = { "@AccountNumber", openingAccountEntryEntity.AccountNumber };
            return(Db.Delete(sql, true, parms));
        }
Example #2
0
 private static object[] Take(OpeningInventoryEntryEntity openingInventoryEntryEntity)
 {
     return(new object[]
     {
         "@RefID", openingInventoryEntryEntity.RefId,
         "@RefType", openingInventoryEntryEntity.RefType,
         "@PostedDate", openingInventoryEntryEntity.PostedDate,
         "@CurrencyCode", openingInventoryEntryEntity.CurrencyCode,
         "@ExchangeRate", openingInventoryEntryEntity.ExchangeRate,
         "@AccountNumber", openingInventoryEntryEntity.AccountNumber,
         "@InventoryItemID", openingInventoryEntryEntity.InventoryItemId,
         "@StockID", openingInventoryEntryEntity.StockId,
         "@BudgetSourceID", openingInventoryEntryEntity.BudgetSourceId,
         "@BudgetChapterCode", openingInventoryEntryEntity.BudgetChapterCode,
         "@BudgetKindItemCode", openingInventoryEntryEntity.BudgetKindItemCode,
         "@BudgetSubKindItemCode", openingInventoryEntryEntity.BudgetSubKindItemCode,
         "@BudgetItemCode", openingInventoryEntryEntity.BudgetItemCode,
         "@BudgetSubItemCode", openingInventoryEntryEntity.BudgetSubItemCode,
         "@Quantity", openingInventoryEntryEntity.Quantity,
         "@UnitPriceOC", openingInventoryEntryEntity.UnitPriceOC,
         "@UnitPrice", openingInventoryEntryEntity.UnitPrice,
         "@AmountOC", openingInventoryEntryEntity.AmountOC,
         "@Amount", openingInventoryEntryEntity.Amount,
         "@ExpiryDate", openingInventoryEntryEntity.ExpiryDate,
         "@LotNo", openingInventoryEntryEntity.LotNo,
         "@SortOrder", openingInventoryEntryEntity.SortOrder,
         "@RefOrder", openingInventoryEntryEntity.RefOrder,
         "@ContractID", openingInventoryEntryEntity.ContractId,
         "@CapitalPlanID", openingInventoryEntryEntity.CapitalPlanId,
     });
 }
Example #3
0
        /// <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>
        /// <returns></returns>
        public JournalEntryAccountEntity AddJournalEntryAccount(OpeningInventoryEntryEntity openingInventoryEntryEntity)
        {
            var     account = AccountDao.GetAccountByAccountCode(openingInventoryEntryEntity.AccountNumber);
            decimal amountOC;
            decimal amountExchange;

            //switch (account.BalanceSide)
            //{
            //    case 0:
            //        amountOC = openingInventoryEntryEntity.AmountOc;
            //        amountExchange = openingInventoryEntryEntity.AmountExchange;
            //        break;
            //    case 1:
            //        amountOC = openingInventoryEntryEntity.AmountOc;
            //        amountExchange = openingInventoryEntryEntity.AmountExchange;
            //        break;
            //    default:
            //        amountOC = Math.Abs(openingAccountEntryDetailEntity.DebitAmountOC - openingAccountEntryDetailEntity.CreditAmountOC);
            //        amountExchange = Math.Abs(openingAccountEntryDetailEntity.DebitAmountExchange - openingAccountEntryDetailEntity.CreditAmountExchange);
            //        break;
            //}
            //Đầu 1 -> Dư Nợ
            amountOC       = openingInventoryEntryEntity.AmountOc;
            amountExchange = openingInventoryEntryEntity.AmountExchange;
            return(new JournalEntryAccountEntity
            {
                RefId = openingInventoryEntryEntity.RefId,
                RefTypeId = openingInventoryEntryEntity.RefTypeId,
                RefNo = "OPN",
                RefDate = openingInventoryEntryEntity.PostedDate,
                PostedDate = openingInventoryEntryEntity.PostedDate,
                JournalMemo = null,
                CurrencyCode = openingInventoryEntryEntity.CurrencyCode,
                ExchangeRate = (decimal)openingInventoryEntryEntity.ExchangeRate,
                BankAccount = null,
                RefDetailId = openingInventoryEntryEntity.RefId, //Lấy RefMaster
                AccountNumber = openingInventoryEntryEntity.AccountNumber,
                CorrespondingAccountNumber = null,
                AmountOc = amountOC,
                Description = null,
                JournalType = 1,
                AmountExchange = amountExchange,
                BudgetSourceCode = null,
                BudgetItemCode = null,
                AccountingObjectId = null,
                EmployeeId = null,
                CustomerId = null,
                VendorId = null,
                MergerFundId = null,
                VoucherTypeId = null,
                ProjectId = null,
            });
        }
Example #4
0
 /// <summary>
 /// Inserts the opening account entry.
 /// </summary>
 /// <param name="openingAccountEntryEntity">The opening account entry entity.</param>
 /// <returns></returns>
 public long InsertOpeningInventoryEntry(OpeningInventoryEntryEntity openingAccountEntryEntity)
 {
     try
     {
         const string sql = @"uspInsert_OpeningInventoryEntry";
         return(Db.Insert(sql, true, Take(openingAccountEntryEntity)));
     }
     catch (Exception e)
     {
         return(0);
     }
 }
Example #5
0
 /// <summary>
 /// Takes the specified opening account entry.
 /// </summary>
 /// <param name="openingAccountEntry">The opening account entry.</param>
 /// <returns></returns>
 private static object[] Take(OpeningInventoryEntryEntity openingAccountEntry)
 {
     return(new object[]
     {
         @"RefID", openingAccountEntry.RefId,
         @"RefTypeID", openingAccountEntry.RefTypeId,
         @"PostedDate", openingAccountEntry.PostedDate,
         @"AccountNumber", openingAccountEntry.AccountNumber,
         @"UnitPriceExchange", openingAccountEntry.UnitPriceExchange,
         @"UnitPriceOC", openingAccountEntry.UnitPriceOc,
         @"Quantity", openingAccountEntry.Quantity,
         @"ExchangeRate", openingAccountEntry.ExchangeRate,
         @"AmountOC", openingAccountEntry.AmountOc,
         @"AmountExchange", openingAccountEntry.AmountExchange,
         @"CurrencyCode", openingAccountEntry.CurrencyCode,
         @"InventoryItemID", openingAccountEntry.InventoryItemId,
         @"StockId", openingAccountEntry.StockId
     });
 }
Example #6
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);
        }
Example #7
0
        public string UpdateOpeningInventoryEntry(OpeningInventoryEntryEntity openingCommitment)
        {
            const string procedures = @"uspUpdate_OpeningInventoryEntry";

            return(Db.Insert(procedures, true, Take(openingCommitment)));
        }
Example #8
0
        /// <summary>
        /// Updates the opening account entry.
        /// </summary>
        /// <param name="openingAccountEntryEntity">The opening account entry entity.</param>
        /// <returns></returns>
        public string UpdateOpeningInventoryEntry(OpeningInventoryEntryEntity openingAccountEntryEntity)
        {
            const string sql = @"uspUpdate_OpeningInventoryEntry";

            return(Db.Update(sql, true, Take(openingAccountEntryEntity)));
        }
        public List <OpeningInventoryEntryEntity> GetOpeningInventoryEntrys(string connectionString)
        {
            List <OpeningInventoryEntryEntity> buentity = new List <OpeningInventoryEntryEntity>();

            using (var context = new MISAEntity(connectionString))
            {
                //var querry = context.OpeningInventoryEntryDetails.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.OpeningInventoryEntries.ToList();
                var fixedasset     = context.FixedAssets.ToList();
                var inventoryitems = context.InventoryItems.ToList();
                //var stocks = context.Stocks.ToList();
                //var invoiceformnumber = context.InvoiceFormNumbers.ToList();
                foreach (var result in resultcontext)
                {
                    var newresult = new OpeningInventoryEntryEntity();

                    newresult.RefId             = result.RefID.ToString();
                    newresult.RefType           = result.RefType;
                    newresult.PostedDate        = result.PostedDate;
                    newresult.CurrencyCode      = result.CurrencyID;
                    newresult.ExchangeRate      = result.ExchangeRate ?? 0;
                    newresult.AccountNumber     = result.AccountNumber;
                    newresult.InventoryItemId   = result.InventoryItem == null ? null : result.InventoryItem.InventoryItemID.ToString();
                    newresult.StockId           = result.StockID.ToString();
                    newresult.BudgetSourceId    = result.BudgetSource == null ? null : result.BudgetSource.BudgetSourceID.ToString();
                    newresult.BudgetChapterCode = result.BudgetChapterCode;
                    // newresult.BudgetKindItemCode = result;
                    //newresult.BudgetSubKindItemCode = result.BudgetSubKindItemCode;
                    //newresult.BudgetItemCode = result.BudgetItemCode;
                    //newresult.BudgetSubItemCode = result.BudgetSubItemCode;
                    newresult.Quantity    = result.Quantity ?? 0;
                    newresult.UnitPriceOC = result.UnitPrice ?? 0;
                    newresult.UnitPrice   = result.UnitPrice ?? 0;
                    newresult.AmountOC    = result.Amount;
                    newresult.Amount      = result.Amount;
                    newresult.ExpiryDate  = result.ExpiryDate ?? DateTime.Now;
                    newresult.LotNo       = result.LotNo;
                    newresult.PostVersion = result.PostVersion ?? 0;
                    newresult.EditVersion = result.EditVersion ?? 0;
                    newresult.SortOrder   = result.SortOrder ?? 0;
                    newresult.RefOrder    = result.RefOrder ?? 0;
                    //newresult.cre = result.CreateDate;
                    buentity.Add(newresult);
                }
            }
            return(buentity);
        }