예제 #1
0
        public string GetAllOtherExpenses(string ExpenseDate, string DefaultDate)
        {
            try
            {
                List <OtherExpenseViewModel> otherExpenseViewModelList = Mapper.Map <List <OtherExpense>, List <OtherExpenseViewModel> >(_otherExpenseBusiness.GetAllOtherExpenses());
                if (!string.IsNullOrEmpty(ExpenseDate))
                {
                    otherExpenseViewModelList = otherExpenseViewModelList != null?otherExpenseViewModelList
                                                .Where(o => o.ExpenseDate == ExpenseDate)
                                                .ToList() : null;
                }
                else if (!string.IsNullOrEmpty(DefaultDate))
                {
                    if (DefaultDate == "0")
                    {
                        otherExpenseViewModelList = otherExpenseViewModelList != null?otherExpenseViewModelList
                                                    .ToList() : null;
                    }
                    else
                    {
                        //DefaultDate is no. of days coming ie 30 or 60 days
                        ExpenseDate = DateTime.Now.AddDays(-int.Parse(DefaultDate)).ToString("dd-MMM-yyyy");
                        //JobList = JobList == null ? null : JobList.Where(stype => stype.SCCode == SCCode && stype.Employee.ID == id && DateTime.Parse(stype.ServiceDate) == DateTime.Parse(servicedate)).ToList();
                        otherExpenseViewModelList = otherExpenseViewModelList != null?otherExpenseViewModelList
                                                    .Where(o => DateTime.Parse(o.ExpenseDate).Date >= DateTime.Parse(ExpenseDate).Date && DateTime.Parse(o.ExpenseDate).Date <= DateTime.Now.Date)
                                                    .ToList() : null;
                    }
                }
                string totamt = _commonBusiness.ConvertCurrency(otherExpenseViewModelList != null ? otherExpenseViewModelList.Sum(o => o.Amount):decimal.Zero);

                return(JsonConvert.SerializeObject(new { Result = "OK", Records = otherExpenseViewModelList, TotalAmount = totamt }));
            }
            catch (Exception ex)
            {
                AppConstMessage cm = c.GetMessage(ex.Message);
                return(JsonConvert.SerializeObject(new { Result = "ERROR", Message = cm.Message }));
            }
        }