/// <summary>
        /// Создать и открыть объект fmCPRRepaymentTask в модальном окне
        /// </summary>
        private void ManualBinding_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            fmCSAStatementAccountDoc current = e.CurrentObject as fmCSAStatementAccountDoc;

            if (current == null)
            {
                return;
            }

            //fmCPRRepaymentTask RT = ObjectSpace.CreateObject<fmCPRRepaymentTask>();
            //IObjectSpace objectSpace = ObjectSpace.CreateNestedObjectSpace();   // Frame.Application.CreateObjectSpace();
            IObjectSpace objectSpace = Application.CreateObjectSpace();

            // Create object
            //fmCPRRepaymentTask nestedRT = objectSpace.GetObject<fmCPRRepaymentTask>(RT);
            fmCPRRepaymentTask nestedRT = objectSpace.CreateObject <fmCPRRepaymentTask>();

            if (current.StatementAccountIn != null)
            {
                nestedRT.BankAccount = objectSpace.GetObject <crmBankAccount>(current.StatementAccountIn.BankAccount);
            }
            else if (current.StatementAccountOut.BankAccount != null)
            {
                nestedRT.BankAccount = objectSpace.GetObject <crmBankAccount>(current.StatementAccountOut.BankAccount);
            }
            nestedRT.PaymentDocument = objectSpace.GetObject <fmCDocRCB>(current.PaymentDocument);
            nestedRT.FillRepaymentTaskLines();
            nestedRT.FillRequestList();

            // Show object
            string DetailViewId = Frame.Application.FindDetailViewId(nestedRT.GetType());

            //BaseObject passedObj = nestedRT;   // objectSpace.GetObject<BaseObject>(rt);

            TargetWindow       openMode = TargetWindow.NewModalWindow;
            DetailView         dv       = Frame.Application.CreateDetailView(objectSpace, DetailViewId, true, nestedRT);
            ShowViewParameters svp      = new ShowViewParameters()
            {
                CreatedView = dv, TargetWindow = openMode, Context = TemplateContext.View, CreateAllControllers = true
            };

            e.ShowViewParameters.Assign(svp);
        }
        private void CreateCFRegisterRecord(Session ssn, ForCashFlowRecord cashFlowRecord)     //, crmCParty ourParty) {
        {
            crmCashFlowRegister cfr = new crmCashFlowRegister(ssn);

            fmCPRRepaymentTask  repaymentTask  = cashFlowRecord.repaymentTask;
            fmCDocRCB           paymentDoc     = cashFlowRecord.paymentDoc;
            fmCPRPaymentRequest paymentRequest = cashFlowRecord.paymentRequest;

            Guid token = paymentRequest.Oid;

            cfr.Token   = token;
            cfr.Section = CashFlowRegisterSection.REPAYMENT_JOURNAL;

            cfr.SourceGUID = repaymentTask.Oid;   // Будет пустой GUID
            cfr.SourceType = repaymentTask.GetType();

            cfr.PaymentDocument = paymentDoc;
            cfr.BankAccount     = repaymentTask.BankAccount;
            cfr.Bank            = repaymentTask.BankAccount.Bank;
            cfr.OperationDate   = cashFlowRecord.date;

            fmCPRPaymentRequestContract paymentRequestContract = paymentRequest as fmCPRPaymentRequestContract;

            //if (paymentRequestContract != null && paymentRequestContract.ContractDeal != null) {
            //    cfr.Contract = paymentRequestContract.ContractDeal.Contract;
            //}
            if (paymentRequestContract != null)
            {
                cfr.Contract     = paymentRequestContract.Contract;
                cfr.ContractDeal = paymentRequestContract.ContractDeal;
            }

            cfr.fmOrder  = cashFlowRecord.paymentRequestObligation.Order;
            cfr.CostItem = cashFlowRecord.paymentRequestObligation.CostItem;
            cfr.Subject  = (cashFlowRecord.paymentRequestObligation.Order != null) ? cashFlowRecord.paymentRequestObligation.Order.Subject : null;

            cfr.PrimaryParty    = paymentRequest.PartyPaySender;
            cfr.ContragentParty = paymentRequest.PartyPayReceiver;

            //cfr.ObligationUnit =
            //cfr.PaymentItem =

            cfr.ValutaPayment    = paymentDoc.GetAccountValuta();
            cfr.ValutaObligation = cashFlowRecord.paymentRequestObligation.Valuta;

            // В валюте платежа
            //cfr.SumIn = this.PaymentDocument.GetSumIn(this.BankAccount);
            //cfr.SumOut = this.PaymentDocument.GetSumOut(this.BankAccount);

            /*
             * if (paymentDoc.PaymentReceiverRequisites.INN == ourParty.INN) {   // && this.PaymentDocument.PaymentReceiverRequisites.StatementOfAccount.BankAccount == this.BankAccount) {
             *  cfr.SumIn = paymentDoc.PaymentCost;
             * }
             * if (paymentDoc.PaymentPayerRequisites.INN == ourParty.INN) {   // && this.PaymentDocument.PaymentPayerRequisites.StatementOfAccount.BankAccount == this.BankAccount) {
             *  cfr.SumOut = paymentDoc.PaymentCost;
             * }
             */
            if (paymentDoc.PaymentReceiverRequisites.BankAccount == cashFlowRecord.repaymentJournalRecord.BankAccount)     // && this.PaymentDocument.PaymentReceiverRequisites.StatementOfAccount.BankAccount == this.BankAccount) {
            //cfr.SumIn = cashFlowRecord.repaymentJournalRecord.SumIn;
            {
                cfr.SumIn = cashFlowRecord.sum;
            }
            if (paymentDoc.PaymentPayerRequisites.BankAccount == cashFlowRecord.repaymentJournalRecord.BankAccount)     // && this.PaymentDocument.PaymentPayerRequisites.StatementOfAccount.BankAccount == this.BankAccount) {
            //cfr.SumOut = cashFlowRecord.repaymentJournalRecord.SumOut;
            {
                cfr.SumOut = cashFlowRecord.sum;
            }



            // В валюте обязательств

            /*
             * if (paymentDoc.PaymentReceiverRequisites.INN == ourParty.INN) {   // && this.PaymentDocument.PaymentReceiverRequisites.StatementOfAccount.BankAccount == this.BankAccount) {
             *  cfr.SumObligationIn = cashFlowRecord.sum;
             * }
             * if (paymentDoc.PaymentPayerRequisites.INN == ourParty.INN) {   // && this.PaymentDocument.PaymentPayerRequisites.StatementOfAccount.BankAccount == this.BankAccount) {
             *  cfr.SumObligationOut = cashFlowRecord.sum;
             * }
             */
            if (paymentDoc.PaymentReceiverRequisites.BankAccount == cashFlowRecord.repaymentJournalRecord.BankAccount)     // && this.PaymentDocument.PaymentReceiverRequisites.StatementOfAccount.BankAccount == this.BankAccount) {
            //cfr.SumObligationIn = cashFlowRecord.sum;
            {
                cfr.SumObligationIn = Math.Round(cfr.SumIn * csCNMValutaCourse.GetCrossCourceOnDate(ssn, paymentDoc.GetAccountDateChange(), cfr.ValutaPayment, cfr.ValutaObligation), 4);
            }
            if (paymentDoc.PaymentPayerRequisites.BankAccount == cashFlowRecord.repaymentJournalRecord.BankAccount)     // && this.PaymentDocument.PaymentPayerRequisites.StatementOfAccount.BankAccount == this.BankAccount) {
            //cfr.SumObligationOut = cashFlowRecord.sum;
            {
                cfr.SumObligationOut = Math.Round(cfr.SumOut * csCNMValutaCourse.GetCrossCourceOnDate(ssn, paymentDoc.GetAccountDateChange(), cfr.ValutaPayment, cfr.ValutaObligation), 4);
            }

            // В рублях
            try {
                cfr.SumInAcc  = Math.Round(cfr.SumIn * csCNMValutaCourse.GetCrossCourceOnDate(ssn, paymentDoc.GetAccountDateChange(), cfr.ValutaPayment, GetValutaByCode(ssn, "RUB")), 4);
                cfr.SumOutAcc = Math.Round(cfr.SumOut * csCNMValutaCourse.GetCrossCourceOnDate(ssn, paymentDoc.GetAccountDateChange(), cfr.ValutaPayment, GetValutaByCode(ssn, "RUB")), 4);
            }
            catch {
            }

            cfr.PaymentRequestObligationGUID = cashFlowRecord.paymentRequestObligationGUID;

            //if (this.PaymentReceiverRequisites.INN == OurParty.INN && this.PaymentReceiverRequisites.StatementOfAccount.BankAccount == bankAccount) {
            //    Res = this.PaymentCost;
            //}
        }