Methmi
1 month ago
116
1
Laravel

Create PDF on searched view

Posted 1 month ago by Methmi

This is my controller to the search, searched view and pdf generation

 public function mdaterange(Request $request,$id)
    {
         $machines = Machines::find($id);
       $sdate = $request->get('sdate');
        $edate = $request->get('edate');

        $dailyrunningcharts = dailyrunningcharts::where('drc_mid',$id)
        ->whereBetween('drc_date', [$sdate, $edate])
        ->get();

             $ename = DB::table('employees')
            ->where('dailyrunningcharts.drc_moperator', $id)
            ->join('dailyrunningcharts', 'dailyrunningcharts.drc_moperator', '=', 'employees.e_id')
            ->select('employees.e_sname')
            ->get();

             $pname = DB::table('projects')
            ->where('dailyrunningcharts.drc_pid', $id)
            ->join('dailyrunningcharts', 'dailyrunningcharts.drc_pid', '=', 'projects.p_id')
            ->select('projects.p_name')
            ->get();

        return view('dashboard.machines.m_overview_report', compact('machines','dailyrunningcharts','ename','pname','sdate','edate'))->with('drc_mid',$id);
               
    }
 public function m_overview_report(Request $request,$id)
    {
          $machines = Machines::find($id);
       $sdate = $request->get('sdate');
        $edate = $request->get('edate');

        $dailyrunningcharts = dailyrunningcharts::where('drc_mid',$id)->get();
       

             $ename = DB::table('employees')
            ->where('dailyrunningcharts.drc_moperator', $id)
            ->join('dailyrunningcharts', 'dailyrunningcharts.drc_moperator', '=', 'employees.e_id')
            ->select('employees.e_sname')
            ->get();

             $pname = DB::table('projects')
            ->where('dailyrunningcharts.drc_pid', $id)
            ->join('dailyrunningcharts', 'dailyrunningcharts.drc_pid', '=', 'projects.p_id')
            ->select('projects.p_name')
            ->get();

        return view('dashboard.machines.m_overview_report', compact('machines','dailyrunningcharts','ename','pname','sdate','edate'))->with('drc_mid',$id);
               
    }
 public function mor_pdf(Request $request,$id)
    {
          $machines = Machines::find($id);
       $sdate = $request->get('sdate');
        $edate = $request->get('edate');

         $dailyrunningcharts = dailyrunningcharts::where('drc_mid',$id)->get();

         $ename = DB::table('employees')
            ->where('dailyrunningcharts.drc_moperator', $id)
            ->join('dailyrunningcharts', 'dailyrunningcharts.drc_moperator', '=', 'employees.e_id')
            ->select('employees.e_sname')
            ->get();

             $pname = DB::table('projects')
            ->where('dailyrunningcharts.drc_pid', $id)
            ->join('dailyrunningcharts', 'dailyrunningcharts.drc_pid', '=', 'projects.p_id')
            ->select('projects.p_name')
            ->get();
        

            $pdf = PDF::loadView('dashboard.machines.mor_pdf',compact('machines','dailyrunningcharts','ename','pname','sdate','edate'));
        return $pdf->stream('dashboard.machines.mor_pdf.pdf');
        
    }

