protected void BtnEdit_Click(object sender, EventArgs e) { try { List <TestAllocation> lst = new List <TestAllocation>(); tblTestInvoice obj = new tblTestInvoice(); obj.Amount = Convert.ToDecimal(txtNetAmount.Text); obj.TestInvoiceNo = Convert.ToInt32(Session["TestInvoiceId"]); obj.Discount = Convert.ToDecimal(txtDiscountAmt.Text); obj.PatientId = Convert.ToInt32(ddlPatient.SelectedValue); string[] arr = txtAllocDate.Text.Split('/'); obj.TestInvoiceDate = new DateTime(Convert.ToInt32(arr[arr.Length - 1]), Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1])); foreach (GridViewRow item in dgvAllTests.Rows) { CheckBox chk = (CheckBox)item.FindControl("chkSelect"); if (chk.Checked) { lst.Add(new TestAllocation() { IsTestDone = false, TestId = Convert.ToInt32(dgvAllTests.DataKeys[item.RowIndex].Value), Charges = Convert.ToDecimal(item.Cells[2].Text) }); } } bool IsCash = chkIsCash.Checked ? true : false; int i = new clsTestAllocation().Update(lst, obj, IsCash); GetInvoiceList(); } catch (Exception ex) { lblMessage.Text = ex.Message; } MultiView1.SetActiveView(View2); }
protected void BtnSave_Click(object sender, EventArgs e) { try { if (dgvAllTests.Rows.Count == 0) { lblMessage.Text = "Please Add Test before Allocate to Patient."; ddlPatient.Focus(); return; } List <TestAllocation> lst = new List <TestAllocation>(); tblTestInvoice obj = new tblTestInvoice(); obj.Amount = Convert.ToDecimal(txtNetAmount.Text); obj.Discount = Convert.ToDecimal(txtDiscountAmt.Text); obj.PatientId = Convert.ToInt32(ddlPatient.SelectedValue); obj.TestInvoiceDate = Convert.ToDateTime(txtAllocDate.Text); foreach (GridViewRow item in dgvAllTests.Rows) { CheckBox chk = (CheckBox)item.FindControl("chkSelect"); if (chk.Checked) { lst.Add(new TestAllocation() { IsTestDone = false, TestId = Convert.ToInt32(dgvAllTests.DataKeys[item.RowIndex].Value), Charges = Convert.ToDecimal(item.Cells[2].Text), TestInvoiceNo = Convert.ToInt32(Session["TestInvoiceId"]) }); } } bool IsCash = chkIsCash.Checked ? true : false; int i = new clsTestAllocation().Save(lst, obj, IsCash); lblMsg.Text = "Record Saved Successfully"; BindTests(); GetInvoiceList(); //Response.Redirect("frmNewIPDPatient.aspx", false); } catch (Exception ex) { lblMsg.Text = ex.Message; } MultiView1.SetActiveView(View2); }
public int Save(List <TestAllocation> lst, tblTestInvoice obj, bool IsCash) { int?Id = 0; objData.STP_Insert_tblTestInvoice(Convert.ToDateTime(DateTime.Now.Date), ref Id, Convert.ToInt32(obj.PatientId), Convert.ToDecimal(obj.Amount), Convert.ToDecimal(obj.Discount)); foreach (TestAllocation item in lst) { tblTestInvoiceDetail objtestDetails = new tblTestInvoiceDetail() { TestInvoiceId = Convert.ToInt32(Id), TestId = item.TestId, IsDelete = false, Charges = Convert.ToDecimal(item.Charges) }; objData.tblTestInvoiceDetails.InsertOnSubmit(objtestDetails); } int TransactionId = new PatientInvoiceBLL().GetTransactionId(); if (IsCash) { tblCustomerTransaction objDebit = new tblCustomerTransaction() { TransactionId = TransactionId, IsCash = true, TransactionDocNo = Id, TransactionType = "TestInvoice", BillAmount = obj.Amount, PayAmount = 0, PatientId = obj.PatientId, IsDelete = false, ReceiptDate = obj.TestInvoiceDate, }; objData.tblCustomerTransactions.InsertOnSubmit(objDebit); //objData.SubmitChanges(); tblCustomerTransaction objCrReceipt = new tblCustomerTransaction() { TransactionId = TransactionId, IsCash = true, TransactionDocNo = Id, TransactionType = "TestInvoice", PayAmount = obj.Amount, BillAmount = 0, PatientId = obj.PatientId, IsDelete = false, ReceiptDate = obj.TestInvoiceDate, }; objData.tblCustomerTransactions.InsertOnSubmit(objCrReceipt); //objData.SubmitChanges(); } else { tblCustomerTransaction objDebit = new tblCustomerTransaction() { TransactionId = TransactionId, IsCash = false, TransactionDocNo = Id, TransactionType = "TestInvoice", BillAmount = obj.Amount, PatientId = obj.PatientId, IsDelete = false, ReceiptDate = obj.TestInvoiceDate, }; objData.tblCustomerTransactions.InsertOnSubmit(objDebit); //objData.SubmitChanges(); } objData.SubmitChanges(); return(1); }
public int Update(List <TestAllocation> lst, tblTestInvoice obj, bool IsCash) { try { tblTestInvoice objTest = (from tbl in objData.tblTestInvoices where tbl.IsDelete == false && tbl.TestInvoiceNo == obj.TestInvoiceNo select tbl).FirstOrDefault(); List <TestAllocation> lstTemp = new List <TestAllocation>(); List <tblTestInvoiceDetail> lstCurrent = (from tbl in objData.tblTestInvoiceDetails where tbl.TestInvoiceId == obj.TestInvoiceNo && tbl.IsDelete == false select tbl).ToList(); List <tblCustomerTransaction> objCust = (from tbl in objData.tblCustomerTransactions where tbl.IsDelete == false && tbl.TransactionDocNo.Equals(Convert.ToString(obj.TestInvoiceNo)) && tbl.TransactionType.Equals("TestInvoice") select tbl).ToList(); if (objTest != null) { objTest.TestInvoiceDate = obj.TestInvoiceDate; objTest.Amount = obj.Amount; objTest.Discount = obj.Discount; objTest.PatientId = obj.PatientId; } if (objCust.Count == 1) { if (IsCash) { tblCustomerTransaction objC = new tblCustomerTransaction() { PayAmount = obj.Amount, ReceiptDate = obj.TestInvoiceDate, IsCash = IsCash, IsDelete = false, TransactionDocNo = obj.TestInvoiceNo, TransactionId = objCust[0].TransactionId, TransactionType = "TestInvoice", PatientId = obj.PatientId, BillAmount = 0 }; objData.tblCustomerTransactions.InsertOnSubmit(objC); foreach (tblCustomerTransaction item in objCust) { item.BillAmount = obj.Amount; item.ReceiptDate = obj.TestInvoiceDate; item.IsCash = IsCash; if (item.IsCash == false) { if (item.PayAmount > 0) { item.IsDelete = true; } } else { if (item.PayAmount > 0) { item.PayAmount = obj.Amount; } else { item.PayAmount = 0; } } } } else { foreach (tblCustomerTransaction item in objCust) { item.BillAmount = obj.Amount; item.ReceiptDate = obj.TestInvoiceDate; item.IsCash = IsCash; if (item.IsCash == false) { if (item.PayAmount > 0) { item.IsDelete = true; } } else { if (item.PayAmount > 0) { item.PayAmount = obj.Amount; } else { item.PayAmount = 0; } } } } } else { foreach (tblCustomerTransaction item in objCust) { item.BillAmount = obj.Amount; item.ReceiptDate = obj.TestInvoiceDate; item.IsCash = IsCash; if (item.IsCash == false) { if (item.PayAmount > 0) { item.IsDelete = true; } } else { if (item.PayAmount > 0) { item.PayAmount = obj.Amount; } else { item.PayAmount = 0; } } } } foreach (TestAllocation item in lst) { int cnt = (from tbl in objData.tblTestInvoiceDetails where tbl.TestInvoiceId == obj.TestInvoiceNo && tbl.TestId == item.TestId && tbl.IsDelete == false select tbl).ToList().Count; if (cnt == 0) { tblTestInvoiceDetail objNewAdded = new tblTestInvoiceDetail() { TestInvoiceId = obj.TestInvoiceNo, TestId = item.TestId, Charges = item.Charges, IsDelete = false, }; objData.tblTestInvoiceDetails.InsertOnSubmit(objNewAdded); objData.SubmitChanges(); } else { lstTemp.Add(item); } } foreach (tblTestInvoiceDetail item in lstCurrent) { int cnt = (from tbl in lst where tbl.TestInvoiceNo == item.TestInvoiceId && tbl.TestId == item.TestId select tbl).ToList().Count; if (cnt == 0) { int checkExist = (from tbl in lstTemp where tbl.TestId == item.TestId select tbl).ToList().Count; if (checkExist == 0) { item.IsDelete = true; } } } objData.SubmitChanges(); return(1); } catch (Exception ex) { throw ex; } }