public void TestXeroLogin()
        {
            //  var test = InboundInvoice.GetAllAquariumPurchaseInvoiceNumbers();

            List<InterResolveXeroService> AllTheInterResolveCompanies = new List<InterResolveXeroService>();

            InterResolveXeroService InterResolve_LtdService = new InterResolveXeroService(InterResolveXeroService.InterResolveXeroOrganisation.InterResolve_Ltd);
            InterResolveXeroService MotorResolve_LtdService = new InterResolveXeroService(InterResolveXeroService.InterResolveXeroOrganisation.MotorResolve_Ltd);
            InterResolveXeroService InterMediation_Group_LtdService = new InterResolveXeroService(InterResolveXeroService.InterResolveXeroOrganisation.InterMediation_Group_Ltd);
            InterResolveXeroService InterResolve_Claims_LtdService = new InterResolveXeroService(InterResolveXeroService.InterResolveXeroOrganisation.InterResolve_Claims_Ltd);
            //    InterResolveXeroService InterResolve_Holdings_LtdService = new InterResolveXeroService(InterResolveXeroService.InterResolveXeroOrganisation.InterResolve_Holdings_Ltd);

            AllTheInterResolveCompanies.Add(InterResolve_LtdService);
            AllTheInterResolveCompanies.Add(MotorResolve_LtdService);
            AllTheInterResolveCompanies.Add(InterMediation_Group_LtdService);
            AllTheInterResolveCompanies.Add(InterResolve_Claims_LtdService);
              //      AllTheInterResolveCompanies.Add(InterResolve_Holdings_LtdService);

            OutboundInvoiceLineItemList someInvoices = new OutboundInvoiceLineItemList();

            someInvoices.Get();

            XeroApi.Model.Invoice anInvoice = OutboundInvoiceLineItem.ConvertSingleLineItemOutboundInvoiceToXeroInvoice(someInvoices.OutboundInvoiceLineItems.FirstOrDefault());

            foreach (var company in AllTheInterResolveCompanies)
            {
                company.LoginToXero();
                anInvoice.LineItems.ElementAt(0).LineAmount = 20;
                anInvoice.LineItems.ElementAt(0).UnitAmount = 20;

                XeroApi.Model.Contact theXeroContact = new XeroApi.Model.Contact();
                theXeroContact.Name = "Test Contact";

                anInvoice.Contact = theXeroContact;
                var InvoiceResponse = company.XeroRepository.Create<XeroApi.Model.Invoice>(anInvoice);
            }
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "Contact,Date,Type,DueDate,Status")] Invoice invoice)
        {
            if (invoice.Date < DateTime.Now.AddDays(-1))
            {
                ModelState.AddModelError("Date", "Date must be today or a future time");
            }
            if (invoice.DueDate < invoice.Date)
            {
                ModelState.AddModelError("DueDate", "DueDate must be greater than the Start Date");
            }


            //in real app we also need to check the existence of the contact

            if (ModelState.IsValid)
            {
                var XeroSession = new XeroApi.OAuth.XeroApiPrivateSession("MyApiTestSoftware", "5INHEEY7VVKTPZPBMTF9BRCDN33KGM", new X509Certificate2("C:\\OpenSSL-Win32\\bin\\public_privatekey.pfx"));
                var repository  = new XeroApi.Repository(XeroSession);

                var contacts = repository.Contacts.Where(c => c.Name == "Marine Systems");

                //new comment

                var uInvoice = new XeroApi.Model.Invoice();
                var uContact = new XeroApi.Model.Contact();

                DateTime today   = DateTime.Now;
                DateTime duedate = today.AddDays(30);

                uContact.Name = "Marine Systems";

                uInvoice.Contact = uContact;
                //uInvoice.Date = DateTime.Now;
                uInvoice.Date = invoice.Date;
                uInvoice.Type = "ACCREC";
                //uInvoice.DueDate = duedate;
                uInvoice.DueDate         = invoice.DueDate;
                uInvoice.Status          = "AUTHORISED";
                uInvoice.FullyPaidOnDate = today;
                uInvoice.AmountPaid      = 230;



                uInvoice.LineItems = new XeroApi.Model.LineItems();
                var uLineItem1 = new XeroApi.Model.LineItem();
                uLineItem1.Quantity    = 1;
                uLineItem1.Description = "Product 1";
                uLineItem1.AccountCode = "200";
                uLineItem1.UnitAmount  = 50;
                uInvoice.LineItems.Add(uLineItem1);

                var uLineItem2 = new XeroApi.Model.LineItem();
                uLineItem2.Quantity    = 3;
                uLineItem2.Description = "Product 2";
                uLineItem2.AccountCode = "200";
                uLineItem2.UnitAmount  = 50;
                uInvoice.LineItems.Add(uLineItem2);

                var sResults = repository.Create((XeroApi.Model.Invoice)uInvoice);

                var theAccount = repository.Accounts.FirstOrDefault();

                //the following section is to create a payment for the invoice
                var invoiceNumber = sResults.InvoiceNumber;
                var invoiceID     = sResults.InvoiceID;
                var NewInvoice    = repository.Invoices.Where(i => i.InvoiceID == invoiceID).FirstOrDefault();

                //var account = repository.Accounts.Where(a => a.Name == "MyAccount").FirstOrDefault();
                var account = new XeroApi.Model.Account();

                //account.ReportingCode = "ABC";

                var Payment = new XeroApi.Model.Payment();
                //Payment.Account = (XeroApi.Model.Account)account;
                Payment.Account = theAccount;
                Payment.Invoice = (XeroApi.Model.Invoice)NewInvoice;
                Payment.Invoice.InvoiceNumber = invoiceNumber.ToString();
                Payment.Invoice.InvoiceID     = invoiceID;
                Payment.Status = "AUTHORISED";
                Payment.Date   = DateTime.Now;
                Payment.Amount = 200;

                var paymentResults = repository.Create((XeroApi.Model.Payment)Payment);

                db.Invoice.Add(invoice);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(invoice));
        }