Byg dig selv en simpel CRM fra bunden i PHP og MySQL

Customer Relationship Management (CRM) er et system, der styrer kundeinteraktioner og data i hele kundens livscyklus mellem kunden og virksomheden på tværs af forskellige kanaler. I denne vejledning skal vi oprette en brugerdefineret CRM i PHP, som et salgsteam kan bruge til at spore kunder gennem hele salgscyklussen.

Vi opretter et simpelt CRM-system for sælgere til at:

  • Få adgang til deres opgaver
  • Se deres kundeemner
  • Opret nye opgaver for hver kundeemne
  • Opret ny mulighed
  • Luk et salg

Salgschefer vil være i stand til at:

  • Administrer alle kunder
  • Administrer salgsteamet
  • Se aktuelle salgsaktiviteter

Download demo-filer

Byggesten i en CRM

Her er en liste over de vigtige komponenter i CRM:

  • Leads : indledende kontakter
  • Konti : Oplysninger om de virksomheder, du handler med
  • Kontakt : Oplysninger om de mennesker, du kender og arbejder sammen med. Normalt har en konto mange kontakter
  • Muligheder : Kvalificerede kundeemner
  • Aktiviteter : Opgaver, møder, telefonopkald, e-mails og andre aktiviteter, der giver dig mulighed for at interagere med kunder
  • Salg : Dit salgsteam
  • Dashboard : CRM-dashboards er meget mere end bare eye candy. De skal levere nøgleoplysninger på et øjeblik og give links til at bore ned for flere detaljer.
  • Login : Sælgere og ledere har forskellige roller i systemet. Ledere har adgang til rapporter og oplysninger om salgspipeline.

Systemkrav

  • PHP 5.3+,
  • MySQL eller MariaDB
  • phpGrid

Opret CRM-database

Vi starter med at oprette vores brugerdefinerede CRM-database. De vigtigste tabeller, vi vil bruge, er:

  • kontakt - indeholder grundlæggende kundedata
  • noter - besidder informationsindsamling fra Contact af sælgere.
  • brugere - oplysninger om sælgere

Den Kontakt Tabellen indeholder grundlæggende kundeoplysninger, herunder navne, firmaadresser, projektinformation, og så videre.

De Notes tabel gemmer alle salgsaktiviteter oplysninger såsom møder og telefonopkald.

Den Brugere Tabellen rummer login-oplysninger om brugere af systemet såsom brugernavne og passwords. Brugere kan også have roller, såsom salg eller manager.

Alle andre tabeller er opslagstabeller for at slutte sig til de tre vigtigste relationsdatabasetabeller.

  • contact_status - indeholder kontaktstatus såsom Lead og Opportunity. Hver angiver et andet trin i en typisk salgscyklus
  • task_status - opgavens status kan enten være afventende eller afsluttet
  • user_status - en salgsperson kan være aktiv eller inaktiv
  • todo_type - en type opgave enten opgave eller møde
  • todo_desc - beskrivelse af en opgave som opfølgnings-e-mail, telefonopkald og konference osv.
  • roller - en bruger kan enten være en salgsrepræsentant eller en manager

Komplet databaseskema diagram

Et databaseskema er den struktur, der repræsenterer den logiske visning, såsom tabeller, visninger eller primære og fremmede nøgler i hele databasen. Et databaseskema inkluderer enheder og forholdet mellem dem.

Det er en god praksis at have en primær nøgle til hver tabel i en relationsdatabase. En primær nøgle er en unik identifikator for hver post. Det kan være socialsikringsnummeret (SSN), køretøjets identifikationsnummer (VIN) eller auto-stigningsnummeret. Dette er et unikt nummer, der genereres, når en ny post indsættes i en tabel.

Nedenfor er databasediagrammet over vores enkle CRM. Nøglesymbolet i hver tabel repræsenterer tabelens primære nøgle. Forstørrelsesglasset angiver fremmed nøgle, der forbinder en anden tabel i databasen. Nogle gange kalder vi det "opslagstabellen".

install.sql

Når du først har forståelse for databasetabellens struktur, skal du finde scriptet “install.sql” i dbmappen og bruge et MySQL-værktøj såsom MySQL Workbench eller Sequel Pro til at køre SQL-scriptet. Det skal oprette en ny relationsdatabase med navnet custom_crmog dens databasetabeller.

En sidebemærkning om ZenBase

The CRM application is also one of the many application templates readily available at ZenBase (built on the top of phpGrid) for anyone — with or without coding skills — to use and customize for their own needs.

Opsætning af phpGrid

Our CRM contains many datagrids. The datagrid is a spreadsheet-like data table that displays rows and columns representing records and fields from the database table. The datagrid gives the end-user ability to read and write to database tables on a webpage. We can use a datagrid tool from phpGrid. We use a tool instead of building them from scratch because developing the datagrid is usually tedious and error-prone. The datagrid library will handle all internal database CRUD (Create, Remove, Update, and Delete) operations for us with better and faster results with little code. To install phpGrid, follow these steps:

  1. Unzip the phpGrid download file.
  2. Upload the phpGrid folder to the phpGrid folder.
  3. Complete the installation by configuring the conf.php file.

Before we begin coding, we must specify the database information in conf.php, the phpGrid configuration file. Here is an example of database connection settings:

  • PHPGRID_DB_HOSTNAME — web server IP or host name
  • PHPGRID_DB_USERNAME — database user name
  • PHPGRID_DB_PASSWORD — database password
  • PHPGRID_DB_NAME — database name of our CRM
  • PHPGRID_DB_TYPE — type of database
  • PHPGRID_DB_CHARSET — always ‘utf8’ in MySQL

To learn more about configuring phpGrid, check out phpGrid complete installation guide.

Page Template

Before we can start building our first page of the CRM, it is a good practice to make the reusable page items such as header and footer.

The page will comprise of a header, menu, body and footer. We will start by creating a reusable page template.

head.php

This is a basic HTML5 template header. It includes a link to a custom stylesheet that will be created in a later step.

menu.php

Notice the usage of $_GET['currentPage']. Each page will set a value which will highlight the name of the current page on the top menu bar.

Include the following code in style.css for menu styling (minified). It will transform the above, unordered list into a menu.

footer.php

Simple closing body and html tags.

Complete Page Template

This is the complete page template. The main content will go after Section Title.

CRM Main Pages

Are you still with me? Good! We can now finally develop the first page in our CRM.

Our CRM for the sales team members has four pages:

  • Tasks
  • Leads
  • Opportunities
  • Customers/Won

Each page indicates a different stage in a typical sales cycle.

Sale People Page Design Mockup

Here’s our CRM design mockup for the sales people.

Tasks Page

When a sales team member logged in, the first page he sees is a list of current tasks.

As you may recall, our Notes table holds all the sales activity information. We can create a datagrid and populate it from the Notes table using phpGrid.

The Tasks page main content is a datagrid. The following two lines will give us a list of tasks of the current sales person.

  • The first line creates a phpGrid object by passing the SELECT SQL statement, its primary key — ID, and then the name of the database table - notes.
  • The second and the final line calls display() function to render the datagrid on the screen. Check out the basic datagrid demo for more detail.

Leads Page

The leads page contains list of current leads that the sales person is responsible for. Each Lead can have one or many Notes. We will use the phpGrid master-detail feature for that.

We also need to use set_query_filter() to display only the leads, Status = 1, and only for the current sales person.

Contact status table

Opportunities Page

A Lead becomes an Opportunity once it is qualified. The Opportunities page is similar to the Leads page. The only difference is the filtered status code in set_query_filter is Status = 2.

Customers/Won Page

Customers/Won has the Status = 3. Similar to Leads and Opportunities, Customers/Won can also have Notes.

That’s all there is to it for sales people in our simple CRM.

Manager Dashboard

The sales manager will have access to all records in the sales pipeline as well as the ability to manage sales team and customer data.

We will have a single web page with tabbed menu similar to the phpGrid tabbed grid demo.

Manager Dashboard Design Mockup

My Sales Reps

Main content

Each tab represents a table in the CRM database. $_GET['gn'] will store the table name. It dynamically generates the datagrid based on table name passed.

It’s very easy to integrate jQueryUI Tabs with phpGrid. Please refer to the phpGrid Tabbed Grid demo for more information.

My Sales Rep Page

Since a sales manager needs to quickly find out whom a sale person is working with, we added a detail grid $sdg populated from contact table and link with the master grid.

sales_rep is the connecting key in contact table to the id that is the foreign key in users table. Remember the users stores all of our sales people information.

Screenshots

CRM — Sales Screen

CRM — Manager Screen

Live Demo

CRM Sales Rep Screen | CRM Managers screen

Need to Write Even Less Code?

If you are new to programming and are not yet comfortable with coding, you may want to check out ZenBase that is built on the top of the phpGrid. The CRM is but one of the many application templates readily available at ZenBase for anyone — with or without coding skills — to use and customize for their own needs.

Complete Source Code on GitHub

phpcontrols/phpgrid-custom-crm

phpgrid-custom-crm - Custom CRM Demo - Lær at opbygge en brugerdefineret CRM i PHP og MySQL, som et salgsteam kan ... github.com

Tak for læsningen. Hvis du kunne lide denne artikel, skal du trykke på den klappeknap? for at hjælpe andre med at finde det og følge mig på Twitter.