Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement Multiple Clients Checklists

Tags:

html

php

I am developing a ticket management website, those who execute these tickets are the technicians, who do the rendering of customer services. monthly, yearly, or quarterly, technicians must check equipment so managers can know if equipment needs maintenance. each of these clients has a different amount of equipment, for example customer A has AC but customer B has no AC. the PMs are the measurement points that will be queried, in case Client A would be PM1 = AC. I have a table with all the PMs needed for all clients already implemented, I was thinking that I could associate the client name with the PMs that this client has, so I could generate tables automatically only queried which PMs from that client, I will submit this by post with $ .ajax ({}) My current problem is to notice how in this URL I can see which PMs are generated for this client. If I do a second query in this url by the client name to get the PMs, I could already know which fields, but would this slow down the whole process right? and even this is very practical at the level of code ....

my table to save the PM is like:

| Inspection_Time  | B_Value | C_Value | client | 
|------------------|---------|---------|--------| 
| dd-mm-yyyy hh:mm |      OK |      OK | A      |
| dd-mm-yyyy hh:mm |      OK |      OK | B      |

However, as I have several clients with different checklists, I'm not sure how to do the implementation, anyone have any idea how this should be done?

Currently I have several files with the configurations of each one checklist of each client (little practical)

Actual code exemple:

<?php 
    if($cliente == "001"){
      include("prev.tab/$cliente.php")
    }elseif($cliente == "002"){
      include("prev.tab/$cliente.php")
    }
    [...]
    }elseif($cliente == "500"){
      include("prev.tab/$cliente.php")
    }
?>

EDIT code exemple from 'include("prev.tab/001.php")':

<div class="table-wrap mt-40">
    <div class="table-responsive">
        <table class="table table-striped table-bordered mb-0">
            <thead>
                <tr>
                    <th>P.M.</th>
                    <th>status</th>
                    <th>OBS</th>

                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>ALARM EXT.</td>
                    <td>
                        <select  name="pm8"  class="form-control select2" size="1" required >
                        <option value="N/A">N/A</option>
                            <option value="NOK">NOK</option>
                            <option value="OK">OK</option>
                        </select>
                    </td>
                    <td>
                        <input type="text" class="form-control" placeholder="N/A"name="pm8obs">
                    </td>
                </tr> 
                <tr>
                    <td>other</td>
                    <td>
                        <select   class="form-control select2" size="1" required name="pm9">
                        <option value="N/A">N/A</option>
                            <option value="NOK">NOK</option>
                            <option value="OK">OK</option>
                        </select>
                    </td>
                    <td>
                        <input type="text" class="form-control" placeholder="N/A"name="pm9obs">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
like image 758
NoobDEV-GBL Avatar asked May 08 '19 16:05

NoobDEV-GBL


1 Answers

This is a pretty big question. My suggestion would be to use json. You can store that in various places the server directly under a client folder, in a database with the client id as a lookup, S3 buckets similar to a db, etc.

From there it would be a matter of what the format is. If each client can create their own questions and they are only selects then something as simple the below could be used and the index is where they appear in the code.

$json = '{
    "headers" : ["P.M", "status", "OBS"],
    "questions": [
        {
            "name" : "pm8",
            "text": "ALARM EXT",
            "options": [
                {
                    "display" : "N/A",
                    "value" : "N/A"
                },
                {
                    "display" : "OK",
                    "value" : "OK"
                },
                {
                    "display" : "NOK",
                    "value" : "NOK"
                }
            ]
        },
        {
            "name" : "pm9",
            "text": "other",
            "options": [
                {
                    "display" : "N/A",
                    "value" : "N/A"
                },
                {
                    "display" : "OK",
                    "value" : "OK"
                },
                {
                    "display" : "NOK",
                    "value" : "NOK"
                }
            ]
        }
    ]
}';

With something like this you can then use php to access the data as an object and some simple loops:

<?php
//Access the data this is an example 
//I am not sure what you will use. 
//Just assuming a similar data structure is returned.
$json = your_storage($cliente);

//Change that JSON to an associative array
$data = json_decode($json, TRUE);
//Drop out of PHP to set up the html
?>
<div class="table-wrap mt-40">
    <div class="table-responsive">
        <table class="table table-striped table-bordered mb-0">
            <thead>
                <tr>
                    <?php
                    //In PHP again use what was retrieved earlier
                    foreach($data["headers"] as $header){
                        echo "<th>$header</th>";
                    }
                    ?>
                </tr>
            </thead>
            <tbody>
            <?php
            foreach($data["questions"] as $question){
                echo '<tr>';    
                echo "<td>$question[text]</td>";
                echo '<td>';
                echo "<select  name='$question[name]'  class='form-control select2' size='1' d >";
                foreach($question["options"] as $option){
                    echo "<option value='$option[value]'>$option[display]</option>";
                }
                echo '</select>';
                echo '</td>';
                echo '<td>';
                echo '<input type="text" class="form-control" placeholder="N/A"name="pm8obs">';
                echo '</td>';
                echo '<tr>';            
            }
            ?>
            </tbody>
        </table>
    </div>
</div>

Normally I do not fall in and out of PHP like this. I use Twig to create my templates but that is a whole other setup I do not want to bring in here.

This is extensible too. If you want you could put a required flag to mark question as required. If there was more then selects then you can put a type and interrogate that in the php rendering.

like image 176
nerdlyist Avatar answered Sep 17 '22 13:09

nerdlyist