Пример #1
0
        public int UpdateInvoice(EntityPatientInvoice entInvoice, List <EntityInvoiceDetails> lst)
        {
            int i = 0;

            try
            {
                tblPatientInvoice objTest = (from tbl in objData.tblPatientInvoices
                                             where tbl.IsDelete == false &&
                                             tbl.BillNo == entInvoice.BillNo
                                             select tbl).FirstOrDefault();
                if (objTest != null)
                {
                    objTest.Amount         = entInvoice.Amount;
                    objTest.BillType       = entInvoice.BillType;
                    objTest.NetAmount      = entInvoice.NetAmount;
                    objTest.TotalAdvance   = entInvoice.TotalAdvance;
                    objTest.BalanceAmount  = entInvoice.BalanceAmount;
                    objTest.ReceivedAmount = entInvoice.ReceivedAmount;
                    objTest.RefundAmount   = entInvoice.RefundAmount;
                    objTest.FixedDiscount  = entInvoice.FixedDiscount;
                    objTest.PreparedByName = entInvoice.PreparedByName;
                    //objTest.Service = entInvoice.Service;
                    //objTest.Vat = entInvoice.Vat;
                    if (entInvoice.BillType != "Estimated")
                    {
                        int TransactionId = GetTransactionId();
                        if (entInvoice.IsCash)
                        {
                            tblCustomerTransaction objDebit = new tblCustomerTransaction()
                            {
                                TransactionId    = TransactionId,
                                IsCash           = true,
                                TransactionDocNo = entInvoice.BillNo,
                                TransactionType  = "Invoice",
                                BillAmount       = entInvoice.NetAmount,
                                PayAmount        = entInvoice.NetAmount,
                                Discount         = entInvoice.FixedDiscount,
                                PatientId        = entInvoice.PatientId,
                                PreparedByName   = entInvoice.PreparedByName,
                                IsDelete         = false,
                                ReceiptDate      = entInvoice.BillDate,
                            };
                            objData.tblCustomerTransactions.InsertOnSubmit(objDebit);
                        }
                        else
                        {
                            tblCustomerTransaction objDebit = new tblCustomerTransaction()
                            {
                                TransactionId    = TransactionId,
                                IsCash           = false,
                                TransactionDocNo = entInvoice.BillNo,
                                TransactionType  = "Invoice",
                                BillAmount       = entInvoice.NetAmount,
                                Discount         = entInvoice.FixedDiscount,
                                PatientId        = entInvoice.PatientId,
                                PreparedByName   = entInvoice.PreparedByName,
                                IsDelete         = false,
                                ReceiptDate      = entInvoice.BillDate,
                            };
                            objData.tblCustomerTransactions.InsertOnSubmit(objDebit);
                            //objData.SubmitChanges();
                        }
                    }
                    else
                    {
                        List <tblCustomerTransaction> objCust = (from tbl in objData.tblCustomerTransactions
                                                                 where tbl.IsDelete == false &&
                                                                 tbl.TransactionDocNo == entInvoice.BillNo &&
                                                                 tbl.TransactionType == "Invoice"
                                                                 select tbl).ToList();
                        if (objCust != null)
                        {
                            if (objCust.Count == 1)
                            {
                                if (entInvoice.IsCash)
                                {
                                    tblCustomerTransaction objC = new tblCustomerTransaction()
                                    {
                                        PayAmount        = entInvoice.NetAmount,
                                        BillAmount       = entInvoice.NetAmount,
                                        Discount         = entInvoice.FixedDiscount,
                                        ReceiptDate      = entInvoice.BillDate,
                                        IsCash           = entInvoice.IsCash,
                                        IsDelete         = false,
                                        TransactionDocNo = entInvoice.BillNo,
                                        TransactionId    = objCust[0].TransactionId,
                                        TransactionType  = "Invoice",
                                        PatientId        = entInvoice.PatientId,
                                        PreparedByName   = entInvoice.PreparedByName,
                                    };
                                    objData.tblCustomerTransactions.InsertOnSubmit(objC);
                                    foreach (tblCustomerTransaction item in objCust)
                                    {
                                        item.BillAmount  = entInvoice.NetAmount;
                                        item.ReceiptDate = entInvoice.BillDate;
                                        item.IsCash      = entInvoice.IsCash;
                                        if (item.IsCash == false)
                                        {
                                            if (item.PayAmount > 0)
                                            {
                                                item.IsDelete = true;
                                            }
                                        }
                                        else
                                        {
                                            item.PayAmount = 0;
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (tblCustomerTransaction item in objCust)
                                    {
                                        item.BillAmount  = entInvoice.NetAmount;
                                        item.ReceiptDate = entInvoice.BillDate;
                                        item.IsCash      = entInvoice.IsCash;
                                        if (item.IsCash == false)
                                        {
                                            if (item.PayAmount > 0)
                                            {
                                                item.IsDelete = true;
                                            }
                                        }
                                        else
                                        {
                                            if (item.PayAmount > 0)
                                            {
                                                item.PayAmount = entInvoice.NetAmount;
                                            }
                                            else
                                            {
                                                item.PayAmount = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                foreach (tblCustomerTransaction item in objCust)
                                {
                                    item.BillAmount  = entInvoice.NetAmount;
                                    item.ReceiptDate = entInvoice.BillDate;
                                    item.IsCash      = entInvoice.IsCash;
                                    if (item.IsCash == false)
                                    {
                                        if (item.PayAmount > 0)
                                        {
                                            item.IsDelete = true;
                                        }
                                    }
                                    else
                                    {
                                        if (item.PayAmount > 0)
                                        {
                                            item.PayAmount = entInvoice.NetAmount;
                                        }
                                        else
                                        {
                                            item.PayAmount = 0;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    foreach (EntityInvoiceDetails item in lst)
                    {
                        if (item.BillSRNo > 0)
                        {
                            tblPatientInvoiceDetail cnt = (from tbl in objData.tblPatientInvoiceDetails
                                                           where tbl.BillNo == item.BillNo &&
                                                           tbl.BillSRNo == item.BillSRNo &&
                                                           tbl.IsDelete == false
                                                           select tbl).FirstOrDefault();
                            if (cnt != null)
                            {
                                cnt.BillNo         = entInvoice.BillNo;
                                cnt.Quantity       = item.Quantity;
                                cnt.NoOfDays       = item.NoOfDays;
                                cnt.Remarks        = item.Remarks;
                                cnt.Amount         = item.Amount;
                                cnt.ChargePerDay   = item.PerDayCharge;
                                cnt.OtherChargesId = item.OtherChargesId;
                                cnt.IsDelete       = item.IsDelete;
                            }
                        }
                        else
                        {
                            tblPatientInvoiceDetail objNewAdded = new tblPatientInvoiceDetail()
                            {
                                BillNo         = entInvoice.BillNo,
                                BedAllocId     = item.BedAllocId,
                                OTAllocId      = item.OTBedAllocId,
                                DocAllocId     = item.DocAllocationId,
                                OtherChargesId = item.OtherChargesId,
                                Amount         = item.Amount,
                                ChargePerDay   = item.PerDayCharge,
                                NetAmount      = item.NetAmount,
                                Remarks        = item.Remarks,
                                NoOfDays       = item.NoOfDays,
                                Quantity       = item.Quantity,
                                IsDelete       = false
                            };
                            objData.tblPatientInvoiceDetails.InsertOnSubmit(objNewAdded);
                            if (entInvoice.BillType == "Original")
                            {
                                if (objNewAdded.BedAllocId > 0)
                                {
                                    int p = new BedStatusBLL().DischargePatient(entInvoice.PatientId, entInvoice.BillDate);
                                }
                            }
                        }
                    }

                    tblPatientAdmitDetail admit = (from tbl in objData.tblPatientAdmitDetails
                                                   where tbl.IsDelete == false &&
                                                   tbl.AdmitId == entInvoice.PatientId
                                                   select tbl).FirstOrDefault();
                    if (entInvoice.BillType == "Estimated")
                    {
                        if (admit != null)
                        {
                            admit.IsDischarge = false;
                        }
                    }

                    if (entInvoice.BillType == "Original")
                    {
                        if (admit != null)
                        {
                            admit.IsDischarge = true;
                        }
                    }

                    objData.SubmitChanges();
                }
                i++;
            }
            catch (Exception ex)
            {
                i = 0;
                throw ex;
            }
            return(i);
        }
Пример #2
0
        public int UpdateOPDRefund(EntityPatientInvoice entInvoice, List <EntityInvoiceDetails> lst)
        {
            int i = 0;

            try
            {
                tblPatientInvoice objTest = (from tbl in objData.tblPatientInvoices
                                             where tbl.IsDelete == false &&
                                             tbl.BillNo == entInvoice.BillNo
                                             select tbl).FirstOrDefault();
                if (objTest != null)
                {
                    objTest.Amount         = 0;
                    objTest.NetAmount      = 0;
                    objTest.ReceivedAmount = 0;
                    objTest.RefundAmount   = entInvoice.NetAmount;
                    objTest.TotalAdvance   = 0;

                    tblCustomerTransaction objCust = (from tbl in objData.tblCustomerTransactions
                                                      where tbl.IsDelete == false &&
                                                      tbl.TransactionDocNo == entInvoice.BillNo &&
                                                      tbl.TransactionType == "Invoice"
                                                      select tbl).FirstOrDefault();


                    if (objCust != null)
                    {
                        objCust.PayAmount  = 0;
                        objCust.BillAmount = 0;
                    }

                    foreach (EntityInvoiceDetails item in lst)
                    {
                        if (item.BillSRNo > 0)
                        {
                            tblPatientInvoiceDetail cnt = (from tbl in objData.tblPatientInvoiceDetails
                                                           where tbl.BillNo == item.BillNo &&
                                                           tbl.BillSRNo == item.BillSRNo &&
                                                           tbl.IsDelete == false
                                                           select tbl).FirstOrDefault();
                            if (cnt != null)
                            {
                                cnt.BillNo         = entInvoice.BillNo;
                                cnt.ChargePerDay   = 0;
                                cnt.NetAmount      = 0;
                                cnt.Amount         = 0;
                                cnt.OtherChargesId = item.OtherChargesId;
                                cnt.IsDelete       = item.IsDelete;
                            }
                            objData.SubmitChanges();
                        }
                    }
                    objData.SubmitChanges();
                }
                i++;
            }
            catch (Exception ex)
            {
                i = 0;
                throw ex;
            }
            return(i);
        }
Пример #3
0
        public int UpdateInvoice(List <EntityInvoiceDetails> lstEdited, List <EntityInvoiceDetails> lstUpdate)
        {
            try
            {
                tblPatientInvoice objTest = (from tbl in objData.tblPatientInvoices
                                             where tbl.IsDelete == false &&
                                             tbl.BillNo == lstEdited[0].BillNo
                                             select tbl).FirstOrDefault();

                List <EntityInvoiceDetails> lstTemp = new List <EntityInvoiceDetails>();

                List <tblCustomerTransaction> objCust = (from tbl in objData.tblCustomerTransactions
                                                         where tbl.IsDelete == false &&
                                                         tbl.TransactionDocNo == lstEdited[0].BillNo &&
                                                         tbl.TransactionType == "Invoice"
                                                         select tbl).ToList();
                if (objTest != null && objCust != null)
                {
                    if (objCust.Count == 1)
                    {
                        if (lstEdited[0].IsCash)
                        {
                            tblCustomerTransaction objC = new tblCustomerTransaction()
                            {
                                PayAmount        = lstEdited[0].NetAmount,
                                ReceiptDate      = lstEdited[0].BillDate,
                                IsCash           = lstEdited[0].IsCash,
                                IsDelete         = false,
                                TransactionDocNo = lstEdited[0].BillNo,
                                TransactionId    = objCust[0].TransactionId,
                                TransactionType  = "Invoice",
                                PatientId        = lstEdited[0].PatientID,
                            };
                            objData.tblCustomerTransactions.InsertOnSubmit(objC);
                            foreach (tblCustomerTransaction item in objCust)
                            {
                                item.BillAmount  = lstEdited[0].NetAmount;
                                item.ReceiptDate = lstEdited[0].BillDate;
                                item.IsCash      = lstEdited[0].IsCash;
                                if (item.IsCash == false)
                                {
                                    if (item.PayAmount > 0)
                                    {
                                        item.IsDelete = true;
                                    }
                                }
                                else
                                {
                                    item.PayAmount = 0;
                                }
                            }
                        }
                        else
                        {
                            foreach (tblCustomerTransaction item in objCust)
                            {
                                item.BillAmount  = lstEdited[0].NetAmount;
                                item.ReceiptDate = lstEdited[0].BillDate;
                                item.IsCash      = lstEdited[0].IsCash;
                                if (item.IsCash == false)
                                {
                                    if (item.PayAmount > 0)
                                    {
                                        item.IsDelete = true;
                                    }
                                }
                                else
                                {
                                    if (item.PayAmount > 0)
                                    {
                                        item.PayAmount = lstEdited[0].NetAmount;
                                    }
                                    else
                                    {
                                        item.PayAmount = 0;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (tblCustomerTransaction item in objCust)
                        {
                            item.BillAmount  = lstEdited[0].NetAmount;
                            item.ReceiptDate = lstEdited[0].BillDate;
                            item.IsCash      = lstEdited[0].IsCash;
                            if (item.IsCash == false)
                            {
                                if (item.PayAmount > 0)
                                {
                                    item.IsDelete = true;
                                }
                            }
                            else
                            {
                                if (item.PayAmount > 0)
                                {
                                    item.PayAmount = lstEdited[0].NetAmount;
                                }
                                else
                                {
                                    item.PayAmount = 0;
                                }
                            }
                        }
                    }

                    objTest.BillDate  = lstEdited[0].BillDate;
                    objTest.Amount    = lstEdited[0].Total;
                    objTest.NetAmount = lstEdited[0].NetAmount;
                    //objTest.Vat = lstEdited[0].Vat;
                    objTest.Discount = lstEdited[0].Discount;
                    //objTest.Service = lstEdited[0].Service;
                }
                foreach (EntityInvoiceDetails item in lstEdited)
                {
                    int cnt = (from tbl in objData.tblPatientInvoiceDetails
                               where tbl.BillNo == item.BillNo &&
                               tbl.OtherChargesId == item.OtherChargesId &&
                               tbl.IsDelete == false
                               select tbl).ToList().Count;
                    if (cnt == 0)
                    {
                        tblPatientInvoiceDetail objNewAdded = new tblPatientInvoiceDetail()
                        {
                            BillNo         = lstEdited[0].BillNo,
                            BedAllocId     = item.BedAllocId,
                            OTAllocId      = item.OTBedAllocId,
                            DocAllocId     = item.DocAllocationId,
                            OtherChargesId = item.OtherChargesId,
                            Amount         = item.Amount,
                            NetAmount      = item.NetAmount,
                            IsDelete       = false
                        };
                        objData.tblPatientInvoiceDetails.InsertOnSubmit(objNewAdded);
                        objData.SubmitChanges();
                    }
                    else
                    {
                        lstTemp.Add(item);
                    }
                }

                foreach (EntityInvoiceDetails item in lstUpdate)
                {
                    tblPatientInvoiceDetail cnt = (from tbl in objData.tblPatientInvoiceDetails
                                                   where tbl.BillNo == item.BillNo &&
                                                   tbl.OtherChargesId == item.OtherChargesId
                                                   select tbl).FirstOrDefault();

                    if (cnt != null)
                    {
                        int checkExist = (from tbl in lstTemp
                                          where tbl.OtherChargesId == item.OtherChargesId
                                          select tbl).ToList().Count;
                        if (checkExist == 0)
                        {
                            cnt.IsDelete = true;
                        }
                    }
                }
                objData.SubmitChanges();
                return(1);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }