<localView:BeWoView x:Class="BeWo.View.Detail.InvoiceView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:localView="clr-namespace:BeWo.View" xmlns:localViewModel="clr-namespace:BeWo.ViewModel" xmlns:localViewDetail="clr-namespace:BeWo.View.Detail" xmlns:val="clr-namespace:BeWo.Validation" xmlns:proxy="clr-namespace:BeWo.ServiceProxy" xmlns:uc="clr-namespace:BeWo.Controls;assembly=BeWo.Controls" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:r="clr-namespace:BeWo.Security" VerticalAlignment="Stretch" Focusable="True" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic">

	<Grid Name="root">

		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="*" />
		</Grid.ColumnDefinitions>

		<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
			<Grid MinWidth="300">
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
				</Grid.RowDefinitions>

				<GroupBox Header="Hilfeplan">
					<Grid>
						<ComboBox x:Name="combo_customer" HorizontalContentAlignment="Stretch" ItemsPanel="{DynamicResource CustomerComboBoxItemsPanelTemplate}" Style="{DynamicResource ObjectComboBoxStyle}" ItemTemplate="{StaticResource SupportConceptComboBoxItemTemplate}" ItemsSource="{Binding PossibleSupportConcepts}" SelectedValuePath="SupportConceptOid" Height="62" Background="{DynamicResource SupportConceptListBrush}" IsTextSearchEnabled="True" TextSearch.TextPath="CustomerName">
							<ComboBox.SelectedValue>
								<MultiBinding Mode="OneWayToSource" Converter="{StaticResource OneWayToSourceSwitch}">
									<Binding Path="NewVM.SupportConceptOid" />
									<Binding Path="SupportConceptFilter" />
								</MultiBinding>
							</ComboBox.SelectedValue>
						</ComboBox>
						<TextBlock Text="&lt; Kein Hilfeplan ausgewählt &gt;" Foreground="LightGray" FontSize="14" Margin="0 0 5 0" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="{Binding SelectedItem, ElementName=combo_customer, Converter={StaticResource ObjectVisibilityConverter}, ConverterParameter='true'}" />
					</Grid>
				</GroupBox>

				<GroupBox x:Name="gb_new" Grid.Row="1" Margin="5 5 5 0" Visibility="{Binding SelectedItem, ElementName=combo_customer, Converter={StaticResource ObjectVisibilityConverter}}" Header="Neue Rechnung anlegen" Padding="0,0,0,0" Style="{DynamicResource ObjectEditGroupBox}" />

				<GroupBox Visibility="{Binding Visibility, ElementName=gb_new}" Grid.Row="2" Header="Empfänger">

					<ListView Name="lb_recipients" SelectedItem="{Binding NewVM.Recipient}" ItemsSource="{Binding SelectedItem.InvoiceRecipients, ElementName=combo_customer}" Background="Transparent" BorderBrush="Transparent" HorizontalAlignment="Stretch">
						<ListView.Resources>
							<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
							<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
						</ListView.Resources>
						<ListView.ItemsPanel>
							<ItemsPanelTemplate>
								<WrapPanel />
							</ItemsPanelTemplate>
						</ListView.ItemsPanel>
						<ListView.ItemTemplate>
							<DataTemplate>
								<RadioButton IsHitTestVisible="False" IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}},Path=IsSelected}" GroupName="rb_recipient" Content="{Binding Name}" Margin="3" />
							</DataTemplate>
						</ListView.ItemTemplate>
					</ListView>

				</GroupBox>

				<GroupBox x:Name="gb_details" DataContext="{Binding NewVM}" Visibility="{Binding SelectedItem, ElementName=lb_recipients, Converter={StaticResource ObjectVisibilityConverter}}" Grid.Row="3" Header="Details">

					<Grid>

						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="Auto" />
							<ColumnDefinition Width="*" />
						</Grid.ColumnDefinitions>
						<Grid.RowDefinitions>
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
						</Grid.RowDefinitions>

						<Label Grid.Row="2" Content="Betrag" Height="23" Margin="3" />
                        <dxe:TextEdit MaskType="Numeric" Mask="c" MaskUseAsDisplayFormat="True" Grid.Column="1" EditValue="{Binding Amount}" Grid.Row="2" Height="23" Margin="3" />
						<Label Grid.Row="3" Content="Rechnungsnummer" Height="23" Margin="3" />
						<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding InvoiceNumber}" Height="23" Margin="3" />
						<Label Grid.Row="4" Content="Rechnungsdatum" Height="23" Margin="3" />
                        <dxe:DateEdit MaskType="DateTimeAdvancingCaret" EditValue="{Binding InvoiceDate}" Grid.Row="4" Grid.Column="1" Height="23" Margin="3" />
						<Label Grid.Row="5" Content="Abrechnungszeitraum von" Height="23" Margin="3" />
                        <dxe:DateEdit MaskType="DateTimeAdvancingCaret" EditValue="{Binding InvoicingPeriodStart}" Grid.Row="5" Grid.Column="1" Height="23" Margin="3" />
						<Label Grid.Row="6" Content="Abrechnungszeitraum bis" Height="23" Margin="3" />
                        <dxe:DateEdit MaskType="DateTimeAdvancingCaret" EditValue="{Binding InvoicingPeriodEnd}" Grid.Row="6" Grid.Column="1" Height="23" Margin="3" />
						<Label Grid.Row="7" Content="Empfänger" Height="23" Margin="3" />
						<TextBox Grid.Row="7" Grid.Column="1" Text="{Binding RecipientName}" Height="23" Margin="3" />
						<Label Grid.Row="8" Content="Adresse" Height="23" Margin="3" />
						<TextBox Grid.Row="8" Text="{Binding RecipientAddress}" Grid.Column="1" Height="40" Margin="3" />
						<Label Grid.Row="9" Content="Fußnote" Height="23" Margin="3" />
						<TextBox Grid.Row="9" Text="{Binding Notice}" Grid.Column="1" Height="40" Margin="3" />

					</Grid>

				</GroupBox>

				<Button x:Name="button_add" Click="button_add_Click" Visibility="{Binding Visibility, ElementName=gb_details}" Grid.Row="4" FontWeight="Normal" Content="Rechnung erstellen" HorizontalAlignment="Right" Height="23" BorderThickness="3" Margin="5" />

			</Grid>
		</ScrollViewer>

		<ListView HorizontalContentAlignment="Stretch" Name="lb_invoivces" Background="{x:Null}" BorderBrush="{x:Null}" ItemsSource="{Binding FilteredInvoices, Mode=OneWay}" Grid.Column="1" Grid.RowSpan="3">
			<ListView.ItemContainerStyle>
				<Style TargetType="{x:Type ListBoxItem}">
					<Setter Property="Focusable" Value="false" />
				</Style>
			</ListView.ItemContainerStyle>
			<ListView.Resources>
				<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
				<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
			</ListView.Resources>
			<ListView.ItemsPanel>
				<ItemsPanelTemplate>
					<StackPanel />
				</ItemsPanelTemplate>
			</ListView.ItemsPanel>
			<ListView.ItemTemplate>
				<DataTemplate>
					<Border Height="85" CornerRadius="5" Background="White" Margin="3" BorderThickness="1" BorderBrush="Black">
						<Grid>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="Auto" />
								<ColumnDefinition Width="Auto" />
								<ColumnDefinition Width="*" />
							</Grid.ColumnDefinitions>
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto" />
								<RowDefinition Height="Auto" />
								<RowDefinition Height="Auto" />
							</Grid.RowDefinitions>
							<TextBlock Margin="5 5 5 3" FontWeight="Bold">
								<TextBlock.Text>
									<MultiBinding StringFormat="{}{0} vom {1:dd.MM.yyyy} an {2}">
										<MultiBinding.Bindings>
											<Binding Path="InvoiceNumber" />
											<Binding Path="InvoiceDate" />
											<Binding Path="RecipientName" />
										</MultiBinding.Bindings>
									</MultiBinding>
								</TextBlock.Text>
							</TextBlock>
							<TextBlock Margin="5 0 0 0" Grid.Row="1" Grid.ColumnSpan="2">
								<TextBlock.Text>
									<MultiBinding StringFormat="Abrechnungszeitraum: {0:dd.MM.yyyy} - {1:dd.MM.yyyy}">
										<MultiBinding.Bindings>
											<Binding Path="InvoicingPeriodStart" />
											<Binding Path="InvoicingPeriodEnd" />
										</MultiBinding.Bindings>
									</MultiBinding>
								</TextBlock.Text>
							</TextBlock>

							<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" FontWeight="Bold" Margin="0 5 5 0" Height="50" FontSize="20" Text="{Binding Amount, StringFormat=\{0:0.00\} €}" Grid.Column="2" Grid.RowSpan="2"></TextBlock>
							<Button x:Name="btnEdit" Click="btnEdit_Click" Grid.Column="2" Grid.Row="2" Width="32" Height="22" HorizontalAlignment="Right" Margin="0,0,40,5" BorderThickness="1,1,1,1" Padding="1,1,1,1" Style="{DynamicResource GlassButton}" Tag="{Binding}" Visibility="{Binding Path=EditAllowed, Converter={StaticResource BoolVisibilityConverter}}">
								<Image Source="..\..\Ressources\Icons\Symbol Edit.png" Stretch="Uniform" Margin="1,1,1,1" />
							</Button>
							<Button x:Name="btnDelete" Grid.Column="2" Grid.Row="2" Click="btnDelete_Click" Width="32" Height="22" HorizontalAlignment="Right" Margin="0,0,5,5" Padding="1,1,1,1" BorderThickness="1,1,1,1" Style="{DynamicResource GlassButton}" Tag="{Binding}" Visibility="{Binding Path=EditAllowed, Converter={StaticResource BoolVisibilityConverter}}">
								<Image Source="..\..\Ressources\Icons\Symbol Delete.png" Stretch="Uniform" Margin="1,1,1,1" />
							</Button>

						</Grid>
					</Border>
				</DataTemplate>
			</ListView.ItemTemplate>
		</ListView>

		<Popup x:Name="pu_edit" DataContext="{Binding EditVM}" AllowsTransparency="True" Placement="Center" HorizontalAlignment="Center" VerticalAlignment="Center" PlacementTarget="{Binding ElementName=root}">
			<Popup.BindingGroup>
				<BindingGroup />
			</Popup.BindingGroup>
			<GroupBox Width="500" Style="{StaticResource PopUpWindowStyle}">
				<GroupBox.Header>
					<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,0,0">
						<Image Source="..\..\Ressources\Icons\CoinsDisabled.png" Height="28" />
						<TextBox Text="Rechnung bearbeiten" Margin="10,4,0,0" Background="{x:Null}" Foreground="{DynamicResource MainGroupBoxForegroundBrush}" FontSize="20" BorderBrush="{x:Null}" VerticalAlignment="Stretch" BorderThickness="0,0,0,0" Padding="0,0,0,0" />
					</StackPanel>
				</GroupBox.Header>

				<Grid Background="{StaticResource ObjectEditBackgroundBrush}">

					<Grid.RowDefinitions>
						<RowDefinition Height="Auto" />
						<RowDefinition Height="Auto" />
						<RowDefinition Height="Auto" />
					</Grid.RowDefinitions>

					<Rectangle Fill="{DynamicResource AccountingContentBrush}" Height="6" />

					<Grid Grid.Row="1" Margin="0,3,0,0">

						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="Auto" />
							<ColumnDefinition Width="*" />
						</Grid.ColumnDefinitions>
						<Grid.RowDefinitions>
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
						</Grid.RowDefinitions>

						<Label Grid.Row="2" Content="Betrag" Height="23" Margin="5" />
                        <dxe:TextEdit MaskType="Numeric" Mask="c" MaskUseAsDisplayFormat="True" Grid.Column="1" EditValue="{Binding Amount}" Grid.Row="2" Height="23" Margin="5" />
						<Label Grid.Row="3" Content="Rechnungsnummer" Height="23" Margin="5" />
						<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding InvoiceNumber}" Height="23" Margin="5" />
						<Label Grid.Row="4" Content="Rechnungsdatum" Height="23" Margin="5" />
                        <dxe:DateEdit MaskType="DateTimeAdvancingCaret" EditValue="{Binding InvoiceDate}" Grid.Row="4" Grid.Column="1" Height="23" Margin="5" />
						<Label Grid.Row="5" Content="Abrechnungszeitraum von" Height="23" Margin="5" />
                        <dxe:DateEdit MaskType="DateTimeAdvancingCaret" EditValue="{Binding InvoicingPeriodStart}" Grid.Row="5" Grid.Column="1" Height="23" Margin="5" />
						<Label Grid.Row="6" Content="Abrechnungszeitraum bis" Height="23" Margin="5" />
                        <dxe:DateEdit MaskType="DateTimeAdvancingCaret" EditValue="{Binding InvoicingPeriodEnd}" Grid.Row="6" Grid.Column="1" Height="23" Margin="5" />
						<Label Grid.Row="7" Content="Empfänger" Height="23" Margin="5" />
						<TextBox Grid.Row="7" Grid.Column="1" Text="{Binding RecipientName}" Height="23" Margin="5" />
						<Label Grid.Row="8" Content="Adresse" Height="23" Margin="5" />
						<TextBox Grid.Row="8" Text="{Binding RecipientAddress}" Grid.Column="1" Height="40" Margin="5" />
						<Label Grid.Row="9" Content="Fußnote" Height="23" Margin="5" />
						<TextBox Grid.Row="9" Text="{Binding Notice}" Grid.Column="1" Height="40" Margin="5" />

					</Grid>

					<StackPanel Grid.ColumnSpan="2" Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Center" Height="Auto" Margin="10" HorizontalAlignment="Right">
						<Button x:Name="btnSave" Content="Speichern und schließen" Margin="5" Command="ApplicationCommands.Save" Height="25" />
						<Button x:Name="btnClose" Content="Abbrechen" Margin="5" Command="ApplicationCommands.Close" Height="25" />
					</StackPanel>

				</Grid>
			</GroupBox>
		</Popup>

	</Grid>
</localView:BeWoView>