public Form GetForm(IncomingInvoiceContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var invoice           = context.Invoice;
            var formattingService = context.UnityContainer.Resolve <IFormattingService>();

            var incomeValuesWrapper = new RejectInvoiceFormValuesWrapper
            {
                Control1TargetIdentifier = formattingService.FormatIdentifier(invoice.TargetIdentifier),
                Control2TargetPurse      = invoice.TargetPurse,
                Control3Amount           = invoice.Amount,
                Control4Description      = invoice.Description ?? string.Empty,
                Control5OrderId          = invoice.OrderId.ToString(),
                Control6Address          = invoice.Address ?? string.Empty,
                Control7PaymentPeriod    = invoice.ExpirationPeriod
            };

            if (null != invoice.ProtectionPeriod)
            {
                incomeValuesWrapper.Control8ProtectionPeriod = invoice.ProtectionPeriod.Value;
            }

            return(GetForm(context, context.Invoice.PrimaryId, context.Invoice.TargetPurse, incomeValuesWrapper));
        }
        public bool CheckCompatibility(IncomingInvoiceContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(true);
        }
        public Form GetForm(IncomingInvoiceContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(GetForm(context, context.Invoice.TargetIdentifier, true));
        }
예제 #4
0
        public bool CheckCompatibility(IncomingInvoiceContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            switch (context.Invoice.State)
            {
            case InvoiceState.NotPaid:
                return(true);

            default:
                return(false);
            }
        }
예제 #5
0
        public Form GetForm(IncomingInvoiceContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var invoice = context.Invoice;

            var currencyService = context.UnityContainer.Resolve <ICurrencyService>();
            var currency        = currencyService.ObtainCurrencyByAccountNumber(invoice.TargetPurse);

            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.PayInvoice);

            var templateWrapper = new PayInvoiceFormTemplateWrapper(template);

            templateWrapper.Control4Amount.CurrencyName = currencyService.AddPrefix(currency);

            // Устанавливаем кошельки
            var origin = new AccountDropDownListOrigin(context.UnityContainer);

            // Оплата в долг не требует денег на кошельке, осуществляется с кредитного кошелька (WMC).
            if (currencyService.CheckCapabilities(currency, CurrencyCapabilities.Debit))
            {
                currency = currencyService.SelectCurrencies(CurrencyCapabilities.Credit).First();
            }
            else
            {
                origin.FilterCriteria.HasMoney = true;
            }

            origin.FilterCriteria.Currency = currency;

            origin.FilterCriteria.CurrencyCapabilities = CurrencyCapabilities.Actual | CurrencyCapabilities.TransferByInvoice;

            var itemTemplates = AccountDisplayHelper.BuildAccountDropDownListItemTemplates(origin);

            templateWrapper.Control11PayFrom.Items.Clear();
            templateWrapper.Control11PayFrom.Items.AddRange(itemTemplates);

            // Запрещена оплата с протекцией
            if (null == invoice.ProtectionPeriod)
            {
                templateWrapper.Control12UsePaymentProtection.Enabled = false;
            }
            else
            {
                templateWrapper.Control14ProtectionPeriod.MaxValue = invoice.ProtectionPeriod.Value;
            }

            var formattingService = context.UnityContainer.Resolve <IFormattingService>();

            var incomeValuesWrapper = new PayInvoiceFormValuesWrapper
            {
                Control1TargetIdentifier = formattingService.FormatIdentifier(invoice.TargetIdentifier),
                Control2TargetPurse      = invoice.TargetPurse,
                Control3Amount           = invoice.Amount,
                Control4Description      = invoice.Description ?? string.Empty,
                Control5OrderId          = invoice.OrderId.ToString(),
                Control6Address          = invoice.Address ?? string.Empty,
                Control7PaymentPeriod    = invoice.ExpirationPeriod.ToString(),
                Control9TransferId       = context.Session.SettingsService.AllocateTransferId()
            };

            if (null != invoice.ProtectionPeriod)
            {
                incomeValuesWrapper.Control8MaxProtectionPeriod = invoice.ProtectionPeriod.Value.ToString();
            }

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            form.ApplyTemplate(template, incomeValuesWrapper.CollectIncomeValues());

            form.ServiceCommand += (sender, args) =>
            {
                if (!PayInvoiceFormValuesWrapper.Control1TargetIdentifierCommandFindPassport.Equals(args.Command))
                {
                    return;
                }

                IdentifierDisplayHelper.ShowFindCertificateForm(form, context, (string)args.Argument);
            };

            form.WorkCallback = (step, list) =>
            {
                var valuesWrapper   = new PayInvoiceFormValuesWrapper(list);
                var transferService = context.UnityContainer.Resolve <ITransferService>();

                var originalTransfer = new OriginalTransfer(valuesWrapper.Control9TransferId,
                                                            valuesWrapper.Control10PayFrom, invoice.TargetPurse, invoice.Amount,
                                                            invoice.Description)
                {
                    InvoiceId = invoice.PrimaryId
                };

                if (valuesWrapper.Control11UsePaymentProtection)
                {
                    originalTransfer.ProtectionPeriod = valuesWrapper.Control12ProtectionPeriod;

                    if (valuesWrapper.Control14ProtectionByTime)
                    {
                        originalTransfer.ProtectionCode = valuesWrapper.Control13ProtectionCode;
                    }
                }

                transferService.CreateTransfer(originalTransfer);

                return(new Dictionary <string, object>());
            };

            return(form);
        }
 public Form GetForm(IncomingInvoiceContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
     return(GetForm(context.Invoice));
 }
예제 #7
0
        public Control GetScreen(ScreenContainerContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var origin = new FilterOrigin(context.ExtensionManager,
                                          ExtensionCatalog.IncomingInvoiceFilterScreen)
            {
                MenuItemsTagName  = ExtensionCatalog.Tags.IncomingInvoiceExtension,
                CommandBarTagName = ExtensionCatalog.Tags.IncomingInvoiceFilterExtension,
                ColumnsSettings   = context.Session.SettingsService.GetSettings().IncomingInvoiceSettings
            };

            var template = FilterDisplayHelper.LoadFilterScreenTemplate(origin);

            // Отключаем кнопки.
            foreach (var buttonTemplate in template.CommandButtons)
            {
                var formProvider =
                    context.ExtensionManager.TryGetTopFormProvider(buttonTemplate.Command);

                if (!(formProvider?.CheckCompatibility(context) ?? false))
                {
                    buttonTemplate.Enabled = false;
                }
            }

            var screen = new FilterScreen();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, screen);

            var now = DateTime.Now;

            var incomeValuesWrapper = new IncomingInvoiceFilterFormValuesWrapper
            {
                Control1FromTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, DateTimeKind.Local),
                Control2ToTime   = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, DateTimeKind.Local)
            };

            screen.ApplyTemplate(template);
            screen.ApplyShapeValues(incomeValuesWrapper.CollectIncomeValues());

            // Меню
            screen.MenuItemResolver = (entity, command) =>
            {
                var invoice = screen.CurrentEntity as IIncomingInvoice;

                if (null == invoice)
                {
                    return(false);
                }

                var invoiceContext = new IncomingInvoiceContext(context, invoice);

                var formProvider = context.ExtensionManager.TryGetIncomingInvoiceFormProvider(command);
                return(formProvider?.CheckCompatibility(invoiceContext) ?? false);
            };

            // Обработка событий.
            screen.ServiceCommand += (sender, args) =>
            {
                string command = args.Command;

                if (null == command)
                {
                    throw new InvalidOperationException("null == command");
                }

                if (command.StartsWith("CellContentClick:", StringComparison.Ordinal))
                {
                    return;
                }

                if (FilterScreen.BeginUpdateServiceCommand.Equals(args.Command))
                {
                    context.ScreenContainer.OnStartProgress();
                    return;
                }

                if (FilterScreen.EndUpdateServiceCommand.Equals(args.Command))
                {
                    context.ScreenContainer.OnStopProgress();
                    return;
                }

                if (FilterScreen.DisplayContentServiceCommand.Equals(args.Command))
                {
                    return;
                }

                if (command.StartsWith("CellMouseDoubleClick:", StringComparison.Ordinal))
                {
                    command = ExtensionCatalog.Details;
                }

                var form = screen.FindForm();

                var invoice = args.Argument as IIncomingInvoice;

                // Кнопки
                if (null == invoice)
                {
                    var formProvider = context.ExtensionManager.TryGetTopFormProvider(command);
                    formProvider?.GetForm(context).Show(form);
                }
                else
                {
                    // Системная
                    var formProvider = context.ExtensionManager.TryGetIncomingInvoiceFormProvider(command);
                    formProvider?.GetForm(new IncomingInvoiceContext(context, invoice))
                    .Show(form);
                }
            };

            // Команда Refresh
            screen.WorkCallback = list =>
            {
                var valuesWrapper = new IncomingInvoiceFilterFormValuesWrapper(list);

                var invoiceService = context.UnityContainer.Resolve <IInvoiceService>();

                var invoices = invoiceService.SelectIncomingInvoices(valuesWrapper.Control1FromTime.ToUniversalTime(),
                                                                     valuesWrapper.Control2ToTime.ToUniversalTime(), true);

                var gridRowContentList = new List <GridRowContent>();

                var operationSettings = context.Session.SettingsService.GetSettings().OperationSettings;

                decimal paid    = 0;
                decimal notPaid = 0;
                decimal refused = 0;

                foreach (var invoice in invoices)
                {
                    var gridRowContent = new GridRowContent(invoice.PrimaryId.ToString(), invoice);

                    switch (invoice.State)
                    {
                    case InvoiceState.Paid:
Paid:
                        gridRowContent.ForeColor          = operationSettings.OutcomeForeColor;
                        gridRowContent.SelectionForeColor = operationSettings.OutcomeForeColor;
                        break;

                    case InvoiceState.PaidWithProtection:
                        gridRowContent.BackColor          = operationSettings.ProtectedColor;
                        gridRowContent.SelectionBackColor = ColorUtility.CalculateSelectionColor(operationSettings.ProtectedColor);
                        goto Paid;

                    case InvoiceState.Refusal:
                        gridRowContent.Strikeout = true;
                        break;
                    }

                    switch (invoice.State)
                    {
                    case InvoiceState.NotPaid:
                        notPaid += invoice.Amount;
                        break;

                    case InvoiceState.PaidWithProtection:
                    case InvoiceState.Paid:
                        paid += invoice.Amount;
                        break;

                    case InvoiceState.Refusal:
                        refused += invoice.Amount;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    gridRowContentList.Add(gridRowContent);
                }

                var chartPoint1 = new ChartPoint(
                    Translator.Instance.Translate(ExtensionCatalog.IncomingInvoiceFilterScreen, "Paid"), (double)paid);
                var chartPoint2 = new ChartPoint(
                    Translator.Instance.Translate(ExtensionCatalog.IncomingInvoiceFilterScreen, "Not paid"),
                    (double)notPaid);
                var chartPoint3 = new ChartPoint(
                    Translator.Instance.Translate(ExtensionCatalog.IncomingInvoiceFilterScreen, "Refused"), (double)refused);

                var filterScreenContent = new FilterScreenContent();

                filterScreenContent.RowContentList.AddRange(gridRowContentList);

                if (paid > 0)
                {
                    filterScreenContent.ChartPoints.Add(chartPoint1);
                }

                if (notPaid > 0)
                {
                    filterScreenContent.ChartPoints.Add(chartPoint2);
                }

                if (refused > 0)
                {
                    filterScreenContent.ChartPoints.Add(chartPoint3);
                }

                return(filterScreenContent);
            };

            return(screen);
        }