//第一步:构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)

//如果当前环境中有login对象则可以省去第一步

U8Login.clsLogin u8Login = new U8Login.clsLogin();

String sSubId = "AS";

String sAccID = "(default)@888";

String sYear = "2008";

String sUserID = "demo";

String sPassword = "";

String sDate = "2008-11-11";

String sServer = "localhost";

String sSerial = "";

if(!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))

{

Console.WriteLine("登陆失败,原因:" + u8Login.ShareString);

Marshal.FinalReleaseComObject(u8Login);

return;

}

//第二步:构造环境上下文对象,传入login,并按需设置其它上下文参数

U8EnvContext envContext = new U8EnvContext();

envContext.U8Login = u8Login;

//第三步:设置API地址标识(Url)

//当前API:添加新单据的地址标识为:U8API/MaterialOut/Add

U8ApiAddress myApiAddress = new U8ApiAddress("U8API/PuStoreIn/Add");

//第四步:构造APIBroker

U8ApiBroker broker = new U8ApiBroker(myApiAddress, envContext);

//第五步:API参数赋值

//给普通参数sVouchType赋值。此参数的数据类型为System.String,此参数按值传递,表示单据类型:01

broker.AssignNormalValue("sVouchType", "01");

MSXML2.IXMLDOMDocument2 docHead = new DOMDocument();

MSXML2.IXMLDOMDocument2 docBody = new DOMDocument();

docHead.load(HttpContext.Current.Server.MapPath("./") + @"XML\rdrecord01.xml");

docBody.load(HttpContext.Current.Server.MapPath("./") + @"XML\rdrecords01.xml");

MSXML2.IXMLDOMNode nodeHead = docHead.selectSingleNode("//z:row");

IXMLDOMElement xeHead = (IXMLDOMElement)nodeHead;

xeHead.setAttribute("id", "");

xeHead.setAttribute("cmaker", cUser);

System.Data.DataTable ccoddt = DbHelperSQL.Query("SELECT MAX(cCode) as cCode FROM rdrecord01 ").Tables[0];

string ccode = "0000000001";

if (ccoddt != null && ccoddt.Rows.Count > 0)

{

ccode = ClsSystem.gnvl(ccoddt.Rows[0]["cCode"], "0000000001");

}

xeHead.setAttribute("ccode", ccode);

xeHead.setAttribute("ddate", u8Login.CurDate);

xeHead.setAttribute("cwhcode", root.paramList[0].cWhcode.Trim()); //仓库编码,string类型

bool redBill = false;

redBill = DbHelperSQL.ToBoolByByte(root.paramList[0].bredvouch, false);

MSXML2.IXMLDOMNode nodeBody = docBody.selectSingleNode("//z:row");

IXMLDOMElement xeBody = (IXMLDOMElement)nodeBody;

int irowno = 1;

foreach (JsonHelper.ParamList list in root.paramList)

{

if (redBill)

{

list.iQuantity = -list.iQuantity;

}

//获取采购到货订单的信息

string arridSqls = string.Format(@"

SELECT TOP 1 s2.cbustype,s1.Autoid,CONVERT(NVARCHAR,s2.dDate,23) AS dDate,s2.cCode,s1.iPOsID ,p2.cPOID,p22.cCode AS cPOID2,s1.bgift, s1.iTaxRate,s2.ID as ipurarriveid,s2.cPersonCode,s2.cpocode,s2.cVenCode,s2.cDepCode ,s2.cPTCode ,s2.cMemo,s1.cbMemo,s1.cInvCode,s1.bgift,s2.iexchrate,

s2.cexch_name, s1.ioritaxcost,aa.iLZFS,s2.cvenpuomprotocol,s1.bTaxCost,(s1.iQuantity -s1.fValidInQuan ) AS iNQuantity,

aad.dcreditstart AS dcreditstart,

CASE WHEN aa.iZQ=0 THEN aa.dblZQNum

WHEN aa.iZQ=1 THEN ISNULL(v1.iVenCreDate,0)

ELSE 0

END AS icreditperiod,

DATEADD(DAY,

CASE WHEN aa.iZQ=0 THEN aa.dblZQNum

WHEN aa.iZQ=1 THEN ISNULL(v1.iVenCreDate,0)

ELSE 0

END,

CASE WHEN aa.iLZFS=0 THEN CONVERT(NVARCHAR,GETDATE(),23)

WHEN aa.iLZFS=1 THEN CONVERT(NVARCHAR,dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0)),23 )

WHEN aa.iLZFS=2 THEN

(CASE WHEN DatePart(dd,aad.dcreditstart) >aa.iGDSZR1 AND DatePart(dd,aad.dcreditstart)<=aa.iGDSZR2 THEN DATEADD(dd,aa.iGDSZR2,CONVERT(NVARCHAR,dateadd(dd,-day(aad.dcreditstart),aad.dcreditstart) ,23))

WHEN DatePart(dd,aad.dcreditstart) >aa.iGDSZR2 AND DatePart(dd,aad.dcreditstart)<=aa.iGDSZR3 THEN DATEADD(dd,aa.iGDSZR3,CONVERT(NVARCHAR,dateadd(dd,-day(aad.dcreditstart),aad.dcreditstart) ,23))

WHEN DatePart(dd,aad.dcreditstart) >=aa.iGDSZR3 AND aa.iGDSZR3 >0 THEN DATEADD(mm,1,DATEADD(dd,aa.iGDSZR1,CONVERT(NVARCHAR,dateadd(dd,-day(aad.dcreditstart),aad.dcreditstart) ,23)))

WHEN DatePart(dd,aad.dcreditstart) <=aa.iGDSZR1 THEN DATEADD(dd,aa.iGDSZR1,CONVERT(NVARCHAR,dateadd(dd,-day(aad.dcreditstart),aad.dcreditstart) ,23))

ELSE CONVERT(NVARCHAR,aad.dcreditstart,23) END )

ELSE NULL

END) AS dgatheringdate,

