IMMREX7
<?php
namespace App\Http\Controllers\School\Stock;
use Illuminate\Http\Request;
use App\Http\Controllers\School\SchoolController;
use Auth;
use DB;
use Session;
class SupplierController extends SchoolController {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$suppliers = \App\Supplier::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idSupplier', 'desc')->get();
return view('schools.stock.supplier', compact('suppliers'));
}
/**
* 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) {
$rules = [
'bussinessName' => "unique:suppliers,bussinessName,NULL,idSupplier,idSchool," . Auth::guard('school')->user()->idSchool,
];
$message = [
'bussinessName.unique' => 'Supplier with this business name already Exist.',
];
$this->Validate($request, $rules, $message);
$supplier = new \App\Supplier();
$supplier->fill($request->all());
$supplier->idSchool = Auth::guard('school')->user()->idSchool;
$supplier->idFinancialYear = Session::get('idFinancialYear');
$supplier->save();
flash('Supplier has been added successfully!!');
return redirect('school/suppliers');
}
/**
* 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) {
$suppliers = \App\Supplier::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idSupplier', 'desc')->get();
$supplier = \App\Supplier::where('idSupplier', '=', $id)->first();
return view('schools.stock.supplier', compact('suppliers','supplier'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {
$rules = [
'bussinessName' => 'unique:suppliers,bussinessName,' . $id . ',idSupplier,idSchool,' . Auth::guard('school')->user()->idSchool,
];
$message = [
'bussinessName.unique' => 'Supplier with this business name already Exist.',
];
$this->Validate($request, $rules, $message);
$supplier = \App\Supplier::where('idSupplier', '=', $id)->first();
$supplier->fill($request->all());
$supplier->update();
return redirect('school/suppliers');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
$supplier = \App\Supplier::where('idSupplier', '=', $id)->first();
$supplier->delete();
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
public function purchaseReturn($id){
$purchase_orders = \App\PurchaseOrder::select('idPurchaseOrder','poNo')->where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('idFinancialYear', '=', Session::get('idFinancialYear'))
->where('idSupplier','=',$id)
->orderBy('idPurchaseOrder', 'desc')
->get();
return json_encode($purchase_orders);
}
public function getReceivedProducts($id) {
$products = DB::table('product_received')
->join('product_received_details','product_received_details.idProductReceived','=','product_received.idProductReceived')
->join('products','products.idProduct','=','product_received_details.idProduct')
->where('idSupplier','=',$id)
->select('product_received_details.idProduct','idPurchaseOrder','productName')
->get();
return json_encode($products);
}
}
Copyright © 2021 -