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

389 lines
18 KiB

using NFine.Code;
using NFine.Data.Extensions;
using NFine.Domain._03_Entity;
using NFine.Domain._03_Entity.SRM;
using NFine.Repository;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
namespace NFine.Application
{
public class QuotedPriceApp : RepositoryFactory<ICSVendor>
{
//ICSWMS_SRMSysEntities db = new ICSWMS_SRMSysEntities();
//初次加载页面数据
public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @"select distinct a.RFQCODE,a.RFQNAME,a.PURCHUGCODE,a.[STATUS] ,a.CREATEUSER,a.CREATEDATE,b.ITEMTYPE ,c.PURCHUGNAME
from dbo.ICSSORRFQ a
left join ICSSORRFQ2NORMALITEM b on a.RFQCODE=b.RFQCODE and a.WorkPoint=b.WorkPoint
left join dbo.ICSPURCHUG c on a.PURCHUGCODE=c.PURCHUGCODE
left join ICSSORRFQ2VENDOR d on a.RFQCODE=d.RFQCODE
where 1=1";
if (!string.IsNullOrWhiteSpace(queryJson))
{
if (!string.IsNullOrWhiteSpace(queryParam["RFQCODE"].ToString()))
{
sql += " and a.RFQCODE like '%" + queryParam["RFQCODE"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["RFQName"].ToString()))
{
sql += " and a.RFQNAME like '%" + queryParam["RFQName"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["ItemCode"].ToString()))
{
sql += " and d.ITEMCODE like '%" + queryParam["ItemCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["ItemName"].ToString()))
{
sql += " and d.ITEMNAME like '%" + queryParam["ItemName"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["BeginDate"].ToString()))
{
sql += " and a.CREATEDATE >='" + queryParam["BeginDate"].ToString() + "' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["EndDate"].ToString()))
{
sql += " and a.CREATEDATE <='" + queryParam["EndDate"].ToString() + "'";
}
if (!string.IsNullOrWhiteSpace(queryParam["StatusNew"].ToString()))
{
sql += " and a.[STATUS] = '" + queryParam["StatusNew"].ToString() + "' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["StatusPublish"].ToString()))
{
sql += " and a.[STATUS] = '" + queryParam["StatusPublish"].ToString() + "' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["StatusClose"].ToString()))
{
sql += " and a.[STATUS] = '" + queryParam["StatusClose"].ToString() + "' ";
}
}
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
{
sql += " and a.WorkPoint in (" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + ")";
}
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
{
sql += " and VENDORCODE='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
}
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
//初次加载QuotedPriceDetails页面数据
public DataTable SelectOffer(string RFQCODE, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
//var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @"select distinct a.ITEMCODE,a.ITEMNAME,a.ITEMTYPE,b.INVSTD,b.INVUOM,c.[STATUS],d.QUOPRICE,c.QUOTATIONCODE
from dbo.ICSSORRFQ2NORMALITEM a
left join ICSINVENTORY b on a.ITEMCODE=b.INVSTD and a.WorkPoint=b.WorkPoint
left join ICSSORQUOTATION c on a.RFQCODE=c.RFQCODE and a.WorkPoint=c.WorkPoint
left join ICSSORQUODETAILNORMAL d on c.QUOTATIONCODE=d.QUOTATIONCODE and a.ITEMCODE=d.ITEMCODE
where a.RFQCODE='{0}'";
sql = string.Format(sql, RFQCODE);
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
#region 注
///// <summary>
///// 获取供应商列表
///// </summary>
///// <returns></returns>
//public DataTable GetVendor()
//{
// string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
// string sql = @"select '' as VENDORCODE,'' as VENDORTYPE
// union all
// SELECT distinct a.VENDORCODE,isnull(a.VENDORTYPE,'') as VENDORTYPE from [dbo].[ICSSORRFQ2VENDOR] a
// where a.VENDORCODE IS NOT NULL ";
// string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
// if (role != "admin")
// {
// sql += " and b.WorkPoint in (" + WorkPoint + ")";
// }
// DataTable dt = SqlHelper.GetDataTableBySql(sql);
// return dt;
//}
#endregion
//获取QuotedPriceDetails页面文本框值
public DataTable GetTxtInfo(string RFQCODE)
{
string configSql = @" select a.RFQCODE,a.RFQNAME,a.PURCHUGCODE,b.ITEMTYPE ,
c.PURCHUGNAME ,c.PURCHUGCONECT ,d.VENDORCODE,e.cVenName,d.VENDORTYPE ,b.CURRENCY,d.TAXRATE,d.PAYMENTCONDITION,f.VENDORMEMO
from dbo.ICSSORRFQ a
left join ICSSORRFQ2NORMALITEM b on a.RFQCODE=b.RFQCODE
left join dbo.ICSPURCHUG c on a.PURCHUGCODE=c.PURCHUGCODE
left join dbo.ICSSORRFQ2VENDOR d on a.RFQCODE=d.RFQCODE
left join ICSVendor e on d.VENDORCODE=e.cVenCode
left join ICSSORQUOTATION f on a.RFQCODE=f.RFQCODE WHERE a.RFQCODE='" + RFQCODE + "'";
DataTable dt = SqlHelper.GetDataTableBySql(configSql);
return dt;
}
/// <summary>
/// 创建报价单
/// </summary>
/// <param name="keyValue"></param>
/// <returns></returns>
public int CreateSoquotaTion(string keyValue)
{
var queryParam = keyValue.ToJObject();
string RFQCODE = queryParam["RFQCODE"].ToString();
string VenCode = queryParam["VenCode"].ToString();
string VENDORTYPE = queryParam["VENDORTYPE"].ToString();
//已改多站点
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string Pre = RFQCODE + DateTime.Now.ToString("yyMMdd");
string sql = string.Empty;
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
string LotNo = GetCode(WorkPoint, "ICSSORQUOTATION", "QUOTATIONCODE", Pre, 5);
sql = string.Format(@"INSERT INTO dbo.ICSSORQUOTATION
( CREATEDATE ,CREATETIME ,CREATEUSER ,CURRENTQUOINDICATOR ,LOGDATE ,LOGTIME ,LOGUSER ,
QUOTATIONCODE ,QUOTEDATE ,QUOTYPE ,RFQCODE ,[STATUS],VENDORCODE,WorkPoint,a.COMPANYCODE
)
SELECT distinct GETDATE(),GETDATE(),'{0}','0',GETDATE(),GETDATE(),'{1}','{2}',GETDATE(),'Normal','{3}','Publish','{6}',a.WorkPoint,a.COMPANYCODE
FROM dbo.ICSSORRFQ2NORMALITEM a
left join ICSSORRFQ2VENDOR b on a.RFQCODE=b.RFQCODE and a.WorkPoint=b.WorkPoint
where a.RFQCODE='{4}' AND a.WorkPoint={5} ",
MUSER, MUSER, LotNo, RFQCODE, RFQCODE, WorkPoint, VenCode);
int count = SqlHelper.ExecuteNonQuery(sql);
CreateSoquotas(keyValue, LotNo);
return count;
}
/// <summary>
/// 发布报价明细单
/// </summary>
/// <param name="keyValue"></param>
/// <returns></returns>
public int CreateSoquotas(string keyValue, string LotNo)
{
var queryParam = keyValue.ToJObject();
string QUOTATIONCODE = LotNo;
string RFQCODE = queryParam["RFQCODE"].ToString();
//已改多站点
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string sql = string.Empty;
string sqls = string.Empty;
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
sql = string.Format(@"insert into ICSSORQUODETAILNORMAL(
COMPANYCODE,CREATEDATE,CREATETIME,CURRENCY,ITEMCODE,ITEMNAME,ITEMTYPE ,LOGDATE,LOGTIME,LOGUSER,QUOPRICE,QUOSTATUS,QUOTATIONCODE,QUOTEDATE,REQUESTQUANTITY,RFQCODE,UNIT,CURRENTQUOINDICATOR,STARTDATE
)select a.COMPANYCODE,getdate(),getdate(),'{0}', a.ITEMCODE,a.ITEMNAME ,a.ITEMTYPE,getdate(),getdate(),'{1}',0,'Pending','{2}',getdate(),a.REQUESTQUANTITY,'{3}',a.UNIT,'0',getdate()
from ICSSORRFQ2NORMALITEM a
left join ICSSORQUOTATION b on a.RFQCODE=b.RFQCODE and a.WorkPoint=b.WorkPoint
where a.RFQCODE='{4}'and b.QUOTATIONCODE='{5}' AND a.WorkPoint={6} ",
MUSERNAME, MUSERNAME, QUOTATIONCODE, RFQCODE, RFQCODE, QUOTATIONCODE, WorkPoint);
int count = SqlHelper.ExecuteNonQuery(sql);
return count;
}
private string GetCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
{
string sql = "EXEC Addins_GetSerialCode {0},'{1}','{2}','{3}',{4}";
sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
return DbHelper.ExecuteScalar(CommandType.Text, sql).ToString();
}
/// <summary>
/// 送货单文件上传
/// </summary>
/// <param name="keyValue"></param>
/// <returns></returns>
public int UpLoadFile(string QUOTATIONCODE, string fileName, string ITEMCODE)
{
DataTable dt = new DataTable();
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string sql = "";
sql = string.Format(@"update ICSSORQUODETAILNORMAL set COSTDETAILSREFERCODE='{0}'
where QUOTATIONCODE='{1}'and ITEMCODE='{2}'",
fileName, QUOTATIONCODE, ITEMCODE);
StringBuilder Str = new StringBuilder(sql);
return Repository().ExecuteBySql(Str);
}
//初次加载QuotedPrice页面数据
public DataTable GetGridJsonPrice(string RFQCODE,string ITEMCODE, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
//var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @"
select distinct a.ITEMCODE,c.ITEMNAME,c.ITEMTYPE,d.INVSTD,c.UNIT,a.QUOSTATUS,a.QUOPRICE,a.COSTDETAILSREFERCODE,a.REQUESTQUANTITY,c.HASCOSTDETAILS ,
case when e.ISSHOWPRICE='1' then a.REFERPRICE else 0 end as REFERPRICE
from ICSSORQUODETAILNORMAL a
left join ICSSORQUOTATION b on a.QUOTATIONCODE=b.QUOTATIONCODE
left join ICSSORRFQ2NORMALITEM c on a.ITEMCODE=c.ITEMCODE
left join ICSINVENTORY d on c.ITEMCODE=d.INVSTD
left join ICSSORRFQ2VENDOR e on b.RFQCODE=e.RFQCODE
where a.ITEMCODE='{0}' and a.RFQCODE='{1}'";
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
{
sql += " and e.PRINCINGVENDORCODE='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
}
sql = string.Format(sql, ITEMCODE, RFQCODE);
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
//获取QuotedPrice页面文本框值
public DataTable GetPriceInfo(string RFQCODE)
{
string configSql = @" select a.RFQCODE,a.RFQNAME,a.PURCHUGCODE,b.ITEMTYPE ,
c.PURCHUGNAME ,c.PURCHUGCONECT ,d.VENDORCODE,e.cVenName,d.VENDORTYPE ,b.CURRENCY,d.TAXRATE,d.PAYMENTCONDITION,f.VENDORMEMO
from dbo.ICSSORRFQ a
left join ICSSORRFQ2NORMALITEM b on a.RFQCODE=b.RFQCODE
left join dbo.ICSPURCHUG c on a.PURCHUGCODE=c.PURCHUGCODE
left join dbo.ICSSORRFQ2VENDOR d on a.RFQCODE=d.RFQCODE
left join ICSVendor e on d.VENDORCODE=e.cVenCode
left join ICSSORQUOTATION f on a.RFQCODE=f.RFQCODE WHERE a.RFQCODE='" + RFQCODE + "'";
DataTable dt = SqlHelper.GetDataTableBySql(configSql);
return dt;
}
/// <summary>
/// 发布报价明细单
/// </summary>
/// <param name="keyValue"></param>
/// <returns></returns>
public int CreateSoquota(string keyValue,double QUOPRICE)
{
var queryParam = keyValue.ToJObject();
string QUOTATIONCODE = queryParam["QUOTATIONCODE"].ToString();
string RFQCODE = queryParam["RFQCODE"].ToString();
string ITEMCODE = queryParam["ITEMCODE"].ToString();
//已改多站点
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string sql = string.Empty;
string sqls = string.Empty;
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
sqls = string.Format(@" select QUOTATIONCODE from ICSSORQUODETAILNORMAL where QUOTATIONCODE='{0}' ",
QUOTATIONCODE);
DataTable dt = SqlHelper.GetDataTableBySql(sqls);
if (dt.Rows.Count==0)
{
sql = string.Format(@"insert into ICSSORQUODETAILNORMAL(
COMPANYCODE,CREATEDATE,CREATETIME,CURRENCY,ITEMCODE,ITEMNAME,ITEMTYPE ,LOGDATE,LOGTIME,LOGUSER,QUOPRICE,QUOSTATUS,QUOTATIONCODE,QUOTEDATE,REQUESTQUANTITY,RFQCODE,UNIT,CURRENTQUOINDICATOR,STARTDATE
)select a.COMPANYCODE,getdate(),getdate(),'{0}', a.ITEMCODE,a.ITEMNAME ,a.ITEMTYPE,getdate(),getdate(),'{1}','{2}','Pending','{3}',getdate(),a.REQUESTQUANTITY,'{4}',a.UNIT,'0',getdate()
from ICSSORRFQ2NORMALITEM a
left join ICSSORQUOTATION b on a.RFQCODE=b.RFQCODE and a.WorkPoint=b.WorkPoint
where a.RFQCODE='{5}'and b.QUOTATIONCODE='{6}' AND a.WorkPoint={7} ",
MUSERNAME, MUSERNAME, QUOPRICE, QUOTATIONCODE, RFQCODE, RFQCODE, QUOTATIONCODE, WorkPoint);
int count = SqlHelper.ExecuteNonQuery(sql);
return count;
}
else
{
sql = string.Format(@"update ICSSORQUODETAILNORMAL set QUOPRICE='{0}',LOGDATE=getdate(),LOGTIME=getdate(),LOGUSER='{1}'
where QUOTATIONCODE='{2}' and ITEMCODE='{3}' ",
QUOPRICE, MUSERNAME, QUOTATIONCODE, ITEMCODE);
int count = SqlHelper.ExecuteNonQuery(sql);
return count;
}
}
public int Refuse(string ITEMCODE, string QUOTATIONCODE)
{
DataTable dt = new DataTable();
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string sql = "";
sql = string.Format(@"update ICSSORQUODETAILNORMAL set QUOSTATUS='PricingReject'
where QUOTATIONCODE='{0}'and ITEMCODE='{1}' and WorkPoint={2}",
QUOTATIONCODE, ITEMCODE, WorkPoint);
int count = SqlHelper.ExecuteNonQuery(sql);
return count;
}
/// <summary>
/// 获取供应商列表
/// </summary>
/// <returns></returns>
public DataTable GetVendor(string RFQCODE)
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string sql = "";
sql = string.Format(@"select '' as VENDORCODE,'' as cVenName
union all
select VENDORCODE,b.cVenName from dbo.ICSSORRFQ2VENDOR a
left join dbo.ICSVendor b on a.VENDORCODE=b.cVenCode
WHERE VENDORCODE<>'' and RFQCODE='{0}'", RFQCODE);
string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
if (role != "admin")
{
sql += " and b.WorkPoint=" + WorkPoint.TrimEnd(',') + "";
}
DataTable dt = SqlHelper.GetDataTableBySql(sql);
return dt;
}
public DataTable GetcVenName(string VenCode,string RFQCODE)
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string sql = "";
sql = string.Format(@" select VENDORCODE,b.cVenName,a.VENDORTYPE from ICSSORRFQ2VENDOR a
left join dbo.ICSVendor b on a.VENDORCODE=b.cVenCode
where a.VENDORCODE='{0}' and RFQCODE='{1}'", VenCode, RFQCODE);
//string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
//if (role != "admin")
//{
// sql += " and b.WorkPoint=" + WorkPoint.TrimEnd(',') + "";
//}
DataTable dt = SqlHelper.GetDataTableBySql(sql);
return dt;
}
}
}