public static string FormatMoneyToString(double _double, SAPbobsCOM.Company oCompany, SAPbobsCOM.BoMoneyPrecisionTypes _Precision)
 {
     SAPbobsCOM.SBObob    businessObject = (SAPbobsCOM.SBObob)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);
     SAPbobsCOM.Recordset recordset      = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
     recordset = businessObject.Format_MoneyToString(_double, _Precision);
     return((string)recordset.Fields.Item(0).Value);
 }
Beispiel #2
0
        public async Task <IActionResult> Get()
        {
            SAPContext context = HttpContext.RequestServices.GetService(typeof(SAPContext)) as SAPContext;

            SAPbobsCOM.SBObob SBO = (SAPbobsCOM.SBObob)context.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);
            try {
                SAPbobsCOM.Recordset oRecSet      = SBO.GetCurrencyRate("USD", DateTime.Today);
                JToken             temp           = context.XMLTOJSON(oRecSet.GetAsXML())["Recordset"][0];
                CurrencyRateDetail CurrencyOutput = temp.ToObject <CurrencyRateDetail>();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                return(Ok(CurrencyOutput));
            } catch (Exception ex) {
                return(Conflict(ex.Message));
            }
        }
Beispiel #3
0
        private void DIA_GetBpList_Click(object sender, EventArgs e)
        {
            SAPbobsCOM.Recordset objRecordset = null;
            try
            {
                if (this.objCompany == null || !objCompany.Connected)
                {
                    this.connect();
                }
                if (this.objCompany != null && objCompany.Connected)
                {
                    objBP        = (SAPbobsCOM.BusinessPartners)objCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
                    objRecordset = (SAPbobsCOM.Recordset)objCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

                    SAPbobsCOM.SBObob objBOB = null;
                    objBOB                  = objCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);
                    objRecordset            = objBOB.GetBPList(getDIACardtype(DIA_CardType.Text));
                    objBP.Browser.Recordset = objRecordset;

                    objBP.Browser.MoveFirst();

                    String msg = null;
                    while (!objBP.Browser.EoF)
                    {
                        msg += objBP.CardCode + " - " + objBP.CardName + "\n";
                        objBP.Browser.MoveNext();
                    }

                    MessageBox.Show(msg);
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }
        }
