ปรับปรุงให้รองรับ การไปช่วยปฏิบัติงาน

This commit is contained in:
Nakorn Rientrakrunchai
2021-03-11 08:03:52 +07:00
parent b5e24a048d
commit 1540543f1f
17 changed files with 1066 additions and 446 deletions

View File

@@ -35,8 +35,8 @@ namespace TodoAPI2.Models
[MaxLength(4000)]
public string remark { get; set; }
public void SetAutoField(DataContext context)
public int? main_dept_id { get; set; }
public void SetAutoField(DataContext context)
{
}

View File

@@ -31,5 +31,12 @@ namespace TodoAPI2.Models
public DateTime? frame_plan_guid_eva_limit_frame_plan_executed_date { get; set; }
public string group_guid_eva_evaluation_group_code { get; set; }
public string remark_formatted {
get
{
if (remark == null) remark = "";
return remark.Replace("\n", "<br/>");
}
}
}
}

View File

@@ -22,6 +22,7 @@ namespace TodoAPI2.Models
List<external_menu> GetMenuByUser(int? userid);
List<external_user> GetAllUser();
List<dept_mappingViewModel> GetDeptMapping();
List<working_records> GetWorkingRecord();
}
}

View File

@@ -643,6 +643,41 @@ else orgdata.department_code::int*100000 end
}
return result;
}
public List<working_records> GetWorkingRecord()
{
var sql = string.Format(@"
select * FROM hrm_working_records where deleted_at is null
", '"'.ToString());
var para = db.GetParameterListNpgsql();
DataTable dt = db.ExecuteDataTableNpgsql(sql, para);
var result = new List<working_records>();
foreach (DataRow dr in dt.Rows)
{
var i = new working_records();
if (dr["id"] != DBNull.Value) i.id = Convert.ToInt32(dr["id"]);
if (dr["employee_id"] != DBNull.Value) i.employee_id = Convert.ToInt32(dr["employee_id"]);
if (dr["place"] != DBNull.Value) i.place = Convert.ToInt32(dr["place"]);
if (dr["start_date"] != DBNull.Value) i.start_date = Convert.ToDateTime(dr["start_date"]);
if (dr["end_date"] != DBNull.Value) i.end_date = Convert.ToDateTime(dr["end_date"]);
if (dr["subject"] != DBNull.Value) i.subject = dr["subject"].ToString();
if (dr["detail"] != DBNull.Value) i.detail = dr["detail"].ToString();
result.Add(i);
}
return result;
}
}
public class working_records
{
public int? id { get; set; }
public int? employee_id { get; set; }
public int? place { get; set; }
public DateTime? start_date { get; set; }
public DateTime? end_date { get; set; }
public string subject { get; set; }
public string detail { get; set; }
}
public class external_menu

View File

@@ -150,6 +150,16 @@ namespace TodoAPI2.Models
entity.id = Guid.NewGuid();
entity.limit_frame_005 = (decimal?)0.05;
var all_all_emp = emp.GetAllEmployee();
var mapping_dept = emp.GetDeptMapping();
var working_record = from i in emp.GetWorkingRecord() where
model.executed_date.HasValue
&& i.start_date <= model.executed_date
&& i.end_date >= model.executed_date
select i;
var result_frame_group = new List<eva_limit_frame_groupEntity>();
var result_frame_employee = new List<eva_limit_frame_employeeEntity>();
var all_group = (from i in _repository.Context.eva_evaluation_group
select i);
foreach (var x in all_group)
@@ -172,7 +182,9 @@ namespace TodoAPI2.Models
new_frame_group.total_salary = all_emp.Sum(z => z.salary);
new_frame_group.total_salary_limit = (new_frame_group.total_salary * new_frame_group.limit_frame_295 / 100);
new_frame_group.total_salary_limit_rounded = MyHelper.RoundOff(new_frame_group.total_salary_limit.Value, 10);
_repository.Context.Add(new_frame_group);
new_frame_group.main_dept_id = x.main_dept_id;
//_repository.Context.Add(new_frame_group);
result_frame_group.Add(new_frame_group);
int i = 1;
foreach (var y in all_emp)
@@ -190,10 +202,60 @@ namespace TodoAPI2.Models
new_emp.cost_of_living = y.cost_of_living;
new_emp.order_of_data = i;
i++;
_repository.Context.Add(new_emp);
//_repository.Context.Add(new_emp);
result_frame_employee.Add(new_emp);
}
}
var help_other_org = from i in result_frame_employee
where
(from j in working_record select j.employee_id).Contains(i.employee_id)
select i;
foreach(var em in help_other_org)
{
var w = (from i in working_record where i.employee_id == em.employee_id select i).FirstOrDefault();
if(w != null)
{
int? main_dept = (from i in mapping_dept where i.id == w.place select i.id2.HasValue?i.id2:i.id).FirstOrDefault();
var s = (from i in result_frame_group where i.main_dept_id == main_dept select i).FirstOrDefault();
if(s != null)
{
em.help_org_id = main_dept;
em.frame_group_guid = s.id;
em.order_of_data += 1000;
}
}
}
foreach(var x in result_frame_group)
{
x.remark = "";
int i = 1;
int j = 1;
foreach(var y in from z in result_frame_employee where z.frame_group_guid==x.id orderby z.order_of_data select z)
{
y.order_of_data = i;
i++;
if (y.help_org_id.HasValue)
{
var theemp = (from q in all_all_emp where q.id == y.employee_id select q).FirstOrDefault();
var thedetail = (from r in working_record where r.employee_id == y.employee_id select r).FirstOrDefault();
var help_at = (from s in mapping_dept where s.id == thedetail.place select s).FirstOrDefault();
if(theemp != null && thedetail != null && help_at != null)
{
if (x.remark != "") x.remark += "\n";
x.remark += $"{j}.ในลำดับที่ {y.order_of_data} {theemp.fullname} ตำแหน่ง{theemp.position_name} {theemp.department_name} \nมาช่วยปฏิบัติงานที่{help_at.department_name} ตั้งแต่วันที่ {MyHelper.GetDateStringForReport(thedetail.start_date)} - {MyHelper.GetDateStringForReport(thedetail.end_date)} \nตาม{thedetail.subject}";
}
j++;
}
}
}
_repository.Context.AddRange(result_frame_group);
_repository.Context.AddRange(result_frame_employee);
entity.SetAutoField(_repository.Context);
if (is_force_save)