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 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 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.");
 }
        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);
        }
        public void ApplyingPaymentToQuote()
        {
            CrudProxy proxy = new InvoiceProxy();
            InvoiceDto dto1 = this.GetServiceSale();
            dto1.Status = InvoiceStatus.Quote;

            try
            {
                proxy.Insert(dto1);
                throw new Exception("Expected exception not thrown.");
            }
            catch (RestException ex)
            {
                Assert.AreEqual("InvalidTransactionException", ex.Type);
            }
        }
        public void ApplyingTaxCodeGSTTransactionCategory()
        {
            CrudProxy proxy = new InvoiceProxy();
            InvoiceDto dto1 = this.GetUnpaidServiceSale();

            ServiceInvoiceItemDto item = (ServiceInvoiceItemDto)dto1.Items[0];
            item.AccountUid = 738;	//	Asset: GST Paid on Purchases
            item.TaxCode = TaxCode.SaleInclGst;

            try
            {
                proxy.Insert(dto1);
                throw new Exception("Expected exception not thrown.");
            }
            catch (RestException ex)
            {
                Assert.AreEqual("InvalidTaxCodeException", ex.Type);
            }
        }
        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.");
        }
        public void ApplyingBankAccountAsAccountUidShouldThrowException()
        {
            //
            //	Apply TaxCode to GST account.
            //
            CrudProxy proxy = new InvoiceProxy();
            InvoiceDto dto1 = this.GetUnpaidServiceSale();

            ServiceInvoiceItemDto item = (ServiceInvoiceItemDto)dto1.Items[0];

            // Banks accounts can't be used as Accounts for line items.
            item.AccountUid = this.Westpac.Uid;
            item.TaxCode = TaxCode.SaleInclGst;

            try
            {
                proxy.Insert(dto1);
                throw new Exception("Expected exception not thrown.");
            }
            catch (RestException ex)
            {
                Assert.AreEqual("InvalidReferenceException", ex.Type);
            }
        }
        public void InsertAndEmailUsingShippingSlipTemplate()
        {
            InvoiceProxy proxy = new InvoiceProxy();

            InvoiceDto dto1 = this.GetServiceSale();

            EmailMessageDto emailMessage = new EmailMessageDto();
            emailMessage.From = ConfigurationSettings.AppSettings["NUnitTests.Email.From"];
            emailMessage.To = ConfigurationSettings.AppSettings["NUnitTests.Email.To"];
            emailMessage.Subject = "Insert And Email: Shipping slip Template";
            emailMessage.Body = "Insert Invoice then email.";

            proxy.InsertAndEmail(dto1, this.ShippingTemplateUid, 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.");
        }
        public void InsertAndGetItemSale()
        {
            CrudProxy proxy = new InvoiceProxy();
            InvoiceDto dto1 = this.GetItemSale();

            proxy.Insert(dto1);

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

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

            AssertEqual(dto1, dto2);
        }
        public void UpdateMultiCcySaleWithPaymentOverrideAutoFXFeed()
        {
            CrudProxy proxy = new InvoiceProxy();

            InvoiceDto dto1 = this.GetServiceSale();
            dto1.Date = DateTime.Parse("12-Feb-2010");
            dto1.Ccy = "USD";
            dto1.AutoPopulateFXRate = true;
            dto1.FCToBCFXRate = 0M;
            proxy.Insert(dto1);

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

            InvoiceDto dto2 = (InvoiceDto)proxy.GetByUid(dto1.Uid);
            dto2.AutoPopulateFXRate = false;
            dto2.FCToBCFXRate = 1.039M;
            try
            {
                proxy.Update(dto2);	// Should not be allowed. There's a payment applied already.
                Assert.Fail("No exception thrown.");
            }
            catch (RestException restException)
            {
                var expectedMessage =
                    "Sorry, FX rate cannot be changed because there are payments applied to the transaction already. Please change the FX rate on payment instead.";
                Assert.AreEqual(expectedMessage, restException.Message, "Incorrect error message.");
            }
        }
        public void InsertAndEmailUsingInvalidTemplate()
        {
            InvoiceProxy proxy = new InvoiceProxy();

            InvoiceDto dto1 = this.GetServiceSale();

            EmailMessageDto emailMessage = new EmailMessageDto();
            emailMessage.From = ConfigurationSettings.AppSettings["NUnitTests.Email.From"];
            emailMessage.To = ConfigurationSettings.AppSettings["NUnitTests.Email.To"];
            emailMessage.Subject = "Insert And Email: Template Not Specified";
            emailMessage.Body = "Insert Invoice then email.";

            try
            {
                proxy.InsertAndEmail(dto1, 99999, emailMessage);
                throw new Exception("Expected exception not thrown.");
            }
            catch (RestException rex)
            {
                Assert.AreEqual("Unable to find the requested  template.", rex.Message, "Incorrect error message.");
            }
        }
        public void UpdateMultiCcySaleWithPaymentOverrideManualFXFeed()
        {
            CrudProxy proxy = new InvoiceProxy();

            InvoiceDto dto1 = this.GetServiceSale();
            dto1.Date = DateTime.Parse("12-Feb-2010");
            dto1.Ccy = "USD";
            dto1.AutoPopulateFXRate = false;
            dto1.FCToBCFXRate = 1.1458902517M;
            proxy.Insert(dto1);

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

            InvoiceDto dto2 = (InvoiceDto)proxy.GetByUid(dto1.Uid);
            dto2.FCToBCFXRate = 1.1258801678M;

            try
            {
                proxy.Update(dto2);
                throw new Exception("Expected exception not thrown.");
            }
            catch (RestException rex)
            {
                Assert.AreEqual("Sorry, FX rate cannot be changed because there are payments applied to the transaction already. Please change the FX rate on payment instead.", rex.Message, "Incorrect message.");
            }
        }
        public void InsertAdjustmentNote()
        {
            CrudProxy proxy = new InvoiceProxy();

            var dto1 = this.GetAdjustmentNote();
            proxy.Insert(dto1);

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

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

            AssertEqual(dto1, savedDto);
        }
        public void EmailPdfInvoiceUsingSpecificTemplate()
        {
            InvoiceProxy proxy = new InvoiceProxy();
            InvoiceDto saleInfo = this.GetItemSale();
            proxy.Insert(saleInfo);

            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.";
            emailMessage.Body = "Hello World. This email is sent using NetAccounts WSAPI";

            proxy.Email(saleInfo.Uid, this.IncTaxTemplateUid, emailMessage);
        }
        public void DeleteSale()
        {
            CrudProxy proxy = new InvoiceProxy();

            InvoiceDto dto1 = this.GetServiceSale();
            proxy.Insert(dto1);

            proxy.DeleteByUid(dto1.Uid);

            try
            {
                proxy.GetByUid(dto1.Uid);
            }
            catch (RestException ex)
            {
                Assert.AreEqual("RecordNotFoundException", ex.Type);
            }
        }
        public void ApplyPaymentOnUpdateCausingOverpayment()
        {
            CrudProxy proxy = new InvoiceProxy();
            InvoiceDto dto1 = this.GetUnpaidServiceSale();

            proxy.Insert(dto1);

            dto1.QuickPayment = this.GetServiceSale().QuickPayment;
            dto1.QuickPayment.Amount = 10000;

            try
            {
                proxy.Update(dto1);
                throw new Exception("Expected exception not thrown.");
            }
            catch (RestException ex)
            {
                Assert.AreEqual("InvalidInvoicePaymentException", ex.Type);
            }
        }
        public void UpdateServiceSale()
        {
            CrudProxy proxy = new InvoiceProxy();

            InvoiceDto dto1 = this.GetServiceSale();
            proxy.Insert(dto1);

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

            int invoiceUid = dto1.Uid;
            string lastUpdatedUid = dto1.LastUpdatedUid;
            string invoiceNumber = dto1.InvoiceNumber;

            dto1 = this.GetServiceSale2();
            dto1.Uid = invoiceUid;
            dto1.LastUpdatedUid = lastUpdatedUid;
            dto1.InvoiceNumber = invoiceNumber;

            proxy.Update(dto1);

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

            Assert.AreEqual("AUD", dto2.Ccy, "Incorrect Currency.");
            Assert.AreEqual(1, dto2.FCToBCFXRate, "Incorrect FXRate.");
            AssertEqual(dto1, dto2);
        }
        public void ApplyPaymentOnUpdate()
        {
            CrudProxy proxy = new InvoiceProxy();
            InvoiceDto dto1 = this.GetUnpaidServiceSale();

            proxy.Insert(dto1);

            dto1.QuickPayment = this.GetServiceSale().QuickPayment;
            proxy.Update(dto1);
        }
        public void Update_Service_Sale_Line_Item_Tags()
        {
            CrudProxy proxy = new InvoiceProxy();

            var dto1 = this.GetServiceSale();

            dto1.Tags = "Tag1, Tag2, Tag3";

            var lineItem1 = (ServiceInvoiceItemDto)dto1.Items[0];
            var lineItem2 = (ServiceInvoiceItemDto)dto1.Items[1];

            lineItem1.Tags = "LineItem1Tag1, LineItem1Tag2";
            lineItem2.Tags = "LineItem2Tag1, LineItem2Tag2";

            proxy.Insert(dto1);

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

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

            AssertEqual(dto1, savedDto);

            var line1 = (ServiceInvoiceItemDto)savedDto.Items[0];
            var line2 = (ServiceInvoiceItemDto)savedDto.Items[1];

            line1.Tags = "UpdateLineItem1Tag1, UpdateLineItem1Tag2";
            line2.Tags = "UpdateLineItem2Tag1, UpdateLineItem2Tag2";

            proxy.Update(savedDto);

            var updatedDto = (InvoiceDto)proxy.GetByUid(savedDto.Uid);
            AssertEqual(savedDto, updatedDto);
        }
        public void UpdateWithInvalidUid()
        {
            CrudProxy proxy = new InvoiceProxy();
            InvoiceDto dto1 = this.GetUnpaidServiceSale();

            proxy.Insert(dto1);

            dto1.Uid = 0;

            try
            {
                proxy.Update(dto1);
                throw new Exception("Expected exception not thrown.");
            }
            catch (RestException ex)
            {
                Assert.AreEqual("ArgumentException", ex.Type);
            }
        }
        public void InsertAndGetItemSale_Invoice_Totals_Test()
        {
            //Arange
            var proxy = new InvoiceProxy();
            var input = GetServiceSaleTotalsTest();

            var item = new ServiceInvoiceItemDto
                           {
                               Description = "Design & Development of REST WS",
                               AccountUid = this.IncomeService.Uid,
                               TaxCode = TaxCode.SaleInclGst,
                               TotalAmountInclTax = 2500.65m
                           };

            input.Items.Add(item);

            item = new ServiceInvoiceItemDto
                       {
                           Description = "Subscription to XYZ",
                           AccountUid = this.IncomeSubscription.Uid,
                           TaxCode = TaxCode.SaleInclGst,
                           TotalAmountInclTax = 11.96m
                       };

            input.Items.Add(item);

            //act
            var totalItem1 = ((ServiceInvoiceItemDto)input.Items[0]).TotalAmountInclTax;
            var totalItem2 = ((ServiceInvoiceItemDto)input.Items[1]).TotalAmountInclTax;
            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 = ((ServiceInvoiceItemDto)output.Items[0]);
            var outputLineItem2 = ((ServiceInvoiceItemDto)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 GetPdfInvoice()
        {
            InvoiceProxy proxy = new InvoiceProxy();
            InvoiceDto dto1 = this.GetItemSale();
            proxy.Insert(dto1);

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

            proxy.GetPdfInvoiceByUid(dto1.Uid, "ItemSale.pdf");									// Template not specified. Will use default template.
            proxy.GetPdfInvoiceByUid(dto1.Uid, this.IncTaxTemplateUid, "ItemSaleIncTax.pdf");	// Use specific template.
        }
        public void InsertAndGetServiceSale()
        {
            CrudProxy proxy = new InvoiceProxy();

            var dto1 = this.GetServiceSale();
            proxy.Insert(dto1);

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

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

            AssertEqual(dto1, savedDto);

            var line1 = (ServiceInvoiceItemDto)savedDto.Items[0];
            var line2 = (ServiceInvoiceItemDto)savedDto.Items[1];

            Assert.AreEqual("AUD", savedDto.Ccy, "Incorrect Currency.");
            Assert.AreEqual(1, savedDto.FCToBCFXRate, "Incorrect FXRate.");
            Assert.AreEqual(2132.51M, line1.TotalAmountInclTax, "Incorrect amount on line 1.");
            Assert.AreEqual(11.22M, line2.TotalAmountInclTax, "Incorrect amount on line 2.");

            // For testing load generation on Tag queue
            //const int numRuns = 5000;
            //CrudProxy proxy = new InvoiceProxy();
            //for (var i = 0; i < numRuns; i++)
            //{
            //    Console.WriteLine("Inserting sale #{0}", i);
            //    var dto1 = this.GetServiceSale();
            //    proxy.Insert(dto1);
            //}
        }
        public void UpdateShipToContactForServiceSale()
        {
            CrudProxy proxy = new InvoiceProxy();

            InvoiceDto dto1 = this.GetServiceSale();
            dto1.ShipToContactUid = MrsSmith.Uid;

            proxy.Insert(dto1);

            dto1.ShipToContactUid = MrsSmith.Uid;

            proxy.Update(dto1);

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

            AssertEqual(dto1, dto2);
        }
        public void InsertAndGetServiceSaleWith_TradingTerms_Due_In_28_days()
        {
            CrudProxy proxy = new InvoiceProxy();
            var dto1 = this.GetServiceSale();

            // DueIn type
            dto1.TradingTerms.TypeEnum = TradingTermsType.DueIn;

            // Days
            dto1.TradingTerms.IntervalTypeEnum = TimeIntervalType.Day;

            // 14 days.
            dto1.TradingTerms.Interval = 28;

            //should be due in 6 months form the end of the transaction date.
            var dueDate = dto1.Date.AddDays(28);

            proxy.Insert(dto1);

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

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

            //check trading terms
            Assert.AreEqual(dto1.TradingTerms.Type, savedDto.TradingTerms.Type);
            Assert.AreEqual(dto1.TradingTerms.IntervalType, savedDto.TradingTerms.IntervalType);
            Assert.AreEqual(dto1.TradingTerms.Interval, savedDto.TradingTerms.Interval);
            Assert.AreEqual(dueDate, savedDto.DueOrExpiryDate);
            Assert.AreEqual(dto1.TradingTerms.TypeEnum, savedDto.TradingTerms.TypeEnum);
            Assert.AreEqual(dto1.TradingTerms.IntervalTypeEnum, savedDto.TradingTerms.IntervalTypeEnum);
            Assert.AreEqual((int)dto1.TradingTerms.IntervalTypeEnum, savedDto.TradingTerms.IntervalType);
            Assert.AreEqual((int)dto1.TradingTerms.TypeEnum, savedDto.TradingTerms.Type);
        }
        public void DeleteSalePayment()
        {
            CrudProxy proxy = new InvoiceProxy();

            InvoiceDto sale1 = this.GetUnpaidItemSale();
            InvoiceDto sale2 = this.GetUnpaidServiceSale();

            proxy.Insert(sale1);
            proxy.Insert(sale2);

            InvoicePaymentDto paymentInfo1 = new InvoicePaymentDto(TransactionType.SalePayment);
            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.55m;

            InvoicePaymentItemDto item = null;

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

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

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

            proxy.DeleteByUid(paymentInfo1.Uid);

            try
            {
                proxy.GetByUid(paymentInfo1.Uid);
            }
            catch (RestException ex)
            {
                Assert.AreEqual("RecordNotFoundException", ex.Type);
            }
        }
        public void InsertAndGetServiceSaleWith_TradingTerms_Due_In_Specific_Date()
        {
            CrudProxy proxy = new InvoiceProxy();
            var dto1 = this.GetServiceSale();

            // DueIn type
            dto1.TradingTerms.TypeEnum = TradingTermsType.DueIn;

            // Unspecified - means actual date
            dto1.TradingTerms.IntervalTypeEnum = TimeIntervalType.Unspecified;

            //Set specific date that invoice is due in.
            var dueDate = new DateTime(2012, 12, 24);

            // Set to specific date
            dto1.DueOrExpiryDate = dueDate;

            proxy.Insert(dto1);

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

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

            //check trading terms
            Assert.AreEqual(dueDate, savedDto.DueOrExpiryDate);
            Assert.AreEqual(dto1.TradingTerms.Type, savedDto.TradingTerms.Type);
            Assert.AreEqual(dto1.TradingTerms.IntervalType, savedDto.TradingTerms.IntervalType);
            Assert.AreEqual(dto1.TradingTerms.Interval, savedDto.TradingTerms.Interval);
            Assert.AreEqual(dto1.TradingTerms.TypeEnum, savedDto.TradingTerms.TypeEnum);
            Assert.AreEqual(dto1.TradingTerms.IntervalTypeEnum, savedDto.TradingTerms.IntervalTypeEnum);
            Assert.AreEqual((int)dto1.TradingTerms.IntervalTypeEnum, savedDto.TradingTerms.IntervalType);
            Assert.AreEqual((int)dto1.TradingTerms.TypeEnum, savedDto.TradingTerms.Type);
        }
        public void DuplicateInvoiceNumber()
        {
            CrudProxy proxy = new InvoiceProxy();
            InvoiceDto dto1 = this.GetServiceSale();
            string invoiceNumber = this.TestUid + "-INV-1";
            dto1.InvoiceNumber = invoiceNumber;

            proxy.Insert(dto1);

            dto1 = this.GetServiceSale();
            dto1.InvoiceNumber = invoiceNumber;

            try
            {
                proxy.Insert(dto1);
                throw new Exception("Expected exception not thrown.");
            }
            catch (RestException ex)
            {
                Assert.AreEqual("DuplicateInvoiceNumberException", ex.Type);
            }
        }