public async Task <LoadResult> Get(DataSourceLoadOptions loadOptions, [FromQuery] AccountingRecordsSearchRequest request)
        {
            var response =
                await _accountingRecordsService.Search(request) as WrappedResponse <IQueryable <AccountingRecord> >;

            return(await DataSourceLoader.LoadAsync(response?.Data, loadOptions));
        }
        private void OnValidEvaluate(object sender, EvaluateInternalEventArgs evaluateInternalEventArgs)
        {
            var bookingsRepo = ServiceProvider.GetService <IRepository <Ltms.Bookings> >();

            var query = bookingsRepo.FindAll().Where(b =>
                                                     !b.DeleteTime.HasValue && b.BookingTypeId != "POOL" && b.BookingTypeId != "STORNO").AsNoTracking();
            var mapper = ServiceProvider.GetService <IMapper>();

            var accountingRecords = query.ProjectTo <IEnumerable <AccountingRecord> >(mapper.ConfigurationProvider);

            var _context = ServiceProvider.GetService <Dal.OlmaDbContext>();

            var _ltmsReferenceLookupService = ServiceProvider.GetService <ILtmsReferenceLookupService>();
            var authData = ServiceProvider.GetService <IAuthorizationDataService>();
            AccountingRecordsSearchRequest request = Context.Parent.Parent;

            var isDplEmployee     = authData.GetUserRole() == UserRole.DplEmployee;
            var postingAccountIds = authData.GetPostingAccountIds().ToArray();
            var accountIds        = _ltmsReferenceLookupService.GetLtmsAccountIds(postingAccountIds).Select(i => i.Value);

            var ltmsPalletInfos = _ltmsReferenceLookupService
                                  .GetLtmsPalletInfos();

            // Using SQL is neccessary as efcore does not support full outer joins
            // We could move this into a view but right now this is the only place where it is needed
            IQueryable <LtmsAccoutingRecord> queryOld = _context.LtmsAccoutingRecords.FromSqlRaw(@"
SELECT
	CASE WHEN B.Id is not null THEN 'B' + CAST(B.Id AS VARCHAR(50)) ELSE 'P' + CAST(PR.Id AS VARCHAR(50)) END AS Id,
	B.Id as BookingId,
	PR.Id as PostingRequestId
FROM LTMS.Bookings B
FULL OUTER JOIN dbo.PostingRequests PR on B.RowGuid = PR.RowGuid and PR.Status <> 1
WHERE B.DeleteTime IS NULL AND B.BookingType_ID != 'POOL' AND B.BookingType_ID != 'STORNO' AND (B.Account_ID IN (" +
                                                                                                 string.Join(",", accountIds.Select(n => n.ToString()).ToArray()) +
                                                                                                 "))") //TODO: add isDplEmployee -statement
                                                        .Include(i => i.Booking).ThenInclude(i => i.Transaction).ThenInclude(i => i.Process)
                                                        .Include(i => i.Booking).ThenInclude(i => i.ReportBookings).ThenInclude(i => i.Report)
                                                        .Include(i => i.Booking).ThenInclude(i => i.OlmaPostingAccount)
                                                        .Include(i => i.PostingRequest).ThenInclude(i => i.DplNote)
                                                        .IgnoreQueryFilters()
                                                        //.Where(i => i.Booking == null || (i.Booking.DeleteTime == null &&( isDplEmployee || accountIds.Contains(i.Booking.AccountId))))
                                                        .Where(i => i.PostingRequest == null || (isDplEmployee ||
                                                                                                 (postingAccountIds.Contains(i.PostingRequest
                                                                                                                             .PostingAccountId) ||
                                                                                                  accountIds.Contains(
                                                                                                      i.PostingRequest.SourceRefLtmsAccountId) ||
                                                                                                  accountIds.Contains(i.PostingRequest
                                                                                                                      .DestinationRefLtmsAccountId))))
            ;


            var queryCount = queryOld.Count();


            Context.AccountingRecordPaginationResult = null;
        }
예제 #3
0
        public async Task <IWrappedResponse> Search(AccountingRecordsSearchRequest request)
        {
            var query = _ltmsBookingsRepo.FindAll().Where(b =>
                                                          b.AccountId == request.RefLtmsAccountId &&
                                                          b.ArticleId == request.RefLtmsArticleId &&
                                                          !b.DeleteTime.HasValue &&
                                                          b.BookingTypeId != "POOL" &&
                                                          b.BookingTypeId != "STORNO")
                        .AsNoTracking();

            switch (request.Status)
            {
            case AccountingRecordStatus.Canceled:
                query = query.Where(b => b.Transaction.CancellationId != null);
                break;

            case AccountingRecordStatus.Coordinated:
                query = query.Where(b => b.Transaction.CancellationId == null &&
                                    b.Matched);
                break;

            case AccountingRecordStatus.InCoordination:
                query = query.Where(b => b.Transaction.CancellationId == null &&
                                    b.IncludeInBalance &&
                                    !b.Matched &&
                                    b.ReportBookings.Any(rb => rb.Report.DeleteTime == null &&
                                                         rb.Report.ReportStateId == "U"));
                break;

            case AccountingRecordStatus.Uncoordinated:
                query = query.Where(b => b.Transaction.CancellationId == null &&
                                    b.IncludeInBalance &&
                                    !b.Matched &&
                                    b.ReportBookings.All(rb => rb.Report.DeleteTime == null &&
                                                         rb.Report.ReportStateId == "I"));
                break;

            case AccountingRecordStatus.Provisional:
                query = query.Where(b => b.Transaction.CancellationId == null &&
                                    !b.IncludeInBalance);
                break;
            }

            var accountingRecords = query.ProjectTo <AccountingRecord>(Mapper.ConfigurationProvider);

            return(Ok(accountingRecords));
        }
예제 #4
0
 public MainRule(AccountingRecordsSearchRequest request, IRule parentRule = null)
 {
     // Create Context
     Context    = new ContextModel(request, this);
     ParentRule = parentRule;
 }