public static ExpenseResponse GetAllExpenses(GetExpensesRequest request)    //Get all Expense Information regarding that User
        {
            ExpenseResponse response = new ExpenseResponse();

            using (var entities = new ExpenseProjectDBEntities())
            {
                response.ExpenseList = (from e in entities.Expenses
                                        join u in entities.Users on e.Created_User equals u.ID
                                        join s in entities.ExpenseStatuses on e.StatusId equals s.ID
                                        where ((e.Created_User == request.UserID && request.RoleID == 1) ||
                                               (e.StatusId == 2 && request.RoleID == 2) ||
                                               (e.StatusId == 3 && request.RoleID == 3))
                                        select new ExpenseDomain
                {
                    ID = e.ID,
                    TotalAmount = e.TotalAmount,
                    CreatedDate = e.CreatedDate,
                    CreatedUserID = e.Created_User,
                    CreatedUserName = u.Name,
                    CreatedUserSurname = u.Surname,
                    StatusID = e.StatusId,
                    StatusName = s.StatusDescription,
                    ModifiedByID = e.ModifiedBy,
                    ModifiedDate = e.ModifiedDate,
                    RejectDescription = e.RejectDescription
                }
                                        ).ToList();

                List <ExpenseDomain> expenses = new List <ExpenseDomain>();

                return(response);
            }
        }
Exemple #2
0
        public static ExpenseResponse ToExpenseModel(this ExpenseDTO expense)
        {
            ExpenseResponse model = new ExpenseResponse();

            model.CategoryId = expense.CategoryId;
            model.Amount     = expense.Amount;
            model.ExpenseId  = expense.ExpenseId;
            model.From       = expense.From;
            model.To         = expense.To;
            model.Name       = expense.Name;
            return(model);
        }
Exemple #3
0
 public Expense CreateFromResponse(ExpenseResponse response)
 {
     return(new Expense
     {
         Id = response.Id,
         CreateAt = response.CreateAt,
         Name = response.Name,
         Amount = response.Amount,
         DueDate = response.DueDate,
         Category = new Category(),
         Contacts = new List <Contact>()
     });
 }
Exemple #4
0
        public ExpenseResponse SaveExpense(ExpenseRequest objExpenseRequest, bool isVerified)
        {
            ExpenseResponse objExpenseResponse = null;

            try
            {
                objExpenseResponse = objExpenseBal.WriteExpense(objExpenseRequest, isVerified);
            }
            catch (Exception ex)
            {
            }
            return(objExpenseResponse);
        }
Exemple #5
0
        public async Task <List <ExpenseResponse> > GetGroupExpensesAsync(int groupID)
        {
            List <ExpenseResponse> expenses = new List <ExpenseResponse>();
            var expData = _Context.expense.Where(c => c.groupID == groupID).ToList();

            for (var i = 0; i < expData.Count; i++)
            {
                var exp = new ExpenseResponse();
                exp = await GetExpenseAsync(expData[i].expenseID);

                expenses.Add(exp);
            }
            return(expenses);
        }
Exemple #6
0
        public async Task <List <ExpenseResponse> > GetAllExpensesAsync(int id)
        {
            List <ExpenseResponse> expenses = new List <ExpenseResponse>();
            var expenseData = _Context.expense.Where(c => c.expense_Members.Any(ex => ex.commonmemberID == id) || c.created_by == id || c.user_Expenses.Any(ex => ex.userexpenseID == id)).ToList();

            for (var i = 0; i < expenseData.Count; i++)
            {
                var exp = new ExpenseResponse();
                exp = await GetExpenseAsync(expenseData[i].expenseID);

                expenses.Add(exp);
            }
            return(expenses);
        }
