121 lines
3.1 KiB
PHP
121 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\WarehouseManagement;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Menu;
|
|
use App\Models\Product;
|
|
use App\Models\ProductCategory;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Yajra\DataTables\Facades\DataTables;
|
|
|
|
class ProductsController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$menu = Menu::where('link','products.index')->first();
|
|
if($request->ajax()){
|
|
$data = Product::with(['category','dealers']);
|
|
return DataTables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('category_name', function ($row) {
|
|
return $row->category ? $row->category->name : '-';
|
|
})
|
|
->addColumn('total_stock', function ($row){
|
|
return $row->dealers->sum(function($dealer){
|
|
return $dealer->pivot->quantity ?? 0;
|
|
});
|
|
})
|
|
->addColumn('action', function ($row) use ($menu) {
|
|
$btn = '';
|
|
|
|
if (Auth::user()->can('delete', $menu)) {
|
|
$btn .= '<button class="btn btn-danger btn-sm btn-destroy-product" data-action="' . route('products.destroy', $row->id) . '" data-id="' . $row->id . '">Hapus</button>';
|
|
}
|
|
|
|
if (Auth::user()->can('update', $menu)) {
|
|
$btn .= '<button class="btn btn-warning btn-sm btn-edit-product" data-url="' . route('products.edit', $row->id) . '" data-action="' . route('products.update', $row->id) . '" data-id="' . $row->id . '">Edit</button>';
|
|
}
|
|
|
|
return $btn;
|
|
})
|
|
->rawColumns(['action'])
|
|
->make(true);
|
|
}
|
|
return view('warehouse_management.products.index');
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
}
|