using Rhea.Common;
using Tiger.Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Newtonsoft.Json;
using Rhea.Common.Authorization;
using Newtonsoft.Json.Linq;
using Tiger.Model.Minsun;
using System.Globalization;
using System.Data;
using Tiger.IBusiness;
namespace Tiger.Business.WMS
{
public partial class iWMS
{
///
/// 通用批量入库
///
///
///
public static ApiAction MultiInStorageAsync(MultiInvInStorageInput input)
{
var action = new ApiAction();
try
{
string flag = "";
//保存到数据库
var db = Business.Biz.Db;
var dbTran = db.UseTran(() =>
{
//插入或更新 InvBarcode
var x = db.Storageable(input.InvBarcodes)
.WhereColumns(t => new { t.BARCODE })
.ToStorage();
x.AsInsertable.ExecuteCommand();
x.AsUpdateable.IgnoreColumns(t => t.Id).ExecuteCommand();
flag = "InvBarcode更新成功";
#region 插入 InvStorageLotInfo
var y = db.Storageable(input.InvStorageLotInfos)
.WhereColumns(t => new { t.BARCODE })
.ToStorage();
y.AsInsertable.ExecuteCommand();
y.AsUpdateable.IgnoreColumns(t => t.Id).ExecuteCommand();
flag += "; InvStorageLotInfo更新成功";
#endregion
#region 插入 InvStorageInfo
var z = db.Storageable(input.InvStorageInfos)
.WhereColumns(t => new { t.WAREHOUSECODE, t.MATERIALCODE })
.ToStorage();
z.AsInsertable.ExecuteCommand();
z.AsUpdateable.IgnoreColumns(t => t.Id).ExecuteCommand();
#endregion
flag += "; InvStorageInfo更新成功";
#region 插入 InvScanMain 和 InvScanDetail
var m = db.Storageable(input.InvScanMains)
.ToStorage();
m.AsInsertable.IgnoreColumns(t => t.LastModificationTime).ExecuteCommand();
var o = db.Storageable(input.InvScanDetails)
.WhereColumns(t => new { t.SCANMAINID, t.SOURCEDETAILLINE, t.WAREHOUSECODE, t.MATERIALCODE })
.ToStorage();
o.AsInsertable.ExecuteCommand();
o.AsUpdateable.IgnoreColumns(t => t.Id).ExecuteCommand();
#endregion
flag += "; InvScanMain更新成功";
#region 插入 InvBarcodeLog
db.Insertable(input.InvBarcodeLogs).ExecuteCommand();
#endregion
flag += "; 入库成功";
});
if (!dbTran.IsSuccess)
{
action.IsSuccessed = false;
action.Message = $"{flag} Error:{dbTran.ErrorException.Message}";
action.Data = new MultiInvInStorageOutput
{
Message = $"{flag} Error:{dbTran.ErrorException.Message}",
InvBarcodes = input.InvBarcodes
};
//throw dbTran.ErrorException;
}
}
catch (System.Exception ex)
{
action.CatchExceptionWithLog(ex, $"入库异常");
}
action.Message = "OK";
action.Data = new MultiInvInStorageOutput
{
Message = "OK",
InvBarcodes = input.InvBarcodes
};
return action;
}
///
/// 获得到货单完成信息
///
///
///
///
public static string GetERP_RECEIPTTips(string billcode, string materialCode)
{
var tips = "";
var otherInDetails = Biz.Db.Queryable().Where(t => t.BILLCODE.ToUpper() == billcode.ToUpper()
&& t.ITEM_CODE.ToUpper() == materialCode.ToUpper()
&& t.STATUS <= WMS_ITEM.STATUSs.WaitIn.GetValue()).ToList();
//if (otherInDetails.Any())
{
tips += $"数量:{otherInDetails.Sum(q => q.SCANQTY):N0}";
}
var otherInScanList = Biz.Db.Queryable().Where(t => t.BILLCODE.ToUpper() == billcode.ToUpper()
&& t.STATUS <= WMS_ITEM.STATUSs.WaitIn.GetValue()
&& t.ITEM_CODE.ToUpper() == materialCode.ToUpper()).ToList();
//if (otherInScanList.Any())
{
tips += $" ({otherInScanList.Count()} 盘)";
}
return tips;
}
///
/// 获得到货单完成信息
///
///
///
///
public static string GetERP_ReturnTips(string billcode, string materialCode)
{
var tips = "";
var otherInDetails = Biz.Db.Queryable().Where(t => t.BUSINESSCODE.ToUpper() == billcode.ToUpper()
//&& t.ITEM_CODE.ToUpper() == materialCode.ToUpper()
&& t.STATUS <= WMS_ITEM.STATUSs.WaitIn.GetValue()).ToList();
//if (otherInDetails.Any())
{
tips += $"数量:{otherInDetails.Sum(q => q.QTY):N0}";
}
var otherInScanList = Biz.Db.Queryable().Where(t => t.BUSINESSCODE.ToUpper() == billcode.ToUpper()
&& t.STATUS <= WMS_ITEM.STATUSs.WaitIn.GetValue()
//&& t.ITEM_CODE.ToUpper() == materialCode.ToUpper()
).ToList();
//if (otherInScanList.Any())
{
tips += $" ({otherInScanList.Count()} 盘)";
}
return tips;
}
///
/// 获得其他入库单完成信息
///
///
///
///
public static string GetERP_OTH_INTips(string billcode, string materialCode)
{
var tips = "";
var otherInDetails = Biz.Db.Queryable().Where(t => t.BILLCODE.ToUpper() == billcode.ToUpper()
&& t.ITEM_CODE.ToUpper() == materialCode.ToUpper()
&& t.LINESTATUS == BIZ_ERP_OTH_IN.STATUSs.WORKING.GetValue()).OrderBy(t => new { t.BILLCODE, t.BILLLINE }).ToList();
//if (otherInDetails.Any())
{
tips += $"数量:{otherInDetails.Sum(q => q.PRQTY - q.QTY):N0}";
}
var otherInScanList = Biz.Db.Queryable().Where(t => t.BUSINESSCODE.ToUpper() == billcode.ToUpper()
&& t.STATUS <= WMS_ITEM.STATUSs.WaitIn.GetValue()
&& t.ITEM_CODE.ToUpper() == materialCode.ToUpper()).ToList();
//if (otherInScanList.Any())
{
tips += $" ({otherInScanList.Count()} 盘)";
}
return tips;
}
///
/// 获得其他入库单完成信息
///
///
///
///
public static string GetFinishedTips(string billcode, string materialCode)
{
var tips = "";
var otherInDetails = Biz.Db.Queryable().Where(t => t.BILLCODE.ToUpper() == billcode.ToUpper()
&& t.ITEM_CODE.ToUpper() == materialCode.ToUpper()
&& t.LINESTATUS == BIZ_ERP_OTH_IN.STATUSs.WORKING.GetValue()).OrderBy(t => new { t.BILLCODE, t.BILLLINE }).ToList();
//if (otherInDetails.Any())
{
tips += $"数量:{otherInDetails.Sum(q => q.PRQTY - q.INVENTORYQTY):N0}";
}
var otherInScanList = Biz.Db.Queryable().Where(t => t.BUSINESSCODE.ToUpper() == billcode.ToUpper()
&& t.STATUS <= WMS_ITEM.STATUSs.WaitIn.GetValue()
&& t.ITEM_CODE.ToUpper() == materialCode.ToUpper()).ToList();
//if (otherInScanList.Any())
{
tips += $" ({otherInScanList.Count()} 盘)";
}
return tips;
}
///
/// 获得其他入库单完成信息
///
///
///
///
public static string GetBIZ_ERP_PROD_INips(string billcode)
{
var tips = "";
//var otherInDetails = Biz.Db.Queryable().Where(t => t.BILLCODE.ToUpper() == billcode.ToUpper()
// && t.ITEM_CODE.ToUpper() == materialCode.ToUpper()
// && t.LINESTATUS == BIZ_ERP_OTH_IN.STATUSs.WORKING.GetValue()).OrderBy(t => new { t.BILLCODE, t.BILLLINE }).ToList();
////if (otherInDetails.Any())
//{
// tips += $"数量:{otherInDetails.Sum(q => q.PRQTY - q.QTY):N0}";
//}
var otherInScanList = Biz.Db.Queryable().Where(t => t.BUSINESSCODE.ToUpper() == billcode.ToUpper()
&& t.STATUS <= WMS_ITEM.STATUSs.WaitIn.GetValue()).ToList();
//if (otherInScanList.Any())
{
tips += $" 总数:({otherInScanList.Count()})";
}
return tips;
}
///
/// 获得完成信息
///
///
///
///
public static string GetIncompleteTips(string billcode, string materialCode)
{
var tips = "";
var otherInDetails = Biz.Db.Queryable().Where(t => t.BILLCODE.ToUpper() == billcode.ToUpper()
&& t.MATERIALCODE.ToUpper() == materialCode.ToUpper()
&& t.LINESTATUS == OtherInstockSides.Status.WORKING.ToString()).OrderBy(t => new { t.BILLCODE, t.BILLLINE }).ToList();
if (otherInDetails.Any())
{
tips += $"数量:{otherInDetails.Sum(q => q.PRQTY - q.QTY):N0}";
}
var otherInScanList = Biz.Db.Queryable().Where(t => t.BUSINESSCODE.ToUpper() == billcode.ToUpper()
&& t.MATERIALCODE.ToUpper() == materialCode.ToUpper()).OrderBy(t => new { t.BUSINESSCODE, t.BUSINESSLINE }).ToList();
if (otherInScanList.Any())
{
tips += $" ({otherInScanList.Count()} 盘)";
}
return tips;
}
///
/// 客供料入库完成信息
///
///
///
public static async Task CustSupplyInIncompleteList(CustSupplyIncompleteInput input)
{
var otherInScanList = await Biz.Db.Queryable()
.Where(t => t.BUSINESSCODE.ToUpper() == input.receiptNo.ToUpper()
&& t.MATERIALCODE.ToUpper() == input.materialCode.ToUpper())
.ToListAsync();
var incompleteList = otherInScanList.OrderBy(q => q.STATUS == "Billed" ? 1 : (q.STATUS == "Complete" ? 3 : 2))
.Select(q => new
{
Barcode = q.BARCODE,
Qty = (int)q.QTY,
Status = q.STATUS == "Billed" ? "待入库" : (q.STATUS == "Complete" ? "已入库" : $"其他({q.STATUS})")
});
return new CustSupplyInOutput() { result = JsonConvert.SerializeObject(incompleteList) };
}
}
}