public static PaymentViewModel Create(EnumPaymentType paymentType, ITPaymentRepository tPaymentRepository, ITPaymentDetRepository tPaymentDetRepository) { PaymentViewModel viewModel = new PaymentViewModel(); TPayment p = new TPayment(); p.SetAssignedIdTo(Guid.NewGuid().ToString()); p.PaymentDate = DateTime.Today; p.PaymentDesc = string.Empty; p.PaymentType = paymentType.ToString(); viewModel.Payment = p; viewModel.Title = string.Format("Pembayaran {0}", paymentType.ToString()); //get label text switch (paymentType) { case EnumPaymentType.Piutang: viewModel.CashAccountLabel = "Deposit ke : "; break; case EnumPaymentType.Hutang: viewModel.CashAccountLabel = "Deposit dari : "; break; } return(viewModel); }
private void SavePayment(TPayment payment, FormCollection formCollection, bool isEdit) { //if (isEdit) //{ // if (ListDeleteDetailTrans != null) // if (ListDeleteDetailTrans.Count > 0) // DeleteTransactionDetail(Trans, addStock, calculateStock, ListDeleteDetailTrans.ToArray()); //} payment.PaymentDets.Clear(); //save detail string splitter = ","; string[] selectedTransId = formCollection["SelectedTransId"].Split(splitter.ToCharArray()); TPaymentDet detToInsert; TTrans trans; decimal total = 0; for (int i = 0; i < selectedTransId.Length; i++) { trans = _tTransRepository.Get(selectedTransId[i]); if (trans != null) { detToInsert = new TPaymentDet(payment); detToInsert.SetAssignedIdTo(Guid.NewGuid().ToString()); detToInsert.TransId = trans; detToInsert.PaymentDetValue = trans.TransGrandTotal; detToInsert.CreatedDate = DateTime.Now; detToInsert.CreatedBy = User.Identity.Name; detToInsert.DataStatus = Enums.EnumDataStatus.New.ToString(); payment.PaymentDets.Add(detToInsert); total += detToInsert.PaymentDetValue.HasValue ? detToInsert.PaymentDetValue.Value : 0; } } payment.PaymentTotal = total; if (isEdit) { _tPaymentRepository.Update(payment); } else { _tPaymentRepository.Save(payment); } ////save journal //SaveJournal(payment); }
private void SavePayment() { TPayment p = new TPayment(); p.FinanceId = financeIdComboBox.SelectedValue.ToString(); p.ModifiedBy = lbl_UserName.Text; p.ModifiedDate = DateTime.Now; p.PaymentAmmount = paymentAmmountNumericUpDown.Value; p.PaymentDate = paymentDateDateTimePicker.Value; p.PaymentDesc = paymentDescTextBox.Text; p.PaymentId = Guid.NewGuid().ToString(); p.TransactionId = transactionIdTextBox.Text; DataMaster.SavePersistence(p); }
public static PaymentViewModel Create(EnumPaymentType paymentType, ITPaymentRepository tPaymentRepository, ITPaymentDetRepository tPaymentDetRepository, IMSupplierRepository mSupplierRepository, IMCustomerRepository mCustomerRepository, IMCostCenterRepository mCostCenterRepository) { PaymentViewModel viewModel = new PaymentViewModel(); TPayment p = new TPayment(); p.SetAssignedIdTo(Guid.NewGuid().ToString()); p.PaymentDate = DateTime.Today; p.PaymentDesc = string.Empty; p.PaymentType = paymentType.ToString(); viewModel.Payment = p; viewModel.Title = string.Format("Pembayaran {0}", paymentType.ToString()); IList <MCostCenter> list = mCostCenterRepository.GetAll(); MCostCenter costCenter = new MCostCenter(); costCenter.CostCenterName = "-Pilih Cost Center-"; list.Insert(0, costCenter); viewModel.CostCenterList = new SelectList(list, "Id", "CostCenterName"); //get label text switch (paymentType) { case EnumPaymentType.Piutang: viewModel.CashAccountLabel = "Deposit ke : "; //fill cust var values = from MCustomer cust in mCustomerRepository.GetAll() select new { Id = cust.Id, Name = cust.PersonId != null ? cust.PersonId.PersonName : "-Pilih Konsumen-" }; viewModel.TransByList = new SelectList(values, "Id", "Name"); break; case EnumPaymentType.Hutang: viewModel.CashAccountLabel = "Deposit dari : "; IList <MSupplier> listAcc = mSupplierRepository.GetAll(); MSupplier supplier = new MSupplier(); supplier.SupplierName = "-Pilih Supplier-"; listAcc.Insert(0, supplier); viewModel.TransByList = new SelectList(listAcc, "Id", "SupplierName"); break; } return(viewModel); }
private void SaveJournal(TPayment payment, string transBy, string cashAccountId, string costCenterId, string desc) { TJournal journal = new TJournal(); journal.JournalType = EnumJournalType.GeneralLedger.ToString(); journal.JournalVoucherNo = Helper.CommonHelper.GetVoucherNo(); journal.JournalDate = payment.PaymentDate; journal.JournalDesc = payment.PaymentDesc; journal.JournalPic2 = payment.PaymentPic; journal.JournalPic = transBy; journal.SetAssignedIdTo(Guid.NewGuid().ToString()); journal.CostCenterId = _mCostCenterRepository.Get(costCenterId); journal.CreatedDate = DateTime.Now; journal.CreatedBy = User.Identity.Name; journal.DataStatus = Enums.EnumDataStatus.New.ToString(); journal.JournalDets.Clear(); MAccount accountCash = _mAccountRepository.Get(cashAccountId); MAccountRef accountRef; if (payment.PaymentType == EnumPaymentType.Hutang.ToString()) { //search supplier hutang account accountRef = _mAccountRefRepository.GetByRefTableId(EnumReferenceTable.Supplier, transBy); //save debet SaveJournalDet(journal, EnumJournalStatus.D, accountRef.AccountId, payment.PaymentTotal, desc); //save kredit SaveJournalDet(journal, EnumJournalStatus.K, accountCash, payment.PaymentTotal, desc); } else if (payment.PaymentType == EnumPaymentType.Piutang.ToString()) { //search Customer piutang account accountRef = _mAccountRefRepository.GetByRefTableId(EnumReferenceTable.Customer, transBy); //save debet SaveJournalDet(journal, EnumJournalStatus.D, accountCash, payment.PaymentTotal, desc); //save kredit SaveJournalDet(journal, EnumJournalStatus.K, accountRef.AccountId, payment.PaymentTotal, desc); } _tJournalRepository.Save(journal); }
public Task <ResultWrapper <CustomerCreatePaymentSessionOutput> > Handle(CustomerCreatePaymentSessionCommand request, CancellationToken cancellationToken) { ResultWrapper <CustomerCreatePaymentSessionOutput> result = new ResultWrapper <CustomerCreatePaymentSessionOutput>(); try { using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew)) { TUser tUser = _dbContext.TUser.FirstOrDefault(x => x.FireBaseId == request.firebaseId); if (tUser == null) { result.Status = false; result.Message = "cannot find customer!"; return(Task.FromResult(result)); } if (!request.OrderItems.Any()) { result.Status = false; result.Message = "invalid foods data!"; return(Task.FromResult(result)); } TUser tSupplier = _dbContext.TFood .Include(x => x.TUser) .FirstOrDefault(x => x.Id == request.OrderItems.First().FoodId)?.TUser; if (tSupplier == null) { result.Status = false; result.Message = "cannot find supplier!"; return(Task.FromResult(result)); } string generatedCode = ""; string generatedTitle = ""; Guid PaymentUniqueId = Guid.NewGuid(); TOrder tOrder = new TOrder() { Enabled = true, Code = generatedCode, Created = DateTime.Now, Date = DateTime.Now, Title = generatedTitle, TrackingCode = PaymentUniqueId.ToString(), TSupplierId = tSupplier.Id, TUserId = tUser.Id, TotalPayablePrice = 0, Submited = false }; _dbContext.TOrder.Add(tOrder); _dbContext.SaveChanges(); decimal TotalPayablePrice = 0; foreach (var detail in request.OrderItems) { TFood food = _dbContext.TFood .FirstOrDefault(x => x.Id == detail.FoodId); if (food == null) { result.Status = false; result.Message = "invalid food data!"; return(Task.FromResult(result)); } TOrderDetail tOrderDetail = new TOrderDetail() { Enabled = true, Created = DateTime.Now, Amount = detail.Amount, TFoodId = food.Id, TUserId = tSupplier.Id, UnitPrice = food.Price, RowPrice = food.Price * detail.Amount, TOrderId = tOrder.Id }; TotalPayablePrice += tOrderDetail.RowPrice; _dbContext.TOrderDetail.Add(tOrderDetail); } _dbContext.SaveChanges(); tOrder.TotalPayablePrice = TotalPayablePrice; _dbContext.TOrder.Update(tOrder); _dbContext.SaveChanges(); string SuccessUrl = request.SuccessUrl + "?UID=" + PaymentUniqueId; TPayment tPayment = new TPayment() { UniqueId = PaymentUniqueId, UserId = tUser.Id, Amount = TotalPayablePrice, OrderId = tOrder.Id, Success = false, Used = false, Enabled = true, Created = DateTime.Now, }; _dbContext.TPayment.Add(tPayment); _dbContext.SaveChanges(); transaction.Complete(); string secretKey = "sk_test_51JKejjB9j2pHQUNgVymkcotBwOhw64UhTOxrOWLn6QzpdIqmUOGh0lJCkozGMgWNLYQcg4XKriYmiNjfDRiwujnV00Lv2iKYgC"; StripeConfiguration.ApiKey = secretKey; var options = new SessionCreateOptions() { PaymentMethodTypes = new List <String>() { "card" }, LineItems = new List <SessionLineItemOptions>() { }, PaymentIntentData = new SessionPaymentIntentDataOptions() { ApplicationFeeAmount = 500, TransferData = new SessionPaymentIntentDataTransferDataOptions() { Destination = "acct_1JL9JuPUzKlkrnDH" } }, Mode = "payment", SuccessUrl = SuccessUrl, CancelUrl = request.CancelUrl }; foreach (var item in request.OrderItems) { options.LineItems.Add(new SessionLineItemOptions() { Quantity = item.Amount, PriceData = new SessionLineItemPriceDataOptions() { Currency = "usd", UnitAmount = item.Price, ProductData = new SessionLineItemPriceDataProductDataOptions() { Name = item.FoodId.ToString() } } }); } var service = new SessionService(); Task <Session> session = service.CreateAsync(options); session.Wait(); result = new ResultWrapper <CustomerCreatePaymentSessionOutput>() { Status = true, Result = new CustomerCreatePaymentSessionOutput() { SessionId = session.Result.Id, SessionUrl = session.Result.Url } }; } } catch (Exception ex) { result.Status = false; result.Message = ex.Message; } return(Task.FromResult(result)); }
private ActionResult SavePayment(EnumPaymentType paymentType, TPayment paymentVM, FormCollection formCollection, bool isDelete) { string Message = string.Empty; bool Success = true; try { _tPaymentRepository.DbContext.BeginTransaction(); //check first TPayment payment = _tPaymentRepository.Get(formCollection["Id"]); if (!isDelete) { bool isEdit = false; if (payment == null) { isEdit = false; //if payment = new TPayment(); payment.SetAssignedIdTo(Guid.NewGuid().ToString()); payment.CreatedDate = DateTime.Now; payment.CreatedBy = User.Identity.Name; payment.DataStatus = Enums.EnumDataStatus.New.ToString(); } else { isEdit = true; payment.ModifiedDate = DateTime.Now; payment.ModifiedBy = User.Identity.Name; payment.DataStatus = Enums.EnumDataStatus.Updated.ToString(); } payment.PaymentDate = paymentVM.PaymentDate; payment.PaymentDesc = paymentVM.PaymentDesc; payment.PaymentStatus = paymentVM.PaymentStatus; payment.PaymentType = paymentType.ToString(); SavePayment(payment, formCollection, isEdit); } else { //if (tr != null) //{ // //do delete // DeleteTransaction(tr, addStock, calculateStock); //} } _tPaymentRepository.DbContext.CommitTransaction(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success; if (!isDelete) { Message = "Data berhasil disimpan."; } else { Message = "Data berhasil dihapus."; } } catch (Exception ex) { Success = false; if (!isDelete) { Message = "Data gagal disimpan."; } else { Message = "Data gagal dihapus."; } Message += "Error : " + ex.GetBaseException().Message; _tPaymentRepository.DbContext.RollbackTransaction(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed; } var e = new { Success, Message }; return(Json(e, JsonRequestBehavior.AllowGet)); }
public ActionResult Index(EnumPaymentType paymentType, PaymentViewModel viewModel, TPayment paymentVM, FormCollection formCollection) { if (formCollection["btnSave"] != null) { return(SavePayment(paymentType, paymentVM, formCollection, false)); } else if (formCollection["btnDelete"] != null) { return(SavePayment(paymentType, paymentVM, formCollection, true)); } return(View()); }
public ActionResult ThanhToanKeDonThuocTaiQuay(TPayment objPayment, TPatientExam objPatientExam, TPaymentDetail[] objArrPaymentDetail) { decimal PtramBHYT = 0; ///tổng tiền hiện tại truyền vào của lần payment đang thực hiện decimal v_TotalOrginPrice = 0; ///tổng tiền đã thanh toán decimal v_TotalPaymentDetail = 0; try { using (var scope = new TransactionScope()) { using (var dbscope = new SharedDbConnectionScope()) { ///lấy tổng số Payment của mang truyền vào của pay ment hiện tại //v_TotalOrginPrice = SumOfPaymentDetail_NGOAITRU(objArrPaymentDetail); TPaymentCollection paymentCollection = new TPaymentController().FetchByQuery( TPayment.CreateQuery().AddWhere(TPayment.Columns.PatientCode, Comparison.Equals, objPatientExam.PatientCode).AND( TPayment.Columns.PatientId, Comparison.Equals, objPatientExam.PatientId).AND( TPayment.Columns.Status, Comparison.Equals, 0). AND(TPayment.Columns.KieuThanhToan, Comparison.Equals, 0).AND( TPayment.Columns.Status, Comparison.Equals, 0)); foreach (TPayment Payment in paymentCollection) { TPaymentDetailCollection paymentDetailCollection = new Select().From(TPaymentDetail.Schema) .Where(TPaymentDetail.Columns.IdThanhtoan).IsEqualTo(Payment.IdThanhtoan) .And(TPaymentDetail.Columns.IsCancel).IsEqualTo(0).ExecuteAsCollection <TPaymentDetailCollection>(); foreach (TPaymentDetail paymentDetail in paymentDetailCollection) { if (paymentDetail.IsPayment == 0) { v_TotalPaymentDetail += Utility.Int32Dbnull(paymentDetail.Quantity) * Utility.DecimaltoDbnull(paymentDetail.OriginPrice); } } } ///lấy thông tin chiết khấu xem đã thực hiện chưa LayThongPtramBHYT(v_TotalOrginPrice + v_TotalPaymentDetail, objPatientExam, ref PtramBHYT); log.Info(string.Format("Thong tin chi khau {0}, voi ma Patient_Code{1}", PtramBHYT, objPatientExam.PatientCode)); ///hàm thực hiện việc xử lý lại thông tin // XuLyChiKhauDacBietBHYT(objPatientExam, PtramBHYT); objPayment.DaIn = 0; objPayment.KieuThanhToan = 0; objPayment.NguoiIn = string.Empty; objPayment.TrongGoi = 0; objPayment.IpMacTao = BusinessHelper.GetMACAddress(); objPayment.IpMayTao = BusinessHelper.GetIP4Address(); objPayment.PaymentCode = BusinessHelper.GeneratePaymentCode(Convert.ToDateTime(objPayment.NgayThanhtoan), 0); objPayment.IsNew = true; objPayment.Save(); //StoredProcedure sp = SPs.KcbThanhtoanThemmoi(objPayment.IdThanhtoan, objPayment.PatientCode, objPayment.PatientId, // objPayment.NgayThanhtoan, objPayment.StaffId, objPayment.Status, // objPayment.CreatedBy, objPayment.CreatedDate, objPayment.ModifyDate, // objPayment.ModifyBy, objPayment.PaymentCode, objPayment.KieuThanhToan, // objPayment.DaIn, objPayment.NgayIn, objPayment.NgayTHop, objPayment.NguoiIn, // objPayment.NguoiTHop, Utility.Int32Dbnull(objPayment.TrongGoi), objPayment.IpMayTao, objPayment.IpMacTao, globalVariables.MA_KHOA_THIEN); //sp.Execute(); //objPayment.IdThanhtoan = Utility.Int32Dbnull(sp.OutputValues[0], -1); //objPayment.IdThanhtoan = Utility.Int32Dbnull(_QueryPayment.GetMax(TPayment.Columns.IdThanhtoan), -1); log.Info("Lay ma thanh toan cua phan thanh toan Payment_ID={0}", objPayment.IdThanhtoan); ///hàm thực hiện việc mảng thao tác mảng của chi tiết thanh toán foreach (TPaymentDetail objPaymentDetail in objArrPaymentDetail) { log.Info("Thuc hien thanh cong cap nhap dich vu can lam sang "); ///thanh toán phần thuốc); if (THU_VIEN_CHUNG.LayMaDviLamViec() == "DETMAY") { if (objPaymentDetail.IdLoaithanhtoan == 3) { new Update(TPrescription.Schema) .Set(TPrescription.Columns.TrangthaiThanhtoan).EqualTo(1) .Set(TPrescription.Columns.Status).EqualTo(2) ///nếu =2 đối với đơn thuốc ngoại trú .Where(TPrescription.Columns.PresId).IsEqualTo(objPaymentDetail.Id).Execute(); } } log.Info("Thuc hien thanh cong cap nhap thuoc"); ///quần áo cho thuê); log.Info("Cap nhap thong tin thanh cong cho phan giuong benh"); switch (BusinessHelper.GetThanhToan_TraiTuyen()) { case "PHUTHU": if (objPaymentDetail.IdLoaithanhtoan == 1) { objPaymentDetail.SurchargePrice = 0; } break; } objPaymentDetail.NguoiTao = globalVariables.UserName; objPaymentDetail.NoiTru = 0; objPaymentDetail.TrongGoi = 0; objPaymentDetail.IpMacTao = BusinessHelper.GetMACAddress(); objPaymentDetail.IpMayTao = BusinessHelper.GetIP4Address(); objPaymentDetail.IdThanhtoan = Utility.Int32Dbnull(objPayment.IdThanhtoan, -1); objPaymentDetail.MaKieuTtoan = BusinessHelper.MaKieuThanhToan(Utility.Int32Dbnull(objPaymentDetail.IdLoaithanhtoan, -1)); objPaymentDetail.TienBnTra = Utility.DecimaltoDbnull(objPaymentDetail.DiscountPrice); StoredProcedure spPaymentDetail = SPs.KcbThanhtoanThemchitiet( objPaymentDetail.PaymentDetailId, objPaymentDetail.IdThanhtoan, objPaymentDetail.Quantity, objPaymentDetail.OriginPrice, objPaymentDetail.DiscountRate, Utility.DecimaltoDbnull(objPaymentDetail.DiscountPrice), Utility.DecimaltoDbnull(objPaymentDetail.TienBnTra), objPaymentDetail.SurchargePrice, objPaymentDetail.Id, objPaymentDetail.IdDetail, objPaymentDetail.ServiceId, objPaymentDetail.ServiceDetailId, objPaymentDetail.IdLoaithanhtoan, objPaymentDetail.IsCancel, objPaymentDetail.IsPayment, objPaymentDetail.CancelBy, objPaymentDetail.CancelDate, objPaymentDetail.DepartmentId, objPaymentDetail.DoctorAssignId, objPaymentDetail.ThuTuIn, objPaymentDetail.DonViTinh, objPaymentDetail.MaDv, objPaymentDetail.PTramBh, objPaymentDetail.ServiceDetailName, Utility.sDbnull(objPaymentDetail.ServiceDetailName), objPaymentDetail.MaKieuTtoan, 0, objPaymentDetail.TrongGoi, objPaymentDetail.IdGoiDvu, objPaymentDetail.NoiTru, objPaymentDetail.NguoiTao, objPaymentDetail.IpMacTao, objPaymentDetail.IpMayTao); spPaymentDetail.Execute(); objPaymentDetail.PaymentDetailId = Utility.Int32Dbnull(spPaymentDetail.OutputValues[0], -1); UpdateTrangThaiBangChucNang(objPayment, objPaymentDetail); log.Info("Thuc hien dua vao chen bang ghi cua phan ky dong"); } if (objPatientExam.MaDoiTuong == "BHYT") { if (globalVariables.gv_BenhVienTuyen == "TW") { SqlQuery sqlQuery = new Select().From(TPaymentDetail.Schema) .Where(TPaymentDetail.Columns.IdThanhtoan).In( new Select(TPayment.Columns.IdThanhtoan).From(TPayment.Schema).Where( TPayment.Columns.PatientCode).IsEqualTo( objPatientExam.PatientCode).And(TPayment.Columns.PatientId).IsEqualTo( objPatientExam.PatientId).And(TPayment.Columns.KieuThanhToan). IsEqualTo(0). And(TPayment.Columns.Status).IsEqualTo(0)) .And(TPaymentDetail.Columns.IsCancel).IsEqualTo(0) .And(TPaymentDetail.Columns.IsPayment).IsEqualTo(0); TPaymentDetailCollection objPaymentDetailCollection = sqlQuery.ExecuteAsCollection <TPaymentDetailCollection>(); decimal TongTien = Utility.DecimaltoDbnull(objPaymentDetailCollection.Sum(c => c.Quantity * c.OriginPrice)); LayThongPtramBHYT(TongTien, objPatientExam, ref PtramBHYT); foreach (TPaymentDetail objPaymentDetail in objPaymentDetailCollection) { decimal BHCT = Utility.DecimaltoDbnull(objPaymentDetail.OriginPrice * PtramBHYT / 100); decimal BNCT = Utility.DecimaltoDbnull(objPaymentDetail.OriginPrice - BHCT); new Update(TPaymentDetail.Schema) .Set(TPaymentDetail.Columns.PTramBh).EqualTo(PtramBHYT) .Set(TPaymentDetail.Columns.DiscountRate).EqualTo(BHCT) .Set(TPaymentDetail.Columns.DiscountPrice).EqualTo(BNCT) .Where(TPaymentDetail.Columns.PaymentDetailId).IsEqualTo(objPaymentDetail.PaymentDetailId).Execute(); } } } SPs.KydongThemthongtinThanhtoanThem(objPatientExam.PatientCode, Utility.Int32Dbnull(objPatientExam.PatientId, -1)). Execute(); } scope.Complete(); // Payment_Id = Utility.Int32Dbnull(objPayment.IdThanhtoan, -1); log.Info("Thuc hien thanh cong viec thanh toan"); return(ActionResult.Success); } } catch (Exception ex) { log.Error("Loi thuc hien thanh toan:" + ex.ToString()); return(ActionResult.Error); } }
public ActionResult ThanhToanKeDonThuocTaiQuay(TPayment objPayment, TPatientExam objPatientExam, TPaymentDetail[] objArrPaymentDetail) { decimal PtramBHYT = 0; ///tổng tiền hiện tại truyền vào của lần payment đang thực hiện decimal v_TotalOrginPrice = 0; ///tổng tiền đã thanh toán decimal v_TotalPaymentDetail = 0; try { using (var scope = new TransactionScope()) { using (var dbscope = new SharedDbConnectionScope()) { ///lấy tổng số Payment của mang truyền vào của pay ment hiện tại //v_TotalOrginPrice = SumOfPaymentDetail_NGOAITRU(objArrPaymentDetail); TPaymentCollection paymentCollection = new TPaymentController().FetchByQuery( TPayment.CreateQuery().AddWhere(TPayment.Columns.PatientCode, Comparison.Equals, objPatientExam.PatientCode).AND( TPayment.Columns.PatientId, Comparison.Equals, objPatientExam.PatientId).AND( TPayment.Columns.Status, Comparison.Equals, 0). AND(TPayment.Columns.KieuThanhToan, Comparison.Equals, 0).AND( TPayment.Columns.Status, Comparison.Equals, 0)); foreach (TPayment Payment in paymentCollection) { TPaymentDetailCollection paymentDetailCollection = new Select().From(TPaymentDetail.Schema) .Where(TPaymentDetail.Columns.IdThanhtoan).IsEqualTo(Payment.IdThanhtoan) .And(TPaymentDetail.Columns.IsCancel).IsEqualTo(0).ExecuteAsCollection <TPaymentDetailCollection>(); foreach (TPaymentDetail paymentDetail in paymentDetailCollection) { if (paymentDetail.IsPayment == 0) v_TotalPaymentDetail += Utility.Int32Dbnull(paymentDetail.Quantity) * Utility.DecimaltoDbnull(paymentDetail.OriginPrice); } } ///lấy thông tin chiết khấu xem đã thực hiện chưa LayThongPtramBHYT(v_TotalOrginPrice + v_TotalPaymentDetail, objPatientExam, ref PtramBHYT); log.Info(string.Format("Thong tin chi khau {0}, voi ma Patient_Code{1}", PtramBHYT, objPatientExam.PatientCode)); ///hàm thực hiện việc xử lý lại thông tin // XuLyChiKhauDacBietBHYT(objPatientExam, PtramBHYT); objPayment.DaIn = 0; objPayment.KieuThanhToan = 0; objPayment.NguoiIn = string.Empty; objPayment.TrongGoi = 0; objPayment.IpMacTao = BusinessHelper.GetMACAddress(); objPayment.IpMayTao = BusinessHelper.GetIP4Address(); objPayment.PaymentCode = BusinessHelper.GeneratePaymentCode(Convert.ToDateTime(objPayment.NgayThanhtoan), 0); objPayment.IsNew = true; objPayment.Save(); //StoredProcedure sp = SPs.KcbThanhtoanThemmoi(objPayment.IdThanhtoan, objPayment.PatientCode, objPayment.PatientId, // objPayment.NgayThanhtoan, objPayment.StaffId, objPayment.Status, // objPayment.CreatedBy, objPayment.CreatedDate, objPayment.ModifyDate, // objPayment.ModifyBy, objPayment.PaymentCode, objPayment.KieuThanhToan, // objPayment.DaIn, objPayment.NgayIn, objPayment.NgayTHop, objPayment.NguoiIn, // objPayment.NguoiTHop, Utility.Int32Dbnull(objPayment.TrongGoi), objPayment.IpMayTao, objPayment.IpMacTao, globalVariables.MA_KHOA_THIEN); //sp.Execute(); //objPayment.IdThanhtoan = Utility.Int32Dbnull(sp.OutputValues[0], -1); //objPayment.IdThanhtoan = Utility.Int32Dbnull(_QueryPayment.GetMax(TPayment.Columns.IdThanhtoan), -1); log.Info("Lay ma thanh toan cua phan thanh toan Payment_ID={0}", objPayment.IdThanhtoan); ///hàm thực hiện việc mảng thao tác mảng của chi tiết thanh toán foreach (TPaymentDetail objPaymentDetail in objArrPaymentDetail) { log.Info("Thuc hien thanh cong cap nhap dich vu can lam sang "); ///thanh toán phần thuốc); if (THU_VIEN_CHUNG.LayMaDviLamViec() == "DETMAY") { if (objPaymentDetail.IdLoaithanhtoan == 3) { new Update(TPrescription.Schema) .Set(TPrescription.Columns.TrangthaiThanhtoan).EqualTo(1) .Set(TPrescription.Columns.Status).EqualTo(2)///nếu =2 đối với đơn thuốc ngoại trú .Where(TPrescription.Columns.PresId).IsEqualTo(objPaymentDetail.Id).Execute(); } } log.Info("Thuc hien thanh cong cap nhap thuoc"); ///quần áo cho thuê); log.Info("Cap nhap thong tin thanh cong cho phan giuong benh"); switch (BusinessHelper.GetThanhToan_TraiTuyen()) { case "PHUTHU": if (objPaymentDetail.IdLoaithanhtoan == 1) { objPaymentDetail.SurchargePrice = 0; } break; } objPaymentDetail.NguoiTao = globalVariables.UserName; objPaymentDetail.NoiTru = 0; objPaymentDetail.TrongGoi = 0; objPaymentDetail.IpMacTao = BusinessHelper.GetMACAddress(); objPaymentDetail.IpMayTao = BusinessHelper.GetIP4Address(); objPaymentDetail.IdThanhtoan = Utility.Int32Dbnull(objPayment.IdThanhtoan, -1); objPaymentDetail.MaKieuTtoan = BusinessHelper.MaKieuThanhToan(Utility.Int32Dbnull(objPaymentDetail.IdLoaithanhtoan, -1)); objPaymentDetail.TienBnTra = Utility.DecimaltoDbnull(objPaymentDetail.DiscountPrice); StoredProcedure spPaymentDetail = SPs.KcbThanhtoanThemchitiet( objPaymentDetail.PaymentDetailId, objPaymentDetail.IdThanhtoan, objPaymentDetail.Quantity, objPaymentDetail.OriginPrice, objPaymentDetail.DiscountRate, Utility.DecimaltoDbnull(objPaymentDetail.DiscountPrice), Utility.DecimaltoDbnull(objPaymentDetail.TienBnTra), objPaymentDetail.SurchargePrice, objPaymentDetail.Id, objPaymentDetail.IdDetail, objPaymentDetail.ServiceId, objPaymentDetail.ServiceDetailId, objPaymentDetail.IdLoaithanhtoan, objPaymentDetail.IsCancel, objPaymentDetail.IsPayment, objPaymentDetail.CancelBy, objPaymentDetail.CancelDate, objPaymentDetail.DepartmentId, objPaymentDetail.DoctorAssignId, objPaymentDetail.ThuTuIn, objPaymentDetail.DonViTinh, objPaymentDetail.MaDv, objPaymentDetail.PTramBh, objPaymentDetail.ServiceDetailName, Utility.sDbnull(objPaymentDetail.ServiceDetailName), objPaymentDetail.MaKieuTtoan, 0, objPaymentDetail.TrongGoi, objPaymentDetail.IdGoiDvu, objPaymentDetail.NoiTru, objPaymentDetail.NguoiTao, objPaymentDetail.IpMacTao, objPaymentDetail.IpMayTao); spPaymentDetail.Execute(); objPaymentDetail.PaymentDetailId = Utility.Int32Dbnull(spPaymentDetail.OutputValues[0], -1); UpdateTrangThaiBangChucNang(objPayment, objPaymentDetail); log.Info("Thuc hien dua vao chen bang ghi cua phan ky dong"); } if (objPatientExam.MaDoiTuong == "BHYT") { if (globalVariables.gv_BenhVienTuyen == "TW") { SqlQuery sqlQuery = new Select().From(TPaymentDetail.Schema) .Where(TPaymentDetail.Columns.IdThanhtoan).In( new Select(TPayment.Columns.IdThanhtoan).From(TPayment.Schema).Where( TPayment.Columns.PatientCode).IsEqualTo( objPatientExam.PatientCode).And(TPayment.Columns.PatientId).IsEqualTo( objPatientExam.PatientId).And(TPayment.Columns.KieuThanhToan). IsEqualTo(0). And(TPayment.Columns.Status).IsEqualTo(0)) .And(TPaymentDetail.Columns.IsCancel).IsEqualTo(0) .And(TPaymentDetail.Columns.IsPayment).IsEqualTo(0); TPaymentDetailCollection objPaymentDetailCollection = sqlQuery.ExecuteAsCollection<TPaymentDetailCollection>(); decimal TongTien = Utility.DecimaltoDbnull(objPaymentDetailCollection.Sum(c => c.Quantity * c.OriginPrice)); LayThongPtramBHYT(TongTien, objPatientExam, ref PtramBHYT); foreach (TPaymentDetail objPaymentDetail in objPaymentDetailCollection) { decimal BHCT = Utility.DecimaltoDbnull(objPaymentDetail.OriginPrice * PtramBHYT / 100); decimal BNCT = Utility.DecimaltoDbnull(objPaymentDetail.OriginPrice - BHCT); new Update(TPaymentDetail.Schema) .Set(TPaymentDetail.Columns.PTramBh).EqualTo(PtramBHYT) .Set(TPaymentDetail.Columns.DiscountRate).EqualTo(BHCT) .Set(TPaymentDetail.Columns.DiscountPrice).EqualTo(BNCT) .Where(TPaymentDetail.Columns.PaymentDetailId).IsEqualTo(objPaymentDetail.PaymentDetailId).Execute(); } } } SPs.KydongThemthongtinThanhtoanThem(objPatientExam.PatientCode, Utility.Int32Dbnull(objPatientExam.PatientId, -1)). Execute(); } scope.Complete(); // Payment_Id = Utility.Int32Dbnull(objPayment.IdThanhtoan, -1); log.Info("Thuc hien thanh cong viec thanh toan"); return ActionResult.Success; } } catch (Exception ex) { log.Error("Loi thuc hien thanh toan:" + ex.ToString()); return ActionResult.Error; } }
public Task <ResultWrapper <CustomerSubmitOrderOutput> > Handle(CustomerSubmitOrderCommand request, CancellationToken cancellationToken) { ResultWrapper <CustomerSubmitOrderOutput> result = new ResultWrapper <CustomerSubmitOrderOutput>(); try { using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew)) { TUser tUser = _dbContext.TUser.FirstOrDefault(x => x.FireBaseId == request.firebaseId); if (tUser == null) { result.Status = false; result.Message = "cannot find customer!"; return(Task.FromResult(result)); } TOrder tOrder = _dbContext.TOrder .Include(x => x.TUser) .FirstOrDefault(x => x.TUser.FireBaseId == request.firebaseId && x.TrackingCode == request.UID.ToString()); if (tOrder == null) { result.Status = false; result.Message = "can't find order!"; return(Task.FromResult(result)); } TPayment TPayment = _dbContext.TPayment .FirstOrDefault(x => x.UniqueId == request.UID && x.UserId == tUser.Id); if (TPayment == null) { result.Status = false; result.Message = "cannot find uid!"; return(Task.FromResult(result)); } if (TPayment.Used) { result.Status = false; result.Message = "already submited!"; return(Task.FromResult(result)); } TPayment.Success = true; TPayment.Used = true; _dbContext.TPayment.Update(TPayment); _dbContext.SaveChanges(); tOrder.Submited = true; _dbContext.TOrder.Update(tOrder); _dbContext.SaveChanges(); transaction.Complete(); result.Status = true; result.Result = new CustomerSubmitOrderOutput() { Id = tOrder.Id }; } } catch (Exception ex) { result.Status = false; result.Message = ex.Message; } return(Task.FromResult(result)); }
private void GetData() { string ReasonBy = ""; string sAccountName = THU_VIEN_CHUNG.LayMaDviLamViec(); LayThongTinPaymentDetail(sAccountName); //grdPaymentDetail.DataSource = m_dtPaymentDetail; SqlQuery sqlQuery = new Select().From(TPhieuthu.Schema) .Where(TPhieuthu.Columns.PaymentId).IsEqualTo(Utility.Int32Dbnull(txtPayment_ID.Text)).And( TPhieuthu.Columns.LoaiPhieu).IsEqualTo(status); if (sqlQuery.GetRecordCount() <= 0) { TPayment objPayment = TPayment.FetchByID(Utility.Int32Dbnull(txtPayment_ID.Text, -1)); if (objPayment != null) { dtCreateDate.Value = Convert.ToDateTime(objPayment.PaymentDate); txtPayment_ID.Text = Utility.sDbnull(objPayment.PaymentId, "-1"); txtMA_PTHU.Text = BusinessHelper.GetMaPhieuThu(dtCreateDate.Value, 0); Janus.Windows.GridEX.GridEXColumn gridExColumn = grdPaymentDetail.RootTable.Columns["TONG"]; txtSO_TIEN.Text = Utility.sDbnull(grdPaymentDetail.GetTotal(gridExColumn, Janus.Windows.GridEX.AggregateFunction.Sum)); txtSLUONG_CTU_GOC.Text = "1"; TPatientInfo objPatientInfo = TPatientInfo.FetchByID(objPayment.PatientId); if (objPatientInfo != null) { txtNGUOI_NOP.Text = objPatientInfo.PatientName; label9.Text = "Người nhận"; } if (status == 0) { switch (sAccountName) { case "YHOCHAIQUAN": ReasonBy = BusinessHelper.GetLyDo_PhieuThu(m_dtPaymentDetail); txtLDO_NOP.Text = ReasonBy; break; case "KYDONG": ReasonBy = BusinessHelper.GetLyDo_PhieuThu(m_dtPaymentDetail); txtLDO_NOP.Text = ReasonBy; break; case "DETMAY": LObjectType objectType = LObjectType.FetchByID(v_ObjectType_Id); if (objectType.ObjectTypeType == 0) { txtLDO_NOP.Text = string.Format("Bệnh nhân cùng chi trả :{0} %", (100 - v_DiscountRate)); } else { ReasonBy = BusinessHelper.GetLyDo_PhieuThu(m_dtPaymentDetail); txtLDO_NOP.Text = ReasonBy; } break; default: ReasonBy = BusinessHelper.GetLyDo_PhieuThu(m_dtPaymentDetail); txtLDO_NOP.Text = ReasonBy; break; } } if (status == 1) { ReasonBy = "Trả lại tiền cho bệnh nhân"; txtLDO_NOP.Text = ReasonBy; } } } else { var objPhieuthu = sqlQuery.ExecuteSingle <TPhieuthu>(); if (objPhieuthu != null) { txtSLUONG_CTU_GOC.Text = Utility.sDbnull(objPhieuthu.SluongCtuGoc, 1); txtMA_PTHU.Text = Utility.sDbnull(objPhieuthu.MaPthu, ""); txtNGUOI_NOP.Text = Utility.sDbnull(objPhieuthu.NguoiNop); txtSO_TIEN.Text = Utility.sDbnull(objPhieuthu.SoTien); txtTKHOAN_CO.Text = Utility.sDbnull(objPhieuthu.TkhoanCo, ""); txtTKHOAN_NO.Text = Utility.sDbnull(objPhieuthu.TkhoanNo, ""); txtLDO_NOP.Text = objPhieuthu.LdoNop; dtCreateDate.Value = Convert.ToDateTime(objPhieuthu.NgayThien); } } }