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

using ICSSoft.ERPWMS.Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ICSSoft.ERPWMS.SQL
{
public class GetPurchaseReturnInfo
{
public static Result Get(GetPurchaseReturnCondition condition)
{
Result res = new Result();
try
{
if (condition.PageIndex == null)
{
throw new Exception("页码未传!");
}
if (condition.PageSize == null)
{
throw new Exception("每页数量未传!");
}
if (string.IsNullOrWhiteSpace(condition.WorkPoint))
{
res.IsSuccess = false;
res.Message = "站点参数为空!";
return res;
}
string WorkPoint = ICSHelper.GetConnectStringTest(condition.WorkPoint);
if (WorkPoint == "NotExit")
{
throw new Exception("站点编码不存在!");
}
string sql = @"select a.ID,a.cCode as '退货单号',b.ivouchrowno as '退货单行号',b.cInvCode as '物料编码',-b.iQuantity as '退货数量',
d.cPOID as '采购订单',c.ivouchrowno as '采购订单行号',e.cPsn_Num as '操作人',isnull(isnull(isnull(a.cReviser,a.cchanger),a.cverifier),a.cMaker) as '操作人名称',
isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) as '操作时间'
from {0}.dbo.PU_ArrivalVouch a
left join {0}.dbo.PU_ArrivalVouchs b on a.ID = b.ID
left join {0}.dbo.PO_Podetails c on b.iPOsID = c.ID
left join {0}.dbo.PO_Pomain d on c.POID = d.POID
left join {0}.dbo.hr_hi_person e on isnull(isnull(isnull(a.cReviser,a.cchanger),a.cverifier),a.cMaker) = e.cPsn_Name
where a.iBillType ='1' and a.cBusType ='普通采购'";
string sql2 = @"select a.ID,a.cCode as '退货单号',b.ivouchrowno as '退货单行号',b.cInvCode as '物料编码',-b.iQuantity as '退货数量',
d.cCode as '采购订单',c.ivouchrowno as '采购订单行号',e.cPsn_Num as '操作人',isnull(isnull(isnull(a.cReviser,a.cchanger),a.cverifier),a.cMaker) as '操作人名称',
isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) as '操作时间'
from {0}.dbo.PU_ArrivalVouch a
left join {0}.dbo.PU_ArrivalVouchs b on a.ID = b.ID
left join {0}.dbo.OM_MODetails c on b.iPOsID = c.MODetailsID
left join {0}.dbo.OM_MOMain d on c.MOID = d.MOID
left join {0}.dbo.hr_hi_person e on isnull(isnull(isnull(a.cReviser,a.cchanger),a.cverifier),a.cMaker) = e.cPsn_Name
where a.iBillType ='1' and a.cBusType ='委外加工'";
sql = string.Format(sql, WorkPoint);
sql2 = string.Format(sql2, WorkPoint);
if (condition.dModifyDateFrom != null)
{
sql += " and isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) >= '{0}'";
sql = string.Format(sql, condition.dModifyDateFrom);
sql2 += " and isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) >= '{0}'";
sql2 = string.Format(sql2, condition.dModifyDateFrom);
}
if (condition.dModifyDateTo != null)
{
sql += " and isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) <= '{0}'";
sql = string.Format(sql, condition.dModifyDateTo);
sql2 += " and isnull(isnull(a.cModifyTime,a.caudittime),a.cMakeTime) <= '{0}'";
sql2 = string.Format(sql2, condition.dModifyDateTo);
}
if (condition.VendorCode != null)
{
sql += " and a.cVenCode like '%{0}%'";
sql = string.Format(sql, condition.VendorCode);
sql2 += " and a.cVenCode like '%{0}%'";
sql2 = string.Format(sql2, condition.VendorCode);
}
if(condition.PO != null)
{
sql += " and d.cPOID like '%{0}%'";
sql = string.Format(sql, condition.PO);
sql2 += " and d.cCode like '%{0}%'";
sql2 = string.Format(sql2, condition.PO);
}
sql = sql + " Union All " + sql2;
string sqlNew = @" select * from (select aa.*,rn=ROW_NUMBER() over(order by ID) from( ";
sqlNew += sql;
sqlNew += ") aa)bb where bb.rn between {0} and {1} ";
sqlNew = string.Format(sqlNew, (condition.PageIndex - 1) * condition.PageSize + 1, condition.PageIndex * condition.PageSize);
DataTable dt = ICSHelper.GetDataTableERP(sqlNew);
List<GetPurchaseReturnEntity> entityList = new List<GetPurchaseReturnEntity>();
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
GetPurchaseReturnEntity entity = new GetPurchaseReturnEntity();
entity.ID = dr["ID"].ToString();
entity.ReturnCode = dr["退货单号"].ToString();
entity.ReturnLine = string.IsNullOrWhiteSpace(dr["退货单行号"].ToString()) ? 1 : Convert.ToInt32(dr["退货单行号"].ToString());
entity.InvCode = dr["物料编码"].ToString();
entity.Quantity = string.IsNullOrWhiteSpace(dr["退货数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["退货数量"].ToString());
entity.PO = dr["采购订单"].ToString();
entity.POLine = string.IsNullOrWhiteSpace(dr["采购订单行号"].ToString()) ? 1 : Convert.ToInt32(dr["采购订单行号"].ToString());
//entity.TransType = "3";
//entity.BusinessCode = "2";
entity.MUSER = dr["操作人"].ToString();
entity.MUSERName = dr["操作人名称"].ToString();
if (string.IsNullOrWhiteSpace(dr["操作时间"].ToString()))
{
entity.dModifyDate = null;
}
else
{
entity.dModifyDate = Convert.ToDateTime(dr["操作时间"].ToString());
}
entity.WorkPoint = WorkPoint;
entityList.Add(entity);
}
res.IsSuccess = true;
res.Message = "执行成功!";
res.data = entityList;
return res;
}
else
{
res.IsSuccess = true;
res.Message = "查询无数据!";
res.data = entityList;
return res;
}
}
catch (Exception ex)
{
res.IsSuccess = false;
res.Message = ex.Message;
return res;
}
}
}
}