Ejemplo n.º 1
0
        public virtual void ReturnDocument(Sungero.Domain.Client.ExecuteActionArgs e)
        {
            if (Functions.Module.IsLockedByOther(_obj, e))
            {
                return;
            }

            var tracking = _obj.Tracking.Where(l => (!l.ReturnDate.HasValue || Equals(l.ReturnResult, Docflow.OfficialDocumentTracking.ReturnResult.AtControl)) &&
                                               l.ReturnDeadline.HasValue &&
                                               (l.Action == Docflow.OfficialDocumentTracking.Action.Delivery ||
                                                l.Action == Docflow.OfficialDocumentTracking.Action.Sending)).ToList();

            if (!tracking.Any())
            {
                Dialogs.NotifyMessage(Docflow.Resources.ReturnDocumentActiveTrackingNotFound);
                return;
            }

            var employees = new List <Company.IEmployee>();

            foreach (var emp in tracking.Select(l => l.DeliveredTo))
            {
                if (!employees.Contains(emp))
                {
                    employees.Add(emp);
                }
            }
            var employee = employees.FirstOrDefault();

            var dialog = Dialogs.CreateInputDialog(Docflow.Resources.ReturnDocumentDialog, _obj.Name);

            dialog.HelpCode = Constants.OfficialDocument.HelpCode.Return;
            INavigationDialogValue <Company.IEmployee> employeeDialog = null;

            if (employees.Count > 1)
            {
                employeeDialog = dialog.AddSelect(Docflow.Resources.ReturnDocumentEmployee, true, employee).From(employees);
            }
            var returnDate = dialog.AddDate(Docflow.Resources.ReturnDocumentDate, true, Calendar.UserToday);

            var returnDocument = dialog.Buttons.AddCustom(Docflow.Resources.ReturnDocument);

            dialog.Buttons.Default = returnDocument;

            var hasAvailableTasks = false;

            foreach (var row in tracking)
            {
                if (row.ReturnTask.AccessRights.CanRead())
                {
                    hasAvailableTasks = hasAvailableTasks || Functions.OfficialDocument.Remote.GetReturnAssignments(row.ReturnTask).Any();
                }
            }
            CommonLibrary.DialogButton openAssignments = null;
            if (hasAvailableTasks)
            {
                openAssignments = dialog.Buttons.AddCustom(Docflow.Resources.ReturnDocumentOpenAssignment);
            }

            dialog.Buttons.AddCancel();

            dialog.SetOnRefresh(d =>
            {
                if (employeeDialog != null)
                {
                    employee = employeeDialog.Value;
                }
                if (employee == null)
                {
                    return;
                }

                var employeeTracking = tracking.Where(l => Equals(l.DeliveredTo, employee));
                foreach (var row in employeeTracking)
                {
                    if (returnDate.Value.HasValue && returnDate.Value.Value < row.DeliveryDate.Value)
                    {
                        d.AddError(Docflow.Resources.ReturnDocumentDeliveryAndReturnDate, returnDate);
                        return;
                    }
                }
            });

            var result = dialog.Show();

            if (result != DialogButtons.Cancel)
            {
                if (employeeDialog != null)
                {
                    employee = employeeDialog.Value;
                }
                var employeeTracking = tracking.Where(l => Equals(l.DeliveredTo, employee));

                if (result == returnDocument)
                {
                    var returnResult = Docflow.OfficialDocumentTracking.ReturnResult.Returned;
                    foreach (var row in employeeTracking)
                    {
                        row.ReturnDate   = returnDate.Value;
                        row.ReturnResult = returnResult;
                    }

                    _obj.Save();
                    Dialogs.NotifyMessage(Docflow.Resources.ReturnDocumentNotify);
                }

                if (result == openAssignments)
                {
                    try
                    {
                        var returnTasks = employeeTracking.Select(i => i.ReturnTask).ToList();
                        var assignments = Functions.OfficialDocument.Remote.GetReturnAssignments(returnTasks);

                        if (assignments.Count == 1)
                        {
                            assignments.Single().Show();
                        }
                        else if (assignments.Count > 1)
                        {
                            assignments.Show();
                        }
                        else if (!assignments.Any())
                        {
                            Dialogs.NotifyMessage(Docflow.Resources.JobToReturnNotFound);
                        }
                    }
                    catch (Exception)
                    {
                        // TODO: продумать ситуацию когда на часть задач все-таки есть права.
                        Dialogs.NotifyMessage(Docflow.Resources.JobToReturnNotFound);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public virtual void ReturnFromCounterparty(Sungero.Domain.Client.ExecuteActionArgs e)
        {
            // TODO: продумать ситуацию когда на часть задач все-таки есть права.
            if (Functions.Module.IsLockedByOther(_obj, e))
            {
                return;
            }

            var tracking = _obj.Tracking.Where(l => (!l.ReturnDate.HasValue || Equals(l.ReturnResult, Docflow.OfficialDocumentTracking.ReturnResult.AtControl)) &&
                                               l.ReturnDeadline.HasValue &&
                                               l.Action == Docflow.OfficialDocumentTracking.Action.Endorsement).ToList();

            if (tracking.Any() && tracking.All(t => t.ExternalLinkId != null))
            {
                Dialogs.NotifyMessage(OfficialDocuments.Resources.TrackingNoneReturnFromCounterparty);
                return;
            }

            tracking = tracking.Where(t => t.ReturnTask != null).ToList();

            if (!tracking.Any())
            {
                Dialogs.NotifyMessage(Docflow.Resources.ReturnDocumentActiveTrackingNotFound);
                return;
            }

            var employees = new List <Company.IEmployee>();

            foreach (var emp in tracking.Select(l => l.DeliveredTo))
            {
                if (!employees.Contains(emp))
                {
                    employees.Add(emp);
                }
            }
            var employee = employees.FirstOrDefault();

            var dialog = Dialogs.CreateInputDialog(Docflow.Resources.ReturnDocumentDialog, _obj.Name);

            dialog.HelpCode = Constants.OfficialDocument.HelpCode.ReturnFromCounterparty;
            INavigationDialogValue <Company.IEmployee> employeeDialog = null;

            if (employees.Count > 1)
            {
                employeeDialog = dialog.AddSelect(Docflow.Resources.ReturnDocumentEmployee, true, employee).From(employees);
            }
            var returnDate = dialog.AddDate(Docflow.Resources.ReturnDocumentDate, true, Calendar.UserToday);

            // Принудительно увеличиваем ширину диалога в Web для корректного отображения кнопок.
            if (ClientApplication.ApplicationType == ApplicationType.Web)
            {
                var fakeControl = dialog.AddString("12345678901234", false);
                fakeControl.IsVisible = false;
            }

            var signed = dialog.Buttons.AddCustom(Docflow.Resources.ReturnDocumentSigned);

            dialog.Buttons.Default = signed;
            var notSigned = dialog.Buttons.AddCustom(Docflow.Resources.ReturnDocumentNotSigned);

            var hasAvailableTasks = false;

            foreach (var row in tracking)
            {
                if (row.ReturnTask.AccessRights.CanRead())
                {
                    hasAvailableTasks = hasAvailableTasks || Functions.OfficialDocument.Remote.GetReturnAssignments(row.ReturnTask).Any();
                }
            }
            CommonLibrary.DialogButton openAssignments = null;
            if (hasAvailableTasks)
            {
                openAssignments = dialog.Buttons.AddCustom(Docflow.Resources.ReturnDocumentOpenAssignment);
            }

            dialog.Buttons.AddCancel();

            var result = dialog.Show();

            if (result != DialogButtons.Cancel)
            {
                if (employeeDialog != null)
                {
                    employee = employeeDialog.Value;
                }
                var employeeTracking = tracking.Where(l => Equals(l.DeliveredTo, employee));

                if (result == signed || result == notSigned)
                {
                    var returnResult = result == signed ?
                                       Docflow.OfficialDocumentTracking.ReturnResult.Signed :
                                       Docflow.OfficialDocumentTracking.ReturnResult.NotSigned;
                    foreach (var row in employeeTracking)
                    {
                        row.ReturnDate   = returnDate.Value;
                        row.ReturnResult = returnResult;
                    }

                    _obj.Save();
                    Dialogs.NotifyMessage(Docflow.Resources.ReturnDocumentNotify);
                }

                if (result == openAssignments)
                {
                    try
                    {
                        var returnTasks = employeeTracking.Select(i => i.ReturnTask).ToList();
                        var assignments = Functions.OfficialDocument.Remote.GetReturnAssignments(returnTasks);

                        if (assignments.Count == 1)
                        {
                            assignments.Single().Show();
                        }
                        else if (assignments.Count > 1)
                        {
                            assignments.Show();
                        }
                        else if (!assignments.Any())
                        {
                            Dialogs.NotifyMessage(Docflow.Resources.JobToReturnNotFound);
                        }
                    }
                    catch (Exception)
                    {
                        Dialogs.NotifyMessage(Docflow.Resources.JobToReturnNotFound);
                    }
                }
            }
        }