Ejemplo n.º 1
0
        public async Task <Filter> Outbox(EntityModel model, List <dynamic> entities, dynamic options)
        {
            var userId = DWKitRuntime.Security.CurrentUser.ImpersonatedUserId.HasValue ? DWKitRuntime.Security.CurrentUser.ImpersonatedUserId.Value :
                         DWKitRuntime.Security.CurrentUser.Id;
            var historyModel = await MetadataToModelConverter.GetEntityModelByModelAsync("WorkflowProcessTransitionHistory");

            var currentUserOutbox = (await historyModel.GetAsync(Filter.And.Equal(userId.ToString(), "ExecutorIdentityId"))).Select(e => (Guid)(e as dynamic).ProcessId).ToList();

            return(Filter.And.In(currentUserOutbox, "Id"));
        }
Ejemplo n.º 2
0
        public async static Task <object> Generate(DateTime datefrom, DateTime dateto)
        {
            EntityModel employeeModel = await MetadataToModelConverter.GetEntityModelByModelAsync("Employee", 0);

            EntityModel businessTripModel = await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.BusinessTrip);

            EntityModel sickLeaveModel = await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.SickLeave);

            EntityModel vacationModel = await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.Vacation);

            var filter = Filter.And.In(WorkflowReport.FinalStates, "State").Merge(
                Filter.And.LessOrEqual(dateto, "DateStart").GreaterOrEqual(datefrom, "DateEnd"));

            var employees = await employeeModel.GetAsync(Filter.Empty);

            var businessTripFilter = DocumentTypes.GetFilter(DocumentTypes.BusinessTrip)
                                     .Merge(filter)
                                     .Merge(Document.GetViewFilterForCurrentUser(businessTripModel));
            var businessTrips = await businessTripModel.GetAsync(businessTripFilter);

            businessTrips.ForEach((item) =>
            {
                var i = (dynamic)item;
                if (!string.IsNullOrEmpty(i.Employees))
                {
                    i.EmployeesList = JsonConvert.DeserializeObject <List <Guid> >(i.Employees);
                    var names       = new List <string>();
                    foreach (Guid empId in i.EmployeesList)
                    {
                        var emp = employees.Select(c => c as dynamic).Where(c => c.Id == empId).FirstOrDefault();
                        names.Add(emp?.Name);
                    }
                    i.EmployeesNames = names.OrderBy(c => c).ToList();
                }
            });

            var sickLeaveFilter = DocumentTypes.GetFilter(DocumentTypes.SickLeave)
                                  .Merge(filter)
                                  .Merge(Document.GetViewFilterForCurrentUser(sickLeaveModel));

            var sickLeaves = await sickLeaveModel.GetAsync(sickLeaveFilter);

            var vacationFilter = DocumentTypes.GetFilter(DocumentTypes.Vacation)
                                 .Merge(filter)
                                 .Merge(Document.GetViewFilterForCurrentUser(vacationModel));
            var vacations = await vacationModel.GetAsync(vacationFilter);

            var res = new List <WorkCalendarEvent>();

            res.AddRange(businessTrips.Select(c => new WorkCalendarEvent(c, "businesstrip", "Business Trip")));
            res.AddRange(sickLeaves.Select(c => new WorkCalendarEvent(c, "sickleave", "Sick Leave")));
            res.AddRange(vacations.Select(c => new WorkCalendarEvent(c, "vacation", "Vacation")));
            return(res);
        }
Ejemplo n.º 3
0
        private static async Task ActivityChanged(ProcessActivityChangedEventArgs args, WorkflowRuntime runtime)
        {
            if (!args.TransitionalProcessWasCompleted)
            {
                return;
            }

            var historyModel = await MetadataToModelConverter.GetEntityModelByModelAsync("DocumentTransitionHistory");

            var emptyHistory = (await historyModel.GetAsync(Filter.And.Equal(Null.Value, "EmployeeId").Equal(args.ProcessId, "DocumentId"))).Select(h => h.GetId()).ToList();
            await historyModel.DeleteAsync(emptyHistory);

            await runtime.PreExecuteFromCurrentActivityAsync(args.ProcessId);

            var nextState     = WorkflowInit.Runtime.GetLocalizedStateName(args.ProcessId, args.ProcessInstance.CurrentState);
            var documentModel = await MetadataToModelConverter.GetEntityModelByModelAsync("Document");

            var document = (await documentModel.GetAsync(Filter.And.Equal(args.ProcessId, "Id"))).FirstOrDefault() as dynamic;

            if (document == null)
            {
                return;
            }

            document.StateName = nextState;
            document.State     = args.ProcessInstance.CurrentState;
            await documentModel.UpdateSingleAsync(document as DynamicEntity);

            var newActors = await Runtime.GetAllActorsForDirectCommandTransitionsAsync(args.ProcessId);

            var newInboxes = new List <dynamic>();

            foreach (var newActor in newActors)
            {
                var newInboxItem = new DynamicEntity() as dynamic;
                newInboxItem.Id         = Guid.NewGuid();
                newInboxItem.IdentityId = new Guid(newActor);
                newInboxItem.ProcessId  = args.ProcessId;
                newInboxes.Add(newInboxItem);
            }

            using (var shared = new SharedTransaction())
            {
                var inboxModel = await MetadataToModelConverter.GetEntityModelByModelAsync("WorkflowInbox");

                var existingInboxes = (await inboxModel.GetAsync(Filter.And.Equal(args.ProcessId, "ProcessId"))).Select(i => i.GetId()).ToList();
                await inboxModel.DeleteAsync(existingInboxes);

                await inboxModel.InsertAsync(newInboxes);

                shared.Commit();
            }
        }
        public IEnumerable <string> RoleGet(ProcessInstance processInstance, WorkflowRuntime runtime, string parameter)
        {
            var rolesModel = MetadataToModelConverter.GetEntityModelByModelAsync("dwSecurityRole").Result;
            var role       = rolesModel.GetAsync(Filter.And.Equal(parameter, "Name")).Result.FirstOrDefault();

            if (role == null)
            {
                return(new List <string>());
            }
            var roleUserModel = MetadataToModelConverter.GetEntityModelByModelAsync("dwV_Security_UserRole").Result;

            return(roleUserModel.GetAsync(Filter.And.Equal(role.GetId(), "RoleId")).Result.Select(r => r["UserId"].ToString()).Distinct());
        }
        public bool RoleCheck(ProcessInstance processInstance, WorkflowRuntime runtime, string identityId, string parameter)
        {
            var rolesModel = MetadataToModelConverter.GetEntityModelByModelAsync("dwSecurityRole").Result;
            var role       = rolesModel.GetAsync(Filter.And.Equal(parameter, "Name")).Result.FirstOrDefault();

            if (role == null)
            {
                return(false);
            }
            var roleUserModel = MetadataToModelConverter.GetEntityModelByModelAsync("dwV_Security_UserRole").Result;

            return(roleUserModel.GetCountAsync(Filter.And.Equal(role.GetId(), "RoleId").Equal(Guid.Parse(identityId), "UserId")).Result > 0);
        }
