private async void OnAddSalaryFunc() { AddMoneyDescription = CrossSettings.Current.GetValueOrDefault("AddMoneyMessage", ""); AddMoneyValue = CrossSettings.Current.GetValueOrDefault("AddMoneyValue", 0.0m); SelectedCategory = UnwrapAddingCategoryType(CrossSettings.Current.GetValueOrDefault("SelectedAddingCategory", 0)); var item = new Transaction { Id = ++lastID, Value = AddMoneyValue, Note = AddMoneyDescription, Date = DateTime.Now, Type = TransactionType.Add, Category = SelectedCategory, MathSymbol = '+' }; switch (CrossSettings.Current.GetValueOrDefault("CurrentAddedMoneyTo", 0)) { case 0: CurrentCash += item.Value; item.Bill = TransactionBill.Cash; _moneyService.SetCurrentCash(CurrentCash); break; case 1: CurrentCard += item.Value; item.Bill = TransactionBill.Card; _moneyService.SetCurrentCard(CurrentCard); break; } _ = _transactionService.Create(item); LastTransactionsList.Clear(); GetData(); }
private async void OnSaveFunc() { SaveDescription = CrossSettings.Current.GetValueOrDefault("SaveMessage", ""); SaveValue = CrossSettings.Current.GetValueOrDefault("SaveValue", 0.0m); SelectedCategory = UnwrapSaveCategoryType(CrossSettings.Current.GetValueOrDefault("SelectedSaveCategory", 0)); switch (SelectedCategory.Type) { case CategoryType.Save: var transaction = new Transaction { Id = ++lastID, Value = SaveValue, Note = SaveDescription, Date = DateTime.Now, Type = TransactionType.Save, Category = SelectedCategory, MathSymbol = '-' }; switch (CrossSettings.Current.GetValueOrDefault("CurrentAddedMoneyTo", 0)) { case 0: if (SaveValue > CurrentCash) { await PopupNavigation.Instance.PushAsync(new AlertPopupView(Strings["alert_no_cash_save"]), true); return; } CurrentCash -= transaction.Value; CurrentAllSavings += transaction.Value; _moneyService.SetCurrentCash(CurrentCash); _moneyService.SetAllSavings(CurrentAllSavings); transaction.Bill = TransactionBill.Cash; break; case 1: if (SaveValue > CurrentCard) { await PopupNavigation.Instance.PushAsync(new AlertPopupView(Strings["alert_no_card_save"]), true); return; } CurrentCard -= transaction.Value; CurrentAllSavings += transaction.Value; _moneyService.SetCurrentCard(CurrentCard); _moneyService.SetAllSavings(CurrentAllSavings); transaction.Bill = TransactionBill.Card; break; } _ = _transactionService.Create(transaction); break; case CategoryType.Take: if (SaveValue > CurrentAllSavings) { await PopupNavigation.Instance.PushAsync(new AlertPopupView(Strings["alert_no_savings"]), true); return; } var item = new Transaction { Id = ++lastID, Value = SaveValue, Note = SaveDescription, Date = DateTime.Now, Type = TransactionType.Save, Category = SelectedCategory, MathSymbol = '+' }; switch (CrossSettings.Current.GetValueOrDefault("CurrentAddedMoneyTo", 0)) { case 0: CurrentCash += item.Value; CurrentAllSavings -= item.Value; _moneyService.SetCurrentCash(CurrentCash); _moneyService.SetAllSavings(CurrentAllSavings); item.Bill = TransactionBill.Cash; break; case 1: CurrentCard += item.Value; CurrentAllSavings -= item.Value; _moneyService.SetCurrentCard(CurrentCard); _moneyService.SetAllSavings(CurrentAllSavings); item.Bill = TransactionBill.Card; break; } _ = _transactionService.Create(item); break; default: break; } LastTransactionsList.Clear(); GetData(); }
private async void OnBankFunc() { CreditDescription = CrossSettings.Current.GetValueOrDefault("CreditMessage", ""); CreditValue = CrossSettings.Current.GetValueOrDefault("CreditValue", 0.0m); SelectedCategory = UnwrapBankCategoryType(CrossSettings.Current.GetValueOrDefault("SelectedBankCategory", 0)); switch (SelectedCategory.Type) { case CategoryType.Lend: var transaction = new Transaction { Id = ++lastID, Value = CreditValue, Note = CreditDescription, Date = DateTime.Now, Type = TransactionType.Bank, Category = SelectedCategory, MathSymbol = '+' }; switch (CrossSettings.Current.GetValueOrDefault("CurrentAddedMoneyTo", 0)) { case 0: CurrentCash += transaction.Value; CurrentCredit += transaction.Value; _moneyService.SetCurrentCash(CurrentCash); _moneyService.SetCurrentCredit(CurrentCredit); transaction.Bill = TransactionBill.Cash; break; case 1: CurrentCard += transaction.Value; CurrentCredit += transaction.Value; _moneyService.SetCurrentCard(CurrentCard); _moneyService.SetCurrentCredit(CurrentCredit); transaction.Bill = TransactionBill.Card; break; } _ = _transactionService.Create(transaction); break; case CategoryType.Repay: if (CurrentCredit <= 0) { await PopupNavigation.Instance.PushAsync(new AlertPopupView(Strings["alert_no_credit"]), true); return; } var item = new Transaction { Id = ++lastID, Value = CreditValue, Note = CreditDescription, Date = DateTime.Now, Type = TransactionType.Bank, Category = SelectedCategory, MathSymbol = '-' }; switch (CrossSettings.Current.GetValueOrDefault("CurrentAddedMoneyTo", 0)) { case 0: if (CreditValue > CurrentCash) { await PopupNavigation.Instance.PushAsync(new AlertPopupView(Strings["alert_no_cash_bank"]), true); return; } if (CreditValue > CurrentCredit) { item.Value = CurrentCredit; } CurrentCash -= item.Value; CurrentCredit -= item.Value; _moneyService.SetCurrentCash(CurrentCash); _moneyService.SetCurrentCredit(CurrentCredit); item.Bill = TransactionBill.Cash; break; case 1: if (CreditValue > CurrentCard) { await PopupNavigation.Instance.PushAsync(new AlertPopupView(Strings["alert_no_card_bank"]), true); return; } if (CreditValue > CurrentCredit) { item.Value = CurrentCredit; } CurrentCard -= item.Value; CurrentCredit -= item.Value; _moneyService.SetCurrentCard(CurrentCard); _moneyService.SetCurrentCredit(CurrentCredit); item.Bill = TransactionBill.Card; break; } _ = _transactionService.Create(item); break; default: break; } LastTransactionsList.Clear(); GetData(); }
private async void OnSpendFunc() { SpendDescription = CrossSettings.Current.GetValueOrDefault("CommitMessage", ""); SelectedCategory = UnwrapSpendingCategoryType(CrossSettings.Current.GetValueOrDefault("SelectedSpendingCategory", 0)); var item = new Transaction { Id = ++lastID, Value = decimal.Parse(SpendValue), Note = SpendDescription, Date = DateTime.Now, Type = TransactionType.Spend, Category = SelectedCategory, MathSymbol = '-' }; switch (CrossSettings.Current.GetValueOrDefault("CurrentCommitMoneyFrom", 0)) { case 0: if (item.Value > CurrentCash) { if (!IsMinusAllowed) { await PopupNavigation.Instance.PushAsync(new AlertPopupView(Strings["alert_no_cash"]), true); return; } else { CurrentCredit += item.Value; _moneyService.SetCurrentCredit(CurrentCredit); } } else { CurrentCash -= item.Value; _moneyService.SetCurrentCash(CurrentCash); } item.Bill = TransactionBill.Cash; break; case 1: if (item.Value > CurrentCard) { if (!IsMinusAllowed) { await PopupNavigation.Instance.PushAsync(new AlertPopupView(Strings["alert_no_card"]), true); return; } else { CurrentCredit += item.Value; _moneyService.SetCurrentCredit(CurrentCredit); } } else { CurrentCard -= item.Value; _moneyService.SetCurrentCard(CurrentCard); } item.Bill = TransactionBill.Card; break; } _ = _transactionService.Create(item); LastTransactionsList.Clear(); SpendValue = ""; GetData(); }
private async void DeleteNoteFunc() { if (ChoicedNote.Date.Month != DateTime.Now.Month && ChoicedNote.Date.Year != DateTime.Now.Year) { } if (ChoicedNote.Bill == TransactionBill.Cash) { if (CurrentCash < ChoicedNote.Value) { await PopupNavigation.Instance.PushAsync(new AlertPopupView(Strings["alert_no_cash_delete"]), true); return; } } else { if (CurrentCard < ChoicedNote.Value) { await PopupNavigation.Instance.PushAsync(new AlertPopupView(Strings["alert_no_card_delete"]), true); return; } } if (await _transactionService.Delete(ChoicedNote.Id)) { LastTransactionsList.Remove(ChoicedNote); switch (ChoicedNote.MathSymbol) { case '+': if (ChoicedNote.Bill == TransactionBill.Cash) { _moneyService.SetCurrentCash(CurrentCash - ChoicedNote.Value); if (ChoicedNote.Type == TransactionType.Bank) { _moneyService.SetCurrentCredit(CurrentCash - ChoicedNote.Value); } } else { _moneyService.SetCurrentCard(CurrentCard - ChoicedNote.Value); if (ChoicedNote.Type == TransactionType.Bank) { _moneyService.SetCurrentCredit(CurrentCard - ChoicedNote.Value); } } break; case '-': if (ChoicedNote.Bill == TransactionBill.Cash) { _moneyService.SetCurrentCash(CurrentCash + ChoicedNote.Value); if (ChoicedNote.Type == TransactionType.Bank) { _moneyService.SetCurrentCredit(CurrentCash + ChoicedNote.Value); } } else { _moneyService.SetCurrentCard(CurrentCard + ChoicedNote.Value); if (ChoicedNote.Type == TransactionType.Bank) { _moneyService.SetCurrentCredit(CurrentCard + ChoicedNote.Value); } } break; default: break; } GetData(); } }