예제 #1
0
        public IHttpActionResult DoInvoiceWorkflowAction(InvoicesApprovalWorkflow workflow)
        {
            if (workflow == null)
            {
                return(BadRequest("workflow object must be passed in the request body"));
            }
            try
            {
                var wfProcessor = new InvoiceWorkflowProcessor();
                var dbWorkflow  = wfProcessor.ChangeWorkflowStageAction(workflow.Id, (int)workflow.Status, workflow.Remarks, User.FullName);

                var currentStageOrderNumber = workflowService.
                                              GetWorkflowStage(dbWorkflow.StageId).
                                              StageOrderNumber;

                var nextStageSerialNumber = currentStageOrderNumber + 1;
                var nextStage             = workflowService.GetWorkflowStages().SingleOrDefault(w => w.StageOrderNumber == nextStageSerialNumber);

                if (nextStage != null)
                {
                    var nextPaymentWorkflow = new InvoicesApprovalWorkflow()
                    {
                        CreatedBy       = User.UserId,
                        CreatedDate     = DateTime.Now,
                        IsActive        = true,
                        InvoiceId       = dbWorkflow.InvoiceId,
                        ProcessedDate   = null,
                        StageId         = nextStage.StageId,
                        Status          = (int)WorkflowLevelStatus.Forwarded,
                        Remarks         = null,
                        IsFinished      = false,
                        ReferenceNumber = "",
                        SequentialId    = nextStageSerialNumber
                    };
                    wfProcessor.ForwardNextStage(nextPaymentWorkflow, nextStage);
                }
                else
                {
                    var taskId = invoicesService.GetInvoice(workflow.InvoiceId).MilestoneId;
                    TasksHandler.Finish(taskId);
                }

                var workflows = invoicesService.GetUserInvoiceWorkflow(User.UserId).Where(l => l.InvoiceId == dbWorkflow.InvoiceId);
                var html      = Helpers.RenderPartial("~/Views/Shared/Partial/Invoices/InvoiceWorkflowList.cshtml", workflows);
                return(Ok(html));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
예제 #2
0
        // GET: Financial
        public ActionResult Invoices()
        {
            var viewModel = new InvoicesListViewModel();

            viewModel.Invoices  = invoicesService.GetInvoices().ToList();
            viewModel.Workflows = invoicesService.GetUserInvoiceWorkflow(User.UserId).ToList();

            ViewData["InvoicesManagement"] = "active";
            return(View(viewModel));
        }
        public ActionResult Dashboard()
        {
            ViewData["dashboardPage"] = "active";

            var viewModel = new DashboardViewModel();

            var userInvoicesWorkflows = invoicesService.GetUserInvoiceWorkflow(User.UserId).ToList();
            var userLeasesWorkflows   = leaseContractsService.GetUserLeasePaymentWorkflow(User.UserId);

            var finishedActionInvoices = userInvoicesWorkflows.Where(i => i.IsFinished).Take(5).Select(i => new KanbanBoardWorkflowTask()
            {
                LastNotes        = i.Remarks,
                ObjectNumber     = i.InvoiceNumber,
                ProcessedDate    = i.ProcessedDate,
                URL              = Url.Action("InvoiceDetails", "Financial", new { id = i.InvoiceId }),
                WorkflowId       = i.Id,
                WorkflowItemType = Core.WorkflowType.Invoice
            }).ToList();
            var ongoingInvoices = userInvoicesWorkflows.Where(i => !i.IsFinished).Take(5).Select(i => new KanbanBoardWorkflowTask()
            {
                LastNotes        = i.Remarks,
                ObjectNumber     = i.InvoiceNumber,
                ReceivedDate     = i.CreatedDate,
                URL              = Url.Action("InvoiceDetails", "Financial", new { id = i.InvoiceId }),
                WorkflowId       = i.Id,
                WorkflowItemType = Core.WorkflowType.Invoice
            }).ToList();
            var needActionInvoices = invoicesService.GetNotFinishedUserInvoiceWorkflow(User.UserId).Select(i => new KanbanBoardWorkflowTask()
            {
                LastNotes        = i.Remarks,
                ObjectNumber     = i.InvoiceNumber,
                ReceivedDate     = i.CreatedDate,
                URL              = Url.Action("InvoiceWorkflowAction", "Financial", new { id = i.Id }),
                WorkflowId       = i.Id,
                WorkflowItemType = Core.WorkflowType.Invoice
            }).ToList();

            var finishedActionLeases = userLeasesWorkflows.Where(i => i.IsFinished).Take(5).Select(i => new KanbanBoardWorkflowTask()
            {
                LastNotes        = i.Remarks,
                ObjectNumber     = i.LeaseContractNumber,
                ProcessedDate    = i.ProcessedDate,
                URL              = Url.Action("LeaseWorkflowAction", "Contracts", new { id = i.Id }),
                WorkflowId       = i.Id,
                WorkflowItemType = Core.WorkflowType.Lease
            }).ToList();
            var ongoingLeases = userLeasesWorkflows.Where(i => !i.IsFinished).Take(5).Select(i => new KanbanBoardWorkflowTask()
            {
                LastNotes        = i.Remarks,
                ObjectNumber     = i.LeaseContractNumber,
                ReceivedDate     = i.CreatedDate,
                URL              = Url.Action("LeaseWorkflowAction", "Contracts", new { id = i.Id }),
                WorkflowId       = i.Id,
                WorkflowItemType = Core.WorkflowType.Lease
            }).ToList();
            var needActionLeases = userLeasesWorkflows.Where(i => !i.IsFinished).Take(5).Select(i => new KanbanBoardWorkflowTask()
            {
                LastNotes        = i.Remarks,
                ObjectNumber     = i.LeaseContractNumber,
                ReceivedDate     = i.CreatedDate,
                URL              = Url.Action("LeaseWorkflowAction", "Contracts", new { id = i.Id }),
                WorkflowId       = i.Id,
                WorkflowItemType = Core.WorkflowType.Lease
            }).ToList();

            var finished = new List <KanbanBoardWorkflowTask>();

            finished.AddRange(finishedActionInvoices);
            finished.AddRange(finishedActionLeases);
            var ongoing = new List <KanbanBoardWorkflowTask>();

            ongoing.AddRange(ongoingInvoices);
            ongoing.AddRange(ongoingLeases);
            var needAction = new List <KanbanBoardWorkflowTask>();

            needAction.AddRange(needActionInvoices);
            needAction.AddRange(needActionLeases);

            viewModel.FinishedTasks   = finished.OrderByDescending(k => k.ProcessedDate).ToList();
            viewModel.OngoingTasks    = ongoing.OrderByDescending(k => k.ProcessedDate).ToList();
            viewModel.NeedActionTasks = needAction.OrderByDescending(k => k.ReceivedDate).ToList();;

            return(View(viewModel));
        }