Ejemplo n.º 6
0
        public static async Task NotifyClientsAboutInboxStatus(string userId)
        {
            var inboxModel = await MetadataToModelConverter.GetEntityModelByModelAsync("WorkflowInbox");

            var historyModel = await MetadataToModelConverter.GetEntityModelByModelAsync("WorkflowProcessTransitionHistory");

            var inboxCount = await inboxModel.GetCountAsync(Filter.And.Equal(userId.ToString(), "IdentityId"));

            var outboxProcessIds = (await historyModel.GetAsync(Filter.And.Equal(userId, "ExecutorIdentityId"))).Select(e => (Guid)(e as dynamic).ProcessId).Distinct();
            var outboxCount      = outboxProcessIds.Count();

            await SendInboxOutboxCountNotification(userId, inboxCount, outboxCount);
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Execute(string name, string request)
        {
            try
            {
                var dictionary = JsonConvert.DeserializeObject <Dictionary <string, object> >(request);

                object objectRequest;

                if (dictionary.ContainsKey("data") && dictionary.ContainsKey("formName"))
                {
                    var formName = dictionary["formName"].ToString();

                    var model = await MetadataToModelConverter.GetEntityModelByFormAsync(formName, new BuildModelOptions(ignoreNameCase : true, strategy : BuildModelStartegy.ForGet))
                                .ConfigureAwait(false);

                    dictionary.TryGetValue("parameters", out var parameters);
                    dictionary.TryGetValue("modalId", out var modalId);

                    if (parameters is JObject parametersJObject)
                    {
                        var parametersDictionary = JsonConvert.DeserializeObject <Dictionary <string, object> >(parametersJObject.ToString());
                        parameters = new DynamicEntity(parametersDictionary);
                    }

                    objectRequest = new ServerCodeActionRequest
                    {
                        Data       = new DynamicEntityDeserializer(model).DeserializeSingle(dictionary["data"].ToString()),
                        FormName   = formName,
                        Parameters = parameters,
                        ModalId    = modalId?.ToString()
                    };
                }
                else
                {
                    objectRequest = new DynamicEntity(dictionary);
                }

                var actionResult = await DWKitRuntime.ServerActions.ExecuteActionAsync(name, objectRequest).ConfigureAwait(false);

                if (actionResult is DynamicEntity de)
                {
                    return(Json(new SuccessResponse(new { data = de.ToDictionary() })));
                }

                return(Json(new SuccessResponse(actionResult)));
            }
            catch (Exception e)
            {
                return(Json(new FailResponse(e)));
            }
        }
Ejemplo n.º 8
0
        public static async Task NotifyClientsAboutInboxStatus(List <string> userIds)
        {
            var inboxModel = await MetadataToModelConverter.GetEntityModelByModelAsync("WorkflowInbox");

            var historyModel = await MetadataToModelConverter.GetEntityModelByModelAsync("WorkflowProcessTransitionHistory");

            var inboxes = await inboxModel.GetAsync(Filter.And.In(userIds, "IdentityId"));

            var outboxes = await historyModel.GetAsync(Filter.And.In(userIds, "ExecutorIdentityId"));

            foreach (var id in userIds)
            {
                var inboxCount  = inboxes.Count(i => (i as dynamic).IdentityId == id);
                var outboxCount = outboxes.Where(i => (i as dynamic).ExecutorIdentityId == id).Select(i => (Guid)(i as dynamic).ProcessId).Distinct().Count();
                await SendInboxOutboxCountNotification(id, inboxCount, outboxCount);
            }
        }
Ejemplo n.º 9
0
        public static async Task NotifyClientsAboutInboxStatus(string userId)
        {
            var inboxModel = await MetadataToModelConverter.GetEntityModelByModelAsync("WorkflowInbox");

            var historyModel = await MetadataToModelConverter.GetEntityModelByModelAsync("WorkflowProcessTransitionHistory");

            long inboxCount = string.IsNullOrWhiteSpace(userId) ? 0L : await inboxModel.GetCountAsync(Filter.And.Equal(userId, "IdentityId"));

            long outboxCount = 0L;

            if (!string.IsNullOrWhiteSpace(userId))
            {
                var outboxProcessIds = (await historyModel.GetAsync(Filter.And.Equal(userId, "ExecutorIdentityId"))).Select(e => (Guid)(e as dynamic).ProcessId).Distinct();
                outboxCount = outboxProcessIds.Count();
            }

            var docModel = await MetadataToModelConverter.GetEntityModelByModelAsync("Document");

            var docCount = await docModel.GetCountAsync(Filter.Empty);

            await SendInboxOutboxCountNotification(userId, docCount, inboxCount, outboxCount);
        }
Ejemplo n.º 10
0
        private async Task UpdateTransitionHistoryAsync(ProcessInstance processInstance, WorkflowRuntime runtime, string actionParameter, CancellationToken token)
        {
            if (string.IsNullOrEmpty(processInstance.CurrentCommand))
            {
                return;
            }

            var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.CurrentState);

            var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.ExecutedActivityState);

            var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId, processInstance.CurrentCommand);

            var isTimer = !string.IsNullOrEmpty(processInstance.ExecutedTimer);

            var historyModel = await MetadataToModelConverter.GetEntityModelByModelAsync("DocumentTransitionHistory");

            var existingModel = (await historyModel.GetAsync(Filter.And.Equal(processInstance.ProcessId, "DocumentId").Equal(Null.Value, "TransitionTime")
                                                             .Equal(currentstate, "InitialState").Equal(nextState, "DestinationState"))).FirstOrDefault();

            if (existingModel == null)
            {
                existingModel = new DynamicEntity();
                var dynModel = existingModel as dynamic;
                dynModel.Id = Guid.NewGuid();
                dynModel.AllowedToEmployeeNames = string.Empty;
                dynModel.DestinationState       = nextState;
                dynModel.DocumentId             = processInstance.ProcessId;
                dynModel.InitialState           = currentstate;
            }

            var dm = existingModel as dynamic;

            dm.Command        = !isTimer ? command : string.Format("Timer: {0}", processInstance.ExecutedTimer);
            dm.TransitionTime = DateTime.Now;
            dm.EmployeeId     = !isTimer && !string.IsNullOrEmpty(processInstance.IdentityId) ? Guid.Parse(processInstance.IdentityId) : (Guid?)null;

            await historyModel.UpdateSingleAsync(existingModel);
        }
