public int IsBedAlloc(int BedId) { int Check = 0; tblICUBedAlloc objICU = (from tbl in objData.tblICUBedAllocs where tbl.BedId.Equals(BedId) && tbl.IsDischargeDone.Equals(true) select tbl).FirstOrDefault(); tblICUBedAlloc objIc = (from tbl in objData.tblICUBedAllocs select tbl).FirstOrDefault(); if (objICU != null && objIc == null) { Check = 1; } else { if (objIc == null) { Check = 1; } } return(Check); }
public int UpdateInvoice(List <EntityICUInvoiceDetail> lstEdited, List <EntityICUInvoiceDetail> lstUpdate, EntityICUInvoice entInvoice) { try { tblICUBedAlloc objTest = (from tbl in objData.tblICUBedAllocs where tbl.IsDelete == false && tbl.ICUBedAllocId == entInvoice.ICUBedAllocId select tbl).FirstOrDefault(); List <EntityICUInvoiceDetail> lstTemp = new List <EntityICUInvoiceDetail>(); List <tblCustomerTransaction> objCust = (from tbl in objData.tblCustomerTransactions where tbl.IsDelete == false && tbl.TransactionDocNo == entInvoice.ICUBedAllocId && tbl.TransactionType == "ICUInvoice" select tbl).ToList(); if (objTest != null && objCust != null) { if (objCust.Count == 1) { if (entInvoice.IsCash.Value) { tblCustomerTransaction objC = new tblCustomerTransaction() { PayAmount = lstEdited[0].NetAmount, ReceiptDate = entInvoice.AllocationDate, IsCash = entInvoice.IsCash, IsDelete = false, TransactionDocNo = entInvoice.ICUBedAllocId, TransactionId = objCust[0].TransactionId, TransactionType = "Invoice", PatientId = entInvoice.PatientId, }; objData.tblCustomerTransactions.InsertOnSubmit(objC); foreach (tblCustomerTransaction item in objCust) { item.BillAmount = lstEdited[0].NetAmount; item.ReceiptDate = entInvoice.AllocationDate; item.IsCash = entInvoice.IsCash; if (item.IsCash == false) { if (item.PayAmount > 0) { item.IsDelete = true; } } else { item.PayAmount = lstEdited[0].NetAmount; } } } else { foreach (tblCustomerTransaction item in objCust) { item.BillAmount = entInvoice.NetAmount; item.ReceiptDate = entInvoice.AllocationDate; item.IsCash = entInvoice.IsCash; if (item.IsCash == false) { if (item.PayAmount > 0) { item.IsDelete = true; } } else { item.PayAmount = lstEdited[0].NetAmount; } } } } else { foreach (tblCustomerTransaction item in objCust) { item.BillAmount = lstEdited[0].NetAmount; item.ReceiptDate = entInvoice.AllocationDate; item.IsCash = entInvoice.IsCash; if (item.IsCash == false) { if (item.PayAmount > 0) { item.IsDelete = true; } } else { item.PayAmount = lstEdited[0].NetAmount; } } } objTest.AllocationDate = entInvoice.AllocationDate; objTest.TotalAmount = entInvoice.TotalAmount; objTest.NetAmount = lstEdited[0].NetAmount; objTest.Tax1 = entInvoice.Tax1; objTest.Discount = entInvoice.Discount; objTest.Tax2 = entInvoice.Tax2; } foreach (EntityICUInvoiceDetail item in lstEdited) { int cnt = (from tbl in objData.tblICUInvoiceDetails where tbl.ICUBedAllocId == entInvoice.ICUBedAllocId && tbl.ChargesId == item.ChargesId && tbl.IsDelete == false select tbl).ToList().Count; if (cnt == 0) { tblICUInvoiceDetail objNewAdded = new tblICUInvoiceDetail() { ICUBedAllocId = entInvoice.ICUBedAllocId, ChargesId = item.ChargesId, Amount = item.Amount, IsDelete = false }; objData.tblICUInvoiceDetails.InsertOnSubmit(objNewAdded); objData.SubmitChanges(); } else { lstTemp.Add(item); } } foreach (EntityICUInvoiceDetail item in lstUpdate) { tblICUInvoiceDetail cnt = (from tbl in objData.tblICUInvoiceDetails where tbl.ICUBedAllocId == entInvoice.ICUBedAllocId && tbl.ChargesId == item.ChargesId select tbl).FirstOrDefault(); if (cnt != null) { int checkExist = (from tbl in lstTemp where tbl.ChargesId == item.ChargesId select tbl).ToList().Count; if (checkExist == 0) { cnt.IsDelete = true; } } } objData.SubmitChanges(); return(1); } catch (Exception ex) { throw ex; } }