/// <summary>
        /// Deletes the ba deposit.
        /// </summary>
        /// <param name="sUIncrementDecrementId">The b a deposit identifier.</param>
        /// <returns></returns>
        public SUIncrementDecrementResponse DeleteSUIncrementDecrement(string sUIncrementDecrementId)
        {
            var response = new SUIncrementDecrementResponse {
                Acknowledge = AcknowledgeType.Success
            };

            try
            {
                var sUIncrementDecrementEntity = SUIncrementDecrementDao.GetSUIncrementDecrement(sUIncrementDecrementId);
                if (sUIncrementDecrementEntity == null)
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    response.Message     = "Dữ liệu cần xóa không tồn tại!";
                    return(response);
                }
                using (var scope = new TransactionScope())
                {
                    #region Update account balance
                    // Cập nhật giá trị vào account balance trước khi xóa
                    response.Message = UpdateAccountBalance(sUIncrementDecrementEntity);
                    if (response.Message != null)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }

                    #endregion

                    // Xóa bảng SUIncrementDecrement
                    response.Message = SUIncrementDecrementDao.DeleteSUIncrementDecrement(sUIncrementDecrementEntity);
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        return(response);
                    }

                    // Xóa bảng SupplyLedger
                    response.Message = SupplyLedgerDao.DeleteSupplyLedgerByRefId(sUIncrementDecrementEntity.RefId, sUIncrementDecrementEntity.RefType);
                    if (response.Message != null)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }

                    scope.Complete();
                }
                response.RefId = sUIncrementDecrementEntity.RefId;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(response);
            }
        }
        public SUIncrementDecrementResponse DeleteSUIncrementDecrement(long sUIncrementDecrementId)
        {
            var response = new SUIncrementDecrementResponse {
                Acknowledge = AcknowledgeType.Success
            };

            try
            {
                var sUIncrementDecrementEntity = SUIncrementDecrementDao.GetSUIncrementDecrement(sUIncrementDecrementId);
                if (sUIncrementDecrementEntity == null)
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    response.Message     = "Dữ liệu cần xóa không tồn tại!";
                    return(response);
                }
                using (var scope = new TransactionScope())
                {
                    #region Delete SUIncrementDecrement

                    response.Message = SUIncrementDecrementDao.DeleteSUIncrementDecrement(sUIncrementDecrementEntity);
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        return(response);
                    }

                    #endregion

                    #region Delete  SupplyLedger

                    response.Message = SupplyLedgerDao.DeleteSupplyLedgerByRefId(sUIncrementDecrementEntity.RefId, sUIncrementDecrementEntity.RefType);
                    if (response.Message != null)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }

                    #endregion

                    scope.Complete();
                }
                response.RefId = sUIncrementDecrementEntity.RefId;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(response);
            }
        }
        public SUIncrementDecrementResponse InsertSUIncrementDecrement(SUIncrementDecrementEntity sUIncrementDecrementEntity, bool isconvertDB)
        {
            var response = new SUIncrementDecrementResponse {
                Acknowledge = AcknowledgeType.Success
            };

            try
            {
                if (!sUIncrementDecrementEntity.Validate())
                {
                    foreach (var error in sUIncrementDecrementEntity.ValidationErrors)
                    {
                        response.Message += error + Environment.NewLine;
                    }
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }
                using (var scope = new TransactionScope())
                {
                    var sUIncrementDecrementByRefNo = SUIncrementDecrementDao.GetSUIncrementDecrementByRefNo(sUIncrementDecrementEntity.RefNo, sUIncrementDecrementEntity.PostedDate);
                    if (sUIncrementDecrementByRefNo != null && sUIncrementDecrementByRefNo.PostedDate.Year == sUIncrementDecrementEntity.PostedDate.Year)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        response.Message     = "Mã chứng từ đã tồn tại!";
                        return(response);
                    }
                    sUIncrementDecrementEntity.RefId = SUIncrementDecrementDao.InsertSUIncrementDecrement(sUIncrementDecrementEntity);
                    if (sUIncrementDecrementEntity.RefId <= 0)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        return(response);
                    }

                    #region Insert Detail & SupplyLedger

                    if (sUIncrementDecrementEntity.SUIncrementDecrementDetails != null)
                    {
                        foreach (var sUIncrementDecrementDetailEntity in sUIncrementDecrementEntity.SUIncrementDecrementDetails)
                        {
                            sUIncrementDecrementDetailEntity.RefId       = sUIncrementDecrementEntity.RefId;
                            sUIncrementDecrementDetailEntity.RefDetailId = SUIncrementDecrementDetailDao.InsertSUIncrementDecrementDetail(sUIncrementDecrementDetailEntity);
                            if (sUIncrementDecrementDetailEntity.RefDetailId <= 0)
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                return(response);
                            }

                            var supplyLedgerEntity = MakeSupplyLedger(sUIncrementDecrementEntity, sUIncrementDecrementDetailEntity);
                            supplyLedgerEntity.SupplyLedgerId = SupplyLedgerDao.InsertSupplyLedger(supplyLedgerEntity);
                            if (supplyLedgerEntity.SupplyLedgerId <= 0)
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                return(response);
                            }
                        }
                    }

                    #endregion

                    #region Auto Number

                    var autoNumber = AutoNumberDao.GetAutoNumberByRefType(sUIncrementDecrementEntity.RefType);
                    if (sUIncrementDecrementEntity.CurrencyCode == "USD")
                    {
                        autoNumber.Value += 1;
                    }
                    else
                    {
                        autoNumber.ValueLocalCurency += 1;
                    }

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

                    #endregion

                    scope.Complete();
                }
                response.RefId = sUIncrementDecrementEntity.RefId;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(response);
            }
        }
        public SUIncrementDecrementResponse UpdateSUIncrementDecrement(SUIncrementDecrementEntity sUIncrementDecrementEntity)
        {
            var response = new SUIncrementDecrementResponse {
                Acknowledge = AcknowledgeType.Success
            };

            try
            {
                if (!sUIncrementDecrementEntity.Validate())
                {
                    foreach (var error in sUIncrementDecrementEntity.ValidationErrors)
                    {
                        response.Message += error + Environment.NewLine;
                    }
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }
                using (var scope = new TransactionScope())
                {
                    var sUIncrementDecrementByRefNo = SUIncrementDecrementDao.GetSUIncrementDecrementByRefNo(sUIncrementDecrementEntity.RefNo, sUIncrementDecrementEntity.PostedDate);
                    if (sUIncrementDecrementByRefNo != null && sUIncrementDecrementByRefNo.RefId != sUIncrementDecrementEntity.RefId)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        response.Message     = "Mã chứng từ đã tồn tại!";
                        return(response);
                    }
                    response.Message = SUIncrementDecrementDao.UpdateSUIncrementDecrement(sUIncrementDecrementEntity);
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        return(response);
                    }

                    #region Delete Detail & SupplyLedger

                    response.Message = SUIncrementDecrementDetailDao.DeleteSUIncrementDecrementDetailByRefId(sUIncrementDecrementEntity.RefId);
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        return(response);
                    }

                    response.Message = SupplyLedgerDao.DeleteSupplyLedgerByRefId(sUIncrementDecrementEntity.RefId, sUIncrementDecrementEntity.RefType);
                    if (response.Message != null)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }

                    #endregion

                    #region Insert Detail & SupplyLedger

                    if (sUIncrementDecrementEntity.SUIncrementDecrementDetails != null)
                    {
                        foreach (var sUIncrementDecrementDetailEntity in sUIncrementDecrementEntity.SUIncrementDecrementDetails)
                        {
                            sUIncrementDecrementDetailEntity.RefId       = sUIncrementDecrementEntity.RefId;
                            sUIncrementDecrementDetailEntity.RefDetailId = SUIncrementDecrementDetailDao.InsertSUIncrementDecrementDetail(sUIncrementDecrementDetailEntity);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                return(response);
                            }

                            var supplyLedgerEntity = MakeSupplyLedger(sUIncrementDecrementEntity, sUIncrementDecrementDetailEntity);
                            supplyLedgerEntity.SupplyLedgerId = SupplyLedgerDao.InsertSupplyLedger(supplyLedgerEntity);
                            if (supplyLedgerEntity.SupplyLedgerId <= 0)
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                return(response);
                            }
                        }
                    }

                    #endregion

                    scope.Complete();
                }
                response.RefId = sUIncrementDecrementEntity.RefId;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(response);
            }
        }
        /// <summary>
        /// Updates the ba deposit.
        /// </summary>
        /// <param name="sUIncrementDecrementEntity">The b a deposit entity.</param>
        /// <returns></returns>
        public SUIncrementDecrementResponse UpdateSUIncrementDecrement(
            SUIncrementDecrementEntity sUIncrementDecrementEntity)
        {
            var response = new SUIncrementDecrementResponse {
                Acknowledge = AcknowledgeType.Success
            };

            try
            {
                if (!sUIncrementDecrementEntity.Validate())
                {
                    foreach (var error in sUIncrementDecrementEntity.ValidationErrors)
                    {
                        response.Message += error + Environment.NewLine;
                    }
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }
                using (var scope = new TransactionScope())
                {
                    var sUIncrementDecrementByRefNo =
                        SUIncrementDecrementDao.GetSUIncrementDecrementByRefNo(sUIncrementDecrementEntity.RefNo, sUIncrementDecrementEntity.PostedDate);
                    if (sUIncrementDecrementByRefNo != null && sUIncrementDecrementByRefNo.RefId != sUIncrementDecrementEntity.RefId)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        response.Message     = "Mã chứng từ đã tồn tại!";
                        return(response);
                    }
                    response.Message = SUIncrementDecrementDao.UpdateSUIncrementDecrement(sUIncrementDecrementEntity);
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        return(response);
                    }

                    #region Update account balance
                    //Trừ đi số tiền của chứng từ cũ trước khi cộng thêm số tiền mới

                    UpdateAccountBalance(sUIncrementDecrementEntity);
                    if (response.Message != null)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }

                    #endregion

                    #region Delete detail and insert detail

                    // Xóa bảng SUIncrementDecrementDetail
                    response.Message = SUIncrementDecrementDetailDao.DeleteSUIncrementDecrementDetailByRefId(sUIncrementDecrementEntity.RefId);
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        return(response);
                    }

                    // Xóa bảng SupplyLedger
                    response.Message = SupplyLedgerDao.DeleteSupplyLedgerByRefId(sUIncrementDecrementEntity.RefId, sUIncrementDecrementEntity.RefType);
                    if (response.Message != null)
                    {
                        response.Acknowledge = AcknowledgeType.Failure;
                        scope.Dispose();
                        return(response);
                    }

                    if (sUIncrementDecrementEntity.SUIncrementDecrementDetails != null)
                    {
                        foreach (var sUIncrementDecrementDetailEntity in sUIncrementDecrementEntity.SUIncrementDecrementDetails)
                        {
                            if (sUIncrementDecrementEntity.RefType == (int)BuCA.Enum.RefType.SUDecrement)
                            {
                                AutoMapper(GetUnitsInDepartment(sUIncrementDecrementDetailEntity.InventoryItemId, sUIncrementDecrementDetailEntity.DepartmentId, sUIncrementDecrementDetailEntity.Quantity, sUIncrementDecrementDetailEntity.Description), response);
                                if (response.Acknowledge == AcknowledgeType.Failure)
                                {
                                    return(response);
                                }
                            }

                            sUIncrementDecrementDetailEntity.RefDetailId = Guid.NewGuid().ToString();
                            sUIncrementDecrementDetailEntity.RefId       = sUIncrementDecrementEntity.RefId;
                            response.Message =
                                SUIncrementDecrementDetailDao.InsertSUIncrementDecrementDetail(sUIncrementDecrementDetailEntity);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                return(response);
                            }

                            #region Insert into AccountBalance

                            // Cộng thêm số tiền mới sau khi sửa chứng từ
                            InsertAccountBalance(sUIncrementDecrementEntity, sUIncrementDecrementDetailEntity);
                            if (response.Message != null)
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                scope.Dispose();
                                return(response);
                            }

                            #endregion

                            #region Insert OriginalGeneralLedger
                            // Xóa bảng OriginalGeneralLedger
                            response.Message = OriginalGeneralLedgerDao.DeleteOriginalGeneralLedger(sUIncrementDecrementEntity.RefId);
                            if (response.Message != null)
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                scope.Dispose();
                                return(response);
                            }

                            var originalGeneralLedgerEntity = new OriginalGeneralLedgerEntity
                            {
                                OriginalGeneralLedgerId = Guid.NewGuid().ToString(),
                                RefType           = sUIncrementDecrementEntity.RefType,
                                RefId             = sUIncrementDecrementEntity.RefId,
                                RefDetailId       = sUIncrementDecrementDetailEntity.RefDetailId,
                                RefDate           = sUIncrementDecrementEntity.RefDate,
                                RefNo             = sUIncrementDecrementEntity.RefNo,
                                Amount            = sUIncrementDecrementDetailEntity.Amount,
                                BudgetChapterCode = sUIncrementDecrementDetailEntity.BudgetChapterCode,
                                CreditAccount     = sUIncrementDecrementDetailEntity.CreditAccount,
                                DebitAccount      = sUIncrementDecrementDetailEntity.DebitAccount,
                                Description       = sUIncrementDecrementDetailEntity.Description,
                                JournalMemo       = sUIncrementDecrementEntity.JournalMemo,
                                SortOrder         = sUIncrementDecrementDetailEntity.SortOrder,
                                PostedDate        = sUIncrementDecrementEntity.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

                            if (sUIncrementDecrementEntity.RefType == 205 || sUIncrementDecrementEntity.RefType == 206)
                            {
                                #region Insert SupplyLedger
                                if (sUIncrementDecrementDetailEntity.InventoryItemId != null)
                                {
                                    var supplyLedgerEntity = new SupplyLedgerEntity
                                    {
                                        SupplyLedgerId    = Guid.NewGuid().ToString(),
                                        RefId             = sUIncrementDecrementEntity.RefId,
                                        RefType           = sUIncrementDecrementEntity.RefType,
                                        RefNo             = sUIncrementDecrementEntity.RefNo,
                                        RefDate           = sUIncrementDecrementEntity.RefDate,
                                        PostedDate        = sUIncrementDecrementEntity.PostedDate,
                                        DepartmentId      = sUIncrementDecrementDetailEntity.DepartmentId,
                                        InventoryItemId   = sUIncrementDecrementDetailEntity.InventoryItemId,
                                        Unit              = null,
                                        UnitPrice         = sUIncrementDecrementDetailEntity.UnitPrice,
                                        IncrementQuantity = sUIncrementDecrementEntity.RefType == 205 ? sUIncrementDecrementDetailEntity.Quantity : 0,
                                        DecrementQuantity = sUIncrementDecrementEntity.RefType == 205 ? 0 : sUIncrementDecrementDetailEntity.Quantity,
                                        IncrementAmount   = sUIncrementDecrementEntity.RefType == 205 ? sUIncrementDecrementDetailEntity.Amount : 0,
                                        DecrementAmount   = sUIncrementDecrementEntity.RefType == 205 ? 0 : sUIncrementDecrementDetailEntity.Amount,
                                        JournalMemo       = sUIncrementDecrementEntity.JournalMemo,
                                        Description       = sUIncrementDecrementDetailEntity.Description,
                                        AccountNumber     = sUIncrementDecrementDetailEntity.DebitAccount,
                                        RefDetailId       = sUIncrementDecrementDetailEntity.RefDetailId
                                    };
                                    response.Message = SupplyLedgerDao.InsertSupplyLedger(supplyLedgerEntity);
                                    if (!string.IsNullOrEmpty(response.Message))
                                    {
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        return(response);
                                    }
                                }
                                #endregion
                            }
                        }
                    }

                    #endregion

                    scope.Complete();
                }
                response.RefId = sUIncrementDecrementEntity.RefId;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(response);
            }
        }
        /// <summary>
        /// Inserts the ba deposit.
        /// </summary>
        /// <param name="sUIncrementDecrementEntity">The b a deposit entity.</param>
        /// <returns></returns>
        public SUIncrementDecrementResponse InsertSUIncrementDecrement(SUIncrementDecrementEntity sUIncrementDecrementEntity, bool isconvertDB)
        {
            var response = new SUIncrementDecrementResponse {
                Acknowledge = AcknowledgeType.Success
            };

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

                    #region insert SUIncrementDecrementDetails

                    if (sUIncrementDecrementEntity.SUIncrementDecrementDetails != null)
                    {
                        foreach (var sUIncrementDecrementDetailEntity in sUIncrementDecrementEntity.SUIncrementDecrementDetails)
                        {
                            if (!isconvertDB)//AnhNT: Nếu không phải convert dữ liệu thì mới check số lượng tồn
                            {
                                if (sUIncrementDecrementEntity.RefType == (int)BuCA.Enum.RefType.SUDecrement)
                                {
                                    AutoMapper(
                                        GetUnitsInDepartment(sUIncrementDecrementDetailEntity.InventoryItemId,
                                                             sUIncrementDecrementDetailEntity.DepartmentId,
                                                             sUIncrementDecrementDetailEntity.Quantity,
                                                             sUIncrementDecrementDetailEntity.Description), response);
                                    if (response.Acknowledge == AcknowledgeType.Failure)
                                    {
                                        return(response);
                                    }
                                }
                            }

                            sUIncrementDecrementDetailEntity.RefDetailId = Guid.NewGuid().ToString();
                            sUIncrementDecrementDetailEntity.RefId       = sUIncrementDecrementEntity.RefId;
                            response.Message =
                                SUIncrementDecrementDetailDao.InsertSUIncrementDecrementDetail(sUIncrementDecrementDetailEntity);
                            if (!string.IsNullOrEmpty(response.Message))
                            {
                                response.Acknowledge = AcknowledgeType.Failure;
                                return(response);
                            }

                            #region Insert to AccountBalance

                            InsertAccountBalance(sUIncrementDecrementEntity, sUIncrementDecrementDetailEntity);

                            #endregion

                            #region Insert OriginalGeneralLedger
                            var originalGeneralLedgerEntity = new OriginalGeneralLedgerEntity
                            {
                                OriginalGeneralLedgerId = Guid.NewGuid().ToString(),
                                RefType           = sUIncrementDecrementEntity.RefType,
                                RefId             = sUIncrementDecrementEntity.RefId,
                                RefDetailId       = sUIncrementDecrementDetailEntity.RefDetailId,
                                RefDate           = sUIncrementDecrementEntity.RefDate,
                                RefNo             = sUIncrementDecrementEntity.RefNo,
                                Amount            = sUIncrementDecrementDetailEntity.Amount,
                                BudgetChapterCode = sUIncrementDecrementDetailEntity.BudgetChapterCode,
                                CreditAccount     = sUIncrementDecrementDetailEntity.CreditAccount,
                                DebitAccount      = sUIncrementDecrementDetailEntity.DebitAccount,
                                Description       = sUIncrementDecrementDetailEntity.Description,
                                JournalMemo       = sUIncrementDecrementEntity.JournalMemo,
                                SortOrder         = sUIncrementDecrementDetailEntity.SortOrder,
                                PostedDate        = sUIncrementDecrementEntity.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

                            if (sUIncrementDecrementEntity.RefType == 205 || sUIncrementDecrementEntity.RefType == 206)
                            {
                                #region Insert SupplyLedger
                                if (sUIncrementDecrementDetailEntity.InventoryItemId != null)
                                {
                                    var supplyLedgerEntity = new SupplyLedgerEntity
                                    {
                                        SupplyLedgerId    = Guid.NewGuid().ToString(),
                                        RefId             = sUIncrementDecrementEntity.RefId,
                                        RefType           = sUIncrementDecrementEntity.RefType,
                                        RefNo             = sUIncrementDecrementEntity.RefNo,
                                        RefDate           = sUIncrementDecrementEntity.RefDate,
                                        PostedDate        = sUIncrementDecrementEntity.PostedDate,
                                        DepartmentId      = sUIncrementDecrementDetailEntity.DepartmentId,
                                        InventoryItemId   = sUIncrementDecrementDetailEntity.InventoryItemId,
                                        Unit              = null,
                                        UnitPrice         = sUIncrementDecrementDetailEntity.UnitPrice,
                                        IncrementQuantity = sUIncrementDecrementEntity.RefType == 205 ? sUIncrementDecrementDetailEntity.Quantity : 0,
                                        DecrementQuantity = sUIncrementDecrementEntity.RefType == 205 ? 0 : sUIncrementDecrementDetailEntity.Quantity,
                                        IncrementAmount   = sUIncrementDecrementEntity.RefType == 205 ? sUIncrementDecrementDetailEntity.Amount : 0,
                                        DecrementAmount   = sUIncrementDecrementEntity.RefType == 205 ? 0 : sUIncrementDecrementDetailEntity.Amount,
                                        JournalMemo       = sUIncrementDecrementEntity.JournalMemo,
                                        Description       = sUIncrementDecrementDetailEntity.Description,
                                        AccountNumber     = sUIncrementDecrementDetailEntity.DebitAccount,
                                        RefDetailId       = sUIncrementDecrementDetailEntity.RefDetailId
                                    };
                                    response.Message = SupplyLedgerDao.InsertSupplyLedger(supplyLedgerEntity);
                                    if (!string.IsNullOrEmpty(response.Message))
                                    {
                                        response.Acknowledge = AcknowledgeType.Failure;
                                        return(response);
                                    }
                                }
                                #endregion
                            }
                        }
                    }

                    #endregion

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