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.
1617 lines
79 KiB
1617 lines
79 KiB
using ICS.Data;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using NFine.Code;
|
|
using NFine.Data.Extensions;
|
|
using NFine.Domain._03_Entity.SRM;
|
|
using NFine.Repository;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using System.Data.SqlClient;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace NFine.Application.MFWMS
|
|
{
|
|
public class ScrapDocumentDealWithApp : RepositoryFactory<ICSVendor>
|
|
{
|
|
public static DataTable Invmes = new DataTable();
|
|
public class LOTStockModel
|
|
{
|
|
public string TransID { get; set; }
|
|
/// <summary>
|
|
/// 源头单据号
|
|
/// </summary>
|
|
public string TransCode { get; set; }
|
|
|
|
/// <summary>
|
|
/// 源头单据行号
|
|
/// </summary>
|
|
public string TransSequence { get; set; }
|
|
/// <summary>
|
|
/// 数量
|
|
/// </summary>
|
|
public string Quantity { get; set; }
|
|
/// <summary>
|
|
/// 辅计量数量
|
|
/// </summary>
|
|
public string Amount { get; set; }
|
|
/// <summary>
|
|
/// 操作类型
|
|
/// </summary>
|
|
public string TransType { get; set; }
|
|
/// <summary>
|
|
/// 操作人
|
|
/// </summary>
|
|
public string User { get; set; }
|
|
/// <summary>
|
|
/// 操作时间
|
|
/// </summary>
|
|
public string MTime { get; set; }
|
|
|
|
|
|
public string WorkPoint { get; set; }
|
|
public List<LOTStockModelList> Detail { get; set; }
|
|
|
|
}
|
|
public class LOTStockModelList
|
|
{
|
|
/// <summary>
|
|
/// 源头单据行号
|
|
/// </summary>
|
|
public string TransSequence { get; set; }
|
|
/// <summary>
|
|
/// 条码
|
|
/// </summary>
|
|
public string LotNo { get; set; }
|
|
/// <summary>
|
|
/// 数量
|
|
/// </summary>
|
|
public string CurrentQuantity { get; set; }
|
|
/// <summary>
|
|
/// 辅计量数量
|
|
/// </summary>
|
|
public string CurrentAmount { get; set; }
|
|
|
|
public string Sequence { get; set; }
|
|
|
|
/// <summary>
|
|
/// 仓库代码
|
|
/// </summary>
|
|
public string WarehouseCode { get; set; }
|
|
/// <summary>
|
|
/// 库位代码
|
|
/// </summary>
|
|
public string LocationCode { get; set; }
|
|
/// <summary>
|
|
/// LogID
|
|
/// </summary>
|
|
public string LogID { get; set; }
|
|
public string Quantity { get; set; }
|
|
public string Amount { get; set; }
|
|
}
|
|
|
|
|
|
public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
// object Figure = GetDecimalDigits();
|
|
#region [SQL]
|
|
string sql = @"select a.ID, a.DNCode, a.Sequence, a.InvCode,b.InvName, a.Quantity, a.Amount, a.RCVQuantity,d.VenName, a.DepCode,
|
|
a.UnitPrice, a.Currency, a.Status, a.CreatePerson, a.CreateDateTime,
|
|
a.WorkPoint ,c.ProjectCode,c.BatchCode,c.Version,
|
|
c.Brand,c.cFree1,c.cFree2,c.cFree3,c.cFree4,c.cFree5,c.cFree6,c.cFree7,c.cFree8,c.cFree9,c.cFree10
|
|
from dbo.ICSDeliveryNotice a
|
|
left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
|
|
left join dbo.ICSExtension c on a.ExtensionID=c.ID and a.WorkPoint=c.WorkPoint
|
|
left join dbo.ICSVendor d on a.VenCode=d.VenCode and a.WorkPoint=d.WorkPoint
|
|
where Status='2' ";
|
|
// sql = string.Format(sql, Figure);
|
|
sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
|
|
#endregion
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
//if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
//{
|
|
// sql += " and a.ApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' ";
|
|
//}
|
|
//if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
//{
|
|
// sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
|
|
//}
|
|
//if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
|
|
//{
|
|
// sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
|
|
//}
|
|
//if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
|
|
//{
|
|
// sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
|
|
//}
|
|
//if (!string.IsNullOrWhiteSpace(queryParam["FromTime"].ToString()))
|
|
//{
|
|
// sql += " and a.MTIME >= '" + queryParam["FromTime"].ToString() + "' ";
|
|
//}
|
|
//if (!string.IsNullOrWhiteSpace(queryParam["ToTime"].ToString()))
|
|
//{
|
|
// sql += " and a.MTIME <= '" + queryParam["ToTime"].ToString() + "' ";
|
|
//}
|
|
//if (!string.IsNullOrWhiteSpace(queryParam["POStatus"].ToString()))
|
|
//{
|
|
// string POStatus = queryParam["POStatus"].ToString();
|
|
// if (POStatus == "0")
|
|
// {
|
|
// //sql += " and a.Quantity=ISNULL(c.LotQty,0)";
|
|
// }
|
|
// else if (POStatus == "1")
|
|
// {
|
|
// sql += " and a.Quantity-ISNULL(c.LOTQTY,0)=0";
|
|
// }
|
|
// else
|
|
// {
|
|
// sql += " and a.Quantity-ISNULL(c.LOTQTY,0)<>0";
|
|
// }
|
|
//}
|
|
|
|
|
|
|
|
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
|
|
{
|
|
sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
|
|
{
|
|
sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
|
|
}
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
|
|
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());
|
|
}
|
|
}
|
|
|
|
public DataTable GetSubGridJson(string OOCode, string Sequence, string Type, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
object Figure = GetDecimalDigits();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string sql = @" select c.TransCode,c.TransSequence ,a.ID,a.LotNo, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity ,a.MUSERName,a.MTIME
|
|
,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,
|
|
case when isnull(d.ID,'')='' then '未入库' else '已入库' end as isStorage,
|
|
case when g.InvIQC='1'and isnull(e.ID,'')='' then '未检验' else '已检验' end as isInspection,
|
|
case when Isnull(g.InvIQC,'0')='1' then '是' else '否' end as isExemption,a.Amount,
|
|
convert(varchar(20),a.ProductDate,23) as ProductDate,convert(varchar(20),a.ExpirationDate,23) as ExpirationDate ,g.EffectiveDays,a.EATTRIBUTE4,a.EATTRIBUTE5
|
|
from ICSInventoryLot a
|
|
left join (select count(LotNo) LotNoCount,LotNo,WorkPoint from ICSWareHouseLotInfo
|
|
group by LotNo,WorkPoint)b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventoryLotDetail c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
left join dbo.ICSWareHouseLotInfo d on a.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint
|
|
left join ICSInspection e on a.LotNo=e.LotNo and e.Enable='1' and a.WorkPoint=e.WorkPoint
|
|
left join ICSInventory g on a.InvCode=g.InvCode and a.WorkPoint=g.WorkPoint
|
|
WHERE isnull(a.EATTRIBUTE1,'')='' and a.Type='" + Type + "' and c.TransCode='" + OOCode + "' and c.TransSequence='" + Sequence + "' and a.WorkPoint in ('" + WorkPoint + "')";
|
|
sql = string.Format(sql, Figure);
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
|
|
|
|
|
|
public DataTable GetDocumentsByCode(string Code, string Sequence, string WorkPoint)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
object Figure = GetDecimalDigits();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
|
|
string sql = @"select a.InvCode,b.InvName,b.ClassCode,b.InvStd,b.InvUnit, CAST( e.Quantity AS DECIMAL(18,4)) as Quantity, CAST( a.Amount as DECIMAL(18,4)) as Amount, CAST( isnull(c.LOTQTY,0) as DECIMAL(18,4)) as CreatedQty ,
|
|
CAST( (e.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,4)) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,4)) as EffectiveDays,
|
|
d.ProjectCode,d.BatchCode,d.Version,d.Brand,d.cFree1,d.cFree2,d.cFree3,d.cFree4,d.cFree5,d.cFree6,d.cFree7,d.cFree8,d.cFree9,d.cFree10
|
|
from ICSDeliveryNotice a
|
|
left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
|
|
|
|
left join(select a.DNCode,a.Sequence,a.WorkPoint,
|
|
case when b.OverInType='1' then a.Quantity*(1+b.OverInValue) when b.OverInType='2' then a.Quantity+b.OverInValue when b.OverInType='3' then 999999 else a.Quantity end as Quantity
|
|
from ICSDeliveryNotice a
|
|
left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint) e on e.DNCode=a.DNCode and e.Sequence=a.Sequence
|
|
|
|
left join (
|
|
select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
|
|
left join ICSInventoryLotDetail b on a.LotNo=b.LotNo
|
|
and a.Type='7'
|
|
where isnull(a.EATTRIBUTE1,'')=''
|
|
group by b.TransCode,b.TransSequence
|
|
) c on a.DNCode=c.TransCode and a.Sequence=c.TransSequence
|
|
left join ICSExtension d on a.ExtensionID=d.ID and a.WorkPoint=d.WorkPoint
|
|
WHERE 1 =1
|
|
and a.DNCode='" + Code + "' and a.Sequence='" + Sequence + "'";
|
|
sql += " and a.WorkPoint='" + WorkPoint + "'";
|
|
sql = string.Format(sql, Figure);
|
|
return Repository().FindTableBySql(sql.ToString());
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GetGeneratedNum(string Code, string Sequence, string Type, string thisCreateQty)
|
|
{
|
|
string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
DataTable dt = new DataTable();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = string.Empty;
|
|
bool flag = true;
|
|
if (Type == "1")
|
|
{
|
|
sql = @" select distinct CAST(isnull(xx.Quantity,0) AS DECIMAL(18,4)) as Quantity ,
|
|
CAST(isnull(c.LOTQTY,0) AS DECIMAL(18,4)) as LOTQTY
|
|
|
|
from ICSDeliveryNotice a
|
|
left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
|
|
left join(select a.OOCode,a.Sequence,a.WorkPoint,
|
|
case when b.OverInType='1' then a.Quantity*(1+b.OverInValue) when b.OverInType='2' then a.Quantity+b.OverInValue when b.OverInType='3' then 999999 else a.Quantity end as Quantity
|
|
from ICSDeliveryNotice a
|
|
left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint) xx on xx.DNCode=a.DNCode and xx.Sequence=a.Sequence and xx.WorkPoint=a.WorkPoint
|
|
|
|
left join (
|
|
select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
|
|
left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo
|
|
and ee.type='7'
|
|
where isnull(ee.EATTRIBUTE1,'')=''
|
|
group by mm.TransCode,mm.TransSequence,ee.WorkPoint
|
|
)c
|
|
on a.DNCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
and a.DNCode='" + Code + "' and a.Sequence='" + Sequence + "' and a.WorkPoint='" + WorkPoints + "'";
|
|
}
|
|
|
|
dt = SqlHelper.GetDataTableBySql(sql);
|
|
decimal Quantity = Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString());
|
|
decimal LOTQTY = Convert.ToDecimal(dt.Rows[0]["LOTQTY"].ToString());
|
|
decimal thisQty = Convert.ToDecimal(thisCreateQty);
|
|
if (LOTQTY + thisQty > Quantity)
|
|
{
|
|
flag = false;
|
|
}
|
|
|
|
return flag;
|
|
}
|
|
|
|
|
|
public string SubmitFormWWSHDH(string ODNCode, string Sequence, string keyValue, string WorkPoint)
|
|
{
|
|
string msg = "";
|
|
var queryParam = keyValue.ToJObject();
|
|
string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
|
|
decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
|
|
decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
|
|
decimal LOTQTY = minPackQty;
|
|
string Pre = "ODN" + ODNCode + (Convert.ToInt32(Sequence)).ToString("D4");
|
|
string sql = string.Empty;
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
|
|
string InvCode = queryParam["ClassCode"].ToString();
|
|
string Location = queryParam["Location"].ToString();
|
|
string sqls = string.Empty;
|
|
string Colspan = "";
|
|
string str1 = "";
|
|
string LotNo = string.Empty;
|
|
List<string> ExtensionIDList = new List<string>();
|
|
|
|
|
|
|
|
for (int i = 0; i < createPageCount; i++)
|
|
{
|
|
if (i + 1 == createPageCount)
|
|
{
|
|
if (minPackQty * createPageCount > thisCreateQty)
|
|
{
|
|
LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
|
|
}
|
|
}
|
|
|
|
Colspan = queryParam["ProjectCode"].ToString() + "~" + queryParam["BatchCode"].ToString() + "~" + queryParam["Version"].ToString() + "~" + queryParam["Brand"].ToString() + "~" + queryParam["cFree1"].ToString() + "~" + queryParam["cFree2"].ToString() + "~" + queryParam["cFree3"].ToString() + "~" + queryParam["cFree4"].ToString() + "~" + queryParam["cFree5"].ToString() + "~" + queryParam["cFree6"].ToString() + "~" + queryParam["cFree7"].ToString() + "~" + queryParam["cFree8"].ToString() + "~" + queryParam["cFree9"].ToString() + "~" + queryParam["cFree10"].ToString();
|
|
sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoint);
|
|
object ExtensionID = SqlHelper.ExecuteScalar(sqls);
|
|
bool flag = true;
|
|
foreach (var item in ExtensionIDList)
|
|
{
|
|
if (item == Colspan + WorkPoint)
|
|
{
|
|
flag = false;
|
|
}
|
|
}
|
|
if (ExtensionID == null && flag == true)
|
|
{
|
|
str1 = Guid.NewGuid().ToString();
|
|
sql += string.Format(@"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
|
|
Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
|
|
str1, Colspan, queryParam["ProjectCode"].ToString(), queryParam["BatchCode"].ToString(), queryParam["Version"].ToString(), queryParam["Brand"].ToString(), queryParam["cFree1"].ToString(), queryParam["cFree2"].ToString(), queryParam["cFree3"].ToString(), queryParam["cFree4"].ToString(), queryParam["cFree5"].ToString(), queryParam["cFree6"].ToString(), queryParam["cFree7"].ToString(), queryParam["cFree8"].ToString(), queryParam["cFree9"].ToString(), queryParam["cFree10"].ToString(),
|
|
MUSER, MUSERNAME, WorkPoints);
|
|
}
|
|
else if (ExtensionID != null)
|
|
{
|
|
str1 = ExtensionID.ToString();
|
|
}
|
|
ExtensionIDList.Add(Colspan + WorkPoint);
|
|
|
|
LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
|
|
|
|
sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint,TransID)
|
|
Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}','{6}' )",
|
|
LotNo, ODNCode, Sequence, MUSER, MUSERNAME, WorkPoints, queryParam["ID"].ToString());
|
|
|
|
sql += string.Format(@"
|
|
insert into ICSInventoryLot
|
|
(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10)
|
|
select
|
|
newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','8','{3}','{4}', getdate(),'{5}','{9}'
|
|
,'{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}'
|
|
from ICSODeliveryNotice where ODNCode='{6}' and Sequence='{7}' and WorkPoint='{5}'",
|
|
LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, ODNCode, Sequence, str1, Convert.ToDecimal(queryParam["Amount"].ToString()) / minPackQty * LOTQTY, queryParam["ExpirationDate"].ToString()
|
|
, queryParam["EATTRIBUTE1"].ToString(), queryParam["EATTRIBUTE2"].ToString(), queryParam["EATTRIBUTE3"].ToString(), queryParam["EATTRIBUTE4"].ToString(), queryParam["EATTRIBUTE5"].ToString(),
|
|
queryParam["EATTRIBUTE6"].ToString(), queryParam["EATTRIBUTE7"].ToString(), queryParam["EATTRIBUTE8"].ToString(), queryParam["EATTRIBUTE9"].ToString(), queryParam["EATTRIBUTE10"].ToString());
|
|
sql += "\r\n";
|
|
}
|
|
try
|
|
{
|
|
if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
|
|
{
|
|
msg = CallWebApiByDH(sql, LotNo, Location, WorkPoint, LOTQTY);
|
|
}
|
|
else
|
|
{
|
|
msg = "报废失败";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
msg = ex.Message;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
|
|
|
|
|
|
public string CallWebApiByDH(string sql, string LotNo, string Location, string WorkPoint, decimal LOTQTY)
|
|
{
|
|
List<Dictionary<string, object>> detailList = new List<Dictionary<string, object>>();
|
|
// 创建Detail项
|
|
var detailItem = new Dictionary<string, object>();
|
|
detailItem["LotNo"] = LotNo;
|
|
detailItem["LocationCode"] = Location;
|
|
detailItem["Quantity"] = LOTQTY;
|
|
// 将Detail项添加到集合中
|
|
detailList.Add(detailItem);
|
|
// 创建JSON参数
|
|
var parameters = new Dictionary<string, object>
|
|
{
|
|
{ "Workpoint", WorkPoint },
|
|
{ "User", NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode },
|
|
{ "TransType", "委外入库-委外订单" },
|
|
{ "MTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
|
|
{ "Detail", detailList }
|
|
};
|
|
// 序列化为JSON字符串
|
|
string Inputstr = JsonConvert.SerializeObject(parameters);
|
|
Inputstr = "[" + Inputstr + "]";
|
|
string msg = "";
|
|
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTStockUp/Create";
|
|
string result = HttpPost(APIURL, Inputstr);
|
|
JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
|
|
string MessAge = Obj["Message"].ToString();
|
|
string Success = Obj["Success"].ToString();
|
|
string ApiSql = string.Empty;
|
|
if (Success.ToUpper() == "FALSE")
|
|
{
|
|
ApiSql = @"delete dbo.ICSInventoryLot where LotNo='" + LotNo + "' delete dbo.ICSInventoryLotDetail where LotNo='" + LotNo + "' ";
|
|
SqlHelper.CmdExecuteNonQueryLi(ApiSql);
|
|
msg = MessAge;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string SubmitFormChengPing(string MOCode, string Sequence, string keyValue, string WorkPoint, float Quantity)
|
|
{
|
|
string msg = "";
|
|
var queryParam = keyValue.ToJObject();
|
|
string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
|
|
decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
|
|
decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
|
|
decimal LOTQTY = minPackQty;
|
|
string InvCode = queryParam["ClassCode"].ToString();
|
|
string InvCodeLP = queryParam["InvCode"].ToString();
|
|
string Pre = "CP" + MOCode + (Convert.ToInt32(Sequence)).ToString("D4");
|
|
string sql = string.Empty;
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
|
|
string Location = queryParam["Location"].ToString();
|
|
|
|
string sqls = string.Empty;
|
|
string Colspan = "";
|
|
string str1 = "";
|
|
string LotNo = string.Empty;
|
|
List<string> ExtensionIDList = new List<string>();
|
|
|
|
|
|
for (int i = 0; i < createPageCount; i++)
|
|
{
|
|
if (i + 1 == createPageCount)
|
|
{
|
|
if (minPackQty * createPageCount > thisCreateQty)
|
|
{
|
|
LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
|
|
}
|
|
}
|
|
|
|
Colspan = queryParam["ProjectCode"].ToString() + "~" + queryParam["BatchCode"].ToString() + "~" + queryParam["Version"].ToString() + "~" + queryParam["Brand"].ToString() + "~" + queryParam["cFree1"].ToString() + "~" + queryParam["cFree2"].ToString() + "~" + queryParam["cFree3"].ToString() + "~" + queryParam["cFree4"].ToString() + "~" + queryParam["cFree5"].ToString() + "~" + queryParam["cFree6"].ToString() + "~" + queryParam["cFree7"].ToString() + "~" + queryParam["cFree8"].ToString() + "~" + queryParam["cFree9"].ToString() + "~" + queryParam["cFree10"].ToString();
|
|
sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoint);
|
|
object ExtensionID = SqlHelper.ExecuteScalar(sqls);
|
|
bool flag = true;
|
|
foreach (var item in ExtensionIDList)
|
|
{
|
|
if (item == Colspan + WorkPoint)
|
|
{
|
|
flag = false;
|
|
}
|
|
}
|
|
if (ExtensionID == null && flag == true)
|
|
{
|
|
str1 = Guid.NewGuid().ToString();
|
|
sql += string.Format(@"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
|
|
Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
|
|
str1, Colspan, queryParam["ProjectCode"].ToString(), queryParam["BatchCode"].ToString(), queryParam["Version"].ToString(), queryParam["Brand"].ToString(), queryParam["cFree1"].ToString(), queryParam["cFree2"].ToString(), queryParam["cFree3"].ToString(), queryParam["cFree4"].ToString(), queryParam["cFree5"].ToString(), queryParam["cFree6"].ToString(), queryParam["cFree7"].ToString(), queryParam["cFree8"].ToString(), queryParam["cFree9"].ToString(), queryParam["cFree10"].ToString(),
|
|
MUSER, MUSERNAME, WorkPoints);
|
|
}
|
|
else if (ExtensionID != null)
|
|
{
|
|
str1 = ExtensionID.ToString();
|
|
}
|
|
|
|
ExtensionIDList.Add(Colspan + WorkPoint);
|
|
|
|
|
|
LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 4);
|
|
|
|
sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint,TransID)
|
|
Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}','{6}' )",
|
|
LotNo, MOCode, Sequence, MUSER, MUSERNAME, WorkPoints, queryParam["ID"].ToString());
|
|
|
|
sql += string.Format(@"insert into ICSInventoryLot
|
|
(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount
|
|
,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10)
|
|
select
|
|
newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','3','{3}','{4}', getdate(),'{5}','{9}','{11}','0','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}'
|
|
from ICSMO where MOCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
|
|
LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, MOCode, Sequence, str1, Convert.ToDecimal(queryParam["Amount"].ToString()) / minPackQty * LOTQTY, queryParam["ExpirationDate"].ToString()
|
|
|
|
, queryParam["EATTRIBUTE1"].ToString(), queryParam["EATTRIBUTE2"].ToString(), queryParam["EATTRIBUTE3"].ToString(), queryParam["EATTRIBUTE4"].ToString(), queryParam["EATTRIBUTE5"].ToString(),
|
|
queryParam["EATTRIBUTE6"].ToString(), queryParam["EATTRIBUTE7"].ToString(), queryParam["EATTRIBUTE8"].ToString(), queryParam["EATTRIBUTE9"].ToString(), queryParam["EATTRIBUTE10"].ToString());
|
|
sql += "\r\n";
|
|
|
|
|
|
|
|
|
|
}
|
|
try
|
|
{
|
|
if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
|
|
{
|
|
string sqlwhcode = @"select b.WarehouseCode from dbo.ICSLocation a
|
|
left join dbo.ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
|
|
where a.LocationCode='"+ Location + "' and a.WorkPoint='"+ WorkPoint + "' ";
|
|
object WarehouseCode= SqlHelper.ExecuteScalar(sqlwhcode);
|
|
msg = CallWebApiByCP(sql, LotNo, Location, WorkPoint, LOTQTY, InvCodeLP, WarehouseCode.ToString(), MOCode);
|
|
}
|
|
else
|
|
{
|
|
msg = "报废失败";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
msg = ex.Message;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
|
|
|
|
|
|
public string CallWebApiByCP(string sql, string LotNo, string Location, string WorkPoint, decimal LOTQTY,string InvCode,string WarehouseCode,string Code)
|
|
{
|
|
List<Dictionary<string, object>> detailList = new List<Dictionary<string, object>>();
|
|
// 创建Detail项
|
|
var detailItem = new Dictionary<string, object>();
|
|
detailItem["LotNo"] = LotNo;
|
|
detailItem["InvCode"] = InvCode;
|
|
detailItem["TransCode"] = Code;
|
|
detailItem["LocationCode"] = Location;
|
|
detailItem["Quantity"] = LOTQTY;
|
|
detailItem["WarehouseCode"] = WarehouseCode;
|
|
// 将Detail项添加到集合中
|
|
detailList.Add(detailItem);
|
|
// 创建JSON参数
|
|
var parameters = new Dictionary<string, object>
|
|
{
|
|
{ "Workpoint", WorkPoint },
|
|
{ "User", NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode },
|
|
{ "TransType", "产成品入库-生产订单" },
|
|
{ "MTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
|
|
{ "Detail", detailList }
|
|
};
|
|
// 序列化为JSON字符串
|
|
string Inputstr = JsonConvert.SerializeObject(parameters);
|
|
Inputstr = "[" + Inputstr + "]";
|
|
string msg = "";
|
|
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTStockUp/Create";
|
|
string result = HttpPost(APIURL, Inputstr);
|
|
JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
|
|
string MessAge = Obj["Message"].ToString();
|
|
string Success = Obj["Success"].ToString();
|
|
string ApiSql = string.Empty;
|
|
if (Success.ToUpper() == "FALSE")
|
|
{
|
|
ApiSql = @"delete dbo.ICSInventoryLot where LotNo='" + LotNo + "' delete dbo.ICSInventoryLotDetail where LotNo='" + LotNo + "' ";
|
|
SqlHelper.CmdExecuteNonQueryLi(ApiSql);
|
|
msg = MessAge;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
|
|
{
|
|
string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
|
|
sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
|
|
//return Repository().FindTableBySql(sql.ToString());
|
|
return SqlHelper.ExecuteScalar(sql).ToString();
|
|
//return DbHelper.ExecuteScalar(CommandType.Text, sql).ToString();
|
|
}
|
|
|
|
|
|
|
|
public DataTable GetGridJsonScrappedIssue(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
object Figure = GetDecimalDigits();
|
|
|
|
#region [SQL]
|
|
string sql = @"
|
|
select distinct a.OutCode,a.WorkPoint,case when (a.Status='1' and a.Quantity=a.OutQuantity) then '审核' when (a.Status='1' and a.Quantity<>a.OutQuantity) then '开立' end as Status
|
|
|
|
from ICSOtherOut a ";
|
|
sql += " WHERE 1=1 ";
|
|
//sql = string.Format(sql, Figure);
|
|
sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
|
|
#endregion
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sql += " and a.OutCode like '%" + queryParam["POCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["selShow"].ToString()))
|
|
{
|
|
string POStatus = queryParam["selShow"].ToString();
|
|
if (POStatus == "0")
|
|
{
|
|
//sql += " and a.Quantity=ISNULL(c.LotQty,0)";
|
|
}
|
|
else if (POStatus == "1")
|
|
{
|
|
sql += "and a.Status='1' and a.Quantity<>a.OutQuantity ";
|
|
}
|
|
else
|
|
{
|
|
sql += "and a.Status='1' and a.Quantity=a.OutQuantity";
|
|
}
|
|
}
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
|
|
{
|
|
sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
|
|
}
|
|
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
|
|
|
|
public DataTable GetSubGridJsonScrappedIssue(string Code, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
object Figure = GetDecimalDigits();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string sql = @" select a.ID,a.OutCode,a.WHCode,b.WarehouseName,a.Sequence,a.InvCode,c.InvName,a.Quantity,a.Amount,a.OutQuantity,a.Type,a.Status,a.CreatePerson,
|
|
a.CreateDateTime,a.OutID,a.OutDetailID,a.TransferID,a.TransferDetailID,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint
|
|
from ICSOtherOut a
|
|
left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join dbo.ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
|
|
where a.OutCode='"+ Code + "' ";
|
|
// sql = string.Format(sql, Figure);
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string ApprovalReview(string Value)
|
|
{
|
|
string msg = string.Empty;
|
|
try
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string UserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
string UserCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
List<LOTStockModel> lOTStockModels = new List<LOTStockModel>();
|
|
var dateNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
var Code = Value.TrimEnd(',');
|
|
//单据先进行拣料
|
|
DataTable dateTable = GetICSMOPickMergeTemp(Code, "8");
|
|
if (dateTable == null || dateTable.Rows.Count<=0)
|
|
{
|
|
msg = "库存不足,请先检查库存";
|
|
return msg;
|
|
}
|
|
DataRow[] dateRowsIsNull = dateTable.Select("ISNULL(LotNo,'')=''");
|
|
//是否条码匹配错误
|
|
if (dateRowsIsNull.Length > 0)
|
|
{
|
|
msg = "单据号:" + dateRowsIsNull[0]["Code"].ToString() + "行号:" + dateRowsIsNull[0]["Sequence"].ToString() + "库存不足,请先检查库存";
|
|
return msg;
|
|
}
|
|
var groupedData = from row in dateTable.AsEnumerable()
|
|
group row by new
|
|
{
|
|
Code = row.Field<string>("Code"),
|
|
Sequence = row.Field<string>("Sequence")
|
|
} into g
|
|
select new
|
|
{
|
|
Code = g.Key.Code,
|
|
Sequence = g.Key.Sequence,
|
|
TotalQTY = g.Sum(x =>
|
|
{
|
|
var qtyString = x.Field<string>("QTY");
|
|
return string.IsNullOrEmpty(qtyString) ? 0 : Convert.ToDecimal(qtyString);
|
|
//return !x.IsNull("QTY") ? x.Field<decimal>("QTY") : 0;
|
|
}),
|
|
TotaliQuantity = string.IsNullOrEmpty(g.First().Field<string>("iQuantity")) ? 0 : Convert.ToDecimal(g.First().Field<string>("iQuantity")),
|
|
// TotaliQuantity = g.First().IsNull("iQuantity") ? 0 : g.First().Field<decimal>("iQuantity"),
|
|
|
|
};
|
|
|
|
foreach (var item in groupedData)
|
|
{
|
|
if (item.TotalQTY != item.TotaliQuantity)
|
|
{
|
|
msg = "单据号:"+ item.Code + "行号:" + item.Sequence + "库存不足,请先检查库存";
|
|
return msg;
|
|
}
|
|
}
|
|
DataRow[] dateRows = dateTable?.Select($@"LotNo <> '' And LotNo is not null");
|
|
|
|
//decimal ToltalCount = 0.0M;
|
|
string tablesql = $@" SELECT ID,OutCode,Sequence,Quantity FROM ICSOtherOut WHERE OutCode in({Code}) and WorkPoint='{WorkPoint}' ";
|
|
var dt = SqlHelper.CmdExecuteDataTable(tablesql);
|
|
|
|
if (dateRows == null || dateRows.Length <= 0)
|
|
{
|
|
msg = "库存不足,请先检查库存";
|
|
return msg;
|
|
}
|
|
else
|
|
{
|
|
string docCode = string.Empty;
|
|
string docCodeAfter = string.Empty;
|
|
LOTStockModel lOTStockModel = null;
|
|
|
|
// 使用 LINQ 根据 Code 字段对 DataRow[] 进行分组
|
|
var groups = dateRows.Cast<DataRow>().GroupBy(row => new
|
|
{
|
|
Code = row.Field<string>("Code"),
|
|
Sequence = row.Field<string>("Sequence"),
|
|
iQuantity = row.Field<string>("iQuantity")
|
|
});
|
|
//将捡料数据分组
|
|
foreach (var group in groups)
|
|
{
|
|
var firstRow = group.First();
|
|
var code = firstRow["Code"];
|
|
// decimal count = 0.0M;
|
|
// 存储过程返回的条码 匹配到具体数据的ID
|
|
DataRow[] SDNSequenceRow = dt.Select("OutCode='" + firstRow["Code"].ToString() + "' and Sequence='" + firstRow["Sequence"].ToString() + "'");
|
|
if (SDNSequenceRow.Length <= 0)
|
|
{
|
|
msg = "条码未能匹配销售发货表!";
|
|
return msg;
|
|
}
|
|
lOTStockModel = new LOTStockModel
|
|
{
|
|
TransID = SDNSequenceRow[0]["ID"].ToString(),
|
|
TransCode = firstRow["Code"].ToString(),
|
|
TransSequence = firstRow["Sequence"].ToString(),
|
|
TransType = "杂发",
|
|
Amount = "0",
|
|
User = UserCode,
|
|
Quantity = SDNSequenceRow[0]["Quantity"].ToString(),
|
|
MTime = dateNow,
|
|
WorkPoint = WorkPoint,
|
|
Detail = new List<LOTStockModelList>(),
|
|
};
|
|
|
|
foreach (var row in group)
|
|
{
|
|
// count += row["QTY"].ToDecimal();
|
|
LOTStockModelList lOTStockModelList = new LOTStockModelList
|
|
{
|
|
CurrentQuantity = row["QTY"].ToString(),
|
|
LotNo = row["LotNo"].ToString(),
|
|
LogID = "",
|
|
//Sequence = row["Sequence"].ToString(),
|
|
//WarehouseCode = row["WarehouseCode"].ToString(),
|
|
//LocationCode = row["LocationCode"].ToString()
|
|
};
|
|
lOTStockModel.Detail.Add(lOTStockModelList);
|
|
}
|
|
// lOTStockModel.Quantity = count.ToString();
|
|
lOTStockModels.Add(lOTStockModel);
|
|
}
|
|
|
|
string Inputstr = JsonConvert.SerializeObject(lOTStockModels);
|
|
|
|
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTStockDown/Create";
|
|
string result = HttpPost(APIURL, Inputstr);
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
msg = ex.Message;
|
|
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
|
|
|
|
public DataTable GetICSMOPickMergeTemp(string ID, string Type)
|
|
{
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
ID = ID.Replace("'", "''");
|
|
ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
|
|
|
|
string Code = SqlHelper.GetItemsDetailEnabledMark("MtimeControl");
|
|
|
|
string sql = @"EXEC ICSPicking '{0}','{1}','0','{2}'";
|
|
sql = string.Format(sql, ID, Type, WorkPoint);
|
|
|
|
var dataset = Repository().FindDataSetBySql(sql);
|
|
if (dataset.Tables[0].Rows.Count == 0)
|
|
return null;
|
|
DataTable table = dataset.Tables[0];
|
|
try
|
|
{
|
|
DataRow[] dss = table.Select("LotNO=''");
|
|
|
|
|
|
|
|
foreach (var item in dss)
|
|
{
|
|
DataRow[] dsss = table.Select("Code='" + item["Code"].ToString() + "' and Sequence='" + item["Sequence"].ToString() + "' and LotNO <> '' ");
|
|
if (dsss != null && dsss.Length > 0)
|
|
{
|
|
table.Rows.Remove(item);
|
|
}
|
|
}
|
|
var result = ConvertCellToString(table);
|
|
if (Invmes.Rows.Count > 0)
|
|
{
|
|
result.Merge(Invmes, false);
|
|
}
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
public DataTable ConvertCellToString(DataTable data)
|
|
{
|
|
DataTable dtCloned = data.Clone();
|
|
foreach (DataColumn col in dtCloned.Columns)
|
|
{
|
|
col.DataType = typeof(string);
|
|
}
|
|
foreach (DataRow row in data.Rows)
|
|
{
|
|
DataRow newrow = dtCloned.NewRow();
|
|
foreach (DataColumn column in dtCloned.Columns)
|
|
{
|
|
newrow[column.ColumnName] = row[column.ColumnName].ToString();
|
|
|
|
}
|
|
dtCloned.Rows.Add(newrow);
|
|
}
|
|
return dtCloned;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DataTable GetGridJsonScrapDocument(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
object Figure = GetDecimalDigits();
|
|
|
|
#region [SQL]
|
|
string sql = @"
|
|
select distinct a.TransferNO,a.WorkPoint,case when a.Status='2' and a.Quantity=a.TransferQuantity then '审核' else '开立' end as Status
|
|
,a.CreatePerson
|
|
|
|
from ICSTransferApplication a
|
|
";
|
|
sql += " WHERE 1=1 and a.Status<>'3'";
|
|
//sql = string.Format(sql, Figure);
|
|
sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
|
|
#endregion
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sql += " and a.TransferNO like '%" + queryParam["POCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["MUSER"].ToString()))
|
|
{
|
|
sql += " and a.CreatePerson like '%" + queryParam["MUSER"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
|
|
{
|
|
string WHStatus = queryParam["Status"].ToString();
|
|
if (WHStatus == "0")
|
|
{
|
|
|
|
}
|
|
else if (WHStatus == "1")
|
|
{
|
|
sql += " and a.Quantity<>a.TransferQuantity";
|
|
}
|
|
else if (WHStatus == "2")
|
|
{
|
|
sql += " and a.Status='2' and a.Quantity=a.TransferQuantity ";
|
|
}
|
|
|
|
}
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
|
|
{
|
|
sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
|
|
}
|
|
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
|
|
|
|
public DataTable GetSubGridJsonScrapDocument(string Code, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
object Figure = GetDecimalDigits();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string sql = @" SELECT a.ID,a.TransferNO,a.Sequence,a.FromWarehouseCode,a.FromLocationCode,a.ToWarehouseCode,a.ToLocationCode,
|
|
a.Status,a.InvCode,a.Quantity,a.Amount,a.TransferQuantity,a.Type,a.Memo,a.CreatePerson,a.CreateDateTime,a.TransferID,
|
|
a.TransferDetailID,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint
|
|
|
|
FROM
|
|
dbo.ICSTransferApplication a
|
|
left join ICSWarehouse b on a.FromWarehouseCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join dbo.ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
|
|
where a.TransferNO='" + Code + "' and a.WorkPoint='"+ WorkPoint + "' ";
|
|
// sql = string.Format(sql, Figure);
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
|
|
public string WWApprovalReview(string Value,string LocationCode)
|
|
{
|
|
string msg = string.Empty;
|
|
try
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string UserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
string UserCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string sqlwhcode = @"select b.WarehouseCode from dbo.ICSLocation a
|
|
left join dbo.ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
|
|
where a.LocationCode='" + LocationCode + "' and a.WorkPoint='" + WorkPoint + "' ";
|
|
object WarehouseCode = SqlHelper.ExecuteScalar(sqlwhcode);
|
|
|
|
|
|
List<LOTStockModel> lOTStockModels = new List<LOTStockModel>();
|
|
var dateNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
var Code = Value.TrimEnd(',');
|
|
//单据先进行拣料
|
|
DataTable dateTable = GetICSMOPickMergeTemp(Code, "17");
|
|
if (dateTable == null || dateTable.Rows.Count <= 0)
|
|
{
|
|
msg = "库存不足,请先检查库存";
|
|
return msg;
|
|
}
|
|
DataRow[] dateRowsIsNull = dateTable.Select("ISNULL(LotNo,'')=''");
|
|
//是否条码匹配错误
|
|
if (dateRowsIsNull.Length > 0)
|
|
{
|
|
msg = "单据号:" + dateRowsIsNull[0]["Code"].ToString() + "行号:" + dateRowsIsNull[0]["Sequence"].ToString() + "库存不足,请先检查库存";
|
|
return msg;
|
|
}
|
|
|
|
var groupedData = from row in dateTable.AsEnumerable()
|
|
group row by new
|
|
{
|
|
Code = row.Field<string>("Code"),
|
|
Sequence = row.Field<string>("Sequence")
|
|
} into g
|
|
select new
|
|
{
|
|
Code = g.Key.Code,
|
|
Sequence = g.Key.Sequence,
|
|
TotalQTY = g.Sum(x =>
|
|
{
|
|
var qtyString = x.Field<string>("QTY");
|
|
return string.IsNullOrEmpty(qtyString) ? 0 : Convert.ToDecimal(qtyString);
|
|
//return !x.IsNull("QTY") ? x.Field<decimal>("QTY") : 0;
|
|
}),
|
|
TotaliQuantity = string.IsNullOrEmpty(g.First().Field<string>("iQuantity")) ? 0 : Convert.ToDecimal(g.First().Field<string>("iQuantity")),
|
|
// TotaliQuantity = g.First().IsNull("iQuantity") ? 0 : g.First().Field<decimal>("iQuantity"),
|
|
|
|
};
|
|
|
|
foreach (var item in groupedData)
|
|
{
|
|
if (item.TotalQTY != item.TotaliQuantity)
|
|
{
|
|
msg = "单据号:" + item.Code + "行号:" + item.Sequence + "库存不足,请先检查库存";
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
DataRow[] dateRows = dateTable?.Select($@"LotNo <> '' And LotNo is not null");
|
|
|
|
//decimal ToltalCount = 0.0M;
|
|
string tablesql = $@" SELECT ID,TransferNO,Sequence FROM ICSTransferApplication WHERE TransferNO in({Code}) and WorkPoint='{WorkPoint}' ";
|
|
var dt = SqlHelper.CmdExecuteDataTable(tablesql);
|
|
|
|
if (dateRows == null || dateRows.Length <= 0)
|
|
{
|
|
msg = "库存不足,请先检查库存";
|
|
return msg;
|
|
}
|
|
else
|
|
{
|
|
string docCode = string.Empty;
|
|
string docCodeAfter = string.Empty;
|
|
LOTStockModel lOTStockModel = null;
|
|
|
|
// 使用 LINQ 根据 Code 字段对 DataRow[] 进行分组
|
|
var groups = dateRows.Cast<DataRow>().GroupBy(row => new
|
|
{
|
|
Code = row.Field<string>("Code"),
|
|
Sequence = row.Field<string>("Sequence"),
|
|
iQuantity = row.Field<string>("iQuantity")
|
|
});
|
|
//将捡料数据分组
|
|
foreach (var group in groups)
|
|
{
|
|
var firstRow = group.First();
|
|
var code = firstRow["Code"];
|
|
decimal count = 0.0M;
|
|
// 存储过程返回的条码 匹配到具体数据的ID
|
|
DataRow[] SDNSequenceRow = dt.Select("TransferNO='" + firstRow["Code"].ToString() + "' and Sequence='" + firstRow["Sequence"].ToString() + "'");
|
|
if (SDNSequenceRow.Length <= 0)
|
|
{
|
|
msg = "条码未能匹配销售发货表!";
|
|
return msg;
|
|
}
|
|
lOTStockModel = new LOTStockModel
|
|
{
|
|
TransID = SDNSequenceRow[0]["ID"].ToString(),
|
|
TransCode = firstRow["Code"].ToString(),
|
|
TransSequence = firstRow["Sequence"].ToString(),
|
|
TransType = "1",
|
|
//Amount = "0",
|
|
User = UserCode,
|
|
//Quantity = firstRow["iQuantity"].ToString(),
|
|
MTime = dateNow,
|
|
WorkPoint = WorkPoint,
|
|
Detail = new List<LOTStockModelList>(),
|
|
};
|
|
|
|
foreach (var row in group)
|
|
{
|
|
|
|
count += row["QTY"].ToDecimal();
|
|
LOTStockModelList lOTStockModelList = new LOTStockModelList
|
|
{
|
|
CurrentQuantity = row["QTY"].ToString(),
|
|
LotNo = row["LotNo"].ToString(),
|
|
// LocationCode = row["LocationCode"].ToString(),
|
|
LocationCode = LocationCode,
|
|
//WarehouseCode = row["WarehouseCode"].ToString(),
|
|
WarehouseCode = WarehouseCode.ToString(),
|
|
Quantity = firstRow["iQuantity"].ToString(),
|
|
Amount = "0",
|
|
//Sequence = row["Sequence"].ToString(),
|
|
//WarehouseCode = row["WarehouseCode"].ToString(),
|
|
//LocationCode = row["LocationCode"].ToString()
|
|
};
|
|
lOTStockModel.Detail.Add(lOTStockModelList);
|
|
}
|
|
lOTStockModel.Quantity = count.ToString();
|
|
lOTStockModels.Add(lOTStockModel);
|
|
}
|
|
|
|
string Inputstr = JsonConvert.SerializeObject(lOTStockModels);
|
|
|
|
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "TransferApplicationIn/Create";
|
|
string result = HttpPost(APIURL, Inputstr);
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
msg = ex.Message;
|
|
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
|
|
|
|
public DataTable GetGridJsonQiTa(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
object Figure = GetDecimalDigits();
|
|
#region [SQL]
|
|
string sql = @" select a.ID,a.InCode,a.Sequence,a.WHCode,a.InvCode, b.InvName,b.InvStd,b.InvDesc,b.InvUnit,
|
|
CAST(a.Quantity AS DECIMAL(38,{0})) as Quantity,CAST(a.Amount AS DECIMAL(38,{0})) as Amount, CAST(a.InQuantity AS DECIMAL(38,{0})) as InQuantity,a.CreatePerson,a.CreateDateTime,CAST(c.LOTQTY AS DECIMAL(38,{0})) as LOTQTY
|
|
,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,
|
|
Case when isnull(b.EffectiveEnable,0)='1' then '是' else '否' end as EffectiveEnable,
|
|
CAST( isnull(b.EffectiveDays,0) as DECIMAL(38,4)) as EffectiveDays ,Case when isnull(b.BatchEnable,0)='1' then '是' else '否' end as BatchEnable
|
|
from ICSOtherIn a
|
|
left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
|
|
left join (
|
|
select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
|
|
left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='5'
|
|
where isnull(ee.EATTRIBUTE1,'')=''
|
|
group by mm.TransCode,mm.TransSequence,ee.WorkPoint
|
|
)c
|
|
on a.InCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.Status='1' and ISNULL(a.Type,'1')='1' ";
|
|
sql = string.Format(sql, Figure);
|
|
|
|
#endregion
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sql += " and a.InCode like '%" + queryParam["POCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
|
|
{
|
|
sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
|
|
{
|
|
sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
|
|
{
|
|
sql += " and b.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POStatus"].ToString()))
|
|
{
|
|
string POStatus = queryParam["POStatus"].ToString();
|
|
if (POStatus == "0")
|
|
{
|
|
//sql += " and a.Quantity=ISNULL(c.LotQty,0)";
|
|
}
|
|
else if (POStatus == "1")
|
|
{
|
|
sql += " and a.Quantity-ISNULL(c.LOTQTY,0)=0";
|
|
}
|
|
else
|
|
{
|
|
sql += " and a.Quantity-ISNULL(c.LOTQTY,0)<>0";
|
|
}
|
|
}
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
|
|
{
|
|
sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
|
|
{
|
|
sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
|
|
}
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
public DataTable GetSubGridJson(string ApplyNegCode, string Sequence, string Type, string isPrint, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
object Figure = GetDecimalDigits();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string sql = @" select c.TransCode,c.TransSequence ,a.ID,a.LotNo, CAST( a.Quantity AS DECIMAL(38,{0})) as Quantity ,a.MUSERName,a.MTIME
|
|
,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,
|
|
case when isnull(d.ID,'')='' then '未入库' else '已入库' end as isStorage,
|
|
case when g.InvIQC='1'and isnull(e.ID,'')='' then '未检验' else '已检验' end as isInspection,
|
|
case when isnull(a.LastPrintUser,'')='' then '未打印' else '已打印' end as isPrint,
|
|
case when Isnull(g.InvIQC,'0')='1' then '否' else '是' end as isExemption,a.Amount,
|
|
convert(varchar(20),a.ProductDate,23) as ProductDate,convert(varchar(20),a.ExpirationDate,23) as ExpirationDate ,g.EffectiveDays,a.EATTRIBUTE4,a.EATTRIBUTE5
|
|
from ICSInventoryLot a
|
|
left join (select count(LotNo) LotNoCount,LotNo,WorkPoint from ICSWareHouseLotInfo
|
|
group by LotNo,WorkPoint)b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventoryLotDetail c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
left join dbo.ICSWareHouseLotInfo d on a.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint
|
|
left join ICSInspection e on a.LotNo=e.LotNo and e.Enable='1' and a.WorkPoint=e.WorkPoint
|
|
left join ICSInventory g on a.InvCode=g.InvCode and a.WorkPoint=g.WorkPoint
|
|
WHERE isnull(a.EATTRIBUTE1,'')='' and a.Type='" + Type + "' and c.TransCode='" + ApplyNegCode + "' and c.TransSequence='" + Sequence + "' and a.WorkPoint in ('" + WorkPoint + "')";
|
|
if (!string.IsNullOrWhiteSpace(isPrint))
|
|
{
|
|
if (isPrint == "0")
|
|
{
|
|
}
|
|
else if (isPrint == "1")
|
|
{
|
|
sql += " and isnull(LastPrintUser,'')<>''";
|
|
}
|
|
else
|
|
{
|
|
sql += " and isnull(LastPrintUser,'')=''";
|
|
}
|
|
}
|
|
|
|
sql = string.Format(sql, Figure);
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
|
|
public string SubmitFormQTALL(string keyValue, string Location)
|
|
{
|
|
List<Dictionary<string, object>> Info = new List<Dictionary<string, object>>();
|
|
string sql = string.Empty;
|
|
string msg = "";
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
JArray res = (JArray)JsonConvert.DeserializeObject(keyValue);
|
|
|
|
foreach (var resItem in res)
|
|
{
|
|
var InfoDeatil = new Dictionary<string, object>();
|
|
JObject jo = (JObject)resItem;
|
|
|
|
int createPageCount = Convert.ToInt32(jo["createPageCount"].ToString());
|
|
decimal minPackQty = Convert.ToDecimal(jo["minPackQty"].ToString());
|
|
decimal thisCreateQty = Convert.ToDecimal(jo["thisCreateQty"].ToString());
|
|
decimal LOTQTY = minPackQty;
|
|
string Pre = "QT" + jo["Code"].ToString() + (Convert.ToInt32(jo["Sequence"])).ToString("D4");
|
|
string PRODUCTDATE = jo["PRODUCTDATE"].ToString();
|
|
string sqls = string.Empty;
|
|
string Colspan = "";
|
|
string str1 = "";
|
|
List<string> ExtensionIDList = new List<string>();
|
|
for (int i = 0; i < createPageCount; i++)
|
|
{
|
|
if (i + 1 == createPageCount)
|
|
{
|
|
if (minPackQty * createPageCount > thisCreateQty)
|
|
{
|
|
LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
|
|
}
|
|
}
|
|
|
|
Colspan = jo["ProjectCode"].ToString() + "~" + jo["BatchCode"].ToString() + "~" + jo["Version"].ToString() + "~" + jo["Brand"].ToString() + "~" + jo["cFree1"].ToString() + "~" + jo["cFree2"].ToString() + "~" + jo["cFree3"].ToString() + "~" + jo["cFree4"].ToString() + "~" + jo["cFree5"].ToString() + "~" + jo["cFree6"].ToString() + "~" + jo["cFree7"].ToString() + "~" + jo["cFree8"].ToString() + "~" + jo["cFree9"].ToString() + "~" + jo["cFree10"].ToString();
|
|
sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoint);
|
|
object ExtensionID = SqlHelper.ExecuteScalar(sqls);
|
|
bool flag = true;
|
|
foreach (var item in ExtensionIDList)
|
|
{
|
|
if (item == Colspan + WorkPoint)
|
|
{
|
|
flag = false;
|
|
}
|
|
}
|
|
if (ExtensionID == null && flag == true)
|
|
{
|
|
str1 = Guid.NewGuid().ToString();
|
|
sql += string.Format(@"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
|
|
Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
|
|
str1, Colspan, jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(), jo["Brand"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(), jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(), jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(),
|
|
MUSER, MUSERNAME, WorkPoint);
|
|
}
|
|
else if (ExtensionID != null)
|
|
{
|
|
str1 = ExtensionID.ToString();
|
|
}
|
|
ExtensionIDList.Add(Colspan + WorkPoint);
|
|
|
|
string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
|
|
sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint,TransID)
|
|
Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' ,'{6}')",
|
|
LotNo, jo["Code"].ToString(), jo["Sequence"].ToString(), MUSER, MUSERNAME, WorkPoint, jo["ID"].ToString());
|
|
|
|
sql += string.Format(@"
|
|
insert into ICSInventoryLot
|
|
(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
|
|
select
|
|
newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','5','{3}','{4}', getdate(),'{5}','{9}'
|
|
from ICSOtherIn where InCode='{6}' and Sequence='{7}' and WorkPoint='{5}'",
|
|
LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoint, jo["Code"].ToString(), jo["Sequence"], str1, Convert.ToDecimal(jo["Amount"].ToString()) / minPackQty * LOTQTY, jo["ExpirationDate"].ToString());
|
|
sql += "\r\n";
|
|
InfoDeatil["LotNo"] = LotNo;
|
|
InfoDeatil["LOTQTY"] = LOTQTY;
|
|
Info.Add(InfoDeatil);
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
|
|
{
|
|
msg = CallWebApiByQT(Location, WorkPoint, Info);
|
|
}
|
|
else
|
|
{
|
|
msg = "批审失败";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
msg = ex.Message;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
|
|
|
|
public string CallWebApiByQT( string Location, string WorkPoint, List<Dictionary<string, object>> Info)
|
|
{
|
|
List<Dictionary<string, object>> detailList = new List<Dictionary<string, object>>();
|
|
foreach (var item in Info)
|
|
{
|
|
// 创建Detail项
|
|
var detailItem = new Dictionary<string, object>();
|
|
detailItem["LotNo"] = item["LotNo"].ToString();
|
|
detailItem["LocationCode"] = Location;
|
|
detailItem["Quantity"] = item["LOTQTY"].ToString();
|
|
// 将Detail项添加到集合中
|
|
detailList.Add(detailItem);
|
|
}
|
|
|
|
// 创建JSON参数
|
|
var parameters = new Dictionary<string, object>
|
|
{
|
|
{ "Workpoint", WorkPoint },
|
|
{ "User", NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode },
|
|
{ "TransType", "杂收" },
|
|
{ "MTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
|
|
{ "Detail", detailList }
|
|
};
|
|
// 序列化为JSON字符串
|
|
string Inputstr = JsonConvert.SerializeObject(parameters);
|
|
Inputstr = "[" + Inputstr + "]";
|
|
string msg = "";
|
|
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTStockUp/Create";
|
|
string result = HttpPost(APIURL, Inputstr);
|
|
JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
|
|
string MessAge = Obj["Message"].ToString();
|
|
string Success = Obj["Success"].ToString();
|
|
string ApiSql = string.Empty;
|
|
if (Success.ToUpper() == "FALSE")
|
|
{
|
|
foreach (var items in Info)
|
|
{
|
|
ApiSql += @"delete dbo.ICSInventoryLot where LotNo='" + items["LotNo"].ToString() + "' delete dbo.ICSInventoryLotDetail where LotNo='" + items["LotNo"].ToString() + "' ";
|
|
}
|
|
|
|
SqlHelper.CmdExecuteNonQueryLi(ApiSql);
|
|
msg = MessAge;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
|
|
|
|
public DataTable GetWHCodeByLocation(string LocationCode)
|
|
{
|
|
string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string sql = @"select a.WarehouseCode from dbo.ICSWarehouse a
|
|
left join dbo.ICSLocation b on a.ID=b.WHID and a.WorkPoint=b.WorkPoint
|
|
where b.LocationCode='"+ LocationCode + "' and a.WorkPoint='" + WorkPoints + "'";
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
return dt;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DataTable GetGridJsonChengPing(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
#region 海格自定义档案配置(MOSpecialInvClass),自定义档案中不配置这个编码可忽略
|
|
List<string> ClassCodeList = new List<string>();
|
|
string configsql = @"select B.F_ItemCode from Sys_SRM_Items A
|
|
INNER JOIN Sys_SRM_ItemsDetail B ON B.F_ItemId=A.F_Id
|
|
where F_EnCode='MOSpecialInvClass'";
|
|
DataTable configdt = SqlHelper.CmdExecuteDataTable(configsql);
|
|
foreach (DataRow dr in configdt.Rows)
|
|
{
|
|
ClassCodeList.Add(dr["F_ItemCode"].ToString());
|
|
}
|
|
#endregion
|
|
DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
object Figure = GetDecimalDigits();
|
|
|
|
#region [SQL]
|
|
string sql = @" select distinct a.ID, a.MODetailID,a.MOCode,a.Sequence,
|
|
CAST(a.RCVQuantity AS DECIMAL(38,{0})) as RCVQuantity ,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,
|
|
CAST( a.Quantity AS DECIMAL(38,{0})) as Quantity,CAST( a.Amount as DECIMAL(38,{0})) as Amount,a.StartDate,a.WHCode,warehouse.WarehouseName as WHName
|
|
,a.DueDate,a.MOStatus,a.ExtensionID,a.MUSERName,a.MTIME ,
|
|
CAST(c.LOTQTY AS DECIMAL(38,{0})) as LOTQTY ,
|
|
CAST( a.Quantity AS DECIMAL(38,{0})) -CAST(a.RCVQuantity AS DECIMAL(38,{0})) as ERPNum,CAST((a.Quantity-ISnull(a.RCVQuantity,0)) AS DECIMAL(38,{0})) as NRCVQuantity,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,a.EATTRIBUTE11,a.EATTRIBUTE12,b.MTIME as TMTime,dep.DepName,a.CreateDateTime,b.EATTRIBUTE1 as ICSInventoryEATTRIBUTE1 ,b.EATTRIBUTE2 as ICSInventoryEATTRIBUTE2,b.EATTRIBUTE3 as ICSInventoryEATTRIBUTE3,b.EATTRIBUTE4 as ICSInventoryEATTRIBUTE4,b.EATTRIBUTE5 as ICSInventoryEATTRIBUTE5,b.EATTRIBUTE6 as ICSInventoryEATTRIBUTE6,b.EATTRIBUTE7 as ICSInventoryEATTRIBUTE7,b.EATTRIBUTE8 as ICSInventoryEATTRIBUTE8,
|
|
b.EATTRIBUTE9 as ICSInventoryEATTRIBUTE9,b.EATTRIBUTE10 as ICSInventoryEATTRIBUTE10
|
|
from ICSMO a
|
|
left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
|
|
left join (
|
|
select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint 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
|
|
)c
|
|
on a.MOCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
left join ICSDepartment dep ON dep.DepCode=a.DepCode and a.WorkPoint=dep.WorkPoint
|
|
left join ICSWarehouse warehouse on a.WHCode=warehouse.WarehouseCode and a.WorkPoint=warehouse.WorkPoint ";
|
|
sql += " WHERE 1=1 and a.MOStatus<>'3' ";
|
|
foreach (string ClassCode in ClassCodeList)
|
|
{
|
|
sql += " AND (b.ClassCode Not like '" + ClassCode + "%' OR b.ClassCode='P01005')";
|
|
}
|
|
sql = string.Format(sql, Figure);
|
|
|
|
#endregion
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
|
|
{
|
|
sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
|
|
{
|
|
sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["SelGDLX"].ToString()))
|
|
{
|
|
sql += " and a.MOType like '%" + queryParam["SelGDLX"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
|
|
{
|
|
sql += " and b.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["FromTime"].ToString()))
|
|
{
|
|
sql += " and a.StartDate >= '" + queryParam["FromTime"].ToString() + "' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["ToTime"].ToString()))
|
|
{
|
|
sql += " and a.StartDate <= '" + queryParam["ToTime"].ToString() + "' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
|
|
}
|
|
JToken chkParentMO = false;
|
|
if (queryParam.TryGetValue("ParentMo", out chkParentMO) && chkParentMO != null)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["ParentMo"].ToString()))
|
|
{
|
|
sql += " and a.EATTRIBUTE5 like '%" + queryParam["ParentMo"].ToString() + "%' ";
|
|
}
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POStatus"].ToString()))
|
|
{
|
|
string POStatus = queryParam["POStatus"].ToString();
|
|
if (POStatus == "0")
|
|
{
|
|
//sql += " and a.Quantity=ISNULL(c.LotQty,0)";
|
|
}
|
|
else if (POStatus == "1")
|
|
{
|
|
sql += " and a.Quantity-ISNULL(c.LOTQTY,0)=0";
|
|
}
|
|
else
|
|
{
|
|
sql += " and a.Quantity-ISNULL(c.LOTQTY,0)>0";
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHStatus"].ToString()))
|
|
{
|
|
string WHStatus = queryParam["WHStatus"].ToString();
|
|
if (WHStatus == "0")
|
|
{
|
|
//sql += " and a.Quantity=ISNULL(c.LotQty,0)";
|
|
}
|
|
else if (WHStatus == "1")
|
|
{
|
|
sql += " and a.Quantity-ISNULL(a.RCVQuantity,0)>0 ";
|
|
}
|
|
else
|
|
{
|
|
sql += " and a.Quantity-ISNULL(a.RCVQuantity,0)=0 ";
|
|
}
|
|
}
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
|
|
{
|
|
sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
|
|
{
|
|
sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
|
|
}
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
}
|
|
}
|