<?php

namespace App\Http\Controllers\Reports;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use App\Models\Product;

use App\Models\User;
use DB;
use PDF;


class repProductList extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        return view('Reports.ProductList.index');
    }


    protected function productsList(){
        return $products = DB::SELECT("select  a.product_code,
                                        (SELECT c.Code FROM units c WHERE c.id = a.BuyingUnit ) BuyingUnit,
                                        a.buying_price,
                                        (SELECT c.Code FROM units c WHERE c.id = a.SellingUnit ) SellingUnit,
                                        a.selling_price,
                                        a.factor,
                                        a.barcode,
                                        b.name tax_name
                                from    products a, taxes b
                                WHERE   a.tax_id = b.id");
    }
    public function Report(Request $request){
        $products = $this->productsList();
        return view('Reports.ProductList.report',compact('request'))->with('products',$products);
    }

    public function pdf(){
        dd('Test');
        $products = $this->productsList();
        $pdf = PDF::loadView('Reports.Stocklevels.pdf',compact('products'));
        return $pdf->stream('ProductList.pdf');
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     */
    public function show(string $id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(string $id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, string $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(string $id)
    {
        //
    }
}