Beispiel #4
0
        public static void UpdateForDate(DateTime pDATE)
        {
            SAPbobsCOM.SBObob bobs = sboDI.oDiCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);

            string _mainCurrency = ((string)bobs.GetLocalCurrency().Fields.Item(0).Value).ToUpperInvariant();

            SAPbobsCOM.Recordset  recordset  = sboDI.oDiCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            System.Data.DataTable currencies = ds.getDataTable(
                sboDI.oDiCompany.DbServerType.Equals(SAPbobsCOM.BoDataServerTypes.dst_HANADB)
                    ? @"SELECT OCRN.* FROM OCRN LEFT JOIN ORTT ON OCRN.""CurrCode"" = ORTT.""Currency"" AND ""RateDate"" = '" + pDATE.ToString("yyyyMMdd") + @"' WHERE COALESCE(""Rate"", 0) = 0"
                    : @"SELECT OCRN.* FROM OCRN LEFT JOIN ORTT ON OCRN.""CurrCode"" = ORTT.""Currency"" AND ""RateDate"" =  '" + pDATE.ToString("yyyyMMdd") + @"' WHERE COALESCE(""Rate"", 0) = 0");

            var currencyCodes = new Dictionary <string, string>();

            foreach (System.Data.DataRow currency in currencies.Rows)
            {
                string code    = currency["CurrCode"] as string;
                string intcode = currency["DocCurrCod"] as string;
                string isocode = currency["ISOCurrCod"] as string;

                string currencyCode = string.IsNullOrWhiteSpace(isocode)
                    ? intcode?.ToUpperInvariant()
                    : isocode.ToUpperInvariant();

                if (code != null && !string.IsNullOrWhiteSpace(currencyCode) && currencyCode.Length == 3)
                {
                    currencyCodes.Add(code, currencyCode);
                }
            }
            string mainCurrency = currencyCodes[_mainCurrency];
            string strDate      = pDATE.ToString("yyyy-MM-dd");

            currencyCodes.Remove(_mainCurrency);

            if (!currencyCodes.Any())
            {
                return;
            }

            JObject    document;
            CURRENCIES result;

            using (WebClient wc = new WebClient())
            {
                //string callString = "https://openexchangerates.org/api/historical/" + strDate + ".json?app_id=64f0b566047049ec93b765fce90530e4&base=" + mainCurrency;
                ////  MessageBox.Show(_mainCurrency + strDate + callString);



                //document =
                //                        JObject.Parse(
                //                            wc.DownloadString(
                //                                $"https://openexchangerates.org/api/historical/" + strDate + ".json?app_id=64f0b566047049ec93b765fce90530e4&base=" + mainCurrency + ""));



                string strXml = wc.DownloadString($"http://www.boi.org.il/currency.xml");


                XmlDocument doc = new XmlDocument();
                doc.LoadXml(strXml);
                XmlSerializer serializer = new XmlSerializer(typeof(CURRENCIES));
                using (TextReader reader = new StringReader(doc.InnerXml))
                {
                    result = (CURRENCIES)serializer.Deserialize(reader);
                }
            }

            //var test = from rate in document.SelectToken("rates").Children()
            //           where rate is JProperty && currencyCodes.ContainsValue(((JProperty)rate).Name)
            //           select
            //           new
            //           {
            //               CurrencyCode = ((JProperty)rate).Name,
            //               Date = pDATE.Date,
            //               Rate = Convert.ToDouble(1M / ((JProperty)rate).Value.Value<decimal>())
            //           };

            var test = from rate in result.CURRENCY
                       where currencyCodes.ContainsValue(rate.CURRENCYCODE)
                       select
                       new
            {
                CurrencyCode = rate.CURRENCYCODE,
                Date         = pDATE.Date,
                Rate         = Convert.ToDouble(rate.RATE)
            };


            int codesUpdated = 0;

            foreach (var rate in test)
            {
                // MessageBox.Show("Updating " + rate.CurrencyCode);

                var code = currencyCodes.FirstOrDefault(kp => kp.Value.Equals(rate.CurrencyCode)).Key;


                var rateExists = false;
                try
                {
                    if (bobs.GetCurrencyRate(code, rate.Date).RecordCount > 0)
                    {
                        rateExists = true;
                    }
                }
                catch (Exception ex)
                {
                    string err = ex.Message;
                }
                finally
                {
                    if (!rateExists)
                    {
                        try
                        {
                            bobs.SetCurrencyRate(code, rate.Date, rate.Rate, false);
                        }
                        catch (Exception ex)
                        {
                            //  MessageBox.Show("Updating " + code);
                        }
                        codesUpdated++;
                    }
                }
            }
        }
