public static List <ReadyInvoicesForAction> GetReadyInvoicesForActionList(List <GetBriefQueue_Result> queueBrieflist)
        {
            if (queueBrieflist == null || queueBrieflist.Count == 0)
            {
                return(null);
            }
            List <ReadyInvoicesForAction> list = new List <ReadyInvoicesForAction>();

            foreach (GetBriefQueue_Result queueResult in queueBrieflist)
            {
                Invoice invoice = DBCommon.GetEntity <Invoice>(queueResult.InvoiceID);
                if (invoice == null)
                {
                    continue;
                }
                Patient_cu patient = DBCommon.GetEntity <Patient_cu>(invoice.Patient_CU_ID);
                if (patient == null)
                {
                    continue;
                }
                ReadyInvoicesForAction readyInvoicesForPayments = new ReadyInvoicesForAction()
                {
                    PatientID           = queueResult.PatientID,
                    PatientFullName     = queueResult.PatientFullName,
                    InvoiceID           = queueResult.InvoiceID,
                    InvoiceType         = (DB_InvoiceType)invoice.InvoiceType_P_ID,
                    InvoiceCreationDate = queueResult.ReservationTime,
                    InvoiceSerial       = invoice.InvoiceSerial,
                    DoctorID            = queueResult.DoctorID,
                    DoctorName          = queueResult.DoctorFullName,
                    IsPaymentEnough     = invoice.IsPaymentsEnough,
                    TotalRequired       = invoice.PatientShare_BeforeAddsOn_InvoiceItem,
                    TotalPayments       = invoice.CalculatedTotal_Payments,
                    ActiveInvoice       = invoice,
                    ActivePatient       = patient
                };

                list.Add(readyInvoicesForPayments);
            }

            return(list);
        }
        public static List <ReadyInvoicesForAction> ReadyInvoicesForAction(AdmissionType admissionType,
                                                                           DateTime?InvoiceCreationDateStart,
                                                                           DateTime?InvoiceCreationDateEnd, bool?InvoiceIsOnDuty, bool?InvoiceIsFinanciallyReviewed,
                                                                           bool?InvoiceIsPrinted, bool?InvoiceIsPaymentEnough, int?DoctorID, Patient_cu Patient)
        {
            List <ReadyInvoicesForAction>         readyInvoiceFormPaymentsList = new List <ReadyInvoicesForAction>();
            List <GetInvoiceForAddmission_Result> result = new List <GetInvoiceForAddmission_Result>();

            using (DBCommon.DBContext_External)
            {
                switch (admissionType)
                {
                case AdmissionType.ClinicAdmission:
                    result =
                        DBCommon.DBContext_External.GetInvoiceForAddmission(InvoiceCreationDateStart, InvoiceCreationDateEnd,
                                                                            (int)DB_InvoiceType.OutPatientPrivate, InvoiceIsOnDuty, InvoiceIsFinanciallyReviewed, InvoiceIsPrinted,
                                                                            InvoiceIsPaymentEnough, DoctorID, Patient != null ? Patient.Person_CU_ID : (int?)null)
                        .OrderByDescending(item => item.InvoiceCreationDate)
                        .ToList();
                    result.AddRange(
                        DBCommon.DBContext_External.GetInvoiceForAddmission(InvoiceCreationDateStart, InvoiceCreationDateEnd,
                                                                            (int)DB_InvoiceType.OutPatientNotPrivate, InvoiceIsOnDuty, InvoiceIsFinanciallyReviewed, InvoiceIsPrinted,
                                                                            InvoiceIsPaymentEnough, DoctorID, Patient != null ? Patient.Person_CU_ID : (int?)null)
                        .OrderByDescending(item => item.InvoiceCreationDate)
                        .ToList());
                    break;

                case AdmissionType.InPatientAdmission:
                    result =
                        DBCommon.DBContext_External.GetInvoiceForAddmission(InvoiceCreationDateStart, InvoiceCreationDateEnd,
                                                                            (int)DB_InvoiceType.InPatientPrivate, InvoiceIsOnDuty, InvoiceIsFinanciallyReviewed, InvoiceIsPrinted,
                                                                            InvoiceIsPaymentEnough, DoctorID, Patient != null ? Patient.Person_CU_ID : (int?)null)
                        .OrderByDescending(item => item.InvoiceCreationDate)
                        .ToList();
                    result.AddRange(
                        DBCommon.DBContext_External.GetInvoiceForAddmission(InvoiceCreationDateStart, InvoiceCreationDateEnd,
                                                                            (int)DB_InvoiceType.InPatientNotPrivate, InvoiceIsOnDuty, InvoiceIsFinanciallyReviewed, InvoiceIsPrinted,
                                                                            InvoiceIsPaymentEnough, DoctorID, Patient != null ? Patient.Person_CU_ID : (int?)null)
                        .OrderByDescending(item => item.InvoiceCreationDate)
                        .ToList());
                    break;
                }

                List <Invoice> invoicesList = new List <Invoice>();
                foreach (GetInvoiceForAddmission_Result getInvoiceForAddmissionResult in result)
                {
                    Invoice invoice = DBCommon.GetEntity <Invoice>(getInvoiceForAddmissionResult.InvoiceID);
                    if (invoice == null)
                    {
                        continue;
                    }
                    invoicesList.Add(invoice);
                    ReadyInvoicesForAction readyInvoicesForPayments = new ReadyInvoicesForAction()
                    {
                        PatientID           = getInvoiceForAddmissionResult.PatientID,
                        PatientFullName     = getInvoiceForAddmissionResult.PatientFullName,
                        InvoiceID           = getInvoiceForAddmissionResult.InvoiceID,
                        InvoiceType         = (DB_InvoiceType)invoice.InvoiceType_P_ID,
                        InvoiceCreationDate = getInvoiceForAddmissionResult.InvoiceCreationDate,
                        InvoiceSerial       = getInvoiceForAddmissionResult.InvoiceSerial,
                        DoctorID            = getInvoiceForAddmissionResult.DoctorID,
                        DoctorName          = getInvoiceForAddmissionResult.DoctorName,
                        IsPaymentEnough     = getInvoiceForAddmissionResult.IsPaymentEnough,
                        TotalRequired       = invoice.PatientShare_BeforeAddsOn_InvoiceItem,
                        TotalPayments       = invoice.CalculatedTotal_Payments,
                        ActiveInvoice       = invoice,
                        ActivePatient       = Patient
                    };

                    readyInvoiceFormPaymentsList.Add(readyInvoicesForPayments);
                }
            }

            return(readyInvoiceFormPaymentsList);
        }