爱思开
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.

2080 lines
137 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Net.Http;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace ICSSoft.DataProject
  13. {
  14. /// <summary>
  15. /// 使用中
  16. /// 更新库存表、日志表
  17. /// </summary>
  18. public class ICSWareHouseLotInfoService
  19. {
  20. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  21. /// <summary>
  22. /// 分批
  23. /// </summary>
  24. /// <param name="Identification"></param>
  25. /// <param name="TransCode"></param>
  26. /// <param name="TransSequence"></param>
  27. /// <param name="LotNo"></param>
  28. /// <param name="Quantity"></param>
  29. /// <param name="User"></param>
  30. /// <param name="WorkPoint"></param>
  31. /// <param name="TransType"></param>
  32. /// <param name="BusinessCode"></param>
  33. /// <param name="cmd"></param>
  34. public static void WareHouseLotInfoInBatches(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  35. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
  36. {
  37. }
  38. /// <summary>
  39. /// 添加库存
  40. /// </summary>
  41. /// <param name="LocationCode"></param>
  42. /// <param name="LotNo"></param>
  43. /// <param name="Quantity"></param>
  44. /// <param name="User"></param>
  45. /// <param name="WorkPoint"></param>
  46. /// <param name="TransType"></param>
  47. /// <param name="BusinessCode"></param>
  48. /// <param name="cmd"></param>
  49. public static void WareHouseLotInfoUp(string Identification, string LocationCode, string LotNo, string Quantity, string User,
  50. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID, string InvCode)
  51. {
  52. try
  53. {
  54. #region 添加库存(原条码退回,更新库存;新条码直接入库)
  55. string sql = string.Empty;
  56. if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription<DBValue>()
  57. && string.IsNullOrWhiteSpace(LogID))
  58. {
  59. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  60. BEGIN
  61. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  62. RETURN
  63. END ";
  64. }
  65. //sql += @"
  66. // IF NOT EXISTS(SELECT 1
  67. // FROM ICSMO a
  68. // INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MoCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  69. // INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  70. // INNER JOIN ICSExtension d ON d.ID=c.ExtensionID AND d.WorkPoint=c.WorkPoint
  71. // INNER JOIN ICSBackflushBCLog bclog ON a.MOCode=bclog.TransCode AND a.Sequence=bclog.TransSequence AND bclog.BatchCode=d.BatchCode
  72. // WHERE c.LotNo='{0}')
  73. // BEGIN
  74. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo468") + @"',16,1);
  75. // END
  76. // ";
  77. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  78. BEGIN
  79. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  80. RETURN
  81. END
  82. UPDATE ICSInventoryLot SET Quantity = '{3}' WHERE LotNo='{0}' AND WorkPoint = '{1}'
  83. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  84. BEGIN
  85. -- UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  86. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL({3},0) WHERE LotNo='{0}' AND WorkPoint='{1}'
  87. END
  88. ELSE
  89. BEGIN
  90. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  91. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  92. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  93. BEGIN
  94. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  95. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  96. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  97. BEGIN
  98. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  99. RETURN
  100. END
  101. END
  102. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  103. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  104. FROM ICSInventoryLot a
  105. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  106. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  107. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  108. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  109. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  110. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  111. END";
  112. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  113. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  114. {
  115. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  116. }
  117. List<ControlMode> mode = ICSControlModeService.GetControlModes();
  118. //管控方式启用"料品"时
  119. //if (mode.itemCode.Equals("ControlMode02"))
  120. //{
  121. //}
  122. ///添加日志
  123. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  124. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  125. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  126. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  127. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  128. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  129. '','',c.WarehouseCode,c.LocationCode,'{6}',
  130. '','0','{4}','{5}','0','',
  131. '','','',f.F_Account ,f.F_RealName ,
  132. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  133. FROM ICSInventoryLot a
  134. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  135. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  136. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  137. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  138. ";
  139. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  140. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  141. {
  142. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  143. }
  144. #endregion
  145. #region 生产入库,倒冲
  146. if (BusinessCode.Equals(TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>()))
  147. {
  148. #region 原sql
  149. // sql = @"-- 1.创建临时表 初始单据数据 maintemp
  150. // select
  151. // c.mocode as transcode,
  152. // a.modetailid as detailid,
  153. // a.invcode,
  154. // b.invname,
  155. // b.invstd,
  156. // a.quantity,
  157. // a.amount,
  158. // a.sequence as transsequence,
  159. // a.issuequantity,
  160. // c.sequence,
  161. // inv.invunit,
  162. // 0 as locationqty,
  163. // inv.amountunit,
  164. // a.extensionid,
  165. // a.workpoint,
  166. // ext.projectcode,
  167. // case when isnull(inv.batchenable, '0')='1' then ext.batchcode else '' end as batchcode,
  168. // ext.version,
  169. // ext.brand,
  170. // ext.cfree1,
  171. // ext.cfree2,
  172. // ext.cfree3,
  173. // ext.cfree4,
  174. // ext.cfree5,
  175. // ext.cfree6,
  176. // ext.cfree7,
  177. // ext.cfree8,
  178. // ext.cfree9,
  179. // ext.cfree10
  180. // into #maintemp
  181. //
  182. // from
  183. // icsmopick a
  184. // inner join icsmo c on a.modetailid=c.modetailid and a.workpoint=c.workpoint
  185. // left join icsinventory b on a.invcode = b.invcode and a.workpoint=b.workpoint
  186. // inner join icsextension ext on a.extensionid=ext.id and a.workpoint=ext.workpoint
  187. // inner join icsinventory inv on a.invcode=inv.invcode and a.workpoint=inv.workpoint
  188. // inner join (
  189. // select a.mocode,a.sequence,a.workpoint
  190. // from icsmo a
  191. // inner join icsinventorylotdetail b on b.transcode=a.mocode and b.transsequence=a.sequence and b.workpoint=a.workpoint
  192. // inner join icsinventorylot c on c.lotno=b.lotno and c.workpoint=b.workpoint
  193. // where c.lotno='{0}' and c.workpoint='{1}'
  194. // ) temp on c.mocode=temp.mocode and a.workpoint=temp.workpoint and c.sequence=temp.sequence
  195. // --where a.supplytype='1'
  196. // group by c.mocode,a.quantity,a.invcode,b.invname,b.invstd,a.whcode,a.extensionid,a.workpoint,inv.batchenable,a.modetailid,a.amount,a.sequence,a.issuequantity,inv.invname,inv.invcode,inv.invunit,inv.amountunit,c.sequence,
  197. // ext.projectcode,ext.batchcode,ext.version,ext.brand,ext.cfree1,ext.cfree2,ext.cfree3,ext.cfree4,ext.cfree5,ext.cfree6,ext.cfree7,ext.cfree8,ext.cfree9,ext.cfree10;
  198. //
  199. // select * into #resulttemp from #maintemp
  200. // alter table #resulttemp add lotno varchar(50)
  201. // delete from #resulttemp
  202. //
  203. // -- 2.根据maintemp 中的物料信息 查出库存中对应的条码信息 barcodetemp
  204. // select a.lotno,a.invcode,(a.quantity-a.lockquantity) as quantity ,a.mtime into #barcodetemp from icswarehouselotinfo a left join
  205. // (select #maintemp.invcode from #maintemp group by #maintemp.invcode) b on a.invcode = b.invcode where a.quantity-a.lockquantity>0 order by a.mtime asc
  206. //
  207. // -- 3.循环maintemp,根据 行号和子表id 向最终结果集中写入数据 ;barcodetemp 中的已匹配数据删除或更新
  208. // begin
  209. // declare @transsequence int;--当前循环的行号
  210. // declare @qty int;--条码表数量
  211. // declare @needqty int;--本行所需数量
  212. // declare @lotno varchar(50);--条码
  213. // declare @detailid varchar(50);--本行所在工单行id
  214. // declare tempcursor cursor for (select transsequence,detailid from #maintemp); --创建游标tempcursor,并定义游标所指向的集合
  215. // open tempcursor; --打开游标
  216. // fetch next from tempcursor into @transsequence,@detailid; --游标读取下一个数据
  217. // while @@fetch_status=0
  218. // begin
  219. // select @needqty=quantity from #maintemp where transsequence = @transsequence and detailid = @detailid
  220. // print @transsequence
  221. // while @needqty>0
  222. // begin
  223. //
  224. // select top 1 @qty = quantity,@lotno = lotno from #barcodetemp where invcode = (select invcode from #maintemp where transsequence = @transsequence and detailid = @detailid) order by mtime
  225. // if(@needqty-@qty>=0)
  226. // begin
  227. // insert into #resulttemp (lotno,transcode,detailid,sequence,transsequence,issuequantity,quantity,
  228. // amount,invcode,invname,invstd,invunit,locationqty,amountunit,
  229. // extensionid,projectcode,batchcode, version,brand,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10,workpoint)
  230. // select @lotno,transcode,detailid,sequence,transsequence,issuequantity, quantity,
  231. // isnull(amount, 0), invcode,invname,isnull(invstd, ''),invunit,@qty,isnull(amountunit, ''),
  232. // extensionid,projectcode,batchcode, version,brand,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10,workpoint from #maintemp
  233. // where #maintemp.transsequence = @transsequence and detailid = @detailid
  234. // delete from #barcodetemp where lotno = @lotno
  235. // set @needqty=@needqty-@qty
  236. // end
  237. // else
  238. // begin
  239. // insert into #resulttemp (lotno,transcode,detailid,sequence,transsequence,issuequantity,quantity,
  240. // amount,invcode,invname,invstd,invunit,locationqty,amountunit,
  241. // extensionid,projectcode,batchcode, version,brand,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10,workpoint)
  242. // select @lotno,transcode,detailid,sequence,transsequence,issuequantity, quantity,
  243. // isnull(amount, 0),invcode,invname,isnull(invstd, ''),invunit,@needqty,isnull(amountunit, ''),
  244. // extensionid,projectcode,batchcode, version,brand,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10,workpoint from #maintemp
  245. // where #maintemp.transsequence = @transsequence and detailid = @detailid
  246. // update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  247. // set @needqty=@needqty-@qty
  248. // end
  249. // end
  250. // fetch next from tempcursor into @transsequence,@detailid;
  251. // end
  252. // close tempcursor
  253. // deallocate tempcursor
  254. // end
  255. //
  256. // select transcode,lotno,locationqty as quantity,invcode,detailid,sequence,transsequence from #resulttemp
  257. // --select * from #resulttemp
  258. //
  259. // drop table #maintemp
  260. // drop table #resulttemp
  261. // drop table #barcodetemp";
  262. #endregion
  263. sql = @"SELECT DISTINCT b.lotno,d.invcode
  264. FROM ICSMO a
  265. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  266. INNER JOIN ICSMOPick d ON a.MODetailID=d.MODetailID AND a.WorkPoint=d.WorkPoint
  267. WHERE b.LotNo='{0}' AND (d.invcode like'1%' or d.invcode like'2%') AND a.WorkPoint='{1}'";
  268. sql = String.Format(sql, LotNo, WorkPoint);
  269. DataTable table2 = DBHelper.SQlReturnData(sql, cmd);
  270. if (table2 != null)
  271. {
  272. #region sql(子件为成品)
  273. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  274. SELECT
  275. c.MOCode AS TransCode,
  276. a.MODetailID AS DetailID,
  277. a.WHCode,
  278. a.InvCode,
  279. b.InvName,
  280. b.InvStd,
  281. (a.Quantity/c.Quantity*temp.Quantity) as Quantity,
  282. a.Amount,
  283. a.Sequence AS TransSequence,
  284. a.IssueQuantity,
  285. c.Sequence,
  286. inv.InvUnit,
  287. 0 AS LocationQty,
  288. inv.AmountUnit,
  289. a.ExtensionID,
  290. a.WorkPoint,
  291. ext.ProjectCode,
  292. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS cBatchCode,
  293. ext.Version,
  294. ext.Brand,
  295. ext.cFree1,
  296. ext.cFree2,
  297. ext.cFree3,
  298. ext.cFree4,
  299. ext.cFree5,
  300. ext.cFree6,
  301. ext.cFree7,
  302. ext.cFree8,
  303. ext.cFree9,
  304. ext.cFree10,
  305. temp.BatchCode
  306. INTO #maintemp
  307. FROM
  308. ICSMOPick a
  309. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  310. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  311. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  312. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  313. INNER JOIN (
  314. SELECT a.MOCode,a.Sequence,a.WorkPoint,d.BatchCode,c.Quantity
  315. FROM ICSMO a
  316. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  317. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  318. LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID AND a.WorkPoint=d.WorkPoint
  319. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  320. ) temp ON c.MOCode=temp.MOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  321. WHERE a.SupplyType='1'
  322. GROUP BY c.MOCode,a.Quantity,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,a.WorkPoint,inv.BatchEnable,a.MODetailID,a.Amount,a.Sequence,a.IssueQuantity,inv.InvName,inv.InvCode,inv.InvUnit,inv.AmountUnit,c.Sequence,
  323. ext.ProjectCode,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,temp.BatchCode,c.Quantity,temp.Quantity;
  324. select * into #resulttemp from #maintemp
  325. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  326. delete from #resulttemp
  327. -- 2.maintemp barcodetemp
  328. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime,ext.BatchCode into #barcodetemp from ICSWareHouseLotInfo a inner JOIN
  329. (select #maintemp.invcode,#maintemp.WHCode from #maintemp group by #maintemp.InvCode,#maintemp.WHCode) b on a.invcode = b.invcode and a.WarehouseCode=b.WHCode
  330. LEFT JOIN ICSInventoryLot lot on a.lotno=lot.lotno and a.WorkPoint=lot.WorkPoint
  331. LEFT JOIN ICSExtension ext on lot.ExtensionID=ext.ID and a.WorkPoint=ext.WorkPoint
  332. where a.Quantity-a.lockQuantity>0 and a.WorkPoint='{1}' ORDER BY a.MTIME ASC
  333. -- 3.maintemp ID barcodetemp
  334. BEGIN
  335. DECLARE @transSequence int;--
  336. DECLARE @qty int;--
  337. DECLARE @needqty int;--
  338. DECLARE @lotno VARCHAR(50);--
  339. DECLARE @batch VARCHAR(50);--
  340. DECLARE @DetailID VARCHAR(50);--ID
  341. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  342. OPEN tempCursor; --
  343. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  344. WHILE @@fetch_status=0
  345. BEGIN
  346. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  347. PRINT @transSequence
  348. WHILE @needqty>0
  349. BEGIN
  350. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,''), @batch=ISNULL(BatchCode, '') from #barcodetemp a
  351. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  352. BEGIN
  353. --IF(@needqty-@qty>=0)
  354. IF(@needqty-@qty>0 and ISNULL(@lotno, '')<>'')
  355. BEGIN
  356. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  357. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  358. ExtensionID,ProjectCode,cBatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,BatchCode)
  359. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  360. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  361. ExtensionID,ProjectCode,@batch, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,BatchCode from #maintemp
  362. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  363. delete from #barcodetemp where lotno = @lotno
  364. SET @needqty=@needqty-@qty
  365. END
  366. ELSE
  367. BEGIN
  368. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  369. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  370. ExtensionID,ProjectCode,cBatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,BatchCode)
  371. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  372. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  373. ExtensionID,ProjectCode,@batch, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,BatchCode from #maintemp
  374. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  375. SET @needqty=0
  376. END
  377. END
  378. END
  379. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  380. END
  381. CLOSE tempCursor
  382. DEALLOCATE tempCursor
  383. END
  384. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence,cBatchCode,BatchCode from #resulttemp
  385. --select * from #resulttemp
  386. DROP table #maintemp
  387. DROP table #resulttemp
  388. DROP table #barcodetemp";
  389. #endregion
  390. }
  391. else
  392. {
  393. #region sql(子件为原料)
  394. sql = @"SELECT DISTINCT a.MOCode as TransCode,a.Sequence,d.Sequence as TransSequence,d.invcode,a.WorkPoint,
  395. d.MODetailID as DetailID,e.BatchCode,{2} as Quantity
  396. FROM ICSMO a
  397. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  398. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  399. INNER JOIN ICSMOPick d ON a.MODetailID=d.MODetailID AND a.WorkPoint=d.WorkPoint
  400. INNER JOIN ICSExtension e ON c.ExtensionID=e.ID AND a.WorkPoint=e.WorkPoint
  401. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'";
  402. #endregion
  403. }
  404. sql = String.Format(sql, LotNo, WorkPoint, Quantity);
  405. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  406. string json = JsonConvert.SerializeObject(table);
  407. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  408. foreach (DownItemModel model in downItemModels)
  409. {
  410. WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, Quantity, User, WorkPoint, "30", model.InvCode, model.BatchCode, model.cBatchCode, BusinessCode, cmd, language);
  411. //回写已领数量
  412. //sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)" + model.Quantity + ") WHERE MODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  413. sql = @"UPDATE ICSMOPick SET IssueQuantity=case WHEN " + model.Quantity + "<>0 and " + model.Quantity + " is not NULL THEN ISNULL(IssueQuantity,0)+" + model.Quantity + " ELSE ISNULL(IssueQuantity,0) end WHERE MODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  414. sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
  415. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  416. {
  417. throw new Exception(language.GetNameByCode("回写已领数量失败"));
  418. }
  419. }
  420. }
  421. #endregion
  422. #region 委外入库,倒冲
  423. if (BusinessCode.Equals(TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>()))
  424. {
  425. #region sql
  426. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  427. SELECT
  428. c.OOCode AS TransCode,
  429. a.OODetailID AS DetailID,
  430. a.InvCode,
  431. b.InvName,
  432. b.InvStd,
  433. a.Quantity,
  434. a.Amount,
  435. a.Sequence AS TransSequence,
  436. a.IssueQuantity,
  437. c.Sequence,
  438. inv.InvUnit,
  439. 0 AS LocationQty,
  440. inv.AmountUnit,
  441. a.ExtensionID,
  442. a.WorkPoint,
  443. ext.ProjectCode,
  444. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  445. ext.Version,
  446. ext.Brand,
  447. ext.cFree1,
  448. ext.cFree2,
  449. ext.cFree3,
  450. ext.cFree4,
  451. ext.cFree5,
  452. ext.cFree6,
  453. ext.cFree7,
  454. ext.cFree8,
  455. ext.cFree9,
  456. ext.cFree10
  457. INTO #maintemp
  458. FROM
  459. ICSOOPick a
  460. inner join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  461. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  462. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  463. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  464. INNER JOIN (
  465. SELECT a.OOCode,a.Sequence,a.WorkPoint
  466. FROM ICSOutsourcingOrder a
  467. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.OOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  468. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  469. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  470. ) temp ON c.OOCode=temp.OOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  471. WHERE a.SupplyType='1'
  472. GROUP BY c.OOCode,a.Quantity,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,a.WorkPoint,inv.BatchEnable,a.OODetailID,a.Amount,a.Sequence,a.IssueQuantity,inv.InvName,inv.InvCode,inv.InvUnit,inv.AmountUnit,c.Sequence,
  473. ext.ProjectCode,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10;
  474. select * into #resulttemp from #maintemp
  475. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  476. delete from #resulttemp
  477. -- 2.maintemp barcodetemp
  478. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
  479. (select #maintemp.invcode from #maintemp group by #maintemp.InvCode) b on a.invcode = b.invcode where a.Quantity-a.lockQuantity>0 ORDER BY a.MTIME ASC
  480. -- 3.maintemp ID barcodetemp
  481. BEGIN
  482. DECLARE @transSequence int;--
  483. DECLARE @qty int;--
  484. DECLARE @needqty int;--
  485. DECLARE @lotno VARCHAR(50);--
  486. DECLARE @DetailID VARCHAR(50);--ID
  487. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  488. OPEN tempCursor; --
  489. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  490. WHILE @@fetch_status=0
  491. BEGIN
  492. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  493. PRINT @transSequence
  494. WHILE @needqty>0
  495. BEGIN
  496. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
  497. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  498. BEGIN
  499. IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
  500. BEGIN
  501. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  502. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  503. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  504. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  505. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  506. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  507. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  508. delete from #barcodetemp where lotno = @lotno
  509. SET @needqty=@needqty-@qty
  510. END
  511. ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
  512. BEGIN
  513. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  514. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  515. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  516. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  517. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  518. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  519. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  520. update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  521. SET @needqty=@needqty-@qty
  522. END
  523. ELSE
  524. BEGIN
  525. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  526. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  527. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  528. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  529. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
  530. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  531. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  532. SET @needqty=0
  533. END
  534. END
  535. END
  536. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  537. END
  538. CLOSE tempCursor
  539. DEALLOCATE tempCursor
  540. END
  541. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
  542. --select * from #resulttemp
  543. DROP table #maintemp
  544. DROP table #resulttemp
  545. DROP table #barcodetemp";
  546. #endregion
  547. sql = String.Format(sql, LotNo, WorkPoint);
  548. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  549. string json = JsonConvert.SerializeObject(table);
  550. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  551. foreach (DownItemModel model in downItemModels)
  552. {
  553. WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, Quantity, User, WorkPoint, "12", model.InvCode, model.BatchCode, model.BatchCode, BusinessCode, cmd, language);
  554. //回写已领数量
  555. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)" + model.Quantity + ") WHERE OODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  556. sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
  557. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  558. {
  559. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  560. }
  561. }
  562. }
  563. #endregion
  564. }
  565. catch (Exception)
  566. {
  567. throw;
  568. }
  569. }
  570. /// <summary>
  571. /// 减少库存
  572. /// </summary>
  573. /// <param name="Identification"></param>
  574. /// <param name="TransCode"></param>
  575. /// <param name="TransSequence"></param>
  576. /// <param name="LotNo"></param>
  577. /// <param name="Quantity"></param>
  578. /// <param name="User"></param>
  579. /// <param name="WorkPoint"></param>
  580. /// <param name="TransType"></param>
  581. /// <param name="BusinessCode"></param>
  582. /// <param name="cmd"></param>
  583. public static DataTable WareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity,string Qty, string User,
  584. string WorkPoint, string TransType, string InvCode, string BatchCode, string cBatchCode, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
  585. {
  586. String LotEnable = "";
  587. String PrintEnable = "";
  588. string lotstr = "";
  589. int result = 0;
  590. List<string> NewBarCodeList = new List<string>();
  591. DataTable dtLotno = new DataTable();
  592. DataTable lstDt = new DataTable();
  593. try
  594. {
  595. if (LotNo != null && LotNo != "")
  596. {
  597. ///更新库存
  598. string sql = "";
  599. if (TransType == "30")
  600. {
  601. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  602. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  603. BEGIN
  604. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  605. RETURN
  606. END";
  607. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  608. }
  609. else
  610. {
  611. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  612. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  613. BEGIN
  614. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  615. RETURN
  616. END";
  617. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  618. }
  619. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  620. {
  621. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  622. }
  623. //检验是否分批
  624. sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  625. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  626. where a.LotNo='{0}' and a.WorkPoint='{1}'
  627. ";
  628. sql = string.Format(sql, LotNo, WorkPoint);
  629. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  630. if (dt.Rows.Count == 0)
  631. {
  632. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  633. }
  634. else
  635. {
  636. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  637. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  638. }
  639. if (LotEnable.Equals("True"))
  640. {
  641. ///分批前添加日志
  642. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  643. BEGIN
  644. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  645. RETURN
  646. END
  647. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  648. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  649. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  650. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  651. MTIME,WorkPoint,EATTRIBUTE1)
  652. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  653. '','',c.WarehouseCode,c.LocationCode,c.Quantity+{6},
  654. '','0','{4}','31','0','',
  655. '','','',f.F_Account ,f.F_RealName ,
  656. SYSDATETIME() ,a.WorkPoint ,''
  657. FROM ICSInventoryLot a
  658. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  659. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  660. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  661. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  662. ";
  663. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity);
  664. log.Error("新增日志sql:" + sql);
  665. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  666. {
  667. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  668. }
  669. #region 获取分批后的条码(lotstr)
  670. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  671. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  672. sql = string.Format(sql, LotNo, WorkPoint);
  673. dt = DBHelper.SQlReturnData(sql, cmd);
  674. if (dt.Rows.Count == 0)
  675. {
  676. lotstr = LotNo + "-" + 1;
  677. }
  678. else
  679. {
  680. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  681. }
  682. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  683. #endregion
  684. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  685. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  686. Quantity,Amount,ExtensionID,Type,PrintTimes,
  687. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  688. WorkPoint,EATTRIBUTE1)
  689. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  690. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  691. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  692. a.WorkPoint ,'{1}'
  693. From ICSInventoryLot a
  694. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  695. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  696. cmd.CommandText = sql;
  697. result = cmd.ExecuteNonQuery();
  698. if (result <= 0)
  699. {
  700. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  701. }
  702. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  703. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'{2}',InDate,LockQuantity
  704. ,MUSER,MUSERName,GETDATE(),'{3}',''
  705. from ICSWareHouseLotInfo
  706. where LotNO='{1}' AND WorkPoint='{3}'";
  707. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  708. cmd.CommandText = sql;
  709. result = cmd.ExecuteNonQuery();
  710. if (result <= 0)
  711. {
  712. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  713. }
  714. //插入条码单据表
  715. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  716. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  717. FROM ICSInventoryLot a
  718. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  719. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  720. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  721. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  722. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  723. {
  724. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  725. }
  726. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  727. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  728. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  729. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  730. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  731. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  732. c.WarehouseCode,c.LocationCode,'','','{6}',
  733. '','0','{7}','105','0','',
  734. '','','',f.F_Account ,f.F_RealName ,
  735. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  736. FROM ICSInventoryLot a
  737. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  738. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  739. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  740. ";
  741. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  742. cmd.CommandText = sql;
  743. result = cmd.ExecuteNonQuery();
  744. if (result <= 0)
  745. {
  746. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  747. }
  748. if (PrintEnable.Equals("True"))
  749. {
  750. sql = @"select A.LotNO AS OLDLotNo , C.Quantity AS OLDLotQty, A.eattribute1 as LotNO, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
  751. from ICSWareHouseLotInfolog A
  752. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  753. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  754. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  755. where a.BusinessCode ='105'
  756. and A.lotno like'{0}%' and a.workpoint='{1}'
  757. ";
  758. sql = string.Format(sql, LotNo, WorkPoint);
  759. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  760. lstDt = dtLotno;
  761. }
  762. ///添加日志
  763. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  764. BEGIN
  765. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  766. RETURN
  767. END
  768. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  769. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  770. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  771. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  772. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  773. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  774. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  775. '','0','{7}','32','0','',
  776. '','','',f.F_Account ,f.F_RealName ,
  777. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  778. FROM ICSInventoryLot a
  779. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  780. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  781. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  782. ";
  783. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  784. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  785. {
  786. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  787. }
  788. #endregion
  789. }
  790. else
  791. {
  792. NewBarCodeList.Add(LotNo);
  793. ///添加日志
  794. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  795. BEGIN
  796. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  797. RETURN
  798. END
  799. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  800. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  801. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  802. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  803. MTIME,WorkPoint,EATTRIBUTE1,MergeID,EATTRIBUTE2,EATTRIBUTE4)
  804. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  805. c.WarehouseCode,c.LocationCode,'','','{6}',
  806. '','0','{7}','{8}','0','',
  807. '','','',f.F_Account ,f.F_RealName ,
  808. SYSDATETIME() ,a.WorkPoint ,'','{9}','{10}','{11}'
  809. FROM ICSInventoryLot a
  810. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  811. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  812. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  813. ";
  814. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, BatchCode, cBatchCode);
  815. log.Error("新增日志sql:" + sql);
  816. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  817. {
  818. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  819. }
  820. }
  821. }
  822. else
  823. {
  824. #region 添加wms没有库存的倒冲日志
  825. string sql1 = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  826. BEGIN
  827. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  828. RETURN
  829. END
  830. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  831. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  832. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  833. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  834. MTIME,WorkPoint,EATTRIBUTE1,MergeID,EATTRIBUTE2)
  835. SELECT NEWID(),'{3}','{4}','{5}','{0}' ,'{0}' ,
  836. '','','','','{6}',
  837. '','0','{7}','{8}','0','',
  838. '','','',f.F_Account ,f.F_RealName ,
  839. SYSDATETIME() ,'{1}' ,'','{9}','{10}'
  840. FROM Sys_SRM_User f
  841. WHERE f.F_Account='{2}' AND f.F_Location='{1}'
  842. ";
  843. sql1 = string.Format(sql1, InvCode, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, BatchCode);
  844. log.Error("新增日志sql:" + sql1);
  845. if (!DBHelper.ExecuteNonQuery(sql1, cmd))
  846. {
  847. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  848. }
  849. #endregion
  850. }
  851. }
  852. catch (Exception)
  853. {
  854. throw;
  855. }
  856. return lstDt;
  857. }
  858. /// <summary>
  859. /// 修改库存
  860. /// </summary>
  861. /// <param name="Identification"></param>
  862. /// <param name="TransCode"></param>
  863. /// <param name="TransSequence"></param>
  864. /// <param name="LotNo"></param>
  865. /// <param name="Quantity"></param>
  866. /// <param name="User"></param>
  867. /// <param name="WorkPoint"></param>
  868. /// <param name="TransType"></param>
  869. /// <param name="cmd"></param>
  870. public static void WareHouseLotInfoUpdate(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  871. string WorkPoint, string TransType, SqlCommand cmd, Dictionary<string, string> language)
  872. {
  873. try
  874. {
  875. ///添加日志
  876. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  877. BEGIN
  878. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  879. RETURN
  880. END
  881. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  882. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  883. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  884. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  885. MTIME,WorkPoint,EATTRIBUTE1)
  886. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  887. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  888. '','0','{6}','{7}','0','',
  889. '','','',f.F_Account ,f.F_RealName ,
  890. SYSDATETIME() ,a.WorkPoint ,''
  891. FROM ICSWareHouseLotInfo a
  892. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  893. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  894. ";
  895. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckBefore.GetDescription<DBValue>());
  896. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  897. {
  898. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  899. }
  900. ///更新库存
  901. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity='{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'";
  902. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  903. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  904. {
  905. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  906. }
  907. ///添加日志
  908. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  909. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  910. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  911. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  912. MTIME,WorkPoint,EATTRIBUTE1)
  913. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  914. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  915. '','0','{6}','{7}','0','',
  916. '','','',f.F_Account ,f.F_RealName ,
  917. SYSDATETIME() ,a.WorkPoint ,''
  918. FROM ICSWareHouseLotInfo a
  919. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  920. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  921. ";
  922. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckAfter.GetDescription<DBValue>());
  923. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  924. {
  925. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  926. }
  927. }
  928. catch (Exception)
  929. {
  930. throw;
  931. }
  932. }
  933. /// <summary>
  934. /// 调拨
  935. /// </summary>
  936. /// <param name="LocationCode"></param>
  937. /// <param name="LotNo"></param>
  938. /// <param name="Quantity"></param>
  939. /// <param name="User"></param>
  940. /// <param name="WorkPoint"></param>
  941. /// <param name="TransType"></param>
  942. /// <param name="BusinessCode"></param>
  943. /// <param name="cmd"></param>
  944. public static DataTable WareHouseLotInfoTransfer(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  945. string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID)
  946. {
  947. String LotEnable = "";
  948. String PrintEnable = "";
  949. string lotstr = "";
  950. int result = 0;
  951. DataTable dtLotno = new DataTable();
  952. DataTable lstDt = new DataTable();
  953. List<string> NewBarCodeList = new List<string>();
  954. try
  955. {
  956. ///分批前添加日志
  957. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  958. BEGIN
  959. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  960. RETURN
  961. END
  962. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  963. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  964. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  965. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  966. MTIME,WorkPoint,EATTRIBUTE1)
  967. SELECT NEWID(),'{3}','{8}','{9}',a.LotNo ,a.InvCode ,
  968. c.WarehouseCode,c.LocationCode,'{6}','{7}',c.Quantity,
  969. '','0','{4}','31','0','',
  970. '','','',f.F_Account ,f.F_RealName ,
  971. SYSDATETIME() ,a.WorkPoint ,''
  972. FROM ICSInventoryLot a
  973. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  974. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  975. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  976. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  977. ";
  978. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, WarehouseCode, LocationCode, TransCode, TransSequence);
  979. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  980. {
  981. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  982. }
  983. //检验是否分批
  984. sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  985. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  986. where a.LotNo='{0}' and a.WorkPoint='{1}'
  987. ";
  988. sql = string.Format(sql, LotNo, WorkPoint);
  989. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  990. if (dt.Rows.Count == 0)
  991. {
  992. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  993. }
  994. else
  995. {
  996. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  997. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  998. }
  999. if (!LotEnable.Equals("False"))
  1000. {
  1001. #region 获取分批后的条码(lotstr)
  1002. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  1003. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  1004. sql = string.Format(sql, LotNo, WorkPoint);
  1005. dt = DBHelper.SQlReturnData(sql, cmd);
  1006. if (dt.Rows.Count == 0)
  1007. {
  1008. lotstr = LotNo + "-" + 1;
  1009. }
  1010. else
  1011. {
  1012. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  1013. }
  1014. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  1015. #endregion
  1016. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  1017. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  1018. Quantity,Amount,ExtensionID,Type,PrintTimes,
  1019. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  1020. WorkPoint,EATTRIBUTE1)
  1021. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  1022. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  1023. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  1024. a.WorkPoint ,'{1}'
  1025. From ICSInventoryLot a
  1026. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  1027. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  1028. cmd.CommandText = sql;
  1029. result = cmd.ExecuteNonQuery();
  1030. if (result <= 0)
  1031. {
  1032. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  1033. }
  1034. #endregion
  1035. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1036. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'{2}',InDate,LockQuantity
  1037. ,MUSER,MUSERName,GETDATE(),'{3}',''
  1038. from ICSWareHouseLotInfo
  1039. where LotNO='{1}' AND WorkPoint='{3}'";
  1040. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  1041. cmd.CommandText = sql;
  1042. result = cmd.ExecuteNonQuery();
  1043. if (result <= 0)
  1044. {
  1045. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  1046. }
  1047. //插入条码单据表
  1048. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1049. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1050. FROM ICSInventoryLot a
  1051. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1052. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1053. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1054. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  1055. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1056. {
  1057. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1058. }
  1059. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1060. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1061. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1062. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1063. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1064. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  1065. c.WarehouseCode,c.LocationCode,'','','{6}',
  1066. '','0','{7}','105','0','',
  1067. '','','',f.F_Account ,f.F_RealName ,
  1068. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1069. FROM ICSInventoryLot a
  1070. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1071. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1072. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1073. ";
  1074. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  1075. cmd.CommandText = sql;
  1076. result = cmd.ExecuteNonQuery();
  1077. if (result <= 0)
  1078. {
  1079. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  1080. }
  1081. ///添加日志
  1082. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1083. BEGIN
  1084. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1085. RETURN
  1086. END
  1087. IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{9}' AND LocationCode='{10}' AND WorkPoint='{1}' AND LotNo = '{0}')
  1088. BEGIN
  1089. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
  1090. RETURN
  1091. END
  1092. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1093. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1094. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1095. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1096. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1097. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  1098. c.WarehouseCode,c.LocationCode,'{9}','{10}',{6},
  1099. '','0','{7}','32','0','',
  1100. '','','',f.F_Account ,f.F_RealName ,
  1101. SYSDATETIME() ,a.WorkPoint ,'','{11}'
  1102. FROM ICSInventoryLot a
  1103. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1104. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1105. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1106. ";
  1107. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
  1108. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1109. {
  1110. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1111. }
  1112. if (PrintEnable.Equals("True"))
  1113. {
  1114. sql = @"select A.LotNO AS OLDLotNo , C.Quantity AS OLDLotQty, A.eattribute1 as LotNO, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
  1115. from ICSWareHouseLotInfolog A
  1116. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  1117. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  1118. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  1119. where a.BusinessCode ='105'
  1120. and A.lotno like'{0}%' and a.workpoint='{1}'
  1121. ";
  1122. sql = string.Format(sql, LotNo, WorkPoint);
  1123. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  1124. lstDt = dtLotno;
  1125. }
  1126. }
  1127. else
  1128. {
  1129. ///添加日志
  1130. // sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1131. // BEGIN
  1132. // RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1133. // RETURN
  1134. // END
  1135. //
  1136. // IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{9}' AND LocationCode='{10}' AND WorkPoint='{1}' AND LotNo = '{0}')
  1137. // BEGIN
  1138. // RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
  1139. // RETURN
  1140. // END
  1141. //
  1142. // INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1143. // FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1144. // Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1145. // ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1146. // MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1147. // SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  1148. // c.WarehouseCode,c.LocationCode,'{9}','{10}',{6},
  1149. // '','0','{7}','{8}','0','',
  1150. // '','','',f.F_Account ,f.F_RealName ,
  1151. // SYSDATETIME() ,a.WorkPoint ,'','{11}'
  1152. // FROM ICSInventoryLot a
  1153. // INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1154. // INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1155. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1156. // ";
  1157. // sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
  1158. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1159. // {
  1160. // throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1161. // }
  1162. }
  1163. ///添加库存
  1164. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
  1165. BEGIN
  1166. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  1167. RETURN
  1168. END
  1169. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}' AND a.Quantity<{4})
  1170. BEGIN
  1171. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1172. RETURN
  1173. END
  1174. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1175. ";
  1176. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
  1177. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1178. {
  1179. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  1180. }
  1181. }
  1182. catch (Exception)
  1183. {
  1184. throw;
  1185. }
  1186. return lstDt;
  1187. }
  1188. /// <summary>
  1189. /// 移库
  1190. /// </summary>
  1191. /// <param name="LocationCode"></param>
  1192. /// <param name="LotNo"></param>
  1193. /// <param name="Quantity"></param>
  1194. /// <param name="User"></param>
  1195. /// <param name="WorkPoint"></param>
  1196. /// <param name="TransType"></param>
  1197. /// <param name="BusinessCode"></param>
  1198. /// <param name="cmd"></param>
  1199. public static void WareHouseLotInfoLibrary(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  1200. string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1201. {
  1202. try
  1203. {
  1204. ///添加日志
  1205. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1206. BEGIN
  1207. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1208. RETURN
  1209. END
  1210. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1211. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1212. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1213. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1214. MTIME,WorkPoint,EATTRIBUTE1)
  1215. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1216. c.WarehouseCode,c.LocationCode,'{8}','{9}',c.Quantity,
  1217. '','0','{6}','{7}','0','',
  1218. '','','',f.F_Account ,f.F_RealName ,
  1219. SYSDATETIME() ,a.WorkPoint ,''
  1220. FROM ICSInventoryLot a
  1221. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1222. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1223. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1224. ";
  1225. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, BusinessCode, WarehouseCode, LocationCode);
  1226. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1227. {
  1228. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1229. }
  1230. ///添加库存
  1231. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
  1232. BEGIN
  1233. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  1234. RETURN
  1235. END
  1236. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1237. ";
  1238. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  1239. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1240. {
  1241. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  1242. }
  1243. }
  1244. catch (Exception)
  1245. {
  1246. throw;
  1247. }
  1248. }
  1249. /// <summary>
  1250. /// 两步调入
  1251. /// </summary>
  1252. /// <param name="LocationCode"></param>
  1253. /// <param name="LotNo"></param>
  1254. /// <param name="Quantity"></param>
  1255. /// <param name="User"></param>
  1256. /// <param name="WorkPoint"></param>
  1257. /// <param name="TransType"></param>
  1258. /// <param name="BusinessCode"></param>
  1259. /// <param name="cmd"></param>
  1260. public static void WareHouseLotInfoTwoStepTransferDocIn(string Identification, string TransCode, string TransSequence, string WarehouseCode,
  1261. string LocationCode, string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1262. {
  1263. try
  1264. {
  1265. ///添加日志
  1266. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1267. BEGIN
  1268. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1269. RETURN
  1270. END
  1271. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1272. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1273. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1274. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1275. MTIME,WorkPoint,EATTRIBUTE1)
  1276. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1277. c.WarehouseCode,c.LocationCode,'{9}','{10}','{6}',
  1278. '','0','{7}','{8}','0','',
  1279. '','','',f.F_Account ,f.F_RealName ,
  1280. SYSDATETIME() ,a.WorkPoint ,''
  1281. FROM ICSInventoryLot a
  1282. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1283. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1284. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1285. ";
  1286. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode);
  1287. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1288. {
  1289. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1290. }
  1291. ///添加库存
  1292. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1293. BEGIN
  1294. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  1295. RETURN
  1296. END
  1297. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}',Quantity='{4}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1298. ";
  1299. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
  1300. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1301. {
  1302. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  1303. }
  1304. }
  1305. catch (Exception)
  1306. {
  1307. throw;
  1308. }
  1309. }
  1310. /// <summary>
  1311. /// 拆分、合并日志
  1312. /// </summary>
  1313. /// <param name="Identification"></param>
  1314. /// <param name="LotNo"></param>
  1315. /// <param name="User"></param>
  1316. /// <param name="WorkPoint"></param>
  1317. /// <param name="TransType"></param>
  1318. /// <param name="BusinessCode"></param>
  1319. /// <param name="cmd"></param>
  1320. public static void WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1321. {
  1322. try
  1323. {
  1324. ///添加日志
  1325. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1326. BEGIN
  1327. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1328. RETURN
  1329. END
  1330. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1331. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1332. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1333. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1334. MTIME,WorkPoint,EATTRIBUTE1)
  1335. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1336. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1337. '','0','{4}','{5}','0','',
  1338. '','','',f.F_Account ,f.F_RealName ,
  1339. SYSDATETIME() ,a.WorkPoint ,''
  1340. FROM ICSInventoryLot a
  1341. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1342. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1343. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1344. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1345. ";
  1346. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1347. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1348. {
  1349. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1350. }
  1351. }
  1352. catch (Exception)
  1353. {
  1354. throw;
  1355. }
  1356. }
  1357. /// <summary>
  1358. /// 合并
  1359. /// </summary>
  1360. /// <param name="Identification"></param>
  1361. /// <param name="LotNo"></param>
  1362. /// <param name="User"></param>
  1363. /// <param name="WorkPoint"></param>
  1364. /// <param name="TransType"></param>
  1365. /// <param name="BusinessCode"></param>
  1366. /// <param name="cmd"></param>
  1367. public static void WareHouseLotInfoMerge(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1368. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1369. {
  1370. try
  1371. {
  1372. ///更新目标条码库存
  1373. string sql = @"IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1374. INNER JOIN ICSInventoryLot b ON b.LotNo='{3}' AND a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1375. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1376. BEGIN
  1377. RAISERROR('" + language.GetNameByCode("WMSAPIInfo170") + @"',16,1);
  1378. RETURN
  1379. END
  1380. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1381. BEGIN
  1382. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  1383. RETURN
  1384. END
  1385. IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1386. INNER JOIN ICSExtension b ON a.ExtensionID=b.ID AND a.WorkPoint=b.WorkPoint
  1387. INNER JOIN (SELECT a.LotNo,b.BatchCode,a.WorkPoint from ICSInventoryLot a
  1388. INNER JOIN ICSExtension b on a.ExtensionID=b.ID AND a.WorkPoint=b.WorkPoint where a.LotNo='{3}' ) c ON b.BatchCode=c.BatchCode and a.WorkPoint=c.WorkPoint
  1389. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1390. BEGIN
  1391. RAISERROR('" + language.GetNameByCode("WMSAPIInfo199") + @"',16,1);
  1392. RETURN
  1393. END
  1394. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a
  1395. INNER JOIN ICSWareHouseLotInfo b ON b.LotNo='{3}' AND a.LocationCode=b.LocationCode AND a.WorkPoint=b.WorkPoint
  1396. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1397. BEGIN
  1398. RAISERROR('" + language.GetNameByCode("WMSAPIInfo200") + @"',16,1);
  1399. RETURN
  1400. END
  1401. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1402. ";
  1403. sql = string.Format(sql, LotNo, WorkPoint, Quantity, CurrentLotNo);
  1404. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1405. {
  1406. throw new Exception(language.GetNameByCode("WMSAPIInfo169"));//"目标条码库存更新失败!");
  1407. }
  1408. ///更新原条码库存
  1409. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1410. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1411. BEGIN
  1412. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1413. RETURN
  1414. END";
  1415. sql = string.Format(sql, CurrentLotNo, WorkPoint, Quantity);
  1416. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1417. {
  1418. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1419. }
  1420. ///添加日志
  1421. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1422. BEGIN
  1423. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1424. RETURN
  1425. END
  1426. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1427. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1428. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1429. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1430. MTIME,WorkPoint,EATTRIBUTE1)
  1431. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1432. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1433. '','0','{4}','{5}','0','',
  1434. '','','',f.F_Account ,f.F_RealName ,
  1435. SYSDATETIME() ,a.WorkPoint ,''
  1436. FROM ICSInventoryLot a
  1437. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1438. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1439. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1440. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1441. ";
  1442. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1443. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1444. {
  1445. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1446. }
  1447. }
  1448. catch (Exception ex)
  1449. {
  1450. throw ex;
  1451. }
  1452. }
  1453. /// <summary>
  1454. /// 拆分
  1455. /// </summary>
  1456. /// <param name="Identification"></param>
  1457. /// <param name="LotNo"></param>
  1458. /// <param name="User"></param>
  1459. /// <param name="WorkPoint"></param>
  1460. /// <param name="TransType"></param>
  1461. /// <param name="BusinessCode"></param>
  1462. /// <param name="cmd"></param>
  1463. public static void WareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1464. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1465. {
  1466. try
  1467. {
  1468. ///更新库存
  1469. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1470. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1471. BEGIN
  1472. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1473. RETURN
  1474. END";
  1475. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1476. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1477. {
  1478. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1479. }
  1480. #region 添加库存
  1481. //插入条码表
  1482. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1483. BEGIN
  1484. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1485. RETURN
  1486. END
  1487. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
  1488. BEGIN
  1489. RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
  1490. RETURN
  1491. END
  1492. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1493. SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
  1494. FROM ICSInventoryLot a
  1495. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1496. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1497. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
  1498. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1499. {
  1500. throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
  1501. }
  1502. //插入条码单据表
  1503. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1504. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1505. FROM ICSInventoryLot a
  1506. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1507. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1508. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1509. sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
  1510. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1511. {
  1512. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1513. }
  1514. ///添加库存
  1515. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1516. BEGIN
  1517. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  1518. RETURN
  1519. END
  1520. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1521. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1522. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1523. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1524. BEGIN
  1525. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1526. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1527. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint AND il.LocationCode=d.LocationCode
  1528. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1529. BEGIN
  1530. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  1531. RETURN
  1532. END
  1533. END
  1534. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1535. SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  1536. FROM ICSInventoryLot a
  1537. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1538. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1539. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1540. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1541. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
  1542. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1543. {
  1544. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  1545. }
  1546. ///添加日志
  1547. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1548. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1549. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1550. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1551. MTIME,WorkPoint,EATTRIBUTE1)
  1552. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1553. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1554. '','0','{4}','{5}','0','',
  1555. '','','',f.F_Account ,f.F_RealName ,
  1556. SYSDATETIME() ,a.WorkPoint ,''
  1557. FROM ICSInventoryLot a
  1558. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1559. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1560. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1561. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1562. ";
  1563. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1564. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1565. {
  1566. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1567. }
  1568. #endregion
  1569. }
  1570. catch (Exception)
  1571. {
  1572. throw;
  1573. }
  1574. }
  1575. /// <summary>
  1576. /// 回写ERP ID
  1577. /// </summary>
  1578. /// <param name="TransType"></param>
  1579. /// <param name="SourceDetailID"></param>
  1580. /// <param name="Identification"></param>
  1581. /// <param name="ID"></param>
  1582. /// <param name="DetailID"></param>
  1583. /// <param name="Code"></param>
  1584. /// <param name="Sequence"></param>
  1585. /// <param name="cmd"></param>
  1586. public static void WareHouseLotInfoLogUpdate(string TransType, string SourceDetailID, string Identification, string ID, string DetailID, string Code, string Sequence, SqlCommand cmd, Dictionary<string, string> language)
  1587. {
  1588. string ERPupdate = string.Empty;
  1589. try
  1590. {
  1591. //采购入库
  1592. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1593. {
  1594. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1595. FROM ICSWareHouseLotInfoLog a
  1596. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1597. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1598. WHERE c.PODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1599. ";
  1600. }
  1601. //审核的到货单
  1602. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1603. {
  1604. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1605. FROM ICSWareHouseLotInfoLog a
  1606. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1607. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1608. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1609. ";
  1610. }
  1611. //采购拒收
  1612. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1613. {
  1614. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1615. FROM ICSWareHouseLotInfoLog a
  1616. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1617. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1618. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1619. ";
  1620. }
  1621. //审核的委外到货单
  1622. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1623. {
  1624. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1625. FROM ICSWareHouseLotInfoLog a
  1626. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1627. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1628. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1629. ";
  1630. }
  1631. //委外拒收
  1632. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1633. {
  1634. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1635. FROM ICSWareHouseLotInfoLog a
  1636. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1637. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1638. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1639. ";
  1640. }
  1641. //采购退货
  1642. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  1643. {
  1644. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1645. FROM ICSWareHouseLotInfoLog a
  1646. INNER JOIN ICSDeliveryNotice c ON a.TransCode=c.DNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1647. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1648. ";
  1649. }
  1650. //委外发料
  1651. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  1652. {
  1653. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1654. FROM ICSWareHouseLotInfoLog a
  1655. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  1656. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  1657. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1658. ";
  1659. }
  1660. //委外退料
  1661. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1662. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1663. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1664. {
  1665. ERPupdate = @"--根据退料单退料
  1666. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1667. FROM ICSWareHouseLotInfoLog a
  1668. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1669. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1670. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  1671. Left JOIN ICSOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1672. WHERE ISNULL(m.ApplyDetailID,ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1673. --退-
  1674. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1675. FROM ICSWareHouseLotInfoLog a
  1676. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1677. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  1678. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1679. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1680. --退-
  1681. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1682. FROM ICSWareHouseLotInfoLog a
  1683. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1684. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1685. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1686. --退-
  1687. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1688. FROM ICSWareHouseLotInfoLog a
  1689. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1690. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1691. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1692. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  1693. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1694. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1695. ";
  1696. }
  1697. //委外入库
  1698. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1699. {
  1700. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1701. FROM ICSWareHouseLotInfoLog a
  1702. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1703. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1704. WHERE c.OODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1705. ";
  1706. }
  1707. //委外退货
  1708. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  1709. {
  1710. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1711. FROM ICSWareHouseLotInfoLog a
  1712. INNER JOIN ICSODeliveryNotice c ON a.TransCode=c.ODNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1713. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.ODNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1714. ";
  1715. }
  1716. //生产发料
  1717. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  1718. {
  1719. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1720. FROM ICSWareHouseLotInfoLog a
  1721. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  1722. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  1723. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1724. ";
  1725. }
  1726. //生产退料
  1727. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1728. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1729. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1730. {
  1731. ERPupdate = @"--根据退料单退料
  1732. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1733. FROM ICSWareHouseLotInfoLog a
  1734. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1735. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1736. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  1737. left JOIN ICSMOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1738. WHERE ISNULL(m.ApplyDetailID, ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1739. --退-
  1740. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1741. FROM ICSWareHouseLotInfoLog a
  1742. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1743. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  1744. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1745. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1746. --退-
  1747. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1748. FROM ICSWareHouseLotInfoLog a
  1749. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1750. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1751. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1752. --退-
  1753. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1754. FROM ICSWareHouseLotInfoLog a
  1755. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1756. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1757. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1758. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1759. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1760. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1761. ";
  1762. }
  1763. //生产入库
  1764. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1765. {
  1766. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1767. FROM ICSWareHouseLotInfoLog a
  1768. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1769. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1770. WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1771. ";
  1772. }
  1773. //开立的生产入库单
  1774. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1775. {
  1776. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1777. FROM ICSWareHouseLotInfoLog a
  1778. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1779. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1780. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1781. ";
  1782. }
  1783. //销售出库
  1784. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  1785. {
  1786. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1787. FROM ICSWareHouseLotInfoLog a
  1788. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1789. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1790. ";
  1791. }
  1792. //销售退货
  1793. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1794. {
  1795. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1796. FROM ICSWareHouseLotInfoLog a
  1797. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1798. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1799. ";
  1800. }
  1801. //返工工单
  1802. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1803. {
  1804. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1805. FROM ICSWareHouseLotInfoLog a
  1806. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1807. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1808. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1809. WHERE d.PickID='{3}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1810. ";
  1811. }
  1812. //一步调拨
  1813. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1814. {
  1815. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1816. FROM ICSWareHouseLotInfoLog a
  1817. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1818. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1819. ";
  1820. }
  1821. //调拨
  1822. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1823. {
  1824. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1825. FROM ICSWareHouseLotInfoLog a
  1826. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1827. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1828. ";
  1829. }
  1830. //两步调出
  1831. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  1832. {
  1833. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1834. FROM ICSWareHouseLotInfoLog a
  1835. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1836. INNER JOIN ICSTransfer d ON c.TransferDetailID=d.TransferDetailID AND c.WorkPoint=d.WorkPoint
  1837. WHERE c.OutID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1838. ";
  1839. }
  1840. //两步调入
  1841. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1842. {
  1843. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1844. FROM ICSWareHouseLotInfoLog a
  1845. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1846. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  1847. WHERE b.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1848. ";
  1849. }
  1850. //销售退货-原条码
  1851. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1852. {
  1853. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1854. FROM ICSWareHouseLotInfoLog a
  1855. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1856. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1857. ";
  1858. }
  1859. //其他出库
  1860. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  1861. {
  1862. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1863. FROM ICSWareHouseLotInfoLog a
  1864. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1865. WHERE c.OutID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1866. ";
  1867. }
  1868. //其他入库
  1869. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1870. {
  1871. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1872. FROM ICSWareHouseLotInfoLog a
  1873. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1874. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1875. WHERE c.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1876. ";
  1877. }
  1878. //拆卸单
  1879. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1880. {
  1881. ERPupdate = @"UPDATE d set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1882. FROM ICSWareHouseLotInfoLog a
  1883. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1884. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1885. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  1886. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND d.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1887. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1888. FROM ICSWareHouseLotInfoLog a
  1889. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1890. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1891. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DABDOCType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1892. ";
  1893. }
  1894. //领料申请单
  1895. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  1896. {
  1897. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1898. FROM ICSWareHouseLotInfoLog a
  1899. INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1900. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1901. ";
  1902. }
  1903. //委外领料申请单
  1904. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  1905. {
  1906. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1907. FROM ICSWareHouseLotInfoLog a
  1908. INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1909. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1910. ";
  1911. }
  1912. //开立材料出库
  1913. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  1914. {
  1915. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1916. FROM ICSWareHouseLotInfoLog a
  1917. INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1918. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1919. ";
  1920. }
  1921. //开立委外材料出库
  1922. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  1923. {
  1924. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1925. FROM ICSWareHouseLotInfoLog a
  1926. INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1927. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1928. ";
  1929. }
  1930. //开立红字入库单
  1931. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  1932. {
  1933. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1934. FROM ICSWareHouseLotInfoLog a
  1935. INNER JOIN ICSPurchaseReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1936. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1937. ";
  1938. }
  1939. //开立委外红字入库单
  1940. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  1941. {
  1942. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1943. FROM ICSWareHouseLotInfoLog a
  1944. INNER JOIN ICSOutsourcingReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1945. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1946. ";
  1947. }
  1948. //借用
  1949. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  1950. {
  1951. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1952. FROM ICSWareHouseLotInfoLog a
  1953. INNER JOIN ICSBrrow c ON a.TransCode=c.BrrowCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1954. WHERE c.BrrowDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1955. ";
  1956. }
  1957. //归还
  1958. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1959. {
  1960. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1961. FROM ICSWareHouseLotInfoLog a
  1962. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1963. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1964. WHERE c.ReturnDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1965. ";
  1966. }
  1967. ERPupdate = string.Format(ERPupdate, SourceDetailID, Identification, ID, DetailID, Code, Sequence);
  1968. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1969. {
  1970. throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  1971. }
  1972. }
  1973. catch (Exception ex)
  1974. {
  1975. log.Debug(ex.ToString());
  1976. log.Debug(TransType + Environment.NewLine + ERPupdate);
  1977. }
  1978. }
  1979. }
  1980. }