Exemple #1
0
        public async Task <FeeRuleDto> Create(Guid userId, FeeRuleForCreationDto feeRuleForCreationDto)
        {
            var product = await _productRepository.GetById(feeRuleForCreationDto.ProductId);

            if (product == null)
            {
                throw new KeyNotFoundException($"Product with id: {feeRuleForCreationDto.ProductId} not found.");
            }

            var feeRule = new FeeRule()
            {
                ProductId    = feeRuleForCreationDto.ProductId,
                Product      = product,
                Date         = DateTime.Now.ToLocalTime(),
                FeesAmountTo = feeRuleForCreationDto.FeesAmountTo,
                Percentage   = feeRuleForCreationDto.Percentage,
                CreatedBy    = userId
            };

            feeRule = await _feeRuleRepositoryRepository.Add(feeRule);

            await _feeRuleRepositoryRepository.CommitAsync();

            return(_mapper.Map <FeeRule, FeeRuleDto>(feeRule));
        }
Exemple #2
0
        public async Task CreateByCategory(Guid userId, FeeRuleByCategoryDto feeRuleByCategoryDto)
        {
            var category = await _categoryRepository.GetById(feeRuleByCategoryDto.CategoryId);

            if (category == null)
            {
                throw new KeyNotFoundException($"Category with id: {feeRuleByCategoryDto.CategoryId} not found.");
            }
            var products = await _productRepository.Find(x => x.CategoryId == feeRuleByCategoryDto.CategoryId);

            foreach (var prod in products)
            {
                var feeRule = new FeeRule()
                {
                    ProductId    = prod.Id,
                    Product      = prod,
                    Date         = DateTime.Now.ToLocalTime(),
                    FeesAmountTo = feeRuleByCategoryDto.FeesAmountTo,
                    Percentage   = feeRuleByCategoryDto.Percentage,
                    CreatedBy    = userId
                };

                await _feeRuleRepositoryRepository.Add(feeRule);
            }

            await _feeRuleRepositoryRepository.CommitAsync();
        }
Exemple #3
0
        public async Task Update(Guid id, FeeRuleDto feeRuleDto)
        {
            var product = await _productRepository.GetById(feeRuleDto.ProductId);

            if (product == null)
            {
                throw new KeyNotFoundException($"Product with id: {feeRuleDto.ProductId} not found.");
            }

            var feeRule = new FeeRule()
            {
                ProductId    = feeRuleDto.ProductId,
                Product      = product,
                Date         = DateTime.Now.ToLocalTime(),
                FeesAmountTo = feeRuleDto.FeesAmountTo,
                Percentage   = feeRuleDto.Percentage,
                CreatedBy    = feeRuleDto.LastModificationBy.Value
            };

            await _feeRuleRepositoryRepository.Add(feeRule);

            await _feeRuleRepositoryRepository.CommitAsync();
        }
Exemple #4
0
 public Client(string clientCode, FeeRule feeRule)
 {
     ClientCode = clientCode;
     Rule       = feeRule;
     SetFeesByRule();
 }
Exemple #5
0
        public static bool CreateAccountFeeRule(int accountId, int feeCalculationId,
            bool executionOnly, bool sendByPost, int startPeriod, int endPeriod)
        {
            IDalSession session = NHSessionFactory.CreateSession();

            ICustomerAccount account = (ICustomerAccount)AccountMapper.GetAccount(session, accountId);
            IFeeCalc calc = FeeCalcMapper.GetFeeCalculation(session, feeCalculationId);

            FeeRule rule = new FeeRule(calc, null, account, false, executionOnly, false, sendByPost, startPeriod);
            if (endPeriod > 0)
                rule.EndPeriod = endPeriod;
            bool success = FeeRuleMapper.Insert(session, rule);
            session.Close();
            return success;
        }
