锐腾搅拌上料功能
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.

365 lines
16 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ICSSoft.Base.Config.AppConfig;
  6. using ICSSoft.Frame.Data.Entity;
  7. using System.Data.Linq;
  8. using System.Data;
  9. namespace ICSSoft.Frame.Common
  10. {
  11. public static class TranOutClass
  12. {
  13. static DataTable dt ;
  14. //物料拣料表
  15. public static DataTable TranOut(string putCode)
  16. {
  17. dt = new DataTable();
  18. dt.Columns.Add("MoCode", typeof(string));
  19. dt.Columns.Add("LineNo", typeof(string));
  20. dt.Columns.Add("BInvCode", typeof(string));
  21. dt.Columns.Add("BInvName", typeof(string));
  22. dt.Columns.Add("LotNo", typeof(string));
  23. dt.Columns.Add("WHCode", typeof(string));
  24. dt.Columns.Add("BinCode", typeof(string));
  25. dt.Columns.Add("INVUOM", typeof(string));
  26. dt.Columns.Add("QTY", typeof(string));
  27. dt.Columns.Add("LotQty", typeof(string));
  28. dt.Columns.Add("User", typeof(string));
  29. dt.Columns.Add("Approver", typeof(string));
  30. FramDataContext context = new FramDataContext(AppConfig.AppConnectString);
  31. List<TranOut> trans = new List<TranOut>();
  32. //查询工单子件信息
  33. var puts = context.ICSPACKINGINPUT.Where(a => a.TransferNO == putCode).OrderBy(a=>a.TransferLineNo).ToList();
  34. if (puts == null) return dt;
  35. //循环查询库存子件信息
  36. foreach (ICSPACKINGINPUT put in puts)
  37. {
  38. decimal qty = 0;
  39. List<ICSWareHouseLotInfo> whs = new List<ICSWareHouseLotInfo>();
  40. var putitem = context.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == put.MOBITEMCODE);
  41. if (putitem.INVTYPE != "原材料" && putitem.INVTYPE != "采购原料")
  42. {
  43. whs = context.ICSWareHouseLotInfo.Where(a => a.INVCode == put.MOBITEMCODE && a.WHCode != "02" && a.LotQty > 0).OrderBy(b => b.MTIME).ToList();
  44. }
  45. else
  46. {
  47. whs = (from a in context.ICSWareHouseLotInfo
  48. join b in context.ICSITEMLot on a.INVCode equals b.ItemCode
  49. where a.INVCode == put.MOBITEMCODE && a.WHCode != "02" && a.LotQty > 0
  50. orderby b.PRODUCTDATE ascending
  51. select a).ToList();
  52. }
  53. foreach (ICSWareHouseLotInfo info in whs)
  54. {
  55. if (qty >= put.MOBITEMQTY)//如果数量满足了,继续下一个子件
  56. {
  57. break;
  58. }
  59. TranOut tran = new TranOut();
  60. tran.MoCode = putCode;
  61. tran.LineNo = put.TransferLineNo;
  62. tran.BInvCode = put.MOBITEMCODE;
  63. var item = context.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == put.MOBITEMCODE);
  64. if (item == null) throw new Exception("料品:" + put.MOBITEMCODE + "不存在!");
  65. tran.BInvName = item.INVNAME;
  66. tran.LotNo = info.LotNO;
  67. tran.WHCode = info.WHCode;
  68. tran.BinCode = info.BinCode;
  69. tran.INVUOM = item.INVUOM;
  70. tran.LotQty = info.LotQty.ToString();
  71. tran.User = put.MUSERName;
  72. tran.Approver = put.Approver;
  73. //应领数量
  74. if (put.MOBITEMQTY - qty < info.LotQty)
  75. {
  76. tran.QTY = (put.MOBITEMQTY - qty).ToString();
  77. }
  78. else
  79. tran.QTY = info.LotQty.ToString();
  80. trans.Add(tran);
  81. qty += decimal.Parse(tran.QTY);
  82. }
  83. }
  84. #region
  85. if (puts.Count == 0)
  86. {
  87. var pouts = context.ICSTransferNO.Where(a => a.TransferNO == putCode).OrderBy(a => a.TransLine).ToList();
  88. if (pouts == null) return dt;
  89. foreach (ICSTransferNO pout in pouts)
  90. {
  91. decimal qty = 0;
  92. List<ICSWareHouseLotInfo> whs = new List<ICSWareHouseLotInfo>();
  93. var putitem = context.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == pout.INVCode);
  94. #region
  95. if (putitem.INVTYPE != "原材料" && putitem.INVTYPE != "采购原料")
  96. {
  97. whs = context.ICSWareHouseLotInfo.Where(a => a.INVCode == pout.INVCode && a.WHCode != "02" && a.LotQty > 0).OrderBy(b => b.MTIME).ToList();
  98. }
  99. else
  100. {
  101. whs = (from a in context.ICSWareHouseLotInfo
  102. join b in context.ICSITEMLot on a.INVCode equals b.ItemCode
  103. where a.INVCode == pout.INVCode && a.WHCode != "02" && a.LotQty > 0
  104. orderby b.PRODUCTDATE ascending
  105. select a).ToList();
  106. }
  107. #endregion
  108. foreach (ICSWareHouseLotInfo info in whs)
  109. {
  110. if (qty >= pout.QTY)//如果数量满足了,继续下一个子件
  111. {
  112. break;
  113. }
  114. TranOut tran = new TranOut();
  115. tran.MoCode = putCode;
  116. tran.LineNo = pout.TransLine;
  117. tran.BInvCode = pout.INVCode;
  118. var item = context.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == pout.INVCode);
  119. if (item == null) throw new Exception("料品:" + pout.INVCode + "不存在!");
  120. tran.BInvName = item.INVNAME;
  121. tran.LotNo = info.LotNO;
  122. tran.WHCode = info.WHCode;
  123. tran.BinCode = info.BinCode;
  124. tran.INVUOM = item.INVUOM;
  125. tran.LotQty = info.LotQty.ToString();
  126. tran.User = pout.MUSERName;
  127. tran.Approver = pout.Approver;
  128. //应领数量
  129. if (pout.QTY - qty < info.LotQty)
  130. {
  131. tran.QTY = (pout.QTY - qty).ToString();
  132. }
  133. else
  134. tran.QTY = info.LotQty.ToString();
  135. trans.Add(tran);
  136. qty += decimal.Parse(tran.QTY);
  137. }
  138. }
  139. }
  140. #endregion
  141. //输出到表
  142. foreach (TranOut tran in trans)
  143. {
  144. DataRow dw = dt.NewRow();
  145. dw["MoCode"] = tran.MoCode;
  146. dw["LineNo"] = tran.LineNo;
  147. dw["BInvCode"] = tran.BInvCode;
  148. dw["BInvName"] = tran.BInvName;
  149. dw["LotNo"] = tran.LotNo;
  150. dw["WHCode"] = tran.WHCode;
  151. dw["BinCode"] = tran.BinCode;
  152. dw["INVUOM"] = tran.INVUOM;
  153. dw["QTY"] = tran.QTY;
  154. dw["LotQty"] = tran.QTY;
  155. dw["User"] = tran.User;
  156. dw["Approver"] = tran.Approver;
  157. dt.Rows.Add(dw);
  158. }
  159. return dt;
  160. }
  161. //销售拣货表
  162. public static DataTable TranOutX(string putCode)
  163. {
  164. dt = new DataTable();
  165. dt.Columns.Add("MoCode", typeof(string));
  166. dt.Columns.Add("LineNo", typeof(string));
  167. dt.Columns.Add("BInvCode", typeof(string));
  168. dt.Columns.Add("BInvName", typeof(string));
  169. dt.Columns.Add("LotNo", typeof(string));
  170. dt.Columns.Add("WHCode", typeof(string));
  171. dt.Columns.Add("BinCode", typeof(string));
  172. dt.Columns.Add("INVUOM", typeof(string));
  173. dt.Columns.Add("QTY", typeof(string));
  174. dt.Columns.Add("LotQty", typeof(string));
  175. dt.Columns.Add("User", typeof(string));
  176. FramDataContext context = new FramDataContext(AppConfig.AppConnectString);
  177. List<TranOut> trans = new List<TranOut>();
  178. //查询工单子件信息
  179. var puts = context.ICSSODispatch.Where(a =>a.DispatchCode == putCode).OrderBy(a => a.DispatchRow).ToList();
  180. if (puts == null) return dt;
  181. //循环查询库存子件信息
  182. foreach (ICSSODispatch put in puts)
  183. {
  184. decimal qty = 0;
  185. List<ICSWareHouseLotInfo> whs=new List<ICSWareHouseLotInfo>() ;
  186. var putitem=context.ICSINVENTORY.SingleOrDefault(a=>a.INVCODE==put.InvCode);
  187. if (putitem.INVTYPE != "原材料" && putitem.INVTYPE != "采购原料")
  188. {
  189. whs = context.ICSWareHouseLotInfo.Where(a => a.INVCode == put.InvCode && a.WHCode != "02" && a.LotQty > 0).OrderBy(b => b.MTIME).ToList();
  190. }
  191. else
  192. {
  193. whs = (from a in context.ICSWareHouseLotInfo
  194. join b in context.ICSITEMLot on a.INVCode equals b.ItemCode
  195. where a.INVCode == put.InvCode && a.WHCode != "02" && a.LotQty > 0
  196. orderby b.PRODUCTDATE ascending
  197. select a).ToList();
  198. }
  199. foreach (ICSWareHouseLotInfo info in whs)
  200. {
  201. if (qty >= put.Quantity)//如果数量满足了,继续下一个子件
  202. {
  203. break;
  204. }
  205. TranOut tran = new TranOut();
  206. tran.MoCode = putCode;
  207. tran.LineNo = put.DispatchRow;
  208. tran.BInvCode = put.InvCode;
  209. var item = context.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == put.InvCode);
  210. if (item == null) throw new Exception("料品:" + put.InvCode + "不存在!");
  211. tran.BInvName = item.INVNAME;
  212. tran.LotNo = info.LotNO;
  213. tran.WHCode = info.WHCode;
  214. tran.BinCode = info.BinCode;
  215. tran.INVUOM = item.INVUOM;
  216. tran.LotQty = info.LotQty.ToString();
  217. tran.User = put.MUSERName;
  218. //应领数量
  219. if (put.Quantity - qty < info.LotQty)
  220. {
  221. tran.QTY = (put.Quantity - qty).ToString();
  222. }
  223. else
  224. tran.QTY = info.LotQty.ToString();
  225. trans.Add(tran);
  226. qty += decimal.Parse(tran.QTY);
  227. }
  228. }
  229. //输出到表
  230. foreach (TranOut tran in trans)
  231. {
  232. DataRow dw = dt.NewRow();
  233. dw["MoCode"] = tran.MoCode;
  234. dw["LineNo"] = tran.LineNo;
  235. dw["BInvCode"] = tran.BInvCode;
  236. dw["BInvName"] = tran.BInvName;
  237. dw["LotNo"] = tran.LotNo;
  238. dw["WHCode"] = tran.WHCode;
  239. dw["BinCode"] = tran.BinCode;
  240. dw["INVUOM"] = tran.INVUOM;
  241. dw["QTY"] = tran.QTY;
  242. dw["LotQty"] = tran.QTY;
  243. dw["User"] = tran.User;
  244. dt.Rows.Add(dw);
  245. }
  246. return dt;
  247. }
  248. public static DataTable TranBack(string putCode)
  249. {
  250. dt = new DataTable();
  251. dt.Columns.Add("MoCode", typeof(string));
  252. dt.Columns.Add("LineNo", typeof(string));
  253. dt.Columns.Add("BInvCode", typeof(string));
  254. dt.Columns.Add("BInvName", typeof(string));
  255. dt.Columns.Add("LotNo", typeof(string));
  256. dt.Columns.Add("WHCode", typeof(string));
  257. dt.Columns.Add("BinCode", typeof(string));
  258. dt.Columns.Add("INVUOM", typeof(string));
  259. dt.Columns.Add("QTY", typeof(string));
  260. dt.Columns.Add("LotQty", typeof(string));
  261. dt.Columns.Add("User", typeof(string));
  262. dt.Columns.Add("Approver", typeof(string));
  263. FramDataContext context = new FramDataContext(AppConfig.AppConnectString);
  264. List<TranOut> trans = new List<TranOut>();
  265. var pouts = context.ICSTransferNOBack.Where(a => a.TransferNO == putCode).OrderBy(a => a.TransLine).ToList();
  266. if (pouts == null) return dt;
  267. foreach (ICSTransferNOBack pout in pouts)
  268. {
  269. decimal qty = 0;
  270. List<ICSWareHouseLotInfo> whs = new List<ICSWareHouseLotInfo>();
  271. var putitem = context.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == pout.INVCode);
  272. #region
  273. if (putitem.INVTYPE != "原材料" && putitem.INVTYPE != "采购原料")
  274. {
  275. whs = context.ICSWareHouseLotInfo.Where(a => a.INVCode == pout.INVCode && a.WHCode != "02" && a.LotQty > 0).OrderBy(b => b.MTIME).ToList();
  276. }
  277. else
  278. {
  279. whs = (from a in context.ICSWareHouseLotInfo
  280. join b in context.ICSITEMLot on a.INVCode equals b.ItemCode
  281. where a.INVCode == pout.INVCode && a.WHCode != "02" && a.LotQty > 0
  282. orderby b.PRODUCTDATE ascending
  283. select a).ToList();
  284. }
  285. #endregion
  286. foreach (ICSWareHouseLotInfo info in whs)
  287. {
  288. if (qty >= pout.QTY)//如果数量满足了,继续下一个子件
  289. {
  290. break;
  291. }
  292. TranOut tran = new TranOut();
  293. tran.MoCode = putCode;
  294. tran.LineNo = pout.TransLine;
  295. tran.BInvCode = pout.INVCode;
  296. var item = context.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == pout.INVCode);
  297. if (item == null) throw new Exception("料品:" + pout.INVCode + "不存在!");
  298. tran.BInvName = item.INVNAME;
  299. tran.LotNo = info.LotNO;
  300. tran.WHCode = info.WHCode;
  301. tran.BinCode = info.BinCode;
  302. tran.INVUOM = item.INVUOM;
  303. tran.LotQty = info.LotQty.ToString();
  304. tran.User = pout.MUSERName;
  305. tran.Approver = pout.Approver;
  306. //应领数量
  307. if (pout.QTY - qty < info.LotQty)
  308. {
  309. tran.QTY = (pout.QTY - qty).ToString();
  310. }
  311. else
  312. tran.QTY = info.LotQty.ToString();
  313. trans.Add(tran);
  314. qty += decimal.Parse(tran.QTY);
  315. }
  316. }
  317. //输出到表
  318. foreach (TranOut tran in trans)
  319. {
  320. DataRow dw = dt.NewRow();
  321. dw["MoCode"] = tran.MoCode;
  322. dw["LineNo"] = tran.LineNo;
  323. dw["BInvCode"] = tran.BInvCode;
  324. dw["BInvName"] = tran.BInvName;
  325. dw["LotNo"] = tran.LotNo;
  326. dw["WHCode"] = tran.WHCode;
  327. dw["BinCode"] = tran.BinCode;
  328. dw["INVUOM"] = tran.INVUOM;
  329. dw["QTY"] = tran.QTY;
  330. dw["LotQty"] = tran.QTY;
  331. dw["User"] = tran.User;
  332. dw["Approver"] = tran.Approver;
  333. dt.Rows.Add(dw);
  334. }
  335. return dt;
  336. }
  337. }
  338. public class TranOut
  339. {
  340. public string MoCode { get; set; }
  341. public string LineNo { get; set; }
  342. public string BInvCode { get; set; }
  343. public string BInvName { get; set; }
  344. public string LotNo { get; set; }
  345. public string WHCode { get; set; }
  346. public string BinCode { get; set; }
  347. public string INVUOM { get; set; }
  348. public string QTY { get; set; }
  349. public string LotQty { get; set; }
  350. public string User { get; set; }
  351. public string Approver { get; set; }
  352. }
  353. }