<file_sep><?php

namespace App\Http\Controllers\Gestionnaire;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\User;
use App\Models\Alert;
use App\Models\Produit;
use App\Models\Statistique;
use App\Charts\TestChart;
use App\Helpers\Helper;
use App\Models\Client;
use App\Models\Fournisseur;
use App\Models\Atelier;
use DB;


class StatistiquesController extends Controller{

    public function indexRetour($year){
        $lineChart = new TestChart;
        $camembertChart = new TestChart;
        $i = 0;
        $totalRetour = array();
        $color = array();
        $color[0] = '#00ED96';
        $color[1]= '#F1BE25';
        $color[2]= '#444BF8';
        $backgroundColor = array();
        $backgroundColor[0] ="rgba(0, 237, 150,0.7)";
        $backgroundColor[1] ="rgba(241, 190, 37,0.8)";
        $backgroundColor[2] ="rgba(68, 75, 248,0.8)";
        
        $lineChart->labels(Helper::getMonthsAbv());
        $lineChart->options([
            'legend'=> [
                'labels' => [
                    'usePointStyle' => true,
                    'fontFamily' => 'Poppins',
                    'fontColor' => 'black'
                ],
            ],
            'tooltips' => [
                'enabled' => true,
                'mode'=> 'index',
                'titleFontSize'=> 12,
                'titleFontColor'=> '#000',
                'bodyFontColor'=> '#000',
                'backgroundColor'=> '#fff',
                'titleFontFamily'=> 'Poppins',
                'bodyFontFamily'=> 'Poppins',
                'cornerRadius'=> 3,
                'intersect'=> false,
            ],
            'scales' => [
                'xAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => 'Mois',
                        'fontSize' => 18,
                    ]
                ]],
                'yAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'fontSize' => 18,
                        'labelString' => "Quantité d'articles"
                    ]
                ]],
            ]
        ]);
        foreach (Helper::getTypesRetour() as $type) {
            $lineChart->dataset($type , 'line',  Statistique::retourParMois($type,$year))->options([
                'fill' => 'true',
                'borderColor' => '#00ed96',
                'backgroundColor' => 'transparent',
                'borderColor' => $color[$i],
                'borderWidth' => 3,
                'pointStyle' => 'circle',
                'pointRadius' => 5,
                'pointBorderColor' => 'transparent',
                'pointBackgroundColor' => $color[$i],
            ]);
            $totalRetour[$i] = Statistique::retourTotalParType($type,$year);
            $i++;
        }

        $camembertChart->labels(Helper::getTypesRetour());
        $camembertChart->dataset('Retours' , 'pie',  $totalRetour)->options([
            'fill' => 'true',
            'fontColor' => 'black',
            'backgroundColor' => $color,
            'hoverBackgroundColor' => $backgroundColor,
        ]);
        $camembertChart->options([
            'scales' => [
                'xAxes'  => [[
                    'display' => false,
                ]],
                'yAxes'  => [[
                    'display' => false,
                ]],
            ]
        ]);
        $yearDisplayed = $year;
        return view('quality.statistiques.indexR',compact('lineChart','camembertChart','yearDisplayed'));
    }

    public function indexArticle($year){

        $barChart = new TestChart;
        $camembertChart = new TestChart;
        $i = 0;
        $total = array();
        $color = array();
        $color[0] = '#00ED96';
        $color[1]= '#F1BE25';
        $color[2]= '#444BF8';
        $backgroundColor = array();
        $backgroundColor[0] ="rgba(0, 237, 150,0.7)";
        $backgroundColor[1] ="rgba(241, 190, 37,0.8)";
        $backgroundColor[2] ="rgba(68, 75, 248,0.8)";

        $articles = Produit::all();
        $barChart->labels($articles->pluck('nom'));
        $barChart->options([
            'legend'=> [
                'display' => false,
            ],
            'tooltips' => [
                'enabled' => true,
                'mode'=> 'index',
                'titleFontSize'=> 12,
                'titleFontColor'=> '#000',
                'bodyFontColor'=> '#000',
                'backgroundColor'=> '#fff',
                'titleFontFamily'=> 'Poppins',
                'bodyFontFamily'=> 'Poppins',
                'cornerRadius'=> 3,
                'intersect'=> false,
            ],
            'scales' => [
                'xAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'fontSize' => 18,
                        'labelString' => 'Articles'
                    ]
                ]],
                'yAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'fontSize' => 18,
                        'labelString' => "Nombre"
                    ]
                ]],
            ]
        ]);
        $barChart->dataset('Retour par Article' , 'bar', Statistique::retourParArticle($articles,$year))->options([
            'fill' => 'true',
            'backgroundColor' => '#00ED96',
            'borderColor' => '#00ED96',
            'borderWidth' => 3,
        ]);

        $typeArticles = Helper::getTypesArticle();
        $camembertChart->labels($typeArticles);
        $camembertChart->dataset("Retour par Type d'Article" , 'doughnut', Statistique::retourParTypeArticle($typeArticles,$year))->options([
            'fill' => 'true',
            'fontColor' => 'black',
            'backgroundColor' => $color,
            'hoverBackgroundColor' => $backgroundColor,
        ]);
        $camembertChart->options([
            'scales' => [
                'xAxes'  => [[
                    'display' => false,
                ]],
                'yAxes'  => [[
                    'display' => false,
                ]],
            ]
        ]); 
        $yearDisplayed = $year;
        return view('quality.statistiques.indexArticle',compact('camembertChart','barChart','yearDisplayed'));

    }
            
    public function indexRetourClient($year){ 
        // retour client par produit ou article
        $produits =  Produit::where('type', '=' ,'Fini')->get();
        $nomsProduit =  Produit::where('type', '=' ,'Fini')->pluck('nom');
        $nombreretourClient = array();
        $i = 0;
        
        foreach($produits as $produit)
        {   
            $nombreretourClientParProduit[$i] = Statistique::retourParArticleType($produit->nom,'Retour client',$year);
            $i++ ;
        }

        $chart = new TestChart;
        $chart->labels(   $nomsProduit->values() );
        //$chart->title('Quantité de retour client par article');
        $chart->options([
            'legend'=> [
                'display' => false,
            ],
            'tooltips' => [
                'enabled' => true,
                'mode'=> 'index',
                'titleFontSize'=> 12,
                'titleFontColor'=> '#000',
                'bodyFontColor'=> '#000',
                'backgroundColor'=> '#fff',
                'titleFontFamily'=> 'Poppins',
                'bodyFontFamily'=> 'Poppins',
                'cornerRadius'=> 3,
                'intersect'=> false,
            ],
            'scales' => [
                'xAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => 'Articles',
                        'fontSize' => 18,
                    ]
                ]],
                'yAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => "Quantité",
                        'fontSize' => 18,
                    ]
                ]],
            ]
        ]);
        $chart->dataset('Quantité de retour client', 'bar', $nombreretourClientParProduit)->options([
            'fill' => 'true',
            'borderColor' => '#444BF8',
            'backgroundColor' => '#444BF8',   
        ]);;  
      
        // retour client par client
        $clients = Client::all();
        $array = array();

        foreach($clients as $client)
        {   
            //$nombreretourClient[$i] = Statistique::retourParClient($client->id);
            $array = array_add($array, $client->nom , Statistique::retourParClient($client->id,$year) );
        }
 
        array_multisort($array,SORT_DESC);  // sort the array 
        $array2 = array_slice($array, 0, 10, true); // get the first 10 elements only 
        list($keys, $values) = array_divide($array2); // separate the keys and the values in two arrays
        //$nomsClients = Client::all()->pluck('nom');
       
        $chartClient = new TestChart;
        $chartClient->labels( $keys );
        $chartClient->options([
            'legend'=> [
                'display' => false,
            ],
            'tooltips' => [
                'enabled' => true,
                'mode'=> 'index',
                'titleFontSize'=> 12,
                'titleFontColor'=> '#000',
                'bodyFontColor'=> '#000',
                'backgroundColor'=> '#fff',
                'titleFontFamily'=> 'Poppins',
                'bodyFontFamily'=> 'Poppins',
                'cornerRadius'=> 3,
                'intersect'=> false,
            ],
            'scales' => [
                'xAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => 'Clients',
                        'fontSize' => 18,
                    ]
                ]],
                'yAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => "Quantité",
                        'fontSize' => 18,
                    ]
                ]],
            ]
        ]);

        $chartClient->dataset('Quantité de retour client', 'bar', $values)->options([
            'fill' => 'true',
            'borderColor' => '#444BF8',
            'backgroundColor' => '#444BF8',   
        ]);; 
        $yearDisplayed = $year;
        return view('quality.statistiques.indexRC',compact('chart','chartClient','yearDisplayed'));
    }

    public function indexRetourProduction($year){   
                
        // Histogramme 1 : retour production par produit ou article
        $produits =  Produit::where('type', '=' ,'Fini')->get();
        $nomsProduit =  Produit::where('type', '=' ,'Fini')->pluck('nom');
        $i = 0;
        
        foreach($produits as $produit)
        {   
            $nombreretourProductionParProduit[$i] = Statistique::retourParArticleType($produit->nom,'Retour production',$year);
            $i++ ;
        }

        $chart = new TestChart;
        $chart->labels(   $nomsProduit->values() );
        $chart->options([
            'legend'=> [
                'display' => false,
            ],
            'tooltips' => [
                'enabled' => true,
                'mode'=> 'index',
                'titleFontSize'=> 12,
                'titleFontColor'=> '#000',
                'bodyFontColor'=> '#000',
                'backgroundColor'=> '#fff',
                'titleFontFamily'=> 'Poppins',
                'bodyFontFamily'=> 'Poppins',
                'cornerRadius'=> 3,
                'intersect'=> false,
            ],
            'scales' => [
                'xAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => 'Article',
                        'fontSize' => 18,
                    ]
                ]],
                'yAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => "Quantité",
                        'fontSize' => 18,
                    ]
                ]],
            ]
        ]);

        $chart->dataset('Quantité de retour production', 'bar', $nombreretourProductionParProduit)->options([
            'fill' => 'true',
            'borderColor' => '#F1BE25',
            'backgroundColor' => '#F1BE25',   
        ]);;  

        //Histogramme 2 : retour production par atelier
        $ateliers = Atelier::all();
        $nomAteliers = Atelier::all()->pluck('nom');
        $i = 0;

        foreach($ateliers as $atelier)
        {   
            $nombreretourProductionParAtelier[$i] = Statistique::retourParAtelier($atelier->id,$year);
            $i++;
        }

        $chartP = new TestChart;
        $chartP->labels( $nomAteliers->values() );
        $chartP->options([
            'legend'=> [
                'display' => false,
            ],
            'tooltips' => [
                'enabled' => true,
                'mode'=> 'index',
                'titleFontSize'=> 12,
                'titleFontColor'=> '#000',
                'bodyFontColor'=> '#000',
                'backgroundColor'=> '#fff',
                'titleFontFamily'=> 'Poppins',
                'bodyFontFamily'=> 'Poppins',
                'cornerRadius'=> 3,
                'intersect'=> false,
            ],
            'scales' => [
                'xAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => 'Ateliers',
                        'fontSize' => 18,
                    ]
                ]],
                'yAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => "Quantité",
                        'fontSize' => 18,
                    ]
                ]],
            ]
        ]);


        $chartP->dataset('Quantité de retour production', 'bar', $nombreretourProductionParAtelier)->options([
            'fill' => 'true',
            'borderColor' => '#F1BE25',
            'backgroundColor' => '#F1BE25',   
        ]);; 
      
        $yearDisplayed = $year;
        return view('quality.statistiques.indexRP',compact('chart','chartP','yearDisplayed'));

    }


    public function indexRetourFournisseur($year){                     
        // Histogramme 1 : retour fournisseur par matiere premiere
        $MPs =  Produit::where('type', '=' ,'Matiere premiere')->get();
        $array = array();

        foreach($MPs as $MP)
        {   
            $array = array_add($array, $MP->nom ,  Statistique::retourParArticleType($MP->nom,'Retour fournisseur',$year) );
        }
 
        array_multisort($array,SORT_DESC);  // sort the array 
        $array2 = array_slice($array, 0, 10, true); // get the first 10 elements only 
        list($keys, $values) = array_divide($array2); // separate the keys and the values in two arrays
      
        $chart = new TestChart;
        $chart->labels( $keys );
        $chart->options([
            'legend'=> [
                'display' => false,
            ],
            'tooltips' => [
                'enabled' => true,
                'mode'=> 'index',
                'titleFontSize'=> 12,
                'titleFontColor'=> '#000',
                'bodyFontColor'=> '#000',
                'backgroundColor'=> '#fff',
                'titleFontFamily'=> 'Poppins',
                'bodyFontFamily'=> 'Poppins',
                'cornerRadius'=> 3,
                'intersect'=> false,
            ],
            'scales' => [
                'xAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => 'Marchandise',
                        'fontSize' => 18,
                    ]
                ]],
                'yAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => "Quantité",
                        'fontSize' => 18,
                    ]
                ]],
            ]
        ]);


        $chart->dataset('Quantité de retour fournisseur', 'bar', $values)->options([
            'fill' => 'true',
            'borderColor' => '#00ed96',
            'backgroundColor' => '#00ed96',   
        ]);; 

        //Histogramme 2 : retour fournisseur par fournisseur
        $fournisseurs = Fournisseur::all();
        $array = array();

        foreach($fournisseurs as $fournisseur)
        {   
            $array = array_add($array, $fournisseur->nom , Statistique::retourParFournisseur($fournisseur->id,$year) );
        }
 
        array_multisort($array,SORT_DESC);  // sort the array 
        $array2 = array_slice($array, 0, 10, true); // get the first 10 elements only 
        list($keys, $values) = array_divide($array2); // separate the keys and the values in two arrays
       
       
        $chartF = new TestChart;
        $chartF->labels( $keys );
        $chartF->options([
            'legend'=> [
                'display' => false,
            ],
            'tooltips' => [
                'enabled' => true,
                'mode'=> 'index',
                'titleFontSize'=> 12,
                'titleFontColor'=> '#000',
                'bodyFontColor'=> '#000',
                'backgroundColor'=> '#fff',
                'titleFontFamily'=> 'Poppins',
                'bodyFontFamily'=> 'Poppins',
                'cornerRadius'=> 3,
                'intersect'=> false,
            ],
            'scales' => [
                'xAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => 'Fournisseurs',
                        'fontSize' => 18,
                    ]
                ]],
                'yAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'labelString' => "Quantité",
                        'fontSize' => 18,
                    ]
                ]],
            ]
        ]);

        $chartF->dataset('Quantité de retour fournisseur', 'bar', $values)->options([
            'fill' => 'true',
            'borderColor' => '#00ed96',
            'backgroundColor' => '#00ed96',   
        ]);; 
      
        $yearDisplayed = $year;
        return view('quality.statistiques.indexRF',compact('chart','chartF','yearDisplayed'));

    }


    public function indexAudit($year){
        $barChart = new TestChart;
        $camembertChart = new TestChart;
        $i = 0;
        $total = array();
        $color = array();
        $color[0] = '#F12559';
        $color[1]= '#00ED96';
        $barChart->labels(Helper::getMonthsAbv());
        $barChart->options([
            'legend'=> [
                'labels' => [
                    'usePointStyle' => true,
                    'fontFamily' => 'Poppins',
                    'fontColor' => 'black'
                ],
            ],
            'tooltips' => [
                'enabled' => true,
                'mode'=> 'index',
                'titleFontSize'=> 12,
                'titleFontColor'=> '#000',
                'bodyFontColor'=> '#000',
                'backgroundColor'=> '#fff',
                'titleFontFamily'=> 'Poppins',
                'bodyFontFamily'=> 'Poppins',
                'cornerRadius'=> 3,
                'intersect'=> false,
            ],
            'scales' => [
                'xAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'fontSize' => 18,
                        'labelString' => 'Mois'
                    ]
                ]],
                'yAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'fontSize' => 18,
                        'labelString' => "Nombre"
                    ]
                ]],
            ]
        ]);
        foreach (Helper::getResultatAudit() as $resultat) {
            $barChart->dataset($resultat , 'bar',  Statistique::auditParMois($resultat,$year))->options([
                'fill' => 'true',
                'backgroundColor' => $color[$i],
                'borderColor' => $color[$i],
                'borderWidth' => 3,
            ]);
            $total[$i] = Statistique::auditTotalParResulat($resultat,$year);
            $i++;
        }
        $camembertChart->labels(Helper::getResultatAudit());
        $camembertChart->dataset('Audits' , 'pie',  $total)->options([
            'fill' => 'true',
            'fontColor' => 'black',
            'backgroundColor' => $color,
        ]);
        $camembertChart->options([
            'scales' => [
                'xAxes'  => [[
                    'display' => false,
                ]],
                'yAxes'  => [[
                    'display' => false,
                ]],
            ]
        ]);
        $yearDisplayed = $year;
        return view('quality.statistiques.indexA',compact('camembertChart','barChart','yearDisplayed'));

    }

    public function indexInspection($year){
        $histoChart = new TestChart;
        $pieChart = new TestChart;
        $i = 0;
        $total = array();
        $color = array();
        $color[0] = '#F12559';
        $color[1]= '#00ED96';
        $histoChart->labels(Helper::getMonthsAbv());
        $histoChart->options([
            'legend'=> [
                'labels' => [
                    'usePointStyle' => true,
                    'fontFamily' => 'Poppins',
                    'fontColor' => 'black'
                ],
            ],
            'tooltips' => [
                'enabled' => true,
                'mode'=> 'index',
                'titleFontSize'=> 12,
                'titleFontColor'=> '#000',
                'bodyFontColor'=> '#000',
                'backgroundColor'=> '#fff',
                'titleFontFamily'=> 'Poppins',
                'bodyFontFamily'=> 'Poppins',
                'cornerRadius'=> 3,
                'intersect'=> false,
            ],
            'scales' => [
                'xAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'fontSize' => 18,
                        'labelString' => 'Mois'
                    ]
                ]],
                'yAxes'  => [[
                    'display' => true,
                    'gridLines' => [
                        'display' => false,
                        'drawBorder' => true
                    ],
                    'scaleLabel' => [
                        'fontColor' => 'black',
                        'display' => true,
                        'fontSize' => 18,
                        'labelString' => "Nombre"
                    ]
                ]],
            ]
        ]);
        foreach (Helper::getTypeInspection() as $resultat) {
            $histoChart->dataset($resultat , 'bar',  Statistique::inspectionParMois($resultat,$year))->options([
                'fill' => 'true',
                'backgroundColor' => $color[$i],
                'borderColor' => $color[$i],
                'borderWidth' => 3,
            ]);
            $total[$i] = Statistique::inspectionTotalParResulat($i,$year);
            $i++;
        }
        $pieChart->labels(Helper::getTypeInspection());
        $pieChart->dataset('Inspection' , 'pie',  $total)->options([
            'fill' => 'true',
            'fontColor' => 'black',
            'backgroundColor' => $color,
        ]);
        $pieChart->options([
            'scales' => [
                'xAxes'  => [[
                    'display' => false,
                ]],
                'yAxes'  => [[
                    'display' => false,
                ]],
            ]
        ]);
        $yearDisplayed = $year;
        return view('quality.statistiques.indexI',compact('histoChart','pieChart','yearDisplayed'));
    }
}

<file_sep><?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class PermissionsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('permissions')->insert([
            'name' => 'edit user',
            'guard_name' => 'web',
            'description' => 'droit de modification des utilisateurs, privileges et roles',
        ]);
        DB::table('permissions')->insert([
            'name' => 'view user',
            'guard_name' => 'web',
            'description' => 'droit de voir la liste des utilisateurs',
        ]);
        DB::table('permissions')->insert([
            'name' => 'edit atelier',
            'guard_name' => 'web',
            'description' => 'droit de modification des ateliers',
        ]);
        DB::table('permissions')->insert([
            'name' => 'edit fournisseur',
            'guard_name' => 'web',
            'description' => 'droit de modification des fournisseurs',
        ]);
        DB::table('permissions')->insert([
            'name' => 'edit client',
            'guard_name' => 'web',
            'description' => 'droit de modification des clients',
        ]);
    }
}
<file_sep><?php
namespace App\Helpers;

class Helper{
    public static function getJours(){
            return array(
            1 => 'Dimanche',
            2 => 'Lundi',
            3 => 'Mardi',
            4 => 'Mercredi',
            5 => 'Jeudi',
            6 => 'Vendredi',
            7 => 'Samedi',
            );
    }
    
    public static function getTypesRetour(){
            return array(
                0 => 'Retour fournisseur',
                1 => 'Retour production',
                2 => 'Retour client',
            );
        }

    public static function getTypesArticle(){
            return array(
                0 => 'Fini',
                1 => 'Semi-fini',
                2 => 'Matiere premiere',
            );
    }

