public static InvoiceStatus DetermineStatus(this EFInvoice.InvoiceHeader value)
        {
            if (value.InvoiceType.Trim().Equals("cm", StringComparison.InvariantCultureIgnoreCase))
            {
                return(InvoiceStatus.Open);
            }

            switch (value.InvoiceStatus.ToUpper())
            {
            case "O":
                if (value.DueDate >= DateTime.Today.AddDays(1))
                {
                    return(InvoiceStatus.Open);
                }
                else
                {
                    return(InvoiceStatus.PastDue);
                }

            case "P":
                return(InvoiceStatus.Pending);

            default:
                return(InvoiceStatus.Paid);
            }
        }
        public static InvoiceModel ToInvoiceModel(this EFInvoice.InvoiceHeader value, KeithLink.Svc.Core.Models.Profile.Customer customer = null)
        {
            InvoiceModel retVal = new InvoiceModel();

            retVal.BranchId        = value.Division.Substring(0, 3);
            retVal.InvoiceNumber   = value.InvoiceNumber.Trim();
            retVal.Type            = DetermineType(value.InvoiceType.Trim());
            retVal.TypeDescription = EnumUtils <InvoiceType> .GetDescription(DetermineType(value.InvoiceType.Trim()));

            retVal.Status            = value.DetermineStatus();
            retVal.StatusDescription = EnumUtils <InvoiceStatus> .GetDescription(value.DetermineStatus());

            retVal.CustomerNumber   = value.CustomerNumber;
            retVal.CustomerName     = customer == null ? "N/A" : customer.CustomerName;
            retVal.Amount           = value.AmountDue;
            retVal.DueDate          = value.DueDate;
            retVal.InvoiceDate      = value.InvoiceDate;
            retVal.OrderDate        = value.InvoiceDate;
            retVal.IsPayable        = value.InvoiceStatus.Equals("O", StringComparison.InvariantCultureIgnoreCase) && customer != null && customer.KPayCustomer;
            retVal.TransactionCount = value.TransactionCount;

            return(retVal);
        }