2021-01-06 12:43:05 +08:00
|
|
|
|
using MSXML2;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2021-01-07 14:06:26 +08:00
|
|
|
|
using System.IO;
|
2021-01-06 12:43:05 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using UFIDA.U8.U8APIFramework;
|
|
|
|
|
|
using UFIDA.U8.U8APIFramework.Parameter;
|
|
|
|
|
|
using UFIDA.U8.U8MOMAPIFramework;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NX.ERP.U8.Store
|
|
|
|
|
|
{
|
2021-05-29 10:18:22 +08:00
|
|
|
|
public class PuStoreInDAL : STVoucherBase
|
2021-01-06 12:43:05 +08:00
|
|
|
|
{
|
2021-01-13 12:37:27 +08:00
|
|
|
|
public PuStoreInDAL() : base("01", "U8API/PuStoreIn")
|
2021-01-07 14:06:26 +08:00
|
|
|
|
{
|
2021-01-09 16:36:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-15 11:13:19 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 保存一个采购到货单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="puStoreIn"></param>
|
|
|
|
|
|
public string AddVocher(Model.Request.PuStoreIn puStoreIn)
|
2021-03-15 09:50:23 +08:00
|
|
|
|
{
|
2021-03-15 11:13:19 +08:00
|
|
|
|
try
|
2021-01-07 14:06:26 +08:00
|
|
|
|
{
|
2021-05-29 10:18:22 +08:00
|
|
|
|
STVoucherParameter voucherParameter = new STVoucherParameter
|
2021-02-06 12:00:12 +08:00
|
|
|
|
{
|
2021-03-15 11:13:19 +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("id", puStoreIn.Id); //DomHead[0]["id"] = ""; //主关键字段,int类型
|
|
|
|
|
|
headXml.setAttribute("bomfirst", "0"); //DomHead[0]["bomfirst"] = ""; //委外期初标志,string类型
|
|
|
|
|
|
headXml.setAttribute("ccode", puStoreIn.Code); //DomHead[0]["ccode"] = ""; //入库单号,string类型
|
|
|
|
|
|
headXml.setAttribute("ddate", System.DateTime.Now.ToString("G")); //DomHead[0]["ddate"] = ""; //入库日期,DateTime类型
|
|
|
|
|
|
headXml.setAttribute("iverifystate", 0); //DomHead[0]["iverifystate"] = ""; //iverifystate,int类型
|
|
|
|
|
|
headXml.setAttribute("iswfcontrolled", 0); //DomHead[0]["iswfcontrolled"] = ""; //iswfcontrolled,int类型
|
|
|
|
|
|
headXml.setAttribute("bpufirst", "0"); //DomHead[0]["bpufirst"] = ""; //采购期初标志,string类型
|
|
|
|
|
|
headXml.setAttribute("brdflag", 1); //DomHead[0]["brdflag"] = ""; //收发标志,int类型
|
|
|
|
|
|
headXml.setAttribute("csource", puStoreIn.Source); //DomHead[0]["csource"] = ""; //单据来源,int类型
|
|
|
|
|
|
headXml.setAttribute("cmaker", puStoreIn.Maker);//DomHead[0]["cmaker"] = ""; //制单人,string类型
|
|
|
|
|
|
headXml.setAttribute("vt_id", new VT().GetDefaltVTID("24"));
|
|
|
|
|
|
headXml.setAttribute("editprop", "A");
|
|
|
|
|
|
headXml.setAttribute("cdepcode", puStoreIn.Deptcode);
|
2021-03-15 15:50:14 +08:00
|
|
|
|
|
2021-03-15 11:13:19 +08:00
|
|
|
|
headXml.setAttribute("crdcode", "101" /*puStoreIn.RdCode*/);
|
|
|
|
|
|
headXml.setAttribute("cwhcode", puStoreIn.Whcode);
|
|
|
|
|
|
headXml.setAttribute("bisstqc", "0");
|
|
|
|
|
|
if (puStoreIn.Source == "采购到货单")
|
2021-01-07 14:06:26 +08:00
|
|
|
|
{
|
2021-03-15 11:13:19 +08:00
|
|
|
|
var Arrival = new Purchase.ArrivalDAL().GetModel(puStoreIn.SourceCode);
|
|
|
|
|
|
if (Arrival == null)
|
2021-02-06 12:00:12 +08:00
|
|
|
|
{
|
2021-03-15 11:13:19 +08:00
|
|
|
|
throw new Exception("未知采购到货单,或到货单已经入库完成");
|
2021-02-06 12:00:12 +08:00
|
|
|
|
}
|
2021-03-15 11:13:19 +08:00
|
|
|
|
headXml.setAttribute("cbustype", Arrival.BusType);
|
|
|
|
|
|
headXml.setAttribute("iexchrate", Arrival.ExchRate);
|
|
|
|
|
|
headXml.setAttribute("cexch_name", Arrival.ExchName);
|
|
|
|
|
|
headXml.setAttribute("cvencode", Arrival.VenCode);
|
|
|
|
|
|
headXml.setAttribute("carvcode", Arrival.ArrivalNo);
|
|
|
|
|
|
headXml.setAttribute("ipurarriveid", Arrival.ArrivalId);
|
|
|
|
|
|
headXml.setAttribute("darvdate", Arrival.ArrivalDate);
|
|
|
|
|
|
headXml.setAttribute("itaxrate", Arrival.TaxRate);
|
|
|
|
|
|
headXml.setAttribute("cptcode", Arrival.PTCode);
|
2021-03-15 15:50:14 +08:00
|
|
|
|
headXml.setAttribute("cpersoncode", Arrival.CPersonCode);
|
|
|
|
|
|
headXml.setAttribute("cpersonname", Arrival.cpersonname);
|
2021-03-15 11:13:19 +08:00
|
|
|
|
IXMLDOMElement bodyXml;
|
|
|
|
|
|
for (var n = 0; n < puStoreIn.Details.Count; n++)
|
2021-02-06 12:00:12 +08:00
|
|
|
|
{
|
2021-03-15 11:13:19 +08:00
|
|
|
|
var detail = puStoreIn.Details[n];
|
|
|
|
|
|
var arrivalDetail = Arrival.ArrivalDtlLst.First(m => { return m.ArrivalDtlId == detail.SorceDetailId; });
|
|
|
|
|
|
headXml.setAttribute("cordercode", arrivalDetail.OrderCode);
|
|
|
|
|
|
bodyXml = domBody.createElement("z:row");
|
|
|
|
|
|
if (arrivalDetail.cunitid != 0) //需要做辅助计量单位
|
|
|
|
|
|
{
|
|
|
|
|
|
var _inum = detail.Quantity / arrivalDetail.inspecexchrate;
|
|
|
|
|
|
bodyXml.setAttribute("inum", _inum);
|
|
|
|
|
|
bodyXml.setAttribute("cinva_unit", arrivalDetail.cinva_unit);
|
|
|
|
|
|
bodyXml.setAttribute("cassunit", arrivalDetail.cunitid);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
bodyXml.setAttribute("innum", 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
bodyXml.setAttribute("cinvcode", detail.Invcode);
|
|
|
|
|
|
bodyXml.setAttribute("iquantity", detail.Quantity);
|
|
|
|
|
|
|
|
|
|
|
|
bodyXml.setAttribute("cbvencode", "10001");
|
|
|
|
|
|
bodyXml.setAttribute("inquantity", detail.Quantity); //应收数量,double类型
|
|
|
|
|
|
bodyXml.setAttribute("cbatch", detail.Batch);
|
|
|
|
|
|
bodyXml.setAttribute("cposition", detail.Position);
|
|
|
|
|
|
bodyXml.setAttribute("cbarvcode", Arrival.ArrivalNo);
|
|
|
|
|
|
bodyXml.setAttribute("ipurarriveid", Arrival.ArrivalId);
|
|
|
|
|
|
bodyXml.setAttribute("iarrsid", detail.SorceDetailId);
|
|
|
|
|
|
bodyXml.setAttribute("darvdate", DateTime.Today.ToShortDateString());
|
|
|
|
|
|
bodyXml.setAttribute("editprop", "A");
|
|
|
|
|
|
bodyXml.setAttribute("cpoid", arrivalDetail.OrderCode);
|
|
|
|
|
|
bodyXml.setAttribute("iposid", arrivalDetail.posId);
|
|
|
|
|
|
bodyXml.setAttribute("itaxrate", Arrival.TaxRate);
|
|
|
|
|
|
var info = new Account.Accinformation();
|
2021-03-23 15:06:34 +08:00
|
|
|
|
var _oricost = (arrivalDetail.orisum / (1 + (Arrival.TaxRate / 100f)) / arrivalDetail.Qty);
|
|
|
|
|
|
FormatHelp.GetUnitPriceByCost(detail.Quantity, _oricost /*arrivalDetail.oricost*/, Arrival.TaxRate, Arrival.ExchRate, out double iprice2, out double itaxprice2, out double isum2);
|
2021-03-15 11:13:19 +08:00
|
|
|
|
bodyXml.setAttribute("iunitcost", arrivalDetail.cost);
|
2021-03-23 15:06:34 +08:00
|
|
|
|
bodyXml.setAttribute("iprice", iprice2);//
|
2021-03-15 11:13:19 +08:00
|
|
|
|
bodyXml.setAttribute("facost", arrivalDetail.cost);
|
2021-03-23 15:06:34 +08:00
|
|
|
|
bodyXml.setAttribute("iaprice", iprice2);//
|
2021-03-15 11:13:19 +08:00
|
|
|
|
bodyXml.setAttribute("itaxprice", itaxprice2);
|
|
|
|
|
|
bodyXml.setAttribute("isum", isum2);
|
2021-03-23 15:06:34 +08:00
|
|
|
|
FormatHelp.GetOriPriceByCost(detail.Quantity, _oricost /*arrivalDetail.oricost*/, Arrival.TaxRate, out double iorimoney2, out double ioritaxprice2, out double iorisum2, out double iunitcost2);
|
2021-03-15 11:13:19 +08:00
|
|
|
|
bodyXml.setAttribute("ioricost", arrivalDetail.oricost);
|
|
|
|
|
|
bodyXml.setAttribute("ioritaxcost", arrivalDetail.oritaxcost);
|
2021-03-23 15:06:34 +08:00
|
|
|
|
bodyXml.setAttribute("iorimoney", iorimoney2);//
|
2021-03-15 11:13:19 +08:00
|
|
|
|
bodyXml.setAttribute("ioritaxprice", ioritaxprice2);
|
|
|
|
|
|
bodyXml.setAttribute("iorisum", iorisum2);
|
|
|
|
|
|
bodyXml.setAttribute("irowno", domBody.selectSingleNode("//rs:data").childNodes.length + 1);
|
|
|
|
|
|
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
|
2021-02-06 12:00:12 +08:00
|
|
|
|
}
|
2021-01-07 14:06:26 +08:00
|
|
|
|
}
|
2021-03-15 11:13:19 +08:00
|
|
|
|
domHead.selectSingleNode("//rs:data").appendChild(headXml);
|
|
|
|
|
|
|
2021-01-13 13:30:24 +08:00
|
|
|
|
return AddRdVoucher(voucherParameter);
|
2021-01-09 16:36:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception err)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
throw err;
|
|
|
|
|
|
}
|
2021-03-15 09:50:23 +08:00
|
|
|
|
}
|
2021-01-09 16:36:17 +08:00
|
|
|
|
|
2021-03-15 11:13:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
2021-03-15 15:50:14 +08:00
|
|
|
|
public string SaveVoucher(Model.Request.PuStoreIn puStoreIn)
|
|
|
|
|
|
{
|
|
|
|
|
|
var voucherParameter = this.LoadVoucher($"id='{puStoreIn.Id}'");
|
|
|
|
|
|
if (voucherParameter.DomHead.selectSingleNode("//rs:data").childNodes.length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.AddVocher(puStoreIn);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.UpdateVocher(puStoreIn, voucherParameter))
|
|
|
|
|
|
{
|
|
|
|
|
|
return puStoreIn.Id.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("保存错误");
|
|
|
|
|
|
}
|
2021-03-15 11:13:19 +08:00
|
|
|
|
|
2021-03-15 15:50:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2021-03-15 11:13:19 +08:00
|
|
|
|
|
2021-03-15 15:50:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
2021-05-29 10:18:22 +08:00
|
|
|
|
public bool UpdateVocher(Model.Request.PuStoreIn puStoreIn, STVoucherParameter voucherParameter = null)
|
2021-03-15 09:50:23 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2021-03-15 15:50:14 +08:00
|
|
|
|
if (voucherParameter == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
voucherParameter = this.LoadVoucher($"id='{puStoreIn.Id}'");
|
|
|
|
|
|
}
|
2021-03-15 09:50:23 +08:00
|
|
|
|
//添加一條
|
|
|
|
|
|
DOMDocument domBody = voucherParameter.DomBody;
|
|
|
|
|
|
if (puStoreIn.Source == "采购到货单")
|
|
|
|
|
|
{
|
|
|
|
|
|
var Arrival = new Purchase.ArrivalDAL().GetModel(puStoreIn.SourceCode);
|
|
|
|
|
|
if (Arrival == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("未知采购到货单,或到货单已经入库完成");
|
|
|
|
|
|
}
|
|
|
|
|
|
IXMLDOMElement bodyXml;
|
|
|
|
|
|
for (var n = 0; n < puStoreIn.Details.Count; n++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var detail = puStoreIn.Details[n];
|
|
|
|
|
|
var arrivalDetail = Arrival.ArrivalDtlLst.First(m => { return m.ArrivalDtlId == detail.SorceDetailId; });
|
|
|
|
|
|
bodyXml = domBody.createElement("z:row");
|
|
|
|
|
|
if (arrivalDetail.cunitid != 0) //需要做辅助计量单位
|
|
|
|
|
|
{
|
|
|
|
|
|
var _inum = detail.Quantity / arrivalDetail.inspecexchrate;
|
|
|
|
|
|
bodyXml.setAttribute("inum", _inum);
|
|
|
|
|
|
bodyXml.setAttribute("cinva_unit", arrivalDetail.cinva_unit);
|
|
|
|
|
|
bodyXml.setAttribute("cassunit", arrivalDetail.cunitid);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
bodyXml.setAttribute("innum", 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
bodyXml.setAttribute("cinvcode", detail.Invcode);
|
|
|
|
|
|
bodyXml.setAttribute("iquantity", detail.Quantity);
|
2021-03-15 11:13:19 +08:00
|
|
|
|
|
2021-03-15 09:50:23 +08:00
|
|
|
|
bodyXml.setAttribute("cbvencode", "10001");
|
|
|
|
|
|
bodyXml.setAttribute("inquantity", detail.Quantity); //应收数量,double类型
|
|
|
|
|
|
bodyXml.setAttribute("cbatch", detail.Batch);
|
|
|
|
|
|
|
|
|
|
|
|
bodyXml.setAttribute("cposition", detail.Position);
|
|
|
|
|
|
bodyXml.setAttribute("cbarvcode", Arrival.ArrivalNo);
|
|
|
|
|
|
bodyXml.setAttribute("ipurarriveid", Arrival.ArrivalId);
|
|
|
|
|
|
bodyXml.setAttribute("iarrsid", detail.SorceDetailId);
|
|
|
|
|
|
bodyXml.setAttribute("darvdate", DateTime.Today.ToShortDateString());
|
|
|
|
|
|
bodyXml.setAttribute("editprop", "A");
|
|
|
|
|
|
bodyXml.setAttribute("cpoid", arrivalDetail.OrderCode);
|
|
|
|
|
|
bodyXml.setAttribute("iposid", arrivalDetail.posId);
|
|
|
|
|
|
bodyXml.setAttribute("itaxrate", Arrival.TaxRate);
|
|
|
|
|
|
var info = new Account.Accinformation();
|
2021-03-23 15:12:22 +08:00
|
|
|
|
var _oricost = (arrivalDetail.orisum / (1 + (Arrival.TaxRate / 100f)) / arrivalDetail.Qty);
|
|
|
|
|
|
FormatHelp.GetUnitPriceByCost(detail.Quantity, _oricost /*arrivalDetail.oricost*/, Arrival.TaxRate, Arrival.ExchRate, out double iprice2, out double itaxprice2, out double isum2);
|
2021-03-15 09:50:23 +08:00
|
|
|
|
bodyXml.setAttribute("iunitcost", arrivalDetail.cost);
|
|
|
|
|
|
bodyXml.setAttribute("iprice", iprice2);
|
|
|
|
|
|
bodyXml.setAttribute("facost", arrivalDetail.cost);
|
|
|
|
|
|
bodyXml.setAttribute("iaprice", iprice2);
|
|
|
|
|
|
bodyXml.setAttribute("itaxprice", itaxprice2);
|
|
|
|
|
|
bodyXml.setAttribute("isum", isum2);
|
2021-03-23 15:12:22 +08:00
|
|
|
|
FormatHelp.GetOriPriceByCost(detail.Quantity, _oricost /* arrivalDetail.oricost*/, Arrival.TaxRate, out double iorimoney2, out double ioritaxprice2, out double iorisum2, out double iunitcost2);
|
2021-03-15 09:50:23 +08:00
|
|
|
|
bodyXml.setAttribute("ioricost", arrivalDetail.oricost);
|
|
|
|
|
|
bodyXml.setAttribute("ioritaxcost", arrivalDetail.oritaxcost);
|
|
|
|
|
|
bodyXml.setAttribute("iorimoney", iorimoney2);
|
|
|
|
|
|
bodyXml.setAttribute("ioritaxprice", ioritaxprice2);
|
|
|
|
|
|
bodyXml.setAttribute("iorisum", iorisum2);
|
2021-03-15 11:13:19 +08:00
|
|
|
|
|
|
|
|
|
|
bodyXml.setAttribute("irowno", domBody.selectSingleNode("//rs:data").childNodes.length + 1);
|
2021-03-15 09:50:23 +08:00
|
|
|
|
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-01-07 14:06:26 +08:00
|
|
|
|
|
2021-01-13 09:02:37 +08:00
|
|
|
|
|
2021-03-15 09:50:23 +08:00
|
|
|
|
|
|
|
|
|
|
return UpdateRdVoucher(voucherParameter);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception err)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
throw err;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-01-06 12:43:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|