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.

153 lines
7.6 KiB

6 months ago
  1. using ICSSoft.ERPWMS.Entity;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace ICSSoft.ERPWMS.SQL
  9. {
  10. public class GetPurchaseReturnInfo
  11. {
  12. public static Result Get(GetPurchaseReturnCondition condition)
  13. {
  14. Result res = new Result();
  15. try
  16. {
  17. if (condition.PageIndex == null)
  18. {
  19. throw new Exception("页码未传!");
  20. }
  21. if (condition.PageSize == null)
  22. {
  23. throw new Exception("每页数量未传!");
  24. }
  25. if (string.IsNullOrWhiteSpace(condition.WorkPoint))
  26. {
  27. res.IsSuccess = false;
  28. res.Message = "站点参数为空!";
  29. return res;
  30. }
  31. string WorkPoint = ICSHelper.GetConnectStringTest(condition.WorkPoint);
  32. if (WorkPoint == "NotExit")
  33. {
  34. throw new Exception("站点编码不存在!");
  35. }
  36. string sql = @"select a.ID,a.cCode as '退货单号',b.ivouchrowno as '退货单行号',b.cInvCode as '物料编码',-b.iQuantity as '退货数量',
  37. d.cPOID as '',c.ivouchrowno as '',e.cPsn_Num as '',isnull(isnull(isnull(a.cReviser,a.cchanger),a.cverifier),a.cMaker) as '',
  38. isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) as ''
  39. from {0}.dbo.PU_ArrivalVouch a
  40. left join {0}.dbo.PU_ArrivalVouchs b on a.ID = b.ID
  41. left join {0}.dbo.PO_Podetails c on b.iPOsID = c.ID
  42. left join {0}.dbo.PO_Pomain d on c.POID = d.POID
  43. left join {0}.dbo.hr_hi_person e on isnull(isnull(isnull(a.cReviser,a.cchanger),a.cverifier),a.cMaker) = e.cPsn_Name
  44. where a.iBillType ='1' and a.cBusType =''";
  45. string sql2 = @"select a.ID,a.cCode as '退货单号',b.ivouchrowno as '退货单行号',b.cInvCode as '物料编码',-b.iQuantity as '退货数量',
  46. d.cCode as '',c.ivouchrowno as '',e.cPsn_Num as '',isnull(isnull(isnull(a.cReviser,a.cchanger),a.cverifier),a.cMaker) as '',
  47. isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) as ''
  48. from {0}.dbo.PU_ArrivalVouch a
  49. left join {0}.dbo.PU_ArrivalVouchs b on a.ID = b.ID
  50. left join {0}.dbo.OM_MODetails c on b.iPOsID = c.MODetailsID
  51. left join {0}.dbo.OM_MOMain d on c.MOID = d.MOID
  52. left join {0}.dbo.hr_hi_person e on isnull(isnull(isnull(a.cReviser,a.cchanger),a.cverifier),a.cMaker) = e.cPsn_Name
  53. where a.iBillType ='1' and a.cBusType =''";
  54. sql = string.Format(sql, WorkPoint);
  55. sql2 = string.Format(sql2, WorkPoint);
  56. if (condition.dModifyDateFrom != null)
  57. {
  58. sql += " and isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) >= '{0}'";
  59. sql = string.Format(sql, condition.dModifyDateFrom);
  60. sql2 += " and isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) >= '{0}'";
  61. sql2 = string.Format(sql2, condition.dModifyDateFrom);
  62. }
  63. if (condition.dModifyDateTo != null)
  64. {
  65. sql += " and isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) <= '{0}'";
  66. sql = string.Format(sql, condition.dModifyDateTo);
  67. sql2 += " and isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) <= '{0}'";
  68. sql2 = string.Format(sql2, condition.dModifyDateTo);
  69. }
  70. if (condition.VendorCode != null)
  71. {
  72. sql += " and a.cVenCode like '%{0}%'";
  73. sql = string.Format(sql, condition.VendorCode);
  74. sql2 += " and a.cVenCode like '%{0}%'";
  75. sql2 = string.Format(sql2, condition.VendorCode);
  76. }
  77. if(condition.PO != null)
  78. {
  79. sql += " and d.cPOID like '%{0}%'";
  80. sql = string.Format(sql, condition.PO);
  81. sql2 += " and d.cCode like '%{0}%'";
  82. sql2 = string.Format(sql2, condition.PO);
  83. }
  84. sql = sql + " Union All " + sql2;
  85. string sqlNew = @" select * from (select aa.*,rn=ROW_NUMBER() over(order by ID) from( ";
  86. sqlNew += sql;
  87. sqlNew += ") aa)bb where bb.rn between {0} and {1} ";
  88. sqlNew = string.Format(sqlNew, (condition.PageIndex - 1) * condition.PageSize + 1, condition.PageIndex * condition.PageSize);
  89. DataTable dt = ICSHelper.GetDataTableERP(sqlNew);
  90. List<GetPurchaseReturnEntity> entityList = new List<GetPurchaseReturnEntity>();
  91. if (dt != null && dt.Rows.Count > 0)
  92. {
  93. foreach (DataRow dr in dt.Rows)
  94. {
  95. GetPurchaseReturnEntity entity = new GetPurchaseReturnEntity();
  96. entity.ID = dr["ID"].ToString();
  97. entity.ReturnCode = dr["退货单号"].ToString();
  98. entity.ReturnLine = string.IsNullOrWhiteSpace(dr["退货单行号"].ToString()) ? 1 : Convert.ToInt32(dr["退货单行号"].ToString());
  99. entity.InvCode = dr["物料编码"].ToString();
  100. entity.Quantity = string.IsNullOrWhiteSpace(dr["退货数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["退货数量"].ToString());
  101. entity.PO = dr["采购订单"].ToString();
  102. entity.POLine = string.IsNullOrWhiteSpace(dr["采购订单行号"].ToString()) ? 1 : Convert.ToInt32(dr["采购订单行号"].ToString());
  103. //entity.TransType = "3";
  104. //entity.BusinessCode = "2";
  105. entity.MUSER = dr["操作人"].ToString();
  106. entity.MUSERName = dr["操作人名称"].ToString();
  107. if (string.IsNullOrWhiteSpace(dr["操作时间"].ToString()))
  108. {
  109. entity.dModifyDate = null;
  110. }
  111. else
  112. {
  113. entity.dModifyDate = Convert.ToDateTime(dr["操作时间"].ToString());
  114. }
  115. entity.WorkPoint = WorkPoint;
  116. entityList.Add(entity);
  117. }
  118. res.IsSuccess = true;
  119. res.Message = "执行成功!";
  120. res.data = entityList;
  121. return res;
  122. }
  123. else
  124. {
  125. res.IsSuccess = true;
  126. res.Message = "查询无数据!";
  127. res.data = entityList;
  128. return res;
  129. }
  130. }
  131. catch (Exception ex)
  132. {
  133. res.IsSuccess = false;
  134. res.Message = ex.Message;
  135. return res;
  136. }
  137. }
  138. }
  139. }