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.

163 lines
8.9 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 GetPurchaseStockInInfo
{
public static Result Get(GetPurchaseStockInCondition 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.LotNo as '条码',b.ASNCode as '送货单号',b.Sequence as '送货单行号',c.DNCode as '到货单号',c.Sequence as '到货单行号',
n.POCode as '采购订单',n.Sequence as '采购订单行号',a.InvCode as '物料代码',a.Quantity as '入库数量',a.ToWarehouseCode as '入库仓库',
a.ToLocationCode as '入库库位',a.ERPCode as '采购入库单号',a.ERPSequence as '采购入库单行号',a.MUSER as '操作人',a.MUSERName as '操作人名称',
a.MTIME as '操作时间',a.WorkPoint as '站点'
from ICSWareHouseLotInfoLog a
inner join ICSASNDETAIL b on a.LotNo = b.LotNo and a.WorkPoint = b.WorkPoint
inner join ICSDeliveryNotice c on b.ASNCode = c.ASNCode and b.WorkPoint = c.WorkPoint
INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND c.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
where a.WorkPoint ='{0}' and a.TransType ='2' and a.BusinessCode ='1'";
string sql2 = @"Select a.ID,a.LotNo as '条码',b.ASNCode as '送货单号',b.Sequence as '送货单行号',c.ODNCode as '到货单号',c.Sequence as '到货单行号',
n.OOCode as '采购订单',n.Sequence as '采购订单行号',a.InvCode as '物料代码',a.Quantity as '入库数量',a.ToWarehouseCode as '入库仓库',
a.ToLocationCode as '入库库位',a.ERPCode as '采购入库单号',a.ERPSequence as '采购入库单行号',a.MUSER as '操作人',a.MUSERName as '操作人名称',
a.MTIME as '操作时间',a.WorkPoint as '站点'
from ICSWareHouseLotInfoLog a
inner join ICSASNDETAIL b on a.LotNo = b.LotNo and a.WorkPoint = b.WorkPoint
inner join ICSODeliveryNotice c on b.ASNCode = c.OASNCode and b.WorkPoint = c.WorkPoint
INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND c.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
where a.WorkPoint ='{0}' and a.TransType ='2' and a.BusinessCode ='9'";
sql = string.Format(sql, WorkPoint);
sql2 = string.Format(sql2, WorkPoint);
if (condition.dModifyDateFrom != null)
{
sql += " and a.Mtime >= '{0}'";
sql = string.Format(sql, condition.dModifyDateFrom);
sql2 += " and a.Mtime >= '{0}'";
sql2 = string.Format(sql2, condition.dModifyDateFrom);
}
if (condition.dModifyDateTo != null)
{
sql += " and a.Mtime <= '{0}'";
sql = string.Format(sql, condition.dModifyDateTo);
sql2 += " and a.Mtime <= '{0}'";
sql2 = string.Format(sql2, condition.dModifyDateTo);
}
if (condition.ASNCode != null)
{
sql += " and b.ASNCode like '%{0}%'";
sql = string.Format(sql, condition.ASNCode);
sql2 += " and b.ASNCode like '%{0}%'";
sql2 = string.Format(sql2, condition.ASNCode);
}
if (condition.PO != null)
{
sql += " and n.POCode like '%{0}%'";
sql = string.Format(sql, condition.PO);
sql2 += " and n.OOCode 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.GetDataTable(sqlNew);
List<GetPurchaseStockInEntity> entityList = new List<GetPurchaseStockInEntity>();
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
GetPurchaseStockInEntity entity = new GetPurchaseStockInEntity();
entity.ID = dr["ID"].ToString();
entity.LotNo = dr["条码"].ToString();
entity.ASNCode = dr["送货单号"].ToString();
entity.ASNLine = string.IsNullOrWhiteSpace(dr["送货单行号"].ToString()) ? 1 : Convert.ToInt32(dr["送货单行号"].ToString());
entity.DNCode = dr["到货单号"].ToString();
entity.DNLine = string.IsNullOrWhiteSpace(dr["到货单行号"].ToString()) ? 1 : Convert.ToInt32(dr["到货单行号"].ToString());
entity.PO = dr["采购订单"].ToString();
entity.POLine = 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.ToWarehouseCode = dr["入库仓库"].ToString();
entity.ToLocationCode = dr["入库库位"].ToString();
entity.RcvDoc = dr["采购入库单号"].ToString();
entity.RcvDocLine = string.IsNullOrWhiteSpace(dr["采购入库单行号"].ToString()) ? 1 : Convert.ToInt32(dr["采购入库单行号"].ToString());
entity.TransType = "2";
entity.BusinessCode = "1";
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 = dr["站点"].ToString();
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;
}
}
}
}