Exemple #7
0
        public async Task <List <ExpenseResponse> > GetIndividualExpenses(int Userid, int Friendid)
        {
            List <ExpenseResponse> bills = new List <ExpenseResponse>();
            var billData = _Context.Expense.Where(c => c.BillMembers.Any(aa => aa.SharedMemberId == Userid) && c.BillMembers.Any(aa => aa.SharedMemberId == Friendid)).OrderByDescending(c => c.CreatedDate).ToList();

            for (var i = 0; i < billData.Count; i++)
            {
                var bill = new ExpenseResponse();
                bill = await GetBillAsync(billData[i].BillId);

                bills.Add(bill);
            }
            return(bills);
        }
        public ExpenseResponse WriteExpense(ExpenseRequest objExpenseRequest, bool isVerified)
        {
            ExpenseResponse objExpenseResponse = null;

            try
            {
                objExpenseResponse = objExpenseDal.WriteExpense(objExpenseRequest, isVerified);
            }
            catch (Exception)
            {
                throw;
            }
            return(objExpenseResponse);
        }
Exemple #9
0
        public async Task <List <ExpenseResponse> > GetIndividualExpenses(int Userid, int Friendid)
        {
            List <ExpenseResponse> expenses = new List <ExpenseResponse>();
            var expData = _Context.expense.Where(c => c.expense_Members.Any(aa => aa.commonmemberID == Friendid || aa.commonmemberID == Userid) && c.user_Expenses.Any(aa => aa.userexpenseID == Userid || aa.userexpenseID == Friendid)).ToList();

            for (var i = 0; i < expData.Count; i++)
            {
                var exp = new ExpenseResponse();
                exp = await GetExpenseAsync(expData[i].expenseID);

                expenses.Add(exp);
            }

            return(expenses);
        }
Exemple #10
0
        public async Task <List <ExpenseResponse> > GetGroupExpenses(int Groupid)
        {
            List <ExpenseResponse> bills = new List <ExpenseResponse>();
            var billData = _Context.Expense.Where(c => c.GroupId == Groupid).OrderByDescending(c => c.CreatedDate).ToList();

            for (var i = 0; i < billData.Count; i++)
            {
                var bill = new ExpenseResponse();
                bill = await GetBillAsync(billData[i].BillId);

                bills.Add(bill);
            }

            return(bills);
        }
Exemple #11
0
        public async Task <ExpenseResponse> GetBillAsync(int id)
        {
            ExpenseResponse bill    = new ExpenseResponse();
            var             payers  = new List <ExpenseMemberResponse>();
            var             members = new List <ExpenseMemberResponse>();

            var billData = _Context.Expense.SingleOrDefault(c => c.BillId == id);

            bill.BillId      = billData.BillId;
            bill.BillName    = billData.BillName;
            bill.Amount      = billData.Amount;
            bill.CreatedDate = billData.CreatedDate;
            bill.GroupId     = billData.GroupId.GetValueOrDefault();

            if (bill.GroupId != 0)
            {
                var groupname = _Context.Group.SingleOrDefault(c => c.GroupId == billData.GroupId);
                bill.GroupName = groupname.GroupName;
            }
            else
            {
                bill.GroupName = "NonGroup Expense";
            }
            var name = _Context.User.SingleOrDefault(c => c.UserId == billData.CreatorId);

            bill.CreatorName = name.UserName;

            var data = _Context.ExpenseMember.Where(c => c.Billid == id).ToList();

            for (var i = 0; i < data.Count; i++)
            {
                var member = _Context.User.SingleOrDefault(c => c.UserId == data[i].SharedMemberId);
                members.Add(new ExpenseMemberResponse(member.UserId, member.UserName, data[i].AmountToPay));
            }

            var payer = _Context.Payer.Where(c => c.BillId == id).ToList();

            for (var i = 0; i < payer.Count; i++)
            {
                var p = _Context.User.SingleOrDefault(c => c.UserId == payer[i].PayerId);
                payers.Add(new ExpenseMemberResponse(p.UserId, p.UserName, payer[i].PaidAmount));
            }

            bill.Payers      = payers;
            bill.BillMembers = members;
            return(bill);
        }
