Exemple #1
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)");
        }
Exemple #2
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);
        }
Exemple #3
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 #4
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);
            }
        }
        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
        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 #7
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());
        }
Exemple #8
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 #9
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 #10
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 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 #12
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);
        }
Exemple #13
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);
        }
        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);
            }
        }