Exemplo n.º 1
0
        private int GetVatPercent(CustomerDTO customer, ServiceProviderDTO serviceProvider)
        {
            if (!serviceProvider.VatPayer)
            {
                return(0);
            }
            if (serviceProvider.VatPayer)
            {
                if (!customer.EuropianUnion)
                {
                    return(0);
                }
                else if (customer.EuropianUnion && !customer.VatPayer && customer.Country != serviceProvider.Country)
                {
                    return(CountriesDataStore.Current.Countries.Single(a => a.Name == customer.Country).Tax);
                }
                else if (customer.EuropianUnion && customer.VatPayer && customer.Country != serviceProvider.Country)
                {
                    return(0);
                }
                else if (customer.EuropianUnion && customer.Country == serviceProvider.Country)
                {
                    return(CountriesDataStore.Current.Countries.Single(a => a.Name == customer.Country).Tax);
                }
            }

            return(0);
        }
Exemplo n.º 2
0
        public void MapInvoiceServiceProviderDto_ServiceProviderDtoPassed_ReturnsInvoiceServiceProviderDto()
        {
            ServiceProviderDTO serviceProvider = new ServiceProviderDTO();

            var actual = Mapper.MapInvoiceServiceProviderDto(serviceProvider);

            actual.ShouldBeOfType <InvoiceServiceProviderDto>();
        }
Exemplo n.º 3
0
 public static InvoiceServiceProviderDto MapInvoiceServiceProviderDto(ServiceProviderDTO serviceProvider)
 {
     return(new InvoiceServiceProviderDto()
     {
         Name = serviceProvider.Name,
         PhoneNumber = serviceProvider.PhoneNumber,
         Email = serviceProvider.Email,
         Address = serviceProvider.Address,
         Country = serviceProvider.Country
     });
 }
Exemplo n.º 4
0
        public async Task <InvoiceDto> GenerateInvoice(InvoiceBuilderParams properties)
        {
            try
            {
                ServiceProviderDTO serviceProvider = ServiceProvidersDataStore.Current.ServiceProviders.Single(a => a.Name == properties.ServiceProviderName);
                CustomerDTO        customer        = CustomersDataStore.Current.Customers.Single(a => a.Name == properties.CustomerName);

                if (serviceProvider != null && customer != null)
                {
                    List <ServiceDto> services = new List <ServiceDto>();
                    foreach (var service in properties.Services)
                    {
                        services.Add(ServicesDataStore.Current.Services.Single(a => a.Name == service && a.ServiceProvider == serviceProvider.Name));
                    }

                    if (services.Count > 0)
                    {
                        InvoiceDto invoice = new InvoiceDto();

                        invoice.InvoiceId       = RandomString(16);
                        invoice.InvoiceDate     = DateTime.Now;
                        invoice.Customer        = Mapper.MapInvoiceCustomerDto(customer);
                        invoice.ServiceProvider = Mapper.MapInvoiceServiceProviderDto(serviceProvider);
                        invoice.Services        = services;
                        invoice.SubTotalPrice   = CalculateAmount(invoice.Services);
                        invoice.Discount        = 0;
                        invoice.VatPercent      = GetVatPercent(customer, serviceProvider);
                        invoice.VatTax          = CalculateVatTax(invoice);
                        invoice.TotalAmount     = CalculateTotalAmount(invoice);

                        return(invoice);
                    }
                }

                return(null);
            }

            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(null);
            }
        }
        public Response <ServiceProviderDTO> ServiceProviderRegistration(ServiceProviderRegistrationDTO dto)
        {
            var response = new Response <ServiceProviderDTO>();

            try
            {
                User user = new User();
                user.Name         = dto.Name;
                user.UserName     = dto.UserName;
                user.Email        = dto.Email;
                user.Password     = Helper.Encrypt(dto.Password);
                user.Birthdate    = dto.Birthday;
                user.Phone_Number = dto.PhoneNumber;
                user.RoleId       = 2;
                user.DateCreated  = DateTime.UtcNow.ToString();
                user.Address      = dto.Address;
                if (_userRepository.ListQuery(a => a.DateDeleted == null && !string.IsNullOrEmpty(a.Email) && !string.IsNullOrEmpty(user.Email) && a.Email.ToLower() == user.Email.ToLower()).Any())
                {
                    response.AddValidationError("", "Email is already exist!");
                    return(response);
                }
                if (_userRepository.ListQuery(a => a.DateDeleted == null && !string.IsNullOrEmpty(a.UserName) && !string.IsNullOrEmpty(user.UserName) && a.UserName.ToLower() == user.UserName.ToLower()).Any())
                {
                    response.AddValidationError("", "UserName is already exist!");
                    return(response);
                }
                var customerCreateOptions = new CustomerCreateOptions();

                //Create Stripe Customer Accout

                customerCreateOptions.Email   = user.Email;
                customerCreateOptions.Name    = user.Name;
                customerCreateOptions.Address = new AddressOptions
                {
                    City       = user.Address.City,
                    State      = user.Address.State,
                    Country    = user.Address.Country,
                    PostalCode = user.Address.PostalCode,
                    Line1      = user.Address.Line1,
                    Line2      = user.Address.Line2
                };

                var customer = _baseServices.CreateStripCustomerAccount(customerCreateOptions);
                user.Stripe_CustomerId = customer.Id;

                _userRepository.Insert(user);
                var token = generateJwtToken(user);
                _userSessionService.Create(new UserSession
                {
                    AccessToken = token,
                    UserId      = user.Id
                });

                var userResponse = _userRepository.GetbyidwithInclude(a => a.Id == user.Id && a.DateDeleted == null, "Roles,Address");

                ServiceProviderDTO registrationResponse = new ServiceProviderDTO();
                registrationResponse.Id           = userResponse.Id;
                registrationResponse.Name         = userResponse.Name;
                registrationResponse.JwtToken     = token;
                registrationResponse.Role         = userResponse.Roles?.Name;
                registrationResponse.RoleId       = userResponse.RoleId;
                registrationResponse.Customer_id  = userResponse.Stripe_CustomerId;
                registrationResponse.UserName     = userResponse.UserName;
                registrationResponse.Email        = userResponse.Email;
                registrationResponse.Phone_Number = userResponse.Phone_Number;
                response.Data    = registrationResponse;
                response.Success = true;
            }
            catch (Exception ex)
            {
                HandleException(response, ex);
            }
            return(response);
        }