Esempio n. 1
0
 public ProxyResponse<UpdateInvoiceResult> UpdateInvoice(int invoiceId, InvoiceTransactionDetail invoiceDetail)
 {
     OperationMethod = HttpMethod.Put;
     _requestPrefix = ResourceNames.Invoice;
     var uri = base.GetRequestUri(invoiceId.ToString());
     return base.GetResponse<InvoiceTransactionDetail, UpdateInvoiceResult>(uri, invoiceDetail);
 }
Esempio n. 2
0
 public ProxyResponse<InsertInvoiceResult> InsertInvoice(InvoiceTransactionDetail invoiceDetail)
 {
     _requestPrefix = ResourceNames.Invoice;
     OperationMethod = HttpMethod.Post;
     var uri = base.GetRequestUri(null);
     return base.GetResponse<InvoiceTransactionDetail, InsertInvoiceResult>(uri, invoiceDetail);
 }
Esempio n. 3
0
        private InvoiceTransactionDetail GetUpdatedInvoice(int tranId, string lastUpdatedId, bool emailToContact = false, InvoiceTransactionDetail invoiceToCopyFrom = null)
        {
            Assert.IsTrue(tranId > 0, "A valid transactionId mus be passed into the GetUpdatedSaleInvoice method");

            var returnInvoice = new InvoiceTransactionDetail();

            if (invoiceToCopyFrom != null)
            {
                returnInvoice = invoiceToCopyFrom;
                returnInvoice.InvoiceNumber = string.Format("Inv{0}", Guid.NewGuid());
                returnInvoice.PurchaseOrderNumber = string.Format("PO{0}", Guid.NewGuid());
                returnInvoice.NotesInternal = "Test internal update note";
                returnInvoice.NotesExternal = "Test external update note";
                returnInvoice.Summary = "Summary Update";
                returnInvoice.Tags = new List<string> { "updated header tag 1", "updated header tag 2" };
                returnInvoice.Terms = new InvoiceTradingTerms
                {
                    Type = 2,
                    Interval = 5,
                    IntervalType = 1
                };
                returnInvoice.Attachments = null;
                returnInvoice.RequiresFollowUp = true;
                returnInvoice.SendEmailToContact = emailToContact;

                return returnInvoice;
            }

            return new InvoiceTransactionDetail
            {
                TransactionId = tranId,
                LastUpdatedId = lastUpdatedId,
                NotesInternal = "Test internal update note",
                NotesExternal = "Test external update note",
                Terms = new InvoiceTradingTerms
                {
                    Type = 2,
                    Interval = 5,
                    IntervalType = 1
                },
                Attachments = null,
                InvoiceNumber = string.Format("Inv{0}", Guid.NewGuid()),
                PurchaseOrderNumber = string.Format("PO{0}", Guid.NewGuid()),
                Summary = "Summary Update",
                RequiresFollowUp = true,
                BillingContactId = _ShippingContactId, //swap the contacts
                ShippingContactId = _BillingContactId,
                Tags = new List<string> { "updated header tag 1", "updated header tag 2" },
                SendEmailToContact = emailToContact
            };
        }
Esempio n. 4
0
        private void VerifyInvoicesAreEqual(InvoiceTransactionDetail inv1, InvoiceTransactionDetail inv2)
        {
            Assert.AreEqual(inv1.NotesInternal, inv2.NotesInternal, "Internal Notes are different");
            Assert.AreEqual(inv1.NotesExternal, inv2.NotesExternal, "External Notes are different");
            Assert.AreEqual(inv1.TemplateId, inv2.TemplateId, "TemplateIds are different");
            Assert.AreEqual(inv1.Currency, inv2.Currency, "Currency is different");
            Assert.AreEqual(inv1.TransactionType, inv2.TransactionType, "TransactionType is different");
            Assert.AreEqual(inv1.AutoPopulateFxRate, inv2.AutoPopulateFxRate, "AutoPopulateFxRate is different");

            switch (inv1.TransactionType)
            {
                case "S":
                    {
                        if (inv1.InvoiceNumber == AutoNumber)
                        {
                            Assert.AreNotEqual(inv1.InvoiceNumber, inv2.InvoiceNumber, "InvoiceNumber are equal but expected to be different");
                        }
                        else
                        {
                            Assert.AreEqual(inv1.InvoiceNumber, inv2.InvoiceNumber, "InvoiceNumber is different");
                        }
                    }
                    break;
                case "P":
                    {
                        if (inv1.PurchaseOrderNumber == AutoNumber)
                        {
                            Assert.AreNotEqual(inv1.PurchaseOrderNumber, inv2.PurchaseOrderNumber, "Purchase Order Number are the same but expected to be different");
                        }
                        else
                        {
                            Assert.AreEqual(inv1.PurchaseOrderNumber, inv2.PurchaseOrderNumber, "Purchase Order number is different");
                        }
                    }
                    break;
            }

            // Cannot assert this here as it gets changed base don whether consumer changes the flag, or consumer asks email to be sent in whch
            // case this flag gets set as well
            //Assert.AreEqual(inv1.SentToContact, inv2.SentToContact);

            Assert.AreEqual(inv1.RequiresFollowUp, inv2.RequiresFollowUp, "RequiresFollowUp is different");

            Assert.AreEqual(inv1.InvoiceType, inv2.InvoiceType, "InvoiceType is different");
            Assert.AreEqual(inv1.Layout, inv2.Layout, "Layout is different");
            Assert.AreEqual(inv1.Summary, inv2.Summary, "Summary is different");
            //Assert.AreEqual(inv1.TotalAmountExcludingTax, inv2.TotalAmountExcludingTax);-- leave out as calcs currently come from items
            //Assert.AreEqual(inv1.TotalTaxAmount, inv2.TotalTaxAmount); -- leave out as calcs currently come from items
            //Assert.AreEqual(inv1.TotalAmountInclTax, inv2.TotalAmountInclTax); -- leave out as calcs currently come from items
            var inv1Date = Convert.ToDateTime(inv1.TransactionDate).Date;
            var inv2Date = Convert.ToDateTime(inv2.TransactionDate).Date;
            Assert.AreEqual(inv1Date.Year, inv2Date.Year, "Year is different");
            Assert.AreEqual(inv1Date.Month, inv2Date.Month, "Month is different");
            Assert.AreEqual(inv1Date.Day, inv2Date.Day, "Day is different");
            //Assert.AreEqual(Convert.ToDateTime(inv1.TransactionDate).Date, Convert.ToDateTime(inv2.TransactionDate).Date);
            Assert.AreEqual(inv1.BillingContactId.GetValueOrDefault(), inv2.BillingContactId.GetValueOrDefault(), "BillingContactId is different");
            Assert.AreEqual(inv1.ShippingContactId.GetValueOrDefault(), inv2.ShippingContactId.GetValueOrDefault(), "ShippingContactId is different");

            VerifyInvoiceItemsAreEqual(inv1.Layout, inv1.LineItems, inv2.LineItems);
            VerifyInvoiceTermsAreEqual(inv1.Terms, inv2.Terms);
            VerifyInvoiceAttachmentsAreEqual(inv1.Attachments, inv2.Attachments);
            VerifyInvoiceEmailMessagesAreEqual(inv1.EmailMessage, inv2.EmailMessage);
        }