Ejemplo n.º 11
0
        public static async Task <IEnumerable <SearchItem> > GetAsync(string term)
        {
            if (string.IsNullOrWhiteSpace(term))
            {
                return(new List <SearchItem>());
            }

            var employeeFilter = Filter.Or
                                 .LikeRightLeft(term, "Name")
                                 .LikeRightLeft(term, "Email")
                                 .LikeRightLeft(term, "PhoneWork")
                                 .LikeRightLeft(term, "OtherEmail")
                                 .LikeRightLeft(term, "PhoneMobile")
                                 .LikeRightLeft(term, "Title");

            EntityModel employeeModel = await MetadataToModelConverter.GetEntityModelByModelAsync("Employee", 0);

            int countLimit = 20;
            var employee   = await employeeModel.GetAsync(employeeFilter);

            var res = employee.Select(c => new SearchItem()
            {
                Id    = c.Dictionary["Id"].ToString(),
                Type  = "employee",
                Text  = c.Dictionary["Name"] as string,
                Title = string.Format("{0} {1} {2}", c.Dictionary["Name"], c.Dictionary["Email"], c.Dictionary["Title"])
            }).Take(countLimit).ToList();

            if (employee.Count > countLimit)
            {
                res.Add(new SearchItem()
                {
                    Text  = "...",
                    Title = "..."
                });
            }

            return(res);
        }
