public string Put() { RbacUser currentUser = HttpContext.Session.Get <RbacUser>("currentuser"); DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>(); responseData.Status = "OK"; try { BillingDbContext billingDbContext = new BillingDbContext(connString); string reqType = this.ReadQueryStringData("reqType"); int depositId = ToInt(this.ReadQueryStringData("depositId")); if (reqType == "updateDepositPrintCount") { BillingDeposit deposit = billingDbContext.BillingDeposits .Where(a => a.DepositId == depositId) .FirstOrDefault <BillingDeposit>(); if (deposit != null) { deposit.PrintCount = deposit.PrintCount == null || deposit.PrintCount == 0 ? 1 : deposit.PrintCount + 1; deposit.PrintedOn = System.DateTime.Now; //Yubraj: 13th August'19 deposit.PrintedBy = currentUser.EmployeeId; billingDbContext.Entry(deposit).Property(a => a.PrintCount).IsModified = true; } billingDbContext.SaveChanges(); responseData.Status = "OK"; } } catch (Exception ex) { responseData.Status = "Failed"; responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString(); } return(DanpheJSONConvert.SerializeObject(responseData, true)); }
[HttpPost]// POST api/values public string Post() { DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>(); //type 'object' since we have variable return types responseData.Status = "OK"; //by default status would be OK, hence assigning at the top string ipDataString = this.ReadPostData(); string reqType = this.ReadQueryStringData("reqType"); try { RbacUser currentUser = HttpContext.Session.Get <RbacUser>("currentuser"); BillingDbContext billingDbContext = new BillingDbContext(connString); if (reqType == "Deposit") { BillingDeposit deposit = DanpheJSONConvert.DeserializeObject <BillingDeposit>(ipDataString); deposit.CreatedOn = System.DateTime.Now; deposit.CreatedBy = currentUser.EmployeeId; BillingFiscalYear fiscYear = BillingBL.GetFiscalYear(connString); deposit.FiscalYearId = fiscYear.FiscalYearId; if (deposit.DepositType != "depositdeduct") { deposit.ReceiptNo = BillingBL.GetDepositReceiptNo(connString); } deposit.FiscalYear = fiscYear.FiscalYearFormatted; EmployeeModel currentEmp = billingDbContext.Employee.Where(emp => emp.EmployeeId == currentUser.EmployeeId).FirstOrDefault(); deposit.BillingUser = currentEmp.FirstName + " " + currentEmp.LastName; deposit.IsActive = true; //yubraj: 18th Dec '18 billingDbContext.BillingDeposits.Add(deposit); billingDbContext.SaveChanges(); responseData.Status = "OK"; responseData.Results = deposit;//check if we need to send back the whole input object back to client.--sudarshan } } catch (Exception ex) { responseData.Status = "Failed"; responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString(); } return(DanpheJSONConvert.SerializeObject(responseData, true)); }
//post to BIL_TXN_BillingTransaction public static BillingTransactionModel PostBillingTransaction(BillingDbContext dbContext, string connString, BillingTransactionModel billingTransaction, int userId, DateTime currentDate) { List <BillingTransactionItemModel> newTxnItems = new List <BillingTransactionItemModel>(); if (billingTransaction.BillingTransactionItems != null && billingTransaction.BillingTransactionItems.Count > 0) { foreach (var txnItem in billingTransaction.BillingTransactionItems) { newTxnItems.Add(BillingTransactionItemModel.GetClone(txnItem)); } billingTransaction.BillingTransactionItems = null; } //if paymentmode is credit, paiddate and paidamount should be null //handle this in client side as well. billingTransaction.CreatedBy = userId; if (billingTransaction.BillStatus == "unpaid") { billingTransaction.PaidDate = null; billingTransaction.PaidAmount = null; billingTransaction.PaymentReceivedBy = null; billingTransaction.PaidCounterId = null; } else if (billingTransaction.BillStatus == "paid") { billingTransaction.PaidDate = currentDate; billingTransaction.PaidCounterId = billingTransaction.CounterId; billingTransaction.PaymentReceivedBy = billingTransaction.CreatedBy; } BillingFiscalYear fiscYear = BillingBL.GetFiscalYear(connString); //ashim: 26Aug2018: Moved from client side to server side. billingTransaction.CreatedOn = currentDate; billingTransaction.CreatedBy = userId; billingTransaction.FiscalYearId = fiscYear.FiscalYearId; billingTransaction.InvoiceNo = BillingBL.GetInvoiceNumber(connString); //billingTransaction.InvoiceCode = BillingBL.InvoiceCode; billingTransaction.InvoiceCode = billingTransaction.IsInsuranceBilling == true ? "INS" : BillingBL.InvoiceCode; dbContext.BillingTransactions.Add(billingTransaction); dbContext.SaveChanges(); PostUpdateBillingTransactionItems(dbContext, connString, newTxnItems, userId, currentDate, billingTransaction.BillStatus, billingTransaction.CounterId, billingTransaction.BillingTransactionId); dbContext.SaveChanges(); //step:3-- if there's deposit deduction, then add to deposit table. if (billingTransaction.PaymentMode != "credit" && billingTransaction.DepositReturnAmount != null && billingTransaction.DepositReturnAmount > 0) { BillingDeposit dep = new BillingDeposit() { DepositType = "depositdeduct", Remarks = "Deposit used in InvoiceNo. " + billingTransaction.InvoiceCode + billingTransaction.InvoiceNo, //Remarks = "depositdeduct" + " for transactionid:" + billingTransaction.BillingTransactionId, IsActive = true, Amount = billingTransaction.DepositReturnAmount, BillingTransactionId = billingTransaction.BillingTransactionId, DepositBalance = billingTransaction.DepositBalance, FiscalYearId = billingTransaction.FiscalYearId, CounterId = billingTransaction.CounterId, CreatedBy = billingTransaction.CreatedBy, CreatedOn = currentDate, PatientId = billingTransaction.PatientId, PatientVisitId = billingTransaction.PatientVisitId, PaymentMode = billingTransaction.PaymentMode, PaymentDetails = billingTransaction.PaymentDetails, ReceiptNo = BillingBL.GetDepositReceiptNo(connString) }; billingTransaction.ReceiptNo = dep.ReceiptNo + 1; dbContext.BillingDeposits.Add(dep); dbContext.SaveChanges(); } billingTransaction.FiscalYear = fiscYear.FiscalYearFormatted; return(billingTransaction); }
[HttpPost]// POST api/values public string Post() { DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>(); int CreatedBy = ToInt(this.ReadQueryStringData("CreatedBy")); responseData.Status = "OK";//by default status would be OK, hence assigning at the top string ipDataString = this.ReadPostData(); string reqType = this.ReadQueryStringData("reqType"); try { BillingDbContext billingDbContext = new BillingDbContext(connString); if (reqType == "postSettlementInvoice")//submit { BillSettlementModel settlement = DanpheJSONConvert.DeserializeObject <BillSettlementModel>(ipDataString); //List<BillingTransactionItemModel> billTxnItm = DanpheJSONConvert.DeserializeObject<List<BillingTransactionItemModel>>(ipDataString); RbacUser currentUser = HttpContext.Session.Get <RbacUser>("currentuser"); using (var dbTransaction = billingDbContext.Database.BeginTransaction()) { try { var txns = settlement.BillingTransactions; //step:0, As EF automatically Inserts Child collection (billingtransactionmodel) while inserting settlement // we have to first create a new list and set settlement.BillingTransactions as null. List <BillingTransactionModel> newTxnList = new List <BillingTransactionModel>(); foreach (BillingTransactionModel txn in txns) { BillingTransactionModel newTxn = BillingTransactionModel.GetCloneWithItems(txn); newTxnList.Add(newTxn); } settlement.BillingTransactions = null; //Step1: assign server side values to the input model and Save the settlementModel settlement.SettlementReceiptNo = GetSettlementReceiptNo(billingDbContext); settlement.CreatedOn = System.DateTime.Now; settlement.SettlementDate = System.DateTime.Now; settlement.FiscalYearId = BillingBL.GetFiscalYear(billingDbContext).FiscalYearId; settlement.CreatedBy = currentUser.EmployeeId; billingDbContext.BillSettlements.Add(settlement); billingDbContext.SaveChanges(); if (newTxnList != null && newTxnList.Count > 0) { //step2: Update necessary fields of BillingTransaction acc to above Settlement Object foreach (var txn in newTxnList) { billingDbContext.BillingTransactions.Attach(txn); txn.SettlementId = settlement.SettlementId; txn.BillStatus = "paid"; txn.PaidAmount = txn.TotalAmount; txn.PaidDate = settlement.SettlementDate; txn.PaymentReceivedBy = currentUser.EmployeeId; //added: sud: 29may'18 txn.PaidCounterId = settlement.CounterId; //added: sud: 29may'18 billingDbContext.Entry(txn).Property(b => b.BillStatus).IsModified = true; billingDbContext.Entry(txn).Property(b => b.SettlementId).IsModified = true; billingDbContext.Entry(txn).Property(b => b.PaidAmount).IsModified = true; billingDbContext.Entry(txn).Property(b => b.PaidDate).IsModified = true; billingDbContext.Entry(txn).Property(b => b.PaymentReceivedBy).IsModified = true; //added: sud: 29may'18 billingDbContext.Entry(txn).Property(b => b.PaidCounterId).IsModified = true; //added: sud: 29may'18 //setp3: Update BillStatus and PaidDate of each transaction items attached with above transactions List <BillingTransactionItemModel> txnItems = billingDbContext.BillingTransactionItems .Where(b => b.BillingTransactionId == txn.BillingTransactionId).ToList(); if (txnItems != null && txnItems.Count > 0) { for (int i = 0; i < txnItems.Count; i++) { txnItems[i] = BillingTransactionBL.UpdateTxnItemBillStatus(billingDbContext, txnItems[i], "paid", currentUser.EmployeeId, settlement.SettlementDate, settlement.CounterId); } billingDbContext.SaveChanges(); } } billingDbContext.SaveChanges(); } //step: 4 Add new row to deposit table if Deposit is deducted if (settlement.DepositDeducted != null && settlement.DepositDeducted > 0) { VisitModel patientVisit = billingDbContext.Visit.Where(visit => visit.PatientId == settlement.PatientId) .OrderByDescending(a => a.PatientVisitId) .FirstOrDefault(); BillingDeposit depositModel = new BillingDeposit() { Amount = settlement.DepositDeducted, DepositType = "depositdeduct", IsActive = true, FiscalYearId = BillingBL.GetFiscalYear(billingDbContext).FiscalYearId, Remarks = "Deposit used in Settlement Receipt No. SR" + settlement.SettlementReceiptNo + " on " + settlement.SettlementDate, CreatedBy = currentUser.EmployeeId, CreatedOn = DateTime.Now, CounterId = settlement.CounterId, PatientVisitId = patientVisit != null ? (int?)patientVisit.PatientVisitId : null, SettlementId = settlement.SettlementId, PatientId = settlement.PatientId, DepositBalance = 0, ReceiptNo = BillingBL.GetDepositReceiptNo(connString), PaymentMode = "cash",//yubraj 4th July '19 }; billingDbContext.BillingDeposits.Add(depositModel); billingDbContext.SaveChanges(); ////update iscurrent and isactive in deposit table for settlement //List<BillingDeposit> depositDetail= (from dep in billingDbContext.BillingDeposits // where dep.PatientId==settlement.PatientId && // dep.IsCurrent==true && // dep.IsActive==true // select dep).ToList(); //if (depositDetail != null) //{ // depositDetail.ForEach(d => // { // //d.IsActive = false; // d.IsCurrent = false; // billingDbContext.SaveChanges(); // }); //} } dbTransaction.Commit(); responseData.Status = "OK"; responseData.Results = settlement; } catch (Exception ex) { dbTransaction.Rollback(); responseData.Status = "Failed"; responseData.ErrorMessage = ex.ToString(); } } } //responseData.Results = null; } catch (Exception ex) { responseData.Status = "Failed"; responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString(); } return(DanpheJSONConvert.SerializeObject(responseData, true)); }
[HttpPost]// POST api/values public string Post() { DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>(); //type 'object' since we have variable return types responseData.Status = "OK"; //by default status would be OK, hence assigning at the top try { string ipDataString = this.ReadPostData(); string reqType = this.ReadQueryStringData("reqType"); RbacUser currentUser = HttpContext.Session.Get <RbacUser>("currentuser"); BillingDbContext billingDbContext = new BillingDbContext(connString); if (reqType == "postBillTransaction")//submit { DateTime currentDate = DateTime.Now; BillingTransactionModel billTransaction = DanpheJSONConvert.DeserializeObject <BillingTransactionModel>(ipDataString); if (billTransaction != null) { //Transaction Begins using (var dbContextTransaction = billingDbContext.Database.BeginTransaction()) { try { //step:1 -- make copy of billingTxnItems into new list, so thate EF doesn't add txn items again. //step:2-- if there's deposit deduction, then add to deposit table. billTransaction = BillingTransactionBL.PostBillingTransaction(billingDbContext, connString, billTransaction, currentUser.EmployeeId, currentDate); //step:3-- if there's deposit balance, then add a return transaction to deposit table. if (billTransaction.PaymentMode != "credit" && billTransaction.DepositBalance != null && billTransaction.DepositBalance > 0) { BillingDeposit dep = new BillingDeposit() { DepositType = "ReturnDeposit", Remarks = "Deposit Refunded from InvoiceNo. " + billTransaction.InvoiceCode + billTransaction.InvoiceNo, //Remarks = "ReturnDeposit" + " for transactionid:" + billTransaction.BillingTransactionId, Amount = billTransaction.DepositBalance, IsActive = true, BillingTransactionId = billTransaction.BillingTransactionId, DepositBalance = 0, FiscalYearId = billTransaction.FiscalYearId, CounterId = billTransaction.CounterId, CreatedBy = billTransaction.CreatedBy, CreatedOn = currentDate, PatientId = billTransaction.PatientId, PatientVisitId = billTransaction.PatientVisitId, PaymentMode = billTransaction.PaymentMode, PaymentDetails = billTransaction.PaymentDetails, ReceiptNo = billTransaction.ReceiptNo }; billingDbContext.BillingDeposits.Add(dep); billingDbContext.SaveChanges(); } //For cancel BillingTransactionItems List <BillingTransactionItemModel> item = (from itm in billingDbContext.BillingTransactionItems where itm.PatientId == billTransaction.PatientId && itm.PatientVisitId == billTransaction.PatientVisitId && itm.BillStatus == "provisional" && itm.Quantity == 0 select itm).ToList(); if (item.Count() > 0) { item.ForEach(itm => { var txnItem = BillingTransactionBL.UpdateTxnItemBillStatus(billingDbContext, itm, "adtCancel", billTransaction.CreatedBy.Value, currentDate, billTransaction.CounterId, null); }); } dbContextTransaction.Commit(); responseData.Results = billTransaction; } catch (Exception ex) { //rollback all changes if any error occurs dbContextTransaction.Rollback(); throw ex; } } } else { responseData.Status = "Failed"; responseData.ErrorMessage = "billTransaction is invalid"; } } } catch (Exception ex) { responseData.Status = "Failed"; responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString(); } return(DanpheJSONConvert.SerializeObject(responseData, true)); }