public int InsertInvoice(EntityICUInvoice entInvoice, List <EntityICUInvoiceDetail> lstInvoice, bool IsCash) { try { int?ICUInvoiceNo = 0; objData.STP_InserttblICUInvoiceDischarge(Convert.ToDateTime(entInvoice.AllocationDate), Convert.ToInt32(entInvoice.PatientId) , Convert.ToDecimal(entInvoice.NetAmount), Convert.ToDecimal(entInvoice.TotalAmount), Convert.ToInt32(entInvoice.Discount), Convert.ToInt32(entInvoice.Tax1), Convert.ToInt32(entInvoice.Tax2), false, Convert.ToBoolean(entInvoice.Is_ShiftIPD), Convert.ToDateTime(entInvoice.ShiftDate), ref ICUInvoiceNo); foreach (EntityICUInvoiceDetail item in lstInvoice) { tblICUInvoiceDischargeDetail obj = new tblICUInvoiceDischargeDetail() { ICUBedAllocId = entInvoice.ICUBedAllocId, IsDelete = false, ChargesId = item.ChargesId, Amount = item.Amount, NoofDays = item.NoofDays, Charge = item.Charges, Quantity = item.Quantity, ICUInvoiceNo = ICUInvoiceNo, }; objData.tblICUInvoiceDischargeDetails.InsertOnSubmit(obj); } int TransactionId = new PatientInvoiceBLL().GetTransactionId(); if (IsCash) { tblCustomerTransaction objDebit = new tblCustomerTransaction() { TransactionId = TransactionId, IsCash = true, TransactionDocNo = ICUInvoiceNo, 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 = ICUInvoiceNo, 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 = ICUInvoiceNo, 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; } }
public int UpdateInvoice(List <EntityICUInvoiceDetail> lstUpdate, EntityICUInvoice entInvoice) { int count = 0; try { tblICUInvoiceDischarge obj = (from tbl in objData.tblICUInvoiceDischarges where tbl.IsDelete == false && tbl.ICUInvoiceNo == entInvoice.InvoiceNo select tbl).FirstOrDefault(); if (obj != null) { obj.Discount = entInvoice.Discount; obj.Vat = Convert.ToInt32(entInvoice.Tax1); obj.ServiceTax = Convert.ToInt32(entInvoice.Tax2); obj.TotalAmount = entInvoice.TotalAmount; obj.NetAmount = entInvoice.NetAmount; } foreach (EntityICUInvoiceDetail item in lstUpdate) { if (item.ICUSRlNo == 0) { tblICUInvoiceDischargeDetail objDetails = new tblICUInvoiceDischargeDetail() { ICUBedAllocId = entInvoice.ICUBedAllocId, IsDelete = false, ChargesId = item.ChargesId, Amount = item.Amount, NoofDays = item.NoofDays, Charge = item.Charges, Quantity = item.Quantity, ICUInvoiceNo = entInvoice.InvoiceNo, }; objData.tblICUInvoiceDischargeDetails.InsertOnSubmit(objDetails); } else { tblICUInvoiceDischargeDetail objDetails = (from tbl in objData.tblICUInvoiceDischargeDetails where tbl.IsDelete == false && tbl.ICUSRlNo == item.ICUSRlNo select tbl).FirstOrDefault(); if (objDetails != null) { objDetails.Amount = item.Amount; objDetails.Charge = item.Charges; objDetails.ChargesId = item.ChargesId; objDetails.NoofDays = item.NoofDays; objDetails.Quantity = item.Quantity; objDetails.IsDelete = item.IsDelete; objDetails.ICUBedAllocId = item.ICUBedAllocId; } } } List <tblCustomerTransaction> objCust = (from tbl in objData.tblCustomerTransactions where tbl.IsDelete == false && tbl.TransactionDocNo == entInvoice.InvoiceNo && tbl.TransactionType == "ICUInvoice" select tbl).ToList(); if (obj != null && objCust != null) { if (objCust.Count == 1) { if (entInvoice.IsCash.Value) { tblCustomerTransaction objC = new tblCustomerTransaction() { PayAmount = entInvoice.NetAmount, ReceiptDate = entInvoice.AllocationDate, IsCash = entInvoice.IsCash, IsDelete = false, TransactionDocNo = entInvoice.ICUBedAllocId, TransactionId = objCust[0].TransactionId, TransactionType = "ICUInvoice", PatientId = entInvoice.PatientId, }; objData.tblCustomerTransactions.InsertOnSubmit(objC); 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 = entInvoice.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 = entInvoice.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 = entInvoice.NetAmount; } } } } objData.SubmitChanges(); count++; } catch (Exception ex) { count = 0; throw ex; } return(count); }
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; } }