    public static function getMonths(){
        return array(
        1 => 'Janvier',
        2 => 'Février',
        3 => 'Mars',
        4 => 'Avril',
        5 => 'Mai',
        6 => 'Juin',
        7 => 'Juillet',
        8 => 'Août',
        9 => 'Septembre',
        10 => 'Octobre',
        11 => 'Novembre',
        12 => 'Décembre',
        );
    }
    

    public static function getMonthsAbv(){
        return array(
            0 => 'Jan',
            1 => 'Fév',
            2 => 'Mar',
            3 => 'Avr',
            4 => 'Mai',
            5 => 'Jui',
            6 => 'Jul',
            7 => 'Aoû',
            8 => 'Sep',
            9 => 'Oct',
            10 => 'Nov',
            11 => 'Déc',
        );
    }
    

    public static function getResultatAudit(){
        return array(
            0 => 'Procédé non conforme',
            1 => 'Procédé conforme',
        );
    }

    public static function getResultatInspection(){
        return array(
            0 => 'Les réponses des examens ne sont pas toutes correctes',
            1 => 'Les réponses des examens sont toutes correctes',
        );
    }
    public static function getTypeInspection(){
        return array(
            0 => 'Echoué',
            1 => 'Réussie',
        );
    }
}
?><file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Client extends Model
{
    protected $fillable = [
        'nom','description','adresse',
    ];

    public function anomalies()
    {
        return $this->hasMany('App\Models\Anomalie');
    }

    public function alerts()
    {
        return $this->hasMany('App\Models\Alert');
    }
}
<file_sep><?php

namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Client;
use App\Models\Produit;
use App\Models\Fournisseur;
use App\Models\Article;
use App\Models\Audit;
use App\Models\Anomalie;
use App\Models\Inspection;
use Carbon\Carbon;
use App\Helpers\Helper;
use Illuminate\Support\Facades\Auth;

class Statistique extends Model
{
    /** Accueil **/
    static function alerteNonTraite(){
        return count(Alert::where("etat","=","nouveau")
        ->whereNotIn('type',['Rappel'])->where("user_id","=",Auth::user()->id)->get());
    }
    static function anomalieEnCours(){
        return count(Anomalie::where("etat","=","en cours")->get());
    }

    static function inspectionEnAttente(){
        return count(Inspection::where("etat","=","nouveau")->get());
    }
    static function auditPlanifie(){
        return count(Audit::where("etat","=","nouveau")->get());
    }

    static function retoursRécents(){
        return Alert::where("etat","=","nouveau")->whereNotIn('type',['Rappel'])->orderBy('updated_at','desc')->limit(3)->get();
    }
    static function auditsRécents(){
        return Audit::where("etat","=","nouveau")->orderBy('updated_at','desc')->limit(2)->get();
    }
    static function inspectionsRécentes(){
        return Inspection::where("etat","=","nouveau")->orderBy('updated_at','desc')->limit(2)->get();
    }

    /** Retours **/
    static function findbyType($type,$year){
        return Alert::where("type","=",$type)->whereYear('created_at','=',$year);
    }

    static function retourParMoisType($mois,$year,$type){

        $sum = 0;
        foreach(Statistique::findbyType($type,$year)->whereMonth('created_at','=',$mois)->get() as $alert){
            $sum += $alert->lot->quantite;
        }
        return $sum;
    }
    static function retourTotalParType($type,$year){
        $sum = 0;
        foreach(Statistique::findbyType($type,$year)->get() as $alert){
            $sum += $alert->lot->quantite;
        }
        return $sum;
    }
    static function retourParMois($type,$year){
        $retour = array();
        foreach(Helper::getMonthsAbv() as $mois){
            $month = array_search($mois,Helper::getMonthsAbv());
            $monthNum = sprintf("%02s",$month+1);
            $retour[$month] = Statistique::retourParMoisType($monthNum,$year,$type);
        }
        return $retour;
    }

    /** Retour par critere **/
    
    // retour par critere client
    static function retourParClient($id,$year){
        $sum = 0;
        $alerts = Alert::where("type","=",'Retour client')
        ->whereYear('created_at','=',$year)->get();// retour client
        
        foreach( $alerts as $alert){
             if ($alert->client_id == $id)
             {
                $sum += $alert->lot->quantite;
             }
        }
        return $sum;
    }
   
    // retour par critere atelier
    static function retourParAtelier($id,$year){
        $sum = 0;
        $alerts = Alert::where("type","=",'Retour production')
        ->whereYear('created_at','=',$year)->get();// retour production
        
        foreach( $alerts as $alert){
             if ($alert->atelier_id == $id)
             {
                $sum += $alert->lot->quantite;
             }
        }
        return $sum;
    }

    // retour par critere fournisseur
    static function retourParFournisseur($id,$year){
        $sum = 0;
        $alerts = Alert::where("type","=",'Retour fournisseur')
        ->whereYear('created_at','=',$year)->get();// retour fournisseur
        
        foreach( $alerts as $alert){
            if ($alert->fournisseur_id == $id)
            {
            $sum += $alert->lot->quantite;
            }
        }
        return $sum;
    }
    
     /** Retours par article et type **/
     static function retourParArticleType($nom,$type,$year){
        $sum = 0;
        $alerts = Alert::where("type","=",$type)->whereYear('created_at','=',$year)->get();
        
        foreach( $alerts as $alert){
             if ($alert->lot->produit->nom == $nom)
             {
                $sum += $alert->lot->quantite;
             }
        }
        return $sum;
    }


    /** Retour par Article **/
    static function findRetourByArticle($article,$year){
        $alerts = Alert::whereYear("created_at","=",$year)->whereNotIn('type',['Rappel'])->get();
        $sum = 0;
        foreach ($alerts as $alert) {
            if($alert->lot->produit->id == $article->id){
                $sum += $alert->lot->quantite;
            }
        }
        return $sum;
    }

    static function retourParArticle($articles, $year){
        $retourParArticle = array();
        $i = 0;
        foreach ($articles as $article) {
            $retourParArticle[$i] = Statistique::findRetourByArticle($article,$year);
            $i++;
        }
        return $retourParArticle;
    }

    static function findRetourByTypeArticle($type,$year){
        $alerts = Alert::whereYear("created_at","=",$year)->whereNotIn('type',['Rappel'])->get();
        $sum = 0;
        foreach ($alerts as $alert) {
            if($alert->lot->produit->type == $type){
                $sum += $alert->lot->quantite;
            }
        }
        return $sum;
    }

    static function retourParTypeArticle($types,$year){
        $retourParTypeArticle = array();
        $i = 0;
        foreach ($types as $type) {
            $retourParTypeArticle[$i] = Statistique::findRetourByTypeArticle($type,$year);
            $i++;
        }
        return $retourParTypeArticle;
    }
    static function retourParMoisArticle($mois,$year,$article){
        $alerts = Alert::whereYear("created_at","=",$year)->whereNotIn('type',['Rappel'])
        ->whereMonth("created_at","=",$mois)->get();
        $sum = 0;
        foreach ($alerts as $alert){
            if($alert->lot->produit->id == $article->id){
                $sum += $alert->lot->quantite;
            }
        }
        return $sum;
    }

    /** Audits **/
    static function findbyResultatA($resultat,$year){
        return Audit::where("resultats","=",$resultat)->where("etat","=","traité")->whereYear('updated_at','=',$year);
    }

    static function auditParMoisResultat($mois,$year,$resultat){
        return count(Statistique::findbyResultatA($resultat,$year)->whereMonth('updated_at','=',$mois)->get());
    }

    static function auditParMois($resultat,$year){
        $audit = array();
        foreach(Helper::getMonthsAbv() as $mois){
            $month = array_search($mois,Helper::getMonthsAbv());
            $monthNum = sprintf("%02s",$month+1);
            $audit[$month] = Statistique::auditParMoisResultat($monthNum,$year,$resultat);
        }
        return $audit;
    }

    static function auditTotalParResulat($resultat,$year){
        return count(Statistique::findbyResultatA($resultat,$year)->get());
    }

    /** Inspections **/
    static function findbyResultatI($resultat,$year){
        return Inspection::where("resultats","=",$resultat)->where("etat","=","traité")->whereYear('updated_at','=',$year);
    }
    static function InspectionParMoisResultat($mois,$year,$typeNum){   
        $resultat = Helper::getResultatInspection()[$typeNum];
        return count(Statistique::findbyResultatI($resultat,$year)->whereMonth('updated_at','=',$mois)->get());
    }

    static function inspectionTotalParResulat($index,$year){
        $resultat = Helper::getResultatInspection()[$index];
        return count(Statistique::findbyResultatI($resultat,$year)->get());
    }

    static function inspectionParMois($resultat,$year){
        $inspection = array();
        foreach(Helper::getMonthsAbv() as $mois){
            $month = array_search($mois,Helper::getMonthsAbv());
            $monthNum = sprintf("%02s",$month+1);
            $inspection[$month] = Statistique::InspectionParMoisResultat($monthNum,$year,
                array_search($resultat,Helper::getTypeInspection()));
        }
        return $inspection;
    }
}
<file_sep><?php

namespace App\Exports;

use App\Models\Client;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithTitle;

use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;


class ClientsExport implements FromQuery,WithMapping,WithHeadings,ShouldAutoSize,WithTitle,WithEvents
{
    use Exportable;
    public function map($client): array
    {
        return [
            $client->id,
            $client->nom,
            $client->adresse,
            $client->description,
            $client->created_at,
        ];
    }
    
    public function headings(): array
    {
        return [
            '#',
            'Nom',
            'Adresse',
            'Description',
            'Créé le',
        ];
    }
    public function title(): string
    {
        return 'Clients';
    }

    public function query()
    {
        return Client::query();
    }
    public function registerEvents(): array{
        $styleArray = [
            'borders' => [
                'allBorders' => [
                    'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
                    ],
                ],
            ];

            return [
                AfterSheet::class => function(AfterSheet $event) use($styleArray) {
                    $cpt = count(Client::all()) +1;
                    $cellRange = 'A1:E1'; 
                    $event->sheet->getStyle($cellRange)->ApplyFromArray($styleArray);
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setName('Calibri');
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);  
                    $event->sheet->getStyle('A2:A'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('B2:B'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('C2:C'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('D2:D'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('E2:E'.$cpt)->applyFromArray($styleArray);  
                },
            ];
    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Alert extends Model
{
    public function lot()
    {
       return $this->belongsTo('App\Models\Lot');
    }
    
    public function anomalie()
    {
       return $this->belongsTo('App\Models\Anomalie');
    }
   
    public function event()
    {
        return $this->belongsTo('App\Models\Event');
    }

    public function atelier()
    {
       return $this->belongsTo('App\Models\Atelier');
    }
    
    public function client()
    {
       return $this->belongsTo('App\Models\Client');
    }
    
    public function fournisseur()
    {
       return $this->belongsTo('App\Models\Fournisseur');
    }
}
<file_sep><?php

namespace App\Http\Controllers\Gestionnaire;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Event;
use App\Models\Inspection;
use App\Models\Alert;
use App\Models\Audit;
use Carbon\Carbon;
use Redirect,Response;
use DB;
use Auth;

class CalendrierController extends Controller
{
    public function index()
    {
        if(request()->ajax()) 
        {
         $start = (!empty($_GET["start"])) ? ($_GET["start"]) : ('');
         $end = (!empty($_GET["end"])) ? ($_GET["end"]) : ('');
 
         $data = Event::whereDate('start', '>=', $start)->whereDate('end',   '<=', $end)->get(['id','title','type','start', 'end']);
         return Response::json($data);
        }
        return view('quality.calendrier.calender');
    }
    
   
    public function create(Request $request)
    {  
        $type = $request->type;
        $inspection_id = 0;
        $audit_id = 0;
        $event = new Event;
        $event->title = $request->title;
        $event->type = $request->type;
        $event->start = $request->start;
        $event->end = $request->end;
        $event->rappel = $request->rappel;
        $event->user_id = Auth::user()->id;

        if ($type == "Inspection"){
            $inspection_id = DB::table('inspections')->insertGetId(
                ['titre' => $request->title,
                'etat' => "nouveau",
                'step' => 1,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),  
                ]
            );
            $event->inspection_id = $inspection_id;
        }
        else{
            $audit_id = DB::table('audits')->insertGetId(
                ['titre' => $request->title,
                 'etat' => "nouveau",
                 'step' => 1,
                 'created_at' => Carbon::now(),
                 'updated_at' => Carbon::now(), ]
            ); 
            $event->audit_id = $audit_id;
        }

        $event->save(); 
        return Response::json($event);
    }
     
 
    public function update(Request $request)
    {   
        $where = array('id' => $request->id);
        $updateArr = ['start' => $request->start, 'end' => $request->end];
        $event  = Event::where($where)->update($updateArr);
 
        return Response::json($event);
    } 
 
 
    public function destroy(Request $request){    
        $event = Event::where("id","=",$request->id)->delete();
        return Response::json($event);
    }    
 

}
<file_sep><?php
Auth::routes();

Route::get('/', 'HomeController@index')->middleware('auth','general')->name('home');

/* AlertRF CRUD Routes for simple user */
Route::group([
    'as' => 'alertRF.',
    'prefix' => 'alertRF', 
    'namespace'=>'Simple', 
    'middleware' => ['auth','general', 'can:edit fournisseur']],
    function(){
        Route::get('create', 'AlertController@createRF')->name('create');
        Route::post('create', 'AlertController@storeRF')->name('store');
        Route::get('edit/{alert}', 'AlertController@editRF')->name('edit');
        Route::get('view/{alert}', 'AlertController@viewRF')->name('view');
        Route::post('update/{alert}', 'AlertController@updateRF')->name('update');
        Route::delete('delete/{alert}', 'AlertController@deleteRF')->name('delete');
        Route::get('fiche/{alert}', 'AlertController@generate_pdf_RF')->name('pdf');
    });   

/* AlertRP CRUD Routes for simple user */
Route::group([
    'as' => 'alertRP.',
    'prefix' => 'alertRP', 
    'namespace'=>'Simple', 
    'middleware' => ['auth','general', 'can:edit atelier']],
    function(){
        Route::get('create', 'AlertController@createRP')->name('create');
        Route::post('create', 'AlertController@storeRP')->name('store');
        Route::get('edit/{alert}', 'AlertController@editRP')->name('edit');
        Route::get('view/{alert}', 'AlertController@viewRP')->name('view');
        Route::post('update/{alert}', 'AlertController@updateRP')->name('update');
        Route::delete('delete/{alert}', 'AlertController@deleteRP')->name('delete');
        Route::get('fiche/{alert}', 'AlertController@generate_pdf_RP')->name('pdf');
    });

/* AlertRC CRUD Routes for simple user */
Route::group([
    'as' => 'alertRC.',
    'prefix' => 'alertRC', 
    'namespace'=>'Simple', 
    'middleware' => ['auth','general', 'can:edit client']],
    function(){
        Route::get('create', 'AlertController@createRC')->name('create');
        Route::post('create', 'AlertController@storeRC')->name('store');
        Route::get('edit/{alert}', 'AlertController@editRC')->name('edit');
        Route::get('view/{alert}', 'AlertController@viewRC')->name('view');
        Route::post('update/{alert}', 'AlertController@updateRC')->name('update');
        Route::delete('delete/{alert}', 'AlertController@deleteRC')->name('delete');
        Route::get('fiche/{alert}', 'AlertController@generate_pdf_RC')->name('pdf');
    });

    /* To make both gestionnaire & simple users view list alerts */
    Route::get('alertRF/list', 'Simple\AlertController@showRF')
    ->middleware('auth', 'general','role_or_permission:edit fournisseur|gestionnaire')
    ->name('alertRF.list'); 

    Route::get('alertRC/list', 'Simple\AlertController@showRC')
    ->middleware('auth','general', 'role_or_permission:edit client|gestionnaire')
    ->name('alertRC.list'); 

    Route::get('alertRP/list', 'Simple\AlertController@showRP')
    ->middleware('auth','general', 'role_or_permission:edit atelier|gestionnaire')
    ->name('alertRP.list'); 

    Route::get('alert/update/{alert}', 'Simple\AlertController@updateRead')
    ->middleware('auth','general')
    ->name('alert.updateRead'); 
    
    
                                /********** ADMIN USER Routes ***********/

/* Admin authentication accueil route */
Route::get('admin/accueil',function () { return view('admin.accueil');})
->middleware('auth','general', 'role:admin')
->name('admin.accueil');

/* User CRUD Routes for admin user only */
Route::group([
    'as' => 'user.',
    'prefix' => 'user', 
    'namespace'=>'Admin', 
    'middleware' => ['auth','general', 'role:admin', 'can:edit user']],
    function(){
        Route::get('dashbord', 'UserController@index')->name('dashbord');
        Route::get('create', 'UserController@create')->name('create');
        Route::post('create', 'UserController@store')->name('store');
        Route::get('edit/{user}', 'UserController@edit')->name('edit');
        Route::post('update/{user}', 'UserController@update')->name('update');
        Route::delete('delete/{user}', 'UserController@delete')->name('delete');
    });

/* Role CRUD Routes for admin user only */
Route::group([
    'as' => 'role.',
    'prefix' => 'role', 
    'namespace'=>'Admin', 
    'middleware' => ['auth', 'general','role:admin', 'can:edit user']],
    function(){
        Route::get('dashbord', 'RoleController@index')->name('dashbord');
        Route::get('create', 'RoleController@create')->name('create');
        Route::post('create', 'RoleController@store')->name('store');
        Route::get('edit/{role}', 'RoleController@edit')->name('edit');
        Route::post('update/{role}', 'RoleController@update')->name('update');
        Route::delete('delete/{role}', 'RoleController@delete')->name('delete');
    });

/* Permision CRUD Routes for admin user only */
Route::group([
    'as' => 'permission.',
    'prefix' => 'permission', 
    'namespace'=>'Admin', 
    'middleware' => ['auth', 'general','role:admin' , 'can:edit user']],
    function(){
        Route::get('dashbord', 'PermissionController@index')->name('dashbord');
        Route::get('create', 'PermissionController@create')->name('create');
        Route::post('create', 'PermissionController@store')->name('store');
        Route::get('edit/{permission}', 'PermissionController@edit')->name('edit');
        Route::post('update/{permission}', 'PermissionController@update')->name('update');
        Route::delete('delete/{permission}', 'PermissionController@delete')->name('delete');
    });


                            /********** Gestionnaire USER Routes ***********/
/* Gestionnaire authentication accueil route */
Route::get('gestionnaire/accueil',function () { return view('gestionnaire.accueil');})
->middleware('auth','general', 'role:gestionnaire')
->name('gestionnaire.accueil');

/* Action CRUD Routes for gestionnaire user */
Route::group([
    'as' => 'action.',
    'prefix' => 'action', 
    'namespace'=>'Gestionnaire', 
    'middleware' => ['auth','general', 'role:gestionnaire']],
    function(){
        Route::get('list', 'ActionController@index')->name('list');
        Route::get('create', 'ActionController@create')->name('create');
        Route::post('create', 'ActionController@store')->name('store');
        Route::get('edit/{action}', 'ActionController@edit')->name('edit');
        Route::post('update/{action}', 'ActionController@update')->name('update');
        Route::delete('delete/{action}', 'ActionController@delete')->name('delete');
    });
    
/* Anomalie CRUD Routes for gestionnaire user */
Route::group([
    'as' => 'anomalie.',
    'prefix' => 'anomalie', 
    'namespace'=>'Gestionnaire', 
    'middleware' => ['auth','general', 'role:gestionnaire']],
    function(){
        Route::get('dashbord', 'AnomalieController@index')->name('dashbord');
        Route::get('create', 'AnomalieController@createFromScratch')->name('createFromScratch');
        Route::get('create/{id}', 'AnomalieController@createFrom')->name('createFrom');
        Route::post('create-step1', 'AnomalieController@postCreateStep1')->name('create-step1');
        Route::post('create-step2', 'AnomalieController@postCreateStep2')->name('create-step2');
        Route::post('create-step3', 'AnomalieController@postCreateStep3')->name('create-step3');
        Route::post('store', 'AnomalieController@store')->name('create-step4');
        Route::delete('delete/{anomalie}', 'AnomalieController@delete')->name('delete');
        Route::get('previous/{anomalie}', 'AnomalieController@previous')->name('previous');
        Route::get('pdf/{anomalie}', 'AnomalieController@generate_pdf')->name('pdf'); 
        Route::get('view/{anomalie}', 'AnomalieController@view')->name('view');
        Route::get('export', 'AnomalieController@export')->name('export');
    });

/* Inspection CRUD Routes for gestionnaire user */
Route::group([
    'as' => 'inspection.',
    'prefix' => 'inspection', 
    'namespace'=>'Gestionnaire', 
    'middleware' => ['auth', 'general','role:gestionnaire']],
    function(){
        Route::get('dashbord', 'InspectionController@index')->name('dashbord');
        Route::get('create', 'InspectionController@create')->name('create');
        Route::get('create/{id}', 'InspectionController@createFrom')->name('createFrom');
        Route::post('create-step1', 'InspectionController@postCreateStep1')->name('create-step1');
        Route::post('create-step2', 'InspectionController@postCreateStep2')->name('create-step2');
        Route::post('store', 'InspectionController@store')->name('create-step3');
        Route::delete('delete/{inspection}', 'InspectionController@delete')->name('delete');
        Route::get('previous/{inspection}', 'InspectionController@previous')->name('previous');
        Route::get('edit/{inspection}', 'InspectionController@edit')->name('edit');
        Route::get('pdf/{inspection}', 'InspectionController@generate_pdf')->name('pdf'); 
        Route::get('view/{inspection}', 'InspectionController@view')->name('view');
        Route::get('export', 'InspectionController@export')->name('export');
    });

/* Audit CRUD Routes for gestionnaire user */
Route::group([
    'as' => 'audit.',
    'prefix' => 'audit', 
    'namespace'=>'Gestionnaire', 
    'middleware' => ['auth','general', 'role:gestionnaire']],
    function(){
        Route::get('dashbord', 'AuditController@index')->name('dashbord');
        Route::get('create', 'AuditController@create')->name('create');
        Route::get('create/{id}', 'AuditController@createFrom')->name('createFrom');
        Route::post('create-step1', 'AuditController@postCreateStep1')->name('create-step1');
        Route::post('create-step2', 'AuditController@postCreateStep2')->name('create-step2');
        Route::post('store', 'AuditController@store')->name('create-step3');
        Route::delete('delete/{audit}', 'AuditController@delete')->name('delete');
        Route::delete('deleteQ/{questionnaire}', 'AuditController@deleteQ')->name('deleteQ');
        Route::get('previous/{audit}', 'AuditController@previous')->name('previous');
        Route::get('edit/{audit}', 'AuditController@edit')->name('edit');
        Route::get('pdf/{audit}', 'AuditController@generate_pdf')->name('pdf'); 
        Route::get('view/{audit}', 'AuditController@view')->name('view');
        Route::get('export', 'AuditController@export')->name('export');
    });


/* Calendrier CRUD Routes for gestionnaire user */
Route::group([
    'as' => 'calendrier.',
    'prefix' => 'calendrier', 
    'namespace'=>'Gestionnaire', 
    'middleware' => ['auth','general', 'role:gestionnaire']],
    function(){
        Route::get('/', 'CalendrierController@index')->name('dashbord');
        Route::post('/create','CalendrierController@create');
        Route::post('/update','CalendrierController@update');
        Route::post('/delete','CalendrierController@destroy');
    });

/* Test CRUD Routes for gestionnaire user */
Route::group([
    'as' => 'test.',
    'prefix' => 'test', 
    'namespace'=>'Gestionnaire', 
    'middleware' => ['auth','general', 'role:gestionnaire']],
    function(){
        Route::get('list', 'TestController@show')->name('list');
        Route::get('create', 'TestController@create')->name('create');
        Route::post('create', 'TestController@store')->name('store');
        Route::get('edit/{test}', 'TestController@edit')->name('edit');
        Route::post('update/{test}', 'TestController@update')->name('update');
        Route::delete('delete/{test}', 'TestController@delete')->name('delete');
        Route::get('createExamen', 'TestController@createExamen')->name('createExamen');
        Route::post('createExamen','TestController@storeExamen')->name('storeExamen');
    });


/* Régle qualité CRUD Routes for gestionnaire user */
Route::group([
    'as' => 'regle.',
    'prefix' => 'regle', 
    'namespace'=>'Gestionnaire', 
    'middleware' => ['auth','general', 'role:gestionnaire']],
    function(){
        Route::get('list', 'RegleController@show')->name('list');
        Route::get('create', 'RegleController@create')->name('create');
        Route::post('create', 'RegleController@store')->name('store');
        Route::get('edit/{regle}', 'RegleController@edit')->name('edit');
        Route::post('update/{regle}', 'RegleController@update')->name('update');
        Route::delete('delete/{regle}', 'RegleController@delete')->name('delete');
    });

    Route::group([ 
        'namespace'=>'Front', 
        'middleware' => ['auth'] ],
        function(){
            Route::get('index123', 'UserController@Getindex');  
        });

/* Statistiques routes */
Route::group([
    'as' => 'statistiques.',
    'namespace'=>'Gestionnaire', 
    'prefix' => 'statistiques', 
    'middleware' => ['auth', 'general','role:gestionnaire|admin']],
    function(){     
        Route::get('retour/{year}', 'StatistiquesController@indexRetour')->name('retour');
        Route::get('article/{year}', 'StatistiquesController@indexArticle')->name('article');
        Route::get('audit/{year}', 'StatistiquesController@indexAudit')->name('audit');
        Route::get('inspection/{year}', 'StatistiquesController@indexInspection')->name('inspection');
        Route::get('retourClient/{year}', 'StatistiquesController@indexRetourClient')->name('retourClient');
        Route::get('retourFournisseur/{year}', 'StatistiquesController@indexRetourFournisseur')->name('retourFournisseur');
        Route::get('retourProduction/{year}', 'StatistiquesController@indexRetourProduction')->name('retourProduction');
    });

                            /********** SIMPLE USER ***********/
/* Simple user authentication accueil route */
Route::get('simple/accueil',function () { return view('simple.accueil');})
->middleware('auth','general', 'role:simple')
->name('simple.accueil');

/* Produit CRUD Routes for simple user */
Route::group([
    'as' => 'produit.',
    'prefix' => 'produit', 
    'namespace'=>'Simple', 
    'middleware' => ['auth','general', 'role:simple']],
    function(){
        Route::get('list', 'ProduitController@index')->name('list');
        Route::get('create', 'ProduitController@create')->name('create');
        Route::post('create', 'ProduitController@store')->name('store');
        Route::get('edit/{produit}', 'ProduitController@edit')->name('edit');
        Route::post('update/{produit}', 'ProduitController@update')->name('update');
        Route::delete('delete/{produit}', 'ProduitController@delete')->name('delete');
        Route::get('export', 'ProduitController@export')->name('export');
        Route::post('import', 'ProduitController@import')->name('import');
    });
/* Client CRUD Routes for simple user */
Route::group([
    'as' => 'client.',
    'prefix' => 'client', 
    'namespace'=>'Simple', 
    'middleware' => ['auth', 'general','permission:edit client']],
    function(){
        Route::get('list', 'ClientController@index')->name('list');
        Route::get('create', 'ClientController@create')->name('create');
        Route::post('create', 'ClientController@store')->name('store');
        Route::get('edit/{client}', 'ClientController@edit')->name('edit');
        Route::post('update/{client}', 'ClientController@update')->name('update');
        Route::delete('delete/{client}', 'ClientController@delete')->name('delete');
        Route::get('export', 'ClientController@export')->name('export');
        Route::post('import', 'ClientController@import')->name('import');
    });
/* Fournisseur CRUD Routes for simple user */
Route::group([
    'as' => 'fournisseur.',
    'prefix' => 'fournisseur', 
    'namespace'=>'Simple', 
    'middleware' => ['auth','general', 'permission:edit fournisseur']],
    function(){
        Route::get('list', 'FournisseurController@index')->name('list');
        Route::get('create', 'FournisseurController@create')->name('create');
        Route::post('create', 'FournisseurController@store')->name('store');
        Route::get('edit/{fournisseur}', 'FournisseurController@edit')->name('edit');
        Route::post('update/{fournisseur}', 'FournisseurController@update')->name('update');
        Route::delete('delete/{fournisseur}', 'FournisseurController@delete')->name('delete');
        Route::get('export', 'FournisseurController@export')->name('export');
        Route::post('import', 'FournisseurController@import')->name('import');
    });




    
/* Atelier CRUD Routes for simple user */
Route::group([
    'as' => 'atelier.',
    'prefix' => 'atelier', 
    'namespace'=>'Simple', 
    'middleware' => ['auth','general', 'permission:edit atelier']],
    function(){
        Route::get('list', 'AtelierController@index')->name('list');
        Route::get('create', 'AtelierController@create')->name('create');
        Route::post('create', 'AtelierController@store')->name('store');
        Route::get('edit/{atelier}', 'AtelierController@edit')->name('edit');
        Route::post('update/{atelier}', 'AtelierController@update')->name('update');
        Route::delete('delete/{atelier}', 'AtelierController@delete')->name('delete');
        Route::get('export', 'AtelierController@export')->name('export');
        Route::post('import', 'AtelierController@import')->name('import');
    });


<file_sep><?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAuditsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('audits', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->text('titre');
            $table->text('description')->nullable(); 

            $table->integer('step')->default(1);
            $table->enum('etat', ['nouveau','en cours','traité'])->default('nouveau');
            
            $table->text('resultats')->nullable();
            $table->text('commentaire')->nullable();
            $table->string('productimg')->nullable();
            $table->unsignedBigInteger('user_id')->nullable(); 
            $table->unsignedBigInteger('atelier_id')->nullable();
            $table->unsignedBigInteger('procede_id')->nullable();
            $table->timestamps();

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        /*Schema::table('alerts', function (Blueprint $table) {
            $table->dropForeign('alerts_event_id_foreign');
            $table->dropColumn('event_id');
            $table->dropForeign('alerts_anomalie_id_foreign');
            $table->dropColumn('anomalie_id');
        }); */
        Schema::dropIfExists('audits');
    }
}
<file_sep><?php

namespace App\Imports;

use App\Models\Produit;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class ProduitsImport implements ToModel,WithHeadingRow
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        return new Produit([
            'nom'     => $row['nom'],
            'modele'    => $row['modele'], 
            'reference'    => $row['reference'], 
            'description'    => $row['description'], 
            'type'    => $row['type'], 
            'prix'    => $row['prix'],     
        ]);
    }
}
<file_sep><?php

use Illuminate\Database\Seeder;

class LotsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('lots')->insert([ 
            'id' => '2',
            'titre' => '',
            'quantite' => '10',
            'caracteristiquep' => '2 m',
            'produit_id' => '10',
        ]);

