<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Purchasing.Core.Domain;
using UCDArch.Core.PersistanceSupport;

namespace Purchasing.Web.Models
{
    public class FilteredOrderListModelDto
    {
        public List<OrderHistoryDto> OrderHistoryDtos { get; set; }

        public class OrderHistoryDto
        {
            public Order Order { get; set; }
            public string Workgroup { get; set; }
            public WorkgroupVendor Vendor { get; set; }
            public string CreatedBy { get; set; }
            public string Status { get; set; }
        }

        // for building dropdown list
        public List<Tuple<string, string>> OrderStatusCodes { get; set; }
        
        public string SelectedOrderStatus { get; set; }
        public bool ShowPending { get; set; }
        [Display(Name = "Created After")]
        public DateTime? StartDate { get; set; }
        [Display(Name = "Created Before")]
        public DateTime? EndDate { get; set; }
        public ColumnPreferences ColumnPreferences { get; set; }
        public string ShowLast { get; set; }

        /// <summary>
        /// Returns true if the user wants to view a column that requires order tracking info
        /// </summary>
        /// <remarks>
        /// Anything that shows "acted on" info will require order tracking history info
        /// </remarks>
        /// <returns></returns>
        public bool RequresOrderTracking()
        {
            return ColumnPreferences.ShowDaysNotActedOn || ColumnPreferences.ShowLastActedOnBy ||
                   ColumnPreferences.ShowLastActedOnDate;
        }

        public void PopulateStatusCodes(IRepositoryWithTypedId<OrderStatusCode, string> statusCodeRepository, List<Tuple<string, string>> orderStatusCodes = null)
        {
            if (orderStatusCodes == null)
            {
                OrderStatusCodes = new List<Tuple<string, string>> {new Tuple<string, string>("All", "All")};
                OrderStatusCodes.AddRange(statusCodeRepository.Queryable
                    .Where(a => a.ShowInFilterList)
                    .OrderBy(a => a.Level)
                    .Select(a => new Tuple<string, string>(a.Id, a.Name))
                    .ToList());
            }
            else
            {
                OrderStatusCodes = orderStatusCodes;
            }
        }

        public List<OrderTracking> OrderTracking { get; set; }

        public bool RequiresSplits()
        {
            return ColumnPreferences.ShowAccountNumber;
        }

        public bool RequiresApprovals()
        {
            return ColumnPreferences.ShowApprover || ColumnPreferences.ShowAccountManager ||
                   ColumnPreferences.ShowPurchaser;
        }

        public string GetNameFromApprovalsForOrder(string orderStatusCodeId, int orderId)
        {
            //TODO: Why are we doing first or default?
            var apprv = Approvals.Where(x => x.Order.Id == orderId)
                    .FirstOrDefault(a => a.StatusCode.Id == orderStatusCodeId && a.User != null);
            if (apprv == null)
            {
                return "[Workgroup]";
            }
            if (apprv.User.IsActive && !apprv.User.IsAway) //User is not away show them
            {
                return apprv.User.FullName;
            }
            if (apprv.SecondaryUser != null && apprv.SecondaryUser.IsActive && !apprv.SecondaryUser.IsAway) //Primary user is away, show Secondary if active and not away
            {
                return apprv.SecondaryUser.FullName;
            }
            return string.Empty; //Shouldn't get here
        }

        public List<Split> Splits { get; set; }

        public List<Approval> Approvals { get; set; }
    }
}<commit_msg>Filtered AP/AM/PR now lists names of all in that status, not just the first<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Purchasing.Core.Domain;
using UCDArch.Core.PersistanceSupport;
using System.Text;

namespace Purchasing.Web.Models
{
    public class FilteredOrderListModelDto
    {
        public List<OrderHistoryDto> OrderHistoryDtos { get; set; }

        public class OrderHistoryDto
        {
            public Order Order { get; set; }
            public string Workgroup { get; set; }
            public WorkgroupVendor Vendor { get; set; }
            public string CreatedBy { get; set; }
            public string Status { get; set; }
        }

        // for building dropdown list
        public List<Tuple<string, string>> OrderStatusCodes { get; set; }
        
        public string SelectedOrderStatus { get; set; }
        public bool ShowPending { get; set; }
        [Display(Name = "Created After")]
        public DateTime? StartDate { get; set; }
        [Display(Name = "Created Before")]
        public DateTime? EndDate { get; set; }
        public ColumnPreferences ColumnPreferences { get; set; }
        public string ShowLast { get; set; }

        /// <summary>
        /// Returns true if the user wants to view a column that requires order tracking info
        /// </summary>
        /// <remarks>
        /// Anything that shows "acted on" info will require order tracking history info
        /// </remarks>
        /// <returns></returns>
        public bool RequresOrderTracking()
        {
            return ColumnPreferences.ShowDaysNotActedOn || ColumnPreferences.ShowLastActedOnBy ||
                   ColumnPreferences.ShowLastActedOnDate;
        }

        public void PopulateStatusCodes(IRepositoryWithTypedId<OrderStatusCode, string> statusCodeRepository, List<Tuple<string, string>> orderStatusCodes = null)
        {
            if (orderStatusCodes == null)
            {
                OrderStatusCodes = new List<Tuple<string, string>> {new Tuple<string, string>("All", "All")};
                OrderStatusCodes.AddRange(statusCodeRepository.Queryable
                    .Where(a => a.ShowInFilterList)
                    .OrderBy(a => a.Level)
                    .Select(a => new Tuple<string, string>(a.Id, a.Name))
                    .ToList());
            }
            else
            {
                OrderStatusCodes = orderStatusCodes;
            }
        }

        public List<OrderTracking> OrderTracking { get; set; }

        public bool RequiresSplits()
        {
            return ColumnPreferences.ShowAccountNumber;
        }

        public bool RequiresApprovals()
        {
            return ColumnPreferences.ShowApprover || ColumnPreferences.ShowAccountManager ||
                   ColumnPreferences.ShowPurchaser;
        }

        public string GetNameFromApprovalsForOrder(string orderStatusCodeId, int orderId)
        {
            var approvalList = Approvals.Where(x => x.Order.Id == orderId && x.StatusCode.Id == orderStatusCodeId).ToList();

            var approvals = new StringBuilder();
            var firstApproval = true;

            foreach (var approval in approvalList)
            {
                var token = firstApproval ? string.Empty : ", ";
                approvals.Append(token); //append either nothing for the first approval or a comma/space for future approvals

                if (approval.User == null)
                {
                    approvals.Append("[Workgroup]");
                }else
                {
                    if (approval.User.IsActive && !approval.User.IsAway) //User is not away show them
                    {
                        approvals.Append(approval.User.FullName);
                    }
                    if (approval.SecondaryUser != null && approval.SecondaryUser.IsActive && !approval.SecondaryUser.IsAway) //Primary user is away, show Secondary if active and not away
                    {
                        approvals.Append(approval.SecondaryUser.FullName);
                    }
                }

                firstApproval = false;
            }

            return approvals.ToString();
        }

        public List<Split> Splits { get; set; }

        public List<Approval> Approvals { get; set; }
    }
}
{'fraction_non_alphanumeric': 0.0902786227034919, 'fraction_numerical': 0.0, 'mean_word_length': 1.8492201039861351, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3825273', 'n_tokens_mistral': 2103, 'n_tokens_neox': 2054, 'n_words': 549}