コード例 #1
0
        public void Test_Book()
        {
            #region Arrange
            var tmpSupplier = new SupplierConnector().Create(new Supplier()
            {
                Name = "TmpSupplier"
            });
            var tmpArticle = new ArticleConnector().Create(new Article()
            {
                Description = "TmpArticle", PurchasePrice = 100
            });
            #endregion Arrange

            ISupplierInvoiceConnector connector = new SupplierInvoiceConnector();

            var newSupplierInvoice = new SupplierInvoice()
            {
                SupplierNumber      = tmpSupplier.SupplierNumber,
                Comments            = "InvoiceComments",
                InvoiceDate         = new DateTime(2020, 1, 1),
                DueDate             = new DateTime(2020, 2, 1),
                SalesType           = SalesType.Stock,
                OCR                 = "123456789",
                Total               = 5000,
                SupplierInvoiceRows = new List <SupplierInvoiceRow>()
                {
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 10, Price = 100
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20, Price = 100
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20, Price = 100
                    }
                }
            };

            var createdSupplierInvoice = connector.Create(newSupplierInvoice);

            //Act
            connector.Bookkeep(createdSupplierInvoice.GivenNumber);
            var bookedInvoice = connector.Get(createdSupplierInvoice.GivenNumber);

            //Assert
            Assert.AreEqual(true, bookedInvoice.Booked);
            Assert.AreEqual(1, bookedInvoice.Vouchers.Count);
            Assert.AreEqual(ReferenceType.SupplierInvoice, bookedInvoice.Vouchers.First().ReferenceType);

            #region Delete arranged resources
            //Can not cancel booked invoice

/*            connector.Cancel(createdSupplierInvoice.GivenNumber);
 *          new SupplierConnector().Delete(tmpSupplier.SupplierNumber);
 *          new ArticleConnector().Delete(tmpArticle.ArticleNumber);*/
            #endregion Delete arranged resources
        }
コード例 #2
0
        public void Test_Issue96_fixed() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/96
        {
            #region Arrange
            var tmpSupplier = new SupplierConnector().Create(new Supplier()
            {
                Name = "TmpSupplier"
            });
            var tmpArticle = new ArticleConnector().Create(new Article()
            {
                Description = "TmpArticle", PurchasePrice = 100
            });
            #endregion Arrange

            var connector = new SupplierInvoiceConnector();

            var createdInvoice = connector.Create(new SupplierInvoice()
            {
                SupplierNumber      = tmpSupplier.SupplierNumber,
                Comments            = "InvoiceComments",
                InvoiceDate         = new DateTime(2010, 1, 1),
                DueDate             = new DateTime(2010, 2, 1),
                SalesType           = SalesType.Stock,
                OCR                 = "123456789",
                Total               = 5000,
                SupplierInvoiceRows = new List <SupplierInvoiceRow>()
                {
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 10, Price = 100
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20, Price = 100
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20, Price = 100
                    }
                }
            });
            MyAssert.HasNoError(connector);
            Assert.AreEqual(false, createdInvoice.Cancelled);

            var retrievedInvoice = connector.Get(createdInvoice.GivenNumber);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(false, retrievedInvoice.Cancelled);

            connector.LastModified = DateTime.Today;
            var invoiceSubsets = connector.Find().Entities;
            MyAssert.HasNoError(connector);
            foreach (var supplierInvoiceSubset in invoiceSubsets)
            {
                Assert.IsNotNull(supplierInvoiceSubset.Cancelled);
            }

            #region Delete arranged resources
            new CustomerConnector().Delete(tmpSupplier.SupplierNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            #endregion Delete arranged resources
        }
