create stock and stock logs
This commit is contained in:
@@ -11,6 +11,7 @@ use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
@@ -25,19 +26,19 @@ class ProductsController extends Controller
|
||||
{
|
||||
$menu = Menu::where('link','products.index')->first();
|
||||
if($request->ajax()){
|
||||
$data = Product::with(['category','opnameDetails']);
|
||||
$data = Product::with(['category', 'stocks']);
|
||||
return DataTables::of($data)
|
||||
->addIndexColumn()
|
||||
->addColumn('category_name', function ($row) {
|
||||
return $row->category ? $row->category->name : '-';
|
||||
})
|
||||
->addColumn('total_stock', function ($row){
|
||||
return $row->opnameDetails->sum('system_stock');
|
||||
return number_format($row->current_total_stock, 2);
|
||||
})
|
||||
->addColumn('action', function ($row) use ($menu) {
|
||||
$btn = '<div class="d-flex">';
|
||||
|
||||
if (Auth::user()->can('update', $menu)) {
|
||||
if (Gate::allows('update', $menu)) {
|
||||
$btn .= '<a href="' . route('products.edit', $row->id) . '" class="btn btn-warning btn-sm" style="margin-right: 8px;">Edit</a>';
|
||||
}
|
||||
|
||||
@@ -196,7 +197,7 @@ class ProductsController extends Controller
|
||||
|
||||
public function all_products(){
|
||||
try{
|
||||
$products = Product::select('id','name')->get();
|
||||
$products = Product::where('is_active', true)->select('id','name')->get();
|
||||
return response()->json($products);
|
||||
}catch(\Exception $ex){
|
||||
Log::error($ex->getMessage());
|
||||
@@ -206,17 +207,12 @@ class ProductsController extends Controller
|
||||
public function dealers_stock(Request $request){
|
||||
$productId = $request->get('product_id');
|
||||
|
||||
$product = Product::with(['opnameDetails.opname.dealer'])->findOrFail($productId);
|
||||
$product = Product::with(['stocks.dealer'])->findOrFail($productId);
|
||||
|
||||
$opnameDetails = $product->opnameDetails;
|
||||
|
||||
$data = $opnameDetails->map(function ($detail) {
|
||||
$data = $product->stocks->map(function ($stock) {
|
||||
return [
|
||||
'dealer_name' => $detail->opname->dealer->name ?? '-',
|
||||
'system_stock' => $detail->system_stock,
|
||||
'physical_stock' => $detail->physical_stock,
|
||||
'difference' => $detail->physical_stock - $detail->system_stock,
|
||||
'opname_date' => optional($detail->opname)->created_at->format('d M Y')
|
||||
'dealer_name' => $stock->dealer->name ?? '-',
|
||||
'quantity' => $stock->quantity
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user