middleware('auth'); $this->middleware('role:User'); $this->middleware('permission:contract.admin'); } public function displayContractDashboard() { $today = Carbon::now(); $contracts = Contract::where('end_date', '>=', $today)->get(); return view('contracts.admin.contractpanel')->with('contracts', $contracts); } public function displayNewContract() { return view('contracts.admin.newcontract'); } public function storeNewContract(Request $request) { $this->validate($request, [ 'name', 'date', 'body', 'type', ]); $date = new Carbon($request->date); //Store the contract in the database $contract = new Contract; $contract->title = $request->name; $contract->end_date = $request->date; $contract->body = $request->body; $contract->type = $request->type; $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', ]); //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($id) { Contract::where(['contract_id' => $id])->delete(); Bid::where(['contract_id' => $id])->delete(); return redirect('/contracts/admin/display')->with('success', 'Contract has been deleted.'); } public function displayEndContract($id) { //Gather the information for the contract, and all bids on the contract $contract = Contract::where(['contract_id' => $id])->first()->toArray(); $bids = Bid::where(['contract_id' => $id])-get()->toArray(); return view('contracts.admin.endcontract')->with('contract', $contract) ->with('bids', $bids); } public function storeEndContract(Request $request) { $this->validate($request, [ 'contract_id', 'bid_id', ]); //Declare class variables $mail = new Mail; $tries = 1; $contract = Contract::where(['id' => $request->contract_id])->first()->toArray(); $bid = Bid::where(['id' => $request->bid_id, 'contract_id' => $request->contract_id])->first()->toArray(); //Update the contract to mark it as finished Contract::where(['id' => $request->contract_id])->update([ 'finished' => true, ]); //Create the accepted contract entry into the table $accepted = new AcceptedBid; $accepted->contract_id = $contract['id']; $accepted->bid_id = $bid['id']; $accepted->bid_amount = $bid['bid_amount']; $accepted->notes = $bid['notes']; $accepted->save(); //Send mail out to winner of the contract $subject = 'Contract Won'; $body = 'You have been accepted to perform the following contract:
'; $body .= $contract['id'] . ' : ' . $contract['title'] . '
'; $body .= 'Notes:
'; $body .= $contract['description'] . '
'; $body .= 'Please remit contract when the items are ready to Spatial Forces. Description should be the contract identification number. Request ISK should be the bid amount.'; $body .= 'Sincerely,
Spatial Forces Contracting Department'; while($mail->SendMail($bid['character_id'], 'character', $subject, $body)) { $tries++; if($tries == 5) { return redirect('/contracts/admin/display')->with('error', 'Could not deliver mail. Please manually send the mail to the winner.'); } } return redirect('/contracts/admin/display')->with('success', 'Contract finalized. Mail took ' . $tries . ' to send to the winner.'); } }