This repository has been archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b093b4
commit 9749bfe
Showing
7 changed files
with
244 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/SolRIA.SaftAnalyser/ViewModels/SaftTaxesViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using OfficeOpenXml; | ||
using OfficeOpenXml.Table; | ||
using Prism.Commands; | ||
using Prism.Mvvm; | ||
using SolRia.Erp.MobileApp.Models.SaftV4; | ||
using SolRIA.SaftAnalyser.Interfaces; | ||
using System; | ||
using System.Data; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace SolRIA.SaftAnalyser.ViewModels | ||
{ | ||
public class SaftTaxesViewModel : BindableBase | ||
{ | ||
INavigationService navService; | ||
IMessageService messageService; | ||
public SaftTaxesViewModel(INavigationService navService, IMessageService messageService) | ||
{ | ||
this.navService = navService; | ||
this.messageService = messageService; | ||
|
||
DoPrintCommand = new DelegateCommand(OnPrint); | ||
|
||
navService.LoadCompleted += NavService_LoadCompleted; | ||
} | ||
|
||
private void NavService_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) | ||
{ | ||
if (OpenedFileInstance.Instance.SaftFile.MasterFiles != null) | ||
taxesBack = OpenedFileInstance.Instance.SaftFile.MasterFiles.TaxTable; | ||
|
||
TaxTable = taxesBack; | ||
messageService.CloseDialog(); | ||
} | ||
|
||
TaxTableEntry[] taxesBack; | ||
|
||
TaxTableEntry[] taxTable; | ||
public TaxTableEntry[] TaxTable | ||
{ | ||
get => taxTable; | ||
set => SetProperty(ref taxTable, value); | ||
} | ||
|
||
TaxTableEntry tax; | ||
public TaxTableEntry Tax | ||
{ | ||
get => tax; | ||
set => SetProperty(ref tax, value); | ||
} | ||
|
||
string filter; | ||
public string Filter | ||
{ | ||
get { return filter; } | ||
set | ||
{ | ||
filter = value; | ||
|
||
if (taxesBack != null) | ||
{ | ||
if (string.IsNullOrEmpty(filter)) | ||
TaxTable = taxesBack; | ||
else | ||
{ | ||
TaxTable = | ||
(from c in taxesBack | ||
where !string.IsNullOrEmpty(c.Description) && c.Description.IndexOf(filter, System.StringComparison.OrdinalIgnoreCase) >= 0 || | ||
!string.IsNullOrEmpty(c.TaxCode) && c.TaxCode.IndexOf(filter, System.StringComparison.OrdinalIgnoreCase) >= 0 || | ||
!string.IsNullOrEmpty(c.TaxCountryRegion) && c.TaxCountryRegion.IndexOf(filter, System.StringComparison.OrdinalIgnoreCase) >= 0 || | ||
c.TaxType.ToString().IndexOf(filter, System.StringComparison.OrdinalIgnoreCase) >= 0 | ||
select c).ToArray(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public DelegateCommand DoPrintCommand { get; private set; } | ||
private void OnPrint() | ||
{ | ||
if (TaxTable != null && TaxTable.Length > 0) | ||
{ | ||
DataTable dt = new DataTable(); | ||
dt.Columns.Add("País ou região imposto", typeof(string)); | ||
dt.Columns.Add("Código", typeof(string)); | ||
dt.Columns.Add("Descrição", typeof(string)); | ||
dt.Columns.Add("Data fim", typeof(DateTime)); | ||
dt.Columns.Add("Valor", typeof(string)); | ||
dt.Columns.Add("Tipo", typeof(string)); | ||
|
||
foreach (var p in TaxTable) | ||
{ | ||
dt.Rows.Add(p.TaxCountryRegion, p.TaxCode, p.Description, p.TaxExpirationDate, p.Item, p.ItemElementName); | ||
} | ||
|
||
ExcelPackage pck = new ExcelPackage(); | ||
var wsEnum = pck.Workbook.Worksheets.Add("SolRIA | SAFT"); | ||
//Load the collection starting from cell A1... | ||
wsEnum.Cells["A1"].LoadFromDataTable(dt, true, TableStyles.Medium9); | ||
wsEnum.Cells[wsEnum.Dimension.Address].AutoFitColumns(); | ||
|
||
//...and save | ||
var fi = new FileInfo(Path.GetTempPath() + Path.GetRandomFileName() + ".xlsx"); | ||
if (fi.Exists) | ||
fi.Delete(); | ||
|
||
pck.SaveAs(fi); | ||
|
||
Process.Start(fi.FullName); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<local:PageBase | ||
x:Class="SolRIA.SaftAnalyser.Views.SaftTaxes" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:SolRIA.SaftAnalyser" | ||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" | ||
xmlns:sf="http://schemas.syncfusion.com/wpf" | ||
mc:Ignorable="d" > | ||
|
||
<DockPanel> | ||
|
||
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal"> | ||
<Border Margin="3" Background="White" MaxHeight="30" Width="500" CornerRadius="3"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
<Button Style="{DynamicResource MaterialDesignToolButton}" | ||
Height="24" Width="24"> | ||
<materialDesign:PackIcon Kind="Magnify" Opacity=".56" /> | ||
</Button> | ||
<TextBox Grid.Column="1" Margin="5 0 0 0" Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged}" | ||
materialDesign:HintAssist.Hint="Filtro por: País ou região imposto ou Código ou Descrição ou Tipo" | ||
materialDesign:TextFieldAssist.DecorationVisibility="Hidden" BorderThickness="0" | ||
MinWidth="200" VerticalAlignment="Center"> | ||
</TextBox> | ||
</Grid> | ||
</Border> | ||
|
||
<Button Width="100" Height="25" Margin="5" Padding="3" VerticalAlignment="Center" ToolTip="Exportar para Excel" | ||
Command="{Binding DoPrintCommand}" | ||
CommandParameter="{Binding ElementName=dataGridTaxEntries}"> | ||
<StackPanel Orientation="Horizontal"> | ||
<Path Style="{StaticResource DataExcelStyle}" Width="20" Height="20"/> | ||
<TextBlock Text="Impostos" Padding="5,0,0,0"/> | ||
</StackPanel> | ||
</Button> | ||
</StackPanel> | ||
|
||
<sf:SfDataGrid x:Name="dataGridTaxes" Grid.Row="1" AllowEditing="False" AllowGrouping="True" GridValidationMode="InView" | ||
EnableDataVirtualization="True" HorizontalAlignment="Stretch" GroupCaptionTextFormat=" {Key} " | ||
ShowGroupDropArea="True" AutoExpandGroups="True" IsGroupDropAreaExpanded="False" | ||
ShowRowHeader="True" AutoGenerateColumns="False" | ||
ItemsSource="{Binding TaxTable}" | ||
SelectedItem="{Binding Tax}"> | ||
<sf:SfDataGrid.GroupColumnDescriptions> | ||
<sf:GroupColumnDescription ColumnName="TaxType" /> | ||
</sf:SfDataGrid.GroupColumnDescriptions> | ||
<sf:SfDataGrid.Columns> | ||
<sf:GridTextColumn HeaderText="País ou região imposto" MappingName="TaxCountryRegion" /> | ||
<sf:GridTextColumn HeaderText="Código" MappingName="TaxCode" /> | ||
<sf:GridTextColumn HeaderText="Descrição" MappingName="Description" /> | ||
<sf:GridTextColumn HeaderText="Data fim" MappingName="TaxExpirationDate" /> | ||
<sf:GridTextColumn HeaderText="Valor" MappingName="Item" /> | ||
<sf:GridTextColumn HeaderText="Tipo" MappingName="ItemElementName" /> | ||
</sf:SfDataGrid.Columns> | ||
</sf:SfDataGrid> | ||
|
||
</DockPanel> | ||
</local:PageBase> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Syncfusion.SfSkinManager; | ||
|
||
namespace SolRIA.SaftAnalyser.Views | ||
{ | ||
/// <summary> | ||
/// Interaction logic for SaftTaxes.xaml | ||
/// </summary> | ||
public partial class SaftTaxes : PageBase | ||
{ | ||
public SaftTaxes() | ||
{ | ||
InitializeComponent(); | ||
SfSkinManager.SetVisualStyle(dataGridTaxes, VisualStyles.Blend); | ||
} | ||
} | ||
} |