Ejemplo n.º 12
0
        public static async Task <object> Generate(DateTime dateFrom, DateTime dateTo, string parameter, int period)
        {
            EntityModel employeeSalaryModel = await MetadataToModelConverter.GetEntityModelByModelAsync("EmployeeSalary", 0);

            var employees = await Employee.SelectAsync(Filter.Empty, Order.StartAsc("DepartmentName").Asc("LocationName").Asc("Name"));

            var employeeSalaryList = await employeeSalaryModel.GetAsync(Filter.Empty);

            DateTime start, end;

            if (period == 0)// month
            {
                start = new DateTime(dateFrom.Year, dateFrom.Month, 1);
                end   = new DateTime(dateTo.Year, dateTo.Month, 1).AddMonths(1).AddSeconds(-1);
            }
            else //year
            {
                start = new DateTime(dateFrom.Year, 1, 1, 0, 0, 0);
                end   = new DateTime(dateFrom.Year, 1, 1, 0, 0, 0).AddYears(1).AddSeconds(-1);
            }

            #region Documents
            EntityModel businessTripModel = await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.BusinessTrip, 1);

            EntityModel sickLeaveModel = await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.SickLeave, 1);

            EntityModel compensationModel = await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.Compensation, 1);

            EntityModel vacationModel = await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.Vacation, 1);

            var periodFilter = Filter.And.LessOrEqual(end, "DateStart").GreaterOrEqual(start, "DateEnd");
            var dateFilter   = Filter.And.GreaterOrEqual(start, "Date").LessOrEqual(end, "Date");

            var periodAndStateFilter = Filter.And.In(WorkflowReport.FinalStates, "State").Merge(periodFilter);
            var dateAndStateFilter   = Filter.And.In(WorkflowReport.FinalStates, "State").Merge(dateFilter);
            var businessTrips        = await businessTripModel.GetAsync(Filter.And.Equal("BusinessTrip", "Type").Merge(periodAndStateFilter));

            businessTrips.ForEach((item) =>
            {
                var i = (dynamic)item;
                if (!string.IsNullOrEmpty(i.Employees))
                {
                    i.EmployeesList = JsonConvert.DeserializeObject <List <Guid> >(i.Employees);
                }
            });

            var sickLeaves = await sickLeaveModel.GetAsync(DocumentTypes.GetFilter(DocumentTypes.SickLeave).Merge(periodAndStateFilter));

            var compensations = await compensationModel.GetAsync(DocumentTypes.GetFilter(DocumentTypes.Compensation).Merge(dateAndStateFilter));

            var vacations = await vacationModel.GetAsync(DocumentTypes.GetFilter(DocumentTypes.Vacation).Merge(periodAndStateFilter));

            #endregion

            var res = new List <Dictionary <string, object> >();
            foreach (var emp in employees)
            {
                var item = new Dictionary <string, object>();
                item["Id"]         = emp.Id;
                item["Department"] = emp.DepartmentName;
                item["Location"]   = emp.LocationName;
                item["Name"]       = emp.Name;
                item["Title"]      = emp.Title;

                DateTime currentDate = period == 0 ?
                                       new DateTime(dateFrom.Year, dateFrom.Month, 1) :
                                       new DateTime(dateFrom.Year, 1, 1);
                while (currentDate < dateTo)
                {
                    var key = period == 0 ? currentDate.ToString("MM/yy") : currentDate.ToString("yyyy") + "Y";
                    switch (parameter)
                    {
                    case "totalamount":
                        var salary       = GetSalary(emp, employeeSalaryList, currentDate, period);
                        var tax          = GetTax(emp, employeeSalaryList, currentDate, period);
                        var compensation = GetCompensation(emp.Id, compensations, currentDate, period);
                        item[key] = (salary + tax + compensation).ToString("N");
                        break;

                    case "salary":
                        item[key] = GetSalary(emp, employeeSalaryList, currentDate, period).ToString("N");
                        break;

                    case "tax":
                        item[key] = GetTax(emp, employeeSalaryList, currentDate, period).ToString("N");
                        break;

                    case "compensation":
                        item[key] = GetCompensation(emp.Id, compensations, currentDate, period).ToString("N");
                        break;

                    case "tripdays":
                        item[key] = GetTripDays(emp.Id, businessTrips, currentDate, period);
                        break;

                    case "sickleavedays":
                        item[key] = GetSickLeaveDays(emp.Id, sickLeaves, currentDate, period);
                        break;

                    case "vacationdays":
                        item[key] = GetVacationDays(emp.Id, vacations, currentDate, period);
                        break;
                    }
                    currentDate = period == 0 ? currentDate.AddMonths(1) : currentDate.AddYears(1);
                }

                res.Add(item);
            }

            return(res);
        }