CASE WHEN ISNULL(s2.cvenpuomprotocol,'')='' THEN 0 ELSE 1 END AS bcredit,

s2.cDefine1 ,s2.cDefine2 ,s2.cDefine3 ,s2.cDefine4 ,s2.cDefine5 ,s2.cDefine6 ,s2.cDefine7 ,s2.cDefine8 ,s2.cDefine9 ,s2.cDefine10 ,s2.cDefine11 ,s2.cDefine12 ,s2.cDefine13 ,s2.cDefine14 ,s2.cDefine15 ,s2.cDefine16 ,

s1.cDefine22 ,s1.cDefine23 ,s1.cDefine24 ,s1.cDefine25 ,s1.cDefine26 ,s1.cDefine27 ,s1.cDefine28 ,s1.cDefine29 ,s1.cDefine30 ,s1.cDefine31 ,s1.cDefine32 ,s1.cDefine33 ,s1.cDefine34 ,s1.cDefine35 ,s1.cDefine36 ,s1.cDefine37 ,

s1.cFree1 ,s1.cFree2 ,s1.cFree3 ,s1.cFree4 ,s1.cFree5 ,s1.cFree6 ,s1.cFree7 ,s1.cFree8 ,s1.cFree9 ,s1.cFree10

FROM dbo.PU_ArrivalVouchs s1

LEFT JOIN PU_ArrivalVouch s2 ON s1.ID=s2.ID

LEFT JOIN Po_podetails p1 on s1.iposid=p1.id

LEFT JOIN Po_Pomain p2 ON p1.poid=p2.poid

LEFT JOIN OM_MODetails p11 on s1.iposid=p11.modetailsid AND s2.cbustype IN ( N'委外加工' )

LEFT JOIN dbo.OM_MOMain p22 ON p11.moid=p22.moid AND s2.cbustype IN ( N'委外加工' )

LEFT JOIN aa_agreement aa ON aa.ccode = s2.cvenpuomprotocol

LEFT JOIN (

SELECT CASE WHEN aa.iLZFS=0 THEN CONVERT(NVARCHAR,GETDATE(),23)

WHEN aa.iLZFS=1 THEN CONVERT(NVARCHAR,dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0)),23 )

WHEN aa.iLZFS=2 THEN

DATEADD(mm,aa.iMon,

(CASE WHEN DatePart(dd,GETDATE()) >aa.iDay1 AND DatePart(dd,GETDATE())<=aa.iDay2 THEN DATEADD(dd,aa.iDay2,CONVERT(NVARCHAR,dateadd(dd,-day(getdate()),getdate()) ,23))

WHEN DatePart(dd,GETDATE()) >aa.iDay2 AND DatePart(dd,GETDATE())<=aa.iDay3 THEN DATEADD(dd,aa.iDay3,CONVERT(NVARCHAR,dateadd(dd,-day(getdate()),getdate()) ,23))

WHEN DATEPART(dd,GETDATE()) >=aa.iDay3 AND aa.iDay3 >0 THEN DATEADD(mm,1,DATEADD(dd,aa.iDay1,CONVERT(NVARCHAR,dateadd(dd,-day(getdate()),getdate()) ,23)))

WHEN DatePart(dd,GETDATE()) <=aa.iDay1 THEN DATEADD(dd,aa.iDay1,CONVERT(NVARCHAR,dateadd(dd,-day(getdate()),getdate()) ,23))

ELSE CONVERT(NVARCHAR,GETDATE(),23) END ))

ELSE NULL

END AS dcreditstart,aa.cCode FROM aa_agreement aa

) aad ON aad.cCode = aa.cCode

LEFT JOIN Vendor v1 ON v1.cVenCode=s2.cVenCode WHERE s1.Autoid='{0}' ", ClsSystem.gnvl(list.ERP_ID.Trim(), "-1"));

System.Data.DataTable arridts = DbHelperSQL.Query(arridSqls).Tables[0];

if (arridts != null && arridts.Rows.Count > 0)

