Exemple #1
0
        public void TestAutoNumberingOfPurchaseIncrementNextAvailableNumber()
        {
            CrudProxy proxy = new InvoiceProxy();

            var dto1 = this.GetUnpaidServicePurchase();

            proxy.Insert(dto1);

            Assert.IsTrue(dto1.Uid > 0, "Uid must be > 0 after save.");

            Assert.IsNotNullOrEmpty(dto1.PurchaseOrderNumber);

            string alphaComponent1;
            var    numericalComponentDto1 = GetNumericalComponentOfPurchaseNumber(dto1.PurchaseOrderNumber, out alphaComponent1);

            var dto2 = this.GetUnpaidServicePurchase();

            proxy.Insert(dto2);

            Assert.IsTrue(dto2.Uid > 0, "Uid must be > 0 after save.");

            Assert.IsNotNullOrEmpty(dto2.PurchaseOrderNumber);

            string alphaComponent2;
            var    numericalComponentDto2 = GetNumericalComponentOfPurchaseNumber(dto2.PurchaseOrderNumber, out alphaComponent2);

            Assert.AreEqual(alphaComponent1, alphaComponent2);
            Assert.AreEqual(numericalComponentDto2, numericalComponentDto1 + 1);
        }
        public void ShouldReturnContactsTransactionsInventoryItemsForMatchAll()
        {
            var faker         = _searchHelper.GetSaleInvoiceFaker();
            var invoiceDetail = faker.Generate();
            var response      = new InvoiceProxy().InsertInvoice(invoiceDetail);

            Assert.True(response != null && response.IsSuccessfull);

            _searchHelper.CreatSaleInventoryItem(invoiceDetail.Summary);
            _searchHelper.CreateContact(companyName: invoiceDetail.Summary);
            Thread.Sleep(5000); // Need to wait for entities to be indexed


            var searchProxy = new SearchProxy();
            var results     = searchProxy.Search("*:*", SearchScope.All, 1, 25);

            Assert.NotNull(results);
            Assert.NotNull(results.DataObject);
            Assert.True(results.DataObject.InventoryItems.Count > 0, "No inventory items returned.");
            Assert.True(results.DataObject.Contacts.Count > 0, "No contacts returned.");
            Assert.True(results.DataObject.InventoryItems.Count > 0, "No inventory items returned.");
            Assert.True(results.DataObject.TotalInventoryItemsFound > 0, "Inventory item count is 0.");
            Assert.True(results.DataObject.TotalContactsFound > 0, "transaction count is 0.");
            Assert.True(results.DataObject.TotalTransactionsFound > 0, "transaction count is 0.");
        }
        private void CreateTestSaleInvoices()
        {
            var accountProxy    = new AccountsProxy();
            var accountResponse = accountProxy.GetAccounts(accountType: "Income");
            var incomeAccountId = accountResponse.DataObject.Accounts.Where(a => a.AccountType == "Income").Take(1).SingleOrDefault().Id;

            var invoice = new InvoiceTransactionDetail
            {
                LineItems = new List <InvoiceTransactionLineItem>
                {
                    new InvoiceTransactionLineItem
                    {
                        Description = "line item 1",
                        AccountId   = incomeAccountId,
                        TotalAmount = new decimal(10.00)
                    }
                },
                Currency        = "AUD",
                InvoiceType     = "Tax Invoice",
                TransactionType = "S",
                Layout          = "S",
                TotalAmount     = 10.00M,
                IsTaxInc        = true,
                TransactionDate = DateTime.Now.AddDays(-10),
                Tags            = new List <string> {
                    _testTag
                }
            };

            var invoiceProxy = new InvoiceProxy();
            var result       = invoiceProxy.InsertInvoice(invoice);

            _saleInvoiceTranId = result.DataObject.InsertedEntityId;

            var invoice2 = new InvoiceTransactionDetail
            {
                LineItems = new List <InvoiceTransactionLineItem>
                {
                    new InvoiceTransactionLineItem
                    {
                        Description = "line item 1",
                        AccountId   = incomeAccountId,
                        TotalAmount = new decimal(10.00)
                    }
                },
                Currency        = "AUD",
                InvoiceType     = "Tax Invoice",
                TransactionType = "S",
                Layout          = "S",
                TotalAmount     = 10.00M,
                IsTaxInc        = true,
                TransactionDate = DateTime.Now.AddDays(-10),
                Tags            = new List <string> {
                    _testTag
                }
            };

            result = invoiceProxy.InsertInvoice(invoice2);
            _saleInvoiceTranId2 = result.DataObject.InsertedEntityId;
        }
