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.
1120 lines
57 KiB
1120 lines
57 KiB
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using NFine.Code;
|
|
using NFine.Data.Extensions;
|
|
using NFine.Domain._03_Entity.SRM;
|
|
using NFine.Domain.Entity.ProductManage;
|
|
using NFine.Domain.IRepository.ProductManage;
|
|
using NFine.Repository;
|
|
using NFine.Repository.ProductManage;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace NFine.Application
|
|
{
|
|
public class InvoiceManageApp : RepositoryFactory<ICSVendor>
|
|
{
|
|
|
|
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 ID,DocNo,MUSER,MUSERName,CONVERT(VARCHAR(100),MTIME,23) AS MTIME,
|
|
CASE Status WHEN 0 THEN '开立' WHEN 1 THEN '发布' WHEN 2 THEN '记账' WHEN 3 THEN '退回' END STATUS,
|
|
CASE InvoiceType WHEN 0 THEN '普票' WHEN 1 THEN '专票' END INVOICETYPE,Tax,
|
|
CASE ISNULL(IsERP, 0) WHEN 0 THEN '否' WHEN 1 THEN '是' END ISERP,
|
|
SupplierCode,SupplierName,PubUser,CONVERT(VARCHAR(100),PubTime,23) AS PubTime,Remark
|
|
FROM ICSInvoice
|
|
WHERE 1=1";
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["DocNo"].ToString()))
|
|
{
|
|
sql += " and DocNo like '%" + queryParam["DocNo"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["SupplierCode"].ToString()))
|
|
{
|
|
sql += " and SupplierCode like '%" + queryParam["SupplierCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["SupplierName"].ToString()))
|
|
{
|
|
sql += " and SupplierName like '%" + queryParam["SupplierName"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
|
|
{
|
|
sql += " and MTIME >= '" + queryParam["TimeFrom"].ToString() + "' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["TimeTo"].ToString()))
|
|
{
|
|
sql += " and MTIME <= '" + queryParam["TimeTo"].ToString() + "' ";
|
|
}
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
|
|
{
|
|
//已改多站点
|
|
sql += " and WorkPoint in (" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + ")";
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
|
|
{
|
|
sql += " and SupplierCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
|
|
}
|
|
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
public DataTable GetGridJsonAdmin(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
|
|
string sql = @"SELECT ID,DocNo,MUSER,MUSERName,CONVERT(VARCHAR(100),MTIME,23) AS MTIME,
|
|
CASE Status WHEN 0 THEN '开立' WHEN 1 THEN '发布' WHEN 2 THEN '记账' WHEN 3 THEN '退回' END STATUS,
|
|
CASE InvoiceType WHEN 0 THEN '普票' WHEN 1 THEN '专票' END INVOICETYPE,Tax,
|
|
CASE ISNULL(IsERP, 0) WHEN 0 THEN '否' WHEN 1 THEN '是' END ISERP,
|
|
SupplierCode,SupplierName,PubUser,CONVERT(VARCHAR(100),PubTime,23) AS PubTime,Remark
|
|
FROM ICSInvoice
|
|
WHERE 1=1 AND Status IN (1,2,3)";
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["DocNo"].ToString()))
|
|
{
|
|
sql += " and DocNo like '%" + queryParam["DocNo"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["SupplierCode"].ToString()))
|
|
{
|
|
sql += " and SupplierCode like '%" + queryParam["SupplierCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["SupplierName"].ToString()))
|
|
{
|
|
sql += " and SupplierName like '%" + queryParam["SupplierName"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
|
|
{
|
|
sql += " and MTIME >= '%" + queryParam["TimeFrom"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["TimeTo"].ToString()))
|
|
{
|
|
sql += " and MTIME <= '%" + queryParam["TimeTo"].ToString() + "%' ";
|
|
}
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
|
|
{
|
|
//已改多站点
|
|
sql += " and WorkPoint in (" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + ")";
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
|
|
{
|
|
sql += " and SupplierCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
|
|
}
|
|
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 子表查询
|
|
/// </summary>
|
|
/// <param name="queryJson"></param>
|
|
/// <param name="jqgridparam"></param>
|
|
/// <returns></returns>
|
|
public DataTable GetSubGridJson(string ID, ref Pagination jqgridparam)
|
|
{
|
|
//
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
DataTable dt = new DataTable();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = @"SELECT DISTINCT a.ID,b.InvCode,b.InvName,a.Qty,b.InvUom,
|
|
CAST(a.TaxPriceSell AS DECIMAL(18,2)) AS Price,CAST(a.TotalMoneySell AS DECIMAL(18,2)) AS Total,
|
|
a.Src_CADocNo AS CACOde,b.DNNO AS DNCOde,b.POCode
|
|
FROM ICSInvoiceDetail a
|
|
LEFT JOIN view_PoMain b ON a.ASNNo = b.DNNO AND a.InvCode = b.InvCode
|
|
WHERE a.DocNo = '{0}' AND a.WorkPoint in ({1}) ";
|
|
sql = string.Format(sql, ID, WorkPoint);
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询送货单新增/修改页面数据
|
|
/// </summary>
|
|
/// <param name="queryJson"></param>
|
|
/// <param name="jqgridparam"></param>
|
|
/// <returns></returns>
|
|
public DataTable GetSubGridJson_Add(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = @"SELECT DISTINCT a.ID,b.InvCode,b.InvName,a.Qty,b.InvUom,
|
|
CAST(a.TaxPriceSell AS DECIMAL(18,2)) AS Price,CAST(a.TotalMoneySell AS DECIMAL(18,2)) AS Total,
|
|
a.Src_CADocNo AS CACOde,b.DNNO AS DNCOde,b.POCode
|
|
FROM ICSInvoiceDetail a
|
|
LEFT JOIN view_PoMain b ON a.ASNNo = b.DNNO AND a.InvCode = b.InvCode
|
|
WHERE a.DocNo = '{0}' AND a.WorkPoint in ({1}) ";
|
|
sql = string.Format(sql, queryParam["DocNo"].ToString(), WorkPoint);
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 子表查询
|
|
/// </summary>
|
|
/// <param name="queryJson"></param>
|
|
/// <param name="jqgridparam"></param>
|
|
/// <returns></returns>
|
|
public DataTable GetSubGridJson(string CartonNo, string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
DataTable dt = new DataTable();
|
|
//var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = @"SELECT a.ID,c.ItemCODE,d.INVNAME,c.VenderLotNO,c.LOTQTY,c.TYPE
|
|
FROM dbo.ICSITEMLot2Carton a
|
|
LEFT JOIN dbo.ICSCarton b ON a.CartonNO=b.CartonNO AND a.WorkPoint=b.WorkPoint
|
|
LEFT JOIN dbo.ICSITEMLot c ON a.LotNo_ID=c.ID AND a.WorkPoint=c.WorkPoint
|
|
LEFT JOIN dbo.ICSINVENTORY d ON c.ItemCODE=d.INVCODE AND a.WorkPoint=d.WorkPoint
|
|
WHERE a.CartonNO='" + CartonNo + "' and a.WorkPoint in (" + WorkPoint + ")";
|
|
if (!string.IsNullOrEmpty(queryJson))
|
|
{
|
|
sql += @"UNION ALL
|
|
SELECT a.ID,a.ItemCODE,b.INVNAME,a.VenderLotNO,a.LOTQTY,a.TYPE FROM
|
|
dbo.ICSITEMLot a
|
|
LEFT JOIN dbo.ICSINVENTORY b ON a.ItemCODE=b.INVCODE AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.ID IN (" + queryJson.TrimEnd(',') + ") and a.WorkPoint in (" + WorkPoint + ")";
|
|
}
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
public DataTable GetSubGridJsonByCreate(string POCode, string PORow)
|
|
{
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
DataTable dt = new DataTable();
|
|
//var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = @"SELECT a.ID, a.POCode,a.PORow,a.PODate,a.ORDERNO,a.VenCode,a.VenName,a.InvCode,
|
|
b.INVNAME,b.INVSTD,b.INVDESC,b.INVUOM,a.Quantity,ISNULL(c.CreatedQty,0) AS CreatedQty,isnull(c.InQty,0) as InQty,a.WorkPoint
|
|
FROM dbo.ICSPO_PoMain a
|
|
LEFT JOIN dbo.ICSINVENTORY b ON a.InvCode=b.INVCODE AND a.WorkPoint=b.WorkPoint
|
|
LEFT JOIN (SELECT SUM(x.LOTQTY) CreatedQty,TransNO,TransLine,x.WorkPoint,
|
|
SUM(CASE WHEN y.LotNO IS NOT NULL THEN x.LOTQTY ELSE 0 END) AS InQty
|
|
FROM dbo.ICSITEMLot x
|
|
LEFT JOIN dbo.ICSWareHouseLotInfo y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
|
|
GROUP BY TransNO,TransLine,x.WorkPoint) c ON a.POCode=c.TransNO AND a.PORow=c.TransLine AND a.WorkPoint=c.WorkPoint
|
|
WHERE 1=1
|
|
and a.POCode='" + POCode + "' and a.PORow='" + PORow + "' and a.WorkPoint='" + WorkPoint + "'";
|
|
return Repository().FindTableBySql(sql.ToString());
|
|
}
|
|
|
|
public DataTable GetVendorLotNo(string VenCode, string WorkPoint)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
//var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string dtPre = DateTime.Now.ToString("yyyyMMdd");
|
|
string sql = @"EXEC Addins_GetSerialCode '" + WorkPoint + "','ICSITEMLotNo','VendorLotNo','" + VenCode + dtPre + "',2";
|
|
return Repository().FindTableBySql(sql.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成条码
|
|
/// </summary>
|
|
/// <param name="POCode"></param>
|
|
/// <param name="PORow"></param>
|
|
/// <param name="keyValue"></param>
|
|
/// <returns></returns>
|
|
public int CreateItemLotNo(string POCode, string PORow, string keyValue)
|
|
{
|
|
var queryParam = keyValue.ToJObject();
|
|
int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
|
|
decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
|
|
decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
|
|
decimal LOTQTY = minPackQty;
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string VenCode = GetVendorCode(POCode, PORow, WorkPoint);
|
|
string Pre = VenCode + DateTime.Now.ToString("yyMMdd");
|
|
string sql = string.Empty;
|
|
string VendorLot = queryParam["VendorLot"].ToString();
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
|
|
for (int i = 0; i < createPageCount; i++)
|
|
{
|
|
if (i + 1 == createPageCount)
|
|
{
|
|
if (minPackQty * createPageCount > thisCreateQty)
|
|
{
|
|
LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
|
|
}
|
|
}
|
|
string LotNo = GetSerialCode(WorkPoint, "ICSITEMLot", "LotNO", Pre, 5);
|
|
sql += string.Format(@"INSERT INTO dbo.ICSITEMLot
|
|
( ID ,LotNO ,ItemCODE ,TransNO ,TransLine ,VENDORITEMCODE ,VENDORCODE ,
|
|
VenderLotNO ,PRODUCTDATE ,LOTQTY ,ACTIVE ,Exdate ,WorkPoint ,
|
|
MUSER ,MUSERName ,MTIME ,TYPE,ORDERNO)
|
|
SELECT NEWID(),'{0}',InvCode,POCode,PORow,'',NULL,
|
|
'{1}',GETDATE(),'{2}','Y','2999-12-31 00:00:00.000','{3}',
|
|
'{4}','{5}',GETDATE(),'采购原料',ORDERNO
|
|
FROM dbo.ICSPO_PoMain WHERE POCode='{6}' AND PORow='{7}' AND WorkPoint='{3}'",
|
|
LotNo, VendorLot, LOTQTY, WorkPoint, MUSER, MUSERNAME, POCode, PORow);
|
|
sql += "\r\n";
|
|
}
|
|
int count = SqlHelper.ExecuteNonQuery(sql);
|
|
return count;
|
|
}
|
|
|
|
|
|
public string GetSerialCode(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();
|
|
}
|
|
|
|
public string GetVendorCode(string POCode, string PORow, string WorkPoint)
|
|
{
|
|
string sql = string.Format(@"SELECT VenCode FROM dbo.ICSPO_PoMain
|
|
WHERE POCode='{0}' AND PORow='{1}' AND WorkPoint='{2}'", POCode, PORow, WorkPoint);
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
string VenCode = string.Empty;
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
VenCode = dt.Rows[0][0].ToString();
|
|
}
|
|
return VenCode;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除送货单内的条码或者箱号
|
|
/// </summary>
|
|
/// <param name="keyValue"></param>
|
|
/// <returns></returns>
|
|
public string DeleteInfo(string keyValue)
|
|
{
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string msg = "";
|
|
string sql = string.Format(@"DELETE
|
|
FROM dbo.ICSCADetail
|
|
WHERE ID IN ({0}) and WorkPoint ='{1}' ", keyValue.TrimEnd(','), WorkPoint);
|
|
try
|
|
{
|
|
SqlHelper.ExecuteNonQuery(sql);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
msg = ex.Message;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除对账单
|
|
/// </summary>
|
|
/// <param name="keyValue"></param>
|
|
/// <returns></returns>
|
|
public string DeleteDocNo(string keyValue)
|
|
{
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string msg = "";
|
|
keyValue = keyValue.Substring(1, keyValue.Length - 2);
|
|
string sql = string.Empty;
|
|
if (string.IsNullOrEmpty(msg))
|
|
{
|
|
sql = string.Format(@"DELETE FROM ICSInvoiceDetail WHERE DocNo IN ({0}) and WorkPoint in ({1})
|
|
DELETE FROM ICSInvoice WHERE DocNo IN ({0}) and WorkPoint in ({1})", keyValue.TrimEnd(','), WorkPoint);
|
|
SqlHelper.ExecuteNonQuery(sql);
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
public int UpDateByDocNo(string keyValue, string Status)
|
|
{
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
keyValue = keyValue.Substring(1, keyValue.Length - 2);
|
|
string sql = string.Empty;
|
|
if (Status == "0")
|
|
{
|
|
sql = @"UPDATE ICSInvoice SET STATUS = '{1}',PubUser = NULL,PubTime = NULL WHERE DocNo IN ({0})";
|
|
sql = string.Format(sql, keyValue.TrimEnd(','), Status);
|
|
}
|
|
else if (Status == "1")
|
|
{
|
|
sql = @"UPDATE ICSInvoice SET STATUS = '{1}',PubUser = '{2}',PubTime = GETDATE() WHERE DocNo IN ({0})";
|
|
sql = string.Format(sql, keyValue.TrimEnd(','), Status, MUSER);
|
|
}
|
|
return SqlHelper.ExecuteNonQuery(sql);
|
|
}
|
|
|
|
public int UpDateByDocNoAdmin(string keyValue, string Status)
|
|
{
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
keyValue = keyValue.Substring(1, keyValue.Length - 2);
|
|
string sql = string.Empty;
|
|
if (Status == "2")
|
|
{
|
|
sql = @"UPDATE ICSInvoice SET STATUS = '{1}',CAComptTime = GETDATE(),CAComptUser = '{2}',ModifyTime = GETDATE(),ModifyUser = '{2}'
|
|
WHERE DocNo IN ({0})";
|
|
sql = string.Format(sql, keyValue.TrimEnd(','), Status, MUSER);
|
|
}
|
|
else if (Status == "3")
|
|
{
|
|
sql = @"UPDATE ICSInvoice SET STATUS = '{1}',CAComptTime = NULL,CAComptUser = NULL,ModifyTime =NULL,ModifyUser = NULL
|
|
WHERE DocNo IN ({0})";
|
|
sql = string.Format(sql, keyValue.TrimEnd(','), Status);
|
|
}
|
|
return SqlHelper.ExecuteNonQuery(sql);
|
|
}
|
|
|
|
public string Bookkeeping(string keyValue)
|
|
{
|
|
string sql = string.Empty;
|
|
string msg = string.Empty;
|
|
string U8ConnStr = ConfigurationManager.ConnectionStrings["U8connstr"].ConnectionString; ;
|
|
keyValue = keyValue.Substring(1, keyValue.Length - 2);
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
try
|
|
{
|
|
#region [更新发票状态和信息]
|
|
sql = @"UPDATE ICSInvoice SET Status = '2',ModifyUser = '{1}',ModifyTime = GETDATE(),
|
|
ComptUser = '{1}',ComptTime = GETDATE(),IsERP = 1
|
|
WHERE DocNo IN ({0})";
|
|
sql = string.Format(sql, keyValue.TrimEnd(','), MUSER);
|
|
SqlHelper.ExecuteNonQuery(sql);
|
|
#endregion
|
|
|
|
#region [查询发票号和供应商是否存在]
|
|
string cContactCode = string.Empty;
|
|
string cContactName = string.Empty;
|
|
string BIDocNo = keyValue.TrimEnd(',').Replace("'", "");
|
|
string VenderCode = string.Empty;
|
|
|
|
#region [获取发票的供应商编码]
|
|
sql = @"SELECT SupplierCode FROM ICSInvoice WHERE DocNo = '{0}'";
|
|
sql = string.Format(sql, BIDocNo);
|
|
DataTable dtVender = SqlHelper.GetDataTableBySql(sql);
|
|
if (dtVender != null && dtVender.Rows.Count > 0 && !string.IsNullOrWhiteSpace(dtVender.Rows[0][0].ToString()))
|
|
VenderCode = dtVender.Rows[0][0].ToString();
|
|
#endregion
|
|
|
|
string sqlPurBillVouch = @"SELECT * FROM PurBillVouch WHERE cPBVCode = '{0}'";
|
|
sqlPurBillVouch = string.Format(sqlPurBillVouch, BIDocNo);
|
|
DataTable dtPurBillVouch = SqlHelper.GetDataTableBySqlWithConn(U8ConnStr, sqlPurBillVouch);
|
|
if (dtPurBillVouch != null && dtPurBillVouch.Rows.Count > 0 && !string.IsNullOrWhiteSpace(dtPurBillVouch.Rows[0][0].ToString()))
|
|
{
|
|
msg = "发票号已存在!";
|
|
}
|
|
else
|
|
{
|
|
string sqlVendor = @"SELECT a.cVenCode,b.cContactCode,b.cContactName
|
|
FROM Vendor a
|
|
LEFT JOIN Ven_Contact b ON a.cVenPerson = b.cContactName
|
|
WHERE a.cVenCode='{0}'";
|
|
sqlVendor = string.Format(sqlVendor, VenderCode);
|
|
DataTable dtVendor = SqlHelper.GetDataTableBySqlWithConn(U8ConnStr, sqlVendor);
|
|
if (dtVendor != null && dtVendor.Rows.Count > 0)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(dtVendor.Rows[0]["cVenCode"].ToString()))
|
|
{
|
|
msg = "U8供应商不存在!";
|
|
}
|
|
else if (string.IsNullOrWhiteSpace(dtVendor.Rows[0]["cContactCode"].ToString()))
|
|
{
|
|
msg = "U8供应商联系人不存在!";
|
|
}
|
|
else
|
|
{
|
|
cContactCode = dtVendor.Rows[0]["cContactCode"].ToString();
|
|
cContactName = dtVendor.Rows[0]["cContactName"].ToString();
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region [回写U8发票]
|
|
if (msg.Length <= 0)
|
|
{
|
|
sql = @"SELECT b.DocNo,b.InvoiceType,b.SupplierCode,b.Tax,a.InvCode,a.Qty,a.TaxPriceSell,a.ASNNo,b.ComptUser
|
|
FROM ICSInvoiceDetail a
|
|
LEFT JOIN ICSInvoice b ON a.DocNo = b.DocNo AND a.WorkPoint = b.WorkPoint
|
|
WHERE b.DocNo = '{0}'";
|
|
sql = string.Format(sql, BIDocNo);
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
sql = "";
|
|
if (dt != null)
|
|
{
|
|
int id = 0, did = 0;
|
|
string cVouchType = "PURBILL";
|
|
string cAcc_Id = U8ConnStr.Substring(U8ConnStr.IndexOf("UFDATA_") + 7, 3);
|
|
FindInvoiceIDFromERP(U8ConnStr, cVouchType, cAcc_Id, dt.Rows.Count, out id, out did);
|
|
|
|
#region [主表]
|
|
string cPBVBillType = dt.Rows[0]["InvoiceType"].ToString();
|
|
string cPBVCode = dt.Rows[0]["DocNo"].ToString();
|
|
string cVenCode = dt.Rows[0]["SupplierCode"].ToString();
|
|
string iPBVTaxRate = dt.Rows[0]["Tax"].ToString();
|
|
string cPBVMaker = dt.Rows[0]["ComptUser"].ToString();
|
|
|
|
string sqlErp = @" INSERT INTO PurBillVouch (PBVID,cPBVBillType,cPBVCode,cPTCode,dPBVDate,
|
|
cVenCode,cUnitCode,cexch_name,cExchRate,iPBVTaxRate,cPBVMemo,cInCode,cBusType,
|
|
cPBVMaker,bNegative,bOriginal,bFirst,iVTid,cSource,iDiscountTaxType,
|
|
cContactCode,cVenPerson,IsWfControlled)
|
|
VALUES({0},'{1}','{2}','03',GETDATE(),
|
|
'{3}','{3}','人民币',1,{4},'','cInCode','普通采购',
|
|
'{5}',0,0,0,8163,'采购','{6}','{7}','{8}',0)";
|
|
sqlErp = string.Format(sqlErp, id, cPBVBillType, cPBVCode,
|
|
cVenCode, Convert.ToDecimal(iPBVTaxRate),
|
|
cPBVMaker, cPBVBillType == "01" ? 0 : 1, cContactCode, cContactName);
|
|
int main = SqlHelper.ExecuteNonQueryWithConn(U8ConnStr, sqlErp);
|
|
if (main <= 0)
|
|
msg = "主表插入失败!";
|
|
|
|
#endregion
|
|
|
|
#region [子表]
|
|
int rowCount = 0;
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
rowCount++;
|
|
string cInvCode = row["InvCode"].ToString();
|
|
decimal iPBVQuantity = Convert.ToDecimal(row["Qty"].ToString());
|
|
decimal taxPrice = Convert.ToDecimal(row["TaxPriceSell"].ToString());
|
|
decimal price = 0;
|
|
decimal iOriMoney = 0;
|
|
decimal iOriTaxPrice = 0;
|
|
decimal ioriSum = 0;
|
|
decimal tax = Convert.ToDecimal(iPBVTaxRate) / 100;
|
|
if (cPBVBillType == "01")
|
|
{
|
|
price = taxPrice / (1 + tax);//无税单价
|
|
iOriMoney = Math.Round(price * iPBVQuantity, 2, MidpointRounding.AwayFromZero);//金额
|
|
iOriTaxPrice = Math.Round(decimal.Parse(iOriMoney.ToString()) * tax, 2, MidpointRounding.AwayFromZero);//税额
|
|
ioriSum = Math.Round(decimal.Parse(taxPrice.ToString()) * iPBVQuantity, 2, MidpointRounding.AwayFromZero);//价税合计
|
|
}
|
|
else
|
|
{
|
|
price = taxPrice - taxPrice * tax;
|
|
iOriMoney = Math.Round(price * iPBVQuantity, 2, MidpointRounding.AwayFromZero);//金额
|
|
iOriTaxPrice = Math.Round(taxPrice * tax * iPBVQuantity, 2, MidpointRounding.AwayFromZero);//税额
|
|
ioriSum = Math.Round(decimal.Parse(taxPrice.ToString()) * iPBVQuantity, 2, MidpointRounding.AwayFromZero);//价税合计
|
|
}
|
|
string sqlErps = @" INSERT INTO PurBillVouchs (ID,PBVID,cInvCode,bExBill,iPBVQuantity,iNum,iOriCost,iOriTaxCost,
|
|
iOriTaxPrice,iOriMoney,iOriSum,iCost,iMoney,iTaxPrice,iSum,iTaxRate,
|
|
RdsId,UpSoType,bCosting,bTaxCost,iinvexchrate,brettax,ivouchrowno)
|
|
VALUES({0},{1},'{2}',0,{3},0,{4},{5},
|
|
{6},{7},{8},{4},{7},{6},{8},{9},
|
|
0,'rd',0,1,0,0,{9})";
|
|
sqlErps = string.Format(sqlErps, did, id, cInvCode, iPBVQuantity, Math.Round(price, 6), taxPrice,
|
|
iOriTaxPrice, iOriMoney, ioriSum, Convert.ToDecimal(iPBVTaxRate), rowCount);
|
|
int sub = SqlHelper.ExecuteNonQueryWithConn(U8ConnStr, sqlErps);
|
|
if (sub <= 0)
|
|
msg = "子表插入失败!";
|
|
did--;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
return msg;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string sqlError = @"UPDATE ICSInvoice SET Status = '1',ModifyUser = NULL,ModifyTime = NULL,
|
|
ComptUser = NULL,ComptTime = NULL,IsERP = NULL
|
|
WHERE DocNo IN ({0})";
|
|
sqlError = string.Format(sqlError, keyValue.TrimEnd(','));
|
|
SqlHelper.ExecuteNonQuery(sqlError);
|
|
msg += ex.Message;
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
public int ReturnByDocNo(string keyValue)
|
|
{
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
keyValue = keyValue.Substring(1, keyValue.Length - 2);
|
|
string sql = @"UPDATE ICSInvoice SET Status = '3',IsERP = NULL
|
|
WHERE DocNo IN ({0})";
|
|
sql = string.Format(sql, keyValue.TrimEnd(','));
|
|
return SqlHelper.ExecuteNonQuery(sql);
|
|
}
|
|
|
|
public static void FindInvoiceIDFromERP(string connectstring, string IDtype, string cAcc_id, int rowCount, out int id, out int DID)
|
|
{
|
|
try
|
|
{
|
|
string str = @"DECLARE @ID int
|
|
DECLARE @DID int
|
|
SET @ID = 0
|
|
SET @DID = 0
|
|
|
|
IF NOT EXISTS (SELECT * FROM ufsystem..ua_identity WHERE cacc_id = '{0}' AND cVouchType = '{1}')
|
|
BEGIN
|
|
INSERT INTO ufsystem..ua_identity(cAcc_Id,cVouchType,iFatherId,iChildId) VALUES('{0}','{1}',1,1)
|
|
|
|
SELECT @ID = ifatherID + 1 ,@DID = ichildID + {2}
|
|
FROM ufsystem..ua_identity
|
|
WHERE cVouchType = '{1}'
|
|
AND cAcc_id = '{0}'
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
UPDATE ufsystem..ua_identity
|
|
SET ifatherID = ifatherID + 1,ichildID = ichildID + {2}
|
|
WHERE cVouchType = '{1}' AND cAcc_id = '{0}'
|
|
END
|
|
select ifatherID ID,ichildID DID FROM ufsystem..ua_identity
|
|
WHERE cVouchType = '{1}' AND cAcc_id = '{0}' ";
|
|
str = string.Format(str, cAcc_id, IDtype, rowCount.ToString());
|
|
DataTable dt = SqlHelper.GetDataTableBySqlWithConn(connectstring, str);
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
throw new Exception("ID取得失败");
|
|
}
|
|
id = Convert.ToInt32(dt.Rows[0]["ID"]) + 1000000000;
|
|
DID = Convert.ToInt32(dt.Rows[0]["DID"]) + 1000000000;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
|
|
public string ChangeStatusBySTNO(string keyValue)
|
|
{
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string msg = "";
|
|
keyValue = keyValue.Substring(1, keyValue.Length - 2);
|
|
string sql = string.Empty;
|
|
sql = "SELECT STNO FROM dbo.ICSPOArrive WHERE STNO IN (" + keyValue.TrimEnd(',') + ")";
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
string STNO = dr["STNO"].ToString();
|
|
if (!string.IsNullOrEmpty(STNO))
|
|
{
|
|
msg += "送货单号:" + STNO + "已生成到货单,无法删除!";
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(msg))
|
|
{
|
|
sql = string.Format(@"DELETE FROM dbo.ICSASNDETAIL WHERE STNO IN ({0}) and WorkPoint ='{1}'
|
|
DELETE FROM dbo.ICSASN WHERE STNO IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
|
|
SqlHelper.ExecuteNonQuery(sql);
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除送货单
|
|
/// </summary>
|
|
/// <param name="keyValue"></param>
|
|
/// <returns></returns>
|
|
public string DeleteCartonNo(string keyValue)
|
|
{
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string msg = "";
|
|
keyValue = keyValue.Substring(1, keyValue.Length - 2);
|
|
|
|
string sql = string.Format(@"SELECT * FROM dbo.ICSASNDETAIL
|
|
WHERE LOTNO IN (
|
|
SELECT LotNO FROM dbo.ICSITEMLot2Carton WHERE CartonNO in ({0}) and WorkPoint='{1}') and WorkPoint='{1}'", keyValue.TrimEnd(','), WorkPoint);
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
if (dt == null || dt.Rows.Count <= 0)
|
|
{
|
|
sql = string.Format(@"DELETE FROM dbo.ICSCarton WHERE CartonNO in ({0}) and WorkPoint='{1}'
|
|
DELETE FROM dbo.ICSITEMLot2Carton WHERE CartonNO in ({0}) and WorkPoint='{1}' ", keyValue.TrimEnd(','), WorkPoint);
|
|
DbHelper.ExecuteNonQuery(CommandType.Text, sql);
|
|
}
|
|
else
|
|
{
|
|
msg = "所选箱号中已有加入送货单中,请先在送单号中删除!";
|
|
}
|
|
|
|
return msg;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 选择明细
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DataTable GetInfoByVenCode(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = @"SELECT a.ID,a.DocNo AS ASDocNo,c.InvCode,c.InvName,c.InvStd,
|
|
CAST(c.YSHQty AS DECIMAL(18,2)) AS RkQty,
|
|
c.InvUom,CAST(c.POPrice AS DECIMAL(18,2)) AS PoPrice,
|
|
CAST(c.POPrice*a.Tax AS DECIMAL(18,2)) AS TotalPrice,
|
|
CONVERT(VARCHAR(100),a.MTIME,23) AS ASDate,
|
|
CASE a.Status WHEN 0 THEN '开立' WHEN 1 THEN '发布' WHEN 2 THEN '完成' WHEN 3 THEN '退回' END STATUS,
|
|
b.Src_ASNDocNo AS DNDocNo,c.POCode AS POCode,CONVERT(VARCHAR(100),c.PODate,23) AS PODate,a.SupplierCode
|
|
FROM ICSCA a
|
|
INNER JOIN ICSCADetail b ON a.DocNo = b.DocNo
|
|
LEFT JOIN view_PoMain c ON b.InvCode = c.LotNO
|
|
WHERE 1=1 AND a.Status = 2 AND a.DocNo NOT IN (SELECT Src_CADocNo FROM ICSInvoiceDetail)";
|
|
// --AND a.STNO NOT IN (SELECT Src_ASNDocNo FROM ICSCADetail) AND a.SupplierCode = '51085'
|
|
if (!string.IsNullOrEmpty(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["ASDocNo"].ToString()))
|
|
sql += " AND a.DocNo like '%" + queryParam["ASDocNo"].ToString() + "%'";
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
sql += " AND c.InvCode like '%" + queryParam["InvCode"].ToString() + "%'";
|
|
if (!string.IsNullOrWhiteSpace(queryParam["DNDocNo"].ToString()))
|
|
sql += " AND b.Src_ASNDocNo like '%" + queryParam["DNDocNo"].ToString() + "%'";
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
sql += " AND c.POCode like '%" + queryParam["POCode"].ToString() + "%'";
|
|
}
|
|
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
|
|
sql += " AND a.SupplierCode = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
|
|
else
|
|
sql += " AND a.SupplierCode = '" + queryParam["VenCode"].ToString() + "'";
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
sql += " AND a.WorkPoint in (" + WorkPoint + ")";
|
|
sql += @" GROUP BY a.ID,a.DocNo,c.InvCode,c.InvName,c.InvStd,c.InvUom,c.POPrice,a.MTIME,a.Status,b.Src_ASNDocNo,
|
|
c.POCode,c.PODate,a.SupplierCode,a.Tax,c.YSHQty ";
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取供应商列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DataTable GetVendor()
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string sql = @"
|
|
select '' as F_VenCode,'' as cVenName
|
|
union all
|
|
SELECT DISTINCT a.F_VenCode,isnull(b.cVenName,'') as cVenName FROM dbo.Sys_SRM_User a
|
|
LEFT JOIN dbo.ICSVendor b ON a.F_VenCode=b.cVenCode and a.F_Location=b.WorkPoint
|
|
WHERE a.F_VenCode IS NOT NULL AND a.F_VenCode <>''";
|
|
string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
|
|
if (role != "admin")
|
|
{
|
|
sql += " and b.WorkPoint in (" + WorkPoint + ")";
|
|
}
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
return dt;
|
|
}
|
|
|
|
public string GetDocNo(string InvoiceType,string WorkPoint,string PaperNo)
|
|
{
|
|
string DocNo = string.Empty;
|
|
string SupplierCode = NFine.Code.OperatorProvider.Provider.GetCurrent().VenCode;
|
|
string SupplierName = string.Empty;
|
|
//已改多站点
|
|
// string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
if (!string.IsNullOrEmpty(SupplierCode))
|
|
{
|
|
string Date = DateTime.Now.ToString("yy");
|
|
string Pre = "BI" + SupplierCode + Date;
|
|
DocNo = GetSerialCode(WorkPoint, "ICSInvoice", "DocNo", Pre, 5);
|
|
SupplierName = GetSupplierName(SupplierCode);
|
|
}
|
|
if (!string.IsNullOrEmpty(DocNo))
|
|
{
|
|
string sql = string.Empty;
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
|
|
sql = @"INSERT INTO ICSInvoice (ID,DocNo,Status,BizType,SupplierCode,SupplierName,Tax,InvoiceType,MUSER,MUSERName,MTIME,WorkPoint,PaperNo)
|
|
VALUES (NEWID(),'{0}',0,0,'{1}','{2}',17,'{3}','{4}','{5}',GETDATE(),'{6}','{7}')";
|
|
sql = string.Format(sql, DocNo, SupplierCode, SupplierName, InvoiceType, MUSER, MUSERNAME, WorkPoint, PaperNo);
|
|
|
|
try
|
|
{
|
|
SqlHelper.ExecuteNonQuery(sql);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
return DocNo;
|
|
}
|
|
|
|
public string GetDocNoByPerson(string SupplierCode, string InvoiceType,string PaperNo)
|
|
{
|
|
string DocNo = string.Empty;
|
|
string Date = DateTime.Now.ToString("yy");
|
|
string Pre = "BI" + SupplierCode + Date;
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
DocNo = GetSerialCode(WorkPoint, "ICSInvoice", "DocNo", Pre, 5);
|
|
if (!string.IsNullOrEmpty(DocNo))
|
|
{
|
|
string sql = string.Empty;
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
string SupplierName = GetSupplierName(SupplierCode);
|
|
sql = @"INSERT INTO ICSInvoice (ID,DocNo,Status,BizType,SupplierCode,SupplierName,Tax,InvoiceType,MUSER,MUSERName,MTIME,WorkPoint,PaperNo)
|
|
VALUES (NEWID(),'{0}',0,0,'{1}','{2}',17,'{3}','{4}','{5}',GETDATE(),{6},'{7}')";
|
|
sql = string.Format(sql, DocNo, SupplierCode, SupplierName, InvoiceType, MUSER, MUSERNAME, WorkPoint, PaperNo);
|
|
|
|
try
|
|
{
|
|
SqlHelper.ExecuteNonQuery(sql);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
return DocNo;
|
|
}
|
|
|
|
public string GetSupplierName(string SupplierCode)
|
|
{
|
|
string sql = @"SELECT cVenName FROM ICSVendor WHERE cVenCode = '{0}'";
|
|
sql = string.Format(sql, SupplierCode);
|
|
try
|
|
{
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0][0].ToString()))
|
|
return dt.Rows[0][0].ToString();
|
|
else
|
|
return "";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
|
|
public string CheckSTNO_ItemCode(string JsonData, string DocNo)
|
|
{
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string msg = "";
|
|
string sql = string.Empty;
|
|
// sql = @"INSERT INTO ICSCADetail(ID,DocNo,DocLineNo,Src_ASNDocNo,Src_ASNDocLineNo,
|
|
// InvCode,Qty,InvUom,MUSER,MUSERName,MTIME,WorkPoint)
|
|
// SELECT NEWID(),'{0}',[送货单行],[送货单号],[送货单行],[条码号],[条码数量],[单位],
|
|
// '{1}','{2}',GETDATE(),'{3}'
|
|
// FROM view_PoMain
|
|
// WHERE [条码号] IN (" + JsonData.TrimEnd(',') + ")";
|
|
// sql = string.Format(sql, DocNo, MUSER, MUSERNAME, WorkPoint);
|
|
|
|
sql = @"INSERT INTO ICSInvoiceDetail (ID,DocNo,DocLineNo,ASNNo,ASNLine,Src_CADocNo,Src_CADocLineNo,InvCode,Qty,InvUom,
|
|
TaxPriceSell,TotalMoneySell,MUSER,MUSERName,MTIME,WorkPoint)
|
|
SELECT NEWID(),'{0}',1,b.Src_ASNDocNo,1,a.DocNo,1,c.InvCode,
|
|
CAST(c.YSHQty AS DECIMAL(18,2)) AS RkQty,c.InvUom,
|
|
CAST(c.POPrice AS DECIMAL(18,2)) AS PoPrice,
|
|
CAST(c.POPrice*a.Tax AS DECIMAL(18,2)) AS TotalPrice,'{1}','{2}',GETDATE(),'{3}'
|
|
FROM ICSCA a
|
|
LEFT JOIN ICSCADetail b ON a.DocNo = b.DocNo
|
|
LEFT JOIN view_PoMain c ON b.InvCode = c.LotNO
|
|
WHERE a.ID IN ({4})
|
|
GROUP BY a.DocNo,c.InvCode,c.InvUom,c.POPrice,b.Src_ASNDocNo,c.POCode,a.Tax,c.YSHQty";
|
|
sql = string.Format(sql, DocNo, MUSER, MUSERNAME, WorkPoint, JsonData.TrimEnd(','));
|
|
try
|
|
{
|
|
SqlHelper.ExecuteNonQuery(sql);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
public string CheckSTNO_CartonNo(string JsonData, string STNO)
|
|
{
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string msg = "";
|
|
string sql = string.Empty;
|
|
sql = @"INSERT INTO dbo.ICSASNDETAIL
|
|
( ASNDETAILID ,CREATEDATE ,CREATETIME ,CREATEUSER ,
|
|
ITEMCODE ,ITEMNAME ,LOGDATE ,LOGTIME ,LOGUSER ,
|
|
LOTNO ,PLANQTY ,STDSTATUS ,STLINE ,
|
|
STNO ,WorkPoint)
|
|
SELECT NEWID(),GETDATE(),GETDATE(),'" + MUSER + @"',
|
|
a.INVCODE,b.INVNAME,GETDATE(),GETDATE(),'" + MUSER + @"',
|
|
a.LotNO,c.LOTQTY,'0',0,
|
|
'" + STNO + "','" + WorkPoint + @"'
|
|
FROM dbo.ICSITEMLot2Carton a
|
|
LEFT JOIN dbo.ICSINVENTORY b ON a.INVCODE=b.INVCODE AND a.WorkPoint=b.WorkPoint
|
|
LEFT JOIN dbo.ICSITEMLot c ON a.LotNo_ID=c.ID AND a.WorkPoint=c.WorkPoint
|
|
WHERE a.CartonNO IN (" + JsonData.TrimEnd(',') + ") and a.WorkPoint='" + WorkPoint + "'";
|
|
try
|
|
{
|
|
SqlHelper.ExecuteNonQuery(sql);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
|
|
return msg;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取箱号主表信息
|
|
/// </summary>
|
|
/// <param name="queryJson"></param>
|
|
/// <param name="jqgridparam"></param>
|
|
/// <returns></returns>
|
|
public DataTable GetCartonGridJson(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = @"SELECT Serial,a.CartonNO,CartonStatus,PrintTimes,
|
|
lastPrintTime,a.MUSERName,a.MTIME,EATTRIBUTE8
|
|
FROM dbo.ICSCarton a
|
|
LEFT JOIN
|
|
(SELECT COUNT(x.LotNO) AS LotNoCount,CartonNO,x.WorkPoint FROM dbo.ICSITEMLot2Carton x
|
|
LEFT JOIN dbo.ICSITEMLot y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
|
|
GROUP BY CartonNO,x.WorkPoint) b ON a.CartonNO=b.CartonNO AND a.WorkPoint=b.WorkPoint
|
|
WHERE b.LotNoCount>0 and a.EATTRIBUTE3='SRM'
|
|
AND a.CartonNo not IN
|
|
(SELECT b.CartonNO FROM dbo.ICSASNDETAIL a inner JOIN dbo.ICSITEMLot2Carton b ON a.LOTNO =b.LotNO AND a.WorkPoint=b.WorkPoint)
|
|
";
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["CartonNo"].ToString()))
|
|
{
|
|
sql += " and a.CartonNO like '%" + queryParam["CartonNo"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["OrderNo"].ToString()))
|
|
{
|
|
sql += " and b.OrderNO like '%" + queryParam["OrderNo"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["TransNo"].ToString()))
|
|
{
|
|
sql += " and b.TransNO like '%" + queryParam["TransNO"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["TransLine"].ToString()))
|
|
{
|
|
sql += " and b.TransLine like '%" + queryParam["TransLine"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
|
|
{
|
|
sql += " and a.EATTRIBUTE8 like '%" + queryParam["VenCode"].ToString() + "%' ";
|
|
}
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
|
|
{
|
|
//已改多站点
|
|
sql += " and a.WorkPoint in ('" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + "')";
|
|
}
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 箱号子表查询
|
|
/// </summary>
|
|
/// <param name="CartonNo"></param>
|
|
/// <param name="jqgridparam"></param>
|
|
/// <returns></returns>
|
|
public DataTable GetCartonSubGridJson(string CartonNo, ref Pagination jqgridparam)
|
|
{
|
|
//已改多站点
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
DataTable dt = new DataTable();
|
|
//var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = @"SELECT a.LotNO, a.ID,c.ItemCODE,d.INVNAME,c.VenderLotNO,c.LOTQTY,
|
|
c.TYPE,b.EATTRIBUTE8,c.ORDERNO,c.TransNO,c.TransLine,d.INVDESC,d.INVTYPE,e.MEMO,d.INVSTD,d.INVPARSETYPE
|
|
FROM dbo.ICSITEMLot2Carton a
|
|
LEFT JOIN dbo.ICSCarton b ON a.CartonNO=b.CartonNO AND a.WorkPoint=b.WorkPoint
|
|
LEFT JOIN dbo.ICSITEMLot c ON a.LotNo_ID=c.ID AND a.WorkPoint=c.WorkPoint
|
|
LEFT JOIN dbo.ICSINVENTORY d ON c.ItemCODE=d.INVCODE AND a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN dbo.ICSPO_PoMain e ON c.TransNO=e.POCode AND c.TransLine =e.PORow AND a.WorkPoint=e.WorkPoint
|
|
WHERE a.CartonNO='" + CartonNo + "' and a.WorkPoint='" + WorkPoint + "'";
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
public DataTable GetASNListGridJson(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = @"SELECT a.ASNDETAILID, a.STNO,a.ITEMCODE,d.INVNAME,d.INVTYPE,d.INVDESC,h.ReMark,a.LOTNO,b.VenderLotNO,
|
|
b.LOTQTY,c.CartonNO,e.VENDORCODE,f.cVenName,
|
|
b.TransNO,b.TransLine,g.F_RealName,CONVERT(NVARCHAR(50),e.CREATETIME,23) as CREATETIME,d.INVSTD,d.INVPARSETYPE,case
|
|
when a.RECEIVEQTY is null then '否'
|
|
else '是'
|
|
end as IsReceive
|
|
|
|
FROM dbo.ICSASNDETAIL a
|
|
LEFT JOIN dbo.ICSITEMLot b ON a.LOTNO=b.LotNO AND a.WorkPoint=b.WorkPoint
|
|
LEFT JOIN dbo.ICSITEMLot2Carton c ON a.LOTNO=c.LotNO AND a.WorkPoint=c.WorkPoint
|
|
LEFT JOIN dbo.ICSINVENTORY d ON a.ITEMCODE=d.INVCODE AND a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN dbo.ICSASN e ON a.STNO=e.STNO AND a.WorkPoint=e.WorkPoint
|
|
LEFT JOIN dbo.ICSVendor f ON e.VENDORCODE=f.cVenCode AND a.WorkPoint=f.WorkPoint
|
|
LEFT JOIN dbo.Sys_SRM_User g ON e.LOGUSER=g.F_Account and g.F_Location=a.WorkPoint
|
|
LEFT JOIN dbo.ICSPO_PoMain h ON b.TransNO=h.POCode AND b.TransLine=h.PORow AND a.WorkPoint=h.WorkPoint where 1=1";
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["STNO"].ToString()))
|
|
{
|
|
sql += " and a.STNO like '%" + queryParam["STNO"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
|
|
{
|
|
sql += " and e.VENDORCODE like '%" + queryParam["VenCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
|
|
{
|
|
sql += " and f.cVenName like '%" + queryParam["VenName"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["BeginDate"].ToString()))
|
|
{
|
|
sql += " and e.CREATETIME >= '%" + queryParam["BeginDate"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["EndDate"].ToString()))
|
|
{
|
|
sql += " and e.CREATETIME <= '%" + queryParam["EndDate"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["VenderLotNO"].ToString()))
|
|
{
|
|
sql += " and b.VenderLotNO = '%" + queryParam["VenderLotNO"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["IsReceive"].ToString()))
|
|
{
|
|
string IsReceive = queryParam["IsReceive"].ToString();
|
|
if (IsReceive == "1")
|
|
{
|
|
sql += " and isnull(a.RECEIVEQTY,0) <>0 ";
|
|
}
|
|
else if (IsReceive == "2")
|
|
{
|
|
sql += " and isnull(a.RECEIVEQTY,0)=0 ";
|
|
}
|
|
}
|
|
}
|
|
//已改多站点
|
|
sql += " and a.WorkPoint in ('" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + "')";
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
|
|
{
|
|
sql += " and e.VENDORCODE='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
|
|
}
|
|
//DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
public DataTable GetASNListExport(string keyVaule)
|
|
{
|
|
//var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = @"SELECT a.STNO AS 送货单号,a.ITEMCODE 物料编码,d.INVNAME 物料名称,d.INVSTD AS 规格型号,
|
|
d.INVPARSETYPE AS 存货代码
|
|
,d.INVTYPE 描述1,d.INVDESC 描述2,h.ReMark 行备注,case
|
|
when a.RECEIVEQTY is null then '否'
|
|
else '是'
|
|
end as 是否到货,
|
|
a.LOTNO 条码,b.VenderLotNO 条码批次,
|
|
b.LOTQTY 数量,c.CartonNO 箱号,e.VENDORCODE 供应商编码,f.cVenName 供应商名称,
|
|
b.TransNO 采购单号,b.TransLine 采购单行,g.F_RealName 维护人, CONVERT(NVARCHAR(50),e.CREATETIME,23) as CREATETIME 维护时间
|
|
FROM dbo.ICSASNDETAIL a
|
|
LEFT JOIN dbo.ICSITEMLot b ON a.LOTNO=b.LotNO AND a.WorkPoint=b.WorkPoint
|
|
LEFT JOIN dbo.ICSITEMLot2Carton c ON a.LOTNO=c.LotNO AND a.WorkPoint=c.WorkPoint
|
|
LEFT JOIN dbo.ICSINVENTORY d ON a.ITEMCODE=d.INVCODE AND a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN dbo.ICSASN e ON a.STNO=e.STNO AND a.WorkPoint=e.WorkPoint
|
|
LEFT JOIN dbo.ICSVendor f ON e.VENDORCODE=f.cVenCode AND a.WorkPoint=f.WorkPoint
|
|
LEFT JOIN dbo.Sys_SRM_User g ON e.LOGUSER=g.F_Account
|
|
LEFT JOIN dbo.ICSPO_PoMain h ON b.TransNO=h.POCode AND b.TransLine=h.PORow AND a.WorkPoint=h.WorkPoint where 1=1";
|
|
sql += " and a.ASNDETAILID in (" + keyVaule + ")";
|
|
//已改多站点
|
|
sql += " and a.WorkPoint in ('" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + "')";
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
return dt;
|
|
}
|
|
|
|
public DataTable GetASNListExport(string ORDERNO, string STNO, string BeginDate, string EndDate, string VenCode, string VenName, string VenderLotNO, string IsReceive)
|
|
{
|
|
//var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string sql = @"SELECT a.STNO AS 送货单号,h.ORDERNO as 项目号,a.ITEMCODE 物料编码,d.INVNAME 物料名称,
|
|
d.INVSTD AS 规格型号,d.INVPARSETYPE AS 存货代码,
|
|
d.INVTYPE 描述1,d.INVDESC 描述2,h.ReMark 行备注,case
|
|
when a.RECEIVEQTY is null then '否'
|
|
else '是'
|
|
end as 是否到货,
|
|
a.LOTNO 条码,b.VenderLotNO 条码批次,
|
|
b.LOTQTY 数量,c.CartonNO 箱号,e.VENDORCODE 供应商编码,f.cVenName 供应商名称,
|
|
b.TransNO 采购单号,b.TransLine 采购单行,g.F_RealName 维护人,CONVERT(NVARCHAR(50),e.CREATETIME,23) as CREATETIME 维护时间
|
|
FROM dbo.ICSASNDETAIL a
|
|
LEFT JOIN dbo.ICSITEMLot b ON a.LOTNO=b.LotNO AND a.WorkPoint=b.WorkPoint
|
|
LEFT JOIN dbo.ICSITEMLot2Carton c ON a.LOTNO=c.LotNO AND a.WorkPoint=c.WorkPoint
|
|
LEFT JOIN dbo.ICSINVENTORY d ON a.ITEMCODE=d.INVCODE AND a.WorkPoint=d.WorkPoint
|
|
LEFT JOIN dbo.ICSASN e ON a.STNO=e.STNO AND a.WorkPoint=e.WorkPoint
|
|
LEFT JOIN dbo.ICSVendor f ON e.VENDORCODE=f.cVenCode AND a.WorkPoint=f.WorkPoint
|
|
LEFT JOIN dbo.Sys_SRM_User g ON e.LOGUSER=g.F_Account
|
|
LEFT JOIN dbo.ICSPO_PoMain h ON b.TransNO=h.POCode AND b.TransLine=h.PORow AND a.WorkPoint=h.WorkPoint where 1=1";
|
|
if (!string.IsNullOrWhiteSpace(ORDERNO))
|
|
sql += " and a.ORDERNO like '%" + ORDERNO + "%'";
|
|
if (!string.IsNullOrWhiteSpace(STNO))
|
|
sql += " and a.STNO like '%" + STNO + "%'";
|
|
if (!string.IsNullOrWhiteSpace(BeginDate))
|
|
sql += " and e.CREATETIME >= '" + BeginDate + "'";
|
|
if (!string.IsNullOrWhiteSpace(BeginDate))
|
|
sql += " and e.CREATETIME <= '" + EndDate + "'";
|
|
if (!string.IsNullOrWhiteSpace(VenCode))
|
|
sql += " and e.VENDORCODE like '%" + VenCode + "%'";
|
|
if (!string.IsNullOrWhiteSpace(VenCode))
|
|
sql += " and f.cVenName like '%" + VenName + "%'";
|
|
if (!string.IsNullOrWhiteSpace(VenderLotNO))
|
|
sql += " and b.VenderLotNO like '%" + VenderLotNO + "%'";
|
|
if (IsReceive == "1")
|
|
{
|
|
sql += " and isnull(a.RECEIVEQTY,0)<>0";
|
|
}
|
|
else if (IsReceive == "2")
|
|
{
|
|
sql += " and isnull(a.RECEIVEQTY,0)=0";
|
|
}
|
|
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
|
|
{
|
|
sql += " and e.VENDORCODE='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
|
|
}
|
|
//已改多站点
|
|
sql += " and a.WorkPoint in ('" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + "')";
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
return dt;
|
|
}
|
|
|
|
public string CheckIsAll(string STNO)
|
|
{
|
|
string sql = @"SELECT * FROM dbo.ICSASNDETAIL WHERE STNO='" + STNO + "' AND ISNULL(RECEIVEQTY,0)<>0";
|
|
//已改多站点
|
|
sql += " and WorkPoint in ('" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + "')";
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
return "0";
|
|
}
|
|
else
|
|
{
|
|
return "1";
|
|
}
|
|
}
|
|
}
|
|
}
|