anoop
anoop

Reputation: 1614

How to create multi-level workflow in php?

I need to create a multi level approval form in php web application. Basically we have different requisition for each requisition there is different level of people who needs to approve. Once the form submitted by the creator the notification has to go to 1st assigner when st assigner approves this the 2nd assigner has to approve. this can be any level and it should dynamic. What is the best procedure to implement this in php. We are writing the application in laravel 5.3 framework and mysql.

Upvotes: 1

Views: 3963

Answers (1)

Tek
Tek

Reputation: 499

You could just store the form data in a table with a field for the current approval level and based on this level show it to the right people.

To notify the different people for forms that need approval, you could fire an event when the form is submitted (meaning: when it goes to the next approval level) and then send an email, or however you like to notify the people.

Update

For the database I would create a table named "requisitions", that contains columns for all the form fields the requisition needs and also two additional ones: level, type. Level could be an integer that and I also would use this for the type column (and "cast" this to a descriptive text in the app).

To map the users to the different types you have also many options to do so. The easiest one regarding querying for relevant user requisitions would be to add a "user_can_approve" table, like that:

user_id     requisition_type     requisition_level
1           2                    2
2           1                    1
2           2                    1
2           3                    1
3           2                    2

(means:

  • user with id 1 can approve requisitions of type 2 that are on level 2
  • user with id 2 can approve requisitions of type 1 that are on level 1
  • user with id 2 can approve requisitions of type 2 that are on level 1
  • and so on...

Then you can query for the relevant requisitions for a specific user like this:

SELECT r.`id` 
FROM `requisitions` r JOIN `users` u JOIN `user_can_approve` uca 
  ON 
    u.`id` = uca.`user_id` 
  AND 
    r.`type` = uca.`requisition_type` 
  AND 
    r.`level` = uca.`requisition_level` 
WHERE uca.`user_id`=$currentUsersID

Upvotes: 3

Related Questions