Exemple #4
0
        public void CheckQuantityOnOrderAndQuantityCommitted()
        {
            CrudProxy        proxy = new InventoryItemProxy();
            InventoryItemDto dto1  = this.GetInventoryItem();

            dto1.RrpInclTax = 7.75M;
            proxy.Insert(dto1);

            Assert.IsTrue(dto1.Uid > 0, "Uid must be > 0 after save.");

            InvoiceDto saleOrder = this.GetSaleOrder(dto1);
            CrudProxy  invoice   = new InvoiceProxy();

            invoice.Insert(saleOrder);

            dto1 = (InventoryItemDto)proxy.GetByUid(dto1.Uid);
            Assert.AreEqual(5, dto1.QuantityCommitted, "Incorrect # of stocks committed (used by sale orders)");

            InvoiceDto po = this.GetPurchaseOrder(dto1);

            po.PurchaseOrderNumber = "<Auto Number>";
            invoice.Insert(po);

            dto1 = (InventoryItemDto)proxy.GetByUid(dto1.Uid);
            Assert.AreEqual(5, dto1.QuantityCommitted, "Incorrect # of stocks committed (used by sale orders)");

            dto1 = (InventoryItemDto)proxy.GetByUid(dto1.Uid);
            Assert.AreEqual(20, dto1.QuantityOnOrder, "Incorrect # of stocks on order(used by purchase orders)");
        }
        protected void SetupTransactions()
        {
            InvoiceDto   dto   = this.GetServiceSale();
            InvoiceProxy proxy = new InvoiceProxy();

            proxy.Insert(dto);
            Assert.IsTrue(dto.Uid > 0, "Invalid uid after save.");
        }
Exemple #6
0
        private void SetupTransactions()
        {
            CrudProxy proxy = new InvoiceProxy();

            _sale1 = GetServiceSale();
            proxy.Insert(_sale1);
            Assert.IsTrue(_sale1.Uid > 0, "Sale tran uid must be > 0 after insert.");

            _purchase1 = GetServicePurchase();
            proxy.Insert(_purchase1);
            Assert.IsTrue(_purchase1.Uid > 0, "Purchase tran uid must be > 0 after insert.");
        }
Exemple #7
0
        public void TestInsertAndGetItemPurchase()
        {
            CrudProxy  proxy = new InvoiceProxy();
            InvoiceDto dto1  = this.GetUnpaidItemPurchase();

            proxy.Insert(dto1);

            Assert.IsTrue(dto1.Uid > 0, "Uid must be > 0 after save.");

            InvoiceDto dto2 = (InvoiceDto)proxy.GetByUid(dto1.Uid);

            AssertEqual(dto1, dto2);
        }
Exemple #8
0
        public void TestWithDeprecatedExtraQueryStringParameters2()
        {
            NameValueCollection queries = new NameValueCollection();

            queries.Add("transactionType", TransactionType.Sale);
            queries.Add("InvoiceDueDateFrom", "01-11-05");
            queries.Add("InvoiceDueDateTo", "10-11-05");
            queries.Add("fields", "InvoiceUid,InvoiceDate,FirstCreated,ModifiedDate,DueDate,InvoiceNumber,TotalAmountInclTax,AmountOwed");
            queries.Add("sortoptions", "InvoiceDate ASC");

            InvoiceProxy proxy = new InvoiceProxy();
            XmlDocument  list  = proxy.Find(queries);
        }
