示例#1
0
        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;
        }
示例#2
0
        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;
        }
示例#3
0
        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;
        }