{

#region 表头数据赋值

if (irowno == 1)

{

xeHead.setAttribute("carvcode", arridts.Rows[0]["cCode"].ToString()); //到货单号,string类型

xeHead.setAttribute("ipurarriveid", arridts.Rows[0]["ipurarriveid"].ToString()); //采购到货单ID,string类型

xeHead.setAttribute("cbustype", arridts.Rows[0]["cbustype"].ToString());//业务类型,int类型

xeHead.setAttribute("cvouchtype", "01"); //单据类型,string类型

xeHead.setAttribute("cordercode", arridts.Rows[0]["cpocode"].ToString());//订单号,string类型

xeHead.setAttribute("cpersoncode", arridts.Rows[0]["cPersonCode"].ToString()); //业务员编码,string类型

xeHead.setAttribute("cvencode", arridts.Rows[0]["cVenCode"].ToString());//供货单位编码,string类型

xeHead.setAttribute("cdepcode", arridts.Rows[0]["cDepCode"].ToString()); //部门编码,string类型

xeHead.setAttribute("cwhcode", list.cWhcode.Trim()); //仓库编码,string类型

xeHead.setAttribute("dARVDate", ClsSystem.gnvl(arridts.Rows[0]["dDate"], "").Replace("/", "-")); //到货日期,DateTime类型

xeHead.setAttribute("itaxrate", arridts.Rows[0]["iTaxRate"].ToString()); //税率

xeHead.setAttribute("iexchrate", arridts.Rows[0]["iexchrate"].ToString()); //税率

xeHead.setAttribute("cexch_name", arridts.Rows[0]["cexch_name"].ToString()); //税率

默认采购类型 新增单据的时候使用 参照采购到货的时候 上游带入

//string cPTCodeSql = @"Select PurchaseType.cPTCode From PurchaseType with (nolock)

//LEFT JOIN (select * from Rd_Style with (nolock) ) as Rd_Style ON PurchaseType.cRdCode=Rd_Style.cRdCode Where bdefault=1";

//string cPTCode = ClsSystem.gnvl(DbHelperSQL.GetSingle(cPTCodeSql), "");

//xeHead.setAttribute("cptcode", !string.IsNullOrEmpty(cPTCode) ? cPTCode : "");//采购类型编码,string类型

xeHead.setAttribute("cptcode", arridts.Rows[0]["cPTCode"].ToString());//采购类型编码,string类型

//默认收发类别

string cRdCode = ClsSystem.gnvl(DbHelperSQL.GetSingle("SELECT TOP 1 V1.cVRRCode FROM VouchRdContrapose V1 WHERE V1.cVBTID IN (SELECT cVBTID FROM VouchTypeDic WHERE cVTChName ='采购入库单')"), "");

xeHead.setAttribute("crdcode", !string.IsNullOrEmpty(cRdCode) ? cRdCode : "");//入库类别编码,string类型

xeHead.setAttribute("brdflag", "1"); //收发标志,int类型

xeHead.setAttribute("csource", (string)arridts.Rows[0]["cbustype"] == "委外加工" ? "委外到货单" : "采购到货单");

xeHead.setAttribute("cmemo", arridts.Rows[0]["cmemo"].ToString());//备注,string类型

xeHead.setAttribute("cvenpuomprotocol", arridts.Rows[0]["cvenpuomprotocol"].ToString()); //收付款协议

xeHead.setAttribute("cmaker", cUser); //制单人,string类型

//收付款协议

//1.立账日取值的方式 0业务日期 1月结 2固定立账日

//2.账期取值iZQ 账期方式 0账期天数 1取客户供应商信用期限

if (!string.IsNullOrEmpty(arridts.Rows[0]["cvenpuomprotocol"].ToString()))

{

xeHead.setAttribute("dcreditstart", arridts.Rows[0]["dcreditstart"].ToString());

xeHead.setAttribute("icreditperiod", arridts.Rows[0]["icreditperiod"].ToString());

xeHead.setAttribute("dgatheringdate", arridts.Rows[0]["dgatheringdate"].ToString());

xeHead.setAttribute("bcredit", arridts.Rows[0]["bcredit"].ToString());

}

xeHead.setAttribute("cdefine1", arridts.Rows[0]["cDefine1"].ToString()); //表头自定义项1,string类型

xeHead.setAttribute("cdefine2", arridts.Rows[0]["cDefine2"].ToString()); //表头自定义项2,string类型

xeHead.setAttribute("cdefine3", arridts.Rows[0]["cDefine3"].ToString()); //表头自定义项3,string类型

xeHead.setAttribute("cdefine4", arridts.Rows[0]["cDefine4"].ToString()); //表头自定义项4,DateTime类型

xeHead.setAttribute("cdefine5", arridts.Rows[0]["cDefine5"].ToString()); //表头自定义项5,int类型

xeHead.setAttribute("cdefine6", arridts.Rows[0]["cDefine6"].ToString()); //表头自定义项6,DateTime类型

xeHead.setAttribute("cdefine7", arridts.Rows[0]["cDefine7"].ToString()); //表头自定义项7,double类型

xeHead.setAttribute("cdefine8", arridts.Rows[0]["cDefine8"].ToString()); //表头自定义项8,string类型

xeHead.setAttribute("cdefine9", arridts.Rows[0]["cDefine9"].ToString()); //表头自定义项9,string类型

xeHead.setAttribute("cdefine10", arridts.Rows[0]["cDefine10"].ToString()); //表头自定义项10,string类型

xeHead.setAttribute("cdefine11", arridts.Rows[0]["cDefine11"].ToString()); //表头自定义项11,string类型

xeHead.setAttribute("cdefine12", arridts.Rows[0]["cDefine12"].ToString()); //表头自定义项12,string类型

xeHead.setAttribute("cdefine13", arridts.Rows[0]["cDefine13"].ToString()); //表头自定义项13,string类型

xeHead.setAttribute("cdefine14", arridts.Rows[0]["cDefine14"].ToString()); //表头自定义项14,string类型

xeHead.setAttribute("cdefine15", arridts.Rows[0]["cDefine15"].ToString()); //表头自定义项15,int类型

xeHead.setAttribute("cdefine16", arridts.Rows[0]["cDefine16"].ToString()); //表头自定义项15,int类型

}

#endregion

IXMLDOMNode newNode = nodeBody.cloneNode(false);

if (irowno != 1)

{

xeBody = (IXMLDOMElement)newNode;

}

xeBody.setAttribute("cinvcode", arridts.Rows[0]["cInvCode"].ToString());

#region 表体自定义字段以及自由项赋值

xeBody.setAttribute("cdefine22", arridts.Rows[0]["cDefine22"].ToString()); //表体自定义项1,string类型

xeBody.setAttribute("cdefine23", arridts.Rows[0]["cDefine23"].ToString()); //表体自定义项2,string类型

xeBody.setAttribute("cdefine24", arridts.Rows[0]["cDefine24"].ToString()); //表体自定义项3,string类型

if (list.MES_Code.Length > 55)

{

xeBody.setAttribute("cdefine25", list.MES_Code.Trim().Substring(0, 50)); //表体自定义项4,string类型

}

else

{

xeBody.setAttribute("cdefine25", list.MES_Code.Trim()); //表体自定义项4,string类型

}

xeBody.setAttribute("cdefine26", arridts.Rows[0]["cDefine26"].ToString()); //表体自定义项5,double类型

xeBody.setAttribute("cdefine27", arridts.Rows[0]["cDefine27"].ToString()); //表体自定义项6,double类型

xeBody.setAttribute("cdefine28", arridts.Rows[0]["cDefine28"].ToString()); //表体自定义项7,string类型

xeBody.setAttribute("cdefine29", arridts.Rows[0]["cDefine29"].ToString()); //表体自定义项8,string类型

xeBody.setAttribute("cdefine30", arridts.Rows[0]["cDefine30"].ToString()); //表体自定义项9,string类型

xeBody.setAttribute("cdefine31", arridts.Rows[0]["cDefine31"].ToString()); //表体自定义项10,string类型

xeBody.setAttribute("cdefine32", arridts.Rows[0]["cDefine32"].ToString()); //表体自定义项11,string类型

xeBody.setAttribute("cdefine33", arridts.Rows[0]["cDefine33"].ToString()); //表体自定义项12,string类型

xeBody.setAttribute("cdefine34", arridts.Rows[0]["cDefine34"].ToString()); //表体自定义项13,int类型

xeBody.setAttribute("cdefine35", arridts.Rows[0]["cDefine35"].ToString()); //表体自定义项14,int类型

xeBody.setAttribute("cdefine36", arridts.Rows[0]["cDefine36"].ToString()); //表体自定义项15,DateTime类型

xeBody.setAttribute("cdefine37", arridts.Rows[0]["cDefine37"].ToString()); //表体自定义项16,DateTime类型

xeBody.setAttribute("cfree1", arridts.Rows[0]["cFree1"].ToString()); //自由项

xeBody.setAttribute("cfree2", arridts.Rows[0]["cFree2"].ToString()); //自由项

xeBody.setAttribute("cfree3", arridts.Rows[0]["cFree3"].ToString()); //自由项

xeBody.setAttribute("cfree4", arridts.Rows[0]["cFree4"].ToString()); //自由项

xeBody.setAttribute("cfree5", arridts.Rows[0]["cFree5"].ToString()); //自由项

xeBody.setAttribute("cfree6", arridts.Rows[0]["cFree6"].ToString()); //自由项

xeBody.setAttribute("cfree7", arridts.Rows[0]["cFree7"].ToString()); //自由项

xeBody.setAttribute("cfree8", arridts.Rows[0]["cFree8"].ToString()); //自由项

xeBody.setAttribute("cfree9", arridts.Rows[0]["cFree9"].ToString()); //自由项

xeBody.setAttribute("cfree10", arridts.Rows[0]["cFree10"].ToString()); //自由项

#endregion

#region 判断存货是否启用保质期管理并获取保质期单位 以及批号处理 还有换算率

string cmassunit = "";

int iMassDate = 0;

bool bInvQuality = false;

int bInvBatch = 0;

DateTime dVDate = DateTime.Parse(ClsSystem.gnvl(u8Login.CurDate, DateTime.Today.ToString("yyyy-MM-dd")));

string strsql = "select cMassUnit,bInvQuality,iMassDate from inventory where cinvcode = '" + ClsSystem.gnvl(arridts.Rows[0]["cinvcode"], "") + "' and bInvQuality = 1";

System.Data.DataTable invt = DbHelperSQL.Query(strsql).Tables[0];

if (invt != null && invt.Rows.Count > 0)

{

cmassunit = ClsSystem.gnvl(invt.Rows[0]["cMassUnit"], "");

bInvQuality = Convert.ToBoolean(ClsSystem.gnvl(invt.Rows[0]["bInvQuality"], "false"));

iMassDate = Convert.ToInt16(ClsSystem.gnvl(invt.Rows[0]["iMassDate"], 0));

//计算保质期天数

if (cmassunit != "" || bInvQuality == true)

{

if (cmassunit == "1")

dVDate = dVDate.AddYears(iMassDate);

else if (cmassunit == "2")

dVDate = dVDate.AddMonths(iMassDate);

else

{

dVDate = dVDate.AddDays(iMassDate);

}

}

xeBody.setAttribute("dMadeDate", ClsSystem.gnvl(u8Login.CurDate, DateTime.Today.ToString("yyyy-MM-dd")));//生产日期

xeBody.setAttribute("dvdate", dVDate.ToString("yyyy-MM-dd"));//失效日期,DateTime类型

xeBody.setAttribute("imassdate", iMassDate);//保质期,int类型

xeBody.setAttribute("cMassUnit", ClsSystem.gnvl(invt.Rows[0]["cMassUnit"], ""));//保质期单位,int类型

}

else

{

xeBody.setAttribute("dMadeDate", "");//生产日期

xeBody.setAttribute("dvdate", "");//失效日期,DateTime类型

xeBody.setAttribute("imassdate", "");//保质期,int类型

xeBody.setAttribute("cMassUnit", "");//保质期单位,int类型

}

string bInvBatchsql = "select isnull(bInvBatch,0) as bInvBatch from inventory where cinvcode = '" + ClsSystem.gnvl(arridts.Rows[0]["cinvcode"], "") + "' ";

System.Data.DataTable bInvBatcht = DbHelperSQL.Query(bInvBatchsql).Tables[0];

if (bInvBatcht != null && bInvBatcht.Rows.Count > 0)

{

bInvBatch = Convert.ToInt16(bInvBatcht.Rows[0]["bInvBatch"]);

xeBody.setAttribute("cbatch", bInvBatch == 1 ? list.cBatch.Trim() : "");

}

else

{

xeBody.setAttribute("cbatch", "");

}

string bInvComUnitCodesql = @"SELECT c1.iChangRate,c2.iChangRate AS iChangRate1,i.cComUnitCode, i.cSTComUnitCode

FROM dbo.Inventory i

LEFT JOIN ComputationUnit c1 ON c1.cComunitCode = i.cComUnitCode

LEFT JOIN ComputationUnit c2 ON c2.cComunitCode = i.cSTComUnitCode where i.cinvcode = '" + ClsSystem.gnvl(arridts.Rows[0]["cinvcode"], "") + "' ";

System.Data.DataTable bInvComUnitCodet = DbHelperSQL.Query(bInvComUnitCodesql).Tables[0];

if (bInvComUnitCodet != null && bInvComUnitCodet.Rows.Count > 0)

{

if (string.IsNullOrEmpty(ClsSystem.gnvl(bInvComUnitCodet.Rows[0]["cSTComUnitCode"], "")))

{

xeBody.setAttribute("cAssUnit", "");

xeBody.setAttribute("iinvexchrate", "");

xeBody.setAttribute("inum", "");

}

else

{

xeBody.setAttribute("cAssUnit", ClsSystem.gnvl(bInvComUnitCodet.Rows[0]["cSTComUnitCode"], ""));

xeBody.setAttribute("iinvexchrate", DbHelperSQL.ToDouble(bInvComUnitCodet.Rows[0]["iChangRate1"], 1));

xeBody.setAttribute("inum", list.iQuantity / DbHelperSQL.ToDecimal(bInvComUnitCodet.Rows[0]["iChangRate1"], 1));

xeBody.setAttribute("iNQuantity", DbHelperSQL.ToDecimal(arridts.Rows[0]["iNQuantity"], 1) / DbHelperSQL.ToDecimal(bInvComUnitCodet.Rows[0]["iChangRate1"], 1)); //应收应发数量

}

}

else

{

xeBody.setAttribute("cAssUnit", "");

xeBody.setAttribute("iinvexchrate", "");

xeBody.setAttribute("inum", "");

}

#endregion

xeBody.setAttribute("iquantity", list.iQuantity);

#region 采购入库单单据根据含税单价计算金额

//字段名 字段 计算公式说明 取数精度

//数量 iQuantity

//原币含税单价 ioritaxcost 取系统单价精度

//原币无税单价 iOriCost iOriMoney/iQuantity 原币无税金额/iQuantity 取系统单价精度

//原币无税金额 iOriMoney ioriSum*100/(100+iTaxRate)原币价税合计*100/(100+税率)保留两位小数

//原币税额 iOriTaxPrice ioriSum- iOriMoney原币价税合计-原币无税金额保留两位小数

//原币价税合计 ioriSum iQuantity *ioritaxcost数量*原币含税单价保留两位小数

//税率 iTaxRate

//表头汇率 iExchRate

//本币无税单价 iUnitCost 本币无税金额/数量取系统单价精度

//本币无税金额 iprice 本币价税合计*100/(100+税率)保留两位小数

//本币税额 iTaxPrice 本币价税合计-本币无税金额保留两位小数

//本币价税合计 iSum 原币价税合计*汇率保留两位小数

//暂估单价 fACost 本币无税单价取系统单价精度

//暂估金额 IAPrice 本币无税金额保留两位小数

double iExchRate = DbHelperSQL.ToDouble(arridts.Rows[0]["iExchRate"], 1); //表头汇率

double iquantity = DbHelperSQL.ToDouble(list.iQuantity, 0); //数量

double iTaxRate = DbHelperSQL.ToDouble(arridts.Rows[0]["iTaxRate"], 13); //税率

double ioritaxcost = DbHelperSQL.ToDouble(arridts.Rows[0]["ioritaxcost"], 0); //原币含税单价

double ioriSum = DbHelperSQL.ToDouble(iquantity * ioritaxcost, 0, 2); //原币价税合计

double iOriMoney = DbHelperSQL.ToDouble(ioriSum * 100 / (100 + iTaxRate), 0, 2); //原币无税金额

double iOriTaxPrice = DbHelperSQL.ToDouble(ioriSum - iOriMoney, 0, 2); //原币税额

double iOriCost = iOriMoney / iquantity; //原币无税单价

double iSum = DbHelperSQL.ToDouble(ioriSum * iExchRate, 0, 2); //本币价税合计

double iprice = DbHelperSQL.ToDouble(iSum * 100 / (100 + iTaxRate), 0, 2); //本币无税金额

double iTaxPrice = DbHelperSQL.ToDouble(iSum - iprice, 0, 2); //本币税额

double iUnitCost = iprice / iquantity; //本币无税单价

double fACost = iUnitCost; //暂估单价

double IAPrice = iprice; //暂估金额

xeBody.setAttribute("ioritaxcost", ioritaxcost);

xeBody.setAttribute("iorisum", ioriSum);

xeBody.setAttribute("iorimoney", iOriMoney);

xeBody.setAttribute("ioritaxprice", iOriTaxPrice);

xeBody.setAttribute("ioricost", iOriCost);

xeBody.setAttribute("isum", iSum);

xeBody.setAttribute("iprice", iprice);

xeBody.setAttribute("itaxprice", iTaxPrice);

xeBody.setAttribute("iunitcost", iUnitCost);

xeBody.setAttribute("facost", fACost);

xeBody.setAttribute("iaprice", IAPrice);

#endregion

xeBody.setAttribute("cbmemo", arridts.Rows[0]["cbmemo"].ToString()); //表体自定义项1,string类型

xeBody.setAttribute("bgift", ClsSystem.gnvl(arridts.Rows[0]["bgift"], 0)); //订单号,string类型

xeBody.setAttribute("cpoid", ClsSystem.gnvl(arridts.Rows[0]["cPOID"], "")); //订单号,string类型

xeBody.setAttribute("iposid", ClsSystem.gnvl(arridts.Rows[0]["iPOsID"], "")); //订单子表ID,int类型

xeBody.setAttribute("iarrsid", ClsSystem.gnvl(arridts.Rows[0]["Autoid"], ""));//采购到货单子表标识,string类型

if ((string)arridts.Rows[0]["cbustype"] == "委外加工")

{

xeBody.setAttribute("iomodid", ClsSystem.gnvl(arridts.Rows[0]["iPOsID"], "")); //订单子表ID,int类型

xeBody.setAttribute("cpoid", ClsSystem.gnvl(arridts.Rows[0]["cPOID2"], "")); //订单号,string类型

}

xeBody.setAttribute("cbarvcode", ClsSystem.gnvl(arridts.Rows[0]["cCode"], "")); //到货单号,string类型

xeBody.setAttribute("dbarvdate", ClsSystem.gnvl(arridts.Rows[0]["dDate"], "").Replace("/", "-")); //到货日期,DateTime类型

xeBody.setAttribute("iTaxRate", ClsSystem.gnvl(arridts.Rows[0]["iTaxRate"], "")); //税率

xeBody.setAttribute("bTaxCost", ClsSystem.gnvl(arridts.Rows[0]["bTaxCost"], "")); //记税方式

xeBody.setAttribute("iNQuantity", ClsSystem.gnvl(arridts.Rows[0]["iNQuantity"], "")); //应收应发数量

//xeBody.setAttribute("bgsp", "0"); //应收应发数量

// xeBody.setAttribute("corufts", ClsSystem.gnvl(arridts.Rows[0]["corufts"], "")); //时间戳,string类型

xeBody.setAttribute("irowno", irowno);

#region 赠品单价去除

if (ClsSystem.gnvl(arridts.Rows[0]["bgift"], "0") == "1")

{

xeBody.setAttribute("ioritaxcost", 0);

xeBody.setAttribute("iorisum", 0);

xeBody.setAttribute("iorimoney", 0);

xeBody.setAttribute("ioritaxprice", 0);

xeBody.setAttribute("ioricost", 0);

xeBody.setAttribute("isum", 0);

xeBody.setAttribute("iprice", 0);

xeBody.setAttribute("itaxprice", 0);

xeBody.setAttribute("iunitcost", 0);

xeBody.setAttribute("facost", 0);

xeBody.setAttribute("iaprice", 0);

}

#endregion

if (irowno != 1)

{

docBody.selectSingleNode("//rs:data").appendChild(newNode);

}

irowno++;

}