Exemple #9
0
        public void TestDeletePurchasePayment()
        {
            CrudProxy proxy = new InvoiceProxy();

            InvoiceDto purchase1 = this.GetUnpaidItemPurchase();
            InvoiceDto purchase2 = this.GetUnpaidServicePurchase();

            proxy.Insert(purchase1);
            proxy.Insert(purchase2);

            InvoicePaymentDto paymentInfo1 = new InvoicePaymentDto(TransactionType.PurchasePayment);

            paymentInfo1.Date = DateTime.Today.Date;
            paymentInfo1.PaymentAccountUid = this.Westpac.Uid;
            paymentInfo1.Reference         = Guid.NewGuid().ToString();
            paymentInfo1.Summary           = "Payment for 2 Outstanding Invoices";
            paymentInfo1.Fee = 3.99m;

            InvoicePaymentItemDto item = null;

            item            = new InvoicePaymentItemDto();
            item.InvoiceUid = purchase2.Uid;
            item.Amount     = 20.05M;
            paymentInfo1.Items.Add(item);

            item            = new InvoicePaymentItemDto();
            item.InvoiceUid = purchase1.Uid;
            item.Amount     = 23.75M;
            paymentInfo1.Items.Add(item);

            proxy = new InvoicePaymentProxy();
            proxy.Insert(paymentInfo1);

            Assert.IsTrue(paymentInfo1.Uid > 0, "Uid must be > 0 after save.");

            InvoicePaymentDto paymentInfo2 = (InvoicePaymentDto)proxy.GetByUid(paymentInfo1.Uid);

            AssertEqual(paymentInfo1, paymentInfo2);

            proxy = new InvoicePaymentProxy();
            proxy.DeleteByUid(paymentInfo1.Uid);

            try
            {
                proxy.GetByUid(paymentInfo1.Uid);
            }
            catch (RestException ex)
            {
                Assert.AreEqual("RecordNotFoundException", ex.Type);
            }
        }
Exemple #10
0
        public void TestWithDateTypeExtraQueryStringParameters2()
        {
            NameValueCollection queries = new NameValueCollection();

            queries.Add("transactionType", TransactionType.Purchase);
            queries.Add("dateType", "DueDate");
            queries.Add("DateFrom", "01-01-09");
            queries.Add("DateTo", "31-12-09");
            queries.Add("paidStatus", "unpaid");
            queries.Add("fields", "InvoiceUid,InvoiceDate,FirstCreated,ModifiedDate,DueDate,InvoiceNumber,TotalAmountInclTax,AmountOwed");
            queries.Add("sortoptions", "InvoiceDate ASC");

            InvoiceProxy proxy = new InvoiceProxy();
            XmlDocument  list  = proxy.Find(queries);
        }
Exemple #11
0
        public void TestInsertAndGetServicePurchaseWithShipToContact()
        {
            CrudProxy  proxy = new InvoiceProxy();
            InvoiceDto dto1  = this.GetUnpaidServicePurchase();

            dto1.ShipToContactUid = MrSmith.Uid;

            proxy.Insert(dto1);

            Assert.IsTrue(dto1.Uid > 0, "Uid must be > 0 after save.");

            InvoiceDto dto2 = (InvoiceDto)proxy.GetByUid(dto1.Uid);

            AssertEqual(dto1, dto2);
        }
Exemple #12
0
        public void TestAutoNumberingOfPurchaseNextAvailableNumberIsAvailable()
        {
            CrudProxy proxy = new InvoiceProxy();

            var dto1 = this.GetUnpaidServicePurchase();

            proxy.Insert(dto1);

            Assert.IsTrue(dto1.Uid > 0, "Uid must be > 0 after save.");

            var savedDto = (InvoiceDto)proxy.GetByUid(dto1.Uid);

            AssertEqual(dto1, savedDto);

            Assert.IsNotNullOrEmpty(dto1.PurchaseOrderNumber);
        }
Exemple #13
0
        private void CreateInvoices()
        {
            var proxy  = new InvoiceProxy();
            var helper = new InvoiceHelper();

            //Create sales.
            _DeletedSaleTranId    = (int)helper.CreateASingleInvoice(amount: 20.00M).TransactionId;
            _NotDeletedSaleTranId = (int)helper.CreateASingleInvoice(amount: 20.00M).TransactionId;

            //Delete only first sale.
            proxy.DeleteInvoice(_DeletedSaleTranId);

            //Create purchases.
            _DeletedPurchaseTranId    = (int)helper.CreateASingleInvoice("P", 20.00M).TransactionId;
            _NotDeletedPurchaseTranId = (int)helper.CreateASingleInvoice("P", 20.00M).TransactionId;

            //Delete only first purchases.
            proxy.DeleteInvoice(_DeletedPurchaseTranId);
        }
