Partage
  • Partager sur Facebook
  • Partager sur Twitter

comment calculer le prix total

comment calculer le prix total

26 mars 2023 à 18:06:12

hello my community

I want to calculate the total price of my card, according to the following formula price unit * qty unit of each line and at the end have the total of the card

this is my Model

export class CdmdetailModel{ idref!:string; designation!:string; qte!:number; price!:number; reduction!:number; puht!:number }

in my car, I have a list of products

detailItem: CdmdetailModel[] = [];

**here a i add item in my detailItem card **

addToCart() { let lcom = new CdmdetailModel(this.refech,this.designation,this.qteech,this.priceech,this.reductionech) this.detailItem.push(lcom) this.toastrService.showSuccess('Ajouté au commande') this.addbtn=false this.clear() this.totalQuantity = this.detailItem.length this.clculPritotal1() }

I created two methods to try to obtain the total value of the card with this method,

1.Method

clculPritotal(){ for (let index = 0; index < this.detailItem.length; index++) { this.totalPriceCalcul.push(this.detailItem[index].price * this.detailItem[index].qte ) } const reducer = (accumulator:any,currentValue:any)=>accumulator+currentValue; this.totprice = this.totalPriceCalcul.reduce(reducer,0) console.log('Tot method 1', this.totprice ) }2.Method

`clculPritotal1(){this.detailItem.map((lc)=>{this.totprice += lc.price*lc.qteconsole.log('Tot method 2', this.totprice )})

`

can someone help me?

  • Partager sur Facebook
  • Partager sur Twitter
27 mars 2023 à 14:37:05 - Message modéré pour le motif suivant : Toute forme de publicité est interdite