|
|
@ -1919,396 +1919,6 @@ namespace CK.SCP.Controller |
|
|
|
// return _ret;
|
|
|
|
//}
|
|
|
|
|
|
|
|
public static ResultObject<bool> PLAN_TO_ASK1(List<V_TB_PO_PLAN> p_order_list, User p_user) |
|
|
|
{ |
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>(); |
|
|
|
try |
|
|
|
{ |
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance()) |
|
|
|
{ |
|
|
|
List<string> lineError = new List<string>(); |
|
|
|
List<string> ErrorList = new List<string>(); |
|
|
|
var _lst = p_order_list.Where(p => p.PlanQty != 0).ToList(); |
|
|
|
|
|
|
|
if (lineError.Count > 0) |
|
|
|
{ |
|
|
|
_ret.State = ReturnStatus.Failed; |
|
|
|
_ret.MessageList.AddRange(ErrorList); |
|
|
|
_ret.Result = false; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var VenderList = _lst.Select(p => p.VendId).Distinct(); |
|
|
|
var PartCodeList = _lst.Select(p => p.PartCode).Distinct(); |
|
|
|
var OrderList = _lst.GroupBy(p => p.PoBillNum).ToList(); |
|
|
|
OrderList.ForEach((p) => |
|
|
|
{ |
|
|
|
var list = p.ToList(); |
|
|
|
if (list.Count > 0) |
|
|
|
{ |
|
|
|
var _entity = list.FirstOrDefault(); |
|
|
|
TB_ASK _ask = new TB_ASK(); |
|
|
|
_ask.AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCode(); |
|
|
|
_ask.VendId = _entity.VendId; |
|
|
|
_ask.State = (int)AskState.New; |
|
|
|
_ask.PoBillNum = _entity.PoBillNum; |
|
|
|
_ask.ModType = (int)BillModType.Contract; |
|
|
|
_ask.Site = _entity.Site; |
|
|
|
_ask.Remark = _entity.Version; |
|
|
|
_ask.State = (int)AskState.New; |
|
|
|
DateTime date = DateTime.Now; |
|
|
|
string str = date.Year.ToString(); |
|
|
|
string str1 = date.Month.ToString(); |
|
|
|
string datetime = str + "-" + str1; |
|
|
|
_ask.UpdateTime = DateTime.Parse(datetime); |
|
|
|
_ask.Buyer = p_user.ChineseName; |
|
|
|
_ask.BuyerPhone = p_user.CellPhone; |
|
|
|
_ask.ErpBillNum = _entity.PoBillNum; |
|
|
|
_ask.BeginTime = DateTime.Parse( _entity.BeginTime.ToString()); |
|
|
|
_ask.EndTime = _entity.EndTime; |
|
|
|
_ask.CreateTime = DateTime.Now.Date; |
|
|
|
_ask.CreateUser = p_user.Name; |
|
|
|
_ask.VendId = _entity.VendId; |
|
|
|
_ask.GUID = Guid.NewGuid(); |
|
|
|
_ask.ReceivedPort = string.Empty; |
|
|
|
_ask.IsDeleted = false; |
|
|
|
_ask.SubSite = p_user.UserdSite; |
|
|
|
db.TB_ASK.Add(_ask); |
|
|
|
#region 供应商新任务代办接口
|
|
|
|
TB_PENING_ITEMS _item = new TB_PENING_ITEMS(); |
|
|
|
_item.ROLE_NAME = "供应商"; |
|
|
|
_item.ITEM_NO = _ask.AskBillNum; |
|
|
|
_item.ITEM_CONTENT = "要货看盘有信息"; |
|
|
|
_item.ITEM_TYPE = (int)PENDING_MESSAGE_TYPE.NEW_ASK; |
|
|
|
_item.VEND_ID = _ask.VendId; |
|
|
|
_item.ITEM_STATE = (int)PENDING_STATE.WAITING; |
|
|
|
_item.SENDER = p_user.ChineseName; |
|
|
|
_item.SENDING_TIME = DateTime.Now; |
|
|
|
db.TB_PENING_ITEMS.Add(_item); |
|
|
|
#endregion
|
|
|
|
// int _number = 1;
|
|
|
|
List<TB_ASK_DETAIL> _ls = new List<TB_ASK_DETAIL>(); |
|
|
|
list.ForEach((itm) => |
|
|
|
{ |
|
|
|
var _number = _ls.Count(p1 => p1.PoBillNum == _ask.PoBillNum |
|
|
|
&& p1.PoLine == itm.PoLine && p1.PartCode == itm.PartCode); |
|
|
|
if (_number > 0) |
|
|
|
{ |
|
|
|
_ret.MessageList.Add(string.Format("已经存在订单为{0}行号为{1}零件编码为{2}", itm.PoBillNum, itm.PoLine.ToString(), itm.PartCode)); |
|
|
|
} |
|
|
|
TB_ASK_DETAIL _t_ASK_Detail = new TB_ASK_DETAIL(); |
|
|
|
//_t_ASK_Detail.PoLine = _number;
|
|
|
|
_t_ASK_Detail.PoLine = itm.PoLine; |
|
|
|
_t_ASK_Detail.Currency = "CNY"; |
|
|
|
_t_ASK_Detail.AskBillNum = _ask.AskBillNum; |
|
|
|
_t_ASK_Detail.PoBillNum = _ask.PoBillNum; |
|
|
|
_t_ASK_Detail.PoUnit = itm.PoUnit; |
|
|
|
_t_ASK_Detail.CreateTime = DateTime.Now; |
|
|
|
_t_ASK_Detail.CreateUser = _ask.CreateUser; |
|
|
|
_t_ASK_Detail.PartCode = itm.PartCode; |
|
|
|
_t_ASK_Detail.BeginTime = _ask.BeginTime; |
|
|
|
_t_ASK_Detail.EndTime = itm.EndTime; |
|
|
|
_t_ASK_Detail.TempQty = itm.PlanQty; |
|
|
|
_t_ASK_Detail.AskQty = itm.PlanQty; |
|
|
|
_t_ASK_Detail.IsDeleted = false; |
|
|
|
_t_ASK_Detail.LocUnit = itm.PoUnit; |
|
|
|
_t_ASK_Detail.UnConv = 1; |
|
|
|
_t_ASK_Detail.Remark = itm.Version; |
|
|
|
_t_ASK_Detail.State = _ask.State; |
|
|
|
_t_ASK_Detail.SubSite = p_user.UserdSite; |
|
|
|
// _t_ASK_Detail.Price = string.IsNullOrEmpty(itm.) ? 0 : decimal.Parse(itm.价格);
|
|
|
|
_t_ASK_Detail.GUID = Guid.NewGuid(); |
|
|
|
_t_ASK_Detail.Remark = _ask.Site; |
|
|
|
db.TB_ASK_DETAIL.Add(_t_ASK_Detail); |
|
|
|
_ls.Add(_t_ASK_Detail); |
|
|
|
// _number++;
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_ret.MessageList.Add("ERP订单编号已存在,请重新导入!"); |
|
|
|
|
|
|
|
} |
|
|
|
if (_ret.MessageList.Count == 0) |
|
|
|
{ |
|
|
|
int state = db.SaveChanges(); |
|
|
|
if (state != -1) |
|
|
|
{ |
|
|
|
_ret.State = ReturnStatus.Succeed; |
|
|
|
_ret.Result = true; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_ret.State = ReturnStatus.Failed; |
|
|
|
_ret.Result = false; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_ret.State = ReturnStatus.Failed; |
|
|
|
_ret.Result = false; |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常
|
|
|
|
{ |
|
|
|
var sb = new StringBuilder(); |
|
|
|
foreach (var error in dbEx.EntityValidationErrors.ToList()) |
|
|
|
{ |
|
|
|
error.ValidationErrors.ToList().ForEach(i => |
|
|
|
{ |
|
|
|
sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage); |
|
|
|
}); |
|
|
|
} |
|
|
|
_ret.State = ReturnStatus.Failed; |
|
|
|
_ret.Result = false; |
|
|
|
_ret.ErrorList.Add(dbEx); |
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", sb.ToString()); |
|
|
|
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString()); |
|
|
|
} |
|
|
|
catch (OptimisticConcurrencyException ex)//并发冲突异常
|
|
|
|
{ |
|
|
|
|
|
|
|
_ret.State = ReturnStatus.Failed; |
|
|
|
_ret.Result = false; |
|
|
|
_ret.ErrorList.Add(ex); |
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", ex.ToString()); |
|
|
|
throw new ScpException(ResultCode.Exception, "9999", ex.ToString()); |
|
|
|
} |
|
|
|
catch (ScpException ex) |
|
|
|
{ |
|
|
|
_ret.State = ReturnStatus.Failed; |
|
|
|
_ret.Result = false; |
|
|
|
_ret.ErrorList.Add(ex); |
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", ex.ToString()); |
|
|
|
|
|
|
|
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException)) |
|
|
|
{ |
|
|
|
var inner = (UpdateException)ex.InnerException; |
|
|
|
|
|
|
|
|
|
|
|
throw new ScpException(ResultCode.Exception, "0000", ex.ToString()); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (ex.InnerException != null) throw ex.InnerException; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
_ret.State = ReturnStatus.Failed; |
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", e.Message); |
|
|
|
_ret.Result = false; |
|
|
|
_ret.ErrorList.Add(e); |
|
|
|
throw e; |
|
|
|
} |
|
|
|
return _ret; |
|
|
|
|
|
|
|
} |
|
|
|
public static DataTable Get_TB_PLAN_REPORT(V_TB_PO_PLAN p_plan) |
|
|
|
{ |
|
|
|
DataTable dt = new DataTable(); |
|
|
|
DataTable dt1 = new DataTable(); |
|
|
|
DataTable dt2 = new DataTable(); |
|
|
|
DataTable dt3 = new DataTable(); |
|
|
|
string _sqlString = "SELECT * FROM ( SELECT partcode,endtime,planqty,partdesc,pounit,domain,pobillnum,poline FROM V_TB_PO_PLAN where {0}\n " + |
|
|
|
") A\n" + |
|
|
|
" pivot ( sum(planQty) for a.endtime in (\n" + |
|
|
|
" {1}\n" + |
|
|
|
")\n" + |
|
|
|
") as ourpivot "; |
|
|
|
|
|
|
|
string _sql = "SELECT DISTINCT(ENDTIME) FROM V_TB_PO_PLAN where {0} ORDER BY ENDTIME"; |
|
|
|
|
|
|
|
string _askBillSql = "SELECT * FROM V_TB_ASK_DETAIL where VENDID = '{0}' AND EndTime IN ({1}) AND AskBillNum like 'E%' "; |
|
|
|
|
|
|
|
string _asn_recive = "SELECT A.PartCode, A.PoBillNum, A.PoLine, SUM(A.Qty) AS AsnQty, SUM(ISNULL(B.Qty, 0)) AS ReciveQty,\n" + |
|
|
|
" SUM(ISNULL(C.AskQty, 0)) AS AskQty\n" + |
|
|
|
"FROM V_TB_ASN_DETAIL AS A LEFT OUTER JOIN\n" + |
|
|
|
" V_TB_RECEIVE_DETAIL AS B ON A.AsnBillNum = B.AsnBillNum AND A.PartCode = B.PartCode AND\n" + |
|
|
|
" A.PoBillNum = B.PoBillNum AND A.PoLine = B.PoLine INNER JOIN\n" + |
|
|
|
" TB_ASK_DETAIL AS C ON A.AskBillNum = C.AskBillNum AND A.PartCode = C.PartCode AND\n" + |
|
|
|
" A.PoBillNum = C.PoBillNum AND A.PoLine = C.PoLine\n" + |
|
|
|
"WHERE (A.AskBillNum LIKE 'E%') AND (A.State > 0) and {0}\n" + |
|
|
|
"GROUP BY A.PartCode, A.PoBillNum, A.PoLine"; |
|
|
|
var dbSetting = GlobalConfig.ScpDatabase; |
|
|
|
try |
|
|
|
{ |
|
|
|
var strConn = EntitiesFactory.GetEfConnectionString(dbSetting); |
|
|
|
SqlConnection conn = new System.Data.SqlClient.SqlConnection(); |
|
|
|
conn.ConnectionString = strConn; |
|
|
|
if (conn.State != ConnectionState.Open) |
|
|
|
{ |
|
|
|
conn.Open(); |
|
|
|
} |
|
|
|
#region 结束时间范围
|
|
|
|
SqlCommand cmd = new SqlCommand(); |
|
|
|
cmd.Connection = conn; |
|
|
|
string where1 = " 1=1 "; |
|
|
|
if (!string.IsNullOrEmpty(p_plan.PartCode)) |
|
|
|
{ |
|
|
|
where1 += string.Format(" and partcode='{0}' ", p_plan.PartCode); |
|
|
|
} |
|
|
|
if (!string.IsNullOrEmpty(p_plan.VendId)) |
|
|
|
{ |
|
|
|
where1 += string.Format(" and VendId='{0}' ", p_plan.VendId); |
|
|
|
} |
|
|
|
if (!string.IsNullOrEmpty(p_plan.PoBillNum)) |
|
|
|
{ |
|
|
|
where1 += string.Format(" and PoBillNum='{0}' ", p_plan.PoBillNum); |
|
|
|
} |
|
|
|
if (p_plan.EndTime_Begin != null) |
|
|
|
{ |
|
|
|
where1 += string.Format(" and EndTime>='{0}'", p_plan.EndTime_Begin.Value.ToString("yyyy-MM-dd")); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
where1 += string.Format(" and EndTime>='{0}'", DateTime.Now.ToString("yyyy-MM-dd")); |
|
|
|
} |
|
|
|
if (p_plan.EndTime_End != null) |
|
|
|
{ |
|
|
|
where1 += string.Format(" and EndTime<='{0}'", p_plan.EndTime_End.Value.ToString("yyyy-MM-dd")); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
where1 += string.Format(" and EndTime<='{0}'", DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd")); |
|
|
|
} |
|
|
|
cmd.CommandText = string.Format(_sql, where1); |
|
|
|
SqlDataAdapter adapter = new SqlDataAdapter(cmd); |
|
|
|
adapter.Fill(dt); |
|
|
|
|
|
|
|
#endregion
|
|
|
|
List<string> _ls = new List<string>(); |
|
|
|
List<string> _ls1 = new List<string>(); |
|
|
|
foreach (DataRow row in dt.Rows) |
|
|
|
{ |
|
|
|
_ls.Add(string.Format("[{0}]", row["EndTime"].ToString())); |
|
|
|
_ls1.Add(string.Format("'{0}'", row["EndTime"].ToString())); |
|
|
|
} |
|
|
|
if (_ls.Count > 0) |
|
|
|
{ |
|
|
|
#region 计划行转列
|
|
|
|
SqlCommand cmd1 = new SqlCommand(); |
|
|
|
cmd1.Connection = conn; |
|
|
|
string where = "1=1 "; |
|
|
|
if (!string.IsNullOrEmpty(p_plan.PartCode)) |
|
|
|
{ |
|
|
|
where += string.Format(" and partcode='{0}' ", p_plan.PartCode); |
|
|
|
} |
|
|
|
where += string.Format(" and VendId='{0}' ", p_plan.VendId); |
|
|
|
if (!string.IsNullOrEmpty(p_plan.PoBillNum)) |
|
|
|
{ |
|
|
|
where += string.Format(" and PoBillNum='{0}' ", p_plan.PoBillNum); |
|
|
|
} |
|
|
|
cmd1.CommandText = string.Format(_sqlString, where, string.Join(",", _ls.ToArray())); |
|
|
|
var adapter1 = new SqlDataAdapter(cmd1); |
|
|
|
adapter1.Fill(dt1); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 此范围内的看板号
|
|
|
|
SqlCommand cmd2 = new SqlCommand(); |
|
|
|
cmd2.Connection = conn; |
|
|
|
cmd2.CommandText = string.Format(_askBillSql, p_plan.VendId, string.Join(",", _ls1.ToArray())); |
|
|
|
SqlDataAdapter adapter2 = new SqlDataAdapter(cmd2); |
|
|
|
adapter2.Fill(dt2); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
List<string> _askList = new List<string>(); |
|
|
|
foreach (DataRow row in dt2.Rows) |
|
|
|
{ |
|
|
|
_askList.Add(string.Format("'{0}'", row["AskBillNum"].ToString())); |
|
|
|
} |
|
|
|
if (_askList.Count > 0) |
|
|
|
{ |
|
|
|
SqlCommand cmd3 = new SqlCommand(); |
|
|
|
cmd3.Connection = conn; |
|
|
|
cmd3.CommandText = string.Format(_asn_recive, string.Format(" A.askBillNum in ({0}) ", string.Join(",", _askList.ToArray()))); |
|
|
|
SqlDataAdapter adapter3 = new SqlDataAdapter(cmd3); |
|
|
|
adapter3.Fill(dt3); |
|
|
|
} |
|
|
|
var column0 = dt1.Columns.Add("要货数量"); |
|
|
|
var column1 = dt1.Columns.Add("收货数量"); |
|
|
|
var column2 = dt1.Columns.Add("发货数量"); |
|
|
|
var column3 = dt1.Columns.Add("未发数量"); |
|
|
|
var column4 = dt1.Columns.Add("未收数量"); |
|
|
|
foreach (DataRow dr in dt1.Rows) |
|
|
|
{ |
|
|
|
foreach (DataRow row in dt3.Rows) |
|
|
|
{ |
|
|
|
if ( |
|
|
|
dr["PartCode"].ToString() == row["PartCode"].ToString() |
|
|
|
&& dr["PoBillNum"].ToString() == row["PoBillNum"].ToString() |
|
|
|
&& dr["PoLine"].ToString() == row["PoLine"].ToString()) |
|
|
|
{ |
|
|
|
dr["要货数量"] = row["ReciveQty"].ToString(); |
|
|
|
dr["收货数量"] = row["ReciveQty"].ToString(); |
|
|
|
dr["发货数量"] = row["AsnQty"].ToString(); |
|
|
|
dr["未收数量"] = decimal.Parse(row["AsnQty"].ToString()) - decimal.Parse(row["ReciveQty"].ToString()); |
|
|
|
dr["未发数量"] = decimal.Parse(row["AskQty"].ToString()) - decimal.Parse(row["AsnQty"].ToString()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
foreach (DataColumn column in dt1.Columns) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
var _dt1 = DateTime.Parse(column.ColumnName); |
|
|
|
var _curDate = _dt1.ToString("yyyy-MM-dd"); |
|
|
|
column.ColumnName = _curDate + "(预测)";//要货预测头
|
|
|
|
|
|
|
|
foreach (DataRow row in dt2.Rows) |
|
|
|
{ |
|
|
|
var _cur = DateTime.Parse(row["EndTime"].ToString()).ToString("yyyy-MM-dd");//看板时间
|
|
|
|
StringBuilder _buf = new StringBuilder(); |
|
|
|
if (_curDate == _cur) |
|
|
|
{ |
|
|
|
var _ask = row["AskBillNum"].ToString(); |
|
|
|
column.ColumnName = _cur + "(" + _ask + ")"; |
|
|
|
switch (int.Parse(row["state"].ToString())) |
|
|
|
{ |
|
|
|
case (int)AskState.New: |
|
|
|
column.ColumnName = _cur + "(" + _ask + ")" + "(计划)"; |
|
|
|
break; |
|
|
|
case (int)AskState.Ship: |
|
|
|
column.ColumnName = _cur + "(" + _ask + ")" + "(已发货)"; |
|
|
|
break; |
|
|
|
case (int)AskState.Confirm: |
|
|
|
column.ColumnName = _cur + "(" + _ask + ")" + "(已确认)"; |
|
|
|
break; |
|
|
|
case (int)AskState.Release: |
|
|
|
column.ColumnName = _cur + "(" + _ask + ")" + "(已发布)"; |
|
|
|
break; |
|
|
|
case (int)AskState.Receive: |
|
|
|
column.ColumnName = _cur + "(" + _ask + ")" + "(已收货)"; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
dt1.Columns["PartCode"].ColumnName = "零件编码"; |
|
|
|
dt1.Columns["PartDesc"].ColumnName = "零件描述"; |
|
|
|
dt1.Columns["PoUnit"].ColumnName = "单位"; |
|
|
|
dt1.Columns["PoBillNum"].ColumnName = "订单编号"; |
|
|
|
dt1.Columns["PoLine"].ColumnName = "行号"; |
|
|
|
dt1.Columns["Domain"].ColumnName = "域"; |
|
|
|
} |
|
|
|
conn.Close(); |
|
|
|
} |
|
|
|
catch (SqlException ex) |
|
|
|
{ |
|
|
|
throw new Exception($"系统无法连接到数据库:{dbSetting},请检查配置的服务器,数据库,用户名和密码等信息是否正确。{Environment.NewLine}{ex}"); |
|
|
|
} |
|
|
|
return dt1; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|