Files
U8-Import/NX.ERP.U8/Store/MaterielStoreOutDAL.cs
2021-05-17 15:40:43 +08:00

351 lines
14 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using MSXML2;
using NX.ERP.Model.Store;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UFIDA.U8.U8APIFramework;
using UFIDA.U8.U8APIFramework.Parameter;
using UFIDA.U8.U8MOMAPIFramework;
namespace NX.ERP.U8.Store
{
public class MaterialStoreOutDAL : VoucherBase
{
public MaterialStoreOutDAL() : base("11", "U8API/MaterialOut")
{
}
private void ByMaterialApp(Model.Request.MaterialStoreOut storeOut, IXMLDOMElement headXml, DOMDocument domBody)
{
var metailApp = new U8.Store.MaterialAppVoucher().GetModel(storeOut.SourceCode);
if (metailApp == null)
{
throw new Exception("未知的领料申请单");
}
headXml.setAttribute("cbustype", "领料");
string lastProductNo = null;
headXml.setAttribute("crdname", "材料出库");
IXMLDOMElement bodyXml;
for (var n = 0; n < storeOut.Details.Count(); n++)
{
bodyXml = domBody.createElement("z:row");
bodyXml.setAttribute("inquantity", "");
bodyXml.setAttribute("innum", "");
bodyXml.setAttribute("imaids","");
bodyXml.setAttribute("imoseq","");
bodyXml.setAttribute("crejectcode", "");
bodyXml.setAttribute("iOMoMID", "");
bodyXml.setAttribute("iopseq", "");
bodyXml.setAttribute("copdesc", "");
bodyXml.setAttribute("invcode", "");
bodyXml.setAttribute("cMoLotCode", "");
bodyXml.setAttribute("cmocode", "");
bodyXml.setAttribute("iMPoIds", "");
bodyXml.setAttribute("comcode", "");
bodyXml.setAttribute("iOMoDID", "");
bodyXml.setAttribute("cciqbookcode", "");
bodyXml.setAttribute("cmworkcentercode", "");
bodyXml.setAttribute("cservicecode", "");
bodyXml.setAttribute("isotype", "");
bodyXml.setAttribute("csocode", "");
bodyXml.setAttribute("isodid", "");
bodyXml.setAttribute("isoseq", "");
bodyXml.setAttribute("iordertype", "");
bodyXml.setAttribute("iordercode", "");
bodyXml.setAttribute("iorderdid", "");
bodyXml.setAttribute("iorderseq", "");
bodyXml.setAttribute("ipesotype", "");
bodyXml.setAttribute("cpesocode", "");
bodyXml.setAttribute("ipesodid", "");
bodyXml.setAttribute("ipesoseq", "");
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
}
headXml.setAttribute("cpspcode", lastProductNo);
}
/// <summary>
/// 生产订单出库
/// </summary>
/// <param name="storeOut"></param>
/// <param name="headXml"></param>
/// <param name="domBody"></param>
private void ByMomOrder(Model.Request.MaterialStoreOut storeOut, IXMLDOMElement headXml, DOMDocument domBody)
{
headXml.setAttribute("cbustype", "领料");
var Order = new Mom.MomOrderDAL().GetModel(storeOut.SourceCode);
if (Order == null)
{
throw new Exception($"未知订单:{storeOut.SourceCode}");
}
headXml.setAttribute("iproorderid", Order.ProductOrderId);
headXml.setAttribute("cmpocode", Order.ProductOrderNo);
string lastProductNo = null;
headXml.setAttribute("crdname", "材料出库");
IXMLDOMElement bodyXml;
for (var n = 0; n < storeOut.Details.Count(); n++)
{
var detail = storeOut.Details[n];
var alllocate = Order.Allocates.FirstOrDefault(m => { return m.AllocateId == detail.SorceDetailId; });
if (alllocate == null)
{
throw new Exception($"未知订单明细行:{detail.SorceDetailId}");
}
if (alllocate.MaterialCode != detail.InvCode)
{
throw new Exception($"订单明细存货编号与出库存货编号不符:{detail.InvCode}");
}
var moomDetail = Order.ProductDtlLst.FirstOrDefault(m => { return m.ProductOrderDtlId == alllocate.ProductOrderDtlId; });
if (lastProductNo == null)
{
lastProductNo = moomDetail.ProductCode;
}
else if (lastProductNo != "" && lastProductNo != moomDetail.ProductCode)
{
lastProductNo = "";
}
headXml.setAttribute("cdepcode", alllocate.momDetail.MDeptCode);
#region 明细
bodyXml = domBody.createElement("z:row");
var metail = new NX.ERP.U8.MaterialDAL().GetInvPrice(detail.InvCode, 1, storeOut.Whcode, out var _cost);
bodyXml.setAttribute("iunitcost", _cost);
var info = new Account.Accinformation();
bodyXml.setAttribute("iprice", info.FormatMoney(_cost * detail.Quantity));
bodyXml.setAttribute("cinvcode", detail.InvCode);
bodyXml.setAttribute("iquantity", detail.Quantity);
bodyXml.setAttribute("irowno", n + 1);
bodyXml.setAttribute("cbatch", "");
bodyXml.setAttribute("cvmivencode", "");
bodyXml.setAttribute("cposition", detail.Position);
bodyXml.setAttribute("editprop", "A");
bodyXml.setAttribute("innum", 10);
bodyXml.setAttribute("autoid", storeOut.Id);
bodyXml.setAttribute("id", storeOut.Id);
bodyXml.setAttribute("impoids", detail.SorceDetailId);
bodyXml.setAttribute("cmocode", Order.ProductOrderNo);
bodyXml.setAttribute("invcode", moomDetail.ProductCode);//产品编码
bodyXml.setAttribute("cwhcode", storeOut.Whcode);
bodyXml.setAttribute("imoseq", 1);
bodyXml.setAttribute("ipesotype", "7");
bodyXml.setAttribute("cpesocode", "");
bodyXml.setAttribute("ipesodid", "");
bodyXml.setAttribute("ipesoseq", "");
bodyXml.setAttribute("isotype", "");
bodyXml.setAttribute("csocode", "");
bodyXml.setAttribute("isodid", "");
bodyXml.setAttribute("isoseq", "");
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
#endregion
}
headXml.setAttribute("cpspcode", lastProductNo);
}
public string AddVocher(Model.Request.MaterialStoreOut storeOut)
{
VoucherParameter voucherParameter = new VoucherParameter
{
VoucherType = this.VoucherID,
DomHead = new DOMDocumentClass(),
DomBody = new DOMDocumentClass()
};
DOMDocument domHead = voucherParameter.DomHead;
DOMDocument domBody = voucherParameter.DomBody;
voucherParameter.DomHead.loadXML(HeadTemplate);
voucherParameter.DomBody.loadXML(BodyTemplate);
IXMLDOMElement headXml = domHead.createElement("z:row");
headXml.setAttribute("ccode", storeOut.Code); //DomHead[0]["ccode"] = ""; //入库单号,string类型
headXml.setAttribute("ddate", storeOut.Date.ToShortDateString()); //DomHead[0]["ddate"] = ""; //入库日期,DateTime类型
headXml.setAttribute("bpufirst", "0");
headXml.setAttribute("bisstqc", "0");
headXml.setAttribute("bomfirst", "0");
headXml.setAttribute("biafirst", "0");
headXml.setAttribute("brdflag", 0);
headXml.setAttribute("cmaker", storeOut.Maker);
headXml.setAttribute("cvouchtype", this.VoucherID);
headXml.setAttribute("vt_id", new VT().GetDefaltVTID("0412"));
headXml.setAttribute("editprop", "A");
headXml.setAttribute("crdcode", "201");
headXml.setAttribute("cwhcode", storeOut.Whcode);
headXml.setAttribute("csource", storeOut.Source);
if (storeOut.Source == "生产订单")
{
ByMomOrder(storeOut, headXml, domBody);
}
else if (storeOut.Source == "领料申请")
{
ByMaterialApp(storeOut, headXml, domBody);
}
domHead.selectSingleNode("//rs:data").appendChild(headXml);
try
{
return AddRdVoucher(voucherParameter);
}
catch (Exception err)
{
throw err;
}
}
public string SaveVoucher(Model.Request.MaterialStoreOut storeOut)
{
var voucherParameter = this.LoadVoucher($"id='{storeOut.Id}'");
if (voucherParameter.DomHead.selectSingleNode("//rs:data").childNodes.length == 0)
{
return this.AddVocher(storeOut);
}
else
{
if (this.UpdateVocher(storeOut, voucherParameter))
{
return storeOut.Id.ToString();
}
else
{
throw new Exception("保存错误");
}
}
}
public bool UpdateVocher(Model.Request.MaterialStoreOut storeOut, VoucherParameter voucherParameter = null)
{
if (voucherParameter == null)
{
voucherParameter = this.LoadVoucher($"Id='{storeOut.Id}'");
}
DOMDocument domBody = voucherParameter.DomBody;
if (storeOut.Source == "生产订单")
{
var Order = new Mom.MomOrderDAL().GetModel(storeOut.SourceCode);
if (Order == null)
{
throw new Exception($"未知订单:{storeOut.SourceCode}");
}
string lastProductNo = null;
//headXml.setAttribute("cdepname", "研发LA组");
IXMLDOMElement bodyXml;
for (var n = 0; n < storeOut.Details.Count(); n++)
{
var detail = storeOut.Details[n];
var alllocate = Order.Allocates.FirstOrDefault(m => { return m.AllocateId == detail.SorceDetailId; });
if (alllocate == null)
{
throw new Exception($"未知订单明细行:{detail.SorceDetailId}");
}
if (alllocate.MaterialCode != detail.InvCode)
{
throw new Exception($"订单明细存货编号与出库存货编号不符:{detail.InvCode}");
}
var moomDetail = Order.ProductDtlLst.FirstOrDefault(m => { return m.ProductOrderDtlId == alllocate.ProductOrderDtlId; });
if (lastProductNo == null)
{
lastProductNo = moomDetail.ProductCode;
}
else if (lastProductNo != "" && lastProductNo != moomDetail.ProductCode)
{
lastProductNo = "";
}
#region 明细
bodyXml = domBody.createElement("z:row");
var metail = new NX.ERP.U8.MaterialDAL().GetInvPrice(detail.InvCode, 1, storeOut.Whcode, out var _cost);
bodyXml.setAttribute("iunitcost", _cost);
var info = new Account.Accinformation();
bodyXml.setAttribute("iprice", info.FormatMoney(_cost * detail.Quantity));
bodyXml.setAttribute("cinvcode", detail.InvCode);
bodyXml.setAttribute("iquantity", detail.Quantity);
bodyXml.setAttribute("irowno", n + 1);
bodyXml.setAttribute("cbatch", "");
bodyXml.setAttribute("cvmivencode", "");
bodyXml.setAttribute("cposition", detail.Position);
bodyXml.setAttribute("editprop", "A");
bodyXml.setAttribute("innum", 10);
bodyXml.setAttribute("autoid", storeOut.Id);
bodyXml.setAttribute("id", storeOut.Id);
bodyXml.setAttribute("impoids", detail.SorceDetailId);
bodyXml.setAttribute("cmocode", Order.ProductOrderNo);
bodyXml.setAttribute("invcode", moomDetail.ProductCode);//产品编码
bodyXml.setAttribute("cwhcode", storeOut.Whcode);
bodyXml.setAttribute("imoseq", 1);
bodyXml.setAttribute("ipesotype", "7");
bodyXml.setAttribute("cpesocode", "");
bodyXml.setAttribute("ipesodid", "");
bodyXml.setAttribute("ipesoseq", "");
bodyXml.setAttribute("isotype", "");
bodyXml.setAttribute("csocode", "");
bodyXml.setAttribute("isodid", "");
bodyXml.setAttribute("isoseq", "");
bodyXml.setAttribute("irowno", domBody.selectSingleNode("//rs:data").childNodes.length + 1);
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
#endregion
}
}
try
{
return base.UpdateRdVoucher(voucherParameter);
}
catch (Exception err)
{
throw err;
}
}
}
}