コード例 #1
0
        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;
            //}
        }
コード例 #2
0
        public static fmCPRPaymentRequest CreateRequest(IObjectSpace workOS, fmCPRRepaymentTask repaymentTask, Type objType, FinRequestKind requestKind)
        {
            if (repaymentTask == null)
            {
                return(null);
            }

            fmCPRPaymentRequest req = workOS.CreateObject(objType) as fmCPRPaymentRequest;

            if (req != null)
            {
                req.State = PaymentRequestStates.OPEN;
                //req.ExtDocDate = DateTime.Now;
                req.Date = DateTime.Now;
                if (repaymentTask.PaymentDocument != null)
                {
                    fmCDocRCB doc  = repaymentTask.PaymentDocument;
                    fmCDocRCB nDoc = workOS.GetObject <fmCDocRCB>(doc);
                    if (nDoc.PaymentPayerRequisites != null)
                    {
                        req.PartyPaySender = nDoc.PaymentPayerRequisites.Party;
                    }
                    if (nDoc.PaymentReceiverRequisites != null)
                    {
                        req.PartyPayReceiver = nDoc.PaymentReceiverRequisites.Party;
                    }
                    //                    req.Number = nDoc.DocNumber;
                    req.ExtDocNumber = nDoc.DocNumber;
                    req.ExtDocDate   = nDoc.DocDate;
                    //                    req.Date = DateTime.Now;
                    req.Summ          = nDoc.PaymentCost; // По умолчанию указывваем полную сумму платёжного документа
                    req.PayDate       = nDoc.GetAccountDateChange();
                    req.PaymentValuta = nDoc.GetAccountValuta();
                    //req.Valuta = nDoc.GetAccountValuta();   // По умолчания указываем валюту платежа в качестве валюты обязательств
                    req.Comment = nDoc.PaymentFunction;

                    // Случай финансовой заявки
                    fmCPRPaymentRequestFinOrder reqFin = req as fmCPRPaymentRequestFinOrder;
                    if (reqFin != null)
                    {
                        reqFin.FinanceRequestKind = requestKind;

                        if (requestKind == FinRequestKind.BANK_COMISSION || requestKind == FinRequestKind.PAYMENT_PERCENTS)
                        {
                            if (nDoc.PaymentReceiverRequisites.Party == null && nDoc.PaymentReceiverRequisites.BankAccount != null && nDoc.PaymentReceiverRequisites.BankAccount != null && nDoc.PaymentReceiverRequisites.BankAccount.Bank != null)
                            {
                                nDoc.PaymentReceiverRequisites.Party = nDoc.PaymentReceiverRequisites.BankAccount.Bank.Party;
                            }
                        }
                        if (requestKind == FinRequestKind.RECEIVING_PERCENTS)
                        {
                            if (nDoc.PaymentPayerRequisites.Party == null && nDoc.PaymentPayerRequisites.BankAccount != null && nDoc.PaymentPayerRequisites.BankAccount != null && nDoc.PaymentPayerRequisites.BankAccount.Bank != null)
                            {
                                nDoc.PaymentPayerRequisites.Party = nDoc.PaymentPayerRequisites.BankAccount.Bank.Party;
                            }
                        }
                        if (requestKind == FinRequestKind.PURSHASE_CURRENCY || requestKind == FinRequestKind.SALE_CURRENCY)
                        {
                            if (repaymentTask.BankAccount == nDoc.PaymentPayerRequisites.BankAccount)
                            {
                                if (nDoc.PaymentReceiverRequisites.Party == null && nDoc.PaymentReceiverRequisites.BankAccount != null && nDoc.PaymentReceiverRequisites.BankAccount != null && nDoc.PaymentReceiverRequisites.BankAccount.Bank != null)
                                {
                                    nDoc.PaymentReceiverRequisites.Party = nDoc.PaymentReceiverRequisites.BankAccount.Bank.Party;
                                }
                            }
                            else if (repaymentTask.BankAccount == nDoc.PaymentReceiverRequisites.BankAccount)
                            {
                                if (nDoc.PaymentPayerRequisites.Party == null && nDoc.PaymentPayerRequisites.BankAccount != null && nDoc.PaymentPayerRequisites.BankAccount != null && nDoc.PaymentPayerRequisites.BankAccount.Bank != null)
                                {
                                    nDoc.PaymentPayerRequisites.Party = nDoc.PaymentPayerRequisites.BankAccount.Bank.Party;
                                }
                            }
                        }

                        reqFin.SetSum(nDoc.PaymentCost);

                        reqFin.State = PaymentRequestStates.FINANCE_PAYMENT;   // ПОзволено редактирование Заказа, статьи, суммы
                        //nDoc.State = PaymentDocProcessingStates.PROCESSED;
                    }
                }
            }
            return(req);
        }
