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

454 lines
27 KiB

3 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.Text;
  10. using System.Threading.Tasks;
  11. namespace ICSSoft.DataProject
  12. {
  13. public class CreateRdRecord01Red
  14. {
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  17. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  18. /// <summary>
  19. /// 获取采购入库单
  20. /// </summary>
  21. /// <param name="infos">传入参数</param>
  22. /// <returns></returns>
  23. public string Get(List<ICSRdRecord01> infos)
  24. {
  25. List<ICSRdRecord01> szJson = new List<ICSRdRecord01>();
  26. DataTable dt = null;
  27. string json = "";
  28. if (infos.Count <= 0)
  29. {
  30. throw new Exception("传送数据为空!");
  31. }
  32. string res = string.Empty;
  33. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  34. conn.Open();
  35. SqlTransaction sqlTran = conn.BeginTransaction();
  36. SqlCommand cmd = new SqlCommand();
  37. cmd.Transaction = sqlTran;
  38. cmd.Connection = conn;
  39. try
  40. {
  41. string sql = string.Empty;
  42. foreach (ICSRdRecord01 info in infos)
  43. {
  44. if (info.MTime < new DateTime(2000, 01, 01))
  45. throw new Exception("请输入正确的操作时间:" + info.MTime);
  46. sql = @"select top 10 a.ID,cCode,cVenCode,''as cVenName,cWhCode,''as cWhName,cARVCode,cMaker,dnmaketime,cHandler,dVeriDate,
  47. AutoID,irowno,cInvCode,iQuantity,iNum,iUnitCost,iArrsId
  48. FROM [{1}].DBO.RdRecord01 a
  49. LEFT JOIN [{1}].DBO.rdrecords01 b on a.ID=b.ID
  50. INNER JOIN [{1}].DBO.DEPARTMENT C ON A.CDEPCODE=C.CDEPCODE
  51. INNER JOIN [{1}].DBO.VENDOR D ON A.CVENCODE=D.CVENCODE WHERE 1=1";
  52. if (!string.IsNullOrWhiteSpace(info.RCVTCode))
  53. {
  54. sql += " and a.cCode='{0}'";
  55. }
  56. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  57. {
  58. sql += " and ISNULL(b.cbCloseTime,ISNULL(a.cChangAuditTime,ISNULL(a.cAuditTime, ISNULL(a.cModifyTime, a.cmaketime))))>='{2}'";
  59. }
  60. if (!string.IsNullOrWhiteSpace(info.User))
  61. {
  62. sql += "and a.CMAKER='{3}'";
  63. }
  64. sql = string.Format(sql, info.RCVTCode, ERPDB, info.MTime, info.User);
  65. dt = DBHelper.SQlReturnData(sql, cmd);
  66. json = JsonConvert.SerializeObject(dt);
  67. }
  68. cmd.Transaction.Commit();
  69. return json;
  70. }
  71. catch (Exception ex)
  72. {
  73. cmd.Transaction.Rollback();
  74. log.Error(ex.Message);
  75. throw new Exception(ex.Message);
  76. }
  77. finally
  78. {
  79. if (conn.State == ConnectionState.Open)
  80. {
  81. conn.Close();
  82. }
  83. conn.Dispose();
  84. }
  85. }
  86. ///<summary>
  87. //创建采购入库单
  88. ///</summary>
  89. ///<param name="Bills"></param>
  90. ///<returns></returns>
  91. public List<ICSRdRecord01> CreateRdRecord01(List<ICSRdRecord01> Bills)
  92. {
  93. List<ICSRdRecord01> szJson = new List<ICSRdRecord01>();
  94. DataTable dt = null;
  95. decimal iTaxRate = 0;
  96. Dictionary<string, int> dic = DBHelper.GetAllCode("", "", "");
  97. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  98. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  99. DateTime dates = DateTime.Now;
  100. string iBaseCodeLen = DBHelper.GetAllRDCode("", "", 1, "");
  101. VouchKey key = new VouchKey();
  102. string json = "";
  103. if (Bills.Count <= 0)
  104. {
  105. throw new Exception("传送数据为空!");
  106. }
  107. string res = string.Empty;
  108. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  109. conn.Open();
  110. SqlTransaction sqlTran = conn.BeginTransaction();
  111. SqlCommand cmd = new SqlCommand();
  112. cmd.Transaction = sqlTran;
  113. cmd.Connection = conn;
  114. foreach (ICSRdRecord01 head in Bills)
  115. {
  116. if (head.MTime < new DateTime(2000, 01, 01))
  117. throw new Exception("请输入正确的操作时间:" + head.MTime);
  118. string sql = "";
  119. #region 验证入库数量不能大于采购订单数量
  120. foreach (ICSRdRecord01s body in head.Record01s)
  121. {
  122. sql = @"SELECT a.iQuantity,a.ID,isnull(a.iReceivedQTY,0) as iReceivedQTY,isnull(a.freceivedqty,0) as freceivedqty,ISNULL(c.fInExcess,0) AS fInExcess
  123. FROM dbo.PO_Podetails a
  124. INNER JOIN dbo.PO_Pomain b ON a.POID=b.POID
  125. LEFT JOIN dbo.Inventory c ON a.cInvCode=c.cInvCode
  126. where a.ID='" + head.ID + "'";
  127. cmd.CommandText = sql;
  128. DataTable dtQty = DBHelper.SQlReturnData(sql, cmd);
  129. if (dtQty != null && dtQty.Rows.Count > 0)
  130. {
  131. decimal fInExcess = decimal.Parse(dtQty.Rows[0]["fInExcess"].ToString());//入库超额上限
  132. decimal PoQty = decimal.Parse(dtQty.Rows[0]["iQuantity"].ToString());
  133. decimal iReceicedQty = decimal.Parse(dtQty.Rows[0]["iReceivedQTY"].ToString());//累计到货数量
  134. decimal freceivedqty = decimal.Parse(dtQty.Rows[0]["freceivedqty"].ToString());//合格品入库数量
  135. PoQty = PoQty * (1 + fInExcess);
  136. log.Info("PO数量:" + PoQty.ToString() + "入库超额上限:" + fInExcess.ToString() + ",累计到货数量:" + iReceicedQty.ToString() + ",合格品入库数量:" + freceivedqty.ToString());
  137. //2021-11-05 回写字段变更,见行408
  138. //decimal to = PoQty - iReceicedQty - freceivedqty;
  139. decimal to = PoQty - freceivedqty;
  140. if (body.Quantity > to)
  141. {
  142. throw new Exception("入库数量" + body.Quantity.ToString("f3") + "大于采购订单可入库数量" + to.ToString("f3")
  143. );
  144. }
  145. }
  146. }
  147. #endregion
  148. #region 采购入库单表头
  149. string BusType = "";//业务类型
  150. sql = @"select a.POID,a.cPOID,a.cVenCode,a.cDepCode,a.cexch_name,a.iTaxRate,a.cMaker,
  151. a.nflat,a.cPersonCode,a.cptcode ,b.ID,b.cCode,a.cBusType
  152. FROM dbo.PO_Pomain a
  153. LEFT JOIN PU_ArrivalVouch b ON a.cPOID=b.cpocode
  154. WHERE a.POID ='" + head.ID + "'";
  155. cmd.CommandText = sql;
  156. DataTable dtPOMain = DBHelper.SQlReturnData(sql, cmd);
  157. if (dtPOMain != null && dtPOMain.Rows.Count > 0)
  158. {
  159. string cSource = "";
  160. string cCode = "";
  161. int bredvouch = 0;
  162. string cRdCode = "";
  163. string WHCode = "";
  164. BusType = dtPOMain.Rows[0]["cBusType"].ToString();
  165. //校验采购订单类型是固定资产仓库
  166. if (BusType.Equals("固定资产"))
  167. {
  168. string sqlwh = @"SELECT bWhAsset FROM Warehouse WHERE cWhCode='" + head.WHCode + "'";
  169. cmd.CommandText = sqlwh;
  170. DataTable dtwhcode = DBHelper.SQlReturnData(sqlwh, cmd);
  171. log.Info(dtwhcode.Rows[0]["bWhAsset"].ToString());
  172. if (!dtwhcode.Rows[0]["bWhAsset"].ToString().Equals("True"))
  173. {
  174. throw new Exception("采购订单:" + dtPOMain.Rows[0]["cPOID"].ToString() + ",业务类型:固定资产,只能入固定资产仓库!");
  175. }
  176. else
  177. {
  178. WHCode = head.WHCode;
  179. }
  180. }
  181. else
  182. {
  183. WHCode = head.WHCode;
  184. }
  185. cSource = "采购退货单";
  186. cCode = dtPOMain.Rows[0]["cCode"].ToString();
  187. bredvouch = 1;
  188. cRdCode = "205";
  189. sql = @"
  190. INSERT INTO dbo.RdRecord01
  191. (ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,
  192. cWhCode ,dDate ,cCode ,cRdCode ,cDepCode ,
  193. cPersonCode ,cVenCode ,cOrderCode ,cARVCode,
  194. cHandler ,bTransFlag ,cMaker,cDefine1,cDefine2,
  195. dVeriDate ,bpufirst ,biafirst , dARVDate ,VT_ID ,
  196. bIsSTQc ,ipurorderid ,iTaxRate ,iExchRate ,cExch_Name ,
  197. bOMFirst ,bFromPreYear ,bIsComplement ,iDiscountTaxType ,ireturncount ,
  198. iverifystate ,iswfcontrolled ,cModifyPerson ,dnmaketime ,dnverifytime ,
  199. bredvouch ,bCredit ,iPrintCount,ipurarriveid,cPTCode,cVenPUOMProtocol)
  200. SELECT
  201. @ID,1,'01',a.cBusType,@cSource,
  202. @cWhCode,@dDate,@cCode,@cRdCode,@cDepCode,
  203. @cPersonCode,a.cVenCode,a.cPOID,@cARVCode,
  204. @cHandler,0,@cMaker,a.cDefine1,a.cDefine2,
  205. @cVeriDate,0,0,@dARVDate,@VT_ID,
  206. 0,@ipurorderid,a.iTaxRate,a.nflat,a.cexch_name,
  207. 0,0,0,0,0,
  208. 0,0,'',@dnmakertime,@dnverifytime,
  209. @bredvouch,0,0,@ipurarriveid,a.cPTCode,a.cPayCode
  210. FROM dbo.PO_Pomain a
  211. WHERE a.POID='" + head.ID + "'";
  212. cmd.Parameters.Clear();
  213. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  214. cmd.Parameters.Add(new SqlParameter("@cSource", cSource));
  215. cmd.Parameters.Add(new SqlParameter("@cWhCode", iFatherId));
  216. cmd.Parameters.Add(new SqlParameter("@dDate", Convert.ToDateTime(DateTime.Now).ToString("yyyy -MM-dd")));
  217. cmd.Parameters.Add(new SqlParameter("@cCode", head.RCVTCode));
  218. cmd.Parameters.Add(new SqlParameter("@cDepCode", dtPOMain.Rows[0]["cDepCode"].ToString()));
  219. cmd.Parameters.Add(new SqlParameter("@cPersonCode", dtPOMain.Rows[0]["cPersonCode"].ToString()));
  220. cmd.Parameters.Add(new SqlParameter("@cARVCode", cCode));
  221. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  222. cmd.Parameters.Add(new SqlParameter("@cVeriDate", Convert.ToDateTime(DateTime.Now).ToString("yyyy-MM-dd")));
  223. cmd.Parameters.Add(new SqlParameter("@dARVDate", Convert.ToDateTime(head.MTime)));
  224. cmd.Parameters.Add(new SqlParameter("@VT_ID", iChildId));
  225. cmd.Parameters.Add(new SqlParameter("@ipurorderid", dtPOMain.Rows[0]["POID"].ToString()));
  226. cmd.Parameters.Add(new SqlParameter("@dnmakertime", Convert.ToDateTime(DateTime.Now).ToString()));
  227. cmd.Parameters.Add(new SqlParameter("@dnverifytime", Convert.ToDateTime(DateTime.Now).ToString()));
  228. cmd.Parameters.Add(new SqlParameter("@bredvouch", bredvouch));
  229. cmd.Parameters.Add(new SqlParameter("@ipurarriveid", dtPOMain.Rows[0]["ID"].ToString()));
  230. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  231. cmd.Parameters.Add(new SqlParameter("@cRdCode", iFatherId));
  232. ;
  233. cmd.CommandText = sql;
  234. try
  235. {
  236. int count = cmd.ExecuteNonQuery();
  237. if (count <= 0)
  238. {
  239. log.Error("生成采购入库单表头失败,受影响行数<=0;");
  240. throw new Exception("生成采购入库单表头失败,受影响行数<=0;");
  241. }
  242. }
  243. catch (Exception ex)
  244. {
  245. log.Error("生成采购入库单表头失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  246. throw new Exception("生成采购入库单表头失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  247. }
  248. }
  249. else
  250. {
  251. throw new Exception("对应采购订单不存在!采购订单号:" + dtPOMain.Rows[0]["cPOID"].ToString());
  252. }
  253. #endregion
  254. #region 采购入库单表体
  255. int irowno = 0;
  256. foreach (ICSRdRecord01s body in head.Record01s)
  257. {
  258. irowno += 1;
  259. iChildId -= 1;
  260. //if (head.IsReturn == "1")
  261. //{
  262. // body.iQuantity = -body.iQuantity;
  263. //}
  264. sql = @"SELECT a.id,a.cInvCode,a.iUnitPrice ,a.iMoney AS 原币无税金额 ,a.ivouchrowno,
  265. a.iTax AS ,a.iSum AS ,a.iNatUnitPrice ,
  266. a.iNatMoney AS ,a.iNatTax AS ,a.iNatSum AS ,
  267. a.iTaxPrice ,a.freceivedqty AS ,a.iPerTaxRate,c.Autoid,d.cCode,d.dDate
  268. FROM dbo.PO_Podetails a
  269. INNER JOIN dbo.PO_Pomain b ON a.POID=b.POID
  270. LEFT JOIN dbo.PU_ArrivalVouchs c ON a.ID=c.iPOsID
  271. LEFT JOIN dbo.PU_ArrivalVouch d ON c.ID=d.ID
  272. where a.ID='" + body.DNDetailID + "'";
  273. cmd.CommandText = sql;
  274. DataTable dtPODetails = DBHelper.SQlReturnData(sql, cmd);
  275. decimal iUnitPrice = 0;
  276. decimal iNatUnitPrice = 0;
  277. decimal iTaxPrice = 0;
  278. string id = "";
  279. string code = "";
  280. string date = "";
  281. if (dtPODetails != null && dtPODetails.Rows.Count > 0)
  282. {
  283. if (!string.IsNullOrEmpty(dtPODetails.Rows[0]["iUnitPrice"].ToString()))
  284. iUnitPrice = decimal.Parse(dtPODetails.Rows[0]["iUnitPrice"].ToString());//原币无税单价
  285. if (!string.IsNullOrEmpty(dtPODetails.Rows[0]["iNatUnitPrice"].ToString()))
  286. iNatUnitPrice = decimal.Parse(dtPODetails.Rows[0]["iNatUnitPrice"].ToString());//本币无税单价
  287. if (!string.IsNullOrEmpty(dtPODetails.Rows[0]["iTaxPrice"].ToString()))
  288. iTaxPrice = decimal.Parse(dtPODetails.Rows[0]["iTaxPrice"].ToString());//原币含税单价
  289. iTaxRate = Convert.ToDecimal(dtPODetails.Rows[0]["iPerTaxRate"]);
  290. if (!string.IsNullOrEmpty(dtPODetails.Rows[0]["Autoid"].ToString()))//采购退货单字体标识
  291. id = dtPODetails.Rows[0]["Autoid"].ToString();
  292. if (!string.IsNullOrEmpty(dtPODetails.Rows[0]["cCode"].ToString()))//采购退货单号
  293. code = dtPODetails.Rows[0]["cCode"].ToString();
  294. if (!string.IsNullOrEmpty(dtPODetails.Rows[0]["dDate"].ToString()))//采购退货单日期
  295. date = dtPODetails.Rows[0]["dDate"].ToString();
  296. sql = @"INSERT INTO dbo.rdrecords01
  297. (
  298. AutoID ,ID ,cInvCode ,iNum ,iQuantity ,
  299. iUnitCost ,iPrice ,iAPrice ,cBatch ,iFlag ,
  300. dSDate ,iSQuantity ,iSNum ,iMoney ,iPOsID ,
  301. fACost ,iNQuantity ,chVencode ,iOriTaxCost ,iOriCost ,
  302. iOriMoney ,iOriTaxPrice ,ioriSum ,iTaxRate ,iTaxPrice ,
  303. iSum ,bTaxCost ,cPOID ,iMatSettleState ,iBillSettleCount ,
  304. bLPUseFree ,iOriTrackID ,cbaccounter ,dbKeepDate ,bCosting ,
  305. iSumBillQuantity ,bVMIUsed ,iExpiratDateCalcu ,isotype ,irowno,
  306. iArrsId,cbarvcode,dbarvdate
  307. )
  308. select
  309. @AutoID,@ID,@cInvCode,0,@iQuantity,
  310. @iUnitCost,@iPrice,@iAPrice,@cBatch,0,
  311. null,0,0,0,a.ID,
  312. @fACost,@iNQuantity,b.cVenCode,@iOriTaxCost,@iOriCost,
  313. @iOriMoney,@iOriTaxPrice,@ioriSum,@iTaxRate,@iTaxPrice,
  314. @iSum,1,@cPOID,0,0,
  315. 0,0,null,null,d.bInCost,
  316. null,0,0,0,@irowno,
  317. @iArrsId,@cbarvcode,@dbarvdate
  318. FROM dbo.PO_Podetails a
  319. INNER JOIN dbo.PO_Pomain b ON a.POID = b.POID
  320. INNER JOIN dbo.PU_ArrivalVouchs c ON a.ID = c.iPOsID
  321. INNER JOIN dbo.Warehouse d ON d.cWhCode = '{0}'
  322. WHERE c.Autoid = '{1}'
  323. ";
  324. sql = string.Format(sql, head.WHCode, body.DNDetailID);
  325. cmd.Parameters.Clear();
  326. cmd.Parameters.Add(new SqlParameter("@AutoID", iFatherId));
  327. cmd.Parameters.Add(new SqlParameter("@ID", iChildId));
  328. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  329. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  330. cmd.Parameters.Add(new SqlParameter("@iUnitCost", iUnitPrice));
  331. cmd.Parameters.Add(new SqlParameter("@iPrice", Math.Round(body.Quantity * iUnitPrice, 2)));
  332. cmd.Parameters.Add(new SqlParameter("@iAPrice", Math.Round(body.Quantity * iUnitPrice, 2)));
  333. cmd.Parameters.Add(new SqlParameter("@cBatch", ""));
  334. cmd.Parameters.Add(new SqlParameter("@iSQuantity", 0));
  335. cmd.Parameters.Add(new SqlParameter("@iMoney", 0));
  336. cmd.Parameters.Add(new SqlParameter("@fACost", iNatUnitPrice));
  337. cmd.Parameters.Add(new SqlParameter("@iNQuantity", body.Quantity));
  338. cmd.Parameters.Add(new SqlParameter("@iOriTaxCost", iTaxPrice));
  339. cmd.Parameters.Add(new SqlParameter("@iOriMoney", iUnitPrice));
  340. cmd.Parameters.Add(new SqlParameter("@iOriTaxPrice", Math.Round(body.Quantity * iUnitPrice, 2)));
  341. cmd.Parameters.Add(new SqlParameter("@ioriSum", Math.Round(Math.Round(iTaxPrice * body.Quantity, 2) - Math.Round(body.Quantity * iUnitPrice, 2), 2)));
  342. cmd.Parameters.Add(new SqlParameter("@iTaxRate", Math.Round(iTaxPrice * body.Quantity, 2)));
  343. cmd.Parameters.Add(new SqlParameter("@iTaxPrice", iTaxRate));
  344. cmd.Parameters.Add(new SqlParameter("@iSum", Math.Round(Math.Round(iTaxPrice * body.Quantity, 2) - Math.Round(body.Quantity * iUnitPrice, 2), 2)));
  345. cmd.Parameters.Add(new SqlParameter("@irowno", Math.Round(iTaxPrice * body.Quantity, 2)));
  346. cmd.Parameters.Add(new SqlParameter("@cPOID", int.Parse(dtPODetails.Rows[0]["ivouchrowno"].ToString())));
  347. cmd.Parameters.Add(new SqlParameter("@iArrsId", body.DNDetailID));
  348. cmd.Parameters.Add(new SqlParameter("@cbarvcode", code));
  349. cmd.Parameters.Add(new SqlParameter("@dbarvdate", Convert.ToDateTime(date)));
  350. cmd.CommandText = sql;
  351. try
  352. {
  353. int count = cmd.ExecuteNonQuery();
  354. if (count <= 0)
  355. {
  356. log.Error("生成采购入库单表体失败,受影响行数<=0;");
  357. throw new Exception("生成采购入库单表体失败,受影响行数<=0;");
  358. }
  359. }
  360. catch (Exception ex)
  361. {
  362. log.Error("生成采购入库单表体失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  363. throw new Exception("生成采购入库单表体失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  364. }
  365. #region 更新[采购到货单子表]PU_ArrivalVouchs 合格品入库数量20211019
  366. sql = @"UPDATE PU_ArrivalVouchs SET fValidInQuan=ISNULL(fValidInQuan,0)+@iQty WHERE Autoid=@Autoid";
  367. cmd.CommandText = sql;
  368. cmd.Parameters.Clear();
  369. cmd.Parameters.Add(new SqlParameter("@iQty", body.Quantity));
  370. cmd.Parameters.Add(new SqlParameter("@Autoid", body.DNDetailID));
  371. try
  372. {
  373. log.Info("PU_Autoid:" + body.DNDetailID);
  374. cmd.ExecuteNonQuery();
  375. }
  376. catch (Exception ex)
  377. {
  378. log.Error("回写采购到货单子表合格品入库数量失败:Autoid:" + body.DNDetailID + ";异常:" + ex.Message);
  379. throw new Exception("程序异常,请联系开发人员!");
  380. }
  381. #endregion
  382. #region 更新[采购订单子表]PO_PODetails累计到货数量和累计到货金额
  383. //sql = @"Update a set iReceivedQTY =isnull(iReceivedQTY ,0)+ @iQty,iReceivedMoney=isnull(iReceivedMoney,0)+@iMoney FROM dbo.PO_Podetails a where a.ID='" + body.iPOsID + "'";
  384. sql = @"
  385. Update a set
  386. iReceivedMoney=isnull(iReceivedMoney,0)+@iMoney
  387. ,freceivedqty=isnull(freceivedqty ,0)+ @iQty
  388. FROM dbo.PO_Podetails a where a.ID=@ID"
  389. ;
  390. //2021-11-05
  391. //1.移除 iReceivedQTY =isnull(iReceivedQTY ,0)+ @iQty 由采购到货,创建到货单CreatePU时写入iReceivedQTY,此处不再回写,累计到货数量
  392. //2.加入 freceivedqty =isnull(freceivedqty ,0) + @iQty 合格品入库数量
  393. cmd.CommandText = sql;
  394. cmd.Parameters.Clear();
  395. cmd.Parameters.Add(new SqlParameter("@iQty", body.Quantity));
  396. cmd.Parameters.Add(new SqlParameter("@iMoney", body.Quantity * iUnitPrice));
  397. cmd.Parameters.Add(new SqlParameter("@ID", body.DNDetailID));
  398. try
  399. {
  400. log.Info("iPOsID:" + body.DNDetailID);
  401. cmd.ExecuteNonQuery();
  402. }
  403. catch (Exception ex)
  404. {
  405. log.Error("回写采购订单累计到货数量和累计到货金额失败:采购订单表体行号:" + body.DNDetailID + ";异常:" + ex.Message);
  406. throw new Exception("程序异常,请联系开发人员!");
  407. }
  408. #endregion
  409. //更新现存量
  410. key.cBustypeUN = "普通采购";
  411. key.cVouchTypeUN = "01";
  412. key.TableName = "IA_ST_UnAccountVouch01";
  413. DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, body.InvCode, body.Quantity, key);
  414. }
  415. ////更新主键ID,DID
  416. //DBHelper.UpdateIDandDID("rd", head.list.Count(), cmd);
  417. }
  418. #endregion
  419. #region 判断现存量是否超入库
  420. sql = @"IF EXISTS(SELECT ID FROM dbo.PO_Podetails WHERE isnull(ireceivedqty,0)+isnull(freceivedqty,0)>iQuantity AND ID>'1000043932')
  421. BEGIN
  422. DECLARE @MSG NVARCHAR(100)
  423. SELECT @MSG='ERP入库数量不能大于订单数量ID'+CAST(ID AS NVARCHAR(100)) FROM dbo.PO_Podetails WHERE isnull(ireceivedqty,0)+isnull(freceivedqty,0)>iQuantity AND ID>'1000043932'
  424. RAISERROR(@MSG,16,1)
  425. END";
  426. cmd.CommandText = sql;
  427. cmd.ExecuteNonQuery();
  428. #endregion
  429. }
  430. return szJson;
  431. }
  432. }
  433. }