Exemple #14
0
        private void PurchaseItemsForInventory()
        {
            InvoiceDto dto = new InvoiceDto(TransactionType.Purchase, InvoiceLayout.Item);

            dto.Date                = DateTime.Today.Date;
            dto.ContactUid          = this.MrSmith.Uid;
            dto.Summary             = "Test Insert Item Purchase";
            dto.Notes               = "From REST";
            dto.DueOrExpiryDate     = dto.Date.AddMonths(1);
            dto.Status              = InvoiceStatus.Invoice;
            dto.InvoiceNumber       = "I123";
            dto.PurchaseOrderNumber = "<Auto Number>";

            ItemInvoiceItemDto item = null;

            item                  = new ItemInvoiceItemDto();
            item.Quantity         = 100;
            item.InventoryItemUid = this.HardDisk.Uid;
            item.Description      = this.HardDisk.Description;
            item.TaxCode          = TaxCode.ExpInclGst;
            item.UnitPriceInclTax = 99.95M;
            dto.Items.Add(item);

            item                  = new ItemInvoiceItemDto();
            item.Quantity         = 5000;
            item.InventoryItemUid = this.Cat5Cable.Uid;
            item.Description      = this.Cat5Cable.Description;
            item.TaxCode          = TaxCode.ExpInclGst;
            item.UnitPriceInclTax = 0.95M;
            dto.Items.Add(item);

            item                  = new ItemInvoiceItemDto();
            item.Quantity         = 1;
            item.InventoryItemUid = this.Shipping1.Uid;
            item.Description      = this.Shipping1.Description;
            item.TaxCode          = TaxCode.ExpInclGst;
            item.UnitPriceInclTax = 111.11M;
            dto.Items.Add(item);

            CrudProxy proxy = new InvoiceProxy();

            proxy.Insert(dto);
        }
        public void ShouldReturnSaleTransactionForScopedSearchByInvoiceNumber()
        {
            var searchProxy   = new SearchProxy();
            var faker         = _searchHelper.GetSaleInvoiceFaker();
            var invoiceDetail = faker.Generate();
            var response      = new InvoiceProxy().InsertInvoice(invoiceDetail);

            Assert.True(response != null && response.IsSuccessfull);
            Thread.Sleep(5000); // Need to wait for entities to be indexed

            var results1 = searchProxy.Search(response.DataObject.GeneratedInvoiceNumber, SearchScope.Transactions, 1, 25);

            Assert.NotNull(results1);
            Assert.True(results1.DataObject.Transactions.Count > 0, "No transactions returned.");
            Assert.True(results1.DataObject.TotalTransactionsFound > 0, "transaction count is 0.");
            Assert.Equal(0, results1.DataObject.TotalContactsFound);
            Assert.Equal(0, results1.DataObject.TotalInventoryItemsFound);
            Assert.Contains(results1.DataObject.Transactions, t => t.Id == response.DataObject.InsertedEntityId);
        }
        public void DeleteReferenced()
        {
            ComboItemProxy proxy     = new ComboItemProxy();
            ComboItemDto   comboItem = this.GetComboItem01();

            proxy.Insert(comboItem);

            // We need to insert stock first using a purchase
            CrudProxy  invoiceProxy = new InvoiceProxy();
            InvoiceDto dto          = new InvoiceDto(TransactionType.Purchase, InvoiceLayout.Item);

            dto.Date                = DateTime.Today.Date;
            dto.ContactUid          = this.MrSmith.Uid;
            dto.Summary             = "Using a combo item.";
            dto.Notes               = "From REST";
            dto.DueOrExpiryDate     = dto.Date.AddMonths(1);
            dto.Status              = InvoiceStatus.Invoice;
            dto.InvoiceNumber       = "I123";
            dto.PurchaseOrderNumber = "<Auto Number>";

            decimal unitsToBuild = 12.25M;

            // "purchase" all the items that are part of this combo item so we have valid stock
            ItemInvoiceItemDto item = new ItemInvoiceItemDto();

            item.Quantity         = 5;
            item.InventoryItemUid = comboItem.Uid;
            item.Description      = "Purchasing: " + comboItem.Description;
            item.TaxCode          = TaxCode.ExpInclGst;
            item.UnitPriceInclTax = 99.95M;
            dto.Items.Add(item);
            invoiceProxy.Insert(dto);

            try
            {
                proxy.DeleteByUid(comboItem.Uid);
                Assert.Fail("Expected exception was not thrown.");
            }
            catch (RestException ex)
            {
                Assert.AreEqual("The specified inventory item is referenced by some Transactions and/or Combo Items  and therefore cannot be deleted.", ex.Message);
            }
        }
