/// <summary>
        /// DropDownBuyForClient
        /// Calls [usp_dropdown_Currency_Buy_For_Client]
        /// </summary>
        public override List <CurrencyDetails> DropDownBuyForClient(System.Int32?clientId)
        {
            SqlConnection cn  = null;
            SqlCommand    cmd = null;

            try {
                cn                 = new SqlConnection(this.ConnectionString);
                cmd                = new SqlCommand("usp_dropdown_Currency_Buy_For_Client", cn);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = 30;
                cmd.Parameters.Add("@ClientId", SqlDbType.Int).Value = clientId;
                cn.Open();
                DbDataReader           reader = ExecuteReader(cmd);
                List <CurrencyDetails> lst    = new List <CurrencyDetails>();
                while (reader.Read())
                {
                    CurrencyDetails obj = new CurrencyDetails();
                    obj.CurrencyId          = GetReaderValue_Int32(reader, "CurrencyId", 0);
                    obj.CurrencyCode        = GetReaderValue_String(reader, "CurrencyCode", "");
                    obj.CurrencyDescription = GetReaderValue_String(reader, "CurrencyDescription", "");
                    lst.Add(obj);
                    obj = null;
                }
                return(lst);
            } catch (SqlException sqlex) {
                //LogException(sqlex);
                throw new Exception("Failed to get Currencys", sqlex);
            } finally {
                cmd.Dispose();
                cn.Close();
                cn.Dispose();
            }
        }
Beispiel #2
0
        public void EditCurrency(CurrencyDetails currencyDetails)
        {
            var currency = _currencyRepository.GetById(currencyDetails.Id);

            currency.Name   = currencyDetails.Name;
            currency.Symbol = currencyDetails.Symbol;
            _currencyRepository.Update(currency);
        }
