public bool CheckTestCoveredByinsurance(long eventId, long packageId, IEnumerable <long> testIds) { var testCoveredByInsurance = false; var billingAccountTests = _billingAccountRepository.GetAllBillingAccountTests(); if (billingAccountTests == null || !billingAccountTests.Any()) { return(testCoveredByInsurance); } var insuredTestIds = billingAccountTests.Select(bat => bat.TestId).ToList(); var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventId, packageId); if (eventPackage != null) { testCoveredByInsurance = eventPackage.Package.Tests.Any(t => insuredTestIds.Contains(t.Id)); } if (!testCoveredByInsurance && !testIds.IsNullOrEmpty()) { return(testIds.Any(t => insuredTestIds.Contains(t))); } return(testCoveredByInsurance); }
public SourceCodeApplyEditModel ApplySourceCode(long packageId, IEnumerable <long> addOnTestIds, decimal orderTotal, string sourceCode, long eventId, long customerId, SignUpMode signUpMode, decimal shippingAmount = 0, decimal productAmount = 0) { var model = new SourceCodeApplyEditModel { OrderTotal = orderTotal, SourceCode = sourceCode, SignUpMode = (int)signUpMode, CustomerId = customerId, EventId = eventId }; if (packageId > 0) { var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventId, packageId); if (eventPackage != null) { model.Package = new OrderedPair <long, decimal>(eventPackage.PackageId, eventPackage.Price); } } if (addOnTestIds != null && addOnTestIds.Count() > 0) { var eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, addOnTestIds); if (eventTests != null && eventTests.Count > 0) { model.SelectedTests = eventTests.Select(et => new OrderedPair <long, decimal>(et.TestId, packageId > 0 ? et.WithPackagePrice : et.Price)); } } model = ApplySourceCode(model); return(model); }
public int GetScreeningTime(long eventId, long packageId, IEnumerable <long> testIds) { var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventId, packageId); var eventTests = !testIds.IsNullOrEmpty() ? _eventTestRepository.GetByEventAndTestIds(eventId, testIds) : null; return(GetScreeningTime(eventPackage, eventTests)); }
public void GetbyEventIdAndPackageId_ValidId_Tester() { var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(24759, 124); Assert.IsNotNull(eventPackage); Assert.AreEqual(eventPackage.Id, 73563); Assert.AreEqual(eventPackage.PackageId, 124); Assert.AreEqual(eventPackage.EventId, 24759); }
private void RemoveTestsAlreadyInPackage(long eventId, long packageId, List <long> selectedTestIds) { var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventId, packageId); var package = eventPackage != null ? eventPackage.Package : null; if (package != null && !selectedTestIds.IsNullOrEmpty()) { var packageTestIds = package.Tests.Select(t => t.Id); selectedTestIds.RemoveAll(t => packageTestIds.Contains(t)); } }
private void RemoveTestsAlreadyInPackage(long eventId, long packageId, List <long> selectedTestIds) { var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventId, packageId); var package = eventPackage != null ? eventPackage.Package : null; if (package != null && !selectedTestIds.IsNullOrEmpty()) { var packageTestIds = package.Tests.Select(t => t.Id); selectedTestIds.RemoveAll(packageTestIds.Contains); if (packageTestIds.Any(x => AbiGroup.Contains(x))) { selectedTestIds.RemoveAll(AbiGroup.Contains); } if (packageTestIds.Any(x => DpnMonofilamentGroup.Contains(x))) { selectedTestIds.RemoveAll(DpnMonofilamentGroup.Contains); } } }
private bool AdjustCustomerOrder(EventCustomer eventCustomer, Order currentOrder, long newPackageId, long oldPackageId, long createdByOrgRoleUserId, long customerId, IEnumerable <long> orderedTestIds, IEnumerable <long> preApprovedTestIds, IEnumerable <long> packageTestIds, long corporateUploadId) { if (corporateUploadId == 0) { return(false); } if (currentOrder != null && !currentOrder.OrderDetails.IsEmpty()) { if (eventCustomer == null) { return(false); } var OrderId = currentOrder.Id; var forOrganizationRoleUser = GetForOrganizationRoleUser(customerId); IOrderController orderController = new Falcon.App.Infrastructure.Finance.Impl.OrderController(); var currentPreApprovedTest = _preApprovedTestRepository.GetByCustomerId(customerId); if (IsOldPreApprovedTestSame(currentPreApprovedTest.Select(x => x.TestId), preApprovedTestIds)) { return(false); } // var selectedTestIds = orderedTestIds.ToList(); var selectedTestIds = new List <long>(); //if (!currentPreApprovedTest.IsNullOrEmpty()) //{ // var testIdToRemove = currentPreApprovedTest.Select(x => x.TestId); // selectedTestIds = selectedTestIds.Where(x => !testIdToRemove.Contains(x)).ToList(); //} //if (newPackageId != oldPackageId && oldPackageId != 0) //{ // selectedTestIds = selectedTestIds.Where(x => !packageTestIds.Contains(x)).ToList(); //} selectedTestIds.AddRange(preApprovedTestIds); var orderables = new List <IOrderable>(); long oldEventPackageId = 0; long newEventPackageId = 0; var oldEventTestIds = new List <long>(); var newEventTestIds = new List <long>(); EventPackage eventPackage = null; EventPackage oldEventPackage = null; if (newPackageId > 0) { eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventCustomer.EventId, newPackageId); } if (oldPackageId > 0) { oldEventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventCustomer.EventId, oldPackageId); } var testIdsInPackage = new List <long>(); if (eventPackage != null) { orderables.Add(eventPackage); newEventPackageId = eventPackage.Id; RemoveTestsAlreadyInPackage(selectedTestIds.ToList(), eventCustomer.EventId, eventPackage); testIdsInPackage = eventPackage.Package.Tests.Select(x => x.Id).ToList(); } if (oldEventPackage != null) { oldEventPackageId = oldEventPackage.Id; if (eventPackage == null) { orderables.Add(oldEventPackage); RemoveTestsAlreadyInPackage(selectedTestIds.ToList(), eventCustomer.EventId, oldEventPackage); testIdsInPackage = oldEventPackage.Package.Tests.Select(x => x.Id).ToList(); } } var oldEventTests = _eventTestRepository.GetByEventAndTestIds(eventCustomer.EventId, orderedTestIds); if (oldEventTests != null) { oldEventTestIds = oldEventTests.Select(x => x.Id).ToList(); } var disqualifiedTestIds = _disqualifiedTestRepository.GetLatestVersionTestId(eventCustomer.CustomerId, eventCustomer.EventId); var dependentDisqualifiedTestIds = _dependentDisqualifiedTestRepository.GetLatestVersionTestId(eventCustomer.CustomerId, eventCustomer.EventId); disqualifiedTestIds = (disqualifiedTestIds.Concat(dependentDisqualifiedTestIds)).Distinct(); //removing disqualified test from new order selectedTestIds = selectedTestIds.Where(x => !disqualifiedTestIds.Contains(x)).ToList(); //remove test which are already present in package test selectedTestIds = selectedTestIds.Where(x => !testIdsInPackage.Intersect(selectedTestIds).Contains(x)).ToList(); if (!selectedTestIds.IsNullOrEmpty()) { var eventTests = _eventTestRepository.GetByEventAndTestIds(eventCustomer.EventId, selectedTestIds); if (newPackageId > 0 || oldPackageId > 0) { foreach (var eventTest in eventTests) { eventTest.Price = eventTest.WithPackagePrice; } } orderables.AddRange(eventTests); newEventTestIds = eventTests.Select(x => x.Id).ToList(); } if (((oldEventPackageId > 0 && newEventPackageId == 0) || (newEventPackageId == oldEventPackageId)) && (newEventTestIds.All(oldEventTestIds.Contains) && newEventTestIds.Count == oldEventTestIds.Count)) { return(false); } if (orderables.IsNullOrEmpty()) { return(false); } var insurancePayment = currentOrder.PaymentsApplied.Where(pi => pi.PaymentType == Falcon.App.Core.Finance.Enum.PaymentType.Insurance).Select(pi => pi).SingleOrDefault(); if (insurancePayment != null) { _insurancePaymentRepository.Delete(insurancePayment.Id); } bool indentedLineItemsAdded = false; foreach (var orderable in orderables) { if (!indentedLineItemsAdded && (orderable.OrderItemType == OrderItemType.EventPackageItem || orderable.OrderItemType == OrderItemType.EventTestItem)) { orderController.AddItem(orderable, 1, forOrganizationRoleUser.Id, createdByOrgRoleUserId, null, null, null, OrderStatusState.FinalSuccess); indentedLineItemsAdded = true; } else { orderController.AddItem(orderable, 1, forOrganizationRoleUser.Id, createdByOrgRoleUserId, OrderStatusState.FinalSuccess); } } Order newOrder = orderController.PlaceOrder(currentOrder); _customerOrderHistoryService.SaveCustomerOrderHistory(eventCustomer, corporateUploadId, oldEventPackageId, newEventPackageId, oldEventTestIds, newEventTestIds); return(true); } return(false); }
public void ChangePackage(CustomerOrderDetail customerOrderDetail) { using (var scope = new TransactionScope()) { try { var eventid = customerOrderDetail.EventId; var customerid = customerOrderDetail.CustomerId; var order = GetOrder(customerid, eventid); IOrderController orderController = new OrderController(); var orderDetail = orderController.GetActiveOrderDetail(order); if (order == null || order.OrderDetails.IsEmpty()) { return; } var orderables = new List <IOrderable>(); var selectedTestIds = new List <long>(); if (customerOrderDetail.PreApprovedTestIds != null && customerOrderDetail.PreApprovedTestIds.Any()) { selectedTestIds = customerOrderDetail.PreApprovedTestIds.ToList(); } long packageId = 0; if (customerOrderDetail.PrePackageId > 0) { var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventid, customerOrderDetail.PrePackageId); if (eventPackage != null) { packageId = eventPackage.PackageId; } } if (packageId == 0) { if (orderDetail.OrderItem.OrderItemType == OrderItemType.EventPackageItem) { var eventPackage = _eventPackageRepository.GetById(orderDetail.OrderItem.ItemId); packageId = eventPackage.PackageId; } } if (packageId > 0) { orderables.Add(_eventPackageRepository.GetByEventAndPackageIds(eventid, packageId)); selectedTestIds = RemoveTestsAlreadyInPackage(selectedTestIds, eventid, packageId); } if (!selectedTestIds.IsNullOrEmpty()) { var eventTests = _eventTestRepository.GetByEventAndTestIds(eventid, selectedTestIds); if (packageId > 0) { foreach (var eventTest in eventTests) { eventTest.Price = eventTest.WithPackagePrice; } } orderables.AddRange(eventTests); } var indentedLineItemsAdded = false; // TODO: applying hook to the system all the indented line items will be attached to the first order item. foreach (var orderable in orderables) { if (!indentedLineItemsAdded && (orderable.OrderItemType == OrderItemType.EventPackageItem || orderable.OrderItemType == OrderItemType.EventTestItem)) { _orderController.AddItem(orderable, 1, customerid, 1, null, null, null, OrderStatusState.FinalSuccess); indentedLineItemsAdded = true; } else { _orderController.AddItem(orderable, 1, customerid, 1, OrderStatusState.FinalSuccess); } } _orderController.PlaceOrder(order); scope.Complete(); } catch (Exception exception) { _logger.Error("Some Error occured" + exception.Message); } } }
public JsonResult CheckPackageAndTestHafTemplate(long eventId, long customerId, long packageId, IEnumerable <long> testIds) { string message = string.Empty; var currentOrder = _orderRepository.GetOrder(customerId, eventId); var packageOrderItem = currentOrder.OrderDetails.FirstOrDefault(od => od.DetailType == OrderItemType.EventPackageItem && od.IsCompleted); var testOrderItems = currentOrder.OrderDetails.Where(od => od.DetailType == OrderItemType.EventTestItem && od.IsCompleted); var currentEventPackageId = (packageOrderItem != null) ? packageOrderItem.OrderItem.ItemId : 0; long currentPackageId = 0; EventPackage currentEventPackage = null; EventPackage eventPackage = null; if (currentEventPackageId > 0) { currentEventPackage = _eventPackageRepository.GetById(currentEventPackageId); currentPackageId = currentEventPackage.PackageId; } eventPackage = packageId > 0 ? _eventPackageRepository.GetByEventAndPackageIds(eventId, packageId) : currentEventPackage; var eventTests = _eventTestRepository.GetTestsForEvent(eventId); var testPackageName = new List <string>(); if (packageId != currentPackageId) { if (eventPackage != null && eventPackage.HealthAssessmentTemplateId.HasValue) { testPackageName.Add(eventPackage.Package.Name); } } var currentTestIds = new List <long>(); if (currentEventPackage != null) { currentTestIds.AddRange(currentEventPackage.Tests.Select(x => x.TestId)); } if (!testOrderItems.IsNullOrEmpty()) { var orderIds = testOrderItems.Select(x => x.OrderItem.ItemId); var customerTests = eventTests.Where(x => orderIds.Contains(x.Id)); currentTestIds.AddRange(customerTests.Select(x => x.TestId)); } var missingTest = currentTestIds.Where(x => !testIds.Contains(x)); if (!missingTest.IsNullOrEmpty()) { var testNames = eventTests.Where(m => missingTest.Contains(m.TestId) && m.HealthAssessmentTemplateId.HasValue).Select(m => m.Test.Name); if (!testNames.IsNullOrEmpty()) { testPackageName.AddRange(testNames); } } var newTestIds = testIds.Where(x => !currentTestIds.Contains(x)); if (!newTestIds.IsNullOrEmpty()) { var testNames = eventTests.Where(m => newTestIds.Contains(m.TestId) && m.HealthAssessmentTemplateId.HasValue) .Select(m => m.Test.Name); if (!testNames.IsNullOrEmpty()) { testPackageName.AddRange(testNames); } } return(Json(testPackageName, JsonRequestBehavior.AllowGet)); }
public bool RegisterCustomer(MassRegistrationEditModel model, long eventId, EventType eventType) { var createdByOrgRoleUser = Mapper.Map <OrganizationRoleUserModel, OrganizationRoleUser>(_sessionContext.UserSession.CurrentOrganizationRole); if (model.Address != null && string.IsNullOrEmpty(model.Address.StreetAddressLine1) && string.IsNullOrEmpty(model.Address.City) && string.IsNullOrEmpty(model.Address.ZipCode)) { var state = _stateRepository.GetStatebyCode(_settings.State) ?? _stateRepository.GetState(_settings.State); model.Address.StreetAddressLine1 = _settings.Address1; model.Address.StreetAddressLine2 = _settings.Address2; model.Address.City = _settings.City; model.Address.StateId = state != null ? state.Id : model.Address.StateId; model.Address.ZipCode = _settings.ZipCode; } var customer = _massRegistrationEditModelFactory.CreateCustomer(model, createdByOrgRoleUser); _customerService.SaveCustomer(customer, createdByOrgRoleUser.Id); var forOrgRoleUser = _orgRoleUserRepository.GetOrganizationRoleUser(customer.CustomerId); var orderables = new List <IOrderable>(); if (model.PackageId > 0) { orderables.Add(_eventPackageRepository.GetByEventAndPackageIds(eventId, model.PackageId)); } if (orderables.IsNullOrEmpty()) { return(false); } var screeningTime = _eventPackageSelectorService.GetScreeningTime(eventId, model.PackageId, null); var slots = _eventSchedulingSlotService.BookSlotTemporarily(model.AppointmentId, screeningTime, model.PackageId, null); if (slots.IsNullOrEmpty()) { throw new InvalidOperationException("Slot is booked by some other customer."); } var eventCustomer = SaveEventCustomer(createdByOrgRoleUser, model.AppointmentId, eventId, customer.CustomerId); ShippingDetail shippingDetail = null; if (model.AddFreeShipping) { var shippingAddress = Mapper.Map <AddressEditModel, Address>(model.Address); shippingDetail = SaveShippingDetail(shippingAddress, createdByOrgRoleUser); } PlaceOrder(forOrgRoleUser, createdByOrgRoleUser, orderables, eventCustomer, null, shippingDetail); if (model.SendNotification) { var eventData = _eventRepository.GetById(eventId); SendNotification(customer, eventData, createdByOrgRoleUser, "/Scheduling/MassRegistration/Create"); } try { _eventSchedulingSlotService.SendEventFillingNotification(eventId, createdByOrgRoleUser.Id); } catch (Exception) { } return(true); }
public void ChangePackage(CustomerOrderDetail customerOrderDetail) { using (var scope = new TransactionScope()) { if (customerOrderDetail.PaymentModel != null) { try { _customerPaymentService.ProcessPayment(customerOrderDetail.PaymentModel); } catch (Exception exception) { throw new Exception(exception.Message, exception); } } try { var eventid = customerOrderDetail.EventId; var customerid = customerOrderDetail.CustomerId; //var eventCustomer = _eventCustomerRepository.Get(eventid, customerid); var order = GetOrder(customerid, eventid); SourceCode sourceCode = null; if (customerOrderDetail.SourceCode != null) { sourceCode = new SourceCode { Id = customerOrderDetail.SourceCode.SourceCodeId, CouponCode = customerOrderDetail.SourceCode.SourceCode, CouponValue = customerOrderDetail.SourceCode.DiscountApplied } } ; IOrderController orderController = new OrderController(); var orderDetail = orderController.GetActiveOrderDetail(order); if (order == null || order.OrderDetails.IsEmpty()) { return; } ShippingDetail shippingDetails = null; if (customerOrderDetail.IsShippingPurchased && customerOrderDetail.ShippingOptions != null && customerOrderDetail.ShippingOptions.Any()) { shippingDetails = _patientShippingDetailFactory.GetShippingDetailData(customerOrderDetail); } var orderables = new List <IOrderable>(); var selectedTestIds = new List <long>(); if (customerOrderDetail.AlaCarteTests != null && customerOrderDetail.AlaCarteTests.Any()) { selectedTestIds = customerOrderDetail.AlaCarteTests.Select(x => x.TestId).ToList(); } long packageId = 0; if (customerOrderDetail.PackageModel != null && customerOrderDetail.PackageModel.PackageId > 0) { packageId = customerOrderDetail.PackageModel.PackageId; orderables.Add(_eventPackageRepository.GetByEventAndPackageIds(eventid, packageId)); selectedTestIds = RemoveTestsAlreadyInPackage(selectedTestIds, eventid, packageId); } if (!selectedTestIds.IsNullOrEmpty()) { var eventTests = _eventTestRepository.GetByEventAndTestIds(eventid, selectedTestIds); if (packageId > 0) { foreach (var eventTest in eventTests) { eventTest.Price = eventTest.WithPackagePrice; } } orderables.AddRange(eventTests); } ElectronicProduct product = null; if (customerOrderDetail.ProductId.HasValue && customerOrderDetail.ProductId.Value > 0) { var productIsAlreadyPurchased = order.OrderDetails.Any( x => x.DetailType == OrderItemType.ProductItem && x.OrderItem.ItemId == customerOrderDetail.ProductId.Value); if (!productIsAlreadyPurchased) { product = _electronicProductRepository.GetById(customerOrderDetail.ProductId.Value); orderables.Add(product); } } if (customerOrderDetail.IsShippingPurchased && shippingDetails != null) { IShippingController shippingController = new ShippingController(); var shippingDetail = shippingController.OrderShipping(shippingDetails); var shippingDetailOrderDetail = new ShippingDetailOrderDetail { Amount = shippingDetail.ActualPrice, IsActive = true, OrderDetailId = orderDetail.Id, ShippingDetailId = shippingDetail.Id }; _shippingDetailOrderDetailRepository.Save(shippingDetailOrderDetail); } var indentedLineItemsAdded = false; // TODO: applying hook to the system all the indented line items will be attached to the first order item. foreach (var orderable in orderables) { if (!indentedLineItemsAdded && (orderable.OrderItemType == OrderItemType.EventPackageItem || orderable.OrderItemType == OrderItemType.EventTestItem)) { _orderController.AddItem(orderable, 1, customerid, _creatorOrganizationRoleUser, sourceCode, null, null, OrderStatusState.FinalSuccess); indentedLineItemsAdded = true; } else { _orderController.AddItem(orderable, 1, customerid, _creatorOrganizationRoleUser, OrderStatusState.FinalSuccess); } } _orderController.PlaceOrder(order); if (shippingDetails != null) { SaveProductShippingDetail(product, orderDetail, shippingDetails); } scope.Complete(); } catch (Exception exception) { if (customerOrderDetail.PaymentModel == null) { throw new Exception("An Exception caused while saving the Order.", exception); } var paymentInstruments = customerOrderDetail.PaymentModel.Payments; var chargeCardPayment = paymentInstruments.ChargeCard ?? null; if (chargeCardPayment == null || paymentInstruments.Amount <= 0) { throw new Exception("An Exception caused while saving the Order.", exception); } var paymentGateway = IoC.Resolve <IPaymentProcessor>(); paymentGateway.VoidRequestforaPreviousResponse(chargeCardPayment.ChargeCardPayment.ProcessorResponse); throw new Exception("An Exception caused while saving the Order.", exception); } } }