แก้ไขหน้า ปรับเลื่อนเงินเดือน และปรับโควต้า

This commit is contained in:
Nakorn Rientrakrunchai
2020-02-28 13:09:50 +07:00
parent d9ca4b0aed
commit 1ca6d4955d
43 changed files with 2854 additions and 372 deletions

View File

@@ -31,6 +31,8 @@ namespace TodoAPI2.Models
public int? managed_by { get; set; }
public string active_mode { get; set; }
public List<eva_adjust_postponement_detail_quota_02InputModel> adjust_postponement_detail_quota_02_model;
}
}

View File

@@ -23,14 +23,17 @@ namespace TodoAPI2.Models
private IMyDatabase db;
private Iexternal_linkageService ext;
private Iexternal_employeeService emp;
private Ieva_adjust_postponement_detail_quota_02Service quota02;
public eva_adjust_postponement_quotaService(IBaseRepository2<eva_adjust_postponementEntity, int> repository, IMyDatabase mydb,
Iexternal_linkageService inext, Iexternal_employeeService inemp)
Iexternal_linkageService inext, Iexternal_employeeService inemp,
Ieva_adjust_postponement_detail_quota_02Service inquota02)
{
_repository = repository;
db = mydb;
ext = inext;
emp = inemp;
quota02 = inquota02;
}
#region Private Functions
@@ -147,18 +150,159 @@ namespace TodoAPI2.Models
return newkey.Value;
}
public int GetNewPrimaryKeyDetail()
{
int? newkey = 0;
var x = (from i in _repository.Context.eva_adjust_postponement_detail
orderby i.id descending
select i).Take(1).ToList();
if (x.Count > 0)
{
newkey = x[0].id + 1;
}
return newkey.Value;
}
public eva_adjust_postponement_quotaViewModel Insert(eva_adjust_postponement_quotaInputModel model)
{
var entity = GetEntity(model);
entity.id = GetNewPrimaryKey();
var all_emp = (from i in emp.GetListByemployee_type(null, null) select i.id).ToList();
AddMultipleDetail(entity.id, all_emp, entity.fiscal_year, entity.theRound);
var inserted = _repository.Insert(entity);
return Get(inserted.id);
}
public string AddMultipleDetail(int? adjust_postponement_quota_id, List<int> model, int? fiscal_year, int? theRound)
{
if (!adjust_postponement_quota_id.HasValue)
{
return "0";
}
else
{
int k = 0;
var all_emp = emp.GetListByemployee_type(null, null);
var cylinder = (from z in _repository.Context.eva_salary_cylinder
select z).ToList();
int newkey = GetNewPrimaryKeyDetail();
var ex = (from x in _repository.Context.eva_adjust_postponement_detail
where x.adjust_postponement_quota_id == adjust_postponement_quota_id
select x.employee_id).ToList();
decimal sum_salary = 0;
foreach (var i in model)
{
if (checkExistEmployeeInExternal(i, all_emp))
{
if (!checkExistEmployeeInInternal(i, ex))
{
var q = (from p in _repository.Context.eva_adjust_postponement_detail
where p.employee_id == i
&& p.eva_adjust_postponement.fiscal_year == fiscal_year
&& p.eva_adjust_postponement.theRound == theRound
select p).FirstOrDefault();
if (q != null)
{
q.adjust_postponement_quota_id = adjust_postponement_quota_id;
q.updated = DateTime.Now;
q.isActive = true;
k++;
}
else
{
var theemp = (from x in all_emp where x.id == i select x).FirstOrDefault();
var r = new eva_adjust_postponement_detailEntity();
r.id = newkey;
r.adjust_postponement_id = null;
r.adjust_postponement_quota_id = adjust_postponement_quota_id;
r.employee_id = i;
if (theemp.salary.HasValue)
{
r.sarary = theemp.salary;
sum_salary += r.sarary.Value;
}
else
{
r.sarary = 0;
}
var c = getCylinderForEmployee(theemp, cylinder);
r.cost_living = 0;
r.middle = 0;
if (c != null)
{
r.middle = c.middle;
r.cost_living = c.cost_living;
}
r.promoted_percentage = 0;
r.total_promote = 0;
r.new_sarary = r.sarary;
r.new_cost_living = r.cost_living;
r.remark = null;
r.receive_quota = 0;
r.new_sarary_with_quota = r.sarary;
r.created = DateTime.Now;
r.updated = DateTime.Now;
r.isActive = true;
_repository.Context.Add(r);
newkey++;
}
}
}
}
//_repository.Context.SaveChanges();
return k.ToString();
}
}
private eva_salary_cylinderEntity getCylinderForEmployee(external_employeeViewModel theemp,
List<eva_salary_cylinderEntity> all_cylinder)
{
var c = (from i in all_cylinder
where i.position_level == theemp.position_level_id
&& i.position_type == theemp.position_type_id
select i).FirstOrDefault();
return c;
}
private bool checkExistEmployeeInExternal(int emp_id, List<external_employeeViewModel> emp)
{
foreach (var i in emp)
{
if (i.id == emp_id) return true;
}
return false;
}
private bool checkExistEmployeeInInternal(int emp_id, List<int?> ex)
{
foreach (var i in ex)
{
if (i.Value == emp_id) return true;
}
return false;
}
public eva_adjust_postponement_quotaViewModel Update(int id, eva_adjust_postponement_quotaInputModel model)
{
var existingEntity = _repository.Get(id);
@@ -172,6 +316,7 @@ namespace TodoAPI2.Models
existingEntity.command_no = model.command_no;
existingEntity.managed_by = model.managed_by;
quota02.UpdateMultiple(model.adjust_postponement_detail_quota_02_model);
var updated = _repository.Update(id, existingEntity);
return Get(updated.id);
@@ -235,6 +380,11 @@ namespace TodoAPI2.Models
}
public void Delete(int id)
{
var data = from i in _repository.Context.eva_adjust_postponement_detail
where i.adjust_postponement_quota_id == id && i.adjust_postponement_id == null
select i;
_repository.Context.RemoveRange(data);
_repository.Delete(id);
return;