コード例 #3
0
        private void DistributeSum(Session ssn, fmCPRRepaymentJurnal repaymentJournalRecord)
        {
            // Задача привязки
            fmCPRRepaymentTask repaymentTask = new fmCPRRepaymentTask(ssn);
            fmCDocRCB          paymentDoc    = repaymentJournalRecord.PaymentDocument;

            repaymentTask.BankAccount     = repaymentJournalRecord.BankAccount;
            repaymentTask.PaymentDocument = paymentDoc;
            //repaymentTask.FillRepaymentTaskLines();
            //repaymentTask.FillRequestList();

            // Сумма, которую надо распределить между обязательствами заявки
            Decimal distributeSum = 0;                                                                  // repaymentJournalRecord.SumOut;   //GetSumRepaymentJournal(ssn, paymentDoc);

            if (paymentDoc.PaymentReceiverRequisites.BankAccount == repaymentJournalRecord.BankAccount) // && this.PaymentDocument.PaymentReceiverRequisites.StatementOfAccount.BankAccount == this.BankAccount) {
            {
                distributeSum = repaymentJournalRecord.SumIn;
            }
            if (paymentDoc.PaymentPayerRequisites.BankAccount == repaymentJournalRecord.BankAccount)     // && this.PaymentDocument.PaymentPayerRequisites.StatementOfAccount.BankAccount == this.BankAccount) {
            {
                distributeSum = repaymentJournalRecord.SumOut;
            }

            if (distributeSum == 0)
            {
                return;
            }

            List <ForCashFlowRecord> cashFlowRecordList = new List <ForCashFlowRecord>();

            // Применяем механизм пропорциональной разбивки
            Decimal intermediateDistributeSum = 0;

            if (distributeSum != 0)
            {
                Decimal totalOblSum = 0;
                foreach (fmCPRPaymentRequestObligation pro in repaymentJournalRecord.PaymentRequest.PaySettlmentOfObligations)
                {
                    totalOblSum += pro.Summ;
                }


                foreach (fmCPRPaymentRequestObligation pro in repaymentJournalRecord.PaymentRequest.PaySettlmentOfObligations)
                {
                    Decimal proSum = Math.Round((pro.Summ / totalOblSum) * distributeSum, 4);

                    // Пишем в промежуточный объект ForCashFlowRecord
                    ForCashFlowRecord cashFlowRecord = new ForCashFlowRecord();
                    cashFlowRecord.repaymentJournalRecord   = repaymentJournalRecord;
                    cashFlowRecord.paymentDoc               = paymentDoc;
                    cashFlowRecord.repaymentTask            = repaymentTask;
                    cashFlowRecord.paymentRequest           = repaymentJournalRecord.PaymentRequest;
                    cashFlowRecord.paymentRequestObligation = pro;
                    cashFlowRecord.sum  = proSum;
                    cashFlowRecord.date = paymentDoc.GetAccountDateChange();
                    cashFlowRecord.paymentRequestObligationGUID = pro.Oid;

                    cashFlowRecordList.Add(cashFlowRecord);

                    intermediateDistributeSum += proSum;
                }
            }

            // Разница между distributeSum и суммой по подуровню в результате ошибки округления
            Decimal diff = intermediateDistributeSum - distributeSum;

            if (diff != 0)
            {
                // Внесение поправки: нахождение самого большого по модулю значения и изменение этого значения
                // (без помощи linq)
                Decimal valueMax = 0;
                for (int i = 0; i < cashFlowRecordList.Count(); i++)
                {
                    if (Math.Abs(cashFlowRecordList[i].sum) > valueMax)
                    {
                        valueMax = Math.Abs(cashFlowRecordList[i].sum);
                    }
                }

                for (int i = 0; i < cashFlowRecordList.Count(); i++)
                {
                    if (Math.Abs(cashFlowRecordList[i].sum) == valueMax)
                    {
                        cashFlowRecordList[i].sum -= diff;
                        break;
                    }
                }
            }

            CreateCFRegisterRecords(ssn, cashFlowRecordList);   //, GetOurParty(ssn));
        }