private void PostCashAdvancedToSAP(WorkflowDataFields fields) { string accountName = string.Empty; SPFieldUser fieldUser = SPContext.Current.ListItem.Fields["ApplicantSPUser"] as SPFieldUser; if (fieldUser != null) { SPFieldUserValue fieldUserValue = fieldUser.GetFieldValue(fields["ApplicantSPUser"].AsString()) as SPFieldUserValue; accountName = fieldUserValue.User.LoginName; } Employee emp = UserProfileUtil.GetEmployee(accountName); if (emp != null) { List<SapParameter> mSapParametersCD = new List<SapParameter>(); SapParameter mSapParameters = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "KR", BusArea = "0001", Currency = "RMB", EmployeeID = emp.EmployeeID, EmployeeName = emp.DisplayName, ExchRate = 1, Header = emp.EmployeeID + "CashAdvanced - OR", RefDocNo = fields["Title"].AsString(), CashAmount = decimal.Parse(fields["CashAdvanced"].AsString()) }; if (mSapParameters.CashAmount <= 2000) { mSapParameters.PymtMeth = "E"; } mSapParametersCD.Add(mSapParameters); string sAPNumber = ""; string errorMsg = ""; bool postResult = false; ISapExchange sapExchange = SapExchangeFactory.GetCashAdvance(); List<object[]> result = sapExchange.ImportDataToSap(mSapParametersCD); //if (null == result) //{ // errorMsg += hfEmployeeName + "-" + DateTime.Now.ToShortDateString() + ":" + "Connection failed."; //} if (null == result) { this.Page.ClientScript.RegisterStartupScript(typeof(DataForm), "alert", "<script type=\"text/javascript\">alert('Connection failed !'); window.location = window.location;</script>"); return; } else { for (int i = 0; i < result.Count; i++) { SapParameter sp = (SapParameter)result[i][0]; bool bl = (bool)result[i][2]; if (bl) { SapResult sr = (SapResult)result[i][1]; sAPNumber = sr.OBJ_KEY; postResult = true; } else { if (result[i][1] is string) { errorMsg += emp.DisplayName + "-" + DateTime.Now.ToShortDateString() + ":" + result[i][1].ToString() + " \n "; } else { string wfID = sp.RefDocNo; SapResult sr = (SapResult)result[i][1]; foreach (SAP.Middleware.Table.RETURN ret in sr.RETURN_LIST) { errorMsg += emp.DisplayName + "-" + DateTime.Now.ToShortDateString() + ":" + ret.MESSAGE + " \n "; } } } } } var delegationList = CA.SharePoint.SharePointUtil.GetList(WorkflowListName.TravelRequestWorkflow2); SPQuery query = new SPQuery(); query.Query = string.Format("<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>{0}</Value></Eq></Where>", fields["Title"].AsString()); SPListItemCollection trListItem = delegationList.GetItems(query); SPListItem trItem = trListItem[0]; string emsg = trItem["ErrorMsg"].AsString(); emsg += errorMsg; if (postResult) { trItem["SAPNumber"] = sAPNumber; } else { trItem["ErrorMsg"] = emsg; } trItem.Web.AllowUnsafeUpdates = true; trItem.Update(); trItem.Web.AllowUnsafeUpdates = false; } }
/// <summary> /// 得到和SAP交互时的参数 /// </summary> /// <param name="dt"></param> /// <returns></returns> List<SapParameter> GetPOTypeChangePar(DataTable dt) { List<SapParameter> listPar = new List<SapParameter>(); foreach (DataRow dr in dt.Rows) { if (dr["NewType"] == null || dr["NewType"].ToString().Trim().Length==0) { continue; } SapParameter par = new SapParameter(); par.SapNumber = dr["PONO"].ToString(); par.PaymentCond = dr["NewType"].ToString(); listPar.Add(par); } return listPar; }
/// <summary> /// 得到和SAP交互时的参数 /// </summary> /// <param name="dt"></param> /// <returns></returns> List<SapParameter> GetSapParaFormDT(List<string> listSeachCondition) { List<SapParameter> listPar = new List<SapParameter>(); foreach (string str in listSeachCondition) { SapParameter par = new SapParameter(); par.SapNumber = str; listPar.Add(par); } return listPar; }
/// <summary> /// 得到和SAP交互时的参数 /// </summary> /// <param name="dt"></param> /// <returns></returns> List<SapParameter> GetSapParaFormDT(DataTable dt) { List<SapParameter> listPar = new List<SapParameter>(); foreach (DataRow dr in dt.Rows) { SapParameter par = new SapParameter(); par.SapNumber = dr["StyleNO"].ToString(); par.PaymentCond = dr["NewOSP"].ToString(); listPar.Add(par); } return listPar; }
private SapParameter GetSapParameterByWorkFlowNumber(string workFlowNumber) { DataTable sapDataTable = ExpatriateBenefitClaimCommon.GetEmployeeExpenseClaimSAPItemsByWorkFlowNumber("Expatriate Benefit Claim SAP Workflow", workFlowNumber).GetDataTable(); DataTable sapItemDataTable = ExpatriateBenefitClaimCommon.GetEmployeeExpenseClaimSAPItemsByWorkFlowNumber("ExpatriateBenefitClaimSAPItems", workFlowNumber).GetDataTable(); if (null == sapDataTable) { sapDataTable = new DataTable(); } if (null == sapItemDataTable) { sapItemDataTable = new DataTable(); } string cashAdvanceWorkFlowNumber = ""; string employeeID = ""; string employeeName = ""; string expenseDescription = ""; StringBuilder logStr = new StringBuilder(); if (sapDataTable != null && sapDataTable.Rows.Count > 0) { expenseDescription = sapDataTable.Rows[0]["ExpenseDescription"].ToString(); cashAdvanceWorkFlowNumber = sapDataTable.Rows[0]["CashAdvanceWorkFlowNumber"].ToString(); string name = sapDataTable.Rows[0]["Applicant"].ToString(); Employee employee = UserProfileUtil.GetEmployee(name.Substring(name.IndexOf('(') + 1, name.IndexOf(')') - name.IndexOf('(') - 1)); employeeID = employee.EmployeeID; employeeName = employee.DisplayName; } CashAdvance[] CashAdvances = new CashAdvance[] { }; if (cashAdvanceWorkFlowNumber != "") { List<string> list = cashAdvanceWorkFlowNumber.Split(';').ToList<string>(); list.Remove(""); CashAdvances = new CashAdvance[list.Count]; for (int i = 0; i < list.Count; i++) { string caWorkFlowNumber = list[i].Substring(0, list[i].IndexOf("-")); string caAmount = list[i].Substring(list[i].IndexOf("-") + 1); CashAdvance cashAdvance = new CashAdvance(); cashAdvance.ID = caWorkFlowNumber; cashAdvance.CashAmount = Int32.Parse(caAmount); CashAdvances[i] = cashAdvance; logStr.AppendFormat("CashAdvance:{0} cashAdvance.ID:{1} cashAdvance.CashAmount:{2}\r\n", i, caWorkFlowNumber, Int32.Parse(caAmount)); } } SapParameter sapParameters = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "KR", BusArea = "0001", Currency = "RMB", EmployeeID = employeeID, EmployeeName = employeeName, ExchRate = 1, Header = expenseDescription, RefDocNo = workFlowNumber, UserName = "******", CashAdvances = CashAdvances }; logStr.AppendFormat("WorkFlowNumber:{0}\r\nEmployeeID:{1}\r\nmployeeName:{2}\r\n", workFlowNumber, employeeID, employeeName); List<ExpenceDetail> expenceDetailsList = new List<ExpenceDetail>(); if (sapItemDataTable != null && sapItemDataTable.Rows.Count > 0) { logStr.AppendFormat("====================Expence Details====================\r\n"); foreach (DataRow dr in sapItemDataTable.Rows) { if (dr["ExpenseType"].ToString().IndexOf("OR - employee vendor") == -1 && dr["ExpenseType"].ToString().IndexOf("OR - cash advance") == -1) { ExpenceDetail expenceDetail = new ExpenceDetail(); expenceDetail.AccountGL = dr["GLAccount"].ToString(); expenceDetail.Amount = decimal.Parse(dr["ItemAmount"].ToString()) < 0 ? 0 - decimal.Parse(dr["ItemAmount"].ToString()) : decimal.Parse(dr["ItemAmount"].ToString()); expenceDetail.CostCenter = dr["CostCenter"].ToString(); expenceDetail.ItemText = employeeName + " " + dr["ExpenseType"].ToString(); expenceDetailsList.Add(expenceDetail); logStr.AppendFormat("AccountGL:{0} Amount:{1} CostCenter:{2} ItemText:{3}\r\n", expenceDetail.AccountGL, expenceDetail.Amount, expenceDetail.CostCenter, expenceDetail.ItemText); } } logStr.AppendFormat("====================Expence Details====================\r\n"); } WriteErrorLog(logStr); sapParameters.ExpenceDetails = expenceDetailsList; return sapParameters; }
/// <summary> /// 初始化数据 /// </summary> static void InitializeData() { //Travel Request Claim 数据 SapParameter mSapParameters1 = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "KR", BusArea = "0001", Currency = "RMB", EmployeeID = "0039000001", // EmployeeName = "TEST", // ExchRate = 1, Header = "Travel Expense Claim", RefDocNo = "CA" + DateTime.Now.ToString("yyyyMMddHHmmss"),// UserName = "******", CashAmount = 100, RefDocNo1 = "", PaidByCC = 100 }; List<ExpenceDetail> expenceDetails1 = new List<ExpenceDetail>(); expenceDetails1.Add(new ExpenceDetail() { Amount = 11.0478m }); //expenceDetails1.Add(new ExpenceDetail() { Amount = 100 }); //expenceDetails1.Add(new ExpenceDetail() { Amount = 100 }); //expenceDetails1.Add(new ExpenceDetail() { Amount = 100 }); //expenceDetails1.Add(new ExpenceDetail() { RefKey = "201112", Amount = 100, CompanyStd = 50, IsApproved = false, IsPaidByCC = true }); //expenceDetails1.Add(new ExpenceDetail() { Amount = 100 }); List<ExpenceDetail> groupExpenceDetails1 = new List<ExpenceDetail>(); groupExpenceDetails1.Add(new ExpenceDetail() { AccountGL = "0011020100", Amount = 11.0478m, CostCenter = "D001", ItemText = "EricZheng Travel_hotel" }); //groupExpenceDetails1.Add(new ExpenceDetail() { AccountGL = "0011020100", Amount = 100, CostCenter = "D001", ItemText = "EricZheng Travel_meal" }); //groupExpenceDetails1.Add(new ExpenceDetail() { AccountGL = "0015511004", Amount = 100, CostCenter = "D001", ItemText = "EricZheng Travel_local_transportation" }); //groupExpenceDetails1.Add(new ExpenceDetail() { AccountGL = "0015511003", Amount = 100, CostCenter = "D001", ItemText = "EricZheng Travel_others" }); //groupExpenceDetails1.Add(new ExpenceDetail() { AccountGL = "0015511003", Amount = 150, CostCenter = "D001", ItemText = "EricZheng Sample_purchase" }); mSapParameters1.GroupExpenceDetails = groupExpenceDetails1; mSapParameters1.ExpenceDetails = expenceDetails1; mSapParametersTR.Add(mSapParameters1); string ewfNo = DateTime.Now.ToString("HHmmss"); //Employee Claim 数据 SapParameter mSapParameters2 = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "KR", BusArea = "0001", Currency = "RMB", //EmployeeID = "0000008047", //申请人ID EmployeeID = "0099999999", //申请人ID EmployeeName = "TEST", //申请人名字 Header = "Payment Request", //工作流名字 RefDocNo = ewfNo, //工作流ID UserName = "******", }; // Console.WriteLine(ewfNo); List<ExpenceDetail> expenceDetails2 = new List<ExpenceDetail>(); expenceDetails2.Add(new ExpenceDetail() { AccountGL = "15171500", ExchRate = 1m, Amount = 1200m, CostCenter = "S008", ItemText = "Payment Request" }); expenceDetails2.Add(new ExpenceDetail() { AccountGL = "15171500", ExchRate = 1m, Amount = 1300m, CostCenter = "S008", ItemText = "Payment Request" }); expenceDetails2.Add(new ExpenceDetail() { AccountGL = "12210102", ExchRate = 1m, Amount = 425m, CostCenter = "", ItemText = "Payment Request" }); // expenceDetails2.Add(new ExpenceDetail() { AccountGL = "15511200", Amount = 100, CostCenter = "D001", ItemText = "EricZheng Travel_local_transportation" }); // expenceDetails2.Add(new ExpenceDetail() { AccountGL = "15511003", Amount = 100, CostCenter = "D001", ItemText = "EricZheng Travel_others" }); // expenceDetails2.Add(new ExpenceDetail() { AccountGL = "15511406", Amount = 100, CostCenter = "D001", ItemText = "EricZheng Sample_purchase" }); mSapParameters2.VendorInfo = new Vendor() { BankAcct = "234567893456789345678", BankCity = "CN", BankNo = "104290003033", City = "上海", Country = "CN", Name = "上海文思创新科技有限公司-上海文思创新科技有限公司" }; mSapParameters2.ExpenceDetails = expenceDetails2; mSapParametersEC.Add(mSapParameters2); //Cash Advance 数据 SapParameter mSapParameters3 = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "KR", BusArea = "0001", Currency = "RMB", EmployeeID = "600011069", // EmployeeName = "TEST", // ExchRate = 1, Header = "Cash Advance", RefDocNo = "CA" + DateTime.Now.ToString("yyyyMMddHHmmss"),// UserName = "******", CashAmount = 200, // PaidByCC = 100 }; mSapParametersCD.Add(mSapParameters3); //Credit Card 数据 SapParameter mSapParameters4_1 = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "KR", BusArea = "0001", Currency = "RMB", EmployeeID = "6000000069", // EmployeeName = "Test", // ExchRate = 1, Header = "Credit Card", //工作流名字 RefDocNo = "CACC1234567_1", // UserName = "******", BankName = "中国工商银行上海市分行第二营业部" }; List<ExpenceDetail> expenceDetails4_1 = new List<ExpenceDetail>(); expenceDetails4_1.Add(new ExpenceDetail() { RefKey = "10011", EmpID = "6000000069", Amount = 225, ItemText = "2342_225" }); expenceDetails4_1.Add(new ExpenceDetail() { RefKey = "10012", EmpID = "6000000069", Amount = 100, ItemText = "2342_100" }); expenceDetails4_1.Add(new ExpenceDetail() { RefKey = "10013", EmpID = "", Amount = -300, ItemText = "2342_-300" }); mSapParameters4_1.ExpenceDetails = expenceDetails4_1; ////Credit Card 数据 //SapParameter mSapParameters4_2 = new SapParameter() //{ // BusAct = "RFBU", // CompCode = "CA10", // DocType = "KR", // BusArea = "0001", // Currency = "USD", // EmployeeID = "6000000069", // // EmployeeName = "TEST", // // ExchRate = 0, // Header = "Credit Card", //工作流名字 // // RefDocNo = "EEC" + DateTime.Now.ToString("yyyyMMddHHmmss"), //工作流ID // RefDocNo = "CA0000002_2", // BankName = "工商银行美国分行" //}; //List<ExpenceDetail> expenceDetails4_2 = new List<ExpenceDetail>(); //expenceDetails4_2.Add(new ExpenceDetail() { RefKey = "1002", Amount = -200, ItemText = "迅销(中国)商贸有限公司中山公园店" }); // mSapParameters4_2.ExpenceDetails = expenceDetails4_2; mSapParametersCC.Add(mSapParameters4_1); // mSapParametersCC.Add(mSapParameters4_2); //Emplyee Credit Card 数据 SapParameter mSapParameters5 = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "KR", BusArea = "0001", Currency = "RMB", // EmployeeID = "6000000150", //申请人ID EmployeeID = "6000000069", EmployeeName = "TEST", //申请人名字 ExchRate = 0, Header = "Emplyee Credit Card", //工作流名字 RefDocNo = "EEC" + DateTime.Now.ToString("yyyyMMddHHmmss"), //工作流ID UserName = "******" }; List<ExpenceDetail> expenceDetails5 = new List<ExpenceDetail>(); expenceDetails5.Add(new ExpenceDetail() { RefKey = "10011", Currency = "RMB", AccountGL = "0015511002", Amount = 225, CostCenter = "D001", ItemText = "EricZheng Travel_hotel" }); expenceDetails5.Add(new ExpenceDetail() { RefKey = "10012", Currency = "RMB", AccountGL = "0015511004", Amount = 100, CostCenter = "D001", ItemText = "EricZheng Travel_meal" }); expenceDetails5.Add(new ExpenceDetail() { RefKey = "10013", Currency = "RMB", AccountGL = "0015511406", Amount = -300, CostCenter = "D001", ItemText = "EricZheng Travel_local_transportation" }); //expenceDetails5.Add(new ExpenceDetail() { RefKey = "1004", AccountGL = "0015511003", Amount = -100, CostCenter = "D001", ItemText = "EricZheng Travel_others" }); //expenceDetails5.Add(new ExpenceDetail() { RefKey = "1005", AccountGL = "0015511406", Amount = 600, CostCenter = "D001", ItemText = "EricZheng Sample_purchase" }); mSapParameters5.ExpenceDetails = expenceDetails5; mSapParametersECC.Add(mSapParameters5); string wfNumber = "PO" + DateTime.Now.ToString("yyyyMMddHHmm"); //Purchase Order 数据 SapParameter mSapParameters6 = new SapParameter() { DocType = "SA", Pmnttrms = "Z002", PurGroup = "NT1", //如果是固定资产,PurGroup的值为AST;否则为 NT1 DocDate = DateTime.Now.ToString("yyyyMMdd"), Vendor = "0000008047", PaymentCond = "TEST", //分期付款信息 RefDocNo = wfNumber, Currency = "RMB" }; List<PurchaseOrderItem> purchaseOrder1 = new List<PurchaseOrderItem>(); purchaseOrder1.Add(new PurchaseOrderItem() { ItemNo = 1, //数据中唯一的ID MatlGroup = "ZNT_STSTY", //ZNT_OTHER Quantity = 121.11m, CondValue = 81, AssetNo = "", //001130000005如果是固定资产,AssetNo的值为实际的AssetNo值;否则为空 CostCenter = "H1012213", //如果是固定资产,CostCenter的值为 空;否则为实际的CostCenter值 Acctasscat = "K", //如果是固定资产,Acctasscat的值为 A;否则为 K TaxCode = "J1", //如果是固定资产,TaxCode的值为JO(无税);否则为 J1 (有税) Description = "test test", Currency = "RMB" } ); //purchaseOrder1.Add(new PurchaseOrderItem() //{ // ItemNo = 1, //数据中唯一的ID // MatlGroup = "ZNT_OTHER", //如果是固定资产,MatlGroup的值为"ZNT_OTHER"固定值;否则AssetNo 关联的MatlGroup值 // Quantity = 1, // CondValue = 10, // AssetNo = "001210000001", //如果是固定资产,AssetNo的值为实际的AssetNo值;否则为空 // CostCenter = "", //如果是固定资产,CostCenter的值为 空;否则为实际的CostCenter值 // Acctasscat = "A", //如果是固定资产,Acctasscat的值为 A;否则为 K // TaxCode = "J0", //如果是固定资产,TaxCode的值为JO(无税);否则为 J1 (有税) // Description = "test test", // Currency = "USD" //} // ); mSapParameters6.PurchaseOrderItems = purchaseOrder1; mSapParametersPO.Add(mSapParameters6); //Purchase Order Return 数据 SapParameter mSapParameters7 = new SapParameter() { DocType = "SA", SapNumber = "6500000142" }; List<PurchaseOrderItem> purchaseOrder2 = new List<PurchaseOrderItem>(); purchaseOrder2.Add(new PurchaseOrderItem() { Quantity = 8, ItemNo = 1 }); mSapParameters7.PurchaseOrderItems = purchaseOrder2; mSapParametersPOR.Add(mSapParameters7); //Stores Receive 数据 SapParameter mSapParameters8 = new SapParameter() { DocDate = "20120203", RefDocNo = "6500000201", Header = DateTime.Now.ToString("yyyyMMddHHmmss") }; List<StoresReceiveItem> storesReceive = new List<StoresReceiveItem>(); storesReceive.Add(new StoresReceiveItem() { Quantity = 9, SapNumber = "6500000201", ItemNo = 1 }); storesReceive.Add(new StoresReceiveItem() { Quantity = 8, SapNumber = "6500000201", ItemNo = 2 }); mSapParameters8.StoresReceiveItems = storesReceive; mSapParametersGR.Add(mSapParameters8); //Payment Request 数据 SapParameter mSapParameters9 = new SapParameter() { DocDate = "20120216", RefDocNo = "6500001595", Header = DateTime.Now.ToString("yyyyMMddHHmmss") }; List<StoresReceiveItem> paymentRequest = new List<StoresReceiveItem>(); paymentRequest.Add(new StoresReceiveItem() { Quantity = 1, SapNumber = "6500001595", ItemNo = 1 }); //paymentRequest.Add(new StoresReceiveItem() //{ // Quantity = 121M, // SapNumber = "6500001547", // ItemNo = 2 //}); //paymentRequest.Add(new StoresReceiveItem() //{ // Quantity = 121M, // SapNumber = "6500001547", // ItemNo = 3 //}); mSapParameters9.StoresReceiveItems = paymentRequest; mSapParametersPR.Add(mSapParameters9); //Purchase Order Return 数据 SapParameter mSapParameters10 = new SapParameter() { RefDocNo = "170104", Vendor = "6000000069" }; mSapParametersPRQ.Add(mSapParameters10); }
/// <summary> /// GRSR Post到SAP /// </summary> public static void PostGRSRDataToSap(string sDate,string sPONO) { List<SapParameter> mSapParametersGR = new List<SapParameter>(); DataTable dt = GetUnSAPGRSR(sPONO);///己经做过EWF GR/SR,且post到sap中去过,但没有 post 到 sys GR/SR if (null == dt) { return; } var poItem = from dr in dt.AsEnumerable() group dr by new { Title = dr["Title"], SapNO = dr["SapNO"] } into g select new { Title = g.Key.Title, SapNO = g.Key.SapNO, }; foreach (var po in poItem)/// { string sSapNO=po.SapNO.ToString(); string sItemPONO = po.Title.ToString();//每项的PO号 DataRow[] drArrayUnRecieve = dt.Select(string.Format("Title='{0}' and IsRecieved<>1", sItemPONO)); if (drArrayUnRecieve.Count() != 0)//PO记录里有没有做完EWF收货的PO Item记录。 { continue; } if (sItemPONO.EndsWith("R", StringComparison.InvariantCultureIgnoreCase)) { continue; } bool isConfigDate = isDateavalible(sItemPONO, sDate); if (!isConfigDate) { continue; } decimal dUnDoPercent = GetUnPaiedPercent(sItemPONO);//没有做完的比例 if (dUnDoPercent == 0)//都做过了SysGR/SR { continue; } SapParameter mSapParGRSR = new SapParameter() { DocDate = DateTime.Now.ToString("yyyyMMdd"), RefDocNo = sSapNO,// "6500000198", Header = sItemPONO// DateTime.Now.ToString("yyyyMMddHHmmss") }; string sCondigion = string.Concat("Title='", sItemPONO, "'"); DataRow[] drArray = dt.Select(sCondigion); List<StoresReceiveItem> listGRSRItem = GetSAPGRSRItem(drArray, sSapNO, sItemPONO, dUnDoPercent); if (null == listGRSRItem || listGRSRItem.Count == 0) { Common.WriteErrorLog(string.Format("There are no available items in PO '{0}' for Post to SAp System GR/SR", sItemPONO)); continue; } mSapParGRSR.StoresReceiveItems = listGRSRItem; mSapParametersGR.Add(mSapParGRSR); StringBuilder sbResult = new StringBuilder(); sbResult.Append(sItemPONO); sbResult.Append(" POst SysGRSR到SAP参数:\n"); sbResult.Append("DocDate:" + mSapParGRSR.DocDate); sbResult.Append("\n RefDocNo:" + mSapParGRSR.RefDocNo); sbResult.Append("\n PurGroup:" + mSapParGRSR.PurGroup); Common.WriteErrorLog(sbResult.ToString()); } ISapExchange iseGRSR = SapExchangeFactory.GetStoresReceive(); List<object[]> resultGRSR = iseGRSR.ImportDataToSap(mSapParametersGR); Common.ProcessResult(resultGRSR, "IsSystemGR", "GRSRSapErrorInfo", true); }
private static void SetSapParameter(SapParameter mSapParameters, Hashtable parametersHash) { foreach (DictionaryEntry entry in parametersHash) { foreach (PropertyInfo prop in mSapParameters.GetType().GetProperties()) { if (entry.Key.AsString() == prop.Name) { switch (prop.PropertyType.ToString()) { case "System.Decimal": prop.SetValue(mSapParameters, decimal.Parse(entry.Value.AsString()), null); break; default: prop.SetValue(mSapParameters, entry.Value.AsString(), null); break; } break; } } } }
private SapParameter GetSapParameterByWorkFlowNumber(string workFlowNumber, out string workFlowNumberAndSAPNO) { DataTable sapDataTable = PaymentRequestSAPCommon.GetEmployeeExpenseClaimSAPItemsByWorkFlowNumber("Payment Request SAP WorkFlow", workFlowNumber).GetDataTable(); DataTable sapItemDataTable = PaymentRequestSAPCommon.GetEmployeeExpenseClaimSAPItemsByWorkFlowNumber("Payment Request SAP Items WorkFlow", workFlowNumber).GetDataTable(); DataTable sapDataTable1 = PaymentRequestSAPCommon.GetEmployeeExpenseClaimSAPItemsByWorkFlowNumber2("PaymentRequestItems", workFlowNumber).GetDataTable(); SapParameter mSapParameters = null; if (null == sapDataTable) { sapDataTable = new DataTable(); } if (null == sapItemDataTable) { sapItemDataTable = new DataTable(); } workFlowNumberAndSAPNO = ""; string employeeID = ""; string employeeName = ""; bool isFromPO = false; string systemPONo = ""; string paidThisTime = ""; string vendorNo = ""; string vendorName = ""; string pONo = ""; string vendorCity = ""; string vendorCountry = ""; string bankCity = ""; string swiftCode = ""; string bankAccount = ""; string taxPrice = ""; string bankName = ""; string paymentDesc = ""; string currency = ""; string exchRate = ""; if (sapDataTable != null && sapDataTable.Rows.Count > 0) { string name = sapDataTable.Rows[0]["Applicant"].ToString(); //systemPONo = sapDataTable.Rows[0]["SystemPONo"].ToString(); systemPONo = sapDataTable1.Rows[0]["SystemPONo"].AsString(); paidThisTime = sapDataTable.Rows[0]["PaidThisTime"].ToString(); vendorNo = sapDataTable.Rows[0]["VendorNo"].AsString(); pONo = sapDataTable.Rows[0]["PONo"].ToString(); vendorName = sapDataTable.Rows[0]["VendorName"].ToString(); isFromPO = sapDataTable.Rows[0]["FromPOStatus"].ToString() == "1" ? true : false; Employee employee = UserProfileUtil.GetEmployee(name.Substring(name.IndexOf('(') + 1, name.IndexOf(')') - name.IndexOf('(') - 1)); employeeID = employee.EmployeeID; employeeName = employee.DisplayName; vendorCity = sapDataTable.Rows[0]["VendorCity"].AsString(); vendorCountry = sapDataTable.Rows[0]["VendorCountry"].AsString(); bankCity = sapDataTable.Rows[0]["BankCity"].AsString(); swiftCode = sapDataTable.Rows[0]["SwiftCode"].AsString(); bankAccount = sapDataTable.Rows[0]["BankAccount"].AsString(); taxPrice = sapDataTable.Rows[0]["TaxPrice"].AsString(); bankName = sapDataTable.Rows[0]["BankName"].AsString(); paymentDesc = sapDataTable.Rows[0]["PaymentDesc"].AsString(); currency = sapDataTable.Rows[0]["Currency"].AsString(); exchRate = sapDataTable.Rows[0]["ExchRate"].AsString(); exchRate = exchRate == "" ? "1" : exchRate; } bool isSystemGR = false; System.Text.StringBuilder strLog = new System.Text.StringBuilder(); if (isFromPO && systemPONo != "") { DataTable dt = PaymentRequestSAPCommon.GetEmployeeExpenseClaimSAPItemsByPONumber("Purchase Order Workflow", pONo).GetDataTable(); if (dt != null && dt.Rows.Count > 0) { string systemGR = dt.Rows[0]["IsSystemGR"].ToString(); string sapNO = dt.Rows[0]["SapNO"].AsString(); if (systemGR == "1") { isSystemGR = true; workFlowNumberAndSAPNO += workFlowNumber + ";" + sapNO; } } //CommonUtil.logError(string.Format("dt.Rows[0][IsSystemGR].ToString(): {0} \n. dt.Rows.Count: {1}\n", dt.Rows[0]["IsSystemGR"].ToString(), dt.Rows.Count)); if (!isSystemGR) { mSapParameters = new SapParameter() { DocDate = DateTime.Now.ToString("yyyyMMdd"), RefDocNo = workFlowNumber, //PO单 POST到SAP时生成的SAP号 Header = workFlowNumber //工作流ID,只要是唯一值就行 }; List<StoresReceiveItem> paymentRequest = new List<StoresReceiveItem>(); DataTable sapItemDataTable1 = PaymentRequestSAPCommon.GetEmployeeExpenseClaimSAPItemsByWorkFlowNumber1("PurchaseOrderItems", pONo) .GetDataTable() .AsEnumerable() .Where(dr => dr.Field<string>("ItemCode").AsString().ToLower().IndexOf("x") != 0) .CopyToDataTable(); foreach (DataRow dr in sapItemDataTable1.Rows) { //decimal returnQuantityForSAP = 0; ////(decimal.Parse(dr["TotalQuantity"].ToString()) * Int32.Parse(paidThisTime)) / 100 //if (dr["ReturnQuantityForSAP"] == null) //{ // returnQuantityForSAP = 0; //} //else //{ // returnQuantityForSAP = decimal.Parse(dr["ReturnQuantityForSAP"].ToString() == "" ? "0" : dr["ReturnQuantityForSAP"].ToString()); //} //if (returnQuantityForSAP < 0) //{ // returnQuantityForSAP = 0 - returnQuantityForSAP; //} //decimal quantity = ((decimal.Parse(dr["TotalQuantity"].ToString()) - returnQuantityForSAP) * decimal.Parse(paidThisTime)) / 100; decimal quantity = (decimal.Parse(dr["TotalQuantity"].ToString()) * decimal.Parse(paidThisTime)) / 100; decimal totalQuantity = Math.Round(quantity, 3); paymentRequest.Add(new StoresReceiveItem() { Quantity = totalQuantity, SapNumber = dr["SapNO"].ToString(), ItemNo = Int32.Parse(dr["ItemNO"].ToString()), ItemText = paymentDesc }); strLog.AppendFormat("\r\nworkFlowNumber:{0} \r\n ", workFlowNumber); strLog.AppendFormat("TotalQuantity:{0} \r\n ", dr["TotalQuantity"].ToString()); strLog.AppendFormat("ReturnQuantityForSAP:{0} \r\n ", dr["ReturnQuantityForSAP"].ToString()); strLog.AppendFormat("totalQuantity:{0} \r\n ", totalQuantity.ToString()); strLog.AppendFormat("SapNO:{0} \r\n ", dr["SapNO"].ToString()); strLog.AppendFormat("ItemNO:{0} \r\n ", dr["ItemNO"].ToString()); strLog.AppendFormat("paidThisTime:{0} \r\n ", paidThisTime); } List<ExpenceDetail> expenceDetailsList1 = new List<ExpenceDetail>(); mSapParameters.ExpenceDetails = expenceDetailsList1; mSapParameters.StoresReceiveItems = paymentRequest; WriteErrorLog(strLog); return mSapParameters; } } if (!isFromPO) { decimal exchrate = 0; if (currency == "RMB") { exchrate = 1; } mSapParameters = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "KR", BusArea = "0001", Currency = currency, EmployeeID = vendorNo == "" ? "0099999999" : vendorNo, EmployeeName = vendorName, ExchRate = exchrate, Header = paymentDesc, RefDocNo = workFlowNumber, UserName = "******", Vendor = vendorNo }; if (vendorNo == "" || vendorNo == "99999999") { mSapParameters.VendorInfo = new Vendor() { BankAcct = bankAccount, //"234567893456789345678", BankCity = bankCity, //"CN", BankNo = swiftCode, //"104290003033", City = vendorCity, //"上海", Country = vendorCountry, // "CN", Name = vendorName //"上海文思创新科技有限公司-上海文思创新科技有限公司" }; } System.Text.StringBuilder detailsList = new System.Text.StringBuilder(); List<ExpenceDetail> expenceDetailsList = new List<ExpenceDetail>(); if (sapItemDataTable != null && sapItemDataTable.Rows.Count > 0) { foreach (DataRow dr in sapItemDataTable.Rows) { if (dr["ExpenseType"].ToString().IndexOf("OP-Non-trade vendor") == -1 && dr["ExpenseType"].ToString().IndexOf("GRIR vendor code") == -1) { ExpenceDetail expenceDetail = new ExpenceDetail(); expenceDetail.AccountGL = dr["GLAccount"].ToString(); expenceDetail.Amount = decimal.Parse(dr["ItemAmount"].ToString()) < 0 ? 0 - decimal.Parse(dr["ItemAmount"].ToString()) : decimal.Parse(dr["ItemAmount"].ToString()); //if (dr["ExpenseType"].ToString().IndexOf("Accrual") != -1 // || dr["ExpenseType"].ToString().IndexOf("Accrued") != -1 // || dr["ExpenseType"].ToString().IndexOf("Prepaid") != -1) //{ // expenceDetail.CostCenter = "0000000000"; // expenceDetail.BusArea = dr["BusinessArea"].AsString(); //} //else //{ // expenceDetail.CostCenter = dr["CostCenter"].AsString() == "" ? "0000000000" : dr["CostCenter"].AsString(); // expenceDetail.BusArea = ""; //} if (dr["ExpenseType"].ToString().ToLower() == ("Tax payable - VAT input").ToLower()) { expenceDetail.CostCenter = "0000000000"; } else { if (dr["ExpenseType"].ToString().IndexOf("Accrual") != -1 || dr["ExpenseType"].ToString().IndexOf("Accrued") != -1 || dr["ExpenseType"].ToString().IndexOf("Prepaid") != -1) { expenceDetail.CostCenter = ""; } else { expenceDetail.CostCenter = dr["CostCenter"].AsString(); } } if (dr["BusinessArea"].AsString() != "") { expenceDetail.BusArea = dr["BusinessArea"].AsString(); } //expenceDetail.ItemText = employeeName + " " + dr["ExpenseType"].ToString(); expenceDetail.ItemText = paymentDesc; expenceDetailsList.Add(expenceDetail); detailsList.AppendFormat("\r\nAccountGL:{0} \r\n ", dr["GLAccount"].AsString()); detailsList.AppendFormat("\r\nAmount:{0} \r\n ", dr["ItemAmount"].AsString()); detailsList.AppendFormat("\r\nExpenseType:{0} \r\n ", OriginalExpenseType[dr["ExpenseType"].AsString()].AsString()); detailsList.AppendFormat("\r\nCostCenter:{0} \r\n ", expenceDetail.CostCenter); detailsList.AppendFormat("\r\nBusinessArea:{0} \r\n ", dr["BusinessArea"].AsString()); } } } List<StoresReceiveItem> paymentRequest1 = new List<StoresReceiveItem>(); mSapParameters.StoresReceiveItems = paymentRequest1; mSapParameters.ExpenceDetails = expenceDetailsList; strLog.AppendFormat("\r\nvendorNo:{0} \r\n ", vendorNo); strLog.AppendFormat("vendorName:{0} \r\n ", vendorName); strLog.AppendFormat("workFlowNumber:{0} \r\n ", workFlowNumber); strLog.AppendFormat("BankAcct:{0} \r\n ", bankAccount); strLog.AppendFormat("BankCity:{0} \r\n ", bankCity); strLog.AppendFormat("BankNo:{0} \r\n ", swiftCode); strLog.AppendFormat("City:{0} \r\n ", vendorCity); strLog.AppendFormat("Country:{0} \r\n ", vendorCountry); strLog.AppendFormat("Name:{0} \r\n ", vendorName); strLog.Append("\r\n============= Currency、Exchange Rate Info =============\r\n"); strLog.AppendFormat("Currency:{0} \r\n ", currency); strLog.AppendFormat("Exchange Rate:{0} \r\n ", exchrate); strLog.Append("\r\n============= Currency、Exchange Rate Info =============\r\n"); strLog.Append("\r\n============= Expence Details List =============\r\n"); strLog.Append(detailsList.ToString()); strLog.Append("\r\n============= Expence Details List =============\r\n"); WriteErrorLog(strLog); return mSapParameters; } WriteErrorLog("null", "null"); return mSapParameters; }
public void btnCashAdvanceRelateToSAP_Click(object sender, EventArgs e) { foreach (RepeaterItem item in this.rpSAPData.Items) { CheckBox chkitem = (CheckBox)item.FindControl("ckAllItems"); if (chkitem.Checked) { HiddenField hfwfID = (HiddenField)item.FindControl("hfwfID"); HiddenField hfEmployeeID = (HiddenField)item.FindControl("hfEmployeeID"); HiddenField hfEmployeeName = (HiddenField)item.FindControl("hfEmployeeName"); HiddenField hfCAWorkflowNumber = (HiddenField)item.FindControl("hfCAWorkflowNumber"); HiddenField hfAmount = (HiddenField)item.FindControl("hfAmount"); //借款类型 cash transfer HiddenField hfAdvanceType = (HiddenField)item.FindControl("hfAdvanceType"); //借款用途或备注,格式用分号隔开,分别为:“借款用途+;+紧急借款备注+;+备注” HiddenField hfAdvanceRemark = (HiddenField)item.FindControl("hfAdvanceRemark"); //List<string> arList = hfAdvanceRemark.Value.Split(';').ToList<string>(); //Post SAP List<SapParameter> mSapParametersCD = new List<SapParameter>(); SapParameter mSapParameters = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "KR", BusArea = "0001", Currency = "RMB", EmployeeID = hfEmployeeID.Value, EmployeeName = hfEmployeeName.Value, ExchRate = 1, Header = hfAdvanceRemark.Value, RefDocNo = hfCAWorkflowNumber.Value, UserName = "******", CashAmount = decimal.Parse(hfAmount.Value), PaidByCC = 100, PymtMeth = hfAdvanceType.Value == "Cash" ? "E" : "" }; mSapParametersCD.Add(mSapParameters); string sAPNumber = ""; string errorMsg = ""; bool postResult = false; ISapExchange sapExchange = SapExchangeFactory.GetCashAdvance(); List<object[]> result = sapExchange.ImportDataToSap(mSapParametersCD); //if (null == result) //{ // errorMsg += hfEmployeeName + "-" + DateTime.Now.ToShortDateString() + ":" + "Connection failed."; //} if (null == result) { this.Page.ClientScript.RegisterStartupScript(typeof(DataEdit), "alert", "<script type=\"text/javascript\">alert('Connection failed !'); window.location = window.location;</script>"); return; } else { for (int i = 0; i < result.Count; i++) { SapParameter sp = (SapParameter)result[i][0]; bool bl = (bool)result[i][2]; if (bl) { SapResult sr = (SapResult)result[i][1]; sAPNumber = sr.OBJ_KEY; postResult = true; } else { if (result[i][1] is string) { errorMsg += hfEmployeeName + "-" + DateTime.Now.ToShortDateString() + ":" + result[i][1].ToString() + " \n "; } else { string wfID = sp.RefDocNo; SapResult sr = (SapResult)result[i][1]; foreach (SAP.Middleware.Table.RETURN ret in sr.RETURN_LIST) { errorMsg += hfEmployeeName + "-" + DateTime.Now.ToShortDateString() + ":" + ret.MESSAGE + " \n "; } } } } } var delegationList = CA.SharePoint.SharePointUtil.GetList("CashAdvanceRequest"); SPQuery query = new SPQuery(); query.Query = string.Format("<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>{0}</Value></Eq></Where>", hfCAWorkflowNumber.Value); SPListItemCollection eecListItem = delegationList.GetItems(query); SPListItem eecli = eecListItem[0]; var delegationSAPList = CA.SharePoint.SharePointUtil.GetList("CashAdvanceRequestSAP"); SPQuery sapquery = new SPQuery(); sapquery.Query = string.Format("<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>{0}</Value></Eq></Where>", hfwfID.Value); SPListItemCollection eecsapListItem = delegationSAPList.GetItems(sapquery); SPListItem eecsapli = eecsapListItem[0]; string emsg = eecli["ErrorMsg"].AsString(); emsg += errorMsg; if (postResult) { eecli["SAPNumber"] = sAPNumber; eecsapli["SAPNumber"] = sAPNumber; eecsapli["SAPStatus"] = "1"; } else { eecli["ErrorMsg"] = emsg; eecsapli["ErrorMsg"] = emsg; } if (eecsapli["PostCount"] == null) { eecsapli["PostCount"] = "1"; } else { eecsapli["PostCount"] = (Int32.Parse(eecsapli["PostCount"].ToString()) + 1).ToString(); } eecli.Web.AllowUnsafeUpdates = true; eecli.Update(); eecsapli.Web.AllowUnsafeUpdates = true; eecsapli.Update(); } } this.Page.ClientScript.RegisterStartupScript(typeof(DataEdit), "alert", "<script type=\"text/javascript\">window.location = window.location;</script>"); }
private static SapParameter InitializeSapParameter(string type, DataTable dataTable) { string bankInfo = ExcelService.GetExcelConfigInfo("CC_BankInfo"); string bankId = bankInfo.Split(new string[] { ";#" }, StringSplitOptions.None)[0]; string bankName = bankInfo.Split(new string[] { ";#" }, StringSplitOptions.None)[1]; SapParameter mSapParameters = new SapParameter() { BusAct = "RFBU", BusArea = "0001", //ExchRate = 1, BankId = bankId, DocType = "KR", BankName = bankName, Header = "Credit Card" //工作流名字 }; Hashtable parametersHash = new Hashtable(); //parametersHash.Add("RefDocNo", refDocNo); switch (type) { case "RMB": parametersHash.Add("Currency", "RMB"); parametersHash.Add("ExchRate", "1"); DataTable rmbDataTable = CreditCardClaimCommon.GetDataSource(dataTable, "Currency='RMB'"); if (rmbDataTable.Rows.Count > 0) { parametersHash.Add("RefDocNo", CreditCardClaimCommon.GetDataSource(dataTable, "Currency='RMB'").Rows[0]["SAPID"].AsString()); } else { parametersHash.Add("RefDocNo", string.Empty); } SetSapParameter(mSapParameters, parametersHash); DataTable rmbDT = ConvertToSAPDataSource(dataTable, type); mSapParameters.ExpenceDetails = GetSapParametersList(rmbDT); break; case "USD": parametersHash.Add("Currency", "USD"); parametersHash.Add("ExchRate", "0"); DataTable usdDataTable = CreditCardClaimCommon.GetDataSource(dataTable, "Currency<>'RMB'"); if (usdDataTable.Rows.Count > 0) { parametersHash.Add("RefDocNo", CreditCardClaimCommon.GetDataSource(dataTable, "Currency<>'RMB'").Rows[0]["SAPID"].AsString()); } else { parametersHash.Add("RefDocNo", string.Empty); } SetSapParameter(mSapParameters, parametersHash); DataTable usdDT = ConvertToSAPDataSource(dataTable, type); mSapParameters.ExpenceDetails = GetSapParametersList(usdDT); break; default: break; } return mSapParameters; }
/// <summary> /// 己经做过系统收货的不需要POST到SAP中 /// </summary> /// <param name="dtCompletePO">没有post到SAP,且没有做GR/SR的,己经完成了PO流程的PO数据, </param> /// <param name="dtPoList">没有post到SAP,且没有做GR/SR的Item数据</param> static void PostPOReturnDataToSap(DataTable dtCompletePO, DataTable dtPoList) { if (null == dtCompletePO || null == dtPoList) { return; } List<SapParameter> mSapParametersPOR = new List<SapParameter>(); List<ReturnPO> listReturnPO = new List<ReturnPO>(); foreach (DataRow dr in dtCompletePO.Rows)//每一条PO ,退货的PO { string sPONO = dr["Title"].ToString(); if (!sPONO.EndsWith("R"))//非退货的PO { continue; } string sSAPNO = string.Empty;//目标退货的PO的SAP号 string sTargetPO = string.Empty;//退货的目标PO号。 bool isReturnPOPostSAP = IsReturnPOPostSAP(sPONO, out sSAPNO, out sTargetPO); if (!isReturnPOPostSAP)///退货的目标PO,没有Post到SAP中 { continue; } bool isComplete = IsSysGRSR(sTargetPO);//PO 是否有己做系统收货。 if (isComplete) { continue; } // PO下的所有的Item string sCondition = string.Concat("Title='", sPONO, "'"); DataRow[] arrDR = dtPoList.Select(sCondition); List<PurchaseOrderItem> listPOI = GetReturnPOItemsPar(arrDR, sTargetPO, sPONO);//, isCapx); if (null == listPOI || listPOI.Count == 0) { Common.WriteErrorLog(string.Format("There are no avaliable Items in {0} to Post return po to SAP", sPONO)); continue; } SapParameter mSapParReturnPO = new SapParameter() { DocType = "SA", SapNumber = sSAPNO, RefDocNo = sPONO }; mSapParReturnPO.PurchaseOrderItems = listPOI; mSapParametersPOR.Add(mSapParReturnPO); ReturnPO structRetunPO = new ReturnPO(); structRetunPO.sPONO = sPONO; structRetunPO.sTargetPO = sTargetPO; listReturnPO.Add(structRetunPO); StringBuilder sbResult = new StringBuilder(); sbResult.Append(sPONO); sbResult.Append(" 执行Post退货参数:\n"); sbResult.Append(".DocType:" + mSapParReturnPO.DocType); sbResult.Append("\n .Pmnttrms:" + mSapParReturnPO.SapNumber); sbResult.Append("\n .PurGroup:" + mSapParReturnPO.RefDocNo); Common.WriteErrorLog(sbResult.ToString()); } try { ISapExchange iseReturn = SapExchangeFactory.GetPurchaseOrderReturn(); List<object[]> resultReturnPO = iseReturn.ImportDataToSap(mSapParametersPOR); Common.ProcessResult(resultReturnPO, "SapNO", "SapErrorInfo", false);///GRSRSaPErrorInfo UpdateReturnPOinfo(listReturnPO); } catch (Exception e) { Common.WriteErrorLog("执行PO退货PO post到SAP接口时出错:" + e.ToString()); } }
/// <summary> /// 将PO的数据Post到SAP中。 /// </summary> static void PostPODataToSap(DataTable dtCompletePO, DataTable dtPoList) { if (null == dtCompletePO || null == dtPoList) { return; } List<SapParameter> mSapParametersPO = new List<SapParameter>(); foreach (DataRow dr in dtCompletePO.Rows)//每一条PO,非退货。 { string sPONO = dr["Title"].ToString(); if (sPONO.EndsWith("R"))//,退货。 { continue; } //得到EmployeeID string sEmployeeID = string.Empty; string sEmployeeName = string.Empty; try { string[] arrayEmployee = Common.GetEmployeeID(dr["EmployeeName"].ToString()); sEmployeeID = arrayEmployee[0]; sEmployeeName = arrayEmployee[1]; } catch (Exception e) { Common.WriteErrorLog("CA.Workflow.PostPOToSap.cs at Line:129 :" + e.ToString()); continue; } //是否是Capex bool isCapx = Convert.ToBoolean(dr["isCapx"].ToString());// IsCapex(sPONO); //PO下的所有的Item string sCondition = string.Concat("Title='", sPONO, "'"); DataRow[] arrDR = dtPoList.Select(sCondition, "ItemNO desc");//.OrderBy("ItemNO"); bool isAllocateAvalible =true; isAllocateAvalible = CheckAllocateValue(arrDR, sPONO);//AllocateAvalible是否和总净价相等。 if (!isAllocateAvalible) { Common.UpdateErrorInfo(sPONO, "Error AllocateValue", "SapErrorInfo", "Purchase Order Workflow"); Common.WriteErrorLog(string.Format("Error AllocateValue for PO:{0}",sPONO)); continue; } List<PurchaseOrderItem> listPOI = GetPOParlist(arrDR, isCapx, sPONO); if (null == listPOI) { Common.WriteErrorLog(string.Format("There are no items in PO:{0}", sPONO)); continue; } SapParameter POItemsArr = new SapParameter(); POItemsArr.DocType = "SA"; POItemsArr.Pmnttrms = "Z002"; POItemsArr.PurGroup = isCapx ? "AST" : "NT1"; //如果是固定资产,PurGroup的值为AST;否则为 NT1 POItemsArr.DocDate = DateTime.Now.ToString("yyyyMMdd"); POItemsArr.Vendor = StrFormate(dr["VendorID"].ToString(),10);//临时0000008008 if (sEmployeeID != null) { POItemsArr.EmployeeID = sEmployeeID;//dr[AuthorID] sEmployeeID.ToString(), POItemsArr.EmployeeName = sEmployeeName;// dr["EmployeeName"].ToString(), } POItemsArr.PaymentCond = dr["CondValue"].ToString();//PO单付款条件 POItemsArr.RefDocNo = sPONO;// "PO" POItemsArr.PurchaseOrderItems = listPOI; POItemsArr.Currency = dr["Currency"]==null?"":dr["Currency"].ToString(); mSapParametersPO.Add(POItemsArr); StringBuilder sbResult = new StringBuilder(); sbResult.Append(sPONO); sbResult.Append(" PO Post到SAP参数:\n"); sbResult.Append(".DocType:" + POItemsArr.DocType); sbResult.Append("\n .Pmnttrms:" + POItemsArr.Pmnttrms); sbResult.Append("\n .PurGroup:" + POItemsArr.PurGroup); sbResult.Append("\n .DocDate:" + POItemsArr.DocDate); sbResult.Append("\n .Vendor:" + POItemsArr.Vendor); sbResult.Append("\n .EmployeeID:" + POItemsArr.EmployeeID); sbResult.Append("\n .EmployeeName:" + POItemsArr.EmployeeName); sbResult.Append("\n .PaymentCond:" + POItemsArr.PaymentCond); sbResult.Append("\n .RefDocNo:" + POItemsArr.RefDocNo); sbResult.Append("\n .Currency:" + POItemsArr.Currency); Common.WriteErrorLog(sbResult.ToString()); } try { ISapExchange sapPOExchange = SapExchangeFactory.GetPurchaseOrder(); List<object[]> resultPO = sapPOExchange.ImportDataToSap(mSapParametersPO);//开始导入并返回post结果 。 Common.ProcessResult(resultPO, "SapNO", "SapErrorInfo", false);//导入成功后,更新到PO的SAPNO,失败的话记录错误信息。 } catch (Exception e) { Common.WriteErrorLog("执行PO post到SAP接口时出错:" + e.ToString()); } }
private SapParameter GetUSDSapParameterByWorkFlowNumber(string workFlowNumber) { SapParameter sapUSDParameters = null; DataTable sapDataTable = CreditCardClaimCommon.GetEmployeeExpenseClaimSAPItemsByWorkFlowNumber("Credit Card Claim SAP Workflow", workFlowNumber).GetDataTable(); DataTable sapItemDataTable = CreditCardClaimCommon.GetEmployeeExpenseClaimSAPItemsByWorkFlowNumber("Credit Card Claim SAP Detail", workFlowNumber, "RMB").GetDataTable(); DataTable sapUSDItemDataTable = CreditCardClaimCommon.GetEmployeeExpenseClaimSAPItemsByWorkFlowNumber("Credit Card Claim SAP Detail", workFlowNumber, "USD").GetDataTable(); if (null == sapDataTable) { sapDataTable = new DataTable(); } if (null == sapItemDataTable) { sapItemDataTable = new DataTable(); } if (null == sapUSDItemDataTable) { sapUSDItemDataTable = new DataTable(); } string employeeID = ""; string employeeName = ""; string expenseDescription = ""; if (sapDataTable != null && sapDataTable.Rows.Count > 0) { expenseDescription = sapDataTable.Rows[0]["ExpenseDescription"].ToString(); string name = sapDataTable.Rows[0]["Applicant"].ToString(); Employee employee = UserProfileUtil.GetEmployee(name.Substring(name.IndexOf('(') + 1, name.IndexOf(')') - name.IndexOf('(') - 1)); employeeID = employee.EmployeeID; employeeName = employee.DisplayName; if (sapUSDItemDataTable != null && sapUSDItemDataTable.Rows.Count > 0) { if (sapUSDItemDataTable.Rows[0]["Status"].ToString() == "success") { return null; } } } if (sapUSDItemDataTable != null && sapUSDItemDataTable.Rows.Count > 0 && sapItemDataTable != null && sapItemDataTable.Rows.Count > 0) { workFlowNumber = workFlowNumber + "_2"; } //USD sapParameters if (sapUSDItemDataTable != null && sapUSDItemDataTable.Rows.Count > 0) { sapUSDParameters = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "KR", BusArea = "0001", Currency = "USD", EmployeeID = employeeID, EmployeeName = employeeName, ExchRate = 0, Header = expenseDescription, RefDocNo = workFlowNumber, UserName = "******" }; List<ExpenceDetail> expenceUSDDetailsList = new List<ExpenceDetail>(); foreach (DataRow dr in sapUSDItemDataTable.Rows) { if (dr["ExpenseType"].ToString().IndexOf("OR - employee vendor") == -1) { ExpenceDetail expenceDetail = new ExpenceDetail(); expenceDetail.AccountGL = dr["GLAccount"].ToString(); expenceDetail.Amount = decimal.Parse(dr["DealAmount"].ToString()); expenceDetail.CostCenter = dr["CostCenter"].ToString(); expenceDetail.ItemText = employeeName + " " + dr["ExpenseType"].ToString(); expenceDetail.RefKey = dr["CreditCardBillID"].AsString(); expenceDetail.Currency = "USD"; expenceDetail.ExchRate = 0; expenceUSDDetailsList.Add(expenceDetail); } } sapUSDParameters.ExpenceDetails = expenceUSDDetailsList; } return sapUSDParameters; }
protected void Button1_Click(object sender, EventArgs e) { List<SapParameter> mSapParametersCD = new List<SapParameter>(); //Cash Advance 数据 SapParameter mSapParameters3 = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "SA", BusArea = "0001", Currency = "RMB", EmployeeID = "6000000150", // EmployeeName = "TEST", // ExchRate = 1, Header = "Cash Advance", RefDocNo = "CA" + DateTime.Now.ToString("yyyyMMddHHmmss"),// UserName = "******", CashAmount = 200, // PaidByCC = 100 }; mSapParametersCD.Add(mSapParameters3); ISapExchange sapExchange = SapExchangeFactory.GetCashAdvance(); List<object[]> result = sapExchange.ImportDataToSap(mSapParametersCD); for (int i = 0; i < result.Count; i++) { SapParameter sp = (SapParameter)result[i][0]; bool bl = (bool)result[i][2]; if (bl) { SapResult sr = (SapResult)result[i][1]; Response.Write("Sap ID : " + sr.OBJ_KEY); } else { Response.Write(result[i][1].ToString()); } } }
private static DataTable GetClaimState(SPList list) { DataTable sourceDT = GetSAPItemsDT(list); List<SapParameter> mSapParametersCQ = new List<SapParameter>(); if (sourceDT != null && sourceDT.Rows.Count > 0) { foreach (DataRow dr in sourceDT.Rows) { string applicantSPuser = dr["ApplicantSPuser"].AsString(); string vendorIdStr = string.Empty; decimal vendorId = 0; if (applicantSPuser.IsNotNullOrWhitespace()) { //Console.WriteLine(dr["ApplicantSPuser"].AsString()); //int userId = int.Parse(dr["ApplicantSPuser"].AsString().Split(new string[] { ";#" }, StringSplitOptions.None)[0]); //SPUser user = list.ParentWeb.AllUsers.GetByID(userId); vendorIdStr = Services.UserProfileService.GetEmployeeId(dr["ApplicantSPuser"].AsString(), list.ParentWeb); } if (decimal.TryParse(vendorIdStr, out vendorId)) { #region init data SapParameter mSapParameters = new SapParameter() { RefDocNo = dr["Title"].AsString(), Vendor = string.Format("{0:0000000000}", vendorId) }; mSapParametersCQ.Add(mSapParameters); #endregion } } ISapExchange sapClaim = SapExchangeFactory.GetClaimQuer(); List<object[]> claimResult = sapClaim.ExportDataToCa(mSapParametersCQ); #region update result for (int i = 0; i < claimResult.Count; i++) { SapParameter sapPara = (SapParameter)claimResult[i][0]; foreach (DataRow dr in sourceDT.Rows) { if (dr["Title"].AsString().Equals(sapPara.RefDocNo.ToString(), StringComparison.CurrentCultureIgnoreCase)) { if ((bool)claimResult[i][2]) { SapResult sr = (SapResult)claimResult[i][1]; Claim claimStatus = ((SapResult)claimResult[i][1]).ClaimStatus; Console.WriteLine("WFNo:{0},Result:{1}", dr["Title"].AsString(), claimStatus.ZFLAG.ToString()); SystemEntry.LogInfoToLogFile(string.Format("WFNo:{0},Result:{1}", dr["Title"].AsString(), claimStatus.ZFLAG.ToString()), string.Empty, "GetClaimState"); if (claimStatus.ZFLAG.Equals("X", StringComparison.CurrentCultureIgnoreCase)) { dr["IsPaid"] = "1"; } } else { Console.WriteLine("WFNo:{0},Result:{1}", dr["Title"].AsString(), bool.FalseString); if (claimResult[i][1] is string) { Console.WriteLine("WFNo:{0},Result:{1}", dr["Title"].AsString(), claimResult[i][1].ToString()); dr["ErrorMsg"] += claimResult[i][1].ToString(); } else { SapResult sr = (SapResult)claimResult[i][1]; Console.WriteLine("WFNo:{0},Result:{1}", dr["Title"].AsString(), sr.ClaimStatus); } } break; } } } #endregion } return sourceDT; }
/// <summary> /// 导入数据到SAP /// </summary> /// <param name="sapParameters">SAP参数对象</param> /// <returns>数据插入到SAP是否成功</returns> private void OperationForSap(SapParameter sapParameter) { if (sapParameter == null){ mErrorSapParameters.Enqueue(new object[] { mCurrentSapParameter, "Current object is null", false }); return; } object[] obj = InitializeEnvironment(); mCurrentSapParameter = sapParameter; if ((bool)obj[0] == false) { mErrorSapParameters.Enqueue(new object[] { mCurrentSapParameter, (string)obj[1], false }); return; } OperationForSap(); }
private List<SapParameter> InitializeSapParameter(DataTable originalDetailsDT, DataTable expenseTypeDT, Hashtable parametersHash) { List<SapParameter> mSapParametersTR = new List<SapParameter>(); SapParameter mSapParameters = new SapParameter() { BusAct = "RFBU", CompCode = "CA10", DocType = "KR", BusArea = "0001", Currency = "RMB", //EmployeeID = "6000000150", // // EmployeeName = "TEST", // ExchRate = 1, //Header = "Travel Expense Claim", //RefDocNo = "CA" + DateTime.Now.ToString("yyyyMMddHHmmss"),// UserName = "******" }; foreach (DictionaryEntry entry in parametersHash) { foreach (PropertyInfo prop in mSapParameters.GetType().GetProperties()) { if (entry.Key.AsString() == prop.Name) { switch (prop.PropertyType.ToString()) { case "System.Decimal": prop.SetValue(mSapParameters, decimal.Parse(entry.Value.AsString()), null); break; default: prop.SetValue(mSapParameters, entry.Value.AsString(), null); break; } break; } } } mSapParameters.GroupExpenceDetails = GetSapParametersList(expenseTypeDT); mSapParameters.ExpenceDetails = GetSapParametersList(originalDetailsDT); mSapParametersTR.Add(mSapParameters); return mSapParametersTR; }