Commit 8c4ccf3c authored by solho's avatar solho

新增關帳相關功能

parent 13e575a9
...@@ -45,54 +45,38 @@ namespace WebAPI.Controllers ...@@ -45,54 +45,38 @@ namespace WebAPI.Controllers
using (SqlConnection Conn = new SqlConnection(connString)) using (SqlConnection Conn = new SqlConnection(connString))
{ {
; ;
SqlCommand cmd = new SqlCommand("", Conn) SqlCommand cmd = new SqlCommand("", Conn);
{ String strsql = "";
CommandText = @" strsql += @"
SELECT top 1 isClosed, Settle_Date SELECT top 1 CONVERT(varchar(7),Settle_Date,126) Settle_Month from [esn_todos_Settle] a
FROM esn_todos_Settle a left join [evw_qResult_EmpDS] b on a.DSNum=b.Emp_DSNum
inner join esn_todos_Settle_config b on a.DSNum=b.DSNum -- and a.DeptNum=b.DeptNum and a.ItemNum=b.ItemNum left join [evw_qResult_Dept] c on a.DeptNum=c.targetID
where [settle_date] between @Settle_Date and @Settle_Date and b.is_enabled = 1; left join [evw_qResult_EmpItem] d on a.ItemNum=d.Emp_ItemNum
SELECT top 1 DATEADD(month,1,[settle_date]) as settle_date_next where 1=1
FROM esn_todos_Settle a ";
inner join esn_todos_Settle_config b on a.DeptNum=b.DeptNum and a.DSNum=b.DSNum and a.ItemNum=b.ItemNum JObject objPermission_furtherSql = JObject.Parse(obj_input["Permission_furtherSql"].ToString());
where isClosed=1 if (obj_input["Settle_Date"] != null)
order by [settle_date] desc;
"
};
string Settle_Date = obj_input["Settle_Date"].ToString() == "" ? "" : obj_input["Settle_Date"].ToString() + "-01";
cmd.Parameters.AddWithValue("@Settle_Date", Settle_Date);
cmd.Parameters.AddWithValue("@user_id", obj_input["gWadeID"].ToString());
DataSet ds = SqlToDs(cmd);
JObject jdata = new JObject();
if (ds.Tables[0].Rows.Count > 0)
{ {
DateTime dtemp = (DateTime)ds.Tables[0].Rows[0]["Settle_Date"] ; strsql += " and Settle_Date between @Settle_Date and @Settle_Date ";
jdata["Settle_Date"] = dtemp.ToString("yyyy-MM"); cmd.Parameters.Add("@Settle_Date", obj_input["Settle_Date"].ToString());
jdata["isClosed"] = ds.Tables[0].Rows[0]["isClosed"].ToString();
} }
else if (obj_input["isClosed"] != null)
{ {
DateTime dtemp; strsql += " and isClosed=@isClosed ";
if (obj_input["Settle_Date"].ToString() != "") cmd.Parameters.Add("@isClosed", (obj_input["isClosed"].ToString() == "1" ? true : false));
{
dtemp = Convert.ToDateTime(obj_input["Settle_Date"].ToString());
} }
else if (objPermission_furtherSql["firmID"] != null)
{ {
dtemp = (DateTime)ds.Tables[1].Rows[0]["settle_date_next"]; strsql += " and b.ID in(@DSid)";
} strsql = strsql.Replace("@DSid", objPermission_furtherSql["firmID"].ToString());
jdata["Settle_Date"] = dtemp.ToString("yyyy-MM"); //cmd.Parameters.Add("@DSid", objPermission_furtherSql["firmID"].ToString());
jdata["isClosed"] = "0";
} }
//dt.Columns["settle_date_next"].ReadOnly = false; strsql += " order by a.Settle_Date";
response.Code = "1"; response.Code = "1";
response.Msg = "success"; cmd.CommandText = strsql;
string JSONString = string.Empty; DataTable dt = SqlToDt(cmd);
JSONString = JsonConvert.SerializeObject(jdata); response.Msg = JsonConvert.SerializeObject(dt);
response.Msg = JSONString;
result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json"); result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json");
} }
} }
...@@ -111,6 +95,11 @@ namespace WebAPI.Controllers ...@@ -111,6 +95,11 @@ namespace WebAPI.Controllers
return result; return result;
} }
/// <summary>
/// 取得結算資料狀態
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
[Route("getesntodosSettle")] [Route("getesntodosSettle")]
[CorsHandle] [CorsHandle]
[HttpPost] [HttpPost]
...@@ -179,6 +168,13 @@ namespace WebAPI.Controllers ...@@ -179,6 +168,13 @@ namespace WebAPI.Controllers
result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json"); result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json");
return result; return result;
} }
/// <summary>
/// 更新結算資料狀態
///
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
[Route("updateesntodosSettle")] [Route("updateesntodosSettle")]
[CorsHandle] [CorsHandle]
[HttpPost] [HttpPost]
...@@ -193,16 +189,16 @@ namespace WebAPI.Controllers ...@@ -193,16 +189,16 @@ namespace WebAPI.Controllers
using (SqlConnection Conn = new SqlConnection(connString)) using (SqlConnection Conn = new SqlConnection(connString))
{ {
SqlCommand cmd = new SqlCommand("", Conn); SqlCommand cmd = new SqlCommand("", Conn);
String strsql = "" ; String strsql = "";
strsql += String.Format(@"update [esn_todos_Settle] set isClosed=@isClosed , update_user_id=@gUserID_wade ,update_time=GETDATE() strsql += String.Format(@"update [esn_todos_Settle] set isClosed=@isClosed , update_user_id=@gUserID_wade ,update_time=GETDATE()
where id in(@ids) "); where id in(@ids) ");
cmd.Parameters.AddWithValue("@gUserID_wade", obj_input["gUserID_wade"].ToString()); cmd.Parameters.AddWithValue("@gUserID_wade", obj_input["gUserID_wade"].ToString());
cmd.Parameters.AddWithValue("@isClosed", obj_input["isClosed"].ToString()=="1"?true:false); cmd.Parameters.AddWithValue("@isClosed", obj_input["isClosed"].ToString() == "1" ? true : false);
JArray idsar =JArray.Parse( obj_input["ids"].ToString()); JArray idsar = JArray.Parse(obj_input["ids"].ToString());
if (idsar.Count>0) if (idsar.Count > 0)
{ {
string t= String.Join(",", obj_input["ids"]); string t = String.Join(",", obj_input["ids"]);
strsql=strsql.Replace("@ids", t); strsql = strsql.Replace("@ids", t);
} }
cmd.CommandText = strsql; cmd.CommandText = strsql;
...@@ -224,6 +220,78 @@ namespace WebAPI.Controllers ...@@ -224,6 +220,78 @@ namespace WebAPI.Controllers
} }
result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json"); result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json");
return result; return result;
}
/// <summary>
/// 關閉結算資料狀態
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
[Route("closeesntodosSettle")]
[CorsHandle]
[HttpPost]
public HttpResponseMessage close_esn_todos_Settle(ParamModel param)
{
if (param != null && param.Input != null && !string.IsNullOrWhiteSpace((param.Input.ToString())))
{
string input = param.Input.ToString();
JObject obj_input = JObject.Parse(input.ToString());
try
{
using (SqlConnection Conn = new SqlConnection(connString))
{
SqlCommand cmd = new SqlCommand("", Conn);
String strsql = "";
String @idswherecase = "";
strsql += String.Format(@"update [esn_todos_Settle] SET isClosed = 1, update_time = getdate(), update_user_id =@gUserID_wade
from (select b.id as etsid,a.id as targetid, DSNum,DeptNum, ItemNum, Settle_Date from evw_qResult_EmpDS a inner join [esn_todos_Settle] b on a.Emp_DSNum=b.DSNum
and Settle_Date between @Settle_Date and @Settle_Date ) a
where a.etsid=id @idswherecase ;
select @@ROWCOUNT;
MERGE INTO esn_todos_Settle WITH(HOLDLOCK) as target
USING( select Emp_DSNum,DeptNum, ItemNum, Settle_Date from (select a.id as targetid,Emp_DSNum,DeptNum, ItemNum, Settle_Date from evw_qResult_EmpDS a left join [esn_todos_Settle] b on a.Emp_DSNum=b.DSNum
and Settle_Date between @Settle_DateNext and @Settle_DateNext) L1
where 1=1 @idswherecase ) as source(DSNum, DeptNum, ItemNum, Settle_Date)
on(target.DSNum = source.DSNum and target.Settle_Date = source.Settle_Date)
-- WHEN MATCHED THEN UPDATE SET isClosed = 1, update_time = getdate(), update_user_id = @gUserID_wade
WHEN NOT MATCHED THEN INSERT(Settle_Date,DSNum,DeptNum,ItemNum,isClosed, update_user_id, update_time, Create_user_id, Create_time)
VALUES(@Settle_DateNext,source.DSNum,'' ,'',0,@gUserID_wade,getdate(),@gUserID_wade,getdate())
OUTPUT $action; ");
JObject objPermission_furtherSql = JObject.Parse(obj_input["Permission_furtherSql"].ToString());
DateTime Settle_Date = Convert.ToDateTime(obj_input["Settle_Date"].ToString());
cmd.Parameters.Add("@Settle_Date", Settle_Date);
cmd.Parameters.Add("@Settle_DateNext", Settle_Date.AddMonths(1));
cmd.Parameters.Add("@isClosed", (obj_input["isClosed"].ToString() == "1" ? true : false));
if (objPermission_furtherSql["firmID"] != null && !string.IsNullOrWhiteSpace(objPermission_furtherSql["firmID"].ToString()))
{
@idswherecase= " and targetid in(" + objPermission_furtherSql["firmID"].ToString() + ")";
}
strsql = strsql.Replace("@idswherecase", @idswherecase);
cmd.Parameters.AddWithValue("@gUserID_wade", obj_input["gUserID_wade"].ToString());
cmd.CommandText = strsql;
DataTable dt = SqlToDt(cmd);
response.Msg = "關帳完成";
response.Code = "1";
}
}
catch (Exception e)
{
response.Code = "0";
response.Msg = "Exception:" + e.StackTrace;
}
}
else
{
response.Code = "0";
response.Msg = "no input or format error";
}
result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json");
return result;
} }
public DataTable get_esn_todos_Settle_config( String gWadeID, bool is_enabled) public DataTable get_esn_todos_Settle_config( String gWadeID, bool is_enabled)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment