Example #1
0
        public MoneyTransferOrder(ICashWithdrawalInstruction instruction)
        {
            if (instruction == null)
                throw new ApplicationException(err_def + "the instruction is mandatory");

            ICounterAccount counterAccount = null;
            if (instruction.CounterAccount != null)
                counterAccount = instruction.CounterAccount;
            else if (instruction.Rule != null)
                counterAccount = instruction.Rule.CounterAccount;
            if (counterAccount == null)
                throw new ApplicationException(err_def + "the counter account is mandatory");

            Money amount = null;
            if (instruction.Amount != null)
                amount = instruction.Amount.Abs();

            fillFromInstruction(instruction, counterAccount, amount);

            this.TransferDescription1 = getDescriptionLine(instruction, 1);
            this.TransferDescription2 = getDescriptionLine(instruction, 2);
            this.TransferDescription3 = getDescriptionLine(instruction, 3);
            this.TransferDescription4 = getDescriptionLine(instruction, 4, counterAccount);

            instruction.MoneyTransferOrder = this;
        }
Example #2
0
        private bool placeCashFundOrder(ICashWithdrawalInstruction instruction)
        {
            ITradeableInstrument cashFund = null;
            IFundPosition posCashFund = null;
            Money cashAmount = null;
            bool retVal = false;

            // Get the modelinstruments
            IModelVersion mv = instruction.Account.ModelPortfolio.LatestVersion;
            if (mv == null)
                throw new ApplicationException(string.Format("Not possible to place cash fund orders for account {0}: Latest ModelVersion is null", instruction.Account.DisplayNumberWithName));

            cashFund = mv.GetCashFundOrAlternative();
            if (cashFund != null)
                posCashFund = instruction.Account.Portfolio.PortfolioInstrument.GetPosition(cashFund);

            // Deduct the cash on the account
            ICurrency baseCurrency = instruction.Account.AccountOwner.StichtingDetails.BaseCurrency;
            ICashSubPosition cashPos = instruction.Account.Portfolio.PortfolioCashGL.GetSettledBaseSubPosition();
            if (cashPos != null)
                cashAmount = cashPos.Size;

            if (posCashFund != null && posCashFund.Size.IsGreaterThanZero && Money.Add(posCashFund.CurrentBaseValue + cashAmount, instruction.Amount).IsGreaterThanOrEqualToZero)
            {
                OrderAmountBased order = new OrderAmountBased(instruction.Account, instruction.Amount + cashAmount, cashFund, true, getFeeFactory(FeeFactoryInstanceTypes.Commission), instruction.DoNotChargeCommission, OrderActionTypes.Withdrawal);
                order.Instruction = instruction;
                order.OrderInfo = string.Format("Free up cash for cash withdrawal ({0}) on {1}", instruction.Amount.DisplayString, instruction.WithdrawalDate.ToString("dd-MM-yyyy"));
                IList orders = new ArrayList();
                orders.Add(order);
                instruction.UpdateableOrders = orders;
                instruction.Message = string.Format("Cash Fund order generated to free up cash on {0}", DateTime.Now.ToString());
                retVal = true;
            }
            else
                createRebalanceInstruction(instruction);

            return retVal;
        }
Example #3
0
        private bool createRebalanceInstruction(ICashWithdrawalInstruction instruction)
        {
            bool retVal = false;

            // check -> does the account have a positive amount
            if (Money.Add(instruction.Account.Portfolio.TotalValue(), instruction.Amount).IsLessThanZero)
            {
                instruction.Message = "The account does not have enough buying power to finance this withdrawal.";
                instruction.Warning = true;
            }
            else
            {
                try
                {
                    IRebalanceInstruction rebalance = (IRebalanceInstruction)instruction.Account.CreateInstruction(InstructionTypes.Rebalance, OrderActionTypes.Withdrawal, DateTime.Today, instruction.DoNotChargeCommission);
                    rebalance.CashWithdrawalInstruction = instruction;
                    instruction.Message = "A rebalance instruction was created to free up cash";
                    retVal = true;
                }
                catch (Exception ex)
                {
                    instruction.Message = "It was not possible to create a rebalance instruction to free up cash. " + ex.Message;
                    instruction.Warning = true;
                }
            }
            return retVal;
        }
Example #4
0
        private bool createMoneyTransferOrder(ICashWithdrawalInstruction instruction)
        {
            bool createMoneyOrder = false;
            if (Money.Add(instruction.Account.TotalCash, instruction.Amount).IsGreaterThanOrEqualToZero)
                createMoneyOrder = true;
            else
            {
                switch (instruction.CheckAccountCash(CashWithdrawalInstructionActions.PlaceFreeUpCashFundOrder))
                {
                    case CashWithdrawalInstructionCheckCashReturnValues.PlaceCashFundOrder:
                        instruction.Warning = true;
                        placeCashFundOrder(instruction);
                        createMoneyOrder = true;
                        break;
                    case CashWithdrawalInstructionCheckCashReturnValues.CreateRebalanceInstruction:
                        createRebalanceInstruction(instruction);
                        instruction.Warning = true;
                        instruction.Status = (int)CashWithdrawalInstructionStati.New;
                        break;
                    case CashWithdrawalInstructionCheckCashReturnValues.NotEnoughBuyingPower:
                        instruction.Message = "Not enough buying power to create the Money Transfer order.";
                        instruction.Warning = true;
                        break;
                }
            }

            if (createMoneyOrder)
            {
                IMoneyTransferOrder moneyOrder = new MoneyTransferOrder(instruction);
                string info = "";
                if (instruction.UpdateableOrders != null && instruction.UpdateableOrders.Count > 0)
                    info = " and a Cash Fund order";
                else if (instruction.Account.ActiveRebalanceInstructions.Count > 0)
                {
                    foreach (IInstruction rebInst in instruction.Account.ActiveRebalanceInstructions)
                    {
                        if (rebInst.Key == 0)
                            info = " and a Rebalance Instruction";
                    }
                }
                instruction.Message = string.Format("Money Transfer order{0} created on {1}", info, DateTime.Now.ToString("yyyy-MM-dd hh:mm"));
                instruction.Warning = (info != "");
            }
            return true;
        }
Example #5
0
 private string getDescriptionLine(ICashWithdrawalInstruction instruction, int line, ICounterAccount counterAccount)
 {
     string transferDescription = getDescriptionLine(instruction.TransferDescription, line);
     switch (line)
     {
         case 1:
             return string.Format("{0} onttrekking", instruction.Account.Number);
         case 2:
             if (!string.IsNullOrEmpty(transferDescription))
                 return transferDescription;
             else
                 return string.Format("{0} {1} {2}", (instruction.Rule != null ? instruction.Rule.Regularity.Description : "Eenmalig"), instruction.Amount.Underlying.ToCurrency.Symbol, instruction.Amount.Abs().Quantity.ToString());
         case 3:
             if (!string.IsNullOrEmpty(transferDescription))
                 return transferDescription;
             else
                 return string.Format("Voor {0}", instruction.Account.ShortName);
         case 4:
             if (!string.IsNullOrEmpty(transferDescription))
                 return transferDescription;
             else
             {
                 if (counterAccount.IsPublic)
                     return "Transfer naar derden";
                 else
                     return "Transfer naar eigen rekening";
             }
     }
     return "";
 }
Example #6
0
 private string getDescriptionLine(ICashWithdrawalInstruction instruction, int line)
 {
     return getDescriptionLine(instruction, line, null);
 }