Conclusão do método "mover"
This commit is contained in:
parent
857e13d667
commit
b65d42e0de
@ -9,16 +9,14 @@
|
|||||||
|
|
||||||
public class Fatura
|
public class Fatura
|
||||||
{
|
{
|
||||||
/* A fatura deve ter alguma propriedades públicas: Local de origem, local de destino, Status do processamento
|
|
||||||
* Outras propriedas privadas: ID, Mes, agrupada, token, UC
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
private const string Token = "UFY4VWzqcHYcGNd0gkBOMFL9G5ZThV6gXBQIJ79F5HSqITzavz4Fe7iXvAbJLvZJ";
|
private const string Token = "UFY4VWzqcHYcGNd0gkBOMFL9G5ZThV6gXBQIJ79F5HSqITzavz4Fe7iXvAbJLvZJ";
|
||||||
|
|
||||||
private JsonElement faturaParsed;
|
private JsonElement faturaParsed;
|
||||||
|
private string? id;
|
||||||
|
private string? empresa;
|
||||||
|
private string? unidade;
|
||||||
|
private string? pastaMiddle;
|
||||||
|
private string? uc;
|
||||||
|
private int mes;
|
||||||
|
|
||||||
public Fatura(string id, string fatura_path, HttpClient httpClient)
|
public Fatura(string id, string fatura_path, HttpClient httpClient)
|
||||||
{
|
{
|
||||||
@ -29,8 +27,10 @@
|
|||||||
{
|
{
|
||||||
this.faturaParsed = JsonDocument.Parse(fatura_response.Content.ReadAsStringAsync().Result).RootElement;
|
this.faturaParsed = JsonDocument.Parse(fatura_response.Content.ReadAsStringAsync().Result).RootElement;
|
||||||
this.Agrupada = this.faturaParsed.TryGetProperty("multiple", out var _);
|
this.Agrupada = this.faturaParsed.TryGetProperty("multiple", out var _);
|
||||||
this.Status = this.faturaParsed.GetProperty("status").GetString() !;
|
this.Status = this.faturaParsed.GetProperty("status").GetString();
|
||||||
this.Arquivo = fatura_path;
|
this.Arquivo = new FileInfo(fatura_path);
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
if (this.Agrupada)
|
if (this.Agrupada)
|
||||||
{
|
{
|
||||||
this.Agrupada_children = this.faturaParsed.GetProperty("children").EnumerateArray();
|
this.Agrupada_children = this.faturaParsed.GetProperty("children").EnumerateArray();
|
||||||
@ -40,13 +40,7 @@
|
|||||||
|
|
||||||
public string? Status { get; private set; }
|
public string? Status { get; private set; }
|
||||||
|
|
||||||
public string? Pasta_middle { get; private set; }
|
public FileInfo? Arquivo { get; private set; }
|
||||||
|
|
||||||
public string? Arquivo { get; private set; }
|
|
||||||
|
|
||||||
public string? UC { get; private set; }
|
|
||||||
|
|
||||||
public int Mes { get; private set; }
|
|
||||||
|
|
||||||
public bool Agrupada { get; private set; }
|
public bool Agrupada { get; private set; }
|
||||||
|
|
||||||
@ -73,11 +67,11 @@
|
|||||||
|
|
||||||
if (unidades == 1)
|
if (unidades == 1)
|
||||||
{
|
{
|
||||||
selectSQL = $"SELECT Cod_Smart_unidade, PerfilCCEE, Submercado, Status_unidade, Grupo, Distribuidora, ICMS_TUSD, Demanda_P, Demanda_FP, Caminho_NFs FROM Dados_cadastrais WHERE Codigo_Instalacao = '{uc}'";
|
selectSQL = $"SELECT Cod_Smart_unidade, Cliente, Unidade, PerfilCCEE, Submercado, Status_unidade, Grupo, Distribuidora, ICMS_TUSD, Demanda_P, Demanda_FP, Caminho_NFs FROM Dados_cadastrais WHERE Codigo_Instalacao = '{uc}'";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
selectSQL = $"SELECT Cod_Smart_unidade, PerfilCCEE, Submercado, Status_unidade, Grupo, Distribuidora, ICMS_TUSD, Demanda_P, Demanda_FP, Caminho_NFs FROM Dados_cadastrais WHERE (CNPJ_CPF LIKE '{parsedResult.customer.cnpj?.Substring(0, 8) ?? "NAN"}%' AND Codigo_Instalacao = '{uc}') OR (Razao_Social LIKE '{parsedResult.customer.name}' AND Codigo_Instalacao = '{uc}')";
|
selectSQL = $"SELECT Cod_Smart_unidade, Cliente, Unidade, PerfilCCEE, Submercado, Status_unidade, Grupo, Distribuidora, ICMS_TUSD, Demanda_P, Demanda_FP, Caminho_NFs FROM Dados_cadastrais WHERE (CNPJ_CPF LIKE '{parsedResult.customer.cnpj?.Substring(0, 8) ?? "NAN"}%' AND Codigo_Instalacao = '{uc}') OR (Razao_Social LIKE '{parsedResult.customer.name}' AND Codigo_Instalacao = '{uc}')";
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandText = selectSQL;
|
cmd.CommandText = selectSQL;
|
||||||
@ -87,16 +81,18 @@
|
|||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
// Dados cadastrais
|
// Dados cadastrais
|
||||||
dadosTusd.Cod_Smart_unidade = long.Parse(reader["Cod_Smart_unidade"].ToString());
|
dadosTusd.Cod_Smart_unidade = long.Parse(reader["Cod_Smart_unidade"].ToString() !);
|
||||||
dadosTusd.Perfil_CliqCCEE = reader["PerfilCCEE"].ToString();
|
dadosTusd.Perfil_CliqCCEE = reader["PerfilCCEE"].ToString();
|
||||||
dadosTusd.Submercado = reader["Submercado"].ToString();
|
dadosTusd.Submercado = reader["Submercado"].ToString();
|
||||||
dadosTusd.Ambiente = reader["Status_unidade"].ToString();
|
dadosTusd.Ambiente = reader["Status_unidade"].ToString();
|
||||||
dadosTusd.Grupo = reader["Grupo"].ToString();
|
dadosTusd.Grupo = reader["Grupo"].ToString();
|
||||||
dadosTusd.Distribuidora = reader["Distribuidora"].ToString();
|
dadosTusd.Distribuidora = reader["Distribuidora"].ToString();
|
||||||
dadosTusd.ICMS = float.Parse(reader["ICMS_TUSD"].ToString());
|
dadosTusd.ICMS = float.Parse(reader["ICMS_TUSD"].ToString() !);
|
||||||
dadosTusd.Dem_Cont_P = float.Parse(reader["Demanda_P"].ToString());
|
dadosTusd.Dem_Cont_P = float.Parse(reader["Demanda_P"].ToString() !);
|
||||||
dadosTusd.Dem_Cont_FP = float.Parse(reader["Demanda_FP"].ToString());
|
dadosTusd.Dem_Cont_FP = float.Parse(reader["Demanda_FP"].ToString() !);
|
||||||
this.Pasta_middle = reader["Caminho_NFs"].ToString();
|
this.pastaMiddle = reader["Caminho_NFs"].ToString();
|
||||||
|
this.empresa = reader["Cliente"].ToString();
|
||||||
|
this.unidade = reader["Unidade"].ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.Close();
|
reader.Close();
|
||||||
@ -110,14 +106,14 @@
|
|||||||
if (dadosTusd.Cod_Smart_unidade == 0)
|
if (dadosTusd.Cod_Smart_unidade == 0)
|
||||||
{
|
{
|
||||||
this.Status = "UNIDADE CONSUMIDORA NÃO LOCALIZADA NO BD";
|
this.Status = "UNIDADE CONSUMIDORA NÃO LOCALIZADA NO BD";
|
||||||
this.UC = uc;
|
this.uc = uc;
|
||||||
this.Mes = dadosTusd.Mes;
|
this.mes = dadosTusd.Mes;
|
||||||
}
|
}
|
||||||
else if (tusdLanc)
|
else if (tusdLanc)
|
||||||
{
|
{
|
||||||
this.Status = "FATURA DUPLICADA NO BD";
|
this.Status = "FATURA DUPLICADA NO BD";
|
||||||
this.UC = uc;
|
this.uc = uc;
|
||||||
this.Mes = dadosTusd.Mes;
|
this.mes = dadosTusd.Mes;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -131,8 +127,8 @@
|
|||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
// PIS e Cofins
|
// PIS e Cofins
|
||||||
dadosTusd.PIS = float.Parse(reader["PIS"].ToString());
|
dadosTusd.PIS = float.Parse(reader["PIS"].ToString() !);
|
||||||
dadosTusd.COFINS = float.Parse(reader["COFINS"].ToString());
|
dadosTusd.COFINS = float.Parse(reader["COFINS"].ToString() !);
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.Close();
|
reader.Close();
|
||||||
@ -160,6 +156,7 @@
|
|||||||
|
|
||||||
// Loop entre os dados faturados na fatura
|
// Loop entre os dados faturados na fatura
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
StringBuilder insertOthers = new StringBuilder();
|
||||||
foreach (Item item in parsedResult.items)
|
foreach (Item item in parsedResult.items)
|
||||||
{
|
{
|
||||||
switch (item.type, item.period)
|
switch (item.type, item.period)
|
||||||
@ -208,18 +205,20 @@
|
|||||||
case ("other", _):
|
case ("other", _):
|
||||||
j++;
|
j++;
|
||||||
|
|
||||||
// Exclui os items lançados anteriormente para a fatura
|
// Exclui os items lançados anteriormente para a fatura e cria a instrução SQL para inserir os novos items
|
||||||
if (j == 1)
|
if (j == 1)
|
||||||
{
|
{
|
||||||
string deleteOthers = $"DELETE FROM Dados_TUSD_aux WHERE Cod_TUSD = {dadosTusd.Cod_TUSD}";
|
string deleteOthers = $"DELETE FROM Dados_TUSD_aux WHERE Cod_TUSD = {dadosTusd.Cod_TUSD}";
|
||||||
cmd.CommandText = deleteOthers;
|
cmd.CommandText = deleteOthers;
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
insertOthers.Append("INSERT INTO Dados_TUSD_aux (Cod_TUSD,Id,Nome,Valor,Cod_lanc) VALUES (" + dadosTusd.Cod_TUSD + "," + j + ",'" + item.name + "'," + item.charge.ToString(new CultureInfo("en-US")) + "," + 0 + ")");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
insertOthers.Append(",(" + dadosTusd.Cod_TUSD + "," + j + ",'" + item.name + "'," + item.charge.ToString(new CultureInfo("en-US")) + "," + 0 + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insere os novos items
|
|
||||||
string insertOthers = "INSERT INTO Dados_TUSD_aux (Cod_TUSD,Id,Nome,Valor,Cod_lanc) VALUES (" + dadosTusd.Cod_TUSD + "," + j + ",'" + item.name + "'," + item.charge.ToString(new CultureInfo("en-US")) + "," + 0 + ")";
|
|
||||||
cmd.CommandText = insertOthers;
|
|
||||||
cmd.ExecuteNonQuery();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,6 +287,10 @@
|
|||||||
updateSQL.Append($" WHERE Cod_TUSD = {dadosTusd.Cod_TUSD}");
|
updateSQL.Append($" WHERE Cod_TUSD = {dadosTusd.Cod_TUSD}");
|
||||||
cmd.CommandText = updateSQL.ToString();
|
cmd.CommandText = updateSQL.ToString();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
// Inseri os itens classificados como "othes" após criar o registro da TUSD devido as relação entre as tabelas
|
||||||
|
cmd.CommandText = insertOthers.ToString();
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -334,11 +337,15 @@
|
|||||||
|
|
||||||
cmd.CommandText = insertSQL.ToString();
|
cmd.CommandText = insertSQL.ToString();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
// Inseri os itens classificados como "othes" após criar o registro da TUSD devido as relação entre as tabelas
|
||||||
|
cmd.CommandText = insertOthers.ToString();
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Status = "FATURA INCLUIDA NO BD";
|
this.Status = "FATURA INCLUIDA NO BD";
|
||||||
this.UC = uc;
|
this.uc = uc;
|
||||||
this.Mes = dadosTusd.Mes;
|
this.mes = dadosTusd.Mes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,27 +354,21 @@
|
|||||||
switch (this.Status)
|
switch (this.Status)
|
||||||
{
|
{
|
||||||
case "UNIDADE CONSUMIDORA NÃO LOCALIZADA NO BD":
|
case "UNIDADE CONSUMIDORA NÃO LOCALIZADA NO BD":
|
||||||
|
this.Arquivo!.MoveTo(this.Arquivo.Directory?.Parent?.FullName + $@"\5 - {this.Status}\ID: {this.id!} - Mês: {this.mes} - UC: {this.uc} - {this.Arquivo.Name}");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "FATURA DUPLICADA NO BD":
|
case "FATURA DUPLICADA NO BD":
|
||||||
|
this.Arquivo!.MoveTo(this.Arquivo.Directory?.Parent?.FullName + $@"\4 - {this.Status}\ID: {this.id!} - Mês: {this.mes} - Empresa: {this.empresa} - Unidade: {this.unidade}");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "FATURA INCLUIDA NO BD":
|
case "FATURA INCLUIDA NO BD":
|
||||||
|
this.Arquivo!.MoveTo(this.Arquivo.Directory?.Parent?.FullName + $@"\6 - {this.Status}\ID: {this.id!} - Mês: {this.uc} - Empresa: {this.empresa} - Unidade: {this.unidade}");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "INVALID":
|
case "INVALID":
|
||||||
|
this.Arquivo!.MoveTo(this.Arquivo.Directory?.Parent?.FullName + $@"\7 - ERRO\ID: {this.id!} - {this.Arquivo.Name}");
|
||||||
break;
|
|
||||||
|
|
||||||
case "DELAYED":
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpResponseMessage GetStatus(HttpClient httpClient, string token, string id)
|
private HttpResponseMessage GetStatus(HttpClient httpClient, string token, string id)
|
||||||
|
|||||||
@ -46,9 +46,8 @@
|
|||||||
if (fatura.Status == "SUCCESS" & !fatura.Agrupada)
|
if (fatura.Status == "SUCCESS" & !fatura.Agrupada)
|
||||||
{
|
{
|
||||||
fatura.Processar(cmd);
|
fatura.Processar(cmd);
|
||||||
|
fatura.Mover();
|
||||||
sw.WriteLine(fatura_ID + "," + fatura.Status + "," + fatura_arquivo);
|
sw.WriteLine(fatura_ID + "," + fatura.Status + "," + fatura_arquivo);
|
||||||
|
|
||||||
// mover_fatura(fatura_processamento, fatura_arquivo);
|
|
||||||
}
|
}
|
||||||
else if (fatura.Status == "SUCCESS" & fatura.Agrupada)
|
else if (fatura.Status == "SUCCESS" & fatura.Agrupada)
|
||||||
{
|
{
|
||||||
@ -59,24 +58,24 @@
|
|||||||
if (faturaIndividual.Status == "SUCCESS")
|
if (faturaIndividual.Status == "SUCCESS")
|
||||||
{
|
{
|
||||||
faturaIndividual.Processar(cmd);
|
faturaIndividual.Processar(cmd);
|
||||||
|
fatura.Mover();
|
||||||
sw.WriteLine(individual_ID.ToString() + "," + faturaIndividual.Status + "," + fatura_arquivo);
|
sw.WriteLine(individual_ID.ToString() + "," + faturaIndividual.Status + "," + fatura_arquivo);
|
||||||
faturaIndividual.Mover();
|
|
||||||
// mover fatura
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sw.WriteLine(individual_ID.ToString() + "," + faturaIndividual.Status + "," + fatura_arquivo);
|
sw.WriteLine(individual_ID.ToString() + "," + faturaIndividual.Status + "," + fatura_arquivo);
|
||||||
|
fatura.Mover();
|
||||||
// mover fatura
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (fatura.Status == "INVALID")
|
||||||
|
{
|
||||||
|
fatura.Mover();
|
||||||
|
sw.WriteLine(fatura_ID + "," + fatura.Status + "," + fatura_arquivo);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sw.WriteLine(fatura_ID + "," + fatura.Status + "," + fatura_arquivo);
|
sw.WriteLine(fatura_ID + "," + fatura.Status + "," + fatura_arquivo);
|
||||||
|
|
||||||
// mover fatura
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user