From 5a019cddec2fd9b2874ad63fc4819b282eae1581 Mon Sep 17 00:00:00 2001 From: Adriano Serighelli Date: Thu, 28 Nov 2024 14:12:44 -0300 Subject: [PATCH] =?UTF-8?q?Faturas=20incluidas=20no=20BD=20ser=C3=A3o=20sa?= =?UTF-8?q?lvas=20automaticamente=20na=20pasta=20da=20unidade.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Download Faturas/Fatura.cs | 14 +++++++++++--- Download Faturas/Rootobject.cs | 1 - Webhook 4docs/.config/dotnet-tools.json | 10 +++++++++- Webhook 4docs/Program.cs | 17 ++++++----------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Download Faturas/Fatura.cs b/Download Faturas/Fatura.cs index a4fcafb..ae22265 100644 --- a/Download Faturas/Fatura.cs +++ b/Download Faturas/Fatura.cs @@ -18,7 +18,6 @@ private const string Token = "UFY4VWzqcHYcGNd0gkBOMFL9G5ZThV6gXBQIJ79F5HSqITzavz4Fe7iXvAbJLvZJ"; private JsonElement faturaParsed; private string? id; - private string? pastaMiddle; private string? uc; private int? pagina; @@ -68,6 +67,8 @@ public FileInfo? Arquivo { get; private set; } + public DirectoryInfo? PastaTUSD { get; private set; } + public bool Agrupada { get; private set; } public JsonElement.ArrayEnumerator Agrupada_children { get; private set; } @@ -146,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.pastaMiddle = reader["Caminho_NFs"].ToString(); + this.PastaTUSD = new DirectoryInfo(reader["Caminho_NFs"].ToString() !.Replace("\\NFe", string.Empty) + "\\TUSD"); this.Gestao = reader["Gestao"].ToString(); this.Empresa = reader["Cliente"].ToString(); this.Unidade = reader["Unidade"].ToString(); @@ -604,7 +605,14 @@ case ("FATURA INCLUIDA NO BD", _): - destino = this.Arquivo?.Directory?.Parent?.FullName + $@"\6 - {this.Status}\ID {this.id!} - Mês {this.Mes} - Empresa {this.Empresa} - Unidade {this.Unidade}.pdf"; + if (this.PastaTUSD!.Exists) + { + destino = this.PastaTUSD!.FullName + $@"\ID {this.id!} - Mês {this.Mes} - Empresa {this.Empresa} - Unidade {this.Unidade}.pdf"; + } + else + { + destino = this.Arquivo?.Directory?.Parent?.FullName + $@"\6 - {this.Status}\ID {this.id!} - Mês {this.Mes} - Empresa {this.Empresa} - Unidade {this.Unidade}.pdf"; + } if (separar) { diff --git a/Download Faturas/Rootobject.cs b/Download Faturas/Rootobject.cs index a0764cc..7d8e58e 100644 --- a/Download Faturas/Rootobject.cs +++ b/Download Faturas/Rootobject.cs @@ -101,7 +101,6 @@ public string[] texts { get; set; } - [JsonConverter(typeof(FloatArrayOrSingleConverter))] public float measured { get; set; } } diff --git a/Webhook 4docs/.config/dotnet-tools.json b/Webhook 4docs/.config/dotnet-tools.json index b0e38ab..4f48799 100644 --- a/Webhook 4docs/.config/dotnet-tools.json +++ b/Webhook 4docs/.config/dotnet-tools.json @@ -1,5 +1,13 @@ { "version": 1, "isRoot": true, - "tools": {} + "tools": { + "dotnet-ef": { + "version": "9.0.0", + "commands": [ + "dotnet-ef" + ], + "rollForward": false + } + } } \ No newline at end of file diff --git a/Webhook 4docs/Program.cs b/Webhook 4docs/Program.cs index 5d78201..3ac9a42 100644 --- a/Webhook 4docs/Program.cs +++ b/Webhook 4docs/Program.cs @@ -73,8 +73,6 @@ namespace Webhook_4docs app.UseHsts(); } - - app.UsePathBase(appFolder); app.UseRouting(); @@ -127,8 +125,6 @@ namespace Webhook_4docs fatura.Processar(conn); } - bool t = false; - string? status = fatura.Status; int status_id = 0; @@ -153,9 +149,12 @@ namespace Webhook_4docs try { string path = $@"X:\Middle\Carteira {fatura.Gestao![0]}\Carteira {fatura.Gestao}\Faturas fourdocs\{status_id} - {status}"; - System.IO.Directory.CreateDirectory(path); + if (status_id == 6 && fatura.PastaTUSD!.Exists) + { + path = fatura.PastaTUSD!.FullName; + } fatura_arquivo = IndexedFilename($@"{path}\ID {fatura_ID!} - Mês {fatura.Mes} - Empresa {fatura.Empresa} - Unidade {fatura.Unidade}", "pdf"); - t = CriarArquivo(fatura_arquivo, JsonBody.GetProperty("pdfFile").ToString()); + CriarArquivo(fatura_arquivo, JsonBody.GetProperty("pdfFile").ToString()); var DatabaseModel = new ProcessedInvoices { @@ -178,7 +177,6 @@ namespace Webhook_4docs } catch { - t = false; logger.LogError("Erro no processamento da fatura"); } @@ -258,10 +256,9 @@ namespace Webhook_4docs return test; } - public static bool CriarArquivo(string fatura_arquivo, string pdfFile64) + public static void CriarArquivo(string fatura_arquivo, string pdfFile64) { //string fatura_arquivo = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\test.pdf"; - bool t = false; if (!File.Exists(fatura_arquivo)) { byte[] bytes = Convert.FromBase64String(pdfFile64); @@ -271,9 +268,7 @@ namespace Webhook_4docs new(stream); writer.Write(bytes, 0, bytes.Length); writer.Close(); - t = true; } - return t; } } public static partial class JsonExtensions