silent-auction/app/Http/Controllers/PagesController.php

504 lines
17 KiB
PHP
Raw Normal View History

2018-06-11 13:43:21 -04:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use View;
2018-12-23 10:26:26 -05:00
use App\helpers;
2018-06-11 13:43:21 -04:00
use PDF;
2018-12-23 09:49:43 -05:00
use App\Models\Bidders;
use App\Models\Items;
use App\Models\Checkout;
use App\Models\PaymentMethods;
use App\Models\WinningBids;
2019-07-11 20:55:45 -04:00
use App\Models\PeoplesChoice;
use App\Models\Judges;
use App\Models\CarShowWinner;
use App\Models\CarShowCategory;
use App\Models\Types;
use App\Models\Vehicles;
use App\Models\VehicleScores;
2018-06-11 13:43:21 -04:00
class PagesController extends Controller
{
2018-12-23 10:26:26 -05:00
public function home()
{
$item_count_result = Items::count();
$bidder_count_result = Bidders::count();
$winner_count_result = WinningBids::count();
2019-07-13 08:52:30 -04:00
$vehicle_count_result = Vehicles::count();
2018-12-23 10:41:29 -05:00
return view('home', [
'item_count_result' => $item_count_result,
'bidder_count_result' => $bidder_count_result,
2019-07-13 08:52:30 -04:00
'winner_count_result' => $winner_count_result,
'vehicle_count_result' => $vehicle_count_result
2018-12-23 10:41:29 -05:00
]);
2018-12-23 10:26:26 -05:00
}
2018-06-11 13:43:21 -04:00
2018-12-23 10:26:26 -05:00
public function bidderlist()
{
$bidderlist_results = Bidders::orderBy('bidder_assigned_number', 'asc')
2018-12-23 09:54:54 -05:00
->orderBy('bidder_lname', 'asc')
->orderBy('bidder_fname', 'asc')
->get();
2018-12-23 10:26:26 -05:00
return view('bidderlist', ['bidderlist_results' => $bidderlist_results]);
2018-06-11 13:43:21 -04:00
}
2018-12-23 10:00:52 -05:00
2018-12-23 10:26:26 -05:00
public function bidders(Request $bidder_req)
{
if (!$bidder_req->bidderlname) {
return view('bidders');
}
$bidder_lname = $bidder_req->bidderlname;
$bidder_fname = $bidder_req->bidderfname;
$bidder_addr = $bidder_req->bidderaddr;
$bidder_city = $bidder_req->biddercity;
$bidder_state = $bidder_req->bidderstate;
$bidder_zip = $bidder_req->bidderzip;
$bidder_phone = $bidder_req->bidderphone;
$bidder_email = $bidder_req->bidderemail;
$bidder_assigned_number = $bidder_req->biddernum;
$bidder_insert = Bidders::updateOrCreate(
[
'bidder_assigned_number' => $bidder_assigned_number,
],
[
'bidder_lname' => $bidder_lname ,
'bidder_fname' => $bidder_fname ,
'bidder_addr' => $bidder_addr ,
'bidder_city' => $bidder_city ,
'bidder_state' => $bidder_state ,
'bidder_zip' => $bidder_zip ,
'bidder_phone' => $bidder_phone ,
'bidder_email' => $bidder_email
]
);
return redirect('bidders');
}
2018-06-11 13:43:21 -04:00
2018-12-23 10:26:26 -05:00
public function checkout(Request $checkout_req)
{
if (!$checkout_req->checkoutbiddernum) {
return view('checkout_select_form');
} elseif (!$checkout_req->checkout_payment_method) {
$checkout_bidder = $checkout_req->checkoutbiddernum;
2018-12-24 13:02:45 -05:00
$checkout_list_results = DB::select("SELECT
*, items.item_assigned_num
FROM winning_bids
INNER JOIN items AS items
ON winning_bids.winning_item_num=items.iditems
WHERE winning_bidder_num = $checkout_bidder
");
$checkout_info_results = DB::select("SELECT
winning_bids.*,
bidders.*,
sum(winning_cost) AS total_cost
FROM winning_bids
INNER JOIN bidders AS bidders
ON winning_bids.winning_bidder_num=bidders.idbidders
WHERE winning_bidder_num = $checkout_bidder
GROUP BY winning_bids.winning_bidder_num
");
2018-12-23 10:41:29 -05:00
return view('checkout', [
'checkout_list_results' => $checkout_list_results,
'checkout_info_results' => $checkout_info_results
]);
2018-12-23 10:26:26 -05:00
} else {
$winnertotal = $checkout_req->winnertotal;
$bidder_num = $checkout_req->checkoutbiddernum;
$payment_method = $checkout_req->checkout_payment_method;
$check_number = $checkout_req->check_number;
$cc_transaction = $checkout_req->cc_transaction;
$cc_amount = $checkout_req->cc_amount;
2018-12-24 13:02:45 -05:00
$checkout_list_results = DB::select("SELECT
*, items.item_assigned_num, items.item_desc
FROM winning_bids
INNER JOIN items AS items
ON winning_bids.winning_item_num=items.iditems
WHERE winning_bidder_num = $bidder_num
");
$checkout_info_results = DB::select("SELECT
winning_bids.*,
bidders.*,
sum(winning_cost) AS total_cost
FROM winning_bids
INNER JOIN bidders AS bidders
ON winning_bids.winning_bidder_num=bidders.idbidders
WHERE winning_bidder_num = $bidder_num
GROUP BY winning_bids.winning_bidder_num
");
2018-12-23 10:26:26 -05:00
$checkout_result = DB::table('checkout')->insertGetID(
[
'bidder_num' => $bidder_num,
'winnertotal' => $winnertotal,
'payment_method' => $payment_method,
'check_number' => $check_number,
'cc_transaction' => $cc_transaction,
'cc_amount' => $cc_amount,
]
);
2018-12-23 10:41:29 -05:00
return view('checkout_complete', [
'checkout_result' => $checkout_result,
'checkout_list_results' => $checkout_list_results,
'checkout_info_results' => $checkout_info_results,
'payment_method' => $payment_method,
'check_number' => $check_number,
'cc_transaction' => $cc_transaction
]);
2018-12-23 10:26:26 -05:00
}
2018-06-11 13:43:21 -04:00
}
2018-12-23 10:41:29 -05:00
public function checkoutCompleteList()
2018-12-23 10:26:26 -05:00
{
2018-12-24 13:14:39 -05:00
$checkout_complete_results = Checkout::join('bidders', 'checkout.bidder_num', '=', 'bidders.idbidders')
->groupBy('bidder_num')
2018-12-24 13:15:41 -05:00
->orderBy('bidders.bidder_assigned_number', 'asc')
2018-12-24 13:14:39 -05:00
->get();
2018-12-23 10:26:26 -05:00
return view('checkout_complete_list', ['checkout_complete_results' => $checkout_complete_results]);
}
2018-06-11 13:43:21 -04:00
2018-12-23 10:26:26 -05:00
public function editwinners(Request $edit_win_req)
{
if (!$edit_win_req->winid) {
return view('editwinners');
}
$winning_bid_id = $edit_win_req->winid;
$winner_bidder = $edit_win_req->winnerbiddernum;
$winner_cost = $edit_win_req->winnerbid;
2018-12-24 13:21:56 -05:00
$winner_insert = WinningBids::where('idwinning_bids', $winning_bid_id)
->update(
[
'winning_bidder_num' => $winner_bidder,
'winning_cost' => $winner_cost
]
);
2018-12-23 10:26:26 -05:00
return redirect('editwinners');
2018-06-11 13:43:21 -04:00
}
2018-12-23 10:26:26 -05:00
public function finaltally()
{
$finaltally_results = DB::select("SELECT
2018-06-11 13:43:21 -04:00
winning_bids.*,
sum(winning_bids.winning_cost) AS total_due,
bidders.*
FROM winning_bids
INNER JOIN bidders as bidders
ON winning_bids.winning_bidder_num=bidders.idbidders
GROUP BY winning_bids.winning_bidder_num
ORDER BY bidders.bidder_lname
");
2018-12-23 10:26:26 -05:00
return view('finaltally', ['finaltally_results' => $finaltally_results]);
}
2018-06-11 13:43:21 -04:00
2018-12-23 10:26:26 -05:00
public function itemlist()
{
2018-12-24 13:21:56 -05:00
$itemlist_results = Items::orderBy('item_assigned_num', 'asc')
->get();
2018-12-23 10:26:26 -05:00
return view('itemlist', ['itemlist_results' => $itemlist_results]);
}
2018-06-11 13:43:21 -04:00
2018-12-23 10:26:26 -05:00
public function items(Request $items_req)
{
if (!$items_req->itemnum) {
return view('items');
}
$item_assigned_num = $items_req->itemnum;
$item_desc = $items_req->itemdesc;
$item_min_bid = $items_req->itemminbid;
$items_est_value = $items_req->itemestvalue;
$item_insert = DB::table('items')->insert(
[
'item_assigned_num' => $item_assigned_num,
'item_desc' => $item_desc,
'item_min_bid' => $item_min_bid,
'item_est_value' => $items_est_value
]
);
return redirect('items');
2018-06-11 13:43:21 -04:00
}
2018-12-23 10:26:26 -05:00
public function receiptpdf(Request $receiptpdf_request)
{
$checkoutid = $receiptpdf_request->checkout_id;
2018-12-29 13:43:36 -05:00
$checkout_final_results = Checkout::where('checkout_id', '=', $checkoutid)
->first();
$bidder_num = $checkout_final_results->bidder_num;
2018-12-29 14:09:40 -05:00
$checkout_list_results = DB::select("SELECT
*, items.item_assigned_num, items.item_desc
FROM winning_bids
INNER JOIN items AS items
ON winning_bids.winning_item_num=items.iditems
WHERE winning_bidder_num = $bidder_num
");
2018-12-23 10:26:26 -05:00
$checkout_info_results = DB::select("SELECT
2018-06-11 13:43:21 -04:00
winning_bids.*,
bidders.*,
sum(winning_cost) AS total_cost
FROM winning_bids
INNER JOIN bidders AS bidders
ON winning_bids.winning_bidder_num=bidders.idbidders
WHERE winning_bidder_num = $bidder_num
GROUP BY winning_bids.winning_bidder_num
");
2018-12-23 10:26:26 -05:00
$checkout_data = [
'checkout_final_results' => $checkout_final_results,
'checkout_list_results' => $checkout_list_results,
'checkout_info_results' => $checkout_info_results
];
return view('receiptpdf', $checkout_data);
}
2018-06-11 13:43:21 -04:00
2018-12-23 10:41:29 -05:00
public function reprintReceipt(Request $reprint_receipt_req)
2018-12-23 10:26:26 -05:00
{
if (!$reprint_receipt_req->reprintbiddernum) {
return view('reprint_receipt_form');
} else {
$bidnum=$reprint_receipt_req->reprintbiddernum;
2018-12-29 13:34:42 -05:00
$checkout_result = Checkout::where('bidder_num', '=', $bidnum)
2018-12-29 13:36:56 -05:00
->first();
2018-12-29 13:34:42 -05:00
return redirect()->route('receiptpdf', ['checkout_id' => $checkout_result->checkout_id]);
2018-12-23 10:26:26 -05:00
}
2018-06-11 13:43:21 -04:00
}
2018-12-23 10:26:26 -05:00
public function winnerlist()
{
2018-12-24 13:29:48 -05:00
$winnerlist_results = WinningBids::join('bidders', 'winning_bids.winning_bidder_num', '=', 'bidders.idbidders')
->groupBy('winning_bidder_num')
->orderBy('bidders.bidder_assigned_number')
->get();
2018-12-23 10:26:26 -05:00
return view('winnerlist', ['winnerlist_results' => $winnerlist_results]);
}
2018-06-11 13:43:21 -04:00
2018-12-23 10:26:26 -05:00
public function winners(Request $winners_req)
{
if (!$winners_req->winnerbid) {
return view('winners');
}
$winner_item = $winners_req->winneritemnum;
$winner_bidder = $winners_req->winnerbiddernum;
$winner_cost = $winners_req->winnerbid;
$winner_insert = DB::table('winning_bids')->insert(
[
'winning_item_num' => $winner_item,
'winning_bidder_num' => $winner_bidder,
'winning_cost' => $winner_cost
]
);
return redirect('winners');
2018-06-11 13:43:21 -04:00
}
2018-12-23 10:26:26 -05:00
public function winnersbyitem()
{
$winnersbyitem_results = DB::select("SELECT
2018-06-11 13:43:21 -04:00
*
FROM winning_bids
INNER JOIN items as items
ON winning_bids.winning_item_num=items.iditems
INNER JOIN bidders AS bidders
ON winning_bids.winning_bidder_num=bidders.idbidders
ORDER BY item_assigned_num ASC
");
2018-12-23 10:26:26 -05:00
return view('winnersbyitem', ['winnersbyitem_results' => $winnersbyitem_results]);
2018-06-11 13:43:21 -04:00
}
2018-12-23 10:26:26 -05:00
public function winnertotal(Request $winnertotal_req)
{
if (!$winnertotal_req->winnerbiddernum) {
return view('winnertotalform');
}
$winner_total_bidder = $winnertotal_req->winnerbiddernum;
$winnertotal_list_results = DB::select("SELECT
2018-06-11 13:43:21 -04:00
*, items.item_assigned_num
FROM winning_bids
INNER JOIN items AS items
ON winning_bids.winning_item_num=items.iditems
WHERE winning_bidder_num = $winner_total_bidder
");
2018-12-23 10:26:26 -05:00
$winnertotal_info_results = DB::select("SELECT
2018-06-11 13:43:21 -04:00
winning_bids.*,
bidders.*,
sum(winning_cost) AS total_cost
FROM winning_bids
INNER JOIN bidders AS bidders
ON winning_bids.winning_bidder_num=bidders.idbidders
WHERE winning_bidder_num = $winner_total_bidder
GROUP BY winning_bids.winning_bidder_num
");
2018-12-23 10:41:29 -05:00
return view('winnertotal', [
'winnertotal_list_results' => $winnertotal_list_results,
'winnertotal_info_results' => $winnertotal_info_results
]);
2018-12-23 10:26:26 -05:00
}
2018-06-11 13:43:21 -04:00
2018-12-23 10:26:26 -05:00
public function winningbidderlist()
{
2018-12-24 13:27:49 -05:00
$winnerlist_results = WinningBids::join('bidders', 'winning_bids.winning_bidder_num', '=', 'bidders.idbidders')
->groupBy('winning_bidder_num')
->orderBy('bidders.bidder_assigned_number')
->get();
2018-12-23 10:26:26 -05:00
return view('winningbidderlist', ['winnerlist_results' => $winnerlist_results]);
}
2019-07-11 20:55:45 -04:00
public function judgingentry(Request $judgingentry_req)
{
if (!$judgingentry_req->vehnum) {
return view('judgingentry');
}
$vehicle = $judgingentry_req->vehnum;
$judge = $judgingentry_req->judgenum;
$score = $judgingentry_req->vehscore;
$bidder_insert = VehicleScores::updateOrCreate(
[
'vehicle' => $vehicle,
'judge' => $judge
],
[
'overall_score' => $score
]
);
return redirect('judgingentry');
}
public function showcars(Request $showcar_req)
{
if (!$showcar_req->bidderlname) {
return view('showcars');
}
$bidder_lname = $showcar_req->bidderlname;
$bidder_fname = $showcar_req->bidderfname;
$bidder_addr = $showcar_req->bidderaddr;
$bidder_city = $showcar_req->biddercity;
$bidder_state = $showcar_req->bidderstate;
$bidder_zip = $showcar_req->bidderzip;
$bidder_phone = $showcar_req->bidderphone;
$bidder_email = $showcar_req->bidderemail;
$bidder_assigned_number = $showcar_req->biddernum;
$year = $showcar_req->vehyear;
$make = $showcar_req->vehmake;
$model = $showcar_req->vehmodel;
$type = $showcar_req->vehtype;
if ($showcar_req->has('vehdonotjudge')) {
$doNotJudge = 1;
} else {
$doNotJudge = 0;
}
$bidder_insert = Bidders::updateOrCreate(
[
'bidder_assigned_number' => $bidder_assigned_number,
],
[
'bidder_lname' => $bidder_lname ,
'bidder_fname' => $bidder_fname ,
'bidder_addr' => $bidder_addr ,
'bidder_city' => $bidder_city ,
'bidder_state' => $bidder_state ,
'bidder_zip' => $bidder_zip ,
'bidder_phone' => $bidder_phone ,
'bidder_email' => $bidder_email
]
);
//$owner = $bidder_insert->idbidders;
//dd($bidder_insert);
$vehicle_insert = Vehicles::updateOrCreate(
[
2019-07-20 09:59:52 -04:00
'owner' => $bidder_assigned_number,
2019-07-11 20:55:45 -04:00
],
[
'year' => $year,
'make' => $make,
'model' => $model,
'type' => $type,
'doNotJudge' => $doNotJudge
]
);
return redirect('showcars');
}
public function pcentry(Request $pcentry_req)
{
if (!$pcentry_req->vehnum) {
return view('pcentry');
}
$vehicle=$pcentry_req->vehnum;
$pc_count=$pcentry_req->pc_count;
$pc_insert = PeoplesChoice::updateOrCreate(
[
'vehicle' => $vehicle,
],
[
'pc_count' => $pc_count
]
);
return redirect('pcentry');
}
public function judges(Request $judge_req)
{
if (!$judge_req->judgenum) {
return view('judges');
}
$judgenum = $judge_req->judgenum;
$judge_insert = Judges::updateOrCreate(
[
'judge_number' => $judgenum,
]
);
return redirect('judges');
}
public function awardcategories(Request $category_req)
{
if (!$category_req->category) {
return view('awardcategories');
}
$category = $category_req->category;
if ($category_req->has('vehtype')) {
$vehicleType = 1;
} else {
$vehicleType = 0;
}
$category_insert = CarShowCategory::updateOrCreate(
[
'category_name' => $category,
],
[
'vehicle_type' => $vehicleType
]
);
return redirect('awardcategories');
}
public function showwinners()
{
$carshowwinner_results = CarShowWinner::with(['awardCategory', 'awardVehicle', 'awardVehicle.vehicleOwner'])->get();
return view('carshowwinners', ['carshowwinner_results' => $carshowwinner_results]);
}
public function showscores()
{
$carshowscore_results = VehicleScores::with(['scoredVehicle'])
->groupBy('vehicle')
->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore')
->orderBy('totalscore', 'desc')
->get();
return view('carshowscores', ['carshowscore_results' => $carshowscore_results]);
}
public function showcarlist()
{
$showcarlist_results = Bidders::has('vehicles')
->join('vehicles', 'vehicles.owner', '=', 'bidders.bidder_assigned_number')
//->join('car_show_categories', 'vehicles.type', '=', 'car_show_categories.category_name')
->orderBy('bidder_assigned_number')
->get();
//dd($showcarlist_results);
return view('showcarlist', ['showcarlist_results' => $showcarlist_results]);
}
2018-06-11 13:43:21 -04:00
}