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.
4022 lines
218 KiB
4022 lines
218 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 NFine.Domain._03_Entity.WMS;
|
|
using System.Data.SqlTypes;
|
|
|
|
namespace NFine.Application.WMS
|
|
{
|
|
public class PickMaterialApp : RepositoryFactory<ICSVendor>
|
|
{
|
|
public static DataTable Invmes = new DataTable();
|
|
//工单备料(工单子件)
|
|
public DataTable GetGridJson(string queryJson, 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>();
|
|
StringBuilder sqlstring = new StringBuilder();
|
|
#region [SQL]
|
|
|
|
// sql = @"select a.ID,b.MOCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,c.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
//case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
//from ICSMOPick a
|
|
//left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
|
|
//left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
|
|
//left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
//left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
|
|
// sql += " WHERE 1=1 and e.ID is null";
|
|
|
|
sqlstring.Append($@"select a.MOCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,
|
|
case when max(d.SourceID) is null then '未合并' else '已合并' end as IsNew,
|
|
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 ICSMO a
|
|
inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
|
|
left join ICSMOPickMerge d on d.SourceID=b.ID and d.WorkPoint=b.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.WorkPoint='{WorkPoint}' ");
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlstring.Append($" and a.MOCode like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlstring.Append($" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
}
|
|
|
|
sqlstring.Append(@" group by a.MOCode, a.WorkPoint,a.CreateDateTime,a.createperson,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");
|
|
|
|
#endregion
|
|
return Repository().FindTablePageBySql(sqlstring.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//工单备料(工单子件)子表查询
|
|
public DataTable GetSubGridJson1(string Code)
|
|
{
|
|
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 a.ID,b.MOCode as Code,a.Sequence+'-'+b.Sequence AS Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,c.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
,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.IssueQuantity as IssueQuantity
|
|
|
|
from ICSMOPick a
|
|
left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
|
|
left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where b.MOCode='{0}' and a.WorkPoint='{1}'";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
return Repository().FindTableBySql(sql.ToString());
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//工单领料(发料申请)
|
|
public DataTable GetGridJson2(string queryJson, 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>();
|
|
StringBuilder sqlString = new StringBuilder();
|
|
#region [SQL]
|
|
// select a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
//case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
// from ICSMOApply a
|
|
|
|
// left join ICSWarehouse b on a.WHCode = b.WarehouseCode and a.WorkPoint = b.WorkPoint
|
|
|
|
// left join ICSInventory d on a.InvCode = d.InvCode and a.WorkPoint = d.WorkPoint
|
|
|
|
// left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
|
|
|
|
sqlString.Append($@"
|
|
SELECT * from(select row_number() over(partition by a.ApplyCode ORDER BY a.ApplyCode) as row,
|
|
|
|
a.ApplyCode as Code,CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,a.createperson as MUSER,a.WHCode,detail.LocationCode AS Area,
|
|
a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
|
|
a.ReceiverNumber,case when a.MUSERName = 'JOB' then a.ReceiverName else a.MUSERName end as ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.Unit,a.StockIndicator,
|
|
case when max(e.SourceID) is null then '未合并' else '已合并' end as IsNew,f.Colspan ,
|
|
g.Status, ISNULL(p.PrintCount, 0) as PrintCount,
|
|
case when max(k.TransCode) is null then '未占料' else '已占料' end as IsOccupy,
|
|
--case when sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName != 'JOB' then '已过账'
|
|
--else (case when sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName = 'JOB' then '已配料' else '未配料' end) end as Status,
|
|
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 a.MUSER!= 'JOB' then a.MUSER else '' end AS PickName
|
|
from ICSMOApply a
|
|
left JOIN ICSInventory b ON b.InvCode=a.InvCode
|
|
LEFT JOIN ICSPrintCount p ON a.APPlyCode=p.TransCode
|
|
LEFT JOIN ICSInventoryDetail detail ON b.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
--left join Sys_SRM_User n ON n.F_Account=a.MUSERName
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
left join (SELECT ApplyCode,
|
|
case when sum(Quantity) =sum(IssueQuantity) and MUSERName != 'JOB' then '已过账'
|
|
else (case when sum(Quantity) =sum(IssueQuantity) and MUSERName = 'JOB' AND sum(IssueQuantity)>0 then '已配料'
|
|
else '未配料' end) end as Status
|
|
from ICSMOApply where WorkPoint='{WorkPoint}' and EATTRIBUTE!='17' group by ApplyCode,MUSERName) g on a.ApplyCode = g.ApplyCode
|
|
left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.ApplyCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
|
|
left join Sys_SRM_ItemsDetail j on j.F_Define3='HGAreaConfig' AND j.F_Define1=a.WHCode AND j.F_Define4=a.WorkPoint and detail.LocationCode = j.F_Define2
|
|
where a.WorkPoint='{WorkPoint}' and a.EATTRIBUTE!='17'");
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.OrderNumber like '%{queryParam["Order"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
{
|
|
sqlString.Append($@" and (j.F_Id is null OR detail.LocationCode is null OR detail.LocationCode='') ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.CreateDateTime >='{queryParam["CreateDate"].ToDate()}' and a.CreateDateTime <'{queryParam["CreateDate"].ToDate().AddDays(+1)}' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
|
|
{
|
|
sqlString.Append($@" and b.InvName like '%{queryParam["InvName"]}%' ");
|
|
}
|
|
}
|
|
sqlString.Append(@"group by a.ApplyCode, a.WorkPoint,a.CreateDateTime,a.createperson,
|
|
|
|
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,g.Status,
|
|
|
|
a.WHCode,detail.LocationCode,a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
|
|
a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.Unit,a.StockIndicator,a.MUSERName,a.MUSER,p.PrintCount) as t where t.row=1");
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
|
|
{
|
|
if (queryParam["Status"].ToString() == "3")
|
|
{
|
|
sqlString.Append($@" AND t.Status='已过账' ");
|
|
}
|
|
else if (queryParam["Status"].ToString() == "2")
|
|
{
|
|
sqlString.Append($@" AND t.Status='已配料' ");
|
|
}
|
|
else if (queryParam["Status"].ToString() == "1")
|
|
{
|
|
sqlString.Append($@" AND t.Status='未配料' ");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//工单领料(发料申请)子表查询
|
|
public DataTable GetSubGridJson2(string queryJson, string Code, 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 * FROM (select row_number() over(partition by a.ApplyCode,a.InvCode,a.Sequence ORDER BY a.ApplyCode) as row,
|
|
a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,a.OrderNumber,
|
|
a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
|
|
a.ReceiverNumber,case when a.MUSERName = 'JOB' then a.ReceiverName else a.MUSERName end as ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
|
|
d.InvName,d.InvDesc,d.InvStd,d.InvUnit,detail.LocationCode AS Area,a.SAPSequence,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
,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.IssueQuantity as IssueQuantity
|
|
from ICSMOApply a
|
|
left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.ApplyCode='{0}' and a.WorkPoint='{1}' and a.EATTRIBUTE!='17'";
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
|
|
{
|
|
sql += $@" and a.OrderNumber like '%{queryParam["Order"]}%' ";
|
|
}
|
|
//if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
//{
|
|
// sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
// WHERE
|
|
// F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
|
|
//}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
|
|
{
|
|
sql += $@" and a.CreateDateTime >='{queryParam["CreateDate"].ToDate()}' and a.CreateDateTime <'{queryParam["CreateDate"].ToDate().AddDays(+1)}' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
|
|
{
|
|
sql += $@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ";
|
|
}
|
|
}
|
|
sql += " ) c WHERE c.row=1 ";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
//return Repository().FindTableBySql(sql.ToString());
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//售后领料
|
|
public DataTable GetGridJson12(string queryJson, 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>();
|
|
StringBuilder sqlString = new StringBuilder();
|
|
#region [SQL]
|
|
// select a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
//case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
// from ICSMOApply a
|
|
|
|
// left join ICSWarehouse b on a.WHCode = b.WarehouseCode and a.WorkPoint = b.WorkPoint
|
|
|
|
// left join ICSInventory d on a.InvCode = d.InvCode and a.WorkPoint = d.WorkPoint
|
|
|
|
// left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
|
|
|
|
sqlString.Append($@"
|
|
SELECT * from(select row_number() over(partition by a.ApplyCode ORDER BY a.ApplyCode) as row,
|
|
|
|
a.ApplyCode as Code,CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,a.createperson as MUSER,a.WHCode,detail.LocationCode AS Area,
|
|
a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
|
|
a.ReceiverNumber,case when a.MUSERName = 'JOB' then a.ReceiverName else a.MUSERName end as ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.Unit,a.StockIndicator,
|
|
case when max(e.SourceID) is null then '未合并' else '已合并' end as IsNew,f.Colspan,a.CustomerName,a.Pagination,
|
|
g.Status,ISNULL(p.PrintCount, 0) as PrintCount,
|
|
case when max(k.TransCode) is null then '未占料' else '已占料' end as IsOccupy,
|
|
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 a.MUSER!= 'JOB' then a.MUSER else '' end AS PickName
|
|
from ICSMOApply a
|
|
left JOIN ICSInventory b ON b.InvCode=a.InvCode
|
|
LEFT JOIN ICSPrintCount p ON a.APPlyCode=p.TransCode
|
|
LEFT JOIN ICSInventoryDetail detail ON b.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join (SELECT ApplyCode,
|
|
case when sum(Quantity) =sum(IssueQuantity) and MUSERName != 'JOB' then '已过账'
|
|
else (case when sum(Quantity) =sum(IssueQuantity) and MUSERName = 'JOB'AND sum(IssueQuantity)>0 then '已配料'
|
|
else '未配料' end) end as Status
|
|
from ICSMOApply where WorkPoint='{WorkPoint}' and EATTRIBUTE='17' group by ApplyCode,MUSERName) g on a.ApplyCode = g.ApplyCode
|
|
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.ApplyCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
|
|
where a.WorkPoint='{WorkPoint}' and a.EATTRIBUTE='17' ");
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.OrderNumber like '%{queryParam["Order"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
{
|
|
sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
WHERE
|
|
F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.CreateDateTime >='{queryParam["CreateDate"].ToDate()}' and a.CreateDateTime <'{queryParam["CreateDate"].ToDate().AddDays(+1)}' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
|
|
{
|
|
sqlString.Append($@" and b.InvName like '%{queryParam["InvName"]}%' ");
|
|
}
|
|
}
|
|
sqlString.Append(@"group by a.ApplyCode, a.WorkPoint,a.CreateDateTime,a.createperson,
|
|
|
|
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,g.Status,
|
|
|
|
a.WHCode,detail.LocationCode,a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
|
|
a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.Unit,a.StockIndicator,a.MUSERName,a.MUSER,p.PrintCount,a.CustomerName,a.Pagination) as t where t.row=1");
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
|
|
{
|
|
if (queryParam["Status"].ToString() == "3")
|
|
{
|
|
sqlString.Append($@" AND t.Status='已过账' ");
|
|
}
|
|
else if (queryParam["Status"].ToString() == "2")
|
|
{
|
|
sqlString.Append($@" AND t.Status='已配料' ");
|
|
}
|
|
else if (queryParam["Status"].ToString() == "1")
|
|
{
|
|
sqlString.Append($@" AND t.Status='未配料' ");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//售后领料(子表查询)
|
|
public DataTable GetSubGridJson12(string queryJson, string Code)
|
|
{
|
|
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 * FROM (select row_number() over(partition by a.ApplyCode,a.InvCode,a.Sequence ORDER BY a.ApplyCode) as row,
|
|
a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,a.OrderNumber,
|
|
a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
|
|
a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
|
|
d.InvName,d.InvDesc,d.InvStd,d.InvUnit,detail.LocationCode AS Area,a.SAPSequence,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
,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.IssueQuantity as IssueQuantity
|
|
from ICSMOApply a
|
|
left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.ApplyCode='{0}' and a.WorkPoint='{1}' and a.EATTRIBUTE='17'";
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
|
|
{
|
|
sql += $@" and a.OrderNumber like '%{queryParam["Order"]}%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
{
|
|
sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
WHERE
|
|
F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
|
|
{
|
|
sql += $@" and a.CreateDateTime like '%{queryParam["CreateDate"]}%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
|
|
{
|
|
sql += $@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ";
|
|
}
|
|
}
|
|
sql += " ) c WHERE c.row=1 ";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
return Repository().FindTableBySql(sql.ToString());
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//工单材料出库(材料出库)
|
|
public DataTable GetGridJson3(string queryJson, 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>();
|
|
StringBuilder sqlString = new StringBuilder();
|
|
#region [SQL]
|
|
// sql = @"select a.ID,a.IssueCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode ,b.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
// case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
// from ICSMOIssue a
|
|
//left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
//left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
//left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint ";
|
|
// sql += " WHERE 1=1 and e.ID is null";
|
|
sqlString.Append($@"SELECT * FROM(SELECT row_number ( ) OVER ( partition BY a.IssueCode ORDER BY a.IssueCode ) AS row,
|
|
a.IssueCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,
|
|
case when max(e.SourceID) is null then '未合并' else '已合并'
|
|
end as IsNew,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 ICSMOIssue a
|
|
left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
|
|
where a.WorkPoint = '{WorkPoint}' ");
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.IssueCode like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
}
|
|
sqlString.Append(@"group by a.IssueCode,a.CreateDateTime,a.createperson,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 ) AS t WHERE t.row= 1 ");
|
|
#endregion
|
|
|
|
|
|
|
|
return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//工单材料出库(材料出库)子表查询
|
|
public DataTable GetSubGridJson3(string Code)
|
|
{
|
|
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 a.ID,a.IssueCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode ,b.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
,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.IssueQuantity as IssueQuantity
|
|
from ICSMOIssue a
|
|
left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.IssueCode='{0}' and a.WorkPoint='{1}'";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
return Repository().FindTableBySql(sql.ToString());
|
|
}
|
|
|
|
|
|
|
|
//委外备料(委外备料)
|
|
public DataTable GetGridJson4(string queryJson, 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>();
|
|
StringBuilder sqlString = new StringBuilder();
|
|
#region [SQL]
|
|
sqlString.Append($@"select * from (select row_number() over(partition by b.OOCode order by b.OOCode) row, b.OOCode as Code,
|
|
b.CreateDateTime as MTIME,
|
|
b.CreatePerson as MUSER,
|
|
case
|
|
when max(e.SourceID) is null then '未合并'
|
|
else '已合并'
|
|
end as IsNew,
|
|
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 ICSOOPick a
|
|
inner join ICSOutsourcingOrder b on a.OODetailID = b.OODetailID and a.WorkPoint = b.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
|
|
WHERE b.WorkPoint = '{WorkPoint}' ");
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.OOCode like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
}
|
|
sqlString.Append(@" group by b.OOCode,b.CreateDateTime,b.CreatePerson,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) t where t.row=1");
|
|
|
|
#endregion
|
|
|
|
return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//委外备料(委外备料)子表查询
|
|
public DataTable GetSubGridJson4(string Code)
|
|
{
|
|
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 a.ID,b.OOCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,c.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
,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.IssueQuantity as IssueQuantity
|
|
from ICSOOPick a
|
|
left join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint
|
|
left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where b.OOCode='{0}' and b.WorkPoint='{1}'";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
return Repository().FindTableBySql(sql.ToString());
|
|
}
|
|
|
|
|
|
//委外领料(委外发料申请)
|
|
public DataTable GetGridJson5(string queryJson, 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>();
|
|
StringBuilder sqlString = new StringBuilder();
|
|
#region [SQL]
|
|
// sql = @"select a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
//case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
// from ICSOApply a
|
|
//left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
//left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
//left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
|
|
// sql += " WHERE 1=1 and e.ID is null";
|
|
sqlString.Append($@"select * from (select row_number() over (partition by a.ApplyCode order by a.ApplyCode ) row, a.ApplyCode as Code,CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,a.CreatePerson as MUSER,
|
|
case when max(e.SourceID) is null then '未合并'
|
|
else '已合并'
|
|
end as IsNew,
|
|
case when max(k.TransCode) is null then '未占料' else '已占料' end as IsOccupy,
|
|
g.Status as Status1,ISNULL(p.PrintCount, 0) as PrintCount,
|
|
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.ID,
|
|
case when a.MUSER!= 'JOB' then a.MUSER else '' end AS PickName
|
|
from ICSOApply a
|
|
left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
|
|
LEFT JOIN ICSPrintCount p ON a.APPlyCode=p.TransCode
|
|
left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
|
|
left join (SELECT ApplyCode,
|
|
case when sum(Quantity) =sum(IssueQuantity) AND sum(IssueQuantity)>0 then '已过账'
|
|
|
|
else '未过账' end as Status
|
|
from ICSOApply
|
|
where WorkPoint='{WorkPoint}'
|
|
group by ApplyCode) g on a.ApplyCode = g.ApplyCode
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.ApplyCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
|
|
where a.WorkPoint = '{WorkPoint}'");
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
{
|
|
sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
WHERE
|
|
F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
|
|
{
|
|
sqlString.Append($@" and d.InvName like '%{queryParam["InvName"]}%' ");
|
|
}
|
|
|
|
}
|
|
sqlString.Append(@"group by a.ApplyCode,a.CreateDateTime,a.CreatePerson,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.ID,g.Status,p.PrintCount,a.MUSER ) t where row=1");
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Status1"].ToString()))
|
|
{
|
|
if (queryParam["Status1"].ToString() == "1")
|
|
{
|
|
sqlString.Append($@" AND t.Status1='已过账' ");
|
|
}
|
|
else
|
|
{
|
|
sqlString.Append($@" AND t.Status1='未过账' ");
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//委外领料(委外发料申请)子表查询
|
|
public DataTable GetSubGridJson5(string Code, string queryJson, 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 * FROM (select row_number() over(partition by a.ApplyCode,a.InvCode,a.Sequence ORDER BY a.ApplyCode) as row,
|
|
a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode, a.SourceCode,a.SourceSequence,a.VenCode,a.VenName,
|
|
b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,a.SAPSequence,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity,detail.LocationCode AS Area,
|
|
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.IssueQuantity as IssueQuantity
|
|
from ICSOApply a
|
|
left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.ApplyCode='{0}' and a.WorkPoint='{1}'";
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
{
|
|
sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
WHERE
|
|
F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
|
|
}
|
|
}
|
|
sql += " ) c WHERE c.row=1 ";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
//return Repository().FindTableBySql(sql.ToString());
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//委外材料出库(委外发料申请)
|
|
public DataTable GetGridJson6(string queryJson, 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>();
|
|
StringBuilder sqlString = new StringBuilder();
|
|
#region [SQL]
|
|
// sql = @"select a.ID,a.IssueCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseCode,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
//case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
// from ICSOIssue a
|
|
//left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
//left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
//left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
|
|
// sql += " WHERE 1=1 and e.ID is null";
|
|
sqlString.Append($@"select * from(select row_number() over(partition by a.IssueCode order by a.IssueCode) row, a.IssueCode as Code,
|
|
a.CreateDateTime as MTIME,
|
|
a.CreatePerson as MUSER,
|
|
case
|
|
when max(e.SourceID) is null then '未合并'
|
|
else '已合并'
|
|
end as IsNew,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 ICSOIssue a
|
|
left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
|
|
where a.WorkPoint = '{WorkPoint}'");
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.IssueCode like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
}
|
|
sqlString.Append(@"group by a.IssueCode,a.CreateDateTime,a.CreatePerson,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) t where t.row=1");
|
|
|
|
#endregion
|
|
|
|
|
|
return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
|
|
//委外材料出库(委外发料申请)子表查询
|
|
public DataTable GetSubGridJson6(string Code)
|
|
{
|
|
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 a.ID,a.IssueCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseCode,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
,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.IssueQuantity as IssueQuantity
|
|
from ICSOIssue a
|
|
left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.IssueCode='{0}' and a.WorkPoint='{1}'";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
return Repository().FindTableBySql(sql.ToString());
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//销售发货(销售发货)
|
|
public DataTable GetGridJson7(string queryJson, 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>();
|
|
StringBuilder sqlString = new StringBuilder();
|
|
#region [SQL]
|
|
// sql = @"select a.ID,a.SDNCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
//case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
// from ICSSDN a
|
|
//left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
//left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
//left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
|
|
// sql += " WHERE 1=1 and a.Type='1' and e.ID is null";
|
|
sqlString.Append($@"SELECT * from (SELECT Row_Number() over(partition by a.SDNCode Order by a.SDNCode) as r, a.SDNCode AS Code,
|
|
CONVERT(varchar(100),a.CreateDateTime,23) AS MTIME,
|
|
a.CreatePerson AS MUSER,
|
|
a.CusCode,a.CusName,ISNULL(p.PrintCount, 0) as PrintCount,
|
|
(CASE WHEN max(e.SourceID) IS NULL THEN '未合并' ELSE '已合并' END) AS IsNew,
|
|
case when max(k.TransCode) is null then '未占料' else '已占料' end as IsOccupy,g.Status as Status1,
|
|
|
|
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.ID
|
|
FROM ICSSDN a
|
|
LEFT JOIN ICSPrintCount p ON a.SDNCode=p.TransCode
|
|
left join (SELECT SDNCode,case when sum(Quantity) =sum(SDNQuantity) AND sum(SDNQuantity)>0 then '已过账' else '未过账' end as Status
|
|
from ICSSDN where WorkPoint='{WorkPoint}' group by SDNCode) g on a.SDNCode = g.SDNCode
|
|
LEFT JOIN ICSMOPickMerge e ON a.ID = e.SourceID AND a.WorkPoint = e.WorkPoint
|
|
LEFT JOIN ICSExtension f ON a.ExtensionID = f.ID AND a.WorkPoint = f.WorkPoint
|
|
LEFT JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.SDNCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
|
|
WHERE a.WorkPoint = '{WorkPoint}' ");
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlString.Append($" and a.SDNCode like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlString.Append($" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["CusCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.CusCode like '%{queryParam["CusCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["CusName"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.CusName like '%{queryParam["CusName"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
{
|
|
sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
WHERE
|
|
F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
|
|
{
|
|
sqlString.Append($@" and d.InvName like '%{queryParam["InvName"]}%' ");
|
|
}
|
|
|
|
}
|
|
sqlString.Append(@"GROUP BY a.SDNCode, a.CreateDateTime, a.CreatePerson, 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.ID,a.CusCode,a.CusName,p.PrintCount,g.Status) t WHERE t.r=1");
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Status1"].ToString()))
|
|
{
|
|
if (queryParam["Status1"].ToString() == "1")
|
|
{
|
|
sqlString.Append($@" AND t.Status1='已过账' ");
|
|
}
|
|
else
|
|
{
|
|
sqlString.Append($@" AND t.Status1='未过账' ");
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//销售发货(销售发货)子表查询
|
|
public DataTable GetSubGridJson7(string Code, string queryJson, 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 * FROM (select row_number() over(partition by a.SDNCode,a.InvCode,a.Sequence ORDER BY a.SDNCode) as row,
|
|
a.ID,a.SDNCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode
|
|
,a.WorkPoint,a.Points,a.DeliveryType,a.DeliveryDescribe,a.InvDescribe,a.OtherDescribe,a.CusCode,a.CusName,
|
|
a.SalesUnit,a.StockIndicator,a.IsSerialNumber,a.SAPSequence,
|
|
d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity,detail.LocationCode AS Area
|
|
,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.SDNQuantity as IssueQuantity
|
|
from ICSSDN a
|
|
left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.SDNCode='{0}' and a.WorkPoint='{1}'";
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["CusCode"].ToString()))
|
|
{
|
|
sql += $@" and a.CusCode like '%{queryParam["CusCode"]}%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["CusName"].ToString()))
|
|
{
|
|
sql += $@" and a.CusName like '%{queryParam["CusName"]}%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
{
|
|
sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
WHERE
|
|
F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
|
|
}
|
|
}
|
|
sql += " ) c WHERE c.row=1 ";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
//return Repository().FindTableBySql(sql.ToString());
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
|
|
|
|
//其它出库(其它出库)
|
|
public DataTable GetGridJson8(string queryJson, 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>();
|
|
StringBuilder sqlString = new StringBuilder();
|
|
#region [SQL]
|
|
// sql = @"select a.ID,a.OutCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
//case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
//from ICSOtherOut a
|
|
//left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
//left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
//left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
|
|
// sql += " WHERE 1=1 and e.ID is null ";
|
|
sqlString.Append($@"select * from(select row_number() over(partition by a.OutCode order by a.OutCode) row, a.OutCode as Code,
|
|
CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,
|
|
a.CreatePerson as MUSER,
|
|
case
|
|
when max(e.SourceID) is null then '未合并'
|
|
else '已合并'
|
|
end as IsNew,
|
|
case when max(k.TransCode) is null then '未占料' else '已占料' end as IsOccupy,
|
|
g.Status as Status1,ISNULL(p.PrintCount, 0) as PrintCount,
|
|
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.ID,a.EATTRIBUTE1
|
|
from ICSOtherOut a
|
|
LEFT JOIN ICSPrintCount p ON a.OutCode=p.TransCode
|
|
left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
|
|
left join (SELECT OutCode,case when sum(Quantity) =sum(OutQuantity) AND sum(OutQuantity)>0 then '已过账' else '未过账' end as Status
|
|
from ICSOtherOut where WorkPoint='{WorkPoint}' group by OutCode) g on a.OutCode = g.OutCode
|
|
left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.OutCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
|
|
where a.WorkPoint = '{WorkPoint}'");
|
|
#endregion
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.OutCode like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
{
|
|
sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
WHERE
|
|
F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
|
|
{
|
|
sqlString.Append($@" and d.InvName like '%{queryParam["InvName"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["EATTRIBUTE1"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.EATTRIBUTE1 like '%{queryParam["EATTRIBUTE1"]}%' ");
|
|
}
|
|
}
|
|
sqlString.Append(@" group by a.OutCode,a.CreateDateTime,a.CreatePerson,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.ID,g.Status,p.PrintCount,a.EATTRIBUTE1) t where t.row=1");
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Status1"].ToString()))
|
|
{
|
|
if (queryParam["Status1"].ToString() == "1")
|
|
{
|
|
sqlString.Append($@" AND t.Status1='已过账' ");
|
|
}
|
|
else
|
|
{
|
|
sqlString.Append($@" AND t.Status1='未过账' ");
|
|
}
|
|
|
|
}
|
|
|
|
return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//其它出库(其它出库)子表查询
|
|
public DataTable GetSubGridJson8(string Code, string queryJson, 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 * FROM (select row_number() over(partition by a.OutCode,a.InvCode,a.Sequence ORDER BY a.OutCode) as row,
|
|
a.ID,a.OutCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.Quantity,
|
|
a.InvCode,a.WorkPoint,a.OrderType, a.TypeDescribe,a.CostCenter,a.Remarks,a.PersonNumber,a.InvDescribe,
|
|
a.Unit,a.StockIndicator,a.SAPSequence,
|
|
d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,detail.LocationCode AS Area
|
|
,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.OutQuantity as IssueQuantity
|
|
from ICSOtherOut a
|
|
left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.OutCode='{0}' and a.WorkPoint='{1}'";
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
{
|
|
sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
WHERE
|
|
F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
|
|
}
|
|
}
|
|
sql += " ) c WHERE c.row=1 ";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
return Repository().FindTableBySql(sql.ToString());
|
|
}
|
|
|
|
|
|
|
|
//借用(借用)
|
|
public DataTable GetGridJson9(string queryJson, 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>();
|
|
StringBuilder sqlString = new StringBuilder();
|
|
#region [SQL]
|
|
// sql = @"
|
|
//select a.ID,a.BrrowCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
// case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
// from ICSBrrow a
|
|
// left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
// left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
// left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
|
|
// sql += " WHERE 1=1 and e.ID is null ";
|
|
sqlString.Append($@"select * from(select row_number() over(partition by a.BrrowCode order by a.BrrowCode) row, a.BrrowCode as Code,
|
|
a.CreateDateTime as MTIME,
|
|
a.CreatePerson as MUSER,
|
|
case
|
|
when max(e.SourceID) is null then '未合并'
|
|
else '已合并'
|
|
end as IsNew,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 ICSBrrow a
|
|
left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
|
|
where a.WorkPoint = '{WorkPoint}'");
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.BrrowCode like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
}
|
|
sqlString.Append(@"group by a.BrrowCode,a.CreateDateTime,a.CreatePerson,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) t where t.row=1");
|
|
#endregion
|
|
|
|
return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//借用(借用)子表查询
|
|
public DataTable GetSubGridJson9(string Code)
|
|
{
|
|
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 a.ID,a.BrrowCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
,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.BrrowQuantity as IssueQuantity
|
|
from ICSBrrow a
|
|
left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.BrrowCode='{0}' and a.WorkPoint='{1}'";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
return Repository().FindTableBySql(sql.ToString());
|
|
}
|
|
|
|
//物料调拨
|
|
public DataTable GetGridJson10(string queryJson, 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>();
|
|
StringBuilder sqlString = new StringBuilder();
|
|
#region [SQL]
|
|
// sql = @"
|
|
//select a.ID,a.BrrowCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
// case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
// from ICSBrrow a
|
|
// left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
// left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
// left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
|
|
// sql += " WHERE 1=1 and e.ID is null ";
|
|
sqlString.Append($@"select * from (select row_number() over(partition by a.TransferNO order by a.TransferNO) row,
|
|
a.TransferNO as Code,a.ID,CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,a.CreatePerson as MUSER,
|
|
g.Status as Status1,ISNULL(p.PrintCount, 0) as PrintCount,
|
|
f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
|
|
case when max(k.TransCode) is null then '未占料' else '已占料' end as IsOccupy,
|
|
f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,
|
|
case when a.MUSER!= 'JOB' then a.MUSER else '' end AS PickName
|
|
from ICSTransfer a
|
|
LEFT JOIN ICSPrintCount p ON a.TransferNO=p.TransCode
|
|
left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
|
|
left join (SELECT TransferNO,case when sum(Quantity) =sum(TransferQuantity) AND sum(TransferQuantity)>0 then '已过账' else '未过账' end as Status
|
|
from ICSTransfer where WorkPoint='{WorkPoint}' group by TransferNO) g on a.TransferNO = g.TransferNO
|
|
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.FromWarehouseCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.TransferNO=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
|
|
where a.WorkPoint = '{WorkPoint}' and a.Status = '2'");
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.TransferNO like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.ToWarehouseCode like '%{queryParam["WHCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
{
|
|
sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
WHERE
|
|
F_Define3='HGAreaConfig' AND F_Define1=a.FromWarehouseCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
|
|
{
|
|
sqlString.Append($@" and d.InvName like '%{queryParam["InvName"]}%' ");
|
|
}
|
|
}
|
|
sqlString.Append(@"group by a.TransferNO,a.CreateDateTime,a.CreatePerson,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.ID,a.TransferQuantity,g.Status,p.PrintCount,a.MUSER) t where t.row=1");
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
|
|
{
|
|
if (queryParam["Status1"].ToString() == "1")
|
|
{
|
|
sqlString.Append($@" AND t.Status1='已过账' ");
|
|
}
|
|
else
|
|
{
|
|
sqlString.Append($@" AND t.Status1='未过账' ");
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
//物料调拨子表查询
|
|
public DataTable GetSubGridJson10(string Code, string queryJson, 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 * from (select row_number() over(partition by a.TransferNO,a.InvCode,
|
|
a.Sequence ORDER BY a.TransferNO) as row, a.ID,a.TransferNO as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.FromWarehouseCode as WHCode,b.WarehouseName,detail.LocationCode AS Area,
|
|
a.InvCode,a.ToWarehouseCode,a.EATTRIBUTE1 AS ReceiveWork,a.WorkPoint,a.OrderType,
|
|
a.TypeDescribe,a.Remarks,a.PersonNumber,a.InvDescribe,
|
|
a.Unit,a.StockIndicator,a.ReceiveInvCode,a.ReceiveInvDescribe,
|
|
a.ReceiveStock,a.ReceiveSales,a.ReceiveSequence,a.Remark2,
|
|
d.InvName,d.InvDesc,d.InvStd,d.InvUnit,a.SAPSequence,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
,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.TransferQuantity as IssueQuantity
|
|
from ICSTransfer a
|
|
left join ICSWarehouse b on a.FromWarehouseCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.FromWarehouseCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.TransferNO='{0}' and b.WorkPoint='{1}'";
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sql += " and a.ToWarehouseCode like '%" + queryParam["WHCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
|
|
{
|
|
sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
|
|
{
|
|
sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
WHERE
|
|
F_Define3='HGAreaConfig' AND F_Define1=a.FromWarehouseCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
|
|
}
|
|
}
|
|
sql += " ) as t where t.row=1";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
//return Repository().FindTableBySql(sql.ToString());
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//两步调拨
|
|
public DataTable GetGridJson11(string queryJson, 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>();
|
|
StringBuilder sqlString = new StringBuilder();
|
|
#region [SQL]
|
|
// sql = @"
|
|
//select a.ID,a.BrrowCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
// case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
// from ICSBrrow a
|
|
// left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
// left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
// left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
|
|
// sql += " WHERE 1=1 and e.ID is null ";
|
|
sqlString.Append($@"select * from (select row_number() over(partition by a.OutCode order by a.OutCode)row, a.OutCode as Code, a.CreateDateTime as MTIME, a.CreatePerson as MUSER,
|
|
case when max(e.SourceID) is null then '未合并' else '已合并' end as IsNew,a.EATTRIBUTE1 AS ReceiveWork,tra.ToWarehouseCode,
|
|
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 ICSOtherOut a
|
|
INNER JOIN ICSTransfer tra ON a.TransferDetailID = tra.TransferDetailID AND a.WorkPoint = tra.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
|
|
where a.WorkPoint = '{WorkPoint}'
|
|
and a.Status = '2' ");
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.OutCode like '%{queryParam["POCode"]}%' ");
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
|
|
}
|
|
}
|
|
sqlString.Append(@" group by a.OutCode, a.CreateDateTime, a.CreatePerson,a.EATTRIBUTE1 ,tra.ToWarehouseCode, 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) t where t.row=1");
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
//两步调拨子表查询
|
|
public DataTable GetSubGridJson11(string Code)
|
|
{
|
|
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 a.ID,a.OutCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode ,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
|
|
case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
|
|
,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.OutQuantity as IssueQuantity
|
|
FROM ICSOtherOut a
|
|
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
|
|
left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
|
|
left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
where a.OutCode='{0}' and a.WorkPoint='{1}'";
|
|
sql = string.Format(sql, Code, WorkPoint);
|
|
return Repository().FindTableBySql(sql.ToString());
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// public DataTable GetICSMOPickMergeTemp(string ID,string Type)
|
|
// {
|
|
// string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
// ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
|
|
// #region sql
|
|
// string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
|
|
// c.Code,
|
|
// c.InvCode,
|
|
// c.InvName,
|
|
// c.InvStd,
|
|
// c.InvUnit,
|
|
// FLOOR(c.iQuantity) AS iQuantity,
|
|
// d.WarehouseCode,
|
|
// m.LotNO,
|
|
// (case when m.LotNo is null then 0 else FLOOR(ISNULL(d.Quantity, 0)) end) AS QTY,
|
|
// (case when m.LotNo is null then null else d.LocationCode end) AS LocationCode,
|
|
// CONVERT(varchar(100),d.MTIME, 23) MTIME,
|
|
// FLOOR(f.QTYTotal) QTYTotal INTO #temp
|
|
// FROM
|
|
// ({0}) c
|
|
// LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
|
|
// left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
|
|
// LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
|
|
|
|
|
|
//DECLARE @ItemCode VARCHAR(50),
|
|
// @QTY DECIMAL(18,3),
|
|
// @ItemCodeCurrent VARCHAR(50),
|
|
// @Lotno VARCHAR(50),
|
|
// @QTYCurrent DECIMAL(18,3),
|
|
// @iQuantityCurrent DECIMAL(18,3),
|
|
// @CanDelete BIT,
|
|
// @Row INT,
|
|
// @rowCurrent INT
|
|
//SET @Row = @@rowcount
|
|
//SET @rowCurrent=1
|
|
//SET @CanDelete=0
|
|
//SET @ItemCode=''
|
|
//SET @Lotno = ''
|
|
|
|
//WHILE @rowCurrent<=@Row
|
|
// BEGIN
|
|
// SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity,@Lotno = Lotno FROM #temp WHERE rowNo=@rowCurrent
|
|
|
|
//PRINT(@rowCurrent)
|
|
// IF @ItemCode<>@ItemCodeCurrent
|
|
// BEGIN
|
|
// SET @ItemCode=@ItemCodeCurrent
|
|
// SET @QTY=0
|
|
// SET @CanDelete=0
|
|
// END
|
|
|
|
// IF @CanDelete=1
|
|
// BEGIN
|
|
// DELETE FROM #temp WHERE rowNo=@rowCurrent
|
|
// SET @rowCurrent += 1
|
|
// CONTINUE
|
|
// END
|
|
|
|
// SET @QTY += @QTYCurrent
|
|
// IF @LotNo is null or @QTY>=@iQuantityCurrent
|
|
// BEGIN
|
|
// SET @CanDelete=1
|
|
// END
|
|
|
|
// SET @rowCurrent += 1
|
|
// END
|
|
//SELECT * FROM #temp
|
|
//DROP TABLE #temp
|
|
//";
|
|
// #endregion
|
|
// string sqls = "";
|
|
// if (Type=="1")
|
|
// {
|
|
// #region 工单备料sql
|
|
// sqls = @" SELECT
|
|
// c.MOCode as Code,
|
|
// a.InvCode,
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
// b.InvUnit,
|
|
// a.ExtensionID
|
|
// FROM
|
|
// ICSMOPick a
|
|
// inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "2")
|
|
// {
|
|
// return GetICSMOPickMergeByWorkorder(ID, WorkPoint);
|
|
// }
|
|
// if (Type=="3")
|
|
// {
|
|
// #region 工单材料出库SQL
|
|
// sqls = @" select
|
|
// a.IssueCode as Code,
|
|
// a.InvCode,
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
// b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
// a.ExtensionID
|
|
// FROM
|
|
// ICSMOIssue a
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
// if (Type=="4")
|
|
// {
|
|
// #region 委外备料SQL
|
|
// sqls = @" select
|
|
// c.OOCode as Code,
|
|
// a.InvCode,
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
// b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
// a.ExtensionID
|
|
// FROM
|
|
// ICSOOPick a
|
|
// left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
// if (Type=="5")
|
|
// {
|
|
// #region 委外领料SQL
|
|
// sqls = @" select
|
|
// a.ApplyCode as Code,
|
|
// a.InvCode,
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
// a.ExtensionID
|
|
// FROM
|
|
// ICSOApply a
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
// if (Type=="6")
|
|
// {
|
|
// #region 委外材料出库SQL
|
|
// sqls = @" select
|
|
// a.IssueCode as Code,
|
|
// a.InvCode,
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSOIssue a
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
// if (Type=="7")
|
|
// {
|
|
// #region 销售发货SQL
|
|
// sqls = @" select
|
|
// a.SDNCode as Code,
|
|
// a.InvCode,
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSSDN a
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
// if (Type=="8")
|
|
// {
|
|
// #region 其它出库SQL
|
|
// sqls = @" select
|
|
// a.OutCode as Code,
|
|
// a.InvCode,
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
// b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
// a.ExtensionID
|
|
// FROM
|
|
// ICSOtherOut a
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "9")
|
|
// {
|
|
// #region 借用SQL
|
|
// sqls = @"select
|
|
// a.BrrowCode as Code,
|
|
// a.InvCode,
|
|
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSBrrow a
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "10")
|
|
// {
|
|
// #region 物料调拨
|
|
// sqls = @" select
|
|
// a.TransferNO as Code,
|
|
// a.InvCode,
|
|
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.FromWarehouseCode as WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSTransfer a
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "11")
|
|
// {
|
|
// #region 两步调出
|
|
// sqls = @"select
|
|
// a.OutCode as Code,
|
|
// a.InvCode,
|
|
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WHCode ,
|
|
//a.ExtensionID
|
|
// from ICSOtherOut a
|
|
// INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
|
|
// sqls = string.Format(sqls, ID,WorkPoint);
|
|
// sql = string.Format(sql, sqls, WorkPoint);
|
|
// 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 (Invmes.Rows.Count > 0)
|
|
// {
|
|
// dtCloned.Merge(Invmes, false);
|
|
// }
|
|
// return dtCloned;
|
|
// }
|
|
public DataTable GetICSMOPickMergeTemp(string ID, string Type)
|
|
{
|
|
string postUrlStr = System.Configuration.ConfigurationManager.AppSettings["HGDocpostUrlStr"].ToString();
|
|
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 = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
|
|
string sqls = "";
|
|
#region sql
|
|
|
|
#endregion
|
|
//调拨单拣料增加逻辑,如果memo字段有条码信息,那么拣料的条码为备注条码,否则走正常逻辑
|
|
if (Type == "10")
|
|
{
|
|
string dataString = $@"select a.Memo,a.FromWarehouseCode,a.Quantity,a.TransferQuantity,a.InvCode,a.TransferNO,a.SAPSequence,a.Sequence FROM ICSTransfer a
|
|
WHERE a.TransferNO in ({ID}) AND a.WorkPoint = '{WorkPoint}'
|
|
AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0)
|
|
AND a.Memo is not null AND a.Memo!='' ";
|
|
|
|
var datasetModel = Repository().FindDataSetBySql(dataString);
|
|
DataTable table1 = null;
|
|
DataTable table = null;
|
|
StringBuilder updateString = new StringBuilder();
|
|
StringBuilder checklot = new StringBuilder();
|
|
string sqlString = String.Empty;
|
|
List<LotMessage> lotMessages = new List<LotMessage>();
|
|
if (datasetModel.Tables[0].Rows.Count != 0)
|
|
{
|
|
DataTable tableModel = datasetModel.Tables[0];
|
|
|
|
|
|
|
|
if (tableModel.Rows.Count > 0)
|
|
{
|
|
//循环验证条码信息是否与单据信息相符
|
|
for (int i = 0; i < tableModel.Rows.Count; i++)
|
|
{
|
|
LotMessage lotMessage = new LotMessage();
|
|
string transCode = tableModel.Rows[i]["TransferNO"].ToString();
|
|
string lotNo = tableModel.Rows[i]["Memo"].ToString();
|
|
string whCode = tableModel.Rows[i]["FromWarehouseCode"].ToString();
|
|
string sequence = tableModel.Rows[i]["Sequence"].ToString();
|
|
lotMessage.LotNo = lotNo;
|
|
lotMessage.Quantity = Convert.ToDecimal(tableModel.Rows[i]["Quantity"].ToString());
|
|
lotMessages.Add(lotMessage);
|
|
//验证信息
|
|
checklot.Append($@"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{lotNo}' AND a.WorkPoint='{WorkPoint}')
|
|
BEGIN
|
|
RAISERROR('条码{lotNo},不存在',16,1);
|
|
RETURN
|
|
END;
|
|
IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{tableModel.Rows[i]["Memo"]}' AND a.WorkPoint='{WorkPoint}' AND a.WarehouseCode='{whCode}')
|
|
BEGIN
|
|
RAISERROR('条码{lotNo}和单据{transCode}行{tableModel.Rows[i]["SAPSequence"]}仓库不一致',16,1);
|
|
RETURN
|
|
END;
|
|
IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{lotNo}' AND a.WorkPoint='{WorkPoint}' AND a.WarehouseCode='{whCode}' AND a.Quantity>=A.LockQuantity+'{tableModel.Rows[i]["Quantity"]}')
|
|
BEGIN
|
|
RAISERROR('条码{lotNo}的库存可分配数量小于单据数量',16,1);
|
|
RETURN
|
|
END;
|
|
IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{lotNo}' AND a.WorkPoint='{WorkPoint}' AND InvCode='{tableModel.Rows[i]["InvCode"]}')
|
|
BEGIN
|
|
RAISERROR('条码{lotNo}和单据{transCode}行号{tableModel.Rows[i]["SAPSequence"]}对应的物料不一致',16,1);
|
|
RETURN
|
|
END;"
|
|
);
|
|
|
|
updateString.Append($@" INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),NEWID(),'{transCode}','{sequence}',a.LotNo ,a.InvCode ,
|
|
a.WarehouseCode,a.LocationCode,'','','{tableModel.Rows[i]["Quantity"]}',
|
|
'','1','15','47','0','',
|
|
'','','','{MUSER}' ,'{MUSERNAME}' ,
|
|
GETDATE() ,'{WorkPoint}' ,''
|
|
FROM ICSWareHouseLotInfo a
|
|
WHERE a.LotNo='{tableModel.Rows[i]["Memo"]}' AND a.WorkPoint='{WorkPoint}'
|
|
|
|
update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{tableModel.Rows[i]["Quantity"]}' where LotNo='{lotNo}' AND WorkPoint='{WorkPoint}';");
|
|
|
|
}
|
|
|
|
SqlHelper.CmdExecuteNonQueryLi(checklot.ToString());
|
|
sqlString = $@"SELECT
|
|
a.TransferNO AS Code,a.Sequence,a.InvCode,b.InvName,b.InvStd,b.InvUnit,
|
|
(SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.TransferQuantity, 0))) AS iQuantity,--应发数量
|
|
a.FromWarehouseCode As WarehouseCode,
|
|
a.Memo AS LotNO,
|
|
ISNULL(c.Quantity, 0) AS QTY,--条码库存
|
|
ISNULL(c.Quantity, 0) AS QTYLeft,
|
|
a.Quantity as SendQTY, --占料数量
|
|
c.LocationCode,
|
|
CONVERT(varchar(100),c.MTIME, 23) MTIME,
|
|
SUM(c.Quantity-c.LockQuantity) AS QTYTotal,
|
|
a.ExtensionID
|
|
from ICSTransfer a
|
|
Left JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
LEFT JOIN ICSWareHouseLotInfo c ON c.LotNo=a.Memo AND a.FromWarehouseCode=c.WarehouseCode
|
|
WHERE a.TransferNO in({ID}) AND a.Memo is NOT NULL and a.Memo!=''
|
|
GROUP BY a.TransferNO,a.Sequence,a.InvCode,b.InvName,b.InvStd,b.InvUnit,
|
|
a.Quantity,a.FromWarehouseCode ,a.Memo,c.LocationCode,c.MTIME,c.Quantity,a.ExtensionID,c.LockQuantity; ";
|
|
|
|
}
|
|
//if (!String.IsNullOrEmpty(sqlString))
|
|
//{
|
|
// var dataSet1 = Repository().FindDataSetBySql(updateString.ToString()+ sqlString);
|
|
// if (dataSet1.Tables[0].Rows.Count != 0)
|
|
// {
|
|
// table1 = dataSet1.Tables[0];
|
|
// }
|
|
//}
|
|
}
|
|
|
|
|
|
|
|
string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
|
|
c.Code,
|
|
c.Sequence,
|
|
c.InvCode,
|
|
c.InvName,
|
|
c.InvStd,
|
|
c.InvUnit,
|
|
c.iQuantity AS iQuantity,
|
|
c.WHCode AS WarehouseCode,
|
|
d.LotNO,
|
|
ISNULL(d.Quantity, 0) AS QTY,
|
|
ISNULL(d.Quantity, 0) AS QTYLeft,
|
|
CONVERT(decimal(18,6),0) AS SendQTY,
|
|
d.LocationCode AS LocationCode,
|
|
CONVERT(varchar(100),d.MTIME, 23) MTIME,
|
|
f.QTYTotal QTYTotal,c.ExtensionID
|
|
FROM
|
|
(select
|
|
a.TransferNO as Code,
|
|
a.Sequence,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
(SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.TransferQuantity, 0))) AS iQuantity,
|
|
a.FromWarehouseCode as WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSTransfer a
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.TransferNO in ({ID}) AND a.WorkPoint = '{WorkPoint}' AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0)
|
|
and (a.Memo is null or a.Memo='' )
|
|
GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,a.Sequence) c
|
|
left join (select d.WarehouseCode,d.Quantity-d.LockQuantity as Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
|
|
from ICSWareHouseLotInfo d ,ICSInventoryLot m
|
|
where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
|
|
and d.WorkPoint='{WorkPoint}' AND d.Quantity-d.LockQuantity>0 AND d.Quantity>0
|
|
--AND SUBSTRING( SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode)),0,CHARINDEX('-', SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode)))) Not IN(SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
--WHERE F_Define3='HGAreaConfig' AND F_Define1=d.WarehouseCode AND F_Define4=d.WorkPoint)
|
|
) d
|
|
on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
|
|
LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity-LockQuantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
|
|
order by c.Code,Convert(int,c.Sequence),d.MTIME,d.LotNO ";
|
|
|
|
var dataset = Repository().FindDataSetBySql(sql);
|
|
if (dataset.Tables[0].Rows.Count != 0)
|
|
{
|
|
table = dataset.Tables[0];
|
|
decimal qtyCount = 0;
|
|
bool remove = false;
|
|
List<int> removeList = new List<int>();
|
|
|
|
|
|
for (int i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
if (lotMessages != null && lotMessages.Count > 0)
|
|
{
|
|
//排除指定条码的锁定库存数量
|
|
List<LotMessage> models = lotMessages.Where(e => e.LotNo == table.Rows[i]["LotNO"].ToString()).ToList();
|
|
if (models != null && models.Count > 0)
|
|
{
|
|
decimal quantity = models.Select(e => e.Quantity).ToList().Sum();
|
|
table.Rows[i]["QTYLeft"] = table.Rows[i]["QTYLeft"].ToString().ToDecimal() - quantity;
|
|
}
|
|
|
|
}
|
|
|
|
if (i != 0
|
|
&& (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
|
|
|| !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString())
|
|
|| !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString())
|
|
|| !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString()))
|
|
)
|
|
{
|
|
qtyCount = 0;
|
|
remove = false;
|
|
}
|
|
if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0)
|
|
{
|
|
removeList.Add(i);
|
|
continue;
|
|
}
|
|
if (remove)
|
|
{
|
|
removeList.Add(i);
|
|
}
|
|
else
|
|
{
|
|
var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal();
|
|
var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
|
|
qtyCount += lotQty;
|
|
foreach (DataRow dr in table.Rows)
|
|
{
|
|
if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString())
|
|
{
|
|
if (qtyCount > orderQty)
|
|
{
|
|
dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty);
|
|
}
|
|
else
|
|
{
|
|
dr["QTYLeft"] = 0;
|
|
}
|
|
}
|
|
}
|
|
if (qtyCount >= orderQty)
|
|
{
|
|
table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty));
|
|
remove = true;
|
|
}
|
|
else
|
|
{
|
|
table.Rows[i]["SendQTY"] = lotQty;
|
|
}
|
|
}
|
|
}
|
|
if (removeList.Count > 0)
|
|
{
|
|
removeList.Reverse();
|
|
foreach (var item in removeList)
|
|
{
|
|
table.Rows.RemoveAt(item);
|
|
}
|
|
}
|
|
try
|
|
{
|
|
#region 占料前增加验证,如果条码数量超出实际需要领料数量,直接报错
|
|
string chksql = "";
|
|
|
|
#region 物料调拨
|
|
chksql = @" select InvCode,FromWarehouseCode AS WHCode,(SUM(ISNULL(Quantity, 0))-SUM(ISNULL(TransferQuantity, 0))) as Quantity from ICSTransfer
|
|
where TransferNO in ({0}) and WorkPoint='{1}' and (Memo is NULL or Memo='')
|
|
GROUP BY InvCode,FromWarehouseCode";
|
|
#endregion
|
|
|
|
chksql = string.Format(chksql, ID, WorkPoint);
|
|
var chkdata = Repository().FindDataSetBySql(chksql);
|
|
DataTable chktable = chkdata.Tables[0];
|
|
foreach (DataRow chkdr in chktable.Rows)
|
|
{
|
|
decimal ZLQty = 0;
|
|
for (int i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
if (table.Rows[i]["WarehouseCode"].ToString() == chkdr["WHCode"].ToString()
|
|
&& table.Rows[i]["InvCode"].ToString() == chkdr["InvCode"].ToString())
|
|
{
|
|
ZLQty += Convert.ToDecimal(table.Rows[i]["SendQTY"].ToString());
|
|
}
|
|
}
|
|
if (Convert.ToDecimal(chkdr["Quantity"]) < ZLQty)
|
|
{
|
|
throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量大于单据需求数量,请尝试重新拣料。");
|
|
}
|
|
//if (Convert.ToDecimal(chkdr["Quantity"]) > ZLQty && (Type == "2" || Type == "5" || Type == "12"))
|
|
//{
|
|
// chksql = @" select B.F_Define2 from ICSInventoryDetail A
|
|
// INNER JOIN Sys_SRM_ItemsDetail B ON B.F_Define1=A.WHCode AND B.F_Define2=A.LocationCode AND B.F_Define4=A.WorkPoint
|
|
// where INVCode='{0}' and WHCode='{1}' and WorkPoint='{2}'";
|
|
// chksql = string.Format(chksql, chkdr["InvCode"].ToString(), chkdr["WHCode"].ToString(), WorkPoint);
|
|
// var chkds = Repository().FindDataSetBySql(chksql);
|
|
// DataTable chkdt = chkds.Tables[0];
|
|
// if (chkdt.Rows.Count != 0)
|
|
// {
|
|
// throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量小于单据需求数量,货柜单据必须整单拣料,请先核对库存。");
|
|
// }
|
|
//}
|
|
if (Convert.ToDecimal(chkdr["Quantity"]) > ZLQty)
|
|
{
|
|
throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量小于单据需求数量,货柜单据必须整单拣料,请先核对库存。");
|
|
}
|
|
}
|
|
#endregion
|
|
if (table.Rows.Count != 0)
|
|
{
|
|
#region 拣料时增加条码出入库记录,修改库存锁定数量,以作占料处理
|
|
int Count = 1;
|
|
string BusinessCode = "10";
|
|
string TransType = "调拨申请单";
|
|
string Identification = Guid.NewGuid().ToString();
|
|
var pikTbLogTime = DateTime.Now;
|
|
string pikTbLogsql = string.Empty;
|
|
List<string> DocNoList = new List<string>();
|
|
if (Type == "2" || Type == "12" || Type == "5")
|
|
{
|
|
#region 货柜
|
|
string InspectJosn = "";
|
|
string InspectJosnHead = "";
|
|
string InspectJosnBody = "";
|
|
InspectJosn += "{";
|
|
InspectJosn += "\"IMP_ORDINI\":[";
|
|
InspectJosn += "货柜主表区域预留";
|
|
InspectJosn += "],";
|
|
InspectJosn += "\"IMP_ORDINI_RIGHE\":[";
|
|
InspectJosn += "货柜子表区域预留";
|
|
InspectJosn += "]";
|
|
InspectJosn += "}";
|
|
for (int i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
string hgsql = @"select A.InvCode,A.LocationCode,B.F_Define3,C.LocationCode AS Area
|
|
from ICSWareHouseLotInfo A
|
|
INNER JOIN Sys_SRM_ItemsDetail B ON B.F_Define2=A.LocationCode AND F_Define4=A.WorkPoint AND F_ItemName='HG_Location'
|
|
INNER JOIN ICSInventoryDetail C ON C.INVCode=A.InvCode AND C.WHCode=A.WarehouseCode AND C.WorkPoint=A.WorkPoint
|
|
where A.LotNo='{0}' AND A.WorkPoint='{1}'";
|
|
hgsql = string.Format(hgsql, table.Rows[i]["LotNO"].ToString(), WorkPoint);
|
|
var hgds = Repository().FindDataSetBySql(hgsql);
|
|
if (hgds.Tables.Count == 0)
|
|
return null;
|
|
DataTable hgtable = hgds.Tables[0];
|
|
if (hgtable.Rows.Count > 0)
|
|
{
|
|
if (!DocNoList.Contains(table.Rows[i]["Code"].ToString()))
|
|
{
|
|
DocNoList.Add(table.Rows[i]["Code"].ToString());
|
|
}
|
|
InspectJosnBody += "{";
|
|
InspectJosnBody += "\"RIG_ORDINE\":\"" + table.Rows[i]["Code"].ToString() + "\",";
|
|
InspectJosnBody += "\"RIG_ARTICOLO\": \"" + hgtable.Rows[0]["InvCode"].ToString() + "\",";
|
|
InspectJosnBody += "\"RIG_SUB1\": \"\",";
|
|
InspectJosnBody += "\"RIG_SUB2\": \"\",";
|
|
InspectJosnBody += "\"RIG_ELERUOLI_GEST\": \"" + hgtable.Rows[0]["Area"].ToString() + "\",";
|
|
InspectJosnBody += "\"RIG_ELEBAIE\": \"" + hgtable.Rows[0]["F_Define3"].ToString() + "\",";
|
|
InspectJosnBody += "\"RIG_QTAR\": " + table.Rows[i]["SendQTY"].ToString() + ",";
|
|
if (i == 0)
|
|
{
|
|
InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + "\"";
|
|
}
|
|
else
|
|
{
|
|
if (table.Rows[i]["Code"].ToString() == table.Rows[i - 1]["Code"].ToString() &&
|
|
table.Rows[i]["Sequence"].ToString() == table.Rows[i - 1]["Sequence"].ToString())
|
|
{
|
|
InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + Count.ToString() + "\"";
|
|
Count++;
|
|
}
|
|
else
|
|
{
|
|
InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + "\"";
|
|
Count = 1;
|
|
}
|
|
}
|
|
InspectJosnBody += "},";
|
|
}
|
|
}
|
|
InspectJosnBody = InspectJosnBody.TrimEnd(',');
|
|
foreach (string DocNo in DocNoList)
|
|
{
|
|
InspectJosnHead += "{";
|
|
InspectJosnHead += "\"ORD_ORDINE\":\"" + DocNo.TrimStart('\'').TrimEnd('\'') + "\",";
|
|
InspectJosnHead += "\"ORD_DES\":\"" + TransType + "\",";
|
|
InspectJosnHead += "\"ORD_TIPOOP\":\"P\",";
|
|
InspectJosnHead += "\"ORD_CLIENTE\":\"" + WorkPoint + "\"";
|
|
InspectJosnHead += "},";
|
|
}
|
|
InspectJosnHead = InspectJosnHead.TrimEnd(',');
|
|
if (InspectJosnBody != "")
|
|
{
|
|
InspectJosn = InspectJosn.Replace("货柜主表区域预留", InspectJosnHead);
|
|
InspectJosn = InspectJosn.Replace("货柜子表区域预留", InspectJosnBody);
|
|
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
|
|
{
|
|
string callresult = "";
|
|
#region 货柜接口调用前日志
|
|
object logID = Guid.NewGuid();
|
|
string logsql = @"insert into ICSWMS_HGLog
|
|
values
|
|
('{0}',GETDATE(),'{1}','{2}','{3}','{4}','{5}')";
|
|
logsql = string.Format(logsql, logID, InspectJosn, "", WorkPoint, MUSER, MUSERNAME);
|
|
SqlHelper.CmdExecuteNonQueryLi(logsql);
|
|
#endregion
|
|
callresult = HTTPHelper.RestFulGet(InspectJosn, postUrlStr);
|
|
#region 货柜接口调用后日志
|
|
logsql = @"update ICSWMS_HGLog set ReturnResult='{0}'
|
|
where ID='{1}'";
|
|
logsql = string.Format(logsql, callresult, logID);
|
|
SqlHelper.CmdExecuteNonQueryLi(logsql);
|
|
#endregion
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
foreach (DataRow PickLog in table.Rows)
|
|
{
|
|
pikTbLogsql += @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{9}' AND a.WorkPoint='{8}' AND a.Quantity>=A.LockQuantity+'{3}')
|
|
BEGIN
|
|
|
|
RAISERROR('条码{9}的库存可分配数量小于单据数量', 16, 1);
|
|
RETURN
|
|
END;
|
|
IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{9}' AND WorkPoint='{8}' AND TransType='15')
|
|
BEGIN
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode ,
|
|
a.WarehouseCode,a.LocationCode,'','','{3}',
|
|
'','1','15','{4}','0','',
|
|
'','','','{5}' ,'{6}' ,
|
|
'{7}' ,'{8}' ,''
|
|
FROM ICSWareHouseLotInfo a
|
|
WHERE a.LotNo='{9}' AND a.WorkPoint='{8}'
|
|
|
|
update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{9}' AND WorkPoint='{8}'
|
|
END
|
|
UPDATE ICSTransfer SET MUSER='{6}' WHERE TransferNO='{1}' and Sequence='{2}' ; ";
|
|
pikTbLogsql = string.Format(pikTbLogsql, Identification, PickLog["Code"].ToString(), PickLog["Sequence"].ToString(), PickLog["SendQTY"].ToString()
|
|
, BusinessCode, MUSER, MUSERNAME, pikTbLogTime, WorkPoint, PickLog["LotNO"].ToString());
|
|
}
|
|
SqlHelper.CmdExecuteNonQueryLi(pikTbLogsql + updateString.ToString());
|
|
#endregion
|
|
}
|
|
//查询有条码的拣料信息
|
|
if (!String.IsNullOrEmpty(sqlString))
|
|
{
|
|
var dataSet1 = Repository().FindDataSetBySql(sqlString);
|
|
if (dataSet1.Tables[0].Rows.Count != 0)
|
|
{
|
|
table1 = dataSet1.Tables[0];
|
|
}
|
|
}
|
|
//if (table1 != null)
|
|
//{
|
|
// table.Merge(table1);
|
|
//}
|
|
//var result = ConvertCellToString(table);
|
|
//if (Invmes.Rows.Count > 0)
|
|
//{
|
|
// result.Merge(Invmes, false);
|
|
//}
|
|
//return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
if (!String.IsNullOrEmpty(updateString.ToString()))
|
|
{
|
|
SqlHelper.CmdExecuteNonQueryLi(updateString.ToString());
|
|
}
|
|
//查询有条码的拣料信息
|
|
if (!String.IsNullOrEmpty(sqlString))
|
|
{
|
|
var dataSet1 = Repository().FindDataSetBySql(sqlString);
|
|
if (dataSet1.Tables[0].Rows.Count != 0)
|
|
{
|
|
table1 = dataSet1.Tables[0];
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
if (table1 != null && table != null)
|
|
{
|
|
table.Merge(table1);
|
|
}
|
|
else if (table == null && table1 != null)
|
|
{
|
|
table = table1;
|
|
}
|
|
else if (table1 == null && table == null)
|
|
{
|
|
return null;
|
|
}
|
|
var result = ConvertCellToString(table);
|
|
if (Invmes.Rows.Count > 0)
|
|
{
|
|
result.Merge(Invmes, false);
|
|
}
|
|
return result;
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
if (Type == "1")
|
|
{
|
|
#region 工单备料sql
|
|
sqls = @" SELECT
|
|
c.MOCode as Code,
|
|
c.Sequence+'~'+a.Sequence as Sequence,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
b.InvUnit,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSMOPick a
|
|
inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,c.Sequence+'~'+a.Sequence";
|
|
#endregion
|
|
}
|
|
if (Type == "2" || Type == "12")
|
|
{
|
|
sqls = @"select
|
|
a.ApplyCode as Code,a.Sequence, a.InvCode, b.InvName, b.InvStd, b.InvUnit, (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.IssueQuantity, 0))) AS iQuantity, a.WhCode,a.ExtensionID
|
|
FROM
|
|
ICSMOApply a
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
|
|
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
|
|
}
|
|
if (Type == "3")
|
|
{
|
|
#region 工单材料出库SQL
|
|
sqls = @" select
|
|
a.IssueCode as Code,
|
|
a.Sequence,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSMOIssue a
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
|
|
#endregion
|
|
}
|
|
if (Type == "4")
|
|
{
|
|
#region 委外备料SQL
|
|
sqls = @" select
|
|
c.OOCode as Code,
|
|
c.Sequence+'~'+a.Sequence as Sequence,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSOOPick a
|
|
left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID,c.Sequence+'~'+a.Sequence";
|
|
#endregion
|
|
}
|
|
if (Type == "5")
|
|
{
|
|
#region 委外领料SQL
|
|
sqls = @"select
|
|
a.ApplyCode as Code,
|
|
a.Sequence,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
(SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.IssueQuantity,0))) AS iQuantity,
|
|
a.WhCode,a.ExtensionID
|
|
FROM
|
|
ICSOApply a
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
|
|
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
|
|
#endregion
|
|
}
|
|
if (Type == "6")
|
|
{
|
|
#region 委外材料出库SQL
|
|
sqls = @" select
|
|
a.IssueCode as Code,
|
|
a.Sequence,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSOIssue a
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
|
|
#endregion
|
|
}
|
|
if (Type == "7")
|
|
{
|
|
#region 销售发货SQL
|
|
sqls = @" select
|
|
a.SDNCode as Code,
|
|
a.Sequence,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
(SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.SDNQuantity, 0))) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSSDN a
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.SDNQuantity, 0)
|
|
GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
|
|
#endregion
|
|
}
|
|
if (Type == "8")
|
|
{
|
|
#region 其它出库SQL
|
|
sqls = @" select
|
|
a.OutCode as Code,
|
|
a.Sequence,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
(SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.OutQuantity, 0))) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSOtherOut a
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.OutQuantity, 0)
|
|
GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
|
|
#endregion
|
|
}
|
|
if (Type == "9")
|
|
{
|
|
#region 借用SQL
|
|
sqls = @"select
|
|
a.BrrowCode as Code,
|
|
a.Sequence,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSBrrow a
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
|
|
#endregion
|
|
}
|
|
if (Type == "10")
|
|
{
|
|
#region 物料调拨
|
|
sqls = @"select
|
|
a.TransferNO as Code,
|
|
a.Sequence,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
(SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.TransferQuantity, 0))) AS iQuantity,
|
|
a.FromWarehouseCode as WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSTransfer a
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0)
|
|
and a.Memo is null
|
|
GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,a.Sequence";
|
|
#endregion
|
|
}
|
|
if (Type == "11")
|
|
{
|
|
#region 两步调出
|
|
sqls = @"select
|
|
a.OutCode as Code,
|
|
a.Sequence,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WHCode ,
|
|
a.ExtensionID
|
|
from ICSOtherOut a
|
|
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,a.Sequence";
|
|
#endregion
|
|
}
|
|
sqls = string.Format(sqls, ID, WorkPoint);
|
|
|
|
string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
|
|
c.Code,
|
|
c.Sequence,
|
|
c.InvCode,
|
|
c.InvName,
|
|
c.InvStd,
|
|
c.InvUnit,
|
|
c.iQuantity AS iQuantity,
|
|
c.WHCode AS WarehouseCode,
|
|
d.LotNO,
|
|
ISNULL(d.Quantity, 0) AS QTY,
|
|
ISNULL(d.Quantity, 0) AS QTYLeft,
|
|
CONVERT(decimal(18,6),0) AS SendQTY,
|
|
d.LocationCode AS LocationCode,
|
|
CONVERT(varchar(100),d.MTIME, 23) MTIME,
|
|
f.QTYTotal QTYTotal,c.ExtensionID
|
|
FROM
|
|
({sqls}) c
|
|
left join (select d.WarehouseCode,d.Quantity-d.LockQuantity as Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
|
|
from ICSWareHouseLotInfo d ,ICSInventoryLot m
|
|
where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
|
|
and d.WorkPoint='{WorkPoint}' AND d.Quantity-d.LockQuantity>0 AND d.Quantity>0
|
|
--AND SUBSTRING( SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode)),0,CHARINDEX('-', SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode)))) Not IN(SELECT F_Define2 FROM Sys_SRM_ItemsDetail
|
|
--WHERE F_Define3='HGAreaConfig' AND F_Define1=d.WarehouseCode AND F_Define4=d.WorkPoint)
|
|
) d
|
|
on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
|
|
LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity-LockQuantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
|
|
order by c.Code,Convert(int,c.Sequence),d.MTIME,d.LotNO ";
|
|
|
|
var dataset = Repository().FindDataSetBySql(sql);
|
|
if (dataset.Tables[0].Rows.Count == 0)
|
|
return null;
|
|
DataTable table = dataset.Tables[0];
|
|
decimal qtyCount = 0;
|
|
bool remove = false;
|
|
List<int> removeList = new List<int>();
|
|
for (int i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
if (i != 0
|
|
&& (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
|
|
|| !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString())
|
|
|| !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString())
|
|
|| !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString()))
|
|
)
|
|
{
|
|
qtyCount = 0;
|
|
remove = false;
|
|
}
|
|
if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0)
|
|
{
|
|
removeList.Add(i);
|
|
continue;
|
|
}
|
|
if (remove)
|
|
{
|
|
removeList.Add(i);
|
|
}
|
|
else
|
|
{
|
|
var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal();
|
|
var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
|
|
qtyCount += lotQty;
|
|
foreach (DataRow dr in table.Rows)
|
|
{
|
|
if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString())
|
|
{
|
|
if (qtyCount > orderQty)
|
|
{
|
|
dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty);
|
|
}
|
|
else
|
|
{
|
|
dr["QTYLeft"] = 0;
|
|
}
|
|
}
|
|
}
|
|
if (qtyCount >= orderQty)
|
|
{
|
|
table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty));
|
|
remove = true;
|
|
}
|
|
else
|
|
{
|
|
table.Rows[i]["SendQTY"] = lotQty;
|
|
}
|
|
}
|
|
}
|
|
if (removeList.Count > 0)
|
|
{
|
|
removeList.Reverse();
|
|
foreach (var item in removeList)
|
|
{
|
|
table.Rows.RemoveAt(item);
|
|
}
|
|
}
|
|
try
|
|
{
|
|
#region 占料前增加验证,如果条码数量超出实际需要领料数量,直接报错
|
|
string chksql = "";
|
|
string updateName = "ICSMOApply";
|
|
string cCode = "ApplyCode";
|
|
if (Type == "2" || Type == "12")
|
|
{
|
|
chksql = @" select InvCode,WHCode,(SUM(ISNULL(Quantity, 0))-SUM(ISNULL(IssueQuantity, 0))) as Quantity from ICSMOApply
|
|
where ApplyCode in ({0}) and WorkPoint='{1}'
|
|
GROUP BY InvCode,WHCode";
|
|
updateName = "ICSMOApply";
|
|
cCode = "ApplyCode";
|
|
}
|
|
if (Type == "5")
|
|
{
|
|
#region 委外领料SQL
|
|
chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOApply
|
|
where ApplyCode in ({0}) and WorkPoint='{1}'
|
|
GROUP BY InvCode,WHCode";
|
|
updateName = "ICSOApply";
|
|
cCode = "ApplyCode";
|
|
#endregion
|
|
}
|
|
if (Type == "7")
|
|
{
|
|
#region 销售发货SQL
|
|
chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSSDN
|
|
where SDNCode in ({0}) and WorkPoint='{1}'
|
|
GROUP BY InvCode,WHCode";
|
|
#endregion
|
|
}
|
|
if (Type == "8")
|
|
{
|
|
#region 其它出库SQL
|
|
chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOtherOut
|
|
where OutCode in ({0}) and WorkPoint='{1}'
|
|
GROUP BY InvCode,WHCode";
|
|
#endregion
|
|
}
|
|
if (Type == "10")
|
|
{
|
|
#region 物料调拨
|
|
chksql = @" select InvCode,FromWarehouseCode AS WHCode,(SUM(ISNULL(Quantity, 0))-SUM(ISNULL(TransferQuantity, 0))) as Quantity from ICSTransfer
|
|
where TransferNO in ({0}) and WorkPoint='{1}'
|
|
GROUP BY InvCode,FromWarehouseCode";
|
|
updateName = "ICSTransfer";
|
|
cCode = "TransferNO";
|
|
#endregion
|
|
}
|
|
chksql = string.Format(chksql, ID, WorkPoint);
|
|
var chkdata = Repository().FindDataSetBySql(chksql);
|
|
DataTable chktable = chkdata.Tables[0];
|
|
foreach (DataRow chkdr in chktable.Rows)
|
|
{
|
|
decimal ZLQty = 0;
|
|
for (int i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
if (table.Rows[i]["WarehouseCode"].ToString() == chkdr["WHCode"].ToString()
|
|
&& table.Rows[i]["InvCode"].ToString() == chkdr["InvCode"].ToString())
|
|
{
|
|
ZLQty += Convert.ToDecimal(table.Rows[i]["SendQTY"].ToString());
|
|
}
|
|
}
|
|
if (Convert.ToDecimal(chkdr["Quantity"]) < ZLQty)
|
|
{
|
|
throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量大于单据需求数量,请尝试重新拣料。");
|
|
}
|
|
//if (Convert.ToDecimal(chkdr["Quantity"]) > ZLQty && (Type == "2" || Type == "5" || Type == "12"))
|
|
//{
|
|
// chksql = @" select B.F_Define2 from ICSInventoryDetail A
|
|
// INNER JOIN Sys_SRM_ItemsDetail B ON B.F_Define1=A.WHCode AND B.F_Define2=A.LocationCode AND B.F_Define4=A.WorkPoint
|
|
// where INVCode='{0}' and WHCode='{1}' and WorkPoint='{2}'";
|
|
// chksql = string.Format(chksql, chkdr["InvCode"].ToString(), chkdr["WHCode"].ToString(), WorkPoint);
|
|
// var chkds = Repository().FindDataSetBySql(chksql);
|
|
// DataTable chkdt = chkds.Tables[0];
|
|
// if (chkdt.Rows.Count != 0)
|
|
// {
|
|
// throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量小于单据需求数量,货柜单据必须整单拣料,请先核对库存。");
|
|
// }
|
|
//}
|
|
|
|
if (Convert.ToDecimal(chkdr["Quantity"]) > ZLQty)
|
|
{
|
|
throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量小于单据需求数量,单据必须整单拣料,请先核对库存。");
|
|
}
|
|
}
|
|
|
|
string sql1 = @" SELECT * from ICSWareHouseLotInfoLog WHERE TransType='15' AND TransCode in ({0}) AND WorkPoint='{1}' ";
|
|
sql1 = string.Format(sql1, ID, WorkPoint);
|
|
var chkdata1 = Repository().FindDataSetBySql(sql1);
|
|
DataTable chktable1 = chkdata1.Tables[0];
|
|
if (chktable1 != null && chktable1.Rows.Count > 0)
|
|
{
|
|
throw new Exception("工单:" + ID + "已拣料完成,请确认。");
|
|
}
|
|
|
|
#endregion
|
|
if (table.Rows.Count != 0)
|
|
{
|
|
#region 拣料时增加条码出入库记录,修改库存锁定数量,以作占料处理
|
|
string ccInspectJosn = "";
|
|
string ForkLiftUrl = System.Configuration.ConfigurationManager.AppSettings["ForkLiftUrl"];
|
|
string cclogsql = @"";
|
|
int Count = 1;
|
|
string BusinessCode = string.Empty;
|
|
string TransType = "";
|
|
if (Type == "2") { BusinessCode = "13"; TransType = "生产发料-领料申请单"; }
|
|
if (Type == "12") { BusinessCode = "14"; TransType = "生产发料-领料申请单"; }
|
|
if (Type == "5") { BusinessCode = "6"; TransType = "委外发料-委外领料申请单"; }
|
|
if (Type == "7") { BusinessCode = "19"; TransType = "销售发货-销售发货单"; }
|
|
if (Type == "8") { BusinessCode = "24"; TransType = "杂发"; }
|
|
if (Type == "10") { BusinessCode = "47"; TransType = "调拨申请单"; }
|
|
string Identification = Guid.NewGuid().ToString();
|
|
var pikTbLogTime = DateTime.Now;
|
|
string pikTbLogsql = string.Empty;
|
|
List<string> DocNoList = new List<string>();
|
|
|
|
if (Type == "2" || Type == "12" || Type == "5")
|
|
{
|
|
string ccsql = @"select B.F_Id from ICSInventoryDetail A
|
|
INNER JOIN Sys_SRM_ItemsDetail B ON B.F_Define1=A.WHCode AND B.F_Define2=A.LocationCode AND B.F_Define4=A.WorkPoint
|
|
where INVCode='{0}' and WHCode='{1}' and WorkPoint='{2}' AND B.F_ItemCode Like 'ForkLiftAreaConfig%' AND B.F_EnabledMark='1'";
|
|
ccsql = string.Format(ccsql, table.Rows[0]["InvCode"].ToString(), table.Rows[0]["WarehouseCode"].ToString()
|
|
, WorkPoint);
|
|
var ccds = Repository().FindDataSetBySql(ccsql);
|
|
DataTable cctable = ccds.Tables[0];
|
|
if (cctable.Rows.Count != 0)
|
|
{
|
|
List<string> SourceBinList = new List<string>();
|
|
#region 窄巷道
|
|
ccInspectJosn += "[";
|
|
foreach (DataRow dr in table.Rows)
|
|
{
|
|
if (!SourceBinList.Contains(dr["LocationCode"].ToString()))
|
|
{
|
|
SourceBinList.Add(dr["LocationCode"].ToString());
|
|
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadForkLift"]))
|
|
{
|
|
string Year = DateTime.Now.Year.ToString();
|
|
string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
|
|
string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
|
|
string Pre = "CC" + Year + Month + Day;
|
|
string serialsql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
|
|
serialsql = string.Format(serialsql, "1701", "ICSForkLiftTaskLog", "TaskCode", Pre, 4);
|
|
string TaskCode = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, serialsql, true, null).Rows[0][0].ToString();
|
|
string SerialNum = DateTime.Now.Hour.ToString().PadLeft(2, '0');
|
|
ccInspectJosn += "{";
|
|
ccInspectJosn += "\"TaskID\":\"" + TaskCode + "\",";//任务编号
|
|
ccInspectJosn += "\"TaskType\": \"PICK\",";//任务类型
|
|
ccInspectJosn += "\"SourceBin\": \"" + dr["LocationCode"].ToString() + "\"";//起始点位
|
|
ccInspectJosn += "},";
|
|
#region 记录叉车的任务编号及相关信息
|
|
#endregion
|
|
cclogsql += @"INSERT INTO ICSForkLiftTaskLog
|
|
(ID,TaskCode,ContainerCode,TaskType,StartLocation,EndLocation,MTIME,WorkPoint)
|
|
select NEWID(),'{0}','','PICK','{1}','',GETDATE(),'1701'";
|
|
cclogsql = string.Format(cclogsql, TaskCode, dr["LocationCode"].ToString());
|
|
}
|
|
}
|
|
}
|
|
ccInspectJosn = ccInspectJosn.TrimEnd(',');
|
|
ccInspectJosn += "]";
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
#region 货柜
|
|
string InspectJosn = "";
|
|
string InspectJosnHead = "";
|
|
string InspectJosnBody = "";
|
|
InspectJosn += "{";
|
|
InspectJosn += "\"IMP_ORDINI\":[";
|
|
InspectJosn += "货柜主表区域预留";
|
|
InspectJosn += "],";
|
|
InspectJosn += "\"IMP_ORDINI_RIGHE\":[";
|
|
InspectJosn += "货柜子表区域预留";
|
|
InspectJosn += "]";
|
|
InspectJosn += "}";
|
|
for (int i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
string hgsql = @"select A.InvCode,A.LocationCode,B.F_Define3,C.LocationCode AS Area
|
|
from ICSWareHouseLotInfo A
|
|
INNER JOIN Sys_SRM_ItemsDetail B ON B.F_Define2=A.LocationCode AND F_Define4=A.WorkPoint AND F_ItemName='HG_Location'
|
|
INNER JOIN ICSInventoryDetail C ON C.INVCode=A.InvCode AND C.WHCode=A.WarehouseCode AND C.WorkPoint=A.WorkPoint
|
|
where A.LotNo='{0}' AND A.WorkPoint='{1}'";
|
|
hgsql = string.Format(hgsql, table.Rows[i]["LotNO"].ToString(), WorkPoint);
|
|
var hgds = Repository().FindDataSetBySql(hgsql);
|
|
if (hgds.Tables.Count == 0)
|
|
return null;
|
|
DataTable hgtable = hgds.Tables[0];
|
|
if (hgtable.Rows.Count > 0)
|
|
{
|
|
if (!DocNoList.Contains(table.Rows[i]["Code"].ToString()))
|
|
{
|
|
DocNoList.Add(table.Rows[i]["Code"].ToString());
|
|
}
|
|
InspectJosnBody += "{";
|
|
InspectJosnBody += "\"RIG_ORDINE\":\"" + table.Rows[i]["Code"].ToString() + "\",";
|
|
InspectJosnBody += "\"RIG_ARTICOLO\": \"" + hgtable.Rows[0]["InvCode"].ToString() + "\",";
|
|
InspectJosnBody += "\"RIG_SUB1\": \"\",";
|
|
InspectJosnBody += "\"RIG_SUB2\": \"\",";
|
|
InspectJosnBody += "\"RIG_ELERUOLI_GEST\": \"" + hgtable.Rows[0]["Area"].ToString() + "\",";
|
|
InspectJosnBody += "\"RIG_ELEBAIE\": \"" + hgtable.Rows[0]["F_Define3"].ToString() + "\",";
|
|
InspectJosnBody += "\"RIG_QTAR\": " + table.Rows[i]["SendQTY"].ToString() + ",";
|
|
if (i == 0)
|
|
{
|
|
InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + "\"";
|
|
}
|
|
else
|
|
{
|
|
if (table.Rows[i]["Code"].ToString() == table.Rows[i - 1]["Code"].ToString() &&
|
|
table.Rows[i]["Sequence"].ToString() == table.Rows[i - 1]["Sequence"].ToString())
|
|
{
|
|
InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + Count.ToString() + "\"";
|
|
Count++;
|
|
}
|
|
else
|
|
{
|
|
InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + "\"";
|
|
Count = 1;
|
|
}
|
|
}
|
|
InspectJosnBody += "},";
|
|
}
|
|
}
|
|
InspectJosnBody = InspectJosnBody.TrimEnd(',');
|
|
foreach (string DocNo in DocNoList)
|
|
{
|
|
InspectJosnHead += "{";
|
|
InspectJosnHead += "\"ORD_ORDINE\":\"" + DocNo.TrimStart('\'').TrimEnd('\'') + "\",";
|
|
InspectJosnHead += "\"ORD_DES\":\"" + TransType + "\",";
|
|
InspectJosnHead += "\"ORD_TIPOOP\":\"P\",";
|
|
InspectJosnHead += "\"ORD_CLIENTE\":\"" + WorkPoint + "\"";
|
|
InspectJosnHead += "},";
|
|
}
|
|
InspectJosnHead = InspectJosnHead.TrimEnd(',');
|
|
if (InspectJosnBody != "")
|
|
{
|
|
InspectJosn = InspectJosn.Replace("货柜主表区域预留", InspectJosnHead);
|
|
InspectJosn = InspectJosn.Replace("货柜子表区域预留", InspectJosnBody);
|
|
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
|
|
{
|
|
string callresult = "";
|
|
#region 货柜接口调用前日志
|
|
object logID = Guid.NewGuid();
|
|
string logsql = @"insert into ICSWMS_HGLog
|
|
values
|
|
('{0}',GETDATE(),'{1}','{2}','{3}','{4}','{5}')";
|
|
logsql = string.Format(logsql, logID, InspectJosn, "", WorkPoint, MUSER, MUSERNAME);
|
|
SqlHelper.CmdExecuteNonQueryLi(logsql);
|
|
#endregion
|
|
callresult = HTTPHelper.RestFulGet(InspectJosn, postUrlStr);
|
|
#region 货柜接口调用后日志
|
|
logsql = @"update ICSWMS_HGLog set ReturnResult='{0}'
|
|
where ID='{1}'";
|
|
logsql = string.Format(logsql, callresult, logID);
|
|
SqlHelper.CmdExecuteNonQueryLi(logsql);
|
|
#endregion
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
foreach (DataRow PickLog in table.Rows)
|
|
{
|
|
pikTbLogsql += @" IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{9}' AND WorkPoint='{8}' AND TransType='15')
|
|
BEGIN
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode ,
|
|
a.WarehouseCode,a.LocationCode,'','','{3}',
|
|
'','1','15','{4}','0','',
|
|
'','','','{5}' ,'{6}' ,
|
|
'{7}' ,'{8}' ,''
|
|
FROM ICSWareHouseLotInfo a
|
|
WHERE a.LotNo='{9}' AND a.WorkPoint='{8}'
|
|
|
|
update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{9}' AND WorkPoint='{8}'
|
|
END
|
|
UPDATE {10} SET MUSER='{6}' WHERE {11}='{1}' and Sequence='{2}' ; ";
|
|
pikTbLogsql = string.Format(pikTbLogsql, Identification, PickLog["Code"].ToString(), PickLog["Sequence"].ToString(), PickLog["SendQTY"].ToString()
|
|
, BusinessCode, MUSER, MUSERNAME, pikTbLogTime, WorkPoint, PickLog["LotNO"].ToString(),updateName, cCode);
|
|
}
|
|
CmdExecuteNonQueryWithAPI(pikTbLogsql, cclogsql, ccInspectJosn, ForkLiftUrl);
|
|
#endregion
|
|
}
|
|
|
|
var result = ConvertCellToString(table);
|
|
if (Invmes.Rows.Count > 0)
|
|
{
|
|
result.Merge(Invmes, false);
|
|
}
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 工单领料推荐
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <param name="workPoint"></param>
|
|
/// <returns></returns>
|
|
public DataTable GetICSMOPickMergeByWorkorder(string Id, string workPoint)
|
|
{
|
|
string sql = $@"SELECT row_number() over (partition by c.Code,c.InvCode order by c.Code,c.InvCode,d.MTIME) AS rowNo,
|
|
c.Code,
|
|
c.InvCode,
|
|
c.InvName,
|
|
c.InvStd,
|
|
c.InvUnit,
|
|
FLOOR(c.iQuantity) AS iQuantity,
|
|
d.WarehouseCode,
|
|
d.LotNO,
|
|
FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
|
|
d.LocationCode LocationCode,
|
|
CONVERT(varchar(100),d.MTIME, 23) MTIME,
|
|
FLOOR(f.QTYTotal) QTYTotal
|
|
FROM
|
|
(select
|
|
a.ApplyCode as Code, a.InvCode, b.InvName, b.InvStd, b.InvUnit, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode,a.ExtensionID
|
|
FROM
|
|
ICSMOApply a
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.ApplyCode in ({Id}) AND a.WorkPoint = '{workPoint}'
|
|
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID) c
|
|
left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID from ICSWareHouseLotInfo d ,ICSInventoryLot m
|
|
where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
|
|
and d.WorkPoint='{workPoint}' AND d.Quantity>0 ) d on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
|
|
LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='1701' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
|
|
order by c.Code,c.InvCode,d.MTIME";
|
|
var dataset = Repository().FindDataSetBySql(sql);
|
|
if (dataset.Tables.Count == 0)
|
|
return null;
|
|
DataTable table = dataset.Tables[0];
|
|
decimal qtyCount = 0;
|
|
bool remove = false;
|
|
List<int> removeList = new List<int>();
|
|
|
|
for (int i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
if (i != 0
|
|
&& !table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString()))
|
|
{
|
|
qtyCount = 0;
|
|
remove = false;
|
|
}
|
|
if (remove)
|
|
{
|
|
removeList.Add(i);
|
|
}
|
|
else
|
|
{
|
|
var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
|
|
var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
|
|
qtyCount += lotQty;
|
|
if (qtyCount >= orderQty)
|
|
{
|
|
remove = true;
|
|
}
|
|
}
|
|
}
|
|
if (removeList.Count > 0)
|
|
{
|
|
removeList.Reverse();
|
|
foreach (var item in removeList)
|
|
{
|
|
table.Rows.RemoveAt(item);
|
|
}
|
|
}
|
|
|
|
var result = ConvertCellToString(table);
|
|
if (Invmes.Rows.Count > 0)
|
|
{
|
|
result.Merge(Invmes, false);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
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 GetICSMOPickMergeTemp2(string ID, string Type)
|
|
// {
|
|
// string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
// #region sql
|
|
// string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
|
|
// c.MergeID,
|
|
// c.Code,
|
|
// c.InvCode,
|
|
// c.InvName,
|
|
// c.InvStd,
|
|
//c.InvUnit,
|
|
// FLOOR(c.iQuantity) AS iQuantity,
|
|
// d.WarehouseCode,
|
|
// d.LocationCode,
|
|
// d.LotNO,
|
|
// FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
|
|
// CONVERT(varchar(100),d.MTIME, 23) MTIME,
|
|
// FLOOR(f.QTYTotal) QTYTotal INTO #temp
|
|
// FROM
|
|
// ({0}) c
|
|
// LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
|
|
// left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
|
|
// LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
|
|
|
|
//DECLARE @ItemCode VARCHAR(50),
|
|
// @QTY DECIMAL(18,3),
|
|
// @ItemCodeCurrent VARCHAR(50),
|
|
// @QTYCurrent DECIMAL(18,3),
|
|
// @iQuantityCurrent DECIMAL(18,3),
|
|
// @CanDelete BIT,
|
|
// @Row INT,
|
|
// @rowCurrent INT
|
|
//SET @Row = @@rowcount
|
|
//SET @rowCurrent=1
|
|
//SET @CanDelete=0
|
|
//SET @ItemCode=''
|
|
|
|
//WHILE @rowCurrent<=@Row
|
|
// BEGIN
|
|
// SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
|
|
|
|
//PRINT(@rowCurrent)
|
|
// IF @ItemCode<>@ItemCodeCurrent
|
|
// BEGIN
|
|
// SET @ItemCode=@ItemCodeCurrent
|
|
// SET @QTY=0
|
|
// SET @CanDelete=0
|
|
// END
|
|
|
|
// IF @CanDelete=1
|
|
// BEGIN
|
|
// DELETE FROM #temp WHERE rowNo=@rowCurrent
|
|
// SET @rowCurrent += 1
|
|
// CONTINUE
|
|
// END
|
|
|
|
// SET @QTY += @QTYCurrent
|
|
// IF @QTY>=@iQuantityCurrent
|
|
// BEGIN
|
|
// SET @CanDelete=1
|
|
// END
|
|
|
|
// SET @rowCurrent += 1
|
|
// END
|
|
//SELECT * FROM #temp
|
|
//DROP TABLE #temp
|
|
//";
|
|
// #endregion
|
|
// string sqls = "";
|
|
// if (Type == "1")
|
|
// {
|
|
// #region 工单备料sql
|
|
// sqls = @" select
|
|
// x.MergeID,
|
|
// c.MOCode as Code,
|
|
|
|
// a.InvCode,
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSMOPick a
|
|
// inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
// inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "2")
|
|
// {
|
|
// #region 工单领料SQL
|
|
// sqls = @" select
|
|
// x.MergeID,
|
|
// a.ApplyCode as Code,
|
|
// a.InvCode,
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
// a.ExtensionID
|
|
// FROM
|
|
// ICSMOApply a
|
|
// inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "3")
|
|
// {
|
|
// #region 工单材料出库SQL
|
|
// sqls = @" select
|
|
// x.MergeID,
|
|
// a.IssueCode as Code,
|
|
// a.InvCode,
|
|
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSMOIssue a
|
|
// inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "4")
|
|
// {
|
|
// #region 委外备料SQL
|
|
// sqls = @" select
|
|
// x.MergeID,
|
|
// c.OOCode as Code,
|
|
// a.InvCode,
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSOOPick a
|
|
// inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
// left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "5")
|
|
// {
|
|
// #region 委外领料SQL
|
|
// sqls = @" select
|
|
// x.MergeID,
|
|
// a.ApplyCode as Code,
|
|
// a.InvCode,
|
|
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSOApply a
|
|
// inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "6")
|
|
// {
|
|
// #region 委外材料出库SQL
|
|
// sqls = @" select
|
|
// x.MergeID,
|
|
// a.IssueCode as Code,
|
|
// a.InvCode,
|
|
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSOIssue a
|
|
// inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "7")
|
|
// {
|
|
// #region 销售发货SQL
|
|
// sqls = @" select
|
|
// x.MergeID,
|
|
// a.SDNCode as Code,
|
|
// a.InvCode,
|
|
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSSDN a
|
|
// inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "8")
|
|
// {
|
|
// #region 其它出库SQL
|
|
// sqls = @" select
|
|
// x.MergeID,
|
|
// a.OutCode as Code,
|
|
// a.InvCode,
|
|
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSOtherOut a
|
|
// inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "9")
|
|
// {
|
|
// #region 借用SQL
|
|
// sqls = @" select
|
|
// x.MergeID,
|
|
// a.BrrowCode as Code,
|
|
// a.InvCode,
|
|
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSBrrow a
|
|
// inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "10")
|
|
// {
|
|
// #region 物料调拨
|
|
// sqls = @" select
|
|
// x.MergeID,
|
|
// a.TransferNO as Code,
|
|
// a.InvCode,
|
|
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
//b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.FromWarehouseCode as WhCode,
|
|
//a.ExtensionID
|
|
// FROM
|
|
// ICSTransfer a
|
|
// inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
|
|
// #endregion
|
|
// }
|
|
// if (Type == "11")
|
|
// {
|
|
// #region 两步调出
|
|
// sqls = @"select
|
|
// x.MergeID,
|
|
// a.OutCode as Code,
|
|
// a.InvCode,
|
|
// b.InvName,
|
|
// b.InvStd,
|
|
// b.InvUnit,
|
|
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
// a.WHCode as WhCode,
|
|
// a.ExtensionID
|
|
// FROM
|
|
// ICSOtherOut a
|
|
// INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
|
|
// inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
// WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
|
|
// GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
|
|
// #endregion
|
|
// }
|
|
|
|
|
|
// sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
|
|
// sql = string.Format(sql, sqls, WorkPoint);
|
|
// 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 (Invmes.Rows.Count > 0)
|
|
// {
|
|
// dtCloned.Merge(Invmes, false);
|
|
// }
|
|
// return dtCloned;
|
|
// }
|
|
public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
|
|
string sqls = "";
|
|
if (Type == "1")
|
|
{
|
|
#region 工单备料sql
|
|
sqls = @" select
|
|
x.MergeID,
|
|
c.MOCode as Code,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSMOPick a
|
|
inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
|
|
#endregion
|
|
}
|
|
if (Type == "2" || Type == "12")
|
|
{
|
|
#region 工单领料SQL
|
|
sqls = @" select
|
|
x.MergeID,
|
|
a.ApplyCode as Code,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSMOApply a
|
|
inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
|
|
#endregion
|
|
}
|
|
if (Type == "3")
|
|
{
|
|
#region 工单材料出库SQL
|
|
sqls = @" select
|
|
x.MergeID,
|
|
a.IssueCode as Code,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSMOIssue a
|
|
inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
#endregion
|
|
}
|
|
if (Type == "4")
|
|
{
|
|
#region 委外备料SQL
|
|
sqls = @" select
|
|
x.MergeID,
|
|
c.OOCode as Code,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSOOPick a
|
|
inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
|
|
#endregion
|
|
}
|
|
if (Type == "5")
|
|
{
|
|
#region 委外领料SQL
|
|
sqls = @" select
|
|
x.MergeID,
|
|
a.ApplyCode as Code,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSOApply a
|
|
inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
#endregion
|
|
}
|
|
if (Type == "6")
|
|
{
|
|
#region 委外材料出库SQL
|
|
sqls = @" select
|
|
x.MergeID,
|
|
a.IssueCode as Code,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSOIssue a
|
|
inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
#endregion
|
|
}
|
|
if (Type == "7")
|
|
{
|
|
#region 销售发货SQL
|
|
sqls = @" select
|
|
x.MergeID,
|
|
a.SDNCode as Code,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSSDN a
|
|
inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}' AND a.Type='1'
|
|
GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
#endregion
|
|
}
|
|
if (Type == "8")
|
|
{
|
|
#region 其它出库SQL
|
|
sqls = @" select
|
|
x.MergeID,
|
|
a.OutCode as Code,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSOtherOut a
|
|
inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
#endregion
|
|
}
|
|
if (Type == "9")
|
|
{
|
|
#region 借用SQL
|
|
sqls = @" select
|
|
x.MergeID,
|
|
a.BrrowCode as Code,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSBrrow a
|
|
inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
|
|
#endregion
|
|
}
|
|
if (Type == "10")
|
|
{
|
|
#region 物料调拨
|
|
sqls = @" select
|
|
x.MergeID,
|
|
a.TransferNO as Code,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.FromWarehouseCode as WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSTransfer a
|
|
inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
|
|
#endregion
|
|
}
|
|
if (Type == "11")
|
|
{
|
|
#region 两步调出
|
|
sqls = @" select
|
|
x.MergeID,
|
|
a.OutCode as Code,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
b.InvUnit,
|
|
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
|
|
a.WHCode as WhCode,
|
|
a.ExtensionID
|
|
FROM
|
|
ICSOtherOut a
|
|
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
|
|
inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
|
|
GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
|
|
#endregion
|
|
}
|
|
|
|
|
|
sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
|
|
#region sql
|
|
string sql = $@"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
|
|
c.MergeID,
|
|
c.Code,
|
|
c.InvCode,
|
|
c.InvName,
|
|
c.InvStd,
|
|
c.InvUnit,
|
|
FLOOR(c.iQuantity) AS iQuantity,
|
|
d.WarehouseCode,
|
|
d.LocationCode,
|
|
d.LotNO,
|
|
FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
|
|
CONVERT(varchar(100),d.MTIME, 23) MTIME,
|
|
FLOOR(f.QTYTotal) QTYTotal
|
|
FROM
|
|
({sqls}) c
|
|
left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
|
|
from ICSWareHouseLotInfo d ,ICSInventoryLot m
|
|
where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
|
|
and d.WorkPoint='{WorkPoint}' AND d.Quantity>0 ) d
|
|
on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
|
|
LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
|
|
order by c.Code,c.InvCode,d.MTIME ";
|
|
#endregion
|
|
var dataset = Repository().FindDataSetBySql(sql);
|
|
if (dataset.Tables.Count == 0)
|
|
return null;
|
|
DataTable table = dataset.Tables[0];
|
|
decimal qtyCount = 0;
|
|
bool remove = false;
|
|
List<int> removeList = new List<int>();
|
|
for (int i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
|
|
if (i != 0
|
|
&& (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
|
|
|| !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString()))
|
|
)
|
|
{
|
|
qtyCount = 0;
|
|
remove = false;
|
|
}
|
|
if (remove)
|
|
{
|
|
removeList.Add(i);
|
|
}
|
|
else
|
|
{
|
|
var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
|
|
var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
|
|
qtyCount += lotQty;
|
|
if (qtyCount >= orderQty)
|
|
{
|
|
remove = true;
|
|
}
|
|
}
|
|
}
|
|
if (removeList.Count > 0)
|
|
{
|
|
removeList.Reverse();
|
|
foreach (var item in removeList)
|
|
{
|
|
table.Rows.RemoveAt(item);
|
|
}
|
|
}
|
|
|
|
var result = ConvertCellToString(table);
|
|
if (Invmes.Rows.Count > 0)
|
|
{
|
|
result.Merge(Invmes, false);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
public string MergeMaterial(string keyValue, 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;
|
|
string msg = "";
|
|
string sql = string.Empty;
|
|
|
|
string dataList = string.Empty;
|
|
List<string> arry = keyValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
|
if (arry.Count > 0)
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
foreach (var i in arry)
|
|
{
|
|
stringBuilder.Append($@"'{i}',");
|
|
}
|
|
dataList = stringBuilder.ToString(0, stringBuilder.Length - 1);
|
|
}
|
|
|
|
|
|
Int64 Merge_ID = 0;
|
|
DateTime time = DateTime.Now;
|
|
string Tday = time.ToString("yyyyMMdd");
|
|
string sqls = string.Format(@"SELECT MAX(A.MergeID) AS SourceID FROM ICSMOPickMerge A WHERE A.MergeID LIKE '{0}%' AND LEN(a.MergeID) = 13", Tday);
|
|
DataSet ds = SqlHelper.GetDataSetBySql(sqls);
|
|
DataTable dts = ds.Tables[0];
|
|
if (dts != null && dts.Rows.Count > 0)
|
|
{
|
|
string lot = dts.Rows[0]["SourceID"].ToString();
|
|
if (!string.IsNullOrWhiteSpace(lot))
|
|
Merge_ID = Convert.ToInt64(lot.Substring(lot.Length - 5));
|
|
}
|
|
string MergeID = Tday + (Merge_ID + 1).ToString().PadLeft(5, '0');
|
|
|
|
|
|
string order = string.Empty;
|
|
string orderCode = string.Empty;
|
|
string quantity = string.Empty;
|
|
string sqlString1 = string.Empty;
|
|
string sqlString2 = string.Empty;
|
|
|
|
|
|
if (Type == "1")//工单备料
|
|
{
|
|
sql += @"INSERT INTO dbo.ICSMOPickMerge
|
|
( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
|
|
select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
|
|
from ICSMO a inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
|
|
where a.MOCode in ({5})
|
|
";
|
|
}
|
|
if (Type == "2")//工单发料
|
|
{
|
|
order = "ICSMOApply";
|
|
orderCode = "b.ApplyCode";
|
|
quantity = "b.IssueQuantity";
|
|
|
|
sql += @"INSERT INTO dbo.ICSMOPickMerge
|
|
( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
|
|
select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.ApplyCode
|
|
from ICSMOApply a
|
|
where a.ApplyCode in ({5})";
|
|
}
|
|
if (Type == "3")//材料出库
|
|
{
|
|
sql += @"INSERT INTO dbo.ICSMOPickMerge
|
|
( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
|
|
select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
|
|
from ICSMOIssue a
|
|
where a.IssueCode in ({5}) ";
|
|
}
|
|
if (Type == "4")//委外备料
|
|
{
|
|
sql += @"INSERT INTO dbo.ICSMOPickMerge
|
|
( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
|
|
select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
|
|
from ICSOutsourcingOrder a inner join ICSOOPick b on a.OODetailID=b.OODetailID and b.WorkPoint=a.WorkPoint
|
|
where a.OOCode in ({5})";
|
|
}
|
|
if (Type == "5")//委外领料
|
|
{
|
|
order = "ICSOApply";
|
|
orderCode = "b.ApplyCode";
|
|
quantity = "b.IssueQuantity";
|
|
sql += @"INSERT INTO dbo.ICSMOPickMerge
|
|
( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
|
|
select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.ApplyCode
|
|
from ICSOApply a
|
|
where a.ApplyCode in ({5})";
|
|
}
|
|
if (Type == "6")//委外材料出库
|
|
{
|
|
sql += @"INSERT INTO dbo.ICSMOPickMerge
|
|
( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
|
|
select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
|
|
from ICSOIssue a
|
|
where a.IssueCode in ({5})";
|
|
}
|
|
if (Type == "7")//销售发货
|
|
{
|
|
order = "ICSSDN";
|
|
orderCode = "b.SDNCode";
|
|
quantity = "b.SDNQuantity";
|
|
sql += @"INSERT INTO dbo.ICSMOPickMerge
|
|
( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
|
|
select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.SDNCode
|
|
from ICSSDN a
|
|
where a.SDNCode in ({5}) AND a.Type='1' ";
|
|
}
|
|
if (Type == "8")//其它出库
|
|
{
|
|
order = "ICSOtherOut";
|
|
orderCode = "b.OutCode";
|
|
quantity = "b.OutQuantity";
|
|
sql += @"INSERT INTO dbo.ICSMOPickMerge
|
|
( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
|
|
select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.OutCode
|
|
from ICSOtherOut a
|
|
where a.OutCode in ({5})";
|
|
}
|
|
if (Type == "9")//借用单
|
|
{
|
|
sql += @"INSERT INTO dbo.ICSMOPickMerge
|
|
( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
|
|
select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
|
|
from ICSBrrow a
|
|
where a.BrrowCode in ({5})";
|
|
}
|
|
if (Type == "10")//物料调拨
|
|
{
|
|
order = "ICSTransfer";
|
|
orderCode = "b.TransferNO";
|
|
quantity = "b.TransferQuantity";
|
|
sql += @"INSERT INTO dbo.ICSMOPickMerge
|
|
( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
|
|
select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.TransferNO
|
|
from ICSTransfer a
|
|
where a.TransferNO in ({5})
|
|
";
|
|
}
|
|
if (Type == "11")//两步调出
|
|
{
|
|
sql += @" INSERT INTO dbo.ICSMOPickMerge
|
|
( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
|
|
select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
|
|
from ICSOtherOut a
|
|
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
|
|
where a.OutCode in ({5})
|
|
";
|
|
}
|
|
sql = string.Format(sql, MergeID, Type, MUSER, MUSERNAME, WorkPoint, dataList);
|
|
sqlString1 += $@" SELECT a.ID FROM ICSMOPickMerge a WHERE a.SourceID IN (SELECT b.ID FROM {order} b WHERE {orderCode} IN({dataList}) )";
|
|
sqlString2 += $@" SELECT b.ID FROM {order} b WHERE {orderCode} IN({dataList}) AND {quantity}>0";
|
|
DataSet ds1 = SqlHelper.GetDataSetBySql(sqlString1);
|
|
DataSet ds2 = SqlHelper.GetDataSetBySql(sqlString2);
|
|
DataTable dts1 = ds1.Tables[0];
|
|
DataTable dts2 = ds2.Tables[0];
|
|
if ((dts1 != null && dts1.Rows.Count > 0))
|
|
{
|
|
|
|
}
|
|
else if (dts2 != null && dts2.Rows.Count > 0)
|
|
{
|
|
msg = "当前选择单据号存在已出库的单据号,合并 失败";
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
|
|
if (SqlHelper.CmdExecuteNonQueryLi(sql) == 0)
|
|
{
|
|
msg = "新增失败";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
public string CancelMergeMaterial(string keyValue, string Type)
|
|
{
|
|
string msg = "";
|
|
string sql = string.Empty;
|
|
keyValue = keyValue.TrimEnd(',');
|
|
List<string> arry = keyValue.Split(',').ToList();
|
|
string dataList = string.Empty;
|
|
if (arry.Count > 0)
|
|
{
|
|
foreach (var i in arry)
|
|
{
|
|
dataList += $@"'{i}',";
|
|
}
|
|
if (dataList.Any())
|
|
{
|
|
dataList = dataList.TrimEnd(',');
|
|
}
|
|
}
|
|
string sqls = $@" SELECT SourceID FROM ICSMOPickMerge WHERE EATTRIBUTE1 IN({dataList}) ";
|
|
DataSet ds = SqlHelper.GetDataSetBySql(sqls);
|
|
|
|
DataTable dts = ds.Tables[0];
|
|
|
|
if (dts == null || dts.Rows.Count <= 0)
|
|
{
|
|
msg = "当前单据未合并拣料,取消合并拣料失败";
|
|
return msg;
|
|
}
|
|
string sqlStrring = string.Empty;
|
|
if (Type == "2")//工单发料
|
|
{
|
|
sqlStrring = $@"select ID from ICSMOApply a where a.ID in ({sqls}) and a.IssueQuantity=0 ";
|
|
}
|
|
|
|
if (Type == "5")//委外领料
|
|
{
|
|
sqlStrring = $@"select ID from ICSOApply a where a.ID in ({sqls}) and a.IssueQuantity=0 ";
|
|
}
|
|
if (Type == "7")//销售发货
|
|
{
|
|
sqlStrring = $@"select ID from ICSSDN a where a.ID in ({sqls}) and a.SDNQuantity=0 AND a.Type='1' ";
|
|
}
|
|
if (Type == "8")//其它出库
|
|
{
|
|
sqlStrring = $@"select ID
|
|
from ICSOtherOut a
|
|
where a.ID in ({sqls}) and a.OutQuantity=0";
|
|
}
|
|
|
|
if (Type == "10")//物料调拨
|
|
{
|
|
sqlStrring = $@"select ID from ICSTransfer a where a.ID in ({sqls}) and a.TransferQuantity=0 ";
|
|
}
|
|
DataSet dsdata = SqlHelper.GetDataSetBySql(sqlStrring);
|
|
|
|
DataTable dtdsdatas = dsdata.Tables[0];
|
|
|
|
if (dtdsdatas == null || dtdsdatas.Rows.Count <= 0)
|
|
{
|
|
msg = "当前物料已经出库,取消合并失败";
|
|
return msg;
|
|
}
|
|
|
|
sql = $@"DELETE FROM ICSMOPickMerge WHERE SourceID IN({sqls})";
|
|
try
|
|
{
|
|
|
|
if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
msg = "取消合并失败";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
|
|
return msg;
|
|
}
|
|
|
|
public string CheckQty(string objArr)
|
|
{
|
|
objArr = objArr.TrimEnd(',');
|
|
string sql = @"select * from ICSMOPickMerge a
|
|
left join ICSMOPick b on a.SourceID=b.ID and a.WorkPoint=b.WorkPoint
|
|
left join ICSMO c on b.MODetailID=c.MODetailID and b.WorkPoint=c.WorkPoint
|
|
where MOCode in ({0})";
|
|
sql = string.Format(sql, objArr);
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
return "1";
|
|
}
|
|
|
|
|
|
return "0";
|
|
|
|
}
|
|
|
|
|
|
//删除占料
|
|
public string DelPickLog(string objCode)
|
|
{
|
|
//站点信息
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
string msg = "";
|
|
objCode = objCode.Substring(1, objCode.Length - 2);
|
|
string sql = string.Empty;
|
|
|
|
// sql += string.Format(@"update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),a.Quantity )
|
|
//from dbo.ICSWareHouseLotInfoLog a
|
|
//left join dbo.ICSWareHouseLotInfo b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
|
|
// where a.TransCode in ({0}) and a.TransType='15' and a.WorkPoint='{1}'", objCode.TrimEnd(','), WorkPoint);
|
|
sql += string.Format(@" update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),c.Quantity )
|
|
from dbo.ICSWareHouseLotInfo b
|
|
inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where TransCode in ({0})and TransType='15' and WorkPoint='{1}' group by LotNo) c
|
|
on c.LotNo =b.LotNo ", objCode.TrimEnd(','), WorkPoint);
|
|
|
|
sql += string.Format(@" delete dbo.ICSWareHouseLotInfoLog where TransCode in({0}) and TransType='15' and WorkPoint='{1}'", objCode.TrimEnd(','), WorkPoint);
|
|
try
|
|
{
|
|
if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
|
|
{
|
|
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
public int SeachPickLog(string objCode)
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
objCode = objCode.TrimEnd(',');
|
|
string[] parameters = objCode.Split(',');
|
|
int parameterCount = parameters.Length;
|
|
string sql = @" select distinct a.TransCode from dbo.ICSWareHouseLotInfoLog a
|
|
left join dbo.ICSWareHouseLotInfo b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
|
|
where a.TransCode in ({0}) and a.TransType='15' and a.WorkPoint='{1}'";
|
|
sql = string.Format(sql, objCode, WorkPoint);
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
int count = dt.Rows.Count;
|
|
return count;
|
|
|
|
|
|
|
|
}
|
|
//添加打印次数
|
|
public int PrintCount(string objCode, string type)
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
string MUser = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string MUserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
var date = DateTime.Now;
|
|
objCode = objCode.TrimEnd(',');
|
|
string[] parameters = objCode.Split(',');
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach (var data in parameters)
|
|
{
|
|
sb.Append($@"IF EXISTS (SELECT ID FROM ICSPrintCount WHERE TransCode={data} )
|
|
BEGIN
|
|
UPDATE ICSPrintCount SET PrintCount=PrintCount+1 WHERE TransCode={data}
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
INSERT INTO ICSPrintCount VALUES(NEWID(),{data},1,'{type}','{WorkPoint}','{MUser}','{MUserName}','{date}')
|
|
END
|
|
;"
|
|
);
|
|
|
|
}
|
|
if (sb.IsEmpty())
|
|
{
|
|
return 0;
|
|
}
|
|
int count = SqlHelper.ExecuteNonQuery(sb.ToString());
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
public DataTable GetPickLogInfo(string ID, ref Pagination jqgridparam)
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
DataTable dt = new DataTable();
|
|
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = @"
|
|
select '' as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
|
|
a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
|
|
from dbo.ICSWareHouseLotInfoLog a
|
|
left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
|
|
left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
|
|
where a.TransCode in ({0}) and a.TransType='15' and a.WorkPoint='{1}'";
|
|
|
|
sql = string.Format(sql, ID.TrimEnd(','), WorkPoint);
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
public class LotMessage
|
|
{
|
|
public string LotNo { get; set; }
|
|
public decimal Quantity { get; set; }
|
|
|
|
}
|
|
|
|
//事务中执行SQL及调用接口
|
|
public static int CmdExecuteNonQueryWithAPI(string sql, string ccsql, string InputJson, string PostUrl, params SqlParameter[] spArr)
|
|
{
|
|
using (SqlConnection conn = SqlHelper.GetDataCenterConn())
|
|
{
|
|
conn.Open();
|
|
SqlTransaction sqlTran = conn.BeginTransaction();
|
|
SqlCommand cmd = new SqlCommand();
|
|
cmd.Transaction = sqlTran;
|
|
cmd.Connection = conn;
|
|
try
|
|
{
|
|
if (ccsql == "")
|
|
{
|
|
cmd.CommandText = sql;
|
|
int RES = cmd.ExecuteNonQuery();
|
|
cmd.Transaction.Commit();
|
|
return RES;
|
|
}
|
|
else
|
|
{
|
|
cmd.CommandText = sql;
|
|
int RES = cmd.ExecuteNonQuery();
|
|
cmd.CommandText = ccsql;
|
|
RES = cmd.ExecuteNonQuery();
|
|
#region 叉车接口调用(写进事务中,报错可以回滚,保证数据正确)
|
|
string rest = HTTPHelper.HttpPost("WMS调用叉车接口出库", PostUrl, InputJson);
|
|
ForkLiftResult result = JsonConvert.DeserializeObject<ForkLiftResult>(rest);
|
|
if (result.Ret == 1)
|
|
{
|
|
cmd.Transaction.Commit();
|
|
return RES;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception(result.RetMsg);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
cmd.Transaction.Rollback();
|
|
throw new Exception(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
if (conn.State != ConnectionState.Closed)
|
|
{
|
|
conn.Close();
|
|
conn.Dispose();
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|