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

808 lines
40 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 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. ICSUserInfo userInfo = new ICSUserInfo();
  69. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  70. if (info.MTime < new DateTime(2000, 01, 01))
  71. throw new Exception("请输入正确的操作时间:" + info.MTime);
  72. sql = @"SELECT A.ID,A.cCode,A. cVenCode ,D.CVENNAME,A.cDepCode,C.CDEPNAME, A.CMAKER,A.CMAKETIME,A.CVERIFIER,A.CAUDITTIME,
  73. B.Autoid ,B.irowno ,B.IQUANTITY ,B.INUM,B.cInvCode ,B.iCost ,B.irejectautoid
  74. FROM PU_ArrivalVouch A
  75. INNER JOIN PU_ArrivalVouchs B ON A.ID=B.ID
  76. INNER JOIN DEPARTMENT C ON A.CDEPCODE=C.CDEPCODE
  77. INNER JOIN VENDOR D ON A.CVENCODE=D.CVENCODE WHERE 1=1 and a.iBillType=2 and b.IQUANTITY<0 ";
  78. if (!string.IsNullOrWhiteSpace(info.RJTCode))
  79. {
  80. sql += " and a.cCode='{0}'";
  81. }
  82. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  83. {
  84. sql += " and ISNULL(A.dclosedate,ISNULL(A.caudittime ,ISNULL(A.cAuditTime, ISNULL(A.cModifyTime, A.cMakeTime))))>='{1}'";
  85. }
  86. if (!string.IsNullOrWhiteSpace(info.User))
  87. {
  88. sql += "and a.CMAKER='{2}'";
  89. }
  90. sql = string.Format(sql, info.RJTCode, info.MTime, userInfo.UserName);
  91. dt = DBHelper.SQlReturnData(sql, cmd);
  92. if (dt.Rows.Count <= 0 || dt == null)
  93. throw new Exception("拒收单单:" + info.RJTCode + ",无信息!");
  94. if (dtNew == null)
  95. dtNew = dt;
  96. else
  97. dtNew.Merge(dt);
  98. cmd.Transaction.Commit();
  99. }
  100. catch (Exception ex)
  101. {
  102. if (cmd.Transaction != null)
  103. cmd.Transaction.Rollback();
  104. log.Error(ex.Message);
  105. throw new Exception(ex.Message);
  106. }
  107. finally
  108. {
  109. if (conn.State == ConnectionState.Open)
  110. {
  111. conn.Close();
  112. }
  113. conn.Dispose();
  114. }
  115. }
  116. json = JsonConvert.SerializeObject(dtNew);
  117. return json;
  118. }
  119. /// <summary>
  120. /// 回写U8到货单,
  121. /// </summary>
  122. /// <param name="cmd"></param>
  123. /// <param name="Lotnos"></param>
  124. /// <param name="info"></param>
  125. public string CreatePUArrive(List<ICSPUArrivalVouch> Bills)
  126. {
  127. string msg = "";
  128. string szJson = "";
  129. DataSet ds = null;
  130. string iFatherIdTwo = "";
  131. int num = 0;
  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. foreach (ICSPUArrivalVouch head in Bills)
  142. {
  143. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  144. {
  145. if (body.Quantity > 0)
  146. {
  147. isNG = true;
  148. }
  149. }
  150. }
  151. List<string> result = Bills.Select(t => t.WorkPoint).Distinct().ToList();
  152. foreach (string WorkPoint in result)
  153. {
  154. try
  155. {
  156. connS = string.Format(connString, WorkPoint);
  157. conn = new System.Data.SqlClient.SqlConnection(connS);
  158. conn.Open();
  159. SqlTransaction sqlTran = conn.BeginTransaction();
  160. cmd = new SqlCommand();
  161. cmd.Transaction = sqlTran;
  162. cmd.Connection = conn;
  163. if (isNG)
  164. {
  165. int sum = 0;
  166. foreach (ICSPUArrivalVouch head in Bills)
  167. {
  168. iFatherIdTwo = "";
  169. num = head.Vouchs.Count();
  170. if (WorkPoint != head.WorkPoint)
  171. {
  172. continue;
  173. }
  174. string[] ss = head.WorkPoint.Split('_');
  175. ERPDB = ss[1];
  176. string sql = "";
  177. VouchKey key = new VouchKey();
  178. //取得out库单的默认显示模版
  179. string[] dd = CRNALL.Split('~');
  180. string crdname = dd[0];
  181. string carname = dd[1];
  182. string surface = dd[2];
  183. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  184. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint, cmd);
  185. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  186. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  187. DateTime date = DateTime.Now;
  188. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", "", head.WorkPoint, cmd);
  189. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  190. ICSUserInfo userInfo = new ICSUserInfo();
  191. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  192. #region 主表
  193. sql = @"INSERT INTO PU_ArrivalVouch
  194. (iVTid, ID, cCode, cPTCode, dDate, cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, cBusType, cMaker, bNegative,
  195. iDiscountTaxType, iBillType, cMakeTime, cAuditDate, caudittime, cverifier, iverifystateex, IsWfControlled, iflowid, iPrintCount, cpocode)
  196. SELECT @iVTid, @ID, @cCode, cPTCode, CONVERT(NVARCHAR(10), GETDATE(), 23), cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, '', @User, 1,
  197. iDiscountTaxType, 2, GETDATE(), CONVERT(NVARCHAR(10), GETDATE(), 23), GETDATE(), @User, 2, 0, 0, iPrintCount, null
  198. FROM PU_ArrivalVouch WHERE 1=1 AND cCode = @headID ";
  199. cmd.Parameters.Clear();
  200. cmd.Parameters.Add(new SqlParameter("@iVTid", DEF_ID));
  201. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  202. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  203. cmd.Parameters.Add(new SqlParameter("@User", userInfo.UserName));
  204. cmd.Parameters.Add(new SqlParameter("@headID", head.DNCode));
  205. cmd.CommandText = sql;
  206. try
  207. {
  208. int count = cmd.ExecuteNonQuery();
  209. if (count <= 0)
  210. {
  211. log.Error("生成采购拒收单表头失败,受影响行数<=0;");
  212. throw new Exception("生成采购拒收单表头失败,受影响行数<=0;");
  213. }
  214. }
  215. catch (Exception ex)
  216. {
  217. log.Error("生成采购拒收单表头失败!到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  218. throw new Exception("生成采购拒收单表头失败!到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  219. }
  220. #endregion
  221. iFatherIdTwo = "'" + iFatherId + "',";
  222. #region 表体
  223. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  224. {
  225. sql = @"INSERT INTO PU_ArrivalVouchs
  226. (Autoid, ID, cInvCode, iQuantity, iOriCost, iOriTaxCost, iOriMoney, iOriTaxPrice, iOriSum, iCost, iMoney, iTaxPrice, iSum, iTaxRate,
  227. iPOsID, fValidInQuan, fRealQuantity, fValidQuantity, fRetQuantity, fInValidInQuan, bGsp, fValidNum, fValidInNum, fRealNum, bTaxCost,
  228. SoType, fInvalidInNum, iinvexchrate, cordercode, RejectSource, iExpiratDateCalcu, iordertype, ivouchrowno, bgift,
  229. cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,cItemCode,
  230. cBatch, cDefine37, fKPQuantity, finValidQuantity, fRefuseQuantity, iProductType,bexigency,inum,iCorId,carrivalcode )
  231. SELECT @Autoid, @ID1, @cInvCode, @iQuantity,pd.iUnitPrice,pd.iTaxPrice,round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),
  232. 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),
  233. round(round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2)*b.nflat,2),
  234. 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,
  235. pd.ID, 0, @iQuantity, @iQuantity, 0, 0, 0, null, null, null, 1,
  236. 0, null, 0, b.cPOID, 0, 0, 0, @ivouchrowno, 0,
  237. @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8, @cFree9, @cFree10,@cItemCode,
  238. @Batch, @cDefine37, null, null, null, null, null,0,a.Autoid,c.cCode
  239. FROM dbo.PU_ArrivalVouchs a LEFT JOIN dbo.PO_Podetails pd ON a.iPOsID= pd.ID
  240. INNER JOIN dbo.PO_Pomain b ON pd.POID=b.POID
  241. INNER JOIN dbo.PU_ArrivalVouch c ON a.ID=c.ID where a.Autoid='" + body.DNDetailID + @"'
  242. EXEC ICSProcedureUpdatePricePOToPUArrivalVouchs @ID= @ID1";
  243. cmd.Parameters.Clear();
  244. cmd.Parameters.Add(new SqlParameter("@Autoid", iChildId));
  245. cmd.Parameters.Add(new SqlParameter("@ID1", iFatherId));
  246. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  247. cmd.Parameters.Add(new SqlParameter("@iQuantity", -body.Quantity));
  248. cmd.Parameters.Add(new SqlParameter("@ivouchrowno", body.Sequence));
  249. cmd.Parameters.Add(new SqlParameter("@Batch", body.BatchCode));
  250. cmd.Parameters.Add(new SqlParameter("@cItemCode", body.ProjectCode));
  251. cmd.Parameters.Add(new SqlParameter("@cDefine37", DateTime.Now.Date.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddSeconds(-1)));
  252. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  253. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  254. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  255. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  256. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  257. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  258. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  259. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  260. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  261. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  262. cmd.CommandText = sql;
  263. try
  264. {
  265. int count = cmd.ExecuteNonQuery();
  266. if (count <= 0)
  267. {
  268. log.Error("生成采购拒收单表体失败,受影响行数<=0;");
  269. throw new Exception("生成采购拒收单表体失败,受影响行数<=0;");
  270. }
  271. }
  272. catch (Exception ex)
  273. {
  274. log.Error("生成采购拒收单表体失败!采购到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  275. throw new Exception("生成采购拒收单表体失败!采购到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  276. }
  277. sql = string.Format(@"update pd set pd.fPoRefuseQuantity = isnull(pd.fPoRefuseQuantity,0)+{0}
  278. from dbo.PU_ArrivalVouchs a LEFT JOIN dbo.PO_Podetails pd ON a.iPOsID= pd.ID
  279. INNER JOIN dbo.PO_Pomain b ON pd.POID=b.POID
  280. INNER JOIN dbo.PU_ArrivalVouch c ON a.ID=c.ID where a.Autoid='" + body.DNDetailID + "' ", body.Quantity);
  281. cmd.CommandText = sql;
  282. cmd.ExecuteNonQuery();
  283. iChildId -= 1;
  284. }
  285. #endregion
  286. #region 查询
  287. sql = @"select DISTINCT a.ID as ID,a.ID as IDs,a.cCode as RJTCode,a.cVenCode VenCode,d.cVenName VenName,a.cDepCode DepCode,c.cDepName DepName
  288. ,b.carrivalcode as DNCode ,a.cMaker as CreateUser ,a.cMakeTime as CreateDateTime
  289. ,a.cverifier as Checker ,a.caudittime as CheckDateTime
  290. from PU_ArrivalVouch a
  291. left join PU_ArrivalVouchs b on a.ID=b.ID
  292. left join Department c on a.cDepCode=c.cDepCode
  293. left join Vendor d on a.cVenCode=d.cVenCode
  294. WHERE A.cverifier IS NOT NULL AND A.ID in({0})
  295. select DISTINCT a.ID as IDs, b.AutoID as DetailID,b.ivouchrowno as Sequence ,b.cInvCode as InvCode ,
  296. b.iQuantity as Quantity ,b.iNum as Amount,a.cexch_name Currency,iOriCost UnitPrice,b.iCorId as DNDetailID
  297. ,isnull(b.cItemCode,'') ProjectCode,
  298. isnull(b.cbatch,'') cBatch,
  299. '' version ,'' brand,
  300. isnull(b.cFree1,'') as cFree1,
  301. isnull(b.cFree2,'') as cFree2,
  302. isnull(b.cFree3,'') as cFree3,
  303. isnull(b.cFree4,'') as cFree4,
  304. isnull(b.cFree5,'') as cFree5,
  305. isnull(b.cFree6,'') as cFree6,
  306. isnull(b.cFree7,'') as cFree7,
  307. isnull(b.cFree8,'') as cFree8,
  308. isnull(b.cFree9,'') as cFree9,
  309. isnull(b.cFree10,'') as cFree10
  310. from PU_ArrivalVouch a
  311. left join PU_ArrivalVouchs b on a.ID=b.ID
  312. WHERE A.cverifier IS NOT NULL AND A.ID in({0}) ";
  313. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  314. if (ds != null)
  315. ds.Merge(DBHelper.SQlReturnDataSet(sql, cmd));
  316. else
  317. ds = DBHelper.SQlReturnDataSet(sql, cmd);
  318. #endregion
  319. }
  320. }
  321. cmd.Transaction.Commit();
  322. }
  323. catch (Exception ex)
  324. {
  325. if (cmd.Transaction != null)
  326. cmd.Transaction.Rollback();
  327. log.Error(ex.Message);
  328. throw new Exception(ex.Message);
  329. }
  330. finally
  331. {
  332. if (conn.State == ConnectionState.Open)
  333. {
  334. conn.Close();
  335. }
  336. conn.Dispose();
  337. }
  338. }
  339. szJson = JSON.DataSetToJson(ds, "details", "IDs");
  340. return szJson;
  341. }
  342. /// <summary>
  343. /// 回写委外拒收单
  344. /// </summary>
  345. /// <param name="cmd"></param>
  346. /// <param name="Lotnos"></param>
  347. /// <param name="info"></param>
  348. public string CreateWPUArrive(List<ICSOPUArrivalVouch> Bills)
  349. {
  350. string msg = "";
  351. string szJson = "";
  352. DataSet ds = null;
  353. string iFatherIdTwo = "";
  354. int num = 0;
  355. string connS = "";
  356. SqlConnection conn = new SqlConnection();
  357. SqlCommand cmd = new SqlCommand();
  358. if (Bills.Count <= 0)
  359. {
  360. throw new Exception("传送数据为空!");
  361. }
  362. bool isNG = false;
  363. LogInfo(Bills);
  364. List<string> result = Bills.Select(t => t.WorkPoint).Distinct().ToList();
  365. foreach (string WorkPoint in result)
  366. {
  367. try
  368. {
  369. connS = string.Format(connString, WorkPoint);
  370. conn = new System.Data.SqlClient.SqlConnection(connS);
  371. conn.Open();
  372. SqlTransaction sqlTran = conn.BeginTransaction();
  373. cmd = new SqlCommand();
  374. cmd.Transaction = sqlTran;
  375. cmd.Connection = conn;
  376. foreach (ICSOPUArrivalVouch head in Bills)
  377. {
  378. foreach (ICSOPUArrivalVouchs body in head.Vouchs)
  379. {
  380. if (body.Quantity > 0)
  381. {
  382. isNG = true;
  383. }
  384. }
  385. }
  386. if (isNG)
  387. {
  388. int sum = 0;
  389. foreach (ICSOPUArrivalVouch head in Bills)
  390. {
  391. iFatherIdTwo = "";
  392. if (WorkPoint != head.WorkPoint)
  393. {
  394. continue;
  395. }
  396. ICSUserInfo userInfo = new ICSUserInfo();
  397. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  398. string[] ss = head.WorkPoint.Split('_');
  399. ERPDB = ss[1];
  400. string sql = "";
  401. VouchKey key = new VouchKey();
  402. //取得out库单的默认显示模版
  403. string[] dd = CRNALL.Split('~');
  404. string crdname = dd[0];
  405. string carname = dd[1];
  406. string surface = dd[2];
  407. num = head.Vouchs.Count();
  408. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  409. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint, cmd);
  410. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  411. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  412. DateTime date = DateTime.Now;
  413. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", "", head.WorkPoint, cmd);
  414. #region 主表
  415. sql = @"INSERT INTO PU_ArrivalVouch
  416. (iVTid, ID, cCode, cPTCode, dDate, cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, cBusType, cMaker, bNegative,
  417. iDiscountTaxType, iBillType, cMakeTime, cAuditDate, caudittime, cverifier, iverifystateex, IsWfControlled, iflowid, iPrintCount, cpocode)
  418. SELECT @iVTid, @ID, @cCode, cPTCode, CONVERT(NVARCHAR(10), GETDATE(), 23), cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, '', @User, 1,
  419. iDiscountTaxType, 2, GETDATE(), CONVERT(NVARCHAR(10), GETDATE(), 23), GETDATE(), @User, 2, 0, 0, iPrintCount, null
  420. FROM PU_ArrivalVouch WHERE 1=1 AND cCode = @headID ";
  421. cmd.Parameters.Clear();
  422. cmd.Parameters.Add(new SqlParameter("@iVTid", iChildId));
  423. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  424. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  425. cmd.Parameters.Add(new SqlParameter("@User", userInfo.UserName));
  426. cmd.Parameters.Add(new SqlParameter("@headID", head.ODNCode));
  427. cmd.CommandText = sql;
  428. try
  429. {
  430. int count = cmd.ExecuteNonQuery();
  431. if (count <= 0)
  432. {
  433. log.Error("生成委外拒收单表头失败,受影响行数<=0;");
  434. throw new Exception("生成委外拒收单表头失败,受影响行数<=0;");
  435. }
  436. }
  437. catch (Exception ex)
  438. {
  439. log.Error("生成委外拒收单表头失败!到货单:" + head.ODNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  440. throw new Exception("生成委外拒收单表头失败!到货单:" + head.ODNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  441. }
  442. #endregion
  443. iFatherIdTwo = "'" + iFatherId + "',";
  444. #region 表体
  445. foreach (ICSOPUArrivalVouchs body in head.Vouchs)
  446. {
  447. iChildId -= 1;
  448. sql = @"INSERT INTO PU_ArrivalVouchs
  449. (Autoid, ID, cInvCode, iQuantity, iOriCost, iOriTaxCost, iOriMoney, iOriTaxPrice, iOriSum, iCost, iMoney, iTaxPrice, iSum, iTaxRate,
  450. iPOsID, fValidInQuan, fRealQuantity, fValidQuantity, fRetQuantity, fInValidInQuan, bGsp, fValidNum, fValidInNum, fRealNum, bTaxCost,
  451. SoType, fInvalidInNum, iinvexchrate, cordercode, RejectSource, iExpiratDateCalcu, iordertype, ivouchrowno, bgift,
  452. cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,cItemCode,
  453. cBatch, cDefine37, fKPQuantity, finValidQuantity, fRefuseQuantity, iProductType,bexigency,inum,iCorId,carrivalcode )
  454. SELECT top 1 @Autoid, @ID1, @cInvCode, @iQuantity,pd.iUnitPrice,pd.iTaxPrice,round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),
  455. 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),
  456. round(round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2)*b.nflat,2),
  457. 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,
  458. pd.MODetailsID, 0, @iQuantity, @iQuantity, 0, 0, 0, null, null, null, 1,
  459. 0, null, 0, b.ccode, 0, 0, 0, @ivouchrowno, 0,
  460. @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8, @cFree9, @cFree10,@cItemCode,
  461. @Batch, @cDefine37, null, null, null, null, null,0,a.Autoid,c.cCode
  462. from dbo.PU_ArrivalVouchs a
  463. LEFT JOIN dbo.OM_MODetails pd ON a.iPOsID = pd.MODetailsID
  464. left JOIN dbo.OM_MOMain b ON pd.MOID = b.MOID
  465. left JOIN dbo.PU_ArrivalVouch c ON a.ID=c.ID where a.Autoid='" + body.ODNDetailID + @"'
  466. EXEC ICSProcedureUpdatePriceOMToPUArrivalVouchs @ID= @ID1
  467. ";
  468. cmd.Parameters.Clear();
  469. cmd.Parameters.Add(new SqlParameter("@Autoid", iChildId));
  470. cmd.Parameters.Add(new SqlParameter("@ID1", iFatherId));
  471. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  472. cmd.Parameters.Add(new SqlParameter("@iQuantity", -body.Quantity));
  473. cmd.Parameters.Add(new SqlParameter("@ivouchrowno", body.Sequence));
  474. cmd.Parameters.Add(new SqlParameter("@Batch", body.BatchCode));
  475. cmd.Parameters.Add(new SqlParameter("@cItemCode", body.ProjectCode));
  476. cmd.Parameters.Add(new SqlParameter("@cDefine37", DateTime.Now.Date.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddSeconds(-1)));
  477. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  478. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  479. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  480. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  481. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  482. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  483. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  484. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  485. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  486. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  487. cmd.CommandText = sql;
  488. try
  489. {
  490. int count = cmd.ExecuteNonQuery();
  491. if (count <= 0)
  492. {
  493. log.Error("生成委外拒收单表体失败,受影响行数<=0;");
  494. throw new Exception("生成委外拒收单表体失败,受影响行数<=0;");
  495. }
  496. }
  497. catch (Exception ex)
  498. {
  499. log.Error("生成委外拒收单表体失败!委外到货单:" + head.ODNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  500. throw new Exception("生成委外拒收单表体失败!委外到货单:" + head.ODNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  501. }
  502. sql = string.Format(@"update pd set pd.fPoRefuseQuantity = isnull(pd.fPoRefuseQuantity,0)+{0}
  503. from dbo.PU_ArrivalVouchs a LEFT JOIN dbo.PO_Podetails pd ON a.iPOsID= pd.ID
  504. where a.Autoid='" + body.ODNDetailID + "' ", body.Quantity);
  505. cmd.CommandText = sql;
  506. cmd.ExecuteNonQuery();
  507. }
  508. #endregion
  509. #region 查询
  510. sql = @"select DISTINCT a.ID as ID,a.ID as IDs,a.cCode as RJTCode,a.cVenCode VenCode,d.cVenName VenName,a.cDepCode DepCode,c.cDepName DepName
  511. ,b.carrivalcode as DNCode ,a.cMaker as CreateUser ,a.cMakeTime as CreateDateTime
  512. ,a.cverifier as Checker ,a.caudittime as CheckDateTime
  513. from PU_ArrivalVouch a
  514. left join PU_ArrivalVouchs b on a.ID=b.ID
  515. left join Department c on a.cDepCode=c.cDepCode
  516. left join Vendor d on a.cVenCode=d.cVenCode
  517. WHERE A.cverifier IS NOT NULL AND A.ID in({0})
  518. select DISTINCT a.ID as IDs, b.AutoID as DetailID,b.ivouchrowno as Sequence ,b.cInvCode as InvCode ,
  519. b.iQuantity as Quantity ,b.iNum as Amount,a.cexch_name Currency,iOriCost UnitPrice,b.iCorId as DNDetailID
  520. ,isnull(b.cItemCode,'') ProjectCode,
  521. isnull(b.cbatch,'') cBatch,
  522. '' version ,'' brand,
  523. isnull(b.cFree1,'') as cFree1,
  524. isnull(b.cFree2,'') as cFree2,
  525. isnull(b.cFree3,'') as cFree3,
  526. isnull(b.cFree4,'') as cFree4,
  527. isnull(b.cFree5,'') as cFree5,
  528. isnull(b.cFree6,'') as cFree6,
  529. isnull(b.cFree7,'') as cFree7,
  530. isnull(b.cFree8,'') as cFree8,
  531. isnull(b.cFree9,'') as cFree9,
  532. isnull(b.cFree10,'') as cFree10
  533. from PU_ArrivalVouch a
  534. left join PU_ArrivalVouchs b on a.ID=b.ID
  535. WHERE A.cverifier IS NOT NULL AND A.ID in({0}) ";
  536. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  537. if (ds != null)
  538. ds.Merge(DBHelper.SQlReturnDataSet(sql, cmd));
  539. else
  540. ds = DBHelper.SQlReturnDataSet(sql, cmd);
  541. #endregion
  542. }
  543. }
  544. cmd.Transaction.Commit();
  545. }
  546. catch (Exception ex)
  547. {
  548. if (cmd.Transaction != null)
  549. cmd.Transaction.Rollback();
  550. log.Error(ex.Message);
  551. throw new Exception(ex.Message);
  552. }
  553. finally
  554. {
  555. if (conn.State == ConnectionState.Open)
  556. {
  557. conn.Close();
  558. }
  559. conn.Dispose();
  560. }
  561. }
  562. szJson = JSON.DataSetToJson(ds, "details", "IDs");
  563. return szJson;
  564. }
  565. public string Approve(List<ICSPUArrivalVouch> infos)
  566. {
  567. List<ICSPUArrivalVouch> szJson = new List<ICSPUArrivalVouch>();
  568. DataTable dt = null;
  569. DataTable dtNew = null;
  570. string connS = "";
  571. string json = "";
  572. if (infos.Count <= 0)
  573. {
  574. throw new Exception("传送数据为空!");
  575. }
  576. string res = string.Empty;
  577. SqlConnection conn = new SqlConnection();
  578. SqlCommand cmd = new SqlCommand();
  579. string sql = string.Empty;
  580. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  581. foreach (string WorkPoint in result)
  582. {
  583. try
  584. {
  585. connS = string.Format(connString, WorkPoint);
  586. conn = new System.Data.SqlClient.SqlConnection(connS);
  587. conn.Open();
  588. SqlTransaction sqlTran = conn.BeginTransaction();
  589. cmd = new SqlCommand();
  590. cmd.Transaction = sqlTran;
  591. cmd.Connection = conn;
  592. foreach (ICSPUArrivalVouch info in infos)
  593. {
  594. if (WorkPoint != info.WorkPoint)
  595. {
  596. continue;
  597. }
  598. ICSUserInfo userInfo = new ICSUserInfo();
  599. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  600. if (info.MTime < new DateTime(2000, 01, 01))
  601. throw new Exception("请输入正确的操作时间:" + info.MTime);
  602. sql = @"UPDATE PU_ArrivalVouch SET cVerifier ='" + userInfo.UserName + @"' ,
  603. cAuditTime=CONVERT(VARCHAR(50),GETDATE(),112),cAuditDate=GETDATE() WHERE ID='{0}'";
  604. sql = string.Format(sql, info.ID);
  605. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  606. }
  607. cmd.Transaction.Commit();
  608. }
  609. catch (Exception ex)
  610. {
  611. if (cmd.Transaction != null)
  612. cmd.Transaction.Rollback();
  613. log.Error(ex.Message);
  614. throw new Exception(ex.Message);
  615. }
  616. finally
  617. {
  618. if (conn.State == ConnectionState.Open)
  619. {
  620. conn.Close();
  621. }
  622. conn.Dispose();
  623. }
  624. }
  625. return json;
  626. }
  627. /// <summary>
  628. /// 删除请购单
  629. /// </summary>
  630. /// <param name="infos"></param>
  631. /// <returns></returns>
  632. public string Delete(List<ICSPUArrivalVouch> infos)
  633. {
  634. List<ICSPUArrivalVouch> szJson = new List<ICSPUArrivalVouch>();
  635. if (infos.Count <= 0)
  636. {
  637. throw new Exception("传送数据为空!");
  638. }
  639. string res = string.Empty;
  640. DataTable dtNew = null;
  641. string connS = "";
  642. SqlConnection conn = new SqlConnection();
  643. SqlCommand cmd = new SqlCommand();
  644. string sql = string.Empty;
  645. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  646. foreach (string WorkPoint in result)
  647. {
  648. try
  649. {
  650. connS = string.Format(connString, WorkPoint);
  651. conn = new System.Data.SqlClient.SqlConnection(connS);
  652. conn.Open();
  653. SqlTransaction sqlTran = conn.BeginTransaction();
  654. cmd = new SqlCommand();
  655. cmd.Transaction = sqlTran;
  656. cmd.Connection = conn;
  657. foreach (ICSPUArrivalVouch info in infos)
  658. {
  659. if (WorkPoint != info.WorkPoint)
  660. {
  661. continue;
  662. }
  663. if (info.MTime < new DateTime(2000, 01, 01))
  664. throw new Exception("请输入正确的操作时间:" + info.MTime);
  665. sql = @" DELETE PU_AppVouch WHERE ID={0}";
  666. sql = string.Format(sql, info.ID);
  667. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  668. }
  669. cmd.Transaction.Commit();
  670. }
  671. catch (Exception ex)
  672. {
  673. if (cmd.Transaction != null)
  674. cmd.Transaction.Rollback();
  675. log.Error(ex.Message);
  676. throw new Exception(ex.Message);
  677. }
  678. finally
  679. {
  680. if (conn.State == ConnectionState.Open)
  681. {
  682. conn.Close();
  683. }
  684. conn.Dispose();
  685. }
  686. }
  687. return res;
  688. }
  689. /// <summary>
  690. ///
  691. /// 记录日志
  692. /// </summary>
  693. /// <param name="Bills"></param>
  694. private void LogInfo(List<ICSPUArrivalVouch> Bills)
  695. {
  696. string HeadList = string.Empty;
  697. string BodyList = string.Empty;
  698. foreach (ICSPUArrivalVouch head in Bills)
  699. {
  700. HeadList += "\r\n 表头主键ID:" + head.ID + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  701. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  702. {
  703. BodyList += "\r\n 表体主键ID: " + body.DNDetailID + ",数量:" + body.Quantity;
  704. }
  705. }
  706. log.Info(HeadList);
  707. log.Info(BodyList);
  708. }
  709. /// <summary>
  710. ///
  711. /// 记录日志
  712. /// </summary>
  713. /// <param name="Bills"></param>
  714. private void LogInfo(List<ICSOPUArrivalVouch> Bills)
  715. {
  716. string HeadList = string.Empty;
  717. string BodyList = string.Empty;
  718. foreach (ICSOPUArrivalVouch head in Bills)
  719. {
  720. HeadList += "\r\n 表头主键ID:" + head.ID + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  721. foreach (ICSOPUArrivalVouchs body in head.Vouchs)
  722. {
  723. BodyList += "\r\n 表体主键ID: " + body.ODNDetailID + ",数量:" + body.Quantity;
  724. }
  725. }
  726. log.Info(HeadList);
  727. log.Info(BodyList);
  728. }
  729. }
  730. }