You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

423 lines
20 KiB

using NFine.Data.Extensions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NFine.Code;
using NFine.Repository;
using System.Data.Common;
using NFine.Domain._03_Entity.SRM;
using ICS.Application.Entity;
using Newtonsoft.Json;
using System.Configuration;
using System.Data.SqlClient;
using ICS.Data;
using Newtonsoft.Json.Linq;
using NFine.Domain._03_Entity.WMS;
using System.Net;
using System.IO;
namespace NFine.Application.WMS
{
public class FinishedProductWarehouseEntryApp : RepositoryFactory<ICSVendor>
{
public static DataTable PRInvmes = new DataTable();
/// <summary>
/// 退料
/// </summary>
/// <param name="jqgridparam"></param>
/// <returns></returns>
public DataTable GetICSMOApplyNeg(ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @" SELECT DISTINCT a.ID,a.RCVCode AS ApplyNegCode,a.WHCode,b.WarehouseName,a.Type,a.Status,a.MUSERName,a.MTIME,a.CreateDateTime,a.CreatePerson,
c.ProjectCode,c.BatchCode,c.Version,c.Brand,c.cFree1,c.cFree2,c.cFree3,cFree4,cFree5,c.cFree6,c.cFree7,c.cFree8,cFree9,cFree10
FROM ICSWMSManufactureReceive a
LEFT JOIN ICSWarehouse b ON b.WarehouseCode=a.WHCode AND b.WorkPoint=a.WorkPoint
LEFT JOIN ICSExtension c ON c.ID=a.ExtensionID AND c.WorkPoint=a.WorkPoint
WHERE 1=1";
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public DataTable GetICSMOApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
DataTable dt = new DataTable();
//var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @"SELECT DISTINCT a.RCVCode AS ApplyNegCode,a.Sequence,a.LotNo,a.InvCode,inv.InvName,a.Quantity,a.RCVQuantity,a.MTIME,a.SourceCode,a.SourceSequence,
c.ProjectCode,c.BatchCode,c.Version,c.Brand,c.cFree1,c.cFree2,c.cFree3,cFree4,cFree5,c.cFree6,c.cFree7,c.cFree8,cFree9,cFree10
FROM ICSWMSManufactureReceiveDetail a
LEFT JOIN ICSInventory inv ON inv.InvCode=a.invcode AND inv.WorkPoint=a.WorkPoint
LEFT JOIN ICSExtension c ON c.ID=a.ExtensionID AND c.WorkPoint=a.WorkPoint
LEFT JOIN ICSMO d ON d.MOCode=a.SourceCode AND d.Sequence=a.SourceSequence AND d.WorkPoint=a.WorkPoint and d.MOStatus<> '3'
LEFT JOIN ICSInventoryLotDetail e ON e.TransCode=d.MOCode AND e.TransSequence=d.Sequence AND e.WorkPoint=d.WorkPoint
WHERE a.RCVCode='" + ApplyNegCode + "' ";
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public string DeleteICSMOApplyNeg(string keyValue)
{
//站点信息
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string msg = "";
keyValue = keyValue.Substring(1, keyValue.Length - 2);
string sql = string.Empty;
sql += string.Format(@"DELETE FROM dbo.ICSWMSManufactureReceive WHERE RCVCode IN ({0}) and WorkPoint ='{1}' ", keyValue.TrimEnd(','), WorkPoint);
sql += string.Format(@"DELETE FROM dbo.ICSWMSManufactureReceiveDetail WHERE RCVCode IN ({0}) and WorkPoint ='{1}' ", keyValue.TrimEnd(','), WorkPoint);
try
{
if (SqlHelper.CmdExecuteNonQueryLi(sql) <= 0)
{
msg = "删除失败!";
}
}
catch (Exception ex)
{
return ex.Message;
//throw new Exception(ex.Message);
}
return msg;
}
public DataTable GetICSReturnTemporary(string rfqno)
{
string sql = @"SELECT DISTINCT a.RCVCode AS ApplyNegCode,a.Sequence,a.LotNo,a.InvCode,a.Quantity,a.RCVQuantity,a.MTIME,
c.ProjectCode,c.BatchCode,c.Version,c.Brand,c.cFree1,c.cFree2,c.cFree3,cFree4,cFree5,c.cFree6,c.cFree7,c.cFree8,cFree9,cFree10
FROM ICSWMSManufactureReceiveDetail a
LEFT JOIN ICSExtension c ON c.ID=a.ExtensionID AND c.WorkPoint=a.WorkPoint
LEFT JOIN ICSMO d ON d.MOCode=a.SourceCode AND d.Sequence=a.SourceSequence AND d.WorkPoint=a.WorkPoint and d.MOStatus<>'3'
LEFT JOIN ICSInventoryLotDetail e ON e.TransCode=d.MOCode AND e.TransSequence=d.Sequence AND e.WorkPoint=d.WorkPoint
WHERE a.RCVCode='" + rfqno + "'";
DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
DataTable dtCloned = table.Clone();
foreach (DataColumn col in dtCloned.Columns)
{
col.DataType = typeof(string);
}
foreach (DataRow row in table.Rows)
{
DataRow newrow = dtCloned.NewRow();
foreach (DataColumn column in dtCloned.Columns)
{
newrow[column.ColumnName] = row[column.ColumnName].ToString();
}
dtCloned.Rows.Add(newrow);
}
if (PRInvmes.Rows.Count > 0)
{
dtCloned.Merge(PRInvmes, false);
}
return dtCloned;
}
public DataTable GetINV(string invcode, string mocode, ref Pagination jqgridparam)
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
object Figure = GetDecimalDigits();
List<DbParameter> parameter = new List<DbParameter>();
DataTable table = new DataTable();
string wherestr = "";
if (!string.IsNullOrEmpty(invcode))
{
wherestr += " and a.InvCode like '%" + invcode + "%'";
}
if (!string.IsNullOrEmpty(mocode))
{
wherestr += " and a.MoCode like '%" + mocode + "%'";
}
string groupstr = " GROUP BY a.MODetailID,a.MOCode,a.Sequence,a.WHCode,a.RCVQuantity,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,a.Quantity,a.Amount,a.StartDate,a.DueDate,a.MOStatus,a.MUSERName,a.MTIME,a.MOMemo ";
string sql = @"select distinct --c.ID,
a.MODetailID,a.MOCode,a.Sequence,
--c.LotNo,
a.WHCode,CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity, CAST(a.RCVQuantity AS DECIMAL(18,{0})) as RCVQuantity ,CAST( a.Quantity AS DECIMAL(18,{0})) -CAST(a.RCVQuantity AS DECIMAL(18,{0})) as ERPNum,
SUM(CAST(c.LOTQTY AS DECIMAL(18,{0}))) as LOTQTY ,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,CAST( a.Amount as DECIMAL(18,{0})) as Amount,a.StartDate
,a.DueDate,a.MOStatus,
-- c.ExtensionID,
a.MUSERName,a.MTIME ,
a.MOMemo
-- ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
-- ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
-- a.EATTRIBUTE9,a.EATTRIBUTE10
from ICSMO a
left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
left join (
select ee.ID,mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint,ee.LotNo,ee.ExtensionID from ICSInventoryLot ee
left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='3'
where isnull(ee.EATTRIBUTE1,'')=''
group by mm.TransCode,mm.TransSequence,ee.WorkPoint,ee.LotNo,ee.ExtensionID,ee.ID
)c
on a.MOCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
left join ICSExtension f on c.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
where 1=1 and a.Quantity-ISNULL(c.LOTQTY,0)<>0 and a.MOStatus<>'3' " + wherestr + groupstr;
sql = string.Format(sql, Figure);
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public void AddMOApplyNegTemp(string json)
{
var data = json.ToJObject();
if (PRInvmes.Columns.Count <= 0)
{
PRInvmes.Columns.Add("ZJID", typeof(string));
PRInvmes.Columns.Add("ApplyNegCode", typeof(string));
PRInvmes.Columns.Add("Sequence", typeof(string));
//PRInvmes.Columns.Add("LotNo", typeof(string));
PRInvmes.Columns.Add("WHCode", typeof(string));
PRInvmes.Columns.Add("InvCode", typeof(string));
PRInvmes.Columns.Add("InvName", typeof(string));
PRInvmes.Columns.Add("InvStd", typeof(string));
PRInvmes.Columns.Add("InvUnit", typeof(string));
PRInvmes.Columns.Add("OriginalQty", typeof(string));
PRInvmes.Columns.Add("Quantity", typeof(string));
PRInvmes.Columns.Add("RCVQuantity", typeof(string));
PRInvmes.Columns.Add("LOTQTY", typeof(string));
PRInvmes.Columns.Add("ERPNum", typeof(string));
PRInvmes.Columns.Add("IssueNegQuantity", typeof(string));
PRInvmes.Columns.Add("ExtensionID", typeof(string));
PRInvmes.Columns.Add("Amount", typeof(string));
PRInvmes.Columns.Add("ID", typeof(string));
}
string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
DataRow newrow = PRInvmes.NewRow();
newrow["ZJID"] = data["ZJID"];
newrow["ApplyNegCode"] = data["ApplyNegCode"];
newrow["Sequence"] = data["Sequence"];
//newrow["LotNo"] = data["LotNo"];
newrow["WHCode"] = data["WHCode"];
newrow["InvName"] = data["InvName"];
newrow["InvCode"] = data["InvCode"];
newrow["InvStd"] = data["InvStd"];
newrow["InvUnit"] = data["InvUnit"];
newrow["OriginalQty"] = data["OriginalQty"];
newrow["RCVQuantity"] = data["RCVQuantity"];
newrow["LOTQTY"] = data["LOTQTY"];
newrow["ERPNum"] = data["ERPNum"];
newrow["Amount"] = data["Amount"];
newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
newrow["ExtensionID"] = data["ExtensionID"];
newrow["Quantity"] = "";
newrow["ID"] = data["ID"];
PRInvmes.Rows.Add(newrow);
}
public string SaveICSMOApplyNeg(string ICSASN)
{
string msg = "";
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "FinishedProductWarehouseEntry/Create";
string result = HttpPost(APIURL, ICSASN);
JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
string MessAge = Obj["Message"].ToString();
string Success = Obj["Success"].ToString();
if (Success.ToUpper() == "FALSE")
{
msg = MessAge;
}
return msg;
}
public void ClearTemp()
{
PRInvmes.Rows.Clear();
}
public DataTable GetICSMOApplyNegDetailTemp(string ApplyNegCode)
{
string sql = @"SELECT
a.ID,
a.ID as TLZID,
a.ApplyNegCode,
a.InvCode,
a.Quantity,
a.Amount,
a.SourceDetailID as ZJID,
b.InvName,
b.InvStd,
b.InvUnit,
a.IssueNegQuantity,
a.ExtensionID
,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
FROM
ICSMOApplyNegDetail a
LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
where a.ApplyNegCode='" + ApplyNegCode + "'";
DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
if (PRInvmes == null || PRInvmes.Columns.Count <= 0)
PRInvmes = table.Clone();
DataTable dtCloned = table.Clone();
foreach (DataColumn col in dtCloned.Columns)
{
col.DataType = typeof(string);
}
foreach (DataRow row in table.Rows)
{
DataRow newrow = dtCloned.NewRow();
foreach (DataColumn column in dtCloned.Columns)
{
newrow[column.ColumnName] = row[column.ColumnName].ToString();
}
dtCloned.Rows.Add(newrow);
}
if (PRInvmes.Rows.Count > 0)
{
//dtCloned.Merge(Invmes, false);
foreach (DataRow data in PRInvmes.Rows)
{
var info = dtCloned.Select(string.Format("TLZID='{0}'", data["TLZID"]));
if (info != null && info.Length > 0)
{
info[0]["ZJID"] = data["ZJID"];
info[0]["InvName"] = data["InvName"];
info[0]["InvCode"] = data["InvCode"];
info[0]["InvStd"] = data["InvStd"];
info[0]["InvUnit"] = data["InvUnit"];
info[0]["Amount"] = data["Amount"];
info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
info[0]["ExtensionID"] = data["ExtensionID"];
info[0]["Quantity"] = 0;
}
else
{
DataRow newrow = dtCloned.NewRow();
newrow["ZJID"] = data["ZJID"];
newrow["InvName"] = data["InvName"];
newrow["InvCode"] = data["InvCode"];
newrow["InvStd"] = data["InvStd"];
newrow["InvUnit"] = data["InvUnit"];
newrow["Amount"] = data["Amount"];
newrow["Quantity"] = 0;
newrow["ID"] = data["ID"];
newrow["TLZID"] = data["TLZID"];
newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
newrow["ExtensionID"] = data["ExtensionID"];
dtCloned.Rows.Add(newrow);
}
}
}
return dtCloned;
}
public void UpdateMOApplyNegTemp(string json)
{
var data = json.ToJObject();
string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
var info = PRInvmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
if (info != null && info.Length > 0)
{
info[0]["ZJID"] = data["ZJID"];
info[0]["InvName"] = data["InvName"];
info[0]["InvCode"] = data["InvCode"];
info[0]["InvStd"] = data["InvStd"];
info[0]["InvUnit"] = data["InvUnit"];
info[0]["Amount"] = data["Amount"];
info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
info[0]["ExtensionID"] = data["ExtensionID"];
info[0]["Quantity"] = 0;
}
else
{
DataRow newrow = PRInvmes.NewRow();
newrow["ZJID"] = data["ZJID"];
newrow["InvName"] = data["InvName"];
newrow["InvCode"] = data["InvCode"];
newrow["InvStd"] = data["InvStd"];
newrow["InvUnit"] = data["InvUnit"];
newrow["Amount"] = data["Amount"];
newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
newrow["ExtensionID"] = data["ExtensionID"];
newrow["Quantity"] = 0;
newrow["ID"] = data["ID"];
newrow["TLZID"] = data["TLZID"];
PRInvmes.Rows.Add(newrow);
}
}
public string AuditICSMOApplyNeg(string ICSASN)
{
string msg = "";
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Approve";
string result = HttpPost(APIURL, ICSASN);
JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
string MessAge = Obj["Message"].ToString();
string Success = Obj["Success"].ToString();
if (Success.ToUpper() == "FALSE")
{
msg = MessAge;
}
return msg;
}
public string UpdateICSMOApplyNeg(string ICSASN)
{
string msg = "";
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Update";
string result = HttpPost(APIURL, ICSASN);
JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
string MessAge = Obj["Message"].ToString();
string Success = Obj["Success"].ToString();
if (Success.ToUpper() == "FALSE")
{
msg = MessAge;
}
return msg;
}
//接口api解析
public static string HttpPost(string url, string body)
{
try
{
Encoding encoding = Encoding.UTF8;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
request.ContentType = "application/json; charset=utf-8";
byte[] buffer = encoding.GetBytes(body);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
{
return reader.ReadToEnd();
}
}
catch (WebException ex)
{
throw new Exception(ex.Message);
}
}
public object GetDecimalDigits()
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
try
{
string sql = string.Empty;
sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
object Figure = SqlHelper.ExecuteScalar(sql);
return Figure;
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
}
}