Exemplo n.º 1
0
    public async Task <byte[]> GetAsync(SIEType type, long?finYearID = null, SIEExportOptions exportOptions = null)
    {
        var request = new FileDownloadRequest()
        {
            Endpoint = Endpoint,
            Indices  = new List <string> {
                type.GetStringValue()
            }
        };

        if (finYearID != null)
        {
            request.Parameters.Add("financialyear", finYearID.ToString());
        }

        if (exportOptions != null)
        {
            foreach (var parameter in GetExportParameters(exportOptions))
            {
                request.Parameters.Add(parameter.Key, parameter.Value);
            }
        }

        return(await SendAsync(request).ConfigureAwait(false));
    }
Exemplo n.º 2
0
    private static Dictionary <string, string> GetExportParameters(SIEExportOptions exportOptions)
    {
        var parameters = new Dictionary <string, string>();

        if (exportOptions.FromDate != null)
        {
            parameters.Add("fromdate", exportOptions.FromDate?.ToString(ApiConstants.DateFormat));
        }
        if (exportOptions.ToDate != null)
        {
            parameters.Add("todate", exportOptions.ToDate?.ToString(ApiConstants.DateFormat));
        }
        if (exportOptions.ExportAll != null)
        {
            parameters.Add("exportall", exportOptions.ExportAll.ToString().ToLower());
        }
        if (exportOptions.Selection != null)
        {
            var selectionValues = exportOptions.Selection.Where(s => s.VoucherSeries != null).Select(s =>
            {
                var value = s.VoucherSeries;
                if (s.FromVoucherNumber != null || s.ToVoucherNumber != null)
                {
                    value += $",{s.FromVoucherNumber},{s.ToVoucherNumber}";
                }
                return(value);
            });

            parameters.Add("selection", string.Join(";", selectionValues));
        }

        return(parameters);
    }
Exemplo n.º 3
0
        public void SIE_Get_ExportOptions_VoucherSelection()
        {
            ISIEConnector connector     = new SIEConnector();
            var           exportOptions = new SIEExportOptions()
            {
                Selection = new List <VoucherSelection>()
                {
                    new VoucherSelection()
                    {
                        VoucherSeries     = "A",
                        FromVoucherNumber = 20,
                        ToVoucherNumber   = 24
                    },
                    new VoucherSelection()
                    {
                        VoucherSeries     = "B",
                        FromVoucherNumber = 5,
                        ToVoucherNumber   = 9
                    }
                }
            };

            var data        = connector.Get(SIEType.Transactions, exportOptions: exportOptions);
            var sieDocument = Parse(data);

            Assert.AreEqual(5 + 5, sieDocument.VER.Count);

            Assert.AreEqual(5, sieDocument.VER.Count(v => v.Series == "A"));
            Assert.AreEqual(false, sieDocument.VER.Any(v => v.Series == "A" && int.Parse(v.Number) < 20));
            Assert.AreEqual(false, sieDocument.VER.Any(v => v.Series == "A" && int.Parse(v.Number) > 24));

            Assert.AreEqual(5, sieDocument.VER.Count(v => v.Series == "B"));
            Assert.AreEqual(false, sieDocument.VER.Any(v => v.Series == "B" && int.Parse(v.Number) < 5));
            Assert.AreEqual(false, sieDocument.VER.Any(v => v.Series == "B" && int.Parse(v.Number) > 9));
        }
Exemplo n.º 4
0
        public void SIE_Get_ExportOptions_Period()
        {
            ISIEConnector connector     = new SIEConnector();
            var           exportOptions = new SIEExportOptions()
            {
                FromDate = new DateTime(2020, 4, 1),
                ToDate   = new DateTime(2020, 8, 31)
            };

            var data        = connector.Get(SIEType.Transactions, exportOptions: exportOptions);
            var sieDocument = Parse(data);

            Assert.AreEqual(false, sieDocument.VER.Any(v => v.VoucherDate < exportOptions.FromDate));
            Assert.AreEqual(false, sieDocument.VER.Any(v => v.VoucherDate > exportOptions.ToDate));

            Assert.AreEqual(true, sieDocument.VER.Any(v => v.VoucherDate > exportOptions.FromDate));
        }
