Commit 8c4ccf3c authored by solho's avatar solho

新增關帳相關功能

parent 13e575a9
......@@ -45,54 +45,38 @@ namespace WebAPI.Controllers
using (SqlConnection Conn = new SqlConnection(connString))
{
;
SqlCommand cmd = new SqlCommand("", Conn)
SqlCommand cmd = new SqlCommand("", Conn);
String strsql = "";
strsql += @"
SELECT top 1 CONVERT(varchar(7),Settle_Date,126) Settle_Month from [esn_todos_Settle] a
left join [evw_qResult_EmpDS] b on a.DSNum=b.Emp_DSNum
left join [evw_qResult_Dept] c on a.DeptNum=c.targetID
left join [evw_qResult_EmpItem] d on a.ItemNum=d.Emp_ItemNum
where 1=1
";
JObject objPermission_furtherSql = JObject.Parse(obj_input["Permission_furtherSql"].ToString());
if (obj_input["Settle_Date"] != null)
{
CommandText = @"
SELECT top 1 isClosed, Settle_Date
FROM esn_todos_Settle a
inner join esn_todos_Settle_config b on a.DSNum=b.DSNum -- and a.DeptNum=b.DeptNum and a.ItemNum=b.ItemNum
where [settle_date] between @Settle_Date and @Settle_Date and b.is_enabled = 1;
SELECT top 1 DATEADD(month,1,[settle_date]) as settle_date_next
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
where isClosed=1
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)
strsql += " and Settle_Date between @Settle_Date and @Settle_Date ";
cmd.Parameters.Add("@Settle_Date", obj_input["Settle_Date"].ToString());
}
if (obj_input["isClosed"] != null)
{
DateTime dtemp = (DateTime)ds.Tables[0].Rows[0]["Settle_Date"] ;
jdata["Settle_Date"] = dtemp.ToString("yyyy-MM");
jdata["isClosed"] = ds.Tables[0].Rows[0]["isClosed"].ToString();
strsql += " and isClosed=@isClosed ";
cmd.Parameters.Add("@isClosed", (obj_input["isClosed"].ToString() == "1" ? true : false));
}
else
if (objPermission_furtherSql["firmID"] != null)
{
DateTime dtemp;
if (obj_input["Settle_Date"].ToString() != "")
{
dtemp = Convert.ToDateTime(obj_input["Settle_Date"].ToString());
}
else
{
dtemp = (DateTime)ds.Tables[1].Rows[0]["settle_date_next"];
}
jdata["Settle_Date"] = dtemp.ToString("yyyy-MM");
jdata["isClosed"] = "0";
strsql += " and b.ID in(@DSid)";
strsql = strsql.Replace("@DSid", objPermission_furtherSql["firmID"].ToString());
//cmd.Parameters.Add("@DSid", objPermission_furtherSql["firmID"].ToString());
}
//dt.Columns["settle_date_next"].ReadOnly = false;
strsql += " order by a.Settle_Date";
response.Code = "1";
response.Msg = "success";
string JSONString = string.Empty;
JSONString = JsonConvert.SerializeObject(jdata);
response.Msg = JSONString;
cmd.CommandText = strsql;
DataTable dt = SqlToDt(cmd);
response.Msg = JsonConvert.SerializeObject(dt);
result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json");
}
}
......@@ -111,6 +95,11 @@ namespace WebAPI.Controllers
return result;
}
/// <summary>
/// 取得結算資料狀態
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
[Route("getesntodosSettle")]
[CorsHandle]
[HttpPost]
......@@ -179,6 +168,13 @@ namespace WebAPI.Controllers
result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json");
return result;
}
/// <summary>
/// 更新結算資料狀態
///
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
[Route("updateesntodosSettle")]
[CorsHandle]
[HttpPost]
......@@ -193,18 +189,18 @@ namespace WebAPI.Controllers
using (SqlConnection Conn = new SqlConnection(connString))
{
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()
where id in(@ids) ");
cmd.Parameters.AddWithValue("@gUserID_wade", obj_input["gUserID_wade"].ToString());
cmd.Parameters.AddWithValue("@isClosed", obj_input["isClosed"].ToString()=="1"?true:false);
JArray idsar =JArray.Parse( obj_input["ids"].ToString());
if (idsar.Count>0)
{
string t= String.Join(",", obj_input["ids"]);
strsql=strsql.Replace("@ids", t);
cmd.Parameters.AddWithValue("@isClosed", obj_input["isClosed"].ToString() == "1" ? true : false);
JArray idsar = JArray.Parse(obj_input["ids"].ToString());
if (idsar.Count > 0)
{
string t = String.Join(",", obj_input["ids"]);
strsql = strsql.Replace("@ids", t);
}
cmd.CommandText = strsql;
DataTable dt = SqlToDt(cmd);
response.Msg = "設定完成";
......@@ -224,6 +220,78 @@ namespace WebAPI.Controllers
}
result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json");
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)
......
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