Skip to content

Commit

Permalink
#790 - Adding KG price
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Sep 8, 2024
1 parent e54913e commit a66a996
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
</ion-col>
<ion-col *ngIf="bean?.cost > 0 && uiBeanHelper.fieldVisible(settings.bean_visible_list_view_parameters.cost)" size="6">
<ion-label class="card-headline">{{'BEAN_DATA_COST' | translate}}</ion-label><br/>
<ion-text>{{bean?.cost}}</ion-text>
<ion-text>{{bean?.cost}}<span *ngIf='showCostPerKG()'>&nbsp;({{calculateCostPerKG()}}{{getCurrencySymbol()}} / kg)</span></ion-text>
</ion-col>
<ion-col *ngIf="bean?.cupping_points !== '' && uiBeanHelper.fieldVisible(settings.bean_visible_list_view_parameters.cupping_points)" size="6">
<ion-label class="card-headline">{{'BEAN_DATA_CUPPING_POINTS' | translate}}</ion-label><br/>
Expand Down
33 changes: 31 additions & 2 deletions src/components/bean-information/bean-information.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import { BeanMapper } from '../../mapper/bean/beanMapper';
import { ServerCommunicationService } from '../../services/serverCommunication/server-communication.service';
import { UIHelper } from '../../services/uiHelper';
import { TranslateService } from '@ngx-translate/core';
import BREW_TRACKING from '../../data/tracking/brewTracking';
import * as htmlToImage from 'html-to-image';
import { UIBrewHelper } from '../../services/uiBrewHelper';
import moment from 'moment/moment';
import { BEAN_FREEZING_STORAGE_ENUM } from '../../enums/beans/beanFreezingStorage';
import { CurrencyService } from '../../services/currencyService/currency.service';

@Component({
selector: 'bean-information',
Expand Down Expand Up @@ -81,7 +81,8 @@ export class BeanInformationComponent implements OnInit {
private readonly translate: TranslateService,
private readonly platform: Platform,
private readonly uiBrewHelper: UIBrewHelper,
private actionSheetCtrl: ActionSheetController
private actionSheetCtrl: ActionSheetController,
private readonly currencyService: CurrencyService
) {
this.settings = this.uiSettingsStorage.getSettings();
}
Expand Down Expand Up @@ -542,4 +543,32 @@ export class BeanInformationComponent implements OnInit {
}
return false;
}

public showCostPerKG(): boolean {
if (
this.bean.weight &&
this.bean.weight > 0 &&
this.bean.weight !== 1000 &&
this.bean.cost &&
this.bean.cost > 0
) {
return true;
}
return false;
}
public getCurrencySymbol() {
return this.currencyService.getActualCurrencySymbol();
}

public calculateCostPerKG() {
const beanWeight = this.bean.weight;
const beanCost = this.bean.cost;

const costPerGramm = this.uiHelper.toFixedIfNecessary(
beanCost / beanWeight,
2
);
const kgCost = costPerGramm * 1000;
return kgCost;
}
}

0 comments on commit a66a996

Please sign in to comment.