Esempio n. 1
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",
                    }
                }
            });
        }
Esempio n. 2
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();
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }