report page
This commit is contained in:
@ -72,7 +72,7 @@ namespace Billing.Views
|
||||
Task.Run(() =>
|
||||
{
|
||||
var bills = App.Bills.Where(b => Helper.IsSameDay(b.CreateTime, e.Date));
|
||||
Bills = new List<UIBill>(bills.OrderBy(b => b.CreateTime).Select(b => WrapBill(b)));
|
||||
Bills = new List<UIBill>(bills.OrderBy(b => b.CreateTime).Select(b => Helper.WrapBill(b)));
|
||||
RefreshBalance(Bills);
|
||||
MainThread.BeginInvokeOnMainThread(async () => await scrollView.ScrollToAsync(0, 0, true));
|
||||
});
|
||||
@ -88,18 +88,6 @@ namespace Billing.Views
|
||||
SetValue(BalanceProperty, income - spending);
|
||||
}
|
||||
|
||||
private UIBill WrapBill(Bill b)
|
||||
{
|
||||
return new UIBill(b)
|
||||
{
|
||||
Icon = App.Categories.FirstOrDefault(c => c.Id == b.CategoryId)?.Icon ?? BaseModel.ICON_DEFAULT,
|
||||
Name = b.Name,
|
||||
DateCreation = b.CreateTime,
|
||||
Amount = b.Amount,
|
||||
Wallet = App.Accounts.FirstOrDefault(a => a.Id == b.WalletId)?.Name
|
||||
};
|
||||
}
|
||||
|
||||
private void UpdateBill(UIBill bill)
|
||||
{
|
||||
bill.Icon = App.Categories.FirstOrDefault(c => c.Id == bill.Bill.CategoryId)?.Icon ?? BaseModel.ICON_DEFAULT;
|
||||
@ -196,7 +184,7 @@ namespace Billing.Views
|
||||
e.Id = maxId + 1;
|
||||
App.Bills.Add(e);
|
||||
var bills = Bills;
|
||||
bills.Add(WrapBill(e));
|
||||
bills.Add(Helper.WrapBill(e));
|
||||
Bills = bills.OrderBy(b => b.DateCreation).ToList();
|
||||
}
|
||||
else
|
||||
|
@ -15,7 +15,7 @@
|
||||
<Grid>
|
||||
<StackLayout Margin="30, 0, 0, 0" HorizontalOptions="Center" VerticalOptions="Center"
|
||||
Orientation="Horizontal" Spacing="10">
|
||||
<ui:TintImageButton Source="calendar.png" WidthRequest="20" HeightRequest="20"
|
||||
<ui:TintImageButton Source="left.png" WidthRequest="20" HeightRequest="20"
|
||||
VerticalOptions="Center" HorizontalOptions="Start"
|
||||
Command="{Binding LeftCommand}"/>
|
||||
<Label Text="{Binding Title}"
|
||||
@ -35,12 +35,66 @@
|
||||
</Shell.TitleView>
|
||||
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Order="Primary" IconImageSource="plus.png" Command="{Binding FilterCommand}"/>
|
||||
<ToolbarItem Order="Primary" IconImageSource="filter.png" Command="{Binding FilterCommand}"/>
|
||||
</ContentPage.ToolbarItems>
|
||||
|
||||
<ScrollView>
|
||||
<ContentPage.Resources>
|
||||
<ui:NegativeConverter x:Key="negativeConverter"/>
|
||||
<ui:MoneyConverter x:Key="moneyConverter" Absolute="True"/>
|
||||
<ui:BalanceColorConverter x:Key="colorConverter"/>
|
||||
<ui:TimeConverter x:Key="timeConverter"/>
|
||||
<ui:IconConverter x:Key="iconConverter"/>
|
||||
<Style x:Key="titleLabel" TargetType="Label">
|
||||
<Setter Property="FontSize" Value="16"/>
|
||||
<Setter Property="Margin" Value="10, 20, 10, 10"/>
|
||||
<!--<Setter Property="TextColor" Value="{DynamicResource SecondaryTextColor}"/>-->
|
||||
</Style>
|
||||
<Style x:Key="promptLabel" TargetType="Label">
|
||||
<Setter Property="HeightRequest" Value="240"/>
|
||||
<Setter Property="FontSize" Value="15"/>
|
||||
<Setter Property="VerticalOptions" Value="Start"/>
|
||||
<Setter Property="HorizontalTextAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalTextAlignment" Value="Center"/>
|
||||
<Setter Property="TextColor" Value="{DynamicResource SecondaryTextColor}"/>
|
||||
</Style>
|
||||
</ContentPage.Resources>
|
||||
|
||||
<ScrollView x:Name="scroller">
|
||||
<StackLayout>
|
||||
<chart:ChartView HeightRequest="240" Chart="{Binding Chart}"/>
|
||||
<Label Text="{r:Text TrackingChart}" Style="{StaticResource titleLabel}"/>
|
||||
<chart:ChartView HeightRequest="240" Chart="{Binding Chart}"
|
||||
IsVisible="{Binding NoResult, Converter={StaticResource negativeConverter}}"/>
|
||||
<Label Text="{r:Text NoResult}" Style="{StaticResource promptLabel}"
|
||||
IsVisible="{Binding NoResult}"/>
|
||||
|
||||
<Label Text="{r:Text Top10}" Style="{StaticResource titleLabel}"/>
|
||||
<ui:GroupStackLayout IsVisible="{Binding NoResult, Converter={StaticResource negativeConverter}}"
|
||||
ItemsSource="{Binding TopBills}" RowHeight="50">
|
||||
|
||||
<ui:GroupStackLayout.ItemTemplate>
|
||||
<DataTemplate x:DataType="v:UIBill">
|
||||
<Grid Padding="20, 0" ColumnSpacing="10"
|
||||
ColumnDefinitions="Auto, *, Auto" RowDefinitions="Auto, Auto">
|
||||
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
|
||||
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
|
||||
<Label Grid.Column="1" Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
|
||||
VerticalOptions="Center"
|
||||
FontSize="Default" FontAttributes="Bold"/>
|
||||
<Label Grid.Column="2" Text="{Binding Amount, Converter={StaticResource moneyConverter}}"
|
||||
TextColor="{Binding Amount, Converter={StaticResource colorConverter}}"
|
||||
VerticalOptions="Center"/>
|
||||
<StackLayout Grid.Row="1" Grid.Column="1" Spacing="6" Orientation="Horizontal">
|
||||
<Label Text="{Binding DateCreation, Converter={StaticResource timeConverter}}"
|
||||
FontSize="10" TextColor="{DynamicResource SecondaryTextColor}"/>
|
||||
<Label Text="{Binding Wallet}"
|
||||
FontSize="10" TextColor="{DynamicResource SecondaryTextColor}"/>
|
||||
</StackLayout>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ui:GroupStackLayout.ItemTemplate>
|
||||
</ui:GroupStackLayout>
|
||||
<Label Text="{r:Text NoResult}" Style="{StaticResource promptLabel}"
|
||||
IsVisible="{Binding NoResult}"/>
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ui:BillingPage>
|
@ -1,5 +1,4 @@
|
||||
using Billing.Languages;
|
||||
using Billing.Models;
|
||||
using Billing.Models;
|
||||
using Billing.Themes;
|
||||
using Billing.UI;
|
||||
using Microcharts;
|
||||
@ -8,7 +7,10 @@ using SkiaSharp.Views.Forms;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Essentials;
|
||||
using Xamarin.Forms;
|
||||
using Resource = Billing.Languages.Resource;
|
||||
|
||||
namespace Billing.Views
|
||||
{
|
||||
@ -16,6 +18,7 @@ namespace Billing.Views
|
||||
{
|
||||
private static readonly BindableProperty ChartProperty = Helper.Create<Chart, RankPage>(nameof(Chart));
|
||||
private static readonly BindableProperty TopBillsProperty = Helper.Create<IList<UIBill>, RankPage>(nameof(TopBills));
|
||||
private static readonly BindableProperty NoResultProperty = Helper.Create<bool, RankPage>(nameof(NoResult));
|
||||
|
||||
public Chart Chart
|
||||
{
|
||||
@ -27,6 +30,11 @@ namespace Billing.Views
|
||||
get => (IList<UIBill>)GetValue(TopBillsProperty);
|
||||
set => SetValue(TopBillsProperty, value);
|
||||
}
|
||||
public bool NoResult
|
||||
{
|
||||
get => (bool)GetValue(NoResultProperty);
|
||||
set => SetValue(NoResultProperty, value);
|
||||
}
|
||||
|
||||
public Command LeftCommand { get; }
|
||||
public Command RightCommand { get; }
|
||||
@ -45,17 +53,25 @@ namespace Billing.Views
|
||||
|
||||
public override void OnLoaded()
|
||||
{
|
||||
SetMonth(DateTime.Today);
|
||||
Task.Run(() => SetMonth(DateTime.Today));
|
||||
}
|
||||
|
||||
private void OnLeftCommand()
|
||||
{
|
||||
SetMonth(current.AddMonths(-1));
|
||||
Task.Run(() =>
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(async () => await scroller.ScrollToAsync(0, 0, true));
|
||||
SetMonth(current.AddMonths(-1));
|
||||
});
|
||||
}
|
||||
|
||||
private void OnRightCommand()
|
||||
{
|
||||
SetMonth(current.AddMonths(1));
|
||||
Task.Run(() =>
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(async () => await scroller.ScrollToAsync(0, 0, true));
|
||||
SetMonth(current.AddMonths(1));
|
||||
});
|
||||
}
|
||||
|
||||
private void SetMonth(DateTime date)
|
||||
@ -87,7 +103,7 @@ namespace Billing.Views
|
||||
{
|
||||
entries.Add(new((float)amount)
|
||||
{
|
||||
Label = day.ToString("MM/dd"),
|
||||
Label = day.ToString("MM-dd"),
|
||||
ValueLabel = amount.ToString("#,##0.##"),
|
||||
Color = primaryColor,
|
||||
TextColor = textColor,
|
||||
@ -96,12 +112,30 @@ namespace Billing.Views
|
||||
}
|
||||
}
|
||||
|
||||
Chart = new LineChart
|
||||
{
|
||||
BackgroundColor = SKColors.Transparent,
|
||||
LabelTextSize = 20,
|
||||
Entries = entries
|
||||
};
|
||||
if (entries.Count > 0)
|
||||
{
|
||||
NoResult = false;
|
||||
Chart = new LineChart
|
||||
{
|
||||
BackgroundColor = SKColors.Transparent,
|
||||
LabelTextSize = 24,
|
||||
Entries = entries
|
||||
};
|
||||
if (type == CategoryType.Income)
|
||||
{
|
||||
TopBills = bills.Where(b => b.Amount > 0).OrderByDescending(b => b.Amount).Take(10).Select(b => Helper.WrapBill(b)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
TopBills = bills.Where(b => b.Amount < 0).OrderBy(b => b.Amount).Take(10).Select(b => Helper.WrapBill(b)).ToList();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NoResult = true;
|
||||
Chart = null;
|
||||
TopBills = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user