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; } }
public int InsertInvoice(EntityICUInvoice entInvoice, List <EntityICUInvoiceDetail> lstInvoice, bool IsCash) { try { int?Id = 0; objData.STP_InserttblICUBedAlloc(Convert.ToInt32(entInvoice.BedId), Convert.ToInt32(0), Convert.ToInt32(0), Convert.ToInt32(0), Convert.ToInt32(entInvoice.PatientId), Convert.ToDateTime(entInvoice.AllocationDate), (entInvoice.DischargeDate), Convert.ToDecimal(entInvoice.NetAmount), Convert.ToDecimal(entInvoice.TotalAmount), Convert.ToInt32(entInvoice.Discount), Convert.ToInt32(entInvoice.Tax1), Convert.ToInt32(entInvoice.Tax2), entInvoice.IsDischarge, ref Id); foreach (EntityICUInvoiceDetail item in lstInvoice) { tblICUInvoiceDetail obj = new tblICUInvoiceDetail() { ICUBedAllocId = Id, IsDelete = false, ChargesId = item.ChargesId, Amount = item.Amount }; objData.tblICUInvoiceDetails.InsertOnSubmit(obj); } int TransactionId = new PatientInvoiceBLL().GetTransactionId(); if (IsCash) { tblCustomerTransaction objDebit = new tblCustomerTransaction() { TransactionId = TransactionId, IsCash = true, TransactionDocNo = Id, TransactionType = "ICUInvoice", BillAmount = entInvoice.NetAmount, PayAmount = 0, PatientId = entInvoice.PatientId, IsDelete = false, ReceiptDate = entInvoice.AllocationDate, }; objData.tblCustomerTransactions.InsertOnSubmit(objDebit); //objData.SubmitChanges(); tblCustomerTransaction objCrReceipt = new tblCustomerTransaction() { TransactionId = TransactionId, IsCash = true, TransactionDocNo = Id, TransactionType = "ICUInvoice", PayAmount = entInvoice.NetAmount, BillAmount = 0, PatientId = entInvoice.PatientId, IsDelete = false, ReceiptDate = entInvoice.AllocationDate, }; objData.tblCustomerTransactions.InsertOnSubmit(objCrReceipt); //objData.SubmitChanges(); } else { tblCustomerTransaction objDebit = new tblCustomerTransaction() { TransactionId = TransactionId, IsCash = false, TransactionDocNo = Id, TransactionType = "ICUInvoice", BillAmount = entInvoice.NetAmount, PatientId = entInvoice.PatientId, IsDelete = false, ReceiptDate = entInvoice.AllocationDate, }; objData.tblCustomerTransactions.InsertOnSubmit(objDebit); //objData.SubmitChanges(); } objData.SubmitChanges(); return(1); } catch (Exception ex) { throw ex; } }