コード例 #3
0
        public void Test_SupplierInvoice_CRUD()
        {
            #region Arrange
            var tmpSupplier = new SupplierConnector().Create(new Supplier()
            {
                Name = "TmpSupplier"
            });
            var tmpArticle = new ArticleConnector().Create(new Article()
            {
                Description = "TmpArticle", PurchasePrice = 100
            });
            #endregion Arrange

            ISupplierInvoiceConnector connector = new SupplierInvoiceConnector();

            #region CREATE
            var newSupplierInvoice = new SupplierInvoice()
            {
                SupplierNumber      = tmpSupplier.SupplierNumber,
                Comments            = "InvoiceComments",
                InvoiceDate         = new DateTime(2010, 1, 1),
                DueDate             = new DateTime(2010, 2, 1),
                SalesType           = SalesType.Stock,
                OCR                 = "123456789",
                Total               = 5000,
                SupplierInvoiceRows = new List <SupplierInvoiceRow>()
                {
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 10, Price = 100
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20, Price = 100
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20, Price = 100
                    }
                }
            };

            var createdSupplierInvoice = connector.Create(newSupplierInvoice);
            Assert.AreEqual("InvoiceComments", createdSupplierInvoice.Comments);
            Assert.AreEqual("TmpSupplier", createdSupplierInvoice.SupplierName);
            Assert.AreEqual(3 + 1, createdSupplierInvoice.SupplierInvoiceRows.Count);
            //3 + 1 => A row "Leverant�rsskulder" is created by default

            #endregion CREATE

            #region UPDATE

            createdSupplierInvoice.Comments = "UpdatedInvoiceComments";

            var updatedSupplierInvoice = connector.Update(createdSupplierInvoice);
            Assert.AreEqual("UpdatedInvoiceComments", updatedSupplierInvoice.Comments);

            #endregion UPDATE

            #region READ / GET

            var retrievedSupplierInvoice = connector.Get(createdSupplierInvoice.GivenNumber);
            Assert.AreEqual("UpdatedInvoiceComments", retrievedSupplierInvoice.Comments);

            #endregion READ / GET

            #region DELETE
            //Not supported
            connector.Cancel(createdSupplierInvoice.GivenNumber);
            var cancelledInvoice = connector.Get(createdSupplierInvoice.GivenNumber);
            Assert.AreEqual(true, cancelledInvoice.Cancelled);
            #endregion DELETE

            #region Delete arranged resources
            new SupplierConnector().Delete(tmpSupplier.SupplierNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            #endregion Delete arranged resources
        }
コード例 #4
0
        public void Test_Find()
        {
            #region Arrange
            var tmpSupplier = new SupplierConnector().Create(new Supplier()
            {
                Name = "TmpSupplier"
            });
            var tmpArticle = new ArticleConnector().Create(new Article()
            {
                Description = "TmpArticle", PurchasePrice = 100
            });
            #endregion Arrange

            ISupplierInvoiceConnector connector = new SupplierInvoiceConnector();
            var newSupplierInvoice = new SupplierInvoice()
            {
                SupplierNumber      = tmpSupplier.SupplierNumber,
                Comments            = "InvoiceComments",
                InvoiceDate         = new DateTime(2010, 1, 1),
                DueDate             = new DateTime(2010, 2, 1),
                SalesType           = SalesType.Stock,
                OCR                 = "123456789",
                Total               = 5000,
                SupplierInvoiceRows = new List <SupplierInvoiceRow>()
                {
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 10, Price = 100
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20, Price = 100
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20, Price = 100
                    }
                }
            };

            //Add entries
            for (var i = 0; i < 5; i++)
            {
                connector.Create(newSupplierInvoice);
            }

            //Apply base test filter
            var searchSettings = new SupplierInvoiceSearch();
            searchSettings.SupplierNumber = tmpSupplier.SupplierNumber;
            var fullCollection = connector.Find(searchSettings);

            Assert.AreEqual(5, fullCollection.TotalResources);
            Assert.AreEqual(5, fullCollection.Entities.Count);
            Assert.AreEqual(1, fullCollection.TotalPages);

            Assert.AreEqual(tmpSupplier.SupplierNumber, fullCollection.Entities.First().SupplierNumber);

            //Apply Limit
            searchSettings.Limit = 2;
            var limitedCollection = connector.Find(searchSettings);

            Assert.AreEqual(5, limitedCollection.TotalResources);
            Assert.AreEqual(2, limitedCollection.Entities.Count);
            Assert.AreEqual(3, limitedCollection.TotalPages);

            //Delete entries (DELETE not supported)
            foreach (var invoice in fullCollection.Entities)
            {
                connector.Cancel(invoice.GivenNumber);
            }

            #region Delete arranged resources
            new SupplierConnector().Delete(tmpSupplier.SupplierNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            #endregion Delete arranged resources
        }
