2020-07-27 04:49:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2024-08-10 00:14:47 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2020-07-27 04:49:59 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
2022-07-29 06:06:19 +00:00
|
|
|
use App\Http\Requests\CheckoutAddEdit;
|
|
|
|
use App\Models\{Checkout,Invoice};
|
2020-07-27 04:49:59 +00:00
|
|
|
|
|
|
|
class CheckoutController extends Controller
|
|
|
|
{
|
2022-07-29 06:06:19 +00:00
|
|
|
/**
|
2024-08-10 00:14:47 +00:00
|
|
|
* Update a checkout details
|
2022-07-29 06:06:19 +00:00
|
|
|
*
|
|
|
|
* @param CheckoutAddEdit $request
|
|
|
|
* @param Checkout $o
|
2024-08-10 00:14:47 +00:00
|
|
|
* @return RedirectResponse
|
2022-07-29 06:06:19 +00:00
|
|
|
*/
|
2024-08-10 00:14:47 +00:00
|
|
|
public function addedit(CheckoutAddEdit $request,Checkout $o): RedirectResponse
|
2022-07-29 06:06:19 +00:00
|
|
|
{
|
2024-08-10 00:14:47 +00:00
|
|
|
foreach ($request->validated() as $key => $item)
|
2022-07-29 06:06:19 +00:00
|
|
|
$o->{$key} = $item;
|
|
|
|
|
2024-08-10 00:14:47 +00:00
|
|
|
$o->active = (bool)$request->validated('active',FALSE);
|
2022-07-29 06:06:19 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$o->save();
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
2024-08-10 00:14:47 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withErrors($e->getMessage())->withInput();
|
2022-07-29 06:06:19 +00:00
|
|
|
}
|
|
|
|
|
2024-08-10 00:14:47 +00:00
|
|
|
return $o->wasRecentlyCreated
|
|
|
|
? redirect()
|
|
|
|
->to('a/checkout/'.$o->id)
|
|
|
|
->with('success','Checkout added')
|
|
|
|
: redirect()
|
|
|
|
->back()
|
|
|
|
->with('success','Checkout saved');
|
2022-07-29 06:06:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 04:49:59 +00:00
|
|
|
public function cart_invoice(Request $request,Invoice $o=NULL)
|
|
|
|
{
|
|
|
|
if ($o) {
|
|
|
|
$request->session()->put('invoice.cart.'.$o->id,$o->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $request->session()->get('invoice.cart'))
|
2024-07-04 05:03:11 +00:00
|
|
|
return redirect()
|
|
|
|
->to('u/home');
|
2020-07-27 04:49:59 +00:00
|
|
|
|
2024-07-04 05:03:11 +00:00
|
|
|
return view('theme.backend.adminlte.u.invoice.cart')
|
2020-07-27 04:49:59 +00:00
|
|
|
->with('invoices',Invoice::find(array_values($request->session()->get('invoice.cart'))));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fee(Request $request,Checkout $o): float
|
|
|
|
{
|
|
|
|
return $o->fee($request->post('total',0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function pay(Request $request,Checkout $o)
|
|
|
|
{
|
|
|
|
return redirect('pay/paypal/authorise');
|
|
|
|
}
|
|
|
|
}
|