diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 716deef..bc90bae 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -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', diff --git a/app/Http/Controllers/CheckoutController.php b/app/Http/Controllers/CheckoutController.php index 030eb17..c835f7d 100644 --- a/app/Http/Controllers/CheckoutController.php +++ b/app/Http/Controllers/CheckoutController.php @@ -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]); + } } \ No newline at end of file diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index d65e49c..f1d05ab 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -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 * diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php new file mode 100644 index 0000000..3c69e73 --- /dev/null +++ b/app/Http/Controllers/InvoiceController.php @@ -0,0 +1,41 @@ +$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]); + } +} \ No newline at end of file diff --git a/app/Http/Requests/CheckoutAddEdit.php b/app/Http/Requests/CheckoutAddEdit.php new file mode 100644 index 0000000..2c14bdb --- /dev/null +++ b/app/Http/Requests/CheckoutAddEdit.php @@ -0,0 +1,36 @@ +isWholesaler(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + 'name' => 'required|string|min:2|max:255', + 'active' => 'sometimes|accepted', + 'description' => 'nullable|string|min:2|max:255', + ]; + } +} \ No newline at end of file diff --git a/app/Mail/InvoiceEmail.php b/app/Mail/InvoiceEmail.php index 1dfdbb6..1b29f4e 100644 --- a/app/Mail/InvoiceEmail.php +++ b/app/Mail/InvoiceEmail.php @@ -19,7 +19,6 @@ class InvoiceEmail extends Mailable * Create a new message instance. * * @param Invoice $o - * @param string $notes */ public function __construct(Invoice $o) { diff --git a/app/Models/Checkout.php b/app/Models/Checkout.php index 82b7514..73c391e 100644 --- a/app/Models/Checkout.php +++ b/app/Models/Checkout.php @@ -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 { diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index aec3ad5..da5f976 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -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 diff --git a/app/Models/Service/SSL.php b/app/Models/Service/SSL.php index b5af411..285ce63 100644 --- a/app/Models/Service/SSL.php +++ b/app/Models/Service/SSL.php @@ -17,7 +17,7 @@ class SSL extends Type protected $public_key = NULL; protected $crt_parse = NULL; - /* STATIC */ + /* STATIC METHODS */ public static function boot() { diff --git a/database/migrations/2022_07_29_151513_convert_checkout.php b/database/migrations/2022_07_29_151513_convert_checkout.php new file mode 100644 index 0000000..d1e50e2 --- /dev/null +++ b/database/migrations/2022_07_29_151513_convert_checkout.php @@ -0,0 +1,53 @@ +datetime('created_at')->nullable()->after('id'); + $table->datetime('updated_at')->nullable()->after('created_at'); + + $table->dropForeign('ab_checkout_site_id_foreign'); + $table->dropIndex('ab_checkout_id_site_id_index'); + + $table->foreign(['site_id'])->references(['id'])->on('sites'); + }); + + Schema::table('payments', function (Blueprint $table) { + $table->foreign(['checkout_id','site_id'])->references(['id','site_id'])->on('checkouts'); + }); + + foreach (\App\Models\Checkout::withoutGlobalScope(\App\Models\Scopes\SiteScope::class)->cursor() as $o) { + if ($x=$o->getRawOriginal('plugin_data')) { + Config::set('site',$o->site); + + $o->plugin_data = unserialize($x); + } + + $o->save(); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + abort(500,'Cant go back'); + } +}; diff --git a/resources/views/theme/backend/adminlte/u/invoice/home.blade.php b/resources/views/theme/backend/adminlte/invoice/view.blade.php similarity index 92% rename from resources/views/theme/backend/adminlte/u/invoice/home.blade.php rename to resources/views/theme/backend/adminlte/invoice/view.blade.php index e595e5e..4e03423 100644 --- a/resources/views/theme/backend/adminlte/u/invoice/home.blade.php +++ b/resources/views/theme/backend/adminlte/invoice/view.blade.php @@ -1,3 +1,4 @@ + @extends('adminlte::layouts.app') @section('htmlheader_title') @@ -140,14 +141,19 @@

Payment Methods:

