For my current project, I am working on generating an invoice. I have implemented a function called get subtotal(){}
to calculate the total value of the invoice, and it is functioning correctly. However, I encountered an issue where I need to apply a discount from 100 to 90 to the subtotal.
I attempted to modify the code but it did not produce the desired result. Could you please provide me with suggestions on how to resolve this problem? Here is the HTML code:
<div class="input-field col s2" style="float: right;">
<input formControlName="Subtotal " id="Subtotal " [value]="subtotal " type="number" class="validate" (change)="updateForm($event)">
</div>
And here is the TypeScript code:
updateForm(event) {
console.log(event)
let updatedAmount = event.target.value
this.addsale['controls']['Subtotal '].setValue(updatedAmount );
}
onaddsale() {
let sale = this.addsale.value;
sale.Subtotal = this.subtotal;
let newSale = new Sale(sale);
console.log(newSale)}
get subtotal() {
return this.products
.map(p => p.p_Unit_price * p.p_Quantity)
.reduce((a, b) => a + b, 0);
}
Thank you for your assistance!
Update:
this.addsale = this.formbuilder.group({
'Subtotal ': new FormControl('', Validators.required),
'products': this.formbuilder.array([]),
});