Exemple #1
0
        public void CalculatePricefor(Asset asset, decimal price, string location, CommissionCalculator commissionCalculator)
        {
            var commission  = commissionCalculator.GetCommission();
            var totalAmount = commissionCalculator.CalculateCommission(asset, price);

            Console.WriteLine("Asset type: {0}, final price: {1}, commission: {2}%, location/number: {3}\n", asset.GetType().Name, totalAmount, commission, location);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            IFrontDesk frontDesk            = new FrontDesk();
            var        commissionCalculator = new CommissionCalculator();

            Console.WriteLine("Select asset type: \n" +
                              "1. House; \n" +
                              "2. Apartment; \n" +
                              "3. Single Room; \n" +
                              "4. Urban Plot. \n");

            var assetType = Console.ReadLine();

            IAsset asset;

            switch (assetType)
            {
            case "1":
                asset = new House();
                Console.WriteLine("Insert the address of the House: ");
                asset.SetAssetAttribute(Console.ReadLine());
                Console.WriteLine("\nInsert the desired price: ");
                asset.Price = Convert.ToDecimal(Console.ReadLine());
                frontDesk.CalculateSellingPrice(asset, commissionCalculator);
                break;

            case "2":
                asset = new Apartment();
                Console.WriteLine("Insert the address of the Apartment: ");
                asset.SetAssetAttribute(Console.ReadLine());
                Console.WriteLine("\nInsert the desired price: ");
                asset.Price = Convert.ToDecimal(Console.ReadLine());
                frontDesk.CalculateSellingPrice(asset, commissionCalculator);
                break;

            case "3":
                asset = new SingleRoom();
                Console.WriteLine("Insert the address of the Single Room: ");
                asset.SetAssetAttribute(Console.ReadLine());
                Console.WriteLine("\nInsert the desired price: ");
                asset.Price = Convert.ToDecimal(Console.ReadLine());
                frontDesk.CalculateSellingPrice(asset, commissionCalculator);
                break;

            case "4":
                asset = new UrbanPlot();
                Console.WriteLine("Insert the Cadastral Reference of the Urban Plot: ");
                asset.SetAssetAttribute(Console.ReadLine());
                Console.WriteLine("\nInsert the desired price: ");
                asset.Price = Convert.ToDecimal(Console.ReadLine());
                frontDesk.CalculateSellingPrice(asset, commissionCalculator);
                break;

            default:
                break;
            }
        }
		} // GenerateAgreementModel

		private void GetSetupFees(
			Customer customer,
			Loan loan,
			out decimal manualSetupFeePct,
			out decimal brokerSetupFeePct
		) {
			if (loan.LoanLegalId != null) {
				var loanLegal = this.loanLegalRepo.GetAll().FirstOrDefault(ll => ll.Id == loan.LoanLegalId.Value);

				if (loanLegal != null) {
					manualSetupFeePct = loanLegal.ManualSetupFeePercent ?? 0;
					brokerSetupFeePct = loanLegal.BrokerSetupFeePercent ?? 0;
					return;
				} // if
			} // if

			manualSetupFeePct = loan.CashRequest.ManualSetupFeePercent ?? 0;
			brokerSetupFeePct = loan.CashRequest.BrokerSetupFeePercent ?? 0;

			decimal approvedAmount =
				(decimal)(loan.CashRequest.ManagerApprovedSum ?? loan.CashRequest.SystemCalculatedSum ?? 0);

			if ((customer.Broker != null) && (approvedAmount != loan.LoanAmount)) {
				this.log.Debug(
					"GetSetupFees: broker customer '{0}', broker fee in cash request with approved amount {1} is {2}.",
					customer.Stringify(),
					approvedAmount.ToString("C2"),
					brokerSetupFeePct.ToString("P2")
				);

				Loan firstLoan = customer.Loans.OrderBy(l => l.Date).FirstOrDefault();

				brokerSetupFeePct = new CommissionCalculator(
					loan.LoanAmount,
					firstLoan == null ? (DateTime?)null : firstLoan.Date
				)
					.Calculate()
					.BrokerCommission;

				this.log.Debug(
					"CreateNewLoan: broker customer '{0}', broker fee adjusted to loan amount {1} is {2}.",
					customer.Stringify(),
					loan.LoanAmount.ToString("C2"),
					brokerSetupFeePct.ToString("P2")
				);
			} // if broker customer
		} // GetSetupFees
        }         // Name

        public override void Execute()
        {
            Log.Debug(
                "Looking for default commissions for cash request {0} with loan amount {1}.",
                this.cashRequestID,
                this.loanAmount.ToString("C2", Library.Instance.Culture)
                );

            SafeReader sr = DB.GetFirst(
                "GetCashRequestForLoanCommissionDefaults",
                CommandSpecies.StoredProcedure,
                new QueryParameter("CashRequestID", this.cashRequestID)
                );

            if (sr.IsEmpty)
            {
                Result = new DefaultCommissions(0, 0);
                Log.Debug("No cash request found by id {0}, result is {1}.", this.cashRequestID, Result);
                return;
            }             // if

            IsBrokerCustomer = sr["IsBrokerCustomer"];

            Result = new DefaultCommissions(sr["BrokerSetupFeePercent"], sr["ManualSetupFeePercent"]);

            if (!IsBrokerCustomer)
            {
                Log.Debug("Cash request {0} belongs to a non-broker customer, result is {1}.", this.cashRequestID, Result);
                return;
            }             // if

            DateTime?firstLoanDate = sr["FirstLoanDate"];

            Result = new CommissionCalculator(this.loanAmount, firstLoanDate).Calculate();

            Log.Debug(
                "Cash request {0} belongs to a customer with {1}, result is {2}.",
                this.cashRequestID,
                firstLoanDate.HasValue
                                        ? "first loan taken on " + firstLoanDate.Value.ToString("d/MMM/yyyy", Library.Instance.Culture)
                                        : "no loans taken",
                Result
                );
        }         // Execute
        async Task IAccountService.TransferMoneyAsync(long senderAccountId, long recepeintAccountId, decimal transferAmount)
        {
            using (var transactionScope = await UnitOfWork.BeginTransactionAsync(System.Data.IsolationLevel.Serializable))
            {
                var senderAccount = await AccountRepository.GetItemAsync(senderAccountId);

                if (senderAccount == null)
                {
                    throw new System.Exception();
                }

                if (senderAccount.Money < transferAmount)
                {
                    throw new System.Exception();
                }

                var recepientAccount = await AccountRepository.GetItemAsync(recepeintAccountId);

                if (recepientAccount == null)
                {
                    throw new System.Exception();
                }

                var totalCommission = await CommissionCalculator.CalculateCommissionAsync(senderAccount, recepientAccount, transferAmount);

                await AccountRepository.UpdateAsync(x => new Models.Account {
                    Money = senderAccount.Money - transferAmount - totalCommission
                }, x => x.Id == senderAccountId);

                await AccountRepository.UpdateAsync(x => new Models.Account {
                    Money = recepientAccount.Money + transferAmount
                }, x => x.Id == recepeintAccountId);

                await CommonPostProcessor.ExecuteAccountTypeProcess(senderAccount.AccountTypeId);

                await CommonPostProcessor.ExecuteBankProcess(senderAccount.BankId);

                await UnitOfWork.SaveChangesAsync();

                transactionScope.Commit();
            }
        }
