1
I have this function that when starting with T
it will generate invoice for every day, example: if you have T10
will generate every day 10 as specified in the form of payment.
Currently being done this way:
if (vf.Substring(0, 1) == "T")
{
var par = vf.Substring(1, 2);
for (int i = 1; i <= parcelas; i++)
{
var venc = new FaturaContasReceber
{
FaturaContasReceberPId = idfatura,
DataFatura = DateTime.Now,
DiasAtraso = totalDia,
Data = DateTime.Parse(par + "/" + DateTime.Now.AddMonths(i).ToString("MM") + "/" + DateTime.Now.ToString("yyyy")),
DataPagamento = datapagamento,
Valor = valor1,
Total = saldo,
Saldo = saldo,
Quitado = quitado,
Caixa = caixa,
};
db.Add(venc);
db.SaveChanges();
saldo = 0;
}
}
The problem that generating today for example, with every day 10, it is generating for the day 10/05
, where the correct would be for the day 10/04
. How can I do this date check ? Because currently I am 1 month
Using the logic of an added answer to this question, I made some changes and stayed this way:
if (DateTime.Now.Day < Convert.ToInt32(par) && i == 1)
{
datavenc = DateTime.Parse(par + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("yyyy"));
}
else
{
datavenc = DateTime.Parse(par + "/" + DateTime.Now.AddMonths(i - 1).ToString("MM") + "/" + DateTime.Now.ToString("yyyy"));
}
Only that so generates for the day 10/04 and jumps to the 10/06 and not 10/05.
A comment that has nothing to do with the question, but has to do with the code: If we have in the month 12 and have 2 installments, it would not be "dd/12/2019" and "dd/01/2019", and the correct one would be "dd/01/2020"?
– Focos
Regarding the question: If you change the
int i = 1
forint i = 0
, would probably generate on 10/04.– Focos
@Focuses in the case if it is every day, it is all next day 10, if it is another type of condition there should be chosen another.
– Mariana
@Focuses if I start at zero, instead of generating 2 times, would generate 3 times, for this reason starts at 1.
– Mariana
But then you put
i <= parcelas - 1
.– Focos
Or simply i < parcels
– Deividson Oliveira