Exemple #6
0
        public async Task <SaleDto> PreCreation(Guid userId, SaleForCreationDto saletForCreationDto)
        {
            try
            {
                Client client = null;
                if (saletForCreationDto.ClientId.HasValue)
                {
                    client = await _clientRepository.GetById(saletForCreationDto.ClientId.Value);

                    if (client == null)
                    {
                        throw new KeyNotFoundException($"Client with id: {saletForCreationDto.ClientId} not found.");
                    }
                }

                var sale = new Sale()
                {
                    ClientId    = saletForCreationDto.ClientId,
                    Client      = client,
                    ClientName  = client != null ? client.Name + " " + client.Lastname : saletForCreationDto.ClientName,
                    Date        = saletForCreationDto.Date.ToLocalTime(),
                    PaymentType = saletForCreationDto.PaymentType,
                    CreatedBy   = userId
                };

                decimal total = 0;
                foreach (var detailFC in saletForCreationDto.Details)
                {
                    var product = await _productRepository.GetById(detailFC.ProductId);

                    if (product == null)
                    {
                        throw new KeyNotFoundException($"Product with id: {detailFC.ProductId} not found.");
                    }

                    var price = (await _priceRepository.GetAll())
                                .OrderByDescending(x => x.DateTime)
                                .FirstOrDefault(
                        x => x.ProductId == detailFC.ProductId &&
                        x.DateTime.ToLocalTime() <= saletForCreationDto.Date.ToLocalTime() &&
                        x.PriceType == ePriceTypes.SalePrice &&
                        !x.IsDeleted
                        );

                    FeeRule feeRule = null;
                    if (sale.PaymentType == ePaymentTypes.OwnFees)
                    {
                        feeRule = (await _feeRuleRepository.Find(x => x.ProductId == detailFC.ProductId))
                                  .OrderByDescending(x => x.Date).ThenBy(x => x.FeesAmountTo)
                                  .FirstOrDefault(x => x.Date <= sale.Date && x.FeesAmountTo >= saletForCreationDto.OwnFees.Quantity);
                        if (feeRule == null)
                        {
                            throw new KeyNotFoundException($"Fee Rule not found.");
                        }

                        decimal percentage = feeRule.Percentage * saletForCreationDto.OwnFees.Quantity / 100;
                        total += price.Value * detailFC.Quantity * (1 + percentage);
                    }
                    else
                    {
                        total += price.Value * detailFC.Quantity;
                    }

                    var detail = new Detail()
                    {
                        SaleId    = sale.Id,
                        ProductId = detailFC.ProductId,
                        Product   = product,
                        Quantity  = detailFC.Quantity,
                        UnitPrice = price.Value,
                        FeeRuleId = feeRule?.Id,
                        CreatedBy = userId
                    };

                    sale.Details.Add(detail);
                }

                Payment payment = null;
                switch (saletForCreationDto.PaymentType)
                {
                case Util.Enums.ePaymentTypes.Cash:
                    var cashDto = (CashForCreationDto)saletForCreationDto.Cash;
                    payment = new Cash(total, cashDto.Discount)
                    {
                        SaleId    = sale.Id,
                        CreatedBy = userId
                    };
                    break;

                case Util.Enums.ePaymentTypes.OwnFees:
                    var ownFeesDto = (OwnFeesForCreationDto)saletForCreationDto.OwnFees;
                    payment = new OwnFees(ownFeesDto.ExpirationDate, total, ownFeesDto.Quantity, userId)
                    {
                        SaleId = sale.Id,
                    };
                    break;

                case Util.Enums.ePaymentTypes.CreditCard:
                    var creditCardDto = (CreditCardForCreationDto)saletForCreationDto.CreditCard;
                    payment = new CreditCard(total, creditCardDto.Discount, creditCardDto.Surcharge)
                    {
                        SaleId    = sale.Id,
                        CardType  = creditCardDto.CardType,
                        Bank      = creditCardDto.Bank,
                        CreatedBy = userId
                    };
                    break;

                case Util.Enums.ePaymentTypes.DebitCard:
                    var debitCardDto = (DebitCardForCreationDto)saletForCreationDto.DebitCard;
                    payment = new DebitCard(total, debitCardDto.Discount, debitCardDto.Surcharge)
                    {
                        SaleId    = sale.Id,
                        CardType  = debitCardDto.CardType,
                        Bank      = debitCardDto.Bank,
                        CreatedBy = userId
                    };
                    break;

                case Util.Enums.ePaymentTypes.Cheques:
                    var chequesDto = (ChequesPaymentForCreationDto)saletForCreationDto.Cheques;

                    if (chequesDto.ListOfCheques.Sum(x => x.Value) != total)
                    {
                        throw new InvalidOperationException("The sum of cheques list is different of amount.");
                    }

                    payment = new ChequesPayment()
                    {
                        SaleId    = sale.Id,
                        Amount    = Math.Ceiling(total * 100) / 100,
                        CreatedBy = userId
                    };

                    foreach (var c in chequesDto.ListOfCheques)
                    {
                        var cheque = new Cheque()
                        {
                            ChequesPaymentId = payment.Id,
                            Bank             = c.Bank,
                            Nro       = c.Nro,
                            Value     = c.Value,
                            CreatedBy = userId
                        };

                        ((ChequesPayment)payment).ListOfCheques.Add(cheque);
                    }
                    break;

                default:
                    break;
                }

                sale.PaymentId = payment.Id;
                sale.Payment   = payment;

                var saleDto = _mapper.Map <Sale, SaleDto>(sale);

                switch (saleDto.PaymentType)
                {
                case Util.Enums.ePaymentTypes.Cash:
                    saleDto.Cash = _mapper.Map <Cash, CashDto>((Cash)payment);
                    break;

                case Util.Enums.ePaymentTypes.OwnFees:
                    OwnFees owF = (OwnFees)payment;
                    saleDto.OwnFees = _mapper.Map <OwnFees, OwnFeesDto>(owF);
                    break;

                case Util.Enums.ePaymentTypes.CreditCard:
                    saleDto.CreditCard = _mapper.Map <CreditCard, CreditCardDto>((CreditCard)payment);
                    break;

                case Util.Enums.ePaymentTypes.DebitCard:
                    saleDto.DebitCard = _mapper.Map <DebitCard, DebitCardDto>((DebitCard)payment);
                    break;

                case Util.Enums.ePaymentTypes.Cheques:
                    saleDto.Cheques = _mapper.Map <ChequesPayment, ChequesPaymentDto>((ChequesPayment)payment);
                    break;

                default:
                    break;
                }

                return(saleDto);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #7
0
 private void AddClient(string clientCode, FeeRule feeRule)
 {
     Clients.Add(new Client(clientCode, feeRule));
 }
Exemple #8
0
 private void SetFeeRules()
 {
     standartFeeRule = new FeeRule(1, 0, 29);
     SetSpecificFeeRules();
 }