mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim-api.git
synced 2026-08-19 04:24:01 +00:00
bug fixing
This commit is contained in:
@@ -19,4 +19,16 @@ class Company extends Model
|
|||||||
return $this->hasMany('App\Deliveryinfo');
|
return $this->hasMany('App\Deliveryinfo');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function warehouse() {
|
||||||
|
|
||||||
|
return $this->hasMany('App\Warehouse');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function contact() {
|
||||||
|
|
||||||
|
return $this->hasMany('App\Contact');
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-7
@@ -8,21 +8,16 @@ class Contact extends Model
|
|||||||
{
|
{
|
||||||
protected $fillable = ['company_id'];
|
protected $fillable = ['company_id'];
|
||||||
|
|
||||||
public function user()
|
public function user() {
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
return $this->belongsTo(App/User);
|
return $this->belongsTo(App/User);
|
||||||
|
|
||||||
}
|
}
|
||||||
public function company()
|
|
||||||
|
|
||||||
{
|
public function company(){
|
||||||
|
|
||||||
return $this->belongsTo(App/Company);
|
return $this->belongsTo(App/Company);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,52 +8,59 @@ use Illuminate\Http\Request;
|
|||||||
|
|
||||||
class ContactController extends Controller
|
class ContactController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* list the company that belongs to user's company only
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$contact=Contact::all();
|
$contacts = Contact::where('user_id', Auth::user()->id)->where('id', $id)->first();
|
||||||
$response=[
|
|
||||||
'contact'=>$contact
|
if (!$contacts)
|
||||||
];
|
{
|
||||||
return response()->json($contact, 200);
|
return response()->json(['message'=>'Access Denied!'], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json($contacts, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a new contact list.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
|
|
||||||
$contact = new Contact;
|
|
||||||
$contact->com_id = $user->company();
|
|
||||||
|
|
||||||
// get company id from request ex:
|
|
||||||
|
|
||||||
// query to find company asisng to $company
|
// query to find company asisng to $company
|
||||||
// $company = Company::find($company_id);
|
$company = Company::find($com_id);
|
||||||
|
|
||||||
// get user from session
|
// get user from session
|
||||||
// $request->user();
|
$request->user();
|
||||||
// $user = $request->user();
|
$user = $request->user();
|
||||||
|
|
||||||
// prepare query
|
// prepare query
|
||||||
$contact = new Contact();
|
$contact = new Contact();
|
||||||
$contact->company_id = $company->id;
|
$contact->com_id = $company->id;
|
||||||
$contact->user_id = $user->id;
|
$contact->user_id = $user->id;
|
||||||
$contact->save();
|
$contact->save();
|
||||||
// insert into database
|
|
||||||
return response()->json($contact, 201);
|
return response()->json($contact, 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy($id)
|
/**
|
||||||
{
|
* Approve a new contact list.
|
||||||
$contact = Contact::where("user_id", Auth::user()->id)->where('id', $id)->first();
|
*
|
||||||
//$contact=Contact::find($id);
|
* @param \Illuminate\Http\Request $request
|
||||||
$contact->delete();
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
return response()->json($contact, 204);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function postApprove(Request $request, $id)
|
public function postApprove(Request $request, $id)
|
||||||
{
|
{
|
||||||
$contact = Contact::where("user_id", Auth::user()->id)->where('id', $id)->first();
|
$contact = Contact::where('com_id', Auth::user()->company())->where('id', $id)->first();
|
||||||
//$contact = Contact::where('id', '=', e($id))->first();
|
//$contact = Contact::where('id', '=', e($id))->first();
|
||||||
if($contact)
|
if($contact)
|
||||||
{
|
{
|
||||||
@@ -67,6 +74,7 @@ class ContactController extends Controller
|
|||||||
$contact->status=0;
|
$contact->status=0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
||||||
return response()->json(["message" => "not allowed"], 400);
|
return response()->json(["message" => "not allowed"], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,4 +90,24 @@ class ContactController extends Controller
|
|||||||
//return redirect()->back()->with('info','Request has been approved ');
|
//return redirect()->back()->with('info','Request has been approved ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the contact list.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
$contact = Contact::where('com_id', Auth::user()->company())->where('id', $id)->first();
|
||||||
|
|
||||||
|
if (!$contact)
|
||||||
|
{
|
||||||
|
return response()->json(['message'=>'Access Denied!'], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$contact->delete($id);
|
||||||
|
|
||||||
|
return response()->json($contact, 204);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class DeliveryinfoController extends Controller
|
|||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$deliveryinfo = Deliveryinfo::where('com_id', Auth::user()->company())->get();
|
$deliveryinfo = Deliveryinfo::where('com_id', Auth::user()->company())->get();
|
||||||
|
|
||||||
return response()->json($deliveryinfo, 200);
|
return response()->json($deliveryinfo, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,33 +16,40 @@ class WarehouseController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$warehouse = Warehouse::where('com_id', Auth::user()->company())->where('id', $id)->firstOrFail();
|
$warehouses = Warehouse::where('com_id', Auth::user()->company())->get();
|
||||||
|
|
||||||
if (!$warehouse)
|
if (!$warehouses)
|
||||||
{
|
{
|
||||||
return response()->json(['message'=>'Access Denied!'], 404);
|
return response()->json(['message'=>'Access Denied!'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$warehouse=Warehouse::all();
|
$warehouse = Warehouse::all();
|
||||||
|
|
||||||
return response()->json($warehouse, 200);
|
return response()->json($warehouses, 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display warehouse list from freight forwarder.
|
* Display warehouse list from freight forwarder. can list the warehouse if it is from the freight forwarder
|
||||||
|
* need to do DB query
|
||||||
|
* show all the warehouse that belongs to the user company
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$warehouse=Warehouse::find($id);
|
$warehouses = DB::table('warehouses')
|
||||||
$response=[
|
//->join('id', 'address', 'city', 'zip')
|
||||||
|
->select('id', 'address', 'city', 'zip', 'state', 'contact_person', 'contact_person_no', 'branch', 'country', 'com_id')
|
||||||
|
->where('com_id', Auth::user()->company())
|
||||||
|
->get();
|
||||||
|
|
||||||
'warehouse'=>$warehouse
|
if (!$warehouses)
|
||||||
|
{
|
||||||
|
return response()->json(['message'=>'Access Denied!'], 404);
|
||||||
|
}
|
||||||
|
|
||||||
];
|
|
||||||
return response()->json($warehouse, 200);
|
return response()->json($warehouse, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -6,5 +6,11 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
|
|
||||||
class Warehouse extends Model
|
class Warehouse extends Model
|
||||||
{
|
{
|
||||||
protected $fillable = ['city', 'address','zip','state','contact_person','contact_person_no','branch','country','company_id'];
|
protected $fillable = ['city', 'address','zip','state','contact_person','contact_person_no','branch','country','comp_id'];
|
||||||
|
|
||||||
|
public function contact(){
|
||||||
|
|
||||||
|
return $this->hasMany(App/Contact);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class AddForeignKeyToWarehousesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('warehouses', function (Blueprint $table) {
|
||||||
|
|
||||||
|
$table->unsignedInteger('com_id');//FK wrn id
|
||||||
|
$table->foreign('com_id')
|
||||||
|
->references('id')->on('warehouses')
|
||||||
|
->onDelete('cascade');
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('warehouses', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user