535 lines
15 KiB
C#
535 lines
15 KiB
C#
|
|
/// <summary>
|
|
///LOGIC CLASS FOR TABLE t_wmsStockPandian
|
|
///By wm with codesmith.
|
|
///on 07/27/2018
|
|
/// </summary>
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using DeiNiu.wms.Data.Model;
|
|
using System.Data;
|
|
using System.Transactions;
|
|
using DeiNiu.Utils;
|
|
|
|
namespace DeiNiu.wms.Logical
|
|
{
|
|
[Serializable]
|
|
public class lWmsStockPandian :lbase
|
|
{
|
|
|
|
public lWmsStockPandian()
|
|
{
|
|
initialize();
|
|
}
|
|
WmsStockPandian _obj;
|
|
public WmsStockPandian getWmsStockPandian
|
|
{
|
|
get
|
|
{
|
|
if (_obj == null)
|
|
{
|
|
_obj = new WmsStockPandian();
|
|
|
|
}
|
|
_obj.operater = operId;
|
|
return _obj;
|
|
}
|
|
}
|
|
|
|
WmsStockPandianResult _pandianItem;
|
|
public WmsStockPandianResult getWmsStockPandianResult
|
|
{
|
|
get
|
|
{
|
|
if (_pandianItem == null)
|
|
{
|
|
_pandianItem = new WmsStockPandianResult();
|
|
|
|
}
|
|
_pandianItem.operater = operId;
|
|
return _pandianItem;
|
|
}
|
|
}
|
|
|
|
public lWmsStockPandian(int operId)
|
|
: base(operId)
|
|
{
|
|
initialize();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// get all data
|
|
/// </summary>
|
|
public DataSet getAllData()
|
|
{
|
|
return _obj.Query();
|
|
}
|
|
|
|
/// <summary>
|
|
/// get all data
|
|
/// </summary>
|
|
public DataSet getAllActiveData()
|
|
{
|
|
return _obj.QueryActived();
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// get a record by id
|
|
/// </summary>
|
|
public void initialize(int id)
|
|
{
|
|
_obj = id != 0 ? new WmsStockPandian(id) : new WmsStockPandian();
|
|
_obj.operater = operId;
|
|
}
|
|
|
|
/// <summary>
|
|
/// get a record by id 0
|
|
/// </summary>
|
|
public void initialize()
|
|
{
|
|
initialize(0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// get a record by id
|
|
/// </summary>
|
|
public void initialize(DataRow dr)
|
|
{
|
|
_obj = new WmsStockPandian(dr);
|
|
_obj.operater = operId;
|
|
}
|
|
|
|
protected override DeiNiu.Data.BaseObject.BaseModel getModel()
|
|
{
|
|
return _obj;
|
|
}
|
|
|
|
//begin cust db operation, query, excute sql etc.
|
|
|
|
|
|
/// <summary>
|
|
/// update in a transaction scrop
|
|
/// </summary>
|
|
|
|
public void update()
|
|
{
|
|
if (valid())
|
|
{
|
|
using (TransactionScope scope = new TransactionScope())
|
|
{
|
|
|
|
//Node tmp = new Node();
|
|
//tmp.parentid = 1;
|
|
//tmp.name = "test trans" + DateTime.Now;
|
|
//tmp.description = "this is for transTest";
|
|
//tmp.Add();
|
|
_obj.Update();
|
|
|
|
scope.Complete();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool valid()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public string createPanOrder(int panType, bool noticeErp, int createBy,string inputValues, string stockCondition)
|
|
{
|
|
WmsStockPandian pandian = new WmsStockPandian();
|
|
|
|
pandian.orderNo = Utils.Util.getOrderNo(Utils.enumCreateOrderType.pandianOrder,pandian.getNextSeq(enumCreateOrderType.pandianOrder));
|
|
pandian.condition = stockCondition;
|
|
pandian.createby = createBy;
|
|
pandian.operater = operId;
|
|
pandian.type = panType;
|
|
pandian.inputValus = inputValues;
|
|
pandian.noticeErp = noticeErp;
|
|
pandian.status = 0;
|
|
pandian.Add();
|
|
return pandian.orderNo;
|
|
|
|
}
|
|
|
|
public bool startPandian(string orderNo)
|
|
{
|
|
WmsStockPandian pandian = new WmsStockPandian(orderNo);
|
|
|
|
if (pandian.ID > 0 && pandian.status ==(int) enumPandianStatus.未开始)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
using (TransactionScope scope = new TransactionScope())
|
|
{
|
|
pandian.status = (int)enumPandianStatus.开始采集;
|
|
string sqlWhere =pandian.getCondition(pandian.condition);
|
|
|
|
sqlWhere += pandian.getPlusCondition();
|
|
|
|
logPandian.Debug(" condition: " + sqlWhere);
|
|
|
|
int cnt= pandian.createDetailMirror(sqlWhere);
|
|
|
|
|
|
|
|
pandian.updateStockStatus(enumStockLocationStatus.盘点锁定, sqlWhere);
|
|
|
|
pandian.startTime = pandian.getDateTime();
|
|
pandian.Update();
|
|
|
|
|
|
WmsFlow wmsflow = new WmsFlow();
|
|
wmsflow.operater = operId;
|
|
wmsflow.orderNo = pandian.orderNo;
|
|
wmsflow.flowNo = pandian.orderNo;
|
|
wmsflow.type = (int)EnumFlowTaskType.盘点采集;
|
|
wmsflow.typeName = EnumFlowTaskType.盘点采集.ToString();
|
|
wmsflow.task = pandian.orderNo; // Util.getOrderNo(enumCreateOrderType.pickJobNo, _obj.getNextSeq(enumCreateOrderType.pickJobNo));
|
|
wmsflow.taskCnt = cnt;
|
|
wmsflow.Add();
|
|
|
|
|
|
scope.Complete();
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
public bool delPandian(string orderNo)
|
|
{
|
|
WmsStockPandian pandian = new WmsStockPandian(orderNo);
|
|
|
|
if (pandian.ID > 0 && pandian.status == (int)enumPandianStatus.未开始)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return pandian.Delete() >0;
|
|
|
|
}
|
|
|
|
public bool finishPandian(string orderNo)
|
|
{
|
|
WmsStockPandian pandian = new WmsStockPandian(orderNo);
|
|
pandian.operater = operId;
|
|
pandian.status = (int)enumPandianStatus.盘点结束;
|
|
pandian.endTime = pandian.getDateTime();
|
|
bool ret = true;
|
|
using (TransactionScope scope = new TransactionScope())
|
|
{
|
|
ret = pandian.Update() > 0;
|
|
|
|
ret = ret && pandian.finishPandian(orderNo, pandian.getCondition(pandian.condition));
|
|
if (pandian.noticeErp)
|
|
{
|
|
WmsOrderRequest wor = pandian.createErpOrder();
|
|
new lWmsOutPickRequest(operId).noticeErpOrder(wor);
|
|
|
|
}
|
|
WmsFlow flow = new WmsFlow(pandian.orderNo);
|
|
flow.finishedCnt = flow.taskCnt;
|
|
flow.state = (int)enumFlowTaskStatus.已完成;
|
|
flow.Update();
|
|
scope.Complete();
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
internal bool adjustPandianStock(string orderNo, bool isRollBack)
|
|
{
|
|
WmsStockPandianAdjust wpa;
|
|
WmsStock wstk;
|
|
decimal factor = isRollBack ? 1 : -1 ;
|
|
DataTable dt = getWmsStockPandian.getPandianBanlanceDetail(orderNo);
|
|
WmsStockPandian wsp = new WmsStockPandian(orderNo);
|
|
|
|
wsp.adjustStatus =isRollBack ?(int)enumPandianAdjustStatus.未校正 : (int)enumPandianAdjustStatus.已校正;
|
|
wsp.operater = operId;
|
|
|
|
DataView dv = dt.DefaultView;
|
|
dv.Sort = "data " + (isRollBack ? "desc" : "asc");
|
|
|
|
using (TransactionScope scope = new TransactionScope())
|
|
{
|
|
wsp.Update();
|
|
|
|
if (isRollBack)
|
|
{
|
|
getWmsStockPandian.deleteAdjust(orderNo);
|
|
}
|
|
|
|
foreach (DataRowView dr in dv)
|
|
{
|
|
WmsStockRecord r = new WmsStockRecord();
|
|
|
|
wpa = new WmsStockPandianAdjust(dr.Row);
|
|
|
|
wpa.operater = operId;
|
|
|
|
r.count = wpa.count;
|
|
|
|
//删除旧库存记录
|
|
wstk = new WmsStock( wpa.locationId,wpa.skuId,wpa.goodsId);
|
|
wstk.Delete();
|
|
wstk = new WmsStock(dr.Row);
|
|
wstk.operater = operId;
|
|
logPandian.Debug(string.Format("isRollback? {0}, wpa.data {1}", isRollBack, wpa.data));
|
|
|
|
if (!isRollBack)
|
|
{
|
|
r.description = "盘点调整";
|
|
wpa.Add();
|
|
|
|
if (wpa.data == 0) //mirror
|
|
{
|
|
|
|
r.count = r.count * -1; //减库存
|
|
}
|
|
else
|
|
{
|
|
|
|
wstk.Add();
|
|
logPandian.Debug("applied pandian result..." + wstk);
|
|
}
|
|
}
|
|
else //回退
|
|
{
|
|
r.description = "回退调整";
|
|
if (wpa.data == 1)//采集
|
|
{
|
|
r.count = r.count * -1;//减库存
|
|
}
|
|
else
|
|
{
|
|
wstk.Add();
|
|
|
|
logPandian.Debug("rollback pandian result..." + wstk);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
r.goodsId = wpa.goodsId.Trim();
|
|
r.locationId = wpa.locationId.Trim();
|
|
r.productDate = wpa.productDate;
|
|
r.validDate = wpa.validDate;
|
|
r.orderNo = wpa.orderNo.Trim();
|
|
r.rectype = (int)enumStockRecordType.盘点调整;
|
|
r.operater = this.operId;
|
|
r.Add();
|
|
|
|
}
|
|
|
|
scope.Complete();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
internal bool newPandianItem(string orderNo, string locationId, int mirrroId, string goodsId, string prdDate, string batch, decimal count)
|
|
{
|
|
|
|
logPandian.Debug(string.Format(" new pandian item: orderNo {0},locationId {1},mirrroId {2},goodsId {3},prdDate {4},batch{5},count {6}", orderNo, locationId, mirrroId, goodsId, prdDate, batch, count));
|
|
|
|
|
|
WmsStockPandian wsp = new WmsStockPandian(orderNo);
|
|
if(wsp.status != (int)enumPandianStatus.开始采集)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
|
|
int skuId = 0;
|
|
|
|
WmsStockPandianResult wr;
|
|
string dtValid = prdDate;
|
|
WmsGoods wg = new WmsGoods(goodsId);
|
|
if (wg.ID ==0)
|
|
{
|
|
throw new Exception("未知商品");
|
|
}
|
|
DateTime dtprd = Util.pareseDateString(prdDate);
|
|
dtValid = (getValidDate(prdDate, wg.goodsId)).ToShortDateString();
|
|
Dictionary<string, string> skuValues = new Dictionary<string, string>();
|
|
skuValues[WmsConstants.SKU_RESEVRED_BATCH_ATTNAME] = batch;
|
|
skuValues[WmsConstants.SKU_RESEVRED_EXPIREDATE_ATTNAME] = dtValid;
|
|
skuValues[WmsConstants.SKU_RESEVRED_PRDDATE_ATTNAME] = dtprd.ToShortDateString();
|
|
|
|
Dictionary<int, string> dic = new lLot().getSKU(skuValues, wg.goodsId);
|
|
|
|
|
|
foreach (int i in dic.Keys)
|
|
{
|
|
skuId = i;
|
|
|
|
break;
|
|
}
|
|
|
|
wr = new WmsStockPandianResult(orderNo, locationId, skuId);
|
|
|
|
logPandian.Debug(" to add new pandian item: " + wr);
|
|
|
|
wr.goodsId = wg.goodsId;
|
|
wr.validDate = dtValid;
|
|
wr.batch = batch;
|
|
wr.mirrorId = mirrroId;
|
|
wr.productDate = prdDate;
|
|
|
|
|
|
wr.orderNo = orderNo;
|
|
wr.locationId = locationId.ToUpper();
|
|
wr.skuId = skuId;
|
|
wr.avCount = count;
|
|
|
|
wr.operater = operId;
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
if (wr.ID > 0)
|
|
{
|
|
cnt= wr.Update() ;
|
|
}
|
|
else
|
|
cnt= wr.Add() ;
|
|
|
|
logPandian.Debug(" done... new pandian result: " + wr +" , success? " +(cnt > 0));
|
|
|
|
return cnt > 0;
|
|
|
|
}
|
|
|
|
internal bool stopPandianPick(string orderNo)
|
|
{
|
|
WmsStockPandian pandian = new WmsStockPandian(orderNo);
|
|
pandian.operater = operId;
|
|
pandian.status = (int)enumPandianStatus.采集结束;
|
|
return pandian.Update() > 0;
|
|
}
|
|
|
|
internal DataTable getPandianResultItem(string orderNo, string locationId)
|
|
{
|
|
return getWmsStockPandianResult.getPandianItem(orderNo,locationId);
|
|
}
|
|
|
|
internal int postPandianItem(int mirrorId, decimal count)
|
|
{
|
|
|
|
|
|
WmsStockPandianStockMirror wps = new WmsStockPandianStockMirror(mirrorId);
|
|
|
|
WmsStockPandian wsp = new WmsStockPandian(wps.orderNo);
|
|
if (wsp.status != (int)enumPandianStatus.开始采集)
|
|
{
|
|
return 0;
|
|
}
|
|
WmsFlow flow = new WmsFlow(wps.orderNo);
|
|
flow.finishedCnt++;
|
|
|
|
flow.Update();
|
|
|
|
WmsStockPandianResult wr = new WmsStockPandianResult();
|
|
|
|
wr.batch=wps.batch;
|
|
wr.goodsId = wps.goodsId;
|
|
wr.productDate = wps.productDate;
|
|
wr.validDate = wps.validDate;
|
|
wr.skuCode = wps.skuCode;
|
|
wr.skuId = wps.skuId;
|
|
wr.avCount = count;
|
|
wr.locationId = wps.locationId;
|
|
wr.orderNo = wps.orderNo;
|
|
wr.operater = operId;
|
|
wr.mirrorId = mirrorId;
|
|
|
|
return wr.Add();
|
|
|
|
|
|
|
|
}
|
|
|
|
internal DataTable getPandianTargetItem(string orderNo, string locationId)
|
|
{
|
|
WmsStockPandian wsp = new WmsStockPandian(orderNo);
|
|
if (wsp.status != (int)enumPandianStatus.开始采集)
|
|
{
|
|
return new DataTable("Noitem");
|
|
}
|
|
|
|
return getWmsStockPandian.getPandianTargetItem(orderNo, locationId);
|
|
}
|
|
|
|
internal DataTable getPandianTargetItems(string orderNo )
|
|
{
|
|
return getWmsStockPandian.getPandianTargetItems(orderNo );
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---test pandian
|
|
|
|
public void testPandian()
|
|
{
|
|
logTest.Debug("start pandian process test...");
|
|
//create order
|
|
|
|
int type =new Random().Next(0,3);
|
|
|
|
string orderNo = createPanOrder(type, true, 282, "whType = #0;state = #0;", "");
|
|
|
|
logTest.Debug(" created pandian order " + orderNo);
|
|
;
|
|
|
|
logTest.Debug("start pandian pick....." + startPandian(orderNo));
|
|
|
|
DataTable dt= getPandianTargetItems(orderNo);
|
|
|
|
foreach(DataRow dr in dt.Rows)
|
|
{
|
|
WmsStockPandianStockMirror wps = new WmsStockPandianStockMirror(dr);
|
|
|
|
postPandianItem(wps.ID, wps.shelfCount);
|
|
//newPandianItem(orderNo,wps.locationId,wps.ID,)
|
|
|
|
}
|
|
|
|
|
|
logTest.Debug("stopped pandian pick " + stopPandianPick(orderNo));
|
|
|
|
logTest.Debug("adjusted pandian result " + adjustPandianStock(orderNo, false));
|
|
|
|
logTest.Debug("finish pandian " + finishPandian(orderNo ));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|