Ejemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            var token = await _tokenService.GetAccessTokenAsync(User.XeroUserId());

            var connections = await _xeroClient.GetConnectionsAsync(token);

            var tenantId = connections[0].TenantId.ToString();

            var invoices = await _accountingApi.GetInvoicesAsync(token.AccessToken, tenantId);

            return(View(invoices._Invoices));
        }
Ejemplo n.º 2
0
        private Contacts GetContact(Guid contactId)
        {
            if (Token == null)
            {
                return(null);
            }

            var connections = Client.GetConnectionsAsync(Token).Result;

            var contact = _accountingApi.GetContactAsync(Token.AccessToken, connections[0].TenantId.ToString()
                                                         , contactId).Result;

            return(contact);
        }
        public async Task <IActionResult> OutstandingInvoices()
        {
            var token = await _tokenStore.GetAccessTokenAsync(User.XeroUserId());

            var connections = await _xeroClient.GetConnectionsAsync(token);

            if (!connections.Any())
            {
                return(RedirectToAction("NoTenants"));
            }

            var data = new Dictionary <string, int>();

            foreach (var connection in connections)
            {
                var accessToken = token.AccessToken;
                var tenantId    = connection.TenantId.ToString();

                var organisations = await _accountingApi.GetOrganisationsAsync(accessToken, tenantId);

                var organisationName = organisations._Organisations[0].Name;

                var outstandingInvoices = await _accountingApi.GetInvoicesAsync(accessToken, tenantId, statuses : "AUTHORISED", where : "Type == \"ACCREC\"");

                data[organisationName] = outstandingInvoices._Invoices.Count;
            }

            var model = new OutstandingInvoicesViewModel
            {
                Name = $"{User.FindFirstValue(ClaimTypes.GivenName)} {User.FindFirstValue(ClaimTypes.Surname)}",
                Data = data
            };

            return(View(model));
        }
        public async Task <IActionResult> TenantClientLists()
        {
            var token = await _tokenStore.GetAccessTokenAsync(User.XeroUserId());

            var connections = await _xeroClient.GetConnectionsAsync(token);

            connections = connections.Where(c => c.TenantType == "PRACTICEMANAGER").ToList();

            if (!connections.Any())
            {
                return(RedirectToAction(nameof(NoTenants)));
            }

            var data = new List <(Guid tenantId, ClientListResponse clients)>();

            var client = _httpClientFactory.CreateClient("XeroPracticeManager");

            client.SetBearerToken(token.AccessToken);

            //Retrieve the WorkflowMax clients for each connection we have access to
            foreach (var connection in connections)
            {
                ClientListResponse clients = await GetClients(client, connection.TenantId);

                data.Add((connection.TenantId, clients));
            }

            var model = new TenantClientListsModel
            {
                LoggedInUser  = $"{User.FindFirstValue(ClaimTypes.GivenName)} {User.FindFirstValue(ClaimTypes.Surname)}",
                TenantClients = data
            };

            return(View(model));
        }
        public async Task <IActionResult> Create(FromFormAttribute formData)
        {
            var token = await _tokenService.GetAccessTokenAsync(User.XeroUserId());

            var connections = await _xeroClient.GetConnectionsAsync(token);

            var tenantId = connections[0].TenantId.ToString();

            Payment payment = new Payment()
            {
                Invoice = new Invoice()
                {
                    InvoiceNumber = "INV-0002"
                },
                Account = new Account()
                {
                    Code = "200"
                },
                Date   = DateTime.Now,
                Amount = 3
            };

            await _accountingApi.CreatePaymentAsync(token.AccessToken, tenantId, payment);

            return(RedirectToAction("Index", "Invoices"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> OutstandingInvoices()
        {
            var token = await _tokenStore.GetAccessTokenAsync(User.XeroUserId());

            var connections = await _xeroClient.GetConnectionsAsync(token);

            if (!connections.Any())
            {
                return(RedirectToAction("NoTenants"));
            }
            var data = new Dictionary <string, int>();

            foreach (var connection in connections)
            {
                //Console.WriteLine("Connection ID :"+connection.id);
                var accessToken   = token.AccessToken;
                var refreshToken  = token.RefreshToken;
                var tenantId      = connection.TenantId.ToString();
                var organisations = await _accountingApi.GetOrganisationsAsync(accessToken, tenantId);

                var accounts = await _accountingApi.GetAccountsAsync(accessToken, tenantId);

                for (int i = 0; i < organisations._Organisations.Count(); i++)
                {
                    await ImportContactDetails(accessToken, tenantId);
                    await FetchInvoicesFromDb(accessToken, tenantId);
                }
            }/*
              * for(int i = 0; i < organisations._Organisations.Count(); i++)
              * {
              *     Console.WriteLine("\nOrganisation #"+i+" is "+organisations._Organisations[i].Name);
              *     Console.WriteLine("\nImport for this organisation ? Press Y to confirm or any other button to continue..");
              *     char input = Console.ReadKey().KeyChar;
              *     if(input.ToString().ToUpper() == "Y" )
              *     {
              *         await ImportContactDetails(accessToken, tenantId);
              *         await FetchInvoicesFromDb(accessToken, tenantId);
              *         goto Foo;
              *     }
              * }
              * }
              * Foo:*/
            var model = new OutstandingInvoicesViewModel
            {
                Name = $"{User.FindFirstValue(ClaimTypes.GivenName)} {User.FindFirstValue(ClaimTypes.Surname)}",
                Data = data
            };

            return(View(model));
        }