Exemple #6
0
    static void Main()
    {
        CommissionCalculator commissionCalculator = new CommissionCalculator();


        int soldItemCounter = 1;

        decimal total = 0;

        double commission = 0.09;

        decimal wage = 200;


        while (true)
        {
            Console.Write($"Please enter the value of sold item {soldItemCounter} or -1 to quit: ");
            decimal commissionCalculatortheSoldItem = decimal.Parse(Console.ReadLine());
            commissionCalculator.SetSoldItem(commissionCalculatortheSoldItem);


            ++soldItemCounter;

            total = (decimal)(commissionCalculator.GetSoldItem() + total);

            decimal totalToPay = total * (decimal)commission + wage;


            if (commissionCalculatortheSoldItem == -1)
            {
                Console.WriteLine($"\nThe total value of the sold item(s) is: {total}");
                Console.WriteLine($"\nThe weekly salary with commission is: {totalToPay}\n");
                break;
            }
        }

        Console.WriteLine("\nThank you and see you soon!");
    }
Exemple #7
0
		} // CreateNewLoan

		public BuiltLoan BuildLoan(CashRequest cr, decimal amount, DateTime now, int term, int interestOnlyTerm = 0) {
			decimal setupFeePct = cr.ManualSetupFeePercent ?? 0;
			decimal brokerFeePct = cr.BrokerSetupFeePercent ?? 0;

			decimal approvedAmount = (decimal)(cr.ManagerApprovedSum ?? cr.SystemCalculatedSum ?? 0);

			if ((cr.Customer.Broker != null) && (approvedAmount != amount)) {
				log.Debug(
					"CreateNewLoan: broker customer '{0}', broker fee in cash request with approved amount {1} is {2}.",
					cr.Customer.Stringify(),
					approvedAmount.ToString("C2"),
					brokerFeePct.ToString("P2")
				);

				Loan firstLoan = cr.Customer.Loans.OrderBy(l => l.Date).FirstOrDefault();

				brokerFeePct = new CommissionCalculator(amount, firstLoan == null ? (DateTime?)null : firstLoan.Date)
					.Calculate()
					.BrokerCommission;

				log.Debug(
					"CreateNewLoan: broker customer '{0}', broker fee adjusted to loan amount {1} is {2}.",
					cr.Customer.Stringify(),
					amount.ToString("C2"),
					brokerFeePct.ToString("P2")
				);
			} // if broker customer

			var fees = new SetupFeeCalculator(setupFeePct, brokerFeePct).Calculate(amount);

			decimal setupFee = fees.Total;
			decimal brokerFee = fees.Broker;

			var calculator = new LoanScheduleCalculator { Interest = cr.InterestRate, Term = term };

			LoanLegal loanLegal = cr.LoanLegals.LastOrDefault();

			var loan = new Loan {
				LoanAmount = amount,
				Date = now,
				LoanType = cr.LoanType,
				CashRequest = cr,
				SetupFee = setupFee,
				LoanLegalId = loanLegal == null ? (int?)null : loanLegal.Id
			};

			calculator.Calculate(amount, loan, loan.Date, interestOnlyTerm, cr.SpreadSetupFee());

			loan.LoanSource = cr.LoanSource;

			if (brokerFee > 0 && cr.Customer.Broker != null) {
				loan.BrokerCommissions.Add(new LoanBrokerCommission {
					Broker = cr.Customer.Broker,
					CardInfo = cr.Customer.Broker.BankAccounts.FirstOrDefault(
						x => x.IsDefault.HasValue && x.IsDefault.Value
					),
					CommissionAmount = brokerFee,
					CreateDate = now,
					Loan = loan,
				});
			} // if broker fee & broker

			return new BuiltLoan {
				Loan = loan,
				BrokerFeePercent = brokerFeePct,
				ManualSetupFeePercent = setupFeePct,
			};
		} // BuildLoan