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.
 
 
 
 
 

244 lines
10 KiB

using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using NFine.Code;
using NFine.Data.Extensions;
using NFine.Domain._03_Entity.SRM;
using NFine.Repository;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Common;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using NFine.Application.Entity;
using NFine.Application.Models;
using NFine.Application.WMS;
using System.Web.UI.WebControls;
using System.Net.NetworkInformation;
using System.Collections;
using System.Xml;
using NFine.Domain._03_Entity.WMS;
namespace NFine.Application.HGWMS
{
public class ICSTransferApp : RepositoryFactory<ICSVendor>
{
public static DataTable Invmes = new DataTable();
/// <summary>
/// 获取仓库库位信息
/// </summary>
/// <param name="queryJson"></param>
/// <param name="jqgridparam"></param>
/// <returns></returns>
public DataTable GetLocationCode(string queryJson, ref Pagination jqgridparam)
{
//站点信息
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
DataTable dt = new DataTable();
List<DbParameter> parameter = new List<DbParameter>();
var queryParam = queryJson.ToJObject();
object Figure = GetDecimalDigits();
#region [SQL]
string sql = $@" SELECT a.WarehouseCode,a.WarehouseName,b.LocationCode,b.LocationName,b.ID
FROM ICSWarehouse a
LEFT JOIN ICSLocation b ON a.ID=b.WHID
WHERE 1=1 ";
sql = string.Format(sql, Figure);
sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
#endregion
if (!string.IsNullOrWhiteSpace(queryJson))
{
if (!string.IsNullOrWhiteSpace(queryParam["WarehouseCode"].ToString()))
{
sql += " and a.WarehouseCode like '%" + queryParam["WarehouseCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["LocationCode"].ToString()))
{
sql += " and b.LocationCode like '%" + queryParam["LocationCode"].ToString() + "%' ";
}
}
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
{
sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
}
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public object GetDecimalDigits()
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
try
{
string sql = string.Empty;
sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
object Figure = SqlHelper.ExecuteScalar(sql);
return Figure;
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
/// <summary>
/// 订单备料明细查询
/// </summary>
/// <param name="jqgridparam"></param>
/// <returns></returns>
public DataTable GetMOIssueApplyNegDetail(string RCVCode, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
//object Figure = GetDecimalDigits();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @"SELECT a.ID,a.RCVCode,a.Sequence,a.SourceSequence,a.SourceCode,a.InvCode,a.Quantity,a.Amount,a.RCVQuantity,a.WHCode,e.WarehouseName as WHName,a.Type
,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,b.InvName,a.CreateDateTime,a.CreatePerson
,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10
from ICSManufactureReceive a
left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
where a.RCVCode = '" + RCVCode + "' ";
//sql = string.Format(sql, Figure);
DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public void ClearTemp()
{
Invmes.Rows.Clear();
}
public string ICSMOIssueSendBackAuditRollback(string keyValue)
{
return "";
}
/// <summary>
/// 创建一步调拨单
/// </summary>
/// <param name="keyValue"></param>
/// <returns></returns>
public string AddICSTransfer(string keyValue)
{
string returnValue = string.Empty;
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
var sql = string.Empty;
try
{
var key = keyValue.ToJObject();
//验证是否同一个供应商
sql = $@"SELECT DISTINCT WarehouseCode FROM ICSWareHouseLotInfo where LotNo in ({key["Lots"]}) AND WorkPoint ='{WorkPoint}' ";
var dt1 = SqlHelper.CmdExecuteDataTable(sql);
if (dt1.Rows.Count>1|| dt1.Rows.Count<=0)
{
throw new Exception("创建调拨单的条码必须是同一个供应商的物料,操作失败");
}
TransferINHead addICSTransfer = new TransferINHead();
List<TransferINBody> transferINBodies = new List<TransferINBody>();
//查询单据信息
sql = $@"SELECT Sum(Quantity) Quantity,WarehouseCode OutWhCode,LocationCode OutBinCode,InvCode from ICSWareHouseLotInfo WHERE LotNo in ({key["Lots"]}) AND WorkPoint='{WorkPoint}' GROUP BY WarehouseCode,LocationCode,InvCode ";
var dt = SqlHelper.CmdExecuteDataTable(sql);
if (dt.Rows.Count <= 1)
{
throw new Exception("条码信息有误请确认,操作失败");
}
addICSTransfer.DocDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
addICSTransfer.OrgCode = WorkPoint;
for (int i=0;i< dt.Rows.Count; i++)
{
TransferINBody transferINBody =
new TransferINBody
{
Quantity = (dt.Rows[i]["Quantity"]).ToDecimal(),
InvCode = dt.Rows[i]["InvCode"].ToString(),
OutWhCode = dt.Rows[i]["OutWhCode"].ToString(),
OutBinCode = dt.Rows[i]["OutBinCode"].ToString(),
//SupplierCode = dt.Rows[0]["VenCode"].ToString(),
INWhCode = key["WarehouseCode"].ToString(),
INBinCode = key["LocationCode"].ToString(),
Sequence = i + 1
};
transferINBodies.Add(transferINBody);
}
addICSTransfer.details = transferINBodies;
#region 调用ERP接口
if (!addICSTransfer.IsEmpty())
{
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "U9OneStepTransferDocIn/Create";
var erpinput = JsonConvert.SerializeObject(addICSTransfer);
string result1 = HttpPost(APIURL, erpinput);
JObject Obj = (JObject)JsonConvert.DeserializeObject(result1);//或者JObject jo = JObject.Parse(jsonText);
string MessAge = Obj["Message"].ToString();
string Success = Obj["Success"].ToString();
if (Success.ToUpper() == "FALSE")
{
throw new Exception(MessAge);
}
}
#endregion
return "";
}
catch (Exception ex)
{
return ex.Message;
}
}
//接口api解析
public static string HttpPost(string url, string body)
{
try
{
Encoding encoding = Encoding.UTF8;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
request.ContentType = "application/json; charset=utf-8";
byte[] buffer = encoding.GetBytes(body);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
{
return reader.ReadToEnd();
}
}
catch (WebException ex)
{
throw new Exception(ex.Message);
}
}
}
/// <summary>
/// api/Rd1011/Approve 调用产成品入库单、材料出库单审核
/// </summary>
public class ApproveInput
{
public string ID { get; set; }//ID
public string User { get; set; }//用户
public string Type { get; set; }//类型(入库,倒冲)
public string WorkPoint { get; set; }//站点
public bool UpdateStock { get; set; }//是否更新现存量
public DateTime MTime { get; set; }//时间
public bool UpdateTodoQuantity { get; set; }//更新待出入数量
}
}