Exemple #17
0
        public void Run()
        {
            CrudProxy proxy = new InvoiceProxy();

            for (int i = 1; i <= 50; i++)
            {
                InvoiceDto serviceDto = this.GetServiceSale();
                proxy.Insert(serviceDto);
                Console.WriteLine("Service invoice #{0}: {1}", i, serviceDto.Uid);
            }

            proxy = new InvoiceProxy();
            for (int i = 1; i <= 50; i++)
            {
                InvoiceDto itemDto = this.GetItemSale();
                proxy.Insert(itemDto);
                Console.WriteLine("Item invoice #{0}: {1}", i, itemDto.Uid);
            }
        }
        public void ShouldReturnPurchasesOnlyWhenTransactionEntityTypeSpecified()
        {
            var invoiceProxy = new InvoiceProxy();
            var saleInfo     = _searchHelper.GetSaleInvoiceFaker().Generate();
            var saleResponse = invoiceProxy.InsertInvoice(saleInfo);

            Assert.True(saleResponse != null && saleResponse.IsSuccessfull);

            var purchaseInfo     = _searchHelper.GetPurchaseInvoiceFaker(saleInfo.Summary).Generate();
            var purchaseResponse = invoiceProxy.InsertInvoice(purchaseInfo);

            Assert.True(purchaseResponse != null && purchaseResponse.IsSuccessfull);
            Thread.Sleep(5000); // Need to wait for entities to be indexed


            var searchProxy = new SearchProxy();
            var results     = searchProxy.Search(purchaseInfo.Summary, SearchScope.Transactions, 1, 25, "transactions.purchase");

            Assert.NotNull(results);
            Assert.NotNull(results.DataObject);
            Assert.True(results.DataObject.Transactions.TrueForAll(x => x.Type == "P"));
        }
        public void Insert1()
        {
            InvoiceProxy proxy = new InvoiceProxy();
            InvoiceDto   dto1  = this.GetSale1();

            EmailMessageDto emailMessage = new EmailMessageDto();

            emailMessage.From    = ConfigurationSettings.AppSettings["NUnitTests.Email.From"];
            emailMessage.To      = ConfigurationSettings.AppSettings["NUnitTests.Email.To"];
            emailMessage.Subject = "Invoice - Sent using NetAccounts OLA REST API (TestInsertAndEmail).";
            emailMessage.Body    = "Insert Invoice then email.";

            proxy.InsertAndEmail(dto1, emailMessage);

            Assert.IsTrue(dto1.Uid > 0, "Uid must be > 0 after save.");

            //
            //	Ensure IsSent is updated.
            //
            dto1 = (InvoiceDto)proxy.GetByUid(dto1.Uid);
            Assert.IsTrue(dto1.IsSent, "Invoice should have been sent.");
        }
Exemple #20
0
        public void IndexedTransactionShouldMatchEntityData()
        {
            var searchProxy = new SearchProxy();
            var invoice     = new InvoiceProxy().GetInvoice(_invoiceHelper.InvoiceId1.Value).DataObject;

            Assert.IsNotNull(invoice.BillingContactId, "Contact not found");
            var contact = new ContactProxy().GetContact(invoice.BillingContactId.Value).DataObject;

            var searchResults = searchProxy.Search(_invoiceHelper.InvoiceId1Summary, SearchScope.Transactions, 1, 100);

            Assert.IsNotNull(searchResults.DataObject);
            Assert.IsTrue(searchResults.DataObject.Transactions.Count > 0);
            var indexedTransaction = searchResults.DataObject.Transactions.First(x => x.Id == invoice.TransactionId);

            Assert.AreEqual(invoice.DueDate, indexedTransaction.DueDate);
            Assert.AreEqual(invoice.BillingContactOrganisationName, indexedTransaction.Company);
            Assert.AreEqual(contact.EmailAddress, ReplaceEm(indexedTransaction.ContactEmail));
            Assert.AreEqual(invoice.InvoiceNumber, indexedTransaction.InvoiceNumber);
            Assert.AreEqual(invoice.PurchaseOrderNumber, indexedTransaction.PurchaseOrderNumber);
            Assert.AreEqual(invoice.NotesExternal, indexedTransaction.ExternalNotes);
            Assert.AreEqual(invoice.NotesInternal, indexedTransaction.Notes);
            Assert.AreEqual(invoice.TransactionType, indexedTransaction.Type);
        }
