private void MapDocuments_Execute(object sender, SimpleActionExecuteEventArgs e) { // ќбработка прив¤зок документов выписок к платЄжным документам. нопка "—охранить" получаетс¤ как бы лишней if (View == null || View.CurrentObject == null || View.CurrentObject as fmCPRRepaymentJurnal == null) { return; } fmCPRRepaymentJurnal rr = View.CurrentObject as fmCPRRepaymentJurnal; // foreach (fmCSAStatementAccountDoc doc in rr.StatementAccountDocuments) { // doc.PaymentDocument = rr.PaymentDocument; // } this.ObjectSpace.CommitChanges(); // ќбновление списка // rr.StatementAccountDocuments.Reload(); }
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)); }
public virtual void AutoBinding(crmBankAccount BankAccount, fmCPRPaymentRequest PaymentRequest, fmCPRRepaymentTask RepaymentTask) { // Привязка с распределением счетов // Проверка на уже связанность заявки XPQuery <fmCPRRepaymentJurnal> repaymentJurnalExists = new XPQuery <fmCPRRepaymentJurnal>(this.Session); var queryRepaymentJurnalExists = from repaymentJurnal in repaymentJurnalExists where repaymentJurnal.PaymentDocument == this select repaymentJurnal; if (queryRepaymentJurnalExists.Count() > 0) { DevExpress.XtraEditors.XtraMessageBox.Show("Заявка уже привязана"); return; } // Проверка на превышение сумм if (RepaymentTask.RepaymentRegisterSum + PaymentRequest.Summ > RepaymentTask.OperationRegisterSum) { DevExpress.XtraEditors.XtraMessageBox.Show("Сумма связанных заявок превысит сумму по документам выписки. Привязка невозможна."); return; } // Наша организация crmCParty OurParty = GetOurParty(); // Привязка в принципе возможна, т.е. выбранная заявка добавляется в fmCPRRepaymentJurnal fmCPRRepaymentJurnal newRepaymentJournalRecord = new fmCPRRepaymentJurnal(Session); newRepaymentJournalRecord.BankAccount = BankAccount; //newRepaymentJournalRecord.PaymentDate = newRepaymentJournalRecord.PaymentDocument = this; newRepaymentJournalRecord.PaymentRequest = PaymentRequest; newRepaymentJournalRecord.PlaneFact = CRM.Contract.Analitic.PlaneFact.FACT; if (OurParty.INN == PaymentRequest.PartyPayReceiver.INN) { newRepaymentJournalRecord.SumIn = PaymentRequest.Summ; } if (OurParty.INN == PaymentRequest.PartyPaySender.INN) { newRepaymentJournalRecord.SumOut = PaymentRequest.Summ; } newRepaymentJournalRecord.ValutaObligation = PaymentRequest.Valuta; // Валюта обязательств newRepaymentJournalRecord.ValutaPayment = PaymentRequest.PaymentValuta; // Валюта платежа // Обновление таблицы RepaymentTaskLines // Удаление всех записей из fmCPRRepaymentTaskLine Session.Delete(RepaymentTask.RepaymentTaskLines); //Session.PurgeDeletedObjects(); // Журнал привязок XPQuery <fmCPRRepaymentJurnal> repaymentJurnals = new XPQuery <fmCPRRepaymentJurnal>(this.Session); var queryRepaymentJurnals = from repaymentJurnal in repaymentJurnals where repaymentJurnal.PaymentDocument == this select repaymentJurnal; var queryGroupRepaymentJurnals = from repaymentJurnal in queryRepaymentJurnals group repaymentJurnal by new { repaymentJurnal.PaymentRequest } into grj select new { PaymentRequest = grj.Key.PaymentRequest, GroupSumIn = grj.Sum(row => row.SumIn), GroupSumOut = grj.Sum(row => row.SumOut) }; foreach (var grj in queryGroupRepaymentJurnals) { // Добавляем запись в fmCPRRepaymentTaskLine fmCPRRepaymentTaskLine newLine = new fmCPRRepaymentTaskLine(Session); newLine.RepaymentTask = RepaymentTask; RepaymentTask.RepaymentTaskLines.Add(newLine); newLine.PaymentRequest = PaymentRequest; newLine.RequestSum = grj.GroupSumIn + grj.GroupSumOut; // Одна из них равна 0 } }