Esempio n. 1
0
        public static async Task <ResultDte> SendDteCreditorAsync(Detalle detalle, string tokenCen, string doc)
        {
            string fileName = detalle.Folio + "_" + detalle.Instruction.Id;
            string idFile   = await SendFileAsync(tokenCen, fileName, doc);

            if (!string.IsNullOrEmpty(idFile))
            {
                ResultDte dte = new ResultDte
                {
                    Folio              = detalle.Folio,
                    GrossAmount        = detalle.MntTotal,
                    Instruction        = detalle.Instruction.Id,
                    NetAmount          = detalle.MntNeto,
                    ReportedByCreditor = true,
                    TypeSiiCode        = 33,
                    EmissionDt         = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(detalle.FechaEmision)),
                    ReceptionDt        = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(detalle.FechaRecepcion)),
                    EmissionFile       = idFile
                };
                try
                {
                    using (CustomWebClient wc = new CustomWebClient())
                    {
                        Uri    uri = new Uri(Properties.Settings.Default.UrlCen, "api/v1/operations/dtes/create/");
                        string d   = JsonConvert.SerializeObject(dte);
                        wc.Headers[HttpRequestHeader.Authorization] = $"Token {tokenCen}";
                        NameValueCollection postData = new NameValueCollection()
                        {
                            { "data", d }
                        };
                        byte[] res = await wc.UploadValuesTaskAsync(uri, WebRequestMethods.Http.Post, postData); // POST

                        if (res != null)
                        {
                            string    json = Encoding.UTF8.GetString(res);
                            InsertDTe r    = JsonConvert.DeserializeObject <InsertDTe>(json, new JsonSerializerSettings {
                                NullValueHandling = NullValueHandling.Ignore
                            });
                            if (r != null)
                            {
                                return(r.ResultDte);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(null);
        }
Esempio n. 2
0
        public static async Task <ResultDte> SendDteDebtorAsync(Detalle detalle, string tokenCen)
        {
            ResultDte dte = new ResultDte
            {
                Folio              = detalle.Folio,
                GrossAmount        = detalle.MntTotal,
                Instruction        = detalle.Instruction.Id,
                NetAmount          = detalle.MntNeto,
                ReportedByCreditor = false,
                TypeSiiCode        = 33,
                AcceptanceDt       = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(detalle.FechaRecepcion))
            };

            switch (detalle.StatusDetalle)
            {
            case StatusDetalle.Accepted:
                dte.AcceptanceStatus = 1;
                break;

            case StatusDetalle.Rejected:
                dte.AcceptanceStatus = 2;
                break;

            case StatusDetalle.Pending:
                break;

            default:
                break;
            }
            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri    uri = new Uri(Properties.Settings.Default.UrlCen, "api/v1/operations/dtes/create/");
                    string d   = JsonConvert.SerializeObject(dte);
                    wc.Headers[HttpRequestHeader.ContentType]   = "application/x-www-form-urlencoded";
                    wc.Headers[HttpRequestHeader.Authorization] = $"Token {tokenCen}";
                    NameValueCollection postData = new NameValueCollection()
                    {
                        { "data", d }
                    };

                    byte[] res = await wc.UploadValuesTaskAsync(uri, WebRequestMethods.Http.Post, postData); // POST

                    if (res != null)
                    {
                        string    json = Encoding.UTF8.GetString(res);
                        InsertDTe r    = JsonConvert.DeserializeObject <InsertDTe>(json, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        if (r != null && r.Errors.Count == 0)
                        {
                            return(r.ResultDte);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }