纽威
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.

3094 lines
161 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. namespace NFine.Application.WMS
  18. {
  19. public class PickMaterialApp : RepositoryFactory<ICSVendor>
  20. {
  21. public static DataTable Invmes = new DataTable();
  22. //工单备料(工单子件)
  23. public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
  24. {
  25. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  26. DataTable dt = new DataTable();
  27. var queryParam = queryJson.ToJObject();
  28. List<DbParameter> parameter = new List<DbParameter>();
  29. StringBuilder sqlstring = new StringBuilder();
  30. #region [SQL]
  31. // 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,
  32. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  33. //from ICSMOPick a
  34. //left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  35. //left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  36. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  37. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  38. // sql += " WHERE 1=1 and e.ID is null";
  39. sqlstring.Append($@"select a.MOCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,
  40. case when max(d.SourceID) is null then '' else '' end as IsNew,
  41. f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,
  42. f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  43. from ICSMO a
  44. inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  45. left join ICSMOPickMerge d on d.SourceID=b.ID and d.WorkPoint=b.WorkPoint
  46. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  47. where a.WorkPoint='{WorkPoint}' ");
  48. if (!string.IsNullOrWhiteSpace(queryJson))
  49. {
  50. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  51. {
  52. sqlstring.Append($" and a.MOCode like '%{queryParam["POCode"]}%' ");
  53. }
  54. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  55. {
  56. sqlstring.Append($" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  57. }
  58. }
  59. sqlstring.Append(@" group by a.MOCode, a.WorkPoint,a.CreateDateTime,a.createperson,f.Colspan,f.ProjectCode,
  60. f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4,
  61. f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10");
  62. #endregion
  63. return Repository().FindTablePageBySql(sqlstring.ToString(), parameter.ToArray(), ref jqgridparam);
  64. }
  65. //工单备料(工单子件)子表查询
  66. public DataTable GetSubGridJson1(string Code)
  67. {
  68. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  69. DataTable dt = new DataTable();
  70. //var queryParam = queryJson.ToJObject();
  71. List<DbParameter> parameter = new List<DbParameter>();
  72. 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,
  73. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  74. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  75. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  76. from ICSMOPick a
  77. left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  78. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  79. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  80. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  81. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  82. where b.MOCode='{0}' and a.WorkPoint='{1}'";
  83. sql = string.Format(sql, Code, WorkPoint);
  84. return Repository().FindTableBySql(sql.ToString());
  85. }
  86. //工单领料(发料申请)
  87. public DataTable GetGridJson2(string queryJson, ref Pagination jqgridparam)
  88. {
  89. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  90. DataTable dt = new DataTable();
  91. var queryParam = queryJson.ToJObject();
  92. List<DbParameter> parameter = new List<DbParameter>();
  93. StringBuilder sqlString = new StringBuilder();
  94. #region [SQL]
  95. // 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,
  96. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  97. // from ICSMOApply a
  98. // left join ICSWarehouse b on a.WHCode = b.WarehouseCode and a.WorkPoint = b.WorkPoint
  99. // left join ICSInventory d on a.InvCode = d.InvCode and a.WorkPoint = d.WorkPoint
  100. // left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  101. sqlString.Append($@"
  102. SELECT * from (select row_number() over(partition by a.ApplyCode ORDER BY a.ApplyCode) as row,
  103. a.ApplyCode as Code,CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,a.createperson as MUSER,a.WHCode,detail.LocationCode AS Area,
  104. a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  105. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
  106. case when max(e.SourceID) is null then '' else '' end as IsNew,f.Colspan ,
  107. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  108. case when sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName != 'JOB' then ''
  109. else (case when sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName = 'JOB' then '' else '' end) end as Status,
  110. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,
  111. f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.ID,
  112. case when a.MUSER!= 'JOB' then a.MUSER else '' end AS PickName
  113. from ICSMOApply a
  114. left JOIN ICSInventory b ON b.InvCode=a.InvCode
  115. LEFT JOIN ICSInventoryDetail detail ON b.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  116. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  117. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  118. 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'
  119. where a.WorkPoint='{WorkPoint}' and a.EATTRIBUTE!='17'");
  120. if (!string.IsNullOrWhiteSpace(queryJson))
  121. {
  122. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  123. {
  124. sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
  125. }
  126. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  127. {
  128. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  129. }
  130. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  131. {
  132. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  133. }
  134. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  135. {
  136. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  137. }
  138. if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
  139. {
  140. sqlString.Append($@" and a.OrderNumber like '%{queryParam["Order"]}%' ");
  141. }
  142. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  143. {
  144. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  145. WHERE
  146. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  147. }
  148. if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
  149. {
  150. sqlString.Append($@" and a.CreateDateTime >='{queryParam["CreateDate"].ToDate()}' and a.CreateDateTime <'{queryParam["CreateDate"].ToDate().AddDays(+1)}' ");
  151. }
  152. if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
  153. {
  154. sqlString.Append($@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ");
  155. }
  156. if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
  157. {
  158. if (queryParam["NeedDate"].ToString() == "3")
  159. {
  160. sqlString.Append($@" and sum(a.Quantity) = sum(IssueQuantity) and a.MUSERName != 'JOB ");
  161. }
  162. else if (queryParam["NeedDate"].ToString() == "2")
  163. {
  164. sqlString.Append($@" and sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName = 'JOB' ");
  165. }
  166. else if (queryParam["NeedDate"].ToString() == "1")
  167. {
  168. sqlString.Append($@" and sum(a.Quantity) >= sum(IssueQuantity) ");
  169. }
  170. }
  171. }
  172. sqlString.Append(@" group by a.ApplyCode, a.WorkPoint,a.IssueQuantity,a.CreateDateTime,a.createperson,
  173. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  174. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.WHCode,detail.LocationCode,a.ID,a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  175. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,a.MUSERName,a.MUSER ) as t where t.row=1");
  176. if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
  177. {
  178. if (queryParam["Status"].ToString() == "3")
  179. {
  180. sqlString.Append($@" AND t.Status='已过账' ");
  181. }
  182. else if (queryParam["Status"].ToString() == "2")
  183. {
  184. sqlString.Append($@" AND t.Status='已配料' ");
  185. }
  186. else if (queryParam["Status"].ToString() == "1")
  187. {
  188. sqlString.Append($@" AND t.Status='未配料' ");
  189. }
  190. }
  191. #endregion
  192. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  193. }
  194. //工单领料(发料申请)子表查询
  195. public DataTable GetSubGridJson2(string queryJson, string Code)
  196. {
  197. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  198. DataTable dt = new DataTable();
  199. var queryParam = queryJson.ToJObject();
  200. List<DbParameter> parameter = new List<DbParameter>();
  201. string sql = @"SELECT * FROM (select row_number() over(partition by a.ApplyCode,a.InvCode,a.Sequence ORDER BY a.ApplyCode) as row,
  202. a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,a.OrderNumber,
  203. a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  204. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
  205. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,detail.LocationCode AS Area,
  206. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  207. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  208. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  209. from ICSMOApply a
  210. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  211. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  212. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  213. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  214. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  215. where a.ApplyCode='{0}' and a.WorkPoint='{1}' and a.EATTRIBUTE!='17'";
  216. if (!string.IsNullOrWhiteSpace(queryJson))
  217. {
  218. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  219. {
  220. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  221. }
  222. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  223. {
  224. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  225. }
  226. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  227. {
  228. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  229. }
  230. if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
  231. {
  232. sql += $@" and a.OrderNumber like '%{queryParam["Order"]}%' ";
  233. }
  234. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  235. {
  236. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  237. WHERE
  238. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  239. }
  240. if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
  241. {
  242. sql += $@" and a.CreateDateTime like '%{queryParam["CreateDate"]}%' ";
  243. }
  244. if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
  245. {
  246. sql += $@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ";
  247. }
  248. }
  249. sql += " ) c WHERE c.row=1 ";
  250. sql = string.Format(sql, Code, WorkPoint);
  251. return Repository().FindTableBySql(sql.ToString());
  252. }
  253. //售后领料
  254. public DataTable GetGridJson12(string queryJson, ref Pagination jqgridparam)
  255. {
  256. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  257. DataTable dt = new DataTable();
  258. var queryParam = queryJson.ToJObject();
  259. List<DbParameter> parameter = new List<DbParameter>();
  260. StringBuilder sqlString = new StringBuilder();
  261. #region [SQL]
  262. // 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,
  263. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  264. // from ICSMOApply a
  265. // left join ICSWarehouse b on a.WHCode = b.WarehouseCode and a.WorkPoint = b.WorkPoint
  266. // left join ICSInventory d on a.InvCode = d.InvCode and a.WorkPoint = d.WorkPoint
  267. // left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  268. sqlString.Append($@"
  269. SELECT * from (select row_number() over(partition by a.ApplyCode ORDER BY a.ApplyCode) as row,
  270. a.ApplyCode as Code,CONVERT(varchar(100),a.CreateDateTime,23) as MTIME ,a.createperson MUSER,a.WHCode,detail.LocationCode AS Area,
  271. a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  272. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
  273. case when max(e.SourceID) is null then '' else '' end as IsNew,f.Colspan ,
  274. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  275. case when sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName != 'JOB' then ''
  276. else (case when sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName = 'JOB' then '' else '' end) end as Status,
  277. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,
  278. f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.ID
  279. from ICSMOApply a
  280. left JOIN ICSInventory b ON b.InvCode=a.InvCode
  281. LEFT JOIN ICSInventoryDetail detail ON b.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  282. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  283. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  284. 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'
  285. where a.WorkPoint='{WorkPoint}' and a.EATTRIBUTE='17' ");
  286. if (!string.IsNullOrWhiteSpace(queryJson))
  287. {
  288. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  289. {
  290. sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
  291. }
  292. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  293. {
  294. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  295. }
  296. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  297. {
  298. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  299. }
  300. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  301. {
  302. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  303. }
  304. if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
  305. {
  306. sqlString.Append($@" and a.OrderNumber like '%{queryParam["Order"]}%' ");
  307. }
  308. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  309. {
  310. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  311. WHERE
  312. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  313. }
  314. if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
  315. {
  316. sqlString.Append($@" and a.CreateDateTime >='{queryParam["CreateDate"].ToDate()}' and a.CreateDateTime <'{queryParam["CreateDate"].ToDate().AddDays(+1)}' ");
  317. }
  318. if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
  319. {
  320. sqlString.Append($@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ");
  321. }
  322. if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
  323. {
  324. if (queryParam["NeedDate"].ToString() == "3")
  325. {
  326. sqlString.Append($@" and sum(a.Quantity) = sum(IssueQuantity) and a.MUSERName != 'JOB ");
  327. }
  328. else if (queryParam["NeedDate"].ToString() == "2")
  329. {
  330. sqlString.Append($@" and sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName = 'JOB' ");
  331. }
  332. else if (queryParam["NeedDate"].ToString() == "1")
  333. {
  334. sqlString.Append($@" and sum(a.Quantity) >= sum(IssueQuantity) ");
  335. }
  336. }
  337. }
  338. sqlString.Append(@" group by a.ApplyCode, a.WorkPoint,a.IssueQuantity,a.CreateDateTime,a.createperson,
  339. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  340. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.WHCode,detail.LocationCode,a.ID,a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  341. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,a.MUSERName) as t where t.row=1");
  342. if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
  343. {
  344. if (queryParam["Status"].ToString() == "3")
  345. {
  346. sqlString.Append($@" AND t.Status='已过帐' ");
  347. }
  348. else if (queryParam["Status"].ToString() == "2")
  349. {
  350. sqlString.Append($@" AND t.Status='已配料' ");
  351. }
  352. else if (queryParam["Status"].ToString() == "1")
  353. {
  354. sqlString.Append($@" AND t.Status='未配料' ");
  355. }
  356. }
  357. #endregion
  358. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  359. }
  360. //售后领料(子表查询)
  361. public DataTable GetSubGridJson12(string queryJson, string Code)
  362. {
  363. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  364. DataTable dt = new DataTable();
  365. var queryParam = queryJson.ToJObject();
  366. List<DbParameter> parameter = new List<DbParameter>();
  367. string sql = @"SELECT * FROM (select row_number() over(partition by a.ApplyCode,a.InvCode,a.Sequence ORDER BY a.ApplyCode) as row,
  368. a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,a.OrderNumber,
  369. a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  370. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
  371. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,detail.LocationCode AS Area,
  372. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  373. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  374. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  375. from ICSMOApply a
  376. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  377. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  378. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  379. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  380. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  381. where a.ApplyCode='{0}' and a.WorkPoint='{1}' and a.EATTRIBUTE='17'";
  382. if (!string.IsNullOrWhiteSpace(queryJson))
  383. {
  384. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  385. {
  386. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  387. }
  388. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  389. {
  390. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  391. }
  392. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  393. {
  394. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  395. }
  396. if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
  397. {
  398. sql += $@" and a.OrderNumber like '%{queryParam["Order"]}%' ";
  399. }
  400. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  401. {
  402. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  403. WHERE
  404. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  405. }
  406. if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
  407. {
  408. sql += $@" and a.CreateDateTime like '%{queryParam["CreateDate"]}%' ";
  409. }
  410. if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
  411. {
  412. sql += $@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ";
  413. }
  414. }
  415. sql += " ) c WHERE c.row=1 ";
  416. sql = string.Format(sql, Code, WorkPoint);
  417. return Repository().FindTableBySql(sql.ToString());
  418. }
  419. //工单材料出库(材料出库)
  420. public DataTable GetGridJson3(string queryJson, ref Pagination jqgridparam)
  421. {
  422. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  423. DataTable dt = new DataTable();
  424. var queryParam = queryJson.ToJObject();
  425. List<DbParameter> parameter = new List<DbParameter>();
  426. StringBuilder sqlString = new StringBuilder();
  427. #region [SQL]
  428. // 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,
  429. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  430. // from ICSMOIssue a
  431. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  432. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  433. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint ";
  434. // sql += " WHERE 1=1 and e.ID is null";
  435. sqlString.Append($@"SELECT * FROM(SELECT row_number ( ) OVER ( partition BY a.IssueCode ORDER BY a.IssueCode ) AS row,
  436. a.IssueCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,
  437. case when max(e.SourceID) is null then '' else ''
  438. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  439. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  440. from ICSMOIssue a
  441. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  442. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  443. where a.WorkPoint = '{WorkPoint}' ");
  444. if (!string.IsNullOrWhiteSpace(queryJson))
  445. {
  446. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  447. {
  448. sqlString.Append($@" and a.IssueCode like '%{queryParam["POCode"]}%' ");
  449. }
  450. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  451. {
  452. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  453. }
  454. }
  455. sqlString.Append(@"group by a.IssueCode,a.CreateDateTime,a.createperson,f.Colspan,f.ProjectCode,f.BatchCode,
  456. f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  457. f.cFree8, f.cFree9, f.cFree10 ) AS t WHERE t.row= 1 ");
  458. #endregion
  459. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  460. }
  461. //工单材料出库(材料出库)子表查询
  462. public DataTable GetSubGridJson3(string Code)
  463. {
  464. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  465. DataTable dt = new DataTable();
  466. //var queryParam = queryJson.ToJObject();
  467. List<DbParameter> parameter = new List<DbParameter>();
  468. 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,
  469. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  470. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  471. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  472. from ICSMOIssue a
  473. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  474. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  475. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  476. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  477. where a.IssueCode='{0}' and a.WorkPoint='{1}'";
  478. sql = string.Format(sql, Code, WorkPoint);
  479. return Repository().FindTableBySql(sql.ToString());
  480. }
  481. //委外备料(委外备料)
  482. public DataTable GetGridJson4(string queryJson, ref Pagination jqgridparam)
  483. {
  484. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  485. DataTable dt = new DataTable();
  486. var queryParam = queryJson.ToJObject();
  487. List<DbParameter> parameter = new List<DbParameter>();
  488. StringBuilder sqlString = new StringBuilder();
  489. #region [SQL]
  490. sqlString.Append($@"select * from (select row_number() over(partition by b.OOCode order by b.OOCode) row, b.OOCode as Code,
  491. b.CreateDateTime as MTIME,
  492. b.CreatePerson as MUSER,
  493. case
  494. when max(e.SourceID) is null then ''
  495. else ''
  496. end as IsNew,
  497. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  498. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  499. from ICSOOPick a
  500. inner join ICSOutsourcingOrder b on a.OODetailID = b.OODetailID and a.WorkPoint = b.WorkPoint
  501. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  502. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  503. WHERE b.WorkPoint = '{WorkPoint}' ");
  504. if (!string.IsNullOrWhiteSpace(queryJson))
  505. {
  506. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  507. {
  508. sqlString.Append($@" and a.OOCode like '%{queryParam["POCode"]}%' ");
  509. }
  510. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  511. {
  512. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  513. }
  514. }
  515. sqlString.Append(@" group by b.OOCode,b.CreateDateTime,b.CreatePerson,f.Colspan ,f.ProjectCode ,
  516. f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4,
  517. f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10) t where t.row=1");
  518. #endregion
  519. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  520. }
  521. //委外备料(委外备料)子表查询
  522. public DataTable GetSubGridJson4(string Code)
  523. {
  524. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  525. DataTable dt = new DataTable();
  526. //var queryParam = queryJson.ToJObject();
  527. List<DbParameter> parameter = new List<DbParameter>();
  528. 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,
  529. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  530. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  531. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  532. from ICSOOPick a
  533. left join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint
  534. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  535. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  536. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  537. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  538. where b.OOCode='{0}' and b.WorkPoint='{1}'";
  539. sql = string.Format(sql, Code, WorkPoint);
  540. return Repository().FindTableBySql(sql.ToString());
  541. }
  542. //委外领料(委外发料申请)
  543. public DataTable GetGridJson5(string queryJson, ref Pagination jqgridparam)
  544. {
  545. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  546. DataTable dt = new DataTable();
  547. var queryParam = queryJson.ToJObject();
  548. List<DbParameter> parameter = new List<DbParameter>();
  549. StringBuilder sqlString = new StringBuilder();
  550. #region [SQL]
  551. // 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,
  552. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  553. // from ICSOApply a
  554. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  555. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  556. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  557. // sql += " WHERE 1=1 and e.ID is null";
  558. 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,
  559. case when max(e.SourceID) is null then ''
  560. else ''
  561. end as IsNew,
  562. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  563. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  564. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID
  565. from ICSOApply a
  566. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  567. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  568. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  569. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  570. 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'
  571. where a.WorkPoint = '{WorkPoint}'");
  572. if (!string.IsNullOrWhiteSpace(queryJson))
  573. {
  574. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  575. {
  576. sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
  577. }
  578. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  579. {
  580. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  581. }
  582. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  583. {
  584. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  585. }
  586. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  587. {
  588. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  589. }
  590. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  591. {
  592. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  593. WHERE
  594. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  595. }
  596. }
  597. sqlString.Append(@"group by a.ApplyCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  598. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,
  599. f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID ) t where row=1");
  600. #endregion
  601. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  602. }
  603. //委外领料(委外发料申请)子表查询
  604. public DataTable GetSubGridJson5(string Code, string queryJson)
  605. {
  606. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  607. DataTable dt = new DataTable();
  608. var queryParam = queryJson.ToJObject();
  609. List<DbParameter> parameter = new List<DbParameter>();
  610. string sql = @"SELECT * FROM (select row_number() over(partition by a.ApplyCode,a.InvCode,a.Sequence ORDER BY a.ApplyCode) as row,
  611. a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode, a.SourceCode,a.SourceSequence,a.VenCode,a.VenName,
  612. b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  613. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity,detail.LocationCode AS Area,
  614. f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  615. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  616. from ICSOApply a
  617. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  618. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  619. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  620. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  621. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  622. where a.ApplyCode='{0}' and a.WorkPoint='{1}'";
  623. if (!string.IsNullOrWhiteSpace(queryJson))
  624. {
  625. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  626. {
  627. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  628. }
  629. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  630. {
  631. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  632. }
  633. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  634. {
  635. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  636. }
  637. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  638. {
  639. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  640. WHERE
  641. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  642. }
  643. }
  644. sql += " ) c WHERE c.row=1 ";
  645. sql = string.Format(sql, Code, WorkPoint);
  646. return Repository().FindTableBySql(sql.ToString());
  647. }
  648. //委外材料出库(委外发料申请)
  649. public DataTable GetGridJson6(string queryJson, ref Pagination jqgridparam)
  650. {
  651. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  652. DataTable dt = new DataTable();
  653. var queryParam = queryJson.ToJObject();
  654. List<DbParameter> parameter = new List<DbParameter>();
  655. StringBuilder sqlString = new StringBuilder();
  656. #region [SQL]
  657. // 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,
  658. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  659. // from ICSOIssue a
  660. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  661. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  662. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  663. // sql += " WHERE 1=1 and e.ID is null";
  664. sqlString.Append($@"select * from(select row_number() over(partition by a.IssueCode order by a.IssueCode) row, a.IssueCode as Code,
  665. a.CreateDateTime as MTIME,
  666. a.CreatePerson as MUSER,
  667. case
  668. when max(e.SourceID) is null then ''
  669. else ''
  670. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,
  671. f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  672. f.cFree8,f.cFree9,f.cFree10
  673. from ICSOIssue a
  674. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  675. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  676. where a.WorkPoint = '{WorkPoint}'");
  677. if (!string.IsNullOrWhiteSpace(queryJson))
  678. {
  679. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  680. {
  681. sqlString.Append($@" and a.IssueCode like '%{queryParam["POCode"]}%' ");
  682. }
  683. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  684. {
  685. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  686. }
  687. }
  688. sqlString.Append(@"group by a.IssueCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  689. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,
  690. f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10) t where t.row=1");
  691. #endregion
  692. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  693. }
  694. //委外材料出库(委外发料申请)子表查询
  695. public DataTable GetSubGridJson6(string Code)
  696. {
  697. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  698. DataTable dt = new DataTable();
  699. //var queryParam = queryJson.ToJObject();
  700. List<DbParameter> parameter = new List<DbParameter>();
  701. 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,
  702. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  703. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  704. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  705. from ICSOIssue a
  706. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  707. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  708. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  709. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  710. where a.IssueCode='{0}' and a.WorkPoint='{1}'";
  711. sql = string.Format(sql, Code, WorkPoint);
  712. return Repository().FindTableBySql(sql.ToString());
  713. }
  714. //销售发货(销售发货)
  715. public DataTable GetGridJson7(string queryJson, ref Pagination jqgridparam)
  716. {
  717. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  718. DataTable dt = new DataTable();
  719. var queryParam = queryJson.ToJObject();
  720. List<DbParameter> parameter = new List<DbParameter>();
  721. StringBuilder sqlString = new StringBuilder();
  722. #region [SQL]
  723. // 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,
  724. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  725. // from ICSSDN a
  726. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  727. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  728. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  729. // sql += " WHERE 1=1 and a.Type='1' and e.ID is null";
  730. sqlString.Append($@"SELECT * from (SELECT Row_Number() over(partition by a.SDNCode Order by a.SDNCode) as r, a.SDNCode AS Code,
  731. CONVERT(varchar(100),a.CreateDateTime,23) AS MTIME,
  732. a.CreatePerson AS MUSER,
  733. a.CusCode,a.CusName,
  734. (CASE WHEN max(e.SourceID) IS NULL THEN '' ELSE '' END) AS IsNew,
  735. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  736. f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  737. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10,a.ID
  738. FROM ICSSDN a
  739. LEFT JOIN ICSMOPickMerge e ON a.ID = e.SourceID AND a.WorkPoint = e.WorkPoint
  740. LEFT JOIN ICSExtension f ON a.ExtensionID = f.ID AND a.WorkPoint = f.WorkPoint
  741. LEFT JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  742. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  743. 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'
  744. WHERE a.WorkPoint = '{WorkPoint}' ");
  745. if (!string.IsNullOrWhiteSpace(queryJson))
  746. {
  747. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  748. {
  749. sqlString.Append($" and a.SDNCode like '%{queryParam["POCode"]}%' ");
  750. }
  751. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  752. {
  753. sqlString.Append($" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  754. }
  755. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  756. {
  757. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  758. }
  759. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  760. {
  761. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  762. }
  763. if (!string.IsNullOrWhiteSpace(queryParam["CusCode"].ToString()))
  764. {
  765. sqlString.Append($@" and a.CusCode like '%{queryParam["CusCode"]}%' ");
  766. }
  767. if (!string.IsNullOrWhiteSpace(queryParam["CusName"].ToString()))
  768. {
  769. sqlString.Append($@" and a.CusName like '%{queryParam["CusName"]}%' ");
  770. }
  771. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  772. {
  773. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  774. WHERE
  775. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  776. }
  777. }
  778. sqlString.Append(@"GROUP BY a.SDNCode, a.CreateDateTime, a.CreatePerson, f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  779. 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) t WHERE t.r=1");
  780. #endregion
  781. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  782. }
  783. //销售发货(销售发货)子表查询
  784. public DataTable GetSubGridJson7(string Code, string queryJson)
  785. {
  786. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  787. DataTable dt = new DataTable();
  788. var queryParam = queryJson.ToJObject();
  789. List<DbParameter> parameter = new List<DbParameter>();
  790. string sql = @"SELECT * FROM (select row_number() over(partition by a.SDNCode,a.InvCode,a.Sequence ORDER BY a.SDNCode) as row,
  791. a.ID,a.SDNCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode
  792. ,a.WorkPoint,a.Points,a.DeliveryType,a.DeliveryDescribe,a.InvDescribe,a.OtherDescribe,a.CusCode,a.CusName,
  793. a.SalesUnit,a.StockIndicator,a.IsSerialNumber,
  794. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  795. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity,detail.LocationCode AS Area
  796. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  797. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.SDNQuantity as IssueQuantity
  798. from ICSSDN a
  799. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  800. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  801. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  802. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  803. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  804. where a.SDNCode='{0}' and a.WorkPoint='{1}'";
  805. if (!string.IsNullOrWhiteSpace(queryJson))
  806. {
  807. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  808. {
  809. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  810. }
  811. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  812. {
  813. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  814. }
  815. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  816. {
  817. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  818. }
  819. if (!string.IsNullOrWhiteSpace(queryParam["CusCode"].ToString()))
  820. {
  821. sql += $@" and a.CusCode like '%{queryParam["CusCode"]}%' ";
  822. }
  823. if (!string.IsNullOrWhiteSpace(queryParam["CusName"].ToString()))
  824. {
  825. sql += $@" and a.CusName like '%{queryParam["CusName"]}%' ";
  826. }
  827. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  828. {
  829. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  830. WHERE
  831. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  832. }
  833. }
  834. sql += " ) c WHERE c.row=1 ";
  835. sql = string.Format(sql, Code, WorkPoint);
  836. return Repository().FindTableBySql(sql.ToString());
  837. }
  838. //其它出库(其它出库)
  839. public DataTable GetGridJson8(string queryJson, ref Pagination jqgridparam)
  840. {
  841. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  842. DataTable dt = new DataTable();
  843. var queryParam = queryJson.ToJObject();
  844. List<DbParameter> parameter = new List<DbParameter>();
  845. StringBuilder sqlString = new StringBuilder();
  846. #region [SQL]
  847. // 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,
  848. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  849. //from ICSOtherOut a
  850. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  851. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  852. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  853. // sql += " WHERE 1=1 and e.ID is null ";
  854. sqlString.Append($@"select * from(select row_number() over(partition by a.OutCode order by a.OutCode) row, a.OutCode as Code,
  855. CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,
  856. a.CreatePerson as MUSER,
  857. case
  858. when max(e.SourceID) is null then ''
  859. else ''
  860. end as IsNew,
  861. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  862. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  863. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID
  864. from ICSOtherOut a
  865. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  866. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  867. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  868. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  869. 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'
  870. where a.WorkPoint = '{WorkPoint}'");
  871. #endregion
  872. if (!string.IsNullOrWhiteSpace(queryJson))
  873. {
  874. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  875. {
  876. sqlString.Append($@" and a.OutCode like '%{queryParam["POCode"]}%' ");
  877. }
  878. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  879. {
  880. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  881. }
  882. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  883. {
  884. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  885. }
  886. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  887. {
  888. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  889. }
  890. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  891. {
  892. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  893. WHERE
  894. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  895. }
  896. }
  897. sqlString.Append(@" group by a.OutCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,f.BatchCode,
  898. f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,
  899. f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID) t where t.row=1");
  900. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  901. }
  902. //其它出库(其它出库)子表查询
  903. public DataTable GetSubGridJson8(string Code, string queryJson)
  904. {
  905. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  906. DataTable dt = new DataTable();
  907. var queryParam = queryJson.ToJObject();
  908. List<DbParameter> parameter = new List<DbParameter>();
  909. string sql = @"SELECT * FROM (select row_number() over(partition by a.OutCode,a.InvCode,a.Sequence ORDER BY a.OutCode) as row,
  910. a.ID,a.OutCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.Quantity,
  911. a.InvCode,a.WorkPoint,a.OrderType, a.TypeDescribe,a.CostCenter,a.Remarks,a.PersonNumber,a.InvDescribe,
  912. a.Unit,a.StockIndicator,
  913. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  914. case when e.SourceID is null then '' else '' end as IsNew,detail.LocationCode AS Area
  915. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  916. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  917. from ICSOtherOut a
  918. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  919. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  920. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  921. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  922. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  923. where a.OutCode='{0}' and a.WorkPoint='{1}'";
  924. if (!string.IsNullOrWhiteSpace(queryJson))
  925. {
  926. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  927. {
  928. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  929. }
  930. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  931. {
  932. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  933. }
  934. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  935. {
  936. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  937. }
  938. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  939. {
  940. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  941. WHERE
  942. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  943. }
  944. }
  945. sql += " ) c WHERE c.row=1 ";
  946. sql = string.Format(sql, Code, WorkPoint);
  947. return Repository().FindTableBySql(sql.ToString());
  948. }
  949. //借用(借用)
  950. public DataTable GetGridJson9(string queryJson, ref Pagination jqgridparam)
  951. {
  952. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  953. DataTable dt = new DataTable();
  954. var queryParam = queryJson.ToJObject();
  955. List<DbParameter> parameter = new List<DbParameter>();
  956. StringBuilder sqlString = new StringBuilder();
  957. #region [SQL]
  958. // sql = @"
  959. //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,
  960. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  961. // from ICSBrrow a
  962. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  963. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  964. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  965. // sql += " WHERE 1=1 and e.ID is null ";
  966. sqlString.Append($@"select * from(select row_number() over(partition by a.BrrowCode order by a.BrrowCode) row, a.BrrowCode as Code,
  967. a.CreateDateTime as MTIME,
  968. a.CreatePerson as MUSER,
  969. case
  970. when max(e.SourceID) is null then ''
  971. else ''
  972. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,
  973. f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  974. f.cFree8,f.cFree9,f.cFree10
  975. from ICSBrrow a
  976. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  977. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  978. where a.WorkPoint = '{WorkPoint}'");
  979. if (!string.IsNullOrWhiteSpace(queryJson))
  980. {
  981. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  982. {
  983. sqlString.Append($@" and a.BrrowCode like '%{queryParam["POCode"]}%' ");
  984. }
  985. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  986. {
  987. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  988. }
  989. }
  990. sqlString.Append(@"group by a.BrrowCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  991. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,
  992. f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,
  993. f.cFree10) t where t.row=1");
  994. #endregion
  995. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  996. }
  997. //借用(借用)子表查询
  998. public DataTable GetSubGridJson9(string Code)
  999. {
  1000. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1001. DataTable dt = new DataTable();
  1002. //var queryParam = queryJson.ToJObject();
  1003. List<DbParameter> parameter = new List<DbParameter>();
  1004. 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,
  1005. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  1006. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1007. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.BrrowQuantity as IssueQuantity
  1008. from ICSBrrow a
  1009. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  1010. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1011. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  1012. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1013. where a.BrrowCode='{0}' and a.WorkPoint='{1}'";
  1014. sql = string.Format(sql, Code, WorkPoint);
  1015. return Repository().FindTableBySql(sql.ToString());
  1016. }
  1017. //物料调拨
  1018. public DataTable GetGridJson10(string queryJson, ref Pagination jqgridparam)
  1019. {
  1020. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1021. DataTable dt = new DataTable();
  1022. var queryParam = queryJson.ToJObject();
  1023. List<DbParameter> parameter = new List<DbParameter>();
  1024. StringBuilder sqlString = new StringBuilder();
  1025. #region [SQL]
  1026. // sql = @"
  1027. //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,
  1028. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  1029. // from ICSBrrow a
  1030. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  1031. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1032. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  1033. // sql += " WHERE 1=1 and e.ID is null ";
  1034. sqlString.Append($@"select * from (select row_number() over(partition by a.TransferNO order by a.TransferNO) row,
  1035. a.TransferNO as Code,a.ID,CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,a.CreatePerson as MUSER,
  1036. case
  1037. when max(e.SourceID) is null then ''
  1038. else ''
  1039. end as IsNew,
  1040. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  1041. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  1042. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  1043. from ICSTransfer a
  1044. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  1045. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  1046. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1047. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.ToWarehouseCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  1048. 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'
  1049. where a.WorkPoint = '{WorkPoint}' and a.Status = '2'");
  1050. if (!string.IsNullOrWhiteSpace(queryJson))
  1051. {
  1052. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1053. {
  1054. sqlString.Append($@" and a.TransferNO like '%{queryParam["POCode"]}%' ");
  1055. }
  1056. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1057. {
  1058. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  1059. }
  1060. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  1061. {
  1062. sqlString.Append($@" and a.ToWarehouseCode like '%{queryParam["WHCode"]}%' ");
  1063. }
  1064. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  1065. {
  1066. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  1067. }
  1068. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  1069. {
  1070. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  1071. WHERE
  1072. F_Define3='HGAreaConfig' AND F_Define1=a.FromWarehouseCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  1073. }
  1074. }
  1075. sqlString.Append(@"group by a.TransferNO,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  1076. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,
  1077. f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID) t where t.row=1");
  1078. #endregion
  1079. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  1080. }
  1081. //物料调拨子表查询
  1082. public DataTable GetSubGridJson10(string Code, string queryJson)
  1083. {
  1084. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1085. DataTable dt = new DataTable();
  1086. var queryParam = queryJson.ToJObject();
  1087. List<DbParameter> parameter = new List<DbParameter>();
  1088. string sql = @"SELECT * from (select row_number() over(partition by a.TransferNO,a.InvCode,
  1089. 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,
  1090. a.InvCode,a.ToWarehouseCode,a.EATTRIBUTE1 AS ReceiveWork,a.WorkPoint,a.OrderType,
  1091. a.TypeDescribe,a.Remarks,a.PersonNumber,a.InvDescribe,
  1092. a.Unit,a.StockIndicator,a.ReceiveInvCode,a.ReceiveInvDescribe,
  1093. a.ReceiveStock,a.ReceiveSales,a.ReceiveSequence,a.Remark2,
  1094. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  1095. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  1096. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1097. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.TransferQuantity as IssueQuantity
  1098. from ICSTransfer a
  1099. left join ICSWarehouse b on a.FromWarehouseCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  1100. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1101. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.ToWarehouseCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  1102. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  1103. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1104. where a.TransferNO='{0}' and b.WorkPoint='{1}'";
  1105. if (!string.IsNullOrWhiteSpace(queryJson))
  1106. {
  1107. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  1108. {
  1109. sql += " and a.ToWarehouseCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  1110. }
  1111. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  1112. {
  1113. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  1114. }
  1115. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1116. {
  1117. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1118. }
  1119. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  1120. {
  1121. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  1122. WHERE
  1123. F_Define3='HGAreaConfig' AND F_Define1=a.FromWarehouseCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  1124. }
  1125. }
  1126. sql += " ) as t where t.row=1";
  1127. sql = string.Format(sql, Code, WorkPoint);
  1128. return Repository().FindTableBySql(sql.ToString());
  1129. }
  1130. //两步调拨
  1131. public DataTable GetGridJson11(string queryJson, ref Pagination jqgridparam)
  1132. {
  1133. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1134. DataTable dt = new DataTable();
  1135. var queryParam = queryJson.ToJObject();
  1136. List<DbParameter> parameter = new List<DbParameter>();
  1137. StringBuilder sqlString = new StringBuilder();
  1138. #region [SQL]
  1139. // sql = @"
  1140. //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,
  1141. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  1142. // from ICSBrrow a
  1143. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  1144. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1145. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  1146. // sql += " WHERE 1=1 and e.ID is null ";
  1147. 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,
  1148. case when max(e.SourceID) is null then '' else '' end as IsNew,a.EATTRIBUTE1 AS ReceiveWork,tra.ToWarehouseCode,
  1149. f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  1150. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10
  1151. FROM ICSOtherOut a
  1152. INNER JOIN ICSTransfer tra ON a.TransferDetailID = tra.TransferDetailID AND a.WorkPoint = tra.WorkPoint
  1153. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  1154. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  1155. where a.WorkPoint = '{WorkPoint}'
  1156. and a.Status = '2' ");
  1157. if (!string.IsNullOrWhiteSpace(queryJson))
  1158. {
  1159. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1160. {
  1161. sqlString.Append($@" and a.OutCode like '%{queryParam["POCode"]}%' ");
  1162. }
  1163. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1164. {
  1165. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  1166. }
  1167. }
  1168. sqlString.Append(@" group by a.OutCode, a.CreateDateTime, a.CreatePerson,a.EATTRIBUTE1 ,tra.ToWarehouseCode, f.Colspan ,f.ProjectCode ,
  1169. f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,
  1170. f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10) t where t.row=1");
  1171. #endregion
  1172. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  1173. }
  1174. //两步调拨子表查询
  1175. public DataTable GetSubGridJson11(string Code)
  1176. {
  1177. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1178. DataTable dt = new DataTable();
  1179. //var queryParam = queryJson.ToJObject();
  1180. List<DbParameter> parameter = new List<DbParameter>();
  1181. 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,
  1182. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  1183. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1184. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  1185. FROM ICSOtherOut a
  1186. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1187. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  1188. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1189. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  1190. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1191. where a.OutCode='{0}' and a.WorkPoint='{1}'";
  1192. sql = string.Format(sql, Code, WorkPoint);
  1193. return Repository().FindTableBySql(sql.ToString());
  1194. }
  1195. // public DataTable GetICSMOPickMergeTemp(string ID,string Type)
  1196. // {
  1197. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1198. // ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  1199. // #region sql
  1200. // string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1201. // c.Code,
  1202. // c.InvCode,
  1203. // c.InvName,
  1204. // c.InvStd,
  1205. // c.InvUnit,
  1206. // FLOOR(c.iQuantity) AS iQuantity,
  1207. // d.WarehouseCode,
  1208. // m.LotNO,
  1209. // (case when m.LotNo is null then 0 else FLOOR(ISNULL(d.Quantity, 0)) end) AS QTY,
  1210. // (case when m.LotNo is null then null else d.LocationCode end) AS LocationCode,
  1211. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1212. // FLOOR(f.QTYTotal) QTYTotal INTO #temp
  1213. // FROM
  1214. // ({0}) c
  1215. // LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  1216. // left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  1217. // 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
  1218. //DECLARE @ItemCode VARCHAR(50),
  1219. // @QTY DECIMAL(18,3),
  1220. // @ItemCodeCurrent VARCHAR(50),
  1221. // @Lotno VARCHAR(50),
  1222. // @QTYCurrent DECIMAL(18,3),
  1223. // @iQuantityCurrent DECIMAL(18,3),
  1224. // @CanDelete BIT,
  1225. // @Row INT,
  1226. // @rowCurrent INT
  1227. //SET @Row = @@rowcount
  1228. //SET @rowCurrent=1
  1229. //SET @CanDelete=0
  1230. //SET @ItemCode=''
  1231. //SET @Lotno = ''
  1232. //WHILE @rowCurrent<=@Row
  1233. // BEGIN
  1234. // SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity,@Lotno = Lotno FROM #temp WHERE rowNo=@rowCurrent
  1235. //PRINT(@rowCurrent)
  1236. // IF @ItemCode<>@ItemCodeCurrent
  1237. // BEGIN
  1238. // SET @ItemCode=@ItemCodeCurrent
  1239. // SET @QTY=0
  1240. // SET @CanDelete=0
  1241. // END
  1242. // IF @CanDelete=1
  1243. // BEGIN
  1244. // DELETE FROM #temp WHERE rowNo=@rowCurrent
  1245. // SET @rowCurrent += 1
  1246. // CONTINUE
  1247. // END
  1248. // SET @QTY += @QTYCurrent
  1249. // IF @LotNo is null or @QTY>=@iQuantityCurrent
  1250. // BEGIN
  1251. // SET @CanDelete=1
  1252. // END
  1253. // SET @rowCurrent += 1
  1254. // END
  1255. //SELECT * FROM #temp
  1256. //DROP TABLE #temp
  1257. //";
  1258. // #endregion
  1259. // string sqls = "";
  1260. // if (Type=="1")
  1261. // {
  1262. // #region 工单备料sql
  1263. // sqls = @" SELECT
  1264. // c.MOCode as Code,
  1265. // a.InvCode,
  1266. // b.InvName,
  1267. // b.InvStd,
  1268. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1269. // a.WhCode,
  1270. // b.InvUnit,
  1271. // a.ExtensionID
  1272. // FROM
  1273. // ICSMOPick a
  1274. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1275. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1276. // WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1277. // GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1278. // #endregion
  1279. // }
  1280. // if (Type == "2")
  1281. // {
  1282. // return GetICSMOPickMergeByWorkorder(ID, WorkPoint);
  1283. // }
  1284. // if (Type=="3")
  1285. // {
  1286. // #region 工单材料出库SQL
  1287. // sqls = @" select
  1288. // a.IssueCode as Code,
  1289. // a.InvCode,
  1290. // b.InvName,
  1291. // b.InvStd,
  1292. // b.InvUnit,
  1293. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1294. // a.WhCode,
  1295. // a.ExtensionID
  1296. // FROM
  1297. // ICSMOIssue a
  1298. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1299. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1300. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1301. // #endregion
  1302. // }
  1303. // if (Type=="4")
  1304. // {
  1305. // #region 委外备料SQL
  1306. // sqls = @" select
  1307. // c.OOCode as Code,
  1308. // a.InvCode,
  1309. // b.InvName,
  1310. // b.InvStd,
  1311. // b.InvUnit,
  1312. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1313. // a.WhCode,
  1314. // a.ExtensionID
  1315. // FROM
  1316. // ICSOOPick a
  1317. // left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1318. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1319. // WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1320. // GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  1321. // #endregion
  1322. // }
  1323. // if (Type=="5")
  1324. // {
  1325. // #region 委外领料SQL
  1326. // sqls = @" select
  1327. // a.ApplyCode as Code,
  1328. // a.InvCode,
  1329. // b.InvName,
  1330. // b.InvStd,
  1331. //b.InvUnit,
  1332. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1333. // a.WhCode,
  1334. // a.ExtensionID
  1335. // FROM
  1336. // ICSOApply a
  1337. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1338. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1339. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1340. // #endregion
  1341. // }
  1342. // if (Type=="6")
  1343. // {
  1344. // #region 委外材料出库SQL
  1345. // sqls = @" select
  1346. // a.IssueCode as Code,
  1347. // a.InvCode,
  1348. // b.InvName,
  1349. // b.InvStd,
  1350. //b.InvUnit,
  1351. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1352. // a.WhCode,
  1353. //a.ExtensionID
  1354. // FROM
  1355. // ICSOIssue a
  1356. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1357. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1358. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1359. // #endregion
  1360. // }
  1361. // if (Type=="7")
  1362. // {
  1363. // #region 销售发货SQL
  1364. // sqls = @" select
  1365. // a.SDNCode as Code,
  1366. // a.InvCode,
  1367. // b.InvName,
  1368. // b.InvStd,
  1369. //b.InvUnit,
  1370. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1371. // a.WhCode,
  1372. //a.ExtensionID
  1373. // FROM
  1374. // ICSSDN a
  1375. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1376. // WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1377. // GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1378. // #endregion
  1379. // }
  1380. // if (Type=="8")
  1381. // {
  1382. // #region 其它出库SQL
  1383. // sqls = @" select
  1384. // a.OutCode as Code,
  1385. // a.InvCode,
  1386. // b.InvName,
  1387. // b.InvStd,
  1388. // b.InvUnit,
  1389. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1390. // a.WhCode,
  1391. // a.ExtensionID
  1392. // FROM
  1393. // ICSOtherOut a
  1394. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1395. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1396. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1397. // #endregion
  1398. // }
  1399. // if (Type == "9")
  1400. // {
  1401. // #region 借用SQL
  1402. // sqls = @"select
  1403. // a.BrrowCode as Code,
  1404. // a.InvCode,
  1405. // b.InvName,
  1406. // b.InvStd,
  1407. //b.InvUnit,
  1408. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1409. // a.WhCode,
  1410. //a.ExtensionID
  1411. // FROM
  1412. // ICSBrrow a
  1413. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1414. // WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1415. // GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1416. // #endregion
  1417. // }
  1418. // if (Type == "10")
  1419. // {
  1420. // #region 物料调拨
  1421. // sqls = @" select
  1422. // a.TransferNO as Code,
  1423. // a.InvCode,
  1424. // b.InvName,
  1425. // b.InvStd,
  1426. //b.InvUnit,
  1427. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1428. // a.FromWarehouseCode as WhCode,
  1429. //a.ExtensionID
  1430. // FROM
  1431. // ICSTransfer a
  1432. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1433. // WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1434. // GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  1435. // #endregion
  1436. // }
  1437. // if (Type == "11")
  1438. // {
  1439. // #region 两步调出
  1440. // sqls = @"select
  1441. // a.OutCode as Code,
  1442. // a.InvCode,
  1443. // b.InvName,
  1444. // b.InvStd,
  1445. //b.InvUnit,
  1446. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1447. // a.WHCode ,
  1448. //a.ExtensionID
  1449. // from ICSOtherOut a
  1450. // INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1451. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1452. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1453. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  1454. // #endregion
  1455. // }
  1456. // sqls = string.Format(sqls, ID,WorkPoint);
  1457. // sql = string.Format(sql, sqls, WorkPoint);
  1458. // DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1459. // DataTable dtCloned = table.Clone();
  1460. // foreach (DataColumn col in dtCloned.Columns)
  1461. // {
  1462. // col.DataType = typeof(string);
  1463. // }
  1464. // foreach (DataRow row in table.Rows)
  1465. // {
  1466. // DataRow newrow = dtCloned.NewRow();
  1467. // foreach (DataColumn column in dtCloned.Columns)
  1468. // {
  1469. // newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1470. // }
  1471. // dtCloned.Rows.Add(newrow);
  1472. // }
  1473. // if (Invmes.Rows.Count > 0)
  1474. // {
  1475. // dtCloned.Merge(Invmes, false);
  1476. // }
  1477. // return dtCloned;
  1478. // }
  1479. public DataTable GetICSMOPickMergeTemp(string ID, string Type)
  1480. {
  1481. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1482. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1483. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1484. ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  1485. #region sql
  1486. #endregion
  1487. string sqls = "";
  1488. if (Type == "1")
  1489. {
  1490. #region 工单备料sql
  1491. sqls = @" SELECT
  1492. c.MOCode as Code,
  1493. c.Sequence+'~'+a.Sequence as Sequence,
  1494. a.InvCode,
  1495. b.InvName,
  1496. b.InvStd,
  1497. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1498. a.WhCode,
  1499. b.InvUnit,
  1500. a.ExtensionID
  1501. FROM
  1502. ICSMOPick a
  1503. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1504. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1505. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1506. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,c.Sequence+'~'+a.Sequence";
  1507. #endregion
  1508. }
  1509. if (Type == "2" || Type == "12")
  1510. {
  1511. sqls = @"select
  1512. a.ApplyCode as Code,a.Sequence, a.InvCode, b.InvName, b.InvStd, b.InvUnit, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode,a.ExtensionID
  1513. FROM
  1514. ICSMOApply a
  1515. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1516. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1517. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1518. }
  1519. if (Type == "3")
  1520. {
  1521. #region 工单材料出库SQL
  1522. sqls = @" select
  1523. a.IssueCode as Code,
  1524. a.Sequence,
  1525. a.InvCode,
  1526. b.InvName,
  1527. b.InvStd,
  1528. b.InvUnit,
  1529. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1530. a.WhCode,
  1531. a.ExtensionID
  1532. FROM
  1533. ICSMOIssue a
  1534. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1535. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1536. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1537. #endregion
  1538. }
  1539. if (Type == "4")
  1540. {
  1541. #region 委外备料SQL
  1542. sqls = @" select
  1543. c.OOCode as Code,
  1544. c.Sequence+'~'+a.Sequence as Sequence,
  1545. a.InvCode,
  1546. b.InvName,
  1547. b.InvStd,
  1548. b.InvUnit,
  1549. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1550. a.WhCode,
  1551. a.ExtensionID
  1552. FROM
  1553. ICSOOPick a
  1554. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1555. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1556. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1557. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID,c.Sequence+'~'+a.Sequence";
  1558. #endregion
  1559. }
  1560. if (Type == "5")
  1561. {
  1562. #region 委外领料SQL
  1563. sqls = @"select
  1564. a.ApplyCode as Code,
  1565. a.Sequence,
  1566. a.InvCode,
  1567. b.InvName,
  1568. b.InvStd,
  1569. b.InvUnit,
  1570. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1571. a.WhCode,a.ExtensionID
  1572. FROM
  1573. ICSOApply a
  1574. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1575. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1576. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1577. #endregion
  1578. }
  1579. if (Type == "6")
  1580. {
  1581. #region 委外材料出库SQL
  1582. sqls = @" select
  1583. a.IssueCode as Code,
  1584. a.Sequence,
  1585. a.InvCode,
  1586. b.InvName,
  1587. b.InvStd,
  1588. b.InvUnit,
  1589. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1590. a.WhCode,
  1591. a.ExtensionID
  1592. FROM
  1593. ICSOIssue a
  1594. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1595. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1596. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1597. #endregion
  1598. }
  1599. if (Type == "7")
  1600. {
  1601. #region 销售发货SQL
  1602. sqls = @" select
  1603. a.SDNCode as Code,
  1604. a.Sequence,
  1605. a.InvCode,
  1606. b.InvName,
  1607. b.InvStd,
  1608. b.InvUnit,
  1609. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1610. a.WhCode,
  1611. a.ExtensionID
  1612. FROM
  1613. ICSSDN a
  1614. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1615. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1616. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1617. #endregion
  1618. }
  1619. if (Type == "8")
  1620. {
  1621. #region 其它出库SQL
  1622. sqls = @" select
  1623. a.OutCode as Code,
  1624. a.Sequence,
  1625. a.InvCode,
  1626. b.InvName,
  1627. b.InvStd,
  1628. b.InvUnit,
  1629. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1630. a.WhCode,
  1631. a.ExtensionID
  1632. FROM
  1633. ICSOtherOut a
  1634. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1635. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1636. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1637. #endregion
  1638. }
  1639. if (Type == "9")
  1640. {
  1641. #region 借用SQL
  1642. sqls = @"select
  1643. a.BrrowCode as Code,
  1644. a.Sequence,
  1645. a.InvCode,
  1646. b.InvName,
  1647. b.InvStd,
  1648. b.InvUnit,
  1649. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1650. a.WhCode,
  1651. a.ExtensionID
  1652. FROM
  1653. ICSBrrow a
  1654. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1655. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1656. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1657. #endregion
  1658. }
  1659. if (Type == "10")
  1660. {
  1661. #region 物料调拨
  1662. sqls = @"select
  1663. a.TransferNO as Code,
  1664. a.Sequence,
  1665. a.InvCode,
  1666. b.InvName,
  1667. b.InvStd,
  1668. b.InvUnit,
  1669. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1670. a.FromWarehouseCode as WhCode,
  1671. a.ExtensionID
  1672. FROM
  1673. ICSTransfer a
  1674. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1675. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1676. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,a.Sequence";
  1677. #endregion
  1678. }
  1679. if (Type == "11")
  1680. {
  1681. #region 两步调出
  1682. sqls = @"select
  1683. a.OutCode as Code,
  1684. a.Sequence,
  1685. a.InvCode,
  1686. b.InvName,
  1687. b.InvStd,
  1688. b.InvUnit,
  1689. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1690. a.WHCode ,
  1691. a.ExtensionID
  1692. from ICSOtherOut a
  1693. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1694. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1695. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1696. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,a.Sequence";
  1697. #endregion
  1698. }
  1699. sqls = string.Format(sqls, ID, WorkPoint);
  1700. string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1701. c.Code,
  1702. c.Sequence,
  1703. c.InvCode,
  1704. c.InvName,
  1705. c.InvStd,
  1706. c.InvUnit,
  1707. FLOOR(c.iQuantity) AS iQuantity,
  1708. c.WHCode AS WarehouseCode,
  1709. d.LotNO,
  1710. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1711. FLOOR(ISNULL(d.Quantity, 0)) AS QTYLeft,
  1712. 0 AS SendQTY,
  1713. d.LocationCode AS LocationCode,
  1714. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1715. FLOOR(f.QTYTotal) QTYTotal,c.ExtensionID
  1716. FROM
  1717. ({sqls}) c
  1718. left join (select d.WarehouseCode,d.Quantity-d.LockQuantity as Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
  1719. from ICSWareHouseLotInfo d ,ICSInventoryLot m
  1720. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  1721. and d.WorkPoint='{WorkPoint}' AND d.Quantity-d.LockQuantity>0
  1722. --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
  1723. --WHERE F_Define3='HGAreaConfig' AND F_Define1=d.WarehouseCode AND F_Define4=d.WorkPoint)
  1724. ) d
  1725. on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  1726. 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
  1727. order by c.Code,c.InvCode,d.MTIME ";
  1728. var dataset = Repository().FindDataSetBySql(sql);
  1729. if (dataset.Tables.Count == 0)
  1730. return null;
  1731. DataTable table = dataset.Tables[0];
  1732. decimal qtyCount = 0;
  1733. bool remove = false;
  1734. List<int> removeList = new List<int>();
  1735. for (int i = 0; i < table.Rows.Count; i++)
  1736. {
  1737. if (i != 0
  1738. && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  1739. || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString())
  1740. || !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString()))
  1741. )
  1742. {
  1743. qtyCount = 0;
  1744. remove = false;
  1745. }
  1746. if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0)
  1747. {
  1748. removeList.Add(i);
  1749. continue;
  1750. }
  1751. if (remove)
  1752. {
  1753. removeList.Add(i);
  1754. }
  1755. else
  1756. {
  1757. var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal();
  1758. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  1759. qtyCount += lotQty;
  1760. foreach (DataRow dr in table.Rows)
  1761. {
  1762. if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString())
  1763. {
  1764. if (qtyCount > orderQty)
  1765. {
  1766. dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty);
  1767. }
  1768. else
  1769. {
  1770. dr["QTYLeft"] = 0;
  1771. }
  1772. }
  1773. }
  1774. if (qtyCount >= orderQty)
  1775. {
  1776. table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty));
  1777. remove = true;
  1778. }
  1779. else
  1780. {
  1781. table.Rows[i]["SendQTY"] = lotQty;
  1782. }
  1783. }
  1784. }
  1785. if (removeList.Count > 0)
  1786. {
  1787. removeList.Reverse();
  1788. foreach (var item in removeList)
  1789. {
  1790. table.Rows.RemoveAt(item);
  1791. }
  1792. }
  1793. #region 拣料时增加条码出入库记录,修改库存锁定数量,以作占料处理
  1794. string BusinessCode = string.Empty;
  1795. if (Type == "2") { BusinessCode = "13"; }
  1796. if (Type == "12") { BusinessCode = "14"; }
  1797. if (Type == "5") { BusinessCode = "5"; }
  1798. if (Type == "7") { BusinessCode = "19"; }
  1799. if (Type == "8") { BusinessCode = "24"; }
  1800. if (Type == "10") { BusinessCode = "47"; }
  1801. string Identification = Guid.NewGuid().ToString();
  1802. var pikTbLogTime = DateTime.Now;
  1803. string pikTbLogsql = string.Empty;
  1804. foreach (DataRow PickLog in table.Rows)
  1805. {
  1806. pikTbLogsql += @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1807. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1808. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1809. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1810. MTIME,WorkPoint,EATTRIBUTE1)
  1811. SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode ,
  1812. a.WarehouseCode,a.LocationCode,'','','{3}',
  1813. '','1','15','{4}','0','',
  1814. '','','','{5}' ,'{6}' ,
  1815. '{7}' ,'{8}' ,''
  1816. FROM ICSWareHouseLotInfo a
  1817. WHERE a.LotNo='{9}' AND a.WorkPoint='{8}' ";
  1818. pikTbLogsql += @"update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{9}' ";
  1819. pikTbLogsql = string.Format(pikTbLogsql, Identification, PickLog["Code"].ToString(), PickLog["Sequence"].ToString(), PickLog["SendQTY"].ToString(), BusinessCode, MUSER, MUSERNAME, pikTbLogTime, WorkPoint, PickLog["LotNO"].ToString());
  1820. }
  1821. SqlHelper.CmdExecuteNonQueryLi(pikTbLogsql);
  1822. #endregion
  1823. #region 将拣料结果存入表中,以人员区分,每次存入之前清空对应人员存入的数据
  1824. string picksql = @"delete from ICSPickPrintTemp
  1825. where MUSER='{0}' AND WorkPoint='{1}'";
  1826. picksql = string.Format(picksql, MUSER, WorkPoint);
  1827. SqlHelper.ExecuteNonQuery(picksql);
  1828. picksql = "";
  1829. foreach (DataRow pickdr in table.Rows)
  1830. {
  1831. picksql += @" INSERT INTO ICSPickPrintTemp
  1832. (ID,DocNO,INVCode,iQuantity,WHCode,BinCode,LotNO,QTYTotal,SendQTY,MUSER,MUSERNAME,WorkPoint)
  1833. VALUES
  1834. (NEWID(),'{0}','{1}',{2},'{3}','{4}','{5}',{6},{7},'{8}','{9}','{10}')";
  1835. picksql = string.Format(picksql, pickdr["Code"].ToString(), pickdr["InvCode"].ToString(), Convert.ToDecimal(pickdr["iQuantity"])
  1836. , pickdr["WarehouseCode"].ToString(), pickdr["LocationCode"].ToString(), pickdr["LotNO"].ToString()
  1837. , Convert.ToDecimal(pickdr["QTYTotal"]), Convert.ToDecimal(pickdr["SendQTY"]), MUSER, MUSERNAME, WorkPoint);
  1838. }
  1839. SqlHelper.ExecuteNonQuery(picksql);
  1840. #endregion
  1841. var result = ConvertCellToString(table);
  1842. if (Invmes.Rows.Count > 0)
  1843. {
  1844. result.Merge(Invmes, false);
  1845. }
  1846. return result;
  1847. }
  1848. /// <summary>
  1849. /// 工单领料推荐
  1850. /// </summary>
  1851. /// <param name="Id"></param>
  1852. /// <param name="workPoint"></param>
  1853. /// <returns></returns>
  1854. public DataTable GetICSMOPickMergeByWorkorder(string Id, string workPoint)
  1855. {
  1856. string sql = $@"SELECT row_number() over (partition by c.Code,c.InvCode order by c.Code,c.InvCode,d.MTIME) AS rowNo,
  1857. c.Code,
  1858. c.InvCode,
  1859. c.InvName,
  1860. c.InvStd,
  1861. c.InvUnit,
  1862. FLOOR(c.iQuantity) AS iQuantity,
  1863. d.WarehouseCode,
  1864. d.LotNO,
  1865. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1866. d.LocationCode LocationCode,
  1867. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1868. FLOOR(f.QTYTotal) QTYTotal
  1869. FROM
  1870. (select
  1871. a.ApplyCode as Code, a.InvCode, b.InvName, b.InvStd, b.InvUnit, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode,a.ExtensionID
  1872. FROM
  1873. ICSMOApply a
  1874. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1875. WHERE a.ApplyCode in ({Id}) AND a.WorkPoint = '{workPoint}'
  1876. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID) c
  1877. left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID from ICSWareHouseLotInfo d ,ICSInventoryLot m
  1878. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  1879. and d.WorkPoint='{workPoint}' AND d.Quantity>0 ) d on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  1880. 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
  1881. order by c.Code,c.InvCode,d.MTIME";
  1882. var dataset = Repository().FindDataSetBySql(sql);
  1883. if (dataset.Tables.Count == 0)
  1884. return null;
  1885. DataTable table = dataset.Tables[0];
  1886. decimal qtyCount = 0;
  1887. bool remove = false;
  1888. List<int> removeList = new List<int>();
  1889. for (int i = 0; i < table.Rows.Count; i++)
  1890. {
  1891. if (i != 0
  1892. && !table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString()))
  1893. {
  1894. qtyCount = 0;
  1895. remove = false;
  1896. }
  1897. if (remove)
  1898. {
  1899. removeList.Add(i);
  1900. }
  1901. else
  1902. {
  1903. var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
  1904. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  1905. qtyCount += lotQty;
  1906. if (qtyCount >= orderQty)
  1907. {
  1908. remove = true;
  1909. }
  1910. }
  1911. }
  1912. if (removeList.Count > 0)
  1913. {
  1914. removeList.Reverse();
  1915. foreach (var item in removeList)
  1916. {
  1917. table.Rows.RemoveAt(item);
  1918. }
  1919. }
  1920. var result = ConvertCellToString(table);
  1921. if (Invmes.Rows.Count > 0)
  1922. {
  1923. result.Merge(Invmes, false);
  1924. }
  1925. return result;
  1926. }
  1927. public DataTable ConvertCellToString(DataTable data)
  1928. {
  1929. DataTable dtCloned = data.Clone();
  1930. foreach (DataColumn col in dtCloned.Columns)
  1931. {
  1932. col.DataType = typeof(string);
  1933. }
  1934. foreach (DataRow row in data.Rows)
  1935. {
  1936. DataRow newrow = dtCloned.NewRow();
  1937. foreach (DataColumn column in dtCloned.Columns)
  1938. {
  1939. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1940. }
  1941. dtCloned.Rows.Add(newrow);
  1942. }
  1943. return dtCloned;
  1944. }
  1945. // public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  1946. // {
  1947. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1948. // #region sql
  1949. // string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1950. // c.MergeID,
  1951. // c.Code,
  1952. // c.InvCode,
  1953. // c.InvName,
  1954. // c.InvStd,
  1955. //c.InvUnit,
  1956. // FLOOR(c.iQuantity) AS iQuantity,
  1957. // d.WarehouseCode,
  1958. // d.LocationCode,
  1959. // d.LotNO,
  1960. // FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1961. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1962. // FLOOR(f.QTYTotal) QTYTotal INTO #temp
  1963. // FROM
  1964. // ({0}) c
  1965. // LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  1966. // left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  1967. // 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
  1968. //DECLARE @ItemCode VARCHAR(50),
  1969. // @QTY DECIMAL(18,3),
  1970. // @ItemCodeCurrent VARCHAR(50),
  1971. // @QTYCurrent DECIMAL(18,3),
  1972. // @iQuantityCurrent DECIMAL(18,3),
  1973. // @CanDelete BIT,
  1974. // @Row INT,
  1975. // @rowCurrent INT
  1976. //SET @Row = @@rowcount
  1977. //SET @rowCurrent=1
  1978. //SET @CanDelete=0
  1979. //SET @ItemCode=''
  1980. //WHILE @rowCurrent<=@Row
  1981. // BEGIN
  1982. // SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  1983. //PRINT(@rowCurrent)
  1984. // IF @ItemCode<>@ItemCodeCurrent
  1985. // BEGIN
  1986. // SET @ItemCode=@ItemCodeCurrent
  1987. // SET @QTY=0
  1988. // SET @CanDelete=0
  1989. // END
  1990. // IF @CanDelete=1
  1991. // BEGIN
  1992. // DELETE FROM #temp WHERE rowNo=@rowCurrent
  1993. // SET @rowCurrent += 1
  1994. // CONTINUE
  1995. // END
  1996. // SET @QTY += @QTYCurrent
  1997. // IF @QTY>=@iQuantityCurrent
  1998. // BEGIN
  1999. // SET @CanDelete=1
  2000. // END
  2001. // SET @rowCurrent += 1
  2002. // END
  2003. //SELECT * FROM #temp
  2004. //DROP TABLE #temp
  2005. //";
  2006. // #endregion
  2007. // string sqls = "";
  2008. // if (Type == "1")
  2009. // {
  2010. // #region 工单备料sql
  2011. // sqls = @" select
  2012. // x.MergeID,
  2013. // c.MOCode as Code,
  2014. // a.InvCode,
  2015. // b.InvName,
  2016. // b.InvStd,
  2017. //b.InvUnit,
  2018. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2019. // a.WhCode,
  2020. //a.ExtensionID
  2021. // FROM
  2022. // ICSMOPick a
  2023. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2024. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  2025. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2026. // WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  2027. // GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  2028. // #endregion
  2029. // }
  2030. // if (Type == "2")
  2031. // {
  2032. // #region 工单领料SQL
  2033. // sqls = @" select
  2034. // x.MergeID,
  2035. // a.ApplyCode as Code,
  2036. // a.InvCode,
  2037. // b.InvName,
  2038. // b.InvStd,
  2039. //b.InvUnit,
  2040. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2041. // a.WhCode,
  2042. // a.ExtensionID
  2043. // FROM
  2044. // ICSMOApply a
  2045. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2046. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2047. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  2048. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  2049. // #endregion
  2050. // }
  2051. // if (Type == "3")
  2052. // {
  2053. // #region 工单材料出库SQL
  2054. // sqls = @" select
  2055. // x.MergeID,
  2056. // a.IssueCode as Code,
  2057. // a.InvCode,
  2058. // b.InvName,
  2059. // b.InvStd,
  2060. //b.InvUnit,
  2061. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2062. // a.WhCode,
  2063. //a.ExtensionID
  2064. // FROM
  2065. // ICSMOIssue a
  2066. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2067. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2068. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  2069. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2070. // #endregion
  2071. // }
  2072. // if (Type == "4")
  2073. // {
  2074. // #region 委外备料SQL
  2075. // sqls = @" select
  2076. // x.MergeID,
  2077. // c.OOCode as Code,
  2078. // a.InvCode,
  2079. // b.InvName,
  2080. // b.InvStd,
  2081. //b.InvUnit,
  2082. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2083. // a.WhCode,
  2084. //a.ExtensionID
  2085. // FROM
  2086. // ICSOOPick a
  2087. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2088. // left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  2089. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2090. // WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  2091. // GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
  2092. // #endregion
  2093. // }
  2094. // if (Type == "5")
  2095. // {
  2096. // #region 委外领料SQL
  2097. // sqls = @" select
  2098. // x.MergeID,
  2099. // a.ApplyCode as Code,
  2100. // a.InvCode,
  2101. // b.InvName,
  2102. // b.InvStd,
  2103. //b.InvUnit,
  2104. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2105. // a.WhCode,
  2106. //a.ExtensionID
  2107. // FROM
  2108. // ICSOApply a
  2109. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2110. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2111. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  2112. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2113. // #endregion
  2114. // }
  2115. // if (Type == "6")
  2116. // {
  2117. // #region 委外材料出库SQL
  2118. // sqls = @" select
  2119. // x.MergeID,
  2120. // a.IssueCode as Code,
  2121. // a.InvCode,
  2122. // b.InvName,
  2123. // b.InvStd,
  2124. //b.InvUnit,
  2125. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2126. // a.WhCode,
  2127. //a.ExtensionID
  2128. // FROM
  2129. // ICSOIssue a
  2130. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2131. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2132. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  2133. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2134. // #endregion
  2135. // }
  2136. // if (Type == "7")
  2137. // {
  2138. // #region 销售发货SQL
  2139. // sqls = @" select
  2140. // x.MergeID,
  2141. // a.SDNCode as Code,
  2142. // a.InvCode,
  2143. // b.InvName,
  2144. // b.InvStd,
  2145. //b.InvUnit,
  2146. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2147. // a.WhCode,
  2148. //a.ExtensionID
  2149. // FROM
  2150. // ICSSDN a
  2151. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2152. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2153. // WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  2154. // GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2155. // #endregion
  2156. // }
  2157. // if (Type == "8")
  2158. // {
  2159. // #region 其它出库SQL
  2160. // sqls = @" select
  2161. // x.MergeID,
  2162. // a.OutCode as Code,
  2163. // a.InvCode,
  2164. // b.InvName,
  2165. // b.InvStd,
  2166. //b.InvUnit,
  2167. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2168. // a.WhCode,
  2169. //a.ExtensionID
  2170. // FROM
  2171. // ICSOtherOut a
  2172. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2173. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2174. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  2175. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2176. // #endregion
  2177. // }
  2178. // if (Type == "9")
  2179. // {
  2180. // #region 借用SQL
  2181. // sqls = @" select
  2182. // x.MergeID,
  2183. // a.BrrowCode as Code,
  2184. // a.InvCode,
  2185. // b.InvName,
  2186. // b.InvStd,
  2187. //b.InvUnit,
  2188. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2189. // a.WhCode,
  2190. //a.ExtensionID
  2191. // FROM
  2192. // ICSBrrow a
  2193. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2194. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2195. // WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  2196. // GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2197. // #endregion
  2198. // }
  2199. // if (Type == "10")
  2200. // {
  2201. // #region 物料调拨
  2202. // sqls = @" select
  2203. // x.MergeID,
  2204. // a.TransferNO as Code,
  2205. // a.InvCode,
  2206. // b.InvName,
  2207. // b.InvStd,
  2208. //b.InvUnit,
  2209. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2210. // a.FromWarehouseCode as WhCode,
  2211. //a.ExtensionID
  2212. // FROM
  2213. // ICSTransfer a
  2214. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2215. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2216. // WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  2217. // GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
  2218. // #endregion
  2219. // }
  2220. // if (Type == "11")
  2221. // {
  2222. // #region 两步调出
  2223. // sqls = @"select
  2224. // x.MergeID,
  2225. // a.OutCode as Code,
  2226. // a.InvCode,
  2227. // b.InvName,
  2228. // b.InvStd,
  2229. // b.InvUnit,
  2230. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2231. // a.WHCode as WhCode,
  2232. // a.ExtensionID
  2233. // FROM
  2234. // ICSOtherOut a
  2235. // INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  2236. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2237. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2238. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  2239. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
  2240. // #endregion
  2241. // }
  2242. // sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  2243. // sql = string.Format(sql, sqls, WorkPoint);
  2244. // DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  2245. // DataTable dtCloned = table.Clone();
  2246. // foreach (DataColumn col in dtCloned.Columns)
  2247. // {
  2248. // col.DataType = typeof(string);
  2249. // }
  2250. // foreach (DataRow row in table.Rows)
  2251. // {
  2252. // DataRow newrow = dtCloned.NewRow();
  2253. // foreach (DataColumn column in dtCloned.Columns)
  2254. // {
  2255. // newrow[column.ColumnName] = row[column.ColumnName].ToString();
  2256. // }
  2257. // dtCloned.Rows.Add(newrow);
  2258. // }
  2259. // if (Invmes.Rows.Count > 0)
  2260. // {
  2261. // dtCloned.Merge(Invmes, false);
  2262. // }
  2263. // return dtCloned;
  2264. // }
  2265. public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  2266. {
  2267. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2268. string sqls = "";
  2269. if (Type == "1")
  2270. {
  2271. #region 工单备料sql
  2272. sqls = @" select
  2273. x.MergeID,
  2274. c.MOCode as Code,
  2275. a.InvCode,
  2276. b.InvName,
  2277. b.InvStd,
  2278. b.InvUnit,
  2279. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2280. a.WhCode,
  2281. a.ExtensionID
  2282. FROM
  2283. ICSMOPick a
  2284. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2285. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  2286. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2287. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  2288. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  2289. #endregion
  2290. }
  2291. if (Type == "2" || Type=="12")
  2292. {
  2293. #region 工单领料SQL
  2294. sqls = @" select
  2295. x.MergeID,
  2296. a.ApplyCode as Code,
  2297. a.InvCode,
  2298. b.InvName,
  2299. b.InvStd,
  2300. b.InvUnit,
  2301. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2302. a.WhCode,
  2303. a.ExtensionID
  2304. FROM
  2305. ICSMOApply a
  2306. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2307. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2308. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  2309. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  2310. #endregion
  2311. }
  2312. if (Type == "3")
  2313. {
  2314. #region 工单材料出库SQL
  2315. sqls = @" select
  2316. x.MergeID,
  2317. a.IssueCode as Code,
  2318. a.InvCode,
  2319. b.InvName,
  2320. b.InvStd,
  2321. b.InvUnit,
  2322. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2323. a.WhCode,
  2324. a.ExtensionID
  2325. FROM
  2326. ICSMOIssue a
  2327. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2328. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2329. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  2330. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2331. #endregion
  2332. }
  2333. if (Type == "4")
  2334. {
  2335. #region 委外备料SQL
  2336. sqls = @" select
  2337. x.MergeID,
  2338. c.OOCode as Code,
  2339. a.InvCode,
  2340. b.InvName,
  2341. b.InvStd,
  2342. b.InvUnit,
  2343. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2344. a.WhCode,
  2345. a.ExtensionID
  2346. FROM
  2347. ICSOOPick a
  2348. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2349. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  2350. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2351. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  2352. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
  2353. #endregion
  2354. }
  2355. if (Type == "5")
  2356. {
  2357. #region 委外领料SQL
  2358. sqls = @" select
  2359. x.MergeID,
  2360. a.ApplyCode as Code,
  2361. a.InvCode,
  2362. b.InvName,
  2363. b.InvStd,
  2364. b.InvUnit,
  2365. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2366. a.WhCode,
  2367. a.ExtensionID
  2368. FROM
  2369. ICSOApply a
  2370. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2371. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2372. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  2373. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2374. #endregion
  2375. }
  2376. if (Type == "6")
  2377. {
  2378. #region 委外材料出库SQL
  2379. sqls = @" select
  2380. x.MergeID,
  2381. a.IssueCode as Code,
  2382. a.InvCode,
  2383. b.InvName,
  2384. b.InvStd,
  2385. b.InvUnit,
  2386. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2387. a.WhCode,
  2388. a.ExtensionID
  2389. FROM
  2390. ICSOIssue a
  2391. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2392. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2393. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  2394. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2395. #endregion
  2396. }
  2397. if (Type == "7")
  2398. {
  2399. #region 销售发货SQL
  2400. sqls = @" select
  2401. x.MergeID,
  2402. a.SDNCode as Code,
  2403. a.InvCode,
  2404. b.InvName,
  2405. b.InvStd,
  2406. b.InvUnit,
  2407. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2408. a.WhCode,
  2409. a.ExtensionID
  2410. FROM
  2411. ICSSDN a
  2412. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2413. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2414. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}' AND a.Type='1'
  2415. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2416. #endregion
  2417. }
  2418. if (Type == "8")
  2419. {
  2420. #region 其它出库SQL
  2421. sqls = @" select
  2422. x.MergeID,
  2423. a.OutCode as Code,
  2424. a.InvCode,
  2425. b.InvName,
  2426. b.InvStd,
  2427. b.InvUnit,
  2428. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2429. a.WhCode,
  2430. a.ExtensionID
  2431. FROM
  2432. ICSOtherOut a
  2433. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2434. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2435. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  2436. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2437. #endregion
  2438. }
  2439. if (Type == "9")
  2440. {
  2441. #region 借用SQL
  2442. sqls = @" select
  2443. x.MergeID,
  2444. a.BrrowCode as Code,
  2445. a.InvCode,
  2446. b.InvName,
  2447. b.InvStd,
  2448. b.InvUnit,
  2449. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2450. a.WhCode,
  2451. a.ExtensionID
  2452. FROM
  2453. ICSBrrow a
  2454. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2455. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2456. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  2457. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2458. #endregion
  2459. }
  2460. if (Type == "10")
  2461. {
  2462. #region 物料调拨
  2463. sqls = @" select
  2464. x.MergeID,
  2465. a.TransferNO as Code,
  2466. a.InvCode,
  2467. b.InvName,
  2468. b.InvStd,
  2469. b.InvUnit,
  2470. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2471. a.FromWarehouseCode as WhCode,
  2472. a.ExtensionID
  2473. FROM
  2474. ICSTransfer a
  2475. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2476. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2477. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  2478. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
  2479. #endregion
  2480. }
  2481. if (Type == "11")
  2482. {
  2483. #region 两步调出
  2484. sqls = @" select
  2485. x.MergeID,
  2486. a.OutCode as Code,
  2487. a.InvCode,
  2488. b.InvName,
  2489. b.InvStd,
  2490. b.InvUnit,
  2491. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2492. a.WHCode as WhCode,
  2493. a.ExtensionID
  2494. FROM
  2495. ICSOtherOut a
  2496. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  2497. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2498. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2499. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  2500. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
  2501. #endregion
  2502. }
  2503. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  2504. #region sql
  2505. string sql = $@"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  2506. c.MergeID,
  2507. c.Code,
  2508. c.InvCode,
  2509. c.InvName,
  2510. c.InvStd,
  2511. c.InvUnit,
  2512. FLOOR(c.iQuantity) AS iQuantity,
  2513. d.WarehouseCode,
  2514. d.LocationCode,
  2515. d.LotNO,
  2516. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  2517. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  2518. FLOOR(f.QTYTotal) QTYTotal
  2519. FROM
  2520. ({sqls}) c
  2521. left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
  2522. from ICSWareHouseLotInfo d ,ICSInventoryLot m
  2523. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  2524. and d.WorkPoint='{WorkPoint}' AND d.Quantity>0 ) d
  2525. on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  2526. 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
  2527. order by c.Code,c.InvCode,d.MTIME ";
  2528. #endregion
  2529. var dataset = Repository().FindDataSetBySql(sql);
  2530. if (dataset.Tables.Count == 0)
  2531. return null;
  2532. DataTable table = dataset.Tables[0];
  2533. decimal qtyCount = 0;
  2534. bool remove = false;
  2535. List<int> removeList = new List<int>();
  2536. for (int i = 0; i < table.Rows.Count; i++)
  2537. {
  2538. if (i != 0
  2539. && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  2540. || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString()))
  2541. )
  2542. {
  2543. qtyCount = 0;
  2544. remove = false;
  2545. }
  2546. if (remove)
  2547. {
  2548. removeList.Add(i);
  2549. }
  2550. else
  2551. {
  2552. var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
  2553. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  2554. qtyCount += lotQty;
  2555. if (qtyCount >= orderQty)
  2556. {
  2557. remove = true;
  2558. }
  2559. }
  2560. }
  2561. if (removeList.Count > 0)
  2562. {
  2563. removeList.Reverse();
  2564. foreach (var item in removeList)
  2565. {
  2566. table.Rows.RemoveAt(item);
  2567. }
  2568. }
  2569. var result = ConvertCellToString(table);
  2570. if (Invmes.Rows.Count > 0)
  2571. {
  2572. result.Merge(Invmes, false);
  2573. }
  2574. return result;
  2575. }
  2576. public string MergeMaterial(string keyValue, string Type)
  2577. {
  2578. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2579. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2580. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2581. string msg = "";
  2582. string sql = string.Empty;
  2583. string dataList = string.Empty;
  2584. List<string> arry = keyValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  2585. if (arry.Count > 0)
  2586. {
  2587. StringBuilder stringBuilder = new StringBuilder();
  2588. foreach (var i in arry)
  2589. {
  2590. stringBuilder.Append($@"'{i}',");
  2591. }
  2592. dataList = stringBuilder.ToString(0, stringBuilder.Length - 1);
  2593. }
  2594. Int64 Merge_ID = 0;
  2595. DateTime time = DateTime.Now;
  2596. string Tday = time.ToString("yyyyMMdd");
  2597. string sqls = string.Format(@"SELECT MAX(A.MergeID) AS SourceID FROM ICSMOPickMerge A WHERE A.MergeID LIKE '{0}%' AND LEN(a.MergeID) = 13", Tday);
  2598. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  2599. DataTable dts = ds.Tables[0];
  2600. if (dts != null && dts.Rows.Count > 0)
  2601. {
  2602. string lot = dts.Rows[0]["SourceID"].ToString();
  2603. if (!string.IsNullOrWhiteSpace(lot))
  2604. Merge_ID = Convert.ToInt64(lot.Substring(lot.Length - 5));
  2605. }
  2606. string MergeID = Tday + (Merge_ID + 1).ToString().PadLeft(5, '0');
  2607. string order = string.Empty;
  2608. string orderCode = string.Empty;
  2609. string quantity = string.Empty;
  2610. string sqlString1 = string.Empty;
  2611. string sqlString2 = string.Empty;
  2612. if (Type == "1")//工单备料
  2613. {
  2614. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2615. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2616. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2617. from ICSMO a inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  2618. where a.MOCode in ({5})
  2619. ";
  2620. }
  2621. if (Type == "2")//工单发料
  2622. {
  2623. order = "ICSMOApply";
  2624. orderCode = "b.ApplyCode";
  2625. quantity = "b.IssueQuantity";
  2626. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2627. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2628. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.ApplyCode
  2629. from ICSMOApply a
  2630. where a.ApplyCode in ({5})";
  2631. }
  2632. if (Type == "3")//材料出库
  2633. {
  2634. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2635. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2636. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2637. from ICSMOIssue a
  2638. where a.IssueCode in ({5}) ";
  2639. }
  2640. if (Type == "4")//委外备料
  2641. {
  2642. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2643. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2644. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2645. from ICSOutsourcingOrder a inner join ICSOOPick b on a.OODetailID=b.OODetailID and b.WorkPoint=a.WorkPoint
  2646. where a.OOCode in ({5})";
  2647. }
  2648. if (Type == "5")//委外领料
  2649. {
  2650. order = "ICSOApply";
  2651. orderCode = "b.ApplyCode";
  2652. quantity = "b.IssueQuantity";
  2653. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2654. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2655. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.ApplyCode
  2656. from ICSOApply a
  2657. where a.ApplyCode in ({5})";
  2658. }
  2659. if (Type == "6")//委外材料出库
  2660. {
  2661. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2662. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2663. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2664. from ICSOIssue a
  2665. where a.IssueCode in ({5})";
  2666. }
  2667. if (Type == "7")//销售发货
  2668. {
  2669. order = "ICSSDN";
  2670. orderCode = "b.SDNCode";
  2671. quantity = "b.SDNQuantity";
  2672. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2673. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2674. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.SDNCode
  2675. from ICSSDN a
  2676. where a.SDNCode in ({5}) AND a.Type='1' ";
  2677. }
  2678. if (Type == "8")//其它出库
  2679. {
  2680. order = "ICSOtherOut";
  2681. orderCode = "b.OutCode";
  2682. quantity = "b.OutQuantity";
  2683. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2684. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2685. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.OutCode
  2686. from ICSOtherOut a
  2687. where a.OutCode in ({5})";
  2688. }
  2689. if (Type == "9")//借用单
  2690. {
  2691. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2692. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2693. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2694. from ICSBrrow a
  2695. where a.BrrowCode in ({5})";
  2696. }
  2697. if (Type == "10")//物料调拨
  2698. {
  2699. order = "ICSTransfer";
  2700. orderCode = "b.TransferNO";
  2701. quantity = "b.TransferQuantity";
  2702. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2703. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2704. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.TransferNO
  2705. from ICSTransfer a
  2706. where a.TransferNO in ({5})
  2707. ";
  2708. }
  2709. if (Type == "11")//两步调出
  2710. {
  2711. sql += @" INSERT INTO dbo.ICSMOPickMerge
  2712. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2713. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2714. from ICSOtherOut a
  2715. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  2716. where a.OutCode in ({5})
  2717. ";
  2718. }
  2719. sql = string.Format(sql, MergeID, Type, MUSER, MUSERNAME, WorkPoint, dataList);
  2720. sqlString1 += $@" SELECT a.ID FROM ICSMOPickMerge a WHERE a.SourceID IN (SELECT b.ID FROM {order} b WHERE {orderCode} IN({dataList}) )";
  2721. sqlString2 += $@" SELECT b.ID FROM {order} b WHERE {orderCode} IN({dataList}) AND {quantity}>0";
  2722. DataSet ds1 = SqlHelper.GetDataSetBySql(sqlString1);
  2723. DataSet ds2 = SqlHelper.GetDataSetBySql(sqlString2);
  2724. DataTable dts1 = ds1.Tables[0];
  2725. DataTable dts2 = ds2.Tables[0];
  2726. if ((dts1 != null && dts1.Rows.Count > 0))
  2727. {
  2728. }
  2729. else if (dts2 != null && dts2.Rows.Count > 0)
  2730. {
  2731. msg = "当前选择单据号存在已出库的单据号,合并 失败";
  2732. }
  2733. else
  2734. {
  2735. try
  2736. {
  2737. if (SqlHelper.CmdExecuteNonQueryLi(sql) == 0)
  2738. {
  2739. msg = "新增失败";
  2740. }
  2741. }
  2742. catch (Exception ex)
  2743. {
  2744. throw new Exception(ex.Message);
  2745. }
  2746. }
  2747. return msg;
  2748. }
  2749. public string CancelMergeMaterial(string keyValue, string Type)
  2750. {
  2751. string msg = "";
  2752. string sql = string.Empty;
  2753. keyValue = keyValue.TrimEnd(',');
  2754. List<string> arry = keyValue.Split(',').ToList();
  2755. string dataList = string.Empty;
  2756. if (arry.Count > 0)
  2757. {
  2758. foreach (var i in arry)
  2759. {
  2760. dataList += $@"'{i}',";
  2761. }
  2762. if (dataList.Any())
  2763. {
  2764. dataList = dataList.TrimEnd(',');
  2765. }
  2766. }
  2767. string sqls = $@" SELECT SourceID FROM ICSMOPickMerge WHERE EATTRIBUTE1 IN({dataList}) ";
  2768. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  2769. DataTable dts = ds.Tables[0];
  2770. if (dts == null || dts.Rows.Count <= 0)
  2771. {
  2772. msg = "当前单据未合并拣料,取消合并拣料失败";
  2773. return msg;
  2774. }
  2775. string sqlStrring = string.Empty;
  2776. if (Type == "2")//工单发料
  2777. {
  2778. sqlStrring = $@"select ID from ICSMOApply a where a.ID in ({sqls}) and a.IssueQuantity=0 ";
  2779. }
  2780. if (Type == "5")//委外领料
  2781. {
  2782. sqlStrring = $@"select ID from ICSOApply a where a.ID in ({sqls}) and a.IssueQuantity=0 ";
  2783. }
  2784. if (Type == "7")//销售发货
  2785. {
  2786. sqlStrring = $@"select ID from ICSSDN a where a.ID in ({sqls}) and a.SDNQuantity=0 AND a.Type='1' ";
  2787. }
  2788. if (Type == "8")//其它出库
  2789. {
  2790. sqlStrring = $@"select ID
  2791. from ICSOtherOut a
  2792. where a.ID in ({sqls}) and a.OutQuantity=0";
  2793. }
  2794. if (Type == "10")//物料调拨
  2795. {
  2796. sqlStrring = $@"select ID from ICSTransfer a where a.ID in ({sqls}) and a.TransferQuantity=0 ";
  2797. }
  2798. DataSet dsdata = SqlHelper.GetDataSetBySql(sqlStrring);
  2799. DataTable dtdsdatas = dsdata.Tables[0];
  2800. if (dtdsdatas == null || dtdsdatas.Rows.Count <= 0)
  2801. {
  2802. msg = "当前物料已经出库,取消合并失败";
  2803. return msg;
  2804. }
  2805. sql = $@"DELETE FROM ICSMOPickMerge WHERE SourceID IN({sqls})";
  2806. try
  2807. {
  2808. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  2809. {
  2810. }
  2811. else
  2812. {
  2813. msg = "取消合并失败";
  2814. }
  2815. }
  2816. catch (Exception ex)
  2817. {
  2818. throw new Exception(ex.Message);
  2819. }
  2820. return msg;
  2821. }
  2822. public string CheckQty(string objArr)
  2823. {
  2824. objArr = objArr.TrimEnd(',');
  2825. string sql = @"select * from ICSMOPickMerge a
  2826. left join ICSMOPick b on a.SourceID=b.ID and a.WorkPoint=b.WorkPoint
  2827. left join ICSMO c on b.MODetailID=c.MODetailID and b.WorkPoint=c.WorkPoint
  2828. where MOCode in ({0})";
  2829. sql = string.Format(sql, objArr);
  2830. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  2831. if (dt != null && dt.Rows.Count > 0)
  2832. {
  2833. return "1";
  2834. }
  2835. return "0";
  2836. }
  2837. //删除占料
  2838. public string DelPickLog(string objCode)
  2839. {
  2840. //站点信息
  2841. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2842. string msg = "";
  2843. objCode = objCode.Substring(1, objCode.Length - 2);
  2844. string sql = string.Empty;
  2845. sql += string.Format(@"update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),a.Quantity )
  2846. from dbo.ICSWareHouseLotInfoLog a
  2847. left join dbo.ICSWareHouseLotInfo b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  2848. where a.TransCode in ({0}) and a.TransType='15' and a.WorkPoint='{1}'", objCode.TrimEnd(','), WorkPoint);
  2849. sql += string.Format(@" delete dbo.ICSWareHouseLotInfoLog where TransCode in({0}) and TransType='15' and WorkPoint='{1}'", objCode.TrimEnd(','), WorkPoint);
  2850. try
  2851. {
  2852. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  2853. {
  2854. }
  2855. }
  2856. catch (Exception ex)
  2857. {
  2858. throw new Exception(ex.Message);
  2859. }
  2860. return msg;
  2861. }
  2862. public int SeachPickLog(string objCode)
  2863. {
  2864. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2865. objCode = objCode.TrimEnd(',');
  2866. string[] parameters = objCode.Split(',');
  2867. int parameterCount = parameters.Length;
  2868. string sql = @" select distinct a.TransCode from dbo.ICSWareHouseLotInfoLog a
  2869. left join dbo.ICSWareHouseLotInfo b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  2870. where a.TransCode in ({0}) and a.TransType='15' and a.WorkPoint='{1}'";
  2871. sql = string.Format(sql, objCode, WorkPoint);
  2872. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  2873. int count = dt.Rows.Count;
  2874. return count;
  2875. }
  2876. public DataTable GetPickLogInfo(string ID)
  2877. {
  2878. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2879. DataTable dt = new DataTable();
  2880. List<DbParameter> parameter = new List<DbParameter>();
  2881. string sql = @"
  2882. 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,
  2883. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  2884. from dbo.ICSWareHouseLotInfoLog a
  2885. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  2886. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  2887. where a.TransCode in ({0}) and a.TransType='15' and a.WorkPoint='{1}'";
  2888. sql = string.Format(sql, ID.TrimEnd(','), WorkPoint);
  2889. return Repository().FindTableBySql(sql.ToString());
  2890. }
  2891. }
  2892. }