Beispiel #5
0
        private void Button0_ClickBefore(object sboObject, SAPbouiCOM.SBOItemEventArg pVal, out bool BubbleEvent)
        {
            BubbleEvent = true;
            try
            {
                if (EditText1.Value == "")
                {
                    Application.SBO_Application.MessageBox("Favor de capturar el Folio de la solicitud");
                    return;
                }
                SAPbobsCOM.StockTransfer lObjStockTrasnfer;
                string               lStrFolio     = EditText1.Value;
                SAPbobsCOM.SBObob    lObjSBObob    = (SAPbobsCOM.SBObob)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);
                SAPbobsCOM.Recordset lObjRecordSet = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                lObjRecordSet = lObjSBObob.GetObjectKeyBySingleValue(SAPbobsCOM.BoObjectTypes.oInventoryTransferRequest, "DocNum", lStrFolio, SAPbobsCOM.BoQueryConditions.bqc_Equal);
                SAPbobsCOM.StockTransfer lObjInventory = (SAPbobsCOM.StockTransfer)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryTransferRequest);
                if (lObjRecordSet.RecordCount == 1)
                {
                    lObjInventory.GetByKey(int.Parse(lObjRecordSet.Fields.Item(0).Value.ToString()));
                }

                Memory.ReleaseComObject(lObjSBObob);
                Memory.ReleaseComObject(lObjRecordSet);

                SAPbobsCOM.Recordset lObjRecordSet2 = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                lObjRecordSet2.DoQuery("select T0.U_CR_Batch, T0.DocEntry,T0.LineNum, T0.OpenQty, T0.WhsCode, T0.FromWhsCod, T0.U_CR_CardCode, T0.ItemCode from WTQ1 T0 inner join OWTQ T1 on T1.DocEntry = T0.DocEntry Inner join OCRD T3 on T3.cardcode = T0.U_CR_CardCode where T1.DocNum = '" + lStrFolio + "' and T0.InvntSttus = 'O'");

                lLstExtraData = new List <object>();

                for (int i = 0; i < lObjRecordSet2.RecordCount; i++)
                {
                    lLstExtraData.Add(new
                    {
                        Lote        = lObjRecordSet2.Fields.Item(0).Value.ToString(),
                        DocEntry    = lObjRecordSet2.Fields.Item(1).Value.ToString(),
                        LineNum     = lObjRecordSet2.Fields.Item(2).Value.ToString(),
                        Quantity    = lObjRecordSet2.Fields.Item(3).Value.ToString(),
                        Whscode     = lObjRecordSet2.Fields.Item(4).Value.ToString(),
                        FromWhscode = lObjRecordSet2.Fields.Item(5).Value.ToString(),
                        CardCode    = lObjRecordSet2.Fields.Item(6).Value.ToString(),
                        ItemCode    = lObjRecordSet2.Fields.Item(7).Value.ToString()
                    });
                    lObjRecordSet2.MoveNext();
                }

                Memory.ReleaseComObject(lObjRecordSet2);



                lObjStockTrasnfer = (SAPbobsCOM.StockTransfer)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer);

                bool lBolIsSuccesss = false;
                for (int i = 1; i <= Matrix1.RowCount; i++)
                {
                    SAPbouiCOM.CheckBox lObjChk = (SAPbouiCOM.CheckBox)Matrix1.Columns.Item(0).Cells.Item(i).Specific;

                    if (lObjChk.Checked)
                    {
                        lObjStockTrasnfer.FromWarehouse = ((SAPbouiCOM.EditText)Matrix1.Columns.Item(3).Cells.Item(i).Specific).Value;
                        lObjStockTrasnfer.ToWarehouse   = ((dynamic)lLstExtraData[i - 1]).Whscode;
                        string lStrCardCode = ((SAPbouiCOM.EditText)Matrix1.Columns.Item("Col_6").Cells.Item(i).Specific).Value;
                        string lStrAlmacen  = ((SAPbouiCOM.EditText)Matrix1.Columns.Item("Col_3").Cells.Item(i).Specific).Value;
                        string lStrCantidad = ((SAPbouiCOM.EditText)Matrix1.Columns.Item("Col_4").Cells.Item(i).Specific).Value;
                        string lStrTrans    = ((SAPbouiCOM.EditText)Matrix1.Columns.Item("Col_5").Cells.Item(i).Specific).Value;
                        string lStrItemCode = ((SAPbouiCOM.EditText)Matrix1.Columns.Item("Col_7").Cells.Item(i).Specific).Value;
                        var    lObjData     = new
                        {
                            CardCode = lStrCardCode,
                            Almacen  = lStrAlmacen,
                            Cantidad = lStrCantidad,
                            Trans    = lStrTrans,
                            ItemCode = lStrItemCode
                        };
                        if (lStrTrans.Trim() != "")
                        {
                            lObjStockTrasnfer = AddLines(lObjStockTrasnfer, lObjInventory, lObjData);
                            lBolIsSuccesss    = true;
                        }
                        else
                        {
                            Application.SBO_Application.StatusBar.SetText("Capturar cantidad", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                        }
                    }
                }
                if (lBolIsSuccesss)
                {
                    lObjStockTrasnfer.DocDate = DateTime.Now;

                    if (lObjStockTrasnfer.Add() != 0)
                    {
                        int    error    = oCompany.GetLastErrorCode();
                        string strError = oCompany.GetLastErrorDescription();
                        Application.SBO_Application.MessageBox(strError);
                    }
                    else
                    {
                        EditText1.Value = "";
                        LoadMatrixPeticiones();
                        Application.SBO_Application.StatusBar.SetText("Traslado correctamente efectuado.", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                    }
                }
                else
                {
                    Application.SBO_Application.StatusBar.SetText("No se ha seleccionado ningun almacen para el traslado.", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                }
            }
            catch (Exception ex)
            {
                Application.SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            try
            {
                DateTime fechaSap = DateTime.Now.AddDays(1);
                WebServiceTRMReference.TCRMServicesInterfaceClient ws = new WebServiceTRMReference.TCRMServicesInterfaceClient();
                WebServiceTRMReference.tcrmResponse respuestaTRM      = new WebServiceTRMReference.tcrmResponse();
                respuestaTRM = ws.queryTCRM(fechaSap);

                SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
                oCompany.Server        = ConfigurationManager.AppSettings.Get("Server");
                oCompany.LicenseServer = ConfigurationManager.AppSettings.Get("LicenseServer");
                oCompany.CompanyDB     = ConfigurationManager.AppSettings.Get("CompanyDB");
                oCompany.UserName      = ConfigurationManager.AppSettings.Get("UserName");
                oCompany.Password      = ConfigurationManager.AppSettings.Get("Password");

                switch (ConfigurationManager.AppSettings.Get("DbServerType"))
                {
                case "dst_HANADB":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
                    break;

                case "dst_MSSQL2005":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005;
                    break;

                case "dst_MSSQL2008":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008;
                    break;

                case "dst_MSSQL2012":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
                    break;

                case "dst_MSSQL2014":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014;
                    break;

                case "dst_MSSQL2016":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016;
                    break;
                }



                int resultado = oCompany.Connect();
                if (resultado == 0)
                {
                    SAPbobsCOM.SBObob bo = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);
                    bo.SetCurrencyRate("USD", fechaSap, Math.Round(respuestaTRM.value, 2), true);

                    oCompany.Disconnect();

                    Console.WriteLine("TRM Actualizada!");
                    string asunto  = "TRM SAP " + ConfigurationManager.AppSettings.Get("CompanyDB") + " Actualizada " + fechaSap.ToString().Substring(0, 10);
                    string mensaje = "Se ha realizado correctamente la actualizacion de la tasa de cambio del dolar para el dia " + fechaSap.ToString().Substring(0, 10) + " - TRM: $" + respuestaTRM.value;
                    //envia el correo solo en caso de existir error de actualizacion
                    if (ConfigurationManager.AppSettings.Get("CorreoErrorActualiza") == "NO")
                    {
                        EnviarCorreo(asunto, mensaje);
                    }
                    Environment.Exit(1);
                }
                else
                {
                    throw new Exception(oCompany.GetLastErrorCode() + ": " + oCompany.GetLastErrorDescription());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                string asunto  = "TRM SAP " + ConfigurationManager.AppSettings.Get("CompanyDB") + " *ERROR* " + DateTime.Now.AddDays(1);
                string mensaje = "Error en la actualizacion: " + DateTime.Now.AddDays(1) + " **" + ex.Message;
                EnviarCorreo(asunto, mensaje);
            }
        }