Skip to content

Commit

Permalink
#818 - Tackle the green bean weight will be splitted aswell
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Oct 20, 2024
1 parent 96a1c13 commit 6ccb108
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
44 changes: 40 additions & 4 deletions src/app/beans/bean-popover-freeze/bean-popover-freeze.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Config } from '../../../classes/objectConfig/objectConfig';
import { UIBeanStorage } from '../../../services/uiBeanStorage';
import { UIAlert } from '../../../services/uiAlert';
import { BeanPopoverFrozenListComponent } from '../bean-popover-frozen-list/bean-popover-frozen-list.component';
import { BEAN_ROASTING_TYPE_ENUM } from '../../../enums/beans/beanRoastingType';
import { BEAN_FREEZING_STORAGE_ENUM } from '../../../enums/beans/beanFreezingStorage';

declare var cordova;
Expand Down Expand Up @@ -42,6 +41,7 @@ export class BeanPopoverFreezeComponent implements OnInit {

public allNewCreatedBeans: Array<Bean> = [];
public readonly beanFreezingStorageEnum = BEAN_FREEZING_STORAGE_ENUM;

constructor(
private readonly modalController: ModalController,
private readonly uiSettingsStorage: UISettingsStorage,
Expand Down Expand Up @@ -96,14 +96,28 @@ export class BeanPopoverFreezeComponent implements OnInit {

let index = 1;

const groupBeanId = this.uiHelper.generateUUID();
//If burnInPercentage is set, we know its a roasted one.
let burnInPercentage = 0;
if (this.bean.bean_roast_information.green_bean_weight > 0) {
//250
const originalWeight = this.bean.weight;
//220
const originalGreenBeanWeight =
this.bean.bean_roast_information.green_bean_weight;

//Example 12%

burnInPercentage = 100 - (originalWeight * 100) / originalGreenBeanWeight;
}

const groupBeanId = this.uiHelper.generateUUID();
for await (const bag of this.addedBags) {
await this.__createNewFrozenBean(
bag.weight,
bag.type,
index,
groupBeanId
groupBeanId,
burnInPercentage
);
index = index + 1;
}
Expand All @@ -129,6 +143,13 @@ export class BeanPopoverFreezeComponent implements OnInit {
this.bean.cost = 0;
}

if (this.bean.bean_roast_information.green_bean_weight > 0) {
const newGreenBeanWeight =
this.bean.weight + this.bean.weight * (burnInPercentage / 100);
this.bean.bean_roast_information.green_bean_weight =
this.uiHelper.toFixedIfNecessary(newGreenBeanWeight, 2);
}

//Don't delete the bean, because we did brews with this
this.bean.frozenGroupId = groupBeanId;
await this.uiBeanStorage.update(this.bean);
Expand Down Expand Up @@ -174,6 +195,13 @@ export class BeanPopoverFreezeComponent implements OnInit {
this.bean.cost = 0;
}

if (this.bean.bean_roast_information.green_bean_weight > 0) {
const newGreenBeanWeight =
this.bean.weight + this.bean.weight * (burnInPercentage / 100);
this.bean.bean_roast_information.green_bean_weight =
this.uiHelper.toFixedIfNecessary(newGreenBeanWeight, 2);
}

this.bean.frozenGroupId = groupBeanId;
await this.uiBeanStorage.update(this.bean);
}
Expand All @@ -191,7 +219,8 @@ export class BeanPopoverFreezeComponent implements OnInit {
_freezingWeight: number,
_freezingType: BEAN_FREEZING_STORAGE_ENUM,
_index: number,
_groupBeanId: string
_groupBeanId: string,
_burnInPercentage: number
) {
const clonedBean: Bean = this.uiHelper.cloneData(this.bean);

Expand All @@ -204,6 +233,13 @@ export class BeanPopoverFreezeComponent implements OnInit {
clonedBean.frozenStorageType = _freezingType;
clonedBean.frozenNote = this.frozenNote;

if (this.bean.bean_roast_information.green_bean_weight > 0) {
const newGreenBeanWeight =
_freezingWeight + _freezingWeight * (_burnInPercentage / 100);
clonedBean.bean_roast_information.green_bean_weight =
this.uiHelper.toFixedIfNecessary(newGreenBeanWeight, 2);
}

if (this.bean.cost !== 0) {
try {
const newCost = this.uiHelper.toFixedIfNecessary(
Expand Down
14 changes: 8 additions & 6 deletions src/services/nfcService/nfc-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ export class NfcService {
private readonly uiHelper: UIHelper,
private readonly uiToast: UIToast
) {
this.uiHelper.isBeanconqurorAppReady().then(async () => {
this.nfcEnabled = await this.getEnabledState();
if (this.isNFCEnabled) {
this.listenToNFCAndroid();
}
});
if (this.platform.is('capacitor')) {
this.uiHelper.isBeanconqurorAppReady().then(async () => {
this.nfcEnabled = await this.getEnabledState();
if (this.isNFCEnabled) {
this.listenToNFCAndroid();
}
});
}
}

public isNFCEnabled() {
Expand Down

0 comments on commit 6ccb108

Please sign in to comment.