Ejemplo n.º 13
0
        public async static Task <DashboardInfo> Generate()
        {
            var res               = new DashboardInfo();
            var employeeModel     = (await MetadataToModelConverter.GetEntityModelByModelAsync("Employee"));
            var businessTripModel = (await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.BusinessTrip));
            var CompensationModel = (await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.Compensation));

            if (DWKitRuntime.Security.CheckPermission("Dashboard", "ViewCompanyInfo"))
            {
                Filter notDraft = Filter.And.NotIn(WorkflowReport.DraftStates, "State");
                res.BusinessTripCount = await Document.GetDocumentTypeCountAsync(DocumentTypes.BusinessTrip, notDraft);

                res.SickLeaveCount = await Document.GetDocumentTypeCountAsync(DocumentTypes.SickLeave, notDraft);

                res.VacationCount = await Document.GetDocumentTypeCountAsync(DocumentTypes.Vacation, notDraft);

                res.CompensationCount = await Document.GetDocumentTypeCountAsync(DocumentTypes.Compensation, notDraft);

                res.RecruitmentCount = await Document.GetDocumentTypeCountAsync(DocumentTypes.Recruitment, notDraft);

                res.EmployeeReport = await EmployeeReport.GenerateForDashboard(DateTime.Now.AddMonths(-5), DateTime.Now);
            }

            if (DWKitRuntime.Security.CurrentUser != null)
            {
                #region For Users
                Guid   id = DWKitRuntime.Security.CurrentUser.Id;
                Filter userBusinessTripFilter = DocumentTypes.GetFilter(DocumentTypes.BusinessTrip).NotIn(WorkflowReport.DraftStates, "State").LikeRightLeft(id.ToString(), "Employees");
                var    trips = await businessTripModel.GetAsync(userBusinessTripFilter, Order.StartAsc("DateStart"));

                Filter userCompenstationFilter = DocumentTypes.GetFilter(DocumentTypes.Compensation).NotIn(WorkflowReport.DraftStates, "State").Equal(id, "EmployeeId");
                var    Compensations           = await CompensationModel.GetAsync(userCompenstationFilter);

                res.UserBusinessTripExpenses         = 0;
                res.UserBusinessTripExpensesApproved = 0;
                foreach (dynamic trip in trips)
                {
                    if (trip.Amount == null || trip.Amount == 0)
                    {
                        continue;
                    }

                    if (WorkflowReport.FinalStates.Contains(trip.State))
                    {
                        res.UserBusinessTripExpensesApproved += (decimal)trip.Amount;
                    }
                    else
                    {
                        res.UserBusinessTripExpenses += (decimal)trip.Amount;
                    }
                }

                res.UserCompensationAmount         = 0;
                res.UserCompensationAmountApproved = 0;
                foreach (dynamic c in Compensations)
                {
                    if (c.Amount == null || c.Amount == 0)
                    {
                        continue;
                    }

                    if (WorkflowReport.FinalStates.Contains(c.State))
                    {
                        res.UserCompensationAmountApproved += (decimal)c.Amount;
                    }
                    else
                    {
                        res.UserCompensationAmount += (decimal)c.Amount;
                    }
                }

                res.UserBusinessTrips = trips.Where(c => ((dynamic)c).DateEnd > DateTime.Now).Select(c => c.ToDictionary(true)).ToList();
                #endregion
            }

            return(res);
        }
Ejemplo n.º 14
0
        public static async Task <object> GenerateForDashboard(DateTime dateFrom, DateTime dateTo)
        {
            EntityModel employeeSalaryModel = await MetadataToModelConverter.GetEntityModelByModelAsync("EmployeeSalary", 0);

            var employees = await Employee.SelectAsync(Filter.Empty, Order.StartAsc("DepartmentName").Asc("LocationName").Asc("Name"));

            var employeeSalaryList = await employeeSalaryModel.GetAsync(Filter.Empty);

            DateTime start = new DateTime(dateFrom.Year, dateFrom.Month, 1);
            DateTime end   = new DateTime(dateTo.Year, dateTo.Month, 1).AddMonths(1).AddSeconds(-1);

            DateTime currentDate = new DateTime(dateFrom.Year, dateFrom.Month, 1);

            var labels       = new List <string>();
            var employeeData = new List <int>();
            var salaryData   = new List <decimal>();
            var taxData      = new List <decimal>();

            while (currentDate < dateTo)
            {
                var     item          = new Dictionary <string, object>();
                int     employeeCount = 0;
                decimal salary        = 0;
                decimal tax           = 0;

                foreach (var emp in employees)
                {
                    if (emp.DateJoin > currentDate || currentDate > emp.DateLeft)
                    {
                        continue;
                    }

                    employeeCount++;
                    salary += GetSalary(emp, employeeSalaryList, currentDate, 0);
                    tax    += GetTax(emp, employeeSalaryList, currentDate, 0);
                }

                labels.Add(currentDate.ToString("MM/yy"));
                employeeData.Add(employeeCount);
                salaryData.Add(salary);
                taxData.Add(tax);

                currentDate = currentDate.AddMonths(1);
            }

            return(new {
                labels,
                datasets = new List <object>()
                {
                    new {
                        label = "Employees",
                        borderColor = "#1362E2",
                        backgroundColor = "#1362E2",
                        fill = false,
                        data = employeeData,
                        yAxisID = "y-axis-1",
                    },
                    new {
                        label = "Salary",
                        borderColor = "#FB617D",
                        backgroundColor = "#FB617D",
                        fill = false,
                        data = salaryData,
                        yAxisID = "y-axis-2",
                    },
                    new {
                        label = "Tax",
                        borderColor = "#FEB64D",
                        backgroundColor = "#FEB64D",
                        fill = false,
                        data = taxData,
                        yAxisID = "y-axis-2",
                    }
                }
            });
        }
