Esempio n. 1
0
        protected void btnObtenerNum_Click(object sender, EventArgs e)
        {
            Settings oSettings = new Settings(ddlEmpresa.SelectedItem.Value);

            AfipConnection afipConnFex = new AfipConnection("wsfex", oSettings);
            AfipConnection afipConnFe = new AfipConnection("wsfe", oSettings);

            wsfex.Service afipFexService = new wsfex.Service();
            afipFexService.Url = oSettings.UrlAFIPwsfex;

            wsfe.Service feService = new wsfe.Service();
            feService.Url = oSettings.UrlAFIPwsfe;

            wsfex.ClsFEX_LastCMP afipLastEx = new wsfex.ClsFEX_LastCMP();

            wsfe.FEAuthRequest afipObjFEAuthRequest = new wsfe.FEAuthRequest();

            switch (ddlTipoComprobante.SelectedValue)
            {
                case "1":
                case "2":
                case "3":
                case "6":
                case "7":
                case "8":
                    try
                    {
                        lblErrorMessages.Text = "";
                        if (afipConnFe.ConnectionErrorDescription == string.Empty)
                        {
                            //Inicializo el objeto AuthRequest de la Afip
                            afipObjFEAuthRequest.Cuit = afipConnFe.Cuit;
                            afipObjFEAuthRequest.Sign = afipConnFe.Sign;
                            afipObjFEAuthRequest.Token = afipConnFe.Token;

                            wsfe.FERecuperaLastCbteResponse objFERecuperaLastCMPResponse = new wsfe.FERecuperaLastCbteResponse();

                            objFERecuperaLastCMPResponse = feService.FECompUltimoAutorizado(afipObjFEAuthRequest, Convert.ToInt16(ddlSucursales.SelectedValue), Convert.ToInt16(ddlTipoComprobante.SelectedValue));

                            lblNumCbte.Text = (objFERecuperaLastCMPResponse.CbteNro + 1).ToString();
                            lblNumCbte.Text = FillWithCeros(lblNumCbte.Text);
                        }
                        else
                        {
                            lblNumCbte.Text = "XXXXXXXX";
                            lblErrorMessages.Text = "Error de login con AFIP.<br>Error: " + afipConnFe.ConnectionErrorDescription;
                        }
                    }
                    catch (Exception ex)
                    {
                        lblNumCbte.Text = "XXXXXXXX";
                        lblErrorMessages.Text = "Error: " + ex.Message;
                    }

                    //wsfe.FETributoResponse trires = feService.FEParamGetTiposTributos(afipObjFEAuthRequest);
                    break;

                case "19":
                case "20":
                case "21":
                    try
                    {
                        lblErrorMessages.Text = "";
                        if (afipConnFex.ConnectionErrorDescription == string.Empty)
                        {
                            //Inicializo el objeto AuthRequest de la Afip
                            afipLastEx.Cuit = afipConnFex.Cuit;
                            afipLastEx.Sign = afipConnFex.Sign;
                            afipLastEx.Token = afipConnFex.Token;
                            afipLastEx.Pto_venta = Convert.ToInt16(ddlSucursales.SelectedItem.Text);
                            afipLastEx.Tipo_cbte = Convert.ToInt16(ddlTipoComprobante.SelectedItem.Value);

                            wsfex.FEXResponseLast_CMP lastResp = afipFexService.FEXGetLast_CMP(afipLastEx);

                            lblNumCbte.Text = (lastResp.FEXResult_LastCMP.Cbte_nro + 1).ToString();
                            lblNumCbte.Text = FillWithCeros(lblNumCbte.Text);
                        }
                        else
                        {
                            lblNumCbte.Text = "XXXXXXXX";
                            lblErrorMessages.Text = "Error de login con AFIP.<br>Error: " + afipConnFex.ConnectionErrorDescription;
                        }
                    }
                    catch (Exception ex)
                    {
                        lblNumCbte.Text = "XXXXXXXX";
                        lblErrorMessages.Text = "Error: " + ex.Message;
                    }

                    break;
            }
        }
Esempio n. 2
0
        public wsfe.FERecuperaLastCbteResponse FERecuperaUltimoComprobante(string tipoComprobante, string puntoVenta)
        {
            wsfe.FERecuperaLastCbteResponse objFERecuperaLastCMPResponse = new wsfe.FERecuperaLastCbteResponse();

            try
            {
                objFERecuperaLastCMPResponse = feService.FECompUltimoAutorizado(objFEAuthRequest, Convert.ToInt16(puntoVenta), Convert.ToInt16(tipoComprobante));
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry("FERecuperaUltimoComprobante", ex.Message, System.Diagnostics.EventLogEntryType.Error);
            }
            return objFERecuperaLastCMPResponse;
        }