else

{

DbHelperSQL.RemoveImsQueueIDNew(root.paramList, "RdRecord01");

_return = PubConstant.CombReturn(false, "error06", string.Format("请输入正确的采购到货单ERP_ID!"));

return _return;

}

}

//传入表头的MSXML2.DOMDocumentClass对象

broker.AssignNormalValue("DomHead", docHead);

//传入表体的MSXML2.DOMDocumentClass对象

broker.AssignNormalValue("domBody", docBody);

//给普通参数domPosition赋值。此参数的数据类型为System.Object,此参数按引用传递,表示货位:传空

broker.AssignNormalValue("domPosition", null);

//该参数errMsg为OUT型参数,由于其数据类型为System.String,为一般值类型,因此不必传入一个参数变量。在API调用返回时,可以通过GetResult("errMsg")获取其值

//给普通参数cnnFrom赋值。此参数的数据类型为ADODB.Connection,此参数按引用传递,表示连接对象,如果由调用方控制事务,则需要设置此连接对象,否则传空

broker.AssignNormalValue("cnnFrom", null);

//该参数VouchId为INOUT型普通参数。此参数的数据类型为System.String,此参数按值传递。在API调用返回时,可以通过GetResult("VouchId")获取其值

string reVouchId = "";

broker.AssignNormalValue("VouchId", reVouchId);

