Exemplo n.º 1
0
        public object Get(Invoices request)
        {
            DateTime startDate, endDate;

            endDate   = request.end_date ?? DateTime.UtcNow;
            startDate = request.start_date ?? endDate.Date.AddDays(-365);
            startDate = startDate.Date;
            endDate   = endDate.Date.AddDays(1).AddSeconds(-1);
            ApiUser hdUser = request.ApiUser;
            List <Models.Invoice> invoices = null;

            return(base.RequestContext.ToOptimizedResultUsingCache(base.Cache, string.Format("urn:{0}:{1}{2}", base.Request.GetBasicAuth(), base.Request.PathInfo.Substring(1), (base.Request.QueryString.Count > 0 ? ":" + base.Request.QueryString.ToString() : "")),
                                                                   new System.TimeSpan(0, 0, 0), () =>
            {
                if ("unbilled" == request.status)
                {
                    invoices = Models.Invoices.GetInvoicesUnbilled(hdUser.OrganizationId, hdUser.DepartmentId, hdUser.UserId, startDate, endDate, request.project, request.account);
                }
                else
                {
                    invoices = Models.Invoices.GetInvoices(hdUser.OrganizationId, hdUser.DepartmentId, hdUser.UserId, startDate, endDate, request.project, request.account);
                }

                if (invoices.Count == 1)
                {
                    //invoices[0].AddDetails(hdUser.OrganizationId, hdUser.DepartmentId, startDate, endDate, false, request.time_logs, request.travel_logs, request.expenses, request.retainers, request.adjustments);
                    if (request.account.HasValue && request.account != 0 && "unbilled" == request.status)
                    {
                        bigWebApps.bigWebDesk.Data.Invoice.CalculateStartSopDates(hdUser.OrganizationId, hdUser.DepartmentId, out startDate, out endDate, request.account.Value, request.project ?? 0);
                        invoices[0].BeginDate = startDate;
                        invoices[0].EndDate = endDate;
                    }
                    invoices[0].recipients = AccountUsers.GetAccountUsers(hdUser.OrganizationId, hdUser.DepartmentId, invoices[0].AccountId);
                    return invoices;
                }
                return request.FilteredResult <Models.Invoice>(invoices);
            }));
        }