Exemple #21
0
        //Should select next available number after taken one.
        public void TestAutoNumberingOfPurchaseNextAvailableNumberNotAvailable()
        {
            CrudProxy proxy = new InvoiceProxy();

            var dto1 = this.GetUnpaidServicePurchase();

            proxy.Insert(dto1);

            Assert.IsTrue(dto1.Uid > 0, "Uid must be > 0 after save.");

            string alphaComponent;
            var    numericalComponentDto1 = GetNumericalComponentOfPurchaseNumber(dto1.PurchaseOrderNumber, out alphaComponent);

            Assert.IsNotNull(numericalComponentDto1, "PurchaseOrderNumber returned did not contain a numerical component");

            //manually insert an invoice.
            var nextAvailablePONumber = alphaComponent + (numericalComponentDto1 + 1).ToString();

            var dto2 = this.GetUnpaidServicePurchase(nextAvailablePONumber);

            proxy.Insert(dto2);

            Assert.IsTrue(dto2.Uid > 0, "Uid must be > 0 after save.");

            //create next auto numbering invoice.
            var dto3 = this.GetUnpaidServicePurchase();

            proxy.Insert(dto3);

            Assert.IsTrue(dto3.Uid > 0, "Uid must be > 0 after save.");

            var savedDto = (InvoiceDto)proxy.GetByUid(dto3.Uid);

            Assert.IsNotNull(savedDto.PurchaseOrderNumber);

            Assert.AreEqual(savedDto.PurchaseOrderNumber, alphaComponent + (numericalComponentDto1 + 2).ToString());
        }
        public void BuildComboItem()
        {
            ComboItemProxy proxy = new ComboItemProxy();

            ComboItemDto comboItemDto = this.GetComboItem01();

            proxy.Insert(comboItemDto);
            ComboItemDto comboItem = (ComboItemDto)proxy.GetByUid(comboItemDto.Uid);

            // We need to insert stock first using a purchase
            CrudProxy  invoiceProxy = new InvoiceProxy();
            InvoiceDto dto          = new InvoiceDto(TransactionType.Purchase, InvoiceLayout.Item);

            dto.Date                = DateTime.Today.Date;
            dto.ContactUid          = this.MrSmith.Uid;
            dto.Summary             = "Add stock do we can build ComboItems";
            dto.Notes               = "From REST";
            dto.DueOrExpiryDate     = dto.Date.AddMonths(1);
            dto.Status              = InvoiceStatus.Invoice;
            dto.InvoiceNumber       = "I123";
            dto.PurchaseOrderNumber = "<Auto Number>";

            decimal unitsToBuild = 12.25M;

            foreach (ComboItemLineItemDto itemInCombo in comboItem.Items)
            {   // "purchase" all the items that are part of this combo item so we have valid stock
                ItemInvoiceItemDto item = new ItemInvoiceItemDto();
                item.Quantity         = itemInCombo.Quantity * unitsToBuild;
                item.InventoryItemUid = itemInCombo.Uid;
                item.Description      = "Purchasing: " + itemInCombo.Code;
                item.TaxCode          = TaxCode.ExpInclGst;
                item.UnitPriceInclTax = 99.95M;
                dto.Items.Add(item);
            }
            invoiceProxy.Insert(dto);

            // Download stock info before
            InventoryItemProxy inventoryItemProxy = new InventoryItemProxy();
            InventoryItemDto   inventoryItem      = (InventoryItemDto)inventoryItemProxy.GetByUid(comboItemDto.Uid);
            decimal            stockOnHand        = inventoryItem.StockOnHand;


            // Build the item!
            BuildComboItemResult result = proxy.Build(comboItemDto.Uid, unitsToBuild);

            Assert.AreNotEqual(0, result.Uid);
            Assert.IsNotNull(result.LastUpdatedUid);

            inventoryItem = (InventoryItemDto)inventoryItemProxy.GetByUid(comboItemDto.Uid);
            decimal newStockOnHand = inventoryItem.StockOnHand;

            Assert.AreEqual(stockOnHand + unitsToBuild, newStockOnHand, "We have one extra item in stock");

            // Read Inventory Transfer details
            InventoryTransferProxy transferProxy = new InventoryTransferProxy();
            InventoryTransferDto   transfer      = (InventoryTransferDto)transferProxy.GetByUid(result.Uid);

            Assert.AreEqual(comboItem.Items.Count + 1, transfer.Items.Count); // +1 as we have the combo item the first one

            // confirm first item is the combo with +1
            InventoryTransferItemDto comboItemTransfer = (InventoryTransferItemDto)transfer.Items[0];

            Assert.AreEqual(comboItemDto.Uid, comboItemTransfer.InventoryItemUid);
            Assert.AreEqual(unitsToBuild, comboItemTransfer.Quantity);

            for (int i = 0; i < comboItem.Items.Count; i++)
            {
                ComboItemLineItemDto     line = comboItem.Items[i];
                InventoryTransferItemDto item = (InventoryTransferItemDto)transfer.Items[i + 1];
                Assert.AreEqual(line.Uid, item.InventoryItemUid);
                Assert.AreEqual(line.Quantity * unitsToBuild, -item.Quantity);
            }
        }