//该参数domMsg为OUT型参数,由于其数据类型为MSXML2.IXMLDOMDocument2,非一般值类型,因此必须传入一个参数变量。在API调用返回时,可以直接使用该参数

MSXML2.IXMLDOMDocument2 domMsg = new DOMDocument();

broker.AssignNormalValue("domMsg", domMsg);

bool bCheck = Convert.ToBoolean(DbHelperSQL.GetSingle("select cValue from AccInformation where cName='ballowzero'"));

//给普通参数bCheck赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否控制可用量。

broker.AssignNormalValue("bCheck", !bCheck);

//给普通参数bBeforCheckStock赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示检查可用量

broker.AssignNormalValue("bBeforCheckStock", false);

//给普通参数bIsRedVouch赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否红字单据

broker.AssignNormalValue("bIsRedVouch", redBill);

//给普通参数sAddedState赋值。此参数的数据类型为System.String,此参数按值传递,表示传空字符串

broker.AssignNormalValue("sAddedState", "");

//给普通参数bReMote赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否远程:转入false

broker.AssignNormalValue("bReMote", false);

//第六步:调用API

if (!broker.Invoke())

{

//错误处理

Exception apiEx = broker.GetException();

if (apiEx != null)

{

if (apiEx is MomSysException)

{

DbHelperSQL.RemoveImsQueueIDNew(root.paramList, "RdRecord01");

MomSysException sysEx = apiEx as MomSysException;

//Console.WriteLine("系统异常:" + sysEx.Message);

_return = PubConstant.CombReturn(false, "ERROR81", "系统异常:" + sysEx.Message);

}

else if (apiEx is MomBizException)

{

DbHelperSQL.RemoveImsQueueIDNew(root.paramList, "RdRecord01");

MomBizException bizEx = apiEx as MomBizException;

//Console.WriteLine("API异常:" + bizEx.Message);

_return = PubConstant.CombReturn(false, "ERROR82", "API异常:" + bizEx.Message);

//todo:异常处理

}

//异常原因

String exReason = broker.GetExceptionString();

if (exReason.Length != 0)

{

DbHelperSQL.RemoveImsQueueIDNew(root.paramList, "RdRecord01");

_return = PubConstant.CombReturn(false, "ERROR83", "异常原因:" + exReason);

//Console.WriteLine("异常原因:" + exReason);

}

}

//结束本次调用,释放API资源

broker.Release();

return _return;

}