        DB::table('lots')->insert([ 
            'id' => '1',
            'titre' => '',
            'quantite' => '45',
            'caracteristiquep' => 'Vert',
            'produit_id' => '8',           
        ]);

        DB::table('lots')->insert([ 
            'id' => '3',
            'titre' => '',
            'quantite' => '45',
            'caracteristiquep' => 'Rouge',
            'produit_id' => '11',           
        ]);

        DB::table('lots')->insert([ 
            'id' => '4',
            'titre' => '',
            'quantite' => '20',
            'caracteristiquep' => 'Female',
            'produit_id' => '9',           
        ]);


    }
}
<file_sep><?php

namespace App\Http\Controllers\Simple;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Fournisseur;
use App\Exports\FournisseursExport;
use App\Imports\FournisseursImport;
use Maatwebsite\Excel\Facades\Excel;

class FournisseurController extends Controller
{
        /**
    * @return \Illuminate\Support\Collection
    */
    public function export(){
        return Excel::download(new FournisseursExport, 'fournisseurs.xlsx');
    }
   
    /**
    * @return \Illuminate\Support\Collection
    */
    public function import(){
        Excel::import(new FournisseursImport,request()->file('file'));
        return back();
    }

    public function index(){
        $fournisseurs = Fournisseur::paginate(15);
        return view('simple.fournisseur.index',compact('fournisseurs'));
    }

    public function create(){ 
        $actionForm = route('fournisseur.create');
        return view('simple.fournisseur.form', compact('actionForm'));
    }

    public function store(Request $request){
        $this->validate($request,[
            'nom' => 'required',
            'description' => 'required',
            'adresse' => 'required'
        ]);
        $fournisseur = new Fournisseur;
        $fournisseur->nom = $request->nom; 
        $fournisseur->description = $request->description; 
        $fournisseur->adresse = $request->adresse; 
        $fournisseur->save();
        return redirect(route('fournisseur.list'))->with('successMsg',"Le fournisseur est ajouté avec succès");
    }

    public function edit(Fournisseur $fournisseur){   
        $actionForm = route('fournisseur.update', ['fournisseur' => $fournisseur]);
        return view('simple.fournisseur.form',compact('fournisseur','actionForm'));
    }

    public function update(Request $request, Fournisseur $fournisseur){
        $this->validate($request,[
            'nom' => 'required',
            'description' => 'required',
            'adresse' => 'required'
        ]);
        $fournisseur->nom = $request->nom; 
        $fournisseur->description = $request->description; 
        $fournisseur->adresse = $request->adresse; 
        $fournisseur->save();
        return redirect(route('fournisseur.list'))->with('successMsg',"Le fournisseur est modifié avec succès");
    }

    public function delete(Fournisseur $fournisseur){
        $fournisseur->delete();
        return redirect(route('fournisseur.list'));
    }
}
<file_sep><?php

namespace App\Http\Controllers\Simple;
use DB;
use Illuminate\Database\Eloquent\Model;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Alert;
use App\Models\Lot;
use App\Models\Produit;
use App\Models\Caracteristique;
use App\Models\Atelier;
use App\Models\Client;
use App\Models\Fournisseur;
use App\Models\Anomalie;
use App\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use PDF;

class AlertController extends Controller
{
    public function updateRead(Request $request, Alert $alert){
        $alert->etat = "en cours";
        $alert->save();
        return back();
    }

    /*----------------- CRUD alertRF --------------------*/
    public function createRF(){ 
        $action = route('alertRF.create');
        return view('simple.alert.formRF', compact('action'));
    }

    public function storeRF(Request $request){
        $this->validate($request,[
            'fournisseur' => 'required',
            'produit' => 'required',
            'caracteristiquep' => 'required',
            'quantite' => ['required','integer']
        ]);
           
        $alert = new Alert;
        $lot = new Lot;
        $alert->type = 'Retour fournisseur';
        if(!empty($request->description)) {
            $alert->description= $request->description; 
        }
        if(!empty($request->motif)) {
            $alert->motif= $request->motif; 
        }
        $alert->fournisseur_id = $request->fournisseur;
        $lot_id = DB::table('lots')->insertGetId([
            'quantite' => $request->quantite, 
            'caracteristiquep' => $request->caracteristiquep, 
            'produit_id' => $request->produit
            ]); 
        /* notify the QHSE user */
        $users = User::whereHas("roles", function($q){ $q->where("name", "gestionnaire"); })->get();
        $alert->user_id = $users[0]->id;
        $alert->sent = 0;
        $alert->etat = "nouveau";

        /* automaticly create an associated anomaly */
        $anomalie = new Anomalie;
        $anomalie->lot_id = $lot_id;
        $anomalie->fournisseur_id = $request->fournisseur;
        $anomalie->type = 'Retour fournisseur';
        $anomalie->step = 1;
        $anomalie->etat = "nouveau";
        $anomalie->created_at = Carbon::now();
        $anomalie->updated_at = Carbon::now();
        if(!empty($request->description)) {
            $anomalie->description= $request->description; 
        }           
        $anomalie->save();

        $alert->anomalie_id = $anomalie->id; 
        $alert->lot_id = $lot_id; 
        $alert->save();

        if(!empty($request->motif)) {
            $anomalie->titre = $alert->motif. ' N°'.$anomalie->id;
        }
        else{
            $anomalie->titre = '';
        }    
        $anomalie->save(); 

        return redirect(route('alertRF.list'))->with('successMsg',"Création d'une nouvelle alerte");
    }

    public function showRF(){    
        
        $alerts = Alert::where('type', '=',  'Retour fournisseur' )->orderBy('id','desc')->paginate(15);
        return view('simple.alert.listRF',compact('alerts'));
    }

    public function editRF(Alert $alert){   
        $action = route('alertRF.update', ['alert' => $alert]);
        return view('simple.alert.formRF',compact('alert','action'));
    }

    public function updateRF(Request $request, Alert $alert){
        $this->validate($request,[
            'fournisseur' => 'required',
            'produit' => 'required',
            'caracteristiquep' => 'required',
            'quantite' => ['required','integer'],
        ]);
        if(!empty($request->description)) {
            $alert->description= $request->description; 
        }
        else{
            $alert->description= '';
        }

        if(!empty($request->motif)) {
            $alert->motif= $request->motif; 
        }        
        else{
            $alert->motif= '';
        }
        $alert->fournisseur_id = $request->fournisseur;
           
        $update_lot = DB::table('lots')
        ->where('id', $alert->lot_id )
        ->update([
            'quantite' => $request->quantite,             
            'caracteristiquep' => $request->caracteristiquep, 
            'produit_id' => $request->produit
            ]);

        $anomalie = Anomalie::where('id','=',$alert->anomalie_id)->first();
        $anomalie->lot_id = $alert->lot_id;
        $anomalie->fournisseur_id = $request->fournisseur_id;
        $anomalie->type = 'Retour fournisseur';
        $anomalie->step = 1;
        $anomalie->etat = "nouveau";
        $anomalie->created_at = Carbon::now();
        $anomalie->updated_at = Carbon::now();
        if(!empty($request->description)) {
            $anomalie->description= $request->description; 
        }           
        else{
            $anomalie->description = '';
        }     

        if(!empty($request->motif)) {
            $anomalie->titre = $request->motif. ' N°'.$anomalie->id;
        }
        else{
            $anomalie->titre = '';
        }    
        $anomalie->save();

        $alert->save();
        return redirect(route('alertRF.list'))->with('successMsg','Modification alerte réussiée');
    }

    public function deleteRF(Alert $alert){
        DB::table('lots')->where('id', $alert->lot_id )->delete();
        DB::table('anomalies')->where('id', $alert->anomalie_id )->delete();
        $alert->delete();
        return redirect(route('alertRF.list'));
    }
    
    function generate_pdf_RF(Alert $alert) {
        $pdf = PDF::loadView('pdf.ficheRF', compact('alert'));
        return $pdf->stream('Fiche.pdf');
    }
    
    public function viewRF(Alert $alert){     
        return view('simple.alert.viewRF',compact('alert'));
    }

    /*----------------- CRUD alertRC --------------------*/

    public function createRC(){ 
        $action = route('alertRC.create');
        return view('simple.alert.formRC', compact('action'));
    }

    public function storeRC(Request $request){
        $this->validate($request,[
            'client' => 'required',
            'caracteristiquep' => 'required',
            'quantite' => ['required','integer'],
            'produit' => 'required',
        ]);
        $alert = new Alert;
        $lot = new Lot;
        $alert->type = 'Retour client';
        if(!empty($request->description)) {
            $alert->description= $request->description; 
        }
        if(!empty($request->motif)) {
            $alert->motif= $request->motif; 
        }
        $alert->client_id = $request->client;
        /* notify the QHSE user */
        $users = User::whereHas("roles", function($q){ $q->where("name", "gestionnaire"); })->get();
        $alert->user_id = $users[0]->id;
        $alert->sent = 0;
        $alert->etat = "nouveau";

        $lot_id = DB::table('lots')->insertGetId([
            'quantite' => $request->quantite, 
            'produit_id' => $request->produit , 
            'caracteristiquep' => $request->caracteristiquep
        ]); 

        /* automaticly create an associated anomaly */
        $anomalie = new Anomalie;
        $anomalie->lot_id = $lot_id;
        $anomalie->client_id = $request->client;
        $anomalie->type = 'Retour client';
        $anomalie->step = 1;
        $anomalie->etat = "nouveau";
        $anomalie->created_at = Carbon::now();
        $anomalie->updated_at = Carbon::now();
        if(!empty($request->description)) {
            $anomalie->description= $request->description; 
        }           
        $anomalie->save();

        $alert->anomalie_id = $anomalie->id; 
        $alert->lot_id = $lot_id; 
        $alert->save();

        if(!empty($request->motif)) {
            $anomalie->titre = $request->motif. ' N°'.$anomalie->id;
        }
        else{
            $anomalie->titre = '';
        }    
        $anomalie->save();

        return redirect(route('alertRC.list'))->with('successMsg',"Création d'une nouvelle alerte");
    }

    public function showRC(){    
       
        $alerts = Alert::where('type', '=',  'Retour client' )
        ->orderBy('id','desc')->paginate(15);
        return view('simple.alert.listRC',compact('alerts'));
    }

    public function editRC(Alert $alert){   
        $action = route('alertRC.update', ['alert' => $alert]);
        return view('simple.alert.formRC',compact('alert','action'));
    }

