public static string GetProxCodeAvarias(SAPbobsCOM.Company oCompany) { SAPbobsCOM.Recordset RecSet = null; string QryStr = null; string proxCod = ""; RecSet = ((SAPbobsCOM.Recordset)(oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset))); QryStr = "DECLARE @Numero AS INT SELECT @Numero = (select top 1 cast (Code as INT) + 1 from [SBO_SEA_Design_Prod].[dbo].[@FLX_FB_AVR] order by Code desc) if @Numero is null begin set @Numero = 0000000 + 1 end SELECT case len(CAST(@Numero AS varchar(7))) WHEN 1 THEN '000000' + CAST(@Numero AS varchar(7)) WHEN 2 THEN '00000' + CAST(@Numero AS varchar(7)) WHEN 3 THEN '0000' + CAST(@Numero AS varchar(7)) WHEN 4 THEN '000' + CAST(@Numero AS varchar(7)) WHEN 5 THEN '00' + CAST(@Numero AS varchar(7)) WHEN 6 THEN '0' + CAST(@Numero AS varchar(7)) WHEN 7 THEN CAST(@Numero AS varchar(7)) END"; RecSet.DoQuery(QryStr); proxCod = Convert.ToString(RecSet.Fields.Item(0).Value); return proxCod; }
/// <summary> /// Preenche um ComboBox com os dados de uma query. /// </summary> /// <param name="comboBox"></param> /// <param name="company">O Company a ser utilizado para obter dos dados.</param> /// <param name="query">A query a ser utilizada para obter os dados.</param> /// <param name="fieldValue">O nome do Field que contém o valor para ComboBox.</param> /// <param name="fieldDescription">O nome do Field que contém a descrição para o ComboBox.</param> /// <param name="noLock">Indica se a query deve ser executada na forma de apenas leiura, isto é, se houver alguma escrita no momento não vai esperar a conclusão desta para continuar.</param> public static Recordset AddValuesFromQuery(this ComboBox comboBox, SAPbobsCOM.Company company, string query, string fieldValue = null, string fieldDescription = null, bool noLock = true) { if (company == null) throw new ArgumentNullException("company"); var recordset = (Recordset)company.GetBusinessObject(BoObjectTypes.BoRecordset); return AddValuesFromQuery(comboBox, recordset, query, fieldValue, fieldDescription, noLock); }
public string Add_SalesQuotation(DataTable oDTSQData, SAPbobsCOM.Company oDICompany, string sCardCode, string sErrDesc) { string sReturnResult = string.Empty; string sFuncName = string.Empty; SAPbobsCOM.Documents oSalesQuotation; int lRetCode; try { sFuncName = "Add_SalesQuotation()"; if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName); oSalesQuotation = oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oQuotations); oSalesQuotation.CardCode = sCardCode; oSalesQuotation.DocDate = DateTime.Now.Date; oSalesQuotation.TaxDate = DateTime.Now.Date; oSalesQuotation.DocDueDate = DateTime.Now.Date; double iCount = 0; int sumOfQty = 0; foreach (DataRow iRow in oDTSQData.Rows) { //if (iCount != 0) // oSalesQuotation.Lines.Add(); if (Convert.ToDouble(iRow["Qty"]) > 0) { //oSalesQuotation.Lines.SetCurrentLine(); oSalesQuotation.Lines.ItemCode = Convert.ToString(iRow["ItemCode"]); oSalesQuotation.Lines.Quantity = Convert.ToInt32(iRow["Qty"]); oSalesQuotation.Lines.Price = Convert.ToDouble(iRow["Price"]); oSalesQuotation.Lines.UserFields.Fields.Item("U_STEP_CREATION_DT").Value = DateTime.Now.Date; oSalesQuotation.Lines.UserFields.Fields.Item("U_STATUS").Value = "PENDING"; oSalesQuotation.Lines.UserFields.Fields.Item("U_NEXT_ACTION_BY").Value = Convert.ToString(iRow["ACTIONBY"]); oSalesQuotation.Lines.UserFields.Fields.Item("U_INT_CASE_SEQ").Value = Convert.ToString(iRow["INTNO"]); oSalesQuotation.Lines.Add(); //oSalesQuotation.Lines.VatGroup = "SR"; iCount = iCount + 1; sumOfQty = sumOfQty + Convert.ToInt32(iRow["Qty"]); } } if (sumOfQty > 0) { lRetCode = oSalesQuotation.Add(); if (lRetCode != 0) { sErrDesc = oDICompany.GetLastErrorDescription(); sReturnResult = sErrDesc.ToString(); throw new ArgumentException(sErrDesc); } else { sReturnResult = "SUCCESS"; if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With SUCCESS ", sFuncName); } } else { sReturnResult = ""; } } catch (Exception Ex) { sErrDesc = Ex.Message.ToString(); oLog.WriteToErrorLogFile(sErrDesc, sFuncName); if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR ", sFuncName); throw Ex; } return sReturnResult; }
public static string getpodocnum(SAPbobsCOM.Company oCompany) { string itemcode = ""; SAPbobsCOM.Recordset ors = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); ors.DoQuery("Select DocNum From OPOR Where DocEntry=(Select MAX(DocEntry) From OPOR)"); itemcode = ors.Fields.Item(0).Value.ToString(); System.Runtime.InteropServices.Marshal.ReleaseComObject(ors); ors = null; GC.Collect(); return itemcode; }
public static string getProduct(SAPbobsCOM.Company oCompany, string Col6, string Col7) { string retvalue = ""; SAPbobsCOM.Recordset ors = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); string empname = Col7 + " " + Col6; ors.DoQuery("select[@BOS_CCDIM].U_Product From [@BOS_CCDIM] Where [@BOS_CCDIM].U_Employee ='" + empname + "'"); retvalue = ors.Fields.Item(0).Value.ToString(); System.Runtime.InteropServices.Marshal.ReleaseComObject(ors); ors = null; GC.Collect(); return retvalue; }
public static string getItemCode(SAPbobsCOM.Company oCompany, string Col63) { string itemcode = ""; SAPbobsCOM.Recordset ors = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); ors.DoQuery("Select Left([@BOS_CCACT].U_Account,8) From [@BOS_CCACT] Where [@BOS_CCACT].U_Category = '"+ Col63 + "'"); itemcode = ors.Fields.Item(0).Value.ToString(); System.Runtime.InteropServices.Marshal.ReleaseComObject(ors); ors = null; GC.Collect(); return itemcode; }
public static int getPOCount(SAPbobsCOM.Company oCompany,string ponumber) { int pocount = 0; SAPbobsCOM.Recordset ors = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); ors.DoQuery("Select Count(U_concurpo) from OPOR Where U_concurpo='"+ ponumber +"'"); pocount = Int32.Parse(ors.Fields.Item(0).Value.ToString()); System.Runtime.InteropServices.Marshal.ReleaseComObject(ors); ors = null; GC.Collect(); return pocount; }
public string AddDocuments(DataTable oDt, SAPbobsCOM.Company oCompany, string sDocType) { string sFuncName = "AddSales_Order"; string sItemCode; SAPbobsCOM.Documents oSalesOrder; SAPbobsCOM.Recordset oRecSet; string sSoDocEntry; string sSql; int iRetCode; double dPrice = 0; double dFee = 0; try { if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName); oSalesOrder = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders); double iCount = 0; foreach (DataRow iRow in oDt.Rows) { if (Convert.ToDouble(iRow["Qty"]) > 0) { oSalesOrder.CardCode = Convert.ToString(iRow["CaseNo"]); oSalesOrder.DocDate = DateTime.Now.Date; oSalesOrder.TaxDate = DateTime.Now.Date; oSalesOrder.DocDueDate = DateTime.Now.Date; oSalesOrder.NumAtCard = Convert.ToString(iRow["DocNum"]) + "/" + Convert.ToString(iRow["LineNum"]); if (iCount > 0) { oSalesOrder.Lines.Add(); } sSql = "select U_PROPERTY_PURPRC [Price] from [OCRD] WITH (NOLOCK) where CardCode = '" + Convert.ToString(iRow["CaseNo"]) + "'"; if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("OCRD Price - SQL Query" + sSql, sFuncName); oRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecSet.DoQuery(sSql); if (oRecSet.RecordCount > 0) { dPrice = Convert.ToDouble(oRecSet.Fields.Item("Price").Value); } sSql = "SELECT DBO.GETFEE('" + Convert.ToString(iRow["ItemCode"]) + "','" + Convert.ToString(iRow["CaseNo"]) + "', '" + dPrice + "','','','') [FeePrice]"; if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("GetFEE - SQL Query" + sSql, sFuncName); oRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecSet.DoQuery(sSql); if (oRecSet.RecordCount > 0) { dFee = Convert.ToDouble(oRecSet.Fields.Item("FeePrice").Value); } sItemCode = Convert.ToString(iRow["ItemCode"]); oSalesOrder.Lines.ItemCode = sItemCode; oSalesOrder.Lines.Quantity = Convert.ToDouble(iRow["Qty"]); //oSalesOrder.Lines.Price = Convert.ToDouble(iRow["Price"]); //oSalesOrder.Lines.UnitPrice = Convert.ToDouble(iRow["Price"]); oSalesOrder.Lines.Price = dFee; oSalesOrder.Lines.UnitPrice = dFee; sSql = "SELECT U_CASE_BRANCH,U_LOAN_MSTR_BANKCODE,ProjectCod FROM OCRD WITH (NOLOCK) WHERE CardCode = '" + Convert.ToString(iRow["CaseNo"]) + "'"; oRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecSet.DoQuery(sSql); if (oRecSet.RecordCount > 0) { oSalesOrder.Lines.COGSCostingCode = oRecSet.Fields.Item("U_CASE_BRANCH").Value; oSalesOrder.Lines.COGSCostingCode2 = oRecSet.Fields.Item("U_LOAN_MSTR_BANKCODE").Value; oSalesOrder.Lines.ProjectCode = oRecSet.Fields.Item("ProjectCod").Value; } iCount = iCount + 1; } } iRetCode = oSalesOrder.Add(); if (iRetCode != 0) { sErrDesc = oCompany.GetLastErrorDescription(); throw new ArgumentException(sErrDesc); } else { sSoDocEntry = oCompany.GetNewObjectKey(); } if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With SUCCESS ", sFuncName); } catch (Exception ex) { sErrDesc = ex.Message.ToString(); oLog.WriteToErrorLogFile(sErrDesc, sFuncName); if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR ", sFuncName); throw ex; } return sSoDocEntry; }
public string CreateSalesQuote(DataTable oDt, SAPbobsCOM.Company oCompany) { string sFuncName = "CreateSalesQuote"; SAPbobsCOM.Documents oSalesQuote; string sSql; int sumOfQty = 0; string sReturnResult = string.Empty; SAPbobsCOM.Recordset oRecSet; string sCaseNo = string.Empty; int sQuoteEntry = 0; try { if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName); oSalesQuote = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oQuotations); double iCount = 0; sCaseNo = Convert.ToString(oDt.Rows[0]["CaseNo"]); sSql = "SELECT DocEntry FROM OQUT WITH (NOLOCK) WHERE CardCode = '" + sCaseNo + "' AND DocStatus = 'O' AND CANCELED = 'N'"; oRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecSet.DoQuery(sSql); if (oRecSet.RecordCount > 0) { sQuoteEntry = oRecSet.Fields.Item("DocEntry").Value; } System.Runtime.InteropServices.Marshal.ReleaseComObject(oRecSet); if (oSalesQuote.GetByKey(sQuoteEntry)) { foreach (DataRow iRow in oDt.Rows) { if (Convert.ToDouble(iRow["Qty"]) > 0) { if (oSalesQuote.Lines.Count > 0) { oSalesQuote.Lines.Add(); } oSalesQuote.Lines.ItemCode = Convert.ToString(iRow["ItemCode"]); oSalesQuote.Lines.Quantity = Convert.ToDouble(iRow["Qty"]); oSalesQuote.Lines.Price = Convert.ToDouble(iRow["Price"]); oSalesQuote.Lines.UnitPrice = Convert.ToDouble(iRow["Price"]); oSalesQuote.Lines.UserFields.Fields.Item("U_STEP_CREATION_DT").Value = DateTime.Now.Date; oSalesQuote.Lines.UserFields.Fields.Item("U_INT_CASE_SEQ").Value = Convert.ToString(iRow["IntNo"]); oSalesQuote.Lines.UserFields.Fields.Item("U_NEXT_ACTION_BY").Value = Convert.ToString(iRow["ActionBy"]); sSql = "SELECT U_CASE_BRANCH,U_LOAN_MSTR_BANKCODE,ProjectCod FROM OCRD WITH (NOLOCK) WHERE CardCode = '" + sCaseNo + "'"; oRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecSet.DoQuery(sSql); if (oRecSet.RecordCount > 0) { oSalesQuote.Lines.COGSCostingCode = oRecSet.Fields.Item("U_CASE_BRANCH").Value; oSalesQuote.Lines.COGSCostingCode2 = oRecSet.Fields.Item("U_LOAN_MSTR_BANKCODE").Value; oSalesQuote.Lines.ProjectCode = oRecSet.Fields.Item("ProjectCod").Value; } sumOfQty = sumOfQty + Convert.ToInt32(iRow["Qty"]); } } if (sumOfQty > 0) { if (oSalesQuote.Update() != 0) { sErrDesc = oCompany.GetLastErrorDescription(); sReturnResult = sErrDesc.ToString(); throw new ArgumentException(sErrDesc); } else { sReturnResult = "SUCCESS"; if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With SUCCESS ", sFuncName); } } else { sReturnResult = ""; } } else { foreach (DataRow iRow in oDt.Rows) { if (Convert.ToDouble(iRow["Qty"]) > 0) { oSalesQuote.CardCode = Convert.ToString(iRow["CaseNo"]); oSalesQuote.DocDate = DateTime.Now.Date; oSalesQuote.TaxDate = DateTime.Now.Date; oSalesQuote.DocDueDate = DateTime.Now.Date; if (iCount > 0) { oSalesQuote.Lines.Add(); } oSalesQuote.Lines.ItemCode = Convert.ToString(iRow["ItemCode"]); oSalesQuote.Lines.Quantity = Convert.ToDouble(iRow["Qty"]); oSalesQuote.Lines.Price = Convert.ToDouble(iRow["Price"]); oSalesQuote.Lines.UnitPrice = Convert.ToDouble(iRow["Price"]); oSalesQuote.Lines.UserFields.Fields.Item("U_STEP_CREATION_DT").Value = DateTime.Now.Date; oSalesQuote.Lines.UserFields.Fields.Item("U_INT_CASE_SEQ").Value = Convert.ToString(iRow["IntNo"]); oSalesQuote.Lines.UserFields.Fields.Item("U_NEXT_ACTION_BY").Value = Convert.ToString(iRow["ActionBy"]); sSql = "SELECT U_CASE_BRANCH,U_LOAN_MSTR_BANKCODE,ProjectCod FROM OCRD WITH (NOLOCK) WHERE CardCode = '" + Convert.ToString(iRow["CaseNo"]) + "'"; oRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecSet.DoQuery(sSql); if (oRecSet.RecordCount > 0) { oSalesQuote.Lines.COGSCostingCode = oRecSet.Fields.Item("U_CASE_BRANCH").Value; oSalesQuote.Lines.COGSCostingCode2 = oRecSet.Fields.Item("U_LOAN_MSTR_BANKCODE").Value; oSalesQuote.Lines.ProjectCode = oRecSet.Fields.Item("ProjectCod").Value; } sumOfQty = sumOfQty + Convert.ToInt32(iRow["Qty"]); iCount = iCount + 1; } } if (sumOfQty > 0) { if (oSalesQuote.Add() != 0) { sErrDesc = oCompany.GetLastErrorDescription(); sReturnResult = sErrDesc.ToString(); throw new ArgumentException(sErrDesc); } else { sReturnResult = "SUCCESS"; if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With SUCCESS ", sFuncName); } } else { sReturnResult = ""; } } } catch (Exception ex) { sErrDesc = ex.Message.ToString(); oLog.WriteToErrorLogFile(sErrDesc, sFuncName); if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR ", sFuncName); throw ex; } return sReturnResult; }
public string Updateddate(string sCaseNo, string sItemCode, SAPbobsCOM.Company oCompany) { string sFuncName = "GetUpdateddate"; string sSql; SAPbobsCOM.Recordset oRecSet; try { if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName); sSql = "DECLARE @V_CASENO NVARCHAR(MAX),@V_ITEMCODE NVARCHAR(MAX) "; sSql += " DECLARE @V_TABLENAME NVARCHAR(MAX),@V_COLUMN NVARCHAR(MAX)"; sSql += " SET @V_CASENO = '" + sCaseNo + "' "; sSql += " SET @V_ITEMCODE = '" + sItemCode + "'"; sSql += " SELECT @V_TABLENAME = SUBSTRING(U_UPDATE_CASE_DATE,0,CHARINDEX('.',U_UPDATE_CASE_DATE,1)) , "; sSql += " @V_COLUMN = SUBSTRING(U_UPDATE_CASE_DATE,CHARINDEX('.',U_UPDATE_CASE_DATE,1) + 1,LEN(U_UPDATE_CASE_DATE)) "; sSql += " FROM OITM WITH (NOLOCK) WHERE ItemCode = @V_ITEMCODE "; sSql += " AND ISNULL(U_UPDATE_CASE_DATE,'') <> '' "; sSql += " IF(ISNULL(@V_TABLENAME,'') != '' AND ISNULL(@V_COLUMN,'') != '') "; sSql += " BEGIN "; sSql += " EXEC (' "; sSql += " UPDATE '+ @V_TABLENAME +' SET '+ @V_COLUMN +' = CONVERT(CHAR(10),GETDATE(),120) WHERE '+ @V_TABLENAME +'.CardCode = '''+@V_CASENO+''' "; sSql += " ') END"; oRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecSet.DoQuery(sSql); if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With SUCCESS ", sFuncName); } catch (Exception ex) { sErrDesc = ex.Message.ToString(); oLog.WriteToErrorLogFile(sErrDesc, sFuncName); if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR ", sFuncName); throw ex; } return "SUCCESS"; }
public string CreatePO(string sSoDocEntry, SAPbobsCOM.Company oCompany, DataTable dt) { string sFuncName = "CreatePO"; string sPoEntry = string.Empty; SAPbobsCOM.Documents objPO; string sItemLine = string.Empty; string sSql; string sCardCode = string.Empty; try { if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName); foreach (DataRow iRow in dt.Rows) { sItemLine = Convert.ToString(iRow["LineNum"]); SAPbobsCOM.Recordset oRecSet; sSql = "SELECT CardCode FROM OITM WITH (NOLOCK) WHERE ItemCode = '" + Convert.ToString(iRow["ItemCode"]) + "'"; oRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecSet.DoQuery(sSql); if (oRecSet.RecordCount > 0) { sCardCode = oRecSet.Fields.Item("CardCode").Value; } else { sCardCode = ""; } if (sCardCode != string.Empty) { if (Convert.ToDouble(iRow["Qty"]) > 0) { objPO = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders); objPO.CardCode = sCardCode; objPO.DocDate = DateTime.Now.Date; objPO.TaxDate = DateTime.Now.Date; objPO.DocDueDate = DateTime.Now.Date; objPO.NumAtCard = Convert.ToString(iRow["CaseNo"]); int iCount = 0; if (iCount != 0) { objPO.Lines.Add(); } objPO.Lines.ItemCode = Convert.ToString(iRow["ItemCode"]); objPO.Lines.Price = Convert.ToDouble(iRow["Price"]); objPO.Lines.UnitPrice = Convert.ToDouble(iRow["Price"]); objPO.Lines.Quantity = Convert.ToDouble(iRow["Qty"]); sSql = "SELECT U_CASE_BRANCH,U_LOAN_MSTR_BANKCODE,ProjectCod FROM OCRD WITH (NOLOCK) WHERE CardCode = '" + sCardCode + "'"; oRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecSet.DoQuery(sSql); if (oRecSet.RecordCount > 0) { objPO.Lines.ProjectCode = oRecSet.Fields.Item("ProjectCod").Value; objPO.Lines.COGSCostingCode = oRecSet.Fields.Item("U_CASE_BRANCH").Value; objPO.Lines.COGSCostingCode2 = oRecSet.Fields.Item("U_LOAN_MSTR_BANKCODE").Value; } iCount = iCount + 1; if (objPO.Add() != 0) { sErrDesc = oCompany.GetLastErrorDescription(); throw new ArgumentException(sErrDesc); } else { sPoEntry = oCompany.GetNewObjectKey(); //UPDATE THE SALES ODER WITH PURCHASE ORDER DETAILS sSql = "UPDATE RDR1 SET PoTrgNum = (SELECT DocNum FROM OPOR WITH (NOLOCK) WHERE DocEntry = '" + sPoEntry + "'), PoTrgEntry = '" + sPoEntry + "', PoLineNum = '" + sItemLine + "' WHERE DocEntry = '" + sSoDocEntry + "'"; oRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecSet.DoQuery(sSql); sSql = "UPDATE POR1 SET BaseType = 17, BaseEntry = '" + sSoDocEntry + "', BaseLine = '" + sItemLine + "',BaseRef = (SELECT DocNum FROM ORDR WITH (NOLOCK) WHERE DocEntry = '" + sSoDocEntry + "') WHERE DocEntry = '" + sPoEntry + "'"; oRecSet.DoQuery(sSql); } } if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With SUCCESS ", sFuncName); } } } catch (Exception ex) { sErrDesc = ex.Message.ToString(); oLog.WriteToErrorLogFile(sErrDesc, sFuncName); if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR ", sFuncName); throw ex; } return sPoEntry; }
public string CreateAPInv(string sPoEntry, SAPbobsCOM.Company oCompany, string sCaseNo) { string sFuncName = "CreateAPInv"; string sSql; string sAPInvEntry = string.Empty; SAPbobsCOM.Recordset oRecSet; SAPbobsCOM.Documents oAPInv; try { if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName); if (sPoEntry != string.Empty) { sSql = "SELECT A.CardCode,B.ItemCode,B.Quantity,B.Price,B.CogsOcrCod,B.CogsOcrCo2,B.Project,B.ObjType,B.LineNum "; sSql += " FROM OPOR A WITH (NOLOCK) "; sSql += " INNER JOIN POR1 B WITH (NOLOCK) ON B.DocEntry = A.DocEntry "; sSql += " WHERE A.DocEntry = '" + sPoEntry + "' "; oRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecSet.DoQuery(sSql); if (oRecSet.RecordCount > 0) { oAPInv = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices); oAPInv.CardCode = oRecSet.Fields.Item("CardCode").Value; oAPInv.DocDate = DateTime.Now.Date; oAPInv.TaxDate = DateTime.Now.Date; oAPInv.DocDueDate = DateTime.Now.Date; oAPInv.NumAtCard = sCaseNo.ToString(); int iCount = 0; if (iCount != 0) { oAPInv.Lines.Add(); } oAPInv.Lines.ItemCode = oRecSet.Fields.Item("ItemCode").Value; oAPInv.Lines.Quantity = oRecSet.Fields.Item("Quantity").Value; oAPInv.Lines.Price = oRecSet.Fields.Item("Price").Value; oAPInv.Lines.UnitPrice = oRecSet.Fields.Item("Price").Value; oAPInv.Lines.COGSCostingCode = oRecSet.Fields.Item("CogsOcrCod").Value; oAPInv.Lines.COGSCostingCode2 = oRecSet.Fields.Item("CogsOcrCo2").Value; oAPInv.Lines.ProjectCode = oRecSet.Fields.Item("Project").Value; oAPInv.Lines.BaseEntry = Convert.ToInt16(sPoEntry); oAPInv.Lines.BaseType = Convert.ToInt16(oRecSet.Fields.Item("ObjType").Value); oAPInv.Lines.BaseLine = Convert.ToInt16(oRecSet.Fields.Item("LineNum").Value); iCount = iCount + 1; if (oAPInv.Add() != 0) { sErrDesc = oCompany.GetLastErrorDescription(); throw new ArgumentException(sErrDesc); } else { sAPInvEntry = oCompany.GetNewObjectKey(); } } } if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With SUCCESS ", sFuncName); } catch (Exception ex) { sErrDesc = ex.Message.ToString(); oLog.WriteToErrorLogFile(sErrDesc, sFuncName); if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR ", sFuncName); throw ex; } return sAPInvEntry; }