//第七步:获取返回结果

//获取返回值

//获取普通返回值。此返回值数据类型为System.Boolean,此参数按值传递,表示返回值:true:成功,false:失败

System.Boolean result = Convert.ToBoolean(broker.GetReturnValue());

//获取out/inout参数值

//获取普通OUT参数errMsg。此返回值数据类型为System.String,在使用该参数之前,请判断是否为空

System.String errMsgRet = broker.GetResult("errMsg") as System.String;

//获取普通INOUT参数VouchId。此返回值数据类型为System.String,在使用该参数之前,请判断是否为空

System.String VouchIdRet = broker.GetResult("VouchId") as System.String;

//System.String cCodeRet = broker.GetResult("cCode") as System.String;

//获取普通OUT参数domMsg。此返回值数据类型为MSXML2.IXMLDOMDocument2,在使用该参数之前,请判断是否为空

MSXML2.IXMLDOMDocument2 domMsgRet = (MSXML2.IXMLDOMDocument2)broker.GetResult("domMsg");

//结束本次调用,释放API资源

broker.Release();

netLogin.ShutDown();

u8Login.ShutDown();

if (!result){}

U8采购入库单API接口示例(参照采购到货)相关推荐

  1. U8到货拒收单API接口示例(参照采购到货)

    //第二步:构造环境上下文对象,传入login,并按需设置其它上下文参数                 U8EnvContext envContext = new U8EnvContext();   ...

  2. 旺店通与金蝶云星空对接集成采购入库单接口

    旺店通·旗舰奇门与金蝶云星空对接集成采购入库单查询连通销售退货新增V1(12-采购入库单集成方案-P) 数据源系统:旺店通·旗舰奇门 旺店通是北京掌上先机网络科技有限公司旗下品牌,国内的零售云服务提供 ...

  3. 用友U8对接打通旺店通·企业奇门获取产成品入库单列表接口与创建其他入库单接口

    用友U8对接打通旺店通·企业奇门获取产成品入库单列表接口与创建其他入库单接口 对接系统:用友U8 用友U8+不再是一款单纯的ERP产品,它为成长型企业构建集精细管理.产业链协同与社交化运营为一体的V1 ...

  4. 金蝶云星空对接打通旺店通·企业版采购入库查询接口与创建采购入库单接口

    接通系统:金蝶云星空 金蝶K/3Cloud(金蝶云星空)是移动互联网时代的新型ERP,是基于WEB2.0与云技术的新时代企业管理服务平台.金蝶K/3Cloud围绕着"生态.人人.体验&quo ...

  5. U8采购入库单的月入库量

    USE [UFDATA_001_2018] GO /****** Object: StoredProcedure [dbo].[P_Quck_MonthOutRd01] Script Date: 20 ...

  6. 旺店通·企业奇门与金蝶云星空对接集成查询采购入库单连通采购入库新增(采购入库单 all)

    旺店通·企业奇门与金蝶云星空对接集成查询采购入库单连通采购入库新增(采购入库单 all) 来源系统:旺店通·企业奇门 旺店通是北京掌上先机网络科技有限公司旗下品牌,国内的零售云服务提供商,基于云计算S ...

  7. 采购入库单记帐后在明细帐等不显示

    问题现象: 2008年7月7日单据号0000000034号采购入库单已做正常单据记帐,但是,在明细帐.流水帐.汇总表等表里均找不到,在恢复单据记帐里也找不到.     原因分析: 先备份数据,然后在查 ...

  8. C#圆通快递电子面单api接口调用方法

    快递电子面单支持多家快递物流公司单号获取.分拣码返回.面单打印.在线下单发货.通知快递员上门取件等功能,可用于电商平台.自营商城.打单工具.WMS仓储系统.APP等需要发货的场景,可有效提高商家的打印 ...

  9. 物流快递电子面单Api接口怎么申请对接(顺丰、快递鸟、菜鸟、拼多多)

    关于电子面单: 电子面单是一种通过热敏纸打印输出纸质物流面单的物流服务.通过热感应显示文字,打印速度比传统针式打印速度提升4~6倍.电子面单以接口形式嵌入到自己的系统.网站上,可以在自己的平台操作打印 ...

最新文章

  1. Extjs Ext.TreePanel
  2. 递归概念分类注意事项
  3. apm java_非Java专家的APM:什么泄漏?
  4. python数据展示库_收藏!盘点很实用的数据科学Python库
  5. pycocotools安装_pycocotools安装问题
  6. java arraylist
  7. [转载] LeetCode题解(面试16.22):兰顿蚂蚁(Python)
  8. Excel自学详细视频教程百度网盘分享
  9. AutoCAD 2019 汉化包
  10. word段落中插入公式后格式编辑
  11. ubuntu系统上进行usb相机端口绑定
  12. matlab弹奏旋律(发声)笔记
  13. 2021年上半年软考真题数据库系统工程师真题
  14. vue项目发版,缓存问题。
  15. 网赚:通过网上引流项目变现要趁早!
  16. python中计时工具timeit模块的基本用法
  17. 鲸鸿动能流量变现服务中国大陆地区测试流程
  18. 预告 | 5月26日IGS大会腾讯云游戏新文娱分论坛遇见TcaplusDB
  19. 计算机算法设计与分析(国科大考试)
  20. 全自动洗衣机matlab仿真,单片机全自动洗衣机程序+仿真+原理图设计调试与分析...

热门文章

  1. U3D-实时PVP小地图实现
  2. shell 脚本程序中空格 $符号的使用
  3. 制作角色血条 [代码清单10-2]
  4. js监听浏览器关闭事件(区分刷新和关闭,兼容IE9,10,11,Edge,Chrome和Firefox)
  5. asp服务器管理系统,ASP服务器软件
  6. 你不知道的水浒好汉,在这里!
  7. 开学季如何选择数码好物,几款开学必备的数码好物分享
  8. SCP不用密码传输文件
  9. python常用内置函数乘法_每个 Python 高手都应该知道的内置函数
  10. 元镜头——手机相机的下一场革命