Exemple #23
0
        public void TestInsertAndGetItemPurchase_Invoice_Totals_Test()
        {
            //Arange
            var proxy = new InvoiceProxy();
            var input = GetUnpaidItemPurchase();

            input.Items.Clear();

            var item = new ItemInvoiceItemDto
            {
                Quantity         = 100,
                InventoryItemUid = this.HardDisk.Uid,
                Description      = this.HardDisk.Description,
                TaxCode          = TaxCode.SaleInclGst,
                UnitPriceInclTax = 99.95M
            };

            input.Items.Add(item);

            item = new ItemInvoiceItemDto
            {
                Quantity         = 5000,
                InventoryItemUid = this.Cat5Cable.Uid,
                Description      = this.Cat5Cable.Description,
                TaxCode          = TaxCode.SaleInclGst,
                UnitPriceInclTax = 0.95M
            };

            input.Items.Add(item);

            //act
            var item1 = ((ItemInvoiceItemDto)input.Items[0]);
            var item2 = ((ItemInvoiceItemDto)input.Items[1]);

            var totalItem1 = (item1.UnitPriceInclTax * item1.Quantity);
            var totalItem2 = (item2.UnitPriceInclTax * item2.Quantity);

            var totalTax1 = totalItem1 - (Math.Round(totalItem1 / (1 + 0.100000m), 2, MidpointRounding.AwayFromZero));
            var totalTax2 = totalItem2 - (Math.Round(totalItem2 / (1 + 0.100000m), 2, MidpointRounding.AwayFromZero));

            proxy.Insert(input);

            var output          = (InvoiceDto)proxy.GetByUid(input.Uid);
            var outputLineItem1 = ((ItemInvoiceItemDto)output.Items[0]);
            var outputLineItem2 = ((ItemInvoiceItemDto)output.Items[1]);

            //assert

            //Test Line Item Totals.
            Assert.AreEqual(outputLineItem1.TotalAmountInclTax, totalItem1);
            Assert.AreEqual(outputLineItem1.TotalTaxAmount, totalTax1);
            Assert.AreEqual(outputLineItem1.TotalAmountExclTax, outputLineItem1.TotalAmountInclTax - totalTax1);

            Assert.AreEqual(outputLineItem2.TotalAmountInclTax, totalItem2);
            Assert.AreEqual(outputLineItem2.TotalTaxAmount, totalTax2);
            Assert.AreEqual(outputLineItem2.TotalAmountExclTax, outputLineItem2.TotalAmountInclTax - totalTax2);

            //Test Invoice Totals.
            Assert.AreEqual(output.TotalAmountInclTax, outputLineItem1.TotalAmountInclTax + outputLineItem2.TotalAmountInclTax);
            Assert.AreEqual(output.TotalTaxAmount, outputLineItem1.TotalTaxAmount + outputLineItem2.TotalTaxAmount);
            Assert.AreEqual(output.TotalAmountExclTax, outputLineItem1.TotalAmountExclTax + outputLineItem2.TotalAmountExclTax);
        }