כיצד ליצור יישום ניהול מלאי מדהים ב- PHP וב- MySQL

אינך זקוק לתוכנות ארגוניות נפוחות כדי לעקוב ביעילות אחר מלאיך. מדריך זה יעזור לך לפתח יישום מעקב מלאי מותאם אישית משלך, כך שתוכל לקבל החלטות מלאי חכמות על סמך נתוני מלאי מתוזמנים ומדויקים.

דרישות מערכת

מערכת המלאי שלנו דורשת רישיון סטנדרטי מסחרי phpGrid ו- phpChart. זה זקוק לכמה תכונות מתקדמות משני הרכיבים.

  • PHP 5.6+ ( עכשיו מומלץ מאוד להשתמש ב- PHP 7.x! )
  • MySQL / MariaDB
  • phpGrid Lite (תת-רשת) -או- phpGrid Enterprise (פרט מאסטר, קיבוץ)
  • phpChart (לדוחות)

מה נמצא במערכת ניהול מלאי

מערכת ניהול מלאי כוללת כמה מרכיבים קריטיים. בבסיסה, בקרת המלאי עובדת על ידי מעקב אחר שתי הפונקציות העיקריות של מחסן: קבלה (נכנסת) ומשלוח (יוצא). פעילויות אחרות כמו העברה או העברת מלאי מתקיימות גם כן. חומרי גלם מורידים ומוצרים מוגמרים מצטברים.

  • משלוחים נכנסים
  • הזמנות יוצאות
  • מְלַאי
  • ספקים
  • סורק ברקוד (1/2019 חדש!)

תכנון בסיסי מערכת מלאי

בדרך כלל, מערכת מלאי כוללת ארבעה אלמנטים בסיסיים: מוצרים, רכישות, הזמנות וספקים. יש לעקוב אחר כל אלמנט בהתבסס על מיקומו, מק"ט וכמותו. המלאי הנוכחי, או המוצרים הקיימים, מתעדכנים על ידי מעקב אחר משלוחים נכנסים והזמנות יוצאות. ניתן להגדיר התראות הזמנה להפעלה כאשר רמות המלאי יורדות מתחת לרמות המינימום שהוגדרו בהתאמה אישית.

הגדרת מאגר מנהל המלאי

הורד את InventoryManager.sqlסקריפט ה- SQL מתוך ריפו GitHub של הדרכה זו ולאחר מכן בצע את התסריט באמצעות כלי MySQL כגון MySQL Workbench. זה ייצור מסד נתונים חדש בשם, InventoryManagerכמו גם את הטבלאות הדרושות להדרכה זו.

הערה צדדית ב- ZenBase

The Inventory Management System 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.

הגדר את phpGrid

בוא נמשיך הלאה.

נשתמש ברכיב מאגר נתונים על ידי phpGrid לטיפול בכל פעולות ה- CRUD (יצירה, הסרה, עדכון ומחיקה) של מסד הנתונים הפנימי .

הקפד להוריד עותק של phpGrid לפני שתמשיך.

כדי להתקין את phpGrid, בצע את הצעדים הבאים:

  1. פתח את קובץ ההורדה של phpGrid.
  2. העלה את phpGridהתיקיה לתיקיית phpGrid.
  3. השלם את ההתקנה על ידי הגדרת התצורה של conf.phpהקובץ.

לפני שנתחיל בקידוד, עלינו לכלול את המידע הבא conf.php, קובץ התצורה של phpGrid.

יצירת ממשק משתמש (UI)

מערכת המלאי שלנו כוללת ארבעה עמודים:

  • מלאי נוכחי
  • רכישות נכנסות
  • הזמנות למשלוח
  • דיווחים

תפריטים

קובץ הכלול של התפריט נשמר incבתיקיה בשם menu.php. הקוד לתפריט הוא פשוט. לצורך המיקוד, לא נפרט לפרטי פרטים. אתם מוזמנים להסתכל על הקוד incשבתיקיה.

הוספנו גם פריט בתפריט בשם Reports.

עמודים

