Download Faturas: Substituição de pasta NFe para TUSD utilizando Case Insensitive.

WebHook: Salvar somente arquivos do tipo "nota_fiscal", ignorar arquivos devec e decisões judiciais.
Salvar no histórico a mensagem de erro.
This commit is contained in:
Adriano Serighelli 2025-06-03 10:23:22 -03:00
parent b29ae2e3d3
commit 48c729e5b6
3 changed files with 31 additions and 15 deletions

View File

@ -147,7 +147,7 @@
dadosTusd.Dem_Cont_P = float.Parse(reader["Demanda_P"].ToString() !);
dadosTusd.Dem_Cont_FP = float.Parse(reader["Demanda_FP"].ToString() !);
dadosTusd.Perfil = reader["Perfil"].ToString();
this.PastaTUSD = new DirectoryInfo(reader["Caminho_NFs"].ToString() !.Replace("\\NFe", string.Empty) + "\\TUSD");
this.PastaTUSD = new DirectoryInfo(reader["Caminho_NFs"].ToString() !.Replace("\\NFe", string.Empty, StringComparison.OrdinalIgnoreCase) + "\\TUSD");
this.Gestao = reader["Gestao"].ToString();
this.Empresa = reader["Cliente"].ToString();
this.Unidade = reader["Unidade"].ToString();
@ -254,6 +254,12 @@
string? kind_P = string.Empty;
string? kind_FP = string.Empty;
if (this.id == "2356193")
{
int i = 0;
i++;
}
List<(string, float)> insertOthers = new List<(string, float)>();
foreach (Item item in parsedResult.items)
{

View File

@ -1,4 +1,5 @@
using System.Net.Http.Headers;
using System.Net;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
@ -81,6 +82,15 @@ public class Program
}
public static HttpResponseMessage SendFatura(string token, string fatura, bool agrupada)
{
var handler = new HttpClientHandler
{
//Proxy = new WebProxy("http://127.0.0.1:8888"),
//UseProxy = true,
//ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
};
using (var httpClient = new HttpClient(handler))
{
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.4docs.cloud/v2/parse");
@ -96,6 +106,7 @@ public class Program
return httpClient.Send(request);
}
}
public static bool IsFileLocked(FileInfo file)
{

View File

@ -118,8 +118,7 @@ namespace Webhook_4docs
JsonElement DadosJson = JsonDocument.Parse(root.ToString()).RootElement;
if (root.Get("documentType")?.ToString().ToLower() == "devec") { return; }
if (root.Get("documentType")?.ToString().ToLower() != "nota_fiscal") { return; }
Fatura fatura = new(fatura_ID, JsonBody);
bool completed = false;
@ -235,7 +234,7 @@ namespace Webhook_4docs
break;
}
int test = await UpdateErrorIdStatusAsync(CaminhoDB, JsonBody.GetProperty("locationID").GetInt64(), errorID, JsonBody.GetProperty("systemText").ToString(), logger);
int test = await UpdateErrorIdStatusAsync(CaminhoDB, JsonBody.GetProperty("locationID").GetInt64(), errorID, (JsonBody.GetProperty("systemText").ToString() == "" ? JsonBody.GetProperty("websiteText").ToString() : JsonBody.GetProperty("systemText").ToString()), logger);
if (test == 0)
{
@ -361,8 +360,8 @@ namespace Webhook_4docs
using (OleDbCommand cmd = new OleDbCommand(
@"UPDATE AgVirtual4Docs
SET errorID = ?, status = ?
WHERE location_id = ?", conn))
SET errorID = @errorID, status = @status
WHERE location_id = @location_id", conn))
{
// Adiciona parâmetros de forma segura
cmd.Parameters.AddWithValue("@errorID", errorID);