Пример #1
0
        public JsonResult AddExpense(int PropertyID, Expense expenseObj)
        {
            JsonResult result = new JsonResult();

            if (ModelState.IsValid)
            {
                using (db)
                {
                    UserAccount usr = db.UserAccounts.Where(u => u.UserName.Equals(User.Identity.Name.ToString())).FirstOrDefault();

                    UserExpense usrExpense = new UserExpense
                    {
                        UserID     = usr.UserID,
                        PropertyID = PropertyID,
                        ExpenseID  = expenseObj.ExpenseID
                    };
                    db.Expenses.Add(expenseObj);
                    db.UserExpenses.Add(usrExpense);

                    db.SaveChanges();
                    result.Data = new { Success = true };
                }
            }
            else
            {
                result.Data = new { Success = false, Error = "Unable to save. Please enter valid values." };
            }
            return(result);
        }
Пример #2
0
        public async Task <UserInExpense> AddUser(UserInExpense userInExpense, int expId)
        {
            //int expId = GetExpenseId(userInExpense.Date);
            List <UserExpense> list = new List <UserExpense>();

            foreach (var i in userInExpense.GroupUsersExpenses)
            {
                UserExpense userExpense = new UserExpense();
                userExpense.ExpId       = expId;
                userExpense.UsersId     = i.UserId;
                userExpense.SplitAmount = i.Amount;
                list.Add(userExpense);
            }
            await context.UserExpenses.AddRangeAsync(list);

            return(userInExpense);
        }
        public JsonResult Delete(string id)
        {
            try
            {
                logger.DebugFormat("Deleting User Expense With CardExpenseID [{0}] ", id);


                if (!PermissionControl.CheckPermission(UserAppPermissions.ALP_Costing_Delete))
                {
                    logger.Info("Don't have right to delete User Expense record");
                    return(Json(new { Message = Resources.Messages.MSG_RESTRICTED_ACCESS, MessageClass = MessageClass.Error, Response = false }));
                }

                UserExpense userExpense = userExpenseManagement.GetUserExpense(id);

                userExpense.IsActive = false;
                if (userExpenseManagement.Delete(userExpense))
                {
                    userExpenseManagement.SaveUserExpense();
                    logger.Info("User Expense record Successfully Deleted");
                    var billing = userAllocationBillingManagement.GetUserAllocationBillingByExpenseId(userExpense.UserExpenseID);
                    if (billing != null)
                    {
                        billing.IsDeleted = true;
                        userAllocationBillingManagement.Update(billing);
                    }
                    userAllocationBillingManagement.SaveUserAllocationBilling();
                    return(Json(new { Message = Resources.Messages.MSG_GENERIC_DELETE_SUCCESS, MessageClass = MessageClass.Success, Response = true }));
                }
                else
                {
                    logger.Info("User Expense record Not Deleted");
                    return(Json(new { Message = Resources.Messages.MSG_GENERIC_DELETE_FAILED, MessageClass = MessageClass.Error, Response = false }));
                }
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Exception Raised : Message[{0}] Stack Trace [{1}] ", ex.Message, ex.StackTrace);
                return(Json(new { Message = Resources.Messages.MSG_GENERIC_DELETE_FAILED, MessageClass = MessageClass.Error, Response = false }));
            }
        }
        public async Task <ActionResult> AssignExpense(NewUserExpenseRequest newRequest)
        {
            var user = await _userManager.FindByNameAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var expenseWithId = _context.Expense.Find(newRequest.ExpenseId);

            if (expenseWithId == null)
            {
                return(BadRequest());
            }

            var userExpense = new UserExpense
            {
                ApplicationUser = user,
                Percent         = newRequest.Percent,
                Expense         = expenseWithId
            };

            _context.UsersExpenses.Add(userExpense);
            await _context.SaveChangesAsync();

            return(Ok());
        }
 public bool Update(UserExpense model)
 {
     return(userExpenseRepository.Update(model));
 }
 public bool Add(UserExpense model)
 {
     return(userExpenseRepository.Add(model));
 }
 public bool Delete(UserExpense model)
 {
     model.LastModified = DateTime.Now;
     return(userExpenseRepository.Update(model));
 }
        private ExcelFileProcess InsertData(DataTable dt, string fileName, List <ApplicationUser> users, DateTime expenseDate, IEnumerable <UserAllocation> userAllocation)
        {
            try
            {
                logger.DebugFormat("Checking existing expense date record exist");
                var expenses = userExpenseManagement.GetAllExpenseByDate(expenseDate);
                logger.DebugFormat("Successfully retrieve user expenses [{0}] record  regarding date [{1}]", expenses.Count(), expenseDate.ToShortDateString());
                if (expenses.Count() > 0)
                {
                    logger.DebugFormat("Deleting existing user allocation billing by date [{0}] records ", expenseDate.ToShortDateString());
                    userAllocationBillingManagement.DeleteAllByDate(expenseDate);
                    userAllocationBillingManagement.SaveUserAllocationBilling();
                    logger.DebugFormat("Successfully deleted user allocation billing by expense date [{0}] records ", expenseDate.ToShortDateString());

                    logger.DebugFormat("Deleting existing expense by date [{0}] records ", expenseDate.ToShortDateString());
                    userExpenseManagement.DeleteAllByDate(expenseDate);
                    userExpenseManagement.SaveUserExpense();
                    logger.DebugFormat("Successfully deleted existing expense by date [{0}] records ", expenseDate.ToShortDateString());
                }



                logger.DebugFormat("Inserting User Expense Sheet Data from File [{0}]", fileName);
                foreach (DataRow row in dt.Rows)
                {
                    UserExpense userExp    = new UserExpense();
                    var         department = departmentManagement.GetDepartment(Convert.ToString(row[UserExpenseMandatoryColumn.Department]));
                    if (department == null)
                    {
                        logger.DebugFormat(string.Format(Resources.Messages.MSG_GENERIC_UPLOAD_DEPARTMENT_NOT_FOUND, Convert.ToString(row[UserExpenseMandatoryColumn.Department])));
                        department = CreateNewDepartment(Convert.ToString(row[UserExpenseMandatoryColumn.Department]), Convert.ToString(row[UserExpenseMandatoryColumn.Department_Type]));
                    }

                    ApplicationUser user = users.Where(x => x.EmployeeNumber == Convert.ToString(row[UserExpenseMandatoryColumn.Employee_Number])).FirstOrDefault();
                    if (user == null)
                    {
                        logger.DebugFormat(string.Format(Resources.Messages.MSG_GENERIC_UPLOAD_EMP_NUMBER_NOT_FOUND, Convert.ToString(row[UserExpenseMandatoryColumn.Employee_Number]), Convert.ToString(row[UserExpenseMandatoryColumn.Employee_Name])));
                        user = CreateNewUser(Convert.ToString(row[UserExpenseMandatoryColumn.Employee_Number]), Convert.ToString(row[UserExpenseMandatoryColumn.Employee_Name]), department.DepartmentID);
                    }

                    var expenseId = Guid.NewGuid();
                    userExp.UserExpenseID = expenseId;
                    userExp.DepartmentID  = department.DepartmentID;
                    userExp.UserID        = user.Id;
                    userExp.ExpenseDate   = expenseDate;
                    userExp.IsActive      = true;
                    userExp.CreatedBy     = new Guid(User.Identity.GetUserId());

                    userExp.Monthly_Salary      = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Monthly_Salary])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Monthly_Salary]);
                    userExp.Monthly_Salary2     = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Monthly_Salary2])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Monthly_Salary2]);
                    userExp.EOBI_Employer       = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.EOBI_Employer])) ? 0 : Convert.ToDecimal(row[UserExpenseType.EOBI_Employer]);
                    userExp.PF_Employer         = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.PF_Employer])) ? 0 : Convert.ToDecimal(row[UserExpenseType.PF_Employer]);
                    userExp.Mobile_Allowance    = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Mobile_Allowance])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Mobile_Allowance]);
                    userExp.Bonus               = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Bonus])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Bonus]);
                    userExp.Meal_Reimbursement  = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Meal_Reimbursement])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Meal_Reimbursement]);
                    userExp.Transportation      = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Transportation])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Transportation]);
                    userExp.Leave_Encashment    = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Leave_Encashment])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Leave_Encashment]);
                    userExp.Incentive_PSM       = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Incentive_PSM])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Incentive_PSM]);
                    userExp.Health_Insurance    = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Health_Insurance])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Health_Insurance]);
                    userExp.Medical_OPD         = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Medical_OPD])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Medical_OPD]);
                    userExp.Billable_Salary_PKR = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Billable_Salary_PKR])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Billable_Salary_PKR]);
                    userExp.Billable_Salary_USD = string.IsNullOrEmpty(Convert.ToString(row[UserExpenseType.Billable_Salary_USD])) ? 0 : Convert.ToDecimal(row[UserExpenseType.Billable_Salary_USD]);
                    userExp.SerialNumber        = DateTime.Now.Ticks.ToString();


                    userExpenseManagement.Add(userExp);
                    userExpenseManagement.SaveUserExpense();

                    AddUserAlloctionBilling(expenseId, user.Id, userAllocation, userExp.Billable_Salary_PKR, userExp.Billable_Salary_USD, expenseDate);
                }


                logger.DebugFormat("Successfully Inserted User Expense Sheet Data from File [{0}]", fileName);
                return(new ExcelFileProcess {
                    Message = string.Format(Resources.Messages.MSG_GENERIC_UPLOAD_SUCCESS, fileName), Response = true, MessageType = MessageClass.Success
                });
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Exception Raised : Message[{0}] Stack Trace [{1}] ", ex.Message, ex.StackTrace);
                return(new ExcelFileProcess {
                    Message = string.Format(Resources.Messages.MSG_GENERIC_UPDATE_FAILED, fileName), Response = false, MessageType = MessageClass.Error
                });
            }
        }