implementing crm with laravel tasks module

Implementing CRM System With Laravel Part 9: Tasks Module

When we do some stuff with contacts like meetings and phone calls we need to record those events, events like this are called tasks in the context of the CRM system and we will implement it in this part.

 

 

Series Topics:

 

Generating the views:

Generating the controller:

 

Tasks Controller

Open app/Http/Controllers/TasksController.php and update it as below:

The code structure shown above is pretty similar to the previous modules. First in the constructor i have added the admin middleware and the actions and their permission names using the format [action-permission] separated by “|”. I have injected the Mailer into the constructor to be used later when sending emails.

The index() function displays the tasks listing and checks on whether this is the super admin with “Auth::user()->is_admin==0”, if the user is not the super admin is displays the tasks that he is assigned to or created by. If this is the super admin we don’t add this restriction.

The create() and edit() functions show the create and update forms respectively. I have added another function getFormData() which retrieves the form data like the documents and users to be used in form dropdown.  The getFormData() function retrieves a lot of items like the users, task statuses, tasks types, contact statuses and documents.

The store() and update() functions do the create or update process respectively.In the store() function we insert the data as usual then we check if the “enable_email_notification” is on and send an email to the user to notify him that he assigned to this task.

In the update() function we update the task and then also we check if the “enable_email_notification” is on then we send an email to the assigned user if this is a new user and send other email to notify him about the task status in case the task have been updated status.

The destroy() delete the task as usual, the getAssignTask() and postAssignTask() functions do assigns a task to a user and send an email to notify the user. The getUpdateStatus() and postUpdateStatus() functions update the task status and also notifies the user of this update.

Tasks Views

Make the following updates to the below view files:

resources/views/pages/tasks/index.blade.php

resources/views/pages/tasks/create.blade.php

resources/views/pages/tasks/edit.blade.php

resources/views/pages/tasks/form.blade.php

resources/views/pages/tasks/show.blade.php

resources/views/pages/tasks/update_status.blade.php

resources/views/pages/tasks/assign.blade.php

I have made a lot of updates to the above files. At first i have adjusted the permissions, this can be seen in the index view file using the user_can() function. Also i have updated the form UI and updated the inputs such as the dropdowns for contact type and contact id.

The contact name dropdown will be filled by ajax when the user select a contact type, we will see the task javascript file below.

 

Tasks Javascript Code

public/theme/views/tasks/form.js

In the above code we initialized the “#documents” selector with select2 plugin, then we initialized the datepickers. then i added a function to be triggered when the contact name dropdown field get changed which is getContacts(), this function make an ajax request to the contacts controller to retrieve the contacts by the status.

 

Update the contacts controller

Now update the contacts controller and add this function at the end of the controller:

Modify app/Helpers/MailerFactory.php add these functions at the end of the class

resources/views/emails/assign_task.blade.php

resources/views/emails/update_task_status.blade.php

resources/views/emails/delete_task.blade.php

 

Updating routes

 

Updating the sidebar

Now let’s update the sidebar with tasks module

resources/views/layout/sidebar.blade.php

Updating the user profile

To finish this part we will conclude by updating the view user profile page to include the tasks assigned to the currently logged in user:

resources/views/pages/users/profile/view.blade.php

 

 

Continue to Part 10: Mailbox module

 

Share this: