示例#1
0
        public async Task <ApiResponse> Handle(GetAllHolidayDetailsQuery request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                FinancialYearDetail financialyear = await _dbContext.FinancialYearDetail.FirstOrDefaultAsync(x => x.IsDefault == true);

                IList <HolidayDetails> holidaylist = await _dbContext.HolidayDetails
                                                     .Where(x => x.IsDeleted == false &&
                                                            x.OfficeId == request.OfficeId &&
                                                            x.FinancialYearId == financialyear.FinancialYearId)
                                                     .ToListAsync();


                response.data.HolidayDetailsList = holidaylist;
                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = ex.Message;
            }
            return(response);
        }
        public ActionResult CreateFYear(FinancialYearDetail objFYD)
        {
            DateTime yearstart = Convert.ToDateTime(objFYD.YearStart.ToString());
            DateTime yearend   = Convert.ToDateTime(objFYD.YearEnd.ToString());
            string   Totaldays = yearend.Subtract(yearstart).TotalDays.ToString();

            objFYD.TotalDays = Totaldays;
            int Totalworkingdays = int.Parse(Totaldays) - int.Parse(objFYD.NonWorkingDays);

            objFYD.TotalWorkingDays = Totalworkingdays.ToString();
            objEmpBLL.CreateFYear(objFYD);
            return(View());
        }
示例#3
0
        public async Task <ApiResponse> Handle(AddFinancialYearDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                List <FinancialYearDetail> yearlist = await _dbContext.FinancialYearDetail.Where(x => x.IsDeleted == false).ToListAsync();

                if (yearlist != null)
                {
                    if (request.IsDefault == true)
                    {
                        foreach (var i in yearlist)
                        {
                            FinancialYearDetail existrecord = await _dbContext.FinancialYearDetail.FirstOrDefaultAsync(x => x.IsDeleted == false && x.FinancialYearId == i.FinancialYearId);

                            existrecord.IsDefault    = false;
                            existrecord.ModifiedById = request.ModifiedById;
                            existrecord.ModifiedDate = request.ModifiedDate;
                            await _dbContext.SaveChangesAsync();
                        }
                    }
                    FinancialYearDetail obj = new FinancialYearDetail
                    {
                        StartDate         = request.StartDate,
                        EndDate           = request.EndDate,
                        FinancialYearName = request.FinancialYearName,
                        Description       = request.Description,
                        IsDefault         = request.IsDefault,
                        CreatedById       = request.CreatedById,
                        CreatedDate       = DateTime.UtcNow,
                    };
                    await _dbContext.FinancialYearDetail.AddAsync(obj);

                    await _dbContext.SaveChangesAsync();
                }

                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = ex.Message;
            }
            return(response);
        }
        public async Task <ApiResponse> Handle(EditFinancialYearDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                FinancialYearDetail existrecord = await _dbContext.FinancialYearDetail.FirstOrDefaultAsync(x => x.IsDeleted == false && x.FinancialYearId == request.FinancialYearId);

                if (existrecord != null)
                {
                    if (request.IsDefault == true)
                    {
                        List <FinancialYearDetail> yearlist = await _dbContext.FinancialYearDetail.Where(x => x.IsDeleted == false).ToListAsync();

                        foreach (var i in yearlist)
                        {
                            var existrecord1 = await _dbContext.FinancialYearDetail.FirstOrDefaultAsync(x => x.IsDeleted == false && x.FinancialYearId == i.FinancialYearId);

                            existrecord1.IsDefault    = false;
                            existrecord1.ModifiedById = request.ModifiedById;
                            existrecord1.ModifiedDate = request.ModifiedDate;
                            await _dbContext.SaveChangesAsync();
                        }
                    }

                    existrecord.FinancialYearName = request.FinancialYearName;
                    existrecord.StartDate         = request.StartDate;
                    existrecord.EndDate           = request.EndDate;
                    existrecord.Description       = request.Description;
                    existrecord.IsDefault         = request.IsDefault;
                    existrecord.ModifiedById      = request.ModifiedById;
                    existrecord.ModifiedDate      = request.ModifiedDate;
                    existrecord.IsDeleted         = request.IsDeleted;

                    await _dbContext.SaveChangesAsync();

                    response.StatusCode = StaticResource.successStatusCode;
                    response.Message    = "Success";
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = ex.Message;
            }
            return(response);
        }
        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);
            }
        }
示例#6
0
 public void CreateFYear(FinancialYearDetail objFYD)
 {
     objEmpDAL.CreateFYear(objFYD);
 }