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

646 lines
31 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using ICSSoft.Entity;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using Newtonsoft.Json;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using ICSSoft.Common;
  11. namespace ICSSoft.DataProject
  12. {
  13. public class CreatePuArrivalVouch
  14. {
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  17. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  18. private static string Type = System.Configuration.ConfigurationManager.AppSettings["Type"];
  19. private static string CRNALL = System.Configuration.ConfigurationManager.AppSettings["PUARRIVALRCRDNAME"];
  20. //参数示例
  21. //[{
  22. // "ASNNO": "DN510852000001",
  23. // "WHCode": "11",
  24. // "User": "CC001",
  25. // "MTime": "2021-08-26 17:20:13",
  26. // "details": [
  27. // {
  28. // "LOTNO": "PO200219004100005",
  29. // "ReceiveQty": "2"
  30. // },{
  31. // "LOTNO": "PO200219004100001",
  32. // "ReceiveQty": "1"
  33. // }
  34. // ]
  35. //}]
  36. //返回参数
  37. //{
  38. //"Success": true,
  39. //"Message": "接口调用成功!",
  40. //"Data": null
  41. //}
  42. public string Get(List<ICSPUArrivalVouch> infos)
  43. {
  44. List<ICSPUArrivalVouch> szJson = new List<ICSPUArrivalVouch>();
  45. DataTable dt = null;
  46. DataTable dtNew = null;
  47. string connS = "";
  48. string json = "";
  49. if (infos.Count <= 0)
  50. {
  51. throw new Exception("传送数据为空!");
  52. }
  53. string res = string.Empty;
  54. SqlConnection conn = new SqlConnection();
  55. SqlCommand cmd = new SqlCommand();
  56. string sql = string.Empty;
  57. foreach (ICSPUArrivalVouch info in infos)
  58. {
  59. try
  60. {
  61. connS = string.Format(connString, info.WorkPoint);
  62. conn = new System.Data.SqlClient.SqlConnection(connS);
  63. conn.Open();
  64. SqlTransaction sqlTran = conn.BeginTransaction();
  65. cmd = new SqlCommand();
  66. cmd.Transaction = sqlTran;
  67. cmd.Connection = conn;
  68. if (info.MTime < new DateTime(2000, 01, 01))
  69. throw new Exception("请输入正确的操作时间:" + info.MTime);
  70. sql = @"SELECT A.ID,A.cCode,A. cVenCode ,D.CVENNAME,A.cDepCode,C.CDEPNAME, A.CMAKER,A.CMAKETIME,A.CVERIFIER,A.CAUDITTIME,
  71. B.Autoid ,B.irowno ,B.IQUANTITY ,B.INUM,B.cInvCode ,B.iCost ,B.irejectautoid
  72. FROM PU_ArrivalVouch A
  73. INNER JOIN PU_ArrivalVouchs B ON A.ID=B.ID
  74. INNER JOIN DEPARTMENT C ON A.CDEPCODE=C.CDEPCODE
  75. INNER JOIN VENDOR D ON A.CVENCODE=D.CVENCODE WHERE 1=1 and a.iBillType=2 and b.IQUANTITY<0 ";
  76. if (!string.IsNullOrWhiteSpace(info.RJTCode))
  77. {
  78. sql += " and a.cCode='{0}'";
  79. }
  80. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  81. {
  82. sql += " and ISNULL(A.dclosedate,ISNULL(A.caudittime ,ISNULL(A.cAuditTime, ISNULL(A.cModifyTime, A.cMakeTime))))>='{1}'";
  83. }
  84. if (!string.IsNullOrWhiteSpace(info.User))
  85. {
  86. sql += "and a.CMAKER='{2}'";
  87. }
  88. sql = string.Format(sql, info.RJTCode, info.MTime, info.User);
  89. dt = DBHelper.SQlReturnData(sql, cmd);
  90. if (dt.Rows.Count <= 0 || dt == null)
  91. throw new Exception("拒收单单:" + info.RJTCode + ",无信息!");
  92. if (dtNew == null)
  93. dtNew = dt;
  94. else
  95. dtNew.Merge(dt);
  96. cmd.Transaction.Commit();
  97. }
  98. catch (Exception ex)
  99. {
  100. cmd.Transaction.Rollback();
  101. log.Error(ex.Message);
  102. throw new Exception(ex.Message);
  103. }
  104. finally
  105. {
  106. if (conn.State == ConnectionState.Open)
  107. {
  108. conn.Close();
  109. }
  110. conn.Dispose();
  111. }
  112. }
  113. json = JsonConvert.SerializeObject(dtNew);
  114. return json;
  115. }
  116. /// <summary>
  117. /// 回写U8到货单,
  118. /// </summary>
  119. /// <param name="cmd"></param>
  120. /// <param name="Lotnos"></param>
  121. /// <param name="info"></param>
  122. public string CreatePUArrive(List<ICSPUArrivalVouch> Bills)
  123. {
  124. string msg = "";
  125. bool ResultFlag = false;
  126. int num = 0;
  127. foreach (ICSPUArrivalVouch head in Bills)
  128. {
  129. num = head.Vouchs.Count();
  130. }
  131. DataTable dtNew = null;
  132. string connS = "";
  133. SqlConnection conn = new SqlConnection();
  134. SqlCommand cmd = new SqlCommand();
  135. if (Bills.Count <= 0)
  136. {
  137. throw new Exception("传送数据为空!");
  138. }
  139. bool isNG = false;
  140. LogInfo(Bills);
  141. DateTime dVDate = new DateTime();
  142. DateTime dPDate = new DateTime();
  143. foreach (ICSPUArrivalVouch head in Bills)
  144. {
  145. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  146. {
  147. if (body.Quantity > 0)
  148. {
  149. isNG = true;
  150. }
  151. }
  152. }
  153. if (isNG)
  154. {
  155. int sum = 0;
  156. foreach (ICSPUArrivalVouch head in Bills)
  157. {
  158. try
  159. {
  160. connS = string.Format(connString, head.WorkPoint);
  161. conn = new System.Data.SqlClient.SqlConnection(connS);
  162. conn.Open();
  163. SqlTransaction sqlTran = conn.BeginTransaction();
  164. cmd = new SqlCommand();
  165. cmd.Transaction = sqlTran;
  166. cmd.Connection = conn;
  167. string[] ss = head.WorkPoint.Split('_');
  168. ERPDB = ss[1];
  169. string sql = "";
  170. VouchKey key = new VouchKey();
  171. //取得out库单的默认显示模版
  172. string[] dd = CRNALL.Split('~');
  173. string crdname = dd[0];
  174. string carname = dd[1];
  175. string surface = dd[2];
  176. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  177. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  178. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  179. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  180. DateTime date = DateTime.Now;
  181. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  182. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  183. #region 主表
  184. sql = @"INSERT INTO PU_ArrivalVouch
  185. (iVTid, ID, cCode, cPTCode, dDate, cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, cBusType, cMaker, bNegative,
  186. iDiscountTaxType, iBillType, cMakeTime, cAuditDate, caudittime, cverifier, iverifystateex, IsWfControlled, iflowid, iPrintCount, cpocode)
  187. SELECT @iVTid, @ID, @cCode, cPTCode, CONVERT(NVARCHAR(10), GETDATE(), 23), cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, '', @User, 1,
  188. iDiscountTaxType, 2, GETDATE(), CONVERT(NVARCHAR(10), GETDATE(), 23), GETDATE(), @User, 2, 0, 0, iPrintCount, null
  189. FROM PU_ArrivalVouch WHERE 1=1 AND cCode = @headID ";
  190. cmd.Parameters.Clear();
  191. cmd.Parameters.Add(new SqlParameter("@iVTid", iChildId));
  192. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  193. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  194. cmd.Parameters.Add(new SqlParameter("@User", head.User));
  195. cmd.Parameters.Add(new SqlParameter("@headID", head.DNCode));
  196. cmd.CommandText = sql;
  197. try
  198. {
  199. int count = cmd.ExecuteNonQuery();
  200. if (count <= 0)
  201. {
  202. log.Error("生成采购拒收单表头失败,受影响行数<=0;");
  203. throw new Exception("生成采购拒收单表头失败,受影响行数<=0;");
  204. }
  205. }
  206. catch (Exception ex)
  207. {
  208. log.Error("生成采购拒收单表头失败!到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  209. throw new Exception("生成采购拒收单表头失败!到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  210. }
  211. #endregion
  212. #region 表体
  213. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  214. {
  215. sql = @"INSERT INTO PU_ArrivalVouchs
  216. (Autoid, ID, cInvCode, iQuantity, iOriCost, iOriTaxCost, iOriMoney, iOriTaxPrice, iOriSum, iCost, iMoney, iTaxPrice, iSum, iTaxRate,
  217. iPOsID, fValidInQuan, fRealQuantity, fValidQuantity, fRetQuantity, fInValidInQuan, bGsp, fValidNum, fValidInNum, fRealNum, bTaxCost,
  218. SoType, fInvalidInNum, iinvexchrate, cordercode, RejectSource, iExpiratDateCalcu, iordertype, ivouchrowno, bgift,
  219. cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,
  220. cBatch, cDefine37, fKPQuantity, finValidQuantity, fRefuseQuantity, iProductType,bexigency,inum,iCorId,carrivalcode )
  221. SELECT @Autoid, @ID1, @cInvCode, @iQuantity,pd.iUnitPrice,pd.iTaxPrice,round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),
  222. round(pd.iTaxPrice*@iQuantity,2)-round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),round(pd.iTaxPrice*@iQuantity,2),round((pd.iTaxPrice/(1+pd.iPerTaxRate/100)*b.nflat),2),
  223. round(round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2)*b.nflat,2),
  224. round((round(pd.iTaxPrice*@iQuantity,2)-round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2))*b.nflat,2),round(round(pd.iTaxPrice*3402,2)*b.nflat,2),pd.iPerTaxRate,
  225. pd.ID, 0, @iQuantity, @iQuantity, 0, 0, 0, null, null, null, 1,
  226. 0, null, 0, b.cPOID, 0, 0, 0, @ivouchrowno, 0,
  227. @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8, @cFree9, @cFree10,
  228. @Batch, @cDefine37, null, null, null, null, null,@iNum,a.Autoid,c.cCode
  229. FROM dbo.PU_ArrivalVouchs a LEFT JOIN dbo.PO_Podetails pd ON a.iPOsID= pd.ID
  230. INNER JOIN dbo.PO_Pomain b ON pd.POID=b.POID
  231. INNER JOIN dbo.PU_ArrivalVouch c ON a.ID=c.ID where a.Autoid='" + body.DNDetailID + @"'
  232. EXEC PROC_Update_PO_PUArrivalVouchs @ID= @ID1";
  233. cmd.Parameters.Clear();
  234. cmd.Parameters.Add(new SqlParameter("@Autoid", iChildId));
  235. cmd.Parameters.Add(new SqlParameter("@ID1", iFatherId));
  236. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  237. cmd.Parameters.Add(new SqlParameter("@iQuantity", -body.Quantity));
  238. cmd.Parameters.Add(new SqlParameter("@iNum", -body.Amount));
  239. cmd.Parameters.Add(new SqlParameter("@ivouchrowno", body.Sequence));
  240. cmd.Parameters.Add(new SqlParameter("@Batch", body.BatchCode));
  241. cmd.Parameters.Add(new SqlParameter("@cDefine37", DateTime.Now.Date.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddSeconds(-1)));
  242. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  243. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  244. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  245. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  246. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  247. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  248. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  249. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  250. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  251. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  252. cmd.CommandText = sql;
  253. try
  254. {
  255. int count = cmd.ExecuteNonQuery();
  256. if (count <= 0)
  257. {
  258. log.Error("生成采购拒收单表体失败,受影响行数<=0;");
  259. throw new Exception("生成采购拒收单表体失败,受影响行数<=0;");
  260. }
  261. }
  262. catch (Exception ex)
  263. {
  264. log.Error("生成采购拒收单表体失败!采购到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  265. throw new Exception("生成采购拒收单表体失败!采购到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  266. }
  267. sql = string.Format(@"update pd set pd.fPoRefuseQuantity = isnull(pd.fPoRefuseQuantity,0)+{0}
  268. from dbo.PU_ArrivalVouchs a LEFT JOIN dbo.PO_Podetails pd ON a.iPOsID= pd.ID
  269. INNER JOIN dbo.PO_Pomain b ON pd.POID=b.POID
  270. INNER JOIN dbo.PU_ArrivalVouch c ON a.ID=c.ID where a.Autoid='" + body.DNDetailID + "' ", body.Quantity);
  271. cmd.CommandText = sql;
  272. cmd.ExecuteNonQuery();
  273. iChildId -= 1;
  274. }
  275. #endregion
  276. cmd.Transaction.Commit();
  277. }
  278. catch (Exception ex)
  279. {
  280. cmd.Transaction.Rollback();
  281. log.Error(ex.Message);
  282. throw new Exception(ex.Message);
  283. }
  284. finally
  285. {
  286. if (conn.State == ConnectionState.Open)
  287. {
  288. conn.Close();
  289. }
  290. conn.Dispose();
  291. }
  292. }
  293. }
  294. ResultFlag = true;
  295. return msg;
  296. }
  297. /// <summary>
  298. /// 回写委外拒收单
  299. /// </summary>
  300. /// <param name="cmd"></param>
  301. /// <param name="Lotnos"></param>
  302. /// <param name="info"></param>
  303. public string CreateWPUArrive(List<ICSPUArrivalVouch> Bills)
  304. {
  305. string msg = "";
  306. bool ResultFlag = false;
  307. int num = 0;
  308. foreach (ICSPUArrivalVouch head in Bills)
  309. {
  310. num = head.Vouchs.Count();
  311. }
  312. DataTable dtNew = null;
  313. string connS = "";
  314. SqlConnection conn = new SqlConnection();
  315. SqlCommand cmd = new SqlCommand();
  316. if (Bills.Count <= 0)
  317. {
  318. throw new Exception("传送数据为空!");
  319. }
  320. bool isNG = false;
  321. LogInfo(Bills);
  322. DateTime dVDate = new DateTime();
  323. DateTime dPDate = new DateTime();
  324. foreach (ICSPUArrivalVouch head in Bills)
  325. {
  326. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  327. {
  328. if (body.Quantity > 0)
  329. {
  330. isNG = true;
  331. }
  332. }
  333. }
  334. if (isNG)
  335. {
  336. int sum = 0;
  337. foreach (ICSPUArrivalVouch head in Bills)
  338. {
  339. try
  340. {
  341. connS = string.Format(connString, head.WorkPoint);
  342. conn = new System.Data.SqlClient.SqlConnection(connS);
  343. conn.Open();
  344. SqlTransaction sqlTran = conn.BeginTransaction();
  345. cmd = new SqlCommand();
  346. cmd.Transaction = sqlTran;
  347. cmd.Connection = conn;
  348. string[] ss = head.WorkPoint.Split('_');
  349. ERPDB = ss[1];
  350. string sql = "";
  351. VouchKey key = new VouchKey();
  352. //取得out库单的默认显示模版
  353. string[] dd = CRNALL.Split('~');
  354. string crdname = dd[0];
  355. string carname = dd[1];
  356. string surface = dd[2];
  357. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  358. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  359. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  360. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  361. DateTime date = DateTime.Now;
  362. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  363. #region 主表
  364. sql = @"INSERT INTO PU_ArrivalVouch
  365. (iVTid, ID, cCode, cPTCode, dDate, cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, cBusType, cMaker, bNegative,
  366. iDiscountTaxType, iBillType, cMakeTime, cAuditDate, caudittime, cverifier, iverifystateex, IsWfControlled, iflowid, iPrintCount, cpocode)
  367. SELECT @iVTid, @ID, @cCode, cPTCode, CONVERT(NVARCHAR(10), GETDATE(), 23), cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, '', @User, 1,
  368. iDiscountTaxType, 2, GETDATE(), CONVERT(NVARCHAR(10), GETDATE(), 23), GETDATE(), @User, 2, 0, 0, iPrintCount, null
  369. FROM PU_ArrivalVouch WHERE 1=1 AND cCode = @headID ";
  370. cmd.Parameters.Clear();
  371. cmd.Parameters.Add(new SqlParameter("@iVTid", iChildId));
  372. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  373. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  374. cmd.Parameters.Add(new SqlParameter("@User", head.User));
  375. cmd.Parameters.Add(new SqlParameter("@headID", head.DNCode));
  376. cmd.CommandText = sql;
  377. try
  378. {
  379. int count = cmd.ExecuteNonQuery();
  380. if (count <= 0)
  381. {
  382. log.Error("生成采购拒收单表头失败,受影响行数<=0;");
  383. throw new Exception("生成采购拒收单表头失败,受影响行数<=0;");
  384. }
  385. }
  386. catch (Exception ex)
  387. {
  388. log.Error("生成采购拒收单表头失败!到货单:" + head.DNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  389. throw new Exception("生成采购拒收单表头失败!到货单:" + head.DNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  390. }
  391. #endregion
  392. #region 表体
  393. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  394. {
  395. iChildId -= 1;
  396. sql = @"INSERT INTO PU_ArrivalVouchs
  397. (Autoid, ID, cInvCode, iQuantity, iOriCost, iOriTaxCost, iOriMoney, iOriTaxPrice, iOriSum, iCost, iMoney, iTaxPrice, iSum, iTaxRate,
  398. iPOsID, fValidInQuan, fRealQuantity, fValidQuantity, fRetQuantity, fInValidInQuan, bGsp, fValidNum, fValidInNum, fRealNum, bTaxCost,
  399. SoType, fInvalidInNum, iinvexchrate, cordercode, RejectSource, iExpiratDateCalcu, iordertype, ivouchrowno, bgift,
  400. cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,
  401. cBatch, cDefine37, fKPQuantity, finValidQuantity, fRefuseQuantity, iProductType,bexigency,inum,iCorId,carrivalcode )
  402. SELECT top 1 @Autoid, @ID1, @cInvCode, @iQuantity,pd.iUnitPrice,pd.iTaxPrice,round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),
  403. round(pd.iTaxPrice*@iQuantity,2)-round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),round(pd.iTaxPrice*@iQuantity,2),round((pd.iTaxPrice/(1+pd.iPerTaxRate/100)*b.nflat),2),
  404. round(round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2)*b.nflat,2),
  405. round((round(pd.iTaxPrice*@iQuantity,2)-round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2))*b.nflat,2),round(round(pd.iTaxPrice*3402,2)*b.nflat,2),pd.iPerTaxRate,
  406. pd.MODetailsID, 0, @iQuantity, @iQuantity, 0, 0, 0, null, null, null, 1,
  407. 0, null, 0, b.ccode, 0, 0, 0, @ivouchrowno, 0,
  408. @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8, @cFree9, @cFree10,
  409. @Batch, @cDefine37, null, null, null, null, null,@iNum,a.Autoid,c.cCode
  410. from dbo.PU_ArrivalVouchs a
  411. LEFT JOIN dbo.OM_MODetails pd ON a.iPOsID = pd.MODetailsID
  412. left JOIN dbo.OM_MOMain b ON pd.MOID = b.MOID
  413. left JOIN dbo.PU_ArrivalVouch c ON a.ID=c.ID where a.Autoid='" + body.DNDetailID + @"'
  414. EXEC PROC_Update_OM_PUArrivalVouchs @ID= @ID1
  415. ";
  416. cmd.Parameters.Clear();
  417. cmd.Parameters.Add(new SqlParameter("@Autoid", iChildId));
  418. cmd.Parameters.Add(new SqlParameter("@ID1", iFatherId));
  419. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  420. cmd.Parameters.Add(new SqlParameter("@iQuantity", -body.Quantity));
  421. cmd.Parameters.Add(new SqlParameter("@iNum", -body.Amount));
  422. cmd.Parameters.Add(new SqlParameter("@ivouchrowno", body.Sequence));
  423. cmd.Parameters.Add(new SqlParameter("@Batch", body.BatchCode));
  424. cmd.Parameters.Add(new SqlParameter("@cDefine37", DateTime.Now.Date.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddSeconds(-1)));
  425. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  426. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  427. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  428. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  429. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  430. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  431. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  432. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  433. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  434. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  435. cmd.CommandText = sql;
  436. try
  437. {
  438. int count = cmd.ExecuteNonQuery();
  439. if (count <= 0)
  440. {
  441. log.Error("生成采购拒收单表体失败,受影响行数<=0;");
  442. throw new Exception("生成采购拒收单表体失败,受影响行数<=0;");
  443. }
  444. }
  445. catch (Exception ex)
  446. {
  447. log.Error("生成委外拒收单表体失败!委外到货单:" + head.DNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  448. throw new Exception("生成委外拒收单表体失败!委外到货单:" + head.DNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  449. }
  450. sql = string.Format(@"update pd set pd.fPoRefuseQuantity = isnull(pd.fPoRefuseQuantity,0)+{0}
  451. from dbo.PU_ArrivalVouchs a LEFT JOIN dbo.PO_Podetails pd ON a.iPOsID= pd.ID
  452. where a.Autoid='" + body.DNDetailID + "' ", body.Quantity);
  453. cmd.CommandText = sql;
  454. cmd.ExecuteNonQuery();
  455. }
  456. #endregion
  457. cmd.Transaction.Commit();
  458. }
  459. catch (Exception ex)
  460. {
  461. cmd.Transaction.Rollback();
  462. log.Error(ex.Message);
  463. throw new Exception(ex.Message);
  464. }
  465. finally
  466. {
  467. if (conn.State == ConnectionState.Open)
  468. {
  469. conn.Close();
  470. }
  471. conn.Dispose();
  472. }
  473. }
  474. }
  475. ResultFlag = true;
  476. return msg;
  477. }
  478. public string Approve(List<ICSPUArrivalVouch> infos)
  479. {
  480. List<ICSPUArrivalVouch> szJson = new List<ICSPUArrivalVouch>();
  481. DataTable dt = null;
  482. DataTable dtNew = null;
  483. string connS = "";
  484. string json = "";
  485. if (infos.Count <= 0)
  486. {
  487. throw new Exception("传送数据为空!");
  488. }
  489. string res = string.Empty;
  490. SqlConnection conn = new SqlConnection();
  491. SqlCommand cmd = new SqlCommand();
  492. string sql = string.Empty;
  493. foreach (ICSPUArrivalVouch info in infos)
  494. {
  495. try
  496. {
  497. connS = string.Format(connString, info.WorkPoint);
  498. conn = new System.Data.SqlClient.SqlConnection(connS);
  499. conn.Open();
  500. SqlTransaction sqlTran = conn.BeginTransaction();
  501. cmd = new SqlCommand();
  502. cmd.Transaction = sqlTran;
  503. cmd.Connection = conn;
  504. if (info.MTime < new DateTime(2000, 01, 01))
  505. throw new Exception("请输入正确的操作时间:" + info.MTime);
  506. sql = @"UPDATE PU_ArrivalVouch SET cVerifier ='" + info.User + @"' ,
  507. cAuditTime=CONVERT(VARCHAR(50),GETDATE(),112),cAuditDate=GETDATE() WHERE ID='{0}'";
  508. sql = string.Format(sql, info.ID);
  509. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  510. cmd.Transaction.Commit();
  511. }
  512. catch (Exception ex)
  513. {
  514. cmd.Transaction.Rollback();
  515. log.Error(ex.Message);
  516. throw new Exception(ex.Message);
  517. }
  518. finally
  519. {
  520. if (conn.State == ConnectionState.Open)
  521. {
  522. conn.Close();
  523. }
  524. conn.Dispose();
  525. }
  526. }
  527. return json;
  528. }
  529. /// <summary>
  530. /// 删除请购单
  531. /// </summary>
  532. /// <param name="infos"></param>
  533. /// <returns></returns>
  534. public string Delete(List<ICSPUArrivalVouch> infos)
  535. {
  536. List<ICSPUArrivalVouch> szJson = new List<ICSPUArrivalVouch>();
  537. if (infos.Count <= 0)
  538. {
  539. throw new Exception("传送数据为空!");
  540. }
  541. string res = string.Empty;
  542. DataTable dtNew = null;
  543. string connS = "";
  544. SqlConnection conn = new SqlConnection();
  545. SqlCommand cmd = new SqlCommand();
  546. string sql = string.Empty;
  547. foreach (ICSPUArrivalVouch info in infos)
  548. {
  549. try
  550. {
  551. connS = string.Format(connString, info.WorkPoint);
  552. conn = new System.Data.SqlClient.SqlConnection(connS);
  553. conn.Open();
  554. SqlTransaction sqlTran = conn.BeginTransaction();
  555. cmd = new SqlCommand();
  556. cmd.Transaction = sqlTran;
  557. cmd.Connection = conn;
  558. if (info.MTime < new DateTime(2000, 01, 01))
  559. throw new Exception("请输入正确的操作时间:" + info.MTime);
  560. sql = @" DELETE PU_AppVouch WHERE ID={0}";
  561. sql = string.Format(sql, info.ID);
  562. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  563. cmd.Transaction.Commit();
  564. }
  565. catch (Exception ex)
  566. {
  567. cmd.Transaction.Rollback();
  568. log.Error(ex.Message);
  569. throw new Exception(ex.Message);
  570. }
  571. finally
  572. {
  573. if (conn.State == ConnectionState.Open)
  574. {
  575. conn.Close();
  576. }
  577. conn.Dispose();
  578. }
  579. }
  580. return res;
  581. }
  582. /// <summary>
  583. ///
  584. /// 记录日志
  585. /// </summary>
  586. /// <param name="Bills"></param>
  587. private void LogInfo(List<ICSPUArrivalVouch> Bills)
  588. {
  589. string HeadList = string.Empty;
  590. string BodyList = string.Empty;
  591. foreach (ICSPUArrivalVouch head in Bills)
  592. {
  593. HeadList += "\r\n 表头主键ID:" + head.ID + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  594. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  595. {
  596. BodyList += "\r\n 表体主键ID: " + body.DNDetailID + ",数量:" + body.Quantity;
  597. }
  598. }
  599. log.Info(HeadList);
  600. log.Info(BodyList);
  601. }
  602. }
  603. }