user side of contracts
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use DB;
|
||||
use Carbon\Carbon;
|
||||
|
||||
//Libraries
|
||||
//use App\Library\Contracts\ContractHelper;
|
||||
@@ -11,31 +12,132 @@ use DB;
|
||||
//Models
|
||||
use App\User;
|
||||
use App\Models\User\UserPermission;
|
||||
use App\Models\Contracts\Contract;
|
||||
use App\Models\Contracts\Bid;
|
||||
|
||||
class ContractController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('role:User');
|
||||
$this->middleware('permission:contract.canbid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller function to display the bids placed on contracts
|
||||
*/
|
||||
public function displayBids($contractId) {
|
||||
$bids = Bids::where(['contract_id' => $contractId, 'character_name' => auth()->user()->getname()])->get();
|
||||
|
||||
return view('contracts.bids')->with('bids', $bids);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Controller function to display all current open contracts
|
||||
*
|
||||
*/
|
||||
public function displayContracts() {
|
||||
//Caluclate today's date to know which contracts to display
|
||||
$today = Carbon::now();
|
||||
|
||||
//Declare array variables
|
||||
$bids = array();
|
||||
$data = array();
|
||||
$contracts = array();
|
||||
|
||||
$contracts = Contract::where(['end_date', '>=', $today])->get();
|
||||
|
||||
return view('contracts.allcontracts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller function to display all current public contracts
|
||||
*/
|
||||
public function displayPublicContracts() {
|
||||
//Calculate today's date to know which contracts to display
|
||||
$today = Carbon::now();
|
||||
|
||||
return view('contracts/publiccontract');
|
||||
//Declare our array variables
|
||||
$bids = array();
|
||||
$data = array();
|
||||
|
||||
//Fetch all of the current contracts from the database
|
||||
$contracts = Contract::where(['end_date', '>=', $today])->get();
|
||||
|
||||
//Check if no contracts were pulled from the database
|
||||
if($contracts != null) {
|
||||
//Foreach each contract we need to gather all of the bids
|
||||
foreach($contracts as $contract) {
|
||||
//Get all of the bids for the current contract
|
||||
$bids = Bid::where(['contract_id' => $contract->id])->get();
|
||||
//Build the data structure
|
||||
$temp = [
|
||||
'contract' => $contract,
|
||||
'bids' => $bids,
|
||||
];
|
||||
|
||||
//Push the new contract onto the stack
|
||||
array_push($data, $temp);
|
||||
}
|
||||
} else {
|
||||
$data = null;
|
||||
}
|
||||
|
||||
|
||||
return view('contracts.publiccontracts')->with('data', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller function to display current private contracts
|
||||
*/
|
||||
public function displayPrivateContracts() {
|
||||
//Calucate today's date to know which contracts to display
|
||||
$today = Carbon::now();
|
||||
|
||||
return view ('contracts/privatecontract');
|
||||
//Fetch all of the current contracts from the database
|
||||
$contracts = Contract::where(['end_date', '>=', $today])->get();
|
||||
|
||||
return view ('contracts.privatecontracts')->with('contracts', $contracts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller function to store a new bid
|
||||
*/
|
||||
public function storeBid(Request $request) {
|
||||
//Valid the request from the enter bid page
|
||||
$this->validate($request, [
|
||||
'contract_id' => 'required',
|
||||
'bid' => 'required',
|
||||
]);
|
||||
|
||||
return redirect('contracts/publiccontract');
|
||||
//Create the model object to save data to
|
||||
$bid = new Bid;
|
||||
$bid->contract_id = $request->contract_id;
|
||||
$bid->bid = $request->bid;
|
||||
$bid->accepted = false;
|
||||
$bid->save();
|
||||
|
||||
//Redirect to the correct page
|
||||
return redirect('/contracts/display/public')->with('success', 'Bid accepted.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller function to delete a bid
|
||||
*/
|
||||
public function deleteBid(Request $request) {
|
||||
//Validate the request from the previous page
|
||||
$this->validate($request, [
|
||||
'id' => 'required',
|
||||
'contract_id' => 'required',
|
||||
]);
|
||||
|
||||
return redirect('contracts/publiccontract');
|
||||
//Delete the bid entry from the database
|
||||
Bid::where([
|
||||
'id' => $request->id,
|
||||
'contract_id' => $request->contract_id,
|
||||
])->delete();
|
||||
|
||||
return redirect('contracts/display/public')->with('success', 'Bid deleted.');
|
||||
}
|
||||
}
|
||||
|
||||
25
app/Models/Contracts/AcceptedBid.php
Normal file
25
app/Models/Contracts/AcceptedBid.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Contracts;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AcceptedBid extends Model
|
||||
{
|
||||
// Table Name
|
||||
public $table = 'accepted_bid';
|
||||
|
||||
//Timestamps
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'contract_id',
|
||||
'bid_id',
|
||||
'amount',
|
||||
];
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class Bid extends Model
|
||||
public $table = 'contract_bids';
|
||||
|
||||
// Timestamps
|
||||
public $timestamps = false;
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable
|
||||
@@ -19,7 +19,7 @@ class Bid extends Model
|
||||
*/
|
||||
protected $fillable = [
|
||||
'contract_id',
|
||||
'bid',
|
||||
'bid_amount',
|
||||
'accepted',
|
||||
];
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class Contract extends Model
|
||||
*/
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'date',
|
||||
'end_date',
|
||||
'body',
|
||||
];
|
||||
|
||||
|
||||
23
app/User.php
23
app/User.php
@@ -37,17 +37,6 @@ class User extends Authenticatable
|
||||
|
||||
protected $table = 'users';
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function getUserType() {
|
||||
return User::where('user_type')->get();
|
||||
}
|
||||
@@ -79,10 +68,6 @@ class User extends Authenticatable
|
||||
return false;
|
||||
}
|
||||
|
||||
public function tickets() {
|
||||
return $this->hasMany('App\Models\HelpDesk\HelpDeskTicket', 'character_id');
|
||||
}
|
||||
|
||||
public function hasEsiScope($scope) {
|
||||
$found = EsiScope::where(['character_id' => $this->character_id, 'scope' => $scope])->get(['scope']);
|
||||
if(isset($found[0]->scope) && $found[0]->scope == $scope) {
|
||||
@@ -117,4 +102,12 @@ class User extends Authenticatable
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getId() {
|
||||
return $this->character_id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ class CreateContractsTable extends Migration
|
||||
{
|
||||
if(!Schema::hasTable('contracts')) {
|
||||
Schema::create('contracts', function(Blueprint $table) {
|
||||
$table->increments('id')->unique();
|
||||
$table->increments('contract_id')->unique();
|
||||
$table->string('title');
|
||||
$table->date('date');
|
||||
$table->date('end_date');
|
||||
$table->text('body');
|
||||
$table->timestamps();
|
||||
});
|
||||
@@ -27,8 +27,22 @@ class CreateContractsTable extends Migration
|
||||
Schema::create('contract_bids', function(Blueprint $table) {
|
||||
$table->increments('id')->unique();
|
||||
$table->integer('contract_id');
|
||||
$table->decimal('bid');
|
||||
$table->boolean('accepted');
|
||||
$table->decimal('bid_amount');
|
||||
$table->string('character_name');
|
||||
$table->string('character_id');
|
||||
$table->string('corporation_name');
|
||||
$table->string('corporation_id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
if(!Schema::hasTable('accepted_bid')) {
|
||||
Schema::create('accepted_bid', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('contract_id');
|
||||
$table->integer('bid_id');
|
||||
$table->decimal('amount');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -42,5 +56,6 @@ class CreateContractsTable extends Migration
|
||||
{
|
||||
Schema::dropIfExists('contracts');
|
||||
Schema::dropIfExists('contract_bids');
|
||||
Schema::dropIfExists('contract_bid_accepted');
|
||||
}
|
||||
}
|
||||
|
||||
4
resources/views/contracts/allcontracts.blade.php
Normal file
4
resources/views/contracts/allcontracts.blade.php
Normal file
@@ -0,0 +1,4 @@
|
||||
@extends('layouts.b4')
|
||||
@section('content')
|
||||
|
||||
@endsection
|
||||
Reference in New Issue
Block a user