From 2d2395a97de8da8bf09945215bbc8331e6ee657c Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Fri, 10 Jul 2020 03:44:33 -0500 Subject: [PATCH] supply chain coding --- .../Contracts/SupplyChainController.php | 102 ++++++++++++++++-- ...6_29_054832_create_new_contracts_table.php | 2 +- .../supplychain/forms/deletebid.blade.php | 4 + .../supplychain/forms/modifybid.blade.php | 6 ++ 4 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 resources/views/supplychain/forms/deletebid.blade.php create mode 100644 resources/views/supplychain/forms/modifybid.blade.php diff --git a/app/Http/Controllers/Contracts/SupplyChainController.php b/app/Http/Controllers/Contracts/SupplyChainController.php index 216410bf9..407c1a0a9 100644 --- a/app/Http/Controllers/Contracts/SupplyChainController.php +++ b/app/Http/Controllers/Contracts/SupplyChainController.php @@ -228,10 +228,37 @@ class SupplyChainController extends Controller */ public function storeSupplyChainContractBid(Request $request) { $this->validate($request, [ - + 'bid' => 'required', + 'contract_id' => 'required', ]); - return redirect('/supplychain/dashboard')->with('success', 'Successfully stored supply chain contract bid.'); + $count = SupplyChainBid::where([ + 'entity_id' => auth()->user()->getId(), + 'entity_name' => auth()->user()->getName(), + 'contract_id' => $request->contract_id, + ])->count(); + + //If the person already has a bid in, then deny them the option to place another bid on the same contract. + //Otherwise, enter the bid into the database + if($count > 0) { + redirect('/supplychain/dashboard')->with('error', 'Unable to insert bid as one is already present for the supply chain contract.'); + } else { + //Sanitize the bid amount + + //Create the database entry + $bid = new SupplyChainBid; + $bid->contract_id = $request->contract_id; + $bid->bid_amount = $request->bid; + $bid->entity_id = auth()->user()->getId(); + $bid->entity_name = auth()->user()->getName(); + $bid->entity_type = 'character'; + if(isset($request->notes)) { + $bid->bid_note = $request->notes; + } + $bid->save(); + + redirect('/supplychain/dashboard')->with('success', 'Bid succesfully entered into the contract.'); + } } /** @@ -239,10 +266,41 @@ class SupplyChainController extends Controller */ public function deleteSupplyChainContractBid(Request $request) { $this->validate($request, [ - + 'contract_id' => 'required', + 'bid_id' => 'required', ]); - return redirect('/suppplychain/dashboard')->with('success', 'Deleted supply chain contract bid.'); + //See if the user has put in a bid. If not, then redirect to failure. + $count = SupplyChainBid::where([ + 'contract_id' => $request->contract_id, + 'entity_id' => auth()->user()->getId(), + 'bid_id' => $request->bid_id, + ])->count(); + + if($count > 0) { + SupplyChainBid::where([ + 'contract_id' => $request->contract_id, + 'entity_id' => auth()->user()->getId(), + 'bid_id' => $request->bid_id, + ])->delete(); + + return redirect('/suppplychain/dashboard')->with('success', 'Deleted supply chain contract bid.'); + } else { + return redirect('/supplychain/dashboard')->with('error', 'No bid found to delete.'); + } + } + + /** + * Display the modify a bid on supply chain contract page + */ + public function displayModifySupplyChainContractBid(Request $request) { + $this->validate($request, [ + 'contract_id' => 'required', + ]); + + $contractId = $request->contract_id; + + return view('supplychain.forms.modifybid')->with('contractId', $contractId); } /** @@ -250,10 +308,42 @@ class SupplyChainController extends Controller */ public function modifySupplyChainContractBid(Request $request) { $this->validate($request, [ - + 'bid_id' => 'required', + 'contract_id' => 'required', + 'bid_amount' => 'required', ]); - return redirect('/supplychain/dashboard')->with('success', 'Modified supply chain contract bid.'); + //Check for the owner of the bid + $count = SupplyChainBid::where([ + 'bid_id' => $request->bid_id, + 'contract_id' => $request->contract_id, + 'entity_id' => auth()->user()->getId(), + ])->count(); + + if($count > 0) { + if(isset($request->bid_note)) { + SupplyChainBid::where([ + 'bid_id' => $request->bid_id, + 'contract_id' => $request->contract_id, + 'entity_id' => auth()->user()->getId(), + ])->update([ + 'bid_amount' => $request->bid_amount, + 'bid_note' => $request->bid_note, + ]); + } else { + SupplyChainBid::where([ + 'bid_id' => $request->bid_id, + 'contract_id' => $request->contract_id, + 'entity_id' => auth()->user()->getId(), + ])->update([ + 'bid_amount' => $request->bid_amount, + ]); + } + + return redirect('/supplychain/dashboard')->with('success', 'Modified supply chain contract bid.'); + } else { + return redirect('/supplychain/dashboard')->with('error', 'Not able to modify supply chain contract bid.'); + } } /** diff --git a/database/migrations/2020_06_29_054832_create_new_contracts_table.php b/database/migrations/2020_06_29_054832_create_new_contracts_table.php index 0c8d10fe1..560a38baf 100644 --- a/database/migrations/2020_06_29_054832_create_new_contracts_table.php +++ b/database/migrations/2020_06_29_054832_create_new_contracts_table.php @@ -47,7 +47,7 @@ class CreateNewContractsTable extends Migration if(!Schema::hasTable('supply_chain_bids')) { Schema::create('supply_chain_bids', function(Blueprint $table) { - $table->increments('id')->unique(); + $table->increments('bid_id')->unique(); $table->unsignedBigInteger('contract_id'); $table->decimal('bid_amount', 20, 2)->default(0.00); $table->unsignedBigInteger('entity_id'); diff --git a/resources/views/supplychain/forms/deletebid.blade.php b/resources/views/supplychain/forms/deletebid.blade.php new file mode 100644 index 000000000..611c41198 --- /dev/null +++ b/resources/views/supplychain/forms/deletebid.blade.php @@ -0,0 +1,4 @@ +@extends('layouts.user.dashb4') +@section('content') + +@endsection \ No newline at end of file diff --git a/resources/views/supplychain/forms/modifybid.blade.php b/resources/views/supplychain/forms/modifybid.blade.php new file mode 100644 index 000000000..d35ebe99a --- /dev/null +++ b/resources/views/supplychain/forms/modifybid.blade.php @@ -0,0 +1,6 @@ +@extends('layouts.user.dashb4') +@section('content') +
+ +
+@endsection \ No newline at end of file