- {{-- - Visa - Mastercard - American Express - Paypal - --}} -

+ + @foreach (\App\Models\Checkout::available() as $cho) + + + + + + + @endforeach +
{{ $cho->name }}{{ $cho->description }}@includeIf('payment.widget.plugin.'.strtolower($cho->plugin),['o'=>$cho])
+ +

{!! $o->invoice_text !!}

diff --git a/resources/views/theme/backend/adminlte/payment/home.blade.php b/resources/views/theme/backend/adminlte/payment/home.blade.php new file mode 100644 index 0000000..4b55421 --- /dev/null +++ b/resources/views/theme/backend/adminlte/payment/home.blade.php @@ -0,0 +1,73 @@ +@extends('adminlte::layouts.app') + +@section('htmlheader_title') + Payment +@endsection +@section('page_title') + Payment +@endsection + +@section('contentheader_title') + Payment +@endsection +@section('contentheader_description') +@endsection + +@section('main-content') +
+
+
+
+

Payment Configuration

+
+ +
+
+ @csrf + +
+
+
+ + + + @error('name') + {{ $message }} + @else + Payment Name is required. + @enderror + + Payment Name +
+
+
+
+
+
+
+
+@endsection + +@section('page-scripts') + @css(select2) + @js(select2,autofocus) + + +@endsection \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/payment/view.blade.php b/resources/views/theme/backend/adminlte/payment/view.blade.php new file mode 100644 index 0000000..3b33535 --- /dev/null +++ b/resources/views/theme/backend/adminlte/payment/view.blade.php @@ -0,0 +1,38 @@ + +@extends('adminlte::layouts.app') + +@section('htmlheader_title') + {{ $o->name ?: 'New Payment' }} +@endsection +@section('page_title') + {{ $o->name ?: 'New Payment' }} +@endsection + +@section('contentheader_title') + {{ $o->name ?: 'New Payment' }} +@endsection +@section('contentheader_description') + @include('adminlte::widget.status') +@endsection + +@section('main-content') +
+
+
+
+ +
+ +
+
+
+ @include('payment.widget.detail') +
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/payment/widget/detail.blade.php b/resources/views/theme/backend/adminlte/payment/widget/detail.blade.php new file mode 100644 index 0000000..cd50c98 --- /dev/null +++ b/resources/views/theme/backend/adminlte/payment/widget/detail.blade.php @@ -0,0 +1,70 @@ + +
+
+

Checkout Details

+
+ @if(session()->has('success')) + {{ session()->get('success') }} + @endif + +
+ @csrf + +
+
+
+ +
+
+ + + + @error('name') + {{ $message }} + @else + Payment Name required. + @enderror + +
+
+ + +
+
+
+ active) ? 'checked' : '' }}> + +
+
+
+
+
+
+ +
+ +
+
+ + + + @error('description') + {{ $message }} + @enderror + +
+
+
+ +
+ +
+ Cancel + @can('wholesaler') + + @endcan +
+
+
+
+
\ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/payment/widget/plugin/remit_bank_wire.blade.php b/resources/views/theme/backend/adminlte/payment/widget/plugin/remit_bank_wire.blade.php new file mode 100644 index 0000000..db74351 --- /dev/null +++ b/resources/views/theme/backend/adminlte/payment/widget/plugin/remit_bank_wire.blade.php @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + +
Bank{{ Arr::get($o->plugin_data,'bankname') }}
Branch{{ Arr::get($o->plugin_data,'bankbranch') }}
BSB{{ Arr::get($o->plugin_data,'bankbsb') }}
ACC{{ Arr::get($o->plugin_data,'bankaccount') }}
\ No newline at end of file diff --git a/resources/views/vendor/adminlte/layouts/partials/sidebarmenu.blade.php b/resources/views/vendor/adminlte/layouts/partials/sidebarmenu.blade.php index 8307287..6ceebb2 100644 --- a/resources/views/vendor/adminlte/layouts/partials/sidebarmenu.blade.php +++ b/resources/views/vendor/adminlte/layouts/partials/sidebarmenu.blade.php @@ -77,6 +77,14 @@ + + + + -