    public function updateRC(Request $request, Alert $alert){
        $this->validate($request,[
            'client' => 'required',
            'quantite' => ['required','integer'],
            'produit' => 'required',
            'caracteristiquep' => 'required'
        ]);
           
            $alert->type = 'Retour client';
            if(!empty($request->description)) {
                $alert->description= $request->description; 
            }
            else{
                $alert->description= '';
            }  

            if(!empty($request->motif)) {
                $alert->motif= $request->motif; 
            }
            else{
                $alert->motif= '';
            }
            $alert->client_id = $request->client;
            $alert->sent = 0;

            $update_lot = DB::table('lots')
                ->where('id', $alert->lot_id )
                ->update(['quantite' => $request->quantite, 'produit_id' => $request->produit ,
                'caracteristiquep' => $request->caracteristiquep]);

            $anomalie = Anomalie::where('id','=',$alert->anomalie_id)->first();
            $anomalie->lot_id = $alert->lot_id;
            $anomalie->client_id = $alert->client_id;
            $anomalie->type = 'Retour client';
            $anomalie->step = 1;
            $anomalie->etat = "nouveau";
            if(!empty($request->description)) {
                $anomalie->description= $request->description; 
            }
            else{
                $anomalie->description= '';
            }    

            if(!empty($request->motif)) {
                $anomalie->titre = $request->motif. ' N°'.$anomalie->id;
            }
            else{
                $anomalie->titre = '';
            }    

            $anomalie->save();

            $alert->save();
            return redirect(route('alertRC.list'))->with('successMsg','Modification alerte réussiée');
    }

    public function deleteRC(Alert $alert){
        DB::table('lots')->where('id', $alert->lot_id )->delete();
        DB::table('anomalies')->where('id', $alert->anomalie_id )->delete();
        $alert->delete();
        return redirect(route('alertRC.list'));
    }
    
    public function viewRC(Alert $alert){     
        return view('simple.alert.viewRC',compact('alert'));
    }

    function generate_pdf_RC(Alert $alert){
        $pdf = PDF::loadView('pdf.ficheRC', compact('alert'));
        return $pdf->stream('Fiche.pdf');
    }

    /*----------------- CRUD alertRP --------------------*/

    public function createRP(){ 
      $action = route('alertRP.create');
      return view('simple.alert.formRP', compact('action'));
    }

    public function storeRP(Request $request){
        $this->validate($request,[
             'atelier' => 'required',
             'quantite' => ['required','integer'],
             'produit' => 'required',
             'caracteristiquep' => 'required'
           ]);
           
            $alert = new Alert;
            $lot = new Lot;
            $alert->type = 'Retour production';
            if(!empty($request->description)) {
                $alert->description= $request->description; 
            }
            if(!empty($request->motif)) {
                $alert->motif= $request->motif; 
            }
            $alert->atelier_id = $request->atelier;
            $lot_id = DB::table('lots')->insertGetId(
                ['quantite' => $request->quantite, 'produit_id' => $request->produit ,
                'caracteristiquep' => $request->caracteristiquep]
            ); 

            /* notify the QHSE user */
            $users = User::whereHas("roles", function($q){ $q->where("name", "gestionnaire"); })->get();
            $alert->user_id = $users[0]->id;
            $alert->sent = 0;
            $alert->etat = "nouveau";

            /* automaticly create an associated anomaly */
            $anomalie = new Anomalie;
            $anomalie->lot_id = $lot_id;
            $anomalie->atelier_id = $request->atelier;
            $anomalie->type = 'Retour production';
            $anomalie->step = 1;
            $anomalie->etat = "nouveau";
            $anomalie->created_at = Carbon::now();
            $anomalie->updated_at = Carbon::now();
            if(!empty($request->description)) {
                $anomalie->description= $request->description; 
            }           
            $anomalie->save();
            
            $alert->anomalie_id = $anomalie->id; 
            $alert->lot_id = $lot_id; 
            $alert->save();

            if(!empty($request->motif)) {
                $anomalie->titre = $request->motif. ' N°'.$anomalie->id;
            }
            else{
                $anomalie->titre = '';
            }    

            $anomalie->save();
            return redirect(route('alertRP.list'))->with('successMsg',"Création d'une nouvelle alerte");
    }

    public function showRP(){    
      
        $alerts = Alert::where('type', '=',  'Retour production' )->orderBy('id','desc')->paginate(15);
        return view('simple.alert.listRP',compact('alerts'));
    }

    public function editRP(Alert $alert){   
        $action = route('alertRP.update', ['alert' => $alert]);
        return view('simple.alert.formRP',compact('alert','action'));
    }

    public function updateRP(Request $request, Alert $alert){
        $this->validate($request,[
            'atelier' => 'required',
            'quantite' => ['required','integer'],
            'produit' => 'required',
            'caracteristiquep' => 'required'
        ]);
           
            $alert->type = 'Retour production';
            if(!empty($request->description)) {
                $alert->description= $request->description; 
            }
            else{
                $alert->description= "";
            }
            
            if(!empty($request->motif)) {
                $alert->motif= $request->motif; 
            }
            else{
                $alert->motif= '';
            }
            $alert->atelier_id = $request->atelier;
           
            $update_lot = DB::table('lots')
              ->where('id', $alert->lot_id )
              ->update(['quantite' => $request->quantite, 'produit_id' => $request->produit ,
               'caracteristiquep' => $request->caracteristiquep]);
            
            $anomalie = Anomalie::where('id','=',$alert->anomalie_id)->first();
            $anomalie->lot_id = $alert->lot_id;
            $anomalie->atelier_id = $request->atelier_id;
            $anomalie->type = 'Retour production';
            $anomalie->step = 1;
            $anomalie->etat = "nouveau";
            if(!empty($request->description)) {
                $anomalie->description= $request->description; 
            }     
            else{
                $anomalie->description= '';
            }             
            
            if(!empty($request->motif)) {
                $anomalie->titre = $request->motif. ' N°'.$anomalie->id;
            }
            else{
                $anomalie->titre = '';
            }    

            $anomalie->save();

            $alert->save();
            return redirect(route('alertRP.list'))->with('successMsg','Modification alerte réussiée');
    }

    public function deleteRP(Alert $alert){
        DB::table('lots')->where('id', $alert->lot_id )->delete();
        DB::table('anomalies')->where('id', $alert->anomalie_id )->delete();
        $alert->delete();
        return redirect(route('alertRP.list'));
    }

    function generate_pdf_RP(Alert $alert) {
        
        $pdf = PDF::loadView('pdf.ficheRP', compact('alert'));
        return $pdf->stream('Fiche.pdf');
    }

    public function viewRP(Alert $alert){     
        return view('simple.alert.viewRP',compact('alert'));
    }

}
<file_sep><?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAlertsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('alerts', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('sent')->default(0);
            $table->enum('etat', ['nouveau','en cours', 'traité'])->nullable();

            $table->enum('type', ['Rappel','Retour fournisseur', 'Retour client', 'Retour production']);
            $table->text('description')->nullable();
            $table->text('motif')->nullable();
            $table->date('start')->nullable(); //for calendar

            $table->unsignedBigInteger('lot_id')->nullable();
            $table->unsignedBigInteger('client_id')->nullable();
            $table->unsignedBigInteger('fournisseur_id')->nullable();
            $table->unsignedBigInteger('atelier_id')->nullable();
            $table->unsignedBigInteger('user_id')->nullable(); /* receiver of the alert */
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('alerts');
    }
}
<file_sep><?php

namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use App\User;
use App\Models\Alert;
use App\Models\Event;
use App\Models\Inspection;
use App\Models\Audit;
use App\Helpers\Helper;
use DB;
use Closure;
use Carbon\Carbon;

class GeneralMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next){
        if(Auth::user()){
            $this->deleteEventsRelations();
            $this->createEventsAlert();
            $this->displayAlerts($request);
        }
        return $next($request);
    }

    public function deleteEventsRelations(){
        $audits = Audit::all();
        foreach ($audits as $audit) {
            if( count(Event::where('audit_id','=',$audit->id)->get()) == 0 ){
                $audit->delete();
            }
        }

        $inspections = Inspection::all();
        foreach ($inspections as $inspection) {
            if( count(Event::where('inspection_id','=',$inspection->id)->get()) == 0 ){
                $inspection->delete();
            }
        }
    }

    public function createEventsAlert(){
        $eventsARappeler = Event::where('rappel','=','true')->get(); // reduce the for loop
        foreach($eventsARappeler as $event) {
            if($event->alert_id == null){
                $alert= new Alert;
                $alert->type = "Rappel";
                $alert->start = $event->start;
                $alert->user_id = $event->user_id;
                $alert->event_id = $event->id;
                $alert->save();
                $event->alert_id = $alert->id;
                $event->save();
            }
            elseif($event->alert->start != $event->start){
                $event->alert->start = $event->start;
                $event->alert->etat= null;
                $event->alert->save();
            }
        }    
    }

    public function displayAlerts(Request $request){
        $alerts = Alert::where('user_id','=',Auth::user()->id)
                        ->where('sent','=',0)
                        ->whereNotIn('etat', ["en cours","traité"])
                        ->orWhereNull('etat')->get();
        foreach ($alerts as $alert) {
            $currentDate = Carbon::now()->toDateString();
            $currentDateT = Carbon::parse($currentDate)->timestamp;
            $startT = Carbon::parse($alert->start)->timestamp;
            $difference = $startT - $currentDateT;              
            if(($alert->type == "Rappel") && ($difference < 96400)  && ($difference > 3600) )  {
                $alert->etat= "nouveau";
                $alert->save();
            }
            if($alert->type != "Rappel"){
                $alert->sent=1;
                $alert->save();
            }
        }
        $toasts = array();
        $aF = $alerts->where('type','=','Retour fournisseur');
        $aP = $alerts->where('type','=','Retour production');
        $aC = $alerts->where('type','=','Retour client');
        $toasts = array_add($toasts,0, count($aF));  
        $toasts = array_add($toasts,1, count($aP));  
        $toasts = array_add($toasts,2, count($aC));
        $request->session()->put('toasts', $toasts);    
    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Produit extends Model
{
    protected $fillable = [
        'nom' , 'modele', 'reference','description','type','prix'
    ];

    public function caracteristiques()
    {
        return $this->hasMany('App\Models\Caracteristique');
    }
    public function procedes()
    {
        return $this->hasMany('App\Models\Procede');
    }
    public function lots()
    {
        return $this->hasMany('App\Models\Lot');
    } 

    public function fichiers()
    {
        return $this->hasMany('App\Models\Fichier');
    }

    public function regles()
    {
        return $this->hasMany('App\Models\Regle');
    }

    public function audits()
    {
        return $this->hasMany('App\Models\Audit');
    }

}
<file_sep><?php

use Illuminate\Database\Seeder;

class AlertsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
       /* DB::table('alerts')->insert([ 
            'id' => '1',
            'sent' => '0',
            'etat' => 'nouveau',
            'type' => 'Retour fournisseur',
            'description' => 'Retour ABS du fournisseur <NAME>',    
            'motif' => 'Mauvaise qualité de ABS', 
            'lot_id' => '1',  
            'fournisseur_id' => '13', 
            'user_id' => '5',   
            'anomalie_id' => '1',
            'created_at' => '2020-08-15 13:36:36',
            'updated_at' => '2020-08-15 13:36:36'           
        ]);

        DB::table('alerts')->insert([ 
            'id' => '2',
            'sent' => '0',
            'etat' => 'nouveau',
            'type' => 'Retour fournisseur',
            'description' => 'Retour Câble blanc du fournisseur <NAME>',    
            'motif' => 'Très faible conductivité', 
            'lot_id' => '2',  
            'fournisseur_id' => '3', 
            'user_id' => '5',   
            'anomalie_id' => '2',
            'created_at' => '2020-08-15 13:36:36',
            'updated_at' => '2020-08-15 13:36:36'           
        ]);
        
        DB::table('alerts')->insert([ 
            'id' => '3',
            'sent' => '0',
            'etat' => 'nouveau',
            'type' => 'Retour fournisseur',
            'description' => 'Retour PVC du fournisseur Bouhoun Pub',    
            'motif' => 'Faible qualité de PVC', 
            'lot_id' => '3',  
            'fournisseur_id' => '4', 
            'user_id' => '5',   
            'anomalie_id' => '3',
            'created_at' => '2020-08-15 13:36:36',
            'updated_at' => '2020-08-15 13:36:36'           
        ]);

        DB::table('alerts')->insert([ 
            'id' => '4',
            'sent' => '0',
            'etat' => 'nouveau',
            'type' => 'Retour fournisseur',
            'description' => 'Retour 3P plug au fournisseur Aitcom Pub',    
            'motif' => 'Réception une petite quantité (inférieure à la quantité achetée )', 
            'lot_id' => '4',  
            'fournisseur_id' => '2', 
            'user_id' => '5',   
            'anomalie_id' => '4',
            'created_at' => '2020-08-15 13:36:36',
            'updated_at' => '2020-08-15 13:36:36'           
        ]);  */

    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Examen extends Model
{
   
    public function test()
    {
       return $this->belongsTo('App\Test');
    }

    public function reponse()
    {
        return $this->hasOne('App\Models\Reponse');
    }
    
}
<file_sep><?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class ActionTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        
        DB::table('actions')->insert([ 
            'id' => '1',
            'type' => 'corrective',
            'designation' => 'Intervention service réparation',
            'description' => 'Réparation des articles défectueux par les réparateurs',
            'resultat' => 'Article mis en état et fonctionnel',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('actions')->insert([ 
            'id' => '2',
            'type' => 'corrective',
            'designation' => 'Intervention service maintenance',
            'description' => 'Maintenance de la machine de production',
            'resultat' => 'Machine en bon état de fonctionnement',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('actions')->insert([ 
            'id' => '3',
            'type' => 'corrective',
            'designation' => 'Arrêter la machine de production',
            'description' => 'Arrêt de la machine afin de diagnostiquer et corriger les problèmes et ensuite réparer la machine',
            'resultat' => 'Machine de production fonctionnelle',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);


        DB::table('actions')->insert([ 
            'id' => '4',
            'type' => 'corrective',
            'designation' => 'Intervention opérateur machine',
            'description' => 'Paramétrage et réglage de la machine de production',
            'resultat' => 'Machine de production paramétrée',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('actions')->insert([ 
            'id' => '5',
            'type' => 'corrective',
            'designation' => 'Instruction et ordres aux ouvriers',
            'description' => 'Donner des instructions aux ouvriers pour les orienter vers les bonnes pratiques de travail',
            'resultat' => 'Travail rigoureux et satisfaisant',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

    }
}
<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use App\Models\Alert;
use App\Models\Event;
use Illuminate\Support\Facades\Auth;
use DB;
use Carbon\Carbon;
use App\User;
use App\Helpers\Helper;
class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index(Request $request)
    {
        if (Auth::check() && Auth::user()->hasRole('admin')) {
            return redirect()->route('user.dashbord');
        } 
        elseif (Auth::check() &&  Auth::user()->hasRole('simple')) {
            return redirect()->route('produit.list');
        }     
        return view('main.accueil');
        
    }
}
<file_sep>function sweetSuccess(successMsg) {
    if(successMsg != ''){
        swal({
            title: "Bravo!",
            text: successMsg,
            type: "success",
            showConfirmButton: true
        });
    }
}

$('#toastr-warning-bottom-right').click(function() {
    toastr.warning('This Is warning Message','Bottom Right',{
        "positionClass": "toast-bottom-right",
        timeOut: 5000,
        "closeButton": true,
        "debug": false,
        "newestOnTop": true,
        "progressBar": true,
        "preventDuplicates": true,
        "onclick": null,
        "showDuration": "300",
        "hideDuration": "1000",
        "extendedTimeOut": "1000",
        "showEasing": "swing",
        "hideEasing": "linear",
        "showMethod": "fadeIn",
        "hideMethod": "fadeOut",
        "tapToDismiss": false

    })
});
<file_sep><?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class AtelierTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('ateliers')->insert([ 
            'id' => '1',
            'nom' => 'SMT',
            'metier' => 'Production des cartes électroniques pour la RAM et flashs disques',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('ateliers')->insert([ 
            'id' => '2',
            'nom' => 'Injection',
            'metier' => 'Injection plastique pour la souris,chargeurs et flashs disques',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('ateliers')->insert([
            'id' => '3',
            'nom' => 'Unité Production Câble',
            'metier' => 'Production des câbles alimenations et câbles USB',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('ateliers')->insert([ 
            'id' => '4',
            'nom' => 'Montage et emballage',
            'metier' => 'Monatge des souris et chargeurs ainsi que emballages de tous les produits',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
        DB::table('ateliers')->insert([ 
            'id' => '5',
            'nom' => 'Contrôle',
            'metier' => 'Test et contrôle des produits en cours de lors fabrication et les produits finis',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Charge extends Model
{
    public function anomalie()
    {
       return $this->belongsTo('App\Models\Anomalie');
    }
}
<file_sep><?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class ProduitTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('produits')->insert([ 
            'id' => '1',
            'nom' => 'Flash disque 2.0',
            'type' => 'Fini',
            'modele' => 'MANHATTAN',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '2',
            'nom' => 'Flash disque 3.0',
            'type' => 'Fini',
            'modele' => 'MANHATTAN',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '3',
            'nom' => 'Souris',
            'modele' => 'AS47',
            'type' => 'Fini',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '4',
            'nom' => 'Chargeur',
            'modele' => 'DIAMOND',
            'type' => 'Fini',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '5',
            'nom' => 'Câble USB',
            'modele' => 'CBL3IP',
            'type' => 'Fini',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '6',
            'nom' => '<NAME>',
            'modele' => 'CEA',
            'type' => 'Fini',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '7',
            'nom' => '<NAME>',
            'modele' => 'DDRIII',
            'type' => 'Fini',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '8',
            'nom' => 'ABS',
            'type' => 'Matiere premiere',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
        
        DB::table('produits')->insert([ 
            'id' => '9',
            'nom' => '3P plug',
            'type' => 'Matiere premiere',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '10',
            'nom' => 'Cable blanc',
            'type' => 'Matiere premiere',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '11',
            'nom' => 'PVC',
            'type' => 'Matiere premiere',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '12',
            'nom' => 'PCBA',
            'type' => 'Matiere premiere',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '13',
            'nom' => 'Connecteur USB',
            'type' => 'Semi-fini',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '14',
            'nom' => '<NAME>',
            'type' => 'Semi-fini',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '15',
            'nom' => 'Connecteur',
            'type' => 'Matiere premiere',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('produits')->insert([ 
            'id' => '16',
            'nom' => 'Câble',
            'type' => 'Matiere premiere',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);


    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;


class Test extends Model
{
    
    public function examens()
    {
        return $this->hasMany('App\Models\Examen');
    }

    public function inspections()
    {
        return $this->hasMany('App\Models\Inspection');
    }

}
<file_sep><?php

namespace App\Exports;

use App\Models\Anomalie;
use Maatwebsite\Excel\Concerns\Exportable;
use Illuminate\Contracts\View\View;

use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithTitle;

use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Concerns\WithEvents;

class AnomaliesExport implements FromQuery, WithTitle,WithHeadings,ShouldAutoSize,WithMapping,WithEvents{

    use Exportable;
    private $year;

    public function __construct(int $year){
        $this->year = $year;
    }

    public function map($anomalie): array{
        return [
            $anomalie->id,
            $anomalie->updated_at,
            $anomalie->titre,
            $anomalie->type,
            $anomalie->lot->produit->nom,
            $anomalie->lot->caracteristiquep,
            $anomalie->lot->quantite,
            $anomalie->criticite,
            $anomalie->test->nom,
            $anomalie->diagnostique,
            collect($anomalie->actions()->pluck('designation'))->implode('; '),
            collect($anomalie->regles()->pluck('titre'))->implode('; '),
            $anomalie->cause,
        ];
    }
    
    public function headings(): array{
        return [
            'Anomalie n°',
            'Date',
            'Titre',
            'Source',
            'Article',
            'Caracteristique',
            'Qté Retourné',
            'Criticité (%)',
            'Test réalisé',
            'Problème',
            'Actions Correctives',
            'Règles Enfreintes',
            'Cause racine',
        ];
    }

    public function query(){
        return Anomalie::where('etat','=','traité')->whereYear('updated_at',$this->year)->orderBy('updated_at','desc');
    }

    public function title(): string{
        return 'Journal des anomalies '.$this->year;
    }

    public function registerEvents(): array{
        $styleArray = [
            'borders' => [
                'allBorders' => [
                    'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
                    ],
                ],
            ];

            return [
                AfterSheet::class => function(AfterSheet $event) use($styleArray) {
                    $cpt = count(Anomalie::where('etat','=','traité')->whereYear('updated_at',$this->year)->get()) +1;
                    $cellRange = 'A1:M1'; 
                    $event->sheet->getStyle($cellRange)->ApplyFromArray($styleArray);
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setName('Calibri');
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);  
                    $event->sheet->getStyle('A2:A'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('B2:B'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('C2:C'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('D2:D'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('E2:E'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('F2:F'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('G2:G'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('H2:H'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('I2:I'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('J2:J'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('K2:K'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('L2:L'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('M2:M'.$cpt)->applyFromArray($styleArray);
                },
            ];
    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Procede extends Model
{
    public function atelier()
    {
       return $this->belongsTo('App\Models\Atelier');
    }
    public function produit()
    {
       return $this->belongsTo('App\Models\Produit');
    }

    public function audits()
    {
        return $this->hasMany('App\Models\Audit');
    }
}
<file_sep><?php

namespace App\Http\Controllers\Gestionnaire;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Regle;
use App\Models\User;
use App\Models\Produit;
use App\Models\Audit;
use Auth;
use App\Models\Anomalie;


class RegleController extends Controller
{
    public function index(){
         
    }

    public function create(){ 
      $action = route('regle.create');
      $produits = Produit::all();
      return view('quality.regle.form', compact('action','produits'));
    }

    public function store(Request $request){
        $this->validate($request,[
             'titre' => ['required'],
             'produit' => 'required',
             'contenu' => 'required'
        ]);
        $regle = new Regle;
        $regle->titre = $request->titre; 
        $regle->contenu = $request->contenu;
        $regle->user_id = Auth::user()->id; // Id de l'utilisateur authentifié
        if(!empty($request->id)){
            $anomalie = Anomalie::findOrFail($request->id);
            $regle->produit_id = $anomalie->lot->produit->id;
            $regle->save();
            return view('quality.anomalie.create', compact('anomalie'));
        }
        else{
            if(!empty($request->idAudit) ){
                $audit = Audit::findOrFail($request->idAudit);
                $regle->produit_id = $request->produit;
                $regle->save();
                return view('quality.audit.create', compact('audit'));
            }
            else{
                $regle->produit_id = $request->produit;
                $regle->save();
                return redirect(route('regle.list'))->with('successMsg',"Création d'une nouvelle règle qualité");
            }    
        }
    }

    public function show()
    {    
        $regles = Regle::paginate(10);
        return view('quality.regle.list',compact('regles'));
    }

    public function edit(Regle $regle)
    {   
        $action = route('regle.update', ['regle' => $regle]);
        $produits = Produit::all();
        return view('quality.regle.form',compact('regle','action','produits'));
    }

    public function update(Request $request, Regle $regle)
    {
        $this->validate($request,[
            'titre' => 'required',
            'produit' => 'required',
            'contenu' => 'required'
          ]);
   
          $regle->titre = $request->titre; 
          $regle->contenu = $request->contenu; 
          $regle->produit_id = $request->produit;
          $regle->user_id = Auth::user()->id; // Id de l'utilisateur authentifié
          $regle->save();
          return redirect(route('regle.list'))->with('successMsg',"Modification de la règle qualité");
    }

    public function delete(Regle $regle)
    {
        $regle->delete();
        return redirect(route('regle.list'));
    }
}
<file_sep><?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;

class UsersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('users')->insert([
            'id' => '1',
            'nom' => 'Ouared',
            'prenom' => 'Nabil',
            'numero_tel' => '+213550902696',
            'service' => 'SI',
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
        DB::table('users')->insert([
            'id' => '2',
            'nom' => 'Nacer',
            'prenom' => 'Thinhinane',
            'numero_tel' => '+213560208116',
            'service' => 'Production',
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
        DB::table('users')->insert([
            'id' => '3',
            'nom' => 'Bendjebbar',
            'prenom' => 'Loubna',
            'numero_tel' => '+213550902702',
            'service' => 'Achat & Stock',
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
        DB::table('users')->insert([
            'id' => '4',
            'nom' => 'Mimoune',
            'prenom' => 'Fahima',
            'numero_tel' => '+213550902702',
            'service' => 'Commerciale',
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
        DB::table('users')->insert([
            'id' => '5',
            'nom' => 'Mohamed',
            'prenom' => 'Dzanouni',
            'numero_tel' => '',
            'service' => 'QHSE',
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
       
        DB::table('users')->insert([
            'id' => '6',
            'nom' => 'Riche',
            'prenom' => '<NAME>',
            'numero_tel' => '',
            'service' => 'Réparation',
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
        DB::table('users')->insert([
            'id' => '7',
            'nom' => 'Hamraoui',
            'prenom' => 'Yasmine',
            'numero_tel' => '',
            'service' => 'Réparation',
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
        DB::table('users')->insert([
            'id' => '8',
            'nom' => 'Slimani',
            'prenom' => 'Nadia',
            'numero_tel' => '',
            'service' => 'Réparation',
            'email' => '<EMAIL>',
            'password' => bcrypt('<PASSWORD>'),
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);   
    }
}
<file_sep><?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
       $this->call(UsersTableSeeder::class);
       $this->call(RolesTableSeeder::class);  
       $this->call(PermissionsTableSeeder::class);  
       $this->call(Model_Has_PermissionsTableSeeder::class);  
       $this->call(Role_Has_PermissionsTableSeeder::class);  
       $this->call(Model_Has_RolesTableSeeder::class);  
       $this->call(ProduitTableSeeder::class);  
       $this->call(CaracteristiqueTableSeeder::class);  
       $this->call(ActionTableSeeder::class); 
       $this->call(TestTableSeeder::class); 
       $this->call(ExamenTableSeeder::class);  
       $this->call(RegleTableSeeder::class); 
       $this->call(AtelierTableSeeder::class); 
       $this->call(AlertsTableSeeder::class); 
       $this->call(ProcedesTableSeeder::class); 
       $this->call(LotsTableSeeder::class);   
       $this->call(ClientTableSeeder::class);  
       $this->call(FournisseurTableSeeder::class); 

    }
}
<file_sep><?php

namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class Event extends Model
{
    
    public function audit()
    {
        return $this->hasOne('App\Models\Audit');
    }

    public function inspection()
    {
        return $this->hasOne('App\Models\Inspection');
    }

    public function alert()
    {
        return $this->hasOne('App\Models\Alert');
    }
    
    public function user()
    {
        return $this->hasOne('App\User');
    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Attribut extends Model
{

    public function anomalie()
    {
       return $this->belongsTo('App\Models\Anomalie');
    }

    public function audit()
    {
       return $this->belongsTo('App\Models\Audit');
    }

    public function inspection()
    {
       return $this->belongsTo('App\Models\Inspection');
    }

    public function action()
    {
       return $this->belongsTo('App\Models\Action');
    }
    
}
<file_sep><?php

namespace App\Exports;

use App\Models\Inspection;
use Maatwebsite\Excel\Concerns\Exportable;
use Illuminate\Contracts\View\View;

use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithTitle;

use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Concerns\WithEvents;

class InspectionsExport implements FromQuery, WithTitle,WithHeadings,ShouldAutoSize,WithMapping,WithEvents{

    use Exportable;
    // use RegistersEventListeners;
    private $year;

    public function __construct(int $year)
    {
        $this->year = $year;
    }

    public function map($inspection): array
    {
        return [
            $inspection->updated_at,
            $inspection->titre,
            $inspection->lot->produit->nom,
            $inspection->lot->caracteristiquep,
            $inspection->lot->quantite,
            ($inspection->lot->quantite - $inspection->quantiteD),
            $inspection->quantiteD,
            number_format(($inspection->lot->quantite - $inspection->quantiteD)*100/$inspection->lot->quantite, 2, '.', ''),
            number_format($inspection->quantiteD*100/($inspection->lot->quantite), 2, '.', ''),
            $inspection->commentaire,
        ];
    }
    
    public function headings(): array
    {
        return [
            'Date',
            'Titre',
            'Article',
            'Caracteristique',
            'Qté Testé',
            'Bonne',
            'Défectueuse',
            '% Bonne',
            '% Défectueuse',
            'Observations',
        ];
    }

    public function query(){
        return Inspection::where('etat','=','traité')->whereYear('updated_at',$this->year)->orderBy('updated_at','desc');
    }

    public function title(): string{
        return 'Journal de qualité '.$this->year;
    }

    public function registerEvents(): array{
        $styleArray = [
            'borders' => [
                'allBorders' => [
                    'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
                    //'color' => ['argb' => 'FFFF0000'],
                    ],
                ],
            ];

            return [
                AfterSheet::class => function(AfterSheet $event) use($styleArray) {
                    $cpt = count(Inspection::where('etat','=','traité')->whereYear('updated_at',$this->year)->get()) +1;
                    $cellRange = 'A1:J1'; 
                    $event->sheet->getStyle($cellRange)->ApplyFromArray($styleArray);
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setName('Calibri');
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);  
                    $event->sheet->getStyle('A2:A'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('B2:B'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('C2:C'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('D2:D'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('E2:E'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('F2:F'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('G2:G'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('H2:H'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('I2:I'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('J2:J'.$cpt)->applyFromArray($styleArray);
  
                },
            ];
    }
}
<file_sep><?php

namespace App\Http\Controllers\Simple;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Produit;
use App\Models\Procede;
use App\Models\Caracteristique;
use App\Exports\ProduitsExport;
use App\Imports\ProduitsImport;
use Maatwebsite\Excel\Facades\Excel;

class ProduitController extends Controller
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function export(){
        return Excel::download(new ProduitsExport, 'Articles.xlsx');
    }
   
    /**
    * @return \Illuminate\Support\Collection
    */
    public function import(){
        Excel::import(new ProduitsImport,request()->file('file'));
        return back();
    }

    public function index(){
        return view('simple.produit.index');
    }

    public function create(){ 
        $actionForm = route('produit.create');
        return view('simple.produit.form', compact('actionForm'));
    }

    public function store(Request $request){
        $this->validate($request, [
            'nom' => 'required',
            'modele' => 'required',
            'prix' => 'integer',
            'description' => 'required'
        ]);
        $produit = new Produit;
        $produit->nom = $request->nom; 
        $produit->type = $request->type; 
        $produit->modele = $request->modele; 
        $produit->prix = $request->prix; 
        $produit->description = $request->description;
        $produit->save(); 
        if(!empty($request->nomc)){
            /* insert all caracteristics one by one */
            for ($i=0; $i < count($request->nomc) ; $i++) { 
                $caracteristique = new Caracteristique;
                $caracteristique->nom = $request->nomc[$i]; 
                $caracteristique->produit_id = $produit->id;  
                $caracteristique->save();
            }
        }

        if(!empty($request->designationp)){
            /* insert all procede one by one */
            for ($i=0; $i < count($request->designationp) ; $i++) { 
                $procede = new Procede;
                $procede->designation = $request->designationp[$i]; 
                $procede->description = $request->descriptionp[$i];
                $procede->atelier_id = $request->atelierp[$i];  
                $procede->produit_id = $produit->id;  
                $procede->save();
            }
        }
        return redirect(route('produit.list'))->with('successMsg',"L'article est ajouté avec succès");
    }

    public function edit(Produit $produit){   
        $actionForm = route('produit.update', ['produit' => $produit]);
        return view('simple.produit.form',compact('produit','actionForm'));
    }

    public function update(Request $request, Produit $produit){
        $this->validate($request,[
            'nom' => 'required',
            'modele' => 'required',
            'type' => 'required',
            'prix' => 'integer',
            'description' => 'required'
        ]);
        $produit->nom = $request->nom; 
        $produit->type = $request->type; 
        $produit->modele = $request->modele; 
        $produit->prix = $request->prix; 
        $produit->description = $request->description;
        $produit->save();

        Caracteristique::where('produit_id', $produit->id)->delete();
        if(!empty($request->nomc)){
            /* insert all caracteristics one by one */
            for ($i=0; $i < count($request->nomc) ; $i++) { 
                $caracteristique = new Caracteristique;
                $caracteristique->nom = $request->nomc[$i]; 
                $caracteristique->produit_id = $produit->id;  
                $caracteristique->save();
            }
        }
        
        Procede::where('produit_id', $produit->id)->delete();
        if(!empty($request->designationp)){
            /* insert all procede one by one */
            for ($i=0; $i < count($request->designationp) ; $i++) { 
                $procede = new Procede;
                $procede->designation = $request->designationp[$i]; 
                $procede->description = $request->descriptionp[$i];
                $procede->atelier_id = $request->atelierp[$i];  
                $procede->produit_id = $produit->id;  
                $procede->save();
            }
        }
        return redirect(route('produit.list'))->with('successMsg',"L'article est modifié avec succès");
    }

    public function delete(Produit $produit){
        $produit->delete();
        return redirect(route('produit.list'));
    }
}
<file_sep><?php

namespace App\Exports;

use App\Models\Audit;
use Maatwebsite\Excel\Concerns\Exportable;
use Illuminate\Contracts\View\View;

use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithTitle;

use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Concerns\WithEvents;

class AuditsExport implements FromQuery, WithTitle,WithHeadings,ShouldAutoSize,WithMapping,WithEvents{

    use Exportable;
    private $year;

    public function __construct(int $year){
        $this->year = $year;
    }

    public function map($audit): array{
        return [
            $audit->id,
            $audit->updated_at,
            $audit->titre,
            $audit->procede->designation,
            $audit->procede->atelier->nom,
            $audit->resultats,
            collect($audit->actions()->pluck('designation'))->implode('; '),
            collect($audit->regles()->pluck('titre'))->implode('; '),
            $audit->commentaire,
        ];
    }
    
    public function headings(): array{
        return [
            'Audit n°',
            'Date',
            'Titre',
            'Procédé métier',
            'Atelier',
            'Résultat',
            'Actions Correctives',
            'Règles enfreintes',
            'Observations',
        ];
    }

    public function query(){
        return Audit::where('etat','=','traité')->whereYear('updated_at',$this->year)->orderBy('updated_at','desc');
    }

    public function title(): string{
        return 'Journal des audits '.$this->year;
    }

    public function registerEvents(): array{
        $styleArray = [
            'borders' => [
                'allBorders' => [
                    'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
                    ],
                ],
            ];

            return [
                AfterSheet::class => function(AfterSheet $event) use($styleArray) {
                    $cpt = count(Audit::where('etat','=','traité')->whereYear('updated_at',$this->year)->get()) +1;
                    $cellRange = 'A1:I1'; 
                    $event->sheet->getStyle($cellRange)->ApplyFromArray($styleArray);
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setName('Calibri');
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);  
                    $event->sheet->getStyle('A2:A'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('B2:B'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('C2:C'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('D2:D'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('E2:E'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('F2:F'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('G2:G'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('H2:H'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('I2:I'.$cpt)->applyFromArray($styleArray);
                },
            ];
    }
}
<file_sep><?php

namespace App\Imports;

use App\Models\Atelier;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class AteliersImport implements ToModel, WithHeadingRow
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        return new Atelier([
            'nom'     => $row['nom'],
            'metier'    => $row['metier'], 
            'description'    => $row['description'], 
        ]);
    }
    
}
<file_sep><?php

namespace App\Exports;

use App\Models\Produit;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithTitle;

use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;

class ProduitsExport implements FromQuery,WithMapping,WithHeadings,ShouldAutoSize,WithTitle,WithEvents
{
    use Exportable;
    public function map($article): array
    {
        return [
            $article->id,
            $article->nom,
            $article->type,
            $article->modele,
            $article->description,
            $article->prix,
            collect($article->procedes()->pluck('designation'))->implode('; '),
            collect($article->caracteristiques()->pluck('nom'))->implode('; '),
            $article->created_at,
        ];
    }
    
    public function headings(): array
    {
        return [
            '#',
            'Nom',
            'Type',
            'Modèle',
            'Description',
            'Prix',
            'Procedes',
            'Caractéristique',
            'Crée le',
        ];
    }
    public function title(): string
    {
        return 'Articles';
    }

    public function query()
    {
        return Produit::query();
    }
    
    public function registerEvents(): array{
        $styleArray = [
            'borders' => [
                'allBorders' => [
                    'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
                    ],
                ],
            ];

            return [
                AfterSheet::class => function(AfterSheet $event) use($styleArray) {
                    $cpt = count(Produit::all()) +1;
                    $cellRange = 'A1:I1'; 
                    $event->sheet->getStyle($cellRange)->ApplyFromArray($styleArray);
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setName('Calibri');
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);  
                    $event->sheet->getStyle('A2:A'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('B2:B'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('C2:C'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('D2:D'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('E2:E'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('F2:F'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('G2:G'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('H2:H'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('I2:I'.$cpt)->applyFromArray($styleArray);
                    
                },
            ];
    }
}
<file_sep><?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class ExamenTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('examens')->insert([ 
            'id' => '1',
            'nom' => 'Vitesse de transfert des données en lecture',
            'type' => 'Quantitatif',
            'min' => '90',
            'max' => '93',
            'unite' => 'MB/s',
            'test_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '2',
            'nom' => 'Vitesse de transfert des données en écriture',
            'type' => 'Quantitatif',
            'min' => '18',
            'max' => '20',
            'unite' => 'MB/s',
            'test_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
        
        DB::table('examens')->insert([ 
            'id' => '3',
            'nom' => 'Capacité de stockage',
            'type' => 'Quantitatif',
            'min' => '15',
            'max' => '17',
            'unite' => 'Go',
            'test_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '4',
            'nom' => 'Système de fichier FAT32',
            'type' => 'Qualitatif',
            'test_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '5',
            'nom' => 'Système de fichier NTFS',
            'type' => 'Qualitatif',
            'test_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '6',
            'nom' => 'Tension',
            'type' => 'Quantitatif',
            'min' => '249',
            'max' => '251',
            'unite' => 'Volt',
            'test_id' => '2',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '7',
            'nom' => 'Courant',
            'type' => 'Quantitatif',
            'min' => '9',
            'max' => '11',
            'unite' => 'Ampére',
            'test_id' => '2',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
        
        DB::table('examens')->insert([ 
            'id' => '8',
            'nom' => 'Puissance',
            'type' => 'Quantitatif',
            'min' => '2000',
            'max' => '2010',
            'unite' => 'Watt',
            'test_id' => '2',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '9',
            'nom' => 'Résistance de température',
            'type' => 'Quantitatif',
            'min' => '20',
            'max' => '85',
            'unite' => 'Degré',
            'test_id' => '2',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '10',
            'nom' => 'Longueur du câble',
            'type' => 'Quantitatif',
            'min' => '1',
            'max' => '2',
            'unite' => 'mètre',
            'test_id' => '3',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '11',
            'nom' => 'Poids du câble',
            'type' => 'Quantitatif',
            'min' => '110',
            'max' => '120',
            'unite' => 'gramme',
            'test_id' => '3',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '12',
            'nom' => 'Matériel isolation en PVC',
            'type' => 'Qualitatif',
            'test_id' => '3',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '13',
            'nom' => 'Trois boutons',
            'type' => 'Qualitatif',
            'test_id' => '4',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '14',
            'nom' => 'Lumière visible',
            'type' => 'Qualitatif',
            'test_id' => '4',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '15',
            'nom' => '<NAME>',
            'type' => 'Qualitatif',
            'test_id' => '4',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
        
        DB::table('examens')->insert([ 
            'id' => '16',
            'nom' => 'Résolution',
            'type' => 'Quantitatif',
            'min' => '1350',
            'max' => '1450',
            'unite' => 'Dpi',
            'test_id' => '4',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '17',
            'nom' => 'Tension entrée',
            'type' => 'Quantitatif',
            'min' => '100',
            'max' => '240',
            'unite' => 'Volt',
            'test_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
    
        DB::table('examens')->insert([ 
            'id' => '18',
            'nom' => '<NAME>',
            'type' => 'Quantitatif',
            'min' => '5',
            'max' => '10',
            'unite' => 'Volt',
            'test_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
    

        DB::table('examens')->insert([ 
            'id' => '19',
            'nom' => '<NAME>',
            'type' => 'Quantitatif',
            'min' => '1',
            'max' => '2',
            'unite' => 'Ampère',
            'test_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '20',
            'nom' => '<NAME>',
            'type' => 'Quantitatif',
            'min' => '1',
            'max' => '2',
            'unite' => 'Ampère',
            'test_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
    
        DB::table('examens')->insert([ 
            'id' => '21',
            'nom' => 'Conductivité du cable',
            'type' => 'Quantitatif',
            'min' => '2',
            'max' => '4',
            'unite' => 'Ohms',
            'test_id' => '6',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
        

        DB::table('examens')->insert([ 
            'id' => '22',
            'nom' => '<NAME> : connecteur USB',
            'type' => 'Qualitatif',
            'test_id' => '6',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '23',
            'nom' => '<NAME> : connecteur Micro USB',
            'type' => 'Qualitatif',
            'test_id' => '6',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '24',
            'nom' => 'Vitesse de transfert des données en lecture',
            'type' => 'Quantitatif',
            'min' => '88',
            'max' => '90',
            'unite' => 'MB/s',
            'test_id' => '7',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '25',
            'nom' => 'Vitesse de transfert des données en écriture',
            'type' => 'Quantitatif',
            'min' => '18',
            'max' => '20',
            'unite' => 'MB/s',
            'test_id' => '7',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
        
        DB::table('examens')->insert([ 
            'id' => '26',
            'nom' => 'Capacité de stockage',
            'type' => 'Quantitatif',
            'min' => '31',
            'max' => '33',
            'unite' => 'Go',
            'test_id' => '7',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '27',
            'nom' => 'Système de fichier FAT32',
            'type' => 'Qualitatif',
            'test_id' => '7',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('examens')->insert([ 
            'id' => '28',
            'nom' => 'Système de fichier NTFS',
            'type' => 'Qualitatif',
            'test_id' => '7',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

    }
}
<file_sep><?php

namespace App\Http\Controllers\Gestionnaire;
use DB;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Lot;
use App\Models\Test;
use App\Models\Inspection;
use App\Models\Alert;
use App\Models\Produit;
use App\Models\Examen;
use App\Models\Reponse;
use App\Models\Event;
use Auth;
use Carbon\Carbon;
use Redirect,Response;
use PDF;
use App\Exports\InspectionsExport;
use Maatwebsite\Excel\Facades\Excel;


class InspectionController extends Controller{

    public function export(){      
        $year = Carbon::now()->format('Y');
        return (new InspectionsExport($year))->download('Journal des inspections '.$year.'.xlsx');
    }

    public function index(){
    	$inspections = Inspection::orderBy('id','desc')->paginate(10);
    	return view('quality.inspection.index',compact('inspections'));
    }

    public function create(Request $request){   
        $produits = Produit::where('type', '=' , 'Fini' )->get();
        return view('quality.inspection.create',compact('produits'));
    }
    
    public function createFrom(Request $request, $id){
        $event = Event::findOrFail($id);
        $event->rappel = "false"; // update rappel variable
        $event->save();
        $inspection = Inspection::where('id', '=' , $event->inspection_id)->first();
        if($event->alert != null){  
            $event->alert->etat ="en cours";
            $event->alert->save();
        }
        $produits = Produit::where('type', '=' , 'Fini' )->get();
        return view('quality.inspection.create', compact('inspection','produits'));
    }
    
    public function postCreateStep1(Request $request){  
        $request->validate([
            'titre' => 'required',
            'date' => 'required',
            'description' => 'required',
            'productimg' => 'image|mimes:jpeg,png,jpg,gif,svg',
            'produit' => 'required',
            'caracteristiquep' => 'required',
            'quantite' => ['required','integer'],
            'test' => 'required'
        ]);
        if(empty($request->id)){
            $inspection = new Inspection();
        }
        else{
            $inspection = Inspection::findOrFail($request->id);
        }

        if(empty($inspection->lot)){
            $lot = new Lot();
        }
        else{
            $lot = Lot::findOrFail($inspection->lot_id);
        }

        $lot->quantite = $request->quantite;
        $lot->produit_id = $request->produit;
        $lot->caracteristiquep = $request->caracteristiquep;
        $lot->save(); 
        $inspection->lot_id = $lot->id;               

        $inspection->titre = $request->titre;
        $inspection->description = $request->description;
        $inspection->test_id = $request->test; 
        $inspection->user_id = Auth::user()->id; // Id de l'utilisateur authentifie
        if(!empty($request->productimg)){
            $fileName = "lot-" . time() . '.' . request()->productimg->getClientOriginalExtension();
            $request->productimg->storeAs('lotImage', $fileName);
            $inspection->productimg = $fileName;
        } else{
            $inspection->productImg = null;
        }

        $inspection->etat="nouveau";
        $inspection->step = 2;
        $test_id = $inspection->test_id;
        $inspection->save();
        
        if(empty($request->id)){
            $event = new Event();
            $event->title = $inspection->titre;
            $event->start = $request->date;
            $event->end = $request->date;
            $event->type = 'Inspection';
            $event->inspection_id = $inspection->id;
            $event->save(); 
        }
        else{
            $update_event = DB::table('events')
            ->where('inspection_id', $inspection->id )
            ->update(['title' => $inspection->titre, 'start' => $request->date , 
            'end' => $request->date]); 
        }
        $examens = Examen::where('test_id', '=' , $test_id )->get();
        $produits = Produit::where('type', '=' , 'Fini' )->get();
        return view('quality.inspection.create',compact('produits','inspection','examens'));    
    }

    public function postCreateStep2(Request $request){

        $inspection = Inspection::findOrFail($request->id);   
        $result = "Les réponses des examens sont toutes correctes";
        
        if (!empty($request->ReponsesEtat)){
            for ($i=0; $i < count($request->ReponsesEtat) ; $i++) { 
                if ($request->ReponsesEtat[$i] =="Incorrect"){
                    $result = "Les réponses des examens ne sont pas toutes correctes";     
                }
                DB::table('reponses')
                ->updateOrInsert(
                    ['inspection_id' => $inspection->id, 'examen_id' => $request->ExamensIdd[$i]],
                    ['valeur' => $request->ReponsesValeur[$i] , 
                    'examen_id' => $request->ExamensIdd[$i] ,
                    'inspection_id' => $inspection->id,
                    'etat' => $request->ReponsesEtat[$i] ]
                ); 
            }
        }
        
        $test_id = $inspection->test_id;
        $inspection->etat="en cours";
        $inspection->step = 3;        
        $inspection->resultats = $result;
        $inspection->save();
        $examens = Examen::where('test_id', '=' , $test_id )->get();
        $produits = Produit::where('type', '=' , 'Fini' )->get();
        return view('quality.inspection.create',compact('produits','inspection','examens'));
    }


    public function store(Request $request){

        $request->validate([
            'quantiteD' => 'integer',  
        ]);

        $inspection = Inspection::findOrFail($request->id);
        if (!empty($request->commentaire)){
            $inspection->commentaire = $request->commentaire;       
        }

        if (!empty($request->quantiteD)){
            $inspection->quantiteD = $request->quantiteD;
        } 
        else{
            $inspection->quantiteD  = 0;
        }

        $inspection->etat="traité";
        $inspection->step = 1;
        $inspection->save();
        
        if ($request->anomalie){
            $lotA = DB::table('lots')->insertGetId([
                'quantite' => $request->quantiteD, 
                'caracteristiquep' => $inspection->lot->caracteristiquep,
                'produit_id' => $inspection->lot->produit->id
            ]); 
            /* automaticly create an associated anomaly */
            $anomalie_id = DB::table('anomalies')->insertGetId([   
                'lot_id' => $lotA,
                'atelier_id' => 5, // atelier de controle dans le seeders
                'test_id' => $inspection->test_id,
                'type' => 'Retour production',              
                'step' => 3,    
                'etat' => "en cours",
                'titre' => $inspection->titre. ' - De Inspection',
                'description' => $inspection->description,
                'resultats' => $inspection->resultats,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]); 

            /* Associate an alert to anomaly */
            $alert = new Alert;
            $alert->type = 'Retour production';
            $alert->description = $inspection->description; 
            $alert->atelier_id = 5; // atelier de controle dans le seeders
            $alert->sent = 1;
            $alert->anomalie_id = $anomalie_id; 
            $alert->etat = "en cours";
            $alert->lot_id = $lotA; 
            $alert->save();

            $reponses = Reponse::where('inspection_id', '=' , $inspection->id )->get();
            for ($i=0; $i < count($reponses) ; $i++) { 
                $reponses[$i]->anomalie_id=  $anomalie_id;
                $reponses[$i]->save();
            }
            $inspection->anomalie_id = $anomalie_id; 
            $inspection->save();          
            return redirect(route('anomalie.createFrom',$anomalie_id));
        }

        return redirect(route('inspection.dashbord'))->with('successMsg',"Création d'une nouvelle inspection");

    }

    public function delete(Inspection $inspection){
        $inspection->delete();
        return redirect(route('inspection.dashbord'));
    }

    public function previous(Inspection $inspection){
        $inspection->step -= 1;
        if($inspection->step < 1) $inspection->step=1;
        $inspection->save();
        $produits = Produit::where('type', '=' , 'Fini' )->get();
        $test_id = $inspection->test_id;
        $examens = Examen::where('test_id', '=' , $test_id )->get();
        return view('quality.inspection.create', compact('inspection','produits','examens'));
    }

    public function edit(Inspection $inspection){   
        $test_id = $inspection->test_id;
        $inspection->step = 1;
        $inspection->etat = "en cours";
        $examens = Examen::where('test_id', '=' , $test_id )->get();
        $produits = Produit::where('type', '=' , 'Fini' )->get();
        return view('quality.inspection.create',compact('produits','inspection','examens')); 
    }
    
    function generate_pdf(Inspection $inspection) {

        $pdf = PDF::loadView('pdf.ficheInspection', compact('inspection'));
        return $pdf->stream('Fiche.pdf');
    }

    public function view(Inspection $inspection){
             
        return view('quality.inspection.view',compact('inspection'));
    }


}
<file_sep><?php

namespace App\Http\Controllers\Gestionnaire;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Examen;
use App\Models\Test;


class TestController extends Controller
{
    public function index(){
         
    }

    public function create(Request $request){ 
        $action = route('test.create');
        return view('quality.test.form', compact('action'));
    }

    public function store(Request $request){
        $this->validate($request,[
             'description' => 'required',
             'nom' => 'required',
             'type' => 'required'
           ]);
        $test = new Test;
        $test->type = $request->type; 
        $test->nom = $request->nom; 
        $test->description = $request->description; 
        $test->save();
        
       if (!empty($request->nomE))
       {
        /* insert all exams one by one */
        for ($i=0; $i < count($request->nomE) ; $i++) { 
            $examen = new Examen;
            $examen->type = $request->typeE[$i]; 
            $examen->nom = $request->nomE[$i];
            $examen->test_id = $test->id;  // after test is inserted u can access his id

            if ($examen->type == "Quantitatif"){          
                 $examen->min = $request->min[$i];
                 $examen->max = $request->max[$i];
                 $examen->unite = $request->unite[$i]; 
            }
           /* if ($examen->type == "Qualitatif"){
                $examen->reponse1 = $request->reponse[$i];
                $examen->reponse2 = $request->reponseTwo[$i];
            }*/
            $examen->save();
        }
       }

        return redirect()->route('test.list')->with('successMsg',"Création d'un nouveau test");             
    }

    public function show(){    
      
        $tests = Test::paginate(10);
        return view('quality.test.list',compact('tests'));
    }

    public function edit(Test $test){          
        $action = route('test.update', ['test' => $test]);
        return view('quality.test.form',compact('test','action'));
    }

    public function update(Request $request, Test $test){
        $this->validate($request,[
            'description' => 'required',
            'nom' => 'required',
            'type' => 'required'
        ]);
   
        $test->type = $request->type; 
        $test->nom = $request->nom; 
        $test->description = $request->description; 
        $test->save();
        Examen::where('test_id', $test->id)->delete();
        /* insert all exams one by one */
        if (!empty($request->nomE)){
            for ($i=0; $i < count($request->nomE) ; $i++) { 
              $examen = new Examen;
              $examen->type = $request->typeE[$i]; 
              $examen->nom = $request->nomE[$i];
              $examen->test_id = $test->id;  // after test is inserted u can access his id
  
              if ($examen->type == "Quantitatif"){          
                   $examen->min = $request->min[$i];
                   $examen->max = $request->max[$i];
                   $examen->unite = $request->unite[$i]; 
              }
             /* if ($examen->type == "Qualitatif"){
                   $examen->question = $request->question[$i];
                   //$examen->reponse2 = $request->reponseTwo[$i];
              } */
              $examen->save();
            }
        }
          
          return redirect(route('test.list'))->with('successMsg',"Modification du test");
    }

    public function delete(Test $test){
        $test->delete();
        return redirect(route('test.list'));
    }

    public function storeExamen(Request $request){   
        $type = $request->typeE;
           
           if ( $type == "Quantitatif"){
                $this->validate($request,[
                    'min' => 'required',
                    'max' => 'required',
                    'unite' => 'required'     
                ]);
            
                $examen = new Examen;
                $examen->type = $request->typeE; 
                $examen->nom = $request->nomE; 
                $examen->min = $request->min;
                $examen->max = $request->max;
                $examen->unite = $request->unite; 
                $examen->test_id = $test_id; 
                $examen->save();
                return redirect(route('test.create'));
         
           }
           if ( $type == "Qualitatif")
           {
                $examen = new Examen;
                $examen->type = $request->typeE; 
                $examen->nom = $request->nomE; 
                $examen->reponse = $request->reponse;
                $examen->test_id = $test_id; 
                $examen->save();
                return redirect(route('test.create'));
           }
           
    }
}
<file_sep><?php

namespace App\Exports;

use App\Models\Fournisseur;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithTitle;

use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;

class FournisseursExport implements FromQuery,WithMapping,WithHeadings,ShouldAutoSize,WithTitle,WithEvents
{
    use Exportable;
    public function map($fournisseur): array
    {
        return [
            $fournisseur->id,
            $fournisseur->nom,
            $fournisseur->adresse,
            $fournisseur->description,
            $fournisseur->created_at,
        ];
    }
    
    public function headings(): array
    {
        return [
            '#',
            'Nom',
            'Adresse',
            'Description',
            'Créé le',
        ];
    }
    public function title(): string
    {
        return 'Fournisseurs';
    }

    public function query()
    {
        return Fournisseur::query();
    }
    
    public function registerEvents(): array{
        $styleArray = [
            'borders' => [
                'allBorders' => [
                    'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
                    ],
                ],
            ];

            return [
                AfterSheet::class => function(AfterSheet $event) use($styleArray) {
                    $cpt = count(Fournisseur::all()) +1;
                    $cellRange = 'A1:E1'; 
                    $event->sheet->getStyle($cellRange)->ApplyFromArray($styleArray);
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setName('Calibri');
                    $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);  
                    $event->sheet->getStyle('A2:A'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('B2:B'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('C2:C'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('D2:D'.$cpt)->applyFromArray($styleArray);
                    $event->sheet->getStyle('E2:E'.$cpt)->applyFromArray($styleArray);  
                },
            ];
    }

}
<file_sep><?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class ProcedesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('procedes')->insert([ 
            'id' => '1',
            'designation' => 'Programmation des machines SMT',
            'description' => '',
            'atelier_id' => '1',
            'produit_id' => '7',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '2',
            'designation' => 'Programmation des cartes électroniques',
            'description' => '',
            'atelier_id' => '1',
            'produit_id' => '7',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '3',
            'designation' => 'Sertissage câble alimentation',
            'description' => '',
            'atelier_id' => '3',
            'produit_id' => '6',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '4',
            'designation' => 'Soudage câble alimentation',
            'description' => '',
            'atelier_id' => '3',
            'produit_id' => '6',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '5',
            'designation' => 'Emballage câble alimentation',
            'description' => '',
            'atelier_id' => '3',
            'produit_id' => '6',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '6',
            'designation' => 'Injection plastique FD',
            'description' => '',
            'atelier_id' => '3',
            'produit_id' => '6',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
        
        DB::table('procedes')->insert([ 
            'id' => '7',
            'designation' => 'Injection plastique souris',
            'description' => '',
            'atelier_id' => '2',
            'produit_id' => '3',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '8',
            'designation' => 'Injection plastique chargeur',
            'description' => '',
            'atelier_id' => '2',
            'produit_id' => '4',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '9',
            'designation' => 'Soudage connecteurs câble USB',
            'description' => '',
            'atelier_id' => '2',
            'produit_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '10',
            'designation' => 'Injection PVC câble USB',
            'description' => '',
            'atelier_id' => '2',
            'produit_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '11',
            'designation' => 'Emballage câble USB',
            'description' => '',
            'atelier_id' => '2',
            'produit_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '12',
            'designation' => 'Montage souris',
            'description' => '',
            'atelier_id' => '4',
            'produit_id' => '3',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
        
        DB::table('procedes')->insert([ 
            'id' => '13',
            'designation' => 'Emballage souris',
            'description' => '',
            'atelier_id' => '4',
            'produit_id' => '3',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '14',
            'designation' => 'Montage chargeur',
            'description' => '',
            'atelier_id' => '4',
            'produit_id' => '4',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '15',
            'designation' => 'Emballage chargeur',
            'description' => '',
            'atelier_id' => '4',
            'produit_id' => '4',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '16',
            'designation' => 'Montage FD',
            'description' => '',
            'atelier_id' => '4',
            'produit_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '17',
            'designation' => 'Emballage FD',
            'description' => '',
            'atelier_id' => '4',
            'produit_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '18',
            'designation' => 'Programmation FD',
            'description' => '',
            'atelier_id' => '5',
            'produit_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('procedes')->insert([ 
            'id' => '19',
            'designation' => 'Emballage RAM',
            'description' => '',
            'atelier_id' => '5',
            'produit_id' => '7',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);


    }
}
<file_sep><?php

namespace App\Http\Controllers\Simple;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Atelier;
use App\Exports\AteliersExport;
use App\Imports\AteliersImport;
use Maatwebsite\Excel\Facades\Excel;


class AtelierController extends Controller
{   
    
    public function export(){
        return Excel::download(new AteliersExport(), 'Ateliers.xlsx');
    }

    public function import(){
        Excel::import(new AteliersImport,request()->file('file'));
        return back();
    }

    public function index(){
        $ateliers = Atelier::paginate(10);
        return view('simple.atelier.index',compact('ateliers'));
    }

    public function create(){ 
        $actionForm = route('atelier.create');
        return view('simple.atelier.form', compact('actionForm'));
    }

    public function store(Request $request){
        $this->validate($request,[
            'description' => 'required',
            'nom' => 'required',
            'metier' => 'required'
        ]);
        $atelier = new Atelier;
        $atelier->nom = $request->nom; 
        $atelier->metier = $request->metier; 
        $atelier->description = $request->description; 
        $atelier->save();
        return redirect(route('atelier.list'))->with('successMsg',"L'atelier est ajouté avec succès");
    }

    public function edit(Atelier $atelier){   
        $actionForm = route('atelier.update', ['atelier' => $atelier]);
        return view('simple.atelier.form',compact('atelier','actionForm'));
    }

    public function update(Request $request, Atelier $atelier){
        $this->validate($request,[
            'description' => 'required',
            'nom' => 'required',
            'metier' => 'required'
          ]);
          $atelier->nom = $request->nom; 
          $atelier->metier = $request->metier; 
          $atelier->description = $request->description; 
          $atelier->save();
          return redirect(route('atelier.list'))->with('successMsg',"L'atelier est modifié avec succès");
        }

    public function delete(Atelier $atelier){
        $atelier->delete();
        return redirect(route('atelier.list'));
    }
}
<file_sep><?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class FournisseurTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
          
        DB::table('fournisseurs')->insert([ 
            'id' => '1',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Rue Sadani M<NAME>-Blida',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('fournisseurs')->insert([ 
            'id' => '2',
            'nom' => 'Aitcom Pub',
            'description' => '',
            'adresse' => 'place 11 mars, villa N°16 plan de partition N°42, Annaba',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);


        DB::table('fournisseurs')->insert([ 
            'id' => '3',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => '89, Lot Vincent II Bouzareah, Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('fournisseurs')->insert([ 
            'id' => '4',
            'nom' => 'Bouhoun Pub',
            'description' => '',
            'adresse' => 'Coopérative el nahda - n 41 Bir Khadem, Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('fournisseurs')->insert([ 
            'id' => '5',
            'nom' => 'DATOTEK',
            'description' => '',
            'adresse' => 'Cité meriem N°07 "A", Baraki Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('fournisseurs')->insert([ 
            'id' => '6',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Bou Ismail, Tipaza',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('fournisseurs')->insert([ 
            'id' => '7',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Zone activité Zouine Aaba Ali Birtouta -alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('fournisseurs')->insert([ 
            'id' => '8',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Succursale N° 26 lot eldjanah lakhdar garidi Kouba,Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('fournisseurs')->insert([ 
            'id' => '9',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Ain Roumana,Blida',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('fournisseurs')->insert([ 
            'id' => '10',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Cheraga,Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('fournisseurs')->insert([ 
            'id' => '11',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Boulevard du 11 Décembre 1960 ,Lot 65, El Biar',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('fournisseurs')->insert([ 
            'id' => '12',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Les eucalyptus,Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);


        DB::table('fournisseurs')->insert([ 
            'id' => '13',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Baraki,Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Anomalie extends Model
{
   protected $fillable = [
      'titre','description','diagnostique','cause','type'
   ];
    public function regles()
    {
       return $this->belongsToMany('App\Models\Regle');
    }

    public function charges()
    {
        return $this->hasMany('App\Models\Charge');
    }
    
    public function inspections()
    {
        return $this->hasMany('App\Models\Inspection');
    }

    public function fichiers()
    {
        return $this->hasMany('App\Models\Fichier');
    }

    public function attributs()
    {
        return $this->hasMany('App\Models\Attribut');
    }

    public function reparateur()
    {
       return $this->belongsTo('App\User');
    }

    public function test()
    {
       return $this->belongsTo('App\Models\Test');
    } 

    public function lot()
    {
       return $this->belongsTo('App\Models\Lot');
    }

    public function atelier()
    {
       return $this->belongsTo('App\Models\Atelier');
    }

    public function client()
    {
       return $this->belongsTo('App\Models\Client');
    }

    public function fournisseur()
    {
       return $this->belongsTo('App\Models\Fournisseur');
    }

    public function actions()
    {
       return $this->belongsToMany('App\Models\Action');
    }

}

<file_sep><?php

use Illuminate\Database\Seeder;

class RolesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('roles')->insert([
            'name' => 'admin',
            'guard_name' => 'web',
            'description' => 'gestion du site entier + privileges utilisateurs (configuration)',
        ]);
        DB::table('roles')->insert([
            'name' => 'gestionnaire',
            'guard_name' => 'web',
            'description' => 'gestion du controle et suivi de la qualité des produits',
        ]);
        DB::table('roles')->insert([
            'name' => 'simple',
            'guard_name' => 'web',
            'description' => 'lanceur d"alerte anomalie produit',
        ]);
    }
}
<file_sep><?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;


class CaracteristiqueTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('caracteristiques')->insert([ 
            'nom' => '4 Go',
            'produit_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '8 Go',
            'produit_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '16 Go',
            'produit_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '32 Go',
            'produit_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '64 Go',
            'produit_id' => '1',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '16 Go',
            'produit_id' => '2',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '32 Go',
            'produit_id' => '2',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '64 Go',
            'produit_id' => '2',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '128 Go',
            'produit_id' => '2',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '256 Go',
            'produit_id' => '2',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
      
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Sans fils',
            'produit_id' => '3',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
        
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Filaire',
            'produit_id' => '3',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'Rapide adaptative',
            'produit_id' => '4',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
        
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Type C',
            'produit_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'Luna',
            'produit_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'Iphone',
            'produit_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
       
        DB::table('caracteristiques')->insert([ 
            'nom' => 'PC',
            'produit_id' => '6',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'LAPTOP',
            'produit_id' => '6',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'Onduleur',
            'produit_id' => '6',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '2 GB',
            'produit_id' => '7',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
            ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '4 GB',
            'produit_id' => '7',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')       
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => '8 GB',
            'produit_id' => '7',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Rouge',
            'produit_id' => '8',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Vert',
            'produit_id' => '8',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Bleu',
            'produit_id' => '8',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Male',
            'produit_id' => '9',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Female',
            'produit_id' => '9',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => '1 m',
            'produit_id' => '10',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => '2 m',
            'produit_id' => '10',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => '3 m',
            'produit_id' => '10',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Rouge',
            'produit_id' => '11',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Vert',
            'produit_id' => '11',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Bleu',
            'produit_id' => '11',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'USB 2.0',
            'produit_id' => '12',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'USB 3.0',
            'produit_id' => '12',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'RAM DDR',
            'produit_id' => '12',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Micro A',
            'produit_id' => '13',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Micro C',
            'produit_id' => '13',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Micro iPhone',
            'produit_id' => '13',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'USB A',
            'produit_id' => '13',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Rouge',
            'produit_id' => '14',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Vert',
            'produit_id' => '14',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);
        DB::table('caracteristiques')->insert([ 
            'nom' => 'Bleu',
            'produit_id' => '14',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'Connecteur USB',
            'produit_id' => '15',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'Connecteur Micro USB',
            'produit_id' => '15',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'Connecteur Type C',
            'produit_id' => '15',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'Connecteur Iphone',
            'produit_id' => '15',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'PC',
            'produit_id' => '16',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'Treflle',
            'produit_id' => '16',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'Onduleur',
            'produit_id' => '16',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);

        DB::table('caracteristiques')->insert([ 
            'nom' => 'Catel',
            'produit_id' => '16',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')        
        ]);



    }
}
<file_sep><?php

namespace App\Http\Controllers\Admin;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Controllers\Controller;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;

class UserController extends Controller
{
    public function index(){
    	$users = User::all();
    	return view('admin.user.index',compact('users'));
    }

    public function create(){
        $roles = Role::all();
        $permissions = Permission::all();
        $action = route('user.create');
        return view('admin.user.form',compact('roles','permissions','action'));
    }


    public function store(Request $request){
        $this->validate($request,[
            'nom' => ['required', 'string', 'max:255'],
            'prenom' => ['required', 'string', 'max:255'],
            'numero_tel' => ['required', 'string', 'max:255'],
            'service' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['<PASSWORD>', 'string', 'min:8'],
  	    ]);
        $user = User::create($request->all());
        $user->password = <PASSWORD>::make($request->password);
        $user->syncRoles($request->roles);
        $user->syncPermissions($request->permissions);
        $user->save();
        return redirect(route('user.dashbord'))->with('successMsg','Utilisateur créé avec succès');
    }

    public function edit(User $user){
        $action = route('user.update', ['user' => $user]);
        $roles = Role::all();
        $permissions = Permission::all();
        return view('admin.user.form',compact('user','roles','permissions','action'));
    }


    public function update(Request $request,User $user){
        $user->nom = $request->nom;
        $user->prenom = $request->prenom;
        $user->email = $request->email;
        $user->numero_tel = $request->numero_tel;
        $user->service = $request->service;
        $user->syncRoles($request->roles);
        $user->syncPermissions($request->permissions);
        $user->save();
        return redirect(route('user.dashbord'))
        ->with('successMsg','Utilisateur modifié avec succès');
    }


    public function delete(User $user){
        $user->delete();
        return redirect(route('user.dashbord'));
    }

}
<file_sep><?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class RegleTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('regles')->insert([ 
            'id' => '1',
            'titre' => 'Compatibilité',
            'contenu' => 'toutes les versions de Windows, Mac Os version 10.4 ou version ultérieure, Linux Kernel 2.6 ou version ultérieure',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '2',
            'titre' => 'Protocole USB',
            'contenu' => 'USB 2.0',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '3',
            'titre' => 'Résolution',
            'contenu' => '1400 Dpi',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '4',
            'titre' => 'Nombre de boutons',
            'contenu' => '3',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);


        DB::table('regles')->insert([ 
            'id' => '5',
            'titre' => 'Capteur',
            'contenu' => 'Type : optique, Lumiére visible : Oui, Couleur de la lumière : rouge',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);


        DB::table('regles')->insert([ 
            'id' => '6',
            'titre' => 'Longeur cable',
            'contenu' => '1,3 métres',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);


        DB::table('regles')->insert([ 
            'id' => '7',
            'titre' => 'Molette',
            'contenu' => 'Ordinaire',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '8',
            'titre' => 'Dimensions',
            'contenu' => '67 mm x 117 mm x 35 mm',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '9',
            'titre' => 'Poids',
            'contenu' => '85 grs',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '10',
            'titre' => 'Type de connexion',
            'contenu' => 'Connectivité avancée sans fils 2,4 GHz',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '11',
            'titre' => 'Interface de connexion',
            'contenu' => 'Récepteur USB',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '12',
            'titre' => 'Distance de travail',
            'contenu' => '10 Métres',
            'produit_id' => '3',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '13',
            'titre' => 'Compatibilité',
            'contenu' => 'Toutes les appareils avec un cable USB',
            'produit_id' => '4',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '14',
            'titre' => 'Dimensions',
            'contenu' => '8 cm x 3,8 cm x 2,5 cm',
            'produit_id' => '4',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '15',
            'titre' => 'Poids',
            'contenu' => '20 grs',
            'produit_id' => '4',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '16',
            'titre' => 'Puissance',
            'contenu' => 'Sortie : 5V, 2.1A et Entrée : 100-240V , 0.5A',
            'produit_id' => '4',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
        
        DB::table('regles')->insert([ 
            'id' => '17',
            'titre' => 'Compatibilité',
            'contenu' => 'toutes les versions de Windows, Mac Os version 10.4 ou version ultérieure, Linux Kernel 2.6 ou version ultérieure',
            'produit_id' => '1',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
       
        DB::table('regles')->insert([ 
            'id' => '18',
            'titre' => 'Protocole USB',
            'contenu' => 'USB 2.0',
            'produit_id' => '1',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '19',
            'titre' => 'Connectivité',
            'contenu' => '1x haute vitesse, 4pin USB,type A',
            'produit_id' => '1',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '20',
            'titre' => 'Branchement',
            'contenu' => 'plug and play',
            'produit_id' => '1',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '21',
            'titre' => 'Températeure',
            'contenu' => 'Min : 0° , Max : 60°',
            'produit_id' => '1',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '22',
            'titre' => 'Dimensions',
            'contenu' => '67mm x 117mm x 35mm',
            'produit_id' => '1',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '23',
            'titre' => 'Poids',
            'contenu' => '85 grs',
            'produit_id' => '1',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '24',
            'titre' => 'Compatibilité',
            'contenu' => 'toutes les versions de Windows, Mac Os version 10.4 ou version ultérieure, Linux Kernel 2.6 ou version ultérieure',
            'produit_id' => '2',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '25',
            'titre' => 'Protocole USB',
            'contenu' => 'USB 3.0',
            'produit_id' => '2',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '26',
            'titre' => 'Branchement',
            'contenu' => 'plug and play',
            'produit_id' => '2',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '27',
            'titre' => 'Températeure',
            'contenu' => 'Min : 0° , Max : 60°',
            'produit_id' => '2',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '28',
            'titre' => 'Tension',
            'contenu' => '250 V , Courant 10 A',
            'produit_id' => '6',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '29',
            'titre' => 'Compatibilité',
            'contenu' => 'Cable alimentation Eur Plug adapté aux moniteurs,ordinateurs,téleviseurs,imprimantes, scanners et projecteurs, code machine , brouilloire, cuiseur à riz',
            'produit_id' => '6',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '30',
            'titre' => 'Résistance de températeure',
            'contenu' => 'Max : 65°',
            'produit_id' => '6',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '31',
            'titre' => 'Puissance nominale',
            'contenu' => '2000 Watt',
            'produit_id' => '6',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '32',
            'titre' => 'Matériaux',
            'contenu' => 'Ignifuge en PVC, noyeau de cuivre de haute qualité',
            'produit_id' => '6',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
         
        DB::table('regles')->insert([ 
            'id' => '33',
            'titre' => 'Longueur du cable',
            'contenu' => '1,2 métres',
            'produit_id' => '6',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '34',
            'titre' => 'Poids',
            'contenu' => '115 grs',
            'produit_id' => '6',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
        
        DB::table('regles')->insert([ 
            'id' => '35',
            'titre' => 'Type de charge',
            'contenu' => 'Universel',
            'produit_id' => '5',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('regles')->insert([ 
            'id' => '36',
            'titre' => 'Entrées',
            'contenu' => 'Entrée A : USB, Entrée B : Micro USB ',
            'produit_id' => '5',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);


        DB::table('regles')->insert([ 
            'id' => '37',
            'titre' => 'Transfert de données mobiles',
            'contenu' => 'Oui',
            'produit_id' => '5',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);


        DB::table('regles')->insert([ 
            'id' => '38',
            'titre' => 'Longueur du câble',
            'contenu' => '1 mètre',
            'produit_id' => '5',
            'user_id' => '5',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Audit extends Model
{

    public function user()
    {
       return $this->belongsTo('App\User');
    }

    public function procede()
    {
       return $this->belongsTo('App\Models\Procede');
    }

    public function atelier()
    {
       return $this->belongsTo('App\Models\Atelier');
    }

    public function attributs()
    {
        return $this->hasMany('App\Models\Attribut');
    }

    public function actions()
    {
       return $this->belongsToMany('App\Models\Action');
    }

    public function event()
    {
       return $this->belongsTo('App\Models\Event');
    }
    
    public function questionnaires()
    {
        return $this->hasMany('App\Models\Questionnaire');
    }

    public function regles()
    {
       return $this->belongsToMany('App\Models\Regle');
    }
    
}
<file_sep><?php

namespace App\Http\Controllers\Simple;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Client;
use App\Exports\ClientsExport;
use App\Imports\ClientsImport;
use Maatwebsite\Excel\Facades\Excel;

class ClientController extends Controller
{ 
    /**
    * @return \Illuminate\Support\Collection
    */
    public function export(){
        return Excel::download(new ClientsExport, 'clients.xlsx');
    }
   
    /**
    * @return \Illuminate\Support\Collection
    */
    public function import(){
        Excel::import(new ClientsImport,request()->file('file'));
        return back();
    }

    public function index(){
       
        $clients = client::paginate(15);
        return view('simple.client.index',compact('clients'));
    }

    public function create(){ 
        $actionForm = route('client.create');
        return view('simple.client.form', compact('actionForm'));
    }

    public function store(Request $request){
        $this->validate($request,[
            'nom' => 'required',
            'description' => 'required',
            'adresse' => 'required'
        ]);
        $client = new Client;
        $client->nom = $request->nom; 
        $client->description = $request->description; 
        $client->adresse = $request->adresse; 
        $client->save();
        return redirect(route('client.list'))->with('successMsg',"Le client est ajouté avec succès");
    }

    public function edit(Client $client){   
        $actionForm = route('client.update', ['client' => $client]);
        return view('simple.client.form',compact('client','actionForm'));
    }

    public function update(Request $request, Client $client){
        $this->validate($request,[
            'nom' => 'required',
            'description' => 'required',
            'adresse' => 'required'
        ]);
        $client->nom = $request->nom; 
        $client->description = $request->description; 
        $client->adresse = $request->adresse; 
        $client->save();
        return redirect(route('client.list'))->with('successMsg',"Le client est modifié avec succès");
    }

    public function delete(client $client){
        $client->delete();
        return redirect(route('client.list'));
    }
}
<file_sep><?php

namespace App\Http\Controllers\Gestionnaire;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Action;
use App\Models\Anomalie;
use App\Models\Audit;
use Illuminate\Support\Facades\Auth;


class ActionController extends Controller
{
    public function index(){
        $actions = Action::paginate(10);
        return view('quality.action.index',compact('actions'));
    }

    public function create(){ 
        $actionForm = route('action.create');
        return view('quality.action.form', compact('actionForm'));
    }

    public function store(Request $request){
        $this->validate($request,[
            'description' => 'required',
            'designation' => 'required',
            'resultat' => 'required',
            'type' => 'required'
        ]);
        $action = new Action;
        $action->type = $request->type; 
        $action->designation = $request->designation; 
        $action->description = $request->description; 
        $action->resultat = $request->resultat; 
        $action->user_id = Auth::user()->id; 
        $action->save();
        if(!empty($request->id)){
            $anomalie = Anomalie::findOrFail($request->id);
            return view('quality.anomalie.create', compact('anomalie'));
        }
        else{
            if( !empty($request->idAudit)){
                $audit = Audit::findOrFail($request->idAudit);
                return view('quality.audit.create', compact('audit'));
            }
            else{
            return redirect(route('action.list'))->with('successMsg',"L'action est ajoutée avec succès");
            }
        }
    }

    public function edit(Action $action){   
        $actionForm = route('action.update', ['action' => $action]);
        return view('quality.action.form',compact('action','actionForm'));
    }

    public function update(Request $request, Action $action){
        $this->validate($request,[
            'description' => 'required',
            'designation' => 'required',
            'resultat' => 'required',
            'type' => 'required'
          ]);
          $action->type = $request->type; 
          $action->designation = $request->designation; 
          $action->description = $request->description; 
          $action->resultat = $request->resultat; 
          $action->user_id = Auth::user()->id; 
          $action->save();
          return redirect(route('action.list'))->with('successMsg',"Modification de l'action avec succès");
    }

    public function delete(Action $action){
        $action->delete();
        return redirect(route('action.list'));
    }


}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Regle extends Model
{
    public function user(){
       return $this->belongsTo('App\User');
   }

    public function anomalies(){
       return $this->belongsToMany('App\Models\Anomalie');
    }

    public function produit()
    {
       return $this->belongsTo('App\Models\Produit');
    }

    public function audits()
    {
       return $this->belongsToMany('App\Models\Audit');
    }
    

}
<file_sep><?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateInspectionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('inspections', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('titre');
            $table->integer('step')->default(1);
            $table->enum('etat', ['nouveau','en cours','traité'])->default('nouveau');
            $table->text('resultats')->nullable();
            $table->text('commentaire')->nullable();
            $table->string('productimg')->nullable();
            $table->text('description')->nullable(); 
            $table->integer('quantiteD')->nullable();
            $table->unsignedBigInteger('user_id')->nullable();
            $table->unsignedBigInteger('test_id')->nullable();
            $table->unsignedBigInteger('lot_id')->nullable();
            $table->unsignedBigInteger('anomalie_id')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('inspections');
    }
}
<file_sep><?php

namespace App\Http\Controllers\Gestionnaire;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Anomalie;
use App\Models\Lot;
use App\Models\Produit;
use App\Models\Caracteristique;
use App\Models\Alert;
use App\Models\Fournisseur;
use App\Models\Client;
use App\Models\Atelier;
use App\Models\Regle;
use App\User;
use App\Models\Examen;
use App\Models\Reponse;
use Carbon\Carbon;
use DB;
use PDF;
use App\Exports\AnomaliesExport;
use Maatwebsite\Excel\Facades\Excel;

use Illuminate\Support\Facades\Auth;

class AnomalieController extends Controller
{
    public function export(){      
        $year = Carbon::now()->format('Y');
        return (new AnomaliesExport($year))->download('Journal des Anomalies '.$year.'.xlsx');
    }

    public function index(){
    	$anomalies = Anomalie::orderBy('id','desc')->paginate(10);
    	return view('quality.anomalie.index',compact('anomalies'));
    }

    public function createFromScratch(Request $request){
        return view('quality.anomalie.create');
    }

    public function createFrom(Request $request, $id){
        $anomalie = Anomalie::findOrFail($id);
        $alerts = Alert::where('anomalie_id', '=' , $id )->
                         where('etat', '=' , 'nouveau' )->get();
        if(!empty($alerts[0])){
            $alerts[0]->etat ="en cours";
            $alerts[0]->save();
        }
        return view('quality.anomalie.create', compact('anomalie'));
    }

    public function postCreateStep1(Request $request){
        $validatedData = $request->validate([
            'titre' => 'required',
            'type' => 'required',
            'test' => 'required',
            'quantite' => ['required','integer'],
            'caracteristiquep' => 'required'
        ]);

        if(empty($request->id)){
            $anomalie = new Anomalie();
            $lot_id = DB::table('lots')->insertGetId(
                [   'quantite' => $request->quantite, 
                    'produit_id' => $request->produit,
                    'caracteristiquep' => $request->caracteristiquep
                ]
            ); 
            $anomalie->lot_id = $lot_id;               
        }
        else{
            $anomalie = Anomalie::findOrFail($request->id);
            $lot_id = DB::table('lots')
            ->where('id', $anomalie->lot_id )
            ->update([
                'quantite' => $request->quantite,
                'produit_id' => $request->produit,
                'caracteristiquep' => $request->caracteristiquep
            ]);
        }

        switch ($request->type) {
            case 'Retour fournisseur':
                $anomalie->fournisseur_id = $request->fournisseur;
                break; 
            case 'Retour client':
                $anomalie->client_id = $request->client;             
                break;
            case 'Retour production':
                $anomalie->atelier_id = $request->atelier;  
                break;
        }
        $anomalie->test_id = $request->test; 
        $anomalie->type = $request->type; 
        $anomalie->titre = $request->titre; 
        $anomalie->description = $request->description;
        if($anomalie->etat != "en cours" && $anomalie->etat != "traité"){
            $anomalie->etat="nouveau";
        } else{
            $anomalie->etat="en cours";
        }
        $anomalie->step = 2;
        $anomalie->save();

        /* Associate an alert if anomaly created from scratch */
        $alerts = Alert::where('anomalie_id', '=' , $anomalie->id )->
                        whereNotIn('type',['Rappel'])->get();
        if(empty($alerts[0])){
            $alert = new Alert;
            $alert->type = $anomalie->type;
            $alert->description = $anomalie->description; 
            switch ($anomalie->type) {
                case 'Retour fournisseur':
                    $alert->fournisseur_id = $anomalie->fournisseur_id;
                    break; 
                case 'Retour client':
                    $alert->client_id = $anomalie->client_id;             
                    break;
                case 'Retour production':
                    $alert->atelier_id = $anomalie->atelier_id;  
                    break;
            }
            $alert->sent = 1;
            $alert->anomalie_id = $anomalie->id; 
            $alert->etat = "en cours";
            $alert->lot_id = $lot_id; 
            $alert->save();
        }

        $examens = Examen::where('test_id', '=' , $anomalie->test_id )->get();
        return view('quality.anomalie.create', compact('anomalie','examens'));
    }

    public function postCreateStep2(Request $request){    
        $anomalie = Anomalie::findOrFail($request->id);
        $result = "Les réponses des examens sont toutes correctes, Aucune erreur detecté";
       
       if (!empty($request->ReponsesEtat)){

            for ($i=0; $i < count($request->ReponsesEtat) ; $i++) { 
                if ($request->ReponsesEtat[$i] =="Incorrect"){
                    $result = "Les réponses des examens ne sont pas toutes correctes, Existence d'une anomalie !";         
                }
                DB::table('reponses')
                ->updateOrInsert(
                    ['anomalie_id' => $anomalie->id, 'examen_id' => $request->ExamensIdd[$i]],
                    ['valeur' => $request->ReponsesValeur[$i] , 
                    'examen_id' => $request->ExamensIdd[$i] ,
                    'anomalie_id' => $anomalie->id,
                    'etat' => $request->ReponsesEtat[$i] ]
                ); 
            }
        }

        if($result == "Les réponses des examens ne sont pas toutes correctes, Existence d'une anomalie !"){
           /* make something red */
        }
        $anomalie->etat="en cours";
        $anomalie->step = 3;
        $anomalie->resultats = $result;
        $anomalie->save();
        $examens = Examen::where('test_id', '=' , $anomalie->test_id )->get();
        return view('quality.anomalie.create',compact('anomalie','examens'));
    }

    public function postCreateStep3(Request $request){
        $anomalie = Anomalie::findOrFail($request->id);
        $validatedData = $request->validate([
            'productimg' => 'image|mimes:jpeg,png,jpg,gif,svg',
            'diagnostique' => 'required',
            'actions' => 'required'
        ]);

        if(!empty($request->actions)){
            $anomalie->actions()->attach($request->actions);
        } 

        if($request->reparer == "on" || !empty($anomalie->reparateur_id)){
            $anomalie->reparateur_id = $request->reparateur;
            if(!empty($request->productimg)){
                $fileName = "FR-" . time() . '.' . request()->productimg->getClientOriginalExtension();
                $request->productimg->storeAs('ficheReparation', $fileName);
                $anomalie->productimg = $fileName;
            }
        } else{
            $anomalie->reparateur_id = null;
            $anomalie->productImg = null;
        }

        $examens = Examen::where('test_id', '=' , $anomalie->test_id )->get();
        $anomalie->diagnostique = $request->diagnostique;        
        $anomalie->step = 4;
        $anomalie->save();

        return view('quality.anomalie.create', compact('anomalie','examens'));
    }

    public function store(Request $request){
        $anomalie = Anomalie::findOrFail($request->id);
        $request->validate([
            'cause' => 'required',     
            'criticite' => 'required',     
            'regles' => 'required'     
        ]);
        if(!empty($request->regles)){
            $anomalie->regles()->attach($request->regles);
        }    
        $anomalie->criticite = $request->criticite;
       
        $anomalie->cause = $request->cause;    
        $anomalie->etat = "traité";  
        $anomalie->step = 1;  
        $anomalie->save();   

        /* Update state of alerts */
        $alerts = Alert::where('anomalie_id', '=' , $anomalie->id )->
                whereNotIn('type',['Rappel'])->
                where('etat', '=' , 'en cours' )->get();
        if(!empty($alerts[0])){
            $alerts[0]->etat ="traité";
            $alerts[0]->save();
        }
        return redirect(route('anomalie.dashbord'));
    }

    public function delete(Anomalie $anomalie){
        $anomalie->delete();
        return redirect(route('anomalie.dashbord'));
    }

    public function previous(Anomalie $anomalie){
        $anomalie->step-=1;
        if($anomalie->step < 1) $anomalie->step=1;
        $anomalie->save();
        $examens = Examen::where('test_id', '=' , $anomalie->test_id )->get();
        return view('quality.anomalie.create', compact('anomalie','examens'));
    }

    function generate_pdf(Anomalie $anomalie) {
        
        $pdf = PDF::loadView('pdf.ficheAnomalie', compact('anomalie'));
        return $pdf->stream('Fiche.pdf');
    }

    public function view(Anomalie $anomalie){     
        return view('quality.anomalie.view',compact('anomalie'));
    }

}<file_sep><?php

namespace App\Http\Controllers\Gestionnaire;
use DB;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Lot;
use App\Models\Test;
use App\Models\Audit;
use App\Models\Alert;
use App\Models\Event;
use App\Models\Produit;
use App\Models\Examen;
use App\Models\Reponse;
use App\Models\Questionnaire;
use Auth;
use Redirect,Response;
use PDF;
use Carbon\Carbon;
use App\Exports\AuditsExport;
use Maatwebsite\Excel\Facades\Excel;

class AuditController extends Controller
{

    public function export(){      
        $year = Carbon::now()->format('Y');
        return (new AuditsExport($year))->download('Journal des audits '.$year.'.xlsx');
    }

    public function index(){
    	$audits = Audit::orderBy('id','desc')->paginate(10);
    	return view('quality.audit.index',compact('audits'));
    }
    
    public function createFrom(Request $request, $id){
        $event = Event::findOrFail($id);
        $event->rappel = "false"; // update rappel variable
        $event->save();
        $audit = Audit::where('id', '=' , $event->audit_id)->first();
  
        if($event->alert != null){
            $event->alert->etat ="en cours";
            $event->alert->save();
        }
        return view('quality.audit.create', compact('audit'));
    }

    public function create(Request $request){   
        return view('quality.audit.create');
    }

    public function postCreateStep1(Request $request){   
        if(empty($request->id)){
            $audit = new audit(); 
        }
        else{
            $audit = audit::findOrFail($request->id);
            $update_lot = DB::table('events')
                ->where('audit_id', $audit->id )
                ->update(['title' => $audit->titre, 'start' => $request->date , 
                'end' => $request->date]); 
        }

        $request->validate([
            'titre' => 'required',
            'date' => 'required',
            'description' => 'required',
            'procede' => 'required'
        ]);

        $audit->titre = $request->titre;
        $audit->description = $request->description;
        $audit->procede_id = $request->procede;
        $audit->user_id = Auth::user()->id; // Id de l'utilisateur authentifie
       
        $audit->etat = "nouveau";   
        $audit->step = 2;
        $audit->save();

        if(empty($request->id)){

            $event = new Event();
            $event->title = $audit->titre;
            $event->start = $request->date;
            $event->end = $request->date;
            $event->type = 'Audit';
            $event->audit_id = $audit->id;
            $event->save();      
        }
     
         
        return view('quality.audit.create',compact('audit'));    
    }

    public function postCreateStep2(Request $request){    
        $audit = Audit::findOrFail($request->id);   
        Questionnaire::where('audit_id', $audit->id )->delete();    
        
        if (!empty($request->IdQ) ){
          for ($i=0; $i < count($request->IdQ) ; $i++) {
            if ( !empty($request->IdQ[$i]) ){
               DB::table('questionnaires')
               ->updateOrInsert(
               ['audit_id' =>  $audit->id , 'id' => $request->IdQ[$i] ],
               ['question' => $request->questions[$i], 
                'reponse' => $request->reponses[$i],
                'remarque' => $request->remarques[$i],
                'audit_id' => $audit->id ]
               ); 
            }
            else{
              $questionnaire = new Questionnaire();
              $questionnaire->question = $request->questions[$i];
              $questionnaire->reponse = $request->reponses[$i];
              $questionnaire->remarque = $request->remarques[$i];
              $questionnaire->audit_id = $audit->id;
              $questionnaire->save();
            }
          }
        }
        $audit->etat = "en cours";   
        $audit->step = 3;
        $audit->save();
        return view('quality.audit.create',compact('audit'));
    }

    public function store(Request $request)
    {
        $audit = audit::findOrFail($request->id);
        $request->validate([
            'resultats' => 'required'
        ]);

        if(!empty($request->actions)){
            $audit->actions()->attach($request->actions);
        } 
        if(!empty($request->regles)){
            $audit->regles()->attach($request->regles);
        }  

        $audit->resultats = $request->resultats; 

        if (!empty($request->commentaire)){
            $audit->commentaire = $request->commentaire; 
        }
        $audit->etat = "traité";   
        $audit->step = 1;
        $audit->save();
        return redirect(route('audit.dashbord'))->with('successMsg',"Création d'un nouveau audit");
    }

    public function delete(Audit $audit){
        $audit->delete();
        return redirect(route('audit.dashbord'));    
    }

    public function deleteQ(Request $request, Questionnaire $questionnaire){   
        $audit = Audit::findOrFail($request->id);
        $audit->step = 3;
        $audit->save();
        $questionnaire->delete();
        return redirect(route('audit.create-step2'));  
       // return view('quality.audit.create',compact('audit'));
    }

    public function previous(Audit $audit){
        $audit->step -= 1;  
        if($audit->step < 1) $audit->step = 1;  
        $audit->save();
        return view('quality.audit.create', compact('audit'));
    }

    public function edit(Audit $audit){        
        $audit->step = 1; 
        $audit->etat = "en cours";  
        return view('quality.audit.create',compact('audit')); 
    }

    function generate_pdf(Audit $audit) {
        
        $pdf = PDF::loadView('pdf.ficheAudit', compact('audit'));
        return $pdf->stream('Fiche.pdf');
    }

    public function view(Audit $audit){     
        return view('quality.audit.view',compact('audit'));
    }


}
<file_sep><?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class TestTableSeeder extends Seeder
{
    public function run()
    {
        DB::table('tests')->insert([ 
            'id' => '1',
            'nom' => 'Test de fiabilité FD 3.0 (16 Go)',
            'type' => 'physique',
            'description' => 'Vérifier la fiabilité du flash disque de type 3.0 et capacité 16 Go',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);


        DB::table('tests')->insert([ 
            'id' => '2',
            'nom' => 'Test électronique du câble alimentation',
            'type' => 'électronique',
            'description' => 'Vérifier les caractéristiques électroniques du câble alimentation',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);
         
        DB::table('tests')->insert([ 
            'id' => '3',
            'nom' => 'Test des caracteristiques du câble alimentation',
            'type' => 'physique',
            'description' => 'Vérifier les caractéristiques du câble alimentation',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('tests')->insert([ 
            'id' => '4',
            'nom' => 'Test fonctionel pour souris',
            'type' => 'fonctionel',
            'description' => 'Vérifier les caractéristiques de la souris',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('tests')->insert([ 
            'id' => '5',
            'nom' => 'Test électronique du chargeur',
            'type' => 'électronique',
            'description' => 'Vérifier les caractéristiques électroniques du chargeur',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('tests')->insert([ 
            'id' => '6',
            'nom' => 'Test fonctionel du câble USB',
            'type' => 'fonctionel',
            'description' => 'Vérifier la fonctionnalité du câble USB ',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

        DB::table('tests')->insert([ 
            'id' => '7',
            'nom' => 'Test de fiabilité FD 3.0 (32 Go)',
            'type' => 'physique',
            'description' => 'Vérifier la fiabilité du flash disque de type 3.0 et capacité 32 Go',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')      
        ]);

         
        
    }
    
}
<file_sep><?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use App\User;

class RoleController extends Controller
{
    public function index(){
    	$roles = Role::paginate(5);
    	return view('admin.role.index',compact('roles'));
    }

    public function create(){
        $permissions = Permission::all();
        $action = route('role.create');
        return view('admin.role.form',compact('permissions','action'));
    }


    public function store(Request $request){
        $this->validate($request,[
            'name' => ['required', 'string', 'max:255','unique:roles'],
            'description' => ['required', 'string', 'max:255'],
            'permissions' => 'required',
  	    ]);
        $role = Role::create(['name'=>$request->name, 'description'=>$request->description]);
        $role->syncPermissions($request->permissions);
        $role->save();

        return redirect(route('role.dashbord'))        
        ->with('successMsg','Role créé avec succès');
    
    }

    public function edit(Role $role){
        $action = route('role.update', ['role' => $role]);
        $permissions = Permission::all();
        return view('admin.role.form',compact('role','permissions','action'));
    }


    public function update(Request $request,Role $role){
        $role->name = $request->name;
        $role->description = $request->description;
        $role->syncPermissions($request->permissions);
        $role->save();
        return redirect(route('role.dashbord'))        
        ->with('successMsg','Role modifié avec succès');

    }


    public function delete(Role $role){
        $role->delete();
        return redirect(route('role.dashbord'));
        }
}
<file_sep><?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAnomaliesTable extends Migration
{

    public function up()
    {
        Schema::create('anomalies', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->text('titre')->nullable();
            $table->text('description')->nullable();
            $table->string('type')->nullable();
            $table->double('amount', 8, 2)->nullable();	
            $table->enum('etat', ['nouveau','en cours','traité'])->default('nouveau');
            $table->integer('step')->default(1);

            $table->string('criticite')->nullable();
            $table->text('cause')->nullable();
            $table->text('diagnostique')->nullable();
            
            $table->text('resultats')->nullable();
            $table->string('action')->nullable(); // to be changed with table (action_anomalie)

            /* one to many */
            $table->string('productimg')->nullable(); // used temporary after will use (fichier table)

            $table->unsignedBigInteger('lot_id'); // required            
            $table->unsignedBigInteger('reparateur_id')->nullable();
            $table->unsignedBigInteger('test_id')->nullable();

            $table->unsignedBigInteger('atelier_id')->nullable(); 
            $table->unsignedBigInteger('fournisseur_id')->nullable(); 
            $table->unsignedBigInteger('client_id')->nullable(); 
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('anomalies');
    }


}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Lot extends Model
{
    public function produit()
   {
       return $this->belongsTo('App\Models\Produit');
   }
   public function anomalies()
   {
       return $this->hasMany('App\Models\Anomalie');
    }

   public function alerts()
   {
       return $this->hasMany('App\Models\Alert');
   }

   public function inspections()
   {
       return $this->hasMany('App\Models\Inspection');
   }
   
}
<file_sep>
  $(document).ready(function () {
         
        var SITEURL = "{{url('/')}}";
        $.ajaxSetup({
          headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          }
        });
        var calendar = $('#calendar').fullCalendar({
            header: {
              left: 'prev,next,today',
              center: 'title',
              right: 'month,agendaWeek,agendaDay,list'
            },
            editable: true,
            events: SITEURL + "/fullcalendareventmaster",
            displayEventTime: true,
            editable: true,
            eventRender: function (event, element, view) {
                if (event.allDay === 'true') {
                    event.allDay = false;
                } else {
                    event.allDay = false;
                }
            },
            selectable: true,
            selectHelper: true,

            select: function (start, end, allDay) {
                $('#modalAddEvent').modal();
                $("#AddEventForm").submit(function(){
                    var start = $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss");
                    var end = $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss");
                    var title =$('#title').val();
                    //var heure =$('#heure').val();
                    var type = $('#type').find('option:selected').text();
                   
                    $.ajax({
                        url: SITEURL + "/fullcalendareventmaster/create",
                        data: 'title=' + title + '&type=' + type + '&start=' + start + '&end=' + end,
                        type: "POST",
                        success: function (data) {
                            $('#modalAddEvent').modal('hide');
                            swal({
                              title: "Bravo!",
                              text: "Planification d'un évenement",
                              type: "success",
                              showConfirmButton: true
                            }); 
                        },
                        error: function(data){
                            $('#modalAddEvent').modal('hide');
                            sweetAlert(
                                "Erreur...", 
                                data,
                                "error");
                        }
                    });
                    calendar.fullCalendar('renderEvent',
                    {
                        title: title,
                        start: start,
                        end: end,
                        allDay: allDay
                    },
                    true
                    ); 
                 });
            
                calendar.fullCalendar('unselect'); 
            },
             
            eventDrop: function (event, delta) {
                        var start = $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss");
                        var end = $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss");
                        $.ajax({
                            url: SITEURL + '/fullcalendareventmaster/update',
                            data: 'title=' + event.title + '&type=' + type + '&start=' + start + '&end=' + end + '&id=' + event.id,
                            type: "POST",
                            success: function (response) {
                               /* swal({
                                   title: "Bravo!",
                                   text: "Date d'évenement modifiée",
                                   type: "success",
                                   showConfirmButton: true
                                }); */
                            }
                        });
                    },
            eventClick: function (event) {
                      swal({
                          title: "Voulez-vous supprimer cet évenement ?",
                          text: "",
                          type: "warning",
                          showCancelButton: true,
                          confirmButtonColor: "#DD6B55",
                          confirmButtonText: "Oui, supprimer",
                          cancelButtonText: "Non, annuler",
                          closeOnConfirm: false,
                          closeOnCancel: false
                          },
                      function(isConfirm){
                        if (isConfirm) {
                           $.ajax({
                           type: "POST",
                           url: SITEURL + '/fullcalendareventmaster/delete',
                           data: "&id=" + event.id,
                           success: function (response) {
                            if(parseInt(response) > 0) {
                                $('#calendar').fullCalendar('removeEvents', event.id);
                               swal("Suppression !!", "Votre évenement a été supprimer !!", "success");
                             }
                            }
                           });
                        }
                        else {
                             swal("Annulation !!", "Votre évenement existe encore", "error");
                         }
                       });
            }
 
        });

  });
 
<file_sep><?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class ClientTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        
        DB::table('clients')->insert([ 
            'id' => '1',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'BP 09 Oued Smar – Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('clients')->insert([ 
            'id' => '2',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => '45,che<NAME>, 16040 hussein Dey, Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('clients')->insert([ 
            'id' => '3',
            'nom' => 'BZA Hardware',
            'description' => '',
            'adresse' => 'Cité abdouni boualem lot n° 1, <NAME>ida,Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('clients')->insert([ 
            'id' => '4',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Siège social RN n°5, Cinq Maisons, Mohammadia 16130 Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('clients')->insert([ 
            'id' => '5',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'LOT N° 1 groupe 13 El hamiz, Dar El Beida Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('clients')->insert([ 
            'id' => '6',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Local N°01 Route de Sebal N°10 El Achour,Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('clients')->insert([ 
            'id' => '7',
            'nom' => 'ISI',
            'description' => '',
            'adresse' => 'Lotissement kaouch Villa N° 8 (deriere AGB Bank) <NAME>, Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('clients')->insert([ 
            'id' => '8',
            'nom' => '<NAME>',
            'description' => '',
            'adresse' => 'Zone d’activités Mesra, Mostaganem',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('clients')->insert([ 
            'id' => '9',
            'nom' => 'COMPUSTROE',
            'description' => '',
            'adresse' => 'Lotissement boursas villa N°21 HYDRA ALGER',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);

        DB::table('clients')->insert([ 
            'id' => '10',
            'nom' => 'RedFabriq',
            'description' => '',
            'adresse' => '89, Lot Vincent II Bouzareah, Alger',
            'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
            'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
        ]);
    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Action extends Model
{
    public function user()
    {
       return $this->belongsTo('App\User');
    }

    public function attributs()
    {
        return $this->hasMany('App\Models\Attribut');
    }

    public function audits()
    {
       return $this->belongsToMany('App\Models\Audit');
    }
    
    public function anomalies()
    {
       return $this->belongsToMany('App\Models\Anomalie');
    }
    
}
<file_sep><?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use App\User;

class PermissionController extends Controller
{
    public function index(){
    	$permissions = Permission::paginate(10);
    	return view('admin.permission.index',compact('permissions'));
    }

    public function create(){
        $roles = Role::all();
        $action = route('permission.create');
        return view('admin.permission.form',compact('roles','action'));
    }
    
    public function store(Request $request){
        $this->validate($request,[
            'name' => ['required', 'string', 'max:255','unique:permissions'],
            'description' => ['required', 'string', 'max:255'],
  	    ]);
        $permission = Permission::create([
            'name'=> $request->name,
            'description'=> $request->description
        ]);
        //$permission->syncRoles($request->roles);
        /*foreach($request->models as $model) {
            $model->givePermissionTo($permission->name);
        }*/
        
        $permission->syncRoles($request->roles);
        $query = $permission->save();
        return redirect(route('permission.dashbord'))
        ->with('successMsg','Permission créé avec succès');

    }

    public function edit(Permission $permission){
        $action = route('permission.update', ['permission' => $permission]);
        $roles = Role::all();
        return view('admin.permission.form',compact('permission','roles','action'));
    }


    public function update(Request $request,Permission $permission){
        $permission->name = $request->name;
        $permission->description = $request->description;
        $permission->syncRoles($request->roles);
        $permission->save();
        return redirect(route('permission.dashbord'))
        ->with('successMsg','Permission modifiée avec succès');
    }


    public function delete(Permission $permission){
        $permission->delete();
        return redirect(route('permission.dashbord'));
    }
}
<file_sep><?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFichiersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('fichiers', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('nom');
            $table->string('type');
            $table->string('url',6000);
            $table->unsignedBigInteger('user_id')->nullable(); // the one who uploaded it or the user's avatar
            $table->unsignedBigInteger('anomalie_id')->nullable(); 
            $table->unsignedBigInteger('produit_id')->nullable(); 
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('fichiers');
    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Atelier extends Model
{   
    protected $fillable = [
        'nom' , 'metier', 'description'
    ];

    public function audits()
    {
        return $this->hasMany('App\Models\Audit');
    }
    
    public function procedes()
    {
        return $this->hasMany('App\Models\Procede');
    }
    public function anomalies()
    {
        return $this->hasMany('App\Models\Anomalie');
    }

    public function alerts()
    {
        return $this->hasMany('App\Models\Alert');
    }
}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Inspection extends Model
{
    public function user()
    {
       return $this->belongsTo('App\user');
    }

    public function lot()
    {
       return $this->belongsTo('App\Models\Lot');
    }

    public function anomalie()
    {
       return $this->belongsTo('App\Models\Anomalie');
    }

    public function attributs()
    {
        return $this->hasMany('App\Models\Attribut');
    }

    public function reponses()
    {
        return $this->hasMany('App\Models\Reponse');
    }

    public function test()
    {
       return $this->belongsTo('App\Models\Test');
    }
    
    public function event()
    {
       return $this->belongsTo('App\Models\Event');
    }
}
