ทำหน้าจอพิเศษ นำเข้าข้อมูลเงินเดือนย้อนหลัง

This commit is contained in:
Nakorn Rientrakrunchai
2020-12-07 15:52:20 +07:00
parent 5ca2b0d53d
commit 8ac63e8ec6
44 changed files with 5165 additions and 42 deletions

View File

@@ -41,6 +41,19 @@ namespace TodoAPI2.Models
public int? managed_by { get; set; }
[MaxLength(1000)]
public string imported_file { get; set; }
[NotMapped]
public string imported_fileDisplay
{
get
{
return (string.IsNullOrEmpty(imported_file) ? "" :
FileUtil.GetFileInfo(TTSW.Constant.FilePathConstant.DirType.FilesTestUpload, id, imported_file).RelativePath).Replace(@"\", "/");
}
}
public DateTime? imported_date { get; set; }
}
}

View File

@@ -20,19 +20,19 @@ namespace TodoAPI2.Models
public class eva_adjust_postponementService : Ieva_adjust_postponementService
{
private IBaseRepository2<eva_adjust_postponementEntity, int> _repository;
private IMyDatabase db;
private Iexternal_linkageService ext;
private IMyDatabase db;
private Iexternal_linkageService ext;
private Iexternal_employeeService emp;
private Ieva_adjust_postponement_detail_normalService detail;
public eva_adjust_postponementService(IBaseRepository2<eva_adjust_postponementEntity, int> repository,
public eva_adjust_postponementService(IBaseRepository2<eva_adjust_postponementEntity, int> repository,
IMyDatabase mydb, Iexternal_linkageService inext,
Iexternal_employeeService inemp,
Ieva_adjust_postponement_detail_normalService indetail)
{
_repository = repository;
db = mydb;
ext = inext;
db = mydb;
ext = inext;
emp = inemp;
detail = indetail;
}
@@ -54,7 +54,7 @@ namespace TodoAPI2.Models
{
return Mapper.Map<List<eva_adjust_postponementViewModel>>(entities);
}
#endregion
#region Public Functions
@@ -89,12 +89,12 @@ namespace TodoAPI2.Models
public List<eva_adjust_postponementViewModel> GetListByfiscal_year(int? fiscal_year)
{
var model = new eva_adjust_postponementSearchModel();
var model = new eva_adjust_postponementSearchModel();
model.fiscal_year = fiscal_year;
return GetListBySearch(model);
}
public List<eva_adjust_postponementViewModel> GetListBySearch(eva_adjust_postponementSearchModel model)
public List<eva_adjust_postponementViewModel> GetListBySearch(eva_adjust_postponementSearchModel model)
{
var all_emp = emp.GetListByemployee_type(null, null);
@@ -110,7 +110,7 @@ namespace TodoAPI2.Models
from fk_external_linkageResult11 in external_linkageResult11.DefaultIfEmpty()
where 1==1
where 1 == 1
//&& (m_eva_adjust_postponement.id == model.id || !model.id.HasValue)
&& (m_eva_adjust_postponement.fiscal_year == model.fiscal_year || !model.fiscal_year.HasValue)
&& (m_eva_adjust_postponement.theRound == model.theRound || !model.theRound.HasValue)
@@ -153,10 +153,10 @@ namespace TodoAPI2.Models
int? newkey = 0;
var x = (from i in _repository.Context.eva_adjust_postponement
orderby i.id descending
select i).Take(1).ToList();
orderby i.id descending
select i).Take(1).ToList();
if(x.Count > 0)
if (x.Count > 0)
{
newkey = x[0].id + 1;
}
@@ -172,7 +172,7 @@ namespace TodoAPI2.Models
var inserted = _repository.Insert(entity);
detail.ReCreatePostponementDetailNormal(entity);
return Get(inserted.id);
}
@@ -198,29 +198,29 @@ namespace TodoAPI2.Models
return Get(updated.id);
}
else
throw new NotificationException("No data to update");
throw new NotificationException("No data to update");
}
public string UpdateMultiple(List<eva_adjust_postponementInputModel> model)
public string UpdateMultiple(List<eva_adjust_postponementInputModel> model)
{
foreach(var i in model)
foreach (var i in model)
{
if (i.active_mode == "1" && i.id.HasValue) // update
{
{
var existingEntity = _repository.Get(i.id.Value);
if (existingEntity != null)
{
existingEntity.fiscal_year = i.fiscal_year;
existingEntity.theDate = i.theDate;
existingEntity.theRound = i.theRound;
existingEntity.create_evaluation_id = i.create_evaluation_id;
existingEntity.limit = i.limit;
existingEntity.limit_frame = i.limit_frame;
existingEntity.limit_quota = i.limit_quota;
existingEntity.limit_frame_quota = i.limit_frame_quota;
existingEntity.percentage = i.percentage;
existingEntity.command_no = i.command_no;
existingEntity.managed_by = i.managed_by;
existingEntity.fiscal_year = i.fiscal_year;
existingEntity.theDate = i.theDate;
existingEntity.theRound = i.theRound;
existingEntity.create_evaluation_id = i.create_evaluation_id;
existingEntity.limit = i.limit;
existingEntity.limit_frame = i.limit_frame;
existingEntity.limit_quota = i.limit_quota;
existingEntity.limit_frame_quota = i.limit_frame_quota;
existingEntity.percentage = i.percentage;
existingEntity.command_no = i.command_no;
existingEntity.managed_by = i.managed_by;
_repository.UpdateWithoutCommit(i.id.Value, existingEntity);
@@ -233,15 +233,15 @@ namespace TodoAPI2.Models
_repository.InsertWithoutCommit(entity);
}
else if (i.active_mode == "0" && i.id.HasValue) // remove
{
{
_repository.DeleteWithoutCommit(i.id.Value);
}
else if (i.active_mode == "0" && !i.id.HasValue)
{
// nothing to do
}
}
}
_repository.Context.SaveChanges();
_repository.Context.SaveChanges();
return model.Count().ToString();
}
@@ -259,8 +259,7 @@ namespace TodoAPI2.Models
return Get(updated.id);
}
public void Delete(int id)
{
{
_repository.Delete(id);

View File

@@ -21,7 +21,7 @@ namespace TodoAPI2.Models
eva_adjust_postponement_detailWithSelectionViewModel GetWithSelection(int id);
eva_adjust_postponement_detailWithSelectionViewModel GetBlankItem();
int GetNewPrimaryKey();
}
}

View File

@@ -47,6 +47,10 @@ namespace TodoAPI2.Models
public decimal? new_sarary_with_quota { get; set; }
[MaxLength(1000)]
public string position_this_time { get; set; }
[MaxLength(1000)]
public string level_this_time { get; set; }
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
using TodoAPI2.Models;
namespace TodoAPI2.Models
{
public interface Ieva_adjust_postponement_detail_migrationService : IBaseService<int, eva_adjust_postponement_detail_migrationInputModel, eva_adjust_postponement_detail_migrationViewModel>
{
new eva_adjust_postponement_detail_migrationViewModel Insert(eva_adjust_postponement_detail_migrationInputModel model);
new eva_adjust_postponement_detail_migrationViewModel Update(int id, eva_adjust_postponement_detail_migrationInputModel model);
List<eva_adjust_postponement_detail_migrationViewModel> GetListByadjust_postponement_id(int? adjust_postponement_id);
List<eva_adjust_postponement_detail_migrationViewModel> GetListBySearch(eva_adjust_postponement_detail_migrationSearchModel model);
string UpdateMultiple(List<eva_adjust_postponement_detail_migrationInputModel> model);
eva_adjust_postponement_detail_migrationWithSelectionViewModel GetWithSelection(int id);
eva_adjust_postponement_detail_migrationWithSelectionViewModel GetBlankItem();
void RefreshAutoFieldOfAllData();
eva_adjust_postponement_detailEntity GetEntity(int id);
DataContext GetContext();
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_detail_migrationInputModel
{
public int? id { get; set; }
public int? adjust_postponement_id { get; set; }
public int? adjust_postponement_quota_id { get; set; }
public int? employee_id { get; set; }
public decimal? sarary { get; set; }
public decimal? cost_living { get; set; }
public decimal? middle { get; set; }
public decimal? promoted_percentage { get; set; }
public decimal? total_promote { get; set; }
public decimal? new_sarary { get; set; }
public decimal? new_cost_living { get; set; }
public string remark { get; set; }
public decimal? receive_quota { get; set; }
public decimal? new_sarary_with_quota { get; set; }
public string position_this_time { get; set; }
public string level_this_time { get; set; }
public string active_mode { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_detail_migrationReportRequestModel : eva_adjust_postponement_detail_migrationSearchModel
{
public string filetype { get; set; }
public string contentType { get { return MyHelper.GetContentType(filetype); } }
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_detail_migrationSearchModel
{
public int id { get; set; }
public int? adjust_postponement_id { get; set; }
public int? adjust_postponement_quota_id { get; set; }
}
}

View File

@@ -0,0 +1,337 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
using TodoAPI2.Models;
using System.IO;
using System.Web;
using System.Net;
using TTSW.Configure;
using Microsoft.Extensions.Options;
using System.Data;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_detail_migrationService : Ieva_adjust_postponement_detail_migrationService
{
private IBaseRepository2<eva_adjust_postponement_detailEntity, int> _repository;
private IMyDatabase db;
private Iexternal_linkageService ext;
private Iexternal_employeeService emp;
public eva_adjust_postponement_detail_migrationService(IBaseRepository2<eva_adjust_postponement_detailEntity, int> repository,
IMyDatabase mydb, Iexternal_linkageService inext, Iexternal_employeeService inemp)
{
_repository = repository;
db = mydb;
ext = inext;
emp = inemp;
}
#region Private Functions
private eva_adjust_postponement_detailEntity GetEntity(eva_adjust_postponement_detail_migrationInputModel model)
{
return Mapper.Map<eva_adjust_postponement_detailEntity>(model);
}
private List<eva_adjust_postponement_detailEntity> GetEntityList(List<eva_adjust_postponement_detail_migrationInputModel> models)
{
return Mapper.Map<List<eva_adjust_postponement_detailEntity>>(models);
}
private eva_adjust_postponement_detail_migrationViewModel GetDto(eva_adjust_postponement_detailEntity entity)
{
return Mapper.Map<eva_adjust_postponement_detail_migrationViewModel>(entity);
}
private List<eva_adjust_postponement_detail_migrationViewModel> GetDtoList(List<eva_adjust_postponement_detailEntity> entities)
{
return Mapper.Map<List<eva_adjust_postponement_detail_migrationViewModel>>(entities);
}
#endregion
#region Public Functions
#region Query Functions
public eva_adjust_postponement_detail_migrationViewModel Get(int id)
{
var entity = _repository.Get(id);
return GetDto(entity);
}
public eva_adjust_postponement_detailEntity GetEntity(int id)
{
var entity = _repository.Get(id);
return entity;
}
public DataContext GetContext()
{
return _repository.Context;
}
public eva_adjust_postponement_detail_migrationWithSelectionViewModel GetWithSelection(int id)
{
var entity = _repository.Get(id);
var i = Mapper.Map<eva_adjust_postponement_detail_migrationWithSelectionViewModel>(entity);
var all_emp = emp.GetListByemployee_type(null, null);
i.item_employee_id = all_emp.ToList();
return i;
}
public eva_adjust_postponement_detail_migrationWithSelectionViewModel GetBlankItem()
{
var i = new eva_adjust_postponement_detail_migrationWithSelectionViewModel();
var all_emp = emp.GetListByemployee_type(null, null);
i.item_employee_id = all_emp.ToList();
return i;
}
public List<eva_adjust_postponement_detail_migrationViewModel> GetListByadjust_postponement_id(int? adjust_postponement_id)
{
var model = new eva_adjust_postponement_detail_migrationSearchModel();
model.adjust_postponement_id = adjust_postponement_id;
return GetListBySearch(model);
}
public List<eva_adjust_postponement_detail_migrationViewModel> GetListBySearch(eva_adjust_postponement_detail_migrationSearchModel model)
{
var data = (
from m_eva_adjust_postponement_detail_migration in _repository.Context.eva_adjust_postponement_detail
join fk_eva_adjust_postponement1 in _repository.Context.eva_adjust_postponement on m_eva_adjust_postponement_detail_migration.adjust_postponement_id equals fk_eva_adjust_postponement1.id
into eva_adjust_postponementResult1
from fk_eva_adjust_postponementResult1 in eva_adjust_postponementResult1.DefaultIfEmpty()
join fk_eva_adjust_postponement2 in _repository.Context.eva_adjust_postponement on m_eva_adjust_postponement_detail_migration.adjust_postponement_quota_id equals fk_eva_adjust_postponement2.id
into eva_adjust_postponementResult2
from fk_eva_adjust_postponementResult2 in eva_adjust_postponementResult2.DefaultIfEmpty()
join fk_external_linkage3 in emp.GetListByemployee_type(null, null) on m_eva_adjust_postponement_detail_migration.employee_id equals fk_external_linkage3.id
into external_linkageResult3
from fk_external_linkageResult3 in external_linkageResult3.DefaultIfEmpty()
where
(m_eva_adjust_postponement_detail_migration.id == model.id)
|| (model.adjust_postponement_id.HasValue && m_eva_adjust_postponement_detail_migration.adjust_postponement_id == model.adjust_postponement_id)
|| (model.adjust_postponement_quota_id.HasValue && m_eva_adjust_postponement_detail_migration.adjust_postponement_quota_id == model.adjust_postponement_quota_id)
orderby m_eva_adjust_postponement_detail_migration.created descending
select new eva_adjust_postponement_detail_migrationViewModel()
{
id = m_eva_adjust_postponement_detail_migration.id,
adjust_postponement_id = m_eva_adjust_postponement_detail_migration.adjust_postponement_id,
adjust_postponement_quota_id = m_eva_adjust_postponement_detail_migration.adjust_postponement_quota_id,
employee_id = m_eva_adjust_postponement_detail_migration.employee_id,
sarary = m_eva_adjust_postponement_detail_migration.sarary,
cost_living = m_eva_adjust_postponement_detail_migration.cost_living,
middle = m_eva_adjust_postponement_detail_migration.middle,
promoted_percentage = m_eva_adjust_postponement_detail_migration.promoted_percentage,
total_promote = m_eva_adjust_postponement_detail_migration.total_promote,
new_sarary = m_eva_adjust_postponement_detail_migration.new_sarary,
new_cost_living = m_eva_adjust_postponement_detail_migration.new_cost_living,
remark = m_eva_adjust_postponement_detail_migration.remark,
receive_quota = m_eva_adjust_postponement_detail_migration.receive_quota,
new_sarary_with_quota = m_eva_adjust_postponement_detail_migration.new_sarary_with_quota,
position_this_time = m_eva_adjust_postponement_detail_migration.position_this_time,
level_this_time = m_eva_adjust_postponement_detail_migration.level_this_time,
adjust_postponement_id_eva_adjust_postponement_fiscal_year = fk_eva_adjust_postponementResult1.fiscal_year,
adjust_postponement_quota_id_eva_adjust_postponement_fiscal_year = fk_eva_adjust_postponementResult2.fiscal_year,
employee_id_external_linkage_external_name = fk_external_linkageResult3.fullname,
isActive = m_eva_adjust_postponement_detail_migration.isActive,
Created = m_eva_adjust_postponement_detail_migration.created,
Updated = m_eva_adjust_postponement_detail_migration.updated
}
).Take(1000).ToList();
return data;
}
#endregion
#region Manipulation Functions
public int GetNewPrimaryKey()
{
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_detail_migrationViewModel Insert(eva_adjust_postponement_detail_migrationInputModel model)
{
var entity = GetEntity(model);
entity.id = GetNewPrimaryKey();
var inserted = _repository.Insert(entity);
return Get(inserted.id);
}
public eva_adjust_postponement_detail_migrationViewModel Update(int id, eva_adjust_postponement_detail_migrationInputModel model)
{
var existingEntity = _repository.Get(id);
if (existingEntity != null)
{
existingEntity.adjust_postponement_id = model.adjust_postponement_id;
existingEntity.adjust_postponement_quota_id = model.adjust_postponement_quota_id;
existingEntity.employee_id = model.employee_id;
existingEntity.sarary = model.sarary;
existingEntity.cost_living = model.cost_living;
existingEntity.middle = model.middle;
existingEntity.promoted_percentage = model.promoted_percentage;
existingEntity.total_promote = model.total_promote;
existingEntity.new_sarary = model.new_sarary;
existingEntity.new_cost_living = model.new_cost_living;
existingEntity.remark = model.remark;
existingEntity.receive_quota = model.receive_quota;
existingEntity.new_sarary_with_quota = model.new_sarary_with_quota;
existingEntity.position_this_time = model.position_this_time;
existingEntity.level_this_time = model.level_this_time;
var updated = _repository.Update(id, existingEntity);
return Get(updated.id);
}
else
throw new NotificationException("No data to update");
}
public string UpdateMultiple(List<eva_adjust_postponement_detail_migrationInputModel> model)
{
foreach (var i in model)
{
if (i.active_mode == "1" && i.id.HasValue) // update
{
var existingEntity = _repository.Get(i.id.Value);
if (existingEntity != null)
{
existingEntity.adjust_postponement_id = i.adjust_postponement_id;
existingEntity.adjust_postponement_quota_id = i.adjust_postponement_quota_id;
existingEntity.employee_id = i.employee_id;
existingEntity.sarary = i.sarary;
existingEntity.cost_living = i.cost_living;
existingEntity.middle = i.middle;
existingEntity.promoted_percentage = i.promoted_percentage;
existingEntity.total_promote = i.total_promote;
existingEntity.new_sarary = i.new_sarary;
existingEntity.new_cost_living = i.new_cost_living;
existingEntity.remark = i.remark;
existingEntity.receive_quota = i.receive_quota;
existingEntity.new_sarary_with_quota = i.new_sarary_with_quota;
existingEntity.position_this_time = i.position_this_time;
existingEntity.level_this_time = i.level_this_time;
//existingEntity.SetAutoField(_repository.Context);
_repository.UpdateWithoutCommit(i.id.Value, existingEntity);
}
}
else if (i.active_mode == "1" && !i.id.HasValue) // add
{
var entity = GetEntity(i);
entity.id = GetNewPrimaryKey();
//entity.SetAutoField(_repository.Context);
_repository.InsertWithoutCommit(entity);
}
else if (i.active_mode == "0" && i.id.HasValue) // remove
{
_repository.DeleteWithoutCommit(i.id.Value);
}
else if (i.active_mode == "0" && !i.id.HasValue)
{
// nothing to do
}
}
_repository.Context.SaveChanges();
return model.Count().ToString();
}
public eva_adjust_postponement_detail_migrationViewModel SetAsActive(int id)
{
var updated = _repository.SetAsActive(id);
return Get(updated.id);
}
public eva_adjust_postponement_detail_migrationViewModel SetAsInactive(int id)
{
var updated = _repository.SetAsInActive(id);
return Get(updated.id);
}
public void Delete(int id)
{
_repository.Delete(id);
return;
}
public void RefreshAutoFieldOfAllData()
{
var all_items = from i in _repository.Context.eva_adjust_postponement_detail
select i;
foreach (var item in all_items)
{
//item.SetAutoField(_repository.Context);
}
_repository.Context.SaveChanges();
}
private Dictionary<string, string> GetLookupForLog()
{
var i = new Dictionary<string, string>();
i.Add("adjust_postponement_id", "รหัสอ้างอิงตาราง eva_adjust_postponement");
i.Add("adjust_postponement_id_eva_adjust_postponement_fiscal_year", "รหัสอ้างอิงตาราง eva_adjust_postponement");
i.Add("adjust_postponement_quota_id", "รหัสอ้างอิงตาราง eva_adjust_postponement");
i.Add("adjust_postponement_quota_id_eva_adjust_postponement_fiscal_year", "รหัสอ้างอิงตาราง eva_adjust_postponement");
i.Add("employee_id", "ผู้รับการประเมิน");
i.Add("employee_id_external_linkage_external_name", "ผู้รับการประเมิน");
i.Add("sarary", "เงินเดือน ก่อนปรับเลื่อน");
i.Add("cost_living", "ค่าครองชีพ ก่อนปรับเลื่อน");
i.Add("middle", "ค่ากลางฐานในการคำนวณ");
i.Add("promoted_percentage", "ร้อยละที่ได้เลื่อน");
i.Add("total_promote", "จำนวนเงินที่ได้เลื่อน");
i.Add("new_sarary", "เงินเดือนใหม่");
i.Add("new_cost_living", "ค่าครองชีพใหม่");
i.Add("remark", "หมายเหตุ");
i.Add("receive_quota", "ได้รับเงินโควต้าพิเศษ");
i.Add("new_sarary_with_quota", "เงินเดือนใหม่ (รวมโควต้า)");
i.Add("position_this_time", "ตำแหน่ง (ณ วันปรับเลื่อน)");
i.Add("level_this_time", "ระดับ (ณ วันปรับเลื่อน)");
return i;
}
#endregion
#region Match Item
#endregion
#endregion
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_detail_migrationViewModel : BaseViewModel2<int>
{
public int? adjust_postponement_id { get; set; }
public int? adjust_postponement_quota_id { get; set; }
public int? employee_id { get; set; }
public decimal? sarary { get; set; }
public decimal? cost_living { get; set; }
public decimal? middle { get; set; }
public decimal? promoted_percentage { get; set; }
public decimal? total_promote { get; set; }
public decimal? new_sarary { get; set; }
public decimal? new_cost_living { get; set; }
public string remark { get; set; }
public decimal? receive_quota { get; set; }
public decimal? new_sarary_with_quota { get; set; }
public string position_this_time { get; set; }
public string level_this_time { get; set; }
public int? adjust_postponement_id_eva_adjust_postponement_fiscal_year { get; set; }
public int? adjust_postponement_quota_id_eva_adjust_postponement_fiscal_year { get; set; }
public string employee_id_external_linkage_external_name { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_detail_migrationWithSelectionViewModel: eva_adjust_postponement_detail_migrationViewModel
{
public List<external_employeeViewModel> item_employee_id { get; set; }
}
}

View File

@@ -244,6 +244,13 @@ namespace TodoAPI2.Models
{
var theemp = (from i in all_emp where i.id == m.employee_id select i).FirstOrDefault();
if (theemp == null) continue;
if (theemp.fullname.Contains("ธัญนันท์"))
{
string zz = "1";
}
var n = new eva_adjust_postponement_detailEntity();
n.id = newkey;
newkey++;

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
using TodoAPI2.Models;
namespace TodoAPI2.Models
{
public interface Ieva_adjust_postponement_migrationService : IBaseService<int, eva_adjust_postponement_migrationInputModel, eva_adjust_postponement_migrationViewModel>
{
new eva_adjust_postponement_migrationViewModel Insert(eva_adjust_postponement_migrationInputModel model);
new eva_adjust_postponement_migrationViewModel Update(int id, eva_adjust_postponement_migrationInputModel model);
List<eva_adjust_postponement_migrationViewModel> GetListByfiscal_year(int? fiscal_year);
List<eva_adjust_postponement_migrationViewModel> GetListBySearch(eva_adjust_postponement_migrationSearchModel model);
string UpdateMultiple(List<eva_adjust_postponement_migrationInputModel> model);
eva_adjust_postponement_migrationWithSelectionViewModel GetWithSelection(int id);
eva_adjust_postponement_migrationWithSelectionViewModel GetBlankItem();
void RefreshAutoFieldOfAllData();
eva_adjust_postponementEntity GetEntity(int id);
DataContext GetContext();
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_migrationInputModel
{
public int? id { get; set; }
public int? fiscal_year { get; set; }
public DateTime? theDate { get; set; }
public int? theRound { get; set; }
public int? create_evaluation_id { get; set; }
public decimal? limit { get; set; }
public decimal? limit_frame { get; set; }
public decimal? limit_quota { get; set; }
public decimal? limit_frame_quota { get; set; }
public decimal? percentage { get; set; }
public string command_no { get; set; }
public int? managed_by { get; set; }
public string imported_file { get; set; }
public string active_mode { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_migrationReportRequestModel : eva_adjust_postponement_migrationSearchModel
{
public string filetype { get; set; }
public string contentType { get { return MyHelper.GetContentType(filetype); } }
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_migrationSearchModel
{
public int id { get; set; }
public int? fiscal_year { get; set; }
public int? theRound { get; set; }
}
}

View File

@@ -0,0 +1,487 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
using TodoAPI2.Models;
using System.IO;
using System.Web;
using System.Net;
using TTSW.Configure;
using Microsoft.Extensions.Options;
using System.Data;
using System.IO;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_migrationService : Ieva_adjust_postponement_migrationService
{
private IBaseRepository2<eva_adjust_postponementEntity, int> _repository;
private IMyDatabase db;
private Iexternal_linkageService ext;
private Iexternal_employeeService emp;
private Ieva_adjust_postponement_detailService postpone_detail;
public eva_adjust_postponement_migrationService(IBaseRepository2<eva_adjust_postponementEntity, int> repository,
IMyDatabase mydb, Iexternal_linkageService inext, Iexternal_employeeService inemp, Ieva_adjust_postponement_detailService in_postpone_detail)
{
_repository = repository;
db = mydb;
ext = inext;
emp = inemp;
postpone_detail = in_postpone_detail;
}
#region Private Functions
private eva_adjust_postponementEntity GetEntity(eva_adjust_postponement_migrationInputModel model)
{
return Mapper.Map<eva_adjust_postponementEntity>(model);
}
private List<eva_adjust_postponementEntity> GetEntityList(List<eva_adjust_postponement_migrationInputModel> models)
{
return Mapper.Map<List<eva_adjust_postponementEntity>>(models);
}
private eva_adjust_postponement_migrationViewModel GetDto(eva_adjust_postponementEntity entity)
{
return Mapper.Map<eva_adjust_postponement_migrationViewModel>(entity);
}
private List<eva_adjust_postponement_migrationViewModel> GetDtoList(List<eva_adjust_postponementEntity> entities)
{
return Mapper.Map<List<eva_adjust_postponement_migrationViewModel>>(entities);
}
#endregion
#region Public Functions
#region Query Functions
public eva_adjust_postponement_migrationViewModel Get(int id)
{
var entity = _repository.Get(id);
return GetDto(entity);
}
public eva_adjust_postponementEntity GetEntity(int id)
{
var entity = _repository.Get(id);
return entity;
}
public DataContext GetContext()
{
return _repository.Context;
}
public eva_adjust_postponement_migrationWithSelectionViewModel GetWithSelection(int id)
{
var entity = _repository.Get(id);
var i = Mapper.Map<eva_adjust_postponement_migrationWithSelectionViewModel>(entity);
i.item_create_evaluation_id = (from x in _repository.Context.eva_create_evaluation select x).ToList();
var all_emp = emp.GetListByemployee_type(null, null);
i.item_managed_by = all_emp.ToList();
return i;
}
public eva_adjust_postponement_migrationWithSelectionViewModel GetBlankItem()
{
var i = new eva_adjust_postponement_migrationWithSelectionViewModel();
i.item_create_evaluation_id = (from x in _repository.Context.eva_create_evaluation select x).ToList();
var all_emp = emp.GetListByemployee_type(null, null);
i.item_managed_by = all_emp.ToList();
return i;
}
public List<eva_adjust_postponement_migrationViewModel> GetListByfiscal_year(int? fiscal_year)
{
var model = new eva_adjust_postponement_migrationSearchModel();
model.fiscal_year = fiscal_year;
return GetListBySearch(model);
}
public List<eva_adjust_postponement_migrationViewModel> GetListBySearch(eva_adjust_postponement_migrationSearchModel model)
{
var data = (
from m_eva_adjust_postponement_migration in _repository.Context.eva_adjust_postponement
join fk_eva_create_evaluation4 in _repository.Context.eva_create_evaluation on m_eva_adjust_postponement_migration.create_evaluation_id equals fk_eva_create_evaluation4.id
into eva_create_evaluationResult4
from fk_eva_create_evaluationResult4 in eva_create_evaluationResult4.DefaultIfEmpty()
join fk_external_linkage11 in emp.GetListByemployee_type(null, null) on m_eva_adjust_postponement_migration.managed_by equals fk_external_linkage11.id
into external_linkageResult11
from fk_external_linkageResult11 in external_linkageResult11.DefaultIfEmpty()
where
1 == 1
&& (!model.fiscal_year.HasValue || m_eva_adjust_postponement_migration.fiscal_year == model.fiscal_year)
&& (!model.theRound.HasValue || m_eva_adjust_postponement_migration.theRound == model.theRound)
orderby m_eva_adjust_postponement_migration.created descending
select new eva_adjust_postponement_migrationViewModel()
{
id = m_eva_adjust_postponement_migration.id,
fiscal_year = m_eva_adjust_postponement_migration.fiscal_year,
theDate = m_eva_adjust_postponement_migration.theDate,
theRound = m_eva_adjust_postponement_migration.theRound,
create_evaluation_id = m_eva_adjust_postponement_migration.create_evaluation_id,
limit = m_eva_adjust_postponement_migration.limit,
limit_frame = m_eva_adjust_postponement_migration.limit_frame,
limit_quota = m_eva_adjust_postponement_migration.limit_quota,
limit_frame_quota = m_eva_adjust_postponement_migration.limit_frame_quota,
percentage = m_eva_adjust_postponement_migration.percentage,
command_no = m_eva_adjust_postponement_migration.command_no,
managed_by = m_eva_adjust_postponement_migration.managed_by,
imported_file = m_eva_adjust_postponement_migration.imported_file,
imported_fileDisplay = m_eva_adjust_postponement_migration.imported_fileDisplay,
create_evaluation_id_eva_create_evaluation_performance_plan_id = fk_eva_create_evaluationResult4.performance_plan_id,
managed_by_external_linkage_external_name = fk_external_linkageResult11.fullname,
isActive = m_eva_adjust_postponement_migration.isActive,
Created = m_eva_adjust_postponement_migration.created,
Updated = m_eva_adjust_postponement_migration.updated
}
).Take(1000).ToList();
return data;
}
#endregion
#region Manipulation Functions
public int GetNewPrimaryKey()
{
int? newkey = 0;
var x = (from i in _repository.Context.eva_adjust_postponement
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_migrationViewModel Insert(eva_adjust_postponement_migrationInputModel model)
{
var entity = GetEntity(model);
entity.id = GetNewPrimaryKey();
if (!string.IsNullOrEmpty(model.imported_file))
{
//Move file from temp to physical
string imported_fileFileName = FileUtil.MoveTempUploadFileToActualPath(
model.imported_file, FilePathConstant.DirType.FilesTestUpload, entity.id);
entity.imported_file = imported_fileFileName;
var filepath = FileUtil.GetFileInfo(TTSW.Constant.FilePathConstant.DirType.FilesTestUpload, entity.id, entity.imported_file).PhysicalPath;
entity.command_no = AddItems(filepath, entity.id);
}
else
{
throw new Exception("ไม่ได้แนบไฟล์เข้ามา ไม่สามารถเพิ่มรายการประวัติเงินเดือนย้อนหลัง ได้");
}
entity.imported_date = DateTime.Now;
var inserted = _repository.Insert(entity);
return Get(inserted.id);
}
private string AddItems(string filepath, int id)
{
string return_text = "";
var excel = GetDataTableFromExcel(filepath);
var all_emp = (from q in emp.GetAllEmployee()
select q).ToList();
var newkey = postpone_detail.GetNewPrimaryKey();
for (int j = 0; j < excel.Rows.Count; j++)
{
string employee_no = "N/A";
try
{
string position = excel.Rows[j]["position"].ToString();
string level = excel.Rows[j]["level"].ToString();
employee_no = excel.Rows[j]["employee_no"].ToString();
decimal? old_salary = Convert.ToDecimal(excel.Rows[j]["old_salary"]);
decimal? old_cost_living = Convert.ToDecimal(excel.Rows[j]["old_cost_living"]);
decimal? middle = Convert.ToDecimal(excel.Rows[j]["middle"]);
decimal? promoted_percentage = Convert.ToDecimal(excel.Rows[j]["promoted_percentage"]);
decimal? total_promote = Convert.ToDecimal(excel.Rows[j]["total_promote"]);
decimal? receive_quota = Convert.ToDecimal(excel.Rows[j]["receive_quota"]);
decimal? new_sarary_with_quota = Convert.ToDecimal(excel.Rows[j]["new_sarary_with_quota"]);
decimal? new_cost_living = Convert.ToDecimal(excel.Rows[j]["new_cost_living"]);
string remark = excel.Rows[j]["remark"].ToString();
var item = new eva_adjust_postponement_detailEntity();
item.id = newkey;
newkey += 1;
item.adjust_postponement_id = id;
item.adjust_postponement_quota_id = id;
var employee = (from qq in all_emp where qq.employee_no == employee_no select qq).FirstOrDefault();
if (employee == null)
{
return_text += " ไม่พบ " + employee_no;
}
else
{
item.employee_id = employee.id;
item.sarary = old_salary;
item.cost_living = old_cost_living;
item.middle = middle;
item.promoted_percentage = promoted_percentage;
item.total_promote = total_promote;
item.new_sarary = old_salary + total_promote;
item.new_cost_living = new_cost_living;
item.remark = remark;
item.receive_quota = receive_quota;
item.new_sarary_with_quota = new_sarary_with_quota;
item.position_this_time = position;
item.level_this_time = level;
_repository.Context.Add(item);
}
}
catch(Exception ex)
{
throw new Exception("มีความผิดพลาดในการแปลงข้อมูลของ "+ employee_no + " = "+ ex.Message);
}
}
return return_text;
}
private DataTable GetDataTableFromExcel(string path, bool hasHeader = true)
{
using (var pck = new OfficeOpenXml.ExcelPackage())
{
using (var stream = File.OpenRead(path))
{
pck.Load(stream);
}
var ws = pck.Workbook.Worksheets.First();
DataTable tbl = new DataTable();
foreach (var firstRowCell in ws.Cells[1, 1, 1, ws.Dimension.End.Column])
{
tbl.Columns.Add(hasHeader ? firstRowCell.Text : string.Format("Column {0}", firstRowCell.Start.Column));
}
var startRow = hasHeader ? 2 : 1;
for (int rowNum = startRow; rowNum <= ws.Dimension.End.Row; rowNum++)
{
var wsRow = ws.Cells[rowNum, 1, rowNum, ws.Dimension.End.Column];
DataRow row = tbl.Rows.Add();
foreach (var cell in wsRow)
{
row[cell.Start.Column - 1] = cell.Text;
}
}
return tbl;
}
}
public eva_adjust_postponement_migrationViewModel Update(int id, eva_adjust_postponement_migrationInputModel model)
{
var existingEntity = _repository.Get(id);
if (existingEntity != null)
{
existingEntity.fiscal_year = model.fiscal_year;
existingEntity.theDate = model.theDate;
existingEntity.theRound = model.theRound;
existingEntity.create_evaluation_id = model.create_evaluation_id;
existingEntity.limit = model.limit;
existingEntity.limit_frame = model.limit_frame;
existingEntity.limit_quota = model.limit_quota;
existingEntity.limit_frame_quota = model.limit_frame_quota;
existingEntity.percentage = model.percentage;
existingEntity.command_no = model.command_no;
existingEntity.managed_by = model.managed_by;
if (!string.IsNullOrEmpty(model.imported_file))
{
if (model.imported_file.StartsWith("Uploads"))
{
var imported_fileFileName = FileUtil.MoveTempUploadFileToActualPath(
model.imported_file, FilePathConstant.DirType.FilesTestUpload, existingEntity.id, existingEntity.imported_file);
existingEntity.imported_file = imported_fileFileName;
}
else
{
existingEntity.imported_file = model.imported_file;
}
}
else
{
existingEntity.imported_file = null;
}
var updated = _repository.Update(id, existingEntity);
return Get(updated.id);
}
else
throw new NotificationException("No data to update");
}
public string UpdateMultiple(List<eva_adjust_postponement_migrationInputModel> model)
{
foreach (var i in model)
{
if (i.active_mode == "1" && i.id.HasValue) // update
{
var existingEntity = _repository.Get(i.id.Value);
if (existingEntity != null)
{
existingEntity.fiscal_year = i.fiscal_year;
existingEntity.theDate = i.theDate;
existingEntity.theRound = i.theRound;
existingEntity.create_evaluation_id = i.create_evaluation_id;
existingEntity.limit = i.limit;
existingEntity.limit_frame = i.limit_frame;
existingEntity.limit_quota = i.limit_quota;
existingEntity.limit_frame_quota = i.limit_frame_quota;
existingEntity.percentage = i.percentage;
existingEntity.command_no = i.command_no;
existingEntity.managed_by = i.managed_by;
if (!string.IsNullOrEmpty(i.imported_file))
{
if (i.imported_file.StartsWith("Uploads"))
{
var imported_fileFileName = FileUtil.MoveTempUploadFileToActualPath(
i.imported_file, FilePathConstant.DirType.FilesTestUpload, existingEntity.id, existingEntity.imported_file);
existingEntity.imported_file = imported_fileFileName;
}
else
{
existingEntity.imported_file = i.imported_file;
}
}
else
{
existingEntity.imported_file = null;
}
//existingEntity.SetAutoField(_repository.Context);
_repository.UpdateWithoutCommit(i.id.Value, existingEntity);
}
}
else if (i.active_mode == "1" && !i.id.HasValue) // add
{
var entity = GetEntity(i);
entity.id = GetNewPrimaryKey();
//entity.SetAutoField(_repository.Context);
_repository.InsertWithoutCommit(entity);
}
else if (i.active_mode == "0" && i.id.HasValue) // remove
{
_repository.DeleteWithoutCommit(i.id.Value);
}
else if (i.active_mode == "0" && !i.id.HasValue)
{
// nothing to do
}
}
_repository.Context.SaveChanges();
return model.Count().ToString();
}
public eva_adjust_postponement_migrationViewModel SetAsActive(int id)
{
var updated = _repository.SetAsActive(id);
return Get(updated.id);
}
public eva_adjust_postponement_migrationViewModel SetAsInactive(int id)
{
var updated = _repository.SetAsInActive(id);
return Get(updated.id);
}
public void Delete(int id)
{
var postponement = (from i in _repository.Context.eva_adjust_postponement
where i.id == id
select i).FirstOrDefault();
if (postponement == null || !postponement.imported_date.HasValue)
{
throw new Exception("ไม่สามารถลบรายการได้ เพราะ ไม่ใช่รายการที่นำเข้าย้อนหลัง");
}
var items = (from i in _repository.Context.eva_adjust_postponement_detail
where i.adjust_postponement_id == id
|| i.adjust_postponement_quota_id == id
select i).ToList();
_repository.Context.RemoveRange(items);
_repository.Delete(id);
return;
}
public void RefreshAutoFieldOfAllData()
{
var all_items = from i in _repository.Context.eva_adjust_postponement
select i;
foreach (var item in all_items)
{
//item.SetAutoField(_repository.Context);
}
_repository.Context.SaveChanges();
}
private Dictionary<string, string> GetLookupForLog()
{
var i = new Dictionary<string, string>();
i.Add("fiscal_year", "ปีงบประมาณ ");
i.Add("theDate", "วันที่เลื่อน");
i.Add("txt_theDate", "วันที่เลื่อน");
i.Add("theRound", "ครั้งที่เลื่อน");
i.Add("create_evaluation_id", "กลุ่มการประเมิน");
i.Add("create_evaluation_id_eva_create_evaluation_performance_plan_id", "กลุ่มการประเมิน");
i.Add("limit", "บริหารวงเงิน");
i.Add("limit_frame", "กรอบวงเงินร้อยละ");
i.Add("limit_quota", "จำนวนเงินที่สามารถบริหารวงเงินหรือวงเงินโควต้าพิเศษ");
i.Add("limit_frame_quota", "กรอบโควต้าพิเศษร้อยละ");
i.Add("percentage", "ร้อยละที่ได้เลื่อน");
i.Add("command_no", "เลขที่คำสั่ง");
i.Add("managed_by", "ผู้จัดทำข้อมูล");
i.Add("managed_by_external_linkage_external_name", "ผู้จัดทำข้อมูล");
return i;
}
#endregion
#region Match Item
#endregion
#endregion
}
}

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_migrationViewModel : BaseViewModel2<int>
{
public int? fiscal_year { get; set; }
public DateTime? theDate { get; set; }
public string txt_theDate { get { return MyHelper.GetDateStringForReport(this.theDate); } }
public int? theRound { get; set; }
public int? create_evaluation_id { get; set; }
public decimal? limit { get; set; }
public decimal? limit_frame { get; set; }
public decimal? limit_quota { get; set; }
public decimal? limit_frame_quota { get; set; }
public decimal? percentage { get; set; }
public string command_no { get; set; }
public int? managed_by { get; set; }
public string imported_file { get; set; }
public string imported_fileDisplay { get; set; }
public string txt_imported_file
{
get
{
return (string.IsNullOrEmpty(imported_file) ? "" :
$"<a href='../{imported_fileDisplay}' target='_blank'>{imported_file}</a>");
}
}
public Guid? create_evaluation_id_eva_create_evaluation_performance_plan_id { get; set; }
public string managed_by_external_linkage_external_name { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TodoAPI2.Models
{
public class eva_adjust_postponement_migrationWithSelectionViewModel: eva_adjust_postponement_migrationViewModel
{
public List<eva_create_evaluationEntity> item_create_evaluation_id { get; set; }
public List<external_employeeViewModel> item_managed_by { get; set; }
}
}