2002 lines
88 KiB
C#
2002 lines
88 KiB
C#
using AutoMapper;
|
|
using HRM.DA;
|
|
using HRM.UI.DTOs.Auth;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using System;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
using System.Security.Cryptography;
|
|
using System.Threading.Tasks;
|
|
using HRM.BO;
|
|
using System.Net.Http;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.Extensions.Options;
|
|
using HRM.UI.Api;
|
|
using System.Text;
|
|
using HRM.BO.Configuration;
|
|
using Newtonsoft.Json;
|
|
using System.Data;
|
|
using System.Reflection;
|
|
using HRM.UI.Components;
|
|
using HRM.UI.MODELS;
|
|
using Microsoft.Reporting.NETCore;
|
|
using HRM.UI.Controllers.MobileAPI.Components;
|
|
using static iTextSharp.text.pdf.AcroFields;
|
|
|
|
namespace HRM.UI.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/Mobile/User")]
|
|
[Authorize]
|
|
public class UserController : ControllerBase
|
|
{
|
|
private readonly IEmpMobileService _empMobileService;
|
|
private readonly IEmployeeService _employeeService;
|
|
private readonly IMOBILEAppVersionService _MOBILEAppVersionService;
|
|
private readonly ILocationService _locationService;
|
|
private readonly IPhotoPathService _photoPath;
|
|
private readonly IHREmployeeService _hREmployeeService;
|
|
private readonly IDepartmentService _departmentService;
|
|
private readonly IDesignationService _designationService;
|
|
private readonly IProfileDashboardMobile _profileDashboardMobile;
|
|
private readonly IAttnMobileRawDataService _attnMobileRawDataService;
|
|
private readonly string Secret;
|
|
private readonly IOptions<MobileAppSettings> _mobileAppSettings;
|
|
|
|
public UserController(
|
|
IMOBILEAppVersionService MOBILEAppVersionService,
|
|
IEmpMobileService empMobileService,
|
|
IEmployeeService employeeService,
|
|
ILocationService locationService,
|
|
IPhotoPathService photoPath,
|
|
IHREmployeeService hREmployeeService,
|
|
IDepartmentService departmentService,
|
|
IDesignationService designationService,
|
|
IProfileDashboardMobile profileDashboardMobile,
|
|
IAttnMobileRawDataService attnMobileRawDataService,
|
|
IOptions<AppSettings> appSettings,
|
|
IOptions<MobileAppSettings> mobileAppSettings)
|
|
{
|
|
this._empMobileService = empMobileService;
|
|
this._MOBILEAppVersionService = MOBILEAppVersionService;
|
|
this._employeeService = employeeService;
|
|
this._locationService = locationService;
|
|
this._photoPath = photoPath;
|
|
this._hREmployeeService = hREmployeeService;
|
|
this._departmentService = departmentService;
|
|
this._designationService = designationService;
|
|
this._profileDashboardMobile = profileDashboardMobile;
|
|
this._attnMobileRawDataService = attnMobileRawDataService;
|
|
this.Secret = appSettings.Value.Secret;
|
|
this._mobileAppSettings = mobileAppSettings;
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("GetApiLink")]
|
|
[AllowAnonymous]
|
|
public ActionResult GetApiLink(MobileApiDetails oMobileApiDetails)
|
|
{
|
|
string address = "";
|
|
string companyName = "";
|
|
try
|
|
{
|
|
string domain = string.Empty;
|
|
string[] parts = oMobileApiDetails.EmailAddress.Split('@');
|
|
|
|
if (parts.Length >= 2)
|
|
{
|
|
domain = parts[1].ToLower();
|
|
}
|
|
|
|
switch (domain)
|
|
{
|
|
case "celimited.com":
|
|
//address = "https://celbd.com/celhrmmobiletest/api/Mobile/";
|
|
companyName = "CEL";
|
|
//address = "http://100.100.100.15:45456/api/Mobile/";
|
|
break;
|
|
|
|
case "shvenergybd.com":
|
|
address = "https://celbd.com/petromaxhrmobileuat/api/Mobile/";
|
|
companyName = "Petromax";
|
|
//address = "http://100.100.100.15:45456/api/Mobile/";
|
|
break;
|
|
|
|
case "lifung.com":
|
|
case "lfsourcing.com":
|
|
case "neotangent.com":
|
|
case "Lifung.com":
|
|
case "LFmilesgroup.com":
|
|
case "lfmilesgroup.com":
|
|
case "LiFung.com":
|
|
case "LFSourcing.com":
|
|
//address = "https://celbd.com/lifungtest/api/Mobile/";
|
|
companyName = "LF";
|
|
address = "http://100.100.100.19:45455/api/Mobile/";
|
|
break;
|
|
|
|
case "customdomain.com":
|
|
Console.WriteLine("This is a Custom Domain address.");
|
|
break;
|
|
|
|
default:
|
|
address = "https://celbd.com/celhrmmobiletest/api/Mobile/";
|
|
companyName = "CEL";
|
|
//address = "http://100.100.100.15:45456/api/Mobile/";
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
return Ok("companyname#" + companyName + "#" + "address#" + address + "#");
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("LogIn")]
|
|
[AllowAnonymous]
|
|
public ActionResult LogIn(string DeviceNo)
|
|
{
|
|
UserTModel oUser = null;
|
|
string userToken = "";
|
|
|
|
try
|
|
{
|
|
DataTable dt = _empMobileService.GetEmpForMobileLogin(DeviceNo);
|
|
|
|
if (dt.Rows.Count != 0)
|
|
{
|
|
if (Convert.ToBoolean(dt.Rows[0]["IsActive"].ToString()) != true)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Informational, "Credentials of this Device have been sent for registration. Please contact with Administrator");
|
|
}
|
|
|
|
if (dt.Rows[0]["ENDOFCONTRACTDATE"] != DBNull.Value && Convert.ToDateTime(dt.Rows[0]["ENDOFCONTRACTDATE"].ToString()) < DateTime.Today)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
}
|
|
|
|
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
bool isContinue = Convert.ToInt32(dt.Rows[0]["STATUS"].ToString()) == 1;
|
|
|
|
oUser = new UserTModel();
|
|
oUser.EmployeeNo = dt.Rows[0]["EMPLOYEENO"].ToString();
|
|
oUser.PKID = Convert.ToInt32(dt.Rows[0]["EMPLOYEEID"].ToString());
|
|
oUser.EmailAddress = dt.Rows[0]["EMAILADDRESS"].ToString();
|
|
oUser.Name = dt.Rows[0]["NAME"].ToString();
|
|
oUser.Designation = dt.Rows[0]["Designation"].ToString();
|
|
oUser.PayrollTypeID = Convert.ToInt32(dt.Rows[0]["PAYROLLTYPEID"].ToString());
|
|
oUser.MobileMenu = new SystemConfigarationService().GetconfigStringValue(EnumConfigurationType.Logic, "root", "mobilemenu");
|
|
|
|
#region for Token generation like sanofi self service
|
|
var key = Encoding.ASCII.GetBytes(this.Secret);
|
|
|
|
var claims = new[]
|
|
{
|
|
new Claim("PKID", oUser.PKID.ToString()),
|
|
new Claim("EmployeeNo", oUser.EmployeeNo.ToString()),
|
|
new Claim("EmailAddress", oUser.EmailAddress.ToString()),
|
|
new Claim("Name", oUser.Name.ToString()),
|
|
new Claim("Designation", oUser.Designation.ToString()),
|
|
new Claim("PayrollTypeID", oUser.PayrollTypeID.ToString())
|
|
};
|
|
var creds = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha512Signature);
|
|
var tokenDescriptor = new SecurityTokenDescriptor
|
|
{
|
|
Subject = new ClaimsIdentity(claims),
|
|
Expires = DateTime.Now.AddDays(1),
|
|
SigningCredentials = creds
|
|
};
|
|
var tokenHandler = new JwtSecurityTokenHandler();
|
|
var token = tokenHandler.CreateToken(tokenDescriptor);
|
|
userToken = tokenHandler.WriteToken(token);
|
|
//userToken = "abc";
|
|
oUser.Token = userToken;
|
|
if (userToken != null)
|
|
{
|
|
HttpContext.Session.SetString("JWToken", userToken);
|
|
}
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Employee not found. ");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Device is not registered. Register the device before accesing the App");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok(oUser);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("LogInNew")]
|
|
[AllowAnonymous]
|
|
public ActionResult LogInNew(MobileApiDetails apiDetail)
|
|
{
|
|
UserTModel oUser = null;
|
|
string userToken = "";
|
|
|
|
try
|
|
{
|
|
DataTable dt = _empMobileService.GetEmpForMobileLogin(apiDetail.DeviceID);
|
|
|
|
if (dt.Rows.Count != 0)
|
|
{
|
|
if (Convert.ToBoolean(dt.Rows[0]["IsActive"].ToString()) != true)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Informational, "Credentials of this Device have been sent for registration. Please contact with Administrator");
|
|
}
|
|
|
|
if (dt.Rows[0]["ENDOFCONTRACTDATE"] != DBNull.Value && Convert.ToDateTime(dt.Rows[0]["ENDOFCONTRACTDATE"].ToString()) < DateTime.Today)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
}
|
|
|
|
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
bool isContinue = Convert.ToInt32(dt.Rows[0]["STATUS"].ToString()) == 1;
|
|
|
|
oUser = new UserTModel();
|
|
oUser.EmployeeNo = dt.Rows[0]["EMPLOYEENO"].ToString();
|
|
oUser.PKID = Convert.ToInt32(dt.Rows[0]["EMPLOYEEID"].ToString());
|
|
oUser.EmailAddress = dt.Rows[0]["EMAILADDRESS"].ToString();
|
|
oUser.Name = dt.Rows[0]["NAME"].ToString();
|
|
oUser.Designation = dt.Rows[0]["Designation"].ToString();
|
|
oUser.PayrollTypeID = Convert.ToInt32(dt.Rows[0]["PAYROLLTYPEID"].ToString());
|
|
oUser.MobileMenu = new SystemConfigarationService().GetconfigStringValue(EnumConfigurationType.Logic, "root", "mobilemenu");
|
|
|
|
#region for Token generation like sanofi self service
|
|
var key = Encoding.ASCII.GetBytes(this.Secret);
|
|
|
|
var claims = new[]
|
|
{
|
|
new Claim("PKID", oUser.PKID.ToString()),
|
|
new Claim("EmployeeNo", oUser.EmployeeNo.ToString()),
|
|
new Claim("EmailAddress", oUser.EmailAddress.ToString()),
|
|
new Claim("Name", oUser.Name.ToString()),
|
|
new Claim("Designation", oUser.Designation.ToString()),
|
|
new Claim("PayrollTypeID", oUser.PayrollTypeID.ToString())
|
|
};
|
|
var creds = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha512Signature);
|
|
var tokenDescriptor = new SecurityTokenDescriptor
|
|
{
|
|
Subject = new ClaimsIdentity(claims),
|
|
Expires = DateTime.Now.AddDays(1),
|
|
SigningCredentials = creds
|
|
};
|
|
var tokenHandler = new JwtSecurityTokenHandler();
|
|
var token = tokenHandler.CreateToken(tokenDescriptor);
|
|
userToken = tokenHandler.WriteToken(token);
|
|
//userToken = "abc";
|
|
oUser.Token = userToken;
|
|
if (userToken != null)
|
|
{
|
|
HttpContext.Session.SetString("JWToken", userToken);
|
|
}
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Employee not found. ");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Device is not registered. Register the device before accesing the App");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok(oUser);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetCurrentUser")]
|
|
public ActionResult GetCurrentUser()
|
|
{
|
|
CurrentMobileUser currentUser = CurrentMobileUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
return Ok(currentUser);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//return ex;
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetUser")]
|
|
[AllowAnonymous]
|
|
public ActionResult GetUser(string id)
|
|
{
|
|
UserTModel oUser = null;
|
|
try
|
|
{
|
|
EmpMobile oEmpMobile = _empMobileService.Get(Convert.ToInt32(id));
|
|
if (oEmpMobile != null)
|
|
{
|
|
if (!oEmpMobile.IsActive)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Informational, "Credentials of this Device have been sent for registration. Please contact with Administrator");
|
|
}
|
|
DataTable dt = _empMobileService.GetEmpForMobileLogin(oEmpMobile.EmpID);
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
bool isContinue = Convert.ToInt32(dt.Rows[0]["STATUS"].ToString()) == 1;
|
|
if (isContinue)
|
|
{
|
|
oUser = new UserTModel();
|
|
oUser.EmployeeNo = dt.Rows[0]["EMPLOYEENO"].ToString();
|
|
oUser.PKID = Convert.ToInt32(dt.Rows[0]["EMPLOYEEID"].ToString());
|
|
oUser.Name = dt.Rows[0]["NAME"].ToString();
|
|
oUser.Designation = dt.Rows[0]["Designation"].ToString();
|
|
oUser.PayrollTypeID = Convert.ToInt32(dt.Rows[0]["PAYROLLTYPEID"].ToString());
|
|
|
|
#region for Token generation like sanofi self service
|
|
var key = Encoding.ASCII.GetBytes(this.Secret);
|
|
|
|
var claims = new[]
|
|
{
|
|
new Claim("EmployeeNo", oUser.EmployeeNo.ToString()),
|
|
new Claim("PKID", oUser.PKID.ToString()),
|
|
new Claim("Name", oUser.Name.ToString()),
|
|
new Claim("Designation", oUser.Name.ToString()),
|
|
new Claim("PayrollTypeID", oUser.Name.ToString())
|
|
};
|
|
var creds = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha512Signature);
|
|
var tokenDescriptor = new SecurityTokenDescriptor
|
|
{
|
|
Subject = new ClaimsIdentity(claims),
|
|
Expires = DateTime.Now.AddDays(1),
|
|
SigningCredentials = creds
|
|
};
|
|
var tokenHandler = new JwtSecurityTokenHandler();
|
|
var token = tokenHandler.CreateToken(tokenDescriptor);
|
|
string userToken = tokenHandler.WriteToken(token);
|
|
if (userToken != null)
|
|
{
|
|
HttpContext.Session.SetString("JWToken", userToken);
|
|
}
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Employee not found. ");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Device is not registered. Register the device before accesing the App");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok(oUser);
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
[Route("GetWithVersionNumber")]
|
|
[AllowAnonymous]
|
|
public ActionResult GetWithVersionNumber(string imei, string versionNumber)
|
|
{
|
|
UserTModel oUser = null;
|
|
try
|
|
{
|
|
MOBILEAppVersion oAppVersion = _MOBILEAppVersionService.GetLatestVersion();
|
|
if (oAppVersion != null && oAppVersion.VersionNumber.Trim() != versionNumber.Trim())
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "You are using old version, please download the latest version.");
|
|
}
|
|
|
|
DataTable dt = new DataTable();
|
|
|
|
dt = _empMobileService.GetEmpForMobileLogin(imei);
|
|
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
if (dt.Rows[0]["ValidMobile"] != DBNull.Value)
|
|
{
|
|
if (Convert.ToBoolean(dt.Rows[0]["IsActive"].ToString()) != true)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Informational, "Credentials of this Device have been sent for registration. Please contact with Administrator");
|
|
}
|
|
|
|
bool isContinue = Convert.ToInt32(dt.Rows[0]["STATUS"].ToString()) == 1;
|
|
if (isContinue)
|
|
{
|
|
oUser = new UserTModel();
|
|
oUser.EmployeeNo = dt.Rows[0]["EMPLOYEENO"].ToString();
|
|
oUser.PKID = Convert.ToInt32(dt.Rows[0]["EMPLOYEEID"].ToString());
|
|
oUser.Name = dt.Rows[0]["NAME"].ToString();
|
|
oUser.Designation = dt.Rows[0]["Designation"].ToString();
|
|
oUser.PayrollTypeID = Convert.ToInt32(dt.Rows[0]["PAYROLLTYPEID"].ToString());
|
|
}
|
|
else
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
}
|
|
|
|
|
|
#region Old Code
|
|
//Employee oEmp = Employee.Get(oEmpMobile.EmpID);
|
|
//bool isContinue = Employee.isContinue(oEmpMobile.EmpID);
|
|
//if (oEmp != null)
|
|
//{
|
|
// if (isContinue)
|
|
// {
|
|
//ServiceInitializer.Initialize(oEmp);
|
|
// oUser = oEmp.ConvertToTModel();
|
|
// }
|
|
// else
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
// }
|
|
|
|
//}
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
#region for hosting purpose uncomment this
|
|
// { for hosting purpose uncomment this}
|
|
//DataTable dt = Employee.GetEmpForMobileLogin(9827);
|
|
//if (dt.Rows.Count > 0)
|
|
//{
|
|
// bool isContinue = Convert.ToInt32(dt.Rows[0]["STATUS"].ToString()) == 1;
|
|
// if (isContinue)
|
|
// {
|
|
// oUser = new UserTModel();
|
|
// oUser.EmployeeNo = dt.Rows[0]["EMPLOYEENO"].ToString();
|
|
// oUser.PKID = Convert.ToInt32(dt.Rows[0]["EMPLOYEEID"].ToString());
|
|
// oUser.Name = dt.Rows[0]["NAME"].ToString();
|
|
// oUser.Designation = dt.Rows[0]["Designation"].ToString();
|
|
// oUser.PayrollTypeID = Convert.ToInt32(dt.Rows[0]["PAYROLLTYPEID"].ToString());
|
|
|
|
// ServiceInitializer.Initialize(oUser.EmployeeNo, oUser.PayrollTypeID);
|
|
// }
|
|
// else
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
// }
|
|
//}
|
|
//else
|
|
//{
|
|
// throw new CustomException(EnumExceptionType.Validation, "The Employee not found. ");
|
|
//}
|
|
#endregion
|
|
|
|
#region After hosted app is approved uncomment this and comment
|
|
// {After hosted app is approved uncomment this and comment }
|
|
throw new CustomException(EnumExceptionType.Validation, "The Device is not registered. Register the device before accesing the App");
|
|
#endregion
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_mobileAppSettings.Value.IsTestUser)
|
|
{
|
|
dt = _empMobileService.GetEmpForMobileLoginByEmpNo(_mobileAppSettings.Value.TestEmpID);
|
|
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
bool isContinue = Convert.ToInt32(dt.Rows[0]["STATUS"].ToString()) == 1;
|
|
if (isContinue)
|
|
{
|
|
oUser = new UserTModel();
|
|
oUser.EmployeeNo = dt.Rows[0]["EMPLOYEENO"].ToString();
|
|
oUser.PKID = Convert.ToInt32(dt.Rows[0]["EMPLOYEEID"].ToString());
|
|
oUser.Name = dt.Rows[0]["NAME"].ToString();
|
|
oUser.Designation = dt.Rows[0]["Designation"].ToString();
|
|
oUser.PayrollTypeID = Convert.ToInt32(dt.Rows[0]["PAYROLLTYPEID"].ToString());
|
|
}
|
|
else
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Employee not found. ");
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
throw new CustomException(EnumExceptionType.Validation, "The Device is not registered. Register the device before accesing the App");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(oUser);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("IsDeviceNotRegistered")]
|
|
[AllowAnonymous]
|
|
public ActionResult IsDeviceNotRegistered(string id)
|
|
{
|
|
try
|
|
{
|
|
EmpMobile oEmpMobile = _empMobileService.Get(id.Trim());
|
|
if (oEmpMobile != null)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Informational,
|
|
oEmpMobile.IsActive ?
|
|
"The device has already been registered. Please log in to access the application." :
|
|
"Credentials of this Device have been sent for registration.Please contact with Administrator");
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
//return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
return Ok(false);
|
|
}
|
|
|
|
return Ok(true);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("CurrentVersion")]
|
|
[AllowAnonymous]
|
|
public ActionResult CurrentVersion()
|
|
{
|
|
string assempblyVersion = string.Empty;
|
|
try
|
|
{
|
|
assempblyVersion = Assembly.GetEntryAssembly().GetName().Version.ToString();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(assempblyVersion);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("RegisterDevice")]
|
|
[AllowAnonymous]
|
|
public ActionResult RegisterDevice(RegisterTModel oRegister)
|
|
{
|
|
try
|
|
{
|
|
#region Validation
|
|
|
|
bool bIsTestUser = oRegister.EmployeeNo.ToLower().Trim().Equals("test") || oRegister.EmployeeNo.ToLower().Trim().Equals("testapprover");
|
|
|
|
EmpMobile oExistingEmpMobile = _empMobileService.Get(oRegister.DeviceNo.Trim());
|
|
if (oExistingEmpMobile != null)
|
|
{
|
|
|
|
throw new CustomException(EnumExceptionType.Informational,
|
|
oExistingEmpMobile.IsActive ?
|
|
"This Device is already registered. Login to access App" :
|
|
"Credentials of this Device have been sent for registration.Please contact with Administrator");
|
|
|
|
}
|
|
|
|
Employee oEmp = _employeeService.GetwitoutchekPayrolltype(oRegister.EmployeeNo);
|
|
|
|
if (oEmp == null)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Error, "Employee does not exists in the system");
|
|
}
|
|
|
|
#endregion
|
|
|
|
EmpMobile oEmpMobile = new EmpMobile();
|
|
oEmpMobile.DeviceNO = oRegister.DeviceNo.Trim();
|
|
oEmpMobile.EmpID = oEmp.ID;
|
|
oEmpMobile.IsActive = bIsTestUser; // For testing purpose we will activate it directly // false;
|
|
_empMobileService.Save(oEmpMobile);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
return Ok();
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("RegisterDeviceNew")]
|
|
[AllowAnonymous]
|
|
public ActionResult RegisterDeviceNew(RegisterTModel oRegister)
|
|
{
|
|
EmpMobile oEmpMobile = new EmpMobile();
|
|
MobileApiDetails mobileApiDetails = new MobileApiDetails();
|
|
|
|
try
|
|
{
|
|
#region Validation
|
|
|
|
bool bIsTestUser = oRegister.EmployeeNo.ToLower().Trim().Equals("test") || oRegister.EmployeeNo.ToLower().Trim().Equals("testapprover");
|
|
|
|
EmpMobile oExistingEmpMobile = _empMobileService.Get(oRegister.DeviceNo.Trim());
|
|
if (oExistingEmpMobile != null)
|
|
{
|
|
|
|
throw new CustomException(EnumExceptionType.Informational,
|
|
oExistingEmpMobile.IsActive ?
|
|
"This Device is already registered. Login to access App" :
|
|
"Credentials of this Device have been sent for registration.Please contact with Administrator");
|
|
|
|
}
|
|
|
|
Employee oEmp = _employeeService.GetwitoutchekPayrolltype(oRegister.EmployeeNo);
|
|
|
|
if (oEmp == null)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Error, "Employee does not exists in the system");
|
|
}
|
|
|
|
string systemEmail = oEmp.EmailAddress.ToLower();
|
|
string inputEmail = oRegister.EmailAddress.ToLower();
|
|
if (systemEmail != inputEmail)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Error, "Email address does not match with system");
|
|
}
|
|
|
|
#endregion
|
|
// check email address of the employee
|
|
|
|
if (_mobileAppSettings.Value.IsTestUser && oEmp.EmployeeNo == _mobileAppSettings.Value.TestEmpID)
|
|
{
|
|
bIsTestUser = true;
|
|
}
|
|
|
|
mobileApiDetails.DeviceID=oEmpMobile.DeviceNO = oRegister.DeviceNo.Trim();
|
|
mobileApiDetails.EmpID = oEmpMobile.EmpID = oEmp.ID;
|
|
mobileApiDetails.EmailAddress = oEmp.EmailAddress.Trim();
|
|
mobileApiDetails.EmpNo = oEmp.EmployeeNo.Trim();
|
|
oEmpMobile.IsActive = bIsTestUser; // For testing purpose we will activate it directly // false;
|
|
_empMobileService.Save(oEmpMobile);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
return Ok(mobileApiDetails);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetEmployeeLocation/{employeeID}")]
|
|
public ActionResult GetEmployeeLocation(int employeeID)
|
|
{
|
|
LocationTModel objs = null;
|
|
try
|
|
{
|
|
//Employee oEmp = _employeeService.Get(employeeID);
|
|
//if (oEmp != null)
|
|
//{
|
|
//Location oLocation = _locationService.Get(oEmp.LocationID ?? default);
|
|
|
|
Location oLocation = new LocationService().GetEmployeeLocation(employeeID);
|
|
if (oLocation != null)
|
|
{
|
|
objs = oLocation.ConvertToTModel();
|
|
|
|
//Check Nullable Properties
|
|
objs.LatLongApproveStatus = objs.LatLongApproveStatus == null ? false : objs.LatLongApproveStatus;
|
|
objs.LatLongSetBy = objs.LatLongSetBy == null ? 0 : objs.LatLongSetBy;
|
|
objs.LatLongSetDate = objs.LatLongSetDate == null ? DateTime.MinValue : objs.LatLongSetDate;
|
|
}
|
|
|
|
//}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(objs);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("CheckEmployeeLocationIsExist/{employeeID}")]
|
|
public ActionResult CheckEmployeeLocationIsExist(int employeeID)
|
|
{
|
|
bool isLocationExist = false;
|
|
|
|
try
|
|
{
|
|
isLocationExist = new LocationService().CheckEmployeeLocationIsExist(employeeID);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(isLocationExist);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetTeamMembers/{employeeID}")]
|
|
public ActionResult GetTeamMembers(int employeeID)
|
|
{
|
|
DataTable item = null;
|
|
|
|
try
|
|
{
|
|
item = new EmployeeService().GetSubordinatesByLineManagerForMobile(employeeID);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(item);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetLatestMobileAppVersion")]
|
|
public ActionResult GetLatestMobileAppVersion()
|
|
{
|
|
MOBILEAppVersion oAppVersion = _MOBILEAppVersionService.GetLatestVersion();
|
|
|
|
if (oAppVersion != null)
|
|
{
|
|
var tempObj = new
|
|
{
|
|
VersionNumber = oAppVersion.VersionNumber,
|
|
DownloadMessage = oAppVersion.DownloadMessage,
|
|
DownloadLink = oAppVersion.DownloadLink,
|
|
AllowOldVersion = oAppVersion.AllowOldVersion
|
|
};
|
|
return Ok(tempObj);
|
|
}
|
|
|
|
return Ok(oAppVersion);
|
|
}
|
|
|
|
//Get profile page Dashboard Info
|
|
[HttpGet]
|
|
[Route("GetProfileDashboardInfo/{employeeID}/{fromDate}/{toDate}")]
|
|
public ActionResult GetProfileDashboardInfo(int EmployeeID, string fromDate, string toDate)
|
|
{
|
|
DateTime FromDate = DateTime.Parse(fromDate);
|
|
DateTime ToDate = DateTime.Parse(toDate);
|
|
|
|
DataSet ds = new DataSet();
|
|
|
|
try
|
|
{
|
|
ds = _profileDashboardMobile.ProfileDashboardMobile(EmployeeID, FromDate, ToDate);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok(ds.Tables[0]);
|
|
}
|
|
|
|
//// GET: api/Mobile/User/5
|
|
//public HttpResponseMessage Get(string id)
|
|
//{
|
|
// return CreateHttpResponse(this.Request, () =>
|
|
// {
|
|
// UserTModel oUser = null;
|
|
// EmpMobile oEmpMobile = EmpMobile.Get(id.Trim());
|
|
// if (oEmpMobile != null)
|
|
// {
|
|
// if (!oEmpMobile.IsActive)
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Informational, "Credentials of this Device have been sent for registration.Please contact with Administrator");
|
|
// }
|
|
// DataTable dt = Employee.GetEmpForMobileLogin(oEmpMobile.EmpID.Integer);
|
|
// if (dt.Rows.Count > 0)
|
|
// {
|
|
// bool isContinue = Convert.ToInt32(dt.Rows[0]["STATUS"].ToString()) == 1;
|
|
// if (isContinue)
|
|
// {
|
|
// oUser = new UserTModel();
|
|
// oUser.EmployeeNo = dt.Rows[0]["EMPLOYEENO"].ToString();
|
|
// oUser.PKID = Convert.ToInt32(dt.Rows[0]["EMPLOYEEID"].ToString());
|
|
// oUser.Name = dt.Rows[0]["NAME"].ToString();
|
|
// oUser.Designation = dt.Rows[0]["Designation"].ToString();
|
|
// oUser.PayrollTypeID = Convert.ToInt32(dt.Rows[0]["PAYROLLTYPEID"].ToString());
|
|
|
|
// ServiceInitializer.Initialize(oUser.EmployeeNo, oUser.PayrollTypeID);
|
|
// }
|
|
// else
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Validation, "The Employee not found. ");
|
|
// }
|
|
// #region Old Code
|
|
// //Employee oEmp = Employee.Get(oEmpMobile.EmpID);
|
|
// //bool isContinue = Employee.isContinue(oEmpMobile.EmpID);
|
|
// //if (oEmp != null)
|
|
// //{
|
|
// // if (isContinue)
|
|
// // {
|
|
// //ServiceInitializer.Initialize(oEmp);
|
|
// // oUser = oEmp.ConvertToTModel();
|
|
// // }
|
|
// // else
|
|
// // {
|
|
// // throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
// // }
|
|
|
|
// //}
|
|
// #endregion
|
|
// }
|
|
// else
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Validation, "The Device is not registered. Register the device before accesing the App");
|
|
// }
|
|
|
|
// return this.Request.CreateResponse(HttpStatusCode.OK, oUser);
|
|
// });
|
|
//}
|
|
|
|
//[HttpGet]
|
|
//[Route("GetWithVersionNumber")]
|
|
//public HttpResponseMessage Get(string imei, string versionNumber)
|
|
//{
|
|
// return CreateHttpResponse(this.Request, () =>
|
|
// {
|
|
|
|
// UserTModel oUser = null;
|
|
// MOBILEAppVersion oAppVersion = MOBILEAppVersion.GetLatestVersion();
|
|
// if (oAppVersion != null && oAppVersion.VersionNumber.Trim() != versionNumber.Trim())
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Validation, "You are using old version, please download the latest version.");
|
|
// }
|
|
// EmpMobile oEmpMobile = EmpMobile.Get(imei.Trim());
|
|
// if (oEmpMobile != null)
|
|
// {
|
|
// if (!oEmpMobile.IsActive)
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Informational, "Credentials of this Device have been sent for registration.Please contact with Administrator");
|
|
// }
|
|
// DataTable dt = Employee.GetEmpForMobileLogin(oEmpMobile.EmpID.Integer);
|
|
// if (dt.Rows.Count > 0)
|
|
// {
|
|
// bool isContinue = Convert.ToInt32(dt.Rows[0]["STATUS"].ToString()) == 1;
|
|
// if (isContinue)
|
|
// {
|
|
// oUser = new UserTModel();
|
|
// oUser.EmployeeNo = dt.Rows[0]["EMPLOYEENO"].ToString();
|
|
// oUser.PKID = Convert.ToInt32(dt.Rows[0]["EMPLOYEEID"].ToString());
|
|
// oUser.Name = dt.Rows[0]["NAME"].ToString();
|
|
// oUser.Designation = dt.Rows[0]["Designation"].ToString();
|
|
// oUser.PayrollTypeID = Convert.ToInt32(dt.Rows[0]["PAYROLLTYPEID"].ToString());
|
|
|
|
// ServiceInitializer.Initialize(oUser.EmployeeNo, oUser.PayrollTypeID);
|
|
// }
|
|
// else
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Validation, "The Employee not found. ");
|
|
// }
|
|
// #region Old Code
|
|
// //Employee oEmp = Employee.Get(oEmpMobile.EmpID);
|
|
// //bool isContinue = Employee.isContinue(oEmpMobile.EmpID);
|
|
// //if (oEmp != null)
|
|
// //{
|
|
// // if (isContinue)
|
|
// // {
|
|
// //ServiceInitializer.Initialize(oEmp);
|
|
// // oUser = oEmp.ConvertToTModel();
|
|
// // }
|
|
// // else
|
|
// // {
|
|
// // throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
// // }
|
|
|
|
// //}
|
|
// #endregion
|
|
// }
|
|
// else
|
|
// {
|
|
// // { for hosting purpose uncomment this}
|
|
// //DataTable dt = Employee.GetEmpForMobileLogin(9827);
|
|
// //if (dt.Rows.Count > 0)
|
|
// //{
|
|
// // bool isContinue = Convert.ToInt32(dt.Rows[0]["STATUS"].ToString()) == 1;
|
|
// // if (isContinue)
|
|
// // {
|
|
// // oUser = new UserTModel();
|
|
// // oUser.EmployeeNo = dt.Rows[0]["EMPLOYEENO"].ToString();
|
|
// // oUser.PKID = Convert.ToInt32(dt.Rows[0]["EMPLOYEEID"].ToString());
|
|
// // oUser.Name = dt.Rows[0]["NAME"].ToString();
|
|
// // oUser.Designation = dt.Rows[0]["Designation"].ToString();
|
|
// // oUser.PayrollTypeID = Convert.ToInt32(dt.Rows[0]["PAYROLLTYPEID"].ToString());
|
|
|
|
// // ServiceInitializer.Initialize(oUser.EmployeeNo, oUser.PayrollTypeID);
|
|
// // }
|
|
// // else
|
|
// // {
|
|
// // throw new CustomException(EnumExceptionType.Validation, "The Employee trying to login has been discontinued. ");
|
|
// // }
|
|
// //}
|
|
// //else
|
|
// //{
|
|
// // throw new CustomException(EnumExceptionType.Validation, "The Employee not found. ");
|
|
// //}
|
|
|
|
// // {After hosted app is approved uncomment this and comment }
|
|
// throw new CustomException(EnumExceptionType.Validation, "The Device is not registered. Register the device before accesing the App");
|
|
// }
|
|
|
|
// return this.Request.CreateResponse(HttpStatusCode.OK, oUser);
|
|
// });
|
|
//}
|
|
|
|
//[HttpGet]
|
|
//[Route("IsDeviceNotRegistered")]
|
|
//public HttpResponseMessage IsDeviceNotRegistered(string id)
|
|
//{
|
|
// return CreateHttpResponse(this.Request, () =>
|
|
// {
|
|
// EmpMobile oEmpMobile = EmpMobile.Get(id.Trim());
|
|
// if (oEmpMobile != null && !oEmpMobile.ID.IsUnassigned)
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Informational,
|
|
// oEmpMobile.IsActive ?
|
|
// "This Device is already registered. Login to access App" :
|
|
// "Credentials of this Device have been sent for registration.Please contact with Administrator");
|
|
// }
|
|
|
|
// return this.Request.CreateResponse(HttpStatusCode.OK, true);
|
|
// });
|
|
//}
|
|
|
|
//[HttpGet]
|
|
//[Route("CurrentVersion")]
|
|
//public HttpResponseMessage CurrentVersion()
|
|
//{
|
|
// return CreateHttpResponse(this.Request, () =>
|
|
// {
|
|
// return this.Request.CreateResponse(HttpStatusCode.OK, Assembly.GetEntryAssembly().GetName().Version.ToString());
|
|
// });
|
|
//}
|
|
|
|
//[HttpPost]
|
|
//[Route("RegisterDevice")]
|
|
//public HttpResponseMessage RegisterDevice(RegisterTModel oRegister)
|
|
//{
|
|
// return CreateHttpResponse(this.Request, () =>
|
|
// {
|
|
// #region Validation
|
|
|
|
// bool bIsTestUser = oRegister.EmployeeNo.ToLower().Trim().Equals("test") || oRegister.EmployeeNo.ToLower().Trim().Equals("testapprover");
|
|
|
|
// EmpMobile oExistingEmpMobile = EmpMobile.Get(oRegister.DeviceNo.Trim());
|
|
// if (oExistingEmpMobile != null && !oExistingEmpMobile.ID.IsUnassigned)
|
|
// {
|
|
|
|
// throw new CustomException(EnumExceptionType.Informational,
|
|
// oExistingEmpMobile.IsActive ?
|
|
// "This Device is already registered. Login to access App" :
|
|
// "Credentials of this Device have been sent for registration.Please contact with Administrator");
|
|
|
|
// }
|
|
|
|
// //Uncomment when deploying for test purpose. Comment when deploying to client
|
|
// //if (bIsTestUser)
|
|
// //{
|
|
// // oRegister.EmployeeNo = oRegister.EmployeeNo.ToLower().Trim().Equals("test") ? "002651" : "002023";
|
|
// //}
|
|
|
|
// Employee oEmp = Employee.GetForMobileRegistration(oRegister.EmployeeNo, oRegister.PayrollTypeID);
|
|
|
|
// if (oEmp == null)
|
|
// {
|
|
// throw new CustomException(EnumExceptionType.Error, "Employee does not exists in the system");
|
|
// }
|
|
|
|
// ServiceInitializer.Initialize(oEmp);
|
|
|
|
// #endregion
|
|
|
|
// #region Save
|
|
|
|
// EmpMobile oEmpMobile = new EmpMobile();
|
|
// oEmpMobile.DeviceNO = oRegister.DeviceNo.Trim();
|
|
// oEmpMobile.EmpID = oEmp.ID;
|
|
// oEmpMobile.IsActive = bIsTestUser; // For testing purpose we will activate it directly // false;
|
|
// oEmpMobile.Save();
|
|
// return this.Request.CreateResponse(HttpStatusCode.OK);
|
|
|
|
// #endregion
|
|
// });
|
|
//}
|
|
|
|
//[Route("GetEmployeeLocation/{employeeID}")]
|
|
//[HttpGet]
|
|
//public HttpResponseMessage GetEmployeeLocation(int employeeID)
|
|
//{
|
|
// return CreateHttpResponse(this.Request, () =>
|
|
// {
|
|
// LocationTModel objs = null;
|
|
// Employee oEmp = Employee.Get(ID.FromInteger(employeeID));
|
|
// ID locationID = (oEmp.LocationID);
|
|
// if (oEmp != null)
|
|
// {
|
|
// Location oLocation = Location.Get(locationID);
|
|
// objs = oLocation.ConvertToTModel();
|
|
// }
|
|
// return this.Request.CreateResponse(HttpStatusCode.OK, objs);
|
|
// });
|
|
//}
|
|
//[Route("GetTeamMembers/{employeeID}")]
|
|
//[HttpGet]
|
|
//public HttpResponseMessage GetTeamMembers(int employeeID)
|
|
//{
|
|
// return CreateHttpResponse(this.Request, () =>
|
|
// {
|
|
// List<EmployeeTModel> objs = null;
|
|
// List<Employee> oEmps = Employee.GetByPrimaryLMID(employeeID);
|
|
// if (oEmps != null && oEmps.Count > 0)
|
|
// {
|
|
// objs = oEmps.ConvertToTModels();
|
|
// }
|
|
// return this.Request.CreateResponse(HttpStatusCode.OK, objs);
|
|
// });
|
|
//}
|
|
|
|
[HttpGet]
|
|
[Route("GetProfileInfo/{id}")]
|
|
public ActionResult GetProfileInfo(int id)
|
|
{
|
|
// Employee oEmp = _employeeService.Get(id);
|
|
|
|
ProfileInformation profile = new ProfileInformation();
|
|
|
|
DataSet ds = new DataSet();
|
|
//DataSet ds2 = new DataSet();
|
|
|
|
//DateTime currentDate = DateTime.Now;
|
|
|
|
ds = _employeeService.GetMobileProfile(id);
|
|
//ds2 = _profileDashboardMobile.ProfileDashboardMobile(id, currentDate, currentDate);
|
|
|
|
//mergedDs.Tables.Add(ds1.Tables[0].Copy());
|
|
//mergedDs.Tables[0].Merge(ds2.Tables[0]);
|
|
|
|
DataTable dt = ds.Tables[0];
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
profile.EmployeeNo = row["EmployeeNo"].ToString() == null ? "" : row["EmployeeNo"].ToString();
|
|
profile.Name = row["Name"].ToString() == null ? "" : row["Name"].ToString();
|
|
profile.JoiningDate = row["JoiningDate"] is DBNull ? Convert.ToDateTime(DateTime.MinValue) : Convert.ToDateTime(row["JoiningDate"]);
|
|
profile.FixedLocationAttn = row["IsFixedLocation"] == DBNull.Value ? 0 : (Int16)row["IsFixedLocation"];
|
|
profile.Department = row["Department"].ToString();
|
|
profile.Designation = row["Designation"].ToString();
|
|
profile.Location = row["Location"].ToString();
|
|
profile.Latitude = row["Latitude"] == DBNull.Value ? 0 : Convert.ToDouble(row["Latitude"]);
|
|
profile.Longitude = row["Longitude"] == DBNull.Value ? 0 : Convert.ToDouble(row["Longitude"]);
|
|
profile.FixedLocationDistance = 5;
|
|
}
|
|
|
|
//DataTable dt2 = ds2.Tables[0];
|
|
//foreach (DataRow row in dt2.Rows)
|
|
//{
|
|
// profile.ShiftName = row["ShiftName"].ToString();
|
|
//}
|
|
|
|
return Ok(profile);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetProfileInfoNew")]
|
|
public ActionResult GetProfileInfoNew()
|
|
{
|
|
// Employee oEmp = _employeeService.Get(id);
|
|
|
|
CurrentMobileUser currentUser = CurrentMobileUser.GetCurrentUser(HttpContext.User);
|
|
DataSet ds = new DataSet();
|
|
ds = _employeeService.GetMobileProfileNew((int)currentUser.PKID);
|
|
|
|
ProfileInformation profile = new ProfileInformation();
|
|
DataTable dt = ds.Tables[0];
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
profile.EmployeeNo = row["EmployeeNo"].ToString() == null ? "" : row["EmployeeNo"].ToString();
|
|
profile.EmailAddress = row["EmailAddress"].ToString() == null ? "" : row["EmailAddress"].ToString();
|
|
profile.Name = row["Name"].ToString() == null ? "" : row["Name"].ToString();
|
|
profile.JoiningDate = row["JoiningDate"] is DBNull ? Convert.ToDateTime(DateTime.MinValue) : Convert.ToDateTime(row["JoiningDate"]);
|
|
profile.FixedLocationAttn = row["IsFixedLocation"] == DBNull.Value ? 0 : (Int16)row["IsFixedLocation"];
|
|
profile.Department = row["Department"].ToString();
|
|
profile.Designation = row["Designation"].ToString();
|
|
profile.Location = row["Location"].ToString();
|
|
profile.Latitude = row["Latitude"] == DBNull.Value ? 0 : Convert.ToDouble(row["Latitude"]);
|
|
profile.Longitude = row["Longitude"] == DBNull.Value ? 0 : Convert.ToDouble(row["Longitude"]);
|
|
profile.FixedLocationDistance = 5;
|
|
}
|
|
|
|
//DataTable dt2 = ds2.Tables[0];
|
|
//foreach (DataRow row in dt2.Rows)
|
|
//{
|
|
// profile.ShiftName = row["ShiftName"].ToString();
|
|
//}
|
|
|
|
return Ok(profile);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetAvaliableLocations/{id}")]
|
|
public ActionResult GetAvaliableLocations(int id)
|
|
{
|
|
Employee oEmp = _employeeService.Get(id);
|
|
List<LocationTModel> oLocations = new List<LocationTModel>();
|
|
|
|
if (oEmp != null)
|
|
{
|
|
if (oEmp.LocationID != null)
|
|
{
|
|
oLocations = _locationService.GetLowerTierLocations(oEmp.LocationID ?? -1).ConvertToTModels();
|
|
}
|
|
}
|
|
|
|
return Ok(oLocations);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("UpdateLocation")]
|
|
public ActionResult UpdateLocation(ProfileInformation profile)
|
|
{
|
|
Employee oEmp = _employeeService.Get(profile.UserID);
|
|
Location oloc = new LocationService().Get((int)oEmp.LocationID);
|
|
|
|
try
|
|
{
|
|
if (oloc.AttendancePoint == false)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Informational, "Location is not an attendance point.");
|
|
}
|
|
//oloc.Latitude = 0;
|
|
//oloc.Longitude = 0;
|
|
if (oloc.Latitude == 0 && oloc.Longitude == 0)
|
|
{
|
|
bool saveLocation = _locationService.SaveLocation(oEmp.LocationID ?? -1, profile.Latitude, profile.Longitude, profile.UserID, false);
|
|
}
|
|
|
|
if (oloc.Latitude != 0 && oloc.Longitude != 0 && oloc.LatLongApproveStatus == false)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Informational, "Lat & long is already defined, but not yet approved");
|
|
}
|
|
|
|
if (oloc.Latitude != 0 && oloc.Longitude != 0 && oloc.LatLongApproveStatus == true)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Informational, "Lat & long is already defined.");
|
|
}
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
return Ok();
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("SetLocation")]
|
|
public ActionResult SetLocation(LocationTModel location)
|
|
{
|
|
Location item = new LocationService().Get(location.ID);
|
|
|
|
// if lat & long is null the update the location table LatLongSetApprv will be false
|
|
|
|
bool saveLocation = _locationService.SaveLocation(location.Id, location.Latitude, location.Longitude, (int)location.LatLongSetBy, (bool)location.LatLongApproveStatus);
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[Route("IsFixedLocation/{id}")]
|
|
[HttpGet]
|
|
[AllowAnonymous]
|
|
public ActionResult IsFixedLocation(int id)
|
|
{
|
|
//Employee emp = new EmployeeService().Get(id);
|
|
//bool isFixed = emp.IsFixedLocation;
|
|
|
|
bool isFixed = new EmployeeService().GetIsFixedPositionForMobile(id);
|
|
return Ok(isFixed);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("IsLineManager/{id}")]
|
|
public ActionResult IsLineManager(int id)
|
|
{
|
|
bool isLM = false;
|
|
List<Employee> oEmps = new List<Employee>();
|
|
oEmps = _employeeService.GetSubordinatesByLineManager(id);
|
|
if (oEmps.Count > 0) isLM = true;
|
|
return Ok(isLM);
|
|
}
|
|
|
|
//[HttpGet]
|
|
//[Route("GetLatestMobileAppVersion")]
|
|
//[Authorize]
|
|
//public HttpResponseMessage GetLatestMobileAppVersion()
|
|
//{
|
|
// return CreateHttpResponse(this.Request, () =>
|
|
// {
|
|
// MOBILEAppVersion oAppVersion = MOBILEAppVersion.GetLatestVersion();
|
|
// return this.Request.CreateResponse(HttpStatusCode.OK,
|
|
// oAppVersion != null ? new
|
|
// {
|
|
// VersionNumber = oAppVersion.VersionNumber,
|
|
// DownloadMessage = oAppVersion.DownloadMessage,
|
|
// DownloadLink = oAppVersion.DownloadLink,
|
|
// AllowOldVersion = oAppVersion.AllowOldVersion
|
|
// } : null);
|
|
// });
|
|
//}
|
|
|
|
|
|
[HttpGet]
|
|
[Route("GetImage")]
|
|
public ActionResult GetImage(int id)
|
|
{
|
|
FileTModel oFTModel = new FileTModel();
|
|
|
|
Employee oEmp = _employeeService.Get(id);
|
|
empFileupload oEmpFileUpload = _hREmployeeService.getuploadedFile(oEmp.ID, oEmp.ID, enumEmpFileUploadType.photo);
|
|
|
|
if (oEmp != null && oEmpFileUpload != null)
|
|
{
|
|
List<PhotoPath> photoPaths = _photoPath.Get();
|
|
string empPhotoPath = photoPaths.Select(x => x.EmployeePhoto).FirstOrDefault();
|
|
string FileName = string.Empty;
|
|
FileName = oEmp.EmployeeNo.Trim() + ".jpg";
|
|
|
|
oFTModel.FileName = oEmpFileUpload.fileName == string.Empty ? FileName : oEmpFileUpload.fileName;
|
|
oFTModel.Type = EnumFileType.Image;
|
|
oFTModel.FileInBytes = (byte[])oEmpFileUpload.fileData;
|
|
}
|
|
|
|
return Ok(oFTModel);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("ShowPayslip")]
|
|
public ActionResult ShowPayslip(int EmployeeID, DateTime Month)
|
|
{
|
|
FileTModel oFTModel = new FileTModel();
|
|
try
|
|
{
|
|
|
|
Employee oEmp = new EmployeeService().Get(EmployeeID);
|
|
|
|
Month = Month.LastDateOfMonth();
|
|
|
|
byte[] bytes = GeneratePayslipDataTable(oEmp, Month);
|
|
if (bytes == null)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Informational, "No payslip data found for this month");
|
|
}
|
|
|
|
oFTModel = new FileTModel()
|
|
{
|
|
FileName = string.Format("Payslip-{0}-{1}.pdf", oEmp.EmployeeNo, Month.ToString("MMM-yyyy")),
|
|
Type = EnumFileType.PDF,
|
|
FileInBytes = bytes
|
|
};
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(oFTModel);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetPayProcessDate")]
|
|
//[Authorize]
|
|
[AllowAnonymous]
|
|
public ActionResult GetPayProcessDate()
|
|
{
|
|
//return this.Request.CreateResponse(HttpStatusCode.OK, Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate);
|
|
return Ok(DateTime.Today);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("UnRegisterUserDevice/{EmpID}/{DeviceNo}")]
|
|
[AllowAnonymous]
|
|
public bool UnRegisterUserDevice(int EmpID, string DeviceNo)
|
|
{
|
|
return _empMobileService.UnRegisterUserDevice(EmpID, DeviceNo);
|
|
}
|
|
//#region Payslip Relatede Function
|
|
|
|
[NonAction]
|
|
private byte[] GeneratePayslipDataTable(Employee emp, DateTime Month)
|
|
{
|
|
string takaInWord = string.Empty;
|
|
Employee oEmployee = null;
|
|
List<Employee> oEmps = new List<Employee>();
|
|
List<SalaryProcess> oSaProcess = new List<SalaryProcess>();
|
|
List<DailyAttnProcess> _dailyAttnProcessEmp = new List<DailyAttnProcess>();
|
|
DataTable basicInfo = new rptDataSet.PayslipBasicInfoDataTable();
|
|
DataTable PayslipData = new rptDataSet.PayslipDataTable();
|
|
DataTable rlforPayslipdt = new rptDataSet.RemainingLoanforPayslipDataTable();
|
|
|
|
DateTime _dMonthEndDate = DateTime.MinValue;
|
|
DateTime salaryMonth = Month.LastDateOfMonth();
|
|
DateTime startMonth = Month.AddMonths(-1);
|
|
startMonth = new DateTime(startMonth.Year, startMonth.Month, 26);
|
|
DateTime endMonth = new DateTime(Month.Year, Month.Month, 25);
|
|
|
|
List<TermParameter> _termParamenters = new TermParameterService().GetByPayrollTypeID(emp.PayrollTypeID);
|
|
List<DailyAttnProcess> _dailyAttnProcess = new DailyAttnProcessService().Get(emp.ID.ToString(), startMonth, endMonth);
|
|
|
|
oEmps.Add(emp);
|
|
oSaProcess = new SalaryProcessService().Get(salaryMonth, emp.PayrollTypeID);
|
|
SalaryMonthly sMonthly = new SalaryMonthlyService().Get(emp.ID, salaryMonth);
|
|
|
|
DataSet oSalaryMonthlysGross = new SalaryMonthlyService().GetEmpPaySlipGrossForOthers(salaryMonth, emp.ID.ToString());
|
|
DataSet dsetEmpBasicInfo = new EmployeeService().GetEmpBasicInfoForReport(emp.ID.ToString());
|
|
DataTable _hourTable = oSalaryMonthlysGross.Tables[2];
|
|
|
|
if (oSaProcess != null && oSaProcess.Count > 0 && oSalaryMonthlysGross.Tables[1].Rows.Count > 0)
|
|
{
|
|
if (oSaProcess[0].PaymentDate != DateTime.MinValue)
|
|
{
|
|
_dMonthEndDate = Convert.ToDateTime(oSaProcess[0].PaymentDate);
|
|
}
|
|
else
|
|
{
|
|
_dMonthEndDate = DateTime.MinValue;
|
|
}
|
|
}
|
|
|
|
bool isDesigFromEmp = HRM.DA.ConfigurationManager.GetBoolValue("designation", "desigfromdescriptiontext", EnumConfigurationType.Logic);
|
|
|
|
foreach (DataRow oRow in oSalaryMonthlysGross.Tables[0].Rows)
|
|
{
|
|
if (isDesigFromEmp)
|
|
{
|
|
oRow["Designation"] = emp.DescriptionText;
|
|
}
|
|
}
|
|
|
|
foreach (DataRow odRow in oSalaryMonthlysGross.Tables[1].Rows)
|
|
{
|
|
double dbl = Convert.ToDouble(odRow["CHANGEDAMOUNT"].ToString());
|
|
if (dbl == 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
DataRow oRow = this.GetItem(PayslipData, Convert.ToString(odRow["EMPLOYEENO"]), (EnumSalaryGroup)Convert.ToInt32(odRow["ITEMGROUP"]), (EnumSalaryItemCode)Convert.ToInt32(odRow["ItemCode"]), Convert.ToInt32(odRow["ItemID"].ToString() == "" ? 0 : odRow["ItemID"]));
|
|
if (oRow == null)
|
|
{
|
|
oRow = PayslipData.NewRow();
|
|
oRow = this.GrossMerge(oRow, odRow, _dMonthEndDate, salaryMonth, _hourTable, _termParamenters, emp.PayrollTypeID);
|
|
oEmployee = oEmps
|
|
.Where(o => o.EmployeeNo.ToUpper().Trim() == odRow["EMPLOYEENO"].ToString().ToUpper().Trim())
|
|
.FirstOrDefault();
|
|
|
|
takaInWord = Ease.Core.Utility.Global.NumericFunctions.TakaWords(Math.Round(sMonthly.Details.Where(o => o.itemGroupCode == EnumSalaryGroup.OtherItem && o.ItemCode == EnumSalaryItemCode.Net_Payable).FirstOrDefault().ChangedAmount));
|
|
oRow["STaka"] = takaInWord;
|
|
PayslipData.Rows.Add(oRow);
|
|
}
|
|
|
|
if ((Convert.ToInt32(odRow["ITEMGROUP"]) == (int)EnumSalaryGroup.Gross))
|
|
{
|
|
oRow["Earning"] = odRow["CHANGEDAMOUNT"];
|
|
}
|
|
|
|
else if ((Convert.ToInt32(odRow["ITEMGROUP"]) == (int)EnumSalaryGroup.Arrear))
|
|
{
|
|
double dArrear = Convert.ToDouble(odRow["CHANGEDAMOUNT"].ToString());
|
|
oRow["Arrear"] = dArrear;
|
|
}
|
|
else if ((Convert.ToInt32(odRow["ITEMGROUP"]) == (int)EnumSalaryGroup.UnauthLeave))
|
|
{
|
|
oRow["unAuthLeave"] = odRow["CHANGEDAMOUNT"];
|
|
}
|
|
if (odRow["PaymentMode"].ToString() == "1")
|
|
{
|
|
oRow["PaymentMode"] = "CashPayment";
|
|
}
|
|
else if (odRow["PaymentMode"].ToString() == "2")
|
|
{
|
|
oRow["PaymentMode"] = "BankTransfer";
|
|
}
|
|
else if (odRow["PaymentMode"] == "3")
|
|
{
|
|
oRow["PaymentMode"] = "Provision";
|
|
}
|
|
}
|
|
|
|
int nCount = 0;
|
|
DataSet oSalaryMonthlysDeduct = new SalaryMonthlyService().GetEmpPaySlipDeductForOthers(salaryMonth, emp.ID.ToString());
|
|
|
|
string employeeNo = "";
|
|
DataRow[] odros = null;
|
|
if (oSalaryMonthlysDeduct.Tables[0].Rows.Count > 0)
|
|
{
|
|
employeeNo = oSalaryMonthlysDeduct.Tables[0].Rows[0]["EMPLOYEENO"].ToString();
|
|
odros = PayslipData.Select(" EmployeeNo='" + oSalaryMonthlysDeduct.Tables[0].Rows[0]["EMPLOYEENO"].ToString() + "'");
|
|
}
|
|
|
|
string sTEmpEmpNo = "";
|
|
double nCurrPFAmount = 0;
|
|
foreach (DataRow odRow in oSalaryMonthlysDeduct.Tables[0].Rows)
|
|
{
|
|
if (Convert.ToDouble(odRow["CHANGEDAMOUNT"].ToString()) != 0)
|
|
{
|
|
DataRow oRow = null;
|
|
if (employeeNo != odRow["EMPLOYEENO"].ToString())
|
|
{
|
|
odros = PayslipData.Select(" EmployeeNo='" + odRow["EMPLOYEENO"].ToString() + "'");
|
|
nCount = 0;
|
|
}
|
|
|
|
if (odros.Length <= nCount)
|
|
{
|
|
oRow = PayslipData.NewRow();
|
|
oRow = this.GrossMerge(oRow, odRow, _dMonthEndDate, salaryMonth, _hourTable, _termParamenters, emp.PayrollTypeID);
|
|
PayslipData.Rows.Add(oRow);
|
|
}
|
|
else oRow = odros[nCount];
|
|
|
|
oRow["DeducDescription"] = odRow["Description"];
|
|
if ((Convert.ToInt32(odRow["ITEMGROUP"]) == (int)EnumSalaryGroup.Deductions))
|
|
oRow["DeducAmount"] = odRow["CHANGEDAMOUNT"];
|
|
|
|
oRow["DeducDescription"] = odRow["Description"];
|
|
|
|
if (sTEmpEmpNo == "" || sTEmpEmpNo != odRow["EMPLOYEENO"].ToString())
|
|
{
|
|
nCurrPFAmount = 0;
|
|
oEmployee = oEmps.Find(delegate (Employee oEmpItem) { return oEmpItem.EmployeeNo == odRow["EMPLOYEENO"].ToString().Trim(); });
|
|
|
|
DataRow[] odrosPF = oSalaryMonthlysDeduct.Tables[0].Select(" ItemCode='" + (int)EnumSalaryItemCode.PF_Contribution + "' AND EMPLOYEENO='" + odRow["EMPLOYEENO"].ToString() + "'");
|
|
if (odrosPF.Length > 0)
|
|
{
|
|
DataRow oRowPF = odrosPF[0];
|
|
nCurrPFAmount = Convert.ToDouble(oRowPF["CHANGEDAMOUNT"]);
|
|
}
|
|
|
|
}
|
|
|
|
if ((Convert.ToInt32(odRow["ITEMGROUP"]) == (int)EnumSalaryGroup.Deductions) &&
|
|
Convert.ToInt32(odRow["ITEMCODE"]) == (int)EnumSalaryItemCode.Loan_Monthly_Installment)
|
|
{
|
|
double balance = 0.0;
|
|
double interest = 0.0;
|
|
DataRow orow = null;
|
|
LoanSchedule oSchedule = new LoanScheduleService().Get(Convert.ToInt32(odRow["SUPPORTID"]));
|
|
List<LoanSchedule> oSchedules = new List<LoanSchedule>();
|
|
if (oSchedule != null)
|
|
{
|
|
oSchedules = new LoanScheduleService().GetByIssueID(oSchedule.LoanIssueID);
|
|
}
|
|
foreach (LoanSchedule oSchdl in oSchedules)
|
|
{
|
|
if (oSchdl.ScheduleNo > oSchedule.ScheduleNo)
|
|
{
|
|
balance += oSchdl.InstallmentPrincipal;
|
|
interest += oSchdl.InstallmentInterest;
|
|
}
|
|
}
|
|
|
|
orow = rlforPayslipdt.NewRow();
|
|
orow["LoanName"] = odRow["Description"];
|
|
orow["RemainingBalance"] = balance;
|
|
orow["RemainingInterest"] = interest;
|
|
orow["EmpNo"] = oEmployee.EmployeeNo;
|
|
|
|
rlforPayslipdt.Rows.Add(orow);
|
|
}
|
|
|
|
nCount = nCount + 1;
|
|
employeeNo = odRow["EMPLOYEENO"].ToString();
|
|
sTEmpEmpNo = odRow["EMPLOYEENO"].ToString();
|
|
}
|
|
|
|
}
|
|
|
|
basicInfo = dsetEmpBasicInfo.Tables[0].Copy(); //oSalaryMonthlysGross.Tables[0].Copy();
|
|
basicInfo.Columns.Add("TotalAbsent", typeof(string));
|
|
basicInfo.Columns.Add("TotalLWP", typeof(string));
|
|
basicInfo.TableName = "BasicInfo";
|
|
double totalAbsentDays = 0;
|
|
double totalDaysOfMonth = Ease.Core.Utility.Global.DateFunctions.DateDiff("d", startMonth, endMonth) + 1;
|
|
List<EmployeeUnAuthorizeLeave> lwps = new EmployeeUnAuthorizeLeaveService().Get(EnumLeaveEntryType.Normal, salaryMonth);
|
|
|
|
foreach (DataRow oRow in basicInfo.Rows)
|
|
{
|
|
oEmployee = oEmps
|
|
.Where(o => o.EmployeeNo.ToUpper().Trim() == oRow["EMPLOYEENO"].ToString().ToUpper().Trim())
|
|
.FirstOrDefault();
|
|
_dailyAttnProcessEmp = _dailyAttnProcess.Where(o => o.EmployeeID == oEmployee.ID && o.AttenType == EnumAttendanceType.Absent).ToList();
|
|
oRow["PayPeriodFrom"] = startMonth.ToString("dd-MMM-yyyy");
|
|
oRow["PayPeriodTo"] = endMonth.ToString("dd-MMM-yyyy");
|
|
if (oEmployee.JoiningDate >= startMonth && oEmployee.JoiningDate <= endMonth)
|
|
{
|
|
totalDaysOfMonth = Ease.Core.Utility.Global.DateFunctions.DateDiff("d", oEmployee.JoiningDate, endMonth) + 1;
|
|
}
|
|
oRow["TotalDays"] = totalDaysOfMonth;
|
|
|
|
totalAbsentDays = _dailyAttnProcessEmp.Count;
|
|
oRow["TotalAbsent"] = totalAbsentDays;
|
|
var totalLwps = 0.0;
|
|
if (lwps.Count > 0)
|
|
{
|
|
totalLwps = lwps.Where(x => x.EmployeeID == oEmployee.ID).Sum(x => x.LeaveDays);
|
|
oRow["TotalLWP"] = totalLwps;
|
|
}
|
|
oRow["PayableDays"] = totalDaysOfMonth - totalAbsentDays - totalLwps;
|
|
oRow["SalaryMonth"] = salaryMonth.ToString("MMMM yyyy");
|
|
oRow["PaymentDate"] = salaryMonth.ToString("dd MMM yyyy");
|
|
}
|
|
|
|
DataSet dsSubReport = new DataSet();
|
|
PayslipData.TableName = "Payslip";
|
|
dsSubReport.Tables.Add(PayslipData);
|
|
rlforPayslipdt.TableName = "RemainingLoanforPayslip";
|
|
dsSubReport.Tables.Add(rlforPayslipdt);
|
|
|
|
bool _isPermanent = new SalaryMonthlyService().IsPermanentEmp(emp.ID, salaryMonth, emp.PayrollTypeID);
|
|
DataSet _dSet = new DataSet();
|
|
DataSet _oSubreportDataset = new DataSet();
|
|
|
|
|
|
_dSet.DataSetName = "rptDataSet";
|
|
basicInfo.TableName = "PayslipBasicInfo";
|
|
_dSet.Tables.Add(basicInfo.Copy());
|
|
|
|
PayslipData.TableName = "Payslip";
|
|
_oSubreportDataset.Tables.Add(PayslipData.Copy());
|
|
rlforPayslipdt.TableName = "RemainingLoanforPayslip";
|
|
_oSubreportDataset.Tables.Add(rlforPayslipdt.Copy());
|
|
|
|
if (_dSet == null || _dSet.Tables.Count <= 0)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Informational, "There is no salary information for the month of " + salaryMonth.ToString("MMM yyyy") + "');");
|
|
}
|
|
|
|
bool bIsSalaryAprove = new SalaryProcessService().GetBySMonth(salaryMonth, emp.PayrollTypeID); //oSProcess.GetBySMonth(_salaryMonth, _payrollTypeID);
|
|
|
|
if (bIsSalaryAprove)
|
|
{
|
|
if (_isPermanent)
|
|
{
|
|
List<ReportParameter> _parameters = new List<ReportParameter>();
|
|
string logoPath1 = string.Empty;
|
|
_parameters = new List<ReportParameter>();
|
|
|
|
_parameters = GetParameters(emp, salaryMonth);
|
|
|
|
string reportName = "";
|
|
if (emp.PayrollTypeID == 1)
|
|
{
|
|
reportName = "Reports\\PaySlipForAnwar.rdlc";
|
|
}
|
|
else
|
|
{
|
|
reportName = "Reports\\PaySlipNewNMGT.rdlc";
|
|
}
|
|
|
|
return RDLCGenerator.GetBytes(reportName, _dSet, _parameters, _oSubreportDataset);
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("There is no salary information for the month of " + salaryMonth.ToString("MMM yyyy"));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//throw new CustomException(EnumExceptionType.Informational, "This salary process is not yet approved for the month of " + salaryMonth.ToString("MMM yyyy") + "');");
|
|
throw new Exception("This salary process is not yet approved for the month of " + salaryMonth.ToString("MMM yyyy"));
|
|
}
|
|
}
|
|
|
|
[NonAction]
|
|
private DataRow GetItem(DataTable Source, string sEmpNo, EnumSalaryGroup groupCode, EnumSalaryItemCode itemCode, int ITemID)
|
|
{
|
|
foreach (DataRow odRow in Source.Rows)
|
|
{
|
|
if (Convert.ToString(odRow["EMPLOYEENO"]) == sEmpNo &&
|
|
Convert.ToInt32(odRow["ItemCode"]) == (int)itemCode && Convert.ToInt32(odRow["ItemID"]) == ITemID)
|
|
{
|
|
return odRow;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
[NonAction]
|
|
private DataRow GrossMerge(DataRow destination, DataRow source, DateTime _dMonthEndDate, DateTime _dSalaryMonth, DataTable _hourTable, List<TermParameter> _termParamenters, int PayrollTypeID)
|
|
{
|
|
TermParameter termParam;
|
|
if (Convert.ToInt32(source["ItemGroup"]) == 3)
|
|
{
|
|
destination["Name"] = source["Name"];
|
|
destination["EMPLOYEENO"] = source["EMPLOYEENO"];
|
|
destination["Grade"] = source["Grade"];
|
|
destination["Designation"] = source["Designation"];
|
|
destination["Department"] = source["Department"];
|
|
destination["ActualBasic"] = source["ActualBasic"];
|
|
|
|
if (Convert.ToInt16(source["PAYMENTMODE"].ToString().Trim()) == (int)EnumPaymentMode.CashPayment)
|
|
{
|
|
destination["PAYMENTMODE"] = "CashPayment";
|
|
}
|
|
else if (Convert.ToInt16(source["PAYMENTMODE"].ToString().Trim()) == (int)EnumPaymentMode.BankTransfer)
|
|
{
|
|
destination["PAYMENTMODE"] = "BankTransfer";
|
|
}
|
|
else if (Convert.ToInt16(source["PAYMENTMODE"].ToString().Trim()) == (int)EnumPaymentMode.Provision)
|
|
{
|
|
destination["PAYMENTMODE"] = "Provision";
|
|
}
|
|
|
|
destination["BName"] = source["BName"];
|
|
destination["ACCOUNTNO"] = source["ACCOUNTNO"];
|
|
|
|
if (_dMonthEndDate != DateTime.MinValue)
|
|
{
|
|
destination["MonthEndDate"] = Convert.ToDateTime(_dMonthEndDate.ToString("dd MMM yyyy"));
|
|
}
|
|
else
|
|
{
|
|
destination["MonthEndDate"] = DateTime.MinValue;
|
|
}
|
|
|
|
destination["SalaryMonth"] = Convert.ToDateTime(_dSalaryMonth.ToString("MMM yyyy"));
|
|
|
|
destination["Description"] = "";
|
|
destination["ItemGroup"] = source["ITEMGROUP"];
|
|
destination["ItemCode"] = source["ITEMCode"];
|
|
destination["ItemID"] = source["ITEMID"];
|
|
destination["JoiningDate"] = Convert.ToDateTime(source["JoiningDate"]).ToString("dd MMM yyyy");
|
|
destination["TINNo"] = source["TINNo"];
|
|
return destination;
|
|
}
|
|
else
|
|
{
|
|
destination["Name"] = source["Name"];
|
|
destination["EMPLOYEENO"] = source["EMPLOYEENO"];
|
|
destination["Grade"] = source["Grade"];
|
|
destination["Designation"] = source["Designation"];
|
|
destination["Department"] = source["Department"];
|
|
destination["ActualBasic"] = source["ActualBasic"];
|
|
|
|
if (Convert.ToInt16(source["PAYMENTMODE"].ToString().Trim()) == (int)EnumPaymentMode.CashPayment)
|
|
{
|
|
destination["PAYMENTMODE"] = "CashPayment";
|
|
}
|
|
else if (Convert.ToInt16(source["PAYMENTMODE"].ToString().Trim()) == (int)EnumPaymentMode.BankTransfer)
|
|
{
|
|
destination["PAYMENTMODE"] = "BankTransfer";
|
|
}
|
|
else if (Convert.ToInt16(source["PAYMENTMODE"].ToString().Trim()) == (int)EnumPaymentMode.Provision)
|
|
{
|
|
destination["PAYMENTMODE"] = "Provision";
|
|
}
|
|
destination["BName"] = source["BName"];
|
|
destination["ACCOUNTNO"] = source["ACCOUNTNO"];
|
|
|
|
if (_dMonthEndDate != DateTime.MinValue)
|
|
{
|
|
destination["MonthEndDate"] = Convert.ToDateTime(_dMonthEndDate.ToString("dd MMM yyyy"));
|
|
}
|
|
else
|
|
{
|
|
destination["MonthEndDate"] = DateTime.MinValue;
|
|
}
|
|
|
|
destination["SalaryMonth"] = Convert.ToDateTime(_dSalaryMonth.ToString("MMM yyyy"));
|
|
//*********
|
|
//Added by Chapal
|
|
if (PayrollTypeID == 1)
|
|
{
|
|
destination["Description"] = source["Description"];
|
|
}
|
|
else
|
|
{
|
|
if ((Convert.ToInt32(source["ITEMGROUP"]) == (int)EnumSalaryGroup.Gross) && (Convert.ToInt32(source["ItemCode"]) == (int)EnumSalaryItemCode.Basic_Salary) && Convert.ToInt32(source["ItemID"]) == (int)EnumSalaryItemCode.Basic_Salary)
|
|
{
|
|
decimal hour = (decimal)_hourTable.AsEnumerable().Where(x => x.Field<int>("ItemGroup") == (int)EnumSalaryGroup.Miscellaneous
|
|
&& x.Field<int>("ItemCode") == (int)EnumSalaryItemCode.Basic_Salary
|
|
&& x.Field<int>("ItemID") == (int)EnumSalaryItemCode.Basic_Salary
|
|
&& x.Field<string>("EMPLOYEENO") == source["EMPLOYEENO"].ToString())
|
|
.Sum(o => Convert.ToDouble(o["ChangedAmount"].ToString()));
|
|
destination["Description"] = source["Description"] + " (" + hour + " Hours)";
|
|
}
|
|
else if ((Convert.ToInt32(source["ITEMGROUP"]) == (int)EnumSalaryGroup.Gross) && (Convert.ToInt32(source["ItemCode"]) == (int)EnumSalaryItemCode.Over_Time_Amount))//'Over Time'
|
|
{
|
|
decimal hour = 0;
|
|
if ((Convert.ToInt32(source["ITEMID"]) == (int)2))
|
|
{
|
|
termParam = _termParamenters.Where(o => o.TermID == 2).FirstOrDefault();
|
|
hour = _hourTable.AsEnumerable().Where(x => x.Field<decimal>("ItemGroup") == (decimal)EnumSalaryGroup.Miscellaneous && x.Field<decimal>("ItemCode") == (decimal)EnumSalaryItemCode.Over_Time_Hours && x.Field<decimal>("ItemID") == Convert.ToInt32(source["ItemID"]) && x.Field<string>("EMPLOYEENO") == source["EMPLOYEENO"].ToString()).Sum(o => o.Field<decimal>("ChangedAmount"));
|
|
hour = hour * Convert.ToDecimal((termParam.Amount / 100));
|
|
hour = hour / 2;
|
|
destination["Description"] = source["Description"] + " (" + hour + " Hours)";
|
|
}
|
|
else if ((Convert.ToInt32(source["ITEMID"]) == (int)3))
|
|
{
|
|
termParam = _termParamenters.Where(o => o.TermID == 3).FirstOrDefault();
|
|
hour = _hourTable.AsEnumerable().Where(x => x.Field<decimal>("ItemGroup") == (decimal)EnumSalaryGroup.Miscellaneous && x.Field<decimal>("ItemCode") == (decimal)EnumSalaryItemCode.Over_Time_Hours && x.Field<decimal>("ItemID") == Convert.ToInt32(source["ItemID"]) && x.Field<string>("EMPLOYEENO") == source["EMPLOYEENO"].ToString()).Sum(o => o.Field<decimal>("ChangedAmount"));
|
|
hour = hour * Convert.ToDecimal((termParam.Amount / 100));
|
|
hour = hour / 2;
|
|
destination["Description"] = source["Description"] + " (" + hour + " Hours)";
|
|
}
|
|
else if ((Convert.ToInt32(source["ITEMID"]) == (int)4))
|
|
{
|
|
termParam = _termParamenters.Where(o => o.TermID == 4).FirstOrDefault();
|
|
hour = _hourTable.AsEnumerable().Where(x => x.Field<decimal>("ItemGroup") == (decimal)EnumSalaryGroup.Miscellaneous && x.Field<decimal>("ItemCode") == (decimal)EnumSalaryItemCode.Over_Time_Hours && x.Field<decimal>("ItemID") == Convert.ToInt32(source["ItemID"]) && x.Field<string>("EMPLOYEENO") == source["EMPLOYEENO"].ToString()).Sum(o => o.Field<decimal>("ChangedAmount"));
|
|
hour = hour * Convert.ToDecimal((termParam.Amount / 100));
|
|
hour = hour / 2;
|
|
destination["Description"] = source["Description"] + " (" + hour + " Hours)";
|
|
}
|
|
else
|
|
{
|
|
hour = _hourTable.AsEnumerable().Where(x => x.Field<decimal>("ItemGroup") == (decimal)EnumSalaryGroup.Miscellaneous && x.Field<decimal>("ItemCode") == (decimal)EnumSalaryItemCode.Over_Time_Hours && x.Field<decimal>("ItemID") == Convert.ToInt32(source["ItemID"]) && x.Field<string>("EMPLOYEENO") == source["EMPLOYEENO"].ToString()).Sum(o => o.Field<decimal>("ChangedAmount"));
|
|
destination["Description"] = source["Description"] + " (" + hour + " Hours)";
|
|
}
|
|
}
|
|
else if ((Convert.ToInt32(source["ITEMGROUP"]) == (int)EnumSalaryGroup.Gross) && (Convert.ToInt32(source["ItemCode"]) == (int)EnumSalaryItemCode.Allowance) && Convert.ToInt32(source["ItemID"]) == 107) //T shift
|
|
{
|
|
decimal hour = _hourTable.AsEnumerable().Where(x => x.Field<decimal>("ItemGroup") == (decimal)EnumSalaryGroup.Miscellaneous && x.Field<decimal>("ItemCode") == (decimal)EnumSalaryItemCode.Allowance && x.Field<decimal>("ItemID") == 107 && x.Field<string>("EMPLOYEENO") == source["EMPLOYEENO"].ToString()).Sum(o => o.Field<decimal>("ChangedAmount"));
|
|
destination["Description"] = source["Description"] + " (" + hour + " Days)";
|
|
}
|
|
else if ((Convert.ToInt32(source["ITEMGROUP"]) == (int)EnumSalaryGroup.Gross) && (Convert.ToInt32(source["ItemCode"]) == (int)EnumSalaryItemCode.Allowance) && Convert.ToInt32(source["ItemID"]) == 13) //Tea Allowance
|
|
{
|
|
decimal hour = _hourTable.AsEnumerable().Where(x => x.Field<decimal>("ItemGroup") == (decimal)EnumSalaryGroup.Miscellaneous && x.Field<decimal>("ItemCode") == (decimal)EnumSalaryItemCode.Allowance && x.Field<decimal>("ItemID") == 13 && x.Field<string>("EMPLOYEENO") == source["EMPLOYEENO"].ToString()).Sum(o => o.Field<decimal>("ChangedAmount"));
|
|
destination["Description"] = source["Description"] + " (" + hour + " Days)";
|
|
}
|
|
else if ((Convert.ToInt32(source["ITEMGROUP"]) == (int)EnumSalaryGroup.Gross) && (Convert.ToInt32(source["ItemCode"]) == (int)EnumSalaryItemCode.Allowance) && Convert.ToInt32(source["ItemID"]) == 106)
|
|
{
|
|
decimal hour = _hourTable.AsEnumerable().Where(x => x.Field<decimal>("ItemGroup") == (decimal)EnumSalaryGroup.Miscellaneous && x.Field<decimal>("ItemCode") == (decimal)EnumSalaryItemCode.Allowance && x.Field<decimal>("ItemID") == 106 && x.Field<string>("EMPLOYEENO") == source["EMPLOYEENO"].ToString()).Sum(o => o.Field<decimal>("ChangedAmount"));
|
|
destination["Description"] = source["Description"] + " (" + hour + " Days)";
|
|
}
|
|
else if ((Convert.ToInt32(source["ITEMGROUP"]) == (int)EnumSalaryGroup.Gross) && (Convert.ToInt32(source["ItemCode"]) == (int)EnumSalaryItemCode.Allowance) && Convert.ToInt32(source["ItemID"]) == 82) // Convence
|
|
{
|
|
decimal hour = _hourTable.AsEnumerable().Where(x => x.Field<decimal>("ItemGroup") == (decimal)EnumSalaryGroup.Miscellaneous && x.Field<decimal>("ItemCode") == (decimal)EnumSalaryItemCode.Allowance && x.Field<decimal>("ItemID") == 82 && x.Field<string>("EMPLOYEENO") == source["EMPLOYEENO"].ToString()).Sum(o => o.Field<decimal>("ChangedAmount"));
|
|
destination["Description"] = source["Description"] + " (" + hour + " Days)";
|
|
}
|
|
|
|
else
|
|
{
|
|
destination["Description"] = source["Description"];
|
|
}
|
|
}
|
|
//*******
|
|
|
|
destination["ItemGroup"] = source["ITEMGROUP"];
|
|
destination["ItemCode"] = source["ITEMCode"];
|
|
destination["ItemID"] = source["ITEMID"];
|
|
destination["JoiningDate"] = Convert.ToDateTime(source["JoiningDate"]).ToString("dd MMM yyyy");
|
|
destination["TINNo"] = source["TINNo"];
|
|
return destination;
|
|
}
|
|
}
|
|
|
|
[NonAction]
|
|
public List<ReportParameter> GetParameters(Employee emp, DateTime Month)
|
|
{
|
|
SystemInformation _systemInfo = new SystemInformationService().Get();
|
|
List<ReportParameter> _parameters = new List<ReportParameter>();
|
|
|
|
string logoPath1 = Directory.GetCurrentDirectory() + "\\images\\logo2.png";
|
|
ReportParameter _rParam;
|
|
ReportParameter rParam;
|
|
|
|
if (System.IO.File.Exists(logoPath1) == true)
|
|
{
|
|
_rParam = new ReportParameter("Logo", logoPath1);
|
|
_parameters.Add(_rParam);
|
|
}
|
|
|
|
if (emp.PayrollTypeID == 1)
|
|
{
|
|
|
|
rParam = new ReportParameter("isBold", false.ToString());
|
|
_parameters.Add(rParam);
|
|
}
|
|
else
|
|
{
|
|
|
|
rParam = new ReportParameter("isBold", true.ToString());
|
|
_parameters.Add(rParam);
|
|
}
|
|
|
|
rParam = new ReportParameter("PrintedBy", emp.Name);
|
|
_parameters.Add(rParam);
|
|
|
|
rParam = new ReportParameter("salaryMonthDT", Month.ToString("MMMM") + " " + Month.Year);
|
|
_parameters.Add(rParam);
|
|
|
|
PayrollType oPT = new PayrollTypeService().Get(emp.PayrollTypeID);
|
|
|
|
if (oPT != null)
|
|
{
|
|
if (oPT.ID == 1)
|
|
{
|
|
//_rParam = new ReportParameter("Logo", _PATH);
|
|
//_parameters.Add(_rParam);
|
|
|
|
_rParam = new ReportParameter("CompanyInfo", oPT.Description);
|
|
_parameters.Add(_rParam);
|
|
|
|
//string address = " Bay's Galleria (1st floor)\n 57 Gulshan Avenue\n Dhaka 1212";
|
|
string address = _systemInfo.corporateAddress.ToString();
|
|
_rParam = new ReportParameter("Address", address);
|
|
_parameters.Add(_rParam);
|
|
|
|
//string phone = "+880 (2) 883 4990 (Auto Hunting) \nFacsimile: +880 (2) 883 4377";
|
|
string phone = _systemInfo.TelephoneNo.ToString();
|
|
_rParam = new ReportParameter("Phone", phone);
|
|
_parameters.Add(_rParam);
|
|
|
|
}
|
|
else if (oPT.ID == 2)
|
|
{
|
|
//_PATH = Server.MapPath("images/logo2.png");
|
|
//_rParam = new ReportParameter("Logo", _PATH);
|
|
//_parameters.Add(_rParam);
|
|
|
|
_rParam = new ReportParameter("CompanyInfo", oPT.Description);
|
|
_parameters.Add(_rParam);
|
|
|
|
string address = "36 Dilkusha C/A (13th floor)\n Dhaka 1000 ";
|
|
_rParam = new ReportParameter("Address", address);
|
|
_parameters.Add(_rParam);
|
|
|
|
string phone = "+880 (2) 957 1842 (Auto Hunting) \nFacsimile: +880 (2) 716 1544";
|
|
_rParam = new ReportParameter("Phone", phone);
|
|
_parameters.Add(_rParam);
|
|
}
|
|
else
|
|
{
|
|
//_PATH = Server.MapPath("images/logo2.png");
|
|
//_rParam = new ReportParameter("Logo", _PATH);
|
|
//_parameters.Add(_rParam);
|
|
|
|
_rParam = new ReportParameter("CompanyInfo", oPT.Description);
|
|
_parameters.Add(_rParam);
|
|
|
|
string address = "Eunoos Trade Centre (Level 21) \n52-53 Dilkusha C/A \nDhaka 1000 ";
|
|
_rParam = new ReportParameter("Address", address);
|
|
_parameters.Add(_rParam);
|
|
|
|
string phone = "+880 (2) 957 1170 (Auto Hunting)\nFacsimile: +880 (2) 957 1171";
|
|
_rParam = new ReportParameter("Phone", phone);
|
|
_parameters.Add(_rParam);
|
|
}
|
|
}
|
|
|
|
|
|
_rParam = new ReportParameter("SearchCriteria", " ", false);
|
|
_parameters.Add(_rParam);
|
|
return _parameters;
|
|
}
|
|
|
|
//[NonAction]
|
|
//private string SelectMonth(int month)
|
|
//{
|
|
// if (month == 1)
|
|
// {
|
|
// return "January";
|
|
// }
|
|
// if (month == 2)
|
|
// {
|
|
// return "February";
|
|
// }
|
|
// if (month == 3)
|
|
// {
|
|
// return "March";
|
|
// }
|
|
// if (month == 4)
|
|
// {
|
|
// return "April";
|
|
// }
|
|
// if (month == 5)
|
|
// {
|
|
// return "May";
|
|
// }
|
|
// if (month == 6)
|
|
// {
|
|
// return "June";
|
|
// }
|
|
// if (month == 7)
|
|
// {
|
|
// return "July";
|
|
// }
|
|
// if (month == 8)
|
|
// {
|
|
// return "August";
|
|
// }
|
|
// if (month == 9)
|
|
// {
|
|
// return "September";
|
|
// }
|
|
// if (month == 10)
|
|
// {
|
|
// return "October";
|
|
// }
|
|
// if (month == 11)
|
|
// {
|
|
// return "November";
|
|
// }
|
|
// if (month == 12)
|
|
// {
|
|
// return "December";
|
|
// }
|
|
// else
|
|
// return "";
|
|
//}
|
|
|
|
|
|
[HttpPost]
|
|
[Route("syncMobileOfflineData")]
|
|
public ActionResult SyncMobileOfflineData(List<AttnMobileRawData> oAttnMobileRawData)
|
|
{
|
|
|
|
try
|
|
{
|
|
_attnMobileRawDataService.SaveBulkMobileAttnRawData(oAttnMobileRawData);
|
|
new AttendanceProcess().MobileDataThreadProcess(oAttnMobileRawData);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
}
|
|
}
|
|
|