-2
I have this select
which brings back the data as follows, if DataCobranca
for 10, and today is day 05, it will pick up all customers that is day 10, as it will be generated 5 days before, or case DiaEspecificoMarcar
for true
and DiaEspecifico
is the same as today, it will also appear in this select
var contrato = db
.Contrato
.Include(a => a.PedidoVenda)
.Include(a => a.Cliente)
.Where(a => a.PedidoVenda.EmpresaID == model.EmpresaID &&
a.Cancelado == false &&
DateTime.Parse(a.PrimeiraCobranca.ToString("dd/MM/yyyy")) >= DateTime.Parse(DateTime.Now.ToString("dd/MM/yyyy")) &&
a.DiaEspecificoMarcar == true && a.DiaEspecifico == int.Parse(DateTime.Now.ToString("dd"))) ||
(a.DiaEspecificoMarcar == false && (int.Parse(a.DataCobranca.Substring(1, 2)) - a.PedidoVenda.Empresa.DataProcessamentoNota) == int.Parse(DateTime.Now.ToString("dd")))
).ToList();
Only when the DataCobranca
for 05, it needs to be generated 5 days before, or as long as it is in the parameter, so as I am using retroactive date, on 31/03 and on 01/04, where I should pull those of day 05, but it always pulls zeroed.
In fact, because the DataCobranca = 5
, and the DataProcessamentoNota = 5
, as he does the account, he checks 5-5 = 0, in case he should take the last day of the month, or else if DataProcessamentoNota = 10
it should do the count 5 - 10, and then it would be -5. The result should be 10 days earlier. How to calculate as days same. How can I verify?
DateTime.Parse(a.PrimeiraCobranca.ToString("dd/MM/yyyy"))
, what is this crazy parse? the first Obranca is not a datetime? type and also what makes it nothing? See problems in your code– novic
@Virgilionovic I need to check if the date of the first charge is greater than or equal to the day being generated. is yes, I’m only getting the date, not the time.
– Mariana
@Virgilionovic until then when it doesn’t get negative works, I need to do the part of
int.Parse(a.DataCobranca.Substring(1, 2)) - a.PedidoVenda.Empresa.DataProcessamentoNota
which is the one that’s giving problems when it generates a negative, because it’s being treated asint
and notDateTime
– Mariana
Mariana a.Primeiracobranca is the type
DateTime
? What is the version ofEntityFramework
? if it is not how you do it !– novic
Yeah, it’s kind of
DateTime
, the version of Entityframeworkcore is2.1.4
– Mariana
your conversions are all wrong! that’s the problem too, and another subject generates conversions at the customer level is bad this search.
– novic
Here you need to catch the day?
a.DataCobranca.Substring(1, 2)
???? the correct isa.DataCobranca.Day
internally he makes the conversion.– novic
In case the
DataCobranca
is a string type, it saves T05, T10, etc, so I use theSubstring
to get both numbers.– Mariana
where you did it:
DateTime.Parse(a.PrimeiraCobranca.ToString("dd/MM/yyyy"))
that’s alla.PrimeiraCobranca.Date
.– novic
int.Parse(DateTime.Now.ToString("dd"))
it’s justDateTime.Now.Day
– novic
then this can stay as it is!
DataCobranca
– novic
I’ll give you a hint! Do a search with type 10 only and then do one with type 5, narrow it down that way. If you need to put these two together at the end it’s easy, but the way you’re very confused understand until your question ... !!!
– novic
@Virgilionovic but until then does not solve my problem, since the problem is here
int.Parse(a.DataCobranca.Substring(1, 2)) - a.PedidoVenda.Empresa.DataProcessamentoNota
, what you gave me improves the code, but it doesn’t solve the problem.– Mariana
The code improvement was good for you to see the wrong path you were taking, but, uh, along that line
int.Parse(a.DataCobranca.Substring(1, 2)) - a.PedidoVenda.Empresa.DataProcessamentoNota
has another problem, but, tell me what’s wrong with this line?– novic
The problem is date, he’s comparing to
DataCobranca = T10
with theDataProcessamentoNota = 5
, or by taking theSubstring
10 - 5 = 5 he would know that to generate the note on day 5, now when it is smaller, for exampleDataCobranca = T05
andDataProcessamentoNota = 05
05-05 he would give 0, or 05-10 = -5, which he will compare with the current day, to see if it is the correct day, in case 05-05, he should generate on the last day of the previous month, and 05-10, he should generate on day 26. I don’t know if you understand.– Mariana