2021-01-13 17:02:03 +08:00
|
|
|
|
using MSXML2;
|
2021-01-18 15:07:20 +08:00
|
|
|
|
using NX.ERP.Model.Request;
|
2021-01-13 17:02:03 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NX.ERP.U8.Store
|
|
|
|
|
|
{
|
2021-05-29 10:18:22 +08:00
|
|
|
|
public class ProductInDAL : STVoucherBase
|
2021-01-13 17:02:03 +08:00
|
|
|
|
{
|
|
|
|
|
|
public ProductInDAL() : base("10", "U8API/ProductIn")
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string AddVoucher(ProductStoreIn storeIn)
|
|
|
|
|
|
{
|
2021-05-29 10:18:22 +08:00
|
|
|
|
STVoucherParameter voucherParameter = new STVoucherParameter
|
2021-01-13 17:02:03 +08:00
|
|
|
|
{
|
|
|
|
|
|
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("cvouchtype", this.VoucherID);//DomHead[0]["cvouchtype"] = ""; //单据类型,string类型
|
|
|
|
|
|
headXml.setAttribute("bpufirst", "0");
|
|
|
|
|
|
headXml.setAttribute("bisstqc", "0");
|
|
|
|
|
|
headXml.setAttribute("bomfirst", "0");
|
|
|
|
|
|
headXml.setAttribute("biafirst", "0");
|
|
|
|
|
|
headXml.setAttribute("brdflag", 1);
|
2021-01-22 11:25:03 +08:00
|
|
|
|
headXml.setAttribute("ccode", storeIn.Code);
|
2021-01-13 17:02:03 +08:00
|
|
|
|
headXml.setAttribute("ddate", storeIn.Date);
|
2021-01-21 13:42:23 +08:00
|
|
|
|
headXml.setAttribute("cmaker", storeIn.Maker);
|
2021-01-18 16:44:18 +08:00
|
|
|
|
headXml.setAttribute("vt_id", new VT().GetDefaltVTID("0411"));
|
2021-01-13 17:02:03 +08:00
|
|
|
|
headXml.setAttribute("editprop", "A");
|
|
|
|
|
|
headXml.setAttribute("cdepcode", "");
|
|
|
|
|
|
headXml.setAttribute("cpersoncode", "");
|
2021-01-18 15:07:20 +08:00
|
|
|
|
headXml.setAttribute("crdcode", "102");
|
2021-01-13 17:02:03 +08:00
|
|
|
|
|
|
|
|
|
|
if (storeIn.Source == "生产订单")
|
|
|
|
|
|
{
|
|
|
|
|
|
var momOrder = new Mom.MomOrderDAL().GetModel(storeIn.SourceCode);
|
|
|
|
|
|
headXml.setAttribute("csource", storeIn.Source);
|
|
|
|
|
|
headXml.setAttribute("cwhcode", storeIn.WhCode);
|
|
|
|
|
|
headXml.setAttribute("cbustype", "成品入库");
|
|
|
|
|
|
headXml.setAttribute("cmemo", "");
|
|
|
|
|
|
IXMLDOMElement bodyXml;
|
|
|
|
|
|
for (var n = 0; n < storeIn.Details.Count; n++)
|
|
|
|
|
|
{
|
|
|
|
|
|
bodyXml = domBody.createElement("z:row");
|
|
|
|
|
|
var detail = storeIn.Details[n];
|
|
|
|
|
|
bodyXml.setAttribute("cinvcode", detail.InvCode);
|
|
|
|
|
|
bodyXml.setAttribute("iquantity", detail.Quantity);
|
2021-01-28 10:10:32 +08:00
|
|
|
|
var _cost = new MaterialDAL().GetCost(detail.InvCode, 0);
|
2021-01-18 11:38:02 +08:00
|
|
|
|
bodyXml.setAttribute("iunitcost", _cost);
|
2021-01-21 16:00:58 +08:00
|
|
|
|
bodyXml.setAttribute("iprice", new Account.Accinformation().FormatMoney(_cost * detail.Quantity));
|
2021-01-13 17:02:03 +08:00
|
|
|
|
bodyXml.setAttribute("irowno", n + 1);
|
|
|
|
|
|
bodyXml.setAttribute("editprop", "A");
|
2021-03-15 13:34:02 +08:00
|
|
|
|
|
2021-01-13 17:02:03 +08:00
|
|
|
|
bodyXml.setAttribute("cbatch", detail.Batch);
|
|
|
|
|
|
bodyXml.setAttribute("cposition", detail.Position);
|
2021-01-22 11:25:03 +08:00
|
|
|
|
var momOrderDetail = momOrder.ProductDtlLst.First(m => { return m.ProductOrderDtlId == detail.SourceDetailId; });
|
|
|
|
|
|
headXml.setAttribute("cmpocode", momOrder.ProductOrderNo);
|
2021-02-06 16:51:41 +08:00
|
|
|
|
bodyXml.setAttribute("cmocode", momOrder.ProductOrderNo);
|
|
|
|
|
|
bodyXml.setAttribute("impoids", detail.SourceDetailId);
|
2021-01-22 11:25:03 +08:00
|
|
|
|
headXml.setAttribute("iproorderid", momOrder.ProductOrderId);
|
2021-01-13 17:02:03 +08:00
|
|
|
|
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
domHead.selectSingleNode("//rs:data").appendChild(headXml);
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return AddRdVoucher(voucherParameter);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception err)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw err;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-15 16:32:40 +08:00
|
|
|
|
|
|
|
|
|
|
public string SaveVoucher(Model.Request.ProductStoreIn storeIn)
|
2021-03-15 13:13:29 +08:00
|
|
|
|
{
|
2021-03-15 13:34:02 +08:00
|
|
|
|
var voucherParameter = this.LoadVoucher($"id='{storeIn.Id}'");
|
2021-03-15 16:32:40 +08:00
|
|
|
|
if (voucherParameter.DomHead.selectSingleNode("//rs:data").childNodes.length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.AddVoucher(storeIn);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.UpdateVoucher(storeIn, voucherParameter))
|
|
|
|
|
|
{
|
|
|
|
|
|
return storeIn.Id.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("保存错误");
|
|
|
|
|
|
}
|
2021-03-15 13:34:02 +08:00
|
|
|
|
|
2021-03-15 16:32:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-29 10:18:22 +08:00
|
|
|
|
public bool UpdateVoucher(ProductStoreIn storeIn, STVoucherParameter voucherParameter=null)
|
2021-03-15 16:32:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (voucherParameter == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
voucherParameter = this.LoadVoucher($"id='{storeIn.Id}'");
|
|
|
|
|
|
}
|
2021-03-15 13:13:29 +08:00
|
|
|
|
DOMDocument domBody = voucherParameter.DomBody;
|
2021-03-15 13:34:02 +08:00
|
|
|
|
|
2021-03-15 13:13:29 +08:00
|
|
|
|
if (storeIn.Source == "生产订单")
|
|
|
|
|
|
{
|
|
|
|
|
|
var momOrder = new Mom.MomOrderDAL().GetModel(storeIn.SourceCode);
|
2021-03-15 13:34:02 +08:00
|
|
|
|
|
2021-03-15 13:13:29 +08:00
|
|
|
|
IXMLDOMElement bodyXml;
|
|
|
|
|
|
for (var n = 0; n < storeIn.Details.Count; n++)
|
|
|
|
|
|
{
|
|
|
|
|
|
bodyXml = domBody.createElement("z:row");
|
|
|
|
|
|
var detail = storeIn.Details[n];
|
|
|
|
|
|
bodyXml.setAttribute("cinvcode", detail.InvCode);
|
|
|
|
|
|
bodyXml.setAttribute("iquantity", detail.Quantity);
|
|
|
|
|
|
var _cost = new MaterialDAL().GetCost(detail.InvCode, 0);
|
|
|
|
|
|
bodyXml.setAttribute("iunitcost", _cost);
|
|
|
|
|
|
bodyXml.setAttribute("iprice", new Account.Accinformation().FormatMoney(_cost * detail.Quantity));
|
2021-03-15 13:34:02 +08:00
|
|
|
|
|
2021-03-15 13:13:29 +08:00
|
|
|
|
bodyXml.setAttribute("editprop", "A");
|
|
|
|
|
|
|
|
|
|
|
|
bodyXml.setAttribute("cbatch", detail.Batch);
|
|
|
|
|
|
bodyXml.setAttribute("cposition", detail.Position);
|
|
|
|
|
|
var momOrderDetail = momOrder.ProductDtlLst.First(m => { return m.ProductOrderDtlId == detail.SourceDetailId; });
|
2021-03-15 13:34:02 +08:00
|
|
|
|
|
2021-03-15 13:13:29 +08:00
|
|
|
|
bodyXml.setAttribute("cmocode", momOrder.ProductOrderNo);
|
|
|
|
|
|
bodyXml.setAttribute("impoids", detail.SourceDetailId);
|
|
|
|
|
|
bodyXml.setAttribute("irowno", domBody.selectSingleNode("//rs:data").childNodes.length + 1);
|
|
|
|
|
|
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-15 13:34:02 +08:00
|
|
|
|
|
2021-03-15 13:13:29 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return UpdateRdVoucher(voucherParameter);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception err)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw err;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-13 17:02:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|