Пример #1
0
        public static Boolean routeIndividual(TNF tnf)
        {
            User               currentUser        = tnf.getUser();
            UserDAO            userDAO            = new UserDAO();
            Workflow           currentWorkflow    = wfDAO.getCurrentActiveWorkflow();
            int                numOfCriteria      = wfDAO.getNumberOfCriteriaByWorkflow(currentWorkflow.getWorkflowID());
            string             currentStatusOfTNF = tnf.getStatus();
            List <WorkflowSub> workflowSubs       = wfsDAO.getSortedWorflowSubByWorkflow(currentWorkflow.getWorkflowID());
            float              tnfTotalCost       = 0.0F; //to get from tnfDAO and to confirm if gst is included in the fee of consideration

            if (currentStatusOfTNF.Equals("Pending"))
            {
                for (int i = 0; i < numOfCriteria; i++)
                {
                    WorkflowSub             currentWFS = workflowSubs[i];
                    float                   low_limit  = currentWFS.getAmount_low();
                    float                   high_limit = currentWFS.getAmount_high();
                    List <WorkflowApprover> approvers  = wfaDAO.getSortedWorkflowApprovers(currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());
                    if (tnfTotalCost >= low_limit && tnfTotalCost <= high_limit)
                    {
                        WorkflowApprover currentWFApprover = approvers[tnf.getWFStatus()];
                        User             approver          = currentWFApprover.getApprover();
                        //to check if applicant's level is higher than approver's level (need to write another function to check)
                        if (currentUser != approver)
                        {
                            //sendApprovalNotification(tnf, approver);
                            return(true);
                        }
                        else
                        {
                            //do something if applicant is approver
                        }
                    }
                }

                //check bond criteria
                float bondCriteria = currentWorkflow.getBondCriteria();
                if (tnfTotalCost >= bondCriteria)
                {
                    //create new bond object
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        public static Boolean routeIndividual(TNF tnf)
        {
            User     currentUser     = tnf.getUser();
            UserDAO  userDAO         = new UserDAO();
            Workflow currentWorkflow = wfDAO.getCurrentActiveWorkflow("individual");
            //int numOfCriteria = wfDAO.getNumberOfCriteriaByWorkflow(currentWorkflow.getWorkflowID());
            string   currentStatusOfTNF = tnf.getStatus();
            int      probationPeriod    = currentWorkflow.getProbationPeriod();
            TimeSpan ts            = DateTime.Now.Subtract(currentUser.getStartDate());
            Course   currentCourse = tnfDAO.getCourseFromTNF(tnf.getTNFID());

            List <WorkflowSub> workflowSubs;

            if (ts.TotalDays < probationPeriod)
            {
                workflowSubs = wfsDAO.getSortedWorflowSubByWorkflowIDandType(currentWorkflow.getWorkflowID(), "ceo");
            }
            else if (currentCourse.getOverseas().Equals("y"))
            {
                workflowSubs = wfsDAO.getSortedWorflowSubByWorkflowIDandType(currentWorkflow.getWorkflowID(), "ceo");
            }
            else
            {
                workflowSubs = wfsDAO.getSortedWorflowSubByWorkflowIDandType(currentWorkflow.getWorkflowID(), "normal");
            }

            double tnfTotalCost = tnfDAO.getCourseFromTNF(tnf.getTNFID()).getPrice(); //to get from tnfDAO and to confirm if gst is included in the fee of consideration

            if (currentStatusOfTNF.Equals("pending"))
            {
                //check bond criteria
                double bondCriteria = currentWorkflow.getBondCriteria();
                if (tnfTotalCost >= bondCriteria)
                {
                    //create new bond object
                    BondDAO  bondDAO       = new BondDAO();
                    Bonds    newBond       = new Bonds(currentUser.getUserID(), tnf.getTNFID(), "pending");
                    int      bondID        = bondDAO.createBond(newBond);
                    DateTime bondStartDate = currentCourse.getEndDate();
                    bondStartDate = bondStartDate.AddDays(1);
                    bondDAO.updateBondStartDate(bondID, bondStartDate);
                }

                for (int i = 0; i < workflowSubs.Count; i++)
                {
                    if (wfsDAO.getWorkflowSubType(workflowSubs[i].getWorkflowSubID()).Equals("superior"))
                    {
                        i = 0;
                    }
                    WorkflowSub             currentWFS = workflowSubs[i];
                    double                  low_limit  = currentWFS.getAmount_low();
                    double                  high_limit = currentWFS.getAmount_high();
                    List <WorkflowApprover> approvers  = wfaDAO.getSortedWorkflowApprovers(currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());
                    if (tnfTotalCost >= low_limit && tnfTotalCost <= high_limit)
                    {
                        WorkflowApprover currentWFApprover        = approvers[tnf.getWFStatus()];
                        string           currentUser_job_category = currentUser.getJobCategory();
                        WorkflowApprover checkApprover            = wfaDAO.getWorkflowApproverByJobCategory(currentUser_job_category, currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());
                        Boolean          checkIfLevelHigher       = checkJobLevelHigher(currentUser_job_category, currentWFApprover.getJobCategory());
                        //to check if applicant's level is higher than approver's level (need to write another function to check)
                        WorkflowApprover lastWFApprover = wfaDAO.getLastApproverInChain(currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());
                        int levelOfUser = wfaDAO.getLevelByJobCategory(currentUser.getJobCategory(), currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());
                        if (checkApprover.getJobCategory() == null)
                        {
                            if (!checkIfLevelHigher)
                            {
                                tnfDAO.updateTNFWFSub(tnf.getTNFID(), currentWFS.getWorkflowSubID());
                                sendApprovalNotification(tnf, currentWFApprover);
                                return(true);
                            }
                            else
                            {
                                Boolean checkIfLevelHigherThanLastApprover = checkJobLevelHigher(currentUser_job_category, lastWFApprover.getJobCategory());
                                if (!checkIfLevelHigherThanLastApprover)
                                {
                                    for (int j = 0; i < approvers.Count; j++)
                                    {
                                        Boolean checkLevelWithCurrentApprover = checkJobLevelHigher(currentUser_job_category, approvers[j].getJobCategory());
                                        if (checkLevelWithCurrentApprover)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            WorkflowApprover nextWFApprover = approvers[j];
                                            tnfDAO.updateTNFWFStatus(tnf.getTNFID(), j);
                                            tnfDAO.updateTNFWFSub(tnf.getTNFID(), currentWFS.getWorkflowSubID());
                                            sendApprovalNotification(tnf, nextWFApprover);
                                            return(true);
                                        }
                                    }
                                }
                                else
                                {
                                    workflowSubs = wfsDAO.getSortedWorflowSubByWorkflowIDandType(currentWorkflow.getWorkflowID(), "superior");
                                }
                            }
                        }
                        else
                        {
                            if (!currentUser.getJobCategory().Equals("ceo"))
                            {
                                if (levelOfUser < lastWFApprover.getLevel())
                                {
                                    WorkflowApprover nextWFApprover = approvers[levelOfUser + 1];
                                    tnfDAO.updateTNFWFSub(tnf.getTNFID(), currentWFS.getWorkflowSubID());
                                    tnfDAO.updateTNFWFStatus(tnf.getTNFID(), levelOfUser + 1);
                                    sendApprovalNotification(tnf, nextWFApprover);
                                    return(true);
                                }
                                else
                                {
                                    //handle last person in chain
                                    workflowSubs = wfsDAO.getSortedWorflowSubByWorkflowIDandType(currentWorkflow.getWorkflowID(), "superior");
                                }
                            }
                            else
                            {
                                //no need handle CEO
                            }
                        }
                    }
                }
            }
            return(false);
        }