Exemple #1
0
        protected void FillDocuments()
        {
            uow = UnitOfWorkFactory.CreateWithoutRoot();
            TreeIter iter;

            progressBar.Fraction = 0;
            progressBar.Text     = "Загружаем выгрузку из банк-клиента... Операция 2/2";
            double progressStep = 1.0 / rowsCount;

            if (!documents.GetIterFirst(out iter))
            {
                return;
            }
            do
            {
                //Шевелим прогрессбаром. I'd like to move it, move it.
                if (progressBar.Fraction + progressStep > 1)
                {
                    progressBar.Fraction = 1;
                }
                else
                {
                    progressBar.Fraction += progressStep;
                }
                while (Application.EventsPending())
                {
                    Application.RunIteration();
                }

                //Проверяем галочку.
                if (!(bool)documents.GetValue(iter, (int)Columns.CheckCol))
                {
                    continue;
                }
                //Получаем документ
                var doc          = (TransferDocument)documents.GetValue(iter, (int)Columns.TransferDocumentCol);
                var organization = OrganizationRepository.GetOrganizationByInn(uow, doc.RecipientInn);
                //Мы платим
                if (organization == null)
                {
                    if (!AccountExpenseRepository.AccountExpenseExists(uow, doc.Date.Year, Int32.Parse(doc.Number), doc.PayerCheckingAccount))
                    {
                        organization = OrganizationRepository.GetOrganizationByInn(uow, doc.PayerInn);
                        var expenseUoW = UnitOfWorkFactory.CreateWithNewRoot <AccountExpense> ();
                        expenseUoW.Root.Number      = Int32.Parse(doc.Number);
                        expenseUoW.Root.Date        = doc.Date;
                        expenseUoW.Root.Total       = doc.Total;
                        expenseUoW.Root.Description = doc.PaymentPurpose;
                        expenseUoW.Root.MoneyOperation.PaymentType = PaymentType.cashless;
                        expenseUoW.Root.Organization        = organization;
                        expenseUoW.Root.OrganizationAccount = organization.Accounts.First(acc => acc.Number == doc.PayerCheckingAccount);
                        expenseUoW.Root.Counterparty        = CounterpartyRepository.GetCounterpartyByINN(expenseUoW, doc.RecipientInn);
                        if (expenseUoW.Root.Counterparty == null)
                        {
                            expenseUoW.Root.Employee        = EmployeeRepository.GetEmployeeByINNAndAccount(expenseUoW, doc.RecipientInn, doc.RecipientCheckingAccount);
                            expenseUoW.Root.EmployeeAccount = expenseUoW.Root.Employee.Accounts.First(acc => acc.Number == doc.RecipientCheckingAccount);
                        }
                        else
                        {
                            expenseUoW.Root.CounterpartyAccount = expenseUoW.Root.Counterparty.Accounts.First(acc => acc.Number == doc.RecipientCheckingAccount);
                        }
                        expenseUoW.Root.Category = (ExpenseCategory)documents.GetValue(iter, (int)Columns.CategoryObject);
                        expenseUoW.Save();
                    }
                }
                //Нам платят
                else
                {
                    if (!AccountIncomeRepository.AccountIncomeExists(uow, doc.Date.Year, Int32.Parse(doc.Number), doc.PayerInn, doc.PayerCheckingAccount))
                    {
                        var incomeUoW = UnitOfWorkFactory.CreateWithNewRoot <AccountIncome> ();
                        incomeUoW.Root.Number      = Int32.Parse(doc.Number);
                        incomeUoW.Root.Date        = doc.Date;
                        incomeUoW.Root.Total       = doc.Total;
                        incomeUoW.Root.Description = doc.PaymentPurpose;
                        incomeUoW.Root.MoneyOperation.PaymentType = PaymentType.cashless;
                        var counterparty = CounterpartyRepository.GetCounterpartyByINN(incomeUoW, doc.PayerInn);
                        if (counterparty == null)
                        {
                            counterparty = CounterpartyRepository.GetCounterpartyByAccount(incomeUoW, doc.PayerAccount);
                        }

                        incomeUoW.Root.Counterparty        = counterparty;
                        incomeUoW.Root.CounterpartyAccount = incomeUoW.Root.Counterparty.Accounts.First(acc => acc.Number == doc.PayerCheckingAccount);
                        incomeUoW.Root.Organization        = organization;
                        incomeUoW.Root.OrganizationAccount = organization.Accounts.First(acc => acc.Number == doc.RecipientCheckingAccount);
                        incomeUoW.Root.Category            = (IncomeCategory)documents.GetValue(iter, (int)Columns.CategoryObject);
                        incomeUoW.Save();
                    }
                }
            } while (documents.IterNext(ref iter));
            progressBar.Text = "Загрузка завершена успешно";
        }
Exemple #2
0
        protected void HighlightDocuments()
        {
            totalIncome = totalExpense = 0;
            TreeIter iter;

            if (!documents.GetIterFirst(out iter))
            {
                return;
            }

            var defaultIncomeCategory = CategoryRepository.DefaultIncomeCategory(uow);

            progressBar.Fraction = 0;
            progressBar.Text     = "Идет обработка файла выгрузки...";
            double progressStep = 1.0 / rowsCount;

            do
            {
                //Шевелим прогрессбаром. I'd like to move it, move it.
                if (progressBar.Fraction + progressStep > 1)
                {
                    progressBar.Fraction = 1;
                }
                else
                {
                    progressBar.Fraction += progressStep;
                }
                while (Application.EventsPending())
                {
                    Application.RunIteration();
                }

                var doc = (documents.GetValue(iter, (int)Columns.TransferDocumentCol) as TransferDocument);

                //Сначала пробуем найти нашу организацию. Она должна фигурировать либо как получатель либо как плательщик.
                var organization = OrganizationRepository.GetOrganizationByInn(uow, doc.PayerInn);
                if (organization == null)
                {
                    //Нам платят
                    organization = OrganizationRepository.GetOrganizationByInn(uow, doc.RecipientInn);
                    if (organization == null)
                    {
                        organization = OrganizationRepository.GetOrganizationByAccountNumber(uow, doc.RecipientCheckingAccount);
                        if (organization == null)
                        {
                            progressBar.Fraction = 0;
                            progressBar.Text     = "Ошибка обработки выгрузки!";
                            throw new Exception("Не удалось обнаружить нашу организацию ни по ИНН, ни по номеру счета. Заполните организацию, или проверьте корректность ИНН.");
                        }
                    }
                    //Проверяем наш счет
                    if (!organization.Accounts.Any(acc => acc.Number == doc.RecipientCheckingAccount))
                    {
                        documents.SetValue(iter, (int)Columns.RecipientAccountColorCol, NeedToAdd);
                    }
                    //Ищем плательщика
                    var payerCounterparty = CounterpartyRepository.GetCounterpartyByINN(uow, doc.PayerInn);
                    if (payerCounterparty == null)
                    {
                        payerCounterparty = CounterpartyRepository.GetCounterpartyByAccount(uow, doc.PayerAccount);
                    }

                    if (payerCounterparty == null)
                    {
                        documents.SetValue(iter, (int)Columns.PayerNameColorCol, NeedToAdd);
                        documents.SetValue(iter, (int)Columns.PayerAccountColorCol, NeedToAdd);
                    }
                    else if (!payerCounterparty.Accounts.Any(acc => acc.Number == doc.PayerCheckingAccount))
                    {
                        documents.SetValue(iter, (int)Columns.PayerAccountColorCol, NeedToAdd);
                    }
                    documents.SetValue(iter, (int)Columns.CategoryComboModel, incomeCategories);
                    documents.SetValue(iter, (int)Columns.CategoryName, defaultIncomeCategory.Name);
                    documents.SetValue(iter, (int)Columns.CategoryObject, defaultIncomeCategory);
                    totalIncome += doc.Total;
                }
                else
                {
                    //Мы платим
                    //Проверяем наш счет
                    if (!organization.Accounts.Any(acc => acc.Number == doc.PayerCheckingAccount))
                    {
                        documents.SetValue(iter, (int)Columns.PayerAccountColorCol, NeedToAdd);
                    }
                    //Ищем получателя
                    var recipientCounterparty = CounterpartyRepository.GetCounterpartyByINN(uow, doc.RecipientInn);
                    if (recipientCounterparty == null)
                    {
                        //Возможно это сотрудник
                        var employee = EmployeeRepository.GetEmployeeByINNAndAccount(uow, doc.RecipientInn, doc.RecipientCheckingAccount);
                        if (employee == null)
                        {
                            documents.SetValue(iter, (int)Columns.RecipientNameColorCol, NeedToAdd);
                            documents.SetValue(iter, (int)Columns.RecipientAccountColorCol, NeedToAdd);
                        }
                    }
                    else if (!recipientCounterparty.Accounts.Any(acc => acc.Number == doc.RecipientCheckingAccount))
                    {
                        documents.SetValue(iter, (int)Columns.RecipientAccountColorCol, NeedToAdd);
                    }
                    documents.SetValue(iter, (int)Columns.CategoryComboModel, expenseCategories);
                    if (recipientCounterparty != null && recipientCounterparty.DefaultExpenseCategory != null)
                    {
                        documents.SetValue(iter, (int)Columns.CategoryName, recipientCounterparty.DefaultExpenseCategory.Name);
                        documents.SetValue(iter, (int)Columns.CategoryObject, recipientCounterparty.DefaultExpenseCategory);
                    }
                    totalExpense += doc.Total;
                }

                //Проверяем банки
                var payerBank = BankRepository.GetBankByBik(uow, doc.PayerBik);
                if (payerBank == null && !String.IsNullOrEmpty(doc.PayerBik))
                {
                    documents.SetValue(iter, (int)Columns.PayerBankColorCol, NeedToAdd);
                }
                var recipientBank = BankRepository.GetBankByBik(uow, doc.RecipientBik);
                if (recipientBank == null && !String.IsNullOrEmpty(doc.PayerBik))
                {
                    documents.SetValue(iter, (int)Columns.RecipientBankColorCol, NeedToAdd);
                }
            } while (documents.IterNext(ref iter));
            progressBar.Text = "Обработка файла выгрузки завершена";
        }