Update checkout, enable editing of checkout, show details on invoices
This commit is contained in:
@@ -96,7 +96,7 @@ class AdminController extends Controller
|
||||
$validation = $request->validate([
|
||||
'account_id' => 'required|exists:accounts,id',
|
||||
'paid_at' => 'required|date',
|
||||
'checkout_id' => 'required|exists:ab_checkout,id',
|
||||
'checkout_id' => 'required|exists:checkouts,id',
|
||||
'total_amt' => 'required|numeric|min:0.01',
|
||||
'fees_amt' => 'nullable|numeric|lt:total_amt',
|
||||
'source_id' => 'nullable|exists:accounts,id',
|
||||
|
@@ -2,13 +2,41 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
use App\Models\Checkout;
|
||||
use App\Http\Requests\CheckoutAddEdit;
|
||||
use App\Models\{Checkout,Invoice};
|
||||
|
||||
class CheckoutController extends Controller
|
||||
{
|
||||
/**
|
||||
* Update a suppliers details
|
||||
*
|
||||
* @param CheckoutAddEdit $request
|
||||
* @param Checkout $o
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function addedit(CheckoutAddEdit $request,Checkout $o)
|
||||
{
|
||||
$this->middleware(['auth','wholesaler']);
|
||||
|
||||
foreach ($request->except(['_token','active','submit']) as $key => $item)
|
||||
$o->{$key} = $item;
|
||||
|
||||
$o->active = (bool)$request->active;
|
||||
|
||||
try {
|
||||
$o->save();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return redirect()->back()->withErrors($e->getMessage())->withInput();
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->with('success','Payment saved');
|
||||
}
|
||||
|
||||
public function cart_invoice(Request $request,Invoice $o=NULL)
|
||||
{
|
||||
if ($o) {
|
||||
@@ -27,8 +55,29 @@ class CheckoutController extends Controller
|
||||
return $o->fee($request->post('total',0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a specific invoice for the user
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function home(): View
|
||||
{
|
||||
return View('payment.home');
|
||||
}
|
||||
|
||||
public function pay(Request $request,Checkout $o)
|
||||
{
|
||||
return redirect('pay/paypal/authorise');
|
||||
}
|
||||
|
||||
/**
|
||||
* View details on a specific payment method
|
||||
*
|
||||
* @param Checkout $o
|
||||
* @return View
|
||||
*/
|
||||
public function view(Checkout $o): View
|
||||
{
|
||||
return View('payment.view',['o'=>$o]);
|
||||
}
|
||||
}
|
@@ -8,7 +8,6 @@ use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\View\View;
|
||||
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
|
||||
|
||||
use App\Models\{Invoice,Service,User};
|
||||
|
||||
@@ -37,28 +36,6 @@ class HomeController extends Controller
|
||||
return View('u.home',['o'=>$o]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a specific invoice for the user
|
||||
*
|
||||
* @param Invoice $o
|
||||
* @return View
|
||||
*/
|
||||
public function invoice(Invoice $o): View
|
||||
{
|
||||
return View('u.invoice.home',['o'=>$o]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the invoice in PDF format, ready to download
|
||||
*
|
||||
* @param Invoice $o
|
||||
* @return mixed
|
||||
*/
|
||||
public function invoice_pdf(Invoice $o)
|
||||
{
|
||||
return PDF::loadView('u.invoice.home',['o'=>$o])->stream(sprintf('%s.pdf',$o->sid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the user to down an invoice by providing a link in email
|
||||
*
|
||||
|
41
app/Http/Controllers/InvoiceController.php
Normal file
41
app/Http/Controllers/InvoiceController.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\View\View;
|
||||
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
|
||||
|
||||
use App\Models\Invoice;
|
||||
|
||||
/**
|
||||
* Class InvoiceController
|
||||
* This controller manages invoices
|
||||
*
|
||||
* The methods to this controller should be projected by the route
|
||||
*
|
||||
* @package App\Http\Controllers
|
||||
*/
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
/**
|
||||
* Return the invoice in PDF format, ready to download
|
||||
*
|
||||
* @param Invoice $o
|
||||
* @return mixed
|
||||
*/
|
||||
public function pdf(Invoice $o)
|
||||
{
|
||||
return PDF::loadView('u.invoice.home',['o'=>$o])->stream(sprintf('%s.pdf',$o->sid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a specific invoice for the user
|
||||
*
|
||||
* @param Invoice $o
|
||||
* @return View
|
||||
*/
|
||||
public function view(Invoice $o): View
|
||||
{
|
||||
return View('invoice.view',['o'=>$o]);
|
||||
}
|
||||
}
|
36
app/Http/Requests/CheckoutAddEdit.php
Normal file
36
app/Http/Requests/CheckoutAddEdit.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* Editing Suppliers
|
||||
*/
|
||||
class CheckoutAddEdit extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Auth::user()->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string|min:2|max:255',
|
||||
'active' => 'sometimes|accepted',
|
||||
'description' => 'nullable|string|min:2|max:255',
|
||||
];
|
||||
}
|
||||
}
|
@@ -19,7 +19,6 @@ class InvoiceEmail extends Mailable
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param Invoice $o
|
||||
* @param string $notes
|
||||
*/
|
||||
public function __construct(Invoice $o)
|
||||
{
|
||||
|
@@ -2,33 +2,43 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Leenooks\Traits\ScopeActive;
|
||||
|
||||
class Checkout extends Model
|
||||
{
|
||||
protected $table = 'ab_checkout';
|
||||
public $timestamps = FALSE;
|
||||
use ScopeActive;
|
||||
|
||||
protected $casts = [
|
||||
'plugin_data'=>'json',
|
||||
];
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany(Payment::class);
|
||||
}
|
||||
|
||||
/** SCOPES **/
|
||||
/* STATIC METHODS */
|
||||
|
||||
/**
|
||||
* Search for a record
|
||||
*
|
||||
* @param $query
|
||||
* @param string $term
|
||||
* @return
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
public static function available(): Collection
|
||||
{
|
||||
return $query->where('active',TRUE);
|
||||
return self::active()->get();
|
||||
}
|
||||
|
||||
/** FUNCTIONS **/
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getIconAttribute(): string
|
||||
{
|
||||
switch(strtolower($this->name)) {
|
||||
case 'paypal': return 'fab fa-cc-paypal';
|
||||
default: return 'fas fa-money-bill-alt';
|
||||
}
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
public function fee(float $amt,int $items=1): float
|
||||
{
|
||||
|
@@ -109,7 +109,7 @@ class Invoice extends Model implements IDs
|
||||
private int $_total = 0;
|
||||
private int $_total_tax = 0;
|
||||
|
||||
/* STATIC */
|
||||
/* STATIC METHODS */
|
||||
|
||||
/**
|
||||
* This works out what multiplier to use to change billing periods
|
||||
|
@@ -17,7 +17,7 @@ class SSL extends Type
|
||||
protected $public_key = NULL;
|
||||
protected $crt_parse = NULL;
|
||||
|
||||
/* STATIC */
|
||||
/* STATIC METHODS */
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
|
Reference in New Issue
Block a user