Beispiel #3
0
        public CurrencyDetails FindCurrency(string currencyCode)
        {
            CurrencyDetails currency = _currencies.FirstOrDefault(
                x => x.CurrencyCode == currencyCode
                );

            return(currency ?? CurrencyDetails.None);
        }
        private static decimal CalculateFinalAmount(long amount, CurrencyDetails firstCurrencyDetails, CurrencyDetails secondCurrencyDetails)
        {
            double firstCoursePLN  = firstCurrencyDetails.rates.FirstOrDefault().mid;
            double secondCoursePLN = secondCurrencyDetails.rates.FirstOrDefault().mid;

            decimal result = (decimal)(amount * (firstCoursePLN / secondCoursePLN));

            return(Math.Round(result, 2));
        }
        /// <summary>
        /// GetListForClient
        /// Calls [usp_selectAll_localCurrency_for_Client]
        /// </summary>
        public override List <CurrencyDetails> GetLocalListForClient(System.Int32?clientId, out string clientLocalCurrencyDescription, out System.Int32?clientLocalCurrencyNo)
        {
            clientLocalCurrencyDescription = string.Empty;
            clientLocalCurrencyNo          = null;

            SqlConnection cn  = null;
            SqlCommand    cmd = null;

            try
            {
                cn                 = new SqlConnection(this.ConnectionString);
                cmd                = new SqlCommand("usp_selectAll_localCurrency_for_Client", cn);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = 30;
                cmd.Parameters.Add("@ClientId", SqlDbType.Int).Value = clientId;
                cn.Open();
                SqlDataReader          reader = cmd.ExecuteReader();
                List <CurrencyDetails> lst    = new List <CurrencyDetails>();
                while (reader.Read())
                {
                    CurrencyDetails obj = new CurrencyDetails();
                    obj.LocalCurrencyId     = GetReaderValue_Int32(reader, "LocalCurrencyId", 0);
                    obj.LocalExchangeRate   = GetReaderValue_NullableDouble(reader, "ExchangeRate", null);
                    obj.CurrencyId          = GetReaderValue_Int32(reader, "CurrencyNo", 0);
                    obj.CurrencyCode        = GetReaderValue_String(reader, "CurrencyCode", "");
                    obj.CurrencyDescription = GetReaderValue_String(reader, "CurrencyDescription", "");
                    obj.Symbol   = GetReaderValue_String(reader, "Symbol", "");
                    obj.ClientNo = GetReaderValue_Int32(reader, "ClientNo", 0);
                    obj.DLUP     = GetReaderValue_DateTime(reader, "DLUP", DateTime.MinValue);
                    obj.Inactive = GetReaderValue_Boolean(reader, "Inactive", false);
                    lst.Add(obj);
                    obj = null;
                }
                if (reader.NextResult())
                {
                    while (reader.Read())
                    {
                        clientLocalCurrencyDescription = GetReaderValue_String(reader, "ClientLocalCurrencyDescription", "");
                        clientLocalCurrencyNo          = GetReaderValue_Int32(reader, "ClientLocalCurrencyNo", 0);
                    }
                }

                return(lst);
            }
            catch (SqlException sqlex)
            {
                //LogException(sqlex);
                throw new Exception("Failed to get Local Currencys", sqlex);
            }
            finally
            {
                cmd.Dispose();
                cn.Close();
                cn.Dispose();
            }
        }
        public static Calculation GetCalculation(long amount, CurrencyDetails firstCurrencyDetails, CurrencyDetails secondCurrencyDetails)
        {
            Calculation calculation = new Calculation();

            calculation.From          = firstCurrencyDetails.code;
            calculation.To            = secondCurrencyDetails.code;
            calculation.InitialAmount = amount;
            calculation.FinalAmount   = CalculateFinalAmount(amount, firstCurrencyDetails, secondCurrencyDetails);
            return(calculation);
        }
        public async Task <CurrencyDetails> GetCurrencyCourse(string currencyCode)
        {
            string uri      = ApplicationHelper.GetApiClientURL(currencyCode);
            var    response = await _httpClient.GetAsync(uri);

            response.EnsureSuccessStatusCode();
            var content = await response.Content.ReadAsStringAsync();

            CurrencyDetails currencyCourse = JsonConvert.DeserializeObject <CurrencyDetails>(content);

            return(currencyCourse);
        }
        private static void GetWolrdCurrencyInfo(List <int> location)
        {
            if (!IsGettingWolrdCurrency)
            {
                IsGettingWolrdCurrency = true;
                ItemStoreServices.GetCurrencyInfo(worldCurrencyInfo =>
                {
                    ItemTextureCache.GetItemTexture(worldCurrencyInfo.PremiumCurrencyImage, icon =>
                    {
                        PremiumInfo = new CurrencyDetails()
                        {
                            Name = worldCurrencyInfo.PremiumCurrencyName,
                            Icon = icon
                        };
                        if (RecivedPremiumDetails != null)
                        {
                            RecivedPremiumDetails(PremiumInfo.Name, PremiumInfo.Icon);
                        }
                    });
                    ItemStoreServices.GetPremiumCurrencyBalance(premiumCurrencyResponse =>
                    {
                        PremiumAmount = premiumCurrencyResponse.Amount;
                        if (RecivecdPremiumAmount != null)
                        {
                            RecivecdPremiumAmount(premiumCurrencyResponse.Amount);
                        }
                    });

                    ItemTextureCache.GetItemTexture(worldCurrencyInfo.StandardCurrencyImage, icon =>
                    {
                        StandardInfo = new CurrencyDetails()
                        {
                            Name = worldCurrencyInfo.StandardCurrencyName,
                            Icon = icon
                        };
                        if (RecivedStandardDetails != null)
                        {
                            RecivedStandardDetails(StandardInfo.Name, StandardInfo.Icon);
                        }
                    });
                    ItemStoreServices.GetStandardCurrencyBalance(new StandardCurrencyBalanceRequest(StandardCurrencyLoaction), standardCurrencybalance =>
                    {
                        StandardAmount = standardCurrencybalance.Total;
                        if (RecivecdStandardAmount != null)
                        {
                            RecivecdStandardAmount(standardCurrencybalance.Total);
                        }
                    });
                });
            }
        }
        /// <summary>
        /// GetListForClient
        /// Calls [usp_selectAll_Currency_for_Client]
        /// </summary>
        public override List <CurrencyDetails> GetListForClient(System.Int32?clientId, System.Boolean?includeInactive)
        {
            SqlConnection cn  = null;
            SqlCommand    cmd = null;

            try {
                cn                 = new SqlConnection(this.ConnectionString);
                cmd                = new SqlCommand("usp_selectAll_Currency_for_Client", cn);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = 30;
                cmd.Parameters.Add("@ClientId", SqlDbType.Int).Value        = clientId;
                cmd.Parameters.Add("@IncludeInactive", SqlDbType.Bit).Value = includeInactive;
                cn.Open();
                DbDataReader           reader = ExecuteReader(cmd);
                List <CurrencyDetails> lst    = new List <CurrencyDetails>();
                while (reader.Read())
                {
                    CurrencyDetails obj = new CurrencyDetails();
                    obj.CurrencyId          = GetReaderValue_Int32(reader, "CurrencyId", 0);
                    obj.GlobalCurrencyNo    = GetReaderValue_Int32(reader, "GlobalCurrencyNo", 0);
                    obj.CurrencyCode        = GetReaderValue_String(reader, "CurrencyCode", "");
                    obj.CurrencyDescription = GetReaderValue_String(reader, "CurrencyDescription", "");
                    obj.Symbol    = GetReaderValue_String(reader, "Symbol", "");
                    obj.ClientNo  = GetReaderValue_Int32(reader, "ClientNo", 0);
                    obj.Buy       = GetReaderValue_Boolean(reader, "Buy", false);
                    obj.Sell      = GetReaderValue_Boolean(reader, "Sell", false);
                    obj.Inactive  = GetReaderValue_Boolean(reader, "Inactive", false);
                    obj.UpdatedBy = GetReaderValue_NullableInt32(reader, "UpdatedBy", null);
                    obj.DLUP      = GetReaderValue_DateTime(reader, "DLUP", DateTime.MinValue);
                    obj.ClientDefaultCurrencyCode = GetReaderValue_String(reader, "ClientDefaultCurrencyCode", "");
                    obj.ClientDefaultCurrencyNo   = GetReaderValue_Int32(reader, "ClientDefaultCurrencyNo", 0);
                    //[001] code start
                    obj.Notes = GetReaderValue_String(reader, "Notes", "");
                    //[001] code end
                    lst.Add(obj);
                    obj = null;
                }
                return(lst);
            } catch (SqlException sqlex) {
                //LogException(sqlex);
                throw new Exception("Failed to get Currencys", sqlex);
            } finally {
                cmd.Dispose();
                cn.Close();
                cn.Dispose();
            }
        }
        /// <summary>
        /// Get
        /// Calls [usp_select_Currency]
        /// </summary>
        public override CurrencyDetails Get(System.Int32?currencyId)
        {
            SqlConnection cn  = null;
            SqlCommand    cmd = null;

            try {
                cn                 = new SqlConnection(this.ConnectionString);
                cmd                = new SqlCommand("usp_select_Currency", cn);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = 30;
                cmd.Parameters.Add("@CurrencyId", SqlDbType.Int).Value = currencyId;
                cn.Open();
                DbDataReader reader = ExecuteReader(cmd, CommandBehavior.SingleRow);
                if (reader.Read())
                {
                    //return GetCurrencyFromReader(reader);
                    CurrencyDetails obj = new CurrencyDetails();
                    obj.CurrencyId          = GetReaderValue_Int32(reader, "CurrencyId", 0);
                    obj.CurrencyCode        = GetReaderValue_String(reader, "CurrencyCode", "");
                    obj.CurrencyDescription = GetReaderValue_String(reader, "CurrencyDescription", "");
                    obj.Symbol    = GetReaderValue_String(reader, "Symbol", "");
                    obj.ClientNo  = GetReaderValue_Int32(reader, "ClientNo", 0);
                    obj.Buy       = GetReaderValue_Boolean(reader, "Buy", false);
                    obj.Sell      = GetReaderValue_Boolean(reader, "Sell", false);
                    obj.Inactive  = GetReaderValue_Boolean(reader, "Inactive", false);
                    obj.UpdatedBy = GetReaderValue_NullableInt32(reader, "UpdatedBy", null);
                    obj.DLUP      = GetReaderValue_DateTime(reader, "DLUP", DateTime.MinValue);
                    //[001] code start
                    obj.Notes = GetReaderValue_String(reader, "Notes", "");
                    //[001] code end
                    obj.GlobalCurrencyNo = GetReaderValue_Int32(reader, "GlobalCurrencyNo", 0);
                    return(obj);
                }
                else
                {
                    return(null);
                }
            } catch (SqlException sqlex) {
                //LogException(sqlex);
                throw new Exception("Failed to get Currency", sqlex);
            } finally {
                cmd.Dispose();
                cn.Close();
                cn.Dispose();
            }
        }
