contract system before testing
This commit is contained in:
@@ -28,31 +28,67 @@ class ContractAdminController extends Controller
|
||||
|
||||
$contracts = Contract::where(['date', '>=', $today])->get();
|
||||
|
||||
return view('contracts.admin.contractpanel');
|
||||
return view('contracts.admin.contractpanel')->with('contracts', $contracts);
|
||||
}
|
||||
|
||||
public function displayNewContract() {
|
||||
|
||||
return view('contracts.admin.newcontract');
|
||||
}
|
||||
|
||||
public function storeNewContract() {
|
||||
public function storeNewContract(Request $request) {
|
||||
$this->validate($request, [
|
||||
'title',
|
||||
'end_date',
|
||||
'body',
|
||||
]);
|
||||
|
||||
return redirect('/contracts/admin/display');
|
||||
$date = new Carbon($request->date);
|
||||
|
||||
//Store the contract in the database
|
||||
$contract = new Contract;
|
||||
$contract->title = $request->title;
|
||||
$contract->end_date = $request->end_date;
|
||||
$contract->body = $request->body;
|
||||
$contract->save();
|
||||
|
||||
return redirect('/contracts/admin/display')->with('success', 'Contract written.');
|
||||
}
|
||||
|
||||
public function storeAcceptContract(Request $request) {
|
||||
$this->validate($request, [
|
||||
'contract_id',
|
||||
'bid_id',
|
||||
'character_id',
|
||||
'bid_amount',
|
||||
]);
|
||||
|
||||
return redirect('/contracts/admin/display');
|
||||
//Update the contract
|
||||
Contract::where([
|
||||
'contract_id' => $request->contract_id,
|
||||
])->update([
|
||||
'finished' => true,
|
||||
'final_cost' => $request->bid_amount,
|
||||
]);
|
||||
|
||||
//Save the accepted bid in the database
|
||||
$accepted = new AcceptedBid;
|
||||
$accepted->contract_id = $request->contract_id;
|
||||
$accepted->bid_id = $request->bid_id;
|
||||
$accepted->bid_amount = $request->bid_amount;
|
||||
$accepted->save();
|
||||
|
||||
return redirect('/contracts/admin/display')->with('success', 'Contract accepted and closed.');
|
||||
}
|
||||
|
||||
public function deleteContract(Request $request) {
|
||||
$this->validate($request, [
|
||||
'contract_id',
|
||||
]);
|
||||
|
||||
return redirect('/contracts/admin/display');
|
||||
Contract::where([
|
||||
'contract_id' => $request->contract_id,
|
||||
])->delete();
|
||||
|
||||
return redirect('/contracts/admin/display')->with('success', 'Contract has been deleted.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class ContractController extends Controller
|
||||
* 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();
|
||||
$bids = Bids::where(['contract_id' => $contractId, 'character_name' => auth()->user()->getName()])->get();
|
||||
|
||||
return view('contracts.bids')->with('bids', $bids);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class AcceptedBid extends Model
|
||||
'contract_id',
|
||||
'bid_id',
|
||||
'bid_amount',
|
||||
'notes',
|
||||
];
|
||||
|
||||
public function Contract() {
|
||||
|
||||
@@ -20,7 +20,10 @@ class Bid extends Model
|
||||
protected $fillable = [
|
||||
'contract_id',
|
||||
'bid_amount',
|
||||
'accepted',
|
||||
'character_name',
|
||||
'character_id',
|
||||
'corporation_name',
|
||||
'corporation_id',
|
||||
];
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
@@ -21,6 +21,8 @@ class Contract extends Model
|
||||
'title',
|
||||
'end_date',
|
||||
'body',
|
||||
'final_cost',
|
||||
'finished',
|
||||
];
|
||||
|
||||
//One-to-Many relationship for the bids on a contract
|
||||
|
||||
@@ -19,6 +19,8 @@ class CreateContractsTable extends Migration
|
||||
$table->string('title');
|
||||
$table->date('end_date');
|
||||
$table->text('body');
|
||||
$table->boolean('finished');
|
||||
$table->decimal('final_cost');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
@@ -42,6 +44,7 @@ class CreateContractsTable extends Migration
|
||||
$table->integer('contract_id');
|
||||
$table->integer('bid_id');
|
||||
$table->decimal('bid_amount');
|
||||
$table->text('notes');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user