コード例 #5
0
        public void Test_SupplierInvoice_CRUD()
        {
            //Arrange
            var tmpSupplier = new SupplierConnector().Create(new Supplier()
            {
                Name = "TmpSupplier", CountryCode = "SE", City = "Testopolis"
            });
            var tmpArticle = new ArticleConnector().Create(new Article()
            {
                Description = "TmpArticle", Type = ArticleType.STOCK, PurchasePrice = 100
            });

            //Act
            var connector = new SupplierInvoiceConnector();

            #region CREATE
            var newInvoice = new SupplierInvoice()
            {
                SupplierNumber      = tmpSupplier.SupplierNumber,
                InvoiceDate         = new DateTime(2019, 1, 20).ToString(APIConstants.DateFormat), //"2019-01-20",
                DueDate             = new DateTime(2019, 2, 20).ToString(APIConstants.DateFormat), //"2019-02-20",
                SalesType           = SalesType.STOCK,
                OCR                 = "123456789",
                SupplierInvoiceRows = new List <SupplierInvoiceRow>()
                {
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 10
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 15
                    }
                }
            };

            var createdInvoice = connector.Create(newInvoice);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(createdInvoice.SupplierName, "TmpSupplier");
            Assert.AreEqual(3 + 1, createdInvoice.SupplierInvoiceRows.Count);
            //3 + 1 => A row "Leverantörsskulder" is created by default

            #endregion CREATE

            #region UPDATE

            createdInvoice.OCR = "987654321";
            var updatedInvoice = connector.Update(createdInvoice);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("987654321", updatedInvoice.OCR);

            #endregion UPDATE

            #region READ / GET

            var retrievedInvoice = connector.Get(createdInvoice.GivenNumber);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("987654321", retrievedInvoice.OCR);

            #endregion READ / GET

            #region DELETE
            //Invoice does not provide DELETE method, but can be canceled
            connector.Cancel(createdInvoice.GivenNumber);
            MyAssert.HasNoError(connector);

            retrievedInvoice = connector.Get(createdInvoice.GivenNumber);
            Assert.AreEqual(true, retrievedInvoice.Cancelled);

            #endregion DELETE

            //Clean
            new SupplierConnector().Delete(tmpSupplier.SupplierNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
        }
コード例 #6
0
        public void Test_SupplierInvoiceAccrual_CRUD()
        {
            #region Arrange
            var tmpSupplier = new SupplierConnector().Create(new Supplier()
            {
                Name = "TmpSupplier"
            });
            var tmpArticle = new ArticleConnector().Create(new Article()
            {
                Description = "TmpArticle"
            });
            var conn = new SupplierInvoiceConnector();
            var tmpSupplierInvoice = conn.Create(new SupplierInvoice()
            {
                SupplierNumber = tmpSupplier.SupplierNumber,
                Comments       = "InvoiceComments",
                InvoiceDate    = new DateTime(2020, 1, 20), //"2019-01-20",
                DueDate        = new DateTime(2020, 6, 20), //"2019-02-20",
                SalesType      = SalesType.Stock,
                //OCR = "123456789",
                Total = 6000,
                SupplierInvoiceRows = new List <SupplierInvoiceRow>()
                {
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 6, Price = 1000, Account = 5820
                    }
                }
            });
            MyAssert.HasNoError(conn);
            #endregion Arrange

            ISupplierInvoiceAccrualConnector connector = new SupplierInvoiceAccrualConnector();

            #region CREATE
            var newSupplierInvoiceAccrual = new SupplierInvoiceAccrual()
            {
                Description           = "TestSupplierInvoiceAccrual",
                SupplierInvoiceNumber = (int?)tmpSupplierInvoice.GivenNumber,
                Period                     = "MONTHLY",
                AccrualAccount             = 1790,
                CostAccount                = 5820,
                StartDate                  = new DateTime(2021, 1, 1),
                EndDate                    = new DateTime(2021, 3, 1),
                VATIncluded                = false,
                Total                      = 2000,
                SupplierInvoiceAccrualRows = new List <SupplierInvoiceAccrualRow>()
                {
                    new SupplierInvoiceAccrualRow()
                    {
                        Account = 5820, Credit = 0, Debit = 2000
                    },
                    new SupplierInvoiceAccrualRow()
                    {
                        Account = 1790, Credit = 2000, Debit = 0
                    }
                }
            };

            var createdSupplierInvoiceAccrual = connector.Create(newSupplierInvoiceAccrual);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("TestSupplierInvoiceAccrual", createdSupplierInvoiceAccrual.Description);

            #endregion CREATE

            #region UPDATE

            createdSupplierInvoiceAccrual.Description = "UpdatedTestSupplierInvoiceAccrual";

            var updatedSupplierInvoiceAccrual = connector.Update(createdSupplierInvoiceAccrual);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("UpdatedTestSupplierInvoiceAccrual", updatedSupplierInvoiceAccrual.Description);

            #endregion UPDATE

            #region READ / GET

            var retrievedSupplierInvoiceAccrual = connector.Get(createdSupplierInvoiceAccrual.SupplierInvoiceNumber);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("UpdatedTestSupplierInvoiceAccrual", retrievedSupplierInvoiceAccrual.Description);

            #endregion READ / GET

            #region DELETE

            connector.Delete(createdSupplierInvoiceAccrual.SupplierInvoiceNumber);
            MyAssert.HasNoError(connector);

            retrievedSupplierInvoiceAccrual = connector.Get(createdSupplierInvoiceAccrual.SupplierInvoiceNumber);
            Assert.AreEqual(null, retrievedSupplierInvoiceAccrual, "Entity still exists after Delete!");

            #endregion DELETE

            #region Delete arranged resources
            new SupplierConnector().Delete(tmpSupplier.SupplierNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            #endregion Delete arranged resources
        }