This is the blade where it can search

 <div class="card" style="height: 80px;" >
      <div class="card-body">
        <div class="row">
          <div class="col-8">

             <form action="{{ route('mdaterange',$machines->m_id)}}" method="get">
        <div class="form-row">

        <div class="col">
          <div class="form-group row">
            &nbsp
         <label >From :</label>
         <div class="col-sm-8">
         <input class="form-control" type="Date" name="sdate" value="{{$sdate}}">
       </div>
     </div>
        </div>
        <div class="col">
          <div class="form-group row">
         <label >To :</label>
         <div class="col-sm-8">
        <input class="form-control" type="Date" name="edate" value="{{$edate}}">
      </div>
        </div>
      </div>
       <button class="btn btn-success" style="height: 40px;" >Filter</button>
       &nbsp &nbsp
        <a href="{{ route('m_overview_report',$machines->m_id)}}" type="submit" class="btn btn-primary" style="height: 40px;">Refresh</a>
        </div>
      </form>
  
          </div>
          <div class="col">
              <a href="{{ route('mor_pdf',$machines->m_id)}}" type="submit" class="btn btn-info float-right" >Save As PDF </a>
          </div>
        </div>
    </div>
    </div>

  <div class="card " >

    <div class="card-header">
    <h5 class="card-title">
      
      <div  class="form-inline">
    <label>Machine ID :</label>
    &nbsp &nbsp
    <label>{{ $machines->m_gid }}</label>
    </div>

    <div  class="form-inline">
    <label>Machine Type :</label>
    &nbsp &nbsp
    <label>{{ $machines->m_type }}</label>
    </div>

        </h5>
  </div>

  <div class="card-body">
  <table class="table table-striped">

        <thead class="thead-dark">
        <tr>
          <th scope="col">Date</th>
          <th scope="col">Project</th>
          <th scope="col">Machine Operator</th>
          <th scope="col">Hours</th>
          <th scope="col">Work Type</th>
          <th scope="col">Notes</th>
          <th scope="col"></th>
        </tr>
      </thead>
      <tbody>
      
        @foreach($pname as $d)
          @foreach($ename as $e)
         @foreach($dailyrunningcharts as $c)
        <tr>
          <td>{{ $c->drc_date }}</td> 
          <td>{{ $d->p_name }}</td>
          <td>{{ $e->e_sname }}</td>
          <td>{{ $c->drc_hours }} hrs</td>
          <td>{{ $c->drc_worktype }}</td>
           <td>{{ $c->drc_notes }}</td>
           <td>
           <div class="btn-group">
            <a href="#" class="btn btn-info"><i class="fas fa-edit"></i></a>
            
            </div>
            </td>
        </tr>
        @endforeach
        @break
         @endforeach
         @break
          @endforeach 

       
       </tbody>
    </table>    
</div>


 </div>

This is the blade for pdf generation

<h4>

    <div  class="form-inline">
    <label>Machine ID :</label>
    <label>{{ $machines->m_gid }}</label>
  </div>

    <div  class="form-inline">
    <label>Machine Type :</label>
    <label>{{ $machines->m_type }}</label>
    </div>

    <div  class="form-inline">
    <label>Time Duration :</label>
    <label>From</label>
    <label>{{ $sdate }}</label>
    <label>To</label>
    <label>{{ $edate }}</label>
    </div>

    </h4>

    <form action="{{ route('mdaterange',$machines->m_id)}}" method="get">
        <div class="form-row">

        <div class="col">
          <div class="form-group row">
            &nbsp
         <label >From :</label>
         <div class="col-sm-8">
         <input class="form-control" type="Date" name="sdate" value="{{$sdate}}">
       </div>
     </div>
        </div>
        <div class="col">
          <div class="form-group row">
         <label >To :</label>
         <div class="col-sm-8">
        <input class="form-control" type="Date" name="edate" value="{{$edate}}">
      </div>
        </div>
      </div>
       <button class="btn btn-success" style="height: 40px;" >Filter</button>
       &nbsp &nbsp
        <a href="{{ route('m_overview_report',$machines->m_id)}}" type="submit" class="btn btn-primary" style="height: 40px;">Refresh</a>
        </div>
      </form>
  

  
   <table>

        <thead>
        <tr>
          <th scope="col">Date</th>
          <th scope="col">Project</th>
          <th scope="col">Machine Operator</th>
          <th scope="col">Hours</th>
          <th scope="col">Work Type</th>
          <th scope="col">Notes</th>
          
        </tr>
    </thead>
    <tbody>
        @foreach($pname as $d)
          @foreach($ename as $e)
         @foreach($dailyrunningcharts as $c)
        <tr>
          <td>{{ $c->drc_date }}</td> 
          <td>{{ $d->p_name }}</td>
          <td>{{ $e->e_sname }}</td>
          <td>{{ $c->drc_hours }}</td>
          <td>{{ $c->drc_worktype }}</td>
           <td>{{ $c->drc_notes }}</td>
        </tr>
        @endforeach
        @break
         @endforeach
         @break
          @endforeach 
        </tbody>
    </table>


How can I view the searched results in my pdf

Please sign in or create an account to participate in this conversation.