Exemple #12
0
        public async Task <ExpenseResponse> GetExpense(ExpenseResponse response, string expenseText)
        {
            var expenseDocument = XDocument.Parse(expenseText);
            var expenseElements = expenseDocument.Descendants();

            var validationResult = await validator.ValidateExpense(expenseDocument);

            response.ExecutionResult.Status = validationResult.IsValid ? Constants.SUCCESS : Constants.FAILED;
            response.ExecutionResult.Errors = validationResult.ErrorMessages;

            response.CostCentre    = expenseElements?.FirstOrDefault(d => d.Name == XHelper.CostCentre)?.Value ?? "UNKNOWN";
            response.PaymentMethod = expenseElements?.FirstOrDefault(d => d.Name == XHelper.PaymentMethod)?.Value;

            decimal.TryParse(expenseElements?.FirstOrDefault(d => d.Name == XHelper.Total)?.Value, out decimal total);
            response.Total = response.TotalExcludingGST = total;
            return(response);
        }
Exemple #13
0
        public async Task <ExpenseResponse> GetExpenseAsync(int id)
        {
            ExpenseResponse expense = new ExpenseResponse();
            var             payers  = new List <ExpenseMemberResponse>();
            var             members = new List <ExpenseMemberResponse>();

            var expData = _Context.expense.SingleOrDefault(c => c.expenseID == id);

            expense.expenseID   = expData.expenseID;
            expense.expenseName = expData.expenseName;
            expense.created_at  = expData.created_at;
            expense.groupID     = expData.groupID.GetValueOrDefault();

            if (expense.groupID != 0)
            {
                var groupname = _Context.group.SingleOrDefault(c => c.groupID == expData.groupID);
                expense.group_name = groupname.group_name;
            }
            var name = _Context.user.SingleOrDefault(c => c.userID == expData.created_by);

            expense.createdBy = name.first_name;

            var data = _Context.expense_member.Where(c => c.expenseID == id).ToList();

            for (var i = 0; i < data.Count; i++)
            {
                var member = _Context.user.SingleOrDefault(c => c.userID == data[i].commonmemberID);
                members.Add(new ExpenseMemberResponse(member.userID, member.first_name, data[i].payableAmount));
            }

            var payer = _Context.user_expense.Where(c => c.expenseID == id).ToList();

            for (var i = 0; i < payer.Count; i++)
            {
                var p = _Context.user.SingleOrDefault(c => c.userID == payer[i].user_expense_id);
                payers.Add(new ExpenseMemberResponse(p.userID, p.first_name, payer[i].paid_share));
            }

            expense.payers         = payers;
            expense.expenseMembers = members;

            return(expense);
        }
        public async Task <ExpenseResponse> CreateExpense(ExpenseRequest request)
        {
            var response = new ExpenseResponse();

            response.Request = request;

            // Get all XML tags. If no XML tags, return error
            logger.LogInformation <PaymentController>("Extracting XML tags");
            var tags = await parser.GetXmlTagsAsync(request.RawText);

            if (tags == null || !tags.Any())
            {
                response.ExecutionResult = new ExecutionResult
                {
                    Status = Constants.FAILED,
                    Errors = new List <string> {
                        Constants.NO_XML_TAGS
                    }
                };
                return(response);
            }

            // Find "expense" tag. If no expense, return error
            logger.LogInformation <PaymentController>("Finding Expense tag");
            var expense = tags.FirstOrDefault(t => t.Length > 9 && t.Substring(0, 9) == Constants.EXPENSE_TAG);

            if (string.IsNullOrWhiteSpace(expense))
            {
                response.ExecutionResult = new ExecutionResult
                {
                    Status = Constants.FAILED,
                    Errors = new List <string> {
                        Constants.MISSING_EXPENSE
                    }
                };
                return(response);
            }

            // Validate XML for its format
            logger.LogInformation <PaymentController>("Validating all XML tags");
            var xmlValidator = await validator.ValidateXmlTags(tags);

            if (!xmlValidator.IsValid)
            {
                response.ExecutionResult = new ExecutionResult
                {
                    Status = Constants.FAILED,
                    Errors = new List <string>(xmlValidator.ErrorMessages)
                };
                return(response);
            }

            // Parse "expense"
            logger.LogInformation <PaymentController>("Parsing Expense");
            response = await parser.GetExpense(response, expense);

            if (decimal.TryParse(configuration[Configuration.GST], out decimal gst))
            {
                response.TotalExcludingGST = Math.Round(response.Total - (response.Total * gst) / 100, Configuration.RoundingDecimals);
            }
            return(response);
        }
        public ExpenseResponse WriteExpense(ExpenseRequest objExpenseRequest, bool isVerified)
        {
            ExpenseResponse objExpenseResponse = new ExpenseResponse();

            try
            {
                SqlParameter[] sqlparams =
                {
                    new SqlParameter("@ExpenseId", SqlDbType.Int)
                    {
                        Value = objExpenseRequest.ExpenseId
                    },
                    new SqlParameter("@ExpenseTypeId", SqlDbType.Int)
                    {
                        Value = objExpenseRequest.ExpenseTypeId
                    },
                    new SqlParameter("@Amount", SqlDbType.Decimal)
                    {
                        Value = objExpenseRequest.Amount
                    },
                    new SqlParameter("@ExpenseTo", SqlDbType.VarChar)
                    {
                        Value = objExpenseRequest.ExpenseTo
                    },
                    new SqlParameter("@ContactNumber", SqlDbType.VarChar)
                    {
                        Value = objExpenseRequest.ContactNumber
                    },
                    new SqlParameter("@DateOfExpense", SqlDbType.Date)
                    {
                        Value = objExpenseRequest.DateOfExpense
                    },
                    new SqlParameter("@Remarks", SqlDbType.VarChar)
                    {
                        Value = objExpenseRequest.Remarks
                    },
                    new SqlParameter("@EditRemarks", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrEmpty(objExpenseRequest.EditRemarks) ? (object)DBNull.Value : objExpenseRequest.EditRemarks
                    },
                    new SqlParameter("@CreatedBy", SqlDbType.Int)
                    {
                        Value = Convert.ToInt32(CommonMethods.URLKeyDecrypt(objExpenseRequest.CreatedBy))
                    },
                    new SqlParameter("@CounterId", SqlDbType.Int)
                    {
                        Value = Convert.ToInt32(CommonMethods.URLKeyDecrypt(objExpenseRequest.CounterId))
                    },
                    new SqlParameter("@IsVerified", SqlDbType.Bit)
                    {
                        Value = isVerified
                    },
                };
                SqlDataReader reader = SqlHelper.ExecuteReader(con, CommandType.StoredProcedure, "USP_WriteExpense", sqlparams);
                while (reader.Read())
                {
                    if (objExpenseResponse.objSaveResponse == null)
                    {
                        objExpenseResponse.objSaveResponse          = new SaveRespone();
                        objExpenseResponse.objSaveResponse.StatusId = (int)reader["StatusId"];
                        if (objExpenseResponse.objSaveResponse.StatusId == 1)
                        {
                            objExpenseResponse.objSaveResponse.StatusMessage = "Expense added successfully.";
                        }
                        else if (objExpenseResponse.objSaveResponse.StatusId == 2)
                        {
                            objExpenseResponse.objSaveResponse.StatusMessage = "We found records similar to this entry.";
                        }
                        else if (objExpenseResponse.objSaveResponse.StatusId == 3)
                        {
                            objExpenseResponse.objSaveResponse.StatusMessage = "Date: " + objExpenseRequest.DateOfExpense + " expenses summary is closed, You can't enter expenses for the selected date.";
                        }
                    }
                    else if (objExpenseResponse.objSaveResponse.StatusId == 2)
                    {
                        objExpenseResponse.objExpenseRequest               = new ExpenseRequest();
                        objExpenseResponse.objExpenseRequest.ExpenseId     = Convert.ToInt32(reader["ExpenseId"]);
                        objExpenseResponse.objExpenseRequest.ExpenseTypeId = Convert.ToInt32(reader["ExpenseTypeId"]);
                        objExpenseResponse.objExpenseRequest.ExpenseType   = Convert.ToString(reader["ExpenseType"]);
                        objExpenseResponse.objExpenseRequest.Amount        = Convert.ToDecimal(reader["Amount"]);
                        objExpenseResponse.objExpenseRequest.Remarks       = Convert.ToString(reader["Remarks"]);
                    }
                    reader.NextResult();
                }
            }
            catch (Exception ex)
            {
                objExpenseResponse.objSaveResponse.StatusMessage = "oops something went wrong, please try again ";
                //throw;
            }
            return(objExpenseResponse);
        }