Ejemplo n.º 15
0
        public static async Task SideMenuInitialNotifier(string userId)
        {
            var userIdGuid = new Guid(userId);

            var tripFilter          = Document.GetViewFilterForUser(userIdGuid, await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.BusinessTrip));
            var sickLeaveFilter     = Document.GetViewFilterForUser(userIdGuid, await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.SickLeave));
            var vacationFilter      = Document.GetViewFilterForUser(userIdGuid, await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.Vacation));
            var compenstationFilter = Document.GetViewFilterForUser(userIdGuid, await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.Compensation));
            var recruitmentFilter   = Document.GetViewFilterForUser(userIdGuid, await MetadataToModelConverter.GetEntityModelByModelAsync(DocumentTypes.Recruitment));

            var status = new
            {
                businesstrip   = await Document.GetDocumentTypeCountAsync(DocumentTypes.BusinessTrip, tripFilter),
                sickleave      = await Document.GetDocumentTypeCountAsync(DocumentTypes.SickLeave, sickLeaveFilter),
                vacation       = await Document.GetDocumentTypeCountAsync(DocumentTypes.Vacation, vacationFilter),
                compensation   = await Document.GetDocumentTypeCountAsync(DocumentTypes.Compensation, compenstationFilter),
                recruitment    = await Document.GetDocumentTypeCountAsync(DocumentTypes.Recruitment, recruitmentFilter),
                employeeform   = DWKitRuntime.Security.CheckPermission(userIdGuid, "Employee", "View"),
                documentsform  = DWKitRuntime.Security.CheckPermission("Documents", "View"),
                workflowreport = DWKitRuntime.Security.CheckPermission("WorkflowReport", "View"),
                employeereport = DWKitRuntime.Security.CheckPermission("EmployeeReport", "View"),
                workcalendar   = DWKitRuntime.Security.CheckPermission("WorkCalendar", "View")
            };

            await DWKitRuntime.SendStateChangeToUserAsync(userId, SideMenuPath, status);
        }
Ejemplo n.º 16
0
        private async Task <bool> CheckBigBossMustSignAsync(ProcessInstance processInstance, WorkflowRuntime runtime, string actionParameter, CancellationToken token)
        {
            var documentModel = await MetadataToModelConverter.GetEntityModelByModelAsync("Document");

            return((await documentModel.GetCountAsync(Filter.And.Equal(processInstance.ProcessId, "Id").GreaterOrEqual(100, "Amount"))) > 0);
        }
