I'd like to know how to increase the expiration date of a purchase. Example: the person made a purchase, and placed the due date for the 30th of March, so the date of the second installment would be April 29th. Follow the function and the HTML code.
<ion-card *ngFor="let p of parcelasCobranca; let i = index">
Parcela
<ion-item>
<ion-label stacked>Valor: {{ valorParcela }}</ion-label>
</ion-item>
<ion-item>
<ion-label stacked>Data de vencimento *</ion-label>
<ion-input type="date" formControlName="due_date" name="due_date" id="due_date"></ion-input>
</ion-item>
<ion-item *ngIf="due_date.hasError('required') && due_date.touched">
<p>Digite a data *</p>
</ion-item>
</ion-card>
parcelas() {
this.parcelasCobranca = [];
this.valorParcela = this.amount / this.quantidadeParcelas;
for (let i = 0; i < this.quantidadeParcelas; i++) {
this.parcelasCobranca.push({
due_date:this.due_date.value,
value: this.valorParcela,
});
}
console.log(this.parcelasCobranca)
}
Update 1 - follow the other code I made, the due date is going back a few days.
parcelas() {
this.parcelasCobranca = [];
this.valorParcela = this.amount / this.quantidadeParcelas;
let someDate = new Date(this.due_date.value);
for (let i = 0; i < this.quantidadeParcelas; i++) {
someDate.setDate(someDate.getDate() + 30);
let dd = someDate.getDate();
let mm = someDate.getMonth();
let y = someDate.getFullYear();
let someFormattedDate = dd + '-' + mm + '-' + y;
this.parcelasCobranca.push({
due_date: someFormattedDate,
value: this.valorParcela,
});
}
console.log(this.parcelasCobranca)
}
<ion-grid [hidden]="!value">
<ion-card *ngFor="let p of parcelasCobranca; let i = index">
Parcela
<ion-item>
<ion-label stacked>Valor: {{ valorParcela }}</ion-label>
</ion-item>
<ion-item>
<ion-label stacked>Data de vencimento *</ion-label>
<ion-input type="date" formControlName="due_date" name="due_date" id="due_date"></ion-input>
</ion-item>
<ion-item *ngIf="due_date.hasError('required') && due_date.touched">
<p>Digite a data *</p>
</ion-item>
</ion-card>
</ion-grid>