Exemplo n.º 5
0
    public async Task SIE_Get_ExportOptions_Period()
    {
        var connector     = FortnoxClient.SIEConnector;
        var exportOptions = new SIEExportOptions()
        {
            FromDate = new DateTime(2020, 4, 1),
            ToDate   = new DateTime(2020, 8, 31)
        };

        var data = await connector.GetAsync(SIEType.Transactions, exportOptions : exportOptions);

        var sieDocument = Parse(data);

        Assert.AreEqual(false, sieDocument.VER.Any(v => v.VoucherDate < exportOptions.FromDate));
        Assert.AreEqual(false, sieDocument.VER.Any(v => v.VoucherDate > exportOptions.ToDate));

        Assert.AreEqual(true, sieDocument.VER.Any(v => v.VoucherDate > exportOptions.FromDate));
    }
Exemplo n.º 6
0
        public void SIE_Get_ExportOptions_ExcludeUnused()
        {
            ISIEConnector connector        = new SIEConnector();
            var           exportOptionsAll = new SIEExportOptions()
            {
                ExportAll = true
            };
            var exportOptionsExcludeUnused = new SIEExportOptions()
            {
                ExportAll = false
            };

            var data            = connector.Get(SIEType.PeriodBalance, exportOptions: exportOptionsAll);
            var sieDocumentFull = Parse(data);

            data = connector.Get(SIEType.Transactions, exportOptions: exportOptionsExcludeUnused);
            var sieDocumentFiltered = Parse(data);

            Assert.AreEqual(true, sieDocumentFull.KONTO.Count > sieDocumentFiltered.KONTO.Count);
        }
Exemplo n.º 7
0
    public async Task SIE_Get_ExportOptions_ExcludeUnused()
    {
        var connector        = FortnoxClient.SIEConnector;
        var exportOptionsAll = new SIEExportOptions()
        {
            ExportAll = true
        };
        var exportOptionsExcludeUnused = new SIEExportOptions()
        {
            ExportAll = false
        };

        var data = await connector.GetAsync(SIEType.PeriodBalance, exportOptions : exportOptionsAll);

        var sieDocumentFull = Parse(data);

        data = await connector.GetAsync(SIEType.Transactions, exportOptions : exportOptionsExcludeUnused);

        var sieDocumentFiltered = Parse(data);

        Assert.AreEqual(true, sieDocumentFull.KONTO.Count > sieDocumentFiltered.KONTO.Count);
    }
Exemplo n.º 8
0
    public async Task SIE_Get_ExportOptions_VoucherSelection_IncompleteInterval()
    {
        var connector     = FortnoxClient.SIEConnector;
        var exportOptions = new SIEExportOptions()
        {
            Selection = new List <VoucherSelection>()
            {
                new VoucherSelection()
                {
                    VoucherSeries     = "A",
                    FromVoucherNumber = 20,
                    //ToVoucherNumber = 24
                },
                new VoucherSelection()
                {
                    VoucherSeries     = "B",
                    FromVoucherNumber = 5,
                    ToVoucherNumber   = 9
                }
            }
        };

        await connector.GetAsync(SIEType.Transactions, exportOptions : exportOptions);
    }
Exemplo n.º 9
0
        public void SIE_Get_ExportOptions_VoucherSelection_IncompleteInterval()
        {
            ISIEConnector connector     = new SIEConnector();
            var           exportOptions = new SIEExportOptions()
            {
                Selection = new List <VoucherSelection>()
                {
                    new VoucherSelection()
                    {
                        VoucherSeries     = "A",
                        FromVoucherNumber = 20,
                        //ToVoucherNumber = 24
                    },
                    new VoucherSelection()
                    {
                        VoucherSeries     = "B",
                        FromVoucherNumber = 5,
                        ToVoucherNumber   = 9
                    }
                }
            };

            connector.Get(SIEType.Transactions, exportOptions: exportOptions);
        }
Exemplo n.º 10
0
 public byte[] Get(SIEType type, long?finYearID = null, SIEExportOptions exportOptions = null)
 {
     return(GetAsync(type, finYearID, exportOptions).GetResult());
 }