Beispiel #11
0
        private static Currency PopulateFromDBDetailsObject(CurrencyDetails obj)
        {
            Currency objNew = new Currency();

            objNew.CurrencyId          = obj.CurrencyId;
            objNew.GlobalCurrencyNo    = obj.GlobalCurrencyNo;
            objNew.CurrencyCode        = obj.CurrencyCode;
            objNew.CurrencyDescription = obj.CurrencyDescription;
            objNew.Symbol                    = obj.Symbol;
            objNew.ClientNo                  = obj.ClientNo;
            objNew.Buy                       = obj.Buy;
            objNew.Sell                      = obj.Sell;
            objNew.Inactive                  = obj.Inactive;
            objNew.UpdatedBy                 = obj.UpdatedBy;
            objNew.DLUP                      = obj.DLUP;
            objNew.ConvertedValue            = obj.ConvertedValue;
            objNew.ClientDefaultCurrencyCode = obj.ClientDefaultCurrencyCode;
            objNew.ClientDefaultCurrencyNo   = obj.ClientDefaultCurrencyNo;
            return(objNew);
        }
        public async Task <ApiResponse> Handle(AddCurrencyCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                if (!(await _dbContext.CurrencyDetails.AnyAsync(c => c.CurrencyCode == request.CurrencyCode)))
                {
                    CurrencyDetails obj = new CurrencyDetails
                    {
                        CurrencyCode = request.CurrencyCode,
                        CurrencyName = request.CurrencyName,
                        CreatedById  = request.CreatedById,
                        CreatedDate  = DateTime.UtcNow,
                        IsDeleted    = false
                    };

                    await _dbContext.CurrencyDetails.AddAsync(obj);

                    await _dbContext.SaveChangesAsync();

                    response.StatusCode = StaticResource.successStatusCode;
                    response.Message    = StaticResource.SuccessText;
                }
                else
                {
                    response.StatusCode = StaticResource.MandateNameAlreadyExistCode;
                    response.Message    = StaticResource.MandateNameAlreadyExist;
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = ex.Message;
            }
            return(response);
        }
        /// <summary>
        /// GetConvertedValueBetweenTwoCurrencies
        /// Calls [usp_select_Currency_ConvertedValueBetweenTwoCurrencies]
        /// </summary>
        public override CurrencyDetails GetConvertedValueBetweenTwoCurrencies(System.Double?valueToBeConverted, System.Int32?currencyFromId, System.Int32?currencyToId, System.DateTime?exchangeRateDate)
        {
            SqlConnection cn  = null;
            SqlCommand    cmd = null;

            try {
                cn                 = new SqlConnection(this.ConnectionString);
                cmd                = new SqlCommand("usp_select_Currency_ConvertedValueBetweenTwoCurrencies", cn);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = 30;
                cmd.Parameters.Add("@ValueToBeConverted", SqlDbType.Float).Value  = valueToBeConverted;
                cmd.Parameters.Add("@CurrencyFromId", SqlDbType.Int).Value        = currencyFromId;
                cmd.Parameters.Add("@CurrencyToId", SqlDbType.Int).Value          = currencyToId;
                cmd.Parameters.Add("@ExchangeRateDate", SqlDbType.DateTime).Value = exchangeRateDate;
                cn.Open();
                DbDataReader reader = ExecuteReader(cmd, CommandBehavior.SingleRow);
                if (reader.Read())
                {
                    //return GetCurrencyFromReader(reader);
                    CurrencyDetails obj = new CurrencyDetails();
                    obj.ConvertedValue = GetReaderValue_NullableDouble(reader, "ConvertedValue", null);
                    return(obj);
                }
                else
                {
                    return(null);
                }
            } catch (SqlException sqlex) {
                //LogException(sqlex);
                throw new Exception("Failed to get Currency", sqlex);
            } finally {
                cmd.Dispose();
                cn.Close();
                cn.Dispose();
            }
        }
        public async Task <ApiResponse> Handle(GetProcurementSummaryQuery request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                CurrencyDetails currencyDetails = await _dbContext.CurrencyDetails.FirstOrDefaultAsync(x => x.IsDeleted == false && x.CurrencyId == request.CurrencyId);

                List <StorePurchaseOrder> ProcurmentData = new List <StorePurchaseOrder>();

                ProcurmentData = await _dbContext.StorePurchaseOrders
                                 .Include(x => x.StoreItemPurchase).ThenInclude(c => c.CurrencyDetails)
                                 .Include(x => x.EmployeeDetail)
                                 .Include(x => x.StoreItemPurchase.PurchaseUnitType)
                                 .Include(x => x.StoreItemPurchase.StoreInventoryItem).ThenInclude(x => x.Inventory)
                                 .Where(x => x.IssuedToEmployeeId == request.EmployeeId).ToListAsync();

                List <ProcurmentSummaryModel> lst = new List <ProcurmentSummaryModel>();

                if (ProcurmentData != null)
                {
                    foreach (var item in ProcurmentData)
                    {
                        ProcurmentSummaryModel obj = new ProcurmentSummaryModel();
                        obj.ProcurementId             = item.OrderId;
                        obj.ProcurementDate           = item.IssueDate;
                        obj.EmployeeName              = item.EmployeeDetail?.EmployeeName;
                        obj.Store                     = item.StoreInventoryItem?.Inventory?.AssetType ?? 0;
                        obj.Inventory                 = item.StoreInventoryItem?.Inventory?.InventoryName ?? null;
                        obj.Item                      = item.StoreInventoryItem?.ItemName ?? null;
                        obj.TotalCost                 = (item.IssuedQuantity) * (item.StoreItemPurchase?.UnitCost ?? 0);
                        obj.MustReturn                = item.MustReturn == true ? "Yes" : "No";
                        obj.Returned                  = item.Returned == true ? "Yes" : "No";
                        obj.TotalCostDetails.UnitType = item.StoreItemPurchase?.PurchaseUnitType?.UnitTypeName ?? null;
                        obj.TotalCostDetails.Amount   = item.IssuedQuantity; //item.StoreItemPurchase?.Quantity ?? 0;
                        obj.TotalCostDetails.UnitCost = item.StoreItemPurchase?.UnitCost ?? 0;
                        obj.TotalCostDetails.Currency = item.StoreItemPurchase?.CurrencyDetails?.CurrencyName ?? null;
                        obj.VoucherDate               = item.StoreItemPurchase.VoucherDate;
                        obj.VoucherNo                 = item.StoreItemPurchase.VoucherId;
                        obj.CurrencyId                = item.StoreItemPurchase.Currency;
                        lst.Add(obj);
                    }

                    if (request.CurrencyId != 0)
                    {
                        //if procurement summary contains all items of currency selected in the drop down
                        bool isProcurementCurrencySame = lst.Any(x => x.CurrencyId == request.CurrencyId);

                        if (!isProcurementCurrencySame)
                        {
                            var dates = lst.Select(y => y.VoucherDate.Date).ToList();

                            List <ExchangeRateDetail> exchangeRateDetail = _dbContext.ExchangeRateDetail.Where(x => x.IsDeleted == false && x.ToCurrency == request.CurrencyId && dates.Contains(x.Date.Date)).ToList();

                            //If Exchange rate is available on voucher date
                            if (exchangeRateDetail.Any())
                            {
                                lst.ForEach(x => x.TotalCostDetails.UnitCost *= exchangeRateDetail.FirstOrDefault(y => y.Date.Date == x.VoucherDate.Date && y.FromCurrency == x.CurrencyId && y.ToCurrency == request.CurrencyId).Rate);
                                lst.ForEach(x => x.TotalCost = x.TotalCostDetails.Amount * x.TotalCostDetails.UnitCost);
                                lst.ForEach(x => x.TotalCostDetails.Currency = currencyDetails.CurrencyName);
                            }
                            else //If Exchange rate is not available on voucher date then take the latest exchange rate updated previously from voucher date
                            {
                                foreach (var obj in lst)
                                {
                                    var exchangeRate = await _dbContext.ExchangeRateDetail.OrderByDescending(x => x.Date).FirstOrDefaultAsync(x => x.IsDeleted == false && x.FromCurrency == obj.CurrencyId && x.ToCurrency == request.CurrencyId && x.Date.Date <= obj.VoucherDate.Date);

                                    if (exchangeRate != null)
                                    {
                                        obj.TotalCostDetails.UnitCost *= exchangeRate.Rate;
                                        obj.TotalCost = obj.TotalCostDetails.Amount * obj.TotalCostDetails.UnitCost;
                                        lst.ForEach(x => x.TotalCostDetails.Currency = currencyDetails.CurrencyName);
                                    }
                                    else
                                    {
                                        throw new Exception("Exchange Rate Not Defined");
                                    }
                                }
                            }
                        }
                    }
                }

                response.data.ProcurmentSummaryModelList = lst;
                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + " " + ex.Message;
                return(response);
            }
            return(response);
        }