נשתמש באותה תבנית עמוד בה השתמשנו לצורך הדרכות CRM וניהול פרויקטים.

מלאי נוכחי

נתחיל בדף המלאי הנוכחי.

רכישות נכנסות מגדילות את המלאי ואילו ההזמנות היוצאות מקטינות אותו. מנקודת מבט של פירוט אב, במלאי הנוכחי אין אחד, אלא שני נתוני נתונים מפורטים - הרכישות ( רכישות נכנסות) וההזמנות ( הזמנות יוצאות).

אז דף המלאי הנוכחי מורכב מרשת מאסטר אחת (המלאי הנוכחי במלאי) ושתי רשתות פירוט (רכישות נכנסות והזמנות יוצאות). אנו יכולים להציג קשרים אלה בקלות באמצעות תכונת מאסטר phpGrid אחת ופרטי נתונים מרובים.

phpGrid Lite לעומת Professional ו- Enterprise

פרטי מאסטר ותכונות קיבוץ דורשים מהדורה phpGrid Professional או Enterprise. אם אתה משתמש בגרסת Lite החינמית, אתה עדיין יכול להשתמש בתת-רשת במקום פרטי מאסטר, אם כי פחות מתקדמים. גרסאות מקצועיות או ארגוניות מומלצות מאוד.

אם קראת את המדריך האחרון לבנות מנהל תרומות מ- Scratch, לא תהיה לך בעיה לעקוב אחר הקוד שלמטה.

שימו לב לשימוש בפונקציה set_col_format () המשמשת לעיצוב המספרים השלמים.

זהו זה עבור מדריך המלאי הנוכחי. הנה איך זה נראה עד כה:

עכשיו, בואו נעשה כמה שינויים בכדי לשפר את מאגר הנתונים שלנו למוצרים .

First of all, we will add some conditional formatting: whenever the InventoryOnHand is set to zero or a negative value, it is displayed using a different background color. We will use the set_conditional_format() function for this purpose.

