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.
195 lines
8.9 KiB
195 lines
8.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Quartz;
|
|
|
|
using System.Data;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
|
|
namespace ICSSoft.FromERP
|
|
{
|
|
/// <summary>
|
|
/// 根据成品入库单自动入库
|
|
/// </summary>
|
|
public class ICSWareHouseLotInfoDoc : IJob
|
|
{
|
|
private static object key = new object();
|
|
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
public void Execute(IJobExecutionContext context)
|
|
{
|
|
try
|
|
{
|
|
lock (key)
|
|
{
|
|
log.Info("开始……………………………………………………………………");
|
|
Execute();
|
|
log.Info("结束……………………………………………………………………");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
|
|
public void Execute()
|
|
{
|
|
try
|
|
{
|
|
string conStr = ICSHelper.GetConnectString();
|
|
using (FramDataContext db = new FramDataContext(conStr))
|
|
{
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
//获取成品入库单
|
|
var manufactureReceives = db.ICSManufactureReceive.Where(e=>e.Status=="3"&&e.RCVQuantity==0).ToList();
|
|
//基础信息
|
|
DateTime time = DateTime.Now;
|
|
string user= "JOB";
|
|
string username = "JOB";
|
|
if (manufactureReceives.Any())
|
|
{
|
|
foreach (var data in manufactureReceives)
|
|
{
|
|
|
|
|
|
|
|
string invCode = data.InvCode;
|
|
string workPoint = data.WorkPoint;
|
|
decimal quantity = data.Quantity;
|
|
string rcvCode = data.RCVCode;
|
|
string sequence=data.Sequence;
|
|
var warehouse = db.ICSWarehouse.SingleOrDefault(e=>e.WarehouseCode==data.WHCode);
|
|
string location = db.ICSLocation.Where(e=>e.WHID== warehouse.ID&&e.WorkPoint==workPoint).FirstOrDefault()?.LocationCode;
|
|
string sql = $@"EXEC Addins_GetSerialCode '{workPoint}','ICSInventoryLot','LotNO','KCP{rcvCode}{sequence}',5;";
|
|
string lotNo;
|
|
if (data.IsSerialNumber == "ZS01")
|
|
{
|
|
var extention = db.ICSExtension.Where(e => e.ID==data.ExtensionID)?.SingleOrDefault();
|
|
if (extention!=null)
|
|
{
|
|
lotNo = extention.BatchCode;
|
|
}
|
|
else
|
|
{
|
|
lotNo = ICSHelper.ExecuteScalar(CommandType.Text, sql).ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lotNo = ICSHelper.ExecuteScalar(CommandType.Text, sql).ToString();
|
|
}
|
|
//条码
|
|
var inventoryLot = new ICSInventoryLot()
|
|
{
|
|
ID = AppConfig.GetGuid(),
|
|
LotNo = lotNo,
|
|
InvCode= invCode,
|
|
ProductDate=time,
|
|
ExpirationDate=time.AddYears(+100),
|
|
Quantity= quantity,
|
|
Amount=data.Amount,
|
|
ExtensionID=data.ExtensionID,
|
|
Type="9",
|
|
MUSER = user,
|
|
MUSERName = username,
|
|
MTIME = time,
|
|
WorkPoint = workPoint
|
|
|
|
};
|
|
//库存表
|
|
var wareHouseLotInfo = new ICSWareHouseLotInfo()
|
|
{
|
|
ID= AppConfig.GetGuid(),
|
|
LotNo= lotNo,
|
|
WarehouseCode=data.WHCode,
|
|
LocationCode=location,
|
|
InvCode= invCode,
|
|
Quantity= quantity,
|
|
InDate=time,
|
|
LockQuantity=0,
|
|
MUSER= user,
|
|
MUSERName= username,
|
|
MTIME=time,
|
|
WorkPoint= workPoint,
|
|
EATTRIBUTE1=""
|
|
|
|
};
|
|
//条码单据关联
|
|
var inventoryLotDetail = new ICSInventoryLotDetail()
|
|
{
|
|
LotNo = lotNo,
|
|
TransCode = rcvCode,
|
|
TransSequence= sequence,
|
|
MUSER=user,
|
|
MUSERName=username,
|
|
MTIME=time,
|
|
WorkPoint=workPoint,
|
|
EATTRIBUTE1=""
|
|
|
|
};
|
|
//出入库记录
|
|
var wareHouseLotInfoLog = new ICSWareHouseLotInfoLog()
|
|
{
|
|
ID= AppConfig.GetGuid(),
|
|
Identification= wareHouseLotInfo.ID,
|
|
TransCode= rcvCode,
|
|
TransSequence= sequence,
|
|
LotNo= lotNo,
|
|
InvCode= invCode,
|
|
FromWarehouseCode="",
|
|
FromLocationCode="",
|
|
ToWarehouseCode=data.WHCode,
|
|
ToLocationCode=location,
|
|
Quantity= quantity,
|
|
Memo="",
|
|
Lock=false,
|
|
TransType="2",
|
|
BusinessCode="18",
|
|
ERPUpload=false,
|
|
ERPID="",
|
|
ERPDetailID="",
|
|
ERPCode="",
|
|
ERPSequence="",
|
|
LogID="",
|
|
MergeID="",
|
|
MUSER=user,
|
|
MUSERName=username,
|
|
MTIME=time,
|
|
WorkPoint=workPoint
|
|
|
|
};
|
|
|
|
|
|
|
|
data.RCVQuantity = quantity;
|
|
db.ICSInventoryLot.InsertOnSubmit(inventoryLot);
|
|
db.ICSInventoryLotDetail.InsertOnSubmit(inventoryLotDetail);
|
|
db.ICSWareHouseLotInfo.InsertOnSubmit(wareHouseLotInfo);
|
|
db.ICSWareHouseLotInfoLog.InsertOnSubmit(wareHouseLotInfoLog);
|
|
}
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|