Beispiel #15
0
        public void CreateCurrency(CurrencyDetails currencyDetails)
        {
            var currency = Mapper.Map <Currency>(currencyDetails);

            _currencyRepository.Create(currency);
        }
 public void Post([FromBody] CurrencyDetails createdObj)
 {
     _currencyService.CreateCurrency(createdObj);
 }
        public async Task <VoucherDetailEntityModel> AddVoucherDetail(AddVoucherDetailCommand request)
        {
            try
            {
                request.TimezoneOffset = request.TimezoneOffset > 0 ? request.TimezoneOffset * -1 : Math.Abs(request.TimezoneOffset.Value);

                DateTime filterVoucherDate = request.VoucherDate.AddMinutes(request.TimezoneOffset.Value);

                Task <List <CurrencyDetails> > currencyListTask = _dbContext.CurrencyDetails.Where(x => x.IsDeleted == false).ToListAsync();

                if (request.IsExchangeGainLossVoucher)
                {
                    request.VoucherDate = DateTime.UtcNow;
                }

                Task <List <ExchangeRateDetail> > exchangeRatePresentTask = _dbContext.ExchangeRateDetail.Where(x => x.Date.Date == request.VoucherDate.Date && x.IsDeleted == false).ToListAsync();

                List <CurrencyDetails> currencyList = await currencyListTask;

                List <int> currencyIds = currencyList.Select(x => x.CurrencyId).ToList();

                string currencyCode = currencyList.FirstOrDefault(x => x.CurrencyId == request.CurrencyId).CurrencyCode;

                List <ExchangeRateDetail> exchangeRatePresent = await exchangeRatePresentTask;

                if (!CheckExchangeRateIsPresent(currencyIds, exchangeRatePresent))
                {
                    throw new Exception(StaticResource.ExchagneRateNotDefined);
                }

                var officeDetail = await _dbContext.OfficeDetail.FirstOrDefaultAsync(o => o.OfficeId == request.OfficeId); //use OfficeCode

                if (officeDetail == null)
                {
                    throw new Exception(StaticResource.officeCodeNotFound);
                }

                Task <FinancialYearDetail> financialYearTask  = _dbContext.FinancialYearDetail.FirstOrDefaultAsync(o => o.IsDefault);
                Task <CurrencyDetails>     currencyDetailTask = _dbContext.CurrencyDetails.FirstOrDefaultAsync(o => o.CurrencyId == request.CurrencyId);

                // NOTE: Dont remove this as we will need journal details in response
                Task <JournalDetail> journaldetailTask = _dbContext.JournalDetail.FirstOrDefaultAsync(o => o.JournalCode == request.JournalCode);
                int voucherCount = await _dbContext.VoucherDetail.Where(x => x.VoucherDate.Month == request.VoucherDate.Month && x.VoucherDate.Year == filterVoucherDate.Year && x.OfficeId == request.OfficeId && x.CurrencyId == request.CurrencyId).CountAsync();

                FinancialYearDetail financialYear = await financialYearTask;

                if (financialYear == null)
                {
                    throw new Exception(StaticResource.defaultFinancialYearIsNotSet);
                }

                CurrencyDetails currencyDetail = await currencyDetailTask;

                if (currencyDetail == null)
                {
                    throw new Exception(StaticResource.CurrencyNotFound);
                }

                JournalDetail journaldetail = await journaldetailTask;

                VoucherDetail obj = _mapper.Map <VoucherDetail>(request);
                obj.JournalCode     = journaldetail != null ? journaldetail.JournalCode : request.JournalCode;
                obj.FinancialYearId = financialYear.FinancialYearId;
                obj.CreatedById     = request.CreatedById;
                obj.VoucherDate     = request.VoucherDate;
                obj.CreatedDate     = DateTime.UtcNow;
                obj.IsDeleted       = false;

                // Pattern: Office Code - Currency Code - Month Number - voucher count on selected month - Year
                string referenceNo = AccountingUtility.GenerateVoucherReferenceCode(request.VoucherDate, voucherCount, currencyDetail.CurrencyCode, officeDetail.OfficeCode);

                int sameVoucherReferenceNoCount = 0;

                if (!string.IsNullOrEmpty(referenceNo))
                {
                    do
                    {
                        sameVoucherReferenceNoCount = await _dbContext.VoucherDetail.Where(x => x.ReferenceNo == referenceNo).CountAsync();

                        if (sameVoucherReferenceNoCount == 0)
                        {
                            obj.ReferenceNo = referenceNo;
                        }
                        else
                        {
                            //DO NOT REMOVE: This is used to get the latest voucher and then we will get the count of vouhcer sequence from it
                            // VoucherDetail voucherDetail = _dbContext.VoucherDetail.OrderByDescending(x => x.VoucherDate).FirstOrDefault(x => x.VoucherDate.Month == filterVoucherDate.Month && x.OfficeId == request.OfficeId && x.VoucherDate.Year == filterVoucherDate.Year);

                            var refNo = referenceNo.Split('-');
                            int count = Convert.ToInt32(refNo[3]);
                            referenceNo = AccountingUtility.GenerateVoucherReferenceCode(request.VoucherDate, count, currencyCode, officeDetail.OfficeCode);
                        }
                    }while (sameVoucherReferenceNoCount != 0);
                }

                await _dbContext.VoucherDetail.AddAsync(obj);

                await _dbContext.SaveChangesAsync();

                VoucherDetailEntityModel voucherModel = _mapper.Map <VoucherDetail, VoucherDetailEntityModel>(obj);

                return(voucherModel);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 public void Put(int id, [FromBody] CurrencyDetails editedObj)
 {
     _currencyService.EditCurrency(editedObj);
 }
        private static void GetWolrdCurrencyInfo(List<int> location)
        {
            if (!IsGettingWolrdCurrency)
            {
                IsGettingWolrdCurrency = true;
                ItemStoreServices.GetCurrencyInfo(worldCurrencyInfo =>
                {
                    ItemTextureCache.GetItemTexture(worldCurrencyInfo.PremiumCurrencyImage, icon =>
                    {
                        PremiumInfo = new CurrencyDetails()
                        {
                            Name = worldCurrencyInfo.PremiumCurrencyName,
                            Icon = icon
                        };
                        if (RecivedPremiumDetails != null)
                        {
                            RecivedPremiumDetails(PremiumInfo.Name, PremiumInfo.Icon);
                        }
                    });
                    ItemStoreServices.GetPremiumCurrencyBalance(premiumCurrencyResponse =>
                    {
                        PremiumAmount = premiumCurrencyResponse.Amount;
                        if (RecivecdPremiumAmount != null)
                        {
                            RecivecdPremiumAmount(premiumCurrencyResponse.Amount);
                        }
                    });

                    ItemTextureCache.GetItemTexture(worldCurrencyInfo.StandardCurrencyImage, icon =>
                    {
                        StandardInfo = new CurrencyDetails()
                        {
                            Name = worldCurrencyInfo.StandardCurrencyName,
                            Icon = icon
                        };
                        if (RecivedStandardDetails != null)
                        {
                            RecivedStandardDetails(StandardInfo.Name, StandardInfo.Icon);
                        }
                    });
                    ItemStoreServices.GetStandardCurrencyBalance(new StandardCurrencyBalanceRequest(StandardCurrencyLoaction), standardCurrencybalance =>
                    {
                        StandardAmount = standardCurrencybalance.Total;
                        if (RecivecdStandardAmount != null)
                        {
                            RecivecdStandardAmount(standardCurrencybalance.Total);
                        }
                    });
                });
            }
        }