The above code adds a display condition so that whenever the InventoryOnHand field has a value that is less than (lt) one, the text color changes to red and the background color to dark gray (#DCDCDC).

Secondly, whenever the InventoryOnHand is less than the value shown in MinimumRequired, we would like to alert the user by displaying it in a prominent background color such as gold. To compare values between two fields, we must switch to Javascript because the set_conditional_format() function only works with a single field.

The code below uses a for loop to iterate through each row in the Products datagrid. It compares the inventoryOnHand with theminimumRequired and, when the condition is met, it will use thesetCell function to change the background color.

You can learn more about comparing multiple cell values on the phpGrid support website.

Next, on the same page, we need to see the purchases coming in (Incoming) and orders going out (Outgoing) for a specific product.

Purchases Detail Grid (Incoming)

Orders Detail Grid (Outgoing)

Both detail grids use the same foreign key ProductId to link to the master datagrid (Products).

Finally, our complete code to manage the Current Inventory page is:

Here’s the a snapshot of the inventory page:

Incoming Purchases

The next page is the Incoming Purchase page. It is similar to the Purchase Detail Grid we saw when setting up the Current Inventory page. We group the purchases by ProductId and display the sum inNumberReceived. Any incoming purchases will increase the inventory.

Note: Grouping feature is only available in the phpGrid Professional and Enterprise edition. To filter without the grouping, use the integration search.

The complete code:

Here’s a screenshot of our Incoming Purchases page with grouping enabled:

Outgoing Orders

The next page is the Outgoing Orders page. It is similar to the Orders Detail Grid from the Current Inventory page. Here, we will introduce an advanced function called set_grid_method().

Summary

This tutorial builds a simple and extendable inventory system in less than 50 lines of code. The progressive style of these tutorials also helps the reader to ultimately become more familar and comfortable with phpGrid by introducing a limited number of new phpGrid features in each one.

What’s Coming Up

This marks the end of the code needed to create the datagrids required for this tutorial. However, we are not done yet. There is still one more page we need to create — Reports. We will cover that after the jump.

What’s the use of an inventory system without some of type of report? In this section, you will learn how to use phpChart — which seamlessly integrates with phpGrid — to create visually pleasing and useful reports for your Inventory Manager application.

Here’s what our page will look like when it’s done:

Before we start, we need to install phpChart. It is recommended that you obtain the full version of phpChart since the free version (phpChart Lite) supports only the line chart.

Setup phpChart

It’s important that we keep phpGrid and phpChart in separate folders. Below is the recommended folder hierarchy.

www +-- Donation_Manager | |-- phpGrid | | +-- conf.php | |-- phpChart | | +-- conf.php | +-- ...

Report Design

We will place a pie chart next to an inventory summary grid. The datagrid provides the series data to plot the pie chart.

phpGrid and phpChart Integration

First of all, include calls to both conf.php files at the beginning of the code.

require_once("phpGrid/conf.php"); require_once("phpChart/conf.php");

Pie Chart

Below is the complete code to create our pie chart:

Let’s walk through the code.

The first line is the constructor. We pass array(null) as the series data because we don’t wish to have any data displayed in the pie chart initially. The inventory data used to plot the chart is not yet available when it is first initialized. The data is fed from the datagrid later in JSON.

We also give our chart a unique name, PieChart.

Next, we give it a title. Nothing fancy here.

Once we have the title, we call the series default function to set the renderer to PieRenderer. Unlike a bar chart, a pie chart does not have a Y axis.

We can also set the rendererOptions property. We will not go into each option in detail here, but you can find more information in the online documentation.

We also want to show a legend. The set_legend command below shows the legend to the west (noted byw) or to the left of the pie chart.

We will also remove the border and the background.

Finally, we draw our chart by giving it a height and width in pixels.

However, if you execute the code now, you will not see the chart because the data used to render it isn’t available yet.

Inventory Summary Datagrid

Here, we will use the same the inventory datagrid as we did in the Products page. We just need to add one more thing — an event handler.

In phpGrid, we can add an event handler with the add_event() function. add_event() binds an event handler, which is essentially a JavaScript function, to a specific phpGrid event. A list of possible events can be found here.

Since we must wait for the datagrid to finish loading before it can send the data to plot the chart, we use the event jqGridLoadComplete.

phpGrid 101 — jqGridLoadComplete Event

jqGridLoadComplete is last event that occurs once the whole datagrid body has finished loading. Note that the grid body will be reloaded if the user changes the sort order of a column or sets a filter.

Sending Data with Javascript

The following is the Javascript event handler for jqGridLoadComplete.

The complete code:

Now there you have it. Your just built your very first inventory management system from scratch using PHP and MySQL!

Thank you for reading! If you enjoyed this post, please give me some claps so more people see it.

New to Programming? Fear Not!

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 Inventory Management System 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.

Online Demo

  • Current Inventory
  • Incoming Purchases
  • Outgoing orders
  • Reports (with datagrid side-by-side)

Next: Add the barcode scanner

Add the barcode scanner to our inventory management system

Download Source Code on Github

phpcontrols/inventory-manager

Source code of inventory-manager the awesome Inventory Management Application in PHP and MySQL from Start to Finishgithub.com

Common Issue:

Fatal error: Uncaught Error: Class ‘phpGrid\C_DataGrid’ not found

How to fix:

If you are using the free Lite version, you can either comment out the first line

// use phpGrid\C_DataGrid;

— OR —

Add a global namespace symbol — single backslash — BEFORE the constructor

$dg = new \C_DataGrid(“SELECT * FROM orders”, “orderNumber”, “orders”);

You may be also interested in those tutorials:

Build a Project Management Application From Scratch

What is a Project Management Application?Build a Simple CRM from Start to Finish

Customer Relationship Management (CRM) is a system that manages customer interactions and data throughout the customer…Building a Donation Manager from Scratch in PHP

Thanks for reading. If you enjoyed this article, please hit that clap button ? to help others find it and follow me on Twitter.

Would you like to see more tutorials like this? Send a request to my Twitter or leave a comment below!