Issue
I'm creating a calculator which shows how much the artist has left to pay to the recordcompany. In my code everytime 'artistCosts' reaches 0 it pops back up to the maximum value. This is my code:
// als er bepaalde waarden wijzigen worden de berekeningen opnieuw uitgevoerd
change() {
console.log('change');
this.calculateValues();
}
// wijziging in dealtype
dealtypeChanged(value) {
this.dealType = value;
console.log(this.dealType);
if (this.dealType == 'licentieDeal') {
this.recordingCosts = 0;
this.marketingCosts = 2000;
this.splitArtist = 25;
} else if (this.dealType == 'distributieDeal') {
this.recordingCosts = 0;
this.marketingCosts = 0;
this.splitArtist = 80;
} else if (this.dealType == 'eigenDeal') {
this.splitArtist = 100;
this.artistAdvance = 0;
this.recordingCosts = 0;
this.marketingCosts = 0;
} else {
this.splitArtist = 15;
this.artistAdvance = 2000;
this.recordingCosts = 2000;
this.marketingCosts = 2000;
}
this.change();
}
// berekende en verdeeld kosten tussen label en artiest op basis van recoupable velden
calculateCosts() {
this.artistCosts = 0;
this.labelCosts = this.artistAdvance + this.marketingCosts + this.recordingCosts;
if (this.recoupableArtistAdvance === true) {
this.artistCosts = this.artistCosts + this.artistAdvance;
}
if (this.recoupableMarketingCosts === true) {
this.artistCosts = this.artistCosts + this.marketingCosts;
}
if (this.recoupableRecordingCosts === true) {
this.artistCosts = this.artistCosts + this.recordingCosts;
}
}
// Distributes revenue between artist and label via split
divideRevenue() {
let artistRevenue = (this.grossRevenue * (this.splitArtist / 100));
let labelRevenue = (this.grossRevenue * (this.splitLabel / 100));
// calculation of royalties label and artist after deduction of costs
if (artistRevenue >= this.artistCosts) {
this.artistBalancedRecouped = 100;
this.artistRoyalty = artistRevenue - this.artistCosts;
} else {
this.artistBalancedRecouped = Math.round((artistRevenue / this.artistCosts) * 100);
this.artistRoyalty = 0;
}
if (labelRevenue >= this.labelCosts) {
this.labelRoyalty = labelRevenue - this.labelCosts;
} else {
this.labelRoyalty = labelRevenue - this.labelCosts;
}
if (this.artistCosts >= this.artistCosts - artistRevenue) {
this.artistCosts = this.artistCosts - artistRevenue;
}
}
How do let I 'artistCosts' stay at 0 when it reaches 0 without popping back up to max value.
Solution
I found it after some troubleshooting, so my calculation was wrong. Still don't know why it doesn't work at the way I made it fist but this part:
if (this.artistCosts >= this.artistCosts - artistRevenue) {
this.artistCosts = this.artistCosts - artistRevenue;
}
I changed it to this:
if (this.artistRoyalty > 0 ) {
this.artistCosts = 0;
} else {
this.artistCosts = this.artistCosts - artistRevenue;
}
Now this.artistCosts will stay also 0 when this.artistRoyalty goes above 0. It doesn't do a calculation anymore of multiple parameters, it just checks if the this.artistRoyalty is above 0. You can't do if (this.artistRoyalty >= 0 ) I don't know why this is, if someone can explain why the first part won't work and why if (this.artistRoyalty >= 0 ) won't work. That would be very helpfull!
Answered By - Gawkky
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.