/// <summary> /// Constructor of Commission object /// </summary> /// <param name="detailsToCopy">The object we want to clone from</param> public Commission(Commission detailsToCopy) { if (detailsToCopy == null || detailsToCopy.BreakupLines == null || detailsToCopy.BreakupLines.Count == 0) throw new ApplicationException("It is not possible to clone the commissiondetails when they are null"); foreach (CommissionBreakupLine line in detailsToCopy.BreakupLines) { BreakupLines.Add(new CommissionBreakupLine(line.Amount, line.CommissionType, line.CommissionInfo)); //AddLine(line.CommissionType, line.Amount, line.CommissionInfo); } }
/// <summary> /// This method multiplies an instance of a <see cref="T:B4F.TotalGiro.Fees.Commission">Commission</see> class with a specified number /// </summary> /// <param name="lhs">The instance of the <see cref="T:B4F.TotalGiro.Fees.Commission">Commission</see> class</param> /// <param name="multiplier">The number that is multiplied with</param> /// <returns>The result. A new instance of the <see cref="T:B4F.TotalGiro.Fees.Commission">Commission</see> class</returns> public static Commission Multiply(Commission lhs, decimal multiplier) { Commission commission = null; if (lhs != null && lhs.BreakupLines.Count > 0) { commission = new Commission(); foreach (CommissionBreakupLine line in lhs.BreakupLines) commission.BreakupLines.Add(new CommissionBreakupLine(line.Amount * multiplier, line.CommissionType, line.CommissionInfo)); } //else // throw new ApplicationException("It is not possible to multiply a null value"); return commission; }
/// <summary> /// The method used by <b>Order</b> and <b>Transaction</b> classes to calculate their attached fees. Also, if applicable, /// the service charge is calculated /// </summary> /// <param name="client">The client (order/transaction) for which the fee is calculated.</param> /// <returns>The commission value .</returns> public Commission CalculateCommission(ICommClient client) { Commission cvd = new Commission(); Money fee = null; if (feeFactory.commRuleFinder == null) { throw new ApplicationException("There are no Commission Rules initialised"); } if (client.Account.AccountType != AccountTypes.Customer) return null; ICommRule commRule = feeFactory.commRuleFinder.FindRule(client); ICommCalc commCalculation = null; if (commRule != null) { // Step 01 : Introduction Fee if (commRule.AdditionalCalculation != null) { ICommCalc feeCalc2 = commRule.AdditionalCalculation; client.CommissionInfo = "Additional Fee: " + feeCalc2.Name + ". "; Money fee2 = feeCalc2.Calculate(client); if (fee2 != null) { if (fee2.Sign) fee2 = fee2.Abs() * -1; if (!fee2.Underlying.Equals(client.OrderCurrency)) fee2 = fee2.Convert(client.OrderCurrency); } else fee2 = new Money(0, client.OrderCurrency); client.PreviousCalculatedFee = fee2; cvd.BreakupLines.Add(new CommissionBreakupLine(fee2, CommissionBreakupTypes.AdditionalCommission, client.CommissionInfo)); client.CommissionInfo = ""; } // Step 02 : Commission commCalculation = commRule.CommCalculation; fee = commCalculation.Calculate(client); client.CommissionInfo = "Commission rule: " + commRule.ToString() + ". " + client.CommissionInfo; } else client.CommissionInfo = "No commission rule found."; if (fee != null) { if (fee.Sign) fee = fee.Abs() * -1; if (!fee.Underlying.Equals(client.OrderCurrency)) fee = fee.Convert(client.OrderCurrency); } else fee = new Money(0, client.OrderCurrency); cvd.BreakupLines.Add(new CommissionBreakupLine(fee, CommissionBreakupTypes.Commission, client.CommissionInfo)); return cvd; }