Example #1
0
        public async Task <ActionResult <InvoiceApi> > GetInvoice(Guid id)
        {
            var _invoive = await _context.Invoices.FindAsync(id);

            if (_invoive == null)
            {
                return(NotFound());
            }

            var _client = await _context.Clients.FindAsync(id);

            var _products = await _context.Products.Where(w => w.invoice_id == id).ToArrayAsync();

            var _payments = await _context.Payments.Where(w => w.invoice_id == id).ToArrayAsync();

            var result = new InvoiceApi();

            result.invoice_id     = _invoive.invoice_id;
            result.lines          = _products;
            result.client         = _client;
            result.payments       = _payments;
            result.tax_total      = _invoive.tax_total;
            result.discount_total = _invoive.discount_total;
            result.subtotal       = _invoive.subtotal;
            result.total          = _invoive.total;
            result.balance        = _invoive.balance;

            return(result);
        }
Example #2
0
        public async Task <ActionResult <IEnumerable <InvoiceApi> > > GetInvoices()
        {
            var _invoices = await _context.Invoices.ToListAsync();

            var _invoicesResponse = new List <InvoiceApi>();

            foreach (Invoice i in _invoices)
            {
                var _response = new InvoiceApi();
                var _client   = await _context.Clients.FindAsync(i.invoice_id);

                var _products = await _context.Products.Where(w => w.invoice_id == i.invoice_id).ToArrayAsync();

                var _payments = await _context.Payments.Where(w => w.invoice_id == i.invoice_id).ToArrayAsync();

                _response.invoice_id     = i.invoice_id;
                _response.lines          = _products;
                _response.client         = _client;
                _response.payments       = _payments;
                _response.tax_total      = i.tax_total;
                _response.discount_total = i.discount_total;
                _response.subtotal       = i.subtotal;
                _response.total          = i.total;
                _response.balance        = i.balance;

                _invoicesResponse.Add(_response);
            }

            return(Ok(new { response = _invoicesResponse }));
        }
Example #3
0
 public CartViewModel(INavigation navigation, ObservableCollection <clsInvoice> items, TBillCount tbill)
 {
     total            = new TBillCount();
     this.Items       = items;
     _InvoiceApi      = new InvoiceApi();
     this.total       = tbill;
     this.navigation1 = navigation;
 }
        public List<InvoiceFindResult> CollectInvoices(string filter)
        {
            InvoiceApi api = new InvoiceApi(site, company, username, password, cookie);

            List<InvoiceFindResult> results = api.FindInvoices(filter, "Id", null, null, null, returnFields);
            logger.Info("Found " + results.Count + " invoices");
            return results;
        }
        public List <InvoiceFindResult> CollectInvoices(string filter)
        {
            InvoiceApi api = new InvoiceApi(site, company, username, password, cookie);

            List <InvoiceFindResult> results = api.FindInvoices(filter, "Id", null, null, null, returnFields);

            logger.Info("Found " + results.Count + " invoices");
            return(results);
        }
        private EntityAPI <W> GetApi <T, W>() where T : EntityAPI <W>
            where W : Entity
        {
            InvoiceApi api         = new InvoiceApi(_config);
            var        existingApi = _apis.Find(a => a.GetType() == typeof(T));

            return((EntityAPI <W>)(existingApi ?? typeof(T)
                                   .GetConstructor(
                                       new Type[]
            {
                typeof(Configuration)
            })
                                   .Invoke(new[]
            {
                _config
            })));
        }
Example #7
0
        public GetAddesssApi(ApiKey apiKey, AdminKey adminKey, HttpClient httpClient = null)
        {
            _client = httpClient ?? new HttpClient();

            _client.BaseAddress = _baseAddress;

            _client.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json");

            AdminKey = adminKey;

            ApiKey = apiKey;

            DomainWhitelist = new DomainWhitelistApi(AdminKey, this);

            IpAddressWhitelist = new IpAddressWhitelistApi(AdminKey, this);

            PrivateAddress = new PrivateAddressApi(AdminKey, this);

            Usage = new UsageApi(AdminKey, this);

            BillingAddress = new BillingAddressApi(AdminKey, this);

            Address = new AddressApi(ApiKey, this);

            FirstLimitReachedWebhook = new FirstLimitReachedWebhookApi(AdminKey, this);

            Subscription = new SubscriptionApi(adminKey, this);

            ApiKeyApi = new ApiKeyApi(adminKey, this);

            EmailAddress = new EmailAddressApi(adminKey, this);

            Invoices = new InvoiceApi(adminKey, this);

            InvoiceCC = new InvoiceCCApi(adminKey, this);
        }
        public async Task <IActionResult> Get(DateTime?fromDate, DateTime?toDate)
        {
            if (!fromDate.HasValue || !toDate.HasValue)
            {
                if (!fromDate.HasValue)
                {
                    ModelState.AddModelError("fromDate", "Required Date is null or empty.");
                }
                if (!toDate.HasValue)
                {
                    ModelState.AddModelError("toDate", "Required Date is null or empty.");
                }
                return(new BadRequestObjectResult(ModelState));
            }

            var dateSpanDays = (toDate.Value - fromDate.Value).TotalDays + 1;

            if (dateSpanDays > 31)
            {
                ModelState.AddModelError("", "Date timespan is more than 31 days.");
                return(new BadRequestObjectResult(ModelState));
            }

            var fromDateValue = fromDate.Value;
            var toDateValue   = toDate.Value;

            var invoice = new InvoiceApi
            {
                FromDate = fromDateValue,
                ToDate   = toDateValue,
            };

            var partitionId = CurrentPartitionId;

            invoice.GroupTasks = DbContext.TaskItems.Where(ti => ti.Task.Group.PartitionId == partitionId && ti.Time > 0 && ti.Date >= fromDateValue && ti.Date <= toDateValue)
                                 .OrderBy(ti => ti.Task.Group.Name).ThenBy(ti => ti.Task.Name).GroupBy(ti => new { Group = ti.Task.Group.Name, Task = ti.Task.Name })
                                 .Select(gw => new InvoiceGroupTaskApi
            {
                Group = gw.Key.Group,
                Task  = gw.Key.Task,
                Time  = gw.Sum(ti => ti.Time),
                Users = gw.OrderBy(ti => ti.User.FullName).GroupBy(ti => ti.UserId)
                        .Select(ggw => new InvoiceUserApi
                {
                    Id       = ggw.Key,
                    FullName = ggw.Select(ti => ti.User.FullName).FirstOrDefault(),
                    Time     = ggw.Sum(ti => ti.Time),
                }).ToList()
            }).AsNoTracking().ToList();

            var hourPriceLogic = new HourPriceLogic(DbContext, CurrentPartitionId);

            invoice.TotalTime = invoice.GroupTasks.Sum(gt => gt.Time);

            invoice.SubTotalPrice = 0;
            foreach (var gt in invoice.GroupTasks)
            {
                foreach (var user in gt.Users)
                {
                    user.HourPrice = hourPriceLogic.GetHourPrice(gt.Group, gt.Task, user.Id).Result?.HourPrice;
                    if (user.HourPrice.HasValue)
                    {
                        user.Price             = user.HourPrice.Value * user.Time / 60;
                        invoice.SubTotalPrice += user.Price.Value;
                    }
                }
                gt.Price = gt.Users.Sum(u => u.Price);
            }

            return(await Task.FromResult(Json(invoice)));
        }
Example #9
0
 public void Init()
 {
     instance = new InvoiceApi();
 }