Esempio n. 5
0
        private InvoiceTransactionDetail GetTestInsertInvoice(string invoiceLayout, List<InvoiceTransactionLineItem> lineItems = null, string notesInternal = null,
            string notesExternal = null, InvoiceTradingTerms terms = null, List<FileAttachmentInfo> attachments = null, int? templateId = null,
            bool emailContact = false, Saasu.API.Core.Models.Email emailMessage = null, string currency = null, string invoiceNumber = null, string purchaseOrderNumber = null,
            string invoiceType = null, string transactionType = null, string summary = null, decimal? totalAmountInclTax = null, bool requiresFollowUp = false, DateTime? transactionDate = null,
            int? billingContactId = null, int? shippingContactId = null, List<string> tags = null, decimal? fxRate = null, string invoiceStatus = null,
            bool actuallyInsertAndVerifyResponse = false, bool autoPopulateFxRate = false)
        {
            var tranType = transactionType ?? "S";

            var invDetail = new InvoiceTransactionDetail
                {
                    LineItems = lineItems ?? GetInsertItems(invoiceLayout, tranType),
                    NotesInternal = notesInternal ?? "Test internal note",
                    NotesExternal = notesExternal ?? "Test external note",
                    Terms = terms ?? GetTradingTerms(),
                    Attachments = attachments ?? GetAttachments(),
                    TemplateId = templateId ?? GetTemplateUid(),
                    SendEmailToContact = emailContact,
                    EmailMessage = emailMessage ?? GetEmailMessage(),
                    Currency = currency ?? "AUD",
                    InvoiceNumber = invoiceNumber ?? AutoNumber,
                    PurchaseOrderNumber = purchaseOrderNumber ?? AutoNumber,
                    InvoiceType = invoiceType ?? "Tax Invoice",
                    TransactionType = tranType,
                    Layout = invoiceLayout,
                    Summary = summary ?? "Summary InsertInvoiceWithServiceItemsNoEmailToContact",
                    TotalAmount = totalAmountInclTax ?? new decimal(20.00),
                    IsTaxInc = true,
                    RequiresFollowUp = requiresFollowUp,
                    TransactionDate = transactionDate ?? DateTime.Now.AddDays(-10),
                    BillingContactId = billingContactId ?? _BillingContactId,
                    ShippingContactId = shippingContactId ?? _ShippingContactId,
                    FxRate = fxRate,
                    AutoPopulateFxRate = autoPopulateFxRate,
                    InvoiceStatus = invoiceStatus,
                    Tags = tags ?? new List<string> { "invoice header tag 1", "invoice header tag 2" }
                };

            if (actuallyInsertAndVerifyResponse)
            {
                var response = new InvoiceProxy().InsertInvoice(invDetail);

                Assert.IsNotNull(response, "Inserting an invoice did not return a response");
                Assert.IsTrue(response.IsSuccessfull, "Inserting an invoice was not successfull. Status code: " + ((int)response.StatusCode).ToString());
                Assert.IsNotNull(response.RawResponse, "No raw response returned as part of inserting an invoice");

                var serialized = response.DataObject;

                Assert.IsTrue(serialized.InsertedEntityId > 0, "Invoice insert did not return an InsertedEntityId > 0");

                invDetail.TransactionId = serialized.InsertedEntityId;
            }

            return invDetail;
        }