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.

231 lines
28 KiB

6 months ago
  1. using ICSSoft.ERPWMS.Entity;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace ICSSoft.ERPWMS.SQL
  11. {
  12. public class GetPOInfo
  13. {
  14. public static Result Get(POCondition condition)
  15. {
  16. Result res = new Result();
  17. try
  18. {
  19. if (condition.PageIndex ==null)
  20. {
  21. throw new Exception("页码未传!");
  22. }
  23. if (condition.PageSize == null)
  24. {
  25. throw new Exception("每页数量未传!");
  26. }
  27. if (string.IsNullOrWhiteSpace(condition.WorkPoint))
  28. {
  29. throw new Exception("站点未传!");
  30. }
  31. string WorkPoint = ICSHelper.GetConnectStringTest(condition.WorkPoint);
  32. if (WorkPoint == "NotExit")
  33. {
  34. throw new Exception("站点编码不存在!");
  35. }
  36. string sql = @"select a.cPOID as '采购订单号',b.ivouchrowno as '采购订单行号',a.cVenCode as '供应商代码',a.cDepCode as '部门代码',a.cPersonCode as '业务员代码',
  37. '' as '',b.cInvCode as '',b.iQuantity as '',b.iNum as '',b.iUnitPrice as '',b.cFree1 '',
  38. b.iMoney as '',b.iTaxPrice as '',b.iPerTaxRate as '',b.iTax as '',b.iSum as '',
  39. a.cexch_name as '',a.nflat as '',a.iverifystateex as '',b.dArriveDate as '',a.cMemo as '',b.cbMemo as '',
  40. a.cMaker as '',a.cmaketime as '',a.dCloseDate as '',a.cChanger as '',
  41. case when a.cChangAuditTime >=(case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  42. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)
  43. then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  44. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) then a.cChangAuditTime
  45. else (case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  46. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)
  47. then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  48. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) end as '',
  49. case when b.iArrQTY is null then isnull(b.iReceivedQTY,0) when cast(b.iArrQTY as int)=0 then isnull(b.iReceivedQTY,0) else b.iArrQTY end as '',
  50. b.cbCloser as '',xx.chdefine31 '',xx.chdefine32 ''
  51. from {0}.dbo.PO_Pomain a
  52. left join {0}.dbo.PO_Podetails b on a.POID = b.POID
  53. LEFT JOIN {0}.dbo.ICSPoModifyTimeRecord hh on a.POID = hh.POID
  54. left join {0}.dbo.po_pomain_extradefine xx on a.poid = xx.poid
  55. left join (select PO_Pomain.cPOID as 'cpocode',MAX(PU_ArrivalVouch.cMakeTime) as 'cMakeTime' from {0}.dbo.PU_ArrivalVouch left join {0}.dbo.PU_ArrivalVouchs on PU_ArrivalVouch.id = PU_ArrivalVouchs.ID
  56. left join {0}.dbo.PO_Podetails on PO_Podetails.ID = PU_ArrivalVouchs.iPOsID
  57. left join {0}.dbo.PO_Pomain on PO_Pomain.POID = PO_Podetails.POID
  58. group by PO_Pomain.cPOID) yy on a.cPOID = yy.cpocode
  59. where a.cVerifier is not null and a.cVerifier!=''";
  60. string sql2 = @"select c.cCode as '采购订单号',d.iVouchRowNo as '采购订单行号',c.cVenCode as '供应商代码',c.cDepCode as '部门代码',c.cPersonCode as '业务员代码',
  61. '' as '',d.cInvCode as '',d.iQuantity as '',d.iNum as '',d.iUnitPrice as '',d.cFree1 '',
  62. d.iMoney as '',d.iTaxPrice as '',d.iPerTaxRate as '',d.iTax as '',d.iSum as '',
  63. c.cexch_name as '',c.nflat as '',c.iVerifyStateNew as '',d.dArriveDate as '',yy.chdefine39 as '',d.cbMemo as '',
  64. c.cMaker as '',c.dCreateTime as '',c.dCloseDate as '',c.cChanger as '',
  65. case when c.dChangeVerifyTime >=(case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  66. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end)
  67. then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  68. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) then c.dChangeVerifyTime
  69. ELSE (case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  70. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end)
  71. then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  72. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) end as '',
  73. case when d.iArrQTY is null then isnull(d.iReceivedQTY,0) when cast(d.iArrQTY as int)=0 then isnull(d.iReceivedQTY,0) else d.iArrQTY end as '',
  74. d.cbCloser as '',yy.chdefine31 '',yy.chdefine32 ''
  75. from {0}.dbo.OM_MOMain c
  76. left join {0}.dbo.OM_MODetails d on c.MOID = d.MOID
  77. left join {0}.dbo.OM_MOMain_extradefine yy on c.MOID = yy.MOID
  78. left join (select OM_MOMain.cCode as 'cpocode',MAX(PU_ArrivalVouch.cMakeTime) as 'cMakeTime' from {0}.dbo.PU_ArrivalVouch left join {0}.dbo.PU_ArrivalVouchs on PU_ArrivalVouch.id = PU_ArrivalVouchs.ID
  79. left join {0}.dbo.OM_MODetails on OM_MODetails.MODetailsID = PU_ArrivalVouchs.iPOsID
  80. left join {0}.dbo.OM_MOMain on OM_MOMain.MOID = OM_MODetails.MOID
  81. group by OM_MOMain.cCode) xx on c.cCode = xx.cpocode
  82. where c.cVerifier is not null and c.cVerifier!=''";
  83. sql = string.Format(sql, WorkPoint);
  84. sql2 = string.Format(sql2, WorkPoint);
  85. if (condition.dModifyDateFrom != null)
  86. {
  87. sql += @" and (case when a.cChangAuditTime >=(case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  88. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)
  89. then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  90. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) then a.cChangAuditTime
  91. else (case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  92. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)
  93. then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  94. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) end) >= '{0}'";
  95. sql = string.Format(sql, condition.dModifyDateFrom);
  96. sql2 += @" and (case when c.dChangeVerifyTime >=(case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  97. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end)
  98. then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  99. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) then c.dChangeVerifyTime
  100. ELSE (case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  101. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end)
  102. then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  103. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) end) >= '{0}'";
  104. sql2 = string.Format(sql2, condition.dModifyDateFrom);
  105. }
  106. if (condition.dModifyDateTo != null)
  107. {
  108. sql += @" and (case when a.cChangAuditTime >=(case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  109. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)
  110. then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  111. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) then a.cChangAuditTime
  112. else (case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  113. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)
  114. then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end)
  115. then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) end) <= '{0}'";
  116. sql = string.Format(sql, condition.dModifyDateTo);
  117. sql2 += @" and (case when c.dChangeVerifyTime >=(case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  118. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end)
  119. then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  120. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) then c.dChangeVerifyTime
  121. ELSE (case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  122. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end)
  123. then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end)
  124. then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) end) <= '{0}'"; ;
  125. sql2 = string.Format(sql2, condition.dModifyDateTo);
  126. }
  127. if (condition.POCode != null)
  128. {
  129. sql += " and a.cPOID like '%{0}%'";
  130. sql = string.Format(sql, condition.POCode);
  131. sql2 += " and c.cCode like '%{0}%'";
  132. sql2 = string.Format(sql2, condition.POCode);
  133. }
  134. sql = sql + " Union All " + sql2;
  135. string sqlNew = @" select * from (select aa.*,rn=dense_rank() over(order by 采购订单号) from( ";
  136. sqlNew += sql;
  137. sqlNew += ") aa)bb where bb.rn between {0} and {1} ";
  138. sqlNew = string.Format(sqlNew, (condition.PageIndex - 1) * condition.PageSize + 1, condition.PageIndex * condition.PageSize);
  139. DataTable dt = ICSHelper.GetDataTableERP(sqlNew);
  140. List<POEntity> entityList = new List<POEntity>();
  141. if (dt != null && dt.Rows.Count > 0)
  142. {
  143. foreach (DataRow dr in dt.Rows)
  144. {
  145. POEntity entity = new POEntity();
  146. entity.POCode = dr["采购订单号"].ToString();
  147. entity.Sequence = string.IsNullOrWhiteSpace(dr["采购订单行号"].ToString()) ? 0 : Convert.ToInt32(dr["采购订单行号"].ToString());
  148. entity.VenCode = dr["供应商代码"].ToString();
  149. entity.DepCode = dr["部门代码"].ToString();
  150. entity.PersonCode = dr["业务员代码"].ToString();
  151. entity.POType = dr["采购类型名称"].ToString() == "标准" ? 1 : 2;
  152. entity.InvCode = dr["物料代码"].ToString();
  153. entity.Quantity = string.IsNullOrWhiteSpace(dr["数量"].ToString()) ? 0 : float.Parse(dr["数量"].ToString());
  154. entity.Amount = string.IsNullOrWhiteSpace(dr["辅计量数量"].ToString()) ? 0 : float.Parse(dr["辅计量数量"].ToString());
  155. entity.UnitPrice = string.IsNullOrWhiteSpace(dr["原币无税单价"].ToString()) ? 0 : float.Parse(dr["原币无税单价"].ToString());
  156. entity.iMoney = string.IsNullOrWhiteSpace(dr["原币无税金额"].ToString()) ? 0 : float.Parse(dr["原币无税金额"].ToString());
  157. entity.iTaxPrice = string.IsNullOrWhiteSpace(dr["原币含税单价"].ToString()) ? 0 : float.Parse(dr["原币含税单价"].ToString());
  158. entity.iPerTaxRate = string.IsNullOrWhiteSpace(dr["原币含税单价"].ToString()) ? 0 : float.Parse(dr["税率"].ToString());
  159. entity.iTax = string.IsNullOrWhiteSpace(dr["原币税额"].ToString()) ? 0 : float.Parse(dr["原币税额"].ToString());
  160. entity.iSum = string.IsNullOrWhiteSpace(dr["原币价税合计"].ToString()) ? 0 : float.Parse(dr["原币价税合计"].ToString());
  161. entity.Currency = dr["币种"].ToString();
  162. entity.nFlat = string.IsNullOrWhiteSpace(dr["汇率"].ToString()) ? 0 : float.Parse(dr["汇率"].ToString());
  163. entity.Status = string.IsNullOrWhiteSpace(dr["状态"].ToString()) ? 0 : Convert.ToInt32(dr["状态"].ToString());
  164. if (!string.IsNullOrWhiteSpace(dr["行关闭人"].ToString()))
  165. {
  166. entity.Status = 3;
  167. }
  168. entity.cMemo = dr["头备注"].ToString();
  169. entity.cbMemo = dr["行备注"].ToString();
  170. entity.CreatePerson = dr["创建人"].ToString();
  171. entity.CreateDateTime = dr["创建时间"].ToString();
  172. entity.cModifyPerson = dr["变更人"].ToString();
  173. if (string.IsNullOrWhiteSpace(dr["计划到货日期"].ToString()))
  174. {
  175. entity.dArriveDate = null;
  176. }
  177. else
  178. {
  179. entity.dArriveDate = Convert.ToDateTime(dr["计划到货日期"].ToString());
  180. }
  181. if (string.IsNullOrWhiteSpace(dr["停用日期"].ToString()))
  182. {
  183. entity.dEndDate = null;
  184. }
  185. else
  186. {
  187. entity.dEndDate = Convert.ToDateTime(dr["停用日期"].ToString());
  188. }
  189. if (string.IsNullOrWhiteSpace(dr["变更日期"].ToString()))
  190. {
  191. entity.dModifyDate = null;
  192. }
  193. else
  194. {
  195. entity.dModifyDate = Convert.ToDateTime(dr["变更日期"].ToString());
  196. }
  197. entity.iReceivedQTY = string.IsNullOrWhiteSpace(dr["到货数量"].ToString()) ? 0.00f : float.Parse(dr["到货数量"].ToString());
  198. entity.ShipAddress = dr["订单送货地址"].ToString();
  199. entity.AcceptAddress = dr["发票接收地址"].ToString();
  200. entity.InvVersion = dr["料品版本"].ToString();
  201. entityList.Add(entity);
  202. }
  203. res.IsSuccess = true;
  204. res.Message = "执行成功!";
  205. res.data = entityList;
  206. return res;
  207. }
  208. else
  209. {
  210. res.IsSuccess = true;
  211. res.Message = "查询无数据!";
  212. res.data = entityList;
  213. return res;
  214. }
  215. }
  216. catch (Exception ex)
  217. {
  218. res.IsSuccess = false;
  219. res.Message = ex.Message;
  220. return res;
  221. }
  222. }
  223. }
  224. }