<?php

namespace App\Http\Controllers\produksi;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use Fpdf;
use Yajra\Datatables\Datatables;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Session;

class LaporanBarangkeluarController extends Controller
{
    //
    public function __construct(){      
        $this->middleware(function ($request, $next) {
        $url = request()->segment(1);
        $kode_group = Session::get('kode_group');
        $d_menu = DB::table("tb_menu as a")->join("tb_role as b","a.kode_menu","b.kode_menu")->where([['a.link_menu',$url],['b.kode_group',$kode_group],['b.status_role','1'],['a.active','1']])->orderBy('a.sort_menu','asc')->count();
        if(Session::get('decode') <> 1)
         {
            Session::flash('message', 'Silahkan login dengan username dan password anda.!!');
             return redirect()->to('login');
         }
         if($d_menu == 0){
            Session::flush();
            Session::flash('message', 'Anda Tidak Punya Akses ke Halaman ini.!!');
             return redirect()->to('login');
         }
        return $next($request); 
        });
    }
    
    Public function index(){
        $data['proses'] = DB::table('ms_proses as mp')->leftJoin('ms_proses as mp2','mp.parent','mp2.id_proses')->select('mp.nama_proses as nama_proses','mp2.nama_proses as nama_proses2','mp.id_proses')->where([['mp.nama_proses','<>','Pengemasan Satuan'],['mp.nama_proses','<>','Pengemasan Sepuluh'],['mp.nama_proses','<>','Pengemasan Seratus'],['mp.nama_proses','<>','Seri'],['mp.nama_proses','<>','Plat'],['mp.nama_proses','<>','Packing Karung']])->orderBy('mp.id_proses','ASC')->get();
        return view('produksi.LaporanBarangkeluarList')->with('data',$data);

    }

    function tampil_rekapkeluar(Request $request){
        
    }

    Public function produksisarung(){
    	require('fpdf181/Mc_table.php');
    	$data['header'] = 'SLIP UPAH BORONGAN Produksi Sarung';
    	$html = view('produksi.cetak.LaporanBarangkeluar_BoronganSarungCetak')->with('data',$data);
        return response($html)->header('Content-Type', 'application/pdf');
    }

    public function produksisarung_makelar(){
    	require('fpdf181/Mc_table.php');
    	$data['header'] = 'SLIP UPAH MAKELAR Produksi Sarung';
    	$html = view('produksi.cetak.LaporanBarangkeluar_MakelarSarungCetak')->with('data',$data);
        return response($html)->header('Content-Type', 'application/pdf');
    }

    public function produksitenun_petugas(){
    	require('fpdf181/Mc_table.php');
    	$data['header'] = 'HASIL PROD. TENUN LAINNYA / PETUGAS';
    	$html = view('produksi.cetak.LaporanBarangkeluar_PetugasTenunCetak')->with('data',$data);
        return response($html)->header('Content-Type', 'application/pdf');
    }

    public function produksi_laporanhasil(){
    	require('fpdf181/Mc_table.php');
    	$data['header'] = 'LAPORAN HASIL Produksi - PROSES BUKA';
    	$html = view('produksi.cetak.LaporanBarangmasuk_BukaCetak')->with('data',$data);
        return response($html)->header('Content-Type', 'application/pdf');	
    }

    public function laporanmutasi_persediaan(){
    	require('fpdf181/Mc_table.php');
    	$data['header'] = 'MUTASI PERSEDIAAN WIP JAHIT II';
    	$html = view('produksi.cetak.LaporanBarangmasuk_MutasiCetak')->with('data',$data);
        return response($html)->header('Content-Type', 'application/pdf');	
    }
}