Ejemplo n.º 17
0
        private static async Task ActivityChanged(ProcessActivityChangedEventArgs args, WorkflowRuntime runtime)
        {
            if (!args.TransitionalProcessWasCompleted)
            {
                return;
            }

            var historyModel = await MetadataToModelConverter.GetEntityModelByModelAsync("DocumentTransitionHistory");

            var emptyHistory = (await historyModel.GetAsync(Filter.And.Equal(Null.Value, "EmployeeId").Equal(args.ProcessId, "DocumentId")
                                                            .Equal(Null.Value, "TransitionTime"))).Select(h => h.GetId()).ToList();
            await historyModel.DeleteAsync(emptyHistory);

            await runtime.PreExecuteFromCurrentActivityAsync(args.ProcessId);

            var nextState     = WorkflowInit.Runtime.GetLocalizedStateName(args.ProcessId, args.ProcessInstance.CurrentState);
            var documentModel = await MetadataToModelConverter.GetEntityModelByModelAsync("Document");

            var document = (await documentModel.GetAsync(Filter.And.Equal(args.ProcessId, "Id"))).FirstOrDefault() as dynamic;

            if (document == null)
            {
                return;
            }

            document.StateName = nextState;
            document.State     = args.ProcessInstance.CurrentState;
            await documentModel.UpdateSingleAsync(document as DynamicEntity);

            var newActors = await Runtime.GetAllActorsForDirectCommandTransitionsAsync(args.ProcessId);

            var newInboxes = new List <dynamic>();

            foreach (var newActor in newActors)
            {
                var newInboxItem = new DynamicEntity() as dynamic;
                newInboxItem.Id         = Guid.NewGuid();
                newInboxItem.IdentityId = newActor;
                newInboxItem.ProcessId  = args.ProcessId;
                newInboxes.Add(newInboxItem);
            }

            var userIdsForNotification = new List <string>();

            userIdsForNotification.AddRange(newInboxes.Select(a => (string)(a as dynamic).IdentityId));

            var inboxModel = await MetadataToModelConverter.GetEntityModelByModelAsync("WorkflowInbox");

            using (var shared = new SharedTransaction())
            {
                await shared.BeginTransactionAsync();

                var existingInbox = (await inboxModel.GetAsync(Filter.And.Equal(args.ProcessId, "ProcessId")));
                userIdsForNotification.AddRange(existingInbox.Select(a => (string)(a as dynamic).IdentityId));
                var existingInboxIds = existingInbox.Select(i => i.GetId()).ToList();
                await inboxModel.DeleteAsync(existingInboxIds);

                await inboxModel.InsertAsync(newInboxes);

                await shared.CommitAsync();
            }

            userIdsForNotification = userIdsForNotification.Distinct().ToList();
            Func <Task> task = async() => { await ClientNotifiers.NotifyClientsAboutInboxStatus(userIdsForNotification); };

            task.FireAndForgetWithDefaultExceptionLogger();
        }
Ejemplo n.º 18
0
        public async Task <ActionResult> Execute(string name, string request, bool useServerCodeActionRequest = false, bool mobile = false)
        {
            try
            {
                if (!await DWKitRuntime.Security.CheckCodeActionPermissionAsync(name, true))
                {
                    throw new Exception("Access denied!");
                }

                var dictionary = JsonConvert.DeserializeObject <Dictionary <string, object> >(request);

                object objectRequest;

                if (useServerCodeActionRequest)
                {
                    var           formName = dictionary.ContainsKey("formName") ? dictionary["formName"]?.ToString() : null;
                    DynamicEntity data     = null;
                    if (!string.IsNullOrEmpty(formName))
                    {
                        var model = await MetadataToModelConverter.GetEntityModelByFormAsync(formName, new BuildModelOptions(ignoreNameCase : true, strategy : BuildModelStartegy.ForGet, mobile : mobile))
                                    .ConfigureAwait(false);

                        if (model.Attributes.Any())
                        {
                            data = new DynamicEntityDeserializer(model).DeserializeSingle(dictionary["data"]
                                                                                          .ToString());
                        }
                    }

                    if (data == null)
                    {
                        data = DynamicEntity.ParseJSON(dictionary["data"]?.ToString());
                    }

                    dictionary.TryGetValue("parameters", out var parameters);
                    dictionary.TryGetValue("modalId", out var modalId);

                    if (parameters is JObject parametersJObject)
                    {
                        var parametersDictionary = JsonConvert.DeserializeObject <Dictionary <string, object> >(parametersJObject.ToString());
                        parameters = new DynamicEntity(parametersDictionary);
                    }

                    objectRequest = new ServerCodeActionRequest
                    {
                        Data       = data,
                        FormName   = formName,
                        Parameters = parameters,
                        ModalId    = modalId?.ToString()
                    };
                }
                else
                {
                    objectRequest = new DynamicEntity(dictionary);
                }

                var actionResult = await DWKitRuntime.ServerActions.ExecuteActionAsync(name, objectRequest).ConfigureAwait(false);

                if (actionResult is DynamicEntity de)
                {
                    return(Json(new SuccessResponse(new { data = de.ToDictionary(true) })));
                }

                return(Json(new SuccessResponse(actionResult)));
            }
            catch (Exception e)
            {
                return(Json(new FailResponse(e)));
            }
        }