Esempio n. 1
0
        public JsonResult SaveInvoice(PatientInvoice invoice, IList <PatientService> patientServices)
        {
            using (PatientInvoiceRepository repository = new PatientInvoiceRepository())
            {
                invoice.UserId = GetLoggedinUserInfo().UserId;
                invoice        = repository.Insert(invoice);
                repository.Commit();
                // CreatePatientService(invoice.Id, patientServices);
            }

            return(Json(invoice.Id, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public JsonResult GetTotalDebit(long patientId)
        {
            int       Totaldebit;
            int       TotalCredit;
            ArrayList debitcredit = new ArrayList();

            using (PatientInvoiceRepository repository = new PatientInvoiceRepository())
            {
                Totaldebit = repository.GetTotalDebit(patientId);
            }

            using (PaymentRepository repository = new PaymentRepository())
            {
                TotalCredit = repository.GetTotalCredit(patientId);
            }

            debitcredit.Add(Totaldebit);
            debitcredit.Add(TotalCredit);

            return(Json(debitcredit, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public JsonResult GetInvoicesByPatientId(long id, long statusid, string DateStart, string DateEnd, long?invoiceId = null)
        {
            List <PatientInvoice> onlypatientInvoices = new List <PatientInvoice>();
            List <PatientInvoice> patientInvoices;

            DateTime invoiceDateStart = DateTime.Parse("1/1/1980");
            DateTime invoiceDateEnd   = DateTime.Today;

            if (IsDate(DateEnd) && IsDate(DateStart))
            {
                invoiceDateStart = DateTime.Parse(DateStart);
                invoiceDateEnd   = DateTime.Parse(DateEnd);
            }


            using (PatientInvoiceRepository repository = new PatientInvoiceRepository())
            {
                /* ParameterExpression argParam = Expression.Parameter(typeof(PatientInvoice), "s");
                 * Expression patientProperty = Expression.Property(argParam, "PatientID");
                 * Expression statusProperty = Expression.Property(argParam, "InvoiceStatusId");
                 *
                 * var val1 = Expression.Constant(id);
                 * var val2 = Expression.Constant(statusid);
                 *
                 * Expression e1 = Expression.Equal(patientProperty, val1);
                 * Expression e2 = Expression.Equal(statusProperty, val2);
                 *
                 * BinaryExpression andExp;*/


                // var andExp = e1;

                //var lambda = Expression.Lambda<Func<PatientInvoice, bool>>(andExp, argParam);
                Expression <Func <PatientInvoice, bool> > lambda;


                if (id == 0)
                {
                    if (statusid == 0)
                    {
                        lambda = (x => x.Active == true && x.InvoiceDate >= invoiceDateStart && x.InvoiceDate <= invoiceDateEnd && (invoiceId == null ? x.Id > 0 : x.Id == invoiceId));
                    }
                    else
                    {
                        lambda = (x => x.InvoiceStatusId == statusid && x.Active == true && x.InvoiceDate >= invoiceDateStart && x.InvoiceDate <= invoiceDateEnd && (invoiceId == null ? x.Id > 0 : x.Id == invoiceId));
                    }
                }
                else
                {
                    if (statusid == 0)
                    {
                        lambda = (x => x.PatientID == id && x.Active == true && x.InvoiceDate >= invoiceDateStart && x.InvoiceDate <= invoiceDateEnd && (invoiceId == null ? x.Id > 0 : x.Id == invoiceId));
                    }
                    else
                    {
                        lambda = (x => x.PatientID == id && x.Active == true && x.InvoiceStatusId == statusid && x.InvoiceDate >= invoiceDateStart && x.InvoiceDate <= invoiceDateEnd && (invoiceId == null ? x.Id > 0 : x.Id == invoiceId));
                    }
                }


                patientInvoices = repository.GetByQuery(lambda).ToList();
                patientInvoices = patientInvoices.OrderByDescending(x => x.InvoiceDate).ToList();



                foreach (PatientInvoice pinvoice in patientInvoices)
                {
                    PatientInvoice onlyPatientInvoice = new PatientInvoice();
                    Patient        patient            = new Patient();
                    onlyPatientInvoice.Patient = patient;

                    onlyPatientInvoice.Id                = pinvoice.Id;
                    onlyPatientInvoice.InvoiceDate       = pinvoice.InvoiceDate;
                    onlyPatientInvoice.DueDate           = pinvoice.DueDate;
                    onlyPatientInvoice.PatientID         = pinvoice.PatientID;
                    onlyPatientInvoice.TotalAmount       = pinvoice.TotalAmount;
                    onlyPatientInvoice.TotalDiscount     = pinvoice.TotalDiscount;
                    onlyPatientInvoice.InvoiceStatusId   = pinvoice.InvoiceStatusId;
                    onlyPatientInvoice.ItemDiscount      = pinvoice.ItemDiscount;
                    onlyPatientInvoice.UserId            = pinvoice.UserId;
                    onlyPatientInvoice.LabStatusId       = pinvoice.LabStatusId;
                    onlyPatientInvoice.IsRefunded        = pinvoice.IsRefunded;
                    onlyPatientInvoice.Patient.FirstName = pinvoice.Patient.FirstName;
                    onlyPatientInvoice.Patient.LastName  = pinvoice.Patient.LastName;
                    onlyPatientInvoice.UserId            = GetLoggedinUserInfo().UserId;

                    foreach (InvoicePayment invoicepayment in pinvoice.InvoicePayments)
                    {
                        InvoicePayment invoicePayment = new InvoicePayment();

                        invoicePayment.Id = invoicepayment.Id;
                        invoicePayment.PatientInvoiceId = invoicepayment.PatientInvoiceId;
                        invoicePayment.Amount           = invoicepayment.Amount;
                        invoicePayment.PaymentID        = invoicepayment.PaymentID;
                        invoicePayment.UserId           = invoicepayment.UserId;
                        onlyPatientInvoice.InvoicePayments.Add(invoicePayment);
                    }

                    foreach (PatientService c in pinvoice.PatientServices)
                    {
                        PatientService patientstitem = new PatientService();
                        Item           item          = new Item();
                        ItemCategory   Category      = new ItemCategory();
                        patientstitem.Item = item;
                        patientstitem.Item.ItemCategory = Category;


                        patientstitem.Id                   = c.Id;
                        patientstitem.PatientID            = c.PatientID;
                        patientstitem.ItemId               = c.ItemId;
                        patientstitem.InvoiceID            = c.InvoiceID;
                        patientstitem.ReceiptId            = c.ReceiptId;
                        patientstitem.PatientAdmissionId   = c.PatientAdmissionId;
                        patientstitem.ServiceListPrice     = c.ServiceListPrice;
                        patientstitem.ServiceActualPrice   = c.ServiceActualPrice;
                        patientstitem.ServiceQuantity      = c.ServiceQuantity;
                        patientstitem.ServiceDate          = c.ServiceDate;
                        patientstitem.UserId               = c.UserId;
                        patientstitem.Discount             = c.Discount;
                        patientstitem.DiscountAfterInvoice = c.DiscountAfterInvoice;
                        patientstitem.Refund               = c.Refund;
                        patientstitem.RefundNote           = c.RefundNote;

                        patientstitem.Billed       = c.Billed;
                        patientstitem.LabStatusId  = c.LabStatusId;
                        patientstitem.ReferralFee  = c.ReferralFee;
                        patientstitem.DeliveryDate = c.DeliveryDate;
                        patientstitem.DeliveryTime = c.DeliveryTime;


                        patientstitem.Item.Name        = c.Item.Name;
                        patientstitem.Item.GenericName = c.Item.GenericName;

                        if (c.Item.ItemCategory != null)
                        {
                            patientstitem.Item.ItemCategory.Name = c.Item.ItemCategory.Name;
                        }

                        patientstitem.Item.ReferralAllowed = c.Item.ReferralAllowed;

                        patientstitem.ReferralFeePaid   = c.ReferralFeePaid;
                        patientstitem.ServiceProviderId = c.ServiceProviderId;
                        patientstitem.UserId            = GetLoggedinUserInfo().UserId;

                        onlyPatientInvoice.PatientServices.Add(patientstitem);
                    }

                    onlypatientInvoices.Add(onlyPatientInvoice);
                }

                if (onlypatientInvoices == null)
                {
                    return(Json(HttpNotFound(), JsonRequestBehavior.AllowGet));
                }

                return(Json(onlypatientInvoices, JsonRequestBehavior.AllowGet));
            }
        }