Exemplo n.º 1
0
        public SaleCommission ComputeCommission(Sale sale, SalesPerson salesPerson)
        {
            // TODO: check for null values on extra commission
            decimal commissionRate;
            SaleCommissionType commissionType;
            if (sale.IsDirectSaleOf(salesPerson))
            {
                commissionRate = salesPerson.CommissionRate.Basic;
                commissionType = SaleCommissionType.Basic;
            }
            else
            {
                commissionRate = salesPerson.CommissionRate.Extra ?? 0;
                commissionType = SaleCommissionType.Extra;
            }

            decimal commissionAmount = (decimal)commissionRate * sale.Amount;
            decimal percentage = (decimal)commissionRate * 100;

            return new SaleCommission(
                sale.Id,
                salesPerson.Id,
                sale.Amount,
                commissionAmount,
                (decimal)commissionRate,
                commissionType);
        }
Exemplo n.º 2
0
        public void MakeNewSale(int customerNo, int serviceTypeId, decimal amount, int salesPersonAccountNo)
        {
            Customer customer = this.uow.CustomerRepository.FindByCustomerNo(customerNo);
            if (customer == null)
                throw new ArgumentException("Unable to add Sale on non-existing Customer");

            SalesPerson salesPerson = this.uow.SalesPersonRepository.FindByAccountNo(salesPersonAccountNo);
            if (salesPerson == null)
                throw new ArgumentException("Unable to add Sale on non-existing Sales Person");

            ServiceType serviceType = this.uow
                .ServiceTypeRepository
                .FindById(serviceTypeId);

            if (serviceType == null)
                throw new ArgumentException("Unable to add Sale on non-existing Service Type");

            Sale sale = new Sale(
                Guid.NewGuid(),
                customer.Id,
                serviceType,
                amount,
                salesPerson.Id);

            this.uow.SaleRepository.Add(sale);
            this.uow.Commit();
        }